@seedprotocol/sdk 0.1.63 → 0.1.65

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.
@@ -1,4 +1,4 @@
1
- export { f as GET_ALL_PROPERTIES_FOR_ALL_VERSIONS, e as GET_PROPERTIES, G as GET_SCHEMAS, a as GET_SEEDS, b as GET_SEED_IDS, c as GET_STORAGE_TRANSACTION_ID, d as GET_VERSIONS, I as Item, g as itemMachineAll, i as itemMachineSingle } from './index-DCYwncVx.js';
1
+ export { f as GET_ALL_PROPERTIES_FOR_ALL_VERSIONS, e as GET_PROPERTIES, G as GET_SCHEMAS, a as GET_SEEDS, b as GET_SEED_IDS, c as GET_STORAGE_TRANSACTION_ID, d as GET_VERSIONS, I as Item, g as itemMachineAll, i as itemMachineSingle } from './index-UWk43qGs.js';
2
2
  import './constants-BLctWkrn.js';
3
3
  import 'path';
4
4
  import 'reflect-metadata';
@@ -27,4 +27,4 @@ import '@zenfs/dom';
27
27
  import 'arweave';
28
28
  import 'use-immer';
29
29
  import '@xstate/react';
30
- //# sourceMappingURL=index-C351N4sQ.js.map
30
+ //# sourceMappingURL=index-D2LDMjA3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-D2LDMjA3.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -3,7 +3,7 @@ import path, { basename } from 'path';
3
3
  import 'reflect-metadata';
4
4
  import { Type } from '@sinclair/typebox';
5
5
  import { fromCallback, assign, createActor, waitFor, setup, emit, raise } from 'xstate';
6
- import { sql, relations, and, eq, max, or, count, isNotNull, isNull, inArray, like, getTableColumns, gt } from 'drizzle-orm';
6
+ import { sql, relations, and, eq, max, or, count, isNotNull, isNull, gt, inArray, like, getTableColumns } from 'drizzle-orm';
7
7
  import { fs, configureSingle } from '@zenfs/core';
8
8
  import 'dayjs';
9
9
  import { customAlphabet } from 'nanoid';
@@ -950,7 +950,9 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
950
950
  return;
951
951
  }
952
952
  const firstRow = rows[0];
953
- const { localId, uid, propertyName: propertyNameFromDb, propertyValue: propertyValueFromDb, seedLocalId: seedLocalIdFromDb, seedUid: seedUidFromDb, schemaUid: schemaUidFromDb, versionLocalId: versionLocalIdFromDb, versionUid: versionUidFromDb, refValueType, refResolvedValue, refResolvedDisplayValue, localStorageDir, } = firstRow;
953
+ const { localId, uid, propertyName: propertyNameFromDb, propertyValue: propertyValueFromDb, seedLocalId: seedLocalIdFromDb, seedUid: seedUidFromDb, schemaUid: schemaUidFromDb, versionLocalId: versionLocalIdFromDb, versionUid: versionUidFromDb, refValueType, refResolvedValue, localStorageDir, } = firstRow;
954
+ let { refResolvedDisplayValue } = firstRow;
955
+ let propertyValueProcessed = propertyValueFromDb;
954
956
  if (propertyName && !propertyNameFromDb) {
955
957
  logger$m(`Property name from code is ${propertyName} but has not value in db ${propertyNameFromDb} for Property.${localId}`);
956
958
  }
@@ -970,11 +972,43 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
970
972
  if (seedUidFromDb !== seedUid) {
971
973
  logger$m(`Seed uid from db ${seedUidFromDb} does not match seed uid ${seedUid} for Property.${localId}`);
972
974
  }
975
+ if (refResolvedValue &&
976
+ refResolvedDisplayValue &&
977
+ refResolvedDisplayValue.includes('http')) {
978
+ let urlNeedsToBeRefreshed = false;
979
+ try {
980
+ const response = yield fetch(refResolvedDisplayValue, {
981
+ method: 'HEAD',
982
+ });
983
+ // Check if the status is in the 200-299 range
984
+ if (!response.ok) {
985
+ urlNeedsToBeRefreshed = true;
986
+ }
987
+ }
988
+ catch (error) {
989
+ urlNeedsToBeRefreshed = true;
990
+ }
991
+ if (urlNeedsToBeRefreshed) {
992
+ const filePath = `/files/${localStorageDir}/${refResolvedValue}`;
993
+ const fileExists = yield fs.promises.exists(filePath);
994
+ if (fileExists) {
995
+ const fileContents = yield fs.promises.readFile(filePath);
996
+ const fileHandler = new File([fileContents], refResolvedValue);
997
+ refResolvedDisplayValue = URL.createObjectURL(fileHandler);
998
+ }
999
+ }
1000
+ }
1001
+ if (propertyRecordSchema &&
1002
+ propertyRecordSchema.dataType === 'List' &&
1003
+ propertyRecordSchema.ref &&
1004
+ typeof propertyValueFromDb === 'string') {
1005
+ propertyValueProcessed = propertyValueFromDb.split(',');
1006
+ }
973
1007
  sendBack({
974
1008
  type: 'updateContext',
975
1009
  localId,
976
1010
  uid,
977
- propertyValue: propertyValueFromDb,
1011
+ propertyValue: propertyValueProcessed,
978
1012
  seedLocalId: seedLocalIdFromDb,
979
1013
  seedUid: seedUidFromDb,
980
1014
  versionLocalId: versionLocalIdFromDb,
@@ -989,7 +1023,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
989
1023
  if (propertyRecordSchema &&
990
1024
  propertyRecordSchema.storageType &&
991
1025
  propertyRecordSchema.storageType === 'ItemStorage') {
992
- const { Item } = yield import('./index-C351N4sQ.js');
1026
+ const { Item } = yield import('./index-D2LDMjA3.js');
993
1027
  const item = yield Item.find({
994
1028
  seedLocalId,
995
1029
  modelName: itemModelName,
@@ -1688,7 +1722,7 @@ const getItemsData = (_a) => __awaiter(void 0, [_a], void 0, function* ({ modelN
1688
1722
  })
1689
1723
  .from(seeds)
1690
1724
  .leftJoin(versionData, eq(seeds.localId, versionData.seedLocalId))
1691
- .where(and(...conditions))
1725
+ .where(and(gt(versionData.versionsCount, 0), ...conditions))
1692
1726
  .orderBy(sql.raw('COALESCE(attestation_created_at, created_at) DESC'))
1693
1727
  .groupBy(seeds.localId);
1694
1728
  const itemsData = (yield query);
@@ -2877,7 +2911,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
2877
2911
  if (!models$1) {
2878
2912
  return;
2879
2913
  }
2880
- const { models: SeedModels } = yield import('./seed.schema.config-8V0ae_un.js');
2914
+ const { models: SeedModels } = yield import('./seed.schema.config-DA3JNobc.js');
2881
2915
  const allModels = Object.assign(Object.assign({}, SeedModels), models$1);
2882
2916
  let hasModelsInDb = false;
2883
2917
  const schemaDefsByModelName = new Map();
@@ -6541,7 +6575,6 @@ const useItem = ({ modelName, seedLocalId, seedUid }) => {
6541
6575
  eventEmitter.removeListener(`item.${modelName}.${seedId}.update`);
6542
6576
  };
6543
6577
  }, []);
6544
- console.log(`returning item ${seedLocalId}`, item);
6545
6578
  return {
6546
6579
  item,
6547
6580
  itemData,
@@ -6641,10 +6674,9 @@ const useCreateItem = (modelName) => {
6641
6674
  const logger$1 = debug('app:react:property');
6642
6675
  const useItemProperty = ({ propertyName, seedLocalId, seedUid, }) => {
6643
6676
  const [property, setProperty] = useState();
6644
- const [isReadingFromDb, setIsReadingFromDb] = useState(false);
6645
6677
  const [isInitialized, setIsInitialized] = useState(false);
6646
- // const isDbReady = useMemo(() => useIsDbReady(), [])
6647
6678
  const { internalStatus } = useGlobalServiceStatus();
6679
+ const isReadingDb = useRef(false);
6648
6680
  const value = useSelector(property === null || property === void 0 ? void 0 : property.getService(), (snapshot) => {
6649
6681
  if (!snapshot || !snapshot.context) {
6650
6682
  return;
@@ -6652,26 +6684,21 @@ const useItemProperty = ({ propertyName, seedLocalId, seedUid, }) => {
6652
6684
  return snapshot.context.renderValue || snapshot.context.propertyValue;
6653
6685
  });
6654
6686
  const status = useSelector(property === null || property === void 0 ? void 0 : property.getService(), (snapshot) => snapshot === null || snapshot === void 0 ? void 0 : snapshot.value);
6655
- // useEffect(() => {
6656
- // if (property && property.value !== value) {
6657
- // readFromDb()
6658
- // }
6659
- // }, [property, value])
6660
6687
  const readFromDb = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
6661
6688
  if (internalStatus !== 'ready' ||
6662
- isReadingFromDb ||
6689
+ isReadingDb.current ||
6663
6690
  (!seedLocalId && !seedUid)) {
6664
6691
  return;
6665
6692
  }
6666
- setIsReadingFromDb(true);
6693
+ isReadingDb.current = true;
6667
6694
  const foundProperty = yield ItemProperty.find({
6668
6695
  propertyName,
6669
6696
  seedLocalId,
6670
6697
  seedUid,
6671
6698
  });
6672
- setIsReadingFromDb(false);
6673
6699
  if (!foundProperty) {
6674
6700
  logger$1(`[useItemPropertyTest] [readFromDb] no property found for Item.${seedLocalId}.${propertyName}`);
6701
+ isReadingDb.current = false;
6675
6702
  return;
6676
6703
  }
6677
6704
  if (foundProperty.status === 'waitingForDb') {
@@ -6679,36 +6706,28 @@ const useItemProperty = ({ propertyName, seedLocalId, seedUid, }) => {
6679
6706
  }
6680
6707
  setProperty(foundProperty);
6681
6708
  setIsInitialized(true);
6682
- }), [internalStatus, isReadingFromDb]);
6683
- // let count = 0
6684
- //
6685
- // const refresh = useCallback(() => {
6686
- // count++
6687
- // console.log('[useItemPropertyTest] [refresh] property', property)
6688
- // }, [property])
6709
+ isReadingDb.current = false;
6710
+ }), [internalStatus]);
6711
+ const listenerRef = useRef(readFromDb);
6712
+ useEffect(() => {
6713
+ listenerRef.current = readFromDb;
6714
+ }, [readFromDb]);
6689
6715
  useEffect(() => {
6690
6716
  if (internalStatus === 'ready') {
6691
6717
  readFromDb();
6692
6718
  }
6693
6719
  }, [internalStatus]);
6694
- // useEffect(() => {
6695
- // eventEmitter.addListener(
6696
- // `property.${seedUid || seedLocalId}.${propertyName}.update`,
6697
- // (event) => {
6698
- // refresh()
6699
- // },
6700
- // )
6701
- //
6702
- // return () => {
6703
- // eventEmitter.removeListener(
6704
- // `property.${seedUid || seedLocalId}.${propertyName}.update`,
6705
- // )
6706
- // }
6707
- // }, [])
6720
+ useEffect(() => {
6721
+ eventEmitter.addListener(`property.${seedUid || seedLocalId}.${propertyName}.update`, () => {
6722
+ listenerRef.current();
6723
+ });
6724
+ return () => {
6725
+ eventEmitter.removeListener(`property.${seedUid || seedLocalId}.${propertyName}.update`);
6726
+ };
6727
+ }, []);
6708
6728
  return {
6709
6729
  property,
6710
6730
  isInitialized,
6711
- isReadingFromDb,
6712
6731
  value,
6713
6732
  status,
6714
6733
  };
@@ -6817,7 +6836,7 @@ const client = {
6817
6836
  console.error('fs listeners not ready during init');
6818
6837
  }
6819
6838
  globalService.send({ type: 'init', endpoints, models, addresses });
6820
- import('./seed.schema.config-8V0ae_un.js').then(({ models }) => {
6839
+ import('./seed.schema.config-DA3JNobc.js').then(({ models }) => {
6821
6840
  for (const [key, value] of Object.entries(models)) {
6822
6841
  setModel(key, value);
6823
6842
  }
@@ -7000,6 +7019,16 @@ const analyzeInput = fromCallback(({ sendBack, input: { context, event } }) => {
7000
7019
  });
7001
7020
  return false;
7002
7021
  }
7022
+ // if (
7023
+ // propertyRecordSchema.dataType === 'List' &&
7024
+ // propertyRecordSchema.ref
7025
+ // ) {
7026
+ // sendBack({
7027
+ // type: 'saveListRelation',
7028
+ // newValue,
7029
+ // })
7030
+ // return false
7031
+ // }
7003
7032
  if (propertyRecordSchema.refValueType === 'ImageSrc' ||
7004
7033
  propertyRecordSchema.dataType === 'ImageSrc') {
7005
7034
  sendBack({
@@ -7390,4 +7419,4 @@ if (isNode()) {
7390
7419
  }
7391
7420
 
7392
7421
  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 };
7393
- //# sourceMappingURL=index-DCYwncVx.js.map
7422
+ //# sourceMappingURL=index-UWk43qGs.js.map