@atls/nestjs-dataloader 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -4
- package/dist/decorators/index.d.ts +2 -2
- package/dist/decorators/index.js +2 -18
- package/dist/decorators/loader.decorator.js +13 -15
- package/dist/decorators/order-result-by-key.decorator.d.ts +1 -1
- package/dist/decorators/order-result-by-key.decorator.js +25 -10
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -19
- package/dist/interceptors/data-loader.interceptor.d.ts +5 -5
- package/dist/interceptors/data-loader.interceptor.js +26 -24
- package/dist/interceptors/index.d.ts +1 -1
- package/dist/interceptors/index.js +1 -17
- package/dist/interfaces/index.d.ts +1 -1
- package/dist/interfaces/index.js +1 -17
- package/dist/interfaces/nest-dataloader.interfaces.d.ts +2 -2
- package/dist/interfaces/nest-dataloader.interfaces.js +1 -2
- package/package.json +34 -19
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
## 0.0.11 (2025-12-31)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
* **packages:** linter errors ([204ce22](https://github.com/atls/nestjs/commit/204ce229e375b09ffd69d93e47c08bd1d1fbea1b))
|
|
10
|
+
* **packages:** linter errors ([d41854b](https://github.com/atls/nestjs/commit/d41854b94d5502ebf2b9e18d22cac33f98c8fc41))
|
|
11
|
+
* **packages:** tests ([ae0f308](https://github.com/atls/nestjs/commit/ae0f308e695cfe39b4e2d38b6a33be4f7e5a8821))
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
* **common:** bump yarn, trigger release ([#338](https://github.com/atls/nestjs/issues/338)) ([9837d48](https://github.com/atls/nestjs/commit/9837d482f75928a3ac132d0306ab6de04d8a04b9))
|
|
17
|
+
|
|
18
|
+
|
package/dist/constants.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const GET_LOADER_CONTEXT_KEY
|
|
1
|
+
export declare const GET_LOADER_CONTEXT_KEY = "GET_LOADER_CONTEXT_KEY";
|
package/dist/constants.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './order-result-by-key.decorator';
|
|
2
|
-
export * from './loader.decorator';
|
|
1
|
+
export * from './order-result-by-key.decorator.js';
|
|
2
|
+
export * from './loader.decorator.js';
|
package/dist/decorators/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./order-result-by-key.decorator"), exports);
|
|
18
|
-
__exportStar(require("./loader.decorator"), exports);
|
|
1
|
+
export * from "./order-result-by-key.decorator.js";
|
|
2
|
+
export * from "./loader.decorator.js";
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const data_loader_interceptor_1 = require("../interceptors/data-loader.interceptor");
|
|
10
|
-
exports.Loader = (0, common_2.createParamDecorator)((type, context) => {
|
|
11
|
-
const graphqlExecutionContext = graphql_1.GqlExecutionContext.create(context);
|
|
1
|
+
import { InternalServerErrorException } from '@nestjs/common';
|
|
2
|
+
import { APP_INTERCEPTOR } from '@nestjs/core';
|
|
3
|
+
import { GqlExecutionContext } from '@nestjs/graphql';
|
|
4
|
+
import { createParamDecorator } from '@nestjs/common';
|
|
5
|
+
import { GET_LOADER_CONTEXT_KEY } from '../constants.js';
|
|
6
|
+
import { DataLoaderInterceptor } from '../interceptors/index.js';
|
|
7
|
+
export const Loader = createParamDecorator((type, context) => {
|
|
8
|
+
const graphqlExecutionContext = GqlExecutionContext.create(context);
|
|
12
9
|
const ctx = graphqlExecutionContext.getContext();
|
|
13
|
-
if (ctx[
|
|
14
|
-
throw new
|
|
15
|
-
You should provide interceptor ${
|
|
10
|
+
if (ctx[GET_LOADER_CONTEXT_KEY] === undefined) {
|
|
11
|
+
throw new InternalServerErrorException(`
|
|
12
|
+
You should provide interceptor ${DataLoaderInterceptor.name} globaly with ${APP_INTERCEPTOR}
|
|
16
13
|
`);
|
|
17
14
|
}
|
|
18
|
-
|
|
15
|
+
const getLoader = ctx[GET_LOADER_CONTEXT_KEY];
|
|
16
|
+
return getLoader(type);
|
|
19
17
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const OrderResultByKey: (key?: string, defaultValue?:
|
|
1
|
+
export declare const OrderResultByKey: (key?: string, defaultValue?: unknown) => (target: object, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const normalizeKey = (value) => {
|
|
2
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
3
|
+
return String(value);
|
|
4
|
+
}
|
|
5
|
+
if (typeof value === 'symbol') {
|
|
6
|
+
return value.toString();
|
|
7
|
+
}
|
|
8
|
+
return undefined;
|
|
9
|
+
};
|
|
10
|
+
export const OrderResultByKey = (key = 'id', defaultValue = undefined) => (target, propertyKey, descriptor) => {
|
|
5
11
|
const original = descriptor.value;
|
|
6
12
|
descriptor.value = async function (keys, ...args) {
|
|
7
13
|
const method = original.bind(this);
|
|
8
14
|
const result = await method(keys, ...args);
|
|
9
|
-
const resultByKey = result.reduce((res, item) =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
const resultByKey = result.reduce((res, item) => {
|
|
16
|
+
const itemKey = item[key];
|
|
17
|
+
const normalizedKey = normalizeKey(itemKey);
|
|
18
|
+
if (normalizedKey !== undefined) {
|
|
19
|
+
res[normalizedKey] = item;
|
|
20
|
+
}
|
|
21
|
+
return res;
|
|
22
|
+
}, {});
|
|
23
|
+
return keys.map((itemKey) => {
|
|
24
|
+
const normalizedKey = normalizeKey(itemKey);
|
|
25
|
+
if (normalizedKey === undefined) {
|
|
26
|
+
return defaultValue;
|
|
27
|
+
}
|
|
28
|
+
return resultByKey[normalizedKey] ?? defaultValue;
|
|
29
|
+
});
|
|
14
30
|
};
|
|
15
31
|
return descriptor;
|
|
16
32
|
};
|
|
17
|
-
exports.OrderResultByKey = OrderResultByKey;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './decorators';
|
|
2
|
-
export * from './interceptors';
|
|
3
|
-
export * from './interfaces';
|
|
1
|
+
export * from './decorators/index.js';
|
|
2
|
+
export * from './interceptors/index.js';
|
|
3
|
+
export type * from './interfaces/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./decorators"), exports);
|
|
18
|
-
__exportStar(require("./interceptors"), exports);
|
|
19
|
-
__exportStar(require("./interfaces"), exports);
|
|
1
|
+
export * from "./decorators/index.js";
|
|
2
|
+
export * from "./interceptors/index.js";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { CallHandler } from '@nestjs/common';
|
|
2
|
-
import { ExecutionContext } from '@nestjs/common';
|
|
3
|
-
import { NestInterceptor } from '@nestjs/common';
|
|
1
|
+
import type { CallHandler } from '@nestjs/common';
|
|
2
|
+
import type { ExecutionContext } from '@nestjs/common';
|
|
3
|
+
import type { NestInterceptor } from '@nestjs/common';
|
|
4
|
+
import type { Observable } from 'rxjs';
|
|
4
5
|
import { ModuleRef } from '@nestjs/core';
|
|
5
|
-
import { Observable } from 'rxjs';
|
|
6
6
|
export declare class DataLoaderInterceptor implements NestInterceptor {
|
|
7
7
|
private readonly moduleRef;
|
|
8
8
|
constructor(moduleRef: ModuleRef);
|
|
9
|
-
intercept(context: ExecutionContext, next: CallHandler): Observable<
|
|
9
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
10
10
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,40 +7,43 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const graphql_1 = require("@nestjs/graphql");
|
|
17
|
-
const constants_1 = require("../constants");
|
|
10
|
+
import { Injectable } from '@nestjs/common';
|
|
11
|
+
import { InternalServerErrorException } from '@nestjs/common';
|
|
12
|
+
import { ModuleRef } from '@nestjs/core';
|
|
13
|
+
import { GqlExecutionContext } from '@nestjs/graphql';
|
|
14
|
+
import { GET_LOADER_CONTEXT_KEY } from '../constants.js';
|
|
18
15
|
let DataLoaderInterceptor = class DataLoaderInterceptor {
|
|
16
|
+
moduleRef;
|
|
19
17
|
constructor(moduleRef) {
|
|
20
18
|
this.moduleRef = moduleRef;
|
|
21
19
|
}
|
|
22
20
|
intercept(context, next) {
|
|
23
|
-
const graphqlExecutionContext =
|
|
21
|
+
const graphqlExecutionContext = GqlExecutionContext.create(context);
|
|
24
22
|
const ctx = graphqlExecutionContext.getContext();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
const loaders = ctx;
|
|
24
|
+
if (ctx[GET_LOADER_CONTEXT_KEY] === undefined) {
|
|
25
|
+
ctx[GET_LOADER_CONTEXT_KEY] = (type) => {
|
|
26
|
+
const existing = loaders[type];
|
|
27
|
+
if (existing) {
|
|
28
|
+
return existing;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const loader = this.moduleRef
|
|
32
|
+
.get(type, { strict: false })
|
|
33
|
+
.generateDataLoader();
|
|
34
|
+
loaders[type] = loader;
|
|
35
|
+
return loader;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new InternalServerErrorException(`The loader ${type} is not provided`);
|
|
36
39
|
}
|
|
37
|
-
return ctx[type];
|
|
38
40
|
};
|
|
39
41
|
}
|
|
40
42
|
return next.handle();
|
|
41
43
|
}
|
|
42
44
|
};
|
|
43
45
|
DataLoaderInterceptor = __decorate([
|
|
44
|
-
|
|
45
|
-
__metadata("design:paramtypes", [
|
|
46
|
+
Injectable(),
|
|
47
|
+
__metadata("design:paramtypes", [ModuleRef])
|
|
46
48
|
], DataLoaderInterceptor);
|
|
47
|
-
|
|
49
|
+
export { DataLoaderInterceptor };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './data-loader.interceptor';
|
|
1
|
+
export * from './data-loader.interceptor.js';
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./data-loader.interceptor"), exports);
|
|
1
|
+
export * from "./data-loader.interceptor.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './nest-dataloader.interfaces';
|
|
1
|
+
export type * from './nest-dataloader.interfaces.js';
|
package/dist/interfaces/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./nest-dataloader.interfaces"), exports);
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atls/nestjs-dataloader",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./package.json": "./package.json",
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
5
14
|
"main": "dist/index.js",
|
|
6
15
|
"files": [
|
|
7
16
|
"dist"
|
|
@@ -15,32 +24,38 @@
|
|
|
15
24
|
"dataloader": "2.2.2"
|
|
16
25
|
},
|
|
17
26
|
"devDependencies": {
|
|
18
|
-
"@nestjs/common": "
|
|
19
|
-
"@nestjs/core": "10.
|
|
20
|
-
"@nestjs/graphql": "12.0
|
|
21
|
-
"@nestjs/microservices": "10.
|
|
22
|
-
"@
|
|
23
|
-
"@types/
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"reflect-metadata": "0.1.13",
|
|
28
|
-
"rxjs": "7.5.4",
|
|
29
|
-
"supertest": "6.3.3",
|
|
27
|
+
"@nestjs/common": "10.4.1",
|
|
28
|
+
"@nestjs/core": "10.4.1",
|
|
29
|
+
"@nestjs/graphql": "12.2.0",
|
|
30
|
+
"@nestjs/microservices": "10.4.1",
|
|
31
|
+
"@types/lodash": "4.17.7",
|
|
32
|
+
"@types/node": "22.5.5",
|
|
33
|
+
"graphql": "16.9.0",
|
|
34
|
+
"reflect-metadata": "0.2.2",
|
|
35
|
+
"rxjs": "7.8.1",
|
|
30
36
|
"ts-morph": "19.0.0",
|
|
31
37
|
"ws": "8.14.1"
|
|
32
38
|
},
|
|
33
39
|
"peerDependencies": {
|
|
34
|
-
"@nestjs/common": "10
|
|
35
|
-
"@nestjs/core": "10
|
|
36
|
-
"@nestjs/graphql": "12
|
|
37
|
-
"graphql": "16
|
|
38
|
-
"reflect-metadata": "0.
|
|
39
|
-
"rxjs": "7
|
|
40
|
+
"@nestjs/common": "10",
|
|
41
|
+
"@nestjs/core": "10",
|
|
42
|
+
"@nestjs/graphql": "12",
|
|
43
|
+
"graphql": "16",
|
|
44
|
+
"reflect-metadata": "0.2",
|
|
45
|
+
"rxjs": "7"
|
|
40
46
|
},
|
|
41
47
|
"publishConfig": {
|
|
48
|
+
"exports": {
|
|
49
|
+
"./package.json": "./package.json",
|
|
50
|
+
".": {
|
|
51
|
+
"import": "./dist/index.js",
|
|
52
|
+
"types": "./dist/index.d.ts",
|
|
53
|
+
"default": "./dist/index.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
42
56
|
"main": "dist/index.js",
|
|
43
57
|
"typings": "dist/index.d.ts"
|
|
44
58
|
},
|
|
59
|
+
"typecheckSkipLibCheck": true,
|
|
45
60
|
"typings": "dist/index.d.ts"
|
|
46
61
|
}
|