@globaltypesystem/gts-ts 0.1.1 → 0.3.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/NOTICE +15 -0
- package/README.md +14 -18
- package/dist/gts.d.ts.map +1 -1
- package/dist/gts.js +37 -4
- package/dist/gts.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -1
- package/dist/server/server.d.ts +2 -0
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +20 -0
- package/dist/server/server.js.map +1 -1
- package/dist/server/types.d.ts +7 -0
- package/dist/server/types.d.ts.map +1 -1
- package/dist/store.d.ts +16 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +775 -2
- package/dist/store.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/x-gts-ref.d.ts +1 -0
- package/dist/x-gts-ref.d.ts.map +1 -1
- package/dist/x-gts-ref.js +65 -0
- package/dist/x-gts-ref.js.map +1 -1
- package/package.json +3 -4
- package/src/gts.ts +40 -5
- package/src/index.ts +22 -0
- package/src/server/server.ts +33 -0
- package/src/server/types.ts +9 -0
- package/src/store.ts +859 -2
- package/src/types.ts +1 -0
- package/src/x-gts-ref.ts +63 -0
- package/tests/gts.test.ts +2 -0
package/src/types.ts
CHANGED
package/src/x-gts-ref.ts
CHANGED
|
@@ -81,6 +81,56 @@ export class XGtsRefValidator {
|
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
+
|
|
85
|
+
// Recurse into combinator subschemas
|
|
86
|
+
if (Array.isArray(schema.allOf)) {
|
|
87
|
+
for (const subSchema of schema.allOf) {
|
|
88
|
+
this.visitInstance(instance, subSchema, path, rootSchema, errors);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (Array.isArray(schema.anyOf)) {
|
|
93
|
+
// Only enforce when all branches have x-gts-ref; mixed branches may be valid via non-x-gts-ref path (Ajv handles that)
|
|
94
|
+
const refBranches = schema.anyOf.filter((s: any) => this.containsXGtsRef(s));
|
|
95
|
+
if (refBranches.length > 0 && refBranches.length === schema.anyOf.length) {
|
|
96
|
+
const branchResults = refBranches.map((subSchema: any) => {
|
|
97
|
+
const branchErrors: XGtsRefValidationError[] = [];
|
|
98
|
+
this.visitInstance(instance, subSchema, path, rootSchema, branchErrors);
|
|
99
|
+
return branchErrors;
|
|
100
|
+
});
|
|
101
|
+
const anyPassed = branchResults.some((errs: XGtsRefValidationError[]) => errs.length === 0);
|
|
102
|
+
if (!anyPassed) {
|
|
103
|
+
for (const branchErrors of branchResults) {
|
|
104
|
+
errors.push(...branchErrors);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (Array.isArray(schema.oneOf)) {
|
|
111
|
+
// Only enforce when all branches have x-gts-ref; mixed branches can't be coordinated with Ajv's branch selection
|
|
112
|
+
const refBranches = schema.oneOf.filter((s: any) => this.containsXGtsRef(s));
|
|
113
|
+
if (refBranches.length > 0 && refBranches.length === schema.oneOf.length) {
|
|
114
|
+
const branchResults = refBranches.map((subSchema: any) => {
|
|
115
|
+
const branchErrors: XGtsRefValidationError[] = [];
|
|
116
|
+
this.visitInstance(instance, subSchema, path, rootSchema, branchErrors);
|
|
117
|
+
return branchErrors;
|
|
118
|
+
});
|
|
119
|
+
const passingCount = branchResults.filter((errs: XGtsRefValidationError[]) => errs.length === 0).length;
|
|
120
|
+
if (passingCount === 0) {
|
|
121
|
+
for (const branchErrors of branchResults) {
|
|
122
|
+
errors.push(...branchErrors);
|
|
123
|
+
}
|
|
124
|
+
} else if (passingCount > 1) {
|
|
125
|
+
errors.push({
|
|
126
|
+
fieldPath: path || '/',
|
|
127
|
+
value: instance,
|
|
128
|
+
refPattern: '',
|
|
129
|
+
reason: `Value matches ${passingCount} oneOf branches but must match exactly one`,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
84
134
|
}
|
|
85
135
|
|
|
86
136
|
private visitSchema(schema: any, path: string, rootSchema: any, errors: XGtsRefValidationError[]): void {
|
|
@@ -300,6 +350,19 @@ export class XGtsRefValidator {
|
|
|
300
350
|
return null;
|
|
301
351
|
}
|
|
302
352
|
|
|
353
|
+
private containsXGtsRef(schema: any): boolean {
|
|
354
|
+
if (!schema || typeof schema !== 'object') return false;
|
|
355
|
+
if (schema['x-gts-ref'] !== undefined) return true;
|
|
356
|
+
for (const value of Object.values(schema)) {
|
|
357
|
+
if (Array.isArray(value)) {
|
|
358
|
+
if (value.some((item) => this.containsXGtsRef(item))) return true;
|
|
359
|
+
} else if (value && typeof value === 'object') {
|
|
360
|
+
if (this.containsXGtsRef(value)) return true;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
|
|
303
366
|
/**
|
|
304
367
|
* Strip the "gts://" prefix from a value if present
|
|
305
368
|
*/
|
package/tests/gts.test.ts
CHANGED
|
@@ -414,6 +414,8 @@ describe('GTS Store Operations', () => {
|
|
|
414
414
|
});
|
|
415
415
|
});
|
|
416
416
|
|
|
417
|
+
// x-gts-ref combinator tests (oneOf/anyOf/allOf) are in the canonical gts-spec test suite
|
|
418
|
+
|
|
417
419
|
describe('OP#12 - Wildcard Validation (v0.7)', () => {
|
|
418
420
|
test('validates wildcard patterns', () => {
|
|
419
421
|
const result = validateGtsID('gts.vendor.pkg.*');
|