@revisium/schema-toolkit 0.5.0 → 0.9.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/README.md +34 -156
- package/dist/{chunk-7LKKRGZG.js → chunk-DFL3HJ4Y.js} +218 -126
- package/dist/chunk-DFL3HJ4Y.js.map +1 -0
- package/dist/chunk-GF3XXYOS.cjs +13 -0
- package/dist/chunk-GF3XXYOS.cjs.map +1 -0
- package/dist/chunk-KJCURW4D.js +11 -0
- package/dist/chunk-KJCURW4D.js.map +1 -0
- package/dist/{chunk-EJAKPKHS.cjs → chunk-QAIYSZIR.cjs} +218 -125
- package/dist/chunk-QAIYSZIR.cjs.map +1 -0
- package/dist/chunk-SBJFTOWW.js +3 -0
- package/dist/{chunk-DEPJRTVT.js.map → chunk-SBJFTOWW.js.map} +1 -1
- package/dist/chunk-XAFOMEOK.cjs +4 -0
- package/dist/{chunk-FD57PCAC.cjs.map → chunk-XAFOMEOK.cjs.map} +1 -1
- package/dist/index.cjs +43 -34
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/lib/index.cjs +38 -33
- package/dist/lib/index.d.cts +4 -1
- package/dist/lib/index.d.ts +4 -1
- package/dist/lib/index.js +2 -1
- package/dist/types/index.cjs +6 -1
- package/dist/types/index.d.cts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +2 -1
- package/dist/value-diff.types-BRoI_kGE.d.cts +13 -0
- package/dist/value-diff.types-BRoI_kGE.d.ts +13 -0
- package/package.json +2 -2
- package/dist/chunk-7LKKRGZG.js.map +0 -1
- package/dist/chunk-DEPJRTVT.js +0 -3
- package/dist/chunk-EJAKPKHS.cjs.map +0 -1
- package/dist/chunk-FD57PCAC.cjs +0 -4
package/README.md
CHANGED
|
@@ -4,181 +4,59 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://sonarcloud.io/summary/new_code?id=revisium_schema-toolkit)
|
|
6
6
|
[](https://codecov.io/gh/revisium/schema-toolkit)
|
|
7
|
-
[](https://github.com/revisium/
|
|
7
|
+
[](https://github.com/revisium/schema-toolkit/blob/master/LICENSE)
|
|
8
8
|
[](https://github.com/revisium/schema-toolkit/releases)
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Framework-agnostic TypeScript types, system schemas, runtime stores, and utilities for working with JSON Schema in [Revisium](https://revisium.io) projects.
|
|
11
11
|
|
|
12
12
|
</div>
|
|
13
13
|
|
|
14
|
-
## Overview
|
|
15
|
-
|
|
16
|
-
`@revisium/schema-toolkit` provides framework-agnostic TypeScript types, system schemas, runtime stores, utilities, and testing helpers for working with JSON Schema in Revisium projects. This package contains shared code used by `revisium-core`, `revisium-endpoint`, and `revisium-admin`.
|
|
17
|
-
|
|
18
|
-
## Features
|
|
19
|
-
|
|
20
|
-
- 🎯 **TypeScript Types** - Complete type definitions for JSON Schema, JSON Patch, JSON Value Patch, and migrations
|
|
21
|
-
- 🔧 **System Schemas** - Pre-defined schemas for Revisium system fields (row ID, timestamps, file handling, etc.)
|
|
22
|
-
- 🏪 **Runtime Stores** - Schema and value store classes for runtime manipulation
|
|
23
|
-
- 🛠️ **Utilities** - 18+ utility functions for schema operations, patches, foreign keys, and more
|
|
24
|
-
- 🧪 **Test Utilities** - Helper functions for generating mock schemas in tests
|
|
25
|
-
- ✅ **Validation Schemas** - Ajv-compatible validation schemas (optional)
|
|
26
|
-
- 🌐 **Framework Agnostic** - No dependencies on backend/frontend frameworks (only `nanoid` for ID generation)
|
|
27
|
-
- 📦 **Tree-shakeable** - Use only what you need with ES modules
|
|
28
|
-
|
|
29
14
|
## Installation
|
|
30
15
|
|
|
31
16
|
```bash
|
|
32
17
|
npm install @revisium/schema-toolkit
|
|
33
18
|
```
|
|
34
19
|
|
|
35
|
-
##
|
|
20
|
+
## API
|
|
36
21
|
|
|
37
|
-
###
|
|
22
|
+
### Schema
|
|
38
23
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
24
|
+
| Function | Description |
|
|
25
|
+
|----------|-------------|
|
|
26
|
+
| `createJsonSchemaStore` | Create runtime schema store |
|
|
27
|
+
| `getJsonSchemaStoreByPath` | Navigate schema by path |
|
|
28
|
+
| `applyPatches` | Apply JSON Patch operations to schema |
|
|
29
|
+
| `resolveRefs` | Resolve $ref to inline schemas |
|
|
30
|
+
| `validateJsonFieldName` | Validate field name format |
|
|
31
|
+
| `getInvalidFieldNamesInSchema` | Find invalid field names in schema |
|
|
45
32
|
|
|
46
|
-
|
|
47
|
-
type: JsonSchemaTypeName.Object,
|
|
48
|
-
properties: {
|
|
49
|
-
name: { type: JsonSchemaTypeName.String, default: '' },
|
|
50
|
-
age: { type: JsonSchemaTypeName.Number, default: 0 },
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
```
|
|
33
|
+
### Value
|
|
54
34
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
fileSchema,
|
|
62
|
-
} from '@revisium/schema-toolkit/plugins';
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Model Stores
|
|
66
|
-
|
|
67
|
-
```typescript
|
|
68
|
-
import {
|
|
69
|
-
createJsonSchemaStore,
|
|
70
|
-
createJsonValueStore,
|
|
71
|
-
} from '@revisium/schema-toolkit/lib';
|
|
72
|
-
|
|
73
|
-
// Create schema store
|
|
74
|
-
const schemaStore = createJsonSchemaStore({
|
|
75
|
-
type: 'object',
|
|
76
|
-
properties: {
|
|
77
|
-
name: { type: 'string', default: '' },
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// Create value store
|
|
82
|
-
const valueStore = createJsonValueStore(
|
|
83
|
-
schemaStore,
|
|
84
|
-
'row-id-123',
|
|
85
|
-
{ name: 'John' }
|
|
86
|
-
);
|
|
87
|
-
```
|
|
35
|
+
| Function | Description |
|
|
36
|
+
|----------|-------------|
|
|
37
|
+
| `createJsonValueStore` | Create runtime value store |
|
|
38
|
+
| `getJsonValueByPath` | Navigate value by path |
|
|
39
|
+
| `computeValueDiff` | Compute field-level diff between two values |
|
|
40
|
+
| `traverseValue` | Traverse value tree |
|
|
88
41
|
|
|
89
|
-
###
|
|
42
|
+
### Foreign Keys
|
|
90
43
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// Apply JSON patches to schema
|
|
99
|
-
const updatedSchema = applyPatches(schema, patches);
|
|
100
|
-
|
|
101
|
-
// Get foreign keys from schema
|
|
102
|
-
const foreignKeys = getForeignKeysFromSchema(schemaStore);
|
|
103
|
-
|
|
104
|
-
// Resolve $ref in schemas (endpoint feature)
|
|
105
|
-
const resolved = resolveRefs(schemaWithRefs);
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
### Test Utilities
|
|
109
|
-
|
|
110
|
-
```typescript
|
|
111
|
-
import {
|
|
112
|
-
getStringSchema,
|
|
113
|
-
getObjectSchema,
|
|
114
|
-
getRefSchema,
|
|
115
|
-
} from '@revisium/schema-toolkit/mocks';
|
|
116
|
-
|
|
117
|
-
const mockSchema = getObjectSchema({
|
|
118
|
-
name: getStringSchema(),
|
|
119
|
-
userId: getStringSchema({ foreignKey: 'User' }),
|
|
120
|
-
avatar: getRefSchema('File'),
|
|
121
|
-
});
|
|
122
|
-
```
|
|
44
|
+
| Function | Description |
|
|
45
|
+
|----------|-------------|
|
|
46
|
+
| `getForeignKeysFromSchema` | Extract foreign keys from schema |
|
|
47
|
+
| `getForeignKeysFromValue` | Extract foreign key values from data |
|
|
48
|
+
| `getForeignKeyPatchesFromSchema` | Get patches for foreign key changes |
|
|
49
|
+
| `replaceForeignKeyValue` | Replace foreign key references |
|
|
123
50
|
|
|
124
|
-
|
|
51
|
+
### Path Utils
|
|
125
52
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
- `@revisium/schema-toolkit/consts` - Constants (CustomSchemeKeywords, SystemSchemaIds)
|
|
133
|
-
- `@revisium/schema-toolkit/model` - Schema and value stores
|
|
134
|
-
- `@revisium/schema-toolkit/lib` - Utility functions
|
|
135
|
-
- `@revisium/schema-toolkit/validation-schemas` - Ajv validation schemas
|
|
136
|
-
|
|
137
|
-
### Key Utilities
|
|
138
|
-
|
|
139
|
-
**Schema Operations:**
|
|
140
|
-
- `createJsonSchemaStore(schema)` - Create runtime schema store
|
|
141
|
-
- `getJsonSchemaStoreByPath(store, path)` - Navigate schema by JSON pointer
|
|
142
|
-
- `applyPatches(schema, patches)` - Apply JSON Patch operations
|
|
143
|
-
|
|
144
|
-
**Value Operations:**
|
|
145
|
-
- `createJsonValueStore(schema, rowId, data)` - Create runtime value store
|
|
146
|
-
- `getJsonValueStoreByPath(store, path)` - Navigate value by JSON pointer
|
|
147
|
-
|
|
148
|
-
**Foreign Keys:**
|
|
149
|
-
- `getForeignKeysFromSchema(store)` - Extract foreign keys from schema
|
|
150
|
-
- `getForeignKeysFromValue(store)` - Extract foreign key values from data
|
|
151
|
-
- `replaceForeignKeyValue(store, fromId, toId)` - Replace foreign key references
|
|
152
|
-
|
|
153
|
-
**Other:**
|
|
154
|
-
- `resolveRefs(schema)` - Resolve $ref to inline schemas
|
|
155
|
-
- `validateJsonFieldName(name)` - Validate field name format
|
|
156
|
-
|
|
157
|
-
## Development
|
|
158
|
-
|
|
159
|
-
```bash
|
|
160
|
-
# Install dependencies
|
|
161
|
-
npm install
|
|
162
|
-
|
|
163
|
-
# Build
|
|
164
|
-
npm run build
|
|
165
|
-
|
|
166
|
-
# Run tests
|
|
167
|
-
npm test
|
|
168
|
-
|
|
169
|
-
# Run tests with coverage
|
|
170
|
-
npm run test:cov
|
|
171
|
-
|
|
172
|
-
# Lint
|
|
173
|
-
npm run lint:ci
|
|
174
|
-
|
|
175
|
-
# Format
|
|
176
|
-
npm run format
|
|
177
|
-
|
|
178
|
-
# Type check
|
|
179
|
-
npm run tsc
|
|
180
|
-
```
|
|
53
|
+
| Function | Description |
|
|
54
|
+
|----------|-------------|
|
|
55
|
+
| `parsePath` | Parse dot-notation path to segments |
|
|
56
|
+
| `getParentForPath` | Get parent path |
|
|
57
|
+
| `getPathByStore` | Get path from store |
|
|
58
|
+
| `deepEqual` | Deep equality comparison |
|
|
181
59
|
|
|
182
60
|
## License
|
|
183
61
|
|
|
184
|
-
MIT
|
|
62
|
+
MIT
|
|
@@ -248,129 +248,6 @@ var applyMovePatch = (store, patch) => {
|
|
|
248
248
|
throw new Error('Invalid type of "to" parent');
|
|
249
249
|
};
|
|
250
250
|
|
|
251
|
-
// src/lib/getDBJsonPathByJsonSchemaStore.ts
|
|
252
|
-
var getDBJsonPathByJsonSchemaStore = (store) => {
|
|
253
|
-
let node = store;
|
|
254
|
-
let path = "";
|
|
255
|
-
while (node.parent) {
|
|
256
|
-
if (node.parent.type === "object" /* Object */) {
|
|
257
|
-
path = `.${node.name}${path}`;
|
|
258
|
-
} else if (node.parent.type === "array" /* Array */) {
|
|
259
|
-
path = `[*]${path}`;
|
|
260
|
-
}
|
|
261
|
-
node = node.parent;
|
|
262
|
-
}
|
|
263
|
-
if (!path) {
|
|
264
|
-
return "$";
|
|
265
|
-
}
|
|
266
|
-
return `$${path}`;
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
// src/lib/getPathByStore.ts
|
|
270
|
-
var getPathByStore = (store) => {
|
|
271
|
-
let node = store;
|
|
272
|
-
let path = "";
|
|
273
|
-
while (node.parent) {
|
|
274
|
-
if (node.parent.type === "object" /* Object */) {
|
|
275
|
-
path = `/properties/${node.name}${path}`;
|
|
276
|
-
} else if (node.parent.type === "array" /* Array */) {
|
|
277
|
-
path = `/items${path}`;
|
|
278
|
-
}
|
|
279
|
-
node = node.parent;
|
|
280
|
-
}
|
|
281
|
-
if (!path) {
|
|
282
|
-
return "/";
|
|
283
|
-
}
|
|
284
|
-
return `${path}`;
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
// src/lib/traverseStore.ts
|
|
288
|
-
var traverseStore = (store, callback) => {
|
|
289
|
-
callback(store);
|
|
290
|
-
if (store.type === "object" /* Object */) {
|
|
291
|
-
Object.values(store.properties).forEach((item) => {
|
|
292
|
-
traverseStore(item, callback);
|
|
293
|
-
});
|
|
294
|
-
} else if (store.type === "array" /* Array */) {
|
|
295
|
-
traverseStore(store.items, callback);
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
// src/lib/getForeignKeyPatchesFromSchema.ts
|
|
300
|
-
var getForeignKeyPatchesFromSchema = (store, options) => {
|
|
301
|
-
const stores = [];
|
|
302
|
-
traverseStore(store, (item) => {
|
|
303
|
-
if (item.type === "string" /* String */ && item.foreignKey === options.tableId) {
|
|
304
|
-
item.foreignKey = options.nextTableId;
|
|
305
|
-
const patch = {
|
|
306
|
-
op: "replace",
|
|
307
|
-
path: getPathByStore(item),
|
|
308
|
-
value: item.getPlainSchema()
|
|
309
|
-
};
|
|
310
|
-
stores.push(patch);
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
return stores;
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
// src/lib/getForeignKeysFromSchema.ts
|
|
317
|
-
var getForeignKeysFromSchema = (store) => {
|
|
318
|
-
const foreignKeys = /* @__PURE__ */ new Set();
|
|
319
|
-
traverseStore(store, (item) => {
|
|
320
|
-
if (item.type === "string" /* String */ && item.foreignKey) {
|
|
321
|
-
foreignKeys.add(item.foreignKey);
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
return [...foreignKeys].sort((a, b) => a.localeCompare(b));
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
// src/lib/traverseValue.ts
|
|
328
|
-
var traverseValue = (store, callback) => {
|
|
329
|
-
callback(store);
|
|
330
|
-
if (store.type === "object" /* Object */) {
|
|
331
|
-
Object.values(store.value).forEach((item) => {
|
|
332
|
-
traverseValue(item, callback);
|
|
333
|
-
});
|
|
334
|
-
} else if (store.type === "array" /* Array */) {
|
|
335
|
-
store.value.forEach((itemValue) => {
|
|
336
|
-
traverseValue(itemValue, callback);
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
// src/lib/getForeignKeysFromValue.ts
|
|
342
|
-
var getForeignKeysFromValue = (value) => {
|
|
343
|
-
const foreignKeys = /* @__PURE__ */ new Map();
|
|
344
|
-
traverseValue(value, (item) => {
|
|
345
|
-
if (item.type === "string" /* String */ && item.foreignKey) {
|
|
346
|
-
let tableForeignKey = foreignKeys.get(item.foreignKey);
|
|
347
|
-
if (!tableForeignKey) {
|
|
348
|
-
tableForeignKey = /* @__PURE__ */ new Set();
|
|
349
|
-
foreignKeys.set(item.foreignKey, tableForeignKey);
|
|
350
|
-
}
|
|
351
|
-
tableForeignKey.add(item.getPlainValue());
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
return [...foreignKeys].map(([tableId, rowIds]) => ({
|
|
355
|
-
tableId,
|
|
356
|
-
rowIds: [...rowIds].sort((a, b) => a.localeCompare(b))
|
|
357
|
-
}));
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
// src/lib/getInvalidFieldNamesInSchema.ts
|
|
361
|
-
var getInvalidFieldNamesInSchema = (schema, refs = {}) => {
|
|
362
|
-
const schemaStore = createJsonSchemaStore(schema, refs);
|
|
363
|
-
const invalidFields = [];
|
|
364
|
-
traverseStore(schemaStore, (item) => {
|
|
365
|
-
if (item.parent?.type === "object" /* Object */) {
|
|
366
|
-
if (!validateJsonFieldName(item.name)) {
|
|
367
|
-
invalidFields.push(item);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
return invalidFields;
|
|
372
|
-
};
|
|
373
|
-
|
|
374
251
|
// src/lib/json-path-utils.ts
|
|
375
252
|
function parsePathSegments(path) {
|
|
376
253
|
const segments = [];
|
|
@@ -595,6 +472,221 @@ function convertSchemaPathToJsonPath(schemaPath) {
|
|
|
595
472
|
return result;
|
|
596
473
|
}
|
|
597
474
|
|
|
475
|
+
// src/lib/computeValueDiff.ts
|
|
476
|
+
function computeValueDiff(fromValue, toValue) {
|
|
477
|
+
if (fromValue === null && toValue === null) {
|
|
478
|
+
return [];
|
|
479
|
+
}
|
|
480
|
+
if (fromValue === null && toValue !== null) {
|
|
481
|
+
return [createChange("", null, toValue, "ADDED" /* Added */)];
|
|
482
|
+
}
|
|
483
|
+
if (fromValue !== null && toValue === null) {
|
|
484
|
+
return [createChange("", fromValue, null, "REMOVED" /* Removed */)];
|
|
485
|
+
}
|
|
486
|
+
return computeDiff(fromValue, toValue, "");
|
|
487
|
+
}
|
|
488
|
+
function computeDiff(fromValue, toValue, path) {
|
|
489
|
+
if (deepEqual(fromValue, toValue)) {
|
|
490
|
+
return [];
|
|
491
|
+
}
|
|
492
|
+
if (isPrimitive(fromValue) || isPrimitive(toValue)) {
|
|
493
|
+
return [createChange(path, fromValue, toValue, "MODIFIED" /* Modified */)];
|
|
494
|
+
}
|
|
495
|
+
if (hasTypeChanged(fromValue, toValue)) {
|
|
496
|
+
return [createChange(path, fromValue, toValue, "MODIFIED" /* Modified */)];
|
|
497
|
+
}
|
|
498
|
+
if (Array.isArray(fromValue) && Array.isArray(toValue)) {
|
|
499
|
+
return computeArrayDiff(fromValue, toValue, path);
|
|
500
|
+
}
|
|
501
|
+
return computeObjectDiff(
|
|
502
|
+
fromValue,
|
|
503
|
+
toValue,
|
|
504
|
+
path
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
function computeObjectDiff(fromObj, toObj, basePath) {
|
|
508
|
+
const changes = [];
|
|
509
|
+
const fromKeys = Object.keys(fromObj);
|
|
510
|
+
const toKeys = new Set(Object.keys(toObj));
|
|
511
|
+
for (const key of fromKeys) {
|
|
512
|
+
const fieldPath = joinPath(basePath, key);
|
|
513
|
+
if (!toKeys.has(key)) {
|
|
514
|
+
changes.push(
|
|
515
|
+
createChange(fieldPath, fromObj[key], null, "REMOVED" /* Removed */)
|
|
516
|
+
);
|
|
517
|
+
} else {
|
|
518
|
+
changes.push(...computeDiff(fromObj[key], toObj[key], fieldPath));
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
for (const key of toKeys) {
|
|
522
|
+
if (!fromKeys.includes(key)) {
|
|
523
|
+
const fieldPath = joinPath(basePath, key);
|
|
524
|
+
changes.push(
|
|
525
|
+
createChange(fieldPath, null, toObj[key], "ADDED" /* Added */)
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return changes;
|
|
530
|
+
}
|
|
531
|
+
function computeArrayDiff(fromArr, toArr, basePath) {
|
|
532
|
+
const changes = [];
|
|
533
|
+
const maxLen = Math.max(fromArr.length, toArr.length);
|
|
534
|
+
for (let i = 0; i < maxLen; i++) {
|
|
535
|
+
const fieldPath = joinPath(basePath, String(i));
|
|
536
|
+
const hasFrom = i < fromArr.length;
|
|
537
|
+
const hasTo = i < toArr.length;
|
|
538
|
+
if (hasFrom && hasTo) {
|
|
539
|
+
changes.push(...computeDiff(fromArr[i], toArr[i], fieldPath));
|
|
540
|
+
} else if (hasFrom) {
|
|
541
|
+
changes.push(
|
|
542
|
+
createChange(fieldPath, fromArr[i], null, "REMOVED" /* Removed */)
|
|
543
|
+
);
|
|
544
|
+
} else {
|
|
545
|
+
changes.push(
|
|
546
|
+
createChange(fieldPath, null, toArr[i], "ADDED" /* Added */)
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return changes;
|
|
551
|
+
}
|
|
552
|
+
function isPrimitive(value) {
|
|
553
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
554
|
+
}
|
|
555
|
+
function hasTypeChanged(fromValue, toValue) {
|
|
556
|
+
const fromIsArray = Array.isArray(fromValue);
|
|
557
|
+
const toIsArray = Array.isArray(toValue);
|
|
558
|
+
return fromIsArray !== toIsArray;
|
|
559
|
+
}
|
|
560
|
+
function joinPath(base, segment) {
|
|
561
|
+
return base ? `${base}.${segment}` : segment;
|
|
562
|
+
}
|
|
563
|
+
function createChange(path, oldValue, newValue, changeType) {
|
|
564
|
+
return { path, oldValue, newValue, changeType };
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// src/lib/getDBJsonPathByJsonSchemaStore.ts
|
|
568
|
+
var getDBJsonPathByJsonSchemaStore = (store) => {
|
|
569
|
+
let node = store;
|
|
570
|
+
let path = "";
|
|
571
|
+
while (node.parent) {
|
|
572
|
+
if (node.parent.type === "object" /* Object */) {
|
|
573
|
+
path = `.${node.name}${path}`;
|
|
574
|
+
} else if (node.parent.type === "array" /* Array */) {
|
|
575
|
+
path = `[*]${path}`;
|
|
576
|
+
}
|
|
577
|
+
node = node.parent;
|
|
578
|
+
}
|
|
579
|
+
if (!path) {
|
|
580
|
+
return "$";
|
|
581
|
+
}
|
|
582
|
+
return `$${path}`;
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// src/lib/getPathByStore.ts
|
|
586
|
+
var getPathByStore = (store) => {
|
|
587
|
+
let node = store;
|
|
588
|
+
let path = "";
|
|
589
|
+
while (node.parent) {
|
|
590
|
+
if (node.parent.type === "object" /* Object */) {
|
|
591
|
+
path = `/properties/${node.name}${path}`;
|
|
592
|
+
} else if (node.parent.type === "array" /* Array */) {
|
|
593
|
+
path = `/items${path}`;
|
|
594
|
+
}
|
|
595
|
+
node = node.parent;
|
|
596
|
+
}
|
|
597
|
+
if (!path) {
|
|
598
|
+
return "/";
|
|
599
|
+
}
|
|
600
|
+
return `${path}`;
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
// src/lib/traverseStore.ts
|
|
604
|
+
var traverseStore = (store, callback) => {
|
|
605
|
+
callback(store);
|
|
606
|
+
if (store.type === "object" /* Object */) {
|
|
607
|
+
Object.values(store.properties).forEach((item) => {
|
|
608
|
+
traverseStore(item, callback);
|
|
609
|
+
});
|
|
610
|
+
} else if (store.type === "array" /* Array */) {
|
|
611
|
+
traverseStore(store.items, callback);
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
// src/lib/getForeignKeyPatchesFromSchema.ts
|
|
616
|
+
var getForeignKeyPatchesFromSchema = (store, options) => {
|
|
617
|
+
const stores = [];
|
|
618
|
+
traverseStore(store, (item) => {
|
|
619
|
+
if (item.type === "string" /* String */ && item.foreignKey === options.tableId) {
|
|
620
|
+
item.foreignKey = options.nextTableId;
|
|
621
|
+
const patch = {
|
|
622
|
+
op: "replace",
|
|
623
|
+
path: getPathByStore(item),
|
|
624
|
+
value: item.getPlainSchema()
|
|
625
|
+
};
|
|
626
|
+
stores.push(patch);
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
return stores;
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
// src/lib/getForeignKeysFromSchema.ts
|
|
633
|
+
var getForeignKeysFromSchema = (store) => {
|
|
634
|
+
const foreignKeys = /* @__PURE__ */ new Set();
|
|
635
|
+
traverseStore(store, (item) => {
|
|
636
|
+
if (item.type === "string" /* String */ && item.foreignKey) {
|
|
637
|
+
foreignKeys.add(item.foreignKey);
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
return [...foreignKeys].sort((a, b) => a.localeCompare(b));
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
// src/lib/traverseValue.ts
|
|
644
|
+
var traverseValue = (store, callback) => {
|
|
645
|
+
callback(store);
|
|
646
|
+
if (store.type === "object" /* Object */) {
|
|
647
|
+
Object.values(store.value).forEach((item) => {
|
|
648
|
+
traverseValue(item, callback);
|
|
649
|
+
});
|
|
650
|
+
} else if (store.type === "array" /* Array */) {
|
|
651
|
+
store.value.forEach((itemValue) => {
|
|
652
|
+
traverseValue(itemValue, callback);
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
// src/lib/getForeignKeysFromValue.ts
|
|
658
|
+
var getForeignKeysFromValue = (value) => {
|
|
659
|
+
const foreignKeys = /* @__PURE__ */ new Map();
|
|
660
|
+
traverseValue(value, (item) => {
|
|
661
|
+
if (item.type === "string" /* String */ && item.foreignKey) {
|
|
662
|
+
let tableForeignKey = foreignKeys.get(item.foreignKey);
|
|
663
|
+
if (!tableForeignKey) {
|
|
664
|
+
tableForeignKey = /* @__PURE__ */ new Set();
|
|
665
|
+
foreignKeys.set(item.foreignKey, tableForeignKey);
|
|
666
|
+
}
|
|
667
|
+
tableForeignKey.add(item.getPlainValue());
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
return [...foreignKeys].map(([tableId, rowIds]) => ({
|
|
671
|
+
tableId,
|
|
672
|
+
rowIds: [...rowIds].sort((a, b) => a.localeCompare(b))
|
|
673
|
+
}));
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
// src/lib/getInvalidFieldNamesInSchema.ts
|
|
677
|
+
var getInvalidFieldNamesInSchema = (schema, refs = {}) => {
|
|
678
|
+
const schemaStore = createJsonSchemaStore(schema, refs);
|
|
679
|
+
const invalidFields = [];
|
|
680
|
+
traverseStore(schemaStore, (item) => {
|
|
681
|
+
if (item.parent?.type === "object" /* Object */) {
|
|
682
|
+
if (!validateJsonFieldName(item.name)) {
|
|
683
|
+
invalidFields.push(item);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
return invalidFields;
|
|
688
|
+
};
|
|
689
|
+
|
|
598
690
|
// src/lib/getJsonValueByPath.ts
|
|
599
691
|
var getJsonValueStoreByPath = (root, path) => {
|
|
600
692
|
if (!path) {
|
|
@@ -725,6 +817,6 @@ var SchemaTable = class {
|
|
|
725
817
|
}
|
|
726
818
|
};
|
|
727
819
|
|
|
728
|
-
export { SchemaTable, VALIDATE_JSON_FIELD_NAME_ERROR_MESSAGE, applyAddPatch, applyMovePatch, applyRemovePatch, applyReplacePatch, convertJsonPathToSchemaPath, convertSchemaPathToJsonPath, createJsonObjectSchemaStore, createJsonSchemaStore, createPrimitiveStoreBySchema, deepEqual, getDBJsonPathByJsonSchemaStore, getForeignKeyPatchesFromSchema, getForeignKeysFromSchema, getForeignKeysFromValue, getInvalidFieldNamesInSchema, getJsonSchemaStoreByPath, getJsonValueStoreByPath, getParentForPath, getPathByStore, getValueByPath, hasPath, parsePath, pluginRefs, replaceForeignKeyValue, resolveRefs, saveSharedFields, setValueByPath, traverseStore, traverseValue, validateJsonFieldName };
|
|
729
|
-
//# sourceMappingURL=chunk-
|
|
730
|
-
//# sourceMappingURL=chunk-
|
|
820
|
+
export { SchemaTable, VALIDATE_JSON_FIELD_NAME_ERROR_MESSAGE, applyAddPatch, applyMovePatch, applyRemovePatch, applyReplacePatch, computeValueDiff, convertJsonPathToSchemaPath, convertSchemaPathToJsonPath, createJsonObjectSchemaStore, createJsonSchemaStore, createPrimitiveStoreBySchema, deepEqual, getDBJsonPathByJsonSchemaStore, getForeignKeyPatchesFromSchema, getForeignKeysFromSchema, getForeignKeysFromValue, getInvalidFieldNamesInSchema, getJsonSchemaStoreByPath, getJsonValueStoreByPath, getParentForPath, getPathByStore, getValueByPath, hasPath, parsePath, pluginRefs, replaceForeignKeyValue, resolveRefs, saveSharedFields, setValueByPath, traverseStore, traverseValue, validateJsonFieldName };
|
|
821
|
+
//# sourceMappingURL=chunk-DFL3HJ4Y.js.map
|
|
822
|
+
//# sourceMappingURL=chunk-DFL3HJ4Y.js.map
|