UNPKG

alinea

Version:

[![npm](https://img.shields.io/npm/v/alinea.svg)](https://npmjs.org/package/alinea) [![install size](https://packagephobia.com/badge?p=alinea)](https://packagephobia.com/result?p=alinea)

56 lines (54 loc) 1.59 kB
import "../chunks/chunk-U5RRZUYZ.js"; // src/core/CMS.ts import { createConfig } from "./Config.js"; import { Graph, GraphRealm } from "./Graph.js"; import { entries } from "./util/Objects.js"; var attached = /* @__PURE__ */ new WeakMap(); var CMS = class extends GraphRealm { graph; config; constructor(config) { const normalizedConfig = createConfig(config); super(normalizedConfig, async (params) => { const cnx = await this.resolver(); return cnx.resolve(params); }); this.config = normalizedConfig; this.graph = new Graph(normalizedConfig, async (params) => { const { resolve } = await this.resolver(); return resolve(params); }); this.#attach(config); } #attach(config) { for (const [name, workspace] of entries(config.workspaces)) { if (attached.has(workspace)) throw new Error(`Workspace is already attached to a CMS: ${name}`); attached.set(workspace, this); for (const [name2, root] of entries(workspace)) { if (attached.has(root)) throw new Error(`Root is already attached to a CMS: ${name2}`); attached.set(root, this); } } } get schema() { return this.config.schema; } get workspaces() { return this.config.workspaces; } }; ((CMS2) => { CMS2.Link = Symbol.for("@alinea/CMS.Link"); function instanceFor(attachment) { const cms = attached.get(attachment); if (!cms) throw new Error(`No CMS attached to ${attachment}`); return cms; } CMS2.instanceFor = instanceFor; })(CMS || (CMS = {})); export { CMS };