@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.
- package/CHANGELOG.md +25 -0
- package/api.md +8 -11
- package/dist/plugin.vue2.es2019.js +7 -7
- package/dist/terafy.bootstrapper.es2019.js +2 -2
- package/dist/terafy.bootstrapper.js +2 -2
- package/dist/terafy.es2019.js +5 -5
- package/dist/terafy.js +5 -5
- package/eslint.config.js +4 -66
- package/lib/{projectFile.ts → projectFile.js} +52 -76
- package/lib/syncro/{entities.ts → entities.js} +14 -83
- package/lib/syncro/{keyed.ts → keyed.js} +46 -68
- package/lib/syncro/{syncro.ts → syncro.js} +104 -136
- package/lib/{terafy.bootstrapper.ts → terafy.bootstrapper.js} +20 -30
- package/lib/{terafy.client.ts → terafy.client.js} +85 -84
- package/lib/{terafy.proxy.ts → terafy.proxy.js} +12 -26
- package/lib/{terafy.server.ts → terafy.server.js} +204 -229
- package/package.json +20 -39
- package/plugins/{base.ts → base.js} +3 -5
- package/plugins/{firebase.ts → firebase.js} +22 -21
- package/plugins/{vite.ts → vite.js} +3 -3
- package/plugins/{vue2.ts → vue2.js} +8 -10
- package/plugins/{vue3.ts → vue3.js} +7 -10
- package/utils/mixin.js +15 -0
- package/utils/{pathTools.ts → pathTools.js} +8 -9
- package/widgets/tera-file-select.vue +1 -1
- package/dist/lib/projectFile.d.ts +0 -190
- package/dist/lib/projectFile.js +0 -305
- package/dist/lib/projectFile.js.map +0 -1
- package/dist/lib/syncro/entities.d.ts +0 -34
- package/dist/lib/syncro/entities.js +0 -212
- package/dist/lib/syncro/entities.js.map +0 -1
- package/dist/lib/syncro/keyed (Rhino's conflicted copy 2026-05-10).js +0 -287
- package/dist/lib/syncro/keyed.d.ts +0 -95
- package/dist/lib/syncro/keyed.js +0 -288
- package/dist/lib/syncro/keyed.js (Rhino's conflicted copy 2026-05-10).map +0 -1
- package/dist/lib/syncro/keyed.js.map +0 -1
- package/dist/lib/syncro/syncro (Rhino's conflicted copy 2026-05-10).js +0 -765
- package/dist/lib/syncro/syncro.d (Rhino's conflicted copy 2026-05-10).ts +0 -336
- package/dist/lib/syncro/syncro.d.ts +0 -343
- package/dist/lib/syncro/syncro.js +0 -771
- package/dist/lib/syncro/syncro.js (Rhino's conflicted copy 2026-05-10).map +0 -1
- package/dist/lib/syncro/syncro.js.map +0 -1
- package/dist/lib/terafy.bootstrapper.d.ts +0 -42
- package/dist/lib/terafy.bootstrapper.js +0 -129
- package/dist/lib/terafy.bootstrapper.js.map +0 -1
- package/dist/lib/terafy.client.d.ts +0 -555
- package/dist/lib/terafy.client.js +0 -1153
- package/dist/lib/terafy.client.js.map +0 -1
- package/dist/lib/terafy.proxy.d.ts +0 -66
- package/dist/lib/terafy.proxy.js +0 -130
- package/dist/lib/terafy.proxy.js.map +0 -1
- package/dist/lib/terafy.server.d.ts +0 -697
- package/dist/lib/terafy.server.js +0 -2062
- package/dist/lib/terafy.server.js.map +0 -1
- package/dist/plugin.vue2.es2019 (Rhino's conflicted copy 2026-05-10).js +0 -1271
- package/dist/plugins/base.d.ts +0 -20
- package/dist/plugins/base.js +0 -22
- package/dist/plugins/base.js.map +0 -1
- package/dist/plugins/firebase.d.ts +0 -62
- package/dist/plugins/firebase.js +0 -123
- package/dist/plugins/firebase.js.map +0 -1
- package/dist/plugins/vite.d.ts +0 -12
- package/dist/plugins/vite.js +0 -22
- package/dist/plugins/vite.js.map +0 -1
- package/dist/plugins/vue2.d.ts +0 -67
- package/dist/plugins/vue2.js +0 -104
- package/dist/plugins/vue2.js.map +0 -1
- package/dist/plugins/vue3.d.ts +0 -63
- package/dist/plugins/vue3.js +0 -93
- package/dist/plugins/vue3.js.map +0 -1
- package/dist/utils/mixin.d.ts +0 -11
- package/dist/utils/mixin.js +0 -15
- package/dist/utils/mixin.js.map +0 -1
- package/dist/utils/pDefer.d.ts +0 -16
- package/dist/utils/pDefer.js +0 -19
- package/dist/utils/pDefer.js.map +0 -1
- package/dist/utils/pathTools.d.ts +0 -70
- package/dist/utils/pathTools.js +0 -120
- package/dist/utils/pathTools.js.map +0 -1
- package/tsconfig.json +0 -30
- package/utils/mixin.ts +0 -18
- package/utils/pDefer.ts +0 -27
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import type TeraFy from './terafy.client.js';
|
|
5
|
-
|
|
6
|
-
// TODO: Refactor terafy.client.ts so that we don't need to extend the class with injected functions
|
|
7
|
-
interface TeraClient extends TeraFy {
|
|
8
|
-
getProjectFileContents: (id: any, options?: any) => any
|
|
9
|
-
setProjectFileContents: (id: any, contents: any, options?: any) => any
|
|
10
|
-
getProjectLibrary: (id: any, options?: any) => any
|
|
11
|
-
setProjectLibrary: (id: any, refs:any, options?: any) => any
|
|
12
|
-
};
|
|
13
|
-
type SupabaseFile = any;
|
|
14
|
-
type RefLibRef = any;
|
|
1
|
+
import {filesize} from 'filesize';
|
|
2
|
+
import {pick, omit} from 'lodash-es';
|
|
3
|
+
|
|
15
4
|
|
|
16
5
|
/**
|
|
17
6
|
* A project file fetched from TERA
|
|
@@ -21,10 +10,10 @@ export default class ProjectFile {
|
|
|
21
10
|
|
|
22
11
|
/**
|
|
23
12
|
* Parent TeraClient instance used by all helper functions
|
|
24
|
-
* @type {
|
|
13
|
+
* @type {Object}
|
|
25
14
|
* @private
|
|
26
15
|
*/
|
|
27
|
-
_tera
|
|
16
|
+
_tera;
|
|
28
17
|
|
|
29
18
|
|
|
30
19
|
/**
|
|
@@ -32,28 +21,28 @@ export default class ProjectFile {
|
|
|
32
21
|
* NOTE: This is computed each time from the Base64 of the file path
|
|
33
22
|
* @type {String}
|
|
34
23
|
*/
|
|
35
|
-
id
|
|
24
|
+
id;
|
|
36
25
|
|
|
37
26
|
|
|
38
27
|
/**
|
|
39
28
|
* The raw Supabase UUID of the file
|
|
40
29
|
* @type {String}
|
|
41
30
|
*/
|
|
42
|
-
sbId
|
|
31
|
+
sbId;
|
|
43
32
|
|
|
44
33
|
|
|
45
34
|
/**
|
|
46
35
|
* Relative name path (can contain prefix directories) for the human readable file name
|
|
47
36
|
* @type {String}
|
|
48
37
|
*/
|
|
49
|
-
name
|
|
38
|
+
name;
|
|
50
39
|
|
|
51
40
|
|
|
52
41
|
/**
|
|
53
42
|
* CSS class to use as the file icon
|
|
54
43
|
* @type {String}
|
|
55
44
|
*/
|
|
56
|
-
icon
|
|
45
|
+
icon;
|
|
57
46
|
|
|
58
47
|
|
|
59
48
|
/**
|
|
@@ -61,7 +50,7 @@ export default class ProjectFile {
|
|
|
61
50
|
* This is also used as the unique identifier within the project
|
|
62
51
|
* @type {String}
|
|
63
52
|
*/
|
|
64
|
-
path
|
|
53
|
+
path;
|
|
65
54
|
|
|
66
55
|
|
|
67
56
|
/**
|
|
@@ -69,7 +58,7 @@ export default class ProjectFile {
|
|
|
69
58
|
* This will usually open an edit UI within the TERA site
|
|
70
59
|
* @type {String}
|
|
71
60
|
*/
|
|
72
|
-
url
|
|
61
|
+
url;
|
|
73
62
|
|
|
74
63
|
|
|
75
64
|
/**
|
|
@@ -77,7 +66,7 @@ export default class ProjectFile {
|
|
|
77
66
|
* This is used to direct to the edit/view/download UI when the files project is active and is usually used in place of URL for TERA related operations
|
|
78
67
|
* @type {String}
|
|
79
68
|
*/
|
|
80
|
-
teraUrl
|
|
69
|
+
teraUrl;
|
|
81
70
|
|
|
82
71
|
|
|
83
72
|
/**
|
|
@@ -88,103 +77,101 @@ export default class ProjectFile {
|
|
|
88
77
|
* @property {String} ext The extension portion of the name (always lower case)
|
|
89
78
|
* @property {String} dirName The directory path portion of the name
|
|
90
79
|
*/
|
|
91
|
-
|
|
92
|
-
parsedName: any;
|
|
80
|
+
parsedName;
|
|
93
81
|
|
|
94
82
|
|
|
95
83
|
/**
|
|
96
84
|
* A date representing when the file was created
|
|
97
85
|
* @type {Date}
|
|
98
86
|
*/
|
|
99
|
-
|
|
100
|
-
created: Date | undefined;
|
|
87
|
+
created;
|
|
101
88
|
|
|
102
89
|
|
|
103
90
|
/**
|
|
104
91
|
* A human readable, formatted version of "created"
|
|
105
92
|
* @type {String}
|
|
106
93
|
*/
|
|
107
|
-
createdFormatted
|
|
94
|
+
createdFormatted;
|
|
108
95
|
|
|
109
96
|
|
|
110
97
|
/**
|
|
111
|
-
* A date representing when the file was
|
|
98
|
+
* A date representing when the file was modifed
|
|
112
99
|
* @type {Date}
|
|
113
100
|
*/
|
|
114
|
-
|
|
115
|
-
modified: Date | undefined;
|
|
101
|
+
modified;
|
|
116
102
|
|
|
117
103
|
|
|
118
104
|
/**
|
|
119
105
|
* A human readable, formatted version of "modified"
|
|
120
106
|
* @type {String}
|
|
121
107
|
*/
|
|
122
|
-
modifiedFormatted
|
|
108
|
+
modifiedFormatted;
|
|
123
109
|
|
|
124
110
|
|
|
125
111
|
/**
|
|
126
112
|
* A date representing when the file was last accessed
|
|
127
113
|
* @type {Date}
|
|
128
114
|
*/
|
|
129
|
-
|
|
130
|
-
accessed: Date | undefined;
|
|
115
|
+
accessed;
|
|
131
116
|
|
|
132
117
|
|
|
133
118
|
/**
|
|
134
119
|
* A human readable, formatted version of "accessed"
|
|
135
120
|
* @type {String}
|
|
136
121
|
*/
|
|
137
|
-
accessedFormatted
|
|
122
|
+
accessedFormatted;
|
|
138
123
|
|
|
139
124
|
|
|
140
125
|
/**
|
|
141
126
|
* Size, in bytes, of the file
|
|
142
127
|
* @type {Number}
|
|
143
128
|
*/
|
|
144
|
-
|
|
145
|
-
size: number | undefined;
|
|
129
|
+
size;
|
|
146
130
|
|
|
147
131
|
|
|
148
132
|
/**
|
|
149
133
|
* A human readable, formatted version of the file size
|
|
150
134
|
* @type {String}
|
|
151
135
|
*/
|
|
152
|
-
sizeFormatted
|
|
136
|
+
sizeFormatted;
|
|
153
137
|
|
|
154
138
|
|
|
155
139
|
/**
|
|
156
140
|
* The associated mime type for the file
|
|
157
141
|
* @type {String}
|
|
158
142
|
*/
|
|
159
|
-
mime
|
|
143
|
+
mime;
|
|
160
144
|
|
|
161
145
|
|
|
162
146
|
/**
|
|
163
147
|
* Additional meta information for the file
|
|
164
148
|
* @type {Object}
|
|
165
149
|
*/
|
|
166
|
-
|
|
167
|
-
|
|
150
|
+
meta = {};
|
|
151
|
+
|
|
168
152
|
|
|
169
153
|
/**
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
154
|
+
* Whether this is a folder or not
|
|
155
|
+
* @type {Boolean}
|
|
156
|
+
*/
|
|
157
|
+
isFolder;
|
|
158
|
+
|
|
173
159
|
|
|
174
160
|
/**
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
161
|
+
* If it is a folder, it will have an array of files in the folder
|
|
162
|
+
* @type {Array<ProjectFile>}
|
|
163
|
+
*/
|
|
164
|
+
files;
|
|
165
|
+
|
|
178
166
|
|
|
179
167
|
/**
|
|
180
168
|
* ProjectFile constructor
|
|
181
169
|
* Takes the input basic file type from Supabase and adds additional formatted fields
|
|
182
|
-
* @param {
|
|
183
|
-
* @param {
|
|
170
|
+
* @param {Object} baseFile The basic Supabase file to extend
|
|
171
|
+
* @param {Object} baseFile.tera The associated TeraFyClient instance to use for some file methods
|
|
184
172
|
*/
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
// Note: baseFile.tera is assumed to exist based on the check below and the SupabaseFile type definition above
|
|
173
|
+
constructor(baseFile) {
|
|
174
|
+
// Note: baseFile.tera is assumed to exist based on the check below
|
|
188
175
|
if (!baseFile.tera) throw new Error('Basic file requires a `tera` key to access the Tera instance');
|
|
189
176
|
Object.assign(this, omit(baseFile, 'encodeIdFunction')); // don't copy encodeIdFunction
|
|
190
177
|
|
|
@@ -194,7 +181,7 @@ export default class ProjectFile {
|
|
|
194
181
|
}
|
|
195
182
|
|
|
196
183
|
// Translate baseFile.tera -> this._tera (non-enumerable, non-configurable)
|
|
197
|
-
const tera =
|
|
184
|
+
const tera = this.tera;
|
|
198
185
|
Object.defineProperty(this, '_tera', {
|
|
199
186
|
enumerable: false,
|
|
200
187
|
configurable: false,
|
|
@@ -203,8 +190,7 @@ export default class ProjectFile {
|
|
|
203
190
|
return tera;
|
|
204
191
|
},
|
|
205
192
|
});
|
|
206
|
-
|
|
207
|
-
delete (this as any).tera; // Remove original ref we merged above
|
|
193
|
+
delete this.tera; // Remove original ref we merged above
|
|
208
194
|
|
|
209
195
|
// Ensure date properties are actual Date objects, not strings.
|
|
210
196
|
// This makes the class resilient to the format of the input data.
|
|
@@ -228,7 +214,7 @@ export default class ProjectFile {
|
|
|
228
214
|
url = url.replace(/\/project\/download\//, '/project/library/');
|
|
229
215
|
}
|
|
230
216
|
return new ProjectFile({
|
|
231
|
-
tera
|
|
217
|
+
tera,
|
|
232
218
|
...file,
|
|
233
219
|
sbId: file.id, // Sash the original Supabase ID under sbId
|
|
234
220
|
id: file.path,
|
|
@@ -244,7 +230,7 @@ export default class ProjectFile {
|
|
|
244
230
|
this.teraUrl = this.url.replace(/^https?:\/\/(?:.+?)\/projects\/(?:.+?)\/project\/(.+)$/, '/project/$1');
|
|
245
231
|
|
|
246
232
|
// Set all `*Formatted` fields
|
|
247
|
-
this.sizeFormatted = filesize(this.size || 0, {
|
|
233
|
+
this.sizeFormatted = filesize(this.size || 0, {spacer: ''});
|
|
248
234
|
this.createdFormatted = this.created ? this.created.toLocaleDateString() : 'Unknown created date';
|
|
249
235
|
this.modifiedFormatted = this.modified ? this.modified.toLocaleDateString() : 'Unknown modified date';
|
|
250
236
|
this.accessedFormatted = this.accessed ? this.accessed.toLocaleDateString() : 'Unknown access date';
|
|
@@ -260,9 +246,7 @@ export default class ProjectFile {
|
|
|
260
246
|
*
|
|
261
247
|
* @see getProjectFile()
|
|
262
248
|
*/
|
|
263
|
-
|
|
264
|
-
getContents(options?: any): Promise<Blob> {
|
|
265
|
-
// Assuming _tera has this method and it returns Promise<Blob>
|
|
249
|
+
getContents(options) {
|
|
266
250
|
return this._tera.getProjectFileContents(this.id, options);
|
|
267
251
|
}
|
|
268
252
|
|
|
@@ -276,9 +260,7 @@ export default class ProjectFile {
|
|
|
276
260
|
*
|
|
277
261
|
* @see setProjectFileContents()
|
|
278
262
|
*/
|
|
279
|
-
|
|
280
|
-
setContents(contents: File | Blob | FormData | object | any[]): Promise<void> {
|
|
281
|
-
// Assuming _tera has this method and it returns Promise<void> or similar
|
|
263
|
+
setContents(contents) {
|
|
282
264
|
return this._tera.setProjectFileContents(this.id, contents, {});
|
|
283
265
|
}
|
|
284
266
|
|
|
@@ -286,13 +268,11 @@ export default class ProjectFile {
|
|
|
286
268
|
/**
|
|
287
269
|
* Fetch the file contents as an array of Reflib refs
|
|
288
270
|
*
|
|
289
|
-
* @returns {Promise<Array
|
|
271
|
+
* @returns {Promise<Array>} An eventual array of RefLib references
|
|
290
272
|
*
|
|
291
273
|
* @see getProjectLibrary()
|
|
292
274
|
*/
|
|
293
|
-
|
|
294
|
-
getRefs(): Promise<Array<RefLibRef>> {
|
|
295
|
-
// Assuming _tera has this method and it returns Promise<Array<RefLibRef>>
|
|
275
|
+
getRefs() {
|
|
296
276
|
return this._tera.getProjectLibrary(this.id);
|
|
297
277
|
}
|
|
298
278
|
|
|
@@ -300,15 +280,13 @@ export default class ProjectFile {
|
|
|
300
280
|
/**
|
|
301
281
|
* Overwrite the contents of a file with a new collection of Reflib refs
|
|
302
282
|
*
|
|
303
|
-
* @param {Array
|
|
283
|
+
* @param {Array} refs Collection of references for the selected library
|
|
304
284
|
*
|
|
305
285
|
* @returns {Promise<void>} A promise which resolves when the operation has completed
|
|
306
286
|
*
|
|
307
287
|
* @see setProjectLibrary()
|
|
308
288
|
*/
|
|
309
|
-
|
|
310
|
-
setRefs(refs: Array<RefLibRef>): Promise<void> {
|
|
311
|
-
// Assuming _tera has this method and it returns Promise<void> or similar
|
|
289
|
+
setRefs(refs) {
|
|
312
290
|
return this._tera.setProjectLibrary(this.id, refs);
|
|
313
291
|
}
|
|
314
292
|
|
|
@@ -320,8 +298,7 @@ export default class ProjectFile {
|
|
|
320
298
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
|
|
321
299
|
* @returns {Object} A Structured Clone compatible representation of this ProjectFile instance
|
|
322
300
|
*/
|
|
323
|
-
|
|
324
|
-
serialize(): Partial<ProjectFile> { // Using Partial<ProjectFile> as it returns a subset
|
|
301
|
+
serialize() {
|
|
325
302
|
return pick(this, [
|
|
326
303
|
'id',
|
|
327
304
|
'sbId',
|
|
@@ -349,8 +326,7 @@ export default class ProjectFile {
|
|
|
349
326
|
* @param {Object} data An input object created via `ProjectFiles.serialize()` (MUST include a 'tera' property added manually)
|
|
350
327
|
* @returns {ProjectFile} A ProjectFile instance setup against the deserialized data
|
|
351
328
|
*/
|
|
352
|
-
|
|
353
|
-
static deserialize(data: any): ProjectFile {
|
|
329
|
+
static deserialize(data) {
|
|
354
330
|
// TODO: Check the below
|
|
355
331
|
// WARNING: The original 'serialize' method does NOT include 'tera'.
|
|
356
332
|
// The caller of 'deserialize' MUST add the correct 'tera' instance to the 'data' object
|
|
@@ -378,4 +354,4 @@ export default class ProjectFile {
|
|
|
378
354
|
]);
|
|
379
355
|
return new ProjectFile(constructorArg);
|
|
380
356
|
}
|
|
381
|
-
}
|
|
357
|
+
}
|
|
@@ -1,75 +1,6 @@
|
|
|
1
|
-
/* eslint-disable jsdoc/reject-function-type, no-unused-vars */
|
|
2
|
-
// @ts-expect-error TODO: Remove when reflib gets declaration file
|
|
3
1
|
import Reflib from '@iebh/reflib';
|
|
4
2
|
import {v4 as uuid4} from 'uuid';
|
|
5
3
|
import {nanoid} from 'nanoid';
|
|
6
|
-
import {BoundSupabaseyFunction} from '@iebh/supabasey';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// Minimal interface for a postgres-npm Sql instance (HYPERDRIVE is injected by the Cloudflare Worker runtime)
|
|
10
|
-
export interface PostgresSql {
|
|
11
|
-
(strings: TemplateStringsArray, ...values: any[]): Promise<any[]>;
|
|
12
|
-
json(value: any): any;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// DATABASE TABLE TYPE DEFINITIONS {{{
|
|
17
|
-
interface ProjectRow {
|
|
18
|
-
data: {
|
|
19
|
-
id: string;
|
|
20
|
-
// TODO: add other properties in project data
|
|
21
|
-
};
|
|
22
|
-
// TODO: Define other columns in project table
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface InstituteRow {
|
|
26
|
-
data: any;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface UserRow {
|
|
30
|
-
id: string;
|
|
31
|
-
data: {
|
|
32
|
-
id: string;
|
|
33
|
-
credits: number;
|
|
34
|
-
[key: string]: any;
|
|
35
|
-
// TODO: add other properties in user data
|
|
36
|
-
};
|
|
37
|
-
// TODO: Define other columns in user table
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface NamespaceRow {
|
|
41
|
-
project: string;
|
|
42
|
-
name: string;
|
|
43
|
-
data: {
|
|
44
|
-
[key: string]: any;
|
|
45
|
-
// TODO: add other properties in namespace data
|
|
46
|
-
};
|
|
47
|
-
// TODO: Define other columns in namespace table
|
|
48
|
-
}
|
|
49
|
-
// }}}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// Interface for each syncro entity config
|
|
53
|
-
interface SyncroEntityConfig {
|
|
54
|
-
singular: string;
|
|
55
|
-
initState: (args: {
|
|
56
|
-
HYPERDRIVE: PostgresSql;
|
|
57
|
-
supabasey: BoundSupabaseyFunction;
|
|
58
|
-
id: string; // Primary ID for the entity
|
|
59
|
-
relation?: string; // Optional relation identifier (for namespaces, libraries)
|
|
60
|
-
}) => Promise<any>;
|
|
61
|
-
flushState: (args: {
|
|
62
|
-
HYPERDRIVE: PostgresSql;
|
|
63
|
-
supabasey?: BoundSupabaseyFunction;
|
|
64
|
-
state: any; // The state object to flush
|
|
65
|
-
id?: string; // Primary ID (used in some lookups like namespaces)
|
|
66
|
-
fsId?: string; // ID often passed to Supabase RPCs (might be same as 'id')
|
|
67
|
-
relation?: string; // Optional relation identifier
|
|
68
|
-
}) => Promise<any>; // Return type signifies completion/result of flush
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
type SyncroConfig = Record<string, SyncroEntityConfig>;
|
|
73
4
|
|
|
74
5
|
|
|
75
6
|
/**
|
|
@@ -78,13 +9,13 @@ type SyncroConfig = Record<string, SyncroEntityConfig>;
|
|
|
78
9
|
* @type {Object} An object lookup of entities
|
|
79
10
|
*
|
|
80
11
|
* @property {String} singular The singular noun for the item
|
|
81
|
-
* @property {Function} initState Function called to initialize state when Firestore has no existing document. Called as `({HYPERDRIVE
|
|
82
|
-
* @property {Function} flushState Function called to flush state from Firebase to Postgres. Called the same as `initState` + `{state
|
|
12
|
+
* @property {Function} initState Function called to initialize state when Firestore has no existing document. Called as `({HYPERDRIVE, supabasey, id, relation?})` and expected to return the initial data object state
|
|
13
|
+
* @property {Function} flushState Function called to flush state from Firebase to Postgres. Called the same as `initState` + `{state}`
|
|
83
14
|
*/
|
|
84
|
-
const syncroConfig
|
|
15
|
+
const syncroConfig = {
|
|
85
16
|
institutes: { // {{{
|
|
86
17
|
singular: 'institute',
|
|
87
|
-
async initState({HYPERDRIVE, id}
|
|
18
|
+
async initState({HYPERDRIVE, id}) {
|
|
88
19
|
let rows = await HYPERDRIVE`
|
|
89
20
|
SELECT data
|
|
90
21
|
FROM institutes
|
|
@@ -109,7 +40,7 @@ const syncroConfig: SyncroConfig = {
|
|
|
109
40
|
}, // }}}
|
|
110
41
|
projects: { // {{{
|
|
111
42
|
singular: 'project',
|
|
112
|
-
async initState({HYPERDRIVE, supabasey, id}
|
|
43
|
+
async initState({HYPERDRIVE, supabasey, id}) {
|
|
113
44
|
let rows = await HYPERDRIVE`
|
|
114
45
|
SELECT data
|
|
115
46
|
FROM projects
|
|
@@ -123,7 +54,7 @@ const syncroConfig: SyncroConfig = {
|
|
|
123
54
|
// MIGRATION - Move data.temp{} into Supabase files + add pointer to filename {{{
|
|
124
55
|
if (
|
|
125
56
|
data.temp // Project contains temp subkey
|
|
126
|
-
&& Object.values(data.temp).some(
|
|
57
|
+
&& Object.values(data.temp).some(t => typeof t == 'object') // Some of the temp keys are objects
|
|
127
58
|
) {
|
|
128
59
|
console.log('[MIGRATION] tera-fy project v1 -> v2', data.temp);
|
|
129
60
|
const tempObject = data.temp;
|
|
@@ -139,7 +70,7 @@ const syncroConfig: SyncroConfig = {
|
|
|
139
70
|
console.log('[MIGRATION] Creating filename:', fileName);
|
|
140
71
|
|
|
141
72
|
return Promise.resolve()
|
|
142
|
-
.then(()=> supabasey(
|
|
73
|
+
.then(()=> supabasey(supabase => supabase // Split data.temp[toolKey] -> file {{{
|
|
143
74
|
.storage
|
|
144
75
|
.from('projects')
|
|
145
76
|
.upload(
|
|
@@ -190,20 +121,20 @@ const syncroConfig: SyncroConfig = {
|
|
|
190
121
|
}, // }}}
|
|
191
122
|
project_libraries: { // {{{
|
|
192
123
|
singular: 'project library',
|
|
193
|
-
async initState({id, relation, supabasey}
|
|
124
|
+
async initState({id, relation, supabasey}) {
|
|
194
125
|
if (!relation || !/_\*$/.test(relation)) throw new Error('Project library relation missing, path should resemble "project_library::${PROJECT}::${LIBRARY_FILE_ID}_*"');
|
|
195
126
|
|
|
196
127
|
const fileId = relation.replace(/_\*$/, '');
|
|
197
128
|
|
|
198
|
-
const files = await supabasey(
|
|
129
|
+
const files = await supabasey(supabase => supabase
|
|
199
130
|
.storage
|
|
200
131
|
.from('projects')
|
|
201
132
|
.list(id))
|
|
202
133
|
|
|
203
|
-
const file = files?.find(
|
|
134
|
+
const file = files?.find(f => f.id == fileId);
|
|
204
135
|
if (!file) return Promise.reject(`Invalid file ID "${fileId}"`);
|
|
205
136
|
|
|
206
|
-
const blob = await supabasey(
|
|
137
|
+
const blob = await supabasey(supabase => supabase
|
|
207
138
|
.storage
|
|
208
139
|
.from('projects')
|
|
209
140
|
.download(`${id}/${file.name}`))
|
|
@@ -218,7 +149,7 @@ const syncroConfig: SyncroConfig = {
|
|
|
218
149
|
})
|
|
219
150
|
|
|
220
151
|
return Object.fromEntries(refs // Transform Reflib Ref array into a keyed UUID object
|
|
221
|
-
.map(
|
|
152
|
+
.map(ref => [ // Construct Object.fromEntries() compatible object [key, val] tuple
|
|
222
153
|
uuid4(), // TODO: This should really be using V5 with some-kind of namespacing but I can't get my head around the documentation - MC 2025-02-21
|
|
223
154
|
ref, // The actual ref payload
|
|
224
155
|
])
|
|
@@ -239,7 +170,7 @@ const syncroConfig: SyncroConfig = {
|
|
|
239
170
|
}, // }}}
|
|
240
171
|
test: { // {{{
|
|
241
172
|
singular: 'test',
|
|
242
|
-
async initState({HYPERDRIVE, id}
|
|
173
|
+
async initState({HYPERDRIVE, id}) {
|
|
243
174
|
let rows = await HYPERDRIVE`
|
|
244
175
|
SELECT data
|
|
245
176
|
FROM test
|
|
@@ -264,7 +195,7 @@ const syncroConfig: SyncroConfig = {
|
|
|
264
195
|
}, // }}}
|
|
265
196
|
users: { // {{{
|
|
266
197
|
singular: 'user',
|
|
267
|
-
async initState({HYPERDRIVE, id}
|
|
198
|
+
async initState({HYPERDRIVE, id}) {
|
|
268
199
|
let rows = await HYPERDRIVE`
|
|
269
200
|
SELECT data
|
|
270
201
|
FROM users
|