这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/openapi-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ declare module '@hey-api/codegen-core' {
category?:
| 'client'
| 'external'
| 'hook'
| 'schema'
| 'sdk'
| 'type'
| 'utility'
| (string & {});
/**
* Path to the resource this symbol represents.
Expand Down
8 changes: 0 additions & 8 deletions packages/openapi-ts/src/plugins/@pinia/colada/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import type { Plugin } from '~/plugins';

type SelectorType =
| '_JSONValue'
| 'AxiosError'
| 'createQueryKey'
| 'defineQueryOptions'
| 'QueryKey'
| 'queryOptionsFn'
| 'serializeQueryKeyValue'
| 'UseMutationOptions'
| 'UseQueryOptions';
Expand All @@ -18,11 +14,7 @@ export type IApi = {
* @param type Selector type.
* @param value Depends on `type`:
* - `_JSONValue`: never
* - `AxiosError`: never
* - `createQueryKey`: never
* - `defineQueryOptions`: never
* - `QueryKey`: never
* - `queryOptionsFn`: `operation.id` string
* - `serializeQueryKeyValue`: never
* - `UseMutationOptions`: never
* - `UseQueryOptions`: never
Expand Down
5 changes: 4 additions & 1 deletion packages/openapi-ts/src/plugins/@pinia/colada/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export const handler: PiniaColadaPlugin['Handler'] = ({ plugin }) => {
plugin.registerSymbol({
external: 'axios',
kind: 'type',
meta: {
category: 'external',
resource: 'axios.AxiosError',
},
name: 'AxiosError',
selector: plugin.api.selector('AxiosError'),
});

const sdkPlugin = plugin.getPluginOrThrow('@hey-api/sdk');
Expand Down
28 changes: 20 additions & 8 deletions packages/openapi-ts/src/plugins/@pinia/colada/queryKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@ export const createQueryKeyFunction = ({
plugin: PiniaColadaPlugin['Instance'];
}) => {
const symbolCreateQueryKey = plugin.registerSymbol({
meta: {
category: 'utility',
resource: 'createQueryKey',
tool: plugin.name,
},
name: buildName({
config: {
case: plugin.config.case,
},
name: 'createQueryKey',
}),
selector: plugin.api.selector('createQueryKey'),
});
const symbolQueryKeyType = plugin.referenceSymbol(
plugin.api.selector('QueryKey'),
);
const symbolQueryKeyType = plugin.referenceSymbol({
category: 'type',
resource: 'QueryKey',
tool: plugin.name,
});
const symbolJsonValue = plugin.referenceSymbol(
plugin.api.selector('_JSONValue'),
);
Expand Down Expand Up @@ -281,9 +287,11 @@ const createQueryKeyLiteral = ({
});
}

const symbolCreateQueryKey = plugin.referenceSymbol(
plugin.api.selector('createQueryKey'),
);
const symbolCreateQueryKey = plugin.referenceSymbol({
category: 'utility',
resource: 'createQueryKey',
tool: plugin.name,
});
const createQueryKeyCallExpression = tsc.callExpression({
functionName: symbolCreateQueryKey.placeholder,
parameters: [tsc.ots.string(id), 'options', tagsExpression],
Expand Down Expand Up @@ -331,8 +339,12 @@ export const createQueryKeyType = ({
const symbolQueryKeyType = plugin.registerSymbol({
exported: true,
kind: 'type',
meta: {
category: 'type',
resource: 'QueryKey',
tool: plugin.name,
},
name: 'QueryKey',
selector: plugin.api.selector('QueryKey'),
});
const queryKeyType = tsc.typeAliasDeclaration({
exportType: symbolQueryKeyType.exported,
Expand Down
24 changes: 19 additions & 5 deletions packages/openapi-ts/src/plugins/@pinia/colada/queryOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ export const createQueryOptions = ({
context: plugin.context,
operation,
});
if (!plugin.getSymbol(plugin.api.selector('createQueryKey'))) {
if (
!plugin.getSymbol({
category: 'utility',
resource: 'createQueryKey',
tool: plugin.name,
})
) {
createQueryKeyType({ plugin });
createQueryKeyFunction({ plugin });
}
Expand All @@ -64,9 +70,11 @@ export const createQueryOptions = ({
parameters: [optionsParamName],
});
} else {
const symbolCreateQueryKey = plugin.referenceSymbol(
plugin.api.selector('createQueryKey'),
);
const symbolCreateQueryKey = plugin.referenceSymbol({
category: 'utility',
resource: 'createQueryKey',
tool: plugin.name,
});
// Optionally include tags when configured
let tagsExpr: ts.Expression | undefined;
if (
Expand Down Expand Up @@ -151,11 +159,17 @@ export const createQueryOptions = ({

const symbolQueryOptionsFn = plugin.registerSymbol({
exported: true,
meta: {
category: 'hook',
resource: 'operation',
resourceId: operation.id,
role: 'queryOptions',
tool: plugin.name,
},
name: buildName({
config: plugin.config.queryOptions,
name: operation.id,
}),
selector: plugin.api.selector('queryOptionsFn', operation.id),
});
const symbolDefineQueryOptions = plugin.registerSymbol({
external: plugin.name,
Expand Down
5 changes: 4 additions & 1 deletion packages/openapi-ts/src/plugins/@pinia/colada/useType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export const useTypeError = ({
typeErrorName = 'Error';
}
if (client.name === '@hey-api/client-axios') {
const symbol = plugin.referenceSymbol(plugin.api.selector('AxiosError'));
const symbol = plugin.referenceSymbol({
category: 'external',
resource: 'axios.AxiosError',
});
typeErrorName = `${symbol.placeholder}<${typeErrorName}>`;
}
return typeErrorName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,3 @@
import type { Selector } from '@hey-api/codegen-core';
export type IApi = any;

import type { Plugin } from '~/plugins';

type SelectorType =
| 'AxiosError'
| 'createInfiniteParams'
| 'createQueryKey'
| 'DefaultError'
| 'infiniteQueryOptions'
| 'InfiniteData'
| 'MutationOptions'
| 'queryOptions'
| 'queryOptionsFn'
| 'QueryKey'
| 'useQuery';

export type IApi = {
/**
* @param type Selector type.
* @param value Depends on `type`:
* - `AxiosError`: never
* - `createInfiniteParams`: never
* - `createQueryKey`: never
* - `DefaultError`: never
* - `infiniteQueryOptions`: never
* - `InfiniteData`: never
* - `MutationOptions`: never
* - `queryOptions`: never
* - `queryOptionsFn`: `operation.id` string
* - `QueryKey`: never
* - `useQuery`: never
* @returns Selector array
* @deprecated
*/
selector: (type: SelectorType, value?: string) => Selector;
};

export class Api implements IApi {
constructor(
public meta: Plugin.Name<'@tanstack/angular-query-experimental'>,
) {}

selector(...args: ReadonlyArray<string | undefined>): Selector {
return [this.meta.name, ...(args as Selector)];
}
}
export class Api implements IApi {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { Api } from './api';
import type { TanStackAngularQueryPlugin } from './types';

export const defaultConfig: TanStackAngularQueryPlugin['Config'] = {
api: new Api({
name: '@tanstack/angular-query-experimental',
}),
api: new Api(),
config: {
case: 'camelCase',
comments: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ const createInfiniteParamsFunction = ({
plugin: PluginInstance;
}) => {
const symbolCreateInfiniteParams = plugin.registerSymbol({
meta: {
category: 'utility',
resource: 'createInfiniteParams',
tool: plugin.name,
},
name: buildName({
config: {
case: plugin.config.case,
},
name: 'createInfiniteParams',
}),
selector: plugin.api.selector('createInfiniteParams'),
});

const fn = tsc.constVariable({
Expand Down Expand Up @@ -242,29 +246,45 @@ export const createInfiniteQueryOptions = ({
operation,
});

if (!plugin.getSymbol(plugin.api.selector('createQueryKey'))) {
if (
!plugin.getSymbol({
category: 'utility',
resource: 'createQueryKey',
tool: plugin.name,
})
) {
createQueryKeyType({ plugin });
createQueryKeyFunction({ plugin });
}

if (!plugin.getSymbol(plugin.api.selector('createInfiniteParams'))) {
if (
!plugin.getSymbol({
category: 'utility',
resource: 'createInfiniteParams',
tool: plugin.name,
})
) {
createInfiniteParamsFunction({ plugin });
}

const symbolInfiniteQueryOptions = plugin.referenceSymbol(
plugin.api.selector('infiniteQueryOptions'),
);
const symbolInfiniteDataType = plugin.referenceSymbol(
plugin.api.selector('InfiniteData'),
);
const symbolInfiniteQueryOptions = plugin.referenceSymbol({
category: 'external',
resource: `${plugin.name}.infiniteQueryOptions`,
});
const symbolInfiniteDataType = plugin.referenceSymbol({
category: 'external',
resource: `${plugin.name}.InfiniteData`,
});

const typeData = useTypeData({ operation, plugin });
const typeError = useTypeError({ operation, plugin });
const typeResponse = useTypeResponse({ operation, plugin });

const symbolQueryKeyType = plugin.referenceSymbol(
plugin.api.selector('QueryKey'),
);
const symbolQueryKeyType = plugin.referenceSymbol({
category: 'type',
resource: 'QueryKey',
tool: plugin.name,
});
const typeQueryKey = `${symbolQueryKeyType.placeholder}<${typeData}>`;
const typePageObjectParam = `Pick<${typeQueryKey}[0], 'body' | 'headers' | 'path' | 'query'>`;
const pluginTypeScript = plugin.getPluginOrThrow('@hey-api/typescript');
Expand Down Expand Up @@ -330,9 +350,11 @@ export const createInfiniteQueryOptions = ({
}),
});

const symbolCreateInfiniteParams = plugin.referenceSymbol(
plugin.api.selector('createInfiniteParams'),
);
const symbolCreateInfiniteParams = plugin.referenceSymbol({
category: 'utility',
resource: 'createInfiniteParams',
tool: plugin.name,
});

const statements: Array<ts.Statement> = [
tsc.constVariable({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ export const createMutationOptions = ({
plugin: PluginInstance;
queryFn: string;
}): void => {
const symbolMutationOptionsType = plugin.referenceSymbol(
plugin.api.selector('MutationOptions'),
);
const symbolMutationOptionsType = plugin.referenceSymbol({
category: 'external',
resource: `${plugin.name}.MutationOptions`,
});

const typeData = useTypeData({ operation, plugin });
const typeError = useTypeError({ operation, plugin });
Expand Down
Loading
Loading