@povio/openapi-codegen-cli 3.0.0-rc.8 → 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.
- package/README.md +41 -0
- package/dist/acl.d.mts +1 -1
- package/dist/{config-C1ME3Ay4.d.mts → config-CrZa_Jbm.d.mts} +1 -1
- package/dist/{generate.runner-C94-P4xF.mjs → generate.runner-BXTc97I0.mjs} +1 -1
- package/dist/{generateCodeFromOpenAPIDoc-DGox5gzo.mjs → generateCodeFromOpenAPIDoc-C-n0Knj8.mjs} +302 -207
- package/dist/generator.d.mts +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/index.d.mts +6 -3
- package/dist/index.mjs +14 -3
- package/dist/metro.d.mts +32 -0
- package/dist/metro.mjs +86 -0
- package/dist/openapi-codegen.runner-QGd35-a3.mjs +42 -0
- package/dist/sh.mjs +3 -3
- package/dist/vite.d.mts +7 -4
- package/dist/vite.mjs +9 -23
- package/dist/zod.d.mts +1 -1
- package/package.json +6 -2
- /package/dist/{error-handling-B4aYKmyL.d.mts → error-handling-oM5YJYYH.d.mts} +0 -0
- /package/dist/{options-BPAjzilp.d.mts → options-BZOw7Hx4.d.mts} +0 -0
package/dist/{generateCodeFromOpenAPIDoc-DGox5gzo.mjs → generateCodeFromOpenAPIDoc-C-n0Knj8.mjs}
RENAMED
|
@@ -386,12 +386,23 @@ function replaceHyphenatedPath(path) {
|
|
|
386
386
|
});
|
|
387
387
|
return path;
|
|
388
388
|
}
|
|
389
|
-
const isSortingParameterObject = (param) => {
|
|
390
|
-
const enumNames = param
|
|
391
|
-
|
|
392
|
-
const isStringSchema = !!param.schema && isSchemaObject(param.schema) && param.schema.type === "string";
|
|
393
|
-
return hasEnumNames && isStringSchema;
|
|
389
|
+
const isSortingParameterObject = (param, schema = param.schema, resolver) => {
|
|
390
|
+
const enumNames = getParameterEnumNames(param, schema);
|
|
391
|
+
return Array.isArray(enumNames) && enumNames.length > 0 && isStringLikeParameterSchema(schema, resolver);
|
|
394
392
|
};
|
|
393
|
+
function getParameterEnumNames(param, schema = param.schema) {
|
|
394
|
+
return param["x-enumNames"] ?? (schema && isSchemaObject(schema) ? schema["x-enumNames"] : void 0);
|
|
395
|
+
}
|
|
396
|
+
function isStringLikeParameterSchema(schema, resolver) {
|
|
397
|
+
if (!schema) return false;
|
|
398
|
+
if (isReferenceObject(schema)) return resolver ? isStringLikeParameterSchema(resolver.resolveObject(schema), resolver) : true;
|
|
399
|
+
if (schema.type === "string" || Array.isArray(schema.type) && schema.type.includes("string")) return true;
|
|
400
|
+
return [
|
|
401
|
+
...schema.allOf ?? [],
|
|
402
|
+
...schema.oneOf ?? [],
|
|
403
|
+
...schema.anyOf ?? []
|
|
404
|
+
].some((compositeSchema) => isStringLikeParameterSchema(compositeSchema, resolver));
|
|
405
|
+
}
|
|
395
406
|
const isPathExcluded = (path, options) => {
|
|
396
407
|
if (!options.excludePathRegex) return false;
|
|
397
408
|
return new RegExp(options.excludePathRegex).test(path);
|
|
@@ -990,7 +1001,6 @@ function resolveZodSchemaName({ schema, zodSchema, fallbackName, resolver, tag }
|
|
|
990
1001
|
if (zodSchema.complexity < COMPLEXITY_THRESHOLD) return result;
|
|
991
1002
|
const zodSchemaName = getZodSchemaName(fallbackName, resolver.options.schemaSuffix);
|
|
992
1003
|
while (resolver.getCodeByZodSchemaName(zodSchemaName)) if (resolver.getZodSchemaNamesByCompositeCode(result)?.includes(zodSchemaName)) return zodSchemaName;
|
|
993
|
-
else if (result === zodSchemaName || result.startsWith(`${zodSchemaName}.`)) return zodSchemaName;
|
|
994
1004
|
else if (resolver.getCodeByZodSchemaName(zodSchemaName) === zodSchemaName) return zodSchemaName;
|
|
995
1005
|
else throw new Error(`Can't uniquely resolve zod schema name: ${zodSchemaName}`);
|
|
996
1006
|
resolver.setZodSchema(zodSchemaName, result, tag);
|
|
@@ -1398,96 +1408,6 @@ const DEFAULT_GENERATE_OPTIONS = {
|
|
|
1398
1408
|
//#region src/generators/utils/array.utils.ts
|
|
1399
1409
|
const getUniqueArray = (...arrs) => [...new Set(arrs.flat())];
|
|
1400
1410
|
|
|
1401
|
-
//#endregion
|
|
1402
|
-
//#region src/generators/utils/generate/generate.acl.utils.ts
|
|
1403
|
-
const getAbilityFunctionName = (endpoint) => `canUse${capitalize(snakeToCamel(endpoint.operationName))}`;
|
|
1404
|
-
const getImportedAbilityFunctionName = (endpoint, options) => {
|
|
1405
|
-
return `${options.tsNamespaces ? `${getNamespaceName({
|
|
1406
|
-
type: GenerateType.Acl,
|
|
1407
|
-
tag: getEndpointTag(endpoint, options),
|
|
1408
|
-
options
|
|
1409
|
-
})}.` : ""}${getAbilityFunctionName(endpoint)}`;
|
|
1410
|
-
};
|
|
1411
|
-
const getAbilityAction = (endpoint) => endpoint.acl?.[0].action;
|
|
1412
|
-
const getAbilitySubject = (endpoint) => endpoint.acl?.[0].subject;
|
|
1413
|
-
const hasAbilityConditions = (endpoint) => !!getAbilityConditionsTypes(endpoint)?.length;
|
|
1414
|
-
const getAbilityConditionsTypes = (endpoint) => endpoint.acl?.[0].conditionsTypes?.sort((a, b) => a.name.localeCompare(b.name));
|
|
1415
|
-
const getAbilityDescription = (endpoint) => endpoint.acl?.[0]?.description;
|
|
1416
|
-
const getAbilitySubjectTypes = (endpoint) => {
|
|
1417
|
-
const abilitySubject = getAbilitySubject(endpoint);
|
|
1418
|
-
const types = [`"${abilitySubject ?? ""}"`];
|
|
1419
|
-
if (hasAbilityConditions(endpoint)) types.push(`ForcedSubject<"${abilitySubject}"> & { ${getAbilityConditionsTypes(endpoint)?.map((conditionType) => `${conditionType.name}${conditionType.required ? "" : "?"}: ${conditionType.type ?? ""}${conditionType.zodSchemaName ?? ""},`).join(" ")} }`);
|
|
1420
|
-
return types;
|
|
1421
|
-
};
|
|
1422
|
-
function getAclData({ resolver, data, tag }) {
|
|
1423
|
-
const endpoints = data.get(tag)?.endpoints.filter(({ acl }) => acl && acl.length > 0);
|
|
1424
|
-
if (!endpoints || endpoints.length === 0) return;
|
|
1425
|
-
return {
|
|
1426
|
-
endpoints,
|
|
1427
|
-
hasAdditionalAbilityImports: endpoints.some(({ acl }) => acl?.[0].conditions && Object.keys(acl[0].conditions).length > 0),
|
|
1428
|
-
modelsImports: getModelsImports({
|
|
1429
|
-
resolver,
|
|
1430
|
-
tag,
|
|
1431
|
-
zodSchemasAsTypes: getUniqueArray(endpoints.reduce((acc, endpoint) => {
|
|
1432
|
-
const zodSchemas = endpoint.acl?.[0].conditionsTypes?.reduce((acc, propertyType) => [...acc, ...propertyType?.zodSchemaName ? [propertyType.zodSchemaName] : []], []);
|
|
1433
|
-
return [...acc, ...zodSchemas ?? []];
|
|
1434
|
-
}, []))
|
|
1435
|
-
})
|
|
1436
|
-
};
|
|
1437
|
-
}
|
|
1438
|
-
const getAppAbilitiesType = ({ resolver, data }) => {
|
|
1439
|
-
const appAbilitiesTypeMap = /* @__PURE__ */ new Map();
|
|
1440
|
-
const modelsImportsArr = [];
|
|
1441
|
-
let hasAdditionalAbilityImports = false;
|
|
1442
|
-
data.forEach((_, tag) => {
|
|
1443
|
-
const aclData = getAclData({
|
|
1444
|
-
resolver,
|
|
1445
|
-
data,
|
|
1446
|
-
tag
|
|
1447
|
-
});
|
|
1448
|
-
if (!aclData) return;
|
|
1449
|
-
const { modelsImports: tagModelsImports, hasAdditionalAbilityImports: tagHasAdditionalAbilityImports, endpoints } = aclData;
|
|
1450
|
-
modelsImportsArr.push(tagModelsImports);
|
|
1451
|
-
hasAdditionalAbilityImports = hasAdditionalAbilityImports || tagHasAdditionalAbilityImports;
|
|
1452
|
-
endpoints.forEach((endpoint) => {
|
|
1453
|
-
const abilityAction = getAbilityAction(endpoint);
|
|
1454
|
-
if (abilityAction) appAbilitiesTypeMap.set(abilityAction, new Set([...appAbilitiesTypeMap.get(abilityAction) ?? [], ...getAbilitySubjectTypes(endpoint)]));
|
|
1455
|
-
});
|
|
1456
|
-
});
|
|
1457
|
-
const modelsImports = mergeImports(resolver.options, ...modelsImportsArr);
|
|
1458
|
-
return {
|
|
1459
|
-
appAbilitiesType: appAbilitiesTypeMap.size > 0 ? Object.fromEntries(Array.from(appAbilitiesTypeMap.entries()).map(([key, valueSet]) => [key, Array.from(valueSet)])) : void 0,
|
|
1460
|
-
modelsImports,
|
|
1461
|
-
hasAdditionalAbilityImports
|
|
1462
|
-
};
|
|
1463
|
-
};
|
|
1464
|
-
|
|
1465
|
-
//#endregion
|
|
1466
|
-
//#region src/generators/utils/generate/generate.query.utils.ts
|
|
1467
|
-
const getQueryName = (endpoint, mutation) => {
|
|
1468
|
-
const addMutationSuffix = isQuery(endpoint) && isMutation(endpoint) && mutation;
|
|
1469
|
-
return `use${capitalize(snakeToCamel(endpoint.operationName))}${addMutationSuffix ? "Mutation" : ""}`;
|
|
1470
|
-
};
|
|
1471
|
-
const getInfiniteQueryName = (endpoint) => `use${capitalize(snakeToCamel(endpoint.operationName))}Infinite`;
|
|
1472
|
-
const getQueryOptionsName = (endpoint) => `${snakeToCamel(endpoint.operationName)}QueryOptions`;
|
|
1473
|
-
const getInfiniteQueryOptionsName = (endpoint) => `${snakeToCamel(endpoint.operationName)}InfiniteQueryOptions`;
|
|
1474
|
-
const getPrefetchQueryName = (endpoint) => `prefetch${capitalize(snakeToCamel(endpoint.operationName))}`;
|
|
1475
|
-
const getPrefetchInfiniteQueryName = (endpoint) => `prefetch${capitalize(snakeToCamel(endpoint.operationName))}Infinite`;
|
|
1476
|
-
const getImportedQueryName = (endpoint, options) => {
|
|
1477
|
-
return `${options.tsNamespaces ? `${getNamespaceName({
|
|
1478
|
-
type: GenerateType.Queries,
|
|
1479
|
-
tag: getEndpointTag(endpoint, options),
|
|
1480
|
-
options
|
|
1481
|
-
})}.` : ""}${getQueryName(endpoint)}`;
|
|
1482
|
-
};
|
|
1483
|
-
const getImportedInfiniteQueryName = (endpoint, options) => {
|
|
1484
|
-
return `${options.tsNamespaces ? `${getNamespaceName({
|
|
1485
|
-
type: GenerateType.Queries,
|
|
1486
|
-
tag: getEndpointTag(endpoint, options),
|
|
1487
|
-
options
|
|
1488
|
-
})}.` : ""}${getInfiniteQueryName(endpoint)}`;
|
|
1489
|
-
};
|
|
1490
|
-
|
|
1491
1411
|
//#endregion
|
|
1492
1412
|
//#region src/generators/core/openapi/iterateSchema.ts
|
|
1493
1413
|
function iterateSchema(schema, options) {
|
|
@@ -1574,16 +1494,20 @@ function getSchemaDescriptions(schemaObj) {
|
|
|
1574
1494
|
const getZodSchemaInferedTypeName = (zodSchemaName, options) => removeSuffix(zodSchemaName, options.schemaSuffix);
|
|
1575
1495
|
const getImportedZodSchemaName = (resolver, zodSchemaName, namespaceTag) => {
|
|
1576
1496
|
if (!isNamedZodSchema(zodSchemaName)) return zodSchemaName;
|
|
1577
|
-
const tag =
|
|
1497
|
+
const tag = getOwningOrLocalProxyTag(resolver, zodSchemaName, namespaceTag);
|
|
1578
1498
|
return `${resolver.options.tsNamespaces ? `${getNamespaceName({
|
|
1579
1499
|
type: GenerateType.Models,
|
|
1580
1500
|
tag,
|
|
1581
1501
|
options: resolver.options
|
|
1582
1502
|
})}.` : ""}${zodSchemaName}`;
|
|
1583
1503
|
};
|
|
1504
|
+
function getOwningOrLocalProxyTag(resolver, zodSchemaName, namespaceTag) {
|
|
1505
|
+
if (namespaceTag && resolver.options.modelsInCommon && resolver.options.splitByTags) return namespaceTag;
|
|
1506
|
+
return resolver.getTagByZodSchemaName(zodSchemaName) ?? namespaceTag;
|
|
1507
|
+
}
|
|
1584
1508
|
const getImportedZodSchemaInferedTypeName = (resolver, zodSchemaName, currentTag, namespaceTag) => {
|
|
1585
1509
|
if (!isNamedZodSchema(zodSchemaName)) return zodSchemaName === VOID_SCHEMA ? "void" : zodSchemaName;
|
|
1586
|
-
const tag =
|
|
1510
|
+
const tag = getOwningOrLocalProxyTag(resolver, zodSchemaName, namespaceTag);
|
|
1587
1511
|
return `${resolver.options.tsNamespaces && (Boolean(namespaceTag) || tag !== currentTag) ? `${getNamespaceName({
|
|
1588
1512
|
type: GenerateType.Models,
|
|
1589
1513
|
tag,
|
|
@@ -1656,6 +1580,113 @@ function getZodSchemaPropertyDescriptions(resolver, data, tag) {
|
|
|
1656
1580
|
return properties;
|
|
1657
1581
|
}
|
|
1658
1582
|
|
|
1583
|
+
//#endregion
|
|
1584
|
+
//#region src/generators/utils/generate/generate.acl.utils.ts
|
|
1585
|
+
const getAbilityFunctionName = (endpoint) => `canUse${capitalize(snakeToCamel(endpoint.operationName))}`;
|
|
1586
|
+
const getImportedAbilityFunctionName = (endpoint, options) => {
|
|
1587
|
+
return `${options.tsNamespaces ? `${getNamespaceName({
|
|
1588
|
+
type: GenerateType.Acl,
|
|
1589
|
+
tag: getEndpointTag(endpoint, options),
|
|
1590
|
+
options
|
|
1591
|
+
})}.` : ""}${getAbilityFunctionName(endpoint)}`;
|
|
1592
|
+
};
|
|
1593
|
+
const getAbilityAction = (endpoint) => endpoint.acl?.[0].action;
|
|
1594
|
+
const getAbilitySubject = (endpoint) => endpoint.acl?.[0].subject;
|
|
1595
|
+
const hasAbilityConditions = (endpoint) => !!getAbilityConditionsTypes(endpoint)?.length;
|
|
1596
|
+
const getAbilityConditionsTypes = (endpoint) => endpoint.acl?.[0].conditionsTypes?.sort((a, b) => a.name.localeCompare(b.name));
|
|
1597
|
+
const getAbilityDescription = (endpoint) => endpoint.acl?.[0]?.description;
|
|
1598
|
+
const getAbilitySubjectTypes = (endpoint, resolver, tag) => {
|
|
1599
|
+
const abilitySubject = getAbilitySubject(endpoint);
|
|
1600
|
+
const types = [`"${abilitySubject ?? ""}"`];
|
|
1601
|
+
if (hasAbilityConditions(endpoint)) types.push(`ForcedSubject<"${abilitySubject}"> & { ${getAbilityConditionsTypes(endpoint)?.map((conditionType) => `${conditionType.name}${conditionType.required ? "" : "?"}: ${getAbilityConditionType(conditionType, resolver, tag)},`).join(" ")} }`);
|
|
1602
|
+
return types;
|
|
1603
|
+
};
|
|
1604
|
+
function getAbilityConditionType(conditionType, resolver, tag) {
|
|
1605
|
+
if (!conditionType.zodSchemaName) return conditionType.type ?? "";
|
|
1606
|
+
if (!resolver) return `${conditionType.type ?? ""}${conditionType.zodSchemaName}`;
|
|
1607
|
+
return getImportedZodSchemaInferedTypeName(resolver, conditionType.zodSchemaName, tag, tag);
|
|
1608
|
+
}
|
|
1609
|
+
function getAclData({ resolver, data, tag }) {
|
|
1610
|
+
const endpoints = data.get(tag)?.endpoints.filter(({ acl }) => acl && acl.length > 0);
|
|
1611
|
+
if (!endpoints || endpoints.length === 0) return;
|
|
1612
|
+
return {
|
|
1613
|
+
endpoints,
|
|
1614
|
+
hasAdditionalAbilityImports: endpoints.some(({ acl }) => acl?.[0].conditions && Object.keys(acl[0].conditions).length > 0),
|
|
1615
|
+
modelsImports: getModelsImports({
|
|
1616
|
+
resolver,
|
|
1617
|
+
tag,
|
|
1618
|
+
zodSchemasAsTypes: getUniqueArray(endpoints.reduce((acc, endpoint) => {
|
|
1619
|
+
const zodSchemas = endpoint.acl?.[0].conditionsTypes?.reduce((acc, propertyType) => [...acc, ...propertyType?.zodSchemaName ? [propertyType.zodSchemaName] : []], []);
|
|
1620
|
+
return [...acc, ...zodSchemas ?? []];
|
|
1621
|
+
}, []))
|
|
1622
|
+
})
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
const getAppAbilitiesType = ({ resolver, data }) => {
|
|
1626
|
+
const appAbilitiesTypeMap = /* @__PURE__ */ new Map();
|
|
1627
|
+
const modelsImportsArr = [];
|
|
1628
|
+
let hasAdditionalAbilityImports = false;
|
|
1629
|
+
data.forEach((_, tag) => {
|
|
1630
|
+
const aclData = getAclData({
|
|
1631
|
+
resolver,
|
|
1632
|
+
data,
|
|
1633
|
+
tag
|
|
1634
|
+
});
|
|
1635
|
+
if (!aclData) return;
|
|
1636
|
+
const { modelsImports: tagModelsImports, hasAdditionalAbilityImports: tagHasAdditionalAbilityImports, endpoints } = aclData;
|
|
1637
|
+
modelsImportsArr.push(tagModelsImports);
|
|
1638
|
+
hasAdditionalAbilityImports = hasAdditionalAbilityImports || tagHasAdditionalAbilityImports;
|
|
1639
|
+
endpoints.forEach((endpoint) => {
|
|
1640
|
+
const abilityAction = getAbilityAction(endpoint);
|
|
1641
|
+
if (abilityAction) appAbilitiesTypeMap.set(abilityAction, new Set([...appAbilitiesTypeMap.get(abilityAction) ?? [], ...getAbilitySubjectTypes(endpoint, resolver, tag)]));
|
|
1642
|
+
});
|
|
1643
|
+
});
|
|
1644
|
+
const modelsImports = mergeImports(resolver.options, ...modelsImportsArr);
|
|
1645
|
+
return {
|
|
1646
|
+
appAbilitiesType: appAbilitiesTypeMap.size > 0 ? Object.fromEntries(Array.from(appAbilitiesTypeMap.entries()).map(([key, valueSet]) => [key, Array.from(valueSet)])) : void 0,
|
|
1647
|
+
modelsImports,
|
|
1648
|
+
hasAdditionalAbilityImports
|
|
1649
|
+
};
|
|
1650
|
+
};
|
|
1651
|
+
/** Renders a `checkAcl(...)` call, passing the ability's conditions object only when the
|
|
1652
|
+
* ability function actually expects one (i.e. the endpoint declares matching conditions). */
|
|
1653
|
+
function renderAclCheckCall(resolver, endpoint, replacements, indent = "") {
|
|
1654
|
+
const checkParams = getAbilityConditionsTypes(endpoint)?.map((condition) => invalidVariableNameCharactersToCamel(condition.name));
|
|
1655
|
+
const paramNames = new Set(endpoint.parameters.map((param) => invalidVariableNameCharactersToCamel(param.name)));
|
|
1656
|
+
const hasAllCheckParams = checkParams?.every((param) => paramNames.has(param));
|
|
1657
|
+
const args = hasAbilityConditions(endpoint) && hasAllCheckParams ? `{ ${(checkParams ?? []).map((param) => {
|
|
1658
|
+
const resolvedParam = replacements?.[param] ?? param;
|
|
1659
|
+
return resolvedParam === param ? param : `${param}: ${resolvedParam}`;
|
|
1660
|
+
}).join(", ")} } ` : "";
|
|
1661
|
+
return `${indent}checkAcl(${getImportedAbilityFunctionName(endpoint, resolver.options)}(${args}));`;
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
//#endregion
|
|
1665
|
+
//#region src/generators/utils/generate/generate.query.utils.ts
|
|
1666
|
+
const getQueryName = (endpoint, mutation) => {
|
|
1667
|
+
const addMutationSuffix = isQuery(endpoint) && isMutation(endpoint) && mutation;
|
|
1668
|
+
return `use${capitalize(snakeToCamel(endpoint.operationName))}${addMutationSuffix ? "Mutation" : ""}`;
|
|
1669
|
+
};
|
|
1670
|
+
const getInfiniteQueryName = (endpoint) => `use${capitalize(snakeToCamel(endpoint.operationName))}Infinite`;
|
|
1671
|
+
const getQueryOptionsName = (endpoint) => `${snakeToCamel(endpoint.operationName)}QueryOptions`;
|
|
1672
|
+
const getInfiniteQueryOptionsName = (endpoint) => `${snakeToCamel(endpoint.operationName)}InfiniteQueryOptions`;
|
|
1673
|
+
const getPrefetchQueryName = (endpoint) => `prefetch${capitalize(snakeToCamel(endpoint.operationName))}`;
|
|
1674
|
+
const getPrefetchInfiniteQueryName = (endpoint) => `prefetch${capitalize(snakeToCamel(endpoint.operationName))}Infinite`;
|
|
1675
|
+
const getImportedQueryName = (endpoint, options) => {
|
|
1676
|
+
return `${options.tsNamespaces ? `${getNamespaceName({
|
|
1677
|
+
type: GenerateType.Queries,
|
|
1678
|
+
tag: getEndpointTag(endpoint, options),
|
|
1679
|
+
options
|
|
1680
|
+
})}.` : ""}${getQueryName(endpoint)}`;
|
|
1681
|
+
};
|
|
1682
|
+
const getImportedInfiniteQueryName = (endpoint, options) => {
|
|
1683
|
+
return `${options.tsNamespaces ? `${getNamespaceName({
|
|
1684
|
+
type: GenerateType.Queries,
|
|
1685
|
+
tag: getEndpointTag(endpoint, options),
|
|
1686
|
+
options
|
|
1687
|
+
})}.` : ""}${getInfiniteQueryName(endpoint)}`;
|
|
1688
|
+
};
|
|
1689
|
+
|
|
1659
1690
|
//#endregion
|
|
1660
1691
|
//#region src/generators/utils/generate/generate.imports.utils.ts
|
|
1661
1692
|
function getModelsImports({ resolver, tag, zodSchemas = [], zodSchemasAsTypes = [] }) {
|
|
@@ -1973,7 +2004,8 @@ const getEndpointBody$1 = (endpoint) => endpoint.parameters.find((param) => para
|
|
|
1973
2004
|
const hasEndpointConfig = (endpoint, resolver) => {
|
|
1974
2005
|
const endpointConfig = getEndpointConfig(endpoint);
|
|
1975
2006
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
1976
|
-
|
|
2007
|
+
const needsBlobConfig = endpoint.mediaDownload || endpoint.response === "z.instanceof(Blob)";
|
|
2008
|
+
return Object.keys(endpointConfig).length > 0 || hasAxiosRequestConfig || needsBlobConfig;
|
|
1977
2009
|
};
|
|
1978
2010
|
const getEndpointPath = (endpoint) => endpoint.path.replace(/:([a-zA-Z0-9_]+)/g, "${$1}");
|
|
1979
2011
|
function mapEndpointParamsToFunctionParams(resolver, endpoint, options) {
|
|
@@ -2040,6 +2072,40 @@ function getEndpointConfig(endpoint) {
|
|
|
2040
2072
|
...Object.keys(headers).length ? { headers } : {}
|
|
2041
2073
|
};
|
|
2042
2074
|
}
|
|
2075
|
+
/** Renders the body of a media-upload mutationFn: call the endpoint (without the file arg) to
|
|
2076
|
+
* get upload instructions, then upload the file itself to the returned URL. Shared between
|
|
2077
|
+
* renderMutation (*.queries.ts) and renderMutationContent (*.configs.ts / builderConfigs) so
|
|
2078
|
+
* both mutation paths stay in sync. Lines are relative to the caller's own indent. */
|
|
2079
|
+
function renderMediaUploadMutationBody({ resolver, endpointFunction, resolvedEndpointArgs }) {
|
|
2080
|
+
return [
|
|
2081
|
+
`const uploadInstructions = await ${endpointFunction}(${resolvedEndpointArgs}${resolver.options.axiosRequestConfig ? `${resolvedEndpointArgs ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}` : ""});`,
|
|
2082
|
+
"",
|
|
2083
|
+
"if (file && uploadInstructions.url) {",
|
|
2084
|
+
` const method = (${BODY_PARAMETER_NAME}?.method?.toLowerCase() ?? "put") as "put" | "post";`,
|
|
2085
|
+
" let dataToSend: File | FormData = file;",
|
|
2086
|
+
" if (method === \"post\") {",
|
|
2087
|
+
" dataToSend = new FormData();",
|
|
2088
|
+
" if (uploadInstructions.fields) {",
|
|
2089
|
+
" for (const [key, value] of uploadInstructions.fields) {",
|
|
2090
|
+
" dataToSend.append(key, value);",
|
|
2091
|
+
" }",
|
|
2092
|
+
" }",
|
|
2093
|
+
" dataToSend.append(\"file\", file);",
|
|
2094
|
+
" }",
|
|
2095
|
+
" await axios[method](uploadInstructions.url, dataToSend, {",
|
|
2096
|
+
" headers: {",
|
|
2097
|
+
" \"Content-Type\": file.type,",
|
|
2098
|
+
" },",
|
|
2099
|
+
" signal: abortController?.signal,",
|
|
2100
|
+
" onUploadProgress: onUploadProgress",
|
|
2101
|
+
" ? (progressEvent) => onUploadProgress({ loaded: progressEvent.loaded, total: progressEvent.total ?? 0 })",
|
|
2102
|
+
" : undefined,",
|
|
2103
|
+
" });",
|
|
2104
|
+
"}",
|
|
2105
|
+
"",
|
|
2106
|
+
"return uploadInstructions;"
|
|
2107
|
+
];
|
|
2108
|
+
}
|
|
2043
2109
|
|
|
2044
2110
|
//#endregion
|
|
2045
2111
|
//#region src/generators/utils/query.utils.ts
|
|
@@ -2097,7 +2163,9 @@ function getEndpointAclConditionPropertyType({ resolver, endpoint, acl, name })
|
|
|
2097
2163
|
const matchingMediaType = Object.keys(bodyParameter?.bodyObject?.content ?? {}).find(isParamMediaTypeAllowed);
|
|
2098
2164
|
if (matchingMediaType) {
|
|
2099
2165
|
schema = bodyParameter?.bodyObject?.content?.[matchingMediaType]?.schema;
|
|
2166
|
+
required = bodyParameter?.bodyObject?.required;
|
|
2100
2167
|
info = `${isQuery(endpoint) ? "query" : "mutation"} data`;
|
|
2168
|
+
if (pathSplits[index]?.startsWith("$")) index++;
|
|
2101
2169
|
}
|
|
2102
2170
|
}
|
|
2103
2171
|
while (schema && index < pathSplits.length) {
|
|
@@ -2172,13 +2240,16 @@ function resolveEndpointZodSchema({ resolver, schema, meta, tag, fallbackName, c
|
|
|
2172
2240
|
fallbackName,
|
|
2173
2241
|
resolver,
|
|
2174
2242
|
tag
|
|
2175
|
-
}) :
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2243
|
+
}) : (() => {
|
|
2244
|
+
const name = resolveZodSchemaName({
|
|
2245
|
+
schema: schemaObject,
|
|
2246
|
+
zodSchema,
|
|
2247
|
+
fallbackName,
|
|
2248
|
+
resolver,
|
|
2249
|
+
tag
|
|
2250
|
+
});
|
|
2251
|
+
return isNamedZodSchema(name) ? name : name + zodChain;
|
|
2252
|
+
})();
|
|
2182
2253
|
entries.set(metaKey, resolved);
|
|
2183
2254
|
return resolved;
|
|
2184
2255
|
}
|
|
@@ -2229,9 +2300,9 @@ function getEndpointParameter({ resolver, param, operationName, isUniqueOperatio
|
|
|
2229
2300
|
if (resolver.options.withDescription && schema) schema.description = (paramObj.description ?? "").trim();
|
|
2230
2301
|
const fallbackName = getParamZodSchemaName(getZodSchemaOperationName(operationName, isUniqueOperationName, tag), paramObj.name);
|
|
2231
2302
|
let parameterSortingEnumSchemaName = void 0;
|
|
2232
|
-
if (isSortingParameterObject(paramObj)) {
|
|
2303
|
+
if (isSortingParameterObject(paramObj, schema, resolver)) {
|
|
2233
2304
|
const enumZodSchemaName = getEnumZodSchemaName(fallbackName, resolver.options.enumSuffix, resolver.options.schemaSuffix);
|
|
2234
|
-
const code = getEnumZodSchemaCodeFromEnumNames(paramObj[
|
|
2305
|
+
const code = getEnumZodSchemaCodeFromEnumNames(getParameterEnumNames(paramObj, schema) ?? []);
|
|
2235
2306
|
resolver.setZodSchema(enumZodSchemaName, code, tag);
|
|
2236
2307
|
parameterSortingEnumSchemaName = enumZodSchemaName;
|
|
2237
2308
|
}
|
|
@@ -2345,7 +2416,7 @@ function getEndpointsFromOpenAPIDoc(resolver) {
|
|
|
2345
2416
|
}) ?? mediaTypes.find(isMediaTypeAllowed);
|
|
2346
2417
|
let schema;
|
|
2347
2418
|
if (matchingMediaType) {
|
|
2348
|
-
endpoint.responseFormat = matchingMediaType;
|
|
2419
|
+
if (isMainResponseStatus(Number(statusCode)) || statusCode === "default" && !endpoint.responseFormat) endpoint.responseFormat = matchingMediaType;
|
|
2349
2420
|
schema = responseObj.content?.[matchingMediaType]?.schema;
|
|
2350
2421
|
} else if (statusCode === "200") resolver.validationErrors.push(getInvalidStatusCodeError({
|
|
2351
2422
|
received: "200",
|
|
@@ -2387,15 +2458,17 @@ function getEndpointsFromOpenAPIDoc(resolver) {
|
|
|
2387
2458
|
} else if (statusCode !== "default" && !Number.isNaN(status) && isErrorStatus(status)) {
|
|
2388
2459
|
const rawSchema = schemaObject;
|
|
2389
2460
|
const domainStr = rawSchema["x-domain-error-domain"];
|
|
2461
|
+
const domainName = rawSchema["x-domain-error-name"];
|
|
2390
2462
|
const codeEnumArr = ((rawSchema?.properties)?.code)?.enum;
|
|
2391
|
-
const domainCode = Array.isArray(codeEnumArr) && codeEnumArr.length === 1 && typeof codeEnumArr[0] === "number" ? codeEnumArr[0] : void 0;
|
|
2463
|
+
const domainCode = Array.isArray(codeEnumArr) && codeEnumArr.length === 1 && (typeof codeEnumArr[0] === "number" || typeof codeEnumArr[0] === "string") ? codeEnumArr[0] : void 0;
|
|
2392
2464
|
endpoint.errors.push({
|
|
2393
2465
|
zodSchema: responseZodSchema,
|
|
2394
2466
|
status,
|
|
2395
2467
|
description: responseObj?.description,
|
|
2396
2468
|
...typeof domainStr === "string" && domainCode !== void 0 ? { domainError: {
|
|
2397
2469
|
domain: domainStr,
|
|
2398
|
-
code: domainCode
|
|
2470
|
+
code: domainCode,
|
|
2471
|
+
...typeof domainName === "string" ? { name: domainName } : {}
|
|
2399
2472
|
} } : {}
|
|
2400
2473
|
});
|
|
2401
2474
|
}
|
|
@@ -3277,9 +3350,9 @@ function renderWorkspaceAclHook({ resolver, endpoint }) {
|
|
|
3277
3350
|
const objectRequired = abilityConditionsTypes.some((propertyType) => propertyType.required && !workspaceConditionNameSet.has(propertyType.name));
|
|
3278
3351
|
const objectParams = abilityConditionsTypes.map((propertyType) => {
|
|
3279
3352
|
const isWorkspaceCondition = workspaceConditionNameSet.has(propertyType.name);
|
|
3280
|
-
return `${propertyType.name}${propertyType.required && !isWorkspaceCondition ? "" : "?"}: ${(
|
|
3353
|
+
return `${propertyType.name}${propertyType.required && !isWorkspaceCondition ? "" : "?"}: ${renderConditionType(resolver, endpoint, propertyType)}, `;
|
|
3281
3354
|
}).join("");
|
|
3282
|
-
const contextType = abilityConditionsTypes.filter((propertyType) => workspaceConditionNameSet.has(propertyType.name)).map((propertyType) => `${propertyType.name}?: ${(
|
|
3355
|
+
const contextType = abilityConditionsTypes.filter((propertyType) => workspaceConditionNameSet.has(propertyType.name)).map((propertyType) => `${propertyType.name}?: ${renderConditionType(resolver, endpoint, propertyType)}`).join("; ");
|
|
3283
3356
|
const contextBindings = workspaceConditionNames.map((name) => `${name}: ${name}Workspace`).join(", ");
|
|
3284
3357
|
const lines = [];
|
|
3285
3358
|
lines.push(`export const use${capitalize(getAbilityFunctionName(endpoint))} = (`);
|
|
@@ -3305,15 +3378,15 @@ function renderAbilityFunction({ resolver, endpoint }) {
|
|
|
3305
3378
|
lines.push("/**");
|
|
3306
3379
|
lines.push(` * Use for ${abilityQuery} ability. ${hasConditions ? "For global ability, omit the object parameter." : ""}${getAbilityDescription(endpoint) ? "" : ""}`);
|
|
3307
3380
|
if (getAbilityDescription(endpoint)) lines.push(` * @description ${getAbilityDescription(endpoint)}`);
|
|
3308
|
-
if (hasConditions) for (const propertyType of abilityConditionsTypes) lines.push(` * @param { ${(
|
|
3381
|
+
if (hasConditions) for (const propertyType of abilityConditionsTypes) lines.push(` * @param { ${renderConditionType(resolver, endpoint, propertyType)} } object.${propertyType.name} ${propertyType.name} from ${propertyType.info}`);
|
|
3309
3382
|
lines.push(` * @returns { AbilityTuple } An ability tuple indicating the user's ability to use ${abilityQuery}`);
|
|
3310
3383
|
lines.push(" */");
|
|
3311
3384
|
lines.push(`export const ${getAbilityFunctionName(endpoint)} = (`);
|
|
3312
|
-
if (hasConditions) lines.push(` object?: { ${abilityConditionsTypes.map((propertyType) => `${propertyType.name}${propertyType.required ? "" : "?"}: ${(
|
|
3385
|
+
if (hasConditions) lines.push(` object?: { ${abilityConditionsTypes.map((propertyType) => `${propertyType.name}${propertyType.required ? "" : "?"}: ${renderConditionType(resolver, endpoint, propertyType)}, `).join("")} } `);
|
|
3313
3386
|
lines.push(") => [");
|
|
3314
3387
|
lines.push(` "${getAbilityAction(endpoint)}",`);
|
|
3315
3388
|
lines.push(` ${hasConditions ? `object ? subject("${getAbilitySubject(endpoint)}", object) : "${getAbilitySubject(endpoint)}"` : `"${getAbilitySubject(endpoint)}"`}`);
|
|
3316
|
-
lines.push(`] as ${CASL_ABILITY_BINDING.abilityTuple}<"${getAbilityAction(endpoint)}", ${getAbilitySubjectTypes(endpoint).join(" | ")}>;`);
|
|
3389
|
+
lines.push(`] as ${CASL_ABILITY_BINDING.abilityTuple}<"${getAbilityAction(endpoint)}", ${getAbilitySubjectTypes(endpoint, resolver, getEndpointTag(endpoint, resolver.options)).join(" | ")}>;`);
|
|
3317
3390
|
const workspaceAclHook = renderWorkspaceAclHook({
|
|
3318
3391
|
resolver,
|
|
3319
3392
|
endpoint
|
|
@@ -3324,6 +3397,9 @@ function renderAbilityFunction({ resolver, endpoint }) {
|
|
|
3324
3397
|
}
|
|
3325
3398
|
return lines.join("\n");
|
|
3326
3399
|
}
|
|
3400
|
+
function renderConditionType(resolver, endpoint, propertyType) {
|
|
3401
|
+
return getAbilityConditionType(propertyType, resolver, getEndpointTag(endpoint, resolver.options));
|
|
3402
|
+
}
|
|
3327
3403
|
|
|
3328
3404
|
//#endregion
|
|
3329
3405
|
//#region src/generators/const/buildConfigs.const.ts
|
|
@@ -3536,7 +3612,7 @@ function getColumnsConfig(resolver, endpoint) {
|
|
|
3536
3612
|
...acc,
|
|
3537
3613
|
[key]: true
|
|
3538
3614
|
}), {});
|
|
3539
|
-
const sortableEnumSchemaName = endpoint.parameters.find((param) => param.
|
|
3615
|
+
const sortableEnumSchemaName = endpoint.parameters.find((param) => param.parameterSortingEnumSchemaName)?.parameterSortingEnumSchemaName;
|
|
3540
3616
|
return {
|
|
3541
3617
|
columns: {
|
|
3542
3618
|
schema: getImportedZodSchemaName(resolver, zodSchema),
|
|
@@ -3579,7 +3655,7 @@ const QUERIES_MODULE_NAME = "moduleName";
|
|
|
3579
3655
|
//#endregion
|
|
3580
3656
|
//#region src/generators/generate/generateConfigs.ts
|
|
3581
3657
|
function generateConfigs(generateTypeParams) {
|
|
3582
|
-
const { configs, hasZodImport, modelsImports, aclImports } = getBuilderConfigs(generateTypeParams);
|
|
3658
|
+
const { configs, hasZodImport, modelsImports, queriesImports, aclImports } = getBuilderConfigs(generateTypeParams);
|
|
3583
3659
|
if (configs.length === 0) return;
|
|
3584
3660
|
const { resolver, tag } = generateTypeParams;
|
|
3585
3661
|
const endpoints = configs.flatMap((config) => [
|
|
@@ -3589,10 +3665,18 @@ function generateConfigs(generateTypeParams) {
|
|
|
3589
3665
|
config.bulkDelete?.mutation
|
|
3590
3666
|
]).filter((m) => typeof m !== "string" && m !== void 0);
|
|
3591
3667
|
const hasMutation = endpoints.length > 0;
|
|
3592
|
-
resolver.options.checkAcl && endpoints.some((e) => e.acl);
|
|
3668
|
+
const hasAclCheck = resolver.options.checkAcl && endpoints.some((e) => e.acl);
|
|
3593
3669
|
const hasMutationEffects = resolver.options.mutationEffects && hasMutation;
|
|
3594
3670
|
const hasMutationDefaultOnError = resolver.options.mutationDefaultOnError && hasMutation;
|
|
3595
|
-
const
|
|
3671
|
+
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
3672
|
+
const hasAxiosDefaultImport = endpoints.some((e) => e.mediaUpload);
|
|
3673
|
+
const hasAxiosImport = hasAxiosRequestConfig || hasAxiosDefaultImport;
|
|
3674
|
+
const axiosImport = {
|
|
3675
|
+
defaultImport: hasAxiosDefaultImport ? AXIOS_DEFAULT_IMPORT_NAME : void 0,
|
|
3676
|
+
bindings: [],
|
|
3677
|
+
typeBindings: hasAxiosImport ? [AXIOS_REQUEST_CONFIG_TYPE] : [],
|
|
3678
|
+
from: "axios"
|
|
3679
|
+
};
|
|
3596
3680
|
const endpointsImports = getEndpointsImports({
|
|
3597
3681
|
tag,
|
|
3598
3682
|
endpoints,
|
|
@@ -3620,10 +3704,6 @@ function generateConfigs(generateTypeParams) {
|
|
|
3620
3704
|
bindings: [ACL_CHECK_HOOK],
|
|
3621
3705
|
from: ACL_PACKAGE_IMPORT_PATH
|
|
3622
3706
|
};
|
|
3623
|
-
const workspaceContextImport = {
|
|
3624
|
-
bindings: ["OpenApiWorkspaceContext"],
|
|
3625
|
-
from: PACKAGE_IMPORT_PATH
|
|
3626
|
-
};
|
|
3627
3707
|
const hasDynamicInputsImport = configs.some((config) => config.readAll.filters || config.create?.inputDefs || config.update?.inputDefs);
|
|
3628
3708
|
const dynamicInputsImport = {
|
|
3629
3709
|
bindings: [BUILDERS_UTILS.dynamicInputs],
|
|
@@ -3635,10 +3715,12 @@ function generateConfigs(generateTypeParams) {
|
|
|
3635
3715
|
from: resolver.options.dynamicColumnsImportPath
|
|
3636
3716
|
};
|
|
3637
3717
|
const lines = [];
|
|
3718
|
+
if (hasAxiosImport) lines.push(renderImport$3(axiosImport));
|
|
3638
3719
|
if (hasZodImport) lines.push(renderImport$3(ZOD_IMPORT));
|
|
3639
3720
|
if (hasDynamicInputsImport) lines.push(renderImport$3(dynamicInputsImport));
|
|
3640
3721
|
if (hasDynamicColumnsImport) lines.push(renderImport$3(dynamicColumnsImport));
|
|
3641
3722
|
for (const modelsImport of modelsImports) lines.push(renderImport$3(modelsImport));
|
|
3723
|
+
for (const queriesImport of queriesImports) lines.push(renderImport$3(queriesImport));
|
|
3642
3724
|
for (const endpointsImport of endpointsImports) lines.push(renderImport$3(endpointsImport));
|
|
3643
3725
|
if (hasMutation) {
|
|
3644
3726
|
lines.push(renderImport$3(queryImport));
|
|
@@ -3647,8 +3729,7 @@ function generateConfigs(generateTypeParams) {
|
|
|
3647
3729
|
lines.push(renderImport$3(queryModulesImport));
|
|
3648
3730
|
lines.push(renderImport$3(mutationEffectsImport));
|
|
3649
3731
|
}
|
|
3650
|
-
lines.push(renderImport$3(aclCheckImport));
|
|
3651
|
-
if (hasWorkspaceContext) lines.push(renderImport$3(workspaceContextImport));
|
|
3732
|
+
if (hasAclCheck) lines.push(renderImport$3(aclCheckImport));
|
|
3652
3733
|
}
|
|
3653
3734
|
for (const aclImport of aclImports) lines.push(renderImport$3(aclImport));
|
|
3654
3735
|
lines.push("");
|
|
@@ -3706,32 +3787,34 @@ function renderMutationContent(resolver, endpoint, tag) {
|
|
|
3706
3787
|
});
|
|
3707
3788
|
const endpointParamsStr = endpointParams.map((p) => `${p.name}${p.required ? "" : "?"}: ${p.type}`).join("; ");
|
|
3708
3789
|
const destructuredMutationArgs = endpointParams.map((p) => p.name).join(", ");
|
|
3790
|
+
const resolvedEndpointArgs = mapEndpointParamsToFunctionParams(resolver, endpoint, { modelNamespaceTag: endpointTag }).map((p) => p.name).join(", ");
|
|
3709
3791
|
const endpointFunction = getImportedEndpointName(endpoint, resolver.options);
|
|
3710
3792
|
const mutationVariablesType = endpoint.mediaUpload ? `{ ${endpointParamsStr}${endpointParamsStr ? "; " : ""}abortController?: AbortController; onUploadProgress?: (progress: { loaded: number; total: number }) => void }` : `{ ${endpointParamsStr} }`;
|
|
3711
3793
|
const lines = [];
|
|
3712
|
-
lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasAxiosRequestConfig ? `, config?:
|
|
3794
|
+
lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasMutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, config?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
|
|
3713
3795
|
if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
3714
|
-
if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects
|
|
3715
|
-
lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
3796
|
+
if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects<${QUERY_MODULE_ENUM}.${endpointTag}>({ currentModule: ${QUERY_MODULE_ENUM}.${tag} });`);
|
|
3797
|
+
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
3716
3798
|
lines.push("");
|
|
3717
3799
|
lines.push(` return ${QUERY_HOOKS.mutation}({`);
|
|
3718
3800
|
const mutationFnArg = destructuredMutationArgs ? `{ ${destructuredMutationArgs}${endpoint.mediaUpload ? `${destructuredMutationArgs ? ", " : ""}abortController, onUploadProgress` : ""} }` : "";
|
|
3719
|
-
lines.push(` mutationFn: (${mutationFnArg}) => {`);
|
|
3720
|
-
if (hasAclCheck) lines.push(
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3801
|
+
lines.push(` mutationFn: ${endpoint.mediaUpload ? "async " : ""}(${mutationFnArg}) => {`);
|
|
3802
|
+
if (hasAclCheck) lines.push(renderAclCheckCall(resolver, endpoint, void 0, " "));
|
|
3803
|
+
if (endpoint.mediaUpload) lines.push(...renderMediaUploadMutationBody({
|
|
3804
|
+
resolver,
|
|
3805
|
+
endpointFunction,
|
|
3806
|
+
resolvedEndpointArgs
|
|
3807
|
+
}).map((line) => ` ${line}`));
|
|
3808
|
+
else lines.push(` return ${endpointFunction}(${destructuredMutationArgs}${hasAxiosRequestConfig ? `${destructuredMutationArgs ? ", " : ""}config` : ""});`);
|
|
3726
3809
|
lines.push(" },");
|
|
3810
|
+
lines.push(" ...options,");
|
|
3811
|
+
if (hasMutationDefaultOnError) lines.push(" onError: options?.onError ?? queryConfig.onError,");
|
|
3727
3812
|
if (hasMutationEffects) {
|
|
3728
|
-
lines.push(" onSuccess: async (
|
|
3729
|
-
lines.push(" await runMutationEffects();");
|
|
3730
|
-
lines.push("
|
|
3813
|
+
lines.push(" onSuccess: async (resData, variables, onMutateResult, context) => {");
|
|
3814
|
+
lines.push(" await runMutationEffects(resData, variables, options);");
|
|
3815
|
+
lines.push(" options?.onSuccess?.(resData, variables, onMutateResult, context);");
|
|
3731
3816
|
lines.push(" },");
|
|
3732
3817
|
}
|
|
3733
|
-
lines.push(" ...options,");
|
|
3734
|
-
if (hasMutationDefaultOnError) lines.push(" onError: options?.onError ?? queryConfig.onError,");
|
|
3735
3818
|
lines.push(" });");
|
|
3736
3819
|
lines.push("}");
|
|
3737
3820
|
return lines.map((line) => " " + line).join("\n").trimStart();
|
|
@@ -3808,10 +3891,11 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
3808
3891
|
from: getAppRestClientImportPath(resolver.options)
|
|
3809
3892
|
};
|
|
3810
3893
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
3811
|
-
const
|
|
3894
|
+
const hasGetEndpoints = endpoints.some((endpoint) => endpoint.method === "get");
|
|
3895
|
+
const hasAxiosImport = hasAxiosRequestConfig || hasGetEndpoints;
|
|
3812
3896
|
const axiosImport = {
|
|
3813
3897
|
bindings: [],
|
|
3814
|
-
typeBindings:
|
|
3898
|
+
typeBindings: hasAxiosImport ? [AXIOS_REQUEST_CONFIG_TYPE] : [],
|
|
3815
3899
|
from: AXIOS_IMPORT.from
|
|
3816
3900
|
};
|
|
3817
3901
|
const generateParse = resolver.options.parseRequestParams;
|
|
@@ -3849,9 +3933,10 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
3849
3933
|
const endpointBody = getEndpointBody$1(endpoint);
|
|
3850
3934
|
const hasUndefinedEndpointBody = requiresBody(endpoint) && !endpointBody && hasEndpointConfig(endpoint, resolver);
|
|
3851
3935
|
const endpointConfig = renderEndpointConfig(resolver, endpoint, tag);
|
|
3852
|
-
|
|
3936
|
+
const hasRequestConfigParam = hasAxiosRequestConfig || endpoint.method === "get";
|
|
3937
|
+
lines.push(`export const ${getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType$1()}` : ""}) => {`);
|
|
3853
3938
|
lines.push(` return ${APP_REST_CLIENT_NAME}.${endpoint.method}(`);
|
|
3854
|
-
lines.push(`
|
|
3939
|
+
lines.push(` ${renderRequestInfo(resolver, endpoint, tag)},`);
|
|
3855
3940
|
lines.push(` \`${getEndpointPath(endpoint)}\`,`);
|
|
3856
3941
|
if (endpointBody) lines.push(` ${generateParse ? renderEndpointParamParse(resolver, endpointBody, endpointBody.name, tag) : endpointBody.name},`);
|
|
3857
3942
|
else if (hasUndefinedEndpointBody) lines.push(" undefined,");
|
|
@@ -3862,6 +3947,12 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
3862
3947
|
if (resolver.options.tsNamespaces) lines.push("}");
|
|
3863
3948
|
return lines.join("\n").trimEnd() + "\n";
|
|
3864
3949
|
}
|
|
3950
|
+
function renderRequestInfo(resolver, endpoint, tag) {
|
|
3951
|
+
return `{ resSchema: ${getImportedZodSchemaName(resolver, endpoint.response, resolver.options.modelsInCommon && resolver.options.splitByTags ? tag : void 0)} }`;
|
|
3952
|
+
}
|
|
3953
|
+
function getRequestConfigType$1() {
|
|
3954
|
+
return `${AXIOS_REQUEST_CONFIG_TYPE} & { allowInvalidResponseData?: boolean }`;
|
|
3955
|
+
}
|
|
3865
3956
|
function renderImport$2(importData) {
|
|
3866
3957
|
const namedImports = [...importData.bindings, ...(importData.typeBindings ?? []).map((binding) => importData.typeOnly ? binding : `type ${binding}`)];
|
|
3867
3958
|
const names = [...importData.defaultImport ? [importData.defaultImport] : [], ...namedImports.length > 0 ? [`{ ${namedImports.join(", ")} }`] : []].join(", ");
|
|
@@ -3875,17 +3966,24 @@ function renderEndpointArgs$1(resolver, endpoint, options) {
|
|
|
3875
3966
|
}
|
|
3876
3967
|
function renderEndpointParamParse(resolver, param, paramName, modelNamespaceTag) {
|
|
3877
3968
|
const addOptional = !(param.parameterObject ?? param.bodyObject)?.required && (Boolean(param.parameterSortingEnumSchemaName) || isNamedZodSchema(param.zodSchema));
|
|
3878
|
-
const schemaValue = param.parameterSortingEnumSchemaName ? `${ZOD_EXTENDED.namespace}.${ZOD_EXTENDED.exports.sortExp}(${getImportedZodSchemaName(resolver, param.parameterSortingEnumSchemaName, modelNamespaceTag)})${
|
|
3969
|
+
const schemaValue = param.parameterSortingEnumSchemaName ? `${ZOD_EXTENDED.namespace}.${ZOD_EXTENDED.exports.sortExp}(${getImportedZodSchemaName(resolver, param.parameterSortingEnumSchemaName, modelNamespaceTag)})${getSortingPresenceChain$1(resolver, param)}` : `${getImportedZodSchemaName(resolver, param.zodSchema, modelNamespaceTag)}${addOptional ? ".optional()" : ""}`;
|
|
3879
3970
|
const queryArgs = param.type === "Query" ? `, { type: "query", name: "${paramName}" }` : "";
|
|
3880
3971
|
return `${ZOD_EXTENDED.namespace}.${ZOD_EXTENDED.exports.parse}(${schemaValue}, ${paramName}${queryArgs})`;
|
|
3881
3972
|
}
|
|
3973
|
+
function getSortingPresenceChain$1(resolver, param) {
|
|
3974
|
+
const zodSchemaCode = resolver.getCodeByZodSchemaName(param.zodSchema) ?? param.zodSchema;
|
|
3975
|
+
if (zodSchemaCode.includes(".nullish()")) return ".nullish()";
|
|
3976
|
+
if (zodSchemaCode.includes(".nullable()")) return ".nullable()";
|
|
3977
|
+
return !(param.parameterObject ?? param.bodyObject)?.required ? ".optional()" : "";
|
|
3978
|
+
}
|
|
3882
3979
|
function renderEndpointConfig(resolver, endpoint, modelNamespaceTag) {
|
|
3883
3980
|
const endpointConfig = getEndpointConfig(endpoint);
|
|
3884
|
-
const
|
|
3885
|
-
|
|
3981
|
+
const hasRequestConfigParam = resolver.options.axiosRequestConfig || endpoint.method === "get";
|
|
3982
|
+
const needsBlobConfig = endpoint.mediaDownload || endpoint.response === "z.instanceof(Blob)";
|
|
3983
|
+
if (Object.keys(endpointConfig).length === 0 && !needsBlobConfig) return hasRequestConfigParam ? AXIOS_REQUEST_CONFIG_NAME : "";
|
|
3886
3984
|
const lines = [];
|
|
3887
3985
|
lines.push("{");
|
|
3888
|
-
if (
|
|
3986
|
+
if (hasRequestConfigParam) lines.push(` ...${AXIOS_REQUEST_CONFIG_NAME},`);
|
|
3889
3987
|
if (endpointConfig.params) {
|
|
3890
3988
|
lines.push(" params: {");
|
|
3891
3989
|
for (const param of endpointConfig.params) {
|
|
@@ -4060,11 +4158,12 @@ function generateQueries(params) {
|
|
|
4060
4158
|
const endpointGroups = groupEndpoints(endpoints, resolver);
|
|
4061
4159
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
4062
4160
|
const hasAxiosDefaultImport = endpoints.some(({ mediaUpload }) => mediaUpload);
|
|
4063
|
-
const
|
|
4161
|
+
const hasGetEndpoints = endpoints.some((endpoint) => endpoint.method === "get");
|
|
4162
|
+
const hasAxiosImport = hasAxiosRequestConfig || hasAxiosDefaultImport || hasGetEndpoints;
|
|
4064
4163
|
const axiosImport = {
|
|
4065
4164
|
defaultImport: hasAxiosDefaultImport ? AXIOS_DEFAULT_IMPORT_NAME : void 0,
|
|
4066
4165
|
bindings: [],
|
|
4067
|
-
typeBindings:
|
|
4166
|
+
typeBindings: hasAxiosImport ? [AXIOS_REQUEST_CONFIG_TYPE] : [],
|
|
4068
4167
|
from: AXIOS_IMPORT.from
|
|
4069
4168
|
};
|
|
4070
4169
|
const { queryEndpoints, infiniteQueryEndpoints, mutationEndpoints, aclEndpoints } = endpointGroups;
|
|
@@ -4095,7 +4194,7 @@ function generateQueries(params) {
|
|
|
4095
4194
|
from: ACL_PACKAGE_IMPORT_PATH
|
|
4096
4195
|
};
|
|
4097
4196
|
const queryTypesImport = {
|
|
4098
|
-
bindings: [...hasMutationDefaultOnError ? ["OpenApiQueryConfig"] : []],
|
|
4197
|
+
bindings: [...queryEndpoints.length > 0 || infiniteQueryEndpoints.length > 0 || hasMutationDefaultOnError ? ["OpenApiQueryConfig"] : []],
|
|
4099
4198
|
typeBindings: [
|
|
4100
4199
|
...queryEndpoints.length > 0 ? [QUERY_OPTIONS_TYPES.query] : [],
|
|
4101
4200
|
...resolver.options.infiniteQueries && infiniteQueryEndpoints.length > 0 ? [QUERY_OPTIONS_TYPES.infiniteQuery] : [],
|
|
@@ -4334,16 +4433,6 @@ function renderWorkspaceParamResolutions({ replacements, paramTypes, indent }) {
|
|
|
4334
4433
|
indent
|
|
4335
4434
|
})];
|
|
4336
4435
|
}
|
|
4337
|
-
function renderAclCheckCall(resolver, endpoint, replacements, indent = "") {
|
|
4338
|
-
const checkParams = getAbilityConditionsTypes(endpoint)?.map((condition) => invalidVariableNameCharactersToCamel(condition.name));
|
|
4339
|
-
const paramNames = new Set(endpoint.parameters.map((param) => invalidVariableNameCharactersToCamel(param.name)));
|
|
4340
|
-
const hasAllCheckParams = checkParams?.every((param) => paramNames.has(param));
|
|
4341
|
-
const args = hasAbilityConditions(endpoint) && hasAllCheckParams ? `{ ${(checkParams ?? []).map((param) => {
|
|
4342
|
-
const resolvedParam = replacements?.[param] ?? param;
|
|
4343
|
-
return resolvedParam === param ? param : `${param}: ${resolvedParam}`;
|
|
4344
|
-
}).join(", ")} } ` : "";
|
|
4345
|
-
return `${indent}checkAcl(${getImportedAbilityFunctionName(endpoint, resolver.options)}(${args}));`;
|
|
4346
|
-
}
|
|
4347
4436
|
function addAsteriskAfterNewLine(str) {
|
|
4348
4437
|
return str.replace(/\n/g, "\n *");
|
|
4349
4438
|
}
|
|
@@ -4398,9 +4487,10 @@ function renderInlineEndpoints({ resolver, endpoints, tag }) {
|
|
|
4398
4487
|
const endpointBody = getEndpointBody$1(endpoint);
|
|
4399
4488
|
const hasUndefinedEndpointBody = requiresBody(endpoint) && !endpointBody && hasEndpointConfig(endpoint, resolver);
|
|
4400
4489
|
const endpointConfig = renderInlineEndpointConfig(resolver, endpoint, tag);
|
|
4401
|
-
|
|
4490
|
+
const hasRequestConfigParam = resolver.options.axiosRequestConfig || endpoint.method === "get";
|
|
4491
|
+
lines.push(`const ${getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType()}` : ""}) => {`);
|
|
4402
4492
|
lines.push(` return ${APP_REST_CLIENT_NAME}.${endpoint.method}(`);
|
|
4403
|
-
lines.push(`
|
|
4493
|
+
lines.push(` ${renderInlineRequestInfo(resolver, endpoint, tag)},`);
|
|
4404
4494
|
lines.push(` \`${getEndpointPath(endpoint)}\`,`);
|
|
4405
4495
|
if (endpointBody) lines.push(` ${resolver.options.parseRequestParams ? renderInlineEndpointParamParse(resolver, endpointBody, endpointBody.name, tag) : endpointBody.name},`);
|
|
4406
4496
|
else if (hasUndefinedEndpointBody) lines.push(" undefined,");
|
|
@@ -4411,19 +4501,32 @@ function renderInlineEndpoints({ resolver, endpoints, tag }) {
|
|
|
4411
4501
|
}
|
|
4412
4502
|
return lines;
|
|
4413
4503
|
}
|
|
4504
|
+
function renderInlineRequestInfo(resolver, endpoint, tag) {
|
|
4505
|
+
return `{ resSchema: ${getImportedZodSchemaName(resolver, endpoint.response, tag)} }`;
|
|
4506
|
+
}
|
|
4507
|
+
function getRequestConfigType() {
|
|
4508
|
+
return `${AXIOS_REQUEST_CONFIG_TYPE} & { allowInvalidResponseData?: boolean }`;
|
|
4509
|
+
}
|
|
4414
4510
|
function renderInlineEndpointParamParse(resolver, param, paramName, modelNamespaceTag) {
|
|
4415
4511
|
const addOptional = !(param.parameterObject ?? param.bodyObject)?.required && (Boolean(param.parameterSortingEnumSchemaName) || isNamedZodSchema(param.zodSchema));
|
|
4416
|
-
const schemaValue = param.parameterSortingEnumSchemaName ? `${ZOD_EXTENDED.namespace}.${ZOD_EXTENDED.exports.sortExp}(${getImportedZodSchemaName(resolver, param.parameterSortingEnumSchemaName, modelNamespaceTag)})${
|
|
4512
|
+
const schemaValue = param.parameterSortingEnumSchemaName ? `${ZOD_EXTENDED.namespace}.${ZOD_EXTENDED.exports.sortExp}(${getImportedZodSchemaName(resolver, param.parameterSortingEnumSchemaName, modelNamespaceTag)})${getSortingPresenceChain(resolver, param)}` : `${getImportedZodSchemaName(resolver, param.zodSchema, modelNamespaceTag)}${addOptional ? ".optional()" : ""}`;
|
|
4417
4513
|
const queryArgs = param.type === "Query" ? `, { type: "query", name: "${paramName}" }` : "";
|
|
4418
4514
|
return `${ZOD_EXTENDED.namespace}.${ZOD_EXTENDED.exports.parse}(${schemaValue}, ${paramName}${queryArgs})`;
|
|
4419
4515
|
}
|
|
4516
|
+
function getSortingPresenceChain(resolver, param) {
|
|
4517
|
+
const zodSchemaCode = resolver.getCodeByZodSchemaName(param.zodSchema) ?? param.zodSchema;
|
|
4518
|
+
if (zodSchemaCode.includes(".nullish()")) return ".nullish()";
|
|
4519
|
+
if (zodSchemaCode.includes(".nullable()")) return ".nullable()";
|
|
4520
|
+
return !(param.parameterObject ?? param.bodyObject)?.required ? ".optional()" : "";
|
|
4521
|
+
}
|
|
4420
4522
|
function renderInlineEndpointConfig(resolver, endpoint, modelNamespaceTag) {
|
|
4421
4523
|
const endpointConfig = getEndpointConfig(endpoint);
|
|
4422
|
-
const
|
|
4423
|
-
|
|
4524
|
+
const hasRequestConfigParam = resolver.options.axiosRequestConfig || endpoint.method === "get";
|
|
4525
|
+
const needsBlobConfig = endpoint.mediaDownload || endpoint.response === "z.instanceof(Blob)";
|
|
4526
|
+
if (Object.keys(endpointConfig).length === 0 && !needsBlobConfig) return hasRequestConfigParam ? AXIOS_REQUEST_CONFIG_NAME : "";
|
|
4424
4527
|
const lines = [];
|
|
4425
4528
|
lines.push("{");
|
|
4426
|
-
if (
|
|
4529
|
+
if (hasRequestConfigParam) lines.push(` ...${AXIOS_REQUEST_CONFIG_NAME},`);
|
|
4427
4530
|
if (endpointConfig.params) {
|
|
4428
4531
|
lines.push(" params: {");
|
|
4429
4532
|
for (const param of endpointConfig.params) {
|
|
@@ -4443,19 +4546,19 @@ function renderInlineEndpointConfig(resolver, endpoint, modelNamespaceTag) {
|
|
|
4443
4546
|
return lines.join("\n");
|
|
4444
4547
|
}
|
|
4445
4548
|
function renderQueryOptions({ resolver, endpoint, inlineEndpoints }) {
|
|
4446
|
-
const
|
|
4549
|
+
const hasRequestConfigParam = resolver.options.axiosRequestConfig || endpoint.method === "get";
|
|
4447
4550
|
const endpointParams = renderEndpointParams(resolver, endpoint, { modelNamespaceTag: getEndpointTag(endpoint, resolver.options) });
|
|
4448
4551
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, {});
|
|
4449
4552
|
const endpointFunction = inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options);
|
|
4450
4553
|
const lines = [];
|
|
4451
|
-
lines.push(`const ${getQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }` : ""}${
|
|
4554
|
+
lines.push(`const ${getQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType()}` : ""}) => ({`);
|
|
4452
4555
|
lines.push(` queryKey: keys.${getEndpointName(endpoint)}(${endpointArgs}),`);
|
|
4453
|
-
lines.push(` queryFn: () => ${endpointFunction}(${endpointArgs}${
|
|
4556
|
+
lines.push(` queryFn: () => ${endpointFunction}(${endpointArgs}${hasRequestConfigParam ? `${endpointArgs ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}` : ""}),`);
|
|
4454
4557
|
lines.push("});");
|
|
4455
4558
|
return lines.join("\n");
|
|
4456
4559
|
}
|
|
4457
4560
|
function renderInfiniteQueryOptions({ resolver, endpoint, inlineEndpoints }) {
|
|
4458
|
-
const
|
|
4561
|
+
const hasRequestConfigParam = resolver.options.axiosRequestConfig || endpoint.method === "get";
|
|
4459
4562
|
const endpointParams = renderEndpointParams(resolver, endpoint, {
|
|
4460
4563
|
excludePageParam: true,
|
|
4461
4564
|
modelNamespaceTag: getEndpointTag(endpoint, resolver.options)
|
|
@@ -4464,13 +4567,13 @@ function renderInfiniteQueryOptions({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4464
4567
|
const endpointArgsWithPage = renderEndpointArgs(resolver, endpoint, { replacePageParam: true });
|
|
4465
4568
|
const endpointFunction = inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options);
|
|
4466
4569
|
const lines = [];
|
|
4467
|
-
lines.push(`const ${getInfiniteQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }` : ""}${
|
|
4570
|
+
lines.push(`const ${getInfiniteQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType()}` : ""}) => ({`);
|
|
4468
4571
|
lines.push(` queryKey: keys.${getEndpointName(endpoint)}Infinite(${endpointArgsWithoutPage}),`);
|
|
4469
|
-
lines.push(` queryFn: ({ pageParam }: { pageParam: number }) => ${endpointFunction}(${endpointArgsWithPage}${
|
|
4572
|
+
lines.push(` queryFn: ({ pageParam }: { pageParam: number }) => ${endpointFunction}(${endpointArgsWithPage}${hasRequestConfigParam ? `, ${AXIOS_REQUEST_CONFIG_NAME}` : ""}),`);
|
|
4470
4573
|
lines.push(" initialPageParam: 1,");
|
|
4471
4574
|
lines.push(` getNextPageParam: ({ ${resolver.options.infiniteQueryResponseParamNames.page}, ${resolver.options.infiniteQueryResponseParamNames.totalItems}, ${resolver.options.infiniteQueryResponseParamNames.limit}: limitParam }: Awaited<ReturnType<typeof ${endpointFunction}>>) => {`);
|
|
4472
4575
|
lines.push(` const pageParam = ${resolver.options.infiniteQueryResponseParamNames.page} ?? 1;`);
|
|
4473
|
-
lines.push(` return pageParam * limitParam < ${resolver.options.infiniteQueryResponseParamNames.totalItems} ? pageParam + 1 : null;`);
|
|
4576
|
+
lines.push(` return pageParam * limitParam < (${resolver.options.infiniteQueryResponseParamNames.totalItems} ?? 0) ? pageParam + 1 : null;`);
|
|
4474
4577
|
lines.push(" },");
|
|
4475
4578
|
lines.push("});");
|
|
4476
4579
|
return lines.join("\n");
|
|
@@ -4513,7 +4616,8 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4513
4616
|
});
|
|
4514
4617
|
const queryOptionsName = getQueryOptionsName(endpoint);
|
|
4515
4618
|
const hasQueryFnOverride = hasAclCheck;
|
|
4516
|
-
const
|
|
4619
|
+
const requestConfig = `{ ${hasAxiosRequestConfig ? `...${AXIOS_REQUEST_CONFIG_NAME}, ` : ""}allowInvalidResponseData: queryConfig.allowInvalidResponseData }`;
|
|
4620
|
+
const queryOptionsArgs = `${resolvedEndpointArgs ? `{ ${resolvedEndpointArgs} }, ` : ""}${requestConfig}`;
|
|
4517
4621
|
const lines = [];
|
|
4518
4622
|
lines.push(renderQueryJsDocs({
|
|
4519
4623
|
resolver,
|
|
@@ -4522,6 +4626,7 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4522
4626
|
tag
|
|
4523
4627
|
}));
|
|
4524
4628
|
lines.push(`export const ${getQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: AppQueryOptions<typeof ${inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options)}, TData>${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
|
|
4629
|
+
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
4525
4630
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
4526
4631
|
lines.push(...renderWorkspaceParamResolutions({
|
|
4527
4632
|
replacements: workspaceParamReplacements,
|
|
@@ -4614,34 +4719,12 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
4614
4719
|
indent: " "
|
|
4615
4720
|
}));
|
|
4616
4721
|
if (hasAclCheck) lines.push(renderAclCheckCall(resolver, endpoint, workspaceParamReplacements, " "));
|
|
4617
|
-
if (endpoint.mediaUpload) {
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
lines.push(" if (method === \"post\") {");
|
|
4624
|
-
lines.push(" dataToSend = new FormData();");
|
|
4625
|
-
lines.push(" if (uploadInstructions.fields) {");
|
|
4626
|
-
lines.push(" for (const [key, value] of uploadInstructions.fields) {");
|
|
4627
|
-
lines.push(" dataToSend.append(key, value);");
|
|
4628
|
-
lines.push(" }");
|
|
4629
|
-
lines.push(" }");
|
|
4630
|
-
lines.push(" dataToSend.append(\"file\", file);");
|
|
4631
|
-
lines.push(" }");
|
|
4632
|
-
lines.push(" await axios[method](uploadInstructions.url, dataToSend, {");
|
|
4633
|
-
lines.push(" headers: {");
|
|
4634
|
-
lines.push(" \"Content-Type\": file.type,");
|
|
4635
|
-
lines.push(" },");
|
|
4636
|
-
lines.push(" signal: abortController?.signal,");
|
|
4637
|
-
lines.push(" onUploadProgress: onUploadProgress");
|
|
4638
|
-
lines.push(" ? (progressEvent) => onUploadProgress({ loaded: progressEvent.loaded, total: progressEvent.total ?? 0 })");
|
|
4639
|
-
lines.push(" : undefined,");
|
|
4640
|
-
lines.push(" });");
|
|
4641
|
-
lines.push(" }");
|
|
4642
|
-
lines.push(" ");
|
|
4643
|
-
lines.push(" return uploadInstructions;");
|
|
4644
|
-
} else lines.push(` ${hasMutationFnBody ? "return " : ""}${endpointFunction}(${resolvedEndpointArgs}${hasAxiosRequestConfig ? `${resolvedEndpointArgs ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}` : ""})`);
|
|
4722
|
+
if (endpoint.mediaUpload) lines.push(...renderMediaUploadMutationBody({
|
|
4723
|
+
resolver,
|
|
4724
|
+
endpointFunction,
|
|
4725
|
+
resolvedEndpointArgs
|
|
4726
|
+
}).map((line) => ` ${line}`));
|
|
4727
|
+
else lines.push(` ${hasMutationFnBody ? "return " : ""}${endpointFunction}(${resolvedEndpointArgs}${hasAxiosRequestConfig ? `${resolvedEndpointArgs ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}` : ""})`);
|
|
4645
4728
|
if (hasMutationFnBody) lines.push(" },");
|
|
4646
4729
|
else lines.push(",");
|
|
4647
4730
|
if (isScoped) {
|
|
@@ -4721,7 +4804,8 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4721
4804
|
const endpointArgsWithoutPage = renderEndpointArgs(resolver, endpoint, { excludePageParam: true });
|
|
4722
4805
|
const resolvedEndpointArgsWithoutPage = renderEndpointObjectArgs(resolver, endpoint, { excludePageParam: true }, workspaceParamReplacements);
|
|
4723
4806
|
const queryOptionsName = getInfiniteQueryOptionsName(endpoint);
|
|
4724
|
-
const
|
|
4807
|
+
const requestConfig = `{ ${hasAxiosRequestConfig ? `...${AXIOS_REQUEST_CONFIG_NAME}, ` : ""}allowInvalidResponseData: queryConfig.allowInvalidResponseData }`;
|
|
4808
|
+
const queryOptionsArgs = `${resolvedEndpointArgsWithoutPage ? `{ ${resolvedEndpointArgsWithoutPage} }, ` : ""}${requestConfig}`;
|
|
4725
4809
|
const hasQueryFnOverride = hasAclCheck;
|
|
4726
4810
|
const lines = [];
|
|
4727
4811
|
lines.push(renderQueryJsDocs({
|
|
@@ -4731,6 +4815,7 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4731
4815
|
tag
|
|
4732
4816
|
}));
|
|
4733
4817
|
lines.push(`export const ${getInfiniteQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }, ` : ""}options?: AppInfiniteQueryOptions<typeof ${inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options)}, TData>${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
|
|
4818
|
+
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
4734
4819
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
4735
4820
|
lines.push(...renderWorkspaceParamResolutions({
|
|
4736
4821
|
replacements: workspaceParamReplacements,
|
|
@@ -4770,6 +4855,7 @@ export const ${APP_REST_CLIENT_NAME} = new RestClient({
|
|
|
4770
4855
|
function domainToPascalCase(domain) {
|
|
4771
4856
|
return domain.split(/[-_]/).map(capitalize).join("");
|
|
4772
4857
|
}
|
|
4858
|
+
const VALID_IDENTIFIER = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
4773
4859
|
function generateDomainErrors({ data }) {
|
|
4774
4860
|
const byDomain = /* @__PURE__ */ new Map();
|
|
4775
4861
|
for (const { endpoints } of data.values()) for (const endpoint of endpoints) for (const error of endpoint.errors) {
|
|
@@ -4779,6 +4865,7 @@ function generateDomainErrors({ data }) {
|
|
|
4779
4865
|
const domainMap = byDomain.get(domain);
|
|
4780
4866
|
if (!domainMap.has(code)) domainMap.set(code, {
|
|
4781
4867
|
code,
|
|
4868
|
+
name: error.domainError.name,
|
|
4782
4869
|
description: error.description
|
|
4783
4870
|
});
|
|
4784
4871
|
}
|
|
@@ -4786,8 +4873,16 @@ function generateDomainErrors({ data }) {
|
|
|
4786
4873
|
const blocks = [];
|
|
4787
4874
|
for (const [domain, codes] of [...byDomain.entries()].sort(([a], [b]) => a.localeCompare(b))) {
|
|
4788
4875
|
const pascalName = domainToPascalCase(domain);
|
|
4789
|
-
const entries = [...codes.values()].sort((a, b) =>
|
|
4790
|
-
|
|
4876
|
+
const entries = [...codes.values()].sort((a, b) => {
|
|
4877
|
+
if (typeof a.code === "number" && typeof b.code === "number") return a.code - b.code;
|
|
4878
|
+
const sa = String(a.code);
|
|
4879
|
+
const sb = String(b.code);
|
|
4880
|
+
return sa < sb ? -1 : sa > sb ? 1 : 0;
|
|
4881
|
+
}).map(({ code, name, description }) => {
|
|
4882
|
+
const comment = description ? ` /** ${description} */\n ` : " ";
|
|
4883
|
+
const key = name ?? (typeof code === "string" ? code : `ERROR_${code}`);
|
|
4884
|
+
if (!VALID_IDENTIFIER.test(key)) throw new Error(`Domain error code "${code}" produces an invalid identifier "${key}". Use the 'name' field on @ApiDomainErrorResponse to provide a valid identifier.`);
|
|
4885
|
+
return `${comment}${key}: ${typeof code === "string" ? `"${code}"` : String(code)}`;
|
|
4791
4886
|
}).join(",\n");
|
|
4792
4887
|
blocks.push(`export const ${pascalName}DomainErrors = {\n${entries},\n} as const;`);
|
|
4793
4888
|
blocks.push(`export type ${pascalName}DomainErrorCode = (typeof ${pascalName}DomainErrors)[keyof typeof ${pascalName}DomainErrors];`);
|