@revisium/schema-toolkit 0.21.5 → 0.22.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 +63 -2
- package/dist/chunk-5G3AVY57.js +1 -0
- package/dist/chunk-5M74TGFQ.cjs +2 -0
- package/dist/{chunk-RXPIMS7W.js → chunk-B3W5BASK.js} +20 -2
- package/dist/{chunk-JLXX3SGF.js → chunk-GAP5KNWN.js} +229 -2
- package/dist/{chunk-XKWWCXGB.js → chunk-HOMXBUQB.js} +143 -20
- package/dist/{chunk-DN2C3T5D.cjs → chunk-JHNATNUI.cjs} +20 -2
- package/dist/{chunk-QKA7DJDN.cjs → chunk-WY3CL7KH.cjs} +143 -19
- package/dist/{chunk-7JWCZZPJ.cjs → chunk-YZEJKK4O.cjs} +236 -0
- package/dist/index.cjs +122 -97
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -3
- package/dist/lib/index.cjs +54 -33
- package/dist/lib/index.d.cts +49 -1
- package/dist/lib/index.d.ts +49 -1
- package/dist/lib/index.js +2 -1
- package/dist/model/index.cjs +46 -46
- package/dist/model/index.d.cts +11 -3
- package/dist/model/index.d.ts +11 -3
- package/dist/model/index.js +1 -1
- package/dist/{typed-DjSH_5Vh.d.cts → typed-C0YM-ar9.d.cts} +6 -0
- package/dist/{typed-KUia-LYN.d.ts → typed-CkirI6bH.d.ts} +6 -0
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/validation-schemas/index.cjs +23 -18
- package/dist/validation-schemas/index.d.cts +3 -1
- package/dist/validation-schemas/index.d.ts +3 -1
- package/dist/validation-schemas/index.js +2 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -49,7 +49,41 @@ row.getValue('name'); // string (typed!)
|
|
|
49
49
|
row.setValue('price', 19.99); // OK
|
|
50
50
|
row.setValue('price', 'wrong'); // TS Error!
|
|
51
51
|
row.getPlainValue(); // { name: string, price: number }
|
|
52
|
-
row.
|
|
52
|
+
row.patches; // JSON Patch operations
|
|
53
|
+
row.root; // typed root node (InferNode<S>)
|
|
54
|
+
row.reset({ name: 'New', price: 0 }); // reset to new data, commit
|
|
55
|
+
row.reset(); // reset to schema defaults
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Array Search
|
|
59
|
+
|
|
60
|
+
Arrays expose `find` and `findIndex` for searching elements by node properties:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { obj, str, arr, createRowModel } from '@revisium/schema-toolkit';
|
|
64
|
+
|
|
65
|
+
const schema = obj({
|
|
66
|
+
sorts: arr(obj({ field: str(), direction: str() })),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const row = createRowModel({
|
|
70
|
+
rowId: 'row-1',
|
|
71
|
+
schema,
|
|
72
|
+
data: { sorts: [
|
|
73
|
+
{ field: 'name', direction: 'asc' },
|
|
74
|
+
{ field: 'age', direction: 'desc' },
|
|
75
|
+
]},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const sortsNode = row.get('sorts');
|
|
79
|
+
// find returns the typed node
|
|
80
|
+
const ageSort = sortsNode.find(
|
|
81
|
+
(node) => node.child('field').getPlainValue() === 'age',
|
|
82
|
+
);
|
|
83
|
+
// findIndex returns the index
|
|
84
|
+
const idx = sortsNode.findIndex(
|
|
85
|
+
(node) => node.child('field').getPlainValue() === 'age',
|
|
86
|
+
); // 1
|
|
53
87
|
```
|
|
54
88
|
|
|
55
89
|
### TableModel
|
|
@@ -215,6 +249,33 @@ See [ForeignKeyResolver docs](src/model/foreign-key-resolver/README.md) for cach
|
|
|
215
249
|
| `createRowModel(options)` | Create a row model (typed overload when schema is typed) |
|
|
216
250
|
| `createTableModel(options)` | Create a table model (typed overload when schema is typed) |
|
|
217
251
|
|
|
252
|
+
#### RowModel
|
|
253
|
+
|
|
254
|
+
| Property / Method | Description |
|
|
255
|
+
|-------------------|-------------|
|
|
256
|
+
| `root` | Typed root node (`InferNode<S>` for typed, `ValueNode` for untyped) |
|
|
257
|
+
| `get(path)` | Get node at path |
|
|
258
|
+
| `getValue(path)` | Get plain value at path |
|
|
259
|
+
| `setValue(path, value)` | Set value at path |
|
|
260
|
+
| `getPlainValue()` | Get full plain value |
|
|
261
|
+
| `patches` | JSON Patch operations (`JsonValuePatch[]`) for current changes |
|
|
262
|
+
| `reset(data?)` | Reset to given data (or schema defaults) and commit |
|
|
263
|
+
| `commit()` | Commit current state as base |
|
|
264
|
+
| `revert()` | Revert to last committed state |
|
|
265
|
+
|
|
266
|
+
#### ArrayValueNode
|
|
267
|
+
|
|
268
|
+
| Method | Description |
|
|
269
|
+
|--------|-------------|
|
|
270
|
+
| `at(index)` | Get element at index (supports negative) |
|
|
271
|
+
| `find(predicate)` | Find first element matching predicate, or `undefined` |
|
|
272
|
+
| `findIndex(predicate)` | Find index of first matching element, or `-1` |
|
|
273
|
+
| `push(node)` | Append element |
|
|
274
|
+
| `pushValue(value?)` | Create and append element from value |
|
|
275
|
+
| `removeAt(index)` | Remove element at index |
|
|
276
|
+
| `move(from, to)` | Move element between positions |
|
|
277
|
+
| `clear()` | Remove all elements |
|
|
278
|
+
|
|
218
279
|
### Value Tree
|
|
219
280
|
|
|
220
281
|
| Function | Description |
|
|
@@ -268,7 +329,7 @@ See [ForeignKeyResolver docs](src/model/foreign-key-resolver/README.md) for cach
|
|
|
268
329
|
| `InferNode<S>` | Schema → typed ValueNode interface |
|
|
269
330
|
| `SchemaFromValue<T>` | Plain TS type → virtual schema shape |
|
|
270
331
|
| `SchemaPaths<S>` | Union of all valid dot-separated paths |
|
|
271
|
-
| `TypedRowModel<S>` | RowModel with typed `getValue`, `setValue`, `getPlainValue` |
|
|
332
|
+
| `TypedRowModel<S>` | RowModel with typed `root`, `getValue`, `setValue`, `getPlainValue`, `reset` |
|
|
272
333
|
| `TypedTableModel<S>` | TableModel with typed rows, `addRow`, `getRow` |
|
|
273
334
|
|
|
274
335
|
See [Typed API documentation](src/types/TYPED-API.md) for the full reference.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -1742,6 +1742,12 @@ var ArrayValueNode = class extends BaseValueNode {
|
|
|
1742
1742
|
}
|
|
1743
1743
|
return this._items[index];
|
|
1744
1744
|
}
|
|
1745
|
+
find(predicate) {
|
|
1746
|
+
return this._items.find((node, index) => predicate(node, index));
|
|
1747
|
+
}
|
|
1748
|
+
findIndex(predicate) {
|
|
1749
|
+
return this._items.findIndex((node, index) => predicate(node, index));
|
|
1750
|
+
}
|
|
1745
1751
|
push(node) {
|
|
1746
1752
|
node.parent = this;
|
|
1747
1753
|
this._items.push(node);
|
|
@@ -3137,12 +3143,16 @@ var ValueTree = class {
|
|
|
3137
3143
|
// src/model/table/row/RowModelImpl.ts
|
|
3138
3144
|
var UNSET_INDEX = -1;
|
|
3139
3145
|
var RowModelImpl = class {
|
|
3140
|
-
constructor(_rowId, _tree) {
|
|
3146
|
+
constructor(_rowId, _tree, _schema, _refSchemas) {
|
|
3141
3147
|
this._rowId = _rowId;
|
|
3142
3148
|
this._tree = _tree;
|
|
3149
|
+
this._schema = _schema;
|
|
3150
|
+
this._refSchemas = _refSchemas;
|
|
3143
3151
|
makeAutoObservable(this, {
|
|
3144
3152
|
_rowId: false,
|
|
3145
3153
|
_tree: false,
|
|
3154
|
+
_schema: false,
|
|
3155
|
+
_refSchemas: false,
|
|
3146
3156
|
_tableModel: "observable.ref"
|
|
3147
3157
|
});
|
|
3148
3158
|
}
|
|
@@ -3156,6 +3166,9 @@ var RowModelImpl = class {
|
|
|
3156
3166
|
get tree() {
|
|
3157
3167
|
return this._tree;
|
|
3158
3168
|
}
|
|
3169
|
+
get root() {
|
|
3170
|
+
return this._tree.root;
|
|
3171
|
+
}
|
|
3159
3172
|
get index() {
|
|
3160
3173
|
if (!this._tableModel) {
|
|
3161
3174
|
return UNSET_INDEX;
|
|
@@ -3215,6 +3228,11 @@ var RowModelImpl = class {
|
|
|
3215
3228
|
revert() {
|
|
3216
3229
|
this._tree.revert();
|
|
3217
3230
|
}
|
|
3231
|
+
reset(data) {
|
|
3232
|
+
const value = data ?? generateDefaultValue(this._schema, { refSchemas: this._refSchemas });
|
|
3233
|
+
this._tree.setValue("", value);
|
|
3234
|
+
this._tree.commit();
|
|
3235
|
+
}
|
|
3218
3236
|
dispose() {
|
|
3219
3237
|
this._tree.dispose();
|
|
3220
3238
|
}
|
|
@@ -3232,7 +3250,7 @@ function createRowModel(options) {
|
|
|
3232
3250
|
const valueTree = new ValueTree(rootNode);
|
|
3233
3251
|
const formulaEngine = new FormulaEngine(valueTree);
|
|
3234
3252
|
valueTree.setFormulaEngine(formulaEngine);
|
|
3235
|
-
return new RowModelImpl(options.rowId, valueTree);
|
|
3253
|
+
return new RowModelImpl(options.rowId, valueTree, options.schema, options.refSchemas);
|
|
3236
3254
|
}
|
|
3237
3255
|
|
|
3238
3256
|
// src/model/table/TableModelImpl.ts
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { fileSchema, rowSchemaHashSchema, rowHashSchema, rowUpdatedAtSchema, rowPublishedAtSchema, rowCreatedAtSchema, rowCreatedIdSchema, rowVersionIdSchema, rowIdSchema } from './chunk-4U2RZHMX.js';
|
|
1
|
+
import { fileSchema, rowSchemaHashSchema, rowHashSchema, rowUpdatedAtSchema, rowPublishedAtSchema, rowCreatedAtSchema, rowCreatedIdSchema, rowVersionIdSchema, rowIdSchema, ajvRowIdSchema, ajvRowCreatedIdSchema, ajvRowVersionIdSchema, ajvRowCreatedAtSchema, ajvRowPublishedAtSchema, ajvRowUpdatedAtSchema, ajvRowHashSchema, ajvRowSchemaHashSchema, ajvFileSchema } from './chunk-4U2RZHMX.js';
|
|
2
2
|
import { JsonArrayStore, JsonObjectStore, JsonStringStore, JsonNumberStore, JsonBooleanStore, JsonObjectValueStore, JsonArrayValueStore, createJsonValueStore, getTransformation } from './chunk-FTBRJODD.js';
|
|
3
|
+
import { metaSchema, jsonPatchSchema, tableMigrationsSchema, historyPatchesSchema, tableViewsSchema } from './chunk-HOMXBUQB.js';
|
|
4
|
+
import Ajv from 'ajv/dist/2020';
|
|
3
5
|
|
|
4
6
|
// src/lib/createJsonSchemaStore.ts
|
|
5
7
|
var createJsonSchemaStore = (schema, refs = {}) => {
|
|
@@ -729,5 +731,230 @@ var SchemaTable = class {
|
|
|
729
731
|
this.store = nextStore;
|
|
730
732
|
}
|
|
731
733
|
};
|
|
734
|
+
var mapErrors = (errors) => {
|
|
735
|
+
if (!errors || errors.length === 0) {
|
|
736
|
+
return null;
|
|
737
|
+
}
|
|
738
|
+
return errors.map((err) => ({
|
|
739
|
+
instancePath: err.instancePath,
|
|
740
|
+
message: err.message,
|
|
741
|
+
keyword: err.keyword,
|
|
742
|
+
params: err.params
|
|
743
|
+
}));
|
|
744
|
+
};
|
|
745
|
+
var wrapValidateFn = (ajvFn) => {
|
|
746
|
+
const fn = ((data) => {
|
|
747
|
+
const result = ajvFn(data);
|
|
748
|
+
fn.errors = mapErrors(ajvFn.errors);
|
|
749
|
+
return result;
|
|
750
|
+
});
|
|
751
|
+
fn.errors = null;
|
|
752
|
+
return fn;
|
|
753
|
+
};
|
|
754
|
+
var RevisiumValidator = class {
|
|
755
|
+
validateMetaSchema;
|
|
756
|
+
validateJsonPatch;
|
|
757
|
+
validateMigrations;
|
|
758
|
+
validateHistoryPatches;
|
|
759
|
+
validateTableViews;
|
|
760
|
+
ajv;
|
|
761
|
+
cache = /* @__PURE__ */ new Map();
|
|
762
|
+
constructor() {
|
|
763
|
+
this.ajv = new Ajv();
|
|
764
|
+
this.ajv.addKeyword({
|
|
765
|
+
keyword: "foreignKey",
|
|
766
|
+
type: "string"
|
|
767
|
+
});
|
|
768
|
+
this.ajv.addKeyword({
|
|
769
|
+
keyword: "x-formula"
|
|
770
|
+
});
|
|
771
|
+
this.ajv.addFormat("regex", {
|
|
772
|
+
type: "string",
|
|
773
|
+
validate: (str) => {
|
|
774
|
+
try {
|
|
775
|
+
new RegExp(str);
|
|
776
|
+
return true;
|
|
777
|
+
} catch {
|
|
778
|
+
return false;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
});
|
|
782
|
+
this.ajv.compile(ajvRowIdSchema);
|
|
783
|
+
this.ajv.compile(ajvRowCreatedIdSchema);
|
|
784
|
+
this.ajv.compile(ajvRowVersionIdSchema);
|
|
785
|
+
this.ajv.compile(ajvRowCreatedAtSchema);
|
|
786
|
+
this.ajv.compile(ajvRowPublishedAtSchema);
|
|
787
|
+
this.ajv.compile(ajvRowUpdatedAtSchema);
|
|
788
|
+
this.ajv.compile(ajvRowHashSchema);
|
|
789
|
+
this.ajv.compile(ajvRowSchemaHashSchema);
|
|
790
|
+
this.ajv.compile(ajvFileSchema);
|
|
791
|
+
this.validateMetaSchema = wrapValidateFn(this.ajv.compile(metaSchema));
|
|
792
|
+
this.validateJsonPatch = wrapValidateFn(this.ajv.compile(jsonPatchSchema));
|
|
793
|
+
this.validateMigrations = wrapValidateFn(
|
|
794
|
+
this.ajv.compile(tableMigrationsSchema)
|
|
795
|
+
);
|
|
796
|
+
this.validateHistoryPatches = wrapValidateFn(
|
|
797
|
+
this.ajv.compile(historyPatchesSchema)
|
|
798
|
+
);
|
|
799
|
+
this.validateTableViews = wrapValidateFn(
|
|
800
|
+
this.ajv.compile(tableViewsSchema)
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
compile(schema) {
|
|
804
|
+
const key = JSON.stringify(schema);
|
|
805
|
+
const cached = this.cache.get(key);
|
|
806
|
+
if (cached) {
|
|
807
|
+
return cached;
|
|
808
|
+
}
|
|
809
|
+
const fn = wrapValidateFn(
|
|
810
|
+
this.ajv.compile(schema)
|
|
811
|
+
);
|
|
812
|
+
this.cache.set(key, fn);
|
|
813
|
+
return fn;
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
// src/lib/validateRevisiumSchema.ts
|
|
818
|
+
var cachedValidator = null;
|
|
819
|
+
var getValidator = () => {
|
|
820
|
+
if (cachedValidator) {
|
|
821
|
+
return cachedValidator;
|
|
822
|
+
}
|
|
823
|
+
cachedValidator = new RevisiumValidator();
|
|
824
|
+
return cachedValidator;
|
|
825
|
+
};
|
|
826
|
+
var validateRevisiumSchema = (schema) => {
|
|
827
|
+
const validator = getValidator();
|
|
828
|
+
const valid = validator.validateMetaSchema(schema);
|
|
829
|
+
if (valid) {
|
|
830
|
+
return { valid: true };
|
|
831
|
+
}
|
|
832
|
+
const errors = (validator.validateMetaSchema.errors ?? []).map((err) => {
|
|
833
|
+
const path = err.instancePath || "/";
|
|
834
|
+
return `${path}: ${err.message ?? "unknown error"}`;
|
|
835
|
+
});
|
|
836
|
+
return { valid: false, errors };
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
// src/lib/calculateSchemaWeight.ts
|
|
840
|
+
var calculateSchemaWeight = (schema) => {
|
|
841
|
+
const result = {
|
|
842
|
+
totalFields: 0,
|
|
843
|
+
maxDepth: 0,
|
|
844
|
+
fieldNames: 0,
|
|
845
|
+
totalArrays: 0,
|
|
846
|
+
maxArrayDepth: 0
|
|
847
|
+
};
|
|
848
|
+
walkSchema(schema, 0, 0, result);
|
|
849
|
+
return result;
|
|
850
|
+
};
|
|
851
|
+
var walkSchema = (schema, depth, arrayDepth, result) => {
|
|
852
|
+
if (result.maxDepth < depth) {
|
|
853
|
+
result.maxDepth = depth;
|
|
854
|
+
}
|
|
855
|
+
if ("$ref" in schema) {
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
if (schema.type === "object" && schema.properties) {
|
|
859
|
+
for (const [fieldName, fieldSchema] of Object.entries(schema.properties)) {
|
|
860
|
+
result.totalFields++;
|
|
861
|
+
result.fieldNames += fieldName.length;
|
|
862
|
+
walkSchema(fieldSchema, depth + 1, arrayDepth, result);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
if (schema.type === "array" && schema.items) {
|
|
866
|
+
const nextArrayDepth = arrayDepth + 1;
|
|
867
|
+
result.totalArrays++;
|
|
868
|
+
if (nextArrayDepth > result.maxArrayDepth) {
|
|
869
|
+
result.maxArrayDepth = nextArrayDepth;
|
|
870
|
+
}
|
|
871
|
+
walkSchema(schema.items, depth + 1, nextArrayDepth, result);
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
|
|
875
|
+
// src/lib/calculateDataWeight.ts
|
|
876
|
+
var calculateDataWeight = (data) => {
|
|
877
|
+
const result = {
|
|
878
|
+
totalBytes: 0,
|
|
879
|
+
totalNodes: 0,
|
|
880
|
+
maxDepth: 0,
|
|
881
|
+
maxArrayLength: 0,
|
|
882
|
+
maxStringLength: 0,
|
|
883
|
+
totalStringsLength: 0
|
|
884
|
+
};
|
|
885
|
+
result.totalBytes = JSON.stringify(data).length;
|
|
886
|
+
walkValue(data, 0, result);
|
|
887
|
+
return result;
|
|
888
|
+
};
|
|
889
|
+
var walkValue = (value, depth, result) => {
|
|
890
|
+
result.totalNodes++;
|
|
891
|
+
if (result.maxDepth < depth) {
|
|
892
|
+
result.maxDepth = depth;
|
|
893
|
+
}
|
|
894
|
+
if (value === null || value === void 0) {
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
if (typeof value === "string") {
|
|
898
|
+
if (value.length > result.maxStringLength) {
|
|
899
|
+
result.maxStringLength = value.length;
|
|
900
|
+
}
|
|
901
|
+
result.totalStringsLength += value.length;
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
if (Array.isArray(value)) {
|
|
908
|
+
if (value.length > result.maxArrayLength) {
|
|
909
|
+
result.maxArrayLength = value.length;
|
|
910
|
+
}
|
|
911
|
+
for (const item of value) {
|
|
912
|
+
walkValue(item, depth + 1, result);
|
|
913
|
+
}
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
if (typeof value === "object") {
|
|
917
|
+
for (const val of Object.values(value)) {
|
|
918
|
+
walkValue(val, depth + 1, result);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
var calculateDataWeightFromStore = (store) => {
|
|
923
|
+
const result = {
|
|
924
|
+
totalBytes: 0,
|
|
925
|
+
totalNodes: 0,
|
|
926
|
+
maxDepth: 0,
|
|
927
|
+
maxArrayLength: 0,
|
|
928
|
+
maxStringLength: 0,
|
|
929
|
+
totalStringsLength: 0
|
|
930
|
+
};
|
|
931
|
+
result.totalBytes = JSON.stringify(store.getPlainValue()).length;
|
|
932
|
+
walkStore(store, 0, result);
|
|
933
|
+
return result;
|
|
934
|
+
};
|
|
935
|
+
var walkStore = (store, depth, result) => {
|
|
936
|
+
result.totalNodes++;
|
|
937
|
+
if (result.maxDepth < depth) {
|
|
938
|
+
result.maxDepth = depth;
|
|
939
|
+
}
|
|
940
|
+
if (store.type === "string") {
|
|
941
|
+
const val = store.getPlainValue();
|
|
942
|
+
if (val.length > result.maxStringLength) {
|
|
943
|
+
result.maxStringLength = val.length;
|
|
944
|
+
}
|
|
945
|
+
result.totalStringsLength += val.length;
|
|
946
|
+
} else if (store.type === "object") {
|
|
947
|
+
for (const child of Object.values(store.value)) {
|
|
948
|
+
walkStore(child, depth + 1, result);
|
|
949
|
+
}
|
|
950
|
+
} else if (store.type === "array") {
|
|
951
|
+
if (store.value.length > result.maxArrayLength) {
|
|
952
|
+
result.maxArrayLength = store.value.length;
|
|
953
|
+
}
|
|
954
|
+
for (const child of store.value) {
|
|
955
|
+
walkStore(child, depth + 1, result);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
};
|
|
732
959
|
|
|
733
|
-
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 };
|
|
960
|
+
export { RevisiumValidator, SchemaTable, VALIDATE_JSON_FIELD_NAME_ERROR_MESSAGE, applyAddPatch, applyMovePatch, applyRemovePatch, applyReplacePatch, calculateDataWeight, calculateDataWeightFromStore, calculateSchemaWeight, 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, validateRevisiumSchema };
|
|
@@ -317,25 +317,6 @@ var jsonPatchSchema = {
|
|
|
317
317
|
type: "array"
|
|
318
318
|
};
|
|
319
319
|
|
|
320
|
-
// src/validation-schemas/history-patches-schema.ts
|
|
321
|
-
var historyPatchesSchema = {
|
|
322
|
-
$id: "history-patches-schema.json",
|
|
323
|
-
type: "array",
|
|
324
|
-
minItems: 1,
|
|
325
|
-
items: {
|
|
326
|
-
type: "object",
|
|
327
|
-
properties: {
|
|
328
|
-
patches: {
|
|
329
|
-
$ref: "json-patch-schema.json"
|
|
330
|
-
},
|
|
331
|
-
hash: {
|
|
332
|
-
type: "string"
|
|
333
|
-
}
|
|
334
|
-
},
|
|
335
|
-
required: ["patches", "hash"]
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
|
|
339
320
|
// src/validation-schemas/table-migrations-schema.ts
|
|
340
321
|
var tableMigrationsSchema = {
|
|
341
322
|
$id: "table-migrations-schema.json",
|
|
@@ -395,4 +376,146 @@ var tableMigrationsSchema = {
|
|
|
395
376
|
title: "JSON Schema for a Single Migration"
|
|
396
377
|
};
|
|
397
378
|
|
|
398
|
-
|
|
379
|
+
// src/validation-schemas/history-patches-schema.ts
|
|
380
|
+
var historyPatchesSchema = {
|
|
381
|
+
$id: "history-patches-schema.json",
|
|
382
|
+
type: "array",
|
|
383
|
+
minItems: 1,
|
|
384
|
+
items: {
|
|
385
|
+
type: "object",
|
|
386
|
+
properties: {
|
|
387
|
+
patches: {
|
|
388
|
+
$ref: "json-patch-schema.json"
|
|
389
|
+
},
|
|
390
|
+
hash: {
|
|
391
|
+
type: "string"
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
required: ["patches", "hash"]
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
// src/validation-schemas/table-views-schema.ts
|
|
399
|
+
var tableViewsSchema = {
|
|
400
|
+
$id: "table-views-schema.json",
|
|
401
|
+
type: "object",
|
|
402
|
+
additionalProperties: false,
|
|
403
|
+
required: ["version", "views"],
|
|
404
|
+
properties: {
|
|
405
|
+
version: {
|
|
406
|
+
type: "integer",
|
|
407
|
+
minimum: 1,
|
|
408
|
+
default: 1
|
|
409
|
+
},
|
|
410
|
+
defaultViewId: {
|
|
411
|
+
type: "string",
|
|
412
|
+
default: "default"
|
|
413
|
+
},
|
|
414
|
+
views: {
|
|
415
|
+
type: "array",
|
|
416
|
+
items: { $ref: "#/$defs/View" },
|
|
417
|
+
default: []
|
|
418
|
+
}
|
|
419
|
+
},
|
|
420
|
+
$defs: {
|
|
421
|
+
View: {
|
|
422
|
+
type: "object",
|
|
423
|
+
additionalProperties: false,
|
|
424
|
+
required: ["id", "name"],
|
|
425
|
+
properties: {
|
|
426
|
+
id: { type: "string", minLength: 1 },
|
|
427
|
+
name: { type: "string", minLength: 1, maxLength: 100 },
|
|
428
|
+
description: { type: "string", maxLength: 500, default: "" },
|
|
429
|
+
columns: {
|
|
430
|
+
oneOf: [
|
|
431
|
+
{ type: "null" },
|
|
432
|
+
{ type: "array", items: { $ref: "#/$defs/Column" } }
|
|
433
|
+
],
|
|
434
|
+
default: null
|
|
435
|
+
},
|
|
436
|
+
filters: { $ref: "#/$defs/FilterGroup" },
|
|
437
|
+
sorts: {
|
|
438
|
+
type: "array",
|
|
439
|
+
items: { $ref: "#/$defs/Sort" },
|
|
440
|
+
default: []
|
|
441
|
+
},
|
|
442
|
+
search: {
|
|
443
|
+
type: "string",
|
|
444
|
+
default: ""
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
Column: {
|
|
449
|
+
type: "object",
|
|
450
|
+
additionalProperties: false,
|
|
451
|
+
required: ["field"],
|
|
452
|
+
properties: {
|
|
453
|
+
field: { type: "string", minLength: 1 },
|
|
454
|
+
width: { type: "number", minimum: 40 }
|
|
455
|
+
}
|
|
456
|
+
},
|
|
457
|
+
FilterGroup: {
|
|
458
|
+
type: "object",
|
|
459
|
+
additionalProperties: false,
|
|
460
|
+
properties: {
|
|
461
|
+
logic: {
|
|
462
|
+
type: "string",
|
|
463
|
+
enum: ["and", "or"],
|
|
464
|
+
default: "and"
|
|
465
|
+
},
|
|
466
|
+
conditions: {
|
|
467
|
+
type: "array",
|
|
468
|
+
items: { $ref: "#/$defs/FilterCondition" },
|
|
469
|
+
default: []
|
|
470
|
+
},
|
|
471
|
+
groups: {
|
|
472
|
+
type: "array",
|
|
473
|
+
items: { $ref: "#/$defs/FilterGroup" },
|
|
474
|
+
default: []
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
},
|
|
478
|
+
FilterCondition: {
|
|
479
|
+
type: "object",
|
|
480
|
+
additionalProperties: false,
|
|
481
|
+
required: ["field", "operator"],
|
|
482
|
+
properties: {
|
|
483
|
+
field: { type: "string", minLength: 1 },
|
|
484
|
+
operator: {
|
|
485
|
+
type: "string",
|
|
486
|
+
enum: [
|
|
487
|
+
"equals",
|
|
488
|
+
"not_equals",
|
|
489
|
+
"contains",
|
|
490
|
+
"not_contains",
|
|
491
|
+
"starts_with",
|
|
492
|
+
"ends_with",
|
|
493
|
+
"is_empty",
|
|
494
|
+
"is_not_empty",
|
|
495
|
+
"gt",
|
|
496
|
+
"gte",
|
|
497
|
+
"lt",
|
|
498
|
+
"lte",
|
|
499
|
+
"is_true",
|
|
500
|
+
"is_false"
|
|
501
|
+
]
|
|
502
|
+
},
|
|
503
|
+
value: {}
|
|
504
|
+
}
|
|
505
|
+
},
|
|
506
|
+
Sort: {
|
|
507
|
+
type: "object",
|
|
508
|
+
additionalProperties: false,
|
|
509
|
+
required: ["field", "direction"],
|
|
510
|
+
properties: {
|
|
511
|
+
field: { type: "string", minLength: 1 },
|
|
512
|
+
direction: {
|
|
513
|
+
type: "string",
|
|
514
|
+
enum: ["asc", "desc"]
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
export { arrayMetaSchema, baseStringFields, booleanMetaSchema, foreignKeyExcludesFormula, historyPatchesSchema, jsonPatchSchema, metaSchema, noForeignKeyStringMetaSchema, notForeignKeyMetaSchema, numberMetaSchema, objectMetaSchema, refMetaSchema, sharedFields, stringMetaSchema, tableMigrationsSchema, tableViewsSchema, xFormulaRequiresReadOnly, xFormulaSchema };
|
|
@@ -1744,6 +1744,12 @@ var ArrayValueNode = class extends BaseValueNode {
|
|
|
1744
1744
|
}
|
|
1745
1745
|
return this._items[index];
|
|
1746
1746
|
}
|
|
1747
|
+
find(predicate) {
|
|
1748
|
+
return this._items.find((node, index) => predicate(node, index));
|
|
1749
|
+
}
|
|
1750
|
+
findIndex(predicate) {
|
|
1751
|
+
return this._items.findIndex((node, index) => predicate(node, index));
|
|
1752
|
+
}
|
|
1747
1753
|
push(node) {
|
|
1748
1754
|
node.parent = this;
|
|
1749
1755
|
this._items.push(node);
|
|
@@ -3139,12 +3145,16 @@ var ValueTree = class {
|
|
|
3139
3145
|
// src/model/table/row/RowModelImpl.ts
|
|
3140
3146
|
var UNSET_INDEX = -1;
|
|
3141
3147
|
var RowModelImpl = class {
|
|
3142
|
-
constructor(_rowId, _tree) {
|
|
3148
|
+
constructor(_rowId, _tree, _schema, _refSchemas) {
|
|
3143
3149
|
this._rowId = _rowId;
|
|
3144
3150
|
this._tree = _tree;
|
|
3151
|
+
this._schema = _schema;
|
|
3152
|
+
this._refSchemas = _refSchemas;
|
|
3145
3153
|
chunkPJ5OFCLO_cjs.makeAutoObservable(this, {
|
|
3146
3154
|
_rowId: false,
|
|
3147
3155
|
_tree: false,
|
|
3156
|
+
_schema: false,
|
|
3157
|
+
_refSchemas: false,
|
|
3148
3158
|
_tableModel: "observable.ref"
|
|
3149
3159
|
});
|
|
3150
3160
|
}
|
|
@@ -3158,6 +3168,9 @@ var RowModelImpl = class {
|
|
|
3158
3168
|
get tree() {
|
|
3159
3169
|
return this._tree;
|
|
3160
3170
|
}
|
|
3171
|
+
get root() {
|
|
3172
|
+
return this._tree.root;
|
|
3173
|
+
}
|
|
3161
3174
|
get index() {
|
|
3162
3175
|
if (!this._tableModel) {
|
|
3163
3176
|
return UNSET_INDEX;
|
|
@@ -3217,6 +3230,11 @@ var RowModelImpl = class {
|
|
|
3217
3230
|
revert() {
|
|
3218
3231
|
this._tree.revert();
|
|
3219
3232
|
}
|
|
3233
|
+
reset(data) {
|
|
3234
|
+
const value = data ?? generateDefaultValue(this._schema, { refSchemas: this._refSchemas });
|
|
3235
|
+
this._tree.setValue("", value);
|
|
3236
|
+
this._tree.commit();
|
|
3237
|
+
}
|
|
3220
3238
|
dispose() {
|
|
3221
3239
|
this._tree.dispose();
|
|
3222
3240
|
}
|
|
@@ -3234,7 +3252,7 @@ function createRowModel(options) {
|
|
|
3234
3252
|
const valueTree = new ValueTree(rootNode);
|
|
3235
3253
|
const formulaEngine = new FormulaEngine(valueTree);
|
|
3236
3254
|
valueTree.setFormulaEngine(formulaEngine);
|
|
3237
|
-
return new RowModelImpl(options.rowId, valueTree);
|
|
3255
|
+
return new RowModelImpl(options.rowId, valueTree, options.schema, options.refSchemas);
|
|
3238
3256
|
}
|
|
3239
3257
|
|
|
3240
3258
|
// src/model/table/TableModelImpl.ts
|