@seedprotocol/sdk 0.2.51 → 0.2.53

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 (207) 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-Bh_lvrAN.js} +6 -3
  6. package/dist/Db-Bh_lvrAN.js.map +1 -0
  7. package/dist/{Db-DMJ0v3gO.js → Db-DqBP6XK2.js} +3 -3
  8. package/dist/{Db-DMJ0v3gO.js.map → Db-DqBP6XK2.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-COP3FuaU.js} +3 -3
  16. package/dist/{Item-D4n439Ei.js.map → Item-COP3FuaU.js.map} +1 -1
  17. package/dist/{ItemProperty-Be5ymRVT.js → ItemProperty-BFn9wM65.js} +3 -3
  18. package/dist/{ItemProperty-Be5ymRVT.js.map → ItemProperty-BFn9wM65.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-BLla2o05.js → index-C4xqqsLw.js} +3 -3
  27. package/dist/index-C4xqqsLw.js.map +1 -0
  28. package/dist/{index-BeKRizLf.js → index-CLvyWg5f.js} +257 -145
  29. package/dist/index-CLvyWg5f.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-Bao3o6wu.js} +3 -3
  33. package/dist/{seed.schema.config-CMpV_hyS.js.map → seed.schema.config-Bao3o6wu.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/db/Db.d.ts.map +1 -1
  48. package/dist/types/src/node/helpers/FileManager.d.ts.map +1 -1
  49. package/dist/types/src/services/internal/actors/validateInput.d.ts.map +1 -1
  50. package/dist/types/src/types/machines.d.ts +5 -0
  51. package/dist/types/src/types/machines.d.ts.map +1 -1
  52. package/package.json +2 -2
  53. package/dist/Db-quJxmvHH.js.map +0 -1
  54. package/dist/FileManager-texI7UwL.js.map +0 -1
  55. package/dist/index-BLla2o05.js.map +0 -1
  56. package/dist/index-BeKRizLf.js.map +0 -1
  57. package/dist/src/AppStateSchema.ts +0 -10
  58. package/dist/src/ArweaveClient.ts +0 -13
  59. package/dist/src/Attestation.ts +0 -21
  60. package/dist/src/BaseArweaveClient.ts +0 -13
  61. package/dist/src/BaseDb.ts +0 -35
  62. package/dist/src/BaseEasClient.ts +0 -13
  63. package/dist/src/BaseFileManager.ts +0 -56
  64. package/dist/src/BaseItem.ts +0 -413
  65. package/dist/src/BaseItemProperty.ts +0 -416
  66. package/dist/src/BaseQueryClient.ts +0 -13
  67. package/dist/src/ConfigSchema.ts +0 -15
  68. package/dist/src/Db.ts +0 -78
  69. package/dist/src/EasClient.ts +0 -13
  70. package/dist/src/FileDownloader.ts +0 -63
  71. package/dist/src/FileManager.ts +0 -57
  72. package/dist/src/IDb.ts +0 -7
  73. package/dist/src/IEasClient.ts +0 -2
  74. package/dist/src/IItem.ts +0 -26
  75. package/dist/src/IItemProperty.ts +0 -28
  76. package/dist/src/IQueryClient.ts +0 -4
  77. package/dist/src/ImageResizer.ts +0 -81
  78. package/dist/src/Item.ts +0 -12
  79. package/dist/src/ItemProperty.ts +0 -9
  80. package/dist/src/MetadataSchema.ts +0 -28
  81. package/dist/src/ModelSchema.ts +0 -46
  82. package/dist/src/ModelUidSchema.ts +0 -16
  83. package/dist/src/PropertyUidSchema.ts +0 -16
  84. package/dist/src/QueryClient.ts +0 -22
  85. package/dist/src/Schema.ts +0 -17
  86. package/dist/src/SeedProtocolSdk.d.ts +0 -19
  87. package/dist/src/SeedSchema.ts +0 -29
  88. package/dist/src/VersionSchema.ts +0 -16
  89. package/dist/src/actors.ts +0 -295
  90. package/dist/src/addModelsToDb.ts +0 -152
  91. package/dist/src/allItems.ts +0 -31
  92. package/dist/src/analyzeInput.ts +0 -144
  93. package/dist/src/browser.app.db.config.ts +0 -27
  94. package/dist/src/browser.ts +0 -30
  95. package/dist/src/checkStatus.ts +0 -50
  96. package/dist/src/client.ts +0 -148
  97. package/dist/src/configureFs.ts +0 -94
  98. package/dist/src/connectToDb.ts +0 -41
  99. package/dist/src/connectionManager.ts +0 -67
  100. package/dist/src/constants.ts +0 -125
  101. package/dist/src/content-hash.ts +0 -30
  102. package/dist/src/create.ts +0 -39
  103. package/dist/src/createMetadata.ts +0 -77
  104. package/dist/src/createNewItem.ts +0 -61
  105. package/dist/src/createPublishAttempt.ts +0 -16
  106. package/dist/src/createSeed.ts +0 -31
  107. package/dist/src/createSeeds.ts +0 -24
  108. package/dist/src/createVersion.ts +0 -33
  109. package/dist/src/dbMachine.ts +0 -182
  110. package/dist/src/deleteItem.ts +0 -19
  111. package/dist/src/download.ts +0 -202
  112. package/dist/src/drizzle.ts +0 -78
  113. package/dist/src/eas.ts +0 -40
  114. package/dist/src/environment.ts +0 -35
  115. package/dist/src/eventBus.ts +0 -5
  116. package/dist/src/events.ts +0 -14
  117. package/dist/src/fetchDataFromEas.ts +0 -94
  118. package/dist/src/fetchDbData.ts +0 -19
  119. package/dist/src/fetchRelatedItems.ts +0 -184
  120. package/dist/src/fetchSeeds.ts +0 -52
  121. package/dist/src/fetchVersions.ts +0 -49
  122. package/dist/src/files.ts +0 -81
  123. package/dist/src/filesDownload.ts +0 -326
  124. package/dist/src/fragment-masking.ts +0 -87
  125. package/dist/src/getExistingItem.ts +0 -60
  126. package/dist/src/getItem.ts +0 -32
  127. package/dist/src/getItemData.ts +0 -99
  128. package/dist/src/getItemProperties.ts +0 -56
  129. package/dist/src/getItemProperty.ts +0 -34
  130. package/dist/src/getItems.ts +0 -70
  131. package/dist/src/getMetadata.ts +0 -40
  132. package/dist/src/getModelSchemas.ts +0 -89
  133. package/dist/src/getPropertyData.ts +0 -50
  134. package/dist/src/getPublishPayload.ts +0 -355
  135. package/dist/src/getPublishUploads.ts +0 -207
  136. package/dist/src/getRelationValueData.ts +0 -27
  137. package/dist/src/getSchemaForItemProperty.ts +0 -68
  138. package/dist/src/getSchemaForModel.ts +0 -42
  139. package/dist/src/getSchemaUidForModel.ts +0 -32
  140. package/dist/src/getSeedData.ts +0 -34
  141. package/dist/src/getSegmentedItemProperties.ts +0 -65
  142. package/dist/src/getStorageTransactionIdForSeedUid.ts +0 -38
  143. package/dist/src/getVersionData.ts +0 -46
  144. package/dist/src/getVersionsForVersionUids.ts +0 -39
  145. package/dist/src/globalMachine.ts +0 -280
  146. package/dist/src/gql.ts +0 -118
  147. package/dist/src/graphql.ts +0 -3209
  148. package/dist/src/helpers.ts +0 -273
  149. package/dist/src/hydrateExistingItem.ts +0 -137
  150. package/dist/src/hydrateFromDb.ts +0 -270
  151. package/dist/src/hydrateNewItem.ts +0 -34
  152. package/dist/src/imageResize.ts +0 -507
  153. package/dist/src/index.d.ts +0 -5
  154. package/dist/src/index.ts +0 -4
  155. package/dist/src/initialize.ts +0 -124
  156. package/dist/src/internalMachine.ts +0 -238
  157. package/dist/src/itemMachineAll.ts +0 -157
  158. package/dist/src/itemMachineSingle.ts +0 -158
  159. package/dist/src/loadAppDb.ts +0 -47
  160. package/dist/src/machines.ts +0 -60
  161. package/dist/src/metadataLatest.ts +0 -34
  162. package/dist/src/migrate.ts +0 -53
  163. package/dist/src/model.ts +0 -72
  164. package/dist/src/modelClass.ts +0 -19
  165. package/dist/src/node.app.db.config.ts +0 -41
  166. package/dist/src/prepareDb.ts +0 -29
  167. package/dist/src/preparePublishRequestData.ts +0 -81
  168. package/dist/src/processItems.ts +0 -74
  169. package/dist/src/property.ts +0 -156
  170. package/dist/src/propertyMachine.ts +0 -202
  171. package/dist/src/publish.ts +0 -28
  172. package/dist/src/publishMachine.ts +0 -77
  173. package/dist/src/queries.ts +0 -13
  174. package/dist/src/recoverDeletedItem.ts +0 -14
  175. package/dist/src/reload.ts +0 -33
  176. package/dist/src/request.ts +0 -45
  177. package/dist/src/requestAll.ts +0 -157
  178. package/dist/src/resolveRelatedValue.ts +0 -367
  179. package/dist/src/resolveRemoteStorage.ts +0 -88
  180. package/dist/src/saveAppState.ts +0 -19
  181. package/dist/src/saveConfig.ts +0 -88
  182. package/dist/src/saveDataToDb.ts +0 -145
  183. package/dist/src/saveImageSrc.ts +0 -242
  184. package/dist/src/saveItemStorage.ts +0 -156
  185. package/dist/src/saveMetadata.ts +0 -18
  186. package/dist/src/savePublishService.ts +0 -30
  187. package/dist/src/saveRelation.ts +0 -112
  188. package/dist/src/seed.schema.config.ts +0 -25
  189. package/dist/src/seed.ts +0 -10
  190. package/dist/src/seedProtocol.ts +0 -17
  191. package/dist/src/services.ts +0 -365
  192. package/dist/src/sqlWasmClient.ts +0 -88
  193. package/dist/src/syncDbWithEas.ts +0 -628
  194. package/dist/src/trash.ts +0 -29
  195. package/dist/src/ts-to-proto.ts +0 -101
  196. package/dist/src/types.ts +0 -12
  197. package/dist/src/updateItemPropertyValue.ts +0 -243
  198. package/dist/src/updateMachineContext.ts +0 -21
  199. package/dist/src/updateMetadata.ts +0 -59
  200. package/dist/src/upload.ts +0 -86
  201. package/dist/src/validate.ts +0 -45
  202. package/dist/src/validateInput.ts +0 -47
  203. package/dist/src/validateItemData.ts +0 -20
  204. package/dist/src/versionData.ts +0 -24
  205. package/dist/src/waitForDb.ts +0 -25
  206. package/dist/src/waitForFiles.ts +0 -34
  207. package/dist/src/wasm.d.ts +0 -8300
@@ -1,152 +0,0 @@
1
- import { EventObject, fromCallback } from 'xstate'
2
- import { models as modelsTable, modelUids } from '@/seedSchema'
3
- import { eq } from 'drizzle-orm'
4
- import { toSnakeCase, BaseEasClient, BaseQueryClient } from '@/helpers'
5
- import { BaseDb } from '@/db/Db/BaseDb'
6
- import { GLOBAL_ADDING_MODELS_TO_DB_SUCCESS } from '@/services/internal/constants'
7
- import { eventEmitter } from '@/eventBus'
8
- import { FromCallbackInput, GlobalMachineContext } from '@/types'
9
- import debug from 'debug'
10
- import { GET_SCHEMAS } from '@/Item/queries'
11
-
12
- const logger = debug('app:services:global:actors:addModelsToDb')
13
-
14
- export const addModelsToDb = fromCallback<
15
- EventObject,
16
- FromCallbackInput<GlobalMachineContext>
17
- >(({ sendBack, input: { context } }) => {
18
- const { models } = context
19
-
20
- const _addModelsToDb = async () => {
21
- const appDb = BaseDb.getAppDb()
22
-
23
- if (!models) {
24
- return
25
- }
26
-
27
- const { models: SeedModels } = await import(
28
- '@/db/configs/seed.schema.config'
29
- )
30
-
31
- const allModels = {
32
- ...SeedModels,
33
- ...models,
34
- }
35
-
36
- let hasModelsInDb = false
37
- const schemaDefsByModelName = new Map<
38
- string,
39
- {
40
- dbId: number
41
- schemaDef: string
42
- }
43
- >()
44
-
45
- for (const [modelName, _] of Object.entries(allModels)) {
46
- logger(
47
- '[helpers/db] [addModelsToInternalDb] starting modelName:',
48
- modelName,
49
- )
50
-
51
- let foundModel
52
-
53
- const foundModelsQuery = await appDb
54
- .select()
55
- .from(modelsTable)
56
- .where(eq(modelsTable.name, modelName))
57
-
58
- if (!foundModelsQuery || foundModelsQuery.length === 0) {
59
- await appDb.insert(modelsTable).values({
60
- name: modelName,
61
- })
62
-
63
- logger('[global/actors] [addModelsToDb] inserted model:', modelName)
64
- const foundModels = await appDb
65
- .select({
66
- id: modelsTable.id,
67
- name: modelsTable.name,
68
- uid: modelUids.uid,
69
- })
70
- .from(modelsTable)
71
- .leftJoin(modelUids, eq(modelsTable.id, modelUids.modelId))
72
- .where(eq(modelsTable.name, modelName))
73
- .limit(1)
74
-
75
- foundModel = foundModels[0]
76
- }
77
-
78
- if (foundModelsQuery && foundModelsQuery.length > 0) {
79
- foundModel = foundModelsQuery[0]
80
- }
81
-
82
- if (!foundModel) {
83
- hasModelsInDb = false
84
- break
85
- }
86
-
87
- schemaDefsByModelName.set(modelName, {
88
- dbId: foundModel.id,
89
- schemaDef: `bytes32 ${toSnakeCase(modelName)}`,
90
- })
91
- }
92
-
93
- if (!hasModelsInDb) {
94
- return false
95
- }
96
-
97
- const schemaDefs = Array.from(schemaDefsByModelName.values()).map(
98
- ({ schemaDef }) => schemaDef,
99
- )
100
-
101
- const queryClient = BaseQueryClient.getQueryClient()
102
- const easClient = BaseEasClient.getEasClient()
103
-
104
- const { schemas } = await queryClient.fetchQuery({
105
- queryKey: [`getSchemasVersion`],
106
- queryFn: async () =>
107
- easClient.request(GET_SCHEMAS, {
108
- where: {
109
- schema: {
110
- in: schemaDefs,
111
- },
112
- },
113
- }),
114
- })
115
-
116
- if (!schemas || schemas.length === 0) {
117
- throw new Error(`No schemas found`)
118
- }
119
-
120
- for (const schema of schemas) {
121
- const modelId = Array.from(schemaDefsByModelName.values()).find(
122
- ({ schemaDef }) => schemaDef === schema.schema,
123
- )?.dbId
124
-
125
- if (!modelId) {
126
- throw new Error(`No modelId found for schema ${schema.schema}`)
127
- }
128
-
129
- await appDb
130
- .insert(modelUids)
131
- .values({
132
- modelId,
133
- uid: schema.id,
134
- })
135
- .onConflictDoNothing()
136
- }
137
- }
138
-
139
- _addModelsToDb().then((hasModelsInDb) => {
140
- sendBack({ type: GLOBAL_ADDING_MODELS_TO_DB_SUCCESS })
141
- if (hasModelsInDb) {
142
- }
143
- for (const [modelName, model] of Object.entries(models)) {
144
- const service = context[`${modelName}Service`]
145
- service.send({ type: 'modelsFound' })
146
- }
147
- eventEmitter.emit('syncDbWithEas')
148
- return
149
- })
150
-
151
- return () => { }
152
- })
@@ -1,31 +0,0 @@
1
- import { getGlobalService } from '@/services/global'
2
-
3
- import { saveAppState } from '@/db/write/saveAppState'
4
-
5
- type SaveServiceEvent = {
6
- modelName: string
7
- }
8
-
9
- export const saveServiceHandler = async (event: SaveServiceEvent) => {
10
- const globalService = getGlobalService()
11
-
12
- if (!globalService || !globalService.getSnapshot().context) {
13
- return
14
- }
15
-
16
- const { modelName } = event
17
-
18
- const nameOfService: string = `${modelName}Service`
19
-
20
- const service = globalService.getSnapshot().context[nameOfService]
21
-
22
- if (!service) {
23
- console.log(`[saveServiceHandler] service not found: ${nameOfService}`)
24
- return
25
- }
26
-
27
- await saveAppState(
28
- `snapshot__${modelName}`,
29
- JSON.stringify(service.getPersistedSnapshot()),
30
- )
31
- }
@@ -1,144 +0,0 @@
1
- import { EventObject, fromCallback } from 'xstate'
2
- import { FromCallbackInput } from '@/types/machines'
3
- import {
4
- ItemPropertyValueType,
5
- PropertyMachineContext,
6
- SaveValueToDbEvent,
7
- } from '@/types/property'
8
- import { updateItemPropertyValue } from '@/db/write/updateItemPropertyValue'
9
-
10
- import { getSchemaForItemProperty } from '@/helpers/getSchemaForItemProperty'
11
- import { INTERNAL_DATA_TYPES } from '@/helpers/constants'
12
- import { TypedData } from '@ethereum-attestation-service/eas-sdk/dist/offchain/typed-data-handler'
13
-
14
- export const analyzeInput = fromCallback<
15
- EventObject,
16
- FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>
17
- >(({ sendBack, input: { context, event } }) => {
18
- const {
19
- localId,
20
- propertyName: propertyNameRaw,
21
- seedLocalId,
22
- versionLocalId,
23
- versionUid,
24
- propertyValue: existingValue,
25
- propertyRecordSchema,
26
- modelName,
27
- } = context
28
-
29
- let { schemaUid } = context
30
-
31
- let newValue: ItemPropertyValueType
32
-
33
- if (event) {
34
- newValue = event.newValue
35
- }
36
-
37
- if (existingValue === newValue) {
38
- sendBack({ type: 'saveValueToDbSuccess' })
39
- return
40
- }
41
-
42
- if (!propertyRecordSchema) {
43
- throw new Error('Missing propertyRecordSchema')
44
- }
45
-
46
- const _analyzeInput = async (): Promise<boolean> => {
47
- let propertyName = propertyNameRaw
48
-
49
- if (
50
- propertyRecordSchema.refValueType &&
51
- propertyRecordSchema.refValueType !== 'ImageSrc' &&
52
- propertyRecordSchema.dataType === 'Relation'
53
- ) {
54
- sendBack({
55
- type: 'saveRelation',
56
- newValue,
57
- })
58
- return false
59
- }
60
-
61
- if (
62
- propertyRecordSchema.refValueType === 'ImageSrc' ||
63
- propertyRecordSchema.dataType === 'ImageSrc'
64
- ) {
65
- sendBack({
66
- type: 'saveImageSrc',
67
- newValue,
68
- })
69
- return false
70
- }
71
-
72
- if (
73
- propertyRecordSchema.storageType &&
74
- propertyRecordSchema.storageType === 'ItemStorage'
75
- ) {
76
- sendBack({
77
- type: 'saveItemStorage',
78
- newValue,
79
- })
80
- return false
81
- }
82
-
83
- if (!schemaUid) {
84
- let easDataType
85
-
86
- if (propertyRecordSchema.dataType) {
87
- easDataType = INTERNAL_DATA_TYPES[propertyRecordSchema.dataType]
88
- .eas as TypedData['type']
89
- }
90
-
91
- const schemaFromEas = await getSchemaForItemProperty({
92
- propertyName,
93
- easDataType,
94
- })
95
- if (schemaFromEas) {
96
- schemaUid = schemaFromEas.id
97
- }
98
- }
99
-
100
- const result = await updateItemPropertyValue({
101
- localId,
102
- propertyName,
103
- newValue,
104
- seedLocalId,
105
- versionLocalId,
106
- versionUid,
107
- modelName,
108
- schemaUid,
109
- })
110
-
111
- let updatedContext: Partial<PropertyMachineContext> = {
112
- propertyValue: newValue,
113
- }
114
-
115
- if (localId) {
116
- updatedContext.localId = localId
117
- }
118
-
119
- if (schemaUid) {
120
- updatedContext.schemaUid = schemaUid
121
- }
122
-
123
- if (!localId && result?.localId) {
124
- updatedContext.localId = result.localId
125
- }
126
-
127
- if (!schemaUid && result?.schemaUid) {
128
- updatedContext.schemaUid = result.schemaUid
129
- }
130
-
131
- sendBack({
132
- type: 'updateContext',
133
- ...updatedContext,
134
- })
135
-
136
- return true
137
- }
138
-
139
- _analyzeInput().then((isDone) => {
140
- if (isDone) {
141
- sendBack({ type: 'saveValueToDbSuccess' })
142
- }
143
- })
144
- })
@@ -1,27 +0,0 @@
1
- import { defineConfig } from 'drizzle-kit'
2
- import dotenv from 'dotenv'
3
- import process from 'node:process'
4
- import path from 'path'
5
-
6
- dotenv.config()
7
-
8
- let dotSeedDir = path.join(process.cwd(), '.seed')
9
-
10
- if (process.env.IS_SEED_DEV) {
11
- dotSeedDir = path.join(
12
- process.cwd(),
13
- '__tests__',
14
- '__mocks__',
15
- 'project',
16
- '.seed',
17
- )
18
- }
19
-
20
- export default defineConfig({
21
- schema: [`${dotSeedDir}/app/schema/*Schema.ts`],
22
- dialect: 'sqlite',
23
- out: `${dotSeedDir}/app/db`,
24
- dbCredentials: {
25
- url: `${dotSeedDir}/app/db/app_db.sqlite3`,
26
- },
27
- })
@@ -1,30 +0,0 @@
1
- import { Endpoints } from './index'
2
- import { SqliteRemoteResult } from 'drizzle-orm/sqlite-proxy'
3
-
4
- export type SeedInitBrowserProps = {
5
- endpoints: Endpoints
6
- }
7
-
8
- export interface SeedInitBrowser {
9
- (props: SeedInitBrowserProps): Promise<void>
10
- }
11
-
12
- export type DbQueryResult = SqliteRemoteResult<SqliteWasmResult>
13
-
14
- export type ResultObject = {
15
- [key: string]: string
16
- }
17
-
18
- export type SqliteWasmResult = {
19
- type: string | null
20
- row: string[] | null
21
- rowNumber: number | null
22
- columnNames: string[]
23
- }
24
-
25
- export type SqliteWasmCallback = (result: SqliteWasmResult) => void
26
-
27
- export type ReturnObj = {
28
- database: string
29
- [key: string]: string | number | null | undefined | string[]
30
- }
@@ -1,50 +0,0 @@
1
- import { EventObject, fromCallback } from 'xstate'
2
- import { DbServiceContext, FromCallbackInput } from '@/types'
3
- import {
4
- BROWSER_FS_TOP_DIR,
5
- DB_CHECK_STATUS_EXISTS,
6
- DB_CHECK_STATUS_UPDATE_PATHS,
7
- } from '@/services/internal/constants'
8
- import debug from 'debug'
9
-
10
- const logger = debug('app:services:db:actors:checkStatus')
11
-
12
- export const checkStatus = fromCallback<
13
- EventObject,
14
- FromCallbackInput<DbServiceContext>
15
- >(({ sendBack, input: { context } }) => {
16
- const { dbName } = context
17
-
18
- logger('[db/actors] checkStatus context', context)
19
- const pathToDir = `${BROWSER_FS_TOP_DIR}`
20
- const pathToDbDir = `${pathToDir}/db`
21
- const pathToDb = `${pathToDbDir}/${dbName}.sqlite3`
22
-
23
- sendBack({
24
- type: DB_CHECK_STATUS_UPDATE_PATHS,
25
- pathToDb,
26
- pathToDir,
27
- pathToDbDir,
28
- })
29
-
30
- const _checkStatus = async (): Promise<void> => {
31
- // logger('[db/actors] _checkStatus pathToDb', pathToDb)
32
- // const exists = await fs.promises.exists(pathToJournal)
33
- // if (exists) {
34
- // sendBack({
35
- // type: DB_CHECK_STATUS_EXISTS,
36
- // })
37
- // return
38
- // }
39
- //
40
- // return new Promise((resolve) => {
41
- // sendBack({ type: DB_CHECK_STATUS_DOES_NOT_EXIST })
42
- //
43
- // })
44
- }
45
-
46
- _checkStatus().then(() => {
47
- sendBack({ type: DB_CHECK_STATUS_EXISTS })
48
- return
49
- })
50
- })
@@ -1,148 +0,0 @@
1
- import { areFsListenersReady, setupFsListeners } from '@/events/files'
2
- import { setupAllItemsEventHandlers } from '@/events'
3
- import { setupServicesEventHandlers } from '@/services/events'
4
- import { eventEmitter } from '@/eventBus'
5
- import { globalService, } from '@/services'
6
- import { ModelClassType, SeedConstructorOptions } from '@/types'
7
- import {
8
- getModel,
9
- getModelNames,
10
- getModels,
11
- setModel,
12
- } from '@/stores/modelClass'
13
- import { setupServiceHandlers } from '@/events/services'
14
- import { initArweaveClient, setArweaveDomain } from '@/helpers/ArweaveClient'
15
- import { initItem } from './Item'
16
- import { initItemProperty } from './ItemProperty'
17
- import { initEasClient } from './helpers/EasClient'
18
- import { initQueryClient } from './helpers/QueryClient'
19
- import { initFileManager } from './helpers/FileManager'
20
- import { initDb } from './db/Db'
21
- import debug from 'debug'
22
- import { appState } from './seedSchema'
23
-
24
- const logger = debug('app:client')
25
-
26
- const client = {
27
- isInitialized: false,
28
- init: async (options: SeedConstructorOptions) => {
29
- logger('init client')
30
-
31
- if (client.isInitialized) {
32
- return
33
- }
34
-
35
- client.isInitialized = true
36
-
37
- const { config, addresses } = options
38
-
39
- await initItem()
40
- await initItemProperty()
41
- await initEasClient()
42
- await initArweaveClient()
43
- await initQueryClient()
44
- await initFileManager()
45
- await initDb()
46
-
47
- const { endpoints, models, arweaveDomain, filesDir, } = config
48
-
49
- if (arweaveDomain) {
50
- setArweaveDomain(arweaveDomain)
51
- }
52
-
53
- for (const [key, value] of Object.entries(models)) {
54
- setModel(key, value)
55
- }
56
- setupFsListeners()
57
- setupAllItemsEventHandlers()
58
- setupServicesEventHandlers()
59
- setupServiceHandlers()
60
- if (areFsListenersReady()) {
61
- eventEmitter.emit('fs.init')
62
- }
63
- if (!areFsListenersReady()) {
64
- console.error('fs listeners not ready during init')
65
- }
66
- globalService.send({
67
- type: 'init',
68
- endpoints,
69
- models,
70
- addresses,
71
- arweaveDomain,
72
- filesDir,
73
- })
74
-
75
- const { models: internalModels } = await import('@/db/configs/seed.schema.config')
76
- for (const [key, value] of Object.entries(internalModels)) {
77
- setModel(key, value)
78
- }
79
- },
80
- setAddresses: async(addresses: string[]) => {
81
- const {BaseDb} = await import('./db/Db/BaseDb')
82
- if (!BaseDb) {
83
- throw new Error('BaseDb not found')
84
- }
85
- if (!BaseDb.PlatformClass) {
86
- await initDb()
87
- }
88
- const appDb = BaseDb.getAppDb()
89
- if (!appDb) {
90
- throw new Error('App DB not found')
91
- }
92
- appDb.insert(appState)
93
- .values({
94
- key: 'addresses',
95
- value: JSON.stringify(addresses),
96
- })
97
- .onConflictDoUpdate({
98
- target: appState.key,
99
- set: {
100
- value: JSON.stringify(addresses),
101
- },
102
- })
103
- },
104
- subscribe: (callback: any) => {
105
- const subscription = globalService.subscribe(callback)
106
-
107
- eventEmitter.addListener('internal.globalService', callback)
108
-
109
- return {
110
- unsubscribe: () => {
111
- subscription.unsubscribe()
112
- eventEmitter.removeListener('internal.globalService', callback)
113
- },
114
- }
115
- },
116
- on: (outerEvent: string, callback: any) => {
117
- eventEmitter.addListener(outerEvent, callback)
118
-
119
- return {
120
- unsubscribe: () => {
121
- eventEmitter.removeListener(outerEvent, callback)
122
- },
123
- }
124
- },
125
- getSeedClass: async () => {
126
- return new Promise((resolve) => {
127
- const subscription = globalService.subscribe((snapshot) => {
128
- if (snapshot.status === 'done') {
129
- resolve(snapshot.output)
130
- }
131
- })
132
-
133
- globalService.send({ type: 'getSeed' })
134
- subscription.unsubscribe()
135
- })
136
- },
137
- getModel: (modelName: string) => {
138
- return getModel(modelName)
139
- },
140
- getModels: (): Record<string, ModelClassType> => {
141
- return getModels()
142
- },
143
- getModelNames: (): string[] => {
144
- return getModelNames()
145
- },
146
- }
147
-
148
- export { client }
@@ -1,94 +0,0 @@
1
- import { EventObject, fromCallback } from 'xstate'
2
- import { areFsListenersReady, isFsInitialized } from '@/events/files'
3
- import { waitForEvent } from '@/events'
4
- import {
5
- BROWSER_FS_TOP_DIR,
6
- DB_WAITING_FOR_FILES_RECEIVED,
7
- INTERNAL_CONFIGURING_FS_SUCCESS,
8
- } from '@/services/internal/constants'
9
- import fs from '@zenfs/core'
10
- import debug from 'debug'
11
- import { FromCallbackInput, InternalMachineContext } from '@/types'
12
-
13
- const logger = debug('app:internal:actors:configureFs')
14
-
15
- export const configureFs = fromCallback<
16
- EventObject,
17
- FromCallbackInput<InternalMachineContext>
18
- >(({ sendBack, input: { context } }) => {
19
- const { endpoints, appDbService, filesDir, } = context
20
-
21
- logger('[internal/actors] [configureFs] Configuring FS')
22
-
23
- const _configureFs = async (): Promise<boolean> => {
24
- logger('[internal/actors] [configureFs] calling _configureFs')
25
-
26
- logger(
27
- '[internal/actors] [configureFs] areFsListenersReady:',
28
- areFsListenersReady(),
29
- )
30
- logger(
31
- '[internal/actors] [configureFs] isFsInitialized:',
32
- isFsInitialized(),
33
- )
34
-
35
- await waitForEvent({
36
- req: {
37
- eventLabel: 'fs.downloadAll.request',
38
- data: { endpoints },
39
- },
40
- res: {
41
- eventLabel: 'fs.downloadAll.success',
42
- },
43
- })
44
-
45
- const journalPath = `${filesDir || BROWSER_FS_TOP_DIR}/db/meta/_journal.json`
46
-
47
-
48
- let journalExists = await fs.promises.exists(journalPath)
49
-
50
- if (!journalExists) {
51
- journalExists = fs.existsSync(journalPath)
52
- }
53
-
54
- if (journalExists) {
55
- appDbService.send({ type: DB_WAITING_FOR_FILES_RECEIVED })
56
- logger('[internal/actors] [configureFs] fs configured!')
57
- return true
58
- }
59
-
60
- sendBack({ type: 'shouldWaitForFiles' })
61
-
62
-
63
- return false
64
-
65
- // return new Promise<void>((resolve) => {
66
- // const interval = setInterval(() => {
67
- // journalExistsSync = fs.existsSync(journalPath)
68
- // logger(
69
- // '[internal/actors] [configureFs] journalExistsSync:',
70
- // journalExistsSync,
71
- // )
72
- // if (journalExistsSync) {
73
- // service.send({ type: DB_WAITING_FOR_FILES_RECEIVED })
74
- // clearInterval(interval)
75
- // resolve()
76
- // }
77
- // }, 200)
78
- // })
79
-
80
- }
81
-
82
- // Some of our dependencies use fs sync functions, which don't work with
83
- // OPFS. ZenFS creates an async cache of all files so that the sync functions
84
- // work, but we have to wait for it to be built. Otherwise things like
85
- // drizzleMigrate will fail since they can't see the migration files yet.
86
- _configureFs().then((fsConfigured) => {
87
- if (fsConfigured) {
88
- sendBack({ type: INTERNAL_CONFIGURING_FS_SUCCESS })
89
- }
90
- return
91
- })
92
-
93
- return () => { }
94
- })