@seedprotocol/sdk 0.1.54 → 0.1.55
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/{index-NmD9sjcJ.js → index-BkzKfVvD.js} +3 -3
- package/dist/index-BkzKfVvD.js.map +1 -0
- package/dist/{index-DQKd-s2Q.js → index-D4my8yy8.js} +2162 -1889
- package/dist/index-D4my8yy8.js.map +1 -0
- package/dist/main.js +2 -2
- package/dist/{seed.schema.config-OyHsE0Zl.js → seed.schema.config-BHZSMMmL.js} +2 -2
- package/dist/{seed.schema.config-OyHsE0Zl.js.map → seed.schema.config-BHZSMMmL.js.map} +1 -1
- package/dist/src/createMetadata.ts +1 -1
- package/dist/src/download.ts +6 -2
- package/dist/src/getItemProperty.ts +0 -1
- package/dist/src/propertyMachine.ts +62 -16
- package/dist/src/resolveRelatedValue.ts +4 -0
- package/dist/src/saveImageSrc.ts +200 -0
- package/dist/src/saveItemStorage.ts +145 -0
- package/dist/src/saveRelation.ts +112 -0
- package/dist/src/write.ts +27 -7
- package/dist/types/src/browser/db/read/getItemProperty.d.ts.map +1 -1
- package/dist/types/src/browser/db/write.d.ts.map +1 -1
- package/dist/types/src/browser/events/files/download.d.ts.map +1 -1
- package/dist/types/src/browser/item/Item.d.ts.map +1 -1
- package/dist/types/src/browser/property/ItemProperty.d.ts +20 -11
- package/dist/types/src/browser/property/ItemProperty.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/resolveRelatedValue.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/saveValueToDb/index.d.ts +8 -0
- package/dist/types/src/browser/property/actors/saveValueToDb/index.d.ts.map +1 -0
- package/dist/types/src/browser/property/actors/saveValueToDb/saveImageSrc.d.ts +5 -0
- package/dist/types/src/browser/property/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -0
- package/dist/types/src/browser/property/actors/saveValueToDb/saveItemStorage.d.ts +5 -0
- package/dist/types/src/browser/property/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -0
- package/dist/types/src/browser/property/actors/saveValueToDb/saveRelation.d.ts +5 -0
- package/dist/types/src/browser/property/actors/saveValueToDb/saveRelation.d.ts.map +1 -0
- package/dist/types/src/browser/property/propertyMachine.d.ts.map +1 -1
- package/dist/types/src/browser/schema/file/fetchAll/actors.d.ts.map +1 -1
- package/dist/types/src/shared/helpers/index.d.ts +1 -1
- package/dist/types/src/shared/helpers/index.d.ts.map +1 -1
- package/dist/types/src/types/property.d.ts +6 -0
- package/dist/types/src/types/property.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/index-DQKd-s2Q.js.map +0 -1
- package/dist/index-NmD9sjcJ.js.map +0 -1
- package/dist/src/saveValueToDb.ts +0 -208
- package/dist/types/src/browser/property/actors/saveValueToDb.d.ts +0 -10
- package/dist/types/src/browser/property/actors/saveValueToDb.d.ts.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-NmD9sjcJ.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import { createSeed, updateItemPropertyValue } from '@/browser/db/write'
|
|
3
|
-
import { fs } from '@zenfs/core'
|
|
4
|
-
import { getContentUrlFromPath } from '@/browser/helpers'
|
|
5
|
-
import { createVersion } from '@/browser/db/write/createVersion'
|
|
6
|
-
import { FromCallbackInput } from '@/types/machines'
|
|
7
|
-
import { PropertyMachineContext } from '@/types/property'
|
|
8
|
-
import { getAppDb } from '@/browser/db/sqlWasmClient'
|
|
9
|
-
import { metadata } from '@/shared/seedSchema'
|
|
10
|
-
import { and, eq } from 'drizzle-orm'
|
|
11
|
-
import { getItemDataFromDb } from '@/browser/db/read/getItem'
|
|
12
|
-
import { getItemPropertyData } from '@/browser/db/read/getItemProperty'
|
|
13
|
-
import { createMetadata } from '@/browser/db/write/createMetadata'
|
|
14
|
-
|
|
15
|
-
type SaveValueToDbEvent = {
|
|
16
|
-
type: 'saveValueToDb'
|
|
17
|
-
newValue: any
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const saveValueToDb = fromCallback<
|
|
21
|
-
EventObject,
|
|
22
|
-
FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>
|
|
23
|
-
>(({ sendBack, input: { context, event } }) => {
|
|
24
|
-
const {
|
|
25
|
-
localId,
|
|
26
|
-
propertyName: propertyNameRaw,
|
|
27
|
-
seedLocalId,
|
|
28
|
-
seedUid,
|
|
29
|
-
versionLocalId,
|
|
30
|
-
versionUid,
|
|
31
|
-
propertyValue: existingValue,
|
|
32
|
-
propertyRecordSchema,
|
|
33
|
-
itemModelName,
|
|
34
|
-
schemaUid,
|
|
35
|
-
} = context
|
|
36
|
-
|
|
37
|
-
let { newValue } = event
|
|
38
|
-
|
|
39
|
-
if (existingValue === newValue) {
|
|
40
|
-
sendBack({ type: 'saveValueToDbSuccess' })
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const _saveValueToDb = async () => {
|
|
45
|
-
let refResolvedValue
|
|
46
|
-
let refResolvedDisplayValue
|
|
47
|
-
let refSeedType
|
|
48
|
-
let propertyName = propertyNameRaw
|
|
49
|
-
let versionLocalIdToSave = versionLocalId
|
|
50
|
-
let versionUidToSave = versionUid
|
|
51
|
-
|
|
52
|
-
if (propertyRecordSchema && propertyRecordSchema.dataType === 'Relation') {
|
|
53
|
-
refResolvedValue = newValue
|
|
54
|
-
|
|
55
|
-
if (!propertyName.endsWith('Id')) {
|
|
56
|
-
propertyName = `${propertyName}Id`
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
let fileType
|
|
60
|
-
|
|
61
|
-
const dirs = await fs.promises.readdir('/files')
|
|
62
|
-
|
|
63
|
-
for (const dir of dirs) {
|
|
64
|
-
const files = await fs.promises.readdir(`/files/${dir}`)
|
|
65
|
-
if (files.includes(newValue)) {
|
|
66
|
-
fileType = dir
|
|
67
|
-
break
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (fileType === 'images') {
|
|
72
|
-
const filePath = `/files/images/${newValue}`
|
|
73
|
-
refResolvedDisplayValue = await getContentUrlFromPath(filePath)
|
|
74
|
-
refSeedType = 'image'
|
|
75
|
-
newValue = await createSeed({
|
|
76
|
-
type: refSeedType,
|
|
77
|
-
})
|
|
78
|
-
versionLocalIdToSave = await createVersion({
|
|
79
|
-
seedLocalId,
|
|
80
|
-
seedUid,
|
|
81
|
-
seedType: refSeedType,
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
propertyRecordSchema &&
|
|
88
|
-
propertyRecordSchema.storageType &&
|
|
89
|
-
propertyRecordSchema.storageType === 'ItemStorage'
|
|
90
|
-
) {
|
|
91
|
-
// Save value to file
|
|
92
|
-
const appDb = getAppDb()
|
|
93
|
-
let propertyData
|
|
94
|
-
|
|
95
|
-
if (localId) {
|
|
96
|
-
propertyData = await getItemPropertyData({
|
|
97
|
-
localId,
|
|
98
|
-
})
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (!localId && seedLocalId) {
|
|
102
|
-
const itemData = await getItemDataFromDb({
|
|
103
|
-
seedLocalId,
|
|
104
|
-
})
|
|
105
|
-
if (itemData) {
|
|
106
|
-
const whereClauses = [
|
|
107
|
-
eq(metadata.propertyName, propertyName),
|
|
108
|
-
eq(metadata.seedLocalId, seedLocalId),
|
|
109
|
-
]
|
|
110
|
-
|
|
111
|
-
if (itemData.latestVersionLocalId) {
|
|
112
|
-
whereClauses.push(
|
|
113
|
-
eq(metadata.versionLocalId, itemData.latestVersionLocalId),
|
|
114
|
-
)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const queryRows = await appDb
|
|
118
|
-
.select()
|
|
119
|
-
.from(metadata)
|
|
120
|
-
.where(and(...whereClauses))
|
|
121
|
-
|
|
122
|
-
if (queryRows && queryRows.length) {
|
|
123
|
-
propertyData = queryRows[0]
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (!propertyData) {
|
|
127
|
-
const propertyDataRows = await createMetadata(
|
|
128
|
-
{
|
|
129
|
-
propertyName,
|
|
130
|
-
modelType: itemModelName.toLowerCase(),
|
|
131
|
-
seedLocalId,
|
|
132
|
-
seedUid,
|
|
133
|
-
versionLocalId: itemData.latestVersionLocalId,
|
|
134
|
-
versionUid: itemData.latestVersionUid,
|
|
135
|
-
localStorageDir: propertyRecordSchema.localStorageDir,
|
|
136
|
-
refValueType: 'file',
|
|
137
|
-
},
|
|
138
|
-
propertyRecordSchema,
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
propertyData = propertyDataRows[0]
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// propertyData = {
|
|
145
|
-
// propertyName,
|
|
146
|
-
// seedLocalId,
|
|
147
|
-
// seedUid,
|
|
148
|
-
// versionLocalId: itemData.latestVersionLocalId,
|
|
149
|
-
// versionUid: itemData.latestVersionUid,
|
|
150
|
-
// schemaUid: itemData.schemaUid,
|
|
151
|
-
// }
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const localStorageDir =
|
|
156
|
-
propertyRecordSchema.localStorageDir || propertyData.localStorageDir
|
|
157
|
-
const fileName =
|
|
158
|
-
propertyData.refResolvedValue ||
|
|
159
|
-
`${propertyData.localId}${propertyRecordSchema.filenameSuffix}`
|
|
160
|
-
|
|
161
|
-
if (!localStorageDir || !fileName) {
|
|
162
|
-
throw new Error(
|
|
163
|
-
`Missing localStorageDir: ${localStorageDir} or fileName: ${fileName}`,
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const filePath = `/files/${localStorageDir}/${fileName}`
|
|
168
|
-
await fs.promises.writeFile(filePath, newValue)
|
|
169
|
-
|
|
170
|
-
await appDb
|
|
171
|
-
.update(metadata)
|
|
172
|
-
.set({
|
|
173
|
-
refResolvedValue: fileName,
|
|
174
|
-
})
|
|
175
|
-
.where(eq(metadata.localId, propertyData.localId))
|
|
176
|
-
|
|
177
|
-
sendBack({
|
|
178
|
-
type: 'updateContext',
|
|
179
|
-
renderValue: newValue,
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
return
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
await updateItemPropertyValue({
|
|
186
|
-
propertyLocalId: localId,
|
|
187
|
-
propertyName,
|
|
188
|
-
newValue,
|
|
189
|
-
seedLocalId,
|
|
190
|
-
refSeedType,
|
|
191
|
-
refResolvedValue,
|
|
192
|
-
refResolvedDisplayValue,
|
|
193
|
-
versionLocalId,
|
|
194
|
-
modelName: itemModelName,
|
|
195
|
-
schemaUid,
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
sendBack({
|
|
199
|
-
type: 'updateContext',
|
|
200
|
-
propertyValue: newValue,
|
|
201
|
-
renderValue: refResolvedDisplayValue,
|
|
202
|
-
})
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
_saveValueToDb().then(() => {
|
|
206
|
-
sendBack({ type: 'saveValueToDbSuccess' })
|
|
207
|
-
})
|
|
208
|
-
})
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { EventObject } from 'xstate';
|
|
2
|
-
import { FromCallbackInput } from '@/types/machines';
|
|
3
|
-
import { PropertyMachineContext } from '@/types/property';
|
|
4
|
-
type SaveValueToDbEvent = {
|
|
5
|
-
type: 'saveValueToDb';
|
|
6
|
-
newValue: any;
|
|
7
|
-
};
|
|
8
|
-
export declare const saveValueToDb: import("xstate").CallbackActorLogic<EventObject, FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>, EventObject>;
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=saveValueToDb.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"saveValueToDb.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/property/actors/saveValueToDb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,QAAQ,CAAA;AAKlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAQzD,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,eAAe,CAAA;IACrB,QAAQ,EAAE,GAAG,CAAA;CACd,CAAA;AAED,eAAO,MAAM,aAAa,8HA4LxB,CAAA"}
|