@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.
- package/dist/{ArweaveClient-Dcqcpsq4.js → ArweaveClient-D5iJisYr.js} +2 -2
- package/dist/{ArweaveClient-Dcqcpsq4.js.map → ArweaveClient-D5iJisYr.js.map} +1 -1
- package/dist/{ArweaveClient-Dh7LRIqD.js → ArweaveClient-HEIIuOfB.js} +2 -2
- package/dist/{ArweaveClient-Dh7LRIqD.js.map → ArweaveClient-HEIIuOfB.js.map} +1 -1
- package/dist/{Db-jJH2s0gO.js → Db-D-BsZYlN.js} +3 -3
- package/dist/{Db-jJH2s0gO.js.map → Db-D-BsZYlN.js.map} +1 -1
- package/dist/{Db-BwkMqaQe.js → Db-Dpsbk_T7.js} +3 -3
- package/dist/{Db-BwkMqaQe.js.map → Db-Dpsbk_T7.js.map} +1 -1
- package/dist/{EasClient-A1xC7Gm-.js → EasClient-D3wKgt0o.js} +2 -2
- package/dist/{EasClient-m2mXad59.js.map → EasClient-D3wKgt0o.js.map} +1 -1
- package/dist/{EasClient-m2mXad59.js → EasClient-jqkT2ZBt.js} +2 -2
- package/dist/{EasClient-A1xC7Gm-.js.map → EasClient-jqkT2ZBt.js.map} +1 -1
- package/dist/{FileManager-Dv2zn1RW.js → FileManager-4mWYO3Mt.js} +3 -5
- package/dist/FileManager-4mWYO3Mt.js.map +1 -0
- package/dist/{Item-DI3FxVPV.js → Item-CqWdJsyg.js} +3 -3
- package/dist/{Item-DI3FxVPV.js.map → Item-CqWdJsyg.js.map} +1 -1
- package/dist/{ItemProperty-CxNUwVnR.js → ItemProperty-BpBW3IWx.js} +3 -3
- package/dist/{ItemProperty-CxNUwVnR.js.map → ItemProperty-BpBW3IWx.js.map} +1 -1
- package/dist/{QueryClient-C-hFMF2j.js → QueryClient-CBOP3OoU.js} +2 -2
- package/dist/{QueryClient-C-hFMF2j.js.map → QueryClient-CBOP3OoU.js.map} +1 -1
- package/dist/{QueryClient-C02sPZ-K.js → QueryClient-bKb3SB0W.js} +2 -2
- package/dist/{QueryClient-C02sPZ-K.js.map → QueryClient-bKb3SB0W.js.map} +1 -1
- package/dist/bin.js +5 -5
- package/dist/{constants-C03RQQht.js → constants-CIDbABDz.js} +5 -2
- package/dist/constants-CIDbABDz.js.map +1 -0
- package/dist/{index-CKrLHw3B.js → index-BRxO1tLl.js} +300 -149
- package/dist/index-BRxO1tLl.js.map +1 -0
- package/dist/{index-Dv8GeuSw.js → index-d8Qsot6w.js} +3 -3
- package/dist/index-d8Qsot6w.js.map +1 -0
- package/dist/main.js +2 -2
- package/dist/package.json +189 -0
- package/dist/{seed.schema.config-1s-iWHq_.js → seed.schema.config-CPRn6KVL.js} +3 -3
- package/dist/{seed.schema.config-1s-iWHq_.js.map → seed.schema.config-CPRn6KVL.js.map} +1 -1
- package/dist/types/src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
- package/dist/types/src/browser/helpers/FileManager.d.ts +1 -0
- package/dist/types/src/browser/helpers/FileManager.d.ts.map +1 -1
- package/dist/types/src/client/BaseClientManager.d.ts +7 -0
- package/dist/types/src/client/BaseClientManager.d.ts.map +1 -0
- package/dist/types/src/client/actions/setAddresses.d.ts +2 -0
- package/dist/types/src/client/actions/setAddresses.d.ts.map +1 -0
- package/dist/types/src/client/actors/initialize.d.ts +4 -0
- package/dist/types/src/client/actors/initialize.d.ts.map +1 -0
- package/dist/types/src/client/actors/saveAppState.d.ts +5 -0
- package/dist/types/src/client/actors/saveAppState.d.ts.map +1 -0
- package/dist/types/src/client/clientManagerMachine.d.ts +19 -0
- package/dist/types/src/client/clientManagerMachine.d.ts.map +1 -0
- package/dist/types/src/client/index.d.ts +41 -0
- package/dist/types/src/client/index.d.ts.map +1 -0
- package/dist/types/src/client.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.map +1 -1
- package/dist/types/src/services/internal/actors/validateInput.d.ts.map +1 -1
- package/dist/types/src/types/machines.d.ts +5 -0
- package/dist/types/src/types/machines.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/FileManager-Dv2zn1RW.js.map +0 -1
- package/dist/constants-C03RQQht.js.map +0 -1
- package/dist/index-CKrLHw3B.js.map +0 -1
- package/dist/index-Dv8GeuSw.js.map +0 -1
- package/dist/src/AppStateSchema.ts +0 -10
- package/dist/src/ArweaveClient.ts +0 -13
- package/dist/src/Attestation.ts +0 -21
- package/dist/src/BaseArweaveClient.ts +0 -13
- package/dist/src/BaseDb.ts +0 -35
- package/dist/src/BaseEasClient.ts +0 -13
- package/dist/src/BaseFileManager.ts +0 -52
- package/dist/src/BaseItem.ts +0 -413
- package/dist/src/BaseItemProperty.ts +0 -416
- package/dist/src/BaseQueryClient.ts +0 -13
- package/dist/src/ConfigSchema.ts +0 -15
- package/dist/src/Db.ts +0 -78
- package/dist/src/EasClient.ts +0 -13
- package/dist/src/FileDownloader.ts +0 -63
- package/dist/src/FileManager.ts +0 -57
- package/dist/src/IDb.ts +0 -7
- package/dist/src/IEasClient.ts +0 -2
- package/dist/src/IItem.ts +0 -26
- package/dist/src/IItemProperty.ts +0 -28
- package/dist/src/IQueryClient.ts +0 -4
- package/dist/src/ImageResizer.ts +0 -81
- package/dist/src/Item.ts +0 -12
- package/dist/src/ItemProperty.ts +0 -9
- package/dist/src/MetadataSchema.ts +0 -28
- package/dist/src/ModelSchema.ts +0 -46
- package/dist/src/ModelUidSchema.ts +0 -16
- package/dist/src/PropertyUidSchema.ts +0 -16
- package/dist/src/QueryClient.ts +0 -22
- package/dist/src/Schema.ts +0 -17
- package/dist/src/SeedProtocolSdk.d.ts +0 -19
- package/dist/src/SeedSchema.ts +0 -29
- package/dist/src/VersionSchema.ts +0 -16
- package/dist/src/actors.ts +0 -295
- package/dist/src/addModelsToDb.ts +0 -152
- package/dist/src/allItems.ts +0 -31
- package/dist/src/analyzeInput.ts +0 -144
- package/dist/src/browser.app.db.config.ts +0 -27
- package/dist/src/browser.ts +0 -30
- package/dist/src/checkStatus.ts +0 -50
- package/dist/src/client.ts +0 -148
- package/dist/src/configureFs.ts +0 -94
- package/dist/src/connectToDb.ts +0 -41
- package/dist/src/connectionManager.ts +0 -67
- package/dist/src/constants.ts +0 -125
- package/dist/src/content-hash.ts +0 -30
- package/dist/src/create.ts +0 -39
- package/dist/src/createMetadata.ts +0 -77
- package/dist/src/createNewItem.ts +0 -61
- package/dist/src/createPublishAttempt.ts +0 -16
- package/dist/src/createSeed.ts +0 -31
- package/dist/src/createSeeds.ts +0 -24
- package/dist/src/createVersion.ts +0 -33
- package/dist/src/dbMachine.ts +0 -182
- package/dist/src/deleteItem.ts +0 -19
- package/dist/src/download.ts +0 -202
- package/dist/src/drizzle.ts +0 -78
- package/dist/src/eas.ts +0 -40
- package/dist/src/environment.ts +0 -35
- package/dist/src/eventBus.ts +0 -5
- package/dist/src/events.ts +0 -14
- package/dist/src/fetchDataFromEas.ts +0 -94
- package/dist/src/fetchDbData.ts +0 -19
- package/dist/src/fetchRelatedItems.ts +0 -184
- package/dist/src/fetchSeeds.ts +0 -52
- package/dist/src/fetchVersions.ts +0 -49
- package/dist/src/files.ts +0 -81
- package/dist/src/filesDownload.ts +0 -326
- package/dist/src/fragment-masking.ts +0 -87
- package/dist/src/getExistingItem.ts +0 -60
- package/dist/src/getItem.ts +0 -32
- package/dist/src/getItemData.ts +0 -99
- package/dist/src/getItemProperties.ts +0 -56
- package/dist/src/getItemProperty.ts +0 -34
- package/dist/src/getItems.ts +0 -70
- package/dist/src/getMetadata.ts +0 -40
- package/dist/src/getModelSchemas.ts +0 -89
- package/dist/src/getPropertyData.ts +0 -50
- package/dist/src/getPublishPayload.ts +0 -355
- package/dist/src/getPublishUploads.ts +0 -207
- package/dist/src/getRelationValueData.ts +0 -27
- package/dist/src/getSchemaForItemProperty.ts +0 -68
- package/dist/src/getSchemaForModel.ts +0 -42
- package/dist/src/getSchemaUidForModel.ts +0 -32
- package/dist/src/getSeedData.ts +0 -34
- package/dist/src/getSegmentedItemProperties.ts +0 -65
- package/dist/src/getStorageTransactionIdForSeedUid.ts +0 -38
- package/dist/src/getVersionData.ts +0 -46
- package/dist/src/getVersionsForVersionUids.ts +0 -39
- package/dist/src/globalMachine.ts +0 -280
- package/dist/src/gql.ts +0 -118
- package/dist/src/graphql.ts +0 -3209
- package/dist/src/helpers.ts +0 -273
- package/dist/src/hydrateExistingItem.ts +0 -137
- package/dist/src/hydrateFromDb.ts +0 -270
- package/dist/src/hydrateNewItem.ts +0 -34
- package/dist/src/imageResize.ts +0 -507
- package/dist/src/index.d.ts +0 -5
- package/dist/src/index.ts +0 -4
- package/dist/src/initialize.ts +0 -124
- package/dist/src/internalMachine.ts +0 -238
- package/dist/src/itemMachineAll.ts +0 -157
- package/dist/src/itemMachineSingle.ts +0 -158
- package/dist/src/loadAppDb.ts +0 -47
- package/dist/src/machines.ts +0 -60
- package/dist/src/metadataLatest.ts +0 -34
- package/dist/src/migrate.ts +0 -53
- package/dist/src/model.ts +0 -72
- package/dist/src/modelClass.ts +0 -19
- package/dist/src/node.app.db.config.ts +0 -41
- package/dist/src/prepareDb.ts +0 -29
- package/dist/src/preparePublishRequestData.ts +0 -81
- package/dist/src/processItems.ts +0 -74
- package/dist/src/property.ts +0 -156
- package/dist/src/propertyMachine.ts +0 -202
- package/dist/src/publish.ts +0 -28
- package/dist/src/publishMachine.ts +0 -77
- package/dist/src/queries.ts +0 -13
- package/dist/src/recoverDeletedItem.ts +0 -14
- package/dist/src/reload.ts +0 -33
- package/dist/src/request.ts +0 -45
- package/dist/src/requestAll.ts +0 -157
- package/dist/src/resolveRelatedValue.ts +0 -367
- package/dist/src/resolveRemoteStorage.ts +0 -88
- package/dist/src/saveAppState.ts +0 -19
- package/dist/src/saveConfig.ts +0 -88
- package/dist/src/saveDataToDb.ts +0 -145
- package/dist/src/saveImageSrc.ts +0 -242
- package/dist/src/saveItemStorage.ts +0 -155
- package/dist/src/saveMetadata.ts +0 -18
- package/dist/src/savePublishService.ts +0 -30
- package/dist/src/saveRelation.ts +0 -112
- package/dist/src/seed.schema.config.ts +0 -25
- package/dist/src/seed.ts +0 -10
- package/dist/src/seedProtocol.ts +0 -17
- package/dist/src/services.ts +0 -365
- package/dist/src/sqlWasmClient.ts +0 -88
- package/dist/src/syncDbWithEas.ts +0 -628
- package/dist/src/trash.ts +0 -29
- package/dist/src/ts-to-proto.ts +0 -101
- package/dist/src/types.ts +0 -12
- package/dist/src/updateItemPropertyValue.ts +0 -243
- package/dist/src/updateMachineContext.ts +0 -21
- package/dist/src/updateMetadata.ts +0 -59
- package/dist/src/upload.ts +0 -86
- package/dist/src/validate.ts +0 -45
- package/dist/src/validateInput.ts +0 -47
- package/dist/src/validateItemData.ts +0 -20
- package/dist/src/versionData.ts +0 -24
- package/dist/src/waitForDb.ts +0 -25
- package/dist/src/waitForFiles.ts +0 -34
- package/dist/src/wasm.d.ts +0 -8300
package/dist/src/saveImageSrc.ts
DELETED
|
@@ -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
|
-
})
|
package/dist/src/saveMetadata.ts
DELETED
|
@@ -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
|
-
})
|
package/dist/src/saveRelation.ts
DELETED
|
@@ -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
package/dist/src/seedProtocol.ts
DELETED
|
@@ -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
|
-
}
|