@seedprotocol/sdk 0.2.31 → 0.2.33

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 (95) 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-CPpw7pPl.js → Db-CRAJJwNf.js} +11 -9
  6. package/dist/{Db-CPpw7pPl.js.map → Db-CRAJJwNf.js.map} +1 -1
  7. package/dist/Db-DJQELGcv.js +390 -0
  8. package/dist/Db-DJQELGcv.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-DJFIzrGb.js → Item-BOhP5-1O.js} +5 -9
  18. package/dist/{Item-DJFIzrGb.js.map → Item-BOhP5-1O.js.map} +1 -1
  19. package/dist/{ItemProperty-DabiYJLq.js → ItemProperty-DCg4lfHD.js} +5 -9
  20. package/dist/{ItemProperty-DabiYJLq.js.map → ItemProperty-DCg4lfHD.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-D3qJ54jj.js → index-BHO9xsvZ.js} +50 -292
  30. package/dist/index-BHO9xsvZ.js.map +1 -0
  31. package/dist/{index-MhbsovAK.js → index-CL38MNKB.js} +5 -9
  32. package/dist/index-CL38MNKB.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-DCFBkB3M.js → seed.schema.config-CpD6BtqH.js} +5 -9
  36. package/dist/seed.schema.config-CpD6BtqH.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/download.ts +1 -1
  46. package/dist/src/getItem.ts +2 -3
  47. package/dist/src/getPublishPayload.ts +2 -8
  48. package/dist/src/image-resize.ts +28 -0
  49. package/dist/src/migrate.ts +3 -241
  50. package/dist/src/preparePublishRequestData.ts +2 -2
  51. package/dist/src/requestAll.ts +3 -3
  52. package/dist/src/saveImageSrc.ts +4 -0
  53. package/dist/src/upload.ts +2 -2
  54. package/dist/types/src/Item/BaseItem.d.ts +11 -1
  55. package/dist/types/src/Item/BaseItem.d.ts.map +1 -1
  56. package/dist/types/src/ItemProperty/service/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
  57. package/dist/types/src/browser/db/Db.d.ts +2 -0
  58. package/dist/types/src/browser/db/Db.d.ts.map +1 -1
  59. package/dist/types/src/browser/index.d.ts.map +1 -1
  60. package/dist/types/src/browser/react/item.d.ts +3 -2
  61. package/dist/types/src/browser/react/item.d.ts.map +1 -1
  62. package/dist/types/src/browser/workers/content-hash.d.ts +2 -0
  63. package/dist/types/src/browser/workers/content-hash.d.ts.map +1 -0
  64. package/dist/types/src/browser/workers/image-resize.d.ts +2 -0
  65. package/dist/types/src/browser/workers/image-resize.d.ts.map +1 -0
  66. package/dist/types/src/db/Db/BaseDb.d.ts +1 -0
  67. package/dist/types/src/db/Db/BaseDb.d.ts.map +1 -1
  68. package/dist/types/src/db/read/getItem.d.ts.map +1 -1
  69. package/dist/types/src/db/read/getPublishPayload.d.ts +2 -2
  70. package/dist/types/src/db/read/getPublishPayload.d.ts.map +1 -1
  71. package/dist/types/src/helpers/ArweaveClient/queries.d.ts.map +1 -0
  72. package/dist/types/src/helpers/index.d.ts +1 -3
  73. package/dist/types/src/helpers/index.d.ts.map +1 -1
  74. package/dist/types/src/index.d.ts +1 -0
  75. package/dist/types/src/index.d.ts.map +1 -1
  76. package/dist/types/src/interfaces/IItem.d.ts +1 -0
  77. package/dist/types/src/interfaces/IItem.d.ts.map +1 -1
  78. package/dist/types/src/node/db/Db.d.ts +3 -0
  79. package/dist/types/src/node/db/Db.d.ts.map +1 -1
  80. package/dist/types/src/services/db/actors/migrate.d.ts +0 -1
  81. package/dist/types/src/services/db/actors/migrate.d.ts.map +1 -1
  82. package/dist/types/src/types/index.d.ts +0 -31
  83. package/dist/types/src/types/index.d.ts.map +1 -1
  84. package/package.json +7 -14
  85. package/dist/Db-DW4cvius.js +0 -138
  86. package/dist/Db-DW4cvius.js.map +0 -1
  87. package/dist/FileManager-EGwM_VHY.js.map +0 -1
  88. package/dist/index-D3qJ54jj.js.map +0 -1
  89. package/dist/index-MhbsovAK.js.map +0 -1
  90. package/dist/seed.schema.config-DCFBkB3M.js.map +0 -1
  91. package/dist/src/logger.ts +0 -33
  92. package/dist/types/src/browser/arweave/queries.d.ts.map +0 -1
  93. package/dist/types/src/helpers/logger.d.ts +0 -7
  94. package/dist/types/src/helpers/logger.d.ts.map +0 -1
  95. /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-DJFIzrGb.js')).Item;
133
+ Item$2 = (yield import('./Item-BOhP5-1O.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-DabiYJLq.js')).ItemProperty;
183
+ ItemProperty$2 = (yield import('./ItemProperty-DCg4lfHD.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-DW4cvius.js')).Db;
190
+ Db = (yield import('./Db-DJQELGcv.js')).Db;
195
191
  }
196
192
  if (!isBrowser()) {
197
- Db = (yield import('./Db-CPpw7pPl.js')).Db;
193
+ Db = (yield import('./Db-CRAJJwNf.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 = () => {
@@ -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, dbId) {
470
+ return __awaiter(this, void 0, void 0, function* () {
471
+ return this.PlatformClass.migrate(pathToDbDir, dbName, dbId);
472
+ });
473
+ }
522
474
  }
523
475
 
524
476
  var AttestationScalarFieldEnum;
@@ -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)}`);
@@ -1696,7 +1646,7 @@ 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-DCFBkB3M.js');
1649
+ const { models: SeedModels } = yield import('./seed.schema.config-CpD6BtqH.js');
1700
1650
  const allModels = Object.assign(Object.assign({}, SeedModels), models$1);
1701
1651
  let hasModelsInDb = false;
1702
1652
  const schemaDefsByModelName = new Map();
@@ -1914,73 +1864,9 @@ const waitForFile = (filePath, interval = 500, timeout = 10000) => {
1914
1864
  };
1915
1865
 
1916
1866
  const logger$i = 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
- });
1980
1867
  const migrate = fromCallback(({ sendBack, input: { context } }) => {
1981
1868
  const { pathToDbDir, dbId, dbName } = context;
1982
1869
  logger$i('[db/actors] migrate context', context);
1983
- const schemaGlobString = `${BROWSER_FS_TOP_DIR}/schema/*`;
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, dbId);
2152
1902
  });
2153
1903
  _checkForFiles()
2154
1904
  .then(() => {
@@ -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';
@@ -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
  }
@@ -3912,7 +3662,7 @@ 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
3667
  logger$9('no item with localId', localId);
3918
3668
  return false;
@@ -5505,7 +5255,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
5505
5255
  if (propertyRecordSchema &&
5506
5256
  propertyRecordSchema.storageType &&
5507
5257
  propertyRecordSchema.storageType === 'ItemStorage') {
5508
- const { Item } = yield import('./index-MhbsovAK.js');
5258
+ const { Item } = yield import('./index-CL38MNKB.js');
5509
5259
  const item = yield Item.find({
5510
5260
  seedLocalId,
5511
5261
  modelName,
@@ -5866,6 +5616,7 @@ const saveImageSrc = fromCallback(({ sendBack, input: { context, event } }) => {
5866
5616
  }
5867
5617
  catch (e) {
5868
5618
  fs.writeFileSync(filePath, new Uint8Array(fileData));
5619
+ eventEmitter.emit('file-saved', filePath);
5869
5620
  }
5870
5621
  }
5871
5622
  if (typeof fileData === 'string') {
@@ -5874,6 +5625,7 @@ const saveImageSrc = fromCallback(({ sendBack, input: { context, event } }) => {
5874
5625
  }
5875
5626
  catch (e) {
5876
5627
  fs.writeFileSync(filePath, fileData);
5628
+ eventEmitter.emit('file-saved', filePath);
5877
5629
  }
5878
5630
  }
5879
5631
  const refResolvedDisplayValue = yield BaseFileManager.getContentUrlFromPath(filePath);
@@ -6840,7 +6592,7 @@ const getItem = (_a) => __awaiter(void 0, [_a], void 0, function* ({ modelName,
6840
6592
  console.error(`[db/queries] [getItem] no itemInitObj.seedLocalId modelName: ${modelName} seedLocalId: ${seedLocalId} seedUid: ${seedUid}`);
6841
6593
  return;
6842
6594
  }
6843
- return Item.create(itemInitObj);
6595
+ return BaseItem.create(itemInitObj);
6844
6596
  });
6845
6597
 
6846
6598
  const getVersionUid = (item) => {
@@ -6998,12 +6750,6 @@ const processListProperty = (listProperty, multiPublishPayload) => __awaiter(voi
6998
6750
  return multiPublishPayload;
6999
6751
  });
7000
6752
  const getPublishPayload = (item, uploadedTransactions) => __awaiter(void 0, void 0, void 0, function* () {
7001
- if (item.modelName === 'Post') {
7002
- item.authors = [
7003
- 'Sr0bIx9Fwj',
7004
- '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',
7005
- ];
7006
- }
7007
6753
  let multiPublishPayload = [];
7008
6754
  // Each PublishPayload is generated from a Seed that needs publishing
7009
6755
  // First we need to determine all Seeds to publish
@@ -7302,6 +7048,9 @@ class BaseItem {
7302
7048
  get properties() {
7303
7049
  return this._propertiesSubject.value;
7304
7050
  }
7051
+ get attestationCreatedAt() {
7052
+ return this.serviceContext.attestationCreatedAt;
7053
+ }
7305
7054
  unload() {
7306
7055
  var _b;
7307
7056
  (_b = this._subscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
@@ -7725,7 +7474,7 @@ const useItem = ({ modelName, seedLocalId, seedUid }) => {
7725
7474
  itemStatus,
7726
7475
  };
7727
7476
  };
7728
- const useItems = ({ modelName, deleted }) => {
7477
+ const useItems = ({ modelName, deleted = false }) => {
7729
7478
  const [items, setItems] = useImmer([]);
7730
7479
  const { status, internalStatus } = useGlobalServiceStatus();
7731
7480
  const modelNameRef = useRef(modelName);
@@ -7768,7 +7517,7 @@ const useItems = ({ modelName, deleted }) => {
7768
7517
  item.attestationCreatedAt ||
7769
7518
  item.createdAt,
7770
7519
  ], ['desc']),
7771
- isReadingDb,
7520
+ isReadingDb: isReadingDb.current,
7772
7521
  };
7773
7522
  };
7774
7523
  const useItemIsReady = () => {
@@ -7824,8 +7573,8 @@ const usePublishItem = () => {
7824
7573
  isLocked.current = true;
7825
7574
  setIsPublishing(true);
7826
7575
  try {
7827
- // await item.publish()
7828
- const payload = yield item.getPublishPayload();
7576
+ const uploads = yield item.getPublishUploads();
7577
+ const payload = yield item.getPublishPayload(uploads);
7829
7578
  if (callback) {
7830
7579
  callback();
7831
7580
  }
@@ -7979,6 +7728,15 @@ const useDeleteItem = () => {
7979
7728
  };
7980
7729
  };
7981
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
+
7982
7740
  const withSeed = (config, webpack, isServer) => {
7983
7741
  // If you need to include directories outside of the project root
7984
7742
  // config.module.rules.push({
@@ -8076,28 +7834,28 @@ const setupServiceHandlers = () => {
8076
7834
 
8077
7835
  const initEasClient = () => __awaiter(void 0, void 0, void 0, function* () {
8078
7836
  if (isBrowser()) {
8079
- (yield import('./EasClient-nvmz2kCc.js')).EasClient;
7837
+ (yield import('./EasClient-BNwSwDTO.js')).EasClient;
8080
7838
  }
8081
7839
  if (!isBrowser()) {
8082
- (yield import('./EasClient-CKv5Eyao.js')).EasClient;
7840
+ (yield import('./EasClient-epqE9aWI.js')).EasClient;
8083
7841
  }
8084
7842
  });
8085
7843
 
8086
7844
  const initQueryClient = () => __awaiter(void 0, void 0, void 0, function* () {
8087
7845
  if (isBrowser()) {
8088
- (yield import('./QueryClient-CkqXe8Nk.js')).QueryClient;
7846
+ (yield import('./QueryClient-Ckl99FYC.js')).QueryClient;
8089
7847
  }
8090
7848
  if (!isBrowser()) {
8091
- (yield import('./QueryClient-pzZAYWa0.js')).QueryClient;
7849
+ (yield import('./QueryClient-Do0C7Jnt.js')).QueryClient;
8092
7850
  }
8093
7851
  });
8094
7852
 
8095
7853
  const initFileManager = () => __awaiter(void 0, void 0, void 0, function* () {
8096
7854
  if (isBrowser()) {
8097
- (yield import('./FileManager-Bm_fGCH1.js')).FileManager;
7855
+ (yield import('./FileManager-DXi-X7r5.js')).FileManager;
8098
7856
  }
8099
7857
  if (!isBrowser()) {
8100
- (yield import('./FileManager-EGwM_VHY.js')).FileManager;
7858
+ (yield import('./FileManager-CXk83EW5.js')).FileManager;
8101
7859
  }
8102
7860
  });
8103
7861
 
@@ -8136,7 +7894,7 @@ const client = {
8136
7894
  arweaveDomain,
8137
7895
  filesDir,
8138
7896
  });
8139
- const { models: internalModels } = yield import('./seed.schema.config-DCFBkB3M.js');
7897
+ const { models: internalModels } = yield import('./seed.schema.config-CpD6BtqH.js');
8140
7898
  for (const [key, value] of Object.entries(internalModels)) {
8141
7899
  setModel(key, value);
8142
7900
  }
@@ -8183,5 +7941,5 @@ const client = {
8183
7941
 
8184
7942
  enableMapSet();
8185
7943
 
8186
- 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 };
8187
- //# sourceMappingURL=index-D3qJ54jj.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-BHO9xsvZ.js.map