@baeta/plugin-pagination 0.1.2 → 0.1.4
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 +22 -0
- package/LICENSE +21 -0
- package/README.md +139 -0
- package/package.json +15 -10
- package/dist/index.cjs +0 -109
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @baeta/plugin-pagination
|
|
2
2
|
|
|
3
|
+
## 0.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`b59db50`](https://github.com/andreisergiu98/baeta/commit/b59db501a83275ab2d964933080e688a3a5d8820) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add readme
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`b59db50`](https://github.com/andreisergiu98/baeta/commit/b59db501a83275ab2d964933080e688a3a5d8820)]:
|
|
10
|
+
- @baeta/generator-sdk@0.1.4
|
|
11
|
+
- @baeta/util-path@0.1.4
|
|
12
|
+
|
|
13
|
+
## 0.1.3
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#180](https://github.com/andreisergiu98/baeta/pull/180) [`483c709`](https://github.com/andreisergiu98/baeta/commit/483c70932f815fd114732c00b74f9488d7924c72) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Raise minimum required NodeJS version to 22.12.0. Drop CommonJS builds in favor of the require_esm feature from NodeJS 22.12.0 onwards.
|
|
18
|
+
|
|
19
|
+
- [`de6e89c`](https://github.com/andreisergiu98/baeta/commit/de6e89c1b592e280967c73a4137d24ee56ef1857) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - raise es target to 2024
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [[`483c709`](https://github.com/andreisergiu98/baeta/commit/483c70932f815fd114732c00b74f9488d7924c72), [`de6e89c`](https://github.com/andreisergiu98/baeta/commit/de6e89c1b592e280967c73a4137d24ee56ef1857)]:
|
|
22
|
+
- @baeta/generator-sdk@0.1.3
|
|
23
|
+
- @baeta/util-path@0.1.3
|
|
24
|
+
|
|
3
25
|
## 0.1.2
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Pampu Andrei
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/andreisergiu98/baeta/refs/heads/main/website/static/img/logo-baeta.svg" alt="Baeta Logo" width="150"/>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<div align="center">
|
|
6
|
+
<h1>Baeta</h1>
|
|
7
|
+
<a href="https://www.npmjs.com/package/@baeta/cli"><img src="https://img.shields.io/npm/v/@baeta/cli.svg?style=flat" /></a>
|
|
8
|
+
<a href="https://github.com/andreisergiu98/baeta/actions/workflows/testing.yml"><img src="https://img.shields.io/github/actions/workflow/status/andreisergiu98/baeta/testing.yml" /></a>
|
|
9
|
+
<a href="https://github.com/andreisergiu98/baeta/pulls"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" /></a>
|
|
10
|
+
<a href="https://github.com/andreisergiu98/baeta/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" /></a>
|
|
11
|
+
<br />
|
|
12
|
+
<br />
|
|
13
|
+
<a href="https://baeta.io/docs/getting-started/installation">Getting Started</a>
|
|
14
|
+
<span> • </span>
|
|
15
|
+
<a href="https://www.baeta.io/">Website</a>
|
|
16
|
+
<span> • </span>
|
|
17
|
+
<a href="https://baeta.io/docs/intro">Docs</a>
|
|
18
|
+
<span> • </span>
|
|
19
|
+
<a href="https://github.com/andreisergiu98/baeta/tree/main/examples">Examples</a>
|
|
20
|
+
<span> • </span>
|
|
21
|
+
<a href="https://discord.gg/BHFXHvyj">Discord</a>
|
|
22
|
+
<br />
|
|
23
|
+
<hr />
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
# What is Baeta?
|
|
27
|
+
|
|
28
|
+
Building GraphQL APIs shouldn't be complicated. **Baeta** is a modern, modular, open-source GraphQL framework designed with flexibility in mind. It follows a granular approach where you only add what you need, helping developers focus on what matters most - creating powerful, scalable APIs without the boilerplate.
|
|
29
|
+
|
|
30
|
+
### Key Features
|
|
31
|
+
|
|
32
|
+
- **Modular Architecture**: Organize your API into manageable modules
|
|
33
|
+
- **Schema-First Development**: Define your API contract upfront
|
|
34
|
+
- **Type Safety**: Automatic code generation for type-safe development
|
|
35
|
+
- **Middleware & Directives**: Easy integration of custom behaviors
|
|
36
|
+
- **High Performance**: Built for scalability and efficiency
|
|
37
|
+
|
|
38
|
+
#### And optional extensions and plugins
|
|
39
|
+
|
|
40
|
+
- **@baeta/extension-auth**: Add powerful scope-based authorization
|
|
41
|
+
- **@baeta/extension-cache**: Implement automatic caching with simple update patterns
|
|
42
|
+
- ... and more!
|
|
43
|
+
|
|
44
|
+
## Why use Baeta?
|
|
45
|
+
|
|
46
|
+
Baeta makes it easy to build better GraphQL APIs while staying flexible. Here's how:
|
|
47
|
+
|
|
48
|
+
**Granular and Progressive:** Start small and add features as you need them. Whether you're building a simple API or a complex system, Baeta scales with your needs.
|
|
49
|
+
|
|
50
|
+
**Modular architecture:** Baeta's modular design allows you to organize your GraphQL API into smaller, more manageable modules that can be added or removed as needed. This makes it easier to maintain and scale your API over time.
|
|
51
|
+
|
|
52
|
+
**Schema-first approach:** With Baeta, you define your schema first, and then logic and resolvers. This approach ensures a consistent and well-defined API for your clients and reduces boilerplate code.
|
|
53
|
+
|
|
54
|
+
## How it Works
|
|
55
|
+
|
|
56
|
+
#### 1. Define your schema
|
|
57
|
+
|
|
58
|
+
```graphql
|
|
59
|
+
type User {
|
|
60
|
+
id: ID!
|
|
61
|
+
name: String!
|
|
62
|
+
email: String!
|
|
63
|
+
age: Int
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
input UserWhereUnique {
|
|
67
|
+
id: ID
|
|
68
|
+
email: String
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type Query {
|
|
72
|
+
user(where: UserWhereUnique!): User!
|
|
73
|
+
users: [User!]!
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### 2. Implement your resolvers
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { getUserModule } from "./typedef";
|
|
81
|
+
|
|
82
|
+
const { Query } = getUserModule();
|
|
83
|
+
|
|
84
|
+
Query.user(({ args }) => {
|
|
85
|
+
return dataSource.user.find(args.where);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
Query.users(() => {
|
|
89
|
+
return dataSource.user.findMany();
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### 3. Add authorization
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
const { Query, Mutation } = getUserModule();
|
|
97
|
+
|
|
98
|
+
Query.users.$auth({
|
|
99
|
+
$or: {
|
|
100
|
+
isPublic: true,
|
|
101
|
+
isLoggedIn: true,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### 4. Add caching
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { getUserModule } from "./typedef";
|
|
110
|
+
|
|
111
|
+
const { User, Query } = getUserModule();
|
|
112
|
+
|
|
113
|
+
export const userCache = User.$createCache();
|
|
114
|
+
|
|
115
|
+
Query.user.$useCache(userCache);
|
|
116
|
+
Query.users.$useCache(userCache);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Compatibility
|
|
120
|
+
|
|
121
|
+
Baeta is compatible with all GraphQL servers, which makes it easy to integrate with your existing stack. It works seamlessly with popular GraphQL server libraries such as **Graphql Yoga** and **Apollo Server**, as well as other popular tools like **Prisma**, **Drizzle** and **Kysely**.
|
|
122
|
+
|
|
123
|
+
Baeta's development tools are built for Node.js, but the runtime code is environment-agnostic. This means your Baeta applications can run anywhere JavaScript runs, including:
|
|
124
|
+
|
|
125
|
+
- Deno
|
|
126
|
+
- Cloudflare Workers
|
|
127
|
+
- AWS Lambda
|
|
128
|
+
- Vercel Edge Functions
|
|
129
|
+
- Bun
|
|
130
|
+
- Node.js
|
|
131
|
+
- Any other JavaScript runtime
|
|
132
|
+
|
|
133
|
+
## Credits
|
|
134
|
+
|
|
135
|
+
Baeta was inspired by several amazing projects and people in the GraphQL ecosystem. Check out our [Credits page](https://baeta.io/docs/credits) to learn more about the individuals and projects that influenced Baeta's development.
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
Baeta is licensed under the [MIT License](./LICENSE).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baeta/plugin-pagination",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"baeta",
|
|
6
6
|
"graphql",
|
|
@@ -28,8 +28,7 @@
|
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
30
30
|
"types": "./dist/index.d.ts",
|
|
31
|
-
"
|
|
32
|
-
"require": "./dist/index.cjs"
|
|
31
|
+
"default": "./dist/index.js"
|
|
33
32
|
}
|
|
34
33
|
},
|
|
35
34
|
"types": "dist/index.d.ts",
|
|
@@ -44,29 +43,28 @@
|
|
|
44
43
|
"types": "tsc --noEmit"
|
|
45
44
|
},
|
|
46
45
|
"dependencies": {
|
|
47
|
-
"@baeta/generator-sdk": "^0.1.
|
|
48
|
-
"@baeta/util-path": "^0.1.
|
|
46
|
+
"@baeta/generator-sdk": "^0.1.4",
|
|
47
|
+
"@baeta/util-path": "^0.1.4"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
50
|
"@baeta/builder": "^0.0.0",
|
|
52
51
|
"@baeta/tsconfig": "^0.0.0",
|
|
53
|
-
"@types/node": "^22.
|
|
52
|
+
"@types/node": "^22.10.1",
|
|
54
53
|
"graphql": "^16.9.0",
|
|
55
|
-
"typescript": "^5.
|
|
54
|
+
"typescript": "^5.7.2"
|
|
56
55
|
},
|
|
57
56
|
"peerDependencies": {
|
|
58
57
|
"graphql": "^16.6.0"
|
|
59
58
|
},
|
|
60
59
|
"engines": {
|
|
61
|
-
"node": ">=22.
|
|
60
|
+
"node": ">=22.12.0"
|
|
62
61
|
},
|
|
63
62
|
"publishConfig": {
|
|
64
63
|
"access": "public",
|
|
65
64
|
"exports": {
|
|
66
65
|
".": {
|
|
67
66
|
"types": "./dist/index.d.ts",
|
|
68
|
-
"
|
|
69
|
-
"require": "./dist/index.cjs"
|
|
67
|
+
"default": "./dist/index.js"
|
|
70
68
|
}
|
|
71
69
|
}
|
|
72
70
|
},
|
|
@@ -78,5 +76,12 @@
|
|
|
78
76
|
"--no-warnings",
|
|
79
77
|
"--experimental-transform-types"
|
|
80
78
|
]
|
|
79
|
+
},
|
|
80
|
+
"typedocOptions": {
|
|
81
|
+
"entryPoints": [
|
|
82
|
+
"./index.ts"
|
|
83
|
+
],
|
|
84
|
+
"readme": "none",
|
|
85
|
+
"tsconfig": "./tsconfig.json"
|
|
81
86
|
}
|
|
82
87
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
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, importExt = "") {
|
|
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}${importExt}";
|
|
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(
|
|
96
|
-
ctx.generatorOptions.moduleDefinitionName,
|
|
97
|
-
moduleName,
|
|
98
|
-
ctx.generatorOptions.importExtension
|
|
99
|
-
),
|
|
100
|
-
"pagination"
|
|
101
|
-
);
|
|
102
|
-
return next();
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
exports.paginationPlugin = paginationPlugin;
|
|
109
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;AAAsB;AAEzB,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;AAC9B,QAAA;AACsB,UAAA;AACrB,UAAA;AACqB,UAAA;AACtB,QAAA;AACA,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, importExt = '') {\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}${importExt}\";\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(\n\t\t\t\t\tctx.generatorOptions.moduleDefinitionName,\n\t\t\t\t\tmoduleName,\n\t\t\t\t\tctx.generatorOptions.importExtension,\n\t\t\t\t),\n\t\t\t\t'pagination',\n\t\t\t);\n\n\t\t\treturn next();\n\t\t},\n\t});\n}\n"]}
|
package/dist/index.d.cts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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<unknown>;
|
|
17
|
-
|
|
18
|
-
export { paginationPlugin };
|