@seedprotocol/sdk 0.1.74 → 0.1.76
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/bin.js +1 -6
- package/dist/bin.js.map +1 -1
- package/dist/{constants-CtmwCBma.js → constants-rmQ8zg8_.js} +2 -1
- package/dist/{constants-CtmwCBma.js.map → constants-rmQ8zg8_.js.map} +1 -1
- package/dist/{index-3ASvLLXY.js → index-D5bGQvS6.js} +3 -3
- package/dist/{index-3ASvLLXY.js.map → index-D5bGQvS6.js.map} +1 -1
- package/dist/{index-Br7jo_vg.js → index-nyYoS6hl.js} +254 -333
- package/dist/index-nyYoS6hl.js.map +1 -0
- package/dist/main.js +2 -2
- package/dist/{seed.schema.config-BHNlL53f.js → seed.schema.config-CaxQONHV.js} +3 -3
- package/dist/{seed.schema.config-BHNlL53f.js.map → seed.schema.config-CaxQONHV.js.map} +1 -1
- package/dist/src/ItemProperty.ts +21 -25
- package/dist/src/actors.ts +7 -282
- package/dist/src/analyzeInput.ts +102 -0
- package/dist/src/db.ts +0 -29
- package/dist/src/drizzle.ts +0 -4
- package/dist/src/getItem.ts +12 -32
- package/dist/src/getItemProperties.ts +17 -113
- package/dist/src/hydrateFromDb.ts +198 -218
- package/dist/src/index.ts +10 -62
- package/dist/src/item.ts +1 -2
- package/dist/src/itemMachineSingle.ts +12 -29
- package/dist/src/propertyMachine.ts +3 -14
- package/dist/src/reload.ts +33 -0
- package/dist/src/request.ts +0 -9
- package/dist/src/resolveRelatedValue.ts +25 -4
- package/dist/src/resolveRemoteStorage.ts +3 -2
- package/dist/src/saveImageSrc.ts +0 -4
- package/dist/src/services.ts +0 -3
- package/dist/src/updateItemPropertyValue.ts +1 -0
- package/dist/src/waitForFiles.ts +33 -0
- package/dist/types/src/browser/db/read/getItem.d.ts.map +1 -1
- package/dist/types/src/browser/db/read/getItemProperties.d.ts.map +1 -1
- package/dist/types/src/browser/db/write/updateItemPropertyValue.d.ts.map +1 -1
- package/dist/types/src/browser/events/item/request.d.ts.map +1 -1
- package/dist/types/src/browser/item/Item.d.ts.map +1 -1
- package/dist/types/src/browser/item/single/actors/reload.d.ts +5 -0
- package/dist/types/src/browser/item/single/actors/reload.d.ts.map +1 -0
- package/dist/types/src/browser/item/single/actors/saveDataToDb.d.ts +1 -55
- package/dist/types/src/browser/item/single/actors/saveDataToDb.d.ts.map +1 -1
- package/dist/types/src/browser/item/single/itemMachineSingle.d.ts +1 -56
- package/dist/types/src/browser/item/single/itemMachineSingle.d.ts.map +1 -1
- package/dist/types/src/browser/property/ItemProperty.d.ts +4 -112
- package/dist/types/src/browser/property/ItemProperty.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts +4 -1
- package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/resolveRelatedValue.d.ts +4 -1
- package/dist/types/src/browser/property/actors/resolveRelatedValue.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/resolveRemoteStorage.d.ts +3 -55
- package/dist/types/src/browser/property/actors/resolveRemoteStorage.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts +5 -0
- package/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts.map +1 -0
- package/dist/types/src/browser/property/actors/saveValueToDb/index.d.ts +1 -4
- package/dist/types/src/browser/property/actors/saveValueToDb/index.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
- package/dist/types/src/browser/property/propertyMachine.d.ts.map +1 -1
- package/dist/types/src/browser/react/item.d.ts.map +1 -1
- package/dist/types/src/browser/react/services.d.ts.map +1 -1
- package/dist/types/src/browser/services/db/actors/waitForFiles.d.ts +4 -0
- package/dist/types/src/browser/services/db/actors/waitForFiles.d.ts.map +1 -0
- package/dist/types/src/node/codegen/drizzle.d.ts.map +1 -1
- package/dist/types/src/node/constants.d.ts.map +1 -1
- package/dist/types/src/node/webpack/index.d.ts.map +1 -1
- package/dist/types/src/shared/helpers/constants.d.ts.map +1 -1
- package/dist/types/src/shared/helpers/db.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/index-Br7jo_vg.js.map +0 -1
package/dist/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { j as ImageSrc, I as Item, k as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, t as client, v as getCorrectId, s as getGlobalService, n as useCreateItem, p as useDeleteItem, q as useGlobalServiceStatus, l as useItem, m as useItemProperties, o as useItemProperty, u as useItems, r as useServices, w as withSeed } from './index-
|
|
1
|
+
export { j as ImageSrc, I as Item, k as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, t as client, v as getCorrectId, s as getGlobalService, n as useCreateItem, p as useDeleteItem, q as useGlobalServiceStatus, l as useItem, m as useItemProperties, o as useItemProperty, u as useItems, r as useServices, w as withSeed } from './index-nyYoS6hl.js';
|
|
2
2
|
import 'immer';
|
|
3
3
|
import 'reflect-metadata';
|
|
4
|
-
import './constants-
|
|
4
|
+
import './constants-rmQ8zg8_.js';
|
|
5
5
|
import 'xstate';
|
|
6
6
|
import 'arweave';
|
|
7
7
|
import 'drizzle-orm';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as __decorate, a as __metadata } from './constants-
|
|
1
|
+
import { _ as __decorate, a as __metadata } from './constants-rmQ8zg8_.js';
|
|
2
2
|
import 'drizzle-orm';
|
|
3
|
-
import { T as Text, M as Model } from './index-
|
|
3
|
+
import { T as Text, M as Model } from './index-nyYoS6hl.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
import 'reflect-metadata';
|
|
6
6
|
import 'xstate';
|
|
@@ -76,4 +76,4 @@ const models = {
|
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
export { models };
|
|
79
|
-
//# sourceMappingURL=seed.schema.config-
|
|
79
|
+
//# sourceMappingURL=seed.schema.config-CaxQONHV.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.schema.config-
|
|
1
|
+
{"version":3,"file":"seed.schema.config-CaxQONHV.js","sources":["../../src/shared/configs/seed.schema.config.ts"],"sourcesContent":["import { Model, Text } from '@/browser'\n\n@Model\nclass Seed {\n @Text() uid!: string\n @Text() type!: string\n}\n\n@Model\nclass Version {\n @Text() seedUid!: string\n @Text() note!: string\n}\n\n@Model\nclass Metadata {\n @Text() key!: string\n @Text() value!: string\n}\n\nexport const models = {\n Seed,\n Version,\n Metadata,\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAM,IAAI,GAAV,MAAM,IAAI,CAAA;CAGT;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA;AAFjB,IAAI,GAAA,UAAA,CAAA;IADT;AACK,CAAA,EAAA,IAAI,CAGT;AAGD,IAAM,OAAO,GAAb,MAAM,OAAO,CAAA;CAGZ;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAiB,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,SAAA,EAAA,KAAA,CAAA,CAAA;AAChB,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA;AAFjB,OAAO,GAAA,UAAA,CAAA;IADZ;AACK,CAAA,EAAA,OAAO,CAGZ;AAGD,IAAM,QAAQ,GAAd,MAAM,QAAQ,CAAA;CAGb;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAe,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,KAAA,CAAA,CAAA;AAFlB,QAAQ,GAAA,UAAA,CAAA;IADb;AACK,CAAA,EAAA,QAAQ,CAGb;AAEY,MAAA,MAAM,GAAG;IACpB,IAAI;IACJ,OAAO;IACP,QAAQ;;;;;"}
|
package/dist/src/ItemProperty.ts
CHANGED
|
@@ -18,7 +18,6 @@ import { getModel } from '@/browser/stores/modelClass'
|
|
|
18
18
|
import { getCorrectId } from '@/browser/helpers'
|
|
19
19
|
import { Static } from '@sinclair/typebox'
|
|
20
20
|
import { TProperty } from '@/browser/property'
|
|
21
|
-
import { fs } from '@zenfs/core'
|
|
22
21
|
|
|
23
22
|
const logger = debug('app:property:class')
|
|
24
23
|
|
|
@@ -151,14 +150,6 @@ export class ItemProperty<PropertyType> {
|
|
|
151
150
|
const { context } = snapshot
|
|
152
151
|
const { propertyRecordSchema } = context
|
|
153
152
|
|
|
154
|
-
// if (this.uid && !cacheHasProperty(this.uid)) {
|
|
155
|
-
// addPropertyToCache(this)
|
|
156
|
-
// }
|
|
157
|
-
//
|
|
158
|
-
// if (!this.uid && this.localId && !cacheHasProperty(this.localId,)) {
|
|
159
|
-
// addPropertyToCache(this)
|
|
160
|
-
// }
|
|
161
|
-
|
|
162
153
|
if (context.seedLocalId) {
|
|
163
154
|
const cacheKey = ItemProperty.cacheKey(
|
|
164
155
|
context.seedLocalId,
|
|
@@ -179,19 +170,26 @@ export class ItemProperty<PropertyType> {
|
|
|
179
170
|
|
|
180
171
|
let renderValue
|
|
181
172
|
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
173
|
+
// if (
|
|
174
|
+
// propertyRecordSchema &&
|
|
175
|
+
// propertyRecordSchema.storageType &&
|
|
176
|
+
// propertyRecordSchema.storageType === 'ItemStorage' &&
|
|
177
|
+
// context.resolvedValue &&
|
|
178
|
+
// context.localStorageDir
|
|
179
|
+
// ) {
|
|
180
|
+
// const filePath = `/files/${context.localStorageDir}/${context.resolvedValue}`
|
|
181
|
+
// try {
|
|
182
|
+
// const exists = await fs.promises.exists(filePath)
|
|
183
|
+
// if (exists) {
|
|
184
|
+
// renderValue = await fs.promises.readFile(filePath, 'utf-8')
|
|
185
|
+
// }
|
|
186
|
+
// } catch (e) {
|
|
187
|
+
// logger(
|
|
188
|
+
// `[ItemProperty] [${context.seedLocalId}] [${context.propertyName}] [storageType] error`,
|
|
189
|
+
// e,
|
|
190
|
+
// )
|
|
191
|
+
// }
|
|
192
|
+
// }
|
|
195
193
|
|
|
196
194
|
if (!renderValue) {
|
|
197
195
|
renderValue = context.renderValue || context.propertyValue
|
|
@@ -296,13 +294,11 @@ export class ItemProperty<PropertyType> {
|
|
|
296
294
|
const cacheKey = ItemProperty.cacheKey(cacheKeyId!, propertyName)
|
|
297
295
|
if (this.instanceCache.has(cacheKey)) {
|
|
298
296
|
const { instance, refCount } = this.instanceCache.get(cacheKey)!
|
|
297
|
+
instance.getService().send({ type: 'reload' })
|
|
299
298
|
this.instanceCache.set(cacheKey, {
|
|
300
299
|
instance,
|
|
301
300
|
refCount: refCount + 1,
|
|
302
301
|
})
|
|
303
|
-
if (instance.status === 'idle') {
|
|
304
|
-
instance.getService().send({ type: 'refresh' })
|
|
305
|
-
}
|
|
306
302
|
return instance
|
|
307
303
|
}
|
|
308
304
|
const propertyData = await getPropertyData(
|
package/dist/src/actors.ts
CHANGED
|
@@ -1,285 +1,10 @@
|
|
|
1
1
|
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import {
|
|
3
|
-
import { ARWEAVE_HOST } from '@/browser/services/internal/constants'
|
|
4
|
-
import { GET_FILES_METADATA } from '@/browser/schema/file/queries'
|
|
5
|
-
import { getArweave } from '../arweave'
|
|
6
|
-
import { fs } from '@zenfs/core'
|
|
7
|
-
import {
|
|
8
|
-
getDataTypeFromString,
|
|
9
|
-
getMimeType,
|
|
10
|
-
identifyString,
|
|
11
|
-
} from '@/shared/helpers'
|
|
12
|
-
import { appState } from 'src/shared/seedSchema'
|
|
13
|
-
import { eq } from 'drizzle-orm'
|
|
14
|
-
import { easClient, queryClient } from '@/browser/helpers'
|
|
15
|
-
import debug from 'debug'
|
|
16
|
-
import { getAppDb } from '@/browser/db/sqlWasmClient'
|
|
2
|
+
import { uploadMachine } from '@/browser/schema/file/upload/index'
|
|
17
3
|
|
|
18
|
-
|
|
4
|
+
export const uploadBinaryData = fromCallback<EventObject, typeof uploadMachine>(
|
|
5
|
+
({ sendBack, receive, input }) => {},
|
|
6
|
+
)
|
|
19
7
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
mimeType: string
|
|
24
|
-
extension: string
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Map of common MIME types to file extensions
|
|
28
|
-
const fileTypeMap: Record<string, FileType> = {
|
|
29
|
-
'image/jpeg': { mimeType: 'image/jpeg', extension: '.jpg' },
|
|
30
|
-
'image/png': { mimeType: 'image/png', extension: '.png' },
|
|
31
|
-
'application/json': { mimeType: 'application/json', extension: '.json' },
|
|
32
|
-
'text/plain': { mimeType: 'text/plain', extension: '.txt' },
|
|
33
|
-
// Add more MIME types and file extensions as needed
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const fetchAllMetadataRecords = fromCallback<
|
|
37
|
-
EventObject,
|
|
38
|
-
typeof fetchAllFilesMachine
|
|
39
|
-
>(({ sendBack, receive, input: { context, event } }) => {
|
|
40
|
-
const { addresses } = context
|
|
41
|
-
|
|
42
|
-
const _fetchAllMetadataRecords = async () => {
|
|
43
|
-
const { filesMetadata } = await queryClient.fetchQuery({
|
|
44
|
-
queryKey: ['getFilesMetadata', ...addresses],
|
|
45
|
-
queryFn: async () =>
|
|
46
|
-
easClient.request(GET_FILES_METADATA, {
|
|
47
|
-
where: {
|
|
48
|
-
attester: {
|
|
49
|
-
in: addresses,
|
|
50
|
-
},
|
|
51
|
-
schema: {
|
|
52
|
-
is: {
|
|
53
|
-
id: {
|
|
54
|
-
equals:
|
|
55
|
-
'0x55fdefb36fcbbaebeb7d6b41dc3a1a9666e4e42154267c889de064faa7ede517',
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
}),
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
return filesMetadata
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
_fetchAllMetadataRecords().then((filesMetadata) => {
|
|
67
|
-
sendBack({ type: 'fetchingAllMetadataRecordsSuccess', filesMetadata })
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
return () => {}
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
export const fetchAllBinaryData = fromCallback<
|
|
74
|
-
EventObject,
|
|
75
|
-
typeof fetchAllFilesMachine
|
|
76
|
-
>(({ sendBack, input: { context } }) => {
|
|
77
|
-
const { filesMetadata, addresses } = context
|
|
78
|
-
|
|
79
|
-
const _fetchAllBinaryData = async () => {
|
|
80
|
-
if (!(await fs.promises.exists('/files'))) {
|
|
81
|
-
await fs.promises.mkdir('/files', { recursive: true })
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (!(await fs.promises.exists('/files/html'))) {
|
|
85
|
-
await fs.promises.mkdir('/files/html', { recursive: true })
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (!(await fs.promises.exists('/files/json'))) {
|
|
89
|
-
await fs.promises.mkdir('/files/json', { recursive: true })
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (!(await fs.promises.exists('/files/images'))) {
|
|
93
|
-
await fs.promises.mkdir('/files/images', { recursive: true })
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const appDb = getAppDb()
|
|
97
|
-
|
|
98
|
-
if (!appDb) {
|
|
99
|
-
logger('[fetchAll/actors] [fetchAllBinaryData] seedDb not available')
|
|
100
|
-
return []
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
for (const fileMetadata of filesMetadata) {
|
|
104
|
-
const json = JSON.parse(fileMetadata.decodedDataJson)
|
|
105
|
-
const transactionId = json[0].value.value
|
|
106
|
-
|
|
107
|
-
const excludedTransactionsQuery = await appDb
|
|
108
|
-
.select()
|
|
109
|
-
.from(appState)
|
|
110
|
-
.where(eq(appState.key, 'excludedTransactions'))
|
|
111
|
-
|
|
112
|
-
let excludedTransactions = new Set<string>()
|
|
113
|
-
|
|
114
|
-
if (excludedTransactionsQuery && excludedTransactionsQuery.length === 1) {
|
|
115
|
-
const valueString = excludedTransactionsQuery[0].value
|
|
116
|
-
if (valueString) {
|
|
117
|
-
const excludedTransactionsArray = JSON.parse(valueString)
|
|
118
|
-
excludedTransactions = new Set(excludedTransactionsArray)
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (excludedTransactions.has(transactionId)) {
|
|
123
|
-
continue
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const arweave = getArweave()
|
|
127
|
-
|
|
128
|
-
if (!arweave) {
|
|
129
|
-
logger('[fetchAll/actors] [fetchAllBinaryData] arweave not available')
|
|
130
|
-
return []
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
|
-
const res = await fetch(
|
|
135
|
-
`https://${ARWEAVE_HOST}/tx/${transactionId}/status`,
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
if (res.status !== 200) {
|
|
139
|
-
logger(
|
|
140
|
-
`[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`,
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
excludedTransactions.add(transactionId)
|
|
144
|
-
|
|
145
|
-
await saveAppState(
|
|
146
|
-
'excludedTransactions',
|
|
147
|
-
JSON.stringify(Array.from(excludedTransactions)),
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
logger(
|
|
151
|
-
'[fetchAll/actors] [fetchAllBinaryData] updated excludedTransactions:',
|
|
152
|
-
excludedTransactions,
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
continue
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const dataString = await arweave.transactions
|
|
159
|
-
.getData(transactionId, {
|
|
160
|
-
decode: true,
|
|
161
|
-
string: true,
|
|
162
|
-
})
|
|
163
|
-
.catch((error) => {
|
|
164
|
-
logger(
|
|
165
|
-
`[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`,
|
|
166
|
-
error,
|
|
167
|
-
)
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
const dataUint8Array = await arweave.transactions.getData(transactionId)
|
|
171
|
-
// let buffer
|
|
172
|
-
//
|
|
173
|
-
// if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
|
|
174
|
-
// }
|
|
175
|
-
|
|
176
|
-
let contentType = identifyString(dataString)
|
|
177
|
-
if (
|
|
178
|
-
contentType !== 'json' &&
|
|
179
|
-
contentType !== 'base64' &&
|
|
180
|
-
contentType !== 'html'
|
|
181
|
-
) {
|
|
182
|
-
const possibleImageType = getDataTypeFromString(dataString)
|
|
183
|
-
if (!possibleImageType) {
|
|
184
|
-
logger(
|
|
185
|
-
`[fetchAll/actors] [fetchAllBinaryData] transaction ${transactionId} data not in expected format: ${possibleImageType}`,
|
|
186
|
-
)
|
|
187
|
-
continue
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
contentType = possibleImageType
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (contentType === 'url') {
|
|
194
|
-
const url = dataString as string
|
|
195
|
-
const response = await fetch(url)
|
|
196
|
-
if (!response.ok) {
|
|
197
|
-
throw new Error(`Failed to fetch image: ${response.statusText}`)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Get the image as a Blob
|
|
201
|
-
const blob = await response.blob()
|
|
202
|
-
const buffer = await blob.arrayBuffer()
|
|
203
|
-
const bufferUint8Array = new Uint8Array(buffer)
|
|
204
|
-
|
|
205
|
-
// Extract the file extension from the URL
|
|
206
|
-
const extensionMatch = url.match(
|
|
207
|
-
/\.(jpg|jpeg|png|gif|bmp|webp|svg)$/i,
|
|
208
|
-
)
|
|
209
|
-
if (!extensionMatch) {
|
|
210
|
-
throw new Error(
|
|
211
|
-
'Unable to determine the file extension from the URL.',
|
|
212
|
-
)
|
|
213
|
-
}
|
|
214
|
-
const fileExtension = extensionMatch[0] // e.g., ".jpg"
|
|
215
|
-
|
|
216
|
-
// Set the file name (you can customize this)
|
|
217
|
-
// const fileNameFromUrl = `${transactionId}${fileExtension}`
|
|
218
|
-
|
|
219
|
-
await fs.promises.writeFile(
|
|
220
|
-
`/files/images/${transactionId}`,
|
|
221
|
-
bufferUint8Array,
|
|
222
|
-
{
|
|
223
|
-
encoding: 'binary',
|
|
224
|
-
},
|
|
225
|
-
)
|
|
226
|
-
|
|
227
|
-
continue
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const mimeType = getMimeType(dataString as string)
|
|
231
|
-
|
|
232
|
-
let fileName = transactionId
|
|
233
|
-
|
|
234
|
-
if (contentType === 'base64') {
|
|
235
|
-
if (mimeType) {
|
|
236
|
-
fileName += `.${mimeType}`
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// Remove the Base64 header if it exists (e.g., "data:image/png;base64,")
|
|
240
|
-
const base64Data = dataString.split(',').pop() || ''
|
|
241
|
-
|
|
242
|
-
// Decode the Base64 string to binary
|
|
243
|
-
const binaryString = atob(base64Data)
|
|
244
|
-
const length = binaryString.length
|
|
245
|
-
const binaryData = new Uint8Array(length)
|
|
246
|
-
|
|
247
|
-
for (let i = 0; i < length; i++) {
|
|
248
|
-
binaryData[i] = binaryString.charCodeAt(i)
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
await fs.promises.writeFile(`/files/images/${fileName}`, binaryData, {
|
|
252
|
-
encoding: 'binary',
|
|
253
|
-
})
|
|
254
|
-
|
|
255
|
-
// if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
|
|
256
|
-
// await fs.promises.writeFile(
|
|
257
|
-
// `/files/images/${fileName}`,
|
|
258
|
-
// dataUint8Array,
|
|
259
|
-
// )
|
|
260
|
-
// }
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (contentType === 'html') {
|
|
264
|
-
fileName += '.html'
|
|
265
|
-
await fs.promises.writeFile(`/files/html/${fileName}`, dataString)
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (contentType === 'json') {
|
|
269
|
-
fileName += '.json'
|
|
270
|
-
await fs.promises.writeFile(`/files/json/${fileName}`, dataString)
|
|
271
|
-
}
|
|
272
|
-
} catch (error) {
|
|
273
|
-
logger(error)
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return []
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
_fetchAllBinaryData().then((binaryData) => {
|
|
281
|
-
sendBack({ type: 'fetchingAllBinaryDataSuccess', binaryData })
|
|
282
|
-
})
|
|
283
|
-
|
|
284
|
-
return () => {}
|
|
285
|
-
})
|
|
8
|
+
export const uploadMetadata = fromCallback<EventObject, typeof uploadMachine>(
|
|
9
|
+
({ sendBack, receive, input }) => {},
|
|
10
|
+
)
|
|
@@ -0,0 +1,102 @@
|
|
|
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 { updateItemPropertyValue } from '@/browser/db/write/updateItemPropertyValue'
|
|
9
|
+
|
|
10
|
+
export const analyzeInput = fromCallback<
|
|
11
|
+
EventObject,
|
|
12
|
+
FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>
|
|
13
|
+
>(({ sendBack, input: { context, event } }) => {
|
|
14
|
+
const {
|
|
15
|
+
localId,
|
|
16
|
+
propertyName: propertyNameRaw,
|
|
17
|
+
seedLocalId,
|
|
18
|
+
versionLocalId,
|
|
19
|
+
versionUid,
|
|
20
|
+
propertyValue: existingValue,
|
|
21
|
+
propertyRecordSchema,
|
|
22
|
+
itemModelName,
|
|
23
|
+
schemaUid,
|
|
24
|
+
} = context
|
|
25
|
+
|
|
26
|
+
let newValue: ItemPropertyValueType
|
|
27
|
+
|
|
28
|
+
if (event) {
|
|
29
|
+
newValue = event.newValue
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (existingValue === newValue) {
|
|
33
|
+
sendBack({ type: 'saveValueToDbSuccess' })
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!propertyRecordSchema) {
|
|
38
|
+
throw new Error('Missing propertyRecordSchema')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const _analyzeInput = async (): Promise<boolean> => {
|
|
42
|
+
let propertyName = propertyNameRaw
|
|
43
|
+
|
|
44
|
+
if (
|
|
45
|
+
propertyRecordSchema.refValueType &&
|
|
46
|
+
propertyRecordSchema.refValueType !== 'ImageSrc' &&
|
|
47
|
+
propertyRecordSchema.dataType === 'Relation'
|
|
48
|
+
) {
|
|
49
|
+
sendBack({
|
|
50
|
+
type: 'saveRelation',
|
|
51
|
+
newValue,
|
|
52
|
+
})
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (
|
|
57
|
+
propertyRecordSchema.refValueType === 'ImageSrc' ||
|
|
58
|
+
propertyRecordSchema.dataType === 'ImageSrc'
|
|
59
|
+
) {
|
|
60
|
+
sendBack({
|
|
61
|
+
type: 'saveImageSrc',
|
|
62
|
+
newValue,
|
|
63
|
+
})
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (
|
|
68
|
+
propertyRecordSchema.storageType &&
|
|
69
|
+
propertyRecordSchema.storageType === 'ItemStorage'
|
|
70
|
+
) {
|
|
71
|
+
sendBack({
|
|
72
|
+
type: 'saveItemStorage',
|
|
73
|
+
newValue,
|
|
74
|
+
})
|
|
75
|
+
return false
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
await updateItemPropertyValue({
|
|
79
|
+
localId: localId,
|
|
80
|
+
propertyName,
|
|
81
|
+
newValue,
|
|
82
|
+
seedLocalId,
|
|
83
|
+
versionLocalId,
|
|
84
|
+
versionUid,
|
|
85
|
+
modelName: itemModelName,
|
|
86
|
+
schemaUid,
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
sendBack({
|
|
90
|
+
type: 'updateContext',
|
|
91
|
+
propertyValue: newValue,
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
return true
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
_analyzeInput().then((isDone) => {
|
|
98
|
+
if (isDone) {
|
|
99
|
+
sendBack({ type: 'saveValueToDbSuccess' })
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
})
|
package/dist/src/db.ts
CHANGED
|
@@ -135,31 +135,13 @@ export const createOrUpdate = async <T>(
|
|
|
135
135
|
.update(table)
|
|
136
136
|
.set(safeValues)
|
|
137
137
|
.where(and(...valueFilters))
|
|
138
|
-
console.log('updatedRecord:', {
|
|
139
|
-
...existingRecords[0],
|
|
140
|
-
...safeValues,
|
|
141
|
-
})
|
|
142
138
|
|
|
143
139
|
const doneWithUpdate = Date.now()
|
|
144
140
|
|
|
145
|
-
console.log(
|
|
146
|
-
'[helpers/db] [createOrUpdate] filters duration:',
|
|
147
|
-
doneWithFilters - startTime,
|
|
148
|
-
)
|
|
149
|
-
console.log(
|
|
150
|
-
'[helpers/db] [createOrUpdate] existingRecords duration:',
|
|
151
|
-
doneWithExistingRecords - doneWithFilters,
|
|
152
|
-
)
|
|
153
|
-
console.log(
|
|
154
|
-
'[helpers/db] [createOrUpdate] update duration:',
|
|
155
|
-
doneWithUpdate - doneWithExistingRecords,
|
|
156
|
-
)
|
|
157
|
-
|
|
158
141
|
return existingRecords[0] as T
|
|
159
142
|
} else {
|
|
160
143
|
// If no record exists, create a new one
|
|
161
144
|
const newRecord = await db.insert(table).values(safeValues).returning()
|
|
162
|
-
console.log('newRecord:', newRecord)
|
|
163
145
|
return newRecord[0] as T
|
|
164
146
|
}
|
|
165
147
|
}
|
|
@@ -168,10 +150,6 @@ export const addModelsToInternalDb = async (
|
|
|
168
150
|
models: ModelDefinitions,
|
|
169
151
|
) => {
|
|
170
152
|
for (const [modelName, modelClass] of Object.entries(models)) {
|
|
171
|
-
console.log(
|
|
172
|
-
'[helpers/db] [addModelsToInternalDb] starting modelName:',
|
|
173
|
-
modelName,
|
|
174
|
-
)
|
|
175
153
|
const modelRecord = await createOrUpdate<NewModelRecord>(db, modelsTable, {
|
|
176
154
|
name: modelName,
|
|
177
155
|
})
|
|
@@ -203,14 +181,7 @@ export const addModelsToInternalDb = async (
|
|
|
203
181
|
properties,
|
|
204
182
|
propertyValues,
|
|
205
183
|
)
|
|
206
|
-
|
|
207
|
-
console.log('propertyRecord:', propertyRecord)
|
|
208
184
|
}
|
|
209
|
-
|
|
210
|
-
console.log(
|
|
211
|
-
'[helpers/db] [addModelsToInternalDb] done modelName:',
|
|
212
|
-
modelName,
|
|
213
|
-
)
|
|
214
185
|
}
|
|
215
186
|
}
|
|
216
187
|
export const getAddressesFromDb = async (): Promise<string[]> => {
|
package/dist/src/drizzle.ts
CHANGED
|
@@ -60,14 +60,10 @@ const generateDrizzleSchemaCode = (
|
|
|
60
60
|
export const createDrizzleSchemaFilesFromConfig = async () => {
|
|
61
61
|
const schemaFilePath = path.join(dotSeedDir, 'schema.ts') // Developer created file with model definitions
|
|
62
62
|
|
|
63
|
-
console.log('schemaFilePath:', schemaFilePath)
|
|
64
|
-
|
|
65
63
|
const { models } = await getTsImport<{
|
|
66
64
|
models: Record<string, ModelClassType>
|
|
67
65
|
}>(schemaFilePath)
|
|
68
66
|
|
|
69
|
-
console.log('models:', models)
|
|
70
|
-
|
|
71
67
|
for (const [modelName, modelClass] of Object.entries(models)) {
|
|
72
68
|
const code = generateDrizzleSchemaCode(modelName, modelClass)
|
|
73
69
|
|
package/dist/src/getItem.ts
CHANGED
|
@@ -83,46 +83,26 @@ export const getItemDataFromDb: GetItemDataFromDb = async ({
|
|
|
83
83
|
|
|
84
84
|
let itemData = itemDataRows[0]
|
|
85
85
|
|
|
86
|
-
const propertiesData = await getItemProperties({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
// seedUid,
|
|
91
|
-
// modelName,
|
|
92
|
-
// }
|
|
86
|
+
const propertiesData = await getItemProperties({
|
|
87
|
+
seedLocalId,
|
|
88
|
+
seedUid: itemData.seedUid || undefined,
|
|
89
|
+
})
|
|
93
90
|
|
|
94
91
|
if (!propertiesData || propertiesData.length === 0) {
|
|
95
92
|
return itemData
|
|
96
93
|
}
|
|
97
94
|
|
|
98
|
-
const firstPropertyData = propertiesData[0]
|
|
99
|
-
|
|
100
95
|
for (const propertyData of propertiesData) {
|
|
101
96
|
const propertyName = propertyData.propertyName
|
|
102
97
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// if (refSeedType) {
|
|
112
|
-
// initObj.refSeedType = refSeedType
|
|
113
|
-
// }
|
|
114
|
-
// const refValueType = propertyDbValues[12]
|
|
115
|
-
// if (refValueType) {
|
|
116
|
-
// initObj.refValueType = refValueType
|
|
117
|
-
// }
|
|
118
|
-
//
|
|
119
|
-
// if (
|
|
120
|
-
// refSeedType &&
|
|
121
|
-
// refValueType === 'list' &&
|
|
122
|
-
// propertyName.endsWith('Ids')
|
|
123
|
-
// ) {
|
|
124
|
-
// logger('[db/queries] [getItemDataFromDb] propertyName', propertyName)
|
|
125
|
-
// }
|
|
98
|
+
let propertyValue = propertyData.propertyValue
|
|
99
|
+
|
|
100
|
+
if (propertyName.endsWith('Id') || propertyName.endsWith('Ids')) {
|
|
101
|
+
if (propertyData.refSeedType) {
|
|
102
|
+
const propertyNameVariant = propertyName.replace(/Ids?$/, '')
|
|
103
|
+
itemData[propertyNameVariant] = propertyValue
|
|
104
|
+
}
|
|
105
|
+
}
|
|
126
106
|
|
|
127
107
|
itemData[propertyName] = propertyValue
|
|
128
108
|
}
|