@povio/openapi-codegen-cli 2.0.8-rc.16 → 2.0.8-rc.18
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/acl.d.mts +12 -1
- package/dist/acl.mjs +13 -3
- package/dist/auth.context-HV1I5QMx.mjs +244 -0
- package/dist/{config-Cu_GYfai.d.mts → config-B4HK4BLi.d.mts} +1 -1
- package/dist/error-handling-p69GkKGP.d.mts +38 -0
- package/dist/{generate.runner-DF2eZ4P-.mjs → generate.runner-C93djZ78.mjs} +1 -1
- package/dist/{generateCodeFromOpenAPIDoc-ao1R1u57.mjs → generateCodeFromOpenAPIDoc-BP7F6YJP.mjs} +46 -214
- package/dist/generator.d.mts +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/index.d.mts +43 -59
- package/dist/index.mjs +74 -189
- package/dist/sh.mjs +3 -3
- package/dist/vite.d.mts +2 -2
- package/dist/vite.mjs +2 -2
- package/package.json +5 -1
- package/dist/auth.context-DKjzWiaA.mjs +0 -59
- package/src/assets/useCrossTabQueryInvalidation.ts +0 -40
- package/src/assets/useMutationEffects.ts +0 -94
- /package/dist/{options-DBz5YE3s.d.mts → options-Bvmh6rai.d.mts} +0 -0
package/dist/{generateCodeFromOpenAPIDoc-ao1R1u57.mjs → generateCodeFromOpenAPIDoc-BP7F6YJP.mjs}
RENAMED
|
@@ -2,7 +2,6 @@ import fs from "fs";
|
|
|
2
2
|
import { match } from "ts-pattern";
|
|
3
3
|
import { OpenAPIV3 } from "openapi-types";
|
|
4
4
|
import path from "path";
|
|
5
|
-
import { fileURLToPath } from "url";
|
|
6
5
|
|
|
7
6
|
//#region src/generators/const/validation.const.ts
|
|
8
7
|
const HTTP_STATUS_CODES = {
|
|
@@ -466,6 +465,7 @@ function groupByType(validationErrors) {
|
|
|
466
465
|
//#region src/generators/const/package.const.ts
|
|
467
466
|
const PACKAGE_IMPORT_PATH = "@povio/openapi-codegen-cli";
|
|
468
467
|
const ACL_PACKAGE_IMPORT_PATH = "@povio/openapi-codegen-cli/acl";
|
|
468
|
+
const ZOD_PACKAGE_IMPORT_PATH = "@povio/openapi-codegen-cli/zod";
|
|
469
469
|
|
|
470
470
|
//#endregion
|
|
471
471
|
//#region src/generators/const/deps.const.ts
|
|
@@ -488,11 +488,6 @@ const ERROR_HANDLING_IMPORT = {
|
|
|
488
488
|
bindings: [ERROR_HANDLERS.ErrorHandler, ERROR_HANDLERS.SharedErrorHandler],
|
|
489
489
|
from: PACKAGE_IMPORT_PATH
|
|
490
490
|
};
|
|
491
|
-
const ABILITY_CONTEXT = "AbilityContext";
|
|
492
|
-
const ABILITY_CONTEXT_IMPORT = {
|
|
493
|
-
bindings: [ABILITY_CONTEXT],
|
|
494
|
-
from: ACL_PACKAGE_IMPORT_PATH
|
|
495
|
-
};
|
|
496
491
|
const BUILDERS_UTILS = {
|
|
497
492
|
dynamicInputs: "dynamicInputs",
|
|
498
493
|
dynamicColumns: "dynamicColumns"
|
|
@@ -507,14 +502,6 @@ const MUTATION_EFFECTS = {
|
|
|
507
502
|
hookName: "useMutationEffects",
|
|
508
503
|
runFunctionName: "runMutationEffects"
|
|
509
504
|
};
|
|
510
|
-
const MUTATION_EFFECTS_FILE = {
|
|
511
|
-
fileName: "useMutationEffects",
|
|
512
|
-
extension: "ts"
|
|
513
|
-
};
|
|
514
|
-
const CROSS_TAB_QUERY_INVALIDATION_FILE = {
|
|
515
|
-
fileName: "useCrossTabQueryInvalidation",
|
|
516
|
-
extension: "ts"
|
|
517
|
-
};
|
|
518
505
|
const ZOD_EXTENDED = {
|
|
519
506
|
namespace: "ZodExtended",
|
|
520
507
|
exports: {
|
|
@@ -522,10 +509,6 @@ const ZOD_EXTENDED = {
|
|
|
522
509
|
sortExp: "sortExp"
|
|
523
510
|
}
|
|
524
511
|
};
|
|
525
|
-
const ZOD_EXTENDED_FILE = {
|
|
526
|
-
fileName: "zod.extended",
|
|
527
|
-
extension: "ts"
|
|
528
|
-
};
|
|
529
512
|
|
|
530
513
|
//#endregion
|
|
531
514
|
//#region src/generators/utils/zod-schema.utils.ts
|
|
@@ -583,10 +566,6 @@ const ACL_APP_ABILITY_FILE = {
|
|
|
583
566
|
extension: "ts"
|
|
584
567
|
};
|
|
585
568
|
const ACL_APP_ABILITIES = "AppAbilities";
|
|
586
|
-
const ACL_CHECK_FILE = {
|
|
587
|
-
fileName: "acl/useAclCheck",
|
|
588
|
-
extension: "ts"
|
|
589
|
-
};
|
|
590
569
|
const ACL_CHECK_HOOK = "useAclCheck";
|
|
591
570
|
const CASL_ABILITY_BINDING = {
|
|
592
571
|
abilityTuple: "AbilityTuple",
|
|
@@ -1070,18 +1049,6 @@ function getQueryModulesImportPath(options) {
|
|
|
1070
1049
|
function getQueryTypesImportPath(options) {
|
|
1071
1050
|
return options.queryTypesImportPath;
|
|
1072
1051
|
}
|
|
1073
|
-
function getMutationEffectsImportPath(options) {
|
|
1074
|
-
return `${getImportPath(options)}${MUTATION_EFFECTS_FILE.fileName}`;
|
|
1075
|
-
}
|
|
1076
|
-
function getAclCheckImportPath(options) {
|
|
1077
|
-
return `${getImportPath(options)}${ACL_CHECK_FILE.fileName}`;
|
|
1078
|
-
}
|
|
1079
|
-
function getZodExtendedImportPath(options) {
|
|
1080
|
-
return `${getImportPath(options)}${ZOD_EXTENDED_FILE.fileName}`;
|
|
1081
|
-
}
|
|
1082
|
-
function getAppAbilitiesImportPath(options) {
|
|
1083
|
-
return `${getImportPath(options)}${ACL_APP_ABILITY_FILE.fileName}`;
|
|
1084
|
-
}
|
|
1085
1052
|
|
|
1086
1053
|
//#endregion
|
|
1087
1054
|
//#region src/generators/utils/ts.utils.ts
|
|
@@ -3050,19 +3017,6 @@ function getTagElement(tag, data) {
|
|
|
3050
3017
|
|
|
3051
3018
|
//#endregion
|
|
3052
3019
|
//#region src/generators/utils/file.utils.ts
|
|
3053
|
-
function readFileSync(filePath) {
|
|
3054
|
-
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
3055
|
-
const candidates = [
|
|
3056
|
-
path.resolve(process.cwd(), filePath),
|
|
3057
|
-
path.resolve(moduleDir, "../../../", filePath),
|
|
3058
|
-
path.resolve(moduleDir, "../", filePath)
|
|
3059
|
-
];
|
|
3060
|
-
for (const candidatePath of candidates) if (fs.existsSync(candidatePath)) return fs.readFileSync(candidatePath, "utf-8");
|
|
3061
|
-
throw new Error(`Cannot read file: ${filePath}`);
|
|
3062
|
-
}
|
|
3063
|
-
function readAssetSync(fileName) {
|
|
3064
|
-
return readFileSync(`src/assets/${fileName}`);
|
|
3065
|
-
}
|
|
3066
3020
|
function getOutputFileName({ output, fileName }) {
|
|
3067
3021
|
return `${output}/${fileName}`;
|
|
3068
3022
|
}
|
|
@@ -3096,8 +3050,8 @@ function generateAcl({ resolver, data, tag }) {
|
|
|
3096
3050
|
from: CASL_ABILITY_IMPORT.from
|
|
3097
3051
|
};
|
|
3098
3052
|
const lines = [];
|
|
3099
|
-
lines.push(renderImport$
|
|
3100
|
-
for (const modelsImport of modelsImports) lines.push(renderImport$
|
|
3053
|
+
lines.push(renderImport$4(caslAbilityTupleImport));
|
|
3054
|
+
for (const modelsImport of modelsImports) lines.push(renderImport$4(modelsImport));
|
|
3101
3055
|
lines.push("");
|
|
3102
3056
|
if (resolver.options.tsNamespaces) lines.push(`export namespace ${getNamespaceName({
|
|
3103
3057
|
type: GenerateType.Acl,
|
|
@@ -3126,8 +3080,8 @@ function generateAppAcl({ resolver, data }) {
|
|
|
3126
3080
|
from: CASL_ABILITY_IMPORT.from
|
|
3127
3081
|
};
|
|
3128
3082
|
const lines = [];
|
|
3129
|
-
lines.push(renderImport$
|
|
3130
|
-
for (const modelsImport of modelsImports) lines.push(renderImport$
|
|
3083
|
+
lines.push(renderImport$4(caslAbilityTupleImport));
|
|
3084
|
+
for (const modelsImport of modelsImports) lines.push(renderImport$4(modelsImport));
|
|
3131
3085
|
lines.push("");
|
|
3132
3086
|
if (appAbilitiesType) {
|
|
3133
3087
|
lines.push(`export type ${ACL_APP_ABILITIES} = `);
|
|
@@ -3137,7 +3091,7 @@ function generateAppAcl({ resolver, data }) {
|
|
|
3137
3091
|
lines.push(`export type AppAbility = PureAbility<${ACL_APP_ABILITIES}>;`);
|
|
3138
3092
|
return lines.join("\n");
|
|
3139
3093
|
}
|
|
3140
|
-
function renderImport$
|
|
3094
|
+
function renderImport$4(importData) {
|
|
3141
3095
|
return `import ${[...importData.defaultImport ? [importData.defaultImport] : [], ...importData.bindings ? [`{ ${importData.bindings.join(", ")} }`] : []].join(", ")} from "${importData.from}";`;
|
|
3142
3096
|
}
|
|
3143
3097
|
function renderAbilityFunction(endpoint) {
|
|
@@ -3393,12 +3347,12 @@ function generateConfigs(generateTypeParams) {
|
|
|
3393
3347
|
from: resolver.options.dynamicColumnsImportPath
|
|
3394
3348
|
};
|
|
3395
3349
|
const lines = [];
|
|
3396
|
-
if (hasZodImport) lines.push(renderImport$
|
|
3397
|
-
if (hasDynamicInputsImport) lines.push(renderImport$
|
|
3398
|
-
if (hasDynamicColumnsImport) lines.push(renderImport$
|
|
3399
|
-
for (const modelsImport of modelsImports) lines.push(renderImport$
|
|
3400
|
-
for (const queriesImport of queriesImports) lines.push(renderImport$
|
|
3401
|
-
for (const aclImport of aclImports) lines.push(renderImport$
|
|
3350
|
+
if (hasZodImport) lines.push(renderImport$3(ZOD_IMPORT));
|
|
3351
|
+
if (hasDynamicInputsImport) lines.push(renderImport$3(dynamicInputsImport));
|
|
3352
|
+
if (hasDynamicColumnsImport) lines.push(renderImport$3(dynamicColumnsImport));
|
|
3353
|
+
for (const modelsImport of modelsImports) lines.push(renderImport$3(modelsImport));
|
|
3354
|
+
for (const queriesImport of queriesImports) lines.push(renderImport$3(queriesImport));
|
|
3355
|
+
for (const aclImport of aclImports) lines.push(renderImport$3(aclImport));
|
|
3402
3356
|
lines.push("");
|
|
3403
3357
|
if (resolver.options.tsNamespaces) lines.push(`export namespace ${getNamespaceName({
|
|
3404
3358
|
type: GenerateType.Configs,
|
|
@@ -3412,7 +3366,7 @@ function generateConfigs(generateTypeParams) {
|
|
|
3412
3366
|
if (resolver.options.tsNamespaces) lines.push("}");
|
|
3413
3367
|
return lines.join("\n").trimEnd() + "\n";
|
|
3414
3368
|
}
|
|
3415
|
-
function renderImport$
|
|
3369
|
+
function renderImport$3(importData) {
|
|
3416
3370
|
return `import ${[...importData.defaultImport ? [importData.defaultImport] : [], ...importData.bindings ? [`{ ${importData.bindings.join(", ")} }`] : []].join(", ")} from "${importData.from}";`;
|
|
3417
3371
|
}
|
|
3418
3372
|
function renderInputsConfig(inputsConfig) {
|
|
@@ -3516,7 +3470,7 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
3516
3470
|
const hasZodExtendedImport = resolver.options.parseRequestParams && endpointParamsParseSchemas.length > 0;
|
|
3517
3471
|
const zodExtendedImport = {
|
|
3518
3472
|
bindings: [ZOD_EXTENDED.namespace],
|
|
3519
|
-
from:
|
|
3473
|
+
from: ZOD_PACKAGE_IMPORT_PATH
|
|
3520
3474
|
};
|
|
3521
3475
|
const modelsImports = getModelsImports({
|
|
3522
3476
|
resolver,
|
|
@@ -3525,11 +3479,11 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
3525
3479
|
zodSchemasAsTypes: getUniqueArray(endpointParams.map((param) => param.zodSchema).filter(isNamedZodSchema))
|
|
3526
3480
|
});
|
|
3527
3481
|
const lines = [];
|
|
3528
|
-
lines.push(renderImport$
|
|
3529
|
-
if (hasAxiosImport) lines.push(renderImport$
|
|
3530
|
-
if (hasZodImport) lines.push(renderImport$
|
|
3531
|
-
if (hasZodExtendedImport) lines.push(renderImport$
|
|
3532
|
-
for (const modelsImport of modelsImports) lines.push(renderImport$
|
|
3482
|
+
lines.push(renderImport$2(appRestClientImport));
|
|
3483
|
+
if (hasAxiosImport) lines.push(renderImport$2(axiosImport));
|
|
3484
|
+
if (hasZodImport) lines.push(renderImport$2(ZOD_IMPORT));
|
|
3485
|
+
if (hasZodExtendedImport) lines.push(renderImport$2(zodExtendedImport));
|
|
3486
|
+
for (const modelsImport of modelsImports) lines.push(renderImport$2(modelsImport));
|
|
3533
3487
|
lines.push("");
|
|
3534
3488
|
if (resolver.options.tsNamespaces) lines.push(`export namespace ${getNamespaceName({
|
|
3535
3489
|
type: GenerateType.Endpoints,
|
|
@@ -3556,7 +3510,7 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
3556
3510
|
if (resolver.options.tsNamespaces) lines.push("}");
|
|
3557
3511
|
return lines.join("\n").trimEnd() + "\n";
|
|
3558
3512
|
}
|
|
3559
|
-
function renderImport$
|
|
3513
|
+
function renderImport$2(importData) {
|
|
3560
3514
|
return `import ${[...importData.defaultImport ? [importData.defaultImport] : [], ...importData.bindings ? [`{ ${importData.bindings.join(", ")} }`] : []].join(", ")} from "${importData.from}";`;
|
|
3561
3515
|
}
|
|
3562
3516
|
function renderEndpointParams$1(resolver, endpoint, options) {
|
|
@@ -3628,8 +3582,8 @@ function generateModels({ resolver, data, tag }) {
|
|
|
3628
3582
|
};
|
|
3629
3583
|
}
|
|
3630
3584
|
const lines = [];
|
|
3631
|
-
lines.push(renderImport$
|
|
3632
|
-
for (const modelsImport of modelsImports) lines.push(renderImport$
|
|
3585
|
+
lines.push(renderImport$1(ZOD_IMPORT));
|
|
3586
|
+
for (const modelsImport of modelsImports) lines.push(renderImport$1(modelsImport));
|
|
3633
3587
|
lines.push("");
|
|
3634
3588
|
if (resolver.options.tsNamespaces) lines.push(`export namespace ${getNamespaceName({
|
|
3635
3589
|
type: GenerateType.Models,
|
|
@@ -3718,7 +3672,7 @@ function getUsedSchemaNames({ resolver, endpoints }) {
|
|
|
3718
3672
|
}
|
|
3719
3673
|
return Array.from(usedSchemaNames);
|
|
3720
3674
|
}
|
|
3721
|
-
function renderImport$
|
|
3675
|
+
function renderImport$1(importData) {
|
|
3722
3676
|
return `import ${[...importData.defaultImport ? [importData.defaultImport] : [], ...importData.bindings ? [`{ ${importData.bindings.join(", ")} }`] : []].join(", ")} from "${importData.from}";`;
|
|
3723
3677
|
}
|
|
3724
3678
|
function renderModelJsDocs({ name, zodSchema, tag, resolver }) {
|
|
@@ -3773,11 +3727,8 @@ function generateQueries(params) {
|
|
|
3773
3727
|
const queryImport = {
|
|
3774
3728
|
bindings: [
|
|
3775
3729
|
...queryEndpoints.length > 0 ? [QUERY_HOOKS.query] : [],
|
|
3776
|
-
...queryEndpoints.length > 0 ? ["UseQueryResult"] : [],
|
|
3777
3730
|
...resolver.options.infiniteQueries && infiniteQueryEndpoints.length > 0 ? [QUERY_HOOKS.infiniteQuery] : [],
|
|
3778
|
-
...
|
|
3779
|
-
...mutationEndpoints.length > 0 ? [QUERY_HOOKS.mutation] : [],
|
|
3780
|
-
...mutationEndpoints.length > 0 ? ["UseMutationResult"] : []
|
|
3731
|
+
...mutationEndpoints.length > 0 ? [QUERY_HOOKS.mutation] : []
|
|
3781
3732
|
],
|
|
3782
3733
|
from: QUERY_IMPORT.from
|
|
3783
3734
|
};
|
|
@@ -3789,12 +3740,12 @@ function generateQueries(params) {
|
|
|
3789
3740
|
const hasMutationEffectsImport = hasMutationEffects && mutationEndpoints.length > 0;
|
|
3790
3741
|
const mutationEffectsImport = {
|
|
3791
3742
|
bindings: [...mutationEndpoints.length > 0 ? [MUTATION_EFFECTS.optionsType, MUTATION_EFFECTS.hookName] : []],
|
|
3792
|
-
from:
|
|
3743
|
+
from: PACKAGE_IMPORT_PATH
|
|
3793
3744
|
};
|
|
3794
3745
|
const hasAclCheck = resolver.options.checkAcl && aclEndpoints.length > 0;
|
|
3795
3746
|
const aclCheckImport = {
|
|
3796
3747
|
bindings: [ACL_CHECK_HOOK],
|
|
3797
|
-
from:
|
|
3748
|
+
from: ACL_PACKAGE_IMPORT_PATH
|
|
3798
3749
|
};
|
|
3799
3750
|
const queryTypesImport = {
|
|
3800
3751
|
bindings: [
|
|
@@ -3821,7 +3772,7 @@ function generateQueries(params) {
|
|
|
3821
3772
|
};
|
|
3822
3773
|
const zodExtendedImport = {
|
|
3823
3774
|
bindings: [ZOD_EXTENDED.namespace],
|
|
3824
|
-
from:
|
|
3775
|
+
from: ZOD_PACKAGE_IMPORT_PATH
|
|
3825
3776
|
};
|
|
3826
3777
|
const modelsImports = getModelsImports({
|
|
3827
3778
|
resolver,
|
|
@@ -3845,23 +3796,23 @@ function generateQueries(params) {
|
|
|
3845
3796
|
options: resolver.options
|
|
3846
3797
|
});
|
|
3847
3798
|
const lines = [];
|
|
3848
|
-
if (hasAxiosImport) lines.push(renderImport
|
|
3799
|
+
if (hasAxiosImport) lines.push(renderImport(axiosImport));
|
|
3849
3800
|
if (inlineEndpoints) {
|
|
3850
|
-
lines.push(renderImport
|
|
3851
|
-
if (hasZodImport) lines.push(renderImport
|
|
3852
|
-
if (hasZodExtendedImport) lines.push(renderImport
|
|
3801
|
+
lines.push(renderImport(appRestClientImport));
|
|
3802
|
+
if (hasZodImport) lines.push(renderImport(ZOD_IMPORT));
|
|
3803
|
+
if (hasZodExtendedImport) lines.push(renderImport(zodExtendedImport));
|
|
3853
3804
|
}
|
|
3854
|
-
lines.push(renderImport
|
|
3855
|
-
if (hasMutationEffects) lines.push(renderImport
|
|
3856
|
-
if (hasMutationEffectsImport) lines.push(renderImport
|
|
3805
|
+
lines.push(renderImport(queryImport));
|
|
3806
|
+
if (hasMutationEffects) lines.push(renderImport(queryModulesImport));
|
|
3807
|
+
if (hasMutationEffectsImport) lines.push(renderImport(mutationEffectsImport));
|
|
3857
3808
|
if (hasAclCheck) {
|
|
3858
|
-
lines.push(renderImport
|
|
3859
|
-
for (const aclImport of aclImports) lines.push(renderImport
|
|
3809
|
+
lines.push(renderImport(aclCheckImport));
|
|
3810
|
+
for (const aclImport of aclImports) lines.push(renderImport(aclImport));
|
|
3860
3811
|
}
|
|
3861
|
-
lines.push(renderImport
|
|
3862
|
-
if (hasWorkspaceContext) lines.push(renderImport
|
|
3863
|
-
for (const modelsImport of modelsImports) lines.push(renderImport
|
|
3864
|
-
for (const endpointsImport of endpointsImports) lines.push(renderImport
|
|
3812
|
+
lines.push(renderImport(queryTypesImport));
|
|
3813
|
+
if (hasWorkspaceContext) lines.push(renderImport(workspaceContextImport));
|
|
3814
|
+
for (const modelsImport of modelsImports) lines.push(renderImport(modelsImport));
|
|
3815
|
+
for (const endpointsImport of endpointsImports) lines.push(renderImport(endpointsImport));
|
|
3865
3816
|
lines.push("");
|
|
3866
3817
|
if (resolver.options.tsNamespaces) lines.push(`export namespace ${namespace} {`);
|
|
3867
3818
|
if (inlineEndpoints) {
|
|
@@ -3929,7 +3880,7 @@ function getEndpointParamMapping(resolver, endpoint, options) {
|
|
|
3929
3880
|
endpointCache.set(key, computed);
|
|
3930
3881
|
return computed;
|
|
3931
3882
|
}
|
|
3932
|
-
function renderImport
|
|
3883
|
+
function renderImport(importData) {
|
|
3933
3884
|
return `import ${[...importData.defaultImport ? [importData.defaultImport] : [], ...importData.bindings ? [`{ ${importData.bindings.join(", ")} }`] : []].join(", ")} from "${importData.from}";`;
|
|
3934
3885
|
}
|
|
3935
3886
|
function renderEndpointParams(resolver, endpoint, options) {
|
|
@@ -4150,7 +4101,7 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
4150
4101
|
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
4151
4102
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
4152
4103
|
if (Object.keys(workspaceParamReplacements).length > 0) lines.push(" const workspaceContext = OpenApiWorkspaceContext.useContext();");
|
|
4153
|
-
if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects({ currentModule: ${QUERIES_MODULE_NAME} });`);
|
|
4104
|
+
if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects<typeof ${QUERY_MODULE_ENUM}.${tag}>({ currentModule: ${QUERIES_MODULE_NAME} });`);
|
|
4154
4105
|
lines.push("");
|
|
4155
4106
|
lines.push(` return ${QUERY_HOOKS.mutation}({`);
|
|
4156
4107
|
const mutationFnArg = endpointParams ? `{ ${destructuredMutationArgs}${endpoint.mediaUpload ? `${destructuredMutationArgs ? ", " : ""}abortController, onUploadProgress` : ""} }` : "";
|
|
@@ -4286,37 +4237,6 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4286
4237
|
return lines.join("\n");
|
|
4287
4238
|
}
|
|
4288
4239
|
|
|
4289
|
-
//#endregion
|
|
4290
|
-
//#region src/generators/generate/generateAclCheck.ts
|
|
4291
|
-
function generateAclCheck(resolver) {
|
|
4292
|
-
const abilityContextImportPath = resolver.options.abilityContextImportPath ?? ABILITY_CONTEXT_IMPORT.from;
|
|
4293
|
-
const appAbilitiesImportPath = getAppAbilitiesImportPath(resolver.options);
|
|
4294
|
-
const errorHandlingImportPath = resolver.options.errorHandlingImportPath ?? ERROR_HANDLING_IMPORT.from;
|
|
4295
|
-
const genericAppAbilities = resolver.options.abilityContextGenericAppAbilities ? `<${ACL_APP_ABILITIES}>` : "";
|
|
4296
|
-
return `import { ${CASL_ABILITY_BINDING.abilityTuple} } from "@casl/ability";
|
|
4297
|
-
import { type ${ERROR_HANDLERS.ErrorHandler}, ${ERROR_HANDLERS.SharedErrorHandler} } from "${errorHandlingImportPath}";
|
|
4298
|
-
import { ${ABILITY_CONTEXT} } from "${abilityContextImportPath}";
|
|
4299
|
-
import { useCallback } from "react";
|
|
4300
|
-
import { ${ACL_APP_ABILITIES} } from "${appAbilitiesImportPath}";
|
|
4301
|
-
|
|
4302
|
-
interface UseAclCheckProps {
|
|
4303
|
-
errorHandler?: ${ERROR_HANDLERS.ErrorHandler}<never>;
|
|
4304
|
-
}
|
|
4305
|
-
|
|
4306
|
-
export function ${ACL_CHECK_HOOK}({ errorHandler }: UseAclCheckProps = {}) {
|
|
4307
|
-
const ability = ${ABILITY_CONTEXT}.useAbility${genericAppAbilities}();
|
|
4308
|
-
|
|
4309
|
-
const checkAcl = useCallback((appAbility: ${ACL_APP_ABILITIES}) => {
|
|
4310
|
-
if (!ability.can(...(appAbility as ${CASL_ABILITY_BINDING.abilityTuple}))) {
|
|
4311
|
-
(errorHandler ?? ${ERROR_HANDLERS.SharedErrorHandler}).rethrowError(new Error("ACL check failed"));
|
|
4312
|
-
}
|
|
4313
|
-
}, [ability, errorHandler]);
|
|
4314
|
-
|
|
4315
|
-
return { checkAcl };
|
|
4316
|
-
}
|
|
4317
|
-
`;
|
|
4318
|
-
}
|
|
4319
|
-
|
|
4320
4240
|
//#endregion
|
|
4321
4241
|
//#region src/generators/generate/generateAppRestClient.ts
|
|
4322
4242
|
function generateAppRestClient(resolver) {
|
|
@@ -4353,66 +4273,6 @@ function generateQueryModules({ resolver, data }) {
|
|
|
4353
4273
|
return lines.join("\n");
|
|
4354
4274
|
}
|
|
4355
4275
|
|
|
4356
|
-
//#endregion
|
|
4357
|
-
//#region src/generators/generate/generateZodExtended.ts
|
|
4358
|
-
function generateZodExtended(resolver) {
|
|
4359
|
-
const errorHandlingImport = {
|
|
4360
|
-
...ERROR_HANDLING_IMPORT,
|
|
4361
|
-
from: resolver.options.errorHandlingImportPath ?? ERROR_HANDLING_IMPORT.from
|
|
4362
|
-
};
|
|
4363
|
-
return `${renderImport(ZOD_IMPORT)}
|
|
4364
|
-
${renderImport(errorHandlingImport)}
|
|
4365
|
-
|
|
4366
|
-
export namespace ZodExtended {
|
|
4367
|
-
interface ParseOptions {
|
|
4368
|
-
type: "body" | "query";
|
|
4369
|
-
name?: string;
|
|
4370
|
-
errorHandler?: ${ERROR_HANDLERS.ErrorHandler}<never>;
|
|
4371
|
-
}
|
|
4372
|
-
|
|
4373
|
-
export function ${ZOD_EXTENDED.exports.parse}<ZOutput, ZInput>(
|
|
4374
|
-
schema: z.ZodType<ZOutput, ZInput>,
|
|
4375
|
-
data: unknown,
|
|
4376
|
-
{ type, name, errorHandler }: ParseOptions = { type: "body" },
|
|
4377
|
-
) {
|
|
4378
|
-
try {
|
|
4379
|
-
return schema.parse(data);
|
|
4380
|
-
} catch (e) {
|
|
4381
|
-
if (e instanceof z.ZodError) {
|
|
4382
|
-
e.name = \`FE Request \${type === "body" ? "body" : "query param"}\${name ? \` ("\${name}")\` : ""} schema mismatch - ZodError\`;
|
|
4383
|
-
}
|
|
4384
|
-
(errorHandler ?? ${ERROR_HANDLERS.SharedErrorHandler}).rethrowError(e);
|
|
4385
|
-
throw e;
|
|
4386
|
-
}
|
|
4387
|
-
}
|
|
4388
|
-
|
|
4389
|
-
function isSortExpValid(enumSchema: z.ZodEnum, data?: string) {
|
|
4390
|
-
if (data === undefined || data === "" || enumSchema.options.length === 0) {
|
|
4391
|
-
return true;
|
|
4392
|
-
}
|
|
4393
|
-
|
|
4394
|
-
const prefixedEnumOptions = \`([+-]?(\${enumSchema.options.join("|")}))\`;
|
|
4395
|
-
const commaSeparatedOptions = \`(\${prefixedEnumOptions})(\\s*,\\s*\${prefixedEnumOptions})*\`;
|
|
4396
|
-
return new RegExp(\`^\${commaSeparatedOptions}$\`).test(data);
|
|
4397
|
-
}
|
|
4398
|
-
|
|
4399
|
-
export const ${ZOD_EXTENDED.exports.sortExp} = (enumSchema: z.ZodEnum) =>
|
|
4400
|
-
z.string().superRefine((arg, ctx) => {
|
|
4401
|
-
if (!isSortExpValid(enumSchema, arg)) {
|
|
4402
|
-
ctx.addIssue({
|
|
4403
|
-
code: "invalid_value",
|
|
4404
|
-
message: "Invalid sorting string.",
|
|
4405
|
-
values: [],
|
|
4406
|
-
});
|
|
4407
|
-
}
|
|
4408
|
-
});
|
|
4409
|
-
}
|
|
4410
|
-
`;
|
|
4411
|
-
}
|
|
4412
|
-
function renderImport(importData) {
|
|
4413
|
-
return `import ${[...importData.defaultImport ? [importData.defaultImport] : [], ...importData.bindings ? [`{ ${importData.bindings.join(", ")} }`] : []].join(", ")} from "${importData.from}";`;
|
|
4414
|
-
}
|
|
4415
|
-
|
|
4416
4276
|
//#endregion
|
|
4417
4277
|
//#region src/generators/utils/generate-files.utils.ts
|
|
4418
4278
|
function getAclFiles(data, resolver) {
|
|
@@ -4426,17 +4286,11 @@ function getAclFiles(data, resolver) {
|
|
|
4426
4286
|
resolver,
|
|
4427
4287
|
data
|
|
4428
4288
|
})
|
|
4429
|
-
}
|
|
4430
|
-
fileName: getOutputFileName({
|
|
4431
|
-
output: resolver.options.output,
|
|
4432
|
-
fileName: getFileNameWithExtension(ACL_CHECK_FILE)
|
|
4433
|
-
}),
|
|
4434
|
-
content: generateAclCheck(resolver)
|
|
4435
|
-
}] : []];
|
|
4289
|
+
}];
|
|
4436
4290
|
}
|
|
4437
4291
|
function getMutationEffectsFiles(data, resolver) {
|
|
4438
4292
|
if (!resolver.options.mutationEffects) return [];
|
|
4439
|
-
return [
|
|
4293
|
+
return [{
|
|
4440
4294
|
fileName: getOutputFileName({
|
|
4441
4295
|
output: resolver.options.output,
|
|
4442
4296
|
fileName: getFileNameWithExtension(QUERY_MODULES_FILE)
|
|
@@ -4447,15 +4301,8 @@ function getMutationEffectsFiles(data, resolver) {
|
|
|
4447
4301
|
})
|
|
4448
4302
|
}];
|
|
4449
4303
|
}
|
|
4450
|
-
function getZodExtendedFiles(
|
|
4451
|
-
|
|
4452
|
-
return [{
|
|
4453
|
-
fileName: getOutputFileName({
|
|
4454
|
-
output: resolver.options.output,
|
|
4455
|
-
fileName: getFileNameWithExtension(ZOD_EXTENDED_FILE)
|
|
4456
|
-
}),
|
|
4457
|
-
content: generateZodExtended(resolver)
|
|
4458
|
-
}];
|
|
4304
|
+
function getZodExtendedFiles(_data, _resolver) {
|
|
4305
|
+
return [];
|
|
4459
4306
|
}
|
|
4460
4307
|
function getAppRestClientFiles(resolver) {
|
|
4461
4308
|
if (resolver.options.restClientImportPath !== DEFAULT_GENERATE_OPTIONS.restClientImportPath) return [];
|
|
@@ -4467,21 +4314,6 @@ function getAppRestClientFiles(resolver) {
|
|
|
4467
4314
|
content: generateAppRestClient(resolver)
|
|
4468
4315
|
}];
|
|
4469
4316
|
}
|
|
4470
|
-
function getAssetFiles(files, resolver) {
|
|
4471
|
-
return files.map((file) => getAssetFile(file, resolver));
|
|
4472
|
-
}
|
|
4473
|
-
function getAssetFile(file, resolver) {
|
|
4474
|
-
const fileName = getFileNameWithExtension(file);
|
|
4475
|
-
let content = readAssetSync(fileName);
|
|
4476
|
-
if (file.fileName === MUTATION_EFFECTS_FILE.fileName) content = content.replace("import { OpenApiQueryConfig, QueryModule, InvalidationMap } from \"../lib/config/queryConfig.context\";", `import { OpenApiQueryConfig, InvalidationMap } from "${PACKAGE_IMPORT_PATH}";\nimport { QueryModule } from "./${QUERY_MODULES_FILE.fileName}";`);
|
|
4477
|
-
return {
|
|
4478
|
-
fileName: getOutputFileName({
|
|
4479
|
-
output: resolver.options.output,
|
|
4480
|
-
fileName
|
|
4481
|
-
}),
|
|
4482
|
-
content
|
|
4483
|
-
};
|
|
4484
|
-
}
|
|
4485
4317
|
|
|
4486
4318
|
//#endregion
|
|
4487
4319
|
//#region src/generators/generateCodeFromOpenAPIDoc.ts
|
package/dist/generator.d.mts
CHANGED
package/dist/generator.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as isMediaTypeAllowed, b as formatTag, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, h as GenerateType, i as getDataFromOpenAPIDoc, l as getTsTypeBase, m as getNamespaceName, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as isParamMediaTypeAllowed, y as invalidVariableNameCharactersToCamel } from "./generateCodeFromOpenAPIDoc-
|
|
1
|
+
import { _ as isMediaTypeAllowed, b as formatTag, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, h as GenerateType, i as getDataFromOpenAPIDoc, l as getTsTypeBase, m as getNamespaceName, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as isParamMediaTypeAllowed, y as invalidVariableNameCharactersToCamel } from "./generateCodeFromOpenAPIDoc-BP7F6YJP.mjs";
|
|
2
2
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/core/getMetadataFromOpenAPIDoc.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -1,48 +1,14 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import
|
|
1
|
+
import { a as GeneralErrorCodes, i as ErrorHandlerOptions, n as ErrorEntry, o as SharedErrorHandler, r as ErrorHandler, t as ApplicationException } from "./error-handling-p69GkKGP.mjs";
|
|
2
|
+
import "./options-Bvmh6rai.mjs";
|
|
3
|
+
import { t as OpenAPICodegenConfig } from "./config-B4HK4BLi.mjs";
|
|
3
4
|
import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, CreateAxiosDefaults } from "axios";
|
|
4
5
|
import { z } from "zod";
|
|
5
|
-
import
|
|
6
|
+
import "i18next";
|
|
6
7
|
import * as react from "react";
|
|
7
8
|
import { PropsWithChildren, ReactNode } from "react";
|
|
8
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
9
9
|
import { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
10
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
10
11
|
|
|
11
|
-
//#region src/lib/rest/error-handling.d.ts
|
|
12
|
-
type GeneralErrorCodes = "DATA_VALIDATION_ERROR" | "NETWORK_ERROR" | "CANCELED_ERROR" | "INTERNAL_ERROR" | "UNKNOWN_ERROR";
|
|
13
|
-
declare class ApplicationException<CodeT> extends Error {
|
|
14
|
-
code: CodeT;
|
|
15
|
-
serverMessage: string | null;
|
|
16
|
-
constructor(message: string, code: CodeT, serverMessage: string | null);
|
|
17
|
-
}
|
|
18
|
-
interface ErrorEntry<CodeT> {
|
|
19
|
-
code: CodeT;
|
|
20
|
-
condition?: (error: unknown) => boolean;
|
|
21
|
-
getMessage: (t: TFunction, error: unknown) => string;
|
|
22
|
-
}
|
|
23
|
-
interface ErrorHandlerOptions<CodeT extends string> {
|
|
24
|
-
entries: ErrorEntry<CodeT>[];
|
|
25
|
-
t?: TFunction;
|
|
26
|
-
onRethrowError?: (error: unknown, exception: ApplicationException<CodeT | GeneralErrorCodes>) => void;
|
|
27
|
-
}
|
|
28
|
-
declare class ErrorHandler<CodeT extends string> {
|
|
29
|
-
entries: ErrorEntry<CodeT | GeneralErrorCodes>[];
|
|
30
|
-
private t;
|
|
31
|
-
private onRethrowError?;
|
|
32
|
-
constructor({
|
|
33
|
-
entries,
|
|
34
|
-
t,
|
|
35
|
-
onRethrowError
|
|
36
|
-
}: ErrorHandlerOptions<CodeT>);
|
|
37
|
-
private matchesEntry;
|
|
38
|
-
setTranslateFunction(t: TFunction): void;
|
|
39
|
-
rethrowError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes>;
|
|
40
|
-
getError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes> | null;
|
|
41
|
-
getErrorCode(error: unknown): CodeT | GeneralErrorCodes | null;
|
|
42
|
-
static getErrorMessage(error: unknown, fallbackToUnknown?: boolean): string | null;
|
|
43
|
-
}
|
|
44
|
-
declare const SharedErrorHandler: ErrorHandler<never>;
|
|
45
|
-
//#endregion
|
|
46
12
|
//#region src/lib/rest/rest-interceptor.d.ts
|
|
47
13
|
declare class RestInterceptor<T extends any[]> {
|
|
48
14
|
private applyInterceptor;
|
|
@@ -114,43 +80,61 @@ type AppQueryOptions<TFunction extends Function, TData = Awaited<ReturnType<TFun
|
|
|
114
80
|
type AppMutationOptions<TFunction extends Function, TVariables = void, TData = Awaited<ReturnType<TFunction>>, TErrorCodes = GeneralErrorCodes> = Omit<UseMutationOptions<TData, ApplicationException<TErrorCodes>, TVariables>, "mutationKey" | "mutationFn">;
|
|
115
81
|
type AppInfiniteQueryOptions<TFunction extends Function, TData = InfiniteData<Awaited<ReturnType<TFunction>>>, TErrorCodes = GeneralErrorCodes, TQueryKey extends QueryKey = QueryKey, TPageParam = number> = Omit<UseInfiniteQueryOptions<Awaited<ReturnType<TFunction>>, ApplicationException<TErrorCodes>, IsUnknown<TData, InfiniteData<Awaited<ReturnType<TFunction>>>>, TQueryKey, TPageParam>, "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">;
|
|
116
82
|
//#endregion
|
|
117
|
-
//#region src/lib/config/router.context.d.ts
|
|
118
|
-
interface RouterProviderProps {
|
|
119
|
-
replace: (url: string) => void;
|
|
120
|
-
}
|
|
121
|
-
declare namespace OpenApiRouter {
|
|
122
|
-
const Provider: ({
|
|
123
|
-
children,
|
|
124
|
-
replace
|
|
125
|
-
}: PropsWithChildren<RouterProviderProps>) => react_jsx_runtime0.JSX.Element;
|
|
126
|
-
const useRouter: () => RouterProviderProps;
|
|
127
|
-
}
|
|
128
|
-
//#endregion
|
|
129
83
|
//#region src/lib/config/queryConfig.context.d.ts
|
|
130
84
|
type QueryModule = string | number | symbol;
|
|
131
85
|
type InvalidationMapFunc<TData = any, TVariables = any> = (data: TData, variables: TVariables) => QueryKey[];
|
|
132
|
-
type InvalidationMap<TData = any, TVariables = any> = Record<
|
|
86
|
+
type InvalidationMap<TQueryModule extends QueryModule = QueryModule, TData = any, TVariables = any> = Partial<Record<TQueryModule, InvalidationMapFunc<TData, TVariables>>>;
|
|
133
87
|
declare namespace OpenApiQueryConfig {
|
|
134
|
-
interface Type {
|
|
88
|
+
export interface Type<TQueryModule extends QueryModule = QueryModule> {
|
|
135
89
|
preferUpdate?: boolean;
|
|
136
90
|
invalidateCurrentModule?: boolean;
|
|
137
|
-
invalidationMap?: InvalidationMap
|
|
91
|
+
invalidationMap?: InvalidationMap<TQueryModule>;
|
|
138
92
|
crossTabInvalidation?: boolean;
|
|
139
93
|
onError?: (error: unknown) => void;
|
|
140
94
|
}
|
|
141
|
-
type ProviderProps = Type
|
|
142
|
-
export
|
|
95
|
+
type ProviderProps<TQueryModule extends QueryModule = QueryModule> = Type<TQueryModule>;
|
|
96
|
+
export function Provider<TQueryModule extends QueryModule = QueryModule>({
|
|
143
97
|
preferUpdate,
|
|
144
98
|
invalidateCurrentModule,
|
|
145
99
|
invalidationMap,
|
|
146
100
|
crossTabInvalidation,
|
|
147
101
|
onError,
|
|
148
102
|
children
|
|
149
|
-
}: PropsWithChildren<ProviderProps
|
|
150
|
-
export const useConfig: () => Type
|
|
103
|
+
}: PropsWithChildren<ProviderProps<TQueryModule>>): react_jsx_runtime0.JSX.Element;
|
|
104
|
+
export const useConfig: <TQueryModule extends QueryModule = QueryModule>() => Type<TQueryModule>;
|
|
151
105
|
export {};
|
|
152
106
|
}
|
|
153
107
|
//#endregion
|
|
108
|
+
//#region src/lib/react-query/useMutationEffects.d.ts
|
|
109
|
+
interface MutationEffectsOptions<TQueryModule extends QueryModule = QueryModule> {
|
|
110
|
+
invalidateCurrentModule?: boolean;
|
|
111
|
+
crossTabInvalidation?: boolean;
|
|
112
|
+
invalidationMap?: InvalidationMap<TQueryModule>;
|
|
113
|
+
invalidateModules?: TQueryModule[];
|
|
114
|
+
invalidateKeys?: QueryKey[];
|
|
115
|
+
preferUpdate?: boolean;
|
|
116
|
+
}
|
|
117
|
+
interface UseMutationEffectsProps<TQueryModule extends QueryModule = QueryModule> {
|
|
118
|
+
currentModule: TQueryModule;
|
|
119
|
+
}
|
|
120
|
+
declare function useMutationEffects<TQueryModule extends QueryModule = QueryModule>({
|
|
121
|
+
currentModule
|
|
122
|
+
}: UseMutationEffectsProps<TQueryModule>): {
|
|
123
|
+
runMutationEffects: <TData, TVariables>(data: TData, variables: TVariables, options?: MutationEffectsOptions<TQueryModule>, updateKeys?: QueryKey[]) => Promise<void>;
|
|
124
|
+
};
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/lib/config/router.context.d.ts
|
|
127
|
+
interface RouterProviderProps {
|
|
128
|
+
replace: (url: string) => void;
|
|
129
|
+
}
|
|
130
|
+
declare namespace OpenApiRouter {
|
|
131
|
+
const Provider: ({
|
|
132
|
+
children,
|
|
133
|
+
replace
|
|
134
|
+
}: PropsWithChildren<RouterProviderProps>) => react_jsx_runtime0.JSX.Element;
|
|
135
|
+
const useRouter: () => RouterProviderProps;
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
154
138
|
//#region src/lib/config/workspace.context.d.ts
|
|
155
139
|
type WorkspaceValues = Record<string, unknown>;
|
|
156
140
|
interface WorkspaceProviderProps {
|
|
@@ -243,4 +227,4 @@ declare const AuthGuard: ({
|
|
|
243
227
|
children
|
|
244
228
|
}: PropsWithChildren<AuthGuardProps>) => react.ReactNode;
|
|
245
229
|
//#endregion
|
|
246
|
-
export { type AppInfiniteQueryOptions, type AppMutationOptions, type AppQueryOptions, ApplicationException, AuthContext, AuthGuard, type AuthGuardProps, type ErrorEntry, ErrorHandler, type ErrorHandlerOptions, type GeneralErrorCodes, type RestClient as IRestClient, type InvalidationMap, OpenAPICodegenConfig, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, type RequestConfig, type RequestInfo, type Response, RestClient$1 as RestClient, RestInterceptor, RestUtils, SharedErrorHandler, ns, resources };
|
|
230
|
+
export { type AppInfiniteQueryOptions, type AppMutationOptions, type AppQueryOptions, ApplicationException, AuthContext, AuthGuard, type AuthGuardProps, type ErrorEntry, ErrorHandler, type ErrorHandlerOptions, type GeneralErrorCodes, type RestClient as IRestClient, type InvalidationMap, type InvalidationMapFunc, type MutationEffectsOptions, OpenAPICodegenConfig, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, type QueryModule, type RequestConfig, type RequestInfo, type Response, RestClient$1 as RestClient, RestInterceptor, RestUtils, SharedErrorHandler, ns, resources, useMutationEffects };
|