@seedprotocol/sdk 0.1.108 → 0.1.110
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-qIJt7998.js → constants-CEnkzyny.js} +3 -3
- package/dist/{constants-qIJt7998.js.map → constants-CEnkzyny.js.map} +1 -1
- package/dist/{index-BmnXNuNp.js → index-DBeuQew5.js} +3 -3
- package/dist/{index-BmnXNuNp.js.map → index-DBeuQew5.js.map} +1 -1
- package/dist/{index-CsC8qxj6.js → index-DPl7MLMn.js} +367 -151
- package/dist/index-DPl7MLMn.js.map +1 -0
- package/dist/main.js +2 -2
- package/dist/{seed.schema.config-hUwOwJMn.js → seed.schema.config-B7qlhJai.js} +3 -3
- package/dist/{seed.schema.config-hUwOwJMn.js.map → seed.schema.config-B7qlhJai.js.map} +1 -1
- package/dist/src/ItemProperty.ts +32 -11
- package/dist/src/analyzeInput.ts +2 -2
- package/dist/src/getItem.ts +1 -1
- package/dist/src/getPublishPayload.ts +45 -49
- package/dist/src/getPublishUploads.ts +240 -0
- package/dist/src/getSegmentedItemProperties.ts +65 -0
- package/dist/src/hydrateFromDb.ts +4 -4
- package/dist/src/propertyMachine.ts +3 -2
- package/dist/src/read.ts +1 -1
- package/dist/src/resolveRelatedValue.ts +12 -12
- package/dist/src/saveImageSrc.ts +5 -5
- package/dist/src/saveItemStorage.ts +2 -2
- package/dist/src/seed.ts +31 -4
- package/dist/types/src/browser/db/read/getPublishPayload.d.ts +9 -1
- package/dist/types/src/browser/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/types/src/browser/db/read/getPublishUploads.d.ts +17 -0
- package/dist/types/src/browser/db/read/getPublishUploads.d.ts.map +1 -0
- package/dist/types/src/browser/helpers/arweave.d.ts.map +1 -0
- package/dist/types/src/browser/helpers/getSegmentedItemProperties.d.ts +9 -0
- package/dist/types/src/browser/helpers/getSegmentedItemProperties.d.ts.map +1 -0
- package/dist/types/src/browser/item/Item.d.ts +3 -1
- package/dist/types/src/browser/item/Item.d.ts.map +1 -1
- package/dist/types/src/browser/property/ItemProperty.d.ts +195 -56
- package/dist/types/src/browser/property/ItemProperty.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts +1 -2
- package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/initialize.d.ts +1 -2
- package/dist/types/src/browser/property/actors/initialize.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/resolveRelatedValue.d.ts +1 -2
- package/dist/types/src/browser/property/actors/resolveRelatedValue.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/resolveRemoteStorage.d.ts +1 -2
- package/dist/types/src/browser/property/actors/resolveRemoteStorage.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts +2 -2
- package/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/saveValueToDb/saveImageSrc.d.ts +2 -2
- package/dist/types/src/browser/property/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/saveValueToDb/saveItemStorage.d.ts +2 -2
- package/dist/types/src/browser/property/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/saveValueToDb/saveRelation.d.ts +2 -2
- package/dist/types/src/browser/property/actors/saveValueToDb/saveRelation.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/waitForDb.d.ts +2 -2
- package/dist/types/src/browser/property/actors/waitForDb.d.ts.map +1 -1
- package/dist/types/src/browser/property/propertyMachine.d.ts +195 -60
- package/dist/types/src/browser/property/propertyMachine.d.ts.map +1 -1
- package/dist/types/src/browser/schema/file/index.d.ts +1 -1
- package/dist/types/src/browser/schema/file/index.d.ts.map +1 -1
- package/dist/types/src/types/item.d.ts +1 -1
- package/dist/types/src/types/item.d.ts.map +1 -1
- package/dist/types/src/types/property.d.ts +3 -36
- package/dist/types/src/types/property.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/index-CsC8qxj6.js.map +0 -1
- package/dist/types/src/browser/schema/file/arweave.d.ts.map +0 -1
- /package/dist/types/src/browser/{schema/file → helpers}/arweave.d.ts +0 -0
package/dist/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { j as ImageSrc, I as Item, k as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, t as client, v as getCorrectId, s as getGlobalService, n as useCreateItem, p as useDeleteItem, q as useGlobalServiceStatus, l as useItem, m as useItemProperties, o as useItemProperty, u as useItems, r as useServices, w as withSeed } from './index-
|
|
1
|
+
export { j as ImageSrc, I as Item, k as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, t as client, v as getCorrectId, s as getGlobalService, n as useCreateItem, p as useDeleteItem, q as useGlobalServiceStatus, l as useItem, m as useItemProperties, o as useItemProperty, u as useItems, r as useServices, w as withSeed } from './index-DPl7MLMn.js';
|
|
2
2
|
import 'immer';
|
|
3
3
|
import 'reflect-metadata';
|
|
4
|
-
import './constants-
|
|
4
|
+
import './constants-CEnkzyny.js';
|
|
5
5
|
import 'xstate';
|
|
6
6
|
import 'arweave';
|
|
7
7
|
import 'drizzle-orm';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as __decorate, a as __metadata } from './constants-
|
|
1
|
+
import { _ as __decorate, a as __metadata } from './constants-CEnkzyny.js';
|
|
2
2
|
import 'drizzle-orm';
|
|
3
|
-
import { T as Text, M as Model } from './index-
|
|
3
|
+
import { T as Text, M as Model } from './index-DPl7MLMn.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
import 'reflect-metadata';
|
|
6
6
|
import 'xstate';
|
|
@@ -76,4 +76,4 @@ const models = {
|
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
export { models };
|
|
79
|
-
//# sourceMappingURL=seed.schema.config-
|
|
79
|
+
//# sourceMappingURL=seed.schema.config-B7qlhJai.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.schema.config-
|
|
1
|
+
{"version":3,"file":"seed.schema.config-B7qlhJai.js","sources":["../../src/shared/configs/seed.schema.config.ts"],"sourcesContent":["import { Model, Text } from '@/browser'\n\n@Model\nclass Seed {\n @Text() uid!: string\n @Text() type!: string\n}\n\n@Model\nclass Version {\n @Text() seedUid!: string\n @Text() note!: string\n}\n\n@Model\nclass Metadata {\n @Text() key!: string\n @Text() value!: string\n}\n\nexport const models = {\n Seed,\n Version,\n Metadata,\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAM,IAAI,GAAV,MAAM,IAAI,CAAA;CAGT;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA;AAFjB,IAAI,GAAA,UAAA,CAAA;IADT;AACK,CAAA,EAAA,IAAI,CAGT;AAGD,IAAM,OAAO,GAAb,MAAM,OAAO,CAAA;CAGZ;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAiB,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,SAAA,EAAA,KAAA,CAAA,CAAA;AAChB,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA;AAFjB,OAAO,GAAA,UAAA,CAAA;IADZ;AACK,CAAA,EAAA,OAAO,CAGZ;AAGD,IAAM,QAAQ,GAAd,MAAM,QAAQ,CAAA;CAGb;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAe,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,KAAA,CAAA,CAAA;AAFlB,QAAQ,GAAA,UAAA,CAAA;IADb;AACK,CAAA,EAAA,QAAQ,CAGb;AAEY,MAAA,MAAM,GAAG;IACpB,IAAI;IACJ,OAAO;IACP,QAAQ;;;;;"}
|
package/dist/src/ItemProperty.ts
CHANGED
|
@@ -58,15 +58,15 @@ export class ItemProperty<PropertyType> {
|
|
|
58
58
|
seedLocalId,
|
|
59
59
|
versionLocalId,
|
|
60
60
|
versionUid,
|
|
61
|
-
|
|
61
|
+
modelName,
|
|
62
62
|
propertyName,
|
|
63
63
|
storageTransactionId,
|
|
64
64
|
schemaUid,
|
|
65
65
|
}: Partial<CreatePropertyInstanceProps>) {
|
|
66
|
-
const ModelClass = getModel(
|
|
66
|
+
const ModelClass = getModel(modelName)
|
|
67
67
|
|
|
68
68
|
if (!ModelClass) {
|
|
69
|
-
throw new Error(`Model ${
|
|
69
|
+
throw new Error(`Model ${modelName} not found`)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
if (!propertyName) {
|
|
@@ -80,7 +80,7 @@ export class ItemProperty<PropertyType> {
|
|
|
80
80
|
seedUid,
|
|
81
81
|
versionLocalId,
|
|
82
82
|
versionUid,
|
|
83
|
-
|
|
83
|
+
modelName: modelName,
|
|
84
84
|
storageTransactionId,
|
|
85
85
|
propertyRecordSchema: ModelClass.schema[propertyName],
|
|
86
86
|
schemaUid,
|
|
@@ -150,6 +150,16 @@ export class ItemProperty<PropertyType> {
|
|
|
150
150
|
const { context } = snapshot
|
|
151
151
|
const { propertyRecordSchema } = context
|
|
152
152
|
|
|
153
|
+
// if (
|
|
154
|
+
// context.propertyName &&
|
|
155
|
+
// context.propertyName.includes('featureImage')
|
|
156
|
+
// ) {
|
|
157
|
+
// console.log(
|
|
158
|
+
// `${context.localId} context for ${snapshot.value}`,
|
|
159
|
+
// context,
|
|
160
|
+
// )
|
|
161
|
+
// }
|
|
162
|
+
|
|
153
163
|
if (context.seedLocalId) {
|
|
154
164
|
const cacheKey = ItemProperty.cacheKey(
|
|
155
165
|
context.seedLocalId,
|
|
@@ -217,12 +227,10 @@ export class ItemProperty<PropertyType> {
|
|
|
217
227
|
|
|
218
228
|
this._subject.next(renderValue)
|
|
219
229
|
if (context.seedLocalId) {
|
|
220
|
-
eventEmitter.emit(
|
|
221
|
-
`item.${itemModelName}.${context.seedLocalId}.update`,
|
|
222
|
-
)
|
|
230
|
+
eventEmitter.emit(`item.${modelName}.${context.seedLocalId}.update`)
|
|
223
231
|
}
|
|
224
232
|
if (context.seedUid) {
|
|
225
|
-
eventEmitter.emit(`item.${
|
|
233
|
+
eventEmitter.emit(`item.${modelName}.${context.seedUid}.update`)
|
|
226
234
|
}
|
|
227
235
|
},
|
|
228
236
|
)
|
|
@@ -232,7 +240,7 @@ export class ItemProperty<PropertyType> {
|
|
|
232
240
|
|
|
233
241
|
private _updateResponseListener(event) {
|
|
234
242
|
logger(
|
|
235
|
-
`[ItemProperty] [_updateResponseListener] [${this.
|
|
243
|
+
`[ItemProperty] [_updateResponseListener] [${this.modelName}.${this.seedLocalId}] ${this.propertyName} event`,
|
|
236
244
|
event,
|
|
237
245
|
)
|
|
238
246
|
}
|
|
@@ -351,14 +359,27 @@ export class ItemProperty<PropertyType> {
|
|
|
351
359
|
return this._getSnapshot().context.propertyName
|
|
352
360
|
}
|
|
353
361
|
|
|
354
|
-
get
|
|
355
|
-
return this._getSnapshot().context.
|
|
362
|
+
get modelName() {
|
|
363
|
+
return this._getSnapshot().context.modelName
|
|
356
364
|
}
|
|
357
365
|
|
|
358
366
|
get propertyDef(): Static<typeof TProperty> | undefined {
|
|
359
367
|
return this._getSnapshot().context.propertyRecordSchema
|
|
360
368
|
}
|
|
361
369
|
|
|
370
|
+
get localStoragePath(): string | void {
|
|
371
|
+
if (this.propertyDef && this.propertyDef.localStorageDir) {
|
|
372
|
+
return `/files${this.propertyDef.localStorageDir}/${this._getSnapshot().context.refResolvedValue}`
|
|
373
|
+
}
|
|
374
|
+
if (this._getSnapshot().context.localStorageDir) {
|
|
375
|
+
return `/files${this._getSnapshot().context.localStorageDir}/${this._getSnapshot().context.refResolvedValue}`
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
get versionLocalId(): string | undefined {
|
|
380
|
+
return this._getSnapshot().context.versionLocalId
|
|
381
|
+
}
|
|
382
|
+
|
|
362
383
|
get status() {
|
|
363
384
|
return this._getSnapshot().value
|
|
364
385
|
}
|
package/dist/src/analyzeInput.ts
CHANGED
|
@@ -23,7 +23,7 @@ export const analyzeInput = fromCallback<
|
|
|
23
23
|
versionUid,
|
|
24
24
|
propertyValue: existingValue,
|
|
25
25
|
propertyRecordSchema,
|
|
26
|
-
|
|
26
|
+
modelName,
|
|
27
27
|
} = context
|
|
28
28
|
|
|
29
29
|
let { schemaUid } = context
|
|
@@ -104,7 +104,7 @@ export const analyzeInput = fromCallback<
|
|
|
104
104
|
seedLocalId,
|
|
105
105
|
versionLocalId,
|
|
106
106
|
versionUid,
|
|
107
|
-
modelName
|
|
107
|
+
modelName,
|
|
108
108
|
schemaUid,
|
|
109
109
|
})
|
|
110
110
|
|
package/dist/src/getItem.ts
CHANGED
|
@@ -18,6 +18,10 @@ import { getSchemaUidForSchemaDefinition } from '@/browser/stores/eas'
|
|
|
18
18
|
import { ItemProperty } from '@/browser/property/ItemProperty'
|
|
19
19
|
import { getCorrectId } from '@/browser/helpers'
|
|
20
20
|
import { Item } from '@/browser/item/Item'
|
|
21
|
+
import debug from 'debug'
|
|
22
|
+
import { getSegmentedItemProperties } from '@/browser/helpers/getSegmentedItemProperties'
|
|
23
|
+
|
|
24
|
+
const logger = debug('app:item:getPublishPayload')
|
|
21
25
|
|
|
22
26
|
const getVersionUid = (item: Item<any>) => {
|
|
23
27
|
let versionUid
|
|
@@ -63,46 +67,6 @@ const getPropertyData = async (itemProperty: ItemProperty<any>) => {
|
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
const getSegmentedItemProperties = (item: Item<any>) => {
|
|
67
|
-
const itemBasicProperties = []
|
|
68
|
-
const itemRelationProperties = []
|
|
69
|
-
const itemListProperties = []
|
|
70
|
-
const itemStorageProperties = []
|
|
71
|
-
|
|
72
|
-
for (const itemProperty of Object.values(item.properties)) {
|
|
73
|
-
if (!itemProperty.propertyDef) {
|
|
74
|
-
continue
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (itemProperty.propertyDef.dataType === 'Relation') {
|
|
78
|
-
itemRelationProperties.push(itemProperty)
|
|
79
|
-
continue
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (itemProperty.propertyDef.dataType === 'List') {
|
|
83
|
-
itemListProperties.push(itemProperty)
|
|
84
|
-
continue
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
itemProperty.propertyDef.storageType &&
|
|
89
|
-
itemProperty.propertyDef.storageType === 'ItemStorage'
|
|
90
|
-
) {
|
|
91
|
-
itemStorageProperties.push(itemProperty)
|
|
92
|
-
continue
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
itemBasicProperties.push(itemProperty)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
itemBasicProperties,
|
|
100
|
-
itemRelationProperties,
|
|
101
|
-
itemListProperties,
|
|
102
|
-
itemStorageProperties,
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
70
|
const processBasicProperties = async (
|
|
107
71
|
itemBasicProperties: ItemProperty<any>[],
|
|
108
72
|
itemPublishData: PublishPayload,
|
|
@@ -148,6 +112,7 @@ const processBasicProperties = async (
|
|
|
148
112
|
const processRelationProperty = async (
|
|
149
113
|
relationProperty: ItemProperty<any>,
|
|
150
114
|
multiPublishPayload: MultiPublishPayload,
|
|
115
|
+
uploadedTransactions: UploadedTransaction[],
|
|
151
116
|
): Promise<MultiPublishPayload> => {
|
|
152
117
|
const value = relationProperty.getService().getSnapshot()
|
|
153
118
|
.context.propertyValue
|
|
@@ -185,7 +150,21 @@ const processRelationProperty = async (
|
|
|
185
150
|
propertiesToUpdate: [],
|
|
186
151
|
}
|
|
187
152
|
|
|
188
|
-
const { itemBasicProperties } =
|
|
153
|
+
const { itemBasicProperties, itemUploadProperties } =
|
|
154
|
+
getSegmentedItemProperties(relatedItem)
|
|
155
|
+
|
|
156
|
+
if (itemUploadProperties.length === 1) {
|
|
157
|
+
const uploadProperty = itemUploadProperties[0]
|
|
158
|
+
const itemProperty = uploadProperty.itemProperty
|
|
159
|
+
const transactionData = uploadedTransactions.find(
|
|
160
|
+
(transaction) => transaction.seedLocalId === relatedItem.seedLocalId,
|
|
161
|
+
)
|
|
162
|
+
if (transactionData) {
|
|
163
|
+
itemProperty.value = transactionData.txId
|
|
164
|
+
await itemProperty.save()
|
|
165
|
+
itemBasicProperties.push(itemProperty)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
189
168
|
|
|
190
169
|
publishPayload = await processBasicProperties(
|
|
191
170
|
itemBasicProperties,
|
|
@@ -285,15 +264,18 @@ type PublishPayload = {
|
|
|
285
264
|
|
|
286
265
|
type MultiPublishPayload = PublishPayload[]
|
|
287
266
|
|
|
267
|
+
type UploadedTransaction = {
|
|
268
|
+
txId: string
|
|
269
|
+
itemPropertyLocalId?: string
|
|
270
|
+
seedLocalId?: string
|
|
271
|
+
versionLocalId?: string
|
|
272
|
+
itemPropertyName?: string
|
|
273
|
+
}
|
|
274
|
+
|
|
288
275
|
export const getPublishPayload = async (
|
|
289
|
-
|
|
276
|
+
item: Item<any>,
|
|
277
|
+
uploadedTransactions: UploadedTransaction[],
|
|
290
278
|
): Promise<MultiPublishPayload> => {
|
|
291
|
-
const item = await getItem({ seedLocalId })
|
|
292
|
-
|
|
293
|
-
if (!item) {
|
|
294
|
-
throw new Error('Item not found')
|
|
295
|
-
}
|
|
296
|
-
|
|
297
279
|
// if (item.modelName === 'Post') {
|
|
298
280
|
// item.authors = [
|
|
299
281
|
// 'Sr0bIx9Fwj',
|
|
@@ -324,9 +306,22 @@ export const getPublishPayload = async (
|
|
|
324
306
|
itemBasicProperties,
|
|
325
307
|
itemRelationProperties,
|
|
326
308
|
itemListProperties,
|
|
327
|
-
|
|
309
|
+
itemUploadProperties,
|
|
328
310
|
} = getSegmentedItemProperties(item)
|
|
329
311
|
|
|
312
|
+
if (itemUploadProperties.length === 1) {
|
|
313
|
+
const uploadProperty = itemUploadProperties[0]
|
|
314
|
+
const itemProperty = uploadProperty.itemProperty
|
|
315
|
+
const transactionData = uploadedTransactions.find(
|
|
316
|
+
(transaction) => transaction.seedLocalId === item.seedLocalId,
|
|
317
|
+
)
|
|
318
|
+
if (transactionData) {
|
|
319
|
+
itemProperty.value = transactionData.txId
|
|
320
|
+
await itemProperty.save()
|
|
321
|
+
itemBasicProperties.push(itemProperty)
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
330
325
|
itemPublishData = await processBasicProperties(
|
|
331
326
|
itemBasicProperties,
|
|
332
327
|
itemPublishData,
|
|
@@ -338,6 +333,7 @@ export const getPublishPayload = async (
|
|
|
338
333
|
multiPublishPayload = await processRelationProperty(
|
|
339
334
|
relationProperty,
|
|
340
335
|
multiPublishPayload,
|
|
336
|
+
uploadedTransactions,
|
|
341
337
|
)
|
|
342
338
|
}
|
|
343
339
|
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { Item, ItemProperty } from '@/browser'
|
|
2
|
+
import Transaction from 'arweave/web/lib/transaction'
|
|
3
|
+
import { CreateTransactionInterface } from 'arweave/web'
|
|
4
|
+
import { getArweave } from '@/browser/helpers/arweave'
|
|
5
|
+
import { fs } from '@zenfs/core'
|
|
6
|
+
import { getCorrectId } from '@/browser/helpers'
|
|
7
|
+
import { getSegmentedItemProperties } from '@/browser/helpers/getSegmentedItemProperties'
|
|
8
|
+
import debug from 'debug'
|
|
9
|
+
|
|
10
|
+
const logger = debug('app:item:getPublishUploads')
|
|
11
|
+
|
|
12
|
+
export const getContentHash = async (
|
|
13
|
+
base64: string | null | undefined,
|
|
14
|
+
uint: Uint8Array | undefined,
|
|
15
|
+
): Promise<string> => {
|
|
16
|
+
let data
|
|
17
|
+
|
|
18
|
+
if (base64 && !uint) {
|
|
19
|
+
const encoder = new TextEncoder()
|
|
20
|
+
data = encoder.encode(base64)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (uint) {
|
|
24
|
+
data = uint
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Hash the data with SHA-256
|
|
28
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', data as Uint8Array)
|
|
29
|
+
|
|
30
|
+
// Convert the ArrayBuffer to a hex string
|
|
31
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer))
|
|
32
|
+
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('')
|
|
33
|
+
}
|
|
34
|
+
export const prepareArweaveTransaction = async (
|
|
35
|
+
data: string | Uint8Array,
|
|
36
|
+
contentHash: string | undefined,
|
|
37
|
+
): Promise<Transaction> => {
|
|
38
|
+
const transactionData: Partial<CreateTransactionInterface> = {
|
|
39
|
+
data,
|
|
40
|
+
tags: [],
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const tx = await getArweave()!.createTransaction(transactionData)
|
|
44
|
+
|
|
45
|
+
if (contentHash) {
|
|
46
|
+
logger('contentHash', contentHash)
|
|
47
|
+
logger('adding content hash tag to tx.id:', tx.id)
|
|
48
|
+
tx.addTag('Content-SHA-256', contentHash)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return tx
|
|
52
|
+
}
|
|
53
|
+
export type UploadProperty = {
|
|
54
|
+
itemProperty: ItemProperty<any>
|
|
55
|
+
childProperties: ItemProperty<any>[]
|
|
56
|
+
}
|
|
57
|
+
type ChildUploadData = {
|
|
58
|
+
propertyName: string
|
|
59
|
+
localStoragePath: string
|
|
60
|
+
}
|
|
61
|
+
const processUploadProperty = async (
|
|
62
|
+
uploadProperty: UploadProperty,
|
|
63
|
+
uploads: PublishUpload[],
|
|
64
|
+
relatedItemProperty?: ItemProperty<any>,
|
|
65
|
+
): Promise<PublishUpload[]> => {
|
|
66
|
+
const itemProperty = uploadProperty.itemProperty
|
|
67
|
+
|
|
68
|
+
const childUploads: ChildUploadData[] = []
|
|
69
|
+
|
|
70
|
+
for (const childProperty of uploadProperty.childProperties) {
|
|
71
|
+
const filePath = childProperty.localStoragePath
|
|
72
|
+
|
|
73
|
+
if (!filePath) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`No localStoragePath found for ItemProperty ${childProperty.propertyName}`,
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const exists = await fs.promises.exists(filePath)
|
|
80
|
+
if (!exists) {
|
|
81
|
+
throw new Error(`File doesn't exist at ${filePath}`)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
childUploads.push({
|
|
85
|
+
propertyName: childProperty.propertyName,
|
|
86
|
+
localStoragePath: filePath,
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// const filePath = itemProperty.localStoragePath
|
|
91
|
+
//
|
|
92
|
+
// if (!filePath) {
|
|
93
|
+
// throw new Error(
|
|
94
|
+
// `No localStoragePath found for ItemProperty ${itemProperty.propertyName}`,
|
|
95
|
+
// )
|
|
96
|
+
// }
|
|
97
|
+
//
|
|
98
|
+
// const exists = await fs.promises.exists(filePath)
|
|
99
|
+
// if (!exists) {
|
|
100
|
+
// throw new Error(`File doesn't exist at ${filePath}`)
|
|
101
|
+
//
|
|
102
|
+
// // const handle = await navigator.storage.getDirectory()
|
|
103
|
+
// //
|
|
104
|
+
// // await configureSingle({
|
|
105
|
+
// // backend: WebAccess,
|
|
106
|
+
// // handle,
|
|
107
|
+
// // })
|
|
108
|
+
// }
|
|
109
|
+
//
|
|
110
|
+
// const mainFileContents = await fs.promises.readFile(filePath)
|
|
111
|
+
let fileContents
|
|
112
|
+
let transaction: Transaction
|
|
113
|
+
|
|
114
|
+
if (!childUploads || childUploads.length === 0) {
|
|
115
|
+
if (relatedItemProperty && relatedItemProperty.localStoragePath) {
|
|
116
|
+
const filePath = relatedItemProperty.localStoragePath
|
|
117
|
+
|
|
118
|
+
const exists = await fs.promises.exists(filePath)
|
|
119
|
+
if (!exists) {
|
|
120
|
+
throw new Error(`File doesn't exist at ${filePath}`)
|
|
121
|
+
|
|
122
|
+
// const handle = await navigator.storage.getDirectory()
|
|
123
|
+
//
|
|
124
|
+
// await configureSingle({
|
|
125
|
+
// backend: WebAccess,
|
|
126
|
+
// handle,
|
|
127
|
+
// })
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
fileContents = await fs.promises.readFile(filePath)
|
|
131
|
+
}
|
|
132
|
+
if (!fileContents) {
|
|
133
|
+
return uploads
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (childUploads.length > 0) {
|
|
138
|
+
const separator = '===FILE_SEPARATOR==='
|
|
139
|
+
// let compositeFileContents = `${itemProperty.propertyName}${separator}${mainFileContents}`
|
|
140
|
+
let compositeFileContents = ''
|
|
141
|
+
|
|
142
|
+
for (const childUpload of childUploads) {
|
|
143
|
+
const childUploadContents = await fs.promises.readFile(
|
|
144
|
+
childUpload.localStoragePath,
|
|
145
|
+
)
|
|
146
|
+
compositeFileContents += `${separator}${childUpload.propertyName}${separator}${childUploadContents}`
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
fileContents = Buffer.from(compositeFileContents)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (!fileContents) {
|
|
153
|
+
throw new Error(`No file contents found for ${itemProperty.propertyName}`)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const uint8Array = new Uint8Array(
|
|
157
|
+
fileContents.buffer,
|
|
158
|
+
fileContents.byteOffset,
|
|
159
|
+
fileContents.byteLength,
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
const contentHash = await getContentHash(null, uint8Array)
|
|
163
|
+
|
|
164
|
+
transaction = await prepareArweaveTransaction(fileContents, contentHash)
|
|
165
|
+
|
|
166
|
+
let itemPropertyLocalId = relatedItemProperty
|
|
167
|
+
? relatedItemProperty.localId
|
|
168
|
+
: itemProperty.localId
|
|
169
|
+
let itemPropertyName = relatedItemProperty
|
|
170
|
+
? relatedItemProperty.propertyName
|
|
171
|
+
: itemProperty.propertyName
|
|
172
|
+
|
|
173
|
+
uploads.push({
|
|
174
|
+
itemPropertyName,
|
|
175
|
+
itemPropertyLocalId,
|
|
176
|
+
seedLocalId: itemProperty.seedLocalId!,
|
|
177
|
+
versionLocalId: itemProperty.versionLocalId!,
|
|
178
|
+
transactionToSign: transaction,
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
return uploads
|
|
182
|
+
}
|
|
183
|
+
export type PublishUpload = {
|
|
184
|
+
itemPropertyName: string
|
|
185
|
+
itemPropertyLocalId: string
|
|
186
|
+
seedLocalId: string
|
|
187
|
+
versionLocalId: string
|
|
188
|
+
transactionToSign: Transaction
|
|
189
|
+
}
|
|
190
|
+
export const getPublishUploads = async (
|
|
191
|
+
item: Item<any>,
|
|
192
|
+
uploads: PublishUpload[] = [],
|
|
193
|
+
relatedItemProperty?: ItemProperty<any>,
|
|
194
|
+
) => {
|
|
195
|
+
// if (item.modelName === 'Post') {
|
|
196
|
+
// if (!item.authors) {
|
|
197
|
+
// item.authors = [
|
|
198
|
+
// 'Sr0bIx9Fwj',
|
|
199
|
+
// '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',
|
|
200
|
+
// ]
|
|
201
|
+
// }
|
|
202
|
+
// }
|
|
203
|
+
|
|
204
|
+
const { itemUploadProperties, itemRelationProperties } =
|
|
205
|
+
getSegmentedItemProperties(item)
|
|
206
|
+
|
|
207
|
+
for (const uploadProperty of itemUploadProperties) {
|
|
208
|
+
uploads = await processUploadProperty(
|
|
209
|
+
uploadProperty,
|
|
210
|
+
uploads,
|
|
211
|
+
relatedItemProperty,
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
for (const relationProperty of itemRelationProperties) {
|
|
216
|
+
const propertyValue = relationProperty.getService().getSnapshot()
|
|
217
|
+
.context.propertyValue
|
|
218
|
+
|
|
219
|
+
if (!propertyValue || relationProperty.uid) {
|
|
220
|
+
continue
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const { localId: seedLocalId, uid: seedUid } = getCorrectId(propertyValue)
|
|
224
|
+
|
|
225
|
+
const relatedItem = await Item.find({
|
|
226
|
+
seedLocalId,
|
|
227
|
+
seedUid,
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
if (!relatedItem) {
|
|
231
|
+
throw new Error(
|
|
232
|
+
`No relatedItem found for ${relationProperty.propertyName}`,
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
uploads = await getPublishUploads(relatedItem, uploads, relationProperty)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return uploads
|
|
240
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Item } from '@/browser'
|
|
2
|
+
import { UploadProperty } from '@/browser/db/read/getPublishUploads'
|
|
3
|
+
|
|
4
|
+
export const getSegmentedItemProperties = (item: Item<any>) => {
|
|
5
|
+
const itemBasicProperties = []
|
|
6
|
+
const itemRelationProperties = []
|
|
7
|
+
const itemListProperties = []
|
|
8
|
+
const itemUploadProperties: UploadProperty[] = []
|
|
9
|
+
const itemStorageProperties = []
|
|
10
|
+
let itemStorageTransactionProperty: UploadProperty | undefined
|
|
11
|
+
|
|
12
|
+
for (const itemProperty of Object.values(item.properties)) {
|
|
13
|
+
if (!itemProperty.propertyDef) {
|
|
14
|
+
continue
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const isItemStorage =
|
|
18
|
+
itemProperty.propertyDef.storageType &&
|
|
19
|
+
itemProperty.propertyDef.storageType === 'ItemStorage'
|
|
20
|
+
|
|
21
|
+
const isImageSrc =
|
|
22
|
+
itemProperty.propertyDef.dataType === 'Relation' &&
|
|
23
|
+
itemProperty.propertyDef.refValueType === 'ImageSrc'
|
|
24
|
+
|
|
25
|
+
const isStorageTransaction =
|
|
26
|
+
itemProperty.propertyName === 'storageTransactionId'
|
|
27
|
+
|
|
28
|
+
if (itemProperty.propertyDef.dataType === 'Relation') {
|
|
29
|
+
itemRelationProperties.push(itemProperty)
|
|
30
|
+
continue
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (itemProperty.propertyDef.dataType === 'List') {
|
|
34
|
+
itemListProperties.push(itemProperty)
|
|
35
|
+
continue
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (isItemStorage) {
|
|
39
|
+
itemStorageProperties.push(itemProperty)
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (isStorageTransaction) {
|
|
44
|
+
itemStorageTransactionProperty = { itemProperty, childProperties: [] }
|
|
45
|
+
continue
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
itemBasicProperties.push(itemProperty)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (itemStorageTransactionProperty && itemStorageProperties.length > 0) {
|
|
52
|
+
itemStorageTransactionProperty.childProperties = itemStorageProperties
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (itemStorageTransactionProperty) {
|
|
56
|
+
itemUploadProperties.push(itemStorageTransactionProperty)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
itemBasicProperties,
|
|
61
|
+
itemRelationProperties,
|
|
62
|
+
itemListProperties,
|
|
63
|
+
itemUploadProperties,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -21,7 +21,7 @@ export const hydrateFromDb = fromCallback<
|
|
|
21
21
|
propertyName: propertyNameRaw,
|
|
22
22
|
propertyValue,
|
|
23
23
|
propertyRecordSchema,
|
|
24
|
-
|
|
24
|
+
modelName,
|
|
25
25
|
} = context
|
|
26
26
|
|
|
27
27
|
let propertyName = propertyNameRaw
|
|
@@ -264,8 +264,8 @@ export const hydrateFromDb = fromCallback<
|
|
|
264
264
|
schemaUid: schemaUidFromDb,
|
|
265
265
|
refValueType,
|
|
266
266
|
localStorageDir,
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
refResolvedValue,
|
|
268
|
+
refResolvedDisplayValue,
|
|
269
269
|
renderValue: refResolvedDisplayValue,
|
|
270
270
|
populatedFromDb: true,
|
|
271
271
|
})
|
|
@@ -278,7 +278,7 @@ export const hydrateFromDb = fromCallback<
|
|
|
278
278
|
const { Item } = await import(`@/browser/item`)
|
|
279
279
|
const item = await Item.find({
|
|
280
280
|
seedLocalId,
|
|
281
|
-
modelName
|
|
281
|
+
modelName,
|
|
282
282
|
})
|
|
283
283
|
if (item) {
|
|
284
284
|
const filePath = `/files/${localStorageDir}/${refResolvedValue}`
|
|
@@ -105,8 +105,9 @@ export const propertyMachine = setup({
|
|
|
105
105
|
resolvingRelatedValueSuccess: {
|
|
106
106
|
target: 'idle',
|
|
107
107
|
actions: assign({
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
refResolvedDisplayValue: ({ event }) =>
|
|
109
|
+
event.refResolvedDisplayValue,
|
|
110
|
+
resolvedValue: ({ event }) => event.refResolvedValue,
|
|
110
111
|
}),
|
|
111
112
|
},
|
|
112
113
|
resolvingRelatedValueDone: {
|