update
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
@@ -0,0 +1,292 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.allExpandedTypes = exports.VISITOR_KEYS = exports.NODE_PARENT_VALIDATIONS = exports.NODE_FIELDS = exports.FLIPPED_ALIAS_KEYS = exports.DEPRECATED_KEYS = exports.BUILDER_KEYS = exports.ALIAS_KEYS = void 0;
|
||||
exports.arrayOf = arrayOf;
|
||||
exports.arrayOfType = arrayOfType;
|
||||
exports.assertEach = assertEach;
|
||||
exports.assertNodeOrValueType = assertNodeOrValueType;
|
||||
exports.assertNodeType = assertNodeType;
|
||||
exports.assertOneOf = assertOneOf;
|
||||
exports.assertOptionalChainStart = assertOptionalChainStart;
|
||||
exports.assertShape = assertShape;
|
||||
exports.assertValueType = assertValueType;
|
||||
exports.chain = chain;
|
||||
exports.default = defineType;
|
||||
exports.defineAliasedType = defineAliasedType;
|
||||
exports.validate = validate;
|
||||
exports.validateArrayOfType = validateArrayOfType;
|
||||
exports.validateOptional = validateOptional;
|
||||
exports.validateOptionalType = validateOptionalType;
|
||||
exports.validateType = validateType;
|
||||
var _is = require("../validators/is.js");
|
||||
var _validate = require("../validators/validate.js");
|
||||
const VISITOR_KEYS = exports.VISITOR_KEYS = {};
|
||||
const ALIAS_KEYS = exports.ALIAS_KEYS = {};
|
||||
const FLIPPED_ALIAS_KEYS = exports.FLIPPED_ALIAS_KEYS = {};
|
||||
const NODE_FIELDS = exports.NODE_FIELDS = {};
|
||||
const BUILDER_KEYS = exports.BUILDER_KEYS = {};
|
||||
const DEPRECATED_KEYS = exports.DEPRECATED_KEYS = {};
|
||||
const NODE_PARENT_VALIDATIONS = exports.NODE_PARENT_VALIDATIONS = {};
|
||||
function getType(val) {
|
||||
if (Array.isArray(val)) {
|
||||
return "array";
|
||||
} else if (val === null) {
|
||||
return "null";
|
||||
} else {
|
||||
return typeof val;
|
||||
}
|
||||
}
|
||||
function validate(validate) {
|
||||
return {
|
||||
validate
|
||||
};
|
||||
}
|
||||
function validateType(...typeNames) {
|
||||
return validate(assertNodeType(...typeNames));
|
||||
}
|
||||
function validateOptional(validate) {
|
||||
return {
|
||||
validate,
|
||||
optional: true
|
||||
};
|
||||
}
|
||||
function validateOptionalType(...typeNames) {
|
||||
return {
|
||||
validate: assertNodeType(...typeNames),
|
||||
optional: true
|
||||
};
|
||||
}
|
||||
function arrayOf(elementType) {
|
||||
return chain(assertValueType("array"), assertEach(elementType));
|
||||
}
|
||||
function arrayOfType(...typeNames) {
|
||||
return arrayOf(assertNodeType(...typeNames));
|
||||
}
|
||||
function validateArrayOfType(...typeNames) {
|
||||
return validate(arrayOfType(...typeNames));
|
||||
}
|
||||
function assertEach(callback) {
|
||||
const childValidator = process.env.BABEL_TYPES_8_BREAKING ? _validate.validateChild : () => {};
|
||||
function validator(node, key, val) {
|
||||
if (!Array.isArray(val)) return;
|
||||
let i = 0;
|
||||
const subKey = {
|
||||
toString() {
|
||||
return `${key}[${i}]`;
|
||||
}
|
||||
};
|
||||
for (; i < val.length; i++) {
|
||||
const v = val[i];
|
||||
callback(node, subKey, v);
|
||||
childValidator(node, subKey, v);
|
||||
}
|
||||
}
|
||||
validator.each = callback;
|
||||
return validator;
|
||||
}
|
||||
function assertOneOf(...values) {
|
||||
function validate(node, key, val) {
|
||||
if (!values.includes(val)) {
|
||||
throw new TypeError(`Property ${key} expected value to be one of ${JSON.stringify(values)} but got ${JSON.stringify(val)}`);
|
||||
}
|
||||
}
|
||||
validate.oneOf = values;
|
||||
return validate;
|
||||
}
|
||||
const allExpandedTypes = exports.allExpandedTypes = [];
|
||||
function assertNodeType(...types) {
|
||||
const expandedTypes = new Set();
|
||||
allExpandedTypes.push({
|
||||
types,
|
||||
set: expandedTypes
|
||||
});
|
||||
function validate(node, key, val) {
|
||||
const valType = val == null ? void 0 : val.type;
|
||||
if (valType != null) {
|
||||
if (expandedTypes.has(valType)) {
|
||||
(0, _validate.validateChild)(node, key, val);
|
||||
return;
|
||||
}
|
||||
if (valType === "Placeholder") {
|
||||
for (const type of types) {
|
||||
if ((0, _is.default)(type, val)) {
|
||||
(0, _validate.validateChild)(node, key, val);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new TypeError(`Property ${key} of ${node.type} expected node to be of a type ${JSON.stringify(types)} but instead got ${JSON.stringify(valType)}`);
|
||||
}
|
||||
validate.oneOfNodeTypes = types;
|
||||
return validate;
|
||||
}
|
||||
function assertNodeOrValueType(...types) {
|
||||
function validate(node, key, val) {
|
||||
const primitiveType = getType(val);
|
||||
for (const type of types) {
|
||||
if (primitiveType === type || (0, _is.default)(type, val)) {
|
||||
(0, _validate.validateChild)(node, key, val);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new TypeError(`Property ${key} of ${node.type} expected node to be of a type ${JSON.stringify(types)} but instead got ${JSON.stringify(val == null ? void 0 : val.type)}`);
|
||||
}
|
||||
validate.oneOfNodeOrValueTypes = types;
|
||||
return validate;
|
||||
}
|
||||
function assertValueType(type) {
|
||||
function validate(node, key, val) {
|
||||
if (getType(val) === type) {
|
||||
return;
|
||||
}
|
||||
throw new TypeError(`Property ${key} expected type of ${type} but got ${getType(val)}`);
|
||||
}
|
||||
validate.type = type;
|
||||
return validate;
|
||||
}
|
||||
function assertShape(shape) {
|
||||
const keys = Object.keys(shape);
|
||||
function validate(node, key, val) {
|
||||
const errors = [];
|
||||
for (const property of keys) {
|
||||
try {
|
||||
(0, _validate.validateField)(node, property, val[property], shape[property]);
|
||||
} catch (error) {
|
||||
if (error instanceof TypeError) {
|
||||
errors.push(error.message);
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
if (errors.length) {
|
||||
throw new TypeError(`Property ${key} of ${node.type} expected to have the following:\n${errors.join("\n")}`);
|
||||
}
|
||||
}
|
||||
validate.shapeOf = shape;
|
||||
return validate;
|
||||
}
|
||||
function assertOptionalChainStart() {
|
||||
function validate(node) {
|
||||
var _current;
|
||||
let current = node;
|
||||
while (node) {
|
||||
const {
|
||||
type
|
||||
} = current;
|
||||
if (type === "OptionalCallExpression") {
|
||||
if (current.optional) return;
|
||||
current = current.callee;
|
||||
continue;
|
||||
}
|
||||
if (type === "OptionalMemberExpression") {
|
||||
if (current.optional) return;
|
||||
current = current.object;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
throw new TypeError(`Non-optional ${node.type} must chain from an optional OptionalMemberExpression or OptionalCallExpression. Found chain from ${(_current = current) == null ? void 0 : _current.type}`);
|
||||
}
|
||||
return validate;
|
||||
}
|
||||
function chain(...fns) {
|
||||
function validate(...args) {
|
||||
for (const fn of fns) {
|
||||
fn(...args);
|
||||
}
|
||||
}
|
||||
validate.chainOf = fns;
|
||||
if (fns.length >= 2 && "type" in fns[0] && fns[0].type === "array" && !("each" in fns[1])) {
|
||||
throw new Error(`An assertValueType("array") validator can only be followed by an assertEach(...) validator.`);
|
||||
}
|
||||
return validate;
|
||||
}
|
||||
const validTypeOpts = new Set(["aliases", "builder", "deprecatedAlias", "fields", "inherits", "visitor", "validate"]);
|
||||
const validFieldKeys = new Set(["default", "optional", "deprecated", "validate"]);
|
||||
const store = {};
|
||||
function defineAliasedType(...aliases) {
|
||||
return (type, opts = {}) => {
|
||||
let defined = opts.aliases;
|
||||
if (!defined) {
|
||||
var _store$opts$inherits$;
|
||||
if (opts.inherits) defined = (_store$opts$inherits$ = store[opts.inherits].aliases) == null ? void 0 : _store$opts$inherits$.slice();
|
||||
defined != null ? defined : defined = [];
|
||||
opts.aliases = defined;
|
||||
}
|
||||
const additional = aliases.filter(a => !defined.includes(a));
|
||||
defined.unshift(...additional);
|
||||
defineType(type, opts);
|
||||
};
|
||||
}
|
||||
function defineType(type, opts = {}) {
|
||||
const inherits = opts.inherits && store[opts.inherits] || {};
|
||||
let fields = opts.fields;
|
||||
if (!fields) {
|
||||
fields = {};
|
||||
if (inherits.fields) {
|
||||
const keys = Object.getOwnPropertyNames(inherits.fields);
|
||||
for (const key of keys) {
|
||||
const field = inherits.fields[key];
|
||||
const def = field.default;
|
||||
if (Array.isArray(def) ? def.length > 0 : def && typeof def === "object") {
|
||||
throw new Error("field defaults can only be primitives or empty arrays currently");
|
||||
}
|
||||
fields[key] = {
|
||||
default: Array.isArray(def) ? [] : def,
|
||||
optional: field.optional,
|
||||
deprecated: field.deprecated,
|
||||
validate: field.validate
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
const visitor = opts.visitor || inherits.visitor || [];
|
||||
const aliases = opts.aliases || inherits.aliases || [];
|
||||
const builder = opts.builder || inherits.builder || opts.visitor || [];
|
||||
for (const k of Object.keys(opts)) {
|
||||
if (!validTypeOpts.has(k)) {
|
||||
throw new Error(`Unknown type option "${k}" on ${type}`);
|
||||
}
|
||||
}
|
||||
if (opts.deprecatedAlias) {
|
||||
DEPRECATED_KEYS[opts.deprecatedAlias] = type;
|
||||
}
|
||||
for (const key of visitor.concat(builder)) {
|
||||
fields[key] = fields[key] || {};
|
||||
}
|
||||
for (const key of Object.keys(fields)) {
|
||||
const field = fields[key];
|
||||
if (field.default !== undefined && !builder.includes(key)) {
|
||||
field.optional = true;
|
||||
}
|
||||
if (field.default === undefined) {
|
||||
field.default = null;
|
||||
} else if (!field.validate && field.default != null) {
|
||||
field.validate = assertValueType(getType(field.default));
|
||||
}
|
||||
for (const k of Object.keys(field)) {
|
||||
if (!validFieldKeys.has(k)) {
|
||||
throw new Error(`Unknown field key "${k}" on ${type}.${key}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
VISITOR_KEYS[type] = opts.visitor = visitor;
|
||||
BUILDER_KEYS[type] = opts.builder = builder;
|
||||
NODE_FIELDS[type] = opts.fields = fields;
|
||||
ALIAS_KEYS[type] = opts.aliases = aliases;
|
||||
aliases.forEach(alias => {
|
||||
FLIPPED_ALIAS_KEYS[alias] = FLIPPED_ALIAS_KEYS[alias] || [];
|
||||
FLIPPED_ALIAS_KEYS[alias].push(type);
|
||||
});
|
||||
if (opts.validate) {
|
||||
NODE_PARENT_VALIDATIONS[type] = opts.validate;
|
||||
}
|
||||
store[type] = opts;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=utils.js.map
|
||||
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var stringify = require('../');
|
||||
|
||||
test('custom comparison function', function (t) {
|
||||
t.plan(1);
|
||||
var obj = { c: 8, b: [{z:6,y:5,x:4},7], a: 3 };
|
||||
var s = stringify(obj, function (a, b) {
|
||||
return a.key < b.key ? 1 : -1;
|
||||
});
|
||||
t.equal(s, '{"c":8,"b":[{"z":6,"y":5,"x":4},7],"a":3}');
|
||||
});
|
||||
@@ -0,0 +1,259 @@
|
||||
'use strict';
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const JSONB = require('json-buffer');
|
||||
|
||||
const loadStore = options => {
|
||||
const adapters = {
|
||||
redis: '@keyv/redis',
|
||||
rediss: '@keyv/redis',
|
||||
mongodb: '@keyv/mongo',
|
||||
mongo: '@keyv/mongo',
|
||||
sqlite: '@keyv/sqlite',
|
||||
postgresql: '@keyv/postgres',
|
||||
postgres: '@keyv/postgres',
|
||||
mysql: '@keyv/mysql',
|
||||
etcd: '@keyv/etcd',
|
||||
offline: '@keyv/offline',
|
||||
tiered: '@keyv/tiered',
|
||||
};
|
||||
if (options.adapter || options.uri) {
|
||||
const adapter = options.adapter || /^[^:+]*/.exec(options.uri)[0];
|
||||
return new (require(adapters[adapter]))(options);
|
||||
}
|
||||
|
||||
return new Map();
|
||||
};
|
||||
|
||||
const iterableAdapters = [
|
||||
'sqlite',
|
||||
'postgres',
|
||||
'mysql',
|
||||
'mongo',
|
||||
'redis',
|
||||
'tiered',
|
||||
];
|
||||
|
||||
class Keyv extends EventEmitter {
|
||||
constructor(uri, {emitErrors = true, ...options} = {}) {
|
||||
super();
|
||||
this.opts = {
|
||||
namespace: 'keyv',
|
||||
serialize: JSONB.stringify,
|
||||
deserialize: JSONB.parse,
|
||||
...((typeof uri === 'string') ? {uri} : uri),
|
||||
...options,
|
||||
};
|
||||
|
||||
if (!this.opts.store) {
|
||||
const adapterOptions = {...this.opts};
|
||||
this.opts.store = loadStore(adapterOptions);
|
||||
}
|
||||
|
||||
if (this.opts.compression) {
|
||||
const compression = this.opts.compression;
|
||||
this.opts.serialize = compression.serialize.bind(compression);
|
||||
this.opts.deserialize = compression.deserialize.bind(compression);
|
||||
}
|
||||
|
||||
if (typeof this.opts.store.on === 'function' && emitErrors) {
|
||||
this.opts.store.on('error', error => this.emit('error', error));
|
||||
}
|
||||
|
||||
this.opts.store.namespace = this.opts.namespace;
|
||||
|
||||
const generateIterator = iterator => async function * () {
|
||||
for await (const [key, raw] of typeof iterator === 'function'
|
||||
? iterator(this.opts.store.namespace)
|
||||
: iterator) {
|
||||
const data = await this.opts.deserialize(raw);
|
||||
if (this.opts.store.namespace && !key.includes(this.opts.store.namespace)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof data.expires === 'number' && Date.now() > data.expires) {
|
||||
this.delete(key);
|
||||
continue;
|
||||
}
|
||||
|
||||
yield [this._getKeyUnprefix(key), data.value];
|
||||
}
|
||||
};
|
||||
|
||||
// Attach iterators
|
||||
if (typeof this.opts.store[Symbol.iterator] === 'function' && this.opts.store instanceof Map) {
|
||||
this.iterator = generateIterator(this.opts.store);
|
||||
} else if (typeof this.opts.store.iterator === 'function' && this.opts.store.opts
|
||||
&& this._checkIterableAdaptar()) {
|
||||
this.iterator = generateIterator(this.opts.store.iterator.bind(this.opts.store));
|
||||
}
|
||||
}
|
||||
|
||||
_checkIterableAdaptar() {
|
||||
return iterableAdapters.includes(this.opts.store.opts.dialect)
|
||||
|| iterableAdapters.findIndex(element => this.opts.store.opts.url.includes(element)) >= 0;
|
||||
}
|
||||
|
||||
_getKeyPrefix(key) {
|
||||
return `${this.opts.namespace}:${key}`;
|
||||
}
|
||||
|
||||
_getKeyPrefixArray(keys) {
|
||||
return keys.map(key => `${this.opts.namespace}:${key}`);
|
||||
}
|
||||
|
||||
_getKeyUnprefix(key) {
|
||||
return key
|
||||
.split(':')
|
||||
.splice(1)
|
||||
.join(':');
|
||||
}
|
||||
|
||||
get(key, options) {
|
||||
const {store} = this.opts;
|
||||
const isArray = Array.isArray(key);
|
||||
const keyPrefixed = isArray ? this._getKeyPrefixArray(key) : this._getKeyPrefix(key);
|
||||
if (isArray && store.getMany === undefined) {
|
||||
const promises = [];
|
||||
for (const key of keyPrefixed) {
|
||||
promises.push(Promise.resolve()
|
||||
.then(() => store.get(key))
|
||||
.then(data => (typeof data === 'string') ? this.opts.deserialize(data) : (this.opts.compression ? this.opts.deserialize(data) : data))
|
||||
.then(data => {
|
||||
if (data === undefined || data === null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (typeof data.expires === 'number' && Date.now() > data.expires) {
|
||||
return this.delete(key).then(() => undefined);
|
||||
}
|
||||
|
||||
return (options && options.raw) ? data : data.value;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.allSettled(promises)
|
||||
.then(values => {
|
||||
const data = [];
|
||||
for (const value of values) {
|
||||
data.push(value.value);
|
||||
}
|
||||
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.resolve()
|
||||
.then(() => isArray ? store.getMany(keyPrefixed) : store.get(keyPrefixed))
|
||||
.then(data => (typeof data === 'string') ? this.opts.deserialize(data) : (this.opts.compression ? this.opts.deserialize(data) : data))
|
||||
.then(data => {
|
||||
if (data === undefined || data === null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (isArray) {
|
||||
return data.map((row, index) => {
|
||||
if ((typeof row === 'string')) {
|
||||
row = this.opts.deserialize(row);
|
||||
}
|
||||
|
||||
if (row === undefined || row === null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (typeof row.expires === 'number' && Date.now() > row.expires) {
|
||||
this.delete(key[index]).then(() => undefined);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return (options && options.raw) ? row : row.value;
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof data.expires === 'number' && Date.now() > data.expires) {
|
||||
return this.delete(key).then(() => undefined);
|
||||
}
|
||||
|
||||
return (options && options.raw) ? data : data.value;
|
||||
});
|
||||
}
|
||||
|
||||
set(key, value, ttl) {
|
||||
const keyPrefixed = this._getKeyPrefix(key);
|
||||
if (typeof ttl === 'undefined') {
|
||||
ttl = this.opts.ttl;
|
||||
}
|
||||
|
||||
if (ttl === 0) {
|
||||
ttl = undefined;
|
||||
}
|
||||
|
||||
const {store} = this.opts;
|
||||
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
const expires = (typeof ttl === 'number') ? (Date.now() + ttl) : null;
|
||||
if (typeof value === 'symbol') {
|
||||
this.emit('error', 'symbol cannot be serialized');
|
||||
}
|
||||
|
||||
value = {value, expires};
|
||||
return this.opts.serialize(value);
|
||||
})
|
||||
.then(value => store.set(keyPrefixed, value, ttl))
|
||||
.then(() => true);
|
||||
}
|
||||
|
||||
delete(key) {
|
||||
const {store} = this.opts;
|
||||
if (Array.isArray(key)) {
|
||||
const keyPrefixed = this._getKeyPrefixArray(key);
|
||||
if (store.deleteMany === undefined) {
|
||||
const promises = [];
|
||||
for (const key of keyPrefixed) {
|
||||
promises.push(store.delete(key));
|
||||
}
|
||||
|
||||
return Promise.allSettled(promises)
|
||||
.then(values => values.every(x => x.value === true));
|
||||
}
|
||||
|
||||
return Promise.resolve()
|
||||
.then(() => store.deleteMany(keyPrefixed));
|
||||
}
|
||||
|
||||
const keyPrefixed = this._getKeyPrefix(key);
|
||||
return Promise.resolve()
|
||||
.then(() => store.delete(keyPrefixed));
|
||||
}
|
||||
|
||||
clear() {
|
||||
const {store} = this.opts;
|
||||
return Promise.resolve()
|
||||
.then(() => store.clear());
|
||||
}
|
||||
|
||||
has(key) {
|
||||
const keyPrefixed = this._getKeyPrefix(key);
|
||||
const {store} = this.opts;
|
||||
return Promise.resolve()
|
||||
.then(async () => {
|
||||
if (typeof store.has === 'function') {
|
||||
return store.has(keyPrefixed);
|
||||
}
|
||||
|
||||
const value = await store.get(keyPrefixed);
|
||||
return value !== undefined;
|
||||
});
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
const {store} = this.opts;
|
||||
if (typeof store.disconnect === 'function') {
|
||||
return store.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Keyv;
|
||||
@@ -0,0 +1,5 @@
|
||||
<img src="https://static.scarf.sh/a.png?x-pxid=d988eb79-b0fc-4a2b-8514-6a1ab932d188" />
|
||||
|
||||
# TanStack Router Core
|
||||
|
||||
See [https://tanstack.com/router](https://tanstack.com/router) for documentation.
|
||||
@@ -0,0 +1,315 @@
|
||||
/**
|
||||
* @fileoverview Rule to enforce the use of `u` or `v` flag on regular expressions.
|
||||
* @author Toru Nagashima
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const {
|
||||
CALL,
|
||||
CONSTRUCT,
|
||||
ReferenceTracker,
|
||||
getStringIfConstant,
|
||||
} = require("@eslint-community/eslint-utils");
|
||||
const astUtils = require("./utils/ast-utils.js");
|
||||
const { isValidWithUnicodeFlag } = require("./utils/regular-expressions");
|
||||
|
||||
/**
|
||||
* Checks whether the flag configuration should be treated as a missing flag.
|
||||
* @param {"u"|"v"|undefined} requireFlag A particular flag to require
|
||||
* @param {string} flags The regex flags
|
||||
* @returns {boolean} Whether the flag configuration results in a missing flag.
|
||||
*/
|
||||
function checkFlags(requireFlag, flags) {
|
||||
let missingFlag;
|
||||
|
||||
if (requireFlag === "v") {
|
||||
missingFlag = !flags.includes("v");
|
||||
} else if (requireFlag === "u") {
|
||||
missingFlag = !flags.includes("u");
|
||||
} else {
|
||||
missingFlag = !flags.includes("u") && !flags.includes("v");
|
||||
}
|
||||
|
||||
return missingFlag;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Enforce the use of `u` or `v` flag on regular expressions",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/require-unicode-regexp",
|
||||
},
|
||||
|
||||
hasSuggestions: true,
|
||||
|
||||
messages: {
|
||||
addUFlag: "Add the 'u' flag.",
|
||||
addVFlag: "Add the 'v' flag.",
|
||||
requireUFlag: "Use the 'u' flag.",
|
||||
requireVFlag: "Use the 'v' flag.",
|
||||
},
|
||||
|
||||
schema: [
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
requireFlag: {
|
||||
enum: ["u", "v"],
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
const { requireFlag } = context.options[0] ?? {};
|
||||
|
||||
return {
|
||||
"Literal[regex]"(node) {
|
||||
const flags = node.regex.flags || "";
|
||||
|
||||
const missingFlag = checkFlags(requireFlag, flags);
|
||||
|
||||
if (missingFlag) {
|
||||
context.report({
|
||||
messageId:
|
||||
requireFlag === "v"
|
||||
? "requireVFlag"
|
||||
: "requireUFlag",
|
||||
node,
|
||||
suggest: isValidWithUnicodeFlag(
|
||||
context.languageOptions.ecmaVersion,
|
||||
node.regex.pattern,
|
||||
requireFlag,
|
||||
)
|
||||
? [
|
||||
{
|
||||
fix(fixer) {
|
||||
const replaceFlag =
|
||||
requireFlag ?? "u";
|
||||
const regex =
|
||||
sourceCode.getText(node);
|
||||
const slashPos =
|
||||
regex.lastIndexOf("/");
|
||||
|
||||
if (requireFlag) {
|
||||
const flag =
|
||||
requireFlag === "u"
|
||||
? "v"
|
||||
: "u";
|
||||
|
||||
if (
|
||||
regex.includes(
|
||||
flag,
|
||||
slashPos,
|
||||
)
|
||||
) {
|
||||
return fixer.replaceText(
|
||||
node,
|
||||
regex.slice(
|
||||
0,
|
||||
slashPos,
|
||||
) +
|
||||
regex
|
||||
.slice(slashPos)
|
||||
.replace(
|
||||
flag,
|
||||
requireFlag,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return fixer.insertTextAfter(
|
||||
node,
|
||||
replaceFlag,
|
||||
);
|
||||
},
|
||||
messageId:
|
||||
requireFlag === "v"
|
||||
? "addVFlag"
|
||||
: "addUFlag",
|
||||
},
|
||||
]
|
||||
: null,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
Program(node) {
|
||||
const scope = sourceCode.getScope(node);
|
||||
const tracker = new ReferenceTracker(scope);
|
||||
const trackMap = {
|
||||
RegExp: { [CALL]: true, [CONSTRUCT]: true },
|
||||
};
|
||||
|
||||
for (const { node: refNode } of tracker.iterateGlobalReferences(
|
||||
trackMap,
|
||||
)) {
|
||||
const [patternNode, flagsNode] = refNode.arguments;
|
||||
|
||||
if (patternNode && patternNode.type === "SpreadElement") {
|
||||
continue;
|
||||
}
|
||||
const pattern = getStringIfConstant(patternNode, scope);
|
||||
const flags = getStringIfConstant(flagsNode, scope);
|
||||
|
||||
let missingFlag = !flagsNode;
|
||||
|
||||
if (typeof flags === "string") {
|
||||
missingFlag = checkFlags(requireFlag, flags);
|
||||
}
|
||||
|
||||
if (missingFlag) {
|
||||
context.report({
|
||||
messageId:
|
||||
requireFlag === "v"
|
||||
? "requireVFlag"
|
||||
: "requireUFlag",
|
||||
node: refNode,
|
||||
suggest:
|
||||
typeof pattern === "string" &&
|
||||
isValidWithUnicodeFlag(
|
||||
context.languageOptions.ecmaVersion,
|
||||
pattern,
|
||||
requireFlag,
|
||||
)
|
||||
? [
|
||||
{
|
||||
fix(fixer) {
|
||||
const replaceFlag =
|
||||
requireFlag ?? "u";
|
||||
|
||||
if (flagsNode) {
|
||||
if (
|
||||
(flagsNode.type ===
|
||||
"Literal" &&
|
||||
typeof flagsNode.value ===
|
||||
"string") ||
|
||||
flagsNode.type ===
|
||||
"TemplateLiteral"
|
||||
) {
|
||||
const flagsNodeText =
|
||||
sourceCode.getText(
|
||||
flagsNode,
|
||||
);
|
||||
const flag =
|
||||
requireFlag ===
|
||||
"u"
|
||||
? "v"
|
||||
: "u";
|
||||
|
||||
if (
|
||||
flags.includes(
|
||||
flag,
|
||||
)
|
||||
) {
|
||||
// Avoid replacing "u" in escapes like `\uXXXX`
|
||||
if (
|
||||
flagsNode.type ===
|
||||
"Literal" &&
|
||||
flagsNode.raw.includes(
|
||||
"\\",
|
||||
)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Avoid replacing "u" in expressions like "`${regularFlags}g`"
|
||||
if (
|
||||
flagsNode.type ===
|
||||
"TemplateLiteral" &&
|
||||
(flagsNode
|
||||
.expressions
|
||||
.length ||
|
||||
flagsNode.quasis.some(
|
||||
({
|
||||
value: {
|
||||
raw,
|
||||
},
|
||||
}) =>
|
||||
raw.includes(
|
||||
"\\",
|
||||
),
|
||||
))
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return fixer.replaceText(
|
||||
flagsNode,
|
||||
flagsNodeText.replace(
|
||||
flag,
|
||||
replaceFlag,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return fixer.replaceText(
|
||||
flagsNode,
|
||||
[
|
||||
flagsNodeText.slice(
|
||||
0,
|
||||
flagsNodeText.length -
|
||||
1,
|
||||
),
|
||||
flagsNodeText.slice(
|
||||
flagsNodeText.length -
|
||||
1,
|
||||
),
|
||||
].join(
|
||||
replaceFlag,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// We intentionally don't suggest concatenating + "u" to non-literals
|
||||
return null;
|
||||
}
|
||||
|
||||
const penultimateToken =
|
||||
sourceCode.getLastToken(
|
||||
refNode,
|
||||
{ skip: 1 },
|
||||
); // skip closing parenthesis
|
||||
|
||||
return fixer.insertTextAfter(
|
||||
penultimateToken,
|
||||
astUtils.isCommaToken(
|
||||
penultimateToken,
|
||||
)
|
||||
? ` "${replaceFlag}",`
|
||||
: `, "${replaceFlag}"`,
|
||||
);
|
||||
},
|
||||
messageId:
|
||||
requireFlag === "v"
|
||||
? "addVFlag"
|
||||
: "addUFlag",
|
||||
},
|
||||
]
|
||||
: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"48":0.00529,"52":0.02647,"56":0.00529,"78":0.02647,"106":0.00529,"107":0.00529,"108":0.00529,"110":0.00529,"113":0.03706,"115":0.29117,"125":0.01588,"127":0.01059,"128":0.07412,"130":0.00529,"131":0.01059,"132":0.02647,"133":0.01588,"134":0.02118,"135":0.54528,"136":1.81055,"137":0.00529,_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 49 50 51 53 54 55 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 109 111 112 114 116 117 118 119 120 121 122 123 124 126 129 138 139 140 3.5 3.6"},D:{"48":0.00529,"49":0.02647,"53":0.00529,"58":0.00529,"63":0.00529,"65":0.01588,"67":0.00529,"68":0.00529,"70":0.00529,"74":0.01588,"75":0.00529,"77":0.1747,"78":0.00529,"79":0.01059,"80":0.00529,"81":0.04235,"83":0.01588,"84":0.00529,"85":0.00529,"86":0.02118,"87":0.01588,"88":0.00529,"89":0.00529,"90":0.00529,"91":0.11647,"92":0.11647,"93":0.03176,"95":0.02118,"96":0.00529,"97":0.01588,"98":0.01059,"99":0.01059,"100":0.00529,"101":0.01588,"102":0.01588,"103":0.05823,"104":0.25941,"105":0.01588,"106":0.05823,"107":0.07941,"108":0.06353,"109":0.74645,"110":0.04765,"111":0.04235,"112":0.06353,"113":0.02647,"114":0.07941,"115":0.00529,"116":0.0847,"117":0.01059,"118":0.07941,"119":0.09529,"120":0.13764,"121":0.06353,"122":0.06882,"123":0.06882,"124":0.13764,"125":4.76989,"126":0.09,"127":0.06882,"128":0.23294,"129":0.13764,"130":0.13235,"131":0.66704,"132":0.6194,"133":6.45339,"134":11.62033,"135":0.03176,"136":0.04235,_:"4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 50 51 52 54 55 56 57 59 60 61 62 64 66 69 71 72 73 76 94 137 138"},F:{"49":0.01059,"87":0.03706,"88":0.02118,"94":0.00529,"95":0.01588,"115":0.00529,"116":0.02647,"117":0.27529,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 50 51 52 53 54 55 56 57 58 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 89 90 91 92 93 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"14":0.00529,"17":0.00529,"92":0.00529,"102":0.00529,"106":0.00529,"107":0.01059,"108":0.01059,"109":0.18529,"110":0.00529,"111":0.00529,"113":0.01059,"114":0.00529,"115":0.00529,"116":0.00529,"117":0.00529,"118":0.00529,"119":0.00529,"120":0.02118,"121":0.01059,"122":0.02118,"123":0.00529,"124":0.01588,"125":0.00529,"126":0.01588,"127":0.02118,"128":0.01588,"129":0.02118,"130":0.03706,"131":0.0847,"132":0.11647,"133":2.74759,"134":6.25751,_:"12 13 15 16 18 79 80 81 83 84 85 86 87 88 89 90 91 93 94 95 96 97 98 99 100 101 103 104 105 112"},E:{"13":0.00529,"14":0.02647,"15":0.00529,_:"0 4 5 6 7 8 9 10 11 12 3.1 3.2 5.1 6.1 7.1 9.1 10.1 11.1","12.1":0.01059,"13.1":0.04235,"14.1":0.07412,"15.1":0.00529,"15.2-15.3":0.00529,"15.4":0.01588,"15.5":0.01588,"15.6":0.16411,"16.0":0.03176,"16.1":0.04235,"16.2":0.01588,"16.3":0.03706,"16.4":0.01059,"16.5":0.01588,"16.6":0.20647,"17.0":0.01059,"17.1":0.12176,"17.2":0.01588,"17.3":0.02118,"17.4":0.05294,"17.5":0.06353,"17.6":0.28588,"18.0":0.02647,"18.1":0.0847,"18.2":0.04765,"18.3":1.24938,"18.4":0.01588},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.00447,"5.0-5.1":0,"6.0-6.1":0.01341,"7.0-7.1":0.00894,"8.1-8.4":0,"9.0-9.2":0.00671,"9.3":0.03129,"10.0-10.2":0.00224,"10.3":0.05141,"11.0-11.2":0.23695,"11.3-11.4":0.01565,"12.0-12.1":0.00894,"12.2-12.5":0.2213,"13.0-13.1":0.00447,"13.2":0.00671,"13.3":0.00894,"13.4-13.7":0.03129,"14.0-14.4":0.07824,"14.5-14.8":0.09388,"15.0-15.1":0.05141,"15.2-15.3":0.05141,"15.4":0.06259,"15.5":0.07153,"15.6-15.8":0.88073,"16.0":0.12518,"16.1":0.25707,"16.2":0.13412,"16.3":0.23248,"16.4":0.05141,"16.5":0.09612,"16.6-16.7":1.04391,"17.0":0.06259,"17.1":0.11177,"17.2":0.08494,"17.3":0.11847,"17.4":0.23695,"17.5":0.52754,"17.6-17.7":1.53121,"18.0":0.42919,"18.1":1.4038,"18.2":0.62813,"18.3":13.12821,"18.4":0.19448},P:{"20":0.0112,"25":0.0112,"26":0.02241,"27":0.89638,_:"4 21 22 23 24 5.0-5.4 6.2-6.4 7.2-7.4 8.2 9.2 10.1 11.1-11.2 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0"},I:{"0":0.02818,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0.00001,"4.4":0,"4.4.3-4.4.4":0.00003},K:{"0":0.15059,_:"10 11 12 11.1 11.5 12.1"},A:{"9":0.04529,"11":0.36234,_:"6 7 8 10 5.5"},S:{_:"2.5 3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{"0":0.46119},Q:{"14.9":0.10824},O:{"0":0.27295},H:{"0":0},L:{"0":29.41273}};
|
||||
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
const isMatch = (match, path) => {
|
||||
const parts = path.split(".");
|
||||
let part;
|
||||
let value = match;
|
||||
while ((part = parts.shift()) != null && value != null) {
|
||||
value = value[part];
|
||||
}
|
||||
return value != null;
|
||||
};
|
||||
exports.isMatch = isMatch;
|
||||
//# sourceMappingURL=Matches.cjs.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_index","require","BLOCK_SCOPED_SYMBOL","Symbol","for","isVar","node","isVariableDeclaration","kind"],"sources":["../../src/validators/isVar.ts"],"sourcesContent":["import { isVariableDeclaration } from \"./generated/index.ts\";\nimport type * as t from \"../index.ts\";\n\nif (!process.env.BABEL_8_BREAKING) {\n // eslint-disable-next-line no-var\n var BLOCK_SCOPED_SYMBOL = Symbol.for(\"var used to be block scoped\");\n}\n\n/**\n * Check if the input `node` is a variable declaration.\n */\nexport default function isVar(node: t.Node): boolean {\n if (process.env.BABEL_8_BREAKING) {\n return isVariableDeclaration(node) && node.kind === \"var\";\n } else {\n return (\n isVariableDeclaration(node, { kind: \"var\" }) &&\n !(\n // @ts-expect-error document private properties\n node[BLOCK_SCOPED_SYMBOL]\n )\n );\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGmC;EAEjC,IAAIC,mBAAmB,GAAGC,MAAM,CAACC,GAAG,CAAC,6BAA6B,CAAC;AACrE;AAKe,SAASC,KAAKA,CAACC,IAAY,EAAW;EAG5C;IACL,OACE,IAAAC,4BAAqB,EAACD,IAAI,EAAE;MAAEE,IAAI,EAAE;IAAM,CAAC,CAAC,IAC5C,CAEEF,IAAI,CAACJ,mBAAmB,CACzB;EAEL;AACF","ignoreList":[]}
|
||||
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
var Type = require('../type');
|
||||
|
||||
module.exports = new Type('tag:yaml.org,2002:str', {
|
||||
kind: 'scalar',
|
||||
construct: function (data) { return data !== null ? data : ''; }
|
||||
});
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
const SemVer = require('../classes/semver')
|
||||
const minor = (a, loose) => new SemVer(a, loose).minor
|
||||
module.exports = minor
|
||||
@@ -0,0 +1,51 @@
|
||||
export type Formatter = (input: string | number | null | undefined) => string
|
||||
|
||||
export interface Colors {
|
||||
isColorSupported: boolean
|
||||
|
||||
reset: Formatter
|
||||
bold: Formatter
|
||||
dim: Formatter
|
||||
italic: Formatter
|
||||
underline: Formatter
|
||||
inverse: Formatter
|
||||
hidden: Formatter
|
||||
strikethrough: Formatter
|
||||
|
||||
black: Formatter
|
||||
red: Formatter
|
||||
green: Formatter
|
||||
yellow: Formatter
|
||||
blue: Formatter
|
||||
magenta: Formatter
|
||||
cyan: Formatter
|
||||
white: Formatter
|
||||
gray: Formatter
|
||||
|
||||
bgBlack: Formatter
|
||||
bgRed: Formatter
|
||||
bgGreen: Formatter
|
||||
bgYellow: Formatter
|
||||
bgBlue: Formatter
|
||||
bgMagenta: Formatter
|
||||
bgCyan: Formatter
|
||||
bgWhite: Formatter
|
||||
|
||||
blackBright: Formatter
|
||||
redBright: Formatter
|
||||
greenBright: Formatter
|
||||
yellowBright: Formatter
|
||||
blueBright: Formatter
|
||||
magentaBright: Formatter
|
||||
cyanBright: Formatter
|
||||
whiteBright: Formatter
|
||||
|
||||
bgBlackBright: Formatter
|
||||
bgRedBright: Formatter
|
||||
bgGreenBright: Formatter
|
||||
bgYellowBright: Formatter
|
||||
bgBlueBright: Formatter
|
||||
bgMagentaBright: Formatter
|
||||
bgCyanBright: Formatter
|
||||
bgWhiteBright: Formatter
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
const jsxRuntime = require("react/jsx-runtime");
|
||||
const Matches = require("./Matches.cjs");
|
||||
const routerContext = require("./routerContext.cjs");
|
||||
function RouterContextProvider({
|
||||
router,
|
||||
children,
|
||||
...rest
|
||||
}) {
|
||||
router.update({
|
||||
...router.options,
|
||||
...rest,
|
||||
context: {
|
||||
...router.options.context,
|
||||
...rest.context
|
||||
}
|
||||
});
|
||||
const routerContext$1 = routerContext.getRouterContext();
|
||||
const provider = /* @__PURE__ */ jsxRuntime.jsx(routerContext$1.Provider, { value: router, children });
|
||||
if (router.options.Wrap) {
|
||||
return /* @__PURE__ */ jsxRuntime.jsx(router.options.Wrap, { children: provider });
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
function RouterProvider({ router, ...rest }) {
|
||||
return /* @__PURE__ */ jsxRuntime.jsx(RouterContextProvider, { router, ...rest, children: /* @__PURE__ */ jsxRuntime.jsx(Matches.Matches, {}) });
|
||||
}
|
||||
exports.RouterContextProvider = RouterContextProvider;
|
||||
exports.RouterProvider = RouterProvider;
|
||||
//# sourceMappingURL=RouterProvider.cjs.map
|
||||
@@ -0,0 +1,228 @@
|
||||
'use strict';
|
||||
module.exports = function generate_custom(it, $keyword, $ruleType) {
|
||||
var out = ' ';
|
||||
var $lvl = it.level;
|
||||
var $dataLvl = it.dataLevel;
|
||||
var $schema = it.schema[$keyword];
|
||||
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
||||
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||
var $breakOnError = !it.opts.allErrors;
|
||||
var $errorKeyword;
|
||||
var $data = 'data' + ($dataLvl || '');
|
||||
var $valid = 'valid' + $lvl;
|
||||
var $errs = 'errs__' + $lvl;
|
||||
var $isData = it.opts.$data && $schema && $schema.$data,
|
||||
$schemaValue;
|
||||
if ($isData) {
|
||||
out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
|
||||
$schemaValue = 'schema' + $lvl;
|
||||
} else {
|
||||
$schemaValue = $schema;
|
||||
}
|
||||
var $rule = this,
|
||||
$definition = 'definition' + $lvl,
|
||||
$rDef = $rule.definition,
|
||||
$closingBraces = '';
|
||||
var $compile, $inline, $macro, $ruleValidate, $validateCode;
|
||||
if ($isData && $rDef.$data) {
|
||||
$validateCode = 'keywordValidate' + $lvl;
|
||||
var $validateSchema = $rDef.validateSchema;
|
||||
out += ' var ' + ($definition) + ' = RULES.custom[\'' + ($keyword) + '\'].definition; var ' + ($validateCode) + ' = ' + ($definition) + '.validate;';
|
||||
} else {
|
||||
$ruleValidate = it.useCustomRule($rule, $schema, it.schema, it);
|
||||
if (!$ruleValidate) return;
|
||||
$schemaValue = 'validate.schema' + $schemaPath;
|
||||
$validateCode = $ruleValidate.code;
|
||||
$compile = $rDef.compile;
|
||||
$inline = $rDef.inline;
|
||||
$macro = $rDef.macro;
|
||||
}
|
||||
var $ruleErrs = $validateCode + '.errors',
|
||||
$i = 'i' + $lvl,
|
||||
$ruleErr = 'ruleErr' + $lvl,
|
||||
$asyncKeyword = $rDef.async;
|
||||
if ($asyncKeyword && !it.async) throw new Error('async keyword in sync schema');
|
||||
if (!($inline || $macro)) {
|
||||
out += '' + ($ruleErrs) + ' = null;';
|
||||
}
|
||||
out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
|
||||
if ($isData && $rDef.$data) {
|
||||
$closingBraces += '}';
|
||||
out += ' if (' + ($schemaValue) + ' === undefined) { ' + ($valid) + ' = true; } else { ';
|
||||
if ($validateSchema) {
|
||||
$closingBraces += '}';
|
||||
out += ' ' + ($valid) + ' = ' + ($definition) + '.validateSchema(' + ($schemaValue) + '); if (' + ($valid) + ') { ';
|
||||
}
|
||||
}
|
||||
if ($inline) {
|
||||
if ($rDef.statements) {
|
||||
out += ' ' + ($ruleValidate.validate) + ' ';
|
||||
} else {
|
||||
out += ' ' + ($valid) + ' = ' + ($ruleValidate.validate) + '; ';
|
||||
}
|
||||
} else if ($macro) {
|
||||
var $it = it.util.copy(it);
|
||||
var $closingBraces = '';
|
||||
$it.level++;
|
||||
var $nextValid = 'valid' + $it.level;
|
||||
$it.schema = $ruleValidate.validate;
|
||||
$it.schemaPath = '';
|
||||
var $wasComposite = it.compositeRule;
|
||||
it.compositeRule = $it.compositeRule = true;
|
||||
var $code = it.validate($it).replace(/validate\.schema/g, $validateCode);
|
||||
it.compositeRule = $it.compositeRule = $wasComposite;
|
||||
out += ' ' + ($code);
|
||||
} else {
|
||||
var $$outStack = $$outStack || [];
|
||||
$$outStack.push(out);
|
||||
out = '';
|
||||
out += ' ' + ($validateCode) + '.call( ';
|
||||
if (it.opts.passContext) {
|
||||
out += 'this';
|
||||
} else {
|
||||
out += 'self';
|
||||
}
|
||||
if ($compile || $rDef.schema === false) {
|
||||
out += ' , ' + ($data) + ' ';
|
||||
} else {
|
||||
out += ' , ' + ($schemaValue) + ' , ' + ($data) + ' , validate.schema' + (it.schemaPath) + ' ';
|
||||
}
|
||||
out += ' , (dataPath || \'\')';
|
||||
if (it.errorPath != '""') {
|
||||
out += ' + ' + (it.errorPath);
|
||||
}
|
||||
var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
|
||||
$parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
|
||||
out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ' , rootData ) ';
|
||||
var def_callRuleValidate = out;
|
||||
out = $$outStack.pop();
|
||||
if ($rDef.errors === false) {
|
||||
out += ' ' + ($valid) + ' = ';
|
||||
if ($asyncKeyword) {
|
||||
out += 'await ';
|
||||
}
|
||||
out += '' + (def_callRuleValidate) + '; ';
|
||||
} else {
|
||||
if ($asyncKeyword) {
|
||||
$ruleErrs = 'customErrors' + $lvl;
|
||||
out += ' var ' + ($ruleErrs) + ' = null; try { ' + ($valid) + ' = await ' + (def_callRuleValidate) + '; } catch (e) { ' + ($valid) + ' = false; if (e instanceof ValidationError) ' + ($ruleErrs) + ' = e.errors; else throw e; } ';
|
||||
} else {
|
||||
out += ' ' + ($ruleErrs) + ' = null; ' + ($valid) + ' = ' + (def_callRuleValidate) + '; ';
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($rDef.modifying) {
|
||||
out += ' if (' + ($parentData) + ') ' + ($data) + ' = ' + ($parentData) + '[' + ($parentDataProperty) + '];';
|
||||
}
|
||||
out += '' + ($closingBraces);
|
||||
if ($rDef.valid) {
|
||||
if ($breakOnError) {
|
||||
out += ' if (true) { ';
|
||||
}
|
||||
} else {
|
||||
out += ' if ( ';
|
||||
if ($rDef.valid === undefined) {
|
||||
out += ' !';
|
||||
if ($macro) {
|
||||
out += '' + ($nextValid);
|
||||
} else {
|
||||
out += '' + ($valid);
|
||||
}
|
||||
} else {
|
||||
out += ' ' + (!$rDef.valid) + ' ';
|
||||
}
|
||||
out += ') { ';
|
||||
$errorKeyword = $rule.keyword;
|
||||
var $$outStack = $$outStack || [];
|
||||
$$outStack.push(out);
|
||||
out = '';
|
||||
var $$outStack = $$outStack || [];
|
||||
$$outStack.push(out);
|
||||
out = ''; /* istanbul ignore else */
|
||||
if (it.createErrors !== false) {
|
||||
out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } ';
|
||||
if (it.opts.messages !== false) {
|
||||
out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
|
||||
}
|
||||
if (it.opts.verbose) {
|
||||
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||
}
|
||||
out += ' } ';
|
||||
} else {
|
||||
out += ' {} ';
|
||||
}
|
||||
var __err = out;
|
||||
out = $$outStack.pop();
|
||||
if (!it.compositeRule && $breakOnError) {
|
||||
/* istanbul ignore if */
|
||||
if (it.async) {
|
||||
out += ' throw new ValidationError([' + (__err) + ']); ';
|
||||
} else {
|
||||
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
||||
}
|
||||
} else {
|
||||
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||
}
|
||||
var def_customError = out;
|
||||
out = $$outStack.pop();
|
||||
if ($inline) {
|
||||
if ($rDef.errors) {
|
||||
if ($rDef.errors != 'full') {
|
||||
out += ' for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } ';
|
||||
if (it.opts.verbose) {
|
||||
out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
|
||||
}
|
||||
out += ' } ';
|
||||
}
|
||||
} else {
|
||||
if ($rDef.errors === false) {
|
||||
out += ' ' + (def_customError) + ' ';
|
||||
} else {
|
||||
out += ' if (' + ($errs) + ' == errors) { ' + (def_customError) + ' } else { for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } ';
|
||||
if (it.opts.verbose) {
|
||||
out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
|
||||
}
|
||||
out += ' } } ';
|
||||
}
|
||||
}
|
||||
} else if ($macro) {
|
||||
out += ' var err = '; /* istanbul ignore else */
|
||||
if (it.createErrors !== false) {
|
||||
out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } ';
|
||||
if (it.opts.messages !== false) {
|
||||
out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
|
||||
}
|
||||
if (it.opts.verbose) {
|
||||
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||
}
|
||||
out += ' } ';
|
||||
} else {
|
||||
out += ' {} ';
|
||||
}
|
||||
out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||
if (!it.compositeRule && $breakOnError) {
|
||||
/* istanbul ignore if */
|
||||
if (it.async) {
|
||||
out += ' throw new ValidationError(vErrors); ';
|
||||
} else {
|
||||
out += ' validate.errors = vErrors; return false; ';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($rDef.errors === false) {
|
||||
out += ' ' + (def_customError) + ' ';
|
||||
} else {
|
||||
out += ' if (Array.isArray(' + ($ruleErrs) + ')) { if (vErrors === null) vErrors = ' + ($ruleErrs) + '; else vErrors = vErrors.concat(' + ($ruleErrs) + '); errors = vErrors.length; for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; ';
|
||||
if (it.opts.verbose) {
|
||||
out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
|
||||
}
|
||||
out += ' } } else { ' + (def_customError) + ' } ';
|
||||
}
|
||||
}
|
||||
out += ' } ';
|
||||
if ($breakOnError) {
|
||||
out += ' else { ';
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
var Type = require('../type');
|
||||
|
||||
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
var _toString = Object.prototype.toString;
|
||||
|
||||
function resolveYamlOmap(data) {
|
||||
if (data === null) return true;
|
||||
|
||||
var objectKeys = [], index, length, pair, pairKey, pairHasKey,
|
||||
object = data;
|
||||
|
||||
for (index = 0, length = object.length; index < length; index += 1) {
|
||||
pair = object[index];
|
||||
pairHasKey = false;
|
||||
|
||||
if (_toString.call(pair) !== '[object Object]') return false;
|
||||
|
||||
for (pairKey in pair) {
|
||||
if (_hasOwnProperty.call(pair, pairKey)) {
|
||||
if (!pairHasKey) pairHasKey = true;
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pairHasKey) return false;
|
||||
|
||||
if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
|
||||
else return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function constructYamlOmap(data) {
|
||||
return data !== null ? data : [];
|
||||
}
|
||||
|
||||
module.exports = new Type('tag:yaml.org,2002:omap', {
|
||||
kind: 'sequence',
|
||||
resolve: resolveYamlOmap,
|
||||
construct: constructYamlOmap
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
import { RouteIds } from './routeInfo.cjs';
|
||||
import { RegisteredRouter } from './router.cjs';
|
||||
export type NotFoundError = {
|
||||
/**
|
||||
@deprecated
|
||||
Use `routeId: rootRouteId` instead
|
||||
*/
|
||||
global?: boolean;
|
||||
/**
|
||||
@private
|
||||
Do not use this. It's used internally to indicate a path matching error
|
||||
*/
|
||||
_global?: boolean;
|
||||
data?: any;
|
||||
throw?: boolean;
|
||||
routeId?: RouteIds<RegisteredRouter['routeTree']>;
|
||||
headers?: HeadersInit;
|
||||
};
|
||||
export declare function notFound(options?: NotFoundError): NotFoundError;
|
||||
export declare function isNotFound(obj: any): obj is NotFoundError;
|
||||
@@ -0,0 +1,107 @@
|
||||
import { useEffect } from 'react';
|
||||
import makeCancellable from 'make-cancellable-promise';
|
||||
import invariant from 'tiny-invariant';
|
||||
import warning from 'warning';
|
||||
|
||||
import StructTreeItem from './StructTreeItem.js';
|
||||
|
||||
import usePageContext from './shared/hooks/usePageContext.js';
|
||||
import useResolver from './shared/hooks/useResolver.js';
|
||||
import { cancelRunningTask } from './shared/utils.js';
|
||||
|
||||
import type { StructTreeNodeWithExtraAttributes } from './shared/types.js';
|
||||
|
||||
export default function StructTree(): React.ReactElement | null {
|
||||
const pageContext = usePageContext();
|
||||
|
||||
invariant(pageContext, 'Unable to find Page context.');
|
||||
|
||||
const {
|
||||
onGetStructTreeError: onGetStructTreeErrorProps,
|
||||
onGetStructTreeSuccess: onGetStructTreeSuccessProps,
|
||||
} = pageContext;
|
||||
|
||||
const [structTreeState, structTreeDispatch] = useResolver<StructTreeNodeWithExtraAttributes>();
|
||||
const { value: structTree, error: structTreeError } = structTreeState;
|
||||
|
||||
const { customTextRenderer, page } = pageContext;
|
||||
|
||||
function onLoadSuccess() {
|
||||
if (!structTree) {
|
||||
// Impossible, but TypeScript doesn't know that
|
||||
return;
|
||||
}
|
||||
|
||||
if (onGetStructTreeSuccessProps) {
|
||||
onGetStructTreeSuccessProps(structTree);
|
||||
}
|
||||
}
|
||||
|
||||
function onLoadError() {
|
||||
if (!structTreeError) {
|
||||
// Impossible, but TypeScript doesn't know that
|
||||
return;
|
||||
}
|
||||
|
||||
warning(false, structTreeError.toString());
|
||||
|
||||
if (onGetStructTreeErrorProps) {
|
||||
onGetStructTreeErrorProps(structTreeError);
|
||||
}
|
||||
}
|
||||
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: useEffect intentionally triggered on page change
|
||||
useEffect(
|
||||
function resetStructTree() {
|
||||
structTreeDispatch({ type: 'RESET' });
|
||||
},
|
||||
[structTreeDispatch, page],
|
||||
);
|
||||
|
||||
useEffect(
|
||||
function loadStructTree() {
|
||||
if (customTextRenderer) {
|
||||
// TODO: Document why this is necessary
|
||||
return;
|
||||
}
|
||||
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cancellable = makeCancellable(page.getStructTree());
|
||||
const runningTask = cancellable;
|
||||
|
||||
cancellable.promise
|
||||
.then((nextStructTree) => {
|
||||
structTreeDispatch({ type: 'RESOLVE', value: nextStructTree });
|
||||
})
|
||||
.catch((error) => {
|
||||
structTreeDispatch({ type: 'REJECT', error });
|
||||
});
|
||||
|
||||
return () => cancelRunningTask(runningTask);
|
||||
},
|
||||
[customTextRenderer, page, structTreeDispatch],
|
||||
);
|
||||
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: Ommitted callbacks so they are not called every time they change
|
||||
useEffect(() => {
|
||||
if (structTree === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (structTree === false) {
|
||||
onLoadError();
|
||||
return;
|
||||
}
|
||||
|
||||
onLoadSuccess();
|
||||
}, [structTree]);
|
||||
|
||||
if (!structTree) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <StructTreeItem className="react-pdf__Page__structTree structTree" node={structTree} />;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
'use client';
|
||||
import { createContext } from 'react';
|
||||
const pageContext = createContext(null);
|
||||
export default pageContext;
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user