@thymian/plugin-sampler 0.3.0-canary.20261007-e6cb8dc → 0.3.0-canary.20261007-cdbe1d3
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/cli/check-result.d.ts +88 -0
- package/dist/cli/check-result.d.ts.map +1 -0
- package/dist/cli/check-result.js +160 -0
- package/dist/cli/check-result.js.map +1 -0
- package/dist/cli/commands/sampler/check.d.ts +32 -4
- package/dist/cli/commands/sampler/check.d.ts.map +1 -1
- package/dist/cli/commands/sampler/check.js +126 -88
- package/dist/cli/commands/sampler/check.js.map +1 -1
- package/dist/cli/commands/sampler/init.d.ts +4 -6
- package/dist/cli/commands/sampler/init.d.ts.map +1 -1
- package/dist/cli/commands/sampler/init.js +33 -49
- package/dist/cli/commands/sampler/init.js.map +1 -1
- package/dist/cli/commands/sampler/show.d.ts +11 -0
- package/dist/cli/commands/sampler/show.d.ts.map +1 -0
- package/dist/cli/commands/sampler/show.js +36 -0
- package/dist/cli/commands/sampler/show.js.map +1 -0
- package/dist/cli/commands/sampler/sync.d.ts +11 -0
- package/dist/cli/commands/sampler/sync.d.ts.map +1 -0
- package/dist/cli/commands/sampler/sync.js +65 -0
- package/dist/cli/commands/sampler/sync.js.map +1 -0
- package/dist/cli/commands/sampler/validate.d.ts +3 -10
- package/dist/cli/commands/sampler/validate.d.ts.map +1 -1
- package/dist/cli/commands/sampler/validate.js +57 -126
- package/dist/cli/commands/sampler/validate.js.map +1 -1
- package/dist/generation/closed-schema.d.ts +22 -0
- package/dist/generation/closed-schema.d.ts.map +1 -0
- package/dist/generation/closed-schema.js +45 -0
- package/dist/generation/closed-schema.js.map +1 -0
- package/dist/generation/content-type-strategies/json.content-type-strategy.d.ts.map +1 -1
- package/dist/generation/content-type-strategies/json.content-type-strategy.js +3 -1
- package/dist/generation/content-type-strategies/json.content-type-strategy.js.map +1 -1
- package/dist/generation/content-type-strategies/xml.content-type-strategy.d.ts.map +1 -1
- package/dist/generation/content-type-strategies/xml.content-type-strategy.js +3 -1
- package/dist/generation/content-type-strategies/xml.content-type-strategy.js.map +1 -1
- package/dist/generation/generate-request-sample.d.ts +12 -0
- package/dist/generation/generate-request-sample.d.ts.map +1 -0
- package/dist/generation/{generate-samples.js → generate-request-sample.js} +11 -4
- package/dist/generation/generate-request-sample.js.map +1 -0
- package/dist/generation/request-generators/default-request-generator.d.ts +14 -0
- package/dist/generation/request-generators/default-request-generator.d.ts.map +1 -1
- package/dist/generation/request-generators/default-request-generator.js +18 -1
- package/dist/generation/request-generators/default-request-generator.js.map +1 -1
- package/dist/generation/types/declaration-set.d.ts +124 -0
- package/dist/generation/types/declaration-set.d.ts.map +1 -0
- package/dist/generation/types/declaration-set.js +389 -0
- package/dist/generation/types/declaration-set.js.map +1 -0
- package/dist/generation/types/example-reflection.d.ts +21 -0
- package/dist/generation/types/example-reflection.d.ts.map +1 -0
- package/dist/generation/types/example-reflection.js +135 -0
- package/dist/generation/types/example-reflection.js.map +1 -0
- package/dist/generation/types/generate-type-surface.d.ts +23 -0
- package/dist/generation/types/generate-type-surface.d.ts.map +1 -0
- package/dist/generation/types/generate-type-surface.js +671 -0
- package/dist/generation/types/generate-type-surface.js.map +1 -0
- package/dist/generation/types/schema-type.d.ts +20 -0
- package/dist/generation/types/schema-type.d.ts.map +1 -0
- package/dist/generation/types/schema-type.js +203 -0
- package/dist/generation/types/schema-type.js.map +1 -0
- package/dist/generation/types/self-check-surface.d.ts +32 -0
- package/dist/generation/types/self-check-surface.d.ts.map +1 -0
- package/dist/generation/types/self-check-surface.js +92 -0
- package/dist/generation/types/self-check-surface.js.map +1 -0
- package/dist/generation/types/type-names.d.ts +135 -0
- package/dist/generation/types/type-names.d.ts.map +1 -0
- package/dist/generation/types/type-names.js +213 -0
- package/dist/generation/types/type-names.js.map +1 -0
- package/dist/generation/types/write-type-surface.d.ts +58 -0
- package/dist/generation/types/write-type-surface.d.ts.map +1 -0
- package/dist/generation/types/write-type-surface.js +119 -0
- package/dist/generation/types/write-type-surface.js.map +1 -0
- package/dist/hooks/create-hook-utils.d.ts +22 -6
- package/dist/hooks/create-hook-utils.d.ts.map +1 -1
- package/dist/hooks/create-hook-utils.js +74 -96
- package/dist/hooks/create-hook-utils.js.map +1 -1
- package/dist/hooks/hook-api.d.ts +49 -0
- package/dist/hooks/hook-api.d.ts.map +1 -0
- package/dist/hooks/hook-api.js +105 -0
- package/dist/hooks/hook-api.js.map +1 -0
- package/dist/hooks/hook-diagnostics.d.ts +45 -0
- package/dist/hooks/hook-diagnostics.d.ts.map +1 -0
- package/dist/hooks/hook-diagnostics.js +80 -0
- package/dist/hooks/hook-diagnostics.js.map +1 -0
- package/dist/hooks/hook-errors.d.ts +33 -0
- package/dist/hooks/hook-errors.d.ts.map +1 -1
- package/dist/hooks/hook-errors.js +46 -0
- package/dist/hooks/hook-errors.js.map +1 -1
- package/dist/hooks/hook-registration.d.ts +108 -0
- package/dist/hooks/hook-registration.d.ts.map +1 -0
- package/dist/hooks/hook-registration.js +69 -0
- package/dist/hooks/hook-registration.js.map +1 -0
- package/dist/hooks/hook-runner.d.ts +111 -11
- package/dist/hooks/hook-runner.d.ts.map +1 -1
- package/dist/hooks/hook-runner.js +309 -142
- package/dist/hooks/hook-runner.js.map +1 -1
- package/dist/hooks/hook-utils-factory.d.ts +19 -0
- package/dist/hooks/hook-utils-factory.d.ts.map +1 -0
- package/dist/hooks/hook-utils-factory.js +2 -0
- package/dist/hooks/hook-utils-factory.js.map +1 -0
- package/dist/hooks/hook-utils.d.ts +80 -12
- package/dist/hooks/hook-utils.d.ts.map +1 -1
- package/dist/hooks/invoke-hook.d.ts +71 -0
- package/dist/hooks/invoke-hook.d.ts.map +1 -0
- package/dist/hooks/invoke-hook.js +161 -0
- package/dist/hooks/invoke-hook.js.map +1 -0
- package/dist/hooks/load-user-hooks.d.ts +96 -0
- package/dist/hooks/load-user-hooks.d.ts.map +1 -0
- package/dist/hooks/load-user-hooks.js +432 -0
- package/dist/hooks/load-user-hooks.js.map +1 -0
- package/dist/hooks/nested-request.d.ts +21 -0
- package/dist/hooks/nested-request.d.ts.map +1 -0
- package/dist/hooks/nested-request.js +24 -0
- package/dist/hooks/nested-request.js.map +1 -0
- package/dist/hooks/overlay-args.d.ts +40 -0
- package/dist/hooks/overlay-args.d.ts.map +1 -0
- package/dist/hooks/overlay-args.js +84 -0
- package/dist/hooks/overlay-args.js.map +1 -0
- package/dist/hooks/resolve-targeting.d.ts +16 -0
- package/dist/hooks/resolve-targeting.d.ts.map +1 -0
- package/dist/hooks/resolve-targeting.js +168 -0
- package/dist/hooks/resolve-targeting.js.map +1 -0
- package/dist/hooks/run-scoped-hooks.d.ts +83 -0
- package/dist/hooks/run-scoped-hooks.d.ts.map +1 -0
- package/dist/hooks/run-scoped-hooks.js +153 -0
- package/dist/hooks/run-scoped-hooks.js.map +1 -0
- package/dist/index.d.ts +42 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +152 -165
- package/dist/index.js.map +1 -1
- package/dist/request-sampler.d.ts +40 -11
- package/dist/request-sampler.d.ts.map +1 -1
- package/dist/request-sampler.js +51 -76
- package/dist/request-sampler.js.map +1 -1
- package/dist/sampler-paths.d.ts +19 -0
- package/dist/sampler-paths.d.ts.map +1 -0
- package/dist/sampler-paths.js +22 -0
- package/dist/sampler-paths.js.map +1 -0
- package/dist/selectors/nearest-paths.d.ts +14 -0
- package/dist/selectors/nearest-paths.d.ts.map +1 -0
- package/dist/selectors/nearest-paths.js +32 -0
- package/dist/selectors/nearest-paths.js.map +1 -0
- package/dist/selectors/path-glob.d.ts +94 -0
- package/dist/selectors/path-glob.d.ts.map +1 -0
- package/dist/selectors/path-glob.js +136 -0
- package/dist/selectors/path-glob.js.map +1 -0
- package/dist/selectors/selector-errors.d.ts +17 -0
- package/dist/selectors/selector-errors.d.ts.map +1 -0
- package/dist/selectors/selector-errors.js +139 -0
- package/dist/selectors/selector-errors.js.map +1 -0
- package/dist/selectors/selector.d.ts +55 -0
- package/dist/selectors/selector.d.ts.map +1 -0
- package/dist/selectors/selector.js +305 -0
- package/dist/selectors/selector.js.map +1 -0
- package/dist/selectors/transaction-catalog.d.ts +96 -0
- package/dist/selectors/transaction-catalog.d.ts.map +1 -0
- package/dist/selectors/transaction-catalog.js +193 -0
- package/dist/selectors/transaction-catalog.js.map +1 -0
- package/dist/selectors/transaction-filter.d.ts +119 -0
- package/dist/selectors/transaction-filter.d.ts.map +1 -0
- package/dist/selectors/transaction-filter.js +191 -0
- package/dist/selectors/transaction-filter.js.map +1 -0
- package/dist/ts-path.d.ts +36 -0
- package/dist/ts-path.d.ts.map +1 -0
- package/dist/ts-path.js +46 -0
- package/dist/ts-path.js.map +1 -0
- package/dist/utils.d.ts +1 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -20
- package/dist/utils.js.map +1 -1
- package/dist/validation/canonicalize.d.ts +17 -0
- package/dist/validation/canonicalize.d.ts.map +1 -0
- package/dist/validation/canonicalize.js +29 -0
- package/dist/validation/canonicalize.js.map +1 -0
- package/dist/validation/shared-compiler-host.d.ts +17 -0
- package/dist/validation/shared-compiler-host.d.ts.map +1 -0
- package/dist/validation/shared-compiler-host.js +58 -0
- package/dist/validation/shared-compiler-host.js.map +1 -0
- package/dist/validation/typecheck-hooks.d.ts +37 -0
- package/dist/validation/typecheck-hooks.d.ts.map +1 -0
- package/dist/validation/typecheck-hooks.js +169 -0
- package/dist/validation/typecheck-hooks.js.map +1 -0
- package/dist/validation/validate-sampler.d.ts +79 -0
- package/dist/validation/validate-sampler.d.ts.map +1 -0
- package/dist/validation/validate-sampler.js +89 -0
- package/dist/validation/validate-sampler.js.map +1 -0
- package/package.json +7 -11
- package/dist/cli/commands/sampler/generate/hook.d.ts +0 -10
- package/dist/cli/commands/sampler/generate/hook.d.ts.map +0 -1
- package/dist/cli/commands/sampler/generate/hook.js +0 -19
- package/dist/cli/commands/sampler/generate/hook.js.map +0 -1
- package/dist/cli/generate-hook.d.ts +0 -4
- package/dist/cli/generate-hook.d.ts.map +0 -1
- package/dist/cli/generate-hook.js +0 -96
- package/dist/cli/generate-hook.js.map +0 -1
- package/dist/cli/templates.d.ts +0 -4
- package/dist/cli/templates.d.ts.map +0 -1
- package/dist/cli/templates.js +0 -28
- package/dist/cli/templates.js.map +0 -1
- package/dist/constants.d.ts +0 -12
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -16
- package/dist/constants.js.map +0 -1
- package/dist/generation/generate-samples-for-thymian-format.d.ts +0 -4
- package/dist/generation/generate-samples-for-thymian-format.d.ts.map +0 -1
- package/dist/generation/generate-samples-for-thymian-format.js +0 -18
- package/dist/generation/generate-samples-for-thymian-format.js.map +0 -1
- package/dist/generation/generate-samples.d.ts +0 -4
- package/dist/generation/generate-samples.d.ts.map +0 -1
- package/dist/generation/generate-samples.js.map +0 -1
- package/dist/hooks/generate-request-types.d.ts +0 -34
- package/dist/hooks/generate-request-types.d.ts.map +0 -1
- package/dist/hooks/generate-request-types.js +0 -458
- package/dist/hooks/generate-request-types.js.map +0 -1
- package/dist/hooks/hook-types.d.ts +0 -7
- package/dist/hooks/hook-types.d.ts.map +0 -1
- package/dist/hooks/hook-types.js +0 -2
- package/dist/hooks/hook-types.js.map +0 -1
- package/dist/hooks/load-hooks-from-samples.d.ts +0 -3
- package/dist/hooks/load-hooks-from-samples.d.ts.map +0 -1
- package/dist/hooks/load-hooks-from-samples.js +0 -22
- package/dist/hooks/load-hooks-from-samples.js.map +0 -1
- package/dist/hooks/ts-config.d.ts +0 -10
- package/dist/hooks/ts-config.d.ts.map +0 -1
- package/dist/hooks/ts-config.js +0 -10
- package/dist/hooks/ts-config.js.map +0 -1
- package/dist/samples-structure/file-request-sample.d.ts +0 -20
- package/dist/samples-structure/file-request-sample.d.ts.map +0 -1
- package/dist/samples-structure/file-request-sample.js +0 -5
- package/dist/samples-structure/file-request-sample.js.map +0 -1
- package/dist/samples-structure/get-path-transaction-id.d.ts +0 -3
- package/dist/samples-structure/get-path-transaction-id.d.ts.map +0 -1
- package/dist/samples-structure/get-path-transaction-id.js +0 -22
- package/dist/samples-structure/get-path-transaction-id.js.map +0 -1
- package/dist/samples-structure/merge-tree.d.ts +0 -5
- package/dist/samples-structure/merge-tree.d.ts.map +0 -1
- package/dist/samples-structure/merge-tree.js +0 -118
- package/dist/samples-structure/merge-tree.js.map +0 -1
- package/dist/samples-structure/read-samples-from-dir.d.ts +0 -13
- package/dist/samples-structure/read-samples-from-dir.d.ts.map +0 -1
- package/dist/samples-structure/read-samples-from-dir.js +0 -205
- package/dist/samples-structure/read-samples-from-dir.js.map +0 -1
- package/dist/samples-structure/samples-from-transactions.d.ts +0 -5
- package/dist/samples-structure/samples-from-transactions.d.ts.map +0 -1
- package/dist/samples-structure/samples-from-transactions.js +0 -120
- package/dist/samples-structure/samples-from-transactions.js.map +0 -1
- package/dist/samples-structure/samples-tree-structure.d.ts +0 -106
- package/dist/samples-structure/samples-tree-structure.d.ts.map +0 -1
- package/dist/samples-structure/samples-tree-structure.js +0 -26
- package/dist/samples-structure/samples-tree-structure.js.map +0 -1
- package/dist/samples-structure/structure-meta-on-disc.d.ts +0 -11
- package/dist/samples-structure/structure-meta-on-disc.d.ts.map +0 -1
- package/dist/samples-structure/structure-meta-on-disc.js +0 -2
- package/dist/samples-structure/structure-meta-on-disc.js.map +0 -1
- package/dist/samples-structure/traverse.d.ts +0 -4
- package/dist/samples-structure/traverse.d.ts.map +0 -1
- package/dist/samples-structure/traverse.js +0 -13
- package/dist/samples-structure/traverse.js.map +0 -1
- package/dist/samples-structure/write-samples-to-dir.d.ts +0 -37
- package/dist/samples-structure/write-samples-to-dir.d.ts.map +0 -1
- package/dist/samples-structure/write-samples-to-dir.js +0 -183
- package/dist/samples-structure/write-samples-to-dir.js.map +0 -1
- package/dist/validation/validate-sampler-output.d.ts +0 -38
- package/dist/validation/validate-sampler-output.d.ts.map +0 -1
- package/dist/validation/validate-sampler-output.js +0 -288
- package/dist/validation/validate-sampler-output.js.map +0 -1
|
@@ -1,59 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join, relative } from 'node:path';
|
|
2
|
+
import { BaseCliRunCommand, oclif } from '@thymian/common-cli';
|
|
3
|
+
const { colorize } = oclif.ux;
|
|
2
4
|
export default class Init extends BaseCliRunCommand {
|
|
3
|
-
static
|
|
4
|
-
static
|
|
5
|
-
|
|
6
|
-
default: false,
|
|
7
|
-
description: 'Overwrite existing samples.',
|
|
8
|
-
}),
|
|
9
|
-
check: oclif.Flags.boolean({
|
|
10
|
-
description: 'After initialization, run sampler check to verify all transactions can be executed.',
|
|
11
|
-
allowNo: true,
|
|
12
|
-
default: false,
|
|
13
|
-
}),
|
|
14
|
-
};
|
|
5
|
+
static enableJsonFlag = true;
|
|
6
|
+
static description = 'Set up the sampler for editor support: generate the committed type surface and scaffold a tsconfig.';
|
|
7
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
15
8
|
async run() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.error('Cannot initialize sampler if sampler plugin is not registered.', {
|
|
19
|
-
exit: 1,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
const format = await this.thymian.loadFormat({
|
|
9
|
+
return this.thymian.run(async (emitter) => {
|
|
10
|
+
await this.thymian.loadFormat({
|
|
23
11
|
inputs: this.thymianConfig.specifications ?? [],
|
|
24
12
|
validateSpecs: this.flags['validate-specs'],
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
},
|
|
14
|
+
// The sampler builds its catalog on `core.format`, and the type surface
|
|
15
|
+
// is generated from that catalog.
|
|
16
|
+
{ emitFormat: true });
|
|
17
|
+
const result = await emitter.emitAction('sampler.init', {}, { strategy: 'first' });
|
|
18
|
+
if (this.jsonEnabled()) {
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
const root = relative(this.flags.cwd, result.root) || result.root;
|
|
22
|
+
// `result.generated` names files inside the surface directory, so the
|
|
23
|
+
// segment has to be put back: without it the command reports a path that
|
|
24
|
+
// does not exist.
|
|
25
|
+
for (const file of result.generated) {
|
|
26
|
+
this.log(`${colorize('green', 'created')} ${join(root, 'generated', file)}`);
|
|
27
|
+
}
|
|
28
|
+
if (result.tsconfig === 'written') {
|
|
29
|
+
this.log(`${colorize('green', 'created')} ${join(root, 'tsconfig.json')}`);
|
|
30
|
+
}
|
|
31
|
+
if (result.rootExcludeNote.length > 0) {
|
|
32
|
+
this.log();
|
|
33
|
+
this.log('One thing left, which only you can do:');
|
|
36
34
|
this.log();
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
if (answer) {
|
|
41
|
-
this.log();
|
|
42
|
-
const args = ['--cwd', this.flags.cwd];
|
|
43
|
-
if (this.flags.config) {
|
|
44
|
-
args.push('-c', this.flags.config);
|
|
45
|
-
}
|
|
46
|
-
await this.config.runCommand('sampler check', args);
|
|
35
|
+
for (const line of result.rootExcludeNote) {
|
|
36
|
+
this.log(` ${line}`);
|
|
47
37
|
}
|
|
48
38
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.log();
|
|
52
|
-
this.log('To check if every transaction can be executed, run:');
|
|
53
|
-
this.log();
|
|
54
|
-
this.log('$ thymian sampler check');
|
|
55
|
-
this.log();
|
|
56
|
-
}
|
|
39
|
+
return result;
|
|
40
|
+
});
|
|
57
41
|
}
|
|
58
42
|
}
|
|
59
43
|
//# sourceMappingURL=init.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../../src/cli/commands/sampler/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../../src/cli/commands/sampler/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EA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AAI,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,CACnE,CAAC;YACJ,CAAC;YAED,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAClC,IAAI,CAAC,GAAG,CACN,GAAG,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,EAAE,CACjE,CAAC;YACJ,CAAC;YAED,IAAI,MAAM,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACtC,IAAI,CAAC,GAAG,EAAE,CAAC;gBACX,IAAI,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;gBACnD,IAAI,CAAC,GAAG,EAAE,CAAC;gBAEX,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,eAAe,EAAE,CAAC;oBAC1C,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCliRunCommand, oclif } from '@thymian/common-cli';
|
|
2
|
+
export default class Show extends BaseCliRunCommand<typeof Show> {
|
|
3
|
+
static enableJsonFlag: boolean;
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static args: {
|
|
7
|
+
selector: oclif.Interfaces.Arg<string, Record<string, unknown>>;
|
|
8
|
+
};
|
|
9
|
+
run(): Promise<unknown>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=show.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"show.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/sampler/show.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG/D,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,iBAAiB,CAAC,OAAO,IAAI,CAAC;IAC9D,OAAgB,cAAc,UAAQ;IAEtC,OAAgB,WAAW,SAC2C;IAEtE,OAAgB,QAAQ,WAGtB;IAEF,OAAgB,IAAI;;MAMlB;IAEa,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC;CA6BvC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BaseCliRunCommand, oclif } from '@thymian/common-cli';
|
|
2
|
+
import { Args } from '@thymian/common-cli/oclif';
|
|
3
|
+
export default class Show extends BaseCliRunCommand {
|
|
4
|
+
static enableJsonFlag = true;
|
|
5
|
+
static description = 'Print the freshly generated request for one transaction selector.';
|
|
6
|
+
static examples = [
|
|
7
|
+
'<%= config.bin %> <%= command.id %> "GET /launches -> 200 (application/json)"',
|
|
8
|
+
'<%= config.bin %> <%= command.id %> "DELETE /astronauts/{id} -> 204" --json',
|
|
9
|
+
];
|
|
10
|
+
static args = {
|
|
11
|
+
selector: Args.string({
|
|
12
|
+
required: true,
|
|
13
|
+
description: 'The transaction selector, as METHOD path [(requestMediaType)] -> status [(responseMediaType)].',
|
|
14
|
+
}),
|
|
15
|
+
};
|
|
16
|
+
async run() {
|
|
17
|
+
return this.thymian.run(async (emitter) => {
|
|
18
|
+
await this.thymian.loadFormat({
|
|
19
|
+
inputs: this.thymianConfig.specifications ?? [],
|
|
20
|
+
validateSpecs: this.flags['validate-specs'],
|
|
21
|
+
},
|
|
22
|
+
// The sampler answers from the projection it builds on `core.format`,
|
|
23
|
+
// so the format has to reach it before the selector is resolved.
|
|
24
|
+
{ emitFormat: true });
|
|
25
|
+
const shown = await emitter.emitAction('sampler.show', { selector: this.args.selector }, { strategy: 'first' });
|
|
26
|
+
if (this.jsonEnabled()) {
|
|
27
|
+
return shown;
|
|
28
|
+
}
|
|
29
|
+
this.log(oclif.ux.colorize('bold', shown.selector));
|
|
30
|
+
this.log();
|
|
31
|
+
this.log(JSON.stringify(shown.request, null, 2));
|
|
32
|
+
return shown;
|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AC;gBACvB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;YACpD,IAAI,CAAC,GAAG,EAAE,CAAC;YACX,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAEjD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCliRunCommand, oclif } from '@thymian/common-cli';
|
|
2
|
+
export default class Sync extends BaseCliRunCommand<typeof Sync> {
|
|
3
|
+
static enableJsonFlag: boolean;
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
check: oclif.Interfaces.BooleanFlag<boolean>;
|
|
8
|
+
};
|
|
9
|
+
run(): Promise<unknown>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/sampler/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG/D,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,iBAAiB,CAAC,OAAO,IAAI,CAAC;IAC9D,OAAgB,cAAc,UAAQ;IAEtC,OAAgB,WAAW,SACkD;IAE7E,OAAgB,QAAQ,WAGtB;IAEF,OAAgB,KAAK;;MAMnB;IAEa,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC;CA6EvC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { BaseCliRunCommand, oclif } from '@thymian/common-cli';
|
|
2
|
+
import { Flags } from '@thymian/common-cli/oclif';
|
|
3
|
+
export default class Sync extends BaseCliRunCommand {
|
|
4
|
+
static enableJsonFlag = true;
|
|
5
|
+
static description = 'Regenerate the committed sampler types from the current API description.';
|
|
6
|
+
static examples = [
|
|
7
|
+
'<%= config.bin %> <%= command.id %>',
|
|
8
|
+
'<%= config.bin %> <%= command.id %> --check',
|
|
9
|
+
];
|
|
10
|
+
static flags = {
|
|
11
|
+
check: Flags.boolean({
|
|
12
|
+
default: false,
|
|
13
|
+
description: 'Report whether regeneration would change the committed types, and write nothing. Exits non-zero if it would.',
|
|
14
|
+
}),
|
|
15
|
+
};
|
|
16
|
+
async run() {
|
|
17
|
+
return this.thymian.run(async (emitter) => {
|
|
18
|
+
await this.thymian.loadFormat({
|
|
19
|
+
inputs: this.thymianConfig.specifications ?? [],
|
|
20
|
+
validateSpecs: this.flags['validate-specs'],
|
|
21
|
+
}, { emitFormat: true });
|
|
22
|
+
const result = await emitter.emitAction('sampler.sync', { check: this.flags.check }, { strategy: 'first' });
|
|
23
|
+
if (this.jsonEnabled()) {
|
|
24
|
+
if (this.flags.check && result.changed.length > 0) {
|
|
25
|
+
process.exitCode = 1;
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
if (result.changed.length === 0) {
|
|
30
|
+
this.log('Sampler types are in sync.');
|
|
31
|
+
// The types matched but the bytes moved — a description edit rewrites a
|
|
32
|
+
// JSDoc comment without moving a type. Saying so is the difference
|
|
33
|
+
// between an explained diff and a mysterious one.
|
|
34
|
+
if (result.rewritten && result.rewritten.length > 0) {
|
|
35
|
+
this.log();
|
|
36
|
+
this.log(oclif.ux.colorize('dim', 'Rewritten anyway, with no change to any type — commit or discard as you like:'));
|
|
37
|
+
for (const file of result.rewritten) {
|
|
38
|
+
this.log(oclif.ux.colorize('dim', ` generated/${file}`));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
if (this.flags.check) {
|
|
44
|
+
this.log(oclif.ux.colorize('red', `Sampler types are out of sync:`));
|
|
45
|
+
for (const file of result.changed) {
|
|
46
|
+
this.log(` ${file}`);
|
|
47
|
+
this.log();
|
|
48
|
+
}
|
|
49
|
+
this.guidance('To regenerate the types, run:\n $ thymian sampler sync');
|
|
50
|
+
// `process.exitCode` rather than `this.exit()`: an early exit throws
|
|
51
|
+
// past this run's teardown, and routes through oclif's error path —
|
|
52
|
+
// a feedback prompt and an error-cache record for what is a legitimate
|
|
53
|
+
// gate verdict, not a crash (mirrors `sampler check`'s outcome model).
|
|
54
|
+
process.exitCode = 1;
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
this.log(oclif.ux.colorize('green', 'Regenerated:'));
|
|
58
|
+
for (const file of result.changed) {
|
|
59
|
+
this.log(` ${file}`);
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../../../src/cli/commands/sampler/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAElD,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,iBAA8B;IAC9D,MAAM,CAAU,cAAc,GAAG,IAAI,CAAC;IAEtC,MAAM,CAAU,WAAW,GACzB,0EAA0E,CAAC;IAE7E,MAAM,CAAU,QAAQ,GAAG;QACzB,qCAAqC;QACrC,6CAA6C;KAC9C,CAAC;IAEF,MAAM,CAAU,KAAK,GAAG;QACtB,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC;YACnB,OAAO,EAAE,KAAK;YACd,WAAW,EACT,8GAA8G;SACjH,CAAC;KACH,CAAC;IAEO,KAAK,CAAC,GAAG;QAChB,OAAO,I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,EAAE,eAAe,IAAI,EAAE,CAAC,CAAC,CAAC;oBAC5D,CAAC;gBACH,CAAC;gBAED,OAAO,MAAM,CAAC;YAChB,CAAC;YAED,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;gBACrB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,gCAAgC,CAAC,CAAC,CAAC;gBAErE,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;oBAClC,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;oBACtB,IAAI,CAAC,GAAG,EAAE,CAAC;gBACb,CAAC;gBAED,IAAI,CAAC,QAAQ,CACX,yDAAyD,CAC1D,CAAC;gBAEF,qEAAqE;gBACrE,oEAAoE;gBACpE,uEAAuE;gBACvE,uEAAuE;gBACvE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;gBAErB,OAAO,MAAM,CAAC;YAChB,CAAC;YAED,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;YAErD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBAClC,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;YACxB,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC"}
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import { BaseCliRunCommand
|
|
2
|
-
import type { SamplerValidationReport } from '../../../validation/validate-sampler-output.js';
|
|
1
|
+
import { BaseCliRunCommand } from '@thymian/common-cli';
|
|
3
2
|
export default class Validate extends BaseCliRunCommand<typeof Validate> {
|
|
4
3
|
static enableJsonFlag: boolean;
|
|
5
4
|
static description: string;
|
|
6
|
-
static
|
|
7
|
-
|
|
8
|
-
"for-path": oclif.Interfaces.OptionFlag<string | undefined, oclif.Interfaces.CustomOptions>;
|
|
9
|
-
};
|
|
10
|
-
run(): Promise<SamplerValidationReport>;
|
|
11
|
-
private logFailure;
|
|
12
|
-
private logJsonChanges;
|
|
13
|
-
private logContentField;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
run(): Promise<unknown>;
|
|
14
7
|
}
|
|
15
8
|
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/sampler/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/sampler/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAS,MAAM,qBAAqB,CAAC;AAE/D,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,iBAAiB,CAAC,OAAO,QAAQ,CAAC;IACtE,OAAgB,cAAc,UAAQ;IAEtC,OAAgB,WAAW,SAC4E;IAEvG,OAAgB,QAAQ,WAA2C;IAEpD,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC;CAuHvC"}
|
|
@@ -1,147 +1,78 @@
|
|
|
1
1
|
import { BaseCliRunCommand, oclif } from '@thymian/common-cli';
|
|
2
|
-
import { SEVERITY_COLORS, SEVERITY_SYMBOLS, successSymbol, } from '@thymian/core';
|
|
3
|
-
const { colorize } = oclif.ux;
|
|
4
|
-
// Map each finding to a core report severity so the command reuses the exact
|
|
5
|
-
// colors and symbols of the Thymian report renderer (see report-style.ts)
|
|
6
|
-
// without constructing a Report. A missing/changed artifact is an error; an
|
|
7
|
-
// unexpected extra file is a warning.
|
|
8
|
-
const FINDING_SEVERITY = {
|
|
9
|
-
'missing-artifact': 'error',
|
|
10
|
-
'changed-artifact': 'error',
|
|
11
|
-
'stale-root-metadata': 'error',
|
|
12
|
-
'metadata-out-of-sync': 'error',
|
|
13
|
-
'invalid-json': 'error',
|
|
14
|
-
'unexpected-artifact': 'warn',
|
|
15
|
-
};
|
|
16
2
|
export default class Validate extends BaseCliRunCommand {
|
|
17
3
|
static enableJsonFlag = true;
|
|
18
|
-
static description = '
|
|
19
|
-
static
|
|
20
|
-
['full-diffs']: oclif.Flags.boolean({
|
|
21
|
-
default: false,
|
|
22
|
-
description: 'Show the full diff for every out-of-sync artifact instead of a summary.',
|
|
23
|
-
}),
|
|
24
|
-
['for-path']: oclif.Flags.string({
|
|
25
|
-
description: 'Validate a single generated artifact by its relative path (e.g. meta.json) and show its full diff. Note: the full artifact set is still regenerated internally, so this scopes the output, not the work.',
|
|
26
|
-
}),
|
|
27
|
-
};
|
|
4
|
+
static description = 'Check the sampler hooks against the current API description, and the committed types against both.';
|
|
5
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
28
6
|
async run() {
|
|
29
7
|
return this.thymian.run(async (emitter) => {
|
|
30
|
-
|
|
31
|
-
this.error('Cannot validate sampler if sampler plugin is not registered.', {
|
|
32
|
-
exit: 1,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
const format = await this.thymian.loadFormat({
|
|
8
|
+
await this.thymian.loadFormat({
|
|
36
9
|
inputs: this.thymianConfig.specifications ?? [],
|
|
37
10
|
validateSpecs: this.flags['validate-specs'],
|
|
38
|
-
}, {
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
const forPath = this.flags['for-path'];
|
|
42
|
-
const report = await emitter.emitAction('sampler.validate', {
|
|
43
|
-
format: format.export(),
|
|
44
|
-
...(forPath !== undefined ? { forPath } : {}),
|
|
45
|
-
}, {
|
|
46
|
-
strategy: 'first',
|
|
47
|
-
});
|
|
48
|
-
// A scoped run reports 0 checked artifacts only when the path is not a
|
|
49
|
-
// known generated artifact — surface that as an error in every mode.
|
|
50
|
-
if (forPath !== undefined && report.checkedArtifacts === 0) {
|
|
51
|
-
if (this.jsonEnabled()) {
|
|
52
|
-
// Keep machine output consistent: emit the (empty) report as JSON and
|
|
53
|
-
// signal the usage error through the exit code instead of throwing,
|
|
54
|
-
// which would abort before any JSON is printed.
|
|
55
|
-
process.exitCode = 2;
|
|
56
|
-
return report;
|
|
57
|
-
}
|
|
58
|
-
this.error(`No generated sampler artifact found at path "${forPath}".`, {
|
|
59
|
-
exit: 2,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
11
|
+
}, { emitFormat: true });
|
|
12
|
+
const report = await emitter.emitAction('sampler.validate', {}, { strategy: 'first' });
|
|
62
13
|
if (this.jsonEnabled()) {
|
|
63
|
-
|
|
64
|
-
// Signal failure through the exit code without throwing, because a throw
|
|
65
|
-
// would abort before the JSON is printed.
|
|
66
|
-
if (report.failures.length > 0) {
|
|
14
|
+
if (report.verdict === 'broken' || report.verdict === 'drifted') {
|
|
67
15
|
process.exitCode = 1;
|
|
68
16
|
}
|
|
69
17
|
return report;
|
|
70
18
|
}
|
|
71
|
-
|
|
72
|
-
this.log(
|
|
73
|
-
? `Generated sampler artifact "${forPath}" is in sync.`
|
|
74
|
-
: `Sampler validation passed: ${report.checkedArtifacts} generated artifacts are in sync.`}`);
|
|
75
|
-
return report;
|
|
76
|
-
}
|
|
77
|
-
// `--for-path` targets one artifact, so its diff is always shown;
|
|
78
|
-
// otherwise details are opt-in via `--full-diffs`.
|
|
79
|
-
const showDiffs = this.flags['full-diffs'] || forPath !== undefined;
|
|
80
|
-
for (const failure of report.failures) {
|
|
81
|
-
this.logFailure(failure, showDiffs);
|
|
19
|
+
for (const warning of report.warnings) {
|
|
20
|
+
this.log(oclif.ux.colorize('yellow', `! ${warning}`));
|
|
82
21
|
}
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
22
|
+
for (const problem of [
|
|
23
|
+
...report.unresolved,
|
|
24
|
+
...report.conflicts,
|
|
25
|
+
...report.unexported,
|
|
26
|
+
]) {
|
|
27
|
+
const where = problem.exportName
|
|
28
|
+
? `${problem.file} (export "${problem.exportName}")`
|
|
29
|
+
: problem.file;
|
|
30
|
+
this.log(oclif.ux.colorize('red', `✖ ${where}: ${problem.reason}`));
|
|
31
|
+
for (const suggestion of problem.suggestions ?? []) {
|
|
32
|
+
this.log(oclif.ux.colorize('dim', ` ${suggestion}`));
|
|
33
|
+
}
|
|
93
34
|
}
|
|
94
|
-
|
|
95
|
-
|
|
35
|
+
for (const error of report.typeErrors) {
|
|
36
|
+
this.log(oclif.ux.colorize('red', `✖ ${error.file}:${error.line}:${error.column} — TS${error.code}: ${error.message}`));
|
|
96
37
|
}
|
|
97
|
-
this.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
this.log(colorize(SEVERITY_COLORS.info, ` ${failure.message}`));
|
|
111
|
-
if (failure.changes && failure.changes.length > 0) {
|
|
112
|
-
this.logJsonChanges(failure.changes);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
this.logContentField('expected', failure.expected);
|
|
116
|
-
this.logContentField('actual', failure.actual);
|
|
117
|
-
}
|
|
118
|
-
this.log();
|
|
119
|
-
}
|
|
120
|
-
logJsonChanges(changes) {
|
|
121
|
-
this.log(colorize(SEVERITY_COLORS.info, ' JSON changes:'));
|
|
122
|
-
for (const change of changes) {
|
|
123
|
-
const pointer = change.pointer || '/';
|
|
124
|
-
let detail;
|
|
125
|
-
if (change.type === 'add') {
|
|
126
|
-
detail = `[add] ${pointer} → ${JSON.stringify(change.actual)}`;
|
|
38
|
+
// `process.exitCode` rather than `this.exit()` for both verdicts below:
|
|
39
|
+
// an early exit throws past this run's teardown and routes through
|
|
40
|
+
// oclif's error path — a feedback prompt and an error-cache record for
|
|
41
|
+
// what is a legitimate gate verdict, not a crash (mirrors `sampler
|
|
42
|
+
// check`'s outcome model).
|
|
43
|
+
if (report.verdict === 'drifted') {
|
|
44
|
+
this.log();
|
|
45
|
+
this.log('Breaking drift: the API description no longer matches these hooks.');
|
|
46
|
+
this.log('Fix them, run "thymian sampler sync", and commit the result.');
|
|
47
|
+
process.exitCode = 1;
|
|
48
|
+
return report;
|
|
127
49
|
}
|
|
128
|
-
|
|
129
|
-
|
|
50
|
+
if (report.verdict === 'broken') {
|
|
51
|
+
this.log();
|
|
52
|
+
this.log('These hooks do not compile against the current API description.');
|
|
53
|
+
// Deliberately not "run sync": the committed types already match the
|
|
54
|
+
// description, so regenerating would rewrite correct files and leave
|
|
55
|
+
// the real error exactly where it is.
|
|
56
|
+
this.log(report.surface === 'absent'
|
|
57
|
+
? 'Fix them. Nothing is committed, so there is nothing to regenerate.'
|
|
58
|
+
: 'Fix them. The committed types are already in sync — there is no drift to resolve.');
|
|
59
|
+
process.exitCode = 1;
|
|
60
|
+
return report;
|
|
130
61
|
}
|
|
131
|
-
|
|
132
|
-
|
|
62
|
+
if (report.verdict === 'stale') {
|
|
63
|
+
this.log(oclif.ux.colorize('yellow', '! The committed sampler types are behind this API description, but every hook still compiles:'));
|
|
64
|
+
for (const file of report.changedFiles) {
|
|
65
|
+
this.log(oclif.ux.colorize('dim', ` generated/${file}`));
|
|
66
|
+
}
|
|
67
|
+
this.log();
|
|
68
|
+
this.log('Run "thymian sampler sync" and commit the result.');
|
|
69
|
+
return report;
|
|
133
70
|
}
|
|
134
|
-
this.log(colorize(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
this.log(colorize(SEVERITY_COLORS.info, ` ${label}:`));
|
|
142
|
-
for (const line of value.split('\n')) {
|
|
143
|
-
this.log(colorize(SEVERITY_COLORS.info, ` ${line}`));
|
|
144
|
-
}
|
|
71
|
+
this.log(oclif.ux.colorize('green', report.surface === 'absent'
|
|
72
|
+
? 'Every hook resolves. Run "thymian sampler init" for editor support and a type gate.'
|
|
73
|
+
: 'Every hook resolves and the committed types match this API description.'));
|
|
74
|
+
return report;
|
|
75
|
+
});
|
|
145
76
|
}
|
|
146
77
|
}
|
|
147
78
|
//# sourceMappingURL=validate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../../src/cli/commands/sampler/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../../src/cli/commands/sampler/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE/D,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,iBAAkC;IACtE,MAAM,CAAU,cAAc,GAAG,IAAI,CAAC;IAEtC,MAAM,CAAU,WAAW,GACzB,oGAAoG,CAAC;IAEvG,MAAM,CAAU,QAAQ,GAAG,CAAC,qCAAqC,CAAC,CAAC;IAE1D,KAAK,CAAC,GAAG;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YACxC,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAC3B;gBACE,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,cAAc,IAAI,EAAE;gBAC/C,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC;aAC5C,EACD,EAAE,UAAU,EAAE,IAAI,EAAE,CACrB,CAAC;YAEF,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,UAAU,CACrC,kBAAkB,EAClB,EAAE,EACF,EAAE,QAAQ,EAAE,OAAO,EAAE,CACtB,CAAC;YAEF,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;gBACvB,IAAI,MAAM,CAAC,OAAO,KAAK,QAAQ,IAA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9D,OAAO,MAAM,CAAC;YAChB,CAAC;YAED,IAAI,CAAC,GAAG,CACN,KAAK,CAAC,EAAE,CAAC,QAAQ,CACf,OAAO,EACP,MAAM,CAAC,OAAO,KAAK,QAAQ;gBACzB,CAAC,CAAC,qFAAqF;gBACvF,CAAC,CAAC,yEAAyE,CAC9E,CACF,CAAC;YAEF,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Restores the boolean form of a schema that forbids everything.
|
|
3
|
+
*
|
|
4
|
+
* `additionalProperties: false` reaches the sampler as `{ not: {} }`, which is
|
|
5
|
+
* the correct JSON Schema for it (`plugin-openapi`'s `normalizeSchema` turns
|
|
6
|
+
* every boolean schema into its object form). Two consumers misread it, since
|
|
7
|
+
* both treat any object in that position as a value schema:
|
|
8
|
+
*
|
|
9
|
+
* - the type emitter emits `[k: string]: { [k: string]: unknown }`, an index
|
|
10
|
+
* signature that every declared property then fails to satisfy — `TS2411`,
|
|
11
|
+
* six times over on the demo description;
|
|
12
|
+
* - `openapi-sampler` invents `property1`, `property2` for it, which the same
|
|
13
|
+
* schema forbids.
|
|
14
|
+
*
|
|
15
|
+
* Handed the boolean, the emitter emits no index signature and the sampler
|
|
16
|
+
* invents nothing, which is what a closed object is.
|
|
17
|
+
*
|
|
18
|
+
* Only this position is rewritten. `{ not: {} }` elsewhere means `never`, which
|
|
19
|
+
* the emitter is free to render however it likes.
|
|
20
|
+
*/
|
|
21
|
+
export declare function closedObjectsToBoolean(input: unknown): unknown;
|
|
22
|
+
//# sourceMappingURL=closed-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"closed-schema.d.ts","sourceRoot":"","sources":["../../src/generation/closed-schema.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAmB9D"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { isRecord } from '@thymian/core';
|
|
2
|
+
/**
|
|
3
|
+
* Restores the boolean form of a schema that forbids everything.
|
|
4
|
+
*
|
|
5
|
+
* `additionalProperties: false` reaches the sampler as `{ not: {} }`, which is
|
|
6
|
+
* the correct JSON Schema for it (`plugin-openapi`'s `normalizeSchema` turns
|
|
7
|
+
* every boolean schema into its object form). Two consumers misread it, since
|
|
8
|
+
* both treat any object in that position as a value schema:
|
|
9
|
+
*
|
|
10
|
+
* - the type emitter emits `[k: string]: { [k: string]: unknown }`, an index
|
|
11
|
+
* signature that every declared property then fails to satisfy — `TS2411`,
|
|
12
|
+
* six times over on the demo description;
|
|
13
|
+
* - `openapi-sampler` invents `property1`, `property2` for it, which the same
|
|
14
|
+
* schema forbids.
|
|
15
|
+
*
|
|
16
|
+
* Handed the boolean, the emitter emits no index signature and the sampler
|
|
17
|
+
* invents nothing, which is what a closed object is.
|
|
18
|
+
*
|
|
19
|
+
* Only this position is rewritten. `{ not: {} }` elsewhere means `never`, which
|
|
20
|
+
* the emitter is free to render however it likes.
|
|
21
|
+
*/
|
|
22
|
+
export function closedObjectsToBoolean(input) {
|
|
23
|
+
if (Array.isArray(input)) {
|
|
24
|
+
return input.map(closedObjectsToBoolean);
|
|
25
|
+
}
|
|
26
|
+
if (!isRecord(input)) {
|
|
27
|
+
return input;
|
|
28
|
+
}
|
|
29
|
+
const out = {};
|
|
30
|
+
for (const [key, value] of Object.entries(input)) {
|
|
31
|
+
out[key] =
|
|
32
|
+
key === 'additionalProperties' && forbidsEverything(value)
|
|
33
|
+
? false
|
|
34
|
+
: closedObjectsToBoolean(value);
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
/** Whether a schema admits no value at all, in the shape normalization emits. */
|
|
39
|
+
function forbidsEverything(schema) {
|
|
40
|
+
return (isRecord(schema) &&
|
|
41
|
+
Object.keys(schema).length === 1 &&
|
|
42
|
+
isRecord(schema['not']) &&
|
|
43
|
+
Object.keys(schema['not']).length === 0);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=closed-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"closed-schema.js","sourceRoot":"","sources":["../../src/generation/closed-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACnD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IAC3C,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,GAAG,GAA4B,EAAE,CAAC;IAExC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,GAAG,CAAC,GAAG,CAAC;YACN,GAAG,KAAK,sBAAsB,IAAI,iBAAiB,CAAC,KAAK,CAAC;gBACxD,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,iFAAiF;AACjF,SAAS,iBAAiB,CAAC,MAAe;IACxC,OAAO,CACL,QAAQ,CAAC,MAAM,CAAC;QAChB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC;QAChC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CACxC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.content-type-strategy.d.ts","sourceRoot":"","sources":["../../../src/generation/content-type-strategies/json.content-type-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"json.content-type-strategy.d.ts","sourceRoot":"","sources":["../../../src/generation/content-type-strategies/json.content-type-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAItE,qBAAa,uBAAwB,YAAW,mBAAmB;IACjE,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAI/B,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;CAO9D"}
|