@nest-boot/graphql-connection 7.2.1 → 7.3.0
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 +1 -0
- package/dist/connection-query-builder.js +8 -1
- package/dist/connection-query-builder.js.map +1 -1
- package/dist/connection.builder.d.ts +5 -5
- package/dist/connection.builder.js +8 -156
- package/dist/connection.builder.js.map +1 -1
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +18 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/unknown-field.error.d.ts +4 -0
- package/dist/errors/unknown-field.error.js +12 -0
- package/dist/errors/unknown-field.error.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/connection-args.interface.d.ts +2 -0
- package/dist/interfaces/field-options.interface.d.ts +10 -13
- package/dist/search-syntax.visitor.js +13 -19
- package/dist/search-syntax.visitor.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils/create-connection-args.d.ts +6 -0
- package/dist/utils/create-connection-args.js +80 -0
- package/dist/utils/create-connection-args.js.map +1 -0
- package/dist/utils/create-connection.d.ts +4 -0
- package/dist/utils/create-connection.js +54 -0
- package/dist/utils/create-connection.js.map +1 -0
- package/dist/utils/create-edge.d.ts +4 -0
- package/dist/utils/create-edge.js +37 -0
- package/dist/utils/create-edge.js.map +1 -0
- package/dist/utils/create-filter.d.ts +5 -0
- package/dist/utils/create-filter.js +209 -0
- package/dist/utils/create-filter.js.map +1 -0
- package/dist/utils/create-order.d.ts +7 -0
- package/dist/utils/create-order.js +50 -0
- package/dist/utils/create-order.js.map +1 -0
- package/dist/utils/index.d.ts +5 -1
- package/dist/utils/index.js +5 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +8 -7
- package/dist/utils/infer-type.d.ts +0 -1
- package/dist/utils/infer-type.js +0 -14
- package/dist/utils/infer-type.js.map +0 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FilterQuery } from "@mikro-orm/core";
|
|
2
|
+
import { type Type } from "@nestjs/common";
|
|
3
|
+
import { GraphQLScalarType } from "graphql";
|
|
4
|
+
import { ConnectionArgsInterface, FieldOptions, OrderInterface } from "../interfaces";
|
|
5
|
+
import { FilterValue } from "./create-filter";
|
|
6
|
+
export declare function createConnectionArgs<Entity extends object>(entityName: string, fieldOptionsMap: Map<string, FieldOptions<Entity, any, any>>, OrderClass: Type<OrderInterface<Entity>>, FilterScalar: GraphQLScalarType<FilterQuery<Entity>, FilterValue>): Type<ConnectionArgsInterface<Entity>>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createConnectionArgs = createConnectionArgs;
|
|
13
|
+
const graphql_1 = require("@nest-boot/graphql");
|
|
14
|
+
const inflection_1 = require("inflection");
|
|
15
|
+
function createConnectionArgs(entityName, fieldOptionsMap, OrderClass, FilterScalar) {
|
|
16
|
+
const humanizeAndPluralizeEntityName = (0, inflection_1.pluralize)((0, inflection_1.humanize)(entityName, true));
|
|
17
|
+
const filterableFields = [...fieldOptionsMap.values()].filter((field) => field.filterable);
|
|
18
|
+
let ConnectionArgs = class ConnectionArgs {
|
|
19
|
+
};
|
|
20
|
+
__decorate([
|
|
21
|
+
(0, graphql_1.Field)(() => String, {
|
|
22
|
+
nullable: true,
|
|
23
|
+
...(filterableFields.length > 0
|
|
24
|
+
? {
|
|
25
|
+
description: `Apply one or multiple filters to the query.\nSupported filter parameters:\n${filterableFields
|
|
26
|
+
.map(({ field }) => `\`${field}\``)
|
|
27
|
+
.join(", ")}`,
|
|
28
|
+
}
|
|
29
|
+
: {}),
|
|
30
|
+
}),
|
|
31
|
+
__metadata("design:type", String)
|
|
32
|
+
], ConnectionArgs.prototype, "query", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, graphql_1.Field)(() => graphql_1.Int, {
|
|
35
|
+
nullable: true,
|
|
36
|
+
description: "Returns up to the first `n` elements from the list.",
|
|
37
|
+
}),
|
|
38
|
+
__metadata("design:type", Number)
|
|
39
|
+
], ConnectionArgs.prototype, "first", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
(0, graphql_1.Field)(() => graphql_1.Int, {
|
|
42
|
+
nullable: true,
|
|
43
|
+
description: "Returns up to the last `n` elements from the list.",
|
|
44
|
+
}),
|
|
45
|
+
__metadata("design:type", Number)
|
|
46
|
+
], ConnectionArgs.prototype, "last", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, graphql_1.Field)(() => String, {
|
|
49
|
+
description: `Returns the elements that come after the specified cursor.`,
|
|
50
|
+
nullable: true,
|
|
51
|
+
}),
|
|
52
|
+
__metadata("design:type", String)
|
|
53
|
+
], ConnectionArgs.prototype, "after", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
(0, graphql_1.Field)(() => String, {
|
|
56
|
+
description: `Returns the elements that come before the specified cursor.`,
|
|
57
|
+
nullable: true,
|
|
58
|
+
}),
|
|
59
|
+
__metadata("design:type", String)
|
|
60
|
+
], ConnectionArgs.prototype, "before", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, graphql_1.Field)(() => OrderClass, {
|
|
63
|
+
nullable: true,
|
|
64
|
+
description: `Ordering options for the returned ${humanizeAndPluralizeEntityName}.`,
|
|
65
|
+
}),
|
|
66
|
+
__metadata("design:type", Object)
|
|
67
|
+
], ConnectionArgs.prototype, "orderBy", void 0);
|
|
68
|
+
__decorate([
|
|
69
|
+
(0, graphql_1.Field)(() => FilterScalar, {
|
|
70
|
+
nullable: true,
|
|
71
|
+
description: `Filter ${humanizeAndPluralizeEntityName} using MongoDB query syntax.`,
|
|
72
|
+
}),
|
|
73
|
+
__metadata("design:type", Object)
|
|
74
|
+
], ConnectionArgs.prototype, "filter", void 0);
|
|
75
|
+
ConnectionArgs = __decorate([
|
|
76
|
+
(0, graphql_1.ArgsType)(`${entityName}ConnectionArgs`)
|
|
77
|
+
], ConnectionArgs);
|
|
78
|
+
return ConnectionArgs;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=create-connection-args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-connection-args.js","sourceRoot":"","sources":["../../src/utils/create-connection-args.ts"],"names":[],"mappings":";;;;;;;;;;;AAaA,oDAkEC;AA9ED,gDAA0D;AAG1D,2CAAiD;AASjD,SAAgB,oBAAoB,CAClC,UAAkB,EAClB,eAA4D,EAC5D,UAAwC,EACxC,YAAiE;IAEjE,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,EA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,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { EntityClass } from "@mikro-orm/core";
|
|
2
|
+
import { type Type } from "@nestjs/common";
|
|
3
|
+
import { ConnectionInterface, EdgeInterface, FieldOptions } from "../interfaces";
|
|
4
|
+
export declare function createConnection<Entity extends object>(entityClass: EntityClass<Entity>, entityName: string, EdgeClass: Type<EdgeInterface<Entity>>, fieldOptionsMap: Map<string, FieldOptions<Entity, any, any>>): Type<ConnectionInterface<Entity>>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createConnection = createConnection;
|
|
13
|
+
const graphql_1 = require("@nest-boot/graphql");
|
|
14
|
+
const inflection_1 = require("inflection");
|
|
15
|
+
const graphql_connection_constants_1 = require("../graphql-connection.constants");
|
|
16
|
+
const objects_1 = require("../objects");
|
|
17
|
+
function createConnection(entityClass, entityName, EdgeClass, fieldOptionsMap) {
|
|
18
|
+
const pluralizeEntityName = (0, inflection_1.pluralize)(entityName);
|
|
19
|
+
let Connection = class Connection {
|
|
20
|
+
};
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, graphql_1.Field)(() => [EdgeClass], {
|
|
23
|
+
complexity: 0,
|
|
24
|
+
description: `A list of edges.`,
|
|
25
|
+
}),
|
|
26
|
+
__metadata("design:type", Array)
|
|
27
|
+
], Connection.prototype, "edges", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, graphql_1.Field)(() => objects_1.PageInfo, {
|
|
30
|
+
complexity: 0,
|
|
31
|
+
description: `Information to aid in pagination.`,
|
|
32
|
+
}),
|
|
33
|
+
__metadata("design:type", objects_1.PageInfo)
|
|
34
|
+
], Connection.prototype, "pageInfo", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, graphql_1.Field)(() => graphql_1.Int, {
|
|
37
|
+
complexity: 0,
|
|
38
|
+
description: `Identifies the total count of items in the connection.`,
|
|
39
|
+
}),
|
|
40
|
+
__metadata("design:type", Number)
|
|
41
|
+
], Connection.prototype, "totalCount", void 0);
|
|
42
|
+
Connection = __decorate([
|
|
43
|
+
Reflect.metadata(graphql_connection_constants_1.GRAPHQL_CONNECTION_METADATA, {
|
|
44
|
+
entityClass,
|
|
45
|
+
fieldOptionsMap,
|
|
46
|
+
}),
|
|
47
|
+
(0, graphql_1.ObjectType)(`${entityName}Connection`, {
|
|
48
|
+
isAbstract: true,
|
|
49
|
+
description: `An auto-generated type for paginating through multiple ${pluralizeEntityName}.`,
|
|
50
|
+
})
|
|
51
|
+
], Connection);
|
|
52
|
+
return Connection;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=create-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-connection.js","sourceRoot":"","sources":["../../src/utils/create-connection.ts"],"names":[],"mappings":";;;;;;;;;;;AAcA,4CAsCC;AAnDD,gDAA4D;AAE5D,2CAAuC;AAEvC,kFAA8E;AAO9E,wCAAsC;AAEtC,SAAgB,gBAAgB,CAC9B,WAAgC,EAChC,UAAkB,EAClB,SAAsC,EACtC,eAA4D;IAE5D,MAAM,mBAAmB,GAAG,IAAA,sBAAS,EAAC,UAAU,CAAC,CAAC;IAUlD,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;QARf,OAAO,CAAC,QAAQ,CAAC,0DAA2B,EAAE;YAC7C,WAAW;YACX,eAAe;SACqB,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"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { EntityClass } from "@mikro-orm/core";
|
|
2
|
+
import { type Type } from "@nestjs/common";
|
|
3
|
+
import { EdgeInterface } from "../interfaces";
|
|
4
|
+
export declare function createEdge<Entity extends object>(entityClass: EntityClass<Entity>, entityName: string): Type<EdgeInterface<Entity>>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createEdge = createEdge;
|
|
13
|
+
const graphql_1 = require("@nest-boot/graphql");
|
|
14
|
+
function createEdge(entityClass, entityName) {
|
|
15
|
+
let Edge = class Edge {
|
|
16
|
+
};
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, graphql_1.Field)(() => entityClass, {
|
|
19
|
+
description: `The item at the end of ${entityName}Edge.`,
|
|
20
|
+
}),
|
|
21
|
+
__metadata("design:type", Object)
|
|
22
|
+
], Edge.prototype, "node", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, graphql_1.Field)(() => String, {
|
|
25
|
+
complexity: 0,
|
|
26
|
+
description: `A cursor for use in pagination.`,
|
|
27
|
+
}),
|
|
28
|
+
__metadata("design:type", String)
|
|
29
|
+
], Edge.prototype, "cursor", void 0);
|
|
30
|
+
Edge = __decorate([
|
|
31
|
+
(0, graphql_1.ObjectType)(`${entityName}Edge`, {
|
|
32
|
+
description: `An auto-generated type which holds one ${entityName} and a cursor during pagination.`,
|
|
33
|
+
})
|
|
34
|
+
], Edge);
|
|
35
|
+
return Edge;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=create-edge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-edge.js","sourceRoot":"","sources":["../../src/utils/create-edge.ts"],"names":[],"mappings":";;;;;;;;;;;AAMA,gCAsBC;AA3BD,gDAAuD;AAKvD,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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { FilterQuery } from "@mikro-orm/core";
|
|
2
|
+
import { GraphQLScalarType } from "graphql";
|
|
3
|
+
import { FieldOptions } from "../interfaces";
|
|
4
|
+
export type FilterValue = Record<string, unknown>;
|
|
5
|
+
export declare function createFilter<Entity extends object>(entityName: string, fieldOptionsMap: Map<string, FieldOptions<Entity, any, any>>): GraphQLScalarType<FilterQuery<Entity>, FilterValue>;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFilter = createFilter;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const errors_1 = require("../errors");
|
|
7
|
+
const comparisonOperators = [
|
|
8
|
+
"$eq",
|
|
9
|
+
"$ne",
|
|
10
|
+
"$gt",
|
|
11
|
+
"$gte",
|
|
12
|
+
"$lt",
|
|
13
|
+
"$lte",
|
|
14
|
+
"$in",
|
|
15
|
+
"$nin",
|
|
16
|
+
"$like",
|
|
17
|
+
"$ilike",
|
|
18
|
+
"$re",
|
|
19
|
+
"$fulltext",
|
|
20
|
+
"$contains",
|
|
21
|
+
"$overlap",
|
|
22
|
+
];
|
|
23
|
+
const logicalOperators = ["$and", "$or", "$not"];
|
|
24
|
+
function createComparisonSchema() {
|
|
25
|
+
const primitiveSchema = zod_1.z.union([
|
|
26
|
+
zod_1.z.string(),
|
|
27
|
+
zod_1.z.number(),
|
|
28
|
+
zod_1.z.boolean(),
|
|
29
|
+
zod_1.z.null(),
|
|
30
|
+
]);
|
|
31
|
+
const comparisonObjectSchema = zod_1.z
|
|
32
|
+
.object({
|
|
33
|
+
$eq: primitiveSchema.optional(),
|
|
34
|
+
$ne: primitiveSchema.optional(),
|
|
35
|
+
$gt: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional(),
|
|
36
|
+
$gte: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional(),
|
|
37
|
+
$lt: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional(),
|
|
38
|
+
$lte: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional(),
|
|
39
|
+
$in: zod_1.z.array(primitiveSchema).optional(),
|
|
40
|
+
$nin: zod_1.z.array(primitiveSchema).optional(),
|
|
41
|
+
$like: zod_1.z.string().optional(),
|
|
42
|
+
$ilike: zod_1.z.string().optional(),
|
|
43
|
+
$re: zod_1.z.string().optional(),
|
|
44
|
+
$fulltext: zod_1.z.string().optional(),
|
|
45
|
+
$contains: zod_1.z.array(primitiveSchema).optional(),
|
|
46
|
+
$overlap: zod_1.z.array(primitiveSchema).optional(),
|
|
47
|
+
})
|
|
48
|
+
.strict();
|
|
49
|
+
return zod_1.z.union([primitiveSchema, comparisonObjectSchema]);
|
|
50
|
+
}
|
|
51
|
+
function createFilterSchema() {
|
|
52
|
+
const comparisonSchema = createComparisonSchema();
|
|
53
|
+
const baseFilterSchema = zod_1.z.lazy(() => zod_1.z.union([
|
|
54
|
+
zod_1.z
|
|
55
|
+
.object({
|
|
56
|
+
$and: zod_1.z.array(baseFilterSchema).optional(),
|
|
57
|
+
$or: zod_1.z.array(baseFilterSchema).optional(),
|
|
58
|
+
$not: baseFilterSchema.optional(),
|
|
59
|
+
})
|
|
60
|
+
.catchall(comparisonSchema),
|
|
61
|
+
zod_1.z.record(zod_1.z.string(), comparisonSchema),
|
|
62
|
+
]));
|
|
63
|
+
return baseFilterSchema;
|
|
64
|
+
}
|
|
65
|
+
const filterSchema = createFilterSchema();
|
|
66
|
+
function parseJson(value) {
|
|
67
|
+
if (typeof value === "string") {
|
|
68
|
+
try {
|
|
69
|
+
return JSON.parse(value);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
throw new Error("Filter must be a valid JSON string");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
function validateSchema(value) {
|
|
78
|
+
const result = filterSchema.safeParse(value);
|
|
79
|
+
if (!result.success) {
|
|
80
|
+
throw new Error(`Invalid filter: ${result.error.message}`);
|
|
81
|
+
}
|
|
82
|
+
return result.data;
|
|
83
|
+
}
|
|
84
|
+
function parseLiteralValue(ast) {
|
|
85
|
+
switch (ast.kind) {
|
|
86
|
+
case graphql_1.Kind.STRING:
|
|
87
|
+
case graphql_1.Kind.ENUM:
|
|
88
|
+
return ast.value;
|
|
89
|
+
case graphql_1.Kind.OBJECT: {
|
|
90
|
+
const obj = {};
|
|
91
|
+
for (const field of ast.fields) {
|
|
92
|
+
obj[field.name.value] = parseLiteralValue(field.value);
|
|
93
|
+
}
|
|
94
|
+
return obj;
|
|
95
|
+
}
|
|
96
|
+
case graphql_1.Kind.LIST:
|
|
97
|
+
return ast.values.map(parseLiteralValue);
|
|
98
|
+
case graphql_1.Kind.INT:
|
|
99
|
+
return parseInt(ast.value, 10);
|
|
100
|
+
case graphql_1.Kind.FLOAT:
|
|
101
|
+
return parseFloat(ast.value);
|
|
102
|
+
case graphql_1.Kind.BOOLEAN:
|
|
103
|
+
return ast.value;
|
|
104
|
+
case graphql_1.Kind.NULL:
|
|
105
|
+
return null;
|
|
106
|
+
default:
|
|
107
|
+
throw new Error(`Unexpected AST kind: ${ast.kind}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function validateFilterFields(filter, fieldOptionsMap, inFieldComparison = false) {
|
|
111
|
+
if (filter === null || typeof filter !== "object") {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
for (const key of Object.keys(filter)) {
|
|
115
|
+
if (logicalOperators.includes(key)) {
|
|
116
|
+
const value = filter[key];
|
|
117
|
+
if (key === "$not" && value !== null && typeof value === "object") {
|
|
118
|
+
validateFilterFields(value, fieldOptionsMap, false);
|
|
119
|
+
}
|
|
120
|
+
else if (Array.isArray(value)) {
|
|
121
|
+
for (const item of value) {
|
|
122
|
+
validateFilterFields(item, fieldOptionsMap, false);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (comparisonOperators.includes(key)) {
|
|
128
|
+
if (!inFieldComparison) {
|
|
129
|
+
throw new Error(`Comparison operator '${key}' is not allowed at root level. Use it inside a field object, e.g., { "fieldName": { "${key}": value } }`);
|
|
130
|
+
}
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const fieldOptions = fieldOptionsMap.get(key);
|
|
134
|
+
if (typeof fieldOptions === "undefined") {
|
|
135
|
+
throw new errors_1.UnknownFieldError(key);
|
|
136
|
+
}
|
|
137
|
+
if (fieldOptions.filterable === false) {
|
|
138
|
+
throw new Error(`Field '${key}' is not filterable`);
|
|
139
|
+
}
|
|
140
|
+
const fieldValue = filter[key];
|
|
141
|
+
if (fieldValue !== null &&
|
|
142
|
+
typeof fieldValue === "object" &&
|
|
143
|
+
!Array.isArray(fieldValue)) {
|
|
144
|
+
validateFilterFields(fieldValue, fieldOptionsMap, true);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function applyReplacement(filter, fieldOptionsMap) {
|
|
149
|
+
if (filter === null || typeof filter !== "object") {
|
|
150
|
+
return filter;
|
|
151
|
+
}
|
|
152
|
+
const result = {};
|
|
153
|
+
for (const key of Object.keys(filter)) {
|
|
154
|
+
const value = filter[key];
|
|
155
|
+
if (logicalOperators.includes(key)) {
|
|
156
|
+
if (key === "$not" && value !== null && typeof value === "object") {
|
|
157
|
+
result[key] = applyReplacement(value, fieldOptionsMap);
|
|
158
|
+
}
|
|
159
|
+
else if (Array.isArray(value)) {
|
|
160
|
+
result[key] = value.map((item) => applyReplacement(item, fieldOptionsMap));
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
result[key] = value;
|
|
164
|
+
}
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const fieldOptions = fieldOptionsMap.get(key);
|
|
168
|
+
if (typeof fieldOptions !== "undefined") {
|
|
169
|
+
const replacement = fieldOptions
|
|
170
|
+
.replacement;
|
|
171
|
+
const targetKey = typeof replacement === "string" ? replacement : fieldOptions.field;
|
|
172
|
+
if (value !== null &&
|
|
173
|
+
typeof value === "object" &&
|
|
174
|
+
!Array.isArray(value)) {
|
|
175
|
+
result[targetKey] = applyReplacement(value, fieldOptionsMap);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
result[targetKey] = value;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
result[key] = value;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
function createFilter(entityName, fieldOptionsMap) {
|
|
188
|
+
const filterableFields = [...fieldOptionsMap.values()]
|
|
189
|
+
.filter((field) => field.filterable)
|
|
190
|
+
.map((field) => field.field);
|
|
191
|
+
return new graphql_1.GraphQLScalarType({
|
|
192
|
+
name: `${entityName}Filter`,
|
|
193
|
+
description: `A filter for ${entityName} that accepts MongoDB query syntax.\nSupported fields: ${filterableFields.join(", ")}`,
|
|
194
|
+
serialize: (value) => value,
|
|
195
|
+
parseValue: (value) => {
|
|
196
|
+
const parsed = parseJson(value);
|
|
197
|
+
const validated = validateSchema(parsed);
|
|
198
|
+
validateFilterFields(validated, fieldOptionsMap);
|
|
199
|
+
return applyReplacement(validated, fieldOptionsMap);
|
|
200
|
+
},
|
|
201
|
+
parseLiteral: (ast) => {
|
|
202
|
+
const parsed = parseLiteralValue(ast);
|
|
203
|
+
const validated = validateSchema(parsed);
|
|
204
|
+
validateFilterFields(validated, fieldOptionsMap);
|
|
205
|
+
return applyReplacement(validated, fieldOptionsMap);
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=create-filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-filter.js","sourceRoot":"","sources":["../../src/utils/create-filter.ts"],"names":[],"mappings":";;AAyOA,oCA+BC;AAvQD,qCAA6D;AAC7D,6BAAwB;AAExB,sCAA8C;AAG9C,MAAM,mBAAmB,GAAG;IAC1B,KAAK;IACL,KAAK;IACL,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,OAAO;IACP,QAAQ;IACR,KAAK;IACL,WAAW;IACX,WAAW;IACX,UAAU;CACF,CAAC;AAEX,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAU,CAAC;AAI1D,SAAS,sBAAsB;IAC7B,MAAM,eAAe,GAAG,OAAC,CAAC,KAAK,CAAC;QAC9B,OAAC,CAAC,MAAM,EAAE;QACV,OAAC,CAAC,MAAM,EAAE;QACV,OAAC,CAAC,OAAO,EAAE;QACX,OAAC,CAAC,IAAI,EAAE;KACT,CAAC,CAAC;IAEH,MAAM,sBAAsB,GAAG,OAAC;SAC7B,MAAM,CAAC;QACN,GAAG,EAAE,eAAe,CAAC,QAAQ,EAAE;QAC/B,GAAG,EAAE,eAAe,CAAC,QAAQ,EAAE;QAC/B,GAAG,EAAE,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC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B,CAClB,SAAS,EACT,eAA8D,CAC/D,CAAC;YACF,OAAO,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QACtD,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Type } from "@nestjs/common";
|
|
2
|
+
import { FieldOptions, OrderFieldType, OrderInterface } from "../interfaces";
|
|
3
|
+
export interface CreateOrderResult<Entity extends object> {
|
|
4
|
+
Order: Type<OrderInterface<Entity>>;
|
|
5
|
+
OrderField: OrderFieldType<Entity>;
|
|
6
|
+
}
|
|
7
|
+
export declare function createOrder<Entity extends object>(entityName: string, fieldOptionsMap: Map<string, FieldOptions<Entity, any, any>>): CreateOrderResult<Entity>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createOrder = createOrder;
|
|
13
|
+
const graphql_1 = require("@nest-boot/graphql");
|
|
14
|
+
const inflection_1 = require("inflection");
|
|
15
|
+
const enums_1 = require("../enums");
|
|
16
|
+
function createOrder(entityName, fieldOptionsMap) {
|
|
17
|
+
const humanizeEntityName = (0, inflection_1.humanize)(entityName, true);
|
|
18
|
+
const humanizeAndPluralizeEntityName = (0, inflection_1.pluralize)((0, inflection_1.humanize)(entityName, true));
|
|
19
|
+
const sortableFields = [...fieldOptionsMap.values()].filter((field) => field?.sortable);
|
|
20
|
+
const OrderField = sortableFields.reduce((result, fieldOptions) => {
|
|
21
|
+
return {
|
|
22
|
+
...result,
|
|
23
|
+
[(0, inflection_1.underscore)(fieldOptions.field).toUpperCase()]: fieldOptions.replacement ??
|
|
24
|
+
fieldOptions.field,
|
|
25
|
+
};
|
|
26
|
+
}, { ID: "id" });
|
|
27
|
+
(0, graphql_1.registerEnumType)(OrderField, {
|
|
28
|
+
name: `${entityName}OrderField`,
|
|
29
|
+
description: `Properties by which ${humanizeEntityName} connections can be ordered.`,
|
|
30
|
+
});
|
|
31
|
+
let Order = class Order {
|
|
32
|
+
};
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, graphql_1.Field)(() => OrderField, {
|
|
35
|
+
description: `The field to order ${humanizeAndPluralizeEntityName} by.`,
|
|
36
|
+
}),
|
|
37
|
+
__metadata("design:type", String)
|
|
38
|
+
], Order.prototype, "field", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, graphql_1.Field)(() => enums_1.OrderDirection, { description: `The ordering direction.` }),
|
|
41
|
+
__metadata("design:type", String)
|
|
42
|
+
], Order.prototype, "direction", void 0);
|
|
43
|
+
Order = __decorate([
|
|
44
|
+
(0, graphql_1.InputType)(`${entityName}Order`, {
|
|
45
|
+
description: `Ordering options for ${humanizeEntityName} connections`,
|
|
46
|
+
})
|
|
47
|
+
], Order);
|
|
48
|
+
return { Order, OrderField };
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=create-order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-order.js","sourceRoot":"","sources":["../../src/utils/create-order.ts"],"names":[],"mappings":";;;;;;;;;;;AAmBA,kCA2CC;AA9DD,gDAAwE;AAExE,2CAA6D;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tE,CAAC;OACI,KAAK,CASV;IAED,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;AAC/B,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -14,5 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./create-connection"), exports);
|
|
18
|
+
__exportStar(require("./create-connection-args"), exports);
|
|
19
|
+
__exportStar(require("./create-edge"), exports);
|
|
20
|
+
__exportStar(require("./create-filter"), exports);
|
|
21
|
+
__exportStar(require("./create-order"), exports);
|
|
18
22
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,2DAAyC;AACzC,gDAA8B;AAC9B,kDAAgC;AAChC,iDAA+B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-boot/graphql-connection",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "d4rkcr0w <me@d4rkcr0w.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -16,15 +16,12 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"chevrotain": "10.5.0",
|
|
18
18
|
"inflection": "^3.0.2",
|
|
19
|
-
"lodash": "^4.17.21"
|
|
19
|
+
"lodash": "^4.17.21",
|
|
20
|
+
"zod": "^3.25.67"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@mikro-orm/core": "^6.5.8",
|
|
23
24
|
"@mikro-orm/knex": "^6.5.8",
|
|
24
|
-
"@nest-boot/eslint-config": "^7.0.0",
|
|
25
|
-
"@nest-boot/eslint-plugin": "^7.0.0",
|
|
26
|
-
"@nest-boot/graphql": "^7.1.1",
|
|
27
|
-
"@nest-boot/tsconfig": "^7.0.0",
|
|
28
25
|
"@nestjs/apollo": "^13.2.1",
|
|
29
26
|
"@nestjs/common": "^11.1.9",
|
|
30
27
|
"@nestjs/core": "^11.1.9",
|
|
@@ -41,7 +38,11 @@
|
|
|
41
38
|
"reflect-metadata": "^0.2.2",
|
|
42
39
|
"rxjs": "^7.8.2",
|
|
43
40
|
"ts-jest": "^29.4.4",
|
|
44
|
-
"typescript": "^5.9.3"
|
|
41
|
+
"typescript": "^5.9.3",
|
|
42
|
+
"@nest-boot/eslint-config": "^7.0.1",
|
|
43
|
+
"@nest-boot/eslint-plugin": "^7.0.2",
|
|
44
|
+
"@nest-boot/graphql": "^7.1.1",
|
|
45
|
+
"@nest-boot/tsconfig": "^7.0.0"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"@mikro-orm/core": "^6.0.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function inferType(value: string | number | bigint | boolean | Date): "string" | "number" | "bigint" | "boolean" | "date";
|
package/dist/utils/infer-type.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.inferType = inferType;
|
|
4
|
-
function inferType(value) {
|
|
5
|
-
if (value instanceof Date) {
|
|
6
|
-
return "date";
|
|
7
|
-
}
|
|
8
|
-
const typeOf = typeof value;
|
|
9
|
-
if (["string", "number", "bigint", "boolean"].includes(typeOf)) {
|
|
10
|
-
return typeOf;
|
|
11
|
-
}
|
|
12
|
-
return "string";
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=infer-type.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"infer-type.js","sourceRoot":"","sources":["../../src/utils/infer-type.ts"],"names":[],"mappings":";;AAAA,8BAcC;AAdD,SAAgB,SAAS,CACvB,KAAgD;IAEhD,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,MAAM,GAAG,OAAO,KAAK,CAAC;IAE5B,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/D,OAAO,MAAoD,CAAC;IAC9D,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|