@seedprotocol/sdk 0.2.54 → 0.3.1

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 (243) hide show
  1. package/dist/{ArweaveClient-D5iJisYr.js → ArweaveClient-C0g0es2v.js} +2 -2
  2. package/dist/{ArweaveClient-D5iJisYr.js.map → ArweaveClient-C0g0es2v.js.map} +1 -1
  3. package/dist/{ArweaveClient-HEIIuOfB.js → ArweaveClient-CzkBgiZY.js} +2 -2
  4. package/dist/{ArweaveClient-HEIIuOfB.js.map → ArweaveClient-CzkBgiZY.js.map} +1 -1
  5. package/dist/{Db-jMth8Y2g.js → Db-C4oog-0n.js} +4 -3
  6. package/dist/{Db-jMth8Y2g.js.map → Db-C4oog-0n.js.map} +1 -1
  7. package/dist/Db-VPouegkr.js +82 -0
  8. package/dist/Db-VPouegkr.js.map +1 -0
  9. package/dist/EasClient-B9a3NsTi.js +10 -0
  10. package/dist/EasClient-B9a3NsTi.js.map +1 -0
  11. package/dist/{EasClient-D3wKgt0o.js → EasClient-DQ93i2ci.js} +2 -2
  12. package/dist/{EasClient-D3wKgt0o.js.map → EasClient-DQ93i2ci.js.map} +1 -1
  13. package/dist/{FileManager-4mWYO3Mt.js → FileManager-_ErxVuwb.js} +9 -5
  14. package/dist/FileManager-_ErxVuwb.js.map +1 -0
  15. package/dist/{Item-CbgjLSUx.js → Item-D9HFPxsK.js} +4 -3
  16. package/dist/{Item-CbgjLSUx.js.map → Item-D9HFPxsK.js.map} +1 -1
  17. package/dist/{ItemProperty-DduurIcl.js → ItemProperty-BdtvKrEy.js} +4 -3
  18. package/dist/{ItemProperty-DduurIcl.js.map → ItemProperty-BdtvKrEy.js.map} +1 -1
  19. package/dist/QueryClient-Bmnv_moN.js +22 -0
  20. package/dist/QueryClient-Bmnv_moN.js.map +1 -0
  21. package/dist/{QueryClient-CBOP3OoU.js → QueryClient-hzOtFe99.js} +3 -2
  22. package/dist/{QueryClient-CBOP3OoU.js.map → QueryClient-hzOtFe99.js.map} +1 -1
  23. package/dist/bin.js +30 -34
  24. package/dist/bin.js.map +1 -1
  25. package/dist/{constants-CIDbABDz.js → constants-Bhl5dZpN.js} +9 -4
  26. package/dist/constants-Bhl5dZpN.js.map +1 -0
  27. package/dist/db/configs/node.app.db.config.ts +27 -0
  28. package/dist/{index-DQNTvzqi.js → index-BAtjd9W-.js} +4 -3
  29. package/dist/index-BAtjd9W-.js.map +1 -0
  30. package/dist/{index-CTZqN6WI.js → index-BSR5hv7Q.js} +305 -268
  31. package/dist/index-BSR5hv7Q.js.map +1 -0
  32. package/dist/main.js +3 -2
  33. package/dist/main.js.map +1 -1
  34. package/dist/node/db/node.app.db.config.ts +1 -1
  35. package/dist/{seed.schema.config-B-4U2RRq.js → seed.schema.config-BxJYabim.js} +10 -9
  36. package/dist/seed.schema.config-BxJYabim.js.map +1 -0
  37. package/dist/src/AppStateSchema.ts +10 -0
  38. package/dist/src/ArweaveClient.ts +13 -0
  39. package/dist/src/Attestation.ts +21 -0
  40. package/dist/src/BaseArweaveClient.ts +13 -0
  41. package/dist/src/BaseClientManager.ts +35 -0
  42. package/dist/src/BaseDb.ts +35 -0
  43. package/dist/src/BaseEasClient.ts +14 -0
  44. package/dist/src/BaseFileManager.ts +60 -0
  45. package/dist/src/BaseItem.ts +413 -0
  46. package/dist/src/BaseItemProperty.ts +416 -0
  47. package/dist/src/BaseQueryClient.ts +13 -0
  48. package/dist/src/ClientManager.ts +63 -0
  49. package/dist/src/ConfigSchema.ts +15 -0
  50. package/dist/src/Db.ts +82 -0
  51. package/dist/src/EasClient.ts +13 -0
  52. package/dist/src/FileDownloader.ts +63 -0
  53. package/dist/src/FileManager.ts +59 -0
  54. package/dist/src/IDb.ts +7 -0
  55. package/dist/src/IEasClient.ts +2 -0
  56. package/dist/src/IItem.ts +26 -0
  57. package/dist/src/IItemProperty.ts +28 -0
  58. package/dist/src/IQueryClient.ts +11 -0
  59. package/dist/src/ImageResizer.ts +81 -0
  60. package/dist/src/Item.ts +12 -0
  61. package/dist/src/ItemProperty.ts +9 -0
  62. package/dist/src/MetadataSchema.ts +28 -0
  63. package/dist/src/ModelSchema.ts +46 -0
  64. package/dist/src/ModelUidSchema.ts +16 -0
  65. package/dist/src/PropertyUidSchema.ts +16 -0
  66. package/dist/src/QueryClient.ts +26 -0
  67. package/dist/src/Schema.ts +17 -0
  68. package/dist/src/SeedProtocolSdk.d.ts +19 -0
  69. package/dist/src/SeedSchema.ts +29 -0
  70. package/dist/src/VersionSchema.ts +16 -0
  71. package/dist/src/actors.ts +295 -0
  72. package/dist/src/addModelsToDb.ts +152 -0
  73. package/dist/src/allItems.ts +31 -0
  74. package/dist/src/analyzeInput.ts +144 -0
  75. package/dist/src/browser.app.db.config.ts +27 -0
  76. package/dist/src/browser.ts +30 -0
  77. package/dist/src/checkStatus.ts +57 -0
  78. package/dist/src/clientManagerMachine.ts +59 -0
  79. package/dist/src/configureFs.ts +98 -0
  80. package/dist/src/connectToDb.ts +41 -0
  81. package/dist/src/connectionManager.ts +67 -0
  82. package/dist/src/constants.ts +125 -0
  83. package/dist/src/content-hash.ts +30 -0
  84. package/dist/src/create.ts +39 -0
  85. package/dist/src/createMetadata.ts +77 -0
  86. package/dist/src/createNewItem.ts +61 -0
  87. package/dist/src/createPublishAttempt.ts +16 -0
  88. package/dist/src/createSeed.ts +31 -0
  89. package/dist/src/createSeeds.ts +24 -0
  90. package/dist/src/createVersion.ts +33 -0
  91. package/dist/src/dbMachine.ts +182 -0
  92. package/dist/src/deleteItem.ts +19 -0
  93. package/dist/src/download.ts +208 -0
  94. package/dist/src/drizzle.ts +78 -0
  95. package/dist/src/eas.ts +40 -0
  96. package/dist/src/environment.ts +35 -0
  97. package/dist/src/eventBus.ts +5 -0
  98. package/dist/src/events.ts +14 -0
  99. package/dist/src/fetchDataFromEas.ts +94 -0
  100. package/dist/src/fetchDbData.ts +19 -0
  101. package/dist/src/fetchRelatedItems.ts +184 -0
  102. package/dist/src/fetchSeeds.ts +45 -0
  103. package/dist/src/fetchVersions.ts +49 -0
  104. package/dist/src/files.ts +81 -0
  105. package/dist/src/filesDownload.ts +326 -0
  106. package/dist/src/fragment-masking.ts +87 -0
  107. package/dist/src/getExistingItem.ts +60 -0
  108. package/dist/src/getItem.ts +32 -0
  109. package/dist/src/getItemData.ts +99 -0
  110. package/dist/src/getItemProperties.ts +56 -0
  111. package/dist/src/getItemProperty.ts +34 -0
  112. package/dist/src/getItems.ts +70 -0
  113. package/dist/src/getMetadata.ts +40 -0
  114. package/dist/src/getModelSchemas.ts +89 -0
  115. package/dist/src/getPropertyData.ts +50 -0
  116. package/dist/src/getPublishPayload.ts +355 -0
  117. package/dist/src/getPublishUploads.ts +207 -0
  118. package/dist/src/getRelationValueData.ts +27 -0
  119. package/dist/src/getSchemaForItemProperty.ts +68 -0
  120. package/dist/src/getSchemaForModel.ts +42 -0
  121. package/dist/src/getSchemaUidForModel.ts +32 -0
  122. package/dist/src/getSeedData.ts +34 -0
  123. package/dist/src/getSegmentedItemProperties.ts +65 -0
  124. package/dist/src/getStorageTransactionIdForSeedUid.ts +38 -0
  125. package/dist/src/getVersionData.ts +46 -0
  126. package/dist/src/getVersionsForVersionUids.ts +39 -0
  127. package/dist/src/globalMachine.ts +280 -0
  128. package/dist/src/gql.ts +118 -0
  129. package/dist/src/graphql.ts +3209 -0
  130. package/dist/src/helpers.ts +273 -0
  131. package/dist/src/hydrateExistingItem.ts +137 -0
  132. package/dist/src/hydrateFromDb.ts +270 -0
  133. package/dist/src/hydrateNewItem.ts +34 -0
  134. package/dist/src/imageResize.ts +507 -0
  135. package/dist/src/index.d.ts +5 -0
  136. package/dist/src/index.ts +4 -0
  137. package/dist/src/initialize.ts +124 -0
  138. package/dist/src/internalMachine.ts +241 -0
  139. package/dist/src/itemMachineAll.ts +157 -0
  140. package/dist/src/itemMachineSingle.ts +158 -0
  141. package/dist/src/loadAppDb.ts +44 -0
  142. package/dist/src/machines.ts +66 -0
  143. package/dist/src/metadataLatest.ts +34 -0
  144. package/dist/src/migrate.ts +57 -0
  145. package/dist/src/model.ts +72 -0
  146. package/dist/src/modelClass.ts +19 -0
  147. package/dist/src/node.app.db.config.ts +41 -0
  148. package/dist/src/prepareDb.ts +29 -0
  149. package/dist/src/preparePublishRequestData.ts +81 -0
  150. package/dist/src/processItems.ts +74 -0
  151. package/dist/src/property.ts +156 -0
  152. package/dist/src/propertyMachine.ts +202 -0
  153. package/dist/src/publish.ts +28 -0
  154. package/dist/src/publishMachine.ts +77 -0
  155. package/dist/src/queries.ts +13 -0
  156. package/dist/src/recoverDeletedItem.ts +14 -0
  157. package/dist/src/reload.ts +33 -0
  158. package/dist/src/request.ts +45 -0
  159. package/dist/src/requestAll.ts +157 -0
  160. package/dist/src/resolveRelatedValue.ts +367 -0
  161. package/dist/src/resolveRemoteStorage.ts +88 -0
  162. package/dist/src/saveAppState.ts +50 -0
  163. package/dist/src/saveConfig.ts +106 -0
  164. package/dist/src/saveDataToDb.ts +145 -0
  165. package/dist/src/saveImageSrc.ts +242 -0
  166. package/dist/src/saveItemStorage.ts +156 -0
  167. package/dist/src/saveMetadata.ts +18 -0
  168. package/dist/src/savePublishService.ts +30 -0
  169. package/dist/src/saveRelation.ts +112 -0
  170. package/dist/src/seed.schema.config.ts +25 -0
  171. package/dist/src/seed.ts +10 -0
  172. package/dist/src/seedProtocol.ts +17 -0
  173. package/dist/src/services.ts +365 -0
  174. package/dist/src/setAddresses.ts +16 -0
  175. package/dist/src/sqlWasmClient.ts +88 -0
  176. package/dist/src/syncDbWithEas.ts +628 -0
  177. package/dist/src/trash.ts +29 -0
  178. package/dist/src/ts-to-proto.ts +101 -0
  179. package/dist/src/types.ts +12 -0
  180. package/dist/src/updateItemPropertyValue.ts +243 -0
  181. package/dist/src/updateMachineContext.ts +21 -0
  182. package/dist/src/updateMetadata.ts +59 -0
  183. package/dist/src/upload.ts +86 -0
  184. package/dist/src/validate.ts +45 -0
  185. package/dist/src/validateInput.ts +43 -0
  186. package/dist/src/validateItemData.ts +20 -0
  187. package/dist/src/versionData.ts +24 -0
  188. package/dist/src/waitForDb.ts +25 -0
  189. package/dist/src/waitForFiles.ts +41 -0
  190. package/dist/src/wasm.d.ts +8300 -0
  191. package/dist/types/scripts/bin.d.ts.map +1 -1
  192. package/dist/types/src/browser/helpers/EasClient.d.ts +1 -3
  193. package/dist/types/src/browser/helpers/EasClient.d.ts.map +1 -1
  194. package/dist/types/src/browser/helpers/FileManager.d.ts +2 -1
  195. package/dist/types/src/browser/helpers/FileManager.d.ts.map +1 -1
  196. package/dist/types/src/client/ClientManager.d.ts +44 -0
  197. package/dist/types/src/client/ClientManager.d.ts.map +1 -0
  198. package/dist/types/src/client/actions/setAddresses.d.ts.map +1 -1
  199. package/dist/types/src/client/actors/initialize.d.ts.map +1 -1
  200. package/dist/types/src/client/actors/saveAppState.d.ts.map +1 -1
  201. package/dist/types/src/client/clientManagerMachine.d.ts.map +1 -1
  202. package/dist/types/src/client/index.d.ts +2 -40
  203. package/dist/types/src/client/index.d.ts.map +1 -1
  204. package/dist/types/src/db/configs/node.app.db.config.d.ts +3 -0
  205. package/dist/types/src/db/configs/node.app.db.config.d.ts.map +1 -0
  206. package/dist/types/src/events/files/download.d.ts.map +1 -1
  207. package/dist/types/src/helpers/EasClient/BaseEasClient.d.ts.map +1 -1
  208. package/dist/types/src/helpers/FileManager/BaseFileManager.d.ts +1 -0
  209. package/dist/types/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
  210. package/dist/types/src/helpers/constants.d.ts +1 -0
  211. package/dist/types/src/helpers/constants.d.ts.map +1 -1
  212. package/dist/types/src/interfaces/IQueryClient.d.ts +7 -1
  213. package/dist/types/src/interfaces/IQueryClient.d.ts.map +1 -1
  214. package/dist/types/src/node/db/Db.d.ts +5 -10
  215. package/dist/types/src/node/db/Db.d.ts.map +1 -1
  216. package/dist/types/src/node/helpers/FileManager.d.ts +2 -1
  217. package/dist/types/src/node/helpers/FileManager.d.ts.map +1 -1
  218. package/dist/types/src/node/helpers/QueryClient.d.ts +2 -4
  219. package/dist/types/src/node/helpers/QueryClient.d.ts.map +1 -1
  220. package/dist/types/src/services/allItems/actors/fetchSeeds.d.ts.map +1 -1
  221. package/dist/types/src/services/db/actors/checkStatus.d.ts.map +1 -1
  222. package/dist/types/src/services/db/actors/migrate.d.ts.map +1 -1
  223. package/dist/types/src/services/db/actors/waitForFiles.d.ts.map +1 -1
  224. package/dist/types/src/services/internal/actors/configureFs.d.ts.map +1 -1
  225. package/dist/types/src/services/internal/actors/loadAppDb.d.ts.map +1 -1
  226. package/dist/types/src/services/internal/actors/saveConfig.d.ts.map +1 -1
  227. package/dist/types/src/services/internal/actors/waitForFiles.d.ts.map +1 -1
  228. package/dist/types/src/services/internal/internalMachine.d.ts.map +1 -1
  229. package/package.json +10 -10
  230. package/dist/Db-DK9wSNIH.js +0 -120
  231. package/dist/Db-DK9wSNIH.js.map +0 -1
  232. package/dist/EasClient-jqkT2ZBt.js +0 -13
  233. package/dist/EasClient-jqkT2ZBt.js.map +0 -1
  234. package/dist/FileManager-4mWYO3Mt.js.map +0 -1
  235. package/dist/QueryClient-bKb3SB0W.js +0 -23
  236. package/dist/QueryClient-bKb3SB0W.js.map +0 -1
  237. package/dist/constants-CIDbABDz.js.map +0 -1
  238. package/dist/index-CTZqN6WI.js.map +0 -1
  239. package/dist/index-DQNTvzqi.js.map +0 -1
  240. package/dist/package.json +0 -189
  241. package/dist/seed.schema.config-B-4U2RRq.js.map +0 -1
  242. package/dist/types/src/client.d.ts +0 -18
  243. package/dist/types/src/client.d.ts.map +0 -1
@@ -1,16 +1,17 @@
1
1
  import { immerable, produce, enableMapSet } from 'immer';
2
2
  import 'reflect-metadata';
3
3
  import { Type } from '@sinclair/typebox';
4
- import { fromCallback, setup, assign, waitFor, createActor, raise } from 'xstate';
5
- import { c as BaseQueryClient, a as BaseEasClient, G as GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY, f as GLOBAL_INITIALIZING_SEND_CONFIG, g as GLOBAL_INITIALIZING_CREATE_ALL_ITEMS_SERVICES, h as GLOBAL_ADDING_MODELS_TO_DB_SUCCESS, D as DB_CHECK_STATUS_UPDATE_PATHS, i as DB_CHECK_STATUS_EXISTS, d as BROWSER_FS_TOP_DIR, j as DB_CREATING_SUCCESS, k as DB_VALIDATING_SUCCESS, l as DB_VALIDATING_WAIT, b as BaseFileManager, m as DB_MIGRATING_SUCCESS, n as DB_WAITING_FOR_FILES_RECEIVED, M as MachineIds, o as DB_MIGRATING_WAIT, p as DbState, I as INTERNAL_VALIDATING_INPUT_SUCCESS, q as ARWEAVE_HOST, B as BaseArweaveClient, r as INTERNAL_CONFIGURING_FS_SUCCESS, s as INTERNAL_SAVING_CONFIG_SUCCESS, t as INTERNAL_LOADING_APP_DB_SUCCESS, u as DB_ON_SNAPSHOT, v as DB_NAME_APP, w as InternalState, P as PublishMachineStates, x as GlobalState, y as INTERNAL_DATA_TYPES, z as ImageSize, C as internalPropertyNames, V as VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA, F as defaultAttestationData } from './constants-CIDbABDz.js';
4
+ import { fromCallback, setup, assign, waitFor, raise, createActor } from 'xstate';
5
+ import { c as BaseQueryClient, a as BaseEasClient, G as GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY, f as GLOBAL_INITIALIZING_SEND_CONFIG, g as GLOBAL_INITIALIZING_CREATE_ALL_ITEMS_SERVICES, h as GLOBAL_ADDING_MODELS_TO_DB_SUCCESS, d as BROWSER_FS_TOP_DIR, D as DB_CHECK_STATUS_UPDATE_PATHS, i as DB_CHECK_STATUS_EXISTS, j as DB_CREATING_SUCCESS, k as DB_VALIDATING_SUCCESS, l as DB_VALIDATING_WAIT, b as BaseFileManager, m as DB_MIGRATING_SUCCESS, n as DB_WAITING_FOR_FILES_RECEIVED, o as DbState, M as MachineIds, p as DB_MIGRATING_WAIT, q as ARWEAVE_HOST, I as INTERNAL_VALIDATING_INPUT_SUCCESS, B as BaseArweaveClient, r as INTERNAL_CONFIGURING_FS_SUCCESS, s as INTERNAL_SAVING_CONFIG_SUCCESS, t as INTERNAL_LOADING_APP_DB_SUCCESS, u as DB_NAME_APP, v as DB_ON_SNAPSHOT, w as InternalState, P as PublishMachineStates, x as GlobalState, y as INTERNAL_DATA_TYPES, z as ImageSize, C as internalPropertyNames, V as VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA, F as defaultAttestationData, H as CLIENT_NOT_INITIALIZED } from './constants-Bhl5dZpN.js';
6
6
  import debug from 'debug';
7
7
  import pluralize from 'pluralize';
8
- import { sqliteTable, text, int, unique } from 'drizzle-orm/sqlite-core';
9
- import { relations, or, and, isNotNull, not, eq, inArray, sql, like, getTableColumns, isNull, count, max, gt } from 'drizzle-orm';
8
+ import { sqliteTable, int, text, unique, getTableConfig } from 'drizzle-orm/sqlite-core';
9
+ import { relations, or, and, isNotNull, not, eq, inArray, sql, like, getTableColumns, isNull, max, count, gt } from 'drizzle-orm';
10
10
  import EventEmitter from 'eventemitter3';
11
11
  import { customAlphabet } from 'nanoid';
12
12
  import * as nanoIdDictionary from 'nanoid-dictionary';
13
13
  import fs from '@zenfs/core';
14
+ import 'graphql-request';
14
15
  import { throttle, camelCase, startCase, orderBy } from 'lodash-es';
15
16
  import { createBrowserInspector } from '@statelyai/inspect';
16
17
  import path from 'path';
@@ -294,7 +295,7 @@ const initialize$4 = fromCallback(({ sendBack, input: { context } }) => {
294
295
 
295
296
  const eventEmitter = new EventEmitter();
296
297
 
297
- const logger$s = debug('app:shared:helpers');
298
+ const logger$p = debug('app:shared:helpers');
298
299
  const { alphanumeric } = nanoIdDictionary;
299
300
  const generateId = () => {
300
301
  return customAlphabet(alphanumeric, 10)();
@@ -351,7 +352,7 @@ const convertTxIdToImageSrc = async (txId) => {
351
352
  const imageFilePath = `/files/images/${txId}`;
352
353
  const fileExists = await fs.promises.exists(imageFilePath);
353
354
  if (!fileExists) {
354
- logger$s(`[ItemView] [updateImageSrc] ${imageFilePath} does not exist`);
355
+ logger$p(`[ItemView] [updateImageSrc] ${imageFilePath} does not exist`);
355
356
  return;
356
357
  }
357
358
  const uint = await fs.promises.readFile(imageFilePath);
@@ -1032,7 +1033,7 @@ const saveEasPropertiesToDb = async ({ itemProperties, itemSeeds, }) => {
1032
1033
  isList = true;
1033
1034
  refValueType = 'list';
1034
1035
  const result = parseEasRelationPropertyName(propertyNameSnake);
1035
- {
1036
+ if (result) {
1036
1037
  propertyNameSnake = result.propertyName;
1037
1038
  refSeedType = result.modelName;
1038
1039
  }
@@ -1198,7 +1199,7 @@ const syncDbWithEasHandler = throttle(async (_) => {
1198
1199
  },
1199
1200
  }),
1200
1201
  });
1201
- saveEasPropertiesToDb({
1202
+ const { propertyUids } = saveEasPropertiesToDb({
1202
1203
  itemProperties,
1203
1204
  itemSeeds,
1204
1205
  });
@@ -1233,7 +1234,7 @@ const getEnvironment = () => {
1233
1234
  return 'node';
1234
1235
  };
1235
1236
 
1236
- const logger$r = debug('app:services:global:actors:initialize');
1237
+ const logger$o = debug('app:services:global:actors:initialize');
1237
1238
  const initialize$3 = fromCallback(({ sendBack, input: { event, context } }) => {
1238
1239
  const { internalService, models, endpoints, arweaveDomain, addresses, } = context;
1239
1240
  if (!internalService) {
@@ -1252,11 +1253,12 @@ const initialize$3 = fromCallback(({ sendBack, input: { event, context } }) => {
1252
1253
  const _initInternal = async () => {
1253
1254
  return new Promise((resolve) => {
1254
1255
  internalSubscription = internalService.subscribe((snapshot) => {
1255
- logger$r('[sdk] [internal] snapshot', snapshot);
1256
+ logger$o('[sdk] [internal] snapshot.value', snapshot.value);
1256
1257
  if (snapshot.value === 'ready') {
1257
1258
  resolve();
1258
1259
  }
1259
1260
  });
1261
+ logger$o('[sdk] [internal] sending init');
1260
1262
  internalService.send({
1261
1263
  type: 'init',
1262
1264
  endpoints,
@@ -1297,7 +1299,7 @@ const initialize$3 = fromCallback(({ sendBack, input: { event, context } }) => {
1297
1299
  await fetchSchemaUids();
1298
1300
  };
1299
1301
  _initFileSystem().then(() => {
1300
- logger$r('[global/actors] File system initialized');
1302
+ logger$o('[global/actors] File system initialized');
1301
1303
  });
1302
1304
  _initInternal()
1303
1305
  .then(() => {
@@ -1307,7 +1309,7 @@ const initialize$3 = fromCallback(({ sendBack, input: { event, context } }) => {
1307
1309
  return _initEas();
1308
1310
  })
1309
1311
  .then(() => {
1310
- logger$r('[global/actors] Internal initialized');
1312
+ logger$o('[global/actors] Internal initialized');
1311
1313
  sendBack({ type: GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY });
1312
1314
  internalSubscription?.unsubscribe();
1313
1315
  });
@@ -1320,7 +1322,7 @@ const initialize$3 = fromCallback(({ sendBack, input: { event, context } }) => {
1320
1322
  };
1321
1323
  });
1322
1324
 
1323
- const logger$q = debug('app:services:global:actors:getSchemaForModel');
1325
+ const logger$n = debug('app:services:global:actors:getSchemaForModel');
1324
1326
  const getSchemaForModel = fromCallback(({ sendBack, input: { context, event } }) => {
1325
1327
  const { modelName } = event;
1326
1328
  if (!modelName) {
@@ -1336,12 +1338,12 @@ const getSchemaForModel = fromCallback(({ sendBack, input: { context, event } })
1336
1338
  if (!model) {
1337
1339
  throw new Error(`Model ${modelName} not found`);
1338
1340
  }
1339
- logger$q('[service/actor] [getSchemaForModel] model:', model);
1341
+ logger$n('[service/actor] [getSchemaForModel] model:', model);
1340
1342
  sendBack({ type: 'schemaForModel', schema: model.schema });
1341
1343
  return () => { };
1342
1344
  });
1343
1345
 
1344
- const logger$p = debug('app:services:global:actors:addModelsToDb');
1346
+ const logger$m = debug('app:services:global:actors:addModelsToDb');
1345
1347
  const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
1346
1348
  const { models: models$1 } = context;
1347
1349
  const _addModelsToDb = async () => {
@@ -1349,7 +1351,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
1349
1351
  if (!models$1) {
1350
1352
  return;
1351
1353
  }
1352
- const { models: SeedModels } = await import('./seed.schema.config-B-4U2RRq.js');
1354
+ const { models: SeedModels } = await import('./seed.schema.config-BxJYabim.js');
1353
1355
  const allModels = {
1354
1356
  ...SeedModels,
1355
1357
  ...models$1,
@@ -1357,7 +1359,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
1357
1359
  let hasModelsInDb = false;
1358
1360
  const schemaDefsByModelName = new Map();
1359
1361
  for (const [modelName, _] of Object.entries(allModels)) {
1360
- logger$p('[helpers/db] [addModelsToInternalDb] starting modelName:', modelName);
1362
+ logger$m('[helpers/db] [addModelsToInternalDb] starting modelName:', modelName);
1361
1363
  let foundModel;
1362
1364
  const foundModelsQuery = await appDb
1363
1365
  .select()
@@ -1367,7 +1369,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
1367
1369
  await appDb.insert(models).values({
1368
1370
  name: modelName,
1369
1371
  });
1370
- logger$p('[global/actors] [addModelsToDb] inserted model:', modelName);
1372
+ logger$m('[global/actors] [addModelsToDb] inserted model:', modelName);
1371
1373
  const foundModels = await appDb
1372
1374
  .select({
1373
1375
  id: models.id,
@@ -1437,11 +1439,16 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
1437
1439
  return () => { };
1438
1440
  });
1439
1441
 
1440
- const logger$o = debug('app:services:db:actors:checkStatus');
1441
- const checkStatus = fromCallback(({ sendBack, input: { context } }) => {
1442
- const { dbName } = context;
1443
- logger$o('[db/actors] checkStatus context', context);
1444
- const pathToDir = `${BROWSER_FS_TOP_DIR}`;
1442
+ const logger$l = debug('app:services:db:actors:checkStatus');
1443
+ const checkStatus = fromCallback(({ sendBack, input: { context, event, } }) => {
1444
+ const { dbName, } = context;
1445
+ let { pathToDir, } = context;
1446
+ logger$l('[db/actors] checkStatus context', context);
1447
+ console.log('[db/actors] checkStatus context', context);
1448
+ console.log('[db/actors] checkStatus event', event);
1449
+ if (isBrowser()) {
1450
+ pathToDir = BROWSER_FS_TOP_DIR;
1451
+ }
1445
1452
  const pathToDbDir = `${pathToDir}/db`;
1446
1453
  const pathToDb = `${pathToDbDir}/${dbName}.sqlite3`;
1447
1454
  sendBack({
@@ -1471,9 +1478,9 @@ const checkStatus = fromCallback(({ sendBack, input: { context } }) => {
1471
1478
  });
1472
1479
  });
1473
1480
 
1474
- const logger$n = debug('app:services:db:actors:connectToDb');
1481
+ const logger$k = debug('app:services:db:actors:connectToDb');
1475
1482
  const connectToDb = fromCallback(({ sendBack, input: { context } }) => {
1476
- logger$n('[db/actors] connectToDb context', context);
1483
+ logger$k('[db/actors] connectToDb context', context);
1477
1484
  const { dbName, pathToDir } = context;
1478
1485
  if (!pathToDir || !dbName) {
1479
1486
  throw new Error('pathToDir and dbName are required');
@@ -2256,20 +2263,13 @@ class ImageResizer {
2256
2263
  }
2257
2264
  }
2258
2265
 
2259
- const logger$m = debug('app:browser:helpers:FileManager');
2266
+ const logger$j = debug('app:browser:helpers:FileManager');
2260
2267
  class FileManager extends BaseFileManager {
2261
- static async readFileAsBuffer(filePath) {
2262
- return new Promise((resolve, reject) => {
2263
- reject(new Error('Not implemented'));
2264
- });
2265
- }
2266
2268
  static async getContentUrlFromPath(path) {
2267
- const fs = await import('@zenfs/core');
2268
- const fileExists = await fs.promises.exists(path);
2269
+ const fileExists = await this.pathExists(path);
2269
2270
  if (fileExists) {
2270
- const fileContents = await fs.promises.readFile(path);
2271
- const fileHandler = new File([fileContents], path);
2272
- return URL.createObjectURL(fileHandler);
2271
+ const file = await this.readFile(path);
2272
+ return URL.createObjectURL(file);
2273
2273
  }
2274
2274
  }
2275
2275
  static async initializeFileSystem() {
@@ -2362,7 +2362,7 @@ class FileManager extends BaseFileManager {
2362
2362
  const startTime = Date.now();
2363
2363
  let isBusy = false;
2364
2364
  const cancelableInterval = new CancelableInterval(async (stop) => {
2365
- logger$m('waitForFile', filePath);
2365
+ logger$j('waitForFile', filePath);
2366
2366
  if (isBusy) {
2367
2367
  return;
2368
2368
  }
@@ -2449,7 +2449,7 @@ class FileManager extends BaseFileManager {
2449
2449
  const fileHandle = await currentDir.getFileHandle(fileName, { create: true });
2450
2450
  // Create a writable stream and write the content
2451
2451
  const writable = await fileHandle.createWritable();
2452
- if (typeof content === 'string') {
2452
+ if (typeof content === 'string' || content instanceof Uint8Array) {
2453
2453
  await writable.write(content);
2454
2454
  }
2455
2455
  else if (content instanceof Blob) {
@@ -2468,6 +2468,45 @@ class FileManager extends BaseFileManager {
2468
2468
  console.error(`Error writing to OPFS: ${error.message}`);
2469
2469
  }
2470
2470
  }
2471
+ static async readFile(filePath) {
2472
+ try {
2473
+ // Get a handle to the OPFS root directory
2474
+ const root = await navigator.storage.getDirectory();
2475
+ // Split the file path into directory and file name
2476
+ const pathParts = filePath.split('/');
2477
+ const fileName = pathParts.pop();
2478
+ if (!fileName)
2479
+ throw new Error('Invalid file path');
2480
+ // Traverse directories to reach the target file
2481
+ let currentDir = root;
2482
+ for (const part of pathParts) {
2483
+ if (part !== '') {
2484
+ currentDir = await currentDir.getDirectoryHandle(part, { create: false });
2485
+ }
2486
+ }
2487
+ // Get the file handle
2488
+ const fileHandle = await currentDir.getFileHandle(fileName, { create: false });
2489
+ // Get the file and read it as an ArrayBuffer
2490
+ return await fileHandle.getFile();
2491
+ }
2492
+ catch (error) {
2493
+ console.error(`Error reading from OPFS: ${error.message}`);
2494
+ throw error;
2495
+ }
2496
+ }
2497
+ static async readFileAsBuffer(filePath) {
2498
+ try {
2499
+ // Get the file and read it as an ArrayBuffer
2500
+ const file = await this.readFile(filePath);
2501
+ const arrayBuffer = await file.arrayBuffer();
2502
+ // Convert ArrayBuffer to Buffer
2503
+ return Buffer.from(arrayBuffer);
2504
+ }
2505
+ catch (error) {
2506
+ console.error(`Error reading from OPFS: ${error.message}`);
2507
+ throw error;
2508
+ }
2509
+ }
2471
2510
  }
2472
2511
  BaseFileManager.setPlatformClass(FileManager);
2473
2512
  class CancelableInterval {
@@ -2522,15 +2561,15 @@ var FileManager$1 = /*#__PURE__*/Object.freeze({
2522
2561
  FileManager: FileManager
2523
2562
  });
2524
2563
 
2525
- const logger$l = debug('app:services:db:actors:migrate');
2564
+ const logger$i = debug('app:services:db:actors:migrate');
2526
2565
  const migrate = fromCallback(({ sendBack, input: { context } }) => {
2527
2566
  const { pathToDbDir, dbId, dbName } = context;
2528
- logger$l('[db/actors] migrate context', context);
2567
+ logger$i('[db/actors] migrate context', context);
2529
2568
  let journalExists = false;
2530
2569
  const _checkForFiles = async () => {
2531
2570
  const journalPath = `/${pathToDbDir}/meta/_journal.json`;
2532
2571
  journalExists = await fs.promises.exists(journalPath);
2533
- if (!journalExists) {
2572
+ if (!journalExists && isBrowser()) {
2534
2573
  await FileManager.waitForFile(journalPath, 500, 60000);
2535
2574
  }
2536
2575
  };
@@ -2539,11 +2578,15 @@ const migrate = fromCallback(({ sendBack, input: { context } }) => {
2539
2578
  };
2540
2579
  _checkForFiles()
2541
2580
  .then(() => {
2581
+ if (!isBrowser()) {
2582
+ return _migrate();
2583
+ }
2542
2584
  if (journalExists) {
2543
2585
  return _migrate();
2544
2586
  }
2545
2587
  })
2546
2588
  .then(() => {
2589
+ console.log('sending db migrating success');
2547
2590
  sendBack({ type: DB_MIGRATING_SUCCESS, dbName });
2548
2591
  });
2549
2592
  return () => { };
@@ -2551,6 +2594,10 @@ const migrate = fromCallback(({ sendBack, input: { context } }) => {
2551
2594
 
2552
2595
  debug('app:services:db:actors:waitForFiles');
2553
2596
  const waitForFiles$1 = fromCallback(({ sendBack, input: { context } }) => {
2597
+ if (!isBrowser()) {
2598
+ sendBack({ type: DB_WAITING_FOR_FILES_RECEIVED });
2599
+ return;
2600
+ }
2554
2601
  const { pathToDbDir } = context;
2555
2602
  const _waitForFiles = async () => {
2556
2603
  return new Promise((resolve) => {
@@ -2569,7 +2616,7 @@ const waitForFiles$1 = fromCallback(({ sendBack, input: { context } }) => {
2569
2616
  });
2570
2617
  });
2571
2618
 
2572
- const logger$k = debug('app:services:db:machine');
2619
+ const logger$h = debug('app:services:db:machine');
2573
2620
  const { CHECKING_STATUS, VALIDATING, WAITING_FOR_FILES, CONNECTING_TO_DB, MIGRATING, } = DbState;
2574
2621
  const dbMachine = setup({
2575
2622
  types: {
@@ -2591,7 +2638,7 @@ const dbMachine = setup({
2591
2638
  [DB_WAITING_FOR_FILES_RECEIVED]: {
2592
2639
  actions: assign({
2593
2640
  hasFiles: ({ event }) => {
2594
- logger$k('[db/machine] DB_WAITING_FOR_FILES_RECEIVED event:', event);
2641
+ logger$h('[db/machine] DB_WAITING_FOR_FILES_RECEIVED event:', event);
2595
2642
  return true;
2596
2643
  },
2597
2644
  }),
@@ -2600,8 +2647,8 @@ const dbMachine = setup({
2600
2647
  target: `.${CHECKING_STATUS}`,
2601
2648
  actions: assign({
2602
2649
  hasFiles: ({ context, event }) => {
2603
- logger$k('[db/machine] updateHasFiles event:', event);
2604
- logger$k('[db/machine] updateHasFiles context:', context);
2650
+ logger$h('[db/machine] updateHasFiles event:', event);
2651
+ logger$h('[db/machine] updateHasFiles context:', context);
2605
2652
  return event.hasFiles;
2606
2653
  },
2607
2654
  }),
@@ -2755,9 +2802,9 @@ const prepareDb = fromCallback(({ sendBack, input: { context } }) => {
2755
2802
  throw new Error('filesDir is required');
2756
2803
  }
2757
2804
  const _prepareDb = async () => {
2758
- const manager = await BaseDb.prepareDb(filesDir);
2759
- if (manager) {
2760
- sendBack({ type: 'prepareDbSuccess', manager });
2805
+ const appDb = await BaseDb.prepareDb(filesDir);
2806
+ if (appDb) {
2807
+ sendBack({ type: 'prepareDbSuccess' });
2761
2808
  }
2762
2809
  };
2763
2810
  _prepareDb().then(() => {
@@ -2765,7 +2812,7 @@ const prepareDb = fromCallback(({ sendBack, input: { context } }) => {
2765
2812
  });
2766
2813
  });
2767
2814
 
2768
- const logger$j = debug('app:services:internal:helpers');
2815
+ const logger$g = debug('app:services:internal:helpers');
2769
2816
  /**
2770
2817
  * Recursively create directories if they don't exist.
2771
2818
  * @param {string} dirPath - The directory path to create.
@@ -2829,11 +2876,11 @@ class FileDownloadManager {
2829
2876
  }
2830
2877
  try {
2831
2878
  await fs.promises.writeFile(localFilePath, fileData);
2832
- logger$j(`[downloadFile] Wrote file async to ${localFilePath}`);
2879
+ logger$g(`[downloadFile] Wrote file async to ${localFilePath}`);
2833
2880
  }
2834
2881
  catch (error) {
2835
2882
  fs.writeFileSync(localFilePath, fileData);
2836
- logger$j(`[downloadFile] Wrote file sync to ${localFilePath}`);
2883
+ logger$g(`[downloadFile] Wrote file sync to ${localFilePath}`);
2837
2884
  }
2838
2885
  }
2839
2886
  async start() {
@@ -2923,7 +2970,7 @@ const syncDbFiles = async ({ filePaths, files }) => {
2923
2970
  await downloadManager.start();
2924
2971
  // await fetchFilesRecursively(files, BROWSER_FS_TOP_DIR, fileList)
2925
2972
  await confirmFilesExist(fileList);
2926
- logger$j('[syncDbFiles] Files synced!');
2973
+ logger$g('[syncDbFiles] Files synced!');
2927
2974
  };
2928
2975
 
2929
2976
  const GET_FILES_METADATA = graphql(/* GraphQL */ `
@@ -2973,7 +3020,7 @@ graphql(/* GraphQL */ `
2973
3020
  const getMetadata = async (props) => {
2974
3021
  const appDb = BaseDb.getAppDb();
2975
3022
  let storageTransactionId;
2976
- {
3023
+ if (props) {
2977
3024
  storageTransactionId = props.storageTransactionId;
2978
3025
  }
2979
3026
  const whereClauses = [];
@@ -3016,10 +3063,10 @@ const GET_TRANSACTION_TAGS = graphql(/* GraphQL */ `
3016
3063
 
3017
3064
  const initArweaveClient = async () => {
3018
3065
  if (isBrowser()) {
3019
- (await import('./ArweaveClient-D5iJisYr.js')).ArweaveClient;
3066
+ (await import('./ArweaveClient-C0g0es2v.js')).ArweaveClient;
3020
3067
  }
3021
3068
  if (!isBrowser()) {
3022
- (await import('./ArweaveClient-HEIIuOfB.js')).ArweaveClient;
3069
+ (await import('./ArweaveClient-CzkBgiZY.js')).ArweaveClient;
3023
3070
  }
3024
3071
  };
3025
3072
  let domain = 'arweave.net';
@@ -3062,8 +3109,11 @@ const setArweaveDomain = (newDomain) => {
3062
3109
  domain = newDomain;
3063
3110
  };
3064
3111
 
3065
- const logger$i = debug('app:files:download');
3112
+ const logger$f = debug('app:files:download');
3066
3113
  const downloadAllFilesRequestHandler = async ({ endpoints, eventId, }) => {
3114
+ if (!isBrowser()) {
3115
+ return;
3116
+ }
3067
3117
  await syncDbFiles(endpoints);
3068
3118
  eventEmitter.emit('fs.downloadAll.success', { eventId });
3069
3119
  eventEmitter.emit('fs.downloadAllBinary.request', { endpoints });
@@ -3146,7 +3196,7 @@ const downloadAllFilesBinaryRequestHandler = async () => {
3146
3196
  try {
3147
3197
  const res = await fetch(`https://${ARWEAVE_HOST}/tx/${transactionId}/status`);
3148
3198
  if (res.status !== 200) {
3149
- logger$i(`[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`);
3199
+ logger$f(`[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`);
3150
3200
  excludedTransactions.add(transactionId);
3151
3201
  await saveAppState$1('excludedTransactions', JSON.stringify(Array.from(excludedTransactions)));
3152
3202
  continue;
@@ -3175,7 +3225,7 @@ const downloadAllFilesBinaryRequestHandler = async () => {
3175
3225
  transactionIdsToDownload.push(transactionId);
3176
3226
  }
3177
3227
  catch (error) {
3178
- logger$i(error);
3228
+ logger$f(error);
3179
3229
  }
3180
3230
  }
3181
3231
  console.log('[download] Calling downloadAllFiles with transactionIdsToDownload', transactionIdsToDownload);
@@ -3226,23 +3276,25 @@ const isFsInitialized = () => {
3226
3276
  return isInitialized;
3227
3277
  };
3228
3278
 
3229
- const logger$h = debug('app:internal:actors:configureFs');
3279
+ const logger$e = debug('app:internal:actors:configureFs');
3230
3280
  const configureFs = fromCallback(({ sendBack, input: { context } }) => {
3231
3281
  const { endpoints, appDbService, filesDir, } = context;
3232
- logger$h('[internal/actors] [configureFs] Configuring FS');
3282
+ logger$e('[internal/actors] [configureFs] Configuring FS');
3233
3283
  const _configureFs = async () => {
3234
- logger$h('[internal/actors] [configureFs] calling _configureFs');
3235
- logger$h('[internal/actors] [configureFs] areFsListenersReady:', areFsListenersReady());
3236
- logger$h('[internal/actors] [configureFs] isFsInitialized:', isFsInitialized());
3237
- await waitForEvent({
3238
- req: {
3239
- eventLabel: 'fs.downloadAll.request',
3240
- data: { endpoints },
3241
- },
3242
- res: {
3243
- eventLabel: 'fs.downloadAll.success',
3244
- },
3245
- });
3284
+ logger$e('[internal/actors] [configureFs] calling _configureFs');
3285
+ logger$e('[internal/actors] [configureFs] areFsListenersReady:', areFsListenersReady());
3286
+ logger$e('[internal/actors] [configureFs] isFsInitialized:', isFsInitialized());
3287
+ if (isBrowser()) {
3288
+ await waitForEvent({
3289
+ req: {
3290
+ eventLabel: 'fs.downloadAll.request',
3291
+ data: { endpoints },
3292
+ },
3293
+ res: {
3294
+ eventLabel: 'fs.downloadAll.success',
3295
+ },
3296
+ });
3297
+ }
3246
3298
  const journalPath = `${filesDir || BROWSER_FS_TOP_DIR}/db/meta/_journal.json`;
3247
3299
  let journalExists = await fs.promises.exists(journalPath);
3248
3300
  if (!journalExists) {
@@ -3250,7 +3302,7 @@ const configureFs = fromCallback(({ sendBack, input: { context } }) => {
3250
3302
  }
3251
3303
  if (journalExists) {
3252
3304
  appDbService.send({ type: DB_WAITING_FOR_FILES_RECEIVED });
3253
- logger$h('[internal/actors] [configureFs] fs configured!');
3305
+ logger$e('[internal/actors] [configureFs] fs configured!');
3254
3306
  return true;
3255
3307
  }
3256
3308
  sendBack({ type: 'shouldWaitForFiles' });
@@ -3283,15 +3335,8 @@ const configureFs = fromCallback(({ sendBack, input: { context } }) => {
3283
3335
  return () => { };
3284
3336
  });
3285
3337
 
3286
- const logger$g = debug('app:services:internal:actors:saveConfig');
3338
+ const logger$d = debug('app:services:internal:actors:saveConfig');
3287
3339
  const saveConfig = fromCallback(({ sendBack, input: { context } }) => {
3288
- if (typeof window === 'undefined') {
3289
- console.error('seedInitBrowser called from non-browser context');
3290
- sendBack({
3291
- type: 'error',
3292
- error: 'Browser method called from non-browser context',
3293
- });
3294
- }
3295
3340
  const { endpoints, addresses, arweaveDomain } = context;
3296
3341
  if (!endpoints) {
3297
3342
  throw new Error('saveConfig called with invalid endpoints');
@@ -3304,81 +3349,84 @@ const saveConfig = fromCallback(({ sendBack, input: { context } }) => {
3304
3349
  }
3305
3350
  const endpointsValueString = JSON.stringify(endpoints);
3306
3351
  const addressesValueString = JSON.stringify(addresses);
3352
+ const tableColumns = getTableColumns(appState);
3353
+ logger$d('tableColumns', tableColumns);
3354
+ const { columns, indexes, foreignKeys, checks, primaryKeys, name, } = getTableConfig(appState);
3355
+ logger$d('columns', columns);
3356
+ logger$d('indexes', indexes);
3357
+ logger$d('foreignKeys', foreignKeys);
3358
+ logger$d('checks', checks);
3359
+ logger$d('primaryKeys', primaryKeys);
3360
+ logger$d('name', name);
3361
+ logger$d('calling select on db');
3362
+ const queryResult = await appDb.select().from(appState);
3363
+ logger$d('queryResult', queryResult);
3307
3364
  // TODO: Figure out how to define on conflict with multiple rows added
3308
- try {
3309
- // logger('[sdk] [internal/actors] Saving endpoints to db')
3310
- await appDb
3311
- .insert(appState)
3312
- .values({
3313
- key: 'endpoints',
3365
+ await appDb
3366
+ .insert(appState)
3367
+ .values({
3368
+ key: 'endpoints',
3369
+ value: endpointsValueString,
3370
+ })
3371
+ .onConflictDoUpdate({
3372
+ target: appState.key,
3373
+ set: {
3314
3374
  value: endpointsValueString,
3315
- })
3316
- .onConflictDoUpdate({
3317
- target: appState.key,
3318
- set: {
3319
- value: endpointsValueString,
3320
- },
3321
- });
3322
- // logger('[sdk] [internal/actors] Saving addresses to db')
3323
- await appDb
3324
- .insert(appState)
3325
- .values({
3326
- key: 'addresses',
3375
+ },
3376
+ });
3377
+ // logger('[sdk] [internal/actors] Saving addresses to db')
3378
+ await appDb
3379
+ .insert(appState)
3380
+ .values({
3381
+ key: 'addresses',
3382
+ value: addressesValueString,
3383
+ })
3384
+ .onConflictDoUpdate({
3385
+ target: appState.key,
3386
+ set: {
3327
3387
  value: addressesValueString,
3328
- })
3329
- .onConflictDoUpdate({
3330
- target: appState.key,
3331
- set: {
3332
- value: addressesValueString,
3333
- },
3334
- });
3335
- await appDb
3336
- .insert(appState)
3337
- .values({
3338
- key: 'arweaveDomain',
3388
+ },
3389
+ });
3390
+ await appDb
3391
+ .insert(appState)
3392
+ .values({
3393
+ key: 'arweaveDomain',
3394
+ value: arweaveDomain || 'arweave.net',
3395
+ })
3396
+ .onConflictDoUpdate({
3397
+ target: appState.key,
3398
+ set: {
3339
3399
  value: arweaveDomain || 'arweave.net',
3340
- })
3341
- .onConflictDoUpdate({
3342
- target: appState.key,
3343
- set: {
3344
- value: arweaveDomain || 'arweave.net',
3345
- },
3346
- });
3347
- logger$g('[sdk] [internal/actors] Should be done saving');
3348
- }
3349
- catch (error) {
3350
- console.error('Error saving config:', error);
3351
- }
3400
+ },
3401
+ });
3402
+ logger$d('[sdk] [internal/actors] Should be done saving');
3352
3403
  };
3353
3404
  _saveConfig().then(() => {
3354
- logger$g('[sdk] [internal/actors] Successfully saved config');
3405
+ logger$d('[sdk] [internal/actors] Successfully saved config');
3355
3406
  return sendBack({ type: INTERNAL_SAVING_CONFIG_SUCCESS });
3356
3407
  });
3357
3408
  return () => { };
3358
3409
  });
3359
3410
 
3360
- const logger$f = debug('app:services:internal:actors:loadAppDb');
3411
+ debug('app:services:internal:actors:loadAppDb');
3361
3412
  const loadAppDb = fromCallback(({ sendBack, input: { context } }) => {
3362
3413
  const { appDbService } = context;
3363
3414
  let subscription;
3364
3415
  const _loadAppDb = async () => {
3416
+ if (appDbService.getSnapshot().value === 'ready') {
3417
+ return;
3418
+ }
3365
3419
  return new Promise((resolve) => {
3366
- if (appDbService.getSnapshot().value === 'ready') {
3367
- return resolve();
3368
- }
3369
- subscription = appDbService.subscribe({
3370
- next: (snapshot) => {
3371
- if (snapshot.value === 'ready') {
3372
- return resolve();
3373
- }
3374
- sendBack({ type: DB_ON_SNAPSHOT, dbName: DB_NAME_APP, snapshot });
3375
- },
3420
+ subscription = appDbService.subscribe((snapshot) => {
3421
+ if (snapshot.value === 'ready') {
3422
+ return resolve();
3423
+ }
3424
+ sendBack({ type: DB_ON_SNAPSHOT, dbName: DB_NAME_APP, snapshot });
3376
3425
  });
3377
3426
  });
3378
3427
  };
3379
3428
  _loadAppDb().then(() => {
3380
3429
  sendBack({ type: INTERNAL_LOADING_APP_DB_SUCCESS });
3381
- logger$f('[sdk] [internal/actors] Successfully loaded app DB');
3382
3430
  });
3383
3431
  return () => {
3384
3432
  if (subscription) {
@@ -3389,6 +3437,10 @@ const loadAppDb = fromCallback(({ sendBack, input: { context } }) => {
3389
3437
 
3390
3438
  debug('app:services:internal:actors:waitForFiles');
3391
3439
  const waitForFiles = fromCallback(({ sendBack, input: { context } }) => {
3440
+ if (!isBrowser()) {
3441
+ sendBack({ type: 'filesReceived' });
3442
+ return;
3443
+ }
3392
3444
  const { endpoints } = context;
3393
3445
  const filesDir = endpoints.files;
3394
3446
  const _waitForFiles = async () => {
@@ -3408,8 +3460,8 @@ const waitForFiles = fromCallback(({ sendBack, input: { context } }) => {
3408
3460
  });
3409
3461
  });
3410
3462
 
3411
- const logger$e = debug('app:services:internal:machine');
3412
- createBrowserInspector({
3463
+ const logger$c = debug('app:services:internal:machine');
3464
+ const { inspect: inspect$1 } = createBrowserInspector({
3413
3465
  autoStart: false,
3414
3466
  });
3415
3467
  const { IDLE: IDLE$1, VALIDATING_INPUT, SAVING_CONFIG, CONFIGURING_FS, LOADING_APP_DB, } = InternalState;
@@ -3445,11 +3497,14 @@ const internalMachine = setup({
3445
3497
  target: VALIDATING_INPUT,
3446
3498
  actions: [
3447
3499
  assign({
3448
- appDbService: ({ spawn }) => spawn(dbMachine, {
3449
- input: {
3450
- dbName: DB_NAME_APP,
3451
- },
3452
- }),
3500
+ appDbService: ({ context, spawn }) => {
3501
+ return spawn(dbMachine, {
3502
+ input: {
3503
+ dbName: DB_NAME_APP,
3504
+ pathToDir: context?.filesDir,
3505
+ },
3506
+ });
3507
+ },
3453
3508
  }),
3454
3509
  ],
3455
3510
  },
@@ -3528,7 +3583,7 @@ const internalMachine = setup({
3528
3583
  [INTERNAL_LOADING_APP_DB_SUCCESS]: {
3529
3584
  target: SAVING_CONFIG,
3530
3585
  actions: () => {
3531
- logger$e('[sdk] [internal/index] App DB loaded!');
3586
+ logger$c('[sdk] [internal/index] App DB loaded!');
3532
3587
  },
3533
3588
  },
3534
3589
  },
@@ -3554,7 +3609,8 @@ const internalMachine = setup({
3554
3609
  },
3555
3610
  ready: {
3556
3611
  entry: () => {
3557
- logger$e('[sdk] [internal/index] Ready!');
3612
+ console.log('[sdk] [internal/index] Ready!');
3613
+ logger$c('[sdk] [internal/index] Ready!');
3558
3614
  },
3559
3615
  meta: {
3560
3616
  displayText: "Crossing the t's ...",
@@ -3569,7 +3625,7 @@ const internalMachine = setup({
3569
3625
  },
3570
3626
  },
3571
3627
  entry: () => {
3572
- logger$e('[sdk] [internal/index] Error!');
3628
+ logger$c('[sdk] [internal/index] Error!');
3573
3629
  },
3574
3630
  meta: {
3575
3631
  displayText: 'Whoops! Something went wrong.',
@@ -3739,6 +3795,7 @@ const initialize$2 = fromCallback(({ sendBack, input: { context } }) => {
3739
3795
  });
3740
3796
 
3741
3797
  const fetchDbData = fromCallback(({ sendBack, input: { context } }) => {
3798
+ const { modelNamePlural, times } = context;
3742
3799
  const _fetchDbData = async () => { };
3743
3800
  _fetchDbData().then(() => {
3744
3801
  sendBack({ type: 'fetchDbDataSuccess' });
@@ -3746,7 +3803,7 @@ const fetchDbData = fromCallback(({ sendBack, input: { context } }) => {
3746
3803
  return () => { };
3747
3804
  });
3748
3805
 
3749
- const logger$d = debug('app:allItemsActors:fetchSeeds');
3806
+ debug('app:allItemsActors:fetchSeeds');
3750
3807
  const fetchSeeds = fromCallback(({ sendBack, input: { context } }) => {
3751
3808
  const { queryVariables, modelName } = context;
3752
3809
  if (!queryVariables) {
@@ -3757,8 +3814,6 @@ const fetchSeeds = fromCallback(({ sendBack, input: { context } }) => {
3757
3814
  const queryKey = [`getSeeds${modelName}`];
3758
3815
  const queryClient = BaseQueryClient.getQueryClient();
3759
3816
  const easClient = BaseEasClient.getEasClient();
3760
- const cachedResults = queryClient.getQueryData(queryKey);
3761
- logger$d(`[allItemsActors] [fetchSeeds] cachedResults ${Date.now()}`, cachedResults);
3762
3817
  const results = await queryClient.fetchQuery({
3763
3818
  queryKey,
3764
3819
  queryFn: async () => easClient.request(GET_SEEDS, queryVariables),
@@ -4173,7 +4228,7 @@ const preparePublishRequestData = fromCallback(({ sendBack, input: { context } }
4173
4228
  }
4174
4229
  const versionSchemaUid = modelsRows[0].schemaUid;
4175
4230
  await item.getEditedProperties();
4176
- await getModelSchemas();
4231
+ const { modelSchemas, schemaStringToModelRecord } = await getModelSchemas();
4177
4232
  // const dataEncoder = new SchemaEncoder(modelProperty.schemaDefinition,)
4178
4233
  // const encodedData = dataEncoder.encodeData(data,)
4179
4234
  //
@@ -4207,13 +4262,13 @@ const preparePublishRequestData = fromCallback(({ sendBack, input: { context } }
4207
4262
  });
4208
4263
  });
4209
4264
 
4210
- const logger$c = debug('app:services:publish:actors:upload');
4265
+ const logger$b = debug('app:services:publish:actors:upload');
4211
4266
  const upload = fromCallback(({ sendBack, input: { context } }) => {
4212
4267
  const { localId } = context;
4213
4268
  const _upload = async () => {
4214
4269
  const item = await BaseItem.find({ seedLocalId: localId });
4215
4270
  if (!item) {
4216
- logger$c('no item with localId', localId);
4271
+ logger$b('no item with localId', localId);
4217
4272
  return false;
4218
4273
  }
4219
4274
  const editedProperties = await item.getEditedProperties();
@@ -4231,7 +4286,7 @@ const upload = fromCallback(({ sendBack, input: { context } }) => {
4231
4286
  editedProperty.propertyDef.refValueType === 'ImageSrc') {
4232
4287
  const context = editedProperty.getService().getSnapshot().context;
4233
4288
  const imageSeedId = context.propertyValue;
4234
- getCorrectId(imageSeedId);
4289
+ const { localId, uid } = getCorrectId(imageSeedId);
4235
4290
  }
4236
4291
  if (editedProperty.propertyDef.storageType === 'ItemStorage' &&
4237
4292
  editedProperty.propertyDef.localStorageDir) ;
@@ -4334,7 +4389,7 @@ const savePublishService = fromCallback(({ sendBack, input: { event, context } }
4334
4389
  });
4335
4390
 
4336
4391
  const { UNINITIALIZED, INITIALIZING, INITIALIZED, PUBLISHING_ITEM, ADDING_MODELS_TO_DB, } = GlobalState;
4337
- createBrowserInspector({
4392
+ const { inspect } = createBrowserInspector({
4338
4393
  autoStart: false,
4339
4394
  });
4340
4395
  const globalMachine = setup({
@@ -5144,7 +5199,7 @@ const getSeedData = async ({ seedLocalId, seedUid }) => {
5144
5199
  return rows[0];
5145
5200
  };
5146
5201
 
5147
- const logger$b = debug('app:db:read:getItemData');
5202
+ const logger$a = debug('app:db:read:getItemData');
5148
5203
  const getItemData = async ({ modelName, seedLocalId, seedUid, }) => {
5149
5204
  if (!seedLocalId && !seedUid) {
5150
5205
  throw new Error('[db/queries] [getItem] no seedLocalId or seedUid');
@@ -5152,7 +5207,7 @@ const getItemData = async ({ modelName, seedLocalId, seedUid, }) => {
5152
5207
  if (seedUid && !seedLocalId) {
5153
5208
  const seedData = await getSeedData({ seedUid });
5154
5209
  if (!seedData) {
5155
- logger$b('[db/queries] [getItem] no seedData seedUid', seedUid);
5210
+ logger$a('[db/queries] [getItem] no seedData seedUid', seedUid);
5156
5211
  return;
5157
5212
  }
5158
5213
  seedLocalId = seedData.localId;
@@ -5187,7 +5242,7 @@ const getItemData = async ({ modelName, seedLocalId, seedUid, }) => {
5187
5242
  .orderBy(sql.raw('COALESCE(attestation_created_at, created_at) DESC'))
5188
5243
  .groupBy(seeds.localId);
5189
5244
  if (!itemDataRows || itemDataRows.length === 0) {
5190
- logger$b('[db/queries] [getItemDataFromDb] no itemDataRows');
5245
+ logger$a('[db/queries] [getItemDataFromDb] no itemDataRows');
5191
5246
  return;
5192
5247
  }
5193
5248
  let itemData = itemDataRows[0];
@@ -5416,7 +5471,7 @@ const getRelationValueData = async (propertyValue) => {
5416
5471
  return rows[0];
5417
5472
  };
5418
5473
 
5419
- const logger$a = debug('app:property:actors:resolveRelatedValue');
5474
+ const logger$9 = debug('app:property:actors:resolveRelatedValue');
5420
5475
  const storageTransactionIdToContentUrl = new Map();
5421
5476
  const refResolvedValueToContentUrl = new Map();
5422
5477
  const seedUidToContentUrl = new Map();
@@ -5431,7 +5486,7 @@ const resolveRelatedValue = fromCallback(({ sendBack, input: { context } }) => {
5431
5486
  parsedValue = JSON.parse(propertyValue);
5432
5487
  }
5433
5488
  catch (error) {
5434
- logger$a(`${propertyName} value is not a JSON string.`);
5489
+ logger$9(`${propertyName} value is not a JSON string.`);
5435
5490
  }
5436
5491
  if (!parsedValue && seedUidToContentUrl.has(propertyValue)) {
5437
5492
  const contentUrl = seedUidToContentUrl.get(propertyValue);
@@ -5447,11 +5502,11 @@ const resolveRelatedValue = fromCallback(({ sendBack, input: { context } }) => {
5447
5502
  }
5448
5503
  if (Array.isArray(propertyValue)) {
5449
5504
  // TODO: Handle array of seedUids
5450
- logger$a(`${propertyName} value is an array of seedUids`);
5505
+ logger$9(`${propertyName} value is an array of seedUids`);
5451
5506
  return;
5452
5507
  }
5453
5508
  if (Array.isArray(parsedValue)) {
5454
- logger$a(`${propertyName} value is a stringified array of seedUids`);
5509
+ logger$9(`${propertyName} value is a stringified array of seedUids`);
5455
5510
  return;
5456
5511
  }
5457
5512
  const storageTransactionId = await getStorageTransactionIdForSeedUid(propertyValue);
@@ -5891,7 +5946,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
5891
5946
  if (propertyRecordSchema &&
5892
5947
  propertyRecordSchema.storageType &&
5893
5948
  propertyRecordSchema.storageType === 'ItemStorage') {
5894
- const { Item } = await import('./index-DQNTvzqi.js');
5949
+ const { Item } = await import('./index-BAtjd9W-.js');
5895
5950
  const item = await Item.find({
5896
5951
  seedLocalId,
5897
5952
  modelName,
@@ -5936,10 +5991,10 @@ const getVersionData = async ({ localId, seedLocalId, uid, }) => {
5936
5991
  return queryRows[0];
5937
5992
  };
5938
5993
 
5939
- const logger$9 = debug('app:write:updateItemPropertyValue');
5994
+ const logger$8 = debug('app:write:updateItemPropertyValue');
5940
5995
  const updateItemPropertyValue = async ({ localId, propertyName, newValue, seedUid, seedLocalId, modelName, refSeedType, refResolvedValue, refResolvedDisplayValue, versionLocalId, versionUid, schemaUid, localStorageDir, }) => {
5941
5996
  if (!localId && !seedLocalId) {
5942
- logger$9(`[db/write] [updateItemPropertyValue] no propertyLocalId or seedLocalId for property: ${propertyName}`);
5997
+ logger$8(`[db/write] [updateItemPropertyValue] no propertyLocalId or seedLocalId for property: ${propertyName}`);
5943
5998
  return;
5944
5999
  }
5945
6000
  let safeNewValue = newValue;
@@ -5977,7 +6032,7 @@ const updateItemPropertyValue = async ({ localId, propertyName, newValue, seedUi
5977
6032
  modelType === modelName?.toLowerCase() &&
5978
6033
  refSeedTypeFromDb === refSeedType &&
5979
6034
  refResolvedValueFromDb === refResolvedValue) {
5980
- logger$9(`[db/write] [updateItemPropertyValue] value is the same as most recent record for property: ${propertyNameFromDb}`);
6035
+ logger$8(`[db/write] [updateItemPropertyValue] value is the same as most recent record for property: ${propertyNameFromDb}`);
5981
6036
  return;
5982
6037
  }
5983
6038
  // This means we already have a local-only record so we should just update that one
@@ -6363,11 +6418,7 @@ const saveImageSrc = fromCallback(({ sendBack, input: { context, event } }) => {
6363
6418
  refSeedType: 'image',
6364
6419
  refResolvedDisplayValue,
6365
6420
  refResolvedValue: fileName,
6366
- refModelUid: imageSchemaUid,
6367
- refSchemaUid: imageSchemaUid,
6368
- localStorageDir: '/images',
6369
- easDataType: 'bytes32',
6370
- });
6421
+ localStorageDir: '/images'});
6371
6422
  }
6372
6423
  sendBack({
6373
6424
  type: 'updateContext',
@@ -6795,7 +6846,7 @@ const getPropertyData$1 = async ({ propertyName, seedLocalId, seedUid, }) => {
6795
6846
  };
6796
6847
 
6797
6848
  var _a$1;
6798
- const logger$8 = debug('app:property:class');
6849
+ const logger$7 = debug('app:property:class');
6799
6850
  class BaseItemProperty {
6800
6851
  constructor(initialValues) {
6801
6852
  this._isRelation = false;
@@ -6842,7 +6893,7 @@ class BaseItemProperty {
6842
6893
  serviceInput.propertyValue = JSON.parse(propertyValue);
6843
6894
  }
6844
6895
  catch (e) {
6845
- logger$8('List property value is not JSON', e);
6896
+ logger$7('List property value is not JSON', e);
6846
6897
  }
6847
6898
  }
6848
6899
  const propertyNameSingular = pluralize(propertyName, 1);
@@ -6889,7 +6940,7 @@ class BaseItemProperty {
6889
6940
  }
6890
6941
  }
6891
6942
  catch (e) {
6892
- logger$8(`[ItemProperty] [${context.seedLocalId}] [${context.propertyName}] [storageType] error`, e);
6943
+ logger$7(`[ItemProperty] [${context.seedLocalId}] [${context.propertyName}] [storageType] error`, e);
6893
6944
  renderValue = 'No file found';
6894
6945
  }
6895
6946
  }
@@ -7134,7 +7185,7 @@ const getSegmentedItemProperties = (item) => {
7134
7185
  };
7135
7186
  };
7136
7187
 
7137
- const logger$7 = debug('app:item:getPublishUploads');
7188
+ const logger$6 = debug('app:item:getPublishUploads');
7138
7189
  const prepareArweaveTransaction = async (data, contentHash) => {
7139
7190
  const transactionData = {
7140
7191
  data,
@@ -7142,8 +7193,8 @@ const prepareArweaveTransaction = async (data, contentHash) => {
7142
7193
  };
7143
7194
  const tx = await getArweave().createTransaction(transactionData);
7144
7195
  if (contentHash) {
7145
- logger$7('contentHash', contentHash);
7146
- logger$7('adding content hash tag to tx.id:', tx.id);
7196
+ logger$6('contentHash', contentHash);
7197
+ logger$6('adding content hash tag to tx.id:', tx.id);
7147
7198
  tx.addTag('Content-SHA-256', contentHash);
7148
7199
  }
7149
7200
  return tx;
@@ -7841,7 +7892,7 @@ const initItem = async () => {
7841
7892
  Item$2 = (await Promise.resolve().then(function () { return Item$1; })).Item;
7842
7893
  }
7843
7894
  if (!isBrowser()) {
7844
- Item$2 = (await import('./Item-CbgjLSUx.js')).Item;
7895
+ Item$2 = (await import('./Item-D9HFPxsK.js')).Item;
7845
7896
  }
7846
7897
  };
7847
7898
 
@@ -7851,17 +7902,17 @@ const initItemProperty = async () => {
7851
7902
  ItemProperty$2 = (await Promise.resolve().then(function () { return ItemProperty$1; })).ItemProperty;
7852
7903
  }
7853
7904
  if (!isBrowser()) {
7854
- ItemProperty$2 = (await import('./ItemProperty-DduurIcl.js')).ItemProperty;
7905
+ ItemProperty$2 = (await import('./ItemProperty-BdtvKrEy.js')).ItemProperty;
7855
7906
  }
7856
7907
  };
7857
7908
 
7858
7909
  let Db;
7859
7910
  const initDb = async () => {
7860
7911
  if (isBrowser()) {
7861
- Db = (await import('./Db-jMth8Y2g.js')).Db;
7912
+ Db = (await import('./Db-C4oog-0n.js')).Db;
7862
7913
  }
7863
7914
  if (!isBrowser()) {
7864
- Db = (await import('./Db-DK9wSNIH.js')).Db;
7915
+ Db = (await import('./Db-VPouegkr.js')).Db;
7865
7916
  }
7866
7917
  // TODO: Add config for React Native
7867
7918
  };
@@ -7878,7 +7929,7 @@ var Item$1 = /*#__PURE__*/Object.freeze({
7878
7929
  Item: Item
7879
7930
  });
7880
7931
 
7881
- const logger$6 = debug('app:react:services');
7932
+ const logger$5 = debug('app:react:services');
7882
7933
  const finalStrings = ['idle', 'ready', 'done', 'success', 'initialized'];
7883
7934
  const getServiceName = (service) => {
7884
7935
  let name = 'actor';
@@ -7925,7 +7976,7 @@ const getServiceUniqueKey = (service) => {
7925
7976
  snapshot = service.getSnapshot();
7926
7977
  }
7927
7978
  catch (error) {
7928
- logger$6('Error:', error);
7979
+ logger$5('Error:', error);
7929
7980
  return uniqueKey;
7930
7981
  }
7931
7982
  if (snapshot) {
@@ -8154,7 +8205,7 @@ const useGlobalServiceStatus = () => {
8154
8205
  };
8155
8206
  };
8156
8207
 
8157
- const logger$5 = debug('app:react:item');
8208
+ const logger$4 = debug('app:react:item');
8158
8209
  const useItem = ({ modelName, seedLocalId, seedUid }) => {
8159
8210
  // const [itemSubscription, setItemSubscription] = useState<
8160
8211
  // Subscription | undefined
@@ -8231,7 +8282,7 @@ const useItem = ({ modelName, seedLocalId, seedUid }) => {
8231
8282
  seedUid,
8232
8283
  });
8233
8284
  if (!foundItem) {
8234
- logger$5('[useItem] [getItemFromDb] no item found', modelName, seedLocalId);
8285
+ logger$4('[useItem] [getItemFromDb] no item found', modelName, seedLocalId);
8235
8286
  isReadingDb.current = false;
8236
8287
  return;
8237
8288
  }
@@ -8253,7 +8304,7 @@ const useItem = ({ modelName, seedLocalId, seedUid }) => {
8253
8304
  const subscription = item.subscribe(async (_) => {
8254
8305
  const newItem = await Item.find({ modelName, seedLocalId, seedUid });
8255
8306
  if (!newItem) {
8256
- logger$5('[useItem] [itemSubscription] no item found', modelName, seedLocalId);
8307
+ logger$4('[useItem] [itemSubscription] no item found', modelName, seedLocalId);
8257
8308
  return;
8258
8309
  }
8259
8310
  updateItem(newItem);
@@ -8412,7 +8463,7 @@ var ItemProperty$1 = /*#__PURE__*/Object.freeze({
8412
8463
  ItemProperty: ItemProperty
8413
8464
  });
8414
8465
 
8415
- const logger$4 = debug('app:react:property');
8466
+ const logger$3 = debug('app:react:property');
8416
8467
  const useItemProperty = (props = {
8417
8468
  propertyName: '',
8418
8469
  seedLocalId: '',
@@ -8443,7 +8494,7 @@ const useItemProperty = (props = {
8443
8494
  seedUid,
8444
8495
  });
8445
8496
  if (!foundProperty) {
8446
- logger$4(`[useItemPropertyTest] [readFromDb] no property found for Item.${seedLocalId}.${propertyName}`);
8497
+ logger$3(`[useItemPropertyTest] [readFromDb] no property found for Item.${seedLocalId}.${propertyName}`);
8447
8498
  isReadingDb.current = false;
8448
8499
  return;
8449
8500
  }
@@ -8480,7 +8531,7 @@ const useItemProperty = (props = {
8480
8531
  };
8481
8532
  const useItemProperties = (item) => {
8482
8533
  const [propertyObj, setPropertyObj] = useImmer({});
8483
- useState(false);
8534
+ const [isListening, setIsListening] = useState(false);
8484
8535
  const updatePropertyObj = useCallback((event) => {
8485
8536
  if (!item) {
8486
8537
  console.error('[XXXXXX] [updatePropertyObj] no item when expected');
@@ -8617,10 +8668,10 @@ const withSeed = (config, webpack, isServer) => {
8617
8668
 
8618
8669
  const initEasClient = async () => {
8619
8670
  if (isBrowser()) {
8620
- (await import('./EasClient-jqkT2ZBt.js')).EasClient;
8671
+ (await import('./EasClient-B9a3NsTi.js')).EasClient;
8621
8672
  }
8622
8673
  if (!isBrowser()) {
8623
- (await import('./EasClient-D3wKgt0o.js')).EasClient;
8674
+ (await import('./EasClient-DQ93i2ci.js')).EasClient;
8624
8675
  }
8625
8676
  };
8626
8677
 
@@ -8629,23 +8680,23 @@ const initFileManager = async () => {
8629
8680
  (await Promise.resolve().then(function () { return FileManager$1; })).FileManager;
8630
8681
  }
8631
8682
  if (!isBrowser()) {
8632
- (await import('./FileManager-4mWYO3Mt.js')).FileManager;
8683
+ (await import('./FileManager-_ErxVuwb.js')).FileManager;
8633
8684
  }
8634
8685
  };
8635
8686
 
8636
8687
  const initQueryClient = async () => {
8637
8688
  if (isBrowser()) {
8638
- (await import('./QueryClient-CBOP3OoU.js')).QueryClient;
8689
+ (await import('./QueryClient-hzOtFe99.js')).QueryClient;
8639
8690
  }
8640
8691
  if (!isBrowser()) {
8641
- (await import('./QueryClient-bKb3SB0W.js')).QueryClient;
8692
+ (await import('./QueryClient-Bmnv_moN.js')).QueryClient;
8642
8693
  }
8643
8694
  };
8644
8695
 
8645
- const logger$3 = debug('app:services:events');
8696
+ const logger$2 = debug('app:services:events');
8646
8697
  const handleServiceSaveState = (event) => {
8647
8698
  const { state, serviceId } = event;
8648
- logger$3(`[browser] [service.saveState.request] serviceId: ${serviceId}`);
8699
+ logger$2(`[browser] [service.saveState.request] serviceId: ${serviceId}`);
8649
8700
  localStorage.setItem(`seed_sdk_service_${serviceId}`, JSON.stringify(state));
8650
8701
  };
8651
8702
  const setupServicesEventHandlers = () => {
@@ -8671,9 +8722,9 @@ const setupServiceHandlers = () => {
8671
8722
  eventEmitter.addListener('service.save', saveServiceHandler);
8672
8723
  };
8673
8724
 
8674
- const logger$2 = debug('app:ClientManager:initialize');
8725
+ const logger$1 = debug('app:ClientManager:initialize');
8675
8726
  const initialize = fromCallback(({ sendBack, input: { context, event } }) => {
8676
- logger$2('initialize from ClientManager');
8727
+ logger$1('initialize from ClientManager');
8677
8728
  const { isInitialized } = context;
8678
8729
  const { options, } = event;
8679
8730
  if (isInitialized) {
@@ -8689,7 +8740,8 @@ const initialize = fromCallback(({ sendBack, input: { context, event } }) => {
8689
8740
  await initQueryClient();
8690
8741
  await initFileManager();
8691
8742
  await initDb();
8692
- const { endpoints, models, arweaveDomain, filesDir, } = config;
8743
+ const { models, endpoints, arweaveDomain, } = config;
8744
+ const { files } = endpoints;
8693
8745
  if (arweaveDomain) {
8694
8746
  setArweaveDomain(arweaveDomain);
8695
8747
  }
@@ -8706,18 +8758,24 @@ const initialize = fromCallback(({ sendBack, input: { context, event } }) => {
8706
8758
  if (!areFsListenersReady()) {
8707
8759
  console.error('fs listeners not ready during init');
8708
8760
  }
8761
+ const globalService = getGlobalService();
8709
8762
  globalService.send({
8710
8763
  type: 'init',
8711
8764
  endpoints,
8712
8765
  models,
8713
8766
  addresses,
8714
8767
  arweaveDomain,
8715
- filesDir,
8768
+ filesDir: files,
8716
8769
  });
8717
- const { models: internalModels } = await import('./seed.schema.config-B-4U2RRq.js');
8770
+ const { models: internalModels } = await import('./seed.schema.config-BxJYabim.js');
8718
8771
  for (const [key, value] of Object.entries(internalModels)) {
8719
8772
  setModel(key, value);
8720
8773
  }
8774
+ await waitFor(globalService, (snapshot) => {
8775
+ logger$1('snapshot.value', snapshot.value);
8776
+ return snapshot.value === GlobalState.INITIALIZED;
8777
+ });
8778
+ logger$1('globalService initialized');
8721
8779
  };
8722
8780
  _initialize().then(() => {
8723
8781
  sendBack({ type: 'initialized' });
@@ -8725,8 +8783,7 @@ const initialize = fromCallback(({ sendBack, input: { context, event } }) => {
8725
8783
  });
8726
8784
 
8727
8785
  debug('app:client:writeToDb');
8728
- const saveAppState = fromCallback(({ sendBack, input: { context, event } }) => {
8729
- const { key, value } = event;
8786
+ const saveAppState = fromCallback(({ sendBack, input: { key, value } }) => {
8730
8787
  const _saveAppState = async () => {
8731
8788
  const { BaseDb } = await Promise.resolve().then(function () { return BaseDb$1; });
8732
8789
  if (!BaseDb) {
@@ -8736,6 +8793,7 @@ const saveAppState = fromCallback(({ sendBack, input: { context, event } }) => {
8736
8793
  if (!appDb) {
8737
8794
  throw new Error('App DB not found');
8738
8795
  }
8796
+ console.log(`key: ${key} value: ${value}`);
8739
8797
  appDb.insert(appState)
8740
8798
  .values({
8741
8799
  key: key,
@@ -8751,6 +8809,8 @@ const saveAppState = fromCallback(({ sendBack, input: { context, event } }) => {
8751
8809
  _saveAppState().then(() => {
8752
8810
  sendBack({
8753
8811
  type: 'saveAppStateSuccess',
8812
+ key,
8813
+ value,
8754
8814
  });
8755
8815
  });
8756
8816
  });
@@ -8765,6 +8825,7 @@ const setAddresses = assign(({ event, spawn }) => {
8765
8825
  });
8766
8826
  return {
8767
8827
  addresses,
8828
+ isSaving: true,
8768
8829
  };
8769
8830
  });
8770
8831
 
@@ -8803,101 +8864,77 @@ const clientManagerMachine = setup({
8803
8864
  },
8804
8865
  },
8805
8866
  idle: {
8867
+ entry: assign({
8868
+ isInitialized: true,
8869
+ }),
8806
8870
  on: {
8807
- setAddressesSuccess: {
8808
- actions: assign({
8809
- isSaving: false,
8871
+ saveAppStateSuccess: {
8872
+ actions: assign(({ event }) => {
8873
+ const { key, value } = event;
8874
+ return {
8875
+ isSaving: false
8876
+ };
8810
8877
  }),
8811
8878
  },
8812
- },
8813
- setAddresses: {
8814
- actions: ['setAddresses'],
8879
+ setAddresses: {
8880
+ actions: ['setAddresses'],
8881
+ },
8815
8882
  },
8816
8883
  },
8817
8884
  },
8818
8885
  });
8819
8886
 
8820
- const logger$1 = debug('app:client');
8887
+ const logger = debug('app:client');
8821
8888
  const clientManager = createActor(clientManagerMachine, {
8822
8889
  input: {
8823
8890
  isInitialized: false,
8824
8891
  }
8825
8892
  });
8826
8893
  const subscription = clientManager.subscribe((snapshot) => {
8827
- console.log('ClientManager snapshot:', snapshot);
8894
+ logger('ClientManager snapshot.value:', snapshot.value);
8895
+ logger('ClientManager snapshot.context.isInitialized:', snapshot.context.isInitialized);
8828
8896
  });
8829
8897
  clientManager.start();
8898
+ const ensureInitialized = () => {
8899
+ if (!clientManager.getSnapshot().context.isInitialized) {
8900
+ throw new Error(CLIENT_NOT_INITIALIZED);
8901
+ }
8902
+ };
8830
8903
  const ClientManager = {
8831
- getService: () => clientManager,
8904
+ isInitialized: () => clientManager.getSnapshot().context.isInitialized,
8905
+ getService: () => {
8906
+ ensureInitialized();
8907
+ return clientManager;
8908
+ },
8832
8909
  init: async (options) => {
8833
- clientManager.send({ type: 'init', options, });
8834
- await waitFor(clientManager, (snapshot) => snapshot.value === 'initialized');
8910
+ clientManager.send({ type: 'init', options });
8911
+ await waitFor(clientManager, (snapshot) => snapshot.context.isInitialized);
8835
8912
  },
8836
8913
  setAddresses: async (addresses) => {
8837
- logger$1('setAddresses', addresses);
8914
+ ensureInitialized();
8915
+ logger('setAddresses', addresses);
8838
8916
  clientManager.send({ type: 'setAddresses', addresses });
8839
8917
  await waitFor(clientManager, (snapshot) => !snapshot.context.isSaving);
8840
- logger$1('setAddresses success', addresses);
8918
+ logger('setAddresses success', addresses);
8919
+ },
8920
+ getAddresses: async () => {
8921
+ ensureInitialized();
8922
+ const db = await BaseDb.getAppDb();
8923
+ const results = await db.select().from(appState).where(eq(appState.key, 'addresses'));
8924
+ return JSON.parse(results[0]?.value);
8925
+ },
8926
+ stop: () => {
8927
+ ensureInitialized();
8928
+ clientManager.stop();
8841
8929
  },
8842
- stop: () => clientManager.stop(),
8843
8930
  unload: () => {
8931
+ ensureInitialized();
8844
8932
  clientManager.stop();
8845
8933
  subscription.unsubscribe();
8846
8934
  },
8847
8935
  };
8848
8936
 
8849
- const logger = debug('app:client');
8850
- const client = {
8851
- isInitialized: false,
8852
- init: async (options) => {
8853
- logger('init client');
8854
- await ClientManager.init(options);
8855
- logger('client initialized');
8856
- },
8857
- setAddresses: async (addresses) => {
8858
- ClientManager.setAddresses(addresses);
8859
- },
8860
- subscribe: (callback) => {
8861
- const subscription = globalService.subscribe(callback);
8862
- eventEmitter.addListener('internal.globalService', callback);
8863
- return {
8864
- unsubscribe: () => {
8865
- subscription.unsubscribe();
8866
- eventEmitter.removeListener('internal.globalService', callback);
8867
- },
8868
- };
8869
- },
8870
- on: (outerEvent, callback) => {
8871
- eventEmitter.addListener(outerEvent, callback);
8872
- return {
8873
- unsubscribe: () => {
8874
- eventEmitter.removeListener(outerEvent, callback);
8875
- },
8876
- };
8877
- },
8878
- getSeedClass: async () => {
8879
- return new Promise((resolve) => {
8880
- const subscription = globalService.subscribe((snapshot) => {
8881
- if (snapshot.status === 'done') {
8882
- resolve(snapshot.output);
8883
- }
8884
- });
8885
- globalService.send({ type: 'getSeed' });
8886
- subscription.unsubscribe();
8887
- });
8888
- },
8889
- getModel: (modelName) => {
8890
- return getModel(modelName);
8891
- },
8892
- getModels: () => {
8893
- return getModels();
8894
- },
8895
- getModelNames: () => {
8896
- return getModelNames();
8897
- },
8898
- };
8899
-
8900
8937
  enableMapSet();
8901
8938
 
8902
- export { BaseItem as B, Db as D, FileManager as F, Item as I, Json as J, List as L, Model as M, Property as P, Relation as R, Text as T, BaseItemProperty as a, BaseDb as b, ImageSrc as c, Item$2 as d, ItemProperty$2 as e, useItem as f, useItemProperties as g, useCreateItem as h, useItemProperty as i, useDeleteItem as j, useGlobalServiceStatus as k, usePublishItem as l, usePersistedSnapshots as m, useServices as n, useService as o, getCorrectId as p, getGlobalService as q, eventEmitter as r, client as s, useItems as u, withSeed as w };
8903
- //# sourceMappingURL=index-CTZqN6WI.js.map
8939
+ export { BaseItem as B, ClientManager as C, Db as D, FileManager as F, Item as I, Json as J, List as L, Model as M, Property as P, Relation as R, Text as T, BaseItemProperty as a, BaseDb as b, appState as c, ImageSrc as d, Item$2 as e, ItemProperty$2 as f, useItem as g, useItemProperties as h, isBrowser as i, useCreateItem as j, useItemProperty as k, useDeleteItem as l, useGlobalServiceStatus as m, usePublishItem as n, usePersistedSnapshots as o, useServices as p, useService as q, getCorrectId as r, getGlobalService as s, eventEmitter as t, useItems as u, withSeed as w };
8940
+ //# sourceMappingURL=index-BSR5hv7Q.js.map