@verdant-web/common 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/EventSubscriber.d.ts +17 -0
- package/dist/cjs/EventSubscriber.js +67 -0
- package/dist/cjs/EventSubscriber.js.map +1 -0
- package/dist/cjs/baseline.d.ts +5 -0
- package/dist/cjs/baseline.js +3 -0
- package/dist/cjs/baseline.js.map +1 -0
- package/dist/cjs/batching.d.ts +41 -0
- package/dist/cjs/batching.js +89 -0
- package/dist/cjs/batching.js.map +1 -0
- package/dist/cjs/files.d.ts +19 -0
- package/dist/cjs/files.js +19 -0
- package/dist/cjs/files.js.map +1 -0
- package/dist/cjs/files.test.d.ts +1 -0
- package/dist/cjs/files.test.js +81 -0
- package/dist/cjs/files.test.js.map +1 -0
- package/dist/cjs/index.d.ts +18 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/indexes.d.ts +14 -0
- package/dist/cjs/indexes.js +116 -0
- package/dist/cjs/indexes.js.map +1 -0
- package/dist/cjs/indexes.test.d.ts +1 -0
- package/dist/cjs/indexes.test.js +128 -0
- package/dist/cjs/indexes.test.js.map +1 -0
- package/dist/cjs/migration.d.ts +98 -0
- package/dist/cjs/migration.js +128 -0
- package/dist/cjs/migration.js.map +1 -0
- package/dist/cjs/oids.d.ts +87 -0
- package/dist/cjs/oids.js +375 -0
- package/dist/cjs/oids.js.map +1 -0
- package/dist/cjs/oids.test.d.ts +1 -0
- package/dist/cjs/oids.test.js +282 -0
- package/dist/cjs/oids.test.js.map +1 -0
- package/dist/cjs/operation.d.ts +139 -0
- package/dist/cjs/operation.js +533 -0
- package/dist/cjs/operation.js.map +1 -0
- package/dist/cjs/operation.test.d.ts +1 -0
- package/dist/cjs/operation.test.js +827 -0
- package/dist/cjs/operation.test.js.map +1 -0
- package/dist/cjs/patch.d.ts +26 -0
- package/dist/cjs/patch.js +227 -0
- package/dist/cjs/patch.js.map +1 -0
- package/dist/cjs/presence.d.ts +27 -0
- package/dist/cjs/presence.js +3 -0
- package/dist/cjs/presence.js.map +1 -0
- package/dist/cjs/protocol.d.ts +145 -0
- package/dist/cjs/protocol.js +4 -0
- package/dist/cjs/protocol.js.map +1 -0
- package/dist/cjs/refs.d.ts +5 -0
- package/dist/cjs/refs.js +22 -0
- package/dist/cjs/refs.js.map +1 -0
- package/dist/cjs/replica.d.ts +28 -0
- package/dist/cjs/replica.js +29 -0
- package/dist/cjs/replica.js.map +1 -0
- package/dist/cjs/schema/defaults.d.ts +4 -0
- package/dist/cjs/schema/defaults.js +72 -0
- package/dist/cjs/schema/defaults.js.map +1 -0
- package/dist/cjs/schema/defaults.test.d.ts +1 -0
- package/dist/cjs/schema/defaults.test.js +21 -0
- package/dist/cjs/schema/defaults.test.js.map +1 -0
- package/dist/cjs/schema/index.d.ts +8 -0
- package/dist/cjs/schema/index.js +29 -0
- package/dist/cjs/schema/index.js.map +1 -0
- package/dist/cjs/schema/indexFilters.d.ts +6 -0
- package/dist/cjs/schema/indexFilters.js +31 -0
- package/dist/cjs/schema/indexFilters.js.map +1 -0
- package/dist/cjs/schema/types/collection.d.ts +51 -0
- package/dist/cjs/schema/types/collection.js +3 -0
- package/dist/cjs/schema/types/collection.js.map +1 -0
- package/dist/cjs/schema/types/compounds.d.ts +12 -0
- package/dist/cjs/schema/types/compounds.js +3 -0
- package/dist/cjs/schema/types/compounds.js.map +1 -0
- package/dist/cjs/schema/types/fields.d.ts +59 -0
- package/dist/cjs/schema/types/fields.js +3 -0
- package/dist/cjs/schema/types/fields.js.map +1 -0
- package/dist/cjs/schema/types/filters.d.ts +29 -0
- package/dist/cjs/schema/types/filters.js +3 -0
- package/dist/cjs/schema/types/filters.js.map +1 -0
- package/dist/cjs/schema/types/shapes.d.ts +21 -0
- package/dist/cjs/schema/types/shapes.js +3 -0
- package/dist/cjs/schema/types/shapes.js.map +1 -0
- package/dist/cjs/schema/types/synthetics.d.ts +28 -0
- package/dist/cjs/schema/types/synthetics.js +3 -0
- package/dist/cjs/schema/types/synthetics.js.map +1 -0
- package/dist/cjs/schema/types.d.ts +18 -0
- package/dist/cjs/schema/types.js +23 -0
- package/dist/cjs/schema/types.js.map +1 -0
- package/dist/cjs/timestamp.d.ts +48 -0
- package/dist/cjs/timestamp.js +244 -0
- package/dist/cjs/timestamp.js.map +1 -0
- package/dist/cjs/timestamp.test.d.ts +1 -0
- package/dist/cjs/timestamp.test.js +94 -0
- package/dist/cjs/timestamp.test.js.map +1 -0
- package/dist/cjs/undo.d.ts +3 -0
- package/dist/cjs/undo.js +199 -0
- package/dist/cjs/undo.js.map +1 -0
- package/dist/cjs/utils.d.ts +15 -0
- package/dist/cjs/utils.js +128 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/cjs/utils.test.d.ts +1 -0
- package/dist/cjs/utils.test.js +37 -0
- package/dist/cjs/utils.test.js.map +1 -0
- package/dist/esm/EventSubscriber.d.ts +17 -0
- package/dist/esm/EventSubscriber.js +63 -0
- package/dist/esm/EventSubscriber.js.map +1 -0
- package/dist/esm/baseline.d.ts +5 -0
- package/dist/esm/baseline.js +2 -0
- package/dist/esm/baseline.js.map +1 -0
- package/dist/esm/batching.d.ts +41 -0
- package/dist/esm/batching.js +84 -0
- package/dist/esm/batching.js.map +1 -0
- package/dist/esm/files.d.ts +19 -0
- package/dist/esm/files.js +13 -0
- package/dist/esm/files.js.map +1 -0
- package/dist/esm/files.test.d.ts +1 -0
- package/dist/esm/files.test.js +79 -0
- package/dist/esm/files.test.js.map +1 -0
- package/dist/esm/index.d.ts +18 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/indexes.d.ts +14 -0
- package/dist/esm/indexes.js +106 -0
- package/dist/esm/indexes.js.map +1 -0
- package/dist/esm/indexes.test.d.ts +1 -0
- package/dist/esm/indexes.test.js +126 -0
- package/dist/esm/indexes.test.js.map +1 -0
- package/dist/esm/migration.d.ts +98 -0
- package/dist/esm/migration.js +122 -0
- package/dist/esm/migration.js.map +1 -0
- package/dist/esm/oids.d.ts +87 -0
- package/dist/esm/oids.js +348 -0
- package/dist/esm/oids.js.map +1 -0
- package/dist/esm/oids.test.d.ts +1 -0
- package/dist/esm/oids.test.js +280 -0
- package/dist/esm/oids.test.js.map +1 -0
- package/dist/esm/operation.d.ts +139 -0
- package/dist/esm/operation.js +518 -0
- package/dist/esm/operation.js.map +1 -0
- package/dist/esm/operation.test.d.ts +1 -0
- package/dist/esm/operation.test.js +825 -0
- package/dist/esm/operation.test.js.map +1 -0
- package/dist/esm/patch.d.ts +26 -0
- package/dist/esm/patch.js +223 -0
- package/dist/esm/patch.js.map +1 -0
- package/dist/esm/presence.d.ts +27 -0
- package/dist/esm/presence.js +2 -0
- package/dist/esm/presence.js.map +1 -0
- package/dist/esm/protocol.d.ts +145 -0
- package/dist/esm/protocol.js +3 -0
- package/dist/esm/protocol.js.map +1 -0
- package/dist/esm/refs.d.ts +5 -0
- package/dist/esm/refs.js +17 -0
- package/dist/esm/refs.js.map +1 -0
- package/dist/esm/replica.d.ts +28 -0
- package/dist/esm/replica.js +26 -0
- package/dist/esm/replica.js.map +1 -0
- package/dist/esm/schema/defaults.d.ts +4 -0
- package/dist/esm/schema/defaults.js +66 -0
- package/dist/esm/schema/defaults.js.map +1 -0
- package/dist/esm/schema/defaults.test.d.ts +1 -0
- package/dist/esm/schema/defaults.test.js +19 -0
- package/dist/esm/schema/defaults.test.js.map +1 -0
- package/dist/esm/schema/index.d.ts +8 -0
- package/dist/esm/schema/index.js +10 -0
- package/dist/esm/schema/index.js.map +1 -0
- package/dist/esm/schema/indexFilters.d.ts +6 -0
- package/dist/esm/schema/indexFilters.js +23 -0
- package/dist/esm/schema/indexFilters.js.map +1 -0
- package/dist/esm/schema/types/collection.d.ts +51 -0
- package/dist/esm/schema/types/collection.js +2 -0
- package/dist/esm/schema/types/collection.js.map +1 -0
- package/dist/esm/schema/types/compounds.d.ts +12 -0
- package/dist/esm/schema/types/compounds.js +2 -0
- package/dist/esm/schema/types/compounds.js.map +1 -0
- package/dist/esm/schema/types/fields.d.ts +59 -0
- package/dist/esm/schema/types/fields.js +2 -0
- package/dist/esm/schema/types/fields.js.map +1 -0
- package/dist/esm/schema/types/filters.d.ts +29 -0
- package/dist/esm/schema/types/filters.js +2 -0
- package/dist/esm/schema/types/filters.js.map +1 -0
- package/dist/esm/schema/types/shapes.d.ts +21 -0
- package/dist/esm/schema/types/shapes.js +2 -0
- package/dist/esm/schema/types/shapes.js.map +1 -0
- package/dist/esm/schema/types/synthetics.d.ts +28 -0
- package/dist/esm/schema/types/synthetics.js +2 -0
- package/dist/esm/schema/types/synthetics.js.map +1 -0
- package/dist/esm/schema/types.d.ts +18 -0
- package/dist/esm/schema/types.js +7 -0
- package/dist/esm/schema/types.js.map +1 -0
- package/dist/esm/timestamp.d.ts +48 -0
- package/dist/esm/timestamp.js +229 -0
- package/dist/esm/timestamp.js.map +1 -0
- package/dist/esm/timestamp.test.d.ts +1 -0
- package/dist/esm/timestamp.test.js +92 -0
- package/dist/esm/timestamp.test.js.map +1 -0
- package/dist/esm/undo.d.ts +3 -0
- package/dist/esm/undo.js +195 -0
- package/dist/esm/undo.js.map +1 -0
- package/dist/esm/utils.d.ts +15 -0
- package/dist/esm/utils.js +114 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/utils.test.d.ts +1 -0
- package/dist/esm/utils.test.js +35 -0
- package/dist/esm/utils.test.js.map +1 -0
- package/dist/tsconfig-cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +38 -0
- package/src/EventSubscriber.ts +81 -0
- package/src/baseline.ts +9 -0
- package/src/batching.ts +135 -0
- package/src/files.ts +34 -0
- package/src/index.ts +26 -0
- package/src/indexes.test.ts +158 -0
- package/src/indexes.ts +151 -0
- package/src/migration.ts +391 -0
- package/src/oids.test.ts +395 -0
- package/src/oids.ts +442 -0
- package/src/operation.test.ts +966 -0
- package/src/operation.ts +755 -0
- package/src/patch.ts +277 -0
- package/src/presence.ts +29 -0
- package/src/protocol.ts +184 -0
- package/src/refs.ts +16 -0
- package/src/replica.ts +29 -0
- package/src/schema/defaults.test.ts +19 -0
- package/src/schema/defaults.ts +72 -0
- package/src/schema/index.ts +28 -0
- package/src/schema/indexFilters.ts +49 -0
- package/src/schema/types/collection.ts +133 -0
- package/src/schema/types/compounds.ts +33 -0
- package/src/schema/types/fields.ts +85 -0
- package/src/schema/types/filters.ts +39 -0
- package/src/schema/types/shapes.ts +83 -0
- package/src/schema/types/synthetics.ts +45 -0
- package/src/schema/types.ts +28 -0
- package/src/timestamp.test.ts +113 -0
- package/src/timestamp.ts +284 -0
- package/src/undo.ts +205 -0
- package/src/utils.test.ts +38 -0
- package/src/utils.ts +137 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const indexes_js_1 = require("./indexes.js");
|
|
5
|
+
(0, vitest_1.describe)('compound indexes', () => {
|
|
6
|
+
(0, vitest_1.it)('can be created from two string values', () => {
|
|
7
|
+
(0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)('a', 'b')).toEqual(`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b`);
|
|
8
|
+
});
|
|
9
|
+
(0, vitest_1.it)('can be created from two number values', () => {
|
|
10
|
+
(0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)(1, 2)).toEqual(`1${indexes_js_1.COMPOUND_INDEX_SEPARATOR}2`);
|
|
11
|
+
});
|
|
12
|
+
(0, vitest_1.it)('can be created from an array and string value', () => {
|
|
13
|
+
(0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)(['a', 'b'], 'c')).toEqual([
|
|
14
|
+
`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}c`,
|
|
15
|
+
`b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}c`,
|
|
16
|
+
]);
|
|
17
|
+
});
|
|
18
|
+
(0, vitest_1.it)('can be created from a string and array of numbers', () => {
|
|
19
|
+
(0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)('a', [1, 2])).toEqual([
|
|
20
|
+
`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}1`,
|
|
21
|
+
`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}2`,
|
|
22
|
+
]);
|
|
23
|
+
});
|
|
24
|
+
(0, vitest_1.it)('can be created from an array of strings and an array of booleans', () => {
|
|
25
|
+
(0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)(['a', 'b'], [true, false])).toEqual([
|
|
26
|
+
`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}true`,
|
|
27
|
+
`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}false`,
|
|
28
|
+
`b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}true`,
|
|
29
|
+
`b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}false`,
|
|
30
|
+
]);
|
|
31
|
+
});
|
|
32
|
+
(0, vitest_1.it)('remove duplicate array compound index values', () => {
|
|
33
|
+
(0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)(['a', 'b', 'b'], [true, false, true])).toEqual([
|
|
34
|
+
`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}true`,
|
|
35
|
+
`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}false`,
|
|
36
|
+
`b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}true`,
|
|
37
|
+
`b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}false`,
|
|
38
|
+
]);
|
|
39
|
+
});
|
|
40
|
+
(0, vitest_1.it)('creates lower bound value for multi-value indexes', () => {
|
|
41
|
+
(0, vitest_1.expect)((0, indexes_js_1.createLowerBoundIndexValue)('a', 'b')).toEqual(`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}${indexes_js_1.COMPOUND_INDEX_LOWER_BOUND_SEPARATOR}`);
|
|
42
|
+
});
|
|
43
|
+
(0, vitest_1.it)('creates upper bound value for multi-value indexes', () => {
|
|
44
|
+
(0, vitest_1.expect)((0, indexes_js_1.createUpperBoundIndexValue)('a', 'b')).toEqual(`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b${indexes_js_1.COMPOUND_INDEX_UPPER_BOUND_SEPARATOR}`);
|
|
45
|
+
}),
|
|
46
|
+
(0, vitest_1.it)('will always be grouped by the first item', () => {
|
|
47
|
+
(0, vitest_1.expect)([
|
|
48
|
+
(0, indexes_js_1.createCompoundIndexValue)('aaaaaa', 'b'),
|
|
49
|
+
(0, indexes_js_1.createCompoundIndexValue)('aaaaaa', 'c'),
|
|
50
|
+
(0, indexes_js_1.createCompoundIndexValue)('aaaaaa', 'd'),
|
|
51
|
+
(0, indexes_js_1.createCompoundIndexValue)('aaaaaa', 'e'),
|
|
52
|
+
// extra nefarious!
|
|
53
|
+
(0, indexes_js_1.createCompoundIndexValue)('aaaaaaa', 'no!'),
|
|
54
|
+
(0, indexes_js_1.createCompoundIndexValue)('aaaaaa ', 'no!'),
|
|
55
|
+
(0, indexes_js_1.createCompoundIndexValue)(`aaaaaa😎`, 'no!'),
|
|
56
|
+
(0, indexes_js_1.createCompoundIndexValue)(`aaaaaa😎😎`, 'no!'),
|
|
57
|
+
(0, indexes_js_1.createCompoundIndexValue)('aaa', 'no!'),
|
|
58
|
+
(0, indexes_js_1.createCompoundIndexValue)(`aaaaaaa😎no!`, 'no!'),
|
|
59
|
+
].sort()).toEqual([
|
|
60
|
+
`aaaaaa ${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
|
|
61
|
+
`aaaaaaa😎no!${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
|
|
62
|
+
`aaaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
|
|
63
|
+
`aaaaaa😎😎${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
|
|
64
|
+
`aaaaaa😎${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
|
|
65
|
+
// this is the contiguous block of relevant values
|
|
66
|
+
`aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b`,
|
|
67
|
+
`aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}c`,
|
|
68
|
+
`aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}d`,
|
|
69
|
+
`aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}e`,
|
|
70
|
+
// here ends the block
|
|
71
|
+
`aaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
|
|
72
|
+
]);
|
|
73
|
+
});
|
|
74
|
+
(0, vitest_1.it)('will be bounded by upper and lower bound values', () => {
|
|
75
|
+
const match = 'aaaaaa';
|
|
76
|
+
const sorted = [
|
|
77
|
+
(0, indexes_js_1.createCompoundIndexValue)(match, 'b'),
|
|
78
|
+
(0, indexes_js_1.createCompoundIndexValue)(match, 'c'),
|
|
79
|
+
(0, indexes_js_1.createCompoundIndexValue)(match, 'd'),
|
|
80
|
+
(0, indexes_js_1.createCompoundIndexValue)(match, 'e'),
|
|
81
|
+
// extra nefarious!
|
|
82
|
+
(0, indexes_js_1.createCompoundIndexValue)(`${match}a`, 'no!'),
|
|
83
|
+
(0, indexes_js_1.createCompoundIndexValue)(`${match} `, 'no!'),
|
|
84
|
+
(0, indexes_js_1.createCompoundIndexValue)(`${match}😎`, 'no!'),
|
|
85
|
+
(0, indexes_js_1.createCompoundIndexValue)(`${match}😎😎`, 'no!'),
|
|
86
|
+
(0, indexes_js_1.createCompoundIndexValue)('aaa', 'no!'),
|
|
87
|
+
(0, indexes_js_1.createCompoundIndexValue)(`${match}a😎no!`, 'no!'),
|
|
88
|
+
].sort();
|
|
89
|
+
const boundedBlock = sorted.filter((value) => value > (0, indexes_js_1.createLowerBoundIndexValue)(match) &&
|
|
90
|
+
value < (0, indexes_js_1.createUpperBoundIndexValue)(match));
|
|
91
|
+
(0, vitest_1.expect)(boundedBlock).toEqual([
|
|
92
|
+
`aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b`,
|
|
93
|
+
`aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}c`,
|
|
94
|
+
`aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}d`,
|
|
95
|
+
`aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}e`,
|
|
96
|
+
]);
|
|
97
|
+
});
|
|
98
|
+
(0, vitest_1.it)('will be bounded by upper and lower bounds when matching multiple sections', () => {
|
|
99
|
+
const match1 = 'aaaaaa';
|
|
100
|
+
const match2 = 'bbbbbb';
|
|
101
|
+
const sorted = [
|
|
102
|
+
(0, indexes_js_1.createCompoundIndexValue)(match1, match2, 'b'),
|
|
103
|
+
(0, indexes_js_1.createCompoundIndexValue)(match1, match2, 'c'),
|
|
104
|
+
(0, indexes_js_1.createCompoundIndexValue)(match1, match2, 'd'),
|
|
105
|
+
(0, indexes_js_1.createCompoundIndexValue)(match1, match2, 'e'),
|
|
106
|
+
// extra nefarious!
|
|
107
|
+
(0, indexes_js_1.createCompoundIndexValue)(`${match1}a`, match2, 'no!'),
|
|
108
|
+
(0, indexes_js_1.createCompoundIndexValue)(`${match1} `, match2, 'no!'),
|
|
109
|
+
(0, indexes_js_1.createCompoundIndexValue)(`${match1}😎`, match2, 'no!'),
|
|
110
|
+
(0, indexes_js_1.createCompoundIndexValue)(`${match1}😎😎`, match2, 'no!'),
|
|
111
|
+
(0, indexes_js_1.createCompoundIndexValue)('aaa', match2, 'no!'),
|
|
112
|
+
(0, indexes_js_1.createCompoundIndexValue)(`${match1}a😎no!`, match2, 'no!'),
|
|
113
|
+
(0, indexes_js_1.createCompoundIndexValue)(match1, `${match2}a😎no!`, 'no!'),
|
|
114
|
+
(0, indexes_js_1.createCompoundIndexValue)(match1, `${match2} `, 'no!'),
|
|
115
|
+
(0, indexes_js_1.createCompoundIndexValue)(match1, ' ', 'no!'),
|
|
116
|
+
(0, indexes_js_1.createCompoundIndexValue)(match1, '\u00001', 'no!'),
|
|
117
|
+
(0, indexes_js_1.createCompoundIndexValue)(match1, '\uE007f', 'no!'),
|
|
118
|
+
].sort();
|
|
119
|
+
(0, vitest_1.expect)(sorted.filter((value) => value > (0, indexes_js_1.createLowerBoundIndexValue)(match1, match2) &&
|
|
120
|
+
value < (0, indexes_js_1.createUpperBoundIndexValue)(match1, match2))).toEqual([
|
|
121
|
+
`aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}bbbbbb${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b`,
|
|
122
|
+
`aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}bbbbbb${indexes_js_1.COMPOUND_INDEX_SEPARATOR}c`,
|
|
123
|
+
`aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}bbbbbb${indexes_js_1.COMPOUND_INDEX_SEPARATOR}d`,
|
|
124
|
+
`aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}bbbbbb${indexes_js_1.COMPOUND_INDEX_SEPARATOR}e`,
|
|
125
|
+
]);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
//# sourceMappingURL=indexes.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.test.js","sourceRoot":"","sources":["../../src/indexes.test.ts"],"names":[],"mappings":";;AAAA,mCAA8C;AAC9C,6CAOsB;AAEtB,IAAA,iBAAQ,EAAC,kBAAkB,EAAE,GAAG,EAAE;IACjC,IAAA,WAAE,EAAC,uCAAuC,EAAE,GAAG,EAAE;QAChD,IAAA,eAAM,EAAC,IAAA,qCAAwB,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CACjD,IAAI,qCAAwB,GAAG,CAC/B,CAAC;IACH,CAAC,CAAC,C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C;YAC1D,IAAA,qCAAwB,EAAC,MAAM,EAAE,GAAG,MAAM,GAAG,EAAE,KAAK,CAAC;YACrD,IAAA,qCAAwB,EAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC;YAC5C,IAAA,qCAAwB,EAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC;YAClD,IAAA,qCAAwB,EAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC;SAClD,CAAC,IAAI,EAAE,CAAC;QACT,IAAA,eAAM,EACL,MAAM,CAAC,MAAM,CACZ,CAAC,KAAK,EAAE,EAAE,CACT,KAAK,GAAG,IAAA,uCAA0B,EAAC,MAAM,EAAE,MAAM,CAAC;YAClD,KAAK,GAAG,IAAA,uCAA0B,EAAC,MAAM,EAAE,MAAM,CAAC,CACnD,CACD,CAAC,OAAO,CAAC;YACT,SAAS,qCAAwB,SAAS,qCAAwB,GAAG;YACrE,SAAS,qCAAwB,SAAS,qCAAwB,GAAG;YACrE,SAAS,qCAAwB,SAAS,qCAAwB,GAAG;YACrE,SAAS,qCAAwB,SAAS,qCAAwB,GAAG;SACrE,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { StorageCollectionSchema, StorageSchema, StorageDocument, CollectionFilter, StorageDocumentInit } from './index.js';
|
|
2
|
+
export interface DroppedCollectionMigrationStrategy<Old extends StorageCollectionSchema<any, any, any>> {
|
|
3
|
+
(old: Old): void | Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
export interface PreservedCollectionMigrationStrategy<Old extends StorageCollectionSchema<any, any, any>, New extends StorageCollectionSchema<any, any, any>> {
|
|
6
|
+
(old: StorageDocument<Old>): StorageDocument<New> | Promise<StorageDocument<New>>;
|
|
7
|
+
}
|
|
8
|
+
declare type MigrationStrategy<Old extends StorageCollectionSchema<any, any, any>, New extends StorageCollectionSchema<any, any, any>> = DroppedCollectionMigrationStrategy<Old> | PreservedCollectionMigrationStrategy<Old, New>;
|
|
9
|
+
export declare type MigrationsKeyedOnCollection<Old extends StorageSchema<any>, New extends StorageSchema<any>> = PreservedCollectionMigrations<Old, New> | DroppedCollectionMigrations<Old, New>;
|
|
10
|
+
declare type NotInSchema<Name extends string | number | symbol, Schema extends StorageSchema<any>> = Name extends keyof Schema['collections'] ? never : Name;
|
|
11
|
+
declare type InSchema<Name extends string | number | symbol, Schema extends StorageSchema<any>> = Name extends keyof Schema['collections'] ? Name : never;
|
|
12
|
+
declare type DroppedCollections<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
|
|
13
|
+
[Key in keyof Old['collections'] as NotInSchema<Key, New>]: StorageCollectionSchema<any, any, any>;
|
|
14
|
+
};
|
|
15
|
+
declare type PreservedCollections<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
|
|
16
|
+
[Key in keyof Old['collections'] as InSchema<Key, New>]: StorageCollectionSchema<any, any, any>;
|
|
17
|
+
};
|
|
18
|
+
declare type DroppedCollectionMigrations<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
|
|
19
|
+
[Key in keyof DroppedCollections<Old, New>]: DroppedCollectionMigrationStrategy<Old['collections'][Key]>;
|
|
20
|
+
};
|
|
21
|
+
declare type PreservedCollectionMigrations<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
|
|
22
|
+
[Key in keyof PreservedCollections<Old, New>]: PreservedCollectionMigrationStrategy<Old['collections'][Key], New['collections'][Key]>;
|
|
23
|
+
};
|
|
24
|
+
declare type StrategyFor<Key extends string, Old extends StorageSchema<any>, New extends StorageSchema<any>> = Key extends keyof New['collections'] ? PreservedCollectionMigrationStrategy<Old['collections'][Key], New['collections'][Key]> : DroppedCollectionMigrationStrategy<Old['collections'][Key]>;
|
|
25
|
+
declare type MigrationRunner<Old extends StorageSchema<any>, New extends StorageSchema<any>> = <Collection extends Extract<keyof Old['collections'], string>>(collection: Collection, strategy: StrategyFor<Collection, Old, New>) => Promise<void>;
|
|
26
|
+
declare type MigrationQueryMaker<Collection extends StorageCollectionSchema<any, any, any>> = {
|
|
27
|
+
get(primaryKey: string): Promise<StorageDocument<Collection> | undefined>;
|
|
28
|
+
findOne(query: CollectionFilter): Promise<StorageDocument<Collection> | undefined>;
|
|
29
|
+
findAll(query?: CollectionFilter): Promise<StorageDocument<Collection>[]>;
|
|
30
|
+
};
|
|
31
|
+
declare type MigrationQueries<Old extends StorageSchema<any>> = {
|
|
32
|
+
[Key in keyof Old['collections']]: MigrationQueryMaker<Old['collections'][Key]>;
|
|
33
|
+
};
|
|
34
|
+
declare type MigrationMutations<New extends StorageSchema> = {
|
|
35
|
+
[Key in keyof New['collections']]: {
|
|
36
|
+
put(document: StorageDocumentInit<New['collections'][Key]>): Promise<StorageDocument<New['collections'][Key]>>;
|
|
37
|
+
delete(primaryKey: string): Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export interface MigrationTools<Old extends StorageSchema<any>, New extends StorageSchema<any>> {
|
|
41
|
+
migrate: MigrationRunner<Old, New>;
|
|
42
|
+
identity: <T>(val: T) => T;
|
|
43
|
+
withDefaults: (collectionName: string, value: any) => any;
|
|
44
|
+
queries: MigrationQueries<Old>;
|
|
45
|
+
mutations: MigrationMutations<New>;
|
|
46
|
+
info: {
|
|
47
|
+
changedCollections: keyof Old['collections'][];
|
|
48
|
+
addedCollections: keyof New['collections'][];
|
|
49
|
+
removedCollections: keyof Old['collections'][];
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export interface MigrationEngine<Old extends StorageSchema, New extends StorageSchema> {
|
|
53
|
+
migrate: (collection: string, strategy: MigrationStrategy<any, any>) => Promise<void>;
|
|
54
|
+
queries: MigrationQueries<Old>;
|
|
55
|
+
mutations: MigrationMutations<New>;
|
|
56
|
+
/** OIDs of any new documents created during the migration */
|
|
57
|
+
newOids: string[];
|
|
58
|
+
/** Promises that should be resolved before completing the migration */
|
|
59
|
+
awaitables: Promise<any>[];
|
|
60
|
+
}
|
|
61
|
+
declare type MigrationProcedure<Old extends StorageSchema, New extends StorageSchema> = (tools: MigrationTools<Old, New>) => Promise<void>;
|
|
62
|
+
declare type EmptySchema = {
|
|
63
|
+
version: 0;
|
|
64
|
+
collections: {};
|
|
65
|
+
};
|
|
66
|
+
export declare function migrate<Schema extends StorageSchema>(schema: Schema, procedure: MigrationProcedure<EmptySchema, Schema>): Migration<EmptySchema, Schema>;
|
|
67
|
+
export declare function migrate<Old extends StorageSchema, New extends StorageSchema>(oldSchema: Old, newSchema: New, procedure: MigrationProcedure<Old, New>): Migration<Old, New>;
|
|
68
|
+
export interface MigrationIndexDescription {
|
|
69
|
+
name: string;
|
|
70
|
+
multiEntry: boolean;
|
|
71
|
+
synthetic: boolean;
|
|
72
|
+
compound: boolean;
|
|
73
|
+
}
|
|
74
|
+
export interface Migration<Old extends StorageSchema = any, New extends StorageSchema = any> {
|
|
75
|
+
version: number;
|
|
76
|
+
oldSchema: Old;
|
|
77
|
+
newSchema: New;
|
|
78
|
+
migrate: (engine: MigrationEngine<Old, New>) => Promise<void>;
|
|
79
|
+
/** Collections which are added in the new schema and not present in the old */
|
|
80
|
+
addedCollections: string[];
|
|
81
|
+
/** Collections which were removed from the old schema */
|
|
82
|
+
removedCollections: string[];
|
|
83
|
+
/** All collections which exist after the migration has completed - i.e. the ones in the new schema */
|
|
84
|
+
allCollections: string[];
|
|
85
|
+
/** Only the collections which were in the old schema */
|
|
86
|
+
oldCollections: string[];
|
|
87
|
+
/** Collections whose fields or indexes changed between schemas */
|
|
88
|
+
changedCollections: string[];
|
|
89
|
+
addedIndexes: Record<string, MigrationIndexDescription[]>;
|
|
90
|
+
removedIndexes: Record<string, MigrationIndexDescription[]>;
|
|
91
|
+
}
|
|
92
|
+
export declare function migrationRange(from: number, to: number): number[];
|
|
93
|
+
export declare function createDefaultMigration(schema: StorageSchema): Migration<{
|
|
94
|
+
version: 0;
|
|
95
|
+
collections: {};
|
|
96
|
+
}>;
|
|
97
|
+
export declare function createDefaultMigration<Old extends StorageSchema>(oldSchema: Old, newSchema: StorageSchema): Migration<Old>;
|
|
98
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDefaultMigration = exports.migrationRange = exports.migrate = void 0;
|
|
4
|
+
const index_js_1 = require("./index.js");
|
|
5
|
+
const emptySchema = {
|
|
6
|
+
version: 0,
|
|
7
|
+
collections: {},
|
|
8
|
+
};
|
|
9
|
+
function migrate(oldSchemaOrNewSchema, newSchemaOrProcedure, procedureIfTwoSchemas) {
|
|
10
|
+
const isProcedureSecondArgument = typeof newSchemaOrProcedure === 'function';
|
|
11
|
+
const oldSchema = isProcedureSecondArgument
|
|
12
|
+
? emptySchema
|
|
13
|
+
: oldSchemaOrNewSchema;
|
|
14
|
+
const newSchema = isProcedureSecondArgument
|
|
15
|
+
? oldSchemaOrNewSchema
|
|
16
|
+
: newSchemaOrProcedure;
|
|
17
|
+
const procedure = isProcedureSecondArgument
|
|
18
|
+
? newSchemaOrProcedure
|
|
19
|
+
: procedureIfTwoSchemas;
|
|
20
|
+
// diff to determine changed collections
|
|
21
|
+
const changedCollections = Object.keys(newSchema.collections).filter((key) => oldSchema.collections[key] &&
|
|
22
|
+
(0, index_js_1.stableStringify)(oldSchema.collections[key]) !==
|
|
23
|
+
(0, index_js_1.stableStringify)(newSchema.collections[key]));
|
|
24
|
+
const removedCollections = Object.keys(oldSchema.collections).filter((key) => !newSchema.collections[key]);
|
|
25
|
+
const addedCollections = Object.keys(newSchema.collections).filter((key) => !oldSchema.collections[key]);
|
|
26
|
+
const addedIndexes = {};
|
|
27
|
+
const removedIndexes = {};
|
|
28
|
+
for (const changed of [...changedCollections, ...addedCollections]) {
|
|
29
|
+
const oldIndexes = getIndexes(oldSchema.collections[changed]);
|
|
30
|
+
const newIndexes = getIndexes(newSchema.collections[changed]);
|
|
31
|
+
const added = newIndexes.filter((index) => !oldIndexes.find((i) => i.name === index.name));
|
|
32
|
+
const removed = oldIndexes.filter((index) => !newIndexes.find((i) => i.name === index.name));
|
|
33
|
+
if (added.length > 0) {
|
|
34
|
+
addedIndexes[changed] = added;
|
|
35
|
+
}
|
|
36
|
+
if (removed.length > 0) {
|
|
37
|
+
removedIndexes[changed] = removed;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
version: newSchema.version,
|
|
42
|
+
migrate: async (engine) => {
|
|
43
|
+
const migratedCollections = [];
|
|
44
|
+
await procedure({
|
|
45
|
+
migrate: async (collection, strategy) => {
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
await engine.migrate(collection, strategy);
|
|
48
|
+
migratedCollections.push(collection);
|
|
49
|
+
},
|
|
50
|
+
identity: (val) => val,
|
|
51
|
+
withDefaults: (collectionName, val) => {
|
|
52
|
+
return (0, index_js_1.addFieldDefaults)(newSchema.collections[collectionName], val);
|
|
53
|
+
},
|
|
54
|
+
info: {
|
|
55
|
+
changedCollections,
|
|
56
|
+
addedCollections,
|
|
57
|
+
removedCollections,
|
|
58
|
+
},
|
|
59
|
+
queries: engine.queries,
|
|
60
|
+
mutations: engine.mutations,
|
|
61
|
+
});
|
|
62
|
+
const unmigrated = changedCollections.filter((collection) => !migratedCollections.includes(collection));
|
|
63
|
+
if (unmigrated.length > 0) {
|
|
64
|
+
console.error('Unmigrated changed collections:', unmigrated);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
removedCollections,
|
|
68
|
+
addedIndexes,
|
|
69
|
+
removedIndexes,
|
|
70
|
+
allCollections: Object.keys(newSchema.collections),
|
|
71
|
+
changedCollections,
|
|
72
|
+
addedCollections,
|
|
73
|
+
oldCollections: Object.keys(oldSchema.collections),
|
|
74
|
+
oldSchema,
|
|
75
|
+
newSchema,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
exports.migrate = migrate;
|
|
79
|
+
function migrationRange(from, to) {
|
|
80
|
+
return [...Array(to - from).keys()].map((i) => 1 + i + from);
|
|
81
|
+
}
|
|
82
|
+
exports.migrationRange = migrationRange;
|
|
83
|
+
function getIndexes(collection) {
|
|
84
|
+
if (!collection)
|
|
85
|
+
return [];
|
|
86
|
+
const fields = Object.keys(collection.fields)
|
|
87
|
+
.filter((key) => collection.fields[key].indexed)
|
|
88
|
+
.map((key) => ({
|
|
89
|
+
name: key,
|
|
90
|
+
multiEntry: collection.fields[key].type === 'array',
|
|
91
|
+
synthetic: false,
|
|
92
|
+
compound: false,
|
|
93
|
+
}));
|
|
94
|
+
return [
|
|
95
|
+
...fields,
|
|
96
|
+
...Object.keys(collection.synthetics || {}).map((key) => ({
|
|
97
|
+
name: key,
|
|
98
|
+
multiEntry: ['array', 'string[]', 'number[]', 'boolean[]'].includes(collection.synthetics[key].type),
|
|
99
|
+
synthetic: true,
|
|
100
|
+
compound: false,
|
|
101
|
+
})),
|
|
102
|
+
...Object.keys(collection.compounds || {}).map((key) => ({
|
|
103
|
+
name: key,
|
|
104
|
+
multiEntry: collection.compounds[key].of.some((fieldName) => (collection.fields[fieldName] || collection.synthetics[fieldName])
|
|
105
|
+
.type === 'array'),
|
|
106
|
+
synthetic: false,
|
|
107
|
+
compound: true,
|
|
108
|
+
})),
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
function createDefaultMigration(schema, newSchema) {
|
|
112
|
+
let oldSchema = newSchema
|
|
113
|
+
? schema
|
|
114
|
+
: {
|
|
115
|
+
version: 0,
|
|
116
|
+
collections: {},
|
|
117
|
+
};
|
|
118
|
+
return migrate(oldSchema, newSchema || schema, async ({ migrate, withDefaults, info }) => {
|
|
119
|
+
if ((newSchema || schema).version === 1)
|
|
120
|
+
return;
|
|
121
|
+
for (const collection of info.changedCollections) {
|
|
122
|
+
// @ts-ignore indefinite type resolution
|
|
123
|
+
await migrate(collection, (old) => withDefaults(collection, old));
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
exports.createDefaultMigration = createDefaultMigration;
|
|
128
|
+
//# sourceMappingURL=migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.js","sourceRoot":"","sources":["../../src/migration.ts"],"names":[],"mappings":";;;AAAA,yCAQoB;AAgLpB,MAAM,WAAW,GAAgB;IAChC,OAAO,EAAE,CAAC;IACV,WAAW,EAAE,EAAE;CACf,CAAC;AAWF,SAAgB,OAAO,CACtB,oBAAyB,EACzB,oBAAyB,EACzB,qBAA2B;IAE3B,MAAM,yBAAyB,GAAG,OAAO,oBAAoB,KAAK,UAAU,CAAC;IAC7E,MAAM,SAAS,GAAG,yBAAyB;QAC1C,CAAC,CAAC,WAAW;QACb,CAAC,CAAC,oBAAoB,CAAC;IACxB,MAAM,SAAS,GAAG,yBAAyB;QAC1C,CAAC,CAAC,oBAAoB;QACtB,CAAC,CAAC,oBAAoB,CAAC;IACxB,MAAM,SAAS,GAAG,yBAAyB;QAC1C,CAAC,CAAC,oBAAoB;QACtB,CAAC,CAAC,qBAAqB,CAAC;IACzB,wCAAwC;IACxC,MAAM,kBAAkB,GAAa,MAAM,CAAC,IAAI,CAC/C,SAAS,CAAC,WAAW,CACrB,CAAC,MAAM,CACP,CAAC,GAAG,EAAE,EAAE,CACP,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC;QAC1B,IAAA,0BAAe,EAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;YAC1C,IAAA,0BAAe,EAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAC7C,CAAC;IACF,MAAM,kBAAkB,GAAa,MAAM,CAAC,IAAI,CAC/C,SAAS,CAAC,WAAW,CACrB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/C,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,MAAM,CACjE,CAAC,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CAAC,SAAS,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;iBAChE,IAAI,KAAK,OAAO,CACnB;YACD,SAAS,EAAE,KAAK;YAChB,QAAQ,EAAE,IAAI;SACd,CAAC,CAAC;KACH,CAAC;AACH,CAAC;AASD,SAAgB,sBAAsB,CACrC,MAAqB,EACrB,SAA8B;IAE9B,IAAI,SAAS,GAAG,SAAS;QACxB,CAAC,CAAC,MAAM;QACR,CAAC,CAAC;YACA,OAAO,EAAE,CAAC;YACV,WAAW,EAAE,EAAE;SACd,CAAC;IACL,OAAO,OAAO,CACb,SAAS,EACT,SAAS,IAAI,MAAM,EACnB,KAAK,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE;QACzC,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,CAAC,OAAO,KAAK,CAAC;YAAE,OAAO;QAEhD,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,kBAAyB,EAAE;YACxD,wCAAwC;YACxC,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC;SAClE;IACF,CAAC,CACD,CAAC;AACH,CAAC;AAtBD,wDAsBC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ObjectRef } from './operation.js';
|
|
2
|
+
/**
|
|
3
|
+
* OIDs
|
|
4
|
+
*
|
|
5
|
+
* OIDs are used to identify objects in the document. They also encode
|
|
6
|
+
* information about the object useful to identifying an object found
|
|
7
|
+
* on its own and associating it back to its parent.
|
|
8
|
+
*
|
|
9
|
+
* An OID is structured as such:
|
|
10
|
+
* <collection>/<root id>[/<key paths>]:<random>
|
|
11
|
+
*
|
|
12
|
+
* OIDs have a few characteristics:
|
|
13
|
+
* - They include the collection name of the parent document
|
|
14
|
+
* - They include the primary key of the parent document
|
|
15
|
+
* - They include the key path of the object within the document
|
|
16
|
+
* - They include a random sequence to identify different objects which
|
|
17
|
+
* exist at the same key path
|
|
18
|
+
*
|
|
19
|
+
* Collection name and document key are used to link any isolated
|
|
20
|
+
* object back to its parent document.
|
|
21
|
+
*
|
|
22
|
+
* The key path is used for authorization - to associate the object
|
|
23
|
+
* (or an operation related to it by OID) with the field it inhabits
|
|
24
|
+
* to utilize authorization rules from that field in the schema.
|
|
25
|
+
*
|
|
26
|
+
* The random sequence allows the application to encode different
|
|
27
|
+
* identities for objects at the same position in a document for
|
|
28
|
+
* conflict resolution purposes
|
|
29
|
+
*/
|
|
30
|
+
export declare type ObjectIdentifier = string;
|
|
31
|
+
export declare type KeyPath = (string | number)[];
|
|
32
|
+
export declare const LEGACY_OID_KEY = "__@@oid_do_not_use";
|
|
33
|
+
export declare const OID_KEY = "@@id";
|
|
34
|
+
export declare function getOid(obj: any): string;
|
|
35
|
+
export declare function maybeGetOid(obj: any): ObjectIdentifier | undefined;
|
|
36
|
+
export declare function assignOid(obj: any, oid: ObjectIdentifier): any;
|
|
37
|
+
export declare function hasOid(obj: any): boolean;
|
|
38
|
+
export declare function removeOid(obj: any): any;
|
|
39
|
+
export declare function isOidKey(key: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* For sub-objects, assign a random sub-OID if no OID
|
|
42
|
+
* is already assigned.
|
|
43
|
+
*/
|
|
44
|
+
export declare function ensureOid(obj: any, rootOid: ObjectIdentifier, key: string | number, createSubId?: () => string): string;
|
|
45
|
+
export declare function createOid(collection: string, documentId: string, keyPath?: KeyPath, subId?: string): string;
|
|
46
|
+
export declare function createSubOid(root: ObjectIdentifier, key: string | number, createSubId?: () => string): string;
|
|
47
|
+
export declare function decomposeOid(oid: ObjectIdentifier): {
|
|
48
|
+
collection: string;
|
|
49
|
+
id: string;
|
|
50
|
+
subId?: string;
|
|
51
|
+
keyPath: KeyPath;
|
|
52
|
+
};
|
|
53
|
+
export declare function assertAllLevelsHaveOids(obj: any, root?: any): void;
|
|
54
|
+
export declare function assignOidsToAllSubObjects(obj: any, createSubId?: () => string): void;
|
|
55
|
+
export declare function assignOidProperty(obj: any, oid: ObjectIdentifier): any;
|
|
56
|
+
export declare function maybeGetOidProperty(obj: any): any;
|
|
57
|
+
/**
|
|
58
|
+
* Assigns a special property to all objects in the given object
|
|
59
|
+
* which have an OID
|
|
60
|
+
*/
|
|
61
|
+
export declare function assignOidPropertiesToAllSubObjects(obj: any): void;
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* Removes the special property from all objects in the given object
|
|
65
|
+
* which have an OID, transferring the OID from the property to the OID
|
|
66
|
+
* system in-memory.
|
|
67
|
+
*/
|
|
68
|
+
export declare function removeOidPropertiesFromAllSubObjects(obj: any): void;
|
|
69
|
+
export declare function removeOidsFromAllSubObjects(obj: any): void;
|
|
70
|
+
export declare function createOidSubId(): string;
|
|
71
|
+
export declare function createRef(oid: ObjectIdentifier): ObjectRef;
|
|
72
|
+
export declare function normalize(obj: any, refs?: Map<ObjectIdentifier, any>): Map<ObjectIdentifier, any>;
|
|
73
|
+
/**
|
|
74
|
+
* Only normalizes direct children. The created map
|
|
75
|
+
* of objects will still have nested objects.
|
|
76
|
+
*/
|
|
77
|
+
export declare function normalizeFirstLevel(obj: any): {
|
|
78
|
+
refs: Map<string, any>;
|
|
79
|
+
oidKeyPairs: Map<string, string | number>;
|
|
80
|
+
};
|
|
81
|
+
export declare function getOidRoot(oid: ObjectIdentifier): string;
|
|
82
|
+
/**
|
|
83
|
+
* Returns an inclusive range of OIDs that represent
|
|
84
|
+
* a root object and all of its sub-objects.
|
|
85
|
+
*/
|
|
86
|
+
export declare function getOidRange(oid: ObjectIdentifier): string[];
|
|
87
|
+
export declare function getRoots(oids: ObjectIdentifier[]): string[];
|