@iebh/tera-fy 2.3.9 → 2.3.10
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 +7 -0
- package/dist/lib/syncro/entities.d.ts +3 -3
- package/dist/lib/syncro/entities.js +42 -38
- package/dist/lib/syncro/entities.js.map +1 -1
- package/dist/lib/syncro/keyed (Rhino's conflicted copy 2026-05-10).js +287 -0
- package/dist/lib/syncro/keyed.js (Rhino's conflicted copy 2026-05-10).map +1 -0
- package/dist/lib/syncro/syncro (Rhino's conflicted copy 2026-05-10).js +765 -0
- package/dist/lib/syncro/syncro.d (Rhino's conflicted copy 2026-05-10).ts +336 -0
- package/dist/lib/syncro/syncro.js (Rhino's conflicted copy 2026-05-10).map +1 -0
- package/dist/plugin.vue2.es2019 (Rhino's conflicted copy 2026-05-10).js +1271 -0
- package/lib/syncro/entities.ts +51 -47
- package/package.json +1 -1
package/lib/syncro/entities.ts
CHANGED
|
@@ -53,18 +53,18 @@ interface NamespaceRow {
|
|
|
53
53
|
interface SyncroEntityConfig {
|
|
54
54
|
singular: string;
|
|
55
55
|
initState: (args: {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
HYPERDRIVE: PostgresSql;
|
|
57
|
+
supabasey: BoundSupabaseyFunction;
|
|
58
|
+
id: string; // Primary ID for the entity
|
|
59
|
+
relation?: string; // Optional relation identifier (for namespaces, libraries)
|
|
60
60
|
}) => Promise<any>;
|
|
61
61
|
flushState: (args: {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
68
|
}) => Promise<any>; // Return type signifies completion/result of flush
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -79,45 +79,46 @@ type SyncroConfig = Record<string, SyncroEntityConfig>;
|
|
|
79
79
|
*
|
|
80
80
|
* @property {String} singular The singular noun for the item
|
|
81
81
|
* @property {Function} initState Function called to initialize state when Firestore has no existing document. Called as `({HYPERDRIVE:PostgresSql, supabasey:BoundSupabaseyFunction, id:String, relation?:string})` and expected to return the initial data object state
|
|
82
|
-
* @property {Function} flushState Function called to flush state from Firebase to
|
|
82
|
+
* @property {Function} flushState Function called to flush state from Firebase to Postgres. Called the same as `initState` + `{state:Object}`
|
|
83
83
|
*/
|
|
84
84
|
const syncroConfig: SyncroConfig = {
|
|
85
85
|
institutes: { // {{{
|
|
86
86
|
singular: 'institute',
|
|
87
87
|
async initState({HYPERDRIVE, id}: {HYPERDRIVE: PostgresSql, id: string}) {
|
|
88
|
-
let
|
|
88
|
+
let rows = await HYPERDRIVE`
|
|
89
89
|
SELECT data
|
|
90
90
|
FROM institutes
|
|
91
91
|
WHERE id = ${id}
|
|
92
92
|
LIMIT 1
|
|
93
93
|
`;
|
|
94
|
-
if (
|
|
95
|
-
return
|
|
94
|
+
if (rows.length > 0) {
|
|
95
|
+
return rows[0].data; // institute is valid and already exists
|
|
96
96
|
} else {
|
|
97
97
|
throw new Error(`Syncro institute "${id}" not found`);
|
|
98
98
|
}
|
|
99
99
|
},
|
|
100
|
-
flushState({
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
flushState({HYPERDRIVE, state, id}) {
|
|
101
|
+
return HYPERDRIVE`
|
|
102
|
+
SELECT syncro_merge_data(
|
|
103
|
+
table_name => 'institutes',
|
|
104
|
+
entity_id => ${id}::UUID,
|
|
105
|
+
new_data => ${HYPERDRIVE.json(state)}::JSONB
|
|
106
|
+
)
|
|
107
|
+
`;
|
|
107
108
|
},
|
|
108
109
|
}, // }}}
|
|
109
110
|
projects: { // {{{
|
|
110
111
|
singular: 'project',
|
|
111
112
|
async initState({HYPERDRIVE, supabasey, id}: {HYPERDRIVE: PostgresSql, supabasey: BoundSupabaseyFunction, id: string}) {
|
|
112
|
-
let
|
|
113
|
+
let rows = await HYPERDRIVE`
|
|
113
114
|
SELECT data
|
|
114
115
|
FROM projects
|
|
115
116
|
WHERE id = ${id}
|
|
116
117
|
LIMIT 1
|
|
117
118
|
`;
|
|
118
|
-
if (
|
|
119
|
+
if (rows.length == 0) throw new Error(`Syncro project "${id}" not found`);
|
|
119
120
|
|
|
120
|
-
const data =
|
|
121
|
+
const data = rows[0].data;
|
|
121
122
|
|
|
122
123
|
// MIGRATION - Move data.temp{} into Supabase files + add pointer to filename {{{
|
|
123
124
|
if (
|
|
@@ -177,13 +178,14 @@ const syncroConfig: SyncroConfig = {
|
|
|
177
178
|
|
|
178
179
|
return data;
|
|
179
180
|
},
|
|
180
|
-
flushState({
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
181
|
+
flushState({HYPERDRIVE, state, fsId}) {
|
|
182
|
+
return HYPERDRIVE`
|
|
183
|
+
SELECT syncro_merge_data(
|
|
184
|
+
table_name => 'projects',
|
|
185
|
+
entity_id => ${fsId}::UUID,
|
|
186
|
+
new_data => ${HYPERDRIVE.json(state)}::JSONB
|
|
187
|
+
)
|
|
188
|
+
`;
|
|
187
189
|
},
|
|
188
190
|
}, // }}}
|
|
189
191
|
project_libraries: { // {{{
|
|
@@ -250,25 +252,26 @@ const syncroConfig: SyncroConfig = {
|
|
|
250
252
|
throw new Error(`Syncro test "${id}" not found`);
|
|
251
253
|
}
|
|
252
254
|
},
|
|
253
|
-
flushState({
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
255
|
+
flushState({HYPERDRIVE, state, fsId}) {
|
|
256
|
+
return HYPERDRIVE`
|
|
257
|
+
SELECT syncro_merge_data(
|
|
258
|
+
table_name => 'test',
|
|
259
|
+
entity_id => ${fsId}::UUID,
|
|
260
|
+
new_data => ${HYPERDRIVE.json(state)}::JSONB
|
|
261
|
+
)
|
|
262
|
+
`;
|
|
260
263
|
},
|
|
261
264
|
}, // }}}
|
|
262
265
|
users: { // {{{
|
|
263
266
|
singular: 'user',
|
|
264
267
|
async initState({HYPERDRIVE, id}: {HYPERDRIVE: PostgresSql, id: string}) {
|
|
265
|
-
let
|
|
268
|
+
let rows = await HYPERDRIVE`
|
|
266
269
|
SELECT data
|
|
267
270
|
FROM users
|
|
268
271
|
WHERE id = ${id}
|
|
269
272
|
LIMIT 1
|
|
270
273
|
`;
|
|
271
|
-
if (
|
|
274
|
+
if (rows.length > 0) return rows[0].data; // User is valid and already exists
|
|
272
275
|
|
|
273
276
|
// User row doesn't already exist - this shouldn't happen if the user has correctly gone through the onboarding process
|
|
274
277
|
// but... *shrugs*, who knows
|
|
@@ -290,13 +293,14 @@ const syncroConfig: SyncroConfig = {
|
|
|
290
293
|
return newUser[0].data; // Return back the data that eventually got created - allowing for database triggers, default field values etc.
|
|
291
294
|
|
|
292
295
|
},
|
|
293
|
-
flushState({
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
296
|
+
flushState({HYPERDRIVE, state, fsId}) {
|
|
297
|
+
return HYPERDRIVE`
|
|
298
|
+
SELECT syncro_merge_data(
|
|
299
|
+
table_name => 'users',
|
|
300
|
+
entity_id => ${fsId}::UUID,
|
|
301
|
+
new_data => ${HYPERDRIVE.json(state)}::JSONB
|
|
302
|
+
)
|
|
303
|
+
`;
|
|
300
304
|
},
|
|
301
305
|
}, // }}}
|
|
302
306
|
};
|
package/package.json
CHANGED