@seedprotocol/sdk 0.2.51 → 0.2.53
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/{ArweaveClient-D1TsTBoj.js → ArweaveClient-D5iJisYr.js} +2 -2
- package/dist/{ArweaveClient-DpdXUcVJ.js.map → ArweaveClient-D5iJisYr.js.map} +1 -1
- package/dist/{ArweaveClient-DpdXUcVJ.js → ArweaveClient-HEIIuOfB.js} +2 -2
- package/dist/{ArweaveClient-D1TsTBoj.js.map → ArweaveClient-HEIIuOfB.js.map} +1 -1
- package/dist/{Db-quJxmvHH.js → Db-Bh_lvrAN.js} +6 -3
- package/dist/Db-Bh_lvrAN.js.map +1 -0
- package/dist/{Db-DMJ0v3gO.js → Db-DqBP6XK2.js} +3 -3
- package/dist/{Db-DMJ0v3gO.js.map → Db-DqBP6XK2.js.map} +1 -1
- package/dist/{EasClient-ClZDuT3o.js → EasClient-D3wKgt0o.js} +2 -2
- package/dist/{EasClient-DfnGY_2X.js.map → EasClient-D3wKgt0o.js.map} +1 -1
- package/dist/{EasClient-DfnGY_2X.js → EasClient-jqkT2ZBt.js} +2 -2
- package/dist/{EasClient-ClZDuT3o.js.map → EasClient-jqkT2ZBt.js.map} +1 -1
- package/dist/{FileManager-texI7UwL.js → FileManager-4mWYO3Mt.js} +3 -5
- package/dist/FileManager-4mWYO3Mt.js.map +1 -0
- package/dist/{Item-D4n439Ei.js → Item-COP3FuaU.js} +3 -3
- package/dist/{Item-D4n439Ei.js.map → Item-COP3FuaU.js.map} +1 -1
- package/dist/{ItemProperty-Be5ymRVT.js → ItemProperty-BFn9wM65.js} +3 -3
- package/dist/{ItemProperty-Be5ymRVT.js.map → ItemProperty-BFn9wM65.js.map} +1 -1
- package/dist/{QueryClient-B1HkAaJo.js → QueryClient-CBOP3OoU.js} +2 -2
- package/dist/{QueryClient-B1HkAaJo.js.map → QueryClient-CBOP3OoU.js.map} +1 -1
- package/dist/{QueryClient-BPoc9eBn.js → QueryClient-bKb3SB0W.js} +2 -2
- package/dist/{QueryClient-BPoc9eBn.js.map → QueryClient-bKb3SB0W.js.map} +1 -1
- package/dist/bin.js +5 -5
- package/dist/{constants-5PxfAeqj.js → constants-CIDbABDz.js} +2 -2
- package/dist/{constants-5PxfAeqj.js.map → constants-CIDbABDz.js.map} +1 -1
- package/dist/{index-BLla2o05.js → index-C4xqqsLw.js} +3 -3
- package/dist/index-C4xqqsLw.js.map +1 -0
- package/dist/{index-BeKRizLf.js → index-CLvyWg5f.js} +257 -145
- package/dist/index-CLvyWg5f.js.map +1 -0
- package/dist/main.js +2 -2
- package/dist/package.json +189 -0
- package/dist/{seed.schema.config-CMpV_hyS.js → seed.schema.config-Bao3o6wu.js} +3 -3
- package/dist/{seed.schema.config-CMpV_hyS.js.map → seed.schema.config-Bao3o6wu.js.map} +1 -1
- package/dist/types/src/client/BaseClientManager.d.ts +7 -0
- package/dist/types/src/client/BaseClientManager.d.ts.map +1 -0
- package/dist/types/src/client/actions/setAddresses.d.ts +2 -0
- package/dist/types/src/client/actions/setAddresses.d.ts.map +1 -0
- package/dist/types/src/client/actors/initialize.d.ts +4 -0
- package/dist/types/src/client/actors/initialize.d.ts.map +1 -0
- package/dist/types/src/client/actors/saveAppState.d.ts +5 -0
- package/dist/types/src/client/actors/saveAppState.d.ts.map +1 -0
- package/dist/types/src/client/clientManagerMachine.d.ts +19 -0
- package/dist/types/src/client/clientManagerMachine.d.ts.map +1 -0
- package/dist/types/src/client/index.d.ts +41 -0
- package/dist/types/src/client/index.d.ts.map +1 -0
- package/dist/types/src/client.d.ts.map +1 -1
- package/dist/types/src/node/db/Db.d.ts.map +1 -1
- package/dist/types/src/node/helpers/FileManager.d.ts.map +1 -1
- package/dist/types/src/services/internal/actors/validateInput.d.ts.map +1 -1
- package/dist/types/src/types/machines.d.ts +5 -0
- package/dist/types/src/types/machines.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/Db-quJxmvHH.js.map +0 -1
- package/dist/FileManager-texI7UwL.js.map +0 -1
- package/dist/index-BLla2o05.js.map +0 -1
- package/dist/index-BeKRizLf.js.map +0 -1
- package/dist/src/AppStateSchema.ts +0 -10
- package/dist/src/ArweaveClient.ts +0 -13
- package/dist/src/Attestation.ts +0 -21
- package/dist/src/BaseArweaveClient.ts +0 -13
- package/dist/src/BaseDb.ts +0 -35
- package/dist/src/BaseEasClient.ts +0 -13
- package/dist/src/BaseFileManager.ts +0 -56
- package/dist/src/BaseItem.ts +0 -413
- package/dist/src/BaseItemProperty.ts +0 -416
- package/dist/src/BaseQueryClient.ts +0 -13
- package/dist/src/ConfigSchema.ts +0 -15
- package/dist/src/Db.ts +0 -78
- package/dist/src/EasClient.ts +0 -13
- package/dist/src/FileDownloader.ts +0 -63
- package/dist/src/FileManager.ts +0 -57
- package/dist/src/IDb.ts +0 -7
- package/dist/src/IEasClient.ts +0 -2
- package/dist/src/IItem.ts +0 -26
- package/dist/src/IItemProperty.ts +0 -28
- package/dist/src/IQueryClient.ts +0 -4
- package/dist/src/ImageResizer.ts +0 -81
- package/dist/src/Item.ts +0 -12
- package/dist/src/ItemProperty.ts +0 -9
- package/dist/src/MetadataSchema.ts +0 -28
- package/dist/src/ModelSchema.ts +0 -46
- package/dist/src/ModelUidSchema.ts +0 -16
- package/dist/src/PropertyUidSchema.ts +0 -16
- package/dist/src/QueryClient.ts +0 -22
- package/dist/src/Schema.ts +0 -17
- package/dist/src/SeedProtocolSdk.d.ts +0 -19
- package/dist/src/SeedSchema.ts +0 -29
- package/dist/src/VersionSchema.ts +0 -16
- package/dist/src/actors.ts +0 -295
- package/dist/src/addModelsToDb.ts +0 -152
- package/dist/src/allItems.ts +0 -31
- package/dist/src/analyzeInput.ts +0 -144
- package/dist/src/browser.app.db.config.ts +0 -27
- package/dist/src/browser.ts +0 -30
- package/dist/src/checkStatus.ts +0 -50
- package/dist/src/client.ts +0 -148
- package/dist/src/configureFs.ts +0 -94
- package/dist/src/connectToDb.ts +0 -41
- package/dist/src/connectionManager.ts +0 -67
- package/dist/src/constants.ts +0 -125
- package/dist/src/content-hash.ts +0 -30
- package/dist/src/create.ts +0 -39
- package/dist/src/createMetadata.ts +0 -77
- package/dist/src/createNewItem.ts +0 -61
- package/dist/src/createPublishAttempt.ts +0 -16
- package/dist/src/createSeed.ts +0 -31
- package/dist/src/createSeeds.ts +0 -24
- package/dist/src/createVersion.ts +0 -33
- package/dist/src/dbMachine.ts +0 -182
- package/dist/src/deleteItem.ts +0 -19
- package/dist/src/download.ts +0 -202
- package/dist/src/drizzle.ts +0 -78
- package/dist/src/eas.ts +0 -40
- package/dist/src/environment.ts +0 -35
- package/dist/src/eventBus.ts +0 -5
- package/dist/src/events.ts +0 -14
- package/dist/src/fetchDataFromEas.ts +0 -94
- package/dist/src/fetchDbData.ts +0 -19
- package/dist/src/fetchRelatedItems.ts +0 -184
- package/dist/src/fetchSeeds.ts +0 -52
- package/dist/src/fetchVersions.ts +0 -49
- package/dist/src/files.ts +0 -81
- package/dist/src/filesDownload.ts +0 -326
- package/dist/src/fragment-masking.ts +0 -87
- package/dist/src/getExistingItem.ts +0 -60
- package/dist/src/getItem.ts +0 -32
- package/dist/src/getItemData.ts +0 -99
- package/dist/src/getItemProperties.ts +0 -56
- package/dist/src/getItemProperty.ts +0 -34
- package/dist/src/getItems.ts +0 -70
- package/dist/src/getMetadata.ts +0 -40
- package/dist/src/getModelSchemas.ts +0 -89
- package/dist/src/getPropertyData.ts +0 -50
- package/dist/src/getPublishPayload.ts +0 -355
- package/dist/src/getPublishUploads.ts +0 -207
- package/dist/src/getRelationValueData.ts +0 -27
- package/dist/src/getSchemaForItemProperty.ts +0 -68
- package/dist/src/getSchemaForModel.ts +0 -42
- package/dist/src/getSchemaUidForModel.ts +0 -32
- package/dist/src/getSeedData.ts +0 -34
- package/dist/src/getSegmentedItemProperties.ts +0 -65
- package/dist/src/getStorageTransactionIdForSeedUid.ts +0 -38
- package/dist/src/getVersionData.ts +0 -46
- package/dist/src/getVersionsForVersionUids.ts +0 -39
- package/dist/src/globalMachine.ts +0 -280
- package/dist/src/gql.ts +0 -118
- package/dist/src/graphql.ts +0 -3209
- package/dist/src/helpers.ts +0 -273
- package/dist/src/hydrateExistingItem.ts +0 -137
- package/dist/src/hydrateFromDb.ts +0 -270
- package/dist/src/hydrateNewItem.ts +0 -34
- package/dist/src/imageResize.ts +0 -507
- package/dist/src/index.d.ts +0 -5
- package/dist/src/index.ts +0 -4
- package/dist/src/initialize.ts +0 -124
- package/dist/src/internalMachine.ts +0 -238
- package/dist/src/itemMachineAll.ts +0 -157
- package/dist/src/itemMachineSingle.ts +0 -158
- package/dist/src/loadAppDb.ts +0 -47
- package/dist/src/machines.ts +0 -60
- package/dist/src/metadataLatest.ts +0 -34
- package/dist/src/migrate.ts +0 -53
- package/dist/src/model.ts +0 -72
- package/dist/src/modelClass.ts +0 -19
- package/dist/src/node.app.db.config.ts +0 -41
- package/dist/src/prepareDb.ts +0 -29
- package/dist/src/preparePublishRequestData.ts +0 -81
- package/dist/src/processItems.ts +0 -74
- package/dist/src/property.ts +0 -156
- package/dist/src/propertyMachine.ts +0 -202
- package/dist/src/publish.ts +0 -28
- package/dist/src/publishMachine.ts +0 -77
- package/dist/src/queries.ts +0 -13
- package/dist/src/recoverDeletedItem.ts +0 -14
- package/dist/src/reload.ts +0 -33
- package/dist/src/request.ts +0 -45
- package/dist/src/requestAll.ts +0 -157
- package/dist/src/resolveRelatedValue.ts +0 -367
- package/dist/src/resolveRemoteStorage.ts +0 -88
- package/dist/src/saveAppState.ts +0 -19
- package/dist/src/saveConfig.ts +0 -88
- package/dist/src/saveDataToDb.ts +0 -145
- package/dist/src/saveImageSrc.ts +0 -242
- package/dist/src/saveItemStorage.ts +0 -156
- package/dist/src/saveMetadata.ts +0 -18
- package/dist/src/savePublishService.ts +0 -30
- package/dist/src/saveRelation.ts +0 -112
- package/dist/src/seed.schema.config.ts +0 -25
- package/dist/src/seed.ts +0 -10
- package/dist/src/seedProtocol.ts +0 -17
- package/dist/src/services.ts +0 -365
- package/dist/src/sqlWasmClient.ts +0 -88
- package/dist/src/syncDbWithEas.ts +0 -628
- package/dist/src/trash.ts +0 -29
- package/dist/src/ts-to-proto.ts +0 -101
- package/dist/src/types.ts +0 -12
- package/dist/src/updateItemPropertyValue.ts +0 -243
- package/dist/src/updateMachineContext.ts +0 -21
- package/dist/src/updateMetadata.ts +0 -59
- package/dist/src/upload.ts +0 -86
- package/dist/src/validate.ts +0 -45
- package/dist/src/validateInput.ts +0 -47
- package/dist/src/validateItemData.ts +0 -20
- package/dist/src/versionData.ts +0 -24
- package/dist/src/waitForDb.ts +0 -25
- package/dist/src/waitForFiles.ts +0 -34
- package/dist/src/wasm.d.ts +0 -8300
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import { convertTxIdToImageSrc } from '@/helpers'
|
|
3
|
-
import fs from '@zenfs/core'
|
|
4
|
-
import debug from 'debug'
|
|
5
|
-
import { FromCallbackInput } from '@/types/machines'
|
|
6
|
-
import { PropertyMachineContext } from '@/types/property'
|
|
7
|
-
import { getStorageTransactionIdForSeedUid } from '@/db/read/getStorageTransactionIdForSeedUid'
|
|
8
|
-
import { getRelationValueData } from '@/db/read/getRelationValueData'
|
|
9
|
-
|
|
10
|
-
const logger = debug('app:property:actors:resolveRelatedValue')
|
|
11
|
-
|
|
12
|
-
const storageTransactionIdToContentUrl = new Map<string, string>()
|
|
13
|
-
const refResolvedValueToContentUrl = new Map<string, string>()
|
|
14
|
-
const seedUidToContentUrl = new Map<string, string>()
|
|
15
|
-
|
|
16
|
-
export const resolveRelatedValue = fromCallback<
|
|
17
|
-
EventObject,
|
|
18
|
-
FromCallbackInput<PropertyMachineContext, EventObject>
|
|
19
|
-
>(({ sendBack, input: { context } }) => {
|
|
20
|
-
const {
|
|
21
|
-
isRelation,
|
|
22
|
-
propertyValue,
|
|
23
|
-
propertyName,
|
|
24
|
-
seedUid,
|
|
25
|
-
propertyRecordSchema,
|
|
26
|
-
populatedFromDb,
|
|
27
|
-
schemaUid,
|
|
28
|
-
} = context
|
|
29
|
-
|
|
30
|
-
const _resolveRelatedValue = async () => {
|
|
31
|
-
if (!propertyValue || !isRelation || populatedFromDb) {
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let parsedValue
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
parsedValue = JSON.parse(propertyValue)
|
|
39
|
-
} catch (error) {
|
|
40
|
-
logger(`${propertyName} value is not a JSON string.`)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!parsedValue && seedUidToContentUrl.has(propertyValue)) {
|
|
44
|
-
const contentUrl = seedUidToContentUrl.get(propertyValue)
|
|
45
|
-
sendBack({
|
|
46
|
-
type: 'updateContext',
|
|
47
|
-
renderValue: contentUrl,
|
|
48
|
-
})
|
|
49
|
-
sendBack({
|
|
50
|
-
type: 'resolvingRelatedValueSuccess',
|
|
51
|
-
refResolvedDisplayValue: contentUrl,
|
|
52
|
-
})
|
|
53
|
-
return true
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (Array.isArray(propertyValue)) {
|
|
57
|
-
// TODO: Handle array of seedUids
|
|
58
|
-
logger(`${propertyName} value is an array of seedUids`)
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (Array.isArray(parsedValue)) {
|
|
63
|
-
logger(`${propertyName} value is a stringified array of seedUids`)
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const storageTransactionId =
|
|
68
|
-
await getStorageTransactionIdForSeedUid(propertyValue)
|
|
69
|
-
|
|
70
|
-
if (storageTransactionId) {
|
|
71
|
-
if (storageTransactionIdToContentUrl.has(storageTransactionId)) {
|
|
72
|
-
const contentUrl =
|
|
73
|
-
storageTransactionIdToContentUrl.get(storageTransactionId)
|
|
74
|
-
sendBack({
|
|
75
|
-
type: 'updateContext',
|
|
76
|
-
renderValue: contentUrl,
|
|
77
|
-
})
|
|
78
|
-
sendBack({
|
|
79
|
-
type: 'resolvingRelatedValueSuccess',
|
|
80
|
-
refResolvedDisplayValue: contentUrl,
|
|
81
|
-
refResolvedValue: storageTransactionId,
|
|
82
|
-
})
|
|
83
|
-
return true
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const contentUrl = await convertTxIdToImageSrc(storageTransactionId)
|
|
87
|
-
if (contentUrl) {
|
|
88
|
-
seedUidToContentUrl.set(propertyValue, contentUrl)
|
|
89
|
-
}
|
|
90
|
-
sendBack({
|
|
91
|
-
type: 'updateContext',
|
|
92
|
-
renderValue: contentUrl,
|
|
93
|
-
})
|
|
94
|
-
sendBack({
|
|
95
|
-
type: 'resolvingRelatedValueSuccess',
|
|
96
|
-
refResolvedDisplayValue: contentUrl,
|
|
97
|
-
refResolvedValue: storageTransactionId,
|
|
98
|
-
})
|
|
99
|
-
return true
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const relationValueData = await getRelationValueData(propertyValue)
|
|
103
|
-
|
|
104
|
-
if (relationValueData) {
|
|
105
|
-
const { refResolvedValue } = relationValueData
|
|
106
|
-
const propertyValueFromDb = relationValueData.propertyValue
|
|
107
|
-
|
|
108
|
-
// This handles a local-only relation value and resolves from the filesystem
|
|
109
|
-
if (
|
|
110
|
-
refResolvedValue &&
|
|
111
|
-
propertyRecordSchema.dataType === 'Relation' &&
|
|
112
|
-
propertyValueFromDb.length === 10 &&
|
|
113
|
-
propertyRecordSchema.ref
|
|
114
|
-
) {
|
|
115
|
-
if (refResolvedValueToContentUrl.has(refResolvedValue)) {
|
|
116
|
-
const contentUrl = refResolvedValueToContentUrl.get(refResolvedValue)
|
|
117
|
-
sendBack({
|
|
118
|
-
type: 'updateContext',
|
|
119
|
-
renderValue: contentUrl,
|
|
120
|
-
})
|
|
121
|
-
sendBack({
|
|
122
|
-
type: 'resolvingRelatedValueSuccess',
|
|
123
|
-
refResolvedDisplayValue: contentUrl,
|
|
124
|
-
})
|
|
125
|
-
return true
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const fileExists = await fs.promises.exists(
|
|
129
|
-
'/files/images/' + refResolvedValue,
|
|
130
|
-
)
|
|
131
|
-
if (fileExists) {
|
|
132
|
-
const fileContents = await fs.promises.readFile(
|
|
133
|
-
'/files/images/' + refResolvedValue,
|
|
134
|
-
)
|
|
135
|
-
const fileHandler = new File([fileContents], refResolvedValue)
|
|
136
|
-
const contentUrl = URL.createObjectURL(fileHandler)
|
|
137
|
-
refResolvedValueToContentUrl.set(refResolvedValue, contentUrl)
|
|
138
|
-
sendBack({
|
|
139
|
-
type: 'updateContext',
|
|
140
|
-
renderValue: contentUrl,
|
|
141
|
-
})
|
|
142
|
-
sendBack({
|
|
143
|
-
type: 'resolvingRelatedValueSuccess',
|
|
144
|
-
refResolvedDisplayValue: contentUrl,
|
|
145
|
-
})
|
|
146
|
-
return true
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (typeof propertyValueFromDb === 'string') {
|
|
151
|
-
// Check files for a filename that matches the propertyValue
|
|
152
|
-
if (
|
|
153
|
-
propertyRecordSchema &&
|
|
154
|
-
propertyRecordSchema.refValueType === 'ImageSrc'
|
|
155
|
-
) {
|
|
156
|
-
let contentUrl
|
|
157
|
-
|
|
158
|
-
if (storageTransactionIdToContentUrl.has(propertyValueFromDb)) {
|
|
159
|
-
contentUrl =
|
|
160
|
-
storageTransactionIdToContentUrl.get(propertyValueFromDb)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (!contentUrl) {
|
|
164
|
-
const imageFileExists = await fs.promises.exists(
|
|
165
|
-
`/images/${propertyValue}`,
|
|
166
|
-
)
|
|
167
|
-
if (imageFileExists) {
|
|
168
|
-
const fileContents = await fs.promises.readFile(
|
|
169
|
-
`/images/${propertyValue}`,
|
|
170
|
-
)
|
|
171
|
-
const fileHandler = new File([fileContents], propertyValue)
|
|
172
|
-
contentUrl = URL.createObjectURL(fileHandler)
|
|
173
|
-
storageTransactionIdToContentUrl.set(
|
|
174
|
-
propertyValueFromDb,
|
|
175
|
-
contentUrl,
|
|
176
|
-
)
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (contentUrl) {
|
|
181
|
-
sendBack({
|
|
182
|
-
type: 'updateContext',
|
|
183
|
-
renderValue: contentUrl,
|
|
184
|
-
})
|
|
185
|
-
sendBack({
|
|
186
|
-
type: 'resolvingRelatedValueSuccess',
|
|
187
|
-
refResolvedDisplayValue: contentUrl,
|
|
188
|
-
})
|
|
189
|
-
return true
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
_resolveRelatedValue().then((success) => {
|
|
197
|
-
// if (success) {
|
|
198
|
-
// sendBack({
|
|
199
|
-
// type: 'resolvingRelatedValueDone',
|
|
200
|
-
// })
|
|
201
|
-
// }
|
|
202
|
-
// return
|
|
203
|
-
sendBack({
|
|
204
|
-
type: 'resolvingRelatedValueDone',
|
|
205
|
-
})
|
|
206
|
-
})
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
// const eventKey = `storage.transaction.${initialValue}.contentUrl.response`
|
|
210
|
-
//
|
|
211
|
-
// const contentUrlListener = async (event) => {
|
|
212
|
-
// console.log('[itemProperty] [constructor] contentUrlListener', event)
|
|
213
|
-
// }
|
|
214
|
-
//
|
|
215
|
-
// eventEmitter.once(eventKey, contentUrlListener)
|
|
216
|
-
//
|
|
217
|
-
// const ready = getArePropertyEventHandlersReady()
|
|
218
|
-
//
|
|
219
|
-
// console.log('[itemProperty] [constructor] ready', ready)
|
|
220
|
-
//
|
|
221
|
-
// eventEmitter.emit('storage.transaction.contentUrl.request', {
|
|
222
|
-
// storageTransactionId: initialValue,
|
|
223
|
-
// })
|
|
224
|
-
|
|
225
|
-
// Related property values can either be seedUid or seedUid[]
|
|
226
|
-
// let relatedSeedUid: string
|
|
227
|
-
// let relatedSeedUids: string[]
|
|
228
|
-
//
|
|
229
|
-
// if (Array.isArray(propertyValue)) {
|
|
230
|
-
// relatedSeedUids = propertyValue
|
|
231
|
-
// } else {
|
|
232
|
-
// relatedSeedUid = propertyValue
|
|
233
|
-
// }
|
|
234
|
-
//
|
|
235
|
-
// if (relatedSeedUid) {
|
|
236
|
-
// console.log(
|
|
237
|
-
// `[property/actors] [resolveRelatedValue] seedUid: ${relatedSeedUid}`,
|
|
238
|
-
// )
|
|
239
|
-
// const latestVersionOfRelatedSeedQuery = await appDb.run(
|
|
240
|
-
// sql.raw(
|
|
241
|
-
// `
|
|
242
|
-
// SELECT local_id, uid, MAX(attestation_created_at)
|
|
243
|
-
// FROM versions
|
|
244
|
-
// WHERE seed_uid = '${relatedSeedUid}';
|
|
245
|
-
// `,
|
|
246
|
-
// ),
|
|
247
|
-
// )
|
|
248
|
-
// if (
|
|
249
|
-
// latestVersionOfRelatedSeedQuery &&
|
|
250
|
-
// latestVersionOfRelatedSeedQuery.rows &&
|
|
251
|
-
// latestVersionOfRelatedSeedQuery.rows.length > 0
|
|
252
|
-
// ) {
|
|
253
|
-
// const latestVersionOfRelatedSeed =
|
|
254
|
-
// latestVersionOfRelatedSeedQuery.rows[0]
|
|
255
|
-
// console.log(
|
|
256
|
-
// '[property/actors] [resolveRelatedValue] latestVersionOfRelatedSeed',
|
|
257
|
-
// latestVersionOfRelatedSeed,
|
|
258
|
-
// )
|
|
259
|
-
// const storageIdQuery = await appDb.run(
|
|
260
|
-
// sql.raw(
|
|
261
|
-
// `
|
|
262
|
-
// SELECT property_value, MAX(attestation_created_at), ref_resolved_display_value, ref_resolved_value
|
|
263
|
-
// FROM metadata
|
|
264
|
-
// WHERE seed_uid = '${relatedSeedUid}'
|
|
265
|
-
// AND property_name = 'storageTransactionId';
|
|
266
|
-
// `,
|
|
267
|
-
// ),
|
|
268
|
-
// )
|
|
269
|
-
//
|
|
270
|
-
// if (
|
|
271
|
-
// storageIdQuery &&
|
|
272
|
-
// storageIdQuery.rows &&
|
|
273
|
-
// storageIdQuery.rows.length > 0
|
|
274
|
-
// ) {
|
|
275
|
-
// const storageId = storageIdQuery.rows[0][0]
|
|
276
|
-
//
|
|
277
|
-
// if (!storageId) {
|
|
278
|
-
// console.error(
|
|
279
|
-
// `storageId not found for ${propertyName} with relatedSeedUid ${relatedSeedUid}`,
|
|
280
|
-
// )
|
|
281
|
-
// }
|
|
282
|
-
//
|
|
283
|
-
// const refResolvedDisplayValue = storageIdQuery.rows[0][2]
|
|
284
|
-
// let resolvedValue = storageIdQuery.rows[0][3]
|
|
285
|
-
//
|
|
286
|
-
// if (refResolvedDisplayValue && resolvedValue) {
|
|
287
|
-
// sendBack({
|
|
288
|
-
// type: 'resolvingRelatedValueSuccess',
|
|
289
|
-
// refResolvedDisplayValue,
|
|
290
|
-
// resolvedValue,
|
|
291
|
-
// })
|
|
292
|
-
// return
|
|
293
|
-
// }
|
|
294
|
-
//
|
|
295
|
-
// console.log(
|
|
296
|
-
// '[property/actors] [resolveRelatedValue] storageId',
|
|
297
|
-
// storageId,
|
|
298
|
-
// )
|
|
299
|
-
//
|
|
300
|
-
// const contentUrl = await convertTxIdToImageSrc(storageId)
|
|
301
|
-
//
|
|
302
|
-
// if (!contentUrl) {
|
|
303
|
-
// throw new Error(
|
|
304
|
-
// `contentUrl not found for ${propertyName} with relatedSeedUid ${relatedSeedUid}`,
|
|
305
|
-
// )
|
|
306
|
-
// }
|
|
307
|
-
//
|
|
308
|
-
// await appDb.run(
|
|
309
|
-
// sql.raw(
|
|
310
|
-
// `UPDATE metadata
|
|
311
|
-
// SET ref_resolved_display_value = '${contentUrl}',
|
|
312
|
-
// ref_resolved_value = '${storageId}'
|
|
313
|
-
// WHERE seed_uid = '${relatedSeedUid}'
|
|
314
|
-
// AND property_name = 'storageTransactionId';
|
|
315
|
-
// `,
|
|
316
|
-
// ),
|
|
317
|
-
// )
|
|
318
|
-
//
|
|
319
|
-
// sendBack({
|
|
320
|
-
// type: 'resolvingRelatedValueSuccess',
|
|
321
|
-
// refResolvedDisplayValue: contentUrl,
|
|
322
|
-
// resolvedValue: storageId,
|
|
323
|
-
// })
|
|
324
|
-
// }
|
|
325
|
-
// }
|
|
326
|
-
//
|
|
327
|
-
// const versionUidQuery = await appDb.run(
|
|
328
|
-
// sql.raw(
|
|
329
|
-
// `
|
|
330
|
-
// SELECT uid
|
|
331
|
-
// FROM versions
|
|
332
|
-
// WHERE seed_uid = '${relatedSeedUid}';
|
|
333
|
-
// `,
|
|
334
|
-
// ),
|
|
335
|
-
// )
|
|
336
|
-
//
|
|
337
|
-
// if (
|
|
338
|
-
// versionUidQuery &&
|
|
339
|
-
// versionUidQuery.rows &&
|
|
340
|
-
// versionUidQuery.rows.length > 0
|
|
341
|
-
// ) {
|
|
342
|
-
// const versionUids = versionUidQuery.rows.map((row) => row[0])
|
|
343
|
-
// console.log(
|
|
344
|
-
// '[property/actors] [resolveRelatedValue] versionUids',
|
|
345
|
-
// versionUids,
|
|
346
|
-
// )
|
|
347
|
-
// const { itemProperties } = await easClient.request(GET_PROPERTIES, {
|
|
348
|
-
// where: {
|
|
349
|
-
// refUID: {
|
|
350
|
-
// in: versionUids,
|
|
351
|
-
// },
|
|
352
|
-
// decodedDataJson: {
|
|
353
|
-
// contains: 'storage_transaction_id',
|
|
354
|
-
// },
|
|
355
|
-
// },
|
|
356
|
-
// })
|
|
357
|
-
//
|
|
358
|
-
// console.log(
|
|
359
|
-
// '[property/actors] [resolveRelatedValue] itemProperties',
|
|
360
|
-
// itemProperties,
|
|
361
|
-
// )
|
|
362
|
-
//
|
|
363
|
-
// if (itemProperties && itemProperties.length > 0) {
|
|
364
|
-
// await savePropertiesToDb(itemProperties)
|
|
365
|
-
// }
|
|
366
|
-
// }
|
|
367
|
-
// }
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import { FromCallbackInput } from '@/types/machines'
|
|
3
|
-
import { PropertyMachineContext } from '@/types/property'
|
|
4
|
-
import fs from '@zenfs/core'
|
|
5
|
-
|
|
6
|
-
export const resolveRemoteStorage = fromCallback<
|
|
7
|
-
EventObject,
|
|
8
|
-
FromCallbackInput<PropertyMachineContext, EventObject>
|
|
9
|
-
>(({ sendBack, input: { context } }) => {
|
|
10
|
-
const { propertyInstances } = context
|
|
11
|
-
|
|
12
|
-
if (!propertyInstances) {
|
|
13
|
-
throw new Error(`propertyInstances not found for ${context.seedLocalId}`)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (!propertyInstances.has('storageTransactionId')) {
|
|
17
|
-
return
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const storageTransactionId = propertyInstances.get('storageTransactionId')
|
|
21
|
-
|
|
22
|
-
const _resolveRemoteStorage = async (): Promise<void> => {
|
|
23
|
-
const path = await import('path-browserify')
|
|
24
|
-
|
|
25
|
-
const filesDirExists = await fs.promises.exists('/files')
|
|
26
|
-
|
|
27
|
-
if (!filesDirExists) {
|
|
28
|
-
await fs.promises.mkdir('/files')
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const htmlDir = path.join('/files', 'html')
|
|
32
|
-
|
|
33
|
-
const htmlExists = await fs.promises.exists(htmlDir)
|
|
34
|
-
|
|
35
|
-
if (htmlExists) {
|
|
36
|
-
const htmlFiles = await fs.promises.readdir(htmlDir)
|
|
37
|
-
const matchingHtmlFile = htmlFiles.find(
|
|
38
|
-
(file) => file === `${storageTransactionId}.html`,
|
|
39
|
-
)
|
|
40
|
-
if (matchingHtmlFile) {
|
|
41
|
-
const htmlString = await fs.promises.readFile(
|
|
42
|
-
path.join(htmlDir, matchingHtmlFile),
|
|
43
|
-
'utf8',
|
|
44
|
-
)
|
|
45
|
-
sendBack({
|
|
46
|
-
type: 'updateValue',
|
|
47
|
-
propertyName: 'html',
|
|
48
|
-
propertyValue: htmlString,
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (!htmlExists) {
|
|
54
|
-
await fs.promises.mkdir(htmlDir)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const jsonDir = path.join('/files', 'json')
|
|
58
|
-
|
|
59
|
-
const jsonExists = await fs.promises.exists(jsonDir)
|
|
60
|
-
|
|
61
|
-
if (jsonExists) {
|
|
62
|
-
const jsonFiles = await fs.promises.readdir(jsonDir)
|
|
63
|
-
const matchingJsonFile = jsonFiles.find(
|
|
64
|
-
(file) => file === `${storageTransactionId}.json`,
|
|
65
|
-
)
|
|
66
|
-
if (matchingJsonFile) {
|
|
67
|
-
const jsonString = await fs.promises.readFile(
|
|
68
|
-
path.join(jsonDir, matchingJsonFile),
|
|
69
|
-
'utf8',
|
|
70
|
-
)
|
|
71
|
-
sendBack({
|
|
72
|
-
type: 'updateValue',
|
|
73
|
-
propertyName: 'json',
|
|
74
|
-
propertyValue: jsonString,
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (!jsonExists) {
|
|
80
|
-
await fs.promises.mkdir(jsonDir)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
_resolveRemoteStorage().then(() => {
|
|
85
|
-
sendBack({ type: 'resolveRemoteStorageSuccess' })
|
|
86
|
-
return
|
|
87
|
-
})
|
|
88
|
-
})
|
package/dist/src/saveAppState.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { BaseDb } from '@/db/Db/BaseDb'
|
|
2
|
-
import { appState } from '@/seedSchema'
|
|
3
|
-
|
|
4
|
-
export const saveAppState = async (key: string, value: string) => {
|
|
5
|
-
const appDb = BaseDb.getAppDb()
|
|
6
|
-
|
|
7
|
-
await appDb
|
|
8
|
-
.insert(appState)
|
|
9
|
-
.values({
|
|
10
|
-
key,
|
|
11
|
-
value,
|
|
12
|
-
})
|
|
13
|
-
.onConflictDoUpdate({
|
|
14
|
-
target: appState.key,
|
|
15
|
-
set: {
|
|
16
|
-
value,
|
|
17
|
-
},
|
|
18
|
-
})
|
|
19
|
-
}
|
package/dist/src/saveConfig.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import { INTERNAL_SAVING_CONFIG_SUCCESS } from '@/services/internal/constants'
|
|
3
|
-
import { BaseDb } from '@/db/Db/BaseDb'
|
|
4
|
-
import debug from 'debug'
|
|
5
|
-
import { FromCallbackInput, InternalMachineContext } from '@/types'
|
|
6
|
-
import { appState } from '@/seedSchema'
|
|
7
|
-
|
|
8
|
-
const logger = debug('app:services:internal:actors:saveConfig')
|
|
9
|
-
|
|
10
|
-
export const saveConfig = fromCallback<
|
|
11
|
-
EventObject,
|
|
12
|
-
FromCallbackInput<InternalMachineContext>
|
|
13
|
-
>(({ sendBack, input: { context } }) => {
|
|
14
|
-
if (typeof window === 'undefined') {
|
|
15
|
-
console.error('seedInitBrowser called from non-browser context')
|
|
16
|
-
sendBack({
|
|
17
|
-
type: 'error',
|
|
18
|
-
error: 'Browser method called from non-browser context',
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const { endpoints, addresses, arweaveDomain } = context
|
|
23
|
-
|
|
24
|
-
if (!endpoints) {
|
|
25
|
-
throw new Error('saveConfig called with invalid endpoints')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const _saveConfig = async (): Promise<void> => {
|
|
29
|
-
// logger('[sdk] [internal/actors] starting _saveConfig')
|
|
30
|
-
const appDb = BaseDb.getAppDb()
|
|
31
|
-
if (!appDb) {
|
|
32
|
-
throw new Error('App DB not found')
|
|
33
|
-
}
|
|
34
|
-
const endpointsValueString = JSON.stringify(endpoints)
|
|
35
|
-
const addressesValueString = JSON.stringify(addresses)
|
|
36
|
-
// TODO: Figure out how to define on conflict with multiple rows added
|
|
37
|
-
try {
|
|
38
|
-
// logger('[sdk] [internal/actors] Saving endpoints to db')
|
|
39
|
-
await appDb
|
|
40
|
-
.insert(appState)
|
|
41
|
-
.values({
|
|
42
|
-
key: 'endpoints',
|
|
43
|
-
value: endpointsValueString,
|
|
44
|
-
})
|
|
45
|
-
.onConflictDoUpdate({
|
|
46
|
-
target: appState.key,
|
|
47
|
-
set: {
|
|
48
|
-
value: endpointsValueString,
|
|
49
|
-
},
|
|
50
|
-
})
|
|
51
|
-
// logger('[sdk] [internal/actors] Saving addresses to db')
|
|
52
|
-
await appDb
|
|
53
|
-
.insert(appState)
|
|
54
|
-
.values({
|
|
55
|
-
key: 'addresses',
|
|
56
|
-
value: addressesValueString,
|
|
57
|
-
})
|
|
58
|
-
.onConflictDoUpdate({
|
|
59
|
-
target: appState.key,
|
|
60
|
-
set: {
|
|
61
|
-
value: addressesValueString,
|
|
62
|
-
},
|
|
63
|
-
})
|
|
64
|
-
await appDb
|
|
65
|
-
.insert(appState)
|
|
66
|
-
.values({
|
|
67
|
-
key: 'arweaveDomain',
|
|
68
|
-
value: arweaveDomain || 'arweave.net',
|
|
69
|
-
})
|
|
70
|
-
.onConflictDoUpdate({
|
|
71
|
-
target: appState.key,
|
|
72
|
-
set: {
|
|
73
|
-
value: arweaveDomain || 'arweave.net',
|
|
74
|
-
},
|
|
75
|
-
})
|
|
76
|
-
logger('[sdk] [internal/actors] Should be done saving')
|
|
77
|
-
} catch (error) {
|
|
78
|
-
console.error('Error saving config:', error)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
_saveConfig().then(() => {
|
|
83
|
-
logger('[sdk] [internal/actors] Successfully saved config')
|
|
84
|
-
return sendBack({ type: INTERNAL_SAVING_CONFIG_SUCCESS })
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
return () => { }
|
|
88
|
-
})
|
package/dist/src/saveDataToDb.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import { itemMachineSingle } from '@/Item/service/itemMachineSingle'
|
|
3
|
-
import { sql } from 'drizzle-orm'
|
|
4
|
-
import { escapeSqliteString } from '@/helpers/db'
|
|
5
|
-
import { generateId } from '@/helpers'
|
|
6
|
-
import { BaseDb } from '@/db/Db/BaseDb'
|
|
7
|
-
|
|
8
|
-
const relatedSnakeCaseToCamelCase = (snakeCase: string): string => {
|
|
9
|
-
let camelCasePropertyName = snakeCase
|
|
10
|
-
|
|
11
|
-
camelCasePropertyName = camelCasePropertyName.replace(/_(id|ids)$/, '')
|
|
12
|
-
|
|
13
|
-
return camelCasePropertyName
|
|
14
|
-
.toLowerCase()
|
|
15
|
-
.replace(/[-_][a-z]/g, (group) => group.slice(-1).toUpperCase())
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const saveDataToDb = fromCallback<EventObject, typeof itemMachineSingle>(
|
|
19
|
-
({ sendBack, input: { context } }) => {
|
|
20
|
-
const {
|
|
21
|
-
modelName,
|
|
22
|
-
modelTableName,
|
|
23
|
-
versionUid,
|
|
24
|
-
versionLocalId,
|
|
25
|
-
seedLocalId,
|
|
26
|
-
propertiesBySchemaUid,
|
|
27
|
-
} = context
|
|
28
|
-
|
|
29
|
-
const _saveDataToDb = async (): Promise<void> => {
|
|
30
|
-
const appDb = BaseDb.getAppDb()
|
|
31
|
-
|
|
32
|
-
// Write fetched data from EAS to the database
|
|
33
|
-
await appDb.run(
|
|
34
|
-
sql.raw(
|
|
35
|
-
`INSERT INTO ${modelTableName} (version_local_id, seed_local_id, version_uid, created_at)
|
|
36
|
-
VALUES ('${versionLocalId}', '${seedLocalId}', '${versionUid}', ${new Date().getTime()});`,
|
|
37
|
-
),
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
const existingItemQuery = await appDb.run(
|
|
41
|
-
sql.raw(
|
|
42
|
-
`SELECT id, version_local_id, version_uid, seed_local_id, created_at
|
|
43
|
-
FROM ${modelTableName}
|
|
44
|
-
WHERE version_local_id = '${versionLocalId}';`,
|
|
45
|
-
),
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
let itemDbId
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
existingItemQuery &&
|
|
52
|
-
existingItemQuery.rows &&
|
|
53
|
-
existingItemQuery.rows.length > 0
|
|
54
|
-
) {
|
|
55
|
-
itemDbId = existingItemQuery.rows[0][0]
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (typeof itemDbId === 'undefined') {
|
|
59
|
-
console.error(
|
|
60
|
-
'[singleItemActors] [saveDataToDb] itemDbId not found in rows: ',
|
|
61
|
-
existingItemQuery.rows,
|
|
62
|
-
)
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
for (const [schemaUid, properties] of Object.entries(
|
|
67
|
-
propertiesBySchemaUid,
|
|
68
|
-
)) {
|
|
69
|
-
for (const property of properties) {
|
|
70
|
-
const json = JSON.parse(property.decodedDataJson)
|
|
71
|
-
const attestationValue = json[0].value
|
|
72
|
-
let propertyValue = attestationValue.value
|
|
73
|
-
|
|
74
|
-
if (typeof propertyValue === 'string') {
|
|
75
|
-
propertyValue = escapeSqliteString(propertyValue)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const camelCasePropertyName = relatedSnakeCaseToCamelCase(
|
|
79
|
-
attestationValue.name,
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
let attestationCreatedAt = property.timeCreated * 1000
|
|
83
|
-
|
|
84
|
-
await appDb.run(
|
|
85
|
-
sql.raw(
|
|
86
|
-
`INSERT INTO metadata (uid,
|
|
87
|
-
local_id,
|
|
88
|
-
property_name,
|
|
89
|
-
property_value,
|
|
90
|
-
model_type,
|
|
91
|
-
schema_uid,
|
|
92
|
-
version_uid,
|
|
93
|
-
eas_data_type,
|
|
94
|
-
created_at,
|
|
95
|
-
attestation_created_at)
|
|
96
|
-
VALUES ('${property.id}', '${generateId()}', '${attestationValue.name}', '${propertyValue}',
|
|
97
|
-
'${modelTableName}', '${schemaUid}',
|
|
98
|
-
'${versionUid}',
|
|
99
|
-
'${attestationValue.type}',
|
|
100
|
-
${new Date().getTime()}, ${attestationCreatedAt}, ${itemDbId})
|
|
101
|
-
ON CONFLICT DO NOTHING;`,
|
|
102
|
-
),
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
// sendBack({
|
|
106
|
-
// type: 'updateValue',
|
|
107
|
-
// propertyName: camelCasePropertyName,
|
|
108
|
-
// propertyValue,
|
|
109
|
-
// source: 'eas',
|
|
110
|
-
// })
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
// const propertiesQuery = (await appDb.run(
|
|
114
|
-
// sql.raw(
|
|
115
|
-
// `SELECT property_name, property_value, schema_uid
|
|
116
|
-
// FROM metadata
|
|
117
|
-
// WHERE version_uid = '${versionUid}'
|
|
118
|
-
// ORDER BY created_at DESC;`,
|
|
119
|
-
// ),
|
|
120
|
-
// )) as { rows: Array<[string, string]> }
|
|
121
|
-
|
|
122
|
-
// propertiesQuery.rows?.forEach((row) => {
|
|
123
|
-
// const propertyName = relatedSnakeCaseToCamelCase(row[0] as string)
|
|
124
|
-
// let propertyValue = row[1] as string
|
|
125
|
-
// const schemaUid = row[2] as string
|
|
126
|
-
// if (isJSONString(propertyValue)) {
|
|
127
|
-
// propertyValue = JSON.parse(propertyValue)
|
|
128
|
-
// }
|
|
129
|
-
// sendBack({
|
|
130
|
-
// type: 'updateValue',
|
|
131
|
-
// propertyName,
|
|
132
|
-
// propertyValue,
|
|
133
|
-
// schemaUid,
|
|
134
|
-
// source: 'db',
|
|
135
|
-
// })
|
|
136
|
-
// })
|
|
137
|
-
|
|
138
|
-
return
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
_saveDataToDb().then(() => {
|
|
142
|
-
sendBack({ type: 'saveDataToDbSuccess' })
|
|
143
|
-
})
|
|
144
|
-
},
|
|
145
|
-
)
|