@verdant-web/common 1.15.2 → 1.15.3-next.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/dist/cjs/EventSubscriber.d.ts +17 -17
- package/dist/cjs/EventSubscriber.js +66 -66
- package/dist/cjs/baseline.d.ts +5 -5
- package/dist/cjs/baseline.js +2 -2
- package/dist/cjs/batching.d.ts +42 -42
- package/dist/cjs/batching.js +91 -91
- package/dist/cjs/files.d.ts +19 -19
- package/dist/cjs/files.js +18 -18
- 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 +19 -18
- package/dist/cjs/index.js +41 -36
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/indexes.d.ts +17 -17
- package/dist/cjs/indexes.js +142 -142
- package/dist/cjs/indexes.test.d.ts +1 -1
- package/dist/cjs/indexes.test.js +127 -127
- package/dist/cjs/migration.d.ts +172 -172
- package/dist/cjs/migration.js +301 -301
- package/dist/cjs/oids.d.ts +100 -96
- package/dist/cjs/oids.js +457 -439
- package/dist/cjs/oids.js.map +1 -1
- package/dist/cjs/oids.test.d.ts +1 -1
- package/dist/cjs/oids.test.js +348 -272
- package/dist/cjs/oids.test.js.map +1 -1
- package/dist/cjs/operation.d.ts +139 -139
- package/dist/cjs/operation.js +545 -545
- package/dist/cjs/operation.test.d.ts +1 -1
- package/dist/cjs/operation.test.js +529 -529
- package/dist/cjs/patch.d.ts +26 -26
- package/dist/cjs/patch.js +226 -226
- package/dist/cjs/presence.d.ts +27 -27
- package/dist/cjs/presence.js +2 -2
- package/dist/cjs/protocol.d.ts +145 -145
- package/dist/cjs/protocol.js +3 -3
- package/dist/cjs/refs.d.ts +7 -5
- package/dist/cjs/refs.js +29 -21
- package/dist/cjs/refs.js.map +1 -1
- package/dist/cjs/replica.d.ts +28 -28
- package/dist/cjs/replica.js +28 -28
- 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 -1
- package/dist/cjs/schema/defaults.test.js +20 -20
- package/dist/cjs/schema/fields.d.ts +9 -9
- package/dist/cjs/schema/fields.js +144 -144
- package/dist/cjs/schema/index.d.ts +8 -8
- package/dist/cjs/schema/index.js +51 -51
- package/dist/cjs/schema/indexFilters.d.ts +6 -6
- package/dist/cjs/schema/indexFilters.js +30 -30
- package/dist/cjs/schema/types/collection.d.ts +23 -23
- package/dist/cjs/schema/types/collection.js +2 -2
- package/dist/cjs/schema/types/compounds.d.ts +11 -11
- package/dist/cjs/schema/types/compounds.js +2 -2
- package/dist/cjs/schema/types/fields.d.ts +75 -75
- package/dist/cjs/schema/types/fields.js +2 -2
- package/dist/cjs/schema/types/filters.d.ts +29 -29
- package/dist/cjs/schema/types/filters.js +2 -2
- package/dist/cjs/schema/types/shapes.d.ts +21 -21
- package/dist/cjs/schema/types/shapes.js +2 -2
- package/dist/cjs/schema/types/synthetics.d.ts +37 -37
- package/dist/cjs/schema/types/synthetics.js +2 -2
- package/dist/cjs/schema/types.d.ts +18 -18
- package/dist/cjs/schema/types.js +22 -22
- package/dist/cjs/schema/validation.d.ts +3 -3
- package/dist/cjs/schema/validation.js +86 -86
- package/dist/cjs/timestamp.d.ts +50 -50
- package/dist/cjs/timestamp.js +251 -251
- package/dist/cjs/timestamp.test.d.ts +1 -1
- package/dist/cjs/timestamp.test.js +104 -104
- package/dist/cjs/undo.d.ts +3 -3
- package/dist/cjs/undo.js +198 -198
- package/dist/cjs/utils.d.ts +20 -20
- package/dist/cjs/utils.js +145 -145
- package/dist/cjs/utils.test.d.ts +1 -1
- package/dist/cjs/utils.test.js +36 -36
- package/dist/esm/EventSubscriber.d.ts +17 -17
- package/dist/esm/EventSubscriber.js +62 -62
- package/dist/esm/baseline.d.ts +5 -5
- package/dist/esm/baseline.js +1 -1
- package/dist/esm/batching.d.ts +42 -42
- package/dist/esm/batching.js +86 -86
- package/dist/esm/files.d.ts +19 -19
- package/dist/esm/files.js +12 -12
- 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 +19 -18
- package/dist/esm/index.js +16 -15
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/indexes.d.ts +17 -17
- package/dist/esm/indexes.js +130 -130
- package/dist/esm/indexes.test.d.ts +1 -1
- package/dist/esm/indexes.test.js +125 -125
- package/dist/esm/migration.d.ts +172 -172
- package/dist/esm/migration.js +294 -294
- package/dist/esm/oids.d.ts +100 -96
- package/dist/esm/oids.js +422 -407
- package/dist/esm/oids.js.map +1 -1
- package/dist/esm/oids.test.d.ts +1 -1
- package/dist/esm/oids.test.js +346 -270
- package/dist/esm/oids.test.js.map +1 -1
- package/dist/esm/operation.d.ts +139 -139
- package/dist/esm/operation.js +530 -530
- package/dist/esm/operation.test.d.ts +1 -1
- package/dist/esm/operation.test.js +527 -527
- package/dist/esm/patch.d.ts +26 -26
- package/dist/esm/patch.js +222 -222
- package/dist/esm/presence.d.ts +27 -27
- package/dist/esm/presence.js +1 -1
- package/dist/esm/protocol.d.ts +145 -145
- package/dist/esm/protocol.js +2 -2
- package/dist/esm/refs.d.ts +7 -5
- package/dist/esm/refs.js +22 -16
- package/dist/esm/refs.js.map +1 -1
- package/dist/esm/replica.d.ts +28 -28
- package/dist/esm/replica.js +25 -25
- 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 -1
- package/dist/esm/schema/defaults.test.js +18 -18
- package/dist/esm/schema/fields.d.ts +9 -9
- package/dist/esm/schema/fields.js +133 -133
- package/dist/esm/schema/index.d.ts +8 -8
- package/dist/esm/schema/index.js +32 -32
- package/dist/esm/schema/indexFilters.d.ts +6 -6
- package/dist/esm/schema/indexFilters.js +22 -22
- package/dist/esm/schema/types/collection.d.ts +23 -23
- package/dist/esm/schema/types/collection.js +1 -1
- package/dist/esm/schema/types/compounds.d.ts +11 -11
- package/dist/esm/schema/types/compounds.js +1 -1
- package/dist/esm/schema/types/fields.d.ts +75 -75
- package/dist/esm/schema/types/fields.js +1 -1
- package/dist/esm/schema/types/filters.d.ts +29 -29
- package/dist/esm/schema/types/filters.js +1 -1
- package/dist/esm/schema/types/shapes.d.ts +21 -21
- package/dist/esm/schema/types/shapes.js +1 -1
- package/dist/esm/schema/types/synthetics.d.ts +37 -37
- package/dist/esm/schema/types/synthetics.js +1 -1
- package/dist/esm/schema/types.d.ts +18 -18
- package/dist/esm/schema/types.js +6 -6
- package/dist/esm/schema/validation.d.ts +3 -3
- package/dist/esm/schema/validation.js +81 -81
- package/dist/esm/timestamp.d.ts +50 -50
- package/dist/esm/timestamp.js +234 -234
- package/dist/esm/timestamp.test.d.ts +1 -1
- package/dist/esm/timestamp.test.js +102 -102
- package/dist/esm/undo.d.ts +3 -3
- package/dist/esm/undo.js +194 -194
- package/dist/esm/utils.d.ts +20 -20
- package/dist/esm/utils.js +127 -127
- package/dist/esm/utils.test.d.ts +1 -1
- package/dist/esm/utils.test.js +34 -34
- package/dist/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/oids.test.ts +82 -0
- package/src/oids.ts +17 -0
- package/src/refs.ts +8 -0
package/dist/esm/indexes.js
CHANGED
|
@@ -1,131 +1,131 @@
|
|
|
1
|
-
import { isIndexed, } from './index.js';
|
|
2
|
-
// unlikely to be used unicode character
|
|
3
|
-
export const COMPOUND_INDEX_SEPARATOR = '\uFFFFFE';
|
|
4
|
-
// 1 lower than separator
|
|
5
|
-
export const COMPOUND_INDEX_LOWER_BOUND_SEPARATOR = '\u0000';
|
|
6
|
-
// 1 higher than separator
|
|
7
|
-
export const COMPOUND_INDEX_UPPER_BOUND_SEPARATOR = '\uFFFFFF';
|
|
8
|
-
export function createCompoundIndexValue(...fields) {
|
|
9
|
-
const value = expandArrayIndex(fields);
|
|
10
|
-
if (value.length === 1) {
|
|
11
|
-
return value[0];
|
|
12
|
-
}
|
|
13
|
-
return value;
|
|
14
|
-
}
|
|
15
|
-
export function createUpperBoundIndexValue(...fields) {
|
|
16
|
-
return (fields.join(COMPOUND_INDEX_SEPARATOR) +
|
|
17
|
-
`${COMPOUND_INDEX_UPPER_BOUND_SEPARATOR}`);
|
|
18
|
-
}
|
|
19
|
-
export function createLowerBoundIndexValue(...fields) {
|
|
20
|
-
return (fields.join(COMPOUND_INDEX_SEPARATOR) +
|
|
21
|
-
`${COMPOUND_INDEX_SEPARATOR}${COMPOUND_INDEX_LOWER_BOUND_SEPARATOR}`);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Whenever an array value is included in a compound index, we have to expand
|
|
25
|
-
* the value to include all permutations of values in the array.
|
|
26
|
-
* For example if we had an index id + tags on a document
|
|
27
|
-
*
|
|
28
|
-
* {
|
|
29
|
-
* id: '1',
|
|
30
|
-
* tags: ['a', 'b']
|
|
31
|
-
* }
|
|
32
|
-
*
|
|
33
|
-
* we want to create an index:
|
|
34
|
-
*
|
|
35
|
-
* id_tags: ['1#a', '1#b']
|
|
36
|
-
*
|
|
37
|
-
* If multiple arrays are indexed we have to exponentially expand...
|
|
38
|
-
*
|
|
39
|
-
* id_tags_tags2: ['1#a#a', '1#a#b', '1#b#a', '1#b#b']
|
|
40
|
-
*
|
|
41
|
-
* To generalize this we construct a 2-level array of strings.
|
|
42
|
-
* Iterating over indexed values, we expand each item into N items if
|
|
43
|
-
* the current value is an array.
|
|
44
|
-
*
|
|
45
|
-
* Then we combine all nested arrays into compound index values.
|
|
46
|
-
* This will produce an array of 1 element if none of the indexed values
|
|
47
|
-
* were arrays. The caller should unwrap that.
|
|
48
|
-
*
|
|
49
|
-
* This function also deduplicates values.
|
|
50
|
-
*/
|
|
51
|
-
function expandArrayIndex(fields) {
|
|
52
|
-
let value = [[]];
|
|
53
|
-
for (const field of fields) {
|
|
54
|
-
if (Array.isArray(field)) {
|
|
55
|
-
const newValue = [];
|
|
56
|
-
for (const previousValue of value) {
|
|
57
|
-
for (const fieldValue of field) {
|
|
58
|
-
newValue.push(previousValue.concat(fieldValue));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
value = newValue;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
for (const item of value) {
|
|
65
|
-
item.push(`${field}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return Array.from(new Set(value.map((item) => {
|
|
70
|
-
return item.join(COMPOUND_INDEX_SEPARATOR);
|
|
71
|
-
})));
|
|
72
|
-
}
|
|
73
|
-
export function isDirectSynthetic(index) {
|
|
74
|
-
return !!index.field;
|
|
75
|
-
}
|
|
76
|
-
export function computeSynthetics(schema, obj) {
|
|
77
|
-
const result = {};
|
|
78
|
-
for (const [name, property] of Object.entries(schema.indexes || {})) {
|
|
79
|
-
const index = property;
|
|
80
|
-
if (isDirectSynthetic(index)) {
|
|
81
|
-
result[name] = sanitizeIndexValue(obj[index.field]);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
result[name] = sanitizeIndexValue(index.compute(obj));
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
export function computeCompoundIndices(schema, doc) {
|
|
90
|
-
return Object.entries(schema.compounds || {}).reduce((acc, [indexKey, index]) => {
|
|
91
|
-
acc[indexKey] = createCompoundIndexValue(...index.of.map((key) => doc[key]));
|
|
92
|
-
return acc;
|
|
93
|
-
}, {});
|
|
94
|
-
}
|
|
95
|
-
function computeIndexedFields(schema, doc) {
|
|
96
|
-
return Object.entries(schema.fields).reduce((acc, [key, field]) => {
|
|
97
|
-
if (isIndexed(field)) {
|
|
98
|
-
acc[key] = sanitizeIndexValue(doc[key]);
|
|
99
|
-
}
|
|
100
|
-
return acc;
|
|
101
|
-
}, {});
|
|
102
|
-
}
|
|
103
|
-
export function getIndexValues(schema, doc) {
|
|
104
|
-
return Object.assign(Object.assign(Object.assign(Object.assign({ [schema.primaryKey]: doc[schema.primaryKey] }, computeIndexedFields(schema, doc)), computeSynthetics(schema, doc)), computeCompoundIndices(schema, doc)), { '@@@snapshot': doc });
|
|
105
|
-
}
|
|
106
|
-
export function assignIndexValues(schema, doc) {
|
|
107
|
-
Object.assign(doc, computeSynthetics(schema, doc));
|
|
108
|
-
Object.assign(doc, computeCompoundIndices(schema, doc));
|
|
109
|
-
return doc;
|
|
110
|
-
}
|
|
111
|
-
export const NULL_INDEX_VALUE = 'null';
|
|
112
|
-
export function sanitizeIndexValue(value) {
|
|
113
|
-
if (value === null) {
|
|
114
|
-
return NULL_INDEX_VALUE;
|
|
115
|
-
}
|
|
116
|
-
if (typeof value === 'string' || typeof value === 'number') {
|
|
117
|
-
return value;
|
|
118
|
-
}
|
|
119
|
-
if (typeof value === 'boolean' || value === null) {
|
|
120
|
-
return `${value}`;
|
|
121
|
-
}
|
|
122
|
-
if (value === undefined) {
|
|
123
|
-
// this shouldn't happen ,but for resiliency...
|
|
124
|
-
return 'undefined';
|
|
125
|
-
}
|
|
126
|
-
if (Array.isArray(value)) {
|
|
127
|
-
return value.map(sanitizeIndexValue);
|
|
128
|
-
}
|
|
129
|
-
throw new Error(`Unsupported index value: ${value}`);
|
|
130
|
-
}
|
|
1
|
+
import { isIndexed, } from './index.js';
|
|
2
|
+
// unlikely to be used unicode character
|
|
3
|
+
export const COMPOUND_INDEX_SEPARATOR = '\uFFFFFE';
|
|
4
|
+
// 1 lower than separator
|
|
5
|
+
export const COMPOUND_INDEX_LOWER_BOUND_SEPARATOR = '\u0000';
|
|
6
|
+
// 1 higher than separator
|
|
7
|
+
export const COMPOUND_INDEX_UPPER_BOUND_SEPARATOR = '\uFFFFFF';
|
|
8
|
+
export function createCompoundIndexValue(...fields) {
|
|
9
|
+
const value = expandArrayIndex(fields);
|
|
10
|
+
if (value.length === 1) {
|
|
11
|
+
return value[0];
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
export function createUpperBoundIndexValue(...fields) {
|
|
16
|
+
return (fields.join(COMPOUND_INDEX_SEPARATOR) +
|
|
17
|
+
`${COMPOUND_INDEX_UPPER_BOUND_SEPARATOR}`);
|
|
18
|
+
}
|
|
19
|
+
export function createLowerBoundIndexValue(...fields) {
|
|
20
|
+
return (fields.join(COMPOUND_INDEX_SEPARATOR) +
|
|
21
|
+
`${COMPOUND_INDEX_SEPARATOR}${COMPOUND_INDEX_LOWER_BOUND_SEPARATOR}`);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Whenever an array value is included in a compound index, we have to expand
|
|
25
|
+
* the value to include all permutations of values in the array.
|
|
26
|
+
* For example if we had an index id + tags on a document
|
|
27
|
+
*
|
|
28
|
+
* {
|
|
29
|
+
* id: '1',
|
|
30
|
+
* tags: ['a', 'b']
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* we want to create an index:
|
|
34
|
+
*
|
|
35
|
+
* id_tags: ['1#a', '1#b']
|
|
36
|
+
*
|
|
37
|
+
* If multiple arrays are indexed we have to exponentially expand...
|
|
38
|
+
*
|
|
39
|
+
* id_tags_tags2: ['1#a#a', '1#a#b', '1#b#a', '1#b#b']
|
|
40
|
+
*
|
|
41
|
+
* To generalize this we construct a 2-level array of strings.
|
|
42
|
+
* Iterating over indexed values, we expand each item into N items if
|
|
43
|
+
* the current value is an array.
|
|
44
|
+
*
|
|
45
|
+
* Then we combine all nested arrays into compound index values.
|
|
46
|
+
* This will produce an array of 1 element if none of the indexed values
|
|
47
|
+
* were arrays. The caller should unwrap that.
|
|
48
|
+
*
|
|
49
|
+
* This function also deduplicates values.
|
|
50
|
+
*/
|
|
51
|
+
function expandArrayIndex(fields) {
|
|
52
|
+
let value = [[]];
|
|
53
|
+
for (const field of fields) {
|
|
54
|
+
if (Array.isArray(field)) {
|
|
55
|
+
const newValue = [];
|
|
56
|
+
for (const previousValue of value) {
|
|
57
|
+
for (const fieldValue of field) {
|
|
58
|
+
newValue.push(previousValue.concat(fieldValue));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
value = newValue;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
for (const item of value) {
|
|
65
|
+
item.push(`${field}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return Array.from(new Set(value.map((item) => {
|
|
70
|
+
return item.join(COMPOUND_INDEX_SEPARATOR);
|
|
71
|
+
})));
|
|
72
|
+
}
|
|
73
|
+
export function isDirectSynthetic(index) {
|
|
74
|
+
return !!index.field;
|
|
75
|
+
}
|
|
76
|
+
export function computeSynthetics(schema, obj) {
|
|
77
|
+
const result = {};
|
|
78
|
+
for (const [name, property] of Object.entries(schema.indexes || {})) {
|
|
79
|
+
const index = property;
|
|
80
|
+
if (isDirectSynthetic(index)) {
|
|
81
|
+
result[name] = sanitizeIndexValue(obj[index.field]);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
result[name] = sanitizeIndexValue(index.compute(obj));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
export function computeCompoundIndices(schema, doc) {
|
|
90
|
+
return Object.entries(schema.compounds || {}).reduce((acc, [indexKey, index]) => {
|
|
91
|
+
acc[indexKey] = createCompoundIndexValue(...index.of.map((key) => doc[key]));
|
|
92
|
+
return acc;
|
|
93
|
+
}, {});
|
|
94
|
+
}
|
|
95
|
+
function computeIndexedFields(schema, doc) {
|
|
96
|
+
return Object.entries(schema.fields).reduce((acc, [key, field]) => {
|
|
97
|
+
if (isIndexed(field)) {
|
|
98
|
+
acc[key] = sanitizeIndexValue(doc[key]);
|
|
99
|
+
}
|
|
100
|
+
return acc;
|
|
101
|
+
}, {});
|
|
102
|
+
}
|
|
103
|
+
export function getIndexValues(schema, doc) {
|
|
104
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({ [schema.primaryKey]: doc[schema.primaryKey] }, computeIndexedFields(schema, doc)), computeSynthetics(schema, doc)), computeCompoundIndices(schema, doc)), { '@@@snapshot': doc });
|
|
105
|
+
}
|
|
106
|
+
export function assignIndexValues(schema, doc) {
|
|
107
|
+
Object.assign(doc, computeSynthetics(schema, doc));
|
|
108
|
+
Object.assign(doc, computeCompoundIndices(schema, doc));
|
|
109
|
+
return doc;
|
|
110
|
+
}
|
|
111
|
+
export const NULL_INDEX_VALUE = 'null';
|
|
112
|
+
export function sanitizeIndexValue(value) {
|
|
113
|
+
if (value === null) {
|
|
114
|
+
return NULL_INDEX_VALUE;
|
|
115
|
+
}
|
|
116
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
if (typeof value === 'boolean' || value === null) {
|
|
120
|
+
return `${value}`;
|
|
121
|
+
}
|
|
122
|
+
if (value === undefined) {
|
|
123
|
+
// this shouldn't happen ,but for resiliency...
|
|
124
|
+
return 'undefined';
|
|
125
|
+
}
|
|
126
|
+
if (Array.isArray(value)) {
|
|
127
|
+
return value.map(sanitizeIndexValue);
|
|
128
|
+
}
|
|
129
|
+
throw new Error(`Unsupported index value: ${value}`);
|
|
130
|
+
}
|
|
131
131
|
//# sourceMappingURL=indexes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/dist/esm/indexes.test.js
CHANGED
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { COMPOUND_INDEX_LOWER_BOUND_SEPARATOR, COMPOUND_INDEX_SEPARATOR, COMPOUND_INDEX_UPPER_BOUND_SEPARATOR, createCompoundIndexValue, createLowerBoundIndexValue, createUpperBoundIndexValue, } from './indexes.js';
|
|
3
|
-
describe('compound indexes', () => {
|
|
4
|
-
it('can be created from two string values', () => {
|
|
5
|
-
expect(createCompoundIndexValue('a', 'b')).toEqual(`a${COMPOUND_INDEX_SEPARATOR}b`);
|
|
6
|
-
});
|
|
7
|
-
it('can be created from two number values', () => {
|
|
8
|
-
expect(createCompoundIndexValue(1, 2)).toEqual(`1${COMPOUND_INDEX_SEPARATOR}2`);
|
|
9
|
-
});
|
|
10
|
-
it('can be created from an array and string value', () => {
|
|
11
|
-
expect(createCompoundIndexValue(['a', 'b'], 'c')).toEqual([
|
|
12
|
-
`a${COMPOUND_INDEX_SEPARATOR}c`,
|
|
13
|
-
`b${COMPOUND_INDEX_SEPARATOR}c`,
|
|
14
|
-
]);
|
|
15
|
-
});
|
|
16
|
-
it('can be created from a string and array of numbers', () => {
|
|
17
|
-
expect(createCompoundIndexValue('a', [1, 2])).toEqual([
|
|
18
|
-
`a${COMPOUND_INDEX_SEPARATOR}1`,
|
|
19
|
-
`a${COMPOUND_INDEX_SEPARATOR}2`,
|
|
20
|
-
]);
|
|
21
|
-
});
|
|
22
|
-
it('can be created from an array of strings and an array of booleans', () => {
|
|
23
|
-
expect(createCompoundIndexValue(['a', 'b'], [true, false])).toEqual([
|
|
24
|
-
`a${COMPOUND_INDEX_SEPARATOR}true`,
|
|
25
|
-
`a${COMPOUND_INDEX_SEPARATOR}false`,
|
|
26
|
-
`b${COMPOUND_INDEX_SEPARATOR}true`,
|
|
27
|
-
`b${COMPOUND_INDEX_SEPARATOR}false`,
|
|
28
|
-
]);
|
|
29
|
-
});
|
|
30
|
-
it('remove duplicate array compound index values', () => {
|
|
31
|
-
expect(createCompoundIndexValue(['a', 'b', 'b'], [true, false, true])).toEqual([
|
|
32
|
-
`a${COMPOUND_INDEX_SEPARATOR}true`,
|
|
33
|
-
`a${COMPOUND_INDEX_SEPARATOR}false`,
|
|
34
|
-
`b${COMPOUND_INDEX_SEPARATOR}true`,
|
|
35
|
-
`b${COMPOUND_INDEX_SEPARATOR}false`,
|
|
36
|
-
]);
|
|
37
|
-
});
|
|
38
|
-
it('creates lower bound value for multi-value indexes', () => {
|
|
39
|
-
expect(createLowerBoundIndexValue('a', 'b')).toEqual(`a${COMPOUND_INDEX_SEPARATOR}b${COMPOUND_INDEX_SEPARATOR}${COMPOUND_INDEX_LOWER_BOUND_SEPARATOR}`);
|
|
40
|
-
});
|
|
41
|
-
it('creates upper bound value for multi-value indexes', () => {
|
|
42
|
-
expect(createUpperBoundIndexValue('a', 'b')).toEqual(`a${COMPOUND_INDEX_SEPARATOR}b${COMPOUND_INDEX_UPPER_BOUND_SEPARATOR}`);
|
|
43
|
-
}),
|
|
44
|
-
it('will always be grouped by the first item', () => {
|
|
45
|
-
expect([
|
|
46
|
-
createCompoundIndexValue('aaaaaa', 'b'),
|
|
47
|
-
createCompoundIndexValue('aaaaaa', 'c'),
|
|
48
|
-
createCompoundIndexValue('aaaaaa', 'd'),
|
|
49
|
-
createCompoundIndexValue('aaaaaa', 'e'),
|
|
50
|
-
// extra nefarious!
|
|
51
|
-
createCompoundIndexValue('aaaaaaa', 'no!'),
|
|
52
|
-
createCompoundIndexValue('aaaaaa ', 'no!'),
|
|
53
|
-
createCompoundIndexValue(`aaaaaa😎`, 'no!'),
|
|
54
|
-
createCompoundIndexValue(`aaaaaa😎😎`, 'no!'),
|
|
55
|
-
createCompoundIndexValue('aaa', 'no!'),
|
|
56
|
-
createCompoundIndexValue(`aaaaaaa😎no!`, 'no!'),
|
|
57
|
-
].sort()).toEqual([
|
|
58
|
-
`aaaaaa ${COMPOUND_INDEX_SEPARATOR}no!`,
|
|
59
|
-
`aaaaaaa😎no!${COMPOUND_INDEX_SEPARATOR}no!`,
|
|
60
|
-
`aaaaaaa${COMPOUND_INDEX_SEPARATOR}no!`,
|
|
61
|
-
`aaaaaa😎😎${COMPOUND_INDEX_SEPARATOR}no!`,
|
|
62
|
-
`aaaaaa😎${COMPOUND_INDEX_SEPARATOR}no!`,
|
|
63
|
-
// this is the contiguous block of relevant values
|
|
64
|
-
`aaaaaa${COMPOUND_INDEX_SEPARATOR}b`,
|
|
65
|
-
`aaaaaa${COMPOUND_INDEX_SEPARATOR}c`,
|
|
66
|
-
`aaaaaa${COMPOUND_INDEX_SEPARATOR}d`,
|
|
67
|
-
`aaaaaa${COMPOUND_INDEX_SEPARATOR}e`,
|
|
68
|
-
// here ends the block
|
|
69
|
-
`aaa${COMPOUND_INDEX_SEPARATOR}no!`,
|
|
70
|
-
]);
|
|
71
|
-
});
|
|
72
|
-
it('will be bounded by upper and lower bound values', () => {
|
|
73
|
-
const match = 'aaaaaa';
|
|
74
|
-
const sorted = [
|
|
75
|
-
createCompoundIndexValue(match, 'b'),
|
|
76
|
-
createCompoundIndexValue(match, 'c'),
|
|
77
|
-
createCompoundIndexValue(match, 'd'),
|
|
78
|
-
createCompoundIndexValue(match, 'e'),
|
|
79
|
-
// extra nefarious!
|
|
80
|
-
createCompoundIndexValue(`${match}a`, 'no!'),
|
|
81
|
-
createCompoundIndexValue(`${match} `, 'no!'),
|
|
82
|
-
createCompoundIndexValue(`${match}😎`, 'no!'),
|
|
83
|
-
createCompoundIndexValue(`${match}😎😎`, 'no!'),
|
|
84
|
-
createCompoundIndexValue('aaa', 'no!'),
|
|
85
|
-
createCompoundIndexValue(`${match}a😎no!`, 'no!'),
|
|
86
|
-
].sort();
|
|
87
|
-
const boundedBlock = sorted.filter((value) => value > createLowerBoundIndexValue(match) &&
|
|
88
|
-
value < createUpperBoundIndexValue(match));
|
|
89
|
-
expect(boundedBlock).toEqual([
|
|
90
|
-
`aaaaaa${COMPOUND_INDEX_SEPARATOR}b`,
|
|
91
|
-
`aaaaaa${COMPOUND_INDEX_SEPARATOR}c`,
|
|
92
|
-
`aaaaaa${COMPOUND_INDEX_SEPARATOR}d`,
|
|
93
|
-
`aaaaaa${COMPOUND_INDEX_SEPARATOR}e`,
|
|
94
|
-
]);
|
|
95
|
-
});
|
|
96
|
-
it('will be bounded by upper and lower bounds when matching multiple sections', () => {
|
|
97
|
-
const match1 = 'aaaaaa';
|
|
98
|
-
const match2 = 'bbbbbb';
|
|
99
|
-
const sorted = [
|
|
100
|
-
createCompoundIndexValue(match1, match2, 'b'),
|
|
101
|
-
createCompoundIndexValue(match1, match2, 'c'),
|
|
102
|
-
createCompoundIndexValue(match1, match2, 'd'),
|
|
103
|
-
createCompoundIndexValue(match1, match2, 'e'),
|
|
104
|
-
// extra nefarious!
|
|
105
|
-
createCompoundIndexValue(`${match1}a`, match2, 'no!'),
|
|
106
|
-
createCompoundIndexValue(`${match1} `, match2, 'no!'),
|
|
107
|
-
createCompoundIndexValue(`${match1}😎`, match2, 'no!'),
|
|
108
|
-
createCompoundIndexValue(`${match1}😎😎`, match2, 'no!'),
|
|
109
|
-
createCompoundIndexValue('aaa', match2, 'no!'),
|
|
110
|
-
createCompoundIndexValue(`${match1}a😎no!`, match2, 'no!'),
|
|
111
|
-
createCompoundIndexValue(match1, `${match2}a😎no!`, 'no!'),
|
|
112
|
-
createCompoundIndexValue(match1, `${match2} `, 'no!'),
|
|
113
|
-
createCompoundIndexValue(match1, ' ', 'no!'),
|
|
114
|
-
createCompoundIndexValue(match1, '\u00001', 'no!'),
|
|
115
|
-
createCompoundIndexValue(match1, '\uE007f', 'no!'),
|
|
116
|
-
].sort();
|
|
117
|
-
expect(sorted.filter((value) => value > createLowerBoundIndexValue(match1, match2) &&
|
|
118
|
-
value < createUpperBoundIndexValue(match1, match2))).toEqual([
|
|
119
|
-
`aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}b`,
|
|
120
|
-
`aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}c`,
|
|
121
|
-
`aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}d`,
|
|
122
|
-
`aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}e`,
|
|
123
|
-
]);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { COMPOUND_INDEX_LOWER_BOUND_SEPARATOR, COMPOUND_INDEX_SEPARATOR, COMPOUND_INDEX_UPPER_BOUND_SEPARATOR, createCompoundIndexValue, createLowerBoundIndexValue, createUpperBoundIndexValue, } from './indexes.js';
|
|
3
|
+
describe('compound indexes', () => {
|
|
4
|
+
it('can be created from two string values', () => {
|
|
5
|
+
expect(createCompoundIndexValue('a', 'b')).toEqual(`a${COMPOUND_INDEX_SEPARATOR}b`);
|
|
6
|
+
});
|
|
7
|
+
it('can be created from two number values', () => {
|
|
8
|
+
expect(createCompoundIndexValue(1, 2)).toEqual(`1${COMPOUND_INDEX_SEPARATOR}2`);
|
|
9
|
+
});
|
|
10
|
+
it('can be created from an array and string value', () => {
|
|
11
|
+
expect(createCompoundIndexValue(['a', 'b'], 'c')).toEqual([
|
|
12
|
+
`a${COMPOUND_INDEX_SEPARATOR}c`,
|
|
13
|
+
`b${COMPOUND_INDEX_SEPARATOR}c`,
|
|
14
|
+
]);
|
|
15
|
+
});
|
|
16
|
+
it('can be created from a string and array of numbers', () => {
|
|
17
|
+
expect(createCompoundIndexValue('a', [1, 2])).toEqual([
|
|
18
|
+
`a${COMPOUND_INDEX_SEPARATOR}1`,
|
|
19
|
+
`a${COMPOUND_INDEX_SEPARATOR}2`,
|
|
20
|
+
]);
|
|
21
|
+
});
|
|
22
|
+
it('can be created from an array of strings and an array of booleans', () => {
|
|
23
|
+
expect(createCompoundIndexValue(['a', 'b'], [true, false])).toEqual([
|
|
24
|
+
`a${COMPOUND_INDEX_SEPARATOR}true`,
|
|
25
|
+
`a${COMPOUND_INDEX_SEPARATOR}false`,
|
|
26
|
+
`b${COMPOUND_INDEX_SEPARATOR}true`,
|
|
27
|
+
`b${COMPOUND_INDEX_SEPARATOR}false`,
|
|
28
|
+
]);
|
|
29
|
+
});
|
|
30
|
+
it('remove duplicate array compound index values', () => {
|
|
31
|
+
expect(createCompoundIndexValue(['a', 'b', 'b'], [true, false, true])).toEqual([
|
|
32
|
+
`a${COMPOUND_INDEX_SEPARATOR}true`,
|
|
33
|
+
`a${COMPOUND_INDEX_SEPARATOR}false`,
|
|
34
|
+
`b${COMPOUND_INDEX_SEPARATOR}true`,
|
|
35
|
+
`b${COMPOUND_INDEX_SEPARATOR}false`,
|
|
36
|
+
]);
|
|
37
|
+
});
|
|
38
|
+
it('creates lower bound value for multi-value indexes', () => {
|
|
39
|
+
expect(createLowerBoundIndexValue('a', 'b')).toEqual(`a${COMPOUND_INDEX_SEPARATOR}b${COMPOUND_INDEX_SEPARATOR}${COMPOUND_INDEX_LOWER_BOUND_SEPARATOR}`);
|
|
40
|
+
});
|
|
41
|
+
it('creates upper bound value for multi-value indexes', () => {
|
|
42
|
+
expect(createUpperBoundIndexValue('a', 'b')).toEqual(`a${COMPOUND_INDEX_SEPARATOR}b${COMPOUND_INDEX_UPPER_BOUND_SEPARATOR}`);
|
|
43
|
+
}),
|
|
44
|
+
it('will always be grouped by the first item', () => {
|
|
45
|
+
expect([
|
|
46
|
+
createCompoundIndexValue('aaaaaa', 'b'),
|
|
47
|
+
createCompoundIndexValue('aaaaaa', 'c'),
|
|
48
|
+
createCompoundIndexValue('aaaaaa', 'd'),
|
|
49
|
+
createCompoundIndexValue('aaaaaa', 'e'),
|
|
50
|
+
// extra nefarious!
|
|
51
|
+
createCompoundIndexValue('aaaaaaa', 'no!'),
|
|
52
|
+
createCompoundIndexValue('aaaaaa ', 'no!'),
|
|
53
|
+
createCompoundIndexValue(`aaaaaa😎`, 'no!'),
|
|
54
|
+
createCompoundIndexValue(`aaaaaa😎😎`, 'no!'),
|
|
55
|
+
createCompoundIndexValue('aaa', 'no!'),
|
|
56
|
+
createCompoundIndexValue(`aaaaaaa😎no!`, 'no!'),
|
|
57
|
+
].sort()).toEqual([
|
|
58
|
+
`aaaaaa ${COMPOUND_INDEX_SEPARATOR}no!`,
|
|
59
|
+
`aaaaaaa😎no!${COMPOUND_INDEX_SEPARATOR}no!`,
|
|
60
|
+
`aaaaaaa${COMPOUND_INDEX_SEPARATOR}no!`,
|
|
61
|
+
`aaaaaa😎😎${COMPOUND_INDEX_SEPARATOR}no!`,
|
|
62
|
+
`aaaaaa😎${COMPOUND_INDEX_SEPARATOR}no!`,
|
|
63
|
+
// this is the contiguous block of relevant values
|
|
64
|
+
`aaaaaa${COMPOUND_INDEX_SEPARATOR}b`,
|
|
65
|
+
`aaaaaa${COMPOUND_INDEX_SEPARATOR}c`,
|
|
66
|
+
`aaaaaa${COMPOUND_INDEX_SEPARATOR}d`,
|
|
67
|
+
`aaaaaa${COMPOUND_INDEX_SEPARATOR}e`,
|
|
68
|
+
// here ends the block
|
|
69
|
+
`aaa${COMPOUND_INDEX_SEPARATOR}no!`,
|
|
70
|
+
]);
|
|
71
|
+
});
|
|
72
|
+
it('will be bounded by upper and lower bound values', () => {
|
|
73
|
+
const match = 'aaaaaa';
|
|
74
|
+
const sorted = [
|
|
75
|
+
createCompoundIndexValue(match, 'b'),
|
|
76
|
+
createCompoundIndexValue(match, 'c'),
|
|
77
|
+
createCompoundIndexValue(match, 'd'),
|
|
78
|
+
createCompoundIndexValue(match, 'e'),
|
|
79
|
+
// extra nefarious!
|
|
80
|
+
createCompoundIndexValue(`${match}a`, 'no!'),
|
|
81
|
+
createCompoundIndexValue(`${match} `, 'no!'),
|
|
82
|
+
createCompoundIndexValue(`${match}😎`, 'no!'),
|
|
83
|
+
createCompoundIndexValue(`${match}😎😎`, 'no!'),
|
|
84
|
+
createCompoundIndexValue('aaa', 'no!'),
|
|
85
|
+
createCompoundIndexValue(`${match}a😎no!`, 'no!'),
|
|
86
|
+
].sort();
|
|
87
|
+
const boundedBlock = sorted.filter((value) => value > createLowerBoundIndexValue(match) &&
|
|
88
|
+
value < createUpperBoundIndexValue(match));
|
|
89
|
+
expect(boundedBlock).toEqual([
|
|
90
|
+
`aaaaaa${COMPOUND_INDEX_SEPARATOR}b`,
|
|
91
|
+
`aaaaaa${COMPOUND_INDEX_SEPARATOR}c`,
|
|
92
|
+
`aaaaaa${COMPOUND_INDEX_SEPARATOR}d`,
|
|
93
|
+
`aaaaaa${COMPOUND_INDEX_SEPARATOR}e`,
|
|
94
|
+
]);
|
|
95
|
+
});
|
|
96
|
+
it('will be bounded by upper and lower bounds when matching multiple sections', () => {
|
|
97
|
+
const match1 = 'aaaaaa';
|
|
98
|
+
const match2 = 'bbbbbb';
|
|
99
|
+
const sorted = [
|
|
100
|
+
createCompoundIndexValue(match1, match2, 'b'),
|
|
101
|
+
createCompoundIndexValue(match1, match2, 'c'),
|
|
102
|
+
createCompoundIndexValue(match1, match2, 'd'),
|
|
103
|
+
createCompoundIndexValue(match1, match2, 'e'),
|
|
104
|
+
// extra nefarious!
|
|
105
|
+
createCompoundIndexValue(`${match1}a`, match2, 'no!'),
|
|
106
|
+
createCompoundIndexValue(`${match1} `, match2, 'no!'),
|
|
107
|
+
createCompoundIndexValue(`${match1}😎`, match2, 'no!'),
|
|
108
|
+
createCompoundIndexValue(`${match1}😎😎`, match2, 'no!'),
|
|
109
|
+
createCompoundIndexValue('aaa', match2, 'no!'),
|
|
110
|
+
createCompoundIndexValue(`${match1}a😎no!`, match2, 'no!'),
|
|
111
|
+
createCompoundIndexValue(match1, `${match2}a😎no!`, 'no!'),
|
|
112
|
+
createCompoundIndexValue(match1, `${match2} `, 'no!'),
|
|
113
|
+
createCompoundIndexValue(match1, ' ', 'no!'),
|
|
114
|
+
createCompoundIndexValue(match1, '\u00001', 'no!'),
|
|
115
|
+
createCompoundIndexValue(match1, '\uE007f', 'no!'),
|
|
116
|
+
].sort();
|
|
117
|
+
expect(sorted.filter((value) => value > createLowerBoundIndexValue(match1, match2) &&
|
|
118
|
+
value < createUpperBoundIndexValue(match1, match2))).toEqual([
|
|
119
|
+
`aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}b`,
|
|
120
|
+
`aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}c`,
|
|
121
|
+
`aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}d`,
|
|
122
|
+
`aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}e`,
|
|
123
|
+
]);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
126
|
//# sourceMappingURL=indexes.test.js.map
|