WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
test("coalesce", () => {
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
|
||||
// test("nonoptional with default", () => {
|
||||
// const schema = z.string().optional().coalesce("hi");
|
||||
// expectTypeOf<typeof schema._input>().toEqualTypeOf<string | undefined>();
|
||||
// expectTypeOf<typeof schema._output>().toEqualTypeOf<string>();
|
||||
// expect(schema.parse(undefined)).toBe("hi");
|
||||
// });
|
||||
|
||||
// test("nonoptional in object", () => {
|
||||
// const schema = z.object({ hi: z.string().optional().nonoptional("hi") });
|
||||
|
||||
// expectTypeOf<typeof schema._input>().toEqualTypeOf<{ hi: string | undefined }>();
|
||||
// expectTypeOf<typeof schema._output>().toEqualTypeOf<{ hi: string }>();
|
||||
// expect(schema.parse(undefined)).toBe("hi");
|
||||
// });
|
||||
@@ -0,0 +1,132 @@
|
||||
# secure-json-parse
|
||||
|
||||
[](https://github.com/fastify/secure-json-parse/actions/workflows/ci.yml)
|
||||
[](https://www.npmjs.com/package/secure-json-parse)
|
||||
[](https://github.com/neostandard/neostandard)
|
||||
|
||||
`JSON.parse()` drop-in replacement with prototype poisoning protection.
|
||||
|
||||
## Introduction
|
||||
|
||||
Consider this:
|
||||
|
||||
```js
|
||||
> const a = '{"__proto__":{ "b":5}}';
|
||||
'{"__proto__":{ "b":5}}'
|
||||
|
||||
> const b = JSON.parse(a);
|
||||
{ __proto__: { b: 5 } }
|
||||
|
||||
> b.b;
|
||||
undefined
|
||||
|
||||
> const c = Object.assign({}, b);
|
||||
{}
|
||||
|
||||
> c.b
|
||||
5
|
||||
```
|
||||
|
||||
The problem is that `JSON.parse()` retains the `__proto__` property as a plain object key. By
|
||||
itself, this is not a security issue. However, as soon as that object is assigned to another or
|
||||
iterated on and values copied, the `__proto__` property leaks and becomes the object's prototype.
|
||||
|
||||
## Install
|
||||
```
|
||||
npm i secure-json-parse
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Pass the option object as a second (or third) parameter for configuring the action to take in case of a bad JSON, if nothing is configured, the default is to throw a `SyntaxError`.<br/>
|
||||
You can choose which action to perform in case `__proto__` is present, and in case `constructor.prototype` is present.
|
||||
|
||||
```js
|
||||
const sjson = require('secure-json-parse')
|
||||
|
||||
const goodJson = '{ "a": 5, "b": 6 }'
|
||||
const badJson = '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "constructor": {"prototype": {"bar": "baz"} } }'
|
||||
|
||||
console.log(JSON.parse(goodJson), sjson.parse(goodJson, undefined, { protoAction: 'remove', constructorAction: 'remove' }))
|
||||
console.log(JSON.parse(badJson), sjson.parse(badJson, undefined, { protoAction: 'remove', constructorAction: 'remove' }))
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `sjson.parse(text, [reviver], [options])`
|
||||
|
||||
Parses a given JSON-formatted text into an object where:
|
||||
- `text` - the JSON text string.
|
||||
- `reviver` - the `JSON.parse()` optional `reviver` argument.
|
||||
- `options` - optional configuration object where:
|
||||
- `protoAction` - optional string with one of:
|
||||
- `'error'` - throw a `SyntaxError` when a `__proto__` key is found. This is the default value.
|
||||
- `'remove'` - deletes any `__proto__` keys from the result object.
|
||||
- `'ignore'` - skips all validation (same as calling `JSON.parse()` directly).
|
||||
- `constructorAction` - optional string with one of:
|
||||
- `'error'` - throw a `SyntaxError` when a `constructor.prototype` key is found. This is the default value.
|
||||
- `'remove'` - deletes any `constructor` keys from the result object.
|
||||
- `'ignore'` - skips all validation (same as calling `JSON.parse()` directly).
|
||||
- `safe` - optional boolean:
|
||||
- `true` - returns `null` instead of throwing when a forbidden prototype property is found.
|
||||
- `false` - default behavior (throws or removes based on `protoAction`/`constructorAction`).
|
||||
|
||||
### `sjson.scan(obj, [options])`
|
||||
|
||||
Scans a given object for prototype properties where:
|
||||
- `obj` - the object being scanned.
|
||||
- `options` - optional configuration object where:
|
||||
- `protoAction` - optional string with one of:
|
||||
- `'error'` - throw a `SyntaxError` when a `__proto__` key is found. This is the default value.
|
||||
- `'remove'` - deletes any `__proto__` keys from the input `obj`.
|
||||
- `constructorAction` - optional string with one of:
|
||||
- `'error'` - throw a `SyntaxError` when a `constructor.prototype` key is found. This is the default value.
|
||||
- `'remove'` - deletes any `constructor` keys from the input `obj`.
|
||||
- `safe` - optional boolean:
|
||||
- `true` - returns `null` instead of throwing when a forbidden prototype property is found.
|
||||
- `false` - default behavior (throws or removes based on `protoAction`/`constructorAction`).
|
||||
|
||||
## Benchmarks
|
||||
|
||||
Machine: 2,7 GHz Quad-Core Intel Core i7
|
||||
|
||||
```
|
||||
v14.8.0
|
||||
|
||||
> node ignore.js
|
||||
|
||||
JSON.parse x 679,376 ops/sec ±1.15% (84 runs sampled)
|
||||
secure-json-parse x 649,605 ops/sec ±0.58% (87 runs sampled)
|
||||
reviver x 244,414 ops/sec ±1.05% (88 runs sampled)
|
||||
Fastest is JSON.parse
|
||||
|
||||
> node no__proto__.js
|
||||
|
||||
JSON.parse x 652,190 ops/sec ±0.67% (86 runs sampled)
|
||||
secure-json-parse x 589,785 ops/sec ±1.01% (88 runs sampled)
|
||||
reviver x 218,075 ops/sec ±1.58% (87 runs sampled)
|
||||
Fastest is JSON.parse
|
||||
|
||||
> node remove.js
|
||||
|
||||
JSON.parse x 683,527 ops/sec ±0.62% (88 runs sampled)
|
||||
secure-json-parse x 316,926 ops/sec ±0.63% (87 runs sampled)
|
||||
reviver x 214,167 ops/sec ±0.63% (86 runs sampled)
|
||||
Fastest is JSON.parse
|
||||
|
||||
> node throw.js
|
||||
|
||||
JSON.parse x 682,548 ops/sec ±0.60% (88 runs sampled)
|
||||
JSON.parse error x 170,716 ops/sec ±0.93% (87 runs sampled)
|
||||
secure-json-parse x 104,483 ops/sec ±0.62% (87 runs sampled)
|
||||
reviver x 114,197 ops/sec ±0.63% (87 runs sampled)
|
||||
Fastest is JSON.parse
|
||||
```
|
||||
|
||||
## Acknowledgments
|
||||
This project has been forked from [hapijs/bourne](https://github.com/hapijs/bourne).
|
||||
All credit before commit [4690682](https://github.com/hapijs/bourne/commit/4690682c6cdaa06590da7b2485d5df91c09da889) goes to the hapijs/bourne project contributors.
|
||||
After, the project will be maintained by the Fastify team.
|
||||
|
||||
## License
|
||||
Licensed under [BSD-3-Clause](./LICENSE).
|
||||
@@ -0,0 +1,36 @@
|
||||
import { TLSSocket, ConnectionOptions } from 'node:tls'
|
||||
import { IpcNetConnectOpts, Socket, TcpNetConnectOpts } from 'node:net'
|
||||
|
||||
export default buildConnector
|
||||
declare function buildConnector (options?: buildConnector.BuildOptions): buildConnector.connector
|
||||
|
||||
declare namespace buildConnector {
|
||||
export type BuildOptions = (ConnectionOptions | TcpNetConnectOpts | IpcNetConnectOpts) & {
|
||||
allowH2?: boolean;
|
||||
maxCachedSessions?: number | null;
|
||||
socketPath?: string | null;
|
||||
timeout?: number | null;
|
||||
port?: number;
|
||||
keepAlive?: boolean | null;
|
||||
keepAliveInitialDelay?: number | null;
|
||||
typeOfService?: number | null;
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
hostname: string
|
||||
host?: string
|
||||
protocol: string
|
||||
port: string
|
||||
servername?: string
|
||||
localAddress?: string | null
|
||||
socketPath?: string | null
|
||||
httpSocket?: Socket
|
||||
}
|
||||
|
||||
export type Callback = (...args: CallbackArgs) => void
|
||||
type CallbackArgs = [null, Socket | TLSSocket] | [Error, null]
|
||||
|
||||
export interface connector {
|
||||
(options: buildConnector.Options, callback: buildConnector.Callback): void
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
declare module 'console' {
|
||||
export = console;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
export { c as configDefaults, a as coverageConfigDefaults, d as defaultExclude, b as defaultInclude } from './chunks/defaults.9aQKnqFk.js';
|
||||
export { mergeConfig } from 'vite';
|
||||
export { d as defaultBrowserPort } from './chunks/constants.CPYnjOGj.js';
|
||||
import 'node:os';
|
||||
import './chunks/env.D4Lgay0q.js';
|
||||
import 'std-env';
|
||||
|
||||
function defineConfig(config) {
|
||||
return config;
|
||||
}
|
||||
function defineProject(config) {
|
||||
return config;
|
||||
}
|
||||
|
||||
export { defineConfig, defineProject };
|
||||
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isSymbolFromDefaultLibrary = isSymbolFromDefaultLibrary;
|
||||
function isSymbolFromDefaultLibrary(program, symbol) {
|
||||
if (!symbol) {
|
||||
return false;
|
||||
}
|
||||
const declarations = symbol.getDeclarations() ?? [];
|
||||
for (const declaration of declarations) {
|
||||
const sourceFile = declaration.getSourceFile();
|
||||
if (program.isSourceFileDefaultLibrary(sourceFile)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
// Minimal msgpack encoder/decoder.
|
||||
// Supports: arrays, unsigned integers, strings, booleans, binary data.
|
||||
import { Wtf8Decoder } from "./wtf8.js";
|
||||
// ── MessagePack format constants ────────────────────────────────────
|
||||
export const MSGPACK_FIXARRAY3 = 0x93; // 3-element fixarray
|
||||
export const MSGPACK_BIN8 = 0xc4;
|
||||
export const MSGPACK_BIN16 = 0xc5;
|
||||
export const MSGPACK_BIN32 = 0xc6;
|
||||
export const MSGPACK_UINT8 = 0xcc;
|
||||
// ── Bin header helpers ──────────────────────────────────────────────
|
||||
/** Compute the MessagePack bin header size for a given data length. */
|
||||
export function binHeaderSize(len) {
|
||||
if (len < 0x100)
|
||||
return 2; // BIN8: marker + 1-byte size
|
||||
if (len < 0x10000)
|
||||
return 3; // BIN16: marker + 2-byte size
|
||||
return 5; // BIN32: marker + 4-byte size
|
||||
}
|
||||
/** Write a MessagePack bin header into `buf` at `off`, return new offset. */
|
||||
export function writeBinHeader(buf, off, len) {
|
||||
if (len < 0x100) {
|
||||
buf[off++] = MSGPACK_BIN8;
|
||||
buf[off++] = len;
|
||||
}
|
||||
else if (len < 0x10000) {
|
||||
buf[off++] = MSGPACK_BIN16;
|
||||
buf[off++] = (len >>> 8) & 0xff;
|
||||
buf[off++] = len & 0xff;
|
||||
}
|
||||
else {
|
||||
buf[off++] = MSGPACK_BIN32;
|
||||
buf[off++] = (len >>> 24) & 0xff;
|
||||
buf[off++] = (len >>> 16) & 0xff;
|
||||
buf[off++] = (len >>> 8) & 0xff;
|
||||
buf[off++] = len & 0xff;
|
||||
}
|
||||
return off;
|
||||
}
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new Wtf8Decoder();
|
||||
export class MsgpackWriter {
|
||||
buf;
|
||||
view;
|
||||
pos;
|
||||
constructor(initialSize = 256) {
|
||||
this.buf = new Uint8Array(initialSize);
|
||||
this.view = new DataView(this.buf.buffer);
|
||||
this.pos = 0;
|
||||
}
|
||||
ensure(n) {
|
||||
if (this.pos + n > this.buf.length) {
|
||||
let newSize = this.buf.length * 2;
|
||||
while (newSize < this.pos + n)
|
||||
newSize *= 2;
|
||||
const next = new Uint8Array(newSize);
|
||||
next.set(this.buf);
|
||||
this.buf = next;
|
||||
this.view = new DataView(this.buf.buffer);
|
||||
}
|
||||
}
|
||||
writeArrayHeader(length) {
|
||||
if (length <= 0x0f) {
|
||||
this.ensure(1);
|
||||
this.buf[this.pos++] = 0x90 | length;
|
||||
}
|
||||
else if (length <= 0xffff) {
|
||||
this.ensure(3);
|
||||
this.buf[this.pos++] = 0xdc;
|
||||
this.view.setUint16(this.pos, length, false);
|
||||
this.pos += 2;
|
||||
}
|
||||
else {
|
||||
this.ensure(5);
|
||||
this.buf[this.pos++] = 0xdd;
|
||||
this.view.setUint32(this.pos, length, false);
|
||||
this.pos += 4;
|
||||
}
|
||||
}
|
||||
writeUint(value) {
|
||||
if (value <= 0x7f) {
|
||||
this.ensure(1);
|
||||
this.buf[this.pos++] = value;
|
||||
}
|
||||
else if (value <= 0xff) {
|
||||
this.ensure(2);
|
||||
this.buf[this.pos++] = 0xcc;
|
||||
this.buf[this.pos++] = value;
|
||||
}
|
||||
else if (value <= 0xffff) {
|
||||
this.ensure(3);
|
||||
this.buf[this.pos++] = 0xcd;
|
||||
this.view.setUint16(this.pos, value, false);
|
||||
this.pos += 2;
|
||||
}
|
||||
else {
|
||||
this.ensure(5);
|
||||
this.buf[this.pos++] = 0xce;
|
||||
this.view.setUint32(this.pos, value, false);
|
||||
this.pos += 4;
|
||||
}
|
||||
}
|
||||
writeString(str) {
|
||||
const encoded = encoder.encode(str);
|
||||
const len = encoded.length;
|
||||
if (len <= 0x1f) {
|
||||
this.ensure(1 + len);
|
||||
this.buf[this.pos++] = 0xa0 | len;
|
||||
}
|
||||
else if (len <= 0xff) {
|
||||
this.ensure(2 + len);
|
||||
this.buf[this.pos++] = 0xd9;
|
||||
this.buf[this.pos++] = len;
|
||||
}
|
||||
else if (len <= 0xffff) {
|
||||
this.ensure(3 + len);
|
||||
this.buf[this.pos++] = 0xda;
|
||||
this.view.setUint16(this.pos, len, false);
|
||||
this.pos += 2;
|
||||
}
|
||||
else {
|
||||
this.ensure(5 + len);
|
||||
this.buf[this.pos++] = 0xdb;
|
||||
this.view.setUint32(this.pos, len, false);
|
||||
this.pos += 4;
|
||||
}
|
||||
this.buf.set(encoded, this.pos);
|
||||
this.pos += len;
|
||||
}
|
||||
writeBool(value) {
|
||||
this.ensure(1);
|
||||
this.buf[this.pos++] = value ? 0xc3 : 0xc2;
|
||||
}
|
||||
finish() {
|
||||
return this.buf.subarray(0, this.pos);
|
||||
}
|
||||
}
|
||||
export class MsgpackReader {
|
||||
buf;
|
||||
view;
|
||||
pos;
|
||||
constructor(data, offset = 0) {
|
||||
this.buf = data;
|
||||
this.view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
||||
this.pos = offset;
|
||||
}
|
||||
readArrayHeader() {
|
||||
const byte = this.buf[this.pos++];
|
||||
if ((byte & 0xf0) === 0x90)
|
||||
return byte & 0x0f;
|
||||
if (byte === 0xdc) {
|
||||
const len = this.view.getUint16(this.pos, false);
|
||||
this.pos += 2;
|
||||
return len;
|
||||
}
|
||||
if (byte === 0xdd) {
|
||||
const len = this.view.getUint32(this.pos, false);
|
||||
this.pos += 4;
|
||||
return len;
|
||||
}
|
||||
throw new Error(`Expected array header, got 0x${byte.toString(16)}`);
|
||||
}
|
||||
readUint() {
|
||||
const byte = this.buf[this.pos++];
|
||||
if (byte <= 0x7f)
|
||||
return byte;
|
||||
if (byte === 0xcc)
|
||||
return this.buf[this.pos++];
|
||||
if (byte === 0xcd) {
|
||||
const val = this.view.getUint16(this.pos, false);
|
||||
this.pos += 2;
|
||||
return val;
|
||||
}
|
||||
if (byte === 0xce) {
|
||||
const val = this.view.getUint32(this.pos, false);
|
||||
this.pos += 4;
|
||||
return val;
|
||||
}
|
||||
throw new Error(`Expected uint, got 0x${byte.toString(16)}`);
|
||||
}
|
||||
readString() {
|
||||
const byte = this.buf[this.pos++];
|
||||
let len;
|
||||
if ((byte & 0xe0) === 0xa0) {
|
||||
len = byte & 0x1f;
|
||||
}
|
||||
else if (byte === 0xd9) {
|
||||
len = this.buf[this.pos++];
|
||||
}
|
||||
else if (byte === 0xda) {
|
||||
len = this.view.getUint16(this.pos, false);
|
||||
this.pos += 2;
|
||||
}
|
||||
else if (byte === 0xdb) {
|
||||
len = this.view.getUint32(this.pos, false);
|
||||
this.pos += 4;
|
||||
}
|
||||
else {
|
||||
throw new Error(`Expected string, got 0x${byte.toString(16)}`);
|
||||
}
|
||||
const str = decoder.decode(this.buf.subarray(this.pos, this.pos + len));
|
||||
this.pos += len;
|
||||
return str;
|
||||
}
|
||||
readBool() {
|
||||
const byte = this.buf[this.pos++];
|
||||
if (byte === 0xc3)
|
||||
return true;
|
||||
if (byte === 0xc2)
|
||||
return false;
|
||||
throw new Error(`Expected bool, got 0x${byte.toString(16)}`);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=msgpack.js.map
|
||||
@@ -0,0 +1,24 @@
|
||||
'use strict'
|
||||
|
||||
const { parentPort, threadName } = require('worker_threads')
|
||||
const { Writable } = require('node:stream')
|
||||
|
||||
let sent = false
|
||||
|
||||
module.exports = (options) => {
|
||||
const myTransportStream = new Writable({
|
||||
autoDestroy: true,
|
||||
write (chunk, enc, cb) {
|
||||
if (!sent) {
|
||||
sent = true
|
||||
parentPort.postMessage({
|
||||
code: 'EVENT',
|
||||
name: 'workerThreadName',
|
||||
args: [threadName]
|
||||
})
|
||||
}
|
||||
cb()
|
||||
}
|
||||
})
|
||||
return myTransportStream
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
const file14 = require("./file14.js")
|
||||
|
||||
module.exports = function () {
|
||||
file14()
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
// THIS CODE WAS AUTOMATICALLY GENERATED
|
||||
// DO NOT EDIT THIS CODE BY HAND
|
||||
// RUN THE FOLLOWING COMMAND FROM THE WORKSPACE ROOT TO REGENERATE:
|
||||
// npx nx generate-lib repo
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.es2015_core = void 0;
|
||||
const base_config_1 = require("./base-config");
|
||||
exports.es2015_core = {
|
||||
libs: [],
|
||||
variables: [
|
||||
['Array', base_config_1.TYPE],
|
||||
['ArrayConstructor', base_config_1.TYPE],
|
||||
['DateConstructor', base_config_1.TYPE],
|
||||
['Function', base_config_1.TYPE],
|
||||
['Math', base_config_1.TYPE],
|
||||
['NumberConstructor', base_config_1.TYPE],
|
||||
['ObjectConstructor', base_config_1.TYPE],
|
||||
['ReadonlyArray', base_config_1.TYPE],
|
||||
['RegExp', base_config_1.TYPE],
|
||||
['RegExpConstructor', base_config_1.TYPE],
|
||||
['String', base_config_1.TYPE],
|
||||
['StringConstructor', base_config_1.TYPE],
|
||||
['Int8Array', base_config_1.TYPE],
|
||||
['Uint8Array', base_config_1.TYPE],
|
||||
['Uint8ClampedArray', base_config_1.TYPE],
|
||||
['Int16Array', base_config_1.TYPE],
|
||||
['Uint16Array', base_config_1.TYPE],
|
||||
['Int32Array', base_config_1.TYPE],
|
||||
['Uint32Array', base_config_1.TYPE],
|
||||
['Float32Array', base_config_1.TYPE],
|
||||
['Float64Array', base_config_1.TYPE],
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
const { stringifyValueForError } = require("./shared");
|
||||
|
||||
module.exports = function ({ ruleId, value }) {
|
||||
return `
|
||||
Configuration for rule "${ruleId}" is invalid. Expected severity of "off", 0, "warn", 1, "error", or 2.
|
||||
|
||||
You passed '${stringifyValueForError(value, 4)}'.
|
||||
|
||||
See https://eslint.org/docs/latest/use/configure/rules#use-configuration-files for configuring rules.
|
||||
`.trimStart();
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
//#region src/utils/misc.ts
|
||||
function arraify(value) {
|
||||
return Array.isArray(value) ? value : [value];
|
||||
}
|
||||
function isPromiseLike(value) {
|
||||
return value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
||||
}
|
||||
function unimplemented(info) {
|
||||
if (info) throw new Error(`unimplemented: ${info}`);
|
||||
throw new Error("unimplemented");
|
||||
}
|
||||
function unreachable(info) {
|
||||
if (info) throw new Error(`unreachable: ${info}`);
|
||||
throw new Error("unreachable");
|
||||
}
|
||||
function unsupported(info) {
|
||||
throw new Error(`UNSUPPORTED: ${info}`);
|
||||
}
|
||||
function noop(..._args) {}
|
||||
const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Za-z]:)?[/\\|])/;
|
||||
/**
|
||||
* Whether `name` is a path fragment — an absolute or relative path. Emitted file
|
||||
* names, `[name]` substitutions and file-name patterns can be neither.
|
||||
*/
|
||||
function isPathFragment(name) {
|
||||
return name[0] === "/" || name[0] === "." && (name[1] === "/" || name[1] === ".") || ABSOLUTE_PATH_REGEX.test(name);
|
||||
}
|
||||
//#endregion
|
||||
export { unimplemented as a, noop as i, isPathFragment as n, unreachable as o, isPromiseLike as r, unsupported as s, arraify as t };
|
||||
@@ -0,0 +1,250 @@
|
||||
import toArray from "./toArray.js";
|
||||
import toPropertyKey from "./toPropertyKey.js";
|
||||
function _decorate(e, r, t, i) {
|
||||
var o = _getDecoratorsApi();
|
||||
if (i) for (var n = 0; n < i.length; n++) o = i[n](o);
|
||||
var s = r(function (e) {
|
||||
o.initializeInstanceElements(e, a.elements);
|
||||
}, t),
|
||||
a = o.decorateClass(_coalesceClassElements(s.d.map(_createElementDescriptor)), e);
|
||||
return o.initializeClassElements(s.F, a.elements), o.runClassFinishers(s.F, a.finishers);
|
||||
}
|
||||
function _getDecoratorsApi() {
|
||||
_getDecoratorsApi = function _getDecoratorsApi() {
|
||||
return e;
|
||||
};
|
||||
var e = {
|
||||
elementsDefinitionOrder: [["method"], ["field"]],
|
||||
initializeInstanceElements: function initializeInstanceElements(e, r) {
|
||||
["method", "field"].forEach(function (t) {
|
||||
r.forEach(function (r) {
|
||||
r.kind === t && "own" === r.placement && this.defineClassElement(e, r);
|
||||
}, this);
|
||||
}, this);
|
||||
},
|
||||
initializeClassElements: function initializeClassElements(e, r) {
|
||||
var t = e.prototype;
|
||||
["method", "field"].forEach(function (i) {
|
||||
r.forEach(function (r) {
|
||||
var o = r.placement;
|
||||
if (r.kind === i && ("static" === o || "prototype" === o)) {
|
||||
var n = "static" === o ? e : t;
|
||||
this.defineClassElement(n, r);
|
||||
}
|
||||
}, this);
|
||||
}, this);
|
||||
},
|
||||
defineClassElement: function defineClassElement(e, r) {
|
||||
var t = r.descriptor;
|
||||
if ("field" === r.kind) {
|
||||
var i = r.initializer;
|
||||
t = {
|
||||
enumerable: t.enumerable,
|
||||
writable: t.writable,
|
||||
configurable: t.configurable,
|
||||
value: void 0 === i ? void 0 : i.call(e)
|
||||
};
|
||||
}
|
||||
Object.defineProperty(e, r.key, t);
|
||||
},
|
||||
decorateClass: function decorateClass(e, r) {
|
||||
var t = [],
|
||||
i = [],
|
||||
o = {
|
||||
"static": [],
|
||||
prototype: [],
|
||||
own: []
|
||||
};
|
||||
if (e.forEach(function (e) {
|
||||
this.addElementPlacement(e, o);
|
||||
}, this), e.forEach(function (e) {
|
||||
if (!_hasDecorators(e)) return t.push(e);
|
||||
var r = this.decorateElement(e, o);
|
||||
t.push(r.element), t.push.apply(t, r.extras), i.push.apply(i, r.finishers);
|
||||
}, this), !r) return {
|
||||
elements: t,
|
||||
finishers: i
|
||||
};
|
||||
var n = this.decorateConstructor(t, r);
|
||||
return i.push.apply(i, n.finishers), n.finishers = i, n;
|
||||
},
|
||||
addElementPlacement: function addElementPlacement(e, r, t) {
|
||||
var i = r[e.placement];
|
||||
if (!t && -1 !== i.indexOf(e.key)) throw new TypeError("Duplicated element (" + e.key + ")");
|
||||
i.push(e.key);
|
||||
},
|
||||
decorateElement: function decorateElement(e, r) {
|
||||
for (var t = [], i = [], o = e.decorators, n = o.length - 1; n >= 0; n--) {
|
||||
var s = r[e.placement];
|
||||
s.splice(s.indexOf(e.key), 1);
|
||||
var a = this.fromElementDescriptor(e),
|
||||
l = this.toElementFinisherExtras((0, o[n])(a) || a);
|
||||
e = l.element, this.addElementPlacement(e, r), l.finisher && i.push(l.finisher);
|
||||
var c = l.extras;
|
||||
if (c) {
|
||||
for (var p = 0; p < c.length; p++) this.addElementPlacement(c[p], r);
|
||||
t.push.apply(t, c);
|
||||
}
|
||||
}
|
||||
return {
|
||||
element: e,
|
||||
finishers: i,
|
||||
extras: t
|
||||
};
|
||||
},
|
||||
decorateConstructor: function decorateConstructor(e, r) {
|
||||
for (var t = [], i = r.length - 1; i >= 0; i--) {
|
||||
var o = this.fromClassDescriptor(e),
|
||||
n = this.toClassDescriptor((0, r[i])(o) || o);
|
||||
if (void 0 !== n.finisher && t.push(n.finisher), void 0 !== n.elements) {
|
||||
e = n.elements;
|
||||
for (var s = 0; s < e.length - 1; s++) for (var a = s + 1; a < e.length; a++) if (e[s].key === e[a].key && e[s].placement === e[a].placement) throw new TypeError("Duplicated element (" + e[s].key + ")");
|
||||
}
|
||||
}
|
||||
return {
|
||||
elements: e,
|
||||
finishers: t
|
||||
};
|
||||
},
|
||||
fromElementDescriptor: function fromElementDescriptor(e) {
|
||||
var r = {
|
||||
kind: e.kind,
|
||||
key: e.key,
|
||||
placement: e.placement,
|
||||
descriptor: e.descriptor
|
||||
};
|
||||
return Object.defineProperty(r, Symbol.toStringTag, {
|
||||
value: "Descriptor",
|
||||
configurable: !0
|
||||
}), "field" === e.kind && (r.initializer = e.initializer), r;
|
||||
},
|
||||
toElementDescriptors: function toElementDescriptors(e) {
|
||||
if (void 0 !== e) return toArray(e).map(function (e) {
|
||||
var r = this.toElementDescriptor(e);
|
||||
return this.disallowProperty(e, "finisher", "An element descriptor"), this.disallowProperty(e, "extras", "An element descriptor"), r;
|
||||
}, this);
|
||||
},
|
||||
toElementDescriptor: function toElementDescriptor(e) {
|
||||
var r = e.kind + "";
|
||||
if ("method" !== r && "field" !== r) throw new TypeError('An element descriptor\'s .kind property must be either "method" or "field", but a decorator created an element descriptor with .kind "' + r + '"');
|
||||
var t = toPropertyKey(e.key),
|
||||
i = e.placement + "";
|
||||
if ("static" !== i && "prototype" !== i && "own" !== i) throw new TypeError('An element descriptor\'s .placement property must be one of "static", "prototype" or "own", but a decorator created an element descriptor with .placement "' + i + '"');
|
||||
var o = e.descriptor;
|
||||
this.disallowProperty(e, "elements", "An element descriptor");
|
||||
var n = {
|
||||
kind: r,
|
||||
key: t,
|
||||
placement: i,
|
||||
descriptor: Object.assign({}, o)
|
||||
};
|
||||
return "field" !== r ? this.disallowProperty(e, "initializer", "A method descriptor") : (this.disallowProperty(o, "get", "The property descriptor of a field descriptor"), this.disallowProperty(o, "set", "The property descriptor of a field descriptor"), this.disallowProperty(o, "value", "The property descriptor of a field descriptor"), n.initializer = e.initializer), n;
|
||||
},
|
||||
toElementFinisherExtras: function toElementFinisherExtras(e) {
|
||||
return {
|
||||
element: this.toElementDescriptor(e),
|
||||
finisher: _optionalCallableProperty(e, "finisher"),
|
||||
extras: this.toElementDescriptors(e.extras)
|
||||
};
|
||||
},
|
||||
fromClassDescriptor: function fromClassDescriptor(e) {
|
||||
var r = {
|
||||
kind: "class",
|
||||
elements: e.map(this.fromElementDescriptor, this)
|
||||
};
|
||||
return Object.defineProperty(r, Symbol.toStringTag, {
|
||||
value: "Descriptor",
|
||||
configurable: !0
|
||||
}), r;
|
||||
},
|
||||
toClassDescriptor: function toClassDescriptor(e) {
|
||||
var r = e.kind + "";
|
||||
if ("class" !== r) throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator created a class descriptor with .kind "' + r + '"');
|
||||
this.disallowProperty(e, "key", "A class descriptor"), this.disallowProperty(e, "placement", "A class descriptor"), this.disallowProperty(e, "descriptor", "A class descriptor"), this.disallowProperty(e, "initializer", "A class descriptor"), this.disallowProperty(e, "extras", "A class descriptor");
|
||||
var t = _optionalCallableProperty(e, "finisher");
|
||||
return {
|
||||
elements: this.toElementDescriptors(e.elements),
|
||||
finisher: t
|
||||
};
|
||||
},
|
||||
runClassFinishers: function runClassFinishers(e, r) {
|
||||
for (var t = 0; t < r.length; t++) {
|
||||
var i = (0, r[t])(e);
|
||||
if (void 0 !== i) {
|
||||
if ("function" != typeof i) throw new TypeError("Finishers must return a constructor.");
|
||||
e = i;
|
||||
}
|
||||
}
|
||||
return e;
|
||||
},
|
||||
disallowProperty: function disallowProperty(e, r, t) {
|
||||
if (void 0 !== e[r]) throw new TypeError(t + " can't have a ." + r + " property.");
|
||||
}
|
||||
};
|
||||
return e;
|
||||
}
|
||||
function _createElementDescriptor(e) {
|
||||
var r,
|
||||
t = toPropertyKey(e.key);
|
||||
"method" === e.kind ? r = {
|
||||
value: e.value,
|
||||
writable: !0,
|
||||
configurable: !0,
|
||||
enumerable: !1
|
||||
} : "get" === e.kind ? r = {
|
||||
get: e.value,
|
||||
configurable: !0,
|
||||
enumerable: !1
|
||||
} : "set" === e.kind ? r = {
|
||||
set: e.value,
|
||||
configurable: !0,
|
||||
enumerable: !1
|
||||
} : "field" === e.kind && (r = {
|
||||
configurable: !0,
|
||||
writable: !0,
|
||||
enumerable: !0
|
||||
});
|
||||
var i = {
|
||||
kind: "field" === e.kind ? "field" : "method",
|
||||
key: t,
|
||||
placement: e["static"] ? "static" : "field" === e.kind ? "own" : "prototype",
|
||||
descriptor: r
|
||||
};
|
||||
return e.decorators && (i.decorators = e.decorators), "field" === e.kind && (i.initializer = e.value), i;
|
||||
}
|
||||
function _coalesceGetterSetter(e, r) {
|
||||
void 0 !== e.descriptor.get ? r.descriptor.get = e.descriptor.get : r.descriptor.set = e.descriptor.set;
|
||||
}
|
||||
function _coalesceClassElements(e) {
|
||||
for (var r = [], isSameElement = function isSameElement(e) {
|
||||
return "method" === e.kind && e.key === o.key && e.placement === o.placement;
|
||||
}, t = 0; t < e.length; t++) {
|
||||
var i,
|
||||
o = e[t];
|
||||
if ("method" === o.kind && (i = r.find(isSameElement))) {
|
||||
if (_isDataDescriptor(o.descriptor) || _isDataDescriptor(i.descriptor)) {
|
||||
if (_hasDecorators(o) || _hasDecorators(i)) throw new ReferenceError("Duplicated methods (" + o.key + ") can't be decorated.");
|
||||
i.descriptor = o.descriptor;
|
||||
} else {
|
||||
if (_hasDecorators(o)) {
|
||||
if (_hasDecorators(i)) throw new ReferenceError("Decorators can't be placed on different accessors with for the same property (" + o.key + ").");
|
||||
i.decorators = o.decorators;
|
||||
}
|
||||
_coalesceGetterSetter(o, i);
|
||||
}
|
||||
} else r.push(o);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
function _hasDecorators(e) {
|
||||
return e.decorators && e.decorators.length;
|
||||
}
|
||||
function _isDataDescriptor(e) {
|
||||
return void 0 !== e && !(void 0 === e.value && void 0 === e.writable);
|
||||
}
|
||||
function _optionalCallableProperty(e, r) {
|
||||
var t = e[r];
|
||||
if (void 0 !== t && "function" != typeof t) throw new TypeError("Expected '" + r + "' to be a function");
|
||||
return t;
|
||||
}
|
||||
export { _decorate as default };
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,603 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2015.symbol" />
|
||||
|
||||
interface SymbolConstructor {
|
||||
/**
|
||||
* A method that returns the default iterator for an object. Called by the semantics of the
|
||||
* for-of statement.
|
||||
*/
|
||||
readonly iterator: unique symbol;
|
||||
}
|
||||
|
||||
interface IteratorYieldResult<TYield> {
|
||||
done?: false;
|
||||
value: TYield;
|
||||
}
|
||||
|
||||
interface IteratorReturnResult<TReturn> {
|
||||
done: true;
|
||||
value: TReturn;
|
||||
}
|
||||
|
||||
type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
|
||||
|
||||
interface Iterator<T, TReturn = any, TNext = any> {
|
||||
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
|
||||
next(...[value]: [] | [TNext]): IteratorResult<T, TReturn>;
|
||||
return?(value?: TReturn): IteratorResult<T, TReturn>;
|
||||
throw?(e?: any): IteratorResult<T, TReturn>;
|
||||
}
|
||||
|
||||
interface Iterable<T, TReturn = any, TNext = any> {
|
||||
[Symbol.iterator](): Iterator<T, TReturn, TNext>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes a user-defined {@link Iterator} that is also iterable.
|
||||
*/
|
||||
interface IterableIterator<T, TReturn = any, TNext = any> extends Iterator<T, TReturn, TNext> {
|
||||
[Symbol.iterator](): IterableIterator<T, TReturn, TNext>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes an {@link Iterator} produced by the runtime that inherits from the intrinsic `Iterator.prototype`.
|
||||
*/
|
||||
interface IteratorObject<T, TReturn = unknown, TNext = unknown> extends Iterator<T, TReturn, TNext> {
|
||||
[Symbol.iterator](): IteratorObject<T, TReturn, TNext>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the `TReturn` type used for built-in iterators produced by `Array`, `Map`, `Set`, and others.
|
||||
* This is `undefined` when `strictBuiltInIteratorReturn` is `true`; otherwise, this is `any`.
|
||||
*/
|
||||
type BuiltinIteratorReturn = intrinsic;
|
||||
|
||||
interface ArrayIterator<T> extends IteratorObject<T, BuiltinIteratorReturn, unknown> {
|
||||
[Symbol.iterator](): ArrayIterator<T>;
|
||||
}
|
||||
|
||||
interface Array<T> {
|
||||
/** Iterator */
|
||||
[Symbol.iterator](): ArrayIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, T]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<T>;
|
||||
}
|
||||
|
||||
interface ArrayConstructor {
|
||||
/**
|
||||
* Creates an array from an iterable object.
|
||||
* @param iterable An iterable object to convert to an array.
|
||||
*/
|
||||
from<T>(iterable: Iterable<T> | ArrayLike<T>): T[];
|
||||
|
||||
/**
|
||||
* Creates an array from an iterable object.
|
||||
* @param iterable An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
|
||||
}
|
||||
|
||||
interface ReadonlyArray<T> {
|
||||
/** Iterator of values in the array. */
|
||||
[Symbol.iterator](): ArrayIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, T]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<T>;
|
||||
}
|
||||
|
||||
interface IArguments {
|
||||
/** Iterator */
|
||||
[Symbol.iterator](): ArrayIterator<any>;
|
||||
}
|
||||
|
||||
interface MapIterator<T> extends IteratorObject<T, BuiltinIteratorReturn, unknown> {
|
||||
[Symbol.iterator](): MapIterator<T>;
|
||||
}
|
||||
|
||||
interface Map<K, V> {
|
||||
/** Returns an iterable of entries in the map. */
|
||||
[Symbol.iterator](): MapIterator<[K, V]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of key, value pairs for every entry in the map.
|
||||
*/
|
||||
entries(): MapIterator<[K, V]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of keys in the map
|
||||
*/
|
||||
keys(): MapIterator<K>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the map
|
||||
*/
|
||||
values(): MapIterator<V>;
|
||||
}
|
||||
|
||||
interface ReadonlyMap<K, V> {
|
||||
/** Returns an iterable of entries in the map. */
|
||||
[Symbol.iterator](): MapIterator<[K, V]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of key, value pairs for every entry in the map.
|
||||
*/
|
||||
entries(): MapIterator<[K, V]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of keys in the map
|
||||
*/
|
||||
keys(): MapIterator<K>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the map
|
||||
*/
|
||||
values(): MapIterator<V>;
|
||||
}
|
||||
|
||||
interface MapConstructor {
|
||||
new (): Map<any, any>;
|
||||
new <K, V>(iterable?: Iterable<readonly [K, V]> | null): Map<K, V>;
|
||||
}
|
||||
|
||||
interface WeakMap<K extends WeakKey, V> {}
|
||||
|
||||
interface WeakMapConstructor {
|
||||
new <K extends WeakKey = WeakKey, V = any>(iterable?: Iterable<readonly [K, V]> | null): WeakMap<K, V>;
|
||||
}
|
||||
|
||||
interface SetIterator<T> extends IteratorObject<T, BuiltinIteratorReturn, unknown> {
|
||||
[Symbol.iterator](): SetIterator<T>;
|
||||
}
|
||||
|
||||
interface Set<T> {
|
||||
/** Iterates over values in the set. */
|
||||
[Symbol.iterator](): SetIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of [v,v] pairs for every value `v` in the set.
|
||||
*/
|
||||
entries(): SetIterator<[T, T]>;
|
||||
|
||||
/**
|
||||
* Despite its name, returns an iterable of the values in the set.
|
||||
*/
|
||||
keys(): SetIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the set.
|
||||
*/
|
||||
values(): SetIterator<T>;
|
||||
}
|
||||
|
||||
interface ReadonlySet<T> {
|
||||
/** Iterates over values in the set. */
|
||||
[Symbol.iterator](): SetIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of [v,v] pairs for every value `v` in the set.
|
||||
*/
|
||||
entries(): SetIterator<[T, T]>;
|
||||
|
||||
/**
|
||||
* Despite its name, returns an iterable of the values in the set.
|
||||
*/
|
||||
keys(): SetIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the set.
|
||||
*/
|
||||
values(): SetIterator<T>;
|
||||
}
|
||||
|
||||
interface SetConstructor {
|
||||
new <T>(iterable?: Iterable<T> | null): Set<T>;
|
||||
}
|
||||
|
||||
interface WeakSet<T extends WeakKey> {}
|
||||
|
||||
interface WeakSetConstructor {
|
||||
new <T extends WeakKey = WeakKey>(iterable: Iterable<T>): WeakSet<T>;
|
||||
}
|
||||
|
||||
interface Promise<T> {}
|
||||
|
||||
interface PromiseConstructor {
|
||||
/**
|
||||
* Creates a Promise that is resolved with an array of results when all of the provided Promises
|
||||
* resolve, or rejected when any Promise is rejected.
|
||||
* @param values An iterable of Promises.
|
||||
* @returns A new Promise.
|
||||
*/
|
||||
all<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>;
|
||||
|
||||
/**
|
||||
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
|
||||
* or rejected.
|
||||
* @param values An iterable of Promises.
|
||||
* @returns A new Promise.
|
||||
*/
|
||||
race<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>;
|
||||
}
|
||||
|
||||
interface StringIterator<T> extends IteratorObject<T, BuiltinIteratorReturn, unknown> {
|
||||
[Symbol.iterator](): StringIterator<T>;
|
||||
}
|
||||
|
||||
interface String {
|
||||
/** Iterator */
|
||||
[Symbol.iterator](): StringIterator<string>;
|
||||
}
|
||||
|
||||
interface Int8Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Int8ArrayConstructor {
|
||||
new (elements: Iterable<number>): Int8Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Int8Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Int8Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Uint8Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Uint8ArrayConstructor {
|
||||
new (elements: Iterable<number>): Uint8Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Uint8Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Uint8Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Uint8ClampedArray<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Uint8ClampedArrayConstructor {
|
||||
new (elements: Iterable<number>): Uint8ClampedArray<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Uint8ClampedArray<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Uint8ClampedArray<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Int16Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Int16ArrayConstructor {
|
||||
new (elements: Iterable<number>): Int16Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Int16Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Int16Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Uint16Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Uint16ArrayConstructor {
|
||||
new (elements: Iterable<number>): Uint16Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Uint16Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Uint16Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Int32Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Int32ArrayConstructor {
|
||||
new (elements: Iterable<number>): Int32Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Int32Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Int32Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Uint32Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Uint32ArrayConstructor {
|
||||
new (elements: Iterable<number>): Uint32Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Uint32Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Uint32Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Float32Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Float32ArrayConstructor {
|
||||
new (elements: Iterable<number>): Float32Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Float32Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Float32Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Float64Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Float64ArrayConstructor {
|
||||
new (elements: Iterable<number>): Float64Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Float64Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Float64Array<ArrayBuffer>;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
{{# def.definitions }}
|
||||
{{# def.errors }}
|
||||
{{# def.setupKeyword }}
|
||||
|
||||
{{## def.skipFormat:
|
||||
{{? $breakOnError }} if (true) { {{?}}
|
||||
{{ return out; }}
|
||||
#}}
|
||||
|
||||
{{? it.opts.format === false }}{{# def.skipFormat }}{{?}}
|
||||
|
||||
|
||||
{{# def.$data }}
|
||||
|
||||
|
||||
{{## def.$dataCheckFormat:
|
||||
{{# def.$dataNotType:'string' }}
|
||||
({{? $unknownFormats != 'ignore' }}
|
||||
({{=$schemaValue}} && !{{=$format}}
|
||||
{{? $allowUnknown }}
|
||||
&& self._opts.unknownFormats.indexOf({{=$schemaValue}}) == -1
|
||||
{{?}}) ||
|
||||
{{?}}
|
||||
({{=$format}} && {{=$formatType}} == '{{=$ruleType}}'
|
||||
&& !(typeof {{=$format}} == 'function'
|
||||
? {{? it.async}}
|
||||
(async{{=$lvl}} ? await {{=$format}}({{=$data}}) : {{=$format}}({{=$data}}))
|
||||
{{??}}
|
||||
{{=$format}}({{=$data}})
|
||||
{{?}}
|
||||
: {{=$format}}.test({{=$data}}))))
|
||||
#}}
|
||||
|
||||
{{## def.checkFormat:
|
||||
{{
|
||||
var $formatRef = 'formats' + it.util.getProperty($schema);
|
||||
if ($isObject) $formatRef += '.validate';
|
||||
}}
|
||||
{{? typeof $format == 'function' }}
|
||||
{{=$formatRef}}({{=$data}})
|
||||
{{??}}
|
||||
{{=$formatRef}}.test({{=$data}})
|
||||
{{?}}
|
||||
#}}
|
||||
|
||||
|
||||
{{
|
||||
var $unknownFormats = it.opts.unknownFormats
|
||||
, $allowUnknown = Array.isArray($unknownFormats);
|
||||
}}
|
||||
|
||||
{{? $isData }}
|
||||
{{
|
||||
var $format = 'format' + $lvl
|
||||
, $isObject = 'isObject' + $lvl
|
||||
, $formatType = 'formatType' + $lvl;
|
||||
}}
|
||||
var {{=$format}} = formats[{{=$schemaValue}}];
|
||||
var {{=$isObject}} = typeof {{=$format}} == 'object'
|
||||
&& !({{=$format}} instanceof RegExp)
|
||||
&& {{=$format}}.validate;
|
||||
var {{=$formatType}} = {{=$isObject}} && {{=$format}}.type || 'string';
|
||||
if ({{=$isObject}}) {
|
||||
{{? it.async}}
|
||||
var async{{=$lvl}} = {{=$format}}.async;
|
||||
{{?}}
|
||||
{{=$format}} = {{=$format}}.validate;
|
||||
}
|
||||
if ({{# def.$dataCheckFormat }}) {
|
||||
{{??}}
|
||||
{{ var $format = it.formats[$schema]; }}
|
||||
{{? !$format }}
|
||||
{{? $unknownFormats == 'ignore' }}
|
||||
{{ it.logger.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"'); }}
|
||||
{{# def.skipFormat }}
|
||||
{{?? $allowUnknown && $unknownFormats.indexOf($schema) >= 0 }}
|
||||
{{# def.skipFormat }}
|
||||
{{??}}
|
||||
{{ throw new Error('unknown format "' + $schema + '" is used in schema at path "' + it.errSchemaPath + '"'); }}
|
||||
{{?}}
|
||||
{{?}}
|
||||
{{
|
||||
var $isObject = typeof $format == 'object'
|
||||
&& !($format instanceof RegExp)
|
||||
&& $format.validate;
|
||||
var $formatType = $isObject && $format.type || 'string';
|
||||
if ($isObject) {
|
||||
var $async = $format.async === true;
|
||||
$format = $format.validate;
|
||||
}
|
||||
}}
|
||||
{{? $formatType != $ruleType }}
|
||||
{{# def.skipFormat }}
|
||||
{{?}}
|
||||
{{? $async }}
|
||||
{{
|
||||
if (!it.async) throw new Error('async format in sync schema');
|
||||
var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
|
||||
}}
|
||||
if (!(await {{=$formatRef}}({{=$data}}))) {
|
||||
{{??}}
|
||||
if (!{{# def.checkFormat }}) {
|
||||
{{?}}
|
||||
{{?}}
|
||||
{{# def.error:'format' }}
|
||||
} {{? $breakOnError }} else { {{?}}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { type PathLike, type WriteStream, createWriteStream } from 'fs'
|
||||
import { once } from 'events'
|
||||
|
||||
export default async function run (
|
||||
opts: { dest: PathLike },
|
||||
): Promise<WriteStream> {
|
||||
const stream = createWriteStream(opts.dest)
|
||||
await once(stream, 'open')
|
||||
return stream
|
||||
}
|
||||
Reference in New Issue
Block a user