jsii 5.9.44-dev.0 → 6.0.0-dev.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/README.md +73 -289
- package/lib/assembler.js +95 -46
- package/lib/assembler.js.map +1 -1
- package/lib/case.js +13 -10
- package/lib/case.js.map +1 -1
- package/lib/common/find-utils.js +35 -2
- package/lib/common/find-utils.js.map +1 -1
- package/lib/common/symbol-id.js +39 -7
- package/lib/common/symbol-id.js.map +1 -1
- package/lib/compiler.js +51 -8
- package/lib/compiler.js.map +1 -1
- package/lib/directives.js +48 -16
- package/lib/directives.js.map +1 -1
- package/lib/docs.js +36 -4
- package/lib/docs.js.map +1 -1
- package/lib/helpers.js +38 -4
- package/lib/helpers.js.map +1 -1
- package/lib/jsii-diagnostic.js +524 -497
- package/lib/jsii-diagnostic.js.map +1 -1
- package/lib/literate.js +35 -2
- package/lib/literate.js.map +1 -1
- package/lib/main.js +40 -7
- package/lib/main.js.map +1 -1
- package/lib/project-info.d.ts +1 -1
- package/lib/project-info.js +41 -11
- package/lib/project-info.js.map +1 -1
- package/lib/support.js +7 -4
- package/lib/support.js.map +1 -1
- package/lib/transforms/deprecated-remover.js +65 -23
- package/lib/transforms/deprecated-remover.js.map +1 -1
- package/lib/transforms/deprecation-warnings.js +50 -10
- package/lib/transforms/deprecation-warnings.js.map +1 -1
- package/lib/transforms/runtime-info.js +36 -2
- package/lib/transforms/runtime-info.js.map +1 -1
- package/lib/tsconfig/compiler-options.js +40 -5
- package/lib/tsconfig/compiler-options.js.map +1 -1
- package/lib/tsconfig/rulesets/configurable-options.js +10 -1
- package/lib/tsconfig/rulesets/configurable-options.js.map +1 -1
- package/lib/tsconfig/rulesets/deprecated-options.js +16 -1
- package/lib/tsconfig/rulesets/deprecated-options.js.map +1 -1
- package/lib/tsconfig/rulesets/generated.public.js +7 -2
- package/lib/tsconfig/rulesets/generated.public.js.map +1 -1
- package/lib/tsconfig/rulesets/jsii-configured-options.js +0 -1
- package/lib/tsconfig/rulesets/jsii-configured-options.js.map +1 -1
- package/lib/tsconfig/rulesets/minimal.public.js +4 -1
- package/lib/tsconfig/rulesets/minimal.public.js.map +1 -1
- package/lib/tsconfig/rulesets/strict.public.js +12 -9
- package/lib/tsconfig/rulesets/strict.public.js.map +1 -1
- package/lib/tsconfig/tsconfig-validator.js +9 -3
- package/lib/tsconfig/tsconfig-validator.js.map +1 -1
- package/lib/tsconfig/validator.d.ts +5 -0
- package/lib/tsconfig/validator.js +26 -16
- package/lib/tsconfig/validator.js.map +1 -1
- package/lib/type-analysis.js +39 -3
- package/lib/type-analysis.js.map +1 -1
- package/lib/type-reference.js +34 -1
- package/lib/type-reference.js.map +1 -1
- package/lib/type-tracker.js +35 -4
- package/lib/type-tracker.js.map +1 -1
- package/lib/type-visitor.js +34 -1
- package/lib/type-visitor.js.map +1 -1
- package/lib/utils.js +37 -2
- package/lib/utils.js.map +1 -1
- package/lib/validator.js +49 -11
- package/lib/validator.js.map +1 -1
- package/lib/version.d.ts +3 -3
- package/lib/version.js +2 -2
- package/lib/version.js.map +1 -1
- package/lib/warnings.js +34 -1
- package/lib/warnings.js.map +1 -1
- package/package.json +6 -8
- package/releases.json +3 -2
|
@@ -13,7 +13,6 @@ jsiiConfiguredOptions.shouldPass('inlineSourceMap', validator_1.Match.ANY);
|
|
|
13
13
|
jsiiConfiguredOptions.shouldPass('inlineSources', validator_1.Match.ANY);
|
|
14
14
|
jsiiConfiguredOptions.shouldPass('sourceMap', validator_1.Match.ANY);
|
|
15
15
|
jsiiConfiguredOptions.shouldPass('types', validator_1.Match.ANY);
|
|
16
|
-
jsiiConfiguredOptions.shouldPass('baseUrl', validator_1.Match.ANY);
|
|
17
16
|
jsiiConfiguredOptions.shouldPass('paths', validator_1.Match.ANY);
|
|
18
17
|
jsiiConfiguredOptions.shouldPass('composite', validator_1.Match.ANY); // configured via projectReferences
|
|
19
18
|
jsiiConfiguredOptions.shouldPass('tsBuildInfoFile', validator_1.Match.ANY);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsii-configured-options.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/jsii-configured-options.ts"],"names":[],"mappings":";;AAAA,4CAA8C;AAE9C,mGAAmG;AACnG,qEAAqE;AACrE,gCAAgC;AAChC,MAAM,qBAAqB,GAAG,IAAI,mBAAO,EAAE,CAAC;AAC5C,qBAAqB,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACtD,qBAAqB,CAAC,UAAU,CAAC,SAAS,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACvD,qBAAqB,CAAC,UAAU,CAAC,kCAAkC,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAChF,qBAAqB,CAAC,UAAU,CAAC,gBAAgB,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAC9D,qBAAqB,CAAC,UAAU,CAAC,iBAAiB,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAC/D,qBAAqB,CAAC,UAAU,CAAC,eAAe,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAC7D,qBAAqB,CAAC,UAAU,CAAC,WAAW,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACzD,qBAAqB,CAAC,UAAU,CAAC,OAAO,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACrD,qBAAqB,CAAC,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"jsii-configured-options.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/jsii-configured-options.ts"],"names":[],"mappings":";;AAAA,4CAA8C;AAE9C,mGAAmG;AACnG,qEAAqE;AACrE,gCAAgC;AAChC,MAAM,qBAAqB,GAAG,IAAI,mBAAO,EAAE,CAAC;AAC5C,qBAAqB,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACtD,qBAAqB,CAAC,UAAU,CAAC,SAAS,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACvD,qBAAqB,CAAC,UAAU,CAAC,kCAAkC,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAChF,qBAAqB,CAAC,UAAU,CAAC,gBAAgB,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAC9D,qBAAqB,CAAC,UAAU,CAAC,iBAAiB,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAC/D,qBAAqB,CAAC,UAAU,CAAC,eAAe,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAC7D,qBAAqB,CAAC,UAAU,CAAC,WAAW,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACzD,qBAAqB,CAAC,UAAU,CAAC,OAAO,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACrD,qBAAqB,CAAC,UAAU,CAAC,OAAO,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACrD,qBAAqB,CAAC,UAAU,CAAC,WAAW,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC,CAAC,mCAAmC;AAC7F,qBAAqB,CAAC,UAAU,CAAC,iBAAiB,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAE/D,kBAAe,qBAAqB,CAAC","sourcesContent":["import { Match, RuleSet } from '../validator';\n\n// A rule set defining all compilerOptions that are configurable via the jsii field in package.json\n// This is an internal rule set, that may be used by other rule sets.\n// We accept all value for these\nconst jsiiConfiguredOptions = new RuleSet();\njsiiConfiguredOptions.shouldPass('outDir', Match.ANY);\njsiiConfiguredOptions.shouldPass('rootDir', Match.ANY);\njsiiConfiguredOptions.shouldPass('forceConsistentCasingInFileNames', Match.ANY);\njsiiConfiguredOptions.shouldPass('declarationMap', Match.ANY);\njsiiConfiguredOptions.shouldPass('inlineSourceMap', Match.ANY);\njsiiConfiguredOptions.shouldPass('inlineSources', Match.ANY);\njsiiConfiguredOptions.shouldPass('sourceMap', Match.ANY);\njsiiConfiguredOptions.shouldPass('types', Match.ANY);\njsiiConfiguredOptions.shouldPass('paths', Match.ANY);\njsiiConfiguredOptions.shouldPass('composite', Match.ANY); // configured via projectReferences\njsiiConfiguredOptions.shouldPass('tsBuildInfoFile', Match.ANY);\n\nexport default jsiiConfiguredOptions;\n"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const incompatible_options_1 = require("./incompatible-options");
|
|
6
|
+
const incompatible_options_1 = __importDefault(require("./incompatible-options"));
|
|
4
7
|
const validator_1 = require("../validator");
|
|
5
8
|
// The public rule set used for the "minimal" tsconfig validation setting
|
|
6
9
|
// To goal of this rule set is to only prevent obvious misconfigurations,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minimal.public.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/minimal.public.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"minimal.public.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/minimal.public.ts"],"names":[],"mappings":";;;;;AAAA,kFAAyD;AACzD,4CAAuC;AAEvC,yEAAyE;AACzE,yEAAyE;AACzE,gDAAgD;AAChD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAC9B,OAAO,CAAC,MAAM,CAAC,8BAAmB,CAAC,CAAC;AAEpC,kBAAe,OAAO,CAAC","sourcesContent":["import incompatibleOptions from './incompatible-options';\nimport { RuleSet } from '../validator';\n\n// The public rule set used for the \"minimal\" tsconfig validation setting\n// To goal of this rule set is to only prevent obvious misconfigurations,\n// while leaving everything else up to the user.\nconst minimal = new RuleSet();\nminimal.import(incompatibleOptions);\n\nexport default minimal;\n"]}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const configurable_options_1 = require("./configurable-options");
|
|
4
|
-
const deprecated_options_1 = require("./deprecated-options");
|
|
5
|
-
const incompatible_options_1 = require("./incompatible-options");
|
|
6
|
-
const strict_family_options_1 = require("./strict-family-options");
|
|
6
|
+
const configurable_options_1 = __importDefault(require("./configurable-options"));
|
|
7
|
+
const deprecated_options_1 = __importDefault(require("./deprecated-options"));
|
|
8
|
+
const incompatible_options_1 = __importDefault(require("./incompatible-options"));
|
|
9
|
+
const strict_family_options_1 = __importDefault(require("./strict-family-options"));
|
|
7
10
|
const validator_1 = require("../validator");
|
|
8
11
|
// The public rule set used for the "strict" tsconfig validation setting.
|
|
9
12
|
// The goal of this rule set is to ensure a tsconfig that is following best practices for jsii.
|
|
@@ -19,15 +22,15 @@ strict.import(incompatible_options_1.default);
|
|
|
19
22
|
// strict family options
|
|
20
23
|
strict.import(strict_family_options_1.default);
|
|
21
24
|
// Best practice rules
|
|
22
|
-
strict.shouldPass('target', validator_1.Match.
|
|
23
|
-
strict.shouldPass('lib', validator_1.Match.arrEq(['es2022'])); // node18
|
|
24
|
-
strict.shouldPass('module', validator_1.Match.oneOf('node16', 'commonjs'));
|
|
25
|
-
strict.shouldPass('moduleResolution', validator_1.Match.optional(validator_1.Match.oneOf('
|
|
26
|
-
strict.shouldPass('esModuleInterop', validator_1.Match.TRUE);
|
|
25
|
+
strict.shouldPass('target', validator_1.Match.oneOf('es2022', 'es2023', 'esnext')); // node18+
|
|
26
|
+
strict.shouldPass('lib', validator_1.Match.anyOf(validator_1.Match.arrEq(['es2022']), validator_1.Match.arrEq(['es2023']), validator_1.Match.arrEq(['esnext']))); // node18+
|
|
27
|
+
strict.shouldPass('module', validator_1.Match.oneOf('node16', 'node18', 'node20', 'nodenext', 'commonjs'));
|
|
28
|
+
strict.shouldPass('moduleResolution', validator_1.Match.optional(validator_1.Match.oneOf('node16', 'nodenext', 'bundler')));
|
|
27
29
|
strict.shouldPass('skipLibCheck', validator_1.Match.TRUE);
|
|
28
30
|
strict.shouldPass('stripInternal', validator_1.Match.optional(validator_1.Match.FALSE));
|
|
29
31
|
strict.shouldPass('noEmitOnError', validator_1.Match.TRUE);
|
|
30
32
|
strict.shouldPass('declaration', validator_1.Match.TRUE);
|
|
33
|
+
strict.shouldPass('noUncheckedSideEffectImports', validator_1.Match.optional(validator_1.Match.TRUE));
|
|
31
34
|
// Deprecated ts options that should not be used with jsii
|
|
32
35
|
strict.import(deprecated_options_1.default);
|
|
33
36
|
exports.default = strict;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strict.public.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/strict.public.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"strict.public.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/strict.public.ts"],"names":[],"mappings":";;;;;AAAA,kFAAyD;AACzD,8EAAqD;AACrD,kFAAyD;AACzD,oFAA0D;AAC1D,4CAAwD;AAExD,yEAAyE;AACzE,+FAA+F;AAC/F,8HAA8H;AAC9H,0DAA0D;AAC1D,MAAM,MAAM,GAAG,IAAI,mBAAO,CAAC;IACzB,gBAAgB,EAAE,oBAAQ,CAAC,IAAI;CAChC,CAAC,CAAC;AAEH,2CAA2C;AAC3C,MAAM,CAAC,MAAM,CAAC,8BAAmB,CAAC,CAAC;AAEnC,sDAAsD;AACtD,MAAM,CAAC,MAAM,CAAC,8BAAmB,CAAC,CAAC;AAEnC,wBAAwB;AACxB,MAAM,CAAC,MAAM,CAAC,+BAAmB,CAAC,CAAC;AAEnC,sBAAsB;AACtB,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU;AAClF,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,iBAAK,CAAC,KAAK,CAAC,iBAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,iBAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,iBAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU;AAC5H,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;AAC/F,MAAM,CAAC,UAAU,CAAC,kBAAkB,EAAE,iBAAK,CAAC,QAAQ,CAAC,iBAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;AACpG,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,iBAAK,CAAC,IAAI,CAAC,CAAC;AAC9C,MAAM,CAAC,UAAU,CAAC,eAAe,EAAE,iBAAK,CAAC,QAAQ,CAAC,iBAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AAChE,MAAM,CAAC,UAAU,CAAC,eAAe,EAAE,iBAAK,CAAC,IAAI,CAAC,CAAC;AAC/C,MAAM,CAAC,UAAU,CAAC,aAAa,EAAE,iBAAK,CAAC,IAAI,CAAC,CAAC;AAC7C,MAAM,CAAC,UAAU,CAAC,8BAA8B,EAAE,iBAAK,CAAC,QAAQ,CAAC,iBAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAE9E,0DAA0D;AAC1D,MAAM,CAAC,MAAM,CAAC,4BAAiB,CAAC,CAAC;AAEjC,kBAAe,MAAM,CAAC","sourcesContent":["import configurableOptions from './configurable-options';\nimport deprecatedOptions from './deprecated-options';\nimport incompatibleOptions from './incompatible-options';\nimport strictFamilyOptions from './strict-family-options';\nimport { Match, RuleSet, RuleType } from '../validator';\n\n// The public rule set used for the \"strict\" tsconfig validation setting.\n// The goal of this rule set is to ensure a tsconfig that is following best practices for jsii.\n// In practice, this is a combination of known incompatible options, known configurable options and additional best practices.\n// The rule set also explicitly disallows unknown options.\nconst strict = new RuleSet({\n unexpectedFields: RuleType.FAIL,\n});\n\n// import all options that are configurable\nstrict.import(configurableOptions);\n\n// import all options that are definitely incompatible\nstrict.import(incompatibleOptions);\n\n// strict family options\nstrict.import(strictFamilyOptions);\n\n// Best practice rules\nstrict.shouldPass('target', Match.oneOf('es2022', 'es2023', 'esnext')); // node18+\nstrict.shouldPass('lib', Match.anyOf(Match.arrEq(['es2022']), Match.arrEq(['es2023']), Match.arrEq(['esnext']))); // node18+\nstrict.shouldPass('module', Match.oneOf('node16', 'node18', 'node20', 'nodenext', 'commonjs'));\nstrict.shouldPass('moduleResolution', Match.optional(Match.oneOf('node16', 'nodenext', 'bundler')));\nstrict.shouldPass('skipLibCheck', Match.TRUE);\nstrict.shouldPass('stripInternal', Match.optional(Match.FALSE));\nstrict.shouldPass('noEmitOnError', Match.TRUE);\nstrict.shouldPass('declaration', Match.TRUE);\nstrict.shouldPass('noUncheckedSideEffectImports', Match.optional(Match.TRUE));\n\n// Deprecated ts options that should not be used with jsii\nstrict.import(deprecatedOptions);\n\nexport default strict;\n"]}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.TypeScriptConfigValidator = void 0;
|
|
4
|
-
const generated_public_1 = require("./rulesets/generated.public");
|
|
5
|
-
const minimal_public_1 = require("./rulesets/minimal.public");
|
|
6
|
-
const strict_public_1 = require("./rulesets/strict.public");
|
|
7
|
+
const generated_public_1 = __importDefault(require("./rulesets/generated.public"));
|
|
8
|
+
const minimal_public_1 = __importDefault(require("./rulesets/minimal.public"));
|
|
9
|
+
const strict_public_1 = __importDefault(require("./rulesets/strict.public"));
|
|
7
10
|
const validator_1 = require("./validator");
|
|
8
11
|
const RuleSets = {
|
|
9
12
|
generated: generated_public_1.default,
|
|
@@ -12,6 +15,9 @@ const RuleSets = {
|
|
|
12
15
|
off: new validator_1.RuleSet(),
|
|
13
16
|
};
|
|
14
17
|
class TypeScriptConfigValidator {
|
|
18
|
+
ruleSet;
|
|
19
|
+
validator;
|
|
20
|
+
compilerOptions;
|
|
15
21
|
constructor(ruleSet) {
|
|
16
22
|
this.ruleSet = ruleSet;
|
|
17
23
|
const topLevelRules = new validator_1.RuleSet({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsconfig-validator.js","sourceRoot":"","sources":["../../src/tsconfig/tsconfig-validator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tsconfig-validator.js","sourceRoot":"","sources":["../../src/tsconfig/tsconfig-validator.ts"],"names":[],"mappings":";;;;;;AACA,mFAAoD;AACpD,+EAAgD;AAChD,6EAA8C;AAC9C,2CAAwE;AAExE,MAAM,QAAQ,GAEV;IACF,SAAS,EAAT,0BAAS;IACT,MAAM,EAAN,uBAAM;IACN,OAAO,EAAP,wBAAO;IACP,GAAG,EAAE,IAAI,mBAAO,EAAE;CACnB,CAAC;AAEF,MAAa,yBAAyB;IAIV;IAHT,SAAS,CAAkB;IAC3B,eAAe,CAAkB;IAElD,YAA0B,OAA0C;QAA1C,YAAO,GAAP,OAAO,CAAmC;QAClE,MAAM,aAAa,GAAG,IAAI,mBAAO,CAAC;YAChC,gBAAgB,EAAE,oBAAQ,CAAC,IAAI;SAChC,CAAC,CAAC;QACH,aAAa,CAAC,UAAU,CAAC,OAAO,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;QAC7C,aAAa,CAAC,UAAU,CAAC,SAAS,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;QAC/C,aAAa,CAAC,UAAU,CAAC,SAAS,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;QAC/C,aAAa,CAAC,UAAU,CAAC,SAAS,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;QAC/C,aAAa,CAAC,UAAU,CAAC,YAAY,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;QAClD,aAAa,CAAC,UAAU,CAAC,cAAc,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;QACpD,aAAa,CAAC,UAAU,CAAC,iBAAiB,EAAE,iBAAK,CAAC,OAAO,CAAC,CAAC;QAE3D,IAAI,CAAC,eAAe,GAAG,IAAI,2BAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC;QACjF,aAAa,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAC,eAAe,EAAE,EAAE;YAC9D,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;YAC/C,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,GAAG,IAAI,2BAAe,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IAClE,CAAC;IAED;;;;;;OAMG;IACI,QAAQ,CAAC,QAA0B;QACxC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;CACF;AAnCD,8DAmCC","sourcesContent":["import { TypeScriptConfig, TypeScriptConfigValidationRuleSet } from '.';\nimport generated from './rulesets/generated.public';\nimport minimal from './rulesets/minimal.public';\nimport strict from './rulesets/strict.public';\nimport { Match, ObjectValidator, RuleSet, RuleType } from './validator';\n\nconst RuleSets: {\n [name in TypeScriptConfigValidationRuleSet]: RuleSet;\n} = {\n generated,\n strict,\n minimal,\n off: new RuleSet(),\n};\n\nexport class TypeScriptConfigValidator {\n private readonly validator: ObjectValidator;\n private readonly compilerOptions: ObjectValidator;\n\n public constructor(public ruleSet: TypeScriptConfigValidationRuleSet) {\n const topLevelRules = new RuleSet({\n unexpectedFields: RuleType.PASS,\n });\n topLevelRules.shouldPass('files', Match.ANY);\n topLevelRules.shouldPass('extends', Match.ANY);\n topLevelRules.shouldPass('include', Match.ANY);\n topLevelRules.shouldPass('exclude', Match.ANY);\n topLevelRules.shouldPass('references', Match.ANY);\n topLevelRules.shouldPass('watchOptions', Match.ANY);\n topLevelRules.shouldPass('typeAcquisition', Match.MISSING);\n\n this.compilerOptions = new ObjectValidator(RuleSets[ruleSet], 'compilerOptions');\n topLevelRules.shouldPass('compilerOptions', (compilerOptions) => {\n this.compilerOptions.validate(compilerOptions);\n return true;\n });\n\n this.validator = new ObjectValidator(topLevelRules, 'tsconfig');\n }\n\n /**\n * Validated the provided config against the set of rules.\n *\n * @throws when the config is invalid\n *\n * @param tsconfig the tsconfig to be validated, this MUST be a tsconfig as a user would have written it in tsconfig.\n */\n public validate(tsconfig: TypeScriptConfig) {\n this.validator.validate(tsconfig);\n }\n}\n"]}
|
|
@@ -99,6 +99,11 @@ export declare class Match {
|
|
|
99
99
|
* Value is optional, but if present should match
|
|
100
100
|
*/
|
|
101
101
|
static optional(matcher: Matcher): Matcher;
|
|
102
|
+
/**
|
|
103
|
+
* Value must match at least one of the provided matchers.
|
|
104
|
+
* All matchers are evaluated (no short-circuit) so their hints are collected.
|
|
105
|
+
*/
|
|
106
|
+
static anyOf(...matchers: Matcher[]): Matcher;
|
|
102
107
|
/**
|
|
103
108
|
* Value must be one of the allowed options
|
|
104
109
|
*/
|
|
@@ -7,6 +7,8 @@ var RuleType;
|
|
|
7
7
|
RuleType[RuleType["FAIL"] = 1] = "FAIL";
|
|
8
8
|
})(RuleType || (exports.RuleType = RuleType = {}));
|
|
9
9
|
class RuleSet {
|
|
10
|
+
options;
|
|
11
|
+
_rules = [];
|
|
10
12
|
get rules() {
|
|
11
13
|
return this._rules;
|
|
12
14
|
}
|
|
@@ -57,7 +59,6 @@ class RuleSet {
|
|
|
57
59
|
unexpectedFields: RuleType.PASS,
|
|
58
60
|
}) {
|
|
59
61
|
this.options = options;
|
|
60
|
-
this._rules = [];
|
|
61
62
|
}
|
|
62
63
|
/**
|
|
63
64
|
* Requires the matcher to pass for the given field.
|
|
@@ -104,10 +105,9 @@ class RuleSet {
|
|
|
104
105
|
// run the matcher to record hints
|
|
105
106
|
rule.matcher(undefined, {
|
|
106
107
|
hints: (receivedHints) => {
|
|
107
|
-
var _a;
|
|
108
108
|
// if we have recorded hints, add them to the map
|
|
109
109
|
if (receivedHints) {
|
|
110
|
-
fieldHints[
|
|
110
|
+
fieldHints[rule.field] ??= [];
|
|
111
111
|
fieldHints[rule.field].push(...receivedHints);
|
|
112
112
|
}
|
|
113
113
|
},
|
|
@@ -161,6 +161,13 @@ class Match {
|
|
|
161
161
|
return matcher(value, options);
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Value must match at least one of the provided matchers.
|
|
166
|
+
* All matchers are evaluated (no short-circuit) so their hints are collected.
|
|
167
|
+
*/
|
|
168
|
+
static anyOf(...matchers) {
|
|
169
|
+
return (value, options) => matchers.map((m) => m(value, options)).some(Boolean);
|
|
170
|
+
}
|
|
164
171
|
/**
|
|
165
172
|
* Value must be one of the allowed options
|
|
166
173
|
*/
|
|
@@ -211,22 +218,23 @@ class Match {
|
|
|
211
218
|
return looseEqual(actual, expected);
|
|
212
219
|
}, (actual) => `Expected string ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`, [expected]);
|
|
213
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Allows any value
|
|
223
|
+
*/
|
|
224
|
+
static ANY = (_val, _options) => true;
|
|
225
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
226
|
+
static TRUE = Match.eq(true);
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
228
|
+
static FALSE = Match.eq(false);
|
|
229
|
+
/**
|
|
230
|
+
* Missing (undefined) value
|
|
231
|
+
*/
|
|
232
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
233
|
+
static MISSING = wrapMatcher((actual) => actual === null || actual === undefined, (actual) => `Expected value to be present, got ${JSON.stringify(actual)}`, [undefined, null]);
|
|
214
234
|
}
|
|
215
235
|
exports.Match = Match;
|
|
216
|
-
/**
|
|
217
|
-
* Allows any value
|
|
218
|
-
*/
|
|
219
|
-
Match.ANY = (_val, _options) => true;
|
|
220
|
-
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
221
|
-
Match.TRUE = Match.eq(true);
|
|
222
|
-
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
223
|
-
Match.FALSE = Match.eq(false);
|
|
224
|
-
/**
|
|
225
|
-
* Missing (undefined) value
|
|
226
|
-
*/
|
|
227
|
-
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
228
|
-
Match.MISSING = wrapMatcher((actual) => actual === null || actual === undefined, (actual) => `Expected value to be present, got ${JSON.stringify(actual)}`, [undefined, null]);
|
|
229
236
|
class ValidationError extends Error {
|
|
237
|
+
violations;
|
|
230
238
|
constructor(violations) {
|
|
231
239
|
// error message is a list of violations
|
|
232
240
|
super('Data is invalid:\n' + violations.map((v) => v.field + ': ' + v.message).join('\n'));
|
|
@@ -237,6 +245,8 @@ class ValidationError extends Error {
|
|
|
237
245
|
}
|
|
238
246
|
exports.ValidationError = ValidationError;
|
|
239
247
|
class ObjectValidator {
|
|
248
|
+
ruleSet;
|
|
249
|
+
dataName;
|
|
240
250
|
constructor(ruleSet, dataName = 'data') {
|
|
241
251
|
this.ruleSet = ruleSet;
|
|
242
252
|
this.dataName = dataName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/tsconfig/validator.ts"],"names":[],"mappings":";;;AA2BA,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,uCAAI,CAAA;IACJ,uCAAI,CAAA;AACN,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB;AAmBD,MAAa,OAAO;IAElB,IAAW,KAAK;QACd,OAAO,IAAI,CAAC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AAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,eAAe,CAAC,UAAU,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF;AAxED,0CAwEC","sourcesContent":["/**\n * A function that receives 3 arguments and validates if the provided value matches.\n * @param value The value to validate\n * @params options Additional options to influence the matcher behavior.\n * @returns true if the value matches\n */\ntype Matcher = (value: any, options?: MatcherOptions) => boolean;\n\ninterface MatcherOptions {\n /**\n * A function that will be called by the matcher with a a violation message.\n * This function is always called, regardless of the outcome of the matcher.\n * It is up to the caller of the matcher to decide if the message should be used or not.\n *\n * @param message The message describing the possible failure.\n */\n reporter?: (message: string) => void;\n /**\n * A function that might receive explicitly allowed values.\n * This can be used to generate synthetics values that would match the matcher.\n * It is not guaranteed that hints are received or that hints are complete.\n *\n * @param allowed The list values that a matcher offers as definitely allowed.\n */\n hints?: (allowed: any[]) => void;\n}\n\nexport enum RuleType {\n PASS,\n FAIL,\n}\n\nexport interface RuleSetOptions {\n /**\n * Defines the behavior for any encountered fields for which no rules are defined.\n * The default is to pass these fields without validation,\n * but this can also be set to fail any unexpected fields.\n *\n * @default RuleType.PASS\n */\n readonly unexpectedFields: RuleType;\n}\n\ninterface Rule {\n field: string;\n type: RuleType;\n matcher: Matcher;\n}\n\nexport class RuleSet {\n private _rules: Array<Rule> = [];\n public get rules(): Array<Rule> {\n return this._rules;\n }\n\n /**\n * Return all fields for which a rule exists\n */\n public get fields(): Array<string> {\n return [...new Set(this._rules.map((r) => r.field))];\n }\n\n /**\n * Return a list of fields that are allowed, or undefined if all are allowed.\n */\n public get allowedFields(): Array<string> | undefined {\n if (this.options.unexpectedFields === RuleType.FAIL) {\n return this.fields;\n }\n\n return undefined;\n }\n\n /**\n * Find all required fields by evaluating every rule in th set against undefined.\n * If the rule fails, the key must be required.\n *\n * @returns A list of keys that must be included or undefined\n */\n public get requiredFields(): Array<string> {\n const required: string[] = [];\n\n for (const rule of this._rules) {\n const key = rule.field;\n const matcherResult = rule.matcher(undefined);\n\n switch (rule.type) {\n case RuleType.PASS:\n if (!matcherResult) {\n required.push(key);\n }\n break;\n case RuleType.FAIL:\n if (matcherResult) {\n required.push(key);\n }\n break;\n default:\n continue;\n }\n }\n\n return required;\n }\n\n public constructor(\n public readonly options: RuleSetOptions = {\n unexpectedFields: RuleType.PASS,\n },\n ) {}\n\n /**\n * Requires the matcher to pass for the given field.\n * Otherwise a violation is detected.\n *\n * @param field The field the rule applies to\n * @param matcher The matcher function\n */\n public shouldPass(field: string, matcher: Matcher) {\n this._rules.push({ field, matcher, type: RuleType.PASS });\n }\n\n /**\n * Detects a violation if the matcher is matching for a certain field.\n *\n * @param field The field the rule applies to\n * @param matcher The matcher function\n */\n public shouldFail(field: string, matcher: Matcher) {\n this._rules.push({ field, matcher, type: RuleType.FAIL });\n }\n\n /**\n * Imports all rules from an other rule set.\n * Note that any options from the other rule set will be ignored.\n *\n * @param other The other rule set to import rules from.\n */\n public import(other: RuleSet) {\n this._rules.push(...other.rules);\n }\n\n /**\n * Records the field hints for the given rule set.\n * Hints are values that are guaranteed to pass the rule.\n * The list of hints is not guaranteed to be complete nor does it guarantee to return any values.\n * This can be used to create synthetic values for testing for error messages.\n *\n * @returns A record of fields and allowed values\n */\n public getFieldHints(): Record<string, any[]> {\n const fieldHints: Record<string, any[]> = {};\n\n for (const rule of this._rules) {\n // We are only interested in PASS rules here.\n // For FAILs we still don't know which values would pass.\n if (rule.type === RuleType.PASS) {\n // run the matcher to record hints\n rule.matcher(undefined, {\n hints: (receivedHints: any[]) => {\n // if we have recorded hints, add them to the map\n if (receivedHints) {\n fieldHints[rule.field] ??= [];\n fieldHints[rule.field].push(...receivedHints);\n }\n },\n });\n }\n }\n\n return fieldHints;\n }\n}\n\n/**\n * Helper to wrap a matcher with error reporting and hints\n */\nfunction wrapMatcher(matcher: Matcher, message: (actual: any) => string, allowed?: any[]): Matcher {\n return (value, options) => {\n options?.reporter?.(message(value));\n if (allowed) {\n options?.hints?.(allowed);\n }\n return matcher(value);\n };\n}\n\n/**\n * Helper to implement loose equality that is safe for any value\n * Needed because there are some values that are equal as object, but not with ==\n * There are also values that cannot be compared using == and will throw\n */\nfunction looseEqual(a: any, b: any): boolean {\n try {\n // if one of the values is an object (or array), but the other isn't - never consider them the same\n if ([typeof a, typeof b].filter((t) => t === 'object').length === 1) {\n return false;\n }\n // if both values are the same object\n // or if both values are loose equal\n return Object.is(a, b) || a == b;\n } catch {\n return false;\n }\n}\n\nexport class Match {\n /**\n * Value is optional, but if present should match\n */\n public static optional(matcher: Matcher): Matcher {\n return (value, options) => {\n if (value == null) {\n return true;\n }\n return matcher(value, options);\n };\n }\n\n /**\n * Value must be one of the allowed options\n */\n public static oneOf(...allowed: Array<string | number>): Matcher {\n return wrapMatcher(\n (actual) => allowed.includes(actual),\n (actual) => `Expected value to be one of ${JSON.stringify(allowed)}, got: ${JSON.stringify(actual)}`,\n allowed,\n );\n }\n\n /**\n * Value must be loosely equal to the expected value\n * Arrays are compared by elements\n */\n public static eq(expected: any): Matcher {\n return (actual, options) => {\n if (Array.isArray(expected)) {\n return Match.arrEq(expected)(actual, options);\n }\n\n options?.hints?.([expected]);\n options?.reporter?.(`Expected value ${JSON.stringify(expected)}, got: ${JSON.stringify(actual)}`);\n return looseEqual(actual, expected);\n };\n }\n\n /**\n * Value must be loosely equal to the expected value\n * Arrays are compared by elements\n */\n public static arrEq(expected: any[]): Matcher {\n return wrapMatcher(\n (actual) => {\n // if both are arrays and of the same length, compare elements\n // if one of them is not, or they are a different length,\n // skip comparing elements as the the equality check later will fail\n if (Array.isArray(expected) && Array.isArray(actual) && expected.length == actual.length) {\n // compare all elements with loose typing\n return expected.every((e) => actual.some((a) => looseEqual(a, e)));\n }\n\n // all other values and arrays of different shape\n return looseEqual(actual, expected);\n },\n (actual) => `Expected array matching ${JSON.stringify(expected)}, got: ${JSON.stringify(actual)}`,\n [expected],\n );\n }\n\n /**\n * Compare strings, allows setting cases sensitivity\n */\n public static strEq(expected: string, caseSensitive = false): Matcher {\n return wrapMatcher(\n (actual) => {\n // case insensitive\n if (!caseSensitive && typeof actual === 'string') {\n return looseEqual(expected.toLowerCase(), actual.toLowerCase());\n }\n\n // case sensitive\n return looseEqual(actual, expected);\n },\n (actual: any) => `Expected string ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`,\n [expected],\n );\n }\n\n /**\n * Allows any value\n */\n public static ANY: Matcher = (_val, _options) => true;\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n public static TRUE: Matcher = Match.eq(true);\n // eslint-disable-next-line @typescript-eslint/member-ordering\n public static FALSE: Matcher = Match.eq(false);\n\n /**\n * Missing (undefined) value\n */\n // eslint-disable-next-line @typescript-eslint/member-ordering\n public static MISSING = wrapMatcher(\n (actual) => actual === null || actual === undefined,\n (actual) => `Expected value to be present, got ${JSON.stringify(actual)}`,\n [undefined, null],\n );\n}\n\nexport interface Violation {\n field: string;\n message: string;\n}\n\nexport class ValidationError extends Error {\n constructor(public readonly violations: Violation[]) {\n // error message is a list of violations\n super('Data is invalid:\\n' + violations.map((v) => v.field + ': ' + v.message).join('\\n'));\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, ValidationError.prototype);\n }\n}\n\nexport class ObjectValidator {\n public constructor(public ruleSet: RuleSet, private readonly dataName: string = 'data') {}\n\n /**\n * Validated the provided data against the set of rules.\n *\n * @throws when the data is invalid\n *\n * @param data the data to be validated\n */\n public validate(data: { [field: string]: any }) {\n // make sure data is an object\n if (!(typeof data === 'object' && !Array.isArray(data) && data !== null)) {\n throw new ValidationError([\n { field: this.dataName, message: 'Provided data must be an object, got: ' + JSON.stringify(data) },\n ]);\n }\n\n const checkedFields = new Set();\n const violations: Violation[] = [];\n\n // first check all defined rules\n for (const rule of this.ruleSet.rules) {\n const value = data[rule.field];\n\n // Use a fallback message, but allow the matcher to report a better arrow\n let violationMessage = 'Value is not allowed, got: ' + JSON.stringify(value);\n const matchResult = rule.matcher(value, {\n reporter: (message: string) => {\n violationMessage = message;\n },\n });\n\n switch (rule.type) {\n case RuleType.PASS:\n if (!matchResult) {\n violations.push({\n field: rule.field,\n message: violationMessage,\n });\n }\n break;\n case RuleType.FAIL:\n if (matchResult) {\n violations.push({\n field: rule.field,\n message: violationMessage,\n });\n }\n break;\n default:\n continue;\n }\n\n checkedFields.add(rule.field);\n }\n\n // finally check fields without any rules if they should fail the validation\n if (this.ruleSet.options.unexpectedFields === RuleType.FAIL) {\n const receivedFields = Object.keys(data);\n for (const field of receivedFields) {\n if (!checkedFields.has(field)) {\n violations.push({ field: field, message: `Unexpected field, got: ${field}` });\n }\n }\n }\n\n // if we have encountered a violation, throw an error\n if (violations.length > 0) {\n throw new ValidationError(violations);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/tsconfig/validator.ts"],"names":[],"mappings":";;;AA2BA,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,uCAAI,CAAA;IACJ,uCAAI,CAAA;AACN,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB;AAmBD,MAAa,OAAO;IAyDA;IAxDV,MAAM,GAAgB,EAAE,CAAC;IACjC,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,IAAW,MAAM;QACf,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACvD,CAAC;IAED;;OAEG;IACH,IAAW,aAAa;QACtB,IAAI,IAAI,CAAC,OAAO,CAAC,gBAAgB,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC;YACpD,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,IAAW,cAAc;QACvB,MAAM,QAAQ,GAAa,EAAE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AAC;aACF,CAAC,CAAC;YAEH,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;gBAClB,KAAK,QAAQ,CAAC,IAAI;oBAChB,IAAI,CAAC,WAAW,EAAE,CAAC;wBACjB,UAAU,CAAC,IAAI,CAAC;4BACd,KAAK,EAAE,IAAI,CAAC,KAAK;4BACjB,OAAO,EAAE,gBAAgB;yBAC1B,CAAC,CAAC;oBACL,CAAC;oBACD,MAAM;gBACR,KAAK,QAAQ,CAAC,IAAI;oBAChB,IAAI,WAAW,EAAE,CAAC;wBAChB,UAAU,CAAC,IAAI,CAAC;4BACd,KAAK,EAAE,IAAI,CAAC,KAAK;4BACjB,OAAO,EAAE,gBAAgB;yBAC1B,CAAC,CAAC;oBACL,CAAC;oBACD,MAAM;gBACR;oBACE,SAAS;YACb,CAAC;YAED,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;QAED,4EAA4E;QAC5E,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,gBAAgB,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC5D,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACzC,KAAK,MAAM,KAAK,IAAI,cAAc,EAAE,CAAC;gBACnC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;oBAC9B,UAAU,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,0BAA0B,KAAK,EAAE,EAAE,CAAC,CAAC;gBAChF,CAAC;YACH,CAAC;QACH,CAAC;QAED,qDAAqD;QACrD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,eAAe,CAAC,UAAU,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF;AAxED,0CAwEC","sourcesContent":["/**\n * A function that receives 3 arguments and validates if the provided value matches.\n * @param value The value to validate\n * @params options Additional options to influence the matcher behavior.\n * @returns true if the value matches\n */\ntype Matcher = (value: any, options?: MatcherOptions) => boolean;\n\ninterface MatcherOptions {\n /**\n * A function that will be called by the matcher with a a violation message.\n * This function is always called, regardless of the outcome of the matcher.\n * It is up to the caller of the matcher to decide if the message should be used or not.\n *\n * @param message The message describing the possible failure.\n */\n reporter?: (message: string) => void;\n /**\n * A function that might receive explicitly allowed values.\n * This can be used to generate synthetics values that would match the matcher.\n * It is not guaranteed that hints are received or that hints are complete.\n *\n * @param allowed The list values that a matcher offers as definitely allowed.\n */\n hints?: (allowed: any[]) => void;\n}\n\nexport enum RuleType {\n PASS,\n FAIL,\n}\n\nexport interface RuleSetOptions {\n /**\n * Defines the behavior for any encountered fields for which no rules are defined.\n * The default is to pass these fields without validation,\n * but this can also be set to fail any unexpected fields.\n *\n * @default RuleType.PASS\n */\n readonly unexpectedFields: RuleType;\n}\n\ninterface Rule {\n field: string;\n type: RuleType;\n matcher: Matcher;\n}\n\nexport class RuleSet {\n private _rules: Array<Rule> = [];\n public get rules(): Array<Rule> {\n return this._rules;\n }\n\n /**\n * Return all fields for which a rule exists\n */\n public get fields(): Array<string> {\n return [...new Set(this._rules.map((r) => r.field))];\n }\n\n /**\n * Return a list of fields that are allowed, or undefined if all are allowed.\n */\n public get allowedFields(): Array<string> | undefined {\n if (this.options.unexpectedFields === RuleType.FAIL) {\n return this.fields;\n }\n\n return undefined;\n }\n\n /**\n * Find all required fields by evaluating every rule in th set against undefined.\n * If the rule fails, the key must be required.\n *\n * @returns A list of keys that must be included or undefined\n */\n public get requiredFields(): Array<string> {\n const required: string[] = [];\n\n for (const rule of this._rules) {\n const key = rule.field;\n const matcherResult = rule.matcher(undefined);\n\n switch (rule.type) {\n case RuleType.PASS:\n if (!matcherResult) {\n required.push(key);\n }\n break;\n case RuleType.FAIL:\n if (matcherResult) {\n required.push(key);\n }\n break;\n default:\n continue;\n }\n }\n\n return required;\n }\n\n public constructor(\n public readonly options: RuleSetOptions = {\n unexpectedFields: RuleType.PASS,\n },\n ) {}\n\n /**\n * Requires the matcher to pass for the given field.\n * Otherwise a violation is detected.\n *\n * @param field The field the rule applies to\n * @param matcher The matcher function\n */\n public shouldPass(field: string, matcher: Matcher) {\n this._rules.push({ field, matcher, type: RuleType.PASS });\n }\n\n /**\n * Detects a violation if the matcher is matching for a certain field.\n *\n * @param field The field the rule applies to\n * @param matcher The matcher function\n */\n public shouldFail(field: string, matcher: Matcher) {\n this._rules.push({ field, matcher, type: RuleType.FAIL });\n }\n\n /**\n * Imports all rules from an other rule set.\n * Note that any options from the other rule set will be ignored.\n *\n * @param other The other rule set to import rules from.\n */\n public import(other: RuleSet) {\n this._rules.push(...other.rules);\n }\n\n /**\n * Records the field hints for the given rule set.\n * Hints are values that are guaranteed to pass the rule.\n * The list of hints is not guaranteed to be complete nor does it guarantee to return any values.\n * This can be used to create synthetic values for testing for error messages.\n *\n * @returns A record of fields and allowed values\n */\n public getFieldHints(): Record<string, any[]> {\n const fieldHints: Record<string, any[]> = {};\n\n for (const rule of this._rules) {\n // We are only interested in PASS rules here.\n // For FAILs we still don't know which values would pass.\n if (rule.type === RuleType.PASS) {\n // run the matcher to record hints\n rule.matcher(undefined, {\n hints: (receivedHints: any[]) => {\n // if we have recorded hints, add them to the map\n if (receivedHints) {\n fieldHints[rule.field] ??= [];\n fieldHints[rule.field].push(...receivedHints);\n }\n },\n });\n }\n }\n\n return fieldHints;\n }\n}\n\n/**\n * Helper to wrap a matcher with error reporting and hints\n */\nfunction wrapMatcher(matcher: Matcher, message: (actual: any) => string, allowed?: any[]): Matcher {\n return (value, options) => {\n options?.reporter?.(message(value));\n if (allowed) {\n options?.hints?.(allowed);\n }\n return matcher(value);\n };\n}\n\n/**\n * Helper to implement loose equality that is safe for any value\n * Needed because there are some values that are equal as object, but not with ==\n * There are also values that cannot be compared using == and will throw\n */\nfunction looseEqual(a: any, b: any): boolean {\n try {\n // if one of the values is an object (or array), but the other isn't - never consider them the same\n if ([typeof a, typeof b].filter((t) => t === 'object').length === 1) {\n return false;\n }\n // if both values are the same object\n // or if both values are loose equal\n return Object.is(a, b) || a == b;\n } catch {\n return false;\n }\n}\n\nexport class Match {\n /**\n * Value is optional, but if present should match\n */\n public static optional(matcher: Matcher): Matcher {\n return (value, options) => {\n if (value == null) {\n return true;\n }\n return matcher(value, options);\n };\n }\n\n /**\n * Value must match at least one of the provided matchers.\n * All matchers are evaluated (no short-circuit) so their hints are collected.\n */\n public static anyOf(...matchers: Matcher[]): Matcher {\n return (value, options) => matchers.map((m) => m(value, options)).some(Boolean);\n }\n\n /**\n * Value must be one of the allowed options\n */\n public static oneOf(...allowed: Array<string | number>): Matcher {\n return wrapMatcher(\n (actual) => allowed.includes(actual),\n (actual) => `Expected value to be one of ${JSON.stringify(allowed)}, got: ${JSON.stringify(actual)}`,\n allowed,\n );\n }\n\n /**\n * Value must be loosely equal to the expected value\n * Arrays are compared by elements\n */\n public static eq(expected: any): Matcher {\n return (actual, options) => {\n if (Array.isArray(expected)) {\n return Match.arrEq(expected)(actual, options);\n }\n\n options?.hints?.([expected]);\n options?.reporter?.(`Expected value ${JSON.stringify(expected)}, got: ${JSON.stringify(actual)}`);\n return looseEqual(actual, expected);\n };\n }\n\n /**\n * Value must be loosely equal to the expected value\n * Arrays are compared by elements\n */\n public static arrEq(expected: any[]): Matcher {\n return wrapMatcher(\n (actual) => {\n // if both are arrays and of the same length, compare elements\n // if one of them is not, or they are a different length,\n // skip comparing elements as the the equality check later will fail\n if (Array.isArray(expected) && Array.isArray(actual) && expected.length == actual.length) {\n // compare all elements with loose typing\n return expected.every((e) => actual.some((a) => looseEqual(a, e)));\n }\n\n // all other values and arrays of different shape\n return looseEqual(actual, expected);\n },\n (actual) => `Expected array matching ${JSON.stringify(expected)}, got: ${JSON.stringify(actual)}`,\n [expected],\n );\n }\n\n /**\n * Compare strings, allows setting cases sensitivity\n */\n public static strEq(expected: string, caseSensitive = false): Matcher {\n return wrapMatcher(\n (actual) => {\n // case insensitive\n if (!caseSensitive && typeof actual === 'string') {\n return looseEqual(expected.toLowerCase(), actual.toLowerCase());\n }\n\n // case sensitive\n return looseEqual(actual, expected);\n },\n (actual: any) => `Expected string ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`,\n [expected],\n );\n }\n\n /**\n * Allows any value\n */\n public static ANY: Matcher = (_val, _options) => true;\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n public static TRUE: Matcher = Match.eq(true);\n // eslint-disable-next-line @typescript-eslint/member-ordering\n public static FALSE: Matcher = Match.eq(false);\n\n /**\n * Missing (undefined) value\n */\n // eslint-disable-next-line @typescript-eslint/member-ordering\n public static MISSING = wrapMatcher(\n (actual) => actual === null || actual === undefined,\n (actual) => `Expected value to be present, got ${JSON.stringify(actual)}`,\n [undefined, null],\n );\n}\n\nexport interface Violation {\n field: string;\n message: string;\n}\n\nexport class ValidationError extends Error {\n constructor(public readonly violations: Violation[]) {\n // error message is a list of violations\n super('Data is invalid:\\n' + violations.map((v) => v.field + ': ' + v.message).join('\\n'));\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, ValidationError.prototype);\n }\n}\n\nexport class ObjectValidator {\n public constructor(public ruleSet: RuleSet, private readonly dataName: string = 'data') {}\n\n /**\n * Validated the provided data against the set of rules.\n *\n * @throws when the data is invalid\n *\n * @param data the data to be validated\n */\n public validate(data: { [field: string]: any }) {\n // make sure data is an object\n if (!(typeof data === 'object' && !Array.isArray(data) && data !== null)) {\n throw new ValidationError([\n { field: this.dataName, message: 'Provided data must be an object, got: ' + JSON.stringify(data) },\n ]);\n }\n\n const checkedFields = new Set();\n const violations: Violation[] = [];\n\n // first check all defined rules\n for (const rule of this.ruleSet.rules) {\n const value = data[rule.field];\n\n // Use a fallback message, but allow the matcher to report a better arrow\n let violationMessage = 'Value is not allowed, got: ' + JSON.stringify(value);\n const matchResult = rule.matcher(value, {\n reporter: (message: string) => {\n violationMessage = message;\n },\n });\n\n switch (rule.type) {\n case RuleType.PASS:\n if (!matchResult) {\n violations.push({\n field: rule.field,\n message: violationMessage,\n });\n }\n break;\n case RuleType.FAIL:\n if (matchResult) {\n violations.push({\n field: rule.field,\n message: violationMessage,\n });\n }\n break;\n default:\n continue;\n }\n\n checkedFields.add(rule.field);\n }\n\n // finally check fields without any rules if they should fail the validation\n if (this.ruleSet.options.unexpectedFields === RuleType.FAIL) {\n const receivedFields = Object.keys(data);\n for (const field of receivedFields) {\n if (!checkedFields.has(field)) {\n violations.push({ field: field, message: `Unexpected field, got: ${field}` });\n }\n }\n }\n\n // if we have encountered a violation, throw an error\n if (violations.length > 0) {\n throw new ValidationError(violations);\n }\n }\n}\n"]}
|
package/lib/type-analysis.js
CHANGED
|
@@ -1,8 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.isAllowedCovariantSubtype = isAllowedCovariantSubtype;
|
|
4
|
-
const spec = require("@jsii/spec");
|
|
5
|
-
const
|
|
40
|
+
const spec = __importStar(require("@jsii/spec"));
|
|
41
|
+
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
|
6
42
|
/**
|
|
7
43
|
* Check if subType is an allowed covariant subtype to superType
|
|
8
44
|
*
|
|
@@ -16,7 +52,7 @@ function isAllowedCovariantSubtype(subType, superType, dereference) {
|
|
|
16
52
|
return false;
|
|
17
53
|
}
|
|
18
54
|
// Same type is always covariant
|
|
19
|
-
if (
|
|
55
|
+
if ((0, fast_deep_equal_1.default)(subType, superType)) {
|
|
20
56
|
return true;
|
|
21
57
|
}
|
|
22
58
|
// Handle array collections (covariant)
|
package/lib/type-analysis.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-analysis.js","sourceRoot":"","sources":["../src/type-analysis.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"type-analysis.js","sourceRoot":"","sources":["../src/type-analysis.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,8DAqIC;AAhJD,iDAAmC;AACnC,sEAAwC;AAGxC;;;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AU,EAAE,CAAC;YAC7B,KAAK,MAAM,KAAK,IAAI,aAAa,CAAC,UAAU,EAAE,CAAC;gBAC7C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;oBACxB,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,MAAM,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;gBACrC,IAAI,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,IAAI,0BAA0B,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC;oBACxF,OAAO,IAAI,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["import * as spec from '@jsii/spec';\nimport deepEqual from 'fast-deep-equal';\nimport { TypeResolver } from './type-reference';\n\n/**\n * Check if subType is an allowed covariant subtype to superType\n *\n * This is not a generic check for subtypes or covariance, but a specific implementation\n * that checks the currently allowed conditions for class covariance.\n * In practice, this is driven by C# limitations.\n */\nexport function isAllowedCovariantSubtype(\n subType: spec.TypeReference | undefined,\n superType: spec.TypeReference | undefined,\n dereference: TypeResolver,\n): boolean {\n // one void, while other isn't => not covariant\n if ((subType === undefined) !== (superType === undefined)) {\n return false;\n }\n\n // Same type is always covariant\n if (deepEqual(subType, superType)) {\n return true;\n }\n\n // Handle array collections (covariant)\n if (spec.isCollectionTypeReference(subType) && spec.isCollectionTypeReference(superType)) {\n if (subType.collection.kind === 'array' && superType.collection.kind === 'array') {\n return isAllowedCovariantSubtype(subType.collection.elementtype, superType.collection.elementtype, dereference);\n }\n // Maps are not allowed to be covariant in C#, so we exclude them here.\n // This seems to be because we use C# Dictionary to implements Maps, which are using generics and generics are not allowed to be covariant\n return false;\n }\n\n // Union types are currently not allowed, because we have not seen the need for it.\n // Technically narrowing (removing `| Type` or subtyping) could be allowed and this works in C#.\n if (spec.isUnionTypeReference(subType) || spec.isUnionTypeReference(superType)) {\n return false;\n }\n\n // Intersection types are invalid, because intersections are only allowed as inputs\n // and covariance is only allowed in outputs.\n if (spec.isIntersectionTypeReference(subType) || spec.isIntersectionTypeReference(superType)) {\n return false;\n }\n\n // Primitives can never be covariant to each other in C#\n if (spec.isPrimitiveTypeReference(subType) || spec.isPrimitiveTypeReference(superType)) {\n return false;\n }\n\n // We really only support covariance for named types (and lists of named types).\n // To be safe, let's guard against any unknown cases.\n if (!spec.isNamedTypeReference(subType) || !spec.isNamedTypeReference(superType)) {\n return false;\n }\n\n const subTypeSpec = dereference(subType.fqn);\n const superTypeSpec = dereference(superType.fqn);\n\n if (!subTypeSpec || !superTypeSpec) {\n return false;\n }\n\n // Handle class-to-class inheritance\n if (spec.isClassType(subTypeSpec) && spec.isClassType(superTypeSpec)) {\n return _classExtendsClass(subTypeSpec, superType.fqn);\n }\n\n // Handle interface-to-interface inheritance\n if (spec.isInterfaceType(subTypeSpec) && spec.isInterfaceType(superTypeSpec)) {\n return _interfaceExtendsInterface(subTypeSpec, superType.fqn);\n }\n\n // Handle class implementing interface\n if (spec.isClassType(subTypeSpec) && spec.isInterfaceType(superTypeSpec)) {\n return _classImplementsInterface(subTypeSpec, superType.fqn);\n }\n\n return false;\n\n function _classExtendsClass(classType: spec.ClassType, targetFqn: string): boolean {\n let current = classType;\n while (current.base) {\n if (current.base === targetFqn) {\n return true;\n }\n const baseType = dereference(current.base);\n if (!spec.isClassType(baseType)) {\n break;\n }\n current = baseType;\n }\n return false;\n }\n\n function _classImplementsInterface(classType: spec.ClassType, interfaceFqn: string): boolean {\n // Check direct interfaces\n if (classType.interfaces?.includes(interfaceFqn)) {\n return true;\n }\n\n // Check inherited interfaces\n if (classType.interfaces) {\n for (const iface of classType.interfaces) {\n const ifaceType = dereference(iface);\n if (spec.isInterfaceType(ifaceType) && _interfaceExtendsInterface(ifaceType, interfaceFqn)) {\n return true;\n }\n }\n }\n\n // Check base class interfaces\n if (classType.base) {\n const baseType = dereference(classType.base);\n if (spec.isClassType(baseType)) {\n return _classImplementsInterface(baseType, interfaceFqn);\n }\n }\n\n return false;\n }\n\n function _interfaceExtendsInterface(interfaceType: spec.InterfaceType, targetFqn: string): boolean {\n if (interfaceType.fqn === targetFqn) {\n return true;\n }\n\n if (interfaceType.interfaces) {\n for (const iface of interfaceType.interfaces) {\n if (iface === targetFqn) {\n return true;\n }\n const ifaceType = dereference(iface);\n if (spec.isInterfaceType(ifaceType) && _interfaceExtendsInterface(ifaceType, targetFqn)) {\n return true;\n }\n }\n }\n\n return false;\n }\n}\n"]}
|
package/lib/type-reference.js
CHANGED
|
@@ -1,10 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.typeReferenceToString = typeReferenceToString;
|
|
4
37
|
exports.typeReferenceEqual = typeReferenceEqual;
|
|
5
38
|
exports.createTypeResolver = createTypeResolver;
|
|
6
39
|
exports.resolveType = resolveType;
|
|
7
|
-
const spec = require("@jsii/spec");
|
|
40
|
+
const spec = __importStar(require("@jsii/spec"));
|
|
8
41
|
const type_visitor_1 = require("./type-visitor");
|
|
9
42
|
/**
|
|
10
43
|
* Convert a type reference to a string
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-reference.js","sourceRoot":"","sources":["../src/type-reference.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"type-reference.js","sourceRoot":"","sources":["../src/type-reference.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,sDAkBC;AAKD,gDAyBC;AAOD,gDAEC;AAMD,kCAcC;AAnFD,iDAAmC;AACnC,iDAAoD;AAEpD;;GAEG;AACH,SAAgB,qBAAqB,CAAC,CAAqB;IACzD,OAAO,IAAA,iCAAkB,EAAS,CAAC,EAAE;QACnC,KAAK,EAAE,UAAU,GAA4B;YAC3C,OAAO,GAAG,CAAC,GAAG,CAAC;QACjB,CAAC;QACD,SAAS,EAAE,UAAU,GAAgC;YACnD,OAAO,GAAG,CAAC,SAAS,CAAC;QACvB,CAAC;QACD,UAAU,EAAE,UAAU,GAAiC;YACrD,OAAO,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,IAAI,qBAAqB,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC;QAC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AE,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IACD,MAAM,WAAW,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IACvE,OAAO,WAAW,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import * as spec from '@jsii/spec';\nimport { visitTypeReference } from './type-visitor';\n\n/**\n * Convert a type reference to a string\n */\nexport function typeReferenceToString(x: spec.TypeReference): string {\n return visitTypeReference<string>(x, {\n named: function (ref: spec.NamedTypeReference) {\n return ref.fqn;\n },\n primitive: function (ref: spec.PrimitiveTypeReference) {\n return ref.primitive;\n },\n collection: function (ref: spec.CollectionTypeReference) {\n return `${ref.collection.kind}<${typeReferenceToString(ref.collection.elementtype)}>`;\n },\n union: function (ref: spec.UnionTypeReference) {\n return ref.union.types.map(typeReferenceToString).join(' | ');\n },\n intersection: function (ref: spec.IntersectionTypeReference) {\n return ref.intersection.types.map(typeReferenceToString).join(' & ');\n },\n });\n}\n\n/**\n * Return whether the given type references are equal\n */\nexport function typeReferenceEqual(a: spec.TypeReference, b: spec.TypeReference): boolean {\n if (spec.isNamedTypeReference(a) && spec.isNamedTypeReference(b)) {\n return a.fqn === b.fqn;\n }\n if (spec.isPrimitiveTypeReference(a) && spec.isPrimitiveTypeReference(b)) {\n return a.primitive === b.primitive;\n }\n if (spec.isCollectionTypeReference(a) && spec.isCollectionTypeReference(b)) {\n return (\n a.collection.kind === b.collection.kind && typeReferenceEqual(a.collection.elementtype, b.collection.elementtype)\n );\n }\n if (spec.isUnionTypeReference(a) && spec.isUnionTypeReference(b)) {\n return (\n a.union.types.length === b.union.types.length &&\n a.union.types.every((aType, i) => typeReferenceEqual(aType, b.union.types[i]))\n );\n }\n if (spec.isIntersectionTypeReference(a) && spec.isIntersectionTypeReference(b)) {\n return (\n a.intersection.types.length === b.intersection.types.length &&\n a.intersection.types.every((aType, i) => typeReferenceEqual(aType, b.intersection.types[i]))\n );\n }\n return false;\n}\n\nexport type TypeResolver = (typeRef: string | spec.NamedTypeReference) => spec.Type | undefined;\n\n/**\n * Creates a type resolver function for a given context (assembly + dependency closure).\n */\nexport function createTypeResolver(assembly: spec.Assembly, dependencyClosure: readonly spec.Assembly[]): TypeResolver {\n return (typeRef) => resolveType(typeRef, assembly, dependencyClosure);\n}\n\n/**\n * Resolve a type from a name to the actual type.\n * Uses a given assembly and dependency closure for lookup.\n */\nexport function resolveType(\n typeRef: string | spec.NamedTypeReference,\n assembly: spec.Assembly,\n dependencyClosure: readonly spec.Assembly[],\n): spec.Type | undefined {\n if (typeof typeRef !== 'string') {\n typeRef = typeRef.fqn;\n }\n const [assm] = typeRef.split('.');\n if (assembly.name === assm) {\n return assembly.types?.[typeRef];\n }\n const foreignAssm = dependencyClosure.find((dep) => dep.name === assm);\n return foreignAssm?.types?.[typeRef];\n}\n"]}
|
package/lib/type-tracker.js
CHANGED
|
@@ -1,16 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.TypeTracker = void 0;
|
|
4
|
-
const ts = require("typescript");
|
|
37
|
+
const ts = __importStar(require("typescript"));
|
|
5
38
|
/**
|
|
6
39
|
* A class that tracks the TypeScript source AST nodes for certain jsii types
|
|
7
40
|
*
|
|
8
41
|
* This is useful if we need to get additional information that is not currently tracked.
|
|
9
42
|
*/
|
|
10
43
|
class TypeTracker {
|
|
11
|
-
|
|
12
|
-
this.enums = {};
|
|
13
|
-
}
|
|
44
|
+
enums = {};
|
|
14
45
|
registerEnum(fqn, decl) {
|
|
15
46
|
this.enums[fqn] = decl;
|
|
16
47
|
}
|
package/lib/type-tracker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-tracker.js","sourceRoot":"","sources":["../src/type-tracker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"type-tracker.js","sourceRoot":"","sources":["../src/type-tracker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC;;;;GAIG;AACH,MAAa,WAAW;IACL,KAAK,GAAuC,EAAE,CAAC;IAEzD,YAAY,CAAC,GAAW,EAAE,IAAwB;QACvD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACzB,CAAC;IAEM,OAAO,CAAC,GAAW;QACxB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CAAC,0CAA0C,GAAG,EAAE,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAEM,cAAc,CAAC,GAAW;QAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAEnC,OAAO,MAAM,CAAC,WAAW,CACvB,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAC1F,CAAC;IACJ,CAAC;CACF;AAtBD,kCAsBC;AAED,SAAS,YAAY,CAAC,CAAU;IAC9B,IAAI,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;QACvB,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import * as ts from 'typescript';\n\n/**\n * A class that tracks the TypeScript source AST nodes for certain jsii types\n *\n * This is useful if we need to get additional information that is not currently tracked.\n */\nexport class TypeTracker {\n private readonly enums: Record<string, ts.EnumDeclaration> = {};\n\n public registerEnum(fqn: string, decl: ts.EnumDeclaration) {\n this.enums[fqn] = decl;\n }\n\n public getEnum(fqn: string): ts.EnumDeclaration {\n const ret = this.enums[fqn];\n if (!ret) {\n throw new Error(`No declaration was registered for enum ${fqn}`);\n }\n return ret;\n }\n\n public getEnumMembers(fqn: string): Record<string, ts.EnumMember> {\n const enumDecl = this.getEnum(fqn);\n\n return Object.fromEntries(\n enumDecl.members.filter(ts.isEnumMember).map((mem) => [asIdentifier(mem.name).text, mem]),\n );\n }\n}\n\nfunction asIdentifier(x: ts.Node): ts.Identifier {\n if (ts.isIdentifier(x)) {\n return x;\n }\n throw new Error(`Expected identifier, got ${JSON.stringify(x)}`);\n}\n"]}
|