@seedprotocol/sdk 0.2.53 → 0.3.0
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.
- package/dist/{ArweaveClient-D5iJisYr.js → ArweaveClient-CmJYeuq1.js} +2 -2
- package/dist/{ArweaveClient-HEIIuOfB.js.map → ArweaveClient-CmJYeuq1.js.map} +1 -1
- package/dist/{ArweaveClient-HEIIuOfB.js → ArweaveClient-EXXrXUzz.js} +2 -2
- package/dist/{ArweaveClient-D5iJisYr.js.map → ArweaveClient-EXXrXUzz.js.map} +1 -1
- package/dist/{Db-DqBP6XK2.js → Db-CESKJH-G.js} +4 -3
- package/dist/{Db-DqBP6XK2.js.map → Db-CESKJH-G.js.map} +1 -1
- package/dist/Db-DiTPSbQ8.js +82 -0
- package/dist/Db-DiTPSbQ8.js.map +1 -0
- package/dist/EasClient-BesHK2bO.js +10 -0
- package/dist/EasClient-BesHK2bO.js.map +1 -0
- package/dist/{EasClient-D3wKgt0o.js → EasClient-Cop6WtWl.js} +2 -2
- package/dist/{EasClient-D3wKgt0o.js.map → EasClient-Cop6WtWl.js.map} +1 -1
- package/dist/{FileManager-4mWYO3Mt.js → FileManager-DTzkncLh.js} +3 -2
- package/dist/{FileManager-4mWYO3Mt.js.map → FileManager-DTzkncLh.js.map} +1 -1
- package/dist/{Item-COP3FuaU.js → Item-B5Tz-Y7t.js} +4 -3
- package/dist/{Item-COP3FuaU.js.map → Item-B5Tz-Y7t.js.map} +1 -1
- package/dist/{ItemProperty-BFn9wM65.js → ItemProperty-DBV0Iib_.js} +4 -3
- package/dist/{ItemProperty-BFn9wM65.js.map → ItemProperty-DBV0Iib_.js.map} +1 -1
- package/dist/{QueryClient-CBOP3OoU.js → QueryClient-BnwbHtqe.js} +3 -2
- package/dist/{QueryClient-CBOP3OoU.js.map → QueryClient-BnwbHtqe.js.map} +1 -1
- package/dist/QueryClient-C7a0NHCt.js +22 -0
- package/dist/QueryClient-C7a0NHCt.js.map +1 -0
- package/dist/bin.js +30 -34
- package/dist/bin.js.map +1 -1
- package/dist/{constants-CIDbABDz.js → constants-CWg2B3Au.js} +6 -4
- package/dist/constants-CWg2B3Au.js.map +1 -0
- package/dist/db/configs/node.app.db.config.ts +27 -0
- package/dist/{index-CLvyWg5f.js → index-BHGJ-Es9.js} +262 -257
- package/dist/index-BHGJ-Es9.js.map +1 -0
- package/dist/{index-C4xqqsLw.js → index-CQ9FS10O.js} +4 -3
- package/dist/index-CQ9FS10O.js.map +1 -0
- package/dist/main.js +3 -2
- package/dist/main.js.map +1 -1
- package/dist/node/db/node.app.db.config.ts +1 -1
- package/dist/package.json +8 -8
- package/dist/{seed.schema.config-Bao3o6wu.js → seed.schema.config-DDzfQguf.js} +10 -9
- package/dist/seed.schema.config-DDzfQguf.js.map +1 -0
- package/dist/types/scripts/bin.d.ts.map +1 -1
- package/dist/types/src/browser/helpers/EasClient.d.ts +1 -3
- package/dist/types/src/browser/helpers/EasClient.d.ts.map +1 -1
- package/dist/types/src/client/ClientManager.d.ts +44 -0
- package/dist/types/src/client/ClientManager.d.ts.map +1 -0
- package/dist/types/src/client/actions/setAddresses.d.ts.map +1 -1
- package/dist/types/src/client/actors/initialize.d.ts.map +1 -1
- package/dist/types/src/client/actors/saveAppState.d.ts.map +1 -1
- package/dist/types/src/client/clientManagerMachine.d.ts.map +1 -1
- package/dist/types/src/client/index.d.ts +2 -40
- package/dist/types/src/client/index.d.ts.map +1 -1
- package/dist/types/src/db/configs/node.app.db.config.d.ts +3 -0
- package/dist/types/src/db/configs/node.app.db.config.d.ts.map +1 -0
- package/dist/types/src/events/files/download.d.ts.map +1 -1
- package/dist/types/src/helpers/EasClient/BaseEasClient.d.ts.map +1 -1
- package/dist/types/src/helpers/constants.d.ts +1 -0
- package/dist/types/src/helpers/constants.d.ts.map +1 -1
- package/dist/types/src/interfaces/IQueryClient.d.ts +7 -1
- package/dist/types/src/interfaces/IQueryClient.d.ts.map +1 -1
- package/dist/types/src/node/db/Db.d.ts +5 -10
- package/dist/types/src/node/db/Db.d.ts.map +1 -1
- package/dist/types/src/node/helpers/QueryClient.d.ts +2 -4
- package/dist/types/src/node/helpers/QueryClient.d.ts.map +1 -1
- package/dist/types/src/services/allItems/actors/fetchSeeds.d.ts.map +1 -1
- package/dist/types/src/services/db/actors/checkStatus.d.ts.map +1 -1
- package/dist/types/src/services/db/actors/migrate.d.ts.map +1 -1
- package/dist/types/src/services/db/actors/waitForFiles.d.ts.map +1 -1
- package/dist/types/src/services/internal/actors/configureFs.d.ts.map +1 -1
- package/dist/types/src/services/internal/actors/loadAppDb.d.ts.map +1 -1
- package/dist/types/src/services/internal/actors/saveConfig.d.ts.map +1 -1
- package/dist/types/src/services/internal/actors/waitForFiles.d.ts.map +1 -1
- package/dist/types/src/services/internal/internalMachine.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/Db-Bh_lvrAN.js +0 -111
- package/dist/Db-Bh_lvrAN.js.map +0 -1
- package/dist/EasClient-jqkT2ZBt.js +0 -13
- package/dist/EasClient-jqkT2ZBt.js.map +0 -1
- package/dist/QueryClient-bKb3SB0W.js +0 -23
- package/dist/QueryClient-bKb3SB0W.js.map +0 -1
- package/dist/constants-CIDbABDz.js.map +0 -1
- package/dist/index-C4xqqsLw.js.map +0 -1
- package/dist/index-CLvyWg5f.js.map +0 -1
- package/dist/seed.schema.config-Bao3o6wu.js.map +0 -1
- package/dist/types/src/client.d.ts +0 -18
- 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,
|
|
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,
|
|
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-CWg2B3Au.js';
|
|
6
6
|
import debug from 'debug';
|
|
7
7
|
import pluralize from 'pluralize';
|
|
8
|
-
import { sqliteTable,
|
|
9
|
-
import { relations, or, and, isNotNull, not, eq, inArray, sql, like, getTableColumns, isNull,
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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-
|
|
1354
|
+
const { models: SeedModels } = await import('./seed.schema.config-DDzfQguf.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$
|
|
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$
|
|
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$
|
|
1441
|
-
const checkStatus = fromCallback(({ sendBack, input: { context } }) => {
|
|
1442
|
-
const { dbName } = context;
|
|
1443
|
-
|
|
1444
|
-
|
|
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$
|
|
1481
|
+
const logger$k = debug('app:services:db:actors:connectToDb');
|
|
1475
1482
|
const connectToDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
1476
|
-
logger$
|
|
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,7 +2263,7 @@ class ImageResizer {
|
|
|
2256
2263
|
}
|
|
2257
2264
|
}
|
|
2258
2265
|
|
|
2259
|
-
const logger$
|
|
2266
|
+
const logger$j = debug('app:browser:helpers:FileManager');
|
|
2260
2267
|
class FileManager extends BaseFileManager {
|
|
2261
2268
|
static async readFileAsBuffer(filePath) {
|
|
2262
2269
|
return new Promise((resolve, reject) => {
|
|
@@ -2362,7 +2369,7 @@ class FileManager extends BaseFileManager {
|
|
|
2362
2369
|
const startTime = Date.now();
|
|
2363
2370
|
let isBusy = false;
|
|
2364
2371
|
const cancelableInterval = new CancelableInterval(async (stop) => {
|
|
2365
|
-
logger$
|
|
2372
|
+
logger$j('waitForFile', filePath);
|
|
2366
2373
|
if (isBusy) {
|
|
2367
2374
|
return;
|
|
2368
2375
|
}
|
|
@@ -2522,15 +2529,15 @@ var FileManager$1 = /*#__PURE__*/Object.freeze({
|
|
|
2522
2529
|
FileManager: FileManager
|
|
2523
2530
|
});
|
|
2524
2531
|
|
|
2525
|
-
const logger$
|
|
2532
|
+
const logger$i = debug('app:services:db:actors:migrate');
|
|
2526
2533
|
const migrate = fromCallback(({ sendBack, input: { context } }) => {
|
|
2527
2534
|
const { pathToDbDir, dbId, dbName } = context;
|
|
2528
|
-
logger$
|
|
2535
|
+
logger$i('[db/actors] migrate context', context);
|
|
2529
2536
|
let journalExists = false;
|
|
2530
2537
|
const _checkForFiles = async () => {
|
|
2531
2538
|
const journalPath = `/${pathToDbDir}/meta/_journal.json`;
|
|
2532
2539
|
journalExists = await fs.promises.exists(journalPath);
|
|
2533
|
-
if (!journalExists) {
|
|
2540
|
+
if (!journalExists && isBrowser()) {
|
|
2534
2541
|
await FileManager.waitForFile(journalPath, 500, 60000);
|
|
2535
2542
|
}
|
|
2536
2543
|
};
|
|
@@ -2539,11 +2546,15 @@ const migrate = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2539
2546
|
};
|
|
2540
2547
|
_checkForFiles()
|
|
2541
2548
|
.then(() => {
|
|
2549
|
+
if (!isBrowser()) {
|
|
2550
|
+
return _migrate();
|
|
2551
|
+
}
|
|
2542
2552
|
if (journalExists) {
|
|
2543
2553
|
return _migrate();
|
|
2544
2554
|
}
|
|
2545
2555
|
})
|
|
2546
2556
|
.then(() => {
|
|
2557
|
+
console.log('sending db migrating success');
|
|
2547
2558
|
sendBack({ type: DB_MIGRATING_SUCCESS, dbName });
|
|
2548
2559
|
});
|
|
2549
2560
|
return () => { };
|
|
@@ -2551,6 +2562,10 @@ const migrate = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2551
2562
|
|
|
2552
2563
|
debug('app:services:db:actors:waitForFiles');
|
|
2553
2564
|
const waitForFiles$1 = fromCallback(({ sendBack, input: { context } }) => {
|
|
2565
|
+
if (!isBrowser()) {
|
|
2566
|
+
sendBack({ type: DB_WAITING_FOR_FILES_RECEIVED });
|
|
2567
|
+
return;
|
|
2568
|
+
}
|
|
2554
2569
|
const { pathToDbDir } = context;
|
|
2555
2570
|
const _waitForFiles = async () => {
|
|
2556
2571
|
return new Promise((resolve) => {
|
|
@@ -2569,7 +2584,7 @@ const waitForFiles$1 = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2569
2584
|
});
|
|
2570
2585
|
});
|
|
2571
2586
|
|
|
2572
|
-
const logger$
|
|
2587
|
+
const logger$h = debug('app:services:db:machine');
|
|
2573
2588
|
const { CHECKING_STATUS, VALIDATING, WAITING_FOR_FILES, CONNECTING_TO_DB, MIGRATING, } = DbState;
|
|
2574
2589
|
const dbMachine = setup({
|
|
2575
2590
|
types: {
|
|
@@ -2591,7 +2606,7 @@ const dbMachine = setup({
|
|
|
2591
2606
|
[DB_WAITING_FOR_FILES_RECEIVED]: {
|
|
2592
2607
|
actions: assign({
|
|
2593
2608
|
hasFiles: ({ event }) => {
|
|
2594
|
-
logger$
|
|
2609
|
+
logger$h('[db/machine] DB_WAITING_FOR_FILES_RECEIVED event:', event);
|
|
2595
2610
|
return true;
|
|
2596
2611
|
},
|
|
2597
2612
|
}),
|
|
@@ -2600,8 +2615,8 @@ const dbMachine = setup({
|
|
|
2600
2615
|
target: `.${CHECKING_STATUS}`,
|
|
2601
2616
|
actions: assign({
|
|
2602
2617
|
hasFiles: ({ context, event }) => {
|
|
2603
|
-
logger$
|
|
2604
|
-
logger$
|
|
2618
|
+
logger$h('[db/machine] updateHasFiles event:', event);
|
|
2619
|
+
logger$h('[db/machine] updateHasFiles context:', context);
|
|
2605
2620
|
return event.hasFiles;
|
|
2606
2621
|
},
|
|
2607
2622
|
}),
|
|
@@ -2755,9 +2770,9 @@ const prepareDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2755
2770
|
throw new Error('filesDir is required');
|
|
2756
2771
|
}
|
|
2757
2772
|
const _prepareDb = async () => {
|
|
2758
|
-
const
|
|
2759
|
-
if (
|
|
2760
|
-
sendBack({ type: 'prepareDbSuccess'
|
|
2773
|
+
const appDb = await BaseDb.prepareDb(filesDir);
|
|
2774
|
+
if (appDb) {
|
|
2775
|
+
sendBack({ type: 'prepareDbSuccess' });
|
|
2761
2776
|
}
|
|
2762
2777
|
};
|
|
2763
2778
|
_prepareDb().then(() => {
|
|
@@ -2765,7 +2780,7 @@ const prepareDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2765
2780
|
});
|
|
2766
2781
|
});
|
|
2767
2782
|
|
|
2768
|
-
const logger$
|
|
2783
|
+
const logger$g = debug('app:services:internal:helpers');
|
|
2769
2784
|
/**
|
|
2770
2785
|
* Recursively create directories if they don't exist.
|
|
2771
2786
|
* @param {string} dirPath - The directory path to create.
|
|
@@ -2829,11 +2844,11 @@ class FileDownloadManager {
|
|
|
2829
2844
|
}
|
|
2830
2845
|
try {
|
|
2831
2846
|
await fs.promises.writeFile(localFilePath, fileData);
|
|
2832
|
-
logger$
|
|
2847
|
+
logger$g(`[downloadFile] Wrote file async to ${localFilePath}`);
|
|
2833
2848
|
}
|
|
2834
2849
|
catch (error) {
|
|
2835
2850
|
fs.writeFileSync(localFilePath, fileData);
|
|
2836
|
-
logger$
|
|
2851
|
+
logger$g(`[downloadFile] Wrote file sync to ${localFilePath}`);
|
|
2837
2852
|
}
|
|
2838
2853
|
}
|
|
2839
2854
|
async start() {
|
|
@@ -2923,7 +2938,7 @@ const syncDbFiles = async ({ filePaths, files }) => {
|
|
|
2923
2938
|
await downloadManager.start();
|
|
2924
2939
|
// await fetchFilesRecursively(files, BROWSER_FS_TOP_DIR, fileList)
|
|
2925
2940
|
await confirmFilesExist(fileList);
|
|
2926
|
-
logger$
|
|
2941
|
+
logger$g('[syncDbFiles] Files synced!');
|
|
2927
2942
|
};
|
|
2928
2943
|
|
|
2929
2944
|
const GET_FILES_METADATA = graphql(/* GraphQL */ `
|
|
@@ -2973,7 +2988,7 @@ graphql(/* GraphQL */ `
|
|
|
2973
2988
|
const getMetadata = async (props) => {
|
|
2974
2989
|
const appDb = BaseDb.getAppDb();
|
|
2975
2990
|
let storageTransactionId;
|
|
2976
|
-
{
|
|
2991
|
+
if (props) {
|
|
2977
2992
|
storageTransactionId = props.storageTransactionId;
|
|
2978
2993
|
}
|
|
2979
2994
|
const whereClauses = [];
|
|
@@ -3016,10 +3031,10 @@ const GET_TRANSACTION_TAGS = graphql(/* GraphQL */ `
|
|
|
3016
3031
|
|
|
3017
3032
|
const initArweaveClient = async () => {
|
|
3018
3033
|
if (isBrowser()) {
|
|
3019
|
-
(await import('./ArweaveClient-
|
|
3034
|
+
(await import('./ArweaveClient-EXXrXUzz.js')).ArweaveClient;
|
|
3020
3035
|
}
|
|
3021
3036
|
if (!isBrowser()) {
|
|
3022
|
-
(await import('./ArweaveClient-
|
|
3037
|
+
(await import('./ArweaveClient-CmJYeuq1.js')).ArweaveClient;
|
|
3023
3038
|
}
|
|
3024
3039
|
};
|
|
3025
3040
|
let domain = 'arweave.net';
|
|
@@ -3062,8 +3077,11 @@ const setArweaveDomain = (newDomain) => {
|
|
|
3062
3077
|
domain = newDomain;
|
|
3063
3078
|
};
|
|
3064
3079
|
|
|
3065
|
-
const logger$
|
|
3080
|
+
const logger$f = debug('app:files:download');
|
|
3066
3081
|
const downloadAllFilesRequestHandler = async ({ endpoints, eventId, }) => {
|
|
3082
|
+
if (!isBrowser()) {
|
|
3083
|
+
return;
|
|
3084
|
+
}
|
|
3067
3085
|
await syncDbFiles(endpoints);
|
|
3068
3086
|
eventEmitter.emit('fs.downloadAll.success', { eventId });
|
|
3069
3087
|
eventEmitter.emit('fs.downloadAllBinary.request', { endpoints });
|
|
@@ -3146,7 +3164,7 @@ const downloadAllFilesBinaryRequestHandler = async () => {
|
|
|
3146
3164
|
try {
|
|
3147
3165
|
const res = await fetch(`https://${ARWEAVE_HOST}/tx/${transactionId}/status`);
|
|
3148
3166
|
if (res.status !== 200) {
|
|
3149
|
-
logger$
|
|
3167
|
+
logger$f(`[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`);
|
|
3150
3168
|
excludedTransactions.add(transactionId);
|
|
3151
3169
|
await saveAppState$1('excludedTransactions', JSON.stringify(Array.from(excludedTransactions)));
|
|
3152
3170
|
continue;
|
|
@@ -3175,7 +3193,7 @@ const downloadAllFilesBinaryRequestHandler = async () => {
|
|
|
3175
3193
|
transactionIdsToDownload.push(transactionId);
|
|
3176
3194
|
}
|
|
3177
3195
|
catch (error) {
|
|
3178
|
-
logger$
|
|
3196
|
+
logger$f(error);
|
|
3179
3197
|
}
|
|
3180
3198
|
}
|
|
3181
3199
|
console.log('[download] Calling downloadAllFiles with transactionIdsToDownload', transactionIdsToDownload);
|
|
@@ -3226,23 +3244,25 @@ const isFsInitialized = () => {
|
|
|
3226
3244
|
return isInitialized;
|
|
3227
3245
|
};
|
|
3228
3246
|
|
|
3229
|
-
const logger$
|
|
3247
|
+
const logger$e = debug('app:internal:actors:configureFs');
|
|
3230
3248
|
const configureFs = fromCallback(({ sendBack, input: { context } }) => {
|
|
3231
3249
|
const { endpoints, appDbService, filesDir, } = context;
|
|
3232
|
-
logger$
|
|
3250
|
+
logger$e('[internal/actors] [configureFs] Configuring FS');
|
|
3233
3251
|
const _configureFs = async () => {
|
|
3234
|
-
logger$
|
|
3235
|
-
logger$
|
|
3236
|
-
logger$
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3252
|
+
logger$e('[internal/actors] [configureFs] calling _configureFs');
|
|
3253
|
+
logger$e('[internal/actors] [configureFs] areFsListenersReady:', areFsListenersReady());
|
|
3254
|
+
logger$e('[internal/actors] [configureFs] isFsInitialized:', isFsInitialized());
|
|
3255
|
+
if (isBrowser()) {
|
|
3256
|
+
await waitForEvent({
|
|
3257
|
+
req: {
|
|
3258
|
+
eventLabel: 'fs.downloadAll.request',
|
|
3259
|
+
data: { endpoints },
|
|
3260
|
+
},
|
|
3261
|
+
res: {
|
|
3262
|
+
eventLabel: 'fs.downloadAll.success',
|
|
3263
|
+
},
|
|
3264
|
+
});
|
|
3265
|
+
}
|
|
3246
3266
|
const journalPath = `${filesDir || BROWSER_FS_TOP_DIR}/db/meta/_journal.json`;
|
|
3247
3267
|
let journalExists = await fs.promises.exists(journalPath);
|
|
3248
3268
|
if (!journalExists) {
|
|
@@ -3250,7 +3270,7 @@ const configureFs = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3250
3270
|
}
|
|
3251
3271
|
if (journalExists) {
|
|
3252
3272
|
appDbService.send({ type: DB_WAITING_FOR_FILES_RECEIVED });
|
|
3253
|
-
logger$
|
|
3273
|
+
logger$e('[internal/actors] [configureFs] fs configured!');
|
|
3254
3274
|
return true;
|
|
3255
3275
|
}
|
|
3256
3276
|
sendBack({ type: 'shouldWaitForFiles' });
|
|
@@ -3283,15 +3303,8 @@ const configureFs = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3283
3303
|
return () => { };
|
|
3284
3304
|
});
|
|
3285
3305
|
|
|
3286
|
-
const logger$
|
|
3306
|
+
const logger$d = debug('app:services:internal:actors:saveConfig');
|
|
3287
3307
|
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
3308
|
const { endpoints, addresses, arweaveDomain } = context;
|
|
3296
3309
|
if (!endpoints) {
|
|
3297
3310
|
throw new Error('saveConfig called with invalid endpoints');
|
|
@@ -3304,81 +3317,84 @@ const saveConfig = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3304
3317
|
}
|
|
3305
3318
|
const endpointsValueString = JSON.stringify(endpoints);
|
|
3306
3319
|
const addressesValueString = JSON.stringify(addresses);
|
|
3320
|
+
const tableColumns = getTableColumns(appState);
|
|
3321
|
+
logger$d('tableColumns', tableColumns);
|
|
3322
|
+
const { columns, indexes, foreignKeys, checks, primaryKeys, name, } = getTableConfig(appState);
|
|
3323
|
+
logger$d('columns', columns);
|
|
3324
|
+
logger$d('indexes', indexes);
|
|
3325
|
+
logger$d('foreignKeys', foreignKeys);
|
|
3326
|
+
logger$d('checks', checks);
|
|
3327
|
+
logger$d('primaryKeys', primaryKeys);
|
|
3328
|
+
logger$d('name', name);
|
|
3329
|
+
logger$d('calling select on db');
|
|
3330
|
+
const queryResult = await appDb.select().from(appState);
|
|
3331
|
+
logger$d('queryResult', queryResult);
|
|
3307
3332
|
// TODO: Figure out how to define on conflict with multiple rows added
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3333
|
+
await appDb
|
|
3334
|
+
.insert(appState)
|
|
3335
|
+
.values({
|
|
3336
|
+
key: 'endpoints',
|
|
3337
|
+
value: endpointsValueString,
|
|
3338
|
+
})
|
|
3339
|
+
.onConflictDoUpdate({
|
|
3340
|
+
target: appState.key,
|
|
3341
|
+
set: {
|
|
3314
3342
|
value: endpointsValueString,
|
|
3315
|
-
}
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3343
|
+
},
|
|
3344
|
+
});
|
|
3345
|
+
// logger('[sdk] [internal/actors] Saving addresses to db')
|
|
3346
|
+
await appDb
|
|
3347
|
+
.insert(appState)
|
|
3348
|
+
.values({
|
|
3349
|
+
key: 'addresses',
|
|
3350
|
+
value: addressesValueString,
|
|
3351
|
+
})
|
|
3352
|
+
.onConflictDoUpdate({
|
|
3353
|
+
target: appState.key,
|
|
3354
|
+
set: {
|
|
3327
3355
|
value: addressesValueString,
|
|
3328
|
-
}
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3356
|
+
},
|
|
3357
|
+
});
|
|
3358
|
+
await appDb
|
|
3359
|
+
.insert(appState)
|
|
3360
|
+
.values({
|
|
3361
|
+
key: 'arweaveDomain',
|
|
3362
|
+
value: arweaveDomain || 'arweave.net',
|
|
3363
|
+
})
|
|
3364
|
+
.onConflictDoUpdate({
|
|
3365
|
+
target: appState.key,
|
|
3366
|
+
set: {
|
|
3339
3367
|
value: arweaveDomain || 'arweave.net',
|
|
3340
|
-
}
|
|
3341
|
-
|
|
3342
|
-
|
|
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
|
-
}
|
|
3368
|
+
},
|
|
3369
|
+
});
|
|
3370
|
+
logger$d('[sdk] [internal/actors] Should be done saving');
|
|
3352
3371
|
};
|
|
3353
3372
|
_saveConfig().then(() => {
|
|
3354
|
-
logger$
|
|
3373
|
+
logger$d('[sdk] [internal/actors] Successfully saved config');
|
|
3355
3374
|
return sendBack({ type: INTERNAL_SAVING_CONFIG_SUCCESS });
|
|
3356
3375
|
});
|
|
3357
3376
|
return () => { };
|
|
3358
3377
|
});
|
|
3359
3378
|
|
|
3360
|
-
|
|
3379
|
+
debug('app:services:internal:actors:loadAppDb');
|
|
3361
3380
|
const loadAppDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
3362
3381
|
const { appDbService } = context;
|
|
3363
3382
|
let subscription;
|
|
3364
3383
|
const _loadAppDb = async () => {
|
|
3384
|
+
if (appDbService.getSnapshot().value === 'ready') {
|
|
3385
|
+
return;
|
|
3386
|
+
}
|
|
3365
3387
|
return new Promise((resolve) => {
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
if (snapshot.value === 'ready') {
|
|
3372
|
-
return resolve();
|
|
3373
|
-
}
|
|
3374
|
-
sendBack({ type: DB_ON_SNAPSHOT, dbName: DB_NAME_APP, snapshot });
|
|
3375
|
-
},
|
|
3388
|
+
subscription = appDbService.subscribe((snapshot) => {
|
|
3389
|
+
if (snapshot.value === 'ready') {
|
|
3390
|
+
return resolve();
|
|
3391
|
+
}
|
|
3392
|
+
sendBack({ type: DB_ON_SNAPSHOT, dbName: DB_NAME_APP, snapshot });
|
|
3376
3393
|
});
|
|
3377
3394
|
});
|
|
3378
3395
|
};
|
|
3379
3396
|
_loadAppDb().then(() => {
|
|
3380
3397
|
sendBack({ type: INTERNAL_LOADING_APP_DB_SUCCESS });
|
|
3381
|
-
logger$f('[sdk] [internal/actors] Successfully loaded app DB');
|
|
3382
3398
|
});
|
|
3383
3399
|
return () => {
|
|
3384
3400
|
if (subscription) {
|
|
@@ -3389,6 +3405,10 @@ const loadAppDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3389
3405
|
|
|
3390
3406
|
debug('app:services:internal:actors:waitForFiles');
|
|
3391
3407
|
const waitForFiles = fromCallback(({ sendBack, input: { context } }) => {
|
|
3408
|
+
if (!isBrowser()) {
|
|
3409
|
+
sendBack({ type: 'filesReceived' });
|
|
3410
|
+
return;
|
|
3411
|
+
}
|
|
3392
3412
|
const { endpoints } = context;
|
|
3393
3413
|
const filesDir = endpoints.files;
|
|
3394
3414
|
const _waitForFiles = async () => {
|
|
@@ -3408,8 +3428,8 @@ const waitForFiles = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3408
3428
|
});
|
|
3409
3429
|
});
|
|
3410
3430
|
|
|
3411
|
-
const logger$
|
|
3412
|
-
createBrowserInspector({
|
|
3431
|
+
const logger$c = debug('app:services:internal:machine');
|
|
3432
|
+
const { inspect: inspect$1 } = createBrowserInspector({
|
|
3413
3433
|
autoStart: false,
|
|
3414
3434
|
});
|
|
3415
3435
|
const { IDLE: IDLE$1, VALIDATING_INPUT, SAVING_CONFIG, CONFIGURING_FS, LOADING_APP_DB, } = InternalState;
|
|
@@ -3445,11 +3465,14 @@ const internalMachine = setup({
|
|
|
3445
3465
|
target: VALIDATING_INPUT,
|
|
3446
3466
|
actions: [
|
|
3447
3467
|
assign({
|
|
3448
|
-
appDbService: ({ spawn }) =>
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3468
|
+
appDbService: ({ context, spawn }) => {
|
|
3469
|
+
return spawn(dbMachine, {
|
|
3470
|
+
input: {
|
|
3471
|
+
dbName: DB_NAME_APP,
|
|
3472
|
+
pathToDir: context?.filesDir,
|
|
3473
|
+
},
|
|
3474
|
+
});
|
|
3475
|
+
},
|
|
3453
3476
|
}),
|
|
3454
3477
|
],
|
|
3455
3478
|
},
|
|
@@ -3528,7 +3551,7 @@ const internalMachine = setup({
|
|
|
3528
3551
|
[INTERNAL_LOADING_APP_DB_SUCCESS]: {
|
|
3529
3552
|
target: SAVING_CONFIG,
|
|
3530
3553
|
actions: () => {
|
|
3531
|
-
logger$
|
|
3554
|
+
logger$c('[sdk] [internal/index] App DB loaded!');
|
|
3532
3555
|
},
|
|
3533
3556
|
},
|
|
3534
3557
|
},
|
|
@@ -3554,7 +3577,8 @@ const internalMachine = setup({
|
|
|
3554
3577
|
},
|
|
3555
3578
|
ready: {
|
|
3556
3579
|
entry: () => {
|
|
3557
|
-
|
|
3580
|
+
console.log('[sdk] [internal/index] Ready!');
|
|
3581
|
+
logger$c('[sdk] [internal/index] Ready!');
|
|
3558
3582
|
},
|
|
3559
3583
|
meta: {
|
|
3560
3584
|
displayText: "Crossing the t's ...",
|
|
@@ -3569,7 +3593,7 @@ const internalMachine = setup({
|
|
|
3569
3593
|
},
|
|
3570
3594
|
},
|
|
3571
3595
|
entry: () => {
|
|
3572
|
-
logger$
|
|
3596
|
+
logger$c('[sdk] [internal/index] Error!');
|
|
3573
3597
|
},
|
|
3574
3598
|
meta: {
|
|
3575
3599
|
displayText: 'Whoops! Something went wrong.',
|
|
@@ -3739,6 +3763,7 @@ const initialize$2 = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3739
3763
|
});
|
|
3740
3764
|
|
|
3741
3765
|
const fetchDbData = fromCallback(({ sendBack, input: { context } }) => {
|
|
3766
|
+
const { modelNamePlural, times } = context;
|
|
3742
3767
|
const _fetchDbData = async () => { };
|
|
3743
3768
|
_fetchDbData().then(() => {
|
|
3744
3769
|
sendBack({ type: 'fetchDbDataSuccess' });
|
|
@@ -3746,7 +3771,7 @@ const fetchDbData = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3746
3771
|
return () => { };
|
|
3747
3772
|
});
|
|
3748
3773
|
|
|
3749
|
-
|
|
3774
|
+
debug('app:allItemsActors:fetchSeeds');
|
|
3750
3775
|
const fetchSeeds = fromCallback(({ sendBack, input: { context } }) => {
|
|
3751
3776
|
const { queryVariables, modelName } = context;
|
|
3752
3777
|
if (!queryVariables) {
|
|
@@ -3757,8 +3782,6 @@ const fetchSeeds = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3757
3782
|
const queryKey = [`getSeeds${modelName}`];
|
|
3758
3783
|
const queryClient = BaseQueryClient.getQueryClient();
|
|
3759
3784
|
const easClient = BaseEasClient.getEasClient();
|
|
3760
|
-
const cachedResults = queryClient.getQueryData(queryKey);
|
|
3761
|
-
logger$d(`[allItemsActors] [fetchSeeds] cachedResults ${Date.now()}`, cachedResults);
|
|
3762
3785
|
const results = await queryClient.fetchQuery({
|
|
3763
3786
|
queryKey,
|
|
3764
3787
|
queryFn: async () => easClient.request(GET_SEEDS, queryVariables),
|
|
@@ -4173,7 +4196,7 @@ const preparePublishRequestData = fromCallback(({ sendBack, input: { context } }
|
|
|
4173
4196
|
}
|
|
4174
4197
|
const versionSchemaUid = modelsRows[0].schemaUid;
|
|
4175
4198
|
await item.getEditedProperties();
|
|
4176
|
-
await getModelSchemas();
|
|
4199
|
+
const { modelSchemas, schemaStringToModelRecord } = await getModelSchemas();
|
|
4177
4200
|
// const dataEncoder = new SchemaEncoder(modelProperty.schemaDefinition,)
|
|
4178
4201
|
// const encodedData = dataEncoder.encodeData(data,)
|
|
4179
4202
|
//
|
|
@@ -4207,13 +4230,13 @@ const preparePublishRequestData = fromCallback(({ sendBack, input: { context } }
|
|
|
4207
4230
|
});
|
|
4208
4231
|
});
|
|
4209
4232
|
|
|
4210
|
-
const logger$
|
|
4233
|
+
const logger$b = debug('app:services:publish:actors:upload');
|
|
4211
4234
|
const upload = fromCallback(({ sendBack, input: { context } }) => {
|
|
4212
4235
|
const { localId } = context;
|
|
4213
4236
|
const _upload = async () => {
|
|
4214
4237
|
const item = await BaseItem.find({ seedLocalId: localId });
|
|
4215
4238
|
if (!item) {
|
|
4216
|
-
logger$
|
|
4239
|
+
logger$b('no item with localId', localId);
|
|
4217
4240
|
return false;
|
|
4218
4241
|
}
|
|
4219
4242
|
const editedProperties = await item.getEditedProperties();
|
|
@@ -4231,7 +4254,7 @@ const upload = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
4231
4254
|
editedProperty.propertyDef.refValueType === 'ImageSrc') {
|
|
4232
4255
|
const context = editedProperty.getService().getSnapshot().context;
|
|
4233
4256
|
const imageSeedId = context.propertyValue;
|
|
4234
|
-
getCorrectId(imageSeedId);
|
|
4257
|
+
const { localId, uid } = getCorrectId(imageSeedId);
|
|
4235
4258
|
}
|
|
4236
4259
|
if (editedProperty.propertyDef.storageType === 'ItemStorage' &&
|
|
4237
4260
|
editedProperty.propertyDef.localStorageDir) ;
|
|
@@ -4334,7 +4357,7 @@ const savePublishService = fromCallback(({ sendBack, input: { event, context } }
|
|
|
4334
4357
|
});
|
|
4335
4358
|
|
|
4336
4359
|
const { UNINITIALIZED, INITIALIZING, INITIALIZED, PUBLISHING_ITEM, ADDING_MODELS_TO_DB, } = GlobalState;
|
|
4337
|
-
createBrowserInspector({
|
|
4360
|
+
const { inspect } = createBrowserInspector({
|
|
4338
4361
|
autoStart: false,
|
|
4339
4362
|
});
|
|
4340
4363
|
const globalMachine = setup({
|
|
@@ -5144,7 +5167,7 @@ const getSeedData = async ({ seedLocalId, seedUid }) => {
|
|
|
5144
5167
|
return rows[0];
|
|
5145
5168
|
};
|
|
5146
5169
|
|
|
5147
|
-
const logger$
|
|
5170
|
+
const logger$a = debug('app:db:read:getItemData');
|
|
5148
5171
|
const getItemData = async ({ modelName, seedLocalId, seedUid, }) => {
|
|
5149
5172
|
if (!seedLocalId && !seedUid) {
|
|
5150
5173
|
throw new Error('[db/queries] [getItem] no seedLocalId or seedUid');
|
|
@@ -5152,7 +5175,7 @@ const getItemData = async ({ modelName, seedLocalId, seedUid, }) => {
|
|
|
5152
5175
|
if (seedUid && !seedLocalId) {
|
|
5153
5176
|
const seedData = await getSeedData({ seedUid });
|
|
5154
5177
|
if (!seedData) {
|
|
5155
|
-
logger$
|
|
5178
|
+
logger$a('[db/queries] [getItem] no seedData seedUid', seedUid);
|
|
5156
5179
|
return;
|
|
5157
5180
|
}
|
|
5158
5181
|
seedLocalId = seedData.localId;
|
|
@@ -5187,7 +5210,7 @@ const getItemData = async ({ modelName, seedLocalId, seedUid, }) => {
|
|
|
5187
5210
|
.orderBy(sql.raw('COALESCE(attestation_created_at, created_at) DESC'))
|
|
5188
5211
|
.groupBy(seeds.localId);
|
|
5189
5212
|
if (!itemDataRows || itemDataRows.length === 0) {
|
|
5190
|
-
logger$
|
|
5213
|
+
logger$a('[db/queries] [getItemDataFromDb] no itemDataRows');
|
|
5191
5214
|
return;
|
|
5192
5215
|
}
|
|
5193
5216
|
let itemData = itemDataRows[0];
|
|
@@ -5416,7 +5439,7 @@ const getRelationValueData = async (propertyValue) => {
|
|
|
5416
5439
|
return rows[0];
|
|
5417
5440
|
};
|
|
5418
5441
|
|
|
5419
|
-
const logger$
|
|
5442
|
+
const logger$9 = debug('app:property:actors:resolveRelatedValue');
|
|
5420
5443
|
const storageTransactionIdToContentUrl = new Map();
|
|
5421
5444
|
const refResolvedValueToContentUrl = new Map();
|
|
5422
5445
|
const seedUidToContentUrl = new Map();
|
|
@@ -5431,7 +5454,7 @@ const resolveRelatedValue = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
5431
5454
|
parsedValue = JSON.parse(propertyValue);
|
|
5432
5455
|
}
|
|
5433
5456
|
catch (error) {
|
|
5434
|
-
logger$
|
|
5457
|
+
logger$9(`${propertyName} value is not a JSON string.`);
|
|
5435
5458
|
}
|
|
5436
5459
|
if (!parsedValue && seedUidToContentUrl.has(propertyValue)) {
|
|
5437
5460
|
const contentUrl = seedUidToContentUrl.get(propertyValue);
|
|
@@ -5447,11 +5470,11 @@ const resolveRelatedValue = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
5447
5470
|
}
|
|
5448
5471
|
if (Array.isArray(propertyValue)) {
|
|
5449
5472
|
// TODO: Handle array of seedUids
|
|
5450
|
-
logger$
|
|
5473
|
+
logger$9(`${propertyName} value is an array of seedUids`);
|
|
5451
5474
|
return;
|
|
5452
5475
|
}
|
|
5453
5476
|
if (Array.isArray(parsedValue)) {
|
|
5454
|
-
logger$
|
|
5477
|
+
logger$9(`${propertyName} value is a stringified array of seedUids`);
|
|
5455
5478
|
return;
|
|
5456
5479
|
}
|
|
5457
5480
|
const storageTransactionId = await getStorageTransactionIdForSeedUid(propertyValue);
|
|
@@ -5891,7 +5914,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
5891
5914
|
if (propertyRecordSchema &&
|
|
5892
5915
|
propertyRecordSchema.storageType &&
|
|
5893
5916
|
propertyRecordSchema.storageType === 'ItemStorage') {
|
|
5894
|
-
const { Item } = await import('./index-
|
|
5917
|
+
const { Item } = await import('./index-CQ9FS10O.js');
|
|
5895
5918
|
const item = await Item.find({
|
|
5896
5919
|
seedLocalId,
|
|
5897
5920
|
modelName,
|
|
@@ -5936,10 +5959,10 @@ const getVersionData = async ({ localId, seedLocalId, uid, }) => {
|
|
|
5936
5959
|
return queryRows[0];
|
|
5937
5960
|
};
|
|
5938
5961
|
|
|
5939
|
-
const logger$
|
|
5962
|
+
const logger$8 = debug('app:write:updateItemPropertyValue');
|
|
5940
5963
|
const updateItemPropertyValue = async ({ localId, propertyName, newValue, seedUid, seedLocalId, modelName, refSeedType, refResolvedValue, refResolvedDisplayValue, versionLocalId, versionUid, schemaUid, localStorageDir, }) => {
|
|
5941
5964
|
if (!localId && !seedLocalId) {
|
|
5942
|
-
logger$
|
|
5965
|
+
logger$8(`[db/write] [updateItemPropertyValue] no propertyLocalId or seedLocalId for property: ${propertyName}`);
|
|
5943
5966
|
return;
|
|
5944
5967
|
}
|
|
5945
5968
|
let safeNewValue = newValue;
|
|
@@ -5977,7 +6000,7 @@ const updateItemPropertyValue = async ({ localId, propertyName, newValue, seedUi
|
|
|
5977
6000
|
modelType === modelName?.toLowerCase() &&
|
|
5978
6001
|
refSeedTypeFromDb === refSeedType &&
|
|
5979
6002
|
refResolvedValueFromDb === refResolvedValue) {
|
|
5980
|
-
logger$
|
|
6003
|
+
logger$8(`[db/write] [updateItemPropertyValue] value is the same as most recent record for property: ${propertyNameFromDb}`);
|
|
5981
6004
|
return;
|
|
5982
6005
|
}
|
|
5983
6006
|
// This means we already have a local-only record so we should just update that one
|
|
@@ -6363,11 +6386,7 @@ const saveImageSrc = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
6363
6386
|
refSeedType: 'image',
|
|
6364
6387
|
refResolvedDisplayValue,
|
|
6365
6388
|
refResolvedValue: fileName,
|
|
6366
|
-
|
|
6367
|
-
refSchemaUid: imageSchemaUid,
|
|
6368
|
-
localStorageDir: '/images',
|
|
6369
|
-
easDataType: 'bytes32',
|
|
6370
|
-
});
|
|
6389
|
+
localStorageDir: '/images'});
|
|
6371
6390
|
}
|
|
6372
6391
|
sendBack({
|
|
6373
6392
|
type: 'updateContext',
|
|
@@ -6795,7 +6814,7 @@ const getPropertyData$1 = async ({ propertyName, seedLocalId, seedUid, }) => {
|
|
|
6795
6814
|
};
|
|
6796
6815
|
|
|
6797
6816
|
var _a$1;
|
|
6798
|
-
const logger$
|
|
6817
|
+
const logger$7 = debug('app:property:class');
|
|
6799
6818
|
class BaseItemProperty {
|
|
6800
6819
|
constructor(initialValues) {
|
|
6801
6820
|
this._isRelation = false;
|
|
@@ -6842,7 +6861,7 @@ class BaseItemProperty {
|
|
|
6842
6861
|
serviceInput.propertyValue = JSON.parse(propertyValue);
|
|
6843
6862
|
}
|
|
6844
6863
|
catch (e) {
|
|
6845
|
-
logger$
|
|
6864
|
+
logger$7('List property value is not JSON', e);
|
|
6846
6865
|
}
|
|
6847
6866
|
}
|
|
6848
6867
|
const propertyNameSingular = pluralize(propertyName, 1);
|
|
@@ -6889,7 +6908,7 @@ class BaseItemProperty {
|
|
|
6889
6908
|
}
|
|
6890
6909
|
}
|
|
6891
6910
|
catch (e) {
|
|
6892
|
-
logger$
|
|
6911
|
+
logger$7(`[ItemProperty] [${context.seedLocalId}] [${context.propertyName}] [storageType] error`, e);
|
|
6893
6912
|
renderValue = 'No file found';
|
|
6894
6913
|
}
|
|
6895
6914
|
}
|
|
@@ -7134,7 +7153,7 @@ const getSegmentedItemProperties = (item) => {
|
|
|
7134
7153
|
};
|
|
7135
7154
|
};
|
|
7136
7155
|
|
|
7137
|
-
const logger$
|
|
7156
|
+
const logger$6 = debug('app:item:getPublishUploads');
|
|
7138
7157
|
const prepareArweaveTransaction = async (data, contentHash) => {
|
|
7139
7158
|
const transactionData = {
|
|
7140
7159
|
data,
|
|
@@ -7142,8 +7161,8 @@ const prepareArweaveTransaction = async (data, contentHash) => {
|
|
|
7142
7161
|
};
|
|
7143
7162
|
const tx = await getArweave().createTransaction(transactionData);
|
|
7144
7163
|
if (contentHash) {
|
|
7145
|
-
logger$
|
|
7146
|
-
logger$
|
|
7164
|
+
logger$6('contentHash', contentHash);
|
|
7165
|
+
logger$6('adding content hash tag to tx.id:', tx.id);
|
|
7147
7166
|
tx.addTag('Content-SHA-256', contentHash);
|
|
7148
7167
|
}
|
|
7149
7168
|
return tx;
|
|
@@ -7841,7 +7860,7 @@ const initItem = async () => {
|
|
|
7841
7860
|
Item$2 = (await Promise.resolve().then(function () { return Item$1; })).Item;
|
|
7842
7861
|
}
|
|
7843
7862
|
if (!isBrowser()) {
|
|
7844
|
-
Item$2 = (await import('./Item-
|
|
7863
|
+
Item$2 = (await import('./Item-B5Tz-Y7t.js')).Item;
|
|
7845
7864
|
}
|
|
7846
7865
|
};
|
|
7847
7866
|
|
|
@@ -7851,17 +7870,17 @@ const initItemProperty = async () => {
|
|
|
7851
7870
|
ItemProperty$2 = (await Promise.resolve().then(function () { return ItemProperty$1; })).ItemProperty;
|
|
7852
7871
|
}
|
|
7853
7872
|
if (!isBrowser()) {
|
|
7854
|
-
ItemProperty$2 = (await import('./ItemProperty-
|
|
7873
|
+
ItemProperty$2 = (await import('./ItemProperty-DBV0Iib_.js')).ItemProperty;
|
|
7855
7874
|
}
|
|
7856
7875
|
};
|
|
7857
7876
|
|
|
7858
7877
|
let Db;
|
|
7859
7878
|
const initDb = async () => {
|
|
7860
7879
|
if (isBrowser()) {
|
|
7861
|
-
Db = (await import('./Db-
|
|
7880
|
+
Db = (await import('./Db-CESKJH-G.js')).Db;
|
|
7862
7881
|
}
|
|
7863
7882
|
if (!isBrowser()) {
|
|
7864
|
-
Db = (await import('./Db-
|
|
7883
|
+
Db = (await import('./Db-DiTPSbQ8.js')).Db;
|
|
7865
7884
|
}
|
|
7866
7885
|
// TODO: Add config for React Native
|
|
7867
7886
|
};
|
|
@@ -7878,7 +7897,7 @@ var Item$1 = /*#__PURE__*/Object.freeze({
|
|
|
7878
7897
|
Item: Item
|
|
7879
7898
|
});
|
|
7880
7899
|
|
|
7881
|
-
const logger$
|
|
7900
|
+
const logger$5 = debug('app:react:services');
|
|
7882
7901
|
const finalStrings = ['idle', 'ready', 'done', 'success', 'initialized'];
|
|
7883
7902
|
const getServiceName = (service) => {
|
|
7884
7903
|
let name = 'actor';
|
|
@@ -7925,7 +7944,7 @@ const getServiceUniqueKey = (service) => {
|
|
|
7925
7944
|
snapshot = service.getSnapshot();
|
|
7926
7945
|
}
|
|
7927
7946
|
catch (error) {
|
|
7928
|
-
logger$
|
|
7947
|
+
logger$5('Error:', error);
|
|
7929
7948
|
return uniqueKey;
|
|
7930
7949
|
}
|
|
7931
7950
|
if (snapshot) {
|
|
@@ -8154,7 +8173,7 @@ const useGlobalServiceStatus = () => {
|
|
|
8154
8173
|
};
|
|
8155
8174
|
};
|
|
8156
8175
|
|
|
8157
|
-
const logger$
|
|
8176
|
+
const logger$4 = debug('app:react:item');
|
|
8158
8177
|
const useItem = ({ modelName, seedLocalId, seedUid }) => {
|
|
8159
8178
|
// const [itemSubscription, setItemSubscription] = useState<
|
|
8160
8179
|
// Subscription | undefined
|
|
@@ -8231,7 +8250,7 @@ const useItem = ({ modelName, seedLocalId, seedUid }) => {
|
|
|
8231
8250
|
seedUid,
|
|
8232
8251
|
});
|
|
8233
8252
|
if (!foundItem) {
|
|
8234
|
-
logger$
|
|
8253
|
+
logger$4('[useItem] [getItemFromDb] no item found', modelName, seedLocalId);
|
|
8235
8254
|
isReadingDb.current = false;
|
|
8236
8255
|
return;
|
|
8237
8256
|
}
|
|
@@ -8253,7 +8272,7 @@ const useItem = ({ modelName, seedLocalId, seedUid }) => {
|
|
|
8253
8272
|
const subscription = item.subscribe(async (_) => {
|
|
8254
8273
|
const newItem = await Item.find({ modelName, seedLocalId, seedUid });
|
|
8255
8274
|
if (!newItem) {
|
|
8256
|
-
logger$
|
|
8275
|
+
logger$4('[useItem] [itemSubscription] no item found', modelName, seedLocalId);
|
|
8257
8276
|
return;
|
|
8258
8277
|
}
|
|
8259
8278
|
updateItem(newItem);
|
|
@@ -8412,7 +8431,7 @@ var ItemProperty$1 = /*#__PURE__*/Object.freeze({
|
|
|
8412
8431
|
ItemProperty: ItemProperty
|
|
8413
8432
|
});
|
|
8414
8433
|
|
|
8415
|
-
const logger$
|
|
8434
|
+
const logger$3 = debug('app:react:property');
|
|
8416
8435
|
const useItemProperty = (props = {
|
|
8417
8436
|
propertyName: '',
|
|
8418
8437
|
seedLocalId: '',
|
|
@@ -8443,7 +8462,7 @@ const useItemProperty = (props = {
|
|
|
8443
8462
|
seedUid,
|
|
8444
8463
|
});
|
|
8445
8464
|
if (!foundProperty) {
|
|
8446
|
-
logger$
|
|
8465
|
+
logger$3(`[useItemPropertyTest] [readFromDb] no property found for Item.${seedLocalId}.${propertyName}`);
|
|
8447
8466
|
isReadingDb.current = false;
|
|
8448
8467
|
return;
|
|
8449
8468
|
}
|
|
@@ -8480,7 +8499,7 @@ const useItemProperty = (props = {
|
|
|
8480
8499
|
};
|
|
8481
8500
|
const useItemProperties = (item) => {
|
|
8482
8501
|
const [propertyObj, setPropertyObj] = useImmer({});
|
|
8483
|
-
useState(false);
|
|
8502
|
+
const [isListening, setIsListening] = useState(false);
|
|
8484
8503
|
const updatePropertyObj = useCallback((event) => {
|
|
8485
8504
|
if (!item) {
|
|
8486
8505
|
console.error('[XXXXXX] [updatePropertyObj] no item when expected');
|
|
@@ -8617,10 +8636,10 @@ const withSeed = (config, webpack, isServer) => {
|
|
|
8617
8636
|
|
|
8618
8637
|
const initEasClient = async () => {
|
|
8619
8638
|
if (isBrowser()) {
|
|
8620
|
-
(await import('./EasClient-
|
|
8639
|
+
(await import('./EasClient-BesHK2bO.js')).EasClient;
|
|
8621
8640
|
}
|
|
8622
8641
|
if (!isBrowser()) {
|
|
8623
|
-
(await import('./EasClient-
|
|
8642
|
+
(await import('./EasClient-Cop6WtWl.js')).EasClient;
|
|
8624
8643
|
}
|
|
8625
8644
|
};
|
|
8626
8645
|
|
|
@@ -8629,23 +8648,23 @@ const initFileManager = async () => {
|
|
|
8629
8648
|
(await Promise.resolve().then(function () { return FileManager$1; })).FileManager;
|
|
8630
8649
|
}
|
|
8631
8650
|
if (!isBrowser()) {
|
|
8632
|
-
(await import('./FileManager-
|
|
8651
|
+
(await import('./FileManager-DTzkncLh.js')).FileManager;
|
|
8633
8652
|
}
|
|
8634
8653
|
};
|
|
8635
8654
|
|
|
8636
8655
|
const initQueryClient = async () => {
|
|
8637
8656
|
if (isBrowser()) {
|
|
8638
|
-
(await import('./QueryClient-
|
|
8657
|
+
(await import('./QueryClient-BnwbHtqe.js')).QueryClient;
|
|
8639
8658
|
}
|
|
8640
8659
|
if (!isBrowser()) {
|
|
8641
|
-
(await import('./QueryClient-
|
|
8660
|
+
(await import('./QueryClient-C7a0NHCt.js')).QueryClient;
|
|
8642
8661
|
}
|
|
8643
8662
|
};
|
|
8644
8663
|
|
|
8645
|
-
const logger$
|
|
8664
|
+
const logger$2 = debug('app:services:events');
|
|
8646
8665
|
const handleServiceSaveState = (event) => {
|
|
8647
8666
|
const { state, serviceId } = event;
|
|
8648
|
-
logger$
|
|
8667
|
+
logger$2(`[browser] [service.saveState.request] serviceId: ${serviceId}`);
|
|
8649
8668
|
localStorage.setItem(`seed_sdk_service_${serviceId}`, JSON.stringify(state));
|
|
8650
8669
|
};
|
|
8651
8670
|
const setupServicesEventHandlers = () => {
|
|
@@ -8671,9 +8690,9 @@ const setupServiceHandlers = () => {
|
|
|
8671
8690
|
eventEmitter.addListener('service.save', saveServiceHandler);
|
|
8672
8691
|
};
|
|
8673
8692
|
|
|
8674
|
-
const logger$
|
|
8693
|
+
const logger$1 = debug('app:ClientManager:initialize');
|
|
8675
8694
|
const initialize = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
8676
|
-
logger$
|
|
8695
|
+
logger$1('initialize from ClientManager');
|
|
8677
8696
|
const { isInitialized } = context;
|
|
8678
8697
|
const { options, } = event;
|
|
8679
8698
|
if (isInitialized) {
|
|
@@ -8689,7 +8708,8 @@ const initialize = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
8689
8708
|
await initQueryClient();
|
|
8690
8709
|
await initFileManager();
|
|
8691
8710
|
await initDb();
|
|
8692
|
-
const {
|
|
8711
|
+
const { models, endpoints, arweaveDomain, } = config;
|
|
8712
|
+
const { files } = endpoints;
|
|
8693
8713
|
if (arweaveDomain) {
|
|
8694
8714
|
setArweaveDomain(arweaveDomain);
|
|
8695
8715
|
}
|
|
@@ -8706,18 +8726,24 @@ const initialize = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
8706
8726
|
if (!areFsListenersReady()) {
|
|
8707
8727
|
console.error('fs listeners not ready during init');
|
|
8708
8728
|
}
|
|
8729
|
+
const globalService = getGlobalService();
|
|
8709
8730
|
globalService.send({
|
|
8710
8731
|
type: 'init',
|
|
8711
8732
|
endpoints,
|
|
8712
8733
|
models,
|
|
8713
8734
|
addresses,
|
|
8714
8735
|
arweaveDomain,
|
|
8715
|
-
filesDir,
|
|
8736
|
+
filesDir: files,
|
|
8716
8737
|
});
|
|
8717
|
-
const { models: internalModels } = await import('./seed.schema.config-
|
|
8738
|
+
const { models: internalModels } = await import('./seed.schema.config-DDzfQguf.js');
|
|
8718
8739
|
for (const [key, value] of Object.entries(internalModels)) {
|
|
8719
8740
|
setModel(key, value);
|
|
8720
8741
|
}
|
|
8742
|
+
await waitFor(globalService, (snapshot) => {
|
|
8743
|
+
logger$1('snapshot.value', snapshot.value);
|
|
8744
|
+
return snapshot.value === GlobalState.INITIALIZED;
|
|
8745
|
+
});
|
|
8746
|
+
logger$1('globalService initialized');
|
|
8721
8747
|
};
|
|
8722
8748
|
_initialize().then(() => {
|
|
8723
8749
|
sendBack({ type: 'initialized' });
|
|
@@ -8725,8 +8751,7 @@ const initialize = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
8725
8751
|
});
|
|
8726
8752
|
|
|
8727
8753
|
debug('app:client:writeToDb');
|
|
8728
|
-
const saveAppState = fromCallback(({ sendBack, input: {
|
|
8729
|
-
const { key, value } = event;
|
|
8754
|
+
const saveAppState = fromCallback(({ sendBack, input: { key, value } }) => {
|
|
8730
8755
|
const _saveAppState = async () => {
|
|
8731
8756
|
const { BaseDb } = await Promise.resolve().then(function () { return BaseDb$1; });
|
|
8732
8757
|
if (!BaseDb) {
|
|
@@ -8736,6 +8761,7 @@ const saveAppState = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
8736
8761
|
if (!appDb) {
|
|
8737
8762
|
throw new Error('App DB not found');
|
|
8738
8763
|
}
|
|
8764
|
+
console.log(`key: ${key} value: ${value}`);
|
|
8739
8765
|
appDb.insert(appState)
|
|
8740
8766
|
.values({
|
|
8741
8767
|
key: key,
|
|
@@ -8751,6 +8777,8 @@ const saveAppState = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
8751
8777
|
_saveAppState().then(() => {
|
|
8752
8778
|
sendBack({
|
|
8753
8779
|
type: 'saveAppStateSuccess',
|
|
8780
|
+
key,
|
|
8781
|
+
value,
|
|
8754
8782
|
});
|
|
8755
8783
|
});
|
|
8756
8784
|
});
|
|
@@ -8765,6 +8793,7 @@ const setAddresses = assign(({ event, spawn }) => {
|
|
|
8765
8793
|
});
|
|
8766
8794
|
return {
|
|
8767
8795
|
addresses,
|
|
8796
|
+
isSaving: true,
|
|
8768
8797
|
};
|
|
8769
8798
|
});
|
|
8770
8799
|
|
|
@@ -8803,101 +8832,77 @@ const clientManagerMachine = setup({
|
|
|
8803
8832
|
},
|
|
8804
8833
|
},
|
|
8805
8834
|
idle: {
|
|
8835
|
+
entry: assign({
|
|
8836
|
+
isInitialized: true,
|
|
8837
|
+
}),
|
|
8806
8838
|
on: {
|
|
8807
|
-
|
|
8808
|
-
actions: assign({
|
|
8809
|
-
|
|
8839
|
+
saveAppStateSuccess: {
|
|
8840
|
+
actions: assign(({ event }) => {
|
|
8841
|
+
const { key, value } = event;
|
|
8842
|
+
return {
|
|
8843
|
+
isSaving: false
|
|
8844
|
+
};
|
|
8810
8845
|
}),
|
|
8811
8846
|
},
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8847
|
+
setAddresses: {
|
|
8848
|
+
actions: ['setAddresses'],
|
|
8849
|
+
},
|
|
8815
8850
|
},
|
|
8816
8851
|
},
|
|
8817
8852
|
},
|
|
8818
8853
|
});
|
|
8819
8854
|
|
|
8820
|
-
const logger
|
|
8855
|
+
const logger = debug('app:client');
|
|
8821
8856
|
const clientManager = createActor(clientManagerMachine, {
|
|
8822
8857
|
input: {
|
|
8823
8858
|
isInitialized: false,
|
|
8824
8859
|
}
|
|
8825
8860
|
});
|
|
8826
8861
|
const subscription = clientManager.subscribe((snapshot) => {
|
|
8827
|
-
|
|
8862
|
+
logger('ClientManager snapshot.value:', snapshot.value);
|
|
8863
|
+
logger('ClientManager snapshot.context.isInitialized:', snapshot.context.isInitialized);
|
|
8828
8864
|
});
|
|
8829
8865
|
clientManager.start();
|
|
8866
|
+
const ensureInitialized = () => {
|
|
8867
|
+
if (!clientManager.getSnapshot().context.isInitialized) {
|
|
8868
|
+
throw new Error(CLIENT_NOT_INITIALIZED);
|
|
8869
|
+
}
|
|
8870
|
+
};
|
|
8830
8871
|
const ClientManager = {
|
|
8831
|
-
|
|
8872
|
+
isInitialized: () => clientManager.getSnapshot().context.isInitialized,
|
|
8873
|
+
getService: () => {
|
|
8874
|
+
ensureInitialized();
|
|
8875
|
+
return clientManager;
|
|
8876
|
+
},
|
|
8832
8877
|
init: async (options) => {
|
|
8833
|
-
clientManager.send({ type: 'init', options
|
|
8834
|
-
await waitFor(clientManager, (snapshot) => snapshot.
|
|
8878
|
+
clientManager.send({ type: 'init', options });
|
|
8879
|
+
await waitFor(clientManager, (snapshot) => snapshot.context.isInitialized);
|
|
8835
8880
|
},
|
|
8836
8881
|
setAddresses: async (addresses) => {
|
|
8837
|
-
|
|
8882
|
+
ensureInitialized();
|
|
8883
|
+
logger('setAddresses', addresses);
|
|
8838
8884
|
clientManager.send({ type: 'setAddresses', addresses });
|
|
8839
8885
|
await waitFor(clientManager, (snapshot) => !snapshot.context.isSaving);
|
|
8840
|
-
logger
|
|
8886
|
+
logger('setAddresses success', addresses);
|
|
8887
|
+
},
|
|
8888
|
+
getAddresses: async () => {
|
|
8889
|
+
ensureInitialized();
|
|
8890
|
+
const db = await BaseDb.getAppDb();
|
|
8891
|
+
const results = await db.select().from(appState).where(eq(appState.key, 'addresses'));
|
|
8892
|
+
return JSON.parse(results[0]?.value);
|
|
8893
|
+
},
|
|
8894
|
+
stop: () => {
|
|
8895
|
+
ensureInitialized();
|
|
8896
|
+
clientManager.stop();
|
|
8841
8897
|
},
|
|
8842
|
-
stop: () => clientManager.stop(),
|
|
8843
8898
|
unload: () => {
|
|
8899
|
+
ensureInitialized();
|
|
8844
8900
|
clientManager.stop();
|
|
8845
8901
|
subscription.unsubscribe();
|
|
8846
8902
|
},
|
|
8847
8903
|
};
|
|
8848
8904
|
|
|
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
8905
|
enableMapSet();
|
|
8901
8906
|
|
|
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,
|
|
8903
|
-
//# sourceMappingURL=index-
|
|
8907
|
+
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 };
|
|
8908
|
+
//# sourceMappingURL=index-BHGJ-Es9.js.map
|