@seedprotocol/sdk 0.1.73 → 0.1.75

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 (50) hide show
  1. package/dist/bin.js +1 -6
  2. package/dist/bin.js.map +1 -1
  3. package/dist/{constants-CtmwCBma.js → constants-B9hSFQXL.js} +3 -2
  4. package/dist/{constants-CtmwCBma.js.map → constants-B9hSFQXL.js.map} +1 -1
  5. package/dist/main.js +7542 -29
  6. package/dist/main.js.map +1 -1
  7. package/dist/{seed.schema.config-DfD4DkGq.js → seed.schema.config-BPJfo_5h.js} +9 -9
  8. package/dist/{seed.schema.config-DfD4DkGq.js.map → seed.schema.config-BPJfo_5h.js.map} +1 -1
  9. package/dist/src/analyzeInput.ts +102 -0
  10. package/dist/src/db.ts +0 -29
  11. package/dist/src/drizzle.ts +0 -4
  12. package/dist/src/getSchemaUidForModel.ts +27 -0
  13. package/dist/src/hydrateFromDb.ts +246 -230
  14. package/dist/src/item.ts +0 -1
  15. package/dist/src/propertyMachine.ts +3 -14
  16. package/dist/src/request.ts +0 -9
  17. package/dist/src/saveImageSrc.ts +0 -4
  18. package/dist/src/services.ts +0 -3
  19. package/dist/src/updateItemPropertyValue.ts +1 -0
  20. package/dist/src/waitForFiles.ts +33 -0
  21. package/dist/src/write.ts +8 -0
  22. package/dist/types/src/browser/db/read/getSchemaUidForModel.d.ts +2 -0
  23. package/dist/types/src/browser/db/read/getSchemaUidForModel.d.ts.map +1 -0
  24. package/dist/types/src/browser/db/write/updateItemPropertyValue.d.ts.map +1 -1
  25. package/dist/types/src/browser/db/write.d.ts.map +1 -1
  26. package/dist/types/src/browser/events/item/request.d.ts.map +1 -1
  27. package/dist/types/src/browser/item/Item.d.ts.map +1 -1
  28. package/dist/types/src/browser/property/ItemProperty.d.ts +2 -2
  29. package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts +4 -1
  30. package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts.map +1 -1
  31. package/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts +5 -0
  32. package/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts.map +1 -0
  33. package/dist/types/src/browser/property/actors/saveValueToDb/index.d.ts +1 -4
  34. package/dist/types/src/browser/property/actors/saveValueToDb/index.d.ts.map +1 -1
  35. package/dist/types/src/browser/property/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
  36. package/dist/types/src/browser/property/propertyMachine.d.ts.map +1 -1
  37. package/dist/types/src/browser/react/item.d.ts.map +1 -1
  38. package/dist/types/src/browser/react/services.d.ts.map +1 -1
  39. package/dist/types/src/browser/services/db/actors/waitForFiles.d.ts +4 -0
  40. package/dist/types/src/browser/services/db/actors/waitForFiles.d.ts.map +1 -0
  41. package/dist/types/src/node/codegen/drizzle.d.ts.map +1 -1
  42. package/dist/types/src/node/constants.d.ts.map +1 -1
  43. package/dist/types/src/node/webpack/index.d.ts.map +1 -1
  44. package/dist/types/src/shared/helpers/constants.d.ts.map +1 -1
  45. package/dist/types/src/shared/helpers/db.d.ts.map +1 -1
  46. package/package.json +1 -1
  47. package/dist/index-BmDmbqJM.js +0 -7600
  48. package/dist/index-BmDmbqJM.js.map +0 -1
  49. package/dist/index-Clo50o_L.js +0 -32
  50. package/dist/index-Clo50o_L.js.map +0 -1
@@ -1,277 +1,293 @@
1
1
  import { EventObject, fromCallback } from 'xstate'
2
- import { propertyMachine } from '../propertyMachine'
3
2
  import { and, eq, or, sql } from 'drizzle-orm'
4
- import { escapeSqliteString } from '@/shared/helpers/db'
5
3
  import debug from 'debug'
6
4
  import { fs } from '@zenfs/core'
7
5
  import { metadata } from 'src/shared/seedSchema'
8
6
  import { getAppDb } from '@/browser/db/sqlWasmClient'
9
7
  import { updateMetadata } from '@/browser/db/write/updateMetadata'
8
+ import { FromCallbackInput } from '@/types/machines'
9
+ import { PropertyMachineContext } from '@/types/property'
10
10
 
11
11
  const logger = debug('app:property:actors:hydrateFromDb')
12
12
 
13
- export const hydrateFromDb = fromCallback<EventObject, typeof propertyMachine>(
14
- ({ sendBack, input: { context } }) => {
15
- const {
16
- seedUid,
17
- seedLocalId,
18
- propertyName: propertyNameRaw,
19
- propertyValue,
20
- propertyRecordSchema,
21
- itemModelName,
22
- } = context
23
-
24
- let propertyName = propertyNameRaw
13
+ export const hydrateFromDb = fromCallback<
14
+ EventObject,
15
+ FromCallbackInput<PropertyMachineContext, EventObject>
16
+ >(({ sendBack, input: { context } }) => {
17
+ const {
18
+ seedUid,
19
+ seedLocalId,
20
+ propertyName: propertyNameRaw,
21
+ propertyValue,
22
+ propertyRecordSchema,
23
+ itemModelName,
24
+ } = context
25
+
26
+ let propertyName = propertyNameRaw
27
+
28
+ if (
29
+ propertyRecordSchema &&
30
+ propertyRecordSchema.ref &&
31
+ propertyRecordSchema.dataType === 'Relation' &&
32
+ !propertyNameRaw.endsWith('Id')
33
+ ) {
34
+ propertyName = propertyNameRaw + 'Id'
35
+ }
36
+
37
+ if (
38
+ propertyRecordSchema &&
39
+ propertyRecordSchema.ref &&
40
+ propertyRecordSchema.dataType === 'List' &&
41
+ !propertyNameRaw.endsWith('Ids')
42
+ ) {
43
+ propertyName = propertyNameRaw + 'Ids'
44
+ }
45
+
46
+ const _hydrateFromDb = async () => {
47
+ const appDb = getAppDb()
48
+
49
+ const whereClauses = []
50
+
51
+ let hydrateQuery
52
+ // let safeValue = propertyValue
53
+ // let propertyValueQueryString = `property_value `
54
+ // let propertyNameQueryString = `property_name = '${propertyName}'`
55
+ let propertyNameQuery = eq(metadata.propertyName, propertyName)
56
+
57
+ // if (safeValue && typeof propertyValue === 'string') {
58
+ // safeValue = escapeSqliteString(propertyValue)
59
+ // propertyValueQueryString += `= '${safeValue}'`
60
+ // }
61
+
62
+ // if (!safeValue) {
63
+ // propertyValueQueryString += 'IS NULL'
64
+ // }
65
+
66
+ // if (typeof propertyValue === 'number') {
67
+ // propertyValueQueryString += `= ${propertyValue}`
68
+ // }
25
69
 
26
70
  if (
27
71
  propertyRecordSchema &&
28
72
  propertyRecordSchema.ref &&
29
- propertyRecordSchema.dataType === 'Relation' &&
30
- !propertyNameRaw.endsWith('Id')
73
+ propertyRecordSchema.dataType === 'Relation'
31
74
  ) {
32
- propertyName = propertyNameRaw + 'Id'
33
- }
34
-
35
- if (
36
- propertyRecordSchema &&
37
- propertyRecordSchema.ref &&
38
- propertyRecordSchema.dataType === 'List' &&
39
- !propertyNameRaw.endsWith('Ids')
40
- ) {
41
- propertyName = propertyNameRaw + 'Ids'
42
- }
43
-
44
- const _hydrateFromDb = async () => {
45
- const db = getAppDb()
46
-
47
- let hydrateQuery
48
- let safeValue = propertyValue
49
- let propertyValueQueryString = `property_value `
50
- let propertyNameQueryString = `property_name = '${propertyName}'`
51
- let propertyNameQuery = eq(metadata.propertyName, propertyName)
52
-
53
- if (safeValue && typeof propertyValue === 'string') {
54
- safeValue = escapeSqliteString(propertyValue)
55
- propertyValueQueryString += `= '${safeValue}'`
56
- }
57
-
58
- if (!safeValue) {
59
- propertyValueQueryString += 'IS NULL'
75
+ let missingPropertyNameVariant
76
+ if (propertyName.endsWith('Id')) {
77
+ missingPropertyNameVariant = propertyName.slice(0, -2)
60
78
  }
61
-
62
- if (typeof propertyValue === 'number') {
63
- propertyValueQueryString += `= ${propertyValue}`
79
+ if (!propertyName.endsWith('Id')) {
80
+ missingPropertyNameVariant = propertyName + 'Id'
64
81
  }
65
-
66
- if (
67
- propertyRecordSchema &&
68
- propertyRecordSchema.ref &&
69
- propertyRecordSchema.dataType === 'Relation'
70
- ) {
71
- let missingPropertyNameVariant
72
- if (propertyName.endsWith('Id')) {
73
- missingPropertyNameVariant = propertyName.slice(0, -2)
74
- }
75
- if (!propertyName.endsWith('Id')) {
76
- missingPropertyNameVariant = propertyName + 'Id'
77
- }
78
- propertyNameQuery = or(
79
- eq(metadata.propertyName, propertyName),
80
- eq(metadata.propertyName, missingPropertyNameVariant),
82
+ if (missingPropertyNameVariant) {
83
+ whereClauses.push(
84
+ or(
85
+ eq(metadata.propertyName, propertyName),
86
+ eq(metadata.propertyName, missingPropertyNameVariant),
87
+ ),
81
88
  )
89
+ // propertyNameQuery = or(
90
+ // eq(metadata.propertyName, propertyName),
91
+ // eq(metadata.propertyName, missingPropertyNameVariant),
92
+ // )
82
93
  }
83
-
84
- const selectFromStatement = db.select().from(metadata)
85
-
86
- if (seedUid && !seedLocalId) {
87
- hydrateQuery = selectFromStatement.where(
88
- and(eq(metadata.seedUid, seedUid), propertyNameQuery),
89
- )
94
+ if (!missingPropertyNameVariant) {
95
+ whereClauses.push(eq(metadata.propertyName, propertyName))
90
96
  }
97
+ }
91
98
 
92
- if (seedUid && seedLocalId) {
93
- hydrateQuery = selectFromStatement.where(
94
- and(
95
- eq(metadata.seedLocalId, seedLocalId),
96
- eq(metadata.seedUid, seedUid),
97
- propertyNameQuery,
98
- ),
99
- )
100
- }
99
+ // if (seedUid && !seedLocalId) {
100
+ // hydrateQuery = selectFromStatement.where(
101
+ // and(eq(metadata.seedUid, seedUid), propertyNameQuery),
102
+ // )
103
+ // }
104
+
105
+ if (seedUid) {
106
+ // hydrateQuery = selectFromStatement.where(
107
+ // and(
108
+ // eq(metadata.seedLocalId, seedLocalId),
109
+ // eq(metadata.seedUid, seedUid),
110
+ // propertyNameQuery,
111
+ // ),
112
+ // )
113
+ whereClauses.push(eq(metadata.seedUid, seedUid))
114
+ }
101
115
 
102
- if (!seedUid && seedLocalId) {
103
- hydrateQuery = selectFromStatement.where(
104
- and(eq(metadata.seedLocalId, seedLocalId), propertyNameQuery),
105
- )
106
- }
116
+ if (seedLocalId) {
117
+ // hydrateQuery = selectFromStatement.where(
118
+ // and(eq(metadata.seedLocalId, seedLocalId), propertyNameQuery),
119
+ // )
120
+ whereClauses.push(eq(metadata.seedLocalId, seedLocalId))
121
+ }
107
122
 
108
- if (!hydrateQuery) {
109
- return
110
- }
123
+ if (!hydrateQuery) {
124
+ return
125
+ }
111
126
 
112
- const rows = await hydrateQuery.orderBy(
113
- sql.raw('COALESCE(attestation_created_at, created_at) DESC'),
114
- )
127
+ const rows = await appDb
128
+ .select()
129
+ .from(metadata)
130
+ .where(and(...whereClauses))
131
+ .orderBy(sql.raw('COALESCE(attestation_created_at, created_at) DESC'))
115
132
 
116
- if (!rows || !rows.length) {
117
- return
118
- }
133
+ if (!rows || !rows.length) {
134
+ return
135
+ }
119
136
 
120
- const firstRow = rows[0]
121
-
122
- const {
123
- localId,
124
- uid,
125
- propertyName: propertyNameFromDb,
126
- propertyValue: propertyValueFromDb,
127
- seedLocalId: seedLocalIdFromDb,
128
- seedUid: seedUidFromDb,
129
- schemaUid: schemaUidFromDb,
130
- versionLocalId: versionLocalIdFromDb,
131
- versionUid: versionUidFromDb,
132
- refValueType,
133
- refResolvedValue,
134
- localStorageDir,
135
- } = firstRow
136
-
137
- let { refResolvedDisplayValue } = firstRow
138
-
139
- let propertyValueProcessed: string | string[] | undefined | null =
140
- propertyValueFromDb
141
-
142
- if (propertyName && !propertyNameFromDb) {
143
- logger(
144
- `Property name from code is ${propertyName} but has not value in db ${propertyNameFromDb} for Property.${localId}`,
145
- )
146
- }
137
+ const firstRow = rows[0]
147
138
 
148
- if (
149
- propertyName &&
150
- propertyNameFromDb &&
151
- !propertyNameFromDb.includes(propertyName) &&
152
- !propertyName.includes(propertyNameFromDb) &&
153
- propertyNameFromDb !== propertyName
154
- ) {
155
- logger(
156
- `Property name from db ${propertyNameFromDb} does not match property name ${propertyName} for Property.${localId}`,
157
- )
158
- }
139
+ const {
140
+ localId,
141
+ uid,
142
+ propertyName: propertyNameFromDb,
143
+ propertyValue: propertyValueFromDb,
144
+ seedLocalId: seedLocalIdFromDb,
145
+ seedUid: seedUidFromDb,
146
+ schemaUid: schemaUidFromDb,
147
+ versionLocalId: versionLocalIdFromDb,
148
+ versionUid: versionUidFromDb,
149
+ refValueType,
150
+ refResolvedValue,
151
+ localStorageDir,
152
+ } = firstRow
153
+
154
+ let { refResolvedDisplayValue } = firstRow
155
+
156
+ let propertyValueProcessed: string | string[] | undefined | null =
157
+ propertyValueFromDb
158
+
159
+ if (propertyName && !propertyNameFromDb) {
160
+ logger(
161
+ `Property name from code is ${propertyName} but has not value in db ${propertyNameFromDb} for Property.${localId}`,
162
+ )
163
+ }
159
164
 
160
- if (propertyValue && propertyValueFromDb !== propertyValue) {
161
- logger(
162
- `Property value from db ${propertyValueFromDb} does not match property value ${propertyValue} for Property.${localId}`,
163
- )
164
- }
165
+ if (
166
+ propertyName &&
167
+ propertyNameFromDb &&
168
+ !propertyNameFromDb.includes(propertyName) &&
169
+ !propertyName.includes(propertyNameFromDb) &&
170
+ propertyNameFromDb !== propertyName
171
+ ) {
172
+ logger(
173
+ `Property name from db ${propertyNameFromDb} does not match property name ${propertyName} for Property.${localId}`,
174
+ )
175
+ }
165
176
 
166
- if (seedLocalIdFromDb !== seedLocalId) {
167
- logger(
168
- `Seed local id from db ${seedLocalIdFromDb} does not match seed local id ${seedLocalId} for Property.${localId}`,
169
- )
170
- }
177
+ if (propertyValue && propertyValueFromDb !== propertyValue) {
178
+ logger(
179
+ `Property value from db ${propertyValueFromDb} does not match property value ${propertyValue} for Property.${localId}`,
180
+ )
181
+ }
171
182
 
172
- if (seedUidFromDb !== seedUid) {
173
- logger(
174
- `Seed uid from db ${seedUidFromDb} does not match seed uid ${seedUid} for Property.${localId}`,
175
- )
176
- }
183
+ if (seedLocalIdFromDb !== seedLocalId) {
184
+ logger(
185
+ `Seed local id from db ${seedLocalIdFromDb} does not match seed local id ${seedLocalId} for Property.${localId}`,
186
+ )
187
+ }
177
188
 
178
- if (
179
- refResolvedValue &&
180
- refResolvedDisplayValue &&
181
- refResolvedDisplayValue.includes('http')
182
- ) {
183
- let urlNeedsToBeRefreshed = false
189
+ if (seedUidFromDb !== seedUid) {
190
+ logger(
191
+ `Seed uid from db ${seedUidFromDb} does not match seed uid ${seedUid} for Property.${localId}`,
192
+ )
193
+ }
184
194
 
185
- try {
186
- const response = await fetch(refResolvedDisplayValue, {
187
- method: 'HEAD',
188
- })
195
+ if (
196
+ refResolvedValue &&
197
+ refResolvedDisplayValue &&
198
+ refResolvedDisplayValue.includes('http')
199
+ ) {
200
+ let urlNeedsToBeRefreshed = false
189
201
 
190
- // Check if the status is in the 200-299 range
191
- if (!response.ok) {
192
- urlNeedsToBeRefreshed = true
193
- }
194
- } catch (error) {
195
- urlNeedsToBeRefreshed = true
196
- }
202
+ try {
203
+ const response = await fetch(refResolvedDisplayValue, {
204
+ method: 'HEAD',
205
+ })
197
206
 
198
- if (urlNeedsToBeRefreshed) {
199
- let dir = localStorageDir
200
- if (
201
- !dir &&
202
- propertyRecordSchema &&
203
- propertyRecordSchema.refValueType === 'ImageSrc'
204
- ) {
205
- dir = 'images'
206
- }
207
- const filePath = `/files/${dir}/${refResolvedValue}`
208
- const fileExists = await fs.promises.exists(filePath)
209
- if (fileExists) {
210
- const fileContents = await fs.promises.readFile(filePath)
211
- const fileHandler = new File([fileContents], refResolvedValue)
212
- refResolvedDisplayValue = URL.createObjectURL(fileHandler)
213
- await updateMetadata({
214
- localId,
215
- refResolvedDisplayValue,
216
- })
217
- }
207
+ // Check if the status is in the 200-299 range
208
+ if (!response.ok) {
209
+ urlNeedsToBeRefreshed = true
218
210
  }
211
+ } catch (error) {
212
+ urlNeedsToBeRefreshed = true
219
213
  }
220
214
 
221
- if (
222
- propertyRecordSchema &&
223
- propertyRecordSchema.dataType === 'List' &&
224
- propertyRecordSchema.ref &&
225
- typeof propertyValueFromDb === 'string'
226
- ) {
227
- propertyValueProcessed = propertyValueFromDb.split(',')
215
+ if (urlNeedsToBeRefreshed) {
216
+ let dir = localStorageDir
217
+ if (
218
+ !dir &&
219
+ propertyRecordSchema &&
220
+ propertyRecordSchema.refValueType === 'ImageSrc'
221
+ ) {
222
+ dir = 'images'
223
+ }
224
+ const filePath = `/files/${dir}/${refResolvedValue}`
225
+ const fileExists = await fs.promises.exists(filePath)
226
+ if (fileExists) {
227
+ const fileContents = await fs.promises.readFile(filePath)
228
+ const fileHandler = new File([fileContents], refResolvedValue)
229
+ refResolvedDisplayValue = URL.createObjectURL(fileHandler)
230
+ await updateMetadata({
231
+ localId,
232
+ refResolvedDisplayValue,
233
+ })
234
+ }
228
235
  }
236
+ }
229
237
 
230
- sendBack({
231
- type: 'updateContext',
232
- localId,
233
- uid,
234
- propertyValue: propertyValueProcessed,
235
- seedLocalId: seedLocalIdFromDb,
236
- seedUid: seedUidFromDb,
237
- versionLocalId: versionLocalIdFromDb,
238
- versionUid: versionUidFromDb,
239
- schemaUid: schemaUidFromDb,
240
- refValueType,
241
- localStorageDir,
242
- resolvedValue: refResolvedValue,
243
- resolvedDisplayValue: refResolvedDisplayValue,
244
- renderValue: refResolvedDisplayValue,
245
- })
238
+ if (
239
+ propertyRecordSchema &&
240
+ propertyRecordSchema.dataType === 'List' &&
241
+ propertyRecordSchema.ref &&
242
+ typeof propertyValueFromDb === 'string'
243
+ ) {
244
+ propertyValueProcessed = propertyValueFromDb.split(',')
245
+ }
246
246
 
247
- if (
248
- propertyRecordSchema &&
249
- propertyRecordSchema.storageType &&
250
- propertyRecordSchema.storageType === 'ItemStorage'
251
- ) {
252
- const { Item } = await import(`@/browser/item`)
253
- const item = await Item.find({
254
- seedLocalId,
255
- modelName: itemModelName,
256
- })
257
- if (item) {
258
- const filePath = `/files/${localStorageDir}/${refResolvedValue}`
259
- const exists = await fs.promises.exists(filePath)
247
+ sendBack({
248
+ type: 'updateContext',
249
+ localId,
250
+ uid,
251
+ propertyValue: propertyValueProcessed,
252
+ seedLocalId: seedLocalIdFromDb,
253
+ seedUid: seedUidFromDb,
254
+ versionLocalId: versionLocalIdFromDb,
255
+ versionUid: versionUidFromDb,
256
+ schemaUid: schemaUidFromDb,
257
+ refValueType,
258
+ localStorageDir,
259
+ resolvedValue: refResolvedValue,
260
+ resolvedDisplayValue: refResolvedDisplayValue,
261
+ renderValue: refResolvedDisplayValue,
262
+ })
260
263
 
261
- if (!exists) {
262
- return
263
- }
264
+ if (
265
+ propertyRecordSchema &&
266
+ propertyRecordSchema.storageType &&
267
+ propertyRecordSchema.storageType === 'ItemStorage'
268
+ ) {
269
+ const { Item } = await import(`@/browser/item`)
270
+ const item = await Item.find({
271
+ seedLocalId,
272
+ modelName: itemModelName,
273
+ })
274
+ if (item) {
275
+ const filePath = `/files/${localStorageDir}/${refResolvedValue}`
276
+ const exists = await fs.promises.exists(filePath)
264
277
 
265
- const renderValue = await fs.promises.readFile(filePath, 'utf8')
266
- const property = item.properties[propertyName]
267
- property.getService().send({ type: 'updateRenderValue', renderValue })
278
+ if (!exists) {
268
279
  return
269
280
  }
281
+
282
+ const renderValue = await fs.promises.readFile(filePath, 'utf8')
283
+ const property = item.properties[propertyName]
284
+ property.getService().send({ type: 'updateRenderValue', renderValue })
285
+ return
270
286
  }
271
287
  }
288
+ }
272
289
 
273
- _hydrateFromDb().then(() => {
274
- sendBack({ type: 'hydrateFromDbSuccess' })
275
- })
276
- },
277
- )
290
+ _hydrateFromDb().then(() => {
291
+ sendBack({ type: 'hydrateFromDbSuccess' })
292
+ })
293
+ })
package/dist/src/item.ts CHANGED
@@ -351,7 +351,6 @@ export const usePublishItem = (): UsePublishItemReturn => {
351
351
  return
352
352
  }
353
353
  isLocked.current = true
354
- console.log('Publishing item', item)
355
354
  setIsPublishing(true)
356
355
  try {
357
356
  // await item.publish()
@@ -7,11 +7,11 @@ import { initialize } from '@/browser/property/actors/initialize'
7
7
  import { resolveRelatedValue } from '@/browser/property/actors/resolveRelatedValue'
8
8
  import { hydrateFromDb } from '@/browser/property/actors/hydrateFromDb'
9
9
  import {
10
- analyzeInput,
11
10
  saveImageSrc,
12
11
  saveItemStorage,
13
12
  saveRelation,
14
- } from '@/browser/property/actors/saveValueToDb' // import { updateMachineContext } from '@/browser/helpers'
13
+ } from '@/browser/property/actors/saveValueToDb'
14
+ import { analyzeInput } from '@/browser/property/actors/saveValueToDb/analyzeInput' // import { updateMachineContext } from '@/browser/helpers'
15
15
  // import { updateMachineContext } from '@/browser/helpers'
16
16
 
17
17
  export const propertyMachine = setup({
@@ -54,6 +54,7 @@ export const propertyMachine = setup({
54
54
  }
55
55
  }),
56
56
  },
57
+ reload: '.hydratingFromDb',
57
58
  save: {
58
59
  actions: assign({
59
60
  isSaving: true,
@@ -64,12 +65,6 @@ export const propertyMachine = setup({
64
65
  actions: assign(({ context, event }) => {
65
66
  const newContext = Object.assign({}, context)
66
67
 
67
- if (context.seedLocalId === 'qpIzW1e52r') {
68
- console.log(
69
- `[updateContext] before update versionLocalId is ${context.versionLocalId}`,
70
- )
71
- }
72
-
73
68
  for (let i = 0; i < Object.keys(event).length; i++) {
74
69
  const key = Object.keys(event)[i]
75
70
  if (key === 'type') {
@@ -77,12 +72,6 @@ export const propertyMachine = setup({
77
72
  }
78
73
  newContext[key] = event[key]
79
74
  }
80
-
81
- if (context.seedLocalId === 'qpIzW1e52r') {
82
- console.log(
83
- `[updateContext] after update versionLocalId is ${newContext.versionLocalId}`,
84
- )
85
- }
86
75
  return newContext
87
76
  }),
88
77
  },
@@ -9,10 +9,6 @@ export const itemRequestHandler = async (event) => {
9
9
  const { seedLocalId, seedUid, modelName, eventId } = event
10
10
 
11
11
  if (activeItemRequests.has(seedLocalId)) {
12
- console.log(
13
- '[item/events] [itemRequestHandler] already requesting item with queue size',
14
- queue.size,
15
- )
16
12
  queue.set(seedLocalId, event)
17
13
  return
18
14
  }
@@ -44,11 +40,6 @@ export const itemRequestHandler = async (event) => {
44
40
  queue.delete(seedLocalId)
45
41
  if (queue.size > 0 && queue.has(seedLocalId)) {
46
42
  const nextEvent = queue.get(seedLocalId)
47
- console.log(
48
- '[item/events] [itemRequestHandler] taking event from queue with queue size',
49
- queue.size,
50
- nextEvent,
51
- )
52
43
  await itemRequestHandler(nextEvent)
53
44
  }
54
45
  }
@@ -78,10 +78,6 @@ export const saveImageSrc = fromCallback<
78
78
  schemaUid,
79
79
  } = context
80
80
 
81
- if (seedLocalId === 'qpIzW1e52r') {
82
- console.log(`[saveImageSrc] versionLocaId is : ${versionLocalId}`)
83
- }
84
-
85
81
  let newValue: ItemPropertyValueType
86
82
 
87
83
  if (event) {
@@ -114,9 +114,6 @@ export const useService = (service: ActorRef<any, any>) => {
114
114
  const updateTime = useCallback(
115
115
  (interval) => {
116
116
  const context = service.getSnapshot().context
117
- if (context && context.times) {
118
- console.log('[ActorItem] [useEffect] context.times', context.times)
119
- }
120
117
  const status = service.getSnapshot().value
121
118
  if (
122
119
  status === 'done' ||
@@ -218,6 +218,7 @@ export const updateItemPropertyValue: UpdateItemPropertyValue = async ({
218
218
  ${refSeedType ? `'${refSeedType}'` : 'NULL'},
219
219
  ${refResolvedValue ? `'${refResolvedValue}'` : 'NULL'},
220
220
  ${refResolvedDisplayValue ? `'${refResolvedDisplayValue}'` : 'NULL'},
221
+ ${localStorageDir ? `'${localStorageDir}'` : 'NULL'},
221
222
  ${Date.now()});`
222
223
 
223
224
  await runQueryForStatement(newPropertyStatement)
@@ -0,0 +1,33 @@
1
+ import { EventObject, fromCallback } from 'xstate'
2
+ import { DbServiceContext, FromCallbackInput } from '@/types'
3
+ import { DB_WAITING_FOR_FILES_RECEIVED } from '@/browser/services/internal/constants'
4
+ import debug from 'debug'
5
+ import fs from '@zenfs/core'
6
+
7
+ const logger = debug('app:services:db:actors:waitForFiles')
8
+
9
+ export const waitForFiles = fromCallback<
10
+ EventObject,
11
+ FromCallbackInput<DbServiceContext>
12
+ >(({ sendBack, input: { context } }) => {
13
+ const { pathToDbDir } = context
14
+
15
+ const _waitForFiles = async (): Promise<void> => {
16
+ return new Promise((resolve) => {
17
+ const interval = setInterval(async () => {
18
+ const journalExists = await fs.promises.exists(
19
+ `${pathToDbDir}/meta/_journaljson`,
20
+ )
21
+ if (journalExists) {
22
+ clearInterval(interval)
23
+ resolve()
24
+ }
25
+ })
26
+ })
27
+ }
28
+
29
+ _waitForFiles().then(() => {
30
+ sendBack({ type: DB_WAITING_FOR_FILES_RECEIVED })
31
+ return
32
+ })
33
+ })