@verdant-web/common 1.15.3-next.0 → 1.15.4

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.
Files changed (154) hide show
  1. package/dist/cjs/EventSubscriber.d.ts +17 -17
  2. package/dist/cjs/EventSubscriber.js +66 -66
  3. package/dist/cjs/baseline.d.ts +5 -5
  4. package/dist/cjs/baseline.js +2 -2
  5. package/dist/cjs/batching.d.ts +42 -42
  6. package/dist/cjs/batching.js +91 -91
  7. package/dist/cjs/files.d.ts +19 -19
  8. package/dist/cjs/files.js +18 -18
  9. package/dist/cjs/index.d.ts +19 -19
  10. package/dist/cjs/index.js +41 -41
  11. package/dist/cjs/indexes.d.ts +17 -17
  12. package/dist/cjs/indexes.js +142 -142
  13. package/dist/cjs/indexes.test.d.ts +1 -1
  14. package/dist/cjs/indexes.test.js +127 -127
  15. package/dist/cjs/migration.d.ts +172 -172
  16. package/dist/cjs/migration.js +301 -301
  17. package/dist/cjs/oids.d.ts +100 -100
  18. package/dist/cjs/oids.js +461 -457
  19. package/dist/cjs/oids.js.map +1 -1
  20. package/dist/cjs/oids.test.d.ts +1 -1
  21. package/dist/cjs/oids.test.js +348 -348
  22. package/dist/cjs/operation.d.ts +139 -139
  23. package/dist/cjs/operation.js +545 -545
  24. package/dist/cjs/operation.test.d.ts +1 -1
  25. package/dist/cjs/operation.test.js +529 -529
  26. package/dist/cjs/patch.d.ts +26 -26
  27. package/dist/cjs/patch.js +226 -226
  28. package/dist/cjs/presence.d.ts +27 -27
  29. package/dist/cjs/presence.js +2 -2
  30. package/dist/cjs/protocol.d.ts +145 -145
  31. package/dist/cjs/protocol.js +3 -3
  32. package/dist/cjs/refs.d.ts +7 -7
  33. package/dist/cjs/refs.js +29 -29
  34. package/dist/cjs/replica.d.ts +28 -28
  35. package/dist/cjs/replica.js +28 -28
  36. package/dist/cjs/schema/defaults.test.d.ts +1 -1
  37. package/dist/cjs/schema/defaults.test.js +20 -20
  38. package/dist/cjs/schema/fields.d.ts +9 -9
  39. package/dist/cjs/schema/fields.js +144 -144
  40. package/dist/cjs/schema/index.d.ts +8 -8
  41. package/dist/cjs/schema/index.js +51 -51
  42. package/dist/cjs/schema/indexFilters.d.ts +6 -6
  43. package/dist/cjs/schema/indexFilters.js +30 -30
  44. package/dist/cjs/schema/types/collection.d.ts +23 -23
  45. package/dist/cjs/schema/types/collection.js +2 -2
  46. package/dist/cjs/schema/types/compounds.d.ts +11 -11
  47. package/dist/cjs/schema/types/compounds.js +2 -2
  48. package/dist/cjs/schema/types/fields.d.ts +75 -75
  49. package/dist/cjs/schema/types/fields.js +2 -2
  50. package/dist/cjs/schema/types/filters.d.ts +29 -29
  51. package/dist/cjs/schema/types/filters.js +2 -2
  52. package/dist/cjs/schema/types/shapes.d.ts +21 -21
  53. package/dist/cjs/schema/types/shapes.js +2 -2
  54. package/dist/cjs/schema/types/synthetics.d.ts +37 -37
  55. package/dist/cjs/schema/types/synthetics.js +2 -2
  56. package/dist/cjs/schema/types.d.ts +18 -18
  57. package/dist/cjs/schema/types.js +22 -22
  58. package/dist/cjs/schema/validation.d.ts +3 -3
  59. package/dist/cjs/schema/validation.js +86 -86
  60. package/dist/cjs/timestamp.d.ts +50 -50
  61. package/dist/cjs/timestamp.js +251 -251
  62. package/dist/cjs/timestamp.test.d.ts +1 -1
  63. package/dist/cjs/timestamp.test.js +104 -104
  64. package/dist/cjs/undo.d.ts +3 -3
  65. package/dist/cjs/undo.js +198 -198
  66. package/dist/cjs/utils.d.ts +20 -20
  67. package/dist/cjs/utils.js +145 -145
  68. package/dist/cjs/utils.test.d.ts +1 -1
  69. package/dist/cjs/utils.test.js +36 -36
  70. package/dist/esm/EventSubscriber.d.ts +17 -17
  71. package/dist/esm/EventSubscriber.js +62 -62
  72. package/dist/esm/baseline.d.ts +5 -5
  73. package/dist/esm/baseline.js +1 -1
  74. package/dist/esm/batching.d.ts +42 -42
  75. package/dist/esm/batching.js +86 -86
  76. package/dist/esm/files.d.ts +19 -19
  77. package/dist/esm/files.js +12 -12
  78. package/dist/esm/index.d.ts +19 -19
  79. package/dist/esm/index.js +16 -16
  80. package/dist/esm/indexes.d.ts +17 -17
  81. package/dist/esm/indexes.js +130 -130
  82. package/dist/esm/indexes.test.d.ts +1 -1
  83. package/dist/esm/indexes.test.js +125 -125
  84. package/dist/esm/migration.d.ts +172 -172
  85. package/dist/esm/migration.js +294 -294
  86. package/dist/esm/oids.d.ts +100 -100
  87. package/dist/esm/oids.js +426 -422
  88. package/dist/esm/oids.js.map +1 -1
  89. package/dist/esm/oids.test.d.ts +1 -1
  90. package/dist/esm/oids.test.js +346 -346
  91. package/dist/esm/operation.d.ts +139 -139
  92. package/dist/esm/operation.js +530 -530
  93. package/dist/esm/operation.test.d.ts +1 -1
  94. package/dist/esm/operation.test.js +527 -527
  95. package/dist/esm/patch.d.ts +26 -26
  96. package/dist/esm/patch.js +222 -222
  97. package/dist/esm/presence.d.ts +27 -27
  98. package/dist/esm/presence.js +1 -1
  99. package/dist/esm/protocol.d.ts +145 -145
  100. package/dist/esm/protocol.js +2 -2
  101. package/dist/esm/refs.d.ts +7 -7
  102. package/dist/esm/refs.js +22 -22
  103. package/dist/esm/replica.d.ts +28 -28
  104. package/dist/esm/replica.js +25 -25
  105. package/dist/esm/schema/defaults.test.d.ts +1 -1
  106. package/dist/esm/schema/defaults.test.js +18 -18
  107. package/dist/esm/schema/fields.d.ts +9 -9
  108. package/dist/esm/schema/fields.js +133 -133
  109. package/dist/esm/schema/index.d.ts +8 -8
  110. package/dist/esm/schema/index.js +32 -32
  111. package/dist/esm/schema/indexFilters.d.ts +6 -6
  112. package/dist/esm/schema/indexFilters.js +22 -22
  113. package/dist/esm/schema/types/collection.d.ts +23 -23
  114. package/dist/esm/schema/types/collection.js +1 -1
  115. package/dist/esm/schema/types/compounds.d.ts +11 -11
  116. package/dist/esm/schema/types/compounds.js +1 -1
  117. package/dist/esm/schema/types/fields.d.ts +75 -75
  118. package/dist/esm/schema/types/fields.js +1 -1
  119. package/dist/esm/schema/types/filters.d.ts +29 -29
  120. package/dist/esm/schema/types/filters.js +1 -1
  121. package/dist/esm/schema/types/shapes.d.ts +21 -21
  122. package/dist/esm/schema/types/shapes.js +1 -1
  123. package/dist/esm/schema/types/synthetics.d.ts +37 -37
  124. package/dist/esm/schema/types/synthetics.js +1 -1
  125. package/dist/esm/schema/types.d.ts +18 -18
  126. package/dist/esm/schema/types.js +6 -6
  127. package/dist/esm/schema/validation.d.ts +3 -3
  128. package/dist/esm/schema/validation.js +81 -81
  129. package/dist/esm/timestamp.d.ts +50 -50
  130. package/dist/esm/timestamp.js +234 -234
  131. package/dist/esm/timestamp.test.d.ts +1 -1
  132. package/dist/esm/timestamp.test.js +102 -102
  133. package/dist/esm/undo.d.ts +3 -3
  134. package/dist/esm/undo.js +194 -194
  135. package/dist/esm/utils.d.ts +20 -20
  136. package/dist/esm/utils.js +127 -127
  137. package/dist/esm/utils.test.d.ts +1 -1
  138. package/dist/esm/utils.test.js +34 -34
  139. package/dist/tsconfig-cjs.tsbuildinfo +1 -1
  140. package/dist/tsconfig.tsbuildinfo +1 -1
  141. package/package.json +1 -1
  142. package/src/oids.ts +5 -1
  143. package/dist/cjs/files.test.d.ts +0 -1
  144. package/dist/cjs/files.test.js +0 -81
  145. package/dist/cjs/files.test.js.map +0 -1
  146. package/dist/cjs/schema/defaults.d.ts +0 -4
  147. package/dist/cjs/schema/defaults.js +0 -72
  148. package/dist/cjs/schema/defaults.js.map +0 -1
  149. package/dist/esm/files.test.d.ts +0 -1
  150. package/dist/esm/files.test.js +0 -79
  151. package/dist/esm/files.test.js.map +0 -1
  152. package/dist/esm/schema/defaults.d.ts +0 -4
  153. package/dist/esm/schema/defaults.js +0 -66
  154. package/dist/esm/schema/defaults.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
@@ -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
+ };
@@ -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
@@ -1,42 +1,42 @@
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
- flushAll: () => any[];
16
- }
17
- export declare class Batch<T, UserData = any> {
18
- items: Array<T>;
19
- max: number | null;
20
- startedAt: number;
21
- timeout: number | null;
22
- flushTimeout?: NodeJS.Timeout;
23
- userData?: any;
24
- flusher: (items: T[], batchKey: string, userData: UserData) => any;
25
- key: string;
26
- constructor({ max, startedAt, timeout, userData, flusher, key, }: {
27
- key: string;
28
- max: number | null;
29
- startedAt: number;
30
- timeout: number | null;
31
- userData?: UserData;
32
- flusher: (items: T[], batchKey: string, userData: UserData) => any;
33
- });
34
- update: ({ items, max, timeout, userData, }: {
35
- items: Array<T>;
36
- max?: number | null | undefined;
37
- timeout?: number | null | undefined;
38
- userData?: UserData | undefined;
39
- }) => void;
40
- flush: () => any;
41
- discard: () => void;
42
- }
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
+ flushAll: () => any[];
16
+ }
17
+ export declare class Batch<T, UserData = any> {
18
+ items: Array<T>;
19
+ max: number | null;
20
+ startedAt: number;
21
+ timeout: number | null;
22
+ flushTimeout?: NodeJS.Timeout;
23
+ userData?: any;
24
+ flusher: (items: T[], batchKey: string, userData: UserData) => any;
25
+ key: string;
26
+ constructor({ max, startedAt, timeout, userData, flusher, key, }: {
27
+ key: string;
28
+ max: number | null;
29
+ startedAt: number;
30
+ timeout: number | null;
31
+ userData?: UserData;
32
+ flusher: (items: T[], batchKey: string, userData: UserData) => any;
33
+ });
34
+ update: ({ items, max, timeout, userData, }: {
35
+ items: Array<T>;
36
+ max?: number | null | undefined;
37
+ timeout?: number | null | undefined;
38
+ userData?: UserData | undefined;
39
+ }) => void;
40
+ flush: () => any;
41
+ discard: () => void;
42
+ }
@@ -1,92 +1,92 @@
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
- this.flushAll = () => {
22
- return [...this.batches.values()].map((batch) => batch.flush());
23
- };
24
- }
25
- add({ key, userData, items, max, timeout, }) {
26
- let batch = this.batches.get(key);
27
- if (!batch) {
28
- batch = new Batch({
29
- max: max || null,
30
- startedAt: Date.now(),
31
- userData,
32
- timeout: timeout || null,
33
- flusher: this.flusher,
34
- key,
35
- });
36
- this.batches.set(key, batch);
37
- }
38
- batch.update({
39
- items,
40
- max,
41
- timeout,
42
- userData,
43
- });
44
- return batch;
45
- }
46
- }
47
- exports.Batcher = Batcher;
48
- class Batch {
49
- constructor({ max, startedAt, timeout, userData, flusher, key, }) {
50
- this.items = [];
51
- this.update = ({ items, max, timeout, userData, }) => {
52
- this.items.push(...items);
53
- if (max !== undefined)
54
- this.max = max;
55
- if (timeout !== undefined)
56
- this.timeout = timeout;
57
- if (userData)
58
- this.userData = userData;
59
- // if the batch has items and a timeout but has not
60
- // scheduled yet, schedule it
61
- const needsSchedule = this.items.length !== 0 && this.timeout !== null && !this.flushTimeout;
62
- // if the batch has already reached its max, skip scheduling
63
- // and flush immediately
64
- if (this.max !== null && this.items.length >= this.max) {
65
- this.flush();
66
- }
67
- else if (needsSchedule && this.timeout !== null) {
68
- this.flushTimeout = setTimeout(this.flush, this.timeout);
69
- }
70
- };
71
- this.flush = () => {
72
- this.flushTimeout && clearTimeout(this.flushTimeout);
73
- this.flushTimeout = undefined;
74
- const items = this.items;
75
- this.items = [];
76
- return this.flusher(items, this.key, this.userData);
77
- };
78
- this.discard = () => {
79
- this.flushTimeout && clearTimeout(this.flushTimeout);
80
- this.flushTimeout = undefined;
81
- this.items = [];
82
- };
83
- this.max = max;
84
- this.startedAt = startedAt;
85
- this.timeout = timeout;
86
- this.userData = userData;
87
- this.flusher = flusher;
88
- this.key = key;
89
- }
90
- }
91
- 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
+ this.flushAll = () => {
22
+ return [...this.batches.values()].map((batch) => batch.flush());
23
+ };
24
+ }
25
+ add({ key, userData, items, max, timeout, }) {
26
+ let batch = this.batches.get(key);
27
+ if (!batch) {
28
+ batch = new Batch({
29
+ max: max || null,
30
+ startedAt: Date.now(),
31
+ userData,
32
+ timeout: timeout || null,
33
+ flusher: this.flusher,
34
+ key,
35
+ });
36
+ this.batches.set(key, batch);
37
+ }
38
+ batch.update({
39
+ items,
40
+ max,
41
+ timeout,
42
+ userData,
43
+ });
44
+ return batch;
45
+ }
46
+ }
47
+ exports.Batcher = Batcher;
48
+ class Batch {
49
+ constructor({ max, startedAt, timeout, userData, flusher, key, }) {
50
+ this.items = [];
51
+ this.update = ({ items, max, timeout, userData, }) => {
52
+ this.items.push(...items);
53
+ if (max !== undefined)
54
+ this.max = max;
55
+ if (timeout !== undefined)
56
+ this.timeout = timeout;
57
+ if (userData)
58
+ this.userData = userData;
59
+ // if the batch has items and a timeout but has not
60
+ // scheduled yet, schedule it
61
+ const needsSchedule = this.items.length !== 0 && this.timeout !== null && !this.flushTimeout;
62
+ // if the batch has already reached its max, skip scheduling
63
+ // and flush immediately
64
+ if (this.max !== null && this.items.length >= this.max) {
65
+ this.flush();
66
+ }
67
+ else if (needsSchedule && this.timeout !== null) {
68
+ this.flushTimeout = setTimeout(this.flush, this.timeout);
69
+ }
70
+ };
71
+ this.flush = () => {
72
+ this.flushTimeout && clearTimeout(this.flushTimeout);
73
+ this.flushTimeout = undefined;
74
+ const items = this.items;
75
+ this.items = [];
76
+ return this.flusher(items, this.key, this.userData);
77
+ };
78
+ this.discard = () => {
79
+ this.flushTimeout && clearTimeout(this.flushTimeout);
80
+ this.flushTimeout = undefined;
81
+ this.items = [];
82
+ };
83
+ this.max = max;
84
+ this.startedAt = startedAt;
85
+ this.timeout = timeout;
86
+ this.userData = userData;
87
+ this.flusher = flusher;
88
+ this.key = key;
89
+ }
90
+ }
91
+ exports.Batch = Batch;
92
92
  //# sourceMappingURL=batching.js.map
@@ -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
@@ -1,19 +1,19 @@
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, createMigration, } 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';
19
- export { makeObjectRef, makeFileRef, isRef, compareRefs } 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, createMigration, } 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';
19
+ export { makeObjectRef, makeFileRef, isRef, compareRefs } from './refs.js';