@povio/openapi-codegen-cli 1.2.11 → 2.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +24 -0
  2. package/dist/commands/generate.d.ts +1 -1
  3. package/dist/generators/const/deps.const.d.ts +2 -8
  4. package/dist/generators/const/package.const.d.ts +1 -0
  5. package/dist/generators/types/options.d.ts +0 -2
  6. package/dist/generators/utils/generate/generate.imports.utils.d.ts +1 -1
  7. package/dist/generators/utils/generate/generate.utils.d.ts +0 -1
  8. package/dist/generators/utils/generate-files.utils.d.ts +1 -1
  9. package/dist/index.d.ts +16 -0
  10. package/dist/index.js +47 -45
  11. package/dist/lib/acl/AclGuard.d.ts +8 -0
  12. package/dist/lib/acl/Can.d.ts +9 -0
  13. package/dist/lib/acl/ability.context.d.ts +15 -0
  14. package/dist/lib/acl/appAbility.types.d.ts +3 -0
  15. package/dist/lib/auth/AuthGuard.d.ts +6 -0
  16. package/dist/lib/auth/auth.context.d.ts +22 -0
  17. package/dist/lib/config/queryConfig.context.d.ts +9 -0
  18. package/dist/lib/config/router.context.d.ts +9 -0
  19. package/dist/lib/react-query.types.d.ts +10 -0
  20. package/dist/lib/rest/error-handling.d.ts +20 -0
  21. package/dist/lib/rest/rest-client.d.ts +20 -0
  22. package/dist/lib/rest/rest-client.types.d.ts +23 -0
  23. package/dist/lib/rest/rest-interceptor.d.ts +8 -0
  24. package/dist/lib/rest/rest.utils.d.ts +7 -0
  25. package/dist/sh.js +139 -139
  26. package/dist/tsconfig.tsbuildinfo +1 -1
  27. package/package.json +18 -2
  28. package/src/assets/useMutationEffects.ts +1 -1
  29. package/src/generators/templates/app-rest-client.hbs +2 -2
  30. package/src/assets/queryConfig.context.tsx +0 -22
  31. package/src/assets/react-query.types.ts +0 -40
  32. package/src/assets/rest-client.ts +0 -99
  33. package/src/assets/rest-interceptor.ts +0 -22
@@ -0,0 +1,8 @@
1
+ import type { PropsWithChildren } from "react";
2
+ import type { AppAbilities } from "./appAbility.types";
3
+ interface AclGuardProps<TAppAbilities extends AppAbilities = AppAbilities> {
4
+ canUse: TAppAbilities;
5
+ redirectTo?: string;
6
+ }
7
+ export declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({ canUse, redirectTo, children }: PropsWithChildren<AclGuardProps<TAppAbilities>>) => import("react").ReactNode;
8
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { AbilityTuple, PureAbility } from "@casl/ability";
2
+ import { type BoundCanProps } from "@casl/react";
3
+ import type { AppAbilities } from "./appAbility.types";
4
+ type CanAbility = PureAbility<AbilityTuple<AppAbilities[0], AppAbilities[1]>>;
5
+ type CanProps<TAppAbilities extends AppAbilities = AppAbilities> = {
6
+ use: TAppAbilities;
7
+ } & Omit<BoundCanProps<CanAbility>, "do" | "I" | "on" | "a" | "an" | "this">;
8
+ export declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({ use, ...props }: CanProps<TAppAbilities>) => import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,15 @@
1
+ import { type PureAbility, type RawRuleOf } from "@casl/ability";
2
+ import { type PackRule } from "@casl/ability/extra";
3
+ import { type PropsWithChildren } from "react";
4
+ import type { AppAbilities, AppAbility } from "./appAbility.types";
5
+ export declare namespace AbilityContext {
6
+ export const Consumer: import("react").Consumer<AppAbility>;
7
+ interface ProviderProps {
8
+ user?: {
9
+ aclRules?: PackRule<RawRuleOf<AppAbility>>[];
10
+ } | null;
11
+ }
12
+ export const Provider: ({ children }: PropsWithChildren<ProviderProps>) => import("react/jsx-runtime").JSX.Element;
13
+ export const useAbility: <TAppAbilities extends AppAbilities = AppAbilities>() => PureAbility<TAppAbilities, unknown>;
14
+ export {};
15
+ }
@@ -0,0 +1,3 @@
1
+ import type { AbilityTuple, PureAbility, Subject } from "@casl/ability";
2
+ export type AppAbilities = AbilityTuple<string, Subject>;
3
+ export type AppAbility = PureAbility<AppAbilities>;
@@ -0,0 +1,6 @@
1
+ import { type PropsWithChildren } from "react";
2
+ export interface AuthGuardProps {
3
+ type: "public-only" | "private";
4
+ redirectTo?: string;
5
+ }
6
+ export declare const AuthGuard: ({ type, redirectTo, children }: PropsWithChildren<AuthGuardProps>) => import("react").ReactNode;
@@ -0,0 +1,22 @@
1
+ import { type PropsWithChildren, type ReactNode } from "react";
2
+ export declare namespace AuthContext {
3
+ export interface Routes {
4
+ authenticated?: string;
5
+ unauthenticated?: string;
6
+ }
7
+ interface Type<TUser = unknown> {
8
+ isAuthenticated: boolean;
9
+ isInitializing: boolean;
10
+ logout: () => void;
11
+ updateTokens?: (accessToken: string | null, refreshToken?: string | null) => void;
12
+ accessToken?: string | null;
13
+ user?: TUser | null;
14
+ userPromise?: () => Promise<TUser | null>;
15
+ routes?: Routes;
16
+ loadingState?: ReactNode;
17
+ }
18
+ type ProviderProps<TUser = unknown> = Type<TUser>;
19
+ export const Provider: <TUser>({ isAuthenticated, isInitializing, logout, updateTokens, accessToken, user, userPromise, routes, loadingState, children, }: PropsWithChildren<ProviderProps<TUser>>) => import("react/jsx-runtime").JSX.Element;
20
+ export const useAuth: <TUser>() => Type<TUser>;
21
+ export {};
22
+ }
@@ -0,0 +1,9 @@
1
+ export declare namespace OpenApiQueryConfig {
2
+ interface Type {
3
+ preferUpdate?: boolean;
4
+ }
5
+ type ProviderProps = Type;
6
+ export const Provider: ({ preferUpdate, children }: React.PropsWithChildren<ProviderProps>) => import("react/jsx-runtime").JSX.Element;
7
+ export const useConfig: () => Type;
8
+ export {};
9
+ }
@@ -0,0 +1,9 @@
1
+ import { type PropsWithChildren } from "react";
2
+ interface RouterProviderProps {
3
+ replace: (url: string) => void;
4
+ }
5
+ export declare namespace OpenApiRouter {
6
+ const Provider: ({ children, replace }: PropsWithChildren<RouterProviderProps>) => import("react/jsx-runtime").JSX.Element;
7
+ const useRouter: () => RouterProviderProps;
8
+ }
9
+ export {};
@@ -0,0 +1,10 @@
1
+ import { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
2
+ import { ApplicationException, GeneralErrorCodes } from "./rest/error-handling";
3
+ type Function = (...args: any) => any;
4
+ type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
5
+ type IsAny<T> = IfAny<T, true, never>;
6
+ type IsUnknown<T, Y, N = T> = IsAny<T> extends never ? (unknown extends T ? Y : N) : N;
7
+ export type AppQueryOptions<TFunction extends Function, TData = Awaited<ReturnType<TFunction>>, TErrorCodes = GeneralErrorCodes> = Omit<UseQueryOptions<Awaited<ReturnType<TFunction>>, ApplicationException<TErrorCodes>, IsUnknown<TData, Awaited<ReturnType<TFunction>>>>, "queryKey" | "queryFn">;
8
+ export type AppMutationOptions<TFunction extends Function, TVariables = void, TData = Awaited<ReturnType<TFunction>>, TErrorCodes = GeneralErrorCodes> = Omit<UseMutationOptions<TData, ApplicationException<TErrorCodes>, TVariables>, "mutationKey" | "mutationFn">;
9
+ export 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">;
10
+ export {};
@@ -0,0 +1,20 @@
1
+ export type GeneralErrorCodes = "DATA_VALIDATION_ERROR" | "NETWORK_ERROR" | "CANCELED_ERROR" | "INTERNAL_ERROR" | "UNKNOWN_ERROR";
2
+ export declare class ApplicationException<CodeT> extends Error {
3
+ code: CodeT;
4
+ serverMessage: string | null;
5
+ constructor(message: string, code: CodeT, serverMessage: string | null);
6
+ }
7
+ export interface ErrorEntry<CodeT> {
8
+ code: CodeT;
9
+ condition: (error: unknown) => boolean;
10
+ getMessage: (error: unknown) => string;
11
+ }
12
+ export declare class ErrorHandler<CodeT extends string> {
13
+ entries: ErrorEntry<CodeT | GeneralErrorCodes>[];
14
+ constructor(entries: ErrorEntry<CodeT>[]);
15
+ rethrowError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes>;
16
+ getError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes> | null;
17
+ getErrorCode(error: unknown): CodeT | GeneralErrorCodes | null;
18
+ static getErrorMessage(error: unknown, fallbackToUnknown?: boolean): string | null;
19
+ }
20
+ export declare const SharedErrorHandler: ErrorHandler<never>;
@@ -0,0 +1,20 @@
1
+ import { AxiosRequestConfig, CreateAxiosDefaults } from "axios";
2
+ import { GeneralErrorCodes } from "./error-handling";
3
+ import { RestInterceptor } from "./rest-interceptor";
4
+ import { RestClient as IRestClient, RequestConfig, RequestInfo, Response } from "./rest-client.types";
5
+ export declare class RestClient implements IRestClient {
6
+ private readonly client;
7
+ constructor({ config, interceptors, }?: {
8
+ config?: CreateAxiosDefaults;
9
+ interceptors?: RestInterceptor<any[]>[];
10
+ });
11
+ attachInterceptors<T extends any[]>(interceptors?: RestInterceptor<T>[], ...args: T): void;
12
+ attachInterceptor<T extends any[]>(interceptor: RestInterceptor<T>, ...args: T): void;
13
+ ejectInterceptor<T extends any[]>(interceptor: RestInterceptor<T>): void;
14
+ get<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
15
+ post<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
16
+ patch<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
17
+ put<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
18
+ delete<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
19
+ private makeRequest;
20
+ }
@@ -0,0 +1,23 @@
1
+ import { AxiosRequestConfig, AxiosResponse } from "axios";
2
+ import { z } from "zod";
3
+ import { ErrorHandler } from "./error-handling";
4
+ import { RestInterceptor } from "./rest-interceptor";
5
+ export type GeneralErrorCodes = string;
6
+ export interface RequestInfo<ZOutput, ECodes extends string> {
7
+ resSchema: z.ZodType<ZOutput>;
8
+ errorHandler?: ErrorHandler<ECodes>;
9
+ }
10
+ export interface RequestConfig<IsRawRes extends boolean = false> {
11
+ rawResponse?: IsRawRes;
12
+ }
13
+ export type Response<ZOutput, IsRawRes extends boolean = false> = IsRawRes extends true ? AxiosResponse<ZOutput> : ZOutput;
14
+ export interface RestClient {
15
+ attachInterceptors<T extends any[]>(interceptors?: RestInterceptor<T>[], ...args: T): void;
16
+ attachInterceptor<T extends any[]>(interceptor: RestInterceptor<T>, ...args: T): void;
17
+ ejectInterceptor<T extends any[]>(interceptor: RestInterceptor<T>): void;
18
+ get<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
19
+ post<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
20
+ patch<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
21
+ put<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
22
+ delete<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
23
+ }
@@ -0,0 +1,8 @@
1
+ import { AxiosInstance } from "axios";
2
+ export declare class RestInterceptor<T extends any[]> {
3
+ private applyInterceptor;
4
+ private interceptorIdMap;
5
+ constructor(applyInterceptor: (client: AxiosInstance, ...args: T) => number);
6
+ addInterceptor(client: AxiosInstance, ...args: T): void;
7
+ removeInterceptor(client: AxiosInstance): void;
8
+ }
@@ -0,0 +1,7 @@
1
+ import { AxiosError, AxiosResponseHeaders } from "axios";
2
+ export declare namespace RestUtils {
3
+ const extractServerResponseCode: (e: unknown) => string | null;
4
+ const doesServerErrorMessageContain: (e: AxiosError, text: string) => boolean;
5
+ const extractServerErrorMessage: (e: unknown) => string | null;
6
+ const extractContentDispositionFilename: (headers: AxiosResponseHeaders) => string | undefined;
7
+ }