@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,365 +0,0 @@
1
- import { useCallback, useEffect, useState } from 'react'
2
- import { ActorRef } from 'xstate'
3
- import { orderBy } from 'lodash-es'
4
- import { produce } from 'immer'
5
- import { eventEmitter } from '@/eventBus'
6
- import pluralize from 'pluralize'
7
- import { getGlobalService } from '@/services/global'
8
- import { useSelector } from '@xstate/react'
9
- import debug from 'debug'
10
- import { appState } from '@/seedSchema'
11
- import { like } from 'drizzle-orm'
12
- import { BaseDb } from '@/db/Db/BaseDb'
13
- import { MachineIds } from '@/services/internal/constants'
14
-
15
- const logger = debug('app:react:services')
16
-
17
- const finalStrings = ['idle', 'ready', 'done', 'success', 'initialized']
18
-
19
- export const getServiceName = (service: ActorRef<any, any>) => {
20
- let name = 'actor'
21
- if (service && service.uniqueKey) {
22
- name = service.uniqueKey
23
- }
24
- if (service && !service.uniqueKey && service.logic && service.logic.config) {
25
- name = getServiceUniqueKey(service)
26
- }
27
- return name
28
- }
29
-
30
- export const getServiceValue = (
31
- service: ActorRef<any, any>,
32
- ): string | undefined => {
33
- let value
34
- if (service && service.getSnapshot() && service.getSnapshot().value) {
35
- value = service.getSnapshot().value
36
- }
37
- if (getServiceName(service) === 'global') {
38
- if (
39
- value &&
40
- typeof value === 'object' &&
41
- Object.keys(value).length > 0 &&
42
- Object.keys(value)[0] === 'initialized'
43
- ) {
44
- value = 'ready'
45
- }
46
- }
47
- if (value && typeof value === 'object') {
48
- value = JSON.stringify(value)
49
- }
50
- return value
51
- }
52
-
53
- export const getServiceUniqueKey = (service: ActorRef<any, any>) => {
54
- if (!service || !service.logic || !service.logic.config) {
55
- return
56
- }
57
- const config = service.logic.config
58
- if (!config.id) {
59
- return
60
- }
61
- let uniqueKey = config.id
62
- if (config.id.includes('@seedSdk/')) {
63
- uniqueKey = config.id.match(/^.*@seedSdk\/(\w+)[\.\w]*/)[1]
64
- }
65
- let snapshot
66
- try {
67
- snapshot = service.getSnapshot()
68
- } catch (error) {
69
- logger('Error:', error)
70
- return uniqueKey
71
- }
72
- if (snapshot) {
73
- const context = snapshot.context
74
- if (context && context.dbName) {
75
- uniqueKey = context.dbName
76
- }
77
- if (context && context.modelNamePlural) {
78
- uniqueKey = context.modelNamePlural
79
- }
80
- if (context && context.modelName) {
81
- uniqueKey = pluralize(context.modelName.toLowerCase())
82
- }
83
- }
84
- return uniqueKey
85
- }
86
-
87
- export const useService = (service: ActorRef<any, any>) => {
88
- const [timeElapsed, setTimeElapsed] = useState(0)
89
-
90
- const getPercentComplete = (service: ActorRef<any, any>) => {
91
- let percentComplete = 0
92
- if (service.logic.states) {
93
- const stateNames = []
94
- const startupStates = []
95
-
96
- for (const [stateName, state] of Object.entries(service.logic.states)) {
97
- if (state.tags.includes('loading')) {
98
- stateNames.push(stateName)
99
- startupStates.push(state)
100
- }
101
- }
102
-
103
- const totalStates = startupStates.length
104
- const value = getServiceValue(service)
105
- if (finalStrings.includes(value)) {
106
- return 0
107
- }
108
- const stateIndex = stateNames.indexOf(value)
109
- percentComplete = (stateIndex / totalStates) * 100
110
- }
111
- return percentComplete
112
- }
113
-
114
- const updateTime = useCallback(
115
- (interval) => {
116
- const context = service.getSnapshot().context
117
- const status = service.getSnapshot().value
118
- if (
119
- status === 'done' ||
120
- status === 'success' ||
121
- status === 'idle' ||
122
- status === 'ready'
123
- ) {
124
- clearInterval(interval)
125
- return
126
- }
127
- setTimeElapsed((timeElapsed) => timeElapsed + 1)
128
- },
129
- [service],
130
- )
131
-
132
- const startInterval = useCallback(() => {
133
- const interval = setInterval(() => {
134
- updateTime(interval)
135
- }, 1000)
136
- return interval
137
- }, [updateTime, service])
138
-
139
- useEffect(() => {
140
- const interval = startInterval()
141
- return () => clearInterval(interval)
142
- }, [])
143
-
144
- return {
145
- name: getServiceName(service),
146
- timeElapsed,
147
- value: getServiceValue(service),
148
- percentComplete: getPercentComplete(service),
149
- uniqueKey: getServiceUniqueKey(service),
150
- }
151
- }
152
-
153
- export const useIsDbReady = () => {
154
- const [isDbReady, setIsDbReady] = useState(false)
155
-
156
- const { internalStatus } = useGlobalServiceStatus()
157
-
158
- useEffect(() => {
159
- if (internalStatus === 'ready') {
160
- setIsDbReady(true)
161
- }
162
- }, [internalStatus])
163
-
164
- return isDbReady
165
- }
166
-
167
- export const usePersistedSnapshots = () => {
168
- const [initialized, setInitialized] = useState(false)
169
-
170
- const hasSavedSnapshots = useHasSavedSnapshots()
171
-
172
- const { services, percentComplete } = useServices()
173
-
174
- // Helper function to save all actor snapshots to the database
175
- const save = useCallback(async () => {
176
- for (const actor of services) {
177
- const uniqueKey = getServiceUniqueKey(actor)
178
- console.log(
179
- `would save to db with snapshot__${uniqueKey}:`,
180
- JSON.stringify(actor.getPersistedSnapshot()),
181
- )
182
- // await writeAppState(
183
- // `snapshot__${uniqueKey}`,
184
- // JSON.stringify(actor.getPersistedSnapshot()),
185
- // )
186
- }
187
- }, [services])
188
-
189
- // Helper function to load persisted snapshots from the database
190
- const load = useCallback(async () => {
191
- const appDb = BaseDb.getAppDb()
192
-
193
- if (!appDb) {
194
- return []
195
- }
196
-
197
- const persistedSnapshots = await appDb
198
- .select()
199
- .from(appState)
200
- .where(like(appState.key, 'snapshot__%'))
201
- return persistedSnapshots
202
- }, [])
203
-
204
- useEffect(() => {
205
- if (!hasSavedSnapshots || initialized) {
206
- return
207
- }
208
- const initialize = async () => {
209
- const persistedSnapshots = await load()
210
- console.log('persistedSnapshots:', persistedSnapshots)
211
- setInitialized(true)
212
- }
213
-
214
- initialize()
215
-
216
- return () => {
217
- save() // Save snapshots on unmount
218
- }
219
- }, [hasSavedSnapshots, initialized])
220
- }
221
-
222
- export const useHasSavedSnapshots = () => {
223
- const [hasSavedSnapshots, setHasSavedSnapshots] = useState(false)
224
-
225
- const isDbReady = useIsDbReady()
226
-
227
- useEffect(() => {
228
- if (isDbReady) {
229
- const _checkForSnapshots = async (): Promise<void> => {
230
- const appDb = BaseDb.getAppDb()
231
-
232
- const rows = await appDb
233
- .select()
234
- .from(appState)
235
- .where(like(appState.key, 'snapshot__%'))
236
-
237
- if (rows && rows.length > 0) {
238
- setHasSavedSnapshots(true)
239
- }
240
- }
241
-
242
- _checkForSnapshots()
243
- }
244
- }, [isDbReady])
245
-
246
- return hasSavedSnapshots
247
- }
248
-
249
- export const useServices = () => {
250
- const [actors, setActors] = useState<ActorRef<any, any>[]>([])
251
- const [percentComplete, setPercentComplete] = useState(5)
252
-
253
- const actorsMap = new Map<string, ActorRef<any, any>>()
254
-
255
- useEffect(() => {
256
- const globalServiceListener = (event) => {
257
- if (event && event.type === 'init') {
258
- return
259
- }
260
- if (
261
- event.actorRef &&
262
- event.actorRef.logic &&
263
- event.actorRef.logic.config
264
- ) {
265
- const service = event.actorRef
266
- const services = [service]
267
-
268
- if (service.logic.config.id === MachineIds.GLOBAL) {
269
- const context = service.getSnapshot().context
270
- const keys = Object.keys(context)
271
- for (const key of keys) {
272
- if (!key.startsWith('internal') && key.endsWith('Service')) {
273
- const allItemsService = context[key]
274
- services.push(allItemsService)
275
- }
276
- }
277
- }
278
-
279
- services.forEach((innerService) => {
280
- const uniqueKey = getServiceUniqueKey(innerService)
281
- if (!uniqueKey) {
282
- return
283
- }
284
- innerService.uniqueKey = uniqueKey
285
- actorsMap.set(uniqueKey, innerService)
286
- })
287
-
288
- let actorsArray = Array.from(actorsMap.values())
289
- actorsArray = orderBy(actorsArray, (a) => a.logic.config.id, ['asc'])
290
-
291
- setActors(
292
- produce(actors, (draft) => {
293
- return actorsArray
294
- }),
295
- )
296
- }
297
- }
298
-
299
- eventEmitter.addListener('inspect.globalService', globalServiceListener)
300
-
301
- return () => {
302
- eventEmitter.removeListener(
303
- 'inspect.globalService',
304
- globalServiceListener,
305
- )
306
- }
307
- }, [])
308
-
309
- useEffect(() => {
310
- const globalService = actors.find(
311
- (actor) => getServiceName(actor) === 'global',
312
- )
313
- const internalService = actors.find(
314
- (actor) => getServiceName(actor) === 'internal',
315
- )
316
- if (!globalService || !internalService) {
317
- return
318
- }
319
- if (
320
- getServiceValue(globalService) === 'initialized' &&
321
- getServiceValue(internalService) === 'ready'
322
- ) {
323
- const denominator = actors.length
324
- const finishedActors = actors.filter((actor) => {
325
- const value = getServiceValue(actor)
326
- return finalStrings.includes(value)
327
- })
328
- const numerator = finishedActors.length
329
- const percentComplete = (numerator / denominator) * 100
330
- setPercentComplete(percentComplete)
331
- }
332
- }, [actors])
333
-
334
- return {
335
- services: actors,
336
- percentComplete,
337
- }
338
- }
339
-
340
- export const useGlobalServiceStatus = () => {
341
- const globalService = getGlobalService()
342
-
343
- const status = useSelector(globalService, (snapshot) => {
344
- return snapshot.value
345
- })
346
-
347
- const internalStatus = useSelector(
348
- globalService.getSnapshot().context.internalService,
349
- (snapshot) => {
350
- if (!snapshot) {
351
- return
352
- }
353
- return snapshot.value
354
- },
355
- )
356
-
357
- const internalService = useSelector(globalService, (snapshot) => {
358
- return snapshot.context.internalService
359
- })
360
-
361
- return {
362
- status,
363
- internalStatus,
364
- }
365
- }
@@ -1,88 +0,0 @@
1
- import { SqliteConnectionManager } from '@/services/db'
2
- import {
3
- SqliteRemoteDatabase,
4
- SqliteRemoteResult,
5
- } from 'drizzle-orm/sqlite-proxy'
6
- import { sql } from 'drizzle-orm'
7
-
8
- let sqlite3InitModule: any
9
- let sqliteWasmClient: any
10
- let manager: SqliteConnectionManager | undefined
11
- let isPreparing = false
12
-
13
- export const setSqliteWasmClient = (client: any) => {
14
- sqliteWasmClient = client
15
- }
16
-
17
- export const getSqliteWasmClient = async () => {
18
- if (sqliteWasmClient) {
19
- return sqliteWasmClient
20
- }
21
- if (typeof window === 'undefined') {
22
- throw new Error('validateInput called from non-browser context')
23
- }
24
-
25
- if (isPreparing) {
26
- return
27
- }
28
-
29
- isPreparing = true
30
-
31
- if (!sqlite3InitModule) {
32
- sqlite3InitModule = await import('@sqlite.org/sqlite-wasm')
33
- }
34
-
35
- if (!window.sqlite3Worker1Promiser) {
36
- await sqlite3InitModule()
37
- }
38
-
39
- if (!window.sqlite3Worker1Promiser) {
40
- console.error('window.sqlite3Worker1Promiser not found')
41
- isPreparing = false
42
- return
43
- }
44
-
45
- try {
46
- sqliteWasmClient = await window.sqlite3Worker1Promiser.v2().catch((err) => {
47
- console.error('Error initializing sqliteWasmClient:', err)
48
- isPreparing = false
49
- })
50
- } catch (err) {
51
- console.error('Error initializing sqliteWasmClient:', err)
52
- isPreparing = false
53
- }
54
- return sqliteWasmClient
55
- }
56
-
57
- export const getManager = () => {
58
- return manager
59
- }
60
-
61
- export const setManager = (m: any) => {
62
- manager = m
63
- }
64
- let appDb: SqliteRemoteDatabase<Record<string, unknown>> | undefined
65
- export const setAppDb = (db: SqliteRemoteDatabase<Record<string, unknown>>) => {
66
- appDb = db
67
- }
68
- export const getAppDb = () => {
69
- if (!appDb) {
70
- throw new Error('getAppDb: appDb is undefined')
71
- }
72
-
73
- return appDb
74
- }
75
- export const isAppDbReady = () => {
76
- return !!appDb
77
- }
78
- type RunQueryForStatement = (
79
- statement: string,
80
- ) => Promise<SqliteRemoteResult<unknown>>
81
-
82
- export const runQueryForStatement: RunQueryForStatement = async (
83
- statement: string,
84
- ) => {
85
- const appDb = getAppDb()
86
-
87
- return appDb.run(sql.raw(statement))
88
- }