@seedprotocol/sdk 0.1.17 → 0.1.18

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/bin.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { _ as __awaiter, D as DB_NAME_SDK_CONFIG, o as models, S as SCHEMA_NJK, p as SCHEMA_TS, q as SDK_DB_CONFIG, r as SEED_DB_CONFIG, A as APP_DB_CONFIG, s as addModelsToInternalDb } from './events-CRCYmF7M.js';
2
+ import { _ as __awaiter, D as DB_NAME_SDK_CONFIG, o as models, S as SCHEMA_NJK, p as SCHEMA_TS, q as SDK_DB_CONFIG, r as SEED_DB_CONFIG, A as APP_DB_CONFIG, s as addModelsToInternalDb } from './events-So24__c6.js';
3
3
  import path from 'path';
4
4
  import fs from 'fs';
5
5
  import { exec as exec$1 } from 'child_process';
@@ -17,7 +17,7 @@ import { camelCase, snakeCase } from 'lodash-es';
17
17
  import * as nunjucks from 'nunjucks';
18
18
  import Database from 'better-sqlite3';
19
19
  import { drizzle } from 'drizzle-orm/better-sqlite3';
20
- import './seed.schema.config-GKCk8sOV.js';
20
+ import './seed.schema.config-DYkIbj49.js';
21
21
  import { defineConfig } from 'drizzle-kit';
22
22
  import dotenv from 'dotenv';
23
23
  import 'xstate';
@@ -214,14 +214,14 @@ const getSqlite = async () => {
214
214
  }
215
215
  };
216
216
 
217
- const logger$k = debug('app:db:actors');
217
+ const logger$l = debug('app:db:actors');
218
218
  let seedDb;
219
219
  let appDb;
220
220
  let sdkConfigDb;
221
221
  let sqliteWasmClient;
222
222
  const checkStatus = fromCallback(({ sendBack, input: { context } }) => {
223
223
  const { dbName, dirName } = context;
224
- logger$k('[db/actors] checkStatus context', context);
224
+ logger$l('[db/actors] checkStatus context', context);
225
225
  const pathToDir = `${BROWSER_FS_TOP_DIR}/${dirName}`;
226
226
  const pathToDbDir = `${pathToDir}/db`;
227
227
  const pathToDb = `${pathToDbDir}/${dbName}.sqlite3`;
@@ -252,7 +252,7 @@ const checkStatus = fromCallback(({ sendBack, input: { context } }) => {
252
252
  });
253
253
  });
254
254
  const connectToDb = fromCallback(({ sendBack, input: { context } }) => {
255
- logger$k('[db/actors] connectToDb context', context);
255
+ logger$l('[db/actors] connectToDb context', context);
256
256
  const { dbName, pathToDir } = context;
257
257
  let isConnecting = false;
258
258
  let dbId;
@@ -267,16 +267,16 @@ const connectToDb = fromCallback(({ sendBack, input: { context } }) => {
267
267
  }
268
268
  //@ts-ignore
269
269
  response = yield sqliteWasmClient('config-get', {});
270
- logger$k(response);
271
- logger$k('Running SQLite3 version', response.result.version.libVersion);
270
+ logger$l(response);
271
+ logger$l('Running SQLite3 version', response.result.version.libVersion);
272
272
  //@ts-ignore
273
273
  response = yield sqliteWasmClient('open', {
274
274
  filename: `file:${pathToDir}/db/${dbName}.sqlite3?vfs=opfs`,
275
275
  });
276
- logger$k(response);
276
+ logger$l(response);
277
277
  dbId = response.dbId;
278
278
  // logger(`dbId: ${dbId}`)
279
- logger$k('OPFS is available, created persisted database at', response.result.filename.replace(/^file:(.*?)\?vfs=opfs$/, '$1'));
279
+ logger$l('OPFS is available, created persisted database at', response.result.filename.replace(/^file:(.*?)\?vfs=opfs$/, '$1'));
280
280
  });
281
281
  const interval = setInterval(() => {
282
282
  // TODO: Add a timeout
@@ -396,7 +396,7 @@ const dbExec = (dbId_1, params_1, sql_1, dbName_1, ...args_1) => __awaiter(void
396
396
  });
397
397
  const migrate = fromCallback(({ sendBack, input: { context } }) => {
398
398
  const { pathToDbDir, dirName, dbId, dbName } = context;
399
- logger$k('[db/actors] migrate context', context);
399
+ logger$l('[db/actors] migrate context', context);
400
400
  const schemaGlobString = `${BROWSER_FS_TOP_DIR}/${dirName}/schema/*`;
401
401
  const isSeedDb = dbName === DB_NAME_SEED;
402
402
  const isAppDb = dbName === DB_NAME_APP;
@@ -676,7 +676,7 @@ const initialize$3 = fromCallback(({ sendBack, input: { context } }) => {
676
676
  }
677
677
  });
678
678
 
679
- const logger$j = debug('app:shared:helpers');
679
+ const logger$k = debug('app:shared:helpers');
680
680
  const { alphanumeric } = nanoIdDictionary;
681
681
  const generateId = () => {
682
682
  return customAlphabet(alphanumeric, 10)();
@@ -739,7 +739,7 @@ const convertTxIdToImageSrc = (txId) => __awaiter(void 0, void 0, void 0, functi
739
739
  const imageFilePath = `/files/images/${txId}`;
740
740
  const fileExists = yield fs.promises.exists(imageFilePath);
741
741
  if (!fileExists) {
742
- logger$j(`[ItemView] [updateImageSrc] ${imageFilePath} does not exist`);
742
+ logger$k(`[ItemView] [updateImageSrc] ${imageFilePath} does not exist`);
743
743
  return;
744
744
  }
745
745
  const uint = yield fs.promises.readFile(imageFilePath);
@@ -1518,7 +1518,7 @@ const getAddressesFromDb = () => __awaiter(void 0, void 0, void 0, function* ()
1518
1518
  return JSON.parse(addressArrayString);
1519
1519
  });
1520
1520
 
1521
- const logger$i = debug('app:property:actors:hydrateFromDb');
1521
+ const logger$j = debug('app:property:actors:hydrateFromDb');
1522
1522
  const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
1523
1523
  const { seedUid, seedLocalId, propertyName: propertyNameRaw, propertyValue, propertyRecordSchema, itemModelName, } = context;
1524
1524
  let propertyName = propertyNameRaw;
@@ -1586,23 +1586,23 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
1586
1586
  const firstRow = rows[0];
1587
1587
  const { localId, uid, propertyName: propertyNameFromDb, propertyValue: propertyValueFromDb, seedLocalId: seedLocalIdFromDb, seedUid: seedUidFromDb, schemaUid: schemaUidFromDb, refResolvedValue, refResolvedDisplayValue, } = firstRow;
1588
1588
  if (propertyName && !propertyNameFromDb) {
1589
- logger$i(`Property name from code is ${propertyName} but has not value in db ${propertyNameFromDb} for Property.${localId}`);
1589
+ logger$j(`Property name from code is ${propertyName} but has not value in db ${propertyNameFromDb} for Property.${localId}`);
1590
1590
  }
1591
1591
  if (propertyName &&
1592
1592
  propertyNameFromDb &&
1593
1593
  !propertyNameFromDb.includes(propertyName) &&
1594
1594
  !propertyName.includes(propertyNameFromDb) &&
1595
1595
  propertyNameFromDb !== propertyName) {
1596
- logger$i(`Property name from db ${propertyNameFromDb} does not match property name ${propertyName} for Property.${localId}`);
1596
+ logger$j(`Property name from db ${propertyNameFromDb} does not match property name ${propertyName} for Property.${localId}`);
1597
1597
  }
1598
1598
  if (propertyValue && propertyValueFromDb !== propertyValue) {
1599
- logger$i(`Property value from db ${propertyValueFromDb} does not match property value ${propertyValue} for Property.${localId}`);
1599
+ logger$j(`Property value from db ${propertyValueFromDb} does not match property value ${propertyValue} for Property.${localId}`);
1600
1600
  }
1601
1601
  if (seedLocalIdFromDb !== seedLocalId) {
1602
- logger$i(`Seed local id from db ${seedLocalIdFromDb} does not match seed local id ${seedLocalId} for Property.${localId}`);
1602
+ logger$j(`Seed local id from db ${seedLocalIdFromDb} does not match seed local id ${seedLocalId} for Property.${localId}`);
1603
1603
  }
1604
1604
  if (seedUidFromDb !== seedUid) {
1605
- logger$i(`Seed uid from db ${seedUidFromDb} does not match seed uid ${seedUid} for Property.${localId}`);
1605
+ logger$j(`Seed uid from db ${seedUidFromDb} does not match seed uid ${seedUid} for Property.${localId}`);
1606
1606
  }
1607
1607
  sendBack({
1608
1608
  type: 'updateContext',
@@ -1617,7 +1617,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
1617
1617
  renderValue: refResolvedDisplayValue,
1618
1618
  });
1619
1619
  if (propertyNameFromDb === 'storageTransactionId') {
1620
- const { Item } = yield import('./index-DR_FgAUY.js');
1620
+ const { Item } = yield import('./index-Cgo0-c0n.js');
1621
1621
  const item = yield Item.find({
1622
1622
  seedLocalId,
1623
1623
  modelName: itemModelName,
@@ -1635,7 +1635,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
1635
1635
  const renderValue = yield fs.promises
1636
1636
  .readFile(htmlFilePath, 'utf8')
1637
1637
  .catch((error) => {
1638
- logger$i('Error reading html file', error);
1638
+ logger$j('Error reading html file', error);
1639
1639
  });
1640
1640
  property
1641
1641
  .getService()
@@ -1716,7 +1716,7 @@ const getVersionData = (_a) => __awaiter(void 0, [_a], void 0, function* ({ seed
1716
1716
 
1717
1717
  const eventEmitter = new EventEmitter();
1718
1718
 
1719
- const logger$h = debug('app:write');
1719
+ const logger$i = debug('app:write');
1720
1720
  const sendItemUpdateEvent = ({ modelName, seedLocalId, seedUid }) => {
1721
1721
  if (!modelName || (!seedLocalId && !seedUid)) {
1722
1722
  return;
@@ -1794,7 +1794,7 @@ const deleteItem = (_a) => __awaiter(void 0, [_a], void 0, function* ({ seedLoca
1794
1794
  });
1795
1795
  const updateItemPropertyValue = (_a) => __awaiter(void 0, [_a], void 0, function* ({ propertyLocalId, propertyName, newValue, seedUid, seedLocalId, modelName, refSeedType, refResolvedValue, refResolvedDisplayValue, versionLocalId, versionUid, schemaUid, }) {
1796
1796
  if (!propertyLocalId && !seedLocalId) {
1797
- logger$h(`[db/write] [updateItemPropertyValue] no propertyLocalId or seedLocalId for property: ${propertyName}`);
1797
+ logger$i(`[db/write] [updateItemPropertyValue] no propertyLocalId or seedLocalId for property: ${propertyName}`);
1798
1798
  return;
1799
1799
  }
1800
1800
  let safeNewValue = newValue;
@@ -1833,7 +1833,7 @@ const updateItemPropertyValue = (_a) => __awaiter(void 0, [_a], void 0, function
1833
1833
  const schemaUid = mostRecentRecord[9];
1834
1834
  const easDataType = mostRecentRecord[10];
1835
1835
  if (propertyValueFromDb === newValue) {
1836
- logger$h(`[db/write] [updateItemPropertyValue] value is the same as most recent record for property: ${propertyNameFromDb}`);
1836
+ logger$i(`[db/write] [updateItemPropertyValue] value is the same as most recent record for property: ${propertyNameFromDb}`);
1837
1837
  return;
1838
1838
  }
1839
1839
  // This means we already have a local-only record so we should just update that one
@@ -2248,7 +2248,7 @@ const setModel = (modelName, model) => {
2248
2248
  };
2249
2249
 
2250
2250
  var _a$1;
2251
- const logger$g = debug('app:property:class');
2251
+ const logger$h = debug('app:property:class');
2252
2252
  const namesThatEndWithId = [];
2253
2253
  class ItemProperty {
2254
2254
  // private constructor(localIdOrUid) {
@@ -2296,7 +2296,7 @@ class ItemProperty {
2296
2296
  serviceInput.propertyValue = JSON.parse(propertyValue);
2297
2297
  }
2298
2298
  catch (e) {
2299
- logger$g('List property value is not JSON', e);
2299
+ logger$h('List property value is not JSON', e);
2300
2300
  }
2301
2301
  }
2302
2302
  const propertyNameSingular = pluralize(propertyName, 1);
@@ -2358,7 +2358,7 @@ class ItemProperty {
2358
2358
  this._service.start();
2359
2359
  }
2360
2360
  _updateResponseListener(event) {
2361
- logger$g(`[ItemProperty] [_updateResponseListener] [${this.itemModelName}.${this.seedLocalId}] ${this.propertyName} event`, event);
2361
+ logger$h(`[ItemProperty] [_updateResponseListener] [${this.itemModelName}.${this.seedLocalId}] ${this.propertyName} event`, event);
2362
2362
  }
2363
2363
  static create(props) {
2364
2364
  const { propertyName, seedLocalId, uid } = props;
@@ -2494,7 +2494,7 @@ class ItemProperty {
2494
2494
  }
2495
2495
  unload() {
2496
2496
  this._service.stop();
2497
- logger$g(`[XXXXXX] [ItemProperty] [${this.seedLocalId}] [unload] removing listener`, this._updateResponseEvent);
2497
+ logger$h(`[XXXXXX] [ItemProperty] [${this.seedLocalId}] [unload] removing listener`, this._updateResponseEvent);
2498
2498
  eventEmitter.removeListener(this._updateResponseEvent, this._updateResponseListener);
2499
2499
  }
2500
2500
  }
@@ -3783,7 +3783,7 @@ const getPropertiesForSeed = (seedLocalId, seedUid) => __awaiter(void 0, void 0,
3783
3783
  return propertiesData;
3784
3784
  });
3785
3785
 
3786
- const logger$f = debug('app:db:queries:getItem');
3786
+ const logger$g = debug('app:db:queries:getItem');
3787
3787
  const getItemDataFromDb = (_a) => __awaiter(void 0, [_a], void 0, function* ({ modelName, seedLocalId, seedUid, }) {
3788
3788
  if (!seedLocalId && !seedUid) {
3789
3789
  throw new Error('[db/queries] [getItem] no seedLocalId or seedUid');
@@ -3791,7 +3791,7 @@ const getItemDataFromDb = (_a) => __awaiter(void 0, [_a], void 0, function* ({ m
3791
3791
  if (seedUid && !seedLocalId) {
3792
3792
  const seedData = yield getSeedData({ seedUid });
3793
3793
  if (!seedData) {
3794
- logger$f('[db/queries] [getItem] no seedData seedUid', seedUid);
3794
+ logger$g('[db/queries] [getItem] no seedData seedUid', seedUid);
3795
3795
  return;
3796
3796
  }
3797
3797
  seedLocalId = seedData.localId;
@@ -4219,7 +4219,7 @@ const fetchDbData = fromCallback(({ sendBack, input: { context } }) => {
4219
4219
  return () => { };
4220
4220
  });
4221
4221
 
4222
- const logger$e = debug('app:allItemsActors:fetchSeeds');
4222
+ const logger$f = debug('app:allItemsActors:fetchSeeds');
4223
4223
  const fetchSeeds = fromCallback(({ sendBack, input: { context } }) => {
4224
4224
  const { queryVariables, modelName } = context;
4225
4225
  if (!queryVariables) {
@@ -4229,7 +4229,7 @@ const fetchSeeds = fromCallback(({ sendBack, input: { context } }) => {
4229
4229
  const _fetchSeeds = () => __awaiter(void 0, void 0, void 0, function* () {
4230
4230
  const queryKey = [`getSeeds${modelName}`];
4231
4231
  const cachedResults = queryClient.getQueryData(queryKey);
4232
- logger$e(`[allItemsActors] [fetchSeeds] cachedResults ${Date.now()}`, cachedResults);
4232
+ logger$f(`[allItemsActors] [fetchSeeds] cachedResults ${Date.now()}`, cachedResults);
4233
4233
  const results = yield queryClient.fetchQuery({
4234
4234
  queryKey,
4235
4235
  queryFn: () => __awaiter(void 0, void 0, void 0, function* () { return easClient.request(GET_SEEDS, queryVariables); }),
@@ -4800,7 +4800,7 @@ const getArweave = () => {
4800
4800
  });
4801
4801
  };
4802
4802
 
4803
- const logger$d = debug('app:react:db');
4803
+ const logger$e = debug('app:react:db');
4804
4804
  const useDbsAreReady = () => {
4805
4805
  const [dbsAreReady, setDbsAreReady] = useState(false);
4806
4806
  const update = useCallback(() => {
@@ -4816,7 +4816,7 @@ const useDbsAreReady = () => {
4816
4816
  const globalService = getGlobalService();
4817
4817
  const internalService = globalService.getSnapshot().context.internalService;
4818
4818
  if (!internalService) {
4819
- logger$d('[useDbsAreReady] [useEffect] no internalService');
4819
+ logger$e('[useDbsAreReady] [useEffect] no internalService');
4820
4820
  globalSubscription = globalService.subscribe(({ context }) => {
4821
4821
  if (!internalSubscription && context && context.internalService) {
4822
4822
  globalSubscription === null || globalSubscription === void 0 ? void 0 : globalSubscription.unsubscribe();
@@ -4857,6 +4857,7 @@ const useDbsAreReady = () => {
4857
4857
  };
4858
4858
  };
4859
4859
 
4860
+ const logger$d = debug('app:react:services');
4860
4861
  const finalStrings = ['idle', 'ready', 'done', 'success'];
4861
4862
  const getServiceName = (service) => {
4862
4863
  let name = 'actor';
@@ -4900,8 +4901,8 @@ const getServiceUniqueKey = (service) => {
4900
4901
  snapshot = service.getSnapshot();
4901
4902
  }
4902
4903
  catch (error) {
4903
- console.error('Error:', error);
4904
- return;
4904
+ logger$d('Error:', error);
4905
+ return uniqueKey;
4905
4906
  }
4906
4907
  if (snapshot) {
4907
4908
  const context = snapshot.context;
@@ -5162,7 +5163,7 @@ const useItemProperty = (propertyName, seedLocalId) => {
5162
5163
  const [property, setProperty] = useImmer(undefined);
5163
5164
  const [isReadingFromDb, setIsReadingFromDb] = useState(false);
5164
5165
  const [isInitialized, setIsInitialized] = useState(false);
5165
- const dbsAreReady = useDbsAreReady();
5166
+ const { dbsAreReady } = useDbsAreReady();
5166
5167
  const value = useSelector(property === null || property === void 0 ? void 0 : property.getService(), (snapshot) => {
5167
5168
  if (!snapshot || !snapshot.context) {
5168
5169
  return;
@@ -5243,7 +5244,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
5243
5244
  if (!models$1) {
5244
5245
  return;
5245
5246
  }
5246
- const { models: SeedModels } = yield import('./seed.schema.config-GKCk8sOV.js');
5247
+ const { models: SeedModels } = yield import('./seed.schema.config-DYkIbj49.js');
5247
5248
  const allModels = Object.assign(Object.assign({}, SeedModels), models$1);
5248
5249
  let hasModelsInDb = false;
5249
5250
  const schemaDefsByModelName = new Map();
@@ -6548,11 +6549,11 @@ const globalMachine = setup({
6548
6549
  (_a) => __awaiter(void 0, [_a], void 0, function* ({ context }) {
6549
6550
  let SeedClass;
6550
6551
  if (context.environment === 'node') {
6551
- const { SeedNode } = yield import('./seed-BJPS_-pY.js');
6552
+ const { SeedNode } = yield import('./seed-DGCfCUOn.js');
6552
6553
  SeedClass = SeedNode;
6553
6554
  }
6554
6555
  else {
6555
- const { SeedBrowser } = yield import('./seed-CjMH4SeR.js');
6556
+ const { SeedBrowser } = yield import('./seed-BgRaREFr.js');
6556
6557
  SeedClass = SeedBrowser;
6557
6558
  }
6558
6559
  return SeedClass;
@@ -6657,4 +6658,4 @@ const setupServicesEventHandlers = () => {
6657
6658
  };
6658
6659
 
6659
6660
  export { useDeleteItem as $, APP_DB_CONFIG as A, setupFsListeners as B, CHILD_SNAPSHOT as C, DB_NAME_SDK_CONFIG as D, setupAllItemsEventHandlers as E, setupServicesEventHandlers as F, GET_SCHEMAS as G, globalService as H, Item as I, Json as J, getModel as K, List as L, Model as M, getModels as N, getModelNames as O, Property as P, areFsListenersReady as Q, Relation as R, SCHEMA_NJK as S, Text as T, ItemProperty as U, useItems as V, useItem as W, useItemProperties as X, useCreateItem as Y, useItemProperty as Z, __awaiter as _, GET_SEEDS as a, useServices as a0, getGlobalService as a1, getCorrectId as a2, GET_SEED_IDS as b, GET_STORAGE_TRANSACTION_ID as c, GET_VERSIONS as d, GET_PROPERTIES as e, GET_ALL_PROPERTIES_FOR_ALL_VERSIONS as f, itemMachineAll as g, internalMachine as h, itemMachineSingle as i, isNode as j, isBrowser as k, isReactNative as l, __decorate as m, __metadata as n, models as o, SCHEMA_TS as p, SDK_DB_CONFIG as q, SEED_DB_CONFIG as r, addModelsToInternalDb as s, ImageSrc as t, createNewMetadataFromExistingRecord as u, generateId as v, eventEmitter as w, getDb as x, DB_NAME_APP as y, setModel as z };
6660
- //# sourceMappingURL=events-CRCYmF7M.js.map
6661
+ //# sourceMappingURL=events-So24__c6.js.map