@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,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 fs.promises.writeFile(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 fs.promises.writeFile(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,155 +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
-
16
- export const saveItemStorage = fromCallback<
17
- EventObject,
18
- FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>
19
- >(({ sendBack, input: { context, event } }) => {
20
- const {
21
- localId,
22
- seedLocalId,
23
- seedUid,
24
- propertyName,
25
- propertyRecordSchema,
26
- modelName,
27
- propertyValue: existingValue,
28
- } = context
29
-
30
- if (!propertyRecordSchema) {
31
- throw new Error('Missing propertyRecordSchema')
32
- }
33
-
34
- let newValue: ItemPropertyValueType
35
-
36
- if (event) {
37
- newValue = event.newValue
38
- }
39
-
40
- if (existingValue === newValue) {
41
- sendBack({ type: 'saveValueToDbSuccess' })
42
- return
43
- }
44
-
45
- const _saveItemStorage = async (): Promise<boolean> => {
46
- // Save value to file
47
- const appDb = BaseDb.getAppDb()
48
- let propertyData
49
-
50
- if (localId) {
51
- propertyData = await getItemPropertyData({
52
- localId,
53
- })
54
- }
55
-
56
- if (!localId && seedLocalId) {
57
- const itemData = await getItemData({
58
- seedLocalId,
59
- })
60
- if (itemData) {
61
- const whereClauses = [
62
- eq(metadata.propertyName, propertyName),
63
- eq(metadata.seedLocalId, seedLocalId),
64
- ]
65
-
66
- if (itemData.latestVersionLocalId) {
67
- whereClauses.push(
68
- eq(metadata.versionLocalId, itemData.latestVersionLocalId),
69
- )
70
- }
71
-
72
- const queryRows = await appDb
73
- .select()
74
- .from(metadata)
75
- .where(and(...whereClauses))
76
-
77
- if (queryRows && queryRows.length) {
78
- propertyData = queryRows[0]
79
- }
80
-
81
- if (!propertyData && newValue) {
82
-
83
- const filename = `${seedUid || seedLocalId}${propertyRecordSchema.filenameSuffix}`
84
- const writeToPath = `/files/${propertyRecordSchema.localStorageDir}/${filename}`
85
- await fs.promises.writeFile(writeToPath, newValue as string)
86
-
87
- const propertyDataRows = await createMetadata(
88
- {
89
- propertyName,
90
- propertyValue: filename,
91
- modelType: modelName.toLowerCase(),
92
- seedLocalId,
93
- seedUid,
94
- versionLocalId: itemData.latestVersionLocalId,
95
- versionUid: itemData.latestVersionUid,
96
- localStorageDir: propertyRecordSchema.localStorageDir,
97
- refValueType: 'file',
98
- },
99
- propertyRecordSchema,
100
- )
101
-
102
- propertyData = propertyDataRows[0]
103
- }
104
-
105
- // propertyData = {
106
- // propertyName,
107
- // seedLocalId,
108
- // seedUid,
109
- // versionLocalId: itemData.latestVersionLocalId,
110
- // versionUid: itemData.latestVersionUid,
111
- // schemaUid: itemData.schemaUid,
112
- // }
113
- }
114
- }
115
-
116
- const localStorageDir =
117
- propertyRecordSchema.localStorageDir || propertyData.localStorageDir
118
- const fileName =
119
- propertyData.refResolvedValue ||
120
- `${propertyData.seedUid || propertyData.seedLocalId}${propertyRecordSchema.filenameSuffix}`
121
-
122
- if (!localStorageDir || !fileName) {
123
- throw new Error(
124
- `Missing localStorageDir: ${localStorageDir} or fileName: ${fileName}`,
125
- )
126
- }
127
-
128
- const filePath = `/files/${localStorageDir}/${fileName}`
129
- try {
130
- await fs.promises.writeFile(filePath, newValue)
131
- } catch (error) {
132
- fs.writeFileSync(filePath, newValue)
133
- }
134
-
135
- await appDb
136
- .update(metadata)
137
- .set({
138
- refResolvedValue: fileName,
139
- })
140
- .where(eq(metadata.localId, propertyData.localId))
141
-
142
- sendBack({
143
- type: 'updateContext',
144
- renderValue: newValue,
145
- })
146
-
147
- return true
148
- }
149
-
150
- _saveItemStorage().then((success) => {
151
- if (success) {
152
- sendBack({ type: 'saveItemStorageSuccess' })
153
- }
154
- })
155
- })
@@ -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
- }