@baeta/plugin-pagination 0.0.7-75-20230619184544-4493aaa → 0.0.7

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,13 +1,17 @@
1
1
  # @baeta/plugin-pagination
2
2
 
3
- ## 0.0.7-75-20230619184544-4493aaa
3
+ ## 0.0.7
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - [#81](https://github.com/andreisergiu98/baeta/pull/81) [`3ff5e54`](https://github.com/andreisergiu98/baeta/commit/3ff5e54f31cf42ba2264b12309338d6e78710722) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add file transformation function from config
8
+
7
9
  - [#69](https://github.com/andreisergiu98/baeta/pull/69) [`3cdd9b3`](https://github.com/andreisergiu98/baeta/commit/3cdd9b30369d21179769a4b8d5f76e326ae6db37) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
8
10
 
9
- - Updated dependencies [[`3cdd9b3`](https://github.com/andreisergiu98/baeta/commit/3cdd9b30369d21179769a4b8d5f76e326ae6db37)]:
10
- - @baeta/generator-sdk@0.0.9-75-20230619184544-4493aaa
11
+ - [#91](https://github.com/andreisergiu98/baeta/pull/91) [`e0944f6`](https://github.com/andreisergiu98/baeta/commit/e0944f6320e6cf2f0a3d2c9f51edd282bdce0546) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
12
+
13
+ - Updated dependencies [[`3ff5e54`](https://github.com/andreisergiu98/baeta/commit/3ff5e54f31cf42ba2264b12309338d6e78710722), [`3cdd9b3`](https://github.com/andreisergiu98/baeta/commit/3cdd9b30369d21179769a4b8d5f76e326ae6db37), [`e0944f6`](https://github.com/andreisergiu98/baeta/commit/e0944f6320e6cf2f0a3d2c9f51edd282bdce0546)]:
14
+ - @baeta/generator-sdk@0.0.9
11
15
 
12
16
  ## 0.0.6
13
17
 
package/dist/index.cjs CHANGED
@@ -1,9 +1,4 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
2
-
3
-
4
-
5
-
6
-
7
2
  var _generatorsdk = require('@baeta/generator-sdk');
8
3
  var _path = require('path');
9
4
  function printFields(fields) {
@@ -15,7 +10,8 @@ ${printFields(fields)}
15
10
  }`;
16
11
  }
17
12
  function printTypes(types) {
18
- return types.join("\n\n") + "\n";
13
+ return `${types.join("\n\n")}
14
+ `;
19
15
  }
20
16
  function printPageInfo(addFields = []) {
21
17
  return printType("PageInfo", [
@@ -84,18 +80,21 @@ function paginationPlugin(options) {
84
80
  types.push(...connectionTypes);
85
81
  }
86
82
  const moduleDir = createConnectionModuleDir(ctx.generatorOptions.modulesDir, moduleName);
87
- const definitionFile = new (0, _generatorsdk.File)(createGqlFilename(moduleDir), printTypes(types), "schema");
83
+ const definitionFile = ctx.fileManager.createAndAdd(
84
+ createGqlFilename(moduleDir),
85
+ printTypes(types),
86
+ "schema"
87
+ );
88
88
  await definitionFile.write();
89
89
  ctx.fileManager.add(definitionFile);
90
90
  if (options.createExport === false) {
91
91
  return next();
92
92
  }
93
- const exportFile = new (0, _generatorsdk.File)(
93
+ ctx.fileManager.createAndAdd(
94
94
  createExportFilename(moduleDir),
95
95
  printExport(ctx.generatorOptions.moduleDefinitionName, moduleName),
96
96
  "export"
97
97
  );
98
- ctx.fileManager.add(exportFile);
99
98
  return next();
100
99
  }
101
100
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts"],"names":[],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,MAAM,aAAa;AAiB5B,SAAS,YAAY,QAAkB;AACrC,SAAO,OAAO,IAAI,CAAC,UAAU,KAAK,OAAO,EAAE,KAAK,IAAI;AACtD;AAEA,SAAS,UAAU,MAAc,QAAkB;AACjD,SAAO,QAAQ;AAAA,EACf,YAAY,MAAM;AAAA;AAEpB;AAEA,SAAS,WAAW,OAAiB;AACnC,SAAO,MAAM,KAAK,MAA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OAAO,KAAK,SAAS;AAC7B,YAAM,QAAkB,CAAC,cAAc,QAAQ,cAAc,CAAC;AAE9D,iBAAW,QAAQ,QAAQ,OAAO;AAChC,cAAM,cAAc,QAAQ,MAAM,IAAI;AAEtC,YAAI,gBAAgB,OAAO;AACzB;AAAA,QACF;AAEA,cAAM,kBAAkB;AAAA,UACtB;AAAA,UACA,gBAAgB,OAAO,CAAC,IAAI;AAAA,UAC5B;AAAA,QACF;AAEA,cAAM,KAAK,GAAG,eAAe;AAAA,MAC/B;AAEA,YAAM,YAAY,0BAA0B,IAAI,iBAAiB,YAAY,UAAU;AAEvF,YAAM,iBAAiB,IAAI,KAAK,kBAAkB,SAAS,GAAG,WAAW,KAAK,GAAG,QAAQ;AAEzF,YAAM,eAAe,MAAM;AAE3B,UAAI,YAAY,IAAI,cAAc;AAElC,UAAI,QAAQ,iBAAiB,OAAO;AAClC,eAAO,KAAK;AAAA,MACd;AAEA,YAAM,aAAa,IAAI;AAAA,QACrB,qBAAqB,SAAS;AAAA,QAC9B,YAAY,IAAI,iBAAiB,sBAAsB,UAAU;AAAA,QACjE;AAAA,MACF;AAEA,UAAI,YAAY,IAAI,UAAU;AAE9B,aAAO,KAAK;AAAA,IACd;AAAA,EACF,CAAC;AACH","sourcesContent":["import {\n createPluginV1,\n File,\n getModuleGetName,\n getModuleVariableName,\n} from '@baeta/generator-sdk';\nimport { join, parse } from 'path';\n\ninterface TypeOptions {\n nodeType?: string;\n cursorType?: string;\n edgeFields?: string[];\n connectionFields?: string[];\n}\n\ninterface PaginationOptions {\n types: Record<string, boolean | TypeOptions>;\n nullableNode?: boolean;\n pageInfoFields?: string[];\n moduleName?: string;\n createExport?: boolean;\n}\n\nfunction printFields(fields: string[]) {\n return fields.map((field) => ` ${field}`).join('\\n');\n}\n\nfunction printType(name: string, fields: string[]) {\n return `type ${name} {\n${printFields(fields)}\n}`;\n}\n\nfunction printTypes(types: string[]) {\n return types.join('\\n\\n') + '\\n';\n}\n\nfunction printPageInfo(addFields: string[] = []) {\n return printType('PageInfo', [\n ...addFields,\n 'hasPreviousPage: Boolean!',\n 'hasNextPage: Boolean!',\n ]);\n}\n\nfunction printExport(moduleDefinitionName: string, moduleName: string) {\n const parsed = parse(moduleDefinitionName);\n const method = getModuleGetName(moduleName);\n const importName = parsed.ext === '.ts' ? parsed.name : moduleDefinitionName;\n\n return `import { ${method} } from \"./${importName}\";\n\nexport const ${getModuleVariableName(moduleName)} = ${method}();\n`;\n}\n\nfunction printConnectionTypes(name: string, typeOptions: TypeOptions, options: PaginationOptions) {\n const {\n cursorType = 'String!',\n nodeType = name,\n connectionFields = [],\n edgeFields = [],\n } = typeOptions;\n\n const connection = printType(`${name}Connection`, [\n ...connectionFields,\n 'pageInfo: PageInfo!',\n `edges: [${name}Edge]`,\n ]);\n\n const edge = printType(`${name}Edge`, [\n ...edgeFields,\n `cursor: ${cursorType}`,\n `node: ${nodeType}${options.nullableNode === false ? '!' : ''}`,\n ]);\n\n return [connection, edge];\n}\n\nfunction createConnectionModuleDir(modulesDir: string, moduleName: string) {\n return join(modulesDir, moduleName);\n}\n\nfunction createGqlFilename(moduleDir: string) {\n return `${moduleDir}/connections.gql`;\n}\n\nfunction createExportFilename(moduleDir: string) {\n return `${moduleDir}/index.ts`;\n}\n\nexport function paginationPlugin(options: PaginationOptions) {\n const { moduleName = 'baeta-pagination' } = options;\n\n return createPluginV1({\n name: 'pagination',\n actionName: 'pagination connections',\n watch: (generatorOptions, watcher) => {\n watcher.ignore(`${createConnectionModuleDir(generatorOptions.modulesDir, moduleName)}/**`);\n },\n generate: async (ctx, next) => {\n const types: string[] = [printPageInfo(options.pageInfoFields)];\n\n for (const name in options.types) {\n const typeOptions = options.types[name];\n\n if (typeOptions === false) {\n continue;\n }\n\n const connectionTypes = printConnectionTypes(\n name,\n typeOptions === true ? {} : typeOptions,\n options\n );\n\n types.push(...connectionTypes);\n }\n\n const moduleDir = createConnectionModuleDir(ctx.generatorOptions.modulesDir, moduleName);\n\n const definitionFile = new File(createGqlFilename(moduleDir), printTypes(types), 'schema');\n\n await definitionFile.write();\n\n ctx.fileManager.add(definitionFile);\n\n if (options.createExport === false) {\n return next();\n }\n\n const exportFile = new File(\n createExportFilename(moduleDir),\n printExport(ctx.generatorOptions.moduleDefinitionName, moduleName),\n 'export'\n );\n\n ctx.fileManager.add(exportFile);\n\n return next();\n },\n });\n}\n"]}
1
+ {"version":3,"sources":["../index.ts"],"names":[],"mappings":";AAAA,SAAS,gBAAgB,kBAAkB,6BAA6B;AACxE,SAAS,MAAM,aAAa;AAiB5B,SAAS,YAAY,QAAkB;AACrC,SAAO,OAAO,IAAI,CAAC,UAAU,KAAK,KAAK,EAAE,EAAE,KAAK,IAAI;AACtD;AAEA,SAAS,UAAU,MAAc,QAAkB;AACjD,SAAO,QAAQ,IAAI;AAAA,EACnB,YAAY,MAAM,CAAC;AAAA;AAErB;AAEA,SAAS,WAAW,OAAiB;AACnC,SAAO,GAAG,MAAM,KAAK,MAAM,CAAC;AAAA;AAC9B;AAEA,SAAS,cAAc,YAAsB,CAAC,GAAG;AAC/C,SAAO,UAAU,YAAY;AAAA,IAC3B,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEA,SAAS,YAAY,sBAA8B,YAAoB;AACrE,QAAM,SAAS,MAAM,oBAAoB;AACzC,QAAM,SAAS,iBAAiB,UAAU;AAC1C,QAAM,aAAa,OAAO,QAAQ,QAAQ,OAAO,OAAO;AAExD,SAAO,YAAY,MAAM,cAAc,UAAU;AAAA;AAAA,eAEpC,sBAAsB,UAAU,CAAC,MAAM,MAAM;AAAA;AAE5D;AAEA,SAAS,qBAAqB,MAAc,aAA0B,SAA4B;AAChG,QAAM;AAAA,IACJ,aAAa;AAAA,IACb,WAAW;AAAA,IACX,mBAAmB,CAAC;AAAA,IACpB,aAAa,CAAC;AAAA,EAChB,IAAI;AAEJ,QAAM,aAAa,UAAU,GAAG,IAAI,cAAc;AAAA,IAChD,GAAG;AAAA,IACH;AA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,UAAI,QAAQ,iBAAiB,OAAO;AAClC,eAAO,KAAK;AAAA,MACd;AAEA,UAAI,YAAY;AAAA,QACd,qBAAqB,SAAS;AAAA,QAC9B,YAAY,IAAI,iBAAiB,sBAAsB,UAAU;AAAA,QACjE;AAAA,MACF;AAEA,aAAO,KAAK;AAAA,IACd;AAAA,EACF,CAAC;AACH","sourcesContent":["import { createPluginV1, getModuleGetName, getModuleVariableName } from '@baeta/generator-sdk';\nimport { join, parse } from 'path';\n\ninterface TypeOptions {\n nodeType?: string;\n cursorType?: string;\n edgeFields?: string[];\n connectionFields?: string[];\n}\n\ninterface PaginationOptions {\n types: Record<string, boolean | TypeOptions>;\n nullableNode?: boolean;\n pageInfoFields?: string[];\n moduleName?: string;\n createExport?: boolean;\n}\n\nfunction printFields(fields: string[]) {\n return fields.map((field) => ` ${field}`).join('\\n');\n}\n\nfunction printType(name: string, fields: string[]) {\n return `type ${name} {\n${printFields(fields)}\n}`;\n}\n\nfunction printTypes(types: string[]) {\n return `${types.join('\\n\\n')}\\n`;\n}\n\nfunction printPageInfo(addFields: string[] = []) {\n return printType('PageInfo', [\n ...addFields,\n 'hasPreviousPage: Boolean!',\n 'hasNextPage: Boolean!',\n ]);\n}\n\nfunction printExport(moduleDefinitionName: string, moduleName: string) {\n const parsed = parse(moduleDefinitionName);\n const method = getModuleGetName(moduleName);\n const importName = parsed.ext === '.ts' ? parsed.name : moduleDefinitionName;\n\n return `import { ${method} } from \"./${importName}\";\n\nexport const ${getModuleVariableName(moduleName)} = ${method}();\n`;\n}\n\nfunction printConnectionTypes(name: string, typeOptions: TypeOptions, options: PaginationOptions) {\n const {\n cursorType = 'String!',\n nodeType = name,\n connectionFields = [],\n edgeFields = [],\n } = typeOptions;\n\n const connection = printType(`${name}Connection`, [\n ...connectionFields,\n 'pageInfo: PageInfo!',\n `edges: [${name}Edge]`,\n ]);\n\n const edge = printType(`${name}Edge`, [\n ...edgeFields,\n `cursor: ${cursorType}`,\n `node: ${nodeType}${options.nullableNode === false ? '!' : ''}`,\n ]);\n\n return [connection, edge];\n}\n\nfunction createConnectionModuleDir(modulesDir: string, moduleName: string) {\n return join(modulesDir, moduleName);\n}\n\nfunction createGqlFilename(moduleDir: string) {\n return `${moduleDir}/connections.gql`;\n}\n\nfunction createExportFilename(moduleDir: string) {\n return `${moduleDir}/index.ts`;\n}\n\nexport function paginationPlugin(options: PaginationOptions) {\n const { moduleName = 'baeta-pagination' } = options;\n\n return createPluginV1({\n name: 'pagination',\n actionName: 'pagination connections',\n watch: (generatorOptions, watcher) => {\n watcher.ignore(`${createConnectionModuleDir(generatorOptions.modulesDir, moduleName)}/**`);\n },\n generate: async (ctx, next) => {\n const types: string[] = [printPageInfo(options.pageInfoFields)];\n\n for (const name in options.types) {\n const typeOptions = options.types[name];\n\n if (typeOptions === false) {\n continue;\n }\n\n const connectionTypes = printConnectionTypes(\n name,\n typeOptions === true ? {} : typeOptions,\n options,\n );\n\n types.push(...connectionTypes);\n }\n\n const moduleDir = createConnectionModuleDir(ctx.generatorOptions.modulesDir, moduleName);\n\n const definitionFile = ctx.fileManager.createAndAdd(\n createGqlFilename(moduleDir),\n printTypes(types),\n 'schema',\n );\n await definitionFile.write();\n\n ctx.fileManager.add(definitionFile);\n\n if (options.createExport === false) {\n return next();\n }\n\n ctx.fileManager.createAndAdd(\n createExportFilename(moduleDir),\n printExport(ctx.generatorOptions.moduleDefinitionName, moduleName),\n 'export',\n );\n\n return next();\n },\n });\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import * as _baeta_generator_sdk from '@baeta/generator-sdk';
2
+
3
+ interface TypeOptions {
4
+ nodeType?: string;
5
+ cursorType?: string;
6
+ edgeFields?: string[];
7
+ connectionFields?: string[];
8
+ }
9
+ interface PaginationOptions {
10
+ types: Record<string, boolean | TypeOptions>;
11
+ nullableNode?: boolean;
12
+ pageInfoFields?: string[];
13
+ moduleName?: string;
14
+ createExport?: boolean;
15
+ }
16
+ declare function paginationPlugin(options: PaginationOptions): _baeta_generator_sdk.GeneratorPluginV1<{}>;
17
+
18
+ export { paginationPlugin };
package/dist/index.js CHANGED
@@ -1,10 +1,5 @@
1
1
  // index.ts
2
- import {
3
- createPluginV1,
4
- File,
5
- getModuleGetName,
6
- getModuleVariableName
7
- } from "@baeta/generator-sdk";
2
+ import { createPluginV1, getModuleGetName, getModuleVariableName } from "@baeta/generator-sdk";
8
3
  import { join, parse } from "path";
9
4
  function printFields(fields) {
10
5
  return fields.map((field) => ` ${field}`).join("\n");
@@ -15,7 +10,8 @@ ${printFields(fields)}
15
10
  }`;
16
11
  }
17
12
  function printTypes(types) {
18
- return types.join("\n\n") + "\n";
13
+ return `${types.join("\n\n")}
14
+ `;
19
15
  }
20
16
  function printPageInfo(addFields = []) {
21
17
  return printType("PageInfo", [
@@ -84,18 +80,21 @@ function paginationPlugin(options) {
84
80
  types.push(...connectionTypes);
85
81
  }
86
82
  const moduleDir = createConnectionModuleDir(ctx.generatorOptions.modulesDir, moduleName);
87
- const definitionFile = new File(createGqlFilename(moduleDir), printTypes(types), "schema");
83
+ const definitionFile = ctx.fileManager.createAndAdd(
84
+ createGqlFilename(moduleDir),
85
+ printTypes(types),
86
+ "schema"
87
+ );
88
88
  await definitionFile.write();
89
89
  ctx.fileManager.add(definitionFile);
90
90
  if (options.createExport === false) {
91
91
  return next();
92
92
  }
93
- const exportFile = new File(
93
+ ctx.fileManager.createAndAdd(
94
94
  createExportFilename(moduleDir),
95
95
  printExport(ctx.generatorOptions.moduleDefinitionName, moduleName),
96
96
  "export"
97
97
  );
98
- ctx.fileManager.add(exportFile);
99
98
  return next();
100
99
  }
101
100
  });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts"],"sourcesContent":["import {\n createPluginV1,\n File,\n getModuleGetName,\n getModuleVariableName,\n} from '@baeta/generator-sdk';\nimport { join, parse } from 'path';\n\ninterface TypeOptions {\n nodeType?: string;\n cursorType?: string;\n edgeFields?: string[];\n connectionFields?: string[];\n}\n\ninterface PaginationOptions {\n types: Record<string, boolean | TypeOptions>;\n nullableNode?: boolean;\n pageInfoFields?: string[];\n moduleName?: string;\n createExport?: boolean;\n}\n\nfunction printFields(fields: string[]) {\n return fields.map((field) => ` ${field}`).join('\\n');\n}\n\nfunction printType(name: string, fields: string[]) {\n return `type ${name} {\n${printFields(fields)}\n}`;\n}\n\nfunction printTypes(types: string[]) {\n return types.join('\\n\\n') + '\\n';\n}\n\nfunction printPageInfo(addFields: string[] = []) {\n return printType('PageInfo', [\n ...addFields,\n 'hasPreviousPage: Boolean!',\n 'hasNextPage: Boolean!',\n ]);\n}\n\nfunction printExport(moduleDefinitionName: string, moduleName: string) {\n const parsed = parse(moduleDefinitionName);\n const method = getModuleGetName(moduleName);\n const importName = parsed.ext === '.ts' ? parsed.name : moduleDefinitionName;\n\n return `import { ${method} } from \"./${importName}\";\n\nexport const ${getModuleVariableName(moduleName)} = ${method}();\n`;\n}\n\nfunction printConnectionTypes(name: string, typeOptions: TypeOptions, options: PaginationOptions) {\n const {\n cursorType = 'String!',\n nodeType = name,\n connectionFields = [],\n edgeFields = [],\n } = typeOptions;\n\n const connection = printType(`${name}Connection`, [\n ...connectionFields,\n 'pageInfo: PageInfo!',\n `edges: [${name}Edge]`,\n ]);\n\n const edge = printType(`${name}Edge`, [\n ...edgeFields,\n `cursor: ${cursorType}`,\n `node: ${nodeType}${options.nullableNode === false ? '!' : ''}`,\n ]);\n\n return [connection, edge];\n}\n\nfunction createConnectionModuleDir(modulesDir: string, moduleName: string) {\n return join(modulesDir, moduleName);\n}\n\nfunction createGqlFilename(moduleDir: string) {\n return `${moduleDir}/connections.gql`;\n}\n\nfunction createExportFilename(moduleDir: string) {\n return `${moduleDir}/index.ts`;\n}\n\nexport function paginationPlugin(options: PaginationOptions) {\n const { moduleName = 'baeta-pagination' } = options;\n\n return createPluginV1({\n name: 'pagination',\n actionName: 'pagination connections',\n watch: (generatorOptions, watcher) => {\n watcher.ignore(`${createConnectionModuleDir(generatorOptions.modulesDir, moduleName)}/**`);\n },\n generate: async (ctx, next) => {\n const types: string[] = [printPageInfo(options.pageInfoFields)];\n\n for (const name in options.types) {\n const typeOptions = options.types[name];\n\n if (typeOptions === false) {\n continue;\n }\n\n const connectionTypes = printConnectionTypes(\n name,\n typeOptions === true ? {} : typeOptions,\n options\n );\n\n types.push(...connectionTypes);\n }\n\n const moduleDir = createConnectionModuleDir(ctx.generatorOptions.modulesDir, moduleName);\n\n const definitionFile = new File(createGqlFilename(moduleDir), printTypes(types), 'schema');\n\n await definitionFile.write();\n\n ctx.fileManager.add(definitionFile);\n\n if (options.createExport === false) {\n return next();\n }\n\n const exportFile = new File(\n createExportFilename(moduleDir),\n printExport(ctx.generatorOptions.moduleDefinitionName, moduleName),\n 'export'\n );\n\n ctx.fileManager.add(exportFile);\n\n return next();\n },\n });\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,MAAM,aAAa;AAiB5B,SAAS,YAAY,QAAkB;AACrC,SAAO,OAAO,IAAI,CAAC,UAAU,KAAK,OAAO,EAAE,KAAK,IAAI;AACtD;AAEA,SAAS,UAAU,MAAc,QAAkB;AACjD,SAAO,QAAQ;AAAA,EACf,YAAY,MAAM;AAAA;AAEpB;AAEA,SAAS,WAAW,OAAiB;AACnC,SAAO,MAAM,KAAK,MAAM,IAAI;AAC9B;AAEA,SAAS,cAAc,YAAsB,CAAC,GAAG;AAC/C,SAAO,UAAU,YAAY;AAAA,IAC3B,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEA,SAAS,YAAY,sBAA8B,YAAoB;AACrE,QAAM,SAAS,MAAM,oBAAoB;AACzC,QAAM,SAAS,iBAAiB,UAAU;AAC1C,QAAM,aAAa,OAAO,QAAQ,QAAQ,OAAO,OAAO;AAExD,SAAO,YAAY,oBAAoB;AAAA;AAAA,eAE1B,sBAAsB,UAAU,OAAO;AAAA;AAEtD;AAEA,SAAS,q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YAAM,iBAAiB,IAAI,KAAK,kBAAkB,SAAS,GAAG,WAAW,KAAK,GAAG,QAAQ;AAEzF,YAAM,eAAe,MAAM;AAE3B,UAAI,YAAY,IAAI,cAAc;AAElC,UAAI,QAAQ,iBAAiB,OAAO;AAClC,eAAO,KAAK;AAAA,MACd;AAEA,YAAM,aAAa,IAAI;AAAA,QACrB,qBAAqB,SAAS;AAAA,QAC9B,YAAY,IAAI,iBAAiB,sBAAsB,UAAU;AAAA,QACjE;AAAA,MACF;AAEA,UAAI,YAAY,IAAI,UAAU;AAE9B,aAAO,KAAK;AAAA,IACd;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../index.ts"],"sourcesContent":["import { createPluginV1, getModuleGetName, getModuleVariableName } from '@baeta/generator-sdk';\nimport { join, parse } from 'path';\n\ninterface TypeOptions {\n nodeType?: string;\n cursorType?: string;\n edgeFields?: string[];\n connectionFields?: string[];\n}\n\ninterface PaginationOptions {\n types: Record<string, boolean | TypeOptions>;\n nullableNode?: boolean;\n pageInfoFields?: string[];\n moduleName?: string;\n createExport?: boolean;\n}\n\nfunction printFields(fields: string[]) {\n return fields.map((field) => ` ${field}`).join('\\n');\n}\n\nfunction printType(name: string, fields: string[]) {\n return `type ${name} {\n${printFields(fields)}\n}`;\n}\n\nfunction printTypes(types: string[]) {\n return `${types.join('\\n\\n')}\\n`;\n}\n\nfunction printPageInfo(addFields: string[] = []) {\n return printType('PageInfo', [\n ...addFields,\n 'hasPreviousPage: Boolean!',\n 'hasNextPage: Boolean!',\n ]);\n}\n\nfunction printExport(moduleDefinitionName: string, moduleName: string) {\n const parsed = parse(moduleDefinitionName);\n const method = getModuleGetName(moduleName);\n const importName = parsed.ext === '.ts' ? parsed.name : moduleDefinitionName;\n\n return `import { ${method} } from \"./${importName}\";\n\nexport const ${getModuleVariableName(moduleName)} = ${method}();\n`;\n}\n\nfunction printConnectionTypes(name: string, typeOptions: TypeOptions, options: PaginationOptions) {\n const {\n cursorType = 'String!',\n nodeType = name,\n connectionFields = [],\n edgeFields = [],\n } = typeOptions;\n\n const connection = printType(`${name}Connection`, [\n ...connectionFields,\n 'pageInfo: PageInfo!',\n `edges: [${name}Edge]`,\n ]);\n\n const edge = printType(`${name}Edge`, [\n ...edgeFields,\n `cursor: ${cursorType}`,\n `node: ${nodeType}${options.nullableNode === false ? '!' : ''}`,\n ]);\n\n return [connection, edge];\n}\n\nfunction createConnectionModuleDir(modulesDir: string, moduleName: string) {\n return join(modulesDir, moduleName);\n}\n\nfunction createGqlFilename(moduleDir: string) {\n return `${moduleDir}/connections.gql`;\n}\n\nfunction createExportFilename(moduleDir: string) {\n return `${moduleDir}/index.ts`;\n}\n\nexport function paginationPlugin(options: PaginationOptions) {\n const { moduleName = 'baeta-pagination' } = options;\n\n return createPluginV1({\n name: 'pagination',\n actionName: 'pagination connections',\n watch: (generatorOptions, watcher) => {\n watcher.ignore(`${createConnectionModuleDir(generatorOptions.modulesDir, moduleName)}/**`);\n },\n generate: async (ctx, next) => {\n const types: string[] = [printPageInfo(options.pageInfoFields)];\n\n for (const name in options.types) {\n const typeOptions = options.types[name];\n\n if (typeOptions === false) {\n continue;\n }\n\n const connectionTypes = printConnectionTypes(\n name,\n typeOptions === true ? {} : typeOptions,\n options,\n );\n\n types.push(...connectionTypes);\n }\n\n const moduleDir = createConnectionModuleDir(ctx.generatorOptions.modulesDir, moduleName);\n\n const definitionFile = ctx.fileManager.createAndAdd(\n createGqlFilename(moduleDir),\n printTypes(types),\n 'schema',\n );\n await definitionFile.write();\n\n ctx.fileManager.add(definitionFile);\n\n if (options.createExport === false) {\n return next();\n }\n\n ctx.fileManager.createAndAdd(\n createExportFilename(moduleDir),\n printExport(ctx.generatorOptions.moduleDefinitionName, moduleName),\n 'export',\n );\n\n return next();\n },\n });\n}\n"],"mappings":";AAAA,SAAS,gBAAgB,kBAAkB,6BAA6B;AACxE,SAAS,MAAM,aAAa;AAiB5B,SAAS,YAAY,QAAkB;AACrC,SAAO,OAAO,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BAAqB,WAAmB;AAC/C,SAAO,GAAG,SAAS;AACrB;AAEO,SAAS,iBAAiB,SAA4B;AAC3D,QAAM,EAAE,aAAa,mBAAmB,IAAI;AAE5C,SAAO,eAAe;AAAA,IACpB,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,OAAO,CAAC,kBAAkB,YAAY;AACpC,cAAQ,OAAO,GAAG,0BAA0B,iBAAiB,YAAY,UAAU,CAAC,KAAK;AAAA,IAC3F;AAAA,IACA,UAAU,OAAO,KAAK,SAAS;AAC7B,YAAM,QAAkB,CAAC,cAAc,QAAQ,cAAc,CAAC;AAE9D,iBAAW,QAAQ,QAAQ,OAAO;AAChC,cAAM,cAAc,QAAQ,MAAM,IAAI;AAEtC,YAAI,gBAAgB,OAAO;AACzB;AAAA,QACF;AAEA,cAAM,kBAAkB;AAAA,UACtB;AAAA,UACA,gBAAgB,OAAO,CAAC,IAAI;AAAA,UAC5B;AAAA,QACF;AAEA,cAAM,KAAK,GAAG,eAAe;AAAA,MAC/B;AAEA,YAAM,YAAY,0BAA0B,IAAI,iBAAiB,YAAY,UAAU;AAEvF,YAAM,iBAAiB,IAAI,YAAY;AAAA,QACrC,kBAAkB,SAAS;AAAA,QAC3B,WAAW,KAAK;AAAA,QAChB;AAAA,MACF;AACA,YAAM,eAAe,MAAM;AAE3B,UAAI,YAAY,IAAI,cAAc;AAElC,UAAI,QAAQ,iBAAiB,OAAO;AAClC,eAAO,KAAK;AAAA,MACd;AAEA,UAAI,YAAY;AAAA,QACd,qBAAqB,SAAS;AAAA,QAC9B,YAAY,IAAI,iBAAiB,sBAAsB,UAAU;AAAA,QACjE;AAAA,MACF;AAEA,aAAO,KAAK;AAAA,IACd;AAAA,EACF,CAAC;AACH;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,15 @@
1
1
  {
2
2
  "name": "@baeta/plugin-pagination",
3
- "version": "0.0.7-75-20230619184544-4493aaa",
3
+ "version": "0.0.7",
4
+ "keywords": [
5
+ "baeta",
6
+ "graphql",
7
+ "schema",
8
+ "types",
9
+ "typescript",
10
+ "framework",
11
+ "builder"
12
+ ],
4
13
  "homepage": "https://github.com/andreisergiu98/baeta#readme",
5
14
  "bugs": {
6
15
  "url": "https://github.com/andreisergiu98/baeta/issues"
@@ -11,7 +20,10 @@
11
20
  "directory": "packages/plugin-pagination"
12
21
  },
13
22
  "license": "MIT",
14
- "author": "Andrei Pampu <pampu.andrei@pm.me>",
23
+ "author": {
24
+ "name": "Andrei Pampu",
25
+ "url": "https://github.com/andreisergiu98"
26
+ },
15
27
  "type": "module",
16
28
  "exports": {
17
29
  ".": {
@@ -33,14 +45,14 @@
33
45
  "types": "tsc --noEmit"
34
46
  },
35
47
  "dependencies": {
36
- "@baeta/generator-sdk": "^0.0.9-75-20230619184544-4493aaa"
48
+ "@baeta/generator-sdk": "^0.0.9"
37
49
  },
38
50
  "devDependencies": {
39
51
  "@baeta/builder": "^0.0.0",
40
52
  "@baeta/tsconfig": "^0.0.0",
41
- "@types/node": "^18.16.18",
42
- "graphql": "^16.6.0",
43
- "typescript": "^5.1.3"
53
+ "@types/node": "^18.19.0",
54
+ "graphql": "^16.8.1",
55
+ "typescript": "^5.3.2"
44
56
  },
45
57
  "peerDependencies": {
46
58
  "graphql": "^16.6.0"