@nest-boot/graphql-connection 7.6.0 → 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.
- package/dist/connection-query-builder.d.ts +21 -0
- package/dist/connection-query-builder.js +21 -0
- package/dist/connection-query-builder.js.map +1 -1
- package/dist/connection.builder.d.ts +83 -0
- package/dist/connection.builder.js +75 -0
- package/dist/connection.builder.js.map +1 -1
- package/dist/connection.manager.d.ts +56 -0
- package/dist/connection.manager.js +41 -0
- package/dist/connection.manager.js.map +1 -1
- package/dist/cursor.d.ts +35 -0
- package/dist/cursor.js +29 -0
- package/dist/cursor.js.map +1 -1
- package/dist/enums/order-direction.enum.d.ts +17 -0
- package/dist/enums/order-direction.enum.js +17 -0
- package/dist/enums/order-direction.enum.js.map +1 -1
- package/dist/enums/paging-type.enum.d.ts +13 -0
- package/dist/enums/paging-type.enum.js +13 -0
- package/dist/enums/paging-type.enum.js.map +1 -1
- package/dist/graphql-connection.constants.d.ts +9 -0
- package/dist/graphql-connection.constants.js +9 -0
- package/dist/graphql-connection.constants.js.map +1 -1
- package/dist/graphql-connection.module.d.ts +20 -0
- package/dist/graphql-connection.module.js +20 -0
- package/dist/graphql-connection.module.js.map +1 -1
- package/dist/interfaces/connection-args.interface.d.ts +47 -0
- package/dist/interfaces/connection-builder-options.interface.d.ts +19 -0
- package/dist/interfaces/connection-metadata.interface.d.ts +19 -0
- package/dist/interfaces/connection.interface.d.ts +19 -0
- package/dist/interfaces/edge.interface.d.ts +17 -0
- package/dist/interfaces/order-field.type.d.ts +25 -0
- package/dist/interfaces/order.interface.d.ts +19 -0
- package/dist/objects/page-info.object.d.ts +35 -0
- package/dist/objects/page-info.object.js +21 -0
- package/dist/objects/page-info.object.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/connection-class.type.d.ts +18 -0
- package/dist/types/field-options.type.d.ts +70 -0
- package/dist/utils/create-connection-args.d.ts +19 -0
- package/dist/utils/create-connection-args.js +19 -0
- package/dist/utils/create-connection-args.js.map +1 -1
- package/dist/utils/create-connection.d.ts +18 -0
- package/dist/utils/create-connection.js +18 -0
- package/dist/utils/create-connection.js.map +1 -1
- package/dist/utils/create-edge.d.ts +14 -0
- package/dist/utils/create-edge.js +14 -0
- package/dist/utils/create-edge.js.map +1 -1
- package/dist/utils/create-filter.d.ts +30 -0
- package/dist/utils/create-filter.js +14 -0
- package/dist/utils/create-filter.js.map +1 -1
- package/dist/utils/create-order.d.ts +27 -0
- package/dist/utils/create-order.js +16 -0
- package/dist/utils/create-order.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,3 +1,21 @@
|
|
|
1
1
|
import { Type } from "@nestjs/common";
|
|
2
2
|
import { ConnectionInterface } from "../interfaces";
|
|
3
|
+
/**
|
|
4
|
+
* Type alias for a Connection class type.
|
|
5
|
+
*
|
|
6
|
+
* This is used to reference Connection classes generated by ConnectionBuilder.build()
|
|
7
|
+
* in type annotations for ConnectionManager.find() and similar methods.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam T - The entity type for the connection
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const UserConnection: ConnectionClass<User> = new ConnectionBuilder(User)
|
|
14
|
+
* .addField({ field: "name", type: "string" })
|
|
15
|
+
* .build().Connection;
|
|
16
|
+
*
|
|
17
|
+
* // Use in ConnectionManager
|
|
18
|
+
* const result = await connectionManager.find(UserConnection, args);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
3
21
|
export type ConnectionClass<T> = Type<ConnectionInterface<T>>;
|
|
@@ -1,12 +1,82 @@
|
|
|
1
1
|
import type { FieldType, ReplacementCallbackFieldOptions as FilterReplacementCallbackFieldOptions, ReplacementFieldOptions as FilterReplacementFieldOptions, SimpleFieldOptions as FilterSimpleFieldOptions } from "mikro-orm-filter-query-schema";
|
|
2
|
+
/**
|
|
3
|
+
* Base options shared by all field types.
|
|
4
|
+
*/
|
|
2
5
|
export interface BaseFieldOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Whether this field can be used in filter queries.
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
3
10
|
filterable?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether this field is included in text search queries.
|
|
13
|
+
* Only applicable to string fields.
|
|
14
|
+
*/
|
|
4
15
|
searchable?: boolean;
|
|
5
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Options for fields that can be sorted.
|
|
19
|
+
*/
|
|
6
20
|
export interface SortableFieldOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Whether this field can be used for ordering results.
|
|
23
|
+
* When true, the field will be included in the OrderField enum.
|
|
24
|
+
*/
|
|
7
25
|
sortable?: boolean;
|
|
8
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Options for a simple field with direct entity property mapping.
|
|
29
|
+
*
|
|
30
|
+
* @typeParam Entity - The entity type
|
|
31
|
+
* @typeParam Type - The field type ("string", "number", "boolean", or "date")
|
|
32
|
+
*/
|
|
9
33
|
export type SimpleFieldOptions<Entity extends object, Type extends FieldType = never> = FilterSimpleFieldOptions<Entity, Type> & BaseFieldOptions & SortableFieldOptions;
|
|
34
|
+
/**
|
|
35
|
+
* Options for a field with a replacement property path.
|
|
36
|
+
*
|
|
37
|
+
* Use this when the GraphQL field name differs from the entity property path.
|
|
38
|
+
*
|
|
39
|
+
* @typeParam Entity - The entity type
|
|
40
|
+
* @typeParam Type - The field type
|
|
41
|
+
* @typeParam Field - The GraphQL field name
|
|
42
|
+
*/
|
|
10
43
|
export type ReplacementFieldOptions<Entity extends object, Type extends FieldType = never, Field extends string = never> = FilterReplacementFieldOptions<Entity, Type, Field> & BaseFieldOptions & SortableFieldOptions;
|
|
44
|
+
/**
|
|
45
|
+
* Options for a field with a replacement callback function.
|
|
46
|
+
*
|
|
47
|
+
* Use this for complex field mappings that require runtime logic.
|
|
48
|
+
*
|
|
49
|
+
* @typeParam Entity - The entity type
|
|
50
|
+
* @typeParam Type - The field type
|
|
51
|
+
*/
|
|
11
52
|
export type ReplacementFunctionFieldOptions<Entity extends object, Type extends FieldType = never> = FilterReplacementCallbackFieldOptions<Entity, Type> & BaseFieldOptions & SortableFieldOptions;
|
|
53
|
+
/**
|
|
54
|
+
* Union type of all field option types.
|
|
55
|
+
*
|
|
56
|
+
* This is the type used when adding fields to a ConnectionBuilder.
|
|
57
|
+
*
|
|
58
|
+
* @typeParam Entity - The entity type
|
|
59
|
+
* @typeParam Type - The field type
|
|
60
|
+
* @typeParam Field - The GraphQL field name (for replacement options)
|
|
61
|
+
*
|
|
62
|
+
* @example Simple field
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const options: FieldOptions<User, "string"> = {
|
|
65
|
+
* field: "name",
|
|
66
|
+
* type: "string",
|
|
67
|
+
* filterable: true,
|
|
68
|
+
* sortable: true,
|
|
69
|
+
* };
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example Replacement field
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const options: FieldOptions<User, "string", "authorName"> = {
|
|
75
|
+
* field: "authorName",
|
|
76
|
+
* type: "string",
|
|
77
|
+
* replacement: "author.name",
|
|
78
|
+
* filterable: true,
|
|
79
|
+
* };
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
12
82
|
export type FieldOptions<Entity extends object, Type extends FieldType = never, Field extends string = never> = SimpleFieldOptions<Entity, Type> | ReplacementFieldOptions<Entity, Type, Field> | ReplacementFunctionFieldOptions<Entity, Type>;
|
|
@@ -3,4 +3,23 @@ import { type Type } from "@nestjs/common";
|
|
|
3
3
|
import { GraphQLScalarType } from "graphql";
|
|
4
4
|
import type { FieldType } from "mikro-orm-filter-query-schema";
|
|
5
5
|
import { ConnectionArgsInterface, FieldOptions, OrderInterface } from "../interfaces";
|
|
6
|
+
/**
|
|
7
|
+
* Creates a GraphQL Args type for connection queries.
|
|
8
|
+
*
|
|
9
|
+
* The generated Args type includes:
|
|
10
|
+
* - `first`/`last`: Number of items to return (for forward/backward pagination)
|
|
11
|
+
* - `after`/`before`: Cursor for pagination position
|
|
12
|
+
* - `query`: Search query string
|
|
13
|
+
* - `filter`: MongoDB-style filter query
|
|
14
|
+
* - `orderBy`: Sorting options
|
|
15
|
+
*
|
|
16
|
+
* @typeParam Entity - The entity type being queried
|
|
17
|
+
* @param entityName - The name to use for the GraphQL type
|
|
18
|
+
* @param fieldOptionsMap - Map of field configurations
|
|
19
|
+
* @param OrderClass - The Order input type class
|
|
20
|
+
* @param FilterScalar - The Filter scalar type
|
|
21
|
+
* @returns A class implementing ConnectionArgsInterface
|
|
22
|
+
*
|
|
23
|
+
* @internal Used by ConnectionBuilder.build()
|
|
24
|
+
*/
|
|
6
25
|
export declare function createConnectionArgs<Entity extends object>(entityName: string, fieldOptionsMap: Map<string, FieldOptions<Entity, FieldType, string>>, OrderClass: Type<OrderInterface<Entity>>, FilterScalar: GraphQLScalarType<FilterQuery<Entity>>): Type<ConnectionArgsInterface<Entity>>;
|
|
@@ -12,6 +12,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.createConnectionArgs = createConnectionArgs;
|
|
13
13
|
const graphql_1 = require("@nest-boot/graphql");
|
|
14
14
|
const inflection_1 = require("inflection");
|
|
15
|
+
/**
|
|
16
|
+
* Creates a GraphQL Args type for connection queries.
|
|
17
|
+
*
|
|
18
|
+
* The generated Args type includes:
|
|
19
|
+
* - `first`/`last`: Number of items to return (for forward/backward pagination)
|
|
20
|
+
* - `after`/`before`: Cursor for pagination position
|
|
21
|
+
* - `query`: Search query string
|
|
22
|
+
* - `filter`: MongoDB-style filter query
|
|
23
|
+
* - `orderBy`: Sorting options
|
|
24
|
+
*
|
|
25
|
+
* @typeParam Entity - The entity type being queried
|
|
26
|
+
* @param entityName - The name to use for the GraphQL type
|
|
27
|
+
* @param fieldOptionsMap - Map of field configurations
|
|
28
|
+
* @param OrderClass - The Order input type class
|
|
29
|
+
* @param FilterScalar - The Filter scalar type
|
|
30
|
+
* @returns A class implementing ConnectionArgsInterface
|
|
31
|
+
*
|
|
32
|
+
* @internal Used by ConnectionBuilder.build()
|
|
33
|
+
*/
|
|
15
34
|
function createConnectionArgs(entityName, fieldOptionsMap, OrderClass, FilterScalar) {
|
|
16
35
|
const humanizeAndPluralizeEntityName = (0, inflection_1.pluralize)((0, inflection_1.humanize)(entityName, true));
|
|
17
36
|
const filterableFields = [...fieldOptionsMap.values()].filter((field) => field.filterable);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-connection-args.js","sourceRoot":"","sources":["../../src/utils/create-connection-args.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"create-connection-args.js","sourceRoot":"","sources":["../../src/utils/create-connection-args.ts"],"names":[],"mappings":";;;;;;;;;;;AAgCA,oDAkEC;AAjGD,gDAA0D;AAG1D,2CAAiD;AASjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,oBAAoB,CAClC,UAAkB,EAClB,eAAqE,EACrE,UAAwC,EACxC,YAAoD;IAEpD,MAAM,8BAA8B,GAAG,IAAA,sBAAS,EAAC,IAAA,qBAAQ,EAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;IAE7E,MAAM,gBAAgB,GAAG,CAAC,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAC3D,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAC5B,CAAC;IAGF,IAAM,cAAc,GAApB,MAAM,cAAc;KAkDnB,CAAA;IAvCC;QAVC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE;YACnB,QAAQ,EAAE,IAAI;YACd,GAAG,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC;gBAC7B,CAAC,CAAC;oBACE,WAAW,EAAE,8EAA8E,gBAAgB;yBACxG,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC;yBAClC,IAAI,CAAC,IAAI,CAAC,EAAE;iBAChB;gBACH,CAAC,CAAC,EAAE,CAAC;SACR,CAAC;;iDACa;IAOf;QAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,YAAY,EAAE;YACzB,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,UAAU,8BAA8B,8BAA8B;SACpF,CAAC;;kDAC2B;IAM7B;QAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,aAAG,EAAE;YAChB,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,qDAAqD;SACnE,CAAC;;iDACa;IAMf;QAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,aAAG,EAAE;YAChB,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,oDAAoD;SAClE,CAAC;;gDACY;IAMd;QAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE;YACnB,WAAW,EAAE,4DAA4D;YACzE,QAAQ,EAAE,IAAI;SACf,CAAC;;iDACa;IAMf;QAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE;YACnB,WAAW,EAAE,6DAA6D;YAC1E,QAAQ,EAAE,IAAI;SACf,CAAC;;kDACc;IAOhB;QAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,UAAU,EAAE;YACvB,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,qCAAqC,8BAA8B,GAAG;SACpF,CAAC;;mDAC+B;IAjD7B,cAAc;QADnB,IAAA,kBAAQ,EAAC,GAAG,UAAU,gBAAgB,CAAC;OAClC,cAAc,CAkDnB;IAED,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
|
@@ -3,4 +3,22 @@ import { type Type } from "@nestjs/common";
|
|
|
3
3
|
import type { FieldType } from "mikro-orm-filter-query-schema";
|
|
4
4
|
import type { ZodType } from "zod";
|
|
5
5
|
import { ConnectionInterface, EdgeInterface, FieldOptions } from "../interfaces";
|
|
6
|
+
/**
|
|
7
|
+
* Creates a GraphQL Connection type for cursor-based pagination.
|
|
8
|
+
*
|
|
9
|
+
* The generated Connection type includes:
|
|
10
|
+
* - `edges`: List of edges containing nodes and cursors
|
|
11
|
+
* - `pageInfo`: Pagination information (hasNextPage, hasPreviousPage, cursors)
|
|
12
|
+
* - `totalCount`: Total number of items matching the query
|
|
13
|
+
*
|
|
14
|
+
* @typeParam Entity - The entity type for the connection
|
|
15
|
+
* @param entityClass - The MikroORM entity class
|
|
16
|
+
* @param entityName - The name to use for the GraphQL type
|
|
17
|
+
* @param EdgeClass - The Edge type class to use for edges
|
|
18
|
+
* @param fieldOptionsMap - Map of field configurations
|
|
19
|
+
* @param filterQuerySchema - Zod schema for validating filter queries
|
|
20
|
+
* @returns A class implementing ConnectionInterface
|
|
21
|
+
*
|
|
22
|
+
* @internal Used by ConnectionBuilder.build()
|
|
23
|
+
*/
|
|
6
24
|
export declare function createConnection<Entity extends object>(entityClass: EntityClass<Entity>, entityName: string, EdgeClass: Type<EdgeInterface<Entity>>, fieldOptionsMap: Map<string, FieldOptions<Entity, FieldType, string>>, filterQuerySchema: ZodType<FilterQuery<Entity>>): Type<ConnectionInterface<Entity>>;
|
|
@@ -14,6 +14,24 @@ const graphql_1 = require("@nest-boot/graphql");
|
|
|
14
14
|
const inflection_1 = require("inflection");
|
|
15
15
|
const graphql_connection_constants_1 = require("../graphql-connection.constants");
|
|
16
16
|
const objects_1 = require("../objects");
|
|
17
|
+
/**
|
|
18
|
+
* Creates a GraphQL Connection type for cursor-based pagination.
|
|
19
|
+
*
|
|
20
|
+
* The generated Connection type includes:
|
|
21
|
+
* - `edges`: List of edges containing nodes and cursors
|
|
22
|
+
* - `pageInfo`: Pagination information (hasNextPage, hasPreviousPage, cursors)
|
|
23
|
+
* - `totalCount`: Total number of items matching the query
|
|
24
|
+
*
|
|
25
|
+
* @typeParam Entity - The entity type for the connection
|
|
26
|
+
* @param entityClass - The MikroORM entity class
|
|
27
|
+
* @param entityName - The name to use for the GraphQL type
|
|
28
|
+
* @param EdgeClass - The Edge type class to use for edges
|
|
29
|
+
* @param fieldOptionsMap - Map of field configurations
|
|
30
|
+
* @param filterQuerySchema - Zod schema for validating filter queries
|
|
31
|
+
* @returns A class implementing ConnectionInterface
|
|
32
|
+
*
|
|
33
|
+
* @internal Used by ConnectionBuilder.build()
|
|
34
|
+
*/
|
|
17
35
|
function createConnection(entityClass, entityName, EdgeClass, fieldOptionsMap, filterQuerySchema) {
|
|
18
36
|
const pluralizeEntityName = (0, inflection_1.pluralize)(entityName);
|
|
19
37
|
let Connection = class Connection {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-connection.js","sourceRoot":"","sources":["../../src/utils/create-connection.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"create-connection.js","sourceRoot":"","sources":["../../src/utils/create-connection.ts"],"names":[],"mappings":";;;;;;;;;;;AAkCA,4CAwCC;AAzED,gDAA4D;AAE5D,2CAAuC;AAIvC,kFAA8E;AAO9E,wCAAsC;AAEtC;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,gBAAgB,CAC9B,WAAgC,EAChC,UAAkB,EAClB,SAAsC,EACtC,eAAqE,EACrE,iBAA+C;IAE/C,MAAM,mBAAmB,GAAG,IAAA,sBAAS,EAAC,UAAU,CAAC,CAAC;IAWlD,IAAM,UAAU,GAAhB,MAAM,UAAU;KAmBf,CAAA;IAbC;QAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE;YACxB,UAAU,EAAE,CAAC;YACb,WAAW,EAAE,kBAAkB;SAChC,CAAC;;6CAC8B;IAMhC;QAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,kBAAQ,EAAE;YACrB,UAAU,EAAE,CAAC;YACb,WAAW,EAAE,mCAAmC;SACjD,CAAC;kCACS,kBAAQ;gDAAC;IAMpB;QAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,aAAG,EAAE;YAChB,UAAU,EAAE,CAAC;YACb,WAAW,EAAE,wDAAwD;SACtE,CAAC;;kDACkB;IAlBhB,UAAU;QATf,OAAO,CAAC,QAAQ,CAAC,0DAA2B,EAAE;YAC7C,WAAW;YACX,eAAe;YACf,iBAAiB;SACmB,CAAC;QACtC,IAAA,oBAAU,EAAC,GAAG,UAAU,YAAY,EAAE;YACrC,UAAU,EAAE,IAAI;YAChB,WAAW,EAAE,0DAA0D,mBAAmB,GAAG;SAC9F,CAAC;OACI,UAAU,CAmBf;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import type { EntityClass } from "@mikro-orm/core";
|
|
2
2
|
import { type Type } from "@nestjs/common";
|
|
3
3
|
import { EdgeInterface } from "../interfaces";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a GraphQL Edge type for a connection.
|
|
6
|
+
*
|
|
7
|
+
* An Edge type contains:
|
|
8
|
+
* - `node`: The actual entity item
|
|
9
|
+
* - `cursor`: A string cursor for pagination
|
|
10
|
+
*
|
|
11
|
+
* @typeParam Entity - The entity type for the edge
|
|
12
|
+
* @param entityClass - The MikroORM entity class (used as the node type)
|
|
13
|
+
* @param entityName - The name to use for the GraphQL type
|
|
14
|
+
* @returns A class implementing EdgeInterface
|
|
15
|
+
*
|
|
16
|
+
* @internal Used by ConnectionBuilder.build()
|
|
17
|
+
*/
|
|
4
18
|
export declare function createEdge<Entity extends object>(entityClass: EntityClass<Entity>, entityName: string): Type<EdgeInterface<Entity>>;
|
|
@@ -11,6 +11,20 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createEdge = createEdge;
|
|
13
13
|
const graphql_1 = require("@nest-boot/graphql");
|
|
14
|
+
/**
|
|
15
|
+
* Creates a GraphQL Edge type for a connection.
|
|
16
|
+
*
|
|
17
|
+
* An Edge type contains:
|
|
18
|
+
* - `node`: The actual entity item
|
|
19
|
+
* - `cursor`: A string cursor for pagination
|
|
20
|
+
*
|
|
21
|
+
* @typeParam Entity - The entity type for the edge
|
|
22
|
+
* @param entityClass - The MikroORM entity class (used as the node type)
|
|
23
|
+
* @param entityName - The name to use for the GraphQL type
|
|
24
|
+
* @returns A class implementing EdgeInterface
|
|
25
|
+
*
|
|
26
|
+
* @internal Used by ConnectionBuilder.build()
|
|
27
|
+
*/
|
|
14
28
|
function createEdge(entityClass, entityName) {
|
|
15
29
|
let Edge = class Edge {
|
|
16
30
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-edge.js","sourceRoot":"","sources":["../../src/utils/create-edge.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"create-edge.js","sourceRoot":"","sources":["../../src/utils/create-edge.ts"],"names":[],"mappings":";;;;;;;;;;;AAoBA,gCAsBC;AAzCD,gDAAuD;AAKvD;;;;;;;;;;;;;GAaG;AACH,SAAgB,UAAU,CACxB,WAAgC,EAChC,UAAkB;IAKlB,IAAM,IAAI,GAAV,MAAM,IAAI;KAYT,CAAA;IAPC;QAHC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,WAAW,EAAE;YACxB,WAAW,EAAE,0BAA0B,UAAU,OAAO;SACzD,CAAC;;sCACY;IAMd;QAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE;YACnB,UAAU,EAAE,CAAC;YACb,WAAW,EAAE,iCAAiC;SAC/C,CAAC;;wCACc;IAXZ,IAAI;QAHT,IAAA,oBAAU,EAAC,GAAG,UAAU,MAAM,EAAE;YAC/B,WAAW,EAAE,0CAA0C,UAAU,kCAAkC;SACpG,CAAC;OACI,IAAI,CAYT;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -2,9 +2,39 @@ import { FilterQuery } from "@mikro-orm/core";
|
|
|
2
2
|
import { GraphQLScalarType } from "graphql";
|
|
3
3
|
import { FieldType, FilterOptions, FilterQuerySchemaBuilder } from "mikro-orm-filter-query-schema";
|
|
4
4
|
import { FieldOptions } from "../interfaces";
|
|
5
|
+
/**
|
|
6
|
+
* The Zod schema type returned by FilterQuerySchemaBuilder.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam Entity - The entity type for the filter
|
|
9
|
+
*/
|
|
5
10
|
export type FilterQuerySchema<Entity extends object> = ReturnType<FilterQuerySchemaBuilder<Entity>["build"]>;
|
|
11
|
+
/**
|
|
12
|
+
* The result of creating a filter scalar and schema.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam Entity - The entity type for the filter
|
|
15
|
+
*/
|
|
6
16
|
export interface CreateFilterResult<Entity extends object> {
|
|
17
|
+
/**
|
|
18
|
+
* The GraphQL scalar type for the filter.
|
|
19
|
+
*/
|
|
7
20
|
Filter: GraphQLScalarType<FilterQuery<Entity>>;
|
|
21
|
+
/**
|
|
22
|
+
* The Zod schema for validating filter queries.
|
|
23
|
+
*/
|
|
8
24
|
filterQuerySchema: FilterQuerySchema<Entity>;
|
|
9
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a GraphQL Filter scalar type and validation schema.
|
|
28
|
+
*
|
|
29
|
+
* The Filter scalar accepts MongoDB-style query syntax and validates
|
|
30
|
+
* it against the configured field options.
|
|
31
|
+
*
|
|
32
|
+
* @typeParam Entity - The entity type being filtered
|
|
33
|
+
* @param entityName - The name to use for the GraphQL scalar
|
|
34
|
+
* @param fieldOptionsMap - Map of field configurations
|
|
35
|
+
* @param filterOptions - Options for filter complexity limits
|
|
36
|
+
* @returns An object containing the Filter scalar and filterQuerySchema
|
|
37
|
+
*
|
|
38
|
+
* @internal Used by ConnectionBuilder.build()
|
|
39
|
+
*/
|
|
10
40
|
export declare function createFilter<Entity extends object>(entityName: string, fieldOptionsMap: Map<string, FieldOptions<Entity, FieldType, string>>, filterOptions?: FilterOptions): CreateFilterResult<Entity>;
|
|
@@ -40,6 +40,20 @@ function parseLiteralValue(ast) {
|
|
|
40
40
|
throw new Error(`Unexpected AST kind: ${ast.kind}`);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a GraphQL Filter scalar type and validation schema.
|
|
45
|
+
*
|
|
46
|
+
* The Filter scalar accepts MongoDB-style query syntax and validates
|
|
47
|
+
* it against the configured field options.
|
|
48
|
+
*
|
|
49
|
+
* @typeParam Entity - The entity type being filtered
|
|
50
|
+
* @param entityName - The name to use for the GraphQL scalar
|
|
51
|
+
* @param fieldOptionsMap - Map of field configurations
|
|
52
|
+
* @param filterOptions - Options for filter complexity limits
|
|
53
|
+
* @returns An object containing the Filter scalar and filterQuerySchema
|
|
54
|
+
*
|
|
55
|
+
* @internal Used by ConnectionBuilder.build()
|
|
56
|
+
*/
|
|
43
57
|
function createFilter(entityName, fieldOptionsMap, filterOptions) {
|
|
44
58
|
const filterableFields = [...fieldOptionsMap.values()]
|
|
45
59
|
.filter((field) => field.filterable !== false)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-filter.js","sourceRoot":"","sources":["../../src/utils/create-filter.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"create-filter.js","sourceRoot":"","sources":["../../src/utils/create-filter.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
import { type Type } from "@nestjs/common";
|
|
2
2
|
import type { FieldType } from "mikro-orm-filter-query-schema";
|
|
3
3
|
import { FieldOptions, OrderFieldType, OrderInterface } from "../interfaces";
|
|
4
|
+
/**
|
|
5
|
+
* The result of creating order types.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam Entity - The entity type for ordering
|
|
8
|
+
*/
|
|
4
9
|
export interface CreateOrderResult<Entity extends object> {
|
|
10
|
+
/**
|
|
11
|
+
* The Order input type class.
|
|
12
|
+
*/
|
|
5
13
|
Order: Type<OrderInterface<Entity>>;
|
|
14
|
+
/**
|
|
15
|
+
* The OrderField enum object mapping field keys to paths.
|
|
16
|
+
*/
|
|
6
17
|
OrderField: OrderFieldType<Entity>;
|
|
7
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates GraphQL Order input type and OrderField enum.
|
|
21
|
+
*
|
|
22
|
+
* The Order type allows specifying:
|
|
23
|
+
* - `field`: Which field to order by (from the OrderField enum)
|
|
24
|
+
* - `direction`: ASC or DESC
|
|
25
|
+
*
|
|
26
|
+
* Only fields marked as `sortable: true` in field options are included.
|
|
27
|
+
*
|
|
28
|
+
* @typeParam Entity - The entity type being ordered
|
|
29
|
+
* @param entityName - The name to use for the GraphQL types
|
|
30
|
+
* @param fieldOptionsMap - Map of field configurations
|
|
31
|
+
* @returns An object containing the Order class and OrderField enum
|
|
32
|
+
*
|
|
33
|
+
* @internal Used by ConnectionBuilder.build()
|
|
34
|
+
*/
|
|
8
35
|
export declare function createOrder<Entity extends object>(entityName: string, fieldOptionsMap: Map<string, FieldOptions<Entity, FieldType, string>>): CreateOrderResult<Entity>;
|
|
@@ -13,6 +13,22 @@ exports.createOrder = createOrder;
|
|
|
13
13
|
const graphql_1 = require("@nest-boot/graphql");
|
|
14
14
|
const inflection_1 = require("inflection");
|
|
15
15
|
const enums_1 = require("../enums");
|
|
16
|
+
/**
|
|
17
|
+
* Creates GraphQL Order input type and OrderField enum.
|
|
18
|
+
*
|
|
19
|
+
* The Order type allows specifying:
|
|
20
|
+
* - `field`: Which field to order by (from the OrderField enum)
|
|
21
|
+
* - `direction`: ASC or DESC
|
|
22
|
+
*
|
|
23
|
+
* Only fields marked as `sortable: true` in field options are included.
|
|
24
|
+
*
|
|
25
|
+
* @typeParam Entity - The entity type being ordered
|
|
26
|
+
* @param entityName - The name to use for the GraphQL types
|
|
27
|
+
* @param fieldOptionsMap - Map of field configurations
|
|
28
|
+
* @returns An object containing the Order class and OrderField enum
|
|
29
|
+
*
|
|
30
|
+
* @internal Used by ConnectionBuilder.build()
|
|
31
|
+
*/
|
|
16
32
|
function createOrder(entityName, fieldOptionsMap) {
|
|
17
33
|
const humanizeEntityName = (0, inflection_1.humanize)(entityName, true);
|
|
18
34
|
const humanizeAndPluralizeEntityName = (0, inflection_1.pluralize)((0, inflection_1.humanize)(entityName, true));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-order.js","sourceRoot":"","sources":["../../src/utils/create-order.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"create-order.js","sourceRoot":"","sources":["../../src/utils/create-order.ts"],"names":[],"mappings":";;;;;;;;;;;AA+CA,kCA2CC;AA1FD,gDAAwE;AAExE,2CAA6D;AAG7D,oCAA0C;AA0B1C;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,WAAW,CACzB,UAAkB,EAClB,eAAqE;IAErE,MAAM,kBAAkB,GAAG,IAAA,qBAAQ,EAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACtD,MAAM,8BAA8B,GAAG,IAAA,sBAAS,EAAC,IAAA,qBAAQ,EAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;IAE7E,MAAM,cAAc,GAAG,CAAC,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CACzD,CAAC,KAAK,EAAE,EAAE,CAAE,KAA8B,EAAE,QAAQ,CACrD,CAAC;IAEF,MAAM,UAAU,GAAG,cAAc,CAAC,MAAM,CACtC,CAAC,MAAM,EAAE,YAAY,EAAE,EAAE;QACvB,OAAO;YACL,GAAG,MAAM;YACT,CAAC,IAAA,uBAAU,EAAC,YAAY,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,EAC3C,YAAyC,CAAC,WAAW;gBACtD,YAAY,CAAC,KAAK;SACrB,CAAC;IACJ,CAAC,EACD,EAAE,EAAE,EAAE,IAAI,EAAuC,CAClD,CAAC;IAEF,IAAA,0BAAgB,EAAC,UAAU,EAAE;QAC3B,IAAI,EAAE,GAAG,UAAU,YAAY;QAC/B,WAAW,EAAE,uBAAuB,kBAAkB,8BAA8B;KACrF,CAAC,CAAC;IAKH,IAAM,KAAK,GAAX,MAAM,KAAK;KASV,CAAA;IAJC;QAHC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,UAAoB,EAAE;YACjC,WAAW,EAAE,sBAAsB,8BAA8B,MAAM;SACxE,CAAC;;wCAC4B;IAG9B;QADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,sBAAc,EAAE,EAAE,WAAW,EAAE,yBAAyB,EAAE,CAAC;;4CAC7C;IARvB,KAAK;QAHV,IAAA,mBAAS,EAAC,GAAG,UAAU,OAAO,EAAE;YAC/B,WAAW,EAAE,wBAAwB,kBAAkB,cAAc;SACtE,CAAC;OACI,KAAK,CASV;IAED,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;AAC/B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-boot/graphql-connection",
|
|
3
|
-
"version": "7.6.
|
|
3
|
+
"version": "7.6.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "d4rkcr0w <me@d4rkcr0w.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"inflection": "^3.0.2",
|
|
18
18
|
"lodash": "^4.17.21",
|
|
19
19
|
"mikro-orm-filter-query-schema": "^1.1.0",
|
|
20
|
-
"search-syntax": "^3.
|
|
20
|
+
"search-syntax": "^3.6.0",
|
|
21
21
|
"zod": "^4.1.13"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"ts-jest": "^29.4.4",
|
|
42
42
|
"typescript": "^5.9.3",
|
|
43
43
|
"@nest-boot/eslint-config": "^7.0.2",
|
|
44
|
-
"@nest-boot/eslint-plugin": "^7.0.
|
|
45
|
-
"@nest-boot/graphql": "^7.1.
|
|
46
|
-
"@nest-boot/tsconfig": "^7.0.
|
|
44
|
+
"@nest-boot/eslint-plugin": "^7.0.3",
|
|
45
|
+
"@nest-boot/graphql": "^7.1.2",
|
|
46
|
+
"@nest-boot/tsconfig": "^7.0.1"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@mikro-orm/core": "^6.0.0",
|