@agoric/swingset-liveslots 0.10.3-dev-dafc7c1.0 → 0.10.3-dev-57685bd.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-dafc7c1.0+dafc7c1",
3
+ "version": "0.10.3-dev-57685bd.0+57685bd",
4
4
  "description": "SwingSet ocap support layer",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -17,9 +17,9 @@
17
17
  "lint:eslint": "eslint ."
18
18
  },
19
19
  "dependencies": {
20
- "@agoric/assert": "0.6.1-dev-dafc7c1.0+dafc7c1",
21
- "@agoric/internal": "0.3.3-dev-dafc7c1.0+dafc7c1",
22
- "@agoric/store": "0.9.3-dev-dafc7c1.0+dafc7c1",
20
+ "@agoric/assert": "0.6.1-dev-57685bd.0+57685bd",
21
+ "@agoric/internal": "0.3.3-dev-57685bd.0+57685bd",
22
+ "@agoric/store": "0.9.3-dev-57685bd.0+57685bd",
23
23
  "@endo/eventual-send": "^0.17.5",
24
24
  "@endo/exo": "^0.2.5",
25
25
  "@endo/far": "^0.2.21",
@@ -63,5 +63,5 @@
63
63
  "publishConfig": {
64
64
  "access": "public"
65
65
  },
66
- "gitHead": "dafc7c1708977aaa55e245dc09a73859cf1df192"
66
+ "gitHead": "57685bd3ed65c1ace377736e049252b9283eb945"
67
67
  }
@@ -50,6 +50,14 @@ function throwNotDurable(value, slotIndex, serializedValue) {
50
50
  Fail`value is not durable: ${value} at slot ${q(slotIndex)} of ${serializedValue.body}`;
51
51
  }
52
52
 
53
+ function failNotFound(key, label) {
54
+ Fail`key ${key} not found in collection ${q(label)}`;
55
+ }
56
+
57
+ function failNotIterable(value) {
58
+ Fail`provided data source is not iterable: ${value}`;
59
+ }
60
+
53
61
  function prefixc(collectionID, dbEntryKey) {
54
62
  return `vc.${collectionID}.${dbEntryKey}`;
55
63
  }
@@ -339,24 +347,26 @@ export function makeCollectionManager(
339
347
  const { keyShape } = getSchema();
340
348
  if (!matches(key, keyShape)) {
341
349
  return false;
342
- }
343
- if (passStyleOf(key) === 'remotable') {
350
+ } else if (passStyleOf(key) === 'remotable') {
344
351
  return getOrdinal(key) !== undefined;
345
352
  } else {
346
353
  return syscall.vatstoreGet(keyToDBKey(key)) !== undefined;
347
354
  }
348
355
  }
349
356
 
357
+ function mustGet(key, label) {
358
+ if (passStyleOf(key) === 'remotable' && getOrdinal(key) === undefined) {
359
+ failNotFound(key, label);
360
+ }
361
+ const dbKey = keyToDBKey(key);
362
+ const result = syscall.vatstoreGet(dbKey) || failNotFound(key, label);
363
+ return { dbKey, result };
364
+ }
365
+
350
366
  function get(key) {
351
367
  const { keyShape, label } = getSchema();
352
368
  mustMatch(key, keyShape, makeInvalidKeyTypeMsg(label));
353
- if (passStyleOf(key) === 'remotable' && getOrdinal(key) === undefined) {
354
- throw Fail`key ${key} not found in collection ${q(label)}`;
355
- }
356
- const result = syscall.vatstoreGet(keyToDBKey(key));
357
- if (!result) {
358
- throw Fail`key ${key} not found in collection ${q(label)}`;
359
- }
369
+ const { result } = mustGet(key, label);
360
370
  return unserializeValue(JSON.parse(result));
361
371
  }
362
372
 
@@ -427,9 +437,7 @@ export function makeCollectionManager(
427
437
  }
428
438
  }
429
439
  }
430
- const dbKey = keyToDBKey(key);
431
- const rawBefore = syscall.vatstoreGet(dbKey);
432
- rawBefore || Fail`key ${key} not found in collection ${q(label)}`;
440
+ const { dbKey, result: rawBefore } = mustGet(key, label);
433
441
  const before = JSON.parse(rawBefore);
434
442
  vrm.updateReferenceCounts(before.slots, after.slots);
435
443
  syscall.vatstoreSet(dbKey, JSON.stringify(after));
@@ -438,12 +446,7 @@ export function makeCollectionManager(
438
446
  function deleteInternal(key) {
439
447
  const { keyShape, label } = getSchema();
440
448
  mustMatch(key, keyShape, makeInvalidKeyTypeMsg(label));
441
- if (passStyleOf(key) === 'remotable' && getOrdinal(key) === undefined) {
442
- throw Fail`key ${key} not found in collection ${q(label)}`;
443
- }
444
- const dbKey = keyToDBKey(key);
445
- const rawValue = syscall.vatstoreGet(dbKey);
446
- rawValue || Fail`key ${key} not found in collection ${q(label)}`;
449
+ const { dbKey, result: rawValue } = mustGet(key, label);
447
450
  const value = JSON.parse(rawValue);
448
451
  const doMoreGC1 = value.slots.map(vrm.removeReachableVref).some(b => b);
449
452
  syscall.vatstoreDelete(dbKey);
@@ -479,18 +482,15 @@ export function makeCollectionManager(
479
482
  const end = prefix(coverEnd); // exclusive
480
483
 
481
484
  const generationAtStart = currentGenerationNumber;
482
- function checkGen() {
483
- if (generationAtStart !== currentGenerationNumber) {
484
- Fail`keys in store cannot be added to during iteration`;
485
- }
486
- }
485
+ const checkGen = () =>
486
+ currentGenerationNumber === generationAtStart ||
487
+ Fail`keys in store cannot be added to during iteration`;
487
488
 
488
489
  const needToMatchKey = !matchAny(keyPatt);
489
490
  const needToMatchValue = !matchAny(valuePatt);
490
491
 
491
- // we always get the dbKey, but we might not need to unserialize it
492
+ // we might not need to unserialize the dbKey or get the dbValue
492
493
  const needKeys = yieldKeys || needToMatchKey;
493
- // we don't always need the dbValue
494
494
  const needValues = yieldValues || needToMatchValue;
495
495
 
496
496
  /**
@@ -631,11 +631,10 @@ export function makeCollectionManager(
631
631
 
632
632
  const addAllToSet = elems => {
633
633
  if (typeof elems[Symbol.iterator] !== 'function') {
634
- if (Object.isFrozen(elems) && isCopySet(elems)) {
635
- elems = getCopySetKeys(elems);
636
- } else {
637
- Fail`provided data source is not iterable: ${elems}`;
638
- }
634
+ elems =
635
+ Object.isFrozen(elems) && isCopySet(elems)
636
+ ? getCopySetKeys(elems)
637
+ : failNotIterable(elems);
639
638
  }
640
639
  for (const elem of elems) {
641
640
  addToSet(elem);
@@ -644,11 +643,10 @@ export function makeCollectionManager(
644
643
 
645
644
  const addAllToMap = mapEntries => {
646
645
  if (typeof mapEntries[Symbol.iterator] !== 'function') {
647
- if (Object.isFrozen(mapEntries) && isCopyMap(mapEntries)) {
648
- mapEntries = getCopyMapEntries(mapEntries);
649
- } else {
650
- Fail`provided data source is not iterable: ${mapEntries}`;
651
- }
646
+ mapEntries =
647
+ Object.isFrozen(mapEntries) && isCopyMap(mapEntries)
648
+ ? getCopyMapEntries(mapEntries)
649
+ : failNotIterable(mapEntries);
652
650
  }
653
651
  for (const [key, value] of mapEntries) {
654
652
  if (has(key)) {
@@ -101,6 +101,12 @@ function exerciseMapOperations(t, collectionName, testStore) {
101
101
  () => testStore.set(86, 'not work'),
102
102
  m(`key 86 not found in collection "${collectionName}"`),
103
103
  );
104
+ t.throws(
105
+ () => testStore.set(somethingMissing, 'not work'),
106
+ m(
107
+ `key "[Alleged: something missing]" not found in collection "${collectionName}"`,
108
+ ),
109
+ );
104
110
  t.throws(
105
111
  () => testStore.init(47, 'already there'),
106
112
  m(`key 47 already registered in collection "${collectionName}"`),
@@ -118,11 +124,17 @@ function exerciseMapOperations(t, collectionName, testStore) {
118
124
  t.is(testStore.get(somethingElse), something);
119
125
 
120
126
  testStore.delete(47);
127
+ testStore.delete(something);
121
128
  t.falsy(testStore.has(47));
129
+ t.falsy(testStore.has(something));
122
130
  t.throws(
123
131
  () => testStore.get(47),
124
132
  m(`key 47 not found in collection "${collectionName}"`),
125
133
  );
134
+ t.throws(
135
+ () => testStore.get(something),
136
+ m(`key "[Alleged: something]" not found in collection "${collectionName}"`),
137
+ );
126
138
  t.throws(
127
139
  () => testStore.delete(22),
128
140
  m(`key 22 not found in collection "${collectionName}"`),
@@ -147,7 +159,9 @@ function exerciseSetOperations(t, collectionName, testStore) {
147
159
  t.notThrows(() => testStore.add(47));
148
160
 
149
161
  testStore.delete(47);
162
+ testStore.delete(something);
150
163
  t.falsy(testStore.has(47));
164
+ t.falsy(testStore.has(something));
151
165
  t.throws(
152
166
  () => testStore.delete(22),
153
167
  m(`key 22 not found in collection "${collectionName}"`),