@circleci/circleci-config-sdk
Advanced tools
Comparing version 0.5.0-alpha.5 to 0.5.0-alpha.6
export * as commands from './lib/Components/Commands'; | ||
export { Job } from './lib/Components/Job'; | ||
export { ParameterizedJob } from './lib/Components/Job/ParameterizedJob'; | ||
export { ParameterizedJob } from './lib/Components/Job/exports/ParameterizedJob'; | ||
export { Workflow } from './lib/Components/Workflow'; | ||
export { WorkflowJob } from './lib/Components/Workflow/WorkflowJob'; | ||
export { WorkflowJob } from './lib/Components/Workflow/exports/WorkflowJob'; | ||
export { Config } from './lib/Config'; | ||
@@ -7,0 +7,0 @@ export { Pipeline } from './lib/Config/Pipeline/index'; |
@@ -1,10 +0,10 @@ | ||
export { Run } from './Native/Run'; | ||
export { Checkout } from './Native/Checkout'; | ||
export * as cache from './Native/Cache'; | ||
export * as workspace from './Native/Workspace'; | ||
export { StoreTestResults } from './Native/StoreTestResults'; | ||
export { StoreArtifacts } from './Native/StoreArtifacts'; | ||
export { SetupRemoteDocker } from './Native/SetupRemoteDocker'; | ||
export { AddSSHKeys } from './Native/AddSSHKeys'; | ||
export * as reusable from './Reusable'; | ||
export { Run } from './exports/Native/Run'; | ||
export { Checkout } from './exports/Native/Checkout'; | ||
export * as cache from './exports/Native/Cache'; | ||
export * as workspace from './exports/Native/Workspace'; | ||
export { StoreTestResults } from './exports/Native/StoreTestResults'; | ||
export { StoreArtifacts } from './exports/Native/StoreArtifacts'; | ||
export { SetupRemoteDocker } from './exports/Native/SetupRemoteDocker'; | ||
export { AddSSHKeys } from './exports/Native/AddSSHKeys'; | ||
export * as reusable from './exports/Reusable'; | ||
//# sourceMappingURL=index.d.ts.map |
/** | ||
* Instantiate a CircleCI Executor, the build environment for a job. Select a type of executor and supply the required parameters. | ||
*/ | ||
export { DockerExecutor } from './DockerExecutor'; | ||
export { MachineExecutor } from './MachineExecutor'; | ||
export { MacOSExecutor } from './MacOSExecutor'; | ||
export { WindowsExecutor } from './WindowsExecutor'; | ||
export { ReusableExecutor } from './ReusableExecutor'; | ||
import { DockerExecutor } from './exports/DockerExecutor'; | ||
import { Executor } from './exports/Executor'; | ||
import { MachineExecutor } from './exports/MachineExecutor'; | ||
import { MacOSExecutor } from './exports/MacOSExecutor'; | ||
import { ReusableExecutor } from './exports/ReusableExecutor'; | ||
import { WindowsExecutor } from './exports/WindowsExecutor'; | ||
/** | ||
* Parse executor type from an object with an executor. | ||
* @returns Executor of the corresponding type | ||
*/ | ||
declare function parse(executorIn: { | ||
resource_class: string; | ||
[key: string]: unknown; | ||
}): Executor | undefined; | ||
export { DockerExecutor, MachineExecutor, MacOSExecutor, WindowsExecutor, ReusableExecutor, parse, }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,6 +0,6 @@ | ||
import { Command } from '../Commands/Command'; | ||
import { AbstractExecutor } from '../Executor/Executor'; | ||
import { ExecutorSchema } from '../Executor/Executor.types'; | ||
import { ReusableExecutor } from '../Executor/ReusableExecutor'; | ||
import { Command } from '../Commands/exports/Command'; | ||
import { Executor } from '../Executor/exports/Executor'; | ||
import { ReusableExecutor } from '../Executor/exports/ReusableExecutor'; | ||
import { Component } from '../index'; | ||
import { JobContentShape, JobShape } from './types/Job.types'; | ||
/** | ||
@@ -17,3 +17,3 @@ * Jobs define a collection of steps to be run within a given executor, and are orchestrated using Workflows. | ||
*/ | ||
executor: AbstractExecutor | ReusableExecutor; | ||
executor: Executor | ReusableExecutor; | ||
/** | ||
@@ -30,3 +30,3 @@ * A list of Commands to execute within the job in the order which they were added. | ||
*/ | ||
constructor(name: string, executor: AbstractExecutor | ReusableExecutor, steps?: Command[]); | ||
constructor(name: string, executor: Executor | ReusableExecutor, steps?: Command[]); | ||
/** | ||
@@ -36,3 +36,3 @@ * Generates the contents of the Job. | ||
*/ | ||
generateJobContents(): JobContentSchema; | ||
generateJobContents(): JobContentShape; | ||
/** | ||
@@ -42,3 +42,3 @@ * Generate Job schema | ||
*/ | ||
generate(): JobSchema; | ||
generate(): JobShape; | ||
/** | ||
@@ -50,9 +50,2 @@ * Add steps to the current Job. Chainable. | ||
} | ||
export interface JobStepsSchema { | ||
steps: unknown[]; | ||
} | ||
export declare type JobContentSchema = JobStepsSchema & ExecutorSchema; | ||
export interface JobSchema { | ||
[key: string]: JobContentSchema; | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
import { Component } from '..'; | ||
import { AnyParameterLiteral, EnumParameterLiteral, ParameterSchema, ParameterValues } from './Parameters.types'; | ||
declare type CustomParameterSchema<ParameterTypeLiteral> = { | ||
type: ParameterTypeLiteral; | ||
default: unknown; | ||
description?: string; | ||
}; | ||
declare type CustomEnumParameterSchema = CustomParameterSchema<EnumParameterLiteral> & { | ||
enum?: string[]; | ||
}; | ||
import { ValidationResult } from '../../Config/ConfigValidator'; | ||
import { CustomParametersList } from './exports/CustomParameterList'; | ||
import { AnyParameterLiteral, EnumParameterLiteral, ParameterizedComponentLiteral } from './types/CustomParameterLiterals.types'; | ||
import { CustomEnumParameterShape, CustomParameterShape, ParameterShape, ParameterValues } from './types/Parameters.types'; | ||
/** | ||
@@ -24,3 +19,3 @@ * Accepted parameters can be assigned to a component. | ||
*/ | ||
export declare class CustomParameter<ParameterTypeLiteral> extends Component implements ParameterValues<ParameterTypeLiteral> { | ||
export declare class CustomParameter<ParameterTypeLiteral extends AnyParameterLiteral> extends Component implements ParameterValues<ParameterTypeLiteral> { | ||
name: string; | ||
@@ -34,3 +29,4 @@ type: ParameterTypeLiteral; | ||
*/ | ||
generate(): CustomParameterSchema<ParameterTypeLiteral>; | ||
generate(): CustomParameterShape<ParameterTypeLiteral>; | ||
static validate(input: unknown, type: ParameterizedComponentLiteral): ValidationResult; | ||
} | ||
@@ -50,28 +46,7 @@ /** | ||
constructor(name: string, enumValues: string[], defaultValue?: unknown, description?: string); | ||
generate(): CustomEnumParameterSchema; | ||
generate(): CustomEnumParameterShape; | ||
static validate(input: unknown): ValidationResult; | ||
} | ||
/** | ||
* A list that can be added to a component. | ||
* | ||
* For use in {@link ParameterizedComponent} | ||
* | ||
* {@label STATIC_2.1} | ||
*/ | ||
export declare class CustomParametersList<ParameterTypeLiteral extends AnyParameterLiteral> extends Component { | ||
parameters: CustomParameter<ParameterTypeLiteral>[]; | ||
constructor(parameters?: CustomParameter<ParameterTypeLiteral>[]); | ||
generate(): CustomParametersSchema; | ||
/** | ||
* Define a parameter to be available to the workflow job. Useful for static configurations. | ||
* @param name - name of the parameter | ||
* @param type - the literal type of the parameter | ||
* @param defaultValue - optional default value of parameter. If this is not provided, the parameter will be required. | ||
* @param description - optional description of parameter | ||
* @param enumValues - list of selectable enum values. Only applicable for enum type parameters. | ||
* @returns this for chaining | ||
*/ | ||
define(name: string, type: ParameterTypeLiteral, defaultValue?: unknown, description?: string, enumValues?: string[]): CustomParameter<ParameterTypeLiteral>; | ||
} | ||
export declare type CustomParametersSchema = Record<string, ParameterSchema>; | ||
export {}; | ||
export declare type CustomParametersShape = Record<string, ParameterShape>; | ||
export { CustomParametersList }; | ||
//# sourceMappingURL=index.d.ts.map |
import { Job } from '../Job'; | ||
import { WorkflowJobParameters } from './Workflow'; | ||
import { WorkflowJob } from './WorkflowJob'; | ||
import { WorkflowJob } from './exports/WorkflowJob'; | ||
import { WorkflowJobParameters } from './types/WorkflowJob.types'; | ||
/** | ||
@@ -23,3 +23,3 @@ * A workflow is a set of rules for defining a collection of jobs and their run order. | ||
/** | ||
* Generate Workflow schema. | ||
* Generate Workflow Shape. | ||
* @returns The generated JSON for the Workflow. | ||
@@ -26,0 +26,0 @@ */ |
@@ -1,7 +0,8 @@ | ||
import { CustomCommand } from '../Components/Commands/Reusable'; | ||
import { CustomCommand } from '../Components/Commands/exports/Reusable'; | ||
import { ReusableExecutor } from '../Components/Executor'; | ||
import { Job } from '../Components/Job'; | ||
import { CustomParametersList } from '../Components/Parameters'; | ||
import { PrimitiveParameterLiteral } from '../Components/Parameters/Parameters.types'; | ||
import { PipelineParameterLiteral } from '../Components/Parameters/types/CustomParameterLiterals.types'; | ||
import { Workflow } from '../Components/Workflow'; | ||
import { ConfigValidator } from './ConfigValidator'; | ||
import { Pipeline } from './Pipeline'; | ||
@@ -12,2 +13,3 @@ /** | ||
export declare class Config implements CircleCIConfigObject { | ||
static validator: ConfigValidator; | ||
/** | ||
@@ -36,3 +38,3 @@ * The version field is intended to be used in order to issue warnings for deprecation or breaking changes. | ||
*/ | ||
parameters?: CustomParametersList<PrimitiveParameterLiteral>; | ||
parameters?: CustomParametersList<PipelineParameterLiteral>; | ||
/** | ||
@@ -52,3 +54,3 @@ * Access information about the current pipeline. | ||
*/ | ||
constructor(setup?: boolean, jobs?: Job[], workflows?: Workflow[], executors?: ReusableExecutor[], commands?: CustomCommand[], parameters?: CustomParametersList<PrimitiveParameterLiteral>); | ||
constructor(setup?: boolean, jobs?: Job[], workflows?: Workflow[], executors?: ReusableExecutor[], commands?: CustomCommand[], parameters?: CustomParametersList<PipelineParameterLiteral>); | ||
/** | ||
@@ -83,3 +85,3 @@ * Add a Workflow to the current Config. Chainable | ||
*/ | ||
defineParameter(name: string, type: PrimitiveParameterLiteral, defaultValue?: unknown, description?: string, enumValues?: string[]): Config; | ||
defineParameter(name: string, type: PipelineParameterLiteral, defaultValue?: unknown, description?: string, enumValues?: string[]): Config; | ||
private prependVersionComment; | ||
@@ -86,0 +88,0 @@ /** |
@@ -1,1002 +0,18 @@ | ||
import { d as defaultTagPrefix, _ as _createForOfIteratorHelper, a as _typeof, b as _createClass, c as _classCallCheck, e as _defineProperty, Y as YAMLSyntaxError, T as Type, f as YAMLWarning, g as YAMLSemanticError, h as _slicedToArray, i as YAMLError, j as _inherits, k as _createSuper } from './PlainValue-b8036b75.js'; | ||
import { parse as parse$1 } from './parse-cst.js'; | ||
import { b as binaryOptions, a as boolOptions, i as intOptions, n as nullOptions, s as strOptions, N as Node, P as Pair, S as Scalar, c as stringifyString, A as Alias, Y as YAMLSeq, d as YAMLMap, M as Merge, C as Collection, r as resolveNode, e as isEmptyPath, t as toJSON, f as addComment } from './resolveSeq-492ab440.js'; | ||
import { S as Schema } from './Schema-e94716c8.js'; | ||
import { w as warn } from './warnings-df54cb69.js'; | ||
var defaultOptions = { | ||
anchorPrefix: 'a', | ||
customTags: null, | ||
indent: 2, | ||
indentSeq: true, | ||
keepCstNodes: false, | ||
keepNodeTypes: true, | ||
keepBlobsInJSON: true, | ||
mapAsMap: false, | ||
maxAliasCount: 100, | ||
prettyErrors: false, | ||
// TODO Set true in v2 | ||
simpleKeys: false, | ||
version: '1.2' | ||
}; | ||
var scalarOptions = { | ||
get binary() { | ||
return binaryOptions; | ||
}, | ||
set binary(opt) { | ||
Object.assign(binaryOptions, opt); | ||
}, | ||
get bool() { | ||
return boolOptions; | ||
}, | ||
set bool(opt) { | ||
Object.assign(boolOptions, opt); | ||
}, | ||
get int() { | ||
return intOptions; | ||
}, | ||
set int(opt) { | ||
Object.assign(intOptions, opt); | ||
}, | ||
get null() { | ||
return nullOptions; | ||
}, | ||
set null(opt) { | ||
Object.assign(nullOptions, opt); | ||
}, | ||
get str() { | ||
return strOptions; | ||
}, | ||
set str(opt) { | ||
Object.assign(strOptions, opt); | ||
} | ||
}; | ||
var documentOptions = { | ||
'1.0': { | ||
schema: 'yaml-1.1', | ||
merge: true, | ||
tagPrefixes: [{ | ||
handle: '!', | ||
prefix: defaultTagPrefix | ||
}, { | ||
handle: '!!', | ||
prefix: 'tag:private.yaml.org,2002:' | ||
}] | ||
}, | ||
1.1: { | ||
schema: 'yaml-1.1', | ||
merge: true, | ||
tagPrefixes: [{ | ||
handle: '!', | ||
prefix: '!' | ||
}, { | ||
handle: '!!', | ||
prefix: defaultTagPrefix | ||
}] | ||
}, | ||
1.2: { | ||
schema: 'core', | ||
merge: false, | ||
tagPrefixes: [{ | ||
handle: '!', | ||
prefix: '!' | ||
}, { | ||
handle: '!!', | ||
prefix: defaultTagPrefix | ||
}] | ||
} | ||
}; | ||
function stringifyTag(doc, tag) { | ||
if ((doc.version || doc.options.version) === '1.0') { | ||
var priv = tag.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/); | ||
if (priv) return '!' + priv[1]; | ||
var vocab = tag.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/); | ||
return vocab ? "!".concat(vocab[1], "/").concat(vocab[2]) : "!".concat(tag.replace(/^tag:/, '')); | ||
} | ||
var p = doc.tagPrefixes.find(function (p) { | ||
return tag.indexOf(p.prefix) === 0; | ||
}); | ||
if (!p) { | ||
var dtp = doc.getDefaults().tagPrefixes; | ||
p = dtp && dtp.find(function (p) { | ||
return tag.indexOf(p.prefix) === 0; | ||
}); | ||
} | ||
if (!p) return tag[0] === '!' ? tag : "!<".concat(tag, ">"); | ||
var suffix = tag.substr(p.prefix.length).replace(/[!,[\]{}]/g, function (ch) { | ||
return { | ||
'!': '%21', | ||
',': '%2C', | ||
'[': '%5B', | ||
']': '%5D', | ||
'{': '%7B', | ||
'}': '%7D' | ||
}[ch]; | ||
}); | ||
return p.handle + suffix; | ||
} | ||
function getTagObject(tags, item) { | ||
if (item instanceof Alias) return Alias; | ||
if (item.tag) { | ||
var match = tags.filter(function (t) { | ||
return t.tag === item.tag; | ||
}); | ||
if (match.length > 0) return match.find(function (t) { | ||
return t.format === item.format; | ||
}) || match[0]; | ||
} | ||
var tagObj, obj; | ||
if (item instanceof Scalar) { | ||
obj = item.value; // TODO: deprecate/remove class check | ||
var _match = tags.filter(function (t) { | ||
return t.identify && t.identify(obj) || t.class && obj instanceof t.class; | ||
}); | ||
tagObj = _match.find(function (t) { | ||
return t.format === item.format; | ||
}) || _match.find(function (t) { | ||
return !t.format; | ||
}); | ||
} else { | ||
obj = item; | ||
tagObj = tags.find(function (t) { | ||
return t.nodeClass && obj instanceof t.nodeClass; | ||
}); | ||
} | ||
if (!tagObj) { | ||
var name = obj && obj.constructor ? obj.constructor.name : _typeof(obj); | ||
throw new Error("Tag not resolved for ".concat(name, " value")); | ||
} | ||
return tagObj; | ||
} // needs to be called before value stringifier to allow for circular anchor refs | ||
function stringifyProps(node, tagObj, _ref) { | ||
var anchors = _ref.anchors, | ||
doc = _ref.doc; | ||
var props = []; | ||
var anchor = doc.anchors.getName(node); | ||
if (anchor) { | ||
anchors[anchor] = node; | ||
props.push("&".concat(anchor)); | ||
} | ||
if (node.tag) { | ||
props.push(stringifyTag(doc, node.tag)); | ||
} else if (!tagObj.default) { | ||
props.push(stringifyTag(doc, tagObj.tag)); | ||
} | ||
return props.join(' '); | ||
} | ||
function stringify$1(item, ctx, onComment, onChompKeep) { | ||
var _ctx$doc = ctx.doc, | ||
anchors = _ctx$doc.anchors, | ||
schema = _ctx$doc.schema; | ||
var tagObj; | ||
if (!(item instanceof Node)) { | ||
var createCtx = { | ||
aliasNodes: [], | ||
onTagObj: function onTagObj(o) { | ||
return tagObj = o; | ||
}, | ||
prevObjects: new Map() | ||
}; | ||
item = schema.createNode(item, true, null, createCtx); | ||
var _iterator = _createForOfIteratorHelper(createCtx.aliasNodes), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var alias = _step.value; | ||
alias.source = alias.source.node; | ||
var name = anchors.getName(alias.source); | ||
if (!name) { | ||
name = anchors.newName(); | ||
anchors.map[name] = alias.source; | ||
} | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
} | ||
if (item instanceof Pair) return item.toString(ctx, onComment, onChompKeep); | ||
if (!tagObj) tagObj = getTagObject(schema.tags, item); | ||
var props = stringifyProps(item, tagObj, ctx); | ||
if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1; | ||
var str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof Scalar ? stringifyString(item, ctx, onComment, onChompKeep) : item.toString(ctx, onComment, onChompKeep); | ||
if (!props) return str; | ||
return item instanceof Scalar || str[0] === '{' || str[0] === '[' ? "".concat(props, " ").concat(str) : "".concat(props, "\n").concat(ctx.indent).concat(str); | ||
} | ||
var Anchors = /*#__PURE__*/function () { | ||
function Anchors(prefix) { | ||
_classCallCheck(this, Anchors); | ||
_defineProperty(this, "map", Object.create(null)); | ||
this.prefix = prefix; | ||
} | ||
_createClass(Anchors, [{ | ||
key: "createAlias", | ||
value: function createAlias(node, name) { | ||
this.setAnchor(node, name); | ||
return new Alias(node); | ||
} | ||
}, { | ||
key: "createMergePair", | ||
value: function createMergePair() { | ||
var _this = this; | ||
var merge = new Merge(); | ||
for (var _len = arguments.length, sources = new Array(_len), _key = 0; _key < _len; _key++) { | ||
sources[_key] = arguments[_key]; | ||
} | ||
merge.value.items = sources.map(function (s) { | ||
if (s instanceof Alias) { | ||
if (s.source instanceof YAMLMap) return s; | ||
} else if (s instanceof YAMLMap) { | ||
return _this.createAlias(s); | ||
} | ||
throw new Error('Merge sources must be Map nodes or their Aliases'); | ||
}); | ||
return merge; | ||
} | ||
}, { | ||
key: "getName", | ||
value: function getName(node) { | ||
var map = this.map; | ||
return Object.keys(map).find(function (a) { | ||
return map[a] === node; | ||
}); | ||
} | ||
}, { | ||
key: "getNames", | ||
value: function getNames() { | ||
return Object.keys(this.map); | ||
} | ||
}, { | ||
key: "getNode", | ||
value: function getNode(name) { | ||
return this.map[name]; | ||
} | ||
}, { | ||
key: "newName", | ||
value: function newName(prefix) { | ||
if (!prefix) prefix = this.prefix; | ||
var names = Object.keys(this.map); | ||
for (var i = 1; true; ++i) { | ||
var name = "".concat(prefix).concat(i); | ||
if (!names.includes(name)) return name; | ||
} | ||
} // During parsing, map & aliases contain CST nodes | ||
}, { | ||
key: "resolveNodes", | ||
value: function resolveNodes() { | ||
var map = this.map, | ||
_cstAliases = this._cstAliases; | ||
Object.keys(map).forEach(function (a) { | ||
map[a] = map[a].resolved; | ||
}); | ||
_cstAliases.forEach(function (a) { | ||
a.source = a.source.resolved; | ||
}); | ||
delete this._cstAliases; | ||
} | ||
}, { | ||
key: "setAnchor", | ||
value: function setAnchor(node, name) { | ||
if (node != null && !Anchors.validAnchorNode(node)) { | ||
throw new Error('Anchors may only be set for Scalar, Seq and Map nodes'); | ||
} | ||
if (name && /[\x00-\x19\s,[\]{}]/.test(name)) { | ||
throw new Error('Anchor names must not contain whitespace or control characters'); | ||
} | ||
var map = this.map; | ||
var prev = node && Object.keys(map).find(function (a) { | ||
return map[a] === node; | ||
}); | ||
if (prev) { | ||
if (!name) { | ||
return prev; | ||
} else if (prev !== name) { | ||
delete map[prev]; | ||
map[name] = node; | ||
} | ||
} else { | ||
if (!name) { | ||
if (!node) return null; | ||
name = this.newName(); | ||
} | ||
map[name] = node; | ||
} | ||
return name; | ||
} | ||
}], [{ | ||
key: "validAnchorNode", | ||
value: function validAnchorNode(node) { | ||
return node instanceof Scalar || node instanceof YAMLSeq || node instanceof YAMLMap; | ||
} | ||
}]); | ||
return Anchors; | ||
}(); | ||
var visit = function visit(node, tags) { | ||
if (node && _typeof(node) === 'object') { | ||
var tag = node.tag; | ||
if (node instanceof Collection) { | ||
if (tag) tags[tag] = true; | ||
node.items.forEach(function (n) { | ||
return visit(n, tags); | ||
}); | ||
} else if (node instanceof Pair) { | ||
visit(node.key, tags); | ||
visit(node.value, tags); | ||
} else if (node instanceof Scalar) { | ||
if (tag) tags[tag] = true; | ||
} | ||
} | ||
return tags; | ||
}; | ||
var listTagNames = function listTagNames(node) { | ||
return Object.keys(visit(node, {})); | ||
}; | ||
function parseContents(doc, contents) { | ||
var comments = { | ||
before: [], | ||
after: [] | ||
}; | ||
var body = undefined; | ||
var spaceBefore = false; | ||
var _iterator = _createForOfIteratorHelper(contents), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var node = _step.value; | ||
if (node.valueRange) { | ||
if (body !== undefined) { | ||
var msg = 'Document contains trailing content not separated by a ... or --- line'; | ||
doc.errors.push(new YAMLSyntaxError(node, msg)); | ||
break; | ||
} | ||
var res = resolveNode(doc, node); | ||
if (spaceBefore) { | ||
res.spaceBefore = true; | ||
spaceBefore = false; | ||
} | ||
body = res; | ||
} else if (node.comment !== null) { | ||
var cc = body === undefined ? comments.before : comments.after; | ||
cc.push(node.comment); | ||
} else if (node.type === Type.BLANK_LINE) { | ||
spaceBefore = true; | ||
if (body === undefined && comments.before.length > 0 && !doc.commentBefore) { | ||
// space-separated comments at start are parsed as document comments | ||
doc.commentBefore = comments.before.join('\n'); | ||
comments.before = []; | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
doc.contents = body || null; | ||
if (!body) { | ||
doc.comment = comments.before.concat(comments.after).join('\n') || null; | ||
} else { | ||
var cb = comments.before.join('\n'); | ||
if (cb) { | ||
var cbNode = body instanceof Collection && body.items[0] ? body.items[0] : body; | ||
cbNode.commentBefore = cbNode.commentBefore ? "".concat(cb, "\n").concat(cbNode.commentBefore) : cb; | ||
} | ||
doc.comment = comments.after.join('\n') || null; | ||
} | ||
} | ||
function resolveTagDirective(_ref, directive) { | ||
var tagPrefixes = _ref.tagPrefixes; | ||
var _directive$parameters = _slicedToArray(directive.parameters, 2), | ||
handle = _directive$parameters[0], | ||
prefix = _directive$parameters[1]; | ||
if (!handle || !prefix) { | ||
var msg = 'Insufficient parameters given for %TAG directive'; | ||
throw new YAMLSemanticError(directive, msg); | ||
} | ||
if (tagPrefixes.some(function (p) { | ||
return p.handle === handle; | ||
})) { | ||
var _msg = 'The %TAG directive must only be given at most once per handle in the same document.'; | ||
throw new YAMLSemanticError(directive, _msg); | ||
} | ||
return { | ||
handle: handle, | ||
prefix: prefix | ||
}; | ||
} | ||
function resolveYamlDirective(doc, directive) { | ||
var _directive$parameters2 = _slicedToArray(directive.parameters, 1), | ||
version = _directive$parameters2[0]; | ||
if (directive.name === 'YAML:1.0') version = '1.0'; | ||
if (!version) { | ||
var msg = 'Insufficient parameters given for %YAML directive'; | ||
throw new YAMLSemanticError(directive, msg); | ||
} | ||
if (!documentOptions[version]) { | ||
var v0 = doc.version || doc.options.version; | ||
var _msg2 = "Document will be parsed as YAML ".concat(v0, " rather than YAML ").concat(version); | ||
doc.warnings.push(new YAMLWarning(directive, _msg2)); | ||
} | ||
return version; | ||
} | ||
function parseDirectives(doc, directives, prevDoc) { | ||
var directiveComments = []; | ||
var hasDirectives = false; | ||
var _iterator = _createForOfIteratorHelper(directives), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var directive = _step.value; | ||
var comment = directive.comment, | ||
name = directive.name; | ||
switch (name) { | ||
case 'TAG': | ||
try { | ||
doc.tagPrefixes.push(resolveTagDirective(doc, directive)); | ||
} catch (error) { | ||
doc.errors.push(error); | ||
} | ||
hasDirectives = true; | ||
break; | ||
case 'YAML': | ||
case 'YAML:1.0': | ||
if (doc.version) { | ||
var msg = 'The %YAML directive must only be given at most once per document.'; | ||
doc.errors.push(new YAMLSemanticError(directive, msg)); | ||
} | ||
try { | ||
doc.version = resolveYamlDirective(doc, directive); | ||
} catch (error) { | ||
doc.errors.push(error); | ||
} | ||
hasDirectives = true; | ||
break; | ||
default: | ||
if (name) { | ||
var _msg3 = "YAML only supports %TAG and %YAML directives, and not %".concat(name); | ||
doc.warnings.push(new YAMLWarning(directive, _msg3)); | ||
} | ||
} | ||
if (comment) directiveComments.push(comment); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
if (prevDoc && !hasDirectives && '1.1' === (doc.version || prevDoc.version || doc.options.version)) { | ||
var copyTagPrefix = function copyTagPrefix(_ref2) { | ||
var handle = _ref2.handle, | ||
prefix = _ref2.prefix; | ||
return { | ||
handle: handle, | ||
prefix: prefix | ||
}; | ||
}; | ||
doc.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix); | ||
doc.version = prevDoc.version; | ||
} | ||
doc.commentBefore = directiveComments.join('\n') || null; | ||
} | ||
function assertCollection(contents) { | ||
if (contents instanceof Collection) return true; | ||
throw new Error('Expected a YAML collection as document contents'); | ||
} | ||
var Document$1 = /*#__PURE__*/function () { | ||
function Document(options) { | ||
_classCallCheck(this, Document); | ||
this.anchors = new Anchors(options.anchorPrefix); | ||
this.commentBefore = null; | ||
this.comment = null; | ||
this.contents = null; | ||
this.directivesEndMarker = null; | ||
this.errors = []; | ||
this.options = options; | ||
this.schema = null; | ||
this.tagPrefixes = []; | ||
this.version = null; | ||
this.warnings = []; | ||
} | ||
_createClass(Document, [{ | ||
key: "add", | ||
value: function add(value) { | ||
assertCollection(this.contents); | ||
return this.contents.add(value); | ||
} | ||
}, { | ||
key: "addIn", | ||
value: function addIn(path, value) { | ||
assertCollection(this.contents); | ||
this.contents.addIn(path, value); | ||
} | ||
}, { | ||
key: "delete", | ||
value: function _delete(key) { | ||
assertCollection(this.contents); | ||
return this.contents.delete(key); | ||
} | ||
}, { | ||
key: "deleteIn", | ||
value: function deleteIn(path) { | ||
if (isEmptyPath(path)) { | ||
if (this.contents == null) return false; | ||
this.contents = null; | ||
return true; | ||
} | ||
assertCollection(this.contents); | ||
return this.contents.deleteIn(path); | ||
} | ||
}, { | ||
key: "getDefaults", | ||
value: function getDefaults() { | ||
return Document.defaults[this.version] || Document.defaults[this.options.version] || {}; | ||
} | ||
}, { | ||
key: "get", | ||
value: function get(key, keepScalar) { | ||
return this.contents instanceof Collection ? this.contents.get(key, keepScalar) : undefined; | ||
} | ||
}, { | ||
key: "getIn", | ||
value: function getIn(path, keepScalar) { | ||
if (isEmptyPath(path)) return !keepScalar && this.contents instanceof Scalar ? this.contents.value : this.contents; | ||
return this.contents instanceof Collection ? this.contents.getIn(path, keepScalar) : undefined; | ||
} | ||
}, { | ||
key: "has", | ||
value: function has(key) { | ||
return this.contents instanceof Collection ? this.contents.has(key) : false; | ||
} | ||
}, { | ||
key: "hasIn", | ||
value: function hasIn(path) { | ||
if (isEmptyPath(path)) return this.contents !== undefined; | ||
return this.contents instanceof Collection ? this.contents.hasIn(path) : false; | ||
} | ||
}, { | ||
key: "set", | ||
value: function set(key, value) { | ||
assertCollection(this.contents); | ||
this.contents.set(key, value); | ||
} | ||
}, { | ||
key: "setIn", | ||
value: function setIn(path, value) { | ||
if (isEmptyPath(path)) this.contents = value;else { | ||
assertCollection(this.contents); | ||
this.contents.setIn(path, value); | ||
} | ||
} | ||
}, { | ||
key: "setSchema", | ||
value: function setSchema(id, customTags) { | ||
if (!id && !customTags && this.schema) return; | ||
if (typeof id === 'number') id = id.toFixed(1); | ||
if (id === '1.0' || id === '1.1' || id === '1.2') { | ||
if (this.version) this.version = id;else this.options.version = id; | ||
delete this.options.schema; | ||
} else if (id && typeof id === 'string') { | ||
this.options.schema = id; | ||
} | ||
if (Array.isArray(customTags)) this.options.customTags = customTags; | ||
var opt = Object.assign({}, this.getDefaults(), this.options); | ||
this.schema = new Schema(opt); | ||
} | ||
}, { | ||
key: "parse", | ||
value: function parse(node, prevDoc) { | ||
if (this.options.keepCstNodes) this.cstNode = node; | ||
if (this.options.keepNodeTypes) this.type = 'DOCUMENT'; | ||
var _node$directives = node.directives, | ||
directives = _node$directives === void 0 ? [] : _node$directives, | ||
_node$contents = node.contents, | ||
contents = _node$contents === void 0 ? [] : _node$contents, | ||
directivesEndMarker = node.directivesEndMarker, | ||
error = node.error, | ||
valueRange = node.valueRange; | ||
if (error) { | ||
if (!error.source) error.source = this; | ||
this.errors.push(error); | ||
} | ||
parseDirectives(this, directives, prevDoc); | ||
if (directivesEndMarker) this.directivesEndMarker = true; | ||
this.range = valueRange ? [valueRange.start, valueRange.end] : null; | ||
this.setSchema(); | ||
this.anchors._cstAliases = []; | ||
parseContents(this, contents); | ||
this.anchors.resolveNodes(); | ||
if (this.options.prettyErrors) { | ||
var _iterator = _createForOfIteratorHelper(this.errors), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var _error = _step.value; | ||
if (_error instanceof YAMLError) _error.makePretty(); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
var _iterator2 = _createForOfIteratorHelper(this.warnings), | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var warn = _step2.value; | ||
if (warn instanceof YAMLError) warn.makePretty(); | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
} | ||
return this; | ||
} | ||
}, { | ||
key: "listNonDefaultTags", | ||
value: function listNonDefaultTags() { | ||
return listTagNames(this.contents).filter(function (t) { | ||
return t.indexOf(Schema.defaultPrefix) !== 0; | ||
}); | ||
} | ||
}, { | ||
key: "setTagPrefix", | ||
value: function setTagPrefix(handle, prefix) { | ||
if (handle[0] !== '!' || handle[handle.length - 1] !== '!') throw new Error('Handle must start and end with !'); | ||
if (prefix) { | ||
var prev = this.tagPrefixes.find(function (p) { | ||
return p.handle === handle; | ||
}); | ||
if (prev) prev.prefix = prefix;else this.tagPrefixes.push({ | ||
handle: handle, | ||
prefix: prefix | ||
}); | ||
} else { | ||
this.tagPrefixes = this.tagPrefixes.filter(function (p) { | ||
return p.handle !== handle; | ||
}); | ||
} | ||
} | ||
}, { | ||
key: "toJSON", | ||
value: function toJSON$1(arg, onAnchor) { | ||
var _this = this; | ||
var _this$options = this.options, | ||
keepBlobsInJSON = _this$options.keepBlobsInJSON, | ||
mapAsMap = _this$options.mapAsMap, | ||
maxAliasCount = _this$options.maxAliasCount; | ||
var keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof Scalar)); | ||
var ctx = { | ||
doc: this, | ||
indentStep: ' ', | ||
keep: keep, | ||
mapAsMap: keep && !!mapAsMap, | ||
maxAliasCount: maxAliasCount, | ||
stringify: stringify$1 // Requiring directly in Pair would create circular dependencies | ||
}; | ||
var anchorNames = Object.keys(this.anchors.map); | ||
if (anchorNames.length > 0) ctx.anchors = new Map(anchorNames.map(function (name) { | ||
return [_this.anchors.map[name], { | ||
alias: [], | ||
aliasCount: 0, | ||
count: 1 | ||
}]; | ||
})); | ||
var res = toJSON(this.contents, arg, ctx); | ||
if (typeof onAnchor === 'function' && ctx.anchors) { | ||
var _iterator3 = _createForOfIteratorHelper(ctx.anchors.values()), | ||
_step3; | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var _step3$value = _step3.value, | ||
count = _step3$value.count, | ||
_res = _step3$value.res; | ||
onAnchor(_res, count); | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
} | ||
} | ||
return res; | ||
} | ||
}, { | ||
key: "toString", | ||
value: function toString() { | ||
if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified'); | ||
var indentSize = this.options.indent; | ||
if (!Number.isInteger(indentSize) || indentSize <= 0) { | ||
var s = JSON.stringify(indentSize); | ||
throw new Error("\"indent\" option must be a positive integer, not ".concat(s)); | ||
} | ||
this.setSchema(); | ||
var lines = []; | ||
var hasDirectives = false; | ||
if (this.version) { | ||
var vd = '%YAML 1.2'; | ||
if (this.schema.name === 'yaml-1.1') { | ||
if (this.version === '1.0') vd = '%YAML:1.0';else if (this.version === '1.1') vd = '%YAML 1.1'; | ||
} | ||
lines.push(vd); | ||
hasDirectives = true; | ||
} | ||
var tagNames = this.listNonDefaultTags(); | ||
this.tagPrefixes.forEach(function (_ref) { | ||
var handle = _ref.handle, | ||
prefix = _ref.prefix; | ||
if (tagNames.some(function (t) { | ||
return t.indexOf(prefix) === 0; | ||
})) { | ||
lines.push("%TAG ".concat(handle, " ").concat(prefix)); | ||
hasDirectives = true; | ||
} | ||
}); | ||
if (hasDirectives || this.directivesEndMarker) lines.push('---'); | ||
if (this.commentBefore) { | ||
if (hasDirectives || !this.directivesEndMarker) lines.unshift(''); | ||
lines.unshift(this.commentBefore.replace(/^/gm, '#')); | ||
} | ||
var ctx = { | ||
anchors: Object.create(null), | ||
doc: this, | ||
indent: '', | ||
indentStep: ' '.repeat(indentSize), | ||
stringify: stringify$1 // Requiring directly in nodes would create circular dependencies | ||
}; | ||
var chompKeep = false; | ||
var contentComment = null; | ||
if (this.contents) { | ||
if (this.contents instanceof Node) { | ||
if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push(''); | ||
if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment | ||
ctx.forceBlockIndent = !!this.comment; | ||
contentComment = this.contents.comment; | ||
} | ||
var onChompKeep = contentComment ? null : function () { | ||
return chompKeep = true; | ||
}; | ||
var body = stringify$1(this.contents, ctx, function () { | ||
return contentComment = null; | ||
}, onChompKeep); | ||
lines.push(addComment(body, '', contentComment)); | ||
} else if (this.contents !== undefined) { | ||
lines.push(stringify$1(this.contents, ctx)); | ||
} | ||
if (this.comment) { | ||
if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '') lines.push(''); | ||
lines.push(this.comment.replace(/^/gm, '#')); | ||
} | ||
return lines.join('\n') + '\n'; | ||
} | ||
}]); | ||
return Document; | ||
}(); | ||
_defineProperty(Document$1, "defaults", documentOptions); | ||
function createNode(value) { | ||
var wrapScalars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
var tag = arguments.length > 2 ? arguments[2] : undefined; | ||
if (tag === undefined && typeof wrapScalars === 'string') { | ||
tag = wrapScalars; | ||
wrapScalars = true; | ||
} | ||
var options = Object.assign({}, Document$1.defaults[defaultOptions.version], defaultOptions); | ||
var schema = new Schema(options); | ||
return schema.createNode(value, wrapScalars, tag); | ||
} | ||
var Document = /*#__PURE__*/function (_YAMLDocument) { | ||
_inherits(Document, _YAMLDocument); | ||
var _super = _createSuper(Document); | ||
function Document(options) { | ||
_classCallCheck(this, Document); | ||
return _super.call(this, Object.assign({}, defaultOptions, options)); | ||
} | ||
return Document; | ||
}(Document$1); | ||
function parseAllDocuments(src, options) { | ||
var stream = []; | ||
var prev; | ||
var _iterator = _createForOfIteratorHelper(parse$1(src)), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var cstDoc = _step.value; | ||
var doc = new Document(options); | ||
doc.parse(cstDoc, prev); | ||
stream.push(doc); | ||
prev = doc; | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
return stream; | ||
} | ||
function parseDocument(src, options) { | ||
var cst = parse$1(src); | ||
var doc = new Document(options).parse(cst[0]); | ||
if (cst.length > 1) { | ||
var errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()'; | ||
doc.errors.unshift(new YAMLSemanticError(cst[1], errMsg)); | ||
} | ||
return doc; | ||
} | ||
function parse(src, options) { | ||
var doc = parseDocument(src, options); | ||
doc.warnings.forEach(function (warning) { | ||
return warn(warning); | ||
}); | ||
if (doc.errors.length > 0) throw doc.errors[0]; | ||
return doc.toJSON(); | ||
} | ||
function stringify(value, options) { | ||
var doc = new Document(options); | ||
doc.contents = value; | ||
return String(doc); | ||
} | ||
var YAML = { | ||
createNode: createNode, | ||
defaultOptions: defaultOptions, | ||
Document: Document, | ||
parse: parse, | ||
parseAllDocuments: parseAllDocuments, | ||
parseCST: parse$1, | ||
parseDocument: parseDocument, | ||
scalarOptions: scalarOptions, | ||
stringify: stringify | ||
}; | ||
export { YAML }; | ||
export { Composer } from './compose/composer.js'; | ||
export { Document } from './doc/Document.js'; | ||
export { Schema } from './schema/Schema.js'; | ||
export { YAMLError, YAMLParseError, YAMLWarning } from './errors.js'; | ||
export { Alias } from './nodes/Alias.js'; | ||
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from './nodes/Node.js'; | ||
export { Pair } from './nodes/Pair.js'; | ||
export { Scalar } from './nodes/Scalar.js'; | ||
export { YAMLMap } from './nodes/YAMLMap.js'; | ||
export { YAMLSeq } from './nodes/YAMLSeq.js'; | ||
export { defaultOptions } from './options.js'; | ||
import * as cst from './parse/cst.js'; | ||
export { cst as CST }; | ||
export { Lexer } from './parse/lexer.js'; | ||
export { LineCounter } from './parse/line-counter.js'; | ||
export { Parser } from './parse/parser.js'; | ||
export { parse, parseAllDocuments, parseDocument, stringify } from './public-api.js'; | ||
export { visit } from './visit.js'; |
@@ -1,2 +0,9 @@ | ||
export { l as findPair, g as parseMap, h as parseSeq, k as stringifyNumber, c as stringifyString, t as toJSON } from './resolveSeq-492ab440.js'; | ||
export { T as Type, i as YAMLError, o as YAMLReferenceError, g as YAMLSemanticError, Y as YAMLSyntaxError, f as YAMLWarning } from './PlainValue-b8036b75.js'; | ||
export { debug, warn } from './log.js'; | ||
export { findPair } from './nodes/YAMLMap.js'; | ||
export { toJS } from './nodes/toJS.js'; | ||
export { map as mapTag } from './schema/common/map.js'; | ||
export { seq as seqTag } from './schema/common/seq.js'; | ||
export { string as stringTag } from './schema/common/string.js'; | ||
export { foldFlowLines } from './stringify/foldFlowLines.js'; | ||
export { stringifyNumber } from './stringify/stringifyNumber.js'; | ||
export { stringifyString } from './stringify/stringifyString.js'; |
@@ -1,1 +0,5 @@ | ||
module.exports = require('./dist').YAML | ||
// `export * as default from ...` fails on Webpack v4 | ||
// https://github.com/eemeli/yaml/issues/228 | ||
import * as YAML from './dist/index.js' | ||
export default YAML | ||
export * from './dist/index.js' |
'use strict'; | ||
var parseCst = require('./parse-cst.js'); | ||
var Document$1 = require('./Document-9b4560a1.js'); | ||
var Schema = require('./Schema-88e323a7.js'); | ||
var PlainValue = require('./PlainValue-ec8e588e.js'); | ||
var warnings = require('./warnings-1000a372.js'); | ||
require('./resolveSeq-d03cb037.js'); | ||
var composer = require('./compose/composer.js'); | ||
var Document = require('./doc/Document.js'); | ||
var Schema = require('./schema/Schema.js'); | ||
var errors = require('./errors.js'); | ||
var Alias = require('./nodes/Alias.js'); | ||
var Node = require('./nodes/Node.js'); | ||
var Pair = require('./nodes/Pair.js'); | ||
var Scalar = require('./nodes/Scalar.js'); | ||
var YAMLMap = require('./nodes/YAMLMap.js'); | ||
var YAMLSeq = require('./nodes/YAMLSeq.js'); | ||
var options = require('./options.js'); | ||
var cst = require('./parse/cst.js'); | ||
var lexer = require('./parse/lexer.js'); | ||
var lineCounter = require('./parse/line-counter.js'); | ||
var parser = require('./parse/parser.js'); | ||
var publicApi = require('./public-api.js'); | ||
var visit = require('./visit.js'); | ||
function createNode(value, wrapScalars = true, tag) { | ||
if (tag === undefined && typeof wrapScalars === 'string') { | ||
tag = wrapScalars; | ||
wrapScalars = true; | ||
} | ||
const options = Object.assign({}, Document$1.Document.defaults[Document$1.defaultOptions.version], Document$1.defaultOptions); | ||
const schema = new Schema.Schema(options); | ||
return schema.createNode(value, wrapScalars, tag); | ||
} | ||
class Document extends Document$1.Document { | ||
constructor(options) { | ||
super(Object.assign({}, Document$1.defaultOptions, options)); | ||
} | ||
} | ||
function parseAllDocuments(src, options) { | ||
const stream = []; | ||
let prev; | ||
for (const cstDoc of parseCst.parse(src)) { | ||
const doc = new Document(options); | ||
doc.parse(cstDoc, prev); | ||
stream.push(doc); | ||
prev = doc; | ||
} | ||
return stream; | ||
} | ||
function parseDocument(src, options) { | ||
const cst = parseCst.parse(src); | ||
const doc = new Document(options).parse(cst[0]); | ||
if (cst.length > 1) { | ||
const errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()'; | ||
doc.errors.unshift(new PlainValue.YAMLSemanticError(cst[1], errMsg)); | ||
} | ||
return doc; | ||
} | ||
function parse(src, options) { | ||
const doc = parseDocument(src, options); | ||
doc.warnings.forEach(warning => warnings.warn(warning)); | ||
if (doc.errors.length > 0) throw doc.errors[0]; | ||
return doc.toJSON(); | ||
} | ||
function stringify(value, options) { | ||
const doc = new Document(options); | ||
doc.contents = value; | ||
return String(doc); | ||
} | ||
const YAML = { | ||
createNode, | ||
defaultOptions: Document$1.defaultOptions, | ||
Document, | ||
parse, | ||
parseAllDocuments, | ||
parseCST: parseCst.parse, | ||
parseDocument, | ||
scalarOptions: Document$1.scalarOptions, | ||
stringify | ||
}; | ||
exports.YAML = YAML; | ||
exports.Composer = composer.Composer; | ||
exports.Document = Document.Document; | ||
exports.Schema = Schema.Schema; | ||
exports.YAMLError = errors.YAMLError; | ||
exports.YAMLParseError = errors.YAMLParseError; | ||
exports.YAMLWarning = errors.YAMLWarning; | ||
exports.Alias = Alias.Alias; | ||
exports.isAlias = Node.isAlias; | ||
exports.isCollection = Node.isCollection; | ||
exports.isDocument = Node.isDocument; | ||
exports.isMap = Node.isMap; | ||
exports.isNode = Node.isNode; | ||
exports.isPair = Node.isPair; | ||
exports.isScalar = Node.isScalar; | ||
exports.isSeq = Node.isSeq; | ||
exports.Pair = Pair.Pair; | ||
exports.Scalar = Scalar.Scalar; | ||
exports.YAMLMap = YAMLMap.YAMLMap; | ||
exports.YAMLSeq = YAMLSeq.YAMLSeq; | ||
exports.defaultOptions = options.defaultOptions; | ||
exports.CST = cst; | ||
exports.Lexer = lexer.Lexer; | ||
exports.LineCounter = lineCounter.LineCounter; | ||
exports.Parser = parser.Parser; | ||
exports.parse = publicApi.parse; | ||
exports.parseAllDocuments = publicApi.parseAllDocuments; | ||
exports.parseDocument = publicApi.parseDocument; | ||
exports.stringify = publicApi.stringify; | ||
exports.visit = visit.visit; |
'use strict'; | ||
var parseCst = require('./parse-cst.js'); | ||
var Document = require('./Document-9b4560a1.js'); | ||
require('./PlainValue-ec8e588e.js'); | ||
require('./resolveSeq-d03cb037.js'); | ||
require('./Schema-88e323a7.js'); | ||
require('./warnings-1000a372.js'); | ||
var Node = require('./nodes/Node.js'); | ||
var publicApi = require('./public-api.js'); | ||
var visit = require('./visit.js'); | ||
function testEvents(src, options) { | ||
const opt = Object.assign({ | ||
keepCstNodes: true, | ||
keepNodeTypes: true, | ||
version: '1.2' | ||
}, options); | ||
const docs = parseCst.parse(src).map(cstDoc => new Document.Document(opt).parse(cstDoc)); | ||
const errDoc = docs.find(doc => doc.errors.length > 0); | ||
const error = errDoc ? errDoc.errors[0].message : null; | ||
const events = ['+STR']; | ||
try { | ||
for (let i = 0; i < docs.length; ++i) { | ||
const doc = docs[i]; | ||
let root = doc.contents; | ||
if (Array.isArray(root)) root = root[0]; | ||
const [rootStart, rootEnd] = doc.range || [0, 0]; | ||
let e = doc.errors[0] && doc.errors[0].source; | ||
if (e && e.type === 'SEQ_ITEM') e = e.node; | ||
if (e && (e.type === 'DOCUMENT' || e.range.start < rootStart)) throw new Error(); | ||
let docStart = '+DOC'; | ||
const pre = src.slice(0, rootStart); | ||
const explicitDoc = /---\s*$/.test(pre); | ||
if (explicitDoc) docStart += ' ---';else if (!doc.contents) continue; | ||
events.push(docStart); | ||
addEvents(events, doc, e, root); | ||
if (doc.contents && doc.contents.length > 1) throw new Error(); | ||
let docEnd = '-DOC'; | ||
if (rootEnd) { | ||
const post = src.slice(rootEnd); | ||
if (/^\.\.\./.test(post)) docEnd += ' ...'; | ||
} | ||
events.push(docEnd); | ||
const scalarChar = { | ||
BLOCK_FOLDED: '>', | ||
BLOCK_LITERAL: '|', | ||
PLAIN: ':', | ||
QUOTE_DOUBLE: '"', | ||
QUOTE_SINGLE: "'" | ||
}; | ||
function anchorExists(doc, anchor) { | ||
let found = false; | ||
visit.visit(doc, { | ||
Value(_key, node) { | ||
if (node.anchor === anchor) { | ||
found = true; | ||
return visit.visit.BREAK; | ||
} | ||
} | ||
}); | ||
return found; | ||
} | ||
// test harness for yaml-test-suite event tests | ||
function testEvents(src) { | ||
var _a; | ||
const docs = publicApi.parseAllDocuments(src); | ||
const errDoc = docs.find(doc => doc.errors.length > 0); | ||
const error = errDoc ? errDoc.errors[0].message : null; | ||
const events = ['+STR']; | ||
try { | ||
for (let i = 0; i < docs.length; ++i) { | ||
const doc = docs[i]; | ||
let root = doc.contents; | ||
if (Array.isArray(root)) | ||
root = root[0]; | ||
// eslint-disable-next-line no-sparse-arrays | ||
const [rootStart, , rootEnd] = doc.range || [0, , 0]; | ||
const error = doc.errors[0]; | ||
if (error && (!error.pos || error.pos[0] < rootStart)) | ||
throw new Error(); | ||
let docStart = '+DOC'; | ||
if (doc.directives.marker) | ||
docStart += ' ---'; | ||
else if (doc.contents && doc.contents.range[2] === doc.contents.range[0]) | ||
continue; | ||
events.push(docStart); | ||
addEvents(events, doc, (_a = error === null || error === void 0 ? void 0 : error.pos[0]) !== null && _a !== void 0 ? _a : -1, root); | ||
let docEnd = '-DOC'; | ||
if (rootEnd) { | ||
const post = src.slice(rootStart, rootEnd); | ||
if (/^\.\.\.($|\s)/m.test(post)) | ||
docEnd += ' ...'; | ||
} | ||
events.push(docEnd); | ||
} | ||
} | ||
} catch (e) { | ||
return { | ||
events, | ||
error: error || e | ||
}; | ||
} | ||
events.push('-STR'); | ||
return { | ||
events, | ||
error | ||
}; | ||
catch (e) { | ||
return { events, error: error || e }; | ||
} | ||
events.push('-STR'); | ||
return { events, error }; | ||
} | ||
function addEvents(events, doc, e, node) { | ||
if (!node) { | ||
events.push('=VAL :'); | ||
return; | ||
} | ||
if (e && node.cstNode === e) throw new Error(); | ||
let props = ''; | ||
let anchor = doc.anchors.getName(node); | ||
if (anchor) { | ||
if (/\d$/.test(anchor)) { | ||
const alt = anchor.replace(/\d$/, ''); | ||
if (doc.anchors.getNode(alt)) anchor = alt; | ||
function addEvents(events, doc, errPos, node) { | ||
if (!node) { | ||
events.push('=VAL :'); | ||
return; | ||
} | ||
props = ` &${anchor}`; | ||
} | ||
if (node.cstNode && node.cstNode.tag) { | ||
const { | ||
handle, | ||
suffix | ||
} = node.cstNode.tag; | ||
props += handle === '!' && !suffix ? ' <!>' : ` <${node.tag}>`; | ||
} | ||
let scalar = null; | ||
switch (node.type) { | ||
case 'ALIAS': | ||
{ | ||
let alias = doc.anchors.getName(node.source); | ||
if (/\d$/.test(alias)) { | ||
const alt = alias.replace(/\d$/, ''); | ||
if (doc.anchors.getNode(alt)) alias = alt; | ||
if (errPos !== -1 && Node.isNode(node) && node.range[0] >= errPos) | ||
throw new Error(); | ||
let props = ''; | ||
let anchor = Node.isScalar(node) || Node.isCollection(node) ? node.anchor : undefined; | ||
if (anchor) { | ||
if (/\d$/.test(anchor)) { | ||
const alt = anchor.replace(/\d$/, ''); | ||
if (anchorExists(doc, alt)) | ||
anchor = alt; | ||
} | ||
props = ` &${anchor}`; | ||
} | ||
if (Node.isNode(node) && node.tag) | ||
props += ` <${node.tag}>`; | ||
if (Node.isMap(node)) { | ||
events.push(`+MAP${props}`); | ||
node.items.forEach(({ key, value }) => { | ||
addEvents(events, doc, errPos, key); | ||
addEvents(events, doc, errPos, value); | ||
}); | ||
events.push('-MAP'); | ||
} | ||
else if (Node.isSeq(node)) { | ||
events.push(`+SEQ${props}`); | ||
node.items.forEach(item => { | ||
addEvents(events, doc, errPos, item); | ||
}); | ||
events.push('-SEQ'); | ||
} | ||
else if (Node.isPair(node)) { | ||
events.push(`+MAP${props}`); | ||
addEvents(events, doc, errPos, node.key); | ||
addEvents(events, doc, errPos, node.value); | ||
events.push('-MAP'); | ||
} | ||
else if (Node.isAlias(node)) { | ||
let alias = node.source; | ||
if (alias && /\d$/.test(alias)) { | ||
const alt = alias.replace(/\d$/, ''); | ||
if (anchorExists(doc, alt)) | ||
alias = alt; | ||
} | ||
events.push(`=ALI${props} *${alias}`); | ||
} | ||
break; | ||
case 'BLOCK_FOLDED': | ||
scalar = '>'; | ||
break; | ||
case 'BLOCK_LITERAL': | ||
scalar = '|'; | ||
break; | ||
case 'PLAIN': | ||
scalar = ':'; | ||
break; | ||
case 'QUOTE_DOUBLE': | ||
scalar = '"'; | ||
break; | ||
case 'QUOTE_SINGLE': | ||
scalar = "'"; | ||
break; | ||
case 'PAIR': | ||
events.push(`+MAP${props}`); | ||
addEvents(events, doc, e, node.key); | ||
addEvents(events, doc, e, node.value); | ||
events.push('-MAP'); | ||
break; | ||
case 'FLOW_SEQ': | ||
case 'SEQ': | ||
events.push(`+SEQ${props}`); | ||
node.items.forEach(item => { | ||
addEvents(events, doc, e, item); | ||
}); | ||
events.push('-SEQ'); | ||
break; | ||
case 'FLOW_MAP': | ||
case 'MAP': | ||
events.push(`+MAP${props}`); | ||
node.items.forEach(({ | ||
key, | ||
value | ||
}) => { | ||
addEvents(events, doc, e, key); | ||
addEvents(events, doc, e, value); | ||
}); | ||
events.push('-MAP'); | ||
break; | ||
default: | ||
throw new Error(`Unexpected node type ${node.type}`); | ||
} | ||
if (scalar) { | ||
const value = node.cstNode.strValue.replace(/\\/g, '\\\\').replace(/\0/g, '\\0').replace(/\x07/g, '\\a').replace(/\x08/g, '\\b').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\v/g, '\\v').replace(/\f/g, '\\f').replace(/\r/g, '\\r').replace(/\x1b/g, '\\e'); | ||
events.push(`=VAL${props} ${scalar}${value}`); | ||
} | ||
} | ||
else { | ||
const scalar = scalarChar[String(node.type)]; | ||
if (!scalar) | ||
throw new Error(`Unexpected node type ${node.type}`); | ||
const value = node.source | ||
.replace(/\\/g, '\\\\') | ||
.replace(/\0/g, '\\0') | ||
.replace(/\x07/g, '\\a') | ||
.replace(/\x08/g, '\\b') | ||
.replace(/\t/g, '\\t') | ||
.replace(/\n/g, '\\n') | ||
.replace(/\v/g, '\\v') | ||
.replace(/\f/g, '\\f') | ||
.replace(/\r/g, '\\r') | ||
.replace(/\x1b/g, '\\e'); | ||
events.push(`=VAL${props} ${scalar}${value}`); | ||
} | ||
} | ||
exports.testEvents = testEvents; |
'use strict'; | ||
var resolveSeq = require('./resolveSeq-d03cb037.js'); | ||
var PlainValue = require('./PlainValue-ec8e588e.js'); | ||
var log = require('./log.js'); | ||
var YAMLMap = require('./nodes/YAMLMap.js'); | ||
var toJS = require('./nodes/toJS.js'); | ||
var map = require('./schema/common/map.js'); | ||
var seq = require('./schema/common/seq.js'); | ||
var string = require('./schema/common/string.js'); | ||
var foldFlowLines = require('./stringify/foldFlowLines.js'); | ||
var stringifyNumber = require('./stringify/stringifyNumber.js'); | ||
var stringifyString = require('./stringify/stringifyString.js'); | ||
exports.findPair = resolveSeq.findPair; | ||
exports.parseMap = resolveSeq.resolveMap; | ||
exports.parseSeq = resolveSeq.resolveSeq; | ||
exports.stringifyNumber = resolveSeq.stringifyNumber; | ||
exports.stringifyString = resolveSeq.stringifyString; | ||
exports.toJSON = resolveSeq.toJSON; | ||
exports.Type = PlainValue.Type; | ||
exports.YAMLError = PlainValue.YAMLError; | ||
exports.YAMLReferenceError = PlainValue.YAMLReferenceError; | ||
exports.YAMLSemanticError = PlainValue.YAMLSemanticError; | ||
exports.YAMLSyntaxError = PlainValue.YAMLSyntaxError; | ||
exports.YAMLWarning = PlainValue.YAMLWarning; | ||
exports.debug = log.debug; | ||
exports.warn = log.warn; | ||
exports.findPair = YAMLMap.findPair; | ||
exports.toJS = toJS.toJS; | ||
exports.mapTag = map.map; | ||
exports.seqTag = seq.seq; | ||
exports.stringTag = string.string; | ||
exports.foldFlowLines = foldFlowLines.foldFlowLines; | ||
exports.stringifyNumber = stringifyNumber.stringifyNumber; | ||
exports.stringifyString = stringifyString.stringifyString; |
{ | ||
"name": "yaml", | ||
"version": "1.10.2", | ||
"version": "2.0.0-9", | ||
"license": "ISC", | ||
@@ -13,61 +13,41 @@ "author": "Eemeli Aro <eemeli@gmail.com>", | ||
], | ||
"homepage": "https://eemeli.org/yaml/v1/", | ||
"homepage": "https://eemeli.org/yaml/", | ||
"files": [ | ||
"browser/", | ||
"dist/", | ||
"types/", | ||
"*.d.ts", | ||
"*.js", | ||
"*.mjs", | ||
"!*config.js" | ||
"util.d.ts", | ||
"util.js" | ||
], | ||
"type": "commonjs", | ||
"main": "./index.js", | ||
"main": "./dist/index.js", | ||
"browser": { | ||
"./index.js": "./browser/index.js", | ||
"./map.js": "./browser/map.js", | ||
"./pair.js": "./browser/pair.js", | ||
"./parse-cst.js": "./browser/parse-cst.js", | ||
"./scalar.js": "./browser/scalar.js", | ||
"./schema.js": "./browser/schema.js", | ||
"./seq.js": "./browser/seq.js", | ||
"./types.js": "./browser/types.js", | ||
"./types.mjs": "./browser/types.js", | ||
"./types/binary.js": "./browser/types/binary.js", | ||
"./types/omap.js": "./browser/types/omap.js", | ||
"./types/pairs.js": "./browser/types/pairs.js", | ||
"./types/set.js": "./browser/types/set.js", | ||
"./types/timestamp.js": "./browser/types/timestamp.js", | ||
"./util.js": "./browser/util.js", | ||
"./util.mjs": "./browser/util.js" | ||
"./dist/index.js": "./browser/index.js", | ||
"./dist/util.js": "./browser/dist/util.js", | ||
"./util.js": "./browser/dist/util.js" | ||
}, | ||
"exports": { | ||
".": "./index.js", | ||
"./parse-cst": "./parse-cst.js", | ||
"./types": [ | ||
{ | ||
"import": "./types.mjs" | ||
}, | ||
"./types.js" | ||
], | ||
"./util": [ | ||
{ | ||
"import": "./util.mjs" | ||
}, | ||
"./util.js" | ||
], | ||
"./": "./" | ||
".": { | ||
"node": "./dist/index.js", | ||
"default": "./browser/index.js" | ||
}, | ||
"./package.json": "./package.json", | ||
"./util": { | ||
"node": "./dist/util.js", | ||
"default": "./browser/dist/util.js" | ||
} | ||
}, | ||
"scripts": { | ||
"build": "npm run build:node && npm run build:browser", | ||
"build:browser": "rollup -c rollup.browser-config.js", | ||
"build:node": "rollup -c rollup.node-config.js", | ||
"build:browser": "rollup -c config/rollup.browser-config.js", | ||
"build:node": "rollup -c config/rollup.node-config.js", | ||
"clean": "git clean -fdxe node_modules", | ||
"lint": "eslint src/", | ||
"prettier": "prettier --write .", | ||
"start": "cross-env TRACE_LEVEL=log npm run build:node && node -i -e 'YAML=require(\".\")'", | ||
"test": "jest", | ||
"prestart": "npm run build:node", | ||
"start": "node -i -e 'YAML=require(\"./dist/index.js\")'", | ||
"test": "jest --config config/jest.config.js", | ||
"test:browsers": "cd playground && npm test", | ||
"test:dist": "npm run build:node && jest", | ||
"test:types": "tsc --lib ES2017 --noEmit tests/typings.ts", | ||
"test:dist": "npm run build:node && jest --config config/jest.config.js", | ||
"test:dist:types": "tsc --allowJs --moduleResolution node --noEmit --target es2017 dist/index.js", | ||
"test:types": "tsc --noEmit", | ||
"docs:install": "cd docs-slate && bundle install", | ||
@@ -79,3 +59,3 @@ "docs:deploy": "cd docs-slate && ./deploy.sh", | ||
}, | ||
"browserslist": "> 0.5%, not dead", | ||
"browserslist": "defaults, not ie 11", | ||
"prettier": { | ||
@@ -90,20 +70,27 @@ "arrowParens": "avoid", | ||
"@babel/plugin-proposal-class-properties": "^7.12.1", | ||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.1", | ||
"@babel/plugin-transform-typescript": "^7.12.17", | ||
"@babel/preset-env": "^7.12.11", | ||
"@rollup/plugin-babel": "^5.2.3", | ||
"babel-eslint": "^10.1.0", | ||
"babel-jest": "^26.6.3", | ||
"babel-plugin-trace": "^1.1.0", | ||
"common-tags": "^1.8.0", | ||
"@rollup/plugin-replace": "^3.0.0", | ||
"@rollup/plugin-typescript": "^8.1.1", | ||
"@types/jest": "^27.0.1", | ||
"@types/node": "^16.9.1", | ||
"@typescript-eslint/eslint-plugin": "^4.15.2", | ||
"@typescript-eslint/parser": "^4.15.2", | ||
"babel-jest": "^27.0.1", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^7.19.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint": "^7.20.0", | ||
"eslint-config-prettier": "^8.1.0", | ||
"fast-check": "^2.12.0", | ||
"jest": "^26.6.3", | ||
"jest": "^27.0.1", | ||
"jest-ts-webcompat-resolver": "^1.0.0", | ||
"prettier": "^2.2.1", | ||
"rollup": "^2.38.2", | ||
"typescript": "^4.1.3" | ||
"tslib": "^2.1.0", | ||
"typescript": "^4.3.5" | ||
}, | ||
"engines": { | ||
"node": ">= 6" | ||
"node": ">= 12" | ||
} | ||
} |
# YAML <a href="https://www.npmjs.com/package/yaml"><img align="right" src="https://badge.fury.io/js/yaml.svg" title="npm package" /></a> | ||
`yaml` is a JavaScript parser and stringifier for [YAML](http://yaml.org/), a human friendly data serialization standard. It supports both parsing and stringifying data using all versions of YAML, along with all common data schemas. As a particularly distinguishing feature, `yaml` fully supports reading and writing comments and blank lines in YAML documents. | ||
`yaml` is a definitive library for [YAML](http://yaml.org/), the human friendly data serialization standard. | ||
This library: | ||
The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). It has no external dependencies and runs on Node.js 6 and later, and in browsers from IE 11 upwards. | ||
- Supports both YAML 1.1 and YAML 1.2 and all common data schemas, | ||
- Passes all of the [yaml-test-suite](https://github.com/yaml/yaml-test-suite) tests, | ||
- Can accept any string as input without throwing, parsing as much YAML out of it as it can, and | ||
- Supports parsing, modifying, and writing YAML comments and blank lines. | ||
For the purposes of versioning, any changes that break any of the endpoints or APIs documented here will be considered semver-major breaking changes. Undocumented library internals may change between minor versions, and previous APIs may be deprecated (but not removed). | ||
The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). | ||
It has no external dependencies and runs on Node.js as well as modern browsers. | ||
For more information, see the project's documentation site: [**eemeli.org/yaml/v1**](https://eemeli.org/yaml/v1/) | ||
For the purposes of versioning, any changes that break any of the documented endpoints or APIs will be considered semver-major breaking changes. | ||
Undocumented library internals may change between minor versions, and previous APIs may be deprecated (but not removed). | ||
For more information, see the project's documentation site: [**eemeli.org/yaml**](https://eemeli.org/yaml/) | ||
To install: | ||
```sh | ||
npm install yaml | ||
npm install --save-exact yaml@next | ||
``` | ||
**Note:** This is `yaml@1`. You may also be interested in the next version, currently available as [`yaml@next`](https://www.npmjs.com/package/yaml/v/next). | ||
**Note:** These docs are for `yaml@2`. For v1, see the [v1.10.0 tag](https://github.com/eemeli/yaml/tree/v1.10.0) for the source and [eemeli.org/yaml/v1](https://eemeli.org/yaml/v1/) for the documentation. | ||
## API Overview | ||
The API provided by `yaml` has three layers, depending on how deep you need to go: [Parse & Stringify](https://eemeli.org/yaml/v1/#parse-amp-stringify), [Documents](https://eemeli.org/yaml/#documents), and the [CST Parser](https://eemeli.org/yaml/#cst-parser). The first has the simplest API and "just works", the second gets you all the bells and whistles supported by the library along with a decent [AST](https://eemeli.org/yaml/#content-nodes), and the third is the closest to YAML source, making it fast, raw, and crude. | ||
The API provided by `yaml` has three layers, depending on how deep you need to go: [Parse & Stringify](https://eemeli.org/yaml/#parse-amp-stringify), [Documents](https://eemeli.org/yaml/#documents), and the underlying [Lexer/Parser/Composer](https://eemeli.org/yaml/#parsing-yaml). | ||
The first has the simplest API and "just works", the second gets you all the bells and whistles supported by the library along with a decent [AST](https://eemeli.org/yaml/#content-nodes), and the third lets you get progressively closer to YAML source, if that's your thing. | ||
```js | ||
import { parse, stringify } from 'yaml' | ||
// or | ||
import YAML from 'yaml' | ||
@@ -31,35 +42,41 @@ // or | ||
- [`YAML.parse(str, options): value`](https://eemeli.org/yaml/v1/#yaml-parse) | ||
- [`YAML.stringify(value, options): string`](https://eemeli.org/yaml/v1/#yaml-stringify) | ||
- [`parse(str, reviver?, options?): value`](https://eemeli.org/yaml/#yaml-parse) | ||
- [`stringify(value, replacer?, options?): string`](https://eemeli.org/yaml/#yaml-stringify) | ||
### YAML Documents | ||
### Documents | ||
- [`YAML.createNode(value, wrapScalars, tag): Node`](https://eemeli.org/yaml/v1/#creating-nodes) | ||
- [`YAML.defaultOptions`](https://eemeli.org/yaml/v1/#options) | ||
- [`YAML.Document`](https://eemeli.org/yaml/v1/#yaml-documents) | ||
- [`constructor(options)`](https://eemeli.org/yaml/v1/#creating-documents) | ||
- [`defaults`](https://eemeli.org/yaml/v1/#options) | ||
- [`#anchors`](https://eemeli.org/yaml/v1/#working-with-anchors) | ||
- [`#contents`](https://eemeli.org/yaml/v1/#content-nodes) | ||
- [`#errors`](https://eemeli.org/yaml/v1/#errors) | ||
- [`YAML.parseAllDocuments(str, options): YAML.Document[]`](https://eemeli.org/yaml/v1/#parsing-documents) | ||
- [`YAML.parseDocument(str, options): YAML.Document`](https://eemeli.org/yaml/v1/#parsing-documents) | ||
- [`Document`](https://eemeli.org/yaml/#documents) | ||
- [`constructor(value, replacer?, options?)`](https://eemeli.org/yaml/#creating-documents) | ||
- [`#anchors`](https://eemeli.org/yaml/#working-with-anchors) | ||
- [`#contents`](https://eemeli.org/yaml/#content-nodes) | ||
- [`#directives`](https://eemeli.org/yaml/#stream-directives) | ||
- [`#errors`](https://eemeli.org/yaml/#errors) | ||
- [`#warnings`](https://eemeli.org/yaml/#errors) | ||
- [`isDocument(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes) | ||
- [`parseAllDocuments(str, options?): Document[]`](https://eemeli.org/yaml/#parsing-documents) | ||
- [`parseDocument(str, options?): Document`](https://eemeli.org/yaml/#parsing-documents) | ||
```js | ||
import { Pair, YAMLMap, YAMLSeq } from 'yaml/types' | ||
``` | ||
### Content Nodes | ||
- [`new Pair(key, value)`](https://eemeli.org/yaml/v1/#creating-nodes) | ||
- [`new YAMLMap()`](https://eemeli.org/yaml/v1/#creating-nodes) | ||
- [`new YAMLSeq()`](https://eemeli.org/yaml/v1/#creating-nodes) | ||
- [`isAlias(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes) | ||
- [`isCollection(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes) | ||
- [`isMap(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes) | ||
- [`isNode(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes) | ||
- [`isPair(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes) | ||
- [`isScalar(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes) | ||
- [`isSeq(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes) | ||
- [`new Scalar(value)`](https://eemeli.org/yaml/#scalar-values) | ||
- [`new YAMLMap()`](https://eemeli.org/yaml/#collections) | ||
- [`new YAMLSeq()`](https://eemeli.org/yaml/#collections) | ||
- [`doc.createAlias(node, name?): Alias`](https://eemeli.org/yaml/#working-with-anchors) | ||
- [`doc.createNode(value, options?): Node`](https://eemeli.org/yaml/#creating-nodes) | ||
- [`doc.createPair(key, value): Pair`](https://eemeli.org/yaml/#creating-nodes) | ||
- [`visit(node, visitor)`](https://eemeli.org/yaml/#modifying-nodes) | ||
### CST Parser | ||
### Parsing YAML | ||
```js | ||
import parseCST from 'yaml/parse-cst' | ||
``` | ||
- [`new Lexer().lex(src)`](https://eemeli.org/yaml/#lexer) | ||
- [`new Parser(onNewLine?).parse(src)`](https://eemeli.org/yaml/#parser) | ||
- [`new Composer(options?).compose(tokens)`](https://eemeli.org/yaml/#composer) | ||
- [`parseCST(str): CSTDocument[]`](https://eemeli.org/yaml/v1/#parsecst) | ||
- [`YAML.parseCST(str): CSTDocument[]`](https://eemeli.org/yaml/v1/#parsecst) | ||
## YAML.parse | ||
@@ -115,5 +132,4 @@ | ||
// plain: string | ||
// block: > | ||
// block: | | ||
// two | ||
// | ||
// lines | ||
@@ -120,0 +136,0 @@ // ` |
@@ -1,86 +0,3 @@ | ||
import { Document } from './index' | ||
import { CST } from './parse-cst' | ||
import { AST, Pair, Scalar, Schema } from './types' | ||
export function findPair(items: any[], key: Scalar | any): Pair | undefined | ||
export function parseMap(doc: Document, cst: CST.Map): AST.BlockMap | ||
export function parseMap(doc: Document, cst: CST.FlowMap): AST.FlowMap | ||
export function parseSeq(doc: Document, cst: CST.Seq): AST.BlockSeq | ||
export function parseSeq(doc: Document, cst: CST.FlowSeq): AST.FlowSeq | ||
export function stringifyNumber(item: Scalar): string | ||
export function stringifyString( | ||
item: Scalar, | ||
ctx: Schema.StringifyContext, | ||
onComment?: () => void, | ||
onChompKeep?: () => void | ||
): string | ||
export function toJSON( | ||
value: any, | ||
arg?: any, | ||
ctx?: Schema.CreateNodeContext | ||
): any | ||
export enum Type { | ||
ALIAS = 'ALIAS', | ||
BLANK_LINE = 'BLANK_LINE', | ||
BLOCK_FOLDED = 'BLOCK_FOLDED', | ||
BLOCK_LITERAL = 'BLOCK_LITERAL', | ||
COMMENT = 'COMMENT', | ||
DIRECTIVE = 'DIRECTIVE', | ||
DOCUMENT = 'DOCUMENT', | ||
FLOW_MAP = 'FLOW_MAP', | ||
FLOW_SEQ = 'FLOW_SEQ', | ||
MAP = 'MAP', | ||
MAP_KEY = 'MAP_KEY', | ||
MAP_VALUE = 'MAP_VALUE', | ||
PLAIN = 'PLAIN', | ||
QUOTE_DOUBLE = 'QUOTE_DOUBLE', | ||
QUOTE_SINGLE = 'QUOTE_SINGLE', | ||
SEQ = 'SEQ', | ||
SEQ_ITEM = 'SEQ_ITEM' | ||
} | ||
interface LinePos { | ||
line: number | ||
col: number | ||
} | ||
export class YAMLError extends Error { | ||
name: | ||
| 'YAMLReferenceError' | ||
| 'YAMLSemanticError' | ||
| 'YAMLSyntaxError' | ||
| 'YAMLWarning' | ||
message: string | ||
source?: CST.Node | ||
nodeType?: Type | ||
range?: CST.Range | ||
linePos?: { start: LinePos; end: LinePos } | ||
/** | ||
* Drops `source` and adds `nodeType`, `range` and `linePos`, as well as | ||
* adding details to `message`. Run automatically for document errors if | ||
* the `prettyErrors` option is set. | ||
*/ | ||
makePretty(): void | ||
} | ||
export class YAMLReferenceError extends YAMLError { | ||
name: 'YAMLReferenceError' | ||
} | ||
export class YAMLSemanticError extends YAMLError { | ||
name: 'YAMLSemanticError' | ||
} | ||
export class YAMLSyntaxError extends YAMLError { | ||
name: 'YAMLSyntaxError' | ||
} | ||
export class YAMLWarning extends YAMLError { | ||
name: 'YAMLWarning' | ||
} | ||
// Workaround for incomplete exports support in TypeScript | ||
// https://github.com/microsoft/TypeScript/issues/33079 | ||
export * from './dist/util.js' |
@@ -1,16 +0,2 @@ | ||
const util = require('./dist/util') | ||
exports.findPair = util.findPair | ||
exports.toJSON = util.toJSON | ||
exports.parseMap = util.parseMap | ||
exports.parseSeq = util.parseSeq | ||
exports.stringifyNumber = util.stringifyNumber | ||
exports.stringifyString = util.stringifyString | ||
exports.Type = util.Type | ||
exports.YAMLError = util.YAMLError | ||
exports.YAMLReferenceError = util.YAMLReferenceError | ||
exports.YAMLSemanticError = util.YAMLSemanticError | ||
exports.YAMLSyntaxError = util.YAMLSyntaxError | ||
exports.YAMLWarning = util.YAMLWarning | ||
// Re-exporter for Node.js < 12.16.0 | ||
module.exports = require('./dist/util.js') |
{ | ||
"name": "@circleci/circleci-config-sdk", | ||
"version": "0.5.0-alpha.5", | ||
"version": "0.5.0-alpha.6", | ||
"description": "An SDK for building CircleCI Configuration files with JavaScript.", | ||
@@ -57,3 +57,4 @@ "main": "dist/circleci-config-sdk.js", | ||
"dependencies": { | ||
"yaml": "^1.10.2" | ||
"ajv": "^8.8.2", | ||
"yaml": "2.0.0-9" | ||
}, | ||
@@ -60,0 +61,0 @@ "directories": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
1944491
381
18848
2
2
80
2
+ Addedajv@^8.8.2
+ Addedajv@8.17.1(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-uri@3.0.3(transitive)
+ Addedjson-schema-traverse@1.0.0(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
Updatedyaml@2.0.0-9