@verdant-web/common 1.11.0 → 1.12.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 +41 -41
- package/dist/cjs/batching.js +88 -88
- package/dist/cjs/files.d.ts +19 -19
- package/dist/cjs/files.js +18 -18
- package/dist/cjs/index.d.ts +18 -18
- package/dist/cjs/index.js +35 -35
- package/dist/cjs/indexes.d.ts +14 -14
- package/dist/cjs/indexes.js +115 -115
- package/dist/cjs/indexes.test.d.ts +1 -1
- package/dist/cjs/indexes.test.js +127 -127
- package/dist/cjs/migration.d.ts +98 -98
- package/dist/cjs/migration.js +127 -127
- package/dist/cjs/oids.d.ts +85 -87
- package/dist/cjs/oids.js +363 -374
- package/dist/cjs/oids.js.map +1 -1
- package/dist/cjs/oids.test.d.ts +1 -1
- package/dist/cjs/oids.test.js +269 -251
- package/dist/cjs/oids.test.js.map +1 -1
- package/dist/cjs/operation.d.ts +139 -139
- package/dist/cjs/operation.js +532 -532
- package/dist/cjs/operation.js.map +1 -1
- package/dist/cjs/operation.test.d.ts +1 -1
- package/dist/cjs/operation.test.js +505 -505
- package/dist/cjs/operation.test.js.map +1 -1
- package/dist/cjs/patch.d.ts +26 -26
- package/dist/cjs/patch.js +226 -226
- package/dist/cjs/patch.js.map +1 -1
- 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 +5 -5
- package/dist/cjs/refs.js +21 -21
- package/dist/cjs/replica.d.ts +28 -28
- package/dist/cjs/replica.js +28 -28
- package/dist/cjs/schema/defaults.d.ts +4 -4
- package/dist/cjs/schema/defaults.js +71 -71
- package/dist/cjs/schema/defaults.test.d.ts +1 -1
- package/dist/cjs/schema/defaults.test.js +20 -20
- package/dist/cjs/schema/defaults.test.js.map +1 -1
- package/dist/cjs/schema/index.d.ts +8 -8
- package/dist/cjs/schema/index.js +28 -28
- 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 +51 -51
- package/dist/cjs/schema/types/collection.js +2 -2
- package/dist/cjs/schema/types/compounds.d.ts +12 -12
- package/dist/cjs/schema/types/compounds.js +2 -2
- package/dist/cjs/schema/types/fields.d.ts +59 -59
- 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 +28 -28
- 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/timestamp.d.ts +48 -48
- package/dist/cjs/timestamp.js +243 -243
- package/dist/cjs/timestamp.test.d.ts +1 -1
- package/dist/cjs/timestamp.test.js +93 -93
- package/dist/cjs/undo.d.ts +3 -3
- package/dist/cjs/undo.js +198 -198
- package/dist/cjs/utils.d.ts +15 -15
- package/dist/cjs/utils.js +127 -127
- 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 +41 -41
- package/dist/esm/batching.js +83 -83
- package/dist/esm/files.d.ts +19 -19
- package/dist/esm/files.js +12 -12
- package/dist/esm/index.d.ts +18 -18
- package/dist/esm/index.js +15 -15
- package/dist/esm/indexes.d.ts +14 -14
- package/dist/esm/indexes.js +105 -105
- package/dist/esm/indexes.test.d.ts +1 -1
- package/dist/esm/indexes.test.js +125 -125
- package/dist/esm/migration.d.ts +98 -98
- package/dist/esm/migration.js +121 -121
- package/dist/esm/oids.d.ts +85 -87
- package/dist/esm/oids.js +336 -347
- package/dist/esm/oids.js.map +1 -1
- package/dist/esm/oids.test.d.ts +1 -1
- package/dist/esm/oids.test.js +267 -249
- package/dist/esm/oids.test.js.map +1 -1
- package/dist/esm/operation.d.ts +139 -139
- package/dist/esm/operation.js +517 -517
- package/dist/esm/operation.js.map +1 -1
- package/dist/esm/operation.test.d.ts +1 -1
- package/dist/esm/operation.test.js +503 -503
- package/dist/esm/operation.test.js.map +1 -1
- package/dist/esm/patch.d.ts +26 -26
- package/dist/esm/patch.js +222 -222
- package/dist/esm/patch.js.map +1 -1
- 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 +5 -5
- package/dist/esm/refs.js +16 -16
- package/dist/esm/replica.d.ts +28 -28
- package/dist/esm/replica.js +25 -25
- package/dist/esm/schema/defaults.d.ts +4 -4
- package/dist/esm/schema/defaults.js +65 -65
- package/dist/esm/schema/defaults.test.d.ts +1 -1
- package/dist/esm/schema/defaults.test.js +18 -18
- package/dist/esm/schema/defaults.test.js.map +1 -1
- package/dist/esm/schema/index.d.ts +8 -8
- package/dist/esm/schema/index.js +9 -9
- 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 +51 -51
- package/dist/esm/schema/types/collection.js +1 -1
- package/dist/esm/schema/types/compounds.d.ts +12 -12
- package/dist/esm/schema/types/compounds.js +1 -1
- package/dist/esm/schema/types/fields.d.ts +59 -59
- 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 +28 -28
- 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/timestamp.d.ts +48 -48
- package/dist/esm/timestamp.js +228 -228
- package/dist/esm/timestamp.test.d.ts +1 -1
- package/dist/esm/timestamp.test.js +91 -91
- package/dist/esm/undo.d.ts +3 -3
- package/dist/esm/undo.js +194 -194
- package/dist/esm/utils.d.ts +15 -15
- package/dist/esm/utils.js +113 -113
- 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/oids.test.ts +62 -51
- package/src/oids.ts +7 -26
- package/src/operation.test.ts +32 -40
- package/src/operation.ts +4 -16
- package/src/patch.ts +5 -15
- package/src/schema/defaults.test.ts +1 -1
- package/dist/cjs/files.test.d.ts +0 -1
- package/dist/cjs/files.test.js +0 -81
- package/dist/cjs/files.test.js.map +0 -1
- package/dist/esm/files.test.d.ts +0 -1
- package/dist/esm/files.test.js +0 -79
- package/dist/esm/files.test.js.map +0 -1
package/dist/esm/batching.js
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
export class Batcher {
|
|
2
|
-
constructor(flusher) {
|
|
3
|
-
this.flusher = flusher;
|
|
4
|
-
this.batches = new Map();
|
|
5
|
-
this.flush = (key) => {
|
|
6
|
-
const batch = this.batches.get(key);
|
|
7
|
-
if (!batch)
|
|
8
|
-
return;
|
|
9
|
-
return batch.flush();
|
|
10
|
-
};
|
|
11
|
-
this.discard = (key) => {
|
|
12
|
-
const batch = this.batches.get(key);
|
|
13
|
-
if (!batch)
|
|
14
|
-
return;
|
|
15
|
-
batch.discard();
|
|
16
|
-
this.batches.delete(key);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
add({ key, userData, items, max, timeout, }) {
|
|
20
|
-
let batch = this.batches.get(key);
|
|
21
|
-
if (!batch) {
|
|
22
|
-
batch = new Batch({
|
|
23
|
-
max: max || null,
|
|
24
|
-
startedAt: Date.now(),
|
|
25
|
-
userData,
|
|
26
|
-
timeout: timeout || null,
|
|
27
|
-
flusher: this.flusher,
|
|
28
|
-
key,
|
|
29
|
-
});
|
|
30
|
-
this.batches.set(key, batch);
|
|
31
|
-
}
|
|
32
|
-
batch.update({
|
|
33
|
-
items,
|
|
34
|
-
max,
|
|
35
|
-
timeout,
|
|
36
|
-
userData,
|
|
37
|
-
});
|
|
38
|
-
return batch;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
export class Batch {
|
|
42
|
-
constructor({ max, startedAt, timeout, userData, flusher, key, }) {
|
|
43
|
-
this.items = [];
|
|
44
|
-
this.update = ({ items, max, timeout, userData, }) => {
|
|
45
|
-
this.items.push(...items);
|
|
46
|
-
if (max !== undefined)
|
|
47
|
-
this.max = max;
|
|
48
|
-
if (timeout !== undefined)
|
|
49
|
-
this.timeout = timeout;
|
|
50
|
-
if (userData)
|
|
51
|
-
this.userData = userData;
|
|
52
|
-
// if the batch has items and a timeout but has not
|
|
53
|
-
// scheduled yet, schedule it
|
|
54
|
-
const needsSchedule = this.items.length !== 0 && this.timeout !== null && !this.flushTimeout;
|
|
55
|
-
// if the batch has already reached its max, skip scheduling
|
|
56
|
-
// and flush immediately
|
|
57
|
-
if (this.max !== null && this.items.length >= this.max) {
|
|
58
|
-
this.flush();
|
|
59
|
-
}
|
|
60
|
-
else if (needsSchedule && this.timeout !== null) {
|
|
61
|
-
this.flushTimeout = setTimeout(this.flush, this.timeout);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
this.flush = () => {
|
|
65
|
-
this.flushTimeout && clearTimeout(this.flushTimeout);
|
|
66
|
-
this.flushTimeout = undefined;
|
|
67
|
-
const items = this.items;
|
|
68
|
-
this.items = [];
|
|
69
|
-
return this.flusher(items, this.key, this.userData);
|
|
70
|
-
};
|
|
71
|
-
this.discard = () => {
|
|
72
|
-
this.flushTimeout && clearTimeout(this.flushTimeout);
|
|
73
|
-
this.flushTimeout = undefined;
|
|
74
|
-
this.items = [];
|
|
75
|
-
};
|
|
76
|
-
this.max = max;
|
|
77
|
-
this.startedAt = startedAt;
|
|
78
|
-
this.timeout = timeout;
|
|
79
|
-
this.userData = userData;
|
|
80
|
-
this.flusher = flusher;
|
|
81
|
-
this.key = key;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
1
|
+
export class Batcher {
|
|
2
|
+
constructor(flusher) {
|
|
3
|
+
this.flusher = flusher;
|
|
4
|
+
this.batches = new Map();
|
|
5
|
+
this.flush = (key) => {
|
|
6
|
+
const batch = this.batches.get(key);
|
|
7
|
+
if (!batch)
|
|
8
|
+
return;
|
|
9
|
+
return batch.flush();
|
|
10
|
+
};
|
|
11
|
+
this.discard = (key) => {
|
|
12
|
+
const batch = this.batches.get(key);
|
|
13
|
+
if (!batch)
|
|
14
|
+
return;
|
|
15
|
+
batch.discard();
|
|
16
|
+
this.batches.delete(key);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
add({ key, userData, items, max, timeout, }) {
|
|
20
|
+
let batch = this.batches.get(key);
|
|
21
|
+
if (!batch) {
|
|
22
|
+
batch = new Batch({
|
|
23
|
+
max: max || null,
|
|
24
|
+
startedAt: Date.now(),
|
|
25
|
+
userData,
|
|
26
|
+
timeout: timeout || null,
|
|
27
|
+
flusher: this.flusher,
|
|
28
|
+
key,
|
|
29
|
+
});
|
|
30
|
+
this.batches.set(key, batch);
|
|
31
|
+
}
|
|
32
|
+
batch.update({
|
|
33
|
+
items,
|
|
34
|
+
max,
|
|
35
|
+
timeout,
|
|
36
|
+
userData,
|
|
37
|
+
});
|
|
38
|
+
return batch;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class Batch {
|
|
42
|
+
constructor({ max, startedAt, timeout, userData, flusher, key, }) {
|
|
43
|
+
this.items = [];
|
|
44
|
+
this.update = ({ items, max, timeout, userData, }) => {
|
|
45
|
+
this.items.push(...items);
|
|
46
|
+
if (max !== undefined)
|
|
47
|
+
this.max = max;
|
|
48
|
+
if (timeout !== undefined)
|
|
49
|
+
this.timeout = timeout;
|
|
50
|
+
if (userData)
|
|
51
|
+
this.userData = userData;
|
|
52
|
+
// if the batch has items and a timeout but has not
|
|
53
|
+
// scheduled yet, schedule it
|
|
54
|
+
const needsSchedule = this.items.length !== 0 && this.timeout !== null && !this.flushTimeout;
|
|
55
|
+
// if the batch has already reached its max, skip scheduling
|
|
56
|
+
// and flush immediately
|
|
57
|
+
if (this.max !== null && this.items.length >= this.max) {
|
|
58
|
+
this.flush();
|
|
59
|
+
}
|
|
60
|
+
else if (needsSchedule && this.timeout !== null) {
|
|
61
|
+
this.flushTimeout = setTimeout(this.flush, this.timeout);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
this.flush = () => {
|
|
65
|
+
this.flushTimeout && clearTimeout(this.flushTimeout);
|
|
66
|
+
this.flushTimeout = undefined;
|
|
67
|
+
const items = this.items;
|
|
68
|
+
this.items = [];
|
|
69
|
+
return this.flusher(items, this.key, this.userData);
|
|
70
|
+
};
|
|
71
|
+
this.discard = () => {
|
|
72
|
+
this.flushTimeout && clearTimeout(this.flushTimeout);
|
|
73
|
+
this.flushTimeout = undefined;
|
|
74
|
+
this.items = [];
|
|
75
|
+
};
|
|
76
|
+
this.max = max;
|
|
77
|
+
this.startedAt = startedAt;
|
|
78
|
+
this.timeout = timeout;
|
|
79
|
+
this.userData = userData;
|
|
80
|
+
this.flusher = flusher;
|
|
81
|
+
this.key = key;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
84
|
//# sourceMappingURL=batching.js.map
|
package/dist/esm/files.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export declare type FileRef = {
|
|
2
|
-
'@@type': 'file';
|
|
3
|
-
id: string;
|
|
4
|
-
};
|
|
5
|
-
export declare function isFileRef(value: any): value is FileRef;
|
|
6
|
-
export declare function createFileRef(id: string): FileRef;
|
|
7
|
-
export declare type FileData = {
|
|
8
|
-
id: string;
|
|
9
|
-
/**
|
|
10
|
-
* For locally created files, this starts false, until it's uploaded
|
|
11
|
-
* Remote files this is always true
|
|
12
|
-
*/
|
|
13
|
-
remote: boolean;
|
|
14
|
-
name: string;
|
|
15
|
-
type: string;
|
|
16
|
-
file?: Blob;
|
|
17
|
-
url?: string;
|
|
18
|
-
};
|
|
19
|
-
export declare function getAllFileFields(snapshot: any): [string, FileRef][];
|
|
1
|
+
export declare type FileRef = {
|
|
2
|
+
'@@type': 'file';
|
|
3
|
+
id: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function isFileRef(value: any): value is FileRef;
|
|
6
|
+
export declare function createFileRef(id: string): FileRef;
|
|
7
|
+
export declare type FileData = {
|
|
8
|
+
id: string;
|
|
9
|
+
/**
|
|
10
|
+
* For locally created files, this starts false, until it's uploaded
|
|
11
|
+
* Remote files this is always true
|
|
12
|
+
*/
|
|
13
|
+
remote: boolean;
|
|
14
|
+
name: string;
|
|
15
|
+
type: string;
|
|
16
|
+
file?: Blob;
|
|
17
|
+
url?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function getAllFileFields(snapshot: any): [string, FileRef][];
|
package/dist/esm/files.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export function isFileRef(value) {
|
|
2
|
-
return value && value['@@type'] === 'file';
|
|
3
|
-
}
|
|
4
|
-
export function createFileRef(id) {
|
|
5
|
-
return {
|
|
6
|
-
'@@type': 'file',
|
|
7
|
-
id,
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
export function getAllFileFields(snapshot) {
|
|
11
|
-
return Object.entries(snapshot).filter((entry) => isFileRef(entry[1]));
|
|
12
|
-
}
|
|
1
|
+
export function isFileRef(value) {
|
|
2
|
+
return value && value['@@type'] === 'file';
|
|
3
|
+
}
|
|
4
|
+
export function createFileRef(id) {
|
|
5
|
+
return {
|
|
6
|
+
'@@type': 'file',
|
|
7
|
+
id,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export function getAllFileFields(snapshot) {
|
|
11
|
+
return Object.entries(snapshot).filter((entry) => isFileRef(entry[1]));
|
|
12
|
+
}
|
|
13
13
|
//# sourceMappingURL=files.js.map
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export * from './protocol.js';
|
|
2
|
-
export * from './timestamp.js';
|
|
3
|
-
export * from './operation.js';
|
|
4
|
-
export * from './baseline.js';
|
|
5
|
-
export * from './replica.js';
|
|
6
|
-
export * from './schema/index.js';
|
|
7
|
-
export * from './utils.js';
|
|
8
|
-
export * from './indexes.js';
|
|
9
|
-
export { migrate, migrationRange, createDefaultMigration, } from './migration.js';
|
|
10
|
-
export type { Migration, MigrationIndexDescription, MigrationEngine, } from './migration.js';
|
|
11
|
-
export type { UserInfo } from './presence.js';
|
|
12
|
-
export * from './patch.js';
|
|
13
|
-
export * from './oids.js';
|
|
14
|
-
export * from './EventSubscriber.js';
|
|
15
|
-
export * from './undo.js';
|
|
16
|
-
export * from './batching.js';
|
|
17
|
-
export * from './files.js';
|
|
18
|
-
export type { Ref } from './refs.js';
|
|
1
|
+
export * from './protocol.js';
|
|
2
|
+
export * from './timestamp.js';
|
|
3
|
+
export * from './operation.js';
|
|
4
|
+
export * from './baseline.js';
|
|
5
|
+
export * from './replica.js';
|
|
6
|
+
export * from './schema/index.js';
|
|
7
|
+
export * from './utils.js';
|
|
8
|
+
export * from './indexes.js';
|
|
9
|
+
export { migrate, migrationRange, createDefaultMigration, } from './migration.js';
|
|
10
|
+
export type { Migration, MigrationIndexDescription, MigrationEngine, } from './migration.js';
|
|
11
|
+
export type { UserInfo } from './presence.js';
|
|
12
|
+
export * from './patch.js';
|
|
13
|
+
export * from './oids.js';
|
|
14
|
+
export * from './EventSubscriber.js';
|
|
15
|
+
export * from './undo.js';
|
|
16
|
+
export * from './batching.js';
|
|
17
|
+
export * from './files.js';
|
|
18
|
+
export type { Ref } from './refs.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export * from './protocol.js';
|
|
2
|
-
export * from './timestamp.js';
|
|
3
|
-
export * from './operation.js';
|
|
4
|
-
export * from './baseline.js';
|
|
5
|
-
export * from './replica.js';
|
|
6
|
-
export * from './schema/index.js';
|
|
7
|
-
export * from './utils.js';
|
|
8
|
-
export * from './indexes.js';
|
|
9
|
-
export { migrate, migrationRange, createDefaultMigration, } from './migration.js';
|
|
10
|
-
export * from './patch.js';
|
|
11
|
-
export * from './oids.js';
|
|
12
|
-
export * from './EventSubscriber.js';
|
|
13
|
-
export * from './undo.js';
|
|
14
|
-
export * from './batching.js';
|
|
15
|
-
export * from './files.js';
|
|
1
|
+
export * from './protocol.js';
|
|
2
|
+
export * from './timestamp.js';
|
|
3
|
+
export * from './operation.js';
|
|
4
|
+
export * from './baseline.js';
|
|
5
|
+
export * from './replica.js';
|
|
6
|
+
export * from './schema/index.js';
|
|
7
|
+
export * from './utils.js';
|
|
8
|
+
export * from './indexes.js';
|
|
9
|
+
export { migrate, migrationRange, createDefaultMigration, } from './migration.js';
|
|
10
|
+
export * from './patch.js';
|
|
11
|
+
export * from './oids.js';
|
|
12
|
+
export * from './EventSubscriber.js';
|
|
13
|
+
export * from './undo.js';
|
|
14
|
+
export * from './batching.js';
|
|
15
|
+
export * from './files.js';
|
|
16
16
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/indexes.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { StorageCollectionSchema } from './index.js';
|
|
2
|
-
export declare const COMPOUND_INDEX_SEPARATOR = "\uFFFFFE";
|
|
3
|
-
export declare const COMPOUND_INDEX_LOWER_BOUND_SEPARATOR = "\0";
|
|
4
|
-
export declare const COMPOUND_INDEX_UPPER_BOUND_SEPARATOR = "\uFFFFFF";
|
|
5
|
-
declare type IndexableFieldValue = string | number | boolean | any[];
|
|
6
|
-
export declare type CompoundIndexValue = string | string[];
|
|
7
|
-
export declare function createCompoundIndexValue(...fields: IndexableFieldValue[]): CompoundIndexValue;
|
|
8
|
-
export declare function createUpperBoundIndexValue(...fields: IndexableFieldValue[]): string;
|
|
9
|
-
export declare function createLowerBoundIndexValue(...fields: IndexableFieldValue[]): string;
|
|
10
|
-
export declare function computeSynthetics(schema: StorageCollectionSchema, obj: any): Record<string, any>;
|
|
11
|
-
export declare function computeCompoundIndices(schema: StorageCollectionSchema<any, any, any>, doc: any): any;
|
|
12
|
-
export declare function assignIndexValues(schema: StorageCollectionSchema<any, any, any>, doc: any): any;
|
|
13
|
-
export declare function sanitizeIndexValue(value: unknown): string | number | (string | number)[];
|
|
14
|
-
export {};
|
|
1
|
+
import { StorageCollectionSchema } from './index.js';
|
|
2
|
+
export declare const COMPOUND_INDEX_SEPARATOR = "\uFFFFFE";
|
|
3
|
+
export declare const COMPOUND_INDEX_LOWER_BOUND_SEPARATOR = "\0";
|
|
4
|
+
export declare const COMPOUND_INDEX_UPPER_BOUND_SEPARATOR = "\uFFFFFF";
|
|
5
|
+
declare type IndexableFieldValue = string | number | boolean | any[];
|
|
6
|
+
export declare type CompoundIndexValue = string | string[];
|
|
7
|
+
export declare function createCompoundIndexValue(...fields: IndexableFieldValue[]): CompoundIndexValue;
|
|
8
|
+
export declare function createUpperBoundIndexValue(...fields: IndexableFieldValue[]): string;
|
|
9
|
+
export declare function createLowerBoundIndexValue(...fields: IndexableFieldValue[]): string;
|
|
10
|
+
export declare function computeSynthetics(schema: StorageCollectionSchema, obj: any): Record<string, any>;
|
|
11
|
+
export declare function computeCompoundIndices(schema: StorageCollectionSchema<any, any, any>, doc: any): any;
|
|
12
|
+
export declare function assignIndexValues(schema: StorageCollectionSchema<any, any, any>, doc: any): any;
|
|
13
|
+
export declare function sanitizeIndexValue(value: unknown): string | number | (string | number)[];
|
|
14
|
+
export {};
|
package/dist/esm/indexes.js
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
// unlikely to be used unicode character
|
|
2
|
-
export const COMPOUND_INDEX_SEPARATOR = '\uFFFFFE';
|
|
3
|
-
// 1 lower than separator
|
|
4
|
-
export const COMPOUND_INDEX_LOWER_BOUND_SEPARATOR = '\u0000';
|
|
5
|
-
// 1 higher than separator
|
|
6
|
-
export const COMPOUND_INDEX_UPPER_BOUND_SEPARATOR = '\uFFFFFF';
|
|
7
|
-
export function createCompoundIndexValue(...fields) {
|
|
8
|
-
const value = expandArrayIndex(fields);
|
|
9
|
-
if (value.length === 1) {
|
|
10
|
-
return value[0];
|
|
11
|
-
}
|
|
12
|
-
return value;
|
|
13
|
-
}
|
|
14
|
-
export function createUpperBoundIndexValue(...fields) {
|
|
15
|
-
return (fields.join(COMPOUND_INDEX_SEPARATOR) +
|
|
16
|
-
`${COMPOUND_INDEX_UPPER_BOUND_SEPARATOR}`);
|
|
17
|
-
}
|
|
18
|
-
export function createLowerBoundIndexValue(...fields) {
|
|
19
|
-
return (fields.join(COMPOUND_INDEX_SEPARATOR) +
|
|
20
|
-
`${COMPOUND_INDEX_SEPARATOR}${COMPOUND_INDEX_LOWER_BOUND_SEPARATOR}`);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Whenever an array value is included in a compound index, we have to expand
|
|
24
|
-
* the value to include all permutations of values in the array.
|
|
25
|
-
* For example if we had an index id + tags on a document
|
|
26
|
-
*
|
|
27
|
-
* {
|
|
28
|
-
* id: '1',
|
|
29
|
-
* tags: ['a', 'b']
|
|
30
|
-
* }
|
|
31
|
-
*
|
|
32
|
-
* we want to create an index:
|
|
33
|
-
*
|
|
34
|
-
* id_tags: ['1#a', '1#b']
|
|
35
|
-
*
|
|
36
|
-
* If multiple arrays are indexed we have to exponentially expand...
|
|
37
|
-
*
|
|
38
|
-
* id_tags_tags2: ['1#a#a', '1#a#b', '1#b#a', '1#b#b']
|
|
39
|
-
*
|
|
40
|
-
* To generalize this we construct a 2-level array of strings.
|
|
41
|
-
* Iterating over indexed values, we expand each item into N items if
|
|
42
|
-
* the current value is an array.
|
|
43
|
-
*
|
|
44
|
-
* Then we combine all nested arrays into compound index values.
|
|
45
|
-
* This will produce an array of 1 element if none of the indexed values
|
|
46
|
-
* were arrays. The caller should unwrap that.
|
|
47
|
-
*
|
|
48
|
-
* This function also deduplicates values.
|
|
49
|
-
*/
|
|
50
|
-
function expandArrayIndex(fields) {
|
|
51
|
-
let value = [[]];
|
|
52
|
-
for (const field of fields) {
|
|
53
|
-
if (Array.isArray(field)) {
|
|
54
|
-
const newValue = [];
|
|
55
|
-
for (const previousValue of value) {
|
|
56
|
-
for (const fieldValue of field) {
|
|
57
|
-
newValue.push(previousValue.concat(fieldValue));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
value = newValue;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
for (const item of value) {
|
|
64
|
-
item.push(`${field}`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return Array.from(new Set(value.map((item) => {
|
|
69
|
-
return item.join(COMPOUND_INDEX_SEPARATOR);
|
|
70
|
-
})));
|
|
71
|
-
}
|
|
72
|
-
export function computeSynthetics(schema, obj) {
|
|
73
|
-
const result = {};
|
|
74
|
-
for (const [name, property] of Object.entries(schema.synthetics || {})) {
|
|
75
|
-
result[name] = sanitizeIndexValue(property.compute(obj));
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
export function computeCompoundIndices(schema, doc) {
|
|
80
|
-
return Object.entries(schema.compounds || {}).reduce((acc, [indexKey, index]) => {
|
|
81
|
-
acc[indexKey] = createCompoundIndexValue(...index.of.map((key) => doc[key]));
|
|
82
|
-
return acc;
|
|
83
|
-
}, {});
|
|
84
|
-
}
|
|
85
|
-
export function assignIndexValues(schema, doc) {
|
|
86
|
-
Object.assign(doc, computeSynthetics(schema, doc));
|
|
87
|
-
Object.assign(doc, computeCompoundIndices(schema, doc));
|
|
88
|
-
return doc;
|
|
89
|
-
}
|
|
90
|
-
export function sanitizeIndexValue(value) {
|
|
91
|
-
if (typeof value === 'string' || typeof value === 'number') {
|
|
92
|
-
return value;
|
|
93
|
-
}
|
|
94
|
-
if (typeof value === 'boolean' || value === null) {
|
|
95
|
-
return `${value}`;
|
|
96
|
-
}
|
|
97
|
-
if (value === undefined) {
|
|
98
|
-
// this shouldn't happen ,but for resiliency...
|
|
99
|
-
return 'undefined';
|
|
100
|
-
}
|
|
101
|
-
if (Array.isArray(value)) {
|
|
102
|
-
return value.map(sanitizeIndexValue);
|
|
103
|
-
}
|
|
104
|
-
throw new Error(`Unsupported index value: ${value}`);
|
|
105
|
-
}
|
|
1
|
+
// unlikely to be used unicode character
|
|
2
|
+
export const COMPOUND_INDEX_SEPARATOR = '\uFFFFFE';
|
|
3
|
+
// 1 lower than separator
|
|
4
|
+
export const COMPOUND_INDEX_LOWER_BOUND_SEPARATOR = '\u0000';
|
|
5
|
+
// 1 higher than separator
|
|
6
|
+
export const COMPOUND_INDEX_UPPER_BOUND_SEPARATOR = '\uFFFFFF';
|
|
7
|
+
export function createCompoundIndexValue(...fields) {
|
|
8
|
+
const value = expandArrayIndex(fields);
|
|
9
|
+
if (value.length === 1) {
|
|
10
|
+
return value[0];
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
export function createUpperBoundIndexValue(...fields) {
|
|
15
|
+
return (fields.join(COMPOUND_INDEX_SEPARATOR) +
|
|
16
|
+
`${COMPOUND_INDEX_UPPER_BOUND_SEPARATOR}`);
|
|
17
|
+
}
|
|
18
|
+
export function createLowerBoundIndexValue(...fields) {
|
|
19
|
+
return (fields.join(COMPOUND_INDEX_SEPARATOR) +
|
|
20
|
+
`${COMPOUND_INDEX_SEPARATOR}${COMPOUND_INDEX_LOWER_BOUND_SEPARATOR}`);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Whenever an array value is included in a compound index, we have to expand
|
|
24
|
+
* the value to include all permutations of values in the array.
|
|
25
|
+
* For example if we had an index id + tags on a document
|
|
26
|
+
*
|
|
27
|
+
* {
|
|
28
|
+
* id: '1',
|
|
29
|
+
* tags: ['a', 'b']
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* we want to create an index:
|
|
33
|
+
*
|
|
34
|
+
* id_tags: ['1#a', '1#b']
|
|
35
|
+
*
|
|
36
|
+
* If multiple arrays are indexed we have to exponentially expand...
|
|
37
|
+
*
|
|
38
|
+
* id_tags_tags2: ['1#a#a', '1#a#b', '1#b#a', '1#b#b']
|
|
39
|
+
*
|
|
40
|
+
* To generalize this we construct a 2-level array of strings.
|
|
41
|
+
* Iterating over indexed values, we expand each item into N items if
|
|
42
|
+
* the current value is an array.
|
|
43
|
+
*
|
|
44
|
+
* Then we combine all nested arrays into compound index values.
|
|
45
|
+
* This will produce an array of 1 element if none of the indexed values
|
|
46
|
+
* were arrays. The caller should unwrap that.
|
|
47
|
+
*
|
|
48
|
+
* This function also deduplicates values.
|
|
49
|
+
*/
|
|
50
|
+
function expandArrayIndex(fields) {
|
|
51
|
+
let value = [[]];
|
|
52
|
+
for (const field of fields) {
|
|
53
|
+
if (Array.isArray(field)) {
|
|
54
|
+
const newValue = [];
|
|
55
|
+
for (const previousValue of value) {
|
|
56
|
+
for (const fieldValue of field) {
|
|
57
|
+
newValue.push(previousValue.concat(fieldValue));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
value = newValue;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
for (const item of value) {
|
|
64
|
+
item.push(`${field}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return Array.from(new Set(value.map((item) => {
|
|
69
|
+
return item.join(COMPOUND_INDEX_SEPARATOR);
|
|
70
|
+
})));
|
|
71
|
+
}
|
|
72
|
+
export function computeSynthetics(schema, obj) {
|
|
73
|
+
const result = {};
|
|
74
|
+
for (const [name, property] of Object.entries(schema.synthetics || {})) {
|
|
75
|
+
result[name] = sanitizeIndexValue(property.compute(obj));
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
export function computeCompoundIndices(schema, doc) {
|
|
80
|
+
return Object.entries(schema.compounds || {}).reduce((acc, [indexKey, index]) => {
|
|
81
|
+
acc[indexKey] = createCompoundIndexValue(...index.of.map((key) => doc[key]));
|
|
82
|
+
return acc;
|
|
83
|
+
}, {});
|
|
84
|
+
}
|
|
85
|
+
export function assignIndexValues(schema, doc) {
|
|
86
|
+
Object.assign(doc, computeSynthetics(schema, doc));
|
|
87
|
+
Object.assign(doc, computeCompoundIndices(schema, doc));
|
|
88
|
+
return doc;
|
|
89
|
+
}
|
|
90
|
+
export function sanitizeIndexValue(value) {
|
|
91
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
if (typeof value === 'boolean' || value === null) {
|
|
95
|
+
return `${value}`;
|
|
96
|
+
}
|
|
97
|
+
if (value === undefined) {
|
|
98
|
+
// this shouldn't happen ,but for resiliency...
|
|
99
|
+
return 'undefined';
|
|
100
|
+
}
|
|
101
|
+
if (Array.isArray(value)) {
|
|
102
|
+
return value.map(sanitizeIndexValue);
|
|
103
|
+
}
|
|
104
|
+
throw new Error(`Unsupported index value: ${value}`);
|
|
105
|
+
}
|
|
106
106
|
//# sourceMappingURL=indexes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|