@agoric/swingset-liveslots 0.10.3-dev-dd19d79.0 → 0.10.3-dev-d589873.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/swingset-liveslots",
3
- "version": "0.10.3-dev-dd19d79.0+dd19d79",
3
+ "version": "0.10.3-dev-d589873.0+d589873",
4
4
  "description": "SwingSet ocap support layer",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -17,10 +17,10 @@
17
17
  "lint:eslint": "eslint ."
18
18
  },
19
19
  "dependencies": {
20
- "@agoric/assert": "0.6.1-dev-dd19d79.0+dd19d79",
21
- "@agoric/internal": "0.3.3-dev-dd19d79.0+dd19d79",
22
- "@agoric/store": "0.9.3-dev-dd19d79.0+dd19d79",
23
- "@agoric/vat-data": "0.5.3-dev-dd19d79.0+dd19d79",
20
+ "@agoric/assert": "0.6.1-dev-d589873.0+d589873",
21
+ "@agoric/internal": "0.3.3-dev-d589873.0+d589873",
22
+ "@agoric/store": "0.9.3-dev-d589873.0+d589873",
23
+ "@agoric/vat-data": "0.5.3-dev-d589873.0+d589873",
24
24
  "@endo/eventual-send": "^0.17.2",
25
25
  "@endo/exo": "^0.2.2",
26
26
  "@endo/far": "^0.2.18",
@@ -61,5 +61,5 @@
61
61
  "publishConfig": {
62
62
  "access": "public"
63
63
  },
64
- "gitHead": "dd19d7941c60a98470fc75cc8ac648ab7e39fde1"
64
+ "gitHead": "d5898733a61b253fae863e4ad5531d9005cdacb0"
65
65
  }
@@ -15,7 +15,10 @@ import {
15
15
  makeCopySet,
16
16
  makeCopyMap,
17
17
  getRankCover,
18
+ getCopyMapEntries,
19
+ getCopySetKeys,
18
20
  } from '@endo/patterns';
21
+ import { isCopyMap, isCopySet } from '@agoric/store';
19
22
  import { makeBaseRef, parseVatSlot } from './parseVatSlots.js';
20
23
  import {
21
24
  enumerateKeysStartEnd,
@@ -624,6 +627,36 @@ export function makeCollectionManager(
624
627
  const snapshotMap = (keyPatt, valuePatt) =>
625
628
  makeCopyMap(entries(keyPatt, valuePatt));
626
629
 
630
+ const addAllToSet = elems => {
631
+ if (typeof elems[Symbol.iterator] !== 'function') {
632
+ if (Object.isFrozen(elems) && isCopySet(elems)) {
633
+ elems = getCopySetKeys(elems);
634
+ } else {
635
+ Fail`provided data source is not iterable: ${elems}`;
636
+ }
637
+ }
638
+ for (const elem of elems) {
639
+ addToSet(elem);
640
+ }
641
+ };
642
+
643
+ const addAllToMap = mapEntries => {
644
+ if (typeof mapEntries[Symbol.iterator] !== 'function') {
645
+ if (Object.isFrozen(mapEntries) && isCopyMap(mapEntries)) {
646
+ mapEntries = getCopyMapEntries(mapEntries);
647
+ } else {
648
+ Fail`provided data source is not iterable: ${mapEntries}`;
649
+ }
650
+ }
651
+ for (const [key, value] of mapEntries) {
652
+ if (has(key)) {
653
+ set(key, value);
654
+ } else {
655
+ doInit(key, value, true);
656
+ }
657
+ }
658
+ };
659
+
627
660
  return {
628
661
  has,
629
662
  get,
@@ -635,6 +668,8 @@ export function makeCollectionManager(
635
668
  keys,
636
669
  values,
637
670
  entries,
671
+ addAllToSet,
672
+ addAllToMap,
638
673
  snapshotSet,
639
674
  snapshotMap,
640
675
  sizeInternal,
@@ -647,12 +682,23 @@ export function makeCollectionManager(
647
682
  const hasWeakKeys = storeKindInfo[kindName].hasWeakKeys;
648
683
  const raw = summonCollectionInternal(initial, collectionID, kindName);
649
684
 
650
- const { has, get, init, addToSet, set, delete: del } = raw;
685
+ const {
686
+ has,
687
+ get,
688
+ init,
689
+ addToSet,
690
+ addAllToMap,
691
+ addAllToSet,
692
+ set,
693
+ delete: del,
694
+ } = raw;
651
695
  const weakMethods = {
652
696
  has,
653
697
  get,
654
698
  init,
655
699
  addToSet,
700
+ addAllToSet,
701
+ addAllToMap,
656
702
  set,
657
703
  delete: del,
658
704
  };
@@ -764,12 +810,48 @@ export function makeCollectionManager(
764
810
  }
765
811
 
766
812
  function collectionToMapStore(collection) {
767
- const { snapshotSet: _, snapshotMap, ...rest } = collection;
768
- return Far('mapStore', { snapshot: snapshotMap, ...rest });
813
+ const {
814
+ has,
815
+ get,
816
+ init,
817
+ set,
818
+ delete: del,
819
+ addAllToMap,
820
+ keys,
821
+ values,
822
+ entries,
823
+ snapshotMap,
824
+ getSize,
825
+ clear,
826
+ } = collection;
827
+ const mapStore = {
828
+ has,
829
+ get,
830
+ init,
831
+ set,
832
+ delete: del,
833
+ addAll: addAllToMap,
834
+ keys,
835
+ values,
836
+ entries,
837
+ snapshot: snapshotMap,
838
+ getSize,
839
+ clear,
840
+ };
841
+ return Far('mapStore', mapStore);
769
842
  }
770
843
 
771
844
  function collectionToWeakMapStore(collection) {
772
- return Far('weakMapStore', collection);
845
+ const { has, get, init, set, delete: del, addAllToMap } = collection;
846
+ const weakMapStore = {
847
+ has,
848
+ get,
849
+ init,
850
+ set,
851
+ delete: del,
852
+ addAll: addAllToMap,
853
+ };
854
+ return Far('weakMapStore', weakMapStore);
773
855
  }
774
856
 
775
857
  function collectionToSetStore(collection) {
@@ -777,50 +859,35 @@ export function makeCollectionManager(
777
859
  has,
778
860
  addToSet,
779
861
  delete: del,
862
+ addAllToSet,
780
863
  keys,
781
- getSize,
782
864
  snapshotSet,
865
+ getSize,
783
866
  clear,
784
867
  } = collection;
785
- function* entries(patt) {
786
- for (const k of keys(patt)) {
787
- yield [k, k];
788
- }
789
- }
790
- function addAll(elems) {
791
- for (const elem of elems) {
792
- addToSet(elem, null);
793
- }
794
- }
795
868
 
796
869
  const setStore = {
797
870
  has,
798
871
  add: addToSet,
799
- addAll,
800
872
  delete: del,
873
+ addAll: addAllToSet,
801
874
  keys: patt => keys(patt),
802
875
  values: patt => keys(patt),
803
- entries,
804
- getSize: patt => getSize(patt),
805
876
  snapshot: snapshotSet,
877
+ getSize: patt => getSize(patt),
806
878
  clear,
807
879
  };
808
880
  return Far('setStore', setStore);
809
881
  }
810
882
 
811
883
  function collectionToWeakSetStore(collection) {
812
- const { has, addToSet, delete: del } = collection;
813
- function addAll(elems) {
814
- for (const elem of elems) {
815
- addToSet(elem);
816
- }
817
- }
884
+ const { has, addToSet, delete: del, addAllToSet } = collection;
818
885
 
819
886
  const weakSetStore = {
820
887
  has,
821
888
  add: addToSet,
822
- addAll,
823
889
  delete: del,
890
+ addAll: addAllToSet,
824
891
  };
825
892
  return Far('weakSetStore', weakSetStore);
826
893
  }
@@ -3,6 +3,7 @@ import '@endo/init/debug.js';
3
3
 
4
4
  import { Far } from '@endo/marshal';
5
5
  import { M } from '@agoric/store';
6
+ import { makeCopyMap, makeCopySet } from '@endo/patterns';
6
7
  import { makeFakeCollectionManager } from '../tools/fakeVirtualSupport.js';
7
8
 
8
9
  const {
@@ -191,6 +192,89 @@ test('basic weak set operations', t => {
191
192
  );
192
193
  });
193
194
 
195
+ function exerciseSetAddAll(t, weak, testStore) {
196
+ const allThatStuff = stuff.map(entry => entry[0]);
197
+
198
+ testStore.addAll(allThatStuff);
199
+ for (const elem of allThatStuff) {
200
+ t.truthy(testStore.has(elem));
201
+ testStore.delete(elem);
202
+ }
203
+ if (!weak) {
204
+ t.is(testStore.getSize(), 0);
205
+ }
206
+
207
+ testStore.addAll(makeCopySet(allThatStuff));
208
+ for (const elem of allThatStuff) {
209
+ t.truthy(testStore.has(elem));
210
+ testStore.delete(elem);
211
+ }
212
+ if (!weak) {
213
+ t.is(testStore.getSize(), 0);
214
+ }
215
+
216
+ t.throws(
217
+ () => testStore.addAll({ bogus: 47 }),
218
+ m(/provided data source is not iterable/),
219
+ );
220
+ }
221
+
222
+ test('set addAll', t => {
223
+ exerciseSetAddAll(t, false, makeScalarBigSetStore('test set'));
224
+ });
225
+
226
+ test('weak set addAll', t => {
227
+ exerciseSetAddAll(t, true, makeScalarBigWeakSetStore('test weak set'));
228
+ });
229
+
230
+ test('set snapshot', t => {
231
+ const testStore = makeScalarBigSetStore('test set');
232
+ const allThatStuff = stuff.map(entry => entry[0]);
233
+ testStore.addAll(allThatStuff);
234
+ t.deepEqual(testStore.snapshot(), makeCopySet(allThatStuff));
235
+ });
236
+
237
+ function exerciseMapAddAll(t, weak, testStore) {
238
+ testStore.addAll(stuff);
239
+ for (const [k, v] of stuff) {
240
+ t.truthy(testStore.has(k));
241
+ t.is(testStore.get(k), v);
242
+ testStore.delete(k);
243
+ }
244
+ if (!weak) {
245
+ t.is(testStore.getSize(), 0);
246
+ }
247
+
248
+ testStore.addAll(makeCopyMap(stuff));
249
+ for (const [k, v] of stuff) {
250
+ t.truthy(testStore.has(k));
251
+ t.is(testStore.get(k), v);
252
+ testStore.delete(k);
253
+ }
254
+ if (!weak) {
255
+ t.is(testStore.getSize(), 0);
256
+ }
257
+
258
+ t.throws(
259
+ () => testStore.addAll({ bogus: 47 }),
260
+ m(/provided data source is not iterable/),
261
+ );
262
+ }
263
+
264
+ test('map addAll', t => {
265
+ exerciseMapAddAll(t, false, makeScalarBigMapStore('test map'));
266
+ });
267
+
268
+ test('weak map addAll', t => {
269
+ exerciseMapAddAll(t, true, makeScalarBigWeakMapStore('test weak map'));
270
+ });
271
+
272
+ test('map snapshot', t => {
273
+ const testStore = makeScalarBigMapStore('test map');
274
+ testStore.addAll(stuff);
275
+ t.deepEqual(testStore.snapshot(), makeCopyMap(stuff));
276
+ });
277
+
194
278
  test('constrain map key shape', t => {
195
279
  const stringsOnly = makeScalarBigMapStore('map key strings only', {
196
280
  keyShape: M.string(),
@@ -766,13 +850,6 @@ test('set queries', t => {
766
850
  symbolKrusty,
767
851
  undefined,
768
852
  ]);
769
-
770
- // @ts-expect-error our BigSetStore has .entries, but not the SetStore type
771
- t.deepEqual(Array.from(testStore.entries(M.number())), [
772
- [-29, -29],
773
- [3, 3],
774
- [47, 47],
775
- ]);
776
853
  });
777
854
 
778
855
  test('remotable sort order', t => {