mobx-tanstack-query-api 0.41.0 → 0.41.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/cli.cjs +36 -18
- package/cli.cjs.map +1 -1
- package/cli.d.ts +4 -3
- package/cli.js +36 -18
- package/cli.js.map +1 -1
- package/package.json +1 -1
package/cli.cjs
CHANGED
|
@@ -219,10 +219,15 @@ const createShortModelType = (shortModelType) => {
|
|
|
219
219
|
description: shortModelType.description || ""
|
|
220
220
|
};
|
|
221
221
|
};
|
|
222
|
-
const
|
|
222
|
+
const DEFAULT_DATA_CONTRACT_TYPE_SUFFIX = "DC";
|
|
223
|
+
const DEFAULT_ZOD_CONTRACT_SUFFIX = "";
|
|
224
|
+
const DEFAULT_ENDPOINT_ZOD_CONTRACT_SUFFIX = "Contract";
|
|
223
225
|
function getZodContractSuffix(zodContracts) {
|
|
224
226
|
return (typeof zodContracts === "object" && zodContracts !== null && typeof zodContracts.suffix === "string" ? zodContracts.suffix : void 0) ?? DEFAULT_ZOD_CONTRACT_SUFFIX;
|
|
225
227
|
}
|
|
228
|
+
function getEndpointZodContractSuffix(zodContracts) {
|
|
229
|
+
return (typeof zodContracts === "object" && zodContracts !== null && typeof zodContracts.suffix === "string" ? zodContracts.suffix : void 0) ?? DEFAULT_ENDPOINT_ZOD_CONTRACT_SUFFIX;
|
|
230
|
+
}
|
|
226
231
|
const REF_PREFIX = "#/components/schemas/";
|
|
227
232
|
const REF_PREFIX_PARAMS = "#/components/parameters/";
|
|
228
233
|
function parseRef(ref) {
|
|
@@ -251,7 +256,7 @@ function getResponseSchemaKeyFromOperation(rawOperation) {
|
|
|
251
256
|
if (typeof ref !== "string") return null;
|
|
252
257
|
return parseRef(ref);
|
|
253
258
|
}
|
|
254
|
-
function typeNameToSchemaKey(typeName, typeSuffix =
|
|
259
|
+
function typeNameToSchemaKey(typeName, typeSuffix = DEFAULT_DATA_CONTRACT_TYPE_SUFFIX) {
|
|
255
260
|
const t = typeName.trim();
|
|
256
261
|
if (typeSuffix && t.endsWith(typeSuffix))
|
|
257
262
|
return t.slice(0, -typeSuffix.length);
|
|
@@ -378,9 +383,16 @@ function collectRefs(schema, schemas, out) {
|
|
|
378
383
|
collectRefs(schema.additionalProperties, schemas, out);
|
|
379
384
|
}
|
|
380
385
|
}
|
|
381
|
-
function
|
|
386
|
+
function dataContractTypeNameToZodVarName(typeName, utils, contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX) {
|
|
382
387
|
const _ = utils._;
|
|
383
|
-
return `${_.camelCase(
|
|
388
|
+
return `${_.camelCase(typeName)}${contractSuffix}`;
|
|
389
|
+
}
|
|
390
|
+
function schemaKeyToContractVarName(key, utils, contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX, typeSuffix = DEFAULT_DATA_CONTRACT_TYPE_SUFFIX) {
|
|
391
|
+
return dataContractTypeNameToZodVarName(
|
|
392
|
+
`${key}${typeSuffix}`,
|
|
393
|
+
utils,
|
|
394
|
+
contractSuffix
|
|
395
|
+
);
|
|
384
396
|
}
|
|
385
397
|
function resolveQueryParameters(operation, componentsParameters) {
|
|
386
398
|
const list = [];
|
|
@@ -448,9 +460,10 @@ function buildCentralZodContractsFile(params) {
|
|
|
448
460
|
const {
|
|
449
461
|
componentsSchemas,
|
|
450
462
|
utils,
|
|
451
|
-
contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX
|
|
463
|
+
contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX,
|
|
464
|
+
typeSuffix = DEFAULT_DATA_CONTRACT_TYPE_SUFFIX
|
|
452
465
|
} = params;
|
|
453
|
-
const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix);
|
|
466
|
+
const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix, typeSuffix);
|
|
454
467
|
const lines = generateAuxiliarySchemas(
|
|
455
468
|
Object.keys(componentsSchemas),
|
|
456
469
|
componentsSchemas,
|
|
@@ -476,7 +489,7 @@ function typeToZodSchemaFallback(typeStr) {
|
|
|
476
489
|
if (t === "unknown") return "z.unknown()";
|
|
477
490
|
return "z.any()";
|
|
478
491
|
}
|
|
479
|
-
function typeToZodSchemaWithSchema(typeStr, schemas, utils, typeSuffix, contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX) {
|
|
492
|
+
function typeToZodSchemaWithSchema(typeStr, schemas, utils, typeSuffix = DEFAULT_DATA_CONTRACT_TYPE_SUFFIX, contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX) {
|
|
480
493
|
const t = typeStr.trim();
|
|
481
494
|
if (!schemas || Object.keys(schemas).length === 0) {
|
|
482
495
|
return { expr: typeToZodSchemaFallback(t), refs: [] };
|
|
@@ -489,7 +502,7 @@ function typeToZodSchemaWithSchema(typeStr, schemas, utils, typeSuffix, contract
|
|
|
489
502
|
}
|
|
490
503
|
const refs = /* @__PURE__ */ new Set();
|
|
491
504
|
collectRefs(schema, schemas, refs);
|
|
492
|
-
const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix);
|
|
505
|
+
const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix, typeSuffix);
|
|
493
506
|
const expr = schemaToZodExpr(
|
|
494
507
|
schema,
|
|
495
508
|
schemas,
|
|
@@ -498,12 +511,12 @@ function typeToZodSchemaWithSchema(typeStr, schemas, utils, typeSuffix, contract
|
|
|
498
511
|
);
|
|
499
512
|
return { expr, refs: [...refs] };
|
|
500
513
|
}
|
|
501
|
-
function schemaKeyToZod(schemaKey, schemas, utils, contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX) {
|
|
514
|
+
function schemaKeyToZod(schemaKey, schemas, utils, typeSuffix = DEFAULT_DATA_CONTRACT_TYPE_SUFFIX, contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX) {
|
|
502
515
|
const schema = schemas[schemaKey];
|
|
503
516
|
if (!schema) return { expr: "z.any()", refs: [] };
|
|
504
517
|
const refs = /* @__PURE__ */ new Set();
|
|
505
518
|
collectRefs(schema, schemas, refs);
|
|
506
|
-
const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix);
|
|
519
|
+
const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix, typeSuffix);
|
|
507
520
|
const expr = schemaToZodExpr(
|
|
508
521
|
schema,
|
|
509
522
|
schemas,
|
|
@@ -520,7 +533,7 @@ function buildEndpointZodContractsCode(params) {
|
|
|
520
533
|
utils,
|
|
521
534
|
contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX,
|
|
522
535
|
componentsSchemas = null,
|
|
523
|
-
typeSuffix =
|
|
536
|
+
typeSuffix = DEFAULT_DATA_CONTRACT_TYPE_SUFFIX,
|
|
524
537
|
responseSchemaKey,
|
|
525
538
|
useExternalZodSchemas = false,
|
|
526
539
|
openApiOperation = null,
|
|
@@ -531,7 +544,7 @@ function buildEndpointZodContractsCode(params) {
|
|
|
531
544
|
const allAuxiliaryKeys = /* @__PURE__ */ new Set();
|
|
532
545
|
const paramParts = [];
|
|
533
546
|
const resolvedQueryParams = openApiOperation && (openApiComponentsParameters || openApiOperation.parameters?.length) ? resolveQueryParameters(openApiOperation, openApiComponentsParameters) : [];
|
|
534
|
-
const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix);
|
|
547
|
+
const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix, typeSuffix);
|
|
535
548
|
for (const p of inputParams) {
|
|
536
549
|
let expr;
|
|
537
550
|
let refKeys = [];
|
|
@@ -560,6 +573,7 @@ function buildEndpointZodContractsCode(params) {
|
|
|
560
573
|
responseSchemaKey,
|
|
561
574
|
componentsSchemas,
|
|
562
575
|
utils,
|
|
576
|
+
typeSuffix,
|
|
563
577
|
contractSuffix
|
|
564
578
|
) : typeToZodSchemaWithSchema(
|
|
565
579
|
responseDataTypeName,
|
|
@@ -754,7 +768,8 @@ const newEndpointTmpl = ({
|
|
|
754
768
|
}) => {
|
|
755
769
|
const zodContractsIsObject = typeof zodContracts === "object" && zodContracts !== null;
|
|
756
770
|
const hasZodContracts = zodContracts === true || zodContractsIsObject;
|
|
757
|
-
const
|
|
771
|
+
const sharedContractSuffix = getZodContractSuffix(zodContracts);
|
|
772
|
+
const endpointContractSuffix = getEndpointZodContractSuffix(zodContracts);
|
|
758
773
|
const { _ } = utils;
|
|
759
774
|
const positiveResponseTypes = route.raw.responsesTypes?.filter(
|
|
760
775
|
(it) => +it.status >= 200 && +it.status < 300 && (!it.typeData || filterTypes(it.typeData))
|
|
@@ -868,7 +883,7 @@ const newEndpointTmpl = ({
|
|
|
868
883
|
});
|
|
869
884
|
const isAllowedInputType = filterTypes(requestInputTypeDc);
|
|
870
885
|
const defaultOkResponseType = positiveResponseTypes?.[0]?.type ?? "unknown";
|
|
871
|
-
const contractVarName = hasZodContracts ? `${_.camelCase(route.routeName.usage)}${
|
|
886
|
+
const contractVarName = hasZodContracts ? `${_.camelCase(route.routeName.usage)}${endpointContractSuffix}` : null;
|
|
872
887
|
const routeInfoForContracts = contractVarName != null ? {
|
|
873
888
|
operationId: raw.operationId ?? "",
|
|
874
889
|
path: path2,
|
|
@@ -911,7 +926,10 @@ const newEndpointTmpl = ({
|
|
|
911
926
|
(m) => m.name === defaultOkResponseType
|
|
912
927
|
);
|
|
913
928
|
if (aliasType?.typeIdentifier === "type" && typeof aliasType.content === "string" && /^[A-Za-z0-9_]+$/.test(aliasType.content.trim())) {
|
|
914
|
-
const resolved = typeNameToSchemaKey(
|
|
929
|
+
const resolved = typeNameToSchemaKey(
|
|
930
|
+
aliasType.content.trim(),
|
|
931
|
+
DEFAULT_DATA_CONTRACT_TYPE_SUFFIX
|
|
932
|
+
);
|
|
915
933
|
if (resolved in componentsSchemas) responseSchemaKey = resolved;
|
|
916
934
|
}
|
|
917
935
|
}
|
|
@@ -929,10 +947,10 @@ const newEndpointTmpl = ({
|
|
|
929
947
|
contractVarName,
|
|
930
948
|
utils,
|
|
931
949
|
componentsSchemas: componentsSchemas ?? void 0,
|
|
932
|
-
typeSuffix:
|
|
950
|
+
typeSuffix: DEFAULT_DATA_CONTRACT_TYPE_SUFFIX,
|
|
933
951
|
responseSchemaKey: responseSchemaKey ?? void 0,
|
|
934
952
|
useExternalZodSchemas: Boolean(relativePathZodSchemas),
|
|
935
|
-
contractSuffix,
|
|
953
|
+
contractSuffix: sharedContractSuffix,
|
|
936
954
|
openApiOperation: operationFromSpec ?? void 0,
|
|
937
955
|
openApiComponentsParameters: swaggerSchema?.components?.parameters ?? void 0,
|
|
938
956
|
queryParamName: queryName
|
|
@@ -1509,7 +1527,7 @@ const generateApi = async (params) => {
|
|
|
1509
1527
|
cleanOutput: params.cleanOutput ?? true,
|
|
1510
1528
|
modular: true,
|
|
1511
1529
|
patch: true,
|
|
1512
|
-
typeSuffix:
|
|
1530
|
+
typeSuffix: DEFAULT_DATA_CONTRACT_TYPE_SUFFIX,
|
|
1513
1531
|
disableStrictSSL: false,
|
|
1514
1532
|
singleHttpClient: true,
|
|
1515
1533
|
extractRequestBody: true,
|