@seedprotocol/sdk 0.1.59 → 0.1.60

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.
@@ -989,7 +989,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
989
989
  if (propertyRecordSchema &&
990
990
  propertyRecordSchema.storageType &&
991
991
  propertyRecordSchema.storageType === 'ItemStorage') {
992
- const { Item } = yield import('./index-C_WqqX4v.js');
992
+ const { Item } = yield import('./index-BE0vEP7p.js');
993
993
  const item = yield Item.find({
994
994
  seedLocalId,
995
995
  modelName: itemModelName,
@@ -2877,7 +2877,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
2877
2877
  if (!models$1) {
2878
2878
  return;
2879
2879
  }
2880
- const { models: SeedModels } = yield import('./seed.schema.config-BH9Kq1yX.js');
2880
+ const { models: SeedModels } = yield import('./seed.schema.config-CFOCE176.js');
2881
2881
  const allModels = Object.assign(Object.assign({}, SeedModels), models$1);
2882
2882
  let hasModelsInDb = false;
2883
2883
  const schemaDefsByModelName = new Map();
@@ -6334,16 +6334,6 @@ const getServiceUniqueKey = (service) => {
6334
6334
  }
6335
6335
  return uniqueKey;
6336
6336
  };
6337
- const useIsDbReady = () => {
6338
- const [isDbReady, setIsDbReady] = useState(false);
6339
- const { internalStatus } = useGlobalServiceStatus();
6340
- useEffect(() => {
6341
- if (internalStatus === 'ready') {
6342
- setIsDbReady(true);
6343
- }
6344
- }, [internalStatus]);
6345
- return isDbReady;
6346
- };
6347
6337
  const useServices = () => {
6348
6338
  const [actors, setActors] = useState([]);
6349
6339
  const [percentComplete, setPercentComplete] = useState(5);
@@ -6510,35 +6500,39 @@ const useItem = ({ modelName, seedLocalId, seedUid }) => {
6510
6500
  };
6511
6501
  const useItems = ({ modelName, deleted }) => {
6512
6502
  const [items, setItems] = useImmer([]);
6513
- const [isReadingDb, setIsReadingDb] = useState(false);
6514
- const [isInitialized, setIsInitialized] = useState(false);
6515
- const isDbReady = useIsDbReady();
6503
+ const { status, internalStatus } = useGlobalServiceStatus();
6516
6504
  const modelNameRef = useRef(modelName);
6517
- const readFromDb = useCallback((event) => __awaiter(void 0, void 0, void 0, function* () {
6518
- if (!event ||
6519
- !event.modelName ||
6520
- event.modelName !== modelNameRef.current ||
6521
- isReadingDb) {
6505
+ const isReadingDb = useRef(false);
6506
+ const readFromDb = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
6507
+ if (isReadingDb.current || internalStatus !== 'ready') {
6522
6508
  return;
6523
6509
  }
6524
- setIsReadingDb(true);
6510
+ isReadingDb.current = true;
6525
6511
  const allItems = yield Item.all(modelNameRef.current, deleted);
6512
+ setItems(() => []);
6526
6513
  setItems(() => allItems);
6527
- setIsReadingDb(false);
6528
- }), [modelName, isReadingDb]);
6514
+ isReadingDb.current = false;
6515
+ }), [internalStatus]);
6516
+ const listenerRef = useRef(readFromDb);
6529
6517
  useEffect(() => {
6530
- if (isDbReady && !isInitialized) {
6531
- const _fetchItems = () => __awaiter(void 0, void 0, void 0, function* () {
6532
- yield readFromDb({ modelName });
6533
- setIsInitialized(true);
6534
- });
6535
- _fetchItems();
6518
+ listenerRef.current = readFromDb;
6519
+ }, [readFromDb]);
6520
+ useEffect(() => {
6521
+ if (internalStatus === 'ready') {
6522
+ listenerRef.current();
6536
6523
  }
6537
- }, [isInitialized, isDbReady]);
6524
+ }, [internalStatus, status]);
6538
6525
  useEffect(() => {
6539
- eventEmitter.addListener('item.requestAll', readFromDb);
6526
+ eventEmitter.addListener('item.requestAll', (event) => {
6527
+ if (!event ||
6528
+ !event.modelName ||
6529
+ event.modelName !== modelNameRef.current) {
6530
+ return;
6531
+ }
6532
+ listenerRef.current();
6533
+ });
6540
6534
  return () => {
6541
- eventEmitter.removeListener('item.requestAll');
6535
+ eventEmitter.removeListener('item.requestAll', readFromDb);
6542
6536
  };
6543
6537
  }, []);
6544
6538
  return {
@@ -6548,7 +6542,6 @@ const useItems = ({ modelName, deleted }) => {
6548
6542
  item.createdAt,
6549
6543
  ], ['desc']).slice(0, 10),
6550
6544
  isReadingDb,
6551
- isInitialized,
6552
6545
  };
6553
6546
  };
6554
6547
  const useItemIsReady = () => {
@@ -6774,7 +6767,7 @@ const client = {
6774
6767
  console.error('fs listeners not ready during init');
6775
6768
  }
6776
6769
  globalService.send({ type: 'init', endpoints, models, addresses });
6777
- import('./seed.schema.config-BH9Kq1yX.js').then(({ models }) => {
6770
+ import('./seed.schema.config-CFOCE176.js').then(({ models }) => {
6778
6771
  for (const [key, value] of Object.entries(models)) {
6779
6772
  setModel(key, value);
6780
6773
  }
@@ -7347,4 +7340,4 @@ if (isNode()) {
7347
7340
  }
7348
7341
 
7349
7342
  export { GET_SCHEMAS as G, Item as I, Json as J, List as L, Model as M, Property as P, Relation as R, Text as T, GET_SEEDS as a, 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, ImageSrc as h, itemMachineSingle as i, ItemProperty as j, useItem as k, useItemProperties as l, useCreateItem as m, useItemProperty as n, useDeleteItem as o, useGlobalServiceStatus as p, useServices as q, getGlobalService as r, client as s, getCorrectId as t, useItems as u, withSeed as w };
7350
- //# sourceMappingURL=index-RCrXtjiO.js.map
7343
+ //# sourceMappingURL=index-4a6qGsTX.js.map