@thymian/plugin-sampler 0.0.0-PLACEHOLDER

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.
Files changed (170) hide show
  1. package/README.md +59 -0
  2. package/dist/cli/commands/sampler/check.d.ts +16 -0
  3. package/dist/cli/commands/sampler/check.d.ts.map +1 -0
  4. package/dist/cli/commands/sampler/check.js +135 -0
  5. package/dist/cli/commands/sampler/check.js.map +1 -0
  6. package/dist/cli/commands/sampler/generate/hook.d.ts +9 -0
  7. package/dist/cli/commands/sampler/generate/hook.d.ts.map +1 -0
  8. package/dist/cli/commands/sampler/generate/hook.js +18 -0
  9. package/dist/cli/commands/sampler/generate/hook.js.map +1 -0
  10. package/dist/cli/commands/sampler/init.d.ts +9 -0
  11. package/dist/cli/commands/sampler/init.d.ts.map +1 -0
  12. package/dist/cli/commands/sampler/init.js +55 -0
  13. package/dist/cli/commands/sampler/init.js.map +1 -0
  14. package/dist/cli/create-context.d.ts +3 -0
  15. package/dist/cli/create-context.d.ts.map +1 -0
  16. package/dist/cli/create-context.js +21 -0
  17. package/dist/cli/create-context.js.map +1 -0
  18. package/dist/cli/generate-hook.d.ts +4 -0
  19. package/dist/cli/generate-hook.d.ts.map +1 -0
  20. package/dist/cli/generate-hook.js +92 -0
  21. package/dist/cli/generate-hook.js.map +1 -0
  22. package/dist/cli/templates.d.ts +4 -0
  23. package/dist/cli/templates.d.ts.map +1 -0
  24. package/dist/cli/templates.js +28 -0
  25. package/dist/cli/templates.js.map +1 -0
  26. package/dist/constants.d.ts +5 -0
  27. package/dist/constants.d.ts.map +1 -0
  28. package/dist/constants.js +5 -0
  29. package/dist/constants.js.map +1 -0
  30. package/dist/generation/content-source-generator.d.ts +10 -0
  31. package/dist/generation/content-source-generator.d.ts.map +1 -0
  32. package/dist/generation/content-source-generator.js +15 -0
  33. package/dist/generation/content-source-generator.js.map +1 -0
  34. package/dist/generation/content-type-strategies/content-type-strategy.d.ts +7 -0
  35. package/dist/generation/content-type-strategies/content-type-strategy.d.ts.map +1 -0
  36. package/dist/generation/content-type-strategies/content-type-strategy.js +2 -0
  37. package/dist/generation/content-type-strategies/content-type-strategy.js.map +1 -0
  38. package/dist/generation/content-type-strategies/error.content-type-strategy.d.ts +7 -0
  39. package/dist/generation/content-type-strategies/error.content-type-strategy.d.ts.map +1 -0
  40. package/dist/generation/content-type-strategies/error.content-type-strategy.js +13 -0
  41. package/dist/generation/content-type-strategies/error.content-type-strategy.js.map +1 -0
  42. package/dist/generation/content-type-strategies/hook.content-type-strategy.d.ts +10 -0
  43. package/dist/generation/content-type-strategies/hook.content-type-strategy.d.ts.map +1 -0
  44. package/dist/generation/content-type-strategies/hook.content-type-strategy.js +27 -0
  45. package/dist/generation/content-type-strategies/hook.content-type-strategy.js.map +1 -0
  46. package/dist/generation/content-type-strategies/image.content-type-strategy.d.ts +15 -0
  47. package/dist/generation/content-type-strategies/image.content-type-strategy.d.ts.map +1 -0
  48. package/dist/generation/content-type-strategies/image.content-type-strategy.js +40 -0
  49. package/dist/generation/content-type-strategies/image.content-type-strategy.js.map +1 -0
  50. package/dist/generation/content-type-strategies/json.content-type-strategy.d.ts +8 -0
  51. package/dist/generation/content-type-strategies/json.content-type-strategy.d.ts.map +1 -0
  52. package/dist/generation/content-type-strategies/json.content-type-strategy.js +12 -0
  53. package/dist/generation/content-type-strategies/json.content-type-strategy.js.map +1 -0
  54. package/dist/generation/content-type-strategies/text.content-type-strategy.d.ts +8 -0
  55. package/dist/generation/content-type-strategies/text.content-type-strategy.d.ts.map +1 -0
  56. package/dist/generation/content-type-strategies/text.content-type-strategy.js +13 -0
  57. package/dist/generation/content-type-strategies/text.content-type-strategy.js.map +1 -0
  58. package/dist/generation/content-type-strategies/xml.content-type-strategy.d.ts +8 -0
  59. package/dist/generation/content-type-strategies/xml.content-type-strategy.d.ts.map +1 -0
  60. package/dist/generation/content-type-strategies/xml.content-type-strategy.js +14 -0
  61. package/dist/generation/content-type-strategies/xml.content-type-strategy.js.map +1 -0
  62. package/dist/generation/generate-samples-for-thymian-format.d.ts +4 -0
  63. package/dist/generation/generate-samples-for-thymian-format.d.ts.map +1 -0
  64. package/dist/generation/generate-samples-for-thymian-format.js +18 -0
  65. package/dist/generation/generate-samples-for-thymian-format.js.map +1 -0
  66. package/dist/generation/generate-samples.d.ts +4 -0
  67. package/dist/generation/generate-samples.d.ts.map +1 -0
  68. package/dist/generation/generate-samples.js +26 -0
  69. package/dist/generation/generate-samples.js.map +1 -0
  70. package/dist/generation/request-generators/default-request-generator.d.ts +22 -0
  71. package/dist/generation/request-generators/default-request-generator.d.ts.map +1 -0
  72. package/dist/generation/request-generators/default-request-generator.js +80 -0
  73. package/dist/generation/request-generators/default-request-generator.js.map +1 -0
  74. package/dist/generation/request-generators/range-request-generator.d.ts +8 -0
  75. package/dist/generation/request-generators/range-request-generator.d.ts.map +1 -0
  76. package/dist/generation/request-generators/range-request-generator.js +22 -0
  77. package/dist/generation/request-generators/range-request-generator.js.map +1 -0
  78. package/dist/generation/request-generators/unauthorized-request-generator.d.ts +6 -0
  79. package/dist/generation/request-generators/unauthorized-request-generator.d.ts.map +1 -0
  80. package/dist/generation/request-generators/unauthorized-request-generator.js +10 -0
  81. package/dist/generation/request-generators/unauthorized-request-generator.js.map +1 -0
  82. package/dist/hooks/create-hook-utils.d.ts +8 -0
  83. package/dist/hooks/create-hook-utils.d.ts.map +1 -0
  84. package/dist/hooks/create-hook-utils.js +137 -0
  85. package/dist/hooks/create-hook-utils.js.map +1 -0
  86. package/dist/hooks/generate-request-types.d.ts +30 -0
  87. package/dist/hooks/generate-request-types.d.ts.map +1 -0
  88. package/dist/hooks/generate-request-types.js +424 -0
  89. package/dist/hooks/generate-request-types.js.map +1 -0
  90. package/dist/hooks/hook-errors.d.ts +5 -0
  91. package/dist/hooks/hook-errors.d.ts.map +1 -0
  92. package/dist/hooks/hook-errors.js +5 -0
  93. package/dist/hooks/hook-errors.js.map +1 -0
  94. package/dist/hooks/hook-runner.d.ts +18 -0
  95. package/dist/hooks/hook-runner.d.ts.map +1 -0
  96. package/dist/hooks/hook-runner.js +172 -0
  97. package/dist/hooks/hook-runner.js.map +1 -0
  98. package/dist/hooks/hook-types.d.ts +7 -0
  99. package/dist/hooks/hook-types.d.ts.map +1 -0
  100. package/dist/hooks/hook-types.js +2 -0
  101. package/dist/hooks/hook-types.js.map +1 -0
  102. package/dist/hooks/hook-utils.d.ts +36 -0
  103. package/dist/hooks/hook-utils.d.ts.map +1 -0
  104. package/dist/hooks/hook-utils.js +2 -0
  105. package/dist/hooks/hook-utils.js.map +1 -0
  106. package/dist/hooks/load-hooks-from-samples.d.ts +3 -0
  107. package/dist/hooks/load-hooks-from-samples.d.ts.map +1 -0
  108. package/dist/hooks/load-hooks-from-samples.js +22 -0
  109. package/dist/hooks/load-hooks-from-samples.js.map +1 -0
  110. package/dist/hooks/ts-config.d.ts +10 -0
  111. package/dist/hooks/ts-config.d.ts.map +1 -0
  112. package/dist/hooks/ts-config.js +10 -0
  113. package/dist/hooks/ts-config.js.map +1 -0
  114. package/dist/http-request-sample.d.ts +24 -0
  115. package/dist/http-request-sample.d.ts.map +1 -0
  116. package/dist/http-request-sample.js +11 -0
  117. package/dist/http-request-sample.js.map +1 -0
  118. package/dist/index.d.ts +41 -0
  119. package/dist/index.d.ts.map +1 -0
  120. package/dist/index.js +145 -0
  121. package/dist/index.js.map +1 -0
  122. package/dist/request-sample-to-request-template.d.ts +6 -0
  123. package/dist/request-sample-to-request-template.d.ts.map +1 -0
  124. package/dist/request-sample-to-request-template.js +35 -0
  125. package/dist/request-sample-to-request-template.js.map +1 -0
  126. package/dist/request-sampler.d.ts +15 -0
  127. package/dist/request-sampler.d.ts.map +1 -0
  128. package/dist/request-sampler.js +82 -0
  129. package/dist/request-sampler.js.map +1 -0
  130. package/dist/samples-structure/file-request-sample.d.ts +20 -0
  131. package/dist/samples-structure/file-request-sample.d.ts.map +1 -0
  132. package/dist/samples-structure/file-request-sample.js +5 -0
  133. package/dist/samples-structure/file-request-sample.js.map +1 -0
  134. package/dist/samples-structure/get-path-transaction-id.d.ts +3 -0
  135. package/dist/samples-structure/get-path-transaction-id.d.ts.map +1 -0
  136. package/dist/samples-structure/get-path-transaction-id.js +22 -0
  137. package/dist/samples-structure/get-path-transaction-id.js.map +1 -0
  138. package/dist/samples-structure/merge-tree.d.ts +5 -0
  139. package/dist/samples-structure/merge-tree.d.ts.map +1 -0
  140. package/dist/samples-structure/merge-tree.js +118 -0
  141. package/dist/samples-structure/merge-tree.js.map +1 -0
  142. package/dist/samples-structure/read-samples-from-dir.d.ts +13 -0
  143. package/dist/samples-structure/read-samples-from-dir.d.ts.map +1 -0
  144. package/dist/samples-structure/read-samples-from-dir.js +204 -0
  145. package/dist/samples-structure/read-samples-from-dir.js.map +1 -0
  146. package/dist/samples-structure/samples-from-transactions.d.ts +5 -0
  147. package/dist/samples-structure/samples-from-transactions.d.ts.map +1 -0
  148. package/dist/samples-structure/samples-from-transactions.js +120 -0
  149. package/dist/samples-structure/samples-from-transactions.js.map +1 -0
  150. package/dist/samples-structure/samples-tree-structure.d.ts +106 -0
  151. package/dist/samples-structure/samples-tree-structure.d.ts.map +1 -0
  152. package/dist/samples-structure/samples-tree-structure.js +26 -0
  153. package/dist/samples-structure/samples-tree-structure.js.map +1 -0
  154. package/dist/samples-structure/structure-meta-on-disc.d.ts +11 -0
  155. package/dist/samples-structure/structure-meta-on-disc.d.ts.map +1 -0
  156. package/dist/samples-structure/structure-meta-on-disc.js +2 -0
  157. package/dist/samples-structure/structure-meta-on-disc.js.map +1 -0
  158. package/dist/samples-structure/traverse.d.ts +4 -0
  159. package/dist/samples-structure/traverse.d.ts.map +1 -0
  160. package/dist/samples-structure/traverse.js +13 -0
  161. package/dist/samples-structure/traverse.js.map +1 -0
  162. package/dist/samples-structure/write-samples-to-dir.d.ts +25 -0
  163. package/dist/samples-structure/write-samples-to-dir.d.ts.map +1 -0
  164. package/dist/samples-structure/write-samples-to-dir.js +173 -0
  165. package/dist/samples-structure/write-samples-to-dir.js.map +1 -0
  166. package/dist/utils.d.ts +4 -0
  167. package/dist/utils.d.ts.map +1 -0
  168. package/dist/utils.js +26 -0
  169. package/dist/utils.js.map +1 -0
  170. package/package.json +70 -0
@@ -0,0 +1,172 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { ThymianBaseError, thymianHttpTransactionToString, } from '@thymian/core';
4
+ import { readSamplesFromDir } from '../samples-structure/read-samples-from-dir.js';
5
+ import { entryExists } from '../utils.js';
6
+ import { createHookUtils } from './create-hook-utils.js';
7
+ import { FailError, SkipError } from './hook-errors.js';
8
+ import { loadHooksFromSamples } from './load-hooks-from-samples.js';
9
+ export class HookRunner {
10
+ path;
11
+ runRequest;
12
+ logger;
13
+ initialized = false;
14
+ hooks = new Map();
15
+ urlToTransactionId = {};
16
+ format;
17
+ constructor(path, runRequest, logger) {
18
+ this.path = path;
19
+ this.runRequest = runRequest;
20
+ this.logger = logger;
21
+ }
22
+ async init(format, samplesStructure) {
23
+ if (this.initialized) {
24
+ return;
25
+ }
26
+ if (!(await entryExists(this.path))) {
27
+ return;
28
+ }
29
+ const samples = samplesStructure ?? (await readSamplesFromDir(this.path));
30
+ const meta = JSON.parse(await readFile(join(this.path, 'meta.json'), 'utf-8'));
31
+ this.urlToTransactionId = meta.transactions;
32
+ this.hooks = loadHooksFromSamples(samples);
33
+ this.format = format;
34
+ this.initialized = true;
35
+ }
36
+ async afterEachResponse(hook) {
37
+ if (!this.initialized) {
38
+ throw new ThymianBaseError('Cannot run hooks before @thymian/plugin-sampler is initialized.', {
39
+ name: 'HookRunnerNotInitialized',
40
+ suggestions: ['Did you run "thymian sampler init"?'],
41
+ });
42
+ }
43
+ const { value, ctx } = hook;
44
+ const hooks = ctx.thymianTransaction
45
+ ? this.hooks.get(ctx.thymianTransaction.transactionId)
46
+ : undefined;
47
+ let result = value;
48
+ const testResults = [];
49
+ const utils = createHookUtils(this.format, this.runRequest, this, this.urlToTransactionId, testResults, this.logger);
50
+ for (const afterEach of hooks?.afterEachResponse ?? []) {
51
+ try {
52
+ result = await afterEach(result, ctx, utils);
53
+ }
54
+ catch (e) {
55
+ if (e instanceof SkipError) {
56
+ return {
57
+ result,
58
+ skip: e.message,
59
+ testResults,
60
+ };
61
+ }
62
+ if (e instanceof FailError) {
63
+ return {
64
+ result,
65
+ fail: e.message,
66
+ testResults,
67
+ };
68
+ }
69
+ throw new ThymianBaseError(`Error while running afterEach hook${hook.ctx && hook.ctx.thymianTransaction ? ' for transaction: ' + thymianHttpTransactionToString(hook.ctx.thymianTransaction.thymianReq, hook.ctx.thymianTransaction.thymianRes) : ''}.`, {
70
+ cause: e,
71
+ name: 'HookError',
72
+ });
73
+ }
74
+ }
75
+ return {
76
+ result,
77
+ testResults,
78
+ };
79
+ }
80
+ async authorize(hook) {
81
+ if (!this.initialized) {
82
+ throw new ThymianBaseError('Cannot run hooks before @thymian/plugin-sampler is initialized.', {
83
+ name: 'HookRunnerNotInitialized',
84
+ suggestions: ['Did you run "thymian sampler init"?'],
85
+ });
86
+ }
87
+ const { value, ctx } = hook;
88
+ const hooks = ctx?.transactionId
89
+ ? this.hooks.get(ctx.transactionId)
90
+ : undefined;
91
+ const authorize = hooks?.authorize?.at(-1);
92
+ if (!authorize) {
93
+ return {
94
+ result: value,
95
+ };
96
+ }
97
+ const testResults = [];
98
+ const utils = createHookUtils(this.format, this.runRequest, this, this.urlToTransactionId, testResults, this.logger);
99
+ try {
100
+ const result = await authorize(value, ctx, utils);
101
+ return {
102
+ result,
103
+ testResults,
104
+ };
105
+ }
106
+ catch (e) {
107
+ if (e instanceof SkipError) {
108
+ return {
109
+ result: value,
110
+ skip: e.message,
111
+ testResults,
112
+ };
113
+ }
114
+ if (e instanceof FailError) {
115
+ return {
116
+ result: value,
117
+ fail: e.message,
118
+ testResults,
119
+ };
120
+ }
121
+ throw new ThymianBaseError(`Error while running authorize hook${hook.ctx ? ' for transaction: ' + thymianHttpTransactionToString(hook.ctx.thymianReq, hook.ctx.thymianRes) : ''}.`, {
122
+ cause: e,
123
+ name: 'HookError',
124
+ });
125
+ }
126
+ }
127
+ async beforeEachRequest(hook) {
128
+ if (!this.initialized) {
129
+ throw new ThymianBaseError('Cannot run hooks before @thymian/plugin-sampler is initialized.', {
130
+ name: 'HookRunnerNotInitialized',
131
+ suggestions: ['Did you run "thymian sampler init"?'],
132
+ });
133
+ }
134
+ const { value, ctx } = hook;
135
+ const hooks = ctx?.transactionId
136
+ ? this.hooks.get(ctx.transactionId)
137
+ : undefined;
138
+ let result = value;
139
+ const testResults = [];
140
+ const utils = createHookUtils(this.format, this.runRequest, this, this.urlToTransactionId, testResults, this.logger);
141
+ for (const beforeEach of hooks?.beforeEachRequest ?? []) {
142
+ try {
143
+ result = await beforeEach(result, ctx, utils);
144
+ }
145
+ catch (e) {
146
+ if (e instanceof SkipError) {
147
+ return {
148
+ result,
149
+ skip: e.message,
150
+ testResults,
151
+ };
152
+ }
153
+ if (e instanceof FailError) {
154
+ return {
155
+ result,
156
+ fail: e.message,
157
+ testResults,
158
+ };
159
+ }
160
+ throw new ThymianBaseError(`Error while running beforeEach hook${hook.ctx ? ' for transaction: ' + thymianHttpTransactionToString(hook.ctx.thymianReq, hook.ctx.thymianRes) : ''}.`, {
161
+ cause: e,
162
+ name: 'HookError',
163
+ });
164
+ }
165
+ }
166
+ return {
167
+ result,
168
+ testResults,
169
+ };
170
+ }
171
+ }
172
+ //# sourceMappingURL=hook-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook-runner.js","sourceRoot":"","sources":["../../src/hooks/hook-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAIL,gBAAgB,EAEhB,8BAA8B,GAC/B,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,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AAM,GAAG,KAAK,CAAC;QAEnB,MAAM,WAAW,GAAyB,EAAE,CAAC;QAC7C,MAAM,KAAK,GAAG,eAAe,CAC3B,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,UAAU,EACf,IAAI,EACJ,IAAI,CAAC,kBAAkB,EACvB,WAAW,EACX,IAAI,CAAC,MAAM,CACZ,CAAC;QAEF,KAAK,MAAM,UAAU,IAAI,KAAK,EAAE,iBAAiB,IAAI,EAAE,EAAE,CAAC;YACxD,IAAI,CAAC;gBACH,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;YAChD,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,IAAI,CAAC,YAAY,SAAS,EAAE,CAAC;oBAC3B,OAAO;wBACL,MAAM;wBACN,IAAI,EAAE,CAAC,CAAC,OAAO;wBACf,WAAW;qBACZ,CAAC;gBACJ,CAAC;gBACD,IAAI,CAAC,YAAY,SAAS,EAAE,CAAC;oBAC3B,OAAO;wBACL,MAAM;wBACN,IAAI,EAAE,CAAC,CAAC,OAAO;wBACf,WAAW;qBACZ,CAAC;gBACJ,CAAC;gBAED,MAAM,IAAI,gBAAgB,CACxB,sCAAsC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,oBAAoB,GAAG,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EACxJ;oBACE,KAAK,EAAE,CAAC;oBACR,IAAI,EAAE,WAAW;iBAClB,CACF,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO;YACL,MAAM;YACN,WAAW;SACZ,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ import type { HttpTestHooks } from '@thymian/core';
2
+ import type { Endpoints, HookUtils } from './hook-utils.js';
3
+ export type SampleHttpTestHook<Hook extends keyof HttpTestHooks, E extends Endpoints> = (value: HttpTestHooks[Hook]['arg']['value'], ctx: HttpTestHooks[Hook]['arg']['ctx'], utils: HookUtils<E>) => Promise<HttpTestHooks[Hook]['return']['result']>;
4
+ export type BeforeEachRequestHook<E extends Endpoints = Record<string, any>> = SampleHttpTestHook<'beforeRequest', E>;
5
+ export type AfterEachResponseHook<E extends Endpoints = Record<string, any>> = SampleHttpTestHook<'afterResponse', E>;
6
+ export type AuthorizeHook<E extends Endpoints = Record<string, any>> = SampleHttpTestHook<'authorize', E>;
7
+ //# sourceMappingURL=hook-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook-types.d.ts","sourceRoot":"","sources":["../../src/hooks/hook-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5D,MAAM,MAAM,kBAAkB,CAC5B,IAAI,SAAS,MAAM,aAAa,EAChC,CAAC,SAAS,SAAS,IACjB,CACF,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAC1C,GAAG,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,EACtC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,KAChB,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AAEtD,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IACzE,kBAAkB,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;AACzC,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IACzE,kBAAkB,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;AACzC,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IACjE,kBAAkB,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=hook-types.js.map
@@ -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,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E,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GACrE,IAAI,CAAC;IAER,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAEnD,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,EACvB,GAAG,EAAE,CAAC,EACN,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EACjB,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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=hook-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook-utils.js","sourceRoot":"","sources":["../../src/hooks/hook-utils.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import { type Hooks, type SamplesStructure } from '../samples-structure/samples-tree-structure.js';
2
+ export declare function loadHooksFromSamples(samples: SamplesStructure): Map<string, Hooks>;
3
+ //# sourceMappingURL=load-hooks-from-samples.d.ts.map
@@ -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,10 @@
1
+ export declare const tsConfig: {
2
+ compilerOptions: {
3
+ baseUrl: string;
4
+ paths: {
5
+ '@thymian/hooks': string[];
6
+ };
7
+ };
8
+ include: string[];
9
+ };
10
+ //# sourceMappingURL=ts-config.d.ts.map
@@ -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,10 @@
1
+ export const tsConfig = {
2
+ compilerOptions: {
3
+ baseUrl: '.',
4
+ paths: {
5
+ '@thymian/hooks': ['./types.d.ts'],
6
+ },
7
+ },
8
+ include: ['./**/*.ts'],
9
+ };
10
+ //# sourceMappingURL=ts-config.js.map
@@ -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"}
@@ -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,8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AE,EACpD;oBACE,IAAI,EAAE,gCAAgC;oBACtC,GAAG,EAAE,2EAA2E;iBACjF,CACF,CAAC;YACJ,CAAC;YAED,GAAG,CAAC,KAAK,CAAC,8BAA8B,CAAC,MAAM,CAAC,CAAC,CAAC;QACpD,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,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":[],"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