@iebh/tera-fy 2.0.13 → 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 CHANGED
@@ -1,5 +1,19 @@
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
+
10
+ ## [2.0.14](https://github.com/IEBH/TERA-fy/compare/v2.0.13...v2.0.14) (2025-03-16)
11
+
12
+
13
+ ### fix
14
+
15
+ * Missing ID when creating blank user ([574aaa4](https://github.com/IEBH/TERA-fy/commit/574aaa4204b02b90405a83e99086b82fdfce8f3d))
16
+
3
17
  ## [2.0.13](https://github.com/IEBH/TERA-fy/compare/v2.0.12...v2.0.13) (2025-03-16)
4
18
 
5
19
 
@@ -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:SupabaseClient, entity:String, id:String, relation?:string})` and expected to return the initial data object state
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 Syncro.wrapSupabase(supabase
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(()=> Syncro.wrapSupabase(supabase.storage // Split data.temp[toolKey] -> file {{{
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 Syncro.wrapSupabase(supabase.rpc('syncro_merge_data', {
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(()=> Syncro.wrapSupabase(supabase.storage
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 => Syncro.wrapSupabase(supabase.storage
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 Syncro.wrapSupabase(supabase.from('project_namespaces')
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
- : Syncro.wrapSupabase(supabase.from('project_namespaces') // Doesn't exist - create it
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 Syncro.wrapSupabase(supabase.from('project_namespaces')
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 Syncro.wrapSupabase(supabase.from('test')
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 Syncro.wrapSupabase(supabase.rpc('syncro_merge_data', {
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 Syncro.wrapSupabase(supabase.from('users')
188
+ return supabase(s => s
189
+ .from('users')
186
190
  .select('data')
187
191
  .limit(1)
188
192
  .maybeSingle()
@@ -192,8 +196,10 @@ 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 Syncro.wrapSupabase(supabase.from('users')
199
+ return supabase(s => s
200
+ .from('users')
196
201
  .insert({
202
+ id,
197
203
  data: {
198
204
  id,
199
205
  data: { // Create user prototype data
@@ -208,7 +214,7 @@ export default {
208
214
  })
209
215
  },
210
216
  flushState({supabase, state, fsId}) {
211
- return Syncro.wrapSupabase(supabase.rpc('syncro_merge_data', {
217
+ return supabase(s => s.rpc('syncro_merge_data', {
212
218
  table_name: 'users',
213
219
  entity_id: fsId,
214
220
  new_data: state,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iebh/tera-fy",
3
- "version": "2.0.13",
3
+ "version": "2.0.15",
4
4
  "description": "TERA website worker",
5
5
  "scripts": {
6
6
  "dev": "esbuild --platform=browser --format=esm --bundle lib/terafy.client.js --outfile=dist/terafy.js --minify --serve --servedir=.",