@nest-boot/graphql-connection 7.6.1 → 7.6.2

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.
Files changed (53) hide show
  1. package/dist/connection-query-builder.d.ts +21 -0
  2. package/dist/connection-query-builder.js +21 -0
  3. package/dist/connection-query-builder.js.map +1 -1
  4. package/dist/connection.builder.d.ts +83 -0
  5. package/dist/connection.builder.js +75 -0
  6. package/dist/connection.builder.js.map +1 -1
  7. package/dist/connection.manager.d.ts +56 -0
  8. package/dist/connection.manager.js +41 -0
  9. package/dist/connection.manager.js.map +1 -1
  10. package/dist/cursor.d.ts +35 -0
  11. package/dist/cursor.js +29 -0
  12. package/dist/cursor.js.map +1 -1
  13. package/dist/enums/order-direction.enum.d.ts +17 -0
  14. package/dist/enums/order-direction.enum.js +17 -0
  15. package/dist/enums/order-direction.enum.js.map +1 -1
  16. package/dist/enums/paging-type.enum.d.ts +13 -0
  17. package/dist/enums/paging-type.enum.js +13 -0
  18. package/dist/enums/paging-type.enum.js.map +1 -1
  19. package/dist/graphql-connection.constants.d.ts +9 -0
  20. package/dist/graphql-connection.constants.js +9 -0
  21. package/dist/graphql-connection.constants.js.map +1 -1
  22. package/dist/graphql-connection.module.d.ts +20 -0
  23. package/dist/graphql-connection.module.js +20 -0
  24. package/dist/graphql-connection.module.js.map +1 -1
  25. package/dist/interfaces/connection-args.interface.d.ts +47 -0
  26. package/dist/interfaces/connection-builder-options.interface.d.ts +19 -0
  27. package/dist/interfaces/connection-metadata.interface.d.ts +19 -0
  28. package/dist/interfaces/connection.interface.d.ts +19 -0
  29. package/dist/interfaces/edge.interface.d.ts +17 -0
  30. package/dist/interfaces/order-field.type.d.ts +25 -0
  31. package/dist/interfaces/order.interface.d.ts +19 -0
  32. package/dist/objects/page-info.object.d.ts +35 -0
  33. package/dist/objects/page-info.object.js +21 -0
  34. package/dist/objects/page-info.object.js.map +1 -1
  35. package/dist/tsconfig.build.tsbuildinfo +1 -1
  36. package/dist/types/connection-class.type.d.ts +18 -0
  37. package/dist/types/field-options.type.d.ts +70 -0
  38. package/dist/utils/create-connection-args.d.ts +19 -0
  39. package/dist/utils/create-connection-args.js +19 -0
  40. package/dist/utils/create-connection-args.js.map +1 -1
  41. package/dist/utils/create-connection.d.ts +18 -0
  42. package/dist/utils/create-connection.js +18 -0
  43. package/dist/utils/create-connection.js.map +1 -1
  44. package/dist/utils/create-edge.d.ts +14 -0
  45. package/dist/utils/create-edge.js +14 -0
  46. package/dist/utils/create-edge.js.map +1 -1
  47. package/dist/utils/create-filter.d.ts +30 -0
  48. package/dist/utils/create-filter.js +14 -0
  49. package/dist/utils/create-filter.js.map +1 -1
  50. package/dist/utils/create-order.d.ts +27 -0
  51. package/dist/utils/create-order.js +16 -0
  52. package/dist/utils/create-order.js.map +1 -1
  53. package/package.json +4 -4
@@ -1,5 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GRAPHQL_CONNECTION_METADATA = void 0;
4
+ /**
5
+ * Symbol used as a metadata key for storing connection metadata on connection classes.
6
+ *
7
+ * This symbol is used internally by the connection builder to attach metadata
8
+ * (entity class, field options, filter schema) to generated connection classes.
9
+ * The metadata is then used by the ConnectionQueryBuilder to construct queries.
10
+ *
11
+ * @internal
12
+ */
4
13
  exports.GRAPHQL_CONNECTION_METADATA = Symbol("GRAPHQL_CONNECTION_METADATA");
5
14
  //# sourceMappingURL=graphql-connection.constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"graphql-connection.constants.js","sourceRoot":"","sources":["../src/graphql-connection.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,2BAA2B,GAAG,MAAM,CAC/C,6BAA6B,CAC9B,CAAC"}
1
+ {"version":3,"file":"graphql-connection.constants.js","sourceRoot":"","sources":["../src/graphql-connection.constants.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACU,QAAA,2BAA2B,GAAG,MAAM,CAC/C,6BAA6B,CAC9B,CAAC"}
@@ -1,3 +1,23 @@
1
1
  import { ConfigurableModuleClass } from "./graphql-connection.module-definition";
2
+ /**
3
+ * NestJS module that provides GraphQL connection-based pagination functionality.
4
+ *
5
+ * This module is global and provides the {@link ConnectionManager} service for
6
+ * executing paginated queries following the Relay connection specification.
7
+ *
8
+ * @example Basic usage
9
+ * ```typescript
10
+ * import { Module } from "@nestjs/common";
11
+ * import { GraphQLConnectionModule } from "@nest-boot/graphql-connection";
12
+ *
13
+ * @Module({
14
+ * imports: [GraphQLConnectionModule.register()],
15
+ * })
16
+ * export class AppModule {}
17
+ * ```
18
+ *
19
+ * @see {@link ConnectionManager} for executing paginated queries
20
+ * @see {@link ConnectionBuilder} for building connection types
21
+ */
2
22
  export declare class GraphQLConnectionModule extends ConfigurableModuleClass {
3
23
  }
@@ -10,6 +10,26 @@ exports.GraphQLConnectionModule = void 0;
10
10
  const common_1 = require("@nestjs/common");
11
11
  const connection_manager_1 = require("./connection.manager");
12
12
  const graphql_connection_module_definition_1 = require("./graphql-connection.module-definition");
13
+ /**
14
+ * NestJS module that provides GraphQL connection-based pagination functionality.
15
+ *
16
+ * This module is global and provides the {@link ConnectionManager} service for
17
+ * executing paginated queries following the Relay connection specification.
18
+ *
19
+ * @example Basic usage
20
+ * ```typescript
21
+ * import { Module } from "@nestjs/common";
22
+ * import { GraphQLConnectionModule } from "@nest-boot/graphql-connection";
23
+ *
24
+ * @Module({
25
+ * imports: [GraphQLConnectionModule.register()],
26
+ * })
27
+ * export class AppModule {}
28
+ * ```
29
+ *
30
+ * @see {@link ConnectionManager} for executing paginated queries
31
+ * @see {@link ConnectionBuilder} for building connection types
32
+ */
13
33
  let GraphQLConnectionModule = class GraphQLConnectionModule extends graphql_connection_module_definition_1.ConfigurableModuleClass {
14
34
  };
15
35
  exports.GraphQLConnectionModule = GraphQLConnectionModule;
@@ -1 +1 @@
1
- {"version":3,"file":"graphql-connection.module.js","sourceRoot":"","sources":["../src/graphql-connection.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgD;AAEhD,6DAAyD;AACzD,iGAAiF;AAO1E,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ,8DAAuB;CAAG,CAAA;AAA1D,0DAAuB;kCAAvB,uBAAuB;IALnC,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,SAAS,EAAE,CAAC,sCAAiB,CAAC;QAC9B,OAAO,EAAE,CAAC,sCAAiB,CAAC;KAC7B,CAAC;GACW,uBAAuB,CAAmC"}
1
+ {"version":3,"file":"graphql-connection.module.js","sourceRoot":"","sources":["../src/graphql-connection.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgD;AAEhD,6DAAyD;AACzD,iGAAiF;AAEjF;;;;;;;;;;;;;;;;;;;GAmBG;AAMI,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ,8DAAuB;CAAG,CAAA;AAA1D,0DAAuB;kCAAvB,uBAAuB;IALnC,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,SAAS,EAAE,CAAC,sCAAiB,CAAC;QAC9B,OAAO,EAAE,CAAC,sCAAiB,CAAC;KAC7B,CAAC;GACW,uBAAuB,CAAmC"}
@@ -1,11 +1,58 @@
1
1
  import { FilterQuery } from "@mikro-orm/core";
2
2
  import { OrderInterface } from "./order.interface";
3
+ /**
4
+ * Arguments for querying a paginated connection.
5
+ *
6
+ * Supports both forward pagination (first/after) and backward pagination (last/before),
7
+ * as well as filtering, ordering, and search query functionality.
8
+ *
9
+ * @typeParam Entity - The entity type being queried
10
+ *
11
+ * @example Forward pagination
12
+ * ```typescript
13
+ * const args: ConnectionArgsInterface<User> = {
14
+ * first: 10,
15
+ * after: "cursor123",
16
+ * orderBy: { field: "CREATED_AT", direction: OrderDirection.DESC },
17
+ * };
18
+ * ```
19
+ *
20
+ * @example Backward pagination
21
+ * ```typescript
22
+ * const args: ConnectionArgsInterface<User> = {
23
+ * last: 10,
24
+ * before: "cursor456",
25
+ * };
26
+ * ```
27
+ */
3
28
  export interface ConnectionArgsInterface<Entity extends object> {
29
+ /**
30
+ * Returns elements after this cursor (for forward pagination).
31
+ */
4
32
  after?: string;
33
+ /**
34
+ * Returns elements before this cursor (for backward pagination).
35
+ */
5
36
  before?: string;
37
+ /**
38
+ * Returns up to the first n elements (for forward pagination).
39
+ */
6
40
  first?: number;
41
+ /**
42
+ * Returns up to the last n elements (for backward pagination).
43
+ */
7
44
  last?: number;
45
+ /**
46
+ * A search query string to filter results.
47
+ * Parsed using search-syntax and applied to searchable fields.
48
+ */
8
49
  query?: string;
50
+ /**
51
+ * A MongoDB-style filter query to apply to the results.
52
+ */
9
53
  filter?: FilterQuery<Entity>;
54
+ /**
55
+ * Ordering options for the returned results.
56
+ */
10
57
  orderBy?: OrderInterface<Entity>;
11
58
  }
@@ -1,4 +1,23 @@
1
1
  import type { FilterOptions } from "mikro-orm-filter-query-schema";
2
+ /**
3
+ * Configuration options for the ConnectionBuilder.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * const options: ConnectionBuilderOptions = {
8
+ * filter: {
9
+ * maxDepth: 3,
10
+ * maxConditions: 10,
11
+ * maxOrBranches: 3,
12
+ * maxArrayLength: 50,
13
+ * },
14
+ * };
15
+ * ```
16
+ */
2
17
  export interface ConnectionBuilderOptions {
18
+ /**
19
+ * Options for the filter query schema builder.
20
+ * Controls limits on filter complexity to prevent abuse.
21
+ */
3
22
  filter?: FilterOptions;
4
23
  }
@@ -2,8 +2,27 @@ import { EntityClass, FilterQuery } from "@mikro-orm/core";
2
2
  import type { FieldType } from "mikro-orm-filter-query-schema";
3
3
  import type { ZodType } from "zod";
4
4
  import { FieldOptions } from "../types/field-options.type";
5
+ /**
6
+ * Metadata stored on connection classes for query building.
7
+ *
8
+ * This metadata is attached to connection classes using the
9
+ * GRAPHQL_CONNECTION_METADATA symbol and is used by the
10
+ * ConnectionQueryBuilder to construct queries.
11
+ *
12
+ * @typeParam Entity - The entity type for the connection
13
+ * @internal
14
+ */
5
15
  export interface ConnectionMetadata<Entity extends object> {
16
+ /**
17
+ * The MikroORM entity class.
18
+ */
6
19
  entityClass: EntityClass<Entity>;
20
+ /**
21
+ * Map of field names to their configuration options.
22
+ */
7
23
  fieldOptionsMap: Map<string, FieldOptions<Entity, FieldType, string>>;
24
+ /**
25
+ * Zod schema for validating and parsing filter queries.
26
+ */
8
27
  filterQuerySchema: ZodType<FilterQuery<Entity>>;
9
28
  }
@@ -1,7 +1,26 @@
1
1
  import { type PageInfo } from "../objects";
2
2
  import { type EdgeInterface } from "./edge.interface";
3
+ /**
4
+ * Represents a paginated connection following the Relay specification.
5
+ *
6
+ * A connection contains a list of edges (items with cursors), pagination info,
7
+ * and the total count of items matching the query.
8
+ *
9
+ * @typeParam T - The type of entities in the connection
10
+ *
11
+ * @see {@link https://relay.dev/graphql/connections.htm Relay Connection Specification}
12
+ */
3
13
  export interface ConnectionInterface<T> {
14
+ /**
15
+ * A list of edges, each containing a node and its cursor.
16
+ */
4
17
  edges: EdgeInterface<T>[];
18
+ /**
19
+ * Information about the current page for pagination.
20
+ */
5
21
  pageInfo: PageInfo;
22
+ /**
23
+ * The total number of items matching the query (before pagination).
24
+ */
6
25
  totalCount: number;
7
26
  }
@@ -1,4 +1,21 @@
1
+ /**
2
+ * Represents an edge in a GraphQL connection.
3
+ *
4
+ * An edge contains a single item (node) and a cursor that can be used
5
+ * for pagination to fetch items before or after this position.
6
+ *
7
+ * @typeParam T - The type of the node (entity) in the edge
8
+ *
9
+ * @see {@link https://relay.dev/graphql/connections.htm#sec-Edge-Types Relay Edge Type Specification}
10
+ */
1
11
  export interface EdgeInterface<T> {
12
+ /**
13
+ * The item at the end of this edge.
14
+ */
2
15
  node: T;
16
+ /**
17
+ * A cursor for use in pagination.
18
+ * Can be passed to `after` or `before` arguments.
19
+ */
3
20
  cursor: string;
4
21
  }
@@ -1,6 +1,31 @@
1
1
  import { AutoPath } from "@mikro-orm/core/typings";
2
+ /**
3
+ * Utility type that converts dot notation to underscore notation.
4
+ * For example: "user.profile.name" becomes "user_profile_name"
5
+ * @internal
6
+ */
2
7
  type DotToUnderscore<S extends string> = S extends `${infer Prefix}.${infer Rest}` ? `${Prefix}_${DotToUnderscore<Rest>}` : S;
8
+ /**
9
+ * The key type for order fields.
10
+ *
11
+ * Converts entity field paths to uppercase with underscores.
12
+ * For example, "createdAt" becomes "CREATED_AT", and "user.name" becomes "USER_NAME".
13
+ *
14
+ * @typeParam T - The entity type
15
+ */
3
16
  export type OrderFieldKey<T> = Uppercase<DotToUnderscore<AutoPath<T, string>>>;
17
+ /**
18
+ * The value type for order fields (the actual field path in the entity).
19
+ *
20
+ * @typeParam T - The entity type
21
+ */
4
22
  export type OrderFieldValue<T> = AutoPath<T, string>;
23
+ /**
24
+ * A record mapping order field keys to their actual field paths.
25
+ *
26
+ * Used to create the GraphQL enum for sortable fields.
27
+ *
28
+ * @typeParam T - The entity type
29
+ */
5
30
  export type OrderFieldType<T> = Record<OrderFieldKey<T>, OrderFieldValue<T>>;
6
31
  export {};
@@ -1,6 +1,25 @@
1
1
  import { type OrderDirection } from "../enums";
2
2
  import { OrderFieldKey } from "./order-field.type";
3
+ /**
4
+ * Specifies the ordering for a connection query.
5
+ *
6
+ * @typeParam T - The entity type being ordered
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const order: OrderInterface<User> = {
11
+ * field: "CREATED_AT",
12
+ * direction: OrderDirection.DESC,
13
+ * };
14
+ * ```
15
+ */
3
16
  export interface OrderInterface<T> {
17
+ /**
18
+ * The field to order by (uppercase with underscores, e.g., "CREATED_AT").
19
+ */
4
20
  field: OrderFieldKey<T>;
21
+ /**
22
+ * The direction to order (ASC or DESC).
23
+ */
5
24
  direction: OrderDirection;
6
25
  }
@@ -1,6 +1,41 @@
1
+ /**
2
+ * Provides information about pagination in a connection.
3
+ *
4
+ * PageInfo is used to determine whether more pages exist and to fetch
5
+ * additional pages using cursor-based pagination.
6
+ *
7
+ * @see {@link https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo Relay PageInfo Specification}
8
+ *
9
+ * @example Using pageInfo for pagination
10
+ * ```typescript
11
+ * const result = await connectionManager.find(UserConnection, { first: 10 });
12
+ *
13
+ * if (result.pageInfo.hasNextPage) {
14
+ * // Fetch next page using endCursor
15
+ * const nextPage = await connectionManager.find(UserConnection, {
16
+ * first: 10,
17
+ * after: result.pageInfo.endCursor,
18
+ * });
19
+ * }
20
+ * ```
21
+ */
1
22
  export declare class PageInfo {
23
+ /**
24
+ * Whether there are more pages to fetch following the current page.
25
+ */
2
26
  hasNextPage: boolean;
27
+ /**
28
+ * Whether there are any pages prior to the current page.
29
+ */
3
30
  hasPreviousPage: boolean;
31
+ /**
32
+ * The cursor of the first edge in the current page.
33
+ * Can be used with `before` for backward pagination.
34
+ */
4
35
  startCursor: string | null;
36
+ /**
37
+ * The cursor of the last edge in the current page.
38
+ * Can be used with `after` for forward pagination.
39
+ */
5
40
  endCursor: string | null;
6
41
  }
@@ -11,6 +11,27 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.PageInfo = void 0;
13
13
  const graphql_1 = require("@nest-boot/graphql");
14
+ /**
15
+ * Provides information about pagination in a connection.
16
+ *
17
+ * PageInfo is used to determine whether more pages exist and to fetch
18
+ * additional pages using cursor-based pagination.
19
+ *
20
+ * @see {@link https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo Relay PageInfo Specification}
21
+ *
22
+ * @example Using pageInfo for pagination
23
+ * ```typescript
24
+ * const result = await connectionManager.find(UserConnection, { first: 10 });
25
+ *
26
+ * if (result.pageInfo.hasNextPage) {
27
+ * // Fetch next page using endCursor
28
+ * const nextPage = await connectionManager.find(UserConnection, {
29
+ * first: 10,
30
+ * after: result.pageInfo.endCursor,
31
+ * });
32
+ * }
33
+ * ```
34
+ */
14
35
  let PageInfo = class PageInfo {
15
36
  };
16
37
  exports.PageInfo = PageInfo;
@@ -1 +1 @@
1
- {"version":3,"file":"page-info.object.js","sourceRoot":"","sources":["../../src/objects/page-info.object.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAAuD;AAKhD,IAAM,QAAQ,GAAd,MAAM,QAAQ;CAkBpB,CAAA;AAlBY,4BAAQ;AAKnB;IAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,OAAO,EAAE;QACpB,UAAU,EAAE,CAAC;QACb,WAAW,EAAE,mEAAmE;KACjF,CAAC;;6CACoB;AAMtB;IAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,OAAO,EAAE;QACpB,UAAU,EAAE,CAAC;QACb,WAAW,EAAE,wDAAwD;KACtE,CAAC;;iDACwB;AAG1B;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;6CACZ;AAG5B;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;2CACd;mBAjBf,QAAQ;IAHpB,IAAA,oBAAU,EAAC;QACV,WAAW,EAAE,uKAAuK;KACrL,CAAC;GACW,QAAQ,CAkBpB"}
1
+ {"version":3,"file":"page-info.object.js","sourceRoot":"","sources":["../../src/objects/page-info.object.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAAuD;AAEvD;;;;;;;;;;;;;;;;;;;;GAoBG;AAII,IAAM,QAAQ,GAAd,MAAM,QAAQ;CAgCpB,CAAA;AAhCY,4BAAQ;AAQnB;IAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,OAAO,EAAE;QACpB,UAAU,EAAE,CAAC;QACb,WAAW,EAAE,mEAAmE;KACjF,CAAC;;6CACoB;AAStB;IAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,OAAO,EAAE;QACpB,UAAU,EAAE,CAAC;QACb,WAAW,EAAE,wDAAwD;KACtE,CAAC;;iDACwB;AAO1B;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;6CACZ;AAO5B;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;2CACd;mBA/Bf,QAAQ;IAHpB,IAAA,oBAAU,EAAC;QACV,WAAW,EAAE,uKAAuK;KACrL,CAAC;GACW,QAAQ,CAgCpB"}