@seedprotocol/sdk 0.2.51 → 0.2.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/dist/{ArweaveClient-D1TsTBoj.js → ArweaveClient-D5iJisYr.js} +2 -2
  2. package/dist/{ArweaveClient-DpdXUcVJ.js.map → ArweaveClient-D5iJisYr.js.map} +1 -1
  3. package/dist/{ArweaveClient-DpdXUcVJ.js → ArweaveClient-HEIIuOfB.js} +2 -2
  4. package/dist/{ArweaveClient-D1TsTBoj.js.map → ArweaveClient-HEIIuOfB.js.map} +1 -1
  5. package/dist/{Db-quJxmvHH.js → Db-D-BsZYlN.js} +3 -3
  6. package/dist/{Db-quJxmvHH.js.map → Db-D-BsZYlN.js.map} +1 -1
  7. package/dist/{Db-DMJ0v3gO.js → Db-Dpsbk_T7.js} +3 -3
  8. package/dist/{Db-DMJ0v3gO.js.map → Db-Dpsbk_T7.js.map} +1 -1
  9. package/dist/{EasClient-ClZDuT3o.js → EasClient-D3wKgt0o.js} +2 -2
  10. package/dist/{EasClient-DfnGY_2X.js.map → EasClient-D3wKgt0o.js.map} +1 -1
  11. package/dist/{EasClient-DfnGY_2X.js → EasClient-jqkT2ZBt.js} +2 -2
  12. package/dist/{EasClient-ClZDuT3o.js.map → EasClient-jqkT2ZBt.js.map} +1 -1
  13. package/dist/{FileManager-texI7UwL.js → FileManager-4mWYO3Mt.js} +3 -5
  14. package/dist/FileManager-4mWYO3Mt.js.map +1 -0
  15. package/dist/{Item-D4n439Ei.js → Item-CqWdJsyg.js} +3 -3
  16. package/dist/{Item-D4n439Ei.js.map → Item-CqWdJsyg.js.map} +1 -1
  17. package/dist/{ItemProperty-Be5ymRVT.js → ItemProperty-BpBW3IWx.js} +3 -3
  18. package/dist/{ItemProperty-Be5ymRVT.js.map → ItemProperty-BpBW3IWx.js.map} +1 -1
  19. package/dist/{QueryClient-B1HkAaJo.js → QueryClient-CBOP3OoU.js} +2 -2
  20. package/dist/{QueryClient-B1HkAaJo.js.map → QueryClient-CBOP3OoU.js.map} +1 -1
  21. package/dist/{QueryClient-BPoc9eBn.js → QueryClient-bKb3SB0W.js} +2 -2
  22. package/dist/{QueryClient-BPoc9eBn.js.map → QueryClient-bKb3SB0W.js.map} +1 -1
  23. package/dist/bin.js +5 -5
  24. package/dist/{constants-5PxfAeqj.js → constants-CIDbABDz.js} +2 -2
  25. package/dist/{constants-5PxfAeqj.js.map → constants-CIDbABDz.js.map} +1 -1
  26. package/dist/{index-BeKRizLf.js → index-BRxO1tLl.js} +257 -145
  27. package/dist/index-BRxO1tLl.js.map +1 -0
  28. package/dist/{index-BLla2o05.js → index-d8Qsot6w.js} +3 -3
  29. package/dist/index-d8Qsot6w.js.map +1 -0
  30. package/dist/main.js +2 -2
  31. package/dist/package.json +189 -0
  32. package/dist/{seed.schema.config-CMpV_hyS.js → seed.schema.config-CPRn6KVL.js} +3 -3
  33. package/dist/{seed.schema.config-CMpV_hyS.js.map → seed.schema.config-CPRn6KVL.js.map} +1 -1
  34. package/dist/types/src/client/BaseClientManager.d.ts +7 -0
  35. package/dist/types/src/client/BaseClientManager.d.ts.map +1 -0
  36. package/dist/types/src/client/actions/setAddresses.d.ts +2 -0
  37. package/dist/types/src/client/actions/setAddresses.d.ts.map +1 -0
  38. package/dist/types/src/client/actors/initialize.d.ts +4 -0
  39. package/dist/types/src/client/actors/initialize.d.ts.map +1 -0
  40. package/dist/types/src/client/actors/saveAppState.d.ts +5 -0
  41. package/dist/types/src/client/actors/saveAppState.d.ts.map +1 -0
  42. package/dist/types/src/client/clientManagerMachine.d.ts +19 -0
  43. package/dist/types/src/client/clientManagerMachine.d.ts.map +1 -0
  44. package/dist/types/src/client/index.d.ts +41 -0
  45. package/dist/types/src/client/index.d.ts.map +1 -0
  46. package/dist/types/src/client.d.ts.map +1 -1
  47. package/dist/types/src/node/helpers/FileManager.d.ts.map +1 -1
  48. package/dist/types/src/services/internal/actors/validateInput.d.ts.map +1 -1
  49. package/dist/types/src/types/machines.d.ts +5 -0
  50. package/dist/types/src/types/machines.d.ts.map +1 -1
  51. package/package.json +2 -2
  52. package/dist/FileManager-texI7UwL.js.map +0 -1
  53. package/dist/index-BLla2o05.js.map +0 -1
  54. package/dist/index-BeKRizLf.js.map +0 -1
  55. package/dist/src/AppStateSchema.ts +0 -10
  56. package/dist/src/ArweaveClient.ts +0 -13
  57. package/dist/src/Attestation.ts +0 -21
  58. package/dist/src/BaseArweaveClient.ts +0 -13
  59. package/dist/src/BaseDb.ts +0 -35
  60. package/dist/src/BaseEasClient.ts +0 -13
  61. package/dist/src/BaseFileManager.ts +0 -56
  62. package/dist/src/BaseItem.ts +0 -413
  63. package/dist/src/BaseItemProperty.ts +0 -416
  64. package/dist/src/BaseQueryClient.ts +0 -13
  65. package/dist/src/ConfigSchema.ts +0 -15
  66. package/dist/src/Db.ts +0 -78
  67. package/dist/src/EasClient.ts +0 -13
  68. package/dist/src/FileDownloader.ts +0 -63
  69. package/dist/src/FileManager.ts +0 -57
  70. package/dist/src/IDb.ts +0 -7
  71. package/dist/src/IEasClient.ts +0 -2
  72. package/dist/src/IItem.ts +0 -26
  73. package/dist/src/IItemProperty.ts +0 -28
  74. package/dist/src/IQueryClient.ts +0 -4
  75. package/dist/src/ImageResizer.ts +0 -81
  76. package/dist/src/Item.ts +0 -12
  77. package/dist/src/ItemProperty.ts +0 -9
  78. package/dist/src/MetadataSchema.ts +0 -28
  79. package/dist/src/ModelSchema.ts +0 -46
  80. package/dist/src/ModelUidSchema.ts +0 -16
  81. package/dist/src/PropertyUidSchema.ts +0 -16
  82. package/dist/src/QueryClient.ts +0 -22
  83. package/dist/src/Schema.ts +0 -17
  84. package/dist/src/SeedProtocolSdk.d.ts +0 -19
  85. package/dist/src/SeedSchema.ts +0 -29
  86. package/dist/src/VersionSchema.ts +0 -16
  87. package/dist/src/actors.ts +0 -295
  88. package/dist/src/addModelsToDb.ts +0 -152
  89. package/dist/src/allItems.ts +0 -31
  90. package/dist/src/analyzeInput.ts +0 -144
  91. package/dist/src/browser.app.db.config.ts +0 -27
  92. package/dist/src/browser.ts +0 -30
  93. package/dist/src/checkStatus.ts +0 -50
  94. package/dist/src/client.ts +0 -148
  95. package/dist/src/configureFs.ts +0 -94
  96. package/dist/src/connectToDb.ts +0 -41
  97. package/dist/src/connectionManager.ts +0 -67
  98. package/dist/src/constants.ts +0 -125
  99. package/dist/src/content-hash.ts +0 -30
  100. package/dist/src/create.ts +0 -39
  101. package/dist/src/createMetadata.ts +0 -77
  102. package/dist/src/createNewItem.ts +0 -61
  103. package/dist/src/createPublishAttempt.ts +0 -16
  104. package/dist/src/createSeed.ts +0 -31
  105. package/dist/src/createSeeds.ts +0 -24
  106. package/dist/src/createVersion.ts +0 -33
  107. package/dist/src/dbMachine.ts +0 -182
  108. package/dist/src/deleteItem.ts +0 -19
  109. package/dist/src/download.ts +0 -202
  110. package/dist/src/drizzle.ts +0 -78
  111. package/dist/src/eas.ts +0 -40
  112. package/dist/src/environment.ts +0 -35
  113. package/dist/src/eventBus.ts +0 -5
  114. package/dist/src/events.ts +0 -14
  115. package/dist/src/fetchDataFromEas.ts +0 -94
  116. package/dist/src/fetchDbData.ts +0 -19
  117. package/dist/src/fetchRelatedItems.ts +0 -184
  118. package/dist/src/fetchSeeds.ts +0 -52
  119. package/dist/src/fetchVersions.ts +0 -49
  120. package/dist/src/files.ts +0 -81
  121. package/dist/src/filesDownload.ts +0 -326
  122. package/dist/src/fragment-masking.ts +0 -87
  123. package/dist/src/getExistingItem.ts +0 -60
  124. package/dist/src/getItem.ts +0 -32
  125. package/dist/src/getItemData.ts +0 -99
  126. package/dist/src/getItemProperties.ts +0 -56
  127. package/dist/src/getItemProperty.ts +0 -34
  128. package/dist/src/getItems.ts +0 -70
  129. package/dist/src/getMetadata.ts +0 -40
  130. package/dist/src/getModelSchemas.ts +0 -89
  131. package/dist/src/getPropertyData.ts +0 -50
  132. package/dist/src/getPublishPayload.ts +0 -355
  133. package/dist/src/getPublishUploads.ts +0 -207
  134. package/dist/src/getRelationValueData.ts +0 -27
  135. package/dist/src/getSchemaForItemProperty.ts +0 -68
  136. package/dist/src/getSchemaForModel.ts +0 -42
  137. package/dist/src/getSchemaUidForModel.ts +0 -32
  138. package/dist/src/getSeedData.ts +0 -34
  139. package/dist/src/getSegmentedItemProperties.ts +0 -65
  140. package/dist/src/getStorageTransactionIdForSeedUid.ts +0 -38
  141. package/dist/src/getVersionData.ts +0 -46
  142. package/dist/src/getVersionsForVersionUids.ts +0 -39
  143. package/dist/src/globalMachine.ts +0 -280
  144. package/dist/src/gql.ts +0 -118
  145. package/dist/src/graphql.ts +0 -3209
  146. package/dist/src/helpers.ts +0 -273
  147. package/dist/src/hydrateExistingItem.ts +0 -137
  148. package/dist/src/hydrateFromDb.ts +0 -270
  149. package/dist/src/hydrateNewItem.ts +0 -34
  150. package/dist/src/imageResize.ts +0 -507
  151. package/dist/src/index.d.ts +0 -5
  152. package/dist/src/index.ts +0 -4
  153. package/dist/src/initialize.ts +0 -124
  154. package/dist/src/internalMachine.ts +0 -238
  155. package/dist/src/itemMachineAll.ts +0 -157
  156. package/dist/src/itemMachineSingle.ts +0 -158
  157. package/dist/src/loadAppDb.ts +0 -47
  158. package/dist/src/machines.ts +0 -60
  159. package/dist/src/metadataLatest.ts +0 -34
  160. package/dist/src/migrate.ts +0 -53
  161. package/dist/src/model.ts +0 -72
  162. package/dist/src/modelClass.ts +0 -19
  163. package/dist/src/node.app.db.config.ts +0 -41
  164. package/dist/src/prepareDb.ts +0 -29
  165. package/dist/src/preparePublishRequestData.ts +0 -81
  166. package/dist/src/processItems.ts +0 -74
  167. package/dist/src/property.ts +0 -156
  168. package/dist/src/propertyMachine.ts +0 -202
  169. package/dist/src/publish.ts +0 -28
  170. package/dist/src/publishMachine.ts +0 -77
  171. package/dist/src/queries.ts +0 -13
  172. package/dist/src/recoverDeletedItem.ts +0 -14
  173. package/dist/src/reload.ts +0 -33
  174. package/dist/src/request.ts +0 -45
  175. package/dist/src/requestAll.ts +0 -157
  176. package/dist/src/resolveRelatedValue.ts +0 -367
  177. package/dist/src/resolveRemoteStorage.ts +0 -88
  178. package/dist/src/saveAppState.ts +0 -19
  179. package/dist/src/saveConfig.ts +0 -88
  180. package/dist/src/saveDataToDb.ts +0 -145
  181. package/dist/src/saveImageSrc.ts +0 -242
  182. package/dist/src/saveItemStorage.ts +0 -156
  183. package/dist/src/saveMetadata.ts +0 -18
  184. package/dist/src/savePublishService.ts +0 -30
  185. package/dist/src/saveRelation.ts +0 -112
  186. package/dist/src/seed.schema.config.ts +0 -25
  187. package/dist/src/seed.ts +0 -10
  188. package/dist/src/seedProtocol.ts +0 -17
  189. package/dist/src/services.ts +0 -365
  190. package/dist/src/sqlWasmClient.ts +0 -88
  191. package/dist/src/syncDbWithEas.ts +0 -628
  192. package/dist/src/trash.ts +0 -29
  193. package/dist/src/ts-to-proto.ts +0 -101
  194. package/dist/src/types.ts +0 -12
  195. package/dist/src/updateItemPropertyValue.ts +0 -243
  196. package/dist/src/updateMachineContext.ts +0 -21
  197. package/dist/src/updateMetadata.ts +0 -59
  198. package/dist/src/upload.ts +0 -86
  199. package/dist/src/validate.ts +0 -45
  200. package/dist/src/validateInput.ts +0 -47
  201. package/dist/src/validateItemData.ts +0 -20
  202. package/dist/src/versionData.ts +0 -24
  203. package/dist/src/waitForDb.ts +0 -25
  204. package/dist/src/waitForFiles.ts +0 -34
  205. package/dist/src/wasm.d.ts +0 -8300
@@ -1,28 +0,0 @@
1
- import { ActorRefFrom, Subscription } from 'xstate';
2
- import { BehaviorSubject } from 'rxjs';
3
- import { Static } from '@sinclair/typebox';
4
- import { TProperty } from '@/schema';
5
- import { CreatePropertyInstanceProps } from '@/types';
6
-
7
- export interface IItemProperty<PropertyType> {
8
-
9
- readonly localId: string;
10
- readonly uid: string;
11
- readonly seedLocalId: string;
12
- readonly seedUid: string;
13
- readonly schemaUid: string;
14
- readonly propertyName: string;
15
- readonly modelName: string;
16
- readonly propertyDef: Static<typeof TProperty> | undefined;
17
- readonly localStoragePath: string | void;
18
- readonly versionLocalId: string | undefined;
19
- readonly status: any;
20
- readonly alias: string | undefined;
21
- value: any;
22
- readonly published: boolean;
23
-
24
- subscribe(callback: Partial<BehaviorSubject<any>>): Subscription;
25
- save(): Promise<void>;
26
- unload(): void;
27
- getService(): ActorRefFrom<any>;
28
- }
@@ -1,4 +0,0 @@
1
- export interface IQueryClient {
2
- fetchQuery: (options: any) => Promise<any>
3
- getQueryData: (queryKey: any) => any
4
- }
@@ -1,81 +0,0 @@
1
- import fs from '@zenfs/core';
2
- import imageResize from './imageResize'
3
- import { FileManager } from '@/browser/helpers/FileManager';
4
-
5
-
6
-
7
- export class ImageResizer {
8
- private cores: number
9
- private workersArchive: Map<string, Worker> = new Map()
10
- private workerBlobUrl: string
11
-
12
- constructor() {
13
- this.cores = Math.min(navigator.hardwareConcurrency || 4, 4);
14
-
15
- this.workerBlobUrl = globalThis.URL.createObjectURL(
16
- new Blob([imageResize], { type: 'application/javascript' })
17
- )
18
- }
19
-
20
- public async resize({filePath, width, height}: ResizeImageParams) {
21
-
22
- if (this.workersArchive.has(filePath)) {
23
- const savedWorker = this.workersArchive.get(filePath)
24
- savedWorker?.terminate()
25
- console.log('[ImageResizer.resize] Terminated worker for filePath due to incoming request', filePath)
26
- this.workersArchive.delete(filePath)
27
- }
28
-
29
- const worker = new Worker(this.workerBlobUrl);
30
-
31
- this.workersArchive.set(filePath, worker)
32
-
33
- return new Promise((resolve, reject) => {
34
- worker.onmessage = (e) => {
35
- console.log('[ImageResizer.resize] main thread onmessage', e.data);
36
- if (e.data.done) {
37
- const savedWorker = this.workersArchive.get(filePath)
38
- savedWorker?.terminate()
39
- console.log('[ImageResizer.resize] Terminated worker for filePath due to done', filePath)
40
- this.workersArchive.delete(filePath)
41
- resolve(e.data)
42
- }
43
-
44
- if (e.data.error) {
45
- reject(e.data.error)
46
- }
47
- }
48
-
49
- worker.postMessage({
50
- filePath,
51
- width,
52
- height,
53
- });
54
- })
55
- }
56
-
57
- public async resizeAll({width, height}: ResizeAllImagesParams) {
58
-
59
- const imageDir = '/files/images'
60
- let imageFilesStats = await fs.promises.readdir(imageDir, {
61
- withFileTypes: true
62
- })
63
-
64
- imageFilesStats = imageFilesStats.filter(file => file.isFile())
65
-
66
- const imageFiles = imageFilesStats.map(file => file.path)
67
-
68
- const widthDir = `${imageDir}/${width}`
69
-
70
- await FileManager.createDirIfNotExists(widthDir)
71
-
72
- for (const imageFile of imageFiles) {
73
- const resizedImageExists = await fs.promises.exists(`${widthDir}/${imageFile}`)
74
- if (!resizedImageExists) {
75
- await this.resize({filePath: `${imageDir}/${imageFile}`, width, height})
76
- }
77
- }
78
-
79
-
80
- }
81
- }
package/dist/src/Item.ts DELETED
@@ -1,12 +0,0 @@
1
- import { IItem } from '@/interfaces';
2
- import { BaseItem } from '@/Item/BaseItem';
3
- import { ModelSchema, ModelValues, NewItemProps } from '@/types';
4
-
5
- export class Item<T extends ModelValues<ModelSchema>> extends BaseItem<T> implements IItem<T> {
6
- constructor(initialValues: NewItemProps<T>) {
7
- super(initialValues);
8
- }
9
-
10
- }
11
-
12
- BaseItem.setPlatformClass(Item)
@@ -1,9 +0,0 @@
1
- import { IItemProperty } from '@/interfaces'
2
- import { BaseItemProperty } from '@/ItemProperty/BaseItemProperty'
3
- import { CreatePropertyInstanceProps, ModelSchema, ModelValues, } from '@/types'
4
-
5
- export class ItemProperty<PropertyType> extends BaseItemProperty<PropertyType> implements IItemProperty<PropertyType> {
6
- constructor(initialValues: Partial<CreatePropertyInstanceProps>) {
7
- super(initialValues)
8
- }
9
- }
@@ -1,28 +0,0 @@
1
- import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core'
2
-
3
- export const metadata = sqliteTable('metadata', {
4
- localId: text('local_id').unique(),
5
- uid: text('uid'),
6
- propertyName: text('property_name'),
7
- propertyValue: text('property_value'),
8
- schemaUid: text('schema_uid'),
9
- modelType: text('model_type'),
10
- seedLocalId: text('seed_local_id'),
11
- seedUid: text('seed_uid'),
12
- versionLocalId: text('version_local_id'),
13
- versionUid: text('version_uid'),
14
- easDataType: text('eas_data_type'),
15
- refValueType: text('ref_value_type'),
16
- refModelUid: text('ref_schema_uid'),
17
- refSeedType: text('ref_seed_type'),
18
- refResolvedValue: text('ref_resolved_value'),
19
- refResolvedDisplayValue: text('ref_resolved_display_value'),
20
- localStorageDir: text('local_storage_dir'),
21
- attestationRaw: text('attestation_raw'),
22
- attestationCreatedAt: int('attestation_created_at'),
23
- contentHash: text('content_hash'),
24
- createdAt: int('created_at'),
25
- updatedAt: int('updated_at'),
26
- })
27
-
28
- export type MetadataType = metadata.$inferSelect
@@ -1,46 +0,0 @@
1
- import { int, sqliteTable, text, unique } from 'drizzle-orm/sqlite-core'
2
- import { relations } from 'drizzle-orm'
3
-
4
- export const models = sqliteTable('models', {
5
- id: int('id').primaryKey({ autoIncrement: true }),
6
- name: text('name').notNull(),
7
- })
8
-
9
- export const modelsRelations = relations(models, ({ many }) => ({
10
- properties: many(properties),
11
- }))
12
-
13
- export type NewModelRecord = typeof models.$inferInsert
14
- export type ModelRecordType = typeof models.$inferSelect
15
-
16
- export const properties = sqliteTable(
17
- 'properties',
18
- {
19
- id: int('id').primaryKey({ autoIncrement: true }),
20
- name: text('name').notNull(),
21
- dataType: text('data_type').notNull(),
22
- readEndpoint: text('read_endpoint'),
23
- updateEndpoint: text('update_endpoint'),
24
- modelId: int('model_id')
25
- .notNull()
26
- .references(() => models.id),
27
- refModelId: int('ref_model_id').references(() => models.id),
28
- refValueType: text('ref_value_type'),
29
- },
30
- (table) => {
31
- return {
32
- uniqueNameModelId: unique('unique_name_model_id').on(
33
- table.name,
34
- table.modelId,
35
- ),
36
- }
37
- },
38
- )
39
-
40
- export const propertiesRelations = relations(properties, ({ one }) => ({
41
- model: one(models),
42
- refModel: one(models),
43
- }))
44
-
45
- export type NewPropertyRecord = typeof properties.$inferInsert
46
- export type PropertyType = typeof properties.$inferSelect
@@ -1,16 +0,0 @@
1
- import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core'
2
- import { relations } from 'drizzle-orm'
3
- import { models } from './ModelSchema'
4
-
5
- export const modelUids = sqliteTable('model_uids', {
6
- id: int('id').primaryKey({ autoIncrement: true }),
7
- uid: text('uid').notNull(),
8
- modelId: int('model_id')
9
- .notNull()
10
- .unique()
11
- .references(() => models.id),
12
- })
13
-
14
- export const modelRelations = relations(modelUids, ({ many, one }) => ({
15
- model: one(models),
16
- }))
@@ -1,16 +0,0 @@
1
- import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core'
2
- import { relations } from 'drizzle-orm'
3
- import { models, properties } from './ModelSchema'
4
-
5
- export const propertyUids = sqliteTable('property_uids', {
6
- id: int('id').primaryKey({ autoIncrement: true }),
7
- uid: text('uid').notNull(),
8
- propertyId: int('property_id')
9
- .notNull()
10
- .unique()
11
- .references(() => models.id),
12
- })
13
-
14
- export const propertyUidRelations = relations(propertyUids, ({ one }) => ({
15
- property: one(properties),
16
- }))
@@ -1,22 +0,0 @@
1
- import { BaseQueryClient } from "@/helpers/QueryClient/BaseQueryClient"
2
-
3
- class QueryClient extends BaseQueryClient {
4
- static getQueryClient() {
5
- return {
6
- fetchQuery: () => {
7
- return new Promise((resolve, reject) => {
8
- reject(new Error('Not implemented'))
9
- })
10
- },
11
- getQueryData: () => {
12
- return new Promise((resolve, reject) => {
13
- reject(new Error('Not implemented'))
14
- })
15
- },
16
- }
17
- }
18
- }
19
-
20
- BaseQueryClient.setPlatformClass(QueryClient)
21
-
22
- export { QueryClient }
@@ -1,17 +0,0 @@
1
- import { graphql, } from '../gql'
2
-
3
- export const SCHEMA_FIELDS = graphql(/* GraphQL */ `
4
- fragment schemaFields on Schema {
5
- id
6
- resolver
7
- revocable
8
- schema
9
- index
10
- schemaNames {
11
- name
12
- }
13
- time
14
- txid
15
- creator
16
- }
17
- `,)
@@ -1,19 +0,0 @@
1
- export interface SeedProtocolSdk {
2
-
3
- getCorrectId: typeof import('@/helpers').getCorrectId;
4
-
5
- // Exported constants
6
- eventEmitter: typeof import('@/eventBus').eventEmitter;
7
-
8
- // Exported types
9
- Model: typeof import('@/schema').Model;
10
- Property: typeof import('@/schema').Property;
11
- ImageSrc: typeof import('@/schema').ImageSrc;
12
- List: typeof import('@/schema').List;
13
- Text: typeof import('@/schema').Text;
14
- Json: typeof import('@/schema').Json;
15
- Relation: typeof import('@/schema').Relation;
16
-
17
- // Node-specific exports
18
- withSeed?: typeof import('@/node').withSeed;
19
- }
@@ -1,29 +0,0 @@
1
- import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core'
2
-
3
- export const seeds = sqliteTable(
4
- 'seeds',
5
- {
6
- localId: text('local_id').unique(),
7
- uid: text('uid'),
8
- schemaUid: text('schema_uid'),
9
- type: text('type'),
10
- attestationRaw: text('attestation_raw'),
11
- attestationCreatedAt: int('attestation_created_at'),
12
- createdAt: int('created_at'),
13
- updatedAt: int('updated_at'),
14
- _markedForDeletion: int('_marked_for_deletion'),
15
- },
16
- // {
17
- // triggers: [
18
- // sql<string>`CREATE TRIGGER IF NOT EXISTS seeds_created_at_trigger
19
- // BEFORE INSERT
20
- // ON seeds
21
- // FOR EACH ROW
22
- // BEGIN
23
- // SELECT strftime('%s', 'now') * 1000 INTO NEW.created_at;
24
- // END;`,
25
- // ],
26
- // },
27
- )
28
-
29
- export type SeedType = seeds.$inferSelect
@@ -1,16 +0,0 @@
1
- import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core'
2
-
3
- export const versions = sqliteTable('versions', {
4
- localId: text('local_id').unique(),
5
- uid: text('uid'),
6
- seedLocalId: text('seed_local_id'),
7
- seedUid: text('seed_uid'),
8
- seedType: text('seed_type'),
9
- note: text('note'),
10
- createdAt: int('created_at'),
11
- updatedAt: int('updated_at'),
12
- attestationCreatedAt: int('attestation_created_at'),
13
- attestationRaw: text('attestation_raw'),
14
- })
15
-
16
- export type VersionsType = versions.$inferSelect
@@ -1,295 +0,0 @@
1
- import { EventObject, fromCallback } from 'xstate'
2
- import { fetchAllFilesMachine } from '@/schema/file/fetchAll/index'
3
- import { ARWEAVE_HOST } from '@/services/internal/constants'
4
- import { GET_FILES_METADATA } from '@/schema/file/queries'
5
- import { getArweave } from '@/helpers/ArweaveClient'
6
- import fs from '@zenfs/core'
7
- import {
8
- getDataTypeFromString,
9
- getMimeType,
10
- identifyString,
11
- } from '@/helpers'
12
- import { appState } from '@/seedSchema'
13
- import { eq } from 'drizzle-orm'
14
- import { BaseEasClient } from '@/helpers/EasClient/BaseEasClient'
15
- import { BaseQueryClient } from '@/helpers/QueryClient/BaseQueryClient'
16
- import debug from 'debug'
17
- import { BaseDb } from '@/db/Db/BaseDb'
18
- import { saveAppState } from '@/db/write/saveAppState'
19
-
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 queryClient = BaseQueryClient.getQueryClient()
44
- const easClient = BaseEasClient.getEasClient()
45
-
46
- const { filesMetadata } = await queryClient.fetchQuery({
47
- queryKey: ['getFilesMetadata', ...addresses],
48
- queryFn: async () =>
49
- easClient.request(GET_FILES_METADATA, {
50
- where: {
51
- attester: {
52
- in: addresses,
53
- },
54
- schema: {
55
- is: {
56
- id: {
57
- equals:
58
- '0x55fdefb36fcbbaebeb7d6b41dc3a1a9666e4e42154267c889de064faa7ede517',
59
- },
60
- },
61
- },
62
- },
63
- }),
64
- })
65
-
66
- return filesMetadata
67
- }
68
-
69
- _fetchAllMetadataRecords().then((filesMetadata) => {
70
- sendBack({ type: 'fetchingAllMetadataRecordsSuccess', filesMetadata })
71
- })
72
-
73
- return () => { }
74
- })
75
-
76
- export const fetchAllBinaryData = fromCallback<
77
- EventObject,
78
- typeof fetchAllFilesMachine
79
- >(({ sendBack, input: { context } }) => {
80
- const { filesMetadata, addresses } = context
81
-
82
- const _fetchAllBinaryData = async () => {
83
- if (!(await fs.promises.exists('/files'))) {
84
- await fs.promises.mkdir('/files', { recursive: true })
85
- }
86
-
87
- if (!(await fs.promises.exists('/files/html'))) {
88
- await fs.promises.mkdir('/files/html', { recursive: true })
89
- }
90
-
91
- if (!(await fs.promises.exists('/files/json'))) {
92
- await fs.promises.mkdir('/files/json', { recursive: true })
93
- }
94
-
95
- if (!(await fs.promises.exists('/files/images'))) {
96
- await fs.promises.mkdir('/files/images', { recursive: true })
97
- }
98
-
99
- const appDb = BaseDb.getAppDb()
100
-
101
- if (!appDb) {
102
- logger('[fetchAll/actors] [fetchAllBinaryData] seedDb not available')
103
- return []
104
- }
105
-
106
- for (const fileMetadata of filesMetadata) {
107
- const json = JSON.parse(fileMetadata.decodedDataJson)
108
- const transactionId = json[0].value.value
109
-
110
- const excludedTransactionsQuery = await appDb
111
- .select()
112
- .from(appState)
113
- .where(eq(appState.key, 'excludedTransactions'))
114
-
115
- let excludedTransactions = new Set<string>()
116
-
117
- if (excludedTransactionsQuery && excludedTransactionsQuery.length === 1) {
118
- const valueString = excludedTransactionsQuery[0].value
119
- if (valueString) {
120
- const excludedTransactionsArray = JSON.parse(valueString)
121
- excludedTransactions = new Set(excludedTransactionsArray)
122
- }
123
- }
124
-
125
- if (excludedTransactions.has(transactionId)) {
126
- continue
127
- }
128
-
129
- const arweave = getArweave()
130
-
131
- if (!arweave) {
132
- logger('[fetchAll/actors] [fetchAllBinaryData] arweave not available')
133
- return []
134
- }
135
-
136
- try {
137
- const res = await fetch(
138
- `https://${ARWEAVE_HOST}/tx/${transactionId}/status`,
139
- )
140
-
141
- if (res.status !== 200) {
142
- logger(
143
- `[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`,
144
- )
145
-
146
- excludedTransactions.add(transactionId)
147
-
148
- await saveAppState(
149
- 'excludedTransactions',
150
- JSON.stringify(Array.from(excludedTransactions)),
151
- )
152
-
153
- logger(
154
- '[fetchAll/actors] [fetchAllBinaryData] updated excludedTransactions:',
155
- excludedTransactions,
156
- )
157
-
158
- continue
159
- }
160
-
161
- const dataString = await arweave.transactions
162
- .getData(transactionId, {
163
- decode: true,
164
- string: true,
165
- })
166
- .catch((error) => {
167
- logger(
168
- `[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`,
169
- error,
170
- )
171
- })
172
-
173
- const dataUint8Array = await arweave.transactions.getData(transactionId)
174
- // let buffer
175
- //
176
- // if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
177
- // }
178
-
179
- let contentType = identifyString(dataString)
180
- if (
181
- contentType !== 'json' &&
182
- contentType !== 'base64' &&
183
- contentType !== 'html'
184
- ) {
185
- const possibleImageType = getDataTypeFromString(dataString)
186
- if (!possibleImageType) {
187
- logger(
188
- `[fetchAll/actors] [fetchAllBinaryData] transaction ${transactionId} data not in expected format: ${possibleImageType}`,
189
- )
190
- continue
191
- }
192
-
193
- contentType = possibleImageType
194
- }
195
-
196
- if (contentType === 'url') {
197
- const url = dataString as string
198
- const response = await fetch(url)
199
- if (!response.ok) {
200
- throw new Error(`Failed to fetch image: ${response.statusText}`)
201
- }
202
-
203
- // Get the image as a Blob
204
- const blob = await response.blob()
205
- const buffer = await blob.arrayBuffer()
206
- const bufferUint8Array = new Uint8Array(buffer)
207
-
208
- // Extract the file extension from the URL
209
- const extensionMatch = url.match(
210
- /\.(jpg|jpeg|png|gif|bmp|webp|svg)$/i,
211
- )
212
- if (!extensionMatch) {
213
- throw new Error(
214
- 'Unable to determine the file extension from the URL.',
215
- )
216
- }
217
- const fileExtension = extensionMatch[0] // e.g., ".jpg"
218
-
219
- // Set the file name (you can customize this)
220
- // const fileNameFromUrl = `${transactionId}${fileExtension}`
221
-
222
- await fs.promises.writeFile(
223
- `/files/images/${transactionId}`,
224
- bufferUint8Array,
225
- {
226
- encoding: 'binary',
227
- },
228
- )
229
-
230
- continue
231
- }
232
-
233
- let mimeType = getMimeType(dataString as string)
234
- let fileExtension = mimeType
235
-
236
- if (fileExtension && fileExtension?.startsWith('image')) {
237
- fileExtension = fileExtension.replace('image/', '')
238
- }
239
-
240
- let fileName = transactionId
241
-
242
- if (contentType === 'base64') {
243
- if (mimeType) {
244
- fileName += `.${fileExtension}`
245
- }
246
-
247
- // Remove the Base64 header if it exists (e.g., "data:image/png;base64,")
248
- const base64Data = dataString.split(',').pop() || ''
249
-
250
- // Decode the Base64 string to binary
251
- const binaryString = atob(base64Data)
252
- const length = binaryString.length
253
- const binaryData = new Uint8Array(length)
254
-
255
- for (let i = 0; i < length; i++) {
256
- binaryData[i] = binaryString.charCodeAt(i)
257
- }
258
-
259
- console.log(`attempting to writeFile to /files/images/${fileName}`)
260
-
261
- await fs.promises.writeFile(`/files/images/${fileName}`, binaryData, {
262
- encoding: 'binary',
263
- })
264
-
265
- // if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
266
- // await fs.promises.writeFile(
267
- // `/files/images/${fileName}`,
268
- // dataUint8Array,
269
- // )
270
- // }
271
- }
272
-
273
- if (contentType === 'html') {
274
- fileName += '.html'
275
- await fs.promises.writeFile(`/files/html/${fileName}`, dataString)
276
- }
277
-
278
- if (contentType === 'json') {
279
- fileName += '.json'
280
- await fs.promises.writeFile(`/files/json/${fileName}`, dataString)
281
- }
282
- } catch (error) {
283
- logger(error)
284
- }
285
- }
286
-
287
- return []
288
- }
289
-
290
- _fetchAllBinaryData().then((binaryData) => {
291
- sendBack({ type: 'fetchingAllBinaryDataSuccess', binaryData })
292
- })
293
-
294
- return () => { }
295
- })