@agoric/internal
Advanced tools
Comparing version 0.4.0-upgrade-17-dev-ec448b0.0 to 0.4.0-upgrade-18-dev-1c820e7.0
{ | ||
"name": "@agoric/internal", | ||
"version": "0.4.0-upgrade-17-dev-ec448b0.0+ec448b0", | ||
"version": "0.4.0-upgrade-18-dev-1c820e7.0+1c820e7", | ||
"description": "Externally unsupported utilities internal to agoric-sdk", | ||
@@ -13,3 +13,3 @@ "type": "module", | ||
"prepack": "tsc --build tsconfig.build.json", | ||
"postpack": "git clean -f '*.d.ts*'", | ||
"postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'", | ||
"test": "ava", | ||
@@ -24,12 +24,12 @@ "test:nyc": "exit 0", | ||
"dependencies": { | ||
"@agoric/base-zone": "0.1.1-upgrade-17-dev-ec448b0.0+ec448b0", | ||
"@endo/common": "^1.2.5", | ||
"@endo/errors": "^1.2.5", | ||
"@endo/far": "^1.1.5", | ||
"@endo/init": "^1.1.4", | ||
"@endo/marshal": "^1.5.3", | ||
"@endo/pass-style": "^1.4.3", | ||
"@endo/patterns": "^1.4.3", | ||
"@endo/promise-kit": "^1.1.5", | ||
"@endo/stream": "^1.2.5", | ||
"@agoric/base-zone": "0.1.1-upgrade-18-dev-1c820e7.0+1c820e7", | ||
"@endo/common": "^1.2.7", | ||
"@endo/errors": "^1.2.7", | ||
"@endo/far": "^1.1.8", | ||
"@endo/init": "^1.1.6", | ||
"@endo/marshal": "^1.6.1", | ||
"@endo/pass-style": "^1.4.6", | ||
"@endo/patterns": "^1.4.6", | ||
"@endo/promise-kit": "^1.1.7", | ||
"@endo/stream": "^1.2.7", | ||
"anylogger": "^0.21.0", | ||
@@ -39,4 +39,4 @@ "jessie.js": "^0.3.4" | ||
"devDependencies": { | ||
"@endo/exo": "^1.5.3", | ||
"@endo/init": "^1.1.4", | ||
"@endo/exo": "^1.5.6", | ||
"@endo/init": "^1.1.6", | ||
"ava": "^5.3.0", | ||
@@ -63,5 +63,5 @@ "tsd": "^0.31.1" | ||
"typeCoverage": { | ||
"atLeast": 93.32 | ||
"atLeast": 93.42 | ||
}, | ||
"gitHead": "ec448b081ac21cbe217f210e06f0b8f7989e73d6" | ||
"gitHead": "1c820e7455802a28c70d6a0ae3a8265ecf42435d" | ||
} |
@@ -17,2 +17,3 @@ export const AG_COSMOS_INIT: "AG_COSMOS_INIT"; | ||
export const VTRANSFER_IBC_EVENT: "VTRANSFER_IBC_EVENT"; | ||
export const KERNEL_UPGRADE_EVENTS: "KERNEL_UPGRADE_EVENTS"; | ||
//# sourceMappingURL=action-types.d.ts.map |
@@ -19,1 +19,2 @@ // @jessie-check | ||
export const VTRANSFER_IBC_EVENT = 'VTRANSFER_IBC_EVENT'; | ||
export const KERNEL_UPGRADE_EVENTS = 'KERNEL_UPGRADE_EVENTS'; |
@@ -0,1 +1,5 @@ | ||
/** | ||
* Event source ids used by the bridge device. | ||
*/ | ||
export type BridgeId = (typeof BridgeId)[keyof typeof BridgeId]; | ||
export namespace BridgeId { | ||
@@ -33,3 +37,2 @@ let BANK: "bank"; | ||
} | ||
export type BridgeIdValue = (typeof BridgeId)[keyof typeof BridgeId]; | ||
//# sourceMappingURL=config.d.ts.map |
@@ -18,2 +18,4 @@ // @ts-check | ||
* Event source ids used by the bridge device. | ||
* | ||
* @enum {(typeof BridgeId)[keyof typeof BridgeId]} | ||
*/ | ||
@@ -32,3 +34,2 @@ export const BridgeId = /** @type {const} */ ({ | ||
harden(BridgeId); | ||
/** @typedef {(typeof BridgeId)[keyof typeof BridgeId]} BridgeIdValue */ | ||
@@ -35,0 +36,0 @@ export const CosmosInitKeyToBridgeId = { |
@@ -8,3 +8,3 @@ export * from "./config.js"; | ||
export * from "./typeGuards.js"; | ||
export * from "./types.js"; | ||
export * from "./types-index.js"; | ||
export { objectMap } from "@endo/common/object-map.js"; | ||
@@ -11,0 +11,0 @@ export { objectMetaMap } from "@endo/common/object-meta-map.js"; |
@@ -14,3 +14,3 @@ // @jessie-check | ||
// eslint-disable-next-line import/export -- just types | ||
export * from './types.js'; | ||
export * from './types-index.js'; | ||
@@ -17,0 +17,0 @@ export { objectMap } from '@endo/common/object-map.js'; |
// @ts-check | ||
import { Fail } from '@endo/errors'; | ||
import { E } from '@endo/far'; | ||
import { E, Far } from '@endo/far'; | ||
import { M } from '@endo/patterns'; | ||
@@ -281,3 +281,6 @@ import { makeHeapZone } from '@agoric/base-zone/heap.js'; | ||
// XXX re-use "ChainStorage" methods above which don't actually depend on chains | ||
return makeChainStorageRoot(() => null, 'null'); | ||
return makeChainStorageRoot( | ||
Far('NullMessenger', () => null), | ||
'null', | ||
); | ||
}; | ||
@@ -284,0 +287,0 @@ |
@@ -1,2 +0,2 @@ | ||
/* global Buffer */ | ||
/* eslint-env node */ | ||
import { Transform } from 'stream'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
/* global Buffer */ | ||
/* eslint-env node */ | ||
import { Fail } from '@endo/errors'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
/* global Buffer */ | ||
/* eslint-env node */ | ||
/* eslint-disable no-underscore-dangle */ | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
/* global process */ | ||
/* eslint-env node */ | ||
// Use modules not prefixed with `node:` since some deploy scripts may | ||
@@ -3,0 +3,0 @@ // still be running in esm emulation |
@@ -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>} | ||
@@ -51,5 +54,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); | ||
@@ -60,27 +65,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; | ||
@@ -91,3 +100,3 @@ }; | ||
await flushed; | ||
await handle.sync().catch(err => { | ||
await handle?.sync().catch(err => { | ||
if (err.code === 'EINVAL') { | ||
@@ -101,8 +110,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 }); | ||
}; |
@@ -1,2 +0,2 @@ | ||
export function slotToRemotable(_slotId: string, iface?: string): import("@endo/marshal").RemotableObject<string> & import("@endo/eventual-send").RemotableBrand<{}, {}>; | ||
export function slotToRemotable(_slotId: string, iface?: string): import("@endo/pass-style").RemotableObject<string> & import("@endo/eventual-send").RemotableBrand<{}, {}>; | ||
/** | ||
@@ -24,6 +24,9 @@ * A basic marshaller whose unserializer produces Remotables. It can only | ||
messages: StorageMessage[]; | ||
toStorage: (message: StorageMessage) => string | number | any[] | { | ||
toStorage: ((message: StorageMessage) => string | number | any[] | { | ||
storeName: string; | ||
storeSubkey: string; | ||
} | null | undefined; | ||
} | null | undefined) & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, (message: StorageMessage) => string | number | any[] | { | ||
storeName: string; | ||
storeSubkey: string; | ||
} | null | undefined>; | ||
}; | ||
@@ -30,0 +33,0 @@ export function makeMockChainStorageRoot(): MockChainStorageRoot; |
@@ -111,78 +111,82 @@ // @ts-check | ||
const messages = []; | ||
/** @param {StorageMessage} message */ | ||
const toStorage = message => { | ||
messages.push(message); | ||
switch (message.method) { | ||
case 'getStoreKey': { | ||
const [key] = message.args; | ||
return { storeName: 'swingset', storeSubkey: `fake:${key}` }; | ||
} | ||
case 'get': { | ||
const [key] = message.args; | ||
return data.has(key) ? data.get(key) : null; | ||
} | ||
case 'children': { | ||
const [key] = message.args; | ||
const childEntries = getChildEntries(`${key}.`); | ||
return [...childEntries.keys()]; | ||
} | ||
case 'entries': { | ||
const [key] = message.args; | ||
const childEntries = getChildEntries(`${key}.`); | ||
return [...childEntries.entries()].map(entry => | ||
entry[1] != null ? entry : [entry[0]], | ||
); | ||
} | ||
case 'set': | ||
case 'setWithoutNotify': { | ||
trace('toStorage set', message); | ||
/** @type {StorageEntry[]} */ | ||
const newEntries = message.args; | ||
for (const [key, value] of newEntries) { | ||
if (value != null) { | ||
data.set(key, value); | ||
} else { | ||
data.delete(key); | ||
const toStorage = Far( | ||
'ToStorage', | ||
/** @param {StorageMessage} message */ | ||
message => { | ||
messages.push(message); | ||
switch (message.method) { | ||
case 'getStoreKey': { | ||
const [key] = message.args; | ||
return { storeName: 'swingset', storeSubkey: `fake:${key}` }; | ||
} | ||
case 'get': { | ||
const [key] = message.args; | ||
return data.has(key) ? data.get(key) : null; | ||
} | ||
case 'children': { | ||
const [key] = message.args; | ||
const childEntries = getChildEntries(`${key}.`); | ||
return [...childEntries.keys()]; | ||
} | ||
case 'entries': { | ||
const [key] = message.args; | ||
const childEntries = getChildEntries(`${key}.`); | ||
return [...childEntries.entries()].map(entry => | ||
entry[1] != null ? entry : [entry[0]], | ||
); | ||
} | ||
case 'set': | ||
case 'setWithoutNotify': { | ||
trace('toStorage set', message); | ||
/** @type {StorageEntry[]} */ | ||
const newEntries = message.args; | ||
for (const [key, value] of newEntries) { | ||
if (value != null) { | ||
data.set(key, value); | ||
} else { | ||
data.delete(key); | ||
} | ||
} | ||
break; | ||
} | ||
break; | ||
} | ||
case 'append': { | ||
trace('toStorage append', message); | ||
/** @type {StorageEntry[]} */ | ||
const newEntries = message.args; | ||
for (const [key, value] of newEntries) { | ||
value != null || Fail`attempt to append with no value`; | ||
// In the absence of block boundaries, everything goes in a single StreamCell. | ||
const oldVal = data.get(key); | ||
let streamCell; | ||
if (oldVal != null) { | ||
try { | ||
streamCell = JSON.parse(oldVal); | ||
assert(isStreamCell(streamCell)); | ||
} catch (_err) { | ||
streamCell = undefined; | ||
case 'append': { | ||
trace('toStorage append', message); | ||
/** @type {StorageEntry[]} */ | ||
const newEntries = message.args; | ||
for (const [key, value] of newEntries) { | ||
value != null || Fail`attempt to append with no value`; | ||
// In the absence of block boundaries, everything goes in a single StreamCell. | ||
const oldVal = data.get(key); | ||
let streamCell; | ||
if (oldVal != null) { | ||
try { | ||
streamCell = JSON.parse(oldVal); | ||
assert(isStreamCell(streamCell)); | ||
} catch (_err) { | ||
streamCell = undefined; | ||
} | ||
} | ||
if (streamCell === undefined) { | ||
streamCell = { | ||
blockHeight: '0', | ||
values: oldVal != null ? [oldVal] : [], | ||
}; | ||
} | ||
streamCell.values.push(value); | ||
data.set(key, JSON.stringify(streamCell)); | ||
} | ||
if (streamCell === undefined) { | ||
streamCell = { | ||
blockHeight: '0', | ||
values: oldVal != null ? [oldVal] : [], | ||
}; | ||
} | ||
streamCell.values.push(value); | ||
data.set(key, JSON.stringify(streamCell)); | ||
break; | ||
} | ||
break; | ||
case 'size': | ||
// Intentionally incorrect because it counts non-child descendants, | ||
// but nevertheless supports a "has children" test. | ||
return [...data.keys()].filter(k => | ||
k.startsWith(`${message.args[0]}.`), | ||
).length; | ||
default: | ||
throw Error(`unsupported method: ${message.method}`); | ||
} | ||
case 'size': | ||
// Intentionally incorrect because it counts non-child descendants, | ||
// but nevertheless supports a "has children" test. | ||
return [...data.keys()].filter(k => k.startsWith(`${message.args[0]}.`)) | ||
.length; | ||
default: | ||
throw Error(`unsupported method: ${message.method}`); | ||
} | ||
}; | ||
}, | ||
); | ||
const rootNode = makeChainStorageRoot(toStorage, rootPath, resolvedOptions); | ||
@@ -189,0 +193,0 @@ return { |
@@ -1,6 +0,5 @@ | ||
/* eslint-disable max-classes-per-file */ | ||
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'; | ||
/** | ||
@@ -11,28 +10,17 @@ * A map corresponding with a total function such that `get(key)` is assumed to | ||
export type TotalMap<K, V> = Omit<Map<K, V>, 'get'> & { | ||
/** Returns the element associated with the specified key in the TotalMap. */ | ||
get: (key: K) => V; | ||
/** Returns the element associated with the specified key in the TotalMap. */ | ||
get: (key: K) => V; | ||
}; | ||
export type TotalMapFrom<M extends Map> = | ||
M extends Map<infer K, infer V> ? TotalMap<K, V> : never; | ||
export type TotalMapFrom<M extends Map<any, any>> = M extends Map<infer K, infer V> ? TotalMap<K, V> : never; | ||
export declare class Callback<I extends (...args: any[]) => any> { | ||
private iface: I; | ||
public target: any; | ||
public methodName?: PropertyKey; | ||
public bound: unknown[]; | ||
public isSync: boolean; | ||
private iface; | ||
target: any; | ||
methodName?: PropertyKey; | ||
bound: unknown[]; | ||
isSync: boolean; | ||
} | ||
export declare class SyncCallback< | ||
I extends (...args: unknown[]) => any, | ||
> extends Callback<I> { | ||
private syncIface: I; | ||
public isSync: true; | ||
export declare class SyncCallback<I extends (...args: unknown[]) => any> extends Callback<I> { | ||
private syncIface; | ||
isSync: true; | ||
} | ||
/** | ||
@@ -54,11 +42,6 @@ Returns a boolean for whether the given type is primitive value or primitive type. | ||
export type IsPrimitive<T> = [T] extends [Primitive] ? true : false; | ||
/** Recursively extract the non-callable properties of T */ | ||
export type DataOnly<T> = | ||
IsPrimitive<T> extends true | ||
? T | ||
: T extends Callable | ||
? never | ||
: { [P in keyof T as T[P] extends Callable ? never : P]: DataOnly<T[P]> }; | ||
export type DataOnly<T> = IsPrimitive<T> extends true ? T : T extends Callable ? never : { | ||
[P in keyof T as T[P] extends Callable ? never : P]: DataOnly<T[P]>; | ||
}; | ||
/** | ||
@@ -69,20 +52,7 @@ * A type that doesn't assume its parameter is local, but is satisfied with both | ||
*/ | ||
export type Remote<Primary, Local = DataOnly<Primary>> = | ||
| Primary | ||
| RemotableBrand<Local, Primary>; | ||
// TODO: Add type tests for FarRef and Remote. | ||
export type Remote<Primary, Local = DataOnly<Primary>> = Primary | RemotableBrand<Local, Primary>; | ||
/** | ||
* Potentially remote promises or settled references. | ||
*/ | ||
export type FarRef<Primary, Local = DataOnly<Primary>> = ERef< | ||
Remote<Primary, Local> | ||
>; | ||
/* | ||
* Stop-gap until https://github.com/Agoric/agoric-sdk/issues/6160 | ||
* explictly specify the type that the Pattern will verify through a match. | ||
* | ||
* TODO move all this pattern typing stuff to @endo/patterns | ||
*/ | ||
export type FarRef<Primary, Local = DataOnly<Primary>> = ERef<Remote<Primary, Local>>; | ||
declare const validatedType: unique symbol; | ||
@@ -92,8 +62,6 @@ /** | ||
*/ | ||
export type TypedPattern<T> = Pattern & { [validatedType]?: T }; | ||
export declare type PatternType<TM extends TypedPattern<any>> = | ||
TM extends TypedPattern<infer T> ? T : never; | ||
// TODO make Endo's mustMatch do this | ||
export type TypedPattern<T> = Pattern & { | ||
[validatedType]?: T; | ||
}; | ||
export declare type PatternType<TM extends TypedPattern<any>> = TM extends TypedPattern<infer T> ? T : never; | ||
/** | ||
@@ -107,6 +75,4 @@ * Returning normally indicates success. Match failure is indicated by | ||
*/ | ||
export declare type MustMatch = <P extends Pattern>( | ||
specimen: unknown, | ||
pattern: P, | ||
label?: string | number, | ||
) => asserts specimen is P extends TypedPattern<any> ? PatternType<P> : unknown; | ||
export declare type MustMatch = <P extends Pattern>(specimen: unknown, pattern: P, label?: string | number) => asserts specimen is P extends TypedPattern<any> ? PatternType<P> : unknown; | ||
export {}; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -8,2 +8,3 @@ export namespace UpgradeDisconnectionShape { | ||
export function isUpgradeDisconnection(reason: any): reason is UpgradeDisconnection; | ||
export function isAbandonedError(reason: any): reason is Error; | ||
/** | ||
@@ -10,0 +11,0 @@ * An Error-like object for use as the rejection reason of promises abandoned by |
@@ -48,3 +48,27 @@ // @ts-check | ||
export const isUpgradeDisconnection = reason => | ||
isFrozen(reason) && matches(reason, UpgradeDisconnectionShape); | ||
reason != null && // eslint-disable-line eqeqeq | ||
isFrozen(reason) && | ||
matches(reason, UpgradeDisconnectionShape); | ||
harden(isUpgradeDisconnection); | ||
/** | ||
* Returns whether a reason is a 'vat terminated' error generated when an object | ||
* is abandoned by a vat during an upgrade. | ||
* | ||
* Normally we do not want to rely on the `message` of an error object, but this | ||
* is a pragmatic solution to the current state of vat upgrade errors. In the | ||
* future we'd prefer having an error with a cause referencing a disconnection | ||
* object like for promise rejections. See | ||
* https://github.com/Agoric/agoric-sdk/issues/9582 | ||
* | ||
* @param {any} reason | ||
* @returns {reason is Error} | ||
*/ | ||
export const isAbandonedError = reason => | ||
reason != null && // eslint-disable-line eqeqeq | ||
isFrozen(reason) && | ||
matches(reason, M.error()) && | ||
// We're not using a constant here since this special value is already | ||
// sprinkled throughout the SDK | ||
reason.message === 'vat terminated'; | ||
harden(isAbandonedError); |
@@ -404,2 +404,6 @@ // @ts-check | ||
}, | ||
// eslint-disable-next-line no-restricted-globals | ||
async [Symbol.asyncDispose]() { | ||
await reader.return(); | ||
}, | ||
}); | ||
@@ -406,0 +410,0 @@ return reader; |
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
164597
109
3733
Updated@agoric/base-zone@0.1.1-upgrade-18-dev-1c820e7.0+1c820e7
Updated@endo/common@^1.2.7
Updated@endo/errors@^1.2.7
Updated@endo/far@^1.1.8
Updated@endo/init@^1.1.6
Updated@endo/marshal@^1.6.1
Updated@endo/pass-style@^1.4.6
Updated@endo/patterns@^1.4.6
Updated@endo/promise-kit@^1.1.7
Updated@endo/stream@^1.2.7