@seedprotocol/sdk 0.1.104 → 0.1.106
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 -1
- package/dist/{constants-rmQ8zg8_.js → constants-qIJt7998.js} +2 -1
- package/dist/{constants-rmQ8zg8_.js.map → constants-qIJt7998.js.map} +1 -1
- package/dist/{index-opZLss_R.js → index-CvfKxmFw.js} +1454 -1256
- package/dist/index-CvfKxmFw.js.map +1 -0
- package/dist/{index-S6aUqdI6.js → index-DyEsLJAK.js} +4 -4
- package/dist/{index-S6aUqdI6.js.map → index-DyEsLJAK.js.map} +1 -1
- package/dist/main.js +3 -3
- package/dist/{seed.schema.config-D5w2jMZV.js → seed.schema.config-C37yDUmq.js} +4 -4
- package/dist/{seed.schema.config-D5w2jMZV.js.map → seed.schema.config-C37yDUmq.js.map} +1 -1
- package/dist/src/actors.ts +7 -289
- package/dist/src/eas.ts +40 -0
- package/dist/src/getPublishPayload.ts +287 -81
- package/dist/src/index.ts +21 -4
- package/dist/src/initialize.ts +6 -11
- package/dist/src/saveImageSrc.ts +21 -1
- package/dist/src/syncDbWithEas.ts +13 -5
- package/dist/types/src/browser/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/types/src/browser/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/types/src/browser/item/Item.d.ts +10 -1
- package/dist/types/src/browser/item/Item.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/initialize.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/index.d.ts +0 -1
- package/dist/types/src/browser/property/index.d.ts.map +1 -1
- package/dist/types/src/browser/react/services.d.ts +1 -1
- package/dist/types/src/browser/services/global/actors/initialize.d.ts +1 -1
- package/dist/types/src/browser/services/global/actors/initialize.d.ts.map +1 -1
- package/dist/types/src/browser/services/global/globalMachine.d.ts +613 -44
- package/dist/types/src/browser/services/global/globalMachine.d.ts.map +1 -1
- package/dist/types/src/browser/stores/eas.d.ts +7 -0
- package/dist/types/src/browser/stores/eas.d.ts.map +1 -0
- package/dist/types/src/shared/helpers/constants.d.ts.map +1 -1
- package/dist/types/src/shared/helpers/index.d.ts +1 -0
- package/dist/types/src/shared/helpers/index.d.ts.map +1 -1
- package/dist/types/src/types/item.d.ts +1 -0
- package/dist/types/src/types/item.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/index-opZLss_R.js.map +0 -1
|
@@ -13,109 +13,126 @@ import {
|
|
|
13
13
|
import { getSchemaForItemProperty } from '@/browser/helpers/getSchemaForItemProperty'
|
|
14
14
|
import { toSnakeCase } from '@/shared/helpers'
|
|
15
15
|
import pluralize from 'pluralize'
|
|
16
|
+
import { getSchemaUidForModel } from '@/browser/db/read/getSchemaUidForModel'
|
|
17
|
+
import { getSchemaUidForSchemaDefinition } from '@/browser/stores/eas'
|
|
18
|
+
import { ItemProperty } from '@/browser/property/ItemProperty'
|
|
19
|
+
import { getCorrectId } from '@/browser/helpers'
|
|
20
|
+
import { Item } from '@/browser/item/Item'
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const getVersionUid = (item: Item<any>) => {
|
|
23
|
+
let versionUid
|
|
24
|
+
|
|
25
|
+
if (
|
|
26
|
+
item.latestVersionUid &&
|
|
27
|
+
item.latestVersionUid !== 'NULL' &&
|
|
28
|
+
item.latestVersionUid !== 'undefined'
|
|
29
|
+
) {
|
|
30
|
+
versionUid = item.latestVersionUid
|
|
31
|
+
}
|
|
32
|
+
return versionUid || ZERO_ADDRESS
|
|
26
33
|
}
|
|
27
34
|
|
|
28
|
-
|
|
35
|
+
const getPropertyData = async (itemProperty: ItemProperty<any>) => {
|
|
36
|
+
const easDataType =
|
|
37
|
+
INTERNAL_DATA_TYPES[itemProperty.propertyDef!.dataType].eas
|
|
29
38
|
|
|
30
|
-
|
|
31
|
-
seedLocalId: string,
|
|
32
|
-
): Promise<MultiPublishPayload> => {
|
|
33
|
-
const item = await getItem({ seedLocalId })
|
|
39
|
+
let schemaUid = itemProperty.schemaUid
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
throw new Error('Item not found')
|
|
37
|
-
}
|
|
41
|
+
const propertyNameForSchema = toSnakeCase(itemProperty.propertyName)
|
|
38
42
|
|
|
39
|
-
const
|
|
40
|
-
const seedIsRevocable = true
|
|
41
|
-
const seedSchemaUid = item.schemaUid
|
|
42
|
-
const seedUid = item.seedUid
|
|
43
|
-
const versionSchemaUid = VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA
|
|
44
|
-
const listOfAttestations = []
|
|
45
|
-
const propertiesToUpdate = []
|
|
43
|
+
const schemaDef = `${easDataType} ${propertyNameForSchema}`
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
if (!schemaUid) {
|
|
46
|
+
schemaUid = getSchemaUidForSchemaDefinition(schemaDef)
|
|
47
|
+
if (!schemaUid) {
|
|
48
|
+
const schema = await getSchemaForItemProperty({
|
|
49
|
+
propertyName: 'version',
|
|
50
|
+
easDataType: 'bytes32',
|
|
51
|
+
})
|
|
52
|
+
if (schema) {
|
|
53
|
+
schemaUid = schema.id
|
|
54
|
+
}
|
|
50
55
|
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
schemaUid,
|
|
60
|
+
easDataType,
|
|
61
|
+
schemaDef,
|
|
62
|
+
propertyNameForSchema,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
51
65
|
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
const getSegmentedItemProperties = (item: Item<any>) => {
|
|
67
|
+
const itemBasicProperties = []
|
|
68
|
+
const itemRelationProperties = []
|
|
69
|
+
const itemListProperties = []
|
|
70
|
+
const itemStorageProperties = []
|
|
54
71
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
72
|
+
for (const itemProperty of Object.values(item.properties)) {
|
|
73
|
+
if (!itemProperty.propertyDef) {
|
|
74
|
+
continue
|
|
75
|
+
}
|
|
59
76
|
|
|
60
77
|
if (itemProperty.propertyDef.dataType === 'Relation') {
|
|
61
|
-
|
|
78
|
+
itemRelationProperties.push(itemProperty)
|
|
79
|
+
continue
|
|
62
80
|
}
|
|
63
81
|
|
|
64
|
-
if (
|
|
65
|
-
itemProperty
|
|
66
|
-
|
|
67
|
-
) {
|
|
68
|
-
const singularPropertyName = pluralize.singular(propertyName)
|
|
69
|
-
propertyNameForSchema = `${singularPropertyName}${itemProperty.propertyDef.ref}Ids`
|
|
70
|
-
if (typeof propertyValue === 'string' && propertyValue.length === 66) {
|
|
71
|
-
propertyValue = [propertyValue]
|
|
72
|
-
}
|
|
73
|
-
if (typeof propertyValue === 'string' && propertyValue.length > 66) {
|
|
74
|
-
try {
|
|
75
|
-
propertyValue = JSON.parse(propertyValue)
|
|
76
|
-
} catch (error) {
|
|
77
|
-
console.log('No-op due to error: ', error)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
82
|
+
if (itemProperty.propertyDef.dataType === 'List') {
|
|
83
|
+
itemListProperties.push(itemProperty)
|
|
84
|
+
continue
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
if (
|
|
83
88
|
itemProperty.propertyDef.storageType &&
|
|
84
89
|
itemProperty.propertyDef.storageType === 'ItemStorage'
|
|
85
90
|
) {
|
|
91
|
+
itemStorageProperties.push(itemProperty)
|
|
86
92
|
continue
|
|
87
93
|
}
|
|
88
94
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
propertyName: propertyNameForSchema,
|
|
92
|
-
easDataType,
|
|
93
|
-
})
|
|
95
|
+
itemBasicProperties.push(itemProperty)
|
|
96
|
+
}
|
|
94
97
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
return {
|
|
99
|
+
itemBasicProperties,
|
|
100
|
+
itemRelationProperties,
|
|
101
|
+
itemListProperties,
|
|
102
|
+
itemStorageProperties,
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const processBasicProperties = async (
|
|
107
|
+
itemBasicProperties: ItemProperty<any>[],
|
|
108
|
+
itemPublishData: PublishPayload,
|
|
109
|
+
): Promise<PublishPayload> => {
|
|
110
|
+
for (const basicProperty of itemBasicProperties) {
|
|
111
|
+
const value = basicProperty.getService().getSnapshot().context.propertyValue
|
|
112
|
+
|
|
113
|
+
if (!value || basicProperty.uid) {
|
|
114
|
+
continue
|
|
99
115
|
}
|
|
100
116
|
|
|
101
|
-
schemaUid =
|
|
117
|
+
const { schemaUid, easDataType, schemaDef } =
|
|
118
|
+
await getPropertyData(basicProperty)
|
|
119
|
+
|
|
120
|
+
const propertyNameForSchema = toSnakeCase(basicProperty.propertyName)
|
|
102
121
|
|
|
103
122
|
const data = [
|
|
104
123
|
{
|
|
105
|
-
name:
|
|
124
|
+
name: propertyNameForSchema,
|
|
106
125
|
type: easDataType,
|
|
107
|
-
value
|
|
126
|
+
value,
|
|
108
127
|
},
|
|
109
128
|
]
|
|
110
129
|
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
const dataEncoder = new SchemaEncoder(easSchemaDefinition)
|
|
130
|
+
const dataEncoder = new SchemaEncoder(schemaDef)
|
|
114
131
|
|
|
115
132
|
const encodedData = dataEncoder.encodeData(data)
|
|
116
133
|
|
|
117
|
-
listOfAttestations.push({
|
|
118
|
-
schema: schemaUid
|
|
134
|
+
itemPublishData.listOfAttestations.push({
|
|
135
|
+
schema: schemaUid!,
|
|
119
136
|
data: [
|
|
120
137
|
{
|
|
121
138
|
...defaultAttestationData,
|
|
@@ -125,22 +142,211 @@ export const getPublishPayload = async (
|
|
|
125
142
|
})
|
|
126
143
|
}
|
|
127
144
|
|
|
128
|
-
|
|
145
|
+
return itemPublishData
|
|
146
|
+
}
|
|
129
147
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
148
|
+
const processRelationProperty = async (
|
|
149
|
+
relationProperty: ItemProperty<any>,
|
|
150
|
+
multiPublishPayload: MultiPublishPayload,
|
|
151
|
+
): Promise<MultiPublishPayload> => {
|
|
152
|
+
const value = relationProperty.getService().getSnapshot()
|
|
153
|
+
.context.propertyValue
|
|
154
|
+
if (!value || relationProperty.uid) {
|
|
155
|
+
return multiPublishPayload
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const { localId: seedLocalId, uid: seedUid } = getCorrectId(value)
|
|
159
|
+
|
|
160
|
+
const relatedItem = await getItem({
|
|
161
|
+
seedLocalId,
|
|
162
|
+
seedUid,
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
if (!relatedItem) {
|
|
166
|
+
throw new Error(
|
|
167
|
+
`No related item found for relation property: ${relationProperty.propertyName}`,
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const versionUid = getVersionUid(relatedItem)
|
|
172
|
+
|
|
173
|
+
const seedSchemaUid = await getSchemaUidForModel(
|
|
174
|
+
relationProperty.propertyDef!.ref as string,
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
let publishPayload: PublishPayload = {
|
|
178
|
+
localId: relationProperty.localId,
|
|
179
|
+
seedIsRevocable: true,
|
|
180
|
+
versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
|
|
181
|
+
seedUid: seedUid || ZERO_ADDRESS,
|
|
182
|
+
seedSchemaUid,
|
|
183
|
+
versionUid,
|
|
184
|
+
listOfAttestations: [],
|
|
185
|
+
propertiesToUpdate: [],
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const { itemBasicProperties } = getSegmentedItemProperties(relatedItem)
|
|
189
|
+
|
|
190
|
+
publishPayload = await processBasicProperties(
|
|
191
|
+
itemBasicProperties,
|
|
192
|
+
publishPayload,
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
multiPublishPayload.push(publishPayload)
|
|
196
|
+
|
|
197
|
+
return multiPublishPayload
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const processListProperty = async (
|
|
201
|
+
listProperty: ItemProperty<any>,
|
|
202
|
+
multiPublishPayload: MultiPublishPayload,
|
|
203
|
+
): Promise<MultiPublishPayload> => {
|
|
204
|
+
let value = listProperty.getService().getSnapshot().context.propertyValue
|
|
205
|
+
if (!value || listProperty.uid) {
|
|
206
|
+
return multiPublishPayload
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const singularPropertyName = pluralize.singular(listProperty.propertyName)
|
|
210
|
+
const propertyNameForSchema = `${singularPropertyName}${listProperty.propertyDef!.ref}Ids`
|
|
211
|
+
if (typeof value === 'string' && value.length === 66) {
|
|
212
|
+
value = [value]
|
|
213
|
+
}
|
|
214
|
+
if (typeof value === 'string' && value.length > 66) {
|
|
215
|
+
try {
|
|
216
|
+
value = JSON.parse(value)
|
|
217
|
+
} catch (error) {
|
|
218
|
+
value = value.split(',')
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
for (const seedId of value) {
|
|
223
|
+
const { localId: seedLocalId, uid: seedUid } = getCorrectId(seedId)
|
|
224
|
+
|
|
225
|
+
const relatedItem = await getItem({
|
|
226
|
+
seedLocalId,
|
|
227
|
+
seedUid,
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
if (!relatedItem) {
|
|
231
|
+
throw new Error(
|
|
232
|
+
`No related item found for list property: ${listProperty.propertyName}`,
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (relatedItem.seedUid) {
|
|
237
|
+
return multiPublishPayload
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const versionUid = getVersionUid(relatedItem)
|
|
241
|
+
|
|
242
|
+
const seedSchemaUid = await getSchemaUidForModel(
|
|
243
|
+
listProperty.propertyDef!.ref as string,
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
let publishPayload: PublishPayload = {
|
|
247
|
+
localId: relatedItem.seedLocalId,
|
|
248
|
+
seedIsRevocable: true,
|
|
249
|
+
versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
|
|
135
250
|
seedUid: seedUid || ZERO_ADDRESS,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
listOfAttestations,
|
|
139
|
-
propertiesToUpdate
|
|
140
|
-
|
|
141
|
-
|
|
251
|
+
seedSchemaUid,
|
|
252
|
+
versionUid,
|
|
253
|
+
listOfAttestations: [],
|
|
254
|
+
propertiesToUpdate: [
|
|
255
|
+
{
|
|
256
|
+
publishLocalId: listProperty.localId,
|
|
257
|
+
propertySchemaUid: listProperty.schemaUid,
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const { itemBasicProperties } = getSegmentedItemProperties(relatedItem)
|
|
263
|
+
|
|
264
|
+
publishPayload = await processBasicProperties(
|
|
265
|
+
itemBasicProperties,
|
|
266
|
+
publishPayload,
|
|
267
|
+
)
|
|
142
268
|
|
|
143
|
-
|
|
269
|
+
multiPublishPayload.push(publishPayload)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return multiPublishPayload
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
type PublishPayload = {
|
|
276
|
+
localId: string
|
|
277
|
+
seedIsRevocable: boolean
|
|
278
|
+
seedSchemaUid: string
|
|
279
|
+
seedUid: string
|
|
280
|
+
versionSchemaUid: string
|
|
281
|
+
versionUid: string
|
|
282
|
+
listOfAttestations: AttestationRequest[]
|
|
283
|
+
propertiesToUpdate: any[]
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
type MultiPublishPayload = PublishPayload[]
|
|
287
|
+
|
|
288
|
+
export const getPublishPayload = async (
|
|
289
|
+
seedLocalId: string,
|
|
290
|
+
): Promise<MultiPublishPayload> => {
|
|
291
|
+
const item = await getItem({ seedLocalId })
|
|
292
|
+
|
|
293
|
+
if (!item) {
|
|
294
|
+
throw new Error('Item not found')
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// if (item.modelName === 'Post') {
|
|
298
|
+
// item.authors = [
|
|
299
|
+
// 'Sr0bIx9Fwj',
|
|
300
|
+
// '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',
|
|
301
|
+
// ]
|
|
302
|
+
// }
|
|
303
|
+
|
|
304
|
+
let multiPublishPayload: MultiPublishPayload = []
|
|
305
|
+
|
|
306
|
+
// Each PublishPayload is generated from a Seed that needs publishing
|
|
307
|
+
|
|
308
|
+
// First we need to determine all Seeds to publish
|
|
309
|
+
|
|
310
|
+
// That means the Seed of the Item, plus any Seeds pointed to by Relations
|
|
311
|
+
|
|
312
|
+
let itemPublishData: PublishPayload = {
|
|
313
|
+
localId: item.seedLocalId,
|
|
314
|
+
seedUid: item.seedUid || ZERO_ADDRESS,
|
|
315
|
+
seedIsRevocable: true,
|
|
316
|
+
seedSchemaUid: item.schemaUid,
|
|
317
|
+
versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
|
|
318
|
+
versionUid: item.latestVersionUid || ZERO_ADDRESS,
|
|
319
|
+
listOfAttestations: [],
|
|
320
|
+
propertiesToUpdate: [],
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const {
|
|
324
|
+
itemBasicProperties,
|
|
325
|
+
itemRelationProperties,
|
|
326
|
+
itemListProperties,
|
|
327
|
+
itemStorageProperties,
|
|
328
|
+
} = getSegmentedItemProperties(item)
|
|
329
|
+
|
|
330
|
+
itemPublishData = await processBasicProperties(
|
|
331
|
+
itemBasicProperties,
|
|
332
|
+
itemPublishData,
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
multiPublishPayload.push(itemPublishData)
|
|
336
|
+
|
|
337
|
+
for (const relationProperty of itemRelationProperties) {
|
|
338
|
+
multiPublishPayload = await processRelationProperty(
|
|
339
|
+
relationProperty,
|
|
340
|
+
multiPublishPayload,
|
|
341
|
+
)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
for (const listProperty of itemListProperties) {
|
|
345
|
+
multiPublishPayload = await processListProperty(
|
|
346
|
+
listProperty,
|
|
347
|
+
multiPublishPayload,
|
|
348
|
+
)
|
|
349
|
+
}
|
|
144
350
|
|
|
145
|
-
return
|
|
351
|
+
return multiPublishPayload
|
|
146
352
|
}
|
package/dist/src/index.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { setup } from 'xstate'
|
|
2
|
+
import {
|
|
3
|
+
uploadBinaryData,
|
|
4
|
+
uploadMetadata,
|
|
5
|
+
} from '@/browser/schema/file/upload/actors'
|
|
6
|
+
|
|
7
|
+
export const uploadMachine = setup({
|
|
8
|
+
actors: {
|
|
9
|
+
uploadBinaryData,
|
|
10
|
+
uploadMetadata,
|
|
11
|
+
},
|
|
12
|
+
}).createMachine({
|
|
13
|
+
id: 'upload',
|
|
14
|
+
initial: 'idle',
|
|
15
|
+
context: {
|
|
16
|
+
file: '',
|
|
17
|
+
},
|
|
18
|
+
states: {
|
|
19
|
+
idle: {},
|
|
20
|
+
},
|
|
21
|
+
})
|
package/dist/src/initialize.ts
CHANGED
|
@@ -10,12 +10,13 @@ import { FromCallbackInput, GlobalMachineContext } from '@/types'
|
|
|
10
10
|
import { getAppDb } from '@/browser/db/sqlWasmClient'
|
|
11
11
|
import { appState } from '@/shared/seedSchema'
|
|
12
12
|
import { like } from 'drizzle-orm'
|
|
13
|
+
import { fetchSchemaUids } from '@/browser/stores/eas'
|
|
13
14
|
|
|
14
15
|
const logger = debug('app:services:global:actors:initialize')
|
|
15
16
|
|
|
16
17
|
export const initialize = fromCallback<
|
|
17
18
|
EventObject,
|
|
18
|
-
FromCallbackInput<GlobalMachineContext>
|
|
19
|
+
FromCallbackInput<GlobalMachineContext, EventObject>
|
|
19
20
|
>(({ sendBack, input: { event, context } }) => {
|
|
20
21
|
const { internalService, models, endpoints } = context
|
|
21
22
|
|
|
@@ -87,16 +88,7 @@ export const initialize = fromCallback<
|
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
const _initEas = async (): Promise<void> => {
|
|
90
|
-
|
|
91
|
-
// easService.send({ type: 'init', endpoints, models })
|
|
92
|
-
// return new Promise((resolve) => {
|
|
93
|
-
// easSubscription = easService.subscribe((snapshot) => {
|
|
94
|
-
// if (snapshot.value === 'ready') {
|
|
95
|
-
// resolve()
|
|
96
|
-
// }
|
|
97
|
-
// })
|
|
98
|
-
// easService.send({ type: 'init', endpoints, models })
|
|
99
|
-
// })
|
|
91
|
+
await fetchSchemaUids()
|
|
100
92
|
}
|
|
101
93
|
|
|
102
94
|
_initFileSystem().then(() => {
|
|
@@ -107,6 +99,9 @@ export const initialize = fromCallback<
|
|
|
107
99
|
.then(() => {
|
|
108
100
|
return _initAllItemsServices()
|
|
109
101
|
})
|
|
102
|
+
.then(() => {
|
|
103
|
+
return _initEas()
|
|
104
|
+
})
|
|
110
105
|
.then(() => {
|
|
111
106
|
logger('[global/actors] Internal initialized')
|
|
112
107
|
sendBack({ type: GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY })
|
package/dist/src/saveImageSrc.ts
CHANGED
|
@@ -12,6 +12,8 @@ import { fs } from '@zenfs/core'
|
|
|
12
12
|
import { getContentUrlFromPath } from '@/browser/helpers'
|
|
13
13
|
import { createMetadata } from '@/browser/db/write/createMetadata'
|
|
14
14
|
import { updateItemPropertyValue } from '@/browser/db/write/updateItemPropertyValue'
|
|
15
|
+
import { getSchemaUidForSchemaDefinition } from '@/browser/stores/eas'
|
|
16
|
+
import { getSchemaUidForModel } from '@/browser/db/read/getSchemaUidForModel'
|
|
15
17
|
|
|
16
18
|
const readFileAsDataUrl = async (file: File): Promise<string> => {
|
|
17
19
|
return new Promise((resolve) => {
|
|
@@ -61,6 +63,8 @@ const fetchImage = async (url: string) => {
|
|
|
61
63
|
return base64
|
|
62
64
|
}
|
|
63
65
|
|
|
66
|
+
let imageSchemaUid: string | undefined
|
|
67
|
+
|
|
64
68
|
export const saveImageSrc = fromCallback<
|
|
65
69
|
EventObject,
|
|
66
70
|
FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>
|
|
@@ -75,9 +79,10 @@ export const saveImageSrc = fromCallback<
|
|
|
75
79
|
seedUid,
|
|
76
80
|
versionLocalId,
|
|
77
81
|
versionUid,
|
|
78
|
-
schemaUid,
|
|
79
82
|
} = context
|
|
80
83
|
|
|
84
|
+
let { schemaUid } = context
|
|
85
|
+
|
|
81
86
|
let newValue: ItemPropertyValueType
|
|
82
87
|
|
|
83
88
|
if (event) {
|
|
@@ -101,6 +106,10 @@ export const saveImageSrc = fromCallback<
|
|
|
101
106
|
let mimeType
|
|
102
107
|
let fileName
|
|
103
108
|
|
|
109
|
+
if (!imageSchemaUid) {
|
|
110
|
+
imageSchemaUid = await getSchemaUidForModel('Image')
|
|
111
|
+
}
|
|
112
|
+
|
|
104
113
|
if (typeof newValue === 'string') {
|
|
105
114
|
newValueType = getDataTypeFromString(newValue)
|
|
106
115
|
}
|
|
@@ -160,6 +169,10 @@ export const saveImageSrc = fromCallback<
|
|
|
160
169
|
|
|
161
170
|
const refResolvedDisplayValue = await getContentUrlFromPath(filePath)
|
|
162
171
|
|
|
172
|
+
if (!schemaUid) {
|
|
173
|
+
schemaUid = getSchemaUidForSchemaDefinition(propertyName)
|
|
174
|
+
}
|
|
175
|
+
|
|
163
176
|
if (!localId) {
|
|
164
177
|
await createMetadata(
|
|
165
178
|
{
|
|
@@ -172,6 +185,8 @@ export const saveImageSrc = fromCallback<
|
|
|
172
185
|
modelName: itemModelName,
|
|
173
186
|
schemaUid,
|
|
174
187
|
refSeedType: 'image',
|
|
188
|
+
refModelUid: imageSchemaUid,
|
|
189
|
+
refSchemaUid: imageSchemaUid,
|
|
175
190
|
refResolvedDisplayValue,
|
|
176
191
|
refResolvedValue: fileName,
|
|
177
192
|
localStorageDir: '/images',
|
|
@@ -193,6 +208,8 @@ export const saveImageSrc = fromCallback<
|
|
|
193
208
|
refSeedType: 'image',
|
|
194
209
|
refResolvedDisplayValue,
|
|
195
210
|
refResolvedValue: fileName,
|
|
211
|
+
refModelUid: imageSchemaUid,
|
|
212
|
+
refSchemaUid: imageSchemaUid,
|
|
196
213
|
localStorageDir: '/images',
|
|
197
214
|
easDataType: 'bytes32',
|
|
198
215
|
})
|
|
@@ -202,9 +219,12 @@ export const saveImageSrc = fromCallback<
|
|
|
202
219
|
type: 'updateContext',
|
|
203
220
|
propertyValue: newImageSeedLocalId,
|
|
204
221
|
refSeedType: 'image',
|
|
222
|
+
refSchemaUid: imageSchemaUid,
|
|
205
223
|
renderValue: refResolvedDisplayValue,
|
|
206
224
|
resolvedDisplayValue: refResolvedDisplayValue,
|
|
207
225
|
resolvedValue: fileName,
|
|
226
|
+
localStorageDir: '/images',
|
|
227
|
+
easDataType: 'bytes32',
|
|
208
228
|
})
|
|
209
229
|
}
|
|
210
230
|
|
|
@@ -32,6 +32,7 @@ import { getModelSchemas } from '@/browser/db/read/getModelSchemas'
|
|
|
32
32
|
import debug from 'debug'
|
|
33
33
|
import { ModelSchema, PropertyType } from '@/types'
|
|
34
34
|
import { createSeeds } from '@/browser/db/write/createSeeds'
|
|
35
|
+
import { setSchemaUidForSchemaDefinition } from '@/browser/stores/eas'
|
|
35
36
|
|
|
36
37
|
const logger = debug('app:item:events:syncDbWithEas')
|
|
37
38
|
|
|
@@ -417,6 +418,7 @@ const saveEasPropertiesToDb: SaveEasPropertiesToDb = async ({
|
|
|
417
418
|
let insertPropertiesQuery = `INSERT INTO metadata (local_id, uid, schema_uid, property_name, property_value,
|
|
418
419
|
eas_data_type, version_uid, version_local_id, seed_uid,
|
|
419
420
|
seed_local_id, model_type, ref_value_type, ref_seed_type,
|
|
421
|
+
ref_schema_uid,
|
|
420
422
|
created_at, attestation_created_at, attestation_raw,
|
|
421
423
|
local_storage_dir, ref_resolved_value)
|
|
422
424
|
VALUES `
|
|
@@ -428,23 +430,26 @@ const saveEasPropertiesToDb: SaveEasPropertiesToDb = async ({
|
|
|
428
430
|
|
|
429
431
|
let propertyNameSnake = metadata.name
|
|
430
432
|
|
|
431
|
-
if (!propertyNameSnake) {
|
|
432
|
-
propertyNameSnake = metadata.name
|
|
433
|
-
}
|
|
434
|
-
|
|
435
433
|
if (!propertyNameSnake) {
|
|
436
434
|
console.warn(
|
|
437
435
|
'[item/events] [syncDbWithEas] no propertyName found for property: ',
|
|
438
436
|
property,
|
|
439
437
|
)
|
|
440
|
-
|
|
438
|
+
continue
|
|
441
439
|
}
|
|
442
440
|
|
|
443
441
|
let isRelation = false
|
|
444
442
|
let refValueType
|
|
445
443
|
let refSeedType
|
|
444
|
+
let refSchemaUid
|
|
446
445
|
let refResolvedValue
|
|
447
446
|
let isList = false
|
|
447
|
+
const schemaUid = property.schemaId
|
|
448
|
+
|
|
449
|
+
setSchemaUidForSchemaDefinition({
|
|
450
|
+
text: propertyNameSnake,
|
|
451
|
+
schemaUid,
|
|
452
|
+
})
|
|
448
453
|
|
|
449
454
|
if (
|
|
450
455
|
(propertyNameSnake.endsWith('_id') ||
|
|
@@ -490,6 +495,7 @@ const saveEasPropertiesToDb: SaveEasPropertiesToDb = async ({
|
|
|
490
495
|
)
|
|
491
496
|
if (relatedSeed && relatedSeed.schema && relatedSeed.schema.schemaNames) {
|
|
492
497
|
refSeedType = relatedSeed.schema.schemaNames[0].name
|
|
498
|
+
refSchemaUid = relatedSeed.schemaId
|
|
493
499
|
}
|
|
494
500
|
}
|
|
495
501
|
|
|
@@ -499,6 +505,7 @@ const saveEasPropertiesToDb: SaveEasPropertiesToDb = async ({
|
|
|
499
505
|
)
|
|
500
506
|
if (relatedSeeds && relatedSeeds.length > 0) {
|
|
501
507
|
refSeedType = relatedSeeds[0].schema.schemaNames[0].name
|
|
508
|
+
refSchemaUid = relatedSeeds[0].schemaId
|
|
502
509
|
}
|
|
503
510
|
}
|
|
504
511
|
|
|
@@ -528,6 +535,7 @@ const saveEasPropertiesToDb: SaveEasPropertiesToDb = async ({
|
|
|
528
535
|
'${versionLocalId}', '${seedUid}', '${seedLocalId}',
|
|
529
536
|
'${modelType}', ${refValueType ? `'${refValueType}'` : 'NULL'},
|
|
530
537
|
${refSeedType ? `'${refSeedType}'` : 'NULL'},
|
|
538
|
+
${refSchemaUid ? `'${refSchemaUid}'` : 'NULL'},
|
|
531
539
|
${Date.now()}, ${attestationCreatedAt}, '${attestationRaw}',
|
|
532
540
|
${localStorageDir ? `'${localStorageDir}'` : 'NULL'},
|
|
533
541
|
${refResolvedValue ? `'${refResolvedValue}'` : 'NULL'})`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPublishPayload.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/db/read/getPublishPayload.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,kBAAkB,EAGnB,MAAM,uCAAuC,CAAA;
|
|
1
|
+
{"version":3,"file":"getPublishPayload.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/db/read/getPublishPayload.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,kBAAkB,EAGnB,MAAM,uCAAuC,CAAA;AAwQ9C,KAAK,cAAc,GAAG;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,EAAE,OAAO,CAAA;IACxB,aAAa,EAAE,MAAM,CAAA;IACrB,OAAO,EAAE,MAAM,CAAA;IACf,gBAAgB,EAAE,MAAM,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,kBAAkB,EAAE,kBAAkB,EAAE,CAAA;IACxC,kBAAkB,EAAE,GAAG,EAAE,CAAA;CAC1B,CAAA;AAED,KAAK,mBAAmB,GAAG,cAAc,EAAE,CAAA;AAE3C,eAAO,MAAM,iBAAiB,gBACf,MAAM,KAClB,OAAO,CAAC,mBAAmB,CA8D7B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syncDbWithEas.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/events/item/syncDbWithEas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,aAAa,EAAuB,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"syncDbWithEas.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/events/item/syncDbWithEas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,aAAa,EAAuB,MAAM,WAAW,CAAA;AA6lBzE,QAAA,MAAM,oBAAoB,EAAE,aAAa,CAAC,GAAG,CA+F5C,CAAA;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAA"}
|
|
@@ -21,7 +21,16 @@ export declare class Item<T extends ModelValues<ModelSchema>> {
|
|
|
21
21
|
getService: () => ActorRefFrom<typeof itemMachineSingle>;
|
|
22
22
|
getEditedProperties: () => Promise<PropertyData[]>;
|
|
23
23
|
publish: () => Promise<void>;
|
|
24
|
-
getPublishPayload: () => Promise<
|
|
24
|
+
getPublishPayload: () => Promise<{
|
|
25
|
+
localId: string;
|
|
26
|
+
seedIsRevocable: boolean;
|
|
27
|
+
seedSchemaUid: string;
|
|
28
|
+
seedUid: string;
|
|
29
|
+
versionSchemaUid: string;
|
|
30
|
+
versionUid: string;
|
|
31
|
+
listOfAttestations: import("@ethereum-attestation-service/eas-sdk").AttestationRequest[];
|
|
32
|
+
propertiesToUpdate: any[];
|
|
33
|
+
}[]>;
|
|
25
34
|
get seedLocalId(): string;
|
|
26
35
|
get seedUid(): string | undefined;
|
|
27
36
|
get schemaUid(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Item.d.ts","sourceRoot":"","sources":["../../../../../src/browser/item/Item.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EACR,aAAa,EACb,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACb,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,YAAY,EAAe,YAAY,EAAE,MAAM,QAAQ,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAYjC,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;
|
|
1
|
+
{"version":3,"file":"Item.d.ts","sourceRoot":"","sources":["../../../../../src/browser/item/Item.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EACR,aAAa,EACb,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACb,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,YAAY,EAAe,YAAY,EAAE,MAAM,QAAQ,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAYjC,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAIhE,qBAAa,IAAI,CAAC,CAAC,SAAS,WAAW,CAAC,WAAW,CAAC;IAClD,OAAO,CAAC,MAAM,CAAC,aAAa,CAGf;IACb,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwC;IACjE,OAAO,CAAC,aAAa,CAA0B;IAC/C,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAqB;IAC3D,CAAC,SAAS,CAAC,UAAO;IAClB,OAAO,CAAC,kBAAkB,CAEC;gBAEf,aAAa,EAAE,YAAY,CAAC,CAAC,CAAC;WAyH7B,MAAM,CAAC,CAAC,SAAS,WAAW,CAAC,WAAW,CAAC,EACpD,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,GACvB,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;WAuDR,IAAI,CAAC,EAChB,SAAS,EACT,WAAW,EACX,OAAO,GACR,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;WAqBpC,GAAG,CACd,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;WAeV,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAcpD,OAAO,CAAC,uBAAuB;IAwB/B,SAAS,aAAc,CAAC,SAAS,EAAE,GAAG,KAAK,IAAI,KAAG,YAAY,CAI7D;IAED,UAAU,QAAO,YAAY,CAAC,OAAO,iBAAiB,CAAC,CAEtD;IAED,mBAAmB,QAAa,OAAO,CAAC,YAAY,EAAE,CAAC,CAKtD;IAED,OAAO,QAAa,OAAO,CAAC,IAAI,CAAC,CAYhC;IAED,iBAAiB;;;;;;;;;SAEhB;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,OAAO,IAAI,MAAM,GAAG,SAAS,CAEhC;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,gBAAgB,IAAI,YAAY,CAEnC;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,CAElD;IAED,MAAM,IAAI,IAAI;CAIf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/property/actors/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,QAAQ,CAAA;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/property/actors/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,QAAQ,CAAA;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAGzD,eAAO,MAAM,UAAU,uHAgErB,CAAA"}
|