@astrale-os/kernel-dsl 0.1.0
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/builders/bitmask.d.ts +5 -0
- package/dist/builders/bitmask.d.ts.map +1 -0
- package/dist/builders/bitmask.js +11 -0
- package/dist/builders/data.d.ts +7 -0
- package/dist/builders/data.d.ts.map +1 -0
- package/dist/builders/data.js +17 -0
- package/dist/builders/definition/base.d.ts +13 -0
- package/dist/builders/definition/base.d.ts.map +1 -0
- package/dist/builders/definition/base.js +23 -0
- package/dist/builders/definition/edge-class.d.ts +8 -0
- package/dist/builders/definition/edge-class.d.ts.map +1 -0
- package/dist/builders/definition/edge-class.js +8 -0
- package/dist/builders/definition/edge-interface.d.ts +8 -0
- package/dist/builders/definition/edge-interface.d.ts.map +1 -0
- package/dist/builders/definition/edge-interface.js +8 -0
- package/dist/builders/definition/index.d.ts +5 -0
- package/dist/builders/definition/index.d.ts.map +1 -0
- package/dist/builders/definition/index.js +4 -0
- package/dist/builders/definition/node-class.d.ts +7 -0
- package/dist/builders/definition/node-class.d.ts.map +1 -0
- package/dist/builders/definition/node-class.js +8 -0
- package/dist/builders/definition/node-interface.d.ts +7 -0
- package/dist/builders/definition/node-interface.d.ts.map +1 -0
- package/dist/builders/definition/node-interface.js +8 -0
- package/dist/builders/function.d.ts +14 -0
- package/dist/builders/function.d.ts.map +1 -0
- package/dist/builders/function.js +4 -0
- package/dist/builders/index.d.ts +10 -0
- package/dist/builders/index.d.ts.map +1 -0
- package/dist/builders/index.js +9 -0
- package/dist/builders/prop.d.ts +7 -0
- package/dist/builders/prop.d.ts.map +1 -0
- package/dist/builders/prop.js +8 -0
- package/dist/builders/ref.d.ts +12 -0
- package/dist/builders/ref.d.ts.map +1 -0
- package/dist/builders/ref.js +26 -0
- package/dist/grammar/definition/base.d.ts +13 -0
- package/dist/grammar/definition/base.d.ts.map +1 -0
- package/dist/grammar/definition/base.js +1 -0
- package/dist/grammar/definition/discriminants.d.ts +31 -0
- package/dist/grammar/definition/discriminants.d.ts.map +1 -0
- package/dist/grammar/definition/discriminants.js +32 -0
- package/dist/grammar/definition/edge-class.d.ts +19 -0
- package/dist/grammar/definition/edge-class.d.ts.map +1 -0
- package/dist/grammar/definition/edge-class.js +1 -0
- package/dist/grammar/definition/edge-interface.d.ts +18 -0
- package/dist/grammar/definition/edge-interface.d.ts.map +1 -0
- package/dist/grammar/definition/edge-interface.js +1 -0
- package/dist/grammar/definition/index.d.ts +8 -0
- package/dist/grammar/definition/index.d.ts.map +1 -0
- package/dist/grammar/definition/index.js +1 -0
- package/dist/grammar/definition/node-class.d.ts +21 -0
- package/dist/grammar/definition/node-class.d.ts.map +1 -0
- package/dist/grammar/definition/node-class.js +1 -0
- package/dist/grammar/definition/node-interface.d.ts +14 -0
- package/dist/grammar/definition/node-interface.d.ts.map +1 -0
- package/dist/grammar/definition/node-interface.js +1 -0
- package/dist/grammar/facets/constraints.d.ts +8 -0
- package/dist/grammar/facets/constraints.d.ts.map +1 -0
- package/dist/grammar/facets/constraints.js +1 -0
- package/dist/grammar/facets/content.d.ts +4 -0
- package/dist/grammar/facets/content.d.ts.map +1 -0
- package/dist/grammar/facets/content.js +1 -0
- package/dist/grammar/facets/endpoints.d.ts +14 -0
- package/dist/grammar/facets/endpoints.d.ts.map +1 -0
- package/dist/grammar/facets/endpoints.js +2 -0
- package/dist/grammar/facets/index.d.ts +9 -0
- package/dist/grammar/facets/index.d.ts.map +1 -0
- package/dist/grammar/facets/index.js +3 -0
- package/dist/grammar/facets/indexes.d.ts +12 -0
- package/dist/grammar/facets/indexes.d.ts.map +1 -0
- package/dist/grammar/facets/indexes.js +8 -0
- package/dist/grammar/facets/properties.d.ts +26 -0
- package/dist/grammar/facets/properties.d.ts.map +1 -0
- package/dist/grammar/facets/properties.js +44 -0
- package/dist/grammar/function/config.d.ts +14 -0
- package/dist/grammar/function/config.d.ts.map +1 -0
- package/dist/grammar/function/config.js +1 -0
- package/dist/grammar/function/def.d.ts +33 -0
- package/dist/grammar/function/def.d.ts.map +1 -0
- package/dist/grammar/function/def.js +1 -0
- package/dist/grammar/function/index.d.ts +5 -0
- package/dist/grammar/function/index.d.ts.map +1 -0
- package/dist/grammar/function/index.js +1 -0
- package/dist/grammar/function/inheritance.d.ts +3 -0
- package/dist/grammar/function/inheritance.d.ts.map +1 -0
- package/dist/grammar/function/inheritance.js +1 -0
- package/dist/grammar/function/output.d.ts +3 -0
- package/dist/grammar/function/output.d.ts.map +1 -0
- package/dist/grammar/function/output.js +1 -0
- package/dist/grammar/index.d.ts +5 -0
- package/dist/grammar/index.d.ts.map +1 -0
- package/dist/grammar/index.js +4 -0
- package/dist/grammar/values/bitmask.d.ts +7 -0
- package/dist/grammar/values/bitmask.d.ts.map +1 -0
- package/dist/grammar/values/bitmask.js +1 -0
- package/dist/grammar/values/data.d.ts +30 -0
- package/dist/grammar/values/data.d.ts.map +1 -0
- package/dist/grammar/values/data.js +1 -0
- package/dist/grammar/values/index.d.ts +9 -0
- package/dist/grammar/values/index.d.ts.map +1 -0
- package/dist/grammar/values/index.js +4 -0
- package/dist/grammar/values/ref.d.ts +26 -0
- package/dist/grammar/values/ref.d.ts.map +1 -0
- package/dist/grammar/values/ref.js +1 -0
- package/dist/grammar/values/self.d.ts +12 -0
- package/dist/grammar/values/self.d.ts.map +1 -0
- package/dist/grammar/values/self.js +5 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/inference/content.d.ts +27 -0
- package/dist/inference/content.d.ts.map +1 -0
- package/dist/inference/content.js +1 -0
- package/dist/inference/index.d.ts +7 -0
- package/dist/inference/index.d.ts.map +1 -0
- package/dist/inference/index.js +1 -0
- package/dist/inference/inheritance.d.ts +48 -0
- package/dist/inference/inheritance.d.ts.map +1 -0
- package/dist/inference/inheritance.js +1 -0
- package/dist/inference/input.d.ts +30 -0
- package/dist/inference/input.d.ts.map +1 -0
- package/dist/inference/input.js +1 -0
- package/dist/inference/methods.d.ts +69 -0
- package/dist/inference/methods.d.ts.map +1 -0
- package/dist/inference/methods.js +1 -0
- package/dist/inference/properties.d.ts +37 -0
- package/dist/inference/properties.d.ts.map +1 -0
- package/dist/inference/properties.js +1 -0
- package/dist/inference/schema.d.ts +37 -0
- package/dist/inference/schema.d.ts.map +1 -0
- package/dist/inference/schema.js +1 -0
- package/dist/instance/core/define.d.ts +13 -0
- package/dist/instance/core/define.d.ts.map +1 -0
- package/dist/instance/core/define.js +62 -0
- package/dist/instance/core/edge.d.ts +9 -0
- package/dist/instance/core/edge.d.ts.map +1 -0
- package/dist/instance/core/edge.js +10 -0
- package/dist/instance/core/endpoint.d.ts +11 -0
- package/dist/instance/core/endpoint.d.ts.map +1 -0
- package/dist/instance/core/endpoint.js +18 -0
- package/dist/instance/core/index.d.ts +7 -0
- package/dist/instance/core/index.d.ts.map +1 -0
- package/dist/instance/core/index.js +5 -0
- package/dist/instance/core/node.d.ts +7 -0
- package/dist/instance/core/node.d.ts.map +1 -0
- package/dist/instance/core/node.js +8 -0
- package/dist/instance/core/path.d.ts +21 -0
- package/dist/instance/core/path.d.ts.map +1 -0
- package/dist/instance/core/path.js +20 -0
- package/dist/instance/core/self.d.ts +15 -0
- package/dist/instance/core/self.d.ts.map +1 -0
- package/dist/instance/core/self.js +7 -0
- package/dist/instance/core/types.d.ts +45 -0
- package/dist/instance/core/types.d.ts.map +1 -0
- package/dist/instance/core/types.js +1 -0
- package/dist/instance/index.d.ts +4 -0
- package/dist/instance/index.d.ts.map +1 -0
- package/dist/instance/index.js +2 -0
- package/dist/instance/seed/define.d.ts +12 -0
- package/dist/instance/seed/define.d.ts.map +1 -0
- package/dist/instance/seed/define.js +33 -0
- package/dist/instance/seed/index.d.ts +3 -0
- package/dist/instance/seed/index.d.ts.map +1 -0
- package/dist/instance/seed/index.js +1 -0
- package/dist/instance/seed/types.d.ts +12 -0
- package/dist/instance/seed/types.d.ts.map +1 -0
- package/dist/instance/seed/types.js +1 -0
- package/dist/ir/classes.d.ts +72 -0
- package/dist/ir/classes.d.ts.map +1 -0
- package/dist/ir/classes.js +1 -0
- package/dist/ir/domain.d.ts +13 -0
- package/dist/ir/domain.d.ts.map +1 -0
- package/dist/ir/domain.js +1 -0
- package/dist/ir/endpoints.d.ts +27 -0
- package/dist/ir/endpoints.d.ts.map +1 -0
- package/dist/ir/endpoints.js +1 -0
- package/dist/ir/functions.d.ts +19 -0
- package/dist/ir/functions.d.ts.map +1 -0
- package/dist/ir/functions.js +1 -0
- package/dist/ir/index.d.ts +8 -0
- package/dist/ir/index.d.ts.map +1 -0
- package/dist/ir/index.js +1 -0
- package/dist/ir/ir.d.ts +63 -0
- package/dist/ir/ir.d.ts.map +1 -0
- package/dist/ir/ir.js +4 -0
- package/dist/ir/json-schema.d.ts +20 -0
- package/dist/ir/json-schema.d.ts.map +1 -0
- package/dist/ir/json-schema.js +1 -0
- package/dist/schema/classify.d.ts +8 -0
- package/dist/schema/classify.d.ts.map +1 -0
- package/dist/schema/classify.js +19 -0
- package/dist/schema/define.d.ts +19 -0
- package/dist/schema/define.d.ts.map +1 -0
- package/dist/schema/define.js +47 -0
- package/dist/schema/error.d.ts +8 -0
- package/dist/schema/error.d.ts.map +1 -0
- package/dist/schema/error.js +13 -0
- package/dist/schema/index.d.ts +8 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/refs.d.ts +80 -0
- package/dist/schema/refs.d.ts.map +1 -0
- package/dist/schema/refs.js +116 -0
- package/dist/schema/resolve/index.d.ts +5 -0
- package/dist/schema/resolve/index.d.ts.map +1 -0
- package/dist/schema/resolve/index.js +4 -0
- package/dist/schema/resolve/methods.d.ts +8 -0
- package/dist/schema/resolve/methods.d.ts.map +1 -0
- package/dist/schema/resolve/methods.js +17 -0
- package/dist/schema/resolve/properties.d.ts +13 -0
- package/dist/schema/resolve/properties.d.ts.map +1 -0
- package/dist/schema/resolve/properties.js +36 -0
- package/dist/schema/resolve/self.d.ts +7 -0
- package/dist/schema/resolve/self.d.ts.map +1 -0
- package/dist/schema/resolve/self.js +32 -0
- package/dist/schema/resolve/thunks.d.ts +12 -0
- package/dist/schema/resolve/thunks.d.ts.map +1 -0
- package/dist/schema/resolve/thunks.js +36 -0
- package/dist/schema/schema.d.ts +21 -0
- package/dist/schema/schema.d.ts.map +1 -0
- package/dist/schema/schema.js +1 -0
- package/dist/schema/validators/context.d.ts +13 -0
- package/dist/schema/validators/context.d.ts.map +1 -0
- package/dist/schema/validators/context.js +1 -0
- package/dist/schema/validators/endpoints.d.ts +4 -0
- package/dist/schema/validators/endpoints.d.ts.map +1 -0
- package/dist/schema/validators/endpoints.js +26 -0
- package/dist/schema/validators/index.d.ts +11 -0
- package/dist/schema/validators/index.d.ts.map +1 -0
- package/dist/schema/validators/index.js +21 -0
- package/dist/schema/validators/indexes.d.ts +4 -0
- package/dist/schema/validators/indexes.d.ts.map +1 -0
- package/dist/schema/validators/indexes.js +18 -0
- package/dist/schema/validators/inheritance.d.ts +4 -0
- package/dist/schema/validators/inheritance.d.ts.map +1 -0
- package/dist/schema/validators/inheritance.js +26 -0
- package/dist/schema/validators/methods.d.ts +9 -0
- package/dist/schema/validators/methods.d.ts.map +1 -0
- package/dist/schema/validators/methods.js +43 -0
- package/dist/schema/validators/names.d.ts +4 -0
- package/dist/schema/validators/names.d.ts.map +1 -0
- package/dist/schema/validators/names.js +18 -0
- package/dist/schema/validators/ref-targets.d.ts +4 -0
- package/dist/schema/validators/ref-targets.d.ts.map +1 -0
- package/dist/schema/validators/ref-targets.js +53 -0
- package/dist/serializer/context.d.ts +32 -0
- package/dist/serializer/context.d.ts.map +1 -0
- package/dist/serializer/context.js +308 -0
- package/dist/serializer/helpers.d.ts +34 -0
- package/dist/serializer/helpers.d.ts.map +1 -0
- package/dist/serializer/helpers.js +115 -0
- package/dist/serializer/index.d.ts +2 -0
- package/dist/serializer/index.d.ts.map +1 -0
- package/dist/serializer/index.js +1 -0
- package/dist/serializer/serialize.d.ts +12 -0
- package/dist/serializer/serialize.d.ts.map +1 -0
- package/dist/serializer/serialize.js +5 -0
- package/package.json +45 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SchemaValidationError } from '../error.js';
|
|
2
|
+
import { eachDef, isKnownDef } from '../refs.js';
|
|
3
|
+
// Runtime symbol
|
|
4
|
+
const REF_TAG_RUNTIME = Symbol.for('REF_TAG');
|
|
5
|
+
/** Extract all ref targets from a Zod schema tree */
|
|
6
|
+
function extractRefTargets(schema) {
|
|
7
|
+
if (schema === null || typeof schema !== 'object')
|
|
8
|
+
return [];
|
|
9
|
+
const targets = [];
|
|
10
|
+
const record = schema;
|
|
11
|
+
// Check for our REF_TAG brand
|
|
12
|
+
if (REF_TAG_RUNTIME in record) {
|
|
13
|
+
const meta = record[REF_TAG_RUNTIME];
|
|
14
|
+
if (meta.target && typeof meta.target === 'object') {
|
|
15
|
+
targets.push(meta.target);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// Walk into Zod internals to find nested refs
|
|
19
|
+
const zod = record;
|
|
20
|
+
const inner = zod.element ?? zod.innerType ?? zod._def?.innerType ?? zod._def?.type;
|
|
21
|
+
if (inner && typeof inner === 'object') {
|
|
22
|
+
targets.push(...extractRefTargets(inner));
|
|
23
|
+
}
|
|
24
|
+
return targets;
|
|
25
|
+
}
|
|
26
|
+
/** Validate that all ref() targets in params/returns point to known definitions */
|
|
27
|
+
export function validateRefTargets(ctx) {
|
|
28
|
+
const validateFnRefs = (path, fnDef) => {
|
|
29
|
+
const params = fnDef.config.params;
|
|
30
|
+
if (params && typeof params === 'object' && typeof params !== 'function') {
|
|
31
|
+
for (const [paramName, paramSchema] of Object.entries(params)) {
|
|
32
|
+
for (const target of extractRefTargets(paramSchema)) {
|
|
33
|
+
if (!isKnownDef(target, ctx.descriptorMap)) {
|
|
34
|
+
throw new SchemaValidationError(`'${path}' param '${paramName}' references an unknown def`, `${path}.params.${paramName}`, 'a def in this schema or imported', 'unknown reference');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const target of extractRefTargets(fnDef.config.returns)) {
|
|
40
|
+
if (!isKnownDef(target, ctx.descriptorMap)) {
|
|
41
|
+
throw new SchemaValidationError(`'${path}' return type references an unknown def`, `${path}.returns`, 'a def in this schema or imported', 'unknown reference');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
for (const [name, def] of eachDef(ctx.interfaces, ctx.classes)) {
|
|
46
|
+
const methods = def.config.methods;
|
|
47
|
+
if (!methods)
|
|
48
|
+
continue;
|
|
49
|
+
for (const [methodName, methodDef] of Object.entries(methods)) {
|
|
50
|
+
validateFnRefs(`${name}.${methodName}`, methodDef);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { SchemaIR } from '../ir/index.js';
|
|
3
|
+
import type { Schema } from '../schema/schema.js';
|
|
4
|
+
export declare class SerializeContext {
|
|
5
|
+
private schema;
|
|
6
|
+
private descriptorMap;
|
|
7
|
+
private importedMaps;
|
|
8
|
+
private zodToTypeName;
|
|
9
|
+
private types;
|
|
10
|
+
private imports;
|
|
11
|
+
constructor(schema: Schema, options?: {
|
|
12
|
+
types?: Record<string, z.ZodType>;
|
|
13
|
+
});
|
|
14
|
+
run(): SchemaIR;
|
|
15
|
+
private serializeInterface;
|
|
16
|
+
private serializeNode;
|
|
17
|
+
private serializeEdge;
|
|
18
|
+
private resolveInherits;
|
|
19
|
+
private serializeEndpoint;
|
|
20
|
+
private serializeConstraints;
|
|
21
|
+
private serializeProperties;
|
|
22
|
+
private serializePropertySchema;
|
|
23
|
+
private serializeMethods;
|
|
24
|
+
private serializeFn;
|
|
25
|
+
private serializeParams;
|
|
26
|
+
private convertZodSchema;
|
|
27
|
+
private zodToJsonSchemaRaw;
|
|
28
|
+
private serializeData;
|
|
29
|
+
private buildNodeRef;
|
|
30
|
+
private getDefName;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/serializer/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAQvB,OAAO,KAAK,EACV,QAAQ,EAUT,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAkBjD,qBAAa,gBAAgB;IAQzB,OAAO,CAAC,MAAM;IAPhB,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,YAAY,CAAiE;IACrF,OAAO,CAAC,aAAa,CAAmC;IACxD,OAAO,CAAC,KAAK,CAAiC;IAC9C,OAAO,CAAC,OAAO,CAAuC;IAEtD,YACU,MAAM,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;KAAE,EAkBhD;IAED,GAAG,IAAI,QAAQ,CA6Bd;IAED,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,aAAa;IAkBrB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,oBAAoB;IAyB5B,OAAO,CAAC,mBAAmB;IAc3B,OAAO,CAAC,uBAAuB;IAQ/B,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAC,WAAW;IAgBnB,OAAO,CAAC,eAAe;IAiCvB,OAAO,CAAC,gBAAgB;IAyBxB,OAAO,CAAC,kBAAkB;IAS1B,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,UAAU;CA0CnB"}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isEdge } from '../grammar/definition/discriminants.js';
|
|
3
|
+
import { normalizeProperty } from '../grammar/facets/properties.js';
|
|
4
|
+
import { buildDescriptorMap, findDefTransitive } from '../schema/refs.js';
|
|
5
|
+
import { unwrapZod, getArrayElement, foldNullable, mapCardinality, hasRefTag, getRefMeta, getDataMeta, hasBitmaskTag, cleanJsonSchema, } from './helpers.js';
|
|
6
|
+
export class SerializeContext {
|
|
7
|
+
schema;
|
|
8
|
+
descriptorMap;
|
|
9
|
+
importedMaps = [];
|
|
10
|
+
zodToTypeName = new WeakMap();
|
|
11
|
+
types = {};
|
|
12
|
+
imports = {};
|
|
13
|
+
constructor(schema, options) {
|
|
14
|
+
this.schema = schema;
|
|
15
|
+
this.descriptorMap = buildDescriptorMap(schema);
|
|
16
|
+
for (const imported of schema.imports ?? []) {
|
|
17
|
+
const importedMap = buildDescriptorMap(imported);
|
|
18
|
+
this.importedMaps.push({ origin: imported.domain, map: importedMap });
|
|
19
|
+
for (const [def, descriptor] of importedMap) {
|
|
20
|
+
this.descriptorMap.set(def, descriptor);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (options?.types) {
|
|
24
|
+
for (const [name, zodSchema] of Object.entries(options.types)) {
|
|
25
|
+
this.zodToTypeName.set(zodSchema, name);
|
|
26
|
+
this.types[name] = this.zodToJsonSchemaRaw(zodSchema);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
run() {
|
|
31
|
+
const interfaces = {};
|
|
32
|
+
const classes = {};
|
|
33
|
+
for (const [name, def] of Object.entries(this.schema.interfaces)) {
|
|
34
|
+
interfaces[name] = this.serializeInterface(name, def);
|
|
35
|
+
}
|
|
36
|
+
for (const [name, def] of Object.entries(this.schema.classes)) {
|
|
37
|
+
if (isEdge(def)) {
|
|
38
|
+
classes[name] = this.serializeEdge(name, def);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
classes[name] = this.serializeNode(name, def);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const result = {
|
|
45
|
+
version: '1.0',
|
|
46
|
+
domain: this.schema.domain,
|
|
47
|
+
types: this.types,
|
|
48
|
+
interfaces,
|
|
49
|
+
classes,
|
|
50
|
+
};
|
|
51
|
+
if (Object.keys(this.imports).length > 0) {
|
|
52
|
+
result.imports = this.imports;
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
serializeInterface(name, def) {
|
|
57
|
+
const { config } = def;
|
|
58
|
+
const result = {
|
|
59
|
+
type: 'interface',
|
|
60
|
+
name,
|
|
61
|
+
extends: this.resolveInherits(config),
|
|
62
|
+
properties: this.serializeProperties(config.properties),
|
|
63
|
+
methods: this.serializeMethods(config.methods, name),
|
|
64
|
+
};
|
|
65
|
+
const content = config.content;
|
|
66
|
+
const data = this.serializeData(content);
|
|
67
|
+
if (data)
|
|
68
|
+
result.data = data;
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
serializeNode(name, def) {
|
|
72
|
+
const { config } = def;
|
|
73
|
+
const result = {
|
|
74
|
+
type: 'node',
|
|
75
|
+
name,
|
|
76
|
+
implements: this.resolveInherits(config),
|
|
77
|
+
properties: this.serializeProperties(config.properties),
|
|
78
|
+
methods: this.serializeMethods(config.methods, name),
|
|
79
|
+
};
|
|
80
|
+
const content = config.content;
|
|
81
|
+
const data = this.serializeData(content);
|
|
82
|
+
if (data)
|
|
83
|
+
result.data = data;
|
|
84
|
+
const icon = config.icon;
|
|
85
|
+
if (typeof icon === 'string' && icon.length > 0)
|
|
86
|
+
result.icon = icon;
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
serializeEdge(name, def) {
|
|
90
|
+
const { config } = def;
|
|
91
|
+
const edgeDef = def;
|
|
92
|
+
const result = {
|
|
93
|
+
type: 'edge',
|
|
94
|
+
name,
|
|
95
|
+
implements: this.resolveInherits(config),
|
|
96
|
+
endpoints: [this.serializeEndpoint(edgeDef.from), this.serializeEndpoint(edgeDef.to)],
|
|
97
|
+
properties: this.serializeProperties(config.properties),
|
|
98
|
+
methods: this.serializeMethods(config.methods, name),
|
|
99
|
+
};
|
|
100
|
+
const constraints = this.serializeConstraints(config.constraints);
|
|
101
|
+
if (constraints)
|
|
102
|
+
result.constraints = constraints;
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
resolveInherits(config) {
|
|
106
|
+
const inherits = config.inherits;
|
|
107
|
+
if (!inherits)
|
|
108
|
+
return [];
|
|
109
|
+
return inherits.map((e) => this.getDefName(e));
|
|
110
|
+
}
|
|
111
|
+
serializeEndpoint(endpoint) {
|
|
112
|
+
const result = {
|
|
113
|
+
name: endpoint.as,
|
|
114
|
+
types: endpoint.types.map((t) => this.getDefName(t)),
|
|
115
|
+
};
|
|
116
|
+
if (endpoint.cardinality) {
|
|
117
|
+
const mapped = mapCardinality(endpoint.cardinality);
|
|
118
|
+
if (mapped)
|
|
119
|
+
result.cardinality = mapped;
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
serializeConstraints(constraints) {
|
|
124
|
+
if (!constraints)
|
|
125
|
+
return undefined;
|
|
126
|
+
const c = {};
|
|
127
|
+
let has = false;
|
|
128
|
+
if (constraints.unique) {
|
|
129
|
+
c.unique = true;
|
|
130
|
+
has = true;
|
|
131
|
+
}
|
|
132
|
+
if (constraints.noSelf) {
|
|
133
|
+
c.noSelf = true;
|
|
134
|
+
has = true;
|
|
135
|
+
}
|
|
136
|
+
if (constraints.acyclic) {
|
|
137
|
+
c.acyclic = true;
|
|
138
|
+
has = true;
|
|
139
|
+
}
|
|
140
|
+
if (constraints.symmetric) {
|
|
141
|
+
c.symmetric = true;
|
|
142
|
+
has = true;
|
|
143
|
+
}
|
|
144
|
+
return has ? c : undefined;
|
|
145
|
+
}
|
|
146
|
+
serializeProperties(attrs) {
|
|
147
|
+
if (!attrs)
|
|
148
|
+
return {};
|
|
149
|
+
const result = {};
|
|
150
|
+
for (const [name, input] of Object.entries(attrs)) {
|
|
151
|
+
const normalized = normalizeProperty(input);
|
|
152
|
+
const decl = this.serializePropertySchema(normalized.schema);
|
|
153
|
+
if (normalized.private)
|
|
154
|
+
decl.private = true;
|
|
155
|
+
result[name] = decl;
|
|
156
|
+
}
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
serializePropertySchema(schema) {
|
|
160
|
+
const { inner, nullable, defaultValue, hasDefault } = unwrapZod(schema);
|
|
161
|
+
let jsonSchema = this.convertZodSchema(inner);
|
|
162
|
+
if (nullable)
|
|
163
|
+
jsonSchema = foldNullable(jsonSchema);
|
|
164
|
+
if (hasDefault)
|
|
165
|
+
jsonSchema = { ...jsonSchema, default: defaultValue };
|
|
166
|
+
return jsonSchema;
|
|
167
|
+
}
|
|
168
|
+
serializeMethods(methods, _className) {
|
|
169
|
+
if (!methods)
|
|
170
|
+
return {};
|
|
171
|
+
const result = {};
|
|
172
|
+
for (const [name, def] of Object.entries(methods)) {
|
|
173
|
+
result[name] = this.serializeFn(name, def);
|
|
174
|
+
}
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
serializeFn(name, def) {
|
|
178
|
+
const { config } = def;
|
|
179
|
+
const { inner: returnInner, nullable: returnNullable } = unwrapZod(config.returns);
|
|
180
|
+
const fn = {
|
|
181
|
+
name,
|
|
182
|
+
params: this.serializeParams(config.params),
|
|
183
|
+
returns: this.convertZodSchema(returnInner),
|
|
184
|
+
static: config.static ?? false,
|
|
185
|
+
inheritance: config.inheritance ?? 'default',
|
|
186
|
+
};
|
|
187
|
+
if (returnNullable)
|
|
188
|
+
fn.returnsNullable = true;
|
|
189
|
+
if (config.output && config.output !== 'value')
|
|
190
|
+
fn.output = config.output;
|
|
191
|
+
return fn;
|
|
192
|
+
}
|
|
193
|
+
serializeParams(params) {
|
|
194
|
+
if (!params)
|
|
195
|
+
return {};
|
|
196
|
+
const resolved = typeof params === 'function' ? params() : params;
|
|
197
|
+
const result = {};
|
|
198
|
+
for (const [name, schema] of Object.entries(resolved)) {
|
|
199
|
+
const zodSchema = schema;
|
|
200
|
+
if (hasRefTag(zodSchema)) {
|
|
201
|
+
result[name] = this.buildNodeRef(zodSchema);
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const { inner, nullable, defaultValue, hasDefault } = unwrapZod(zodSchema);
|
|
205
|
+
if (hasRefTag(inner)) {
|
|
206
|
+
let refSchema = this.buildNodeRef(inner);
|
|
207
|
+
if (nullable)
|
|
208
|
+
refSchema = foldNullable(refSchema);
|
|
209
|
+
if (hasDefault)
|
|
210
|
+
refSchema = { ...refSchema, default: defaultValue };
|
|
211
|
+
result[name] = refSchema;
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
let jsonSchema = this.convertZodSchema(inner);
|
|
215
|
+
if (nullable)
|
|
216
|
+
jsonSchema = foldNullable(jsonSchema);
|
|
217
|
+
if (hasDefault)
|
|
218
|
+
jsonSchema = { ...jsonSchema, default: defaultValue };
|
|
219
|
+
result[name] = jsonSchema;
|
|
220
|
+
}
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
convertZodSchema(schema) {
|
|
224
|
+
if (hasRefTag(schema))
|
|
225
|
+
return this.buildNodeRef(schema);
|
|
226
|
+
const dataMeta = getDataMeta(schema);
|
|
227
|
+
if (dataMeta) {
|
|
228
|
+
if (dataMeta.kind === 'self')
|
|
229
|
+
return { $dataRef: 'self' };
|
|
230
|
+
return { $dataRef: this.getDefName(dataMeta.target) };
|
|
231
|
+
}
|
|
232
|
+
if (hasBitmaskTag(schema))
|
|
233
|
+
return { type: 'integer', format: 'bitmask' };
|
|
234
|
+
const typeName = this.zodToTypeName.get(schema);
|
|
235
|
+
if (typeName)
|
|
236
|
+
return { $ref: `#/types/${typeName}` };
|
|
237
|
+
const element = getArrayElement(schema);
|
|
238
|
+
if (element) {
|
|
239
|
+
const itemSchema = this.convertZodSchema(element);
|
|
240
|
+
if (itemSchema.$nodeRef || itemSchema.$dataRef || itemSchema.$ref) {
|
|
241
|
+
return { type: 'array', items: itemSchema };
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return this.zodToJsonSchemaRaw(schema);
|
|
245
|
+
}
|
|
246
|
+
zodToJsonSchemaRaw(schema) {
|
|
247
|
+
try {
|
|
248
|
+
const result = z.toJSONSchema(schema);
|
|
249
|
+
return cleanJsonSchema(result);
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
return {};
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
serializeData(data) {
|
|
256
|
+
if (!data || Object.keys(data).length === 0)
|
|
257
|
+
return undefined;
|
|
258
|
+
const objectSchema = z.object(data);
|
|
259
|
+
const result = z.toJSONSchema(objectSchema);
|
|
260
|
+
return cleanJsonSchema(result);
|
|
261
|
+
}
|
|
262
|
+
buildNodeRef(schema) {
|
|
263
|
+
const meta = getRefMeta(schema);
|
|
264
|
+
if (!meta)
|
|
265
|
+
return {};
|
|
266
|
+
const result = {
|
|
267
|
+
$nodeRef: this.getDefName(meta.target),
|
|
268
|
+
};
|
|
269
|
+
if (meta.includeData)
|
|
270
|
+
result.includeData = true;
|
|
271
|
+
return result;
|
|
272
|
+
}
|
|
273
|
+
getDefName(def) {
|
|
274
|
+
const descriptor = this.descriptorMap.get(def);
|
|
275
|
+
if (!descriptor) {
|
|
276
|
+
const transitive = findDefTransitive(this.schema, def);
|
|
277
|
+
if (transitive) {
|
|
278
|
+
throw new Error(`Serialization error: referenced def is declared in schema "${transitive.origin}" ` +
|
|
279
|
+
`(reachable via ${transitive.path.join(' → ')}), but "${transitive.origin}" ` +
|
|
280
|
+
`is not in the direct imports of "${this.schema.domain}". ` +
|
|
281
|
+
`Add it to your schema's \`imports\` array.`);
|
|
282
|
+
}
|
|
283
|
+
throw new Error(`Serialization error: referenced def not found in schema "${this.schema.domain}" ` +
|
|
284
|
+
`or any of its imports. Is the def from an unregistered schema?`);
|
|
285
|
+
}
|
|
286
|
+
// Already recorded — early-out doubles as cycle-guard for the recursion below.
|
|
287
|
+
if (this.imports[descriptor.name])
|
|
288
|
+
return descriptor.name;
|
|
289
|
+
for (const { origin, map } of this.importedMaps) {
|
|
290
|
+
const importedDescriptor = map.get(def);
|
|
291
|
+
if (!importedDescriptor)
|
|
292
|
+
continue;
|
|
293
|
+
this.imports[descriptor.name] = { origin, definition: importedDescriptor.group };
|
|
294
|
+
// Recurse on `inherits` so transitive ancestors are recorded too:
|
|
295
|
+
// a method materialized via an indirect ancestor (e.g.
|
|
296
|
+
// `View → UI → Function → Identity` where only Function is referenced
|
|
297
|
+
// directly) must qualify to the ancestor's owning schema, not ours.
|
|
298
|
+
// The early-out above keeps the recursion cycle-safe.
|
|
299
|
+
const inherits = def.config.inherits;
|
|
300
|
+
if (inherits) {
|
|
301
|
+
for (const parent of inherits)
|
|
302
|
+
this.getDefName(parent);
|
|
303
|
+
}
|
|
304
|
+
return descriptor.name;
|
|
305
|
+
}
|
|
306
|
+
return descriptor.name;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { Cardinality } from '../grammar/facets/endpoints.js';
|
|
3
|
+
export declare function getZodDef(schema: z.ZodType): Record<string, any> | null;
|
|
4
|
+
export declare function getZodTypeName(def: Record<string, any>): string | undefined;
|
|
5
|
+
export declare function getZodInner(def: Record<string, any>): z.ZodType | null;
|
|
6
|
+
export interface UnwrapResult {
|
|
7
|
+
inner: z.ZodType;
|
|
8
|
+
nullable: boolean;
|
|
9
|
+
defaultValue: unknown;
|
|
10
|
+
hasDefault: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function unwrapZod(schema: z.ZodType): UnwrapResult;
|
|
13
|
+
export declare function getArrayElement(schema: z.ZodType): z.ZodType | null;
|
|
14
|
+
export declare function hasRefTag(schema: z.ZodType): boolean;
|
|
15
|
+
export declare function getRefMeta(schema: z.ZodType): {
|
|
16
|
+
target: object;
|
|
17
|
+
includeData: boolean;
|
|
18
|
+
} | null;
|
|
19
|
+
export declare function hasDataTag(schema: z.ZodType): boolean;
|
|
20
|
+
export declare function getDataMeta(schema: z.ZodType): {
|
|
21
|
+
kind: 'self';
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'grant';
|
|
24
|
+
target: object;
|
|
25
|
+
} | null;
|
|
26
|
+
export declare function hasBitmaskTag(schema: z.ZodType): boolean;
|
|
27
|
+
export type JsonSchema = Record<string, unknown>;
|
|
28
|
+
export declare function foldNullable(schema: JsonSchema): JsonSchema;
|
|
29
|
+
export declare function mapCardinality(c: Cardinality): {
|
|
30
|
+
min: number;
|
|
31
|
+
max: number | null;
|
|
32
|
+
} | undefined;
|
|
33
|
+
export declare function cleanJsonSchema(schema: Record<string, unknown>): JsonSchema;
|
|
34
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/serializer/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAYjE,wBAAgB,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAEvE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,GAAG,SAAS,CAE3E;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,GAAG,IAAI,CAEtE;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,CAAC,CAAC,OAAO,CAAA;IAChB,QAAQ,EAAE,OAAO,CAAA;IACjB,YAAY,EAAE,OAAO,CAAA;IACrB,UAAU,EAAE,OAAO,CAAA;CACpB;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,YAAY,CA0CzD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,GAAG,IAAI,CAQnE;AAID,wBAAgB,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,OAAO,CAEpD;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAG7F;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,OAAO,CAErD;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,CAAC,CAAC,OAAO,GAChB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAG7D;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,OAAO,CAExD;AAID,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEhD,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAS3D;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,WAAW,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,SAAS,CAW9F;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAO3E"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Runtime symbols
|
|
2
|
+
const REF_TAG_RUNTIME = Symbol.for('REF_TAG');
|
|
3
|
+
const DATA_TAG_RUNTIME = Symbol.for('DATA_TAG');
|
|
4
|
+
const BITMASK_TAG_RUNTIME = Symbol.for('BITMASK_TAG');
|
|
5
|
+
// ── Zod introspection ─────────────────────────────────────────────────
|
|
6
|
+
export function getZodDef(schema) {
|
|
7
|
+
return schema?._zod?.def ?? schema?._def ?? null;
|
|
8
|
+
}
|
|
9
|
+
export function getZodTypeName(def) {
|
|
10
|
+
return def.typeName ?? def.type;
|
|
11
|
+
}
|
|
12
|
+
export function getZodInner(def) {
|
|
13
|
+
return def.innerType ?? def.inner ?? null;
|
|
14
|
+
}
|
|
15
|
+
export function unwrapZod(schema) {
|
|
16
|
+
let current = schema;
|
|
17
|
+
let nullable = false;
|
|
18
|
+
let defaultValue = undefined;
|
|
19
|
+
let hasDefault = false;
|
|
20
|
+
for (let i = 0; i < 10; i++) {
|
|
21
|
+
const def = getZodDef(current);
|
|
22
|
+
if (!def)
|
|
23
|
+
break;
|
|
24
|
+
const typeName = getZodTypeName(def);
|
|
25
|
+
if (typeName === 'ZodOptional' || typeName === 'optional') {
|
|
26
|
+
nullable = true;
|
|
27
|
+
const inner = getZodInner(def);
|
|
28
|
+
if (!inner)
|
|
29
|
+
break;
|
|
30
|
+
current = inner;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (typeName === 'ZodNullable' || typeName === 'nullable') {
|
|
34
|
+
nullable = true;
|
|
35
|
+
const inner = getZodInner(def);
|
|
36
|
+
if (!inner)
|
|
37
|
+
break;
|
|
38
|
+
current = inner;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (typeName === 'ZodDefault' || typeName === 'default') {
|
|
42
|
+
hasDefault = true;
|
|
43
|
+
const dv = def.defaultValue !== undefined ? def.defaultValue : def.value;
|
|
44
|
+
defaultValue = typeof dv === 'function' ? dv() : dv;
|
|
45
|
+
const inner = getZodInner(def);
|
|
46
|
+
if (!inner)
|
|
47
|
+
break;
|
|
48
|
+
current = inner;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
return { inner: current, nullable, defaultValue, hasDefault };
|
|
54
|
+
}
|
|
55
|
+
export function getArrayElement(schema) {
|
|
56
|
+
const def = getZodDef(schema);
|
|
57
|
+
if (!def)
|
|
58
|
+
return null;
|
|
59
|
+
const typeName = getZodTypeName(def);
|
|
60
|
+
if (typeName === 'ZodArray' || typeName === 'array') {
|
|
61
|
+
return def.element ?? def.items ?? null;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
// ── Brand detection (new symbol-based) ────────────────────────────────
|
|
66
|
+
export function hasRefTag(schema) {
|
|
67
|
+
return schema !== null && typeof schema === 'object' && REF_TAG_RUNTIME in schema;
|
|
68
|
+
}
|
|
69
|
+
export function getRefMeta(schema) {
|
|
70
|
+
if (!hasRefTag(schema))
|
|
71
|
+
return null;
|
|
72
|
+
return schema[REF_TAG_RUNTIME];
|
|
73
|
+
}
|
|
74
|
+
export function hasDataTag(schema) {
|
|
75
|
+
return schema !== null && typeof schema === 'object' && DATA_TAG_RUNTIME in schema;
|
|
76
|
+
}
|
|
77
|
+
export function getDataMeta(schema) {
|
|
78
|
+
if (!hasDataTag(schema))
|
|
79
|
+
return null;
|
|
80
|
+
return schema[DATA_TAG_RUNTIME];
|
|
81
|
+
}
|
|
82
|
+
export function hasBitmaskTag(schema) {
|
|
83
|
+
return schema !== null && typeof schema === 'object' && BITMASK_TAG_RUNTIME in schema;
|
|
84
|
+
}
|
|
85
|
+
export function foldNullable(schema) {
|
|
86
|
+
if (schema.type) {
|
|
87
|
+
const existing = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
88
|
+
if (!existing.includes('null')) {
|
|
89
|
+
return { ...schema, type: [...existing, 'null'] };
|
|
90
|
+
}
|
|
91
|
+
return schema;
|
|
92
|
+
}
|
|
93
|
+
return { anyOf: [schema, { type: 'null' }] };
|
|
94
|
+
}
|
|
95
|
+
export function mapCardinality(c) {
|
|
96
|
+
switch (c) {
|
|
97
|
+
case '0..1':
|
|
98
|
+
return { min: 0, max: 1 };
|
|
99
|
+
case '1':
|
|
100
|
+
return { min: 1, max: 1 };
|
|
101
|
+
case '0..*':
|
|
102
|
+
return undefined;
|
|
103
|
+
case '1..*':
|
|
104
|
+
return { min: 1, max: null };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export function cleanJsonSchema(schema) {
|
|
108
|
+
const result = {};
|
|
109
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
110
|
+
if (key === '$schema')
|
|
111
|
+
continue;
|
|
112
|
+
result[key] = value;
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/serializer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { serialize } from './serialize.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { SchemaIR } from '../ir/index.js';
|
|
3
|
+
import type { Schema } from '../schema/schema.js';
|
|
4
|
+
export interface SerializeOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Named types to hoist into the IR `types` record.
|
|
7
|
+
* Pass Zod schemas that should be shared across multiple properties/params.
|
|
8
|
+
*/
|
|
9
|
+
types?: Record<string, z.ZodType>;
|
|
10
|
+
}
|
|
11
|
+
export declare function serialize(schema: Schema, options?: SerializeOptions): SchemaIR;
|
|
12
|
+
//# sourceMappingURL=serialize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/serializer/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAIjD,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;CAClC;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,QAAQ,CAG9E"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@astrale-os/kernel-dsl",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Astrale Kernel DSL - Schema authoring, inference, and IR serialization",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./ir": {
|
|
17
|
+
"types": "./dist/ir/index.d.ts",
|
|
18
|
+
"import": "./dist/ir/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "restricted",
|
|
23
|
+
"registry": "https://npm.pkg.github.com"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"zod": "^4.3.6"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
|
|
30
|
+
"@typescript/native-preview": "latest",
|
|
31
|
+
"typescript": "~6.0.1-rc",
|
|
32
|
+
"vitest": "^4.0.18"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"typescript": "~6.0.1-rc"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsgo",
|
|
39
|
+
"clean": "rm -rf dist",
|
|
40
|
+
"typecheck": "tsgo --noEmit",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"test:watch": "vitest",
|
|
43
|
+
"preinstall": "node .check-workspace.cjs"
|
|
44
|
+
}
|
|
45
|
+
}
|