@revisium/schema-toolkit 0.2.0 → 0.2.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.
- package/dist/chunk-22HBQQF4.js +519 -0
- package/dist/chunk-22HBQQF4.js.map +1 -0
- package/dist/chunk-22K22MMD.js +112 -0
- package/dist/chunk-22K22MMD.js.map +1 -0
- package/dist/chunk-47AQWLHU.cjs +122 -0
- package/dist/chunk-47AQWLHU.cjs.map +1 -0
- package/dist/chunk-5VDDLW7U.js +9 -0
- package/dist/chunk-5VDDLW7U.js.map +1 -0
- package/dist/chunk-62P6L7GI.js +693 -0
- package/dist/chunk-62P6L7GI.js.map +1 -0
- package/dist/chunk-AORPUIKD.js +81 -0
- package/dist/chunk-AORPUIKD.js.map +1 -0
- package/dist/chunk-ASXCDIN2.js +365 -0
- package/dist/chunk-ASXCDIN2.js.map +1 -0
- package/dist/chunk-BQWQLLSC.cjs +719 -0
- package/dist/chunk-BQWQLLSC.cjs.map +1 -0
- package/dist/chunk-DEPJRTVT.js +3 -0
- package/dist/chunk-DEPJRTVT.js.map +1 -0
- package/dist/chunk-EJYILFAK.cjs +92 -0
- package/dist/chunk-EJYILFAK.cjs.map +1 -0
- package/dist/chunk-FD57PCAC.cjs +4 -0
- package/dist/chunk-FD57PCAC.cjs.map +1 -0
- package/dist/chunk-H7W4QNMA.js +3 -0
- package/dist/chunk-H7W4QNMA.js.map +1 -0
- package/dist/chunk-IPL2CGVA.cjs +11 -0
- package/dist/chunk-IPL2CGVA.cjs.map +1 -0
- package/dist/chunk-ODCH3PP2.cjs +4 -0
- package/dist/chunk-ODCH3PP2.cjs.map +1 -0
- package/dist/chunk-Q2UOTIMG.js +17 -0
- package/dist/chunk-Q2UOTIMG.js.map +1 -0
- package/dist/chunk-RV56Z2F4.cjs +545 -0
- package/dist/chunk-RV56Z2F4.cjs.map +1 -0
- package/dist/chunk-V2SSSD5X.cjs +15 -0
- package/dist/chunk-V2SSSD5X.cjs.map +1 -0
- package/dist/chunk-VGTHMWJJ.cjs +380 -0
- package/dist/chunk-VGTHMWJJ.cjs.map +1 -0
- package/dist/chunk-XNFSFT7T.cjs +19 -0
- package/dist/chunk-XNFSFT7T.cjs.map +1 -0
- package/dist/chunk-ZXLLJAMQ.js +13 -0
- package/dist/chunk-ZXLLJAMQ.js.map +1 -0
- package/dist/consts/index.cjs +11 -20
- package/dist/consts/index.cjs.map +1 -1
- package/dist/consts/index.js +2 -21
- package/dist/consts/index.js.map +1 -1
- package/dist/index.cjs +356 -1869
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10 -1785
- package/dist/index.js.map +1 -1
- package/dist/lib/index.cjs +128 -1342
- package/dist/lib/index.cjs.map +1 -1
- package/dist/lib/index.js +5 -1313
- package/dist/lib/index.js.map +1 -1
- package/dist/mocks/index.cjs +38 -81
- package/dist/mocks/index.cjs.map +1 -1
- package/dist/mocks/index.js +2 -79
- package/dist/mocks/index.js.map +1 -1
- package/dist/model/index.cjs +83 -711
- package/dist/model/index.cjs.map +1 -1
- package/dist/model/index.js +3 -695
- package/dist/model/index.js.map +1 -1
- package/dist/plugins/index.cjs +41 -118
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.js +2 -110
- package/dist/plugins/index.js.map +1 -1
- package/dist/types/index.cjs +9 -11
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.js +2 -11
- package/dist/types/index.js.map +1 -1
- package/dist/validation-schemas/index.cjs +57 -373
- package/dist/validation-schemas/index.cjs.map +1 -1
- package/dist/validation-schemas/index.js +1 -363
- package/dist/validation-schemas/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
import { fileSchema, rowSchemaHashSchema, rowHashSchema, rowUpdatedAtSchema, rowPublishedAtSchema, rowCreatedAtSchema, rowCreatedIdSchema, rowVersionIdSchema, rowIdSchema } from './chunk-22K22MMD.js';
|
|
2
|
+
import { JsonArrayStore, JsonObjectStore, JsonStringStore, JsonNumberStore, JsonBooleanStore, JsonObjectValueStore, JsonArrayValueStore, createJsonValueStore, getTransformation } from './chunk-62P6L7GI.js';
|
|
3
|
+
|
|
4
|
+
// src/lib/createJsonSchemaStore.ts
|
|
5
|
+
var createJsonSchemaStore = (schema, refs = {}) => {
|
|
6
|
+
if ("$ref" in schema) {
|
|
7
|
+
const refSchema = refs[schema.$ref];
|
|
8
|
+
if (!refSchema) {
|
|
9
|
+
throw new Error(`Not found schema for $ref="${schema.$ref}"`);
|
|
10
|
+
}
|
|
11
|
+
const refStore = createJsonSchemaStore(refSchema, refs);
|
|
12
|
+
saveSharedFields(refStore, schema);
|
|
13
|
+
refStore.$ref = schema.$ref;
|
|
14
|
+
return refStore;
|
|
15
|
+
} else if (schema.type === "object" /* Object */) {
|
|
16
|
+
const objectStore = createJsonObjectSchemaStore(schema, refs);
|
|
17
|
+
saveSharedFields(objectStore, schema);
|
|
18
|
+
return objectStore;
|
|
19
|
+
} else if (schema.type === "array" /* Array */) {
|
|
20
|
+
const itemsStore = createJsonSchemaStore(schema.items, refs);
|
|
21
|
+
const arrayStore = new JsonArrayStore(itemsStore);
|
|
22
|
+
saveSharedFields(arrayStore, schema);
|
|
23
|
+
return arrayStore;
|
|
24
|
+
} else {
|
|
25
|
+
const primitivesStore = createPrimitiveStoreBySchema(schema);
|
|
26
|
+
saveSharedFields(primitivesStore, schema);
|
|
27
|
+
primitivesStore.readOnly = schema.readOnly;
|
|
28
|
+
return primitivesStore;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var createJsonObjectSchemaStore = (value, refs) => {
|
|
32
|
+
const store = new JsonObjectStore();
|
|
33
|
+
for (const requiredField of value.required) {
|
|
34
|
+
if (!value.properties[requiredField]) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`Not found required field "${requiredField}" in "properties"`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
Object.entries(value.properties).forEach(([name, item]) => {
|
|
41
|
+
store.addPropertyWithStore(name, createJsonSchemaStore(item, refs));
|
|
42
|
+
});
|
|
43
|
+
return store;
|
|
44
|
+
};
|
|
45
|
+
var createPrimitiveStoreBySchema = (schema) => {
|
|
46
|
+
if (schema.type === "string" /* String */) {
|
|
47
|
+
const stringStore = new JsonStringStore();
|
|
48
|
+
stringStore.foreignKey = schema.foreignKey;
|
|
49
|
+
stringStore.format = schema.format;
|
|
50
|
+
stringStore.enum = schema.enum;
|
|
51
|
+
stringStore.contentMediaType = schema.contentMediaType;
|
|
52
|
+
stringStore.pattern = schema.pattern;
|
|
53
|
+
return stringStore;
|
|
54
|
+
} else if (schema.type === "number" /* Number */) {
|
|
55
|
+
return new JsonNumberStore();
|
|
56
|
+
} else if (schema.type === "boolean" /* Boolean */) {
|
|
57
|
+
return new JsonBooleanStore();
|
|
58
|
+
} else {
|
|
59
|
+
throw new Error("this type is not allowed");
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var saveSharedFields = (store, schema) => {
|
|
63
|
+
store.title = schema.title;
|
|
64
|
+
store.description = schema.description;
|
|
65
|
+
store.deprecated = schema.deprecated;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/lib/getJsonSchemaStoreByPath.ts
|
|
69
|
+
var getJsonSchemaStoreByPath = (store, path) => {
|
|
70
|
+
if (path === "") {
|
|
71
|
+
return store;
|
|
72
|
+
}
|
|
73
|
+
if (path === "/") {
|
|
74
|
+
throw new Error(
|
|
75
|
+
'invalid root path, need to use path="" instead of path="/"'
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
const tokens = path.split("/");
|
|
79
|
+
tokens.shift();
|
|
80
|
+
let currentStore = store;
|
|
81
|
+
let currentToken = tokens.shift();
|
|
82
|
+
let currentPath = "";
|
|
83
|
+
while (currentToken) {
|
|
84
|
+
if (currentStore.type === "object" /* Object */) {
|
|
85
|
+
if (currentToken !== "properties") {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`Expected "${currentPath}/properties/*" instead of ${currentPath}/${currentToken}/*`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
currentPath = `${currentPath}/${currentToken}`;
|
|
91
|
+
currentToken = tokens.shift();
|
|
92
|
+
if (!currentToken) {
|
|
93
|
+
throw new Error(`Expected property name after "${currentPath}"`);
|
|
94
|
+
}
|
|
95
|
+
const foundCurrentStore = currentStore.getProperty(currentToken);
|
|
96
|
+
if (!foundCurrentStore) {
|
|
97
|
+
throw new Error(`Not found "${currentToken}" in "${currentPath}"`);
|
|
98
|
+
}
|
|
99
|
+
currentStore = foundCurrentStore;
|
|
100
|
+
currentPath = `${currentPath}/${currentToken}`;
|
|
101
|
+
currentToken = tokens.shift();
|
|
102
|
+
} else if (currentStore.type === "array" /* Array */) {
|
|
103
|
+
if (currentToken !== "items") {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`Expected "${currentPath}/items/*" instead of ${currentPath}/${currentToken}/*`
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
currentPath = `${currentPath}/${currentToken}`;
|
|
109
|
+
currentStore = currentStore.items;
|
|
110
|
+
currentToken = tokens.shift();
|
|
111
|
+
} else {
|
|
112
|
+
throw new Error(`Unexpected "${currentToken}" in "${currentPath}"`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return currentStore;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// src/lib/getParentForPath.ts
|
|
119
|
+
var getParentForPath = (path) => {
|
|
120
|
+
if (path === "" || path === "/") {
|
|
121
|
+
throw new Error("Invalid path");
|
|
122
|
+
}
|
|
123
|
+
const tokens = path.split("/");
|
|
124
|
+
tokens.shift();
|
|
125
|
+
let currentToken = tokens.shift();
|
|
126
|
+
let parentPath = "";
|
|
127
|
+
let field = "";
|
|
128
|
+
while (currentToken) {
|
|
129
|
+
if (currentToken === "properties") {
|
|
130
|
+
currentToken = tokens.shift();
|
|
131
|
+
if (!currentToken) {
|
|
132
|
+
throw new Error("Invalid path");
|
|
133
|
+
}
|
|
134
|
+
field = currentToken;
|
|
135
|
+
currentToken = tokens.shift();
|
|
136
|
+
if (currentToken) {
|
|
137
|
+
parentPath = `${parentPath}/properties/${field}`;
|
|
138
|
+
}
|
|
139
|
+
} else if (currentToken === "items") {
|
|
140
|
+
field = currentToken;
|
|
141
|
+
currentToken = tokens.shift();
|
|
142
|
+
if (currentToken && !["items", "properties"].includes(currentToken)) {
|
|
143
|
+
throw new Error("Invalid path");
|
|
144
|
+
} else if (currentToken) {
|
|
145
|
+
parentPath = `${parentPath}/items`;
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
throw new Error("Invalid path");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
parentPath,
|
|
153
|
+
field
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/lib/validateJsonFieldName.ts
|
|
158
|
+
var maxLength = 64;
|
|
159
|
+
var VALIDATE_JSON_FIELD_NAME_ERROR_MESSAGE = `It must contain between 1 and ${maxLength} characters, start with a letter or underscore (_), cannot start with two underscores (__), and can only include letters (a-z, A-Z), numbers (0-9), hyphens (-), and underscores (_).`;
|
|
160
|
+
var validPattern = /^(?!__)[a-zA-Z_][a-zA-Z0-9-_]*$/;
|
|
161
|
+
var validateJsonFieldName = (id) => {
|
|
162
|
+
const isInvalid = id.length < 1 || id.length > maxLength || !validPattern.test(id);
|
|
163
|
+
return !isInvalid;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// src/lib/applyPatches.ts
|
|
167
|
+
var applyReplacePatch = (store, patch, refs = {}) => {
|
|
168
|
+
const patchStore = createJsonSchemaStore(patch.value, refs);
|
|
169
|
+
const foundStore = getJsonSchemaStoreByPath(store, patch.path);
|
|
170
|
+
const parent = foundStore.parent;
|
|
171
|
+
if (!parent) {
|
|
172
|
+
return patchStore;
|
|
173
|
+
}
|
|
174
|
+
if (parent.type === "object" /* Object */) {
|
|
175
|
+
parent.migratePropertyWithStore(foundStore.name, patchStore);
|
|
176
|
+
} else if (parent.type === "array" /* Array */) {
|
|
177
|
+
parent.migrateItems(patchStore);
|
|
178
|
+
} else {
|
|
179
|
+
throw new Error("Invalid parent");
|
|
180
|
+
}
|
|
181
|
+
return store;
|
|
182
|
+
};
|
|
183
|
+
var applyRemovePatch = (rootStore, patch) => {
|
|
184
|
+
const foundStore = getJsonSchemaStoreByPath(rootStore, patch.path);
|
|
185
|
+
const parent = foundStore.parent;
|
|
186
|
+
if (!parent) {
|
|
187
|
+
throw new Error("Parent does not exist");
|
|
188
|
+
}
|
|
189
|
+
if (parent.type !== "object" /* Object */) {
|
|
190
|
+
throw new Error("Cannot remove from non-object");
|
|
191
|
+
}
|
|
192
|
+
parent.removeProperty(foundStore.name);
|
|
193
|
+
};
|
|
194
|
+
var applyAddPatch = (rootStore, patch, refs = {}) => {
|
|
195
|
+
const patchStore = createJsonSchemaStore(patch.value, refs);
|
|
196
|
+
const { parentPath, field } = getParentForPath(patch.path);
|
|
197
|
+
const foundParent = getJsonSchemaStoreByPath(rootStore, parentPath);
|
|
198
|
+
if (!foundParent) {
|
|
199
|
+
throw new Error("Parent does not exist");
|
|
200
|
+
}
|
|
201
|
+
if (foundParent.type !== "object" /* Object */) {
|
|
202
|
+
throw new Error("Cannot add to non-object");
|
|
203
|
+
}
|
|
204
|
+
if (foundParent.getProperty(field)) {
|
|
205
|
+
throw new Error(`Field "${field}" already exists in parent`);
|
|
206
|
+
}
|
|
207
|
+
foundParent.addPropertyWithStore(field, patchStore);
|
|
208
|
+
};
|
|
209
|
+
var applyMovePatch = (store, patch) => {
|
|
210
|
+
const { parentPath: fromParentPath, field: fromField } = getParentForPath(
|
|
211
|
+
patch.from
|
|
212
|
+
);
|
|
213
|
+
const { parentPath: toParentPath, field: toField } = getParentForPath(
|
|
214
|
+
patch.path
|
|
215
|
+
);
|
|
216
|
+
const foundFromParent = getJsonSchemaStoreByPath(store, fromParentPath);
|
|
217
|
+
const foundToParent = getJsonSchemaStoreByPath(store, toParentPath);
|
|
218
|
+
const isValidToField = validateJsonFieldName(toField);
|
|
219
|
+
if (!isValidToField) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
`Invalid name: ${toField}. ${VALIDATE_JSON_FIELD_NAME_ERROR_MESSAGE}`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
if (!foundFromParent || !foundToParent) {
|
|
225
|
+
throw new Error("Cannot move from or to non-existent parent");
|
|
226
|
+
}
|
|
227
|
+
if (foundFromParent.type !== "object" /* Object */) {
|
|
228
|
+
throw new Error("Cannot move from non-object parent");
|
|
229
|
+
}
|
|
230
|
+
const foundFromField = getJsonSchemaStoreByPath(store, patch.from);
|
|
231
|
+
const isMovedPropertyInSameParentPatch = foundFromParent === foundToParent && foundFromParent.type === "object" /* Object */ && foundFromParent.getProperty(fromField);
|
|
232
|
+
if (isMovedPropertyInSameParentPatch) {
|
|
233
|
+
return foundFromParent.changeName(fromField, toField);
|
|
234
|
+
}
|
|
235
|
+
if (foundToParent.type === "object" /* Object */) {
|
|
236
|
+
foundFromParent.removeProperty(fromField);
|
|
237
|
+
if (foundToParent.getProperty(toField)) {
|
|
238
|
+
foundToParent.removeProperty(toField);
|
|
239
|
+
}
|
|
240
|
+
foundToParent.addPropertyWithStore(toField, foundFromField);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (foundToParent.type === "array" /* Array */) {
|
|
244
|
+
foundFromParent.removeProperty(fromField);
|
|
245
|
+
foundToParent.replaceItems(foundFromField);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
throw new Error('Invalid type of "to" parent');
|
|
249
|
+
};
|
|
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
|
+
// src/lib/getJsonValueByPath.ts
|
|
375
|
+
var getJsonValueStoreByPath = (root, path) => {
|
|
376
|
+
if (!path) {
|
|
377
|
+
return root;
|
|
378
|
+
}
|
|
379
|
+
const segments = getSegments(path);
|
|
380
|
+
let current = root;
|
|
381
|
+
for (const seg of segments) {
|
|
382
|
+
if (current instanceof JsonObjectValueStore) {
|
|
383
|
+
const next = current.value[String(seg)];
|
|
384
|
+
if (!next) {
|
|
385
|
+
throw new Error(`Path not found at segment "${seg}"`);
|
|
386
|
+
}
|
|
387
|
+
current = next;
|
|
388
|
+
} else if (current instanceof JsonArrayValueStore) {
|
|
389
|
+
if (typeof seg !== "number") {
|
|
390
|
+
throw new Error(`Invalid array index "${seg}"`);
|
|
391
|
+
}
|
|
392
|
+
const next = current.value[seg];
|
|
393
|
+
if (!next) {
|
|
394
|
+
throw new Error(`Path not found at segment "${seg}"`);
|
|
395
|
+
}
|
|
396
|
+
current = next;
|
|
397
|
+
} else {
|
|
398
|
+
throw new Error(`Cannot navigate into primitive at segment "${seg}"`);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return current;
|
|
402
|
+
};
|
|
403
|
+
var regex = /([^.[\]]+)|\[(\d+)]/g;
|
|
404
|
+
var getSegments = (path) => {
|
|
405
|
+
const segments = [];
|
|
406
|
+
let match;
|
|
407
|
+
while (match = regex.exec(path)) {
|
|
408
|
+
if (match[1] !== void 0) {
|
|
409
|
+
segments.push(match[1]);
|
|
410
|
+
} else if (match[2] !== void 0) {
|
|
411
|
+
segments.push(Number(match[2]));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return segments;
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
// src/lib/replaceForeignKeyValue.ts
|
|
418
|
+
var replaceForeignKeyValue = (options) => {
|
|
419
|
+
let wasUpdated = false;
|
|
420
|
+
traverseValue(options.valueStore, (item) => {
|
|
421
|
+
if (item.type === "string" /* String */ && item.foreignKey === options.foreignKey && item.value === options.value) {
|
|
422
|
+
item.value = options.nextValue;
|
|
423
|
+
wasUpdated = true;
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
return wasUpdated;
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
// src/lib/resolveRefs.ts
|
|
430
|
+
var pluginRefs = {
|
|
431
|
+
["urn:jsonschema:io:revisium:row-id-schema:1.0.0" /* RowId */]: rowIdSchema,
|
|
432
|
+
["urn:jsonschema:io:revisium:row-version-id-schema:1.0.0" /* RowVersionId */]: rowVersionIdSchema,
|
|
433
|
+
["urn:jsonschema:io:revisium:row-created-id-schema:1.0.0" /* RowCreatedId */]: rowCreatedIdSchema,
|
|
434
|
+
["urn:jsonschema:io:revisium:row-created-at-schema:1.0.0" /* RowCreatedAt */]: rowCreatedAtSchema,
|
|
435
|
+
["urn:jsonschema:io:revisium:row-published-at-schema:1.0.0" /* RowPublishedAt */]: rowPublishedAtSchema,
|
|
436
|
+
["urn:jsonschema:io:revisium:row-updated-at-schema:1.0.0" /* RowUpdatedAt */]: rowUpdatedAtSchema,
|
|
437
|
+
["urn:jsonschema:io:revisium:row-hash-schema:1.0.0" /* RowHash */]: rowHashSchema,
|
|
438
|
+
["urn:jsonschema:io:revisium:row-schema-hash-schema:1.0.0" /* RowSchemaHash */]: rowSchemaHashSchema,
|
|
439
|
+
["urn:jsonschema:io:revisium:file-schema:1.0.0" /* File */]: fileSchema
|
|
440
|
+
};
|
|
441
|
+
var resolveRefs = (schema) => {
|
|
442
|
+
const store = createJsonSchemaStore(schema, pluginRefs);
|
|
443
|
+
return store.getPlainSchema({ skip$Ref: true });
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
// src/lib/schema-table.ts
|
|
447
|
+
var SchemaTable = class {
|
|
448
|
+
constructor(schema, refs = {}) {
|
|
449
|
+
this.refs = refs;
|
|
450
|
+
this.store = createJsonSchemaStore(schema, refs);
|
|
451
|
+
}
|
|
452
|
+
rows = /* @__PURE__ */ new Map();
|
|
453
|
+
store;
|
|
454
|
+
applyPatches(patches) {
|
|
455
|
+
patches.forEach((patch) => {
|
|
456
|
+
switch (patch.op) {
|
|
457
|
+
case "replace": {
|
|
458
|
+
const nextStore = applyReplacePatch(this.store, patch, this.refs);
|
|
459
|
+
if (nextStore !== this.store) {
|
|
460
|
+
this.migrateRows(nextStore);
|
|
461
|
+
}
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
case "remove": {
|
|
465
|
+
applyRemovePatch(this.store, patch);
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
case "add": {
|
|
469
|
+
applyAddPatch(this.store, patch, this.refs);
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
case "move": {
|
|
473
|
+
applyMovePatch(this.store, patch);
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
default:
|
|
477
|
+
throw new Error(`Unsupported patch operation`);
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
getSchema() {
|
|
482
|
+
return this.store.getPlainSchema();
|
|
483
|
+
}
|
|
484
|
+
addRow(rowId, data) {
|
|
485
|
+
const row = createJsonValueStore(this.store, rowId, data);
|
|
486
|
+
this.rows.set(rowId, row);
|
|
487
|
+
}
|
|
488
|
+
getRow(id) {
|
|
489
|
+
const row = this.rows.get(id);
|
|
490
|
+
if (!row) {
|
|
491
|
+
throw new Error("Invalid id");
|
|
492
|
+
}
|
|
493
|
+
return row.getPlainValue();
|
|
494
|
+
}
|
|
495
|
+
getRows() {
|
|
496
|
+
return [...this.rows].map(([id, data]) => ({
|
|
497
|
+
id,
|
|
498
|
+
data: data.getPlainValue()
|
|
499
|
+
}));
|
|
500
|
+
}
|
|
501
|
+
migrateRows(nextStore) {
|
|
502
|
+
const transformation = getTransformation(this.store, nextStore);
|
|
503
|
+
if (transformation) {
|
|
504
|
+
for (const [rowId, row] of this.rows) {
|
|
505
|
+
const rawNextValue = transformation(
|
|
506
|
+
row.getPlainValue(),
|
|
507
|
+
nextStore.default
|
|
508
|
+
);
|
|
509
|
+
const nextRow = createJsonValueStore(nextStore, rowId, rawNextValue);
|
|
510
|
+
this.rows.set(rowId, nextRow);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
this.store = nextStore;
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
export { SchemaTable, VALIDATE_JSON_FIELD_NAME_ERROR_MESSAGE, applyAddPatch, applyMovePatch, applyRemovePatch, applyReplacePatch, createJsonObjectSchemaStore, createJsonSchemaStore, createPrimitiveStoreBySchema, getDBJsonPathByJsonSchemaStore, getForeignKeyPatchesFromSchema, getForeignKeysFromSchema, getForeignKeysFromValue, getInvalidFieldNamesInSchema, getJsonSchemaStoreByPath, getJsonValueStoreByPath, getParentForPath, getPathByStore, pluginRefs, replaceForeignKeyValue, resolveRefs, saveSharedFields, traverseStore, traverseValue, validateJsonFieldName };
|
|
518
|
+
//# sourceMappingURL=chunk-22HBQQF4.js.map
|
|
519
|
+
//# sourceMappingURL=chunk-22HBQQF4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/createJsonSchemaStore.ts","../src/lib/getJsonSchemaStoreByPath.ts","../src/lib/getParentForPath.ts","../src/lib/validateJsonFieldName.ts","../src/lib/applyPatches.ts","../src/lib/getDBJsonPathByJsonSchemaStore.ts","../src/lib/getPathByStore.ts","../src/lib/traverseStore.ts","../src/lib/getForeignKeyPatchesFromSchema.ts","../src/lib/getForeignKeysFromSchema.ts","../src/lib/traverseValue.ts","../src/lib/getForeignKeysFromValue.ts","../src/lib/getInvalidFieldNamesInSchema.ts","../src/lib/getJsonValueByPath.ts","../src/lib/replaceForeignKeyValue.ts","../src/lib/resolveRefs.ts","../src/lib/schema-table.ts"],"names":[],"mappings":";;;;AAkBO,IAAM,qBAAA,GAAwB,CACnC,MAAA,EACA,IAAA,GAAiB,EAAC,KACE;AACpB,EAAA,IAAI,UAAU,MAAA,EAAQ;AACpB,IAAA,MAAM,SAAA,GAAoC,IAAA,CAAK,MAAA,CAAO,IAAI,CAAA;AAE1D,IAAA,IAAI,CAAC,SAAA,EAAW;AACd,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,2BAAA,EAA8B,MAAA,CAAO,IAAI,CAAA,CAAA,CAAG,CAAA;AAAA,IAC9D;AAEA,IAAA,MAAM,QAAA,GAAW,qBAAA,CAAsB,SAAA,EAAW,IAAI,CAAA;AACtD,IAAA,gBAAA,CAAiB,UAAU,MAAM,CAAA;AACjC,IAAA,QAAA,CAAS,OAAO,MAAA,CAAO,IAAA;AACvB,IAAA,OAAO,QAAA;AAAA,EACT,CAAA,MAAA,IAAW,OAAO,IAAA,KAAA,QAAA,eAAoC;AACpD,IAAA,MAAM,WAAA,GAAc,2BAAA,CAA4B,MAAA,EAAQ,IAAI,CAAA;AAC5D,IAAA,gBAAA,CAAiB,aAAa,MAAM,CAAA;AAEpC,IAAA,OAAO,WAAA;AAAA,EACT,CAAA,MAAA,IAAW,OAAO,IAAA,KAAA,OAAA,cAAmC;AACnD,IAAA,MAAM,UAAA,GAAa,qBAAA,CAAsB,MAAA,CAAO,KAAA,EAAO,IAAI,CAAA;AAC3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;AAAA,EACf;AACF","file":"chunk-22HBQQF4.js","sourcesContent":["import {\n JsonObjectSchema,\n JsonSchema,\n JsonSchemaPrimitives,\n JsonSchemaTypeName,\n} from '../types/schema.types.js';\nimport { JsonArrayStore } from '../model/schema/json-array.store.js';\nimport { JsonBooleanStore } from '../model/schema/json-boolean.store.js';\nimport { JsonNumberStore } from '../model/schema/json-number.store.js';\nimport { JsonStringStore } from '../model/schema/json-string.store.js';\nimport { JsonObjectStore } from '../model/schema/json-object.store.js';\nimport {\n JsonSchemaStore,\n JsonSchemaStorePrimitives,\n} from '../model/schema/json-schema.store.js';\n\nexport type RefsType = Record<string, JsonSchema>;\n\nexport const createJsonSchemaStore = (\n schema: JsonSchema,\n refs: RefsType = {},\n): JsonSchemaStore => {\n if ('$ref' in schema) {\n const refSchema: JsonSchema | undefined = refs[schema.$ref];\n\n if (!refSchema) {\n throw new Error(`Not found schema for $ref=\"${schema.$ref}\"`);\n }\n\n const refStore = createJsonSchemaStore(refSchema, refs);\n saveSharedFields(refStore, schema);\n refStore.$ref = schema.$ref;\n return refStore;\n } else if (schema.type === JsonSchemaTypeName.Object) {\n const objectStore = createJsonObjectSchemaStore(schema, refs);\n saveSharedFields(objectStore, schema);\n\n return objectStore;\n } else if (schema.type === JsonSchemaTypeName.Array) {\n const itemsStore = createJsonSchemaStore(schema.items, refs);\n const arrayStore = new JsonArrayStore(itemsStore);\n saveSharedFields(arrayStore, schema);\n\n return arrayStore;\n } else {\n const primitivesStore = createPrimitiveStoreBySchema(schema);\n saveSharedFields(primitivesStore, schema);\n primitivesStore.readOnly = schema.readOnly;\n\n return primitivesStore;\n }\n};\n\nexport const createJsonObjectSchemaStore = (\n value: JsonObjectSchema,\n refs: RefsType,\n): JsonObjectStore => {\n const store = new JsonObjectStore();\n\n for (const requiredField of value.required) {\n if (!value.properties[requiredField]) {\n throw new Error(\n `Not found required field \"${requiredField}\" in \"properties\"`,\n );\n }\n }\n\n Object.entries(value.properties).forEach(([name, item]) => {\n store.addPropertyWithStore(name, createJsonSchemaStore(item, refs));\n });\n\n return store;\n};\n\nexport const createPrimitiveStoreBySchema = (\n schema: JsonSchemaPrimitives,\n): JsonSchemaStorePrimitives => {\n if (schema.type === JsonSchemaTypeName.String) {\n const stringStore = new JsonStringStore();\n stringStore.foreignKey = schema.foreignKey;\n stringStore.format = schema.format;\n stringStore.enum = schema.enum;\n stringStore.contentMediaType = schema.contentMediaType;\n stringStore.pattern = schema.pattern;\n return stringStore;\n } else if (schema.type === JsonSchemaTypeName.Number) {\n return new JsonNumberStore();\n } else if (schema.type === JsonSchemaTypeName.Boolean) {\n return new JsonBooleanStore();\n } else {\n throw new Error('this type is not allowed');\n }\n};\n\nexport const saveSharedFields = (\n store: JsonSchemaStore,\n schema: JsonSchema,\n) => {\n store.title = schema.title;\n store.description = schema.description;\n store.deprecated = schema.deprecated;\n};\n","import { JsonSchemaTypeName } from '../types/schema.types.js';\nimport { JsonSchemaStore } from '../model/schema/json-schema.store.js';\n\nexport const getJsonSchemaStoreByPath = (\n store: JsonSchemaStore,\n path: string,\n): JsonSchemaStore => {\n if (path === '') {\n return store;\n }\n\n if (path === '/') {\n throw new Error(\n 'invalid root path, need to use path=\"\" instead of path=\"/\"',\n );\n }\n\n const tokens = path.split('/');\n tokens.shift();\n\n let currentStore = store;\n\n let currentToken = tokens.shift();\n let currentPath = '';\n\n while (currentToken) {\n if (currentStore.type === JsonSchemaTypeName.Object) {\n if (currentToken !== 'properties') {\n throw new Error(\n `Expected \"${currentPath}/properties/*\" instead of ${currentPath}/${currentToken}/*`,\n );\n }\n\n currentPath = `${currentPath}/${currentToken}`;\n\n currentToken = tokens.shift();\n\n if (!currentToken) {\n throw new Error(`Expected property name after \"${currentPath}\"`);\n }\n\n const foundCurrentStore = currentStore.getProperty(currentToken);\n\n if (!foundCurrentStore) {\n throw new Error(`Not found \"${currentToken}\" in \"${currentPath}\"`);\n }\n\n currentStore = foundCurrentStore;\n currentPath = `${currentPath}/${currentToken}`;\n\n currentToken = tokens.shift();\n } else if (currentStore.type === JsonSchemaTypeName.Array) {\n if (currentToken !== 'items') {\n throw new Error(\n `Expected \"${currentPath}/items/*\" instead of ${currentPath}/${currentToken}/*`,\n );\n }\n\n currentPath = `${currentPath}/${currentToken}`;\n\n currentStore = currentStore.items;\n\n currentToken = tokens.shift();\n } else {\n throw new Error(`Unexpected \"${currentToken}\" in \"${currentPath}\"`);\n }\n }\n\n return currentStore;\n};\n","export const getParentForPath = (\n path: string,\n): { parentPath: string; field: string } => {\n if (path === '' || path === '/') {\n throw new Error('Invalid path');\n }\n\n const tokens = path.split('/');\n tokens.shift();\n\n let currentToken = tokens.shift();\n\n let parentPath = '';\n let field = '';\n\n while (currentToken) {\n if (currentToken === 'properties') {\n currentToken = tokens.shift();\n\n if (!currentToken) {\n throw new Error('Invalid path');\n }\n\n field = currentToken;\n\n currentToken = tokens.shift();\n\n if (currentToken) {\n parentPath = `${parentPath}/properties/${field}`;\n }\n } else if (currentToken === 'items') {\n field = currentToken;\n\n currentToken = tokens.shift();\n\n if (currentToken && !['items', 'properties'].includes(currentToken)) {\n throw new Error('Invalid path');\n } else if (currentToken) {\n parentPath = `${parentPath}/items`;\n }\n } else {\n throw new Error('Invalid path');\n }\n }\n\n return {\n parentPath: parentPath,\n field,\n };\n};\n","const maxLength = 64;\n\nexport const VALIDATE_JSON_FIELD_NAME_ERROR_MESSAGE = `It must contain between 1 and ${maxLength} characters, start with a letter or underscore (_), cannot start with two underscores (__), and can only include letters (a-z, A-Z), numbers (0-9), hyphens (-), and underscores (_).`;\n\nconst validPattern = /^(?!__)[a-zA-Z_][a-zA-Z0-9-_]*$/;\n\nexport const validateJsonFieldName = (id: string) => {\n const isInvalid =\n id.length < 1 || id.length > maxLength || !validPattern.test(id);\n\n return !isInvalid;\n};\n","import { JsonSchema, JsonSchemaTypeName } from '../types/schema.types.js';\nimport {\n JsonPatchAdd,\n JsonPatchMove,\n JsonPatchRemove,\n JsonPatchReplace,\n} from '../types/json-patch.types.js';\nimport { JsonSchemaStore } from '../model/schema/json-schema.store.js';\nimport { createJsonSchemaStore } from './createJsonSchemaStore.js';\nimport { getJsonSchemaStoreByPath } from './getJsonSchemaStoreByPath.js';\nimport { getParentForPath } from './getParentForPath.js';\nimport {\n VALIDATE_JSON_FIELD_NAME_ERROR_MESSAGE,\n validateJsonFieldName,\n} from './validateJsonFieldName.js';\n\nexport const applyReplacePatch = (\n store: JsonSchemaStore,\n patch: JsonPatchReplace,\n refs: Record<string, JsonSchema> = {},\n): JsonSchemaStore => {\n const patchStore = createJsonSchemaStore(patch.value, refs);\n const foundStore = getJsonSchemaStoreByPath(store, patch.path);\n\n const parent = foundStore.parent;\n\n if (!parent) {\n return patchStore;\n }\n\n if (parent.type === JsonSchemaTypeName.Object) {\n parent.migratePropertyWithStore(foundStore.name, patchStore);\n } else if (parent.type === JsonSchemaTypeName.Array) {\n parent.migrateItems(patchStore);\n } else {\n throw new Error('Invalid parent');\n }\n\n return store;\n};\n\nexport const applyRemovePatch = (\n rootStore: JsonSchemaStore,\n patch: JsonPatchRemove,\n): void => {\n const foundStore = getJsonSchemaStoreByPath(rootStore, patch.path);\n const parent = foundStore.parent;\n\n if (!parent) {\n throw new Error('Parent does not exist');\n }\n\n if (parent.type !== JsonSchemaTypeName.Object) {\n throw new Error('Cannot remove from non-object');\n }\n\n parent.removeProperty(foundStore.name);\n};\n\nexport const applyAddPatch = (\n rootStore: JsonSchemaStore,\n patch: JsonPatchAdd,\n refs: Record<string, JsonSchema> = {},\n): void => {\n const patchStore = createJsonSchemaStore(patch.value, refs);\n\n const { parentPath, field } = getParentForPath(patch.path);\n const foundParent = getJsonSchemaStoreByPath(rootStore, parentPath);\n\n if (!foundParent) {\n throw new Error('Parent does not exist');\n }\n\n if (foundParent.type !== JsonSchemaTypeName.Object) {\n throw new Error('Cannot add to non-object');\n }\n\n if (foundParent.getProperty(field)) {\n throw new Error(`Field \"${field}\" already exists in parent`);\n }\n\n foundParent.addPropertyWithStore(field, patchStore);\n};\n\nexport const applyMovePatch = (\n store: JsonSchemaStore,\n patch: JsonPatchMove,\n): void => {\n const { parentPath: fromParentPath, field: fromField } = getParentForPath(\n patch.from,\n );\n const { parentPath: toParentPath, field: toField } = getParentForPath(\n patch.path,\n );\n\n const foundFromParent = getJsonSchemaStoreByPath(store, fromParentPath);\n const foundToParent = getJsonSchemaStoreByPath(store, toParentPath);\n\n const isValidToField = validateJsonFieldName(toField);\n\n if (!isValidToField) {\n throw new Error(\n `Invalid name: ${toField}. ${VALIDATE_JSON_FIELD_NAME_ERROR_MESSAGE}`,\n );\n }\n\n if (!foundFromParent || !foundToParent) {\n throw new Error('Cannot move from or to non-existent parent');\n }\n\n if (foundFromParent.type !== JsonSchemaTypeName.Object) {\n throw new Error('Cannot move from non-object parent');\n }\n\n const foundFromField = getJsonSchemaStoreByPath(store, patch.from);\n\n const isMovedPropertyInSameParentPatch =\n foundFromParent === foundToParent &&\n foundFromParent.type === JsonSchemaTypeName.Object &&\n foundFromParent.getProperty(fromField);\n\n if (isMovedPropertyInSameParentPatch) {\n return foundFromParent.changeName(fromField, toField);\n }\n\n if (foundToParent.type === JsonSchemaTypeName.Object) {\n foundFromParent.removeProperty(fromField);\n if (foundToParent.getProperty(toField)) {\n foundToParent.removeProperty(toField);\n }\n foundToParent.addPropertyWithStore(toField, foundFromField);\n return;\n }\n\n if (foundToParent.type === JsonSchemaTypeName.Array) {\n foundFromParent.removeProperty(fromField);\n foundToParent.replaceItems(foundFromField);\n\n return;\n }\n throw new Error('Invalid type of \"to\" parent');\n};\n","import { JsonSchemaTypeName } from '../types/schema.types.js';\nimport { JsonSchemaStore } from '../model/schema/json-schema.store.js';\n\nexport const getDBJsonPathByJsonSchemaStore = (\n store: JsonSchemaStore,\n): string => {\n let node = store;\n\n let path = '';\n\n while (node.parent) {\n if (node.parent.type === JsonSchemaTypeName.Object) {\n path = `.${node.name}${path}`;\n } else if (node.parent.type === JsonSchemaTypeName.Array) {\n path = `[*]${path}`;\n }\n\n node = node.parent;\n }\n\n if (!path) {\n return '$';\n }\n\n return `$${path}`;\n};\n","import { JsonSchemaTypeName } from '../types/schema.types.js';\nimport { JsonSchemaStore } from '../model/schema/json-schema.store.js';\n\nexport const getPathByStore = (store: JsonSchemaStore): string => {\n let node = store;\n\n let path = '';\n\n while (node.parent) {\n if (node.parent.type === JsonSchemaTypeName.Object) {\n path = `/properties/${node.name}${path}`;\n } else if (node.parent.type === JsonSchemaTypeName.Array) {\n path = `/items${path}`;\n }\n\n node = node.parent;\n }\n\n if (!path) {\n return '/';\n }\n\n return `${path}`;\n};\n","import { JsonSchemaTypeName } from '../types/schema.types.js';\nimport { JsonSchemaStore } from '../model/schema/json-schema.store.js';\n\nexport const traverseStore = (\n store: JsonSchemaStore,\n callback: (node: JsonSchemaStore) => void,\n) => {\n callback(store);\n\n if (store.type === JsonSchemaTypeName.Object) {\n Object.values(store.properties).forEach((item) => {\n traverseStore(item, callback);\n });\n } else if (store.type === JsonSchemaTypeName.Array) {\n traverseStore(store.items, callback);\n }\n};\n","import { JsonSchemaTypeName } from '../types/schema.types.js';\nimport { JsonPatch, JsonPatchReplace } from '../types/json-patch.types.js';\nimport { JsonSchemaStore } from '../model/schema/json-schema.store.js';\nimport { getPathByStore } from './getPathByStore.js';\nimport { traverseStore } from './traverseStore.js';\n\nexport const getForeignKeyPatchesFromSchema = (\n store: JsonSchemaStore,\n options: { tableId: string; nextTableId: string },\n) => {\n const stores: JsonPatch[] = [];\n\n traverseStore(store, (item) => {\n if (\n item.type === JsonSchemaTypeName.String &&\n item.foreignKey === options.tableId\n ) {\n item.foreignKey = options.nextTableId;\n\n const patch: JsonPatchReplace = {\n op: 'replace',\n path: getPathByStore(item),\n value: item.getPlainSchema(),\n };\n\n stores.push(patch);\n }\n });\n\n return stores;\n};\n","import { JsonSchemaTypeName } from '../types/schema.types.js';\nimport { JsonSchemaStore } from '../model/schema/json-schema.store.js';\nimport { traverseStore } from './traverseStore.js';\n\nexport const getForeignKeysFromSchema = (store: JsonSchemaStore): string[] => {\n const foreignKeys = new Set<string>();\n\n traverseStore(store, (item) => {\n if (item.type === JsonSchemaTypeName.String && item.foreignKey) {\n foreignKeys.add(item.foreignKey);\n }\n });\n\n return [...foreignKeys].sort((a, b) => a.localeCompare(b));\n};\n","import { JsonSchemaTypeName } from '../types/schema.types.js';\nimport { JsonValueStore } from '../model/value/json-value.store.js';\n\nexport const traverseValue = (\n store: JsonValueStore,\n callback: (node: JsonValueStore) => void,\n) => {\n callback(store);\n\n if (store.type === JsonSchemaTypeName.Object) {\n Object.values(store.value).forEach((item) => {\n traverseValue(item, callback);\n });\n } else if (store.type === JsonSchemaTypeName.Array) {\n store.value.forEach((itemValue) => {\n traverseValue(itemValue, callback);\n });\n }\n};\n","import { JsonSchemaTypeName } from '../types/schema.types.js';\nimport { JsonValueStore } from '../model/value/json-value.store.js';\nimport { traverseValue } from './traverseValue.js';\n\nexport type GetForeignKeysFromValueType = {\n tableId: string;\n rowIds: string[];\n};\n\nexport const getForeignKeysFromValue = (\n value: JsonValueStore,\n): GetForeignKeysFromValueType[] => {\n const foreignKeys = new Map<string, Set<string>>();\n\n traverseValue(value, (item) => {\n if (item.type === JsonSchemaTypeName.String && item.foreignKey) {\n let tableForeignKey = foreignKeys.get(item.foreignKey);\n\n if (!tableForeignKey) {\n tableForeignKey = new Set<string>();\n foreignKeys.set(item.foreignKey, tableForeignKey);\n }\n\n tableForeignKey.add(item.getPlainValue());\n }\n });\n\n return [...foreignKeys].map(([tableId, rowIds]) => ({\n tableId,\n rowIds: [...rowIds].sort((a, b) => a.localeCompare(b)),\n }));\n};\n","import { JsonSchema, JsonSchemaTypeName } from '../types/schema.types.js';\nimport { JsonSchemaStore } from '../model/schema/json-schema.store.js';\nimport { createJsonSchemaStore } from './createJsonSchemaStore.js';\nimport { traverseStore } from './traverseStore.js';\nimport { validateJsonFieldName } from './validateJsonFieldName.js';\n\nexport const getInvalidFieldNamesInSchema = (\n schema: JsonSchema,\n refs: Record<string, JsonSchema> = {},\n) => {\n const schemaStore = createJsonSchemaStore(schema, refs);\n\n const invalidFields: JsonSchemaStore[] = [];\n\n traverseStore(schemaStore, (item) => {\n if (item.parent?.type === JsonSchemaTypeName.Object) {\n if (!validateJsonFieldName(item.name)) {\n invalidFields.push(item);\n }\n }\n });\n\n return invalidFields;\n};\n","import { JsonArrayValueStore } from '../model/value/json-array-value.store.js';\nimport { JsonObjectValueStore } from '../model/value/json-object-value.store.js';\nimport { JsonValueStore } from '../model/value/json-value.store.js';\n\nexport const getJsonValueStoreByPath = (\n root: JsonValueStore,\n path: string,\n): JsonValueStore => {\n if (!path) {\n return root;\n }\n\n const segments = getSegments(path);\n\n let current: JsonValueStore = root;\n\n for (const seg of segments) {\n if (current instanceof JsonObjectValueStore) {\n const next = current.value[String(seg)];\n if (!next) {\n throw new Error(`Path not found at segment \"${seg}\"`);\n }\n current = next;\n } else if (current instanceof JsonArrayValueStore) {\n if (typeof seg !== 'number') {\n throw new Error(`Invalid array index \"${seg}\"`);\n }\n const next = current.value[seg];\n if (!next) {\n throw new Error(`Path not found at segment \"${seg}\"`);\n }\n current = next;\n } else {\n throw new Error(`Cannot navigate into primitive at segment \"${seg}\"`);\n }\n }\n\n return current;\n};\n\nconst regex = /([^.[\\]]+)|\\[(\\d+)]/g;\n\nconst getSegments = (path: string) => {\n const segments: (string | number)[] = [];\n\n let match: RegExpExecArray | null;\n\n while ((match = regex.exec(path))) {\n if (match[1] !== undefined) {\n segments.push(match[1]);\n } else if (match[2] !== undefined) {\n segments.push(Number(match[2]));\n }\n }\n\n return segments;\n};\n","import { JsonSchemaTypeName } from '../types/schema.types.js';\nimport { JsonValueStore } from '../model/value/json-value.store.js';\nimport { traverseValue } from './traverseValue.js';\n\nexport type ReplaceForeignKeyValueOptions = {\n valueStore: JsonValueStore;\n foreignKey: string;\n value: string;\n nextValue: string;\n};\n\nexport const replaceForeignKeyValue = (\n options: ReplaceForeignKeyValueOptions,\n) => {\n let wasUpdated = false;\n\n traverseValue(options.valueStore, (item) => {\n if (\n item.type === JsonSchemaTypeName.String &&\n item.foreignKey === options.foreignKey &&\n item.value === options.value\n ) {\n item.value = options.nextValue;\n wasUpdated = true;\n }\n });\n\n return wasUpdated;\n};\n","import { SystemSchemaIds } from '../consts/system-schema-ids.js';\nimport { createJsonSchemaStore } from './createJsonSchemaStore.js';\nimport {\n fileSchema,\n rowCreatedAtSchema,\n rowCreatedIdSchema,\n rowHashSchema,\n rowPublishedAtSchema,\n rowSchemaHashSchema,\n rowUpdatedAtSchema,\n rowVersionIdSchema,\n rowIdSchema,\n} from '../plugins/index.js';\nimport { JsonSchema } from '../types/schema.types.js';\n\nexport const pluginRefs: Readonly<Record<string, JsonSchema>> = {\n [SystemSchemaIds.RowId]: rowIdSchema,\n [SystemSchemaIds.RowVersionId]: rowVersionIdSchema,\n [SystemSchemaIds.RowCreatedId]: rowCreatedIdSchema,\n [SystemSchemaIds.RowCreatedAt]: rowCreatedAtSchema,\n [SystemSchemaIds.RowPublishedAt]: rowPublishedAtSchema,\n [SystemSchemaIds.RowUpdatedAt]: rowUpdatedAtSchema,\n [SystemSchemaIds.RowHash]: rowHashSchema,\n [SystemSchemaIds.RowSchemaHash]: rowSchemaHashSchema,\n [SystemSchemaIds.File]: fileSchema,\n};\n\nexport const resolveRefs = (schema: JsonSchema) => {\n const store = createJsonSchemaStore(schema, pluginRefs);\n return store.getPlainSchema({ skip$Ref: true });\n};\n","import { JsonSchema } from '../types/schema.types.js';\nimport { JsonValue } from '../types/json.types.js';\nimport { JsonPatch } from '../types/json-patch.types.js';\nimport { JsonSchemaStore } from '../model/schema/json-schema.store.js';\nimport { JsonValueStore } from '../model/value/json-value.store.js';\nimport { getTransformation } from '../model/value/value-transformation.js';\nimport { createJsonSchemaStore } from './createJsonSchemaStore.js';\nimport { createJsonValueStore } from './createJsonValueStore.js';\nimport {\n applyAddPatch,\n applyMovePatch,\n applyRemovePatch,\n applyReplacePatch,\n} from './applyPatches.js';\n\nexport class SchemaTable {\n private readonly rows = new Map<string, JsonValueStore>();\n private store: JsonSchemaStore;\n\n constructor(\n schema: JsonSchema,\n private readonly refs: Record<string, JsonSchema> = {},\n ) {\n this.store = createJsonSchemaStore(schema, refs);\n }\n\n public applyPatches(patches: JsonPatch[]): void {\n patches.forEach((patch) => {\n switch (patch.op) {\n case 'replace': {\n const nextStore = applyReplacePatch(this.store, patch, this.refs);\n if (nextStore !== this.store) {\n this.migrateRows(nextStore);\n }\n break;\n }\n case 'remove': {\n applyRemovePatch(this.store, patch);\n break;\n }\n case 'add': {\n applyAddPatch(this.store, patch, this.refs);\n break;\n }\n case 'move': {\n applyMovePatch(this.store, patch);\n break;\n }\n default:\n throw new Error(`Unsupported patch operation`);\n }\n });\n }\n\n public getSchema(): JsonSchema {\n return this.store.getPlainSchema();\n }\n\n public addRow(rowId: string, data: JsonValue) {\n const row = createJsonValueStore(this.store, rowId, data);\n\n this.rows.set(rowId, row);\n }\n\n public getRow(id: string): JsonValue {\n const row = this.rows.get(id);\n\n if (!row) {\n throw new Error('Invalid id');\n }\n\n return row.getPlainValue();\n }\n\n public getRows(): { id: string; data: JsonValue }[] {\n return [...this.rows].map(([id, data]) => ({\n id,\n data: data.getPlainValue(),\n }));\n }\n\n private migrateRows(nextStore: JsonSchemaStore): void {\n const transformation = getTransformation(this.store, nextStore);\n\n if (transformation) {\n for (const [rowId, row] of this.rows) {\n const rawNextValue = transformation(\n row.getPlainValue(),\n nextStore.default,\n ) as JsonValue;\n\n const nextRow = createJsonValueStore(nextStore, rowId, rawNextValue);\n this.rows.set(rowId, nextRow);\n }\n }\n\n this.store = nextStore;\n }\n}\n"]}
|