@seedprotocol/sdk 0.1.84 → 0.1.85

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 (38) hide show
  1. package/dist/{index-CBTE_R-7.js → index-BFSW1upn.js} +2 -2
  2. package/dist/{index-CBTE_R-7.js.map → index-BFSW1upn.js.map} +1 -1
  3. package/dist/{index-JmHVBmP7.js → index-D0rjBEnK.js} +47 -49
  4. package/dist/index-D0rjBEnK.js.map +1 -0
  5. package/dist/main.js +1 -1
  6. package/dist/{seed.schema.config-BSTzpuJg.js → seed.schema.config-DjUwnjlb.js} +2 -2
  7. package/dist/{seed.schema.config-BSTzpuJg.js.map → seed.schema.config-DjUwnjlb.js.map} +1 -1
  8. package/dist/src/actors.ts +289 -7
  9. package/dist/src/dbMachine.ts +1 -6
  10. package/dist/src/download.ts +6 -3
  11. package/dist/src/index.ts +62 -10
  12. package/dist/src/syncDbWithEas.ts +12 -3
  13. package/dist/src/waitForFiles.ts +1 -1
  14. package/dist/types/src/browser/db/read/subqueries/versionData.d.ts +16 -4
  15. package/dist/types/src/browser/db/read/subqueries/versionData.d.ts.map +1 -1
  16. package/dist/types/src/browser/events/files/download.d.ts.map +1 -1
  17. package/dist/types/src/browser/events/item/syncDbWithEas.d.ts.map +1 -1
  18. package/dist/types/src/browser/services/db/dbMachine.d.ts.map +1 -1
  19. package/dist/types/src/shared/helpers/files.d.ts +1 -1
  20. package/dist/types/src/shared/helpers/files.d.ts.map +1 -1
  21. package/dist/types/src/shared/seedSchema/AppStateSchema.d.ts +12 -4
  22. package/dist/types/src/shared/seedSchema/AppStateSchema.d.ts.map +1 -1
  23. package/dist/types/src/shared/seedSchema/ConfigSchema.d.ts +16 -7
  24. package/dist/types/src/shared/seedSchema/ConfigSchema.d.ts.map +1 -1
  25. package/dist/types/src/shared/seedSchema/MetadataSchema.d.ts +82 -22
  26. package/dist/types/src/shared/seedSchema/MetadataSchema.d.ts.map +1 -1
  27. package/dist/types/src/shared/seedSchema/ModelSchema.d.ts +32 -10
  28. package/dist/types/src/shared/seedSchema/ModelSchema.d.ts.map +1 -1
  29. package/dist/types/src/shared/seedSchema/ModelUidSchema.d.ts +8 -3
  30. package/dist/types/src/shared/seedSchema/ModelUidSchema.d.ts.map +1 -1
  31. package/dist/types/src/shared/seedSchema/PropertyUidSchema.d.ts +8 -3
  32. package/dist/types/src/shared/seedSchema/PropertyUidSchema.d.ts.map +1 -1
  33. package/dist/types/src/shared/seedSchema/SeedSchema.d.ts +28 -9
  34. package/dist/types/src/shared/seedSchema/SeedSchema.d.ts.map +1 -1
  35. package/dist/types/src/shared/seedSchema/VersionSchema.d.ts +34 -10
  36. package/dist/types/src/shared/seedSchema/VersionSchema.d.ts.map +1 -1
  37. package/package.json +50 -50
  38. package/dist/index-JmHVBmP7.js.map +0 -1
package/dist/main.js CHANGED
@@ -1,4 +1,4 @@
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-JmHVBmP7.js';
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-D0rjBEnK.js';
2
2
  import 'immer';
3
3
  import 'reflect-metadata';
4
4
  import './constants-rmQ8zg8_.js';
@@ -1,6 +1,6 @@
1
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-JmHVBmP7.js';
3
+ import { T as Text, M as Model } from './index-D0rjBEnK.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-BSTzpuJg.js.map
79
+ //# sourceMappingURL=seed.schema.config-DjUwnjlb.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"seed.schema.config-BSTzpuJg.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;;;;;"}
1
+ {"version":3,"file":"seed.schema.config-DjUwnjlb.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;;;;;"}
@@ -1,10 +1,292 @@
1
1
  import { EventObject, fromCallback } from 'xstate'
2
- import { uploadMachine } from '@/browser/schema/file/upload/index'
2
+ import { fetchAllFilesMachine } from '@/browser/schema/file/fetchAll/index'
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'
3
17
 
4
- export const uploadBinaryData = fromCallback<EventObject, typeof uploadMachine>(
5
- ({ sendBack, receive, input }) => {},
6
- )
18
+ import { saveAppState } from '@/browser/db/write/saveAppState'
7
19
 
8
- export const uploadMetadata = fromCallback<EventObject, typeof uploadMachine>(
9
- ({ sendBack, receive, input }) => {},
10
- )
20
+ const logger = debug('app:file:actors:fetchAll')
21
+
22
+ type FileType = {
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
+ let mimeType = getMimeType(dataString as string)
231
+ let fileExtension = mimeType
232
+
233
+ if (fileExtension && fileExtension?.startsWith('image')) {
234
+ fileExtension = fileExtension.replace('image/', '')
235
+ }
236
+
237
+ let fileName = transactionId
238
+
239
+ if (contentType === 'base64') {
240
+ if (mimeType) {
241
+ fileName += `.${fileExtension}`
242
+ }
243
+
244
+ // Remove the Base64 header if it exists (e.g., "data:image/png;base64,")
245
+ const base64Data = dataString.split(',').pop() || ''
246
+
247
+ // Decode the Base64 string to binary
248
+ const binaryString = atob(base64Data)
249
+ const length = binaryString.length
250
+ const binaryData = new Uint8Array(length)
251
+
252
+ for (let i = 0; i < length; i++) {
253
+ binaryData[i] = binaryString.charCodeAt(i)
254
+ }
255
+
256
+ console.log(`attempting to writeFile to /files/images/${fileName}`)
257
+
258
+ await fs.promises.writeFile(`/files/images/${fileName}`, binaryData, {
259
+ encoding: 'binary',
260
+ })
261
+
262
+ // if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
263
+ // await fs.promises.writeFile(
264
+ // `/files/images/${fileName}`,
265
+ // dataUint8Array,
266
+ // )
267
+ // }
268
+ }
269
+
270
+ if (contentType === 'html') {
271
+ fileName += '.html'
272
+ await fs.promises.writeFile(`/files/html/${fileName}`, dataString)
273
+ }
274
+
275
+ if (contentType === 'json') {
276
+ fileName += '.json'
277
+ await fs.promises.writeFile(`/files/json/${fileName}`, dataString)
278
+ }
279
+ } catch (error) {
280
+ logger(error)
281
+ }
282
+ }
283
+
284
+ return []
285
+ }
286
+
287
+ _fetchAllBinaryData().then((binaryData) => {
288
+ sendBack({ type: 'fetchingAllBinaryDataSuccess', binaryData })
289
+ })
290
+
291
+ return () => {}
292
+ })
@@ -1,4 +1,4 @@
1
- import { assign, emit, setup } from 'xstate'
1
+ import { assign, setup } from 'xstate'
2
2
  import {
3
3
  DB_CHECK_STATUS_EXISTS,
4
4
  DB_CHECK_STATUS_UPDATE_PATHS,
@@ -146,11 +146,6 @@ const dbMachine = setup({
146
146
  },
147
147
  [DB_MIGRATING_SUCCESS]: 'ready',
148
148
  },
149
- entry: ({ context }) => {
150
- if (context.hasFiles) {
151
- emit({ type: DB_WAITING_FOR_FILES_RECEIVED })
152
- }
153
- },
154
149
  },
155
150
  [MIGRATING]: {
156
151
  on: {
@@ -157,7 +157,7 @@ export const downloadAllFilesBinaryRequestHandler = async () => {
157
157
  }),
158
158
  })
159
159
 
160
- if (tags && tags.length === 0) {
160
+ if (tags && tags.length > 0) {
161
161
  for (const { name, value } of tags) {
162
162
  if (name === 'Content-SHA-256') {
163
163
  const metadataRecord = await getMetadata({
@@ -176,10 +176,12 @@ export const downloadAllFilesBinaryRequestHandler = async () => {
176
176
  const dataString = await queryClient.fetchQuery({
177
177
  queryKey: ['fetchTransaction', transactionId],
178
178
  queryFn: async () => {
179
- const response = await fetch(`https://${ARWEAVE_HOST}/raw/${transactionId}`)
179
+ const response = await fetch(
180
+ `https://${ARWEAVE_HOST}/raw/${transactionId}`,
181
+ )
180
182
  return await response.text()
181
183
  },
182
- networkMode: "offlineFirst"
184
+ networkMode: 'offlineFirst',
183
185
  })
184
186
 
185
187
  // const dataString = await arweave.transactions.getData(transactionId, {
@@ -250,6 +252,7 @@ export const downloadAllFilesBinaryRequestHandler = async () => {
250
252
 
251
253
  if (fileExtension && fileExtension?.startsWith('image')) {
252
254
  fileExtension = fileExtension.replace('image/', '')
255
+ }
253
256
 
254
257
  let fileName = transactionId
255
258
 
package/dist/src/index.ts CHANGED
@@ -1,21 +1,73 @@
1
- import { setup } from 'xstate'
1
+ import { assign, setup } from 'xstate'
2
2
  import {
3
- uploadBinaryData,
4
- uploadMetadata,
5
- } from '@/browser/schema/file/upload/actors'
3
+ fetchAllBinaryData,
4
+ fetchAllMetadataRecords,
5
+ } from '@/browser/schema/file/fetchAll/actors'
6
+ import { Attestation } from '@/browser/gql/graphql'
6
7
 
7
- export const uploadMachine = setup({
8
+ type FetchAllFilesMachineContext = {
9
+ addresses: string[]
10
+ dbsLoaded: boolean
11
+ filesMetadata?: Attestation[]
12
+ filesBlobData?: any[]
13
+ }
14
+
15
+ export const fetchAllFilesMachine = setup({
16
+ types: {
17
+ context: {} as FetchAllFilesMachineContext,
18
+ },
8
19
  actors: {
9
- uploadBinaryData,
10
- uploadMetadata,
20
+ fetchAllMetadataRecords,
21
+ fetchAllBinaryData,
11
22
  },
12
23
  }).createMachine({
13
- id: 'upload',
24
+ id: 'fetchAllFiles',
14
25
  initial: 'idle',
15
- context: {
16
- file: '',
26
+ context: ({ input }) =>
27
+ ({
28
+ ...input,
29
+ dbsLoaded: false,
30
+ }) as FetchAllFilesMachineContext,
31
+ on: {
32
+ allDbsLoaded: {
33
+ target: '.fetchingAllMetadataRecords',
34
+ actions: assign({
35
+ dbsLoaded: true,
36
+ }),
37
+ },
17
38
  },
18
39
  states: {
19
40
  idle: {},
41
+ fetchingAllMetadataRecords: {
42
+ on: {
43
+ fetchingAllMetadataRecordsSuccess: {
44
+ target: 'fetchingAllBinaryData',
45
+ actions: assign({
46
+ filesMetadata: ({ event }) => event.filesMetadata,
47
+ }),
48
+ },
49
+ },
50
+ invoke: {
51
+ src: 'fetchAllMetadataRecords',
52
+ input: ({ context, event }) => ({ context, event }),
53
+ },
54
+ },
55
+ fetchingAllBinaryData: {
56
+ on: {
57
+ fetchingAllBinaryDataSuccess: {
58
+ target: 'success',
59
+ actions: assign({
60
+ filesBlobData: ({ event }) => event.filesBlobData,
61
+ }),
62
+ },
63
+ },
64
+ invoke: {
65
+ src: 'fetchAllBinaryData',
66
+ input: ({ context }) => ({ context }),
67
+ },
68
+ },
69
+ success: {
70
+ type: 'final',
71
+ },
20
72
  },
21
73
  })
@@ -1,4 +1,4 @@
1
- import { camelCase, debounce, DebouncedFunc, startCase } from 'lodash-es'
1
+ import { camelCase, DebouncedFunc, startCase, throttle } from 'lodash-es'
2
2
  import { Attestation, SchemaWhereInput } from '@/browser/gql/graphql'
3
3
  import {
4
4
  metadata,
@@ -375,10 +375,17 @@ type SaveEasPropertiesToDb = (
375
375
  props: SaveEasPropertiesToDbParams,
376
376
  ) => Promise<Record<string, unknown>>
377
377
 
378
+ let isSavingToDb = false
379
+
378
380
  const saveEasPropertiesToDb: SaveEasPropertiesToDb = async ({
379
381
  itemProperties,
380
382
  itemSeeds,
381
383
  }) => {
384
+ if (isSavingToDb) {
385
+ return
386
+ }
387
+ isSavingToDb = true
388
+
382
389
  const propertyUids = itemProperties.map((property) => property.id)
383
390
 
384
391
  const models = getModels()
@@ -546,6 +553,8 @@ const saveEasPropertiesToDb: SaveEasPropertiesToDb = async ({
546
553
 
547
554
  await appDb.run(sql.raw(insertPropertiesQuery))
548
555
 
556
+ isSavingToDb = false
557
+
549
558
  return { propertyUids }
550
559
  }
551
560
 
@@ -586,7 +595,7 @@ const getRelatedSeedsAndVersions = async () => {
586
595
  })
587
596
  }
588
597
 
589
- const syncDbWithEasHandler: DebouncedFunc<any> = debounce(
598
+ const syncDbWithEasHandler: DebouncedFunc<any> = throttle(
590
599
  async (_) => {
591
600
  const appDb = getAppDb()
592
601
 
@@ -676,7 +685,7 @@ const syncDbWithEasHandler: DebouncedFunc<any> = debounce(
676
685
  eventEmitter.emit('item.requestAll', { modelName })
677
686
  }
678
687
  },
679
- 10000,
688
+ 30000,
680
689
  {
681
690
  leading: true,
682
691
  trailing: false,
@@ -16,7 +16,7 @@ export const waitForFiles = fromCallback<
16
16
  return new Promise((resolve) => {
17
17
  const interval = setInterval(async () => {
18
18
  const journalExists = await fs.promises.exists(
19
- `${pathToDbDir}/meta/_journaljson`,
19
+ `${pathToDbDir}/meta/_journal.json`,
20
20
  )
21
21
  if (journalExists) {
22
22
  clearInterval(interval)
@@ -13,8 +13,11 @@ export declare const getVersionData: () => import("drizzle-orm/sqlite-core").Wit
13
13
  hasRuntimeDefault: false;
14
14
  enumValues: [string, ...string[]];
15
15
  baseColumn: never;
16
+ identity: undefined;
16
17
  generated: undefined;
17
- }, object>;
18
+ }, {}, {
19
+ length: number | undefined;
20
+ }>;
18
21
  seedUid: import("drizzle-orm/sqlite-core").SQLiteColumn<{
19
22
  name: "seed_uid";
20
23
  tableName: "versions";
@@ -29,8 +32,11 @@ export declare const getVersionData: () => import("drizzle-orm/sqlite-core").Wit
29
32
  hasRuntimeDefault: false;
30
33
  enumValues: [string, ...string[]];
31
34
  baseColumn: never;
35
+ identity: undefined;
32
36
  generated: undefined;
33
- }, object>;
37
+ }, {}, {
38
+ length: number | undefined;
39
+ }>;
34
40
  latestVersionUid: import("drizzle-orm/sqlite-core").SQLiteColumn<{
35
41
  name: "uid";
36
42
  tableName: "versions";
@@ -45,8 +51,11 @@ export declare const getVersionData: () => import("drizzle-orm/sqlite-core").Wit
45
51
  hasRuntimeDefault: false;
46
52
  enumValues: [string, ...string[]];
47
53
  baseColumn: never;
54
+ identity: undefined;
48
55
  generated: undefined;
49
- }, object>;
56
+ }, {}, {
57
+ length: number | undefined;
58
+ }>;
50
59
  latestVersionLocalId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
51
60
  name: "local_id";
52
61
  tableName: "versions";
@@ -61,8 +70,11 @@ export declare const getVersionData: () => import("drizzle-orm/sqlite-core").Wit
61
70
  hasRuntimeDefault: false;
62
71
  enumValues: [string, ...string[]];
63
72
  baseColumn: never;
73
+ identity: undefined;
64
74
  generated: undefined;
65
- }, object>;
75
+ }, {}, {
76
+ length: number | undefined;
77
+ }>;
66
78
  versionsCount: import("drizzle-orm").SQL.Aliased<number>;
67
79
  lastVersionPublishedAt: import("drizzle-orm").SQL.Aliased<number | null>;
68
80
  lastLocalUpdateAt: import("drizzle-orm").SQL.Aliased<number | null>;
@@ -1 +1 @@
1
- {"version":3,"file":"versionData.d.ts","sourceRoot":"","sources":["../../../../../../../src/browser/db/read/subqueries/versionData.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmB1B,CAAA"}
1
+ {"version":3,"file":"versionData.d.ts","sourceRoot":"","sources":["../../../../../../../src/browser/db/read/subqueries/versionData.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmB1B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/events/files/download.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,8BAA8B;;;mBAQ1C,CAAA;AAED,eAAO,MAAM,oCAAoC,oCAqQhD,CAAA"}
1
+ {"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/events/files/download.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,8BAA8B;;;mBAQ1C,CAAA;AAED,eAAO,MAAM,oCAAoC,oCAwQhD,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"syncDbWithEas.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/events/item/syncDbWithEas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,aAAa,EAAa,MAAM,WAAW,CAAA;AA4kBzE,QAAA,MAAM,oBAAoB,EAAE,aAAa,CAAC,GAAG,CA+F5C,CAAA;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAA"}
1
+ {"version":3,"file":"syncDbWithEas.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/events/item/syncDbWithEas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,aAAa,EAAuB,MAAM,WAAW,CAAA;AAqlBzE,QAAA,MAAM,oBAAoB,EAAE,aAAa,CAAC,GAAG,CA+F5C,CAAA;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"dbMachine.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/services/db/dbMachine.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAgB1C,QAAA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6JAoJb,CAAA;AAEF,OAAO,EAAE,SAAS,EAAE,CAAA"}
1
+ {"version":3,"file":"dbMachine.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/services/db/dbMachine.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAgB1C,QAAA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6JA+Ib,CAAA;AAEF,OAAO,EAAE,SAAS,EAAE,CAAA"}
@@ -1,2 +1,2 @@
1
- export declare const listFilesInOPFSRoot: () => Promise<string[]>;
1
+ export declare const listFilesInOPFSRoot: () => Promise<any[]>;
2
2
  //# sourceMappingURL=files.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../../../src/shared/helpers/files.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,yBAe/B,CAAA"}
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../../../src/shared/helpers/files.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,sBAe/B,CAAA"}
@@ -16,8 +16,11 @@ export declare const appState: import("drizzle-orm/sqlite-core").SQLiteTableWith
16
16
  hasRuntimeDefault: false;
17
17
  enumValues: [string, ...string[]];
18
18
  baseColumn: never;
19
+ identity: undefined;
19
20
  generated: undefined;
20
- }, object>;
21
+ }, {}, {
22
+ length: number | undefined;
23
+ }>;
21
24
  value: import("drizzle-orm/sqlite-core").SQLiteColumn<{
22
25
  name: "value";
23
26
  tableName: "appState";
@@ -32,8 +35,11 @@ export declare const appState: import("drizzle-orm/sqlite-core").SQLiteTableWith
32
35
  hasRuntimeDefault: false;
33
36
  enumValues: [string, ...string[]];
34
37
  baseColumn: never;
38
+ identity: undefined;
35
39
  generated: undefined;
36
- }, object>;
40
+ }, {}, {
41
+ length: number | undefined;
42
+ }>;
37
43
  createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
38
44
  name: "created_at";
39
45
  tableName: "appState";
@@ -48,8 +54,9 @@ export declare const appState: import("drizzle-orm/sqlite-core").SQLiteTableWith
48
54
  hasRuntimeDefault: false;
49
55
  enumValues: undefined;
50
56
  baseColumn: never;
57
+ identity: undefined;
51
58
  generated: undefined;
52
- }, object>;
59
+ }, {}, {}>;
53
60
  updatedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
54
61
  name: "updated_at";
55
62
  tableName: "appState";
@@ -64,8 +71,9 @@ export declare const appState: import("drizzle-orm/sqlite-core").SQLiteTableWith
64
71
  hasRuntimeDefault: false;
65
72
  enumValues: undefined;
66
73
  baseColumn: never;
74
+ identity: undefined;
67
75
  generated: undefined;
68
- }, object>;
76
+ }, {}, {}>;
69
77
  };
70
78
  dialect: "sqlite";
71
79
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"AppStateSchema.d.ts","sourceRoot":"","sources":["../../../../../src/shared/seedSchema/AppStateSchema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKnB,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAA"}
1
+ {"version":3,"file":"AppStateSchema.d.ts","sourceRoot":"","sources":["../../../../../src/shared/seedSchema/AppStateSchema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKnB,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAA"}