UNPKG

@silexlabs/grapesjs-data-source

Version:
58 lines 2.84 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const GraphQL_1 = __importDefault(require("./datasources/GraphQL")); const dataSourceManager_1 = require("./model/dataSourceManager"); const dataSourceRegistry_1 = require("./model/dataSourceRegistry"); exports.default = (editor) => { // Save and load data sources editor.on('storage:start:store', (data) => { data.dataSources = (0, dataSourceRegistry_1.getAllDataSources)() .filter((ds) => typeof ds.readonly === 'undefined' || ds.readonly === false) .map((ds) => { const baseData = { id: ds.id, label: ds.label, url: ds.url, type: ds.type, method: ds.method, headers: ds.headers, readonly: ds.readonly, hidden: ds.hidden }; // Include GraphQL-specific fields if available if (ds instanceof GraphQL_1.default) { return Object.assign(Object.assign({}, baseData), { backendType: ds.backendType, disabledTypes: ds.disabledTypes }); } return baseData; }); }); editor.on('storage:end:load', (data) => __awaiter(void 0, void 0, void 0, function* () { // Connect the data sources const newDataSources = (data.dataSources || []) .map((ds) => new GraphQL_1.default(ds)); // Get all data sources const dataSources = (0, dataSourceRegistry_1.getAllDataSources)() // Keep only data sources from the config .filter((ds) => ds.readonly === true); // Reset the data sources to the original config (0, dataSourceManager_1.resetDataSources)(dataSources); // Add the new data sources newDataSources.forEach(ds => { (0, dataSourceRegistry_1.addDataSource)(ds); }); (0, dataSourceManager_1.refreshDataSources)(); })); }; //# sourceMappingURL=storage.js.map