@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
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { Selector } from '../selectors/selector.js';
|
|
2
|
+
import type { TransactionFilter } from '../selectors/transaction-filter.js';
|
|
3
|
+
/**
|
|
4
|
+
* The brand every registration carries.
|
|
5
|
+
*
|
|
6
|
+
* `Symbol.for` rather than a fresh symbol: the plugin's jiti instance evaluates
|
|
7
|
+
* the hooks runtime in its own module registry, so a hook file and the loader
|
|
8
|
+
* hold different module instances of that file. A registry-local symbol would
|
|
9
|
+
* differ between them; a well-known one is the same symbol in both realms.
|
|
10
|
+
*/
|
|
11
|
+
export declare const HOOK_REGISTRATION: unique symbol;
|
|
12
|
+
export type HookKind = 'defineSample' | 'beforeEach' | 'afterEach' | 'authorize' | 'beforeAll' | 'afterAll';
|
|
13
|
+
/**
|
|
14
|
+
* What a per-transaction hook is aimed at: exactly one Transaction by Selector,
|
|
15
|
+
* several by a list of them, or a set by a filter.
|
|
16
|
+
*/
|
|
17
|
+
export type HookTarget = Selector | readonly Selector[] | TransactionFilter;
|
|
18
|
+
/**
|
|
19
|
+
* Callbacks are stored, never inspected. Each kind's precise signature is the
|
|
20
|
+
* runner's contract, and the generated `.d.ts` is what types it for the author;
|
|
21
|
+
* here they only have to be functions.
|
|
22
|
+
*/
|
|
23
|
+
export type HookCallback = (...args: never[]) => unknown;
|
|
24
|
+
type Brand = {
|
|
25
|
+
readonly [HOOK_REGISTRATION]: true;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* One hook, as a value.
|
|
29
|
+
*
|
|
30
|
+
* A registration is **returned**, not pushed into an ambient registry, because
|
|
31
|
+
* discovery is export-based: a module-scope registry in the loader's realm is
|
|
32
|
+
* not the one a hook file writing `@thymian/hooks` would reach. `order` is
|
|
33
|
+
* stamped at creation and is monotonic within the realm that evaluated the file,
|
|
34
|
+
* which is what gives composition an order that does not depend on
|
|
35
|
+
* `Object.keys(namespace)` — an ESM namespace exposes its keys sorted, so export
|
|
36
|
+
* order is not registration order.
|
|
37
|
+
*/
|
|
38
|
+
export type HookRegistration = Brand & ({
|
|
39
|
+
kind: 'defineSample';
|
|
40
|
+
order: number;
|
|
41
|
+
target: HookTarget;
|
|
42
|
+
callback: HookCallback;
|
|
43
|
+
} | {
|
|
44
|
+
kind: 'beforeEach';
|
|
45
|
+
order: number;
|
|
46
|
+
target: HookTarget;
|
|
47
|
+
callback: HookCallback;
|
|
48
|
+
} | {
|
|
49
|
+
kind: 'afterEach';
|
|
50
|
+
order: number;
|
|
51
|
+
target: HookTarget;
|
|
52
|
+
callback: HookCallback;
|
|
53
|
+
} | {
|
|
54
|
+
kind: 'authorize';
|
|
55
|
+
order: number;
|
|
56
|
+
target: HookTarget | undefined;
|
|
57
|
+
callback: HookCallback;
|
|
58
|
+
} | {
|
|
59
|
+
kind: 'beforeAll';
|
|
60
|
+
order: number;
|
|
61
|
+
callback: HookCallback;
|
|
62
|
+
} | {
|
|
63
|
+
kind: 'afterAll';
|
|
64
|
+
order: number;
|
|
65
|
+
callback: HookCallback;
|
|
66
|
+
});
|
|
67
|
+
/** What a factory hands to {@link registerHook}: the record minus brand and order. */
|
|
68
|
+
export type HookRegistrationDraft = {
|
|
69
|
+
kind: 'defineSample';
|
|
70
|
+
target: HookTarget;
|
|
71
|
+
callback: HookCallback;
|
|
72
|
+
} | {
|
|
73
|
+
kind: 'beforeEach';
|
|
74
|
+
target: HookTarget;
|
|
75
|
+
callback: HookCallback;
|
|
76
|
+
} | {
|
|
77
|
+
kind: 'afterEach';
|
|
78
|
+
target: HookTarget;
|
|
79
|
+
callback: HookCallback;
|
|
80
|
+
} | {
|
|
81
|
+
kind: 'authorize';
|
|
82
|
+
target: HookTarget | undefined;
|
|
83
|
+
callback: HookCallback;
|
|
84
|
+
} | {
|
|
85
|
+
kind: 'beforeAll';
|
|
86
|
+
callback: HookCallback;
|
|
87
|
+
} | {
|
|
88
|
+
kind: 'afterAll';
|
|
89
|
+
callback: HookCallback;
|
|
90
|
+
};
|
|
91
|
+
/** Every registration created so far, oldest first. Mutable on purpose. */
|
|
92
|
+
export declare function createdRegistrations(): HookRegistration[];
|
|
93
|
+
/** Freezes a draft into a branded, ordered registration. */
|
|
94
|
+
export declare function registerHook(draft: HookRegistrationDraft): HookRegistration;
|
|
95
|
+
/**
|
|
96
|
+
* Is this value a registration produced by the hooks runtime?
|
|
97
|
+
*
|
|
98
|
+
* The `typeof value !== 'object'` test rejects functions before anything else,
|
|
99
|
+
* which makes "a function is never invoked to discover a hook" a structural
|
|
100
|
+
* property of this predicate rather than a discipline to remember. The brand is
|
|
101
|
+
* compared `=== true`, so a same-keyed symbol carrying some other value cannot
|
|
102
|
+
* pass by accident, and a plain object that merely has a `kind` string is not a
|
|
103
|
+
* hook. The read is guarded because a user export may be a Proxy or an accessor
|
|
104
|
+
* that throws.
|
|
105
|
+
*/
|
|
106
|
+
export declare function isHookRegistration(value: unknown): value is HookRegistration;
|
|
107
|
+
export {};
|
|
108
|
+
//# sourceMappingURL=hook-registration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-registration.d.ts","sourceRoot":"","sources":["../../src/hooks/hook-registration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAE5E;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,EAAE,OAAO,MAEtC,CAAC;AAEF,MAAM,MAAM,QAAQ,GAChB,cAAc,GACd,YAAY,GACZ,WAAW,GACX,WAAW,GACX,WAAW,GACX,UAAU,CAAC;AAEf;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,SAAS,QAAQ,EAAE,GAAG,iBAAiB,CAAC;AAE5E;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;AAEzD,KAAK,KAAK,GAAG;IAAE,QAAQ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,GACjE;IACE,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,EAAE,UAAU,GAAG,SAAS,CAAC;IAC/B,QAAQ,EAAE,YAAY,CAAC;CACxB,GACD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,YAAY,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,YAAY,CAAA;CAAE,CAAC;AA8BjD,2EAA2E;AAC3E,wBAAgB,oBAAoB,IAAI,gBAAgB,EAAE,CAIzD;AAED,4DAA4D;AAC5D,wBAAgB,YAAY,CAAC,KAAK,EAAE,qBAAqB,GAAG,gBAAgB,CAc3E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAU5E"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The brand every registration carries.
|
|
3
|
+
*
|
|
4
|
+
* `Symbol.for` rather than a fresh symbol: the plugin's jiti instance evaluates
|
|
5
|
+
* the hooks runtime in its own module registry, so a hook file and the loader
|
|
6
|
+
* hold different module instances of that file. A registry-local symbol would
|
|
7
|
+
* differ between them; a well-known one is the same symbol in both realms.
|
|
8
|
+
*/
|
|
9
|
+
export const HOOK_REGISTRATION = Symbol.for('@thymian/plugin-sampler.hook-registration');
|
|
10
|
+
let nextOrder = 0;
|
|
11
|
+
/**
|
|
12
|
+
* Where every registration created in this process is recorded, so the loader
|
|
13
|
+
* can tell a hook that was *created* from one that was *exported*.
|
|
14
|
+
*
|
|
15
|
+
* `beforeEach(...)` written without `export const x =` compiles, runs, creates
|
|
16
|
+
* a registration — and is then unreachable, because discovery is export-based.
|
|
17
|
+
* Nothing failed, so nothing was reported: the hook simply never fired.
|
|
18
|
+
*
|
|
19
|
+
* On `globalThis` under a well-known symbol, for the same reason
|
|
20
|
+
* {@link HOOK_REGISTRATION} is: the loader's jiti instance evaluates this
|
|
21
|
+
* module in its own registry, and evicts it after every scan, so a
|
|
22
|
+
* module-scope array would be a different array per scan and never the one
|
|
23
|
+
* the loader itself imported. `globalThis` is the one thing all of those
|
|
24
|
+
* evaluations share.
|
|
25
|
+
*
|
|
26
|
+
* The loader empties it at the start of each scan and reads it per file, so it
|
|
27
|
+
* holds one scan's worth of registrations rather than the process's.
|
|
28
|
+
*/
|
|
29
|
+
const CREATED_REGISTRATIONS = Symbol.for('@thymian/plugin-sampler.created-registrations');
|
|
30
|
+
/** Every registration created so far, oldest first. Mutable on purpose. */
|
|
31
|
+
export function createdRegistrations() {
|
|
32
|
+
const channel = globalThis;
|
|
33
|
+
return (channel[CREATED_REGISTRATIONS] ??= []);
|
|
34
|
+
}
|
|
35
|
+
/** Freezes a draft into a branded, ordered registration. */
|
|
36
|
+
export function registerHook(draft) {
|
|
37
|
+
const order = nextOrder;
|
|
38
|
+
nextOrder = order + 1;
|
|
39
|
+
const registration = Object.freeze({
|
|
40
|
+
...draft,
|
|
41
|
+
order,
|
|
42
|
+
[HOOK_REGISTRATION]: true,
|
|
43
|
+
});
|
|
44
|
+
createdRegistrations().push(registration);
|
|
45
|
+
return registration;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Is this value a registration produced by the hooks runtime?
|
|
49
|
+
*
|
|
50
|
+
* The `typeof value !== 'object'` test rejects functions before anything else,
|
|
51
|
+
* which makes "a function is never invoked to discover a hook" a structural
|
|
52
|
+
* property of this predicate rather than a discipline to remember. The brand is
|
|
53
|
+
* compared `=== true`, so a same-keyed symbol carrying some other value cannot
|
|
54
|
+
* pass by accident, and a plain object that merely has a `kind` string is not a
|
|
55
|
+
* hook. The read is guarded because a user export may be a Proxy or an accessor
|
|
56
|
+
* that throws.
|
|
57
|
+
*/
|
|
58
|
+
export function isHookRegistration(value) {
|
|
59
|
+
if (typeof value !== 'object' || value === null) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
return value[HOOK_REGISTRATION] === true;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=hook-registration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-registration.js","sourceRoot":"","sources":["../../src/hooks/hook-registration.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAkB,MAAM,CAAC,GAAG,CACxD,2CAA2C,CAC5C,CAAC;AA+EF,IAAI,SAAS,GAAG,CAAC,CAAC;AAElB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,qBAAqB,GAAkB,MAAM,CAAC,GAAG,CACrD,+CAA+C,CAChD,CAAC;AAMF,2EAA2E;AAC3E,MAAM,UAAU,oBAAoB;IAClC,MAAM,OAAO,GAAG,UAAkC,CAAC;IAEnD,OAAO,CAAC,OAAO,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC,CAAC;AACjD,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,YAAY,CAAC,KAA4B;IACvD,MAAM,KAAK,GAAG,SAAS,CAAC;IAExB,SAAS,GAAG,KAAK,GAAG,CAAC,CAAC;IAEtB,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;QACjC,GAAG,KAAK;QACR,KAAK;QACL,CAAC,iBAAiB,CAAC,EAAE,IAAI;KAC1B,CAAqB,CAAC;IAEvB,oBAAoB,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAE1C,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC;QACH,OAAQ,KAAsC,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;IAC7E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -1,18 +1,118 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
import type
|
|
1
|
+
import { type HttpRequest, type HttpRequestTemplate, type HttpResponse, type HttpTestHooks, type Logger, ThymianFormat, type ThymianHttpTransaction } from '@thymian/core';
|
|
2
|
+
import { TransactionCatalog } from '../selectors/transaction-catalog.js';
|
|
3
|
+
import { type LoadUserHooksResult } from './load-user-hooks.js';
|
|
4
|
+
/** What the runner needs from the rest of the plugin to send a request. */
|
|
5
|
+
export type HookRunnerPorts = {
|
|
6
|
+
/** The freshly generated request for one transaction. */
|
|
7
|
+
sampleRequest: (transaction: ThymianHttpTransaction) => Promise<HttpRequestTemplate>;
|
|
8
|
+
/** Puts a serialized request on the wire. */
|
|
9
|
+
dispatch: (request: HttpRequest) => Promise<HttpResponse>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Runs the user's hooks at the http-testing seams.
|
|
13
|
+
*
|
|
14
|
+
* Holds the bindings the loader produced and nothing else: an unbound
|
|
15
|
+
* Transaction simply has no hooks, which is the pass-through case, so there is
|
|
16
|
+
* no "not initialized" state to guard against.
|
|
17
|
+
*/
|
|
4
18
|
export declare class HookRunner {
|
|
5
|
-
private readonly path;
|
|
6
|
-
private readonly runRequest;
|
|
7
19
|
private readonly logger;
|
|
8
|
-
private
|
|
9
|
-
private hooks;
|
|
10
|
-
private urlToTransactionId;
|
|
20
|
+
private readonly ports;
|
|
11
21
|
private format;
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
private catalog;
|
|
23
|
+
private byTransactionId;
|
|
24
|
+
private globalAuthorize;
|
|
25
|
+
private readonly runScoped;
|
|
26
|
+
/**
|
|
27
|
+
* The origin this run is actually talking to — a `--target-url` override or
|
|
28
|
+
* a configured target, same as the server the description names when
|
|
29
|
+
* neither is set — so a run-scoped hook's seed goes where the run goes
|
|
30
|
+
* rather than where the description points.
|
|
31
|
+
*
|
|
32
|
+
* Captured once, from the very first request. "Before the run" has no
|
|
33
|
+
* meaning until something decides when the run starts, and the sampler's
|
|
34
|
+
* first observation of a run is its first request, so this is captured in
|
|
35
|
+
* lockstep with {@link RunScopedHooks.start}'s latch, in
|
|
36
|
+
* {@link beforeEachRequest}.
|
|
37
|
+
*
|
|
38
|
+
* **One origin per run**, which is a simplification the CLI does not
|
|
39
|
+
* currently expose: a format assembled from several descriptions may name
|
|
40
|
+
* different servers per transaction, and a `beforeAll` seed would still be
|
|
41
|
+
* sent to whichever origin the first request happened to use rather than to
|
|
42
|
+
* its own transaction's server. Per-request hooks are unaffected — they read
|
|
43
|
+
* the origin off the request in front of them. Reset on {@link load}, so the
|
|
44
|
+
* value never outlives the run that observed it.
|
|
45
|
+
*/
|
|
46
|
+
private runOrigin;
|
|
47
|
+
constructor(logger: Logger, ports: HookRunnerPorts);
|
|
48
|
+
/** Adopt a newly loaded format and the hooks bound against it. */
|
|
49
|
+
load(format: ThymianFormat, catalog: TransactionCatalog, hooks?: LoadUserHooksResult): void;
|
|
50
|
+
/**
|
|
51
|
+
* Teardown, on `core.close`. A no-op when no request was ever sent, so a
|
|
52
|
+
* non-test command never runs somebody's teardown.
|
|
53
|
+
*/
|
|
54
|
+
close(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* The `utils` a hook with no request to shape gets: the run-scoped pair. A
|
|
57
|
+
* nested request is available, because a `beforeAll` seeding the API is the
|
|
58
|
+
* reason `utils.request` exists. `dir` comes from the registration's own
|
|
59
|
+
* file, not the process's working directory, so a run-scoped hook's file
|
|
60
|
+
* helpers resolve the same way a per-Transaction hook's do.
|
|
61
|
+
*/
|
|
62
|
+
private readonly utilsFactory;
|
|
63
|
+
/**
|
|
64
|
+
* Shape one request draft with its Transaction's `defineSample` hook, if it
|
|
65
|
+
* has one. This is what `RequestSampler` calls at generation time; the sampler
|
|
66
|
+
* itself knows nothing about hooks.
|
|
67
|
+
*
|
|
68
|
+
* Runs through the same attribution wrapper as every other kind: a throwing
|
|
69
|
+
* `defineSample` used to escape here as a raw error with no pointer to the
|
|
70
|
+
* hook that threw it, misattributed by whatever generic handler caught it
|
|
71
|
+
* further up.
|
|
72
|
+
*/
|
|
73
|
+
readonly shapeSample: (draft: HttpRequestTemplate, transactionId: string) => Promise<void>;
|
|
74
|
+
private hooksFor;
|
|
75
|
+
private callContext;
|
|
76
|
+
beforeEachRequest(hook: HttpTestHooks['beforeRequest']['arg']): Promise<HttpTestHooks['beforeRequest']['return']>;
|
|
14
77
|
afterEachResponse(hook: HttpTestHooks['afterResponse']['arg']): Promise<HttpTestHooks['afterResponse']['return']>;
|
|
15
78
|
authorize(hook: HttpTestHooks['authorize']['arg']): Promise<HttpTestHooks['authorize']['return']>;
|
|
16
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Which authorize hook supplies this Transaction's credentials.
|
|
81
|
+
*
|
|
82
|
+
* A targeted hook wins over the global one for the Transactions it covers, and
|
|
83
|
+
* within each tier the last registration wins, so a later file can override an
|
|
84
|
+
* earlier one. Exactly one hook runs: authorization is "who am I", and
|
|
85
|
+
* composing two answers would mean two sets of credentials on one request.
|
|
86
|
+
*
|
|
87
|
+
* Whether it runs at all is not decided here — core runs this seam only when
|
|
88
|
+
* the run option and the request's own `authorize` flag agree — so a
|
|
89
|
+
* registered hook is necessary but not sufficient, which is what makes
|
|
90
|
+
* "force on" need both.
|
|
91
|
+
*/
|
|
92
|
+
private authorizeFor;
|
|
93
|
+
/**
|
|
94
|
+
* The chain a hook of `transaction` runs with: the Transaction's own Selector,
|
|
95
|
+
* so a hook that seeds itself is caught on the first step.
|
|
96
|
+
*/
|
|
97
|
+
private chainFor;
|
|
98
|
+
/**
|
|
99
|
+
* Run a kind's hooks in order over one value, and translate whatever comes
|
|
100
|
+
* back into the shape the http-testing seam expects.
|
|
101
|
+
*
|
|
102
|
+
* Every hook **mutates `value` in place**; the callback's return value is
|
|
103
|
+
* deliberately discarded (see {@link invokeHook}).
|
|
104
|
+
*/
|
|
105
|
+
private compose;
|
|
106
|
+
/**
|
|
107
|
+
* Send a request to another Transaction, addressed by its Selector.
|
|
108
|
+
*
|
|
109
|
+
* By default the nested request runs the target's own
|
|
110
|
+
* `beforeEach → authorize → afterEach` pipeline, so seeding behaves like the
|
|
111
|
+
* real run rather than like a second, quieter client. `runHooks: false` sends
|
|
112
|
+
* the generated request as-is, which is also the way out of a cycle.
|
|
113
|
+
*/
|
|
114
|
+
private runNested;
|
|
115
|
+
/** Whether the target's operation declares a response with this status. */
|
|
116
|
+
private declaresStatus;
|
|
17
117
|
}
|
|
18
118
|
//# sourceMappingURL=hook-runner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook-runner.d.ts","sourceRoot":"","sources":["../../src/hooks/hook-runner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hook-runner.d.ts","sourceRoot":"","sources":["../../src/hooks/hook-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EAEjB,KAAK,aAAa,EAClB,KAAK,MAAM,EAEX,aAAa,EACb,KAAK,sBAAsB,EAC5B,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAoBzE,OAAO,EAEL,KAAK,mBAAmB,EAEzB,MAAM,sBAAsB,CAAC;AAgB9B,2EAA2E;AAC3E,MAAM,MAAM,eAAe,GAAG;IAC5B,yDAAyD;IACzD,aAAa,EAAE,CACb,WAAW,EAAE,sBAAsB,KAChC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAClC,6CAA6C;IAC7C,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;CAC3D,CAAC;AAEF;;;;;;GAMG;AACH,qBAAa,UAAU;IAgCnB,OAAO,CAAC,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