@seedprotocol/sdk 0.2.30 → 0.2.32

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 (101) hide show
  1. package/dist/{ArweaveClient-C-HZgUWJ.js → ArweaveClient-BXD_aTsx.js} +2 -2
  2. package/dist/{ArweaveClient-rTTCUjiu.js.map → ArweaveClient-BXD_aTsx.js.map} +1 -1
  3. package/dist/{ArweaveClient-rTTCUjiu.js → ArweaveClient-CkcZD_QE.js} +2 -2
  4. package/dist/{ArweaveClient-C-HZgUWJ.js.map → ArweaveClient-CkcZD_QE.js.map} +1 -1
  5. package/dist/{Db-lX4nNJTb.js → Db-BKm58Z1E.js} +11 -9
  6. package/dist/{Db-lX4nNJTb.js.map → Db-BKm58Z1E.js.map} +1 -1
  7. package/dist/Db-xO-g5pKA.js +390 -0
  8. package/dist/Db-xO-g5pKA.js.map +1 -0
  9. package/dist/{EasClient-CKv5Eyao.js → EasClient-BNwSwDTO.js} +2 -2
  10. package/dist/{EasClient-nvmz2kCc.js.map → EasClient-BNwSwDTO.js.map} +1 -1
  11. package/dist/{EasClient-nvmz2kCc.js → EasClient-epqE9aWI.js} +2 -2
  12. package/dist/{EasClient-CKv5Eyao.js.map → EasClient-epqE9aWI.js.map} +1 -1
  13. package/dist/{FileManager-EGwM_VHY.js → FileManager-CXk83EW5.js} +4 -4
  14. package/dist/FileManager-CXk83EW5.js.map +1 -0
  15. package/dist/{FileManager-Bm_fGCH1.js → FileManager-DXi-X7r5.js} +2 -2
  16. package/dist/{FileManager-Bm_fGCH1.js.map → FileManager-DXi-X7r5.js.map} +1 -1
  17. package/dist/{Item-BRHX17yq.js → Item-DCdD-972.js} +5 -9
  18. package/dist/{Item-BRHX17yq.js.map → Item-DCdD-972.js.map} +1 -1
  19. package/dist/{ItemProperty-CZzIP1b8.js → ItemProperty-BlE3BrNc.js} +5 -9
  20. package/dist/{ItemProperty-CZzIP1b8.js.map → ItemProperty-BlE3BrNc.js.map} +1 -1
  21. package/dist/{QueryClient-CkqXe8Nk.js → QueryClient-Ckl99FYC.js} +2 -2
  22. package/dist/{QueryClient-CkqXe8Nk.js.map → QueryClient-Ckl99FYC.js.map} +1 -1
  23. package/dist/{QueryClient-pzZAYWa0.js → QueryClient-Do0C7Jnt.js} +2 -2
  24. package/dist/{QueryClient-pzZAYWa0.js.map → QueryClient-Do0C7Jnt.js.map} +1 -1
  25. package/dist/bin.js +6 -5
  26. package/dist/bin.js.map +1 -1
  27. package/dist/{constants-BjOTXEgm.js → constants-BakHTrB9.js} +2 -2
  28. package/dist/{constants-BjOTXEgm.js.map → constants-BakHTrB9.js.map} +1 -1
  29. package/dist/{index-BCmsQoYg.js → index-B2ovknu0.js} +112 -371
  30. package/dist/index-B2ovknu0.js.map +1 -0
  31. package/dist/{index-DzDVTUae.js → index-D3j5ZJGe.js} +5 -9
  32. package/dist/index-D3j5ZJGe.js.map +1 -0
  33. package/dist/main.js +6 -10
  34. package/dist/main.js.map +1 -1
  35. package/dist/{seed.schema.config-BswsDyRe.js → seed.schema.config-DQalKJ_d.js} +5 -9
  36. package/dist/seed.schema.config-DQalKJ_d.js.map +1 -0
  37. package/dist/src/BaseDb.ts +4 -0
  38. package/dist/src/BaseItem.ts +4 -0
  39. package/dist/src/Db.ts +5 -0
  40. package/dist/src/FileManager.ts +2 -2
  41. package/dist/src/IItem.ts +2 -1
  42. package/dist/src/SeedProtocolSdk.d.ts +0 -15
  43. package/dist/src/content-hash.ts +30 -0
  44. package/dist/src/create.ts +2 -2
  45. package/dist/src/createMetadata.ts +1 -1
  46. package/dist/src/download.ts +1 -1
  47. package/dist/src/getItem.ts +2 -3
  48. package/dist/src/getPublishPayload.ts +2 -8
  49. package/dist/src/hydrateFromDb.ts +2 -36
  50. package/dist/src/image-resize.ts +28 -0
  51. package/dist/src/migrate.ts +3 -241
  52. package/dist/src/preparePublishRequestData.ts +2 -2
  53. package/dist/src/propertyMachine.ts +1 -1
  54. package/dist/src/requestAll.ts +3 -3
  55. package/dist/src/saveImageSrc.ts +4 -0
  56. package/dist/src/saveItemStorage.ts +1 -1
  57. package/dist/src/upload.ts +2 -2
  58. package/dist/src/waitForDb.ts +18 -17
  59. package/dist/types/src/Item/BaseItem.d.ts +11 -1
  60. package/dist/types/src/Item/BaseItem.d.ts.map +1 -1
  61. package/dist/types/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
  62. package/dist/types/src/ItemProperty/service/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
  63. package/dist/types/src/browser/db/Db.d.ts +2 -0
  64. package/dist/types/src/browser/db/Db.d.ts.map +1 -1
  65. package/dist/types/src/browser/index.d.ts.map +1 -1
  66. package/dist/types/src/browser/react/item.d.ts +3 -2
  67. package/dist/types/src/browser/react/item.d.ts.map +1 -1
  68. package/dist/types/src/browser/workers/content-hash.d.ts +2 -0
  69. package/dist/types/src/browser/workers/content-hash.d.ts.map +1 -0
  70. package/dist/types/src/browser/workers/image-resize.d.ts +2 -0
  71. package/dist/types/src/browser/workers/image-resize.d.ts.map +1 -0
  72. package/dist/types/src/db/Db/BaseDb.d.ts +1 -0
  73. package/dist/types/src/db/Db/BaseDb.d.ts.map +1 -1
  74. package/dist/types/src/db/read/getItem.d.ts.map +1 -1
  75. package/dist/types/src/db/read/getPublishPayload.d.ts +2 -2
  76. package/dist/types/src/db/read/getPublishPayload.d.ts.map +1 -1
  77. package/dist/types/src/helpers/ArweaveClient/queries.d.ts.map +1 -0
  78. package/dist/types/src/helpers/index.d.ts +1 -3
  79. package/dist/types/src/helpers/index.d.ts.map +1 -1
  80. package/dist/types/src/index.d.ts +1 -0
  81. package/dist/types/src/index.d.ts.map +1 -1
  82. package/dist/types/src/interfaces/IItem.d.ts +1 -0
  83. package/dist/types/src/interfaces/IItem.d.ts.map +1 -1
  84. package/dist/types/src/node/db/Db.d.ts +3 -0
  85. package/dist/types/src/node/db/Db.d.ts.map +1 -1
  86. package/dist/types/src/services/db/actors/migrate.d.ts +0 -1
  87. package/dist/types/src/services/db/actors/migrate.d.ts.map +1 -1
  88. package/dist/types/src/types/index.d.ts +0 -31
  89. package/dist/types/src/types/index.d.ts.map +1 -1
  90. package/package.json +7 -14
  91. package/dist/Db-Bu5Y7_fn.js +0 -138
  92. package/dist/Db-Bu5Y7_fn.js.map +0 -1
  93. package/dist/FileManager-EGwM_VHY.js.map +0 -1
  94. package/dist/index-BCmsQoYg.js.map +0 -1
  95. package/dist/index-DzDVTUae.js.map +0 -1
  96. package/dist/seed.schema.config-BswsDyRe.js.map +0 -1
  97. package/dist/src/logger.ts +0 -33
  98. package/dist/types/src/browser/arweave/queries.d.ts.map +0 -1
  99. package/dist/types/src/helpers/logger.d.ts +0 -7
  100. package/dist/types/src/helpers/logger.d.ts.map +0 -1
  101. /package/dist/types/src/{browser/arweave → helpers/ArweaveClient}/queries.d.ts +0 -0
@@ -2,31 +2,27 @@ import { immerable, produce, enableMapSet } from 'immer';
2
2
  import 'reflect-metadata';
3
3
  import { __awaiter, __rest } from 'tslib';
4
4
  import { Type } from '@sinclair/typebox';
5
+ import EventEmitter from 'eventemitter3';
5
6
  import { sql, relations, or, and, isNotNull, not, eq, inArray, like, isNull, getTableColumns, count, max, gt } from 'drizzle-orm';
6
7
  import { useState, useCallback, useEffect, useRef } from 'react';
7
- import 'dayjs';
8
8
  import { customAlphabet } from 'nanoid';
9
9
  import * as nanoIdDictionary from 'nanoid-dictionary';
10
10
  import fs$1, { fs, configureSingle } from '@zenfs/core';
11
11
  import debug from 'debug';
12
12
  import { sqliteTable, text, int, blob, check, unique } from 'drizzle-orm/sqlite-core';
13
- import { b as BaseQueryClient, a as BaseEasClient, I as INTERNAL_DATA_TYPES, G as GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY, e as GLOBAL_INITIALIZING_SEND_CONFIG, f as GLOBAL_INITIALIZING_CREATE_ALL_ITEMS_SERVICES, g as GLOBAL_ADDING_MODELS_TO_DB_SUCCESS, D as DB_CHECK_STATUS_UPDATE_PATHS, h as DB_CHECK_STATUS_EXISTS, i as BROWSER_FS_TOP_DIR, j as DB_CREATING_SUCCESS, k as DB_VALIDATING_SUCCESS, l as DB_VALIDATING_WAIT, m as DB_MIGRATING_SUCCESS, M as MachineIds, n as DB_WAITING_FOR_FILES_RECEIVED, o as DB_MIGRATING_WAIT, p as DbState, q as INTERNAL_VALIDATING_INPUT_SUCCESS, r as ARWEAVE_HOST, B as BaseArweaveClient, s as INTERNAL_CONFIGURING_FS_SUCCESS, t as INTERNAL_SAVING_CONFIG_SUCCESS, u as INTERNAL_LOADING_APP_DB_SUCCESS, v as DB_ON_SNAPSHOT, w as DB_NAME_APP, x as InternalState, P as PublishMachineStates, y as GlobalState, c as BaseFileManager, z as internalPropertyNames, V as VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA, C as defaultAttestationData } from './constants-BjOTXEgm.js';
13
+ import { b as BaseQueryClient, a as BaseEasClient, I as INTERNAL_DATA_TYPES, 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, m as DB_MIGRATING_SUCCESS, M as MachineIds, n as DB_WAITING_FOR_FILES_RECEIVED, o as DB_MIGRATING_WAIT, p as DbState, q as INTERNAL_VALIDATING_INPUT_SUCCESS, r as ARWEAVE_HOST, B as BaseArweaveClient, s as INTERNAL_CONFIGURING_FS_SUCCESS, t as INTERNAL_SAVING_CONFIG_SUCCESS, u as INTERNAL_LOADING_APP_DB_SUCCESS, v as DB_ON_SNAPSHOT, w as DB_NAME_APP, x as InternalState, P as PublishMachineStates, y as GlobalState, c as BaseFileManager, z as internalPropertyNames, V as VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA, C as defaultAttestationData } from './constants-BakHTrB9.js';
14
14
  import { fromCallback, setup, assign, waitFor, createActor, raise } from 'xstate';
15
15
  import pluralize from 'pluralize';
16
- import EventEmitter from 'eventemitter3';
17
16
  import { throttle, camelCase, startCase, orderBy } from 'lodash-es';
18
17
  import { createBrowserInspector } from '@statelyai/inspect';
19
- import { drizzle } from 'drizzle-orm/sqlite-proxy';
20
- import { migrate as migrate$1 } from 'drizzle-orm/sqlite-proxy/migrator';
21
- import { readMigrationFiles } from 'drizzle-orm/migrator';
22
18
  import * as fsNode from 'node:fs';
23
19
  import { WebAccess } from '@zenfs/dom';
24
20
  import path from 'path';
25
21
  import Arweave from 'arweave';
26
- import { useImmer } from 'use-immer';
27
- import { useSelector } from '@xstate/react';
28
22
  import { BehaviorSubject } from 'rxjs';
29
23
  import { ZERO_BYTES32, SchemaEncoder } from '@ethereum-attestation-service/eas-sdk';
24
+ import { useImmer } from 'use-immer';
25
+ import { useSelector } from '@xstate/react';
30
26
 
31
27
  const TPropertyDataType = Type.Union([
32
28
  Type.Literal('Text'),
@@ -134,7 +130,7 @@ const initItem = () => __awaiter(void 0, void 0, void 0, function* () {
134
130
  Item$2 = (yield Promise.resolve().then(function () { return Item$1; })).Item;
135
131
  }
136
132
  if (!isBrowser()) {
137
- Item$2 = (yield import('./Item-BRHX17yq.js')).Item;
133
+ Item$2 = (yield import('./Item-DCdD-972.js')).Item;
138
134
  }
139
135
  });
140
136
 
@@ -184,71 +180,22 @@ const initItemProperty = () => __awaiter(void 0, void 0, void 0, function* () {
184
180
  ItemProperty$2 = (yield Promise.resolve().then(function () { return ItemProperty$1; })).ItemProperty;
185
181
  }
186
182
  if (!isBrowser()) {
187
- ItemProperty$2 = (yield import('./ItemProperty-CZzIP1b8.js')).ItemProperty;
183
+ ItemProperty$2 = (yield import('./ItemProperty-BlE3BrNc.js')).ItemProperty;
188
184
  }
189
185
  });
190
186
 
191
187
  let Db;
192
188
  const initDb = () => __awaiter(void 0, void 0, void 0, function* () {
193
189
  if (isBrowser()) {
194
- Db = (yield import('./Db-Bu5Y7_fn.js')).Db;
190
+ Db = (yield import('./Db-xO-g5pKA.js')).Db;
195
191
  }
196
192
  if (!isBrowser()) {
197
- Db = (yield import('./Db-lX4nNJTb.js')).Db;
193
+ Db = (yield import('./Db-BKm58Z1E.js')).Db;
198
194
  }
199
195
  // TODO: Add config for React Native
200
196
  });
201
197
 
202
- let sqlite3InitModule;
203
- let sqliteWasmClient;
204
- let isPreparing = false;
205
- const getSqliteWasmClient = () => __awaiter(void 0, void 0, void 0, function* () {
206
- if (sqliteWasmClient) {
207
- return sqliteWasmClient;
208
- }
209
- if (typeof window === 'undefined') {
210
- throw new Error('validateInput called from non-browser context');
211
- }
212
- if (isPreparing) {
213
- return;
214
- }
215
- isPreparing = true;
216
- if (!sqlite3InitModule) {
217
- sqlite3InitModule = yield import('@sqlite.org/sqlite-wasm');
218
- }
219
- if (!window.sqlite3Worker1Promiser) {
220
- yield sqlite3InitModule();
221
- }
222
- if (!window.sqlite3Worker1Promiser) {
223
- console.error('window.sqlite3Worker1Promiser not found');
224
- isPreparing = false;
225
- return;
226
- }
227
- try {
228
- sqliteWasmClient = yield window.sqlite3Worker1Promiser.v2().catch((err) => {
229
- console.error('Error initializing sqliteWasmClient:', err);
230
- isPreparing = false;
231
- });
232
- }
233
- catch (err) {
234
- console.error('Error initializing sqliteWasmClient:', err);
235
- isPreparing = false;
236
- }
237
- return sqliteWasmClient;
238
- });
239
- let appDb;
240
- const setAppDb = (db) => {
241
- appDb = db;
242
- };
243
- const getAppDb = () => {
244
- if (!appDb) {
245
- throw new Error('getAppDb: appDb is undefined');
246
- }
247
- return appDb;
248
- };
249
- const isAppDbReady = () => {
250
- return !!appDb;
251
- };
198
+ const eventEmitter = new EventEmitter();
252
199
 
253
200
  const modelStore = new Map();
254
201
  const getModels = () => {
@@ -264,7 +211,7 @@ const setModel = (modelName, model) => {
264
211
  modelStore.set(modelName, model);
265
212
  };
266
213
 
267
- const logger$p = debug('app:shared:helpers');
214
+ const logger$o = debug('app:shared:helpers');
268
215
  const { alphanumeric } = nanoIdDictionary;
269
216
  const generateId = () => {
270
217
  return customAlphabet(alphanumeric, 10)();
@@ -345,7 +292,7 @@ const convertTxIdToImageSrc = (txId) => __awaiter(void 0, void 0, void 0, functi
345
292
  const imageFilePath = `/files/images/${txId}`;
346
293
  const fileExists = yield fs.promises.exists(imageFilePath);
347
294
  if (!fileExists) {
348
- logger$p(`[ItemView] [updateImageSrc] ${imageFilePath} does not exist`);
295
+ logger$o(`[ItemView] [updateImageSrc] ${imageFilePath} does not exist`);
349
296
  return;
350
297
  }
351
298
  const uint = yield fs.promises.readFile(imageFilePath);
@@ -519,6 +466,11 @@ class BaseDb {
519
466
  static connectToDb(pathToDir, dbName) {
520
467
  return this.PlatformClass.connectToDb(pathToDir, dbName);
521
468
  }
469
+ static migrate(pathToDbDir, dbName) {
470
+ return __awaiter(this, void 0, void 0, function* () {
471
+ return this.PlatformClass.migrate(pathToDbDir, dbName);
472
+ });
473
+ }
522
474
  }
523
475
 
524
476
  var AttestationScalarFieldEnum;
@@ -812,7 +764,7 @@ const createMetadata = (metadataValues, propertyRecordSchema) => __awaiter(void
812
764
  if (propertyRecordSchema &&
813
765
  propertyRecordSchema.localStorageDir &&
814
766
  propertyRecordSchema.storageType === 'ItemStorage') {
815
- metadataValues.refResolvedValue = `${metadataValues.seedLocalId}${propertyRecordSchema.filenameSuffix}`;
767
+ metadataValues.refResolvedValue = `${metadataValues.seedUid || metadataValues.seedLocalId}${propertyRecordSchema.filenameSuffix}`;
816
768
  metadataValues.refValueType = 'file';
817
769
  }
818
770
  return appDb
@@ -917,8 +869,6 @@ const initialize$3 = fromCallback(({ sendBack, input: { context } }) => {
917
869
  });
918
870
  });
919
871
 
920
- const eventEmitter = new EventEmitter();
921
-
922
872
  const escapeSqliteString = (value) => {
923
873
  if (typeof value !== 'string') {
924
874
  throw new Error(`Value must be a string, instead got: ${JSON.stringify(value)}`);
@@ -1582,7 +1532,7 @@ const syncDbWithEasHandler = throttle((_) => __awaiter(void 0, void 0, void 0, f
1582
1532
  trailing: false,
1583
1533
  });
1584
1534
 
1585
- const logger$o = debug('app:services:global:actors:initialize');
1535
+ const logger$n = debug('app:services:global:actors:initialize');
1586
1536
  const initialize$2 = fromCallback(({ sendBack, input: { event, context } }) => {
1587
1537
  const { internalService, models, endpoints, arweaveDomain, addresses, } = context;
1588
1538
  if (!internalService) {
@@ -1601,7 +1551,7 @@ const initialize$2 = fromCallback(({ sendBack, input: { event, context } }) => {
1601
1551
  const _initInternal = () => __awaiter(void 0, void 0, void 0, function* () {
1602
1552
  return new Promise((resolve) => {
1603
1553
  internalSubscription = internalService.subscribe((snapshot) => {
1604
- logger$o('[sdk] [internal] snapshot', snapshot);
1554
+ logger$n('[sdk] [internal] snapshot', snapshot);
1605
1555
  if (snapshot.value === 'ready') {
1606
1556
  resolve();
1607
1557
  }
@@ -1643,7 +1593,7 @@ const initialize$2 = fromCallback(({ sendBack, input: { event, context } }) => {
1643
1593
  yield fetchSchemaUids();
1644
1594
  });
1645
1595
  _initFileSystem().then(() => {
1646
- logger$o('[global/actors] File system initialized');
1596
+ logger$n('[global/actors] File system initialized');
1647
1597
  });
1648
1598
  _initInternal()
1649
1599
  .then(() => {
@@ -1653,7 +1603,7 @@ const initialize$2 = fromCallback(({ sendBack, input: { event, context } }) => {
1653
1603
  return _initEas();
1654
1604
  })
1655
1605
  .then(() => {
1656
- logger$o('[global/actors] Internal initialized');
1606
+ logger$n('[global/actors] Internal initialized');
1657
1607
  sendBack({ type: GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY });
1658
1608
  internalSubscription === null || internalSubscription === void 0 ? void 0 : internalSubscription.unsubscribe();
1659
1609
  });
@@ -1666,7 +1616,7 @@ const initialize$2 = fromCallback(({ sendBack, input: { event, context } }) => {
1666
1616
  };
1667
1617
  });
1668
1618
 
1669
- const logger$n = debug('app:services:global:actors:getSchemaForModel');
1619
+ const logger$m = debug('app:services:global:actors:getSchemaForModel');
1670
1620
  const getSchemaForModel = fromCallback(({ sendBack, input: { context, event } }) => {
1671
1621
  const { modelName } = event;
1672
1622
  if (!modelName) {
@@ -1682,12 +1632,12 @@ const getSchemaForModel = fromCallback(({ sendBack, input: { context, event } })
1682
1632
  if (!model) {
1683
1633
  throw new Error(`Model ${modelName} not found`);
1684
1634
  }
1685
- logger$n('[service/actor] [getSchemaForModel] model:', model);
1635
+ logger$m('[service/actor] [getSchemaForModel] model:', model);
1686
1636
  sendBack({ type: 'schemaForModel', schema: model.schema });
1687
1637
  return () => { };
1688
1638
  });
1689
1639
 
1690
- const logger$m = debug('app:services:global:actors:addModelsToDb');
1640
+ const logger$l = debug('app:services:global:actors:addModelsToDb');
1691
1641
  const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
1692
1642
  const { models: models$1 } = context;
1693
1643
  const _addModelsToDb = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -1696,12 +1646,12 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
1696
1646
  if (!models$1) {
1697
1647
  return;
1698
1648
  }
1699
- const { models: SeedModels } = yield import('./seed.schema.config-BswsDyRe.js');
1649
+ const { models: SeedModels } = yield import('./seed.schema.config-DQalKJ_d.js');
1700
1650
  const allModels = Object.assign(Object.assign({}, SeedModels), models$1);
1701
1651
  let hasModelsInDb = false;
1702
1652
  const schemaDefsByModelName = new Map();
1703
1653
  for (const [modelName, _] of Object.entries(allModels)) {
1704
- logger$m('[helpers/db] [addModelsToInternalDb] starting modelName:', modelName);
1654
+ logger$l('[helpers/db] [addModelsToInternalDb] starting modelName:', modelName);
1705
1655
  let foundModel;
1706
1656
  const foundModelsQuery = yield appDb
1707
1657
  .select()
@@ -1711,7 +1661,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
1711
1661
  yield appDb.insert(models).values({
1712
1662
  name: modelName,
1713
1663
  });
1714
- logger$m('[global/actors] [addModelsToDb] inserted model:', modelName);
1664
+ logger$l('[global/actors] [addModelsToDb] inserted model:', modelName);
1715
1665
  const foundModels = yield appDb
1716
1666
  .select({
1717
1667
  id: models.id,
@@ -1783,10 +1733,10 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
1783
1733
  return () => { };
1784
1734
  });
1785
1735
 
1786
- const logger$l = debug('app:services:db:actors:checkStatus');
1736
+ const logger$k = debug('app:services:db:actors:checkStatus');
1787
1737
  const checkStatus = fromCallback(({ sendBack, input: { context } }) => {
1788
1738
  const { dbName } = context;
1789
- logger$l('[db/actors] checkStatus context', context);
1739
+ logger$k('[db/actors] checkStatus context', context);
1790
1740
  const pathToDir = `${BROWSER_FS_TOP_DIR}`;
1791
1741
  const pathToDbDir = `${pathToDir}/db`;
1792
1742
  const pathToDb = `${pathToDbDir}/${dbName}.sqlite3`;
@@ -1817,9 +1767,9 @@ const checkStatus = fromCallback(({ sendBack, input: { context } }) => {
1817
1767
  });
1818
1768
  });
1819
1769
 
1820
- const logger$k = debug('app:services:db:actors:connectToDb');
1770
+ const logger$j = debug('app:services:db:actors:connectToDb');
1821
1771
  const connectToDb = fromCallback(({ sendBack, input: { context } }) => {
1822
- logger$k('[db/actors] connectToDb context', context);
1772
+ logger$j('[db/actors] connectToDb context', context);
1823
1773
  const { dbName, pathToDir } = context;
1824
1774
  if (!pathToDir || !dbName) {
1825
1775
  throw new Error('pathToDir and dbName are required');
@@ -1913,74 +1863,10 @@ const waitForFile = (filePath, interval = 500, timeout = 10000) => {
1913
1863
  });
1914
1864
  };
1915
1865
 
1916
- const logger$j = debug('app:services:db:actors:migrate');
1917
- const dbExec = (dbId_1, params_1, sql_1, dbName_1, ...args_1) => __awaiter(void 0, [dbId_1, params_1, sql_1, dbName_1, ...args_1], void 0, function* (dbId, params, sql, dbName, retries = 2) {
1918
- const rowsToReturnRaw = [];
1919
- const sqliteWasmClient = yield getSqliteWasmClient();
1920
- // For a single exec command, the callback potentially gets called several times -- once for each row.
1921
- // So we need to collect all rows into a final array to return (execResult).
1922
- const rowsToReturn = yield new Promise((resolve, reject) => {
1923
- sqliteWasmClient('exec', {
1924
- dbId,
1925
- sql,
1926
- bind: params,
1927
- callback: (result) => {
1928
- // Checks if this is the final callback of the query
1929
- if (!result || !result.row || !result.rowNumber) {
1930
- const returnResult = [];
1931
- // Before returning the array, we process it to match the expected output format
1932
- // const rowsToReturnProcessed = rowsToReturnRaw.reduce((acc, curr) => {
1933
- // if (
1934
- // Array.isArray(curr.row) &&
1935
- // curr.row?.length > 0 &&
1936
- // curr.columnNames.length > 0
1937
- // ) {
1938
- // const returnObj: ReturnObj = {
1939
- // database: dbName,
1940
- // }
1941
- //
1942
- // const values = []
1943
- //
1944
- // curr.columnNames.forEach((colName, index: number) => {
1945
- // if (curr.row && curr.row[index]) {
1946
- // returnObj[colName] = curr.row[index]
1947
- // values.push(curr.row[index])
1948
- // }
1949
- // })
1950
- // // rowsValueStrings.push(`(${values.join(', ')})`)
1951
- // acc.push(returnObj)
1952
- // }
1953
- // return acc
1954
- // }, [] as string[])
1955
- for (const currRow of rowsToReturnRaw) {
1956
- // const values: string[] = []
1957
- // currRow.columnNames.forEach((colName, index: number) => {
1958
- // if (currRow.row) {
1959
- // values.push(currRow.row[index])
1960
- // }
1961
- // })
1962
- // logger(`[db/actors] [dbExec] currRow`, currRow)
1963
- returnResult.push(currRow.row);
1964
- }
1965
- resolve(returnResult);
1966
- }
1967
- else {
1968
- // If not the final response, add this row to the return array
1969
- rowsToReturnRaw.push(result);
1970
- }
1971
- },
1972
- }).catch((error) => __awaiter(void 0, void 0, void 0, function* () {
1973
- reject(error);
1974
- }));
1975
- });
1976
- // logger(`[db/actors] [dbExec] rowsToReturn`, rowsToReturn)
1977
- // logger(`[db/actors] [dbExec] rowsValues`, rowsValues)
1978
- return rowsToReturn || [];
1979
- });
1866
+ const logger$i = debug('app:services:db:actors:migrate');
1980
1867
  const migrate = fromCallback(({ sendBack, input: { context } }) => {
1981
1868
  const { pathToDbDir, dbId, dbName } = context;
1982
- logger$j('[db/actors] migrate context', context);
1983
- const schemaGlobString = `${BROWSER_FS_TOP_DIR}/schema/*`;
1869
+ logger$i('[db/actors] migrate context', context);
1984
1870
  let journalExists = false;
1985
1871
  // const _initFs = async (): Promise<void> => {
1986
1872
  // const handle = await navigator.storage.getDirectory()
@@ -1994,13 +1880,7 @@ const migrate = fromCallback(({ sendBack, input: { context } }) => {
1994
1880
  // _initFs()
1995
1881
  const _checkForFiles = () => __awaiter(void 0, void 0, void 0, function* () {
1996
1882
  const journalPath = `/${pathToDbDir}/meta/_journal.json`;
1997
- journalExists = yield fs.promises.exists(journalPath);
1998
- const journalExistsAsync = journalExists;
1999
- const journalExistsSync = fs.existsSync(journalPath);
2000
- const journalExistsSyncNode = fsNode.existsSync(journalPath);
2001
- console.log('journalExistsAsync', journalExistsAsync);
2002
- console.log('journalExistsSync', journalExistsSync);
2003
- console.log('journalExistsSyncNode', journalExistsSyncNode);
1883
+ journalExists = yield fs$1.promises.exists(journalPath);
2004
1884
  if (!journalExists) {
2005
1885
  yield waitForFile(journalPath);
2006
1886
  // const handle = await navigator.storage.getDirectory()
@@ -2018,137 +1898,7 @@ const migrate = fromCallback(({ sendBack, input: { context } }) => {
2018
1898
  }
2019
1899
  });
2020
1900
  const _migrate = () => __awaiter(void 0, void 0, void 0, function* () {
2021
- const drizzleDb = drizzle((sql, params, method) => __awaiter(void 0, void 0, void 0, function* () {
2022
- try {
2023
- // logger(
2024
- // `executing sql on ${dbName} with id: ${dbId} and method: ${method}`,
2025
- // sql,
2026
- // )
2027
- const finalResult = yield dbExec(dbId, params, sql, dbName);
2028
- // logger(`finalResult with method: ${method}`, finalResult)
2029
- // Drizzle always waits for {rows: string[][]} or {rows: string[]} for the return value.
2030
- // When the method is get, you should return a value as {rows: string[]}.
2031
- // Otherwise, you should return {rows: string[][]}.
2032
- return { rows: finalResult };
2033
- }
2034
- catch (e) {
2035
- console.error('Error from sqlite proxy server: ', JSON.stringify(e));
2036
- return { rows: [] };
2037
- }
2038
- }), {
2039
- schema: schemaGlobString,
2040
- // logger: true,
2041
- });
2042
- try {
2043
- const migrations = readMigrationFiles({
2044
- migrationsFolder: pathToDbDir,
2045
- });
2046
- if (migrations.length > 0) {
2047
- const incomingMigrationHashes = migrations.map((migration) => migration.hash);
2048
- let existingMigrationHashes;
2049
- let rows = [];
2050
- try {
2051
- const query = yield drizzleDb.run(sql.raw(`SELECT hash, created_at
2052
- FROM main.__drizzle_migrations;`));
2053
- rows = query.rows;
2054
- }
2055
- catch (e) {
2056
- rows = [];
2057
- }
2058
- if (rows && rows.length > 0) {
2059
- existingMigrationHashes = rows.map((row) => row[0]);
2060
- }
2061
- if (existingMigrationHashes) {
2062
- let shouldRebuildDb = false;
2063
- for (const existingHash of existingMigrationHashes) {
2064
- if (!incomingMigrationHashes.includes(existingHash)) {
2065
- shouldRebuildDb = true;
2066
- break;
2067
- }
2068
- }
2069
- if (shouldRebuildDb) {
2070
- yield fs.promises.unlink(`${pathToDbDir}/${dbName}.sqlite3`);
2071
- }
2072
- }
2073
- }
2074
- yield migrate$1(drizzleDb, (queriesToRun) => __awaiter(void 0, void 0, void 0, function* () {
2075
- // logger('queriesToRun', queriesToRun)
2076
- for (const query of queriesToRun) {
2077
- // logger('query', query)
2078
- yield drizzleDb.run(sql.raw(query));
2079
- }
2080
- }), {
2081
- migrationsFolder: pathToDbDir,
2082
- });
2083
- }
2084
- catch (error) {
2085
- // console.error('Error migrating database: ', error)
2086
- // window.location.reload()
2087
- // const handle = await navigator.storage.getDirectory()
2088
- //
2089
- // await configureSingle({
2090
- // backend: WebAccess,
2091
- // handle,
2092
- // })
2093
- yield waitForFile(`${pathToDbDir}/meta/_journal.json`);
2094
- return _migrate();
2095
- }
2096
- setAppDb(drizzleDb);
2097
- // const createTempTableQuery = await appDb.run(
2098
- // sql.raw(
2099
- // `CREATE TEMP TABLE IF NOT EXISTS temp_last_inserted_id (id INTEGER, table TEXT);`,
2100
- // ),
2101
- // )
2102
- //
2103
- // logger(
2104
- // '[db/actors] [migrate] createTempTableQuery',
2105
- // createTempTableQuery,
2106
- // )
2107
- // const triggersQuery = await appDb.run(
2108
- // sql.raw(
2109
- // `SELECT name
2110
- // FROM main.sqlite_master
2111
- // WHERE type = 'trigger';`,
2112
- // ),
2113
- // )
2114
- //
2115
- // logger('[db/actors] [migrate] triggersQuery', triggersQuery)
2116
- //
2117
- // const triggers = triggersQuery.rows.map((row) => row[0])
2118
- //
2119
- // const tablesQuery = await appDb.run(
2120
- // sql.raw(
2121
- // `SELECT name
2122
- // FROM main.sqlite_master
2123
- // WHERE type = 'table';`,
2124
- // ),
2125
- // )
2126
- //
2127
- // logger('[db/actors] [migrate] tablesQuery', tablesQuery)
2128
- //
2129
- // const tableNames = tablesQuery.rows.map((row) => row[0])
2130
- // logger('[db/actors] [migrate] tableNames', tableNames)
2131
- // for (const tableName of tableNames) {
2132
- // const triggerName = `after_insert_${tableName}`
2133
- // if (triggers.includes(triggerName)) {
2134
- // continue
2135
- // }
2136
- // const createTriggerQuery = await appDb.run(
2137
- // sql.raw(
2138
- // `CREATE TRIGGER after_insert_${tableName}
2139
- // AFTER INSERT ON ${tableName}
2140
- // BEGIN
2141
- // DELETE FROM temp_last_inserted_id;
2142
- // INSERT INTO temp_last_inserted_id (id) VALUES (new.id);
2143
- // END;`,
2144
- // ),
2145
- // )
2146
- //
2147
- // logger(
2148
- // '[db/actors] [migrate] createTriggerQuery',
2149
- // createTriggerQuery,
2150
- // )
2151
- // }
1901
+ yield BaseDb.migrate(pathToDbDir, dbName);
2152
1902
  });
2153
1903
  _checkForFiles()
2154
1904
  .then(() => {
@@ -2162,7 +1912,7 @@ const migrate = fromCallback(({ sendBack, input: { context } }) => {
2162
1912
  return () => { };
2163
1913
  });
2164
1914
 
2165
- const logger$i = debug('app:services:db:machine');
1915
+ const logger$h = debug('app:services:db:machine');
2166
1916
  const { CHECKING_STATUS, VALIDATING, WAITING_FOR_FILES, CONNECTING_TO_DB, MIGRATING, } = DbState;
2167
1917
  const dbMachine = setup({
2168
1918
  types: {
@@ -2183,7 +1933,7 @@ const dbMachine = setup({
2183
1933
  [DB_WAITING_FOR_FILES_RECEIVED]: {
2184
1934
  actions: assign({
2185
1935
  hasFiles: ({ event }) => {
2186
- logger$i('[db/machine] DB_WAITING_FOR_FILES_RECEIVED event:', event);
1936
+ logger$h('[db/machine] DB_WAITING_FOR_FILES_RECEIVED event:', event);
2187
1937
  return true;
2188
1938
  },
2189
1939
  }),
@@ -2192,8 +1942,8 @@ const dbMachine = setup({
2192
1942
  target: `.${CHECKING_STATUS}`,
2193
1943
  actions: assign({
2194
1944
  hasFiles: ({ context, event }) => {
2195
- logger$i('[db/machine] updateHasFiles event:', event);
2196
- logger$i('[db/machine] updateHasFiles context:', context);
1945
+ logger$h('[db/machine] updateHasFiles event:', event);
1946
+ logger$h('[db/machine] updateHasFiles context:', context);
2197
1947
  return event.hasFiles;
2198
1948
  },
2199
1949
  }),
@@ -2356,7 +2106,7 @@ const prepareDb = fromCallback(({ sendBack, input: { context } }) => {
2356
2106
  });
2357
2107
  });
2358
2108
 
2359
- const logger$h = debug('app:services:internal:helpers');
2109
+ const logger$g = debug('app:services:internal:helpers');
2360
2110
  /**
2361
2111
  * Recursively create directories if they don't exist.
2362
2112
  * @param {string} dirPath - The directory path to create.
@@ -2432,7 +2182,7 @@ const downloadFile = (url, localFilePath) => __awaiter(void 0, void 0, void 0, f
2432
2182
  if (JSON.stringify(error).includes('File exists')) {
2433
2183
  yield fs.promises.readFile(localFilePath, 'utf-8');
2434
2184
  }
2435
- logger$h(`[Error] Failed to download file from ${url}:`, error);
2185
+ logger$g(`[Error] Failed to download file from ${url}:`, error);
2436
2186
  }
2437
2187
  busy = false;
2438
2188
  });
@@ -2472,7 +2222,7 @@ const syncDbFiles = (_a) => __awaiter(void 0, [_a], void 0, function* ({ filePat
2472
2222
  fileList = fileList.filter((file) => !filesToExclude.includes(file));
2473
2223
  yield fetchFilesRecursively(files, BROWSER_FS_TOP_DIR, fileList);
2474
2224
  yield confirmFilesExist(fileList);
2475
- logger$h('[syncDbFiles] Files synced!');
2225
+ logger$g('[syncDbFiles] Files synced!');
2476
2226
  });
2477
2227
 
2478
2228
  const GET_FILES_METADATA = graphql(/* GraphQL */ `
@@ -2578,10 +2328,10 @@ const saveAppState = (key, value) => __awaiter(void 0, void 0, void 0, function*
2578
2328
 
2579
2329
  const initArweaveClient = () => __awaiter(void 0, void 0, void 0, function* () {
2580
2330
  if (isBrowser()) {
2581
- (yield import('./ArweaveClient-rTTCUjiu.js')).ArweaveClient;
2331
+ (yield import('./ArweaveClient-BXD_aTsx.js')).ArweaveClient;
2582
2332
  }
2583
2333
  if (!isBrowser()) {
2584
- (yield import('./ArweaveClient-C-HZgUWJ.js')).ArweaveClient;
2334
+ (yield import('./ArweaveClient-CkcZD_QE.js')).ArweaveClient;
2585
2335
  }
2586
2336
  });
2587
2337
  let domain = 'arweave.net';
@@ -2624,7 +2374,7 @@ const setArweaveDomain = (newDomain) => {
2624
2374
  domain = newDomain;
2625
2375
  };
2626
2376
 
2627
- const logger$g = debug('app:files:download');
2377
+ const logger$f = debug('app:files:download');
2628
2378
  const downloadAllFilesRequestHandler = (_a) => __awaiter(void 0, [_a], void 0, function* ({ endpoints, eventId, }) {
2629
2379
  yield syncDbFiles(endpoints);
2630
2380
  eventEmitter.emit('fs.downloadAll.success', { eventId });
@@ -2710,7 +2460,7 @@ const downloadAllFilesBinaryRequestHandler = () => __awaiter(void 0, void 0, voi
2710
2460
  try {
2711
2461
  const res = yield fetch(`https://${ARWEAVE_HOST}/tx/${transactionId}/status`);
2712
2462
  if (res.status !== 200) {
2713
- logger$g(`[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`);
2463
+ logger$f(`[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`);
2714
2464
  excludedTransactions.add(transactionId);
2715
2465
  yield saveAppState('excludedTransactions', JSON.stringify(Array.from(excludedTransactions)));
2716
2466
  continue;
@@ -2765,7 +2515,7 @@ const downloadAllFilesBinaryRequestHandler = () => __awaiter(void 0, void 0, voi
2765
2515
  // string: true,
2766
2516
  // })
2767
2517
  if (!dataString && !arrayBuffer) {
2768
- logger$g(`[fetchAll/actors] [fetchAllBinaryData] transaction ${transactionId} data not found`);
2518
+ logger$f(`[fetchAll/actors] [fetchAllBinaryData] transaction ${transactionId} data not found`);
2769
2519
  }
2770
2520
  if (dataString && dataString.startsWith('===FILE_SEPARATOR===')) {
2771
2521
  const dataStringParts = dataString
@@ -2801,7 +2551,7 @@ const downloadAllFilesBinaryRequestHandler = () => __awaiter(void 0, void 0, voi
2801
2551
  contentType !== 'html') {
2802
2552
  const possibleImageType = getDataTypeFromString(dataString);
2803
2553
  if (!possibleImageType) {
2804
- logger$g(`[fetchAll/actors] [fetchAllBinaryData] transaction ${transactionId} data not in expected format: ${possibleImageType}`);
2554
+ logger$f(`[fetchAll/actors] [fetchAllBinaryData] transaction ${transactionId} data not in expected format: ${possibleImageType}`);
2805
2555
  continue;
2806
2556
  }
2807
2557
  contentType = possibleImageType;
@@ -2868,7 +2618,7 @@ const downloadAllFilesBinaryRequestHandler = () => __awaiter(void 0, void 0, voi
2868
2618
  }
2869
2619
  }
2870
2620
  catch (error) {
2871
- logger$g(error);
2621
+ logger$f(error);
2872
2622
  }
2873
2623
  }
2874
2624
  });
@@ -2914,14 +2664,14 @@ const isFsInitialized = () => {
2914
2664
  return isInitialized;
2915
2665
  };
2916
2666
 
2917
- const logger$f = debug('app:internal:actors:configureFs');
2667
+ const logger$e = debug('app:internal:actors:configureFs');
2918
2668
  const configureFs = fromCallback(({ sendBack, input: { context } }) => {
2919
2669
  const { endpoints, appDbService, filesDir, } = context;
2920
- logger$f('[internal/actors] [configureFs] Configuring FS');
2670
+ logger$e('[internal/actors] [configureFs] Configuring FS');
2921
2671
  const _configureFs = () => __awaiter(void 0, void 0, void 0, function* () {
2922
- logger$f('[internal/actors] [configureFs] calling _configureFs');
2923
- logger$f('[internal/actors] [configureFs] areFsListenersReady:', areFsListenersReady());
2924
- logger$f('[internal/actors] [configureFs] isFsInitialized:', isFsInitialized());
2672
+ logger$e('[internal/actors] [configureFs] calling _configureFs');
2673
+ logger$e('[internal/actors] [configureFs] areFsListenersReady:', areFsListenersReady());
2674
+ logger$e('[internal/actors] [configureFs] isFsInitialized:', isFsInitialized());
2925
2675
  yield waitForEvent({
2926
2676
  req: {
2927
2677
  eventLabel: 'fs.downloadAll.request',
@@ -2950,7 +2700,7 @@ const configureFs = fromCallback(({ sendBack, input: { context } }) => {
2950
2700
  // }
2951
2701
  // }, 200)
2952
2702
  // })
2953
- logger$f('[internal/actors] [configureFs] fs configured!');
2703
+ logger$e('[internal/actors] [configureFs] fs configured!');
2954
2704
  });
2955
2705
  // Some of our dependencies use fs sync functions, which don't work with
2956
2706
  // OPFS. ZenFS creates an async cache of all files so that the sync functions
@@ -2963,7 +2713,7 @@ const configureFs = fromCallback(({ sendBack, input: { context } }) => {
2963
2713
  return () => { };
2964
2714
  });
2965
2715
 
2966
- const logger$e = debug('app:services:internal:actors:saveConfig');
2716
+ const logger$d = debug('app:services:internal:actors:saveConfig');
2967
2717
  const saveConfig = fromCallback(({ sendBack, input: { context } }) => {
2968
2718
  if (typeof window === 'undefined') {
2969
2719
  console.error('seedInitBrowser called from non-browser context');
@@ -3024,20 +2774,20 @@ const saveConfig = fromCallback(({ sendBack, input: { context } }) => {
3024
2774
  value: arweaveDomain || 'arweave.net',
3025
2775
  },
3026
2776
  });
3027
- logger$e('[sdk] [internal/actors] Should be done saving');
2777
+ logger$d('[sdk] [internal/actors] Should be done saving');
3028
2778
  }
3029
2779
  catch (error) {
3030
2780
  console.error('Error saving config:', error);
3031
2781
  }
3032
2782
  });
3033
2783
  _saveConfig().then(() => {
3034
- logger$e('[sdk] [internal/actors] Successfully saved config');
2784
+ logger$d('[sdk] [internal/actors] Successfully saved config');
3035
2785
  return sendBack({ type: INTERNAL_SAVING_CONFIG_SUCCESS });
3036
2786
  });
3037
2787
  return () => { };
3038
2788
  });
3039
2789
 
3040
- const logger$d = debug('app:services:internal:actors:loadAppDb');
2790
+ const logger$c = debug('app:services:internal:actors:loadAppDb');
3041
2791
  const loadAppDb = fromCallback(({ sendBack, input: { context } }) => {
3042
2792
  const { appDbService } = context;
3043
2793
  let subscription;
@@ -3058,7 +2808,7 @@ const loadAppDb = fromCallback(({ sendBack, input: { context } }) => {
3058
2808
  });
3059
2809
  _loadAppDb().then(() => {
3060
2810
  sendBack({ type: INTERNAL_LOADING_APP_DB_SUCCESS });
3061
- logger$d('[sdk] [internal/actors] Successfully loaded app DB');
2811
+ logger$c('[sdk] [internal/actors] Successfully loaded app DB');
3062
2812
  });
3063
2813
  return () => {
3064
2814
  if (subscription) {
@@ -3067,7 +2817,7 @@ const loadAppDb = fromCallback(({ sendBack, input: { context } }) => {
3067
2817
  };
3068
2818
  });
3069
2819
 
3070
- const logger$c = debug('app:services:internal:machine');
2820
+ const logger$b = debug('app:services:internal:machine');
3071
2821
  createBrowserInspector({
3072
2822
  autoStart: false,
3073
2823
  });
@@ -3168,7 +2918,7 @@ const internalMachine = setup({
3168
2918
  [INTERNAL_LOADING_APP_DB_SUCCESS]: {
3169
2919
  target: SAVING_CONFIG,
3170
2920
  actions: () => {
3171
- logger$c('[sdk] [internal/index] App DB loaded!');
2921
+ logger$b('[sdk] [internal/index] App DB loaded!');
3172
2922
  },
3173
2923
  },
3174
2924
  },
@@ -3194,7 +2944,7 @@ const internalMachine = setup({
3194
2944
  },
3195
2945
  ready: {
3196
2946
  entry: () => {
3197
- logger$c('[sdk] [internal/index] Ready!');
2947
+ logger$b('[sdk] [internal/index] Ready!');
3198
2948
  },
3199
2949
  meta: {
3200
2950
  displayText: "Crossing the t's ...",
@@ -3209,7 +2959,7 @@ const internalMachine = setup({
3209
2959
  },
3210
2960
  },
3211
2961
  entry: () => {
3212
- logger$c('[sdk] [internal/index] Error!');
2962
+ logger$b('[sdk] [internal/index] Error!');
3213
2963
  },
3214
2964
  meta: {
3215
2965
  displayText: 'Whoops! Something went wrong.',
@@ -3447,7 +3197,7 @@ const fetchDbData = fromCallback(({ sendBack, input: { context } }) => {
3447
3197
  return () => { };
3448
3198
  });
3449
3199
 
3450
- const logger$b = debug('app:allItemsActors:fetchSeeds');
3200
+ const logger$a = debug('app:allItemsActors:fetchSeeds');
3451
3201
  const fetchSeeds = fromCallback(({ sendBack, input: { context } }) => {
3452
3202
  const { queryVariables, modelName } = context;
3453
3203
  if (!queryVariables) {
@@ -3459,7 +3209,7 @@ const fetchSeeds = fromCallback(({ sendBack, input: { context } }) => {
3459
3209
  const queryClient = BaseQueryClient.getQueryClient();
3460
3210
  const easClient = BaseEasClient.getEasClient();
3461
3211
  const cachedResults = queryClient.getQueryData(queryKey);
3462
- logger$b(`[allItemsActors] [fetchSeeds] cachedResults ${Date.now()}`, cachedResults);
3212
+ logger$a(`[allItemsActors] [fetchSeeds] cachedResults ${Date.now()}`, cachedResults);
3463
3213
  const results = yield queryClient.fetchQuery({
3464
3214
  queryKey,
3465
3215
  queryFn: () => __awaiter(void 0, void 0, void 0, function* () { return easClient.request(GET_SEEDS, queryVariables); }),
@@ -3858,7 +3608,7 @@ const updateMachineContext = {
3858
3608
  const preparePublishRequestData = fromCallback(({ sendBack, input: { context } }) => {
3859
3609
  const { localId } = context;
3860
3610
  const _preparePublishRequestData = () => __awaiter(void 0, void 0, void 0, function* () {
3861
- const item = yield Item.find({ seedLocalId: localId });
3611
+ const item = yield BaseItem.find({ seedLocalId: localId });
3862
3612
  if (!item) {
3863
3613
  return false;
3864
3614
  }
@@ -3908,13 +3658,13 @@ const preparePublishRequestData = fromCallback(({ sendBack, input: { context } }
3908
3658
  });
3909
3659
  });
3910
3660
 
3911
- const logger$a = debug('app:services:publish:actors:upload');
3661
+ const logger$9 = debug('app:services:publish:actors:upload');
3912
3662
  const upload = fromCallback(({ sendBack, input: { context } }) => {
3913
3663
  const { localId } = context;
3914
3664
  const _upload = () => __awaiter(void 0, void 0, void 0, function* () {
3915
- const item = yield Item.find({ seedLocalId: localId });
3665
+ const item = yield BaseItem.find({ seedLocalId: localId });
3916
3666
  if (!item) {
3917
- logger$a('no item with localId', localId);
3667
+ logger$9('no item with localId', localId);
3918
3668
  return false;
3919
3669
  }
3920
3670
  const editedProperties = yield item.getEditedProperties();
@@ -4767,7 +4517,7 @@ const getSeedData = (_a) => __awaiter(void 0, [_a], void 0, function* ({ seedLoc
4767
4517
  return rows[0];
4768
4518
  });
4769
4519
 
4770
- const logger$9 = debug('app:db:read:getItemData');
4520
+ const logger$8 = debug('app:db:read:getItemData');
4771
4521
  const getItemData = (_a) => __awaiter(void 0, [_a], void 0, function* ({ modelName, seedLocalId, seedUid, }) {
4772
4522
  if (!seedLocalId && !seedUid) {
4773
4523
  throw new Error('[db/queries] [getItem] no seedLocalId or seedUid');
@@ -4775,7 +4525,7 @@ const getItemData = (_a) => __awaiter(void 0, [_a], void 0, function* ({ modelNa
4775
4525
  if (seedUid && !seedLocalId) {
4776
4526
  const seedData = yield getSeedData({ seedUid });
4777
4527
  if (!seedData) {
4778
- logger$9('[db/queries] [getItem] no seedData seedUid', seedUid);
4528
+ logger$8('[db/queries] [getItem] no seedData seedUid', seedUid);
4779
4529
  return;
4780
4530
  }
4781
4531
  seedLocalId = seedData.localId;
@@ -4802,7 +4552,7 @@ const getItemData = (_a) => __awaiter(void 0, [_a], void 0, function* ({ modelNa
4802
4552
  .orderBy(sql.raw('COALESCE(attestation_created_at, created_at) DESC'))
4803
4553
  .groupBy(seeds.localId);
4804
4554
  if (!itemDataRows || itemDataRows.length === 0) {
4805
- logger$9('[db/queries] [getItemDataFromDb] no itemDataRows');
4555
+ logger$8('[db/queries] [getItemDataFromDb] no itemDataRows');
4806
4556
  return;
4807
4557
  }
4808
4558
  let itemData = itemDataRows[0];
@@ -5030,7 +4780,7 @@ const getRelationValueData = (propertyValue) => __awaiter(void 0, void 0, void 0
5030
4780
  return rows[0];
5031
4781
  });
5032
4782
 
5033
- const logger$8 = debug('app:property:actors:resolveRelatedValue');
4783
+ const logger$7 = debug('app:property:actors:resolveRelatedValue');
5034
4784
  const storageTransactionIdToContentUrl = new Map();
5035
4785
  const refResolvedValueToContentUrl = new Map();
5036
4786
  const seedUidToContentUrl = new Map();
@@ -5045,7 +4795,7 @@ const resolveRelatedValue = fromCallback(({ sendBack, input: { context } }) => {
5045
4795
  parsedValue = JSON.parse(propertyValue);
5046
4796
  }
5047
4797
  catch (error) {
5048
- logger$8(`${propertyName} value is not a JSON string.`);
4798
+ logger$7(`${propertyName} value is not a JSON string.`);
5049
4799
  }
5050
4800
  if (!parsedValue && seedUidToContentUrl.has(propertyValue)) {
5051
4801
  const contentUrl = seedUidToContentUrl.get(propertyValue);
@@ -5061,11 +4811,11 @@ const resolveRelatedValue = fromCallback(({ sendBack, input: { context } }) => {
5061
4811
  }
5062
4812
  if (Array.isArray(propertyValue)) {
5063
4813
  // TODO: Handle array of seedUids
5064
- logger$8(`${propertyName} value is an array of seedUids`);
4814
+ logger$7(`${propertyName} value is an array of seedUids`);
5065
4815
  return;
5066
4816
  }
5067
4817
  if (Array.isArray(parsedValue)) {
5068
- logger$8(`${propertyName} value is a stringified array of seedUids`);
4818
+ logger$7(`${propertyName} value is a stringified array of seedUids`);
5069
4819
  return;
5070
4820
  }
5071
4821
  const storageTransactionId = yield getStorageTransactionIdForSeedUid(propertyValue);
@@ -5349,9 +5099,9 @@ const updateMetadata = (metadataValues) => __awaiter(void 0, void 0, void 0, fun
5349
5099
  yield appDb.update(metadata).set(rest).where(eq(metadata.localId, localId));
5350
5100
  });
5351
5101
 
5352
- const logger$7 = debug('app:property:actors:hydrateFromDb');
5102
+ debug('app:property:actors:hydrateFromDb');
5353
5103
  const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
5354
- const { seedUid, seedLocalId, propertyName: propertyNameRaw, propertyValue, propertyRecordSchema, modelName, } = context;
5104
+ const { seedUid, seedLocalId, propertyName: propertyNameRaw, propertyRecordSchema, modelName, } = context;
5355
5105
  let propertyName = propertyNameRaw;
5356
5106
  if (propertyRecordSchema &&
5357
5107
  propertyRecordSchema.ref &&
@@ -5407,25 +5157,6 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
5407
5157
  const { localId, uid, propertyName: propertyNameFromDb, propertyValue: propertyValueFromDb, seedLocalId: seedLocalIdFromDb, seedUid: seedUidFromDb, schemaUid: schemaUidFromDb, versionLocalId: versionLocalIdFromDb, versionUid: versionUidFromDb, refValueType, localStorageDir, } = firstRow;
5408
5158
  let { refResolvedDisplayValue, refResolvedValue } = firstRow;
5409
5159
  let propertyValueProcessed = propertyValueFromDb;
5410
- if (propertyName && !propertyNameFromDb) {
5411
- logger$7(`Property name from code is ${propertyName} but has not value in db ${propertyNameFromDb} for Property.${localId}`);
5412
- }
5413
- if (propertyName &&
5414
- propertyNameFromDb &&
5415
- !propertyNameFromDb.includes(propertyName) &&
5416
- !propertyName.includes(propertyNameFromDb) &&
5417
- propertyNameFromDb !== propertyName) {
5418
- logger$7(`Property name from db ${propertyNameFromDb} does not match property name ${propertyName} for Property.${localId}`);
5419
- }
5420
- if (propertyValue && propertyValueFromDb !== propertyValue) {
5421
- logger$7(`Property value from db ${propertyValueFromDb} does not match property value ${propertyValue} for Property.${localId}`);
5422
- }
5423
- if (seedLocalIdFromDb !== seedLocalId) {
5424
- logger$7(`Seed local id from db ${seedLocalIdFromDb} does not match seed local id ${seedLocalId} for Property.${localId}`);
5425
- }
5426
- if (seedUidFromDb !== seedUid) {
5427
- logger$7(`Seed uid from db ${seedUidFromDb} does not match seed uid ${seedUid} for Property.${localId}`);
5428
- }
5429
5160
  if (propertyRecordSchema &&
5430
5161
  propertyRecordSchema.refValueType === 'ImageSrc') {
5431
5162
  let shouldReadFromFile = true;
@@ -5456,6 +5187,8 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
5456
5187
  if (!refResolvedValue &&
5457
5188
  propertyValueFromDb &&
5458
5189
  propertyValueFromDb.length === 66) {
5190
+ // Here the storageTransactionId is stored on a different record and
5191
+ // we want to add it as the refResolvedValue
5459
5192
  const storageTransactionQuery = yield appDb
5460
5193
  .select({
5461
5194
  propertyValue: metadata.propertyValue,
@@ -5522,7 +5255,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
5522
5255
  if (propertyRecordSchema &&
5523
5256
  propertyRecordSchema.storageType &&
5524
5257
  propertyRecordSchema.storageType === 'ItemStorage') {
5525
- const { Item } = yield import('./index-DzDVTUae.js');
5258
+ const { Item } = yield import('./index-D3j5ZJGe.js');
5526
5259
  const item = yield Item.find({
5527
5260
  seedLocalId,
5528
5261
  modelName,
@@ -5883,6 +5616,7 @@ const saveImageSrc = fromCallback(({ sendBack, input: { context, event } }) => {
5883
5616
  }
5884
5617
  catch (e) {
5885
5618
  fs.writeFileSync(filePath, new Uint8Array(fileData));
5619
+ eventEmitter.emit('file-saved', filePath);
5886
5620
  }
5887
5621
  }
5888
5622
  if (typeof fileData === 'string') {
@@ -5891,6 +5625,7 @@ const saveImageSrc = fromCallback(({ sendBack, input: { context, event } }) => {
5891
5625
  }
5892
5626
  catch (e) {
5893
5627
  fs.writeFileSync(filePath, fileData);
5628
+ eventEmitter.emit('file-saved', filePath);
5894
5629
  }
5895
5630
  }
5896
5631
  const refResolvedDisplayValue = yield BaseFileManager.getContentUrlFromPath(filePath);
@@ -6112,7 +5847,7 @@ const saveItemStorage = fromCallback(({ sendBack, input: { context, event } }) =
6112
5847
  }
6113
5848
  const localStorageDir = propertyRecordSchema.localStorageDir || propertyData.localStorageDir;
6114
5849
  const fileName = propertyData.refResolvedValue ||
6115
- `${propertyData.seedLocalId}${propertyRecordSchema.filenameSuffix}`;
5850
+ `${propertyData.seedUid || propertyData.seedLocalId}${propertyRecordSchema.filenameSuffix}`;
6116
5851
  if (!localStorageDir || !fileName) {
6117
5852
  throw new Error(`Missing localStorageDir: ${localStorageDir} or fileName: ${fileName}`);
6118
5853
  }
@@ -6234,7 +5969,7 @@ const propertyMachine = setup({
6234
5969
  target: 'idle',
6235
5970
  actions: assign({
6236
5971
  refResolvedDisplayValue: ({ event }) => event.refResolvedDisplayValue,
6237
- resolvedValue: ({ event }) => event.refResolvedValue,
5972
+ refResolvedValue: ({ event }) => event.refResolvedValue,
6238
5973
  }),
6239
5974
  },
6240
5975
  resolvingRelatedValueDone: {
@@ -6857,7 +6592,7 @@ const getItem = (_a) => __awaiter(void 0, [_a], void 0, function* ({ modelName,
6857
6592
  console.error(`[db/queries] [getItem] no itemInitObj.seedLocalId modelName: ${modelName} seedLocalId: ${seedLocalId} seedUid: ${seedUid}`);
6858
6593
  return;
6859
6594
  }
6860
- return Item.create(itemInitObj);
6595
+ return BaseItem.create(itemInitObj);
6861
6596
  });
6862
6597
 
6863
6598
  const getVersionUid = (item) => {
@@ -7015,12 +6750,6 @@ const processListProperty = (listProperty, multiPublishPayload) => __awaiter(voi
7015
6750
  return multiPublishPayload;
7016
6751
  });
7017
6752
  const getPublishPayload = (item, uploadedTransactions) => __awaiter(void 0, void 0, void 0, function* () {
7018
- if (item.modelName === 'Post') {
7019
- item.authors = [
7020
- 'Sr0bIx9Fwj',
7021
- '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',
7022
- ];
7023
- }
7024
6753
  let multiPublishPayload = [];
7025
6754
  // Each PublishPayload is generated from a Seed that needs publishing
7026
6755
  // First we need to determine all Seeds to publish
@@ -7319,6 +7048,9 @@ class BaseItem {
7319
7048
  get properties() {
7320
7049
  return this._propertiesSubject.value;
7321
7050
  }
7051
+ get attestationCreatedAt() {
7052
+ return this.serviceContext.attestationCreatedAt;
7053
+ }
7322
7054
  unload() {
7323
7055
  var _b;
7324
7056
  (_b = this._subscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
@@ -7742,7 +7474,7 @@ const useItem = ({ modelName, seedLocalId, seedUid }) => {
7742
7474
  itemStatus,
7743
7475
  };
7744
7476
  };
7745
- const useItems = ({ modelName, deleted }) => {
7477
+ const useItems = ({ modelName, deleted = false }) => {
7746
7478
  const [items, setItems] = useImmer([]);
7747
7479
  const { status, internalStatus } = useGlobalServiceStatus();
7748
7480
  const modelNameRef = useRef(modelName);
@@ -7785,7 +7517,7 @@ const useItems = ({ modelName, deleted }) => {
7785
7517
  item.attestationCreatedAt ||
7786
7518
  item.createdAt,
7787
7519
  ], ['desc']),
7788
- isReadingDb,
7520
+ isReadingDb: isReadingDb.current,
7789
7521
  };
7790
7522
  };
7791
7523
  const useItemIsReady = () => {
@@ -7841,8 +7573,8 @@ const usePublishItem = () => {
7841
7573
  isLocked.current = true;
7842
7574
  setIsPublishing(true);
7843
7575
  try {
7844
- // await item.publish()
7845
- const payload = yield item.getPublishPayload();
7576
+ const uploads = yield item.getPublishUploads();
7577
+ const payload = yield item.getPublishPayload(uploads);
7846
7578
  if (callback) {
7847
7579
  callback();
7848
7580
  }
@@ -7996,6 +7728,15 @@ const useDeleteItem = () => {
7996
7728
  };
7997
7729
  };
7998
7730
 
7731
+ eventEmitter.on('file-saved', (filePath) => {
7732
+ const worker = new Worker('./workers/image-resize.ts?worker');
7733
+ console.log('file-saved', filePath);
7734
+ worker.postMessage({
7735
+ type: 'resize',
7736
+ filePath,
7737
+ });
7738
+ });
7739
+
7999
7740
  const withSeed = (config, webpack, isServer) => {
8000
7741
  // If you need to include directories outside of the project root
8001
7742
  // config.module.rules.push({
@@ -8093,28 +7834,28 @@ const setupServiceHandlers = () => {
8093
7834
 
8094
7835
  const initEasClient = () => __awaiter(void 0, void 0, void 0, function* () {
8095
7836
  if (isBrowser()) {
8096
- (yield import('./EasClient-nvmz2kCc.js')).EasClient;
7837
+ (yield import('./EasClient-BNwSwDTO.js')).EasClient;
8097
7838
  }
8098
7839
  if (!isBrowser()) {
8099
- (yield import('./EasClient-CKv5Eyao.js')).EasClient;
7840
+ (yield import('./EasClient-epqE9aWI.js')).EasClient;
8100
7841
  }
8101
7842
  });
8102
7843
 
8103
7844
  const initQueryClient = () => __awaiter(void 0, void 0, void 0, function* () {
8104
7845
  if (isBrowser()) {
8105
- (yield import('./QueryClient-CkqXe8Nk.js')).QueryClient;
7846
+ (yield import('./QueryClient-Ckl99FYC.js')).QueryClient;
8106
7847
  }
8107
7848
  if (!isBrowser()) {
8108
- (yield import('./QueryClient-pzZAYWa0.js')).QueryClient;
7849
+ (yield import('./QueryClient-Do0C7Jnt.js')).QueryClient;
8109
7850
  }
8110
7851
  });
8111
7852
 
8112
7853
  const initFileManager = () => __awaiter(void 0, void 0, void 0, function* () {
8113
7854
  if (isBrowser()) {
8114
- (yield import('./FileManager-Bm_fGCH1.js')).FileManager;
7855
+ (yield import('./FileManager-DXi-X7r5.js')).FileManager;
8115
7856
  }
8116
7857
  if (!isBrowser()) {
8117
- (yield import('./FileManager-EGwM_VHY.js')).FileManager;
7858
+ (yield import('./FileManager-CXk83EW5.js')).FileManager;
8118
7859
  }
8119
7860
  });
8120
7861
 
@@ -8153,7 +7894,7 @@ const client = {
8153
7894
  arweaveDomain,
8154
7895
  filesDir,
8155
7896
  });
8156
- const { models: internalModels } = yield import('./seed.schema.config-BswsDyRe.js');
7897
+ const { models: internalModels } = yield import('./seed.schema.config-DQalKJ_d.js');
8157
7898
  for (const [key, value] of Object.entries(internalModels)) {
8158
7899
  setModel(key, value);
8159
7900
  }
@@ -8200,5 +7941,5 @@ const client = {
8200
7941
 
8201
7942
  enableMapSet();
8202
7943
 
8203
- export { BaseItem as B, Db as D, 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, getSqliteWasmClient as c, ImageSrc as d, Item$2 as e, ItemProperty$2 as f, getAppDb as g, useItem as h, isAppDbReady as i, useItemProperties as j, useCreateItem as k, useItemProperty as l, useDeleteItem as m, useGlobalServiceStatus as n, usePublishItem as o, usePersistedSnapshots as p, useServices as q, useService as r, getCorrectId as s, getGlobalService as t, useItems as u, eventEmitter as v, withSeed as w, client as x };
8204
- //# sourceMappingURL=index-BCmsQoYg.js.map
7944
+ export { BaseItem as B, Db as D, 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, withSeed as s, client as t, useItems as u, waitForFile as w };
7945
+ //# sourceMappingURL=index-B2ovknu0.js.map