@agoric/internal 0.3.3-dev-dcddffd.0 → 0.3.3-dev-f010e07.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 +3 -3
- package/src/lib-chainStorage.d.ts +0 -1
- package/src/lib-chainStorage.d.ts.map +1 -1
- package/src/lib-chainStorage.js +0 -32
- package/src/marshal.d.ts +17 -0
- package/src/marshal.d.ts.map +1 -0
- package/src/marshal.js +118 -0
- package/src/storage-test-utils.d.ts.map +1 -1
- package/src/storage-test-utils.js +2 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/internal",
|
|
3
|
-
"version": "0.3.3-dev-
|
|
3
|
+
"version": "0.3.3-dev-f010e07.0+f010e07",
|
|
4
4
|
"description": "Externally unsupported utilities internal to agoric-sdk",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"lint:types": "tsc -p jsconfig.json"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@agoric/zone": "0.2.3-dev-
|
|
23
|
+
"@agoric/zone": "0.2.3-dev-f010e07.0+f010e07",
|
|
24
24
|
"@endo/far": "^0.2.18",
|
|
25
25
|
"@endo/marshal": "^0.8.5",
|
|
26
26
|
"@endo/patterns": "^0.2.2",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "f010e07de4def9e926f60e3327908baf5fa91b90"
|
|
46
46
|
}
|
|
@@ -51,7 +51,6 @@ export function makeChainStorageRoot(handleStorageMessage: (message: StorageMess
|
|
|
51
51
|
export function makeStorageNodeChild(storageNodeRef: import('@endo/far').ERef<StorageNode | null>, childName: string): Promise<StorageNode>;
|
|
52
52
|
export function isStreamCell(cell: any): cell is StreamCell<unknown>;
|
|
53
53
|
export function assertCapData(data: unknown): asserts data is import("@endo/marshal").CapData<string>;
|
|
54
|
-
export function unmarshalFromVstorage(data: Map<string, string>, key: string, fromCapData: ReturnType<typeof import('@endo/marshal').makeMarshal>['fromCapData'], index?: number | undefined): any;
|
|
55
54
|
/** @type {(name: string) => void} */
|
|
56
55
|
export const assertPathSegment: (name: string) => void;
|
|
57
56
|
export function prepareChainStorageNode(zone: import('@agoric/zone').Zone): (args_0: import("./types.js").Callback<(message: StorageMessage) => any>, args_1: string, args_2?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib-chainStorage.d.ts","sourceRoot":"","sources":["lib-chainStorage.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lib-chainStorage.d.ts","sourceRoot":"","sources":["lib-chainStorage.js"],"names":[],"mappings":"AAmNA;;;;;;;;;;;GAWG;AACH,qEATqB,cAAc,KAAK,GAAG,YAGhC,MAAM;;;;IA1DX;;;OAGG;mBADa,QAAQ,WAAW,CAAC;IASpC,qFAAqF;wBAAnE,MAAM;;oBAA8C,WAAW;IAWjF,+CAA+C;oBAA5B,MAAM,GAAK,QAAQ,IAAI,CAAC;;;IAtB3C;;;OAGG;mBADa,QAAQ,WAAW,CAAC;IASpC,qFAAqF;wBAAnE,MAAM;;oBAA8C,WAAW;IAWjF,+CAA+C;oBAA5B,MAAM,GAAK,QAAQ,IAAI,CAAC;GAoDhD;AAUD;;;;;;;;GAQG;AACH,qDAJW,OAAO,WAAW,EAAE,IAAI,CAAC,WAAW,QAAE,aACtC,MAAM,GACJ,QAAQ,WAAW,CAAC,CAMhC;AAlMM,mCAHI,GAAG,+BAQ8B;AASrC,oCAHI,OAAO,2DASjB;AAgBD,qCAAqC;AACrC,uCADkB,MAAM,KAAK,IAAI,CAI/B;AAwBK,8CAFI,OAAO,cAAc,EAAE,IAAI,oDAqBiB,cAAc,KAAK,GAAG;;;;IAcvE;;;OAGG;mBADa,QAAQ,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,iBAA8B;CAClC,GAAG;IACP,MAAU,EAAE,iCAAiC,CAAC;IAC9C,IAAQ,kCAAkC;CACvC"}
|
package/src/lib-chainStorage.js
CHANGED
|
@@ -83,38 +83,6 @@ export const assertCapData = data => {
|
|
|
83
83
|
};
|
|
84
84
|
harden(assertCapData);
|
|
85
85
|
|
|
86
|
-
/**
|
|
87
|
-
* Read and unmarshal a value from a map representation of vstorage data
|
|
88
|
-
*
|
|
89
|
-
* @param {Map<string, string>} data
|
|
90
|
-
* @param {string} key
|
|
91
|
-
* @param {ReturnType<typeof import('@endo/marshal').makeMarshal>['fromCapData']} fromCapData
|
|
92
|
-
* @param {number} [index=-1] index of the desired value in a deserialized stream cell
|
|
93
|
-
*/
|
|
94
|
-
export const unmarshalFromVstorage = (data, key, fromCapData, index = -1) => {
|
|
95
|
-
const serialized = data.get(key) || Fail`no data for ${key}`;
|
|
96
|
-
assert.typeof(serialized, 'string');
|
|
97
|
-
|
|
98
|
-
const streamCell = JSON.parse(serialized);
|
|
99
|
-
if (!isStreamCell(streamCell)) {
|
|
100
|
-
throw Fail`not a StreamCell: ${streamCell}`;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const { values } = streamCell;
|
|
104
|
-
values.length > 0 || Fail`no StreamCell values: ${streamCell}`;
|
|
105
|
-
|
|
106
|
-
const marshalled = values.at(index);
|
|
107
|
-
assert.typeof(marshalled, 'string');
|
|
108
|
-
|
|
109
|
-
/** @type {import("@endo/marshal").CapData<string>} */
|
|
110
|
-
const capData = harden(JSON.parse(marshalled));
|
|
111
|
-
assertCapData(capData);
|
|
112
|
-
|
|
113
|
-
const unmarshalled = fromCapData(capData);
|
|
114
|
-
return unmarshalled;
|
|
115
|
-
};
|
|
116
|
-
harden(unmarshalFromVstorage);
|
|
117
|
-
|
|
118
86
|
/**
|
|
119
87
|
* @typedef {object} StoredFacet
|
|
120
88
|
* @property {() => Promise<string>} getPath the chain storage path at which the node was constructed
|
package/src/marshal.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function makeBoardRemote({ boardId, iface }: any): BoardRemote;
|
|
2
|
+
export function slotToBoardRemote(boardId: any, iface: any): BoardRemote;
|
|
3
|
+
export function boardValToSlot(val: any): any;
|
|
4
|
+
export function boardSlottingMarshaller(slotToVal?: ((slot: string, iface: string) => any) | undefined): Omit<import('@endo/marshal').Marshal<string>, 'serialize' | 'unserialize'>;
|
|
5
|
+
export function unmarshalFromVstorage(data: Map<string, string>, key: string, fromCapData: ReturnType<typeof import('@endo/marshal').makeMarshal>['fromCapData'], index?: number | undefined): any;
|
|
6
|
+
export function makeHistoryReviver(entries: Array<[string, string]>, slotToVal?: ((slot: string, iface?: string) => any) | undefined): {
|
|
7
|
+
getItem: (key: any) => any;
|
|
8
|
+
children: (prefix: any) => string[];
|
|
9
|
+
has: (k: any) => boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Should be a union with Remotable, but that's `any`, making this type meaningless
|
|
13
|
+
*/
|
|
14
|
+
export type BoardRemote = {
|
|
15
|
+
getBoardId: () => string;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=marshal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marshal.d.ts","sourceRoot":"","sources":["marshal.js"],"names":[],"mappings":"AAgBO,0DAFM,WAAW,CAKvB;AAEM,yEAC8B;AAE9B,8CAKN;AAWM,4DAHW,MAAM,SAAS,MAAM,KAAK,GAAG,gBAClC,KAAK,OAAO,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC,CAMtF;AAyBM,4CALI,IAAI,MAAM,EAAE,MAAM,CAAC,OACnB,MAAM,eACN,WAAW,cAAc,eAAe,EAAE,WAAW,CAAC,CAAC,aAAa,CAAC,mCAwB/E;AASM,4CAHI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,sBAChB,MAAM,UAAU,MAAM,KAAK,GAAG;;;;EAoB/C;;;;0BA5GY;IAAE,UAAU,EAAE,MAAM,MAAM,CAAA;CAAE"}
|
package/src/marshal.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Far } from '@endo/far';
|
|
2
|
+
import { makeMarshal } from '@endo/marshal';
|
|
3
|
+
import { isStreamCell } from './lib-chainStorage.js';
|
|
4
|
+
|
|
5
|
+
const { Fail } = assert;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Should be a union with Remotable, but that's `any`, making this type meaningless
|
|
9
|
+
*
|
|
10
|
+
* @typedef {{ getBoardId: () => string }} BoardRemote
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {*} slotInfo
|
|
15
|
+
* @returns {BoardRemote}
|
|
16
|
+
*/
|
|
17
|
+
export const makeBoardRemote = ({ boardId, iface }) => {
|
|
18
|
+
const nonalleged = iface ? iface.replace(/^Alleged: /, '') : '';
|
|
19
|
+
return Far(`BoardRemote${nonalleged}`, { getBoardId: () => boardId });
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const slotToBoardRemote = (boardId, iface) =>
|
|
23
|
+
makeBoardRemote({ boardId, iface });
|
|
24
|
+
|
|
25
|
+
export const boardValToSlot = val => {
|
|
26
|
+
if ('getBoardId' in val) {
|
|
27
|
+
return val.getBoardId();
|
|
28
|
+
}
|
|
29
|
+
Fail`unknown obj in boardSlottingMarshaller.valToSlot ${val}`;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A marshaller which can serialize getBoardId() -bearing
|
|
34
|
+
* Remotables. This allows the caller to pick their slots. The
|
|
35
|
+
* deserializer is configurable: the default cannot handle
|
|
36
|
+
* Remotable-bearing data.
|
|
37
|
+
*
|
|
38
|
+
* @param {(slot: string, iface: string) => any} [slotToVal]
|
|
39
|
+
* @returns {Omit<import('@endo/marshal').Marshal<string>, 'serialize' | 'unserialize'>}
|
|
40
|
+
*/
|
|
41
|
+
export const boardSlottingMarshaller = (slotToVal = undefined) => {
|
|
42
|
+
return makeMarshal(boardValToSlot, slotToVal, {
|
|
43
|
+
serializeBodyFormat: 'smallcaps',
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// TODO: Consolidate with `insistCapData` functions from swingset-liveslots,
|
|
48
|
+
// swingset-xsnap-supervisor, etc.
|
|
49
|
+
/**
|
|
50
|
+
* @param {unknown} data
|
|
51
|
+
* @returns {asserts data is import('@endo/marshal').CapData<string>}
|
|
52
|
+
*/
|
|
53
|
+
const assertCapData = data => {
|
|
54
|
+
assert.typeof(data, 'object');
|
|
55
|
+
assert(data);
|
|
56
|
+
assert.typeof(data.body, 'string');
|
|
57
|
+
assert(Array.isArray(data.slots));
|
|
58
|
+
// XXX check that the .slots array elements are actually strings
|
|
59
|
+
};
|
|
60
|
+
harden(assertCapData);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Read and unmarshal a value from a map representation of vstorage data
|
|
64
|
+
*
|
|
65
|
+
* @param {Map<string, string>} data
|
|
66
|
+
* @param {string} key
|
|
67
|
+
* @param {ReturnType<typeof import('@endo/marshal').makeMarshal>['fromCapData']} fromCapData
|
|
68
|
+
* @param {number} [index=-1] index of the desired value in a deserialized stream cell
|
|
69
|
+
*/
|
|
70
|
+
export const unmarshalFromVstorage = (data, key, fromCapData, index = -1) => {
|
|
71
|
+
const serialized = data.get(key) || Fail`no data for ${key}`;
|
|
72
|
+
assert.typeof(serialized, 'string');
|
|
73
|
+
|
|
74
|
+
const streamCell = JSON.parse(serialized);
|
|
75
|
+
if (!isStreamCell(streamCell)) {
|
|
76
|
+
throw Fail`not a StreamCell: ${streamCell}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const { values } = streamCell;
|
|
80
|
+
values.length > 0 || Fail`no StreamCell values: ${streamCell}`;
|
|
81
|
+
|
|
82
|
+
const marshalled = values.at(index);
|
|
83
|
+
assert.typeof(marshalled, 'string');
|
|
84
|
+
|
|
85
|
+
/** @type {import("@endo/marshal").CapData<string>} */
|
|
86
|
+
const capData = harden(JSON.parse(marshalled));
|
|
87
|
+
assertCapData(capData);
|
|
88
|
+
|
|
89
|
+
const unmarshalled = fromCapData(capData);
|
|
90
|
+
return unmarshalled;
|
|
91
|
+
};
|
|
92
|
+
harden(unmarshalFromVstorage);
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Provide access to object graphs serialized in vstorage.
|
|
96
|
+
*
|
|
97
|
+
* @param {Array<[string, string]>} entries
|
|
98
|
+
* @param {(slot: string, iface?: string) => any} [slotToVal]
|
|
99
|
+
*/
|
|
100
|
+
export const makeHistoryReviver = (entries, slotToVal = undefined) => {
|
|
101
|
+
const board = boardSlottingMarshaller(slotToVal);
|
|
102
|
+
const vsMap = new Map(entries);
|
|
103
|
+
const fromCapData = (...args) =>
|
|
104
|
+
Reflect.apply(board.fromCapData, board, args);
|
|
105
|
+
const getItem = key => unmarshalFromVstorage(vsMap, key, fromCapData);
|
|
106
|
+
const children = prefix => {
|
|
107
|
+
prefix.endsWith('.') || Fail`prefix must end with '.'`;
|
|
108
|
+
return harden([
|
|
109
|
+
...new Set(
|
|
110
|
+
entries
|
|
111
|
+
.map(([k, _]) => k)
|
|
112
|
+
.filter(k => k.startsWith(prefix))
|
|
113
|
+
.map(k => k.slice(prefix.length).split('.')[0]),
|
|
114
|
+
),
|
|
115
|
+
]);
|
|
116
|
+
};
|
|
117
|
+
return harden({ getItem, children, has: k => vsMap.get(k) !== undefined });
|
|
118
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-test-utils.d.ts","sourceRoot":"","sources":["storage-test-utils.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"storage-test-utils.d.ts","sourceRoot":"","sources":["storage-test-utils.js"],"names":[],"mappings":"AA+BO,yCAHI,MAAM,UACN,MAAM,wDAGC;AAElB;;;GAGG;AACH;;;;;EAEG;AAsBW,+CAAU,GAAG,GAAK,GAAG,CAAA;AAgC5B,6CAHI,MAAM,gBACN;;eAAwC,CAAC,CAAC;;;;;;;;;;;;;;;;;;yBAyBvC,OAAO,4BAA4B,EAAE,cAAc;;;;EAoFhE;AAIM;IAIH;;;;;;;;;OASG;oBAHQ,MAAM,eACN,OAAO,uBAAuB,EAAE,UAAU,KACxC,OAAO;;;;;;;;;IARpB;;;;;;;;;OASG;oBAHQ,MAAM,eACN,OAAO,uBAAuB,EAAE,UAAU,KACxC,OAAO;;;;;;;;GAWvB;;;;;;;;;;;;;;;;;;eAnNiF,CAAC,KAAK,CAAC;;;6BA0L3E,WAAY,yBAAyB,CAAC;mCA0BtC,WAAW,+BAA+B,CAAC"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import { Far } from '@endo/far';
|
|
3
3
|
import { makeMarshal, Remotable } from '@endo/marshal';
|
|
4
|
+
import { unmarshalFromVstorage } from './marshal.js';
|
|
4
5
|
import { makeTracer } from './debug.js';
|
|
5
|
-
import {
|
|
6
|
-
isStreamCell,
|
|
7
|
-
makeChainStorageRoot,
|
|
8
|
-
unmarshalFromVstorage,
|
|
9
|
-
} from './lib-chainStorage.js';
|
|
6
|
+
import { isStreamCell, makeChainStorageRoot } from './lib-chainStorage.js';
|
|
10
7
|
import { bindAllMethods } from './method-tools.js';
|
|
11
8
|
|
|
12
9
|
const { Fail } = assert;
|