WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
function _initializerDefineProperty(e, i, r, l) {
|
||||
r && Object.defineProperty(e, i, {
|
||||
enumerable: r.enumerable,
|
||||
configurable: r.configurable,
|
||||
writable: r.writable,
|
||||
value: r.initializer ? r.initializer.call(l) : void 0
|
||||
});
|
||||
}
|
||||
module.exports = _initializerDefineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
@@ -0,0 +1,4 @@
|
||||
import type * as errors from "../core/errors.js";
|
||||
export default function (): {
|
||||
localeError: errors.$ZodErrorMap;
|
||||
};
|
||||
@@ -0,0 +1,665 @@
|
||||
'use strict';
|
||||
|
||||
// This is free and unencumbered software released into the public domain.
|
||||
// See LICENSE.md for more information.
|
||||
|
||||
//
|
||||
// Utilities
|
||||
//
|
||||
|
||||
/**
|
||||
* @param {number} a The number to test.
|
||||
* @param {number} min The minimum value in the range, inclusive.
|
||||
* @param {number} max The maximum value in the range, inclusive.
|
||||
* @return {boolean} True if a >= min and a <= max.
|
||||
*/
|
||||
function inRange(a, min, max) {
|
||||
return min <= a && a <= max;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} o
|
||||
* @return {Object}
|
||||
*/
|
||||
function ToDictionary(o) {
|
||||
if (o === undefined) return {};
|
||||
if (o === Object(o)) return o;
|
||||
throw TypeError('Could not convert argument to dictionary');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} string Input string of UTF-16 code units.
|
||||
* @return {!Array.<number>} Code points.
|
||||
*/
|
||||
function stringToCodePoints(string) {
|
||||
// https://heycam.github.io/webidl/#dfn-obtain-unicode
|
||||
|
||||
// 1. Let S be the DOMString value.
|
||||
var s = String(string);
|
||||
|
||||
// 2. Let n be the length of S.
|
||||
var n = s.length;
|
||||
|
||||
// 3. Initialize i to 0.
|
||||
var i = 0;
|
||||
|
||||
// 4. Initialize U to be an empty sequence of Unicode characters.
|
||||
var u = [];
|
||||
|
||||
// 5. While i < n:
|
||||
while (i < n) {
|
||||
|
||||
// 1. Let c be the code unit in S at index i.
|
||||
var c = s.charCodeAt(i);
|
||||
|
||||
// 2. Depending on the value of c:
|
||||
|
||||
// c < 0xD800 or c > 0xDFFF
|
||||
if (c < 0xD800 || c > 0xDFFF) {
|
||||
// Append to U the Unicode character with code point c.
|
||||
u.push(c);
|
||||
}
|
||||
|
||||
// 0xDC00 ≤ c ≤ 0xDFFF
|
||||
else if (0xDC00 <= c && c <= 0xDFFF) {
|
||||
// Append to U a U+FFFD REPLACEMENT CHARACTER.
|
||||
u.push(0xFFFD);
|
||||
}
|
||||
|
||||
// 0xD800 ≤ c ≤ 0xDBFF
|
||||
else if (0xD800 <= c && c <= 0xDBFF) {
|
||||
// 1. If i = n−1, then append to U a U+FFFD REPLACEMENT
|
||||
// CHARACTER.
|
||||
if (i === n - 1) {
|
||||
u.push(0xFFFD);
|
||||
}
|
||||
// 2. Otherwise, i < n−1:
|
||||
else {
|
||||
// 1. Let d be the code unit in S at index i+1.
|
||||
var d = string.charCodeAt(i + 1);
|
||||
|
||||
// 2. If 0xDC00 ≤ d ≤ 0xDFFF, then:
|
||||
if (0xDC00 <= d && d <= 0xDFFF) {
|
||||
// 1. Let a be c & 0x3FF.
|
||||
var a = c & 0x3FF;
|
||||
|
||||
// 2. Let b be d & 0x3FF.
|
||||
var b = d & 0x3FF;
|
||||
|
||||
// 3. Append to U the Unicode character with code point
|
||||
// 2^16+2^10*a+b.
|
||||
u.push(0x10000 + (a << 10) + b);
|
||||
|
||||
// 4. Set i to i+1.
|
||||
i += 1;
|
||||
}
|
||||
|
||||
// 3. Otherwise, d < 0xDC00 or d > 0xDFFF. Append to U a
|
||||
// U+FFFD REPLACEMENT CHARACTER.
|
||||
else {
|
||||
u.push(0xFFFD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Set i to i+1.
|
||||
i += 1;
|
||||
}
|
||||
|
||||
// 6. Return U.
|
||||
return u;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Array.<number>} code_points Array of code points.
|
||||
* @return {string} string String of UTF-16 code units.
|
||||
*/
|
||||
function codePointsToString(code_points) {
|
||||
var s = '';
|
||||
for (var i = 0; i < code_points.length; ++i) {
|
||||
var cp = code_points[i];
|
||||
if (cp <= 0xFFFF) {
|
||||
s += String.fromCharCode(cp);
|
||||
} else {
|
||||
cp -= 0x10000;
|
||||
s += String.fromCharCode((cp >> 10) + 0xD800,
|
||||
(cp & 0x3FF) + 0xDC00);
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Implementation of Encoding specification
|
||||
// https://encoding.spec.whatwg.org/
|
||||
//
|
||||
|
||||
//
|
||||
// 3. Terminology
|
||||
//
|
||||
|
||||
/**
|
||||
* End-of-stream is a special token that signifies no more tokens
|
||||
* are in the stream.
|
||||
* @const
|
||||
*/ var end_of_stream = -1;
|
||||
|
||||
/**
|
||||
* A stream represents an ordered sequence of tokens.
|
||||
*
|
||||
* @constructor
|
||||
* @param {!(Array.<number>|Uint8Array)} tokens Array of tokens that provide the
|
||||
* stream.
|
||||
*/
|
||||
function Stream(tokens) {
|
||||
/** @type {!Array.<number>} */
|
||||
this.tokens = [].slice.call(tokens);
|
||||
}
|
||||
|
||||
Stream.prototype = {
|
||||
/**
|
||||
* @return {boolean} True if end-of-stream has been hit.
|
||||
*/
|
||||
endOfStream: function() {
|
||||
return !this.tokens.length;
|
||||
},
|
||||
|
||||
/**
|
||||
* When a token is read from a stream, the first token in the
|
||||
* stream must be returned and subsequently removed, and
|
||||
* end-of-stream must be returned otherwise.
|
||||
*
|
||||
* @return {number} Get the next token from the stream, or
|
||||
* end_of_stream.
|
||||
*/
|
||||
read: function() {
|
||||
if (!this.tokens.length)
|
||||
return end_of_stream;
|
||||
return this.tokens.shift();
|
||||
},
|
||||
|
||||
/**
|
||||
* When one or more tokens are prepended to a stream, those tokens
|
||||
* must be inserted, in given order, before the first token in the
|
||||
* stream.
|
||||
*
|
||||
* @param {(number|!Array.<number>)} token The token(s) to prepend to the stream.
|
||||
*/
|
||||
prepend: function(token) {
|
||||
if (Array.isArray(token)) {
|
||||
var tokens = /**@type {!Array.<number>}*/(token);
|
||||
while (tokens.length)
|
||||
this.tokens.unshift(tokens.pop());
|
||||
} else {
|
||||
this.tokens.unshift(token);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* When one or more tokens are pushed to a stream, those tokens
|
||||
* must be inserted, in given order, after the last token in the
|
||||
* stream.
|
||||
*
|
||||
* @param {(number|!Array.<number>)} token The tokens(s) to prepend to the stream.
|
||||
*/
|
||||
push: function(token) {
|
||||
if (Array.isArray(token)) {
|
||||
var tokens = /**@type {!Array.<number>}*/(token);
|
||||
while (tokens.length)
|
||||
this.tokens.push(tokens.shift());
|
||||
} else {
|
||||
this.tokens.push(token);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// 4. Encodings
|
||||
//
|
||||
|
||||
// 4.1 Encoders and decoders
|
||||
|
||||
/** @const */
|
||||
var finished = -1;
|
||||
|
||||
/**
|
||||
* @param {boolean} fatal If true, decoding errors raise an exception.
|
||||
* @param {number=} opt_code_point Override the standard fallback code point.
|
||||
* @return {number} The code point to insert on a decoding error.
|
||||
*/
|
||||
function decoderError(fatal, opt_code_point) {
|
||||
if (fatal)
|
||||
throw TypeError('Decoder error');
|
||||
return opt_code_point || 0xFFFD;
|
||||
}
|
||||
|
||||
/** @interface */
|
||||
function Decoder() {}
|
||||
Decoder.prototype = {
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point, or |finished|.
|
||||
*/
|
||||
handler: function(stream, bite) {}
|
||||
};
|
||||
|
||||
/** @interface */
|
||||
function Encoder() {}
|
||||
Encoder.prototype = {
|
||||
/**
|
||||
* @param {Stream} stream The stream of code points being encoded.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit, or |finished|.
|
||||
*/
|
||||
handler: function(stream, code_point) {}
|
||||
};
|
||||
|
||||
//
|
||||
// 7. API
|
||||
//
|
||||
|
||||
/** @const */ var DEFAULT_ENCODING = 'utf-8';
|
||||
|
||||
// 7.1 Interface TextDecoder
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {string=} encoding The label of the encoding;
|
||||
* defaults to 'utf-8'.
|
||||
* @param {Object=} options
|
||||
*/
|
||||
function TextDecoder(encoding, options) {
|
||||
if (!(this instanceof TextDecoder)) {
|
||||
return new TextDecoder(encoding, options);
|
||||
}
|
||||
encoding = encoding !== undefined ? String(encoding).toLowerCase() : DEFAULT_ENCODING;
|
||||
if (encoding !== DEFAULT_ENCODING) {
|
||||
throw new Error('Encoding not supported. Only utf-8 is supported');
|
||||
}
|
||||
options = ToDictionary(options);
|
||||
|
||||
/** @private @type {boolean} */
|
||||
this._streaming = false;
|
||||
/** @private @type {boolean} */
|
||||
this._BOMseen = false;
|
||||
/** @private @type {?Decoder} */
|
||||
this._decoder = null;
|
||||
/** @private @type {boolean} */
|
||||
this._fatal = Boolean(options['fatal']);
|
||||
/** @private @type {boolean} */
|
||||
this._ignoreBOM = Boolean(options['ignoreBOM']);
|
||||
|
||||
Object.defineProperty(this, 'encoding', {value: 'utf-8'});
|
||||
Object.defineProperty(this, 'fatal', {value: this._fatal});
|
||||
Object.defineProperty(this, 'ignoreBOM', {value: this._ignoreBOM});
|
||||
}
|
||||
|
||||
TextDecoder.prototype = {
|
||||
/**
|
||||
* @param {ArrayBufferView=} input The buffer of bytes to decode.
|
||||
* @param {Object=} options
|
||||
* @return {string} The decoded string.
|
||||
*/
|
||||
decode: function decode(input, options) {
|
||||
var bytes;
|
||||
if (typeof input === 'object' && input instanceof ArrayBuffer) {
|
||||
bytes = new Uint8Array(input);
|
||||
} else if (typeof input === 'object' && 'buffer' in input &&
|
||||
input.buffer instanceof ArrayBuffer) {
|
||||
bytes = new Uint8Array(input.buffer,
|
||||
input.byteOffset,
|
||||
input.byteLength);
|
||||
} else {
|
||||
bytes = new Uint8Array(0);
|
||||
}
|
||||
|
||||
options = ToDictionary(options);
|
||||
|
||||
if (!this._streaming) {
|
||||
this._decoder = new UTF8Decoder({fatal: this._fatal});
|
||||
this._BOMseen = false;
|
||||
}
|
||||
this._streaming = Boolean(options['stream']);
|
||||
|
||||
var input_stream = new Stream(bytes);
|
||||
|
||||
var code_points = [];
|
||||
|
||||
/** @type {?(number|!Array.<number>)} */
|
||||
var result;
|
||||
|
||||
while (!input_stream.endOfStream()) {
|
||||
result = this._decoder.handler(input_stream, input_stream.read());
|
||||
if (result === finished)
|
||||
break;
|
||||
if (result === null)
|
||||
continue;
|
||||
if (Array.isArray(result))
|
||||
code_points.push.apply(code_points, /**@type {!Array.<number>}*/(result));
|
||||
else
|
||||
code_points.push(result);
|
||||
}
|
||||
if (!this._streaming) {
|
||||
do {
|
||||
result = this._decoder.handler(input_stream, input_stream.read());
|
||||
if (result === finished)
|
||||
break;
|
||||
if (result === null)
|
||||
continue;
|
||||
if (Array.isArray(result))
|
||||
code_points.push.apply(code_points, /**@type {!Array.<number>}*/(result));
|
||||
else
|
||||
code_points.push(result);
|
||||
} while (!input_stream.endOfStream());
|
||||
this._decoder = null;
|
||||
}
|
||||
|
||||
if (code_points.length) {
|
||||
// If encoding is one of utf-8, utf-16be, and utf-16le, and
|
||||
// ignore BOM flag and BOM seen flag are unset, run these
|
||||
// subsubsteps:
|
||||
if (['utf-8'].indexOf(this.encoding) !== -1 &&
|
||||
!this._ignoreBOM && !this._BOMseen) {
|
||||
// If token is U+FEFF, set BOM seen flag.
|
||||
if (code_points[0] === 0xFEFF) {
|
||||
this._BOMseen = true;
|
||||
code_points.shift();
|
||||
} else {
|
||||
// Otherwise, if token is not end-of-stream, set BOM seen
|
||||
// flag and append token to output.
|
||||
this._BOMseen = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return codePointsToString(code_points);
|
||||
}
|
||||
};
|
||||
|
||||
// 7.2 Interface TextEncoder
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {string=} encoding The label of the encoding;
|
||||
* defaults to 'utf-8'.
|
||||
* @param {Object=} options
|
||||
*/
|
||||
function TextEncoder(encoding, options) {
|
||||
if (!(this instanceof TextEncoder))
|
||||
return new TextEncoder(encoding, options);
|
||||
encoding = encoding !== undefined ? String(encoding).toLowerCase() : DEFAULT_ENCODING;
|
||||
if (encoding !== DEFAULT_ENCODING) {
|
||||
throw new Error('Encoding not supported. Only utf-8 is supported');
|
||||
}
|
||||
options = ToDictionary(options);
|
||||
|
||||
/** @private @type {boolean} */
|
||||
this._streaming = false;
|
||||
/** @private @type {?Encoder} */
|
||||
this._encoder = null;
|
||||
/** @private @type {{fatal: boolean}} */
|
||||
this._options = {fatal: Boolean(options['fatal'])};
|
||||
|
||||
Object.defineProperty(this, 'encoding', {value: 'utf-8'});
|
||||
}
|
||||
|
||||
TextEncoder.prototype = {
|
||||
/**
|
||||
* @param {string=} opt_string The string to encode.
|
||||
* @param {Object=} options
|
||||
* @return {Uint8Array} Encoded bytes, as a Uint8Array.
|
||||
*/
|
||||
encode: function encode(opt_string, options) {
|
||||
opt_string = opt_string ? String(opt_string) : '';
|
||||
options = ToDictionary(options);
|
||||
|
||||
// NOTE: This option is nonstandard. None of the encodings
|
||||
// permitted for encoding (i.e. UTF-8, UTF-16) are stateful,
|
||||
// so streaming is not necessary.
|
||||
if (!this._streaming)
|
||||
this._encoder = new UTF8Encoder(this._options);
|
||||
this._streaming = Boolean(options['stream']);
|
||||
|
||||
var bytes = [];
|
||||
var input_stream = new Stream(stringToCodePoints(opt_string));
|
||||
/** @type {?(number|!Array.<number>)} */
|
||||
var result;
|
||||
while (!input_stream.endOfStream()) {
|
||||
result = this._encoder.handler(input_stream, input_stream.read());
|
||||
if (result === finished)
|
||||
break;
|
||||
if (Array.isArray(result))
|
||||
bytes.push.apply(bytes, /**@type {!Array.<number>}*/(result));
|
||||
else
|
||||
bytes.push(result);
|
||||
}
|
||||
if (!this._streaming) {
|
||||
while (true) {
|
||||
result = this._encoder.handler(input_stream, input_stream.read());
|
||||
if (result === finished)
|
||||
break;
|
||||
if (Array.isArray(result))
|
||||
bytes.push.apply(bytes, /**@type {!Array.<number>}*/(result));
|
||||
else
|
||||
bytes.push(result);
|
||||
}
|
||||
this._encoder = null;
|
||||
}
|
||||
return new Uint8Array(bytes);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// 8. The encoding
|
||||
//
|
||||
|
||||
// 8.1 utf-8
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Decoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
function UTF8Decoder(options) {
|
||||
var fatal = options.fatal;
|
||||
|
||||
// utf-8's decoder's has an associated utf-8 code point, utf-8
|
||||
// bytes seen, and utf-8 bytes needed (all initially 0), a utf-8
|
||||
// lower boundary (initially 0x80), and a utf-8 upper boundary
|
||||
// (initially 0xBF).
|
||||
var /** @type {number} */ utf8_code_point = 0,
|
||||
/** @type {number} */ utf8_bytes_seen = 0,
|
||||
/** @type {number} */ utf8_bytes_needed = 0,
|
||||
/** @type {number} */ utf8_lower_boundary = 0x80,
|
||||
/** @type {number} */ utf8_upper_boundary = 0xBF;
|
||||
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point.
|
||||
*/
|
||||
this.handler = function(stream, bite) {
|
||||
// 1. If byte is end-of-stream and utf-8 bytes needed is not 0,
|
||||
// set utf-8 bytes needed to 0 and return error.
|
||||
if (bite === end_of_stream && utf8_bytes_needed !== 0) {
|
||||
utf8_bytes_needed = 0;
|
||||
return decoderError(fatal);
|
||||
}
|
||||
|
||||
// 2. If byte is end-of-stream, return finished.
|
||||
if (bite === end_of_stream)
|
||||
return finished;
|
||||
|
||||
// 3. If utf-8 bytes needed is 0, based on byte:
|
||||
if (utf8_bytes_needed === 0) {
|
||||
|
||||
// 0x00 to 0x7F
|
||||
if (inRange(bite, 0x00, 0x7F)) {
|
||||
// Return a code point whose value is byte.
|
||||
return bite;
|
||||
}
|
||||
|
||||
// 0xC2 to 0xDF
|
||||
if (inRange(bite, 0xC2, 0xDF)) {
|
||||
// Set utf-8 bytes needed to 1 and utf-8 code point to byte
|
||||
// − 0xC0.
|
||||
utf8_bytes_needed = 1;
|
||||
utf8_code_point = bite - 0xC0;
|
||||
}
|
||||
|
||||
// 0xE0 to 0xEF
|
||||
else if (inRange(bite, 0xE0, 0xEF)) {
|
||||
// 1. If byte is 0xE0, set utf-8 lower boundary to 0xA0.
|
||||
if (bite === 0xE0)
|
||||
utf8_lower_boundary = 0xA0;
|
||||
// 2. If byte is 0xED, set utf-8 upper boundary to 0x9F.
|
||||
if (bite === 0xED)
|
||||
utf8_upper_boundary = 0x9F;
|
||||
// 3. Set utf-8 bytes needed to 2 and utf-8 code point to
|
||||
// byte − 0xE0.
|
||||
utf8_bytes_needed = 2;
|
||||
utf8_code_point = bite - 0xE0;
|
||||
}
|
||||
|
||||
// 0xF0 to 0xF4
|
||||
else if (inRange(bite, 0xF0, 0xF4)) {
|
||||
// 1. If byte is 0xF0, set utf-8 lower boundary to 0x90.
|
||||
if (bite === 0xF0)
|
||||
utf8_lower_boundary = 0x90;
|
||||
// 2. If byte is 0xF4, set utf-8 upper boundary to 0x8F.
|
||||
if (bite === 0xF4)
|
||||
utf8_upper_boundary = 0x8F;
|
||||
// 3. Set utf-8 bytes needed to 3 and utf-8 code point to
|
||||
// byte − 0xF0.
|
||||
utf8_bytes_needed = 3;
|
||||
utf8_code_point = bite - 0xF0;
|
||||
}
|
||||
|
||||
// Otherwise
|
||||
else {
|
||||
// Return error.
|
||||
return decoderError(fatal);
|
||||
}
|
||||
|
||||
// Then (byte is in the range 0xC2 to 0xF4) set utf-8 code
|
||||
// point to utf-8 code point << (6 × utf-8 bytes needed) and
|
||||
// return continue.
|
||||
utf8_code_point = utf8_code_point << (6 * utf8_bytes_needed);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. If byte is not in the range utf-8 lower boundary to utf-8
|
||||
// upper boundary, run these substeps:
|
||||
if (!inRange(bite, utf8_lower_boundary, utf8_upper_boundary)) {
|
||||
|
||||
// 1. Set utf-8 code point, utf-8 bytes needed, and utf-8
|
||||
// bytes seen to 0, set utf-8 lower boundary to 0x80, and set
|
||||
// utf-8 upper boundary to 0xBF.
|
||||
utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;
|
||||
utf8_lower_boundary = 0x80;
|
||||
utf8_upper_boundary = 0xBF;
|
||||
|
||||
// 2. Prepend byte to stream.
|
||||
stream.prepend(bite);
|
||||
|
||||
// 3. Return error.
|
||||
return decoderError(fatal);
|
||||
}
|
||||
|
||||
// 5. Set utf-8 lower boundary to 0x80 and utf-8 upper boundary
|
||||
// to 0xBF.
|
||||
utf8_lower_boundary = 0x80;
|
||||
utf8_upper_boundary = 0xBF;
|
||||
|
||||
// 6. Increase utf-8 bytes seen by one and set utf-8 code point
|
||||
// to utf-8 code point + (byte − 0x80) << (6 × (utf-8 bytes
|
||||
// needed − utf-8 bytes seen)).
|
||||
utf8_bytes_seen += 1;
|
||||
utf8_code_point += (bite - 0x80) << (6 * (utf8_bytes_needed - utf8_bytes_seen));
|
||||
|
||||
// 7. If utf-8 bytes seen is not equal to utf-8 bytes needed,
|
||||
// continue.
|
||||
if (utf8_bytes_seen !== utf8_bytes_needed)
|
||||
return null;
|
||||
|
||||
// 8. Let code point be utf-8 code point.
|
||||
var code_point = utf8_code_point;
|
||||
|
||||
// 9. Set utf-8 code point, utf-8 bytes needed, and utf-8 bytes
|
||||
// seen to 0.
|
||||
utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;
|
||||
|
||||
// 10. Return a code point whose value is code point.
|
||||
return code_point;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Encoder}
|
||||
* @param {{fatal: boolean}} options
|
||||
*/
|
||||
function UTF8Encoder(options) {
|
||||
var fatal = options.fatal;
|
||||
/**
|
||||
* @param {Stream} stream Input stream.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit.
|
||||
*/
|
||||
this.handler = function(stream, code_point) {
|
||||
// 1. If code point is end-of-stream, return finished.
|
||||
if (code_point === end_of_stream)
|
||||
return finished;
|
||||
|
||||
// 2. If code point is in the range U+0000 to U+007F, return a
|
||||
// byte whose value is code point.
|
||||
if (inRange(code_point, 0x0000, 0x007f))
|
||||
return code_point;
|
||||
|
||||
// 3. Set count and offset based on the range code point is in:
|
||||
var count, offset;
|
||||
// U+0080 to U+07FF: 1 and 0xC0
|
||||
if (inRange(code_point, 0x0080, 0x07FF)) {
|
||||
count = 1;
|
||||
offset = 0xC0;
|
||||
}
|
||||
// U+0800 to U+FFFF: 2 and 0xE0
|
||||
else if (inRange(code_point, 0x0800, 0xFFFF)) {
|
||||
count = 2;
|
||||
offset = 0xE0;
|
||||
}
|
||||
// U+10000 to U+10FFFF: 3 and 0xF0
|
||||
else if (inRange(code_point, 0x10000, 0x10FFFF)) {
|
||||
count = 3;
|
||||
offset = 0xF0;
|
||||
}
|
||||
|
||||
// 4.Let bytes be a byte sequence whose first byte is (code
|
||||
// point >> (6 × count)) + offset.
|
||||
var bytes = [(code_point >> (6 * count)) + offset];
|
||||
|
||||
// 5. Run these substeps while count is greater than 0:
|
||||
while (count > 0) {
|
||||
|
||||
// 1. Set temp to code point >> (6 × (count − 1)).
|
||||
var temp = code_point >> (6 * (count - 1));
|
||||
|
||||
// 2. Append to bytes 0x80 | (temp & 0x3F).
|
||||
bytes.push(0x80 | (temp & 0x3F));
|
||||
|
||||
// 3. Decrease count by one.
|
||||
count -= 1;
|
||||
}
|
||||
|
||||
// 6. Return bytes bytes, in order.
|
||||
return bytes;
|
||||
};
|
||||
}
|
||||
|
||||
export {TextEncoder, TextDecoder};
|
||||
@@ -0,0 +1,2 @@
|
||||
export declare var LanguageVariant: any;
|
||||
//# sourceMappingURL=languageVariant.d.ts.map
|
||||
@@ -0,0 +1,74 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getModifiers = getModifiers;
|
||||
exports.getDecorators = getDecorators;
|
||||
const ts = __importStar(require("typescript"));
|
||||
const version_check_1 = require("./version-check");
|
||||
const isAtLeast48 = version_check_1.typescriptVersionIsAtLeast['4.8'];
|
||||
function getModifiers(node, includeIllegalModifiers = false) {
|
||||
if (node == null) {
|
||||
return undefined;
|
||||
}
|
||||
if (isAtLeast48) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated -- this is safe as it's guarded
|
||||
if (includeIllegalModifiers || ts.canHaveModifiers(node)) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated -- this is safe as it's guarded
|
||||
const modifiers = ts.getModifiers(node);
|
||||
return modifiers ? [...modifiers] : undefined;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
return (
|
||||
// @ts-expect-error intentional fallback for older TS versions
|
||||
node.modifiers?.filter((m) => !ts.isDecorator(m)));
|
||||
}
|
||||
function getDecorators(node, includeIllegalDecorators = false) {
|
||||
if (node == null) {
|
||||
return undefined;
|
||||
}
|
||||
if (isAtLeast48) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated -- this is safe as it's guarded
|
||||
if (includeIllegalDecorators || ts.canHaveDecorators(node)) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated -- this is safe as it's guarded
|
||||
const decorators = ts.getDecorators(node);
|
||||
return decorators ? [...decorators] : undefined;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
return (
|
||||
// @ts-expect-error intentional fallback for older TS versions
|
||||
node.decorators?.filter(ts.isDecorator));
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// @ts-ignore TS6133
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
import * as z from "zod/v3";
|
||||
import { util } from "../helpers/util.js";
|
||||
|
||||
test("instanceof", async () => {
|
||||
class Test {}
|
||||
class Subtest extends Test {}
|
||||
abstract class AbstractBar {
|
||||
constructor(public val: string) {}
|
||||
}
|
||||
class Bar extends AbstractBar {}
|
||||
|
||||
const TestSchema = z.instanceof(Test);
|
||||
const SubtestSchema = z.instanceof(Subtest);
|
||||
const AbstractSchema = z.instanceof(AbstractBar);
|
||||
const BarSchema = z.instanceof(Bar);
|
||||
|
||||
TestSchema.parse(new Test());
|
||||
TestSchema.parse(new Subtest());
|
||||
SubtestSchema.parse(new Subtest());
|
||||
AbstractSchema.parse(new Bar("asdf"));
|
||||
const bar = BarSchema.parse(new Bar("asdf"));
|
||||
expect(bar.val).toEqual("asdf");
|
||||
|
||||
await expect(() => SubtestSchema.parse(new Test())).toThrow(/Input not instance of Subtest/);
|
||||
await expect(() => TestSchema.parse(12)).toThrow(/Input not instance of Test/);
|
||||
|
||||
util.assertEqual<Test, z.infer<typeof TestSchema>>(true);
|
||||
});
|
||||
|
||||
test("instanceof fatal", () => {
|
||||
const schema = z.instanceof(Date).refine((d) => d.toString());
|
||||
const res = schema.safeParse(null);
|
||||
expect(res.success).toBe(false);
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "detect-libc",
|
||||
"version": "2.1.2",
|
||||
"description": "Node.js module to detect the C standard library (libc) implementation family and version",
|
||||
"main": "lib/detect-libc.js",
|
||||
"files": [
|
||||
"lib/",
|
||||
"index.d.ts"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "semistandard && nyc --reporter=text --check-coverage --branches=100 ava test/unit.js",
|
||||
"changelog": "conventional-changelog -i CHANGELOG.md -s",
|
||||
"bench": "node benchmark/detect-libc",
|
||||
"bench:calls": "node benchmark/call-familySync.js && sleep 1 && node benchmark/call-isNonGlibcLinuxSync.js && sleep 1 && node benchmark/call-versionSync.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/lovell/detect-libc.git"
|
||||
},
|
||||
"keywords": [
|
||||
"libc",
|
||||
"glibc",
|
||||
"musl"
|
||||
],
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"contributors": [
|
||||
"Niklas Salmoukas <niklas@salmoukas.com>",
|
||||
"Vinícius Lourenço <vinyygamerlol@gmail.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"ava": "^2.4.0",
|
||||
"benchmark": "^2.1.4",
|
||||
"conventional-changelog-cli": "^5.0.0",
|
||||
"eslint-config-standard": "^13.0.1",
|
||||
"nyc": "^15.1.0",
|
||||
"proxyquire": "^2.1.3",
|
||||
"semistandard": "^14.2.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"types": "index.d.ts"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
|
||||
// ref: https://github.com/tc39/proposal-global
|
||||
var getGlobal = function () {
|
||||
// the only reliable means to get the global object is
|
||||
// `Function('return this')()`
|
||||
// However, this causes CSP violations in Chrome apps.
|
||||
if (typeof self !== 'undefined') { return self; }
|
||||
if (typeof window !== 'undefined') { return window; }
|
||||
if (typeof global !== 'undefined') { return global; }
|
||||
throw new Error('unable to locate global object');
|
||||
}
|
||||
|
||||
var globalObject = getGlobal();
|
||||
|
||||
module.exports = exports = globalObject.fetch;
|
||||
|
||||
// Needed for TypeScript and Webpack.
|
||||
if (globalObject.fetch) {
|
||||
exports.default = globalObject.fetch.bind(globalObject);
|
||||
}
|
||||
|
||||
exports.Headers = globalObject.Headers;
|
||||
exports.Request = globalObject.Request;
|
||||
exports.Response = globalObject.Response;
|
||||
@@ -0,0 +1,139 @@
|
||||
import * as util from "./util.js";
|
||||
/**
|
||||
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
||||
* (timestamps embedded in the id). Use {@link cuid2} instead.
|
||||
* See https://github.com/paralleldrive/cuid.
|
||||
*/
|
||||
export const cuid = /^[cC][0-9a-z]{6,}$/;
|
||||
export const cuid2 = /^[0-9a-z]+$/;
|
||||
export const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
|
||||
export const xid = /^[0-9a-vA-V]{20}$/;
|
||||
export const ksuid = /^[A-Za-z0-9]{27}$/;
|
||||
export const nanoid = /^[a-zA-Z0-9_-]{21}$/;
|
||||
/** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
|
||||
export const duration = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
|
||||
/** Implements ISO 8601-2 extensions like explicit +- prefixes, mixing weeks with other units, and fractional/negative components. */
|
||||
export const extendedDuration = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
||||
/** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
|
||||
export const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
|
||||
/** Returns a regex for validating an RFC 9562/4122 UUID.
|
||||
*
|
||||
* @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
|
||||
export const uuid = (version) => {
|
||||
if (!version)
|
||||
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
|
||||
return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
|
||||
};
|
||||
export const uuid4 = /*@__PURE__*/ uuid(4);
|
||||
export const uuid6 = /*@__PURE__*/ uuid(6);
|
||||
export const uuid7 = /*@__PURE__*/ uuid(7);
|
||||
/** Practical email validation */
|
||||
export const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
|
||||
/** Equivalent to the HTML5 input[type=email] validation implemented by browsers. Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email */
|
||||
export const html5Email = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
||||
/** The classic emailregex.com regex for RFC 5322-compliant emails */
|
||||
export const rfc5322Email = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
/** A loose regex that allows Unicode characters, enforces length limits, and that's about it. */
|
||||
export const unicodeEmail = /^[^\s@"]{1,64}@[^\s@]{1,255}$/u;
|
||||
export const idnEmail = unicodeEmail;
|
||||
export const browserEmail = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
||||
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
||||
const _emoji = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
||||
export function emoji() {
|
||||
return new RegExp(_emoji, "u");
|
||||
}
|
||||
export const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
||||
export const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
|
||||
export const mac = (delimiter) => {
|
||||
const escapedDelim = util.escapeRegex(delimiter ?? ":");
|
||||
return new RegExp(`^(?:[0-9A-F]{2}${escapedDelim}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${escapedDelim}){5}[0-9a-f]{2}$`);
|
||||
};
|
||||
export const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
|
||||
export const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
||||
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
||||
export const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
||||
export const base64url = /^[A-Za-z0-9_-]*$/;
|
||||
// based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
|
||||
// export const hostname: RegExp = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
|
||||
export const hostname = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
|
||||
export const domain = /^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
|
||||
export const httpProtocol = /^https?$/;
|
||||
// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
|
||||
// E.164: leading digit must be 1-9; total digits (excluding '+') between 7-15
|
||||
export const e164 = /^\+[1-9]\d{6,14}$/;
|
||||
// const dateSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
||||
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
|
||||
export const date = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
|
||||
function timeSource(args) {
|
||||
const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
|
||||
const regex = typeof args.precision === "number"
|
||||
? args.precision === -1
|
||||
? `${hhmm}`
|
||||
: args.precision === 0
|
||||
? `${hhmm}:[0-5]\\d`
|
||||
: `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}`
|
||||
: `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
|
||||
return regex;
|
||||
}
|
||||
export function time(args) {
|
||||
return new RegExp(`^${timeSource(args)}$`);
|
||||
}
|
||||
// Adapted from https://stackoverflow.com/a/3143231
|
||||
export function datetime(args) {
|
||||
const time = timeSource({ precision: args.precision });
|
||||
const opts = ["Z"];
|
||||
if (args.local)
|
||||
opts.push("");
|
||||
// if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
|
||||
if (args.offset)
|
||||
opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
|
||||
const timeRegex = `${time}(?:${opts.join("|")})`;
|
||||
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
||||
}
|
||||
export const string = (params) => {
|
||||
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
||||
return new RegExp(`^${regex}$`);
|
||||
};
|
||||
export const bigint = /^-?\d+n?$/;
|
||||
export const integer = /^-?\d+$/;
|
||||
export const number = /^-?\d+(?:\.\d+)?$/;
|
||||
export const boolean = /^(?:true|false)$/i;
|
||||
const _null = /^null$/i;
|
||||
export { _null as null };
|
||||
const _undefined = /^undefined$/i;
|
||||
export { _undefined as undefined };
|
||||
// regex for string with no uppercase letters
|
||||
export const lowercase = /^[^A-Z]*$/;
|
||||
// regex for string with no lowercase letters
|
||||
export const uppercase = /^[^a-z]*$/;
|
||||
// regex for hexadecimal strings (any length)
|
||||
export const hex = /^[0-9a-fA-F]*$/;
|
||||
// Hash regexes for different algorithms and encodings
|
||||
// Helper function to create base64 regex with exact length and padding
|
||||
function fixedBase64(bodyLength, padding) {
|
||||
return new RegExp(`^[A-Za-z0-9+/]{${bodyLength}}${padding}$`);
|
||||
}
|
||||
// Helper function to create base64url regex with exact length (no padding)
|
||||
function fixedBase64url(length) {
|
||||
return new RegExp(`^[A-Za-z0-9_-]{${length}}$`);
|
||||
}
|
||||
// MD5 (16 bytes): base64 = 24 chars total (22 + "==")
|
||||
export const md5_hex = /^[0-9a-fA-F]{32}$/;
|
||||
export const md5_base64 = /*@__PURE__*/ fixedBase64(22, "==");
|
||||
export const md5_base64url = /*@__PURE__*/ fixedBase64url(22);
|
||||
// SHA1 (20 bytes): base64 = 28 chars total (27 + "=")
|
||||
export const sha1_hex = /^[0-9a-fA-F]{40}$/;
|
||||
export const sha1_base64 = /*@__PURE__*/ fixedBase64(27, "=");
|
||||
export const sha1_base64url = /*@__PURE__*/ fixedBase64url(27);
|
||||
// SHA256 (32 bytes): base64 = 44 chars total (43 + "=")
|
||||
export const sha256_hex = /^[0-9a-fA-F]{64}$/;
|
||||
export const sha256_base64 = /*@__PURE__*/ fixedBase64(43, "=");
|
||||
export const sha256_base64url = /*@__PURE__*/ fixedBase64url(43);
|
||||
// SHA384 (48 bytes): base64 = 64 chars total (no padding)
|
||||
export const sha384_hex = /^[0-9a-fA-F]{96}$/;
|
||||
export const sha384_base64 = /*@__PURE__*/ fixedBase64(64, "");
|
||||
export const sha384_base64url = /*@__PURE__*/ fixedBase64url(64);
|
||||
// SHA512 (64 bytes): base64 = 88 chars total (86 + "==")
|
||||
export const sha512_hex = /^[0-9a-fA-F]{128}$/;
|
||||
export const sha512_base64 = /*@__PURE__*/ fixedBase64(86, "==");
|
||||
export const sha512_base64url = /*@__PURE__*/ fixedBase64url(86);
|
||||
@@ -0,0 +1,325 @@
|
||||
import * as checks from "./checks.js";
|
||||
import type * as core from "./core.js";
|
||||
import type * as errors from "./errors.js";
|
||||
import * as registries from "./registries.js";
|
||||
import * as schemas from "./schemas.js";
|
||||
import * as util from "./util.js";
|
||||
export type Params<T extends schemas.$ZodType | checks.$ZodCheck, IssueTypes extends errors.$ZodIssueBase, OmitKeys extends keyof T["_zod"]["def"] = never> = util.Flatten<Partial<util.EmptyToNever<Omit<T["_zod"]["def"], OmitKeys> & ([IssueTypes] extends [never] ? {} : {
|
||||
error?: string | errors.$ZodErrorMap<IssueTypes> | undefined;
|
||||
/** @deprecated This parameter is deprecated. Use `error` instead. */
|
||||
message?: string | undefined;
|
||||
})>>>;
|
||||
export type TypeParams<T extends schemas.$ZodType = schemas.$ZodType & {
|
||||
_isst: never;
|
||||
}, AlsoOmit extends Exclude<keyof T["_zod"]["def"], "type" | "checks" | "error"> = never> = Params<T, NonNullable<T["_zod"]["isst"]>, "type" | "checks" | "error" | AlsoOmit>;
|
||||
export type CheckParams<T extends checks.$ZodCheck = checks.$ZodCheck, // & { _issc: never },
|
||||
AlsoOmit extends Exclude<keyof T["_zod"]["def"], "check" | "error"> = never> = Params<T, NonNullable<T["_zod"]["issc"]>, "check" | "error" | AlsoOmit>;
|
||||
export type StringFormatParams<T extends schemas.$ZodStringFormat = schemas.$ZodStringFormat, AlsoOmit extends Exclude<keyof T["_zod"]["def"], "type" | "coerce" | "checks" | "error" | "check" | "format"> = never> = Params<T, NonNullable<T["_zod"]["isst"] | T["_zod"]["issc"]>, "type" | "coerce" | "checks" | "error" | "check" | "format" | AlsoOmit>;
|
||||
export type CheckStringFormatParams<T extends schemas.$ZodStringFormat = schemas.$ZodStringFormat, AlsoOmit extends Exclude<keyof T["_zod"]["def"], "type" | "coerce" | "checks" | "error" | "check" | "format"> = never> = Params<T, NonNullable<T["_zod"]["issc"]>, "type" | "coerce" | "checks" | "error" | "check" | "format" | AlsoOmit>;
|
||||
export type CheckTypeParams<T extends schemas.$ZodType & checks.$ZodCheck = schemas.$ZodType & checks.$ZodCheck, AlsoOmit extends Exclude<keyof T["_zod"]["def"], "type" | "checks" | "error" | "check"> = never> = Params<T, NonNullable<T["_zod"]["isst"] | T["_zod"]["issc"]>, "type" | "checks" | "error" | "check" | AlsoOmit>;
|
||||
export type $ZodStringParams = TypeParams<schemas.$ZodString<string>, "coerce">;
|
||||
export declare function _string<T extends schemas.$ZodString>(Class: util.SchemaClass<T>, params?: string | $ZodStringParams): T;
|
||||
export declare function _coercedString<T extends schemas.$ZodString>(Class: util.SchemaClass<T>, params?: string | $ZodStringParams): T;
|
||||
export type $ZodStringFormatParams = CheckTypeParams<schemas.$ZodStringFormat, "format" | "coerce" | "when" | "pattern">;
|
||||
export type $ZodCheckStringFormatParams = CheckParams<checks.$ZodCheckStringFormat, "format">;
|
||||
export type $ZodEmailParams = StringFormatParams<schemas.$ZodEmail, "when">;
|
||||
export type $ZodCheckEmailParams = CheckStringFormatParams<schemas.$ZodEmail, "when">;
|
||||
export declare function _email<T extends schemas.$ZodEmail>(Class: util.SchemaClass<T>, params?: string | $ZodEmailParams | $ZodCheckEmailParams): T;
|
||||
export type $ZodGUIDParams = StringFormatParams<schemas.$ZodGUID, "pattern" | "when">;
|
||||
export type $ZodCheckGUIDParams = CheckStringFormatParams<schemas.$ZodGUID, "pattern" | "when">;
|
||||
export declare function _guid<T extends schemas.$ZodGUID>(Class: util.SchemaClass<T>, params?: string | $ZodGUIDParams | $ZodCheckGUIDParams): T;
|
||||
export type $ZodUUIDParams = StringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodCheckUUIDParams = CheckStringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export declare function _uuid<T extends schemas.$ZodUUID>(Class: util.SchemaClass<T>, params?: string | $ZodUUIDParams | $ZodCheckUUIDParams): T;
|
||||
export type $ZodUUIDv4Params = StringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodCheckUUIDv4Params = CheckStringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export declare function _uuidv4<T extends schemas.$ZodUUID>(Class: util.SchemaClass<T>, params?: string | $ZodUUIDv4Params | $ZodCheckUUIDv4Params): T;
|
||||
export type $ZodUUIDv6Params = StringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodCheckUUIDv6Params = CheckStringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export declare function _uuidv6<T extends schemas.$ZodUUID>(Class: util.SchemaClass<T>, params?: string | $ZodUUIDv6Params | $ZodCheckUUIDv6Params): T;
|
||||
export type $ZodUUIDv7Params = StringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export type $ZodCheckUUIDv7Params = CheckStringFormatParams<schemas.$ZodUUID, "pattern" | "when">;
|
||||
export declare function _uuidv7<T extends schemas.$ZodUUID>(Class: util.SchemaClass<T>, params?: string | $ZodUUIDv7Params | $ZodCheckUUIDv7Params): T;
|
||||
export type $ZodURLParams = StringFormatParams<schemas.$ZodURL, "when">;
|
||||
export type $ZodCheckURLParams = CheckStringFormatParams<schemas.$ZodURL, "when">;
|
||||
export declare function _url<T extends schemas.$ZodURL>(Class: util.SchemaClass<T>, params?: string | $ZodURLParams | $ZodCheckURLParams): T;
|
||||
export type $ZodEmojiParams = StringFormatParams<schemas.$ZodEmoji, "when">;
|
||||
export type $ZodCheckEmojiParams = CheckStringFormatParams<schemas.$ZodEmoji, "when">;
|
||||
export declare function _emoji<T extends schemas.$ZodEmoji>(Class: util.SchemaClass<T>, params?: string | $ZodEmojiParams | $ZodCheckEmojiParams): T;
|
||||
export type $ZodNanoIDParams = StringFormatParams<schemas.$ZodNanoID, "when">;
|
||||
export type $ZodCheckNanoIDParams = CheckStringFormatParams<schemas.$ZodNanoID, "when">;
|
||||
export declare function _nanoid<T extends schemas.$ZodNanoID>(Class: util.SchemaClass<T>, params?: string | $ZodNanoIDParams | $ZodCheckNanoIDParams): T;
|
||||
/**
|
||||
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
||||
* (timestamps embedded in the id). Use {@link _cuid2} instead.
|
||||
* See https://github.com/paralleldrive/cuid.
|
||||
*/
|
||||
export type $ZodCUIDParams = StringFormatParams<schemas.$ZodCUID, "when">;
|
||||
/**
|
||||
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
||||
* (timestamps embedded in the id). Use {@link _cuid2} instead.
|
||||
* See https://github.com/paralleldrive/cuid.
|
||||
*/
|
||||
export type $ZodCheckCUIDParams = CheckStringFormatParams<schemas.$ZodCUID, "when">;
|
||||
/**
|
||||
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
||||
* (timestamps embedded in the id). Use {@link _cuid2} instead.
|
||||
* See https://github.com/paralleldrive/cuid.
|
||||
*/
|
||||
export declare function _cuid<T extends schemas.$ZodCUID>(Class: util.SchemaClass<T>, params?: string | $ZodCUIDParams | $ZodCheckCUIDParams): T;
|
||||
export type $ZodCUID2Params = StringFormatParams<schemas.$ZodCUID2, "when">;
|
||||
export type $ZodCheckCUID2Params = CheckStringFormatParams<schemas.$ZodCUID2, "when">;
|
||||
export declare function _cuid2<T extends schemas.$ZodCUID2>(Class: util.SchemaClass<T>, params?: string | $ZodCUID2Params | $ZodCheckCUID2Params): T;
|
||||
export type $ZodULIDParams = StringFormatParams<schemas.$ZodULID, "when">;
|
||||
export type $ZodCheckULIDParams = CheckStringFormatParams<schemas.$ZodULID, "when">;
|
||||
export declare function _ulid<T extends schemas.$ZodULID>(Class: util.SchemaClass<T>, params?: string | $ZodULIDParams | $ZodCheckULIDParams): T;
|
||||
export type $ZodXIDParams = StringFormatParams<schemas.$ZodXID, "when">;
|
||||
export type $ZodCheckXIDParams = CheckStringFormatParams<schemas.$ZodXID, "when">;
|
||||
export declare function _xid<T extends schemas.$ZodXID>(Class: util.SchemaClass<T>, params?: string | $ZodXIDParams | $ZodCheckXIDParams): T;
|
||||
export type $ZodKSUIDParams = StringFormatParams<schemas.$ZodKSUID, "when">;
|
||||
export type $ZodCheckKSUIDParams = CheckStringFormatParams<schemas.$ZodKSUID, "when">;
|
||||
export declare function _ksuid<T extends schemas.$ZodKSUID>(Class: util.SchemaClass<T>, params?: string | $ZodKSUIDParams | $ZodCheckKSUIDParams): T;
|
||||
export type $ZodIPv4Params = StringFormatParams<schemas.$ZodIPv4, "pattern" | "when" | "version">;
|
||||
export type $ZodCheckIPv4Params = CheckStringFormatParams<schemas.$ZodIPv4, "pattern" | "when" | "version">;
|
||||
export declare function _ipv4<T extends schemas.$ZodIPv4>(Class: util.SchemaClass<T>, params?: string | $ZodIPv4Params | $ZodCheckIPv4Params): T;
|
||||
export type $ZodIPv6Params = StringFormatParams<schemas.$ZodIPv6, "pattern" | "when" | "version">;
|
||||
export type $ZodCheckIPv6Params = CheckStringFormatParams<schemas.$ZodIPv6, "pattern" | "when" | "version">;
|
||||
export declare function _ipv6<T extends schemas.$ZodIPv6>(Class: util.SchemaClass<T>, params?: string | $ZodIPv6Params | $ZodCheckIPv6Params): T;
|
||||
export type $ZodMACParams = StringFormatParams<schemas.$ZodMAC, "pattern" | "when">;
|
||||
export type $ZodCheckMACParams = CheckStringFormatParams<schemas.$ZodMAC, "pattern" | "when">;
|
||||
export declare function _mac<T extends schemas.$ZodMAC>(Class: util.SchemaClass<T>, params?: string | $ZodMACParams | $ZodCheckMACParams): T;
|
||||
export type $ZodCIDRv4Params = StringFormatParams<schemas.$ZodCIDRv4, "pattern" | "when">;
|
||||
export type $ZodCheckCIDRv4Params = CheckStringFormatParams<schemas.$ZodCIDRv4, "pattern" | "when">;
|
||||
export declare function _cidrv4<T extends schemas.$ZodCIDRv4>(Class: util.SchemaClass<T>, params?: string | $ZodCIDRv4Params | $ZodCheckCIDRv4Params): T;
|
||||
export type $ZodCIDRv6Params = StringFormatParams<schemas.$ZodCIDRv6, "pattern" | "when">;
|
||||
export type $ZodCheckCIDRv6Params = CheckStringFormatParams<schemas.$ZodCIDRv6, "pattern" | "when">;
|
||||
export declare function _cidrv6<T extends schemas.$ZodCIDRv6>(Class: util.SchemaClass<T>, params?: string | $ZodCIDRv6Params | $ZodCheckCIDRv6Params): T;
|
||||
export type $ZodBase64Params = StringFormatParams<schemas.$ZodBase64, "pattern" | "when">;
|
||||
export type $ZodCheckBase64Params = CheckStringFormatParams<schemas.$ZodBase64, "pattern" | "when">;
|
||||
export declare function _base64<T extends schemas.$ZodBase64>(Class: util.SchemaClass<T>, params?: string | $ZodBase64Params | $ZodCheckBase64Params): T;
|
||||
export type $ZodBase64URLParams = StringFormatParams<schemas.$ZodBase64URL, "pattern" | "when">;
|
||||
export type $ZodCheckBase64URLParams = CheckStringFormatParams<schemas.$ZodBase64URL, "pattern" | "when">;
|
||||
export declare function _base64url<T extends schemas.$ZodBase64URL>(Class: util.SchemaClass<T>, params?: string | $ZodBase64URLParams | $ZodCheckBase64URLParams): T;
|
||||
export type $ZodE164Params = StringFormatParams<schemas.$ZodE164, "when">;
|
||||
export type $ZodCheckE164Params = CheckStringFormatParams<schemas.$ZodE164, "when">;
|
||||
export declare function _e164<T extends schemas.$ZodE164>(Class: util.SchemaClass<T>, params?: string | $ZodE164Params | $ZodCheckE164Params): T;
|
||||
export type $ZodJWTParams = StringFormatParams<schemas.$ZodJWT, "pattern" | "when">;
|
||||
export type $ZodCheckJWTParams = CheckStringFormatParams<schemas.$ZodJWT, "pattern" | "when">;
|
||||
export declare function _jwt<T extends schemas.$ZodJWT>(Class: util.SchemaClass<T>, params?: string | $ZodJWTParams | $ZodCheckJWTParams): T;
|
||||
export declare const TimePrecision: {
|
||||
readonly Any: null;
|
||||
readonly Minute: -1;
|
||||
readonly Second: 0;
|
||||
readonly Millisecond: 3;
|
||||
readonly Microsecond: 6;
|
||||
};
|
||||
export type $ZodISODateTimeParams = StringFormatParams<schemas.$ZodISODateTime, "pattern" | "when">;
|
||||
export type $ZodCheckISODateTimeParams = CheckStringFormatParams<schemas.$ZodISODateTime, "pattern" | "when">;
|
||||
export declare function _isoDateTime<T extends schemas.$ZodISODateTime>(Class: util.SchemaClass<T>, params?: string | $ZodISODateTimeParams | $ZodCheckISODateTimeParams): T;
|
||||
export type $ZodISODateParams = StringFormatParams<schemas.$ZodISODate, "pattern" | "when">;
|
||||
export type $ZodCheckISODateParams = CheckStringFormatParams<schemas.$ZodISODate, "pattern" | "when">;
|
||||
export declare function _isoDate<T extends schemas.$ZodISODate>(Class: util.SchemaClass<T>, params?: string | $ZodISODateParams | $ZodCheckISODateParams): T;
|
||||
export type $ZodISOTimeParams = StringFormatParams<schemas.$ZodISOTime, "pattern" | "when">;
|
||||
export type $ZodCheckISOTimeParams = CheckStringFormatParams<schemas.$ZodISOTime, "pattern" | "when">;
|
||||
export declare function _isoTime<T extends schemas.$ZodISOTime>(Class: util.SchemaClass<T>, params?: string | $ZodISOTimeParams | $ZodCheckISOTimeParams): T;
|
||||
export type $ZodISODurationParams = StringFormatParams<schemas.$ZodISODuration, "when">;
|
||||
export type $ZodCheckISODurationParams = CheckStringFormatParams<schemas.$ZodISODuration, "when">;
|
||||
export declare function _isoDuration<T extends schemas.$ZodISODuration>(Class: util.SchemaClass<T>, params?: string | $ZodISODurationParams | $ZodCheckISODurationParams): T;
|
||||
export type $ZodNumberParams = TypeParams<schemas.$ZodNumber<number>, "coerce">;
|
||||
export type $ZodNumberFormatParams = CheckTypeParams<schemas.$ZodNumberFormat, "format" | "coerce">;
|
||||
export type $ZodCheckNumberFormatParams = CheckParams<checks.$ZodCheckNumberFormat, "format" | "when">;
|
||||
export declare function _number<T extends schemas.$ZodNumber>(Class: util.SchemaClass<T>, params?: string | $ZodNumberParams): T;
|
||||
export declare function _coercedNumber<T extends schemas.$ZodNumber>(Class: util.SchemaClass<T>, params?: string | $ZodNumberParams): T;
|
||||
export declare function _int<T extends schemas.$ZodNumberFormat>(Class: util.SchemaClass<T>, params?: string | $ZodCheckNumberFormatParams): T;
|
||||
export declare function _float32<T extends schemas.$ZodNumberFormat>(Class: util.SchemaClass<T>, params?: string | $ZodCheckNumberFormatParams): T;
|
||||
export declare function _float64<T extends schemas.$ZodNumberFormat>(Class: util.SchemaClass<T>, params?: string | $ZodCheckNumberFormatParams): T;
|
||||
export declare function _int32<T extends schemas.$ZodNumberFormat>(Class: util.SchemaClass<T>, params?: string | $ZodCheckNumberFormatParams): T;
|
||||
export declare function _uint32<T extends schemas.$ZodNumberFormat>(Class: util.SchemaClass<T>, params?: string | $ZodCheckNumberFormatParams): T;
|
||||
export type $ZodBooleanParams = TypeParams<schemas.$ZodBoolean<boolean>, "coerce">;
|
||||
export declare function _boolean<T extends schemas.$ZodBoolean>(Class: util.SchemaClass<T>, params?: string | $ZodBooleanParams): T;
|
||||
export declare function _coercedBoolean<T extends schemas.$ZodBoolean>(Class: util.SchemaClass<T>, params?: string | $ZodBooleanParams): T;
|
||||
export type $ZodBigIntParams = TypeParams<schemas.$ZodBigInt<bigint>>;
|
||||
export type $ZodBigIntFormatParams = CheckTypeParams<schemas.$ZodBigIntFormat, "format" | "coerce">;
|
||||
export type $ZodCheckBigIntFormatParams = CheckParams<checks.$ZodCheckBigIntFormat, "format" | "when">;
|
||||
export declare function _bigint<T extends schemas.$ZodBigInt>(Class: util.SchemaClass<T>, params?: string | $ZodBigIntParams): T;
|
||||
export declare function _coercedBigint<T extends schemas.$ZodBigInt>(Class: util.SchemaClass<T>, params?: string | $ZodBigIntParams): T;
|
||||
export declare function _int64<T extends schemas.$ZodBigIntFormat>(Class: util.SchemaClass<T>, params?: string | $ZodBigIntFormatParams): T;
|
||||
export declare function _uint64<T extends schemas.$ZodBigIntFormat>(Class: util.SchemaClass<T>, params?: string | $ZodBigIntFormatParams): T;
|
||||
export type $ZodSymbolParams = TypeParams<schemas.$ZodSymbol>;
|
||||
export declare function _symbol<T extends schemas.$ZodSymbol>(Class: util.SchemaClass<T>, params?: string | $ZodSymbolParams): T;
|
||||
export type $ZodUndefinedParams = TypeParams<schemas.$ZodUndefined>;
|
||||
export declare function _undefined<T extends schemas.$ZodUndefined>(Class: util.SchemaClass<T>, params?: string | $ZodUndefinedParams): T;
|
||||
export type $ZodNullParams = TypeParams<schemas.$ZodNull>;
|
||||
export declare function _null<T extends schemas.$ZodNull>(Class: util.SchemaClass<T>, params?: string | $ZodNullParams): T;
|
||||
export type $ZodAnyParams = TypeParams<schemas.$ZodAny>;
|
||||
export declare function _any<T extends schemas.$ZodAny>(Class: util.SchemaClass<T>): T;
|
||||
export type $ZodUnknownParams = TypeParams<schemas.$ZodUnknown>;
|
||||
export declare function _unknown<T extends schemas.$ZodUnknown>(Class: util.SchemaClass<T>): T;
|
||||
export type $ZodNeverParams = TypeParams<schemas.$ZodNever>;
|
||||
export declare function _never<T extends schemas.$ZodNever>(Class: util.SchemaClass<T>, params?: string | $ZodNeverParams): T;
|
||||
export type $ZodVoidParams = TypeParams<schemas.$ZodVoid>;
|
||||
export declare function _void<T extends schemas.$ZodVoid>(Class: util.SchemaClass<T>, params?: string | $ZodVoidParams): T;
|
||||
export type $ZodDateParams = TypeParams<schemas.$ZodDate, "coerce">;
|
||||
export declare function _date<T extends schemas.$ZodDate>(Class: util.SchemaClass<T>, params?: string | $ZodDateParams): T;
|
||||
export declare function _coercedDate<T extends schemas.$ZodDate>(Class: util.SchemaClass<T>, params?: string | $ZodDateParams): T;
|
||||
export type $ZodNaNParams = TypeParams<schemas.$ZodNaN>;
|
||||
export declare function _nan<T extends schemas.$ZodNaN>(Class: util.SchemaClass<T>, params?: string | $ZodNaNParams): T;
|
||||
export type $ZodCheckLessThanParams = CheckParams<checks.$ZodCheckLessThan, "inclusive" | "value" | "when">;
|
||||
export declare function _lt(value: util.Numeric, params?: string | $ZodCheckLessThanParams): checks.$ZodCheckLessThan<util.Numeric>;
|
||||
export declare function _lte(value: util.Numeric, params?: string | $ZodCheckLessThanParams): checks.$ZodCheckLessThan<util.Numeric>;
|
||||
export {
|
||||
/** @deprecated Use `z.lte()` instead. */
|
||||
_lte as _max, };
|
||||
export type $ZodCheckGreaterThanParams = CheckParams<checks.$ZodCheckGreaterThan, "inclusive" | "value" | "when">;
|
||||
export declare function _gt(value: util.Numeric, params?: string | $ZodCheckGreaterThanParams): checks.$ZodCheckGreaterThan;
|
||||
export declare function _gte(value: util.Numeric, params?: string | $ZodCheckGreaterThanParams): checks.$ZodCheckGreaterThan;
|
||||
export {
|
||||
/** @deprecated Use `z.gte()` instead. */
|
||||
_gte as _min, };
|
||||
export declare function _positive(params?: string | $ZodCheckGreaterThanParams): checks.$ZodCheckGreaterThan;
|
||||
export declare function _negative(params?: string | $ZodCheckLessThanParams): checks.$ZodCheckLessThan;
|
||||
export declare function _nonpositive(params?: string | $ZodCheckLessThanParams): checks.$ZodCheckLessThan;
|
||||
export declare function _nonnegative(params?: string | $ZodCheckGreaterThanParams): checks.$ZodCheckGreaterThan;
|
||||
export type $ZodCheckMultipleOfParams = CheckParams<checks.$ZodCheckMultipleOf, "value" | "when">;
|
||||
export declare function _multipleOf(value: number | bigint, params?: string | $ZodCheckMultipleOfParams): checks.$ZodCheckMultipleOf;
|
||||
export type $ZodCheckMaxSizeParams = CheckParams<checks.$ZodCheckMaxSize, "maximum" | "when">;
|
||||
export declare function _maxSize(maximum: number, params?: string | $ZodCheckMaxSizeParams): checks.$ZodCheckMaxSize<util.HasSize>;
|
||||
export type $ZodCheckMinSizeParams = CheckParams<checks.$ZodCheckMinSize, "minimum" | "when">;
|
||||
export declare function _minSize(minimum: number, params?: string | $ZodCheckMinSizeParams): checks.$ZodCheckMinSize<util.HasSize>;
|
||||
export type $ZodCheckSizeEqualsParams = CheckParams<checks.$ZodCheckSizeEquals, "size" | "when">;
|
||||
export declare function _size(size: number, params?: string | $ZodCheckSizeEqualsParams): checks.$ZodCheckSizeEquals<util.HasSize>;
|
||||
export type $ZodCheckMaxLengthParams = CheckParams<checks.$ZodCheckMaxLength, "maximum" | "when">;
|
||||
export declare function _maxLength(maximum: number, params?: string | $ZodCheckMaxLengthParams): checks.$ZodCheckMaxLength<util.HasLength>;
|
||||
export type $ZodCheckMinLengthParams = CheckParams<checks.$ZodCheckMinLength, "minimum" | "when">;
|
||||
export declare function _minLength(minimum: number, params?: string | $ZodCheckMinLengthParams): checks.$ZodCheckMinLength<util.HasLength>;
|
||||
export type $ZodCheckLengthEqualsParams = CheckParams<checks.$ZodCheckLengthEquals, "length" | "when">;
|
||||
export declare function _length(length: number, params?: string | $ZodCheckLengthEqualsParams): checks.$ZodCheckLengthEquals<util.HasLength>;
|
||||
export type $ZodCheckRegexParams = CheckParams<checks.$ZodCheckRegex, "format" | "pattern" | "when">;
|
||||
export declare function _regex(pattern: RegExp, params?: string | $ZodCheckRegexParams): checks.$ZodCheckRegex;
|
||||
export type $ZodCheckLowerCaseParams = CheckParams<checks.$ZodCheckLowerCase, "format" | "when">;
|
||||
export declare function _lowercase(params?: string | $ZodCheckLowerCaseParams): checks.$ZodCheckLowerCase;
|
||||
export type $ZodCheckUpperCaseParams = CheckParams<checks.$ZodCheckUpperCase, "format" | "when">;
|
||||
export declare function _uppercase(params?: string | $ZodCheckUpperCaseParams): checks.$ZodCheckUpperCase;
|
||||
export type $ZodCheckIncludesParams = CheckParams<checks.$ZodCheckIncludes, "includes" | "format" | "when" | "pattern">;
|
||||
export declare function _includes(includes: string, params?: string | $ZodCheckIncludesParams): checks.$ZodCheckIncludes;
|
||||
export type $ZodCheckStartsWithParams = CheckParams<checks.$ZodCheckStartsWith, "prefix" | "format" | "when" | "pattern">;
|
||||
export declare function _startsWith(prefix: string, params?: string | $ZodCheckStartsWithParams): checks.$ZodCheckStartsWith;
|
||||
export type $ZodCheckEndsWithParams = CheckParams<checks.$ZodCheckEndsWith, "suffix" | "format" | "pattern" | "when">;
|
||||
export declare function _endsWith(suffix: string, params?: string | $ZodCheckEndsWithParams): checks.$ZodCheckEndsWith;
|
||||
export type $ZodCheckPropertyParams = CheckParams<checks.$ZodCheckProperty, "property" | "schema" | "when">;
|
||||
export declare function _property<K extends string, T extends schemas.$ZodType>(property: K, schema: T, params?: string | $ZodCheckPropertyParams): checks.$ZodCheckProperty<{
|
||||
[k in K]: core.output<T>;
|
||||
}>;
|
||||
export type $ZodCheckMimeTypeParams = CheckParams<checks.$ZodCheckMimeType, "mime" | "when">;
|
||||
export declare function _mime(types: util.MimeTypes[], params?: string | $ZodCheckMimeTypeParams): checks.$ZodCheckMimeType;
|
||||
export declare function _overwrite<T>(tx: (input: T) => T): checks.$ZodCheckOverwrite<T>;
|
||||
export declare function _normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (string & {})): checks.$ZodCheckOverwrite<string>;
|
||||
export declare function _trim(): checks.$ZodCheckOverwrite<string>;
|
||||
export declare function _toLowerCase(): checks.$ZodCheckOverwrite<string>;
|
||||
export declare function _toUpperCase(): checks.$ZodCheckOverwrite<string>;
|
||||
export declare function _slugify(): checks.$ZodCheckOverwrite<string>;
|
||||
export type $ZodArrayParams = TypeParams<schemas.$ZodArray, "element">;
|
||||
export declare function _array<T extends schemas.$ZodType>(Class: util.SchemaClass<schemas.$ZodArray>, element: T, params?: string | $ZodArrayParams): schemas.$ZodArray<T>;
|
||||
export type $ZodObjectParams = TypeParams<schemas.$ZodObject, "shape" | "catchall">;
|
||||
export type $ZodUnionParams = TypeParams<schemas.$ZodUnion, "options">;
|
||||
export declare function _union<const T extends readonly schemas.$ZodObject[]>(Class: util.SchemaClass<schemas.$ZodUnion>, options: T, params?: string | $ZodUnionParams): schemas.$ZodUnion<T>;
|
||||
export type $ZodXorParams = TypeParams<schemas.$ZodXor, "options">;
|
||||
export declare function _xor<const T extends readonly schemas.$ZodObject[]>(Class: util.SchemaClass<schemas.$ZodXor>, options: T, params?: string | $ZodXorParams): schemas.$ZodXor<T>;
|
||||
export interface $ZodTypeDiscriminableInternals<Disc extends string = string> extends schemas.$ZodTypeInternals<unknown, {
|
||||
[K in Disc]?: unknown;
|
||||
}> {
|
||||
propValues: util.PropValues;
|
||||
}
|
||||
export interface $ZodTypeDiscriminable<Disc extends string = string> extends schemas.$ZodType {
|
||||
_zod: $ZodTypeDiscriminableInternals<Disc>;
|
||||
}
|
||||
export type $ZodDiscriminatedUnionParams = TypeParams<schemas.$ZodDiscriminatedUnion, "options" | "discriminator">;
|
||||
export declare function _discriminatedUnion<Types extends [$ZodTypeDiscriminable<Disc>, ...$ZodTypeDiscriminable<Disc>[]], Disc extends string>(Class: util.SchemaClass<schemas.$ZodDiscriminatedUnion>, discriminator: Disc, options: Types, params?: string | $ZodDiscriminatedUnionParams): schemas.$ZodDiscriminatedUnion<Types, Disc>;
|
||||
export type $ZodIntersectionParams = TypeParams<schemas.$ZodIntersection, "left" | "right">;
|
||||
export declare function _intersection<T extends schemas.$ZodObject, U extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodIntersection>, left: T, right: U): schemas.$ZodIntersection<T, U>;
|
||||
export type $ZodTupleParams = TypeParams<schemas.$ZodTuple, "items" | "rest">;
|
||||
export declare function _tuple<T extends readonly [schemas.$ZodType, ...schemas.$ZodType[]]>(Class: util.SchemaClass<schemas.$ZodTuple>, items: T, params?: string | $ZodTupleParams): schemas.$ZodTuple<T, null>;
|
||||
export declare function _tuple<T extends readonly [schemas.$ZodType, ...schemas.$ZodType[]], Rest extends schemas.$ZodType>(Class: util.SchemaClass<schemas.$ZodTuple>, items: T, rest: Rest, params?: string | $ZodTupleParams): schemas.$ZodTuple<T, Rest>;
|
||||
export type $ZodRecordParams = TypeParams<schemas.$ZodRecord, "keyType" | "valueType">;
|
||||
export declare function _record<Key extends schemas.$ZodRecordKey, Value extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodRecord>, keyType: Key, valueType: Value, params?: string | $ZodRecordParams): schemas.$ZodRecord<Key, Value>;
|
||||
export type $ZodMapParams = TypeParams<schemas.$ZodMap, "keyType" | "valueType">;
|
||||
export declare function _map<Key extends schemas.$ZodObject, Value extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodMap>, keyType: Key, valueType: Value, params?: string | $ZodMapParams): schemas.$ZodMap<Key, Value>;
|
||||
export type $ZodSetParams = TypeParams<schemas.$ZodSet, "valueType">;
|
||||
export declare function _set<Value extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodSet>, valueType: Value, params?: string | $ZodSetParams): schemas.$ZodSet<Value>;
|
||||
export type $ZodEnumParams = TypeParams<schemas.$ZodEnum, "entries">;
|
||||
export declare function _enum<const T extends string[]>(Class: util.SchemaClass<schemas.$ZodEnum>, values: T, params?: string | $ZodEnumParams): schemas.$ZodEnum<util.ToEnum<T[number]>>;
|
||||
export declare function _enum<T extends util.EnumLike>(Class: util.SchemaClass<schemas.$ZodEnum>, entries: T, params?: string | $ZodEnumParams): schemas.$ZodEnum<T>;
|
||||
/** @deprecated This API has been merged into `z.enum()`. Use `z.enum()` instead.
|
||||
*
|
||||
* ```ts
|
||||
* enum Colors { red, green, blue }
|
||||
* z.enum(Colors);
|
||||
* ```
|
||||
*/
|
||||
export declare function _nativeEnum<T extends util.EnumLike>(Class: util.SchemaClass<schemas.$ZodEnum>, entries: T, params?: string | $ZodEnumParams): schemas.$ZodEnum<T>;
|
||||
export type $ZodLiteralParams = TypeParams<schemas.$ZodLiteral, "values">;
|
||||
export declare function _literal<const T extends Array<util.Literal>>(Class: util.SchemaClass<schemas.$ZodLiteral>, value: T, params?: string | $ZodLiteralParams): schemas.$ZodLiteral<T[number]>;
|
||||
export declare function _literal<const T extends util.Literal>(Class: util.SchemaClass<schemas.$ZodLiteral>, value: T, params?: string | $ZodLiteralParams): schemas.$ZodLiteral<T>;
|
||||
export type $ZodFileParams = TypeParams<schemas.$ZodFile>;
|
||||
export declare function _file(Class: util.SchemaClass<schemas.$ZodFile>, params?: string | $ZodFileParams): schemas.$ZodFile;
|
||||
export type $ZodTransformParams = TypeParams<schemas.$ZodTransform, "transform">;
|
||||
export declare function _transform<I = unknown, O = I>(Class: util.SchemaClass<schemas.$ZodTransform>, fn: (input: I, ctx?: schemas.ParsePayload) => O): schemas.$ZodTransform<Awaited<O>, I>;
|
||||
export type $ZodOptionalParams = TypeParams<schemas.$ZodOptional, "innerType">;
|
||||
export declare function _optional<T extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodOptional>, innerType: T): schemas.$ZodOptional<T>;
|
||||
export type $ZodNullableParams = TypeParams<schemas.$ZodNullable, "innerType">;
|
||||
export declare function _nullable<T extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodNullable>, innerType: T): schemas.$ZodNullable<T>;
|
||||
export type $ZodDefaultParams = TypeParams<schemas.$ZodDefault, "innerType" | "defaultValue">;
|
||||
export declare function _default<T extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodDefault>, innerType: T, defaultValue: util.NoUndefined<core.output<T>> | (() => util.NoUndefined<core.output<T>>)): schemas.$ZodDefault<T>;
|
||||
export type $ZodNonOptionalParams = TypeParams<schemas.$ZodNonOptional, "innerType">;
|
||||
export declare function _nonoptional<T extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodNonOptional>, innerType: T, params?: string | $ZodNonOptionalParams): schemas.$ZodNonOptional<T>;
|
||||
export type $ZodSuccessParams = TypeParams<schemas.$ZodSuccess, "innerType">;
|
||||
export declare function _success<T extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodSuccess>, innerType: T): schemas.$ZodSuccess<T>;
|
||||
export type $ZodCatchParams = TypeParams<schemas.$ZodCatch, "innerType" | "catchValue">;
|
||||
export declare function _catch<T extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodCatch>, innerType: T, catchValue: core.output<T> | ((ctx: schemas.$ZodCatchCtx) => core.output<T>)): schemas.$ZodCatch<T>;
|
||||
export type $ZodPipeParams = TypeParams<schemas.$ZodPipe, "in" | "out">;
|
||||
export declare function _pipe<const A extends schemas.$ZodType, B extends schemas.$ZodType<unknown, core.output<A>> = schemas.$ZodType<unknown, core.output<A>>>(Class: util.SchemaClass<schemas.$ZodPipe>, in_: A, out: B | schemas.$ZodType<unknown, core.output<A>>): schemas.$ZodPipe<A, B>;
|
||||
export type $ZodReadonlyParams = TypeParams<schemas.$ZodReadonly, "innerType">;
|
||||
export declare function _readonly<T extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodReadonly>, innerType: T): schemas.$ZodReadonly<T>;
|
||||
export type $ZodTemplateLiteralParams = TypeParams<schemas.$ZodTemplateLiteral, "parts">;
|
||||
export declare function _templateLiteral<const Parts extends schemas.$ZodTemplateLiteralPart[]>(Class: util.SchemaClass<schemas.$ZodTemplateLiteral>, parts: Parts, params?: string | $ZodTemplateLiteralParams): schemas.$ZodTemplateLiteral<schemas.$PartsToTemplateLiteral<Parts>>;
|
||||
export type $ZodLazyParams = TypeParams<schemas.$ZodLazy, "getter">;
|
||||
export declare function _lazy<T extends schemas.$ZodType>(Class: util.SchemaClass<schemas.$ZodLazy>, getter: () => T): schemas.$ZodLazy<T>;
|
||||
export type $ZodPromiseParams = TypeParams<schemas.$ZodPromise, "innerType">;
|
||||
export declare function _promise<T extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodPromise>, innerType: T): schemas.$ZodPromise<T>;
|
||||
export type $ZodCustomParams = CheckTypeParams<schemas.$ZodCustom, "fn">;
|
||||
export declare function _custom<O = unknown, I = O>(Class: util.SchemaClass<schemas.$ZodCustom>, fn: (data: O) => unknown, _params: string | $ZodCustomParams | undefined): schemas.$ZodCustom<O, I>;
|
||||
export declare function _refine<O = unknown, I = O>(Class: util.SchemaClass<schemas.$ZodCustom>, fn: (data: O) => unknown, _params: string | $ZodCustomParams | undefined): schemas.$ZodCustom<O, I>;
|
||||
export type $ZodSuperRefineIssue<T extends errors.$ZodIssueBase = errors.$ZodIssue> = T extends any ? RawIssue<T> : never;
|
||||
type RawIssue<T extends errors.$ZodIssueBase> = T extends any ? util.Flatten<util.MakePartial<T, "message" | "path"> & {
|
||||
/** The schema or check that originated this issue. */
|
||||
readonly inst?: schemas.$ZodType | checks.$ZodCheck;
|
||||
/** If `true`, Zod will execute subsequent checks/refinements instead of immediately aborting */
|
||||
readonly continue?: boolean | undefined;
|
||||
} & Record<string, unknown>> : never;
|
||||
export interface $RefinementCtx<T = unknown> extends schemas.ParsePayload<T> {
|
||||
addIssue(arg: string | $ZodSuperRefineIssue): void;
|
||||
}
|
||||
export interface $ZodSuperRefineParams {
|
||||
/** If provided, the refinement runs only when this returns `true`. By default, it is skipped if prior parsing produced aborting issues. */
|
||||
when?: ((payload: schemas.ParsePayload) => boolean) | undefined;
|
||||
}
|
||||
export declare function _superRefine<T>(fn: (arg: T, payload: $RefinementCtx<T>) => void | Promise<void>, params?: $ZodSuperRefineParams): checks.$ZodCheck<T>;
|
||||
export declare function _check<O = unknown>(fn: schemas.CheckFn<O>, params?: string | $ZodCustomParams): checks.$ZodCheck<O>;
|
||||
export declare function describe<T>(description: string): checks.$ZodCheck<T>;
|
||||
export declare function meta<T>(metadata: registries.GlobalMeta): checks.$ZodCheck<T>;
|
||||
export interface $ZodStringBoolParams extends TypeParams {
|
||||
truthy?: string[];
|
||||
falsy?: string[];
|
||||
/**
|
||||
* Options: `"sensitive"`, `"insensitive"`
|
||||
*
|
||||
* @default `"insensitive"`
|
||||
*/
|
||||
case?: "sensitive" | "insensitive" | undefined;
|
||||
}
|
||||
export declare function _stringbool(Classes: {
|
||||
Codec?: typeof schemas.$ZodCodec;
|
||||
Boolean?: typeof schemas.$ZodBoolean;
|
||||
String?: typeof schemas.$ZodString;
|
||||
}, _params?: string | $ZodStringBoolParams): schemas.$ZodCodec<schemas.$ZodString, schemas.$ZodBoolean>;
|
||||
export declare function _stringFormat<Format extends string>(Class: typeof schemas.$ZodCustomStringFormat, format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | $ZodStringFormatParams): schemas.$ZodCustomStringFormat<Format>;
|
||||
@@ -0,0 +1,106 @@
|
||||
import { expectTypeOf, test } from "vitest";
|
||||
import * as z from "zod/v4";
|
||||
|
||||
test("branded types", () => {
|
||||
const mySchema = z
|
||||
.object({
|
||||
name: z.string(),
|
||||
})
|
||||
.brand<"superschema">();
|
||||
|
||||
// simple branding
|
||||
type MySchema = z.infer<typeof mySchema>;
|
||||
|
||||
expectTypeOf<MySchema>().toEqualTypeOf<{ name: string } & z.$brand<"superschema">>();
|
||||
|
||||
const doStuff = (arg: MySchema) => arg;
|
||||
doStuff(mySchema.parse({ name: "hello there" }));
|
||||
|
||||
// inheritance
|
||||
const extendedSchema = mySchema.brand<"subschema">();
|
||||
type ExtendedSchema = z.infer<typeof extendedSchema>;
|
||||
expectTypeOf<ExtendedSchema>().toEqualTypeOf<{ name: string } & z.BRAND<"superschema"> & z.BRAND<"subschema">>();
|
||||
|
||||
doStuff(extendedSchema.parse({ name: "hello again" }));
|
||||
|
||||
// number branding
|
||||
const numberSchema = z.number().brand<42>();
|
||||
type NumberSchema = z.infer<typeof numberSchema>;
|
||||
expectTypeOf<NumberSchema>().toEqualTypeOf<number & { [z.$brand]: { 42: true } }>();
|
||||
|
||||
// symbol branding
|
||||
const MyBrand: unique symbol = Symbol("hello");
|
||||
type MyBrand = typeof MyBrand;
|
||||
const symbolBrand = z.number().brand<"sup">().brand<typeof MyBrand>();
|
||||
type SymbolBrand = z.infer<typeof symbolBrand>;
|
||||
// number & { [z.BRAND]: { sup: true, [MyBrand]: true } }
|
||||
expectTypeOf<SymbolBrand>().toEqualTypeOf<number & z.BRAND<"sup"> & z.BRAND<MyBrand>>();
|
||||
|
||||
// keeping brands out of input types
|
||||
const age = z.number().brand<"age">();
|
||||
|
||||
type Age = z.infer<typeof age>;
|
||||
type AgeInput = z.input<typeof age>;
|
||||
|
||||
expectTypeOf<AgeInput>().not.toEqualTypeOf<Age>();
|
||||
expectTypeOf<number>().toEqualTypeOf<AgeInput>();
|
||||
expectTypeOf<number & z.BRAND<"age">>().toEqualTypeOf<Age>();
|
||||
|
||||
// @ts-expect-error
|
||||
doStuff({ name: "hello there!" });
|
||||
});
|
||||
|
||||
test("$branded", () => {
|
||||
const a = z.string().brand<"a">();
|
||||
|
||||
expectTypeOf<typeof a>().toEqualTypeOf<z.core.$ZodBranded<z.ZodString, "a">>();
|
||||
});
|
||||
|
||||
test("branded record", () => {
|
||||
const recordWithBrandedNumberKeys = z.record(z.string().brand("SomeBrand"), z.number());
|
||||
type recordWithBrandedNumberKeys = z.infer<typeof recordWithBrandedNumberKeys>;
|
||||
expectTypeOf<recordWithBrandedNumberKeys>().toEqualTypeOf<Record<string & z.core.$brand<"SomeBrand">, number>>();
|
||||
});
|
||||
|
||||
test("brand direction: out (default)", () => {
|
||||
const schema = z.string().brand<"A">();
|
||||
type Input = z.input<typeof schema>;
|
||||
type Output = z.output<typeof schema>;
|
||||
|
||||
// output is branded
|
||||
expectTypeOf<Output>().toEqualTypeOf<string & z.$brand<"A">>();
|
||||
// input is NOT branded (default behavior)
|
||||
expectTypeOf<Input>().toEqualTypeOf<string>();
|
||||
});
|
||||
|
||||
test("brand direction: out (explicit)", () => {
|
||||
const schema = z.string().brand<"A", "out">();
|
||||
type Input = z.input<typeof schema>;
|
||||
type Output = z.output<typeof schema>;
|
||||
|
||||
// output is branded
|
||||
expectTypeOf<Output>().toEqualTypeOf<string & z.$brand<"A">>();
|
||||
// input is NOT branded
|
||||
expectTypeOf<Input>().toEqualTypeOf<string>();
|
||||
});
|
||||
|
||||
test("brand direction: in", () => {
|
||||
const schema = z.string().brand<"A", "in">();
|
||||
type Input = z.input<typeof schema>;
|
||||
type Output = z.output<typeof schema>;
|
||||
|
||||
// input is branded
|
||||
expectTypeOf<Input>().toEqualTypeOf<string & z.$brand<"A">>();
|
||||
// output is NOT branded
|
||||
expectTypeOf<Output>().toEqualTypeOf<string>();
|
||||
});
|
||||
|
||||
test("brand direction: inout", () => {
|
||||
const schema = z.string().brand<"A", "inout">();
|
||||
type Input = z.input<typeof schema>;
|
||||
type Output = z.output<typeof schema>;
|
||||
|
||||
// both are branded
|
||||
expectTypeOf<Input>().toEqualTypeOf<string & z.$brand<"A">>();
|
||||
expectTypeOf<Output>().toEqualTypeOf<string & z.$brand<"A">>();
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
// THIS CODE WAS AUTOMATICALLY GENERATED
|
||||
// DO NOT EDIT THIS CODE BY HAND
|
||||
// RUN THE FOLLOWING COMMAND FROM THE WORKSPACE ROOT TO REGENERATE:
|
||||
// npx nx generate-lib repo
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.es2024_collection = void 0;
|
||||
const base_config_1 = require("./base-config");
|
||||
exports.es2024_collection = {
|
||||
libs: [],
|
||||
variables: [['MapConstructor', base_config_1.TYPE]],
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import type * as ts from 'typescript';
|
||||
export declare enum Awaitable {
|
||||
Always = 0,
|
||||
Never = 1,
|
||||
May = 2
|
||||
}
|
||||
export declare function needsToBeAwaited(checker: ts.TypeChecker, node: ts.Node, type: ts.Type): Awaitable;
|
||||
@@ -0,0 +1,130 @@
|
||||
// Generated by LiveScript 1.6.0
|
||||
var max, min, negate, abs, signum, quot, rem, div, mod, recip, pi, tau, exp, sqrt, ln, pow, sin, tan, cos, asin, acos, atan, atan2, truncate, round, ceiling, floor, isItNaN, even, odd, gcd, lcm;
|
||||
max = curry$(function(x$, y$){
|
||||
return x$ > y$ ? x$ : y$;
|
||||
});
|
||||
min = curry$(function(x$, y$){
|
||||
return x$ < y$ ? x$ : y$;
|
||||
});
|
||||
negate = function(x){
|
||||
return -x;
|
||||
};
|
||||
abs = Math.abs;
|
||||
signum = function(x){
|
||||
if (x < 0) {
|
||||
return -1;
|
||||
} else if (x > 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
quot = curry$(function(x, y){
|
||||
return ~~(x / y);
|
||||
});
|
||||
rem = curry$(function(x$, y$){
|
||||
return x$ % y$;
|
||||
});
|
||||
div = curry$(function(x, y){
|
||||
return Math.floor(x / y);
|
||||
});
|
||||
mod = curry$(function(x$, y$){
|
||||
var ref$;
|
||||
return ((x$) % (ref$ = y$) + ref$) % ref$;
|
||||
});
|
||||
recip = (function(it){
|
||||
return 1 / it;
|
||||
});
|
||||
pi = Math.PI;
|
||||
tau = pi * 2;
|
||||
exp = Math.exp;
|
||||
sqrt = Math.sqrt;
|
||||
ln = Math.log;
|
||||
pow = curry$(function(x$, y$){
|
||||
return Math.pow(x$, y$);
|
||||
});
|
||||
sin = Math.sin;
|
||||
tan = Math.tan;
|
||||
cos = Math.cos;
|
||||
asin = Math.asin;
|
||||
acos = Math.acos;
|
||||
atan = Math.atan;
|
||||
atan2 = curry$(function(x, y){
|
||||
return Math.atan2(x, y);
|
||||
});
|
||||
truncate = function(x){
|
||||
return ~~x;
|
||||
};
|
||||
round = Math.round;
|
||||
ceiling = Math.ceil;
|
||||
floor = Math.floor;
|
||||
isItNaN = function(x){
|
||||
return x !== x;
|
||||
};
|
||||
even = function(x){
|
||||
return x % 2 === 0;
|
||||
};
|
||||
odd = function(x){
|
||||
return x % 2 !== 0;
|
||||
};
|
||||
gcd = curry$(function(x, y){
|
||||
var z;
|
||||
x = Math.abs(x);
|
||||
y = Math.abs(y);
|
||||
while (y !== 0) {
|
||||
z = x % y;
|
||||
x = y;
|
||||
y = z;
|
||||
}
|
||||
return x;
|
||||
});
|
||||
lcm = curry$(function(x, y){
|
||||
return Math.abs(Math.floor(x / gcd(x, y) * y));
|
||||
});
|
||||
module.exports = {
|
||||
max: max,
|
||||
min: min,
|
||||
negate: negate,
|
||||
abs: abs,
|
||||
signum: signum,
|
||||
quot: quot,
|
||||
rem: rem,
|
||||
div: div,
|
||||
mod: mod,
|
||||
recip: recip,
|
||||
pi: pi,
|
||||
tau: tau,
|
||||
exp: exp,
|
||||
sqrt: sqrt,
|
||||
ln: ln,
|
||||
pow: pow,
|
||||
sin: sin,
|
||||
tan: tan,
|
||||
cos: cos,
|
||||
acos: acos,
|
||||
asin: asin,
|
||||
atan: atan,
|
||||
atan2: atan2,
|
||||
truncate: truncate,
|
||||
round: round,
|
||||
ceiling: ceiling,
|
||||
floor: floor,
|
||||
isItNaN: isItNaN,
|
||||
even: even,
|
||||
odd: odd,
|
||||
gcd: gcd,
|
||||
lcm: lcm
|
||||
};
|
||||
function curry$(f, bound){
|
||||
var context,
|
||||
_curry = function(args) {
|
||||
return f.length > 1 ? function(){
|
||||
var params = args ? args.concat() : [];
|
||||
context = bound ? context || this : this;
|
||||
return params.push.apply(params, arguments) <
|
||||
f.length && arguments.length ?
|
||||
_curry.call(context, params) : f.apply(context, params);
|
||||
} : f;
|
||||
};
|
||||
return _curry();
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
import type { OperatorPrecedence } from './getOperatorPrecedence';
|
||||
export declare function getWrappedCode(text: string, nodePrecedence: OperatorPrecedence, parentPrecedence: OperatorPrecedence): string;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
// Code generated by Herebyfile.mjs generate:enums from internal/core/compileroptions.go. DO NOT EDIT.
|
||||
export var ModuleResolutionKind;
|
||||
(function (ModuleResolutionKind) {
|
||||
ModuleResolutionKind[ModuleResolutionKind["Unknown"] = 0] = "Unknown";
|
||||
ModuleResolutionKind[ModuleResolutionKind["Classic"] = 1] = "Classic";
|
||||
ModuleResolutionKind[ModuleResolutionKind["Node10"] = 2] = "Node10";
|
||||
ModuleResolutionKind[ModuleResolutionKind["Node16"] = 3] = "Node16";
|
||||
ModuleResolutionKind[ModuleResolutionKind["NodeNext"] = 99] = "NodeNext";
|
||||
ModuleResolutionKind[ModuleResolutionKind["Bundler"] = 100] = "Bundler";
|
||||
})(ModuleResolutionKind || (ModuleResolutionKind = {}));
|
||||
//# sourceMappingURL=moduleResolutionKind.enum.js.map
|
||||
@@ -0,0 +1,476 @@
|
||||
/**
|
||||
* @fileoverview Rule to flag missing semicolons.
|
||||
* @author Nicholas C. Zakas
|
||||
* @deprecated in ESLint v8.53.0
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const FixTracker = require("./utils/fix-tracker");
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
deprecated: {
|
||||
message: "Formatting rules are being moved out of ESLint core.",
|
||||
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
||||
deprecatedSince: "8.53.0",
|
||||
availableUntil: "11.0.0",
|
||||
replacedBy: [
|
||||
{
|
||||
message:
|
||||
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
||||
url: "https://eslint.style/guide/migration",
|
||||
plugin: {
|
||||
name: "@stylistic/eslint-plugin",
|
||||
url: "https://eslint.style",
|
||||
},
|
||||
rule: {
|
||||
name: "semi",
|
||||
url: "https://eslint.style/rules/semi",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
type: "layout",
|
||||
|
||||
docs: {
|
||||
description: "Require or disallow semicolons instead of ASI",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/semi",
|
||||
},
|
||||
|
||||
fixable: "code",
|
||||
|
||||
schema: {
|
||||
anyOf: [
|
||||
{
|
||||
type: "array",
|
||||
items: [
|
||||
{
|
||||
enum: ["never"],
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
beforeStatementContinuationChars: {
|
||||
enum: ["always", "any", "never"],
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
minItems: 0,
|
||||
maxItems: 2,
|
||||
},
|
||||
{
|
||||
type: "array",
|
||||
items: [
|
||||
{
|
||||
enum: ["always"],
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
omitLastInOneLineBlock: { type: "boolean" },
|
||||
omitLastInOneLineClassBody: { type: "boolean" },
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
minItems: 0,
|
||||
maxItems: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
messages: {
|
||||
missingSemi: "Missing semicolon.",
|
||||
extraSemi: "Extra semicolon.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const OPT_OUT_PATTERN = /^[-[(/+`]/u; // One of [(/+-`
|
||||
const unsafeClassFieldNames = new Set(["get", "set", "static"]);
|
||||
const unsafeClassFieldFollowers = new Set(["*", "in", "instanceof"]);
|
||||
const options = context.options[1];
|
||||
const never = context.options[0] === "never";
|
||||
const exceptOneLine = Boolean(
|
||||
options && options.omitLastInOneLineBlock,
|
||||
);
|
||||
const exceptOneLineClassBody = Boolean(
|
||||
options && options.omitLastInOneLineClassBody,
|
||||
);
|
||||
const beforeStatementContinuationChars =
|
||||
(options && options.beforeStatementContinuationChars) || "any";
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reports a semicolon error with appropriate location and message.
|
||||
* @param {ASTNode} node The node with an extra or missing semicolon.
|
||||
* @param {boolean} missing True if the semicolon is missing.
|
||||
* @returns {void}
|
||||
*/
|
||||
function report(node, missing) {
|
||||
const lastToken = sourceCode.getLastToken(node);
|
||||
let messageId, fix, loc;
|
||||
|
||||
if (!missing) {
|
||||
messageId = "missingSemi";
|
||||
loc = {
|
||||
start: lastToken.loc.end,
|
||||
end: astUtils.getNextLocation(
|
||||
sourceCode,
|
||||
lastToken.loc.end,
|
||||
),
|
||||
};
|
||||
fix = function (fixer) {
|
||||
return fixer.insertTextAfter(lastToken, ";");
|
||||
};
|
||||
} else {
|
||||
messageId = "extraSemi";
|
||||
loc = lastToken.loc;
|
||||
fix = function (fixer) {
|
||||
/*
|
||||
* Expand the replacement range to include the surrounding
|
||||
* tokens to avoid conflicting with no-extra-semi.
|
||||
* https://github.com/eslint/eslint/issues/7928
|
||||
*/
|
||||
return new FixTracker(fixer, sourceCode)
|
||||
.retainSurroundingTokens(lastToken)
|
||||
.remove(lastToken);
|
||||
};
|
||||
}
|
||||
|
||||
context.report({
|
||||
node,
|
||||
loc,
|
||||
messageId,
|
||||
fix,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given semicolon token is redundant.
|
||||
* @param {Token} semiToken A semicolon token to check.
|
||||
* @returns {boolean} `true` if the next token is `;` or `}`.
|
||||
*/
|
||||
function isRedundantSemi(semiToken) {
|
||||
const nextToken = sourceCode.getTokenAfter(semiToken);
|
||||
|
||||
return (
|
||||
!nextToken ||
|
||||
astUtils.isClosingBraceToken(nextToken) ||
|
||||
astUtils.isSemicolonToken(nextToken)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given token is the closing brace of an arrow function.
|
||||
* @param {Token} lastToken A token to check.
|
||||
* @returns {boolean} `true` if the token is the closing brace of an arrow function.
|
||||
*/
|
||||
function isEndOfArrowBlock(lastToken) {
|
||||
if (!astUtils.isClosingBraceToken(lastToken)) {
|
||||
return false;
|
||||
}
|
||||
const node = sourceCode.getNodeByRangeIndex(lastToken.range[0]);
|
||||
|
||||
return (
|
||||
node.type === "BlockStatement" &&
|
||||
node.parent.type === "ArrowFunctionExpression"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given PropertyDefinition node followed by a semicolon
|
||||
* can safely remove that semicolon. It is not to safe to remove if
|
||||
* the class field name is "get", "set", or "static", or if
|
||||
* followed by a generator method.
|
||||
* @param {ASTNode} node The node to check.
|
||||
* @returns {boolean} `true` if the node cannot have the semicolon
|
||||
* removed.
|
||||
*/
|
||||
function maybeClassFieldAsiHazard(node) {
|
||||
if (node.type !== "PropertyDefinition") {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Computed property names and non-identifiers are always safe
|
||||
* as they can be distinguished from keywords easily.
|
||||
*/
|
||||
const needsNameCheck =
|
||||
!node.computed && node.key.type === "Identifier";
|
||||
|
||||
/*
|
||||
* Certain names are problematic unless they also have a
|
||||
* a way to distinguish between keywords and property
|
||||
* names.
|
||||
*/
|
||||
if (needsNameCheck && unsafeClassFieldNames.has(node.key.name)) {
|
||||
/*
|
||||
* Special case: If the field name is `static`,
|
||||
* it is only valid if the field is marked as static,
|
||||
* so "static static" is okay but "static" is not.
|
||||
*/
|
||||
const isStaticStatic =
|
||||
node.static && node.key.name === "static";
|
||||
|
||||
/*
|
||||
* For other unsafe names, we only care if there is no
|
||||
* initializer. No initializer = hazard.
|
||||
*/
|
||||
if (!isStaticStatic && !node.value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const followingToken = sourceCode.getTokenAfter(node);
|
||||
|
||||
return unsafeClassFieldFollowers.has(followingToken.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given node is on the same line with the next token.
|
||||
* @param {Node} node A statement node to check.
|
||||
* @returns {boolean} `true` if the node is on the same line with the next token.
|
||||
*/
|
||||
function isOnSameLineWithNextToken(node) {
|
||||
const prevToken = sourceCode.getLastToken(node, 1);
|
||||
const nextToken = sourceCode.getTokenAfter(node);
|
||||
|
||||
return (
|
||||
!!nextToken && astUtils.isTokenOnSameLine(prevToken, nextToken)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given node can connect the next line if the next line is unreliable.
|
||||
* @param {Node} node A statement node to check.
|
||||
* @returns {boolean} `true` if the node can connect the next line.
|
||||
*/
|
||||
function maybeAsiHazardAfter(node) {
|
||||
const t = node.type;
|
||||
|
||||
if (
|
||||
t === "DoWhileStatement" ||
|
||||
t === "BreakStatement" ||
|
||||
t === "ContinueStatement" ||
|
||||
t === "DebuggerStatement" ||
|
||||
t === "ImportDeclaration" ||
|
||||
t === "ExportAllDeclaration"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (t === "ReturnStatement") {
|
||||
return Boolean(node.argument);
|
||||
}
|
||||
if (t === "ExportNamedDeclaration") {
|
||||
return Boolean(node.declaration);
|
||||
}
|
||||
if (isEndOfArrowBlock(sourceCode.getLastToken(node, 1))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given token can connect the previous statement.
|
||||
* @param {Token} token A token to check.
|
||||
* @returns {boolean} `true` if the token is one of `[`, `(`, `/`, `+`, `-`, ```, `++`, and `--`.
|
||||
*/
|
||||
function maybeAsiHazardBefore(token) {
|
||||
return (
|
||||
Boolean(token) &&
|
||||
OPT_OUT_PATTERN.test(token.value) &&
|
||||
token.value !== "++" &&
|
||||
token.value !== "--"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the semicolon of a given node is unnecessary, only true if:
|
||||
* - next token is a valid statement divider (`;` or `}`).
|
||||
* - next token is on a new line and the node is not connectable to the new line.
|
||||
* @param {Node} node A statement node to check.
|
||||
* @returns {boolean} whether the semicolon is unnecessary.
|
||||
*/
|
||||
function canRemoveSemicolon(node) {
|
||||
if (isRedundantSemi(sourceCode.getLastToken(node))) {
|
||||
return true; // `;;` or `;}`
|
||||
}
|
||||
if (maybeClassFieldAsiHazard(node)) {
|
||||
return false;
|
||||
}
|
||||
if (isOnSameLineWithNextToken(node)) {
|
||||
return false; // One liner.
|
||||
}
|
||||
|
||||
// continuation characters should not apply to class fields
|
||||
if (
|
||||
node.type !== "PropertyDefinition" &&
|
||||
beforeStatementContinuationChars === "never" &&
|
||||
!maybeAsiHazardAfter(node)
|
||||
) {
|
||||
return true; // ASI works. This statement doesn't connect to the next.
|
||||
}
|
||||
if (!maybeAsiHazardBefore(sourceCode.getTokenAfter(node))) {
|
||||
return true; // ASI works. The next token doesn't connect to this statement.
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a node to see if it's the last item in a one-liner block.
|
||||
* Block is any `BlockStatement` or `StaticBlock` node. Block is a one-liner if its
|
||||
* braces (and consequently everything between them) are on the same line.
|
||||
* @param {ASTNode} node The node to check.
|
||||
* @returns {boolean} whether the node is the last item in a one-liner block.
|
||||
*/
|
||||
function isLastInOneLinerBlock(node) {
|
||||
const parent = node.parent;
|
||||
const nextToken = sourceCode.getTokenAfter(node);
|
||||
|
||||
if (!nextToken || nextToken.value !== "}") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (parent.type === "BlockStatement") {
|
||||
return parent.loc.start.line === parent.loc.end.line;
|
||||
}
|
||||
|
||||
if (parent.type === "StaticBlock") {
|
||||
const openingBrace = sourceCode.getFirstToken(parent, {
|
||||
skip: 1,
|
||||
}); // skip the `static` token
|
||||
|
||||
return openingBrace.loc.start.line === parent.loc.end.line;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a node to see if it's the last item in a one-liner `ClassBody` node.
|
||||
* ClassBody is a one-liner if its braces (and consequently everything between them) are on the same line.
|
||||
* @param {ASTNode} node The node to check.
|
||||
* @returns {boolean} whether the node is the last item in a one-liner ClassBody.
|
||||
*/
|
||||
function isLastInOneLinerClassBody(node) {
|
||||
const parent = node.parent;
|
||||
const nextToken = sourceCode.getTokenAfter(node);
|
||||
|
||||
if (!nextToken || nextToken.value !== "}") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (parent.type === "ClassBody") {
|
||||
return parent.loc.start.line === parent.loc.end.line;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a node to see if it's followed by a semicolon.
|
||||
* @param {ASTNode} node The node to check.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkForSemicolon(node) {
|
||||
const isSemi = astUtils.isSemicolonToken(
|
||||
sourceCode.getLastToken(node),
|
||||
);
|
||||
|
||||
if (never) {
|
||||
if (isSemi && canRemoveSemicolon(node)) {
|
||||
report(node, true);
|
||||
} else if (
|
||||
!isSemi &&
|
||||
beforeStatementContinuationChars === "always" &&
|
||||
node.type !== "PropertyDefinition" &&
|
||||
maybeAsiHazardBefore(sourceCode.getTokenAfter(node))
|
||||
) {
|
||||
report(node);
|
||||
}
|
||||
} else {
|
||||
const oneLinerBlock =
|
||||
exceptOneLine && isLastInOneLinerBlock(node);
|
||||
const oneLinerClassBody =
|
||||
exceptOneLineClassBody && isLastInOneLinerClassBody(node);
|
||||
const oneLinerBlockOrClassBody =
|
||||
oneLinerBlock || oneLinerClassBody;
|
||||
|
||||
if (isSemi && oneLinerBlockOrClassBody) {
|
||||
report(node, true);
|
||||
} else if (!isSemi && !oneLinerBlockOrClassBody) {
|
||||
report(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if there's a semicolon after a variable declaration.
|
||||
* @param {ASTNode} node The node to check.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkForSemicolonForVariableDeclaration(node) {
|
||||
const parent = node.parent;
|
||||
|
||||
if (
|
||||
(parent.type !== "ForStatement" || parent.init !== node) &&
|
||||
(!/^For(?:In|Of)Statement/u.test(parent.type) ||
|
||||
parent.left !== node)
|
||||
) {
|
||||
checkForSemicolon(node);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public API
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
VariableDeclaration: checkForSemicolonForVariableDeclaration,
|
||||
ExpressionStatement: checkForSemicolon,
|
||||
ReturnStatement: checkForSemicolon,
|
||||
ThrowStatement: checkForSemicolon,
|
||||
DoWhileStatement: checkForSemicolon,
|
||||
DebuggerStatement: checkForSemicolon,
|
||||
BreakStatement: checkForSemicolon,
|
||||
ContinueStatement: checkForSemicolon,
|
||||
ImportDeclaration: checkForSemicolon,
|
||||
ExportAllDeclaration: checkForSemicolon,
|
||||
ExportNamedDeclaration(node) {
|
||||
if (!node.declaration) {
|
||||
checkForSemicolon(node);
|
||||
}
|
||||
},
|
||||
ExportDefaultDeclaration(node) {
|
||||
if (
|
||||
!/(?:Class|Function)Declaration/u.test(
|
||||
node.declaration.type,
|
||||
)
|
||||
) {
|
||||
checkForSemicolon(node);
|
||||
}
|
||||
},
|
||||
PropertyDefinition: checkForSemicolon,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,89 @@
|
||||
declare module "node:punycode" {
|
||||
/**
|
||||
* The `punycode.decode()` method converts a [Punycode](https://tools.ietf.org/html/rfc3492) string of ASCII-only
|
||||
* characters to the equivalent string of Unicode codepoints.
|
||||
*
|
||||
* ```js
|
||||
* punycode.decode('maana-pta'); // 'mañana'
|
||||
* punycode.decode('--dqo34k'); // '☃-⌘'
|
||||
* ```
|
||||
* @since v0.5.1
|
||||
*/
|
||||
function decode(string: string): string;
|
||||
/**
|
||||
* The `punycode.encode()` method converts a string of Unicode codepoints to a [Punycode](https://tools.ietf.org/html/rfc3492) string of ASCII-only characters.
|
||||
*
|
||||
* ```js
|
||||
* punycode.encode('mañana'); // 'maana-pta'
|
||||
* punycode.encode('☃-⌘'); // '--dqo34k'
|
||||
* ```
|
||||
* @since v0.5.1
|
||||
*/
|
||||
function encode(string: string): string;
|
||||
/**
|
||||
* The `punycode.toUnicode()` method converts a string representing a domain name
|
||||
* containing [Punycode](https://tools.ietf.org/html/rfc3492) encoded characters into Unicode. Only the [Punycode](https://tools.ietf.org/html/rfc3492) encoded parts of the domain name are be
|
||||
* converted.
|
||||
*
|
||||
* ```js
|
||||
* // decode domain names
|
||||
* punycode.toUnicode('xn--maana-pta.com'); // 'mañana.com'
|
||||
* punycode.toUnicode('xn----dqo34k.com'); // '☃-⌘.com'
|
||||
* punycode.toUnicode('example.com'); // 'example.com'
|
||||
* ```
|
||||
* @since v0.6.1
|
||||
*/
|
||||
function toUnicode(domain: string): string;
|
||||
/**
|
||||
* The `punycode.toASCII()` method converts a Unicode string representing an
|
||||
* Internationalized Domain Name to [Punycode](https://tools.ietf.org/html/rfc3492). Only the non-ASCII parts of the
|
||||
* domain name will be converted. Calling `punycode.toASCII()` on a string that
|
||||
* already only contains ASCII characters will have no effect.
|
||||
*
|
||||
* ```js
|
||||
* // encode domain names
|
||||
* punycode.toASCII('mañana.com'); // 'xn--maana-pta.com'
|
||||
* punycode.toASCII('☃-⌘.com'); // 'xn----dqo34k.com'
|
||||
* punycode.toASCII('example.com'); // 'example.com'
|
||||
* ```
|
||||
* @since v0.6.1
|
||||
*/
|
||||
function toASCII(domain: string): string;
|
||||
/**
|
||||
* @deprecated since v7.0.0
|
||||
* The version of the punycode module bundled in Node.js is being deprecated.
|
||||
* In a future major version of Node.js this module will be removed.
|
||||
* Users currently depending on the punycode module should switch to using
|
||||
* the userland-provided Punycode.js module instead.
|
||||
*/
|
||||
const ucs2: ucs2;
|
||||
interface ucs2 {
|
||||
/**
|
||||
* @deprecated since v7.0.0
|
||||
* The version of the punycode module bundled in Node.js is being deprecated.
|
||||
* In a future major version of Node.js this module will be removed.
|
||||
* Users currently depending on the punycode module should switch to using
|
||||
* the userland-provided Punycode.js module instead.
|
||||
*/
|
||||
decode(string: string): number[];
|
||||
/**
|
||||
* @deprecated since v7.0.0
|
||||
* The version of the punycode module bundled in Node.js is being deprecated.
|
||||
* In a future major version of Node.js this module will be removed.
|
||||
* Users currently depending on the punycode module should switch to using
|
||||
* the userland-provided Punycode.js module instead.
|
||||
*/
|
||||
encode(codePoints: readonly number[]): string;
|
||||
}
|
||||
/**
|
||||
* @deprecated since v7.0.0
|
||||
* The version of the punycode module bundled in Node.js is being deprecated.
|
||||
* In a future major version of Node.js this module will be removed.
|
||||
* Users currently depending on the punycode module should switch to using
|
||||
* the userland-provided Punycode.js module instead.
|
||||
*/
|
||||
const version: string;
|
||||
}
|
||||
declare module "punycode" {
|
||||
export * from "node:punycode";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
global.process = { __proto__: process, pid: 123456 }
|
||||
Date.now = function () { return 1459875739796 }
|
||||
require('node:os').hostname = function () { return 'abcdefghijklmnopqr' }
|
||||
const pino = require(require.resolve('./../../'))
|
||||
const dest = pino.destination({ dest: 1, minLength: 4096, sync: false })
|
||||
const logger = pino({}, dest)
|
||||
logger.info('hello')
|
||||
logger.info('world')
|
||||
process.exit(0)
|
||||
@@ -0,0 +1,142 @@
|
||||
/*! *****************************************************************************
|
||||
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.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
declare namespace Reflect {
|
||||
/**
|
||||
* Calls the function with the specified object as the this value
|
||||
* and the elements of specified array as the arguments.
|
||||
* @param target The function to call.
|
||||
* @param thisArgument The object to be used as the this object.
|
||||
* @param argumentsList An array of argument values to be passed to the function.
|
||||
*/
|
||||
function apply<T, A extends readonly any[], R>(
|
||||
target: (this: T, ...args: A) => R,
|
||||
thisArgument: T,
|
||||
argumentsList: Readonly<A>,
|
||||
): R;
|
||||
function apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;
|
||||
|
||||
/**
|
||||
* Constructs the target with the elements of specified array as the arguments
|
||||
* and the specified constructor as the `new.target` value.
|
||||
* @param target The constructor to invoke.
|
||||
* @param argumentsList An array of argument values to be passed to the constructor.
|
||||
* @param newTarget The constructor to be used as the `new.target` object.
|
||||
*/
|
||||
function construct<A extends readonly any[], R>(
|
||||
target: new (...args: A) => R,
|
||||
argumentsList: Readonly<A>,
|
||||
newTarget?: new (...args: any) => any,
|
||||
): R;
|
||||
function construct(target: Function, argumentsList: ArrayLike<any>, newTarget?: Function): any;
|
||||
|
||||
/**
|
||||
* Adds a property to an object, or modifies attributes of an existing property.
|
||||
* @param target Object on which to add or modify the property. This can be a native JavaScript object
|
||||
* (that is, a user-defined object or a built in object) or a DOM object.
|
||||
* @param propertyKey The property name.
|
||||
* @param attributes Descriptor for the property. It can be for a data property or an accessor property.
|
||||
*/
|
||||
function defineProperty(target: object, propertyKey: PropertyKey, attributes: PropertyDescriptor & ThisType<any>): boolean;
|
||||
|
||||
/**
|
||||
* Removes a property from an object, equivalent to `delete target[propertyKey]`,
|
||||
* except it won't throw if `target[propertyKey]` is non-configurable.
|
||||
* @param target Object from which to remove the own property.
|
||||
* @param propertyKey The property name.
|
||||
*/
|
||||
function deleteProperty(target: object, propertyKey: PropertyKey): boolean;
|
||||
|
||||
/**
|
||||
* Gets the property of target, equivalent to `target[propertyKey]` when `receiver === target`.
|
||||
* @param target Object that contains the property on itself or in its prototype chain.
|
||||
* @param propertyKey The property name.
|
||||
* @param receiver The reference to use as the `this` value in the getter function,
|
||||
* if `target[propertyKey]` is an accessor property.
|
||||
*/
|
||||
function get<T extends object, P extends PropertyKey>(
|
||||
target: T,
|
||||
propertyKey: P,
|
||||
receiver?: unknown,
|
||||
): P extends keyof T ? T[P] : any;
|
||||
|
||||
/**
|
||||
* Gets the own property descriptor of the specified object.
|
||||
* An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype.
|
||||
* @param target Object that contains the property.
|
||||
* @param propertyKey The property name.
|
||||
*/
|
||||
function getOwnPropertyDescriptor<T extends object, P extends PropertyKey>(
|
||||
target: T,
|
||||
propertyKey: P,
|
||||
): TypedPropertyDescriptor<P extends keyof T ? T[P] : any> | undefined;
|
||||
|
||||
/**
|
||||
* Returns the prototype of an object.
|
||||
* @param target The object that references the prototype.
|
||||
*/
|
||||
function getPrototypeOf(target: object): object | null;
|
||||
|
||||
/**
|
||||
* Equivalent to `propertyKey in target`.
|
||||
* @param target Object that contains the property on itself or in its prototype chain.
|
||||
* @param propertyKey Name of the property.
|
||||
*/
|
||||
function has(target: object, propertyKey: PropertyKey): boolean;
|
||||
|
||||
/**
|
||||
* Returns a value that indicates whether new properties can be added to an object.
|
||||
* @param target Object to test.
|
||||
*/
|
||||
function isExtensible(target: object): boolean;
|
||||
|
||||
/**
|
||||
* Returns the string and symbol keys of the own properties of an object. The own properties of an object
|
||||
* are those that are defined directly on that object, and are not inherited from the object's prototype.
|
||||
* @param target Object that contains the own properties.
|
||||
*/
|
||||
function ownKeys(target: object): (string | symbol)[];
|
||||
|
||||
/**
|
||||
* Prevents the addition of new properties to an object.
|
||||
* @param target Object to make non-extensible.
|
||||
* @return Whether the object has been made non-extensible.
|
||||
*/
|
||||
function preventExtensions(target: object): boolean;
|
||||
|
||||
/**
|
||||
* Sets the property of target, equivalent to `target[propertyKey] = value` when `receiver === target`.
|
||||
* @param target Object that contains the property on itself or in its prototype chain.
|
||||
* @param propertyKey Name of the property.
|
||||
* @param receiver The reference to use as the `this` value in the setter function,
|
||||
* if `target[propertyKey]` is an accessor property.
|
||||
*/
|
||||
function set<T extends object, P extends PropertyKey>(
|
||||
target: T,
|
||||
propertyKey: P,
|
||||
value: P extends keyof T ? T[P] : any,
|
||||
receiver?: any,
|
||||
): boolean;
|
||||
function set(target: object, propertyKey: PropertyKey, value: any, receiver?: any): boolean;
|
||||
|
||||
/**
|
||||
* Sets the prototype of a specified object o to object proto or null.
|
||||
* @param target The object to change its prototype.
|
||||
* @param proto The value of the new prototype or null.
|
||||
* @return Whether setting the prototype was successful.
|
||||
*/
|
||||
function setPrototypeOf(target: object, proto: object | null): boolean;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=types.js.map
|
||||
@@ -0,0 +1,135 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tsutils = __importStar(require("ts-api-utils"));
|
||||
const ts = __importStar(require("typescript"));
|
||||
const util_1 = require("../util");
|
||||
const getESLintCoreRule_1 = require("../util/getESLintCoreRule");
|
||||
const baseRule = (0, getESLintCoreRule_1.getESLintCoreRule)('consistent-return');
|
||||
const defaultOptions = [{ treatUndefinedAsUnspecified: false }];
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'consistent-return',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
defaultOptions,
|
||||
docs: {
|
||||
description: 'Require `return` statements to either always or never specify values',
|
||||
extendsBaseRule: true,
|
||||
requiresTypeChecking: true,
|
||||
},
|
||||
hasSuggestions: baseRule.meta.hasSuggestions,
|
||||
messages: baseRule.meta.messages,
|
||||
schema: baseRule.meta.schema,
|
||||
},
|
||||
defaultOptions,
|
||||
create(context, [options]) {
|
||||
const services = (0, util_1.getParserServices)(context);
|
||||
const checker = services.program.getTypeChecker();
|
||||
const rules = baseRule.create(context);
|
||||
const functions = [];
|
||||
const treatUndefinedAsUnspecified = options?.treatUndefinedAsUnspecified === true;
|
||||
function enterFunction(node) {
|
||||
functions.push(node);
|
||||
}
|
||||
function exitFunction() {
|
||||
functions.pop();
|
||||
}
|
||||
function getCurrentFunction() {
|
||||
return functions[functions.length - 1] ?? null;
|
||||
}
|
||||
function isPromiseVoid(node, type) {
|
||||
if (tsutils.isThenableType(checker, node, type) &&
|
||||
tsutils.isTypeReference(type)) {
|
||||
const awaitedType = type.typeArguments?.[0];
|
||||
if (awaitedType) {
|
||||
if ((0, util_1.isTypeFlagSet)(awaitedType, ts.TypeFlags.Void)) {
|
||||
return true;
|
||||
}
|
||||
return isPromiseVoid(node, awaitedType);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function isReturnVoidOrThenableVoid(node) {
|
||||
const functionType = services.getTypeAtLocation(node);
|
||||
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
||||
const callSignatures = functionType.getCallSignatures();
|
||||
return callSignatures.some(signature => {
|
||||
const returnType = signature.getReturnType();
|
||||
if (node.async) {
|
||||
return isPromiseVoid(tsNode, returnType);
|
||||
}
|
||||
return (0, util_1.isTypeFlagSet)(returnType, ts.TypeFlags.Void);
|
||||
});
|
||||
}
|
||||
return {
|
||||
...rules,
|
||||
ArrowFunctionExpression: enterFunction,
|
||||
'ArrowFunctionExpression:exit'(node) {
|
||||
exitFunction();
|
||||
rules['ArrowFunctionExpression:exit'](node);
|
||||
},
|
||||
FunctionDeclaration: enterFunction,
|
||||
'FunctionDeclaration:exit'(node) {
|
||||
exitFunction();
|
||||
rules['FunctionDeclaration:exit'](node);
|
||||
},
|
||||
FunctionExpression: enterFunction,
|
||||
'FunctionExpression:exit'(node) {
|
||||
exitFunction();
|
||||
rules['FunctionExpression:exit'](node);
|
||||
},
|
||||
ReturnStatement(node) {
|
||||
const functionNode = getCurrentFunction();
|
||||
if (!node.argument &&
|
||||
functionNode &&
|
||||
isReturnVoidOrThenableVoid(functionNode)) {
|
||||
return;
|
||||
}
|
||||
if (treatUndefinedAsUnspecified && node.argument) {
|
||||
const returnValueType = services.getTypeAtLocation(node.argument);
|
||||
if (returnValueType.flags === ts.TypeFlags.Undefined) {
|
||||
rules.ReturnStatement({
|
||||
...node,
|
||||
argument: null,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
rules.ReturnStatement(node);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,257 @@
|
||||
/**
|
||||
* @fileoverview Enforce newlines between operands of ternary expressions
|
||||
* @author Kai Cataldo
|
||||
* @deprecated in ESLint v8.53.0
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
deprecated: {
|
||||
message: "Formatting rules are being moved out of ESLint core.",
|
||||
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
||||
deprecatedSince: "8.53.0",
|
||||
availableUntil: "11.0.0",
|
||||
replacedBy: [
|
||||
{
|
||||
message:
|
||||
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
||||
url: "https://eslint.style/guide/migration",
|
||||
plugin: {
|
||||
name: "@stylistic/eslint-plugin",
|
||||
url: "https://eslint.style",
|
||||
},
|
||||
rule: {
|
||||
name: "multiline-ternary",
|
||||
url: "https://eslint.style/rules/multiline-ternary",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
type: "layout",
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Enforce newlines between operands of ternary expressions",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/multiline-ternary",
|
||||
},
|
||||
|
||||
schema: [
|
||||
{
|
||||
enum: ["always", "always-multiline", "never"],
|
||||
},
|
||||
],
|
||||
|
||||
messages: {
|
||||
expectedTestCons:
|
||||
"Expected newline between test and consequent of ternary expression.",
|
||||
expectedConsAlt:
|
||||
"Expected newline between consequent and alternate of ternary expression.",
|
||||
unexpectedTestCons:
|
||||
"Unexpected newline between test and consequent of ternary expression.",
|
||||
unexpectedConsAlt:
|
||||
"Unexpected newline between consequent and alternate of ternary expression.",
|
||||
},
|
||||
|
||||
fixable: "whitespace",
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
const option = context.options[0];
|
||||
const multiline = option !== "never";
|
||||
const allowSingleLine = option === "always-multiline";
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
ConditionalExpression(node) {
|
||||
const questionToken = sourceCode.getTokenAfter(
|
||||
node.test,
|
||||
astUtils.isNotClosingParenToken,
|
||||
);
|
||||
const colonToken = sourceCode.getTokenAfter(
|
||||
node.consequent,
|
||||
astUtils.isNotClosingParenToken,
|
||||
);
|
||||
|
||||
const firstTokenOfTest = sourceCode.getFirstToken(node);
|
||||
const lastTokenOfTest =
|
||||
sourceCode.getTokenBefore(questionToken);
|
||||
const firstTokenOfConsequent =
|
||||
sourceCode.getTokenAfter(questionToken);
|
||||
const lastTokenOfConsequent =
|
||||
sourceCode.getTokenBefore(colonToken);
|
||||
const firstTokenOfAlternate =
|
||||
sourceCode.getTokenAfter(colonToken);
|
||||
|
||||
const areTestAndConsequentOnSameLine =
|
||||
astUtils.isTokenOnSameLine(
|
||||
lastTokenOfTest,
|
||||
firstTokenOfConsequent,
|
||||
);
|
||||
const areConsequentAndAlternateOnSameLine =
|
||||
astUtils.isTokenOnSameLine(
|
||||
lastTokenOfConsequent,
|
||||
firstTokenOfAlternate,
|
||||
);
|
||||
|
||||
const hasComments = !!sourceCode.getCommentsInside(node).length;
|
||||
|
||||
if (!multiline) {
|
||||
if (!areTestAndConsequentOnSameLine) {
|
||||
context.report({
|
||||
node: node.test,
|
||||
loc: {
|
||||
start: firstTokenOfTest.loc.start,
|
||||
end: lastTokenOfTest.loc.end,
|
||||
},
|
||||
messageId: "unexpectedTestCons",
|
||||
fix(fixer) {
|
||||
if (hasComments) {
|
||||
return null;
|
||||
}
|
||||
const fixers = [];
|
||||
const areTestAndQuestionOnSameLine =
|
||||
astUtils.isTokenOnSameLine(
|
||||
lastTokenOfTest,
|
||||
questionToken,
|
||||
);
|
||||
const areQuestionAndConsOnSameLine =
|
||||
astUtils.isTokenOnSameLine(
|
||||
questionToken,
|
||||
firstTokenOfConsequent,
|
||||
);
|
||||
|
||||
if (!areTestAndQuestionOnSameLine) {
|
||||
fixers.push(
|
||||
fixer.removeRange([
|
||||
lastTokenOfTest.range[1],
|
||||
questionToken.range[0],
|
||||
]),
|
||||
);
|
||||
}
|
||||
if (!areQuestionAndConsOnSameLine) {
|
||||
fixers.push(
|
||||
fixer.removeRange([
|
||||
questionToken.range[1],
|
||||
firstTokenOfConsequent.range[0],
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
return fixers;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (!areConsequentAndAlternateOnSameLine) {
|
||||
context.report({
|
||||
node: node.consequent,
|
||||
loc: {
|
||||
start: firstTokenOfConsequent.loc.start,
|
||||
end: lastTokenOfConsequent.loc.end,
|
||||
},
|
||||
messageId: "unexpectedConsAlt",
|
||||
fix(fixer) {
|
||||
if (hasComments) {
|
||||
return null;
|
||||
}
|
||||
const fixers = [];
|
||||
const areConsAndColonOnSameLine =
|
||||
astUtils.isTokenOnSameLine(
|
||||
lastTokenOfConsequent,
|
||||
colonToken,
|
||||
);
|
||||
const areColonAndAltOnSameLine =
|
||||
astUtils.isTokenOnSameLine(
|
||||
colonToken,
|
||||
firstTokenOfAlternate,
|
||||
);
|
||||
|
||||
if (!areConsAndColonOnSameLine) {
|
||||
fixers.push(
|
||||
fixer.removeRange([
|
||||
lastTokenOfConsequent.range[1],
|
||||
colonToken.range[0],
|
||||
]),
|
||||
);
|
||||
}
|
||||
if (!areColonAndAltOnSameLine) {
|
||||
fixers.push(
|
||||
fixer.removeRange([
|
||||
colonToken.range[1],
|
||||
firstTokenOfAlternate.range[0],
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
return fixers;
|
||||
},
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
allowSingleLine &&
|
||||
node.loc.start.line === node.loc.end.line
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (areTestAndConsequentOnSameLine) {
|
||||
context.report({
|
||||
node: node.test,
|
||||
loc: {
|
||||
start: firstTokenOfTest.loc.start,
|
||||
end: lastTokenOfTest.loc.end,
|
||||
},
|
||||
messageId: "expectedTestCons",
|
||||
fix: fixer =>
|
||||
hasComments
|
||||
? null
|
||||
: fixer.replaceTextRange(
|
||||
[
|
||||
lastTokenOfTest.range[1],
|
||||
questionToken.range[0],
|
||||
],
|
||||
"\n",
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
if (areConsequentAndAlternateOnSameLine) {
|
||||
context.report({
|
||||
node: node.consequent,
|
||||
loc: {
|
||||
start: firstTokenOfConsequent.loc.start,
|
||||
end: lastTokenOfConsequent.loc.end,
|
||||
},
|
||||
messageId: "expectedConsAlt",
|
||||
fix: fixer =>
|
||||
hasComments
|
||||
? null
|
||||
: fixer.replaceTextRange(
|
||||
[
|
||||
lastTokenOfConsequent.range[1],
|
||||
colonToken.range[0],
|
||||
],
|
||||
"\n",
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
const { test } = require('node:test')
|
||||
const createDate = require('./create-date')
|
||||
|
||||
const wanted = 1624450038567
|
||||
|
||||
test('accepts arguments the Date constructor would accept', t => {
|
||||
t.plan(2)
|
||||
t.assert.strictEqual(createDate(1624450038567).getTime(), wanted)
|
||||
t.assert.strictEqual(createDate('2021-06-23T12:07:18.567Z').getTime(), wanted)
|
||||
})
|
||||
|
||||
test('accepts epoch as a string', t => {
|
||||
// If Date() accepts this argument, the createDate function is not needed
|
||||
// and can be replaced with Date()
|
||||
t.plan(2)
|
||||
t.assert.notEqual(new Date('16244500385-67').getTime(), wanted)
|
||||
t.assert.strictEqual(createDate('1624450038567').getTime(), wanted)
|
||||
})
|
||||
@@ -0,0 +1,111 @@
|
||||
import Dispatcher from './dispatcher'
|
||||
|
||||
declare namespace MockCallHistoryLog {
|
||||
/** request's configuration properties */
|
||||
export type MockCallHistoryLogProperties = 'protocol' | 'host' | 'port' | 'origin' | 'path' | 'hash' | 'fullUrl' | 'method' | 'searchParams' | 'body' | 'headers'
|
||||
}
|
||||
|
||||
/** a log reflecting request configuration */
|
||||
declare class MockCallHistoryLog {
|
||||
constructor (requestInit: Dispatcher.DispatchOptions)
|
||||
/** protocol used. ie. 'https:' or 'http:' etc... */
|
||||
protocol: string
|
||||
/** request's host. */
|
||||
host: string
|
||||
/** request's port. */
|
||||
port: string
|
||||
/** request's origin. ie. https://localhost:3000. */
|
||||
origin: string
|
||||
/** path. never contains searchParams. */
|
||||
path: string
|
||||
/** request's hash. */
|
||||
hash: string
|
||||
/** the full url requested. */
|
||||
fullUrl: string
|
||||
/** request's method. */
|
||||
method: string
|
||||
/** search params. */
|
||||
searchParams: Record<string, string>
|
||||
/** request's body */
|
||||
body: string | null | undefined
|
||||
/** request's headers */
|
||||
headers: Record<string, string | string[]> | null | undefined
|
||||
|
||||
/** returns an Map of property / value pair */
|
||||
toMap (): Map<MockCallHistoryLog.MockCallHistoryLogProperties, string | Record<string, string | string[]> | null | undefined>
|
||||
|
||||
/** returns a string computed with all key value pair */
|
||||
toString (): string
|
||||
}
|
||||
|
||||
declare namespace MockCallHistory {
|
||||
export type FilterCallsOperator = 'AND' | 'OR'
|
||||
|
||||
/** modify the filtering behavior */
|
||||
export interface FilterCallsOptions {
|
||||
/** the operator to apply when filtering. 'OR' will adds any MockCallHistoryLog matching any criteria given. 'AND' will adds only MockCallHistoryLog matching every criteria given. (default 'OR') */
|
||||
operator?: FilterCallsOperator | Lowercase<FilterCallsOperator>
|
||||
}
|
||||
/** a function to be executed for filtering MockCallHistoryLog */
|
||||
export type FilterCallsFunctionCriteria = (log: MockCallHistoryLog) => boolean
|
||||
|
||||
/** parameter to filter MockCallHistoryLog */
|
||||
export type FilterCallsParameter = string | RegExp | undefined | null
|
||||
|
||||
/** an object to execute multiple filtering at once */
|
||||
export interface FilterCallsObjectCriteria extends Record<string, FilterCallsParameter> {
|
||||
/** filter by request protocol. ie https: */
|
||||
protocol?: FilterCallsParameter;
|
||||
/** filter by request host. */
|
||||
host?: FilterCallsParameter;
|
||||
/** filter by request port. */
|
||||
port?: FilterCallsParameter;
|
||||
/** filter by request origin. */
|
||||
origin?: FilterCallsParameter;
|
||||
/** filter by request path. */
|
||||
path?: FilterCallsParameter;
|
||||
/** filter by request hash. */
|
||||
hash?: FilterCallsParameter;
|
||||
/** filter by request fullUrl. */
|
||||
fullUrl?: FilterCallsParameter;
|
||||
/** filter by request method. */
|
||||
method?: FilterCallsParameter;
|
||||
}
|
||||
}
|
||||
|
||||
/** a call history to track requests configuration */
|
||||
declare class MockCallHistory {
|
||||
constructor (name: string)
|
||||
/** returns an array of MockCallHistoryLog. */
|
||||
calls (): Array<MockCallHistoryLog>
|
||||
/** returns the first MockCallHistoryLog */
|
||||
firstCall (): MockCallHistoryLog | undefined
|
||||
/** returns the last MockCallHistoryLog. */
|
||||
lastCall (): MockCallHistoryLog | undefined
|
||||
/** returns the nth MockCallHistoryLog. */
|
||||
nthCall (position: number): MockCallHistoryLog | undefined
|
||||
/** return all MockCallHistoryLog matching any of criteria given. if an object is used with multiple properties, you can change the operator to apply during filtering on options */
|
||||
filterCalls (criteria: MockCallHistory.FilterCallsFunctionCriteria | MockCallHistory.FilterCallsObjectCriteria | RegExp, options?: MockCallHistory.FilterCallsOptions): Array<MockCallHistoryLog>
|
||||
/** return all MockCallHistoryLog matching the given protocol. if a string is given, it is matched with includes */
|
||||
filterCallsByProtocol (protocol: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
||||
/** return all MockCallHistoryLog matching the given host. if a string is given, it is matched with includes */
|
||||
filterCallsByHost (host: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
||||
/** return all MockCallHistoryLog matching the given port. if a string is given, it is matched with includes */
|
||||
filterCallsByPort (port: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
||||
/** return all MockCallHistoryLog matching the given origin. if a string is given, it is matched with includes */
|
||||
filterCallsByOrigin (origin: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
||||
/** return all MockCallHistoryLog matching the given path. if a string is given, it is matched with includes */
|
||||
filterCallsByPath (path: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
||||
/** return all MockCallHistoryLog matching the given hash. if a string is given, it is matched with includes */
|
||||
filterCallsByHash (hash: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
||||
/** return all MockCallHistoryLog matching the given fullUrl. if a string is given, it is matched with includes */
|
||||
filterCallsByFullUrl (fullUrl: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
||||
/** return all MockCallHistoryLog matching the given method. if a string is given, it is matched with includes */
|
||||
filterCallsByMethod (method: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
||||
/** clear all MockCallHistoryLog on this MockCallHistory. */
|
||||
clear (): void
|
||||
/** use it with for..of loop or spread operator */
|
||||
[Symbol.iterator]: () => Generator<MockCallHistoryLog>
|
||||
}
|
||||
|
||||
export { MockCallHistoryLog, MockCallHistory }
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "postgres-bytea",
|
||||
"main": "index.js",
|
||||
"version": "1.0.1",
|
||||
"description": "Postgres bytea parser",
|
||||
"license": "MIT",
|
||||
"repository": "bendrucker/postgres-bytea",
|
||||
"author": {
|
||||
"name": "Ben Drucker",
|
||||
"email": "bvdrucker@gmail.com",
|
||||
"url": "bendrucker.me"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard && tape test.js"
|
||||
},
|
||||
"keywords": [
|
||||
"bytea",
|
||||
"postgres",
|
||||
"binary",
|
||||
"parser"
|
||||
],
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"tape": "^4.0.0",
|
||||
"standard": "^4.0.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* SHA1 (RFC 3174) legacy hash function.
|
||||
* @module
|
||||
* @deprecated
|
||||
*/
|
||||
import { SHA1 as SHA1n, sha1 as sha1n } from "./legacy.js";
|
||||
/** @deprecated Use import from `noble/hashes/legacy` module */
|
||||
export const SHA1 = SHA1n;
|
||||
/** @deprecated Use import from `noble/hashes/legacy` module */
|
||||
export const sha1 = sha1n;
|
||||
//# sourceMappingURL=sha1.js.map
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* SHA2-512 a.k.a. sha512 and sha384. It is slower than sha256 in js because u64 operations are slow.
|
||||
*
|
||||
* Check out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and
|
||||
* [the paper on truncated SHA512/256](https://eprint.iacr.org/2010/548.pdf).
|
||||
* @module
|
||||
* @deprecated
|
||||
*/
|
||||
import { SHA384 as SHA384n, sha384 as sha384n, sha512_224 as sha512_224n, SHA512_224 as SHA512_224n, sha512_256 as sha512_256n, SHA512_256 as SHA512_256n, SHA512 as SHA512n, sha512 as sha512n, } from "./sha2.js";
|
||||
/** @deprecated Use import from `noble/hashes/sha2` module */
|
||||
export const SHA512 = SHA512n;
|
||||
/** @deprecated Use import from `noble/hashes/sha2` module */
|
||||
export const sha512 = sha512n;
|
||||
/** @deprecated Use import from `noble/hashes/sha2` module */
|
||||
export const SHA384 = SHA384n;
|
||||
/** @deprecated Use import from `noble/hashes/sha2` module */
|
||||
export const sha384 = sha384n;
|
||||
/** @deprecated Use import from `noble/hashes/sha2` module */
|
||||
export const SHA512_224 = SHA512_224n;
|
||||
/** @deprecated Use import from `noble/hashes/sha2` module */
|
||||
export const sha512_224 = sha512_224n;
|
||||
/** @deprecated Use import from `noble/hashes/sha2` module */
|
||||
export const SHA512_256 = SHA512_256n;
|
||||
/** @deprecated Use import from `noble/hashes/sha2` module */
|
||||
export const sha512_256 = sha512_256n;
|
||||
//# sourceMappingURL=sha512.js.map
|
||||
@@ -0,0 +1 @@
|
||||
export { _ as default } from "../esm/_get_prototype_of.js";
|
||||
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
var parse = require('../');
|
||||
var test = require('tape');
|
||||
|
||||
test('dotted alias', function (t) {
|
||||
var argv = parse(['--a.b', '22'], { default: { 'a.b': 11 }, alias: { 'a.b': 'aa.bb' } });
|
||||
t.equal(argv.a.b, 22);
|
||||
t.equal(argv.aa.bb, 22);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('dotted default', function (t) {
|
||||
var argv = parse('', { default: { 'a.b': 11 }, alias: { 'a.b': 'aa.bb' } });
|
||||
t.equal(argv.a.b, 11);
|
||||
t.equal(argv.aa.bb, 11);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('dotted default with no alias', function (t) {
|
||||
var argv = parse('', { default: { 'a.b': 11 } });
|
||||
t.equal(argv.a.b, 11);
|
||||
t.end();
|
||||
});
|
||||
@@ -0,0 +1,129 @@
|
||||
import type { $ZodStringFormats } from "../core/checks.js";
|
||||
import type * as errors from "../core/errors.js";
|
||||
import * as util from "../core/util.js";
|
||||
|
||||
const error: () => errors.$ZodErrorMap = () => {
|
||||
const Sizable: Record<string, { unit: string; verb: string }> = {
|
||||
string: { unit: "caractere", verb: "să aibă" },
|
||||
file: { unit: "octeți", verb: "să aibă" },
|
||||
array: { unit: "elemente", verb: "să aibă" },
|
||||
set: { unit: "elemente", verb: "să aibă" },
|
||||
map: { unit: "intrări", verb: "să aibă" },
|
||||
};
|
||||
|
||||
function getSizing(origin: string): { unit: string; verb: string } | null {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
|
||||
const FormatDictionary: {
|
||||
[k in $ZodStringFormats | (string & {})]?: string;
|
||||
} = {
|
||||
regex: "intrare",
|
||||
email: "adresă de email",
|
||||
url: "URL",
|
||||
emoji: "emoji",
|
||||
uuid: "UUID",
|
||||
uuidv4: "UUIDv4",
|
||||
uuidv6: "UUIDv6",
|
||||
nanoid: "nanoid",
|
||||
guid: "GUID",
|
||||
cuid: "cuid",
|
||||
cuid2: "cuid2",
|
||||
ulid: "ULID",
|
||||
xid: "XID",
|
||||
ksuid: "KSUID",
|
||||
datetime: "dată și oră ISO",
|
||||
date: "dată ISO",
|
||||
time: "oră ISO",
|
||||
duration: "durată ISO",
|
||||
ipv4: "adresă IPv4",
|
||||
ipv6: "adresă IPv6",
|
||||
mac: "adresă MAC",
|
||||
cidrv4: "interval IPv4",
|
||||
cidrv6: "interval IPv6",
|
||||
base64: "șir codat base64",
|
||||
base64url: "șir codat base64url",
|
||||
json_string: "șir JSON",
|
||||
e164: "număr E.164",
|
||||
jwt: "JWT",
|
||||
template_literal: "intrare",
|
||||
};
|
||||
|
||||
const TypeDictionary: {
|
||||
[k in errors.$ZodInvalidTypeExpected | (string & {})]?: string;
|
||||
} = {
|
||||
nan: "NaN",
|
||||
string: "șir",
|
||||
number: "număr",
|
||||
boolean: "boolean",
|
||||
function: "funcție",
|
||||
array: "matrice",
|
||||
object: "obiect",
|
||||
undefined: "nedefinit",
|
||||
symbol: "simbol",
|
||||
bigint: "număr mare",
|
||||
void: "void",
|
||||
never: "never",
|
||||
map: "hartă",
|
||||
set: "set",
|
||||
};
|
||||
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
return `Intrare invalidă: așteptat ${expected}, primit ${received}`;
|
||||
}
|
||||
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1) return `Intrare invalidă: așteptat ${util.stringifyPrimitive(issue.values[0])}`;
|
||||
return `Opțiune invalidă: așteptat una dintre ${util.joinValues(issue.values, "|")}`;
|
||||
case "too_big": {
|
||||
const adj = issue.inclusive ? "<=" : "<";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing)
|
||||
return `Prea mare: așteptat ca ${issue.origin ?? "valoarea"} ${sizing.verb} ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elemente"}`;
|
||||
return `Prea mare: așteptat ca ${issue.origin ?? "valoarea"} să fie ${adj}${issue.maximum.toString()}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const adj = issue.inclusive ? ">=" : ">";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing) {
|
||||
return `Prea mic: așteptat ca ${issue.origin} ${sizing.verb} ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
||||
}
|
||||
|
||||
return `Prea mic: așteptat ca ${issue.origin} să fie ${adj}${issue.minimum.toString()}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue as errors.$ZodStringFormatIssues;
|
||||
if (_issue.format === "starts_with") {
|
||||
return `Șir invalid: trebuie să înceapă cu "${_issue.prefix}"`;
|
||||
}
|
||||
if (_issue.format === "ends_with") return `Șir invalid: trebuie să se termine cu "${_issue.suffix}"`;
|
||||
if (_issue.format === "includes") return `Șir invalid: trebuie să includă "${_issue.includes}"`;
|
||||
if (_issue.format === "regex") return `Șir invalid: trebuie să se potrivească cu modelul ${_issue.pattern}`;
|
||||
return `Format invalid: ${FormatDictionary[_issue.format] ?? issue.format}`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `Număr invalid: trebuie să fie multiplu de ${issue.divisor}`;
|
||||
case "unrecognized_keys":
|
||||
return `Chei nerecunoscute: ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return `Cheie invalidă în ${issue.origin}`;
|
||||
case "invalid_union":
|
||||
return "Intrare invalidă";
|
||||
case "invalid_element":
|
||||
return `Valoare invalidă în ${issue.origin}`;
|
||||
default:
|
||||
return `Intrare invalidă`;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default function (): { localeError: errors.$ZodErrorMap } {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user