swagger-sdk-generator 0.0.0-stage → 3.0.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 (217) hide show
  1. package/README.md +58 -2
  2. package/dist/cli/commands/generate.d.ts +2 -0
  3. package/dist/cli/commands/generate.js +196 -0
  4. package/dist/cli/commands/init.d.ts +2 -0
  5. package/dist/cli/commands/init.js +130 -0
  6. package/dist/cli/commands/inspect.d.ts +2 -0
  7. package/dist/cli/commands/inspect.js +164 -0
  8. package/dist/cli/commands/templates.d.ts +2 -0
  9. package/dist/cli/commands/templates.js +126 -0
  10. package/dist/cli/context.d.ts +16 -0
  11. package/dist/cli/context.js +85 -0
  12. package/dist/cli/main.d.ts +2 -0
  13. package/dist/cli/main.js +25 -0
  14. package/dist/config/dotenv.d.ts +2 -0
  15. package/dist/config/dotenv.js +82 -0
  16. package/dist/config/interpolate.d.ts +8 -0
  17. package/dist/config/interpolate.js +85 -0
  18. package/dist/config/load.d.ts +11 -0
  19. package/dist/config/load.js +182 -0
  20. package/dist/config/migrate-v3.d.ts +5 -0
  21. package/dist/config/migrate-v3.js +6 -0
  22. package/dist/config/mode-compatibility.d.ts +9 -0
  23. package/dist/config/mode-compatibility.js +17 -0
  24. package/dist/config/modes.d.ts +13 -0
  25. package/dist/config/modes.js +27 -0
  26. package/dist/config/preset-definitions.d.ts +2 -0
  27. package/dist/config/preset-definitions.js +4 -0
  28. package/dist/config/presets.d.ts +25 -0
  29. package/dist/config/presets.js +36 -0
  30. package/dist/config/resolve.d.ts +32 -0
  31. package/dist/config/resolve.js +288 -0
  32. package/dist/config/schema.d.ts +93 -0
  33. package/dist/config/schema.js +173 -0
  34. package/dist/config/types.d.ts +42 -0
  35. package/dist/config/types.js +2 -0
  36. package/dist/config/workspace.d.ts +30 -0
  37. package/dist/config/workspace.js +95 -0
  38. package/dist/core/case-align.d.ts +5 -0
  39. package/dist/core/case-align.js +90 -0
  40. package/dist/core/deep-merge.d.ts +2 -0
  41. package/dist/core/deep-merge.js +21 -0
  42. package/dist/core/file-set.d.ts +10 -0
  43. package/dist/core/file-set.js +31 -0
  44. package/dist/core/import-module.d.ts +1 -0
  45. package/dist/core/import-module.js +61 -0
  46. package/dist/core/log.d.ts +9 -0
  47. package/dist/core/log.js +24 -0
  48. package/dist/core/manifest.d.ts +17 -0
  49. package/dist/core/manifest.js +195 -0
  50. package/dist/core/overlaps.d.ts +6 -0
  51. package/dist/core/overlaps.js +67 -0
  52. package/dist/core/package-version.d.ts +1 -0
  53. package/dist/core/package-version.js +44 -0
  54. package/dist/core/pipeline.d.ts +30 -0
  55. package/dist/core/pipeline.js +335 -0
  56. package/dist/core/plugin.d.ts +72 -0
  57. package/dist/core/plugin.js +2 -0
  58. package/dist/core/targets.d.ts +14 -0
  59. package/dist/core/targets.js +120 -0
  60. package/dist/core/unmanaged.d.ts +3 -0
  61. package/dist/core/unmanaged.js +101 -0
  62. package/dist/core/writer.d.ts +28 -0
  63. package/dist/core/writer.js +148 -0
  64. package/dist/index.d.ts +20 -0
  65. package/dist/index.js +37 -0
  66. package/dist/ir/casing.d.ts +5 -0
  67. package/dist/ir/casing.js +22 -0
  68. package/dist/ir/graph.d.ts +8 -0
  69. package/dist/ir/graph.js +95 -0
  70. package/dist/ir/operations/grouping.d.ts +17 -0
  71. package/dist/ir/operations/grouping.js +39 -0
  72. package/dist/ir/operations/legacy-naming.d.ts +2 -0
  73. package/dist/ir/operations/legacy-naming.js +8 -0
  74. package/dist/ir/operations/naming.d.ts +6 -0
  75. package/dist/ir/operations/naming.js +54 -0
  76. package/dist/ir/option-errors.d.ts +3 -0
  77. package/dist/ir/option-errors.js +68 -0
  78. package/dist/ir/transforms/builtins.d.ts +2 -0
  79. package/dist/ir/transforms/builtins.js +4 -0
  80. package/dist/ir/transforms/index.d.ts +10 -0
  81. package/dist/ir/transforms/index.js +39 -0
  82. package/dist/ir/transforms/types.d.ts +9 -0
  83. package/dist/ir/transforms/types.js +2 -0
  84. package/dist/ir/types.d.ts +140 -0
  85. package/dist/ir/types.js +2 -0
  86. package/dist/runtime/axios.d.ts +28 -0
  87. package/dist/runtime/axios.js +132 -0
  88. package/dist/runtime/fetch.d.ts +6 -0
  89. package/dist/runtime/fetch.js +38 -0
  90. package/dist/runtime/index.d.ts +54 -0
  91. package/dist/runtime/index.js +167 -0
  92. package/dist/runtime/rtk.d.ts +35 -0
  93. package/dist/runtime/rtk.js +36 -0
  94. package/dist/runtime/transport.d.ts +38 -0
  95. package/dist/runtime/transport.js +30 -0
  96. package/dist/runtime/wire.d.ts +27 -0
  97. package/dist/runtime/wire.js +148 -0
  98. package/dist/spec/html-entities.d.ts +1 -0
  99. package/dist/spec/html-entities.js +25 -0
  100. package/dist/spec/load.d.ts +26 -0
  101. package/dist/spec/load.js +130 -0
  102. package/dist/spec/openapi/all-of.d.ts +3 -0
  103. package/dist/spec/openapi/all-of.js +9 -0
  104. package/dist/spec/openapi/normalize.d.ts +4 -0
  105. package/dist/spec/openapi/normalize.js +31 -0
  106. package/dist/spec/openapi/operations.d.ts +4 -0
  107. package/dist/spec/openapi/operations.js +173 -0
  108. package/dist/spec/openapi/schema.d.ts +51 -0
  109. package/dist/spec/openapi/schema.js +307 -0
  110. package/dist/targets/declarative/config.d.ts +533 -0
  111. package/dist/targets/declarative/config.js +280 -0
  112. package/dist/targets/declarative/extensions.d.ts +45 -0
  113. package/dist/targets/declarative/extensions.js +123 -0
  114. package/dist/targets/declarative/files.d.ts +13 -0
  115. package/dist/targets/declarative/files.js +127 -0
  116. package/dist/targets/declarative/format.d.ts +4 -0
  117. package/dist/targets/declarative/format.js +104 -0
  118. package/dist/targets/declarative/index.d.ts +9 -0
  119. package/dist/targets/declarative/index.js +170 -0
  120. package/dist/targets/declarative/liquid.d.ts +8 -0
  121. package/dist/targets/declarative/liquid.js +57 -0
  122. package/dist/targets/declarative/naming-case.d.ts +3 -0
  123. package/dist/targets/declarative/naming-case.js +31 -0
  124. package/dist/targets/declarative/naming.d.ts +42 -0
  125. package/dist/targets/declarative/naming.js +174 -0
  126. package/dist/targets/declarative/scaffold.d.ts +5 -0
  127. package/dist/targets/declarative/scaffold.js +146 -0
  128. package/dist/targets/declarative/types.d.ts +52 -0
  129. package/dist/targets/declarative/types.js +287 -0
  130. package/dist/targets/declarative/views.d.ts +180 -0
  131. package/dist/targets/declarative/views.js +447 -0
  132. package/dist/targets/python/extensions.js +152 -0
  133. package/dist/targets/python/target.json +549 -0
  134. package/dist/targets/python/templates/client/client.liquid +114 -0
  135. package/dist/targets/python/templates/client/httpx_transport.liquid +172 -0
  136. package/dist/targets/python/templates/client/init.liquid +20 -0
  137. package/dist/targets/python/templates/client/partials/operation_method.liquid +41 -0
  138. package/dist/targets/python/templates/client/resource.liquid +28 -0
  139. package/dist/targets/python/templates/client/runtime.liquid +133 -0
  140. package/dist/targets/python/templates/client/transport.liquid +62 -0
  141. package/dist/targets/python/templates/models/module.liquid +48 -0
  142. package/dist/targets/python/templates/models/partials/docstring.liquid +5 -0
  143. package/dist/targets/python/templates/models/partials/enum_class.liquid +11 -0
  144. package/dist/targets/python/templates/models/partials/field_line.liquid +5 -0
  145. package/dist/targets/python/templates/models/partials/model_class.liquid +17 -0
  146. package/dist/targets/typescript/compatibility-naming.d.ts +6 -0
  147. package/dist/targets/typescript/compatibility-naming.js +28 -0
  148. package/dist/targets/typescript/compatibility-options.d.ts +5 -0
  149. package/dist/targets/typescript/compatibility-options.js +8 -0
  150. package/dist/targets/typescript/compatibility-target.d.ts +5 -0
  151. package/dist/targets/typescript/compatibility-target.js +10 -0
  152. package/dist/targets/typescript/http-operations.d.ts +34 -0
  153. package/dist/targets/typescript/http-operations.js +155 -0
  154. package/dist/targets/typescript/imports.d.ts +43 -0
  155. package/dist/targets/typescript/imports.js +154 -0
  156. package/dist/targets/typescript/index.d.ts +7 -0
  157. package/dist/targets/typescript/index.js +52 -0
  158. package/dist/targets/typescript/mock-compatibility.d.ts +4 -0
  159. package/dist/targets/typescript/mock-compatibility.js +6 -0
  160. package/dist/targets/typescript/mock-hints.d.ts +13 -0
  161. package/dist/targets/typescript/mock-hints.js +75 -0
  162. package/dist/targets/typescript/mock-reachability.d.ts +12 -0
  163. package/dist/targets/typescript/mock-reachability.js +87 -0
  164. package/dist/targets/typescript/model-compatibility.d.ts +14 -0
  165. package/dist/targets/typescript/model-compatibility.js +16 -0
  166. package/dist/targets/typescript/naming.d.ts +13 -0
  167. package/dist/targets/typescript/naming.js +50 -0
  168. package/dist/targets/typescript/options.d.ts +124 -0
  169. package/dist/targets/typescript/options.js +90 -0
  170. package/dist/targets/typescript/outputs/client.d.ts +67 -0
  171. package/dist/targets/typescript/outputs/client.js +187 -0
  172. package/dist/targets/typescript/outputs/mocks.d.ts +32 -0
  173. package/dist/targets/typescript/outputs/mocks.js +371 -0
  174. package/dist/targets/typescript/outputs/models.d.ts +85 -0
  175. package/dist/targets/typescript/outputs/models.js +246 -0
  176. package/dist/targets/typescript/outputs/rtk-query.d.ts +69 -0
  177. package/dist/targets/typescript/outputs/rtk-query.js +266 -0
  178. package/dist/targets/typescript/prettier.d.ts +7 -0
  179. package/dist/targets/typescript/prettier.js +44 -0
  180. package/dist/targets/typescript/templates/client/client.liquid +30 -0
  181. package/dist/targets/typescript/templates/client/partials/api-member.liquid +13 -0
  182. package/dist/targets/typescript/templates/client/partials/jsdoc.liquid +10 -0
  183. package/dist/targets/typescript/templates/client/partials/method.liquid +26 -0
  184. package/dist/targets/typescript/templates/client/partials/query-type.liquid +10 -0
  185. package/dist/targets/typescript/templates/client/resource.liquid +34 -0
  186. package/dist/targets/typescript/templates/mocks/mock.liquid +15 -0
  187. package/dist/targets/typescript/templates/mocks/partials/factory.liquid +12 -0
  188. package/dist/targets/typescript/templates/mocks/partials/imports.liquid +7 -0
  189. package/dist/targets/typescript/templates/models/alias.liquid +16 -0
  190. package/dist/targets/typescript/templates/models/enum.liquid +27 -0
  191. package/dist/targets/typescript/templates/models/index.liquid +14 -0
  192. package/dist/targets/typescript/templates/models/model.liquid +25 -0
  193. package/dist/targets/typescript/templates/models/partials/const.liquid +10 -0
  194. package/dist/targets/typescript/templates/models/partials/imports.liquid +9 -0
  195. package/dist/targets/typescript/templates/models/partials/jsdoc.liquid +9 -0
  196. package/dist/targets/typescript/templates/models/partials/property.liquid +7 -0
  197. package/dist/targets/typescript/templates/rtk-query/api.liquid +16 -0
  198. package/dist/targets/typescript/templates/rtk-query/partials/arg-types.liquid +6 -0
  199. package/dist/targets/typescript/templates/rtk-query/partials/endpoint-mutation.liquid +13 -0
  200. package/dist/targets/typescript/templates/rtk-query/partials/endpoint-query.liquid +13 -0
  201. package/dist/targets/typescript/templates/rtk-query/partials/file-warning.liquid +7 -0
  202. package/dist/targets/typescript/templates/rtk-query/partials/hooks.liquid +9 -0
  203. package/dist/targets/typescript/templates/rtk-query/partials/imports.liquid +7 -0
  204. package/dist/targets/typescript/templates/rtk-query/partials/request-config.liquid +9 -0
  205. package/dist/targets/typescript/templates/rtk-query/resource.liquid +40 -0
  206. package/dist/targets/typescript/ts-type.d.ts +70 -0
  207. package/dist/targets/typescript/ts-type.js +62 -0
  208. package/dist/targets/typescript/type-printer.d.ts +21 -0
  209. package/dist/targets/typescript/type-printer.js +115 -0
  210. package/dist/templates/engine.d.ts +20 -0
  211. package/dist/templates/engine.js +161 -0
  212. package/dist/templates/inspect.d.ts +27 -0
  213. package/dist/templates/inspect.js +331 -0
  214. package/package.json +65 -4
  215. package/schema/sdk-gen.local.schema.json +75 -0
  216. package/schema/sdk-gen.schema.json +980 -0
  217. package/schema/sdk-gen.target.schema.json +1384 -0
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalConfigSchema = exports.UserConfigSchema = void 0;
4
+ exports.formatConfigError = formatConfigError;
5
+ exports.parseUserConfig = parseUserConfig;
6
+ exports.defineConfig = defineConfig;
7
+ exports.parseLocalConfig = parseLocalConfig;
8
+ const all_of_1 = require("../spec/openapi/all-of");
9
+ const zod_1 = require("zod");
10
+ const presets_1 = require("./presets");
11
+ const modes_1 = require("./modes");
12
+ const freeformRecord = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
13
+ const optionsMap = zod_1.z.record(zod_1.z.string(), zod_1.z.union([zod_1.z.literal(false), freeformRecord]));
14
+ const transformsMap = zod_1.z.record(zod_1.z.string(), zod_1.z.union([zod_1.z.boolean(), freeformRecord]));
15
+ const sourceSettingsSchema = zod_1.z
16
+ .object({
17
+ normalize: zod_1.z.object({ allOf: zod_1.z.enum(all_of_1.ALLOF_MODES).optional() }).strict().optional(),
18
+ transforms: transformsMap.optional(),
19
+ outputs: optionsMap.optional(),
20
+ })
21
+ .strict();
22
+ const headerValueSchema = zod_1.z.union([
23
+ zod_1.z.string(),
24
+ zod_1.z
25
+ .object({
26
+ value: zod_1.z.string(),
27
+ when: zod_1.z.string().describe('Interpolated; the header is sent only when this is non-empty (e.g. "${ADMIN_JWT:-}").'),
28
+ })
29
+ .strict(),
30
+ ]);
31
+ const headersSchema = zod_1.z.record(zod_1.z.string(), headerValueSchema);
32
+ const sourceSchema = sourceSettingsSchema
33
+ .extend({
34
+ name: zod_1.z.string().regex(/^[A-Za-z0-9._-]+$/, 'Source name may only contain letters, numbers, dots, underscores, and dashes'),
35
+ url: zod_1.z.string().optional(),
36
+ file: zod_1.z.string().optional(),
37
+ headers: headersSchema.optional(),
38
+ skip: zod_1.z
39
+ .string()
40
+ .optional()
41
+ .describe('Interpolated; non-empty → this source is skipped this run (e.g. "${OFFLINE_SPEC:-}").'),
42
+ onError: zod_1.z
43
+ .string()
44
+ .min(1)
45
+ .optional()
46
+ .describe('Makes the source non-fatal: when it fails (fetch, HTTP status, parse, generation) this warning is logged (`{error}` = the error message), nothing of it is written or pruned, and the run continues and succeeds without it.'),
47
+ })
48
+ .strict();
49
+ const workspaceRuleSchema = zod_1.z
50
+ .object({
51
+ default: zod_1.z.string().optional().describe('Interpolated default workspace, e.g. "${ENV_URL:-}".'),
52
+ pattern: zod_1.z
53
+ .string()
54
+ .refine(isValidRegExp, { message: 'Invalid regular expression' })
55
+ .optional()
56
+ .describe('Regex applied to the default: when it matches, capture group 1 is the workspace.'),
57
+ prompt: zod_1.z.boolean().optional().describe('Ask on a TTY when nothing else (CLI, config, SDK_WORKSPACE) sets the workspace.'),
58
+ production: zod_1.z.string().optional().describe('The token that selects production (e.g. "-"), for -w and the prompt.'),
59
+ })
60
+ .strict();
61
+ const hostsSchema = zod_1.z
62
+ .object({
63
+ workspace: zod_1.z
64
+ .string()
65
+ .refine((host) => host.includes('{workspace}'), { message: 'hosts.workspace must contain {workspace}' })
66
+ .describe('Host for a workspace, e.g. "{workspace}.dev.example.com".'),
67
+ production: zod_1.z.string().describe('Host when production is selected, e.g. "example.com".'),
68
+ })
69
+ .strict()
70
+ .describe('Values of the {host} placeholder.');
71
+ exports.UserConfigSchema = zod_1.z
72
+ .object({
73
+ $schema: zod_1.z.string().optional(),
74
+ version: zod_1.z.literal(4),
75
+ mode: zod_1.z.enum(modes_1.GENERATION_MODES).optional().describe('TypeScript SDK mode. Default uses Redux Toolkit and future uses the configurable SDK runtime.'),
76
+ preset: zod_1.z
77
+ .string()
78
+ .refine((name) => (0, presets_1.getPreset)(name) !== undefined, {
79
+ message: `Unknown preset. Known presets: ${(0, presets_1.listPresets)().map((preset) => preset.name).join(', ')}`,
80
+ })
81
+ .optional(),
82
+ target: zod_1.z.string().optional(),
83
+ targetOptions: freeformRecord.optional(),
84
+ plugins: zod_1.z.array(zod_1.z.string()).optional(),
85
+ templates: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]).optional(),
86
+ workspace: zod_1.z.union([zod_1.z.string(), workspaceRuleSchema]).optional(),
87
+ hosts: hostsSchema.optional(),
88
+ envFile: zod_1.z
89
+ .union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())])
90
+ .optional()
91
+ .describe('dotenv files (relative to the config file) feeding ${VAR}; lowest precedence, missing files skipped.'),
92
+ env: zod_1.z
93
+ .record(zod_1.z.string(), zod_1.z.string())
94
+ .optional()
95
+ .describe('Values for ${VAR} interpolation; the real environment wins. Secrets belong in the gitignored local file.'),
96
+ prune: zod_1.z.boolean().optional(),
97
+ defaults: sourceSettingsSchema.optional(),
98
+ sources: zod_1.z.array(sourceSchema).min(1, 'At least one source is required').optional(),
99
+ })
100
+ .strict()
101
+ .superRefine((config, ctx) => {
102
+ var _a, _b;
103
+ var _c, _d;
104
+ const presetSources = (_c = (config.preset ? (_b = (_a = (0, presets_1.getPreset)(config.preset)) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.sources : undefined)) !== null && _c !== void 0 ? _c : [];
105
+ if (!config.sources && !presetSources.length) {
106
+ ctx.addIssue({
107
+ code: 'custom',
108
+ path: ['sources'],
109
+ message: config.preset
110
+ ? `"sources" is required: preset "${config.preset}" provides none`
111
+ : 'At least one source is required ("sources")',
112
+ });
113
+ }
114
+ const seen = new Set();
115
+ for (const [index, source] of ((_d = config.sources) !== null && _d !== void 0 ? _d : []).entries()) {
116
+ const inPreset = presetSources.some((p) => p.name === source.name);
117
+ if (!inPreset && source.url === undefined && source.file === undefined) {
118
+ ctx.addIssue({
119
+ code: 'custom',
120
+ path: ['sources', index],
121
+ message: 'Source must set "url" or "file" (both: the file wins when it interpolates to a non-empty path)',
122
+ });
123
+ }
124
+ if (seen.has(source.name)) {
125
+ ctx.addIssue({
126
+ code: 'custom',
127
+ path: ['sources', index, 'name'],
128
+ message: `Duplicate source name "${source.name}"`,
129
+ });
130
+ }
131
+ seen.add(source.name);
132
+ }
133
+ });
134
+ function isValidRegExp(pattern) {
135
+ try {
136
+ new RegExp(pattern);
137
+ return true;
138
+ }
139
+ catch (_a) {
140
+ return false;
141
+ }
142
+ }
143
+ function formatConfigError(error) {
144
+ return zod_1.z.prettifyError(error);
145
+ }
146
+ function parseUserConfig(raw) {
147
+ const result = exports.UserConfigSchema.safeParse(raw);
148
+ if (!result.success) {
149
+ throw new Error(formatConfigError(result.error));
150
+ }
151
+ return result.data;
152
+ }
153
+ function defineConfig(c) {
154
+ return c;
155
+ }
156
+ const localSourceSchema = zod_1.z
157
+ .object({
158
+ url: zod_1.z.string().optional(),
159
+ file: zod_1.z.string().optional().describe('Wins over url when it resolves non-empty; "" falls back to url.'),
160
+ headers: headersSchema.optional().describe('Merged over the config headers (string or { value, when }).'),
161
+ })
162
+ .strict();
163
+ exports.LocalConfigSchema = zod_1.z
164
+ .object({
165
+ $schema: zod_1.z.string().optional(),
166
+ workspace: zod_1.z.string().optional().describe('Your workspace for {workspace} (the -w flag still wins).'),
167
+ env: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional().describe('Secrets / values for ${VAR}; the real environment wins.'),
168
+ sources: zod_1.z.record(zod_1.z.string(), localSourceSchema).optional().describe('Overrides by source name.'),
169
+ })
170
+ .strict();
171
+ function parseLocalConfig(input) {
172
+ return exports.LocalConfigSchema.parse(input);
173
+ }
@@ -0,0 +1,42 @@
1
+ export interface ResolvedConfig {
2
+ cwd: string;
3
+ target: string;
4
+ targetOptions: Record<string, unknown>;
5
+ plugins: string[];
6
+ templates: string[];
7
+ prune: boolean;
8
+ sources: ResolvedSource[];
9
+ sourceNames?: string[];
10
+ skipped?: Array<{
11
+ name: string;
12
+ reason: string;
13
+ }>;
14
+ }
15
+ export type SpecInput = {
16
+ kind: 'url';
17
+ url: string;
18
+ headers: Record<string, string>;
19
+ } | {
20
+ kind: 'file';
21
+ path: string;
22
+ };
23
+ export interface ResolvedSource {
24
+ name: string;
25
+ input: SpecInput;
26
+ normalize: NormalizeOptions;
27
+ transforms: Array<{
28
+ name: string;
29
+ options: Record<string, unknown>;
30
+ }>;
31
+ configuredTransforms?: string[];
32
+ outputs: Record<string, ResolvedOutputOptions>;
33
+ onError?: string;
34
+ }
35
+ export interface NormalizeOptions {
36
+ allOf: 'merge' | 'intersection';
37
+ }
38
+ export interface ResolvedOutputOptions {
39
+ dir?: string;
40
+ format?: boolean;
41
+ [option: string]: unknown;
42
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,30 @@
1
+ import { type Env } from './interpolate';
2
+ import type { HostsConfig, WorkspaceRule } from './schema';
3
+ export type WorkspaceChoice = {
4
+ production: true;
5
+ } | {
6
+ production: false;
7
+ name: string;
8
+ };
9
+ export type AskFn = (question: string) => Promise<string>;
10
+ export interface WorkspaceInputs {
11
+ cli?: string;
12
+ configured?: string;
13
+ rule?: WorkspaceRule;
14
+ hosts?: HostsConfig;
15
+ envFile?: string | string[];
16
+ env: Env;
17
+ }
18
+ export declare const MAX_PROMPT_TRIES = 3;
19
+ export declare class WorkspacePromptNeeded extends Error {
20
+ readonly inputs: WorkspaceInputs;
21
+ constructor(inputs: WorkspaceInputs);
22
+ }
23
+ export declare function chooseWorkspace(inputs: WorkspaceInputs, opts?: {
24
+ promptable?: boolean;
25
+ prompted?: WorkspaceChoice;
26
+ }): WorkspaceChoice;
27
+ export declare function isOrigin(value: string): boolean;
28
+ export declare function stripTrailingSlashes(value: string): string;
29
+ export declare function ruleDefault(rule: WorkspaceRule, env: Env): string;
30
+ export declare function promptWorkspace(inputs: WorkspaceInputs, ask: AskFn): Promise<WorkspaceChoice>;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.WorkspacePromptNeeded = exports.MAX_PROMPT_TRIES = void 0;
13
+ exports.chooseWorkspace = chooseWorkspace;
14
+ exports.isOrigin = isOrigin;
15
+ exports.stripTrailingSlashes = stripTrailingSlashes;
16
+ exports.ruleDefault = ruleDefault;
17
+ exports.promptWorkspace = promptWorkspace;
18
+ const interpolate_1 = require("./interpolate");
19
+ exports.MAX_PROMPT_TRIES = 3;
20
+ class WorkspacePromptNeeded extends Error {
21
+ constructor(inputs) {
22
+ super('Workspace prompt needed');
23
+ this.inputs = inputs;
24
+ }
25
+ }
26
+ exports.WorkspacePromptNeeded = WorkspacePromptNeeded;
27
+ function chooseWorkspace(inputs, opts = {}) {
28
+ const explicit = [inputs.cli, inputs.configured, inputs.env.SDK_WORKSPACE].find((v) => v !== undefined && v !== '');
29
+ if (explicit !== undefined)
30
+ return fromToken(explicit, inputs);
31
+ const rule = inputs.rule;
32
+ if (rule) {
33
+ if (opts.prompted)
34
+ return opts.prompted;
35
+ if (rule.prompt && opts.promptable)
36
+ throw new WorkspacePromptNeeded(inputs);
37
+ const fallback = ruleDefault(rule, inputs.env);
38
+ if (fallback)
39
+ return fromToken(fallback, inputs);
40
+ }
41
+ throw new Error('Workspace could not be resolved: no workspace was provided. ' +
42
+ 'Set it via the --workspace <name> CLI option, "workspace" in your <config>.local.json (sdk-gen init --local), or the SDK_WORKSPACE environment variable.' +
43
+ ((rule === null || rule === void 0 ? void 0 : rule.prompt) ? ' (The workspace prompt only runs on an interactive terminal.)' : ''));
44
+ }
45
+ function fromToken(value, inputs) {
46
+ var _a;
47
+ const token = (_a = inputs.rule) === null || _a === void 0 ? void 0 : _a.production;
48
+ if ((token !== undefined && token !== '' && value === token) || (inputs.hosts && value === 'prod'))
49
+ return { production: true };
50
+ return { production: false, name: value };
51
+ }
52
+ function isOrigin(value) {
53
+ return /^https?:\/\//i.test(value);
54
+ }
55
+ function stripTrailingSlashes(value) {
56
+ return value.replace(/\/+$/, '');
57
+ }
58
+ function ruleDefault(rule, env) {
59
+ const value = rule.default !== undefined ? (0, interpolate_1.interpolateEnv)(rule.default, env).trim() : '';
60
+ if (!value || !rule.pattern)
61
+ return value;
62
+ const match = new RegExp(rule.pattern).exec(value);
63
+ if ((match === null || match === void 0 ? void 0 : match[1]) !== undefined)
64
+ return match[1];
65
+ return isOrigin(value) ? stripTrailingSlashes(value) : value;
66
+ }
67
+ function promptWorkspace(inputs, ask) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ var _a;
70
+ const rule = (_a = inputs.rule) !== null && _a !== void 0 ? _a : {};
71
+ const fallback = ruleDefault(rule, inputs.env);
72
+ const question = promptQuestion(rule, fallback, inputs);
73
+ for (let attempt = 0; attempt < exports.MAX_PROMPT_TRIES; attempt++) {
74
+ const answer = (yield ask(question)).trim();
75
+ if (answer)
76
+ return fromToken(answer, inputs);
77
+ if (fallback)
78
+ return fromToken(fallback, inputs);
79
+ }
80
+ throw new Error(`No workspace given (${exports.MAX_PROMPT_TRIES} empty answers). Pass -w <workspace> or set "workspace" in your <config>.local.json.`);
81
+ });
82
+ }
83
+ function promptQuestion(rule, fallback, inputs) {
84
+ var _a;
85
+ var _b;
86
+ const example = fallback && fallback !== rule.production && !isOrigin(fallback) ? fallback : 'akt';
87
+ const eg = inputs.hosts ? ` eg ${example} for ${inputs.hosts.workspace.split('{workspace}').join(example)}` : '';
88
+ const files = inputs.envFile === undefined ? [] : Array.isArray(inputs.envFile) ? inputs.envFile : [inputs.envFile];
89
+ const hints = [];
90
+ if (fallback)
91
+ hints.push(`default: ${fallback}${files.length ? ` — from ${files.join(', ')}` : ''}`);
92
+ if (rule.production)
93
+ hints.push(`type "${rule.production}" for ${(_b = (_a = inputs.hosts) === null || _a === void 0 ? void 0 : _a.production) !== null && _b !== void 0 ? _b : 'production'}`);
94
+ return `What is your workspace?${eg}\n${hints.length ? `(${hints.join(' / ')})\n` : ''}> `;
95
+ }
@@ -0,0 +1,5 @@
1
+ export declare class CaseAligner {
2
+ private readonly listings;
3
+ align(root: string, relPath: string): Promise<void>;
4
+ private list;
5
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.CaseAligner = void 0;
46
+ const fs = __importStar(require("fs-extra"));
47
+ const path = __importStar(require("path"));
48
+ class CaseAligner {
49
+ constructor() {
50
+ this.listings = new Map();
51
+ }
52
+ align(root, relPath) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ let dir = root;
55
+ for (const segment of relPath.split('/')) {
56
+ const entries = yield this.list(dir);
57
+ const actual = entries.find((e) => e !== segment && e.toLowerCase() === segment.toLowerCase());
58
+ if (actual && (yield sameEntry(path.join(dir, actual), path.join(dir, segment)))) {
59
+ const tmp = path.join(dir, `${segment}.case-${process.pid}`);
60
+ yield fs.rename(path.join(dir, actual), tmp);
61
+ yield fs.rename(tmp, path.join(dir, segment));
62
+ this.listings.set(dir, entries.map((e) => (e === actual ? segment : e)));
63
+ }
64
+ dir = path.join(dir, segment);
65
+ }
66
+ });
67
+ }
68
+ list(dir) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ let entries = this.listings.get(dir);
71
+ if (!entries) {
72
+ entries = yield fs.readdir(dir).catch(() => []);
73
+ this.listings.set(dir, entries);
74
+ }
75
+ return entries;
76
+ });
77
+ }
78
+ }
79
+ exports.CaseAligner = CaseAligner;
80
+ function sameEntry(a, b) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ try {
83
+ const [sa, sb] = yield Promise.all([fs.stat(a), fs.stat(b)]);
84
+ return sa.ino === sb.ino && sa.dev === sb.dev;
85
+ }
86
+ catch (_a) {
87
+ return false;
88
+ }
89
+ });
90
+ }
@@ -0,0 +1,2 @@
1
+ export declare function deepMerge<T extends object>(base: T, ...overrides: Array<Partial<T> | Record<string, unknown> | undefined>): T;
2
+ export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deepMerge = deepMerge;
4
+ exports.isPlainObject = isPlainObject;
5
+ function deepMerge(base, ...overrides) {
6
+ let result = Object.assign({}, base);
7
+ for (const override of overrides) {
8
+ if (!override)
9
+ continue;
10
+ for (const [key, value] of Object.entries(override)) {
11
+ if (value === undefined)
12
+ continue;
13
+ const current = result[key];
14
+ result[key] = isPlainObject(current) && isPlainObject(value) ? deepMerge(current, value) : value;
15
+ }
16
+ }
17
+ return result;
18
+ }
19
+ function isPlainObject(value) {
20
+ return typeof value === 'object' && value !== null && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
21
+ }
@@ -0,0 +1,10 @@
1
+ import type { EmittedFile } from './plugin';
2
+ export declare class FileSet {
3
+ private readonly owner;
4
+ private readonly files;
5
+ constructor(owner: string);
6
+ add(file: EmittedFile): void;
7
+ get size(): number;
8
+ list(): EmittedFile[];
9
+ }
10
+ export declare function normalizeRelativePath(p: string): string;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileSet = void 0;
4
+ exports.normalizeRelativePath = normalizeRelativePath;
5
+ class FileSet {
6
+ constructor(owner) {
7
+ this.owner = owner;
8
+ this.files = new Map();
9
+ }
10
+ add(file) {
11
+ const normalized = normalizeRelativePath(file.path);
12
+ if (this.files.has(normalized)) {
13
+ throw new Error(`[${this.owner}] file emitted twice: ${normalized}`);
14
+ }
15
+ this.files.set(normalized, Object.assign(Object.assign({}, file), { path: normalized }));
16
+ }
17
+ get size() {
18
+ return this.files.size;
19
+ }
20
+ list() {
21
+ return Array.from(this.files.values());
22
+ }
23
+ }
24
+ exports.FileSet = FileSet;
25
+ function normalizeRelativePath(p) {
26
+ const posix = p.replace(/\\/g, '/').replace(/^\.\//, '');
27
+ if (posix.startsWith('/') || posix.split('/').includes('..')) {
28
+ throw new Error(`Emitted path must stay inside the output dir: ${p}`);
29
+ }
30
+ return posix;
31
+ }
@@ -0,0 +1 @@
1
+ export declare function importModule(absPath: string): Promise<unknown>;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.importModule = importModule;
46
+ const url_1 = require("url");
47
+ function importModule(absPath) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const specifier = (0, url_1.pathToFileURL)(absPath).href;
50
+ const importer = new Function('s', 'return import(s)');
51
+ try {
52
+ return yield importer(specifier);
53
+ }
54
+ catch (error) {
55
+ if ((error === null || error === void 0 ? void 0 : error.code) === 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING') {
56
+ return Promise.resolve(`${specifier}`).then(s => __importStar(require(s)));
57
+ }
58
+ throw error;
59
+ }
60
+ });
61
+ }
@@ -0,0 +1,9 @@
1
+ export interface Logger {
2
+ info(message: string): void;
3
+ warn(message: string): void;
4
+ error(message: string): void;
5
+ debug(scope: string, message: string, data?: unknown): void;
6
+ }
7
+ export type LogLevel = 'silent' | 'error' | 'warn' | 'info';
8
+ export declare function createLogger(level?: LogLevel): Logger;
9
+ export declare const silentLogger: Logger;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.silentLogger = void 0;
4
+ exports.createLogger = createLogger;
5
+ const RANK = { silent: 0, error: 1, warn: 2, info: 3 };
6
+ function createLogger(level = 'info') {
7
+ var _a;
8
+ const enabled = (l) => RANK[level] >= RANK[l];
9
+ const debugScopes = ((_a = process.env.SDK_GEN_DEBUG) !== null && _a !== void 0 ? _a : '').split(',').map((s) => s.trim()).filter(Boolean);
10
+ const debugOn = (scope) => debugScopes.length > 0 && (debugScopes.includes('*') || debugScopes.includes('1') || debugScopes.includes(scope));
11
+ return {
12
+ info: (m) => enabled('info') && console.log(m),
13
+ warn: (m) => enabled('warn') && console.warn(m),
14
+ error: (m) => enabled('error') && console.error(m),
15
+ debug: (scope, m, data) => {
16
+ if (!debugOn(scope))
17
+ return;
18
+ console.log(`[debug:${scope}] ${m}`);
19
+ if (data !== undefined)
20
+ console.dir(data, { depth: 4 });
21
+ },
22
+ };
23
+ }
24
+ exports.silentLogger = createLogger('silent');
@@ -0,0 +1,17 @@
1
+ export declare const MANIFEST_FILENAME = ".sdk-gen-manifest.json";
2
+ export interface OutputManifest {
3
+ version: string;
4
+ files: string[];
5
+ bySource?: Record<string, string[]>;
6
+ }
7
+ export interface PruneResult {
8
+ deletedFiles: string[];
9
+ deletedDirs: string[];
10
+ }
11
+ export declare function readManifest(outputDir: string): Promise<OutputManifest | null>;
12
+ export declare function writeManifest(outputDir: string, relativeFiles: string[]): Promise<void>;
13
+ export declare function pruneOrphans(outputDir: string, newRelativeFiles: string[], options?: {
14
+ noPrune?: boolean;
15
+ sourceKey?: string;
16
+ isAliasKey?: (key: string) => boolean;
17
+ }): Promise<PruneResult>;