@baeta/plugin-pagination 0.0.0-57-20230619210342-5073d33
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 +52 -0
- package/dist/index.cjs +106 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +106 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @baeta/plugin-pagination
|
|
2
|
+
|
|
3
|
+
## 0.0.0-57-20230619210342-5073d33
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
+
|
|
9
|
+
- Updated dependencies [[`3cdd9b3`](https://github.com/andreisergiu98/baeta/commit/3cdd9b30369d21179769a4b8d5f76e326ae6db37)]:
|
|
10
|
+
- @baeta/generator-sdk@0.0.0-57-20230619210342-5073d33
|
|
11
|
+
|
|
12
|
+
## 0.0.6
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#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
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`9a4a021`](https://github.com/andreisergiu98/baeta/commit/9a4a0214351b70295ce4f7eecaa8c49ab0e1325b)]:
|
|
19
|
+
- @baeta/generator-sdk@0.0.8
|
|
20
|
+
|
|
21
|
+
## 0.0.5
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies []:
|
|
26
|
+
- @baeta/generator-sdk@0.0.7
|
|
27
|
+
|
|
28
|
+
## 0.0.4
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- [#47](https://github.com/andreisergiu98/baeta/pull/47) [`eb7096d`](https://github.com/andreisergiu98/baeta/commit/eb7096d42a53b17bae0a8365eccb795e7ded02e9) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
|
|
33
|
+
|
|
34
|
+
- [#43](https://github.com/andreisergiu98/baeta/pull/43) [`670501b`](https://github.com/andreisergiu98/baeta/commit/670501b2b1cfb1126be3421293b8ccd597c6ffc2) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - bump dependencies
|
|
35
|
+
|
|
36
|
+
- Updated dependencies [[`eb7096d`](https://github.com/andreisergiu98/baeta/commit/eb7096d42a53b17bae0a8365eccb795e7ded02e9), [`670501b`](https://github.com/andreisergiu98/baeta/commit/670501b2b1cfb1126be3421293b8ccd597c6ffc2)]:
|
|
37
|
+
- @baeta/generator-sdk@0.0.6
|
|
38
|
+
|
|
39
|
+
## 0.0.3
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- [`8569eca`](https://github.com/andreisergiu98/baeta/commit/8569ecaf263e24f8d17f62ea00a0cd374dd27941) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add final new line
|
|
44
|
+
|
|
45
|
+
- [#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
|
|
46
|
+
|
|
47
|
+
## 0.0.2
|
|
48
|
+
|
|
49
|
+
### Patch Changes
|
|
50
|
+
|
|
51
|
+
- Updated dependencies [[`9f937f4`](https://github.com/andreisergiu98/baeta/commit/9f937f47d3464a082680047414ee13a76cf6c056), [`9f937f4`](https://github.com/andreisergiu98/baeta/commit/9f937f47d3464a082680047414ee13a76cf6c056)]:
|
|
52
|
+
- @baeta/generator-sdk@0.0.5
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _generatorsdk = require('@baeta/generator-sdk');
|
|
8
|
+
var _path = require('path');
|
|
9
|
+
function printFields(fields) {
|
|
10
|
+
return fields.map((field) => ` ${field}`).join("\n");
|
|
11
|
+
}
|
|
12
|
+
function printType(name, fields) {
|
|
13
|
+
return `type ${name} {
|
|
14
|
+
${printFields(fields)}
|
|
15
|
+
}`;
|
|
16
|
+
}
|
|
17
|
+
function printTypes(types) {
|
|
18
|
+
return types.join("\n\n") + "\n";
|
|
19
|
+
}
|
|
20
|
+
function printPageInfo(addFields = []) {
|
|
21
|
+
return printType("PageInfo", [
|
|
22
|
+
...addFields,
|
|
23
|
+
"hasPreviousPage: Boolean!",
|
|
24
|
+
"hasNextPage: Boolean!"
|
|
25
|
+
]);
|
|
26
|
+
}
|
|
27
|
+
function printExport(moduleDefinitionName, moduleName) {
|
|
28
|
+
const parsed = _path.parse.call(void 0, moduleDefinitionName);
|
|
29
|
+
const method = _generatorsdk.getModuleGetName.call(void 0, moduleName);
|
|
30
|
+
const importName = parsed.ext === ".ts" ? parsed.name : moduleDefinitionName;
|
|
31
|
+
return `import { ${method} } from "./${importName}";
|
|
32
|
+
|
|
33
|
+
export const ${_generatorsdk.getModuleVariableName.call(void 0, moduleName)} = ${method}();
|
|
34
|
+
`;
|
|
35
|
+
}
|
|
36
|
+
function printConnectionTypes(name, typeOptions, options) {
|
|
37
|
+
const {
|
|
38
|
+
cursorType = "String!",
|
|
39
|
+
nodeType = name,
|
|
40
|
+
connectionFields = [],
|
|
41
|
+
edgeFields = []
|
|
42
|
+
} = typeOptions;
|
|
43
|
+
const connection = printType(`${name}Connection`, [
|
|
44
|
+
...connectionFields,
|
|
45
|
+
"pageInfo: PageInfo!",
|
|
46
|
+
`edges: [${name}Edge]`
|
|
47
|
+
]);
|
|
48
|
+
const edge = printType(`${name}Edge`, [
|
|
49
|
+
...edgeFields,
|
|
50
|
+
`cursor: ${cursorType}`,
|
|
51
|
+
`node: ${nodeType}${options.nullableNode === false ? "!" : ""}`
|
|
52
|
+
]);
|
|
53
|
+
return [connection, edge];
|
|
54
|
+
}
|
|
55
|
+
function createConnectionModuleDir(modulesDir, moduleName) {
|
|
56
|
+
return _path.join.call(void 0, modulesDir, moduleName);
|
|
57
|
+
}
|
|
58
|
+
function createGqlFilename(moduleDir) {
|
|
59
|
+
return `${moduleDir}/connections.gql`;
|
|
60
|
+
}
|
|
61
|
+
function createExportFilename(moduleDir) {
|
|
62
|
+
return `${moduleDir}/index.ts`;
|
|
63
|
+
}
|
|
64
|
+
function paginationPlugin(options) {
|
|
65
|
+
const { moduleName = "baeta-pagination" } = options;
|
|
66
|
+
return _generatorsdk.createPluginV1.call(void 0, {
|
|
67
|
+
name: "pagination",
|
|
68
|
+
actionName: "pagination connections",
|
|
69
|
+
watch: (generatorOptions, watcher) => {
|
|
70
|
+
watcher.ignore(`${createConnectionModuleDir(generatorOptions.modulesDir, moduleName)}/**`);
|
|
71
|
+
},
|
|
72
|
+
generate: async (ctx, next) => {
|
|
73
|
+
const types = [printPageInfo(options.pageInfoFields)];
|
|
74
|
+
for (const name in options.types) {
|
|
75
|
+
const typeOptions = options.types[name];
|
|
76
|
+
if (typeOptions === false) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const connectionTypes = printConnectionTypes(
|
|
80
|
+
name,
|
|
81
|
+
typeOptions === true ? {} : typeOptions,
|
|
82
|
+
options
|
|
83
|
+
);
|
|
84
|
+
types.push(...connectionTypes);
|
|
85
|
+
}
|
|
86
|
+
const moduleDir = createConnectionModuleDir(ctx.generatorOptions.modulesDir, moduleName);
|
|
87
|
+
const definitionFile = new (0, _generatorsdk.File)(createGqlFilename(moduleDir), printTypes(types), "schema");
|
|
88
|
+
await definitionFile.write();
|
|
89
|
+
ctx.fileManager.add(definitionFile);
|
|
90
|
+
if (options.createExport === false) {
|
|
91
|
+
return next();
|
|
92
|
+
}
|
|
93
|
+
const exportFile = new (0, _generatorsdk.File)(
|
|
94
|
+
createExportFilename(moduleDir),
|
|
95
|
+
printExport(ctx.generatorOptions.moduleDefinitionName, moduleName),
|
|
96
|
+
"export"
|
|
97
|
+
);
|
|
98
|
+
ctx.fileManager.add(exportFile);
|
|
99
|
+
return next();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
exports.paginationPlugin = paginationPlugin;
|
|
106
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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,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;AA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/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"]}
|
package/dist/index.d.ts
ADDED
|
@@ -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,106 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import {
|
|
3
|
+
createPluginV1,
|
|
4
|
+
File,
|
|
5
|
+
getModuleGetName,
|
|
6
|
+
getModuleVariableName
|
|
7
|
+
} from "@baeta/generator-sdk";
|
|
8
|
+
import { join, parse } from "path";
|
|
9
|
+
function printFields(fields) {
|
|
10
|
+
return fields.map((field) => ` ${field}`).join("\n");
|
|
11
|
+
}
|
|
12
|
+
function printType(name, fields) {
|
|
13
|
+
return `type ${name} {
|
|
14
|
+
${printFields(fields)}
|
|
15
|
+
}`;
|
|
16
|
+
}
|
|
17
|
+
function printTypes(types) {
|
|
18
|
+
return types.join("\n\n") + "\n";
|
|
19
|
+
}
|
|
20
|
+
function printPageInfo(addFields = []) {
|
|
21
|
+
return printType("PageInfo", [
|
|
22
|
+
...addFields,
|
|
23
|
+
"hasPreviousPage: Boolean!",
|
|
24
|
+
"hasNextPage: Boolean!"
|
|
25
|
+
]);
|
|
26
|
+
}
|
|
27
|
+
function printExport(moduleDefinitionName, moduleName) {
|
|
28
|
+
const parsed = parse(moduleDefinitionName);
|
|
29
|
+
const method = getModuleGetName(moduleName);
|
|
30
|
+
const importName = parsed.ext === ".ts" ? parsed.name : moduleDefinitionName;
|
|
31
|
+
return `import { ${method} } from "./${importName}";
|
|
32
|
+
|
|
33
|
+
export const ${getModuleVariableName(moduleName)} = ${method}();
|
|
34
|
+
`;
|
|
35
|
+
}
|
|
36
|
+
function printConnectionTypes(name, typeOptions, options) {
|
|
37
|
+
const {
|
|
38
|
+
cursorType = "String!",
|
|
39
|
+
nodeType = name,
|
|
40
|
+
connectionFields = [],
|
|
41
|
+
edgeFields = []
|
|
42
|
+
} = typeOptions;
|
|
43
|
+
const connection = printType(`${name}Connection`, [
|
|
44
|
+
...connectionFields,
|
|
45
|
+
"pageInfo: PageInfo!",
|
|
46
|
+
`edges: [${name}Edge]`
|
|
47
|
+
]);
|
|
48
|
+
const edge = printType(`${name}Edge`, [
|
|
49
|
+
...edgeFields,
|
|
50
|
+
`cursor: ${cursorType}`,
|
|
51
|
+
`node: ${nodeType}${options.nullableNode === false ? "!" : ""}`
|
|
52
|
+
]);
|
|
53
|
+
return [connection, edge];
|
|
54
|
+
}
|
|
55
|
+
function createConnectionModuleDir(modulesDir, moduleName) {
|
|
56
|
+
return join(modulesDir, moduleName);
|
|
57
|
+
}
|
|
58
|
+
function createGqlFilename(moduleDir) {
|
|
59
|
+
return `${moduleDir}/connections.gql`;
|
|
60
|
+
}
|
|
61
|
+
function createExportFilename(moduleDir) {
|
|
62
|
+
return `${moduleDir}/index.ts`;
|
|
63
|
+
}
|
|
64
|
+
function paginationPlugin(options) {
|
|
65
|
+
const { moduleName = "baeta-pagination" } = options;
|
|
66
|
+
return createPluginV1({
|
|
67
|
+
name: "pagination",
|
|
68
|
+
actionName: "pagination connections",
|
|
69
|
+
watch: (generatorOptions, watcher) => {
|
|
70
|
+
watcher.ignore(`${createConnectionModuleDir(generatorOptions.modulesDir, moduleName)}/**`);
|
|
71
|
+
},
|
|
72
|
+
generate: async (ctx, next) => {
|
|
73
|
+
const types = [printPageInfo(options.pageInfoFields)];
|
|
74
|
+
for (const name in options.types) {
|
|
75
|
+
const typeOptions = options.types[name];
|
|
76
|
+
if (typeOptions === false) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const connectionTypes = printConnectionTypes(
|
|
80
|
+
name,
|
|
81
|
+
typeOptions === true ? {} : typeOptions,
|
|
82
|
+
options
|
|
83
|
+
);
|
|
84
|
+
types.push(...connectionTypes);
|
|
85
|
+
}
|
|
86
|
+
const moduleDir = createConnectionModuleDir(ctx.generatorOptions.modulesDir, moduleName);
|
|
87
|
+
const definitionFile = new File(createGqlFilename(moduleDir), printTypes(types), "schema");
|
|
88
|
+
await definitionFile.write();
|
|
89
|
+
ctx.fileManager.add(definitionFile);
|
|
90
|
+
if (options.createExport === false) {
|
|
91
|
+
return next();
|
|
92
|
+
}
|
|
93
|
+
const exportFile = new File(
|
|
94
|
+
createExportFilename(moduleDir),
|
|
95
|
+
printExport(ctx.generatorOptions.moduleDefinitionName, moduleName),
|
|
96
|
+
"export"
|
|
97
|
+
);
|
|
98
|
+
ctx.fileManager.add(exportFile);
|
|
99
|
+
return next();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
export {
|
|
104
|
+
paginationPlugin
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,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,kBAAkB;AAAA,IAChD,GAAG;AAAA,IACH;AAAA,IACA,WAAW;AAAA,EACb,CAA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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":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@baeta/plugin-pagination",
|
|
3
|
+
"version": "0.0.0-57-20230619210342-5073d33",
|
|
4
|
+
"homepage": "https://github.com/andreisergiu98/baeta#readme",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/andreisergiu98/baeta/issues"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/andreisergiu98/baeta.git",
|
|
11
|
+
"directory": "packages/plugin-pagination"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Andrei Pampu <pampu.andrei@pm.me>",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist/index.cjs",
|
|
20
|
+
"types": "./dist/index.d.ts"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"types": "dist/index.d.ts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"package.json"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"dev": "tsup --watch",
|
|
31
|
+
"prepack": "prep",
|
|
32
|
+
"postpack": "prep --clean",
|
|
33
|
+
"types": "tsc --noEmit"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@baeta/generator-sdk": "^0.0.0-57-20230619210342-5073d33"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@baeta/builder": "^0.0.0",
|
|
40
|
+
"@baeta/tsconfig": "^0.0.0",
|
|
41
|
+
"@types/node": "^18.16.18",
|
|
42
|
+
"graphql": "^16.6.0",
|
|
43
|
+
"typescript": "^5.1.3"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"graphql": "^16.6.0"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=18.0.0"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
}
|
|
54
|
+
}
|