@agoric/internal
Advanced tools
Comparing version 0.3.3-dev-7946226.0 to 0.3.3-dev-79df2da.0
{ | ||
"name": "@agoric/internal", | ||
"version": "0.3.3-dev-7946226.0+7946226", | ||
"version": "0.3.3-dev-79df2da.0+79df2da", | ||
"description": "Externally unsupported utilities internal to agoric-sdk", | ||
@@ -23,12 +23,12 @@ "type": "module", | ||
"dependencies": { | ||
"@agoric/base-zone": "0.1.1-dev-7946226.0+7946226", | ||
"@endo/common": "^1.2.6", | ||
"@endo/errors": "^1.2.6", | ||
"@endo/far": "^1.1.6", | ||
"@endo/init": "^1.1.5", | ||
"@endo/marshal": "^1.5.4", | ||
"@endo/pass-style": "^1.4.4", | ||
"@endo/patterns": "^1.4.4", | ||
"@endo/promise-kit": "^1.1.6", | ||
"@endo/stream": "^1.2.6", | ||
"@agoric/base-zone": "0.1.1-dev-79df2da.0+79df2da", | ||
"@endo/common": "^1.2.8", | ||
"@endo/errors": "^1.2.8", | ||
"@endo/far": "^1.1.9", | ||
"@endo/init": "^1.1.7", | ||
"@endo/marshal": "^1.6.2", | ||
"@endo/pass-style": "^1.4.7", | ||
"@endo/patterns": "^1.4.7", | ||
"@endo/promise-kit": "^1.1.8", | ||
"@endo/stream": "^1.2.8", | ||
"anylogger": "^0.21.0", | ||
@@ -38,4 +38,5 @@ "jessie.js": "^0.3.4" | ||
"devDependencies": { | ||
"@endo/exo": "^1.5.4", | ||
"@endo/init": "^1.1.5", | ||
"@agoric/cosmic-proto": "0.4.1-dev-79df2da.0+79df2da", | ||
"@endo/exo": "^1.5.7", | ||
"@endo/init": "^1.1.7", | ||
"ava": "^5.3.0", | ||
@@ -62,5 +63,5 @@ "tsd": "^0.31.1" | ||
"typeCoverage": { | ||
"atLeast": 93.42 | ||
"atLeast": 93.06 | ||
}, | ||
"gitHead": "7946226c7863ac90bb2de0cfc8b9e6770ef06697" | ||
"gitHead": "79df2da0e8a48f8d7d5301fc22101a9609f3a658" | ||
} |
@@ -13,7 +13,7 @@ **NOTE: unsupported** | ||
It is meant to be a home for modules that have no Agoric-specific dependencies themselves. It does depend on a these other @agoric packages but they are all destined to migrate out of the repo, | ||
It is meant to be a home for modules that have no dependencies on other packages in this repository, except for the following packages that do not theirselves depend upon any other @agoric packages and may be destined for migration elsewhere: | ||
- base-zone | ||
- store | ||
- assert | ||
- [base-zone](../base-zone) | ||
- [store](../store) | ||
- [cosmic-proto](../cosmic-proto) | ||
@@ -20,0 +20,0 @@ This package may not take dependencies on any others in this repository. |
@@ -0,11 +1,54 @@ | ||
/** | ||
* Types of messages used for communication between a cosmos-sdk blockchain node | ||
* and its paired swingset VM, especially for the ABCI lifecycle. See: | ||
* | ||
* - https://github.com/tendermint/tendermint/blob/v0.34.x/spec/abci/abci.md#block-execution | ||
* - ../../../golang/cosmos/vm/action.go | ||
* - ../../../golang/cosmos/app/app.go | ||
* - ../../../golang/cosmos/x/swingset/abci.go | ||
* - ../../../golang/cosmos/x/swingset/keeper/swing_store_exports_handler.go | ||
* - ../../cosmic-swingset/src/chain-main.js | ||
* - ../../cosmic-swingset/src/launch-chain.js | ||
*/ | ||
export type SwingsetMessageType = (typeof SwingsetMessageType)[keyof typeof SwingsetMessageType]; | ||
export namespace SwingsetMessageType { | ||
let AG_COSMOS_INIT: "AG_COSMOS_INIT"; | ||
let BEGIN_BLOCK: "BEGIN_BLOCK"; | ||
let END_BLOCK: "END_BLOCK"; | ||
let COMMIT_BLOCK: "COMMIT_BLOCK"; | ||
let AFTER_COMMIT_BLOCK: "AFTER_COMMIT_BLOCK"; | ||
let SWING_STORE_EXPORT: "SWING_STORE_EXPORT"; | ||
} | ||
export const AG_COSMOS_INIT: "AG_COSMOS_INIT"; | ||
export const SWING_STORE_EXPORT: "SWING_STORE_EXPORT"; | ||
export const BEGIN_BLOCK: "BEGIN_BLOCK"; | ||
export const CALCULATE_FEES_IN_BEANS: "CALCULATE_FEES_IN_BEANS"; | ||
export const CORE_EVAL: "CORE_EVAL"; | ||
export const DELIVER_INBOUND: "DELIVER_INBOUND"; | ||
export const END_BLOCK: "END_BLOCK"; | ||
export const COMMIT_BLOCK: "COMMIT_BLOCK"; | ||
export const AFTER_COMMIT_BLOCK: "AFTER_COMMIT_BLOCK"; | ||
export const SWING_STORE_EXPORT: "SWING_STORE_EXPORT"; | ||
/** | ||
* Types of "action" messages consumed by the swingset VM from actionQueue or | ||
* highPriorityQueue during END_BLOCK. See: | ||
* | ||
* - ../../../golang/cosmos/x/swingset/keeper/msg_server.go | ||
* - ../../../golang/cosmos/x/swingset/keeper/proposal.go | ||
* - ../../../golang/cosmos/x/vbank/vbank.go | ||
* - ../../../golang/cosmos/x/vibc/handler.go | ||
* - ../../../golang/cosmos/x/vibc/keeper/triggers.go | ||
* - ../../../golang/cosmos/x/vibc/types/ibc_module.go | ||
*/ | ||
export type QueuedActionType = (typeof QueuedActionType)[keyof typeof QueuedActionType]; | ||
export namespace QueuedActionType { | ||
let CORE_EVAL: "CORE_EVAL"; | ||
let DELIVER_INBOUND: "DELIVER_INBOUND"; | ||
let IBC_EVENT: "IBC_EVENT"; | ||
let INSTALL_BUNDLE: "INSTALL_BUNDLE"; | ||
let PLEASE_PROVISION: "PLEASE_PROVISION"; | ||
let VBANK_BALANCE_UPDATE: "VBANK_BALANCE_UPDATE"; | ||
let WALLET_ACTION: "WALLET_ACTION"; | ||
let WALLET_SPEND_ACTION: "WALLET_SPEND_ACTION"; | ||
} | ||
export const CORE_EVAL: "CORE_EVAL"; | ||
export const DELIVER_INBOUND: "DELIVER_INBOUND"; | ||
export const IBC_EVENT: "IBC_EVENT"; | ||
export const INSTALL_BUNDLE: "INSTALL_BUNDLE"; | ||
export const PLEASE_PROVISION: "PLEASE_PROVISION"; | ||
@@ -15,4 +58,5 @@ export const VBANK_BALANCE_UPDATE: "VBANK_BALANCE_UPDATE"; | ||
export const WALLET_SPEND_ACTION: "WALLET_SPEND_ACTION"; | ||
export const INSTALL_BUNDLE: "INSTALL_BUNDLE"; | ||
export const CALCULATE_FEES_IN_BEANS: "CALCULATE_FEES_IN_BEANS"; | ||
export const VTRANSFER_IBC_EVENT: "VTRANSFER_IBC_EVENT"; | ||
export const KERNEL_UPGRADE_EVENTS: "KERNEL_UPGRADE_EVENTS"; | ||
//# sourceMappingURL=action-types.d.ts.map |
// @jessie-check | ||
export const AG_COSMOS_INIT = 'AG_COSMOS_INIT'; | ||
export const SWING_STORE_EXPORT = 'SWING_STORE_EXPORT'; | ||
export const BEGIN_BLOCK = 'BEGIN_BLOCK'; | ||
/** | ||
* Types of messages used for communication between a cosmos-sdk blockchain node | ||
* and its paired swingset VM, especially for the ABCI lifecycle. See: | ||
* | ||
* - https://github.com/tendermint/tendermint/blob/v0.34.x/spec/abci/abci.md#block-execution | ||
* - ../../../golang/cosmos/vm/action.go | ||
* - ../../../golang/cosmos/app/app.go | ||
* - ../../../golang/cosmos/x/swingset/abci.go | ||
* - ../../../golang/cosmos/x/swingset/keeper/swing_store_exports_handler.go | ||
* - ../../cosmic-swingset/src/chain-main.js | ||
* - ../../cosmic-swingset/src/launch-chain.js | ||
* | ||
* @enum {(typeof SwingsetMessageType)[keyof typeof SwingsetMessageType]} | ||
*/ | ||
export const SwingsetMessageType = /** @type {const} */ ({ | ||
AG_COSMOS_INIT: 'AG_COSMOS_INIT', // used to synchronize at process launch | ||
BEGIN_BLOCK: 'BEGIN_BLOCK', | ||
END_BLOCK: 'END_BLOCK', | ||
COMMIT_BLOCK: 'COMMIT_BLOCK', | ||
AFTER_COMMIT_BLOCK: 'AFTER_COMMIT_BLOCK', | ||
SWING_STORE_EXPORT: 'SWING_STORE_EXPORT', // used to synchronize data export | ||
}); | ||
harden(SwingsetMessageType); | ||
// TODO: Update all imports to use SwingsetMessageType. But until then... | ||
export const { | ||
AG_COSMOS_INIT, | ||
BEGIN_BLOCK, | ||
END_BLOCK, | ||
COMMIT_BLOCK, | ||
AFTER_COMMIT_BLOCK, | ||
SWING_STORE_EXPORT, | ||
} = SwingsetMessageType; | ||
/** | ||
* Types of "action" messages consumed by the swingset VM from actionQueue or | ||
* highPriorityQueue during END_BLOCK. See: | ||
* | ||
* - ../../../golang/cosmos/x/swingset/keeper/msg_server.go | ||
* - ../../../golang/cosmos/x/swingset/keeper/proposal.go | ||
* - ../../../golang/cosmos/x/vbank/vbank.go | ||
* - ../../../golang/cosmos/x/vibc/handler.go | ||
* - ../../../golang/cosmos/x/vibc/keeper/triggers.go | ||
* - ../../../golang/cosmos/x/vibc/types/ibc_module.go | ||
* | ||
* @enum {(typeof QueuedActionType)[keyof typeof QueuedActionType]} | ||
*/ | ||
export const QueuedActionType = /** @type {const} */ ({ | ||
CORE_EVAL: 'CORE_EVAL', | ||
DELIVER_INBOUND: 'DELIVER_INBOUND', | ||
IBC_EVENT: 'IBC_EVENT', | ||
INSTALL_BUNDLE: 'INSTALL_BUNDLE', | ||
PLEASE_PROVISION: 'PLEASE_PROVISION', | ||
VBANK_BALANCE_UPDATE: 'VBANK_BALANCE_UPDATE', | ||
WALLET_ACTION: 'WALLET_ACTION', | ||
WALLET_SPEND_ACTION: 'WALLET_SPEND_ACTION', | ||
}); | ||
harden(QueuedActionType); | ||
// TODO: Update all imports to use QueuedActionType. But until then... | ||
export const { | ||
CORE_EVAL, | ||
DELIVER_INBOUND, | ||
IBC_EVENT, | ||
INSTALL_BUNDLE, | ||
PLEASE_PROVISION, | ||
VBANK_BALANCE_UPDATE, | ||
WALLET_ACTION, | ||
WALLET_SPEND_ACTION, | ||
} = QueuedActionType; | ||
export const CALCULATE_FEES_IN_BEANS = 'CALCULATE_FEES_IN_BEANS'; | ||
export const CORE_EVAL = 'CORE_EVAL'; | ||
export const DELIVER_INBOUND = 'DELIVER_INBOUND'; | ||
export const END_BLOCK = 'END_BLOCK'; | ||
export const COMMIT_BLOCK = 'COMMIT_BLOCK'; | ||
export const AFTER_COMMIT_BLOCK = 'AFTER_COMMIT_BLOCK'; | ||
export const IBC_EVENT = 'IBC_EVENT'; | ||
export const PLEASE_PROVISION = 'PLEASE_PROVISION'; | ||
export const VBANK_BALANCE_UPDATE = 'VBANK_BALANCE_UPDATE'; | ||
export const WALLET_ACTION = 'WALLET_ACTION'; | ||
export const WALLET_SPEND_ACTION = 'WALLET_SPEND_ACTION'; | ||
export const INSTALL_BUNDLE = 'INSTALL_BUNDLE'; | ||
export const VTRANSFER_IBC_EVENT = 'VTRANSFER_IBC_EVENT'; | ||
export const KERNEL_UPGRADE_EVENTS = 'KERNEL_UPGRADE_EVENTS'; |
@@ -18,3 +18,3 @@ export function callSync<I extends (...args: any[]) => any>(callback: SyncCallback<I>, ...args: Parameters<I>): ReturnType<I>; | ||
tag?: string | undefined; | ||
} | undefined): MakeAttenuator<any>; | ||
}): MakeAttenuator<any>; | ||
export type MakeAttenuator<T extends import("@endo/exo").Methods> = (...args: Parameters<ReturnType<(<M extends PropertyKey>(zone: import("@agoric/base-zone").Zone, methodNames: M[], { interfaceGuard, tag }?: { | ||
@@ -21,0 +21,0 @@ interfaceGuard?: import("@endo/patterns").InterfaceGuard<{ [K in M]: import("@endo/patterns").MethodGuard; }> | undefined; |
@@ -1,2 +0,2 @@ | ||
export function NonNullish<T>(val: T | null | undefined, optDetails?: string | undefined): T; | ||
export function NonNullish<T>(val: T | null | undefined, optDetails?: string): T; | ||
//# sourceMappingURL=errors.d.ts.map |
export * from "./config.js"; | ||
export * from "./debug.js"; | ||
export * from "./errors.js"; | ||
export * from "./utils.js"; | ||
export * from "./js-utils.js"; | ||
export * from "./method-tools.js"; | ||
export * from "./ses-utils.js"; | ||
export * from "./typeCheck.js"; | ||
export * from "./typeGuards.js"; | ||
export * from "./types-index.js"; | ||
export { pureDataMarshaller } from "./marshal.js"; | ||
export { objectMap } from "@endo/common/object-map.js"; | ||
@@ -10,0 +12,0 @@ export { objectMetaMap } from "@endo/common/object-meta-map.js"; |
@@ -8,4 +8,6 @@ // @jessie-check | ||
export * from './errors.js'; | ||
export * from './utils.js'; | ||
export * from './js-utils.js'; | ||
export { pureDataMarshaller } from './marshal.js'; | ||
export * from './method-tools.js'; | ||
export * from './ses-utils.js'; | ||
export * from './typeCheck.js'; | ||
@@ -12,0 +14,0 @@ export * from './typeGuards.js'; |
@@ -16,19 +16,8 @@ /** | ||
sequence?: boolean | undefined; | ||
} | undefined): import("@endo/exo").Guarded<{ | ||
}): import("@endo/exo").Guarded<{ | ||
getPath(): string; | ||
/** | ||
* @deprecated use getPath | ||
* @type {() => Promise<VStorageKey>} | ||
*/ | ||
getStoreKey(): Promise<VStorageKey>; | ||
/** | ||
* @type {( | ||
* name: string, | ||
* childNodeOptions?: { sequence?: boolean }, | ||
* ) => StorageNode} | ||
*/ | ||
makeChildNode(name: string, childNodeOptions?: { | ||
sequence?: boolean; | ||
}): StorageNode; | ||
/** @type {(value: string) => Promise<void>} */ | ||
setValue(value: string): Promise<void>; | ||
@@ -54,17 +43,6 @@ }>; | ||
getPath(): string; | ||
/** | ||
* @deprecated use getPath | ||
* @type {() => Promise<VStorageKey>} | ||
*/ | ||
getStoreKey(): Promise<VStorageKey>; | ||
/** | ||
* @type {( | ||
* name: string, | ||
* childNodeOptions?: { sequence?: boolean }, | ||
* ) => StorageNode} | ||
*/ | ||
makeChildNode(name: string, childNodeOptions?: { | ||
sequence?: boolean; | ||
}): StorageNode; | ||
/** @type {(value: string) => Promise<void>} */ | ||
setValue(value: string): Promise<void>; | ||
@@ -71,0 +49,0 @@ }>; |
export default engineGC; | ||
declare const engineGC: () => void; | ||
declare const engineGC: GCFunction; | ||
//# sourceMappingURL=engine-gc.d.ts.map |
@@ -6,5 +6,5 @@ export function makeBoardRemote({ boardId, iface }: { | ||
export function slotToBoardRemote(boardId: string, iface: string): BoardRemote; | ||
export function boardSlottingMarshaller(slotToVal?: ((slot: string, iface: string) => any) | undefined): Omit<import("@endo/marshal").Marshal<string | null>, "serialize" | "unserialize">; | ||
export function boardSlottingMarshaller(slotToVal?: (slot: string, iface: string) => any): Omit<import("@endo/marshal").Marshal<string | null>, "serialize" | "unserialize">; | ||
export function unmarshalFromVstorage(data: Map<string, string>, key: string, fromCapData: ReturnType<typeof import("@endo/marshal").makeMarshal>["fromCapData"], index: number): any; | ||
export function makeHistoryReviver(entries: [string, string][], slotToVal?: ((slot: string, iface?: string) => any) | undefined): { | ||
export function makeHistoryReviver(entries: [string, string][], slotToVal?: (slot: string, iface?: string) => any): { | ||
getItem: (key: string) => any; | ||
@@ -14,2 +14,8 @@ children: (prefix: string) => string[]; | ||
}; | ||
export const pureDataMarshaller: { | ||
toCapData: import("@endo/marshal").ToCapData<import("@endo/marshal").CapData<unknown>>; | ||
fromCapData: import("@endo/marshal").FromCapData<import("@endo/marshal").CapData<unknown>>; | ||
serialize: import("@endo/marshal").ToCapData<import("@endo/marshal").CapData<unknown>>; | ||
unserialize: import("@endo/marshal").FromCapData<import("@endo/marshal").CapData<unknown>>; | ||
}; | ||
/** | ||
@@ -16,0 +22,0 @@ * Should be a union with Remotable, but that's `any`, making this type |
@@ -138,1 +138,8 @@ // @ts-check | ||
}; | ||
/** @param {import('@endo/marshal').CapData<unknown>} cap */ | ||
const rejectOCap = cap => Fail`${cap} is not pure data`; | ||
export const pureDataMarshaller = makeMarshal(rejectOCap, rejectOCap, { | ||
serializeBodyFormat: 'smallcaps', | ||
}); | ||
harden(pureDataMarshaller); |
@@ -14,3 +14,3 @@ /** | ||
*/ | ||
export function decode(data: Buffer, optMaxChunkSize?: number | undefined): { | ||
export function decode(data: Buffer, optMaxChunkSize?: number): { | ||
leftover: Buffer; | ||
@@ -23,4 +23,4 @@ payloads: Buffer[]; | ||
*/ | ||
export function netstringDecoderStream(optMaxChunkSize?: number | undefined): Transform; | ||
export function netstringDecoderStream(optMaxChunkSize?: number): Transform; | ||
import { Transform } from 'stream'; | ||
//# sourceMappingURL=netstring.d.ts.map |
@@ -92,2 +92,3 @@ /* eslint-env node */ | ||
export function netstringDecoderStream(optMaxChunkSize) { | ||
/** @type {Buffer<ArrayBufferLike>} */ | ||
let buffered = Buffer.from(''); | ||
@@ -94,0 +95,0 @@ /** |
@@ -16,4 +16,4 @@ /** | ||
*/ | ||
constructor(options?: (import("stream").TransformOptions & BufferLineTransformOptions) | undefined); | ||
_breakValue: string | number | Buffer; | ||
constructor(options?: import("node:stream").TransformOptions & BufferLineTransformOptions); | ||
_breakValue: string | number | Buffer<ArrayBufferLike>; | ||
_breakEncoding: BufferEncoding | undefined; | ||
@@ -38,3 +38,3 @@ _breakLength: number; | ||
*/ | ||
break?: string | number | Buffer | undefined; | ||
break?: string | number | Buffer<ArrayBufferLike> | undefined; | ||
/** | ||
@@ -41,0 +41,0 @@ * if break is a string, the encoding |
@@ -1,2 +0,2 @@ | ||
export function fsStreamReady(stream: import("fs").ReadStream | import("fs").WriteStream): Promise<void>; | ||
export function fsStreamReady(stream: import("fs").ReadStream | import("fs").WriteStream | import("net").Socket): Promise<void>; | ||
export function makeFsStreamWriter(filePath: string | undefined | null): Promise<{ | ||
@@ -3,0 +3,0 @@ write: (data: any) => Promise<void>; |
import { createWriteStream } from 'node:fs'; | ||
import process from 'node:process'; | ||
import { open } from 'node:fs/promises'; | ||
/** | ||
* @param {import('fs').ReadStream | import('fs').WriteStream} stream | ||
* @param {import('fs').ReadStream | ||
* | import('fs').WriteStream | ||
* | import('net').Socket} stream | ||
* @returns {Promise<void>} | ||
@@ -21,3 +24,3 @@ */ | ||
const onReady = () => { | ||
cleanup(); // eslint-disable-line no-use-before-define | ||
cleanup(); | ||
resolve(); | ||
@@ -28,3 +31,3 @@ }; | ||
const onError = err => { | ||
cleanup(); // eslint-disable-line no-use-before-define | ||
cleanup(); | ||
reject(err); | ||
@@ -53,5 +56,7 @@ }; | ||
const handle = await open(filePath, 'a'); | ||
const handle = await (filePath !== '-' ? open(filePath, 'a') : undefined); | ||
const stream = createWriteStream(noPath, { fd: handle.fd }); | ||
const stream = handle | ||
? createWriteStream(noPath, { fd: handle.fd }) | ||
: process.stdout; | ||
await fsStreamReady(stream); | ||
@@ -62,27 +67,31 @@ | ||
const write = async data => { | ||
if (closed) { | ||
throw Error('Stream closed'); | ||
} | ||
/** @type {Promise<void>} */ | ||
const written = new Promise((resolve, reject) => { | ||
stream.write(data, err => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
const updateFlushed = p => { | ||
flushed = flushed.then( | ||
() => written, | ||
async err => | ||
Promise.reject( | ||
written.then( | ||
() => err, | ||
writtenError => AggregateError([err, writtenError]), | ||
), | ||
() => p, | ||
err => | ||
p.then( | ||
() => Promise.reject(err), | ||
pError => | ||
Promise.reject( | ||
pError !== err ? AggregateError([err, pError]) : err, | ||
), | ||
), | ||
); | ||
flushed.catch(() => {}); | ||
}; | ||
const write = async data => { | ||
/** @type {Promise<void>} */ | ||
const written = closed | ||
? Promise.reject(Error('Stream closed')) | ||
: new Promise((resolve, reject) => { | ||
stream.write(data, err => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
updateFlushed(written); | ||
return written; | ||
@@ -93,3 +102,3 @@ }; | ||
await flushed; | ||
await handle.sync().catch(err => { | ||
await handle?.sync().catch(err => { | ||
if (err.code === 'EINVAL') { | ||
@@ -103,8 +112,12 @@ return; | ||
const close = async () => { | ||
// TODO: Consider creating a single Error here to use a write rejection | ||
closed = true; | ||
await flush(); | ||
stream.close(); | ||
// @ts-expect-error calling a possibly missing method | ||
stream.close?.(); | ||
}; | ||
stream.on('error', err => updateFlushed(Promise.reject(err))); | ||
return harden({ write, flush, close }); | ||
}; |
@@ -25,3 +25,2 @@ import process from 'node:process'; | ||
process.off('beforeExit', shutdown); | ||
// eslint-disable-next-line no-use-before-define | ||
process.off('uncaughtException', uncaughtShutdown); | ||
@@ -28,0 +27,0 @@ verbose && console.error(`Shutting down cleanly...`); |
@@ -12,2 +12,6 @@ export function slotToRemotable(_slotId: string, iface?: string): import("@endo/pass-style").RemotableObject<string> & import("@endo/eventual-send").RemotableBrand<{}, {}>; | ||
}; | ||
export namespace defaultSerializer { | ||
let parse: (text: string) => unknown; | ||
let stringify: (obj: any) => string; | ||
} | ||
export const slotStringUnserialize: (capData: any) => any; | ||
@@ -24,2 +28,3 @@ export function makeFakeStorageKit(rootPath: string, rootOptions?: Parameters<typeof makeChainStorageRoot>[2]): { | ||
data: Map<string, string>; | ||
getValues: (path: string) => string[]; | ||
messages: StorageMessage[]; | ||
@@ -43,3 +48,5 @@ toStorage: ((message: StorageMessage) => string | number | any[] | { | ||
replacement: string; | ||
} | {})): Promise<void>; | ||
} | {}) & { | ||
showValue?: (v: string) => unknown; | ||
}): Promise<void>; | ||
export type FakeStorageKit = ReturnType<typeof makeFakeStorageKit>; | ||
@@ -46,0 +53,0 @@ export type MockChainStorageRootMethods = { |
@@ -5,5 +5,6 @@ // @ts-check | ||
import { makeMarshal, Remotable } from '@endo/marshal'; | ||
import { unmarshalFromVstorage } from './marshal.js'; | ||
import { makeTracer } from './debug.js'; | ||
import { NonNullish } from './errors.js'; | ||
import { isStreamCell, makeChainStorageRoot } from './lib-chainStorage.js'; | ||
import { unmarshalFromVstorage } from './marshal.js'; | ||
import { bindAllMethods } from './method-tools.js'; | ||
@@ -38,2 +39,12 @@ import { eventLoopIteration } from './testing-utils.js'; | ||
/** | ||
* Serialize/deserialize functions using {@link defaultMarshaller} | ||
*/ | ||
export const defaultSerializer = { | ||
/** @type {(text: string) => unknown} */ | ||
parse: txt => defaultMarshaller.fromCapData(JSON.parse(txt)), | ||
/** @type {(obj: any) => string} */ | ||
stringify: obj => JSON.stringify(defaultMarshaller.toCapData(obj)), | ||
}; | ||
/** | ||
* A deserializer which produces slot strings instead of Remotables, so if `a = | ||
@@ -194,2 +205,17 @@ * Far('iface')`, and serializing `{ a }` into `capData` assigned it slot | ||
const rootNode = makeChainStorageRoot(toStorage, rootPath, resolvedOptions); | ||
/** | ||
* Get the values at a sequence node | ||
* | ||
* @param {string} path | ||
* @returns {string[]} | ||
*/ | ||
const getValues = path => { | ||
assert(resolvedOptions.sequence); | ||
const nodeData = data.get(path); | ||
assert(nodeData, `no data at path ${path}`); | ||
const wrapper = JSON.parse(nodeData); | ||
return wrapper.values; | ||
}; | ||
return { | ||
@@ -199,2 +225,3 @@ rootNode, | ||
data: /** @type {Map<string, string>} */ (data), | ||
getValues, | ||
messages, | ||
@@ -257,3 +284,5 @@ toStorage, | ||
* @param {({ note: string } | { node: string; owner: string }) & | ||
* ({ pattern: string; replacement: string } | {})} opts | ||
* ({ pattern: string; replacement: string } | {}) & { | ||
* showValue?: (v: string) => unknown; | ||
* }} opts | ||
*/ | ||
@@ -264,6 +293,15 @@ export const documentStorageSchema = async (t, storage, opts) => { | ||
const getLast = (/** @type {string} */ cell) => | ||
JSON.parse(cell).values.at(-1) || assert.fail(); | ||
const { showValue = s => s } = opts; | ||
/** @type {(d: Map<string, string>, k: string) => unknown} */ | ||
const getBodyDefault = (d, k) => showValue(getLast(NonNullish(d.get(k)))); | ||
const [keys, getBody] = | ||
'keys' in storage | ||
? [storage.keys(), (/** @type {string} */ k) => storage.getBody(k)] | ||
: [storage.data.keys(), (/** @type {string} */ k) => storage.data.get(k)]; | ||
: [ | ||
storage.data.keys(), | ||
(/** @type {string} */ k) => getBodyDefault(storage.data, k), | ||
]; | ||
@@ -274,11 +312,18 @@ const { pattern, replacement } = | ||
: { pattern: 'mockChainStorageRoot.', replacement: 'published.' }; | ||
const illustration = [...keys].sort().map( | ||
const pruned = [...keys] | ||
.sort() | ||
.filter( | ||
'node' in opts | ||
? key => | ||
key | ||
.replace(pattern, replacement) | ||
.startsWith(`published.${opts.node}`) | ||
: _entry => true, | ||
); | ||
const illustration = pruned.map( | ||
/** @type {(k: string) => [string, unknown]} */ | ||
key => [key.replace(pattern, replacement), getBody(key)], | ||
); | ||
const pruned = illustration.filter( | ||
'node' in opts | ||
? ([key, _]) => key.startsWith(`published.${opts.node}`) | ||
: _entry => true, | ||
); | ||
@@ -293,3 +338,3 @@ const note = | ||
See also board marshalling conventions (_to appear_).`; | ||
t.snapshot(pruned, note + boilerplate); | ||
t.snapshot(illustration, note + boilerplate); | ||
}; |
import type { ERef, RemotableBrand } from '@endo/eventual-send'; | ||
import type { Primitive } from '@endo/pass-style'; | ||
import type { Pattern } from '@endo/patterns'; | ||
import type { Callable } from './utils.js'; | ||
import type { Callable } from './ses-utils.js'; | ||
/** | ||
@@ -6,0 +6,0 @@ * A map corresponding with a total function such that `get(key)` is assumed to |
@@ -5,3 +5,3 @@ /* eslint-disable max-classes-per-file */ | ||
import type { Pattern } from '@endo/patterns'; | ||
import type { Callable } from './utils.js'; | ||
import type { Callable } from './ses-utils.js'; | ||
@@ -8,0 +8,0 @@ /** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
173558
115
3966
5
Updated@endo/common@^1.2.8
Updated@endo/errors@^1.2.8
Updated@endo/far@^1.1.9
Updated@endo/init@^1.1.7
Updated@endo/marshal@^1.6.2
Updated@endo/pass-style@^1.4.7
Updated@endo/patterns@^1.4.7
Updated@endo/promise-kit@^1.1.8
Updated@endo/stream@^1.2.8