node_modules: upgrade

This commit is contained in:
Dawid Dziurla
2024-01-17 10:08:10 +01:00
parent 9ff0bc8d99
commit 00765f79cf
320 changed files with 31840 additions and 1039 deletions

View File

@@ -1,4 +1,4 @@
import { MAP, SCALAR, SEQ } from '../nodes/Node.js';
import { MAP, SCALAR, SEQ } from '../nodes/identity.js';
import type { Pair } from '../nodes/Pair.js';
import type { SchemaOptions, ToStringOptions } from '../options.js';
import type { CollectionTag, ScalarTag } from './types.js';

View File

@@ -1,6 +1,6 @@
'use strict';
var Node = require('../nodes/Node.js');
var identity = require('../nodes/identity.js');
var map = require('./common/map.js');
var seq = require('./common/seq.js');
var string = require('./common/string.js');
@@ -19,9 +19,9 @@ class Schema {
this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
this.tags = tags.getTags(customTags, this.name);
this.toStringOptions = toStringDefaults ?? null;
Object.defineProperty(this, Node.MAP, { value: map.map });
Object.defineProperty(this, Node.SCALAR, { value: string.string });
Object.defineProperty(this, Node.SEQ, { value: seq.seq });
Object.defineProperty(this, identity.MAP, { value: map.map });
Object.defineProperty(this, identity.SCALAR, { value: string.string });
Object.defineProperty(this, identity.SEQ, { value: seq.seq });
// Used by createMap()
this.sortMapEntries =
typeof sortMapEntries === 'function'

View File

@@ -1,44 +1,19 @@
'use strict';
var Node = require('../../nodes/Node.js');
var Pair = require('../../nodes/Pair.js');
var identity = require('../../nodes/identity.js');
var YAMLMap = require('../../nodes/YAMLMap.js');
function createMap(schema, obj, ctx) {
const { keepUndefined, replacer } = ctx;
const map = new YAMLMap.YAMLMap(schema);
const add = (key, value) => {
if (typeof replacer === 'function')
value = replacer.call(obj, key, value);
else if (Array.isArray(replacer) && !replacer.includes(key))
return;
if (value !== undefined || keepUndefined)
map.items.push(Pair.createPair(key, value, ctx));
};
if (obj instanceof Map) {
for (const [key, value] of obj)
add(key, value);
}
else if (obj && typeof obj === 'object') {
for (const key of Object.keys(obj))
add(key, obj[key]);
}
if (typeof schema.sortMapEntries === 'function') {
map.items.sort(schema.sortMapEntries);
}
return map;
}
const map = {
collection: 'map',
createNode: createMap,
default: true,
nodeClass: YAMLMap.YAMLMap,
tag: 'tag:yaml.org,2002:map',
resolve(map, onError) {
if (!Node.isMap(map))
if (!identity.isMap(map))
onError('Expected a mapping for this tag');
return map;
}
},
createNode: (schema, obj, ctx) => YAMLMap.YAMLMap.from(schema, obj, ctx)
};
exports.map = map;

View File

@@ -1,35 +1,19 @@
'use strict';
var createNode = require('../../doc/createNode.js');
var Node = require('../../nodes/Node.js');
var identity = require('../../nodes/identity.js');
var YAMLSeq = require('../../nodes/YAMLSeq.js');
function createSeq(schema, obj, ctx) {
const { replacer } = ctx;
const seq = new YAMLSeq.YAMLSeq(schema);
if (obj && Symbol.iterator in Object(obj)) {
let i = 0;
for (let it of obj) {
if (typeof replacer === 'function') {
const key = obj instanceof Set ? it : String(i++);
it = replacer.call(obj, key, it);
}
seq.items.push(createNode.createNode(it, undefined, ctx));
}
}
return seq;
}
const seq = {
collection: 'seq',
createNode: createSeq,
default: true,
nodeClass: YAMLSeq.YAMLSeq,
tag: 'tag:yaml.org,2002:seq',
resolve(seq, onError) {
if (!Node.isSeq(seq))
if (!identity.isSeq(seq))
onError('Expected a sequence for this tag');
return seq;
}
},
createNode: (schema, obj, ctx) => YAMLSeq.YAMLSeq.from(schema, obj, ctx)
};
exports.seq = seq;

View File

@@ -1 +1 @@
export declare const schema: (import("../types.js").ScalarTag | import("../types.js").CollectionTag)[];
export declare const schema: (import("../types.js").CollectionTag | import("../types.js").ScalarTag)[];

View File

@@ -1,5 +1,5 @@
declare type JsonSchema = boolean | ArraySchema | ObjectSchema | NumberSchema | StringSchema;
declare type JsonType = 'array' | 'object' | 'string' | 'number' | 'integer' | 'boolean' | 'null';
type JsonSchema = boolean | ArraySchema | ObjectSchema | NumberSchema | StringSchema;
type JsonType = 'array' | 'object' | 'string' | 'number' | 'integer' | 'boolean' | 'null';
interface CommonSchema {
type?: JsonType | JsonType[];
const?: unknown;

View File

@@ -1,2 +1,2 @@
import { CollectionTag, ScalarTag } from '../types.js';
export declare const schema: (ScalarTag | CollectionTag)[];
export declare const schema: (CollectionTag | ScalarTag)[];

View File

@@ -25,8 +25,8 @@ declare const tagsByName: {
test: RegExp;
};
};
export declare type TagId = keyof typeof tagsByName;
export declare type Tags = Array<ScalarTag | CollectionTag | TagId>;
export type TagId = keyof typeof tagsByName;
export type Tags = Array<ScalarTag | CollectionTag | TagId>;
export declare const coreKnownTags: {
'tag:yaml.org,2002:binary': ScalarTag;
'tag:yaml.org,2002:omap': CollectionTag;
@@ -36,5 +36,5 @@ export declare const coreKnownTags: {
test: RegExp;
};
};
export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: string): (ScalarTag | CollectionTag)[];
export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: string): (CollectionTag | ScalarTag)[];
export {};

View File

@@ -1,11 +1,11 @@
import type { CreateNodeContext } from '../doc/createNode.js';
import type { Schema } from './Schema.js';
import type { Node } from '../nodes/Node.js';
import type { Scalar } from '../nodes/Scalar.js';
import type { YAMLMap } from '../nodes/YAMLMap.js';
import type { YAMLSeq } from '../nodes/YAMLSeq.js';
import type { ParseOptions } from '../options.js';
import type { StringifyContext } from '../stringify/stringify.js';
import type { Schema } from './Schema.js';
interface TagBase {
/**
* An optional factory function, used e.g. by collections when wrapping JS objects as AST nodes.
@@ -16,7 +16,7 @@ interface TagBase {
* an explicit tag. For most cases, it's unlikely that you'll actually want to
* use this, even if you first think you do.
*/
default: boolean;
default?: boolean;
/**
* If a tag has multiple forms that should be parsed and/or stringified
* differently, use `format` to identify them.
@@ -71,12 +71,20 @@ export interface CollectionTag extends TagBase {
/**
* The `Node` child class that implements this tag.
* If set, used to select this tag when stringifying.
*
* If the class provides a static `from` method, then that
* will be used if the tag object doesn't have a `createNode` method.
*/
nodeClass?: new () => Node;
nodeClass?: {
new (schema?: Schema): Node;
from?: (schema: Schema, obj: unknown, ctx: CreateNodeContext) => Node;
};
/**
* Turns a value into an AST node.
* If returning a non-`Node` value, the output will be wrapped as a `Scalar`.
*
* Note: this is required if nodeClass is not provided.
*/
resolve(value: YAMLMap.Parsed | YAMLSeq.Parsed, onError: (message: string) => void, options: ParseOptions): unknown;
resolve?: (value: YAMLMap.Parsed | YAMLSeq.Parsed, onError: (message: string) => void, options: ParseOptions) => unknown;
}
export {};

View File

@@ -1,5 +1,7 @@
import { YAMLSeq } from '../../nodes/YAMLSeq.js';
import { ToJSContext } from '../../nodes/toJS.js';
import { YAMLSeq } from '../../nodes/YAMLSeq.js';
import { CreateNodeContext } from '../../util.js';
import type { Schema } from '../Schema.js';
import { CollectionTag } from '../types.js';
export declare class YAMLOMap extends YAMLSeq {
static tag: string;
@@ -21,5 +23,6 @@ export declare class YAMLOMap extends YAMLSeq {
* but TypeScript won't allow widening the signature of a child method.
*/
toJSON(_?: unknown, ctx?: ToJSContext): unknown[];
static from(schema: Schema, iterable: unknown, ctx: CreateNodeContext): YAMLOMap;
}
export declare const omap: CollectionTag;

View File

@@ -1,9 +1,9 @@
'use strict';
var YAMLSeq = require('../../nodes/YAMLSeq.js');
var identity = require('../../nodes/identity.js');
var toJS = require('../../nodes/toJS.js');
var Node = require('../../nodes/Node.js');
var YAMLMap = require('../../nodes/YAMLMap.js');
var YAMLSeq = require('../../nodes/YAMLSeq.js');
var pairs = require('./pairs.js');
class YAMLOMap extends YAMLSeq.YAMLSeq {
@@ -28,7 +28,7 @@ class YAMLOMap extends YAMLSeq.YAMLSeq {
ctx.onCreate(map);
for (const pair of this.items) {
let key, value;
if (Node.isPair(pair)) {
if (identity.isPair(pair)) {
key = toJS.toJS(pair.key, '', ctx);
value = toJS.toJS(pair.value, key, ctx);
}
@@ -41,6 +41,12 @@ class YAMLOMap extends YAMLSeq.YAMLSeq {
}
return map;
}
static from(schema, iterable, ctx) {
const pairs$1 = pairs.createPairs(schema, iterable, ctx);
const omap = new this();
omap.items = pairs$1.items;
return omap;
}
}
YAMLOMap.tag = 'tag:yaml.org,2002:omap';
const omap = {
@@ -53,7 +59,7 @@ const omap = {
const pairs$1 = pairs.resolvePairs(seq, onError);
const seenKeys = [];
for (const { key } of pairs$1.items) {
if (Node.isScalar(key)) {
if (identity.isScalar(key)) {
if (seenKeys.includes(key.value)) {
onError(`Ordered maps must not include duplicate keys: ${key.value}`);
}
@@ -64,12 +70,7 @@ const omap = {
}
return Object.assign(new YAMLOMap(), pairs$1);
},
createNode(schema, iterable, ctx) {
const pairs$1 = pairs.createPairs(schema, iterable, ctx);
const omap = new YAMLOMap();
omap.items = pairs$1.items;
return omap;
}
createNode: (schema, iterable, ctx) => YAMLOMap.from(schema, iterable, ctx)
};
exports.YAMLOMap = YAMLOMap;

View File

@@ -1,5 +1,5 @@
import type { CreateNodeContext } from '../../doc/createNode.js';
import { ParsedNode } from '../../nodes/Node.js';
import type { ParsedNode } from '../../nodes/Node.js';
import { Pair } from '../../nodes/Pair.js';
import { YAMLMap } from '../../nodes/YAMLMap.js';
import { YAMLSeq } from '../../nodes/YAMLSeq.js';

View File

@@ -1,17 +1,17 @@
'use strict';
var Node = require('../../nodes/Node.js');
var identity = require('../../nodes/identity.js');
var Pair = require('../../nodes/Pair.js');
var Scalar = require('../../nodes/Scalar.js');
var YAMLSeq = require('../../nodes/YAMLSeq.js');
function resolvePairs(seq, onError) {
if (Node.isSeq(seq)) {
if (identity.isSeq(seq)) {
for (let i = 0; i < seq.items.length; ++i) {
let item = seq.items[i];
if (Node.isPair(item))
if (identity.isPair(item))
continue;
else if (Node.isMap(item)) {
else if (identity.isMap(item)) {
if (item.items.length > 1)
onError('Each pair must have its own sequence indicator');
const pair = item.items[0] || new Pair.Pair(new Scalar.Scalar(null));
@@ -27,7 +27,7 @@ function resolvePairs(seq, onError) {
}
item = pair;
}
seq.items[i] = Node.isPair(item) ? item : new Pair.Pair(item);
seq.items[i] = identity.isPair(item) ? item : new Pair.Pair(item);
}
}
else
@@ -58,8 +58,9 @@ function createPairs(schema, iterable, ctx) {
key = keys[0];
value = it[key];
}
else
throw new TypeError(`Expected { key: value } tuple: ${it}`);
else {
throw new TypeError(`Expected tuple with one key, not ${keys.length} keys`);
}
}
else {
key = it;

View File

@@ -1 +1 @@
export declare const schema: (import("../types.js").ScalarTag | import("../types.js").CollectionTag)[];
export declare const schema: (import("../types.js").CollectionTag | import("../types.js").ScalarTag)[];

View File

@@ -1,9 +1,10 @@
import type { Schema } from '../../schema/Schema.js';
import { Pair } from '../../nodes/Pair.js';
import { Scalar } from '../../nodes/Scalar.js';
import { ToJSContext } from '../../nodes/toJS.js';
import { YAMLMap } from '../../nodes/YAMLMap.js';
import type { Schema } from '../../schema/Schema.js';
import type { StringifyContext } from '../../stringify/stringify.js';
import { CreateNodeContext } from '../../util.js';
import type { CollectionTag } from '../types.js';
export declare class YAMLSet<T = unknown> extends YAMLMap<T, Scalar<null> | null> {
static tag: string;
@@ -22,5 +23,6 @@ export declare class YAMLSet<T = unknown> extends YAMLMap<T, Scalar<null> | null
set(key: T, value: null): void;
toJSON(_?: unknown, ctx?: ToJSContext): any;
toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
static from(schema: Schema, iterable: unknown, ctx: CreateNodeContext): YAMLSet<unknown>;
}
export declare const set: CollectionTag;

View File

@@ -1,6 +1,6 @@
'use strict';
var Node = require('../../nodes/Node.js');
var identity = require('../../nodes/identity.js');
var Pair = require('../../nodes/Pair.js');
var YAMLMap = require('../../nodes/YAMLMap.js');
@@ -11,7 +11,7 @@ class YAMLSet extends YAMLMap.YAMLMap {
}
add(key) {
let pair;
if (Node.isPair(key))
if (identity.isPair(key))
pair = key;
else if (key &&
typeof key === 'object' &&
@@ -31,8 +31,8 @@ class YAMLSet extends YAMLMap.YAMLMap {
*/
get(key, keepPair) {
const pair = YAMLMap.findPair(this.items, key);
return !keepPair && Node.isPair(pair)
? Node.isScalar(pair.key)
return !keepPair && identity.isPair(pair)
? identity.isScalar(pair.key)
? pair.key.value
: pair.key
: pair;
@@ -59,28 +59,9 @@ class YAMLSet extends YAMLMap.YAMLMap {
else
throw new Error('Set items must all have null values');
}
}
YAMLSet.tag = 'tag:yaml.org,2002:set';
const set = {
collection: 'map',
identify: value => value instanceof Set,
nodeClass: YAMLSet,
default: false,
tag: 'tag:yaml.org,2002:set',
resolve(map, onError) {
if (Node.isMap(map)) {
if (map.hasAllNullValues(true))
return Object.assign(new YAMLSet(), map);
else
onError('Set items must all have null values');
}
else
onError('Expected a mapping for this tag');
return map;
},
createNode(schema, iterable, ctx) {
static from(schema, iterable, ctx) {
const { replacer } = ctx;
const set = new YAMLSet(schema);
const set = new this(schema);
if (iterable && Symbol.iterator in Object(iterable))
for (let value of iterable) {
if (typeof replacer === 'function')
@@ -89,6 +70,26 @@ const set = {
}
return set;
}
}
YAMLSet.tag = 'tag:yaml.org,2002:set';
const set = {
collection: 'map',
identify: value => value instanceof Set,
nodeClass: YAMLSet,
default: false,
tag: 'tag:yaml.org,2002:set',
createNode: (schema, iterable, ctx) => YAMLSet.from(schema, iterable, ctx),
resolve(map, onError) {
if (identity.isMap(map)) {
if (map.hasAllNullValues(true))
return Object.assign(new YAMLSet(), map);
else
onError('Set items must all have null values');
}
else
onError('Expected a mapping for this tag');
return map;
}
};
exports.YAMLSet = YAMLSet;

View File

@@ -45,7 +45,7 @@ function stringifySexagesimal(node) {
}
return (sign +
parts
.map(n => (n < 10 ? '0' + String(n) : String(n)))
.map(n => String(n).padStart(2, '0'))
.join(':')
.replace(/000000\d*$/, '') // % 60 may introduce error
);