@thangnv-dev/data-nest 0.0.1
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-builder.d.ts +22 -0
- package/dist/connection-builder.d.ts.map +1 -0
- package/dist/connection-builder.js +216 -0
- package/dist/connection-builder.js.map +1 -0
- package/dist/connection-types.d.ts +38 -0
- package/dist/connection-types.d.ts.map +1 -0
- package/dist/connection-types.js +2 -0
- package/dist/connection-types.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { EntityRepository, FilterQuery, OrderDefinition } from '@mikro-orm/core';
|
|
2
|
+
import type { ConnectionArgs, ConnectionNode, ConnectionResult } from './connection-types.js';
|
|
3
|
+
export declare abstract class ConnectionBuilder<TEntity extends object, TNode extends ConnectionNode, TParent = undefined, TArgs extends ConnectionArgs = ConnectionArgs> {
|
|
4
|
+
protected readonly repository: EntityRepository<TEntity>;
|
|
5
|
+
protected constructor(repository: EntityRepository<TEntity>);
|
|
6
|
+
build(args: TArgs, parent?: TParent): Promise<ConnectionResult<TNode>>;
|
|
7
|
+
protected getDefaultPageSize(): number;
|
|
8
|
+
protected getMaxPageSize(): number;
|
|
9
|
+
protected resolveIncludeCount(args: TArgs): boolean;
|
|
10
|
+
protected resolveParentWhere(_parent: TParent | undefined, _args: TArgs): FilterQuery<TEntity> | Promise<FilterQuery<TEntity>>;
|
|
11
|
+
protected abstract resolveWhere(args: TArgs): FilterQuery<TEntity> | Promise<FilterQuery<TEntity>>;
|
|
12
|
+
protected abstract resolveOrderBy(args: TArgs): OrderDefinition<TEntity> | Promise<OrderDefinition<TEntity>>;
|
|
13
|
+
protected abstract toNode(entity: TEntity, index: number): TNode | Promise<TNode>;
|
|
14
|
+
private buildCursorConnection;
|
|
15
|
+
private buildOffsetConnection;
|
|
16
|
+
private resolvePagination;
|
|
17
|
+
private mergeWhere;
|
|
18
|
+
private hasWhereCondition;
|
|
19
|
+
private assertValidPageSize;
|
|
20
|
+
private assertValidOffset;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=connection-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-builder.d.ts","sourceRoot":"","sources":["../src/connection-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,eAAe,EAChB,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,gBAAgB,EACjB,MAAM,uBAAuB,CAAA;AAkB9B,8BACsB,iBAAiB,CACrC,OAAO,SAAS,MAAM,EACtB,KAAK,SAAS,cAAc,EAC5B,OAAO,GAAG,SAAS,EACnB,KAAK,SAAS,cAAc,GAAG,cAAc;IAEvB,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC,OAAO,CAAC;IAA9E,SAAS,aAAgC,UAAU,EAAE,gBAAgB,CAAC,OAAO,CAAC;IAExE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAkB5E,SAAS,CAAC,kBAAkB,IAAI,MAAM;IAItC,SAAS,CAAC,cAAc,IAAI,MAAM;IAIlC,SAAS,CAAC,mBAAmB,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO;IAInD,SAAS,CAAC,kBAAkB,CAC1B,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,KAAK,EAAE,KAAK,GACX,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAIvD,SAAS,CAAC,QAAQ,CAAC,YAAY,CAC7B,IAAI,EAAE,KAAK,GACV,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAEvD,SAAS,CAAC,QAAQ,CAAC,cAAc,CAC/B,IAAI,EAAE,KAAK,GACV,eAAe,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAE/D,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;YAEnE,qBAAqB;YAgDrB,qBAAqB;IAiDnC,OAAO,CAAC,iBAAiB;IAoFzB,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,mBAAmB;IAc3B,OAAO,CAAC,iBAAiB;CAK1B"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { BadRequestException, Injectable } from '@nestjs/common';
|
|
11
|
+
let ConnectionBuilder = class ConnectionBuilder {
|
|
12
|
+
repository;
|
|
13
|
+
constructor(repository) {
|
|
14
|
+
this.repository = repository;
|
|
15
|
+
}
|
|
16
|
+
async build(args, parent) {
|
|
17
|
+
const includeCount = this.resolveIncludeCount(args);
|
|
18
|
+
const pagination = this.resolvePagination(args);
|
|
19
|
+
const [where, parentWhere, orderBy] = await Promise.all([
|
|
20
|
+
this.resolveWhere(args),
|
|
21
|
+
this.resolveParentWhere(parent, args),
|
|
22
|
+
this.resolveOrderBy(args),
|
|
23
|
+
]);
|
|
24
|
+
const mergedWhere = this.mergeWhere(where, parentWhere);
|
|
25
|
+
if (pagination.mode === 'offset') {
|
|
26
|
+
return this.buildOffsetConnection(mergedWhere, orderBy, pagination, includeCount);
|
|
27
|
+
}
|
|
28
|
+
return this.buildCursorConnection(mergedWhere, orderBy, pagination, includeCount);
|
|
29
|
+
}
|
|
30
|
+
getDefaultPageSize() {
|
|
31
|
+
return 20;
|
|
32
|
+
}
|
|
33
|
+
getMaxPageSize() {
|
|
34
|
+
return 100;
|
|
35
|
+
}
|
|
36
|
+
resolveIncludeCount(args) {
|
|
37
|
+
return args.includeCount ?? true;
|
|
38
|
+
}
|
|
39
|
+
resolveParentWhere(_parent, _args) {
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
async buildCursorConnection(where, orderBy, pagination, includeCount) {
|
|
43
|
+
const cursor = await this.repository.findByCursor(where, {
|
|
44
|
+
orderBy,
|
|
45
|
+
first: pagination.first,
|
|
46
|
+
after: pagination.after,
|
|
47
|
+
last: pagination.last,
|
|
48
|
+
before: pagination.before,
|
|
49
|
+
includeCount,
|
|
50
|
+
});
|
|
51
|
+
const loadNodes = async () => Promise.all(cursor.items.map((entity, index) => this.toNode(entity, index)));
|
|
52
|
+
let nodesPromise;
|
|
53
|
+
let totalCountPromise;
|
|
54
|
+
return {
|
|
55
|
+
pageInfo: {
|
|
56
|
+
mode: 'cursor',
|
|
57
|
+
hasNextPage: cursor.hasNextPage,
|
|
58
|
+
hasPreviousPage: cursor.hasPrevPage,
|
|
59
|
+
startCursor: cursor.startCursor ?? undefined,
|
|
60
|
+
endCursor: cursor.endCursor ?? undefined,
|
|
61
|
+
},
|
|
62
|
+
get nodes() {
|
|
63
|
+
if (!nodesPromise) {
|
|
64
|
+
nodesPromise = loadNodes();
|
|
65
|
+
}
|
|
66
|
+
return nodesPromise;
|
|
67
|
+
},
|
|
68
|
+
get totalCount() {
|
|
69
|
+
if (!totalCountPromise) {
|
|
70
|
+
totalCountPromise = Promise.resolve(includeCount ? cursor.totalCount : undefined);
|
|
71
|
+
}
|
|
72
|
+
return totalCountPromise;
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
async buildOffsetConnection(where, orderBy, pagination, includeCount) {
|
|
77
|
+
const rows = await this.repository.find(where, {
|
|
78
|
+
limit: pagination.limit + 1,
|
|
79
|
+
offset: pagination.offset,
|
|
80
|
+
orderBy,
|
|
81
|
+
});
|
|
82
|
+
const hasNextPage = rows.length > pagination.limit;
|
|
83
|
+
const items = rows.slice(0, pagination.limit);
|
|
84
|
+
const loadNodes = async () => Promise.all(items.map((entity, index) => this.toNode(entity, index)));
|
|
85
|
+
const loadTotalCount = () => includeCount
|
|
86
|
+
? this.repository.count(where)
|
|
87
|
+
: Promise.resolve(undefined);
|
|
88
|
+
let nodesPromise;
|
|
89
|
+
let totalCountPromise;
|
|
90
|
+
return {
|
|
91
|
+
pageInfo: {
|
|
92
|
+
mode: 'offset',
|
|
93
|
+
limit: pagination.limit,
|
|
94
|
+
offset: pagination.offset,
|
|
95
|
+
hasNextPage,
|
|
96
|
+
hasPreviousPage: pagination.offset > 0,
|
|
97
|
+
},
|
|
98
|
+
get nodes() {
|
|
99
|
+
if (!nodesPromise) {
|
|
100
|
+
nodesPromise = loadNodes();
|
|
101
|
+
}
|
|
102
|
+
return nodesPromise;
|
|
103
|
+
},
|
|
104
|
+
get totalCount() {
|
|
105
|
+
if (!totalCountPromise) {
|
|
106
|
+
totalCountPromise = loadTotalCount();
|
|
107
|
+
}
|
|
108
|
+
return totalCountPromise;
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
resolvePagination(args) {
|
|
113
|
+
const maxPageSize = this.getMaxPageSize();
|
|
114
|
+
const defaultPageSize = this.getDefaultPageSize();
|
|
115
|
+
if (!Number.isInteger(maxPageSize) || maxPageSize < 1) {
|
|
116
|
+
throw new Error('ConnectionBuilder.getMaxPageSize() must return a positive integer.');
|
|
117
|
+
}
|
|
118
|
+
if (!Number.isInteger(defaultPageSize) ||
|
|
119
|
+
defaultPageSize < 1 ||
|
|
120
|
+
defaultPageSize > maxPageSize) {
|
|
121
|
+
throw new Error('ConnectionBuilder.getDefaultPageSize() must return a positive integer <= max page size.');
|
|
122
|
+
}
|
|
123
|
+
if (args.first !== undefined && args.last !== undefined) {
|
|
124
|
+
throw new BadRequestException('Use either "first" or "last", not both.');
|
|
125
|
+
}
|
|
126
|
+
if (args.last !== undefined && args.after !== undefined) {
|
|
127
|
+
throw new BadRequestException('"after" cannot be used together with "last".');
|
|
128
|
+
}
|
|
129
|
+
if (args.first !== undefined && args.before !== undefined) {
|
|
130
|
+
throw new BadRequestException('"before" cannot be used together with "first".');
|
|
131
|
+
}
|
|
132
|
+
const hasCursorParams = args.first !== undefined ||
|
|
133
|
+
args.last !== undefined ||
|
|
134
|
+
args.after !== undefined ||
|
|
135
|
+
args.before !== undefined;
|
|
136
|
+
const hasOffsetParams = args.limit !== undefined || args.offset !== undefined;
|
|
137
|
+
if (hasCursorParams && hasOffsetParams) {
|
|
138
|
+
throw new BadRequestException('Cannot mix cursor pagination params with offset pagination params.');
|
|
139
|
+
}
|
|
140
|
+
if (hasOffsetParams) {
|
|
141
|
+
const limit = args.limit ?? defaultPageSize;
|
|
142
|
+
const offset = args.offset ?? 0;
|
|
143
|
+
this.assertValidPageSize('limit', limit, maxPageSize);
|
|
144
|
+
this.assertValidOffset(offset);
|
|
145
|
+
return {
|
|
146
|
+
mode: 'offset',
|
|
147
|
+
limit,
|
|
148
|
+
offset,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
if (args.first === undefined && args.last === undefined) {
|
|
152
|
+
return {
|
|
153
|
+
mode: 'cursor',
|
|
154
|
+
first: defaultPageSize,
|
|
155
|
+
after: args.after,
|
|
156
|
+
before: args.before,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (args.first !== undefined) {
|
|
160
|
+
this.assertValidPageSize('first', args.first, maxPageSize);
|
|
161
|
+
return {
|
|
162
|
+
mode: 'cursor',
|
|
163
|
+
first: args.first,
|
|
164
|
+
after: args.after,
|
|
165
|
+
before: args.before,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const last = args.last ?? defaultPageSize;
|
|
169
|
+
this.assertValidPageSize('last', last, maxPageSize);
|
|
170
|
+
return {
|
|
171
|
+
mode: 'cursor',
|
|
172
|
+
last,
|
|
173
|
+
after: args.after,
|
|
174
|
+
before: args.before,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
mergeWhere(where, parentWhere) {
|
|
178
|
+
const hasWhere = this.hasWhereCondition(where);
|
|
179
|
+
const hasParentWhere = this.hasWhereCondition(parentWhere);
|
|
180
|
+
if (!hasWhere) {
|
|
181
|
+
return parentWhere;
|
|
182
|
+
}
|
|
183
|
+
if (!hasParentWhere) {
|
|
184
|
+
return where;
|
|
185
|
+
}
|
|
186
|
+
return { $and: [where, parentWhere] };
|
|
187
|
+
}
|
|
188
|
+
hasWhereCondition(where) {
|
|
189
|
+
if (Array.isArray(where)) {
|
|
190
|
+
return where.length > 0;
|
|
191
|
+
}
|
|
192
|
+
if (where && typeof where === 'object') {
|
|
193
|
+
return Object.keys(where).length > 0;
|
|
194
|
+
}
|
|
195
|
+
return where !== undefined && where !== null;
|
|
196
|
+
}
|
|
197
|
+
assertValidPageSize(key, value, maxPageSize) {
|
|
198
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
199
|
+
throw new BadRequestException(`"${key}" must be a positive integer.`);
|
|
200
|
+
}
|
|
201
|
+
if (value > maxPageSize) {
|
|
202
|
+
throw new BadRequestException(`"${key}" cannot be greater than ${maxPageSize}.`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
assertValidOffset(offset) {
|
|
206
|
+
if (!Number.isInteger(offset) || offset < 0) {
|
|
207
|
+
throw new BadRequestException('"offset" must be a non-negative integer.');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
ConnectionBuilder = __decorate([
|
|
212
|
+
Injectable(),
|
|
213
|
+
__metadata("design:paramtypes", [Function])
|
|
214
|
+
], ConnectionBuilder);
|
|
215
|
+
export { ConnectionBuilder };
|
|
216
|
+
//# sourceMappingURL=connection-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-builder.js","sourceRoot":"","sources":["../src/connection-builder.ts"],"names":[],"mappings":";;;;;;;;;AAKA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAwBzD,IAAe,iBAAiB,GAAhC,MAAe,iBAAiB;IAMI;IAAzC,YAAyC,UAAqC;QAArC,eAAU,GAAV,UAAU,CAA2B;IAAG,CAAC;IAElF,KAAK,CAAC,KAAK,CAAC,IAAW,EAAE,MAAgB;QACvC,MAAM,YAAY,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAA;QACnD,MAAM,UAAU,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAA;QAC/C,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACtD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;YACvB,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;SAC1B,CAAC,CAAA;QAEF,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;QAEvD,IAAI,UAAU,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC,qBAAqB,CAAC,W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AAK,QAAQ,EAAE,CAAC;YACvC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAA;QACtC,CAAC;QAED,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAA;IAC9C,CAAC;IAEO,mBAAmB,CACzB,GAA+B,EAC/B,KAAa,EACb,WAAmB;QAEnB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YAC1C,MAAM,IAAI,mBAAmB,CAAC,IAAI,GAAG,+BAA+B,CAAC,CAAA;QACvE,CAAC;QAED,IAAI,KAAK,GAAG,WAAW,EAAE,CAAC;YACxB,MAAM,IAAI,mBAAmB,CAAC,IAAI,GAAG,4BAA4B,WAAW,GAAG,CAAC,CAAA;QAClF,CAAC;IACH,CAAC;IAEO,iBAAiB,CAAC,MAAc;QACtC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,mBAAmB,CAAC,0CAA0C,CAAC,CAAA;QAC3E,CAAC;IACH,CAAC;CACF,CAAA;AA7RqB,iBAAiB;IADtC,UAAU,EAAE;;GACS,iBAAiB,CA6RtC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type ConnectionNode = {
|
|
2
|
+
id: string;
|
|
3
|
+
};
|
|
4
|
+
export type CursorConnectionPageInfo = {
|
|
5
|
+
mode: 'cursor';
|
|
6
|
+
hasNextPage: boolean;
|
|
7
|
+
hasPreviousPage: boolean;
|
|
8
|
+
startCursor?: string;
|
|
9
|
+
endCursor?: string;
|
|
10
|
+
};
|
|
11
|
+
export type OffsetConnectionPageInfo = {
|
|
12
|
+
mode: 'offset';
|
|
13
|
+
hasNextPage: boolean;
|
|
14
|
+
hasPreviousPage: boolean;
|
|
15
|
+
limit: number;
|
|
16
|
+
offset: number;
|
|
17
|
+
};
|
|
18
|
+
export type ConnectionPageInfo = CursorConnectionPageInfo | OffsetConnectionPageInfo;
|
|
19
|
+
export type ConnectionLazyValue<T> = T | Promise<T> | (() => T | Promise<T>);
|
|
20
|
+
export type ConnectionResult<TNode extends ConnectionNode = ConnectionNode> = {
|
|
21
|
+
nodes: ConnectionLazyValue<TNode[]>;
|
|
22
|
+
pageInfo: ConnectionPageInfo;
|
|
23
|
+
totalCount?: ConnectionLazyValue<number | undefined>;
|
|
24
|
+
};
|
|
25
|
+
export type CursorConnectionArgs = {
|
|
26
|
+
first?: number;
|
|
27
|
+
after?: string;
|
|
28
|
+
last?: number;
|
|
29
|
+
before?: string;
|
|
30
|
+
};
|
|
31
|
+
export type OffsetConnectionArgs = {
|
|
32
|
+
limit?: number;
|
|
33
|
+
offset?: number;
|
|
34
|
+
};
|
|
35
|
+
export type ConnectionArgs = CursorConnectionArgs & OffsetConnectionArgs & {
|
|
36
|
+
includeCount?: boolean;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=connection-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-types.d.ts","sourceRoot":"","sources":["../src/connection-types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,QAAQ,CAAA;IACd,WAAW,EAAE,OAAO,CAAA;IACpB,eAAe,EAAE,OAAO,CAAA;IACxB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,QAAQ,CAAA;IACd,WAAW,EAAE,OAAO,CAAA;IACpB,eAAe,EAAE,OAAO,CAAA;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,kBAAkB,GAC1B,wBAAwB,GACxB,wBAAwB,CAAA;AAE5B,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AAE5E,MAAM,MAAM,gBAAgB,CAAC,KAAK,SAAS,cAAc,GAAG,cAAc,IAAI;IAC5E,KAAK,EAAE,mBAAmB,CAAC,KAAK,EAAE,CAAC,CAAA;IACnC,QAAQ,EAAE,kBAAkB,CAAA;IAC5B,UAAU,CAAC,EAAE,mBAAmB,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;CACrD,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG,oBAAoB,GAC/C,oBAAoB,GAAG;IACrB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-types.js","sourceRoot":"","sources":["../src/connection-types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ConnectionBuilder } from './connection-builder.js';
|
|
2
|
+
export type { ConnectionArgs, ConnectionNode, ConnectionPageInfo, ConnectionLazyValue, ConnectionResult, CursorConnectionPageInfo, OffsetConnectionPageInfo, CursorConnectionArgs, OffsetConnectionArgs, } from './connection-types.js';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC3D,YAAY,EACV,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,uBAAuB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@thangnv-dev/data-nest",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -p tsconfig.build.json",
|
|
22
|
+
"lint": "eslint .",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"test": "vitest run"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@mikro-orm/core": "^6.6.7",
|
|
28
|
+
"@nestjs/common": "^11.1.14"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^8.56.0",
|
|
32
|
+
"@typescript-eslint/parser": "^8.56.0",
|
|
33
|
+
"eslint": "^10.0.0",
|
|
34
|
+
"reflect-metadata": "^0.2.2",
|
|
35
|
+
"rxjs": "^7.8.2",
|
|
36
|
+
"temporal-polyfill": "^0.3.0",
|
|
37
|
+
"typescript": "^5.9.3",
|
|
38
|
+
"vitest": "^4.0.18"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@nestjs/common": "^11.0.0",
|
|
42
|
+
"reflect-metadata": "^0.2.0",
|
|
43
|
+
"rxjs": "^7.8.0",
|
|
44
|
+
"temporal-polyfill": "*"
|
|
45
|
+
}
|
|
46
|
+
}
|