@vladimirdev635/gql-codegen 0.0.107 → 0.0.109

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.
@@ -1,3 +1,3 @@
1
1
  import { Formatter } from '../../shared.js';
2
2
  import { LoadESLintFuncType } from './types.js';
3
- export declare function buildESLintFormatter(loadFunc: LoadESLintFuncType): Promise<Formatter>;
3
+ export declare function build(loadFunc: LoadESLintFuncType): Promise<Formatter>;
@@ -1,5 +1,5 @@
1
1
  import assert from 'assert';
2
- export async function buildESLintFormatter(loadFunc) {
2
+ export async function build(loadFunc) {
3
3
  const ESLint = await loadFunc({ useFlatConfig: true });
4
4
  const eslint = new ESLint({ fix: true });
5
5
  return async (code) => {
@@ -1,2 +1,2 @@
1
1
  export type { LintResult, ESLintClass, ESLintClassConstructor, LoadESLintFuncType, } from './types.js';
2
- export { buildESLintFormatter } from './formatter.js';
2
+ export { build } from './formatter.js';
@@ -1 +1 @@
1
- export { buildESLintFormatter } from './formatter.js';
1
+ export { build } from './formatter.js';
@@ -1,3 +1,3 @@
1
1
  import { Formatter } from '../../shared.js';
2
2
  import { FormatFunc } from './types.js';
3
- export declare function buildOxfmtFormatter<T>(formatFunc: FormatFunc<T>, options: T): Promise<Formatter>;
3
+ export declare function build<T>(formatFunc: FormatFunc<T>, options: T): Promise<Formatter>;
@@ -1,4 +1,4 @@
1
- export async function buildOxfmtFormatter(formatFunc, options) {
1
+ export async function build(formatFunc, options) {
2
2
  return async (code) => {
3
3
  const result = await formatFunc('[buffer].ts', code, options);
4
4
  for (const error of result.errors) {
@@ -1,2 +1,2 @@
1
1
  export type { ErrorLabel, OxcError, Severity, FormatResult, FormatFunc, } from './types.js';
2
- export { buildOxfmtFormatter } from './formatter.js';
2
+ export { build } from './formatter.js';
@@ -1 +1 @@
1
- export { buildOxfmtFormatter } from './formatter.js';
1
+ export { build } from './formatter.js';
@@ -10,10 +10,10 @@ export interface SDKConfig {
10
10
  mutationsKey: string;
11
11
  subscriptionsKey: string;
12
12
  }
13
- export interface GQLClientActorConfig extends TSActorConfig {
13
+ export interface Config extends TSActorConfig {
14
14
  outPath: PathOrFileDescriptor;
15
15
  importDeclarations: ts.ImportDeclaration[];
16
16
  sdk: SDKConfig;
17
17
  graphqlModulePath: string;
18
18
  }
19
- export declare function buildGQLClientActor(config: GQLClientActorConfig): Actor<ActorContext>;
19
+ export declare function build(config: Config): Actor<ActorContext>;
@@ -1,11 +1,11 @@
1
1
  import { writeFileSync } from 'fs';
2
2
  import { renderNodes } from '../shared.js';
3
3
  import { generateNodes } from './generators/main.js';
4
- async function gqlActor(config, context) {
4
+ async function actor(config, context) {
5
5
  const nodes = generateNodes(config, context);
6
6
  const code = await renderNodes(config, nodes);
7
7
  writeFileSync(config.outPath, code);
8
8
  }
9
- export function buildGQLClientActor(config) {
10
- return (context) => gqlActor(config, context);
9
+ export function build(config) {
10
+ return (context) => actor(config, context);
11
11
  }
@@ -1,4 +1,4 @@
1
1
  import { ActorContext } from '../../../../config.js';
2
- import { GQLClientActorConfig } from '../actor.js';
2
+ import { Config } from '../actor.js';
3
3
  import ts from 'typescript';
4
- export declare function generateNodes(config: GQLClientActorConfig, context: ActorContext): ts.Node[];
4
+ export declare function generateNodes(config: Config, context: ActorContext): ts.Node[];
@@ -1 +1 @@
1
- export { type OperationReturnType, type SDKConfig, type GQLClientActorConfig, buildGQLClientActor, } from './actor.js';
1
+ export { type OperationReturnType, type SDKConfig, type Config, build, } from './actor.js';
@@ -1 +1 @@
1
- export { buildGQLClientActor, } from './actor.js';
1
+ export { build, } from './actor.js';
@@ -2,7 +2,7 @@ import { PathOrFileDescriptor } from 'fs';
2
2
  import { Actor, ActorContext } from '../../../config.js';
3
3
  import { TSActorConfig } from '../shared.js';
4
4
  import ts from 'typescript';
5
- export interface GQLClientReactActorConfig extends TSActorConfig {
5
+ export interface Config extends TSActorConfig {
6
6
  outPath: PathOrFileDescriptor;
7
7
  importDeclarations: ts.ImportDeclaration[];
8
8
  graphqlModulePath: string;
@@ -12,4 +12,4 @@ export interface GQLClientReactActorConfig extends TSActorConfig {
12
12
  subscriptionsKey: string;
13
13
  };
14
14
  }
15
- export declare function buildGQLClientReactActor(config: GQLClientReactActorConfig): Actor<ActorContext>;
15
+ export declare function build(config: Config): Actor<ActorContext>;
@@ -1,11 +1,11 @@
1
1
  import { writeFileSync } from 'fs';
2
2
  import { renderNodes } from '../shared.js';
3
3
  import { generateNodes } from './generators/main.js';
4
- async function gqlClientReactActor(config, context) {
4
+ async function actor(config, context) {
5
5
  const nodes = generateNodes(config, context);
6
6
  const code = await renderNodes(config, nodes);
7
7
  writeFileSync(config.outPath, code);
8
8
  }
9
- export function buildGQLClientReactActor(config) {
10
- return (context) => gqlClientReactActor(config, context);
9
+ export function build(config) {
10
+ return (context) => actor(config, context);
11
11
  }
@@ -1,4 +1,4 @@
1
1
  import { ActorContext } from '../../../../config.js';
2
- import { GQLClientReactActorConfig } from '../actor.js';
2
+ import { Config } from '../actor.js';
3
3
  import ts from 'typescript';
4
- export declare function generateNodes(config: GQLClientReactActorConfig, context: ActorContext): ts.Node[];
4
+ export declare function generateNodes(config: Config, context: ActorContext): ts.Node[];
@@ -1 +1 @@
1
- export { type GQLClientReactActorConfig, buildGQLClientReactActor, } from './actor.js';
1
+ export { type Config, build } from './actor.js';
@@ -1 +1 @@
1
- export { buildGQLClientReactActor, } from './actor.js';
1
+ export { build } from './actor.js';
@@ -0,0 +1,15 @@
1
+ import { Actor, ActorContext } from '../../../config.js';
2
+ import { PathOrFileDescriptor } from 'fs';
3
+ import ts from 'typescript';
4
+ import { TSActorConfig } from '../shared.js';
5
+ export interface Config extends TSActorConfig {
6
+ outPath: PathOrFileDescriptor;
7
+ importDeclarations: ts.ImportDeclaration[];
8
+ graphqlModulePath: string;
9
+ sdk: {
10
+ queriesKey: string;
11
+ mutationsKey: string;
12
+ subscriptionsKey: string;
13
+ };
14
+ }
15
+ export declare function build(config: Config): Actor<ActorContext>;
@@ -0,0 +1,11 @@
1
+ import { writeFileSync } from 'fs';
2
+ import { renderNodes } from '../shared.js';
3
+ import { generateNodes } from './generators/main.js';
4
+ async function actor(config, context) {
5
+ const nodes = generateNodes(config, context);
6
+ const code = await renderNodes(config, nodes);
7
+ writeFileSync(config.outPath, code);
8
+ }
9
+ export function build(config) {
10
+ return (context) => actor(config, context);
11
+ }
@@ -0,0 +1,4 @@
1
+ import { ActorContext } from '../../../../config.js';
2
+ import ts from 'typescript';
3
+ import { Config } from '../actor.js';
4
+ export declare function generateNodes(config: Config, context: ActorContext): ts.Node[];
@@ -0,0 +1,135 @@
1
+ import ts from 'typescript';
2
+ function generateFunctionBlock(operationName, type) {
3
+ switch (type) {
4
+ case 'SYNC':
5
+ return ts.factory.createCallExpression(ts.factory.createIdentifier('useOperation'), undefined, [
6
+ ts.factory.createIdentifier('executor'),
7
+ ts.factory.createIdentifier(operationName),
8
+ ts.factory.createIdentifier('variables'),
9
+ ts.factory.createIdentifier('requestContext'),
10
+ ]);
11
+ case 'LAZY':
12
+ return ts.factory.createCallExpression(ts.factory.createIdentifier('useLazyOperation'), undefined, [
13
+ ts.factory.createIdentifier('executor'),
14
+ ts.factory.createIdentifier(operationName),
15
+ ]);
16
+ case 'SUBSCRIPTION':
17
+ return ts.factory.createCallExpression(ts.factory.createIdentifier('useSubscription'), undefined, [
18
+ ts.factory.createIdentifier('executor'),
19
+ ts.factory.createIdentifier(operationName),
20
+ ts.factory.createIdentifier('variables'),
21
+ ts.factory.createIdentifier('requestContext'),
22
+ ]);
23
+ }
24
+ }
25
+ function createTypeOrRefTypeNode(innerType) {
26
+ return ts.factory.createUnionTypeNode([
27
+ innerType,
28
+ ts.factory.createTypeReferenceNode('Ref', [innerType]),
29
+ ]);
30
+ }
31
+ function generateArrowFunction(operationName, variablesName, resultName, type) {
32
+ const parameters = [];
33
+ let resultType;
34
+ switch (type) {
35
+ case 'LAZY':
36
+ resultType = ts.factory.createTypeReferenceNode('UseLazyOperationReturnType', [
37
+ ts.factory.createTypeReferenceNode(variablesName),
38
+ ts.factory.createTypeReferenceNode(resultName),
39
+ ts.factory.createTypeReferenceNode('TRequestContext'),
40
+ ]);
41
+ break;
42
+ case 'SYNC': {
43
+ resultType = ts.factory.createTypeReferenceNode('ShallowRef', [
44
+ ts.factory.createTypeReferenceNode('OperationState', [
45
+ ts.factory.createTypeReferenceNode(resultName),
46
+ ]),
47
+ ]);
48
+ parameters.push(ts.factory.createParameterDeclaration(undefined, undefined, 'variables', undefined, createTypeOrRefTypeNode(ts.factory.createTypeReferenceNode(variablesName))), ts.factory.createParameterDeclaration(undefined, undefined, 'requestContext', undefined, createTypeOrRefTypeNode(ts.factory.createTypeReferenceNode('TRequestContext'))));
49
+ break;
50
+ }
51
+ case 'SUBSCRIPTION': {
52
+ resultType = ts.factory.createTypeReferenceNode('ShallowRef', [
53
+ ts.factory.createTypeReferenceNode('OperationState', [
54
+ ts.factory.createTypeReferenceNode('SubOpAsyncIterable', [
55
+ ts.factory.createTypeReferenceNode(resultName),
56
+ ]),
57
+ ]),
58
+ ]);
59
+ parameters.push(ts.factory.createParameterDeclaration(undefined, undefined, 'variables', undefined, createTypeOrRefTypeNode(ts.factory.createTypeReferenceNode(variablesName))), ts.factory.createParameterDeclaration(undefined, undefined, 'requestContext', undefined, createTypeOrRefTypeNode(ts.factory.createTypeReferenceNode('TRequestContext'))));
60
+ break;
61
+ }
62
+ }
63
+ return ts.factory.createArrowFunction(undefined, undefined, parameters, resultType, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), generateFunctionBlock(operationName, type));
64
+ }
65
+ export function generateNodes(config, context) {
66
+ const graphqlImports = [];
67
+ const queryNodes = [];
68
+ const mutationNodes = [];
69
+ const subscriptionNodes = [];
70
+ for (const operation of Object.values(context.schema.client.operations)) {
71
+ const operationName = operation.name + 'Operation';
72
+ const variablesName = operation.name + 'Variables';
73
+ const resultName = operation.name + 'Result';
74
+ graphqlImports.push(operationName, variablesName, resultName);
75
+ switch (operation.type) {
76
+ case 'SUBSCRIPTION': {
77
+ subscriptionNodes.push(ts.factory.createPropertyAssignment('use' + operation.name, generateArrowFunction(operationName, variablesName, resultName, 'SUBSCRIPTION')));
78
+ break;
79
+ }
80
+ case 'MUTATION': {
81
+ mutationNodes.push(ts.factory.createPropertyAssignment('use' + operation.name, generateArrowFunction(operationName, variablesName, resultName, 'LAZY')));
82
+ break;
83
+ }
84
+ case 'QUERY': {
85
+ queryNodes.push(ts.factory.createPropertyAssignment('use' + operation.name, generateArrowFunction(operationName, variablesName, resultName, 'SYNC')), ts.factory.createPropertyAssignment('useLazy' + operation.name, generateArrowFunction(operationName, variablesName, resultName, 'LAZY')));
86
+ break;
87
+ }
88
+ }
89
+ }
90
+ const gqlClientVueImports = [
91
+ ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useOperation')),
92
+ ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useLazyOperation')),
93
+ ts.factory.createImportSpecifier(true, undefined, ts.factory.createIdentifier('OperationState')),
94
+ ts.factory.createImportSpecifier(true, undefined, ts.factory.createIdentifier('UseLazyOperationReturnType')),
95
+ ];
96
+ const gqlClientImports = [
97
+ ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('IExecutor')),
98
+ ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('RequestContext')),
99
+ ];
100
+ if (subscriptionNodes.length !== 0) {
101
+ gqlClientVueImports.push(ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('useSubscription')));
102
+ gqlClientImports.push(ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('SubOpAsyncIterable')));
103
+ }
104
+ const returnObjectNodes = [];
105
+ if (queryNodes.length !== 0) {
106
+ returnObjectNodes.push(ts.factory.createPropertyAssignment(config.sdk.queriesKey, ts.factory.createObjectLiteralExpression(queryNodes, true)));
107
+ }
108
+ if (mutationNodes.length !== 0) {
109
+ returnObjectNodes.push(ts.factory.createPropertyAssignment(config.sdk.mutationsKey, ts.factory.createObjectLiteralExpression(mutationNodes, true)));
110
+ }
111
+ if (subscriptionNodes.length !== 0) {
112
+ returnObjectNodes.push(ts.factory.createPropertyAssignment(config.sdk.subscriptionsKey, ts.factory.createObjectLiteralExpression(subscriptionNodes, true)));
113
+ }
114
+ return [
115
+ ts.factory.createIdentifier('// @ts-nocheck'),
116
+ ...config.importDeclarations,
117
+ ts.factory.createImportDeclaration([], ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
118
+ ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('Ref')),
119
+ ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('ShallowRef')),
120
+ ])), ts.factory.createStringLiteral('vue')),
121
+ ts.factory.createImportDeclaration([], ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(gqlClientVueImports)), ts.factory.createStringLiteral('@vladimirdev635/gql-client-vue')),
122
+ ts.factory.createImportDeclaration([], ts.factory.createImportClause(true, undefined, ts.factory.createNamedImports(gqlClientImports)), ts.factory.createStringLiteral('@vladimirdev635/gql-client/types')),
123
+ ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(graphqlImports.map((i) => ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier(i))))), ts.factory.createStringLiteral(config.graphqlModulePath)),
124
+ ts.factory.createIdentifier('\n'),
125
+ ts.factory.createFunctionDeclaration(ts.factory.createModifiersFromModifierFlags(ts.ModifierFlags.Export), undefined, 'createSdk', [
126
+ ts.factory.createTypeParameterDeclaration(undefined, 'TRequestContext', ts.factory.createTypeReferenceNode('RequestContext')),
127
+ ], [
128
+ ts.factory.createParameterDeclaration(undefined, undefined, 'executor', undefined, ts.factory.createTypeReferenceNode('IExecutor', [
129
+ ts.factory.createTypeReferenceNode('TRequestContext'),
130
+ ])),
131
+ ], undefined, ts.factory.createBlock([
132
+ ts.factory.createReturnStatement(ts.factory.createObjectLiteralExpression(returnObjectNodes, true)),
133
+ ], true)),
134
+ ];
135
+ }
@@ -0,0 +1 @@
1
+ export { type Config, build } from './actor.js';
@@ -0,0 +1 @@
1
+ export { build } from './actor.js';
@@ -1,5 +1,6 @@
1
1
  export * as gqlClient from './gql-client/index.js';
2
2
  export * as gqlClientReact from './gql-client-react/index.js';
3
+ export * as gqlClientVue from './gql-client-vue/index.js';
3
4
  export * as graphql from './graphql/index.js';
4
5
  export { type Formatter, type TSActorConfig, renderNodes, loadTsConfigCompilerOptions, addNewLineBetweenNodes, invokeMethod, } from './shared.js';
5
6
  export { generateImportDeclaration } from './utils.js';
@@ -1,5 +1,6 @@
1
1
  export * as gqlClient from './gql-client/index.js';
2
2
  export * as gqlClientReact from './gql-client-react/index.js';
3
+ export * as gqlClientVue from './gql-client-vue/index.js';
3
4
  export * as graphql from './graphql/index.js';
4
5
  export { renderNodes, loadTsConfigCompilerOptions, addNewLineBetweenNodes, invokeMethod, } from './shared.js';
5
6
  export { generateImportDeclaration } from './utils.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vladimirdev635/gql-codegen",
3
- "version": "0.0.107",
3
+ "version": "0.0.109",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/Voldemat/graphql-plus-plus#readme",
package/schema/utils.d.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  import { PathOrFileDescriptor } from 'fs';
2
- import { objectFieldSchema, objectFieldSpecSchema, objectSchema, ServerSchema, unionSchema } from './server.js';
3
- import { ClientSchema } from './client/root.js';
4
2
  import { z } from 'zod/v4';
5
- import { RootSchema } from './root.js';
6
- import { fieldSelection, fragmentSchema, fragmentSpecSchema } from './client/fragment.js';
7
3
  import { argument } from './client/argument.js';
4
+ import { fieldSelection, fragmentSchema, fragmentSpecSchema } from './client/fragment.js';
5
+ import { ClientSchema } from './client/root.js';
6
+ import { RootSchema } from './root.js';
7
+ import { objectFieldSchema, objectFieldSpecSchema, objectSchema, ServerSchema, unionSchema } from './server.js';
8
8
  export declare function loadSchemaFromFile<T extends z.ZodType>(p: PathOrFileDescriptor, schema: T): z.infer<T>;
9
9
  export declare function loadServerSchemaFromFile(p: PathOrFileDescriptor): ServerSchema;
10
10
  export declare function loadClientSchemaFromFile(p: PathOrFileDescriptor): ClientSchema;
11
- export declare function loadServerSchemaFromGQLSubprocess(gqlPath?: string, gqlArgs?: string[]): Promise<ServerSchema>;
12
- export declare function loadRootSchemaFromGQLSubprocess(gqlPath?: string, gqlArgs?: string[]): Promise<RootSchema>;
11
+ export declare function loadServerSchemaFromGQLSubprocess(gqlPath?: string, gqlArgs?: string[], maxBuffer?: number | undefined): Promise<ServerSchema>;
12
+ export declare function loadRootSchemaFromGQLSubprocess(gqlPath?: string, gqlArgs?: string[], maxBuffer?: number | undefined): Promise<RootSchema>;
13
13
  export declare function buildFragmentFromUnion(union: z.infer<typeof unionSchema>): z.infer<typeof fragmentSchema>;
14
14
  export declare function buildSelectionFromFieldSpec(spec: z.infer<typeof objectFieldSpecSchema>): z.infer<typeof fragmentSpecSchema> | null;
15
15
  export declare function buildArgumentFromFieldSpec(spec: z.infer<typeof objectFieldSpecSchema>): Record<string, z.infer<typeof argument>>;
package/schema/utils.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable max-lines */
2
2
  import { readFileSync } from 'fs';
3
- import { serverSchema, } from './server.js';
4
- import { clientSchema } from './client/root.js';
5
3
  import { exec } from 'node:child_process';
4
+ import { clientSchema } from './client/root.js';
5
+ import { serverSchema, } from './server.js';
6
6
  export function loadSchemaFromFile(p, schema) {
7
7
  return schema.parse(JSON.parse(readFileSync(p).toString()));
8
8
  }
@@ -12,9 +12,11 @@ export function loadServerSchemaFromFile(p) {
12
12
  export function loadClientSchemaFromFile(p) {
13
13
  return loadSchemaFromFile(p, clientSchema);
14
14
  }
15
- export async function loadServerSchemaFromGQLSubprocess(gqlPath = 'gql', gqlArgs = ['generate']) {
15
+ export async function loadServerSchemaFromGQLSubprocess(gqlPath = 'gql', gqlArgs = ['generate'], maxBuffer = undefined) {
16
16
  const output = await new Promise((resolve, reject) => {
17
- exec([gqlPath, ...gqlArgs].join(' '), (err, stdout, stderr) => {
17
+ exec([gqlPath, ...gqlArgs].join(' '), {
18
+ maxBuffer,
19
+ }, (err, stdout, stderr) => {
18
20
  if (err !== null) {
19
21
  reject(err);
20
22
  }
@@ -26,9 +28,9 @@ export async function loadServerSchemaFromGQLSubprocess(gqlPath = 'gql', gqlArgs
26
28
  });
27
29
  return serverSchema.parse(JSON.parse(output));
28
30
  }
29
- export async function loadRootSchemaFromGQLSubprocess(gqlPath = 'gql', gqlArgs = ['generate']) {
31
+ export async function loadRootSchemaFromGQLSubprocess(gqlPath = 'gql', gqlArgs = ['generate'], maxBuffer = undefined) {
30
32
  const output = await new Promise((resolve, reject) => {
31
- exec([gqlPath, ...gqlArgs].join(' '), (err, stdout, stderr) => {
33
+ exec([gqlPath, ...gqlArgs].join(' '), { maxBuffer }, (err, stdout, stderr) => {
32
34
  if (err !== null) {
33
35
  reject(err);
34
36
  }