@seedprotocol/sdk 0.1.40 → 0.1.41

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.
@@ -984,7 +984,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
984
984
  renderValue: refResolvedDisplayValue,
985
985
  });
986
986
  if (propertyNameFromDb === 'storageTransactionId') {
987
- const { Item } = yield import('./index-BbMR37dq.js');
987
+ const { Item } = yield import('./index-ClKB3DC-.js');
988
988
  const item = yield Item.find({
989
989
  seedLocalId,
990
990
  modelName: itemModelName,
@@ -1660,6 +1660,7 @@ class ItemProperty {
1660
1660
  if (!propertyName) {
1661
1661
  throw new Error(`Property name not provided`);
1662
1662
  }
1663
+ this._lastRenderedValue = propertyValue;
1663
1664
  const serviceInput = {
1664
1665
  propertyValue,
1665
1666
  seedUid,
@@ -1746,7 +1747,12 @@ class ItemProperty {
1746
1747
  }
1747
1748
  if (skipTransform && !this._alias) ;
1748
1749
  this._subject.next(renderValue);
1749
- // this._lastRenderedValue = renderValue
1750
+ if (context.seedLocalId) {
1751
+ eventEmitter.emit(`item.${itemModelName}.${context.seedLocalId}.update`);
1752
+ }
1753
+ if (context.seedUid) {
1754
+ eventEmitter.emit(`item.${itemModelName}.${context.seedUid}.update`);
1755
+ }
1750
1756
  });
1751
1757
  this._service.start();
1752
1758
  }
@@ -4362,7 +4368,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
4362
4368
  if (!models$1) {
4363
4369
  return;
4364
4370
  }
4365
- const { models: SeedModels } = yield import('./seed.schema.config-cLeX7Oyb.js');
4371
+ const { models: SeedModels } = yield import('./seed.schema.config-CtfrG9dk.js');
4366
4372
  const allModels = Object.assign(Object.assign({}, SeedModels), models$1);
4367
4373
  let hasModelsInDb = false;
4368
4374
  const schemaDefsByModelName = new Map();
@@ -5838,11 +5844,11 @@ const globalMachine = setup({
5838
5844
  (_a) => __awaiter(void 0, [_a], void 0, function* ({ context }) {
5839
5845
  let SeedClass;
5840
5846
  if (context.environment === 'node') {
5841
- const { SeedNode } = yield import('./seed-C8LDZtnw.js');
5847
+ const { SeedNode } = yield import('./seed-Bj6wb5Jr.js');
5842
5848
  SeedClass = SeedNode;
5843
5849
  }
5844
5850
  else {
5845
- const { SeedBrowser } = yield import('./seed-Dm6nbxxo.js');
5851
+ const { SeedBrowser } = yield import('./seed-BpJsAlzT.js');
5846
5852
  SeedClass = SeedBrowser;
5847
5853
  }
5848
5854
  return SeedClass;
@@ -6099,13 +6105,19 @@ const useGlobalServiceStatus = () => {
6099
6105
 
6100
6106
  const logger$2 = debug('app:react:item');
6101
6107
  const useItem = ({ modelName, seedLocalId, seedUid }) => {
6102
- const [item, setItem] = useImmer(undefined);
6108
+ const [itemData, setItemData] = useImmer({});
6109
+ const [item, setItem] = useState();
6103
6110
  const [itemSubscription, setItemSubscription] = useState();
6104
6111
  const { status, internalStatus } = useGlobalServiceStatus();
6105
6112
  const isReadingDb = useRef(false);
6106
6113
  const itemStatus = useSelector(item === null || item === void 0 ? void 0 : item.getService(), (snapshot) => snapshot === null || snapshot === void 0 ? void 0 : snapshot.value);
6107
6114
  const updateItem = useCallback((newItem) => {
6108
- setItem(() => newItem);
6115
+ setItemData((draft) => {
6116
+ Object.keys(newItem.properties).forEach((propertyName) => {
6117
+ const value = newItem[propertyName];
6118
+ draft[propertyName] = value;
6119
+ });
6120
+ });
6109
6121
  }, []);
6110
6122
  const readFromDb = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
6111
6123
  if (isReadingDb.current ||
@@ -6123,12 +6135,17 @@ const useItem = ({ modelName, seedLocalId, seedUid }) => {
6123
6135
  logger$2('[useItem] [getItemFromDb] no item found', modelName, seedLocalId);
6124
6136
  return;
6125
6137
  }
6138
+ setItem(foundItem);
6126
6139
  updateItem(foundItem);
6127
6140
  isReadingDb.current = false;
6128
6141
  }), [internalStatus]);
6142
+ const listenerRef = useRef(readFromDb);
6143
+ useEffect(() => {
6144
+ listenerRef.current = readFromDb;
6145
+ }, [readFromDb]);
6129
6146
  useEffect(() => {
6130
6147
  if (internalStatus === 'ready') {
6131
- readFromDb();
6148
+ listenerRef.current();
6132
6149
  }
6133
6150
  }, [internalStatus, status]);
6134
6151
  useEffect(() => {
@@ -6139,7 +6156,8 @@ const useItem = ({ modelName, seedLocalId, seedUid }) => {
6139
6156
  logger$2('[useItem] [itemSubscription] no item found', modelName, seedLocalId);
6140
6157
  return;
6141
6158
  }
6142
- setItem(() => newItem);
6159
+ updateItem(newItem);
6160
+ setItem(newItem);
6143
6161
  }));
6144
6162
  setItemSubscription(subscription);
6145
6163
  }
@@ -6149,13 +6167,16 @@ const useItem = ({ modelName, seedLocalId, seedUid }) => {
6149
6167
  }, [item, itemSubscription]);
6150
6168
  useEffect(() => {
6151
6169
  const seedId = seedUid || seedLocalId;
6152
- eventEmitter.addListener(`item.${modelName}.${seedId}.update`, readFromDb);
6170
+ eventEmitter.addListener(`item.${modelName}.${seedId}.update`, () => {
6171
+ listenerRef.current();
6172
+ });
6153
6173
  return () => {
6154
6174
  eventEmitter.removeListener(`item.${modelName}.${seedId}.update`, readFromDb);
6155
6175
  };
6156
6176
  }, []);
6157
6177
  return {
6158
6178
  item,
6179
+ itemData,
6159
6180
  itemStatus,
6160
6181
  };
6161
6182
  };
@@ -6266,9 +6287,10 @@ const useDeleteItem = () => {
6266
6287
 
6267
6288
  const logger$1 = debug('app:react:property');
6268
6289
  const useItemProperty = ({ propertyName, seedLocalId, seedUid, }) => {
6269
- const [property, setProperty] = useImmer(undefined);
6290
+ const [property, setProperty] = useState();
6270
6291
  const [isReadingFromDb, setIsReadingFromDb] = useState(false);
6271
6292
  const [isInitialized, setIsInitialized] = useState(false);
6293
+ // const isDbReady = useMemo(() => useIsDbReady(), [])
6272
6294
  const { internalStatus } = useGlobalServiceStatus();
6273
6295
  const value = useSelector(property === null || property === void 0 ? void 0 : property.getService(), (snapshot) => {
6274
6296
  if (!snapshot || !snapshot.context) {
@@ -6283,8 +6305,7 @@ const useItemProperty = ({ propertyName, seedLocalId, seedUid, }) => {
6283
6305
  // }
6284
6306
  // }, [property, value])
6285
6307
  const readFromDb = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
6286
- if (!isAppDbReady() ||
6287
- internalStatus !== 'ready' ||
6308
+ if (internalStatus !== 'ready' ||
6288
6309
  isReadingFromDb ||
6289
6310
  (!seedLocalId && !seedUid)) {
6290
6311
  return;
@@ -6295,6 +6316,7 @@ const useItemProperty = ({ propertyName, seedLocalId, seedUid, }) => {
6295
6316
  seedLocalId,
6296
6317
  seedUid,
6297
6318
  });
6319
+ console.log(`[useItemPropertyTest] [readFromDb] ${propertyName} foundProperty`, foundProperty);
6298
6320
  setIsReadingFromDb(false);
6299
6321
  if (!foundProperty) {
6300
6322
  logger$1(`[useItemPropertyTest] [readFromDb] no property found for Item.${seedLocalId}.${propertyName}`);
@@ -6303,15 +6325,34 @@ const useItemProperty = ({ propertyName, seedLocalId, seedUid, }) => {
6303
6325
  if (foundProperty.status === 'waitingForDb') {
6304
6326
  foundProperty.getService().send({ type: 'waitForDbSuccess' });
6305
6327
  }
6306
- setProperty(() => foundProperty);
6328
+ setProperty(foundProperty);
6307
6329
  setIsInitialized(true);
6308
6330
  }), [internalStatus, isReadingFromDb]);
6331
+ // let count = 0
6332
+ //
6333
+ // const refresh = useCallback(() => {
6334
+ // count++
6335
+ // console.log('[useItemPropertyTest] [refresh] property', property)
6336
+ // }, [property])
6309
6337
  useEffect(() => {
6310
6338
  if (internalStatus === 'ready') {
6311
- console.log('[useItemPropertyTest] [useEffect] internalStatus is ready');
6312
6339
  readFromDb();
6313
6340
  }
6314
6341
  }, [internalStatus]);
6342
+ // useEffect(() => {
6343
+ // eventEmitter.addListener(
6344
+ // `property.${seedUid || seedLocalId}.${propertyName}.update`,
6345
+ // (event) => {
6346
+ // refresh()
6347
+ // },
6348
+ // )
6349
+ //
6350
+ // return () => {
6351
+ // eventEmitter.removeListener(
6352
+ // `property.${seedUid || seedLocalId}.${propertyName}.update`,
6353
+ // )
6354
+ // }
6355
+ // }, [])
6315
6356
  return {
6316
6357
  property,
6317
6358
  isInitialized,
@@ -6643,7 +6684,7 @@ const client = {
6643
6684
  console.error('fs listeners not ready during init');
6644
6685
  }
6645
6686
  globalService.send({ type: 'init', endpoints, models, addresses });
6646
- import('./seed.schema.config-cLeX7Oyb.js').then(({ models }) => {
6687
+ import('./seed.schema.config-CtfrG9dk.js').then(({ models }) => {
6647
6688
  for (const [key, value] of Object.entries(models)) {
6648
6689
  setModel(key, value);
6649
6690
  }
@@ -6700,4 +6741,4 @@ if (isNode()) {
6700
6741
  }
6701
6742
 
6702
6743
  export { CHILD_SNAPSHOT as C, 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, internalMachine as h, itemMachineSingle as i, isNode as j, isBrowser as k, isReactNative as l, ImageSrc as m, ItemProperty as n, useItem as o, useItemProperties as p, useCreateItem as q, useItemProperty as r, useDeleteItem as s, useGlobalServiceStatus as t, useItems as u, useServices as v, withSeed as w, getGlobalService as x, client as y, getCorrectId as z };
6703
- //# sourceMappingURL=index-B6e21b8Z.js.map
6744
+ //# sourceMappingURL=index-BvH0sjnH.js.map