@thymian/plugin-sampler 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/cli/commands/sampler/hooks/generate.d.ts +9 -0
- package/dist/cli/commands/sampler/hooks/generate.d.ts.map +1 -0
- package/dist/cli/commands/sampler/hooks/generate.js +18 -0
- package/dist/cli/commands/sampler/hooks/generate.js.map +1 -0
- package/dist/cli/commands/sampler/init.d.ts +9 -0
- package/dist/cli/commands/sampler/init.d.ts.map +1 -0
- package/dist/cli/commands/sampler/init.js +55 -0
- package/dist/cli/commands/sampler/init.js.map +1 -0
- package/dist/cli/create-context.d.ts +3 -0
- package/dist/cli/create-context.d.ts.map +1 -0
- package/dist/cli/create-context.js +21 -0
- package/dist/cli/create-context.js.map +1 -0
- package/dist/cli/generate-hook.d.ts +4 -0
- package/dist/cli/generate-hook.d.ts.map +1 -0
- package/dist/cli/generate-hook.js +92 -0
- package/dist/cli/generate-hook.js.map +1 -0
- package/dist/cli/templates.d.ts +4 -0
- package/dist/cli/templates.d.ts.map +1 -0
- package/dist/cli/templates.js +28 -0
- package/dist/cli/templates.js.map +1 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/generation/content-source-generator.d.ts +10 -0
- package/dist/generation/content-source-generator.d.ts.map +1 -0
- package/dist/generation/content-source-generator.js +15 -0
- package/dist/generation/content-source-generator.js.map +1 -0
- package/dist/generation/content-type-strategies/content-type-strategy.d.ts +7 -0
- package/dist/generation/content-type-strategies/content-type-strategy.d.ts.map +1 -0
- package/dist/generation/content-type-strategies/content-type-strategy.js +2 -0
- package/dist/generation/content-type-strategies/content-type-strategy.js.map +1 -0
- package/dist/generation/content-type-strategies/error.content-type-strategy.d.ts +7 -0
- package/dist/generation/content-type-strategies/error.content-type-strategy.d.ts.map +1 -0
- package/dist/generation/content-type-strategies/error.content-type-strategy.js +13 -0
- package/dist/generation/content-type-strategies/error.content-type-strategy.js.map +1 -0
- package/dist/generation/content-type-strategies/hook.content-type-strategy.d.ts +10 -0
- package/dist/generation/content-type-strategies/hook.content-type-strategy.d.ts.map +1 -0
- package/dist/generation/content-type-strategies/hook.content-type-strategy.js +27 -0
- package/dist/generation/content-type-strategies/hook.content-type-strategy.js.map +1 -0
- package/dist/generation/content-type-strategies/image.content-type-strategy.d.ts +15 -0
- package/dist/generation/content-type-strategies/image.content-type-strategy.d.ts.map +1 -0
- package/dist/generation/content-type-strategies/image.content-type-strategy.js +40 -0
- package/dist/generation/content-type-strategies/image.content-type-strategy.js.map +1 -0
- package/dist/generation/content-type-strategies/json.content-type-strategy.d.ts +8 -0
- package/dist/generation/content-type-strategies/json.content-type-strategy.d.ts.map +1 -0
- package/dist/generation/content-type-strategies/json.content-type-strategy.js +12 -0
- package/dist/generation/content-type-strategies/json.content-type-strategy.js.map +1 -0
- package/dist/generation/content-type-strategies/text.content-type-strategy.d.ts +8 -0
- package/dist/generation/content-type-strategies/text.content-type-strategy.d.ts.map +1 -0
- package/dist/generation/content-type-strategies/text.content-type-strategy.js +13 -0
- package/dist/generation/content-type-strategies/text.content-type-strategy.js.map +1 -0
- package/dist/generation/content-type-strategies/xml.content-type-strategy.d.ts +8 -0
- package/dist/generation/content-type-strategies/xml.content-type-strategy.d.ts.map +1 -0
- package/dist/generation/content-type-strategies/xml.content-type-strategy.js +14 -0
- package/dist/generation/content-type-strategies/xml.content-type-strategy.js.map +1 -0
- package/dist/generation/generate-samples-for-thymian-format.d.ts +4 -0
- package/dist/generation/generate-samples-for-thymian-format.d.ts.map +1 -0
- package/dist/generation/generate-samples-for-thymian-format.js +18 -0
- package/dist/generation/generate-samples-for-thymian-format.js.map +1 -0
- package/dist/generation/generate-samples.d.ts +4 -0
- package/dist/generation/generate-samples.d.ts.map +1 -0
- package/dist/generation/generate-samples.js +26 -0
- package/dist/generation/generate-samples.js.map +1 -0
- package/dist/generation/request-generators/default-request-generator.d.ts +22 -0
- package/dist/generation/request-generators/default-request-generator.d.ts.map +1 -0
- package/dist/generation/request-generators/default-request-generator.js +80 -0
- package/dist/generation/request-generators/default-request-generator.js.map +1 -0
- package/dist/generation/request-generators/range-request-generator.d.ts +8 -0
- package/dist/generation/request-generators/range-request-generator.d.ts.map +1 -0
- package/dist/generation/request-generators/range-request-generator.js +22 -0
- package/dist/generation/request-generators/range-request-generator.js.map +1 -0
- package/dist/generation/request-generators/unauthorized-request-generator.d.ts +6 -0
- package/dist/generation/request-generators/unauthorized-request-generator.d.ts.map +1 -0
- package/dist/generation/request-generators/unauthorized-request-generator.js +10 -0
- package/dist/generation/request-generators/unauthorized-request-generator.js.map +1 -0
- package/dist/hooks/create-hook-utils.d.ts +8 -0
- package/dist/hooks/create-hook-utils.d.ts.map +1 -0
- package/dist/hooks/create-hook-utils.js +137 -0
- package/dist/hooks/create-hook-utils.js.map +1 -0
- package/dist/hooks/generate-request-types.d.ts +30 -0
- package/dist/hooks/generate-request-types.d.ts.map +1 -0
- package/dist/hooks/generate-request-types.js +424 -0
- package/dist/hooks/generate-request-types.js.map +1 -0
- package/dist/hooks/hook-errors.d.ts +5 -0
- package/dist/hooks/hook-errors.d.ts.map +1 -0
- package/dist/hooks/hook-errors.js +5 -0
- package/dist/hooks/hook-errors.js.map +1 -0
- package/dist/hooks/hook-runner.d.ts +18 -0
- package/dist/hooks/hook-runner.d.ts.map +1 -0
- package/dist/hooks/hook-runner.js +172 -0
- package/dist/hooks/hook-runner.js.map +1 -0
- package/dist/hooks/hook-types.d.ts +7 -0
- package/dist/hooks/hook-types.d.ts.map +1 -0
- package/dist/hooks/hook-types.js +2 -0
- package/dist/hooks/hook-types.js.map +1 -0
- package/dist/hooks/hook-utils.d.ts +36 -0
- package/dist/hooks/hook-utils.d.ts.map +1 -0
- package/dist/hooks/hook-utils.js +2 -0
- package/dist/hooks/hook-utils.js.map +1 -0
- package/dist/hooks/load-hooks-from-samples.d.ts +3 -0
- package/dist/hooks/load-hooks-from-samples.d.ts.map +1 -0
- package/dist/hooks/load-hooks-from-samples.js +22 -0
- package/dist/hooks/load-hooks-from-samples.js.map +1 -0
- package/dist/hooks/ts-config.d.ts +10 -0
- package/dist/hooks/ts-config.d.ts.map +1 -0
- package/dist/hooks/ts-config.js +10 -0
- package/dist/hooks/ts-config.js.map +1 -0
- package/dist/http-request-sample.d.ts +24 -0
- package/dist/http-request-sample.d.ts.map +1 -0
- package/dist/http-request-sample.js +11 -0
- package/dist/http-request-sample.js.map +1 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +145 -0
- package/dist/index.js.map +1 -0
- package/dist/request-sample-to-request-template.d.ts +6 -0
- package/dist/request-sample-to-request-template.d.ts.map +1 -0
- package/dist/request-sample-to-request-template.js +35 -0
- package/dist/request-sample-to-request-template.js.map +1 -0
- package/dist/request-sampler.d.ts +15 -0
- package/dist/request-sampler.d.ts.map +1 -0
- package/dist/request-sampler.js +82 -0
- package/dist/request-sampler.js.map +1 -0
- package/dist/samples-structure/file-request-sample.d.ts +20 -0
- package/dist/samples-structure/file-request-sample.d.ts.map +1 -0
- package/dist/samples-structure/file-request-sample.js +5 -0
- package/dist/samples-structure/file-request-sample.js.map +1 -0
- package/dist/samples-structure/get-path-transaction-id.d.ts +3 -0
- package/dist/samples-structure/get-path-transaction-id.d.ts.map +1 -0
- package/dist/samples-structure/get-path-transaction-id.js +22 -0
- package/dist/samples-structure/get-path-transaction-id.js.map +1 -0
- package/dist/samples-structure/merge-tree.d.ts +5 -0
- package/dist/samples-structure/merge-tree.d.ts.map +1 -0
- package/dist/samples-structure/merge-tree.js +118 -0
- package/dist/samples-structure/merge-tree.js.map +1 -0
- package/dist/samples-structure/read-samples-from-dir.d.ts +13 -0
- package/dist/samples-structure/read-samples-from-dir.d.ts.map +1 -0
- package/dist/samples-structure/read-samples-from-dir.js +204 -0
- package/dist/samples-structure/read-samples-from-dir.js.map +1 -0
- package/dist/samples-structure/samples-from-transactions.d.ts +5 -0
- package/dist/samples-structure/samples-from-transactions.d.ts.map +1 -0
- package/dist/samples-structure/samples-from-transactions.js +120 -0
- package/dist/samples-structure/samples-from-transactions.js.map +1 -0
- package/dist/samples-structure/samples-tree-structure.d.ts +106 -0
- package/dist/samples-structure/samples-tree-structure.d.ts.map +1 -0
- package/dist/samples-structure/samples-tree-structure.js +26 -0
- package/dist/samples-structure/samples-tree-structure.js.map +1 -0
- package/dist/samples-structure/structure-meta-on-disc.d.ts +11 -0
- package/dist/samples-structure/structure-meta-on-disc.d.ts.map +1 -0
- package/dist/samples-structure/structure-meta-on-disc.js +2 -0
- package/dist/samples-structure/structure-meta-on-disc.js.map +1 -0
- package/dist/samples-structure/traverse.d.ts +4 -0
- package/dist/samples-structure/traverse.d.ts.map +1 -0
- package/dist/samples-structure/traverse.js +13 -0
- package/dist/samples-structure/traverse.js.map +1 -0
- package/dist/samples-structure/write-samples-to-dir.d.ts +25 -0
- package/dist/samples-structure/write-samples-to-dir.d.ts.map +1 -0
- package/dist/samples-structure/write-samples-to-dir.js +173 -0
- package/dist/samples-structure/write-samples-to-dir.js.map +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +26 -0
- package/dist/utils.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-types.js","sourceRoot":"","sources":["../../src/hooks/hook-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type ParameterType = string | number | null | boolean;
|
|
2
|
+
export type EndpointRequest = {
|
|
3
|
+
body: unknown;
|
|
4
|
+
headers?: Record<PropertyKey, string | string[] | undefined>;
|
|
5
|
+
query?: Record<PropertyKey, ParameterType>;
|
|
6
|
+
cookies?: Record<PropertyKey, ParameterType>;
|
|
7
|
+
path?: Record<PropertyKey, ParameterType | ParameterType[] | Record<string, ParameterType | ParameterType[]>>;
|
|
8
|
+
};
|
|
9
|
+
export type Endpoints = Record<string, {
|
|
10
|
+
req: EndpointRequest;
|
|
11
|
+
res: {
|
|
12
|
+
body: unknown;
|
|
13
|
+
statusCode: number;
|
|
14
|
+
headers: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
}>;
|
|
17
|
+
export interface HookUtils<E extends Endpoints = Record<string, never>> {
|
|
18
|
+
skip(message: string): never;
|
|
19
|
+
fail(message: string): never;
|
|
20
|
+
info(message: string): void;
|
|
21
|
+
warn(message: string, details?: string): void;
|
|
22
|
+
assertionSuccess(message: string, assertion?: string): void;
|
|
23
|
+
assertionFailure(message: string, details?: {
|
|
24
|
+
assertion?: string;
|
|
25
|
+
expected?: unknown;
|
|
26
|
+
actual?: unknown;
|
|
27
|
+
}): void;
|
|
28
|
+
timeout(message: string, durationMs: number): void;
|
|
29
|
+
request<R extends keyof E>(req: R, args: E[R]['req'], options?: {
|
|
30
|
+
runHooks?: boolean;
|
|
31
|
+
authorize?: boolean;
|
|
32
|
+
forStatusCode?: number;
|
|
33
|
+
}): Promise<E[R]['res']>;
|
|
34
|
+
randomString(length?: number): string;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=hook-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-utils.d.ts","sourceRoot":"","sources":["../../src/hooks/hook-utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC;AAE7D,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IAC7D,KAAK,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC,C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jB,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,GACA,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAExB,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-utils.js","sourceRoot":"","sources":["../../src/hooks/hook-utils.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-hooks-from-samples.d.ts","sourceRoot":"","sources":["../../src/hooks/load-hooks-from-samples.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,KAAK,EAEV,KAAK,gBAAgB,EACtB,MAAM,gDAAgD,CAAC;AAGxD,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,gBAAgB,GACxB,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CA0BpB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { mergeHooks } from '../samples-structure/merge-tree.js';
|
|
2
|
+
import { nodeIsType, } from '../samples-structure/samples-tree-structure.js';
|
|
3
|
+
import { traverse } from '../samples-structure/traverse.js';
|
|
4
|
+
export function loadHooksFromSamples(samples) {
|
|
5
|
+
const result = new Map();
|
|
6
|
+
traverse(samples, {
|
|
7
|
+
afterEachResponse: [],
|
|
8
|
+
authorize: [],
|
|
9
|
+
beforeEachRequest: [],
|
|
10
|
+
}, (node, hooks) => {
|
|
11
|
+
let nextHooks = hooks;
|
|
12
|
+
if (node.hooks) {
|
|
13
|
+
nextHooks = mergeHooks(nextHooks, node.hooks);
|
|
14
|
+
}
|
|
15
|
+
if (nodeIsType(node, 'samples')) {
|
|
16
|
+
result.set(node.meta.sourceTransaction, nextHooks);
|
|
17
|
+
}
|
|
18
|
+
return nextHooks;
|
|
19
|
+
});
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=load-hooks-from-samples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-hooks-from-samples.js","sourceRoot":"","sources":["../../src/hooks/load-hooks-from-samples.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAEL,UAAU,GAEX,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,MAAM,UAAU,oBAAoB,CAClC,OAAyB;IAEzB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAiB,CAAC;IAExC,QAAQ,CACN,OAAO,EACP;QACE,iBAAiB,EAAE,EAAE;QACrB,SAAS,EAAE,EAAE;QACb,iBAAiB,EAAE,EAAE;KACtB,EACD,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACd,IAAI,SAAS,GAAG,KAAK,CAAC;QAEtB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,SAAS,GAAG,UAAU,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,CAAC;YAChC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC;QACrD,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ts-config.d.ts","sourceRoot":"","sources":["../../src/hooks/ts-config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ;;;;;;;;CAQpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ts-config.js","sourceRoot":"","sources":["../../src/hooks/ts-config.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,eAAe,EAAE;QACf,OAAO,EAAE,GAAG;QACZ,KAAK,EAAE;YACL,gBAAgB,EAAE,CAAC,cAAc,CAAC;SACnC;KACF;IACD,OAAO,EAAE,CAAC,WAAW,CAAC;CACvB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type InlineContentSource = {
|
|
2
|
+
$content: unknown;
|
|
3
|
+
};
|
|
4
|
+
export type FileContentSource = {
|
|
5
|
+
$encoding: string;
|
|
6
|
+
$buffer: Buffer;
|
|
7
|
+
$ext: string;
|
|
8
|
+
};
|
|
9
|
+
export type ContentSource = InlineContentSource | FileContentSource;
|
|
10
|
+
export type HttpRequestSample = {
|
|
11
|
+
origin: string;
|
|
12
|
+
path: string;
|
|
13
|
+
method: string;
|
|
14
|
+
authorize: boolean;
|
|
15
|
+
bodyEncoding?: string;
|
|
16
|
+
headers: Record<string, ContentSource>;
|
|
17
|
+
cookies: Record<string, ContentSource>;
|
|
18
|
+
pathParameters: Record<string, ContentSource>;
|
|
19
|
+
query: Record<string, ContentSource>;
|
|
20
|
+
body?: ContentSource;
|
|
21
|
+
};
|
|
22
|
+
export declare function isFileContentSource(source: unknown): source is FileContentSource;
|
|
23
|
+
export declare function isInlineContentSource(source: unknown): source is InlineContentSource;
|
|
24
|
+
//# sourceMappingURL=http-request-sample.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-request-sample.d.ts","sourceRoot":"","sources":["../src/http-request-sample.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG,iBAAiB,CAAC;AAEpE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACvC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC9C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACrC,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,iBAAiB,CAO7B;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,mBAAmB,CAE/B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isRecord } from '@thymian/core';
|
|
2
|
+
export function isFileContentSource(source) {
|
|
3
|
+
return (isRecord(source) &&
|
|
4
|
+
'$buffer' in source &&
|
|
5
|
+
'$encoding' in source &&
|
|
6
|
+
'$ext' in source);
|
|
7
|
+
}
|
|
8
|
+
export function isInlineContentSource(source) {
|
|
9
|
+
return isRecord(source) && '$content' in source;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=http-request-sample.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-request-sample.js","sourceRoot":"","sources":["../src/http-request-sample.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AA2BzC,MAAM,UAAU,mBAAmB,CACjC,MAAe;IAEf,OAAO,CACL,QAAQ,CAAC,MAAM,CAAC;QAChB,SAAS,IAAI,MAAM;QACnB,WAAW,IAAI,MAAM;QACrB,MAAM,IAAI,MAAM,CACjB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,MAAe;IAEf,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,UAAU,IAAI,MAAM,CAAC;AAClD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type HttpRequestTemplate, type SerializedThymianFormat, type ThymianHttpTransaction, type ThymianPlugin, type ThymianSchema } from '@thymian/core';
|
|
2
|
+
declare module '@thymian/core' {
|
|
3
|
+
interface ThymianActions {
|
|
4
|
+
'sampler.init': {
|
|
5
|
+
event: {
|
|
6
|
+
format: SerializedThymianFormat;
|
|
7
|
+
overwrite?: boolean;
|
|
8
|
+
};
|
|
9
|
+
response: void;
|
|
10
|
+
};
|
|
11
|
+
'core.request.sample': {
|
|
12
|
+
event: {
|
|
13
|
+
transaction: ThymianHttpTransaction;
|
|
14
|
+
options?: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
response: HttpRequestTemplate;
|
|
17
|
+
};
|
|
18
|
+
'sampler.unknown-type': {
|
|
19
|
+
event: {
|
|
20
|
+
contentType: string;
|
|
21
|
+
schema: ThymianSchema;
|
|
22
|
+
};
|
|
23
|
+
response: {
|
|
24
|
+
$content: unknown;
|
|
25
|
+
$encoding?: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
'sampler.path-from-transaction': {
|
|
29
|
+
event: {
|
|
30
|
+
transactionId: string;
|
|
31
|
+
};
|
|
32
|
+
response: string | undefined;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export type SamplerPluginOptions = {
|
|
37
|
+
path: string;
|
|
38
|
+
};
|
|
39
|
+
export declare const samplePlugin: ThymianPlugin<Partial<SamplerPluginOptions>>;
|
|
40
|
+
export default samplePlugin;
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAG5B,KAAK,sBAAsB,EAE3B,KAAK,aAAa,EAClB,KAAK,aAAa,EACnB,MAAM,eAAe,CAAC;AAkBvB,OAAO,QAAQ,eAAe,CAAC;IAC7B,UAAU,cAAc;QACtB,cAAc,EAAE;YACd,KAAK,EAAE;gBACL,MAAM,EAAE,uBAAuB,CAAC;gBAChC,SAAS,CAAC,EAAE,OAAO,CAAC;aACrB,CAAC;YACF,QAAQ,EAAE,IAAI,CAAC;SAChB,CAAC;QAEF,qBAAqB,EAAE;YACrB,KAAK,EAAE;gBACL,WAAW,EAAE,sBAAsB,CAAC;gBACpC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;aACnC,CAAC;YACF,QAAQ,EAAE,mBAAmB,CAAC;SAC/B,CAAC;QAEF,sBAAsB,EAAE;YACtB,KAAK,EAAE;gBACL,WAAW,EAAE,MAAM,CAAC;gBACpB,MAAM,EAAE,aAAa,CAAC;aACvB,CAAC;YACF,QAAQ,EAAE;gBAAE,QAAQ,EAAE,OAAO,CAAC;gBAAC,SAAS,CAAC,EAAE,MAAM,CAAA;aAAE,CAAC;SACrD,CAAC;QAEF,+BAA+B,EAAE;YAC/B,KAAK,EAAE;gBACL,aAAa,EAAE,MAAM,CAAC;aACvB,CAAC;YACF,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;SAC9B,CAAC;KACH;CACF;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,aAAa,CAAC,OAAO,CAAC,oBAAoB,CAAC,CA2LrE,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
import { isAbsolute, join } from 'node:path';
|
|
3
|
+
import { ThymianBaseError, ThymianFormat, thymianHttpTransactionToString, } from '@thymian/core';
|
|
4
|
+
import { generateSamplesForThymianFormat } from './generation/generate-samples-for-thymian-format.js';
|
|
5
|
+
import { generatedTypesToString, generateTypesForThymianFormat, } from './hooks/generate-request-types.js';
|
|
6
|
+
import { HookRunner } from './hooks/hook-runner.js';
|
|
7
|
+
import { tsConfig } from './hooks/ts-config.js';
|
|
8
|
+
import { requestSampleToRequestTemplate } from './request-sample-to-request-template.js';
|
|
9
|
+
import { RequestSampler } from './request-sampler.js';
|
|
10
|
+
import { getPathTransactionId } from './samples-structure/get-path-transaction-id.js';
|
|
11
|
+
import { readSamplesFromDir } from './samples-structure/read-samples-from-dir.js';
|
|
12
|
+
import { writeSamplesToDir } from './samples-structure/write-samples-to-dir.js';
|
|
13
|
+
import { entryExists } from './utils.js';
|
|
14
|
+
export const samplePlugin = {
|
|
15
|
+
name: '@thymian/plugin-sampler',
|
|
16
|
+
version: '0.x',
|
|
17
|
+
options: {
|
|
18
|
+
// ### for reference documentation ###
|
|
19
|
+
title: 'Plugin Options',
|
|
20
|
+
description: 'Configuration options for the Sampler plugin',
|
|
21
|
+
// ###################################
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: {
|
|
24
|
+
path: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
nullable: true,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
actions: {
|
|
31
|
+
provides: {
|
|
32
|
+
'sampler.init': {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
34
|
+
// @ts-expect-error
|
|
35
|
+
event: {
|
|
36
|
+
type: 'object',
|
|
37
|
+
required: ['contentType', 'schema'],
|
|
38
|
+
properties: {
|
|
39
|
+
contentType: { type: 'string' },
|
|
40
|
+
schema: {},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
44
|
+
// @ts-expect-error
|
|
45
|
+
response: {
|
|
46
|
+
type: 'object',
|
|
47
|
+
required: ['contentType', 'schema'],
|
|
48
|
+
properties: {
|
|
49
|
+
contentType: { type: 'string' },
|
|
50
|
+
schema: {},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
plugin: async (emitter, logger, options) => {
|
|
57
|
+
let basePath = join(options.cwd, '.thymian', 'samples');
|
|
58
|
+
if (options.path) {
|
|
59
|
+
basePath = isAbsolute(options.path)
|
|
60
|
+
? options.path
|
|
61
|
+
: join(options.cwd, options.path);
|
|
62
|
+
}
|
|
63
|
+
let format;
|
|
64
|
+
let samples;
|
|
65
|
+
const requestSampler = new RequestSampler(basePath);
|
|
66
|
+
const hookRunner = new HookRunner(basePath, async (request) => {
|
|
67
|
+
return await emitter.emitAction('core.request.dispatch', {
|
|
68
|
+
request,
|
|
69
|
+
}, {
|
|
70
|
+
strategy: 'first',
|
|
71
|
+
});
|
|
72
|
+
}, logger);
|
|
73
|
+
async function initializeSamplerAndHookRunner(format) {
|
|
74
|
+
samples = (await entryExists(basePath))
|
|
75
|
+
? await readSamplesFromDir(basePath)
|
|
76
|
+
: undefined;
|
|
77
|
+
await requestSampler.init(samples);
|
|
78
|
+
await hookRunner.init(format, samples);
|
|
79
|
+
}
|
|
80
|
+
emitter.onAction('core.format', async (f, ctx) => {
|
|
81
|
+
format = ThymianFormat.import(f);
|
|
82
|
+
await initializeSamplerAndHookRunner(format);
|
|
83
|
+
ctx.reply();
|
|
84
|
+
});
|
|
85
|
+
emitter.onAction('sampler.path-from-transaction', ({ transactionId }, ctx) => {
|
|
86
|
+
if (!samples) {
|
|
87
|
+
throw new ThymianBaseError('No samples are loaded.', {
|
|
88
|
+
name: 'SamplesNotLoadedError',
|
|
89
|
+
ref: 'https://thymian.dev/references/errors/samples-not-loaded-error/',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
ctx.reply(getPathTransactionId(transactionId, basePath, samples));
|
|
93
|
+
});
|
|
94
|
+
emitter.onAction('sampler.init', async ({ format, overwrite }, ctx) => {
|
|
95
|
+
const parsedFormat = ThymianFormat.import(format);
|
|
96
|
+
const samples = await generateSamplesForThymianFormat(parsedFormat, emitter);
|
|
97
|
+
const generatedTypes = await generateTypesForThymianFormat(parsedFormat);
|
|
98
|
+
await writeSamplesToDir(samples, generatedTypes.keyToTransactionId, {
|
|
99
|
+
path: basePath,
|
|
100
|
+
mode: typeof overwrite === 'boolean' ? 'overwrite' : 'failIfExist',
|
|
101
|
+
});
|
|
102
|
+
await writeFile(join(basePath, 'types.d.ts'), generatedTypesToString(generatedTypes.types));
|
|
103
|
+
await writeFile(join(basePath, 'tsconfig.json'), JSON.stringify(tsConfig, null, 2));
|
|
104
|
+
ctx.reply();
|
|
105
|
+
});
|
|
106
|
+
emitter.onAction('core.request.sample', async ({ transaction }, ctx) => {
|
|
107
|
+
if (!format) {
|
|
108
|
+
throw new ThymianBaseError('Format is not loaded.', {
|
|
109
|
+
name: 'FormatNotLoadedError',
|
|
110
|
+
ref: 'https://thymian.dev/references/errors/format-not-loaded-error/',
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const sample = requestSampler.sampleForTransaction(transaction.transactionId);
|
|
114
|
+
if (!sample) {
|
|
115
|
+
const currentFormatVersion = format.toHash();
|
|
116
|
+
if (currentFormatVersion !== requestSampler.version()) {
|
|
117
|
+
throw new ThymianBaseError(`Cannot sample for transaction "${thymianHttpTransactionToString(transaction.thymianReq, transaction.thymianRes)}", because it based on version "${currentFormatVersion}" but the loaded samples are based on version "${requestSampler.version()}".`, {
|
|
118
|
+
name: 'VersionMismatchError',
|
|
119
|
+
suggestions: [
|
|
120
|
+
`The loaded samples were generated at ${requestSampler.timestamp()}. Did you forget to regenerate the samples?`,
|
|
121
|
+
'$ thymian sampler:init',
|
|
122
|
+
],
|
|
123
|
+
ref: 'https://thymian.dev/guides/samples/update-samples',
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
throw new ThymianBaseError(`Cannot sample for transaction ${thymianHttpTransactionToString(transaction.thymianReq, transaction.thymianRes)} with transaction ID ${transaction.transactionId}`, {
|
|
127
|
+
name: 'TransactionSampleNotFoundError',
|
|
128
|
+
ref: 'https://thymian.dev/references/errors/transaction-sample-not-found-error/',
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
ctx.reply(requestSampleToRequestTemplate(sample));
|
|
132
|
+
});
|
|
133
|
+
emitter.onAction('http-testing.beforeRequest', async (hook, ctx) => {
|
|
134
|
+
ctx.reply(await hookRunner.beforeEachRequest(hook));
|
|
135
|
+
});
|
|
136
|
+
emitter.onAction('http-testing.afterResponse', async (hook, ctx) => {
|
|
137
|
+
ctx.reply(await hookRunner.afterEachResponse(hook));
|
|
138
|
+
});
|
|
139
|
+
emitter.onAction('http-testing.authorize', async (hook, ctx) => {
|
|
140
|
+
ctx.reply(await hookRunner.authorize(hook));
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
export default samplePlugin;
|
|
145
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAGL,gBAAgB,EAChB,aAAa,EAEb,8BAA8B,GAG/B,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,+BAA+B,EAAE,MAAM,qDAAqD,CAAC;AACtG,OAAO,EACL,sBAAsB,EACtB,6BAA6B,GAC9B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,M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AEH,OAAO,CAAC,QAAQ,CAAC,4BAA4B,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE;YACjE,GAAG,CAAC,KAAK,CAAC,MAAM,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,QAAQ,CAAC,4BAA4B,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE;YACjE,GAAG,CAAC,KAAK,CAAC,MAAM,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,QAAQ,CAAC,wBAAwB,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE;YAC7D,GAAG,CAAC,KAAK,CAAC,MAAM,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HttpRequestTemplate } from '@thymian/core';
|
|
2
|
+
import { type ContentSource, type HttpRequestSample } from './http-request-sample.js';
|
|
3
|
+
export declare function transformContentSource<T extends string | unknown>(source: ContentSource): T;
|
|
4
|
+
export declare function transformParameters(parameters: Record<string, ContentSource>): Record<string, unknown>;
|
|
5
|
+
export declare function requestSampleToRequestTemplate(sample: HttpRequestSample): HttpRequestTemplate;
|
|
6
|
+
//# sourceMappingURL=request-sample-to-request-template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-sample-to-request-template.d.ts","sourceRoot":"","sources":["../src/request-sample-to-request-template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzD,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,iBAAiB,EAGvB,MAAM,0BAA0B,CAAC;AAElC,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,GAAG,OAAO,EAC/D,MAAM,EAAE,aAAa,GACpB,CAAC,CAUH;AAED,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GACxC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASzB;AAED,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,iBAAiB,GACxB,mBAAmB,CAmBrB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isFileContentSource, isInlineContentSource, } from './http-request-sample.js';
|
|
2
|
+
export function transformContentSource(source) {
|
|
3
|
+
if (isInlineContentSource(source)) {
|
|
4
|
+
return source.$content;
|
|
5
|
+
}
|
|
6
|
+
else if (isFileContentSource(source)) {
|
|
7
|
+
return Buffer.from(source.$buffer).toString(source.$encoding);
|
|
8
|
+
}
|
|
9
|
+
throw new Error('Unknown content source type .' + source);
|
|
10
|
+
}
|
|
11
|
+
export function transformParameters(parameters) {
|
|
12
|
+
return Object.entries(parameters).reduce((acc, [name, source]) => {
|
|
13
|
+
acc[name] = transformContentSource(source);
|
|
14
|
+
return acc;
|
|
15
|
+
}, {});
|
|
16
|
+
}
|
|
17
|
+
export function requestSampleToRequestTemplate(sample) {
|
|
18
|
+
const template = {
|
|
19
|
+
authorize: sample.authorize,
|
|
20
|
+
cookies: transformParameters(sample.cookies),
|
|
21
|
+
headers: transformParameters(sample.headers),
|
|
22
|
+
method: sample.method,
|
|
23
|
+
origin: sample.origin,
|
|
24
|
+
path: sample.path,
|
|
25
|
+
pathParameters: transformParameters(sample.pathParameters),
|
|
26
|
+
query: transformParameters(sample.query),
|
|
27
|
+
bodyEncoding: sample.bodyEncoding,
|
|
28
|
+
};
|
|
29
|
+
if (sample.body) {
|
|
30
|
+
template.bodyEncoding = sample.bodyEncoding;
|
|
31
|
+
template.body = transformContentSource(sample.body);
|
|
32
|
+
}
|
|
33
|
+
return template;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=request-sample-to-request-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-sample-to-request-template.js","sourceRoot":"","sources":["../src/request-sample-to-request-template.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,0BAA0B,CAAC;AAElC,MAAM,UAAU,sBAAsB,CACpC,MAAqB;IAErB,IAAI,qBAAqB,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC,QAAa,CAAC;IAC9B,CAAC;SAAM,IAAI,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC;QACvC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,CACzC,MAAM,CAAC,SAA2B,CAC9B,CAAC;IACT,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,MAAM,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,UAAyC;IAEzC,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,MAAM,CACtC,CAAC,GAA4B,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE;QAC/C,GAAG,CAAC,IAAI,CAAC,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAE3C,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAE,CACH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,8BAA8B,CAC5C,MAAyB;IAEzB,MAAM,QAAQ,GAAwB;QACpC,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,OAAO,EAAE,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC;QAC5C,OAAO,EAAE,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC;QAC5C,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,cAAc,EAAE,mBAAmB,CAAC,MAAM,CAAC,cAAc,CAAC;QAC1D,KAAK,EAAE,mBAAmB,CAAC,MAAM,CAAC,KAAK,CAAC;QACxC,YAAY,EAAE,MAAM,CAAC,YAAY;KAClC,CAAC;IAEF,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAChB,QAAQ,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QAC5C,QAAQ,CAAC,IAAI,GAAG,sBAAsB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HttpRequestSample } from './http-request-sample.js';
|
|
2
|
+
import { type SamplesNode, type SamplesStructure } from './samples-structure/samples-tree-structure.js';
|
|
3
|
+
export declare function readSamplesNodesFromTree(tree: SamplesStructure): Map<string, SamplesNode>;
|
|
4
|
+
export declare class RequestSampler {
|
|
5
|
+
private readonly basePath;
|
|
6
|
+
constructor(basePath: string, samples?: SamplesStructure);
|
|
7
|
+
private samples;
|
|
8
|
+
private initialized;
|
|
9
|
+
private sampleNodes;
|
|
10
|
+
version(): string;
|
|
11
|
+
timestamp(): string;
|
|
12
|
+
init(samples?: SamplesStructure): Promise<void>;
|
|
13
|
+
sampleForTransaction(transactionId: string): HttpRequestSample | undefined;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=request-sampler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-sampler.d.ts","sourceRoot":"","sources":["../src/request-sampler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACtB,MAAM,+CAA+C,CAAC;AAIvD,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,gBAAgB,GACrB,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAY1B;AAED,qBAAa,cAAc;IAEvB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,MAAM,EACjC,OAAO,CAAC,EAAE,gBAAgB;IAS5B,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAuC;IAE1D,OAAO,IAAI,MAAM;IAIjB,SAAS,IAAI,MAAM;IAeb,IAAI,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBrD,oBAAoB,CAAC,aAAa,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS;CA+B3E"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ThymianBaseError } from '@thymian/core';
|
|
2
|
+
import { readSamplesFromDir } from './samples-structure/read-samples-from-dir.js';
|
|
3
|
+
import { nodeIsType, } from './samples-structure/samples-tree-structure.js';
|
|
4
|
+
import { traverse } from './samples-structure/traverse.js';
|
|
5
|
+
import { entryExists } from './utils.js';
|
|
6
|
+
export function readSamplesNodesFromTree(tree) {
|
|
7
|
+
const result = new Map();
|
|
8
|
+
traverse(tree, null, (node, ctx) => {
|
|
9
|
+
if (nodeIsType(node, 'samples')) {
|
|
10
|
+
result.set(node.meta.sourceTransaction, node);
|
|
11
|
+
}
|
|
12
|
+
return ctx;
|
|
13
|
+
});
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
export class RequestSampler {
|
|
17
|
+
basePath;
|
|
18
|
+
constructor(basePath, samples) {
|
|
19
|
+
this.basePath = basePath;
|
|
20
|
+
if (samples) {
|
|
21
|
+
this.sampleNodes = readSamplesNodesFromTree(samples);
|
|
22
|
+
this.samples = samples;
|
|
23
|
+
this.initialized = true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
samples;
|
|
27
|
+
initialized = false;
|
|
28
|
+
sampleNodes = new Map();
|
|
29
|
+
version() {
|
|
30
|
+
return this.samples.meta.version;
|
|
31
|
+
}
|
|
32
|
+
timestamp() {
|
|
33
|
+
try {
|
|
34
|
+
return new Date(this.samples.meta.timestamp).toISOString();
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
throw new ThymianBaseError(`Invalid timestamp in samples meta: ${this.samples.meta.timestamp}`, {
|
|
38
|
+
name: 'InvalidSampleTimestampError',
|
|
39
|
+
ref: 'https://thymian.dev/references/errors/invalid-sample-timestamp-error/',
|
|
40
|
+
cause: e,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async init(samples) {
|
|
45
|
+
if (this.initialized) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (!(await entryExists(this.basePath))) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.samples = samples ?? (await readSamplesFromDir(this.basePath));
|
|
52
|
+
this.sampleNodes = readSamplesNodesFromTree(this.samples);
|
|
53
|
+
this.initialized = true;
|
|
54
|
+
}
|
|
55
|
+
sampleForTransaction(transactionId) {
|
|
56
|
+
if (!this.initialized) {
|
|
57
|
+
throw new ThymianBaseError('Cannot sample for transaction before @thymian/plugin-sampler was initialized.', {
|
|
58
|
+
suggestions: ['Did you run "thymian sampler:init"?'],
|
|
59
|
+
name: 'SamplerNotInitializedError',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const node = this.sampleNodes.get(transactionId);
|
|
63
|
+
if (!node) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const { samplingStrategy } = node.meta;
|
|
67
|
+
const samples = node.children
|
|
68
|
+
.filter((child) => nodeIsType(child, 'requests'))
|
|
69
|
+
.flatMap((child) => child.value);
|
|
70
|
+
if (samplingStrategy.type === 'random') {
|
|
71
|
+
const randomIndex = Math.floor(Math.random() * samples.length);
|
|
72
|
+
return samples[randomIndex];
|
|
73
|
+
}
|
|
74
|
+
else if (samplingStrategy.type === 'fixed') {
|
|
75
|
+
return samples[0];
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
throw new Error(`Unsupported sampling strategy ${samplingStrategy}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=request-sampler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-sampler.js","sourceRoot":"","sources":["../src/request-sampler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAClF,OAAO,EACL,UAAU,GAGX,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,UAAU,wBAAwB,CACtC,IAAsB;IAEtB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAuB,CAAC;IAE9C,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;QACjC,IAAI,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,CAAC;YAChC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;QAChD,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,OAAO,cAAc;IAEN;IADnB,YACmB,QAAgB,EACjC,OAA0B;QADT,aAAQ,GAAR,QAAQ,CAAQ;QAGjC,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,WAAW,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC;YACrD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YACvB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAC1B,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ACJ,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAEjD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO;QACT,CAAC;QAED,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ;aAC1B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;aAChD,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAEnC,IAAI,gBAAgB,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;YAC/D,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC;QAC9B,CAAC;aAAM,IAAI,gBAAgB,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC7C,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,iCAAiC,gBAAgB,EAAE,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type InlineValue = unknown;
|
|
2
|
+
export type FileValue = {
|
|
3
|
+
$file: string;
|
|
4
|
+
$encoding?: string;
|
|
5
|
+
};
|
|
6
|
+
export type Value = InlineValue | FileValue;
|
|
7
|
+
export type FileRequestSample = {
|
|
8
|
+
origin: string;
|
|
9
|
+
path: string;
|
|
10
|
+
method: string;
|
|
11
|
+
authorize: boolean;
|
|
12
|
+
bodyEncoding?: string;
|
|
13
|
+
headers: Record<string, Value>;
|
|
14
|
+
cookies: Record<string, Value>;
|
|
15
|
+
pathParameters: Record<string, Value>;
|
|
16
|
+
query: Record<string, Value>;
|
|
17
|
+
body?: Value;
|
|
18
|
+
};
|
|
19
|
+
export declare function isFileValue(value: Value): value is FileValue;
|
|
20
|
+
//# sourceMappingURL=file-request-sample.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-request-sample.d.ts","sourceRoot":"","sources":["../../src/samples-structure/file-request-sample.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC;AAElC,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,WAAW,GAAG,SAAS,CAAC;AAG5C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC/B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACtC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC7B,IAAI,CAAC,EAAE,KAAK,CAAC;CACd,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,SAAS,CAE5D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-request-sample.js","sourceRoot":"","sources":["../../src/samples-structure/file-request-sample.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAyBzC,MAAM,UAAU,WAAW,CAAC,KAAY;IACtC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-path-transaction-id.d.ts","sourceRoot":"","sources":["../../src/samples-structure/get-path-transaction-id.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,6BAA6B,CAAC;AAIrC,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,gBAAgB,GACxB,MAAM,GAAG,SAAS,CAuBpB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { isValidNodeType, nodeIsType, } from './samples-tree-structure.js';
|
|
3
|
+
import { traverse } from './traverse.js';
|
|
4
|
+
import { getFolderNameFromNode } from './write-samples-to-dir.js';
|
|
5
|
+
export function getPathTransactionId(id, path, samples) {
|
|
6
|
+
let finalPath = path;
|
|
7
|
+
traverse(samples, path, (node, currentPath, prev) => {
|
|
8
|
+
if (!isValidNodeType(node.type)) {
|
|
9
|
+
throw new Error(`Invalid node type: ${node.type}`);
|
|
10
|
+
}
|
|
11
|
+
const folderName = getFolderNameFromNode(node);
|
|
12
|
+
const newName = join(currentPath, folderName);
|
|
13
|
+
if (nodeIsType(node, 'requests') &&
|
|
14
|
+
nodeIsType(prev, 'samples') &&
|
|
15
|
+
prev.meta.sourceTransaction === id) {
|
|
16
|
+
finalPath = newName;
|
|
17
|
+
}
|
|
18
|
+
return newName;
|
|
19
|
+
});
|
|
20
|
+
return finalPath === path ? undefined : finalPath;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=get-path-transaction-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-path-transaction-id.js","sourceRoot":"","sources":["../../src/samples-structure/get-path-transaction-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACL,eAAe,EACf,UAAU,GAEX,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE,MAAM,UAAU,oBAAoB,CAClC,EAAU,EACV,IAAY,EACZ,OAAyB;IAEzB,IAAI,SAAS,GAAG,IAAI,CAAC;IAErB,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE;QAClD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,sBAAsB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACrD,CAAC;QAED,MAAM,UAAU,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAE9C,IACE,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC;YAC5B,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC;YAC3B,IAAI,CAAC,IAAI,CAAC,iBAAiB,KAAK,EAAE,EAClC,CAAC;YACD,SAAS,GAAG,OAAO,CAAC;QACtB,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Hooks, type Node, type SamplesStructure } from './samples-tree-structure.js';
|
|
2
|
+
export declare function mergeHooks(a: Hooks | undefined, b: Hooks | undefined): Hooks;
|
|
3
|
+
export declare function mergeNodes(a: Node, b: Node): Node;
|
|
4
|
+
export declare function mergeTrees(a: SamplesStructure, b: SamplesStructure): SamplesStructure;
|
|
5
|
+
//# sourceMappingURL=merge-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-tree.d.ts","sourceRoot":"","sources":["../../src/samples-structure/merge-tree.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,KAAK,EACV,KAAK,IAAI,EAGT,KAAK,gBAAgB,EAEtB,MAAM,6BAA6B,CAAC;AAErC,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,GAAG,SAAS,EAAE,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,KAAK,CAoB5E;AAuDD,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI,CAiCjD;AAED,wBAAgB,UAAU,CACxB,CAAC,EAAE,gBAAgB,EACnB,CAAC,EAAE,gBAAgB,GAClB,gBAAgB,CAqBlB"}
|