@contractual/governance 0.1.0-dev.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/LICENSE +21 -0
- package/dist/differs/index.d.ts +11 -0
- package/dist/differs/index.d.ts.map +1 -0
- package/dist/differs/index.js +11 -0
- package/dist/differs/index.js.map +1 -0
- package/dist/differs/json-schema/index.d.ts +8 -0
- package/dist/differs/json-schema/index.d.ts.map +1 -0
- package/dist/differs/json-schema/index.js +9 -0
- package/dist/differs/json-schema/index.js.map +1 -0
- package/dist/differs/openapi-diff.d.ts +22 -0
- package/dist/differs/openapi-diff.d.ts.map +1 -0
- package/dist/differs/openapi-diff.js +113 -0
- package/dist/differs/openapi-diff.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/linters/index.d.ts +9 -0
- package/dist/linters/index.d.ts.map +1 -0
- package/dist/linters/index.js +11 -0
- package/dist/linters/index.js.map +1 -0
- package/dist/linters/json-schema-ajv.d.ts +42 -0
- package/dist/linters/json-schema-ajv.d.ts.map +1 -0
- package/dist/linters/json-schema-ajv.js +146 -0
- package/dist/linters/json-schema-ajv.js.map +1 -0
- package/dist/linters/json-schema-rules.d.ts +42 -0
- package/dist/linters/json-schema-rules.d.ts.map +1 -0
- package/dist/linters/json-schema-rules.js +747 -0
- package/dist/linters/json-schema-rules.js.map +1 -0
- package/dist/linters/openapi-redocly.d.ts +15 -0
- package/dist/linters/openapi-redocly.d.ts.map +1 -0
- package/dist/linters/openapi-redocly.js +69 -0
- package/dist/linters/openapi-redocly.js.map +1 -0
- package/dist/registry.d.ts +48 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +178 -0
- package/dist/registry.js.map +1 -0
- package/dist/runner.d.ts +32 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +321 -0
- package/dist/runner.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2025 Omer Morad
|
|
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.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Differs
|
|
3
|
+
*
|
|
4
|
+
* Contract differ implementations for detecting structural changes
|
|
5
|
+
* between two versions of a contract specification.
|
|
6
|
+
*
|
|
7
|
+
* All differs are pure Node.js - no binary dependencies.
|
|
8
|
+
*/
|
|
9
|
+
export { diffOpenAPI, diffOpenAPIObjects, hasOpenAPIBreakingChanges } from './openapi-diff.js';
|
|
10
|
+
export { diffJsonSchema } from './json-schema/index.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../differs/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAE/F,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Differs
|
|
3
|
+
*
|
|
4
|
+
* Contract differ implementations for detecting structural changes
|
|
5
|
+
* between two versions of a contract specification.
|
|
6
|
+
*
|
|
7
|
+
* All differs are pure Node.js - no binary dependencies.
|
|
8
|
+
*/
|
|
9
|
+
export { diffOpenAPI, diffOpenAPIObjects, hasOpenAPIBreakingChanges } from './openapi-diff.js';
|
|
10
|
+
export { diffJsonSchema } from './json-schema/index.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../differs/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAE/F,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../differs/json-schema/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema Differ
|
|
3
|
+
*
|
|
4
|
+
* Re-exports from @contractual/differs.json-schema package.
|
|
5
|
+
* This module provides JSON Schema structural diffing capabilities.
|
|
6
|
+
*/
|
|
7
|
+
// Re-export everything from the json-schema-differ package
|
|
8
|
+
export * from '@contractual/differs.json-schema';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../differs/json-schema/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,2DAA2D;AAC3D,cAAc,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAPI Differ using openapi-diff (native Node.js)
|
|
3
|
+
*
|
|
4
|
+
* Pure Node.js library for detecting breaking changes in OpenAPI specs.
|
|
5
|
+
* No binary dependencies required.
|
|
6
|
+
*
|
|
7
|
+
* @see https://www.npmjs.com/package/openapi-diff
|
|
8
|
+
*/
|
|
9
|
+
import type { DiffResult } from '@contractual/types';
|
|
10
|
+
/**
|
|
11
|
+
* Diff two OpenAPI specifications using openapi-diff
|
|
12
|
+
*/
|
|
13
|
+
export declare function diffOpenAPI(oldSpecPath: string, newSpecPath: string): Promise<DiffResult>;
|
|
14
|
+
/**
|
|
15
|
+
* Diff two OpenAPI spec objects directly (no file I/O)
|
|
16
|
+
*/
|
|
17
|
+
export declare function diffOpenAPIObjects(oldSpec: object, newSpec: object): Promise<DiffResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Quick check if specs have breaking changes
|
|
20
|
+
*/
|
|
21
|
+
export declare function hasOpenAPIBreakingChanges(oldSpec: object, newSpec: object): Promise<boolean>;
|
|
22
|
+
//# sourceMappingURL=openapi-diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-diff.d.ts","sourceRoot":"","sources":["../../differs/openapi-diff.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,UAAU,EAA0B,MAAM,oBAAoB,CAAC;AAoC7E;;GAEG;AACH,wBAAsB,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAkB/F;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAkB9F;AAED;;GAEG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC,CAGlB"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAPI Differ using openapi-diff (native Node.js)
|
|
3
|
+
*
|
|
4
|
+
* Pure Node.js library for detecting breaking changes in OpenAPI specs.
|
|
5
|
+
* No binary dependencies required.
|
|
6
|
+
*
|
|
7
|
+
* @see https://www.npmjs.com/package/openapi-diff
|
|
8
|
+
*/
|
|
9
|
+
import { readFile } from 'node:fs/promises';
|
|
10
|
+
import openapiDiff from 'openapi-diff';
|
|
11
|
+
/**
|
|
12
|
+
* Diff two OpenAPI specifications using openapi-diff
|
|
13
|
+
*/
|
|
14
|
+
export async function diffOpenAPI(oldSpecPath, newSpecPath) {
|
|
15
|
+
const oldContent = await readSpecFile(oldSpecPath);
|
|
16
|
+
const newContent = await readSpecFile(newSpecPath);
|
|
17
|
+
const result = await openapiDiff.diffSpecs({
|
|
18
|
+
sourceSpec: {
|
|
19
|
+
content: oldContent,
|
|
20
|
+
location: oldSpecPath,
|
|
21
|
+
format: detectFormat(oldContent),
|
|
22
|
+
},
|
|
23
|
+
destinationSpec: {
|
|
24
|
+
content: newContent,
|
|
25
|
+
location: newSpecPath,
|
|
26
|
+
format: detectFormat(newContent),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
return parseResult(result);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Diff two OpenAPI spec objects directly (no file I/O)
|
|
33
|
+
*/
|
|
34
|
+
export async function diffOpenAPIObjects(oldSpec, newSpec) {
|
|
35
|
+
const oldContent = JSON.stringify(oldSpec);
|
|
36
|
+
const newContent = JSON.stringify(newSpec);
|
|
37
|
+
const result = await openapiDiff.diffSpecs({
|
|
38
|
+
sourceSpec: {
|
|
39
|
+
content: oldContent,
|
|
40
|
+
location: 'old-spec.json',
|
|
41
|
+
format: detectFormatFromObject(oldSpec),
|
|
42
|
+
},
|
|
43
|
+
destinationSpec: {
|
|
44
|
+
content: newContent,
|
|
45
|
+
location: 'new-spec.json',
|
|
46
|
+
format: detectFormatFromObject(newSpec),
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return parseResult(result);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Quick check if specs have breaking changes
|
|
53
|
+
*/
|
|
54
|
+
export async function hasOpenAPIBreakingChanges(oldSpec, newSpec) {
|
|
55
|
+
const result = await diffOpenAPIObjects(oldSpec, newSpec);
|
|
56
|
+
return result.summary.breaking > 0;
|
|
57
|
+
}
|
|
58
|
+
// --- Internal helpers ---
|
|
59
|
+
async function readSpecFile(path) {
|
|
60
|
+
try {
|
|
61
|
+
return await readFile(path, 'utf-8');
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
throw new Error(`Failed to read spec "${path}": ${error instanceof Error ? error.message : String(error)}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function detectFormat(content) {
|
|
68
|
+
if (content.includes('openapi:') || content.includes('"openapi"')) {
|
|
69
|
+
return 'openapi3';
|
|
70
|
+
}
|
|
71
|
+
return 'swagger2';
|
|
72
|
+
}
|
|
73
|
+
function detectFormatFromObject(spec) {
|
|
74
|
+
const s = spec;
|
|
75
|
+
if (s.openapi && typeof s.openapi === 'string' && s.openapi.startsWith('3')) {
|
|
76
|
+
return 'openapi3';
|
|
77
|
+
}
|
|
78
|
+
return 'swagger2';
|
|
79
|
+
}
|
|
80
|
+
function parseResult(result) {
|
|
81
|
+
const breaking = result.breakingDifferencesFound ? result.breakingDifferences : [];
|
|
82
|
+
const nonBreaking = result.nonBreakingDifferences ?? [];
|
|
83
|
+
const unclassified = result.unclassifiedDifferences ?? [];
|
|
84
|
+
const changes = [
|
|
85
|
+
...breaking.map((d) => mapChange(d, 'breaking')),
|
|
86
|
+
...nonBreaking.map((d) => mapChange(d, 'non-breaking')),
|
|
87
|
+
...unclassified.map((d) => mapChange(d, 'unknown')),
|
|
88
|
+
];
|
|
89
|
+
const summary = {
|
|
90
|
+
breaking: breaking.length,
|
|
91
|
+
nonBreaking: nonBreaking.length,
|
|
92
|
+
patch: 0,
|
|
93
|
+
unknown: unclassified.length,
|
|
94
|
+
};
|
|
95
|
+
const suggestedBump = summary.breaking > 0 ? 'major' : summary.nonBreaking > 0 ? 'minor' : 'none';
|
|
96
|
+
return { contract: '', changes, summary, suggestedBump };
|
|
97
|
+
}
|
|
98
|
+
function mapChange(diff, severity) {
|
|
99
|
+
const srcDetails = diff.sourceSpecEntityDetails?.[0];
|
|
100
|
+
const destDetails = diff.destinationSpecEntityDetails?.[0];
|
|
101
|
+
const path = destDetails?.location || srcDetails?.location || '/';
|
|
102
|
+
// Generate human-readable message from code
|
|
103
|
+
const message = `${diff.action} ${diff.entity.replace(/\./g, ' ')} at ${path}`;
|
|
104
|
+
return {
|
|
105
|
+
path,
|
|
106
|
+
severity,
|
|
107
|
+
category: diff.code,
|
|
108
|
+
message,
|
|
109
|
+
oldValue: srcDetails?.value,
|
|
110
|
+
newValue: destDetails?.value,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=openapi-diff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-diff.js","sourceRoot":"","sources":["../../differs/openapi-diff.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,WAAW,MAAM,cAAc,CAAC;AAmCvC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,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,EAAE,IAAI,CAAC,IAAI;QACnB,OAAO;QACP,QAAQ,EAAE,UAAU,EAAE,KAAK;QAC3B,QAAQ,EAAE,WAAW,EAAE,KAAK;KAC7B,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Governance Engines
|
|
3
|
+
*
|
|
4
|
+
* Central module for all linting and diffing capabilities.
|
|
5
|
+
* Registers all built-in engines with the registry at import time.
|
|
6
|
+
*/
|
|
7
|
+
export { registerLinter, registerDiffer, getLinter, getDiffer, hasLinter, hasDiffer, getRegisteredLinterTypes, getRegisteredDifferTypes, } from './registry.js';
|
|
8
|
+
export type { Change, ChangeSeverity, DiffResult, DiffSummary, SuggestedBump, LintResult, LintIssue, LintSeverity, LintFn, DiffFn, ContractType, RawChange, ChangeType, } from '@contractual/types';
|
|
9
|
+
export { lintOpenAPI } from './linters/openapi-redocly.js';
|
|
10
|
+
export { lintJsonSchema } from './linters/json-schema-ajv.js';
|
|
11
|
+
export { diffOpenAPI, diffOpenAPIObjects, hasOpenAPIBreakingChanges, } from './differs/openapi-diff.js';
|
|
12
|
+
export { diffJsonSchema, diffJsonSchemaObjects, compareSchemas, checkCompatibility, classify, classifyPropertyAdded, classifyAll, CLASSIFICATION_SETS, resolveRefs, hasUnresolvedRefs, extractRefs, validateRefs, walk, formatChangeMessage, } from '@contractual/differs.json-schema';
|
|
13
|
+
export type { CompareResult, CompareOptions, StrandsTrace, StrandsCompatibility, StrandsVersion, SemanticVersion, JsonSchemaDraft, ResolvedSchema, ResolveResult, } from '@contractual/differs.json-schema';
|
|
14
|
+
export { executeCustomCommand, parseCustomLintOutput, parseCustomDiffOutput } from './runner.js';
|
|
15
|
+
/**
|
|
16
|
+
* Register all built-in governance engines
|
|
17
|
+
*
|
|
18
|
+
* Call this function at CLI startup to make all engines available
|
|
19
|
+
* through the registry.
|
|
20
|
+
*/
|
|
21
|
+
export declare function registerAllEngines(): void;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EACL,cAAc,EACd,cAAc,EACd,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,eAAe,CAAC;AAGvB,YAAY,EACV,MAAM,EACN,cAAc,EACd,UAAU,EACV,WAAW,EACX,aAAa,EACb,UAAU,EACV,SAAS,EACT,YAAY,EACZ,MAAM,EACN,MAAM,EACN,YAAY,EACZ,SAAS,EACT,UAAU,GACX,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,cAAc,EACd,kBAAkB,EAClB,QAAQ,EACR,qBAAqB,EACrB,WAAW,EACX,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,IAAI,EACJ,mBAAmB,GACpB,MAAM,kCAAkC,CAAC;AAE1C,YAAY,EACV,aAAa,EACb,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,eAAe,EACf,cAAc,EACd,aAAa,GACd,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEjG;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAczC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Governance Engines
|
|
3
|
+
*
|
|
4
|
+
* Central module for all linting and diffing capabilities.
|
|
5
|
+
* Registers all built-in engines with the registry at import time.
|
|
6
|
+
*/
|
|
7
|
+
import { registerLinter, registerDiffer } from './registry.js';
|
|
8
|
+
import { lintOpenAPI } from './linters/openapi-redocly.js';
|
|
9
|
+
import { lintJsonSchema } from './linters/json-schema-ajv.js';
|
|
10
|
+
import { diffOpenAPI } from './differs/openapi-diff.js';
|
|
11
|
+
import { diffJsonSchema } from '@contractual/differs.json-schema';
|
|
12
|
+
// Re-export registry functions
|
|
13
|
+
export { registerLinter, registerDiffer, getLinter, getDiffer, hasLinter, hasDiffer, getRegisteredLinterTypes, getRegisteredDifferTypes, } from './registry.js';
|
|
14
|
+
// Re-export linters
|
|
15
|
+
export { lintOpenAPI } from './linters/openapi-redocly.js';
|
|
16
|
+
export { lintJsonSchema } from './linters/json-schema-ajv.js';
|
|
17
|
+
// Re-export differs
|
|
18
|
+
export { diffOpenAPI, diffOpenAPIObjects, hasOpenAPIBreakingChanges, } from './differs/openapi-diff.js';
|
|
19
|
+
// Re-export everything from JSON Schema differ package
|
|
20
|
+
export { diffJsonSchema, diffJsonSchemaObjects, compareSchemas, checkCompatibility, classify, classifyPropertyAdded, classifyAll, CLASSIFICATION_SETS, resolveRefs, hasUnresolvedRefs, extractRefs, validateRefs, walk, formatChangeMessage, } from '@contractual/differs.json-schema';
|
|
21
|
+
// Re-export runner for custom commands
|
|
22
|
+
export { executeCustomCommand, parseCustomLintOutput, parseCustomDiffOutput } from './runner.js';
|
|
23
|
+
/**
|
|
24
|
+
* Register all built-in governance engines
|
|
25
|
+
*
|
|
26
|
+
* Call this function at CLI startup to make all engines available
|
|
27
|
+
* through the registry.
|
|
28
|
+
*/
|
|
29
|
+
export function registerAllEngines() {
|
|
30
|
+
// Register linters
|
|
31
|
+
registerLinter('openapi', lintOpenAPI);
|
|
32
|
+
registerLinter('json-schema', lintJsonSchema);
|
|
33
|
+
// Register differs
|
|
34
|
+
registerDiffer('openapi', diffOpenAPI);
|
|
35
|
+
registerDiffer('json-schema', diffJsonSchema);
|
|
36
|
+
// Phase 2:
|
|
37
|
+
// registerLinter('asyncapi', lintAsyncAPI);
|
|
38
|
+
// registerLinter('odcs', lintODCS);
|
|
39
|
+
// registerDiffer('asyncapi', diffAsyncAPI);
|
|
40
|
+
// registerDiffer('odcs', diffODCS);
|
|
41
|
+
}
|
|
42
|
+
// Auto-register on import
|
|
43
|
+
registerAllEngines();
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAElE,+BAA+B;AAC/B,OAAO,EACL,cAAc,EACd,cAAc,EACd,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,eAAe,CAAC;AAmBvB,oBAAoB;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,oBAAoB;AACpB,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AAEnC,uDAAuD;AACvD,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,cAAc,EACd,kBAAkB,EAClB,QAAQ,EACR,qBAAqB,EACrB,WAAW,EACX,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,IAAI,EACJ,mBAAmB,GACpB,MAAM,kCAAkC,CAAC;AAc1C,uCAAuC;AACvC,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEjG;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB;IAChC,mBAAmB;IACnB,cAAc,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACvC,cAAc,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;IAE9C,mBAAmB;IACnB,cAAc,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACvC,cAAc,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;IAE9C,WAAW;IACX,4CAA4C;IAC5C,oCAAoC;IACpC,4CAA4C;IAC5C,oCAAoC;AACtC,CAAC;AAED,0BAA0B;AAC1B,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linters - Export all linter implementations
|
|
3
|
+
*/
|
|
4
|
+
export { lintOpenAPI } from './openapi-redocly.js';
|
|
5
|
+
export { lintJsonSchema, lintJsonSchemaObject } from './json-schema-ajv.js';
|
|
6
|
+
export type { JsonSchemaLintOptions } from './json-schema-ajv.js';
|
|
7
|
+
export { runLintRules, getAvailableRules, getRuleDescription, LINT_RULES, } from './json-schema-rules.js';
|
|
8
|
+
export type { LintRule, SchemaNode } from './json-schema-rules.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../linters/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,YAAY,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAGlE,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,GACX,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linters - Export all linter implementations
|
|
3
|
+
*/
|
|
4
|
+
export { lintOpenAPI } from './openapi-redocly.js';
|
|
5
|
+
export { lintJsonSchema, lintJsonSchemaObject } from './json-schema-ajv.js';
|
|
6
|
+
// JSON Schema lint rules (for programmatic access)
|
|
7
|
+
export { runLintRules, getAvailableRules, getRuleDescription, LINT_RULES, } from './json-schema-rules.js';
|
|
8
|
+
// Phase 2:
|
|
9
|
+
// export { lintAsyncAPI } from './asyncapi-parser.js';
|
|
10
|
+
// export { lintODCS } from './odcs-ajv.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../linters/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAG5E,mDAAmD;AACnD,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,GACX,MAAM,wBAAwB,CAAC;AAGhC,WAAW;AACX,uDAAuD;AACvD,4CAA4C"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema Linter using ajv + custom rules
|
|
3
|
+
*
|
|
4
|
+
* Two-phase linting:
|
|
5
|
+
* 1. Meta-validation: Validates that the schema is itself valid JSON Schema (ajv)
|
|
6
|
+
* 2. Style rules: Checks for best practices, anti-patterns, and quality (custom rules)
|
|
7
|
+
*
|
|
8
|
+
* @see https://github.com/sourcemeta/jsonschema
|
|
9
|
+
* @see https://github.com/orgs/json-schema-org/discussions/323
|
|
10
|
+
*/
|
|
11
|
+
import type { LintResult, LintOptions } from '@contractual/types';
|
|
12
|
+
import type { SchemaNode } from './json-schema-rules.js';
|
|
13
|
+
/**
|
|
14
|
+
* Options for JSON Schema linting (extends base LintOptions)
|
|
15
|
+
*/
|
|
16
|
+
export interface JsonSchemaLintOptions extends LintOptions {
|
|
17
|
+
/** Rules to enable (if not specified, all rules are enabled) */
|
|
18
|
+
enabledRules?: Set<string>;
|
|
19
|
+
/** Rules to disable */
|
|
20
|
+
disabledRules?: Set<string>;
|
|
21
|
+
/** Skip meta-validation (ajv) */
|
|
22
|
+
skipMetaValidation?: boolean;
|
|
23
|
+
/** Skip style rules */
|
|
24
|
+
skipStyleRules?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Lint a JSON Schema using ajv meta-validation and custom style rules
|
|
28
|
+
*
|
|
29
|
+
* @param specPath - Path to the JSON Schema file
|
|
30
|
+
* @param options - Linting options
|
|
31
|
+
* @returns Lint result with errors and warnings
|
|
32
|
+
*/
|
|
33
|
+
export declare function lintJsonSchema(specPath: string, options?: JsonSchemaLintOptions): Promise<LintResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Lint a JSON Schema object directly (no file I/O)
|
|
36
|
+
*
|
|
37
|
+
* @param schema - JSON Schema object
|
|
38
|
+
* @param options - Linting options
|
|
39
|
+
* @returns Lint result with errors and warnings
|
|
40
|
+
*/
|
|
41
|
+
export declare function lintJsonSchemaObject(schema: SchemaNode, options?: JsonSchemaLintOptions): Promise<LintResult>;
|
|
42
|
+
//# sourceMappingURL=json-schema-ajv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema-ajv.d.ts","sourceRoot":"","sources":["../../linters/json-schema-ajv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAa,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAKzD;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,WAAW;IACxD,gEAAgE;IAChE,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3B,uBAAuB;IACvB,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5B,iCAAiC;IACjC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,uBAAuB;IACvB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,UAAU,CAAC,CAqFrB;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,UAAU,EAClB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,UAAU,CAAC,CA8CrB"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema Linter using ajv + custom rules
|
|
3
|
+
*
|
|
4
|
+
* Two-phase linting:
|
|
5
|
+
* 1. Meta-validation: Validates that the schema is itself valid JSON Schema (ajv)
|
|
6
|
+
* 2. Style rules: Checks for best practices, anti-patterns, and quality (custom rules)
|
|
7
|
+
*
|
|
8
|
+
* @see https://github.com/sourcemeta/jsonschema
|
|
9
|
+
* @see https://github.com/orgs/json-schema-org/discussions/323
|
|
10
|
+
*/
|
|
11
|
+
import { readFile } from 'node:fs/promises';
|
|
12
|
+
import Ajv from 'ajv';
|
|
13
|
+
import addFormats from 'ajv-formats';
|
|
14
|
+
import { runLintRules } from './json-schema-rules.js';
|
|
15
|
+
const AjvConstructor = Ajv.default ?? Ajv;
|
|
16
|
+
const addFormatsFunc = addFormats.default ?? addFormats;
|
|
17
|
+
/**
|
|
18
|
+
* Lint a JSON Schema using ajv meta-validation and custom style rules
|
|
19
|
+
*
|
|
20
|
+
* @param specPath - Path to the JSON Schema file
|
|
21
|
+
* @param options - Linting options
|
|
22
|
+
* @returns Lint result with errors and warnings
|
|
23
|
+
*/
|
|
24
|
+
export async function lintJsonSchema(specPath, options = {}) {
|
|
25
|
+
const errors = [];
|
|
26
|
+
const warnings = [];
|
|
27
|
+
let schema;
|
|
28
|
+
try {
|
|
29
|
+
const content = await readFile(specPath, 'utf-8');
|
|
30
|
+
schema = JSON.parse(content);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const message = error instanceof Error ? error.message : 'Unknown error reading schema';
|
|
34
|
+
errors.push({
|
|
35
|
+
path: '/',
|
|
36
|
+
message: `Failed to read or parse schema: ${message}`,
|
|
37
|
+
rule: 'parse-error',
|
|
38
|
+
severity: 'error',
|
|
39
|
+
});
|
|
40
|
+
return { contract: '', specPath, errors, warnings };
|
|
41
|
+
}
|
|
42
|
+
// Phase 1: Meta-validation using ajv
|
|
43
|
+
if (!options.skipMetaValidation) {
|
|
44
|
+
const ajv = new AjvConstructor({
|
|
45
|
+
allErrors: true,
|
|
46
|
+
strict: false,
|
|
47
|
+
validateSchema: true,
|
|
48
|
+
});
|
|
49
|
+
addFormatsFunc(ajv);
|
|
50
|
+
const valid = ajv.validateSchema(schema);
|
|
51
|
+
if (!valid && ajv.errors) {
|
|
52
|
+
for (const err of ajv.errors) {
|
|
53
|
+
errors.push({
|
|
54
|
+
path: err.instancePath || '/',
|
|
55
|
+
message: `${err.keyword}: ${err.message}`,
|
|
56
|
+
rule: `meta:${err.keyword}`,
|
|
57
|
+
severity: 'error',
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Phase 2: Style rules
|
|
63
|
+
if (!options.skipStyleRules) {
|
|
64
|
+
const styleIssues = runLintRules(schema, options.enabledRules, options.disabledRules);
|
|
65
|
+
// Partition into errors and warnings
|
|
66
|
+
for (const issue of styleIssues) {
|
|
67
|
+
if (issue.severity === 'error') {
|
|
68
|
+
errors.push(issue);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
warnings.push(issue);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Additional meta-level warnings
|
|
76
|
+
// Warn about unknown $schema versions
|
|
77
|
+
if (schema.$schema && typeof schema.$schema === 'string') {
|
|
78
|
+
const schemaUri = schema.$schema;
|
|
79
|
+
const supportedDrafts = ['draft-04', 'draft-06', 'draft-07', 'draft/2019-09', 'draft/2020-12'];
|
|
80
|
+
const isKnown = supportedDrafts.some((draft) => schemaUri.includes(draft) || schemaUri.includes(draft.replace('draft-', 'draft/')));
|
|
81
|
+
if (!isKnown && !schemaUri.includes('json-schema.org')) {
|
|
82
|
+
warnings.push({
|
|
83
|
+
path: '/$schema',
|
|
84
|
+
message: `Unknown schema draft: ${schemaUri}. Validation may be incomplete.`,
|
|
85
|
+
rule: 'unknown-draft',
|
|
86
|
+
severity: 'warning',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
contract: '',
|
|
92
|
+
specPath,
|
|
93
|
+
errors,
|
|
94
|
+
warnings,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Lint a JSON Schema object directly (no file I/O)
|
|
99
|
+
*
|
|
100
|
+
* @param schema - JSON Schema object
|
|
101
|
+
* @param options - Linting options
|
|
102
|
+
* @returns Lint result with errors and warnings
|
|
103
|
+
*/
|
|
104
|
+
export async function lintJsonSchemaObject(schema, options = {}) {
|
|
105
|
+
const errors = [];
|
|
106
|
+
const warnings = [];
|
|
107
|
+
// Phase 1: Meta-validation using ajv
|
|
108
|
+
if (!options.skipMetaValidation) {
|
|
109
|
+
const ajv = new AjvConstructor({
|
|
110
|
+
allErrors: true,
|
|
111
|
+
strict: false,
|
|
112
|
+
validateSchema: true,
|
|
113
|
+
});
|
|
114
|
+
addFormatsFunc(ajv);
|
|
115
|
+
const valid = ajv.validateSchema(schema);
|
|
116
|
+
if (!valid && ajv.errors) {
|
|
117
|
+
for (const err of ajv.errors) {
|
|
118
|
+
errors.push({
|
|
119
|
+
path: err.instancePath || '/',
|
|
120
|
+
message: `${err.keyword}: ${err.message}`,
|
|
121
|
+
rule: `meta:${err.keyword}`,
|
|
122
|
+
severity: 'error',
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Phase 2: Style rules
|
|
128
|
+
if (!options.skipStyleRules) {
|
|
129
|
+
const styleIssues = runLintRules(schema, options.enabledRules, options.disabledRules);
|
|
130
|
+
for (const issue of styleIssues) {
|
|
131
|
+
if (issue.severity === 'error') {
|
|
132
|
+
errors.push(issue);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
warnings.push(issue);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
contract: '',
|
|
141
|
+
specPath: '',
|
|
142
|
+
errors,
|
|
143
|
+
warnings,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=json-schema-ajv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema-ajv.js","sourceRoot":"","sources":["../../linters/json-schema-ajv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,UAAU,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGtD,MAAM,cAAc,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC;AAC1C,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,IAAI,UAAU,CAAC;AAgBxD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,QAAgB,EAChB,UAAiC,EAAE;IAEnC,MAAM,MAAM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MAAM,KAAK,IAAI,WAAW,EAAE,CAAC;YAChC,IAAI,KAAK,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;gBAC/B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrB,CAAC;iBAAM,CAAC;gBACN,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,EAAE;QACZ,QAAQ,EAAE,EAAE;QACZ,MAAM;QACN,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema Linting Rules
|
|
3
|
+
*
|
|
4
|
+
* Native TypeScript implementation of linting rules for JSON Schema.
|
|
5
|
+
* Based on best practices from Sourcemeta, JSON Schema org, and community discussions.
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/sourcemeta/jsonschema
|
|
8
|
+
* @see https://github.com/orgs/json-schema-org/discussions/323
|
|
9
|
+
*/
|
|
10
|
+
import type { LintIssue, LintSeverity } from '@contractual/types';
|
|
11
|
+
import { type ResolvedSchema } from '@contractual/differs.json-schema';
|
|
12
|
+
export type { ResolvedSchema as SchemaNode } from '@contractual/differs.json-schema';
|
|
13
|
+
/**
|
|
14
|
+
* Lint rule definition
|
|
15
|
+
*/
|
|
16
|
+
export interface LintRule {
|
|
17
|
+
/** Rule identifier */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Human-readable description */
|
|
20
|
+
description: string;
|
|
21
|
+
/** Default severity */
|
|
22
|
+
severity: LintSeverity;
|
|
23
|
+
/** Check function - returns issues found at this schema node */
|
|
24
|
+
check: (schema: ResolvedSchema, path: string, root: ResolvedSchema) => LintIssue[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* All built-in linting rules
|
|
28
|
+
*/
|
|
29
|
+
export declare const LINT_RULES: LintRule[];
|
|
30
|
+
/**
|
|
31
|
+
* Run all lint rules against a schema, recursively walking all subschemas
|
|
32
|
+
*/
|
|
33
|
+
export declare function runLintRules(schema: ResolvedSchema, enabledRules?: Set<string>, disabledRules?: Set<string>): LintIssue[];
|
|
34
|
+
/**
|
|
35
|
+
* Get all available rule IDs
|
|
36
|
+
*/
|
|
37
|
+
export declare function getAvailableRules(): string[];
|
|
38
|
+
/**
|
|
39
|
+
* Get rule description by ID
|
|
40
|
+
*/
|
|
41
|
+
export declare function getRuleDescription(ruleId: string): string | undefined;
|
|
42
|
+
//# sourceMappingURL=json-schema-rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema-rules.d.ts","sourceRoot":"","sources":["../../linters/json-schema-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,KAAK,cAAc,EAAkB,MAAM,kCAAkC,CAAC;AAGvF,YAAY,EAAE,cAAc,IAAI,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAErF;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,sBAAsB;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,uBAAuB;IACvB,QAAQ,EAAE,YAAY,CAAC;IACvB,gEAAgE;IAChE,KAAK,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,KAAK,SAAS,EAAE,CAAC;CACpF;AAkED;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,QAAQ,EA2kBhC,CAAC;AAEF;;GAEG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,cAAc,EACtB,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAC1B,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAC1B,SAAS,EAAE,CAgBb;AAiHD;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,EAAE,CAE5C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAErE"}
|