@sohcah/openapi-generator 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-51aI8Tpl.js +33 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +27 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +6 -0
- package/dist/config.js.map +1 -0
- package/dist/generators/index.d.ts +103 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +495 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/helpers-ChEkrLHV.js +14145 -0
- package/dist/helpers-ChEkrLHV.js.map +1 -0
- package/dist/index-COF3JXv1.d.ts +26 -0
- package/dist/index-COF3JXv1.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/src-UQLWBWmZ.js +167 -0
- package/dist/src-UQLWBWmZ.js.map +1 -0
- package/dist/types-7ABKlnLu.d.ts +66 -0
- package/dist/types-7ABKlnLu.d.ts.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
import { __toESM } from "../chunk-51aI8Tpl.js";
|
|
2
|
+
import { DocumentContext, NotImplementedError, ensureImport, ensureNamespaceImport, getKey, helpers_exports, require_lib } from "../helpers-ChEkrLHV.js";
|
|
3
|
+
import { Effect } from "effect";
|
|
4
|
+
|
|
5
|
+
//#region src/generators/schema.ts
|
|
6
|
+
var import_lib$3 = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
7
|
+
const equivalentType = (type) => ({
|
|
8
|
+
typeDecoded: type,
|
|
9
|
+
typeEncoded: type
|
|
10
|
+
});
|
|
11
|
+
function defaultParseJson(options) {
|
|
12
|
+
return (expression) => options.transformer({
|
|
13
|
+
encoded: options.schema.string,
|
|
14
|
+
decoded: expression,
|
|
15
|
+
decode: import_lib$3.blockStatement([import_lib$3.tryStatement(import_lib$3.blockStatement([import_lib$3.returnStatement(import_lib$3.callExpression(import_lib$3.memberExpression(import_lib$3.identifier("JSON"), import_lib$3.identifier("parse")), [import_lib$3.identifier("from")]))]), import_lib$3.catchClause(Object.assign(import_lib$3.identifier("error"), { typeAnnotation: import_lib$3.tsTypeAnnotation(import_lib$3.tsUnknownKeyword()) }), options.transformerCatch(import_lib$3.identifier("error"))))]),
|
|
16
|
+
encode: import_lib$3.callExpression(import_lib$3.memberExpression(import_lib$3.identifier("JSON"), import_lib$3.identifier("stringify")), [import_lib$3.identifier("from")])
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function createSchemaGenerator(options) {
|
|
20
|
+
const ensureStandardParametersSchema = Effect.fn(function* () {
|
|
21
|
+
const ctx = yield* DocumentContext;
|
|
22
|
+
if (!ctx.schemas.has("ParametersSchema")) ctx.schemas.set("ParametersSchema", [import_lib$3.exportNamedDeclaration(import_lib$3.variableDeclaration("const", [import_lib$3.variableDeclarator(import_lib$3.identifier("ParametersSchema"), import_lib$3.callExpression(options.schema.object, [import_lib$3.objectExpression([
|
|
23
|
+
import_lib$3.objectProperty(import_lib$3.identifier("query"), options.modifiers.optional(import_lib$3.callExpression(options.schema.instanceOf, [import_lib$3.identifier("URLSearchParams")]))),
|
|
24
|
+
import_lib$3.objectProperty(import_lib$3.identifier("headers"), options.modifiers.optional(import_lib$3.callExpression(options.schema.instanceOf, [import_lib$3.identifier("Headers")]))),
|
|
25
|
+
import_lib$3.objectProperty(import_lib$3.identifier("path"), options.modifiers.optional(options.schema.record(options.schema.string, options.schema.string))),
|
|
26
|
+
import_lib$3.objectProperty(import_lib$3.identifier("body"), options.modifiers.optional(options.schema.union([options.schema.string, import_lib$3.callExpression(options.schema.instanceOf, [import_lib$3.identifier("Blob")])])))
|
|
27
|
+
])]))]))]);
|
|
28
|
+
return import_lib$3.identifier("ParametersSchema");
|
|
29
|
+
});
|
|
30
|
+
const getBaseEffectSchema = Effect.fn(function* (schema) {
|
|
31
|
+
const ctx = yield* DocumentContext;
|
|
32
|
+
const typeMeta = {};
|
|
33
|
+
if ("$ref" in schema) {
|
|
34
|
+
const ref = schema.$ref;
|
|
35
|
+
if (!ref.startsWith("#/components/schemas/")) return yield* new NotImplementedError({ message: `$ref ${ref}` });
|
|
36
|
+
const schemaName = ref.slice(21);
|
|
37
|
+
const schemaKey = yield* getKey(schemaName);
|
|
38
|
+
const resolvedSchema = ctx.document.components?.schemas?.[schemaName];
|
|
39
|
+
if (!resolvedSchema) return yield* new NotImplementedError({ message: `Missing $ref ${ref}` });
|
|
40
|
+
if (ctx.processingSchemas.has(schemaName)) {
|
|
41
|
+
const fn = import_lib$3.arrowFunctionExpression([], import_lib$3.identifier(schemaKey.upper));
|
|
42
|
+
if (ctx.processingSchemaTypes.has(schemaName)) return {
|
|
43
|
+
expression: import_lib$3.nullLiteral(),
|
|
44
|
+
typeDecoded: import_lib$3.tsTypeReference(options.types.typeDecoded, import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsTypeQuery(import_lib$3.identifier(schemaKey.upper))])),
|
|
45
|
+
typeEncoded: import_lib$3.tsTypeReference(options.types.typeEncoded, import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsTypeQuery(import_lib$3.identifier(schemaKey.upper))])),
|
|
46
|
+
typeMeta
|
|
47
|
+
};
|
|
48
|
+
ctx.processingSchemaTypes.add(schemaName);
|
|
49
|
+
const typeSchema = yield* ensureSchema(resolvedSchema);
|
|
50
|
+
fn.returnType = import_lib$3.tsTypeAnnotation(import_lib$3.tsTypeReference(options.types.schema, import_lib$3.tsTypeParameterInstantiation([typeSchema.typeDecoded, typeSchema.typeEncoded])));
|
|
51
|
+
ctx.processingSchemaTypes.delete(schemaName);
|
|
52
|
+
return {
|
|
53
|
+
expression: options.modifiers.lazy(fn),
|
|
54
|
+
typeDecoded: import_lib$3.tsTypeReference(options.types.typeDecoded, import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsTypeQuery(import_lib$3.identifier(schemaKey.upper))])),
|
|
55
|
+
typeEncoded: import_lib$3.tsTypeReference(options.types.typeEncoded, import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsTypeQuery(import_lib$3.identifier(schemaKey.upper))])),
|
|
56
|
+
typeMeta
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (!ctx.schemas.has(schemaName)) {
|
|
60
|
+
ctx.processingSchemas.add(schemaName);
|
|
61
|
+
const schemaExpression = yield* ensureSchema(resolvedSchema);
|
|
62
|
+
const schemaKeyIdentifier = import_lib$3.identifier(schemaKey.upper);
|
|
63
|
+
if (options.experimental_includeTypes) schemaKeyIdentifier.typeAnnotation = import_lib$3.tsTypeAnnotation(import_lib$3.tsTypeReference(options.types.schema, import_lib$3.tsTypeParameterInstantiation([schemaExpression.typeDecoded, schemaExpression.typeEncoded])));
|
|
64
|
+
ctx.schemas.set(schemaName, [import_lib$3.exportNamedDeclaration(import_lib$3.variableDeclaration("const", [import_lib$3.variableDeclarator(schemaKeyIdentifier, schemaExpression.expression)])), import_lib$3.exportNamedDeclaration(import_lib$3.tsTypeAliasDeclaration(import_lib$3.identifier(schemaKey.upper), null, import_lib$3.tsTypeReference(options.types.typeDecoded, import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsTypeQuery(import_lib$3.identifier(schemaKey.upper))]))))]);
|
|
65
|
+
ctx.processingSchemas.delete(schemaName);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
expression: import_lib$3.identifier(schemaKey.upper),
|
|
69
|
+
typeDecoded: import_lib$3.tsTypeReference(options.types.typeDecoded, import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsTypeQuery(import_lib$3.identifier(schemaKey.upper))])),
|
|
70
|
+
typeEncoded: import_lib$3.tsTypeReference(options.types.typeEncoded, import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsTypeQuery(import_lib$3.identifier(schemaKey.upper))])),
|
|
71
|
+
typeMeta
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (schema.deprecated) if (options.deprecationHandling === "optional") typeMeta.optional = true;
|
|
75
|
+
else return {
|
|
76
|
+
expression: options.modifiers.optional(options.schema.unknown),
|
|
77
|
+
...equivalentType(import_lib$3.tsUnionType([import_lib$3.tsUnknownKeyword(), import_lib$3.tsUndefinedKeyword()])),
|
|
78
|
+
typeMeta
|
|
79
|
+
};
|
|
80
|
+
const customResult = options.custom?.(schema);
|
|
81
|
+
if (customResult) {
|
|
82
|
+
const identifier = yield* ensureImport(customResult.name, customResult.from);
|
|
83
|
+
const returnType = import_lib$3.tsTypeReference(import_lib$3.identifier("ReturnType"), import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsTypeQuery(identifier)]));
|
|
84
|
+
return {
|
|
85
|
+
expression: import_lib$3.callExpression(identifier, []),
|
|
86
|
+
typeDecoded: import_lib$3.tsTypeReference(options.types.typeDecoded, import_lib$3.tsTypeParameterInstantiation([returnType])),
|
|
87
|
+
typeEncoded: import_lib$3.tsTypeReference(options.types.typeEncoded, import_lib$3.tsTypeParameterInstantiation([returnType])),
|
|
88
|
+
typeMeta
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
if (schema.enum) {
|
|
92
|
+
const unsupportedEnumValue = schema.enum.find((i) => typeof i !== "string");
|
|
93
|
+
if (unsupportedEnumValue !== void 0) return yield* new NotImplementedError({ message: `Unsupported 'enum' value: ${JSON.stringify(unsupportedEnumValue)}` });
|
|
94
|
+
return {
|
|
95
|
+
expression: options.schema.enum(schema.enum.map((e) => import_lib$3.stringLiteral(e))),
|
|
96
|
+
...equivalentType(import_lib$3.tsUnionType(schema.enum.map((e) => import_lib$3.tsLiteralType(import_lib$3.stringLiteral(e))))),
|
|
97
|
+
typeMeta
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
switch (schema.type) {
|
|
101
|
+
case "boolean": return {
|
|
102
|
+
expression: options.schema.boolean,
|
|
103
|
+
...equivalentType(import_lib$3.tsBooleanKeyword()),
|
|
104
|
+
typeMeta
|
|
105
|
+
};
|
|
106
|
+
case "string": {
|
|
107
|
+
let expression = {
|
|
108
|
+
expression: options.schema.string,
|
|
109
|
+
...equivalentType(import_lib$3.tsStringKeyword()),
|
|
110
|
+
typeMeta
|
|
111
|
+
};
|
|
112
|
+
if (schema.pattern) expression.expression = options.modifiers.regex(expression.expression, schema.pattern);
|
|
113
|
+
return expression;
|
|
114
|
+
}
|
|
115
|
+
case "number": return {
|
|
116
|
+
expression: options.schema.number,
|
|
117
|
+
...equivalentType(import_lib$3.tsNumberKeyword()),
|
|
118
|
+
typeMeta
|
|
119
|
+
};
|
|
120
|
+
case "integer": return {
|
|
121
|
+
expression: options.schema.integer,
|
|
122
|
+
...equivalentType(import_lib$3.tsNumberKeyword()),
|
|
123
|
+
typeMeta
|
|
124
|
+
};
|
|
125
|
+
case "object": {
|
|
126
|
+
const object = import_lib$3.objectExpression([]);
|
|
127
|
+
const objectTypeDecoded = import_lib$3.tsTypeLiteral([]);
|
|
128
|
+
const objectTypeEncoded = import_lib$3.tsTypeLiteral([]);
|
|
129
|
+
for (const [propertyKey, property] of Object.entries(schema.properties ?? {})) {
|
|
130
|
+
let propertySchema = yield* ensureSchema(property);
|
|
131
|
+
const decodedMember = import_lib$3.tsPropertySignature(import_lib$3.identifier(propertyKey), import_lib$3.tsTypeAnnotation(propertySchema.typeDecoded));
|
|
132
|
+
const encodedMember = import_lib$3.tsPropertySignature(import_lib$3.identifier(propertyKey), import_lib$3.tsTypeAnnotation(propertySchema.typeEncoded));
|
|
133
|
+
decodedMember.readonly = !!propertySchema.typeMeta?.readonly;
|
|
134
|
+
encodedMember.readonly = !!propertySchema.typeMeta?.readonly;
|
|
135
|
+
if (propertySchema.typeMeta?.optional || !schema.required?.includes(propertyKey)) {
|
|
136
|
+
propertySchema.expression = options.modifiers.optional(propertySchema.expression);
|
|
137
|
+
decodedMember.optional = true;
|
|
138
|
+
encodedMember.optional = true;
|
|
139
|
+
}
|
|
140
|
+
const objectProperty = import_lib$3.objectProperty(import_lib$3.identifier(propertyKey), propertySchema.expression);
|
|
141
|
+
if (property.description) import_lib$3.addComment(objectProperty, "leading", `* ${property.description}`);
|
|
142
|
+
object.properties.push(objectProperty);
|
|
143
|
+
objectTypeDecoded.members.push(decodedMember);
|
|
144
|
+
objectTypeEncoded.members.push(encodedMember);
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
expression: import_lib$3.callExpression(options.schema.object, [object]),
|
|
148
|
+
typeDecoded: objectTypeDecoded,
|
|
149
|
+
typeEncoded: objectTypeEncoded,
|
|
150
|
+
typeMeta
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
case "array": {
|
|
154
|
+
const itemsSchema = yield* ensureSchema(schema.items);
|
|
155
|
+
let expression = import_lib$3.callExpression(options.schema.array, [itemsSchema.expression]);
|
|
156
|
+
let typeDecoded = import_lib$3.tsArrayType(itemsSchema.typeDecoded);
|
|
157
|
+
let typeEncoded = import_lib$3.tsArrayType(itemsSchema.typeEncoded);
|
|
158
|
+
if (options.supportsImmutability) if (itemsSchema.typeMeta?.readonly) {
|
|
159
|
+
expression = options.modifiers.immutable(expression);
|
|
160
|
+
typeDecoded = import_lib$3.tsTypeOperator(typeDecoded, "readonly");
|
|
161
|
+
typeEncoded = import_lib$3.tsTypeOperator(typeEncoded, "readonly");
|
|
162
|
+
} else expression = options.modifiers.mutable(expression);
|
|
163
|
+
return {
|
|
164
|
+
expression,
|
|
165
|
+
typeDecoded,
|
|
166
|
+
typeEncoded,
|
|
167
|
+
typeMeta
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
case "null": return {
|
|
171
|
+
expression: options.schema.null,
|
|
172
|
+
...equivalentType(import_lib$3.tsNullKeyword()),
|
|
173
|
+
typeMeta
|
|
174
|
+
};
|
|
175
|
+
case void 0: return {
|
|
176
|
+
expression: options.schema.unknown,
|
|
177
|
+
...equivalentType(import_lib$3.tsUnknownKeyword()),
|
|
178
|
+
typeMeta
|
|
179
|
+
};
|
|
180
|
+
default:
|
|
181
|
+
console.info(schema);
|
|
182
|
+
return yield* new NotImplementedError({ message: `type ${schema.type}` });
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
const applyModifiers = Effect.fn(function* (expression, schema) {
|
|
186
|
+
if ("$ref" in schema) return expression;
|
|
187
|
+
const modified = { ...expression };
|
|
188
|
+
if ("nullable" in schema && schema.nullable) {
|
|
189
|
+
modified.expression = options.modifiers.nullable(modified.expression);
|
|
190
|
+
modified.typeDecoded = import_lib$3.tsUnionType([modified.typeDecoded, import_lib$3.tsNullKeyword()]);
|
|
191
|
+
modified.typeEncoded = import_lib$3.tsUnionType([modified.typeEncoded, import_lib$3.tsNullKeyword()]);
|
|
192
|
+
}
|
|
193
|
+
if (options.supportsImmutability) if (schema.readOnly) {
|
|
194
|
+
modified.expression = options.modifiers.immutable(modified.expression);
|
|
195
|
+
modified.typeMeta ??= {};
|
|
196
|
+
modified.typeMeta.readonly = true;
|
|
197
|
+
} else modified.expression = options.modifiers.mutable(modified.expression);
|
|
198
|
+
return modified;
|
|
199
|
+
});
|
|
200
|
+
const ensureSchema = Effect.fn(function* (schema) {
|
|
201
|
+
let schemas = [schema].flatMap((schema$1) => {
|
|
202
|
+
if ("$ref" in schema$1) return [schema$1];
|
|
203
|
+
if (schema$1.oneOf) return schema$1.oneOf;
|
|
204
|
+
return [schema$1];
|
|
205
|
+
}).flatMap((schema$1) => {
|
|
206
|
+
if ("$ref" in schema$1) return [schema$1];
|
|
207
|
+
if (Array.isArray(schema$1.type)) return schema$1.type.map((type) => ({
|
|
208
|
+
...schema$1,
|
|
209
|
+
type
|
|
210
|
+
}));
|
|
211
|
+
return [schema$1];
|
|
212
|
+
});
|
|
213
|
+
const expressions = [];
|
|
214
|
+
for (const schema$1 of schemas) expressions.push(yield* applyModifiers(yield* getBaseEffectSchema(schema$1), schema$1));
|
|
215
|
+
if (expressions.length !== 1) return {
|
|
216
|
+
expression: options.schema.union(expressions.map((e) => e.expression)),
|
|
217
|
+
typeDecoded: import_lib$3.tsUnionType(expressions.map((e) => e.typeDecoded)),
|
|
218
|
+
typeEncoded: import_lib$3.tsUnionType(expressions.map((e) => e.typeEncoded)),
|
|
219
|
+
typeMeta: {}
|
|
220
|
+
};
|
|
221
|
+
return expressions[0];
|
|
222
|
+
});
|
|
223
|
+
const ensureParametersSchema = Effect.fn(function* (operationKey, method) {
|
|
224
|
+
const ctx = yield* DocumentContext;
|
|
225
|
+
const identifier = import_lib$3.identifier(`${operationKey.upper}_Parameters`);
|
|
226
|
+
const object = import_lib$3.objectExpression([]);
|
|
227
|
+
const queryArray = import_lib$3.arrayExpression([]);
|
|
228
|
+
const pathObject = import_lib$3.objectExpression([]);
|
|
229
|
+
const headerArray = import_lib$3.arrayExpression([]);
|
|
230
|
+
let hasBody = false;
|
|
231
|
+
for (const parameter of method.parameters ?? []) {
|
|
232
|
+
if ("$ref" in parameter) return yield* new NotImplementedError({ message: "$ref in parameter" });
|
|
233
|
+
if (!parameter.schema) return yield* new NotImplementedError({ message: "parameter without schema" });
|
|
234
|
+
let expression = (yield* ensureSchema(parameter.schema)).expression;
|
|
235
|
+
if (!parameter.required) expression = options.modifiers.optional(expression);
|
|
236
|
+
const objectProperty = import_lib$3.objectProperty(import_lib$3.identifier(parameter.name), expression);
|
|
237
|
+
if (parameter.description) import_lib$3.addComment(objectProperty, "leading", `* ${parameter.description}`);
|
|
238
|
+
object.properties.push(objectProperty);
|
|
239
|
+
if (parameter.in === "query") {
|
|
240
|
+
const param = import_lib$3.memberExpression(import_lib$3.identifier("from"), import_lib$3.identifier(parameter.name));
|
|
241
|
+
if ("type" in parameter.schema && parameter.schema.type === "array") queryArray.elements.push(import_lib$3.spreadElement(import_lib$3.logicalExpression("??", Object.assign(import_lib$3.optionalCallExpression(import_lib$3.optionalMemberExpression(param, import_lib$3.identifier("map"), false, true), [import_lib$3.arrowFunctionExpression([import_lib$3.identifier("value")], import_lib$3.arrayExpression([import_lib$3.stringLiteral(parameter.name), import_lib$3.callExpression(import_lib$3.identifier("String"), [import_lib$3.identifier("value")])]))], false), { typeParameters: import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsTypeReference(import_lib$3.identifier("[string, string]"))]) }), import_lib$3.arrayExpression([]))));
|
|
242
|
+
else queryArray.elements.push(import_lib$3.arrayExpression([import_lib$3.stringLiteral(parameter.name), import_lib$3.callExpression(import_lib$3.identifier("String"), [param])]));
|
|
243
|
+
} else if (parameter.in === "path") pathObject.properties.push(import_lib$3.objectProperty(import_lib$3.identifier(parameter.name), import_lib$3.callExpression(import_lib$3.identifier("String"), [import_lib$3.memberExpression(import_lib$3.identifier("from"), import_lib$3.identifier(parameter.name))])));
|
|
244
|
+
else if (parameter.in === "header") headerArray.elements.push(import_lib$3.arrayExpression([import_lib$3.stringLiteral(parameter.name), import_lib$3.callExpression(import_lib$3.identifier("String"), [import_lib$3.memberExpression(import_lib$3.identifier("from"), import_lib$3.identifier(parameter.name))])]));
|
|
245
|
+
else return yield* new NotImplementedError({ message: `parameter in ${parameter.in}` });
|
|
246
|
+
}
|
|
247
|
+
body: if (method.requestBody) {
|
|
248
|
+
if ("$ref" in method.requestBody) return yield* new NotImplementedError({ message: "$ref in requestBody" });
|
|
249
|
+
for (const contentKey in method.requestBody.content) {
|
|
250
|
+
hasBody = true;
|
|
251
|
+
const schema = method.requestBody.content[contentKey]?.schema;
|
|
252
|
+
if (!!schema && contentKey === "application/json") {
|
|
253
|
+
object.properties.push(import_lib$3.objectProperty(import_lib$3.identifier("data"), (options.builtins.parseJson ?? defaultParseJson(options))((yield* ensureSchema(schema)).expression)));
|
|
254
|
+
break body;
|
|
255
|
+
} else if (contentKey === "application/octet-stream") {
|
|
256
|
+
object.properties.push(import_lib$3.objectProperty(import_lib$3.identifier("data"), import_lib$3.callExpression(options.schema.instanceOf, [import_lib$3.identifier("Blob")])));
|
|
257
|
+
break body;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return yield* new NotImplementedError({ message: `No supported requestBody type (${Object.keys(method.requestBody.content).join(", ")})` });
|
|
261
|
+
}
|
|
262
|
+
const decodedSchema = import_lib$3.callExpression(options.schema.object, [object]);
|
|
263
|
+
const transform = options.transformer({
|
|
264
|
+
encoded: yield* ensureStandardParametersSchema(),
|
|
265
|
+
decoded: decodedSchema,
|
|
266
|
+
decode: import_lib$3.blockStatement([import_lib$3.throwStatement(import_lib$3.newExpression(import_lib$3.identifier("Error"), [import_lib$3.stringLiteral("Not implemented")]))]),
|
|
267
|
+
encode: import_lib$3.objectExpression([
|
|
268
|
+
...queryArray.elements.length ? [import_lib$3.objectProperty(import_lib$3.identifier("query"), import_lib$3.newExpression(import_lib$3.identifier("URLSearchParams"), [queryArray]))] : [],
|
|
269
|
+
...pathObject.properties.length ? [import_lib$3.objectProperty(import_lib$3.identifier("path"), pathObject)] : [],
|
|
270
|
+
...headerArray.elements.length ? [import_lib$3.objectProperty(import_lib$3.identifier("header"), import_lib$3.newExpression(import_lib$3.identifier("Headers"), [headerArray]))] : [],
|
|
271
|
+
...hasBody ? [import_lib$3.objectProperty(import_lib$3.identifier("body"), import_lib$3.memberExpression(import_lib$3.identifier("from"), import_lib$3.identifier("data")))] : []
|
|
272
|
+
])
|
|
273
|
+
});
|
|
274
|
+
ctx.schemas.set(identifier.name, [import_lib$3.exportNamedDeclaration(import_lib$3.variableDeclaration("const", [import_lib$3.variableDeclarator(identifier, transform)]))]);
|
|
275
|
+
return {
|
|
276
|
+
expression: identifier,
|
|
277
|
+
typeReference: import_lib$3.tsTypeReference(options.types.typeDecoded, import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsTypeQuery(identifier)]))
|
|
278
|
+
};
|
|
279
|
+
});
|
|
280
|
+
const ensureResponseSchema = Effect.fn(function* (operationKey, method) {
|
|
281
|
+
const ctx = yield* DocumentContext;
|
|
282
|
+
if (!method.responses?.["200"]) return null;
|
|
283
|
+
if ("$ref" in method.responses["200"]) return yield* new NotImplementedError({ message: "$ref in response" });
|
|
284
|
+
if (!method.responses["200"].content) return null;
|
|
285
|
+
if (!method.responses["200"].content["application/json"]?.schema) return yield* new NotImplementedError({ message: `response without 'application/json' content schema in ${operationKey.upper}` });
|
|
286
|
+
const schema = method.responses["200"].content["application/json"].schema;
|
|
287
|
+
const identifier = import_lib$3.identifier(`${operationKey.upper}_Response`);
|
|
288
|
+
const decodedSchema = (yield* ensureSchema(schema)).expression;
|
|
289
|
+
const transform = (options.builtins.parseJson ?? defaultParseJson(options))(decodedSchema);
|
|
290
|
+
ctx.schemas.set(identifier.name, [import_lib$3.exportNamedDeclaration(import_lib$3.variableDeclaration("const", [import_lib$3.variableDeclarator(identifier, transform)]))]);
|
|
291
|
+
return {
|
|
292
|
+
expression: identifier,
|
|
293
|
+
typeReference: import_lib$3.tsTypeReference(options.types.typeDecoded, import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsTypeQuery(identifier)]))
|
|
294
|
+
};
|
|
295
|
+
});
|
|
296
|
+
const processSchema = Effect.fn(function* (schema) {
|
|
297
|
+
if (options.includeSchemas ?? true) yield* ensureSchema(schema);
|
|
298
|
+
});
|
|
299
|
+
const processOperation = Effect.fn(function* (operationKey, _path, _method, operation) {
|
|
300
|
+
if (options.includeOperations) {
|
|
301
|
+
yield* ensureParametersSchema(operationKey, operation);
|
|
302
|
+
yield* ensureResponseSchema(operationKey, operation);
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
return {
|
|
306
|
+
processSchema,
|
|
307
|
+
processOperation,
|
|
308
|
+
ensureParametersSchema,
|
|
309
|
+
ensureResponseSchema,
|
|
310
|
+
get schemaType() {
|
|
311
|
+
return options.types.schema;
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
//#endregion
|
|
317
|
+
//#region src/generators/effect.ts
|
|
318
|
+
var import_lib$2 = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
319
|
+
const createEffectSchemaGenerator = (options) => ({
|
|
320
|
+
...createSchemaGenerator({
|
|
321
|
+
...options,
|
|
322
|
+
modifiers: {
|
|
323
|
+
lazy: (expression) => import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("suspend")), [expression]),
|
|
324
|
+
optional: (expression) => import_lib$2.callExpression(import_lib$2.memberExpression(expression, import_lib$2.identifier("pipe")), [import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("optional"))]),
|
|
325
|
+
regex: (expression, pattern) => import_lib$2.callExpression(import_lib$2.memberExpression(expression, import_lib$2.identifier("pipe")), [import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("pattern")), [import_lib$2.regExpLiteral(pattern)])]),
|
|
326
|
+
immutable: (expression) => expression,
|
|
327
|
+
mutable: (expression) => import_lib$2.callExpression(import_lib$2.memberExpression(expression, import_lib$2.identifier("pipe")), [import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("mutable"))]),
|
|
328
|
+
nullable: (expression) => import_lib$2.callExpression(import_lib$2.memberExpression(expression, import_lib$2.identifier("pipe")), [import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("NullOr"))])
|
|
329
|
+
},
|
|
330
|
+
types: {
|
|
331
|
+
schema: import_lib$2.tsQualifiedName(import_lib$2.identifier("Schema"), import_lib$2.identifier("Schema")),
|
|
332
|
+
typeDecoded: import_lib$2.tsQualifiedName(import_lib$2.tsQualifiedName(import_lib$2.identifier("Schema"), import_lib$2.identifier("Schema")), import_lib$2.identifier("Type")),
|
|
333
|
+
typeEncoded: import_lib$2.tsQualifiedName(import_lib$2.tsQualifiedName(import_lib$2.identifier("Schema"), import_lib$2.identifier("Schema")), import_lib$2.identifier("Encoded"))
|
|
334
|
+
},
|
|
335
|
+
schema: {
|
|
336
|
+
record: (key, value) => import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("Record")), [import_lib$2.objectExpression([import_lib$2.objectProperty(import_lib$2.identifier("key"), key), import_lib$2.objectProperty(import_lib$2.identifier("value"), value)])]),
|
|
337
|
+
union: (expressions) => import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("Union")), expressions),
|
|
338
|
+
enum: (expressions) => import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("Literal")), expressions),
|
|
339
|
+
instanceOf: import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("instanceOf")),
|
|
340
|
+
boolean: import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("Boolean")),
|
|
341
|
+
string: import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("String")),
|
|
342
|
+
number: import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("Number")),
|
|
343
|
+
integer: import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("Number")), import_lib$2.identifier("pipe")), [import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("int")), [])]),
|
|
344
|
+
array: import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("Array")),
|
|
345
|
+
object: import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("Struct")),
|
|
346
|
+
null: import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("Null")),
|
|
347
|
+
unknown: import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("Unknown"))
|
|
348
|
+
},
|
|
349
|
+
transformer: ({ encoded, decoded, decode, encode }) => import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("transform")), [
|
|
350
|
+
encoded,
|
|
351
|
+
decoded,
|
|
352
|
+
import_lib$2.objectExpression([
|
|
353
|
+
import_lib$2.objectProperty(import_lib$2.identifier("strict"), import_lib$2.booleanLiteral(true)),
|
|
354
|
+
import_lib$2.objectProperty(import_lib$2.identifier("decode"), import_lib$2.arrowFunctionExpression([import_lib$2.identifier("from"), import_lib$2.identifier("ctx")], decode)),
|
|
355
|
+
import_lib$2.objectProperty(import_lib$2.identifier("encode"), import_lib$2.arrowFunctionExpression([import_lib$2.identifier("from"), import_lib$2.identifier("ctx")], encode))
|
|
356
|
+
])
|
|
357
|
+
]),
|
|
358
|
+
transformerCatch: (expression) => import_lib$2.blockStatement([import_lib$2.throwStatement(expression)]),
|
|
359
|
+
builtins: { parseJson: (expression) => import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("parseJson")), [expression]) },
|
|
360
|
+
methods: {
|
|
361
|
+
encode: (schema, value) => import_lib$2.callExpression(import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("encodeSync")), [schema]), [value]),
|
|
362
|
+
decode: (schema, value) => import_lib$2.callExpression(import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("decodeSync")), [schema]), [value]),
|
|
363
|
+
parse: (schema, value) => import_lib$2.callExpression(import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("decodeUnknownSync")), [schema]), [value])
|
|
364
|
+
},
|
|
365
|
+
supportsImmutability: true
|
|
366
|
+
}),
|
|
367
|
+
initialize: Effect.fn(function* () {
|
|
368
|
+
yield* ensureNamespaceImport("Schema", "effect/Schema");
|
|
369
|
+
})
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
//#endregion
|
|
373
|
+
//#region src/generators/zod.ts
|
|
374
|
+
var import_lib$1 = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
375
|
+
const createZodSchemaGenerator = ({ mini = false,...options }) => {
|
|
376
|
+
const z = import_lib$1.identifier("z");
|
|
377
|
+
const maybeExtension = (expression, extension, args) => mini ? import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier(extension)), [expression, ...args]) : import_lib$1.callExpression(import_lib$1.memberExpression(expression, import_lib$1.identifier(extension)), args);
|
|
378
|
+
return {
|
|
379
|
+
...createSchemaGenerator({
|
|
380
|
+
...options,
|
|
381
|
+
modifiers: {
|
|
382
|
+
lazy: (expression) => import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("lazy")), [expression]),
|
|
383
|
+
optional: (expression) => maybeExtension(expression, "optional", []),
|
|
384
|
+
regex: (expression, pattern) => maybeExtension(expression, "regex", [import_lib$1.regExpLiteral(pattern)]),
|
|
385
|
+
immutable: (expression) => expression,
|
|
386
|
+
mutable: (expression) => expression,
|
|
387
|
+
nullable: (expression) => maybeExtension(expression, "nullable", [])
|
|
388
|
+
},
|
|
389
|
+
types: {
|
|
390
|
+
schema: import_lib$1.tsQualifiedName(z, import_lib$1.identifier(mini ? "ZodMiniType" : "Schema")),
|
|
391
|
+
typeDecoded: import_lib$1.tsQualifiedName(z, import_lib$1.identifier("output")),
|
|
392
|
+
typeEncoded: import_lib$1.tsQualifiedName(z, import_lib$1.identifier("input"))
|
|
393
|
+
},
|
|
394
|
+
schema: {
|
|
395
|
+
record: (key, value) => import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("record")), [key, value]),
|
|
396
|
+
union: (expressions) => import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("union")), [import_lib$1.arrayExpression(expressions)]),
|
|
397
|
+
enum: (expressions) => import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("enum")), [import_lib$1.arrayExpression(expressions)]),
|
|
398
|
+
instanceOf: import_lib$1.memberExpression(z, import_lib$1.identifier("instanceof")),
|
|
399
|
+
boolean: import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("boolean")), []),
|
|
400
|
+
string: import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("string")), []),
|
|
401
|
+
number: import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("number")), []),
|
|
402
|
+
integer: import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("int")), []),
|
|
403
|
+
array: import_lib$1.memberExpression(z, import_lib$1.identifier("array")),
|
|
404
|
+
object: import_lib$1.memberExpression(z, import_lib$1.identifier("object")),
|
|
405
|
+
null: import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("null")), []),
|
|
406
|
+
unknown: import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("unknown")), [])
|
|
407
|
+
},
|
|
408
|
+
transformer: ({ encoded, decoded, decode, encode }) => import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("codec")), [
|
|
409
|
+
encoded,
|
|
410
|
+
decoded,
|
|
411
|
+
import_lib$1.objectExpression([import_lib$1.objectProperty(import_lib$1.identifier("decode"), import_lib$1.arrowFunctionExpression([import_lib$1.identifier("from"), import_lib$1.identifier("ctx")], decode)), import_lib$1.objectProperty(import_lib$1.identifier("encode"), import_lib$1.arrowFunctionExpression([import_lib$1.identifier("from"), import_lib$1.identifier("ctx")], encode))])
|
|
412
|
+
]),
|
|
413
|
+
transformerCatch: (expression) => import_lib$1.blockStatement([import_lib$1.expressionStatement(import_lib$1.callExpression(import_lib$1.memberExpression(import_lib$1.memberExpression(import_lib$1.identifier("ctx"), import_lib$1.identifier("issues")), import_lib$1.identifier("push")), [import_lib$1.objectExpression([
|
|
414
|
+
import_lib$1.objectProperty(import_lib$1.identifier("code"), import_lib$1.stringLiteral("custom")),
|
|
415
|
+
import_lib$1.objectProperty(import_lib$1.identifier("input"), import_lib$1.identifier("from")),
|
|
416
|
+
import_lib$1.objectProperty(import_lib$1.identifier("message"), import_lib$1.memberExpression(import_lib$1.tsAsExpression(expression, import_lib$1.tsTypeReference(import_lib$1.identifier("Error"))), import_lib$1.identifier("message")))
|
|
417
|
+
])])), import_lib$1.returnStatement(import_lib$1.memberExpression(import_lib$1.identifier("z"), import_lib$1.identifier("NEVER")))]),
|
|
418
|
+
builtins: {},
|
|
419
|
+
methods: {
|
|
420
|
+
encode: (schema, value) => import_lib$1.callExpression(import_lib$1.memberExpression(import_lib$1.identifier("z"), import_lib$1.identifier("encode")), [schema, value]),
|
|
421
|
+
decode: (schema, value) => import_lib$1.callExpression(import_lib$1.memberExpression(import_lib$1.identifier("z"), import_lib$1.identifier("decode")), [schema, value]),
|
|
422
|
+
parse: (schema, value) => import_lib$1.callExpression(import_lib$1.memberExpression(import_lib$1.identifier("z"), import_lib$1.identifier("parse")), [schema, value])
|
|
423
|
+
},
|
|
424
|
+
supportsImmutability: false
|
|
425
|
+
}),
|
|
426
|
+
initialize: Effect.fn(function* () {
|
|
427
|
+
yield* ensureImport("z", mini ? "zod/mini" : "zod");
|
|
428
|
+
})
|
|
429
|
+
};
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region src/generators/client.ts
|
|
434
|
+
var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
435
|
+
function createReactQueryClientGenerator(options) {
|
|
436
|
+
const ensureApi = Effect.fn(function* () {
|
|
437
|
+
const ctx = yield* DocumentContext;
|
|
438
|
+
if (!ctx.schemas.has("Api")) {
|
|
439
|
+
const makeRequest = import_lib.identifier("makeRequest");
|
|
440
|
+
const makeRequestOptions = import_lib.identifier("options");
|
|
441
|
+
makeRequestOptions.typeAnnotation = import_lib.tsTypeAnnotation(import_lib.tsTypeLiteral([
|
|
442
|
+
import_lib.tsPropertySignature(import_lib.identifier("method"), import_lib.tsTypeAnnotation(import_lib.tsStringKeyword())),
|
|
443
|
+
import_lib.tsPropertySignature(import_lib.identifier("path"), import_lib.tsTypeAnnotation(import_lib.tsStringKeyword())),
|
|
444
|
+
import_lib.tsPropertySignature(import_lib.identifier("parametersSchema"), import_lib.tsTypeAnnotation(import_lib.tsTypeReference(options.schema.schemaType, import_lib.tsTypeParameterInstantiation([import_lib.tsTypeReference(import_lib.identifier("TParams")), import_lib.tsTypeLiteral([
|
|
445
|
+
Object.assign(import_lib.tsPropertySignature(import_lib.identifier("query"), import_lib.tsTypeAnnotation(import_lib.tsTypeReference(import_lib.identifier("URLSearchParams")))), { optional: true }),
|
|
446
|
+
Object.assign(import_lib.tsPropertySignature(import_lib.identifier("body"), import_lib.tsTypeAnnotation(import_lib.tsUnionType([import_lib.tsStringKeyword(), import_lib.tsTypeReference(import_lib.identifier("Blob"))]))), { optional: true }),
|
|
447
|
+
Object.assign(import_lib.tsPropertySignature(import_lib.identifier("headers"), import_lib.tsTypeAnnotation(import_lib.tsTypeReference(import_lib.identifier("Headers")))), { optional: true }),
|
|
448
|
+
Object.assign(import_lib.tsPropertySignature(import_lib.identifier("path"), import_lib.tsTypeAnnotation(import_lib.tsTypeReference(import_lib.identifier("Record<string, string>")))), { optional: true })
|
|
449
|
+
])])))),
|
|
450
|
+
import_lib.tsPropertySignature(import_lib.identifier("parameters"), import_lib.tsTypeAnnotation(import_lib.tsTypeReference(import_lib.identifier("TParams")))),
|
|
451
|
+
Object.assign(import_lib.tsPropertySignature(import_lib.identifier("responseSchema"), import_lib.tsTypeAnnotation(import_lib.tsTypeReference(options.schema.schemaType, import_lib.tsTypeParameterInstantiation([import_lib.tsTypeReference(import_lib.identifier("TResponse")), import_lib.tsStringKeyword()])))), { optional: true })
|
|
452
|
+
]));
|
|
453
|
+
makeRequest.typeAnnotation = import_lib.tsTypeAnnotation(import_lib.tsFunctionType(import_lib.tsTypeParameterDeclaration([import_lib.tsTypeParameter(null, null, "TParams"), import_lib.tsTypeParameter(null, null, "TResponse")]), [makeRequestOptions], import_lib.tsTypeAnnotation(import_lib.tsTypeReference(import_lib.identifier(options.responseGeneric ? `Promise<${(yield* ensureImport(options.responseGeneric.name, options.responseGeneric.from)).name}<TResponse>>` : "Promise<TResponse>")))));
|
|
454
|
+
ctx.schemas.set("Api", [import_lib.exportNamedDeclaration(import_lib.classDeclaration(import_lib.identifier("Api"), null, import_lib.classBody([import_lib.classPrivateProperty(import_lib.privateName(makeRequest)), import_lib.classMethod("constructor", import_lib.identifier("constructor"), [makeRequest], import_lib.blockStatement([import_lib.expressionStatement(import_lib.assignmentExpression("=", import_lib.memberExpression(import_lib.thisExpression(), import_lib.privateName(makeRequest)), makeRequest))]))])))]);
|
|
455
|
+
}
|
|
456
|
+
return ctx.schemas.get("Api")[0].declaration.body;
|
|
457
|
+
});
|
|
458
|
+
return {
|
|
459
|
+
initialize: Effect.fn(function* () {
|
|
460
|
+
yield* ensureApi();
|
|
461
|
+
if (options.schema.initialize) yield* options.schema.initialize();
|
|
462
|
+
}),
|
|
463
|
+
processOperation: Effect.fn(function* (operationKey, path, method, operation) {
|
|
464
|
+
yield* DocumentContext;
|
|
465
|
+
const parametersSchema = yield* options.schema.ensureParametersSchema(operationKey, operation);
|
|
466
|
+
const responseSchema = yield* options.schema.ensureResponseSchema(operationKey, operation);
|
|
467
|
+
const parameters = import_lib.identifier("parameters");
|
|
468
|
+
parameters.typeAnnotation = import_lib.tsTypeAnnotation(parametersSchema.typeReference);
|
|
469
|
+
const isMutation = method !== "get";
|
|
470
|
+
const fnBody = import_lib.awaitExpression(import_lib.callExpression(import_lib.memberExpression(import_lib.thisExpression(), import_lib.privateName(import_lib.identifier("makeRequest"))), [import_lib.objectExpression([
|
|
471
|
+
import_lib.objectProperty(import_lib.identifier("method"), import_lib.stringLiteral(method)),
|
|
472
|
+
import_lib.objectProperty(import_lib.identifier("path"), import_lib.stringLiteral(path)),
|
|
473
|
+
import_lib.objectProperty(import_lib.identifier("parametersSchema"), parametersSchema.expression, false, true),
|
|
474
|
+
import_lib.objectProperty(import_lib.identifier("parameters"), parameters),
|
|
475
|
+
...responseSchema ? [import_lib.objectProperty(import_lib.identifier("responseSchema"), responseSchema.expression)] : []
|
|
476
|
+
])]));
|
|
477
|
+
const doMethod = import_lib.classMethod("method", import_lib.identifier(operationKey.lower), [parameters], import_lib.blockStatement([import_lib.returnStatement(fnBody)]), false, false, false, true);
|
|
478
|
+
const queryMethod = import_lib.classMethod("method", import_lib.identifier(operationKey.lower + (isMutation ? "Mutation" : "Query")), isMutation ? [] : [parameters], import_lib.blockStatement([import_lib.returnStatement(import_lib.callExpression(yield* ensureImport(isMutation ? "mutationOptions" : "queryOptions", "@tanstack/react-query"), [import_lib.objectExpression([...isMutation ? [] : [import_lib.objectProperty(import_lib.identifier("queryKey"), import_lib.arrayExpression([import_lib.stringLiteral(operationKey.upper), parameters]))], import_lib.objectProperty(import_lib.identifier(isMutation ? "mutationFn" : "queryFn"), import_lib.arrowFunctionExpression(isMutation ? [parameters] : [], import_lib.callExpression(import_lib.memberExpression(import_lib.thisExpression(), import_lib.identifier(operationKey.lower)), [parameters]), true))])]))]));
|
|
479
|
+
const commentLines = [];
|
|
480
|
+
if (operation.summary) commentLines.push(`### ${operation.summary}`);
|
|
481
|
+
if (operation.description) commentLines.push(`${operation.description}`);
|
|
482
|
+
if (commentLines.length) {
|
|
483
|
+
import_lib.addComment(queryMethod, "leading", `*\n${commentLines.join("\n")}\n*`);
|
|
484
|
+
import_lib.addComment(doMethod, "leading", `*\n${commentLines.join("\n")}\n*`);
|
|
485
|
+
}
|
|
486
|
+
const api = yield* ensureApi();
|
|
487
|
+
api.body.push(doMethod);
|
|
488
|
+
api.body.push(queryMethod);
|
|
489
|
+
})
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
//#endregion
|
|
494
|
+
export { createEffectSchemaGenerator, createReactQueryClientGenerator, createSchemaGenerator, createZodSchemaGenerator, helpers_exports as generatorHelpers };
|
|
495
|
+
//# sourceMappingURL=index.js.map
|