@openapi-qraft/tanstack-query-react-plugin 2.0.0-next.0 → 2.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @openapi-qraft/tanstack-query-react-plugin
2
2
 
3
+ ## 2.0.0-next.1
4
+
5
+ ### Minor Changes
6
+
7
+ - 2a53608: Updated TypeScript to version 5.5.4
8
+ - 76634bf: ### Changeset: `createPredefinedParametersRequestFn`
9
+
10
+ Introduced `createPredefinedParametersRequestFn`, generated by the `@openapi-qraft/cli` using
11
+ the `--operation-predefined-parameters` option.
12
+ This function allows for the automatic application of predefined
13
+ parameters to selected API operations by wrapping the base `requestFn`. It simplifies managing parameters, reducing
14
+ boilerplate code, and supports both static and dynamic values, enhancing flexibility in API request handling.
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [2a53608]
19
+ - Updated dependencies [76634bf]
20
+ - @openapi-qraft/plugin@2.0.0-next.1
21
+
3
22
  ## 2.0.0-next.0
4
23
 
5
24
  ### Major Changes
@@ -1,6 +1,7 @@
1
1
  import { GeneratorFile } from '@openapi-qraft/plugin/lib/GeneratorFile';
2
2
  import { Service } from '@openapi-qraft/plugin/lib/open-api/getServices';
3
3
  import { OutputOptions as OutputOptionsBase } from '@openapi-qraft/plugin/lib/OutputOptions';
4
+ import { PredefinedParametersGlob } from '@openapi-qraft/plugin/lib/predefineSchemaParameters';
4
5
  import { Ora } from 'ora';
5
6
  import { ServiceImportsFactoryOptions } from './ts-factory/getServiceFactory.js';
6
7
  interface OutputOptions extends OutputOptionsBase {
@@ -8,6 +9,7 @@ interface OutputOptions extends OutputOptionsBase {
8
9
  servicesDirName: string;
9
10
  explicitImportExtensions: boolean;
10
11
  exportSchemaTypes: boolean | undefined;
12
+ operationPredefinedParameters: Array<PredefinedParametersGlob> | undefined;
11
13
  }
12
14
  export declare const generateCode: ({ spinner, services, serviceImports, output, }: {
13
15
  spinner: Ora;
@@ -1 +1 @@
1
- {"version":3,"file":"generateCode.d.ts","sourceRoot":"","sources":["../src/generateCode.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,gDAAgD,CAAC;AACzE,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAE7F,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAI1B,OAAO,EAEL,4BAA4B,EAC7B,MAAM,mCAAmC,CAAC;AAG3C,UAAU,aAAc,SAAQ,iBAAiB;IAC/C,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,eAAe,EAAE,MAAM,CAAC;IACxB,wBAAwB,EAAE,OAAO,CAAC;IAClC,iBAAiB,EAAE,OAAO,GAAG,SAAS,CAAC;CACxC;AAED,eAAO,MAAM,YAAY;aAMd,GAAG;cACF,OAAO,EAAE;oBACH,4BAA4B;YACpC,aAAa;8BAQtB,CAAC"}
1
+ {"version":3,"file":"generateCode.d.ts","sourceRoot":"","sources":["../src/generateCode.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,gDAAgD,CAAC;AACzE,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC7F,OAAO,EAAE,wBAAwB,EAAE,MAAM,qDAAqD,CAAC;AAE/F,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAK1B,OAAO,EAEL,4BAA4B,EAC7B,MAAM,mCAAmC,CAAC;AAG3C,UAAU,aAAc,SAAQ,iBAAiB;IAC/C,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,eAAe,EAAE,MAAM,CAAC;IACxB,wBAAwB,EAAE,OAAO,CAAC;IAClC,iBAAiB,EAAE,OAAO,GAAG,SAAS,CAAC;IACvC,6BAA6B,EAAE,KAAK,CAAC,wBAAwB,CAAC,GAAG,SAAS,CAAC;CAC5E;AAED,eAAO,MAAM,YAAY,mDAKtB;IACD,OAAO,EAAE,GAAG,CAAC;IACb,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,cAAc,EAAE,4BAA4B,CAAC;IAC7C,MAAM,EAAE,aAAa,CAAC;CACvB,6BAcA,CAAC"}
@@ -3,6 +3,7 @@ import { formatFileHeader } from '@openapi-qraft/plugin/lib/formatFileHeader';
3
3
  import c from 'ansi-colors';
4
4
  import { astToString } from './ts-factory/astToString.js';
5
5
  import { getClientFactory } from './ts-factory/getClientFactory.js';
6
+ import { getCreatePredefinedParametersRequestFnFactory } from './ts-factory/getCreatePredefinedParametersRequestFnFactory.js';
6
7
  import { getIndexFactory } from './ts-factory/getIndexFactory.js';
7
8
  import { getServiceFactory, } from './ts-factory/getServiceFactory.js';
8
9
  import { getServiceIndexFactory } from './ts-factory/getServiceIndexFactory.js';
@@ -11,6 +12,9 @@ export const generateCode = async ({ spinner, services, serviceImports, output,
11
12
  ...(await generateServices(spinner, services, serviceImports, output)),
12
13
  ...(await generateServiceIndex(spinner, services, output)),
13
14
  ...(await generateClient(spinner, output)),
15
+ ...(output.operationPredefinedParameters
16
+ ? await generateCreatePredefinedParametersRequestFn(spinner, serviceImports, output)
17
+ : []),
14
18
  ...(await generateIndex(spinner, serviceImports, output)),
15
19
  ];
16
20
  };
@@ -91,6 +95,27 @@ const generateClient = async (spinner, output) => {
91
95
  spinner.succeed(c.green('Client has been generated'));
92
96
  return clientFiles;
93
97
  };
98
+ const generateCreatePredefinedParametersRequestFn = async (spinner, serviceImports, output) => {
99
+ spinner.start('Generating "createPredefinedParametersRequestFn"');
100
+ const clientFiles = [];
101
+ try {
102
+ const code = astToString(getCreatePredefinedParametersRequestFnFactory({
103
+ servicesDirName: output.servicesDirName,
104
+ operationPredefinedParameters: output.operationPredefinedParameters,
105
+ openapiTypesImportPath: serviceImports.openapiTypesImportPath,
106
+ }));
107
+ clientFiles.push({
108
+ file: new URL('create-predefined-parameters-request-fn.ts', output.dir),
109
+ code: formatFileHeader(output.fileHeader) + code,
110
+ });
111
+ }
112
+ catch (error) {
113
+ spinner.fail(c.redBright('Error occurred during "createPredefinedParametersRequestFn" generation'));
114
+ throw error;
115
+ }
116
+ spinner.succeed(c.green('"createPredefinedParametersRequestFn" has been generated'));
117
+ return clientFiles;
118
+ };
94
119
  const generateIndex = async (spinner, serviceImports, output) => {
95
120
  spinner.start('Generating index');
96
121
  const indexFiles = [];
@@ -1 +1 @@
1
- {"version":3,"file":"generateCode.js","sourceRoot":"","sources":["../src/generateCode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAI9E,OAAO,CAAC,MAAM,aAAa,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EACL,iBAAiB,GAElB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAShF,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,EACjC,OAAO,EACP,QAAQ,EACR,cAAc,EACd,MAAM,GAMP,EAAE,EAAE;IACH,OAAO;QACL,GAAG,CAAC,MAAM,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;QACtE,GAAG,CAAC,MAAM,oBAAoB,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC1D,GAAG,CAAC,MAAM,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC1C,GAAG,CAAC,MAA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f,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,wCAAwC,CAAC,CAAC,CAAC;QAEpE,MAAM,KAAK,CAAC;IACd,CAAC;IAED,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAC;IAErD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Prepend the import path if it's a relative path.
3
+ * Normally,`openapiTypesImportPath` is a relative path to the services' directory.
4
+ */
5
+ export declare function maybeResolveImport<T extends string | undefined>({ openapiTypesImportPath, servicesDirName, }: {
6
+ openapiTypesImportPath: T;
7
+ servicesDirName: string;
8
+ }): string | T;
9
+ //# sourceMappingURL=maybeResolveImport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maybeResolveImport.d.ts","sourceRoot":"","sources":["../../src/lib/maybeResolveImport.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,EAAE,EAC/D,sBAAsB,EACtB,eAAe,GAChB,EAAE;IACD,sBAAsB,EAAE,CAAC,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;CACzB,cAQA"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Prepend the import path if it's a relative path.
3
+ * Normally,`openapiTypesImportPath` is a relative path to the services' directory.
4
+ */
5
+ export function maybeResolveImport({ openapiTypesImportPath, servicesDirName, }) {
6
+ if (openapiTypesImportPath?.startsWith('../')) {
7
+ return `./${openapiTypesImportPath.slice(3)}`;
8
+ }
9
+ else if (openapiTypesImportPath?.startsWith('./')) {
10
+ return `./${servicesDirName}/${openapiTypesImportPath.slice(2)}`;
11
+ }
12
+ return openapiTypesImportPath;
13
+ }
14
+ //# sourceMappingURL=maybeResolveImport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maybeResolveImport.js","sourceRoot":"","sources":["../../src/lib/maybeResolveImport.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAA+B,EAC/D,sBAAsB,EACtB,eAAe,GAIhB;IACC,IAAI,sBAAsB,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9C,OAAO,KAAK,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAChD,CAAC;SAAM,IAAI,sBAAsB,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACpD,OAAO,KAAK,eAAe,IAAI,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,CAAC;IAED,OAAO,sBAAsB,CAAC;AAChC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAGlF,eAAO,MAAM,MAAM,EAAE,kBA0CpB,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAGlF,eAAO,MAAM,MAAM,EAAE,kBAkDpB,CAAC"}
package/dist/plugin.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { fileHeader } from '@openapi-qraft/plugin/lib/fileHeader';
2
+ import { createPredefinedParametersGlobs, parseOperationPredefinedParametersOption, } from '@openapi-qraft/plugin/lib/predefineSchemaParameters';
2
3
  import { generateCode } from './generateCode.js';
3
4
  export const plugin = {
4
5
  setupCommand(command) {
@@ -10,7 +11,7 @@ export const plugin = {
10
11
  return arg?.toLowerCase() !== 'false';
11
12
  })
12
13
  .option('--operation-generics-import-path <path>', 'Path to operation generics file', '@openapi-qraft/react')
13
- .action(async ({ spinner, output, args, services }, resolve) => {
14
+ .action(async ({ spinner, output, args, services, schema }, resolve) => {
14
15
  return void (await generateCode({
15
16
  spinner,
16
17
  services,
@@ -24,6 +25,9 @@ export const plugin = {
24
25
  explicitImportExtensions: args.explicitImportExtensions,
25
26
  servicesDirName: 'services',
26
27
  exportSchemaTypes: args.exportOpenapiTypes,
28
+ operationPredefinedParameters: args.operationPredefinedParameters
29
+ ? createPredefinedParametersGlobs(schema, parseOperationPredefinedParametersOption(...args.operationPredefinedParameters))
30
+ : undefined, // inherited from `--operation-predefined-parameters` option
27
31
  },
28
32
  }).then(resolve));
29
33
  });
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAGlE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,CAAC,MAAM,MAAM,GAAuB;IACxC,YAAY,CAAC,OAAqB;QAChC,OAAO;aACJ,WAAW,CAAC,0DAA0D,CAAC;aACvE,cAAc,CACb,oCAAoC,EACpC,yDAAyD,CAC1D;aACA,MAAM,CACL,8BAA8B,EAC9B,4GAA4G,CAC7G;aACA,MAAM,CACL,+BAA+B,EAC/B,sEAAsE,EACtE,CAAC,GAAG,EAAE,EAAE;YACN,OAAO,GAAG,EAAE,WAAW,EAAE,KAAK,OAAO,CAAC;QACxC,CAAC,CACF;aACA,MAAM,CACL,yCAAyC,EACzC,iCAAiC,EACjC,sBAAsB,CACvB;aACA,MAAM,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,EAAE;YAC7D,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;gBAC9B,OAAO;gBACP,QAAQ;gBACR,cAAc,EAAE;oBACd,2BAA2B,EAAE,IAAI,CAAC,2BAA2B;oBAC7D,sBAAsB,EAAE,IAAI,CAAC,sBAAsB;iBACpD;gBACD,MAAM,EAAE;oBACN,GAAG,MAAM;oBACT,UAAU,E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,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,UAAU;oBACzC,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;oBACvD,eAAe,EAAE,UAAU;oBAC3B,iBAAiB,EAAE,IAAI,CAAC,kBAAkB;oBAC1C,6BAA6B,EAAE,IAAI,CAAC,6BAA6B;wBAC/D,CAAC,CAAC,+BAA+B,CAC7B,MAAM,EACN,wCAAwC,CACtC,GAAG,IAAI,CAAC,6BAA6B,CACtC,CACF;wBACH,CAAC,CAAC,SAAS,EAAE,4DAA4D;iBAC5E;aACF,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACP,CAAC;CACF,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { PredefinedParametersGlob } from '@openapi-qraft/plugin/lib/predefineSchemaParameters';
2
+ import ts from 'typescript';
3
+ type Options = {
4
+ servicesDirName: string;
5
+ operationPredefinedParameters: Array<PredefinedParametersGlob> | undefined;
6
+ openapiTypesImportPath: string | undefined;
7
+ };
8
+ export declare const getCreatePredefinedParametersRequestFnFactory: (options: Options) => (ts.ImportDeclaration | ts.FunctionDeclaration | ts.TypeAliasDeclaration | ts.VariableStatement)[];
9
+ export {};
10
+ //# sourceMappingURL=getCreatePredefinedParametersRequestFnFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCreatePredefinedParametersRequestFnFactory.d.ts","sourceRoot":"","sources":["../../src/ts-factory/getCreatePredefinedParametersRequestFnFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qDAAqD,CAAC;AAC/F,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,KAAK,OAAO,GAAG;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,6BAA6B,EAAE,KAAK,CAAC,wBAAwB,CAAC,GAAG,SAAS,CAAC;IAC3E,sBAAsB,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5C,CAAC;AAEF,eAAO,MAAM,6CAA6C,YAC/C,OAAO,uGAWjB,CAAC"}
@@ -0,0 +1,89 @@
1
+ import ts from 'typescript';
2
+ import { maybeResolveImport } from '../lib/maybeResolveImport.js';
3
+ export const getCreatePredefinedParametersRequestFnFactory = (options) => {
4
+ if (!options.openapiTypesImportPath)
5
+ return [];
6
+ if (!options.operationPredefinedParameters?.length)
7
+ return [];
8
+ return [
9
+ ...getCreatePredefinedParametersRequestFnImportsFactory(options),
10
+ ...getCreatePredefinedParametersRequestFnTypesFactory(options),
11
+ ...getCreatePredefinedParametersRequestFnVariablesFactory(options),
12
+ ...getCreatePredefinedParametersRequestFnFunctionFactory(options),
13
+ ];
14
+ };
15
+ const getCreatePredefinedParametersRequestFnImportsFactory = ({ servicesDirName, openapiTypesImportPath, }) => {
16
+ if (!openapiTypesImportPath)
17
+ return [];
18
+ const factory = ts.factory;
19
+ return [
20
+ factory.createImportDeclaration(undefined, factory.createImportClause(true, undefined, factory.createNamedImports([
21
+ factory.createImportSpecifier(false, undefined, factory.createIdentifier('RequestFn')),
22
+ ])), factory.createStringLiteral('@openapi-qraft/react'), undefined),
23
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
24
+ factory.createImportSpecifier(false, undefined, factory.createIdentifier('qraftPredefinedParametersRequestFn')),
25
+ factory.createImportSpecifier(false, undefined, factory.createIdentifier('QraftPredefinedParameterValue')),
26
+ ])), factory.createStringLiteral('@openapi-qraft/react/qraftPredefinedParametersRequestFn'), undefined),
27
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
28
+ factory.createImportSpecifier(false, undefined, factory.createIdentifier('paths')),
29
+ ])), factory.createStringLiteral(maybeResolveImport({ openapiTypesImportPath, servicesDirName })), undefined),
30
+ ];
31
+ };
32
+ const getCreatePredefinedParametersRequestFnTypesFactory = ({ operationPredefinedParameters, }) => {
33
+ if (!operationPredefinedParameters)
34
+ return [];
35
+ const factory = ts.factory;
36
+ return [
37
+ factory.createTypeAliasDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier('ServiceOperationsPredefinedParameters'), undefined, factory.createTupleTypeNode(operationPredefinedParameters.map((item) => {
38
+ return factory.createTypeLiteralNode([
39
+ factory.createPropertySignature(undefined, factory.createIdentifier('requestPattern'), undefined, factory.createLiteralTypeNode(factory.createStringLiteral(`${item.methods.join(',')} ${item.pathGlobs}`))),
40
+ factory.createPropertySignature(undefined, factory.createIdentifier('parameters'), undefined, factory.createTupleTypeNode(item.parameters.map((parameter) => factory.createTypeLiteralNode([
41
+ factory.createPropertySignature(undefined, factory.createIdentifier('in'), undefined, factory.createLiteralTypeNode(factory.createStringLiteral(parameter.in))),
42
+ factory.createPropertySignature(undefined, factory.createIdentifier('name'), undefined, factory.createLiteralTypeNode(factory.createStringLiteral(parameter.name))),
43
+ factory.createPropertySignature(undefined, factory.createIdentifier('value'), undefined, factory.createTypeReferenceNode(factory.createIdentifier('QraftPredefinedParameterValue'), [
44
+ factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(factory.createIdentifier('NonNullable'), [
45
+ factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(factory.createIdentifier('paths'), undefined), factory.createLiteralTypeNode(factory.createStringLiteral(item.paths[0]))), factory.createLiteralTypeNode(factory.createStringLiteral(item.methods ? item.methods[0] : 'get'))), factory.createLiteralTypeNode(factory.createStringLiteral('parameters'))), factory.createLiteralTypeNode(factory.createStringLiteral(parameter.in))),
46
+ ]), factory.createLiteralTypeNode(factory.createStringLiteral(parameter.name))),
47
+ ])),
48
+ ])))),
49
+ ]);
50
+ }))),
51
+ ];
52
+ };
53
+ const getCreatePredefinedParametersRequestFnVariablesFactory = ({ operationPredefinedParameters, }) => {
54
+ if (!operationPredefinedParameters)
55
+ return [];
56
+ const factory = ts.factory;
57
+ return [
58
+ factory.createVariableStatement([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([
59
+ factory.createVariableDeclaration(factory.createIdentifier('serviceOperationsPredefinedParameters'), undefined, undefined, factory.createAsExpression(factory.createArrayLiteralExpression(operationPredefinedParameters.map((item) => factory.createObjectLiteralExpression([
60
+ factory.createPropertyAssignment(factory.createIdentifier('requestPattern'), factory.createStringLiteral(`${item.methods.join(',')} ${item.pathGlobs}`)),
61
+ factory.createPropertyAssignment(factory.createIdentifier('methods'), factory.createArrayLiteralExpression(item.methods.map((method) => factory.createStringLiteral(method)), false)),
62
+ factory.createPropertyAssignment(factory.createIdentifier('paths'), factory.createArrayLiteralExpression(item.paths.map((path) => factory.createStringLiteral(path)), true)),
63
+ ], true)), true), factory.createTypeReferenceNode(factory.createIdentifier('const'), undefined))),
64
+ ], ts.NodeFlags.Const)),
65
+ ];
66
+ };
67
+ const getCreatePredefinedParametersRequestFnFunctionFactory = ({ operationPredefinedParameters, }) => {
68
+ if (!operationPredefinedParameters)
69
+ return [];
70
+ const factory = ts.factory;
71
+ return [
72
+ factory.createFunctionDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], undefined, factory.createIdentifier('createPredefinedParametersRequestFn'), [
73
+ factory.createTypeParameterDeclaration(undefined, factory.createIdentifier('TRequestFn'), factory.createTypeReferenceNode(factory.createIdentifier('RequestFn'), [
74
+ factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),
75
+ factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),
76
+ ]), undefined),
77
+ ], [
78
+ factory.createParameterDeclaration(undefined, undefined, factory.createIdentifier('predefinedParameters'), undefined, factory.createTypeReferenceNode(factory.createIdentifier('ServiceOperationsPredefinedParameters'), undefined), undefined),
79
+ factory.createParameterDeclaration(undefined, undefined, factory.createIdentifier('requestFn'), undefined, factory.createTypeReferenceNode(factory.createIdentifier('TRequestFn'), undefined), undefined),
80
+ ], factory.createTypeReferenceNode(factory.createIdentifier('TRequestFn'), undefined), factory.createBlock([
81
+ factory.createReturnStatement(factory.createAsExpression(factory.createCallExpression(factory.createIdentifier('qraftPredefinedParametersRequestFn'), undefined, [
82
+ factory.createIdentifier('predefinedParameters'),
83
+ factory.createIdentifier('serviceOperationsPredefinedParameters'),
84
+ factory.createIdentifier('requestFn'),
85
+ ]), factory.createTypeReferenceNode(factory.createIdentifier('TRequestFn'), undefined))),
86
+ ], true)),
87
+ ];
88
+ };
89
+ //# sourceMappingURL=getCreatePredefinedParametersRequestFnFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCreatePredefinedParametersRequestFnFactory.js","sourceRoot":"","sources":["../../src/ts-factory/getCreatePredefinedParametersRequestFnFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAQlE,MAAM,CAAC,MAAM,6CAA6C,GAAG,CAC3D,OAAgB,EAChB,EAAE;IACF,IAAI,CAAC,OAAO,CAAC,sBAAsB;QAAE,OAAO,EAAE,CAAC;IAC/C,IAAI,CAAC,OAAO,CAAC,6BAA6B,EAAE,MAAM;QAAE,OAAO,EAAE,CAAC;IAE9D,OAAO;QACL,GAAG,oDAAoD,CAAC,OAAO,CAAC;QAChE,GAAG,kDAAkD,CAAC,OAAO,CAAC;QAC9D,GAAG,sDAAsD,CAAC,OAAO,CAAC;QAClE,GAAG,qDAAqD,CAAC,OAAO,CAAC;KAClE,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,oDAAoD,GAAG,CAAC,EAC5D,eAAe,EACf,sBAAsB,GACd,EAAE,EAAE;IACZ,IAAI,CAAC,sBAAsB;QAAE,OAAO,EAAE,CAAC;IAEvC,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC;IAE3B,OAAO;QACL,OAAO,CAAC,uBAAuB,CAC7B,SAAS,EACT,OAAO,CAAC,kBAAkB,CACxB,IAAI,EACJ,SAAS,EACT,OAAO,CAAC,kBAAkB,CAAC;YACzB,OA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AoB,CAC1B,OAAO,CAAC,gBAAgB,CAAC,oCAAoC,CAAC,EAC9D,SAAS,EACT;gBACE,OAAO,CAAC,gBAAgB,CAAC,sBAAsB,CAAC;gBAChD,OAAO,CAAC,gBAAgB,CACtB,uCAAuC,CACxC;gBACD,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC;aACtC,CACF,EACD,OAAO,CAAC,uBAAuB,CAC7B,OAAO,CAAC,gBAAgB,CAAC,YAAY,CAAC,EACtC,SAAS,CACV,CACF,CACF;SACF,EACD,IAAI,CACL,CACF;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -4,12 +4,4 @@ export declare const getIndexFactory: ({ openapiTypesImportPath, servicesDirName
4
4
  servicesDirName: string;
5
5
  explicitImportExtensions: boolean;
6
6
  } & Partial<Pick<ServiceImportsFactoryOptions, "openapiTypesImportPath">>) => ts.ExportDeclaration[];
7
- /**
8
- * Prepend the import path if it's a relative path.
9
- * Normally,`openapiTypesImportPath` is a relative path to the services' directory.
10
- */
11
- export declare function maybeResolveImport<T extends string | undefined>({ openapiTypesImportPath, servicesDirName, }: {
12
- openapiTypesImportPath: T;
13
- servicesDirName: string;
14
- }): string | T;
15
7
  //# sourceMappingURL=getIndexFactory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getIndexFactory.d.ts","sourceRoot":"","sources":["../../src/ts-factory/getIndexFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,eAAO,MAAM,eAAe;qBAKT,MAAM;8BACG,OAAO;oGA+DlC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,EAAE,EAC/D,sBAAsB,EACtB,eAAe,GAChB,EAAE;IACD,sBAAsB,EAAE,CAAC,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;CACzB,cAQA"}
1
+ {"version":3,"file":"getIndexFactory.d.ts","sourceRoot":"","sources":["../../src/ts-factory/getIndexFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,eAAO,MAAM,eAAe,2EAIzB;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,wBAAwB,EAAE,OAAO,CAAC;CACnC,GAAG,OAAO,CAAC,IAAI,CAAC,4BAA4B,EAAE,wBAAwB,CAAC,CAAC,2BA8DxE,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import ts from 'typescript';
2
+ import { maybeResolveImport } from '../lib/maybeResolveImport.js';
2
3
  export const getIndexFactory = ({ openapiTypesImportPath, servicesDirName, explicitImportExtensions, }) => {
3
4
  const factory = ts.factory;
4
5
  const importExtension = explicitImportExtensions ? '.js' : '';
@@ -19,17 +20,4 @@ export const getIndexFactory = ({ openapiTypesImportPath, servicesDirName, expli
19
20
  ]), factory.createStringLiteral(`./create-api-client${importExtension}`), undefined),
20
21
  ];
21
22
  };
22
- /**
23
- * Prepend the import path if it's a relative path.
24
- * Normally,`openapiTypesImportPath` is a relative path to the services' directory.
25
- */
26
- export function maybeResolveImport({ openapiTypesImportPath, servicesDirName, }) {
27
- if (openapiTypesImportPath?.startsWith('../')) {
28
- return `./${openapiTypesImportPath.slice(3)}`;
29
- }
30
- else if (openapiTypesImportPath?.startsWith('./')) {
31
- return `./${servicesDirName}/${openapiTypesImportPath.slice(2)}`;
32
- }
33
- return openapiTypesImportPath;
34
- }
35
23
  //# sourceMappingURL=getIndexFactory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getIndexFactory.js","sourceRoot":"","sources":["../../src/ts-factory/getIndexFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAC9B,sBAAsB,EACtB,eAAe,EACf,wBAAw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,EACT,KAAK,EACL,OAAO,CAAC,kBAAkB,CAAC;YACzB,OAAO,CAAC,qBAAqB,CAC3B,KAAK,EACL,SAAS,EACT,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC,CACrC;SACF,CAAC,EACF,OAAO,CAAC,mBAAmB,CACzB,KAAK,eAAe,SAAS,eAAe,EAAE,CAC/C,EACD,SAAS,CACV;QACD,OAAO,CAAC,uBAAuB,CAC7B,SAAS,EACT,IAAI,EACJ,OAAO,CAAC,kBAAkB,CAAC;YACzB,OAAO,CAAC,qBAAqB,CAC3B,KAAK,EACL,SAAS,EACT,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC,CACrC;SACF,CAAC,EACF,OAAO,CAAC,mBAAmB,CACzB,KAAK,eAAe,SAAS,eAAe,EAAE,CAC/C,EACD,SAAS,CACV;QACD,OAAO,CAAC,uBAAuB,CAC7B,SAAS,EACT,KAAK,EACL,OAAO,CAAC,kBAAkB,CAAC;YACzB,OAAO,CAAC,qBAAqB,CAC3B,KAAK,EACL,SAAS,EACT,OAAO,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAC5C;SACF,CAAC,EACF,OAAO,CAAC,mBAAmB,CAAC,sBAAsB,eAAe,EAAE,CAAC,EACpE,SAAS,CACV;KACF,CAAC;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openapi-qraft/tanstack-query-react-plugin",
3
- "version": "2.0.0-next.0",
3
+ "version": "2.0.0-next.1",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "tsc --project tsconfig.build.json",
@@ -26,8 +26,8 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
- "@openapi-qraft/plugin": "^2.0.0-next.0",
30
- "typescript": "^5.3.3"
29
+ "@openapi-qraft/plugin": "^2.0.0-next.1",
30
+ "typescript": "^5.5.4"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@openapi-qraft/eslint-config": "1.0.0",
@@ -3,10 +3,12 @@ import { formatFileHeader } from '@openapi-qraft/plugin/lib/formatFileHeader';
3
3
  import { GeneratorFile } from '@openapi-qraft/plugin/lib/GeneratorFile';
4
4
  import { Service } from '@openapi-qraft/plugin/lib/open-api/getServices';
5
5
  import { OutputOptions as OutputOptionsBase } from '@openapi-qraft/plugin/lib/OutputOptions';
6
+ import { PredefinedParametersGlob } from '@openapi-qraft/plugin/lib/predefineSchemaParameters';
6
7
  import c from 'ansi-colors';
7
8
  import { Ora } from 'ora';
8
9
  import { astToString } from './ts-factory/astToString.js';
9
10
  import { getClientFactory } from './ts-factory/getClientFactory.js';
11
+ import { getCreatePredefinedParametersRequestFnFactory } from './ts-factory/getCreatePredefinedParametersRequestFnFactory.js';
10
12
  import { getIndexFactory } from './ts-factory/getIndexFactory.js';
11
13
  import {
12
14
  getServiceFactory,
@@ -19,6 +21,7 @@ interface OutputOptions extends OutputOptionsBase {
19
21
  servicesDirName: string;
20
22
  explicitImportExtensions: boolean;
21
23
  exportSchemaTypes: boolean | undefined;
24
+ operationPredefinedParameters: Array<PredefinedParametersGlob> | undefined;
22
25
  }
23
26
 
24
27
  export const generateCode = async ({
@@ -36,6 +39,13 @@ export const generateCode = async ({
36
39
  ...(await generateServices(spinner, services, serviceImports, output)),
37
40
  ...(await generateServiceIndex(spinner, services, output)),
38
41
  ...(await generateClient(spinner, output)),
42
+ ...(output.operationPredefinedParameters
43
+ ? await generateCreatePredefinedParametersRequestFn(
44
+ spinner,
45
+ serviceImports,
46
+ output
47
+ )
48
+ : []),
39
49
  ...(await generateIndex(spinner, serviceImports, output)),
40
50
  ];
41
51
  };
@@ -166,6 +176,45 @@ const generateClient = async (spinner: Ora, output: OutputOptions) => {
166
176
  return clientFiles;
167
177
  };
168
178
 
179
+ const generateCreatePredefinedParametersRequestFn = async (
180
+ spinner: Ora,
181
+ serviceImports: ServiceImportsFactoryOptions,
182
+ output: OutputOptions
183
+ ) => {
184
+ spinner.start('Generating "createPredefinedParametersRequestFn"');
185
+
186
+ const clientFiles: GeneratorFile[] = [];
187
+
188
+ try {
189
+ const code = astToString(
190
+ getCreatePredefinedParametersRequestFnFactory({
191
+ servicesDirName: output.servicesDirName,
192
+ operationPredefinedParameters: output.operationPredefinedParameters,
193
+ openapiTypesImportPath: serviceImports.openapiTypesImportPath,
194
+ })
195
+ );
196
+
197
+ clientFiles.push({
198
+ file: new URL('create-predefined-parameters-request-fn.ts', output.dir),
199
+ code: formatFileHeader(output.fileHeader) + code,
200
+ });
201
+ } catch (error) {
202
+ spinner.fail(
203
+ c.redBright(
204
+ 'Error occurred during "createPredefinedParametersRequestFn" generation'
205
+ )
206
+ );
207
+
208
+ throw error;
209
+ }
210
+
211
+ spinner.succeed(
212
+ c.green('"createPredefinedParametersRequestFn" has been generated')
213
+ );
214
+
215
+ return clientFiles;
216
+ };
217
+
169
218
  const generateIndex = async (
170
219
  spinner: Ora,
171
220
  serviceImports: ServiceImportsFactoryOptions,
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Prepend the import path if it's a relative path.
3
+ * Normally,`openapiTypesImportPath` is a relative path to the services' directory.
4
+ */
5
+ export function maybeResolveImport<T extends string | undefined>({
6
+ openapiTypesImportPath,
7
+ servicesDirName,
8
+ }: {
9
+ openapiTypesImportPath: T;
10
+ servicesDirName: string;
11
+ }) {
12
+ if (openapiTypesImportPath?.startsWith('../')) {
13
+ return `./${openapiTypesImportPath.slice(3)}`;
14
+ } else if (openapiTypesImportPath?.startsWith('./')) {
15
+ return `./${servicesDirName}/${openapiTypesImportPath.slice(2)}`;
16
+ }
17
+
18
+ return openapiTypesImportPath;
19
+ }
package/src/plugin.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import { fileHeader } from '@openapi-qraft/plugin/lib/fileHeader';
2
+ import {
3
+ createPredefinedParametersGlobs,
4
+ parseOperationPredefinedParametersOption,
5
+ } from '@openapi-qraft/plugin/lib/predefineSchemaParameters';
2
6
  import { QraftCommand } from '@openapi-qraft/plugin/lib/QraftCommand';
3
7
  import { QraftCommandPlugin } from '@openapi-qraft/plugin/lib/QraftCommandPlugin';
4
8
  import { generateCode } from './generateCode.js';
@@ -27,7 +31,7 @@ export const plugin: QraftCommandPlugin = {
27
31
  'Path to operation generics file',
28
32
  '@openapi-qraft/react'
29
33
  )
30
- .action(async ({ spinner, output, args, services }, resolve) => {
34
+ .action(async ({ spinner, output, args, services, schema }, resolve) => {
31
35
  return void (await generateCode({
32
36
  spinner,
33
37
  services,
@@ -41,6 +45,14 @@ export const plugin: QraftCommandPlugin = {
41
45
  explicitImportExtensions: args.explicitImportExtensions,
42
46
  servicesDirName: 'services',
43
47
  exportSchemaTypes: args.exportOpenapiTypes,
48
+ operationPredefinedParameters: args.operationPredefinedParameters
49
+ ? createPredefinedParametersGlobs(
50
+ schema,
51
+ parseOperationPredefinedParametersOption(
52
+ ...args.operationPredefinedParameters
53
+ )
54
+ )
55
+ : undefined, // inherited from `--operation-predefined-parameters` option
44
56
  },
45
57
  }).then(resolve));
46
58
  });
@@ -0,0 +1,346 @@
1
+ import { PredefinedParametersGlob } from '@openapi-qraft/plugin/lib/predefineSchemaParameters';
2
+ import ts from 'typescript';
3
+ import { maybeResolveImport } from '../lib/maybeResolveImport.js';
4
+
5
+ type Options = {
6
+ servicesDirName: string;
7
+ operationPredefinedParameters: Array<PredefinedParametersGlob> | undefined;
8
+ openapiTypesImportPath: string | undefined;
9
+ };
10
+
11
+ export const getCreatePredefinedParametersRequestFnFactory = (
12
+ options: Options
13
+ ) => {
14
+ if (!options.openapiTypesImportPath) return [];
15
+ if (!options.operationPredefinedParameters?.length) return [];
16
+
17
+ return [
18
+ ...getCreatePredefinedParametersRequestFnImportsFactory(options),
19
+ ...getCreatePredefinedParametersRequestFnTypesFactory(options),
20
+ ...getCreatePredefinedParametersRequestFnVariablesFactory(options),
21
+ ...getCreatePredefinedParametersRequestFnFunctionFactory(options),
22
+ ];
23
+ };
24
+
25
+ const getCreatePredefinedParametersRequestFnImportsFactory = ({
26
+ servicesDirName,
27
+ openapiTypesImportPath,
28
+ }: Options) => {
29
+ if (!openapiTypesImportPath) return [];
30
+
31
+ const factory = ts.factory;
32
+
33
+ return [
34
+ factory.createImportDeclaration(
35
+ undefined,
36
+ factory.createImportClause(
37
+ true,
38
+ undefined,
39
+ factory.createNamedImports([
40
+ factory.createImportSpecifier(
41
+ false,
42
+ undefined,
43
+ factory.createIdentifier('RequestFn')
44
+ ),
45
+ ])
46
+ ),
47
+ factory.createStringLiteral('@openapi-qraft/react'),
48
+ undefined
49
+ ),
50
+ factory.createImportDeclaration(
51
+ undefined,
52
+ factory.createImportClause(
53
+ false,
54
+ undefined,
55
+ factory.createNamedImports([
56
+ factory.createImportSpecifier(
57
+ false,
58
+ undefined,
59
+ factory.createIdentifier('qraftPredefinedParametersRequestFn')
60
+ ),
61
+ factory.createImportSpecifier(
62
+ false,
63
+ undefined,
64
+ factory.createIdentifier('QraftPredefinedParameterValue')
65
+ ),
66
+ ])
67
+ ),
68
+ factory.createStringLiteral(
69
+ '@openapi-qraft/react/qraftPredefinedParametersRequestFn'
70
+ ),
71
+ undefined
72
+ ),
73
+ factory.createImportDeclaration(
74
+ undefined,
75
+ factory.createImportClause(
76
+ false,
77
+ undefined,
78
+ factory.createNamedImports([
79
+ factory.createImportSpecifier(
80
+ false,
81
+ undefined,
82
+ factory.createIdentifier('paths')
83
+ ),
84
+ ])
85
+ ),
86
+ factory.createStringLiteral(
87
+ maybeResolveImport({ openapiTypesImportPath, servicesDirName })
88
+ ),
89
+ undefined
90
+ ),
91
+ ];
92
+ };
93
+
94
+ const getCreatePredefinedParametersRequestFnTypesFactory = ({
95
+ operationPredefinedParameters,
96
+ }: Options) => {
97
+ if (!operationPredefinedParameters) return [];
98
+
99
+ const factory = ts.factory;
100
+
101
+ return [
102
+ factory.createTypeAliasDeclaration(
103
+ [factory.createToken(ts.SyntaxKind.ExportKeyword)],
104
+ factory.createIdentifier('ServiceOperationsPredefinedParameters'),
105
+ undefined,
106
+ factory.createTupleTypeNode(
107
+ operationPredefinedParameters.map((item) => {
108
+ return factory.createTypeLiteralNode([
109
+ factory.createPropertySignature(
110
+ undefined,
111
+ factory.createIdentifier('requestPattern'),
112
+ undefined,
113
+ factory.createLiteralTypeNode(
114
+ factory.createStringLiteral(
115
+ `${item.methods.join(',')} ${item.pathGlobs}`
116
+ )
117
+ )
118
+ ),
119
+ factory.createPropertySignature(
120
+ undefined,
121
+ factory.createIdentifier('parameters'),
122
+ undefined,
123
+ factory.createTupleTypeNode(
124
+ item.parameters.map((parameter) =>
125
+ factory.createTypeLiteralNode([
126
+ factory.createPropertySignature(
127
+ undefined,
128
+ factory.createIdentifier('in'),
129
+ undefined,
130
+ factory.createLiteralTypeNode(
131
+ factory.createStringLiteral(parameter.in)
132
+ )
133
+ ),
134
+ factory.createPropertySignature(
135
+ undefined,
136
+ factory.createIdentifier('name'),
137
+ undefined,
138
+ factory.createLiteralTypeNode(
139
+ factory.createStringLiteral(parameter.name)
140
+ )
141
+ ),
142
+ factory.createPropertySignature(
143
+ undefined,
144
+ factory.createIdentifier('value'),
145
+ undefined,
146
+ factory.createTypeReferenceNode(
147
+ factory.createIdentifier(
148
+ 'QraftPredefinedParameterValue'
149
+ ),
150
+ [
151
+ factory.createIndexedAccessTypeNode(
152
+ factory.createTypeReferenceNode(
153
+ factory.createIdentifier('NonNullable'),
154
+ [
155
+ factory.createIndexedAccessTypeNode(
156
+ factory.createIndexedAccessTypeNode(
157
+ factory.createIndexedAccessTypeNode(
158
+ factory.createIndexedAccessTypeNode(
159
+ factory.createTypeReferenceNode(
160
+ factory.createIdentifier('paths'),
161
+ undefined
162
+ ),
163
+ factory.createLiteralTypeNode(
164
+ factory.createStringLiteral(
165
+ item.paths[0]
166
+ )
167
+ )
168
+ ),
169
+ factory.createLiteralTypeNode(
170
+ factory.createStringLiteral(
171
+ item.methods ? item.methods[0] : 'get'
172
+ )
173
+ )
174
+ ),
175
+ factory.createLiteralTypeNode(
176
+ factory.createStringLiteral('parameters')
177
+ )
178
+ ),
179
+ factory.createLiteralTypeNode(
180
+ factory.createStringLiteral(parameter.in)
181
+ )
182
+ ),
183
+ ]
184
+ ),
185
+ factory.createLiteralTypeNode(
186
+ factory.createStringLiteral(parameter.name)
187
+ )
188
+ ),
189
+ ]
190
+ )
191
+ ),
192
+ ])
193
+ )
194
+ )
195
+ ),
196
+ ]);
197
+ })
198
+ )
199
+ ),
200
+ ];
201
+ };
202
+ const getCreatePredefinedParametersRequestFnVariablesFactory = ({
203
+ operationPredefinedParameters,
204
+ }: Options) => {
205
+ if (!operationPredefinedParameters) return [];
206
+
207
+ const factory = ts.factory;
208
+
209
+ return [
210
+ factory.createVariableStatement(
211
+ [factory.createToken(ts.SyntaxKind.ExportKeyword)],
212
+ factory.createVariableDeclarationList(
213
+ [
214
+ factory.createVariableDeclaration(
215
+ factory.createIdentifier('serviceOperationsPredefinedParameters'),
216
+ undefined,
217
+ undefined,
218
+ factory.createAsExpression(
219
+ factory.createArrayLiteralExpression(
220
+ operationPredefinedParameters.map((item) =>
221
+ factory.createObjectLiteralExpression(
222
+ [
223
+ factory.createPropertyAssignment(
224
+ factory.createIdentifier('requestPattern'),
225
+ factory.createStringLiteral(
226
+ `${item.methods.join(',')} ${item.pathGlobs}`
227
+ )
228
+ ),
229
+ factory.createPropertyAssignment(
230
+ factory.createIdentifier('methods'),
231
+ factory.createArrayLiteralExpression(
232
+ item.methods.map((method) =>
233
+ factory.createStringLiteral(method)
234
+ ),
235
+ false
236
+ )
237
+ ),
238
+ factory.createPropertyAssignment(
239
+ factory.createIdentifier('paths'),
240
+ factory.createArrayLiteralExpression(
241
+ item.paths.map((path) =>
242
+ factory.createStringLiteral(path)
243
+ ),
244
+ true
245
+ )
246
+ ),
247
+ ],
248
+ true
249
+ )
250
+ ),
251
+ true
252
+ ),
253
+ factory.createTypeReferenceNode(
254
+ factory.createIdentifier('const'),
255
+ undefined
256
+ )
257
+ )
258
+ ),
259
+ ],
260
+ ts.NodeFlags.Const
261
+ )
262
+ ),
263
+ ];
264
+ };
265
+
266
+ const getCreatePredefinedParametersRequestFnFunctionFactory = ({
267
+ operationPredefinedParameters,
268
+ }: Options) => {
269
+ if (!operationPredefinedParameters) return [];
270
+
271
+ const factory = ts.factory;
272
+
273
+ return [
274
+ factory.createFunctionDeclaration(
275
+ [factory.createToken(ts.SyntaxKind.ExportKeyword)],
276
+ undefined,
277
+ factory.createIdentifier('createPredefinedParametersRequestFn'),
278
+ [
279
+ factory.createTypeParameterDeclaration(
280
+ undefined,
281
+ factory.createIdentifier('TRequestFn'),
282
+ factory.createTypeReferenceNode(
283
+ factory.createIdentifier('RequestFn'),
284
+ [
285
+ factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),
286
+ factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),
287
+ ]
288
+ ),
289
+ undefined
290
+ ),
291
+ ],
292
+ [
293
+ factory.createParameterDeclaration(
294
+ undefined,
295
+ undefined,
296
+ factory.createIdentifier('predefinedParameters'),
297
+ undefined,
298
+ factory.createTypeReferenceNode(
299
+ factory.createIdentifier('ServiceOperationsPredefinedParameters'),
300
+ undefined
301
+ ),
302
+ undefined
303
+ ),
304
+ factory.createParameterDeclaration(
305
+ undefined,
306
+ undefined,
307
+ factory.createIdentifier('requestFn'),
308
+ undefined,
309
+ factory.createTypeReferenceNode(
310
+ factory.createIdentifier('TRequestFn'),
311
+ undefined
312
+ ),
313
+ undefined
314
+ ),
315
+ ],
316
+ factory.createTypeReferenceNode(
317
+ factory.createIdentifier('TRequestFn'),
318
+ undefined
319
+ ),
320
+ factory.createBlock(
321
+ [
322
+ factory.createReturnStatement(
323
+ factory.createAsExpression(
324
+ factory.createCallExpression(
325
+ factory.createIdentifier('qraftPredefinedParametersRequestFn'),
326
+ undefined,
327
+ [
328
+ factory.createIdentifier('predefinedParameters'),
329
+ factory.createIdentifier(
330
+ 'serviceOperationsPredefinedParameters'
331
+ ),
332
+ factory.createIdentifier('requestFn'),
333
+ ]
334
+ ),
335
+ factory.createTypeReferenceNode(
336
+ factory.createIdentifier('TRequestFn'),
337
+ undefined
338
+ )
339
+ )
340
+ ),
341
+ ],
342
+ true
343
+ )
344
+ ),
345
+ ];
346
+ };
@@ -1,5 +1,6 @@
1
1
  import type { ServiceImportsFactoryOptions } from './getServiceFactory.js';
2
2
  import ts from 'typescript';
3
+ import { maybeResolveImport } from '../lib/maybeResolveImport.js';
3
4
 
4
5
  export const getIndexFactory = ({
5
6
  openapiTypesImportPath,
@@ -71,23 +72,3 @@ export const getIndexFactory = ({
71
72
  ),
72
73
  ];
73
74
  };
74
-
75
- /**
76
- * Prepend the import path if it's a relative path.
77
- * Normally,`openapiTypesImportPath` is a relative path to the services' directory.
78
- */
79
- export function maybeResolveImport<T extends string | undefined>({
80
- openapiTypesImportPath,
81
- servicesDirName,
82
- }: {
83
- openapiTypesImportPath: T;
84
- servicesDirName: string;
85
- }) {
86
- if (openapiTypesImportPath?.startsWith('../')) {
87
- return `./${openapiTypesImportPath.slice(3)}`;
88
- } else if (openapiTypesImportPath?.startsWith('./')) {
89
- return `./${servicesDirName}/${openapiTypesImportPath.slice(2)}`;
90
- }
91
-
92
- return openapiTypesImportPath;
93
- }