@baeta/plugin-pagination 0.0.7 → 0.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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @baeta/plugin-pagination
2
2
 
3
+ ## 0.0.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#102](https://github.com/andreisergiu98/baeta/pull/102) [`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
8
+
9
+ - [#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
10
+
11
+ - [#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
12
+
13
+ - 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)]:
14
+ - @baeta/generator-sdk@0.0.10
15
+ - @baeta/util-path@0.0.2
16
+
3
17
  ## 0.0.7
4
18
 
5
19
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
2
2
  var _generatorsdk = require('@baeta/generator-sdk');
3
- var _path = require('path');
3
+ var _utilpath = require('@baeta/util-path');
4
4
  function printFields(fields) {
5
5
  return fields.map((field) => ` ${field}`).join("\n");
6
6
  }
@@ -21,7 +21,7 @@ function printPageInfo(addFields = []) {
21
21
  ]);
22
22
  }
23
23
  function printExport(moduleDefinitionName, moduleName) {
24
- const parsed = _path.parse.call(void 0, moduleDefinitionName);
24
+ const parsed = _utilpath.parse.call(void 0, moduleDefinitionName);
25
25
  const method = _generatorsdk.getModuleGetName.call(void 0, moduleName);
26
26
  const importName = parsed.ext === ".ts" ? parsed.name : moduleDefinitionName;
27
27
  return `import { ${method} } from "./${importName}";
@@ -49,7 +49,7 @@ function printConnectionTypes(name, typeOptions, options) {
49
49
  return [connection, edge];
50
50
  }
51
51
  function createConnectionModuleDir(modulesDir, moduleName) {
52
- return _path.join.call(void 0, modulesDir, moduleName);
52
+ return _utilpath.join.call(void 0, modulesDir, moduleName);
53
53
  }
54
54
  function createGqlFilename(moduleDir) {
55
55
  return `${moduleDir}/connections.gql`;
@@ -1 +1 @@
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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;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","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}\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{ createPluginV1, getModuleGetName, getModuleVariableName } from '@baeta/generator-sdk';\nimport { join, parse } from '@baeta/util-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"]}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // index.ts
2
2
  import { createPluginV1, getModuleGetName, getModuleVariableName } from "@baeta/generator-sdk";
3
- import { join, parse } from "path";
3
+ import { join, parse } from "@baeta/util-path";
4
4
  function printFields(fields) {
5
5
  return fields.map((field) => ` ${field}`).join("\n");
6
6
  }
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 '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,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;AA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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":[]}
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 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,IAAI,CAAC,UAAU,KAAK,K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O,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,6 @@
1
1
  {
2
2
  "name": "@baeta/plugin-pagination",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "keywords": [
5
5
  "baeta",
6
6
  "graphql",
@@ -45,14 +45,15 @@
45
45
  "types": "tsc --noEmit"
46
46
  },
47
47
  "dependencies": {
48
- "@baeta/generator-sdk": "^0.0.9"
48
+ "@baeta/generator-sdk": "^0.0.10",
49
+ "@baeta/util-path": "^0.0.2"
49
50
  },
50
51
  "devDependencies": {
51
52
  "@baeta/builder": "^0.0.0",
52
53
  "@baeta/tsconfig": "^0.0.0",
53
- "@types/node": "^18.19.0",
54
+ "@types/node": "^18.19.9",
54
55
  "graphql": "^16.8.1",
55
- "typescript": "^5.3.2"
56
+ "typescript": "^5.3.3"
56
57
  },
57
58
  "peerDependencies": {
58
59
  "graphql": "^16.6.0"