WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
import type { LibDefinition } from '../variable';
|
||||
export declare const esnext_iterator: LibDefinition;
|
||||
@@ -0,0 +1,35 @@
|
||||
/*global self*/
|
||||
import Promise from './promise';
|
||||
|
||||
export default function polyfill() {
|
||||
let local;
|
||||
|
||||
if (typeof global !== 'undefined') {
|
||||
local = global;
|
||||
} else if (typeof self !== 'undefined') {
|
||||
local = self;
|
||||
} else {
|
||||
try {
|
||||
local = Function('return this')();
|
||||
} catch (e) {
|
||||
throw new Error('polyfill failed because global object is unavailable in this environment');
|
||||
}
|
||||
}
|
||||
|
||||
let P = local.Promise;
|
||||
|
||||
if (P) {
|
||||
var promiseToString = null;
|
||||
try {
|
||||
promiseToString = Object.prototype.toString.call(P.resolve());
|
||||
} catch(e) {
|
||||
// silently ignored
|
||||
}
|
||||
|
||||
if (promiseToString === '[object Promise]' && !P.cast){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
local.Promise = Promise;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import convertSourceMap from 'convert-source-map';
|
||||
|
||||
// based on vite
|
||||
// https://github.com/vitejs/vite/blob/84079a84ad94de4c1ef4f1bdb2ab448ff2c01196/packages/vite/src/node/server/sourcemap.ts#L149
|
||||
function extractSourcemapFromFile(code, filePath) {
|
||||
const map = (convertSourceMap.fromSource(code) || convertSourceMap.fromMapFileSource(code, createConvertSourceMapReadMap(filePath)))?.toObject();
|
||||
return map ? { map } : undefined;
|
||||
}
|
||||
function createConvertSourceMapReadMap(originalFileName) {
|
||||
return (filename) => {
|
||||
// convertSourceMap can detect invalid filename from comments.
|
||||
// fallback to empty source map to avoid errors.
|
||||
const targetPath = path.resolve(path.dirname(originalFileName), filename);
|
||||
if (existsSync(targetPath)) {
|
||||
return readFileSync(targetPath, "utf-8");
|
||||
}
|
||||
return "{}";
|
||||
};
|
||||
}
|
||||
|
||||
export { extractSourcemapFromFile };
|
||||
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TypeScope = void 0;
|
||||
const ScopeBase_1 = require("./ScopeBase");
|
||||
const ScopeType_1 = require("./ScopeType");
|
||||
class TypeScope extends ScopeBase_1.ScopeBase {
|
||||
constructor(scopeManager, upperScope, block) {
|
||||
super(scopeManager, ScopeType_1.ScopeType.type, upperScope, block, false);
|
||||
}
|
||||
}
|
||||
exports.TypeScope = TypeScope;
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"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"}
|
||||
@@ -0,0 +1,27 @@
|
||||
"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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./AST"), exports);
|
||||
__exportStar(require("./Config"), exports);
|
||||
__exportStar(require("./ESLint"), exports);
|
||||
__exportStar(require("./Linter"), exports);
|
||||
__exportStar(require("./Parser"), exports);
|
||||
__exportStar(require("./ParserOptions"), exports);
|
||||
__exportStar(require("./Processor"), exports);
|
||||
__exportStar(require("./Rule"), exports);
|
||||
__exportStar(require("./RuleTester"), exports);
|
||||
__exportStar(require("./Scope"), exports);
|
||||
__exportStar(require("./SourceCode"), exports);
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* @fileoverview disallow use of the Buffer() constructor
|
||||
* @author Teddy Katz
|
||||
* @deprecated in ESLint v7.0.0
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
deprecated: {
|
||||
message: "Node.js rules were moved out of ESLint core.",
|
||||
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
|
||||
deprecatedSince: "7.0.0",
|
||||
availableUntil: "11.0.0",
|
||||
replacedBy: [
|
||||
{
|
||||
message:
|
||||
"eslint-plugin-n now maintains deprecated Node.js-related rules.",
|
||||
plugin: {
|
||||
name: "eslint-plugin-n",
|
||||
url: "https://github.com/eslint-community/eslint-plugin-n",
|
||||
},
|
||||
rule: {
|
||||
name: "no-deprecated-api",
|
||||
url: "https://github.com/eslint-community/eslint-plugin-n/tree/master/docs/rules/no-deprecated-api.md",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
type: "problem",
|
||||
|
||||
docs: {
|
||||
description: "Disallow use of the `Buffer()` constructor",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/no-buffer-constructor",
|
||||
},
|
||||
|
||||
schema: [],
|
||||
|
||||
messages: {
|
||||
deprecated:
|
||||
"{{expr}} is deprecated. Use Buffer.from(), Buffer.alloc(), or Buffer.allocUnsafe() instead.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
//----------------------------------------------------------------------
|
||||
// Public
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
"CallExpression[callee.name='Buffer'], NewExpression[callee.name='Buffer']"(
|
||||
node,
|
||||
) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "deprecated",
|
||||
data: {
|
||||
expr:
|
||||
node.type === "CallExpression"
|
||||
? "Buffer()"
|
||||
: "new Buffer()",
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
function _initializer_define_property(target, property, descriptor, context) {
|
||||
if (!descriptor) return;
|
||||
|
||||
Object.defineProperty(target, property, {
|
||||
enumerable: descriptor.enumerable,
|
||||
configurable: descriptor.configurable,
|
||||
writable: descriptor.writable,
|
||||
value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
|
||||
});
|
||||
}
|
||||
export { _initializer_define_property as _ };
|
||||
@@ -0,0 +1,80 @@
|
||||
'use strict';
|
||||
module.exports = function generate__limitItems(it, $keyword, $ruleType) {
|
||||
var out = ' ';
|
||||
var $lvl = it.level;
|
||||
var $dataLvl = it.dataLevel;
|
||||
var $schema = it.schema[$keyword];
|
||||
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
||||
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||
var $breakOnError = !it.opts.allErrors;
|
||||
var $errorKeyword;
|
||||
var $data = 'data' + ($dataLvl || '');
|
||||
var $isData = it.opts.$data && $schema && $schema.$data,
|
||||
$schemaValue;
|
||||
if ($isData) {
|
||||
out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
|
||||
$schemaValue = 'schema' + $lvl;
|
||||
} else {
|
||||
$schemaValue = $schema;
|
||||
}
|
||||
if (!($isData || typeof $schema == 'number')) {
|
||||
throw new Error($keyword + ' must be number');
|
||||
}
|
||||
var $op = $keyword == 'maxItems' ? '>' : '<';
|
||||
out += 'if ( ';
|
||||
if ($isData) {
|
||||
out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
|
||||
}
|
||||
out += ' ' + ($data) + '.length ' + ($op) + ' ' + ($schemaValue) + ') { ';
|
||||
var $errorKeyword = $keyword;
|
||||
var $$outStack = $$outStack || [];
|
||||
$$outStack.push(out);
|
||||
out = ''; /* istanbul ignore else */
|
||||
if (it.createErrors !== false) {
|
||||
out += ' { keyword: \'' + ($errorKeyword || '_limitItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
|
||||
if (it.opts.messages !== false) {
|
||||
out += ' , message: \'should NOT have ';
|
||||
if ($keyword == 'maxItems') {
|
||||
out += 'more';
|
||||
} else {
|
||||
out += 'fewer';
|
||||
}
|
||||
out += ' than ';
|
||||
if ($isData) {
|
||||
out += '\' + ' + ($schemaValue) + ' + \'';
|
||||
} else {
|
||||
out += '' + ($schema);
|
||||
}
|
||||
out += ' items\' ';
|
||||
}
|
||||
if (it.opts.verbose) {
|
||||
out += ' , schema: ';
|
||||
if ($isData) {
|
||||
out += 'validate.schema' + ($schemaPath);
|
||||
} else {
|
||||
out += '' + ($schema);
|
||||
}
|
||||
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||
}
|
||||
out += ' } ';
|
||||
} else {
|
||||
out += ' {} ';
|
||||
}
|
||||
var __err = out;
|
||||
out = $$outStack.pop();
|
||||
if (!it.compositeRule && $breakOnError) {
|
||||
/* istanbul ignore if */
|
||||
if (it.async) {
|
||||
out += ' throw new ValidationError([' + (__err) + ']); ';
|
||||
} else {
|
||||
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
||||
}
|
||||
} else {
|
||||
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||
}
|
||||
out += '} ';
|
||||
if ($breakOnError) {
|
||||
out += ' else { ';
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "stream-chain",
|
||||
"version": "2.2.5",
|
||||
"description": "Chain functions as transform streams.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"debug": "node --inspect-brk tests/tests.js",
|
||||
"test": "node tests/tests.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/uhop/stream-chain.git"
|
||||
},
|
||||
"keywords": [
|
||||
"stream",
|
||||
"chain"
|
||||
],
|
||||
"author": "Eugene Lazutkin <eugene.lazutkin@gmail.com> (http://lazutkin.com/)",
|
||||
"license": "BSD-3-Clause",
|
||||
"bugs": {
|
||||
"url": "https://github.com/uhop/stream-chain/issues"
|
||||
},
|
||||
"homepage": "https://github.com/uhop/stream-chain#readme",
|
||||
"devDependencies": {
|
||||
"heya-unit": "^0.3.0"
|
||||
},
|
||||
"files": [
|
||||
"/*.js",
|
||||
"/utils"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"bls12-381.d.ts","sourceRoot":"","sources":["src/bls12-381.ts"],"names":[],"mappings":"AAgFA,OAAO,EAAO,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAS,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAmE3D,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,CAGtC,CAAC;AAuTH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,EAAE,OA8HtB,CAAC"}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/** @import * as types from "eslint-scope" */
|
||||
/** @import Reference from "./reference.js" */
|
||||
|
||||
/**
|
||||
* A Variable represents a locally scoped identifier. These include arguments to
|
||||
* functions.
|
||||
* @constructor Variable
|
||||
* @implements {types.Variable}
|
||||
*/
|
||||
class Variable {
|
||||
constructor(name, scope) {
|
||||
/**
|
||||
* The variable name, as given in the source code.
|
||||
* @member {string} Variable#name
|
||||
*/
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* List of defining occurrences of this variable (like in 'var ...'
|
||||
* statements or as parameter), as AST nodes.
|
||||
* @member {espree.Identifier[]} Variable#identifiers
|
||||
*/
|
||||
this.identifiers = [];
|
||||
|
||||
/**
|
||||
* List of {@link Reference|references} of this variable (excluding parameter entries)
|
||||
* in its defining scope and all nested scopes. For defining
|
||||
* occurrences only see {@link Variable#defs}.
|
||||
* @member {Reference[]} Variable#references
|
||||
*/
|
||||
this.references = [];
|
||||
|
||||
/**
|
||||
* List of defining occurrences of this variable (like in 'var ...'
|
||||
* statements or as parameter), as custom objects.
|
||||
* @member {Definition[]} Variable#defs
|
||||
*/
|
||||
this.defs = [];
|
||||
|
||||
this.tainted = false;
|
||||
|
||||
/**
|
||||
* Whether this is a stack variable.
|
||||
* @member {boolean} Variable#stack
|
||||
*/
|
||||
this.stack = true;
|
||||
|
||||
/**
|
||||
* Reference to the enclosing Scope.
|
||||
* @member {Scope} Variable#scope
|
||||
*/
|
||||
this.scope = scope;
|
||||
}
|
||||
}
|
||||
|
||||
Variable.CatchClause = "CatchClause";
|
||||
Variable.Parameter = "Parameter";
|
||||
Variable.FunctionName = "FunctionName";
|
||||
Variable.ClassName = "ClassName";
|
||||
Variable.Variable = "Variable";
|
||||
Variable.ImportBinding = "ImportBinding";
|
||||
Variable.ImplicitGlobalVariable = "ImplicitGlobalVariable";
|
||||
|
||||
export default Variable;
|
||||
|
||||
/* vim: set sw=4 ts=4 et tw=80 : */
|
||||
@@ -0,0 +1,114 @@
|
||||
import type * as core from "../core/index.cjs";
|
||||
import type * as JSONSchema from "./json-schema.cjs";
|
||||
import { type $ZodRegistry } from "./registries.cjs";
|
||||
import type * as schemas from "./schemas.cjs";
|
||||
import type { StandardJSONSchemaV1, StandardSchemaWithJSONProps } from "./standard-schema.cjs";
|
||||
export type Processor<T extends schemas.$ZodType = schemas.$ZodType> = (schema: T, ctx: ToJSONSchemaContext, json: JSONSchema.BaseSchema, params: ProcessParams) => void;
|
||||
export interface JSONSchemaGeneratorParams {
|
||||
processors: Record<string, Processor>;
|
||||
/** A registry used to look up metadata for each schema. Any schema with an `id` property will be extracted as a $def.
|
||||
* @default globalRegistry */
|
||||
metadata?: $ZodRegistry<Record<string, any>>;
|
||||
/** The JSON Schema version to target.
|
||||
* - `"draft-2020-12"` — Default. JSON Schema Draft 2020-12
|
||||
* - `"draft-07"` — JSON Schema Draft 7
|
||||
* - `"draft-04"` — JSON Schema Draft 4
|
||||
* - `"openapi-3.0"` — OpenAPI 3.0 Schema Object */
|
||||
target?: "draft-04" | "draft-07" | "draft-2020-12" | "openapi-3.0" | ({} & string) | undefined;
|
||||
/** How to handle unrepresentable types.
|
||||
* - `"throw"` — Default. Unrepresentable types throw an error
|
||||
* - `"any"` — Unrepresentable types become `{}` */
|
||||
unrepresentable?: "throw" | "any";
|
||||
/** Arbitrary custom logic that can be used to modify the generated JSON Schema. */
|
||||
override?: (ctx: {
|
||||
zodSchema: schemas.$ZodTypes;
|
||||
jsonSchema: JSONSchema.BaseSchema;
|
||||
path: (string | number)[];
|
||||
}) => void;
|
||||
/** Whether to extract the `"input"` or `"output"` type. Relevant to transforms, defaults, coerced primitives, etc.
|
||||
* - `"output"` — Default. Convert the output schema.
|
||||
* - `"input"` — Convert the input schema. */
|
||||
io?: "input" | "output";
|
||||
cycles?: "ref" | "throw";
|
||||
reused?: "ref" | "inline";
|
||||
external?: {
|
||||
registry: $ZodRegistry<{
|
||||
id?: string | undefined;
|
||||
}>;
|
||||
uri?: ((id: string) => string) | undefined;
|
||||
defs: Record<string, JSONSchema.BaseSchema>;
|
||||
} | undefined;
|
||||
}
|
||||
/**
|
||||
* Parameters for the toJSONSchema function.
|
||||
*/
|
||||
export type ToJSONSchemaParams = Omit<JSONSchemaGeneratorParams, "processors" | "external">;
|
||||
/**
|
||||
* Parameters for the toJSONSchema function when passing a registry.
|
||||
*/
|
||||
export interface RegistryToJSONSchemaParams extends ToJSONSchemaParams {
|
||||
uri?: (id: string) => string;
|
||||
}
|
||||
export interface ProcessParams {
|
||||
schemaPath: schemas.$ZodType[];
|
||||
path: (string | number)[];
|
||||
}
|
||||
export interface Seen {
|
||||
/** JSON Schema result for this Zod schema */
|
||||
schema: JSONSchema.BaseSchema;
|
||||
/** A cached version of the schema that doesn't get overwritten during ref resolution */
|
||||
def?: JSONSchema.BaseSchema;
|
||||
defId?: string | undefined;
|
||||
/** Number of times this schema was encountered during traversal */
|
||||
count: number;
|
||||
/** Cycle path */
|
||||
cycle?: (string | number)[] | undefined;
|
||||
isParent?: boolean | undefined;
|
||||
/** Schema to inherit JSON Schema properties from (set by processor for wrappers) */
|
||||
ref?: schemas.$ZodType | null;
|
||||
/** JSON Schema property path for this schema */
|
||||
path?: (string | number)[] | undefined;
|
||||
}
|
||||
export interface ToJSONSchemaContext {
|
||||
processors: Record<string, Processor>;
|
||||
metadataRegistry: $ZodRegistry<Record<string, any>>;
|
||||
target: "draft-04" | "draft-07" | "draft-2020-12" | "openapi-3.0" | ({} & string);
|
||||
unrepresentable: "throw" | "any";
|
||||
override: (ctx: {
|
||||
zodSchema: schemas.$ZodType;
|
||||
jsonSchema: JSONSchema.BaseSchema;
|
||||
path: (string | number)[];
|
||||
}) => void;
|
||||
io: "input" | "output";
|
||||
counter: number;
|
||||
seen: Map<schemas.$ZodType, Seen>;
|
||||
cycles: "ref" | "throw";
|
||||
reused: "ref" | "inline";
|
||||
external?: {
|
||||
registry: $ZodRegistry<{
|
||||
id?: string | undefined;
|
||||
}>;
|
||||
uri?: ((id: string) => string) | undefined;
|
||||
defs: Record<string, JSONSchema.BaseSchema>;
|
||||
} | undefined;
|
||||
}
|
||||
export declare function initializeContext(params: JSONSchemaGeneratorParams): ToJSONSchemaContext;
|
||||
export declare function process<T extends schemas.$ZodType>(schema: T, ctx: ToJSONSchemaContext, _params?: ProcessParams): JSONSchema.BaseSchema;
|
||||
export declare function extractDefs<T extends schemas.$ZodType>(ctx: ToJSONSchemaContext, schema: T): void;
|
||||
export declare function finalize<T extends schemas.$ZodType>(ctx: ToJSONSchemaContext, schema: T): ZodStandardJSONSchemaPayload<T>;
|
||||
export type ZodStandardSchemaWithJSON<T> = StandardSchemaWithJSONProps<core.input<T>, core.output<T>>;
|
||||
export interface ZodStandardJSONSchemaPayload<T> extends JSONSchema.BaseSchema {
|
||||
"~standard": ZodStandardSchemaWithJSON<T>;
|
||||
}
|
||||
/**
|
||||
* Creates a toJSONSchema method for a schema instance.
|
||||
* This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
|
||||
*/
|
||||
export declare const createToJSONSchemaMethod: <T extends schemas.$ZodType>(schema: T, processors?: Record<string, Processor>) => (params?: ToJSONSchemaParams) => ZodStandardJSONSchemaPayload<T>;
|
||||
/**
|
||||
* Creates a toJSONSchema method for a schema instance.
|
||||
* This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
|
||||
*/
|
||||
type StandardJSONSchemaMethodParams = Parameters<StandardJSONSchemaV1["~standard"]["jsonSchema"]["input"]>[0];
|
||||
export declare const createStandardJSONSchemaMethod: <T extends schemas.$ZodType>(schema: T, io: "input" | "output", processors?: Record<string, Processor>) => (params?: StandardJSONSchemaMethodParams) => JSONSchema.BaseSchema;
|
||||
export {};
|
||||
@@ -0,0 +1,2 @@
|
||||
import type { LibDefinition } from '../variable';
|
||||
export declare const es2021_string: LibDefinition;
|
||||
@@ -0,0 +1,141 @@
|
||||
# `@humanfs/node`
|
||||
|
||||
by [Nicholas C. Zakas](https://humanwhocodes.com)
|
||||
|
||||
If you find this useful, please consider supporting my work with a [donation](https://humanwhocodes.com/donate) or [nominate me](https://stars.github.com/nominate/) for a GitHub Star.
|
||||
|
||||
## Description
|
||||
|
||||
The `hfs` bindings for use in Node.js and Node.js-compatible runtimes.
|
||||
|
||||
> [!WARNING]
|
||||
> This project is **experimental** and may change significantly before v1.0.0. Use at your own caution and definitely not in production!
|
||||
|
||||
## Installation
|
||||
|
||||
Install using your favorite package manager:
|
||||
|
||||
```shell
|
||||
npm install @humanfs/node
|
||||
|
||||
# or
|
||||
|
||||
pnpm install @humanfs/node
|
||||
|
||||
# or
|
||||
|
||||
yarn add @humanfs/node
|
||||
|
||||
# or
|
||||
|
||||
bun install @humanfs/node
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
The easiest way to use hfs in your project is to import the `hfs` object:
|
||||
|
||||
```js
|
||||
import { hfs } from "@humanfs/node";
|
||||
```
|
||||
|
||||
Then, you can use the API methods:
|
||||
|
||||
```js
|
||||
// 1. Files
|
||||
|
||||
// read from a text file
|
||||
const text = await hfs.text("file.txt");
|
||||
|
||||
// read from a JSON file
|
||||
const json = await hfs.json("file.json");
|
||||
|
||||
// read raw bytes from a text file
|
||||
const arrayBuffer = await hfs.arrayBuffer("file.txt");
|
||||
|
||||
// write text to a file
|
||||
await hfs.write("file.txt", "Hello world!");
|
||||
|
||||
// write bytes to a file
|
||||
await hfs.write("file.txt", new TextEncoder().encode("Hello world!"));
|
||||
|
||||
// append text to a file
|
||||
await hfs.append("file.txt", "Hello world!");
|
||||
|
||||
// append bytes to a file
|
||||
await hfs.append("file.txt", new TextEncoder().encode("Hello world!"));
|
||||
|
||||
// does the file exist?
|
||||
const found = await hfs.isFile("file.txt");
|
||||
|
||||
// how big is the file?
|
||||
const size = await hfs.size("file.txt");
|
||||
|
||||
// when was the file modified?
|
||||
const mtime = await hfs.lastModified("file.txt");
|
||||
|
||||
// copy a file from one location to another
|
||||
await hfs.copy("file.txt", "file-copy.txt");
|
||||
|
||||
// move a file from one location to another
|
||||
await hfs.move("file.txt", "renamed.txt");
|
||||
|
||||
// delete a file
|
||||
await hfs.delete("file.txt");
|
||||
|
||||
// 2. Directories
|
||||
|
||||
// create a directory
|
||||
await hfs.createDirectory("dir");
|
||||
|
||||
// create a directory recursively
|
||||
await hfs.createDirectory("dir/subdir");
|
||||
|
||||
// does the directory exist?
|
||||
const dirFound = await hfs.isDirectory("dir");
|
||||
|
||||
// copy the entire directory
|
||||
hfs.copyAll("from-dir", "to-dir");
|
||||
|
||||
// move the entire directory
|
||||
hfs.moveAll("from-dir", "to-dir");
|
||||
|
||||
// delete a directory
|
||||
await hfs.delete("dir");
|
||||
|
||||
// delete a non-empty directory
|
||||
await hfs.deleteAll("dir");
|
||||
```
|
||||
|
||||
If you'd like to create your own instance, import the `NodeHfs` constructor:
|
||||
|
||||
```js
|
||||
import { NodeHfs } from "@humanfs/node";
|
||||
import fsp from "fs/promises";
|
||||
|
||||
const hfs = new NodeHfs();
|
||||
|
||||
// optionally specify the fs/promises object to use
|
||||
const hfs = new NodeHfs({ fsp });
|
||||
```
|
||||
|
||||
If you'd like to use just the impl, import the `NodeHfsImpl` constructor:
|
||||
|
||||
```js
|
||||
import { NodeHfsImpl } from "@humanfs/node";
|
||||
import fsp from "fs/promises";
|
||||
|
||||
const hfs = new NodeHfsImpl();
|
||||
|
||||
// optionally specify the fs/promises object to use
|
||||
const hfs = new NodeHfsImpl({ fsp });
|
||||
```
|
||||
|
||||
## Errors Handled
|
||||
|
||||
* `ENOENT` - in most cases, these errors are handled silently.
|
||||
* `ENFILE` and `EMFILE` - calls that result in these errors are retried for up to 60 seconds before giving up for good.
|
||||
|
||||
## License
|
||||
|
||||
Apache 2.0
|
||||
@@ -0,0 +1,4 @@
|
||||
function _classApplyDescriptorGet(e, t) {
|
||||
return t.get ? t.get.call(e) : t.value;
|
||||
}
|
||||
module.exports = _classApplyDescriptorGet, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
@@ -0,0 +1,69 @@
|
||||
import { expect, test } from "vitest";
|
||||
import * as z from "zod/v4";
|
||||
import { parsedType } from "../../util.js";
|
||||
|
||||
test("parsedType", () => {
|
||||
expect(parsedType("string")).toBe("string");
|
||||
expect(parsedType(1)).toBe("number");
|
||||
expect(parsedType(true)).toBe("boolean");
|
||||
expect(parsedType(null)).toBe("null");
|
||||
expect(parsedType(undefined)).toBe("undefined");
|
||||
expect(parsedType([])).toBe("array");
|
||||
expect(parsedType({})).toBe("object");
|
||||
expect(parsedType(new Date())).toBe("Date");
|
||||
expect(parsedType(new Map())).toBe("Map");
|
||||
expect(parsedType(new Set())).toBe("Set");
|
||||
expect(parsedType(new Error())).toBe("Error");
|
||||
|
||||
const nullPrototype = Object.create(null);
|
||||
expect(parsedType(nullPrototype)).toBe("object");
|
||||
|
||||
const doubleNullPrototype = Object.create(Object.create(null));
|
||||
expect(parsedType(doubleNullPrototype)).toBe("object");
|
||||
|
||||
expect(parsedType(Number.NaN)).toBe("nan");
|
||||
});
|
||||
|
||||
test("locales - tr", () => {
|
||||
z.config(z.locales.tr());
|
||||
|
||||
const invalidType = z.number().safeParse("a");
|
||||
expect(invalidType.error!.issues[0].code).toBe("invalid_type");
|
||||
expect(invalidType.error!.issues[0].message).toBe("Geçersiz değer: beklenen number, alınan string");
|
||||
|
||||
const invalidType2 = z.string().safeParse(1);
|
||||
expect(invalidType2.error!.issues[0].code).toBe("invalid_type");
|
||||
expect(invalidType2.error!.issues[0].message).toBe("Geçersiz değer: beklenen string, alınan number");
|
||||
|
||||
const invalidValue = z.enum(["a", "b"]).safeParse(1);
|
||||
expect(invalidValue.error!.issues[0].code).toBe("invalid_value");
|
||||
expect(invalidValue.error!.issues[0].message).toBe('Geçersiz seçenek: aşağıdakilerden biri olmalı: "a"|"b"');
|
||||
|
||||
const tooBig = z.number().max(10).safeParse(15);
|
||||
expect(tooBig.error!.issues[0].code).toBe("too_big");
|
||||
expect(tooBig.error!.issues[0].message).toBe("Çok büyük: beklenen number <=10");
|
||||
|
||||
const tooSmall = z.number().min(10).safeParse(5);
|
||||
expect(tooSmall.error!.issues[0].code).toBe("too_small");
|
||||
expect(tooSmall.error!.issues[0].message).toBe("Çok küçük: beklenen number >=10");
|
||||
|
||||
const invalidFormatRegex = z.string().regex(/abcd/).safeParse("invalid-string");
|
||||
expect(invalidFormatRegex.error!.issues[0].code).toBe("invalid_format");
|
||||
expect(invalidFormatRegex.error!.issues[0].message).toBe("Geçersiz metin: /abcd/ desenine uymalı");
|
||||
|
||||
const invalidFormatStartsWith = z.string().startsWith("abcd").safeParse("invalid-string");
|
||||
expect(invalidFormatStartsWith.error!.issues[0].code).toBe("invalid_format");
|
||||
expect(invalidFormatStartsWith.error!.issues[0].message).toBe('Geçersiz metin: "abcd" ile başlamalı');
|
||||
|
||||
const notMultipleOf = z.number().multipleOf(3).safeParse(10);
|
||||
expect(notMultipleOf.error!.issues[0].code).toBe("not_multiple_of");
|
||||
expect(notMultipleOf.error!.issues[0].message).toBe("Geçersiz sayı: 3 ile tam bölünebilmeli");
|
||||
|
||||
const unrecognizedKeys = z.object({ a: z.string(), b: z.number() }).strict().safeParse({ a: "a", b: 1, c: 2 });
|
||||
expect(unrecognizedKeys.error!.issues[0].code).toBe("unrecognized_keys");
|
||||
expect(unrecognizedKeys.error!.issues[0].message).toBe('Tanınmayan anahtar: "c"');
|
||||
|
||||
const invalidUnion = z.union([z.string(), z.number()]).safeParse(true);
|
||||
expect(invalidUnion.error!.issues[0].code).toBe("invalid_union");
|
||||
expect(invalidUnion.error!.issues[0].message).toBe("Geçersiz değer");
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "pg-pool",
|
||||
"version": "3.14.0",
|
||||
"description": "Connection pool for node-postgres",
|
||||
"main": "index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./esm/index.mjs",
|
||||
"require": "./index.js",
|
||||
"default": "./index.js"
|
||||
}
|
||||
},
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"test": " node_modules/.bin/mocha"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/brianc/node-postgres.git",
|
||||
"directory": "packages/pg-pool"
|
||||
},
|
||||
"keywords": [
|
||||
"pg",
|
||||
"postgres",
|
||||
"pool",
|
||||
"database"
|
||||
],
|
||||
"author": "Brian M. Carlson",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/brianc/node-postgres/issues"
|
||||
},
|
||||
"homepage": "https://github.com/brianc/node-postgres/tree/master/packages/pg-pool#readme",
|
||||
"devDependencies": {
|
||||
"bluebird": "3.7.2",
|
||||
"co": "4.6.0",
|
||||
"expect.js": "0.3.1",
|
||||
"lodash": "^4.17.11",
|
||||
"mocha": "^11.7.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"pg": ">=8.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"esm"
|
||||
],
|
||||
"gitHead": "544b1ce8152bc280e398dc1e8a66920abe6a640e"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import type { ZodArray, ZodNullable, ZodObject, ZodOptional, ZodRawShape, ZodTuple, ZodTupleItems, ZodTypeAny } from "../types.cjs";
|
||||
export declare namespace partialUtil {
|
||||
type DeepPartial<T extends ZodTypeAny> = T extends ZodObject<ZodRawShape> ? ZodObject<{
|
||||
[k in keyof T["shape"]]: ZodOptional<DeepPartial<T["shape"][k]>>;
|
||||
}, T["_def"]["unknownKeys"], T["_def"]["catchall"]> : T extends ZodArray<infer Type, infer Card> ? ZodArray<DeepPartial<Type>, Card> : T extends ZodOptional<infer Type> ? ZodOptional<DeepPartial<Type>> : T extends ZodNullable<infer Type> ? ZodNullable<DeepPartial<Type>> : T extends ZodTuple<infer Items> ? {
|
||||
[k in keyof Items]: Items[k] extends ZodTypeAny ? DeepPartial<Items[k]> : never;
|
||||
} extends infer PI ? PI extends ZodTupleItems ? ZodTuple<PI> : never : never : T;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Generate secure URL-friendly unique ID.
|
||||
*
|
||||
* By default, the ID will have 21 symbols to have a collision probability
|
||||
* similar to UUID v4.
|
||||
*
|
||||
* ```js
|
||||
* import { nanoid } from 'nanoid'
|
||||
* model.id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqL"
|
||||
* ```
|
||||
*
|
||||
* @param size Size of the ID. The default size is 21.
|
||||
* @returns A random string.
|
||||
*/
|
||||
export function nanoid(size?: number): string
|
||||
|
||||
/**
|
||||
* Generate secure unique ID with custom alphabet.
|
||||
*
|
||||
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
||||
* will not be secure.
|
||||
*
|
||||
* @param alphabet Alphabet used to generate the ID.
|
||||
* @param defaultSize Size of the ID. The default size is 21.
|
||||
* @returns A random string generator.
|
||||
*
|
||||
* ```js
|
||||
* const { customAlphabet } = require('nanoid')
|
||||
* const nanoid = customAlphabet('0123456789абвгдеё', 5)
|
||||
* nanoid() //=> "8ё56а"
|
||||
* ```
|
||||
*/
|
||||
export function customAlphabet(
|
||||
alphabet: string,
|
||||
defaultSize?: number
|
||||
): (size?: number) => string
|
||||
|
||||
/**
|
||||
* Generate unique ID with custom random generator and alphabet.
|
||||
*
|
||||
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
||||
* will not be secure.
|
||||
*
|
||||
* ```js
|
||||
* import { customRandom } from 'nanoid/format'
|
||||
*
|
||||
* const nanoid = customRandom('abcdef', 5, size => {
|
||||
* const random = []
|
||||
* for (let i = 0; i < size; i++) {
|
||||
* random.push(randomByte())
|
||||
* }
|
||||
* return random
|
||||
* })
|
||||
*
|
||||
* nanoid() //=> "fbaef"
|
||||
* ```
|
||||
*
|
||||
* @param alphabet Alphabet used to generate a random string.
|
||||
* @param size Size of the random string.
|
||||
* @param random A random bytes generator.
|
||||
* @returns A random string generator.
|
||||
*/
|
||||
export function customRandom(
|
||||
alphabet: string,
|
||||
size: number,
|
||||
random: (bytes: number) => Uint8Array
|
||||
): () => string
|
||||
|
||||
/**
|
||||
* URL safe symbols.
|
||||
*
|
||||
* ```js
|
||||
* import { urlAlphabet } from 'nanoid'
|
||||
* const nanoid = customAlphabet(urlAlphabet, 10)
|
||||
* nanoid() //=> "Uakgb_J5m9"
|
||||
* ```
|
||||
*/
|
||||
export const urlAlphabet: string
|
||||
|
||||
/**
|
||||
* Generate an array of random bytes collected from hardware noise.
|
||||
*
|
||||
* ```js
|
||||
* import { customRandom, random } from 'nanoid'
|
||||
* const nanoid = customRandom("abcdef", 5, random)
|
||||
* ```
|
||||
*
|
||||
* @param bytes Size of the array.
|
||||
* @returns An array of random bytes.
|
||||
*/
|
||||
export function random(bytes: number): Uint8Array
|
||||
@@ -0,0 +1,2 @@
|
||||
import type { LibDefinition } from '../variable';
|
||||
export declare const es2025_promise: LibDefinition;
|
||||
@@ -0,0 +1,79 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface PromiseConstructor {
|
||||
/**
|
||||
* A reference to the prototype.
|
||||
*/
|
||||
readonly prototype: Promise<any>;
|
||||
|
||||
/**
|
||||
* Creates a new Promise.
|
||||
* @param executor A callback used to initialize the promise. This callback is passed two arguments:
|
||||
* a resolve callback used to resolve the promise with a value or the result of another promise,
|
||||
* and a reject callback used to reject the promise with a provided reason or error.
|
||||
*/
|
||||
new <T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
|
||||
|
||||
/**
|
||||
* Creates a Promise that is resolved with an array of results when all of the provided Promises
|
||||
* resolve, or rejected when any Promise is rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new Promise.
|
||||
*/
|
||||
all<T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>;
|
||||
|
||||
// see: lib.es2015.iterable.d.ts
|
||||
// all<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>;
|
||||
|
||||
/**
|
||||
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
|
||||
* or rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new Promise.
|
||||
*/
|
||||
race<T extends readonly unknown[] | []>(values: T): Promise<Awaited<T[number]>>;
|
||||
|
||||
// see: lib.es2015.iterable.d.ts
|
||||
// race<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>;
|
||||
|
||||
/**
|
||||
* Creates a new rejected promise for the provided reason.
|
||||
* @param reason The reason the promise was rejected.
|
||||
* @returns A new rejected Promise.
|
||||
*/
|
||||
reject<T = never>(reason?: any): Promise<T>;
|
||||
|
||||
/**
|
||||
* Creates a new resolved promise.
|
||||
* @returns A resolved promise.
|
||||
*/
|
||||
resolve(): Promise<void>;
|
||||
/**
|
||||
* Creates a new resolved promise for the provided value.
|
||||
* @param value A promise.
|
||||
* @returns A promise whose internal state matches the provided promise.
|
||||
*/
|
||||
resolve<T>(value: T): Promise<Awaited<T>>;
|
||||
/**
|
||||
* Creates a new resolved promise for the provided value.
|
||||
* @param value A promise.
|
||||
* @returns A promise whose internal state matches the provided promise.
|
||||
*/
|
||||
resolve<T>(value: T | PromiseLike<T>): Promise<Awaited<T>>;
|
||||
}
|
||||
|
||||
declare var Promise: PromiseConstructor;
|
||||
@@ -0,0 +1,44 @@
|
||||
type ModeWriter = (doc: Doc, modes: { execution: "sync" | "async" }) => void;
|
||||
|
||||
export class Doc {
|
||||
args!: string[];
|
||||
content: string[] = [];
|
||||
indent = 0;
|
||||
|
||||
constructor(args: string[] = []) {
|
||||
if (this) this.args = args;
|
||||
}
|
||||
|
||||
indented(fn: (doc: Doc) => void) {
|
||||
this.indent += 1;
|
||||
fn(this);
|
||||
this.indent -= 1;
|
||||
}
|
||||
|
||||
write(fn: ModeWriter): void;
|
||||
write(line: string): void;
|
||||
write(arg: any) {
|
||||
if (typeof arg === "function") {
|
||||
(arg as ModeWriter)(this, { execution: "sync" });
|
||||
(arg as ModeWriter)(this, { execution: "async" });
|
||||
return;
|
||||
}
|
||||
|
||||
const content = arg as string;
|
||||
const lines = content.split("\n").filter((x) => x);
|
||||
const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
|
||||
const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
|
||||
for (const line of dedented) {
|
||||
this.content.push(line);
|
||||
}
|
||||
}
|
||||
|
||||
compile(): any {
|
||||
const F = Function;
|
||||
const args = this?.args;
|
||||
const content = this?.content ?? [``];
|
||||
const lines = [...content.map((x) => ` ${x}`)];
|
||||
// console.log(lines.join("\n"));
|
||||
return new F(...args, lines.join("\n")) as any;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user