@seedprotocol/sdk 0.1.84 → 0.1.86

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.
Files changed (39) hide show
  1. package/dist/{index-JmHVBmP7.js → index-64tJyd3u.js} +48 -51
  2. package/dist/index-64tJyd3u.js.map +1 -0
  3. package/dist/{index-CBTE_R-7.js → index-DAMQTiS7.js} +2 -2
  4. package/dist/{index-CBTE_R-7.js.map → index-DAMQTiS7.js.map} +1 -1
  5. package/dist/main.js +1 -1
  6. package/dist/{seed.schema.config-BSTzpuJg.js → seed.schema.config-BqcatDl0.js} +2 -2
  7. package/dist/{seed.schema.config-BSTzpuJg.js.map → seed.schema.config-BqcatDl0.js.map} +1 -1
  8. package/dist/src/ItemProperty.ts +0 -1
  9. package/dist/src/dbMachine.ts +1 -6
  10. package/dist/src/download.ts +6 -3
  11. package/dist/src/propertyMachine.ts +1 -1
  12. package/dist/src/syncDbWithEas.ts +12 -3
  13. package/dist/src/waitForFiles.ts +1 -1
  14. package/dist/types/src/browser/db/read/subqueries/versionData.d.ts +16 -4
  15. package/dist/types/src/browser/db/read/subqueries/versionData.d.ts.map +1 -1
  16. package/dist/types/src/browser/events/files/download.d.ts.map +1 -1
  17. package/dist/types/src/browser/events/item/syncDbWithEas.d.ts.map +1 -1
  18. package/dist/types/src/browser/property/ItemProperty.d.ts.map +1 -1
  19. package/dist/types/src/browser/services/db/dbMachine.d.ts.map +1 -1
  20. package/dist/types/src/shared/helpers/files.d.ts +1 -1
  21. package/dist/types/src/shared/helpers/files.d.ts.map +1 -1
  22. package/dist/types/src/shared/seedSchema/AppStateSchema.d.ts +12 -4
  23. package/dist/types/src/shared/seedSchema/AppStateSchema.d.ts.map +1 -1
  24. package/dist/types/src/shared/seedSchema/ConfigSchema.d.ts +16 -7
  25. package/dist/types/src/shared/seedSchema/ConfigSchema.d.ts.map +1 -1
  26. package/dist/types/src/shared/seedSchema/MetadataSchema.d.ts +82 -22
  27. package/dist/types/src/shared/seedSchema/MetadataSchema.d.ts.map +1 -1
  28. package/dist/types/src/shared/seedSchema/ModelSchema.d.ts +32 -10
  29. package/dist/types/src/shared/seedSchema/ModelSchema.d.ts.map +1 -1
  30. package/dist/types/src/shared/seedSchema/ModelUidSchema.d.ts +8 -3
  31. package/dist/types/src/shared/seedSchema/ModelUidSchema.d.ts.map +1 -1
  32. package/dist/types/src/shared/seedSchema/PropertyUidSchema.d.ts +8 -3
  33. package/dist/types/src/shared/seedSchema/PropertyUidSchema.d.ts.map +1 -1
  34. package/dist/types/src/shared/seedSchema/SeedSchema.d.ts +28 -9
  35. package/dist/types/src/shared/seedSchema/SeedSchema.d.ts.map +1 -1
  36. package/dist/types/src/shared/seedSchema/VersionSchema.d.ts +34 -10
  37. package/dist/types/src/shared/seedSchema/VersionSchema.d.ts.map +1 -1
  38. package/package.json +50 -50
  39. package/dist/index-JmHVBmP7.js.map +0 -1
@@ -2,14 +2,14 @@ import { b as __awaiter, d as __rest, i as internalPropertyNames, I as INTERNAL_
2
2
  import path, { basename } from 'path';
3
3
  import 'reflect-metadata';
4
4
  import { Type } from '@sinclair/typebox';
5
- import { fromCallback, assign, createActor, waitFor, setup, emit, raise } from 'xstate';
5
+ import { fromCallback, assign, createActor, waitFor, setup, raise } from 'xstate';
6
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';
10
10
  import * as nanoIdDictionary from 'nanoid-dictionary';
11
11
  import debug from 'debug';
12
- import { startCase, debounce, camelCase, orderBy } from 'lodash-es';
12
+ import { startCase, throttle, camelCase, orderBy } from 'lodash-es';
13
13
  import { sqliteTable, text, int, blob, check, unique } from 'drizzle-orm/sqlite-core';
14
14
  import { useState, useEffect, useRef, useCallback } from 'react';
15
15
  import { QueryClient } from '@tanstack/react-query';
@@ -1061,7 +1061,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
1061
1061
  if (propertyRecordSchema &&
1062
1062
  propertyRecordSchema.storageType &&
1063
1063
  propertyRecordSchema.storageType === 'ItemStorage') {
1064
- const { Item } = yield import('./index-CBTE_R-7.js');
1064
+ const { Item } = yield import('./index-DAMQTiS7.js');
1065
1065
  const item = yield Item.find({
1066
1066
  seedLocalId,
1067
1067
  modelName: itemModelName,
@@ -1611,7 +1611,6 @@ class ItemProperty {
1611
1611
  const cacheKey = ItemProperty.cacheKey(cacheKeyId, propertyName);
1612
1612
  if (this.instanceCache.has(cacheKey)) {
1613
1613
  const { instance, refCount } = this.instanceCache.get(cacheKey);
1614
- instance.getService().send({ type: 'reload' });
1615
1614
  this.instanceCache.set(cacheKey, {
1616
1615
  instance,
1617
1616
  refCount: refCount + 1,
@@ -2289,7 +2288,12 @@ const createMetadataRecordsForStorageTransactionId = (storageTransactionIdProper
2289
2288
  });
2290
2289
  }
2291
2290
  });
2291
+ let isSavingToDb = false;
2292
2292
  const saveEasPropertiesToDb = (_a) => __awaiter(void 0, [_a], void 0, function* ({ itemProperties, itemSeeds, }) {
2293
+ if (isSavingToDb) {
2294
+ return;
2295
+ }
2296
+ isSavingToDb = true;
2293
2297
  const propertyUids = itemProperties.map((property) => property.id);
2294
2298
  const models = getModels();
2295
2299
  const appDb = getAppDb();
@@ -2410,6 +2414,7 @@ const saveEasPropertiesToDb = (_a) => __awaiter(void 0, [_a], void 0, function*
2410
2414
  insertPropertiesQuery = insertPropertiesQuery.slice(0, -2) + ';';
2411
2415
  }
2412
2416
  yield appDb.run(sql.raw(insertPropertiesQuery));
2417
+ isSavingToDb = false;
2413
2418
  return { propertyUids };
2414
2419
  });
2415
2420
  const getRelatedSeedsAndVersions = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -2442,7 +2447,7 @@ const getRelatedSeedsAndVersions = () => __awaiter(void 0, void 0, void 0, funct
2442
2447
  itemSeeds,
2443
2448
  });
2444
2449
  });
2445
- const syncDbWithEasHandler = debounce((_) => __awaiter(void 0, void 0, void 0, function* () {
2450
+ const syncDbWithEasHandler = throttle((_) => __awaiter(void 0, void 0, void 0, function* () {
2446
2451
  const appDb = getAppDb();
2447
2452
  const { modelSchemas, schemaStringToModelRecord } = yield getModelSchemas();
2448
2453
  if (!modelSchemas ||
@@ -2512,7 +2517,7 @@ const syncDbWithEasHandler = debounce((_) => __awaiter(void 0, void 0, void 0, f
2512
2517
  for (const modelName of getModelNames()) {
2513
2518
  eventEmitter.emit('item.requestAll', { modelName });
2514
2519
  }
2515
- }), 10000, {
2520
+ }), 30000, {
2516
2521
  leading: true,
2517
2522
  trailing: false,
2518
2523
  });
@@ -2623,7 +2628,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
2623
2628
  if (!models$1) {
2624
2629
  return;
2625
2630
  }
2626
- const { models: SeedModels } = yield import('./seed.schema.config-BSTzpuJg.js');
2631
+ const { models: SeedModels } = yield import('./seed.schema.config-BqcatDl0.js');
2627
2632
  const allModels = Object.assign(Object.assign({}, SeedModels), models$1);
2628
2633
  let hasModelsInDb = false;
2629
2634
  const schemaDefsByModelName = new Map();
@@ -3173,11 +3178,6 @@ const dbMachine = setup({
3173
3178
  },
3174
3179
  [DB_MIGRATING_SUCCESS]: 'ready',
3175
3180
  },
3176
- entry: ({ context }) => {
3177
- if (context.hasFiles) {
3178
- emit({ type: DB_WAITING_FOR_FILES_RECEIVED });
3179
- }
3180
- },
3181
3181
  },
3182
3182
  [MIGRATING]: {
3183
3183
  on: {
@@ -3755,7 +3755,7 @@ const downloadAllFilesBinaryRequestHandler = () => __awaiter(void 0, void 0, voi
3755
3755
  });
3756
3756
  }),
3757
3757
  });
3758
- if (tags && tags.length === 0) {
3758
+ if (tags && tags.length > 0) {
3759
3759
  for (const { name, value } of tags) {
3760
3760
  if (name === 'Content-SHA-256') {
3761
3761
  const metadataRecord = yield getMetadata({
@@ -3775,7 +3775,7 @@ const downloadAllFilesBinaryRequestHandler = () => __awaiter(void 0, void 0, voi
3775
3775
  const response = yield fetch(`https://${ARWEAVE_HOST}/raw/${transactionId}`);
3776
3776
  return yield response.text();
3777
3777
  }),
3778
- networkMode: "offlineFirst"
3778
+ networkMode: 'offlineFirst',
3779
3779
  });
3780
3780
  // const dataString = await arweave.transactions.getData(transactionId, {
3781
3781
  // decode: true,
@@ -3822,45 +3822,42 @@ const downloadAllFilesBinaryRequestHandler = () => __awaiter(void 0, void 0, voi
3822
3822
  let fileExtension = mimeType;
3823
3823
  if (fileExtension && (fileExtension === null || fileExtension === void 0 ? void 0 : fileExtension.startsWith('image'))) {
3824
3824
  fileExtension = fileExtension.replace('image/', '');
3825
- let fileName = transactionId;
3826
- if (contentType === 'base64') {
3827
- if (fileExtension) {
3828
- fileName += `.${fileExtension}`;
3829
- }
3830
- // Remove the Base64 header if it exists (e.g., "data:image/png;base64,")
3831
- const base64Data = dataString.split(',').pop() || '';
3832
- // Decode the Base64 string to binary
3833
- const binaryString = atob(base64Data);
3834
- const length = binaryString.length;
3835
- const binaryData = new Uint8Array(length);
3836
- for (let i = 0; i < length; i++) {
3837
- binaryData[i] = binaryString.charCodeAt(i);
3838
- }
3839
- yield fs.promises.writeFile(`/files/images/${fileName}`, binaryData, {
3840
- encoding: 'binary',
3841
- });
3842
- // if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
3843
- // await fs.promises.writeFile(
3844
- // `/files/images/${fileName}`,
3845
- // dataUint8Array,
3846
- // )
3847
- // }
3848
- }
3849
- if (contentType === 'html') {
3850
- fileName += '.html';
3851
- yield fs.promises.writeFile(`/files/html/${fileName}`, dataString);
3825
+ }
3826
+ let fileName = transactionId;
3827
+ if (contentType === 'base64') {
3828
+ if (fileExtension) {
3829
+ fileName += `.${fileExtension}`;
3852
3830
  }
3853
- if (contentType === 'json') {
3854
- fileName += '.json';
3855
- yield fs.promises.writeFile(`/files/json/${fileName}`, dataString);
3831
+ // Remove the Base64 header if it exists (e.g., "data:image/png;base64,")
3832
+ const base64Data = dataString.split(',').pop() || '';
3833
+ // Decode the Base64 string to binary
3834
+ const binaryString = atob(base64Data);
3835
+ const length = binaryString.length;
3836
+ const binaryData = new Uint8Array(length);
3837
+ for (let i = 0; i < length; i++) {
3838
+ binaryData[i] = binaryString.charCodeAt(i);
3856
3839
  }
3840
+ yield fs.promises.writeFile(`/files/images/${fileName}`, binaryData, {
3841
+ encoding: 'binary',
3842
+ });
3843
+ // if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
3844
+ // await fs.promises.writeFile(
3845
+ // `/files/images/${fileName}`,
3846
+ // dataUint8Array,
3847
+ // )
3848
+ // }
3849
+ }
3850
+ if (contentType === 'html') {
3851
+ fileName += '.html';
3852
+ yield fs.promises.writeFile(`/files/html/${fileName}`, dataString);
3857
3853
  }
3858
- try { }
3859
- catch (error) {
3860
- logger$c(error);
3854
+ if (contentType === 'json') {
3855
+ fileName += '.json';
3856
+ yield fs.promises.writeFile(`/files/json/${fileName}`, dataString);
3861
3857
  }
3862
3858
  }
3863
- finally {
3859
+ catch (error) {
3860
+ logger$c(error);
3864
3861
  }
3865
3862
  }
3866
3863
  });
@@ -6633,7 +6630,7 @@ const client = {
6633
6630
  console.error('fs listeners not ready during init');
6634
6631
  }
6635
6632
  globalService.send({ type: 'init', endpoints, models, addresses });
6636
- import('./seed.schema.config-BSTzpuJg.js').then(({ models }) => {
6633
+ import('./seed.schema.config-BqcatDl0.js').then(({ models }) => {
6637
6634
  for (const [key, value] of Object.entries(models)) {
6638
6635
  setModel(key, value);
6639
6636
  }
@@ -7275,7 +7272,7 @@ const propertyMachine = setup({
7275
7272
  };
7276
7273
  }),
7277
7274
  },
7278
- reload: '.hydratingFromDb',
7275
+ // reload: '.hydratingFromDb',
7279
7276
  save: {
7280
7277
  actions: assign({
7281
7278
  isSaving: true,
@@ -7587,4 +7584,4 @@ if (isNode()) {
7587
7584
  }
7588
7585
 
7589
7586
  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 };
7590
- //# sourceMappingURL=index-JmHVBmP7.js.map
7587
+ //# sourceMappingURL=index-64tJyd3u.js.map