@iebh/tera-fy 2.3.11 → 2.3.12

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 (82) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/api.md +8 -11
  3. package/dist/plugin.vue2.es2019.js +7 -7
  4. package/dist/terafy.bootstrapper.es2019.js +2 -2
  5. package/dist/terafy.bootstrapper.js +2 -2
  6. package/dist/terafy.es2019.js +5 -5
  7. package/dist/terafy.js +5 -5
  8. package/eslint.config.js +4 -66
  9. package/lib/{projectFile.ts → projectFile.js} +52 -76
  10. package/lib/syncro/{entities.ts → entities.js} +14 -83
  11. package/lib/syncro/{keyed.ts → keyed.js} +46 -68
  12. package/lib/syncro/{syncro.ts → syncro.js} +104 -136
  13. package/lib/{terafy.bootstrapper.ts → terafy.bootstrapper.js} +20 -30
  14. package/lib/{terafy.client.ts → terafy.client.js} +85 -84
  15. package/lib/{terafy.proxy.ts → terafy.proxy.js} +12 -26
  16. package/lib/{terafy.server.ts → terafy.server.js} +204 -229
  17. package/package.json +20 -39
  18. package/plugins/{base.ts → base.js} +3 -5
  19. package/plugins/{firebase.ts → firebase.js} +22 -21
  20. package/plugins/{vite.ts → vite.js} +3 -3
  21. package/plugins/{vue2.ts → vue2.js} +8 -10
  22. package/plugins/{vue3.ts → vue3.js} +7 -10
  23. package/utils/mixin.js +15 -0
  24. package/utils/{pathTools.ts → pathTools.js} +8 -9
  25. package/widgets/tera-file-select.vue +1 -1
  26. package/dist/lib/projectFile.d.ts +0 -190
  27. package/dist/lib/projectFile.js +0 -305
  28. package/dist/lib/projectFile.js.map +0 -1
  29. package/dist/lib/syncro/entities.d.ts +0 -34
  30. package/dist/lib/syncro/entities.js +0 -212
  31. package/dist/lib/syncro/entities.js.map +0 -1
  32. package/dist/lib/syncro/keyed (Rhino's conflicted copy 2026-05-10).js +0 -287
  33. package/dist/lib/syncro/keyed.d.ts +0 -95
  34. package/dist/lib/syncro/keyed.js +0 -288
  35. package/dist/lib/syncro/keyed.js (Rhino's conflicted copy 2026-05-10).map +0 -1
  36. package/dist/lib/syncro/keyed.js.map +0 -1
  37. package/dist/lib/syncro/syncro (Rhino's conflicted copy 2026-05-10).js +0 -765
  38. package/dist/lib/syncro/syncro.d (Rhino's conflicted copy 2026-05-10).ts +0 -336
  39. package/dist/lib/syncro/syncro.d.ts +0 -343
  40. package/dist/lib/syncro/syncro.js +0 -771
  41. package/dist/lib/syncro/syncro.js (Rhino's conflicted copy 2026-05-10).map +0 -1
  42. package/dist/lib/syncro/syncro.js.map +0 -1
  43. package/dist/lib/terafy.bootstrapper.d.ts +0 -42
  44. package/dist/lib/terafy.bootstrapper.js +0 -129
  45. package/dist/lib/terafy.bootstrapper.js.map +0 -1
  46. package/dist/lib/terafy.client.d.ts +0 -555
  47. package/dist/lib/terafy.client.js +0 -1153
  48. package/dist/lib/terafy.client.js.map +0 -1
  49. package/dist/lib/terafy.proxy.d.ts +0 -66
  50. package/dist/lib/terafy.proxy.js +0 -130
  51. package/dist/lib/terafy.proxy.js.map +0 -1
  52. package/dist/lib/terafy.server.d.ts +0 -697
  53. package/dist/lib/terafy.server.js +0 -2062
  54. package/dist/lib/terafy.server.js.map +0 -1
  55. package/dist/plugin.vue2.es2019 (Rhino's conflicted copy 2026-05-10).js +0 -1271
  56. package/dist/plugins/base.d.ts +0 -20
  57. package/dist/plugins/base.js +0 -22
  58. package/dist/plugins/base.js.map +0 -1
  59. package/dist/plugins/firebase.d.ts +0 -62
  60. package/dist/plugins/firebase.js +0 -123
  61. package/dist/plugins/firebase.js.map +0 -1
  62. package/dist/plugins/vite.d.ts +0 -12
  63. package/dist/plugins/vite.js +0 -22
  64. package/dist/plugins/vite.js.map +0 -1
  65. package/dist/plugins/vue2.d.ts +0 -67
  66. package/dist/plugins/vue2.js +0 -104
  67. package/dist/plugins/vue2.js.map +0 -1
  68. package/dist/plugins/vue3.d.ts +0 -63
  69. package/dist/plugins/vue3.js +0 -93
  70. package/dist/plugins/vue3.js.map +0 -1
  71. package/dist/utils/mixin.d.ts +0 -11
  72. package/dist/utils/mixin.js +0 -15
  73. package/dist/utils/mixin.js.map +0 -1
  74. package/dist/utils/pDefer.d.ts +0 -16
  75. package/dist/utils/pDefer.js +0 -19
  76. package/dist/utils/pDefer.js.map +0 -1
  77. package/dist/utils/pathTools.d.ts +0 -70
  78. package/dist/utils/pathTools.js +0 -120
  79. package/dist/utils/pathTools.js.map +0 -1
  80. package/tsconfig.json +0 -30
  81. package/utils/mixin.ts +0 -18
  82. package/utils/pDefer.ts +0 -27
@@ -1,336 +0,0 @@
1
- import { DocumentReference, Firestore } from 'firebase/firestore';
2
- import { FirebaseApp } from 'firebase/app';
3
- import { BoundSupabaseyFunction } from '@iebh/supabasey';
4
- interface ThrottleOptions<T = any> {
5
- limit: number;
6
- interval: number;
7
- strict: boolean;
8
- }
9
- interface ReactiveWrapper<T = any> {
10
- doc: T;
11
- setState: (newState: T) => void;
12
- getState: () => T;
13
- watch: (cb: (newState: T) => void) => void;
14
- throttle?: ThrottleOptions | true;
15
- }
16
- interface PathSplitResult {
17
- fsCollection: string;
18
- fsId: string;
19
- entity: string;
20
- id: string;
21
- relation?: string;
22
- }
23
- /**
24
- * @class Syncro
25
- * TERA Isomorphic Syncro class
26
- * Slurp an entity from Supabase and hold it in Firebase/Firestore as a "floating" entity which periodically gets flushed back to Supabase and eventually completely cleaned up
27
- * This class tries to be as independent as possible to help with adapting it to various front-end TERA-fy plugin frameworks
28
- */
29
- export default class Syncro {
30
- /**
31
- * Firebase instance in use
32
- *
33
- * @type {FirebaseApp}
34
- */
35
- static firebase: FirebaseApp;
36
- /**
37
- * Firestore instance in use
38
- *
39
- * @type {Firestore}
40
- */
41
- static firestore: Firestore;
42
- /**
43
- * Supabasey instance in use
44
- *
45
- * @type {Supabasey}
46
- */
47
- static supabasey: BoundSupabaseyFunction;
48
- /**
49
- * The current user session, should be unique for the user + browser tab
50
- * Used by the heartbeat system
51
- *
52
- * @type {String}
53
- */
54
- static session: string | undefined;
55
- /**
56
- * OPTIONAL SyncroEntries from './entities.ts' if its required
57
- * This only gets populated if `config.forceLocalInit` is truthy and we've mounted at least one Syncro
58
- *
59
- * @type {Record<string, any>}
60
- */
61
- static SyncroEntities: Record<string, any>;
62
- /**
63
- * This instances fully formed string path
64
- *
65
- * @type {String}
66
- */
67
- path: string;
68
- /**
69
- * The Firestore docHandle when calling various Firestore functions
70
- *
71
- * @type {DocumentReference | undefined}
72
- */
73
- docRef: DocumentReference | undefined;
74
- /**
75
- * The reactive object managed by this Syncro instance
76
- * The nature of this varies by framework and what `getReactive()` provides
77
- *
78
- * @type {any}
79
- */
80
- value: any;
81
- /**
82
- * Default throttle to apply for writes
83
- *
84
- * @type {Number} Throttle time in milliseconds
85
- */
86
- throttle: number;
87
- /**
88
- * Various Misc config for the Syncro instance
89
- *
90
- * @type {Object}
91
- * @property {Number} heartbeatInterval Time in milliseconds between heartbeat beacons
92
- * @property {String} syncroRegistryUrl The prefix Sync worker URL, used to populate Syncros and determine their active status
93
- * @property {Object} context Additional named parameters to pass to callbacks like initState
94
- */
95
- config: {
96
- heartbeatInterval: number;
97
- syncroRegistryUrl: string;
98
- context: Record<string, any>;
99
- };
100
- /**
101
- * Whether the next heartbeat should be marked as 'dirty'
102
- * This indicates that at least one change has occurred since the last heartbeat and the server should perform a flush (but not a clean)
103
- * This flag is only transmitted once in the next heartbeat before being reset
104
- *
105
- * @see markDirty()
106
- * @type {Boolean}
107
- */
108
- isDirty: boolean;
109
- /**
110
- * @interface
111
- * Debugging printer for this instance
112
- * Defaults to doing nothing
113
- *
114
- * @param {*...} [msg] The message to output
115
- */
116
- debug(...msg: any[]): void;
117
- /**
118
- * @interface
119
- * Debugging printer specifically for error messages
120
- * Defaults to using console.log()
121
- *
122
- * @param {*...} [msg] The message to output
123
- */
124
- debugError(...msg: any[]): void;
125
- /**
126
- * Instance constructor
127
- *
128
- * @param {String} path Mount path for the Syncro. Should be in the form `${ENTITY}::${ID}(::${RELATION})?`
129
- * @param {Object} [options] Additional instance setters (mutates instance directly), note that the `config` subkey is merged with the existing config rather than assigned
130
- */
131
- constructor(path: string, options?: any);
132
- /**
133
- * Instance destruction trigger
134
- * This will unsubscribe from various facilities and release the object for cleanup
135
- *
136
- * @returns {Promise} A promise which resolves when the operation has completed
137
- */
138
- destroy(): Promise<any[]>;
139
- /**
140
- * Actions to preform when we are destroying this instance
141
- * This is an array of function callbacks to execute in parallel when `destroy()` is called
142
- *
143
- * @type {Array<Function<Promise>>}
144
- */
145
- _destroyActions: Array<() => void>;
146
- /**
147
- * Function to return whatever the local framework uses as a reactive object
148
- * This should respond with an object of mandatory functions to watch for changes and re-merge them
149
- *
150
- * @param {Object} value Initial value of the reactive
151
- *
152
- * @returns {ReactiveWrapper} A reactive object prototype
153
- * @property {Object} doc The reactive object
154
- * @property {Function} setState Function used to overwrite the default state, called as `(newState:Object)`
155
- * @property {Function} getState Function used to fetch the current snapshot state, called as `()`
156
- * @property {Function} watch Function used to set up state watchers, should call its callback when a change is detected, called as `(cb:Function)`
157
- */
158
- getReactive(value: any): ReactiveWrapper;
159
- /**
160
- * Returns the split entity + ID relationship from a given session path
161
- * This function checks for valid UUID format strings + that the entity is a known/supported entity (see `knownEntities`)
162
- * NOTE: When used by itself (i.e. ignoring response) this function can also act as a guard that a path is valid
163
- *
164
- * INPUT: `widgets::UUID` -> `{entity:'widgets', id:UUID}`
165
- * INPUT: `widgets::UUID::thing` -> `{entity:'widgets', id:UUID, relation:'thing'}`
166
- *
167
- * @param {String} path The input session path of the form `${ENTITY}::${ID}`
168
- * @param {Object} [options] Additional options to mutate behaviour
169
- * @param {Boolean} [options.allowAsterisk=false] Whether to allow the meta asterisk character when recognising paths, this is used by the SyncroKeyed class
170
- *
171
- * @returns {PathSplitResult} An object composed of the session path components
172
- */
173
- static pathSplit(path: string, options?: any): PathSplitResult;
174
- /**
175
- * Convert local POJO -> Firestore compatible object
176
- * This applies the following mutations to the incoming object:
177
- *
178
- * 1. Arrays are converted to Objects (Firestore cannot store nested arrays)
179
- * 2. All non-POJO objects (e.g. Dates) to a symmetric object
180
- *
181
- * @param {Object} snapshot The current state to convert
182
- * @returns {Object} A Firebase compatible object
183
- */
184
- static toFirestore(snapshot?: any): any;
185
- /**
186
- * Convert local Firestore compatible object -> local POJO
187
- * This reverses the mutations listed in `toFirestore()`
188
- *
189
- * @param {Object} snapshot The raw Firebase state to convert
190
- * @returns {Object} A JavaScript POJO representing the converted state
191
- */
192
- static fromFirestore(snapshot?: any): any;
193
- /**
194
- * Convert a raw POJO into Firestore field layout
195
- * Field structures are usually consumed by the Firestore ReST API and need converting before being used
196
- * NOTE: This does not serialize the incoming data so you likely want to use this as `toFirestoreFields(toFirestore(data))`
197
- *
198
- * @see https://stackoverflow.com/a/62304377
199
- * @param {Object} data The raw value to convert
200
- * @returns {Object} A Firestore compatible, typed data structure
201
- */
202
- static toFirestoreFields(data: any): Record<string, any>;
203
- /**
204
- * Convert a Firestore field dump into a native POJO
205
- * Field structures are usually provided by the Firestore ReST API and need de-typing back into a native document
206
- * NOTE: This does not deserialize the result so you likely want to use this as `fromFirestore(fromFirestoreFields(response.fields))`
207
- *
208
- * @see https://stackoverflow.com/a/62304377
209
- * @param {Object} fields The raw Snapshot to convert
210
- * @returns {Object} A JavaScript POJO representing the converted state
211
- */
212
- static fromFirestoreFields(fields?: any): any;
213
- /**
214
- * Perform a one-off fetch of a given Syncro path
215
- *
216
- * @param {String} path The Syncro entity + ID path. Takes the form `ENTITY::ID`
217
- *
218
- * @returns {Promise<Object|Null>} An eventual snapshot of the given path, if the entity doesn't exist null is returned
219
- */
220
- static getSnapshot(path: string): Promise<object | null>;
221
- /**
222
- * Perform a one-off set/merge operation against
223
- *
224
- * @param {String} path The Syncro entity + ID path. Takes the form `ENTITY::ID`
225
- * @param {Object} state The new state to set/merge
226
- *
227
- * @param {Object} [options] Additional options to mutate behaviour
228
- * @param {'merge'|'set'} [options.method='merge'] How to apply the new state. 'merge' (merge in partial data to an existing Syncro), 'set' (overwrite the entire Syncro state)
229
- *
230
- * @returns {Promise<*>} The state object after it has been applied
231
- */
232
- static setSnapshot(path: string, state: any, options?: {
233
- method?: 'merge' | 'set';
234
- }): Promise<any>;
235
- /**
236
- * Mount the remote Firestore document against this Syncro instance
237
- *
238
- * @param {Object} [options] Additional options to mutate behaviour
239
- * @param {Object} [options.initialState] State to use if no state is already loaded, overrides the entities own `initState` function fetcher
240
- * @param {Number} [options.retries=3] Number of times to retry if a mounted Syncro fails its sanity checks
241
- * @returns {Promise<Syncro>} A promise which resolves as this syncro instance when completed
242
- */
243
- mount(options?: any): Promise<Syncro>;
244
- /**
245
- * Merge a single or multiple values into a Syncro data object
246
- * NOTE: Default behaviour is to flush (if any changes apply), use direct object mutation or disable with `flush:false` to disable
247
- *
248
- * @param {String|Object} key Either the single named key to set OR the object to merge
249
- * @param {*} [value] The value to set if `key` is a string
250
- *
251
- * @param {Object} [options] Additional options to mutate behaviour
252
- * @param {Boolean} [options.delta=true] Only merge keys that differ, skipping flush if no changes are made
253
- * @param {Boolean} [options.flush=true] Send a flush signal that Firebase should sync to Supabase on changes
254
- * @param {Boolean} [options.forceFlush=false] Flush even if no changes were made
255
- * @param {Boolean} [options.flushDestroy=false] Destroy the Syncro after flushing
256
- *
257
- * @returns {Promise<Syncro>} A promise which resolves with this Syncro instance on completion
258
- */
259
- set(key: string | object, value: any, options: {
260
- delta?: boolean;
261
- flush?: boolean;
262
- forceFlush?: boolean;
263
- flushDestroy?: boolean;
264
- }): Promise<this>;
265
- /**
266
- * Schedule Syncro heartbeats
267
- * This populates the `sync` presence meta-information
268
- *
269
- * @param {Boolean} [enable=true] Whether to enable heartbeats
270
- *
271
- * @param {Object} [options] Additional options to mutate behaviour
272
- * @param {Boolean} [options.immediate=false] Fire a heartbeat as soon as this function is called, this is only really useful on mount
273
- * @returns {Promise|Void} A promise that resolves when completed (if `{immediate:true}`) or void
274
- */
275
- setHeartbeat(enable?: boolean, options?: any): Promise<void> | void;
276
- /**
277
- * Perform one heartbeat pulse to the server to indicate presence within this Syncro
278
- * This function is automatically called by a timer if `setHeartbeat(true)` (the default behaviour)
279
- *
280
- * @returns {Promise} A promise which resolves when the operation has completed
281
- */
282
- heartbeat(): Promise<void>;
283
- /**
284
- * Utility function to directly set this documents firestore state
285
- *
286
- * @param {Object} state The state to set / merge
287
- * @param {Object} [options] Additional options to mutate behaviour
288
- * @param {'merge'|'set'} [options.method='merge'] How to apply the new state. 'merge' (merge in partial data to an existing Syncro), 'set' (overwrite the entire Syncro state)
289
- *
290
- * @param {number} retries How many tries to take before erroring
291
- * @returns {Promise} A promise which resolves when the operation has completed
292
- */
293
- setFirestoreState(state: any, options?: {
294
- method?: 'merge' | 'set';
295
- }, retries?: number): Promise<void>;
296
- /**
297
- * Utility method to fetch the Firestore state for this Syncro
298
- * NOTE: This directly extracts the state of the Firestore, not its wrapping doc object returned by `FirestoreGetDoc`
299
- *
300
- * @returns {Promise<Object>} A promise which resolves to the Firestore state
301
- */
302
- getFirestoreState(): Promise<any>;
303
- /**
304
- * Set the Syncro dirty flag which gets passed to the server on the next heartbeat
305
- *
306
- * @see isDirty
307
- * @returns {Syncro} This chainable Syncro instance
308
- */
309
- markDirty(): this;
310
- /**
311
- * Force the server to flush state
312
- * This is only really useful for debugging as this happens automatically anyway
313
- *
314
- * @param {Object} [options] Additional options to mutate behaviour
315
- * @param {Boolean} [options.destroy=false] Instruct the server to also dispose of the Syncro state
316
- *
317
- * @returns {Promise} A promise which resolves when the operation has completed
318
- */
319
- flush(options?: any): Promise<void | null>;
320
- /**
321
- * Timer handle for heartbeats
322
- *
323
- * @type {any}
324
- */
325
- _heartbeatTimer: any;
326
- }
327
- /**
328
- * Build a chaotic random tree structure based on dice rolls
329
- * This function is mainly used for sync testing
330
- *
331
- * @param {Number} [depth=0] The current depth we are starting at, changes the nature of branches based on probability
332
- *
333
- * @returns {*} The current branch contents
334
- */
335
- export declare function randomBranch(depth?: number): any;
336
- export {};
@@ -1,343 +0,0 @@
1
- import { DocumentReference, Firestore } from 'firebase/firestore';
2
- import { FirebaseApp } from 'firebase/app';
3
- import { BoundSupabaseyFunction } from '@iebh/supabasey';
4
- import type { PostgresSql } from './entities.js';
5
- interface ThrottleOptions<T = any> {
6
- limit: number;
7
- interval: number;
8
- strict: boolean;
9
- }
10
- interface ReactiveWrapper<T = any> {
11
- doc: T;
12
- setState: (newState: T) => void;
13
- getState: () => T;
14
- watch: (cb: (newState: T) => void) => void;
15
- throttle?: ThrottleOptions | true;
16
- }
17
- interface PathSplitResult {
18
- fsCollection: string;
19
- fsId: string;
20
- entity: string;
21
- id: string;
22
- relation?: string;
23
- }
24
- /**
25
- * @class Syncro
26
- * TERA Isomorphic Syncro class
27
- * Slurp an entity from Supabase and hold it in Firebase/Firestore as a "floating" entity which periodically gets flushed back to Supabase and eventually completely cleaned up
28
- * This class tries to be as independent as possible to help with adapting it to various front-end TERA-fy plugin frameworks
29
- */
30
- export default class Syncro {
31
- /**
32
- * Firebase instance in use
33
- *
34
- * @type {FirebaseApp}
35
- */
36
- static firebase: FirebaseApp;
37
- /**
38
- * Firestore instance in use
39
- *
40
- * @type {Firestore}
41
- */
42
- static firestore: Firestore;
43
- /**
44
- * Supabasey instance in use
45
- *
46
- * @type {Supabasey}
47
- */
48
- static supabasey: BoundSupabaseyFunction;
49
- /**
50
- * Postgres SQL instance in use (injected by the Cloudflare Worker runtime via Hyperdrive)
51
- *
52
- * @type {PostgresSql}
53
- */
54
- static db: PostgresSql;
55
- /**
56
- * The current user session, should be unique for the user + browser tab
57
- * Used by the heartbeat system
58
- *
59
- * @type {String}
60
- */
61
- static session: string | undefined;
62
- /**
63
- * OPTIONAL SyncroEntries from './entities.ts' if its required
64
- * This only gets populated if `config.forceLocalInit` is truthy and we've mounted at least one Syncro
65
- *
66
- * @type {Record<string, any>}
67
- */
68
- static SyncroEntities: Record<string, any>;
69
- /**
70
- * This instances fully formed string path
71
- *
72
- * @type {String}
73
- */
74
- path: string;
75
- /**
76
- * The Firestore docHandle when calling various Firestore functions
77
- *
78
- * @type {DocumentReference | undefined}
79
- */
80
- docRef: DocumentReference | undefined;
81
- /**
82
- * The reactive object managed by this Syncro instance
83
- * The nature of this varies by framework and what `getReactive()` provides
84
- *
85
- * @type {any}
86
- */
87
- value: any;
88
- /**
89
- * Default throttle to apply for writes
90
- *
91
- * @type {Number} Throttle time in milliseconds
92
- */
93
- throttle: number;
94
- /**
95
- * Various Misc config for the Syncro instance
96
- *
97
- * @type {Object}
98
- * @property {Number} heartbeatInterval Time in milliseconds between heartbeat beacons
99
- * @property {String} syncroRegistryUrl The prefix Sync worker URL, used to populate Syncros and determine their active status
100
- * @property {Object} context Additional named parameters to pass to callbacks like initState
101
- */
102
- config: {
103
- heartbeatInterval: number;
104
- syncroRegistryUrl: string;
105
- context: Record<string, any>;
106
- };
107
- /**
108
- * Whether the next heartbeat should be marked as 'dirty'
109
- * This indicates that at least one change has occurred since the last heartbeat and the server should perform a flush (but not a clean)
110
- * This flag is only transmitted once in the next heartbeat before being reset
111
- *
112
- * @see markDirty()
113
- * @type {Boolean}
114
- */
115
- isDirty: boolean;
116
- /**
117
- * @interface
118
- * Debugging printer for this instance
119
- * Defaults to doing nothing
120
- *
121
- * @param {*...} [msg] The message to output
122
- */
123
- debug(...msg: any[]): void;
124
- /**
125
- * @interface
126
- * Debugging printer specifically for error messages
127
- * Defaults to using console.log()
128
- *
129
- * @param {*...} [msg] The message to output
130
- */
131
- debugError(...msg: any[]): void;
132
- /**
133
- * Instance constructor
134
- *
135
- * @param {String} path Mount path for the Syncro. Should be in the form `${ENTITY}::${ID}(::${RELATION})?`
136
- * @param {Object} [options] Additional instance setters (mutates instance directly), note that the `config` subkey is merged with the existing config rather than assigned
137
- */
138
- constructor(path: string, options?: any);
139
- /**
140
- * Instance destruction trigger
141
- * This will unsubscribe from various facilities and release the object for cleanup
142
- *
143
- * @returns {Promise} A promise which resolves when the operation has completed
144
- */
145
- destroy(): Promise<any[]>;
146
- /**
147
- * Actions to preform when we are destroying this instance
148
- * This is an array of function callbacks to execute in parallel when `destroy()` is called
149
- *
150
- * @type {Array<Function<Promise>>}
151
- */
152
- _destroyActions: Array<() => void>;
153
- /**
154
- * Function to return whatever the local framework uses as a reactive object
155
- * This should respond with an object of mandatory functions to watch for changes and re-merge them
156
- *
157
- * @param {Object} value Initial value of the reactive
158
- *
159
- * @returns {ReactiveWrapper} A reactive object prototype
160
- * @property {Object} doc The reactive object
161
- * @property {Function} setState Function used to overwrite the default state, called as `(newState:Object)`
162
- * @property {Function} getState Function used to fetch the current snapshot state, called as `()`
163
- * @property {Function} watch Function used to set up state watchers, should call its callback when a change is detected, called as `(cb:Function)`
164
- */
165
- getReactive(value: any): ReactiveWrapper;
166
- /**
167
- * Returns the split entity + ID relationship from a given session path
168
- * This function checks for valid UUID format strings + that the entity is a known/supported entity (see `knownEntities`)
169
- * NOTE: When used by itself (i.e. ignoring response) this function can also act as a guard that a path is valid
170
- *
171
- * INPUT: `widgets::UUID` -> `{entity:'widgets', id:UUID}`
172
- * INPUT: `widgets::UUID::thing` -> `{entity:'widgets', id:UUID, relation:'thing'}`
173
- *
174
- * @param {String} path The input session path of the form `${ENTITY}::${ID}`
175
- * @param {Object} [options] Additional options to mutate behaviour
176
- * @param {Boolean} [options.allowAsterisk=false] Whether to allow the meta asterisk character when recognising paths, this is used by the SyncroKeyed class
177
- *
178
- * @returns {PathSplitResult} An object composed of the session path components
179
- */
180
- static pathSplit(path: string, options?: any): PathSplitResult;
181
- /**
182
- * Convert local POJO -> Firestore compatible object
183
- * This applies the following mutations to the incoming object:
184
- *
185
- * 1. Arrays are converted to Objects (Firestore cannot store nested arrays)
186
- * 2. All non-POJO objects (e.g. Dates) to a symmetric object
187
- *
188
- * @param {Object} snapshot The current state to convert
189
- * @returns {Object} A Firebase compatible object
190
- */
191
- static toFirestore(snapshot?: any): any;
192
- /**
193
- * Convert local Firestore compatible object -> local POJO
194
- * This reverses the mutations listed in `toFirestore()`
195
- *
196
- * @param {Object} snapshot The raw Firebase state to convert
197
- * @returns {Object} A JavaScript POJO representing the converted state
198
- */
199
- static fromFirestore(snapshot?: any): any;
200
- /**
201
- * Convert a raw POJO into Firestore field layout
202
- * Field structures are usually consumed by the Firestore ReST API and need converting before being used
203
- * NOTE: This does not serialize the incoming data so you likely want to use this as `toFirestoreFields(toFirestore(data))`
204
- *
205
- * @see https://stackoverflow.com/a/62304377
206
- * @param {Object} data The raw value to convert
207
- * @returns {Object} A Firestore compatible, typed data structure
208
- */
209
- static toFirestoreFields(data: any): Record<string, any>;
210
- /**
211
- * Convert a Firestore field dump into a native POJO
212
- * Field structures are usually provided by the Firestore ReST API and need de-typing back into a native document
213
- * NOTE: This does not deserialize the result so you likely want to use this as `fromFirestore(fromFirestoreFields(response.fields))`
214
- *
215
- * @see https://stackoverflow.com/a/62304377
216
- * @param {Object} fields The raw Snapshot to convert
217
- * @returns {Object} A JavaScript POJO representing the converted state
218
- */
219
- static fromFirestoreFields(fields?: any): any;
220
- /**
221
- * Perform a one-off fetch of a given Syncro path
222
- *
223
- * @param {String} path The Syncro entity + ID path. Takes the form `ENTITY::ID`
224
- *
225
- * @returns {Promise<Object|Null>} An eventual snapshot of the given path, if the entity doesn't exist null is returned
226
- */
227
- static getSnapshot(path: string): Promise<object | null>;
228
- /**
229
- * Perform a one-off set/merge operation against
230
- *
231
- * @param {String} path The Syncro entity + ID path. Takes the form `ENTITY::ID`
232
- * @param {Object} state The new state to set/merge
233
- *
234
- * @param {Object} [options] Additional options to mutate behaviour
235
- * @param {'merge'|'set'} [options.method='merge'] How to apply the new state. 'merge' (merge in partial data to an existing Syncro), 'set' (overwrite the entire Syncro state)
236
- *
237
- * @returns {Promise<*>} The state object after it has been applied
238
- */
239
- static setSnapshot(path: string, state: any, options?: {
240
- method?: 'merge' | 'set';
241
- }): Promise<any>;
242
- /**
243
- * Mount the remote Firestore document against this Syncro instance
244
- *
245
- * @param {Object} [options] Additional options to mutate behaviour
246
- * @param {Object} [options.initialState] State to use if no state is already loaded, overrides the entities own `initState` function fetcher
247
- * @param {Number} [options.retries=3] Number of times to retry if a mounted Syncro fails its sanity checks
248
- * @returns {Promise<Syncro>} A promise which resolves as this syncro instance when completed
249
- */
250
- mount(options?: any): Promise<Syncro>;
251
- /**
252
- * Merge a single or multiple values into a Syncro data object
253
- * NOTE: Default behaviour is to flush (if any changes apply), use direct object mutation or disable with `flush:false` to disable
254
- *
255
- * @param {String|Object} key Either the single named key to set OR the object to merge
256
- * @param {*} [value] The value to set if `key` is a string
257
- *
258
- * @param {Object} [options] Additional options to mutate behaviour
259
- * @param {Boolean} [options.delta=true] Only merge keys that differ, skipping flush if no changes are made
260
- * @param {Boolean} [options.flush=true] Send a flush signal that Firebase should sync to Supabase on changes
261
- * @param {Boolean} [options.forceFlush=false] Flush even if no changes were made
262
- * @param {Boolean} [options.flushDestroy=false] Destroy the Syncro after flushing
263
- *
264
- * @returns {Promise<Syncro>} A promise which resolves with this Syncro instance on completion
265
- */
266
- set(key: string | object, value: any, options: {
267
- delta?: boolean;
268
- flush?: boolean;
269
- forceFlush?: boolean;
270
- flushDestroy?: boolean;
271
- }): Promise<this>;
272
- /**
273
- * Schedule Syncro heartbeats
274
- * This populates the `sync` presence meta-information
275
- *
276
- * @param {Boolean} [enable=true] Whether to enable heartbeats
277
- *
278
- * @param {Object} [options] Additional options to mutate behaviour
279
- * @param {Boolean} [options.immediate=false] Fire a heartbeat as soon as this function is called, this is only really useful on mount
280
- * @returns {Promise|Void} A promise that resolves when completed (if `{immediate:true}`) or void
281
- */
282
- setHeartbeat(enable?: boolean, options?: any): Promise<void> | void;
283
- /**
284
- * Perform one heartbeat pulse to the server to indicate presence within this Syncro
285
- * This function is automatically called by a timer if `setHeartbeat(true)` (the default behaviour)
286
- *
287
- * @returns {Promise} A promise which resolves when the operation has completed
288
- */
289
- heartbeat(): Promise<void>;
290
- /**
291
- * Utility function to directly set this documents firestore state
292
- *
293
- * @param {Object} state The state to set / merge
294
- * @param {Object} [options] Additional options to mutate behaviour
295
- * @param {'merge'|'set'} [options.method='merge'] How to apply the new state. 'merge' (merge in partial data to an existing Syncro), 'set' (overwrite the entire Syncro state)
296
- *
297
- * @param {number} retries How many tries to take before erroring
298
- * @returns {Promise} A promise which resolves when the operation has completed
299
- */
300
- setFirestoreState(state: any, options?: {
301
- method?: 'merge' | 'set';
302
- }, retries?: number): Promise<void>;
303
- /**
304
- * Utility method to fetch the Firestore state for this Syncro
305
- * NOTE: This directly extracts the state of the Firestore, not its wrapping doc object returned by `FirestoreGetDoc`
306
- *
307
- * @returns {Promise<Object>} A promise which resolves to the Firestore state
308
- */
309
- getFirestoreState(): Promise<any>;
310
- /**
311
- * Set the Syncro dirty flag which gets passed to the server on the next heartbeat
312
- *
313
- * @see isDirty
314
- * @returns {Syncro} This chainable Syncro instance
315
- */
316
- markDirty(): this;
317
- /**
318
- * Force the server to flush state
319
- * This is only really useful for debugging as this happens automatically anyway
320
- *
321
- * @param {Object} [options] Additional options to mutate behaviour
322
- * @param {Boolean} [options.destroy=false] Instruct the server to also dispose of the Syncro state
323
- *
324
- * @returns {Promise} A promise which resolves when the operation has completed
325
- */
326
- flush(options?: any): Promise<void | null>;
327
- /**
328
- * Timer handle for heartbeats
329
- *
330
- * @type {any}
331
- */
332
- _heartbeatTimer: any;
333
- }
334
- /**
335
- * Build a chaotic random tree structure based on dice rolls
336
- * This function is mainly used for sync testing
337
- *
338
- * @param {Number} [depth=0] The current depth we are starting at, changes the nature of branches based on probability
339
- *
340
- * @returns {*} The current branch contents
341
- */
342
- export declare function randomBranch(depth?: number): any;
343
- export {};