@seedprotocol/sdk 0.1.74 → 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.
- package/dist/bin.js +1 -6
- package/dist/bin.js.map +1 -1
- package/dist/{constants-CtmwCBma.js → constants-B9hSFQXL.js} +3 -2
- package/dist/{constants-CtmwCBma.js.map → constants-B9hSFQXL.js.map} +1 -1
- package/dist/main.js +7542 -29
- package/dist/main.js.map +1 -1
- package/dist/{seed.schema.config-BHNlL53f.js → seed.schema.config-BPJfo_5h.js} +3 -3
- package/dist/{seed.schema.config-BHNlL53f.js.map → seed.schema.config-BPJfo_5h.js.map} +1 -1
- package/dist/src/actors.ts +7 -282
- package/dist/src/analyzeInput.ts +102 -0
- package/dist/src/db.ts +0 -29
- package/dist/src/drizzle.ts +0 -4
- package/dist/src/hydrateFromDb.ts +246 -230
- package/dist/src/index.ts +10 -62
- package/dist/src/item.ts +0 -1
- package/dist/src/propertyMachine.ts +3 -14
- package/dist/src/request.ts +0 -9
- package/dist/src/saveImageSrc.ts +0 -4
- package/dist/src/services.ts +0 -3
- package/dist/src/updateItemPropertyValue.ts +1 -0
- package/dist/src/waitForFiles.ts +33 -0
- package/dist/types/src/browser/db/write/updateItemPropertyValue.d.ts.map +1 -1
- package/dist/types/src/browser/events/item/request.d.ts.map +1 -1
- package/dist/types/src/browser/item/Item.d.ts.map +1 -1
- package/dist/types/src/browser/property/ItemProperty.d.ts +2 -2
- package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts +4 -1
- package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts +5 -0
- package/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts.map +1 -0
- package/dist/types/src/browser/property/actors/saveValueToDb/index.d.ts +1 -4
- package/dist/types/src/browser/property/actors/saveValueToDb/index.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
- package/dist/types/src/browser/property/propertyMachine.d.ts.map +1 -1
- package/dist/types/src/browser/react/item.d.ts.map +1 -1
- package/dist/types/src/browser/react/services.d.ts.map +1 -1
- package/dist/types/src/browser/services/db/actors/waitForFiles.d.ts +4 -0
- package/dist/types/src/browser/services/db/actors/waitForFiles.d.ts.map +1 -0
- package/dist/types/src/node/codegen/drizzle.d.ts.map +1 -1
- package/dist/types/src/node/constants.d.ts.map +1 -1
- package/dist/types/src/node/webpack/index.d.ts.map +1 -1
- package/dist/types/src/shared/helpers/constants.d.ts.map +1 -1
- package/dist/types/src/shared/helpers/db.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/index-3ASvLLXY.js +0 -32
- package/dist/index-3ASvLLXY.js.map +0 -1
- package/dist/index-Br7jo_vg.js +0 -7626
- package/dist/index-Br7jo_vg.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<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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
|
-
|
|
63
|
-
propertyValueQueryString += `= ${propertyValue}`
|
|
79
|
+
if (!propertyName.endsWith('Id')) {
|
|
80
|
+
missingPropertyNameVariant = propertyName + 'Id'
|
|
64
81
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
123
|
+
if (!hydrateQuery) {
|
|
124
|
+
return
|
|
125
|
+
}
|
|
111
126
|
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
133
|
+
if (!rows || !rows.length) {
|
|
134
|
+
return
|
|
135
|
+
}
|
|
119
136
|
|
|
120
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
195
|
+
if (
|
|
196
|
+
refResolvedValue &&
|
|
197
|
+
refResolvedDisplayValue &&
|
|
198
|
+
refResolvedDisplayValue.includes('http')
|
|
199
|
+
) {
|
|
200
|
+
let urlNeedsToBeRefreshed = false
|
|
189
201
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
} catch (error) {
|
|
195
|
-
urlNeedsToBeRefreshed = true
|
|
196
|
-
}
|
|
202
|
+
try {
|
|
203
|
+
const response = await fetch(refResolvedDisplayValue, {
|
|
204
|
+
method: 'HEAD',
|
|
205
|
+
})
|
|
197
206
|
|
|
198
|
-
if
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
262
|
-
|
|
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
|
-
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
)
|
|
290
|
+
_hydrateFromDb().then(() => {
|
|
291
|
+
sendBack({ type: 'hydrateFromDbSuccess' })
|
|
292
|
+
})
|
|
293
|
+
})
|
package/dist/src/index.ts
CHANGED
|
@@ -1,73 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { setup } from 'xstate'
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from '@/browser/schema/file/
|
|
6
|
-
import { Attestation } from '@/browser/gql/graphql'
|
|
3
|
+
uploadBinaryData,
|
|
4
|
+
uploadMetadata,
|
|
5
|
+
} from '@/browser/schema/file/upload/actors'
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
addresses: string[]
|
|
10
|
-
dbsLoaded: boolean
|
|
11
|
-
filesMetadata?: Attestation[]
|
|
12
|
-
filesBlobData?: any[]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const fetchAllFilesMachine = setup({
|
|
16
|
-
types: {
|
|
17
|
-
context: {} as FetchAllFilesMachineContext,
|
|
18
|
-
},
|
|
7
|
+
export const uploadMachine = setup({
|
|
19
8
|
actors: {
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
uploadBinaryData,
|
|
10
|
+
uploadMetadata,
|
|
22
11
|
},
|
|
23
12
|
}).createMachine({
|
|
24
|
-
id: '
|
|
13
|
+
id: 'upload',
|
|
25
14
|
initial: 'idle',
|
|
26
|
-
context:
|
|
27
|
-
|
|
28
|
-
...input,
|
|
29
|
-
dbsLoaded: false,
|
|
30
|
-
}) as FetchAllFilesMachineContext,
|
|
31
|
-
on: {
|
|
32
|
-
allDbsLoaded: {
|
|
33
|
-
target: '.fetchingAllMetadataRecords',
|
|
34
|
-
actions: assign({
|
|
35
|
-
dbsLoaded: true,
|
|
36
|
-
}),
|
|
37
|
-
},
|
|
15
|
+
context: {
|
|
16
|
+
file: '',
|
|
38
17
|
},
|
|
39
18
|
states: {
|
|
40
19
|
idle: {},
|
|
41
|
-
fetchingAllMetadataRecords: {
|
|
42
|
-
on: {
|
|
43
|
-
fetchingAllMetadataRecordsSuccess: {
|
|
44
|
-
target: 'fetchingAllBinaryData',
|
|
45
|
-
actions: assign({
|
|
46
|
-
filesMetadata: ({ event }) => event.filesMetadata,
|
|
47
|
-
}),
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
invoke: {
|
|
51
|
-
src: 'fetchAllMetadataRecords',
|
|
52
|
-
input: ({ context, event }) => ({ context, event }),
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
fetchingAllBinaryData: {
|
|
56
|
-
on: {
|
|
57
|
-
fetchingAllBinaryDataSuccess: {
|
|
58
|
-
target: 'success',
|
|
59
|
-
actions: assign({
|
|
60
|
-
filesBlobData: ({ event }) => event.filesBlobData,
|
|
61
|
-
}),
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
invoke: {
|
|
65
|
-
src: 'fetchAllBinaryData',
|
|
66
|
-
input: ({ context }) => ({ context }),
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
success: {
|
|
70
|
-
type: 'final',
|
|
71
|
-
},
|
|
72
20
|
},
|
|
73
21
|
})
|
package/dist/src/item.ts
CHANGED
|
@@ -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'
|
|
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
|
},
|