@intentius/chant 0.104.3 → 0.104.4
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/dist/codegen/generate-runtime-index.d.ts +3 -1
- package/dist/codegen/generate-runtime-index.d.ts.map +1 -1
- package/dist/vendor/js-yaml-load.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/codegen/generate-runtime-index.test.ts +3 -3
- package/src/codegen/generate-runtime-index.ts +5 -3
- package/src/vendor/js-yaml-load.ts +14 -63
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* Generic runtime index generator for lexicon packages.
|
|
3
3
|
*
|
|
4
4
|
* Produces the `index.ts` file containing factory constructor exports
|
|
5
|
-
* (`createResource`, `createProperty`) and collision-safe re-exports.
|
|
5
|
+
* (`createResource`, `createProperty`) and collision-safe re-exports. Each
|
|
6
|
+
* factory call is marked pure, so a bundler drops the classes a caller does
|
|
7
|
+
* not import instead of keeping every one.
|
|
6
8
|
*/
|
|
7
9
|
export interface RuntimeIndexConfig {
|
|
8
10
|
/** Lexicon identifier: "aws", "terraform", etc. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-runtime-index.d.ts","sourceRoot":"","sources":["../../src/codegen/generate-runtime-index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"generate-runtime-index.d.ts","sourceRoot":"","sources":["../../src/codegen/generate-runtime-index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,kBAAkB;IACjC,mDAAmD;IACnD,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,kBAAkB,CAAC,EAAE;QACnB,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,gDAAgD;IAChD,eAAe,CAAC,EAAE;QAChB,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,iBAAiB,EAAE,EAC9B,UAAU,EAAE,yBAAyB,EAAE,EACvC,MAAM,EAAE,kBAAkB,GACzB,MAAM,CAoDR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js-yaml-load.d.ts","sourceRoot":"","sources":["../../src/vendor/js-yaml-load.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"js-yaml-load.d.ts","sourceRoot":"","sources":["../../src/vendor/js-yaml-load.ts"],"names":[],"mappings":"AAuCA,qBAAa,aAAc,SAAQ,KAAK;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9F,YAAY,MAAM,KAAA,EAAE,IAAI,KAAA,EAKvB;CACF;AAeD,eAAO,MAAM,SAAS;;;;;CAKrB,CAAC;AAMF,iBAAS,kBAAkB,CAAE,IAAI,KAAA,WAyChC;AAED,iBAAS,gBAAgB,CAAE,IAAI,KAAA,UAqB9B;AAED,eAAO,MAAM,QAAQ;IACnB,GAAG;IACH,IAAI;IACJ,OAAO;IACP,SAAS;CACV,CAAA;AAWD,iBAAS,gBAAgB,CAAE,IAAI,KAAA,WAK9B;AAED,eAAO,MAAM,UAAU;;;;;CAYtB,CAAA;AAED,eAAO,MAAM,QAAQ;;;;CAAqG,CAAC;AAC3H,eAAO,MAAM,QAAQ;;;;CAAuG,CAAC;AAC7H,eAAO,MAAM,QAAQ;;;;CAAsG,CAAC;AAipD5H;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,KAAK,KAAA,EAAE,KAAK,KAAA,OAuBhC"}
|
package/package.json
CHANGED
|
@@ -25,9 +25,9 @@ describe("generateRuntimeIndex", () => {
|
|
|
25
25
|
const result = generateRuntimeIndex(resources, properties, baseConfig);
|
|
26
26
|
|
|
27
27
|
// Resources sorted: Alarm before Bucket
|
|
28
|
-
expect(result).toContain('export const Alarm = createResource("AWS::CloudWatch::Alarm", "test", {});');
|
|
29
|
-
expect(result).toContain('export const Bucket = createResource("AWS::S3::Bucket", "test", {"arn":"Arn"});');
|
|
30
|
-
expect(result).toContain('export const Bucket_Versioning = createProperty("AWS::S3::Bucket.VersioningConfiguration", "test");');
|
|
28
|
+
expect(result).toContain('export const Alarm = /* @__PURE__ */ createResource("AWS::CloudWatch::Alarm", "test", {});');
|
|
29
|
+
expect(result).toContain('export const Bucket = /* @__PURE__ */ createResource("AWS::S3::Bucket", "test", {"arn":"Arn"});');
|
|
30
|
+
expect(result).toContain('export const Bucket_Versioning = /* @__PURE__ */ createProperty("AWS::S3::Bucket.VersioningConfiguration", "test");');
|
|
31
31
|
|
|
32
32
|
// Alarm should come before Bucket in the output
|
|
33
33
|
const alarmIdx = result.indexOf("Alarm");
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* Generic runtime index generator for lexicon packages.
|
|
3
3
|
*
|
|
4
4
|
* Produces the `index.ts` file containing factory constructor exports
|
|
5
|
-
* (`createResource`, `createProperty`) and collision-safe re-exports.
|
|
5
|
+
* (`createResource`, `createProperty`) and collision-safe re-exports. Each
|
|
6
|
+
* factory call is marked pure, so a bundler drops the classes a caller does
|
|
7
|
+
* not import instead of keeping every one.
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
10
|
export interface RuntimeIndexConfig {
|
|
@@ -55,7 +57,7 @@ export function generateRuntimeIndex(
|
|
|
55
57
|
for (const { tsName, resourceType, attrs } of sortedResources) {
|
|
56
58
|
const attrsStr = JSON.stringify(attrs);
|
|
57
59
|
lines.push(
|
|
58
|
-
`export const ${tsName} = createResource(${JSON.stringify(resourceType)}, ${JSON.stringify(config.lexiconName)}, ${attrsStr});`,
|
|
60
|
+
`export const ${tsName} = /* @__PURE__ */ createResource(${JSON.stringify(resourceType)}, ${JSON.stringify(config.lexiconName)}, ${attrsStr});`,
|
|
59
61
|
);
|
|
60
62
|
}
|
|
61
63
|
|
|
@@ -65,7 +67,7 @@ export function generateRuntimeIndex(
|
|
|
65
67
|
const sortedProperties = [...properties].sort((a, b) => a.tsName.localeCompare(b.tsName));
|
|
66
68
|
for (const { tsName, resourceType } of sortedProperties) {
|
|
67
69
|
lines.push(
|
|
68
|
-
`export const ${tsName} = createProperty(${JSON.stringify(resourceType)}, ${JSON.stringify(config.lexiconName)});`,
|
|
70
|
+
`export const ${tsName} = /* @__PURE__ */ createProperty(${JSON.stringify(resourceType)}, ${JSON.stringify(config.lexiconName)});`,
|
|
69
71
|
);
|
|
70
72
|
}
|
|
71
73
|
|
|
@@ -29,7 +29,10 @@
|
|
|
29
29
|
* timestamp, omap, pairs, set), the snippet renderer, the schema classes and
|
|
30
30
|
* the loader's option handling are gone. The reader always runs in json mode
|
|
31
31
|
* (a repeated mapping key takes the last value) and takes its type list from
|
|
32
|
-
* the caller.
|
|
32
|
+
* the caller. With the options fixed, the branches only another setting
|
|
33
|
+
* reached (the duplicate key error, the legacy line break check) and the
|
|
34
|
+
* warnings, which nothing listened to, are gone too. The parsing code itself
|
|
35
|
+
* is otherwise unchanged. It is kept in one file
|
|
33
36
|
* because js-yaml's ES module wraps each of its files in an init function a
|
|
34
37
|
* bundler cannot shake, so importing it costs the whole library.
|
|
35
38
|
*/
|
|
@@ -214,7 +217,6 @@ const CHOMPING_KEEP = 3
|
|
|
214
217
|
|
|
215
218
|
// eslint-disable-next-line no-control-regex
|
|
216
219
|
const PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/
|
|
217
|
-
const PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/
|
|
218
220
|
// eslint-disable-next-line no-useless-escape
|
|
219
221
|
const PATTERN_FLOW_INDICATORS = /[,\[\]{}]/
|
|
220
222
|
// eslint-disable-next-line no-useless-escape
|
|
@@ -338,12 +340,8 @@ for (let i = 0; i < 256; i++) {
|
|
|
338
340
|
function State (input, types) {
|
|
339
341
|
this.input = input
|
|
340
342
|
|
|
341
|
-
this.filename = null
|
|
342
343
|
this.implicitTypes = types.implicit
|
|
343
344
|
this.typeMap = compileTypes(types.implicit, types.explicit)
|
|
344
|
-
// json mode: a duplicate mapping key takes the last value
|
|
345
|
-
this.json = true
|
|
346
|
-
this.legacy = false
|
|
347
345
|
this.maxDepth = 100
|
|
348
346
|
this.maxTotalMergeKeys = 10000
|
|
349
347
|
|
|
@@ -364,7 +362,6 @@ function State (input, types) {
|
|
|
364
362
|
|
|
365
363
|
/*
|
|
366
364
|
this.version;
|
|
367
|
-
this.checkLineBreaks;
|
|
368
365
|
this.tagMap;
|
|
369
366
|
this.anchorMap;
|
|
370
367
|
this.tag;
|
|
@@ -375,7 +372,7 @@ function State (input, types) {
|
|
|
375
372
|
|
|
376
373
|
function generateError (state, message) {
|
|
377
374
|
const mark = {
|
|
378
|
-
name:
|
|
375
|
+
name: null,
|
|
379
376
|
buffer: state.input.slice(0, -1), // omit trailing \0
|
|
380
377
|
position: state.position,
|
|
381
378
|
line: state.line,
|
|
@@ -389,8 +386,6 @@ function throwError (state, message) {
|
|
|
389
386
|
throw generateError(state, message)
|
|
390
387
|
}
|
|
391
388
|
|
|
392
|
-
function throwWarning () {}
|
|
393
|
-
|
|
394
389
|
function storeAnchor (state, name, value) {
|
|
395
390
|
const transactions = state.anchorMapTransactions
|
|
396
391
|
|
|
@@ -489,18 +484,12 @@ const directiveHandlers = {
|
|
|
489
484
|
}
|
|
490
485
|
|
|
491
486
|
const major = parseInt(match[1], 10)
|
|
492
|
-
const minor = parseInt(match[2], 10)
|
|
493
487
|
|
|
494
488
|
if (major !== 1) {
|
|
495
489
|
throwError(state, 'unacceptable YAML version of the document')
|
|
496
490
|
}
|
|
497
491
|
|
|
498
492
|
state.version = args[0]
|
|
499
|
-
state.checkLineBreaks = (minor < 2)
|
|
500
|
-
|
|
501
|
-
if (minor !== 1 && minor !== 2) {
|
|
502
|
-
throwWarning(state, 'unsupported YAML version of the document')
|
|
503
|
-
}
|
|
504
493
|
},
|
|
505
494
|
|
|
506
495
|
TAG: function handleTagDirective (state, name, args) {
|
|
@@ -585,8 +574,7 @@ function mergeMappings (state, destination, source, overridableKeys) {
|
|
|
585
574
|
}
|
|
586
575
|
}
|
|
587
576
|
|
|
588
|
-
function storeMappingPair (state, _result, overridableKeys, keyTag, keyNode, valueNode
|
|
589
|
-
startLine, startLineStart, startPos) {
|
|
577
|
+
function storeMappingPair (state, _result, overridableKeys, keyTag, keyNode, valueNode) {
|
|
590
578
|
// The output is a plain object here, so keys can only be strings.
|
|
591
579
|
// We need to convert keyNode to a string, but doing so can hang the process
|
|
592
580
|
// (deeply nested arrays that explode exponentially using aliases).
|
|
@@ -630,15 +618,7 @@ function storeMappingPair (state, _result, overridableKeys, keyTag, keyNode, val
|
|
|
630
618
|
mergeMappings(state, _result, valueNode, overridableKeys)
|
|
631
619
|
}
|
|
632
620
|
} else {
|
|
633
|
-
|
|
634
|
-
!_hasOwnProperty.call(overridableKeys, keyNode) &&
|
|
635
|
-
_hasOwnProperty.call(_result, keyNode)) {
|
|
636
|
-
state.line = startLine || state.line
|
|
637
|
-
state.lineStart = startLineStart || state.lineStart
|
|
638
|
-
state.position = startPos || state.position
|
|
639
|
-
throwError(state, 'duplicated mapping key')
|
|
640
|
-
}
|
|
641
|
-
|
|
621
|
+
// json mode: a repeated key takes the last value.
|
|
642
622
|
setProperty(_result, keyNode, valueNode)
|
|
643
623
|
delete overridableKeys[keyNode]
|
|
644
624
|
}
|
|
@@ -699,10 +679,6 @@ function skipSeparationSpace (state, allowComments, checkIndent) {
|
|
|
699
679
|
}
|
|
700
680
|
}
|
|
701
681
|
|
|
702
|
-
if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
|
|
703
|
-
throwWarning(state, 'deficient indentation')
|
|
704
|
-
}
|
|
705
|
-
|
|
706
682
|
return lineBreaks
|
|
707
683
|
}
|
|
708
684
|
|
|
@@ -956,8 +932,6 @@ function readDoubleQuotedScalar (state, nodeIndent) {
|
|
|
956
932
|
function readFlowCollection (state, nodeIndent) {
|
|
957
933
|
let readNext = true
|
|
958
934
|
let _line
|
|
959
|
-
let _lineStart
|
|
960
|
-
let _pos
|
|
961
935
|
const _tag = state.tag
|
|
962
936
|
let _result
|
|
963
937
|
const _anchor = state.anchor
|
|
@@ -1023,8 +997,6 @@ function readFlowCollection (state, nodeIndent) {
|
|
|
1023
997
|
}
|
|
1024
998
|
|
|
1025
999
|
_line = state.line // Save the current line.
|
|
1026
|
-
_lineStart = state.lineStart
|
|
1027
|
-
_pos = state.position
|
|
1028
1000
|
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true)
|
|
1029
1001
|
keyTag = state.tag
|
|
1030
1002
|
keyNode = state.result
|
|
@@ -1041,9 +1013,9 @@ function readFlowCollection (state, nodeIndent) {
|
|
|
1041
1013
|
}
|
|
1042
1014
|
|
|
1043
1015
|
if (isMapping) {
|
|
1044
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode
|
|
1016
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode)
|
|
1045
1017
|
} else if (isPair) {
|
|
1046
|
-
_result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode
|
|
1018
|
+
_result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode))
|
|
1047
1019
|
} else {
|
|
1048
1020
|
_result.push(keyNode)
|
|
1049
1021
|
}
|
|
@@ -1274,9 +1246,6 @@ function readBlockSequence (state, nodeIndent) {
|
|
|
1274
1246
|
|
|
1275
1247
|
function readBlockMapping (state, nodeIndent, flowIndent) {
|
|
1276
1248
|
let allowCompact
|
|
1277
|
-
let _keyLine
|
|
1278
|
-
let _keyLineStart
|
|
1279
|
-
let _keyPos
|
|
1280
1249
|
const _tag = state.tag
|
|
1281
1250
|
const _anchor = state.anchor
|
|
1282
1251
|
const _result = {}
|
|
@@ -1313,7 +1282,7 @@ function readBlockMapping (state, nodeIndent, flowIndent) {
|
|
|
1313
1282
|
if ((ch === 0x3F/* ? */ || ch === 0x3A/* : */) && isWsOrEol(following)) {
|
|
1314
1283
|
if (ch === 0x3F/* ? */) {
|
|
1315
1284
|
if (atExplicitKey) {
|
|
1316
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null
|
|
1285
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null)
|
|
1317
1286
|
keyTag = keyNode = valueNode = null
|
|
1318
1287
|
}
|
|
1319
1288
|
|
|
@@ -1335,10 +1304,6 @@ function readBlockMapping (state, nodeIndent, flowIndent) {
|
|
|
1335
1304
|
// Implicit notation case. Flow-style node as the key first, then ":", and the value.
|
|
1336
1305
|
//
|
|
1337
1306
|
} else {
|
|
1338
|
-
_keyLine = state.line
|
|
1339
|
-
_keyLineStart = state.lineStart
|
|
1340
|
-
_keyPos = state.position
|
|
1341
|
-
|
|
1342
1307
|
if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
|
|
1343
1308
|
// Neither implicit nor explicit notation.
|
|
1344
1309
|
// Reading is done. Go to the epilogue.
|
|
@@ -1360,7 +1325,7 @@ function readBlockMapping (state, nodeIndent, flowIndent) {
|
|
|
1360
1325
|
}
|
|
1361
1326
|
|
|
1362
1327
|
if (atExplicitKey) {
|
|
1363
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null
|
|
1328
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null)
|
|
1364
1329
|
keyTag = keyNode = valueNode = null
|
|
1365
1330
|
}
|
|
1366
1331
|
|
|
@@ -1389,12 +1354,6 @@ function readBlockMapping (state, nodeIndent, flowIndent) {
|
|
|
1389
1354
|
// Common reading code for both explicit and implicit notations.
|
|
1390
1355
|
//
|
|
1391
1356
|
if (state.line === _line || state.lineIndent > nodeIndent) {
|
|
1392
|
-
if (atExplicitKey) {
|
|
1393
|
-
_keyLine = state.line
|
|
1394
|
-
_keyLineStart = state.lineStart
|
|
1395
|
-
_keyPos = state.position
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
1357
|
if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
|
|
1399
1358
|
if (atExplicitKey) {
|
|
1400
1359
|
keyNode = state.result
|
|
@@ -1404,7 +1363,7 @@ function readBlockMapping (state, nodeIndent, flowIndent) {
|
|
|
1404
1363
|
}
|
|
1405
1364
|
|
|
1406
1365
|
if (!atExplicitKey) {
|
|
1407
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode
|
|
1366
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode)
|
|
1408
1367
|
keyTag = keyNode = valueNode = null
|
|
1409
1368
|
}
|
|
1410
1369
|
|
|
@@ -1425,7 +1384,7 @@ function readBlockMapping (state, nodeIndent, flowIndent) {
|
|
|
1425
1384
|
|
|
1426
1385
|
// Special case: last mapping's node contains only the key in explicit notation.
|
|
1427
1386
|
if (atExplicitKey) {
|
|
1428
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null
|
|
1387
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null)
|
|
1429
1388
|
}
|
|
1430
1389
|
|
|
1431
1390
|
// Expose the resulting mapping.
|
|
@@ -1807,12 +1766,10 @@ function composeNode (state, parentIndent, nodeContext, allowToSeek, allowCompac
|
|
|
1807
1766
|
}
|
|
1808
1767
|
|
|
1809
1768
|
function readDocument (state) {
|
|
1810
|
-
const documentStart = state.position
|
|
1811
1769
|
let hasDirectives = false
|
|
1812
1770
|
let ch
|
|
1813
1771
|
|
|
1814
1772
|
state.version = null
|
|
1815
|
-
state.checkLineBreaks = state.legacy
|
|
1816
1773
|
state.tagMap = Object.create(null)
|
|
1817
1774
|
state.anchorMap = Object.create(null)
|
|
1818
1775
|
|
|
@@ -1864,10 +1821,9 @@ function readDocument (state) {
|
|
|
1864
1821
|
|
|
1865
1822
|
if (ch !== 0) readLineBreak(state)
|
|
1866
1823
|
|
|
1824
|
+
// An unknown directive is ignored.
|
|
1867
1825
|
if (_hasOwnProperty.call(directiveHandlers, directiveName)) {
|
|
1868
1826
|
directiveHandlers[directiveName](state, directiveName, directiveArgs)
|
|
1869
|
-
} else {
|
|
1870
|
-
throwWarning(state, 'unknown document directive "' + directiveName + '"')
|
|
1871
1827
|
}
|
|
1872
1828
|
}
|
|
1873
1829
|
|
|
@@ -1886,11 +1842,6 @@ function readDocument (state) {
|
|
|
1886
1842
|
composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true)
|
|
1887
1843
|
skipSeparationSpace(state, true, -1)
|
|
1888
1844
|
|
|
1889
|
-
if (state.checkLineBreaks &&
|
|
1890
|
-
PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
|
|
1891
|
-
throwWarning(state, 'non-ASCII line breaks are interpreted as content')
|
|
1892
|
-
}
|
|
1893
|
-
|
|
1894
1845
|
state.documents.push(state.result)
|
|
1895
1846
|
|
|
1896
1847
|
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|