@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.
Files changed (211) hide show
  1. package/dist/{ArweaveClient-Dcqcpsq4.js → ArweaveClient-D5iJisYr.js} +2 -2
  2. package/dist/{ArweaveClient-Dcqcpsq4.js.map → ArweaveClient-D5iJisYr.js.map} +1 -1
  3. package/dist/{ArweaveClient-Dh7LRIqD.js → ArweaveClient-HEIIuOfB.js} +2 -2
  4. package/dist/{ArweaveClient-Dh7LRIqD.js.map → ArweaveClient-HEIIuOfB.js.map} +1 -1
  5. package/dist/{Db-jJH2s0gO.js → Db-D-BsZYlN.js} +3 -3
  6. package/dist/{Db-jJH2s0gO.js.map → Db-D-BsZYlN.js.map} +1 -1
  7. package/dist/{Db-BwkMqaQe.js → Db-Dpsbk_T7.js} +3 -3
  8. package/dist/{Db-BwkMqaQe.js.map → Db-Dpsbk_T7.js.map} +1 -1
  9. package/dist/{EasClient-A1xC7Gm-.js → EasClient-D3wKgt0o.js} +2 -2
  10. package/dist/{EasClient-m2mXad59.js.map → EasClient-D3wKgt0o.js.map} +1 -1
  11. package/dist/{EasClient-m2mXad59.js → EasClient-jqkT2ZBt.js} +2 -2
  12. package/dist/{EasClient-A1xC7Gm-.js.map → EasClient-jqkT2ZBt.js.map} +1 -1
  13. package/dist/{FileManager-Dv2zn1RW.js → FileManager-4mWYO3Mt.js} +3 -5
  14. package/dist/FileManager-4mWYO3Mt.js.map +1 -0
  15. package/dist/{Item-DI3FxVPV.js → Item-CqWdJsyg.js} +3 -3
  16. package/dist/{Item-DI3FxVPV.js.map → Item-CqWdJsyg.js.map} +1 -1
  17. package/dist/{ItemProperty-CxNUwVnR.js → ItemProperty-BpBW3IWx.js} +3 -3
  18. package/dist/{ItemProperty-CxNUwVnR.js.map → ItemProperty-BpBW3IWx.js.map} +1 -1
  19. package/dist/{QueryClient-C-hFMF2j.js → QueryClient-CBOP3OoU.js} +2 -2
  20. package/dist/{QueryClient-C-hFMF2j.js.map → QueryClient-CBOP3OoU.js.map} +1 -1
  21. package/dist/{QueryClient-C02sPZ-K.js → QueryClient-bKb3SB0W.js} +2 -2
  22. package/dist/{QueryClient-C02sPZ-K.js.map → QueryClient-bKb3SB0W.js.map} +1 -1
  23. package/dist/bin.js +5 -5
  24. package/dist/{constants-C03RQQht.js → constants-CIDbABDz.js} +5 -2
  25. package/dist/constants-CIDbABDz.js.map +1 -0
  26. package/dist/{index-CKrLHw3B.js → index-BRxO1tLl.js} +300 -149
  27. package/dist/index-BRxO1tLl.js.map +1 -0
  28. package/dist/{index-Dv8GeuSw.js → index-d8Qsot6w.js} +3 -3
  29. package/dist/index-d8Qsot6w.js.map +1 -0
  30. package/dist/main.js +2 -2
  31. package/dist/package.json +189 -0
  32. package/dist/{seed.schema.config-1s-iWHq_.js → seed.schema.config-CPRn6KVL.js} +3 -3
  33. package/dist/{seed.schema.config-1s-iWHq_.js.map → seed.schema.config-CPRn6KVL.js.map} +1 -1
  34. package/dist/types/src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
  35. package/dist/types/src/browser/helpers/FileManager.d.ts +1 -0
  36. package/dist/types/src/browser/helpers/FileManager.d.ts.map +1 -1
  37. package/dist/types/src/client/BaseClientManager.d.ts +7 -0
  38. package/dist/types/src/client/BaseClientManager.d.ts.map +1 -0
  39. package/dist/types/src/client/actions/setAddresses.d.ts +2 -0
  40. package/dist/types/src/client/actions/setAddresses.d.ts.map +1 -0
  41. package/dist/types/src/client/actors/initialize.d.ts +4 -0
  42. package/dist/types/src/client/actors/initialize.d.ts.map +1 -0
  43. package/dist/types/src/client/actors/saveAppState.d.ts +5 -0
  44. package/dist/types/src/client/actors/saveAppState.d.ts.map +1 -0
  45. package/dist/types/src/client/clientManagerMachine.d.ts +19 -0
  46. package/dist/types/src/client/clientManagerMachine.d.ts.map +1 -0
  47. package/dist/types/src/client/index.d.ts +41 -0
  48. package/dist/types/src/client/index.d.ts.map +1 -0
  49. package/dist/types/src/client.d.ts.map +1 -1
  50. package/dist/types/src/helpers/FileManager/BaseFileManager.d.ts +1 -0
  51. package/dist/types/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
  52. package/dist/types/src/node/helpers/FileManager.d.ts.map +1 -1
  53. package/dist/types/src/services/internal/actors/validateInput.d.ts.map +1 -1
  54. package/dist/types/src/types/machines.d.ts +5 -0
  55. package/dist/types/src/types/machines.d.ts.map +1 -1
  56. package/package.json +2 -2
  57. package/dist/FileManager-Dv2zn1RW.js.map +0 -1
  58. package/dist/constants-C03RQQht.js.map +0 -1
  59. package/dist/index-CKrLHw3B.js.map +0 -1
  60. package/dist/index-Dv8GeuSw.js.map +0 -1
  61. package/dist/src/AppStateSchema.ts +0 -10
  62. package/dist/src/ArweaveClient.ts +0 -13
  63. package/dist/src/Attestation.ts +0 -21
  64. package/dist/src/BaseArweaveClient.ts +0 -13
  65. package/dist/src/BaseDb.ts +0 -35
  66. package/dist/src/BaseEasClient.ts +0 -13
  67. package/dist/src/BaseFileManager.ts +0 -52
  68. package/dist/src/BaseItem.ts +0 -413
  69. package/dist/src/BaseItemProperty.ts +0 -416
  70. package/dist/src/BaseQueryClient.ts +0 -13
  71. package/dist/src/ConfigSchema.ts +0 -15
  72. package/dist/src/Db.ts +0 -78
  73. package/dist/src/EasClient.ts +0 -13
  74. package/dist/src/FileDownloader.ts +0 -63
  75. package/dist/src/FileManager.ts +0 -57
  76. package/dist/src/IDb.ts +0 -7
  77. package/dist/src/IEasClient.ts +0 -2
  78. package/dist/src/IItem.ts +0 -26
  79. package/dist/src/IItemProperty.ts +0 -28
  80. package/dist/src/IQueryClient.ts +0 -4
  81. package/dist/src/ImageResizer.ts +0 -81
  82. package/dist/src/Item.ts +0 -12
  83. package/dist/src/ItemProperty.ts +0 -9
  84. package/dist/src/MetadataSchema.ts +0 -28
  85. package/dist/src/ModelSchema.ts +0 -46
  86. package/dist/src/ModelUidSchema.ts +0 -16
  87. package/dist/src/PropertyUidSchema.ts +0 -16
  88. package/dist/src/QueryClient.ts +0 -22
  89. package/dist/src/Schema.ts +0 -17
  90. package/dist/src/SeedProtocolSdk.d.ts +0 -19
  91. package/dist/src/SeedSchema.ts +0 -29
  92. package/dist/src/VersionSchema.ts +0 -16
  93. package/dist/src/actors.ts +0 -295
  94. package/dist/src/addModelsToDb.ts +0 -152
  95. package/dist/src/allItems.ts +0 -31
  96. package/dist/src/analyzeInput.ts +0 -144
  97. package/dist/src/browser.app.db.config.ts +0 -27
  98. package/dist/src/browser.ts +0 -30
  99. package/dist/src/checkStatus.ts +0 -50
  100. package/dist/src/client.ts +0 -148
  101. package/dist/src/configureFs.ts +0 -94
  102. package/dist/src/connectToDb.ts +0 -41
  103. package/dist/src/connectionManager.ts +0 -67
  104. package/dist/src/constants.ts +0 -125
  105. package/dist/src/content-hash.ts +0 -30
  106. package/dist/src/create.ts +0 -39
  107. package/dist/src/createMetadata.ts +0 -77
  108. package/dist/src/createNewItem.ts +0 -61
  109. package/dist/src/createPublishAttempt.ts +0 -16
  110. package/dist/src/createSeed.ts +0 -31
  111. package/dist/src/createSeeds.ts +0 -24
  112. package/dist/src/createVersion.ts +0 -33
  113. package/dist/src/dbMachine.ts +0 -182
  114. package/dist/src/deleteItem.ts +0 -19
  115. package/dist/src/download.ts +0 -202
  116. package/dist/src/drizzle.ts +0 -78
  117. package/dist/src/eas.ts +0 -40
  118. package/dist/src/environment.ts +0 -35
  119. package/dist/src/eventBus.ts +0 -5
  120. package/dist/src/events.ts +0 -14
  121. package/dist/src/fetchDataFromEas.ts +0 -94
  122. package/dist/src/fetchDbData.ts +0 -19
  123. package/dist/src/fetchRelatedItems.ts +0 -184
  124. package/dist/src/fetchSeeds.ts +0 -52
  125. package/dist/src/fetchVersions.ts +0 -49
  126. package/dist/src/files.ts +0 -81
  127. package/dist/src/filesDownload.ts +0 -326
  128. package/dist/src/fragment-masking.ts +0 -87
  129. package/dist/src/getExistingItem.ts +0 -60
  130. package/dist/src/getItem.ts +0 -32
  131. package/dist/src/getItemData.ts +0 -99
  132. package/dist/src/getItemProperties.ts +0 -56
  133. package/dist/src/getItemProperty.ts +0 -34
  134. package/dist/src/getItems.ts +0 -70
  135. package/dist/src/getMetadata.ts +0 -40
  136. package/dist/src/getModelSchemas.ts +0 -89
  137. package/dist/src/getPropertyData.ts +0 -50
  138. package/dist/src/getPublishPayload.ts +0 -355
  139. package/dist/src/getPublishUploads.ts +0 -207
  140. package/dist/src/getRelationValueData.ts +0 -27
  141. package/dist/src/getSchemaForItemProperty.ts +0 -68
  142. package/dist/src/getSchemaForModel.ts +0 -42
  143. package/dist/src/getSchemaUidForModel.ts +0 -32
  144. package/dist/src/getSeedData.ts +0 -34
  145. package/dist/src/getSegmentedItemProperties.ts +0 -65
  146. package/dist/src/getStorageTransactionIdForSeedUid.ts +0 -38
  147. package/dist/src/getVersionData.ts +0 -46
  148. package/dist/src/getVersionsForVersionUids.ts +0 -39
  149. package/dist/src/globalMachine.ts +0 -280
  150. package/dist/src/gql.ts +0 -118
  151. package/dist/src/graphql.ts +0 -3209
  152. package/dist/src/helpers.ts +0 -273
  153. package/dist/src/hydrateExistingItem.ts +0 -137
  154. package/dist/src/hydrateFromDb.ts +0 -270
  155. package/dist/src/hydrateNewItem.ts +0 -34
  156. package/dist/src/imageResize.ts +0 -507
  157. package/dist/src/index.d.ts +0 -5
  158. package/dist/src/index.ts +0 -4
  159. package/dist/src/initialize.ts +0 -124
  160. package/dist/src/internalMachine.ts +0 -238
  161. package/dist/src/itemMachineAll.ts +0 -157
  162. package/dist/src/itemMachineSingle.ts +0 -158
  163. package/dist/src/loadAppDb.ts +0 -47
  164. package/dist/src/machines.ts +0 -60
  165. package/dist/src/metadataLatest.ts +0 -34
  166. package/dist/src/migrate.ts +0 -53
  167. package/dist/src/model.ts +0 -72
  168. package/dist/src/modelClass.ts +0 -19
  169. package/dist/src/node.app.db.config.ts +0 -41
  170. package/dist/src/prepareDb.ts +0 -29
  171. package/dist/src/preparePublishRequestData.ts +0 -81
  172. package/dist/src/processItems.ts +0 -74
  173. package/dist/src/property.ts +0 -156
  174. package/dist/src/propertyMachine.ts +0 -202
  175. package/dist/src/publish.ts +0 -28
  176. package/dist/src/publishMachine.ts +0 -77
  177. package/dist/src/queries.ts +0 -13
  178. package/dist/src/recoverDeletedItem.ts +0 -14
  179. package/dist/src/reload.ts +0 -33
  180. package/dist/src/request.ts +0 -45
  181. package/dist/src/requestAll.ts +0 -157
  182. package/dist/src/resolveRelatedValue.ts +0 -367
  183. package/dist/src/resolveRemoteStorage.ts +0 -88
  184. package/dist/src/saveAppState.ts +0 -19
  185. package/dist/src/saveConfig.ts +0 -88
  186. package/dist/src/saveDataToDb.ts +0 -145
  187. package/dist/src/saveImageSrc.ts +0 -242
  188. package/dist/src/saveItemStorage.ts +0 -155
  189. package/dist/src/saveMetadata.ts +0 -18
  190. package/dist/src/savePublishService.ts +0 -30
  191. package/dist/src/saveRelation.ts +0 -112
  192. package/dist/src/seed.schema.config.ts +0 -25
  193. package/dist/src/seed.ts +0 -10
  194. package/dist/src/seedProtocol.ts +0 -17
  195. package/dist/src/services.ts +0 -365
  196. package/dist/src/sqlWasmClient.ts +0 -88
  197. package/dist/src/syncDbWithEas.ts +0 -628
  198. package/dist/src/trash.ts +0 -29
  199. package/dist/src/ts-to-proto.ts +0 -101
  200. package/dist/src/types.ts +0 -12
  201. package/dist/src/updateItemPropertyValue.ts +0 -243
  202. package/dist/src/updateMachineContext.ts +0 -21
  203. package/dist/src/updateMetadata.ts +0 -59
  204. package/dist/src/upload.ts +0 -86
  205. package/dist/src/validate.ts +0 -45
  206. package/dist/src/validateInput.ts +0 -47
  207. package/dist/src/validateItemData.ts +0 -20
  208. package/dist/src/versionData.ts +0 -24
  209. package/dist/src/waitForDb.ts +0 -25
  210. package/dist/src/waitForFiles.ts +0 -34
  211. package/dist/src/wasm.d.ts +0 -8300
@@ -1,355 +0,0 @@
1
- import { getItem } from '@/db/read/getItem'
2
- import {
3
- defaultAttestationData,
4
- INTERNAL_DATA_TYPES,
5
- VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
6
- } from '@/helpers/constants'
7
- import {
8
- AttestationRequest,
9
- SchemaEncoder,
10
- ZERO_BYTES32,
11
- } from '@ethereum-attestation-service/eas-sdk'
12
-
13
- import { getSchemaForItemProperty } from '@/helpers/getSchemaForItemProperty'
14
- import { toSnakeCase } from '@/helpers'
15
- import pluralize from 'pluralize'
16
- import { getSchemaUidForModel } from '@/db/read/getSchemaUidForModel'
17
- import { getSchemaUidForSchemaDefinition } from '@/stores/eas'
18
- import { getCorrectId } from '@/helpers'
19
- import { getSegmentedItemProperties } from '@/helpers/getSegmentedItemProperties'
20
- import { IItemProperty } from '@/interfaces'
21
- import { IItem } from '@/interfaces'
22
- import { BaseItem } from '@/Item/BaseItem'
23
-
24
- const getVersionUid = (item: IItem<any>) => {
25
- let versionUid
26
-
27
- if (
28
- item.latestVersionUid &&
29
- item.latestVersionUid !== 'NULL' &&
30
- item.latestVersionUid !== 'undefined'
31
- ) {
32
- versionUid = item.latestVersionUid
33
- }
34
- return versionUid || ZERO_BYTES32
35
- }
36
-
37
- const getPropertyData = async (itemProperty: IItemProperty<any>) => {
38
- const easDataType =
39
- INTERNAL_DATA_TYPES[itemProperty.propertyDef!.dataType].eas
40
-
41
- let schemaUid: string | undefined = itemProperty.schemaUid
42
-
43
- const propertyNameForSchema = toSnakeCase(itemProperty.propertyName)
44
-
45
- const schemaDef = `${easDataType} ${propertyNameForSchema}`
46
-
47
- if (!schemaUid) {
48
- schemaUid = getSchemaUidForSchemaDefinition(schemaDef)
49
- if (!schemaUid) {
50
- const schema = await getSchemaForItemProperty({
51
- propertyName: 'version',
52
- easDataType: 'bytes32',
53
- })
54
- if (schema) {
55
- schemaUid = schema.id
56
- }
57
- }
58
- }
59
-
60
- return {
61
- schemaUid,
62
- easDataType,
63
- schemaDef,
64
- propertyNameForSchema,
65
- }
66
- }
67
-
68
- const processBasicProperties = async (
69
- itemBasicProperties: IItemProperty<any>[],
70
- itemPublishData: PublishPayload,
71
- ): Promise<PublishPayload> => {
72
- for (const basicProperty of itemBasicProperties) {
73
- const value = basicProperty.getService().getSnapshot().context.propertyValue
74
-
75
- if (!value || basicProperty.uid) {
76
- continue
77
- }
78
-
79
- const { schemaUid, easDataType, schemaDef } =
80
- await getPropertyData(basicProperty)
81
-
82
- const propertyNameForSchema = toSnakeCase(basicProperty.propertyName)
83
-
84
- const data = [
85
- {
86
- name: propertyNameForSchema,
87
- type: easDataType,
88
- value,
89
- },
90
- ]
91
-
92
- const dataEncoder = new SchemaEncoder(schemaDef)
93
-
94
- const encodedData = dataEncoder.encodeData(data)
95
-
96
- itemPublishData.listOfAttestations.push({
97
- schema: schemaUid!,
98
- data: [
99
- {
100
- ...defaultAttestationData,
101
- data: encodedData,
102
- },
103
- ],
104
- })
105
- }
106
-
107
- return itemPublishData
108
- }
109
-
110
- const processRelationProperty = async (
111
- relationProperty: IItemProperty<any>,
112
- multiPublishPayload: MultiPublishPayload,
113
- uploadedTransactions: UploadedTransaction[],
114
- originalSeedLocalId: string,
115
- ): Promise<MultiPublishPayload> => {
116
- const value = relationProperty.getService().getSnapshot()
117
- .context.propertyValue
118
- if (!value || relationProperty.uid) {
119
- return multiPublishPayload
120
- }
121
-
122
- const { localId: seedLocalId, uid: seedUid } = getCorrectId(value)
123
-
124
- const relatedItem = await getItem({
125
- seedLocalId,
126
- seedUid,
127
- })
128
-
129
- if (!relatedItem) {
130
- throw new Error(
131
- `No related item found for relation property: ${relationProperty.propertyName}`,
132
- )
133
- }
134
-
135
- const versionUid = getVersionUid(relatedItem)
136
-
137
- const seedSchemaUid = await getSchemaUidForModel(
138
- relationProperty.propertyDef!.ref as string,
139
- )
140
-
141
- let publishPayload: PublishPayload = {
142
- localId: relationProperty.localId,
143
- seedIsRevocable: true,
144
- versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
145
- seedUid: seedUid || ZERO_BYTES32,
146
- seedSchemaUid,
147
- versionUid,
148
- listOfAttestations: [],
149
- propertiesToUpdate: [
150
- {
151
- publishLocalId: originalSeedLocalId,
152
- propertySchemaUid: relationProperty.schemaUid,
153
- },
154
- ],
155
- }
156
-
157
- const { itemBasicProperties, itemUploadProperties } =
158
- getSegmentedItemProperties(relatedItem)
159
-
160
- if (itemUploadProperties.length === 1) {
161
- const uploadProperty = itemUploadProperties[0]
162
- const itemProperty = uploadProperty.itemProperty
163
- const transactionData = uploadedTransactions.find(
164
- (transaction) => transaction.seedLocalId === relatedItem.seedLocalId,
165
- )
166
- if (transactionData) {
167
- itemProperty.value = transactionData.txId
168
- await itemProperty.save()
169
- itemBasicProperties.push(itemProperty)
170
- }
171
- }
172
-
173
- publishPayload = await processBasicProperties(
174
- itemBasicProperties,
175
- publishPayload,
176
- )
177
-
178
- multiPublishPayload.push(publishPayload)
179
-
180
- return multiPublishPayload
181
- }
182
-
183
- const processListProperty = async (
184
- listProperty: IItemProperty<any>,
185
- multiPublishPayload: MultiPublishPayload,
186
- originalSeedLocalId: string,
187
- ): Promise<MultiPublishPayload> => {
188
- let value = listProperty.getService().getSnapshot().context.propertyValue
189
- if (!value || listProperty.uid) {
190
- return multiPublishPayload
191
- }
192
-
193
- const singularPropertyName = pluralize.singular(listProperty.propertyName)
194
- const propertyNameForSchema = `${singularPropertyName}${listProperty.propertyDef!.ref}Ids`
195
- if (typeof value === 'string' && value.length === 66) {
196
- value = [value]
197
- }
198
- if (typeof value === 'string' && value.length > 66) {
199
- try {
200
- value = JSON.parse(value)
201
- } catch (error) {
202
- value = value.split(',')
203
- }
204
- }
205
-
206
- for (const seedId of value) {
207
- const { localId: seedLocalId, uid: seedUid } = getCorrectId(seedId)
208
-
209
- const relatedItem = await getItem({
210
- seedLocalId,
211
- seedUid,
212
- })
213
-
214
- if (!relatedItem) {
215
- console.error(
216
- `No related item found for list property: ${listProperty.propertyName}`,
217
- )
218
- continue
219
- }
220
-
221
- if (relatedItem.seedUid) {
222
- return multiPublishPayload
223
- }
224
-
225
- const versionUid = getVersionUid(relatedItem)
226
-
227
- const seedSchemaUid = await getSchemaUidForModel(
228
- listProperty.propertyDef!.ref as string,
229
- )
230
-
231
- let publishPayload: PublishPayload = {
232
- localId: relatedItem.seedLocalId,
233
- seedIsRevocable: true,
234
- versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
235
- seedUid: seedUid || ZERO_BYTES32,
236
- seedSchemaUid,
237
- versionUid,
238
- listOfAttestations: [],
239
- propertiesToUpdate: [
240
- {
241
- publishLocalId: originalSeedLocalId,
242
- propertySchemaUid: listProperty.schemaUid,
243
- },
244
- ],
245
- }
246
-
247
- const { itemBasicProperties } = getSegmentedItemProperties(relatedItem)
248
-
249
- publishPayload = await processBasicProperties(
250
- itemBasicProperties,
251
- publishPayload,
252
- )
253
-
254
- multiPublishPayload.push(publishPayload)
255
- }
256
-
257
- return multiPublishPayload
258
- }
259
-
260
- type PublishPayload = {
261
- localId: string
262
- seedIsRevocable: boolean
263
- seedSchemaUid: string
264
- seedUid: string
265
- versionSchemaUid: string
266
- versionUid: string
267
- listOfAttestations: AttestationRequest[]
268
- propertiesToUpdate: any[]
269
- }
270
-
271
- type MultiPublishPayload = PublishPayload[]
272
-
273
- type UploadedTransaction = {
274
- txId: string
275
- itemPropertyLocalId?: string
276
- seedLocalId?: string
277
- versionLocalId?: string
278
- itemPropertyName?: string
279
- }
280
-
281
- export const getPublishPayload = async (
282
- item: BaseItem<any>,
283
- uploadedTransactions: UploadedTransaction[],
284
- ): Promise<MultiPublishPayload> => {
285
-
286
- let multiPublishPayload: MultiPublishPayload = []
287
-
288
- // Each PublishPayload is generated from a Seed that needs publishing
289
-
290
- // First we need to determine all Seeds to publish
291
-
292
- // That means the Seed of the Item, plus any Seeds pointed to by Relations
293
-
294
- let itemPublishData: PublishPayload = {
295
- localId: item.seedLocalId,
296
- seedUid: item.seedUid || ZERO_BYTES32,
297
- seedIsRevocable: true,
298
- seedSchemaUid: item.schemaUid,
299
- versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
300
- versionUid: getVersionUid(item),
301
- listOfAttestations: [],
302
- propertiesToUpdate: [],
303
- }
304
-
305
- const {
306
- itemBasicProperties,
307
- itemRelationProperties,
308
- itemListProperties,
309
- itemUploadProperties,
310
- } = getSegmentedItemProperties(item)
311
-
312
- if (itemUploadProperties.length === 1) {
313
- const uploadProperty = itemUploadProperties[0]
314
- const itemProperty = uploadProperty.itemProperty
315
- const transactionData = uploadedTransactions.find(
316
- (transaction) => transaction.seedLocalId === item.seedLocalId,
317
- )
318
- if (transactionData) {
319
- itemProperty.value = transactionData.txId
320
- await itemProperty.save()
321
- itemBasicProperties.push(itemProperty)
322
- }
323
- }
324
-
325
- for (const relationProperty of itemRelationProperties) {
326
- multiPublishPayload = await processRelationProperty(
327
- relationProperty,
328
- multiPublishPayload,
329
- uploadedTransactions,
330
- item.seedLocalId,
331
- )
332
- itemBasicProperties.push(relationProperty)
333
- }
334
-
335
- for (const listProperty of itemListProperties) {
336
- multiPublishPayload = await processListProperty(
337
- listProperty,
338
- multiPublishPayload,
339
- item.seedLocalId,
340
- )
341
- itemBasicProperties.push(listProperty)
342
- }
343
-
344
- itemPublishData = await processBasicProperties(
345
- itemBasicProperties,
346
- itemPublishData,
347
- )
348
-
349
- multiPublishPayload.push(itemPublishData)
350
-
351
-
352
-
353
-
354
- return multiPublishPayload
355
- }
@@ -1,207 +0,0 @@
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
- }
@@ -1,27 +0,0 @@
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
- }
@@ -1,68 +0,0 @@
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
- }
@@ -1,42 +0,0 @@
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
- })