@seedprotocol/sdk 0.2.49 → 0.2.51

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 (54) hide show
  1. package/dist/{ArweaveClient-Dcqcpsq4.js → ArweaveClient-D1TsTBoj.js} +2 -2
  2. package/dist/{ArweaveClient-Dh7LRIqD.js.map → ArweaveClient-D1TsTBoj.js.map} +1 -1
  3. package/dist/{ArweaveClient-Dh7LRIqD.js → ArweaveClient-DpdXUcVJ.js} +2 -2
  4. package/dist/{ArweaveClient-Dcqcpsq4.js.map → ArweaveClient-DpdXUcVJ.js.map} +1 -1
  5. package/dist/{Db-CMRjCZoY.js → Db-DMJ0v3gO.js} +3 -3
  6. package/dist/{Db-CMRjCZoY.js.map → Db-DMJ0v3gO.js.map} +1 -1
  7. package/dist/{Db-BjoRtCFg.js → Db-quJxmvHH.js} +3 -3
  8. package/dist/{Db-BjoRtCFg.js.map → Db-quJxmvHH.js.map} +1 -1
  9. package/dist/{EasClient-A1xC7Gm-.js → EasClient-ClZDuT3o.js} +2 -2
  10. package/dist/{EasClient-A1xC7Gm-.js.map → EasClient-ClZDuT3o.js.map} +1 -1
  11. package/dist/{EasClient-m2mXad59.js → EasClient-DfnGY_2X.js} +2 -2
  12. package/dist/{EasClient-m2mXad59.js.map → EasClient-DfnGY_2X.js.map} +1 -1
  13. package/dist/{FileManager-Dv2zn1RW.js → FileManager-texI7UwL.js} +2 -2
  14. package/dist/{FileManager-Dv2zn1RW.js.map → FileManager-texI7UwL.js.map} +1 -1
  15. package/dist/{Item-7vg6XRhw.js → Item-D4n439Ei.js} +3 -3
  16. package/dist/{Item-7vg6XRhw.js.map → Item-D4n439Ei.js.map} +1 -1
  17. package/dist/{ItemProperty-Bcht9WTV.js → ItemProperty-Be5ymRVT.js} +3 -3
  18. package/dist/{ItemProperty-Bcht9WTV.js.map → ItemProperty-Be5ymRVT.js.map} +1 -1
  19. package/dist/{QueryClient-C-hFMF2j.js → QueryClient-B1HkAaJo.js} +2 -2
  20. package/dist/{QueryClient-C-hFMF2j.js.map → QueryClient-B1HkAaJo.js.map} +1 -1
  21. package/dist/{QueryClient-C02sPZ-K.js → QueryClient-BPoc9eBn.js} +2 -2
  22. package/dist/{QueryClient-C02sPZ-K.js.map → QueryClient-BPoc9eBn.js.map} +1 -1
  23. package/dist/bin.js +5 -5
  24. package/dist/{constants-C03RQQht.js → constants-5PxfAeqj.js} +4 -1
  25. package/dist/constants-5PxfAeqj.js.map +1 -0
  26. package/dist/{index-Dp3GcggF.js → index-BLla2o05.js} +3 -3
  27. package/dist/index-BLla2o05.js.map +1 -0
  28. package/dist/{index-D3Scq_ka.js → index-BeKRizLf.js} +80 -34
  29. package/dist/index-BeKRizLf.js.map +1 -0
  30. package/dist/main.js +2 -2
  31. package/dist/{seed.schema.config-CS6BvsTl.js → seed.schema.config-CMpV_hyS.js} +3 -3
  32. package/dist/{seed.schema.config-CS6BvsTl.js.map → seed.schema.config-CMpV_hyS.js.map} +1 -1
  33. package/dist/src/BaseFileManager.ts +4 -0
  34. package/dist/src/BaseItem.ts +1 -0
  35. package/dist/src/BaseItemProperty.ts +2 -2
  36. package/dist/src/createMetadata.ts +14 -9
  37. package/dist/src/createNewItem.ts +1 -1
  38. package/dist/src/saveImageSrc.ts +2 -6
  39. package/dist/src/saveItemStorage.ts +9 -2
  40. package/dist/src/updateMetadata.ts +41 -1
  41. package/dist/types/src/Item/BaseItem.d.ts.map +1 -1
  42. package/dist/types/src/ItemProperty/service/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
  43. package/dist/types/src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
  44. package/dist/types/src/browser/helpers/FileManager.d.ts +1 -0
  45. package/dist/types/src/browser/helpers/FileManager.d.ts.map +1 -1
  46. package/dist/types/src/db/write/createMetadata.d.ts.map +1 -1
  47. package/dist/types/src/db/write/updateMetadata.d.ts +2 -1
  48. package/dist/types/src/db/write/updateMetadata.d.ts.map +1 -1
  49. package/dist/types/src/helpers/FileManager/BaseFileManager.d.ts +1 -0
  50. package/dist/types/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
  51. package/package.json +1 -1
  52. package/dist/constants-C03RQQht.js.map +0 -1
  53. package/dist/index-D3Scq_ka.js.map +0 -1
  54. package/dist/index-Dp3GcggF.js.map +0 -1
@@ -2,7 +2,7 @@ import { immerable, produce, enableMapSet } from 'immer';
2
2
  import 'reflect-metadata';
3
3
  import { Type } from '@sinclair/typebox';
4
4
  import { fromCallback, setup, assign, waitFor, createActor, raise } from 'xstate';
5
- import { b as BaseQueryClient, a as BaseEasClient, G as GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY, f as GLOBAL_INITIALIZING_SEND_CONFIG, g as GLOBAL_INITIALIZING_CREATE_ALL_ITEMS_SERVICES, h as GLOBAL_ADDING_MODELS_TO_DB_SUCCESS, D as DB_CHECK_STATUS_UPDATE_PATHS, i as DB_CHECK_STATUS_EXISTS, d as BROWSER_FS_TOP_DIR, j as DB_CREATING_SUCCESS, k as DB_VALIDATING_SUCCESS, l as DB_VALIDATING_WAIT, c as BaseFileManager, m as DB_MIGRATING_SUCCESS, n as DB_WAITING_FOR_FILES_RECEIVED, M as MachineIds, o as DB_MIGRATING_WAIT, p as DbState, I as INTERNAL_VALIDATING_INPUT_SUCCESS, q as ARWEAVE_HOST, B as BaseArweaveClient, r as INTERNAL_CONFIGURING_FS_SUCCESS, s as INTERNAL_SAVING_CONFIG_SUCCESS, t as INTERNAL_LOADING_APP_DB_SUCCESS, u as DB_ON_SNAPSHOT, v as DB_NAME_APP, w as InternalState, P as PublishMachineStates, x as GlobalState, y as INTERNAL_DATA_TYPES, z as ImageSize, C as internalPropertyNames, V as VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA, F as defaultAttestationData } from './constants-C03RQQht.js';
5
+ import { b as BaseQueryClient, a as BaseEasClient, G as GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY, f as GLOBAL_INITIALIZING_SEND_CONFIG, g as GLOBAL_INITIALIZING_CREATE_ALL_ITEMS_SERVICES, h as GLOBAL_ADDING_MODELS_TO_DB_SUCCESS, D as DB_CHECK_STATUS_UPDATE_PATHS, i as DB_CHECK_STATUS_EXISTS, d as BROWSER_FS_TOP_DIR, j as DB_CREATING_SUCCESS, k as DB_VALIDATING_SUCCESS, l as DB_VALIDATING_WAIT, c as BaseFileManager, m as DB_MIGRATING_SUCCESS, n as DB_WAITING_FOR_FILES_RECEIVED, M as MachineIds, o as DB_MIGRATING_WAIT, p as DbState, I as INTERNAL_VALIDATING_INPUT_SUCCESS, q as ARWEAVE_HOST, B as BaseArweaveClient, r as INTERNAL_CONFIGURING_FS_SUCCESS, s as INTERNAL_SAVING_CONFIG_SUCCESS, t as INTERNAL_LOADING_APP_DB_SUCCESS, u as DB_ON_SNAPSHOT, v as DB_NAME_APP, w as InternalState, P as PublishMachineStates, x as GlobalState, y as INTERNAL_DATA_TYPES, z as ImageSize, C as internalPropertyNames, V as VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA, F as defaultAttestationData } from './constants-5PxfAeqj.js';
6
6
  import debug from 'debug';
7
7
  import pluralize from 'pluralize';
8
8
  import { sqliteTable, text, int, unique } from 'drizzle-orm/sqlite-core';
@@ -1349,7 +1349,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
1349
1349
  if (!models$1) {
1350
1350
  return;
1351
1351
  }
1352
- const { models: SeedModels } = await import('./seed.schema.config-CS6BvsTl.js');
1352
+ const { models: SeedModels } = await import('./seed.schema.config-CMpV_hyS.js');
1353
1353
  const allModels = {
1354
1354
  ...SeedModels,
1355
1355
  ...models$1,
@@ -2429,6 +2429,45 @@ class FileManager extends BaseFileManager {
2429
2429
  // )
2430
2430
  });
2431
2431
  }
2432
+ static async saveFile(filePath, content) {
2433
+ try {
2434
+ // Get a handle to the OPFS root directory
2435
+ const root = await navigator.storage.getDirectory();
2436
+ // Split the file path into directory and file name
2437
+ const pathParts = filePath.split('/');
2438
+ const fileName = pathParts.pop();
2439
+ if (!fileName)
2440
+ throw new Error('Invalid file path');
2441
+ // Traverse directories and create them if they don't exist
2442
+ let currentDir = root;
2443
+ for (const part of pathParts) {
2444
+ if (part !== '') {
2445
+ currentDir = await currentDir.getDirectoryHandle(part, { create: true });
2446
+ }
2447
+ }
2448
+ // Get the file handle and create the file if it doesn't exist
2449
+ const fileHandle = await currentDir.getFileHandle(fileName, { create: true });
2450
+ // Create a writable stream and write the content
2451
+ const writable = await fileHandle.createWritable();
2452
+ if (typeof content === 'string') {
2453
+ await writable.write(content);
2454
+ }
2455
+ else if (content instanceof Blob) {
2456
+ await writable.write(content);
2457
+ }
2458
+ else if (content instanceof ArrayBuffer) {
2459
+ await writable.write(new Blob([content]));
2460
+ }
2461
+ else {
2462
+ throw new Error('Unsupported content type');
2463
+ }
2464
+ await writable.close();
2465
+ console.log(`File written successfully: ${filePath}`);
2466
+ }
2467
+ catch (error) {
2468
+ console.error(`Error writing to OPFS: ${error.message}`);
2469
+ }
2470
+ }
2432
2471
  }
2433
2472
  BaseFileManager.setPlatformClass(FileManager);
2434
2473
  class CancelableInterval {
@@ -2980,10 +3019,10 @@ const GET_TRANSACTION_TAGS = graphql(/* GraphQL */ `
2980
3019
 
2981
3020
  const initArweaveClient = async () => {
2982
3021
  if (isBrowser()) {
2983
- (await import('./ArweaveClient-Dcqcpsq4.js')).ArweaveClient;
3022
+ (await import('./ArweaveClient-DpdXUcVJ.js')).ArweaveClient;
2984
3023
  }
2985
3024
  if (!isBrowser()) {
2986
- (await import('./ArweaveClient-Dh7LRIqD.js')).ArweaveClient;
3025
+ (await import('./ArweaveClient-D1TsTBoj.js')).ArweaveClient;
2987
3026
  }
2988
3027
  };
2989
3028
  let domain = 'arweave.net';
@@ -5690,7 +5729,7 @@ const resolveRelatedValue = fromCallback(({ sendBack, input: { context } }) => {
5690
5729
  // }
5691
5730
  // }
5692
5731
 
5693
- const updateMetadata = async (metadataValues) => {
5732
+ const updateMetadata = async (metadataValues, propertyRecordSchema) => {
5694
5733
  const appDb = BaseDb.getAppDb();
5695
5734
  const { localId, ...rest } = metadataValues;
5696
5735
  if (!localId) {
@@ -5855,7 +5894,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
5855
5894
  if (propertyRecordSchema &&
5856
5895
  propertyRecordSchema.storageType &&
5857
5896
  propertyRecordSchema.storageType === 'ItemStorage') {
5858
- const { Item } = await import('./index-Dp3GcggF.js');
5897
+ const { Item } = await import('./index-BLla2o05.js');
5859
5898
  const item = await Item.find({
5860
5899
  seedLocalId,
5861
5900
  modelName,
@@ -6142,15 +6181,20 @@ const createMetadata = async (metadataValues, propertyRecordSchema) => {
6142
6181
  const appDb = BaseDb.getAppDb();
6143
6182
  metadataValues.localId = generateId();
6144
6183
  if (!metadataValues.modelType && metadataValues.modelName) {
6145
- metadataValues.modelType = metadataValues.modelName.toLowerCase();
6184
+ metadataValues.modelType = toSnakeCase$1(metadataValues.modelName);
6146
6185
  }
6147
6186
  const isItemStorage = propertyRecordSchema && propertyRecordSchema.storageType === 'ItemStorage';
6148
- if (propertyRecordSchema &&
6149
- propertyRecordSchema.localStorageDir &&
6150
- isItemStorage) {
6151
- metadataValues.refResolvedValue = `${metadataValues.seedUid || metadataValues.seedLocalId}${propertyRecordSchema.filenameSuffix}`;
6152
- metadataValues.refValueType = 'file';
6153
- }
6187
+ // if (
6188
+ // propertyRecordSchema &&
6189
+ // propertyRecordSchema.localStorageDir &&
6190
+ // isItemStorage
6191
+ // ) {
6192
+ // const filename = `${metadataValues.seedUid || metadataValues.seedLocalId}${propertyRecordSchema.filenameSuffix}`
6193
+ // const filePath = path.join(propertyRecordSchema.localStorageDir, filename)
6194
+ // await fs.promises.writeFile(filePath, metadataValues.propertyValue)
6195
+ // metadataValues.propertyValue = filename
6196
+ // metadataValues.refValueType = 'file'
6197
+ // }
6154
6198
  if (!isItemStorage && !metadataValues.schemaUid && propertyRecordSchema) {
6155
6199
  const queryClient = BaseQueryClient.getQueryClient();
6156
6200
  const easClient = BaseEasClient.getEasClient();
@@ -6267,7 +6311,7 @@ const saveImageSrc = fromCallback(({ sendBack, input: { context, event } }) => {
6267
6311
  });
6268
6312
  if (fileData instanceof ArrayBuffer) {
6269
6313
  try {
6270
- await fs.promises.writeFile(filePath, new Uint8Array(fileData));
6314
+ await BaseFileManager.saveFile(filePath, new Uint8Array(fileData));
6271
6315
  }
6272
6316
  catch (e) {
6273
6317
  fs.writeFileSync(filePath, new Uint8Array(fileData));
@@ -6276,7 +6320,7 @@ const saveImageSrc = fromCallback(({ sendBack, input: { context, event } }) => {
6276
6320
  }
6277
6321
  if (typeof fileData === 'string') {
6278
6322
  try {
6279
- await fs.promises.writeFile(filePath, fileData);
6323
+ await BaseFileManager.saveFile(filePath, fileData);
6280
6324
  }
6281
6325
  catch (e) {
6282
6326
  fs.writeFileSync(filePath, fileData);
@@ -6289,9 +6333,6 @@ const saveImageSrc = fromCallback(({ sendBack, input: { context, event } }) => {
6289
6333
  await BaseFileManager.resizeImage({ filePath, width: ImageSize.LARGE, height: ImageSize.LARGE });
6290
6334
  await BaseFileManager.resizeImage({ filePath, width: ImageSize.EXTRA_LARGE, height: ImageSize.EXTRA_LARGE });
6291
6335
  const refResolvedDisplayValue = await BaseFileManager.getContentUrlFromPath(filePath);
6292
- if (!schemaUid) {
6293
- schemaUid = getSchemaUidForSchemaDefinition(propertyName);
6294
- }
6295
6336
  let newLocalId;
6296
6337
  if (!localId) {
6297
6338
  const result = await createMetadata({
@@ -6486,9 +6527,13 @@ const saveItemStorage = fromCallback(({ sendBack, input: { context, event } }) =
6486
6527
  if (queryRows && queryRows.length) {
6487
6528
  propertyData = queryRows[0];
6488
6529
  }
6489
- if (!propertyData) {
6530
+ if (!propertyData && newValue) {
6531
+ const filename = `${seedUid || seedLocalId}${propertyRecordSchema.filenameSuffix}`;
6532
+ const writeToPath = `/files/${propertyRecordSchema.localStorageDir}/${filename}`;
6533
+ await BaseFileManager.saveFile(writeToPath, newValue);
6490
6534
  const propertyDataRows = await createMetadata({
6491
6535
  propertyName,
6536
+ propertyValue: filename,
6492
6537
  modelType: modelName.toLowerCase(),
6493
6538
  seedLocalId,
6494
6539
  seedUid,
@@ -6517,7 +6562,7 @@ const saveItemStorage = fromCallback(({ sendBack, input: { context, event } }) =
6517
6562
  }
6518
6563
  const filePath = `/files/${localStorageDir}/${fileName}`;
6519
6564
  try {
6520
- await fs.promises.writeFile(filePath, newValue);
6565
+ await BaseFileManager.saveFile(filePath, newValue);
6521
6566
  }
6522
6567
  catch (error) {
6523
6568
  fs.writeFileSync(filePath, newValue);
@@ -6871,8 +6916,8 @@ class BaseItemProperty {
6871
6916
  }
6872
6917
  this._subject.next(renderValue);
6873
6918
  // TODO: Maybe have this only update the property?
6874
- // if (context.seedLocalId) {
6875
- // eventEmitter.emit(`item.${modelName}.${context.seedLocalId}.update`)
6919
+ // if (context.seedLocalId || context.seedUid) {
6920
+ // eventEmitter.emit(`property.${context.seedUid || context.seedLocalId}.${propertyName}.update`)
6876
6921
  // }
6877
6922
  // if (context.seedUid) {
6878
6923
  // eventEmitter.emit(`item.${modelName}.${context.seedUid}.update`)
@@ -7440,7 +7485,7 @@ const createNewItem = async ({ modelName, ...propertyData }) => {
7440
7485
  if (!modelName) {
7441
7486
  throw new Error('A model name is required for createNewItem');
7442
7487
  }
7443
- const seedType = modelName.toLowerCase();
7488
+ const seedType = toSnakeCase$1(modelName);
7444
7489
  const newSeedId = await createSeed({ type: seedType });
7445
7490
  const newVersionId = await createVersion({ seedLocalId: newSeedId, seedType: toSnakeCase$1(modelName) });
7446
7491
  const propertySchemas = getModel(modelName)?.schema;
@@ -7641,6 +7686,7 @@ class BaseItem {
7641
7686
  }
7642
7687
  const { seedLocalId, versionLocalId, } = await createNewItem({
7643
7688
  modelName: props.modelName,
7689
+ ...props,
7644
7690
  });
7645
7691
  props.seedLocalId = seedLocalId;
7646
7692
  props.latestVersionLocalId = versionLocalId;
@@ -7798,7 +7844,7 @@ const initItem = async () => {
7798
7844
  Item$2 = (await Promise.resolve().then(function () { return Item$1; })).Item;
7799
7845
  }
7800
7846
  if (!isBrowser()) {
7801
- Item$2 = (await import('./Item-7vg6XRhw.js')).Item;
7847
+ Item$2 = (await import('./Item-D4n439Ei.js')).Item;
7802
7848
  }
7803
7849
  };
7804
7850
 
@@ -7808,17 +7854,17 @@ const initItemProperty = async () => {
7808
7854
  ItemProperty$2 = (await Promise.resolve().then(function () { return ItemProperty$1; })).ItemProperty;
7809
7855
  }
7810
7856
  if (!isBrowser()) {
7811
- ItemProperty$2 = (await import('./ItemProperty-Bcht9WTV.js')).ItemProperty;
7857
+ ItemProperty$2 = (await import('./ItemProperty-Be5ymRVT.js')).ItemProperty;
7812
7858
  }
7813
7859
  };
7814
7860
 
7815
7861
  let Db;
7816
7862
  const initDb = async () => {
7817
7863
  if (isBrowser()) {
7818
- Db = (await import('./Db-CMRjCZoY.js')).Db;
7864
+ Db = (await import('./Db-DMJ0v3gO.js')).Db;
7819
7865
  }
7820
7866
  if (!isBrowser()) {
7821
- Db = (await import('./Db-BjoRtCFg.js')).Db;
7867
+ Db = (await import('./Db-quJxmvHH.js')).Db;
7822
7868
  }
7823
7869
  // TODO: Add config for React Native
7824
7870
  };
@@ -8603,19 +8649,19 @@ const setupServiceHandlers = () => {
8603
8649
 
8604
8650
  const initEasClient = async () => {
8605
8651
  if (isBrowser()) {
8606
- (await import('./EasClient-A1xC7Gm-.js')).EasClient;
8652
+ (await import('./EasClient-ClZDuT3o.js')).EasClient;
8607
8653
  }
8608
8654
  if (!isBrowser()) {
8609
- (await import('./EasClient-m2mXad59.js')).EasClient;
8655
+ (await import('./EasClient-DfnGY_2X.js')).EasClient;
8610
8656
  }
8611
8657
  };
8612
8658
 
8613
8659
  const initQueryClient = async () => {
8614
8660
  if (isBrowser()) {
8615
- (await import('./QueryClient-C-hFMF2j.js')).QueryClient;
8661
+ (await import('./QueryClient-B1HkAaJo.js')).QueryClient;
8616
8662
  }
8617
8663
  if (!isBrowser()) {
8618
- (await import('./QueryClient-C02sPZ-K.js')).QueryClient;
8664
+ (await import('./QueryClient-BPoc9eBn.js')).QueryClient;
8619
8665
  }
8620
8666
  };
8621
8667
 
@@ -8624,7 +8670,7 @@ const initFileManager = async () => {
8624
8670
  (await Promise.resolve().then(function () { return FileManager$1; })).FileManager;
8625
8671
  }
8626
8672
  if (!isBrowser()) {
8627
- (await import('./FileManager-Dv2zn1RW.js')).FileManager;
8673
+ (await import('./FileManager-texI7UwL.js')).FileManager;
8628
8674
  }
8629
8675
  };
8630
8676
 
@@ -8670,7 +8716,7 @@ const client = {
8670
8716
  arweaveDomain,
8671
8717
  filesDir,
8672
8718
  });
8673
- const { models: internalModels } = await import('./seed.schema.config-CS6BvsTl.js');
8719
+ const { models: internalModels } = await import('./seed.schema.config-CMpV_hyS.js');
8674
8720
  for (const [key, value] of Object.entries(internalModels)) {
8675
8721
  setModel(key, value);
8676
8722
  }
@@ -8742,4 +8788,4 @@ const client = {
8742
8788
  enableMapSet();
8743
8789
 
8744
8790
  export { BaseItem as B, Db as D, FileManager as F, Item as I, Json as J, List as L, Model as M, Property as P, Relation as R, Text as T, BaseItemProperty as a, BaseDb as b, ImageSrc as c, Item$2 as d, ItemProperty$2 as e, useItem as f, useItemProperties as g, useCreateItem as h, useItemProperty as i, useDeleteItem as j, useGlobalServiceStatus as k, usePublishItem as l, usePersistedSnapshots as m, useServices as n, useService as o, getCorrectId as p, getGlobalService as q, eventEmitter as r, client as s, useItems as u, withSeed as w };
8745
- //# sourceMappingURL=index-D3Scq_ka.js.map
8791
+ //# sourceMappingURL=index-BeKRizLf.js.map