structured-context-map-views 0.7.3 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/artifact.html +1 -1
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/html.js +1 -1
- package/dist/{node-ctbuxC-s.js → node-DGcocEa5.js} +5 -4
- package/dist/node-DGcocEa5.js.map +1 -0
- package/dist/node.js +1 -1
- package/dist/{read-definitions-DFcOXatz.js → read-definitions-BRHtaObL.js} +18 -9
- package/dist/{read-definitions-DFcOXatz.js.map → read-definitions-BRHtaObL.js.map} +1 -1
- package/dist/types/node/index.d.ts +6 -1
- package/dist/types/node/read-definitions.d.ts +8 -2
- package/package.json +1 -1
- package/dist/node-ctbuxC-s.js.map +0 -1
package/dist/artifact.html
CHANGED
|
@@ -667,4 +667,4 @@ body { background: var(--viewer-ground); color: var(--mv-color-ink); }
|
|
|
667
667
|
</style>
|
|
668
668
|
<div id="root"></div>
|
|
669
669
|
<script type="importmap">{"imports":{"structured-context/browser":"https://cdn.jsdelivr.net/npm/structured-context@0.28.1/dist/browser.js/+esm","react":"https://cdn.jsdelivr.net/npm/react@19.3.0/+esm","react/jsx-runtime":"https://cdn.jsdelivr.net/npm/react@19.3.0/jsx-runtime/+esm","react-dom":"https://cdn.jsdelivr.net/npm/react-dom@19.3.0/+esm","react-dom/client":"https://cdn.jsdelivr.net/npm/react-dom@19.3.0/client/+esm","ajv/dist/2020":"https://cdn.jsdelivr.net/npm/ajv@8.20.0/dist/2020.js/+esm","json5":"https://cdn.jsdelivr.net/npm/json5@2.2.3/+esm","https://cdn.jsdelivr.net/npm/react@%5E19.3.0/+esm":"https://cdn.jsdelivr.net/npm/react@19.3.0/+esm"}}</script>
|
|
670
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/structured-context-map-views@0.7.
|
|
670
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/structured-context-map-views@0.7.4/dist/artifact.js"></script>
|
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { r as mapViewsForSchema } from "./definition-SjmROmJC.js";
|
|
3
|
-
import { t as loadMapViewDefinitions } from "./node-
|
|
3
|
+
import { t as loadMapViewDefinitions } from "./node-DGcocEa5.js";
|
|
4
4
|
import { SctxError, assembleSpaceGraph, createSpaceContext, exportSpaceGraph, loadConfig, resolveConfigPath, setConfigPath, validateSpace } from "structured-context/api";
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
var package_default = {
|
|
7
7
|
name: "structured-context-map-views",
|
|
8
|
-
version: "0.7.
|
|
8
|
+
version: "0.7.4",
|
|
9
9
|
description: "Declarative map views of structured-context spaces: render a space as a tree, nested containers and other layouts from a short definition.",
|
|
10
10
|
license: "MIT",
|
|
11
11
|
type: "module",
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":["packageJson"],"sources":["../package.json","../src/node/snapshot.ts","../src/node/cli.ts"],"sourcesContent":["{\n \"name\": \"structured-context-map-views\",\n \"version\": \"0.7.
|
|
1
|
+
{"version":3,"file":"cli.js","names":["packageJson"],"sources":["../package.json","../src/node/snapshot.ts","../src/node/cli.ts"],"sourcesContent":["{\n \"name\": \"structured-context-map-views\",\n \"version\": \"0.7.4\",\n \"description\": \"Declarative map views of structured-context spaces: render a space as a tree, nested containers and other layouts from a short definition.\",\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/mindsocket/structured-context-map-views.git\",\n \"directory\": \"packages/map-views\"\n },\n \"homepage\": \"https://github.com/mindsocket/structured-context-map-views#readme\",\n \"bugs\": \"https://github.com/mindsocket/structured-context-map-views/issues\",\n \"keywords\": [\n \"structured-context\",\n \"visualisation\",\n \"map-view\",\n \"react\"\n ],\n \"files\": [\n \"dist/\"\n ],\n \"sideEffects\": false,\n \"bin\": {\n \"structured-context-map-views\": \"dist/cli.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./dist/types/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"./node\": {\n \"types\": \"./dist/types/node/index.d.ts\",\n \"default\": \"./dist/node.js\"\n },\n \"./html\": {\n \"types\": \"./dist/types/node/html.d.ts\",\n \"default\": \"./dist/html.js\"\n },\n \"./styles.css\": \"./dist/styles.css\",\n \"./page.html\": {\n \"types\": \"./dist/page.html.d.ts\",\n \"default\": \"./dist/page.html\"\n }\n },\n \"scripts\": {\n \"clean\": \"rm -rf dist\",\n \"generate\": \"bun run generate:schemas && bun run generate:definitions\",\n \"generate:schemas\": \"bun scripts/generate-schemas.ts\",\n \"generate:definitions\": \"bun scripts/generate-definitions.ts\",\n \"build:library\": \"bun run clean && bun run generate && bun --bun vite build && tsc -p tsconfig.build.json && tailwindcss -i src/components/styles.css -o dist/styles.css && bun scripts/build-page.ts\",\n \"build\": \"bun run build:library && bun scripts/build-artifact-page.ts\",\n \"typecheck\": \"tsc --noEmit\",\n \"capture-fixtures\": \"bun scripts/capture-fixtures.ts\",\n \"test\": \"bun test\",\n \"test:package\": \"bash scripts/test-package.sh\",\n \"prepublishOnly\": \"bun run build\",\n \"preversion\": \"bun run build:library && bun run --cwd ../.. lint:fix && bun run --cwd ../.. test && bun run --cwd ../.. test:package\",\n \"version\": \"bun run generate:schemas --release && git add -A\"\n },\n \"peerDependencies\": {\n \"react\": \"^19.3.0\",\n \"react-dom\": \"^19.3.0\",\n \"structured-context\": \">=0.25.0 <1.0.0\"\n },\n \"dependencies\": {\n \"ajv\": \"^8.20.0\",\n \"commander\": \"^15.0.0\",\n \"d3-force\": \"^3.0.1\",\n \"json-schema-to-ts\": \"^3.1.1\",\n \"json5\": \"^2.2.3\"\n },\n \"devDependencies\": {\n \"@tailwindcss/cli\": \"^4.3.3\",\n \"@types/d3-force\": \"^3.0.10\",\n \"@types/node\": \"^22.20.5\",\n \"@types/react\": \"^19.3.0\",\n \"@types/react-dom\": \"^19.3.0\",\n \"@vitejs/plugin-react\": \"^6.1.1\",\n \"react\": \"^19.3.0\",\n \"react-dom\": \"^19.3.0\",\n \"structured-context\": \"^0.28.1\",\n \"tailwindcss\": \"^4.3.3\",\n \"vite\": \"^8.3.2\"\n }\n}\n","import {\n assembleSpaceGraph,\n type Config,\n createSpaceContext,\n exportSpaceGraph,\n validateSpace,\n} from 'structured-context/api';\nimport { mapViewsForSchema } from '../core/definition';\nimport type { SpaceSnapshot } from '../core/space-snapshot';\nimport { loadMapViewDefinitions } from './index';\n\n/** The `validateSpace` options `export` passes through unchanged. */\nexport type ExportValidateOptions = Pick<\n NonNullable<Parameters<typeof validateSpace>[1]>,\n 'depth' | 'includeGated' | 'semantic' | 'ruleFilter'\n>;\n\n/**\n * Node-only: snapshot a space for a browser-only host. Validation is structured-context's own\n * `validateSpace`, which also decides whether a judge runs.\n */\nexport async function exportSnapshot(\n spaceName: string,\n config: Config,\n configDir?: string,\n validateOptions: ExportValidateOptions = {},\n): Promise<SpaceSnapshot> {\n const context = createSpaceContext(spaceName, config);\n const graph = await assembleSpaceGraph(context, {});\n const schemaId = context.schema.$id;\n const validation = await validateSpace(context, validateOptions);\n return {\n space: spaceName,\n schemaId,\n graph: exportSpaceGraph(graph.nodes.values(), context.schema.metadata),\n validation: { issues: validation.issues },\n definitions: mapViewsForSchema(loadMapViewDefinitions(config, { configDir }), schemaId),\n };\n}\n","#!/usr/bin/env bun\nimport { Command } from 'commander';\nimport { loadConfig, resolveConfigPath, SctxError, setConfigPath } from 'structured-context/api';\nimport packageJson from '../../package.json' with { type: 'json' };\nimport { type ExportValidateOptions, exportSnapshot } from './snapshot';\n\nconst program = new Command();\n\nprogram\n .name('structured-context-map-views')\n .description('Map view tools for structured-context spaces')\n .version(packageJson.version)\n .option('--config <path>', 'Path to config file (overrides config discovery)');\n\nprogram\n .command('export')\n .description('Print a JSON snapshot of a space: its graph, validation results and map view definitions')\n .argument('<space-name>', 'Space name')\n .option('--depth <n>', 'Validate only hierarchy nodes within N levels from the top', (v) => parseInt(v, 10))\n .option('--include-gated', 'Evaluate rules even on nodes gated by an upstream failure')\n .option(\n '--rule-filter <dimension=values>',\n 'Evaluate only matching rules; dimensions: category, severity, type, id (repeatable, e.g. severity=error)',\n (v: string, prev: string[] = []) => [...prev, v],\n )\n .option('--semantic [provider]', 'Evaluate semantic rules, with the configured model provider or the one named')\n .action(async (spaceName: string, options: ExportValidateOptions) => {\n setConfigPath(program.opts().config);\n try {\n const config = loadConfig();\n const configDir = resolveConfigPath().root;\n const result = await exportSnapshot(spaceName, config, configDir, options);\n process.stdout.write(`${JSON.stringify(result)}\\n`);\n } catch (err) {\n if (!(err instanceof SctxError)) throw err;\n console.error(`${err.code}: ${err.message}`);\n process.exitCode = 1;\n }\n });\n\nawait program.parseAsync();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACqBA,eAAsB,eACpB,WACA,QACA,WACA,kBAAyC,CAAC,GAClB;CACxB,MAAM,UAAU,mBAAmB,WAAW,MAAM;CACpD,MAAM,QAAQ,MAAM,mBAAmB,SAAS,CAAC,CAAC;CAClD,MAAM,WAAW,QAAQ,OAAO;CAChC,MAAM,aAAa,MAAM,cAAc,SAAS,eAAe;CAC/D,OAAO;EACL,OAAO;EACP;EACA,OAAO,iBAAiB,MAAM,MAAM,OAAO,GAAG,QAAQ,OAAO,QAAQ;EACrE,YAAY,EAAE,QAAQ,WAAW,OAAO;EACxC,aAAa,kBAAkB,uBAAuB,QAAQ,EAAE,UAAU,CAAC,GAAG,QAAQ;CACxF;AACF;;;AChCA,IAAM,UAAU,IAAI,QAAQ;AAE5B,QACG,KAAK,8BAA8B,CAAC,CACpC,YAAY,8CAA8C,CAAC,CAC3D,QAAQA,gBAAY,OAAO,CAAC,CAC5B,OAAO,mBAAmB,kDAAkD;AAE/E,QACG,QAAQ,QAAQ,CAAC,CACjB,YAAY,0FAA0F,CAAC,CACvG,SAAS,gBAAgB,YAAY,CAAC,CACtC,OAAO,eAAe,+DAA+D,MAAM,SAAS,GAAG,EAAE,CAAC,CAAC,CAC3G,OAAO,mBAAmB,2DAA2D,CAAC,CACtF,OACC,oCACA,6GACC,GAAW,OAAiB,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CACjD,CAAC,CACA,OAAO,yBAAyB,8EAA8E,CAAC,CAC/G,OAAO,OAAO,WAAmB,YAAmC;CACnE,cAAc,QAAQ,KAAK,CAAC,CAAC,MAAM;CACnC,IAAI;EACF,MAAM,SAAS,WAAW;EAC1B,MAAM,YAAY,kBAAkB,CAAC,CAAC;EACtC,MAAM,SAAS,MAAM,eAAe,WAAW,QAAQ,WAAW,OAAO;EACzE,QAAQ,OAAO,MAAM,GAAG,KAAK,UAAU,MAAM,EAAE,GAAG;CACpD,SAAS,KAAK;EACZ,IAAI,EAAE,eAAe,YAAY,MAAM;EACvC,QAAQ,MAAM,GAAG,IAAI,KAAK,IAAI,IAAI,SAAS;EAC3C,QAAQ,WAAW;CACrB;AACF,CAAC;AAEH,MAAM,QAAQ,WAAW"}
|
package/dist/html.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as readDefinitionFolders } from "./read-definitions-
|
|
1
|
+
import { t as readDefinitionFolders } from "./read-definitions-BRHtaObL.js";
|
|
2
2
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
4
|
import { PLUGIN_PREFIX, resolveConfigPath, resolvePluginDir, resourceDir } from "structured-context/api";
|
|
@@ -11,7 +11,8 @@ var DEFINITIONS_DIR = "map-views";
|
|
|
11
11
|
var CONFIG_PLUGINS_DIR = "plugins";
|
|
12
12
|
/**
|
|
13
13
|
* Every map view definition available with `config`, found as docs/definitions.md describes.
|
|
14
|
-
* Throws on the first invalid definition
|
|
14
|
+
* Throws on the first invalid definition unless `onError` is provided, in which case invalid
|
|
15
|
+
* definitions are reported to `onError` and skipped so valid definitions still load.
|
|
15
16
|
*
|
|
16
17
|
* `configDir` is the root of the main config file; it defaults to where structured-context finds it.
|
|
17
18
|
*/
|
|
@@ -34,7 +35,7 @@ function loadMapViewDefinitions(config, options = {}) {
|
|
|
34
35
|
source: { kind: "config" }
|
|
35
36
|
}] : [];
|
|
36
37
|
})];
|
|
37
|
-
return readDefinitionFolders(folders);
|
|
38
|
+
return readDefinitionFolders(folders, { onError: options.onError });
|
|
38
39
|
}
|
|
39
40
|
/** Plugin short name → root directory, for plugins in a config root's plugins folder or named by the config. */
|
|
40
41
|
function pluginDirs(config, configDir, configDirs) {
|
|
@@ -71,4 +72,4 @@ function pluginDefinitionsDir(pluginDir) {
|
|
|
71
72
|
//#endregion
|
|
72
73
|
export { loadMapViewDefinitions as t };
|
|
73
74
|
|
|
74
|
-
//# sourceMappingURL=node-
|
|
75
|
+
//# sourceMappingURL=node-DGcocEa5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-DGcocEa5.js","names":[],"sources":["../src/node/index.ts"],"sourcesContent":["/// <reference types=\"node\" />\nimport { existsSync, readdirSync, readFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport { type Config, PLUGIN_PREFIX, resolveConfigPath, resolvePluginDir, resourceDir } from 'structured-context/api';\nimport type { MapViewDefinition } from '../core/definition';\nimport { type DefinitionSource, readDefinitionFolders } from './read-definitions';\n\n/**\n * Node-only: finds map view definitions the way structured-context finds plugin schemas.\n * Browser-only hosts receive the result from a server, like graph data.\n */\n\nconst DEFINITIONS_DIR = 'map-views';\nconst CONFIG_PLUGINS_DIR = 'plugins';\n\n/**\n * Every map view definition available with `config`, found as docs/definitions.md describes.\n * Throws on the first invalid definition unless `onError` is provided, in which case invalid\n * definitions are reported to `onError` and skipped so valid definitions still load.\n *\n * `configDir` is the root of the main config file; it defaults to where structured-context finds it.\n */\nexport function loadMapViewDefinitions(\n config: Config,\n options: { configDir?: string; onError?: (error: { path: string; message: string }) => void } = {},\n): MapViewDefinition[] {\n const configDir = options.configDir ?? resolveConfigPath().root;\n const configDirs = [...new Set([configDir, ...config.spaces.flatMap((s) => (s.sourceDir ? [s.sourceDir] : []))])];\n\n const folders: { dir: string; source: DefinitionSource }[] = [\n ...pluginDirs(config, configDir, configDirs).flatMap(([plugin, dir]) => {\n const definitions = pluginDefinitionsDir(dir);\n return definitions ? [{ dir: definitions, source: { kind: 'plugin', plugin } as const }] : [];\n }),\n ...configDirs.flatMap((dir) => {\n const definitions = resourceDir(dir, DEFINITIONS_DIR);\n return definitions ? [{ dir: definitions, source: { kind: 'config' } as const }] : [];\n }),\n ];\n\n return readDefinitionFolders(folders, { onError: options.onError });\n}\n\n/** Plugin short name → root directory, for plugins in a config root's plugins folder or named by the config. */\nfunction pluginDirs(config: Config, configDir: string, configDirs: string[]): [string, string][] {\n const found = new Map<string, string>();\n const add = (name: string, fromDir: string) => {\n const short = name.startsWith(PLUGIN_PREFIX) ? name.slice(PLUGIN_PREFIX.length) : name;\n if (found.has(short)) return;\n const dir = resolvePluginDir(name, fromDir);\n if (dir) found.set(short, dir);\n };\n\n for (const dir of configDirs) {\n const plugins = resourceDir(dir, CONFIG_PLUGINS_DIR);\n if (!plugins) continue;\n for (const entry of readdirSync(plugins)\n .filter((e) => e.startsWith(PLUGIN_PREFIX))\n .sort())\n add(entry, dir);\n }\n const topLevel = (config as { plugins?: Record<string, unknown> }).plugins ?? {};\n for (const name of Object.keys(topLevel)) add(name, configDir);\n for (const space of config.spaces) {\n const fromDir = space.sourceDir ?? configDir;\n // A schema named through a plugin, e.g. \"sctx-wardley-mapping/wardley_map.json\".\n const schemaPlugin = /^([^./][^/]*)\\/./.exec(space.schema ?? '')?.[1];\n if (schemaPlugin) add(schemaPlugin, fromDir);\n for (const name of Object.keys(space.plugins ?? {})) add(name, fromDir);\n }\n return [...found];\n}\n\nfunction pluginDefinitionsDir(pluginDir: string): string | undefined {\n const pkgPath = join(pluginDir, 'package.json');\n if (existsSync(pkgPath)) {\n const declared = JSON.parse(readFileSync(pkgPath, 'utf8')).sctx?.[DEFINITIONS_DIR];\n if (typeof declared === 'string') return resolve(pluginDir, declared);\n }\n return join(pluginDir, DEFINITIONS_DIR);\n}\n"],"mappings":";;;;;;;;;AAYA,IAAM,kBAAkB;AACxB,IAAM,qBAAqB;;;;;;;;AAS3B,SAAgB,uBACd,QACA,UAAgG,CAAC,GAC5E;CACrB,MAAM,YAAY,QAAQ,aAAa,kBAAkB,CAAC,CAAC;CAC3D,MAAM,aAAa,CAAC,mBAAG,IAAI,IAAI,CAAC,WAAW,GAAG,OAAO,OAAO,SAAS,MAAO,EAAE,YAAY,CAAC,EAAE,SAAS,IAAI,CAAC,CAAE,CAAC,CAAC,CAAC;CAEhH,MAAM,UAAuD,CAC3D,GAAG,WAAW,QAAQ,WAAW,UAAU,CAAC,CAAC,SAAS,CAAC,QAAQ,SAAS;EACtE,MAAM,cAAc,qBAAqB,GAAG;EAC5C,OAAO,cAAc,CAAC;GAAE,KAAK;GAAa,QAAQ;IAAE,MAAM;IAAU;GAAO;EAAW,CAAC,IAAI,CAAC;CAC9F,CAAC,GACD,GAAG,WAAW,SAAS,QAAQ;EAC7B,MAAM,cAAc,YAAY,KAAK,eAAe;EACpD,OAAO,cAAc,CAAC;GAAE,KAAK;GAAa,QAAQ,EAAE,MAAM,SAAS;EAAW,CAAC,IAAI,CAAC;CACtF,CAAC,CACH;CAEA,OAAO,sBAAsB,SAAS,EAAE,SAAS,QAAQ,QAAQ,CAAC;AACpE;;AAGA,SAAS,WAAW,QAAgB,WAAmB,YAA0C;CAC/F,MAAM,wBAAQ,IAAI,IAAoB;CACtC,MAAM,OAAO,MAAc,YAAoB;EAC7C,MAAM,QAAQ,KAAK,WAAW,aAAa,IAAI,KAAK,MAAM,cAAc,MAAM,IAAI;EAClF,IAAI,MAAM,IAAI,KAAK,GAAG;EACtB,MAAM,MAAM,iBAAiB,MAAM,OAAO;EAC1C,IAAI,KAAK,MAAM,IAAI,OAAO,GAAG;CAC/B;CAEA,KAAK,MAAM,OAAO,YAAY;EAC5B,MAAM,UAAU,YAAY,KAAK,kBAAkB;EACnD,IAAI,CAAC,SAAS;EACd,KAAK,MAAM,SAAS,YAAY,OAAO,CAAC,CACrC,QAAQ,MAAM,EAAE,WAAW,aAAa,CAAC,CAAC,CAC1C,KAAK,GACN,IAAI,OAAO,GAAG;CAClB;CACA,MAAM,WAAY,OAAiD,WAAW,CAAC;CAC/E,KAAK,MAAM,QAAQ,OAAO,KAAK,QAAQ,GAAG,IAAI,MAAM,SAAS;CAC7D,KAAK,MAAM,SAAS,OAAO,QAAQ;EACjC,MAAM,UAAU,MAAM,aAAa;EAEnC,MAAM,eAAe,mBAAmB,KAAK,MAAM,UAAU,EAAE,CAAC,GAAG;EACnE,IAAI,cAAc,IAAI,cAAc,OAAO;EAC3C,KAAK,MAAM,QAAQ,OAAO,KAAK,MAAM,WAAW,CAAC,CAAC,GAAG,IAAI,MAAM,OAAO;CACxE;CACA,OAAO,CAAC,GAAG,KAAK;AAClB;AAEA,SAAS,qBAAqB,WAAuC;CACnE,MAAM,UAAU,KAAK,WAAW,cAAc;CAC9C,IAAI,WAAW,OAAO,GAAG;EACvB,MAAM,WAAW,KAAK,MAAM,aAAa,SAAS,MAAM,CAAC,CAAC,CAAC,OAAO;EAClE,IAAI,OAAO,aAAa,UAAU,OAAO,QAAQ,WAAW,QAAQ;CACtE;CACA,OAAO,KAAK,WAAW,eAAe;AACxC"}
|
package/dist/node.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as loadMapViewDefinitions } from "./node-
|
|
1
|
+
import { t as loadMapViewDefinitions } from "./node-DGcocEa5.js";
|
|
2
2
|
export { loadMapViewDefinitions };
|
|
@@ -14,18 +14,27 @@ var SCHEME = "sctx-map-view://";
|
|
|
14
14
|
var PACKAGE_NAME = "structured-context-map-views";
|
|
15
15
|
/**
|
|
16
16
|
* Definitions in `folders` and this package's embedded ones, each checked against the namespace of its source.
|
|
17
|
-
* Throws on the first invalid definition or a repeated id
|
|
17
|
+
* Throws on the first invalid definition or a repeated id unless `onError` is provided, in which case
|
|
18
|
+
* invalid definitions are reported to `onError` and skipped so valid definitions still load.
|
|
18
19
|
*/
|
|
19
|
-
function readDefinitionFolders(folders) {
|
|
20
|
+
function readDefinitionFolders(folders, options = {}) {
|
|
20
21
|
const foundAt = /* @__PURE__ */ new Map();
|
|
21
22
|
const definitions = [];
|
|
22
23
|
const add = (label, text, source) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
try {
|
|
25
|
+
const definition = parseMapViewDefinition(label, text);
|
|
26
|
+
assertIdNamespace(definition.id, source, label);
|
|
27
|
+
const existing = foundAt.get(definition.id);
|
|
28
|
+
if (existing) throw new Error(`Map view id "${definition.id}" is defined by both ${existing} and ${label}.`);
|
|
29
|
+
foundAt.set(definition.id, label);
|
|
30
|
+
definitions.push(definition);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
if (!options.onError) throw err;
|
|
33
|
+
options.onError({
|
|
34
|
+
path: label,
|
|
35
|
+
message: err instanceof Error ? err.message : String(err)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
29
38
|
};
|
|
30
39
|
for (const [file, text] of Object.entries(BUNDLED_DEFINITIONS)) add(`${PACKAGE_NAME}/${file}`, text, { kind: "core" });
|
|
31
40
|
for (const { dir, source } of folders) {
|
|
@@ -48,4 +57,4 @@ function isDirectory(path) {
|
|
|
48
57
|
//#endregion
|
|
49
58
|
export { readDefinitionFolders as t };
|
|
50
59
|
|
|
51
|
-
//# sourceMappingURL=read-definitions-
|
|
60
|
+
//# sourceMappingURL=read-definitions-BRHtaObL.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-definitions-
|
|
1
|
+
{"version":3,"file":"read-definitions-BRHtaObL.js","names":[],"sources":["../src/node/bundled-definitions.ts","../src/node/read-definitions.ts"],"sourcesContent":["// Generated by scripts/generate-definitions.ts from map-views/*.json5. Do not edit.\nexport const BUNDLED_DEFINITIONS: Record<string, string> = {\n \"graph.json5\": \"// Every node and edge as a network. Any schema.\\n{\\n $schema: 'https://raw.githubusercontent.com/mindsocket/structured-context-map-views/main/schemas/generated/latest/definition.json',\\n $id: 'sctx-map-view://core/graph',\\n title: 'Graph',\\n parameters: {\\n nodeStyle: { $ref: 'settings.json#/$defs/nodeStyle', default: 'shape' },\\n labels: { type: 'boolean', title: 'Relationship labels', default: false },\\n validation: { $ref: 'settings.json#/$defs/validationLevel', default: 'off' },\\n },\\n regions: [\\n {\\n id: 'main',\\n layout: { type: 'graph' },\\n nodes: { style: { $param: 'nodeStyle' }, validation: { $param: 'validation' } },\\n edges: { show: true, labels: { $param: 'labels' } },\\n },\\n ],\\n}\\n\",\n \"neighbourhood.json5\": \"// One node with the nodes it is related to around it. Any schema.\\n{\\n $schema: 'https://raw.githubusercontent.com/mindsocket/structured-context-map-views/main/schemas/generated/latest/definition.json',\\n $id: 'sctx-map-view://core/neighbourhood',\\n title: 'Neighbourhood',\\n parameters: {\\n labels: { type: 'boolean', title: 'Relationship labels', default: true },\\n validation: { $ref: 'settings.json#/$defs/validationLevel', default: 'off' },\\n },\\n regions: [\\n {\\n id: 'main',\\n layout: { type: 'neighbourhood' },\\n nodes: { validation: { $param: 'validation' } },\\n edges: { show: true, labels: { $param: 'labels' } },\\n },\\n ],\\n}\\n\",\n \"strategy-tree.json5\": \"// Strategy stack as a tree: vision → mission → goals → opportunities → solutions → experiments.\\n{\\n $schema: 'https://raw.githubusercontent.com/mindsocket/structured-context-map-views/main/schemas/generated/latest/definition.json',\\n $id: 'sctx-map-view://core/strategy-tree',\\n title: 'Strategy tree',\\n schema: 'sctx://core/strategy_general',\\n parameters: {\\n orientation: { $ref: 'settings.json#/$defs/orientation', default: 'vertical' },\\n nodeStyle: { $ref: 'settings.json#/$defs/nodeStyle', default: 'card' },\\n validation: { $ref: 'settings.json#/$defs/validationLevel', default: 'off' },\\n cardFields: {\\n title: 'Card fields',\\n type: 'array',\\n items: { enum: ['status', 'priority', 'summary'] },\\n default: ['status'],\\n },\\n },\\n regions: [\\n {\\n id: 'main',\\n layout: { type: 'tree', orientation: { $param: 'orientation' } },\\n nodes: { style: { $param: 'nodeStyle' }, fields: { $param: 'cardFields' }, validation: { $param: 'validation' } },\\n edges: { show: true },\\n },\\n ],\\n}\\n\",\n \"tree.json5\": \"// The hierarchy as a tree. Any schema that has one.\\n{\\n $schema: 'https://raw.githubusercontent.com/mindsocket/structured-context-map-views/main/schemas/generated/latest/definition.json',\\n $id: 'sctx-map-view://core/tree',\\n title: 'Tree',\\n parameters: {\\n orientation: { $ref: 'settings.json#/$defs/orientation', default: 'vertical' },\\n nodeStyle: { $ref: 'settings.json#/$defs/nodeStyle', default: 'card' },\\n validation: { $ref: 'settings.json#/$defs/validationLevel', default: 'off' },\\n },\\n regions: [\\n {\\n id: 'main',\\n layout: { type: 'tree', orientation: { $param: 'orientation' } },\\n nodes: { style: { $param: 'nodeStyle' }, validation: { $param: 'validation' } },\\n edges: { show: true },\\n },\\n ],\\n}\\n\",\n};\n","import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { type MapViewDefinition, parseMapViewDefinition } from '../core/definition';\nimport { BUNDLED_DEFINITIONS } from './bundled-definitions';\n\nconst SCHEME = 'sctx-map-view://';\nconst PACKAGE_NAME = 'structured-context-map-views';\n\nexport type DefinitionSource = { kind: 'core' } | { kind: 'plugin'; plugin: string } | { kind: 'config' };\n\n/**\n * Definitions in `folders` and this package's embedded ones, each checked against the namespace of its source.\n * Throws on the first invalid definition or a repeated id unless `onError` is provided, in which case\n * invalid definitions are reported to `onError` and skipped so valid definitions still load.\n */\nexport function readDefinitionFolders(\n folders: { dir: string; source: DefinitionSource }[],\n options: { onError?: (error: { path: string; message: string }) => void } = {},\n): MapViewDefinition[] {\n const foundAt = new Map<string, string>();\n const definitions: MapViewDefinition[] = [];\n const add = (label: string, text: string, source: DefinitionSource) => {\n try {\n const definition = parseMapViewDefinition(label, text);\n assertIdNamespace(definition.id, source, label);\n const existing = foundAt.get(definition.id);\n if (existing) throw new Error(`Map view id \"${definition.id}\" is defined by both ${existing} and ${label}.`);\n foundAt.set(definition.id, label);\n definitions.push(definition);\n } catch (err) {\n if (!options.onError) throw err;\n options.onError({ path: label, message: err instanceof Error ? err.message : String(err) });\n }\n };\n\n for (const [file, text] of Object.entries(BUNDLED_DEFINITIONS))\n add(`${PACKAGE_NAME}/${file}`, text, { kind: 'core' });\n for (const { dir, source } of folders) {\n if (!isDirectory(dir)) continue;\n for (const file of readdirSync(dir)\n .filter((f) => f.endsWith('.json5'))\n .sort()) {\n const path = join(dir, file);\n add(path, readFileSync(path, 'utf8'), source);\n }\n }\n return definitions;\n}\n\nfunction assertIdNamespace(id: string, source: DefinitionSource, path: string): void {\n const segments = id.slice(SCHEME.length).split('/');\n const expected =\n source.kind === 'core'\n ? `${SCHEME}core/<name>`\n : source.kind === 'plugin'\n ? `${SCHEME}${source.plugin}/<name>`\n : `${SCHEME}<name>`;\n const ok =\n source.kind === 'config'\n ? segments.length === 1\n : segments.length === 2 && segments[0] === (source.kind === 'core' ? 'core' : source.plugin);\n if (!ok || (source.kind === 'plugin' && source.plugin === 'core')) {\n throw new Error(`Map view namespace violation: ${path} has $id \"${id}\". Use the form \"${expected}\".`);\n }\n}\n\nfunction isDirectory(path: string): boolean {\n return existsSync(path) && statSync(path).isDirectory();\n}\n"],"mappings":";;;;AACA,IAAa,sBAA8C;CACzD,eAAe;CACf,uBAAuB;CACvB,uBAAuB;CACvB,cAAc;AAChB;;;ACDA,IAAM,SAAS;AACf,IAAM,eAAe;;;;;;AASrB,SAAgB,sBACd,SACA,UAA4E,CAAC,GACxD;CACrB,MAAM,0BAAU,IAAI,IAAoB;CACxC,MAAM,cAAmC,CAAC;CAC1C,MAAM,OAAO,OA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,OAAO,SAAS,YAAY,OAAO,WAAW,QACxD,MAAM,IAAI,MAAM,iCAAiC,KAAK,YAAY,GAAG,mBAAmB,SAAS,GAAG;AAExG;AAEA,SAAS,YAAY,MAAuB;CAC1C,OAAO,WAAW,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,YAAY;AACxD"}
|
|
@@ -2,10 +2,15 @@ import { type Config } from 'structured-context/api';
|
|
|
2
2
|
import type { MapViewDefinition } from '../core/definition';
|
|
3
3
|
/**
|
|
4
4
|
* Every map view definition available with `config`, found as docs/definitions.md describes.
|
|
5
|
-
* Throws on the first invalid definition
|
|
5
|
+
* Throws on the first invalid definition unless `onError` is provided, in which case invalid
|
|
6
|
+
* definitions are reported to `onError` and skipped so valid definitions still load.
|
|
6
7
|
*
|
|
7
8
|
* `configDir` is the root of the main config file; it defaults to where structured-context finds it.
|
|
8
9
|
*/
|
|
9
10
|
export declare function loadMapViewDefinitions(config: Config, options?: {
|
|
10
11
|
configDir?: string;
|
|
12
|
+
onError?: (error: {
|
|
13
|
+
path: string;
|
|
14
|
+
message: string;
|
|
15
|
+
}) => void;
|
|
11
16
|
}): MapViewDefinition[];
|
|
@@ -9,9 +9,15 @@ export type DefinitionSource = {
|
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
11
|
* Definitions in `folders` and this package's embedded ones, each checked against the namespace of its source.
|
|
12
|
-
* Throws on the first invalid definition or a repeated id
|
|
12
|
+
* Throws on the first invalid definition or a repeated id unless `onError` is provided, in which case
|
|
13
|
+
* invalid definitions are reported to `onError` and skipped so valid definitions still load.
|
|
13
14
|
*/
|
|
14
15
|
export declare function readDefinitionFolders(folders: {
|
|
15
16
|
dir: string;
|
|
16
17
|
source: DefinitionSource;
|
|
17
|
-
}[]
|
|
18
|
+
}[], options?: {
|
|
19
|
+
onError?: (error: {
|
|
20
|
+
path: string;
|
|
21
|
+
message: string;
|
|
22
|
+
}) => void;
|
|
23
|
+
}): MapViewDefinition[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "structured-context-map-views",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"description": "Declarative map views of structured-context spaces: render a space as a tree, nested containers and other layouts from a short definition.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"node-ctbuxC-s.js","names":[],"sources":["../src/node/index.ts"],"sourcesContent":["/// <reference types=\"node\" />\nimport { existsSync, readdirSync, readFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport { type Config, PLUGIN_PREFIX, resolveConfigPath, resolvePluginDir, resourceDir } from 'structured-context/api';\nimport type { MapViewDefinition } from '../core/definition';\nimport { type DefinitionSource, readDefinitionFolders } from './read-definitions';\n\n/**\n * Node-only: finds map view definitions the way structured-context finds plugin schemas.\n * Browser-only hosts receive the result from a server, like graph data.\n */\n\nconst DEFINITIONS_DIR = 'map-views';\nconst CONFIG_PLUGINS_DIR = 'plugins';\n\n/**\n * Every map view definition available with `config`, found as docs/definitions.md describes.\n * Throws on the first invalid definition, including one outside its namespace or with a duplicate `$id`.\n *\n * `configDir` is the root of the main config file; it defaults to where structured-context finds it.\n */\nexport function loadMapViewDefinitions(config: Config, options: { configDir?: string } = {}): MapViewDefinition[] {\n const configDir = options.configDir ?? resolveConfigPath().root;\n const configDirs = [...new Set([configDir, ...config.spaces.flatMap((s) => (s.sourceDir ? [s.sourceDir] : []))])];\n\n const folders: { dir: string; source: DefinitionSource }[] = [\n ...pluginDirs(config, configDir, configDirs).flatMap(([plugin, dir]) => {\n const definitions = pluginDefinitionsDir(dir);\n return definitions ? [{ dir: definitions, source: { kind: 'plugin', plugin } as const }] : [];\n }),\n ...configDirs.flatMap((dir) => {\n const definitions = resourceDir(dir, DEFINITIONS_DIR);\n return definitions ? [{ dir: definitions, source: { kind: 'config' } as const }] : [];\n }),\n ];\n\n return readDefinitionFolders(folders);\n}\n\n/** Plugin short name → root directory, for plugins in a config root's plugins folder or named by the config. */\nfunction pluginDirs(config: Config, configDir: string, configDirs: string[]): [string, string][] {\n const found = new Map<string, string>();\n const add = (name: string, fromDir: string) => {\n const short = name.startsWith(PLUGIN_PREFIX) ? name.slice(PLUGIN_PREFIX.length) : name;\n if (found.has(short)) return;\n const dir = resolvePluginDir(name, fromDir);\n if (dir) found.set(short, dir);\n };\n\n for (const dir of configDirs) {\n const plugins = resourceDir(dir, CONFIG_PLUGINS_DIR);\n if (!plugins) continue;\n for (const entry of readdirSync(plugins)\n .filter((e) => e.startsWith(PLUGIN_PREFIX))\n .sort())\n add(entry, dir);\n }\n const topLevel = (config as { plugins?: Record<string, unknown> }).plugins ?? {};\n for (const name of Object.keys(topLevel)) add(name, configDir);\n for (const space of config.spaces) {\n const fromDir = space.sourceDir ?? configDir;\n // A schema named through a plugin, e.g. \"sctx-wardley-mapping/wardley_map.json\".\n const schemaPlugin = /^([^./][^/]*)\\/./.exec(space.schema ?? '')?.[1];\n if (schemaPlugin) add(schemaPlugin, fromDir);\n for (const name of Object.keys(space.plugins ?? {})) add(name, fromDir);\n }\n return [...found];\n}\n\nfunction pluginDefinitionsDir(pluginDir: string): string | undefined {\n const pkgPath = join(pluginDir, 'package.json');\n if (existsSync(pkgPath)) {\n const declared = JSON.parse(readFileSync(pkgPath, 'utf8')).sctx?.[DEFINITIONS_DIR];\n if (typeof declared === 'string') return resolve(pluginDir, declared);\n }\n return join(pluginDir, DEFINITIONS_DIR);\n}\n"],"mappings":";;;;;;;;;AAYA,IAAM,kBAAkB;AACxB,IAAM,qBAAqB;;;;;;;AAQ3B,SAAgB,uBAAuB,QAAgB,UAAkC,CAAC,GAAwB;CAChH,MAAM,YAAY,QAAQ,aAAa,kBAAkB,CAAC,CAAC;CAC3D,MAAM,aAAa,CAAC,mBAAG,IAAI,IAAI,CAAC,WAAW,GAAG,OAAO,OAAO,SAAS,MAAO,EAAE,YAAY,CAAC,EAAE,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