@xschemadev/core 0.0.6 → 0.2.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/cli.d.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/ir/constraints.d.ts +52 -0
- package/dist/ir/constraints.d.ts.map +1 -0
- package/dist/ir/constraints.js +6 -0
- package/dist/ir/constraints.js.map +1 -0
- package/dist/ir/index.d.ts +9 -0
- package/dist/ir/index.d.ts.map +1 -0
- package/dist/ir/index.js +8 -0
- package/dist/ir/index.js.map +1 -0
- package/dist/ir/nodes.d.ts +157 -0
- package/dist/ir/nodes.d.ts.map +1 -0
- package/dist/ir/nodes.js +11 -0
- package/dist/ir/nodes.js.map +1 -0
- package/dist/parser/collections.d.ts +11 -0
- package/dist/parser/collections.d.ts.map +1 -0
- package/dist/parser/collections.js +219 -0
- package/dist/parser/collections.js.map +1 -0
- package/dist/parser/composition.d.ts +14 -0
- package/dist/parser/composition.d.ts.map +1 -0
- package/dist/parser/composition.js +36 -0
- package/dist/parser/composition.js.map +1 -0
- package/dist/parser/context.d.ts +12 -0
- package/dist/parser/context.d.ts.map +1 -0
- package/dist/parser/context.js +10 -0
- package/dist/parser/context.js.map +1 -0
- package/dist/parser/index.d.ts +19 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +325 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/primitives.d.ts +8 -0
- package/dist/parser/primitives.d.ts.map +1 -0
- package/dist/parser/primitives.js +28 -0
- package/dist/parser/primitives.js.map +1 -0
- package/dist/parser/values.d.ts +8 -0
- package/dist/parser/values.d.ts.map +1 -0
- package/dist/parser/values.js +16 -0
- package/dist/parser/values.js.map +1 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/json-schema.d.ts +66 -0
- package/dist/schema/json-schema.d.ts.map +1 -0
- package/dist/schema/json-schema.js +6 -0
- package/dist/schema/json-schema.js.map +1 -0
- package/dist/types.d.ts +6 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/code-builder.d.ts +49 -0
- package/dist/utils/code-builder.d.ts.map +1 -0
- package/dist/utils/code-builder.js +112 -0
- package/dist/utils/code-builder.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/json-pointer.d.ts +14 -0
- package/dist/utils/json-pointer.d.ts.map +1 -0
- package/dist/utils/json-pointer.js +17 -0
- package/dist/utils/json-pointer.js.map +1 -0
- package/dist/utils/primitives.d.ts +28 -0
- package/dist/utils/primitives.d.ts.map +1 -0
- package/dist/utils/primitives.js +57 -0
- package/dist/utils/primitives.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code builder utilities for generating validation code
|
|
3
|
+
* These helpers make code generation safer and more readable
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Chain method calls onto a base expression
|
|
7
|
+
* Filters out null/undefined values
|
|
8
|
+
*/
|
|
9
|
+
export declare function chain(base: string, ...methods: (string | null | undefined)[]): string;
|
|
10
|
+
/**
|
|
11
|
+
* Build a Zod union from an array of schema strings
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildUnion(schemas: string[]): string;
|
|
14
|
+
/**
|
|
15
|
+
* Build a Zod intersection from an array of schema strings
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildIntersection(schemas: string[]): string;
|
|
18
|
+
/**
|
|
19
|
+
* Build a superRefine call
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildSuperRefine(body: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Build a refine call with a predicate and message
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildRefine(predicate: string, message: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Build a literal schema
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildLiteral(value: unknown): string;
|
|
30
|
+
/**
|
|
31
|
+
* Build validation code that checks if a safeParse failed and adds issues
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildSafeParseCheck(schemaCode: string, valueExpr?: string, pathPrefix?: string[]): string;
|
|
34
|
+
/**
|
|
35
|
+
* Build validation code that checks safeParse at a specific path
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildPropertyCheck(schemaCode: string, propKey: string, required: boolean): string;
|
|
38
|
+
/**
|
|
39
|
+
* Recursively normalize a JSON value so that object keys are sorted at every depth,
|
|
40
|
+
* then stringify. Produces deterministic output regardless of key insertion order.
|
|
41
|
+
*/
|
|
42
|
+
export declare function sortedStringify(value: unknown): string;
|
|
43
|
+
/**
|
|
44
|
+
* Runtime code snippet for deep-sort-stringify.
|
|
45
|
+
* Adapters embed this in generated refine/narrow callbacks for complex const/enum comparison.
|
|
46
|
+
* Call as: `${DEEP_SORTED_STRINGIFY_RUNTIME}(val)` — returns a JSON string with recursively sorted keys.
|
|
47
|
+
*/
|
|
48
|
+
export declare const DEEP_SORTED_STRINGIFY_RUNTIME = "((v) => { const s = (v) => { if (v === null || typeof v !== 'object') return v; if (Array.isArray(v)) return v.map(s); const o = {}; for (const k of Object.keys(v).sort()) o[k] = s(v[k]); return o; }; return JSON.stringify(s(v)); })";
|
|
49
|
+
//# sourceMappingURL=code-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-builder.d.ts","sourceRoot":"","sources":["../../src/utils/code-builder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;GAGG;AACH,wBAAgB,KAAK,CACpB,IAAI,EAAE,MAAM,EACZ,GAAG,OAAO,EAAE,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,GACvC,MAAM,CAIR;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAIpD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAS3D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEnD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAClC,UAAU,EAAE,MAAM,EAClB,SAAS,GAAE,MAAc,EACzB,UAAU,GAAE,MAAM,EAAO,GACvB,MAAM,CAYR;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CACjC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,OAAO,GACf,MAAM,CAYR;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEtD;AAED;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,6OAA6O,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code builder utilities for generating validation code
|
|
3
|
+
* These helpers make code generation safer and more readable
|
|
4
|
+
*/
|
|
5
|
+
import { escapeString } from "./primitives.js";
|
|
6
|
+
/**
|
|
7
|
+
* Chain method calls onto a base expression
|
|
8
|
+
* Filters out null/undefined values
|
|
9
|
+
*/
|
|
10
|
+
export function chain(base, ...methods) {
|
|
11
|
+
return methods
|
|
12
|
+
.filter((m) => m != null && m !== "")
|
|
13
|
+
.reduce((acc, m) => `${acc}.${m}`, base);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Build a Zod union from an array of schema strings
|
|
17
|
+
*/
|
|
18
|
+
export function buildUnion(schemas) {
|
|
19
|
+
if (schemas.length === 0)
|
|
20
|
+
return "z.never()";
|
|
21
|
+
if (schemas.length === 1)
|
|
22
|
+
return schemas[0];
|
|
23
|
+
return `z.union([${schemas.join(", ")}])`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Build a Zod intersection from an array of schema strings
|
|
27
|
+
*/
|
|
28
|
+
export function buildIntersection(schemas) {
|
|
29
|
+
if (schemas.length === 0)
|
|
30
|
+
return "z.any()";
|
|
31
|
+
if (schemas.length === 1)
|
|
32
|
+
return schemas[0];
|
|
33
|
+
let result = schemas[0];
|
|
34
|
+
for (let i = 1; i < schemas.length; i++) {
|
|
35
|
+
result = `z.intersection(${result}, ${schemas[i]})`;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build a superRefine call
|
|
41
|
+
*/
|
|
42
|
+
export function buildSuperRefine(body) {
|
|
43
|
+
return `.superRefine((val, ctx) => {${body}})`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build a refine call with a predicate and message
|
|
47
|
+
*/
|
|
48
|
+
export function buildRefine(predicate, message) {
|
|
49
|
+
return `.refine(${predicate}, { message: ${escapeString(message)} })`;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Build a literal schema
|
|
53
|
+
*/
|
|
54
|
+
export function buildLiteral(value) {
|
|
55
|
+
return `z.literal(${JSON.stringify(value)})`;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Build validation code that checks if a safeParse failed and adds issues
|
|
59
|
+
*/
|
|
60
|
+
export function buildSafeParseCheck(schemaCode, valueExpr = "val", pathPrefix = []) {
|
|
61
|
+
const pathArray = pathPrefix.length > 0
|
|
62
|
+
? `[${pathPrefix.map((p) => escapeString(p)).join(", ")}, ...issue.path]`
|
|
63
|
+
: "issue.path";
|
|
64
|
+
return `{
|
|
65
|
+
const result = ${schemaCode}.safeParse(${valueExpr});
|
|
66
|
+
if (!result.success) {
|
|
67
|
+
result.error.issues.forEach(issue => ctx.addIssue({ ...issue, path: ${pathArray} }));
|
|
68
|
+
}
|
|
69
|
+
}`;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Build validation code that checks safeParse at a specific path
|
|
73
|
+
*/
|
|
74
|
+
export function buildPropertyCheck(schemaCode, propKey, required) {
|
|
75
|
+
const keyExpr = escapeString(propKey);
|
|
76
|
+
const check = buildSafeParseCheck(schemaCode, `val[${keyExpr}]`, [propKey]);
|
|
77
|
+
if (required) {
|
|
78
|
+
return `
|
|
79
|
+
if (Object.hasOwn(val, ${keyExpr})) ${check} else {
|
|
80
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: [${keyExpr}], message: "Required" });
|
|
81
|
+
}`;
|
|
82
|
+
}
|
|
83
|
+
return `
|
|
84
|
+
if (Object.hasOwn(val, ${keyExpr})) ${check}`;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Recursively normalize a JSON value so that object keys are sorted at every depth,
|
|
88
|
+
* then stringify. Produces deterministic output regardless of key insertion order.
|
|
89
|
+
*/
|
|
90
|
+
export function sortedStringify(value) {
|
|
91
|
+
return JSON.stringify(deepSortKeys(value));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Runtime code snippet for deep-sort-stringify.
|
|
95
|
+
* Adapters embed this in generated refine/narrow callbacks for complex const/enum comparison.
|
|
96
|
+
* Call as: `${DEEP_SORTED_STRINGIFY_RUNTIME}(val)` — returns a JSON string with recursively sorted keys.
|
|
97
|
+
*/
|
|
98
|
+
export const DEEP_SORTED_STRINGIFY_RUNTIME = `((v) => { const s = (v) => { if (v === null || typeof v !== 'object') return v; if (Array.isArray(v)) return v.map(s); const o = {}; for (const k of Object.keys(v).sort()) o[k] = s(v[k]); return o; }; return JSON.stringify(s(v)); })`;
|
|
99
|
+
function deepSortKeys(value) {
|
|
100
|
+
if (value === null || typeof value !== "object") {
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
if (Array.isArray(value)) {
|
|
104
|
+
return value.map(deepSortKeys);
|
|
105
|
+
}
|
|
106
|
+
const sorted = {};
|
|
107
|
+
for (const key of Object.keys(value).sort()) {
|
|
108
|
+
sorted[key] = deepSortKeys(value[key]);
|
|
109
|
+
}
|
|
110
|
+
return sorted;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=code-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-builder.js","sourceRoot":"","sources":["../../src/utils/code-builder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,KAAK,CACpB,IAAY,EACZ,GAAG,OAAsC;IAEzC,OAAO,OAAO;SACZ,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;SACjD,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,OAAiB;IAC3C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,WAAW,CAAC;IAC7C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC,CAAC,CAAE,CAAC;IAC7C,OAAO,YAAY,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAiB;IAClD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC3C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC,CAAC,CAAE,CAAC;IAE7C,IAAI,MAAM,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,MAAM,GAAG,kBAAkB,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IACrD,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,OAAO,+BAA+B,IAAI,IAAI,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB,EAAE,OAAe;IAC7D,OAAO,WAAW,SAAS,gBAAgB,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC;AACvE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IAC1C,OAAO,aAAa,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAClC,UAAkB,EAClB,YAAoB,KAAK,EACzB,aAAuB,EAAE;IAEzB,MAAM,SAAS,GACd,UAAU,CAAC,MAAM,GAAG,CAAC;QACpB,CAAC,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB;QACzE,CAAC,CAAC,YAAY,CAAC;IAEjB,OAAO;uBACe,UAAU,cAAc,SAAS;;8EAEsB,SAAS;;MAEjF,CAAC;AACP,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CACjC,UAAkB,EAClB,OAAe,EACf,QAAiB;IAEjB,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,mBAAmB,CAAC,UAAU,EAAE,OAAO,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAE5E,IAAI,QAAQ,EAAE,CAAC;QACd,OAAO;iCACwB,OAAO,MAAM,KAAK;+DACY,OAAO;UAC5D,CAAC;IACV,CAAC;IACD,OAAO;iCACyB,OAAO,MAAM,KAAK,EAAE,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC7C,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,0OAA0O,CAAC;AAExR,SAAS,YAAY,CAAC,KAAc;IACnC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACjD,OAAO,KAAK,CAAC;IACd,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAChC,CAAC;IACD,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAgC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QACxE,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAE,KAAiC,CAAC,GAAG,CAAC,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for adapters
|
|
3
|
+
*/
|
|
4
|
+
export { isPrimitive, escapeString, isEmptyObject, getOwnProperty, PROTOTYPE_PROPERTY_NAMES, hasPrototypeProperties, } from "./primitives.js";
|
|
5
|
+
export { getRefName } from "./json-pointer.js";
|
|
6
|
+
export { chain, buildUnion, buildIntersection, buildSuperRefine, buildRefine, buildLiteral, buildSafeParseCheck, buildPropertyCheck, sortedStringify, DEEP_SORTED_STRINGIFY_RUNTIME, } from "./code-builder.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACN,WAAW,EACX,YAAY,EACZ,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,sBAAsB,GACtB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EACN,KAAK,EACL,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,6BAA6B,GAC7B,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for adapters
|
|
3
|
+
*/
|
|
4
|
+
export { isPrimitive, escapeString, isEmptyObject, getOwnProperty, PROTOTYPE_PROPERTY_NAMES, hasPrototypeProperties, } from "./primitives.js";
|
|
5
|
+
export { getRefName } from "./json-pointer.js";
|
|
6
|
+
export { chain, buildUnion, buildIntersection, buildSuperRefine, buildRefine, buildLiteral, buildSafeParseCheck, buildPropertyCheck, sortedStringify, DEEP_SORTED_STRINGIFY_RUNTIME, } from "./code-builder.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACN,WAAW,EACX,YAAY,EACZ,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,sBAAsB,GACtB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EACN,KAAK,EACL,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,6BAA6B,GAC7B,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Pointer utilities
|
|
3
|
+
* Note: All $ref resolution is handled by the Go CLI bundler.
|
|
4
|
+
* TypeScript receives pre-bundled schemas with all refs resolved.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Extract definition name from a $ref path
|
|
8
|
+
* e.g., "#/$defs/User" -> "User"
|
|
9
|
+
*
|
|
10
|
+
* @deprecated This function may be removed in future versions as refs
|
|
11
|
+
* should be resolved by the Go bundler before reaching TypeScript.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getRefName(ref: string): string | null;
|
|
14
|
+
//# sourceMappingURL=json-pointer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-pointer.d.ts","sourceRoot":"","sources":["../../src/utils/json-pointer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGrD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Pointer utilities
|
|
3
|
+
* Note: All $ref resolution is handled by the Go CLI bundler.
|
|
4
|
+
* TypeScript receives pre-bundled schemas with all refs resolved.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Extract definition name from a $ref path
|
|
8
|
+
* e.g., "#/$defs/User" -> "User"
|
|
9
|
+
*
|
|
10
|
+
* @deprecated This function may be removed in future versions as refs
|
|
11
|
+
* should be resolved by the Go bundler before reaching TypeScript.
|
|
12
|
+
*/
|
|
13
|
+
export function getRefName(ref) {
|
|
14
|
+
const match = ref.match(/#\/(?:\$defs|definitions)\/(.+)$/);
|
|
15
|
+
return match ? match[1] : null;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=json-pointer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-pointer.js","sourceRoot":"","sources":["../../src/utils/json-pointer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACrC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;IAC5D,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Primitive utility functions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Check if a value is a primitive (string, number, boolean, null)
|
|
6
|
+
*/
|
|
7
|
+
export declare function isPrimitive(value: unknown): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Escape a string for use in generated code (JSON.stringify)
|
|
10
|
+
*/
|
|
11
|
+
export declare function escapeString(str: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Check if an object is empty
|
|
14
|
+
*/
|
|
15
|
+
export declare function isEmptyObject(obj: object): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Get own property safely (handles __proto__ etc.)
|
|
18
|
+
*/
|
|
19
|
+
export declare function getOwnProperty<T>(obj: Record<string, T>, key: string): T | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Property names that exist on Object.prototype and need special handling
|
|
22
|
+
*/
|
|
23
|
+
export declare const PROTOTYPE_PROPERTY_NAMES: Set<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Check if any keys are prototype property names
|
|
26
|
+
*/
|
|
27
|
+
export declare function hasPrototypeProperties(keys: string[]): boolean;
|
|
28
|
+
//# sourceMappingURL=primitives.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/utils/primitives.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAOnD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC/B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,EACtB,GAAG,EAAE,MAAM,GACT,CAAC,GAAG,SAAS,CAKf;AAED;;GAEG;AACH,eAAO,MAAM,wBAAwB,aAanC,CAAC;AAEH;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAE9D"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Primitive utility functions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Check if a value is a primitive (string, number, boolean, null)
|
|
6
|
+
*/
|
|
7
|
+
export function isPrimitive(value) {
|
|
8
|
+
return (value === null ||
|
|
9
|
+
typeof value === "string" ||
|
|
10
|
+
typeof value === "number" ||
|
|
11
|
+
typeof value === "boolean");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Escape a string for use in generated code (JSON.stringify)
|
|
15
|
+
*/
|
|
16
|
+
export function escapeString(str) {
|
|
17
|
+
return JSON.stringify(str);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Check if an object is empty
|
|
21
|
+
*/
|
|
22
|
+
export function isEmptyObject(obj) {
|
|
23
|
+
return Object.keys(obj).length === 0;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get own property safely (handles __proto__ etc.)
|
|
27
|
+
*/
|
|
28
|
+
export function getOwnProperty(obj, key) {
|
|
29
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
30
|
+
return obj[key];
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Property names that exist on Object.prototype and need special handling
|
|
36
|
+
*/
|
|
37
|
+
export const PROTOTYPE_PROPERTY_NAMES = new Set([
|
|
38
|
+
"__proto__",
|
|
39
|
+
"constructor",
|
|
40
|
+
"toString",
|
|
41
|
+
"valueOf",
|
|
42
|
+
"hasOwnProperty",
|
|
43
|
+
"isPrototypeOf",
|
|
44
|
+
"propertyIsEnumerable",
|
|
45
|
+
"toLocaleString",
|
|
46
|
+
"__defineGetter__",
|
|
47
|
+
"__defineSetter__",
|
|
48
|
+
"__lookupGetter__",
|
|
49
|
+
"__lookupSetter__",
|
|
50
|
+
]);
|
|
51
|
+
/**
|
|
52
|
+
* Check if any keys are prototype property names
|
|
53
|
+
*/
|
|
54
|
+
export function hasPrototypeProperties(keys) {
|
|
55
|
+
return keys.some((k) => PROTOTYPE_PROPERTY_NAMES.has(k));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=primitives.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../src/utils/primitives.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACzC,OAAO,CACN,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,KAAK,SAAS,CAC1B,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACvC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACxC,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAC7B,GAAsB,EACtB,GAAW;IAEX,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;QACpD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC;IAC/C,WAAW;IACX,aAAa;IACb,UAAU;IACV,SAAS;IACT,gBAAgB;IAChB,eAAe;IACf,sBAAsB;IACtB,gBAAgB;IAChB,kBAAkB;IAClB,kBAAkB;IAClB,kBAAkB;IAClB,kBAAkB;CAClB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAc;IACpD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,wBAAwB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xschemadev/core",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "XSchema Adapter CLI helper and protocol types",
|
|
6
6
|
"exports": {
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "tsc",
|
|
17
|
-
"typecheck": "tsc --noEmit"
|
|
17
|
+
"typecheck": "tsc --noEmit",
|
|
18
|
+
"test": "bun test"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
21
|
"@types/node": "^22.0.0"
|