@verdant-web/common 1.11.0 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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 +87 -87
- package/dist/cjs/oids.js +374 -374
- package/dist/cjs/oids.test.d.ts +1 -1
- package/dist/cjs/oids.test.js +245 -245
- package/dist/cjs/operation.d.ts +139 -139
- package/dist/cjs/operation.js +532 -532
- package/dist/cjs/operation.test.d.ts +1 -1
- package/dist/cjs/operation.test.js +484 -484
- 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 +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/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 +87 -87
- package/dist/esm/oids.js +347 -347
- package/dist/esm/oids.test.d.ts +1 -1
- package/dist/esm/oids.test.js +243 -243
- package/dist/esm/operation.d.ts +139 -139
- package/dist/esm/operation.js +517 -517
- package/dist/esm/operation.test.d.ts +1 -1
- package/dist/esm/operation.test.js +482 -482
- 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 +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/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/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
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export declare class EventSubscriber<Events extends {
|
|
2
|
-
[key: string]: (...args: any[]) => void;
|
|
3
|
-
}> {
|
|
4
|
-
private _onAllUnsubscribed?;
|
|
5
|
-
protected subscribers: Record<string, Record<string, (...args: any[]) => void>>;
|
|
6
|
-
protected counts: Record<string, number>;
|
|
7
|
-
private _disabled;
|
|
8
|
-
constructor(_onAllUnsubscribed?: ((event: keyof Events) => void) | undefined);
|
|
9
|
-
get disabled(): boolean;
|
|
10
|
-
subscriberCount: (event: Extract<keyof Events, string>) => number;
|
|
11
|
-
totalSubscriberCount: () => number;
|
|
12
|
-
subscribe: <K extends Extract<keyof Events, string>>(event: K, callback: Events[K]) => () => void;
|
|
13
|
-
emit: <K extends Extract<keyof Events, string>>(event: K, ...args: Parameters<Events[K]>) => void;
|
|
14
|
-
dispose: () => void;
|
|
15
|
-
disable: () => void;
|
|
16
|
-
}
|
|
17
|
-
export declare type EventsOf<T extends EventSubscriber<any>> = T extends EventSubscriber<infer E> ? keyof E : never;
|
|
1
|
+
export declare class EventSubscriber<Events extends {
|
|
2
|
+
[key: string]: (...args: any[]) => void;
|
|
3
|
+
}> {
|
|
4
|
+
private _onAllUnsubscribed?;
|
|
5
|
+
protected subscribers: Record<string, Record<string, (...args: any[]) => void>>;
|
|
6
|
+
protected counts: Record<string, number>;
|
|
7
|
+
private _disabled;
|
|
8
|
+
constructor(_onAllUnsubscribed?: ((event: keyof Events) => void) | undefined);
|
|
9
|
+
get disabled(): boolean;
|
|
10
|
+
subscriberCount: (event: Extract<keyof Events, string>) => number;
|
|
11
|
+
totalSubscriberCount: () => number;
|
|
12
|
+
subscribe: <K extends Extract<keyof Events, string>>(event: K, callback: Events[K]) => () => void;
|
|
13
|
+
emit: <K extends Extract<keyof Events, string>>(event: K, ...args: Parameters<Events[K]>) => void;
|
|
14
|
+
dispose: () => void;
|
|
15
|
+
disable: () => void;
|
|
16
|
+
}
|
|
17
|
+
export declare type EventsOf<T extends EventSubscriber<any>> = T extends EventSubscriber<infer E> ? keyof E : never;
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventSubscriber = void 0;
|
|
4
|
-
const utils_js_1 = require("./utils.js");
|
|
5
|
-
class EventSubscriber {
|
|
6
|
-
constructor(_onAllUnsubscribed) {
|
|
7
|
-
this._onAllUnsubscribed = _onAllUnsubscribed;
|
|
8
|
-
this.subscribers = {};
|
|
9
|
-
this.counts = {};
|
|
10
|
-
this._disabled = false;
|
|
11
|
-
this.subscriberCount = (event) => {
|
|
12
|
-
var _a;
|
|
13
|
-
return (_a = this.counts[event]) !== null && _a !== void 0 ? _a : 0;
|
|
14
|
-
};
|
|
15
|
-
this.totalSubscriberCount = () => {
|
|
16
|
-
return Object.values(this.counts).reduce((acc, count) => acc + count, 0);
|
|
17
|
-
};
|
|
18
|
-
this.subscribe = (event, callback) => {
|
|
19
|
-
const key = (0, utils_js_1.generateId)();
|
|
20
|
-
let subscribers = this.subscribers[event];
|
|
21
|
-
if (!subscribers) {
|
|
22
|
-
subscribers = this.subscribers[event] = {};
|
|
23
|
-
}
|
|
24
|
-
subscribers[key] = callback;
|
|
25
|
-
this.counts[event] = (this.counts[event] || 0) + 1;
|
|
26
|
-
return () => {
|
|
27
|
-
// already removed
|
|
28
|
-
if (!this.subscribers[event])
|
|
29
|
-
return;
|
|
30
|
-
delete this.subscribers[event][key];
|
|
31
|
-
this.counts[event]--;
|
|
32
|
-
if (this.counts[event] === 0) {
|
|
33
|
-
delete this.subscribers[event];
|
|
34
|
-
delete this.counts[event];
|
|
35
|
-
if (this._onAllUnsubscribed) {
|
|
36
|
-
this._onAllUnsubscribed(event);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
this.emit = (event, ...args) => {
|
|
42
|
-
if (this._disabled)
|
|
43
|
-
return;
|
|
44
|
-
if (this.subscribers[event]) {
|
|
45
|
-
Object.values(this.subscribers[event]).forEach((c) => c(...args));
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
this.dispose = () => {
|
|
49
|
-
const events = Object.keys(this.subscribers);
|
|
50
|
-
this.subscribers = {};
|
|
51
|
-
this.counts = {};
|
|
52
|
-
events.forEach((event) => {
|
|
53
|
-
if (this._onAllUnsubscribed) {
|
|
54
|
-
this._onAllUnsubscribed(event);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
this.disable = () => {
|
|
59
|
-
this._disabled = true;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
get disabled() {
|
|
63
|
-
return this._disabled;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.EventSubscriber = EventSubscriber;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventSubscriber = void 0;
|
|
4
|
+
const utils_js_1 = require("./utils.js");
|
|
5
|
+
class EventSubscriber {
|
|
6
|
+
constructor(_onAllUnsubscribed) {
|
|
7
|
+
this._onAllUnsubscribed = _onAllUnsubscribed;
|
|
8
|
+
this.subscribers = {};
|
|
9
|
+
this.counts = {};
|
|
10
|
+
this._disabled = false;
|
|
11
|
+
this.subscriberCount = (event) => {
|
|
12
|
+
var _a;
|
|
13
|
+
return (_a = this.counts[event]) !== null && _a !== void 0 ? _a : 0;
|
|
14
|
+
};
|
|
15
|
+
this.totalSubscriberCount = () => {
|
|
16
|
+
return Object.values(this.counts).reduce((acc, count) => acc + count, 0);
|
|
17
|
+
};
|
|
18
|
+
this.subscribe = (event, callback) => {
|
|
19
|
+
const key = (0, utils_js_1.generateId)();
|
|
20
|
+
let subscribers = this.subscribers[event];
|
|
21
|
+
if (!subscribers) {
|
|
22
|
+
subscribers = this.subscribers[event] = {};
|
|
23
|
+
}
|
|
24
|
+
subscribers[key] = callback;
|
|
25
|
+
this.counts[event] = (this.counts[event] || 0) + 1;
|
|
26
|
+
return () => {
|
|
27
|
+
// already removed
|
|
28
|
+
if (!this.subscribers[event])
|
|
29
|
+
return;
|
|
30
|
+
delete this.subscribers[event][key];
|
|
31
|
+
this.counts[event]--;
|
|
32
|
+
if (this.counts[event] === 0) {
|
|
33
|
+
delete this.subscribers[event];
|
|
34
|
+
delete this.counts[event];
|
|
35
|
+
if (this._onAllUnsubscribed) {
|
|
36
|
+
this._onAllUnsubscribed(event);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
this.emit = (event, ...args) => {
|
|
42
|
+
if (this._disabled)
|
|
43
|
+
return;
|
|
44
|
+
if (this.subscribers[event]) {
|
|
45
|
+
Object.values(this.subscribers[event]).forEach((c) => c(...args));
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
this.dispose = () => {
|
|
49
|
+
const events = Object.keys(this.subscribers);
|
|
50
|
+
this.subscribers = {};
|
|
51
|
+
this.counts = {};
|
|
52
|
+
events.forEach((event) => {
|
|
53
|
+
if (this._onAllUnsubscribed) {
|
|
54
|
+
this._onAllUnsubscribed(event);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
this.disable = () => {
|
|
59
|
+
this._disabled = true;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
get disabled() {
|
|
63
|
+
return this._disabled;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.EventSubscriber = EventSubscriber;
|
|
67
67
|
//# sourceMappingURL=EventSubscriber.js.map
|
package/dist/cjs/baseline.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare type DocumentBaseline<T extends any = any> = {
|
|
2
|
-
oid: string;
|
|
3
|
-
snapshot: T;
|
|
4
|
-
timestamp: string;
|
|
5
|
-
};
|
|
1
|
+
export declare type DocumentBaseline<T extends any = any> = {
|
|
2
|
+
oid: string;
|
|
3
|
+
snapshot: T;
|
|
4
|
+
timestamp: string;
|
|
5
|
+
};
|
package/dist/cjs/baseline.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=baseline.js.map
|
package/dist/cjs/batching.d.ts
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
export declare class Batcher<T, UserData = any> {
|
|
3
|
-
private flusher;
|
|
4
|
-
private batches;
|
|
5
|
-
constructor(flusher: (items: T[], batchKey: string, userData: UserData) => any);
|
|
6
|
-
add({ key, userData, items, max, timeout, }: {
|
|
7
|
-
key: string;
|
|
8
|
-
userData?: UserData;
|
|
9
|
-
items: T[];
|
|
10
|
-
max?: number | null;
|
|
11
|
-
timeout?: number | null;
|
|
12
|
-
}): Batch<T, UserData>;
|
|
13
|
-
flush: (key: string) => any;
|
|
14
|
-
discard: (key: string) => void;
|
|
15
|
-
}
|
|
16
|
-
export declare class Batch<T, UserData = any> {
|
|
17
|
-
items: Array<T>;
|
|
18
|
-
max: number | null;
|
|
19
|
-
startedAt: number;
|
|
20
|
-
timeout: number | null;
|
|
21
|
-
flushTimeout?: NodeJS.Timeout;
|
|
22
|
-
userData?: any;
|
|
23
|
-
flusher: (items: T[], batchKey: string, userData: UserData) => any;
|
|
24
|
-
key: string;
|
|
25
|
-
constructor({ max, startedAt, timeout, userData, flusher, key, }: {
|
|
26
|
-
key: string;
|
|
27
|
-
max: number | null;
|
|
28
|
-
startedAt: number;
|
|
29
|
-
timeout: number | null;
|
|
30
|
-
userData?: UserData;
|
|
31
|
-
flusher: (items: T[], batchKey: string, userData: UserData) => any;
|
|
32
|
-
});
|
|
33
|
-
update: ({ items, max, timeout, userData, }: {
|
|
34
|
-
items: Array<T>;
|
|
35
|
-
max?: number | null | undefined;
|
|
36
|
-
timeout?: number | null | undefined;
|
|
37
|
-
userData?: UserData | undefined;
|
|
38
|
-
}) => void;
|
|
39
|
-
flush: () => any;
|
|
40
|
-
discard: () => void;
|
|
41
|
-
}
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
export declare class Batcher<T, UserData = any> {
|
|
3
|
+
private flusher;
|
|
4
|
+
private batches;
|
|
5
|
+
constructor(flusher: (items: T[], batchKey: string, userData: UserData) => any);
|
|
6
|
+
add({ key, userData, items, max, timeout, }: {
|
|
7
|
+
key: string;
|
|
8
|
+
userData?: UserData;
|
|
9
|
+
items: T[];
|
|
10
|
+
max?: number | null;
|
|
11
|
+
timeout?: number | null;
|
|
12
|
+
}): Batch<T, UserData>;
|
|
13
|
+
flush: (key: string) => any;
|
|
14
|
+
discard: (key: string) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare class Batch<T, UserData = any> {
|
|
17
|
+
items: Array<T>;
|
|
18
|
+
max: number | null;
|
|
19
|
+
startedAt: number;
|
|
20
|
+
timeout: number | null;
|
|
21
|
+
flushTimeout?: NodeJS.Timeout;
|
|
22
|
+
userData?: any;
|
|
23
|
+
flusher: (items: T[], batchKey: string, userData: UserData) => any;
|
|
24
|
+
key: string;
|
|
25
|
+
constructor({ max, startedAt, timeout, userData, flusher, key, }: {
|
|
26
|
+
key: string;
|
|
27
|
+
max: number | null;
|
|
28
|
+
startedAt: number;
|
|
29
|
+
timeout: number | null;
|
|
30
|
+
userData?: UserData;
|
|
31
|
+
flusher: (items: T[], batchKey: string, userData: UserData) => any;
|
|
32
|
+
});
|
|
33
|
+
update: ({ items, max, timeout, userData, }: {
|
|
34
|
+
items: Array<T>;
|
|
35
|
+
max?: number | null | undefined;
|
|
36
|
+
timeout?: number | null | undefined;
|
|
37
|
+
userData?: UserData | undefined;
|
|
38
|
+
}) => void;
|
|
39
|
+
flush: () => any;
|
|
40
|
+
discard: () => void;
|
|
41
|
+
}
|
package/dist/cjs/batching.js
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Batch = exports.Batcher = void 0;
|
|
4
|
-
class Batcher {
|
|
5
|
-
constructor(flusher) {
|
|
6
|
-
this.flusher = flusher;
|
|
7
|
-
this.batches = new Map();
|
|
8
|
-
this.flush = (key) => {
|
|
9
|
-
const batch = this.batches.get(key);
|
|
10
|
-
if (!batch)
|
|
11
|
-
return;
|
|
12
|
-
return batch.flush();
|
|
13
|
-
};
|
|
14
|
-
this.discard = (key) => {
|
|
15
|
-
const batch = this.batches.get(key);
|
|
16
|
-
if (!batch)
|
|
17
|
-
return;
|
|
18
|
-
batch.discard();
|
|
19
|
-
this.batches.delete(key);
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
add({ key, userData, items, max, timeout, }) {
|
|
23
|
-
let batch = this.batches.get(key);
|
|
24
|
-
if (!batch) {
|
|
25
|
-
batch = new Batch({
|
|
26
|
-
max: max || null,
|
|
27
|
-
startedAt: Date.now(),
|
|
28
|
-
userData,
|
|
29
|
-
timeout: timeout || null,
|
|
30
|
-
flusher: this.flusher,
|
|
31
|
-
key,
|
|
32
|
-
});
|
|
33
|
-
this.batches.set(key, batch);
|
|
34
|
-
}
|
|
35
|
-
batch.update({
|
|
36
|
-
items,
|
|
37
|
-
max,
|
|
38
|
-
timeout,
|
|
39
|
-
userData,
|
|
40
|
-
});
|
|
41
|
-
return batch;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.Batcher = Batcher;
|
|
45
|
-
class Batch {
|
|
46
|
-
constructor({ max, startedAt, timeout, userData, flusher, key, }) {
|
|
47
|
-
this.items = [];
|
|
48
|
-
this.update = ({ items, max, timeout, userData, }) => {
|
|
49
|
-
this.items.push(...items);
|
|
50
|
-
if (max !== undefined)
|
|
51
|
-
this.max = max;
|
|
52
|
-
if (timeout !== undefined)
|
|
53
|
-
this.timeout = timeout;
|
|
54
|
-
if (userData)
|
|
55
|
-
this.userData = userData;
|
|
56
|
-
// if the batch has items and a timeout but has not
|
|
57
|
-
// scheduled yet, schedule it
|
|
58
|
-
const needsSchedule = this.items.length !== 0 && this.timeout !== null && !this.flushTimeout;
|
|
59
|
-
// if the batch has already reached its max, skip scheduling
|
|
60
|
-
// and flush immediately
|
|
61
|
-
if (this.max !== null && this.items.length >= this.max) {
|
|
62
|
-
this.flush();
|
|
63
|
-
}
|
|
64
|
-
else if (needsSchedule && this.timeout !== null) {
|
|
65
|
-
this.flushTimeout = setTimeout(this.flush, this.timeout);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
this.flush = () => {
|
|
69
|
-
this.flushTimeout && clearTimeout(this.flushTimeout);
|
|
70
|
-
this.flushTimeout = undefined;
|
|
71
|
-
const items = this.items;
|
|
72
|
-
this.items = [];
|
|
73
|
-
return this.flusher(items, this.key, this.userData);
|
|
74
|
-
};
|
|
75
|
-
this.discard = () => {
|
|
76
|
-
this.flushTimeout && clearTimeout(this.flushTimeout);
|
|
77
|
-
this.flushTimeout = undefined;
|
|
78
|
-
this.items = [];
|
|
79
|
-
};
|
|
80
|
-
this.max = max;
|
|
81
|
-
this.startedAt = startedAt;
|
|
82
|
-
this.timeout = timeout;
|
|
83
|
-
this.userData = userData;
|
|
84
|
-
this.flusher = flusher;
|
|
85
|
-
this.key = key;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.Batch = Batch;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Batch = exports.Batcher = void 0;
|
|
4
|
+
class Batcher {
|
|
5
|
+
constructor(flusher) {
|
|
6
|
+
this.flusher = flusher;
|
|
7
|
+
this.batches = new Map();
|
|
8
|
+
this.flush = (key) => {
|
|
9
|
+
const batch = this.batches.get(key);
|
|
10
|
+
if (!batch)
|
|
11
|
+
return;
|
|
12
|
+
return batch.flush();
|
|
13
|
+
};
|
|
14
|
+
this.discard = (key) => {
|
|
15
|
+
const batch = this.batches.get(key);
|
|
16
|
+
if (!batch)
|
|
17
|
+
return;
|
|
18
|
+
batch.discard();
|
|
19
|
+
this.batches.delete(key);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
add({ key, userData, items, max, timeout, }) {
|
|
23
|
+
let batch = this.batches.get(key);
|
|
24
|
+
if (!batch) {
|
|
25
|
+
batch = new Batch({
|
|
26
|
+
max: max || null,
|
|
27
|
+
startedAt: Date.now(),
|
|
28
|
+
userData,
|
|
29
|
+
timeout: timeout || null,
|
|
30
|
+
flusher: this.flusher,
|
|
31
|
+
key,
|
|
32
|
+
});
|
|
33
|
+
this.batches.set(key, batch);
|
|
34
|
+
}
|
|
35
|
+
batch.update({
|
|
36
|
+
items,
|
|
37
|
+
max,
|
|
38
|
+
timeout,
|
|
39
|
+
userData,
|
|
40
|
+
});
|
|
41
|
+
return batch;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.Batcher = Batcher;
|
|
45
|
+
class Batch {
|
|
46
|
+
constructor({ max, startedAt, timeout, userData, flusher, key, }) {
|
|
47
|
+
this.items = [];
|
|
48
|
+
this.update = ({ items, max, timeout, userData, }) => {
|
|
49
|
+
this.items.push(...items);
|
|
50
|
+
if (max !== undefined)
|
|
51
|
+
this.max = max;
|
|
52
|
+
if (timeout !== undefined)
|
|
53
|
+
this.timeout = timeout;
|
|
54
|
+
if (userData)
|
|
55
|
+
this.userData = userData;
|
|
56
|
+
// if the batch has items and a timeout but has not
|
|
57
|
+
// scheduled yet, schedule it
|
|
58
|
+
const needsSchedule = this.items.length !== 0 && this.timeout !== null && !this.flushTimeout;
|
|
59
|
+
// if the batch has already reached its max, skip scheduling
|
|
60
|
+
// and flush immediately
|
|
61
|
+
if (this.max !== null && this.items.length >= this.max) {
|
|
62
|
+
this.flush();
|
|
63
|
+
}
|
|
64
|
+
else if (needsSchedule && this.timeout !== null) {
|
|
65
|
+
this.flushTimeout = setTimeout(this.flush, this.timeout);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
this.flush = () => {
|
|
69
|
+
this.flushTimeout && clearTimeout(this.flushTimeout);
|
|
70
|
+
this.flushTimeout = undefined;
|
|
71
|
+
const items = this.items;
|
|
72
|
+
this.items = [];
|
|
73
|
+
return this.flusher(items, this.key, this.userData);
|
|
74
|
+
};
|
|
75
|
+
this.discard = () => {
|
|
76
|
+
this.flushTimeout && clearTimeout(this.flushTimeout);
|
|
77
|
+
this.flushTimeout = undefined;
|
|
78
|
+
this.items = [];
|
|
79
|
+
};
|
|
80
|
+
this.max = max;
|
|
81
|
+
this.startedAt = startedAt;
|
|
82
|
+
this.timeout = timeout;
|
|
83
|
+
this.userData = userData;
|
|
84
|
+
this.flusher = flusher;
|
|
85
|
+
this.key = key;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.Batch = Batch;
|
|
89
89
|
//# sourceMappingURL=batching.js.map
|
package/dist/cjs/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/cjs/files.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAllFileFields = exports.createFileRef = exports.isFileRef = void 0;
|
|
4
|
-
function isFileRef(value) {
|
|
5
|
-
return value && value['@@type'] === 'file';
|
|
6
|
-
}
|
|
7
|
-
exports.isFileRef = isFileRef;
|
|
8
|
-
function createFileRef(id) {
|
|
9
|
-
return {
|
|
10
|
-
'@@type': 'file',
|
|
11
|
-
id,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
exports.createFileRef = createFileRef;
|
|
15
|
-
function getAllFileFields(snapshot) {
|
|
16
|
-
return Object.entries(snapshot).filter((entry) => isFileRef(entry[1]));
|
|
17
|
-
}
|
|
18
|
-
exports.getAllFileFields = getAllFileFields;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllFileFields = exports.createFileRef = exports.isFileRef = void 0;
|
|
4
|
+
function isFileRef(value) {
|
|
5
|
+
return value && value['@@type'] === 'file';
|
|
6
|
+
}
|
|
7
|
+
exports.isFileRef = isFileRef;
|
|
8
|
+
function createFileRef(id) {
|
|
9
|
+
return {
|
|
10
|
+
'@@type': 'file',
|
|
11
|
+
id,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
exports.createFileRef = createFileRef;
|
|
15
|
+
function getAllFileFields(snapshot) {
|
|
16
|
+
return Object.entries(snapshot).filter((entry) => isFileRef(entry[1]));
|
|
17
|
+
}
|
|
18
|
+
exports.getAllFileFields = getAllFileFields;
|
|
19
19
|
//# sourceMappingURL=files.js.map
|
package/dist/cjs/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/cjs/index.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createDefaultMigration = exports.migrationRange = exports.migrate = void 0;
|
|
18
|
-
__exportStar(require("./protocol.js"), exports);
|
|
19
|
-
__exportStar(require("./timestamp.js"), exports);
|
|
20
|
-
__exportStar(require("./operation.js"), exports);
|
|
21
|
-
__exportStar(require("./baseline.js"), exports);
|
|
22
|
-
__exportStar(require("./replica.js"), exports);
|
|
23
|
-
__exportStar(require("./schema/index.js"), exports);
|
|
24
|
-
__exportStar(require("./utils.js"), exports);
|
|
25
|
-
__exportStar(require("./indexes.js"), exports);
|
|
26
|
-
var migration_js_1 = require("./migration.js");
|
|
27
|
-
Object.defineProperty(exports, "migrate", { enumerable: true, get: function () { return migration_js_1.migrate; } });
|
|
28
|
-
Object.defineProperty(exports, "migrationRange", { enumerable: true, get: function () { return migration_js_1.migrationRange; } });
|
|
29
|
-
Object.defineProperty(exports, "createDefaultMigration", { enumerable: true, get: function () { return migration_js_1.createDefaultMigration; } });
|
|
30
|
-
__exportStar(require("./patch.js"), exports);
|
|
31
|
-
__exportStar(require("./oids.js"), exports);
|
|
32
|
-
__exportStar(require("./EventSubscriber.js"), exports);
|
|
33
|
-
__exportStar(require("./undo.js"), exports);
|
|
34
|
-
__exportStar(require("./batching.js"), exports);
|
|
35
|
-
__exportStar(require("./files.js"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createDefaultMigration = exports.migrationRange = exports.migrate = void 0;
|
|
18
|
+
__exportStar(require("./protocol.js"), exports);
|
|
19
|
+
__exportStar(require("./timestamp.js"), exports);
|
|
20
|
+
__exportStar(require("./operation.js"), exports);
|
|
21
|
+
__exportStar(require("./baseline.js"), exports);
|
|
22
|
+
__exportStar(require("./replica.js"), exports);
|
|
23
|
+
__exportStar(require("./schema/index.js"), exports);
|
|
24
|
+
__exportStar(require("./utils.js"), exports);
|
|
25
|
+
__exportStar(require("./indexes.js"), exports);
|
|
26
|
+
var migration_js_1 = require("./migration.js");
|
|
27
|
+
Object.defineProperty(exports, "migrate", { enumerable: true, get: function () { return migration_js_1.migrate; } });
|
|
28
|
+
Object.defineProperty(exports, "migrationRange", { enumerable: true, get: function () { return migration_js_1.migrationRange; } });
|
|
29
|
+
Object.defineProperty(exports, "createDefaultMigration", { enumerable: true, get: function () { return migration_js_1.createDefaultMigration; } });
|
|
30
|
+
__exportStar(require("./patch.js"), exports);
|
|
31
|
+
__exportStar(require("./oids.js"), exports);
|
|
32
|
+
__exportStar(require("./EventSubscriber.js"), exports);
|
|
33
|
+
__exportStar(require("./undo.js"), exports);
|
|
34
|
+
__exportStar(require("./batching.js"), exports);
|
|
35
|
+
__exportStar(require("./files.js"), exports);
|
|
36
36
|
//# sourceMappingURL=index.js.map
|