@seedprotocol/sdk 0.1.122 → 0.1.125

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.
@@ -917,15 +917,7 @@ class ItemProperty {
917
917
  return;
918
918
  }
919
919
  const { context } = snapshot;
920
- // if (
921
- // context.propertyName &&
922
- // context.propertyName.includes('featureImage')
923
- // ) {
924
- // console.log(
925
- // `${context.localId} context for ${snapshot.value}`,
926
- // context,
927
- // )
928
- // }
920
+ const { propertyRecordSchema } = context;
929
921
  if (context.seedLocalId) {
930
922
  const cacheKey = ItemProperty.cacheKey(context.seedLocalId, context.propertyName);
931
923
  if (!ItemProperty.instanceCache.has(cacheKey)) {
@@ -940,27 +932,32 @@ class ItemProperty {
940
932
  // this._updateResponseListener,
941
933
  // )
942
934
  }
935
+ if (context.seedUid ===
936
+ '0x66922b8f40057eb04f94983d59a608e32bceb95b47134dd5b550688940c64f1d' &&
937
+ propertyName === 'featureImage') {
938
+ console.log('context', context);
939
+ }
943
940
  let renderValue;
944
- // if (
945
- // propertyRecordSchema &&
946
- // propertyRecordSchema.storageType &&
947
- // propertyRecordSchema.storageType === 'ItemStorage' &&
948
- // context.resolvedValue &&
949
- // context.localStorageDir
950
- // ) {
951
- // const filePath = `/files/${context.localStorageDir}/${context.resolvedValue}`
952
- // try {
953
- // const exists = await fs.promises.exists(filePath)
954
- // if (exists) {
955
- // renderValue = await fs.promises.readFile(filePath, 'utf-8')
956
- // }
957
- // } catch (e) {
958
- // logger(
959
- // `[ItemProperty] [${context.seedLocalId}] [${context.propertyName}] [storageType] error`,
960
- // e,
961
- // )
962
- // }
963
- // }
941
+ if (propertyRecordSchema &&
942
+ propertyRecordSchema.storageType &&
943
+ propertyRecordSchema.storageType === 'ItemStorage' &&
944
+ context.refResolvedValue &&
945
+ context.localStorageDir) {
946
+ const filePath = `/files/${context.localStorageDir}/${context.refResolvedValue}`;
947
+ try {
948
+ const exists = yield fs.promises.exists(filePath);
949
+ if (exists) {
950
+ renderValue = yield fs.promises.readFile(filePath, 'utf-8');
951
+ }
952
+ if (!exists) {
953
+ renderValue = 'No file found';
954
+ }
955
+ }
956
+ catch (e) {
957
+ logger$o(`[ItemProperty] [${context.seedLocalId}] [${context.propertyName}] [storageType] error`, e);
958
+ renderValue = 'No file found';
959
+ }
960
+ }
964
961
  if (!renderValue) {
965
962
  renderValue = context.renderValue || context.propertyValue;
966
963
  }
@@ -976,6 +973,9 @@ class ItemProperty {
976
973
  transformedPropertyName = this._alias;
977
974
  }
978
975
  if (skipTransform && !this._alias) ;
976
+ if (this._subject.value === renderValue) {
977
+ return;
978
+ }
979
979
  this._subject.next(renderValue);
980
980
  if (context.seedLocalId) {
981
981
  eventEmitter.emit(`item.${modelName}.${context.seedLocalId}.update`);
@@ -2114,7 +2114,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
2114
2114
  if (!models$1) {
2115
2115
  return;
2116
2116
  }
2117
- const { models: SeedModels } = yield import('./seed.schema.config-BHoBrAJe.js');
2117
+ const { models: SeedModels } = yield import('./seed.schema.config-Cj3PtmOG.js');
2118
2118
  const allModels = Object.assign(Object.assign({}, SeedModels), models$1);
2119
2119
  let hasModelsInDb = false;
2120
2120
  const schemaDefsByModelName = new Map();
@@ -3300,7 +3300,10 @@ const downloadAllFilesBinaryRequestHandler = () => __awaiter(void 0, void 0, voi
3300
3300
  yield saveAppState('excludedTransactions', JSON.stringify(Array.from(excludedTransactions)));
3301
3301
  continue;
3302
3302
  }
3303
- const { tags } = yield queryClient.fetchQuery({
3303
+ if (transactionId === 'ZXnDkNk_PHRl5Yqu90kEJn_R3LS3Tl9P8eLtlJTqB-M') {
3304
+ console.log('transactionId', transactionId);
3305
+ }
3306
+ const { tags: tagsResult } = yield queryClient.fetchQuery({
3304
3307
  queryKey: ['getTransactionTags', transactionId],
3305
3308
  queryFn: () => __awaiter(void 0, void 0, void 0, function* () {
3306
3309
  return arweaveClient.request(GET_TRANSACTION_TAGS, {
@@ -3308,7 +3311,8 @@ const downloadAllFilesBinaryRequestHandler = () => __awaiter(void 0, void 0, voi
3308
3311
  });
3309
3312
  }),
3310
3313
  });
3311
- if (tags && tags.length > 0) {
3314
+ const tags = tagsResult.tags || [];
3315
+ if (tagsResult.tags && tagsResult.tags.length > 0) {
3312
3316
  for (const { name, value } of tags) {
3313
3317
  if (name === 'Content-SHA-256') {
3314
3318
  const metadataRecord = yield getMetadata({
@@ -3322,21 +3326,62 @@ const downloadAllFilesBinaryRequestHandler = () => __awaiter(void 0, void 0, voi
3322
3326
  }
3323
3327
  }
3324
3328
  }
3325
- const dataString = yield queryClient.fetchQuery({
3329
+ const data = yield queryClient.fetchQuery({
3326
3330
  queryKey: ['fetchTransaction', transactionId],
3327
3331
  queryFn: () => __awaiter(void 0, void 0, void 0, function* () {
3328
3332
  const response = yield fetch(`https://${ARWEAVE_HOST}/raw/${transactionId}`);
3333
+ const responseContentType = response.headers.get('Content-Type');
3334
+ console.log('Content type', responseContentType);
3335
+ if (responseContentType === 'application/octet-stream') {
3336
+ return yield response.arrayBuffer();
3337
+ }
3329
3338
  return yield response.text();
3330
3339
  }),
3331
3340
  networkMode: 'offlineFirst',
3332
3341
  });
3342
+ let dataString;
3343
+ let arrayBuffer;
3344
+ if (data instanceof ArrayBuffer) {
3345
+ arrayBuffer = data;
3346
+ }
3347
+ if (typeof data === 'string') {
3348
+ dataString = data;
3349
+ }
3333
3350
  // const dataString = await arweave.transactions.getData(transactionId, {
3334
3351
  // decode: true,
3335
3352
  // string: true,
3336
3353
  // })
3337
- if (!dataString) {
3354
+ if (!dataString && !arrayBuffer) {
3338
3355
  logger$f(`[fetchAll/actors] [fetchAllBinaryData] transaction ${transactionId} data not found`);
3339
3356
  }
3357
+ if (dataString && dataString.startsWith('===FILE_SEPARATOR===')) {
3358
+ const dataStringParts = dataString
3359
+ .split('===FILE_SEPARATOR===')
3360
+ .slice(1);
3361
+ if (dataStringParts.length % 2 !== 0) {
3362
+ throw new Error('Input array must have an even number of elements.');
3363
+ }
3364
+ for (let i = 0; i < dataStringParts.length; i += 2) {
3365
+ const contentType = dataStringParts[i];
3366
+ const content = dataStringParts[i + 1];
3367
+ if (contentType === 'html') {
3368
+ const fileName = `${transactionId}.html`;
3369
+ yield fs.promises.writeFile(`/files/html/${fileName}`, content);
3370
+ }
3371
+ if (contentType === 'json') {
3372
+ const fileName = `${transactionId}.json`;
3373
+ yield fs.promises.writeFile(`/files/json/${fileName}`, content);
3374
+ }
3375
+ }
3376
+ continue;
3377
+ }
3378
+ if (!dataString && arrayBuffer) {
3379
+ yield fs.promises.writeFile(`/files/images/${transactionId}`, new Uint8Array(arrayBuffer));
3380
+ continue;
3381
+ }
3382
+ if (!dataString) {
3383
+ continue;
3384
+ }
3340
3385
  let contentType = identifyString(dataString);
3341
3386
  if (contentType !== 'json' &&
3342
3387
  contentType !== 'base64' &&
@@ -6564,7 +6609,7 @@ const client = {
6564
6609
  addresses,
6565
6610
  arweaveDomain,
6566
6611
  });
6567
- import('./seed.schema.config-BHoBrAJe.js').then(({ models }) => {
6612
+ import('./seed.schema.config-Cj3PtmOG.js').then(({ models }) => {
6568
6613
  for (const [key, value] of Object.entries(models)) {
6569
6614
  setModel(key, value);
6570
6615
  }
@@ -7142,6 +7187,11 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
7142
7187
  if (seedUidFromDb !== seedUid) {
7143
7188
  logger$1(`Seed uid from db ${seedUidFromDb} does not match seed uid ${seedUid} for Property.${localId}`);
7144
7189
  }
7190
+ if (seedUidFromDb ===
7191
+ '0x66922b8f40057eb04f94983d59a608e32bceb95b47134dd5b550688940c64f1d' &&
7192
+ propertyName === 'featureImage') {
7193
+ console.log('Property featureImage', firstRow);
7194
+ }
7145
7195
  if (propertyRecordSchema &&
7146
7196
  propertyRecordSchema.refValueType === 'ImageSrc') {
7147
7197
  let shouldReadFromFile = true;
@@ -7239,7 +7289,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
7239
7289
  if (propertyRecordSchema &&
7240
7290
  propertyRecordSchema.storageType &&
7241
7291
  propertyRecordSchema.storageType === 'ItemStorage') {
7242
- const { Item } = yield import('./index-IgTStLC1.js');
7292
+ const { Item } = yield import('./index-D1R2g9ZX.js');
7243
7293
  const item = yield Item.find({
7244
7294
  seedLocalId,
7245
7295
  modelName,
@@ -7595,10 +7645,20 @@ const saveImageSrc = fromCallback(({ sendBack, input: { context, event } }) => {
7595
7645
  seedType: 'image',
7596
7646
  });
7597
7647
  if (fileData instanceof ArrayBuffer) {
7598
- yield fs.promises.writeFile(filePath, new Uint8Array(fileData));
7648
+ try {
7649
+ yield fs.promises.writeFile(filePath, new Uint8Array(fileData));
7650
+ }
7651
+ catch (e) {
7652
+ fs.writeFileSync(filePath, new Uint8Array(fileData));
7653
+ }
7599
7654
  }
7600
7655
  if (typeof fileData === 'string') {
7601
- yield fs.promises.writeFile(filePath, fileData);
7656
+ try {
7657
+ yield fs.promises.writeFile(filePath, fileData);
7658
+ }
7659
+ catch (e) {
7660
+ fs.writeFileSync(filePath, fileData);
7661
+ }
7602
7662
  }
7603
7663
  const refResolvedDisplayValue = yield getContentUrlFromPath(filePath);
7604
7664
  if (!schemaUid) {
@@ -7824,7 +7884,12 @@ const saveItemStorage = fromCallback(({ sendBack, input: { context, event } }) =
7824
7884
  throw new Error(`Missing localStorageDir: ${localStorageDir} or fileName: ${fileName}`);
7825
7885
  }
7826
7886
  const filePath = `/files/${localStorageDir}/${fileName}`;
7827
- yield fs.promises.writeFile(filePath, newValue);
7887
+ try {
7888
+ yield fs.promises.writeFile(filePath, newValue);
7889
+ }
7890
+ catch (error) {
7891
+ fs.writeFileSync(filePath, newValue);
7892
+ }
7828
7893
  yield appDb
7829
7894
  .update(metadata)
7830
7895
  .set({
@@ -8181,4 +8246,4 @@ if (isNode()) {
8181
8246
  }
8182
8247
 
8183
8248
  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_SCHEMA_BY_NAME as a, GET_SEEDS as b, GET_SEED_IDS as c, GET_STORAGE_TRANSACTION_ID as d, GET_VERSIONS as e, GET_PROPERTIES as f, GET_ALL_PROPERTIES_FOR_ALL_VERSIONS as g, itemMachineAll as h, itemMachineSingle as i, ImageSrc as j, ItemProperty as k, useItem as l, useItemProperties as m, useCreateItem as n, useItemProperty as o, useDeleteItem as p, useGlobalServiceStatus as q, useServices as r, getGlobalService as s, client as t, useItems as u, getCorrectId as v, withSeed as w };
8184
- //# sourceMappingURL=index-D30kap8f.js.map
8249
+ //# sourceMappingURL=index-B4chWeSi.js.map