@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,207 @@
|
|
|
1
|
+
import Transaction from 'arweave'
|
|
2
|
+
import { CreateTransactionInterface } from 'arweave/web'
|
|
3
|
+
import { getArweave } from '@/helpers/ArweaveClient'
|
|
4
|
+
import fs from '@zenfs/core'
|
|
5
|
+
import { getCorrectId } from '@/helpers'
|
|
6
|
+
import { getSegmentedItemProperties } from '@/helpers/getSegmentedItemProperties'
|
|
7
|
+
import debug from 'debug'
|
|
8
|
+
import { IItem, IItemProperty } from '@/interfaces'
|
|
9
|
+
import { getContentHash } from '@/helpers'
|
|
10
|
+
import { BaseItem } from '@/Item/BaseItem'
|
|
11
|
+
|
|
12
|
+
const logger = debug('app:item:getPublishUploads')
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export const prepareArweaveTransaction = async (
|
|
16
|
+
data: string | Uint8Array,
|
|
17
|
+
contentHash: string | undefined,
|
|
18
|
+
): Promise<Transaction> => {
|
|
19
|
+
const transactionData: Partial<CreateTransactionInterface> = {
|
|
20
|
+
data,
|
|
21
|
+
tags: [],
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const tx = await getArweave()!.createTransaction(transactionData)
|
|
25
|
+
|
|
26
|
+
if (contentHash) {
|
|
27
|
+
logger('contentHash', contentHash)
|
|
28
|
+
logger('adding content hash tag to tx.id:', tx.id)
|
|
29
|
+
tx.addTag('Content-SHA-256', contentHash)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return tx
|
|
33
|
+
}
|
|
34
|
+
export type UploadProperty = {
|
|
35
|
+
itemProperty: IItemProperty<any>
|
|
36
|
+
childProperties: IItemProperty<any>[]
|
|
37
|
+
}
|
|
38
|
+
type ChildUploadData = {
|
|
39
|
+
propertyName: string
|
|
40
|
+
localStoragePath: string
|
|
41
|
+
}
|
|
42
|
+
const processUploadProperty = async (
|
|
43
|
+
uploadProperty: UploadProperty,
|
|
44
|
+
uploads: PublishUpload[],
|
|
45
|
+
relatedItemProperty?: IItemProperty<any>,
|
|
46
|
+
): Promise<PublishUpload[]> => {
|
|
47
|
+
const itemProperty = uploadProperty.itemProperty
|
|
48
|
+
|
|
49
|
+
const childUploads: ChildUploadData[] = []
|
|
50
|
+
|
|
51
|
+
for (const childProperty of uploadProperty.childProperties) {
|
|
52
|
+
const filePath = childProperty.localStoragePath
|
|
53
|
+
|
|
54
|
+
if (!filePath || filePath.endsWith('undefined')) {
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const exists = await fs.promises.exists(filePath)
|
|
59
|
+
if (!exists) {
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
childUploads.push({
|
|
64
|
+
propertyName: childProperty.propertyName,
|
|
65
|
+
localStoragePath: filePath,
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let fileContents
|
|
70
|
+
let transaction: Transaction
|
|
71
|
+
|
|
72
|
+
if (!childUploads || childUploads.length === 0) {
|
|
73
|
+
if (relatedItemProperty && relatedItemProperty.localStoragePath) {
|
|
74
|
+
const filePath = relatedItemProperty.localStoragePath
|
|
75
|
+
|
|
76
|
+
if (!filePath || filePath.endsWith('undefined')) {
|
|
77
|
+
return uploads
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const exists = await fs.promises.exists(filePath)
|
|
81
|
+
if (!exists) {
|
|
82
|
+
return uploads
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
fileContents = await fs.promises.readFile(filePath)
|
|
88
|
+
} catch (e) {
|
|
89
|
+
fileContents = fs.readFileSync(filePath)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!fileContents) {
|
|
93
|
+
return uploads
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (childUploads.length > 0) {
|
|
98
|
+
const separator = '===FILE_SEPARATOR==='
|
|
99
|
+
// let compositeFileContents = `${itemProperty.propertyName}${separator}${mainFileContents}`
|
|
100
|
+
let compositeFileContents = ''
|
|
101
|
+
|
|
102
|
+
for (const childUpload of childUploads) {
|
|
103
|
+
let childUploadContents
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
childUploadContents = await fs.promises.readFile(
|
|
107
|
+
childUpload.localStoragePath,
|
|
108
|
+
)
|
|
109
|
+
} catch (e) {
|
|
110
|
+
childUploadContents = fs.readFileSync(childUpload.localStoragePath)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
compositeFileContents += `${separator}${childUpload.propertyName}${separator}${childUploadContents}`
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
fileContents = Buffer.from(compositeFileContents)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!fileContents) {
|
|
120
|
+
throw new Error(`No file contents found for ${itemProperty.propertyName}`)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const uint8Array = new Uint8Array(
|
|
124
|
+
fileContents.buffer,
|
|
125
|
+
fileContents.byteOffset,
|
|
126
|
+
fileContents.byteLength,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
const contentHash = await getContentHash(null, uint8Array)
|
|
130
|
+
|
|
131
|
+
transaction = await prepareArweaveTransaction(fileContents, contentHash)
|
|
132
|
+
|
|
133
|
+
let itemPropertyLocalId = relatedItemProperty
|
|
134
|
+
? relatedItemProperty.localId
|
|
135
|
+
: itemProperty.localId
|
|
136
|
+
let itemPropertyName = relatedItemProperty
|
|
137
|
+
? relatedItemProperty.propertyName
|
|
138
|
+
: itemProperty.propertyName
|
|
139
|
+
|
|
140
|
+
uploads.push({
|
|
141
|
+
itemPropertyName,
|
|
142
|
+
itemPropertyLocalId,
|
|
143
|
+
seedLocalId: itemProperty.seedLocalId!,
|
|
144
|
+
versionLocalId: itemProperty.versionLocalId!,
|
|
145
|
+
transactionToSign: transaction,
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
return uploads
|
|
149
|
+
}
|
|
150
|
+
export type PublishUpload = {
|
|
151
|
+
itemPropertyName: string
|
|
152
|
+
itemPropertyLocalId: string
|
|
153
|
+
seedLocalId: string
|
|
154
|
+
versionLocalId: string
|
|
155
|
+
transactionToSign: Transaction
|
|
156
|
+
}
|
|
157
|
+
export const getPublishUploads = async (
|
|
158
|
+
item: IItem<any>,
|
|
159
|
+
uploads: PublishUpload[] = [],
|
|
160
|
+
relatedItemProperty?: IItemProperty<any>,
|
|
161
|
+
) => {
|
|
162
|
+
// if (item.modelName === 'Post') {
|
|
163
|
+
// if (!item.authors) {
|
|
164
|
+
// item.authors = [
|
|
165
|
+
// 'Sr0bIx9Fwj',
|
|
166
|
+
// '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',
|
|
167
|
+
// ]
|
|
168
|
+
// }
|
|
169
|
+
// }
|
|
170
|
+
|
|
171
|
+
const { itemUploadProperties, itemRelationProperties } =
|
|
172
|
+
getSegmentedItemProperties(item)
|
|
173
|
+
|
|
174
|
+
for (const uploadProperty of itemUploadProperties) {
|
|
175
|
+
uploads = await processUploadProperty(
|
|
176
|
+
uploadProperty,
|
|
177
|
+
uploads,
|
|
178
|
+
relatedItemProperty,
|
|
179
|
+
)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
for (const relationProperty of itemRelationProperties) {
|
|
183
|
+
const propertyValue = relationProperty.getService().getSnapshot()
|
|
184
|
+
.context.propertyValue
|
|
185
|
+
|
|
186
|
+
if (!propertyValue || relationProperty.uid) {
|
|
187
|
+
continue
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const { localId: seedLocalId, uid: seedUid } = getCorrectId(propertyValue)
|
|
191
|
+
|
|
192
|
+
const relatedItem = await BaseItem.find({
|
|
193
|
+
seedLocalId,
|
|
194
|
+
seedUid,
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
if (!relatedItem) {
|
|
198
|
+
throw new Error(
|
|
199
|
+
`No relatedItem found for ${relationProperty.propertyName}`,
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
uploads = await getPublishUploads(relatedItem, uploads, relationProperty)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return uploads
|
|
207
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { metadata, MetadataType } from '@/seedSchema'
|
|
2
|
+
import { eq, max } from 'drizzle-orm'
|
|
3
|
+
import { BaseDb } from '@/db/Db/BaseDb'
|
|
4
|
+
|
|
5
|
+
export const getRelationValueData = async (
|
|
6
|
+
propertyValue: any,
|
|
7
|
+
): Promise<MetadataType | undefined> => {
|
|
8
|
+
const appDb = BaseDb.getAppDb()
|
|
9
|
+
|
|
10
|
+
const rows = (await appDb
|
|
11
|
+
.select({
|
|
12
|
+
propertyValue: metadata.propertyValue,
|
|
13
|
+
attestationCreatedAt: max(metadata.attestationCreatedAt),
|
|
14
|
+
refResolvedDisplayValue: metadata.refResolvedDisplayValue,
|
|
15
|
+
refResolvedValue: metadata.refResolvedValue,
|
|
16
|
+
refSeedType: metadata.refSeedType,
|
|
17
|
+
easDataType: metadata.easDataType,
|
|
18
|
+
})
|
|
19
|
+
.from(metadata)
|
|
20
|
+
.where(eq(metadata.propertyValue, propertyValue))) as MetadataType[]
|
|
21
|
+
|
|
22
|
+
if (!rows || rows.length === 0) {
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return rows[0]
|
|
27
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Schema, SchemaWhereInput } from '@/graphql/gql/graphql'
|
|
2
|
+
import { toSnakeCase, BaseEasClient, BaseQueryClient } from '@/helpers'
|
|
3
|
+
import { GET_SCHEMAS } from '@/Item/queries'
|
|
4
|
+
import { TypedData } from '@ethereum-attestation-service/eas-sdk/dist/offchain/typed-data-handler'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
type GetSchemaForPropertyProps = {
|
|
8
|
+
schemaUid?: string
|
|
9
|
+
propertyName: string
|
|
10
|
+
easDataType?: TypedData['type']
|
|
11
|
+
}
|
|
12
|
+
type GetSchemaForProperty = (
|
|
13
|
+
props: GetSchemaForPropertyProps,
|
|
14
|
+
) => Promise<Schema | void>
|
|
15
|
+
export const getSchemaForItemProperty: GetSchemaForProperty = async ({
|
|
16
|
+
schemaUid,
|
|
17
|
+
propertyName,
|
|
18
|
+
easDataType,
|
|
19
|
+
}): Promise<Schema | void> => {
|
|
20
|
+
const propertyNameSnakeCase = toSnakeCase(propertyName)
|
|
21
|
+
const isMissingSchemaUid =
|
|
22
|
+
!schemaUid || schemaUid === 'null' || schemaUid === 'undefined'
|
|
23
|
+
|
|
24
|
+
const queryClient = BaseQueryClient.getQueryClient()
|
|
25
|
+
const easClient = BaseEasClient.getEasClient()
|
|
26
|
+
|
|
27
|
+
let queryParams: { where: SchemaWhereInput } = {
|
|
28
|
+
where: {
|
|
29
|
+
id: {
|
|
30
|
+
equals: schemaUid,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (easDataType) {
|
|
36
|
+
queryParams = {
|
|
37
|
+
where: {
|
|
38
|
+
schema: {
|
|
39
|
+
equals: `${easDataType} ${propertyNameSnakeCase}`,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!easDataType && isMissingSchemaUid) {
|
|
46
|
+
queryParams = {
|
|
47
|
+
where: {
|
|
48
|
+
schemaNames: {
|
|
49
|
+
some: {
|
|
50
|
+
name: {
|
|
51
|
+
equals: propertyNameSnakeCase,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const foundPropertySchema = await queryClient.fetchQuery({
|
|
60
|
+
queryKey: [`getPropertySchema${propertyName}`],
|
|
61
|
+
queryFn: async () => easClient.request(GET_SCHEMAS, queryParams),
|
|
62
|
+
networkMode: 'offlineFirst',
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
if (foundPropertySchema && foundPropertySchema.schemas.length > 0) {
|
|
66
|
+
return foundPropertySchema.schemas[0] as Schema
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
+
import {
|
|
3
|
+
FromCallbackInput,
|
|
4
|
+
GetSchemaForModelEvent,
|
|
5
|
+
GlobalMachineContext,
|
|
6
|
+
} from '@/types'
|
|
7
|
+
import debug from 'debug'
|
|
8
|
+
|
|
9
|
+
const logger = debug('app:services:global:actors:getSchemaForModel')
|
|
10
|
+
|
|
11
|
+
export const getSchemaForModel = fromCallback<
|
|
12
|
+
EventObject,
|
|
13
|
+
FromCallbackInput<GlobalMachineContext, GetSchemaForModelEvent>
|
|
14
|
+
>(({ sendBack, input: { context, event } }) => {
|
|
15
|
+
const { modelName } = event
|
|
16
|
+
|
|
17
|
+
if (!modelName) {
|
|
18
|
+
console.warn('No modelName found')
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { models } = context
|
|
23
|
+
|
|
24
|
+
if (!models) {
|
|
25
|
+
console.warn('No models found')
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const model = Object.entries(models).find(
|
|
30
|
+
([modelNameFromConfig]) => modelNameFromConfig === modelName,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
if (!model) {
|
|
34
|
+
throw new Error(`Model ${modelName} not found`)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
logger('[service/actor] [getSchemaForModel] model:', model)
|
|
38
|
+
|
|
39
|
+
sendBack({ type: 'schemaForModel', schema: model.schema })
|
|
40
|
+
|
|
41
|
+
return () => {}
|
|
42
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { GET_SCHEMAS } from '@/Item/queries'
|
|
2
|
+
import { BaseEasClient } from '@/helpers/EasClient/BaseEasClient'
|
|
3
|
+
import { BaseQueryClient } from '@/helpers/QueryClient/BaseQueryClient'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export const getSchemaUidForModel = async (
|
|
7
|
+
modelName: string,
|
|
8
|
+
): Promise<string> => {
|
|
9
|
+
const queryClient = BaseQueryClient.getQueryClient()
|
|
10
|
+
const easClient = BaseEasClient.getEasClient()
|
|
11
|
+
|
|
12
|
+
const modeType = modelName.toLowerCase()
|
|
13
|
+
|
|
14
|
+
const modelSchemaQuery = await queryClient.fetchQuery({
|
|
15
|
+
queryKey: [`getPropertySchema${modelName}`],
|
|
16
|
+
queryFn: async () =>
|
|
17
|
+
easClient.request(GET_SCHEMAS, {
|
|
18
|
+
where: {
|
|
19
|
+
schemaNames: {
|
|
20
|
+
some: {
|
|
21
|
+
name: {
|
|
22
|
+
equals: modeType,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const foundSchema = modelSchemaQuery.schemas[0]
|
|
31
|
+
return foundSchema.id
|
|
32
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BaseDb } from '@/db/Db/BaseDb'
|
|
2
|
+
import { seeds, SeedType } from '@/seedSchema'
|
|
3
|
+
import { eq } from 'drizzle-orm'
|
|
4
|
+
|
|
5
|
+
type GetSeedDataProps = {
|
|
6
|
+
seedLocalId?: string
|
|
7
|
+
seedUid?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type GetSeedData = (props: GetSeedDataProps) => Promise<SeedType | undefined>
|
|
11
|
+
|
|
12
|
+
export const getSeedData: GetSeedData = async ({ seedLocalId, seedUid }) => {
|
|
13
|
+
const appDb = BaseDb.getAppDb()
|
|
14
|
+
|
|
15
|
+
let query
|
|
16
|
+
|
|
17
|
+
const queryBase = appDb.select().from(seeds)
|
|
18
|
+
|
|
19
|
+
if (seedLocalId) {
|
|
20
|
+
query = queryBase.where(eq(seeds.localId, seedLocalId))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (seedUid) {
|
|
24
|
+
query = queryBase.where(eq(seeds.uid, seedUid))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const rows = await query
|
|
28
|
+
|
|
29
|
+
if (!rows || !rows.length) {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return rows[0]
|
|
34
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { UploadProperty } from '@/db/read/getPublishUploads'
|
|
2
|
+
import { IItem } from '@/interfaces'
|
|
3
|
+
|
|
4
|
+
export const getSegmentedItemProperties = (item: IItem<any>) => {
|
|
5
|
+
const itemBasicProperties = []
|
|
6
|
+
const itemRelationProperties = []
|
|
7
|
+
const itemListProperties = []
|
|
8
|
+
const itemUploadProperties: UploadProperty[] = []
|
|
9
|
+
const itemStorageProperties = []
|
|
10
|
+
let itemStorageTransactionProperty: UploadProperty | undefined
|
|
11
|
+
|
|
12
|
+
for (const itemProperty of Object.values(item.properties)) {
|
|
13
|
+
if (!itemProperty.propertyDef) {
|
|
14
|
+
continue
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const isItemStorage =
|
|
18
|
+
itemProperty.propertyDef.storageType &&
|
|
19
|
+
itemProperty.propertyDef.storageType === 'ItemStorage'
|
|
20
|
+
|
|
21
|
+
const isImageSrc =
|
|
22
|
+
itemProperty.propertyDef.dataType === 'Relation' &&
|
|
23
|
+
itemProperty.propertyDef.refValueType === 'ImageSrc'
|
|
24
|
+
|
|
25
|
+
const isStorageTransaction =
|
|
26
|
+
itemProperty.propertyName === 'storageTransactionId'
|
|
27
|
+
|
|
28
|
+
if (itemProperty.propertyDef.dataType === 'Relation') {
|
|
29
|
+
itemRelationProperties.push(itemProperty)
|
|
30
|
+
continue
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (itemProperty.propertyDef.dataType === 'List') {
|
|
34
|
+
itemListProperties.push(itemProperty)
|
|
35
|
+
continue
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (isItemStorage) {
|
|
39
|
+
itemStorageProperties.push(itemProperty)
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (isStorageTransaction) {
|
|
44
|
+
itemStorageTransactionProperty = { itemProperty, childProperties: [] }
|
|
45
|
+
continue
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
itemBasicProperties.push(itemProperty)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (itemStorageTransactionProperty && itemStorageProperties.length > 0) {
|
|
52
|
+
itemStorageTransactionProperty.childProperties = itemStorageProperties
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (itemStorageTransactionProperty) {
|
|
56
|
+
itemUploadProperties.push(itemStorageTransactionProperty)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
itemBasicProperties,
|
|
61
|
+
itemRelationProperties,
|
|
62
|
+
itemListProperties,
|
|
63
|
+
itemUploadProperties,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { metadata } from '@/seedSchema'
|
|
2
|
+
import { and, eq } from 'drizzle-orm'
|
|
3
|
+
import { BaseDb } from '@/db/Db/BaseDb'
|
|
4
|
+
|
|
5
|
+
const seedUidToStorageTransactionId = new Map<string, string>()
|
|
6
|
+
|
|
7
|
+
type GetStorageTransactionIdResults = {
|
|
8
|
+
storageTransactionId: string
|
|
9
|
+
}[]
|
|
10
|
+
|
|
11
|
+
export const getStorageTransactionIdForSeedUid = async (
|
|
12
|
+
seedUid: string,
|
|
13
|
+
): Promise<string | undefined> => {
|
|
14
|
+
if (seedUidToStorageTransactionId.has(seedUid)) {
|
|
15
|
+
return seedUidToStorageTransactionId.get(seedUid)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const appDb = BaseDb.getAppDb()
|
|
19
|
+
|
|
20
|
+
const results = (await appDb
|
|
21
|
+
.select({
|
|
22
|
+
storageTransactionId: metadata.propertyValue,
|
|
23
|
+
})
|
|
24
|
+
.from(metadata)
|
|
25
|
+
.where(
|
|
26
|
+
and(
|
|
27
|
+
eq(metadata.seedUid, seedUid),
|
|
28
|
+
eq(metadata.propertyName, 'storageTransactionId'),
|
|
29
|
+
),
|
|
30
|
+
)) as GetStorageTransactionIdResults
|
|
31
|
+
|
|
32
|
+
if (!results || results.length === 0) {
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
seedUidToStorageTransactionId.set(seedUid, results[0].storageTransactionId)
|
|
37
|
+
return results[0].storageTransactionId
|
|
38
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { versions, VersionsType } from '@/seedSchema'
|
|
2
|
+
import { and, eq } from 'drizzle-orm'
|
|
3
|
+
import { BaseDb } from '../Db/BaseDb'
|
|
4
|
+
|
|
5
|
+
type GetVersionDataProps = {
|
|
6
|
+
localId?: string | null
|
|
7
|
+
uid?: string
|
|
8
|
+
seedLocalId?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type GetVersionData = (
|
|
12
|
+
props: GetVersionDataProps,
|
|
13
|
+
) => Promise<VersionsType | undefined>
|
|
14
|
+
|
|
15
|
+
export const getVersionData: GetVersionData = async ({
|
|
16
|
+
localId,
|
|
17
|
+
seedLocalId,
|
|
18
|
+
uid,
|
|
19
|
+
}) => {
|
|
20
|
+
const appDb = BaseDb.getAppDb()
|
|
21
|
+
|
|
22
|
+
const whereClauses = []
|
|
23
|
+
|
|
24
|
+
if (seedLocalId) {
|
|
25
|
+
whereClauses.push(eq(versions.localId, seedLocalId))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (localId) {
|
|
29
|
+
whereClauses.push(eq(versions.localId, localId))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (uid) {
|
|
33
|
+
whereClauses.push(eq(versions.uid, uid))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const queryRows = await appDb
|
|
37
|
+
.select()
|
|
38
|
+
.from(versions)
|
|
39
|
+
.where(and(...whereClauses))
|
|
40
|
+
|
|
41
|
+
if (!queryRows || !queryRows.length) {
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return queryRows[0]
|
|
46
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { runQueryForStatement } from '../sqlWasmClient'
|
|
2
|
+
|
|
3
|
+
type VersionData = {
|
|
4
|
+
localId: string
|
|
5
|
+
uid: string
|
|
6
|
+
seedUid: string
|
|
7
|
+
seedLocalId: string
|
|
8
|
+
}
|
|
9
|
+
type GetVersionsForVersionUids = (
|
|
10
|
+
versionUids: string[],
|
|
11
|
+
) => Promise<VersionData[]>
|
|
12
|
+
export const getVersionsForVersionUids: GetVersionsForVersionUids = async (
|
|
13
|
+
versionUids: string[],
|
|
14
|
+
) => {
|
|
15
|
+
const queryStatement = `
|
|
16
|
+
SELECT local_id, uid, seed_uid, seed_local_id
|
|
17
|
+
FROM versions
|
|
18
|
+
WHERE uid IN ('${versionUids.join("','")}');
|
|
19
|
+
`
|
|
20
|
+
|
|
21
|
+
const { rows } = await runQueryForStatement(queryStatement)
|
|
22
|
+
|
|
23
|
+
if (!rows || rows.length === 0) {
|
|
24
|
+
return []
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const versionsData: VersionData[] = []
|
|
28
|
+
|
|
29
|
+
for (const row of rows) {
|
|
30
|
+
versionsData.push({
|
|
31
|
+
localId: row[0],
|
|
32
|
+
uid: row[1],
|
|
33
|
+
seedUid: row[2],
|
|
34
|
+
seedLocalId: row[3],
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return versionsData
|
|
39
|
+
}
|