@seedprotocol/sdk 0.2.50 → 0.2.52
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-Dcqcpsq4.js → ArweaveClient-D5iJisYr.js} +2 -2
- package/dist/{ArweaveClient-Dcqcpsq4.js.map → ArweaveClient-D5iJisYr.js.map} +1 -1
- package/dist/{ArweaveClient-Dh7LRIqD.js → ArweaveClient-HEIIuOfB.js} +2 -2
- package/dist/{ArweaveClient-Dh7LRIqD.js.map → ArweaveClient-HEIIuOfB.js.map} +1 -1
- package/dist/{Db-jJH2s0gO.js → Db-D-BsZYlN.js} +3 -3
- package/dist/{Db-jJH2s0gO.js.map → Db-D-BsZYlN.js.map} +1 -1
- package/dist/{Db-BwkMqaQe.js → Db-Dpsbk_T7.js} +3 -3
- package/dist/{Db-BwkMqaQe.js.map → Db-Dpsbk_T7.js.map} +1 -1
- package/dist/{EasClient-A1xC7Gm-.js → EasClient-D3wKgt0o.js} +2 -2
- package/dist/{EasClient-m2mXad59.js.map → EasClient-D3wKgt0o.js.map} +1 -1
- package/dist/{EasClient-m2mXad59.js → EasClient-jqkT2ZBt.js} +2 -2
- package/dist/{EasClient-A1xC7Gm-.js.map → EasClient-jqkT2ZBt.js.map} +1 -1
- package/dist/{FileManager-Dv2zn1RW.js → FileManager-4mWYO3Mt.js} +3 -5
- package/dist/FileManager-4mWYO3Mt.js.map +1 -0
- package/dist/{Item-DI3FxVPV.js → Item-CqWdJsyg.js} +3 -3
- package/dist/{Item-DI3FxVPV.js.map → Item-CqWdJsyg.js.map} +1 -1
- package/dist/{ItemProperty-CxNUwVnR.js → ItemProperty-BpBW3IWx.js} +3 -3
- package/dist/{ItemProperty-CxNUwVnR.js.map → ItemProperty-BpBW3IWx.js.map} +1 -1
- package/dist/{QueryClient-C-hFMF2j.js → QueryClient-CBOP3OoU.js} +2 -2
- package/dist/{QueryClient-C-hFMF2j.js.map → QueryClient-CBOP3OoU.js.map} +1 -1
- package/dist/{QueryClient-C02sPZ-K.js → QueryClient-bKb3SB0W.js} +2 -2
- package/dist/{QueryClient-C02sPZ-K.js.map → QueryClient-bKb3SB0W.js.map} +1 -1
- package/dist/bin.js +5 -5
- package/dist/{constants-C03RQQht.js → constants-CIDbABDz.js} +5 -2
- package/dist/constants-CIDbABDz.js.map +1 -0
- package/dist/{index-CKrLHw3B.js → index-BRxO1tLl.js} +300 -149
- package/dist/index-BRxO1tLl.js.map +1 -0
- package/dist/{index-Dv8GeuSw.js → index-d8Qsot6w.js} +3 -3
- package/dist/index-d8Qsot6w.js.map +1 -0
- package/dist/main.js +2 -2
- package/dist/package.json +189 -0
- package/dist/{seed.schema.config-1s-iWHq_.js → seed.schema.config-CPRn6KVL.js} +3 -3
- package/dist/{seed.schema.config-1s-iWHq_.js.map → seed.schema.config-CPRn6KVL.js.map} +1 -1
- package/dist/types/src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
- package/dist/types/src/browser/helpers/FileManager.d.ts +1 -0
- package/dist/types/src/browser/helpers/FileManager.d.ts.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/helpers/FileManager/BaseFileManager.d.ts +1 -0
- package/dist/types/src/helpers/FileManager/BaseFileManager.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/FileManager-Dv2zn1RW.js.map +0 -1
- package/dist/constants-C03RQQht.js.map +0 -1
- package/dist/index-CKrLHw3B.js.map +0 -1
- package/dist/index-Dv8GeuSw.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 -52
- 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 -155
- 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,184 +0,0 @@
|
|
|
1
|
-
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import {
|
|
3
|
-
GET_ALL_PROPERTIES_FOR_ALL_VERSIONS,
|
|
4
|
-
GET_SEED_IDS,
|
|
5
|
-
GET_VERSIONS,
|
|
6
|
-
} from '@/Item/queries'
|
|
7
|
-
import {
|
|
8
|
-
models as modelsTable,
|
|
9
|
-
modelUids,
|
|
10
|
-
PropertyType,
|
|
11
|
-
} from '@/seedSchema'
|
|
12
|
-
import { Attestation } from '@/graphql/gql/graphql'
|
|
13
|
-
import {
|
|
14
|
-
AllItemsMachineContext,
|
|
15
|
-
FromCallbackInput,
|
|
16
|
-
ModelClassType,
|
|
17
|
-
} from '@/types'
|
|
18
|
-
import { getAddressesFromDb } from '@/helpers/db'
|
|
19
|
-
import { eq } from 'drizzle-orm'
|
|
20
|
-
import { BaseDb } from '@/db/Db/BaseDb'
|
|
21
|
-
import { BaseEasClient } from '@/helpers/EasClient/BaseEasClient'
|
|
22
|
-
import { BaseQueryClient } from '@/helpers/QueryClient/BaseQueryClient'
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export const fetchRelatedItems = fromCallback<
|
|
26
|
-
EventObject,
|
|
27
|
-
FromCallbackInput<AllItemsMachineContext>
|
|
28
|
-
>(({ sendBack, input: { context } }) => {
|
|
29
|
-
const { ModelClass, modelName } = context
|
|
30
|
-
|
|
31
|
-
const appDb = BaseDb.getAppDb()
|
|
32
|
-
|
|
33
|
-
const relatedProperties = new Map<string, PropertyType>()
|
|
34
|
-
const relatedVersionsBySeedUid = new Map<string, Attestation[]>()
|
|
35
|
-
const schemaUidsByModelName = new Map<string, string>()
|
|
36
|
-
const mostRecentVersionsBySeedUid = new Map<string, Attestation>()
|
|
37
|
-
const mostRecentPropertiesBySeedUid = new Map<string, Attestation[]>()
|
|
38
|
-
const seedUidsByMostRecentVersionUid = new Map<string, string>()
|
|
39
|
-
|
|
40
|
-
const _fetchRelatedItems = async () => {
|
|
41
|
-
// Get related properties
|
|
42
|
-
for (const [propertyName, propertyDef] of Object.entries(
|
|
43
|
-
(ModelClass as ModelClassType).schema,
|
|
44
|
-
)) {
|
|
45
|
-
if (propertyDef && propertyDef.ref && propertyDef.refModelId) {
|
|
46
|
-
relatedProperties.set(propertyName, propertyDef)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const addresses = await getAddressesFromDb(appDb)
|
|
51
|
-
|
|
52
|
-
// Get the models they point to from sdkConfigDb
|
|
53
|
-
for (const [propertyName, propertyDef] of relatedProperties.entries()) {
|
|
54
|
-
const relatedModelQuery = await appDb
|
|
55
|
-
.select({
|
|
56
|
-
id: modelsTable.id,
|
|
57
|
-
name: modelsTable.name,
|
|
58
|
-
uid: modelUids.uid,
|
|
59
|
-
})
|
|
60
|
-
.from(modelsTable)
|
|
61
|
-
.leftJoin(modelUids, eq(modelsTable.id, modelUids.modelId))
|
|
62
|
-
.where(eq(modelsTable.id, propertyDef.refModelId))
|
|
63
|
-
.limit(1)
|
|
64
|
-
|
|
65
|
-
if (relatedModelQuery && relatedModelQuery.length > 0) {
|
|
66
|
-
const relatedModel = relatedModelQuery[0]
|
|
67
|
-
const relatedModelUid = relatedModel.uid
|
|
68
|
-
// Exclude the current model's schemaUid since we already have its versions
|
|
69
|
-
if (relatedModelUid && relatedModelUid !== ModelClass.schemaUid) {
|
|
70
|
-
schemaUidsByModelName.set(relatedModel.name, relatedModelUid)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const queryKey = [`getRelatedSeedIds${modelName}`]
|
|
76
|
-
|
|
77
|
-
const queryClient = BaseQueryClient.getQueryClient()
|
|
78
|
-
const easClient = BaseEasClient.getEasClient()
|
|
79
|
-
|
|
80
|
-
const { itemSeedIds: relatedSeedIdAttestations } =
|
|
81
|
-
await queryClient.fetchQuery({
|
|
82
|
-
queryKey,
|
|
83
|
-
queryFn: async () =>
|
|
84
|
-
easClient.request(GET_SEED_IDS, {
|
|
85
|
-
where: {
|
|
86
|
-
schema: {
|
|
87
|
-
is: {
|
|
88
|
-
id: {
|
|
89
|
-
in: Array.from(schemaUidsByModelName.values()),
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
attester: {
|
|
94
|
-
in: addresses,
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
}),
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
const relatedSeedIds = relatedSeedIdAttestations.map((seed) => seed.id)
|
|
101
|
-
|
|
102
|
-
const { itemVersions: relatedVersions } = await queryClient.fetchQuery({
|
|
103
|
-
queryKey: [`getRelatedVersions${modelName}`],
|
|
104
|
-
queryFn: async () =>
|
|
105
|
-
easClient.request(GET_VERSIONS, {
|
|
106
|
-
where: {
|
|
107
|
-
refUID: {
|
|
108
|
-
in: relatedSeedIds,
|
|
109
|
-
},
|
|
110
|
-
attester: {
|
|
111
|
-
in: addresses,
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
}),
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
// Index versions by seedUid
|
|
118
|
-
for (const version of relatedVersions) {
|
|
119
|
-
const existingVersionsForSeedUid =
|
|
120
|
-
relatedVersionsBySeedUid.get(version.refUID) || []
|
|
121
|
-
existingVersionsForSeedUid.push(version)
|
|
122
|
-
relatedVersionsBySeedUid.set(version.refUID, existingVersionsForSeedUid)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Sort the indexed versions by timeCreated and index the most recent
|
|
126
|
-
for (const [
|
|
127
|
-
seedUid,
|
|
128
|
-
versionsForSeed,
|
|
129
|
-
] of relatedVersionsBySeedUid.entries()) {
|
|
130
|
-
const versionsForSeedSorted = versionsForSeed.sort(
|
|
131
|
-
(a: Attestation, b: Attestation) => {
|
|
132
|
-
return a.timeCreated - b.timeCreated
|
|
133
|
-
},
|
|
134
|
-
)
|
|
135
|
-
relatedVersionsBySeedUid.set(seedUid, versionsForSeedSorted)
|
|
136
|
-
mostRecentVersionsBySeedUid.set(seedUid, versionsForSeedSorted[0])
|
|
137
|
-
seedUidsByMostRecentVersionUid.set(versionsForSeedSorted[0].id, seedUid)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Extract the ids of the most recent versions
|
|
141
|
-
const mostRecentVersionIds = Array.from(
|
|
142
|
-
mostRecentVersionsBySeedUid.values(),
|
|
143
|
-
).map((version) => version.id)
|
|
144
|
-
|
|
145
|
-
const { allProperties } = await queryClient.fetchQuery({
|
|
146
|
-
queryKey: [`getAllProperties${modelName}`],
|
|
147
|
-
queryFn: async () =>
|
|
148
|
-
easClient.request(GET_ALL_PROPERTIES_FOR_ALL_VERSIONS, {
|
|
149
|
-
where: {
|
|
150
|
-
refUID: {
|
|
151
|
-
in: mostRecentVersionIds,
|
|
152
|
-
},
|
|
153
|
-
attester: {
|
|
154
|
-
in: addresses,
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
}),
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
for (const propertyAttestation of allProperties) {
|
|
161
|
-
const seedUidForProperty = seedUidsByMostRecentVersionUid.get(
|
|
162
|
-
propertyAttestation.refUID,
|
|
163
|
-
)
|
|
164
|
-
const existingPropertiesForSeedUid =
|
|
165
|
-
mostRecentPropertiesBySeedUid.get(seedUidForProperty!) || []
|
|
166
|
-
existingPropertiesForSeedUid.push(propertyAttestation)
|
|
167
|
-
mostRecentPropertiesBySeedUid.set(
|
|
168
|
-
seedUidForProperty!,
|
|
169
|
-
existingPropertiesForSeedUid,
|
|
170
|
-
)
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
_fetchRelatedItems().then(() => {
|
|
175
|
-
sendBack({
|
|
176
|
-
type: 'fetchRelatedItemsSuccess',
|
|
177
|
-
mostRecentPropertiesBySeedUid,
|
|
178
|
-
relatedVersionsBySeedUid,
|
|
179
|
-
relatedProperties,
|
|
180
|
-
schemaUidsByModelName,
|
|
181
|
-
})
|
|
182
|
-
return
|
|
183
|
-
})
|
|
184
|
-
})
|
package/dist/src/fetchSeeds.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import { GET_SEEDS } from '@/Item/queries'
|
|
3
|
-
import { AllItemsMachineContext, FromCallbackInput } from '@/types'
|
|
4
|
-
import { Attestation } from '@/graphql/gql/graphql'
|
|
5
|
-
import { BaseEasClient } from '@/helpers/EasClient/BaseEasClient'
|
|
6
|
-
import { BaseQueryClient } from '@/helpers/QueryClient/BaseQueryClient'
|
|
7
|
-
import debug from 'debug'
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const logger = debug('app:allItemsActors:fetchSeeds')
|
|
11
|
-
|
|
12
|
-
export const fetchSeeds = fromCallback<
|
|
13
|
-
EventObject,
|
|
14
|
-
FromCallbackInput<AllItemsMachineContext>
|
|
15
|
-
>(
|
|
16
|
-
({ sendBack, input: { context } }) => {
|
|
17
|
-
const { queryVariables, modelName } = context
|
|
18
|
-
|
|
19
|
-
if (!queryVariables) {
|
|
20
|
-
throw new Error('No queryVariables found')
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let itemSeeds: Attestation[] | undefined
|
|
24
|
-
|
|
25
|
-
const _fetchSeeds = async () => {
|
|
26
|
-
const queryKey = [`getSeeds${modelName}`]
|
|
27
|
-
|
|
28
|
-
const queryClient = BaseQueryClient.getQueryClient()
|
|
29
|
-
const easClient = BaseEasClient.getEasClient()
|
|
30
|
-
|
|
31
|
-
const cachedResults = queryClient.getQueryData(queryKey)
|
|
32
|
-
|
|
33
|
-
logger(
|
|
34
|
-
`[allItemsActors] [fetchSeeds] cachedResults ${Date.now()}`,
|
|
35
|
-
cachedResults,
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
const results = await queryClient.fetchQuery({
|
|
39
|
-
queryKey,
|
|
40
|
-
queryFn: async () => easClient.request(GET_SEEDS, queryVariables),
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
itemSeeds = results.itemSeeds
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
_fetchSeeds().then(() => {
|
|
47
|
-
sendBack({ type: 'fetchSeedsSuccess', itemSeeds })
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
return () => { }
|
|
51
|
-
},
|
|
52
|
-
)
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import { GET_VERSIONS } from '@/Item/queries'
|
|
3
|
-
import { AllItemsMachineContext, FromCallbackInput } from '@/types'
|
|
4
|
-
import { Attestation } from '@/graphql/gql/graphql'
|
|
5
|
-
import { BaseEasClient } from '@/helpers/EasClient/BaseEasClient'
|
|
6
|
-
import { BaseQueryClient } from '@/helpers/QueryClient/BaseQueryClient'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export const fetchVersions = fromCallback<
|
|
10
|
-
EventObject,
|
|
11
|
-
FromCallbackInput<AllItemsMachineContext>
|
|
12
|
-
>(
|
|
13
|
-
({ sendBack, input: { context } }) => {
|
|
14
|
-
const { itemSeeds, modelName } = context
|
|
15
|
-
|
|
16
|
-
if (!itemSeeds) {
|
|
17
|
-
throw new Error('No queryVariables found')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
let itemVersions: Attestation[] | undefined
|
|
21
|
-
|
|
22
|
-
const _fetchVersions = async () => {
|
|
23
|
-
const queryClient = BaseQueryClient.getQueryClient()
|
|
24
|
-
const easClient = BaseEasClient.getEasClient()
|
|
25
|
-
|
|
26
|
-
const seedIds = itemSeeds.map((seed) => seed.id)
|
|
27
|
-
|
|
28
|
-
const results = await queryClient.fetchQuery({
|
|
29
|
-
queryKey: [`getVersions${modelName}`],
|
|
30
|
-
queryFn: async () =>
|
|
31
|
-
easClient.request(GET_VERSIONS, {
|
|
32
|
-
where: {
|
|
33
|
-
refUID: {
|
|
34
|
-
in: seedIds,
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
}),
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
itemVersions = results.itemVersions
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
_fetchVersions().then(() => {
|
|
44
|
-
sendBack({ type: 'fetchVersionsSuccess', itemVersions })
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
return () => { }
|
|
48
|
-
},
|
|
49
|
-
)
|
package/dist/src/files.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import fs from '@zenfs/core'
|
|
2
|
-
import * as fsNode from 'node:fs'
|
|
3
|
-
import debug from 'debug'
|
|
4
|
-
|
|
5
|
-
const logger = debug('app:helpers:files')
|
|
6
|
-
// import * as retry from 'async-es/retry'
|
|
7
|
-
|
|
8
|
-
export const listFilesInOPFSRoot = async () => {
|
|
9
|
-
// Get the root directory handle
|
|
10
|
-
const rootDirHandle = await navigator.storage.getDirectory()
|
|
11
|
-
|
|
12
|
-
// Initialize an array to hold the file names
|
|
13
|
-
let fileNames = []
|
|
14
|
-
|
|
15
|
-
// Create an async iterator to loop through directory entries
|
|
16
|
-
for await (const entry of rootDirHandle.values()) {
|
|
17
|
-
if (entry.kind === 'file') {
|
|
18
|
-
fileNames.push(entry.name)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return fileNames
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Waits for a file to exist at the specified path.
|
|
27
|
-
* @param {string} filePath - The path of the file to check.
|
|
28
|
-
* @param {number} interval - The interval in milliseconds between checks (default: 500ms).
|
|
29
|
-
* @param {number} timeout - The timeout in milliseconds to wait for the file to exist (default: 10s).
|
|
30
|
-
* @returns {Promise<boolean>} - Resolves to true if the file exists within the timeout period, otherwise false.
|
|
31
|
-
*/
|
|
32
|
-
export const waitForFile = (
|
|
33
|
-
filePath: string,
|
|
34
|
-
interval: number = 1000,
|
|
35
|
-
timeout: number = 60000,
|
|
36
|
-
): Promise<boolean> => {
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
const startTime = Date.now()
|
|
39
|
-
|
|
40
|
-
let isBusy = false
|
|
41
|
-
|
|
42
|
-
const _interval = setInterval(async () => {
|
|
43
|
-
logger('waitForFile', filePath)
|
|
44
|
-
if (isBusy) {
|
|
45
|
-
return
|
|
46
|
-
}
|
|
47
|
-
isBusy = true
|
|
48
|
-
if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {
|
|
49
|
-
clearInterval(_interval)
|
|
50
|
-
resolve(true)
|
|
51
|
-
}
|
|
52
|
-
if (Date.now() - startTime >= timeout) {
|
|
53
|
-
clearInterval(_interval)
|
|
54
|
-
reject(new Error('Timeout exceeded while waiting for file'))
|
|
55
|
-
}
|
|
56
|
-
isBusy = false
|
|
57
|
-
}, interval)
|
|
58
|
-
|
|
59
|
-
// retry(
|
|
60
|
-
// {
|
|
61
|
-
// times: Math.ceil(timeout / interval),
|
|
62
|
-
// interval: interval,
|
|
63
|
-
// },
|
|
64
|
-
// (callback: Function) => {
|
|
65
|
-
// if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {
|
|
66
|
-
// return callback(null, true) // File exists, finish with success
|
|
67
|
-
// }
|
|
68
|
-
// if (Date.now() - startTime >= timeout) {
|
|
69
|
-
// return callback(new Error('Timeout exceeded while waiting for file'))
|
|
70
|
-
// }
|
|
71
|
-
// callback(new Error('File does not exist yet')) // Retry with this error
|
|
72
|
-
// },
|
|
73
|
-
// (err: Error, result: boolean) => {
|
|
74
|
-
// if (err) {
|
|
75
|
-
// return resolve(false) // Resolve as false if timeout or error occurs
|
|
76
|
-
// }
|
|
77
|
-
// resolve(result) // Resolve as true if file exists
|
|
78
|
-
// },
|
|
79
|
-
// )
|
|
80
|
-
})
|
|
81
|
-
}
|
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export default `(
|
|
3
|
-
${
|
|
4
|
-
function () {
|
|
5
|
-
|
|
6
|
-
const identifyString = (str: string) => {
|
|
7
|
-
try {
|
|
8
|
-
JSON.parse(str)
|
|
9
|
-
return 'json'
|
|
10
|
-
} catch (e) {
|
|
11
|
-
// Not JSON
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (!str) {
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (str.trim().startsWith('<') && str.trim().endsWith('>')) {
|
|
19
|
-
return 'html'
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Simple markdown checks (very naive)
|
|
23
|
-
if (/^#{1,6}\s|^-{3,}|\*{3,}|^-{1,2}\s|\*\s/.test(str)) {
|
|
24
|
-
return 'markdown'
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (/^data:image\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/.test(str)) {
|
|
28
|
-
return 'base64'
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Default to plain text if unsure
|
|
32
|
-
return 'text'
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const getMimeType = (base64: string) => {
|
|
36
|
-
if (!base64) {
|
|
37
|
-
return null
|
|
38
|
-
}
|
|
39
|
-
const result = base64.match(/^data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,/)
|
|
40
|
-
|
|
41
|
-
if (result && result.length > 1) {
|
|
42
|
-
return result[1]
|
|
43
|
-
} else {
|
|
44
|
-
return null // MIME type could not be determined
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const getDataTypeFromString = (
|
|
49
|
-
data: string,
|
|
50
|
-
): 'imageBase64' | 'base64' | 'url' | null => {
|
|
51
|
-
const nonImageBase64Regex =
|
|
52
|
-
/^(?!data:image\/(?:jpeg|png|gif|bmp|webp);base64,)[A-Za-z0-9+/=]+$/
|
|
53
|
-
|
|
54
|
-
if (nonImageBase64Regex.test(data)) {
|
|
55
|
-
return 'base64'
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Regular expression for base64 (simple version, checking for base64 format)
|
|
59
|
-
const imageBase64Regex = /^data:image\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/
|
|
60
|
-
|
|
61
|
-
if (imageBase64Regex.test(data)) {
|
|
62
|
-
return 'imageBase64'
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Regular expression for URL (simple version, checking for common URL format)
|
|
66
|
-
const urlRegex =
|
|
67
|
-
/^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/
|
|
68
|
-
|
|
69
|
-
if (urlRegex.test(data)) {
|
|
70
|
-
return 'url'
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return null
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const isBinary = (arrayBuffer: ArrayBuffer): boolean => {
|
|
77
|
-
const view = new Uint8Array(arrayBuffer);
|
|
78
|
-
|
|
79
|
-
let nonTextCount = 0;
|
|
80
|
-
const threshold = 0.2; // Adjust as needed (e.g., 20% non-text implies binary)
|
|
81
|
-
|
|
82
|
-
for (let i = 0; i < view.length; i++) {
|
|
83
|
-
const byte = view[i];
|
|
84
|
-
|
|
85
|
-
// ASCII printable characters (32-126) and common whitespace (9, 10, 13)
|
|
86
|
-
if (
|
|
87
|
-
(byte >= 32 && byte <= 126) || // Printable ASCII
|
|
88
|
-
byte === 9 || byte === 10 || byte === 13 // Tab, LF, CR
|
|
89
|
-
) {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
nonTextCount++;
|
|
94
|
-
if (nonTextCount / view.length > threshold) {
|
|
95
|
-
return true; // More than threshold are non-text bytes
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return false; // Fewer than threshold are non-text bytes
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const saveBufferToOPFS = async (filePath: string, buffer: Uint8Array): Promise<void> => {
|
|
103
|
-
// Access the OPFS root directory
|
|
104
|
-
const rootHandle = await navigator.storage.getDirectory();
|
|
105
|
-
|
|
106
|
-
// Split the filePath into directory segments and file name
|
|
107
|
-
const segments = filePath.split('/').filter(Boolean);
|
|
108
|
-
const fileName = segments.pop(); // Extract the file name
|
|
109
|
-
if (!fileName) {
|
|
110
|
-
throw new Error('Invalid file path: No file name provided.');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Traverse or create directories as needed
|
|
114
|
-
let currentDirHandle = rootHandle;
|
|
115
|
-
for (const segment of segments) {
|
|
116
|
-
currentDirHandle = await currentDirHandle.getDirectoryHandle(segment, { create: true });
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Create or open the file in OPFS
|
|
120
|
-
const fileHandleAsync = await currentDirHandle.getFileHandle(fileName, { create: true });
|
|
121
|
-
const fileHandle = await fileHandleAsync.createSyncAccessHandle();
|
|
122
|
-
// Write the buffer to the file
|
|
123
|
-
fileHandle.write(buffer);
|
|
124
|
-
fileHandle.flush();
|
|
125
|
-
fileHandle.close();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const downloadFiles = async ({
|
|
129
|
-
transactionIds,
|
|
130
|
-
arweaveHost,
|
|
131
|
-
}: {
|
|
132
|
-
transactionIds: string[],
|
|
133
|
-
arweaveHost: string,
|
|
134
|
-
}) => {
|
|
135
|
-
|
|
136
|
-
let arrayBuffer: ArrayBuffer | undefined
|
|
137
|
-
|
|
138
|
-
for (const transactionId of transactionIds) {
|
|
139
|
-
try {
|
|
140
|
-
const response = await fetch(`https://${arweaveHost}/raw/${transactionId}`);
|
|
141
|
-
|
|
142
|
-
arrayBuffer = await response.arrayBuffer();
|
|
143
|
-
} catch(error) {
|
|
144
|
-
console.log(`[filesDownload] transaction ${transactionId} data not found`, error)
|
|
145
|
-
globalThis.postMessage({
|
|
146
|
-
message: 'excludeTransaction',
|
|
147
|
-
transactionId,
|
|
148
|
-
})
|
|
149
|
-
continue
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
let dataString
|
|
153
|
-
const isBinaryData = isBinary(arrayBuffer)
|
|
154
|
-
|
|
155
|
-
if (!isBinaryData) {
|
|
156
|
-
const decoder = new TextDecoder('utf-8')
|
|
157
|
-
const text = decoder.decode(arrayBuffer)
|
|
158
|
-
dataString = text
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (!dataString && !arrayBuffer) {
|
|
162
|
-
console.log(
|
|
163
|
-
`[filesDownload] transaction ${transactionId} data not found`,
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (dataString && dataString.startsWith('===FILE_SEPARATOR===')) {
|
|
168
|
-
const dataStringParts = dataString
|
|
169
|
-
.split('===FILE_SEPARATOR===')
|
|
170
|
-
.slice(1)
|
|
171
|
-
|
|
172
|
-
if (dataStringParts.length % 2 !== 0) {
|
|
173
|
-
throw new Error('Input array must have an even number of elements.')
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
for (let i = 0; i < dataStringParts.length; i += 2) {
|
|
177
|
-
const contentType = dataStringParts[i]
|
|
178
|
-
const content = dataStringParts[i + 1]
|
|
179
|
-
const encoder = new TextEncoder()
|
|
180
|
-
if (contentType === 'html') {
|
|
181
|
-
const fileName = `${transactionId}.html`
|
|
182
|
-
const buffer = encoder.encode(content)
|
|
183
|
-
saveBufferToOPFS(`/files/html/${fileName}`, buffer)
|
|
184
|
-
}
|
|
185
|
-
if (contentType === 'json') {
|
|
186
|
-
const fileName = `${transactionId}.json`
|
|
187
|
-
const buffer = encoder.encode(content)
|
|
188
|
-
saveBufferToOPFS(`/files/json/${fileName}`, buffer)
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
continue
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (!dataString && arrayBuffer) {
|
|
196
|
-
saveBufferToOPFS(
|
|
197
|
-
`/files/images/${transactionId}`,
|
|
198
|
-
new Uint8Array(arrayBuffer),
|
|
199
|
-
)
|
|
200
|
-
continue
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (!dataString) {
|
|
204
|
-
continue
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
let contentType = identifyString(dataString)
|
|
208
|
-
|
|
209
|
-
if (
|
|
210
|
-
contentType !== 'json' &&
|
|
211
|
-
contentType !== 'base64' &&
|
|
212
|
-
contentType !== 'html'
|
|
213
|
-
) {
|
|
214
|
-
const possibleImageType = getDataTypeFromString(dataString)
|
|
215
|
-
if (!possibleImageType) {
|
|
216
|
-
console.log(
|
|
217
|
-
`[filesDownload] transaction ${transactionId} data not in expected format: ${possibleImageType}`,
|
|
218
|
-
)
|
|
219
|
-
continue
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
contentType = possibleImageType
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (contentType === 'url') {
|
|
226
|
-
const url = dataString as string
|
|
227
|
-
|
|
228
|
-
let buffer: ArrayBuffer | undefined
|
|
229
|
-
|
|
230
|
-
try {
|
|
231
|
-
const response = await fetch(url)
|
|
232
|
-
|
|
233
|
-
buffer = await response.arrayBuffer()
|
|
234
|
-
|
|
235
|
-
} catch(error) {
|
|
236
|
-
console.log(`[filesDownload] transaction ${transactionId} value was url: ${dataString} but failed to fetch`, error)
|
|
237
|
-
globalThis.postMessage({
|
|
238
|
-
message: 'excludeTransaction',
|
|
239
|
-
transactionId,
|
|
240
|
-
})
|
|
241
|
-
continue
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
const bufferUint8Array = new Uint8Array(buffer)
|
|
245
|
-
|
|
246
|
-
// Extract the file extension from the URL
|
|
247
|
-
const extensionMatch = url.match(/\.(jpg|jpeg|png|gif|bmp|webp|svg)$/i)
|
|
248
|
-
if (!extensionMatch) {
|
|
249
|
-
throw new Error(
|
|
250
|
-
'Unable to determine the file extension from the URL.',
|
|
251
|
-
)
|
|
252
|
-
}
|
|
253
|
-
const fileExtension = extensionMatch[0] // e.g., ".jpg"
|
|
254
|
-
|
|
255
|
-
// Set the file name (you can customize this)
|
|
256
|
-
// const fileNameFromUrl = `${transactionId}${fileExtension}`
|
|
257
|
-
|
|
258
|
-
await saveBufferToOPFS(
|
|
259
|
-
`/files/images/${transactionId}`,
|
|
260
|
-
bufferUint8Array,
|
|
261
|
-
)
|
|
262
|
-
|
|
263
|
-
continue
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const mimeType = getMimeType(dataString as string)
|
|
267
|
-
let fileExtension = mimeType
|
|
268
|
-
|
|
269
|
-
if (fileExtension && fileExtension?.startsWith('image')) {
|
|
270
|
-
fileExtension = fileExtension.replace('image/', '')
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
let fileName = transactionId
|
|
274
|
-
|
|
275
|
-
if (contentType === 'base64') {
|
|
276
|
-
if (fileExtension) {
|
|
277
|
-
fileName += `.${fileExtension}`
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// Remove the Base64 header if it exists (e.g., "data:image/png;base64,")
|
|
281
|
-
const base64Data = dataString.split(',').pop() || ''
|
|
282
|
-
|
|
283
|
-
// Decode the Base64 string to binary
|
|
284
|
-
const binaryString = atob(base64Data)
|
|
285
|
-
const length = binaryString.length
|
|
286
|
-
const binaryData = new Uint8Array(length)
|
|
287
|
-
|
|
288
|
-
for (let i = 0; i < length; i++) {
|
|
289
|
-
binaryData[i] = binaryString.charCodeAt(i)
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
await saveBufferToOPFS(`/files/images/${fileName}`, binaryData)
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (contentType === 'html') {
|
|
297
|
-
fileName += '.html'
|
|
298
|
-
const encoder = new TextEncoder()
|
|
299
|
-
const buffer = encoder.encode(dataString)
|
|
300
|
-
await saveBufferToOPFS(`/files/html/${fileName}`, buffer)
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
if (contentType === 'json') {
|
|
304
|
-
fileName += '.json'
|
|
305
|
-
const encoder = new TextEncoder()
|
|
306
|
-
const buffer = encoder.encode(dataString)
|
|
307
|
-
await saveBufferToOPFS(`/files/json/${fileName}`, buffer)
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
onmessage = async (e) => {
|
|
313
|
-
console.log({
|
|
314
|
-
message: 'filesDownload onmessage',
|
|
315
|
-
data: e.data,
|
|
316
|
-
})
|
|
317
|
-
await downloadFiles(e.data);
|
|
318
|
-
globalThis.postMessage({
|
|
319
|
-
message: 'filesDownload onmessage done',
|
|
320
|
-
done: true,
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
}
|
|
324
|
-
}.toString()
|
|
325
|
-
}
|
|
326
|
-
)()`
|