@seedprotocol/sdk 0.3.0 → 0.3.1
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-CmJYeuq1.js → ArweaveClient-C0g0es2v.js} +2 -2
- package/dist/{ArweaveClient-EXXrXUzz.js.map → ArweaveClient-C0g0es2v.js.map} +1 -1
- package/dist/{ArweaveClient-EXXrXUzz.js → ArweaveClient-CzkBgiZY.js} +2 -2
- package/dist/{ArweaveClient-CmJYeuq1.js.map → ArweaveClient-CzkBgiZY.js.map} +1 -1
- package/dist/{Db-CESKJH-G.js → Db-C4oog-0n.js} +3 -3
- package/dist/{Db-CESKJH-G.js.map → Db-C4oog-0n.js.map} +1 -1
- package/dist/{Db-DiTPSbQ8.js → Db-VPouegkr.js} +3 -3
- package/dist/{Db-DiTPSbQ8.js.map → Db-VPouegkr.js.map} +1 -1
- package/dist/{EasClient-BesHK2bO.js → EasClient-B9a3NsTi.js} +2 -2
- package/dist/{EasClient-BesHK2bO.js.map → EasClient-B9a3NsTi.js.map} +1 -1
- package/dist/{EasClient-Cop6WtWl.js → EasClient-DQ93i2ci.js} +2 -2
- package/dist/{EasClient-Cop6WtWl.js.map → EasClient-DQ93i2ci.js.map} +1 -1
- package/dist/{FileManager-DTzkncLh.js → FileManager-_ErxVuwb.js} +8 -5
- package/dist/FileManager-_ErxVuwb.js.map +1 -0
- package/dist/{Item-B5Tz-Y7t.js → Item-D9HFPxsK.js} +3 -3
- package/dist/{Item-B5Tz-Y7t.js.map → Item-D9HFPxsK.js.map} +1 -1
- package/dist/{ItemProperty-DBV0Iib_.js → ItemProperty-BdtvKrEy.js} +3 -3
- package/dist/{ItemProperty-DBV0Iib_.js.map → ItemProperty-BdtvKrEy.js.map} +1 -1
- package/dist/{QueryClient-C7a0NHCt.js → QueryClient-Bmnv_moN.js} +2 -2
- package/dist/{QueryClient-C7a0NHCt.js.map → QueryClient-Bmnv_moN.js.map} +1 -1
- package/dist/{QueryClient-BnwbHtqe.js → QueryClient-hzOtFe99.js} +2 -2
- package/dist/{QueryClient-BnwbHtqe.js.map → QueryClient-hzOtFe99.js.map} +1 -1
- package/dist/bin.js +5 -5
- package/dist/bin.js.map +1 -1
- package/dist/{constants-CWg2B3Au.js → constants-Bhl5dZpN.js} +4 -1
- package/dist/constants-Bhl5dZpN.js.map +1 -0
- package/dist/{index-CQ9FS10O.js → index-BAtjd9W-.js} +3 -3
- package/dist/index-BAtjd9W-.js.map +1 -0
- package/dist/{index-BHGJ-Es9.js → index-BSR5hv7Q.js} +59 -27
- package/dist/index-BSR5hv7Q.js.map +1 -0
- package/dist/main.js +2 -2
- package/dist/{seed.schema.config-DDzfQguf.js → seed.schema.config-BxJYabim.js} +3 -3
- package/dist/{seed.schema.config-DDzfQguf.js.map → seed.schema.config-BxJYabim.js.map} +1 -1
- package/dist/src/AppStateSchema.ts +10 -0
- package/dist/src/ArweaveClient.ts +13 -0
- package/dist/src/Attestation.ts +21 -0
- package/dist/src/BaseArweaveClient.ts +13 -0
- package/dist/src/BaseClientManager.ts +35 -0
- package/dist/src/BaseDb.ts +35 -0
- package/dist/src/BaseEasClient.ts +14 -0
- package/dist/src/BaseFileManager.ts +60 -0
- package/dist/src/BaseItem.ts +413 -0
- package/dist/src/BaseItemProperty.ts +416 -0
- package/dist/src/BaseQueryClient.ts +13 -0
- package/dist/src/ClientManager.ts +63 -0
- package/dist/src/ConfigSchema.ts +15 -0
- package/dist/src/Db.ts +82 -0
- package/dist/src/EasClient.ts +13 -0
- package/dist/src/FileDownloader.ts +63 -0
- package/dist/src/FileManager.ts +59 -0
- package/dist/src/IDb.ts +7 -0
- package/dist/src/IEasClient.ts +2 -0
- package/dist/src/IItem.ts +26 -0
- package/dist/src/IItemProperty.ts +28 -0
- package/dist/src/IQueryClient.ts +11 -0
- package/dist/src/ImageResizer.ts +81 -0
- package/dist/src/Item.ts +12 -0
- package/dist/src/ItemProperty.ts +9 -0
- package/dist/src/MetadataSchema.ts +28 -0
- package/dist/src/ModelSchema.ts +46 -0
- package/dist/src/ModelUidSchema.ts +16 -0
- package/dist/src/PropertyUidSchema.ts +16 -0
- package/dist/src/QueryClient.ts +26 -0
- package/dist/src/Schema.ts +17 -0
- package/dist/src/SeedProtocolSdk.d.ts +19 -0
- package/dist/src/SeedSchema.ts +29 -0
- package/dist/src/VersionSchema.ts +16 -0
- package/dist/src/actors.ts +295 -0
- package/dist/src/addModelsToDb.ts +152 -0
- package/dist/src/allItems.ts +31 -0
- package/dist/src/analyzeInput.ts +144 -0
- package/dist/src/browser.app.db.config.ts +27 -0
- package/dist/src/browser.ts +30 -0
- package/dist/src/checkStatus.ts +57 -0
- package/dist/src/clientManagerMachine.ts +59 -0
- package/dist/src/configureFs.ts +98 -0
- package/dist/src/connectToDb.ts +41 -0
- package/dist/src/connectionManager.ts +67 -0
- package/dist/src/constants.ts +125 -0
- package/dist/src/content-hash.ts +30 -0
- package/dist/src/create.ts +39 -0
- package/dist/src/createMetadata.ts +77 -0
- package/dist/src/createNewItem.ts +61 -0
- package/dist/src/createPublishAttempt.ts +16 -0
- package/dist/src/createSeed.ts +31 -0
- package/dist/src/createSeeds.ts +24 -0
- package/dist/src/createVersion.ts +33 -0
- package/dist/src/dbMachine.ts +182 -0
- package/dist/src/deleteItem.ts +19 -0
- package/dist/src/download.ts +208 -0
- package/dist/src/drizzle.ts +78 -0
- package/dist/src/eas.ts +40 -0
- package/dist/src/environment.ts +35 -0
- package/dist/src/eventBus.ts +5 -0
- package/dist/src/events.ts +14 -0
- package/dist/src/fetchDataFromEas.ts +94 -0
- package/dist/src/fetchDbData.ts +19 -0
- package/dist/src/fetchRelatedItems.ts +184 -0
- package/dist/src/fetchSeeds.ts +45 -0
- package/dist/src/fetchVersions.ts +49 -0
- package/dist/src/files.ts +81 -0
- package/dist/src/filesDownload.ts +326 -0
- package/dist/src/fragment-masking.ts +87 -0
- package/dist/src/getExistingItem.ts +60 -0
- package/dist/src/getItem.ts +32 -0
- package/dist/src/getItemData.ts +99 -0
- package/dist/src/getItemProperties.ts +56 -0
- package/dist/src/getItemProperty.ts +34 -0
- package/dist/src/getItems.ts +70 -0
- package/dist/src/getMetadata.ts +40 -0
- package/dist/src/getModelSchemas.ts +89 -0
- package/dist/src/getPropertyData.ts +50 -0
- package/dist/src/getPublishPayload.ts +355 -0
- package/dist/src/getPublishUploads.ts +207 -0
- package/dist/src/getRelationValueData.ts +27 -0
- package/dist/src/getSchemaForItemProperty.ts +68 -0
- package/dist/src/getSchemaForModel.ts +42 -0
- package/dist/src/getSchemaUidForModel.ts +32 -0
- package/dist/src/getSeedData.ts +34 -0
- package/dist/src/getSegmentedItemProperties.ts +65 -0
- package/dist/src/getStorageTransactionIdForSeedUid.ts +38 -0
- package/dist/src/getVersionData.ts +46 -0
- package/dist/src/getVersionsForVersionUids.ts +39 -0
- package/dist/src/globalMachine.ts +280 -0
- package/dist/src/gql.ts +118 -0
- package/dist/src/graphql.ts +3209 -0
- package/dist/src/helpers.ts +273 -0
- package/dist/src/hydrateExistingItem.ts +137 -0
- package/dist/src/hydrateFromDb.ts +270 -0
- package/dist/src/hydrateNewItem.ts +34 -0
- package/dist/src/imageResize.ts +507 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.ts +4 -0
- package/dist/src/initialize.ts +124 -0
- package/dist/src/internalMachine.ts +241 -0
- package/dist/src/itemMachineAll.ts +157 -0
- package/dist/src/itemMachineSingle.ts +158 -0
- package/dist/src/loadAppDb.ts +44 -0
- package/dist/src/machines.ts +66 -0
- package/dist/src/metadataLatest.ts +34 -0
- package/dist/src/migrate.ts +57 -0
- package/dist/src/model.ts +72 -0
- package/dist/src/modelClass.ts +19 -0
- package/dist/src/node.app.db.config.ts +41 -0
- package/dist/src/prepareDb.ts +29 -0
- package/dist/src/preparePublishRequestData.ts +81 -0
- package/dist/src/processItems.ts +74 -0
- package/dist/src/property.ts +156 -0
- package/dist/src/propertyMachine.ts +202 -0
- package/dist/src/publish.ts +28 -0
- package/dist/src/publishMachine.ts +77 -0
- package/dist/src/queries.ts +13 -0
- package/dist/src/recoverDeletedItem.ts +14 -0
- package/dist/src/reload.ts +33 -0
- package/dist/src/request.ts +45 -0
- package/dist/src/requestAll.ts +157 -0
- package/dist/src/resolveRelatedValue.ts +367 -0
- package/dist/src/resolveRemoteStorage.ts +88 -0
- package/dist/src/saveAppState.ts +50 -0
- package/dist/src/saveConfig.ts +106 -0
- package/dist/src/saveDataToDb.ts +145 -0
- package/dist/src/saveImageSrc.ts +242 -0
- package/dist/src/saveItemStorage.ts +156 -0
- package/dist/src/saveMetadata.ts +18 -0
- package/dist/src/savePublishService.ts +30 -0
- package/dist/src/saveRelation.ts +112 -0
- package/dist/src/seed.schema.config.ts +25 -0
- package/dist/src/seed.ts +10 -0
- package/dist/src/seedProtocol.ts +17 -0
- package/dist/src/services.ts +365 -0
- package/dist/src/setAddresses.ts +16 -0
- package/dist/src/sqlWasmClient.ts +88 -0
- package/dist/src/syncDbWithEas.ts +628 -0
- package/dist/src/trash.ts +29 -0
- package/dist/src/ts-to-proto.ts +101 -0
- package/dist/src/types.ts +12 -0
- package/dist/src/updateItemPropertyValue.ts +243 -0
- package/dist/src/updateMachineContext.ts +21 -0
- package/dist/src/updateMetadata.ts +59 -0
- package/dist/src/upload.ts +86 -0
- package/dist/src/validate.ts +45 -0
- package/dist/src/validateInput.ts +43 -0
- package/dist/src/validateItemData.ts +20 -0
- package/dist/src/versionData.ts +24 -0
- package/dist/src/waitForDb.ts +25 -0
- package/dist/src/waitForFiles.ts +41 -0
- package/dist/src/wasm.d.ts +8300 -0
- package/dist/types/scripts/bin.d.ts.map +1 -1
- package/dist/types/src/browser/helpers/FileManager.d.ts +2 -1
- package/dist/types/src/browser/helpers/FileManager.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 +2 -1
- package/dist/types/src/node/helpers/FileManager.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/FileManager-DTzkncLh.js.map +0 -1
- package/dist/constants-CWg2B3Au.js.map +0 -1
- package/dist/index-BHGJ-Es9.js.map +0 -1
- package/dist/index-CQ9FS10O.js.map +0 -1
- package/dist/package.json +0 -189
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
+
import { GET_PROPERTIES } from '@/Item/queries'
|
|
3
|
+
import { itemMachineSingle } from '@/Item/service/itemMachineSingle'
|
|
4
|
+
import { PropertyType } from '@/seedSchema'
|
|
5
|
+
import { Attestation } from '@/graphql/gql/graphql'
|
|
6
|
+
import { ModelClassType } from '@/types'
|
|
7
|
+
import { BaseEasClient, BaseQueryClient } from '@/helpers'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export const fetchDataFromEas = fromCallback<
|
|
11
|
+
EventObject,
|
|
12
|
+
typeof itemMachineSingle
|
|
13
|
+
>(({ sendBack, input: { context } }) => {
|
|
14
|
+
const { ModelClass, modelTableName, versionUid } = context
|
|
15
|
+
|
|
16
|
+
const propertiesMetadata = new Map<string, PropertyType>()
|
|
17
|
+
|
|
18
|
+
// EAS is the final source of truth, so we need to see if our Item is
|
|
19
|
+
// already represented there. Then we need to intelligently sync/merge
|
|
20
|
+
// with whatever new data has been created on the device before the sync.
|
|
21
|
+
for (const [propertyName, propertyMetadata] of Object.entries(
|
|
22
|
+
(ModelClass as ModelClassType).schema,
|
|
23
|
+
)) {
|
|
24
|
+
if (propertyMetadata) {
|
|
25
|
+
propertiesMetadata.set(propertyName, propertyMetadata)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
sendBack({ type: 'updatePropertiesMetadata', propertiesMetadata })
|
|
30
|
+
|
|
31
|
+
if (!versionUid) {
|
|
32
|
+
// In this case this is a local only item, so we don't need to fetch anything
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const _fetchDataFromEas = async (): Promise<void> => {
|
|
37
|
+
const queryClient = BaseQueryClient.getQueryClient()
|
|
38
|
+
const easClient = BaseEasClient.getEasClient()
|
|
39
|
+
|
|
40
|
+
// Fetch Properties by versionUid
|
|
41
|
+
const { itemProperties } = await queryClient.fetchQuery({
|
|
42
|
+
queryKey: ['getProperties', versionUid],
|
|
43
|
+
queryFn: async () =>
|
|
44
|
+
easClient.request(GET_PROPERTIES, {
|
|
45
|
+
where: {
|
|
46
|
+
refUID: {
|
|
47
|
+
in: [versionUid],
|
|
48
|
+
},
|
|
49
|
+
decodedDataJson: {
|
|
50
|
+
not: {
|
|
51
|
+
// The first of many filters to keep bad data out
|
|
52
|
+
contains:
|
|
53
|
+
'"value":"0x0000000000000000000000000000000000000000000000000000000000000020"',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
}),
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
// Filter properties by schemaId
|
|
61
|
+
const selectedPropertiesMap: {
|
|
62
|
+
[schemaId: string]: Attestation[]
|
|
63
|
+
} = {}
|
|
64
|
+
itemProperties.forEach((property) => {
|
|
65
|
+
const existingProperties = selectedPropertiesMap[property.schemaId] || []
|
|
66
|
+
existingProperties.push(property)
|
|
67
|
+
selectedPropertiesMap[property.schemaId] = existingProperties
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
// For each schemaId, sort property Attestations by timeCreated DESC
|
|
71
|
+
Object.keys(selectedPropertiesMap).forEach((schemaId) => {
|
|
72
|
+
const sorted = selectedPropertiesMap[schemaId].sort((a, b) => {
|
|
73
|
+
return a.timeCreated - b.timeCreated
|
|
74
|
+
})
|
|
75
|
+
selectedPropertiesMap[schemaId] = sorted
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
Object.keys(selectedPropertiesMap).forEach((schemaId) => {
|
|
79
|
+
// TODO: Finish this logic
|
|
80
|
+
// console.log('[singleItemActors] [fetchDataFromEas] schemaId', schemaId)
|
|
81
|
+
// sendBack({ type: 'addPropertyAttestation', schemaId })
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// Attach processed properties to the itemService/itemMachine context
|
|
85
|
+
sendBack({
|
|
86
|
+
type: 'updatedPropertiesBySchemaUid',
|
|
87
|
+
propertiesBySchemaUid: selectedPropertiesMap,
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
_fetchDataFromEas().then(() => {
|
|
92
|
+
sendBack({ type: 'fetchDataFromEasSuccess' })
|
|
93
|
+
})
|
|
94
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
+
import { AllItemsMachineContext, FromCallbackInput } from '@/types'
|
|
3
|
+
|
|
4
|
+
export const fetchDbData = fromCallback<
|
|
5
|
+
EventObject,
|
|
6
|
+
FromCallbackInput<AllItemsMachineContext>
|
|
7
|
+
>(
|
|
8
|
+
({ sendBack, input: { context } }) => {
|
|
9
|
+
const { modelNamePlural, times } = context
|
|
10
|
+
|
|
11
|
+
const _fetchDbData = async (): Promise<void> => { }
|
|
12
|
+
|
|
13
|
+
_fetchDbData().then(() => {
|
|
14
|
+
sendBack({ type: 'fetchDbDataSuccess' })
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
return () => { }
|
|
18
|
+
},
|
|
19
|
+
)
|
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,45 @@
|
|
|
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 results = await queryClient.fetchQuery({
|
|
32
|
+
queryKey,
|
|
33
|
+
queryFn: async () => easClient.request(GET_SEEDS, queryVariables),
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
itemSeeds = results.itemSeeds
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
_fetchSeeds().then(() => {
|
|
40
|
+
sendBack({ type: 'fetchSeedsSuccess', itemSeeds })
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
return () => { }
|
|
44
|
+
},
|
|
45
|
+
)
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
)
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
}
|