@seedprotocol/sdk 0.1.41 → 0.1.43

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 (32) hide show
  1. package/dist/{index-ClKB3DC-.js → index-CLdGyn50.js} +2 -2
  2. package/dist/index-CLdGyn50.js.map +1 -0
  3. package/dist/{index-BvH0sjnH.js → index-CdvwVcYz.js} +57 -39
  4. package/dist/index-CdvwVcYz.js.map +1 -0
  5. package/dist/main.js +1 -1
  6. package/dist/{seed-Bj6wb5Jr.js → seed-BHTgf9tV.js} +3 -3
  7. package/dist/{seed-Bj6wb5Jr.js.map → seed-BHTgf9tV.js.map} +1 -1
  8. package/dist/{seed-DJoW3qHO.js → seed-BNSwbrsZ.js} +2 -2
  9. package/dist/{seed-DJoW3qHO.js.map → seed-BNSwbrsZ.js.map} +1 -1
  10. package/dist/{seed-BpJsAlzT.js → seed-BY0EJg54.js} +3 -3
  11. package/dist/{seed-BpJsAlzT.js.map → seed-BY0EJg54.js.map} +1 -1
  12. package/dist/{seed.schema.config-CtfrG9dk.js → seed.schema.config-keaMgDSQ.js} +3 -3
  13. package/dist/{seed.schema.config-CtfrG9dk.js.map → seed.schema.config-keaMgDSQ.js.map} +1 -1
  14. package/dist/types/src/browser/db/read/getItems.d.ts +7 -1
  15. package/dist/types/src/browser/db/read/getItems.d.ts.map +1 -1
  16. package/dist/types/src/browser/db/write/deleteItem.d.ts +8 -0
  17. package/dist/types/src/browser/db/write/deleteItem.d.ts.map +1 -0
  18. package/dist/types/src/browser/db/write/recoverDeletedItem.d.ts +5 -0
  19. package/dist/types/src/browser/db/write/recoverDeletedItem.d.ts.map +1 -0
  20. package/dist/types/src/browser/db/write.d.ts +0 -3
  21. package/dist/types/src/browser/db/write.d.ts.map +1 -1
  22. package/dist/types/src/browser/item/class.d.ts +1 -1
  23. package/dist/types/src/browser/item/class.d.ts.map +1 -1
  24. package/dist/types/src/browser/react/index.d.ts +1 -0
  25. package/dist/types/src/browser/react/index.d.ts.map +1 -1
  26. package/dist/types/src/browser/react/item.d.ts +3 -7
  27. package/dist/types/src/browser/react/item.d.ts.map +1 -1
  28. package/dist/types/src/browser/react/trash.d.ts +6 -0
  29. package/dist/types/src/browser/react/trash.d.ts.map +1 -0
  30. package/package.json +1 -1
  31. package/dist/index-BvH0sjnH.js.map +0 -1
  32. package/dist/index-ClKB3DC-.js.map +0 -1
@@ -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-BvH0sjnH.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-CdvwVcYz.js';
2
2
  import './constants-KW2RTtZB.js';
3
3
  import 'path';
4
4
  import 'reflect-metadata';
@@ -27,4 +27,4 @@ import '@xstate/react';
27
27
  import '@statelyai/inspect';
28
28
  import '@zenfs/dom';
29
29
  import 'drizzle-orm/sqlite-proxy';
30
- //# sourceMappingURL=index-ClKB3DC-.js.map
30
+ //# sourceMappingURL=index-CLdGyn50.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-CLdGyn50.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, setup, assign, createActor, waitFor, emit, raise } from 'xstate';
6
- import { sql, relations, and, eq, max, or, count, isNull, like } from 'drizzle-orm';
6
+ import { sql, relations, and, eq, max, or, isNotNull, isNull, count, desc, like } from 'drizzle-orm';
7
7
  import { fs, configureSingle } from '@zenfs/core';
8
8
  import 'dayjs';
9
9
  import { customAlphabet } from 'nanoid';
@@ -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-ClKB3DC-.js');
987
+ const { Item } = yield import('./index-CLdGyn50.js');
988
988
  const item = yield Item.find({
989
989
  seedLocalId,
990
990
  modelName: itemModelName,
@@ -1139,12 +1139,6 @@ const createNewItem = (_a) => __awaiter(void 0, void 0, void 0, function* () {
1139
1139
  versionLocalId: newVersionId,
1140
1140
  };
1141
1141
  });
1142
- const deleteItem = (_a) => __awaiter(void 0, [_a], void 0, function* ({ seedLocalId }) {
1143
- const appDb = getAppDb();
1144
- yield appDb.run(sql.raw(`UPDATE seeds
1145
- SET _marked_for_deletion = 1
1146
- WHERE local_id = '${seedLocalId}';`));
1147
- });
1148
1142
  const updateItemPropertyValue = (_a) => __awaiter(void 0, [_a], void 0, function* ({ propertyLocalId, propertyName, newValue, seedUid, seedLocalId, modelName, refSeedType, refResolvedValue, refResolvedDisplayValue, versionLocalId, versionUid, schemaUid, }) {
1149
1143
  if (!propertyLocalId && !seedLocalId) {
1150
1144
  logger$k(`[db/write] [updateItemPropertyValue] no propertyLocalId or seedLocalId for property: ${propertyName}`);
@@ -3103,9 +3097,19 @@ const itemMachineSingle = setup({
3103
3097
  },
3104
3098
  });
3105
3099
 
3106
- const getItemsData = (modelName) => __awaiter(void 0, void 0, void 0, function* () {
3100
+ const getItemsData = (_a) => __awaiter(void 0, [_a], void 0, function* ({ modelName, deleted, }) {
3107
3101
  const appDb = getAppDb();
3108
- const itemsData = (yield appDb
3102
+ const conditions = [];
3103
+ if (modelName) {
3104
+ conditions.push(eq(seeds.type, modelName.toLowerCase()));
3105
+ }
3106
+ if (deleted) {
3107
+ conditions.push(or(isNotNull(seeds._markedForDeletion), eq(seeds._markedForDeletion, 1)));
3108
+ }
3109
+ if (!deleted) {
3110
+ conditions.push(or(isNull(seeds._markedForDeletion), eq(seeds._markedForDeletion, 0)));
3111
+ }
3112
+ let query = appDb
3109
3113
  .select({
3110
3114
  seedLocalId: seeds.localId,
3111
3115
  seedUid: seeds.uid,
@@ -3115,11 +3119,14 @@ const getItemsData = (modelName) => __awaiter(void 0, void 0, void 0, function*
3115
3119
  versionsCount: count(versions.localId),
3116
3120
  lastVersionPublishedAt: max(versions.attestationCreatedAt),
3117
3121
  lastLocalUpdateAt: max(versions.createdAt),
3122
+ createdAt: seeds.createdAt,
3118
3123
  })
3119
3124
  .from(seeds)
3120
3125
  .leftJoin(versions, eq(seeds.localId, versions.seedLocalId))
3121
- .where(and(eq(seeds.type, modelName.toLowerCase()), or(isNull(seeds._markedForDeletion), eq(seeds._markedForDeletion, 0))))
3122
- .groupBy(seeds.localId));
3126
+ .where(and(...conditions))
3127
+ .orderBy(desc(seeds.createdAt))
3128
+ .groupBy(seeds.localId);
3129
+ const itemsData = (yield query);
3123
3130
  return itemsData;
3124
3131
  });
3125
3132
 
@@ -3406,9 +3413,9 @@ class Item {
3406
3413
  return Item.create(Object.assign(Object.assign({}, itemData), { modelName }));
3407
3414
  });
3408
3415
  }
3409
- static all(modelName) {
3416
+ static all(modelName, deleted) {
3410
3417
  return __awaiter(this, void 0, void 0, function* () {
3411
- const itemsData = yield getItemsData(modelName);
3418
+ const itemsData = yield getItemsData({ modelName, deleted });
3412
3419
  const itemInstances = [];
3413
3420
  for (const itemData of itemsData) {
3414
3421
  itemInstances.push(yield Item.create(Object.assign(Object.assign({}, itemData), { modelName })));
@@ -4368,7 +4375,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
4368
4375
  if (!models$1) {
4369
4376
  return;
4370
4377
  }
4371
- const { models: SeedModels } = yield import('./seed.schema.config-CtfrG9dk.js');
4378
+ const { models: SeedModels } = yield import('./seed.schema.config-keaMgDSQ.js');
4372
4379
  const allModels = Object.assign(Object.assign({}, SeedModels), models$1);
4373
4380
  let hasModelsInDb = false;
4374
4381
  const schemaDefsByModelName = new Map();
@@ -5844,11 +5851,11 @@ const globalMachine = setup({
5844
5851
  (_a) => __awaiter(void 0, [_a], void 0, function* ({ context }) {
5845
5852
  let SeedClass;
5846
5853
  if (context.environment === 'node') {
5847
- const { SeedNode } = yield import('./seed-Bj6wb5Jr.js');
5854
+ const { SeedNode } = yield import('./seed-BHTgf9tV.js');
5848
5855
  SeedClass = SeedNode;
5849
5856
  }
5850
5857
  else {
5851
- const { SeedBrowser } = yield import('./seed-BpJsAlzT.js');
5858
+ const { SeedBrowser } = yield import('./seed-BY0EJg54.js');
5852
5859
  SeedClass = SeedBrowser;
5853
5860
  }
5854
5861
  return SeedClass;
@@ -6180,7 +6187,7 @@ const useItem = ({ modelName, seedLocalId, seedUid }) => {
6180
6187
  itemStatus,
6181
6188
  };
6182
6189
  };
6183
- const useItems = ({ modelName, options }) => {
6190
+ const useItems = ({ modelName, deleted }) => {
6184
6191
  const [items, setItems] = useImmer([]);
6185
6192
  const [isReadingDb, setIsReadingDb] = useState(false);
6186
6193
  const [isInitialized, setIsInitialized] = useState(false);
@@ -6194,7 +6201,7 @@ const useItems = ({ modelName, options }) => {
6194
6201
  return;
6195
6202
  }
6196
6203
  setIsReadingDb(true);
6197
- const allItems = yield Item.all(modelNameRef.current);
6204
+ const allItems = yield Item.all(modelNameRef.current, deleted);
6198
6205
  setItems(() => allItems);
6199
6206
  setIsReadingDb(false);
6200
6207
  }), [modelName, isReadingDb]);
@@ -6266,24 +6273,6 @@ const useCreateItem = (modelName) => {
6266
6273
  isCreatingItem,
6267
6274
  };
6268
6275
  };
6269
- const useDeleteItem = () => {
6270
- const [isDeletingItem, setIsDeletingItem] = useState(false);
6271
- const destroy = useCallback((item) => __awaiter(void 0, void 0, void 0, function* () {
6272
- if (!item) {
6273
- return;
6274
- }
6275
- setIsDeletingItem(true);
6276
- const { modelName } = item.getService().getSnapshot().context;
6277
- yield deleteItem({ seedLocalId: item.seedLocalId });
6278
- eventEmitter.emit('item.requestAll', { modelName });
6279
- setIsDeletingItem(false);
6280
- }), [isDeletingItem]);
6281
- useEffect(() => { }, []);
6282
- return {
6283
- deleteItem: destroy,
6284
- isDeletingItem,
6285
- };
6286
- };
6287
6276
 
6288
6277
  const logger$1 = debug('app:react:property');
6289
6278
  const useItemProperty = ({ propertyName, seedLocalId, seedUid, }) => {
@@ -6394,6 +6383,35 @@ const useItemProperties = (item) => {
6394
6383
 
6395
6384
  debug('app:react:db');
6396
6385
 
6386
+ const deleteItem = (_a) => __awaiter(void 0, [_a], void 0, function* ({ seedLocalId, seedUid }) {
6387
+ const appDb = getAppDb();
6388
+ yield appDb
6389
+ .update(seeds)
6390
+ .set({
6391
+ _markedForDeletion: 1,
6392
+ })
6393
+ .where(or(eq(seeds.localId, seedLocalId), eq(seeds.uid, seedUid)));
6394
+ });
6395
+
6396
+ const useDeleteItem = () => {
6397
+ const [isDeletingItem, setIsDeletingItem] = useState(false);
6398
+ const destroy = useCallback((item) => __awaiter(void 0, void 0, void 0, function* () {
6399
+ if (!item) {
6400
+ return;
6401
+ }
6402
+ setIsDeletingItem(true);
6403
+ const { modelName } = item.getService().getSnapshot().context;
6404
+ yield deleteItem({ seedLocalId: item.seedLocalId });
6405
+ eventEmitter.emit('item.requestAll', { modelName });
6406
+ setIsDeletingItem(false);
6407
+ }), [isDeletingItem]);
6408
+ useEffect(() => { }, []);
6409
+ return {
6410
+ deleteItem: destroy,
6411
+ isDeletingItem,
6412
+ };
6413
+ };
6414
+
6397
6415
  const logger = debug('app:services:events');
6398
6416
  const handleServiceSaveState = (event) => {
6399
6417
  const { state, serviceId } = event;
@@ -6684,7 +6702,7 @@ const client = {
6684
6702
  console.error('fs listeners not ready during init');
6685
6703
  }
6686
6704
  globalService.send({ type: 'init', endpoints, models, addresses });
6687
- import('./seed.schema.config-CtfrG9dk.js').then(({ models }) => {
6705
+ import('./seed.schema.config-keaMgDSQ.js').then(({ models }) => {
6688
6706
  for (const [key, value] of Object.entries(models)) {
6689
6707
  setModel(key, value);
6690
6708
  }
@@ -6741,4 +6759,4 @@ if (isNode()) {
6741
6759
  }
6742
6760
 
6743
6761
  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 };
6744
- //# sourceMappingURL=index-BvH0sjnH.js.map
6762
+ //# sourceMappingURL=index-CdvwVcYz.js.map