@seedprotocol/sdk 0.2.51 → 0.2.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/dist/{ArweaveClient-D1TsTBoj.js → ArweaveClient-D5iJisYr.js} +2 -2
  2. package/dist/{ArweaveClient-DpdXUcVJ.js.map → ArweaveClient-D5iJisYr.js.map} +1 -1
  3. package/dist/{ArweaveClient-DpdXUcVJ.js → ArweaveClient-HEIIuOfB.js} +2 -2
  4. package/dist/{ArweaveClient-D1TsTBoj.js.map → ArweaveClient-HEIIuOfB.js.map} +1 -1
  5. package/dist/{Db-quJxmvHH.js → Db-Bh_lvrAN.js} +6 -3
  6. package/dist/Db-Bh_lvrAN.js.map +1 -0
  7. package/dist/{Db-DMJ0v3gO.js → Db-DqBP6XK2.js} +3 -3
  8. package/dist/{Db-DMJ0v3gO.js.map → Db-DqBP6XK2.js.map} +1 -1
  9. package/dist/{EasClient-ClZDuT3o.js → EasClient-D3wKgt0o.js} +2 -2
  10. package/dist/{EasClient-DfnGY_2X.js.map → EasClient-D3wKgt0o.js.map} +1 -1
  11. package/dist/{EasClient-DfnGY_2X.js → EasClient-jqkT2ZBt.js} +2 -2
  12. package/dist/{EasClient-ClZDuT3o.js.map → EasClient-jqkT2ZBt.js.map} +1 -1
  13. package/dist/{FileManager-texI7UwL.js → FileManager-4mWYO3Mt.js} +3 -5
  14. package/dist/FileManager-4mWYO3Mt.js.map +1 -0
  15. package/dist/{Item-D4n439Ei.js → Item-COP3FuaU.js} +3 -3
  16. package/dist/{Item-D4n439Ei.js.map → Item-COP3FuaU.js.map} +1 -1
  17. package/dist/{ItemProperty-Be5ymRVT.js → ItemProperty-BFn9wM65.js} +3 -3
  18. package/dist/{ItemProperty-Be5ymRVT.js.map → ItemProperty-BFn9wM65.js.map} +1 -1
  19. package/dist/{QueryClient-B1HkAaJo.js → QueryClient-CBOP3OoU.js} +2 -2
  20. package/dist/{QueryClient-B1HkAaJo.js.map → QueryClient-CBOP3OoU.js.map} +1 -1
  21. package/dist/{QueryClient-BPoc9eBn.js → QueryClient-bKb3SB0W.js} +2 -2
  22. package/dist/{QueryClient-BPoc9eBn.js.map → QueryClient-bKb3SB0W.js.map} +1 -1
  23. package/dist/bin.js +5 -5
  24. package/dist/{constants-5PxfAeqj.js → constants-CIDbABDz.js} +2 -2
  25. package/dist/{constants-5PxfAeqj.js.map → constants-CIDbABDz.js.map} +1 -1
  26. package/dist/{index-BLla2o05.js → index-C4xqqsLw.js} +3 -3
  27. package/dist/index-C4xqqsLw.js.map +1 -0
  28. package/dist/{index-BeKRizLf.js → index-CLvyWg5f.js} +257 -145
  29. package/dist/index-CLvyWg5f.js.map +1 -0
  30. package/dist/main.js +2 -2
  31. package/dist/package.json +189 -0
  32. package/dist/{seed.schema.config-CMpV_hyS.js → seed.schema.config-Bao3o6wu.js} +3 -3
  33. package/dist/{seed.schema.config-CMpV_hyS.js.map → seed.schema.config-Bao3o6wu.js.map} +1 -1
  34. package/dist/types/src/client/BaseClientManager.d.ts +7 -0
  35. package/dist/types/src/client/BaseClientManager.d.ts.map +1 -0
  36. package/dist/types/src/client/actions/setAddresses.d.ts +2 -0
  37. package/dist/types/src/client/actions/setAddresses.d.ts.map +1 -0
  38. package/dist/types/src/client/actors/initialize.d.ts +4 -0
  39. package/dist/types/src/client/actors/initialize.d.ts.map +1 -0
  40. package/dist/types/src/client/actors/saveAppState.d.ts +5 -0
  41. package/dist/types/src/client/actors/saveAppState.d.ts.map +1 -0
  42. package/dist/types/src/client/clientManagerMachine.d.ts +19 -0
  43. package/dist/types/src/client/clientManagerMachine.d.ts.map +1 -0
  44. package/dist/types/src/client/index.d.ts +41 -0
  45. package/dist/types/src/client/index.d.ts.map +1 -0
  46. package/dist/types/src/client.d.ts.map +1 -1
  47. package/dist/types/src/node/db/Db.d.ts.map +1 -1
  48. package/dist/types/src/node/helpers/FileManager.d.ts.map +1 -1
  49. package/dist/types/src/services/internal/actors/validateInput.d.ts.map +1 -1
  50. package/dist/types/src/types/machines.d.ts +5 -0
  51. package/dist/types/src/types/machines.d.ts.map +1 -1
  52. package/package.json +2 -2
  53. package/dist/Db-quJxmvHH.js.map +0 -1
  54. package/dist/FileManager-texI7UwL.js.map +0 -1
  55. package/dist/index-BLla2o05.js.map +0 -1
  56. package/dist/index-BeKRizLf.js.map +0 -1
  57. package/dist/src/AppStateSchema.ts +0 -10
  58. package/dist/src/ArweaveClient.ts +0 -13
  59. package/dist/src/Attestation.ts +0 -21
  60. package/dist/src/BaseArweaveClient.ts +0 -13
  61. package/dist/src/BaseDb.ts +0 -35
  62. package/dist/src/BaseEasClient.ts +0 -13
  63. package/dist/src/BaseFileManager.ts +0 -56
  64. package/dist/src/BaseItem.ts +0 -413
  65. package/dist/src/BaseItemProperty.ts +0 -416
  66. package/dist/src/BaseQueryClient.ts +0 -13
  67. package/dist/src/ConfigSchema.ts +0 -15
  68. package/dist/src/Db.ts +0 -78
  69. package/dist/src/EasClient.ts +0 -13
  70. package/dist/src/FileDownloader.ts +0 -63
  71. package/dist/src/FileManager.ts +0 -57
  72. package/dist/src/IDb.ts +0 -7
  73. package/dist/src/IEasClient.ts +0 -2
  74. package/dist/src/IItem.ts +0 -26
  75. package/dist/src/IItemProperty.ts +0 -28
  76. package/dist/src/IQueryClient.ts +0 -4
  77. package/dist/src/ImageResizer.ts +0 -81
  78. package/dist/src/Item.ts +0 -12
  79. package/dist/src/ItemProperty.ts +0 -9
  80. package/dist/src/MetadataSchema.ts +0 -28
  81. package/dist/src/ModelSchema.ts +0 -46
  82. package/dist/src/ModelUidSchema.ts +0 -16
  83. package/dist/src/PropertyUidSchema.ts +0 -16
  84. package/dist/src/QueryClient.ts +0 -22
  85. package/dist/src/Schema.ts +0 -17
  86. package/dist/src/SeedProtocolSdk.d.ts +0 -19
  87. package/dist/src/SeedSchema.ts +0 -29
  88. package/dist/src/VersionSchema.ts +0 -16
  89. package/dist/src/actors.ts +0 -295
  90. package/dist/src/addModelsToDb.ts +0 -152
  91. package/dist/src/allItems.ts +0 -31
  92. package/dist/src/analyzeInput.ts +0 -144
  93. package/dist/src/browser.app.db.config.ts +0 -27
  94. package/dist/src/browser.ts +0 -30
  95. package/dist/src/checkStatus.ts +0 -50
  96. package/dist/src/client.ts +0 -148
  97. package/dist/src/configureFs.ts +0 -94
  98. package/dist/src/connectToDb.ts +0 -41
  99. package/dist/src/connectionManager.ts +0 -67
  100. package/dist/src/constants.ts +0 -125
  101. package/dist/src/content-hash.ts +0 -30
  102. package/dist/src/create.ts +0 -39
  103. package/dist/src/createMetadata.ts +0 -77
  104. package/dist/src/createNewItem.ts +0 -61
  105. package/dist/src/createPublishAttempt.ts +0 -16
  106. package/dist/src/createSeed.ts +0 -31
  107. package/dist/src/createSeeds.ts +0 -24
  108. package/dist/src/createVersion.ts +0 -33
  109. package/dist/src/dbMachine.ts +0 -182
  110. package/dist/src/deleteItem.ts +0 -19
  111. package/dist/src/download.ts +0 -202
  112. package/dist/src/drizzle.ts +0 -78
  113. package/dist/src/eas.ts +0 -40
  114. package/dist/src/environment.ts +0 -35
  115. package/dist/src/eventBus.ts +0 -5
  116. package/dist/src/events.ts +0 -14
  117. package/dist/src/fetchDataFromEas.ts +0 -94
  118. package/dist/src/fetchDbData.ts +0 -19
  119. package/dist/src/fetchRelatedItems.ts +0 -184
  120. package/dist/src/fetchSeeds.ts +0 -52
  121. package/dist/src/fetchVersions.ts +0 -49
  122. package/dist/src/files.ts +0 -81
  123. package/dist/src/filesDownload.ts +0 -326
  124. package/dist/src/fragment-masking.ts +0 -87
  125. package/dist/src/getExistingItem.ts +0 -60
  126. package/dist/src/getItem.ts +0 -32
  127. package/dist/src/getItemData.ts +0 -99
  128. package/dist/src/getItemProperties.ts +0 -56
  129. package/dist/src/getItemProperty.ts +0 -34
  130. package/dist/src/getItems.ts +0 -70
  131. package/dist/src/getMetadata.ts +0 -40
  132. package/dist/src/getModelSchemas.ts +0 -89
  133. package/dist/src/getPropertyData.ts +0 -50
  134. package/dist/src/getPublishPayload.ts +0 -355
  135. package/dist/src/getPublishUploads.ts +0 -207
  136. package/dist/src/getRelationValueData.ts +0 -27
  137. package/dist/src/getSchemaForItemProperty.ts +0 -68
  138. package/dist/src/getSchemaForModel.ts +0 -42
  139. package/dist/src/getSchemaUidForModel.ts +0 -32
  140. package/dist/src/getSeedData.ts +0 -34
  141. package/dist/src/getSegmentedItemProperties.ts +0 -65
  142. package/dist/src/getStorageTransactionIdForSeedUid.ts +0 -38
  143. package/dist/src/getVersionData.ts +0 -46
  144. package/dist/src/getVersionsForVersionUids.ts +0 -39
  145. package/dist/src/globalMachine.ts +0 -280
  146. package/dist/src/gql.ts +0 -118
  147. package/dist/src/graphql.ts +0 -3209
  148. package/dist/src/helpers.ts +0 -273
  149. package/dist/src/hydrateExistingItem.ts +0 -137
  150. package/dist/src/hydrateFromDb.ts +0 -270
  151. package/dist/src/hydrateNewItem.ts +0 -34
  152. package/dist/src/imageResize.ts +0 -507
  153. package/dist/src/index.d.ts +0 -5
  154. package/dist/src/index.ts +0 -4
  155. package/dist/src/initialize.ts +0 -124
  156. package/dist/src/internalMachine.ts +0 -238
  157. package/dist/src/itemMachineAll.ts +0 -157
  158. package/dist/src/itemMachineSingle.ts +0 -158
  159. package/dist/src/loadAppDb.ts +0 -47
  160. package/dist/src/machines.ts +0 -60
  161. package/dist/src/metadataLatest.ts +0 -34
  162. package/dist/src/migrate.ts +0 -53
  163. package/dist/src/model.ts +0 -72
  164. package/dist/src/modelClass.ts +0 -19
  165. package/dist/src/node.app.db.config.ts +0 -41
  166. package/dist/src/prepareDb.ts +0 -29
  167. package/dist/src/preparePublishRequestData.ts +0 -81
  168. package/dist/src/processItems.ts +0 -74
  169. package/dist/src/property.ts +0 -156
  170. package/dist/src/propertyMachine.ts +0 -202
  171. package/dist/src/publish.ts +0 -28
  172. package/dist/src/publishMachine.ts +0 -77
  173. package/dist/src/queries.ts +0 -13
  174. package/dist/src/recoverDeletedItem.ts +0 -14
  175. package/dist/src/reload.ts +0 -33
  176. package/dist/src/request.ts +0 -45
  177. package/dist/src/requestAll.ts +0 -157
  178. package/dist/src/resolveRelatedValue.ts +0 -367
  179. package/dist/src/resolveRemoteStorage.ts +0 -88
  180. package/dist/src/saveAppState.ts +0 -19
  181. package/dist/src/saveConfig.ts +0 -88
  182. package/dist/src/saveDataToDb.ts +0 -145
  183. package/dist/src/saveImageSrc.ts +0 -242
  184. package/dist/src/saveItemStorage.ts +0 -156
  185. package/dist/src/saveMetadata.ts +0 -18
  186. package/dist/src/savePublishService.ts +0 -30
  187. package/dist/src/saveRelation.ts +0 -112
  188. package/dist/src/seed.schema.config.ts +0 -25
  189. package/dist/src/seed.ts +0 -10
  190. package/dist/src/seedProtocol.ts +0 -17
  191. package/dist/src/services.ts +0 -365
  192. package/dist/src/sqlWasmClient.ts +0 -88
  193. package/dist/src/syncDbWithEas.ts +0 -628
  194. package/dist/src/trash.ts +0 -29
  195. package/dist/src/ts-to-proto.ts +0 -101
  196. package/dist/src/types.ts +0 -12
  197. package/dist/src/updateItemPropertyValue.ts +0 -243
  198. package/dist/src/updateMachineContext.ts +0 -21
  199. package/dist/src/updateMetadata.ts +0 -59
  200. package/dist/src/upload.ts +0 -86
  201. package/dist/src/validate.ts +0 -45
  202. package/dist/src/validateInput.ts +0 -47
  203. package/dist/src/validateItemData.ts +0 -20
  204. package/dist/src/versionData.ts +0 -24
  205. package/dist/src/waitForDb.ts +0 -25
  206. package/dist/src/waitForFiles.ts +0 -34
  207. package/dist/src/wasm.d.ts +0 -8300
@@ -1,242 +0,0 @@
1
- import { EventObject, fromCallback } from 'xstate'
2
- import { FromCallbackInput } from '@/types/machines'
3
- import {
4
- ItemPropertyValueType,
5
- PropertyMachineContext,
6
- SaveValueToDbEvent,
7
- } from '@/types/property'
8
- import { createSeed } from '@/db/write/createSeed'
9
- import { getDataTypeFromString, getMimeType } from '@/helpers'
10
- import { createVersion } from '@/db/write/createVersion'
11
- import fs from '@zenfs/core'
12
- import { createMetadata } from '@/db/write/createMetadata'
13
- import { updateItemPropertyValue } from '@/db/write/updateItemPropertyValue'
14
- import { getSchemaUidForSchemaDefinition } from '@/stores/eas'
15
- import { getSchemaUidForModel } from '@/db/read/getSchemaUidForModel'
16
- import { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'
17
- import { eventEmitter } from '@/eventBus'
18
- import { ImageSize } from '@/helpers/constants'
19
-
20
-
21
-
22
- const readFileAsArrayBuffer = async (file: File): Promise<ArrayBuffer> => {
23
- return new Promise((resolve) => {
24
- const reader = new FileReader()
25
- reader.onload = async (e) => {
26
- const arrayBuffer = e.target.result as ArrayBuffer
27
-
28
- resolve(arrayBuffer)
29
- }
30
-
31
- reader.readAsArrayBuffer(file)
32
- })
33
- }
34
-
35
- const fetchImage = async (url: string) => {
36
- const response = await fetch(url)
37
- const mimeType = response.headers.get('Content-Type')
38
- const imageBuffer = await response.arrayBuffer()
39
- const bytes = new Uint8Array(imageBuffer)
40
-
41
- const binaryString = bytes.reduce(
42
- (acc, byte) => acc + String.fromCharCode(byte),
43
- '',
44
- )
45
-
46
- let base64 = btoa(binaryString)
47
-
48
- if (mimeType) {
49
- base64 = `data:${mimeType};base64,${base64}`
50
- }
51
-
52
- return base64
53
- }
54
-
55
- let imageSchemaUid: string | undefined
56
-
57
- export const saveImageSrc = fromCallback<
58
- EventObject,
59
- FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>
60
- >(({ sendBack, input: { context, event } }) => {
61
- const {
62
- localId,
63
- propertyName: propertyNameRaw,
64
- propertyValue: existingValue,
65
- propertyRecordSchema,
66
- modelName,
67
- seedLocalId,
68
- seedUid,
69
- versionLocalId,
70
- versionUid,
71
- } = context
72
-
73
- let { schemaUid } = context
74
-
75
- let newValue: ItemPropertyValueType
76
-
77
- if (event) {
78
- newValue = event.newValue
79
- }
80
-
81
- if (existingValue === newValue) {
82
- sendBack({ type: 'saveValueToDbSuccess' })
83
- return
84
- }
85
-
86
- const _saveImageSrc = async (): Promise<void> => {
87
- let propertyName = propertyNameRaw
88
-
89
- if (!propertyNameRaw.endsWith('Id')) {
90
- propertyName = `${propertyName}Id`
91
- }
92
-
93
- let newValueType
94
- let fileData: string | ArrayBuffer | undefined
95
- let mimeType
96
- let fileName
97
-
98
- if (!imageSchemaUid) {
99
- imageSchemaUid = await getSchemaUidForModel('Image')
100
- }
101
-
102
- if (typeof newValue === 'string') {
103
- newValueType = getDataTypeFromString(newValue)
104
- }
105
-
106
- if (newValueType === 'imageBase64') {
107
- mimeType = getMimeType(newValue as string)
108
- const base64Data = (newValue as string).split(',')[1] // Strip the Base64 prefix
109
- const binaryString = atob(base64Data)
110
-
111
- const binaryLength = binaryString.length
112
- const binaryArray = new Uint8Array(binaryLength)
113
- for (let i = 0; i < binaryLength; i++) {
114
- binaryArray[i] = binaryString.charCodeAt(i)
115
- }
116
- fileData = binaryArray.buffer
117
- }
118
-
119
- if (newValueType === 'url') {
120
- fileData = await fetchImage(newValue as string)
121
- }
122
-
123
- if (newValue instanceof File) {
124
- fileName = newValue.name
125
- mimeType = newValue.type
126
- fileData = await readFileAsArrayBuffer(newValue)
127
- }
128
-
129
- if (!fileData) {
130
- throw new Error('No file data found')
131
- }
132
-
133
- const newImageSeedLocalId = await createSeed({
134
- type: 'image',
135
- })
136
-
137
- if (!fileName) {
138
- fileName = newImageSeedLocalId
139
- if (mimeType) {
140
- fileName += `.${mimeType.split('/')[1]}`
141
- }
142
- }
143
-
144
- const filePath = `/files/images/${fileName}`
145
-
146
- const imageVersionLocalId = await createVersion({
147
- seedLocalId: newImageSeedLocalId,
148
- seedType: 'image',
149
- })
150
-
151
- if (fileData instanceof ArrayBuffer) {
152
- try {
153
- await BaseFileManager.saveFile(filePath, new Uint8Array(fileData))
154
- } catch (e) {
155
- fs.writeFileSync(filePath, new Uint8Array(fileData))
156
- eventEmitter.emit('file-saved', filePath)
157
- }
158
- }
159
-
160
- if (typeof fileData === 'string') {
161
- try {
162
- await BaseFileManager.saveFile(filePath, fileData)
163
- } catch (e) {
164
- fs.writeFileSync(filePath, fileData)
165
- eventEmitter.emit('file-saved', filePath)
166
- }
167
- }
168
-
169
-
170
- await BaseFileManager.resizeImage({filePath, width: ImageSize.EXTRA_SMALL, height: ImageSize.EXTRA_SMALL})
171
- await BaseFileManager.resizeImage({filePath, width: ImageSize.SMALL, height: ImageSize.SMALL})
172
- await BaseFileManager.resizeImage({filePath, width: ImageSize.MEDIUM, height: ImageSize.MEDIUM})
173
- await BaseFileManager.resizeImage({filePath, width: ImageSize.LARGE, height: ImageSize.LARGE})
174
- await BaseFileManager.resizeImage({filePath, width: ImageSize.EXTRA_LARGE, height: ImageSize.EXTRA_LARGE})
175
-
176
- const refResolvedDisplayValue = await BaseFileManager.getContentUrlFromPath(filePath)
177
-
178
- let newLocalId
179
-
180
- if (!localId) {
181
- const result = await createMetadata(
182
- {
183
- propertyName,
184
- propertyValue: newImageSeedLocalId,
185
- seedLocalId,
186
- seedUid,
187
- versionLocalId,
188
- versionUid,
189
- modelName,
190
- schemaUid,
191
- refSeedType: 'image',
192
- refModelUid: imageSchemaUid,
193
- refSchemaUid: imageSchemaUid,
194
- refResolvedDisplayValue,
195
- refResolvedValue: fileName,
196
- localStorageDir: '/images',
197
- easDataType: 'bytes32',
198
- },
199
- propertyRecordSchema,
200
- )
201
-
202
- newLocalId = result[0].localId
203
- }
204
-
205
- if (localId) {
206
- await updateItemPropertyValue({
207
- localId: localId,
208
- propertyName: propertyNameRaw,
209
- newValue: newImageSeedLocalId,
210
- seedLocalId,
211
- versionLocalId,
212
- modelName,
213
- schemaUid,
214
- refSeedType: 'image',
215
- refResolvedDisplayValue,
216
- refResolvedValue: fileName,
217
- refModelUid: imageSchemaUid,
218
- refSchemaUid: imageSchemaUid,
219
- localStorageDir: '/images',
220
- easDataType: 'bytes32',
221
- })
222
- }
223
-
224
- sendBack({
225
- type: 'updateContext',
226
- localId: newLocalId || localId,
227
- propertyValue: newImageSeedLocalId,
228
- refSeedType: 'image',
229
- refSchemaUid: imageSchemaUid,
230
- renderValue: refResolvedDisplayValue,
231
- refResolvedDisplayValue,
232
- refResolvedValue: fileName,
233
- localStorageDir: '/images',
234
- easDataType: 'bytes32',
235
- schemaUid,
236
- })
237
- }
238
-
239
- _saveImageSrc().then(() => {
240
- sendBack({ type: 'saveImageSrcSuccess' })
241
- })
242
- })
@@ -1,156 +0,0 @@
1
- import { EventObject, fromCallback } from 'xstate'
2
- import { FromCallbackInput } from '@/types/machines'
3
- import {
4
- ItemPropertyValueType,
5
- PropertyMachineContext,
6
- SaveValueToDbEvent,
7
- } from '@/types/property'
8
- import { BaseDb } from '@/db/Db/BaseDb'
9
- import { getItemPropertyData } from '@/db/read/getItemProperty'
10
- import { getItemData } from '@/db/read/getItemData'
11
- import { and, eq } from 'drizzle-orm'
12
- import { metadata } from '@/seedSchema'
13
- import { createMetadata } from '@/db/write/createMetadata'
14
- import fs from '@zenfs/core'
15
- import { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'
16
-
17
- export const saveItemStorage = fromCallback<
18
- EventObject,
19
- FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>
20
- >(({ sendBack, input: { context, event } }) => {
21
- const {
22
- localId,
23
- seedLocalId,
24
- seedUid,
25
- propertyName,
26
- propertyRecordSchema,
27
- modelName,
28
- propertyValue: existingValue,
29
- } = context
30
-
31
- if (!propertyRecordSchema) {
32
- throw new Error('Missing propertyRecordSchema')
33
- }
34
-
35
- let newValue: ItemPropertyValueType
36
-
37
- if (event) {
38
- newValue = event.newValue
39
- }
40
-
41
- if (existingValue === newValue) {
42
- sendBack({ type: 'saveValueToDbSuccess' })
43
- return
44
- }
45
-
46
- const _saveItemStorage = async (): Promise<boolean> => {
47
- // Save value to file
48
- const appDb = BaseDb.getAppDb()
49
- let propertyData
50
-
51
- if (localId) {
52
- propertyData = await getItemPropertyData({
53
- localId,
54
- })
55
- }
56
-
57
- if (!localId && seedLocalId) {
58
- const itemData = await getItemData({
59
- seedLocalId,
60
- })
61
- if (itemData) {
62
- const whereClauses = [
63
- eq(metadata.propertyName, propertyName),
64
- eq(metadata.seedLocalId, seedLocalId),
65
- ]
66
-
67
- if (itemData.latestVersionLocalId) {
68
- whereClauses.push(
69
- eq(metadata.versionLocalId, itemData.latestVersionLocalId),
70
- )
71
- }
72
-
73
- const queryRows = await appDb
74
- .select()
75
- .from(metadata)
76
- .where(and(...whereClauses))
77
-
78
- if (queryRows && queryRows.length) {
79
- propertyData = queryRows[0]
80
- }
81
-
82
- if (!propertyData && newValue) {
83
-
84
- const filename = `${seedUid || seedLocalId}${propertyRecordSchema.filenameSuffix}`
85
- const writeToPath = `/files/${propertyRecordSchema.localStorageDir}/${filename}`
86
- await BaseFileManager.saveFile(writeToPath, newValue as string | Blob | ArrayBuffer)
87
-
88
- const propertyDataRows = await createMetadata(
89
- {
90
- propertyName,
91
- propertyValue: filename,
92
- modelType: modelName.toLowerCase(),
93
- seedLocalId,
94
- seedUid,
95
- versionLocalId: itemData.latestVersionLocalId,
96
- versionUid: itemData.latestVersionUid,
97
- localStorageDir: propertyRecordSchema.localStorageDir,
98
- refValueType: 'file',
99
- },
100
- propertyRecordSchema,
101
- )
102
-
103
- propertyData = propertyDataRows[0]
104
- }
105
-
106
- // propertyData = {
107
- // propertyName,
108
- // seedLocalId,
109
- // seedUid,
110
- // versionLocalId: itemData.latestVersionLocalId,
111
- // versionUid: itemData.latestVersionUid,
112
- // schemaUid: itemData.schemaUid,
113
- // }
114
- }
115
- }
116
-
117
- const localStorageDir =
118
- propertyRecordSchema.localStorageDir || propertyData.localStorageDir
119
- const fileName =
120
- propertyData.refResolvedValue ||
121
- `${propertyData.seedUid || propertyData.seedLocalId}${propertyRecordSchema.filenameSuffix}`
122
-
123
- if (!localStorageDir || !fileName) {
124
- throw new Error(
125
- `Missing localStorageDir: ${localStorageDir} or fileName: ${fileName}`,
126
- )
127
- }
128
-
129
- const filePath = `/files/${localStorageDir}/${fileName}`
130
- try {
131
- await BaseFileManager.saveFile(filePath, newValue as string | Blob | ArrayBuffer)
132
- } catch (error) {
133
- fs.writeFileSync(filePath, newValue)
134
- }
135
-
136
- await appDb
137
- .update(metadata)
138
- .set({
139
- refResolvedValue: fileName,
140
- })
141
- .where(eq(metadata.localId, propertyData.localId))
142
-
143
- sendBack({
144
- type: 'updateContext',
145
- renderValue: newValue,
146
- })
147
-
148
- return true
149
- }
150
-
151
- _saveItemStorage().then((success) => {
152
- if (success) {
153
- sendBack({ type: 'saveItemStorageSuccess' })
154
- }
155
- })
156
- })
@@ -1,18 +0,0 @@
1
- import { metadata, MetadataType } from '@/seedSchema'
2
- import { BaseDb } from '@/db/Db/BaseDb'
3
- import { eq } from 'drizzle-orm'
4
-
5
- export const saveMetadata = async (
6
- metadataRecord: Partial<MetadataType>,
7
- metadataValues: Partial<MetadataType>,
8
- ) => {
9
- const appDb = BaseDb.getAppDb()
10
-
11
- await appDb
12
- .update(metadata)
13
- .set({
14
- ...metadataValues,
15
- updatedAt: Date.now(),
16
- })
17
- .where(eq(metadata.localId, metadataRecord.localId))
18
- }
@@ -1,30 +0,0 @@
1
- import { EventObject, fromCallback } from 'xstate'
2
- import { FromCallbackInput, GlobalMachineContext } from '@/types/machines'
3
- import { saveAppState } from '@/db/write/saveAppState'
4
-
5
- export const savePublishService = fromCallback<
6
- EventObject,
7
- FromCallbackInput<GlobalMachineContext>
8
- >(({ sendBack, input: { event, context } }) => {
9
- const { publishItemService } = context
10
-
11
- if (!publishItemService) {
12
- sendBack({ type: 'savePublishServiceError' })
13
- return
14
- }
15
-
16
- const _savePublishService = async (): Promise<boolean> => {
17
- await saveAppState(
18
- `snapshot__publishItemService`,
19
- JSON.stringify(publishItemService.getPersistedSnapshot()),
20
- )
21
-
22
- return true
23
- }
24
-
25
- _savePublishService().then((success) => {
26
- if (success) {
27
- sendBack({ type: 'savePublishServiceSuccess' })
28
- }
29
- })
30
- })
@@ -1,112 +0,0 @@
1
- import { EventObject, fromCallback } from 'xstate'
2
- import { FromCallbackInput } from '@/types/machines'
3
- import {
4
- ItemPropertyValueType,
5
- PropertyMachineContext,
6
- SaveValueToDbEvent,
7
- } from '@/types/property'
8
- import { getDataTypeFromString } from '@/helpers'
9
-
10
- export const saveRelation = fromCallback<
11
- EventObject,
12
- FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>
13
- >(({ sendBack, input: { context, event } }) => {
14
- const {
15
- localId,
16
- propertyName: propertyNameRaw,
17
- versionLocalId,
18
- seedUid,
19
- seedLocalId,
20
- propertyValue: existingValue,
21
- propertyRecordSchema,
22
- } = context
23
-
24
- if (!propertyRecordSchema) {
25
- throw new Error('Missing propertyRecordSchema')
26
- }
27
-
28
- let newValue: ItemPropertyValueType
29
-
30
- if (event) {
31
- newValue = event.newValue
32
- }
33
-
34
- const _saveRelation = async (): Promise<boolean> => {
35
- let refResolvedDisplayValue
36
- let refSeedType
37
- let propertyName = propertyNameRaw
38
- let versionLocalIdToSave = versionLocalId
39
-
40
- const refResolvedValue = newValue
41
-
42
- if (!propertyName.endsWith('Id')) {
43
- propertyName = `${propertyName}Id`
44
- }
45
-
46
- let newValueType
47
-
48
- if (typeof newValue === 'string') {
49
- newValueType = getDataTypeFromString(newValue)
50
- }
51
-
52
- if (newValue instanceof File) {
53
- newValueType = 'file'
54
- }
55
-
56
- if (propertyRecordSchema.dataType === 'ImageSrc') {
57
- sendBack({
58
- type: 'saveImageSrc',
59
- newValue,
60
- newValueType,
61
- })
62
- return false
63
- }
64
-
65
- return true
66
-
67
- // let fileType
68
- //
69
- // const dirs = await fs.promises.readdir('/files')
70
- //
71
- // for (const dir of dirs) {
72
- // const files = await fs.promises.readdir(`/files/${dir}`)
73
- // if (newValue && files.includes(newValue as string)) {
74
- // fileType = dir
75
- // break
76
- // }
77
- // }
78
- //
79
- // if (newValue && fileType === 'images') {
80
- // const filePath = `/files/images/${newValue}`
81
- // refResolvedDisplayValue = await getContentUrlFromPath(filePath)
82
- // refSeedType = 'image'
83
- // newValue = await createSeed({
84
- // type: refSeedType,
85
- // })
86
- // await createVersion({
87
- // seedLocalId,
88
- // seedUid,
89
- // seedType: refSeedType,
90
- // })
91
- // }
92
- //
93
- // await updateItemPropertyValue({
94
- // propertyLocalId: localId,
95
- // propertyName,
96
- // newValue,
97
- // seedLocalId,
98
- // refSeedType,
99
- // refResolvedValue,
100
- // refResolvedDisplayValue,
101
- // versionLocalId,
102
- // modelName: itemModelName,
103
- // schemaUid,
104
- // })
105
- }
106
-
107
- _saveRelation().then((isDone) => {
108
- if (isDone) {
109
- sendBack({ type: 'saveRelationSuccess' })
110
- }
111
- })
112
- })
@@ -1,25 +0,0 @@
1
- import { Model, Text } from '@/schema'
2
-
3
- @Model
4
- class Seed {
5
- @Text() uid!: string
6
- @Text() type!: string
7
- }
8
-
9
- @Model
10
- class Version {
11
- @Text() seedUid!: string
12
- @Text() note!: string
13
- }
14
-
15
- @Model
16
- class Metadata {
17
- @Text() key!: string
18
- @Text() value!: string
19
- }
20
-
21
- export const models = {
22
- Seed,
23
- Version,
24
- Metadata,
25
- }
package/dist/src/seed.ts DELETED
@@ -1,10 +0,0 @@
1
- import { SeedConstructorOptions } from '@/types/types'
2
- import { SeedBase } from '@/shared/seed'
3
-
4
- class SeedNode extends SeedBase {
5
- constructor(props: SeedConstructorOptions) {
6
- super(props)
7
- }
8
- }
9
-
10
- export { SeedNode }
@@ -1,17 +0,0 @@
1
- import { Attestation } from '@/graphql/gql/graphql'
2
-
3
- export type PropertyToUpdateWithSeed = {
4
- publishLocalId: string
5
- propertySchemaUid: string
6
- }
7
-
8
- export type PublishRequestData = {
9
- localId: string
10
- seedIsRevocable: boolean
11
- seedSchemaUid: string
12
- seedUid?: string
13
- versionSchemaUid: string
14
- versionUid?: string
15
- propertiesToUpdate: PropertyToUpdateWithSeed[]
16
- listOfAttestations: Attestation[]
17
- }