@contractual/differs.json-schema 0.1.0-dev.0 → 0.1.0-dev.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.
@@ -1,357 +0,0 @@
1
- /**
2
- * JSON Schema Change Classifiers
3
- *
4
- * Classifies raw structural changes into severity levels for semantic versioning.
5
- * Follows API compatibility principles where breaking changes require major bumps,
6
- * additive changes require minor bumps, and metadata changes are patches.
7
- */
8
- /**
9
- * Change types that are always breaking (require major version bump)
10
- *
11
- * These changes can break existing consumers:
12
- * - Removing properties removes data they may depend on
13
- * - Adding required fields forces consumers to provide new data
14
- * - Type changes can break parsing/validation
15
- * - Enum removals can invalidate existing data
16
- * - Tightened constraints can reject previously valid data
17
- * - Composition option additions can change validation semantics
18
- *
19
- * Aligned with Strands API classification rules.
20
- */
21
- const BREAKING_CHANGES = new Set([
22
- 'property-removed',
23
- 'required-added',
24
- 'type-changed',
25
- 'type-narrowed',
26
- 'enum-value-removed',
27
- 'enum-added',
28
- 'constraint-tightened',
29
- 'additional-properties-denied',
30
- 'items-changed',
31
- 'min-items-increased',
32
- 'max-items-decreased',
33
- 'ref-target-changed',
34
- 'dependent-required-added',
35
- // Composition breaking changes (per Strands API)
36
- 'anyof-option-added',
37
- 'oneof-option-added',
38
- 'allof-member-added',
39
- 'not-schema-changed',
40
- ]);
41
- /**
42
- * Change types that are non-breaking (require minor version bump)
43
- *
44
- * These changes are backward compatible additions/relaxations:
45
- * - Adding optional properties extends the schema without breaking
46
- * - Removing required constraints makes the schema more permissive
47
- * - Type widening accepts more values
48
- * - Loosened constraints accept more values
49
- * - Composition option removals make schema less restrictive
50
- *
51
- * Aligned with Strands API classification rules.
52
- */
53
- const NON_BREAKING_CHANGES = new Set([
54
- 'property-added',
55
- 'required-removed',
56
- 'type-widened',
57
- 'enum-value-added',
58
- 'enum-removed',
59
- 'constraint-loosened',
60
- 'additional-properties-allowed',
61
- 'additional-properties-changed',
62
- 'dependent-required-removed',
63
- // Composition non-breaking changes (per Strands API)
64
- 'anyof-option-removed',
65
- 'oneof-option-removed',
66
- 'allof-member-removed',
67
- ]);
68
- /**
69
- * Change types that are patches (documentation/metadata only)
70
- *
71
- * These changes don't affect validation behavior:
72
- * - Description changes are documentation only
73
- * - Title changes are display metadata
74
- * - Default/example changes don't affect validation
75
- * - Format is an annotation (per Strands API) - doesn't affect validation
76
- * - Annotation keywords (deprecated, readOnly, writeOnly)
77
- * - Content keywords (contentEncoding, contentMediaType, contentSchema)
78
- *
79
- * Aligned with Strands API classification rules.
80
- */
81
- const PATCH_CHANGES = new Set([
82
- // Metadata changes
83
- 'description-changed',
84
- 'title-changed',
85
- 'default-changed',
86
- 'examples-changed',
87
- // Format is annotation (patch per Strands API)
88
- 'format-added',
89
- 'format-removed',
90
- 'format-changed',
91
- // Annotation keywords (Draft 2019-09+)
92
- 'deprecated-changed',
93
- 'read-only-changed',
94
- 'write-only-changed',
95
- // Content keywords
96
- 'content-encoding-changed',
97
- 'content-media-type-changed',
98
- 'content-schema-changed',
99
- ]);
100
- /**
101
- * Change types that require manual review
102
- *
103
- * These changes are too complex to classify automatically:
104
- * - Generic composition changes require semantic analysis
105
- * - Complex keywords (propertyNames, dependentSchemas, unevaluated*)
106
- * - Conditional schema changes (if/then/else)
107
- * - Unknown changes need human evaluation
108
- *
109
- * Aligned with Strands API classification rules.
110
- */
111
- const UNKNOWN_CHANGES = new Set([
112
- // Complex object keywords
113
- 'property-names-changed',
114
- 'dependent-schemas-changed',
115
- 'unevaluated-properties-changed',
116
- // Complex array keywords
117
- 'unevaluated-items-changed',
118
- 'min-contains-changed',
119
- 'max-contains-changed',
120
- // Conditional schema
121
- 'if-then-else-changed',
122
- // Legacy/generic composition
123
- 'composition-changed',
124
- // Catch-all
125
- 'unknown-change',
126
- ]);
127
- /**
128
- * Export classification sets for external analysis
129
- */
130
- export const CLASSIFICATION_SETS = {
131
- breaking: BREAKING_CHANGES,
132
- nonBreaking: NON_BREAKING_CHANGES,
133
- patch: PATCH_CHANGES,
134
- unknown: UNKNOWN_CHANGES,
135
- };
136
- /**
137
- * Classify a raw change into a severity level
138
- *
139
- * Uses the Strands API classification rules where:
140
- * - Breaking changes require major version bump
141
- * - Non-breaking changes require minor version bump
142
- * - Patch changes are metadata/annotation only
143
- * - Unknown changes require manual review
144
- *
145
- * @param change - The raw change to classify
146
- * @returns The severity classification
147
- *
148
- * @example
149
- * ```typescript
150
- * const change: RawChange = {
151
- * path: '/properties/name',
152
- * type: 'property-removed',
153
- * oldValue: { type: 'string' },
154
- * };
155
- * const severity = classify(change);
156
- * // severity === 'breaking'
157
- * ```
158
- */
159
- export function classify(change) {
160
- const { type } = change;
161
- // Check each category in order of specificity
162
- if (BREAKING_CHANGES.has(type)) {
163
- return 'breaking';
164
- }
165
- if (NON_BREAKING_CHANGES.has(type)) {
166
- return 'non-breaking';
167
- }
168
- if (PATCH_CHANGES.has(type)) {
169
- return 'patch';
170
- }
171
- if (UNKNOWN_CHANGES.has(type)) {
172
- return 'unknown';
173
- }
174
- // Defensive: any unhandled type is unknown
175
- return 'unknown';
176
- }
177
- /**
178
- * Classify a property-added change with schema context
179
- *
180
- * Property additions are breaking if the property is required,
181
- * otherwise they are non-breaking (additive).
182
- *
183
- * @param change - The property-added change
184
- * @param newSchema - The new schema for context (to check required array)
185
- * @returns The severity classification
186
- *
187
- * @example
188
- * ```typescript
189
- * const change: RawChange = {
190
- * path: '/properties/email',
191
- * type: 'property-added',
192
- * newValue: { type: 'string', format: 'email' },
193
- * };
194
- *
195
- * const schema = {
196
- * type: 'object',
197
- * properties: { email: { type: 'string', format: 'email' } },
198
- * required: ['email'], // email is required!
199
- * };
200
- *
201
- * const severity = classifyPropertyAdded(change, schema);
202
- * // severity === 'breaking' (because email is in required[])
203
- * ```
204
- */
205
- export function classifyPropertyAdded(change, newSchema) {
206
- // Validate change type
207
- if (change.type !== 'property-added') {
208
- return classify(change);
209
- }
210
- // Extract property name from path
211
- const propertyName = extractPropertyName(change.path);
212
- if (!propertyName) {
213
- // Cannot determine property name, fall back to non-breaking
214
- return 'non-breaking';
215
- }
216
- // Find the parent schema containing this property
217
- const parentSchema = findParentSchema(change.path, newSchema);
218
- if (!parentSchema) {
219
- // Cannot find parent schema, fall back to non-breaking
220
- return 'non-breaking';
221
- }
222
- // Check if property is in the required array
223
- const required = getRequiredArray(parentSchema);
224
- if (required.includes(propertyName)) {
225
- // Adding a required property is breaking
226
- return 'breaking';
227
- }
228
- // Adding an optional property is non-breaking
229
- return 'non-breaking';
230
- }
231
- /**
232
- * Extract the property name from a JSON Pointer path
233
- *
234
- * @param path - JSON Pointer path (e.g., '/properties/name' or '/properties/user/properties/email')
235
- * @returns The property name or null if not found
236
- */
237
- function extractPropertyName(path) {
238
- // Match the last /properties/NAME segment
239
- const match = path.match(/\/properties\/([^/]+)$/);
240
- if (match?.[1] !== undefined) {
241
- return decodeJsonPointerSegment(match[1]);
242
- }
243
- return null;
244
- }
245
- /**
246
- * Decode a JSON Pointer segment (handles ~0 and ~1 escapes)
247
- *
248
- * @param segment - The encoded segment
249
- * @returns The decoded segment
250
- */
251
- function decodeJsonPointerSegment(segment) {
252
- return segment.replace(/~1/g, '/').replace(/~0/g, '~');
253
- }
254
- /**
255
- * Find the parent schema containing a property
256
- *
257
- * @param path - JSON Pointer path to the property
258
- * @param schema - The root schema
259
- * @returns The parent schema or null if not found
260
- */
261
- function findParentSchema(path, schema) {
262
- if (!isObject(schema)) {
263
- return null;
264
- }
265
- // Remove the last segment to get parent path
266
- // e.g., '/properties/name' -> '' (root)
267
- // e.g., '/properties/user/properties/email' -> '/properties/user'
268
- const segments = path.split('/').filter(Boolean);
269
- // We need to navigate to the schema containing /properties/NAME
270
- // So we remove 'properties' and 'NAME' from the end
271
- if (segments.length < 2) {
272
- // Path is too short, parent is root
273
- return schema;
274
- }
275
- // Remove 'NAME' and 'properties' from the end
276
- const parentSegments = segments.slice(0, -2);
277
- // Navigate to parent
278
- let current = schema;
279
- for (const segment of parentSegments) {
280
- if (!isObject(current)) {
281
- return null;
282
- }
283
- const decoded = decodeJsonPointerSegment(segment);
284
- current = current[decoded];
285
- }
286
- return current;
287
- }
288
- /**
289
- * Get the required array from a schema object
290
- *
291
- * @param schema - The schema object
292
- * @returns Array of required property names
293
- */
294
- function getRequiredArray(schema) {
295
- if (!isObject(schema)) {
296
- return [];
297
- }
298
- const obj = schema;
299
- const required = obj['required'];
300
- if (!Array.isArray(required)) {
301
- return [];
302
- }
303
- return required.filter((item) => typeof item === 'string');
304
- }
305
- /**
306
- * Type guard for objects
307
- */
308
- function isObject(value) {
309
- return typeof value === 'object' && value !== null && !Array.isArray(value);
310
- }
311
- /**
312
- * Batch classify multiple changes
313
- *
314
- * @param changes - Array of raw changes
315
- * @param newSchema - Optional schema for context-aware classification
316
- * @returns Map of change to severity
317
- */
318
- export function classifyAll(changes, newSchema) {
319
- const results = new Map();
320
- for (const change of changes) {
321
- if (change.type === 'property-added' && newSchema !== undefined) {
322
- results.set(change, classifyPropertyAdded(change, newSchema));
323
- }
324
- else {
325
- results.set(change, classify(change));
326
- }
327
- }
328
- return results;
329
- }
330
- /**
331
- * Get a human-readable message for a classified change
332
- *
333
- * @param change - The raw change
334
- * @param severity - The classified severity
335
- * @returns Human-readable description
336
- */
337
- export function getChangeMessage(change, severity) {
338
- const severityLabel = severity === 'breaking'
339
- ? 'BREAKING'
340
- : severity === 'non-breaking'
341
- ? 'Non-breaking'
342
- : severity === 'patch'
343
- ? 'Patch'
344
- : 'Unknown';
345
- const typeLabel = formatChangeType(change.type);
346
- return `[${severityLabel}] ${typeLabel} at ${change.path}`;
347
- }
348
- /**
349
- * Format a change type into a human-readable label
350
- */
351
- function formatChangeType(type) {
352
- return type
353
- .split('-')
354
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
355
- .join(' ');
356
- }
357
- //# sourceMappingURL=classifiers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"classifiers.js","sourceRoot":"","sources":["../src/classifiers.ts"],"names":[],"mappings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AAE,CAAC;QAC7B,IAAI,MAAM,CAAC,IAAI,KAAK,gBAAgB,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAChE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;QAChE,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAiB,EAAE,QAAwB;IAC1E,MAAM,aAAa,GACjB,QAAQ,KAAK,UAAU;QACrB,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,QAAQ,KAAK,cAAc;YAC3B,CAAC,CAAC,cAAc;YAChB,CAAC,CAAC,QAAQ,KAAK,OAAO;gBACpB,CAAC,CAAC,OAAO;gBACT,CAAC,CAAC,SAAS,CAAC;IAEpB,MAAM,SAAS,GAAG,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAEhD,OAAO,IAAI,aAAa,KAAK,SAAS,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AAC7D,CAAC;AAED;;GAEG;AACH,SAAS,gBAAgB,CAAC,IAAgB;IACxC,OAAO,IAAI;SACR,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAC3D,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
@@ -1,73 +0,0 @@
1
- /**
2
- * JSON Schema $ref Resolver
3
- *
4
- * Resolves all $ref pointers in a JSON Schema, producing a self-contained schema.
5
- * Handles internal references ($defs, definitions) and detects circular references.
6
- *
7
- * This resolver operates on in-memory schema objects and does not fetch external URLs.
8
- * External references are flagged as warnings.
9
- */
10
- /**
11
- * Result of resolving references in a schema
12
- */
13
- export interface ResolveResult {
14
- /** The resolved schema with $refs replaced */
15
- readonly schema: unknown;
16
- /** Warnings encountered during resolution (circular refs, external refs, etc.) */
17
- readonly warnings: string[];
18
- }
19
- /**
20
- * Resolve all $ref pointers in a JSON Schema
21
- *
22
- * Creates a self-contained schema by inlining all internal references.
23
- * Does not modify the original schema.
24
- *
25
- * @param schema - The JSON Schema to resolve
26
- * @returns The resolved schema and any warnings
27
- *
28
- * @example
29
- * ```typescript
30
- * const schema = {
31
- * type: 'object',
32
- * properties: {
33
- * user: { $ref: '#/$defs/User' }
34
- * },
35
- * $defs: {
36
- * User: { type: 'object', properties: { name: { type: 'string' } } }
37
- * }
38
- * };
39
- *
40
- * const result = resolveRefs(schema);
41
- * // result.schema.properties.user === { type: 'object', properties: { name: { type: 'string' } } }
42
- * // result.warnings === []
43
- * ```
44
- */
45
- export declare function resolveRefs(schema: unknown): ResolveResult;
46
- /**
47
- * Check if a schema contains any unresolved $refs
48
- *
49
- * @param schema - The schema to check
50
- * @returns True if the schema contains $ref pointers
51
- */
52
- export declare function hasUnresolvedRefs(schema: unknown): boolean;
53
- /**
54
- * Extract all $ref pointers from a schema
55
- *
56
- * @param schema - The schema to analyze
57
- * @returns Array of { pointer, path } objects
58
- */
59
- export declare function extractRefs(schema: unknown): Array<{
60
- pointer: string;
61
- path: string;
62
- }>;
63
- /**
64
- * Validate that all internal references in a schema are resolvable
65
- *
66
- * @param schema - The schema to validate
67
- * @returns Object with valid flag and any error messages
68
- */
69
- export declare function validateRefs(schema: unknown): {
70
- valid: boolean;
71
- errors: string[];
72
- };
73
- //# sourceMappingURL=ref-resolver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ref-resolver.d.ts","sourceRoot":"","sources":["../src/ref-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,8CAA8C;IAC9C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,kFAAkF;IAClF,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;CAC7B;AAkBD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,aAAa,CAe1D;AA2PD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CA0B1D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,KAAK,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAIrF;AAiCD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG;IAC7C,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAoBA"}