@prometheus-ags/entity-graph-sdl 3.2.0 → 4.0.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @prometheus-ags/entity-graph-sdl
2
2
 
3
+ ## 4.0.0
4
+
3
5
  ## 3.2.0
4
6
 
5
7
  ### Minor Changes
package/package.json CHANGED
@@ -1,23 +1,17 @@
1
1
  {
2
2
  "name": "@prometheus-ags/entity-graph-sdl",
3
- "version": "3.2.0",
3
+ "version": "4.0.1",
4
4
  "description": "Schema Definition Language (SDL) for the entity graph — the shared contract every code generator (Rust CLI, Flutter, framework bindings) consumes.",
5
5
  "author": "Travis James <travis@prometheus.dev>",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
- "main": "./dist/index.cjs",
8
+ "main": "./dist/index.mjs",
9
9
  "module": "./dist/index.mjs",
10
10
  "types": "./dist/index.d.ts",
11
11
  "exports": {
12
12
  ".": {
13
- "import": {
14
- "types": "./dist/index.d.ts",
15
- "default": "./dist/index.mjs"
16
- },
17
- "require": {
18
- "types": "./dist/index.d.cts",
19
- "default": "./dist/index.cjs"
20
- }
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.mjs"
21
15
  }
22
16
  },
23
17
  "sideEffects": false,
@@ -29,6 +23,13 @@
29
23
  "publishConfig": {
30
24
  "access": "public"
31
25
  },
26
+ "scripts": {
27
+ "build": "tsup",
28
+ "typecheck": "tsc --noEmit -p tsconfig.json",
29
+ "test": "vitest run",
30
+ "refresh:exports": "pnpm run build && node ../../scripts/refresh-exports-ledger.mjs --pkg sdl",
31
+ "verify:skills": "node ../../scripts/verify-skills-exports.mjs --pkg sdl"
32
+ },
32
33
  "keywords": [
33
34
  "entity-graph",
34
35
  "schema",
@@ -46,12 +47,5 @@
46
47
  },
47
48
  "engines": {
48
49
  "node": "^22.14.0 || ^24.0.0 || >=26.0.0"
49
- },
50
- "scripts": {
51
- "build": "tsup",
52
- "typecheck": "tsc --noEmit -p tsconfig.json",
53
- "test": "vitest run",
54
- "refresh:exports": "pnpm run build && node ../../scripts/refresh-exports-ledger.mjs --pkg sdl",
55
- "verify:skills": "node ../../scripts/verify-skills-exports.mjs --pkg sdl"
56
50
  }
57
- }
51
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Travis James / Prometheus AGS / KnowMe LLC
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/dist/index.cjs DELETED
@@ -1,92 +0,0 @@
1
- 'use strict';
2
-
3
- // src/index.ts
4
- var SdlValidationError = class extends Error {
5
- path;
6
- constructor(message, path) {
7
- super(`${message} (at ${path})`);
8
- this.name = "SdlValidationError";
9
- this.path = path;
10
- }
11
- };
12
- var SCALAR_TYPES = /* @__PURE__ */ new Set([
13
- "string",
14
- "number",
15
- "integer",
16
- "decimal",
17
- "boolean",
18
- "datetime",
19
- "date",
20
- "json",
21
- "enum",
22
- "uuid"
23
- ]);
24
- function parseSdl(doc) {
25
- if (!isObject(doc)) throw new SdlValidationError("SDL root must be an object", "$");
26
- const version = typeof doc.version === "string" ? doc.version : "1.0";
27
- if (!isObject(doc.entities)) throw new SdlValidationError("`entities` must be an object", "$.entities");
28
- const entities = [];
29
- for (const [name, raw] of Object.entries(doc.entities)) {
30
- const path = `$.entities.${name}`;
31
- if (!isObject(raw) || !isObject(raw.fields)) {
32
- throw new SdlValidationError("entity must have a `fields` object", path);
33
- }
34
- const def = raw;
35
- const fields = [];
36
- let primaryKey = null;
37
- for (const [fname, fdefRaw] of Object.entries(def.fields)) {
38
- const fpath = `${path}.fields.${fname}`;
39
- if (!isObject(fdefRaw)) throw new SdlValidationError("field must be an object", fpath);
40
- const fdef = fdefRaw;
41
- if (!SCALAR_TYPES.has(fdef.type)) throw new SdlValidationError(`unknown field type "${fdef.type}"`, fpath);
42
- if (fdef.type === "enum" && (!Array.isArray(fdef.values) || fdef.values.length === 0)) {
43
- throw new SdlValidationError("enum field requires non-empty `values`", fpath);
44
- }
45
- if (fdef.primary) {
46
- if (primaryKey) throw new SdlValidationError("multiple primary keys not supported", fpath);
47
- primaryKey = fname;
48
- }
49
- fields.push({ ...fdef, name: fname });
50
- }
51
- if (!primaryKey) throw new SdlValidationError("entity needs exactly one `primary: true` field", path);
52
- const relations = [];
53
- for (const [rname, rdefRaw] of Object.entries(def.relations ?? {})) {
54
- const rpath = `${path}.relations.${rname}`;
55
- if (!isObject(rdefRaw)) throw new SdlValidationError("relation must be an object", rpath);
56
- const rdef = rdefRaw;
57
- if (!["belongsTo", "hasMany", "manyToMany"].includes(rdef.type)) {
58
- throw new SdlValidationError(`unknown relation type "${rdef.type}"`, rpath);
59
- }
60
- if (typeof rdef.target !== "string") throw new SdlValidationError("relation needs a `target`", rpath);
61
- relations.push({ ...rdef, name: rname });
62
- }
63
- entities.push({ name, table: def.table ?? name, primaryKey, fields, relations });
64
- }
65
- const names = new Set(entities.map((e) => e.name));
66
- for (const e of entities) {
67
- for (const r of e.relations) {
68
- if (!names.has(r.target)) {
69
- throw new SdlValidationError(`relation target "${r.target}" is not a defined entity`, `$.entities.${e.name}.relations.${r.name}`);
70
- }
71
- }
72
- }
73
- return { version, entities, config: doc.config ?? {} };
74
- }
75
- function parseSdlJson(json) {
76
- let doc;
77
- try {
78
- doc = JSON.parse(json);
79
- } catch (cause) {
80
- throw new SdlValidationError("invalid JSON", "$");
81
- }
82
- return parseSdl(doc);
83
- }
84
- function isObject(v) {
85
- return typeof v === "object" && v !== null && !Array.isArray(v);
86
- }
87
-
88
- exports.SdlValidationError = SdlValidationError;
89
- exports.parseSdl = parseSdl;
90
- exports.parseSdlJson = parseSdlJson;
91
- //# sourceMappingURL=index.cjs.map
92
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAwFO,IAAM,kBAAA,GAAN,cAAiC,KAAA,CAAM;AAAA,EACnC,IAAA;AAAA,EACT,WAAA,CAAY,SAAiB,IAAA,EAAc;AACzC,IAAA,KAAA,CAAM,CAAA,EAAG,OAAO,CAAA,KAAA,EAAQ,IAAI,CAAA,CAAA,CAAG,CAAA;AAC/B,IAAA,IAAA,CAAK,IAAA,GAAO,oBAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AACF;AAEA,IAAM,YAAA,uBAAmB,GAAA,CAAmB;AAAA,EAC1C,QAAA;AAAA,EAAU,QAAA;AAAA,EAAU,SAAA;AAAA,EAAW,SAAA;AAAA,EAAW,SAAA;AAAA,EAAW,UAAA;AAAA,EAAY,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ;AAC3F,CAAC,CAAA;AAMM,SAAS,SAAS,GAAA,EAA6B;AACpD,EAAA,IAAI,CAAC,SAAS,GAAG,CAAA,QAAS,IAAI,kBAAA,CAAmB,8BAA8B,GAAG,CAAA;AAClF,EAAA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/entity-graph-sdl\n *\n * The Schema Definition Language (SDL) for the entity graph: a stable JSON/TOML\n * schema format + a parser that produces a validated intermediate\n * representation (IR). Every code generator (Rust CLI, Flutter, framework\n * bindings) consumes the SAME IR so generated targets never diverge.\n *\n * Format (schema.json):\n * {\n * \"version\": \"1.0\",\n * \"entities\": {\n * \"user\": {\n * \"fields\": { \"id\": {\"type\":\"string\",\"primary\":true}, \"name\": {\"type\":\"string\",\"required\":true} },\n * \"relations\": { \"orders\": {\"type\":\"hasMany\",\"target\":\"order\",\"foreignKey\":\"userId\"} }\n * }\n * },\n * \"config\": { \"localFirst\": {\"engine\":\"pglite\",\"sync\":\"electric\"}, \"ai\": {\"mcp\":true,\"a2a\":true} }\n * }\n */\n\n// ── Source format types ───────────────────────────────────────────────────\n\nexport type SdlScalarType =\n | \"string\" | \"number\" | \"integer\" | \"decimal\" | \"boolean\"\n | \"datetime\" | \"date\" | \"json\" | \"enum\" | \"uuid\";\n\nexport interface SdlFieldDef {\n type: SdlScalarType;\n primary?: boolean;\n required?: boolean;\n unique?: boolean;\n default?: unknown;\n /** For enum fields. */\n values?: string[];\n /** Auto-managed by the store/server (e.g. createdAt). */\n auto?: boolean;\n}\n\nexport type SdlRelationKind = \"belongsTo\" | \"hasMany\" | \"manyToMany\";\n\nexport interface SdlRelationDef {\n type: SdlRelationKind;\n target: string;\n foreignKey?: string;\n /** For manyToMany. */\n through?: string;\n}\n\nexport interface SdlEntityDef {\n fields: Record<string, SdlFieldDef>;\n relations?: Record<string, SdlRelationDef>;\n /** Optional table name override (defaults to the entity key). */\n table?: string;\n}\n\nexport interface SdlConfig {\n localFirst?: { engine?: \"pglite\" | \"sqlite\" | \"none\"; sync?: \"electric\" | \"yjs\" | \"none\" };\n ai?: { mcp?: boolean; a2a?: boolean };\n}\n\nexport interface SdlDocument {\n version: string;\n entities: Record<string, SdlEntityDef>;\n config?: SdlConfig;\n}\n\n// ── Validated IR (what generators consume) ────────────────────────────────\n\nexport interface IrField extends SdlFieldDef {\n name: string;\n}\nexport interface IrRelation extends SdlRelationDef {\n name: string;\n}\nexport interface IrEntity {\n name: string;\n table: string;\n primaryKey: string;\n fields: IrField[];\n relations: IrRelation[];\n}\nexport interface EntityGraphIR {\n version: string;\n entities: IrEntity[];\n config: SdlConfig;\n}\n\nexport class SdlValidationError extends Error {\n readonly path: string;\n constructor(message: string, path: string) {\n super(`${message} (at ${path})`);\n this.name = \"SdlValidationError\";\n this.path = path;\n }\n}\n\nconst SCALAR_TYPES = new Set<SdlScalarType>([\n \"string\", \"number\", \"integer\", \"decimal\", \"boolean\", \"datetime\", \"date\", \"json\", \"enum\", \"uuid\",\n]);\n\n/**\n * Parse + validate an SDL document into the generator IR. Throws\n * {@link SdlValidationError} with a precise path on the first problem.\n */\nexport function parseSdl(doc: unknown): EntityGraphIR {\n if (!isObject(doc)) throw new SdlValidationError(\"SDL root must be an object\", \"$\");\n const version = typeof doc.version === \"string\" ? doc.version : \"1.0\";\n if (!isObject(doc.entities)) throw new SdlValidationError(\"`entities` must be an object\", \"$.entities\");\n\n const entities: IrEntity[] = [];\n for (const [name, raw] of Object.entries(doc.entities)) {\n const path = `$.entities.${name}`;\n if (!isObject(raw) || !isObject(raw.fields)) {\n throw new SdlValidationError(\"entity must have a `fields` object\", path);\n }\n const def = raw as unknown as SdlEntityDef;\n\n const fields: IrField[] = [];\n let primaryKey: string | null = null;\n for (const [fname, fdefRaw] of Object.entries(def.fields)) {\n const fpath = `${path}.fields.${fname}`;\n if (!isObject(fdefRaw)) throw new SdlValidationError(\"field must be an object\", fpath);\n const fdef = fdefRaw as SdlFieldDef;\n if (!SCALAR_TYPES.has(fdef.type)) throw new SdlValidationError(`unknown field type \"${fdef.type}\"`, fpath);\n if (fdef.type === \"enum\" && (!Array.isArray(fdef.values) || fdef.values.length === 0)) {\n throw new SdlValidationError(\"enum field requires non-empty `values`\", fpath);\n }\n if (fdef.primary) {\n if (primaryKey) throw new SdlValidationError(\"multiple primary keys not supported\", fpath);\n primaryKey = fname;\n }\n fields.push({ ...fdef, name: fname });\n }\n if (!primaryKey) throw new SdlValidationError(\"entity needs exactly one `primary: true` field\", path);\n\n const relations: IrRelation[] = [];\n for (const [rname, rdefRaw] of Object.entries(def.relations ?? {})) {\n const rpath = `${path}.relations.${rname}`;\n if (!isObject(rdefRaw)) throw new SdlValidationError(\"relation must be an object\", rpath);\n const rdef = rdefRaw as SdlRelationDef;\n if (![\"belongsTo\", \"hasMany\", \"manyToMany\"].includes(rdef.type)) {\n throw new SdlValidationError(`unknown relation type \"${rdef.type}\"`, rpath);\n }\n if (typeof rdef.target !== \"string\") throw new SdlValidationError(\"relation needs a `target`\", rpath);\n relations.push({ ...rdef, name: rname });\n }\n\n entities.push({ name, table: def.table ?? name, primaryKey, fields, relations });\n }\n\n // Cross-reference relation targets.\n const names = new Set(entities.map((e) => e.name));\n for (const e of entities) {\n for (const r of e.relations) {\n if (!names.has(r.target)) {\n throw new SdlValidationError(`relation target \"${r.target}\" is not a defined entity`, `$.entities.${e.name}.relations.${r.name}`);\n }\n }\n }\n\n return { version, entities, config: (doc.config as SdlConfig) ?? {} };\n}\n\n/** Parse SDL from a JSON string. */\nexport function parseSdlJson(json: string): EntityGraphIR {\n let doc: unknown;\n try { doc = JSON.parse(json); } catch (cause) {\n throw new SdlValidationError(\"invalid JSON\", \"$\");\n }\n return parseSdl(doc);\n}\n\nfunction isObject(v: unknown): v is Record<string, unknown> {\n return typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n"]}
package/dist/index.d.cts DELETED
@@ -1,92 +0,0 @@
1
- /**
2
- * @prometheus-ags/entity-graph-sdl
3
- *
4
- * The Schema Definition Language (SDL) for the entity graph: a stable JSON/TOML
5
- * schema format + a parser that produces a validated intermediate
6
- * representation (IR). Every code generator (Rust CLI, Flutter, framework
7
- * bindings) consumes the SAME IR so generated targets never diverge.
8
- *
9
- * Format (schema.json):
10
- * {
11
- * "version": "1.0",
12
- * "entities": {
13
- * "user": {
14
- * "fields": { "id": {"type":"string","primary":true}, "name": {"type":"string","required":true} },
15
- * "relations": { "orders": {"type":"hasMany","target":"order","foreignKey":"userId"} }
16
- * }
17
- * },
18
- * "config": { "localFirst": {"engine":"pglite","sync":"electric"}, "ai": {"mcp":true,"a2a":true} }
19
- * }
20
- */
21
- type SdlScalarType = "string" | "number" | "integer" | "decimal" | "boolean" | "datetime" | "date" | "json" | "enum" | "uuid";
22
- interface SdlFieldDef {
23
- type: SdlScalarType;
24
- primary?: boolean;
25
- required?: boolean;
26
- unique?: boolean;
27
- default?: unknown;
28
- /** For enum fields. */
29
- values?: string[];
30
- /** Auto-managed by the store/server (e.g. createdAt). */
31
- auto?: boolean;
32
- }
33
- type SdlRelationKind = "belongsTo" | "hasMany" | "manyToMany";
34
- interface SdlRelationDef {
35
- type: SdlRelationKind;
36
- target: string;
37
- foreignKey?: string;
38
- /** For manyToMany. */
39
- through?: string;
40
- }
41
- interface SdlEntityDef {
42
- fields: Record<string, SdlFieldDef>;
43
- relations?: Record<string, SdlRelationDef>;
44
- /** Optional table name override (defaults to the entity key). */
45
- table?: string;
46
- }
47
- interface SdlConfig {
48
- localFirst?: {
49
- engine?: "pglite" | "sqlite" | "none";
50
- sync?: "electric" | "yjs" | "none";
51
- };
52
- ai?: {
53
- mcp?: boolean;
54
- a2a?: boolean;
55
- };
56
- }
57
- interface SdlDocument {
58
- version: string;
59
- entities: Record<string, SdlEntityDef>;
60
- config?: SdlConfig;
61
- }
62
- interface IrField extends SdlFieldDef {
63
- name: string;
64
- }
65
- interface IrRelation extends SdlRelationDef {
66
- name: string;
67
- }
68
- interface IrEntity {
69
- name: string;
70
- table: string;
71
- primaryKey: string;
72
- fields: IrField[];
73
- relations: IrRelation[];
74
- }
75
- interface EntityGraphIR {
76
- version: string;
77
- entities: IrEntity[];
78
- config: SdlConfig;
79
- }
80
- declare class SdlValidationError extends Error {
81
- readonly path: string;
82
- constructor(message: string, path: string);
83
- }
84
- /**
85
- * Parse + validate an SDL document into the generator IR. Throws
86
- * {@link SdlValidationError} with a precise path on the first problem.
87
- */
88
- declare function parseSdl(doc: unknown): EntityGraphIR;
89
- /** Parse SDL from a JSON string. */
90
- declare function parseSdlJson(json: string): EntityGraphIR;
91
-
92
- export { type EntityGraphIR, type IrEntity, type IrField, type IrRelation, type SdlConfig, type SdlDocument, type SdlEntityDef, type SdlFieldDef, type SdlRelationDef, type SdlRelationKind, type SdlScalarType, SdlValidationError, parseSdl, parseSdlJson };