@agoric/internal 0.2.2-pismo-dev-50dc068.0 → 0.3.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/CHANGELOG.md +52 -0
- package/package.json +15 -7
- package/src/action-types.d.ts +16 -0
- package/src/action-types.d.ts.map +1 -0
- package/src/action-types.js +17 -0
- package/src/batched-deliver.d.ts +15 -0
- package/src/batched-deliver.d.ts.map +1 -0
- package/src/batched-deliver.js +50 -0
- package/src/callback.d.ts +23 -0
- package/src/callback.d.ts.map +1 -0
- package/src/callback.js +322 -0
- package/src/chain-storage-paths.d.ts +16 -0
- package/src/chain-storage-paths.d.ts.map +1 -0
- package/src/chain-storage-paths.js +17 -0
- package/src/config.d.ts +25 -0
- package/src/config.d.ts.map +1 -0
- package/src/config.js +20 -3
- package/src/debug.d.ts +2 -0
- package/src/debug.d.ts.map +1 -0
- package/src/debug.js +41 -0
- package/src/index.d.ts +6 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +7 -2
- package/src/lib-chainStorage.d.ts +179 -0
- package/src/lib-chainStorage.d.ts.map +1 -0
- package/src/lib-chainStorage.js +304 -0
- package/src/magic-cookie-test-only.d.ts +2 -0
- package/src/magic-cookie-test-only.d.ts.map +1 -0
- package/src/magic-cookie-test-only.js +11 -0
- package/src/method-tools.d.ts +3 -0
- package/src/method-tools.d.ts.map +1 -0
- package/src/method-tools.js +110 -0
- package/src/node/buffer-line-transform.d.ts +41 -0
- package/src/node/buffer-line-transform.d.ts.map +1 -0
- package/src/node/buffer-line-transform.js +119 -0
- package/src/node/createBundles.d.ts +4 -0
- package/src/node/createBundles.d.ts.map +1 -0
- package/src/node/createBundles.js +80 -0
- package/src/node/fs-stream.d.ts +8 -0
- package/src/node/fs-stream.d.ts.map +1 -0
- package/src/node/fs-stream.js +105 -0
- package/src/node/shutdown.d.ts +6 -0
- package/src/node/shutdown.d.ts.map +1 -0
- package/src/node/shutdown.js +81 -0
- package/src/priority-senders.d.ts +31 -0
- package/src/priority-senders.d.ts.map +1 -0
- package/src/priority-senders.js +104 -0
- package/src/queue.d.ts +2 -0
- package/src/queue.d.ts.map +1 -0
- package/src/queue.js +58 -0
- package/src/scratch.d.ts +19 -0
- package/src/scratch.d.ts.map +1 -0
- package/src/scratch.js +52 -0
- package/src/storage-test-utils.d.ts +99 -0
- package/src/storage-test-utils.d.ts.map +1 -0
- package/src/storage-test-utils.js +228 -0
- package/src/testing-utils.d.ts +2 -0
- package/src/testing-utils.d.ts.map +1 -0
- package/src/testing-utils.js +14 -0
- package/src/typeGuards.d.ts +2 -0
- package/src/typeGuards.d.ts.map +1 -0
- package/src/typeGuards.js +5 -0
- package/src/types.d.ts +20 -0
- package/src/upgrade-api.d.ts +8 -0
- package/src/upgrade-api.d.ts.map +1 -0
- package/src/upgrade-api.js +41 -0
- package/src/utils.d.ts +67 -0
- package/src/utils.d.ts.map +1 -0
- package/src/utils.js +232 -124
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { isObject } from '@endo/marshal';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @file method-tools use dynamic property lookup, which is not Jessie-compatible
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { getPrototypeOf, create, fromEntries, getOwnPropertyDescriptors } =
|
|
9
|
+
Object;
|
|
10
|
+
const { ownKeys, apply } = Reflect;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Prioritize symbols as earlier than strings.
|
|
14
|
+
*
|
|
15
|
+
* @param {string|symbol} a
|
|
16
|
+
* @param {string|symbol} b
|
|
17
|
+
* @returns {-1 | 0 | 1}
|
|
18
|
+
*/
|
|
19
|
+
const compareStringified = (a, b) => {
|
|
20
|
+
if (typeof a === typeof b) {
|
|
21
|
+
const left = String(a);
|
|
22
|
+
const right = String(b);
|
|
23
|
+
// eslint-disable-next-line no-nested-ternary
|
|
24
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
25
|
+
}
|
|
26
|
+
if (typeof a === 'symbol') {
|
|
27
|
+
assert(typeof b === 'string');
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
30
|
+
assert(typeof a === 'string');
|
|
31
|
+
assert(typeof b === 'symbol');
|
|
32
|
+
return 1;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* TODO Consolidate with the `getMethodNames` in `@endo/eventual-send`
|
|
37
|
+
*
|
|
38
|
+
* @template {PropertyKey} K
|
|
39
|
+
* @param {Record<K, any>} val
|
|
40
|
+
* @returns {K[]}
|
|
41
|
+
*/
|
|
42
|
+
export const getMethodNames = val => {
|
|
43
|
+
let layer = val;
|
|
44
|
+
const names = new Set(); // Set to deduplicate
|
|
45
|
+
while (layer !== null && layer !== Object.prototype) {
|
|
46
|
+
// be tolerant of non-objects
|
|
47
|
+
const descs = getOwnPropertyDescriptors(layer);
|
|
48
|
+
const ownNames = /** @type {K[]} */ (ownKeys(descs));
|
|
49
|
+
for (const name of ownNames) {
|
|
50
|
+
// In case a method is overridden by a non-method,
|
|
51
|
+
// test `val[name]` rather than `layer[name]`
|
|
52
|
+
if (typeof val[name] === 'function') {
|
|
53
|
+
names.add(name);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!isObject(val)) {
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
layer = getPrototypeOf(layer);
|
|
60
|
+
}
|
|
61
|
+
return harden([...names].sort(compareStringified));
|
|
62
|
+
};
|
|
63
|
+
harden(getMethodNames);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* TODO This function exists only to ease the
|
|
67
|
+
* https://github.com/Agoric/agoric-sdk/pull/5970 transition, from all methods
|
|
68
|
+
* being own properties to methods being inherited from a common prototype.
|
|
69
|
+
* This transition breaks two patterns used in prior code: autobinding,
|
|
70
|
+
* and enumerating methods by enumerating own properties. For both, the
|
|
71
|
+
* preferred repairs are
|
|
72
|
+
* * autobinding: Replace, for example,
|
|
73
|
+
* `foo(obj.method)` with `foo(arg => `obj.method(arg))`. IOW, stop relying
|
|
74
|
+
* on expressions like `obj.method` to extract a method still bound to the
|
|
75
|
+
* state of `obj` because, for virtual and durable objects,
|
|
76
|
+
* they no longer will after #5970.
|
|
77
|
+
* * method enumeration: Replace, for example
|
|
78
|
+
* `Reflect.ownKeys(obj)` with `getMethodNames(obj)`.
|
|
79
|
+
*
|
|
80
|
+
* Once all problematic cases have been converted in this manner, this
|
|
81
|
+
* `bindAllMethods` hack can and TODO should be deleted. However, we currently
|
|
82
|
+
* have no reliable static way to track down and fix all autobinding sites.
|
|
83
|
+
* For those objects that have not yet been fully repaired by the above two
|
|
84
|
+
* techniques, `bindAllMethods` creates an object that acts much like the
|
|
85
|
+
* pre-#5970 objects, with all their methods as instance-bound own properties.
|
|
86
|
+
* It does this by making a new object inheriting from `obj` where the new
|
|
87
|
+
* object has bound own methods overridding all the methods it would have
|
|
88
|
+
* inherited from `obj`.
|
|
89
|
+
*
|
|
90
|
+
* @template {Record<PropertyKey, any>} T
|
|
91
|
+
* @param {T} obj
|
|
92
|
+
* @returns {T}
|
|
93
|
+
*/
|
|
94
|
+
export const bindAllMethods = obj =>
|
|
95
|
+
harden(
|
|
96
|
+
create(
|
|
97
|
+
obj,
|
|
98
|
+
fromEntries(
|
|
99
|
+
getMethodNames(obj).map(name => [
|
|
100
|
+
name,
|
|
101
|
+
{
|
|
102
|
+
value: (/** @type {unknown[]} */ ...args) =>
|
|
103
|
+
apply(obj[name], obj, args),
|
|
104
|
+
enumerable: true,
|
|
105
|
+
},
|
|
106
|
+
]),
|
|
107
|
+
),
|
|
108
|
+
),
|
|
109
|
+
);
|
|
110
|
+
harden(bindAllMethods);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {object} BufferLineTransformOptions
|
|
4
|
+
* @property {Buffer | string | number} [break] line break matcher for Buffer.indexOf() (default: 10)
|
|
5
|
+
* @property {BufferEncoding} [breakEncoding] if break is a string, the encoding to use
|
|
6
|
+
*/
|
|
7
|
+
export default class BufferLineTransform extends Transform {
|
|
8
|
+
/**
|
|
9
|
+
* The BufferLineTransform is reading String or Buffer content from a Readable stream
|
|
10
|
+
* and writing each line as a Buffer in object mode
|
|
11
|
+
*
|
|
12
|
+
* @param {import('node:stream').TransformOptions & BufferLineTransformOptions} [options]
|
|
13
|
+
*/
|
|
14
|
+
constructor(options?: (import("stream").TransformOptions & BufferLineTransformOptions) | undefined);
|
|
15
|
+
_breakValue: string | number | Buffer;
|
|
16
|
+
_breakEncoding: BufferEncoding | undefined;
|
|
17
|
+
_breakLength: number;
|
|
18
|
+
/** @type {Array<Buffer>} */
|
|
19
|
+
_chunks: Array<Buffer>;
|
|
20
|
+
/**
|
|
21
|
+
* @override
|
|
22
|
+
* @param {any} chunk
|
|
23
|
+
* @param {BufferEncoding | 'buffer'} encoding
|
|
24
|
+
* @param {import('node:stream').TransformCallback} cb
|
|
25
|
+
*/
|
|
26
|
+
override _transform(chunk: any, encoding: BufferEncoding | 'buffer', cb: import('node:stream').TransformCallback): void;
|
|
27
|
+
/** @param {Buffer} line */
|
|
28
|
+
_writeItem(line: Buffer): void;
|
|
29
|
+
}
|
|
30
|
+
export type BufferLineTransformOptions = {
|
|
31
|
+
/**
|
|
32
|
+
* line break matcher for Buffer.indexOf() (default: 10)
|
|
33
|
+
*/
|
|
34
|
+
break?: string | number | Buffer | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* if break is a string, the encoding to use
|
|
37
|
+
*/
|
|
38
|
+
breakEncoding?: BufferEncoding | undefined;
|
|
39
|
+
};
|
|
40
|
+
import { Transform } from "stream";
|
|
41
|
+
//# sourceMappingURL=buffer-line-transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer-line-transform.d.ts","sourceRoot":"","sources":["buffer-line-transform.js"],"names":[],"mappings":";AAKA;;;;GAIG;AAEH;IACE;;;;;OAKG;IACH,oGAuBC;IAhBC,sCAAmC;IACnC,2CAAmC;IAWnC,qBAA+B;IAE/B,4BAA4B;IAC5B,SADW,MAAM,MAAM,CAAC,CACP;IAGnB;;;;;OAKG;IACH,2BAJW,GAAG,YACH,cAAc,GAAG,QAAQ,MACzB,OAAO,aAAa,EAAE,iBAAiB,QAgDjD;IAeD,2BAA2B;IAC3B,iBADY,MAAM,QAOjB;CACF"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/* global Buffer */
|
|
2
|
+
/* eslint-disable no-underscore-dangle */
|
|
3
|
+
|
|
4
|
+
import { Transform } from 'node:stream';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {object} BufferLineTransformOptions
|
|
8
|
+
* @property {Buffer | string | number} [break] line break matcher for Buffer.indexOf() (default: 10)
|
|
9
|
+
* @property {BufferEncoding} [breakEncoding] if break is a string, the encoding to use
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export default class BufferLineTransform extends Transform {
|
|
13
|
+
/**
|
|
14
|
+
* The BufferLineTransform is reading String or Buffer content from a Readable stream
|
|
15
|
+
* and writing each line as a Buffer in object mode
|
|
16
|
+
*
|
|
17
|
+
* @param {import('node:stream').TransformOptions & BufferLineTransformOptions} [options]
|
|
18
|
+
*/
|
|
19
|
+
constructor(options) {
|
|
20
|
+
const {
|
|
21
|
+
break: breakValue,
|
|
22
|
+
breakEncoding,
|
|
23
|
+
...transformOptions
|
|
24
|
+
} = options || {};
|
|
25
|
+
super({ ...transformOptions, readableObjectMode: true });
|
|
26
|
+
this._breakValue = breakValue || 10;
|
|
27
|
+
this._breakEncoding = breakEncoding;
|
|
28
|
+
|
|
29
|
+
/** @type {number} */
|
|
30
|
+
let breakLength;
|
|
31
|
+
if (!breakValue || typeof breakValue === 'number') {
|
|
32
|
+
breakLength = 1;
|
|
33
|
+
} else if (Buffer.isBuffer(breakValue)) {
|
|
34
|
+
breakLength = breakValue.length;
|
|
35
|
+
} else {
|
|
36
|
+
breakLength = Buffer.from(breakValue, breakEncoding).length;
|
|
37
|
+
}
|
|
38
|
+
this._breakLength = breakLength;
|
|
39
|
+
|
|
40
|
+
/** @type {Array<Buffer>} */
|
|
41
|
+
this._chunks = [];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @override
|
|
46
|
+
* @param {any} chunk
|
|
47
|
+
* @param {BufferEncoding | 'buffer'} encoding
|
|
48
|
+
* @param {import('node:stream').TransformCallback} cb
|
|
49
|
+
*/
|
|
50
|
+
_transform(chunk, encoding, cb) {
|
|
51
|
+
try {
|
|
52
|
+
/** @type {Buffer} */
|
|
53
|
+
let buf =
|
|
54
|
+
Buffer.isBuffer(chunk) || encoding === 'buffer'
|
|
55
|
+
? chunk
|
|
56
|
+
: Buffer.from(chunk, encoding);
|
|
57
|
+
|
|
58
|
+
// In case the break value is more than a single byte, it may span
|
|
59
|
+
// multiple chunks. Since Node doesn't provide a way to get partial
|
|
60
|
+
// search result, fallback to a less optimal early concatenation
|
|
61
|
+
if (this._breakLength > 1 && this._chunks.length) {
|
|
62
|
+
buf = Buffer.concat([/** @type {Buffer} */ (this._chunks.pop()), buf]);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
while (buf.length) {
|
|
66
|
+
const offset = buf.indexOf(this._breakValue, 0, this._breakEncoding);
|
|
67
|
+
|
|
68
|
+
/** @type {number} */
|
|
69
|
+
let endOffset;
|
|
70
|
+
if (offset >= 0) {
|
|
71
|
+
endOffset = offset + this._breakLength;
|
|
72
|
+
if (this._chunks.length) {
|
|
73
|
+
const concatLength = this._chunks.reduce(
|
|
74
|
+
(acc, { length }) => acc + length,
|
|
75
|
+
endOffset,
|
|
76
|
+
);
|
|
77
|
+
this._writeItem(
|
|
78
|
+
Buffer.concat(
|
|
79
|
+
[...this._chunks.splice(0, this._chunks.length), buf],
|
|
80
|
+
concatLength,
|
|
81
|
+
),
|
|
82
|
+
);
|
|
83
|
+
} else {
|
|
84
|
+
this._writeItem(buf.subarray(0, endOffset));
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
endOffset = buf.length;
|
|
88
|
+
this._chunks.push(buf);
|
|
89
|
+
}
|
|
90
|
+
buf = buf.subarray(endOffset);
|
|
91
|
+
}
|
|
92
|
+
cb();
|
|
93
|
+
} catch (err) {
|
|
94
|
+
cb(/** @type {any} */ (err)); // invalid data type;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @override
|
|
100
|
+
* @param {import('node:stream').TransformCallback} cb
|
|
101
|
+
*/
|
|
102
|
+
_flush(cb) {
|
|
103
|
+
if (this._chunks.length) {
|
|
104
|
+
this._writeItem(
|
|
105
|
+
Buffer.concat(this._chunks.splice(0, this._chunks.length)),
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
cb();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** @param {Buffer} line */
|
|
112
|
+
_writeItem(line) {
|
|
113
|
+
if (this.readableEncoding) {
|
|
114
|
+
this.push(line.toString(this.readableEncoding), this.readableEncoding);
|
|
115
|
+
} else {
|
|
116
|
+
this.push(line);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export function createBundlesFromAbsolute(sourceBundles: any): Promise<void>;
|
|
2
|
+
export function createBundles(sourceBundles: any, dirname?: string): Promise<void>;
|
|
3
|
+
export function extractProposalBundles(dirProposalBuilder: any, dirname?: string): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=createBundles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBundles.d.ts","sourceRoot":"","sources":["createBundles.js"],"names":[],"mappings":"AAUO,6EAyBN;AAEM,mFAMN;AAEM,iGAkCN"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Use modules not prefixed with `node:` since some deploy scripts may
|
|
2
|
+
// still be running in esm emulation
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { spawnSync } from 'child_process';
|
|
5
|
+
import { createRequire } from 'module';
|
|
6
|
+
|
|
7
|
+
const { Fail, quote: q } = assert;
|
|
8
|
+
const BUNDLE_SOURCE_PROGRAM = 'bundle-source';
|
|
9
|
+
const req = createRequire(import.meta.url);
|
|
10
|
+
|
|
11
|
+
export const createBundlesFromAbsolute = async sourceBundles => {
|
|
12
|
+
const prog = req.resolve(`.bin/${BUNDLE_SOURCE_PROGRAM}`);
|
|
13
|
+
|
|
14
|
+
const cacheToArgs = new Map();
|
|
15
|
+
for (const [srcPath, bundlePath] of sourceBundles) {
|
|
16
|
+
const cache = path.dirname(bundlePath);
|
|
17
|
+
const base = path.basename(bundlePath);
|
|
18
|
+
|
|
19
|
+
const match = base.match(/^bundle-(.*)\.js$/);
|
|
20
|
+
if (!match) {
|
|
21
|
+
throw Fail`${q(bundlePath)} is not 'DIR/bundle-NAME.js'`;
|
|
22
|
+
}
|
|
23
|
+
const bundle = match[1];
|
|
24
|
+
|
|
25
|
+
const args = cacheToArgs.get(cache) || ['--to', cache];
|
|
26
|
+
args.push(srcPath, bundle);
|
|
27
|
+
cacheToArgs.set(cache, args);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (const args of cacheToArgs.values()) {
|
|
31
|
+
console.log(BUNDLE_SOURCE_PROGRAM, ...args);
|
|
32
|
+
const { status } = spawnSync(prog, args, { stdio: 'inherit' });
|
|
33
|
+
status === 0 ||
|
|
34
|
+
Fail`${q(BUNDLE_SOURCE_PROGRAM)} failed with status ${q(status)}`;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const createBundles = async (sourceBundles, dirname = '.') => {
|
|
39
|
+
const absBundleSources = sourceBundles.map(([srcPath, bundlePath]) => [
|
|
40
|
+
req.resolve(srcPath, { paths: [dirname] }),
|
|
41
|
+
path.resolve(dirname, bundlePath),
|
|
42
|
+
]);
|
|
43
|
+
return createBundlesFromAbsolute(absBundleSources);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const extractProposalBundles = async (
|
|
47
|
+
dirProposalBuilder,
|
|
48
|
+
dirname = '.',
|
|
49
|
+
) => {
|
|
50
|
+
const toBundle = new Map();
|
|
51
|
+
|
|
52
|
+
await Promise.all(
|
|
53
|
+
dirProposalBuilder.map(async ([dir, proposalBuilder]) => {
|
|
54
|
+
const home = path.resolve(dirname, dir);
|
|
55
|
+
const publishRef = x => x;
|
|
56
|
+
const install = async (src, bundleName) => {
|
|
57
|
+
if (bundleName) {
|
|
58
|
+
const bundlePath = path.resolve(home, bundleName);
|
|
59
|
+
const srcPath = req.resolve(src, { paths: [home] });
|
|
60
|
+
if (toBundle.has(bundlePath)) {
|
|
61
|
+
const oldSrc = toBundle.get(bundlePath);
|
|
62
|
+
oldSrc === srcPath ||
|
|
63
|
+
Fail`${q(bundlePath)} already installed as ${q(
|
|
64
|
+
oldSrc,
|
|
65
|
+
)}, also given ${q(srcPath)}`;
|
|
66
|
+
}
|
|
67
|
+
toBundle.set(bundlePath, srcPath);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
return proposalBuilder({ publishRef, install });
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
return createBundlesFromAbsolute(
|
|
75
|
+
[...toBundle.entries()].map(([bundlePath, srcPath]) => [
|
|
76
|
+
srcPath,
|
|
77
|
+
bundlePath,
|
|
78
|
+
]),
|
|
79
|
+
);
|
|
80
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function fsStreamReady(stream: import("fs").ReadStream | import("fs").WriteStream): Promise<void>;
|
|
2
|
+
export function makeFsStreamWriter(filePath: string | undefined | null): Promise<{
|
|
3
|
+
write: (data: any) => Promise<void>;
|
|
4
|
+
flush: () => Promise<void>;
|
|
5
|
+
close: () => Promise<void>;
|
|
6
|
+
} | undefined>;
|
|
7
|
+
export type FsStreamWriter = NonNullable<Awaited<ReturnType<typeof makeFsStreamWriter>>>;
|
|
8
|
+
//# sourceMappingURL=fs-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-stream.d.ts","sourceRoot":"","sources":["fs-stream.js"],"names":[],"mappings":"AAQO,sCAHI,OAAO,IAAI,EAAE,UAAU,GAAG,OAAO,IAAI,EAAE,WAAW,GAChD,QAAQ,IAAI,CAAC,CAgCtB;AAQG,6CADK,MAAM,GAAG,SAAS,GAAG,IAAI;;;;eA2DpC;6BA5Da,YAAY,QAAQ,WAAW,yBAAyB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { createWriteStream } from 'node:fs';
|
|
2
|
+
import { open } from 'node:fs/promises';
|
|
3
|
+
import { makeAggregateError } from '../utils.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {import("fs").ReadStream | import("fs").WriteStream} stream
|
|
7
|
+
* @returns {Promise<void>}
|
|
8
|
+
*/
|
|
9
|
+
export const fsStreamReady = stream =>
|
|
10
|
+
new Promise((resolve, reject) => {
|
|
11
|
+
if (stream.destroyed) {
|
|
12
|
+
reject(Error('Stream already destroyed'));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!stream.pending) {
|
|
17
|
+
resolve();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const onReady = () => {
|
|
22
|
+
cleanup(); // eslint-disable-line no-use-before-define
|
|
23
|
+
resolve();
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** @param {Error} err */
|
|
27
|
+
const onError = err => {
|
|
28
|
+
cleanup(); // eslint-disable-line no-use-before-define
|
|
29
|
+
reject(err);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const cleanup = () => {
|
|
33
|
+
stream.off('ready', onReady);
|
|
34
|
+
stream.off('error', onError);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
stream.on('ready', onReady);
|
|
38
|
+
stream.on('error', onError);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const noPath = /** @type {import('fs').PathLike} */ (
|
|
42
|
+
/** @type {unknown} */ (undefined)
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
/** @typedef {NonNullable<Awaited<ReturnType<typeof makeFsStreamWriter>>>} FsStreamWriter */
|
|
46
|
+
/** @param {string | undefined | null} filePath */
|
|
47
|
+
export const makeFsStreamWriter = async filePath => {
|
|
48
|
+
if (!filePath) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const handle = await open(filePath, 'a');
|
|
53
|
+
|
|
54
|
+
const stream = createWriteStream(noPath, { fd: handle.fd });
|
|
55
|
+
await fsStreamReady(stream);
|
|
56
|
+
|
|
57
|
+
let flushed = Promise.resolve();
|
|
58
|
+
let closed = false;
|
|
59
|
+
|
|
60
|
+
const write = async data => {
|
|
61
|
+
if (closed) {
|
|
62
|
+
throw Error('Stream closed');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** @type {Promise<void>} */
|
|
66
|
+
const written = new Promise((resolve, reject) => {
|
|
67
|
+
stream.write(data, err => {
|
|
68
|
+
if (err) {
|
|
69
|
+
reject(err);
|
|
70
|
+
} else {
|
|
71
|
+
resolve();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
flushed = flushed.then(
|
|
76
|
+
() => written,
|
|
77
|
+
async err =>
|
|
78
|
+
Promise.reject(
|
|
79
|
+
written.then(
|
|
80
|
+
() => err,
|
|
81
|
+
writtenError => makeAggregateError([err, writtenError]),
|
|
82
|
+
),
|
|
83
|
+
),
|
|
84
|
+
);
|
|
85
|
+
return written;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const flush = async () => {
|
|
89
|
+
await flushed;
|
|
90
|
+
await handle.sync().catch(err => {
|
|
91
|
+
if (err.code === 'EINVAL') {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
throw err;
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const close = async () => {
|
|
99
|
+
closed = true;
|
|
100
|
+
await flush();
|
|
101
|
+
stream.close();
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return harden({ write, flush, close });
|
|
105
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shutdown.d.ts","sourceRoot":"","sources":["shutdown.js"],"names":[],"mappings":"AAKO;;EA+DN;AAGM,wDAON"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import anylogger from 'anylogger';
|
|
3
|
+
|
|
4
|
+
const console = anylogger('shutdown');
|
|
5
|
+
|
|
6
|
+
export const makeFreshShutdown = (verbose = true) => {
|
|
7
|
+
const shutdownThunks = new Set();
|
|
8
|
+
|
|
9
|
+
let shuttingDown = false;
|
|
10
|
+
/** @type {NodeJS.SignalsListener & NodeJS.BeforeExitListener} */
|
|
11
|
+
const shutdown = code => {
|
|
12
|
+
const sig = typeof code === 'string' && code.startsWith('SIG');
|
|
13
|
+
const isSigInt = code === 'SIGINT';
|
|
14
|
+
if (sig) {
|
|
15
|
+
process.exitCode = 98;
|
|
16
|
+
}
|
|
17
|
+
if (shuttingDown) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
shuttingDown = true;
|
|
21
|
+
// Allow an explicit exit to terminate the process.
|
|
22
|
+
process.off('SIGINT', shutdown);
|
|
23
|
+
process.off('SIGTERM', shutdown);
|
|
24
|
+
process.off('beforeExit', shutdown);
|
|
25
|
+
// eslint-disable-next-line no-use-before-define
|
|
26
|
+
process.off('uncaughtException', uncaughtShutdown);
|
|
27
|
+
verbose && console.error(`Shutting down cleanly...`);
|
|
28
|
+
const shutdowners = [...shutdownThunks.keys()];
|
|
29
|
+
shutdownThunks.clear();
|
|
30
|
+
Promise.allSettled(
|
|
31
|
+
[...shutdowners].map(t => Promise.resolve(isSigInt).then(t)),
|
|
32
|
+
)
|
|
33
|
+
.then(statuses => {
|
|
34
|
+
for (const status of statuses) {
|
|
35
|
+
if (status.status === 'rejected') {
|
|
36
|
+
verbose && console.warn(status.reason);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
verbose && console.warn('Process terminated!');
|
|
40
|
+
})
|
|
41
|
+
.catch(error => verbose && console.warn('Error shutting down', error))
|
|
42
|
+
.finally(() => {
|
|
43
|
+
// Let `beforeExit` exit cleanly
|
|
44
|
+
if (!(code >= 0)) {
|
|
45
|
+
process.exit();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const uncaughtShutdown = e => {
|
|
51
|
+
console.error(e);
|
|
52
|
+
shutdown(-1);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// gracefully shut down the thunks on process exit
|
|
56
|
+
process.on('SIGTERM', shutdown);
|
|
57
|
+
process.on('SIGINT', shutdown);
|
|
58
|
+
process.on('beforeExit', shutdown);
|
|
59
|
+
process.on('uncaughtException', uncaughtShutdown);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
registerShutdown: thunk => {
|
|
63
|
+
shutdownThunks.add(thunk);
|
|
64
|
+
return () => {
|
|
65
|
+
shutdownThunks.delete(thunk);
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
let cachedShutdown = null;
|
|
72
|
+
export const makeCachedShutdown = (...args) => {
|
|
73
|
+
// It's possible our caller has specified different arguments.
|
|
74
|
+
// Since they control verbosity only, first-one-wins is acceptable.
|
|
75
|
+
if (!cachedShutdown) {
|
|
76
|
+
cachedShutdown = makeFreshShutdown(...args);
|
|
77
|
+
}
|
|
78
|
+
return cachedShutdown;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export { makeCachedShutdown as makeShutdown };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** @type {(namespace: string) => string} */
|
|
2
|
+
export const normalizeSenderNamespace: (namespace: string) => string;
|
|
3
|
+
export function makePrioritySendersManager(sendersNode: ERef<import("./lib-chainStorage.js").StorageNode>): {
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} rawNamespace
|
|
6
|
+
* @param {string} address
|
|
7
|
+
* @returns {Promise<void>}
|
|
8
|
+
*/
|
|
9
|
+
add: (rawNamespace: string, address: string) => Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} rawNamespace
|
|
12
|
+
* @param {string} address
|
|
13
|
+
* @returns {Promise<void>}
|
|
14
|
+
*/
|
|
15
|
+
remove: (rawNamespace: string, address: string) => Promise<void>;
|
|
16
|
+
} & import("@endo/eventual-send").RemotableBrand<{}, {
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} rawNamespace
|
|
19
|
+
* @param {string} address
|
|
20
|
+
* @returns {Promise<void>}
|
|
21
|
+
*/
|
|
22
|
+
add: (rawNamespace: string, address: string) => Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} rawNamespace
|
|
25
|
+
* @param {string} address
|
|
26
|
+
* @returns {Promise<void>}
|
|
27
|
+
*/
|
|
28
|
+
remove: (rawNamespace: string, address: string) => Promise<void>;
|
|
29
|
+
}>;
|
|
30
|
+
export type PrioritySendersManager = ReturnType<typeof makePrioritySendersManager>;
|
|
31
|
+
//# sourceMappingURL=priority-senders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"priority-senders.d.ts","sourceRoot":"","sources":["priority-senders.js"],"names":[],"mappings":"AAMA,4CAA4C;AAC5C,mDADuB,MAAM,KAAK,MAAM,CAMtC;AAQK;IAoCH;;;;OAIG;wBAHQ,MAAM,WACN,MAAM,KACJ,QAAQ,IAAI,CAAC;IAe1B;;;;OAIG;2BAHQ,MAAM,WACN,MAAM,KACJ,QAAQ,IAAI,CAAC;;IArB1B;;;;OAIG;wBAHQ,MAAM,WACN,MAAM,KACJ,QAAQ,IAAI,CAAC;IAe1B;;;;OAIG;2BAHQ,MAAM,WACN,MAAM,KACJ,QAAQ,IAAI,CAAC;GAuB7B;qCAGa,WAAW,iCAAiC,CAAC"}
|