@iebh/tera-fy 2.0.14 → 2.0.15
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/lib/syncro/entities.js +20 -15
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.0.15](https://github.com/IEBH/TERA-fy/compare/v2.0.14...v2.0.15) (2025-03-19)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### refactor
|
|
7
|
+
|
|
8
|
+
* Switch from Syncro.wrapSupabase() -> NPM:@iebh/supabasey handling ([23e3805](https://github.com/IEBH/TERA-fy/commit/23e3805aecb70e130a727028df27c0d269d4d603))
|
|
9
|
+
|
|
3
10
|
## [2.0.14](https://github.com/IEBH/TERA-fy/compare/v2.0.13...v2.0.14) (2025-03-16)
|
|
4
11
|
|
|
5
12
|
|
package/lib/syncro/entities.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import Reflib from '@iebh/reflib';
|
|
2
2
|
import {v4 as uuid4} from 'uuid';
|
|
3
3
|
import {nanoid} from 'nanoid';
|
|
4
|
-
import Syncro from './syncro.js';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Entities we support Syncro paths for, each should correspond directly with a Firebase/Firestore collection name
|
|
@@ -9,14 +8,14 @@ import Syncro from './syncro.js';
|
|
|
9
8
|
* @type {Object} An object lookup of entities
|
|
10
9
|
*
|
|
11
10
|
* @property {String} singular The singular noun for the item
|
|
12
|
-
* @property {Function} initState Function called to initialize state when Firestore has no existing document. Called as `({supabase:
|
|
11
|
+
* @property {Function} initState Function called to initialize state when Firestore has no existing document. Called as `({supabase:Supabasey, entity:String, id:String, relation?:string})` and expected to return the initial data object state
|
|
13
12
|
* @property {Function} flushState Function called to flush state from Firebase to Supabase. Called the same as `initState` + `{state:Object}`
|
|
14
13
|
*/
|
|
15
14
|
export default {
|
|
16
15
|
projects: { // {{{
|
|
17
16
|
singular: 'project',
|
|
18
17
|
async initState({supabase, id}) {
|
|
19
|
-
let data = await
|
|
18
|
+
let data = await supabase(s => s
|
|
20
19
|
.from('projects')
|
|
21
20
|
.select('data')
|
|
22
21
|
.maybeSingle()
|
|
@@ -43,7 +42,7 @@ export default {
|
|
|
43
42
|
console.log('[MIGRATION] Creating filename:', fileName);
|
|
44
43
|
|
|
45
44
|
return Promise.resolve()
|
|
46
|
-
.then(()=>
|
|
45
|
+
.then(()=> supabase(s => s // Split data.temp[toolKey] -> file {{{
|
|
47
46
|
.from('projects')
|
|
48
47
|
.upload(
|
|
49
48
|
`${id}/${fileName}`,
|
|
@@ -82,7 +81,7 @@ export default {
|
|
|
82
81
|
return data;
|
|
83
82
|
},
|
|
84
83
|
flushState({supabase, state, fsId}) {
|
|
85
|
-
return
|
|
84
|
+
return supabase(s => s.rpc('syncro_merge_data', {
|
|
86
85
|
table_name: 'projects',
|
|
87
86
|
entity_id: fsId,
|
|
88
87
|
new_data: state,
|
|
@@ -97,13 +96,13 @@ export default {
|
|
|
97
96
|
let fileId = relation.replace(/_\*$/, '');
|
|
98
97
|
|
|
99
98
|
return Promise.resolve()
|
|
100
|
-
.then(()=>
|
|
99
|
+
.then(()=> supabase(s => s.storage
|
|
101
100
|
.from('projects')
|
|
102
101
|
.list(id)
|
|
103
102
|
))
|
|
104
103
|
.then(files => files.find(f => f.id == fileId))
|
|
105
104
|
.then(file => file || Promise.reject(`Invalid file ID "${fileId}"`))
|
|
106
|
-
.then(file =>
|
|
105
|
+
.then(file => supabase(s => s.storage
|
|
107
106
|
.from('projects')
|
|
108
107
|
.download(`${id}/${file.name}`)
|
|
109
108
|
)
|
|
@@ -130,7 +129,8 @@ export default {
|
|
|
130
129
|
singular: 'project namespace',
|
|
131
130
|
initState({supabase, id, relation}) {
|
|
132
131
|
if (!relation) throw new Error('Project namespace relation missing, path should resemble "project_namespaces::${PROJECT}::${RELATION}"');
|
|
133
|
-
return
|
|
132
|
+
return supabase(s => s
|
|
133
|
+
.from('project_namespaces')
|
|
134
134
|
.select('data')
|
|
135
135
|
.limit(1)
|
|
136
136
|
.eq('project', id)
|
|
@@ -138,7 +138,8 @@ export default {
|
|
|
138
138
|
)
|
|
139
139
|
.then(rows => rows.length == 1
|
|
140
140
|
? rows[0]
|
|
141
|
-
:
|
|
141
|
+
: supabase(s => s
|
|
142
|
+
.from('project_namespaces') // Doesn't exist - create it
|
|
142
143
|
.insert({
|
|
143
144
|
project: id,
|
|
144
145
|
name: relation,
|
|
@@ -150,7 +151,8 @@ export default {
|
|
|
150
151
|
.then(item => item.data);
|
|
151
152
|
},
|
|
152
153
|
flushState({supabase, state, id, relation}) {
|
|
153
|
-
return
|
|
154
|
+
return supabase(s => s
|
|
155
|
+
.from('project_namespaces')
|
|
154
156
|
.update({
|
|
155
157
|
edited_at: new Date(),
|
|
156
158
|
data: state,
|
|
@@ -163,7 +165,8 @@ export default {
|
|
|
163
165
|
test: { // {{{
|
|
164
166
|
singular: 'test',
|
|
165
167
|
initState({supabase, id}) {
|
|
166
|
-
return
|
|
168
|
+
return supabase(s => s
|
|
169
|
+
.from('test')
|
|
167
170
|
.select('data')
|
|
168
171
|
.limit(1)
|
|
169
172
|
.eq('id', id)
|
|
@@ -172,7 +175,7 @@ export default {
|
|
|
172
175
|
.then(item => item.data);
|
|
173
176
|
},
|
|
174
177
|
flushState({supabase, state, fsId}) {
|
|
175
|
-
return
|
|
178
|
+
return supabase(s => s.rpc('syncro_merge_data', {
|
|
176
179
|
table_name: 'test',
|
|
177
180
|
entity_id: fsId,
|
|
178
181
|
new_data: state,
|
|
@@ -182,7 +185,8 @@ export default {
|
|
|
182
185
|
users: { // {{{
|
|
183
186
|
singular: 'user',
|
|
184
187
|
initState({supabase, id}) {
|
|
185
|
-
return
|
|
188
|
+
return supabase(s => s
|
|
189
|
+
.from('users')
|
|
186
190
|
.select('data')
|
|
187
191
|
.limit(1)
|
|
188
192
|
.maybeSingle()
|
|
@@ -192,7 +196,8 @@ export default {
|
|
|
192
196
|
if (user) return user.data; // User is valid and already exists
|
|
193
197
|
|
|
194
198
|
// User row doesn't already exist - need to create stub
|
|
195
|
-
return
|
|
199
|
+
return supabase(s => s
|
|
200
|
+
.from('users')
|
|
196
201
|
.insert({
|
|
197
202
|
id,
|
|
198
203
|
data: {
|
|
@@ -209,7 +214,7 @@ export default {
|
|
|
209
214
|
})
|
|
210
215
|
},
|
|
211
216
|
flushState({supabase, state, fsId}) {
|
|
212
|
-
return
|
|
217
|
+
return supabase(s => s.rpc('syncro_merge_data', {
|
|
213
218
|
table_name: 'users',
|
|
214
219
|
entity_id: fsId,
|
|
215
220
|
new_data: state,
|
package/package.json
CHANGED