@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.
Files changed (166) hide show
  1. package/README.md +11 -0
  2. package/dist/cli/commands/sampler/hooks/generate.d.ts +9 -0
  3. package/dist/cli/commands/sampler/hooks/generate.d.ts.map +1 -0
  4. package/dist/cli/commands/sampler/hooks/generate.js +18 -0
  5. package/dist/cli/commands/sampler/hooks/generate.js.map +1 -0
  6. package/dist/cli/commands/sampler/init.d.ts +9 -0
  7. package/dist/cli/commands/sampler/init.d.ts.map +1 -0
  8. package/dist/cli/commands/sampler/init.js +55 -0
  9. package/dist/cli/commands/sampler/init.js.map +1 -0
  10. package/dist/cli/create-context.d.ts +3 -0
  11. package/dist/cli/create-context.d.ts.map +1 -0
  12. package/dist/cli/create-context.js +21 -0
  13. package/dist/cli/create-context.js.map +1 -0
  14. package/dist/cli/generate-hook.d.ts +4 -0
  15. package/dist/cli/generate-hook.d.ts.map +1 -0
  16. package/dist/cli/generate-hook.js +92 -0
  17. package/dist/cli/generate-hook.js.map +1 -0
  18. package/dist/cli/templates.d.ts +4 -0
  19. package/dist/cli/templates.d.ts.map +1 -0
  20. package/dist/cli/templates.js +28 -0
  21. package/dist/cli/templates.js.map +1 -0
  22. package/dist/constants.d.ts +5 -0
  23. package/dist/constants.d.ts.map +1 -0
  24. package/dist/constants.js +5 -0
  25. package/dist/constants.js.map +1 -0
  26. package/dist/generation/content-source-generator.d.ts +10 -0
  27. package/dist/generation/content-source-generator.d.ts.map +1 -0
  28. package/dist/generation/content-source-generator.js +15 -0
  29. package/dist/generation/content-source-generator.js.map +1 -0
  30. package/dist/generation/content-type-strategies/content-type-strategy.d.ts +7 -0
  31. package/dist/generation/content-type-strategies/content-type-strategy.d.ts.map +1 -0
  32. package/dist/generation/content-type-strategies/content-type-strategy.js +2 -0
  33. package/dist/generation/content-type-strategies/content-type-strategy.js.map +1 -0
  34. package/dist/generation/content-type-strategies/error.content-type-strategy.d.ts +7 -0
  35. package/dist/generation/content-type-strategies/error.content-type-strategy.d.ts.map +1 -0
  36. package/dist/generation/content-type-strategies/error.content-type-strategy.js +13 -0
  37. package/dist/generation/content-type-strategies/error.content-type-strategy.js.map +1 -0
  38. package/dist/generation/content-type-strategies/hook.content-type-strategy.d.ts +10 -0
  39. package/dist/generation/content-type-strategies/hook.content-type-strategy.d.ts.map +1 -0
  40. package/dist/generation/content-type-strategies/hook.content-type-strategy.js +27 -0
  41. package/dist/generation/content-type-strategies/hook.content-type-strategy.js.map +1 -0
  42. package/dist/generation/content-type-strategies/image.content-type-strategy.d.ts +15 -0
  43. package/dist/generation/content-type-strategies/image.content-type-strategy.d.ts.map +1 -0
  44. package/dist/generation/content-type-strategies/image.content-type-strategy.js +40 -0
  45. package/dist/generation/content-type-strategies/image.content-type-strategy.js.map +1 -0
  46. package/dist/generation/content-type-strategies/json.content-type-strategy.d.ts +8 -0
  47. package/dist/generation/content-type-strategies/json.content-type-strategy.d.ts.map +1 -0
  48. package/dist/generation/content-type-strategies/json.content-type-strategy.js +12 -0
  49. package/dist/generation/content-type-strategies/json.content-type-strategy.js.map +1 -0
  50. package/dist/generation/content-type-strategies/text.content-type-strategy.d.ts +8 -0
  51. package/dist/generation/content-type-strategies/text.content-type-strategy.d.ts.map +1 -0
  52. package/dist/generation/content-type-strategies/text.content-type-strategy.js +13 -0
  53. package/dist/generation/content-type-strategies/text.content-type-strategy.js.map +1 -0
  54. package/dist/generation/content-type-strategies/xml.content-type-strategy.d.ts +8 -0
  55. package/dist/generation/content-type-strategies/xml.content-type-strategy.d.ts.map +1 -0
  56. package/dist/generation/content-type-strategies/xml.content-type-strategy.js +14 -0
  57. package/dist/generation/content-type-strategies/xml.content-type-strategy.js.map +1 -0
  58. package/dist/generation/generate-samples-for-thymian-format.d.ts +4 -0
  59. package/dist/generation/generate-samples-for-thymian-format.d.ts.map +1 -0
  60. package/dist/generation/generate-samples-for-thymian-format.js +18 -0
  61. package/dist/generation/generate-samples-for-thymian-format.js.map +1 -0
  62. package/dist/generation/generate-samples.d.ts +4 -0
  63. package/dist/generation/generate-samples.d.ts.map +1 -0
  64. package/dist/generation/generate-samples.js +26 -0
  65. package/dist/generation/generate-samples.js.map +1 -0
  66. package/dist/generation/request-generators/default-request-generator.d.ts +22 -0
  67. package/dist/generation/request-generators/default-request-generator.d.ts.map +1 -0
  68. package/dist/generation/request-generators/default-request-generator.js +80 -0
  69. package/dist/generation/request-generators/default-request-generator.js.map +1 -0
  70. package/dist/generation/request-generators/range-request-generator.d.ts +8 -0
  71. package/dist/generation/request-generators/range-request-generator.d.ts.map +1 -0
  72. package/dist/generation/request-generators/range-request-generator.js +22 -0
  73. package/dist/generation/request-generators/range-request-generator.js.map +1 -0
  74. package/dist/generation/request-generators/unauthorized-request-generator.d.ts +6 -0
  75. package/dist/generation/request-generators/unauthorized-request-generator.d.ts.map +1 -0
  76. package/dist/generation/request-generators/unauthorized-request-generator.js +10 -0
  77. package/dist/generation/request-generators/unauthorized-request-generator.js.map +1 -0
  78. package/dist/hooks/create-hook-utils.d.ts +8 -0
  79. package/dist/hooks/create-hook-utils.d.ts.map +1 -0
  80. package/dist/hooks/create-hook-utils.js +137 -0
  81. package/dist/hooks/create-hook-utils.js.map +1 -0
  82. package/dist/hooks/generate-request-types.d.ts +30 -0
  83. package/dist/hooks/generate-request-types.d.ts.map +1 -0
  84. package/dist/hooks/generate-request-types.js +424 -0
  85. package/dist/hooks/generate-request-types.js.map +1 -0
  86. package/dist/hooks/hook-errors.d.ts +5 -0
  87. package/dist/hooks/hook-errors.d.ts.map +1 -0
  88. package/dist/hooks/hook-errors.js +5 -0
  89. package/dist/hooks/hook-errors.js.map +1 -0
  90. package/dist/hooks/hook-runner.d.ts +18 -0
  91. package/dist/hooks/hook-runner.d.ts.map +1 -0
  92. package/dist/hooks/hook-runner.js +172 -0
  93. package/dist/hooks/hook-runner.js.map +1 -0
  94. package/dist/hooks/hook-types.d.ts +7 -0
  95. package/dist/hooks/hook-types.d.ts.map +1 -0
  96. package/dist/hooks/hook-types.js +2 -0
  97. package/dist/hooks/hook-types.js.map +1 -0
  98. package/dist/hooks/hook-utils.d.ts +36 -0
  99. package/dist/hooks/hook-utils.d.ts.map +1 -0
  100. package/dist/hooks/hook-utils.js +2 -0
  101. package/dist/hooks/hook-utils.js.map +1 -0
  102. package/dist/hooks/load-hooks-from-samples.d.ts +3 -0
  103. package/dist/hooks/load-hooks-from-samples.d.ts.map +1 -0
  104. package/dist/hooks/load-hooks-from-samples.js +22 -0
  105. package/dist/hooks/load-hooks-from-samples.js.map +1 -0
  106. package/dist/hooks/ts-config.d.ts +10 -0
  107. package/dist/hooks/ts-config.d.ts.map +1 -0
  108. package/dist/hooks/ts-config.js +10 -0
  109. package/dist/hooks/ts-config.js.map +1 -0
  110. package/dist/http-request-sample.d.ts +24 -0
  111. package/dist/http-request-sample.d.ts.map +1 -0
  112. package/dist/http-request-sample.js +11 -0
  113. package/dist/http-request-sample.js.map +1 -0
  114. package/dist/index.d.ts +41 -0
  115. package/dist/index.d.ts.map +1 -0
  116. package/dist/index.js +145 -0
  117. package/dist/index.js.map +1 -0
  118. package/dist/request-sample-to-request-template.d.ts +6 -0
  119. package/dist/request-sample-to-request-template.d.ts.map +1 -0
  120. package/dist/request-sample-to-request-template.js +35 -0
  121. package/dist/request-sample-to-request-template.js.map +1 -0
  122. package/dist/request-sampler.d.ts +15 -0
  123. package/dist/request-sampler.d.ts.map +1 -0
  124. package/dist/request-sampler.js +82 -0
  125. package/dist/request-sampler.js.map +1 -0
  126. package/dist/samples-structure/file-request-sample.d.ts +20 -0
  127. package/dist/samples-structure/file-request-sample.d.ts.map +1 -0
  128. package/dist/samples-structure/file-request-sample.js +5 -0
  129. package/dist/samples-structure/file-request-sample.js.map +1 -0
  130. package/dist/samples-structure/get-path-transaction-id.d.ts +3 -0
  131. package/dist/samples-structure/get-path-transaction-id.d.ts.map +1 -0
  132. package/dist/samples-structure/get-path-transaction-id.js +22 -0
  133. package/dist/samples-structure/get-path-transaction-id.js.map +1 -0
  134. package/dist/samples-structure/merge-tree.d.ts +5 -0
  135. package/dist/samples-structure/merge-tree.d.ts.map +1 -0
  136. package/dist/samples-structure/merge-tree.js +118 -0
  137. package/dist/samples-structure/merge-tree.js.map +1 -0
  138. package/dist/samples-structure/read-samples-from-dir.d.ts +13 -0
  139. package/dist/samples-structure/read-samples-from-dir.d.ts.map +1 -0
  140. package/dist/samples-structure/read-samples-from-dir.js +204 -0
  141. package/dist/samples-structure/read-samples-from-dir.js.map +1 -0
  142. package/dist/samples-structure/samples-from-transactions.d.ts +5 -0
  143. package/dist/samples-structure/samples-from-transactions.d.ts.map +1 -0
  144. package/dist/samples-structure/samples-from-transactions.js +120 -0
  145. package/dist/samples-structure/samples-from-transactions.js.map +1 -0
  146. package/dist/samples-structure/samples-tree-structure.d.ts +106 -0
  147. package/dist/samples-structure/samples-tree-structure.d.ts.map +1 -0
  148. package/dist/samples-structure/samples-tree-structure.js +26 -0
  149. package/dist/samples-structure/samples-tree-structure.js.map +1 -0
  150. package/dist/samples-structure/structure-meta-on-disc.d.ts +11 -0
  151. package/dist/samples-structure/structure-meta-on-disc.d.ts.map +1 -0
  152. package/dist/samples-structure/structure-meta-on-disc.js +2 -0
  153. package/dist/samples-structure/structure-meta-on-disc.js.map +1 -0
  154. package/dist/samples-structure/traverse.d.ts +4 -0
  155. package/dist/samples-structure/traverse.d.ts.map +1 -0
  156. package/dist/samples-structure/traverse.js +13 -0
  157. package/dist/samples-structure/traverse.js.map +1 -0
  158. package/dist/samples-structure/write-samples-to-dir.d.ts +25 -0
  159. package/dist/samples-structure/write-samples-to-dir.d.ts.map +1 -0
  160. package/dist/samples-structure/write-samples-to-dir.js +173 -0
  161. package/dist/samples-structure/write-samples-to-dir.js.map +1 -0
  162. package/dist/utils.d.ts +4 -0
  163. package/dist/utils.d.ts.map +1 -0
  164. package/dist/utils.js +26 -0
  165. package/dist/utils.js.map +1 -0
  166. package/package.json +51 -0
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # Thymian
2
+
3
+ Add resilience and HTTP conformance to your API development workflow. Thymian is a lightweight, language-agnostic library that helps you build robust APIs.
4
+
5
+ ## @thymian/sampler
6
+
7
+ Generates sample implementations from API specifications.
8
+
9
+ ## Documentation
10
+
11
+ For comprehensive documentation, visit [Thymian Documentation](https://thymian.dev/).
@@ -0,0 +1,9 @@
1
+ import { BaseCliRunCommand } from '@thymian/common-cli';
2
+ export default class GenerateHook extends BaseCliRunCommand<typeof GenerateHook> {
3
+ static aliases: string[];
4
+ static flags: {
5
+ 'for-transaction': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ };
7
+ run(): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=generate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/sampler/hooks/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAKxD,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,iBAAiB,CACzD,OAAO,YAAY,CACpB;IACC,OAAgB,OAAO,WAAsC;IAE7D,OAAgB,KAAK;;MAKnB;IAEa,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAWpC"}
@@ -0,0 +1,18 @@
1
+ import { BaseCliRunCommand } from '@thymian/common-cli';
2
+ import { Flags } from '@thymian/common-cli/oclif';
3
+ import { generateHook } from '../../../generate-hook.js';
4
+ export default class GenerateHook extends BaseCliRunCommand {
5
+ static aliases = ['sampler:hooks:g', 'sampler:h:g'];
6
+ static flags = {
7
+ 'for-transaction': Flags.string({
8
+ description: 'For which transaction do you want to generate a hook?',
9
+ required: false,
10
+ }),
11
+ };
12
+ async run() {
13
+ await this.thymian.run(async (emitter) => {
14
+ await generateHook(this.thymian, emitter, this, this.flags.cwd, this.flags['for-transaction']);
15
+ });
16
+ }
17
+ }
18
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../../../src/cli/commands/sampler/hooks/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,iBAEzC;IACC,MAAM,CAAU,OAAO,GAAG,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAC;IAE7D,MAAM,CAAU,KAAK,GAAG;QACtB,iBAAiB,EAAE,KAAK,CAAC,MAAM,CAAC;YAC9B,WAAW,EAAE,uDAAuD;YACpE,QAAQ,EAAE,KAAK;SAChB,CAAC;KACH,CAAC;IAEO,KAAK,CAAC,GAAG;QAChB,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YACvC,MAAM,YAAY,CAChB,IAAI,CAAC,OAAO,EACZ,OAAO,EACP,IAAI,EACJ,IAAI,CAAC,KAAK,CAAC,GAAG,EACd,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAC9B,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { BaseCliRunCommand, oclif } from '@thymian/common-cli';
2
+ export default class Init extends BaseCliRunCommand<typeof Init> {
3
+ static flags: {
4
+ overwrite: oclif.Interfaces.BooleanFlag<boolean>;
5
+ check: oclif.Interfaces.BooleanFlag<boolean>;
6
+ };
7
+ run(): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/sampler/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAW,MAAM,qBAAqB,CAAC;AAExE,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,iBAAiB,CAAC,OAAO,IAAI,CAAC;IAC9D,OAAgB,KAAK;;;MAYnB;IAEI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAuD3B"}
@@ -0,0 +1,55 @@
1
+ import { BaseCliRunCommand, oclif, prompts } from '@thymian/common-cli';
2
+ export default class Init extends BaseCliRunCommand {
3
+ static flags = {
4
+ overwrite: oclif.Flags.boolean({
5
+ default: false,
6
+ description: 'Overwrite existing samples.',
7
+ }),
8
+ check: oclif.Flags.boolean({
9
+ description: 'After initialization, run a format check to verify all transactions can be executed.',
10
+ allowNo: true,
11
+ default: false,
12
+ }),
13
+ };
14
+ async run() {
15
+ await this.thymian.run(async (emitter) => {
16
+ if (!this.thymian.plugins.find((p) => p.plugin.name === '@thymian/plugin-sampler')) {
17
+ this.error('Cannot initialize sampler if sampler plugin is not registered.', {
18
+ exit: 1,
19
+ });
20
+ }
21
+ const format = await this.thymian.loadFormat({ inputs: [] }, {
22
+ emitFormat: true,
23
+ });
24
+ await emitter.emitAction('sampler.init', {
25
+ format: format.export(),
26
+ overwrite: this.flags.overwrite,
27
+ });
28
+ });
29
+ this.log(oclif.ux.colorize('green', 'Sampler initialized.'));
30
+ if (this.flags.check) {
31
+ if (this.config.findCommand('format:check')) {
32
+ this.log();
33
+ const answer = await prompts.confirm({
34
+ message: 'Do you want to run this check now?',
35
+ });
36
+ if (answer) {
37
+ this.log();
38
+ const args = ['--cwd', this.flags.cwd];
39
+ if (this.flags.config) {
40
+ args.push('-c', this.flags.config);
41
+ }
42
+ await this.config.runCommand('format:check', args);
43
+ }
44
+ }
45
+ }
46
+ else {
47
+ this.log();
48
+ this.log('To check if every transaction can be executed, run:');
49
+ this.log();
50
+ this.log('$ thymian format:check');
51
+ this.log();
52
+ }
53
+ }
54
+ }
55
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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AC,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC;QAE7D,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACrB,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE,CAAC;gBAC5C,IAAI,CAAC,GAAG,EAAE,CAAC;gBACX,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC;oBACnC,OAAO,EAAE,oCAAoC;iBAC9C,CAAC,CAAC;gBAEH,IAAI,MAAM,EAAE,CAAC;oBACX,IAAI,CAAC,GAAG,EAAE,CAAC;oBAEX,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBAEvC,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;wBACtB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;oBACrC,CAAC;oBAED,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;gBACrD,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,GAAG,EAAE,CAAC;YACX,IAAI,CAAC,GAAG,CAAC,qDAAqD,CAAC,CAAC;YAChE,IAAI,CAAC,GAAG,EAAE,CAAC;YACX,IAAI,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;YACnC,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,CAAC;IACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type Logger, ThymianEmitter, ThymianFormat } from '@thymian/core';
2
+ export declare function createContext(format: ThymianFormat, logger: Logger, emitter: ThymianEmitter): import("@thymian/core").HttpTestContext<{}>;
3
+ //# sourceMappingURL=create-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-context.d.ts","sourceRoot":"","sources":["../../src/cli/create-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,MAAM,EACX,cAAc,EACd,aAAa,EAEd,MAAM,eAAe,CAAC;AAMvB,wBAAgB,aAAa,CAC3B,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,cAAc,+CA4BxB"}
@@ -0,0 +1,21 @@
1
+ import { ThymianEmitter, ThymianFormat, } from '@thymian/core';
2
+ import { createHttpTestContext, createHttpTestHookRunnerFromThymianEmitter, } from '@thymian/core';
3
+ export function createContext(format, logger, emitter) {
4
+ return createHttpTestContext({
5
+ format,
6
+ logger,
7
+ locals: {},
8
+ sampleRequest: async function (transaction) {
9
+ return await emitter.emitAction('core.request.sample', { transaction }, { strategy: 'first' });
10
+ },
11
+ runRequest: async function (request) {
12
+ return await emitter.emitAction('core.request.dispatch', {
13
+ request,
14
+ }, {
15
+ strategy: 'first',
16
+ });
17
+ },
18
+ runHook: createHttpTestHookRunnerFromThymianEmitter(emitter),
19
+ });
20
+ }
21
+ //# sourceMappingURL=create-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-context.js","sourceRoot":"","sources":["../../src/cli/create-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,cAAc,EACd,aAAa,GAEd,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,0CAA0C,GAC3C,MAAM,eAAe,CAAC;AAEvB,MAAM,UAAU,aAAa,CAC3B,MAAqB,EACrB,MAAc,EACd,OAAuB;IAEvB,OAAO,qBAAqB,CAAC;QAC3B,MAAM;QACN,MAAM;QACN,MAAM,EAAE,EAAE;QACV,aAAa,EAAE,KAAK,WAClB,WAAmC;YAEnC,OAAO,MAAM,OAAO,CAAC,UAAU,CAC7B,qBAAqB,EACrB,EAAE,WAAW,EAAE,EACf,EAAE,QAAQ,EAAE,OAAO,EAAE,CACtB,CAAC;QACJ,CAAC;QACD,UAAU,EAAE,KAAK,WAAW,OAAoB;YAC9C,OAAO,MAAM,OAAO,CAAC,UAAU,CAC7B,uBAAuB,EACvB;gBACE,OAAO;aACR,EACD;gBACE,QAAQ,EAAE,OAAO;aAClB,CACF,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,0CAA0C,CAAC,OAAO,CAAC;KAC7D,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { BaseCliRunCommand, oclif } from '@thymian/common-cli';
2
+ import { type Thymian, type ThymianEmitter, type ThymianFormat } from '@thymian/core';
3
+ export declare function generateHook<T extends typeof oclif.Command = typeof oclif.Command>(thymian: Thymian, emitter: ThymianEmitter, command: BaseCliRunCommand<T>, cwd: string, forTransaction?: string, loadedThymianFormat?: ThymianFormat): Promise<void>;
4
+ //# sourceMappingURL=generate-hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-hook.d.ts","sourceRoot":"","sources":["../../src/cli/generate-hook.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAW,MAAM,qBAAqB,CAAC;AACxE,OAAO,EACL,KAAK,OAAO,EAEZ,KAAK,cAAc,EACnB,KAAK,aAAa,EAGnB,MAAM,eAAe,CAAC;AASvB,wBAAsB,YAAY,CAChC,CAAC,SAAS,OAAO,KAAK,CAAC,OAAO,GAAG,OAAO,KAAK,CAAC,OAAO,EAErD,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC7B,GAAG,EAAE,MAAM,EACX,cAAc,CAAC,EAAE,MAAM,EACvB,mBAAmB,CAAC,EAAE,aAAa,GAClC,OAAO,CAAC,IAAI,CAAC,CAiHf"}
@@ -0,0 +1,92 @@
1
+ import { writeFile } from 'node:fs/promises';
2
+ import { format, join, relative } from 'node:path';
3
+ import { BaseCliRunCommand, oclif, prompts } from '@thymian/common-cli';
4
+ import { ThymianBaseError, thymianHttpTransactionToString, } from '@thymian/core';
5
+ import launchEditor from 'launch-editor';
6
+ import { afterEachRequestHook, authorizeHook, beforeEachRequestHook, } from './templates.js';
7
+ export async function generateHook(thymian, emitter, command, cwd, forTransaction, loadedThymianFormat) {
8
+ const thymianFormat = loadedThymianFormat ?? (await thymian.loadFormat({ inputs: [] }));
9
+ const titleToTransaction = new Map();
10
+ for (const t of thymianFormat.getThymianHttpTransactions()) {
11
+ titleToTransaction.set(thymianHttpTransactionToString(t.thymianReq, t.thymianRes), t);
12
+ }
13
+ const transactions = [...titleToTransaction.keys()].map((title) => ({
14
+ name: title,
15
+ value: title,
16
+ }));
17
+ let transaction;
18
+ if (!forTransaction) {
19
+ const result = await prompts.search({
20
+ message: 'For which transaction do you want to generate a hook?',
21
+ source: (answersSoFar) => {
22
+ if (typeof answersSoFar === 'undefined') {
23
+ return transactions;
24
+ }
25
+ return transactions.filter((t) => t.value.toLowerCase().includes(answersSoFar.toLowerCase()));
26
+ },
27
+ });
28
+ transaction = titleToTransaction.get(result);
29
+ }
30
+ else {
31
+ transaction = thymianFormat.getThymianHttpTransactionById(forTransaction);
32
+ }
33
+ if (!transaction) {
34
+ throw new ThymianBaseError('Invalid transaction selected.', {
35
+ name: 'InvalidTransactionError',
36
+ ref: 'https://thymian.dev/references/errors/invalid-transaction-error/',
37
+ });
38
+ }
39
+ const path = await emitter.emitAction('sampler.path-from-transaction', {
40
+ transactionId: transaction.transactionId,
41
+ }, {
42
+ strategy: 'first',
43
+ });
44
+ if (path) {
45
+ const relativePath = relative(cwd, path);
46
+ const answer = await prompts.confirm({
47
+ message: `Do you want to generate a hook file at ${oclif.ux.colorize('bold', oclif.ux.colorize('underline', relativePath))}?`,
48
+ default: true,
49
+ });
50
+ if (answer) {
51
+ const choice = await prompts.select({
52
+ message: 'When do you want to execute the hook?',
53
+ choices: ['Before each request', 'After each response', 'Authorize'],
54
+ });
55
+ const fileName = Math.random().toString(36).slice(2, 7);
56
+ const dir = join(path, '..');
57
+ const suffix = choice === 'After each response'
58
+ ? 'afterEach'
59
+ : choice === 'Before each request'
60
+ ? 'beforeEach'
61
+ : 'authorize';
62
+ const fullFilePath = format({
63
+ dir,
64
+ name: `${fileName}.${suffix}`,
65
+ ext: '.ts',
66
+ });
67
+ if (choice === 'After each response') {
68
+ await writeFile(fullFilePath, afterEachRequestHook);
69
+ }
70
+ else if (choice === 'Authorize') {
71
+ await writeFile(fullFilePath, authorizeHook);
72
+ }
73
+ else {
74
+ await writeFile(fullFilePath, beforeEachRequestHook);
75
+ }
76
+ command.log(oclif.ux.colorize('green', 'Hook generated successfully!'));
77
+ const openInEditor = await prompts.confirm({
78
+ message: `Do you want to open the file in your editor now?`,
79
+ default: true,
80
+ });
81
+ if (openInEditor) {
82
+ launchEditor(fullFilePath, 'webstorm', (_, errorMessage) => {
83
+ if (errorMessage) {
84
+ command.error(errorMessage);
85
+ }
86
+ command.log('Opening file in editor.');
87
+ });
88
+ }
89
+ }
90
+ }
91
+ }
92
+ //# sourceMappingURL=generate-hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-hook.js","sourceRoot":"","sources":["../../src/cli/generate-hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAEL,gBAAgB,EAIhB,8BAA8B,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,YAAY,MAAM,eAAe,CAAC;AAEzC,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAExB,MAAM,CAAC,KAAK,UAAU,YAAY,CAGhC,OAAgB,EAChB,OAAuB,EACvB,OAA6B,EAC7B,GAAW,EACX,cAAuB,EACvB,mBAAmC;IAEnC,MAAM,aAAa,GACjB,mBAAmB,IAAI,CAAC,MAAM,OAAO,CAAC,UA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AAG,EAAE,KAAK;aACX,CAAC,CAAC;YAEH,IAAI,MAAM,KAAK,qBAAqB,EAAE,CAAC;gBACrC,MAAM,SAAS,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;YACtD,CAAC;iBAAM,IAAI,MAAM,KAAK,WAAW,EAAE,CAAC;gBAClC,MAAM,SAAS,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;YAC/C,CAAC;iBAAM,CAAC;gBACN,MAAM,SAAS,CAAC,YAAY,EAAE,qBAAqB,CAAC,CAAC;YACvD,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,8BAA8B,CAAC,CAAC,CAAC;YAExE,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC;gBACzC,OAAO,EAAE,kDAAkD;gBAC3D,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;YAEH,IAAI,YAAY,EAAE,CAAC;gBACjB,YAAY,CAAC,YAAY,EAAE,UAAU,EAAE,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE;oBACzD,IAAI,YAAY,EAAE,CAAC;wBACjB,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;oBAC9B,CAAC;oBAED,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;gBACzC,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const beforeEachRequestHook = "import * as Hooks from '@thymian/hooks';\n\nconst hook: Hooks.BeforeEachRequestHook = async (request, context, utils) => {\n\n return request;\n}\n\nexport default hook;\n";
2
+ export declare const afterEachRequestHook = "import * as Hooks from '@thymian/hooks';\n\nconst hook: Hooks.AfterEachRequestHook = async (response, context, utils) => {\n\n return response;\n}\n\nexport default hook;\n";
3
+ export declare const authorizeHook = "import * as Hooks from '@thymian/hooks';\n\nconst hook: Hooks.AuthorizeHook = async (request, context, utils) => {\n\n return request;\n}\n\nexport default hook;\n";
4
+ //# sourceMappingURL=templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/cli/templates.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,iLAQjC,CAAC;AAEF,eAAO,MAAM,oBAAoB,kLAQhC,CAAC;AAEF,eAAO,MAAM,aAAa,yKAQzB,CAAC"}
@@ -0,0 +1,28 @@
1
+ export const beforeEachRequestHook = `import * as Hooks from '@thymian/hooks';
2
+
3
+ const hook: Hooks.BeforeEachRequestHook = async (request, context, utils) => {
4
+
5
+ return request;
6
+ }
7
+
8
+ export default hook;
9
+ `;
10
+ export const afterEachRequestHook = `import * as Hooks from '@thymian/hooks';
11
+
12
+ const hook: Hooks.AfterEachRequestHook = async (response, context, utils) => {
13
+
14
+ return response;
15
+ }
16
+
17
+ export default hook;
18
+ `;
19
+ export const authorizeHook = `import * as Hooks from '@thymian/hooks';
20
+
21
+ const hook: Hooks.AuthorizeHook = async (request, context, utils) => {
22
+
23
+ return request;
24
+ }
25
+
26
+ export default hook;
27
+ `;
28
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../src/cli/templates.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;CAQpC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;CAQnC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;CAQ5B,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const SAMPLE_FILE: RegExp;
2
+ export declare const BEFORE_EACH_HOOK: RegExp;
3
+ export declare const AFTER_EACH_HOOK: RegExp;
4
+ export declare const AUTHORIZE_HOOK: RegExp;
5
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,QAAoB,CAAC;AAC7C,eAAO,MAAM,gBAAgB,QAA+C,CAAC;AAC7E,eAAO,MAAM,eAAe,QAA8C,CAAC;AAC3E,eAAO,MAAM,cAAc,QAA8C,CAAC"}
@@ -0,0 +1,5 @@
1
+ export const SAMPLE_FILE = /.*request\.json/;
2
+ export const BEFORE_EACH_HOOK = /(.*\.)?beforeEach\.(ts|js|mjs|cjs|mts|cts)/;
3
+ export const AFTER_EACH_HOOK = /(.*\.)?afterEach\.(ts|js|mjs|cjs|mts|cts)/;
4
+ export const AUTHORIZE_HOOK = /(.*\.)?authorize\.(ts|js|mjs|cjs|mts|cts)/;
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAC7C,MAAM,CAAC,MAAM,gBAAgB,GAAG,4CAA4C,CAAC;AAC7E,MAAM,CAAC,MAAM,eAAe,GAAG,2CAA2C,CAAC;AAC3E,MAAM,CAAC,MAAM,cAAc,GAAG,2CAA2C,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ThymianSchema } from '@thymian/core';
2
+ import type { ContentSource } from '../http-request-sample.js';
3
+ import type { ContentTypeStrategy } from './content-type-strategies/content-type-strategy.js';
4
+ export declare class ContentSourceGenerator {
5
+ private readonly strategies;
6
+ private readonly fallbackStrategy;
7
+ constructor(strategies: ContentTypeStrategy[], fallbackStrategy?: ContentTypeStrategy);
8
+ generate(contentType: string, schema: ThymianSchema): Promise<ContentSource>;
9
+ }
10
+ //# sourceMappingURL=content-source-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-source-generator.d.ts","sourceRoot":"","sources":["../../src/generation/content-source-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oDAAoD,CAAC;AAG9F,qBAAa,sBAAsB;IAE/B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;gBADhB,UAAU,EAAE,mBAAmB,EAAE,EACjC,gBAAgB,GAAE,mBAAoD;IAGzF,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;CAO7E"}
@@ -0,0 +1,15 @@
1
+ import { ErrorContentTypeStrategy } from './content-type-strategies/error.content-type-strategy.js';
2
+ export class ContentSourceGenerator {
3
+ strategies;
4
+ fallbackStrategy;
5
+ constructor(strategies, fallbackStrategy = new ErrorContentTypeStrategy()) {
6
+ this.strategies = strategies;
7
+ this.fallbackStrategy = fallbackStrategy;
8
+ }
9
+ generate(contentType, schema) {
10
+ const strategy = this.strategies.find((strategy) => strategy.matches(contentType)) ??
11
+ this.fallbackStrategy;
12
+ return strategy.generate(schema, contentType);
13
+ }
14
+ }
15
+ //# sourceMappingURL=content-source-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-source-generator.js","sourceRoot":"","sources":["../../src/generation/content-source-generator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,wBAAwB,EAAE,MAAM,0DAA0D,CAAC;AAEpG,MAAM,OAAO,sBAAsB;IAEd;IACA;IAFnB,YACmB,UAAiC,EACjC,mBAAwC,IAAI,wBAAwB,EAAE;QADtE,eAAU,GAAV,UAAU,CAAuB;QACjC,qBAAgB,GAAhB,gBAAgB,CAAsD;IACtF,CAAC;IAEJ,QAAQ,CAAC,WAAmB,EAAE,MAAqB;QACjD,MAAM,QAAQ,GACZ,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YACjE,IAAI,CAAC,gBAAgB,CAAC;QAExB,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAChD,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ import type { ThymianSchema } from '@thymian/core';
2
+ import type { ContentSource } from '../../http-request-sample.js';
3
+ export interface ContentTypeStrategy {
4
+ matches(contentType: string): boolean;
5
+ generate(schema: ThymianSchema, contentType: string): Promise<ContentSource>;
6
+ }
7
+ //# sourceMappingURL=content-type-strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-type-strategy.d.ts","sourceRoot":"","sources":["../../../src/generation/content-type-strategies/content-type-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;IAEtC,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAC9E"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=content-type-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-type-strategy.js","sourceRoot":"","sources":["../../../src/generation/content-type-strategies/content-type-strategy.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import { type ThymianSchema } from '@thymian/core';
2
+ import type { ContentTypeStrategy } from './content-type-strategy.js';
3
+ export declare class ErrorContentTypeStrategy implements ContentTypeStrategy {
4
+ matches(): boolean;
5
+ generate(schema: ThymianSchema, contentType: string): never;
6
+ }
7
+ //# sourceMappingURL=error.content-type-strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.content-type-strategy.d.ts","sourceRoot":"","sources":["../../../src/generation/content-type-strategies/error.content-type-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,qBAAa,wBAAyB,YAAW,mBAAmB;IAClE,OAAO,IAAI,OAAO;IAIlB,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,GAAG,KAAK;CAS5D"}
@@ -0,0 +1,13 @@
1
+ import { ThymianBaseError } from '@thymian/core';
2
+ export class ErrorContentTypeStrategy {
3
+ matches() {
4
+ return false;
5
+ }
6
+ generate(schema, contentType) {
7
+ throw new ThymianBaseError(`Cannot generate content for content type "${contentType}".`, {
8
+ name: 'UnsupportedContentTypeError',
9
+ ref: 'https://thymian.dev/references/errors/unsupported-content-type-error/',
10
+ });
11
+ }
12
+ }
13
+ //# sourceMappingURL=error.content-type-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.content-type-strategy.js","sourceRoot":"","sources":["../../../src/generation/content-type-strategies/error.content-type-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAsB,MAAM,eAAe,CAAC;AAIrE,MAAM,OAAO,wBAAwB;IACnC,OAAO;QACL,OAAO,KAAK,CAAC;IACf,CAAC;IAED,QAAQ,CAAC,MAAqB,EAAE,WAAmB;QACjD,MAAM,IAAI,gBAAgB,CACxB,6CAA6C,WAAW,IAAI,EAC5D;YACE,IAAI,EAAE,6BAA6B;YACnC,GAAG,EAAE,uEAAuE;SAC7E,CACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import { ThymianEmitter, type ThymianSchema } from '@thymian/core';
2
+ import type { ContentSource } from '../../http-request-sample.js';
3
+ import type { ContentTypeStrategy } from './content-type-strategy.js';
4
+ export declare class HookContentTypeStrategy implements ContentTypeStrategy {
5
+ private readonly emitter;
6
+ constructor(emitter: ThymianEmitter);
7
+ matches(): boolean;
8
+ generate(schema: ThymianSchema, contentType: string): Promise<ContentSource>;
9
+ }
10
+ //# sourceMappingURL=hook.content-type-strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.content-type-strategy.d.ts","sourceRoot":"","sources":["../../../src/generation/content-type-strategies/hook.content-type-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,KAAK,aAAa,EACnB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,qBAAa,uBAAwB,YAAW,mBAAmB;IACrD,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,cAAc;IAEpD,OAAO,IAAI,OAAO;IAIZ,QAAQ,CACZ,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,aAAa,CAAC;CAyB1B"}
@@ -0,0 +1,27 @@
1
+ import { ThymianBaseError, ThymianEmitter, } from '@thymian/core';
2
+ export class HookContentTypeStrategy {
3
+ emitter;
4
+ constructor(emitter) {
5
+ this.emitter = emitter;
6
+ }
7
+ matches() {
8
+ return false;
9
+ }
10
+ async generate(schema, contentType) {
11
+ const content = await this.emitter.emitAction('sampler.unknown-type', {
12
+ schema,
13
+ contentType,
14
+ }, {
15
+ strategy: 'first',
16
+ strict: false,
17
+ });
18
+ if (!content) {
19
+ throw new ThymianBaseError(`Cannot sample data for content type ${contentType}.`, {
20
+ name: 'UnsupportedContentTypeError',
21
+ ref: 'https://thymian.dev/references/errors/unsupported-content-type-error/',
22
+ });
23
+ }
24
+ return content;
25
+ }
26
+ }
27
+ //# sourceMappingURL=hook.content-type-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.content-type-strategy.js","sourceRoot":"","sources":["../../../src/generation/content-type-strategies/hook.content-type-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,cAAc,GAEf,MAAM,eAAe,CAAC;AAKvB,MAAM,OAAO,uBAAuB;IACL;IAA7B,YAA6B,OAAuB;QAAvB,YAAO,GAAP,OAAO,CAAgB;IAAG,CAAC;IAExD,OAAO;QACL,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,QAAQ,CACZ,MAAqB,EACrB,WAAmB;QAEnB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAC3C,sBAAsB,EACtB;YACE,MAAM;YACN,WAAW;SACZ,EACD;YACE,QAAQ,EAAE,OAAO;YACjB,MAAM,EAAE,KAAK;SACd,CACF,CAAC;QAEF,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,gBAAgB,CACxB,uCAAuC,WAAW,GAAG,EACrD;gBACE,IAAI,EAAE,6BAA6B;gBACnC,GAAG,EAAE,uEAAuE;aAC7E,CACF,CAAC;QACJ,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ import type { ThymianSchema } from '@thymian/core';
2
+ import type { ContentSource } from '../../http-request-sample.js';
3
+ import type { ContentTypeStrategy } from './content-type-strategy.js';
4
+ export type ImageContentTypeStrategyOptions = {
5
+ width: number;
6
+ height: number;
7
+ };
8
+ export declare class ImageContentTypeStrategy implements ContentTypeStrategy {
9
+ private readonly options;
10
+ constructor(options?: Partial<ImageContentTypeStrategyOptions>);
11
+ matches(contentType: string): boolean;
12
+ generate(schema: ThymianSchema, contentType: string): Promise<ContentSource>;
13
+ private randomPixelsBuffer;
14
+ }
15
+ //# sourceMappingURL=image.content-type-strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.content-type-strategy.d.ts","sourceRoot":"","sources":["../../../src/generation/content-type-strategies/image.content-type-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,MAAM,MAAM,+BAA+B,GAAG;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,qBAAa,wBAAyB,YAAW,mBAAmB;IAClE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkC;gBAE9C,OAAO,GAAE,OAAO,CAAC,+BAA+B,CAAM;IAQlE,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAI/B,QAAQ,CACZ,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,aAAa,CAAC;IAoBzB,OAAO,CAAC,kBAAkB;CAS3B"}
@@ -0,0 +1,40 @@
1
+ import sharp from 'sharp';
2
+ export class ImageContentTypeStrategy {
3
+ options;
4
+ constructor(options = {}) {
5
+ this.options = {
6
+ width: 256,
7
+ height: 256,
8
+ ...options,
9
+ };
10
+ }
11
+ matches(contentType) {
12
+ // TODO: fill regex https://sharp.pixelplumbing.com/api-output/
13
+ return /^image\/(jpeg|png|jpg)/i.test(contentType);
14
+ }
15
+ async generate(schema, contentType) {
16
+ let content = sharp(this.randomPixelsBuffer(), {
17
+ raw: {
18
+ width: this.options.width,
19
+ height: this.options.height,
20
+ channels: 3,
21
+ },
22
+ });
23
+ content = /^image\/(png)/i.test(contentType)
24
+ ? content.png()
25
+ : content.jpeg();
26
+ return {
27
+ $encoding: 'base64',
28
+ $buffer: await content.toBuffer(),
29
+ $ext: 'png',
30
+ };
31
+ }
32
+ randomPixelsBuffer() {
33
+ const buffer = Buffer.alloc(this.options.height * this.options.width * 3);
34
+ for (let i = 0; i < buffer.length; i++) {
35
+ buffer[i] = Math.floor(Math.random() * 256);
36
+ }
37
+ return buffer;
38
+ }
39
+ }
40
+ //# sourceMappingURL=image.content-type-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.content-type-strategy.js","sourceRoot":"","sources":["../../../src/generation/content-type-strategies/image.content-type-strategy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAU1B,MAAM,OAAO,wBAAwB;IAClB,OAAO,CAAkC;IAE1D,YAAY,UAAoD,EAAE;QAChE,IAAI,CAAC,OAAO,GAAG;YACb,KAAK,EAAE,GAAG;YACV,MAAM,EAAE,GAAG;YACX,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,WAAmB;QACzB,+DAA+D;QAC/D,OAAO,yBAAyB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACrD,CAAC;IACD,KAAK,CAAC,QAAQ,CACZ,MAAqB,EACrB,WAAmB;QAEnB,IAAI,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE;YAC7C,GAAG,EAAE;gBACH,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;gBACzB,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;gBAC3B,QAAQ,EAAE,CAAC;aACZ;SACF,CAAC,CAAC;QAEH,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC;YAC1C,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;YACf,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAEnB,OAAO;YACL,SAAS,EAAE,QAAQ;YACnB,OAAO,EAAE,MAAM,OAAO,CAAC,QAAQ,EAAE;YACjC,IAAI,EAAE,KAAK;SACZ,CAAC;IACJ,CAAC;IAEO,kBAAkB;QACxB,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAE1E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACvC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;QAC9C,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ import type { ThymianSchema } from '@thymian/core';
2
+ import type { ContentSource } from '../../http-request-sample.js';
3
+ import type { ContentTypeStrategy } from './content-type-strategy.js';
4
+ export declare class JsonContentTypeStrategy implements ContentTypeStrategy {
5
+ matches(contentType: string): boolean;
6
+ generate(schema: ThymianSchema): Promise<ContentSource>;
7
+ }
8
+ //# sourceMappingURL=json.content-type-strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.content-type-strategy.d.ts","sourceRoot":"","sources":["../../../src/generation/content-type-strategies/json.content-type-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAItE,qBAAa,uBAAwB,YAAW,mBAAmB;IACjE,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAI/B,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;CAK9D"}
@@ -0,0 +1,12 @@
1
+ import { sample } from 'openapi-sampler';
2
+ export class JsonContentTypeStrategy {
3
+ matches(contentType) {
4
+ return /^application\/[^+]*[+]?(json);?.*/.test(contentType);
5
+ }
6
+ async generate(schema) {
7
+ return {
8
+ $content: sample(schema),
9
+ };
10
+ }
11
+ }
12
+ //# sourceMappingURL=json.content-type-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.content-type-strategy.js","sourceRoot":"","sources":["../../../src/generation/content-type-strategies/json.content-type-strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAOzC,MAAM,OAAO,uBAAuB;IAClC,OAAO,CAAC,WAAmB;QACzB,OAAO,mCAAmC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAqB;QAClC,OAAO;YACL,QAAQ,EAAE,MAAM,CAAC,MAAuB,CAAC;SAC1C,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ import type { ThymianSchema } from '@thymian/core';
2
+ import type { ContentSource } from '../../http-request-sample.js';
3
+ import type { ContentTypeStrategy } from './content-type-strategy.js';
4
+ export declare class PlainTextContentTypeStrategy implements ContentTypeStrategy {
5
+ matches(contentType: string): boolean;
6
+ generate(schema: ThymianSchema): Promise<ContentSource>;
7
+ }
8
+ //# sourceMappingURL=text.content-type-strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.content-type-strategy.d.ts","sourceRoot":"","sources":["../../../src/generation/content-type-strategies/text.content-type-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,qBAAa,4BAA6B,YAAW,mBAAmB;IACtE,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAI/B,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;CAO9D"}
@@ -0,0 +1,13 @@
1
+ export class PlainTextContentTypeStrategy {
2
+ matches(contentType) {
3
+ return /^text\/plain;?.*/.test(contentType);
4
+ }
5
+ async generate(schema) {
6
+ return {
7
+ $encoding: 'utf-8',
8
+ $ext: '.txt',
9
+ $buffer: Buffer.from(schema.examples?.[0]?.toString() || 'plain text'),
10
+ };
11
+ }
12
+ }
13
+ //# sourceMappingURL=text.content-type-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.content-type-strategy.js","sourceRoot":"","sources":["../../../src/generation/content-type-strategies/text.content-type-strategy.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,4BAA4B;IACvC,OAAO,CAAC,WAAmB;QACzB,OAAO,kBAAkB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAqB;QAClC,OAAO;YACL,SAAS,EAAE,OAAO;YAClB,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,YAAY,CAAC;SACvE,CAAC;IACJ,CAAC;CACF"}