@r146023/omniturbo 0.1.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.
Files changed (107) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +320 -0
  3. package/dist/Omni.d.ts +82 -0
  4. package/dist/Omni.d.ts.map +1 -0
  5. package/dist/Omni.js +477 -0
  6. package/dist/Omni.js.map +1 -0
  7. package/dist/aliases/AliasRegistry.d.ts +8 -0
  8. package/dist/aliases/AliasRegistry.d.ts.map +1 -0
  9. package/dist/aliases/AliasRegistry.js +29 -0
  10. package/dist/aliases/AliasRegistry.js.map +1 -0
  11. package/dist/batch/batch.d.ts +4 -0
  12. package/dist/batch/batch.d.ts.map +1 -0
  13. package/dist/batch/batch.js +17 -0
  14. package/dist/batch/batch.js.map +1 -0
  15. package/dist/core/equality.d.ts +6 -0
  16. package/dist/core/equality.d.ts.map +1 -0
  17. package/dist/core/equality.js +43 -0
  18. package/dist/core/equality.js.map +1 -0
  19. package/dist/core/ids.d.ts +5 -0
  20. package/dist/core/ids.d.ts.map +1 -0
  21. package/dist/core/ids.js +6 -0
  22. package/dist/core/ids.js.map +1 -0
  23. package/dist/core/object.d.ts +49 -0
  24. package/dist/core/object.d.ts.map +1 -0
  25. package/dist/core/object.js +134 -0
  26. package/dist/core/object.js.map +1 -0
  27. package/dist/core/path.d.ts +9 -0
  28. package/dist/core/path.d.ts.map +1 -0
  29. package/dist/core/path.js +46 -0
  30. package/dist/core/path.js.map +1 -0
  31. package/dist/datatypes/DataTypeRegistry.d.ts +10 -0
  32. package/dist/datatypes/DataTypeRegistry.d.ts.map +1 -0
  33. package/dist/datatypes/DataTypeRegistry.js +27 -0
  34. package/dist/datatypes/DataTypeRegistry.js.map +1 -0
  35. package/dist/datatypes/builtins.d.ts +3 -0
  36. package/dist/datatypes/builtins.d.ts.map +1 -0
  37. package/dist/datatypes/builtins.js +41 -0
  38. package/dist/datatypes/builtins.js.map +1 -0
  39. package/dist/history/history.d.ts +4 -0
  40. package/dist/history/history.d.ts.map +1 -0
  41. package/dist/history/history.js +22 -0
  42. package/dist/history/history.js.map +1 -0
  43. package/dist/history/timeline.d.ts +11 -0
  44. package/dist/history/timeline.d.ts.map +1 -0
  45. package/dist/history/timeline.js +22 -0
  46. package/dist/history/timeline.js.map +1 -0
  47. package/dist/index.d.ts +14 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +14 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/privacy/PrivacyRegistry.d.ts +22 -0
  52. package/dist/privacy/PrivacyRegistry.d.ts.map +1 -0
  53. package/dist/privacy/PrivacyRegistry.js +84 -0
  54. package/dist/privacy/PrivacyRegistry.js.map +1 -0
  55. package/dist/privacy/writeTokens.d.ts +15 -0
  56. package/dist/privacy/writeTokens.d.ts.map +1 -0
  57. package/dist/privacy/writeTokens.js +23 -0
  58. package/dist/privacy/writeTokens.js.map +1 -0
  59. package/dist/result/resultFactories.d.ts +28 -0
  60. package/dist/result/resultFactories.d.ts.map +1 -0
  61. package/dist/result/resultFactories.js +30 -0
  62. package/dist/result/resultFactories.js.map +1 -0
  63. package/dist/schema/SchemaRegistry.d.ts +33 -0
  64. package/dist/schema/SchemaRegistry.d.ts.map +1 -0
  65. package/dist/schema/SchemaRegistry.js +90 -0
  66. package/dist/schema/SchemaRegistry.js.map +1 -0
  67. package/dist/schema/schemaDefaults.d.ts +3 -0
  68. package/dist/schema/schemaDefaults.d.ts.map +1 -0
  69. package/dist/schema/schemaDefaults.js +6 -0
  70. package/dist/schema/schemaDefaults.js.map +1 -0
  71. package/dist/schema/schemaValidation.d.ts +20 -0
  72. package/dist/schema/schemaValidation.d.ts.map +1 -0
  73. package/dist/schema/schemaValidation.js +80 -0
  74. package/dist/schema/schemaValidation.js.map +1 -0
  75. package/dist/subscriptions/subscriptions.d.ts +341 -0
  76. package/dist/subscriptions/subscriptions.d.ts.map +1 -0
  77. package/dist/subscriptions/subscriptions.js +373 -0
  78. package/dist/subscriptions/subscriptions.js.map +1 -0
  79. package/dist/types/datatype_types.d.ts +25 -0
  80. package/dist/types/datatype_types.d.ts.map +1 -0
  81. package/dist/types/datatype_types.js +3 -0
  82. package/dist/types/datatype_types.js.map +1 -0
  83. package/dist/types/issue_types.d.ts +14 -0
  84. package/dist/types/issue_types.d.ts.map +1 -0
  85. package/dist/types/issue_types.js +2 -0
  86. package/dist/types/issue_types.js.map +1 -0
  87. package/dist/types/options_types.d.ts +48 -0
  88. package/dist/types/options_types.d.ts.map +1 -0
  89. package/dist/types/options_types.js +2 -0
  90. package/dist/types/options_types.js.map +1 -0
  91. package/dist/types/privacy_types.d.ts +22 -0
  92. package/dist/types/privacy_types.d.ts.map +1 -0
  93. package/dist/types/privacy_types.js +2 -0
  94. package/dist/types/privacy_types.js.map +1 -0
  95. package/dist/types/result_types.d.ts +20 -0
  96. package/dist/types/result_types.d.ts.map +1 -0
  97. package/dist/types/result_types.js +2 -0
  98. package/dist/types/result_types.js.map +1 -0
  99. package/dist/types/schema_types.d.ts +35 -0
  100. package/dist/types/schema_types.d.ts.map +1 -0
  101. package/dist/types/schema_types.js +2 -0
  102. package/dist/types/schema_types.js.map +1 -0
  103. package/dist/types/store_types.d.ts +37 -0
  104. package/dist/types/store_types.d.ts.map +1 -0
  105. package/dist/types/store_types.js +2 -0
  106. package/dist/types/store_types.js.map +1 -0
  107. package/package.json +41 -0
@@ -0,0 +1,373 @@
1
+ import { generateFastId } from "../core/ids";
2
+ import { getParentPaths, normalizePath } from "../core/path";
3
+ /**
4
+ * ## Subscription Registry
5
+ *
6
+ * The SubscriptionRegistry class manages all subscribers, alerts, and coercers for the Omni data
7
+ * store. It allows for registering direct subscribers for specific paths, tree subscribers for path
8
+ * prefixes, and global subscribers that listen to all changes. It also handles alerts that can be
9
+ * triggered during set operations and coercers that can transform values before they are set. The
10
+ * registry provides methods to subscribe, notify changes, trigger alerts, and manage coercers,
11
+ * ensuring that all relevant functions are called appropriately based on the paths and options
12
+ * specified.
13
+ *
14
+ */
15
+ export class SubscriptionRegistry {
16
+ constructor() {
17
+ this.directSubs = new Map();
18
+ this.treeSubs = new Map();
19
+ this.globalSubscribers = new Map();
20
+ this.alerts = new Map();
21
+ this.coercers = new Map();
22
+ }
23
+ /**
24
+ * Registers a direct subscriber function for a specific path. Direct subscribers are functions
25
+ * that will be called only when a change occurs at the exact specified path. The subscriber
26
+ * function will receive the normalized path, new value, and old value as arguments whenever a
27
+ * change occurs at that path. Direct subscribers are useful for reacting to changes at specific
28
+ * paths without being triggered by changes at parent or child paths. The path will be normalized
29
+ * before storing, so it will match the normalized paths used when notifying changes. This method
30
+ * returns a function that can be called to remove the registered subscriber when it is no longer
31
+ * needed.
32
+ *
33
+ * @param path The path for which to register the direct subscriber. This will be normalized
34
+ * before storing, so it should be in a format that can be normalized (e.g., using dot notation).
35
+ * The subscriber will only be triggered for changes at this exact path, and not for changes at
36
+ * parent or child paths. This allows for precise reactions to changes at specific locations in
37
+ * the data store.
38
+ * @param callback The subscriber function that will be called when a change occurs at the
39
+ * specified path. It should have the signature `(path: string, newValue: unknown, oldValue:
40
+ * unknown) => void`, where `path` is the normalized path where the change occurred, `newValue` is
41
+ * the new value at that path, and `oldValue` is the previous value at that path (if any). The
42
+ * subscriber can use these arguments to react to changes at this specific path.
43
+ * @param type Optional timing for the subscriber, either "PRE" or "POST". This determines whether
44
+ * the subscriber is called before or after tree subscribers for parent paths are called. The
45
+ * default is "POST", meaning the direct subscriber will be called after tree subscribers. If set
46
+ * to "PRE", the direct subscriber will be called before tree subscribers. This can be useful for
47
+ * certain use cases where you want to react to changes at this path before other subscribers are
48
+ * notified.
49
+ * @returns A function that can be called to remove the registered direct subscriber. When called,
50
+ * it will unregister the subscriber so it will no longer be triggered for future changes at the
51
+ * specified path.
52
+ *
53
+ */
54
+ subscribe(path, callback, type = "POST") {
55
+ const normalized = normalizePath(path);
56
+ const id = generateFastId("sub");
57
+ let bucket = this.directSubs.get(normalized);
58
+ if (!bucket)
59
+ this.directSubs.set(normalized, (bucket = new Map()));
60
+ bucket.set(id, { id, fn: callback, type: type === "PRE" ? 0 : 1 });
61
+ return () => bucket?.delete(id);
62
+ }
63
+ /**
64
+ * Retrieves the direct subscriber bucket for a specific path. This method returns the map of
65
+ * direct subscribers that are registered for the exact given path. The path will be normalized
66
+ * before looking up, so it will match the normalized paths used when subscribers are registered.
67
+ * The returned bucket contains subscribers that will be triggered only for changes at this exact
68
+ * path, and it does not include subscribers that are registered for parent paths (tree
69
+ * subscribers) or global subscribers. This method can be used internally when notifying changes
70
+ * at a specific path to access the direct subscribers that need to be triggered. If there are no
71
+ * direct subscribers for the given path, this method will return undefined.
72
+ *
73
+ * @param path The path for which to retrieve the direct subscriber bucket. This will be
74
+ * normalized before looking up. The returned bucket contains subscribers that are registered for
75
+ * this exact path, and it does not include tree subscribers or global subscribers. This can be
76
+ * used internally to access the direct subscribers when notifying changes at a specific path. If
77
+ * there are no direct subscribers for the given path, this method will return undefined.
78
+ * @returns A Map of direct subscribers for the specified path, or undefined if there are no
79
+ * direct subscribers registered for that path. The keys of the Map are subscriber IDs, and the
80
+ * values are OmniSubscriber objects containing the subscriber function and metadata. This bucket
81
+ * will only include subscribers that are registered for this exact path, and it does not include
82
+ * tree subscribers or global subscribers.
83
+ */
84
+ getDirectBucket(path) {
85
+ return this.directSubs.get(normalizePath(path));
86
+ }
87
+ /**
88
+ * Registers a tree subscriber function for a specific path prefix. Tree subscribers are functions
89
+ * that will be called for changes at any path that starts with the specified prefix. This allows for
90
+ * reacting to changes in an entire subtree of the data store without needing to register individual
91
+ * subscribers for each path. The subscriber function will receive the parent path (the prefix), the
92
+ * full path where the change occurred, the new value, and the old value as arguments whenever a change
93
+ * occurs at any path that matches the prefix. Tree subscribers can be useful for monitoring changes in a
94
+ *
95
+ * @param prefix The path prefix for which to register the tree subscriber. This will be normalized before storing.
96
+ * @param callback The tree subscriber function that will be called when a change occurs at any path that starts with the specified prefix. It should have the signature `(parentPath: string, fullPath: string, newValue: unknown, oldValue: unknown) => void`, where `parentPath` is the normalized prefix path, `fullPath` is the normalized path where the change occurred, `newValue` is the new value at that path, and `oldValue` is the previous value at that path (if any). The subscriber can use these arguments to react to changes in the subtree of paths that match the prefix.
97
+ * @param type Optional timing for the subscriber, either "PRE" or "POST". This determines whether the subscriber is called before or after direct subscribers for the exact path are called. The default is "POST", meaning the tree subscriber will be called after direct subscribers. If set to "PRE", the tree subscriber will be called before direct subscribers. This can be useful for certain use cases where you want to react to changes before other subscribers are notified.
98
+ * @returns A function that can be called to remove the registered tree subscriber. When called, it will unregister the subscriber so it will no longer be triggered for future changes at paths that match the specified prefix.
99
+ */
100
+ subscribeTree(prefix, callback, type = "POST") {
101
+ const normalized = normalizePath(prefix);
102
+ const id = generateFastId("treesub");
103
+ let bucket = this.treeSubs.get(normalized);
104
+ if (!bucket)
105
+ this.treeSubs.set(normalized, (bucket = new Map()));
106
+ bucket.set(id, { id, fn: callback, type: type === "PRE" ? 0 : 1 });
107
+ return () => bucket?.delete(id);
108
+ }
109
+ /**
110
+ * Registers a global subscriber function that will be called for every change at any path. Global
111
+ * subscribers are useful for logging, debugging, or any functionality that needs to react to all
112
+ * changes in the data store. They can have optional throttling to limit how often they are
113
+ * triggered, and they can also be set to trigger only once. The subscriber function will receive
114
+ * the path, new value, and old value as arguments whenever a change occurs.
115
+ *
116
+ * ## Be Cautious
117
+ * Global subscribers can have a significant performance impact if they perform heavy computations
118
+ * or Listening to every path in the store will trigger damn near constant calls to the
119
+ * subscriber, so it's important to use them judiciously and ensure that the subscriber function
120
+ * is optimized for performance. Consider using throttling or the `once` option to mitigate
121
+ * potential performance issues when using global subscribers.
122
+ *
123
+ *
124
+ * @param fn The subscriber function to register as a global subscriber. It should have the
125
+ * signature
126
+ * @param options Optional settings for the global subscriber:
127
+ * @returns A function that can be called to remove the registered global subscriber. When called,
128
+ * it will
129
+ */
130
+ subscribeGlobal(fn, options = {}) {
131
+ const id = generateFastId("globalsub");
132
+ this.globalSubscribers.set(id, { id, fn, throttle: options.throttle, once: options.once, lastTrigger: 0 });
133
+ return () => this.globalSubscribers.delete(id);
134
+ }
135
+ /**
136
+ * Notifies subscribers of a change at a specific path. This method is responsible for triggering
137
+ * all relevant subscribers when a value changes at a given path. It will notify direct
138
+ * subscribers for the exact path, tree subscribers for any parent paths, and global subscribers
139
+ * for all changes. The notification includes the new value, old value, and the normalized path.
140
+ * Subscribers with the `once` option will be automatically unregistered after being triggered.
141
+ * Global subscribers can also have throttling to limit how often they are triggered.
142
+ * @param path The path where the change occurred. This will be normalized before looking up
143
+ * subscribers. Subscribers
144
+ * @param value The new value that has been set at the specified path. This is passed to
145
+ * subscriber functions as an argument, along with the old value and path. Subscribers can use
146
+ * this value in their logic to respond to the change.
147
+ * @param oldValue The previous value at the specified path before the change. This is passed to
148
+ * subscriber functions as an argument, along with the new value and path. Subscribers can use
149
+ * this value in their logic to compare against the new value or perform actions based on what
150
+ * changed. It can be undefined if there was no previous value.
151
+ * @param getParentValue A function that can be called to retrieve the current value of a parent
152
+ * path. This is used when notifying tree subscribers and when the `parentNotifications` option is
153
+ * enabled, allowing subscribers to get the current value of parent paths without needing to
154
+ * access the main data store directly. The function takes a parent path as an argument and
155
+ * returns the current value at that path.
156
+ * @param parentNotifications A boolean flag that indicates whether to notify direct subscribers
157
+ * of parent paths about changes to their child paths. If true, then when a change occurs at a
158
+ * path, direct subscribers for all parent paths will also be notified with the current value of
159
+ * the parent path. This allows for more comprehensive notifications but can result in more
160
+ * subscriber calls, so it should be used based on the needs of the application.
161
+ * @returns void
162
+ * @remarks This method is typically called internally by the set operation after a value has been
163
+ * changed, to ensure that all relevant subscribers are notified of the change. It handles the
164
+ * logic for determining which subscribers to notify based on the path and options provided.
165
+ */
166
+ notify(path, value, oldValue, getParentValue, parentNotifications) {
167
+ const normalized = normalizePath(path);
168
+ const direct = this.directSubs.get(normalized);
169
+ if (direct?.size) {
170
+ for (const sub of Array.from(direct.values())) {
171
+ sub.fn(normalized, value, oldValue);
172
+ if (sub.once)
173
+ direct.delete(sub.id);
174
+ }
175
+ }
176
+ const now = Date.now();
177
+ for (const sub of Array.from(this.globalSubscribers.values())) {
178
+ if (sub.throttle && sub.lastTrigger && now - sub.lastTrigger < sub.throttle)
179
+ continue;
180
+ sub.fn(normalized, value, oldValue);
181
+ sub.lastTrigger = now;
182
+ if (sub.once)
183
+ this.globalSubscribers.delete(sub.id);
184
+ }
185
+ for (const parent of getParentPaths(normalized)) {
186
+ const bucket = this.treeSubs.get(parent);
187
+ if (bucket?.size) {
188
+ for (const sub of Array.from(bucket.values())) {
189
+ sub.fn(parent, normalized, value, oldValue);
190
+ if (sub.once)
191
+ bucket.delete(sub.id);
192
+ }
193
+ }
194
+ }
195
+ if (parentNotifications) {
196
+ for (const parent of getParentPaths(normalized)) {
197
+ const bucket = this.directSubs.get(parent);
198
+ if (!bucket?.size)
199
+ continue;
200
+ const parentValue = getParentValue(parent);
201
+ for (const sub of Array.from(bucket.values())) {
202
+ sub.fn(parent, parentValue, undefined);
203
+ if (sub.once)
204
+ bucket.delete(sub.id);
205
+ }
206
+ }
207
+ }
208
+ }
209
+ /**
210
+ * Registers an alert function for a specific path. Alerts are functions that can be triggered
211
+ * when a specific path is set to a new value, allowing for critical checks, transformations, or
212
+ * side effects that must happen before subscribers are notified. The alert will be triggered
213
+ * synchronously during the set operation, and it can have optional conditions and throttling to
214
+ * control when it runs.
215
+ * @param path The path for which to register the alert. This will be normalized before storing.
216
+ * Alerts registered
217
+ * @param callback The alert function that will be called when a value is set at the specified
218
+ * path. It should have the signature `(newValue: unknown, oldValue: unknown, path: string) =>
219
+ * void`, where `newValue` is the new value being set, `oldValue` is the previous value at that
220
+ * path (if any), and `path` is the normalized path being set. The alert can perform critical
221
+ * checks or transformations based on these values, and it can throw an error to prevent the set
222
+ * operation from completing if necessary.
223
+ * @param options Optional settings for the alert:
224
+ * @returns A function that can be called to remove the registered alert. When called, it will
225
+ * unregister the alert so it will no longer be triggered for future set operations at the
226
+ * specified path.
227
+ */
228
+ alert(path, callback, options = {}) {
229
+ const normalized = normalizePath(path);
230
+ const id = generateFastId("alert");
231
+ const alert = { id, path: normalized, fn: callback, condition: options.condition, throttle: options.throttle ?? 0, lastTrigger: 0, once: options.once ?? false };
232
+ const bucket = this.alerts.get(normalized) ?? [];
233
+ bucket.push(alert);
234
+ this.alerts.set(normalized, bucket);
235
+ return () => this.removeAlert(id);
236
+ }
237
+ /**
238
+ * Triggers alerts for a given path and value. Alerts are functions that can be registered to run
239
+ * when a specific path is set to a new value. They can have optional conditions that determine
240
+ * whether they should run based on the new and old values, as well as throttling to limit how
241
+ * often they can be triggered. When an alert is triggered, it will be called with the new value,
242
+ * old value, and path as arguments. If an alert has the `once` option set to true, it will be
243
+ * automatically unregistered after being triggered once.
244
+ * @param path The path for which to trigger alerts. This will be normalized before looking up
245
+ * alerts. Alerts registered
246
+ * @param value The new value that is being set at the specified path. This is passed to alert
247
+ * functions as an argument, along with the old value and path. Alerts can use this value in their
248
+ * logic, and conditions can compare it to the old value to decide whether to run the alert or
249
+ * not.
250
+ * @param oldValue The previous value at the specified path before the change. This is passed to
251
+ * alert functions as an argument, along with the new value and path. Alerts can use this value in
252
+ * their logic, and conditions can compare it to the new value to decide whether to run the alert
253
+ * or not. It can be undefined if there was no previous value.
254
+ * @returns void
255
+ * @remarks Alerts are triggered synchronously during the set operation, before any subscribers
256
+ * are notified. This means that if an alert modifies the value or throws an error, it can affect
257
+ * the outcome of the set operation and whether subscribers are notified. Use alerts for critical
258
+ * checks or transformations that must happen before subscribers are involved.
259
+ */
260
+ triggerAlerts(path, value, oldValue) {
261
+ const bucket = this.alerts.get(normalizePath(path));
262
+ if (!bucket?.length)
263
+ return;
264
+ const now = Date.now();
265
+ for (let i = bucket.length - 1; i >= 0; i--) {
266
+ const alert = bucket[i];
267
+ if (!alert)
268
+ continue;
269
+ if (alert.throttle && now - alert.lastTrigger < alert.throttle)
270
+ continue;
271
+ if (alert.condition && !alert.condition(value, oldValue))
272
+ continue;
273
+ alert.fn(value, oldValue, path);
274
+ alert.lastTrigger = now;
275
+ if (alert.once)
276
+ bucket.splice(i, 1);
277
+ }
278
+ }
279
+ /**
280
+ * Registers a coercer function for a specific path. Coercers are functions that can transform a
281
+ * value before it is set, allowing for validation, normalization, or other transformations. The
282
+ * coercer will be triggered whenever a value is set at the specified path, and it can return a
283
+ * new value to replace the original one. Coercers can also have optional conditions and
284
+ * throttling to control when they are applied.
285
+ *
286
+ * @param path The path for which to register the coercer. This will be normalized before storing.
287
+ * Coercers registered for this exact path will be triggered, but not coercers for parent or child
288
+ * paths. Coercers will receive the normalized path as an argument, so they can perform their own
289
+ * checks if needed.
290
+ * @param callback The coercer function that will be called when a value is set at the specified
291
+ * path. It should have the signature `(path: string, value: unknown, oldValue?: unknown) =>
292
+ * unknown`, where `path` is the normalized path being set, `value` is the new value being set,
293
+ * and `oldValue` is the previous value at that path (if any). The coercer should return the new
294
+ * value to use for the set operation, or it can return `"__NO_COERCE__"` to indicate that no
295
+ * coercion should be applied and the original value should be used.
296
+ * @param options Optional settings for the coercer:
297
+ * @returns A function that can be called to remove the registered coercer. When called, it will
298
+ * unregister the coercer so it will no longer be triggered for future set operations at the
299
+ * specified path.
300
+ */
301
+ coercer(path, callback, options = {}) {
302
+ const normalized = normalizePath(path);
303
+ const id = generateFastId("coercer");
304
+ const coerce = { id, path: normalized, fn: callback, condition: options.condition, throttle: options.throttle ?? 0, lastTrigger: 0, once: options.once ?? false };
305
+ const bucket = this.coercers.get(normalized) ?? [];
306
+ bucket.push(coerce);
307
+ this.coercers.set(normalized, bucket);
308
+ return () => this.removeCoercer(id);
309
+ }
310
+ /**
311
+ * Triggers coercers for a given path and value, returning the final coerced value. Coercers are
312
+ * applied
313
+ * @param path The path for which to trigger coercers. This will be normalized before looking up
314
+ * coercers. Coercers registered for this exact path will be triggered, but not coercers for
315
+ * parent or child paths. Coercers will receive the normalized path as an argument, so they can
316
+ * perform their own checks if needed. Coercers should return the new value or "__NO_COERCE__" to
317
+ * skip coercion.
318
+ * @param value The value to coerce. This is the value that will be passed to coercers and
319
+ * potentially transformed by them. Coercers will receive the current value as an argument and can
320
+ * return a new value to replace it. The final result after all coercers have been applied will be
321
+ * returned by this function.
322
+ * @param oldValue The previous value before the change. This is provided for coercers that need
323
+ * to compare the new value with the old value to decide whether to coerce or not. Coercers will
324
+ * receive this as an argument and can use it in their logic. It can be undefined if there was no
325
+ * previous value.
326
+ * @returns The final coerced value after all applicable coercers have been triggered. If no
327
+ * coercers were triggered or if all coercers returned "__NO_COERCE__", this will be the original
328
+ * value passed in. Otherwise, it will be the result of applying the coercion functions in
329
+ * sequence, with each coercer potentially transforming the value further.
330
+ */
331
+ triggerCoercers(path, value, oldValue) {
332
+ const bucket = this.coercers.get(normalizePath(path));
333
+ if (!bucket?.length)
334
+ return value;
335
+ const now = Date.now();
336
+ let output = value;
337
+ for (let i = bucket.length - 1; i >= 0; i--) {
338
+ const coerce = bucket[i];
339
+ if (!coerce)
340
+ continue;
341
+ if (coerce.throttle && now - coerce.lastTrigger < coerce.throttle)
342
+ continue;
343
+ if (coerce.condition && !coerce.condition(output, oldValue))
344
+ continue;
345
+ const next = coerce.fn(path, output, oldValue);
346
+ if (next !== "__NO_COERCE__")
347
+ output = next;
348
+ coerce.lastTrigger = now;
349
+ if (coerce.once)
350
+ bucket.splice(i, 1);
351
+ }
352
+ return output;
353
+ }
354
+ removeAlert(id) {
355
+ for (const [path, bucket] of this.alerts.entries()) {
356
+ const next = bucket.filter((item) => item.id !== id);
357
+ if (next.length)
358
+ this.alerts.set(path, next);
359
+ else
360
+ this.alerts.delete(path);
361
+ }
362
+ }
363
+ removeCoercer(id) {
364
+ for (const [path, bucket] of this.coercers.entries()) {
365
+ const next = bucket.filter((item) => item.id !== id);
366
+ if (next.length)
367
+ this.coercers.set(path, next);
368
+ else
369
+ this.coercers.delete(path);
370
+ }
371
+ }
372
+ }
373
+ //# sourceMappingURL=subscriptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscri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MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;YACrD,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YACrD,IAAI,IAAI,CAAC,MAAM;gBAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;;gBAC1C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,25 @@
1
+ import type { OmniIssue } from "./issue_types";
2
+ export declare const NO_COERCE: "__NO_COERCE__";
3
+ export declare const OMNI_REJECT: unique symbol;
4
+ export type OmniDataTypeName = "any" | "unknown" | "string" | "number" | "boolean" | "object" | "array" | "null" | "undefined" | "integer" | (string & {});
5
+ export interface OmniCoerceContext {
6
+ path: string;
7
+ oldValue?: unknown;
8
+ }
9
+ export interface OmniValidateContext {
10
+ path: string;
11
+ originalValue?: unknown;
12
+ oldValue?: unknown;
13
+ }
14
+ export type OmniCoerceResult = unknown | typeof NO_COERCE | typeof OMNI_REJECT;
15
+ export type OmniCoercer = (value: unknown, context: OmniCoerceContext) => OmniCoerceResult;
16
+ export type OmniValidator = (value: unknown, context: OmniValidateContext) => boolean | string | OmniIssue | OmniIssue[];
17
+ export interface OmniDataTypeDefinition<T = unknown> {
18
+ name: OmniDataTypeName;
19
+ title?: string;
20
+ base?: OmniDataTypeName;
21
+ coerce?: OmniCoercer;
22
+ validate?: OmniValidator;
23
+ is?: (value: unknown) => value is T;
24
+ }
25
+ //# sourceMappingURL=datatype_types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datatype_types.d.ts","sourceRoot":"","sources":["../../src/types/datatype_types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EA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ol("OMNI_REJECT");
3
+ //# sourceMappingURL=datatype_types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datatype_types.js","sourceRoot":"","sources":["../../src/types/datatype_types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAG,eAAwB,CAAC;AAClD,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC"}
@@ -0,0 +1,14 @@
1
+ export type OmniIssueSeverity = "debug" | "info" | "warning" | "error";
2
+ export type OmniIssueSource = "schema" | "datatype" | "privacy" | "coercion" | "subscription" | "history" | "batch" | "alias" | "internal";
3
+ export interface OmniIssue {
4
+ code: string;
5
+ severity: OmniIssueSeverity;
6
+ path: string;
7
+ message: string;
8
+ source: OmniIssueSource;
9
+ expected?: unknown;
10
+ received?: unknown;
11
+ details?: Record<string, unknown>;
12
+ }
13
+ export declare const createIssue: (issue: OmniIssue) => OmniIssue;
14
+ //# sourceMappingURL=issue_types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issue_types.d.ts","sourceRoot":"","sources":["../../src/types/issue_types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;AAEvE,MAAM,MAAM,eAAe,GACvB,QAAQ,GACR,UAAU,GACV,SAAS,GACT,UAAU,GACV,cAAc,GACd,SAAS,GACT,OAAO,GACP,OAAO,GACP,UAAU,CAAC;AAEf,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,eAAO,MAAM,WAAW,GAAI,OAAO,SAAS,KAAG,SAAkB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const createIssue = (issue) => issue;
2
+ //# sourceMappingURL=issue_types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issue_types.js","sourceRoot":"","sources":["../../src/types/issue_types.ts"],"names":[],"mappings":"AAwBA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAgB,EAAa,EAAE,CAAC,KAAK,CAAC"}
@@ -0,0 +1,48 @@
1
+ import type { OmniSchema } from "./schema_types";
2
+ import type { OmniWriteToken } from "./privacy_types";
3
+ export type CloneMode = "none" | "shallow" | "deep";
4
+ export type SubscriberTiming = "PRE" | "POST";
5
+ export interface OmniSubscriber {
6
+ id: string;
7
+ fn: Function;
8
+ type: 0 | 1;
9
+ once?: boolean;
10
+ }
11
+ export interface SetOptions {
12
+ immediate?: boolean;
13
+ history?: boolean;
14
+ historyLimit?: number;
15
+ clone?: CloneMode;
16
+ silent?: boolean;
17
+ suppressTimeline?: boolean;
18
+ asObject?: boolean;
19
+ pushToArray?: boolean;
20
+ schema?: OmniSchema;
21
+ privateSet?: boolean;
22
+ owner?: string;
23
+ deletePolicy?: "anyone" | "owner" | "never";
24
+ token?: OmniWriteToken;
25
+ validate?: boolean;
26
+ coerce?: boolean;
27
+ }
28
+ export interface InternalSetOptions extends SetOptions {
29
+ suppressNotifications?: boolean;
30
+ suppressAlerts?: boolean;
31
+ suppressWaiters?: boolean;
32
+ dryRun?: boolean;
33
+ action?: "set" | "setObj" | "canSet";
34
+ }
35
+ export interface BatchOptions {
36
+ notify?: boolean;
37
+ alerts?: boolean;
38
+ waiters?: boolean;
39
+ validate?: boolean;
40
+ coerce?: boolean;
41
+ history?: boolean;
42
+ suppressTimeline?: boolean;
43
+ }
44
+ export interface GetOptions {
45
+ clone?: CloneMode;
46
+ asObject?: boolean;
47
+ }
48
+ //# sourceMappingURL=options_types.d.ts.map
@@ -0,0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AO,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;CACtC;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=options_types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options_types.js","sourceRoot":"","sources":["../../src/types/options_types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ import type { OmniResult } from "./result_types";
2
+ import type { SetOptions } from "./options_types";
3
+ export interface OmniWriteToken {
4
+ id: string;
5
+ rootPath: string;
6
+ owner?: string;
7
+ canWriteChildren: boolean;
8
+ created: number;
9
+ }
10
+ export type OmniPrivateSetter = {
11
+ (value: unknown, options?: SetOptions): OmniResult;
12
+ (childPath: string, value: unknown, options?: SetOptions): OmniResult;
13
+ token: OmniWriteToken;
14
+ };
15
+ export interface PrivacyRule {
16
+ rootPath: string;
17
+ tokenId: string;
18
+ owner?: string;
19
+ canWriteChildren: boolean;
20
+ deletePolicy: "anyone" | "owner" | "never";
21
+ }
22
+ //# sourceMappingURL=privacy_types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"privacy_types.d.ts","sourceRoot":"","sources":["../../src/types/privacy_types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,OAAO,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;IACnD,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;IACtE,KAAK,EAAE,cAAc,CAAC;CACvB,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,OAAO,CAAC;IAC1B,YAAY,EAAE,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;CAC5C"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=privacy_types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"privacy_types.js","sourceRoot":"","sources":["../../src/types/privacy_types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ import type { OmniIssue } from "./issue_types";
2
+ import type { OmniSchema } from "./schema_types";
3
+ import type { OmniPrivateSetter } from "./privacy_types";
4
+ export type OmniAction = "set" | "setObj" | "delete" | "batch" | "schema" | "datatype" | "privacy" | "canSet" | "noop";
5
+ export interface OmniResult<T = unknown> {
6
+ success: boolean;
7
+ action: OmniAction;
8
+ path: string;
9
+ originalValue?: unknown;
10
+ value?: T;
11
+ oldValue?: unknown;
12
+ changed?: boolean;
13
+ rejected?: boolean;
14
+ issues: OmniIssue[];
15
+ options?: Record<string, unknown>;
16
+ schema?: OmniSchema;
17
+ setter?: OmniPrivateSetter;
18
+ children?: OmniResult[];
19
+ }
20
+ //# sourceMappingURL=result_types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result_types.d.ts","sourceRoot":"","sources":["../../src/types/result_types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,MAAM,MAAM,UAAU,GAClB,KAAK,GACL,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,UAAU,GACV,SAAS,GACT,QAAQ,GACR,MAAM,CAAC;AAEX,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,OAAO;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,CAAC,CAAC;IACV,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;CACzB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=result_types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result_types.js","sourceRoot":"","sources":["../../src/types/result_types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ import type { OmniCoercer, OmniDataTypeName, OmniValidator } from "./datatype_types";
2
+ export interface OmniSchema {
3
+ type?: OmniDataTypeName;
4
+ required?: boolean;
5
+ nullable?: boolean;
6
+ default?: unknown | (() => unknown);
7
+ coerce?: boolean | OmniCoercer;
8
+ validate?: OmniValidator | OmniValidator[];
9
+ min?: number;
10
+ max?: number;
11
+ minLength?: number;
12
+ maxLength?: number;
13
+ enum?: unknown[];
14
+ pattern?: RegExp | string;
15
+ children?: Record<string, OmniSchema>;
16
+ items?: OmniSchema;
17
+ strictObject?: boolean;
18
+ atomic?: boolean;
19
+ history?: boolean;
20
+ historyLimit?: number;
21
+ privateSet?: boolean;
22
+ readonly?: boolean;
23
+ writeOnce?: boolean;
24
+ deletePolicy?: "anyone" | "owner" | "never";
25
+ onInvalid?: "reject" | "keepOld" | "setDefault";
26
+ description?: string;
27
+ meta?: Record<string, unknown>;
28
+ }
29
+ export interface OmniResolvedSchema {
30
+ path: string;
31
+ pattern: string;
32
+ schema: OmniSchema;
33
+ score: number;
34
+ }
35
+ //# sourceMappingURL=schema_types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema_types.d.ts","sourceRoot":"","sources":["../../src/types/schema_types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAErF,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC;IACpC,MAAM,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;IAC/B,QAAQ,CAAC,EAAE,aAAa,GAAG,aAAa,EAAE,CAAC;IAE3C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAE1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACtC,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;IAE5C,SAAS,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,YAAY,CAAC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=schema_types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema_types.js","sourceRoot":"","sources":["../../src/types/schema_types.ts"],"names":[],"mappings":""}