@baeta/plugin-pagination 0.0.0-107-20241005143517-53e56e9

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 ADDED
@@ -0,0 +1,126 @@
1
+ # @baeta/plugin-pagination
2
+
3
+ ## 0.0.0-107-20241005143517-53e56e9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#152](https://github.com/andreisergiu98/baeta/pull/152) [`d538c79`](https://github.com/andreisergiu98/baeta/commit/d538c7905e6ba96d9f294e2d528f9252e83acbe7) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update formatter
8
+
9
+ - [#145](https://github.com/andreisergiu98/baeta/pull/145) [`08428d4`](https://github.com/andreisergiu98/baeta/commit/08428d4f03b79cab9c116ff7b3a3cf9a0b2620f2) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
10
+
11
+ - Updated dependencies [[`d538c79`](https://github.com/andreisergiu98/baeta/commit/d538c7905e6ba96d9f294e2d528f9252e83acbe7), [`08428d4`](https://github.com/andreisergiu98/baeta/commit/08428d4f03b79cab9c116ff7b3a3cf9a0b2620f2)]:
12
+ - @baeta/generator-sdk@0.0.0-107-20241005143517-53e56e9
13
+ - @baeta/util-path@0.0.0-107-20241005143517-53e56e9
14
+
15
+ ## 0.0.12
16
+
17
+ ### Patch Changes
18
+
19
+ - [#139](https://github.com/andreisergiu98/baeta/pull/139) [`00dbc8f`](https://github.com/andreisergiu98/baeta/commit/00dbc8f35839aaa6524a6c0125ff38a766e45be4) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
20
+
21
+ - [#139](https://github.com/andreisergiu98/baeta/pull/139) [`00dbc8f`](https://github.com/andreisergiu98/baeta/commit/00dbc8f35839aaa6524a6c0125ff38a766e45be4) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update typescript
22
+
23
+ - Updated dependencies [[`00dbc8f`](https://github.com/andreisergiu98/baeta/commit/00dbc8f35839aaa6524a6c0125ff38a766e45be4), [`00dbc8f`](https://github.com/andreisergiu98/baeta/commit/00dbc8f35839aaa6524a6c0125ff38a766e45be4)]:
24
+ - @baeta/generator-sdk@0.0.14
25
+ - @baeta/util-path@0.0.6
26
+
27
+ ## 0.0.11
28
+
29
+ ### Patch Changes
30
+
31
+ - [#128](https://github.com/andreisergiu98/baeta/pull/128) [`534917a`](https://github.com/andreisergiu98/baeta/commit/534917a18e7ed5d788a90a0335a5370d6af8f4a4) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
32
+
33
+ - Updated dependencies [[`534917a`](https://github.com/andreisergiu98/baeta/commit/534917a18e7ed5d788a90a0335a5370d6af8f4a4)]:
34
+ - @baeta/generator-sdk@0.0.13
35
+ - @baeta/util-path@0.0.5
36
+
37
+ ## 0.0.10
38
+
39
+ ### Patch Changes
40
+
41
+ - [#121](https://github.com/andreisergiu98/baeta/pull/121) [`ceae50d`](https://github.com/andreisergiu98/baeta/commit/ceae50d88e4e59b22c603637620f4fc6b28b2454) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Update Node to v20
42
+
43
+ - [#51](https://github.com/andreisergiu98/baeta/pull/51) [`d94ee47`](https://github.com/andreisergiu98/baeta/commit/d94ee47bc485c541ff011290c4ac6ef0c145c83f) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add native support for file monifications
44
+
45
+ - Updated dependencies [[`ceae50d`](https://github.com/andreisergiu98/baeta/commit/ceae50d88e4e59b22c603637620f4fc6b28b2454), [`d94ee47`](https://github.com/andreisergiu98/baeta/commit/d94ee47bc485c541ff011290c4ac6ef0c145c83f)]:
46
+ - @baeta/generator-sdk@0.0.12
47
+ - @baeta/util-path@0.0.4
48
+
49
+ ## 0.0.9
50
+
51
+ ### Patch Changes
52
+
53
+ - [#119](https://github.com/andreisergiu98/baeta/pull/119) [`643a2eb`](https://github.com/andreisergiu98/baeta/commit/643a2eb17c2789cd25361ddeede149a0e459e68a) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
54
+
55
+ - Updated dependencies [[`18db339`](https://github.com/andreisergiu98/baeta/commit/18db339719aa309c619372d2161c5fdbc08fa316), [`643a2eb`](https://github.com/andreisergiu98/baeta/commit/643a2eb17c2789cd25361ddeede149a0e459e68a)]:
56
+ - @baeta/generator-sdk@0.0.11
57
+ - @baeta/util-path@0.0.3
58
+
59
+ ## 0.0.8
60
+
61
+ ### Patch Changes
62
+
63
+ - [#102](https://github.com/andreisergiu98/baeta/pull/102) [`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
64
+
65
+ - [#102](https://github.com/andreisergiu98/baeta/pull/102) [`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies and builder
66
+
67
+ - [#106](https://github.com/andreisergiu98/baeta/pull/106) [`01788ab`](https://github.com/andreisergiu98/baeta/commit/01788ab04ff6956b2b50186af5bec8ed7ebbe76e) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add compatibility with windows
68
+
69
+ - Updated dependencies [[`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c), [`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c), [`01788ab`](https://github.com/andreisergiu98/baeta/commit/01788ab04ff6956b2b50186af5bec8ed7ebbe76e)]:
70
+ - @baeta/generator-sdk@0.0.10
71
+ - @baeta/util-path@0.0.2
72
+
73
+ ## 0.0.7
74
+
75
+ ### Patch Changes
76
+
77
+ - [#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
78
+
79
+ - [#69](https://github.com/andreisergiu98/baeta/pull/69) [`3cdd9b3`](https://github.com/andreisergiu98/baeta/commit/3cdd9b30369d21179769a4b8d5f76e326ae6db37) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
80
+
81
+ - [#91](https://github.com/andreisergiu98/baeta/pull/91) [`e0944f6`](https://github.com/andreisergiu98/baeta/commit/e0944f6320e6cf2f0a3d2c9f51edd282bdce0546) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
82
+
83
+ - 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)]:
84
+ - @baeta/generator-sdk@0.0.9
85
+
86
+ ## 0.0.6
87
+
88
+ ### Patch Changes
89
+
90
+ - [#66](https://github.com/andreisergiu98/baeta/pull/66) [`9a4a021`](https://github.com/andreisergiu98/baeta/commit/9a4a0214351b70295ce4f7eecaa8c49ab0e1325b) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - replace chokidar with @parcel/watcher
91
+
92
+ - Updated dependencies [[`9a4a021`](https://github.com/andreisergiu98/baeta/commit/9a4a0214351b70295ce4f7eecaa8c49ab0e1325b)]:
93
+ - @baeta/generator-sdk@0.0.8
94
+
95
+ ## 0.0.5
96
+
97
+ ### Patch Changes
98
+
99
+ - Updated dependencies []:
100
+ - @baeta/generator-sdk@0.0.7
101
+
102
+ ## 0.0.4
103
+
104
+ ### Patch Changes
105
+
106
+ - [#47](https://github.com/andreisergiu98/baeta/pull/47) [`eb7096d`](https://github.com/andreisergiu98/baeta/commit/eb7096d42a53b17bae0a8365eccb795e7ded02e9) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
107
+
108
+ - [#43](https://github.com/andreisergiu98/baeta/pull/43) [`670501b`](https://github.com/andreisergiu98/baeta/commit/670501b2b1cfb1126be3421293b8ccd597c6ffc2) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - bump dependencies
109
+
110
+ - Updated dependencies [[`eb7096d`](https://github.com/andreisergiu98/baeta/commit/eb7096d42a53b17bae0a8365eccb795e7ded02e9), [`670501b`](https://github.com/andreisergiu98/baeta/commit/670501b2b1cfb1126be3421293b8ccd597c6ffc2)]:
111
+ - @baeta/generator-sdk@0.0.6
112
+
113
+ ## 0.0.3
114
+
115
+ ### Patch Changes
116
+
117
+ - [`8569eca`](https://github.com/andreisergiu98/baeta/commit/8569ecaf263e24f8d17f62ea00a0cd374dd27941) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add final new line
118
+
119
+ - [#31](https://github.com/andreisergiu98/baeta/pull/31) [`f122a1e`](https://github.com/andreisergiu98/baeta/commit/f122a1e2970d915ce3c24931d4309db26665c739) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - ignore generated sdl
120
+
121
+ ## 0.0.2
122
+
123
+ ### Patch Changes
124
+
125
+ - Updated dependencies [[`9f937f4`](https://github.com/andreisergiu98/baeta/commit/9f937f47d3464a082680047414ee13a76cf6c056), [`9f937f4`](https://github.com/andreisergiu98/baeta/commit/9f937f47d3464a082680047414ee13a76cf6c056)]:
126
+ - @baeta/generator-sdk@0.0.5
package/dist/index.cjs ADDED
@@ -0,0 +1,105 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
2
+ var _generatorsdk = require('@baeta/generator-sdk');
3
+ var _utilpath = require('@baeta/util-path');
4
+ function printFields(fields) {
5
+ return fields.map((field) => ` ${field}`).join("\n");
6
+ }
7
+ function printType(name, fields) {
8
+ return `type ${name} {
9
+ ${printFields(fields)}
10
+ }`;
11
+ }
12
+ function printTypes(types) {
13
+ return `${types.join("\n\n")}
14
+ `;
15
+ }
16
+ function printPageInfo(addFields = []) {
17
+ return printType("PageInfo", [
18
+ ...addFields,
19
+ "hasPreviousPage: Boolean!",
20
+ "hasNextPage: Boolean!"
21
+ ]);
22
+ }
23
+ function printExport(moduleDefinitionName, moduleName) {
24
+ const parsed = _utilpath.parse.call(void 0, moduleDefinitionName);
25
+ const method = _generatorsdk.getModuleGetName.call(void 0, moduleName);
26
+ const importName = parsed.ext === ".ts" ? parsed.name : moduleDefinitionName;
27
+ return `import { ${method} } from "./${importName}";
28
+
29
+ export const ${_generatorsdk.getModuleVariableName.call(void 0, moduleName)} = ${method}();
30
+ `;
31
+ }
32
+ function printConnectionTypes(name, typeOptions, options) {
33
+ const {
34
+ cursorType = "String!",
35
+ nodeType = name,
36
+ connectionFields = [],
37
+ edgeFields = []
38
+ } = typeOptions;
39
+ const connection = printType(`${name}Connection`, [
40
+ ...connectionFields,
41
+ "pageInfo: PageInfo!",
42
+ `edges: [${name}Edge]`
43
+ ]);
44
+ const edge = printType(`${name}Edge`, [
45
+ ...edgeFields,
46
+ `cursor: ${cursorType}`,
47
+ `node: ${nodeType}${options.nullableNode === false ? "!" : ""}`
48
+ ]);
49
+ return [connection, edge];
50
+ }
51
+ function createConnectionModuleDir(modulesDir, moduleName) {
52
+ return _utilpath.join.call(void 0, modulesDir, moduleName);
53
+ }
54
+ function createGqlFilename(moduleDir) {
55
+ return `${moduleDir}/connections.gql`;
56
+ }
57
+ function createExportFilename(moduleDir) {
58
+ return `${moduleDir}/index.ts`;
59
+ }
60
+ function paginationPlugin(options) {
61
+ const { moduleName = "baeta-pagination" } = options;
62
+ return _generatorsdk.createPluginV1.call(void 0, {
63
+ name: "pagination",
64
+ actionName: "pagination connections",
65
+ watch: (generatorOptions, watcher) => {
66
+ watcher.ignore(`${createConnectionModuleDir(generatorOptions.modulesDir, moduleName)}/**`);
67
+ },
68
+ generate: async (ctx, next) => {
69
+ const types = [printPageInfo(options.pageInfoFields)];
70
+ for (const name in options.types) {
71
+ const typeOptions = options.types[name];
72
+ if (typeOptions === false) {
73
+ continue;
74
+ }
75
+ const connectionTypes = printConnectionTypes(
76
+ name,
77
+ typeOptions === true ? {} : typeOptions,
78
+ options
79
+ );
80
+ types.push(...connectionTypes);
81
+ }
82
+ const moduleDir = createConnectionModuleDir(ctx.generatorOptions.modulesDir, moduleName);
83
+ const definitionFile = ctx.fileManager.createAndAdd(
84
+ createGqlFilename(moduleDir),
85
+ printTypes(types),
86
+ "pagination"
87
+ );
88
+ await definitionFile.write();
89
+ ctx.fileManager.add(definitionFile);
90
+ if (options.createExport === false) {
91
+ return next();
92
+ }
93
+ ctx.fileManager.createAndAdd(
94
+ createExportFilename(moduleDir),
95
+ printExport(ctx.generatorOptions.moduleDefinitionName, moduleName),
96
+ "pagination"
97
+ );
98
+ return next();
99
+ }
100
+ });
101
+ }
102
+
103
+
104
+ exports.paginationPlugin = paginationPlugin;
105
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/baeta/baeta/packages/plugin-pagination/dist/index.cjs","../index.ts"],"names":[],"mappings":"AAAA;ACAA,oDAAwE;AACxE,4CAA4B;AAiB5B,SAAS,WAAA,CAAY,MAAA,EAAkB;AACtC,EAAA,OAAO,MAAA,CAAO,GAAA,CAAI,CAAC,KAAA,EAAA,GAAU,CAAA,EAAA,EAAK,KAAK,CAAA,CAAA;AACxC;AAEmD;AAC/B,EAAA;AACC;AAAA,CAAA;AAErB;AAEqC;AACR,EAAA;AAAA;AAC7B;AAEiD;AACnB,EAAA;AACzB,IAAA;AACH,IAAA;AACA,IAAA;AACA,EAAA;AACF;AAEqB;AACC,EAAA;AACW,EAAA;AACE,EAAA;AAEK,EAAA;AAAU;AAEb,aAAA;AAAuB;AAE5D;AAE4C;AACrC,EAAA;AACQ,IAAA;AACF,IAAA;AACS,IAAA;AACN,IAAA;AACX,EAAA;AAEgC,EAAA;AAChC,IAAA;AACH,IAAA;AACe,IAAA;AACf,EAAA;AAEqC,EAAA;AAClC,IAAA;AACkB,IAAA;AACO,IAAA;AAC5B,EAAA;AAEuB,EAAA;AACzB;AAEmC;AACA,EAAA;AACnC;AAE8C;AAC1B,EAAA;AACpB;AAEiD;AAC7B,EAAA;AACpB;AAE6D;AACpB,EAAA;AAElB,EAAA;AACf,IAAA;AACM,IAAA;AAC0B,IAAA;AACnB,MAAA;AACnB,IAAA;AAC+B,IAAA;AACS,MAAA;AAEL,MAAA;AACC,QAAA;AAEP,QAAA;AAC1B,UAAA;AACD,QAAA;AAEwB,QAAA;AACvB,UAAA;AAC4B,UAAA;AAC5B,UAAA;AACD,QAAA;AAE6B,QAAA;AAC9B,MAAA;AAEkB,MAAA;AAES,MAAA;AACC,QAAA;AACX,QAAA;AAChB,QAAA;AACD,MAAA;AAC2B,MAAA;AAEO,MAAA;AAEE,MAAA;AACvB,QAAA;AACb,MAAA;AAEgB,MAAA;AACe,QAAA;AACG,QAAA;AACjC,QAAA;AACD,MAAA;AAEY,MAAA;AACb,IAAA;AACA,EAAA;AACF;ADrC0C;AACA;AACA","file":"/home/runner/work/baeta/baeta/packages/plugin-pagination/dist/index.cjs","sourcesContent":[null,"import { createPluginV1, getModuleGetName, getModuleVariableName } from '@baeta/generator-sdk';\nimport { join, parse } from '@baeta/util-path';\n\ninterface TypeOptions {\n\tnodeType?: string;\n\tcursorType?: string;\n\tedgeFields?: string[];\n\tconnectionFields?: string[];\n}\n\ninterface PaginationOptions {\n\ttypes: Record<string, boolean | TypeOptions>;\n\tnullableNode?: boolean;\n\tpageInfoFields?: string[];\n\tmoduleName?: string;\n\tcreateExport?: boolean;\n}\n\nfunction printFields(fields: string[]) {\n\treturn fields.map((field) => ` ${field}`).join('\\n');\n}\n\nfunction printType(name: string, fields: string[]) {\n\treturn `type ${name} {\n${printFields(fields)}\n}`;\n}\n\nfunction printTypes(types: string[]) {\n\treturn `${types.join('\\n\\n')}\\n`;\n}\n\nfunction printPageInfo(addFields: string[] = []) {\n\treturn printType('PageInfo', [\n\t\t...addFields,\n\t\t'hasPreviousPage: Boolean!',\n\t\t'hasNextPage: Boolean!',\n\t]);\n}\n\nfunction printExport(moduleDefinitionName: string, moduleName: string) {\n\tconst parsed = parse(moduleDefinitionName);\n\tconst method = getModuleGetName(moduleName);\n\tconst importName = parsed.ext === '.ts' ? parsed.name : moduleDefinitionName;\n\n\treturn `import { ${method} } from \"./${importName}\";\n\nexport const ${getModuleVariableName(moduleName)} = ${method}();\n`;\n}\n\nfunction printConnectionTypes(name: string, typeOptions: TypeOptions, options: PaginationOptions) {\n\tconst {\n\t\tcursorType = 'String!',\n\t\tnodeType = name,\n\t\tconnectionFields = [],\n\t\tedgeFields = [],\n\t} = typeOptions;\n\n\tconst connection = printType(`${name}Connection`, [\n\t\t...connectionFields,\n\t\t'pageInfo: PageInfo!',\n\t\t`edges: [${name}Edge]`,\n\t]);\n\n\tconst edge = printType(`${name}Edge`, [\n\t\t...edgeFields,\n\t\t`cursor: ${cursorType}`,\n\t\t`node: ${nodeType}${options.nullableNode === false ? '!' : ''}`,\n\t]);\n\n\treturn [connection, edge];\n}\n\nfunction createConnectionModuleDir(modulesDir: string, moduleName: string) {\n\treturn join(modulesDir, moduleName);\n}\n\nfunction createGqlFilename(moduleDir: string) {\n\treturn `${moduleDir}/connections.gql`;\n}\n\nfunction createExportFilename(moduleDir: string) {\n\treturn `${moduleDir}/index.ts`;\n}\n\nexport function paginationPlugin(options: PaginationOptions) {\n\tconst { moduleName = 'baeta-pagination' } = options;\n\n\treturn createPluginV1({\n\t\tname: 'pagination',\n\t\tactionName: 'pagination connections',\n\t\twatch: (generatorOptions, watcher) => {\n\t\t\twatcher.ignore(`${createConnectionModuleDir(generatorOptions.modulesDir, moduleName)}/**`);\n\t\t},\n\t\tgenerate: async (ctx, next) => {\n\t\t\tconst types: string[] = [printPageInfo(options.pageInfoFields)];\n\n\t\t\tfor (const name in options.types) {\n\t\t\t\tconst typeOptions = options.types[name];\n\n\t\t\t\tif (typeOptions === false) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst connectionTypes = printConnectionTypes(\n\t\t\t\t\tname,\n\t\t\t\t\ttypeOptions === true ? {} : typeOptions,\n\t\t\t\t\toptions,\n\t\t\t\t);\n\n\t\t\t\ttypes.push(...connectionTypes);\n\t\t\t}\n\n\t\t\tconst moduleDir = createConnectionModuleDir(ctx.generatorOptions.modulesDir, moduleName);\n\n\t\t\tconst definitionFile = ctx.fileManager.createAndAdd(\n\t\t\t\tcreateGqlFilename(moduleDir),\n\t\t\t\tprintTypes(types),\n\t\t\t\t'pagination',\n\t\t\t);\n\t\t\tawait definitionFile.write();\n\n\t\t\tctx.fileManager.add(definitionFile);\n\n\t\t\tif (options.createExport === false) {\n\t\t\t\treturn next();\n\t\t\t}\n\n\t\t\tctx.fileManager.createAndAdd(\n\t\t\t\tcreateExportFilename(moduleDir),\n\t\t\t\tprintExport(ctx.generatorOptions.moduleDefinitionName, moduleName),\n\t\t\t\t'pagination',\n\t\t\t);\n\n\t\t\treturn next();\n\t\t},\n\t});\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 };
@@ -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 ADDED
@@ -0,0 +1,105 @@
1
+ // index.ts
2
+ import { createPluginV1, getModuleGetName, getModuleVariableName } from "@baeta/generator-sdk";
3
+ import { join, parse } from "@baeta/util-path";
4
+ function printFields(fields) {
5
+ return fields.map((field) => ` ${field}`).join("\n");
6
+ }
7
+ function printType(name, fields) {
8
+ return `type ${name} {
9
+ ${printFields(fields)}
10
+ }`;
11
+ }
12
+ function printTypes(types) {
13
+ return `${types.join("\n\n")}
14
+ `;
15
+ }
16
+ function printPageInfo(addFields = []) {
17
+ return printType("PageInfo", [
18
+ ...addFields,
19
+ "hasPreviousPage: Boolean!",
20
+ "hasNextPage: Boolean!"
21
+ ]);
22
+ }
23
+ function printExport(moduleDefinitionName, moduleName) {
24
+ const parsed = parse(moduleDefinitionName);
25
+ const method = getModuleGetName(moduleName);
26
+ const importName = parsed.ext === ".ts" ? parsed.name : moduleDefinitionName;
27
+ return `import { ${method} } from "./${importName}";
28
+
29
+ export const ${getModuleVariableName(moduleName)} = ${method}();
30
+ `;
31
+ }
32
+ function printConnectionTypes(name, typeOptions, options) {
33
+ const {
34
+ cursorType = "String!",
35
+ nodeType = name,
36
+ connectionFields = [],
37
+ edgeFields = []
38
+ } = typeOptions;
39
+ const connection = printType(`${name}Connection`, [
40
+ ...connectionFields,
41
+ "pageInfo: PageInfo!",
42
+ `edges: [${name}Edge]`
43
+ ]);
44
+ const edge = printType(`${name}Edge`, [
45
+ ...edgeFields,
46
+ `cursor: ${cursorType}`,
47
+ `node: ${nodeType}${options.nullableNode === false ? "!" : ""}`
48
+ ]);
49
+ return [connection, edge];
50
+ }
51
+ function createConnectionModuleDir(modulesDir, moduleName) {
52
+ return join(modulesDir, moduleName);
53
+ }
54
+ function createGqlFilename(moduleDir) {
55
+ return `${moduleDir}/connections.gql`;
56
+ }
57
+ function createExportFilename(moduleDir) {
58
+ return `${moduleDir}/index.ts`;
59
+ }
60
+ function paginationPlugin(options) {
61
+ const { moduleName = "baeta-pagination" } = options;
62
+ return createPluginV1({
63
+ name: "pagination",
64
+ actionName: "pagination connections",
65
+ watch: (generatorOptions, watcher) => {
66
+ watcher.ignore(`${createConnectionModuleDir(generatorOptions.modulesDir, moduleName)}/**`);
67
+ },
68
+ generate: async (ctx, next) => {
69
+ const types = [printPageInfo(options.pageInfoFields)];
70
+ for (const name in options.types) {
71
+ const typeOptions = options.types[name];
72
+ if (typeOptions === false) {
73
+ continue;
74
+ }
75
+ const connectionTypes = printConnectionTypes(
76
+ name,
77
+ typeOptions === true ? {} : typeOptions,
78
+ options
79
+ );
80
+ types.push(...connectionTypes);
81
+ }
82
+ const moduleDir = createConnectionModuleDir(ctx.generatorOptions.modulesDir, moduleName);
83
+ const definitionFile = ctx.fileManager.createAndAdd(
84
+ createGqlFilename(moduleDir),
85
+ printTypes(types),
86
+ "pagination"
87
+ );
88
+ await definitionFile.write();
89
+ ctx.fileManager.add(definitionFile);
90
+ if (options.createExport === false) {
91
+ return next();
92
+ }
93
+ ctx.fileManager.createAndAdd(
94
+ createExportFilename(moduleDir),
95
+ printExport(ctx.generatorOptions.moduleDefinitionName, moduleName),
96
+ "pagination"
97
+ );
98
+ return next();
99
+ }
100
+ });
101
+ }
102
+ export {
103
+ paginationPlugin
104
+ };
105
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../index.ts"],"sourcesContent":["import { createPluginV1, getModuleGetName, getModuleVariableName } from '@baeta/generator-sdk';\nimport { join, parse } from '@baeta/util-path';\n\ninterface TypeOptions {\n\tnodeType?: string;\n\tcursorType?: string;\n\tedgeFields?: string[];\n\tconnectionFields?: string[];\n}\n\ninterface PaginationOptions {\n\ttypes: Record<string, boolean | TypeOptions>;\n\tnullableNode?: boolean;\n\tpageInfoFields?: string[];\n\tmoduleName?: string;\n\tcreateExport?: boolean;\n}\n\nfunction printFields(fields: string[]) {\n\treturn fields.map((field) => ` ${field}`).join('\\n');\n}\n\nfunction printType(name: string, fields: string[]) {\n\treturn `type ${name} {\n${printFields(fields)}\n}`;\n}\n\nfunction printTypes(types: string[]) {\n\treturn `${types.join('\\n\\n')}\\n`;\n}\n\nfunction printPageInfo(addFields: string[] = []) {\n\treturn printType('PageInfo', [\n\t\t...addFields,\n\t\t'hasPreviousPage: Boolean!',\n\t\t'hasNextPage: Boolean!',\n\t]);\n}\n\nfunction printExport(moduleDefinitionName: string, moduleName: string) {\n\tconst parsed = parse(moduleDefinitionName);\n\tconst method = getModuleGetName(moduleName);\n\tconst importName = parsed.ext === '.ts' ? parsed.name : moduleDefinitionName;\n\n\treturn `import { ${method} } from \"./${importName}\";\n\nexport const ${getModuleVariableName(moduleName)} = ${method}();\n`;\n}\n\nfunction printConnectionTypes(name: string, typeOptions: TypeOptions, options: PaginationOptions) {\n\tconst {\n\t\tcursorType = 'String!',\n\t\tnodeType = name,\n\t\tconnectionFields = [],\n\t\tedgeFields = [],\n\t} = typeOptions;\n\n\tconst connection = printType(`${name}Connection`, [\n\t\t...connectionFields,\n\t\t'pageInfo: PageInfo!',\n\t\t`edges: [${name}Edge]`,\n\t]);\n\n\tconst edge = printType(`${name}Edge`, [\n\t\t...edgeFields,\n\t\t`cursor: ${cursorType}`,\n\t\t`node: ${nodeType}${options.nullableNode === false ? '!' : ''}`,\n\t]);\n\n\treturn [connection, edge];\n}\n\nfunction createConnectionModuleDir(modulesDir: string, moduleName: string) {\n\treturn join(modulesDir, moduleName);\n}\n\nfunction createGqlFilename(moduleDir: string) {\n\treturn `${moduleDir}/connections.gql`;\n}\n\nfunction createExportFilename(moduleDir: string) {\n\treturn `${moduleDir}/index.ts`;\n}\n\nexport function paginationPlugin(options: PaginationOptions) {\n\tconst { moduleName = 'baeta-pagination' } = options;\n\n\treturn createPluginV1({\n\t\tname: 'pagination',\n\t\tactionName: 'pagination connections',\n\t\twatch: (generatorOptions, watcher) => {\n\t\t\twatcher.ignore(`${createConnectionModuleDir(generatorOptions.modulesDir, moduleName)}/**`);\n\t\t},\n\t\tgenerate: async (ctx, next) => {\n\t\t\tconst types: string[] = [printPageInfo(options.pageInfoFields)];\n\n\t\t\tfor (const name in options.types) {\n\t\t\t\tconst typeOptions = options.types[name];\n\n\t\t\t\tif (typeOptions === false) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst connectionTypes = printConnectionTypes(\n\t\t\t\t\tname,\n\t\t\t\t\ttypeOptions === true ? {} : typeOptions,\n\t\t\t\t\toptions,\n\t\t\t\t);\n\n\t\t\t\ttypes.push(...connectionTypes);\n\t\t\t}\n\n\t\t\tconst moduleDir = createConnectionModuleDir(ctx.generatorOptions.modulesDir, moduleName);\n\n\t\t\tconst definitionFile = ctx.fileManager.createAndAdd(\n\t\t\t\tcreateGqlFilename(moduleDir),\n\t\t\t\tprintTypes(types),\n\t\t\t\t'pagination',\n\t\t\t);\n\t\t\tawait definitionFile.write();\n\n\t\t\tctx.fileManager.add(definitionFile);\n\n\t\t\tif (options.createExport === false) {\n\t\t\t\treturn next();\n\t\t\t}\n\n\t\t\tctx.fileManager.createAndAdd(\n\t\t\t\tcreateExportFilename(moduleDir),\n\t\t\t\tprintExport(ctx.generatorOptions.moduleDefinitionName, moduleName),\n\t\t\t\t'pagination',\n\t\t\t);\n\n\t\t\treturn next();\n\t\t},\n\t});\n}\n"],"mappings":"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","names":[]}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@baeta/plugin-pagination",
3
+ "version": "0.0.0-107-20241005143517-53e56e9",
4
+ "keywords": [
5
+ "baeta",
6
+ "graphql",
7
+ "schema",
8
+ "types",
9
+ "typescript",
10
+ "framework",
11
+ "builder"
12
+ ],
13
+ "homepage": "https://github.com/andreisergiu98/baeta#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/andreisergiu98/baeta/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/andreisergiu98/baeta.git",
20
+ "directory": "packages/plugin-pagination"
21
+ },
22
+ "license": "MIT",
23
+ "author": {
24
+ "name": "Andrei Pampu",
25
+ "url": "https://github.com/andreisergiu98"
26
+ },
27
+ "type": "module",
28
+ "exports": {
29
+ ".": {
30
+ "import": "./dist/index.js",
31
+ "require": "./dist/index.cjs",
32
+ "types": "./dist/index.d.ts"
33
+ }
34
+ },
35
+ "types": "dist/index.d.ts",
36
+ "files": [
37
+ "dist",
38
+ "package.json"
39
+ ],
40
+ "scripts": {
41
+ "build": "tsup",
42
+ "prepack": "prep",
43
+ "postpack": "prep --clean",
44
+ "types": "tsc --noEmit"
45
+ },
46
+ "dependencies": {
47
+ "@baeta/generator-sdk": "^0.0.0-107-20241005143517-53e56e9",
48
+ "@baeta/util-path": "^0.0.0-107-20241005143517-53e56e9"
49
+ },
50
+ "devDependencies": {
51
+ "@baeta/builder": "^0.0.0",
52
+ "@baeta/tsconfig": "^0.0.0",
53
+ "@types/node": "^20.16.10",
54
+ "graphql": "^16.9.0",
55
+ "typescript": "^5.6.2"
56
+ },
57
+ "peerDependencies": {
58
+ "graphql": "^16.6.0"
59
+ },
60
+ "engines": {
61
+ "node": ">=20.0.0"
62
+ },
63
+ "publishConfig": {
64
+ "access": "public"
65
+ }
66
+ }