shelfware 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.output/nitro.json +15 -0
- package/.output/public/_nuxt/6IstVYrV.js +1 -0
- package/.output/public/_nuxt/9C5WUlLE.js +36 -0
- package/.output/public/_nuxt/BDNMzG2s.js +1 -0
- package/.output/public/_nuxt/BW3xJdEx.js +1 -0
- package/.output/public/_nuxt/BXXtFil5.js +1 -0
- package/.output/public/_nuxt/BZuUK3cr.js +1 -0
- package/.output/public/_nuxt/BeLyMmd4.js +1 -0
- package/.output/public/_nuxt/C_VgD9ZI.js +3 -0
- package/.output/public/_nuxt/DB5Vxbte.js +2 -0
- package/.output/public/_nuxt/DMg0j7gv.js +14 -0
- package/.output/public/_nuxt/builds/latest.json +1 -0
- package/.output/public/_nuxt/builds/meta/4c307968-4837-497b-a570-d6ee336accc4.json +1 -0
- package/.output/public/_nuxt/entry.b3_DJTEt.css +2 -0
- package/.output/public/_nuxt/error-404.CHsn7XF-.css +1 -0
- package/.output/public/_nuxt/error-500.Bawx2bLr.css +1 -0
- package/.output/server/chunks/_/api-handler.mjs +44 -0
- package/.output/server/chunks/_/batch.mjs +27 -0
- package/.output/server/chunks/_/catalog.mjs +1115 -0
- package/.output/server/chunks/_/detail.mjs +16 -0
- package/.output/server/chunks/_/error-500.mjs +19 -0
- package/.output/server/chunks/_/quarantine.mjs +159 -0
- package/.output/server/chunks/nitro/nitro.mjs +5399 -0
- package/.output/server/chunks/routes/api/_..._.mjs +16 -0
- package/.output/server/chunks/routes/api/health.get.mjs +13 -0
- package/.output/server/chunks/routes/api/skills/_id/file.get.mjs +25 -0
- package/.output/server/chunks/routes/api/skills/_id_.get.mjs +25 -0
- package/.output/server/chunks/routes/api/skills/_id_.put.mjs +74 -0
- package/.output/server/chunks/routes/api/skills/delete.post.mjs +48 -0
- package/.output/server/chunks/routes/api/skills/quarantine.post.mjs +26 -0
- package/.output/server/chunks/routes/api/skills/restore.post.mjs +26 -0
- package/.output/server/chunks/routes/api/skills.get.mjs +41 -0
- package/.output/server/chunks/routes/renderer.mjs +341 -0
- package/.output/server/chunks/virtual/_virtual_spa-template.mjs +3 -0
- package/.output/server/chunks/virtual/precomputed.mjs +3 -0
- package/.output/server/index.mjs +9 -0
- package/.output/server/node_modules/@babel/parser/lib/index.js +14611 -0
- package/.output/server/node_modules/@babel/parser/package.json +50 -0
- package/.output/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +6801 -0
- package/.output/server/node_modules/@vue/compiler-core/package.json +58 -0
- package/.output/server/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +692 -0
- package/.output/server/node_modules/@vue/compiler-dom/package.json +57 -0
- package/.output/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1420 -0
- package/.output/server/node_modules/@vue/compiler-ssr/package.json +34 -0
- package/.output/server/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js +1903 -0
- package/.output/server/node_modules/@vue/reactivity/package.json +55 -0
- package/.output/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js +6980 -0
- package/.output/server/node_modules/@vue/runtime-core/package.json +52 -0
- package/.output/server/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.prod.js +1867 -0
- package/.output/server/node_modules/@vue/runtime-dom/package.json +60 -0
- package/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +904 -0
- package/.output/server/node_modules/@vue/server-renderer/package.json +53 -0
- package/.output/server/node_modules/@vue/shared/dist/shared.cjs.prod.js +636 -0
- package/.output/server/node_modules/@vue/shared/package.json +47 -0
- package/.output/server/node_modules/devalue/index.js +17 -0
- package/.output/server/node_modules/devalue/package.json +39 -0
- package/.output/server/node_modules/devalue/src/base64.js +60 -0
- package/.output/server/node_modules/devalue/src/constants.js +12 -0
- package/.output/server/node_modules/devalue/src/operations.js +193 -0
- package/.output/server/node_modules/devalue/src/parse.js +274 -0
- package/.output/server/node_modules/devalue/src/stringify.js +428 -0
- package/.output/server/node_modules/devalue/src/uneval.js +606 -0
- package/.output/server/node_modules/devalue/src/utils.js +185 -0
- package/.output/server/node_modules/entities/dist/commonjs/decode-codepoint.js +77 -0
- package/.output/server/node_modules/entities/dist/commonjs/decode.js +568 -0
- package/.output/server/node_modules/entities/dist/commonjs/generated/decode-data-html.js +7 -0
- package/.output/server/node_modules/entities/dist/commonjs/generated/decode-data-xml.js +7 -0
- package/.output/server/node_modules/entities/dist/commonjs/internal/bin-trie-flags.js +21 -0
- package/.output/server/node_modules/entities/dist/commonjs/internal/decode-shared.js +31 -0
- package/.output/server/node_modules/entities/dist/commonjs/package.json +3 -0
- package/.output/server/node_modules/entities/package.json +120 -0
- package/.output/server/node_modules/estree-walker/dist/umd/estree-walker.js +344 -0
- package/.output/server/node_modules/estree-walker/package.json +37 -0
- package/.output/server/node_modules/hookable/dist/index.mjs +257 -0
- package/.output/server/node_modules/hookable/package.json +53 -0
- package/.output/server/node_modules/nostics/dist/formatters/ansi.mjs +19 -0
- package/.output/server/node_modules/nostics/dist/index.mjs +187 -0
- package/.output/server/node_modules/nostics/package.json +125 -0
- package/.output/server/node_modules/source-map-js/lib/array-set.js +121 -0
- package/.output/server/node_modules/source-map-js/lib/base64-vlq.js +140 -0
- package/.output/server/node_modules/source-map-js/lib/base64.js +67 -0
- package/.output/server/node_modules/source-map-js/lib/binary-search.js +111 -0
- package/.output/server/node_modules/source-map-js/lib/mapping-list.js +79 -0
- package/.output/server/node_modules/source-map-js/lib/quick-sort.js +132 -0
- package/.output/server/node_modules/source-map-js/lib/source-map-consumer.js +1188 -0
- package/.output/server/node_modules/source-map-js/lib/source-map-generator.js +444 -0
- package/.output/server/node_modules/source-map-js/lib/source-node.js +413 -0
- package/.output/server/node_modules/source-map-js/lib/util.js +594 -0
- package/.output/server/node_modules/source-map-js/package.json +71 -0
- package/.output/server/node_modules/source-map-js/source-map.js +8 -0
- package/.output/server/node_modules/ufo/dist/index.mjs +645 -0
- package/.output/server/node_modules/ufo/package.json +48 -0
- package/.output/server/node_modules/unhead/dist/client.mjs +22 -0
- package/.output/server/node_modules/unhead/dist/legacy.mjs +33 -0
- package/.output/server/node_modules/unhead/dist/minify.mjs +183 -0
- package/.output/server/node_modules/unhead/dist/parser.mjs +518 -0
- package/.output/server/node_modules/unhead/dist/plugins.mjs +720 -0
- package/.output/server/node_modules/unhead/dist/server.mjs +99 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.-hZVKou0.mjs +400 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.BEmVMkeA.mjs +673 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.BGFxPGPQ.mjs +47 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.BQWSw36o.mjs +192 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.Bf_fPVYA.mjs +6 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.Bjbp1C8D.mjs +224 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.Bm4Y6XQI.mjs +17 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.C5Bksi2B.mjs +49 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.CGPOfp5O.mjs +32 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.CHEy9ana.mjs +7 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.D7HkBzZn.mjs +59 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.Dssd7L5I.mjs +196 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.jEy9BmRq.mjs +264 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.oZ7pkTV1.mjs +19 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.tQnRaXfX.mjs +240 -0
- package/.output/server/node_modules/unhead/dist/stream/client.mjs +33 -0
- package/.output/server/node_modules/unhead/dist/stream/iife.mjs +2 -0
- package/.output/server/node_modules/unhead/dist/stream/server.mjs +445 -0
- package/.output/server/node_modules/unhead/dist/utils.mjs +7 -0
- package/.output/server/node_modules/unhead/package.json +179 -0
- package/.output/server/node_modules/vue/dist/vue.cjs.js +80 -0
- package/.output/server/node_modules/vue/dist/vue.cjs.prod.js +66 -0
- package/.output/server/node_modules/vue/index.js +7 -0
- package/.output/server/node_modules/vue/index.mjs +1 -0
- package/.output/server/node_modules/vue/package.json +112 -0
- package/.output/server/node_modules/vue/server-renderer/index.mjs +1 -0
- package/.output/server/node_modules/vue-bundle-renderer/dist/runtime.mjs +278 -0
- package/.output/server/node_modules/vue-bundle-renderer/package.json +54 -0
- package/.output/server/node_modules/yaml/dist/compose/compose-collection.js +90 -0
- package/.output/server/node_modules/yaml/dist/compose/compose-doc.js +45 -0
- package/.output/server/node_modules/yaml/dist/compose/compose-node.js +112 -0
- package/.output/server/node_modules/yaml/dist/compose/compose-scalar.js +88 -0
- package/.output/server/node_modules/yaml/dist/compose/composer.js +224 -0
- package/.output/server/node_modules/yaml/dist/compose/resolve-block-map.js +117 -0
- package/.output/server/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
- package/.output/server/node_modules/yaml/dist/compose/resolve-block-seq.js +51 -0
- package/.output/server/node_modules/yaml/dist/compose/resolve-end.js +39 -0
- package/.output/server/node_modules/yaml/dist/compose/resolve-flow-collection.js +209 -0
- package/.output/server/node_modules/yaml/dist/compose/resolve-flow-scalar.js +227 -0
- package/.output/server/node_modules/yaml/dist/compose/resolve-props.js +148 -0
- package/.output/server/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
- package/.output/server/node_modules/yaml/dist/compose/util-empty-scalar-position.js +28 -0
- package/.output/server/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
- package/.output/server/node_modules/yaml/dist/compose/util-map-includes.js +15 -0
- package/.output/server/node_modules/yaml/dist/doc/Document.js +337 -0
- package/.output/server/node_modules/yaml/dist/doc/anchors.js +76 -0
- package/.output/server/node_modules/yaml/dist/doc/applyReviver.js +57 -0
- package/.output/server/node_modules/yaml/dist/doc/createNode.js +90 -0
- package/.output/server/node_modules/yaml/dist/doc/directives.js +178 -0
- package/.output/server/node_modules/yaml/dist/errors.js +62 -0
- package/.output/server/node_modules/yaml/dist/index.js +50 -0
- package/.output/server/node_modules/yaml/dist/log.js +19 -0
- package/.output/server/node_modules/yaml/dist/nodes/Alias.js +118 -0
- package/.output/server/node_modules/yaml/dist/nodes/Collection.js +151 -0
- package/.output/server/node_modules/yaml/dist/nodes/Node.js +40 -0
- package/.output/server/node_modules/yaml/dist/nodes/Pair.js +39 -0
- package/.output/server/node_modules/yaml/dist/nodes/Scalar.js +27 -0
- package/.output/server/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
- package/.output/server/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
- package/.output/server/node_modules/yaml/dist/nodes/addPairToJSMap.js +65 -0
- package/.output/server/node_modules/yaml/dist/nodes/identity.js +53 -0
- package/.output/server/node_modules/yaml/dist/nodes/toJS.js +39 -0
- package/.output/server/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
- package/.output/server/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
- package/.output/server/node_modules/yaml/dist/parse/cst-visit.js +99 -0
- package/.output/server/node_modules/yaml/dist/parse/cst.js +112 -0
- package/.output/server/node_modules/yaml/dist/parse/lexer.js +723 -0
- package/.output/server/node_modules/yaml/dist/parse/line-counter.js +41 -0
- package/.output/server/node_modules/yaml/dist/parse/parser.js +980 -0
- package/.output/server/node_modules/yaml/dist/public-api.js +107 -0
- package/.output/server/node_modules/yaml/dist/schema/Schema.js +39 -0
- package/.output/server/node_modules/yaml/dist/schema/common/map.js +19 -0
- package/.output/server/node_modules/yaml/dist/schema/common/null.js +17 -0
- package/.output/server/node_modules/yaml/dist/schema/common/seq.js +19 -0
- package/.output/server/node_modules/yaml/dist/schema/common/string.js +16 -0
- package/.output/server/node_modules/yaml/dist/schema/core/bool.js +21 -0
- package/.output/server/node_modules/yaml/dist/schema/core/float.js +47 -0
- package/.output/server/node_modules/yaml/dist/schema/core/int.js +42 -0
- package/.output/server/node_modules/yaml/dist/schema/core/schema.js +25 -0
- package/.output/server/node_modules/yaml/dist/schema/json/schema.js +64 -0
- package/.output/server/node_modules/yaml/dist/schema/tags.js +99 -0
- package/.output/server/node_modules/yaml/dist/schema/yaml-1.1/binary.js +70 -0
- package/.output/server/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
- package/.output/server/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
- package/.output/server/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
- package/.output/server/node_modules/yaml/dist/schema/yaml-1.1/merge.js +71 -0
- package/.output/server/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
- package/.output/server/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
- package/.output/server/node_modules/yaml/dist/schema/yaml-1.1/schema.js +41 -0
- package/.output/server/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
- package/.output/server/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
- package/.output/server/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
- package/.output/server/node_modules/yaml/dist/stringify/stringify.js +132 -0
- package/.output/server/node_modules/yaml/dist/stringify/stringifyCollection.js +155 -0
- package/.output/server/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
- package/.output/server/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
- package/.output/server/node_modules/yaml/dist/stringify/stringifyNumber.js +27 -0
- package/.output/server/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
- package/.output/server/node_modules/yaml/dist/stringify/stringifyString.js +338 -0
- package/.output/server/node_modules/yaml/dist/visit.js +236 -0
- package/.output/server/node_modules/yaml/package.json +97 -0
- package/.output/server/package.json +28 -0
- package/LICENSE +21 -0
- package/README.md +57 -1
- package/bin/launch.mjs +158 -0
- package/bin/shelfware.mjs +6 -0
- package/package.json +64 -5
- package/cli.mjs +0 -3
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var identity = require('../nodes/identity.js');
|
|
4
|
+
var Scalar = require('../nodes/Scalar.js');
|
|
5
|
+
var YAMLMap = require('../nodes/YAMLMap.js');
|
|
6
|
+
var YAMLSeq = require('../nodes/YAMLSeq.js');
|
|
7
|
+
var resolveBlockMap = require('./resolve-block-map.js');
|
|
8
|
+
var resolveBlockSeq = require('./resolve-block-seq.js');
|
|
9
|
+
var resolveFlowCollection = require('./resolve-flow-collection.js');
|
|
10
|
+
|
|
11
|
+
function resolveCollection(CN, ctx, token, onError, tagName, tag) {
|
|
12
|
+
const coll = token.type === 'block-map'
|
|
13
|
+
? resolveBlockMap.resolveBlockMap(CN, ctx, token, onError, tag)
|
|
14
|
+
: token.type === 'block-seq'
|
|
15
|
+
? resolveBlockSeq.resolveBlockSeq(CN, ctx, token, onError, tag)
|
|
16
|
+
: resolveFlowCollection.resolveFlowCollection(CN, ctx, token, onError, tag);
|
|
17
|
+
const Coll = coll.constructor;
|
|
18
|
+
// If we got a tagName matching the class, or the tag name is '!',
|
|
19
|
+
// then use the tagName from the node class used to create it.
|
|
20
|
+
if (tagName === '!' || tagName === Coll.tagName) {
|
|
21
|
+
coll.tag = Coll.tagName;
|
|
22
|
+
return coll;
|
|
23
|
+
}
|
|
24
|
+
if (tagName)
|
|
25
|
+
coll.tag = tagName;
|
|
26
|
+
return coll;
|
|
27
|
+
}
|
|
28
|
+
function composeCollection(CN, ctx, token, props, onError) {
|
|
29
|
+
const tagToken = props.tag;
|
|
30
|
+
const tagName = !tagToken
|
|
31
|
+
? null
|
|
32
|
+
: ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg));
|
|
33
|
+
if (token.type === 'block-seq') {
|
|
34
|
+
const { anchor, newlineAfterProp: nl } = props;
|
|
35
|
+
const lastProp = anchor && tagToken
|
|
36
|
+
? anchor.offset > tagToken.offset
|
|
37
|
+
? anchor
|
|
38
|
+
: tagToken
|
|
39
|
+
: (anchor ?? tagToken);
|
|
40
|
+
if (lastProp && (!nl || nl.offset < lastProp.offset)) {
|
|
41
|
+
const message = 'Missing newline after block sequence props';
|
|
42
|
+
onError(lastProp, 'MISSING_CHAR', message);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const expType = token.type === 'block-map'
|
|
46
|
+
? 'map'
|
|
47
|
+
: token.type === 'block-seq'
|
|
48
|
+
? 'seq'
|
|
49
|
+
: token.start.source === '{'
|
|
50
|
+
? 'map'
|
|
51
|
+
: 'seq';
|
|
52
|
+
// shortcut: check if it's a generic YAMLMap or YAMLSeq
|
|
53
|
+
// before jumping into the custom tag logic.
|
|
54
|
+
if (!tagToken ||
|
|
55
|
+
!tagName ||
|
|
56
|
+
tagName === '!' ||
|
|
57
|
+
(tagName === YAMLMap.YAMLMap.tagName && expType === 'map') ||
|
|
58
|
+
(tagName === YAMLSeq.YAMLSeq.tagName && expType === 'seq')) {
|
|
59
|
+
return resolveCollection(CN, ctx, token, onError, tagName);
|
|
60
|
+
}
|
|
61
|
+
let tag = ctx.schema.tags.find(t => t.tag === tagName && t.collection === expType);
|
|
62
|
+
if (!tag) {
|
|
63
|
+
const kt = ctx.schema.knownTags[tagName];
|
|
64
|
+
if (kt?.collection === expType) {
|
|
65
|
+
ctx.schema.tags.push(Object.assign({}, kt, { default: false }));
|
|
66
|
+
tag = kt;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
if (kt) {
|
|
70
|
+
onError(tagToken, 'BAD_COLLECTION_TYPE', `${kt.tag} used for ${expType} collection, but expects ${kt.collection ?? 'scalar'}`, true);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, true);
|
|
74
|
+
}
|
|
75
|
+
return resolveCollection(CN, ctx, token, onError, tagName);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const coll = resolveCollection(CN, ctx, token, onError, tagName, tag);
|
|
79
|
+
const res = tag.resolve?.(coll, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg), ctx.options) ?? coll;
|
|
80
|
+
const node = identity.isNode(res)
|
|
81
|
+
? res
|
|
82
|
+
: new Scalar.Scalar(res);
|
|
83
|
+
node.range = coll.range;
|
|
84
|
+
node.tag = tagName;
|
|
85
|
+
if (tag?.format)
|
|
86
|
+
node.format = tag.format;
|
|
87
|
+
return node;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
exports.composeCollection = composeCollection;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Document = require('../doc/Document.js');
|
|
4
|
+
var composeNode = require('./compose-node.js');
|
|
5
|
+
var resolveEnd = require('./resolve-end.js');
|
|
6
|
+
var resolveProps = require('./resolve-props.js');
|
|
7
|
+
|
|
8
|
+
function composeDoc(options, directives, { offset, start, value, end }, onError) {
|
|
9
|
+
const opts = Object.assign({ _directives: directives }, options);
|
|
10
|
+
const doc = new Document.Document(undefined, opts);
|
|
11
|
+
const ctx = {
|
|
12
|
+
atKey: false,
|
|
13
|
+
atRoot: true,
|
|
14
|
+
directives: doc.directives,
|
|
15
|
+
options: doc.options,
|
|
16
|
+
schema: doc.schema
|
|
17
|
+
};
|
|
18
|
+
const props = resolveProps.resolveProps(start, {
|
|
19
|
+
indicator: 'doc-start',
|
|
20
|
+
next: value ?? end?.[0],
|
|
21
|
+
offset,
|
|
22
|
+
onError,
|
|
23
|
+
parentIndent: 0,
|
|
24
|
+
startOnNewline: true
|
|
25
|
+
});
|
|
26
|
+
if (props.found) {
|
|
27
|
+
doc.directives.docStart = true;
|
|
28
|
+
if (value &&
|
|
29
|
+
(value.type === 'block-map' || value.type === 'block-seq') &&
|
|
30
|
+
!props.hasNewline)
|
|
31
|
+
onError(props.end, 'MISSING_CHAR', 'Block collection cannot start on same line with directives-end marker');
|
|
32
|
+
}
|
|
33
|
+
// @ts-expect-error If Contents is set, let's trust the user
|
|
34
|
+
doc.contents = value
|
|
35
|
+
? composeNode.composeNode(ctx, value, props, onError)
|
|
36
|
+
: composeNode.composeEmptyNode(ctx, props.end, start, null, props, onError);
|
|
37
|
+
const contentEnd = doc.contents.range[2];
|
|
38
|
+
const re = resolveEnd.resolveEnd(end, contentEnd, false, onError);
|
|
39
|
+
if (re.comment)
|
|
40
|
+
doc.comment = re.comment;
|
|
41
|
+
doc.range = [offset, contentEnd, re.offset];
|
|
42
|
+
return doc;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
exports.composeDoc = composeDoc;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Alias = require('../nodes/Alias.js');
|
|
4
|
+
var identity = require('../nodes/identity.js');
|
|
5
|
+
var composeCollection = require('./compose-collection.js');
|
|
6
|
+
var composeScalar = require('./compose-scalar.js');
|
|
7
|
+
var resolveEnd = require('./resolve-end.js');
|
|
8
|
+
var utilEmptyScalarPosition = require('./util-empty-scalar-position.js');
|
|
9
|
+
|
|
10
|
+
const CN = { composeNode, composeEmptyNode };
|
|
11
|
+
function composeNode(ctx, token, props, onError) {
|
|
12
|
+
const atKey = ctx.atKey;
|
|
13
|
+
const { spaceBefore, comment, anchor, tag } = props;
|
|
14
|
+
let node;
|
|
15
|
+
let isSrcToken = true;
|
|
16
|
+
switch (token.type) {
|
|
17
|
+
case 'alias':
|
|
18
|
+
node = composeAlias(ctx, token, onError);
|
|
19
|
+
if (anchor || tag)
|
|
20
|
+
onError(token, 'ALIAS_PROPS', 'An alias node must not specify any properties');
|
|
21
|
+
break;
|
|
22
|
+
case 'scalar':
|
|
23
|
+
case 'single-quoted-scalar':
|
|
24
|
+
case 'double-quoted-scalar':
|
|
25
|
+
case 'block-scalar':
|
|
26
|
+
node = composeScalar.composeScalar(ctx, token, tag, onError);
|
|
27
|
+
if (anchor)
|
|
28
|
+
node.anchor = anchor.source.substring(1);
|
|
29
|
+
break;
|
|
30
|
+
case 'block-map':
|
|
31
|
+
case 'block-seq':
|
|
32
|
+
case 'flow-collection':
|
|
33
|
+
try {
|
|
34
|
+
node = composeCollection.composeCollection(CN, ctx, token, props, onError);
|
|
35
|
+
if (anchor)
|
|
36
|
+
node.anchor = anchor.source.substring(1);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
// Almost certainly here due to a stack overflow
|
|
40
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
41
|
+
onError(token, 'RESOURCE_EXHAUSTION', message);
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
default: {
|
|
45
|
+
const message = token.type === 'error'
|
|
46
|
+
? token.message
|
|
47
|
+
: `Unsupported token (type: ${token.type})`;
|
|
48
|
+
onError(token, 'UNEXPECTED_TOKEN', message);
|
|
49
|
+
isSrcToken = false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
node ?? (node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError));
|
|
53
|
+
if (anchor && node.anchor === '')
|
|
54
|
+
onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string');
|
|
55
|
+
if (atKey &&
|
|
56
|
+
ctx.options.stringKeys &&
|
|
57
|
+
(!identity.isScalar(node) ||
|
|
58
|
+
typeof node.value !== 'string' ||
|
|
59
|
+
(node.tag && node.tag !== 'tag:yaml.org,2002:str'))) {
|
|
60
|
+
const msg = 'With stringKeys, all keys must be strings';
|
|
61
|
+
onError(tag ?? token, 'NON_STRING_KEY', msg);
|
|
62
|
+
}
|
|
63
|
+
if (spaceBefore)
|
|
64
|
+
node.spaceBefore = true;
|
|
65
|
+
if (comment) {
|
|
66
|
+
if (token.type === 'scalar' && token.source === '')
|
|
67
|
+
node.comment = comment;
|
|
68
|
+
else
|
|
69
|
+
node.commentBefore = comment;
|
|
70
|
+
}
|
|
71
|
+
// @ts-expect-error Type checking misses meaning of isSrcToken
|
|
72
|
+
if (ctx.options.keepSourceTokens && isSrcToken)
|
|
73
|
+
node.srcToken = token;
|
|
74
|
+
return node;
|
|
75
|
+
}
|
|
76
|
+
function composeEmptyNode(ctx, offset, before, pos, { spaceBefore, comment, anchor, tag, end }, onError) {
|
|
77
|
+
const token = {
|
|
78
|
+
type: 'scalar',
|
|
79
|
+
offset: utilEmptyScalarPosition.emptyScalarPosition(offset, before, pos),
|
|
80
|
+
indent: -1,
|
|
81
|
+
source: ''
|
|
82
|
+
};
|
|
83
|
+
const node = composeScalar.composeScalar(ctx, token, tag, onError);
|
|
84
|
+
if (anchor) {
|
|
85
|
+
node.anchor = anchor.source.substring(1);
|
|
86
|
+
if (node.anchor === '')
|
|
87
|
+
onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string');
|
|
88
|
+
}
|
|
89
|
+
if (spaceBefore)
|
|
90
|
+
node.spaceBefore = true;
|
|
91
|
+
if (comment) {
|
|
92
|
+
node.comment = comment;
|
|
93
|
+
node.range[2] = end;
|
|
94
|
+
}
|
|
95
|
+
return node;
|
|
96
|
+
}
|
|
97
|
+
function composeAlias({ options }, { offset, source, end }, onError) {
|
|
98
|
+
const alias = new Alias.Alias(source.substring(1));
|
|
99
|
+
if (alias.source === '')
|
|
100
|
+
onError(offset, 'BAD_ALIAS', 'Alias cannot be an empty string');
|
|
101
|
+
if (alias.source.endsWith(':'))
|
|
102
|
+
onError(offset + source.length - 1, 'BAD_ALIAS', 'Alias ending in : is ambiguous', true);
|
|
103
|
+
const valueEnd = offset + source.length;
|
|
104
|
+
const re = resolveEnd.resolveEnd(end, valueEnd, options.strict, onError);
|
|
105
|
+
alias.range = [offset, valueEnd, re.offset];
|
|
106
|
+
if (re.comment)
|
|
107
|
+
alias.comment = re.comment;
|
|
108
|
+
return alias;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
exports.composeEmptyNode = composeEmptyNode;
|
|
112
|
+
exports.composeNode = composeNode;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var identity = require('../nodes/identity.js');
|
|
4
|
+
var Scalar = require('../nodes/Scalar.js');
|
|
5
|
+
var resolveBlockScalar = require('./resolve-block-scalar.js');
|
|
6
|
+
var resolveFlowScalar = require('./resolve-flow-scalar.js');
|
|
7
|
+
|
|
8
|
+
function composeScalar(ctx, token, tagToken, onError) {
|
|
9
|
+
const { value, type, comment, range } = token.type === 'block-scalar'
|
|
10
|
+
? resolveBlockScalar.resolveBlockScalar(ctx, token, onError)
|
|
11
|
+
: resolveFlowScalar.resolveFlowScalar(token, ctx.options.strict, onError);
|
|
12
|
+
const tagName = tagToken
|
|
13
|
+
? ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg))
|
|
14
|
+
: null;
|
|
15
|
+
let tag;
|
|
16
|
+
if (ctx.options.stringKeys && ctx.atKey) {
|
|
17
|
+
tag = ctx.schema[identity.SCALAR];
|
|
18
|
+
}
|
|
19
|
+
else if (tagName)
|
|
20
|
+
tag = findScalarTagByName(ctx.schema, value, tagName, tagToken, onError);
|
|
21
|
+
else if (token.type === 'scalar')
|
|
22
|
+
tag = findScalarTagByTest(ctx, value, token, onError);
|
|
23
|
+
else
|
|
24
|
+
tag = ctx.schema[identity.SCALAR];
|
|
25
|
+
let scalar;
|
|
26
|
+
try {
|
|
27
|
+
const res = tag.resolve(value, msg => onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
|
|
28
|
+
scalar = identity.isScalar(res) ? res : new Scalar.Scalar(res);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
32
|
+
onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg);
|
|
33
|
+
scalar = new Scalar.Scalar(value);
|
|
34
|
+
}
|
|
35
|
+
scalar.range = range;
|
|
36
|
+
scalar.source = value;
|
|
37
|
+
if (type)
|
|
38
|
+
scalar.type = type;
|
|
39
|
+
if (tagName)
|
|
40
|
+
scalar.tag = tagName;
|
|
41
|
+
if (tag.format)
|
|
42
|
+
scalar.format = tag.format;
|
|
43
|
+
if (comment)
|
|
44
|
+
scalar.comment = comment;
|
|
45
|
+
return scalar;
|
|
46
|
+
}
|
|
47
|
+
function findScalarTagByName(schema, value, tagName, tagToken, onError) {
|
|
48
|
+
if (tagName === '!')
|
|
49
|
+
return schema[identity.SCALAR]; // non-specific tag
|
|
50
|
+
const matchWithTest = [];
|
|
51
|
+
for (const tag of schema.tags) {
|
|
52
|
+
if (!tag.collection && tag.tag === tagName) {
|
|
53
|
+
if (tag.default && tag.test)
|
|
54
|
+
matchWithTest.push(tag);
|
|
55
|
+
else
|
|
56
|
+
return tag;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
for (const tag of matchWithTest)
|
|
60
|
+
if (tag.test?.test(value))
|
|
61
|
+
return tag;
|
|
62
|
+
const kt = schema.knownTags[tagName];
|
|
63
|
+
if (kt && !kt.collection) {
|
|
64
|
+
// Ensure that the known tag is available for stringifying,
|
|
65
|
+
// but does not get used by default.
|
|
66
|
+
schema.tags.push(Object.assign({}, kt, { default: false, test: undefined }));
|
|
67
|
+
return kt;
|
|
68
|
+
}
|
|
69
|
+
onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, tagName !== 'tag:yaml.org,2002:str');
|
|
70
|
+
return schema[identity.SCALAR];
|
|
71
|
+
}
|
|
72
|
+
function findScalarTagByTest({ atKey, directives, schema }, value, token, onError) {
|
|
73
|
+
const tag = schema.tags.find(tag => (tag.default === true || (atKey && tag.default === 'key')) &&
|
|
74
|
+
tag.test?.test(value)) || schema[identity.SCALAR];
|
|
75
|
+
if (schema.compat) {
|
|
76
|
+
const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ??
|
|
77
|
+
schema[identity.SCALAR];
|
|
78
|
+
if (tag.tag !== compat.tag) {
|
|
79
|
+
const ts = directives.tagString(tag.tag);
|
|
80
|
+
const cs = directives.tagString(compat.tag);
|
|
81
|
+
const msg = `Value may be parsed as either ${ts} or ${cs}`;
|
|
82
|
+
onError(token, 'TAG_RESOLVE_FAILED', msg, true);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return tag;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
exports.composeScalar = composeScalar;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_process = require('process');
|
|
4
|
+
var directives = require('../doc/directives.js');
|
|
5
|
+
var Document = require('../doc/Document.js');
|
|
6
|
+
var errors = require('../errors.js');
|
|
7
|
+
var identity = require('../nodes/identity.js');
|
|
8
|
+
var composeDoc = require('./compose-doc.js');
|
|
9
|
+
var resolveEnd = require('./resolve-end.js');
|
|
10
|
+
|
|
11
|
+
function getErrorPos(src) {
|
|
12
|
+
if (typeof src === 'number')
|
|
13
|
+
return [src, src + 1];
|
|
14
|
+
if (Array.isArray(src))
|
|
15
|
+
return src.length === 2 ? src : [src[0], src[1]];
|
|
16
|
+
const { offset, source } = src;
|
|
17
|
+
return [offset, offset + (typeof source === 'string' ? source.length : 1)];
|
|
18
|
+
}
|
|
19
|
+
function parsePrelude(prelude) {
|
|
20
|
+
let comment = '';
|
|
21
|
+
let atComment = false;
|
|
22
|
+
let afterEmptyLine = false;
|
|
23
|
+
for (let i = 0; i < prelude.length; ++i) {
|
|
24
|
+
const source = prelude[i];
|
|
25
|
+
switch (source[0]) {
|
|
26
|
+
case '#':
|
|
27
|
+
comment +=
|
|
28
|
+
(comment === '' ? '' : afterEmptyLine ? '\n\n' : '\n') +
|
|
29
|
+
(source.substring(1) || ' ');
|
|
30
|
+
atComment = true;
|
|
31
|
+
afterEmptyLine = false;
|
|
32
|
+
break;
|
|
33
|
+
case '%':
|
|
34
|
+
if (prelude[i + 1]?.[0] !== '#')
|
|
35
|
+
i += 1;
|
|
36
|
+
atComment = false;
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
// This may be wrong after doc-end, but in that case it doesn't matter
|
|
40
|
+
if (!atComment)
|
|
41
|
+
afterEmptyLine = true;
|
|
42
|
+
atComment = false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { comment, afterEmptyLine };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Compose a stream of CST nodes into a stream of YAML Documents.
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { Composer, Parser } from 'yaml'
|
|
52
|
+
*
|
|
53
|
+
* const src: string = ...
|
|
54
|
+
* const tokens = new Parser().parse(src)
|
|
55
|
+
* const docs = new Composer().compose(tokens)
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
class Composer {
|
|
59
|
+
constructor(options = {}) {
|
|
60
|
+
this.doc = null;
|
|
61
|
+
this.atDirectives = false;
|
|
62
|
+
this.prelude = [];
|
|
63
|
+
this.errors = [];
|
|
64
|
+
this.warnings = [];
|
|
65
|
+
this.onError = (source, code, message, warning) => {
|
|
66
|
+
const pos = getErrorPos(source);
|
|
67
|
+
if (warning)
|
|
68
|
+
this.warnings.push(new errors.YAMLWarning(pos, code, message));
|
|
69
|
+
else
|
|
70
|
+
this.errors.push(new errors.YAMLParseError(pos, code, message));
|
|
71
|
+
};
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
73
|
+
this.directives = new directives.Directives({ version: options.version || '1.2' });
|
|
74
|
+
this.options = options;
|
|
75
|
+
}
|
|
76
|
+
decorate(doc, afterDoc) {
|
|
77
|
+
const { comment, afterEmptyLine } = parsePrelude(this.prelude);
|
|
78
|
+
//console.log({ dc: doc.comment, prelude, comment })
|
|
79
|
+
if (comment) {
|
|
80
|
+
const dc = doc.contents;
|
|
81
|
+
if (afterDoc) {
|
|
82
|
+
doc.comment = doc.comment ? `${doc.comment}\n${comment}` : comment;
|
|
83
|
+
}
|
|
84
|
+
else if (afterEmptyLine || doc.directives.docStart || !dc) {
|
|
85
|
+
doc.commentBefore = comment;
|
|
86
|
+
}
|
|
87
|
+
else if (identity.isCollection(dc) && !dc.flow && dc.items.length > 0) {
|
|
88
|
+
let it = dc.items[0];
|
|
89
|
+
if (identity.isPair(it))
|
|
90
|
+
it = it.key;
|
|
91
|
+
const cb = it.commentBefore;
|
|
92
|
+
it.commentBefore = cb ? `${comment}\n${cb}` : comment;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const cb = dc.commentBefore;
|
|
96
|
+
dc.commentBefore = cb ? `${comment}\n${cb}` : comment;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (afterDoc) {
|
|
100
|
+
for (let i = 0; i < this.errors.length; ++i)
|
|
101
|
+
doc.errors.push(this.errors[i]);
|
|
102
|
+
for (let i = 0; i < this.warnings.length; ++i)
|
|
103
|
+
doc.warnings.push(this.warnings[i]);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
doc.errors = this.errors;
|
|
107
|
+
doc.warnings = this.warnings;
|
|
108
|
+
}
|
|
109
|
+
this.prelude = [];
|
|
110
|
+
this.errors = [];
|
|
111
|
+
this.warnings = [];
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Current stream status information.
|
|
115
|
+
*
|
|
116
|
+
* Mostly useful at the end of input for an empty stream.
|
|
117
|
+
*/
|
|
118
|
+
streamInfo() {
|
|
119
|
+
return {
|
|
120
|
+
comment: parsePrelude(this.prelude).comment,
|
|
121
|
+
directives: this.directives,
|
|
122
|
+
errors: this.errors,
|
|
123
|
+
warnings: this.warnings
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Compose tokens into documents.
|
|
128
|
+
*
|
|
129
|
+
* @param forceDoc - If the stream contains no document, still emit a final document including any comments and directives that would be applied to a subsequent document.
|
|
130
|
+
* @param endOffset - Should be set if `forceDoc` is also set, to set the document range end and to indicate errors correctly.
|
|
131
|
+
*/
|
|
132
|
+
*compose(tokens, forceDoc = false, endOffset = -1) {
|
|
133
|
+
for (const token of tokens)
|
|
134
|
+
yield* this.next(token);
|
|
135
|
+
yield* this.end(forceDoc, endOffset);
|
|
136
|
+
}
|
|
137
|
+
/** Advance the composer by one CST token. */
|
|
138
|
+
*next(token) {
|
|
139
|
+
if (node_process.env.LOG_STREAM)
|
|
140
|
+
console.dir(token, { depth: null });
|
|
141
|
+
switch (token.type) {
|
|
142
|
+
case 'directive':
|
|
143
|
+
this.directives.add(token.source, (offset, message, warning) => {
|
|
144
|
+
const pos = getErrorPos(token);
|
|
145
|
+
pos[0] += offset;
|
|
146
|
+
this.onError(pos, 'BAD_DIRECTIVE', message, warning);
|
|
147
|
+
});
|
|
148
|
+
this.prelude.push(token.source);
|
|
149
|
+
this.atDirectives = true;
|
|
150
|
+
break;
|
|
151
|
+
case 'document': {
|
|
152
|
+
const doc = composeDoc.composeDoc(this.options, this.directives, token, this.onError);
|
|
153
|
+
if (this.atDirectives && !doc.directives.docStart)
|
|
154
|
+
this.onError(token, 'MISSING_CHAR', 'Missing directives-end/doc-start indicator line');
|
|
155
|
+
this.decorate(doc, false);
|
|
156
|
+
if (this.doc)
|
|
157
|
+
yield this.doc;
|
|
158
|
+
this.doc = doc;
|
|
159
|
+
this.atDirectives = false;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
case 'byte-order-mark':
|
|
163
|
+
case 'space':
|
|
164
|
+
break;
|
|
165
|
+
case 'comment':
|
|
166
|
+
case 'newline':
|
|
167
|
+
this.prelude.push(token.source);
|
|
168
|
+
break;
|
|
169
|
+
case 'error': {
|
|
170
|
+
const msg = token.source
|
|
171
|
+
? `${token.message}: ${JSON.stringify(token.source)}`
|
|
172
|
+
: token.message;
|
|
173
|
+
const error = new errors.YAMLParseError(getErrorPos(token), 'UNEXPECTED_TOKEN', msg);
|
|
174
|
+
if (this.atDirectives || !this.doc)
|
|
175
|
+
this.errors.push(error);
|
|
176
|
+
else
|
|
177
|
+
this.doc.errors.push(error);
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
case 'doc-end': {
|
|
181
|
+
if (!this.doc) {
|
|
182
|
+
const msg = 'Unexpected doc-end without preceding document';
|
|
183
|
+
this.errors.push(new errors.YAMLParseError(getErrorPos(token), 'UNEXPECTED_TOKEN', msg));
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
this.doc.directives.docEnd = true;
|
|
187
|
+
const end = resolveEnd.resolveEnd(token.end, token.offset + token.source.length, this.doc.options.strict, this.onError);
|
|
188
|
+
this.decorate(this.doc, true);
|
|
189
|
+
if (end.comment) {
|
|
190
|
+
const dc = this.doc.comment;
|
|
191
|
+
this.doc.comment = dc ? `${dc}\n${end.comment}` : end.comment;
|
|
192
|
+
}
|
|
193
|
+
this.doc.range[2] = end.offset;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
default:
|
|
197
|
+
this.errors.push(new errors.YAMLParseError(getErrorPos(token), 'UNEXPECTED_TOKEN', `Unsupported token ${token.type}`));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Call at end of input to yield any remaining document.
|
|
202
|
+
*
|
|
203
|
+
* @param forceDoc - If the stream contains no document, still emit a final document including any comments and directives that would be applied to a subsequent document.
|
|
204
|
+
* @param endOffset - Should be set if `forceDoc` is also set, to set the document range end and to indicate errors correctly.
|
|
205
|
+
*/
|
|
206
|
+
*end(forceDoc = false, endOffset = -1) {
|
|
207
|
+
if (this.doc) {
|
|
208
|
+
this.decorate(this.doc, true);
|
|
209
|
+
yield this.doc;
|
|
210
|
+
this.doc = null;
|
|
211
|
+
}
|
|
212
|
+
else if (forceDoc) {
|
|
213
|
+
const opts = Object.assign({ _directives: this.directives }, this.options);
|
|
214
|
+
const doc = new Document.Document(undefined, opts);
|
|
215
|
+
if (this.atDirectives)
|
|
216
|
+
this.onError(endOffset, 'MISSING_CHAR', 'Missing directives-end indicator line');
|
|
217
|
+
doc.range = [0, endOffset, endOffset];
|
|
218
|
+
this.decorate(doc, false);
|
|
219
|
+
yield doc;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
exports.Composer = Composer;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Pair = require('../nodes/Pair.js');
|
|
4
|
+
var YAMLMap = require('../nodes/YAMLMap.js');
|
|
5
|
+
var resolveProps = require('./resolve-props.js');
|
|
6
|
+
var utilContainsNewline = require('./util-contains-newline.js');
|
|
7
|
+
var utilFlowIndentCheck = require('./util-flow-indent-check.js');
|
|
8
|
+
var utilMapIncludes = require('./util-map-includes.js');
|
|
9
|
+
|
|
10
|
+
const startColMsg = 'All mapping items must start at the same column';
|
|
11
|
+
function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, tag) {
|
|
12
|
+
const NodeClass = tag?.nodeClass ?? YAMLMap.YAMLMap;
|
|
13
|
+
const map = new NodeClass(ctx.schema);
|
|
14
|
+
if (ctx.atRoot)
|
|
15
|
+
ctx.atRoot = false;
|
|
16
|
+
let offset = bm.offset;
|
|
17
|
+
let commentEnd = null;
|
|
18
|
+
for (const collItem of bm.items) {
|
|
19
|
+
const { start, key, sep, value } = collItem;
|
|
20
|
+
// key properties
|
|
21
|
+
const keyProps = resolveProps.resolveProps(start, {
|
|
22
|
+
indicator: 'explicit-key-ind',
|
|
23
|
+
next: key ?? sep?.[0],
|
|
24
|
+
offset,
|
|
25
|
+
onError,
|
|
26
|
+
parentIndent: bm.indent,
|
|
27
|
+
startOnNewline: true
|
|
28
|
+
});
|
|
29
|
+
const implicitKey = !keyProps.found;
|
|
30
|
+
if (implicitKey) {
|
|
31
|
+
if (key) {
|
|
32
|
+
if (key.type === 'block-seq')
|
|
33
|
+
onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'A block sequence may not be used as an implicit map key');
|
|
34
|
+
else if ('indent' in key && key.indent !== bm.indent)
|
|
35
|
+
onError(offset, 'BAD_INDENT', startColMsg);
|
|
36
|
+
}
|
|
37
|
+
if (!keyProps.anchor && !keyProps.tag && !sep) {
|
|
38
|
+
commentEnd = keyProps.end;
|
|
39
|
+
if (keyProps.comment) {
|
|
40
|
+
if (map.comment)
|
|
41
|
+
map.comment += '\n' + keyProps.comment;
|
|
42
|
+
else
|
|
43
|
+
map.comment = keyProps.comment;
|
|
44
|
+
}
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (keyProps.newlineAfterProp || utilContainsNewline.containsNewline(key)) {
|
|
48
|
+
onError(key ?? start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else if (keyProps.found?.indent !== bm.indent) {
|
|
52
|
+
onError(offset, 'BAD_INDENT', startColMsg);
|
|
53
|
+
}
|
|
54
|
+
// key value
|
|
55
|
+
ctx.atKey = true;
|
|
56
|
+
const keyStart = keyProps.end;
|
|
57
|
+
const keyNode = key
|
|
58
|
+
? composeNode(ctx, key, keyProps, onError)
|
|
59
|
+
: composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
|
|
60
|
+
if (ctx.schema.compat)
|
|
61
|
+
utilFlowIndentCheck.flowIndentCheck(bm.indent, key, onError);
|
|
62
|
+
ctx.atKey = false;
|
|
63
|
+
if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
|
|
64
|
+
onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
|
|
65
|
+
// value properties
|
|
66
|
+
const valueProps = resolveProps.resolveProps(sep ?? [], {
|
|
67
|
+
indicator: 'map-value-ind',
|
|
68
|
+
next: value,
|
|
69
|
+
offset: keyNode.range[2],
|
|
70
|
+
onError,
|
|
71
|
+
parentIndent: bm.indent,
|
|
72
|
+
startOnNewline: !key || key.type === 'block-scalar'
|
|
73
|
+
});
|
|
74
|
+
offset = valueProps.end;
|
|
75
|
+
if (valueProps.found) {
|
|
76
|
+
if (implicitKey) {
|
|
77
|
+
if (value?.type === 'block-map' && !valueProps.hasNewline)
|
|
78
|
+
onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'Nested mappings are not allowed in compact mappings');
|
|
79
|
+
if (ctx.options.strict &&
|
|
80
|
+
keyProps.start < valueProps.found.offset - 1024)
|
|
81
|
+
onError(keyNode.range, 'KEY_OVER_1024_CHARS', 'The : indicator must be at most 1024 chars after the start of an implicit block mapping key');
|
|
82
|
+
}
|
|
83
|
+
// value value
|
|
84
|
+
const valueNode = value
|
|
85
|
+
? composeNode(ctx, value, valueProps, onError)
|
|
86
|
+
: composeEmptyNode(ctx, offset, sep, null, valueProps, onError);
|
|
87
|
+
if (ctx.schema.compat)
|
|
88
|
+
utilFlowIndentCheck.flowIndentCheck(bm.indent, value, onError);
|
|
89
|
+
offset = valueNode.range[2];
|
|
90
|
+
const pair = new Pair.Pair(keyNode, valueNode);
|
|
91
|
+
if (ctx.options.keepSourceTokens)
|
|
92
|
+
pair.srcToken = collItem;
|
|
93
|
+
map.items.push(pair);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// key with no value
|
|
97
|
+
if (implicitKey)
|
|
98
|
+
onError(keyNode.range, 'MISSING_CHAR', 'Implicit map keys need to be followed by map values');
|
|
99
|
+
if (valueProps.comment) {
|
|
100
|
+
if (keyNode.comment)
|
|
101
|
+
keyNode.comment += '\n' + valueProps.comment;
|
|
102
|
+
else
|
|
103
|
+
keyNode.comment = valueProps.comment;
|
|
104
|
+
}
|
|
105
|
+
const pair = new Pair.Pair(keyNode);
|
|
106
|
+
if (ctx.options.keepSourceTokens)
|
|
107
|
+
pair.srcToken = collItem;
|
|
108
|
+
map.items.push(pair);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (commentEnd && commentEnd < offset)
|
|
112
|
+
onError(commentEnd, 'IMPOSSIBLE', 'Map comment with trailing content');
|
|
113
|
+
map.range = [bm.offset, offset, commentEnd ?? offset];
|
|
114
|
+
return map;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
exports.resolveBlockMap = resolveBlockMap;
|