WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||

|
||||
|
||||
# pino
|
||||
[](https://www.npmjs.com/package/pino)
|
||||
[](https://github.com/pinojs/pino/actions)
|
||||
[](https://standardjs.com/)
|
||||
|
||||
[Very low overhead](#low-overhead) JavaScript logger.
|
||||
|
||||
## Documentation
|
||||
|
||||
* [Benchmarks ⇗](/docs/benchmarks.md)
|
||||
* [API ⇗](/docs/api.md)
|
||||
* [Browser API ⇗](/docs/browser.md)
|
||||
* [Redaction ⇗](/docs/redaction.md)
|
||||
* [Child Loggers ⇗](/docs/child-loggers.md)
|
||||
* [Transports ⇗](/docs/transports.md)
|
||||
* [Diagnostics ⇗](/docs/diagnostics.md)
|
||||
* [Web Frameworks ⇗](/docs/web.md)
|
||||
* [Pretty Printing ⇗](/docs/pretty.md)
|
||||
* [Asynchronous Logging ⇗](/docs/asynchronous.md)
|
||||
* [Ecosystem ⇗](/docs/ecosystem.md)
|
||||
* [Help ⇗](/docs/help.md)
|
||||
* [Long Term Support Policy ⇗](/docs/lts.md)
|
||||
|
||||
## Runtimes
|
||||
|
||||
### Node.js
|
||||
|
||||
Pino is built to run on [Node.js](http://nodejs.org).
|
||||
|
||||
### Bare
|
||||
|
||||
Pino works on [Bare](https://github.com/holepunchto/bare) with the [`pino-bare`](https://github.com/pinojs/pino-bare) compatability module.
|
||||
|
||||
### Pear
|
||||
|
||||
Pino works on [Pear](https://docs.pears.com), which is built on [Bare](https://github.com/holepunchto/bare), with the [`pino-bare`](https://github.com/pinojs/pino-bare) compatibility module.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
Using NPM:
|
||||
```
|
||||
$ npm install pino
|
||||
```
|
||||
|
||||
Using YARN:
|
||||
```
|
||||
$ yarn add pino
|
||||
```
|
||||
|
||||
If you would like to install pino v6, refer to https://github.com/pinojs/pino/tree/v6.x.
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const logger = require('pino')()
|
||||
|
||||
logger.info('hello world')
|
||||
|
||||
const child = logger.child({ a: 'property' })
|
||||
child.info('hello child!')
|
||||
```
|
||||
|
||||
This produces:
|
||||
|
||||
```
|
||||
{"level":30,"time":1531171074631,"msg":"hello world","pid":657,"hostname":"Davids-MBP-3.fritz.box"}
|
||||
{"level":30,"time":1531171082399,"msg":"hello child!","pid":657,"hostname":"Davids-MBP-3.fritz.box","a":"property"}
|
||||
```
|
||||
|
||||
For using Pino with a web framework see:
|
||||
|
||||
* [Pino with Fastify](docs/web.md#fastify)
|
||||
* [Pino with Express](docs/web.md#express)
|
||||
* [Pino with Hapi](docs/web.md#hapi)
|
||||
* [Pino with Restify](docs/web.md#restify)
|
||||
* [Pino with Koa](docs/web.md#koa)
|
||||
* [Pino with Node core `http`](docs/web.md#http)
|
||||
* [Pino with Nest](docs/web.md#nest)
|
||||
* [Pino with Hono](docs/web.md#hono)
|
||||
|
||||
<a name="essentials"></a>
|
||||
## Essentials
|
||||
|
||||
### Development Formatting
|
||||
|
||||
The [`pino-pretty`](https://github.com/pinojs/pino-pretty) module can be used to
|
||||
format logs during development:
|
||||
|
||||

|
||||
|
||||
### Transports & Log Processing
|
||||
|
||||
Due to Node's single-threaded event-loop, it's highly recommended that sending,
|
||||
alert triggering, reformatting, and all forms of log processing
|
||||
are conducted in a separate process or thread.
|
||||
|
||||
In Pino terminology, we call all log processors "transports" and recommend that the
|
||||
transports be run in a worker thread using our `pino.transport` API.
|
||||
|
||||
For more details see our [Transports⇗](docs/transports.md) document.
|
||||
|
||||
### Low overhead
|
||||
|
||||
Using minimum resources for logging is very important. Log messages
|
||||
tend to get added over time and this can lead to a throttling effect
|
||||
on applications – such as reduced requests per second.
|
||||
|
||||
In many cases, Pino is over 5x faster than alternatives.
|
||||
|
||||
See the [Benchmarks](docs/benchmarks.md) document for comparisons.
|
||||
|
||||
### Bundling support
|
||||
|
||||
Pino supports being bundled using tools like webpack or esbuild.
|
||||
|
||||
See [Bundling](docs/bundling.md) document for more information.
|
||||
|
||||
<a name="team"></a>
|
||||
## The Team
|
||||
|
||||
### Matteo Collina
|
||||
|
||||
<https://github.com/mcollina>
|
||||
|
||||
<https://www.npmjs.com/~matteo.collina>
|
||||
|
||||
<https://twitter.com/matteocollina>
|
||||
|
||||
### David Mark Clements
|
||||
|
||||
<https://github.com/davidmarkclements>
|
||||
|
||||
<https://www.npmjs.com/~davidmarkclements>
|
||||
|
||||
<https://twitter.com/davidmarkclem>
|
||||
|
||||
### James Sumners
|
||||
|
||||
<https://github.com/jsumners>
|
||||
|
||||
<https://www.npmjs.com/~jsumners>
|
||||
|
||||
<https://twitter.com/jsumners79>
|
||||
|
||||
### Thomas Watson Steen
|
||||
|
||||
<https://github.com/watson>
|
||||
|
||||
<https://www.npmjs.com/~watson>
|
||||
|
||||
<https://twitter.com/wa7son>
|
||||
|
||||
## Contributing
|
||||
|
||||
Pino is an **OPEN Open Source Project**. This means that:
|
||||
|
||||
> Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
|
||||
|
||||
See the [CONTRIBUTING.md](https://github.com/pinojs/pino/blob/main/CONTRIBUTING.md) file for more details.
|
||||
|
||||
<a name="acknowledgments"></a>
|
||||
## Acknowledgments
|
||||
|
||||
This project was kindly sponsored by [nearForm](https://nearform.com).
|
||||
This project is kindly sponsored by [Platformatic](https://platformatic.dev).
|
||||
|
||||
Logo and identity designed by Cosmic Fox Design: https://www.behance.net/cosmicfox.
|
||||
|
||||
## License
|
||||
|
||||
Licensed under [MIT](./LICENSE).
|
||||
|
||||
[elasticsearch]: https://www.elastic.co/products/elasticsearch
|
||||
[kibana]: https://www.elastic.co/products/kibana
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Ben Drucker <bvdrucker@gmail.com> (bendrucker.me)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* @fileoverview Rule to flag when using constructor for wrapper objects
|
||||
* @author Ilya Volodin
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const { getVariableByName } = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Disallow `new` operators with the `String`, `Number`, and `Boolean` objects",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/no-new-wrappers",
|
||||
},
|
||||
|
||||
schema: [],
|
||||
|
||||
messages: {
|
||||
noConstructor: "Do not use {{fn}} as a constructor.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const { sourceCode } = context;
|
||||
|
||||
return {
|
||||
NewExpression(node) {
|
||||
const wrapperObjects = ["String", "Number", "Boolean"];
|
||||
const { name } = node.callee;
|
||||
|
||||
if (wrapperObjects.includes(name)) {
|
||||
const variable = getVariableByName(
|
||||
sourceCode.getScope(node),
|
||||
name,
|
||||
);
|
||||
|
||||
if (variable && variable.identifiers.length === 0) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "noConstructor",
|
||||
data: { fn: name },
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { _ as default } from "../esm/_identity.js";
|
||||
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
withResolvers: function () {
|
||||
let promiseResolve, promiseReject
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
promiseResolve = resolve
|
||||
promiseReject = reject
|
||||
})
|
||||
return { promise, resolve: promiseResolve, reject: promiseReject }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,356 @@
|
||||
declare module 'zlib' {
|
||||
import * as stream from 'stream';
|
||||
|
||||
interface ZlibOptions {
|
||||
/**
|
||||
* @default constants.Z_NO_FLUSH
|
||||
*/
|
||||
flush?: number | undefined;
|
||||
/**
|
||||
* @default constants.Z_FINISH
|
||||
*/
|
||||
finishFlush?: number | undefined;
|
||||
/**
|
||||
* @default 16*1024
|
||||
*/
|
||||
chunkSize?: number | undefined;
|
||||
windowBits?: number | undefined;
|
||||
level?: number | undefined; // compression only
|
||||
memLevel?: number | undefined; // compression only
|
||||
strategy?: number | undefined; // compression only
|
||||
dictionary?: NodeJS.ArrayBufferView | ArrayBuffer | undefined; // deflate/inflate only, empty dictionary by default
|
||||
info?: boolean | undefined;
|
||||
maxOutputLength?: number | undefined;
|
||||
}
|
||||
|
||||
interface BrotliOptions {
|
||||
/**
|
||||
* @default constants.BROTLI_OPERATION_PROCESS
|
||||
*/
|
||||
flush?: number | undefined;
|
||||
/**
|
||||
* @default constants.BROTLI_OPERATION_FINISH
|
||||
*/
|
||||
finishFlush?: number | undefined;
|
||||
/**
|
||||
* @default 16*1024
|
||||
*/
|
||||
chunkSize?: number | undefined;
|
||||
params?: {
|
||||
/**
|
||||
* Each key is a `constants.BROTLI_*` constant.
|
||||
*/
|
||||
[key: number]: boolean | number;
|
||||
} | undefined;
|
||||
maxOutputLength?: number | undefined;
|
||||
}
|
||||
|
||||
interface Zlib {
|
||||
/** @deprecated Use bytesWritten instead. */
|
||||
readonly bytesRead: number;
|
||||
readonly bytesWritten: number;
|
||||
shell?: boolean | string | undefined;
|
||||
close(callback?: () => void): void;
|
||||
flush(kind?: number, callback?: () => void): void;
|
||||
flush(callback?: () => void): void;
|
||||
}
|
||||
|
||||
interface ZlibParams {
|
||||
params(level: number, strategy: number, callback: () => void): void;
|
||||
}
|
||||
|
||||
interface ZlibReset {
|
||||
reset(): void;
|
||||
}
|
||||
|
||||
interface BrotliCompress extends stream.Transform, Zlib { }
|
||||
interface BrotliDecompress extends stream.Transform, Zlib { }
|
||||
interface Gzip extends stream.Transform, Zlib { }
|
||||
interface Gunzip extends stream.Transform, Zlib { }
|
||||
interface Deflate extends stream.Transform, Zlib, ZlibReset, ZlibParams { }
|
||||
interface Inflate extends stream.Transform, Zlib, ZlibReset { }
|
||||
interface DeflateRaw extends stream.Transform, Zlib, ZlibReset, ZlibParams { }
|
||||
interface InflateRaw extends stream.Transform, Zlib, ZlibReset { }
|
||||
interface Unzip extends stream.Transform, Zlib { }
|
||||
|
||||
function createBrotliCompress(options?: BrotliOptions): BrotliCompress;
|
||||
function createBrotliDecompress(options?: BrotliOptions): BrotliDecompress;
|
||||
function createGzip(options?: ZlibOptions): Gzip;
|
||||
function createGunzip(options?: ZlibOptions): Gunzip;
|
||||
function createDeflate(options?: ZlibOptions): Deflate;
|
||||
function createInflate(options?: ZlibOptions): Inflate;
|
||||
function createDeflateRaw(options?: ZlibOptions): DeflateRaw;
|
||||
function createInflateRaw(options?: ZlibOptions): InflateRaw;
|
||||
function createUnzip(options?: ZlibOptions): Unzip;
|
||||
|
||||
type InputType = string | ArrayBuffer | NodeJS.ArrayBufferView;
|
||||
|
||||
type CompressCallback = (error: Error | null, result: Buffer) => void;
|
||||
|
||||
function brotliCompress(buf: InputType, options: BrotliOptions, callback: CompressCallback): void;
|
||||
function brotliCompress(buf: InputType, callback: CompressCallback): void;
|
||||
namespace brotliCompress {
|
||||
function __promisify__(buffer: InputType, options?: BrotliOptions): Promise<Buffer>;
|
||||
}
|
||||
|
||||
function brotliCompressSync(buf: InputType, options?: BrotliOptions): Buffer;
|
||||
|
||||
function brotliDecompress(buf: InputType, options: BrotliOptions, callback: CompressCallback): void;
|
||||
function brotliDecompress(buf: InputType, callback: CompressCallback): void;
|
||||
namespace brotliDecompress {
|
||||
function __promisify__(buffer: InputType, options?: BrotliOptions): Promise<Buffer>;
|
||||
}
|
||||
|
||||
function brotliDecompressSync(buf: InputType, options?: BrotliOptions): Buffer;
|
||||
|
||||
function deflate(buf: InputType, callback: CompressCallback): void;
|
||||
function deflate(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
|
||||
namespace deflate {
|
||||
function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
|
||||
}
|
||||
|
||||
function deflateSync(buf: InputType, options?: ZlibOptions): Buffer;
|
||||
|
||||
function deflateRaw(buf: InputType, callback: CompressCallback): void;
|
||||
function deflateRaw(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
|
||||
namespace deflateRaw {
|
||||
function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
|
||||
}
|
||||
|
||||
function deflateRawSync(buf: InputType, options?: ZlibOptions): Buffer;
|
||||
|
||||
function gzip(buf: InputType, callback: CompressCallback): void;
|
||||
function gzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
|
||||
namespace gzip {
|
||||
function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
|
||||
}
|
||||
|
||||
function gzipSync(buf: InputType, options?: ZlibOptions): Buffer;
|
||||
|
||||
function gunzip(buf: InputType, callback: CompressCallback): void;
|
||||
function gunzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
|
||||
namespace gunzip {
|
||||
function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
|
||||
}
|
||||
|
||||
function gunzipSync(buf: InputType, options?: ZlibOptions): Buffer;
|
||||
|
||||
function inflate(buf: InputType, callback: CompressCallback): void;
|
||||
function inflate(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
|
||||
namespace inflate {
|
||||
function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
|
||||
}
|
||||
|
||||
function inflateSync(buf: InputType, options?: ZlibOptions): Buffer;
|
||||
|
||||
function inflateRaw(buf: InputType, callback: CompressCallback): void;
|
||||
function inflateRaw(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
|
||||
namespace inflateRaw {
|
||||
function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
|
||||
}
|
||||
|
||||
function inflateRawSync(buf: InputType, options?: ZlibOptions): Buffer;
|
||||
|
||||
function unzip(buf: InputType, callback: CompressCallback): void;
|
||||
function unzip(buf: InputType, options: ZlibOptions, callback: CompressCallback): void;
|
||||
namespace unzip {
|
||||
function __promisify__(buffer: InputType, options?: ZlibOptions): Promise<Buffer>;
|
||||
}
|
||||
|
||||
function unzipSync(buf: InputType, options?: ZlibOptions): Buffer;
|
||||
|
||||
namespace constants {
|
||||
const BROTLI_DECODE: number;
|
||||
const BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: number;
|
||||
const BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: number;
|
||||
const BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: number;
|
||||
const BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: number;
|
||||
const BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: number;
|
||||
const BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: number;
|
||||
const BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_DISTANCE: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_PADDING_1: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_PADDING_2: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_RESERVED: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: number;
|
||||
const BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: number;
|
||||
const BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: number;
|
||||
const BROTLI_DECODER_ERROR_UNREACHABLE: number;
|
||||
const BROTLI_DECODER_NEEDS_MORE_INPUT: number;
|
||||
const BROTLI_DECODER_NEEDS_MORE_OUTPUT: number;
|
||||
const BROTLI_DECODER_NO_ERROR: number;
|
||||
const BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: number;
|
||||
const BROTLI_DECODER_PARAM_LARGE_WINDOW: number;
|
||||
const BROTLI_DECODER_RESULT_ERROR: number;
|
||||
const BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: number;
|
||||
const BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: number;
|
||||
const BROTLI_DECODER_RESULT_SUCCESS: number;
|
||||
const BROTLI_DECODER_SUCCESS: number;
|
||||
|
||||
const BROTLI_DEFAULT_MODE: number;
|
||||
const BROTLI_DEFAULT_QUALITY: number;
|
||||
const BROTLI_DEFAULT_WINDOW: number;
|
||||
const BROTLI_ENCODE: number;
|
||||
const BROTLI_LARGE_MAX_WINDOW_BITS: number;
|
||||
const BROTLI_MAX_INPUT_BLOCK_BITS: number;
|
||||
const BROTLI_MAX_QUALITY: number;
|
||||
const BROTLI_MAX_WINDOW_BITS: number;
|
||||
const BROTLI_MIN_INPUT_BLOCK_BITS: number;
|
||||
const BROTLI_MIN_QUALITY: number;
|
||||
const BROTLI_MIN_WINDOW_BITS: number;
|
||||
|
||||
const BROTLI_MODE_FONT: number;
|
||||
const BROTLI_MODE_GENERIC: number;
|
||||
const BROTLI_MODE_TEXT: number;
|
||||
|
||||
const BROTLI_OPERATION_EMIT_METADATA: number;
|
||||
const BROTLI_OPERATION_FINISH: number;
|
||||
const BROTLI_OPERATION_FLUSH: number;
|
||||
const BROTLI_OPERATION_PROCESS: number;
|
||||
|
||||
const BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: number;
|
||||
const BROTLI_PARAM_LARGE_WINDOW: number;
|
||||
const BROTLI_PARAM_LGBLOCK: number;
|
||||
const BROTLI_PARAM_LGWIN: number;
|
||||
const BROTLI_PARAM_MODE: number;
|
||||
const BROTLI_PARAM_NDIRECT: number;
|
||||
const BROTLI_PARAM_NPOSTFIX: number;
|
||||
const BROTLI_PARAM_QUALITY: number;
|
||||
const BROTLI_PARAM_SIZE_HINT: number;
|
||||
|
||||
const DEFLATE: number;
|
||||
const DEFLATERAW: number;
|
||||
const GUNZIP: number;
|
||||
const GZIP: number;
|
||||
const INFLATE: number;
|
||||
const INFLATERAW: number;
|
||||
const UNZIP: number;
|
||||
|
||||
const Z_NO_FLUSH: number;
|
||||
const Z_PARTIAL_FLUSH: number;
|
||||
const Z_SYNC_FLUSH: number;
|
||||
const Z_FULL_FLUSH: number;
|
||||
const Z_FINISH: number;
|
||||
const Z_BLOCK: number;
|
||||
const Z_TREES: number;
|
||||
|
||||
const Z_OK: number;
|
||||
const Z_STREAM_END: number;
|
||||
const Z_NEED_DICT: number;
|
||||
const Z_ERRNO: number;
|
||||
const Z_STREAM_ERROR: number;
|
||||
const Z_DATA_ERROR: number;
|
||||
const Z_MEM_ERROR: number;
|
||||
const Z_BUF_ERROR: number;
|
||||
const Z_VERSION_ERROR: number;
|
||||
|
||||
const Z_NO_COMPRESSION: number;
|
||||
const Z_BEST_SPEED: number;
|
||||
const Z_BEST_COMPRESSION: number;
|
||||
const Z_DEFAULT_COMPRESSION: number;
|
||||
|
||||
const Z_FILTERED: number;
|
||||
const Z_HUFFMAN_ONLY: number;
|
||||
const Z_RLE: number;
|
||||
const Z_FIXED: number;
|
||||
const Z_DEFAULT_STRATEGY: number;
|
||||
|
||||
const Z_DEFAULT_WINDOWBITS: number;
|
||||
const Z_MIN_WINDOWBITS: number;
|
||||
const Z_MAX_WINDOWBITS: number;
|
||||
|
||||
const Z_MIN_CHUNK: number;
|
||||
const Z_MAX_CHUNK: number;
|
||||
const Z_DEFAULT_CHUNK: number;
|
||||
|
||||
const Z_MIN_MEMLEVEL: number;
|
||||
const Z_MAX_MEMLEVEL: number;
|
||||
const Z_DEFAULT_MEMLEVEL: number;
|
||||
|
||||
const Z_MIN_LEVEL: number;
|
||||
const Z_MAX_LEVEL: number;
|
||||
const Z_DEFAULT_LEVEL: number;
|
||||
|
||||
const ZLIB_VERNUM: number;
|
||||
}
|
||||
|
||||
// Allowed flush values.
|
||||
/** @deprecated Use `constants.Z_NO_FLUSH` */
|
||||
const Z_NO_FLUSH: number;
|
||||
/** @deprecated Use `constants.Z_PARTIAL_FLUSH` */
|
||||
const Z_PARTIAL_FLUSH: number;
|
||||
/** @deprecated Use `constants.Z_SYNC_FLUSH` */
|
||||
const Z_SYNC_FLUSH: number;
|
||||
/** @deprecated Use `constants.Z_FULL_FLUSH` */
|
||||
const Z_FULL_FLUSH: number;
|
||||
/** @deprecated Use `constants.Z_FINISH` */
|
||||
const Z_FINISH: number;
|
||||
/** @deprecated Use `constants.Z_BLOCK` */
|
||||
const Z_BLOCK: number;
|
||||
/** @deprecated Use `constants.Z_TREES` */
|
||||
const Z_TREES: number;
|
||||
|
||||
// Return codes for the compression/decompression functions.
|
||||
// Negative values are errors, positive values are used for special but normal events.
|
||||
/** @deprecated Use `constants.Z_OK` */
|
||||
const Z_OK: number;
|
||||
/** @deprecated Use `constants.Z_STREAM_END` */
|
||||
const Z_STREAM_END: number;
|
||||
/** @deprecated Use `constants.Z_NEED_DICT` */
|
||||
const Z_NEED_DICT: number;
|
||||
/** @deprecated Use `constants.Z_ERRNO` */
|
||||
const Z_ERRNO: number;
|
||||
/** @deprecated Use `constants.Z_STREAM_ERROR` */
|
||||
const Z_STREAM_ERROR: number;
|
||||
/** @deprecated Use `constants.Z_DATA_ERROR` */
|
||||
const Z_DATA_ERROR: number;
|
||||
/** @deprecated Use `constants.Z_MEM_ERROR` */
|
||||
const Z_MEM_ERROR: number;
|
||||
/** @deprecated Use `constants.Z_BUF_ERROR` */
|
||||
const Z_BUF_ERROR: number;
|
||||
/** @deprecated Use `constants.Z_VERSION_ERROR` */
|
||||
const Z_VERSION_ERROR: number;
|
||||
|
||||
// Compression levels.
|
||||
/** @deprecated Use `constants.Z_NO_COMPRESSION` */
|
||||
const Z_NO_COMPRESSION: number;
|
||||
/** @deprecated Use `constants.Z_BEST_SPEED` */
|
||||
const Z_BEST_SPEED: number;
|
||||
/** @deprecated Use `constants.Z_BEST_COMPRESSION` */
|
||||
const Z_BEST_COMPRESSION: number;
|
||||
/** @deprecated Use `constants.Z_DEFAULT_COMPRESSION` */
|
||||
const Z_DEFAULT_COMPRESSION: number;
|
||||
|
||||
// Compression strategy.
|
||||
/** @deprecated Use `constants.Z_FILTERED` */
|
||||
const Z_FILTERED: number;
|
||||
/** @deprecated Use `constants.Z_HUFFMAN_ONLY` */
|
||||
const Z_HUFFMAN_ONLY: number;
|
||||
/** @deprecated Use `constants.Z_RLE` */
|
||||
const Z_RLE: number;
|
||||
/** @deprecated Use `constants.Z_FIXED` */
|
||||
const Z_FIXED: number;
|
||||
/** @deprecated Use `constants.Z_DEFAULT_STRATEGY` */
|
||||
const Z_DEFAULT_STRATEGY: number;
|
||||
|
||||
/** @deprecated */
|
||||
const Z_BINARY: number;
|
||||
/** @deprecated */
|
||||
const Z_TEXT: number;
|
||||
/** @deprecated */
|
||||
const Z_ASCII: number;
|
||||
/** @deprecated */
|
||||
const Z_UNKNOWN: number;
|
||||
/** @deprecated */
|
||||
const Z_DEFLATED: number;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
export function parse(source: string): string[];
|
||||
export function parse<T>(source: string, transform: (value: string) => T): T[];
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
|
||||
// @ts-ignore `lightningcss` may not be installed
|
||||
import type Lightningcss from 'lightningcss'
|
||||
|
||||
/* eslint-enable @typescript-eslint/ban-ts-comment */
|
||||
|
||||
export type LightningCSSOptions = Omit<
|
||||
Lightningcss.BundleAsyncOptions<Lightningcss.CustomAtRules>,
|
||||
| 'filename'
|
||||
| 'resolver'
|
||||
| 'minify'
|
||||
| 'sourceMap'
|
||||
| 'analyzeDependencies'
|
||||
// properties not overridden by Vite, but does not make sense to set by end users
|
||||
| 'inputSourceMap'
|
||||
| 'projectRoot'
|
||||
>
|
||||
@@ -0,0 +1,75 @@
|
||||
{
|
||||
"name": "minimist",
|
||||
"version": "1.2.8",
|
||||
"description": "parse argument options",
|
||||
"main": "index.js",
|
||||
"devDependencies": {
|
||||
"@ljharb/eslint-config": "^21.0.1",
|
||||
"aud": "^2.0.2",
|
||||
"auto-changelog": "^2.4.0",
|
||||
"eslint": "=8.8.0",
|
||||
"in-publish": "^2.0.1",
|
||||
"npmignore": "^0.3.0",
|
||||
"nyc": "^10.3.2",
|
||||
"safe-publish-latest": "^2.0.0",
|
||||
"tape": "^5.6.3"
|
||||
},
|
||||
"scripts": {
|
||||
"prepack": "npmignore --auto --commentLines=auto",
|
||||
"prepublishOnly": "safe-publish-latest",
|
||||
"prepublish": "not-in-publish || npm run prepublishOnly",
|
||||
"lint": "eslint --ext=js,mjs .",
|
||||
"pretest": "npm run lint",
|
||||
"tests-only": "nyc tape 'test/**/*.js'",
|
||||
"test": "npm run tests-only",
|
||||
"posttest": "aud --production",
|
||||
"version": "auto-changelog && git add CHANGELOG.md",
|
||||
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
|
||||
},
|
||||
"testling": {
|
||||
"files": "test/*.js",
|
||||
"browsers": [
|
||||
"ie/6..latest",
|
||||
"ff/5",
|
||||
"firefox/latest",
|
||||
"chrome/10",
|
||||
"chrome/latest",
|
||||
"safari/5.1",
|
||||
"safari/latest",
|
||||
"opera/12"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/minimistjs/minimist.git"
|
||||
},
|
||||
"homepage": "https://github.com/minimistjs/minimist",
|
||||
"keywords": [
|
||||
"argv",
|
||||
"getopt",
|
||||
"parser",
|
||||
"optimist"
|
||||
],
|
||||
"author": {
|
||||
"name": "James Halliday",
|
||||
"email": "mail@substack.net",
|
||||
"url": "http://substack.net"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
},
|
||||
"license": "MIT",
|
||||
"auto-changelog": {
|
||||
"output": "CHANGELOG.md",
|
||||
"template": "keepachangelog",
|
||||
"unreleased": false,
|
||||
"commitLimit": false,
|
||||
"backfillLimit": false,
|
||||
"hideCredit": true
|
||||
},
|
||||
"publishConfig": {
|
||||
"ignore": [
|
||||
".github/workflows"
|
||||
]
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,73 @@
|
||||
function _using_ctx() {
|
||||
var _disposeSuppressedError = typeof SuppressedError === "function"
|
||||
// eslint-disable-next-line no-undef
|
||||
? SuppressedError
|
||||
: (function(error, suppressed) {
|
||||
var err = new Error();
|
||||
err.name = "SuppressedError";
|
||||
err.suppressed = suppressed;
|
||||
err.error = error;
|
||||
return err;
|
||||
}),
|
||||
empty = {},
|
||||
stack = [];
|
||||
function using(isAwait, value) {
|
||||
if (value != null) {
|
||||
if (Object(value) !== value) {
|
||||
throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
||||
}
|
||||
// core-js-pure uses Symbol.for for polyfilling well-known symbols
|
||||
if (isAwait) {
|
||||
var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
|
||||
}
|
||||
if (dispose == null) {
|
||||
dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
|
||||
}
|
||||
if (typeof dispose !== "function") {
|
||||
throw new TypeError(`Property [Symbol.dispose] is not a function.`);
|
||||
}
|
||||
stack.push({ v: value, d: dispose, a: isAwait });
|
||||
} else if (isAwait) {
|
||||
// provide the nullish `value` as `d` for minification gain
|
||||
stack.push({ d: value, a: isAwait });
|
||||
}
|
||||
return value;
|
||||
}
|
||||
return {
|
||||
// error
|
||||
e: empty,
|
||||
// using
|
||||
u: using.bind(null, false),
|
||||
// await using
|
||||
a: using.bind(null, true),
|
||||
// dispose
|
||||
d: function() {
|
||||
var error = this.e;
|
||||
|
||||
function next() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
while ((resource = stack.pop())) {
|
||||
try {
|
||||
var resource, disposalResult = resource.d && resource.d.call(resource.v);
|
||||
if (resource.a) {
|
||||
return Promise.resolve(disposalResult).then(next, err);
|
||||
}
|
||||
} catch (e) {
|
||||
return err(e);
|
||||
}
|
||||
}
|
||||
if (error !== empty) throw error;
|
||||
}
|
||||
|
||||
function err(e) {
|
||||
error = error !== empty ? new _disposeSuppressedError(e, error) : e;
|
||||
|
||||
return next();
|
||||
}
|
||||
|
||||
return next();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export { _using_ctx as _ };
|
||||
@@ -0,0 +1,48 @@
|
||||
// @ts-ignore TS6133
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
import * as z from "zod/v3";
|
||||
import { util } from "../helpers/util.js";
|
||||
|
||||
test("generics", () => {
|
||||
async function stripOuter<TData extends z.ZodTypeAny>(schema: TData, data: unknown) {
|
||||
return z
|
||||
.object({
|
||||
nested: schema, // as z.ZodTypeAny,
|
||||
})
|
||||
.transform((data) => {
|
||||
return data.nested!;
|
||||
})
|
||||
.parse({ nested: data });
|
||||
}
|
||||
|
||||
const result = stripOuter(z.object({ a: z.string() }), { a: "asdf" });
|
||||
util.assertEqual<typeof result, Promise<{ a: string }>>(true);
|
||||
});
|
||||
|
||||
// test("assignability", () => {
|
||||
// const createSchemaAndParse = <K extends string, VS extends z.ZodString>(
|
||||
// key: K,
|
||||
// valueSchema: VS,
|
||||
// data: unknown
|
||||
// ) => {
|
||||
// const schema = z.object({
|
||||
// [key]: valueSchema,
|
||||
// } as { [k in K]: VS });
|
||||
// return { [key]: valueSchema };
|
||||
// const parsed = schema.parse(data);
|
||||
// return parsed;
|
||||
// // const inferred: z.infer<z.ZodObject<{ [k in K]: VS }>> = parsed;
|
||||
// // return inferred;
|
||||
// };
|
||||
// const parsed = createSchemaAndParse("foo", z.string(), { foo: "" });
|
||||
// util.assertEqual<typeof parsed, { foo: string }>(true);
|
||||
// });
|
||||
|
||||
test("nested no undefined", () => {
|
||||
const inner = z.string().or(z.array(z.string()));
|
||||
const outer = z.object({ inner });
|
||||
type outerSchema = z.infer<typeof outer>;
|
||||
z.util.assertEqual<outerSchema, { inner: string | string[] }>(true);
|
||||
expect(outer.safeParse({ inner: undefined }).success).toEqual(false);
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
## Unreleased
|
||||
- Fixes stringify to only take ancestors into account when checking
|
||||
circularity.
|
||||
It previously assumed every visited object was circular which led to [false
|
||||
positives][issue9].
|
||||
Uses the tiny serializer I wrote for [Must.js][must] a year and a half ago.
|
||||
- Fixes calling the `replacer` function in the proper context (`thisArg`).
|
||||
- Fixes calling the `cycleReplacer` function in the proper context (`thisArg`).
|
||||
- Speeds serializing by a factor of
|
||||
Big-O(h-my-god-it-linearly-searched-every-object) it had ever seen. Searching
|
||||
only the ancestors for a circular references speeds up things considerably.
|
||||
|
||||
[must]: https://github.com/moll/js-must
|
||||
[issue9]: https://github.com/isaacs/json-stringify-safe/issues/9
|
||||
@@ -0,0 +1,599 @@
|
||||
import { globalRegistry } from "../core/registries.js";
|
||||
import * as _checks from "./checks.js";
|
||||
import * as _iso from "./iso.js";
|
||||
import * as _schemas from "./schemas.js";
|
||||
// Local z object to avoid circular dependency with ../index.js
|
||||
const z = {
|
||||
..._schemas,
|
||||
..._checks,
|
||||
iso: _iso,
|
||||
};
|
||||
// Keys that are recognized and handled by the conversion logic
|
||||
const RECOGNIZED_KEYS = /*@__PURE__*/ new Set([
|
||||
// Schema identification
|
||||
"$schema",
|
||||
"$ref",
|
||||
"$defs",
|
||||
"definitions",
|
||||
// Core schema keywords
|
||||
"$id",
|
||||
"id",
|
||||
"$comment",
|
||||
"$anchor",
|
||||
"$vocabulary",
|
||||
"$dynamicRef",
|
||||
"$dynamicAnchor",
|
||||
// Type
|
||||
"type",
|
||||
"enum",
|
||||
"const",
|
||||
// Composition
|
||||
"anyOf",
|
||||
"oneOf",
|
||||
"allOf",
|
||||
"not",
|
||||
// Object
|
||||
"properties",
|
||||
"required",
|
||||
"additionalProperties",
|
||||
"patternProperties",
|
||||
"propertyNames",
|
||||
"minProperties",
|
||||
"maxProperties",
|
||||
// Array
|
||||
"items",
|
||||
"prefixItems",
|
||||
"additionalItems",
|
||||
"minItems",
|
||||
"maxItems",
|
||||
"uniqueItems",
|
||||
"contains",
|
||||
"minContains",
|
||||
"maxContains",
|
||||
// String
|
||||
"minLength",
|
||||
"maxLength",
|
||||
"pattern",
|
||||
"format",
|
||||
// Number
|
||||
"minimum",
|
||||
"maximum",
|
||||
"exclusiveMinimum",
|
||||
"exclusiveMaximum",
|
||||
"multipleOf",
|
||||
// Already handled metadata
|
||||
"description",
|
||||
"default",
|
||||
// Content
|
||||
"contentEncoding",
|
||||
"contentMediaType",
|
||||
"contentSchema",
|
||||
// Unsupported (error-throwing)
|
||||
"unevaluatedItems",
|
||||
"unevaluatedProperties",
|
||||
"if",
|
||||
"then",
|
||||
"else",
|
||||
"dependentSchemas",
|
||||
"dependentRequired",
|
||||
// OpenAPI
|
||||
"nullable",
|
||||
"readOnly",
|
||||
]);
|
||||
function detectVersion(schema, defaultTarget) {
|
||||
const $schema = schema.$schema;
|
||||
if ($schema === "https://json-schema.org/draft/2020-12/schema") {
|
||||
return "draft-2020-12";
|
||||
}
|
||||
if ($schema === "http://json-schema.org/draft-07/schema#") {
|
||||
return "draft-7";
|
||||
}
|
||||
if ($schema === "http://json-schema.org/draft-04/schema#") {
|
||||
return "draft-4";
|
||||
}
|
||||
// Use defaultTarget if provided, otherwise default to draft-2020-12
|
||||
return defaultTarget ?? "draft-2020-12";
|
||||
}
|
||||
function resolveRef(ref, ctx) {
|
||||
if (!ref.startsWith("#")) {
|
||||
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
||||
}
|
||||
const path = ref.slice(1).split("/").filter(Boolean);
|
||||
// Handle root reference "#"
|
||||
if (path.length === 0) {
|
||||
return ctx.rootSchema;
|
||||
}
|
||||
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
||||
if (path[0] === defsKey) {
|
||||
const key = path[1];
|
||||
if (!key || !ctx.defs[key]) {
|
||||
throw new Error(`Reference not found: ${ref}`);
|
||||
}
|
||||
return ctx.defs[key];
|
||||
}
|
||||
throw new Error(`Reference not found: ${ref}`);
|
||||
}
|
||||
function convertBaseSchema(schema, ctx) {
|
||||
// Handle unsupported features
|
||||
if (schema.not !== undefined) {
|
||||
// Special case: { not: {} } represents never
|
||||
if (typeof schema.not === "object" && Object.keys(schema.not).length === 0) {
|
||||
return z.never();
|
||||
}
|
||||
throw new Error("not is not supported in Zod (except { not: {} } for never)");
|
||||
}
|
||||
if (schema.unevaluatedItems !== undefined) {
|
||||
throw new Error("unevaluatedItems is not supported");
|
||||
}
|
||||
if (schema.unevaluatedProperties !== undefined) {
|
||||
throw new Error("unevaluatedProperties is not supported");
|
||||
}
|
||||
if (schema.if !== undefined || schema.then !== undefined || schema.else !== undefined) {
|
||||
throw new Error("Conditional schemas (if/then/else) are not supported");
|
||||
}
|
||||
if (schema.dependentSchemas !== undefined || schema.dependentRequired !== undefined) {
|
||||
throw new Error("dependentSchemas and dependentRequired are not supported");
|
||||
}
|
||||
// Handle $ref
|
||||
if (schema.$ref) {
|
||||
const refPath = schema.$ref;
|
||||
if (ctx.refs.has(refPath)) {
|
||||
return ctx.refs.get(refPath);
|
||||
}
|
||||
if (ctx.processing.has(refPath)) {
|
||||
// Circular reference - use lazy
|
||||
return z.lazy(() => {
|
||||
if (!ctx.refs.has(refPath)) {
|
||||
throw new Error(`Circular reference not resolved: ${refPath}`);
|
||||
}
|
||||
return ctx.refs.get(refPath);
|
||||
});
|
||||
}
|
||||
ctx.processing.add(refPath);
|
||||
const resolved = resolveRef(refPath, ctx);
|
||||
const zodSchema = convertSchema(resolved, ctx);
|
||||
ctx.refs.set(refPath, zodSchema);
|
||||
ctx.processing.delete(refPath);
|
||||
return zodSchema;
|
||||
}
|
||||
// Handle enum
|
||||
if (schema.enum !== undefined) {
|
||||
const enumValues = schema.enum;
|
||||
// Special case: OpenAPI 3.0 null representation { type: "string", nullable: true, enum: [null] }
|
||||
if (ctx.version === "openapi-3.0" &&
|
||||
schema.nullable === true &&
|
||||
enumValues.length === 1 &&
|
||||
enumValues[0] === null) {
|
||||
return z.null();
|
||||
}
|
||||
if (enumValues.length === 0) {
|
||||
return z.never();
|
||||
}
|
||||
if (enumValues.length === 1) {
|
||||
return z.literal(enumValues[0]);
|
||||
}
|
||||
// Check if all values are strings
|
||||
if (enumValues.every((v) => typeof v === "string")) {
|
||||
return z.enum(enumValues);
|
||||
}
|
||||
// Mixed types - use union of literals
|
||||
const literalSchemas = enumValues.map((v) => z.literal(v));
|
||||
if (literalSchemas.length < 2) {
|
||||
return literalSchemas[0];
|
||||
}
|
||||
return z.union([literalSchemas[0], literalSchemas[1], ...literalSchemas.slice(2)]);
|
||||
}
|
||||
// Handle const
|
||||
if (schema.const !== undefined) {
|
||||
return z.literal(schema.const);
|
||||
}
|
||||
// Handle type
|
||||
const type = schema.type;
|
||||
if (Array.isArray(type)) {
|
||||
// Expand type array into anyOf union
|
||||
const typeSchemas = type.map((t) => {
|
||||
const typeSchema = { ...schema, type: t };
|
||||
return convertBaseSchema(typeSchema, ctx);
|
||||
});
|
||||
if (typeSchemas.length === 0) {
|
||||
return z.never();
|
||||
}
|
||||
if (typeSchemas.length === 1) {
|
||||
return typeSchemas[0];
|
||||
}
|
||||
return z.union(typeSchemas);
|
||||
}
|
||||
if (!type) {
|
||||
// No type specified - empty schema (any)
|
||||
return z.any();
|
||||
}
|
||||
let zodSchema;
|
||||
switch (type) {
|
||||
case "string": {
|
||||
let stringSchema = z.string();
|
||||
// Apply format using .check() with Zod format functions
|
||||
if (schema.format) {
|
||||
const format = schema.format;
|
||||
// Map common formats to Zod check functions
|
||||
if (format === "email") {
|
||||
stringSchema = stringSchema.check(z.email());
|
||||
}
|
||||
else if (format === "uri" || format === "uri-reference") {
|
||||
stringSchema = stringSchema.check(z.url());
|
||||
}
|
||||
else if (format === "uuid" || format === "guid") {
|
||||
stringSchema = stringSchema.check(z.uuid());
|
||||
}
|
||||
else if (format === "date-time") {
|
||||
stringSchema = stringSchema.check(z.iso.datetime());
|
||||
}
|
||||
else if (format === "date") {
|
||||
stringSchema = stringSchema.check(z.iso.date());
|
||||
}
|
||||
else if (format === "time") {
|
||||
stringSchema = stringSchema.check(z.iso.time());
|
||||
}
|
||||
else if (format === "duration") {
|
||||
stringSchema = stringSchema.check(z.iso.duration());
|
||||
}
|
||||
else if (format === "ipv4") {
|
||||
stringSchema = stringSchema.check(z.ipv4());
|
||||
}
|
||||
else if (format === "ipv6") {
|
||||
stringSchema = stringSchema.check(z.ipv6());
|
||||
}
|
||||
else if (format === "mac") {
|
||||
stringSchema = stringSchema.check(z.mac());
|
||||
}
|
||||
else if (format === "cidr") {
|
||||
stringSchema = stringSchema.check(z.cidrv4());
|
||||
}
|
||||
else if (format === "cidr-v6") {
|
||||
stringSchema = stringSchema.check(z.cidrv6());
|
||||
}
|
||||
else if (format === "base64") {
|
||||
stringSchema = stringSchema.check(z.base64());
|
||||
}
|
||||
else if (format === "base64url") {
|
||||
stringSchema = stringSchema.check(z.base64url());
|
||||
}
|
||||
else if (format === "e164") {
|
||||
stringSchema = stringSchema.check(z.e164());
|
||||
}
|
||||
else if (format === "jwt") {
|
||||
stringSchema = stringSchema.check(z.jwt());
|
||||
}
|
||||
else if (format === "emoji") {
|
||||
stringSchema = stringSchema.check(z.emoji());
|
||||
}
|
||||
else if (format === "nanoid") {
|
||||
stringSchema = stringSchema.check(z.nanoid());
|
||||
}
|
||||
else if (format === "cuid") {
|
||||
stringSchema = stringSchema.check(z.cuid());
|
||||
}
|
||||
else if (format === "cuid2") {
|
||||
stringSchema = stringSchema.check(z.cuid2());
|
||||
}
|
||||
else if (format === "ulid") {
|
||||
stringSchema = stringSchema.check(z.ulid());
|
||||
}
|
||||
else if (format === "xid") {
|
||||
stringSchema = stringSchema.check(z.xid());
|
||||
}
|
||||
else if (format === "ksuid") {
|
||||
stringSchema = stringSchema.check(z.ksuid());
|
||||
}
|
||||
// Note: json-string format is not currently supported by Zod
|
||||
// Custom formats are ignored - keep as plain string
|
||||
}
|
||||
// Apply constraints
|
||||
if (typeof schema.minLength === "number") {
|
||||
stringSchema = stringSchema.min(schema.minLength);
|
||||
}
|
||||
if (typeof schema.maxLength === "number") {
|
||||
stringSchema = stringSchema.max(schema.maxLength);
|
||||
}
|
||||
if (schema.pattern) {
|
||||
// JSON Schema patterns are not implicitly anchored (match anywhere in string)
|
||||
stringSchema = stringSchema.regex(new RegExp(schema.pattern));
|
||||
}
|
||||
zodSchema = stringSchema;
|
||||
break;
|
||||
}
|
||||
case "number":
|
||||
case "integer": {
|
||||
let numberSchema = type === "integer" ? z.number().int() : z.number();
|
||||
// Apply constraints
|
||||
if (typeof schema.minimum === "number") {
|
||||
numberSchema = numberSchema.min(schema.minimum);
|
||||
}
|
||||
if (typeof schema.maximum === "number") {
|
||||
numberSchema = numberSchema.max(schema.maximum);
|
||||
}
|
||||
if (typeof schema.exclusiveMinimum === "number") {
|
||||
numberSchema = numberSchema.gt(schema.exclusiveMinimum);
|
||||
}
|
||||
else if (schema.exclusiveMinimum === true && typeof schema.minimum === "number") {
|
||||
numberSchema = numberSchema.gt(schema.minimum);
|
||||
}
|
||||
if (typeof schema.exclusiveMaximum === "number") {
|
||||
numberSchema = numberSchema.lt(schema.exclusiveMaximum);
|
||||
}
|
||||
else if (schema.exclusiveMaximum === true && typeof schema.maximum === "number") {
|
||||
numberSchema = numberSchema.lt(schema.maximum);
|
||||
}
|
||||
if (typeof schema.multipleOf === "number") {
|
||||
numberSchema = numberSchema.multipleOf(schema.multipleOf);
|
||||
}
|
||||
zodSchema = numberSchema;
|
||||
break;
|
||||
}
|
||||
case "boolean": {
|
||||
zodSchema = z.boolean();
|
||||
break;
|
||||
}
|
||||
case "null": {
|
||||
zodSchema = z.null();
|
||||
break;
|
||||
}
|
||||
case "object": {
|
||||
const shape = {};
|
||||
const properties = schema.properties || {};
|
||||
const requiredSet = new Set(schema.required || []);
|
||||
// Convert properties - mark optional ones
|
||||
for (const [key, propSchema] of Object.entries(properties)) {
|
||||
const propZodSchema = convertSchema(propSchema, ctx);
|
||||
// If not in required array, make it optional
|
||||
shape[key] = requiredSet.has(key) ? propZodSchema : propZodSchema.optional();
|
||||
}
|
||||
// Handle propertyNames
|
||||
if (schema.propertyNames) {
|
||||
const keySchema = convertSchema(schema.propertyNames, ctx);
|
||||
const valueSchema = schema.additionalProperties && typeof schema.additionalProperties === "object"
|
||||
? convertSchema(schema.additionalProperties, ctx)
|
||||
: z.any();
|
||||
// Case A: No properties (pure record)
|
||||
if (Object.keys(shape).length === 0) {
|
||||
zodSchema = z.record(keySchema, valueSchema);
|
||||
break;
|
||||
}
|
||||
// Case B: With properties (intersection of object and looseRecord)
|
||||
const objectSchema = z.object(shape).passthrough();
|
||||
const recordSchema = z.looseRecord(keySchema, valueSchema);
|
||||
zodSchema = z.intersection(objectSchema, recordSchema);
|
||||
break;
|
||||
}
|
||||
// Handle patternProperties
|
||||
if (schema.patternProperties) {
|
||||
// patternProperties: keys matching pattern must satisfy corresponding schema
|
||||
// Use loose records so non-matching keys pass through
|
||||
const patternProps = schema.patternProperties;
|
||||
const patternKeys = Object.keys(patternProps);
|
||||
const looseRecords = [];
|
||||
for (const pattern of patternKeys) {
|
||||
const patternValue = convertSchema(patternProps[pattern], ctx);
|
||||
const keySchema = z.string().regex(new RegExp(pattern));
|
||||
looseRecords.push(z.looseRecord(keySchema, patternValue));
|
||||
}
|
||||
// Build intersection: object schema + all pattern property records
|
||||
const schemasToIntersect = [];
|
||||
if (Object.keys(shape).length > 0) {
|
||||
// Use passthrough so patternProperties can validate additional keys
|
||||
schemasToIntersect.push(z.object(shape).passthrough());
|
||||
}
|
||||
schemasToIntersect.push(...looseRecords);
|
||||
if (schemasToIntersect.length === 0) {
|
||||
zodSchema = z.object({}).passthrough();
|
||||
}
|
||||
else if (schemasToIntersect.length === 1) {
|
||||
zodSchema = schemasToIntersect[0];
|
||||
}
|
||||
else {
|
||||
// Chain intersections: (A & B) & C & D ...
|
||||
let result = z.intersection(schemasToIntersect[0], schemasToIntersect[1]);
|
||||
for (let i = 2; i < schemasToIntersect.length; i++) {
|
||||
result = z.intersection(result, schemasToIntersect[i]);
|
||||
}
|
||||
zodSchema = result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Handle additionalProperties
|
||||
// In JSON Schema, additionalProperties defaults to true (allow any extra properties)
|
||||
// In Zod, objects strip unknown keys by default, so we need to handle this explicitly
|
||||
const objectSchema = z.object(shape);
|
||||
if (schema.additionalProperties === false) {
|
||||
// Strict mode - no extra properties allowed
|
||||
zodSchema = objectSchema.strict();
|
||||
}
|
||||
else if (typeof schema.additionalProperties === "object") {
|
||||
// Extra properties must match the specified schema
|
||||
zodSchema = objectSchema.catchall(convertSchema(schema.additionalProperties, ctx));
|
||||
}
|
||||
else {
|
||||
// additionalProperties is true or undefined - allow any extra properties (passthrough)
|
||||
zodSchema = objectSchema.passthrough();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "array": {
|
||||
// TODO: uniqueItems is not supported
|
||||
// TODO: contains/minContains/maxContains are not supported
|
||||
// Check if this is a tuple (prefixItems or items as array)
|
||||
const prefixItems = schema.prefixItems;
|
||||
const items = schema.items;
|
||||
if (prefixItems && Array.isArray(prefixItems)) {
|
||||
// Tuple with prefixItems (draft-2020-12)
|
||||
const tupleItems = prefixItems.map((item) => convertSchema(item, ctx));
|
||||
const rest = items && typeof items === "object" && !Array.isArray(items)
|
||||
? convertSchema(items, ctx)
|
||||
: undefined;
|
||||
if (rest) {
|
||||
zodSchema = z.tuple(tupleItems).rest(rest);
|
||||
}
|
||||
else {
|
||||
zodSchema = z.tuple(tupleItems);
|
||||
}
|
||||
// Apply minItems/maxItems constraints to tuples
|
||||
if (typeof schema.minItems === "number") {
|
||||
zodSchema = zodSchema.check(z.minLength(schema.minItems));
|
||||
}
|
||||
if (typeof schema.maxItems === "number") {
|
||||
zodSchema = zodSchema.check(z.maxLength(schema.maxItems));
|
||||
}
|
||||
}
|
||||
else if (Array.isArray(items)) {
|
||||
// Tuple with items array (draft-7)
|
||||
const tupleItems = items.map((item) => convertSchema(item, ctx));
|
||||
const rest = schema.additionalItems && typeof schema.additionalItems === "object"
|
||||
? convertSchema(schema.additionalItems, ctx)
|
||||
: undefined; // additionalItems: false means no rest, handled by default tuple behavior
|
||||
if (rest) {
|
||||
zodSchema = z.tuple(tupleItems).rest(rest);
|
||||
}
|
||||
else {
|
||||
zodSchema = z.tuple(tupleItems);
|
||||
}
|
||||
// Apply minItems/maxItems constraints to tuples
|
||||
if (typeof schema.minItems === "number") {
|
||||
zodSchema = zodSchema.check(z.minLength(schema.minItems));
|
||||
}
|
||||
if (typeof schema.maxItems === "number") {
|
||||
zodSchema = zodSchema.check(z.maxLength(schema.maxItems));
|
||||
}
|
||||
}
|
||||
else if (items !== undefined) {
|
||||
// Regular array
|
||||
const element = convertSchema(items, ctx);
|
||||
let arraySchema = z.array(element);
|
||||
// Apply constraints
|
||||
if (typeof schema.minItems === "number") {
|
||||
arraySchema = arraySchema.min(schema.minItems);
|
||||
}
|
||||
if (typeof schema.maxItems === "number") {
|
||||
arraySchema = arraySchema.max(schema.maxItems);
|
||||
}
|
||||
zodSchema = arraySchema;
|
||||
}
|
||||
else {
|
||||
// No items specified - array of any
|
||||
zodSchema = z.array(z.any());
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unsupported type: ${type}`);
|
||||
}
|
||||
return zodSchema;
|
||||
}
|
||||
function convertSchema(schema, ctx) {
|
||||
if (typeof schema === "boolean") {
|
||||
return schema ? z.any() : z.never();
|
||||
}
|
||||
// Convert base schema first (ignoring composition keywords)
|
||||
let baseSchema = convertBaseSchema(schema, ctx);
|
||||
const hasExplicitType = schema.type || schema.enum !== undefined || schema.const !== undefined;
|
||||
// Process composition keywords LAST (they can appear together)
|
||||
// Handle anyOf - wrap base schema with union
|
||||
if (schema.anyOf && Array.isArray(schema.anyOf)) {
|
||||
const options = schema.anyOf.map((s) => convertSchema(s, ctx));
|
||||
const anyOfUnion = z.union(options);
|
||||
baseSchema = hasExplicitType ? z.intersection(baseSchema, anyOfUnion) : anyOfUnion;
|
||||
}
|
||||
// Handle oneOf - exclusive union (exactly one must match)
|
||||
if (schema.oneOf && Array.isArray(schema.oneOf)) {
|
||||
const options = schema.oneOf.map((s) => convertSchema(s, ctx));
|
||||
const oneOfUnion = z.xor(options);
|
||||
baseSchema = hasExplicitType ? z.intersection(baseSchema, oneOfUnion) : oneOfUnion;
|
||||
}
|
||||
// Handle allOf - wrap base schema with intersection
|
||||
if (schema.allOf && Array.isArray(schema.allOf)) {
|
||||
if (schema.allOf.length === 0) {
|
||||
baseSchema = hasExplicitType ? baseSchema : z.any();
|
||||
}
|
||||
else {
|
||||
let result = hasExplicitType ? baseSchema : convertSchema(schema.allOf[0], ctx);
|
||||
const startIdx = hasExplicitType ? 0 : 1;
|
||||
for (let i = startIdx; i < schema.allOf.length; i++) {
|
||||
result = z.intersection(result, convertSchema(schema.allOf[i], ctx));
|
||||
}
|
||||
baseSchema = result;
|
||||
}
|
||||
}
|
||||
// Handle nullable (OpenAPI 3.0)
|
||||
if (schema.nullable === true && ctx.version === "openapi-3.0") {
|
||||
baseSchema = z.nullable(baseSchema);
|
||||
}
|
||||
// Handle readOnly
|
||||
if (schema.readOnly === true) {
|
||||
baseSchema = z.readonly(baseSchema);
|
||||
}
|
||||
// Apply `default` so it wraps the fully-composed schema. This ensures
|
||||
// `parse(undefined) -> default` works regardless of which branch of
|
||||
// `convertBaseSchema` produced the inner schema (enum/const/not/typed/etc.).
|
||||
if (schema.default !== undefined) {
|
||||
baseSchema = baseSchema.default(schema.default);
|
||||
}
|
||||
// Collect non-description annotation metadata into the user-supplied
|
||||
// registry. Description is handled separately below via `.describe()` to
|
||||
// preserve the contract that `schema.description` reads from globalRegistry.
|
||||
const extraMeta = {};
|
||||
const coreMetadataKeys = ["$id", "id", "$comment", "$anchor", "$vocabulary", "$dynamicRef", "$dynamicAnchor"];
|
||||
for (const key of coreMetadataKeys) {
|
||||
if (key in schema) {
|
||||
extraMeta[key] = schema[key];
|
||||
}
|
||||
}
|
||||
const contentMetadataKeys = ["contentEncoding", "contentMediaType", "contentSchema"];
|
||||
for (const key of contentMetadataKeys) {
|
||||
if (key in schema) {
|
||||
extraMeta[key] = schema[key];
|
||||
}
|
||||
}
|
||||
for (const key of Object.keys(schema)) {
|
||||
if (!RECOGNIZED_KEYS.has(key)) {
|
||||
extraMeta[key] = schema[key];
|
||||
}
|
||||
}
|
||||
if (Object.keys(extraMeta).length > 0) {
|
||||
ctx.registry.add(baseSchema, extraMeta);
|
||||
}
|
||||
// Apply description last. `.describe()` clones the schema and sets
|
||||
// `_zod.parent` on the clone, so registry lookups on the returned reference
|
||||
// still resolve `extraMeta` via parent inheritance.
|
||||
if (schema.description) {
|
||||
baseSchema = baseSchema.describe(schema.description);
|
||||
}
|
||||
return baseSchema;
|
||||
}
|
||||
/**
|
||||
* Converts a JSON Schema to a Zod schema. This function should be considered semi-experimental. It's behavior is liable to change. */
|
||||
export function fromJSONSchema(schema, params) {
|
||||
// Handle boolean schemas
|
||||
if (typeof schema === "boolean") {
|
||||
return schema ? z.any() : z.never();
|
||||
}
|
||||
// Normalize input via a JSON round-trip. This guarantees the converter
|
||||
// walks a plain, finite, JSON-valid object graph: cyclic inputs fail here,
|
||||
// getter/Proxy-based properties are materialized into static values, and
|
||||
// class instances collapse to plain objects.
|
||||
let normalized;
|
||||
try {
|
||||
normalized = JSON.parse(JSON.stringify(schema));
|
||||
}
|
||||
catch {
|
||||
throw new Error("fromJSONSchema input is not valid JSON (possibly cyclic); use $defs/$ref for recursive schemas");
|
||||
}
|
||||
const version = detectVersion(normalized, params?.defaultTarget);
|
||||
const defs = (normalized.$defs || normalized.definitions || {});
|
||||
const ctx = {
|
||||
version,
|
||||
defs,
|
||||
refs: new Map(),
|
||||
processing: new Set(),
|
||||
rootSchema: normalized,
|
||||
registry: params?.registry ?? globalRegistry,
|
||||
};
|
||||
return convertSchema(normalized, ctx);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import {Buffer} from 'buffer';
|
||||
|
||||
export const toBuffer = (arr: Buffer | Uint8Array | Array<number>): Buffer => {
|
||||
if (Buffer.isBuffer(arr)) {
|
||||
return arr;
|
||||
} else if (arr instanceof Uint8Array) {
|
||||
return Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
|
||||
} else {
|
||||
return Buffer.from(arr);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
<script src="tslib.es6.js"></script>
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,18 @@
|
||||
Copyright 2022 The is_utf8 authors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Jameson Little
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,89 @@
|
||||
{
|
||||
"name": "node-fetch",
|
||||
"version": "2.7.0",
|
||||
"description": "A light-weight module that brings window.fetch to node.js",
|
||||
"main": "lib/index.js",
|
||||
"browser": "./browser.js",
|
||||
"module": "lib/index.mjs",
|
||||
"files": [
|
||||
"lib/index.js",
|
||||
"lib/index.mjs",
|
||||
"lib/index.es.js",
|
||||
"browser.js"
|
||||
],
|
||||
"engines": {
|
||||
"node": "4.x || >=6.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "cross-env BABEL_ENV=rollup rollup -c",
|
||||
"prepare": "npm run build",
|
||||
"test": "cross-env BABEL_ENV=test mocha --require babel-register --throw-deprecation test/test.js",
|
||||
"report": "cross-env BABEL_ENV=coverage nyc --reporter lcov --reporter text mocha -R spec test/test.js",
|
||||
"coverage": "cross-env BABEL_ENV=coverage nyc --reporter json --reporter text mocha -R spec test/test.js && codecov -f coverage/coverage-final.json"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/bitinn/node-fetch.git"
|
||||
},
|
||||
"keywords": [
|
||||
"fetch",
|
||||
"http",
|
||||
"promise"
|
||||
],
|
||||
"author": "David Frank",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/bitinn/node-fetch/issues"
|
||||
},
|
||||
"homepage": "https://github.com/bitinn/node-fetch",
|
||||
"dependencies": {
|
||||
"whatwg-url": "^5.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"encoding": "^0.1.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"encoding": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ungap/url-search-params": "^0.1.2",
|
||||
"abort-controller": "^1.1.0",
|
||||
"abortcontroller-polyfill": "^1.3.0",
|
||||
"babel-core": "^6.26.3",
|
||||
"babel-plugin-istanbul": "^4.1.6",
|
||||
"babel-plugin-transform-async-generator-functions": "^6.24.1",
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"babel-preset-env": "1.4.0",
|
||||
"babel-register": "^6.16.3",
|
||||
"chai": "^3.5.0",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
"chai-iterator": "^1.1.1",
|
||||
"chai-string": "~1.3.0",
|
||||
"codecov": "3.3.0",
|
||||
"cross-env": "^5.2.0",
|
||||
"form-data": "^2.3.3",
|
||||
"is-builtin-module": "^1.0.0",
|
||||
"mocha": "^5.0.0",
|
||||
"nyc": "11.9.0",
|
||||
"parted": "^0.1.1",
|
||||
"promise": "^8.0.3",
|
||||
"resumer": "0.0.0",
|
||||
"rollup": "^0.63.4",
|
||||
"rollup-plugin-babel": "^3.0.7",
|
||||
"string-to-arraybuffer": "^1.0.2",
|
||||
"teeny-request": "3.7.0"
|
||||
},
|
||||
"release": {
|
||||
"branches": [
|
||||
"+([0-9]).x",
|
||||
"main",
|
||||
"next",
|
||||
{
|
||||
"name": "beta",
|
||||
"prerelease": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user