@baeta/plugin-pagination 0.1.5 → 1.0.8
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 +12 -0
- package/dist/index.d.ts +60 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +10 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @baeta/plugin-pagination
|
|
2
2
|
|
|
3
|
+
## 1.0.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#189](https://github.com/andreisergiu98/baeta/pull/189) [`d500378`](https://github.com/andreisergiu98/baeta/commit/d500378198e0a9c48298c4242913bca8ad348228) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add jsdocs
|
|
8
|
+
|
|
9
|
+
- [#165](https://github.com/andreisergiu98/baeta/pull/165) [`1334c2a`](https://github.com/andreisergiu98/baeta/commit/1334c2a866676c88f0f3d380b22133d81c4e98bc) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - mark as stable
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`d500378`](https://github.com/andreisergiu98/baeta/commit/d500378198e0a9c48298c4242913bca8ad348228), [`1334c2a`](https://github.com/andreisergiu98/baeta/commit/1334c2a866676c88f0f3d380b22133d81c4e98bc)]:
|
|
12
|
+
- @baeta/generator-sdk@1.0.0
|
|
13
|
+
- @baeta/util-path@1.0.0
|
|
14
|
+
|
|
3
15
|
## 0.1.5
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,74 @@
|
|
|
1
1
|
import * as _baeta_generator_sdk from '@baeta/generator-sdk';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for a specific pagination type
|
|
5
|
+
*/
|
|
6
|
+
interface PaginationTypeOptions {
|
|
7
|
+
/** The GraphQL type for nodes (e.g., "User!") */
|
|
4
8
|
nodeType?: string;
|
|
9
|
+
/** The GraphQL type for cursors
|
|
10
|
+
* @defaultValue "ID!"
|
|
11
|
+
*/
|
|
5
12
|
cursorType?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Additional fields to add to the edge type
|
|
15
|
+
* @example edgeFields: ["hasPhotos: Boolean!"]
|
|
16
|
+
*/
|
|
6
17
|
edgeFields?: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Additional fields to add to the connection type
|
|
20
|
+
* @example connectionFields: ["totalCount: Int!"]
|
|
21
|
+
*/
|
|
7
22
|
connectionFields?: string[];
|
|
8
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Configuration options for the pagination plugin
|
|
26
|
+
*/
|
|
9
27
|
interface PaginationOptions {
|
|
10
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Map of type names to their pagination configuration.
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* {
|
|
33
|
+
* // Simple configuration
|
|
34
|
+
* User: true,
|
|
35
|
+
*
|
|
36
|
+
* // Advanced configuration
|
|
37
|
+
* UserCustom: {
|
|
38
|
+
* nodeType: "User",
|
|
39
|
+
* cursorType: "UUID!",
|
|
40
|
+
* connectionFields: ["totalCount: Int!"],
|
|
41
|
+
* edgeFields: ["hasPhotos: Boolean!"]
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
types: Record<string, boolean | PaginationTypeOptions>;
|
|
47
|
+
/**
|
|
48
|
+
* Whether the node field should be nullable in all connections
|
|
49
|
+
* @defaultValue true
|
|
50
|
+
*/
|
|
11
51
|
nullableNode?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Additional fields to add to the PageInfo type
|
|
54
|
+
* @example ["hasMorePages: Boolean!"]
|
|
55
|
+
*/
|
|
12
56
|
pageInfoFields?: string[];
|
|
13
|
-
|
|
57
|
+
/** Whether to create an export file */
|
|
14
58
|
createExport?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Custom name for the pagination module
|
|
61
|
+
* @defaultValue 'baeta-pagination'
|
|
62
|
+
*/
|
|
63
|
+
moduleName?: string;
|
|
15
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* A plugin that generates Relay-style pagination types for GraphQL.
|
|
67
|
+
* See https://baeta.io/docs/plugins/pagination for more details
|
|
68
|
+
*
|
|
69
|
+
* @param options - Configuration options for the pagination plugin
|
|
70
|
+
* @returns A Baeta generator plugin
|
|
71
|
+
*/
|
|
16
72
|
declare function paginationPlugin(options: PaginationOptions): _baeta_generator_sdk.GeneratorPluginV1<unknown>;
|
|
17
73
|
|
|
18
|
-
export { paginationPlugin };
|
|
74
|
+
export { type PaginationOptions, type PaginationTypeOptions, paginationPlugin };
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts"],"sourcesContent":["import { createPluginV1, getModuleGetName, getModuleVariableName } from '@baeta/generator-sdk';\nimport { join, parse } from '@baeta/util-path';\n\
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["import { createPluginV1, getModuleGetName, getModuleVariableName } from '@baeta/generator-sdk';\nimport { join, parse } from '@baeta/util-path';\n\n/**\n * Configuration options for a specific pagination type\n */\nexport interface PaginationTypeOptions {\n\t/** The GraphQL type for nodes (e.g., \"User!\") */\n\tnodeType?: string;\n\t/** The GraphQL type for cursors\n\t * @defaultValue \"ID!\"\n\t */\n\tcursorType?: string;\n\t/**\n\t * Additional fields to add to the edge type\n\t * @example edgeFields: [\"hasPhotos: Boolean!\"]\n\t */\n\tedgeFields?: string[];\n\t/**\n\t * Additional fields to add to the connection type\n\t * @example connectionFields: [\"totalCount: Int!\"]\n\t */\n\tconnectionFields?: string[];\n}\n\n/**\n * Configuration options for the pagination plugin\n */\nexport interface PaginationOptions {\n\t/**\n\t * Map of type names to their pagination configuration.\n\t * @example\n\t * ```typescript\n\t * {\n\t * // Simple configuration\n\t * User: true,\n\t *\n\t * // Advanced configuration\n\t * UserCustom: {\n\t * nodeType: \"User\",\n\t * cursorType: \"UUID!\",\n\t * connectionFields: [\"totalCount: Int!\"],\n\t * edgeFields: [\"hasPhotos: Boolean!\"]\n\t * }\n\t * }\n\t * ```\n\t */\n\ttypes: Record<string, boolean | PaginationTypeOptions>;\n\t/**\n\t * Whether the node field should be nullable in all connections\n\t * @defaultValue true\n\t */\n\tnullableNode?: boolean;\n\t/**\n\t * Additional fields to add to the PageInfo type\n\t * @example [\"hasMorePages: Boolean!\"]\n\t */\n\tpageInfoFields?: string[];\n\t/** Whether to create an export file */\n\tcreateExport?: boolean;\n\t/**\n\t * Custom name for the pagination module\n\t * @defaultValue 'baeta-pagination'\n\t */\n\tmoduleName?: string;\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(\n\tname: string,\n\ttypeOptions: PaginationTypeOptions,\n\toptions: PaginationOptions,\n) {\n\tconst {\n\t\tcursorType = 'ID!',\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\n/**\n * A plugin that generates Relay-style pagination types for GraphQL.\n * See https://baeta.io/docs/plugins/pagination for more details\n *\n * @param options - Configuration options for the pagination plugin\n * @returns A Baeta generator plugin\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"],"mappings":";AAAA,SAAS,gBAAgB,kBAAkB,6BAA6B;AACxE,SAAS,MAAM,aAAa;AAkE5B,SAAS,YAAY,QAAkB;AACtC,SAAO,OAAO,IAAI,CAAC,UAAU,KAAK,KAAK,EAAE,EAAE,KAAK,IAAI;AACrD;AAEA,SAAS,UAAU,MAAc,QAAkB;AAClD,SAAO,QAAQ,IAAI;AAAA,EAClB,YAAY,MAAM,CAAC;AAAA;AAErB;AAEA,SAAS,WAAW,OAAiB;AACpC,SAAO,GAAG,MAAM,KAAK,MAAM,CAAC;AAAA;AAC7B;AAEA,SAAS,cAAc,YAAsB,CAAC,GAAG;AAChD,SAAO,UAAU,YAAY;AAAA,IAC5B,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACD,CAAC;AACF;AAEA,SAAS,YAAY,sBAA8B,YAAoB,YAAY,IAAI;AACtF,QAAM,SAAS,MAAM,oBAAoB;AACzC,QAAM,SAAS,iBAAiB,UAAU;AAC1C,QAAM,aAAa,OAAO,QAAQ,QAAQ,OAAO,OAAO;AAExD,SAAO,YAAY,MAAM,cAAc,UAAU,GAAG,SAAS;AAAA;AAAA,eAE/C,sBAAsB,UAAU,CAAC,MAAM,MAAM;AAAA;AAE5D;AAEA,SAAS,qBACR,MACA,aACA,SACC;AACD,QAAM;AAAA,IACL,aAAa;AAAA,IACb,WAAW;AAAA,IACX,mBAAmB,CAA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kB,SAAS;AAAA,QAC3B,WAAW,KAAK;AAAA,QAChB;AAAA,MACD;AACA,YAAM,eAAe,MAAM;AAE3B,UAAI,YAAY,IAAI,cAAc;AAElC,UAAI,QAAQ,iBAAiB,OAAO;AACnC,eAAO,KAAK;AAAA,MACb;AAEA,UAAI,YAAY;AAAA,QACf,qBAAqB,SAAS;AAAA,QAC9B;AAAA,UACC,IAAI,iBAAiB;AAAA,UACrB;AAAA,UACA,IAAI,iBAAiB;AAAA,QACtB;AAAA,QACA;AAAA,MACD;AAEA,aAAO,KAAK;AAAA,IACb;AAAA,EACD,CAAC;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baeta/plugin-pagination",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"baeta",
|
|
6
6
|
"graphql",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"types": "tsc --noEmit"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@baeta/generator-sdk": "^0.
|
|
47
|
-
"@baeta/util-path": "^0.
|
|
46
|
+
"@baeta/generator-sdk": "^1.0.0",
|
|
47
|
+
"@baeta/util-path": "^1.0.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@baeta/builder": "^0.0.0",
|
|
@@ -82,6 +82,12 @@
|
|
|
82
82
|
"./index.ts"
|
|
83
83
|
],
|
|
84
84
|
"readme": "none",
|
|
85
|
-
"tsconfig": "./tsconfig.json"
|
|
85
|
+
"tsconfig": "./tsconfig.json",
|
|
86
|
+
"sort": [
|
|
87
|
+
"kind",
|
|
88
|
+
"instance-first",
|
|
89
|
+
"required-first",
|
|
90
|
+
"alphabetical-ignoring-documents"
|
|
91
|
+
]
|
|
86
92
|
}
|
|
87
93
|
}
|