@philiprehberger/schema-diff 0.1.5
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/README.md +61 -0
- package/dist/index.cjs +68 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 philiprehberger
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @philiprehberger/schema-diff
|
|
2
|
+
|
|
3
|
+
[](https://github.com/philiprehberger/ts-schema-diff/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@philiprehberger/schema-diff)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Compare JSON schemas and detect breaking changes
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @philiprehberger/schema-diff
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { diffSchemas } from '@philiprehberger/schema-diff';
|
|
19
|
+
|
|
20
|
+
const changes = diffSchemas(
|
|
21
|
+
{ name: { type: 'string' }, email: { type: 'string' } },
|
|
22
|
+
{ name: { type: 'string' }, age: { type: 'number' } },
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// [
|
|
26
|
+
// { path: 'email', type: 'removed', breaking: true, message: 'Removed "email"' },
|
|
27
|
+
// { path: 'age', type: 'added', breaking: false, message: 'Added "age"' },
|
|
28
|
+
// ]
|
|
29
|
+
|
|
30
|
+
const hasBreaking = changes.some(c => c.breaking);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## API
|
|
34
|
+
|
|
35
|
+
| Export | Description |
|
|
36
|
+
|--------|-------------|
|
|
37
|
+
| `diffSchemas(before, after)` | Deep-compare two schemas, returns `SchemaChange[]` |
|
|
38
|
+
|
|
39
|
+
### `SchemaChange`
|
|
40
|
+
|
|
41
|
+
| Property | Type | Description |
|
|
42
|
+
|----------|------|-------------|
|
|
43
|
+
| `path` | `string` | Dot-separated path |
|
|
44
|
+
| `type` | `'added' \| 'removed' \| 'changed'` | Change type |
|
|
45
|
+
| `breaking` | `boolean` | Whether the change is breaking |
|
|
46
|
+
| `before` | `unknown` | Previous value |
|
|
47
|
+
| `after` | `unknown` | New value |
|
|
48
|
+
| `message` | `string` | Human-readable description |
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## Development
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm install
|
|
55
|
+
npm run build
|
|
56
|
+
npm test
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/diff.ts
|
|
4
|
+
function isObject(val) {
|
|
5
|
+
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
6
|
+
}
|
|
7
|
+
function diffObjects(before, after, path, changes) {
|
|
8
|
+
const allKeys = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
9
|
+
for (const key of allKeys) {
|
|
10
|
+
const fullPath = path ? `${path}.${key}` : key;
|
|
11
|
+
const inBefore = key in before;
|
|
12
|
+
const inAfter = key in after;
|
|
13
|
+
if (inBefore && !inAfter) {
|
|
14
|
+
changes.push({
|
|
15
|
+
path: fullPath,
|
|
16
|
+
type: "removed",
|
|
17
|
+
breaking: true,
|
|
18
|
+
before: before[key],
|
|
19
|
+
message: `Removed "${fullPath}"`
|
|
20
|
+
});
|
|
21
|
+
} else if (!inBefore && inAfter) {
|
|
22
|
+
changes.push({
|
|
23
|
+
path: fullPath,
|
|
24
|
+
type: "added",
|
|
25
|
+
breaking: false,
|
|
26
|
+
after: after[key],
|
|
27
|
+
message: `Added "${fullPath}"`
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
const bVal = before[key];
|
|
31
|
+
const aVal = after[key];
|
|
32
|
+
if (isObject(bVal) && isObject(aVal)) {
|
|
33
|
+
diffObjects(bVal, aVal, fullPath, changes);
|
|
34
|
+
} else if (Array.isArray(bVal) && Array.isArray(aVal)) {
|
|
35
|
+
if (JSON.stringify(bVal) !== JSON.stringify(aVal)) {
|
|
36
|
+
changes.push({
|
|
37
|
+
path: fullPath,
|
|
38
|
+
type: "changed",
|
|
39
|
+
breaking: true,
|
|
40
|
+
before: bVal,
|
|
41
|
+
after: aVal,
|
|
42
|
+
message: `Changed "${fullPath}"`
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
} else if (bVal !== aVal) {
|
|
46
|
+
const isTypeChange = key === "type";
|
|
47
|
+
const isRequiredChange = key === "required" && aVal === true && bVal !== true;
|
|
48
|
+
changes.push({
|
|
49
|
+
path: fullPath,
|
|
50
|
+
type: "changed",
|
|
51
|
+
breaking: isTypeChange || isRequiredChange,
|
|
52
|
+
before: bVal,
|
|
53
|
+
after: aVal,
|
|
54
|
+
message: `Changed "${fullPath}" from ${JSON.stringify(bVal)} to ${JSON.stringify(aVal)}`
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function diffSchemas(before, after) {
|
|
61
|
+
const changes = [];
|
|
62
|
+
diffObjects(before, after, "", changes);
|
|
63
|
+
return changes;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.diffSchemas = diffSchemas;
|
|
67
|
+
//# sourceMappingURL=index.cjs.map
|
|
68
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/diff.ts"],"names":[],"mappings":";;;AAEA,SAAS,SAAS,GAAA,EAA8C;AAC9D,EAAA,OAAO,GAAA,KAAQ,QAAQ,OAAO,GAAA,KAAQ,YAAY,CAAC,KAAA,CAAM,QAAQ,GAAG,CAAA;AACtE;AAEA,SAAS,WAAA,CACP,MAAA,EACA,KAAA,EACA,IAAA,EACA,OAAA,EACM;AACN,EAAA,MAAM,OAAA,mBAAU,IAAI,GAAA,CAAI,CAAC,GAAG,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA,EAAG,GAAG,MAAA,CAAO,IAAA,CAAK,KAAK,CAAC,CAAC,CAAA;AAEvE,EAAA,KAAA,MAAW,OAAO,OAAA,EAAS;AACzB,IAA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,OAAA,CAAQ,IAAA,CAAK;AAAA,YACX,IAAA,EAAM,QAAA;AAAA,YACN,IAAA,EAAM,SAAA;AAAA,YACN,QAAA,EAAU,IAAA;AAAA,YACV,MAAA,EAAQ,IAAA;AAAA,YACR,KAAA,EAAO,IAAA;AAAA,YACP,OAAA,EAAS,YAAY,QAAQ,CAAA,CAAA;AAAA,WAC9B,CAAA;AAAA,QACH;AAAA,MACF,CAAA,MAAA,IAAW,SAAS,IAAA,EAAM;AACxB,QAAA,MAAM,eAAe,GAAA,KAAQ,MAAA;AAC7B,QAAA,MAAM,gBAAA,GAAmB,GAAA,KAAQ,UAAA,IAAc,IAAA,KAAS,QAAQ,IAAA,KAAS,IAAA;AACzE,QAAA,OAAA,CAAQ,IAAA,CAAK;AAAA,UACX,IAAA,EAAM,QAAA;AAAA,UACN,IAAA,EAAM,SAAA;AAAA,UACN,UAAU,YAAA,IAAgB,gBAAA;AAAA,UAC1B,MAAA,EAAQ,IAAA;AAAA,UACR,KAAA,EAAO,IAAA;AAAA,UACP,OAAA,EAAS,CAAA,SAAA,EAAY,QAAQ,CAAA,OAAA,EAAU,IAAA,CAAK,SAAA,CAAU,IAAI,CAAC,CAAA,IAAA,EAAO,IAAA,CAAK,SAAA,CAAU,IAAI,CAAC,CAAA;AAAA,SACvF,CAAA;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,WAAA,CAAY,QAAoB,KAAA,EAAmC;AACjF,EAAA,MAAM,UAA0B,EAAC;AACjC,EAAA,WAAA,CAAY,MAAA,EAAQ,KAAA,EAAO,EAAA,EAAI,OAAO,CAAA;AACtC,EAAA,OAAO,OAAA;AACT","file":"index.cjs","sourcesContent":["import type { SchemaChange, JsonSchema } from './types.js';\n\nfunction isObject(val: unknown): val is Record<string, unknown> {\n return val !== null && typeof val === 'object' && !Array.isArray(val);\n}\n\nfunction diffObjects(\n before: Record<string, unknown>,\n after: Record<string, unknown>,\n path: string,\n changes: SchemaChange[],\n): void {\n const allKeys = new Set([...Object.keys(before), ...Object.keys(after)]);\n\n for (const key of allKeys) {\n const fullPath = path ? `${path}.${key}` : key;\n const inBefore = key in before;\n const inAfter = key in after;\n\n if (inBefore && !inAfter) {\n changes.push({\n path: fullPath,\n type: 'removed',\n breaking: true,\n before: before[key],\n message: `Removed \"${fullPath}\"`,\n });\n } else if (!inBefore && inAfter) {\n changes.push({\n path: fullPath,\n type: 'added',\n breaking: false,\n after: after[key],\n message: `Added \"${fullPath}\"`,\n });\n } else {\n const bVal = before[key];\n const aVal = after[key];\n\n if (isObject(bVal) && isObject(aVal)) {\n diffObjects(bVal, aVal, fullPath, changes);\n } else if (Array.isArray(bVal) && Array.isArray(aVal)) {\n if (JSON.stringify(bVal) !== JSON.stringify(aVal)) {\n changes.push({\n path: fullPath,\n type: 'changed',\n breaking: true,\n before: bVal,\n after: aVal,\n message: `Changed \"${fullPath}\"`,\n });\n }\n } else if (bVal !== aVal) {\n const isTypeChange = key === 'type';\n const isRequiredChange = key === 'required' && aVal === true && bVal !== true;\n changes.push({\n path: fullPath,\n type: 'changed',\n breaking: isTypeChange || isRequiredChange,\n before: bVal,\n after: aVal,\n message: `Changed \"${fullPath}\" from ${JSON.stringify(bVal)} to ${JSON.stringify(aVal)}`,\n });\n }\n }\n }\n}\n\nexport function diffSchemas(before: JsonSchema, after: JsonSchema): SchemaChange[] {\n const changes: SchemaChange[] = [];\n diffObjects(before, after, '', changes);\n return changes;\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type ChangeType = 'added' | 'removed' | 'changed';
|
|
2
|
+
interface SchemaChange {
|
|
3
|
+
path: string;
|
|
4
|
+
type: ChangeType;
|
|
5
|
+
breaking: boolean;
|
|
6
|
+
before?: unknown;
|
|
7
|
+
after?: unknown;
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
type JsonSchema = Record<string, unknown>;
|
|
11
|
+
|
|
12
|
+
declare function diffSchemas(before: JsonSchema, after: JsonSchema): SchemaChange[];
|
|
13
|
+
|
|
14
|
+
export { type ChangeType, type JsonSchema, type SchemaChange, diffSchemas };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type ChangeType = 'added' | 'removed' | 'changed';
|
|
2
|
+
interface SchemaChange {
|
|
3
|
+
path: string;
|
|
4
|
+
type: ChangeType;
|
|
5
|
+
breaking: boolean;
|
|
6
|
+
before?: unknown;
|
|
7
|
+
after?: unknown;
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
type JsonSchema = Record<string, unknown>;
|
|
11
|
+
|
|
12
|
+
declare function diffSchemas(before: JsonSchema, after: JsonSchema): SchemaChange[];
|
|
13
|
+
|
|
14
|
+
export { type ChangeType, type JsonSchema, type SchemaChange, diffSchemas };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// src/diff.ts
|
|
2
|
+
function isObject(val) {
|
|
3
|
+
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
4
|
+
}
|
|
5
|
+
function diffObjects(before, after, path, changes) {
|
|
6
|
+
const allKeys = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
7
|
+
for (const key of allKeys) {
|
|
8
|
+
const fullPath = path ? `${path}.${key}` : key;
|
|
9
|
+
const inBefore = key in before;
|
|
10
|
+
const inAfter = key in after;
|
|
11
|
+
if (inBefore && !inAfter) {
|
|
12
|
+
changes.push({
|
|
13
|
+
path: fullPath,
|
|
14
|
+
type: "removed",
|
|
15
|
+
breaking: true,
|
|
16
|
+
before: before[key],
|
|
17
|
+
message: `Removed "${fullPath}"`
|
|
18
|
+
});
|
|
19
|
+
} else if (!inBefore && inAfter) {
|
|
20
|
+
changes.push({
|
|
21
|
+
path: fullPath,
|
|
22
|
+
type: "added",
|
|
23
|
+
breaking: false,
|
|
24
|
+
after: after[key],
|
|
25
|
+
message: `Added "${fullPath}"`
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
const bVal = before[key];
|
|
29
|
+
const aVal = after[key];
|
|
30
|
+
if (isObject(bVal) && isObject(aVal)) {
|
|
31
|
+
diffObjects(bVal, aVal, fullPath, changes);
|
|
32
|
+
} else if (Array.isArray(bVal) && Array.isArray(aVal)) {
|
|
33
|
+
if (JSON.stringify(bVal) !== JSON.stringify(aVal)) {
|
|
34
|
+
changes.push({
|
|
35
|
+
path: fullPath,
|
|
36
|
+
type: "changed",
|
|
37
|
+
breaking: true,
|
|
38
|
+
before: bVal,
|
|
39
|
+
after: aVal,
|
|
40
|
+
message: `Changed "${fullPath}"`
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
} else if (bVal !== aVal) {
|
|
44
|
+
const isTypeChange = key === "type";
|
|
45
|
+
const isRequiredChange = key === "required" && aVal === true && bVal !== true;
|
|
46
|
+
changes.push({
|
|
47
|
+
path: fullPath,
|
|
48
|
+
type: "changed",
|
|
49
|
+
breaking: isTypeChange || isRequiredChange,
|
|
50
|
+
before: bVal,
|
|
51
|
+
after: aVal,
|
|
52
|
+
message: `Changed "${fullPath}" from ${JSON.stringify(bVal)} to ${JSON.stringify(aVal)}`
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function diffSchemas(before, after) {
|
|
59
|
+
const changes = [];
|
|
60
|
+
diffObjects(before, after, "", changes);
|
|
61
|
+
return changes;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { diffSchemas };
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/diff.ts"],"names":[],"mappings":";AAEA,SAAS,SAAS,GAAA,EAA8C;AAC9D,EAAA,OAAO,GAAA,KAAQ,QAAQ,OAAO,GAAA,KAAQ,YAAY,CAAC,KAAA,CAAM,QAAQ,GAAG,CAAA;AACtE;AAEA,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AAA,EAAO,EAAA,EAAI,OAAO,CAAA;AACtC,EAAA,OAAO,OAAA;AACT","file":"index.js","sourcesContent":["import type { SchemaChange, JsonSchema } from './types.js';\n\nfunction isObject(val: unknown): val is Record<string, unknown> {\n return val !== null && typeof val === 'object' && !Array.isArray(val);\n}\n\nfunction diffObjects(\n before: Record<string, unknown>,\n after: Record<string, unknown>,\n path: string,\n changes: SchemaChange[],\n): void {\n const allKeys = new Set([...Object.keys(before), ...Object.keys(after)]);\n\n for (const key of allKeys) {\n const fullPath = path ? `${path}.${key}` : key;\n const inBefore = key in before;\n const inAfter = key in after;\n\n if (inBefore && !inAfter) {\n changes.push({\n path: fullPath,\n type: 'removed',\n breaking: true,\n before: before[key],\n message: `Removed \"${fullPath}\"`,\n });\n } else if (!inBefore && inAfter) {\n changes.push({\n path: fullPath,\n type: 'added',\n breaking: false,\n after: after[key],\n message: `Added \"${fullPath}\"`,\n });\n } else {\n const bVal = before[key];\n const aVal = after[key];\n\n if (isObject(bVal) && isObject(aVal)) {\n diffObjects(bVal, aVal, fullPath, changes);\n } else if (Array.isArray(bVal) && Array.isArray(aVal)) {\n if (JSON.stringify(bVal) !== JSON.stringify(aVal)) {\n changes.push({\n path: fullPath,\n type: 'changed',\n breaking: true,\n before: bVal,\n after: aVal,\n message: `Changed \"${fullPath}\"`,\n });\n }\n } else if (bVal !== aVal) {\n const isTypeChange = key === 'type';\n const isRequiredChange = key === 'required' && aVal === true && bVal !== true;\n changes.push({\n path: fullPath,\n type: 'changed',\n breaking: isTypeChange || isRequiredChange,\n before: bVal,\n after: aVal,\n message: `Changed \"${fullPath}\" from ${JSON.stringify(bVal)} to ${JSON.stringify(aVal)}`,\n });\n }\n }\n }\n}\n\nexport function diffSchemas(before: JsonSchema, after: JsonSchema): SchemaChange[] {\n const changes: SchemaChange[] = [];\n diffObjects(before, after, '', changes);\n return changes;\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@philiprehberger/schema-diff",
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "Compare JSON schemas and detect breaking changes",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"dev": "tsup --watch",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"prepublishOnly": "npm run build",
|
|
29
|
+
"test": "node --test"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"tsup": "^8.0.0",
|
|
33
|
+
"typescript": "^5.0.0"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"schema",
|
|
37
|
+
"diff",
|
|
38
|
+
"breaking-change",
|
|
39
|
+
"api",
|
|
40
|
+
"contract",
|
|
41
|
+
"json-schema"
|
|
42
|
+
],
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/philiprehberger/ts-schema-diff.git"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/philiprehberger/ts-schema-diff#readme",
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/philiprehberger/ts-schema-diff/issues"
|
|
51
|
+
},
|
|
52
|
+
"author": "Philip Rehberger",
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=18.0.0"
|
|
55
|
+
},
|
|
56
|
+
"sideEffects": false
|
|
57
|
+
}
|