WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"bn254.d.ts","sourceRoot":"","sources":["../src/bn254.ts"],"names":[],"mappings":"AAyDA,OAAO,EAEL,KAAK,OAAO,IAAI,UAAU,EAC1B,KAAK,gBAAgB,EAEtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAS,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAG3D,OAAO,EAAE,KAAK,OAAO,EAAqC,MAAM,2BAA2B,CAAC;AAsB5F,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,CAA2B,CAAC;AAsDhE,eAAO,MAAM,eAAe,EAAE,gBAY7B,CAAC;AAmBF;;;GAGG;AACH,eAAO,MAAM,KAAK,EAAE,UAgDlB,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE,OAS9B,CAAC"}
|
||||
@@ -0,0 +1,14 @@
|
||||
import Dispatcher from './dispatcher'
|
||||
|
||||
export declare class RedirectHandler implements Dispatcher.DispatchHandler {
|
||||
constructor (
|
||||
dispatch: Dispatcher.Dispatch,
|
||||
maxRedirections: number,
|
||||
opts: Dispatcher.DispatchOptions,
|
||||
handler: Dispatcher.DispatchHandler
|
||||
)
|
||||
}
|
||||
|
||||
export declare class DecoratorHandler implements Dispatcher.DispatchHandler {
|
||||
constructor (handler: Dispatcher.DispatchHandler)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { _ as default } from "../esm/_class_private_field_loose_key.js";
|
||||
@@ -0,0 +1,79 @@
|
||||
import fs from 'node:fs';
|
||||
import module$1 from 'node:module';
|
||||
import { d as dirname, j as join, b as basename, r as resolve, e as extname } from './chunk-pathe.M-eThtNZ.js';
|
||||
|
||||
const { existsSync, readdirSync, statSync } = fs;
|
||||
function findMockRedirect(root, mockPath, external) {
|
||||
const path = external || mockPath;
|
||||
// it's a node_module alias
|
||||
// all mocks should be inside <root>/__mocks__
|
||||
if (external || isNodeBuiltin(mockPath) || !existsSync(mockPath)) {
|
||||
const mockDirname = dirname(path);
|
||||
const mockFolder = join(root, "__mocks__", mockDirname);
|
||||
if (!existsSync(mockFolder)) {
|
||||
return null;
|
||||
}
|
||||
const baseOriginal = basename(path);
|
||||
function findFile(mockFolder, baseOriginal) {
|
||||
const files = readdirSync(mockFolder);
|
||||
for (const file of files) {
|
||||
const baseFile = basename(file, extname(file));
|
||||
if (baseFile === baseOriginal) {
|
||||
const path = resolve(mockFolder, file);
|
||||
// if the same name, return the file
|
||||
if (statSync(path).isFile()) {
|
||||
return path;
|
||||
} else {
|
||||
// find folder/index.{js,ts}
|
||||
const indexFile = findFile(path, "index");
|
||||
if (indexFile) {
|
||||
return indexFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return findFile(mockFolder, baseOriginal);
|
||||
}
|
||||
const dir = dirname(path);
|
||||
const baseId = basename(path);
|
||||
const fullPath = resolve(dir, "__mocks__", baseId);
|
||||
return existsSync(fullPath) ? fullPath : null;
|
||||
}
|
||||
const builtins = new Set([
|
||||
...module$1.builtinModules,
|
||||
"assert/strict",
|
||||
"diagnostics_channel",
|
||||
"dns/promises",
|
||||
"fs/promises",
|
||||
"path/posix",
|
||||
"path/win32",
|
||||
"readline/promises",
|
||||
"stream/consumers",
|
||||
"stream/promises",
|
||||
"stream/web",
|
||||
"timers/promises",
|
||||
"util/types",
|
||||
"wasi"
|
||||
]);
|
||||
// https://nodejs.org/api/modules.html#built-in-modules-with-mandatory-node-prefix
|
||||
const prefixedBuiltins = new Set([
|
||||
"node:sea",
|
||||
"node:sqlite",
|
||||
"node:test",
|
||||
"node:test/reporters"
|
||||
]);
|
||||
const NODE_BUILTIN_NAMESPACE = "node:";
|
||||
function isNodeBuiltin(id) {
|
||||
// Added in v18.6.0
|
||||
if (module$1.isBuiltin) {
|
||||
return module$1.isBuiltin(id);
|
||||
}
|
||||
if (prefixedBuiltins.has(id)) {
|
||||
return true;
|
||||
}
|
||||
return builtins.has(id.startsWith(NODE_BUILTIN_NAMESPACE) ? id.slice(NODE_BUILTIN_NAMESPACE.length) : id);
|
||||
}
|
||||
|
||||
export { findMockRedirect };
|
||||
@@ -0,0 +1,24 @@
|
||||
import {Buffer} from 'buffer';
|
||||
import {blob, Layout} from '@solana/buffer-layout';
|
||||
import {getU64Codec} from '@solana/codecs-numbers';
|
||||
|
||||
export function u64(property?: string): Layout<bigint> {
|
||||
const layout = blob(8 /* bytes */, property);
|
||||
const decode = layout.decode.bind(layout);
|
||||
const encode = layout.encode.bind(layout);
|
||||
|
||||
const bigIntLayout = layout as Layout<unknown> as Layout<bigint>;
|
||||
const codec = getU64Codec();
|
||||
|
||||
bigIntLayout.decode = (buffer: Buffer, offset: number) => {
|
||||
const src = decode(buffer as Uint8Array, offset);
|
||||
return codec.decode(src);
|
||||
};
|
||||
|
||||
bigIntLayout.encode = (bigInt: bigint, buffer: Buffer, offset: number) => {
|
||||
const src = codec.encode(bigInt) as Uint8Array;
|
||||
return encode(src, buffer as Uint8Array, offset);
|
||||
};
|
||||
|
||||
return bigIntLayout;
|
||||
}
|
||||
@@ -0,0 +1,386 @@
|
||||
/*! *****************************************************************************
|
||||
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,
|
||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
/**
|
||||
* The decorator context types provided to class element decorators.
|
||||
*/
|
||||
type ClassMemberDecoratorContext =
|
||||
| ClassMethodDecoratorContext
|
||||
| ClassGetterDecoratorContext
|
||||
| ClassSetterDecoratorContext
|
||||
| ClassFieldDecoratorContext
|
||||
| ClassAccessorDecoratorContext;
|
||||
|
||||
/**
|
||||
* The decorator context types provided to any decorator.
|
||||
*/
|
||||
type DecoratorContext =
|
||||
| ClassDecoratorContext
|
||||
| ClassMemberDecoratorContext;
|
||||
|
||||
type DecoratorMetadataObject = Record<PropertyKey, unknown> & object;
|
||||
|
||||
type DecoratorMetadata = typeof globalThis extends { Symbol: { readonly metadata: symbol; }; } ? DecoratorMetadataObject : DecoratorMetadataObject | undefined;
|
||||
|
||||
/**
|
||||
* Context provided to a class decorator.
|
||||
* @template Class The type of the decorated class associated with this context.
|
||||
*/
|
||||
interface ClassDecoratorContext<
|
||||
Class extends abstract new (...args: any) => any = abstract new (...args: any) => any,
|
||||
> {
|
||||
/** The kind of element that was decorated. */
|
||||
readonly kind: "class";
|
||||
|
||||
/** The name of the decorated class. */
|
||||
readonly name: string | undefined;
|
||||
|
||||
/**
|
||||
* Adds a callback to be invoked after the class definition has been finalized.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* function customElement(name: string): ClassDecoratorFunction {
|
||||
* return (target, context) => {
|
||||
* context.addInitializer(function () {
|
||||
* customElements.define(name, this);
|
||||
* });
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @customElement("my-element")
|
||||
* class MyElement {}
|
||||
* ```
|
||||
*/
|
||||
addInitializer(initializer: (this: Class) => void): void;
|
||||
|
||||
readonly metadata: DecoratorMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Context provided to a class method decorator.
|
||||
* @template This The type on which the class element will be defined. For a static class element, this will be
|
||||
* the type of the constructor. For a non-static class element, this will be the type of the instance.
|
||||
* @template Value The type of the decorated class method.
|
||||
*/
|
||||
interface ClassMethodDecoratorContext<
|
||||
This = unknown,
|
||||
Value extends (this: This, ...args: any) => any = (this: This, ...args: any) => any,
|
||||
> {
|
||||
/** The kind of class element that was decorated. */
|
||||
readonly kind: "method";
|
||||
|
||||
/** The name of the decorated class element. */
|
||||
readonly name: string | symbol;
|
||||
|
||||
/** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
|
||||
readonly static: boolean;
|
||||
|
||||
/** A value indicating whether the class element has a private name. */
|
||||
readonly private: boolean;
|
||||
|
||||
/** An object that can be used to access the current value of the class element at runtime. */
|
||||
readonly access: {
|
||||
/**
|
||||
* Determines whether an object has a property with the same name as the decorated element.
|
||||
*/
|
||||
has(object: This): boolean;
|
||||
/**
|
||||
* Gets the current value of the method from the provided object.
|
||||
*
|
||||
* @example
|
||||
* let fn = context.access.get(instance);
|
||||
*/
|
||||
get(object: This): Value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a callback to be invoked either before static initializers are run (when
|
||||
* decorating a `static` element), or before instance initializers are run (when
|
||||
* decorating a non-`static` element).
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const bound: ClassMethodDecoratorFunction = (value, context) {
|
||||
* if (context.private) throw new TypeError("Not supported on private methods.");
|
||||
* context.addInitializer(function () {
|
||||
* this[context.name] = this[context.name].bind(this);
|
||||
* });
|
||||
* }
|
||||
*
|
||||
* class C {
|
||||
* message = "Hello";
|
||||
*
|
||||
* @bound
|
||||
* m() {
|
||||
* console.log(this.message);
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
addInitializer(initializer: (this: This) => void): void;
|
||||
|
||||
readonly metadata: DecoratorMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Context provided to a class getter decorator.
|
||||
* @template This The type on which the class element will be defined. For a static class element, this will be
|
||||
* the type of the constructor. For a non-static class element, this will be the type of the instance.
|
||||
* @template Value The property type of the decorated class getter.
|
||||
*/
|
||||
interface ClassGetterDecoratorContext<
|
||||
This = unknown,
|
||||
Value = unknown,
|
||||
> {
|
||||
/** The kind of class element that was decorated. */
|
||||
readonly kind: "getter";
|
||||
|
||||
/** The name of the decorated class element. */
|
||||
readonly name: string | symbol;
|
||||
|
||||
/** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
|
||||
readonly static: boolean;
|
||||
|
||||
/** A value indicating whether the class element has a private name. */
|
||||
readonly private: boolean;
|
||||
|
||||
/** An object that can be used to access the current value of the class element at runtime. */
|
||||
readonly access: {
|
||||
/**
|
||||
* Determines whether an object has a property with the same name as the decorated element.
|
||||
*/
|
||||
has(object: This): boolean;
|
||||
/**
|
||||
* Invokes the getter on the provided object.
|
||||
*
|
||||
* @example
|
||||
* let value = context.access.get(instance);
|
||||
*/
|
||||
get(object: This): Value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a callback to be invoked either before static initializers are run (when
|
||||
* decorating a `static` element), or before instance initializers are run (when
|
||||
* decorating a non-`static` element).
|
||||
*/
|
||||
addInitializer(initializer: (this: This) => void): void;
|
||||
|
||||
readonly metadata: DecoratorMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Context provided to a class setter decorator.
|
||||
* @template This The type on which the class element will be defined. For a static class element, this will be
|
||||
* the type of the constructor. For a non-static class element, this will be the type of the instance.
|
||||
* @template Value The type of the decorated class setter.
|
||||
*/
|
||||
interface ClassSetterDecoratorContext<
|
||||
This = unknown,
|
||||
Value = unknown,
|
||||
> {
|
||||
/** The kind of class element that was decorated. */
|
||||
readonly kind: "setter";
|
||||
|
||||
/** The name of the decorated class element. */
|
||||
readonly name: string | symbol;
|
||||
|
||||
/** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
|
||||
readonly static: boolean;
|
||||
|
||||
/** A value indicating whether the class element has a private name. */
|
||||
readonly private: boolean;
|
||||
|
||||
/** An object that can be used to access the current value of the class element at runtime. */
|
||||
readonly access: {
|
||||
/**
|
||||
* Determines whether an object has a property with the same name as the decorated element.
|
||||
*/
|
||||
has(object: This): boolean;
|
||||
/**
|
||||
* Invokes the setter on the provided object.
|
||||
*
|
||||
* @example
|
||||
* context.access.set(instance, value);
|
||||
*/
|
||||
set(object: This, value: Value): void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a callback to be invoked either before static initializers are run (when
|
||||
* decorating a `static` element), or before instance initializers are run (when
|
||||
* decorating a non-`static` element).
|
||||
*/
|
||||
addInitializer(initializer: (this: This) => void): void;
|
||||
|
||||
readonly metadata: DecoratorMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Context provided to a class `accessor` field decorator.
|
||||
* @template This The type on which the class element will be defined. For a static class element, this will be
|
||||
* the type of the constructor. For a non-static class element, this will be the type of the instance.
|
||||
* @template Value The type of decorated class field.
|
||||
*/
|
||||
interface ClassAccessorDecoratorContext<
|
||||
This = unknown,
|
||||
Value = unknown,
|
||||
> {
|
||||
/** The kind of class element that was decorated. */
|
||||
readonly kind: "accessor";
|
||||
|
||||
/** The name of the decorated class element. */
|
||||
readonly name: string | symbol;
|
||||
|
||||
/** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
|
||||
readonly static: boolean;
|
||||
|
||||
/** A value indicating whether the class element has a private name. */
|
||||
readonly private: boolean;
|
||||
|
||||
/** An object that can be used to access the current value of the class element at runtime. */
|
||||
readonly access: {
|
||||
/**
|
||||
* Determines whether an object has a property with the same name as the decorated element.
|
||||
*/
|
||||
has(object: This): boolean;
|
||||
|
||||
/**
|
||||
* Invokes the getter on the provided object.
|
||||
*
|
||||
* @example
|
||||
* let value = context.access.get(instance);
|
||||
*/
|
||||
get(object: This): Value;
|
||||
|
||||
/**
|
||||
* Invokes the setter on the provided object.
|
||||
*
|
||||
* @example
|
||||
* context.access.set(instance, value);
|
||||
*/
|
||||
set(object: This, value: Value): void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a callback to be invoked either before static initializers are run (when
|
||||
* decorating a `static` element), or before instance initializers are run (when
|
||||
* decorating a non-`static` element).
|
||||
*/
|
||||
addInitializer(initializer: (this: This) => void): void;
|
||||
|
||||
readonly metadata: DecoratorMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the target provided to class `accessor` field decorators.
|
||||
* @template This The `this` type to which the target applies.
|
||||
* @template Value The property type for the class `accessor` field.
|
||||
*/
|
||||
interface ClassAccessorDecoratorTarget<This, Value> {
|
||||
/**
|
||||
* Invokes the getter that was defined prior to decorator application.
|
||||
*
|
||||
* @example
|
||||
* let value = target.get.call(instance);
|
||||
*/
|
||||
get(this: This): Value;
|
||||
|
||||
/**
|
||||
* Invokes the setter that was defined prior to decorator application.
|
||||
*
|
||||
* @example
|
||||
* target.set.call(instance, value);
|
||||
*/
|
||||
set(this: This, value: Value): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the allowed return value from a class `accessor` field decorator.
|
||||
* @template This The `this` type to which the target applies.
|
||||
* @template Value The property type for the class `accessor` field.
|
||||
*/
|
||||
interface ClassAccessorDecoratorResult<This, Value> {
|
||||
/**
|
||||
* An optional replacement getter function. If not provided, the existing getter function is used instead.
|
||||
*/
|
||||
get?(this: This): Value;
|
||||
|
||||
/**
|
||||
* An optional replacement setter function. If not provided, the existing setter function is used instead.
|
||||
*/
|
||||
set?(this: This, value: Value): void;
|
||||
|
||||
/**
|
||||
* An optional initializer mutator that is invoked when the underlying field initializer is evaluated.
|
||||
* @param value The incoming initializer value.
|
||||
* @returns The replacement initializer value.
|
||||
*/
|
||||
init?(this: This, value: Value): Value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Context provided to a class field decorator.
|
||||
* @template This The type on which the class element will be defined. For a static class element, this will be
|
||||
* the type of the constructor. For a non-static class element, this will be the type of the instance.
|
||||
* @template Value The type of the decorated class field.
|
||||
*/
|
||||
interface ClassFieldDecoratorContext<
|
||||
This = unknown,
|
||||
Value = unknown,
|
||||
> {
|
||||
/** The kind of class element that was decorated. */
|
||||
readonly kind: "field";
|
||||
|
||||
/** The name of the decorated class element. */
|
||||
readonly name: string | symbol;
|
||||
|
||||
/** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
|
||||
readonly static: boolean;
|
||||
|
||||
/** A value indicating whether the class element has a private name. */
|
||||
readonly private: boolean;
|
||||
|
||||
/** An object that can be used to access the current value of the class element at runtime. */
|
||||
readonly access: {
|
||||
/**
|
||||
* Determines whether an object has a property with the same name as the decorated element.
|
||||
*/
|
||||
has(object: This): boolean;
|
||||
|
||||
/**
|
||||
* Gets the value of the field on the provided object.
|
||||
*/
|
||||
get(object: This): Value;
|
||||
|
||||
/**
|
||||
* Sets the value of the field on the provided object.
|
||||
*/
|
||||
set(object: This, value: Value): void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a callback to be invoked either before static initializers are run (when
|
||||
* decorating a `static` element), or before instance initializers are run (when
|
||||
* decorating a non-`static` element).
|
||||
*/
|
||||
addInitializer(initializer: (this: This) => void): void;
|
||||
|
||||
readonly metadata: DecoratorMetadata;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
var classApplyDescriptorDestructureSet = require("./classApplyDescriptorDestructureSet.js");
|
||||
var assertClassBrand = require("./assertClassBrand.js");
|
||||
var classCheckPrivateStaticFieldDescriptor = require("./classCheckPrivateStaticFieldDescriptor.js");
|
||||
function _classStaticPrivateFieldDestructureSet(t, r, s) {
|
||||
return assertClassBrand(r, t), classCheckPrivateStaticFieldDescriptor(s, "set"), classApplyDescriptorDestructureSet(t, s);
|
||||
}
|
||||
module.exports = _classStaticPrivateFieldDestructureSet, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { TSESLint } from '@typescript-eslint/utils';
|
||||
export type MessageId = 'noUnnecessaryTemplateExpression';
|
||||
declare const _default: TSESLint.RuleModule<"noUnnecessaryTemplateExpression", [], import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
|
||||
name: string;
|
||||
};
|
||||
export default _default;
|
||||
@@ -0,0 +1,75 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert'
|
||||
import { readFile } from 'fs'
|
||||
import ThreadStream from '../index.js'
|
||||
import { join } from 'desm'
|
||||
import { file } from './helper.js'
|
||||
|
||||
test('break up utf8 multibyte (sync)', (t, done) => {
|
||||
const longString = '\u03A3'.repeat(16)
|
||||
|
||||
const dest = file()
|
||||
const stream = new ThreadStream({
|
||||
bufferSize: 15, // this must be odd
|
||||
filename: join(import.meta.url, 'to-file.js'),
|
||||
workerData: { dest },
|
||||
sync: true
|
||||
})
|
||||
|
||||
stream.on('finish', () => {
|
||||
readFile(dest, 'utf8', (err, data) => {
|
||||
assert.ifError(err)
|
||||
assert.strictEqual(data, longString)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
stream.write(longString)
|
||||
stream.end()
|
||||
})
|
||||
|
||||
test('break up utf8 multibyte (async)', (t, done) => {
|
||||
const longString = '\u03A3'.repeat(16)
|
||||
|
||||
const dest = file()
|
||||
const stream = new ThreadStream({
|
||||
bufferSize: 15, // this must be odd
|
||||
filename: join(import.meta.url, 'to-file.js'),
|
||||
workerData: { dest },
|
||||
sync: false
|
||||
})
|
||||
|
||||
stream.on('finish', () => {
|
||||
readFile(dest, 'utf8', (err, data) => {
|
||||
assert.ifError(err)
|
||||
assert.strictEqual(data, longString)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
stream.write(longString)
|
||||
stream.end()
|
||||
})
|
||||
|
||||
test('break up utf8 multibyte several times bigger than write buffer', (t, done) => {
|
||||
const longString = '\u03A3'.repeat(32)
|
||||
|
||||
const dest = file()
|
||||
const stream = new ThreadStream({
|
||||
bufferSize: 15, // this must be odd
|
||||
filename: join(import.meta.url, 'to-file.js'),
|
||||
workerData: { dest },
|
||||
sync: false
|
||||
})
|
||||
|
||||
stream.on('finish', () => {
|
||||
readFile(dest, 'utf8', (err, data) => {
|
||||
assert.ifError(err)
|
||||
assert.strictEqual(data, longString)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
stream.write(longString)
|
||||
stream.end()
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
import * as BufferLayout from '@solana/buffer-layout';
|
||||
|
||||
/**
|
||||
* https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export const FeeCalculatorLayout = BufferLayout.nu64('lamportsPerSignature');
|
||||
|
||||
/**
|
||||
* Calculator for transaction fees.
|
||||
*
|
||||
* @deprecated Deprecated since Solana v1.8.0.
|
||||
*/
|
||||
export interface FeeCalculator {
|
||||
/** Cost in lamports to validate a signature. */
|
||||
lamportsPerSignature: number;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export * from './constants';
|
||||
export * from './expiry-custom-errors';
|
||||
export * from './legacy';
|
||||
export * from './message';
|
||||
export * from './versioned';
|
||||
@@ -0,0 +1,8 @@
|
||||
import type { TSESTree } from '@typescript-eslint/types';
|
||||
import type { ScopeManager } from '../ScopeManager';
|
||||
import type { Scope } from './Scope';
|
||||
import { ScopeBase } from './ScopeBase';
|
||||
import { ScopeType } from './ScopeType';
|
||||
export declare class ClassScope extends ScopeBase<ScopeType.class, TSESTree.ClassDeclaration | TSESTree.ClassExpression, Scope> {
|
||||
constructor(scopeManager: ScopeManager, upperScope: ClassScope['upper'], block: ClassScope['block']);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Disposable = void 0;
|
||||
var Disposable;
|
||||
(function (Disposable) {
|
||||
function create(func) {
|
||||
return {
|
||||
dispose: func
|
||||
};
|
||||
}
|
||||
Disposable.create = create;
|
||||
})(Disposable || (exports.Disposable = Disposable = {}));
|
||||
@@ -0,0 +1,91 @@
|
||||
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
|
||||
import { NumberCodecConfig } from './common';
|
||||
/**
|
||||
* Returns an encoder for 128-bit signed integers (`i128`).
|
||||
*
|
||||
* This encoder serializes `i128` values using 16 bytes.
|
||||
* Values can be provided as either `number` or `bigint`.
|
||||
*
|
||||
* For more details, see {@link getI128Codec}.
|
||||
*
|
||||
* @param config - Optional configuration to specify endianness (little by default).
|
||||
* @returns A `FixedSizeEncoder<number | bigint, 16>` for encoding `i128` values.
|
||||
*
|
||||
* @example
|
||||
* Encoding an `i128` value.
|
||||
* ```ts
|
||||
* const encoder = getI128Encoder();
|
||||
* const bytes = encoder.encode(-42n); // 0xd6ffffffffffffffffffffffffffffff
|
||||
* ```
|
||||
*
|
||||
* @see {@link getI128Codec}
|
||||
*/
|
||||
export declare const getI128Encoder: (config?: NumberCodecConfig) => FixedSizeEncoder<bigint | number, 16>;
|
||||
/**
|
||||
* Returns a decoder for 128-bit signed integers (`i128`).
|
||||
*
|
||||
* This decoder deserializes `i128` values from 16 bytes.
|
||||
* The decoded value is always a `bigint`.
|
||||
*
|
||||
* For more details, see {@link getI128Codec}.
|
||||
*
|
||||
* @param config - Optional configuration to specify endianness (little by default).
|
||||
* @returns A `FixedSizeDecoder<bigint, 16>` for decoding `i128` values.
|
||||
*
|
||||
* @example
|
||||
* Decoding an `i128` value.
|
||||
* ```ts
|
||||
* const decoder = getI128Decoder();
|
||||
* const value = decoder.decode(new Uint8Array([
|
||||
* 0xd6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
* 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
|
||||
* ])); // -42n
|
||||
* ```
|
||||
*
|
||||
* @see {@link getI128Codec}
|
||||
*/
|
||||
export declare const getI128Decoder: (config?: NumberCodecConfig) => FixedSizeDecoder<bigint, 16>;
|
||||
/**
|
||||
* Returns a codec for encoding and decoding 128-bit signed integers (`i128`).
|
||||
*
|
||||
* This codec serializes `i128` values using 16 bytes.
|
||||
* Values can be provided as either `number` or `bigint`, but the decoded value is always a `bigint`.
|
||||
*
|
||||
* @param config - Optional configuration to specify endianness (little by default).
|
||||
* @returns A `FixedSizeCodec<number | bigint, bigint, 16>` for encoding and decoding `i128` values.
|
||||
*
|
||||
* @example
|
||||
* Encoding and decoding an `i128` value.
|
||||
* ```ts
|
||||
* const codec = getI128Codec();
|
||||
* const bytes = codec.encode(-42n); // 0xd6ffffffffffffffffffffffffffffff
|
||||
* const value = codec.decode(bytes); // -42n
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* Using big-endian encoding.
|
||||
* ```ts
|
||||
* const codec = getI128Codec({ endian: Endian.Big });
|
||||
* const bytes = codec.encode(-42n); // 0xffffffffffffffffffffffffffffd6
|
||||
* ```
|
||||
*
|
||||
* @remarks
|
||||
* This codec supports values between `-2^127` and `2^127 - 1`.
|
||||
* Since JavaScript `number` cannot safely represent values beyond `2^53 - 1`, the decoded value is always a `bigint`.
|
||||
*
|
||||
* - If you need a smaller signed integer, consider using {@link getI64Codec} or {@link getI32Codec}.
|
||||
* - If you need a larger signed integer, consider using a custom codec.
|
||||
* - If you need unsigned integers, consider using {@link getU128Codec}.
|
||||
*
|
||||
* Separate {@link getI128Encoder} and {@link getI128Decoder} functions are available.
|
||||
*
|
||||
* ```ts
|
||||
* const bytes = getI128Encoder().encode(-42);
|
||||
* const value = getI128Decoder().decode(bytes);
|
||||
* ```
|
||||
*
|
||||
* @see {@link getI128Encoder}
|
||||
* @see {@link getI128Decoder}
|
||||
*/
|
||||
export declare const getI128Codec: (config?: NumberCodecConfig) => FixedSizeCodec<bigint | number, bigint, 16>;
|
||||
//# sourceMappingURL=i128.d.ts.map
|
||||
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* @fileoverview Rule to enforce a maximum number of nested callbacks.
|
||||
* @author Ian Christian Myers
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
docs: {
|
||||
description: "Enforce a maximum depth that callbacks can be nested",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/max-nested-callbacks",
|
||||
},
|
||||
|
||||
schema: [
|
||||
{
|
||||
oneOf: [
|
||||
{
|
||||
type: "integer",
|
||||
minimum: 0,
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
maximum: {
|
||||
type: "integer",
|
||||
minimum: 0,
|
||||
},
|
||||
max: {
|
||||
type: "integer",
|
||||
minimum: 0,
|
||||
},
|
||||
checkConstructorCallCallbacks: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
defaultOptions: [10],
|
||||
|
||||
messages: {
|
||||
exceed: "Too many nested callbacks ({{num}}). Maximum allowed is {{max}}.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Constants
|
||||
//--------------------------------------------------------------------------
|
||||
const option = context.options[0];
|
||||
let THRESHOLD = 10;
|
||||
|
||||
if (
|
||||
typeof option === "object" &&
|
||||
(Object.hasOwn(option, "maximum") || Object.hasOwn(option, "max"))
|
||||
) {
|
||||
THRESHOLD = option.maximum || option.max;
|
||||
} else if (typeof option === "number") {
|
||||
THRESHOLD = option;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
const callbackStack = [];
|
||||
|
||||
/**
|
||||
* Checks a given function node for too many callbacks.
|
||||
* @param {ASTNode} node The node to check.
|
||||
* @returns {void}
|
||||
* @private
|
||||
*/
|
||||
function checkFunction(node) {
|
||||
const parent = node.parent;
|
||||
|
||||
if (
|
||||
(parent.type !== "CallExpression" &&
|
||||
!(
|
||||
option.checkConstructorCallCallbacks &&
|
||||
parent.type === "NewExpression"
|
||||
)) ||
|
||||
parent.callee === node
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
callbackStack.push(node);
|
||||
|
||||
if (callbackStack.length > THRESHOLD) {
|
||||
const opts = { num: callbackStack.length, max: THRESHOLD };
|
||||
|
||||
context.report({
|
||||
node,
|
||||
loc: astUtils.getFunctionHeadLoc(node, sourceCode),
|
||||
messageId: "exceed",
|
||||
data: opts,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pops the call stack.
|
||||
* @param {ASTNode} node The node to check.
|
||||
* @returns {void}
|
||||
* @private
|
||||
*/
|
||||
function popStack(node) {
|
||||
if (callbackStack.at(-1) === node) {
|
||||
callbackStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public API
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
ArrowFunctionExpression: checkFunction,
|
||||
"ArrowFunctionExpression:exit": popStack,
|
||||
|
||||
FunctionExpression: checkFunction,
|
||||
"FunctionExpression:exit": popStack,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"reg": {
|
||||
"name": "reg",
|
||||
"browser": "Edge 14.14393.0 (Windows 10 0.0.0)",
|
||||
"suite": "escape-short",
|
||||
"hz": 613213.9007119045,
|
||||
"success": true,
|
||||
"fastest": false,
|
||||
"rme": 0.014974749195626105,
|
||||
"rhz": 0.4084658150744344,
|
||||
"sampleSize": 172
|
||||
},
|
||||
"fn if": {
|
||||
"name": "fn if",
|
||||
"browser": "Edge 14.14393.0 (Windows 10 0.0.0)",
|
||||
"suite": "escape-short",
|
||||
"hz": 714253.4975991725,
|
||||
"success": true,
|
||||
"fastest": false,
|
||||
"rme": 0.018992545536700448,
|
||||
"rhz": 0.4757689555437499,
|
||||
"sampleSize": 168
|
||||
},
|
||||
"fn if reverse": {
|
||||
"name": "fn if reverse",
|
||||
"browser": "Edge 14.14393.0 (Windows 10 0.0.0)",
|
||||
"suite": "escape-short",
|
||||
"hz": 595903.4738796077,
|
||||
"success": true,
|
||||
"fastest": false,
|
||||
"rme": 0.017260970308691965,
|
||||
"rhz": 0.3969352258344779,
|
||||
"sampleSize": 167
|
||||
},
|
||||
"escape31": {
|
||||
"name": "escape31",
|
||||
"browser": "Edge 14.14393.0 (Windows 10 0.0.0)",
|
||||
"suite": "escape-short",
|
||||
"hz": 1013969.6558224236,
|
||||
"success": true,
|
||||
"fastest": false,
|
||||
"rme": 0.01728600326103597,
|
||||
"rhz": 0.6754118610902676,
|
||||
"sampleSize": 172
|
||||
},
|
||||
"native": {
|
||||
"name": "native",
|
||||
"browser": "Edge 14.14393.0 (Windows 10 0.0.0)",
|
||||
"suite": "escape-short",
|
||||
"hz": 1501261.2514468536,
|
||||
"success": true,
|
||||
"fastest": true,
|
||||
"rme": 0.012863296877945634,
|
||||
"rhz": 1,
|
||||
"sampleSize": 172
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
# path-key [](https://travis-ci.org/sindresorhus/path-key)
|
||||
|
||||
> Get the [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) environment variable key cross-platform
|
||||
|
||||
It's usually `PATH`, but on Windows it can be any casing like `Path`...
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install path-key
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const pathKey = require('path-key');
|
||||
|
||||
const key = pathKey();
|
||||
//=> 'PATH'
|
||||
|
||||
const PATH = process.env[key];
|
||||
//=> '/usr/local/bin:/usr/bin:/bin'
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### pathKey(options?)
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### env
|
||||
|
||||
Type: `object`<br>
|
||||
Default: [`process.env`](https://nodejs.org/api/process.html#process_process_env)
|
||||
|
||||
Use a custom environment variables object.
|
||||
|
||||
#### platform
|
||||
|
||||
Type: `string`<br>
|
||||
Default: [`process.platform`](https://nodejs.org/api/process.html#process_process_platform)
|
||||
|
||||
Get the PATH key for a specific platform.
|
||||
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-path-key?utm_source=npm-path-key&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
||||
@@ -0,0 +1,152 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
const util = __importStar(require("../core/util.cjs"));
|
||||
const error = () => {
|
||||
const Sizable = {
|
||||
string: { unit: "caractères", verb: "avoir" },
|
||||
file: { unit: "octets", verb: "avoir" },
|
||||
array: { unit: "éléments", verb: "avoir" },
|
||||
set: { unit: "éléments", verb: "avoir" },
|
||||
};
|
||||
function getSizing(origin) {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
const FormatDictionary = {
|
||||
regex: "entrée",
|
||||
email: "adresse e-mail",
|
||||
url: "URL",
|
||||
emoji: "emoji",
|
||||
uuid: "UUID",
|
||||
uuidv4: "UUIDv4",
|
||||
uuidv6: "UUIDv6",
|
||||
nanoid: "nanoid",
|
||||
guid: "GUID",
|
||||
cuid: "cuid",
|
||||
cuid2: "cuid2",
|
||||
ulid: "ULID",
|
||||
xid: "XID",
|
||||
ksuid: "KSUID",
|
||||
datetime: "date et heure ISO",
|
||||
date: "date ISO",
|
||||
time: "heure ISO",
|
||||
duration: "durée ISO",
|
||||
ipv4: "adresse IPv4",
|
||||
ipv6: "adresse IPv6",
|
||||
cidrv4: "plage IPv4",
|
||||
cidrv6: "plage IPv6",
|
||||
base64: "chaîne encodée en base64",
|
||||
base64url: "chaîne encodée en base64url",
|
||||
json_string: "chaîne JSON",
|
||||
e164: "numéro E.164",
|
||||
jwt: "JWT",
|
||||
template_literal: "entrée",
|
||||
};
|
||||
const TypeDictionary = {
|
||||
string: "chaîne",
|
||||
number: "nombre",
|
||||
int: "entier",
|
||||
boolean: "booléen",
|
||||
bigint: "grand entier",
|
||||
symbol: "symbole",
|
||||
undefined: "indéfini",
|
||||
null: "null",
|
||||
never: "jamais",
|
||||
void: "vide",
|
||||
date: "date",
|
||||
array: "tableau",
|
||||
object: "objet",
|
||||
tuple: "tuple",
|
||||
record: "enregistrement",
|
||||
map: "carte",
|
||||
set: "ensemble",
|
||||
file: "fichier",
|
||||
nonoptional: "non-optionnel",
|
||||
nan: "NaN",
|
||||
function: "fonction",
|
||||
};
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
if (/^[A-Z]/.test(issue.expected)) {
|
||||
return `Entrée invalide : instanceof ${issue.expected} attendu, ${received} reçu`;
|
||||
}
|
||||
return `Entrée invalide : ${expected} attendu, ${received} reçu`;
|
||||
}
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1)
|
||||
return `Entrée invalide : ${util.stringifyPrimitive(issue.values[0])} attendu`;
|
||||
return `Option invalide : une valeur parmi ${util.joinValues(issue.values, "|")} attendue`;
|
||||
case "too_big": {
|
||||
const adj = issue.inclusive ? "<=" : "<";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing)
|
||||
return `Trop grand : ${TypeDictionary[issue.origin] ?? "valeur"} doit ${sizing.verb} ${adj}${issue.maximum.toString()} ${sizing.unit ?? "élément(s)"}`;
|
||||
return `Trop grand : ${TypeDictionary[issue.origin] ?? "valeur"} doit être ${adj}${issue.maximum.toString()}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const adj = issue.inclusive ? ">=" : ">";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing)
|
||||
return `Trop petit : ${TypeDictionary[issue.origin] ?? "valeur"} doit ${sizing.verb} ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
||||
return `Trop petit : ${TypeDictionary[issue.origin] ?? "valeur"} doit être ${adj}${issue.minimum.toString()}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue;
|
||||
if (_issue.format === "starts_with")
|
||||
return `Chaîne invalide : doit commencer par "${_issue.prefix}"`;
|
||||
if (_issue.format === "ends_with")
|
||||
return `Chaîne invalide : doit se terminer par "${_issue.suffix}"`;
|
||||
if (_issue.format === "includes")
|
||||
return `Chaîne invalide : doit inclure "${_issue.includes}"`;
|
||||
if (_issue.format === "regex")
|
||||
return `Chaîne invalide : doit correspondre au modèle ${_issue.pattern}`;
|
||||
return `${FormatDictionary[_issue.format] ?? issue.format} invalide`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `Nombre invalide : doit être un multiple de ${issue.divisor}`;
|
||||
case "unrecognized_keys":
|
||||
return `Clé${issue.keys.length > 1 ? "s" : ""} non reconnue${issue.keys.length > 1 ? "s" : ""} : ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return `Clé invalide dans ${issue.origin}`;
|
||||
case "invalid_union":
|
||||
return "Entrée invalide";
|
||||
case "invalid_element":
|
||||
return `Valeur invalide dans ${issue.origin}`;
|
||||
default:
|
||||
return `Entrée invalide`;
|
||||
}
|
||||
};
|
||||
};
|
||||
function default_1() {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
module.exports = exports.default;
|
||||
@@ -0,0 +1,7 @@
|
||||
import { URISchemeHandler, URIComponents } from "../uri";
|
||||
export interface WSComponents extends URIComponents {
|
||||
resourceName?: string;
|
||||
secure?: boolean;
|
||||
}
|
||||
declare const handler: URISchemeHandler;
|
||||
export default handler;
|
||||
@@ -0,0 +1,34 @@
|
||||
import { a as RolldownLog } from "./logging-xuHO4mAy.mjs";
|
||||
//#region src/get-log-filter.d.ts
|
||||
/**
|
||||
* @param filters A list of log filters to apply
|
||||
* @returns A function that tests whether a log should be output
|
||||
*
|
||||
* @category Config
|
||||
*/
|
||||
type GetLogFilter = (filters: string[]) => (log: RolldownLog) => boolean;
|
||||
/**
|
||||
* A helper function to generate log filters using the same syntax as the CLI.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { defineConfig } from 'rolldown';
|
||||
* import { getLogFilter } from 'rolldown/getLogFilter';
|
||||
*
|
||||
* const logFilter = getLogFilter(['code:FOO', 'code:BAR']);
|
||||
*
|
||||
* export default defineConfig({
|
||||
* input: 'main.js',
|
||||
* onLog(level, log, handler) {
|
||||
* if (logFilter(log)) {
|
||||
* handler(level, log);
|
||||
* }
|
||||
* }
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @category Config
|
||||
*/
|
||||
declare const getLogFilter: GetLogFilter;
|
||||
//#endregion
|
||||
export { getLogFilter as n, GetLogFilter as t };
|
||||
@@ -0,0 +1,434 @@
|
||||
// @ts-ignore TS6133
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
import * as z from "zod/v3";
|
||||
import { util } from "../helpers/util.js";
|
||||
|
||||
const Test = z.object({
|
||||
f1: z.number(),
|
||||
f2: z.string().optional(),
|
||||
f3: z.string().nullable(),
|
||||
f4: z.array(z.object({ t: z.union([z.string(), z.boolean()]) })),
|
||||
});
|
||||
|
||||
test("object type inference", () => {
|
||||
type TestType = {
|
||||
f1: number;
|
||||
f2?: string | undefined;
|
||||
f3: string | null;
|
||||
f4: { t: string | boolean }[];
|
||||
};
|
||||
|
||||
util.assertEqual<z.TypeOf<typeof Test>, TestType>(true);
|
||||
});
|
||||
|
||||
test("unknown throw", () => {
|
||||
const asdf: unknown = 35;
|
||||
expect(() => Test.parse(asdf)).toThrow();
|
||||
});
|
||||
|
||||
test("shape() should return schema of particular key", () => {
|
||||
const f1Schema = Test.shape.f1;
|
||||
const f2Schema = Test.shape.f2;
|
||||
const f3Schema = Test.shape.f3;
|
||||
const f4Schema = Test.shape.f4;
|
||||
|
||||
expect(f1Schema).toBeInstanceOf(z.ZodNumber);
|
||||
expect(f2Schema).toBeInstanceOf(z.ZodOptional);
|
||||
expect(f3Schema).toBeInstanceOf(z.ZodNullable);
|
||||
expect(f4Schema).toBeInstanceOf(z.ZodArray);
|
||||
});
|
||||
|
||||
test("correct parsing", () => {
|
||||
Test.parse({
|
||||
f1: 12,
|
||||
f2: "string",
|
||||
f3: "string",
|
||||
f4: [
|
||||
{
|
||||
t: "string",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Test.parse({
|
||||
f1: 12,
|
||||
f3: null,
|
||||
f4: [
|
||||
{
|
||||
t: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("incorrect #1", () => {
|
||||
expect(() => Test.parse({} as any)).toThrow();
|
||||
});
|
||||
|
||||
test("nonstrict by default", () => {
|
||||
z.object({ points: z.number() }).parse({
|
||||
points: 2314,
|
||||
unknown: "asdf",
|
||||
});
|
||||
});
|
||||
|
||||
const data = {
|
||||
points: 2314,
|
||||
unknown: "asdf",
|
||||
};
|
||||
|
||||
test("strip by default", () => {
|
||||
const val = z.object({ points: z.number() }).parse(data);
|
||||
expect(val).toEqual({ points: 2314 });
|
||||
});
|
||||
|
||||
test("unknownkeys override", () => {
|
||||
const val = z.object({ points: z.number() }).strict().passthrough().strip().nonstrict().parse(data);
|
||||
|
||||
expect(val).toEqual(data);
|
||||
});
|
||||
|
||||
test("passthrough unknown", () => {
|
||||
const val = z.object({ points: z.number() }).passthrough().parse(data);
|
||||
|
||||
expect(val).toEqual(data);
|
||||
});
|
||||
|
||||
test("strip unknown", () => {
|
||||
const val = z.object({ points: z.number() }).strip().parse(data);
|
||||
|
||||
expect(val).toEqual({ points: 2314 });
|
||||
});
|
||||
|
||||
test("strict", () => {
|
||||
const val = z.object({ points: z.number() }).strict().safeParse(data);
|
||||
|
||||
expect(val.success).toEqual(false);
|
||||
});
|
||||
|
||||
test("catchall inference", () => {
|
||||
const o1 = z
|
||||
.object({
|
||||
first: z.string(),
|
||||
})
|
||||
.catchall(z.number());
|
||||
|
||||
const d1 = o1.parse({ first: "asdf", num: 1243 });
|
||||
util.assertEqual<number, (typeof d1)["asdf"]>(true);
|
||||
util.assertEqual<string, (typeof d1)["first"]>(true);
|
||||
});
|
||||
|
||||
test("catchall overrides strict", () => {
|
||||
const o1 = z.object({ first: z.string().optional() }).strict().catchall(z.number());
|
||||
|
||||
// should run fine
|
||||
// setting a catchall overrides the unknownKeys behavior
|
||||
o1.parse({
|
||||
asdf: 1234,
|
||||
});
|
||||
|
||||
// should only run catchall validation
|
||||
// against unknown keys
|
||||
o1.parse({
|
||||
first: "asdf",
|
||||
asdf: 1234,
|
||||
});
|
||||
});
|
||||
|
||||
test("catchall overrides strict", () => {
|
||||
const o1 = z
|
||||
.object({
|
||||
first: z.string(),
|
||||
})
|
||||
.strict()
|
||||
.catchall(z.number());
|
||||
|
||||
// should run fine
|
||||
// setting a catchall overrides the unknownKeys behavior
|
||||
o1.parse({
|
||||
first: "asdf",
|
||||
asdf: 1234,
|
||||
});
|
||||
});
|
||||
|
||||
test("test that optional keys are unset", () => {
|
||||
const SNamedEntity = z.object({
|
||||
id: z.string(),
|
||||
set: z.string().optional(),
|
||||
unset: z.string().optional(),
|
||||
});
|
||||
const result = SNamedEntity.parse({
|
||||
id: "asdf",
|
||||
set: undefined,
|
||||
});
|
||||
// eslint-disable-next-line ban/ban
|
||||
expect(Object.keys(result)).toEqual(["id", "set"]);
|
||||
});
|
||||
|
||||
test("test catchall parsing", async () => {
|
||||
const result = z.object({ name: z.string() }).catchall(z.number()).parse({ name: "Foo", validExtraKey: 61 });
|
||||
|
||||
expect(result).toEqual({ name: "Foo", validExtraKey: 61 });
|
||||
|
||||
const result2 = z
|
||||
.object({ name: z.string() })
|
||||
.catchall(z.number())
|
||||
.safeParse({ name: "Foo", validExtraKey: 61, invalid: "asdf" });
|
||||
|
||||
expect(result2.success).toEqual(false);
|
||||
});
|
||||
|
||||
test("test nonexistent keys", async () => {
|
||||
const Schema = z.union([z.object({ a: z.string() }), z.object({ b: z.number() })]);
|
||||
const obj = { a: "A" };
|
||||
const result = await Schema.spa(obj); // Works with 1.11.10, breaks with 2.0.0-beta.21
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
test("test async union", async () => {
|
||||
const Schema2 = z.union([
|
||||
z.object({
|
||||
ty: z.string(),
|
||||
}),
|
||||
z.object({
|
||||
ty: z.number(),
|
||||
}),
|
||||
]);
|
||||
|
||||
const obj = { ty: "A" };
|
||||
const result = await Schema2.spa(obj); // Works with 1.11.10, breaks with 2.0.0-beta.21
|
||||
expect(result.success).toEqual(true);
|
||||
});
|
||||
|
||||
test("test inferred merged type", async () => {
|
||||
const asdf = z.object({ a: z.string() }).merge(z.object({ a: z.number() }));
|
||||
type asdf = z.infer<typeof asdf>;
|
||||
util.assertEqual<asdf, { a: number }>(true);
|
||||
});
|
||||
|
||||
test("inferred merged object type with optional properties", async () => {
|
||||
const Merged = z
|
||||
.object({ a: z.string(), b: z.string().optional() })
|
||||
.merge(z.object({ a: z.string().optional(), b: z.string() }));
|
||||
type Merged = z.infer<typeof Merged>;
|
||||
util.assertEqual<Merged, { a?: string | undefined; b: string }>(true);
|
||||
// todo
|
||||
// util.assertEqual<Merged, { a?: string | undefined; b: string }>(true);
|
||||
});
|
||||
|
||||
test("inferred unioned object type with optional properties", async () => {
|
||||
const Unioned = z.union([
|
||||
z.object({ a: z.string(), b: z.string().optional() }),
|
||||
z.object({ a: z.string().optional(), b: z.string() }),
|
||||
]);
|
||||
type Unioned = z.infer<typeof Unioned>;
|
||||
util.assertEqual<Unioned, { a: string; b?: string | undefined } | { a?: string | undefined; b: string }>(true);
|
||||
});
|
||||
|
||||
test("inferred enum type", async () => {
|
||||
const Enum = z.object({ a: z.string(), b: z.string().optional() }).keyof();
|
||||
|
||||
expect(Enum.Values).toEqual({
|
||||
a: "a",
|
||||
b: "b",
|
||||
});
|
||||
expect(Enum.enum).toEqual({
|
||||
a: "a",
|
||||
b: "b",
|
||||
});
|
||||
expect(Enum._def.values).toEqual(["a", "b"]);
|
||||
type Enum = z.infer<typeof Enum>;
|
||||
util.assertEqual<Enum, "a" | "b">(true);
|
||||
});
|
||||
|
||||
test("inferred partial object type with optional properties", async () => {
|
||||
const Partial = z.object({ a: z.string(), b: z.string().optional() }).partial();
|
||||
type Partial = z.infer<typeof Partial>;
|
||||
util.assertEqual<Partial, { a?: string | undefined; b?: string | undefined }>(true);
|
||||
});
|
||||
|
||||
test("inferred picked object type with optional properties", async () => {
|
||||
const Picked = z.object({ a: z.string(), b: z.string().optional() }).pick({ b: true });
|
||||
type Picked = z.infer<typeof Picked>;
|
||||
util.assertEqual<Picked, { b?: string | undefined }>(true);
|
||||
});
|
||||
|
||||
test("inferred type for unknown/any keys", () => {
|
||||
const myType = z.object({
|
||||
anyOptional: z.any().optional(),
|
||||
anyRequired: z.any(),
|
||||
unknownOptional: z.unknown().optional(),
|
||||
unknownRequired: z.unknown(),
|
||||
});
|
||||
type myType = z.infer<typeof myType>;
|
||||
util.assertEqual<
|
||||
myType,
|
||||
{
|
||||
anyOptional?: any;
|
||||
anyRequired?: any;
|
||||
unknownOptional?: unknown;
|
||||
unknownRequired?: unknown;
|
||||
}
|
||||
>(true);
|
||||
});
|
||||
|
||||
test("setKey", () => {
|
||||
const base = z.object({ name: z.string() });
|
||||
const withNewKey = base.setKey("age", z.number());
|
||||
|
||||
type withNewKey = z.infer<typeof withNewKey>;
|
||||
util.assertEqual<withNewKey, { name: string; age: number }>(true);
|
||||
withNewKey.parse({ name: "asdf", age: 1234 });
|
||||
});
|
||||
|
||||
test("strictcreate", async () => {
|
||||
const strictObj = z.strictObject({
|
||||
name: z.string(),
|
||||
});
|
||||
|
||||
const syncResult = strictObj.safeParse({ name: "asdf", unexpected: 13 });
|
||||
expect(syncResult.success).toEqual(false);
|
||||
|
||||
const asyncResult = await strictObj.spa({ name: "asdf", unexpected: 13 });
|
||||
expect(asyncResult.success).toEqual(false);
|
||||
});
|
||||
|
||||
test("object with refine", async () => {
|
||||
const schema = z
|
||||
.object({
|
||||
a: z.string().default("foo"),
|
||||
b: z.number(),
|
||||
})
|
||||
.refine(() => true);
|
||||
expect(schema.parse({ b: 5 })).toEqual({ b: 5, a: "foo" });
|
||||
const result = await schema.parseAsync({ b: 5 });
|
||||
expect(result).toEqual({ b: 5, a: "foo" });
|
||||
});
|
||||
|
||||
test("intersection of object with date", async () => {
|
||||
const schema = z.object({
|
||||
a: z.date(),
|
||||
});
|
||||
expect(schema.and(schema).parse({ a: new Date(1637353595983) })).toEqual({
|
||||
a: new Date(1637353595983),
|
||||
});
|
||||
const result = await schema.parseAsync({ a: new Date(1637353595983) });
|
||||
expect(result).toEqual({ a: new Date(1637353595983) });
|
||||
});
|
||||
|
||||
test("intersection of object with refine with date", async () => {
|
||||
const schema = z
|
||||
.object({
|
||||
a: z.date(),
|
||||
})
|
||||
.refine(() => true);
|
||||
expect(schema.and(schema).parse({ a: new Date(1637353595983) })).toEqual({
|
||||
a: new Date(1637353595983),
|
||||
});
|
||||
const result = await schema.parseAsync({ a: new Date(1637353595983) });
|
||||
expect(result).toEqual({ a: new Date(1637353595983) });
|
||||
});
|
||||
|
||||
test("constructor key", () => {
|
||||
const person = z
|
||||
.object({
|
||||
name: z.string(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
expect(() =>
|
||||
person.parse({
|
||||
name: "bob dylan",
|
||||
constructor: 61,
|
||||
})
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
test("constructor key", () => {
|
||||
const Example = z.object({
|
||||
prop: z.string(),
|
||||
opt: z.number().optional(),
|
||||
arr: z.string().array(),
|
||||
});
|
||||
|
||||
type Example = z.infer<typeof Example>;
|
||||
util.assertEqual<keyof Example, "prop" | "opt" | "arr">(true);
|
||||
});
|
||||
|
||||
test("unknownkeys merging", () => {
|
||||
// This one is "strict"
|
||||
const schemaA = z
|
||||
.object({
|
||||
a: z.string(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
// This one is "strip"
|
||||
const schemaB = z
|
||||
.object({
|
||||
b: z.string(),
|
||||
})
|
||||
.catchall(z.string());
|
||||
|
||||
const mergedSchema = schemaA.merge(schemaB);
|
||||
type mergedSchema = typeof mergedSchema;
|
||||
util.assertEqual<mergedSchema["_def"]["unknownKeys"], "strip">(true);
|
||||
expect(mergedSchema._def.unknownKeys).toEqual("strip");
|
||||
|
||||
util.assertEqual<mergedSchema["_def"]["catchall"], z.ZodString>(true);
|
||||
expect(mergedSchema._def.catchall instanceof z.ZodString).toEqual(true);
|
||||
});
|
||||
|
||||
const personToExtend = z.object({
|
||||
firstName: z.string(),
|
||||
lastName: z.string(),
|
||||
});
|
||||
|
||||
test("extend() should return schema with new key", () => {
|
||||
const PersonWithNickname = personToExtend.extend({ nickName: z.string() });
|
||||
type PersonWithNickname = z.infer<typeof PersonWithNickname>;
|
||||
|
||||
const expected = { firstName: "f", nickName: "n", lastName: "l" };
|
||||
const actual = PersonWithNickname.parse(expected);
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
util.assertEqual<keyof PersonWithNickname, "firstName" | "lastName" | "nickName">(true);
|
||||
util.assertEqual<PersonWithNickname, { firstName: string; lastName: string; nickName: string }>(true);
|
||||
});
|
||||
|
||||
test("extend() should have power to override existing key", () => {
|
||||
const PersonWithNumberAsLastName = personToExtend.extend({
|
||||
lastName: z.number(),
|
||||
});
|
||||
type PersonWithNumberAsLastName = z.infer<typeof PersonWithNumberAsLastName>;
|
||||
|
||||
const expected = { firstName: "f", lastName: 42 };
|
||||
const actual = PersonWithNumberAsLastName.parse(expected);
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
util.assertEqual<PersonWithNumberAsLastName, { firstName: string; lastName: number }>(true);
|
||||
});
|
||||
|
||||
test("passthrough index signature", () => {
|
||||
const a = z.object({ a: z.string() });
|
||||
type a = z.infer<typeof a>;
|
||||
util.assertEqual<{ a: string }, a>(true);
|
||||
const b = a.passthrough();
|
||||
type b = z.infer<typeof b>;
|
||||
util.assertEqual<{ a: string } & { [k: string]: unknown }, b>(true);
|
||||
});
|
||||
|
||||
test("xor", () => {
|
||||
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
|
||||
type XOR<T, U> = T extends object ? (U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : U) : T;
|
||||
|
||||
type A = { name: string; a: number };
|
||||
type B = { name: string; b: number };
|
||||
type C = XOR<A, B>;
|
||||
type Outer = { data: C };
|
||||
|
||||
const _Outer: z.ZodType<Outer> = z.object({
|
||||
data: z.union([z.object({ name: z.string(), a: z.number() }), z.object({ name: z.string(), b: z.number() })]),
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,835 @@
|
||||
// Code generated by _scripts/generate-encoder.ts. DO NOT EDIT.
|
||||
import { getTokenPosOfNode, ModifierFlags, SyntaxKind, } from "../../ast/index.js";
|
||||
import { modifierToFlag, NODE_CHILD_MASK, NODE_DATA_TYPE_MASK, NODE_EXTENDED_DATA_MASK, NODE_STRING_INDEX_MASK, popcount8, RemoteNodeBase, } from "./node.infrastructure.js";
|
||||
import { childProperties, KIND_NODE_LIST, NODE_DATA_TYPE_CHILDREN, NODE_DATA_TYPE_EXTENDED, NODE_DATA_TYPE_STRING, NODE_LEN, NODE_OFFSET_DATA, NODE_OFFSET_END, NODE_OFFSET_FLAGS, NODE_OFFSET_KIND, NODE_OFFSET_NEXT, NODE_OFFSET_PARENT, NODE_OFFSET_POS, } from "./protocol.js";
|
||||
export class RemoteNodeList extends Array {
|
||||
// Inherited Array methods like filter/map/slice use ArraySpeciesCreate, which would
|
||||
// otherwise call `new RemoteNodeList(length)` and fail. Produce a plain Array instead.
|
||||
static get [Symbol.species]() {
|
||||
return Array;
|
||||
}
|
||||
parent;
|
||||
hasTrailingComma;
|
||||
transformFlags = 0;
|
||||
view;
|
||||
index;
|
||||
_byteIndex;
|
||||
// Cursor memoizing the last resolved (logical index -> node index) so that
|
||||
// sequential forward access (index loops and list[i], plus forEach/map/
|
||||
// reduce/filter) resumes instead of re-walking from the head, turning an
|
||||
// O(n) pass over the whole list from O(n^2) into O(n).
|
||||
_cursorIndex = 0;
|
||||
_cursorNodeIndex = 0;
|
||||
get pos() {
|
||||
return this.view.getUint32(this._byteIndex + NODE_OFFSET_POS, true);
|
||||
}
|
||||
get end() {
|
||||
return this.view.getUint32(this._byteIndex + NODE_OFFSET_END, true);
|
||||
}
|
||||
get next() {
|
||||
return this.view.getUint32(this._byteIndex + NODE_OFFSET_NEXT, true);
|
||||
}
|
||||
get data() {
|
||||
return this.view.getUint32(this._byteIndex + NODE_OFFSET_DATA, true);
|
||||
}
|
||||
sourceFile;
|
||||
constructor(view, index, parent, sourceFile, offsetNodes) {
|
||||
super();
|
||||
this.view = view;
|
||||
this.index = index;
|
||||
this.parent = parent;
|
||||
this.sourceFile = sourceFile;
|
||||
this._byteIndex = offsetNodes + index * NODE_LEN;
|
||||
this.length = this.data;
|
||||
this._cursorNodeIndex = index + 1;
|
||||
const length = this.length;
|
||||
for (let i = 16; i < length; i++) {
|
||||
Object.defineProperty(this, i, {
|
||||
get() {
|
||||
return this.at(i);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
get 0() {
|
||||
return this.at(0);
|
||||
}
|
||||
get 1() {
|
||||
return this.at(1);
|
||||
}
|
||||
get 2() {
|
||||
return this.at(2);
|
||||
}
|
||||
get 3() {
|
||||
return this.at(3);
|
||||
}
|
||||
get 4() {
|
||||
return this.at(4);
|
||||
}
|
||||
get 5() {
|
||||
return this.at(5);
|
||||
}
|
||||
get 6() {
|
||||
return this.at(6);
|
||||
}
|
||||
get 7() {
|
||||
return this.at(7);
|
||||
}
|
||||
get 8() {
|
||||
return this.at(8);
|
||||
}
|
||||
get 9() {
|
||||
return this.at(9);
|
||||
}
|
||||
get 10() {
|
||||
return this.at(10);
|
||||
}
|
||||
get 11() {
|
||||
return this.at(11);
|
||||
}
|
||||
get 12() {
|
||||
return this.at(12);
|
||||
}
|
||||
get 13() {
|
||||
return this.at(13);
|
||||
}
|
||||
get 14() {
|
||||
return this.at(14);
|
||||
}
|
||||
get 15() {
|
||||
return this.at(15);
|
||||
}
|
||||
*[Symbol.iterator]() {
|
||||
if (!this.length)
|
||||
return;
|
||||
let next = this.index + 1;
|
||||
while (next) {
|
||||
const child = this.getOrCreateChildAtNodeIndex(next);
|
||||
next = child.next;
|
||||
yield child;
|
||||
}
|
||||
}
|
||||
forEachNode(visitNode) {
|
||||
if (!this.length)
|
||||
return;
|
||||
let next = this.index + 1;
|
||||
while (next) {
|
||||
const child = this.getOrCreateChildAtNodeIndex(next);
|
||||
next = child.next;
|
||||
const result = visitNode(child);
|
||||
if (result)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
at(index) {
|
||||
if (!Number.isInteger(index)) {
|
||||
return undefined;
|
||||
}
|
||||
if (index >= this.data || (index < 0 && -index > this.data)) {
|
||||
return undefined;
|
||||
}
|
||||
if (index < 0) {
|
||||
index = this.length + index;
|
||||
}
|
||||
// Walk the raw buffer following each node's `next` pointer instead of
|
||||
// materializing every intermediate RemoteNode just to read it. Resume from
|
||||
// the memoized cursor when possible so sequential forward access is O(1)
|
||||
// amortized (a full in-order pass is O(n) rather than O(n^2)).
|
||||
const offsetNodes = this.sourceFile._offsetNodes;
|
||||
let i;
|
||||
let next;
|
||||
if (index >= this._cursorIndex) {
|
||||
i = this._cursorIndex;
|
||||
next = this._cursorNodeIndex;
|
||||
}
|
||||
else {
|
||||
i = 0;
|
||||
next = this.index + 1;
|
||||
}
|
||||
for (; i < index; i++) {
|
||||
next = this.view.getUint32(offsetNodes + next * NODE_LEN + NODE_OFFSET_NEXT, true);
|
||||
}
|
||||
this._cursorIndex = index;
|
||||
this._cursorNodeIndex = next;
|
||||
return this.getOrCreateChildAtNodeIndex(next);
|
||||
}
|
||||
getOrCreateChildAtNodeIndex(index) {
|
||||
let child = this.sourceFile.nodes[index];
|
||||
if (!child) {
|
||||
const kind = this.view.getUint32(this.sourceFile._offsetNodes + index * NODE_LEN + NODE_OFFSET_KIND, true);
|
||||
if (kind === KIND_NODE_LIST) {
|
||||
throw new Error("NodeList cannot directly contain another NodeList");
|
||||
}
|
||||
const sf = this.sourceFile;
|
||||
child = new RemoteNode(this.view, index, this.parent, sf, sf._offsetNodes);
|
||||
sf.nodes[index] = child;
|
||||
sf._timing?.recordMaterialization();
|
||||
}
|
||||
return child;
|
||||
}
|
||||
__print() {
|
||||
const result = [];
|
||||
result.push(`kind: NodeList`);
|
||||
result.push(`index: ${this.index}`);
|
||||
result.push(`byteIndex: ${this._byteIndex}`);
|
||||
result.push(`length: ${this.length}`);
|
||||
return result.join("\n");
|
||||
}
|
||||
}
|
||||
export class RemoteNode extends RemoteNodeBase {
|
||||
static NODE_LEN = NODE_LEN;
|
||||
get sourceFile() {
|
||||
return this._sourceFile;
|
||||
}
|
||||
_sourceFile;
|
||||
get id() {
|
||||
return `${this.index}.${this.kind}.${this.sourceFile.path}`;
|
||||
}
|
||||
constructor(view, index, parent, sourceFile, offsetNodes) {
|
||||
super(view, index, parent, offsetNodes + index * NODE_LEN);
|
||||
this._sourceFile = sourceFile;
|
||||
}
|
||||
forEachChild(visitNode, visitList) {
|
||||
if (this.hasChildren()) {
|
||||
let next = this.index + 1;
|
||||
do {
|
||||
const child = this.getOrCreateChildAtNodeIndex(next);
|
||||
if (child instanceof RemoteNodeList) {
|
||||
if (visitList) {
|
||||
const result = visitList(child);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else {
|
||||
const result = child.forEachNode(visitNode);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (child.kind !== SyntaxKind.JSDoc) {
|
||||
const result = visitNode(child);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
next = child.next;
|
||||
} while (next);
|
||||
}
|
||||
}
|
||||
get jsDoc() {
|
||||
if (!this.hasChildren()) {
|
||||
return undefined;
|
||||
}
|
||||
let result;
|
||||
let next = this.index + 1;
|
||||
do {
|
||||
const child = this.getOrCreateChildAtNodeIndex(next);
|
||||
if (!(child instanceof RemoteNodeList) && child.kind === SyntaxKind.JSDoc) {
|
||||
(result ??= []).push(child);
|
||||
}
|
||||
next = child.next;
|
||||
} while (next);
|
||||
return result;
|
||||
}
|
||||
getSourceFile() {
|
||||
return this.sourceFile;
|
||||
}
|
||||
getStart(sourceFile, includeJsDocComment) {
|
||||
return getTokenPosOfNode(this, sourceFile ?? this.getSourceFile(), includeJsDocComment);
|
||||
}
|
||||
getFullStart() {
|
||||
return this.pos;
|
||||
}
|
||||
getEnd() {
|
||||
return this.end;
|
||||
}
|
||||
getWidth(sourceFile) {
|
||||
return this.getEnd() - this.getStart(sourceFile);
|
||||
}
|
||||
getFullWidth() {
|
||||
return this.end - this.pos;
|
||||
}
|
||||
getLeadingTriviaWidth(sourceFile) {
|
||||
return this.getStart(sourceFile) - this.pos;
|
||||
}
|
||||
getFullText(sourceFile) {
|
||||
return (sourceFile ?? this.getSourceFile()).text.substring(this.pos, this.end);
|
||||
}
|
||||
getText(sourceFile) {
|
||||
sourceFile ??= this.getSourceFile();
|
||||
return sourceFile.text.substring(this.getStart(sourceFile), this.end);
|
||||
}
|
||||
getString(index) {
|
||||
const offsetStringTableOffsets = this.sourceFile._offsetStringTableOffsets;
|
||||
const start = this.view.getUint32(offsetStringTableOffsets + index * 4, true);
|
||||
const end = this.view.getUint32(offsetStringTableOffsets + (index + 1) * 4, true);
|
||||
const offsetStringTable = this.sourceFile._offsetStringTable;
|
||||
const text = new Uint8Array(this.view.buffer, this.view.byteOffset + offsetStringTable + start, end - start);
|
||||
return this.sourceFile._decoder.decode(text);
|
||||
}
|
||||
getOrCreateChildAtNodeIndex(index) {
|
||||
let child = this.sourceFile.nodes[index];
|
||||
if (!child) {
|
||||
const sf = this.sourceFile;
|
||||
const offsetNodes = sf._offsetNodes;
|
||||
const kind = this.view.getUint32(offsetNodes + index * NODE_LEN + NODE_OFFSET_KIND, true);
|
||||
child = kind === KIND_NODE_LIST
|
||||
? new RemoteNodeList(this.view, index, this, sf, offsetNodes)
|
||||
: new RemoteNode(this.view, index, this, sf, offsetNodes);
|
||||
sf.nodes[index] = child;
|
||||
sf._timing?.recordMaterialization();
|
||||
}
|
||||
return child;
|
||||
}
|
||||
hasChildren() {
|
||||
if (this._byteIndex >= this.view.byteLength - NODE_LEN) {
|
||||
return false;
|
||||
}
|
||||
const nextNodeParent = this.view.getUint32(this.sourceFile._offsetNodes + (this.index + 1) * NODE_LEN + NODE_OFFSET_PARENT, true);
|
||||
return nextNodeParent === this.index;
|
||||
}
|
||||
getNamedChild(propertyName) {
|
||||
const kind = this.kind;
|
||||
const propertyNames = childProperties[kind];
|
||||
if (!propertyNames) {
|
||||
return undefined;
|
||||
}
|
||||
const order = propertyNames.indexOf(propertyName);
|
||||
if (order === -1) {
|
||||
return undefined;
|
||||
}
|
||||
return this.getChildAtOrder(order);
|
||||
}
|
||||
getChildAtOrder(order) {
|
||||
const mask = this.childMask;
|
||||
if (!(mask & (1 << order))) {
|
||||
// Property is not present
|
||||
return undefined;
|
||||
}
|
||||
// The property index is `order`, minus the number of zeros in the mask that are in bit positions less
|
||||
// than the `order`th bit. Example:
|
||||
//
|
||||
// This is a MethodDeclaration with mask 0b01110101. The possible properties are
|
||||
// ["modifiers", "asteriskToken", "name", "postfixToken", "typeParameters", "parameters", "type", "body"]
|
||||
// (it has modifiers, name, typeParameters, parameters, and type).
|
||||
//
|
||||
// | Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|
||||
// | ----- | ---- | ---- | ---------- | -------------- | ------------ | ---- | ------------- | --------- |
|
||||
// | Value | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 |
|
||||
// | Name | body | type | parameters | typeParameters | postfixToken | name | asteriskToken | modifiers |
|
||||
//
|
||||
// We are trying to get the index of "parameters" (bit = 5).
|
||||
// First, set all the more significant bits to 1:
|
||||
//
|
||||
// | Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|
||||
// | ----- | ---- | ---- | ---------- | -------------- | ------------ | ---- | ------------- | --------- |
|
||||
// | Value | 1 | 1 | 1 | 1 | 0 | 1 | 0 | 1 |
|
||||
//
|
||||
// Then, flip the bits:
|
||||
//
|
||||
// | Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|
||||
// | ----- | ---- | ---- | ---------- | -------------- | ------------ | ---- | ------------- | --------- |
|
||||
// | Value | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 |
|
||||
//
|
||||
// Counting the 1s gives us the number of *missing properties* before the `order`th property. If every property
|
||||
// were present, we would have `parameters = children[5]`, but since `postfixToken` and `astersiskToken` are
|
||||
// missing, we have `parameters = children[5 - 2]`.
|
||||
const propertyIndex = order - popcount8[~(mask | ((0xff << order) & 0xff)) & 0xff];
|
||||
let childIndex = this.index + 1;
|
||||
for (let i = 0; i < propertyIndex; i++) {
|
||||
// Walk through children via their `next` pointer until we get to the right property index
|
||||
childIndex = this.view.getUint32(this.sourceFile._offsetNodes + childIndex * NODE_LEN + NODE_OFFSET_NEXT, true);
|
||||
}
|
||||
return this.getOrCreateChildAtNodeIndex(childIndex);
|
||||
}
|
||||
__print() {
|
||||
const result = [];
|
||||
result.push(`index: ${this.index}`);
|
||||
result.push(`byteIndex: ${this._byteIndex}`);
|
||||
result.push(`kind: ${SyntaxKind[this.kind]}`);
|
||||
result.push(`pos: ${this.pos}`);
|
||||
result.push(`end: ${this.end}`);
|
||||
result.push(`next: ${this.next}`);
|
||||
result.push(`parent: ${this.parentIndex}`);
|
||||
result.push(`data: ${this.data.toString(2).padStart(32, "0")}`);
|
||||
const dataType = this.dataType === NODE_DATA_TYPE_CHILDREN ? "children" :
|
||||
this.dataType === NODE_DATA_TYPE_STRING ? "string" :
|
||||
"extended";
|
||||
result.push(`dataType: ${dataType}`);
|
||||
if (this.dataType === NODE_DATA_TYPE_CHILDREN) {
|
||||
result.push(`childMask: ${this.childMask.toString(2).padStart(8, "0")}`);
|
||||
result.push(`childProperties: ${childProperties[this.kind]?.join(", ")}`);
|
||||
}
|
||||
return result.join("\n");
|
||||
}
|
||||
__printChildren() {
|
||||
const result = [];
|
||||
let next = this.index + 1;
|
||||
while (next) {
|
||||
const child = this.getOrCreateChildAtNodeIndex(next);
|
||||
next = child.next;
|
||||
result.push(child.__print());
|
||||
}
|
||||
return result.join("\n\n");
|
||||
}
|
||||
__printSubtree() {
|
||||
const result = [this.__print()];
|
||||
this.forEachChild(function visitNode(node) {
|
||||
result.push(node.__print());
|
||||
node.forEachChild(visitNode);
|
||||
}, visitList => {
|
||||
result.push(visitList.__print());
|
||||
});
|
||||
return result.join("\n\n");
|
||||
}
|
||||
// ═══ Generated boolean property getters ═══
|
||||
get containsOnlyTriviaWhiteSpaces() {
|
||||
return (this.data & (1 << 24)) !== 0;
|
||||
}
|
||||
get isArrayType() {
|
||||
return (this.data & (1 << 24)) !== 0;
|
||||
}
|
||||
get isBracketed() {
|
||||
return (this.data & (1 << 24)) !== 0;
|
||||
}
|
||||
get isExportEquals() {
|
||||
return (this.data & (1 << 24)) !== 0;
|
||||
}
|
||||
get isNameFirst() {
|
||||
return (this.data & (1 << 25)) !== 0;
|
||||
}
|
||||
get isTypeOf() {
|
||||
return (this.data & (1 << 24)) !== 0;
|
||||
}
|
||||
get isTypeOnly() {
|
||||
return (this.data & (1 << 24)) !== 0;
|
||||
}
|
||||
get multiLine() {
|
||||
return (this.data & (1 << 24)) !== 0;
|
||||
}
|
||||
// ═══ Generated SyntaxKind union property getters ═══
|
||||
get keyword() {
|
||||
switch (this.kind) {
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
return (this.data >> 24) & 0x1 ? SyntaxKind.NamespaceKeyword : SyntaxKind.ModuleKeyword;
|
||||
}
|
||||
}
|
||||
get keywordToken() {
|
||||
switch (this.kind) {
|
||||
case SyntaxKind.MetaProperty:
|
||||
return (this.data >> 24) & 0x1 ? SyntaxKind.NewKeyword : SyntaxKind.ImportKeyword;
|
||||
}
|
||||
}
|
||||
get operator() {
|
||||
switch (this.kind) {
|
||||
case SyntaxKind.PrefixUnaryExpression: {
|
||||
const idx = (this.data >> 24) & 0x7;
|
||||
if (idx === 1)
|
||||
return SyntaxKind.MinusToken;
|
||||
if (idx === 2)
|
||||
return SyntaxKind.TildeToken;
|
||||
if (idx === 3)
|
||||
return SyntaxKind.ExclamationToken;
|
||||
if (idx === 4)
|
||||
return SyntaxKind.PlusPlusToken;
|
||||
if (idx === 5)
|
||||
return SyntaxKind.MinusMinusToken;
|
||||
return SyntaxKind.PlusToken;
|
||||
}
|
||||
case SyntaxKind.PostfixUnaryExpression:
|
||||
return (this.data >> 24) & 0x1 ? SyntaxKind.MinusMinusToken : SyntaxKind.PlusPlusToken;
|
||||
case SyntaxKind.TypeOperator: {
|
||||
const idx = (this.data >> 24) & 0x3;
|
||||
if (idx === 1)
|
||||
return SyntaxKind.ReadonlyKeyword;
|
||||
if (idx === 2)
|
||||
return SyntaxKind.UniqueKeyword;
|
||||
return SyntaxKind.KeyOfKeyword;
|
||||
}
|
||||
}
|
||||
}
|
||||
get phaseModifier() {
|
||||
switch (this.kind) {
|
||||
case SyntaxKind.ImportClause: {
|
||||
const idx = (this.data >> 24) & 0x3;
|
||||
if (idx === 0)
|
||||
return undefined;
|
||||
return idx === 1 ? SyntaxKind.TypeKeyword : idx === 2 ? SyntaxKind.DeferKeyword : undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
get token() {
|
||||
switch (this.kind) {
|
||||
case SyntaxKind.HeritageClause:
|
||||
return (this.data >> 24) & 0x1 ? SyntaxKind.ImplementsKeyword : SyntaxKind.ExtendsKeyword;
|
||||
case SyntaxKind.ImportAttributes:
|
||||
return (this.data >> 25) & 0x1 ? SyntaxKind.AssertKeyword : SyntaxKind.WithKeyword;
|
||||
}
|
||||
}
|
||||
get templateFlags() {
|
||||
switch (this.kind) {
|
||||
case SyntaxKind.TemplateHead:
|
||||
case SyntaxKind.TemplateMiddle:
|
||||
case SyntaxKind.TemplateTail:
|
||||
const extendedDataOffset = this.sourceFile._offsetExtendedData + (this.data & NODE_EXTENDED_DATA_MASK);
|
||||
return this.view.getUint32(extendedDataOffset + 8, true);
|
||||
}
|
||||
}
|
||||
get tokenFlags() {
|
||||
switch (this.kind) {
|
||||
case SyntaxKind.StringLiteral:
|
||||
case SyntaxKind.NumericLiteral:
|
||||
case SyntaxKind.BigIntLiteral:
|
||||
case SyntaxKind.RegularExpressionLiteral:
|
||||
const extendedDataOffset = this.sourceFile._offsetExtendedData + (this.data & NODE_EXTENDED_DATA_MASK);
|
||||
return this.view.getUint32(extendedDataOffset + 4, true);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// ═══ Generated child property getters ═══
|
||||
get argument() {
|
||||
return this.getNamedChild("argument");
|
||||
}
|
||||
get argumentExpression() {
|
||||
return this.getNamedChild("argumentExpression");
|
||||
}
|
||||
get arguments() {
|
||||
return this.getNamedChild("arguments");
|
||||
}
|
||||
get assertsModifier() {
|
||||
return this.getNamedChild("assertsModifier");
|
||||
}
|
||||
get asteriskToken() {
|
||||
return this.getNamedChild("asteriskToken");
|
||||
}
|
||||
get attributes() {
|
||||
return this.getNamedChild("attributes");
|
||||
}
|
||||
get awaitModifier() {
|
||||
return this.getNamedChild("awaitModifier");
|
||||
}
|
||||
get block() {
|
||||
return this.getNamedChild("block");
|
||||
}
|
||||
get body() {
|
||||
return this.getNamedChild("body");
|
||||
}
|
||||
get caseBlock() {
|
||||
return this.getNamedChild("caseBlock");
|
||||
}
|
||||
get catchClause() {
|
||||
return this.getNamedChild("catchClause");
|
||||
}
|
||||
get checkType() {
|
||||
return this.getNamedChild("checkType");
|
||||
}
|
||||
get children() {
|
||||
return this.getNamedChild("children");
|
||||
}
|
||||
get className() {
|
||||
return this.getNamedChild("className");
|
||||
}
|
||||
get clauses() {
|
||||
return this.getNamedChild("clauses");
|
||||
}
|
||||
get closingElement() {
|
||||
return this.getNamedChild("closingElement");
|
||||
}
|
||||
get closingFragment() {
|
||||
return this.getNamedChild("closingFragment");
|
||||
}
|
||||
get colonToken() {
|
||||
return this.getNamedChild("colonToken");
|
||||
}
|
||||
get comment() {
|
||||
return this.getNamedChild("comment");
|
||||
}
|
||||
get condition() {
|
||||
return this.getNamedChild("condition");
|
||||
}
|
||||
get constraint() {
|
||||
return this.getNamedChild("constraint");
|
||||
}
|
||||
get declarationList() {
|
||||
return this.getNamedChild("declarationList");
|
||||
}
|
||||
get declarations() {
|
||||
return this.getNamedChild("declarations");
|
||||
}
|
||||
get defaultType() {
|
||||
return this.getNamedChild("defaultType");
|
||||
}
|
||||
get dotDotDotToken() {
|
||||
return this.getNamedChild("dotDotDotToken");
|
||||
}
|
||||
get elements() {
|
||||
return this.getNamedChild("elements");
|
||||
}
|
||||
get elementType() {
|
||||
return this.getNamedChild("elementType");
|
||||
}
|
||||
get elseStatement() {
|
||||
return this.getNamedChild("elseStatement");
|
||||
}
|
||||
get endOfFileToken() {
|
||||
return this.getNamedChild("endOfFileToken");
|
||||
}
|
||||
get equalsGreaterThanToken() {
|
||||
return this.getNamedChild("equalsGreaterThanToken");
|
||||
}
|
||||
get equalsToken() {
|
||||
return this.getNamedChild("equalsToken");
|
||||
}
|
||||
get exclamationToken() {
|
||||
return this.getNamedChild("exclamationToken");
|
||||
}
|
||||
get exportClause() {
|
||||
return this.getNamedChild("exportClause");
|
||||
}
|
||||
get expression() {
|
||||
return this.getNamedChild("expression");
|
||||
}
|
||||
get exprName() {
|
||||
return this.getNamedChild("exprName");
|
||||
}
|
||||
get extendsType() {
|
||||
return this.getNamedChild("extendsType");
|
||||
}
|
||||
get falseType() {
|
||||
return this.getNamedChild("falseType");
|
||||
}
|
||||
get finallyBlock() {
|
||||
return this.getNamedChild("finallyBlock");
|
||||
}
|
||||
get head() {
|
||||
return this.getNamedChild("head");
|
||||
}
|
||||
get heritageClauses() {
|
||||
return this.getNamedChild("heritageClauses");
|
||||
}
|
||||
get importClause() {
|
||||
return this.getNamedChild("importClause");
|
||||
}
|
||||
get incrementor() {
|
||||
return this.getNamedChild("incrementor");
|
||||
}
|
||||
get indexType() {
|
||||
return this.getNamedChild("indexType");
|
||||
}
|
||||
get initializer() {
|
||||
return this.getNamedChild("initializer");
|
||||
}
|
||||
get jsdocPropertyTags() {
|
||||
return this.getNamedChild("jsdocPropertyTags");
|
||||
}
|
||||
get label() {
|
||||
return this.getNamedChild("label");
|
||||
}
|
||||
get left() {
|
||||
return this.getNamedChild("left");
|
||||
}
|
||||
get literal() {
|
||||
return this.getNamedChild("literal");
|
||||
}
|
||||
get members() {
|
||||
return this.getNamedChild("members");
|
||||
}
|
||||
get modifiers() {
|
||||
return this.getNamedChild("modifiers");
|
||||
}
|
||||
get moduleReference() {
|
||||
return this.getNamedChild("moduleReference");
|
||||
}
|
||||
get moduleSpecifier() {
|
||||
return this.getNamedChild("moduleSpecifier");
|
||||
}
|
||||
get name() {
|
||||
return this.getNamedChild("name");
|
||||
}
|
||||
get namedBindings() {
|
||||
return this.getNamedChild("namedBindings");
|
||||
}
|
||||
get nameExpression() {
|
||||
return this.getNamedChild("nameExpression");
|
||||
}
|
||||
get namespace() {
|
||||
return this.getNamedChild("namespace");
|
||||
}
|
||||
get nameType() {
|
||||
return this.getNamedChild("nameType");
|
||||
}
|
||||
get objectAssignmentInitializer() {
|
||||
return this.getNamedChild("objectAssignmentInitializer");
|
||||
}
|
||||
get objectType() {
|
||||
return this.getNamedChild("objectType");
|
||||
}
|
||||
get openingElement() {
|
||||
return this.getNamedChild("openingElement");
|
||||
}
|
||||
get openingFragment() {
|
||||
return this.getNamedChild("openingFragment");
|
||||
}
|
||||
get operand() {
|
||||
return this.getNamedChild("operand");
|
||||
}
|
||||
get operatorToken() {
|
||||
return this.getNamedChild("operatorToken");
|
||||
}
|
||||
get parameterName() {
|
||||
return this.getNamedChild("parameterName");
|
||||
}
|
||||
get parameters() {
|
||||
return this.getNamedChild("parameters");
|
||||
}
|
||||
get postfixToken() {
|
||||
return this.getNamedChild("postfixToken");
|
||||
}
|
||||
get properties() {
|
||||
return this.getNamedChild("properties");
|
||||
}
|
||||
get propertyName() {
|
||||
return this.getNamedChild("propertyName");
|
||||
}
|
||||
get qualifier() {
|
||||
return this.getNamedChild("qualifier");
|
||||
}
|
||||
get questionDotToken() {
|
||||
return this.getNamedChild("questionDotToken");
|
||||
}
|
||||
get questionToken() {
|
||||
return this.getNamedChild("questionToken");
|
||||
}
|
||||
get readonlyToken() {
|
||||
return this.getNamedChild("readonlyToken");
|
||||
}
|
||||
get right() {
|
||||
return this.getNamedChild("right");
|
||||
}
|
||||
get statement() {
|
||||
return this.getNamedChild("statement");
|
||||
}
|
||||
get statements() {
|
||||
return this.getNamedChild("statements");
|
||||
}
|
||||
get tag() {
|
||||
return this.getNamedChild("tag");
|
||||
}
|
||||
get tagName() {
|
||||
return this.getNamedChild("tagName");
|
||||
}
|
||||
get tags() {
|
||||
return this.getNamedChild("tags");
|
||||
}
|
||||
get template() {
|
||||
return this.getNamedChild("template");
|
||||
}
|
||||
get templateSpans() {
|
||||
return this.getNamedChild("templateSpans");
|
||||
}
|
||||
get thenStatement() {
|
||||
return this.getNamedChild("thenStatement");
|
||||
}
|
||||
get thisArg() {
|
||||
return this.getNamedChild("thisArg");
|
||||
}
|
||||
get trueType() {
|
||||
return this.getNamedChild("trueType");
|
||||
}
|
||||
get tryBlock() {
|
||||
return this.getNamedChild("tryBlock");
|
||||
}
|
||||
get tupleNameSource() {
|
||||
return this.getNamedChild("tupleNameSource");
|
||||
}
|
||||
get type() {
|
||||
return this.getNamedChild("type");
|
||||
}
|
||||
get typeArguments() {
|
||||
return this.getNamedChild("typeArguments");
|
||||
}
|
||||
get typeExpression() {
|
||||
return this.getNamedChild("typeExpression");
|
||||
}
|
||||
get typeName() {
|
||||
return this.getNamedChild("typeName");
|
||||
}
|
||||
get typeParameter() {
|
||||
return this.getNamedChild("typeParameter");
|
||||
}
|
||||
get typeParameters() {
|
||||
return this.getNamedChild("typeParameters");
|
||||
}
|
||||
get types() {
|
||||
return this.getNamedChild("types");
|
||||
}
|
||||
get value() {
|
||||
return this.getNamedChild("value");
|
||||
}
|
||||
get variableDeclaration() {
|
||||
return this.getNamedChild("variableDeclaration");
|
||||
}
|
||||
get whenFalse() {
|
||||
return this.getNamedChild("whenFalse");
|
||||
}
|
||||
get whenTrue() {
|
||||
return this.getNamedChild("whenTrue");
|
||||
}
|
||||
// ═══ Generated string property getters ═══
|
||||
get text() {
|
||||
switch (this.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
case SyntaxKind.PrivateIdentifier:
|
||||
case SyntaxKind.JsxText:
|
||||
case SyntaxKind.JSDocText:
|
||||
case SyntaxKind.JSDocLink:
|
||||
case SyntaxKind.JSDocLinkPlain:
|
||||
case SyntaxKind.JSDocLinkCode: {
|
||||
const stringIndex = this.data & NODE_STRING_INDEX_MASK;
|
||||
return this.getString(stringIndex);
|
||||
}
|
||||
case SyntaxKind.StringLiteral:
|
||||
case SyntaxKind.NumericLiteral:
|
||||
case SyntaxKind.BigIntLiteral:
|
||||
case SyntaxKind.RegularExpressionLiteral:
|
||||
case SyntaxKind.NoSubstitutionTemplateLiteral:
|
||||
case SyntaxKind.TemplateHead:
|
||||
case SyntaxKind.TemplateMiddle:
|
||||
case SyntaxKind.TemplateTail:
|
||||
case SyntaxKind.SourceFile: {
|
||||
const extendedDataOffset = this.sourceFile._offsetExtendedData + (this.data & NODE_EXTENDED_DATA_MASK);
|
||||
const stringIndex = this.view.getUint32(extendedDataOffset, true);
|
||||
return this.getString(stringIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
get rawText() {
|
||||
switch (this.kind) {
|
||||
case SyntaxKind.TemplateHead:
|
||||
case SyntaxKind.TemplateMiddle:
|
||||
case SyntaxKind.TemplateTail:
|
||||
const extendedDataOffset = this.sourceFile._offsetExtendedData + (this.data & NODE_EXTENDED_DATA_MASK);
|
||||
const stringIndex = this.view.getUint32(extendedDataOffset + 4, true);
|
||||
return this.getString(stringIndex);
|
||||
}
|
||||
}
|
||||
// ═══ Generated extended data property getters ═══
|
||||
// ═══ Other property getters ═══
|
||||
get flags() {
|
||||
return this.view.getUint32(this._byteIndex + NODE_OFFSET_FLAGS, true);
|
||||
}
|
||||
get modifierFlags() {
|
||||
const mods = this.modifiers;
|
||||
if (!mods)
|
||||
return ModifierFlags.None;
|
||||
let flags = ModifierFlags.None;
|
||||
for (const mod of mods) {
|
||||
flags |= modifierToFlag(mod.kind);
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=node.generated.js.map
|
||||
@@ -0,0 +1,4 @@
|
||||
interface ImportMeta {
|
||||
url: string
|
||||
readonly vitest?: typeof import('vitest')
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import type * as errors from "../core/errors.js";
|
||||
/** @deprecated Use `uk` instead. */
|
||||
export default function (): {
|
||||
localeError: errors.$ZodErrorMap;
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
function _tagged_template_literal(strings, raw) {
|
||||
if (!raw) raw = strings.slice(0);
|
||||
|
||||
return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } }));
|
||||
}
|
||||
exports._ = _tagged_template_literal;
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { TSESTree } from '@typescript-eslint/utils';
|
||||
import type { RuleContext } from '@typescript-eslint/utils/ts-eslint';
|
||||
/**
|
||||
* @return `true` if the function or method node has overload signatures.
|
||||
*/
|
||||
export declare function hasOverloadSignatures(node: TSESTree.FunctionDeclaration | TSESTree.MethodDefinition, context: RuleContext<string, unknown[]>): boolean;
|
||||
@@ -0,0 +1 @@
|
||||
"use strict";var r=require("./get-pipe-path-D4YM6rQt.cjs"),e=require("./esm/index.cjs");require("module"),require("node:path"),require("./temporary-directory-B83uKxJF.cjs"),require("node:os"),require("node:worker_threads"),require("./node-features-CEjg7cMX.cjs"),require("./register-Ciecs-Zx.cjs"),require("node:crypto"),require("node:module"),require("./register-C557imBs.cjs"),require("node:url"),require("node:fs"),require("fs"),require("os"),require("path"),require("./index-6kqi0x0U.cjs"),require("esbuild"),require("./client-D3mGB526.cjs"),require("node:net"),require("node:util"),require("./index-BWFBUo6r.cjs"),require("node:fs/promises"),require("./require-DDxgG93A.cjs"),r.require("./cjs/index.cjs"),exports.globalPreload=e.globalPreload,exports.initialize=e.initialize,exports.load=e.load,exports.resolve=e.resolve;
|
||||
@@ -0,0 +1,55 @@
|
||||
import { TestError, ParsedStack } from './types.js';
|
||||
|
||||
type OriginalMapping = {
|
||||
source: string | null;
|
||||
line: number;
|
||||
column: number;
|
||||
name: string | null;
|
||||
};
|
||||
|
||||
interface StackTraceParserOptions {
|
||||
ignoreStackEntries?: (RegExp | string)[];
|
||||
getSourceMap?: (file: string) => unknown;
|
||||
getUrlId?: (id: string) => string;
|
||||
frameFilter?: (error: TestError, frame: ParsedStack) => boolean | void;
|
||||
}
|
||||
declare const stackIgnorePatterns: (string | RegExp)[];
|
||||
|
||||
declare function parseSingleFFOrSafariStack(raw: string): ParsedStack | null;
|
||||
declare function parseSingleStack(raw: string): ParsedStack | null;
|
||||
declare function parseSingleV8Stack(raw: string): ParsedStack | null;
|
||||
declare function createStackString(stacks: ParsedStack[]): string;
|
||||
declare function parseStacktrace(stack: string, options?: StackTraceParserOptions): ParsedStack[];
|
||||
declare function parseErrorStacktrace(e: TestError | Error, options?: StackTraceParserOptions): ParsedStack[];
|
||||
interface SourceMapLike {
|
||||
version: number;
|
||||
mappings?: string;
|
||||
names?: string[];
|
||||
sources?: string[];
|
||||
sourcesContent?: string[];
|
||||
sourceRoot?: string;
|
||||
}
|
||||
interface Needle {
|
||||
line: number;
|
||||
column: number;
|
||||
}
|
||||
declare class DecodedMap {
|
||||
map: SourceMapLike;
|
||||
_encoded: string;
|
||||
_decoded: undefined | number[][][];
|
||||
_decodedMemo: Stats;
|
||||
url: string;
|
||||
version: number;
|
||||
names: string[];
|
||||
resolvedSources: string[];
|
||||
constructor(map: SourceMapLike, from: string);
|
||||
}
|
||||
interface Stats {
|
||||
lastKey: number;
|
||||
lastNeedle: number;
|
||||
lastIndex: number;
|
||||
}
|
||||
declare function getOriginalPosition(map: DecodedMap, needle: Needle): OriginalMapping | null;
|
||||
|
||||
export { DecodedMap, createStackString, stackIgnorePatterns as defaultStackIgnorePatterns, getOriginalPosition, parseErrorStacktrace, parseSingleFFOrSafariStack, parseSingleStack, parseSingleV8Stack, parseStacktrace };
|
||||
export type { StackTraceParserOptions };
|
||||
@@ -0,0 +1,81 @@
|
||||
"use strict";
|
||||
// THIS CODE WAS AUTOMATICALLY GENERATED
|
||||
// DO NOT EDIT THIS CODE BY HAND
|
||||
// SEE https://typescript-eslint.io/users/configs
|
||||
//
|
||||
// For developers working in the typescript-eslint monorepo:
|
||||
// You can regenerate it using `pnpm run generate-configs`
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/**
|
||||
* A utility ruleset that will disable type-aware linting and all type-aware rules available in our project.
|
||||
* @see {@link https://typescript-eslint.io/users/configs#disable-type-checked}
|
||||
*/
|
||||
exports.default = (_plugin, _parser) => ({
|
||||
name: 'typescript-eslint/disable-type-checked',
|
||||
rules: {
|
||||
'@typescript-eslint/await-thenable': 'off',
|
||||
'@typescript-eslint/consistent-return': 'off',
|
||||
'@typescript-eslint/consistent-type-exports': 'off',
|
||||
'@typescript-eslint/dot-notation': 'off',
|
||||
'@typescript-eslint/naming-convention': 'off',
|
||||
'@typescript-eslint/no-array-delete': 'off',
|
||||
'@typescript-eslint/no-base-to-string': 'off',
|
||||
'@typescript-eslint/no-confusing-void-expression': 'off',
|
||||
'@typescript-eslint/no-deprecated': 'off',
|
||||
'@typescript-eslint/no-duplicate-type-constituents': 'off',
|
||||
'@typescript-eslint/no-floating-promises': 'off',
|
||||
'@typescript-eslint/no-for-in-array': 'off',
|
||||
'@typescript-eslint/no-implied-eval': 'off',
|
||||
'@typescript-eslint/no-meaningless-void-operator': 'off',
|
||||
'@typescript-eslint/no-misused-promises': 'off',
|
||||
'@typescript-eslint/no-misused-spread': 'off',
|
||||
'@typescript-eslint/no-mixed-enums': 'off',
|
||||
'@typescript-eslint/no-redundant-type-constituents': 'off',
|
||||
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'off',
|
||||
'@typescript-eslint/no-unnecessary-condition': 'off',
|
||||
'@typescript-eslint/no-unnecessary-qualifier': 'off',
|
||||
'@typescript-eslint/no-unnecessary-template-expression': 'off',
|
||||
'@typescript-eslint/no-unnecessary-type-arguments': 'off',
|
||||
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
|
||||
'@typescript-eslint/no-unnecessary-type-conversion': 'off',
|
||||
'@typescript-eslint/no-unnecessary-type-parameters': 'off',
|
||||
'@typescript-eslint/no-unsafe-argument': 'off',
|
||||
'@typescript-eslint/no-unsafe-assignment': 'off',
|
||||
'@typescript-eslint/no-unsafe-call': 'off',
|
||||
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
|
||||
'@typescript-eslint/no-unsafe-member-access': 'off',
|
||||
'@typescript-eslint/no-unsafe-return': 'off',
|
||||
'@typescript-eslint/no-unsafe-type-assertion': 'off',
|
||||
'@typescript-eslint/no-unsafe-unary-minus': 'off',
|
||||
'@typescript-eslint/no-useless-default-assignment': 'off',
|
||||
'@typescript-eslint/non-nullable-type-assertion-style': 'off',
|
||||
'@typescript-eslint/only-throw-error': 'off',
|
||||
'@typescript-eslint/prefer-destructuring': 'off',
|
||||
'@typescript-eslint/prefer-find': 'off',
|
||||
'@typescript-eslint/prefer-includes': 'off',
|
||||
'@typescript-eslint/prefer-nullish-coalescing': 'off',
|
||||
'@typescript-eslint/prefer-optional-chain': 'off',
|
||||
'@typescript-eslint/prefer-promise-reject-errors': 'off',
|
||||
'@typescript-eslint/prefer-readonly': 'off',
|
||||
'@typescript-eslint/prefer-readonly-parameter-types': 'off',
|
||||
'@typescript-eslint/prefer-reduce-type-parameter': 'off',
|
||||
'@typescript-eslint/prefer-regexp-exec': 'off',
|
||||
'@typescript-eslint/prefer-return-this-type': 'off',
|
||||
'@typescript-eslint/prefer-string-starts-ends-with': 'off',
|
||||
'@typescript-eslint/promise-function-async': 'off',
|
||||
'@typescript-eslint/related-getter-setter-pairs': 'off',
|
||||
'@typescript-eslint/require-array-sort-compare': 'off',
|
||||
'@typescript-eslint/require-await': 'off',
|
||||
'@typescript-eslint/restrict-plus-operands': 'off',
|
||||
'@typescript-eslint/restrict-template-expressions': 'off',
|
||||
'@typescript-eslint/return-await': 'off',
|
||||
'@typescript-eslint/strict-boolean-expressions': 'off',
|
||||
'@typescript-eslint/strict-void-return': 'off',
|
||||
'@typescript-eslint/switch-exhaustiveness-check': 'off',
|
||||
'@typescript-eslint/unbound-method': 'off',
|
||||
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'off',
|
||||
},
|
||||
languageOptions: {
|
||||
parserOptions: { program: null, project: false, projectService: false },
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TypeDefinition = void 0;
|
||||
const DefinitionBase_1 = require("./DefinitionBase");
|
||||
const DefinitionType_1 = require("./DefinitionType");
|
||||
class TypeDefinition extends DefinitionBase_1.DefinitionBase {
|
||||
isTypeDefinition = true;
|
||||
isVariableDefinition = false;
|
||||
constructor(name, node) {
|
||||
super(DefinitionType_1.DefinitionType.Type, name, node, null);
|
||||
}
|
||||
}
|
||||
exports.TypeDefinition = TypeDefinition;
|
||||
@@ -0,0 +1,38 @@
|
||||
import { getRandomBytesAsync } from 'expo-random'
|
||||
|
||||
import { urlAlphabet } from '../url-alphabet/index.js'
|
||||
|
||||
let random = getRandomBytesAsync
|
||||
|
||||
let customAlphabet = (alphabet, defaultSize = 21) => {
|
||||
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
||||
|
||||
|
||||
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
||||
|
||||
let tick = (id, size = defaultSize) =>
|
||||
random(step).then(bytes => {
|
||||
let i = step
|
||||
while (i--) {
|
||||
id += alphabet[bytes[i] & mask] || ''
|
||||
if (id.length >= size) return id
|
||||
}
|
||||
return tick(id, size)
|
||||
})
|
||||
|
||||
return (size = defaultSize) => {
|
||||
if (size <= 0) return Promise.resolve('')
|
||||
return tick('', size)
|
||||
}
|
||||
}
|
||||
|
||||
let nanoid = (size = 21) =>
|
||||
random((size |= 0)).then(bytes => {
|
||||
let id = ''
|
||||
while (size--) {
|
||||
id += urlAlphabet[bytes[size] & 63]
|
||||
}
|
||||
return id
|
||||
})
|
||||
|
||||
export { nanoid, customAlphabet, random }
|
||||
@@ -0,0 +1,15 @@
|
||||
import pino from '../../..'
|
||||
import { join } from 'node:path'
|
||||
|
||||
const transport = pino.transport({
|
||||
target: join(__dirname, 'to-file-transport-with-transform.ts'),
|
||||
options: {
|
||||
destination: process.argv[2]
|
||||
}
|
||||
})
|
||||
const logger = pino(transport)
|
||||
|
||||
logger.info('Hello')
|
||||
logger.info('World')
|
||||
|
||||
process.exit(0)
|
||||
@@ -0,0 +1,10 @@
|
||||
declare namespace ieee754 {
|
||||
export function read(
|
||||
buffer: Uint8Array, offset: number, isLE: boolean, mLen: number,
|
||||
nBytes: number): number;
|
||||
export function write(
|
||||
buffer: Uint8Array, value: number, offset: number, isLE: boolean,
|
||||
mLen: number, nBytes: number): void;
|
||||
}
|
||||
|
||||
export = ieee754;
|
||||
@@ -0,0 +1,137 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
const util = __importStar(require("../core/util.cjs"));
|
||||
const error = () => {
|
||||
const Sizable = {
|
||||
string: { unit: "តួអក្សរ", verb: "គួរមាន" },
|
||||
file: { unit: "បៃ", verb: "គួរមាន" },
|
||||
array: { unit: "ធាតុ", verb: "គួរមាន" },
|
||||
set: { unit: "ធាតុ", verb: "គួរមាន" },
|
||||
};
|
||||
function getSizing(origin) {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
const FormatDictionary = {
|
||||
regex: "ទិន្នន័យបញ្ចូល",
|
||||
email: "អាសយដ្ឋានអ៊ីមែល",
|
||||
url: "URL",
|
||||
emoji: "សញ្ញាអារម្មណ៍",
|
||||
uuid: "UUID",
|
||||
uuidv4: "UUIDv4",
|
||||
uuidv6: "UUIDv6",
|
||||
nanoid: "nanoid",
|
||||
guid: "GUID",
|
||||
cuid: "cuid",
|
||||
cuid2: "cuid2",
|
||||
ulid: "ULID",
|
||||
xid: "XID",
|
||||
ksuid: "KSUID",
|
||||
datetime: "កាលបរិច្ឆេទ និងម៉ោង ISO",
|
||||
date: "កាលបរិច្ឆេទ ISO",
|
||||
time: "ម៉ោង ISO",
|
||||
duration: "រយៈពេល ISO",
|
||||
ipv4: "អាសយដ្ឋាន IPv4",
|
||||
ipv6: "អាសយដ្ឋាន IPv6",
|
||||
cidrv4: "ដែនអាសយដ្ឋាន IPv4",
|
||||
cidrv6: "ដែនអាសយដ្ឋាន IPv6",
|
||||
base64: "ខ្សែអក្សរអ៊ិកូដ base64",
|
||||
base64url: "ខ្សែអក្សរអ៊ិកូដ base64url",
|
||||
json_string: "ខ្សែអក្សរ JSON",
|
||||
e164: "លេខ E.164",
|
||||
jwt: "JWT",
|
||||
template_literal: "ទិន្នន័យបញ្ចូល",
|
||||
};
|
||||
const TypeDictionary = {
|
||||
nan: "NaN",
|
||||
number: "លេខ",
|
||||
array: "អារេ (Array)",
|
||||
null: "គ្មានតម្លៃ (null)",
|
||||
};
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
if (/^[A-Z]/.test(issue.expected)) {
|
||||
return `ទិន្នន័យបញ្ចូលមិនត្រឹមត្រូវ៖ ត្រូវការ instanceof ${issue.expected} ប៉ុន្តែទទួលបាន ${received}`;
|
||||
}
|
||||
return `ទិន្នន័យបញ្ចូលមិនត្រឹមត្រូវ៖ ត្រូវការ ${expected} ប៉ុន្តែទទួលបាន ${received}`;
|
||||
}
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1)
|
||||
return `ទិន្នន័យបញ្ចូលមិនត្រឹមត្រូវ៖ ត្រូវការ ${util.stringifyPrimitive(issue.values[0])}`;
|
||||
return `ជម្រើសមិនត្រឹមត្រូវ៖ ត្រូវជាមួយក្នុងចំណោម ${util.joinValues(issue.values, "|")}`;
|
||||
case "too_big": {
|
||||
const adj = issue.inclusive ? "<=" : "<";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing)
|
||||
return `ធំពេក៖ ត្រូវការ ${issue.origin ?? "តម្លៃ"} ${adj} ${issue.maximum.toString()} ${sizing.unit ?? "ធាតុ"}`;
|
||||
return `ធំពេក៖ ត្រូវការ ${issue.origin ?? "តម្លៃ"} ${adj} ${issue.maximum.toString()}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const adj = issue.inclusive ? ">=" : ">";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing) {
|
||||
return `តូចពេក៖ ត្រូវការ ${issue.origin} ${adj} ${issue.minimum.toString()} ${sizing.unit}`;
|
||||
}
|
||||
return `តូចពេក៖ ត្រូវការ ${issue.origin} ${adj} ${issue.minimum.toString()}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue;
|
||||
if (_issue.format === "starts_with") {
|
||||
return `ខ្សែអក្សរមិនត្រឹមត្រូវ៖ ត្រូវចាប់ផ្តើមដោយ "${_issue.prefix}"`;
|
||||
}
|
||||
if (_issue.format === "ends_with")
|
||||
return `ខ្សែអក្សរមិនត្រឹមត្រូវ៖ ត្រូវបញ្ចប់ដោយ "${_issue.suffix}"`;
|
||||
if (_issue.format === "includes")
|
||||
return `ខ្សែអក្សរមិនត្រឹមត្រូវ៖ ត្រូវមាន "${_issue.includes}"`;
|
||||
if (_issue.format === "regex")
|
||||
return `ខ្សែអក្សរមិនត្រឹមត្រូវ៖ ត្រូវតែផ្គូផ្គងនឹងទម្រង់ដែលបានកំណត់ ${_issue.pattern}`;
|
||||
return `មិនត្រឹមត្រូវ៖ ${FormatDictionary[_issue.format] ?? issue.format}`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `លេខមិនត្រឹមត្រូវ៖ ត្រូវតែជាពហុគុណនៃ ${issue.divisor}`;
|
||||
case "unrecognized_keys":
|
||||
return `រកឃើញសោមិនស្គាល់៖ ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return `សោមិនត្រឹមត្រូវនៅក្នុង ${issue.origin}`;
|
||||
case "invalid_union":
|
||||
return `ទិន្នន័យមិនត្រឹមត្រូវ`;
|
||||
case "invalid_element":
|
||||
return `ទិន្នន័យមិនត្រឹមត្រូវនៅក្នុង ${issue.origin}`;
|
||||
default:
|
||||
return `ទិន្នន័យមិនត្រឹមត្រូវ`;
|
||||
}
|
||||
};
|
||||
};
|
||||
function default_1() {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
module.exports = exports.default;
|
||||
Reference in New Issue
Block a user