@gabroberge/nestjs-dataloader 3.0.0 → 12.0.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/CHANGELOG.md +8 -0
- package/README.md +3 -3
- package/dist/index.cjs +61 -0
- package/dist/index.d.cts +39 -0
- package/dist/index.d.mts +36 -29
- package/dist/index.mjs +49 -103
- package/package.json +55 -63
- package/dist/index.d.ts +0 -32
- package/dist/index.js +0 -134
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @gabroberge/nestjs-dataloader
|
|
2
2
|
|
|
3
|
+
## 12.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#58](https://github.com/gabroberge/nestjs-dataloader/pull/58) [`f1af94d`](https://github.com/gabroberge/nestjs-dataloader/commit/f1af94de346480527bde11dd21a6cea104b2051c) Thanks [@gabroberge](https://github.com/gabroberge)! - Raise peer dependencies to **NestJS 12** (`@nestjs/common`, `@nestjs/core`) and **`@nestjs/graphql` 14**. Applications still on NestJS 11 or `@nestjs/graphql` 13 must upgrade before installing this release.
|
|
8
|
+
|
|
9
|
+
The package build was also modernized: the library now ships from a workspace package built with **tsdown** instead of tsup.
|
|
10
|
+
|
|
3
11
|
## 3.0.0
|
|
4
12
|
|
|
5
13
|
### Major Changes
|
package/README.md
CHANGED
|
@@ -4,10 +4,10 @@ NestJS dataloader simplifies adding [graphql/dataloader](https://github.com/grap
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
Install with
|
|
7
|
+
Install with bun
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
|
|
10
|
+
bun add @gabroberge/nestjs-dataloader
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
Install with yarn
|
|
@@ -95,4 +95,4 @@ The important thing to note is that the parameter of the `@Loader` decorator is
|
|
|
95
95
|
|
|
96
96
|
## Contributing
|
|
97
97
|
|
|
98
|
-
Pull requests are always welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
98
|
+
Pull requests are always welcome. For major changes, please open an issue first to discuss what you would like to change.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _nestjs_common = require("@nestjs/common");
|
|
3
|
+
let _nestjs_core = require("@nestjs/core");
|
|
4
|
+
let _nestjs_graphql = require("@nestjs/graphql");
|
|
5
|
+
//#region src/dataloader/data-loader.ts
|
|
6
|
+
var NestDataLoader = class {};
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/constants.ts
|
|
9
|
+
const NEST_LOADER_CONTEXT_KEY = "NEST_LOADER_CONTEXT_KEY";
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/decorateMetadata.js
|
|
12
|
+
function __decorateMetadata(k, v) {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/decorate.js
|
|
17
|
+
function __decorate(decorators, target, key, desc) {
|
|
18
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
+
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;
|
|
21
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/interceptors/data-loader.interceptor.ts
|
|
25
|
+
let NestDataLoaderInterceptor = class NestDataLoaderInterceptor {
|
|
26
|
+
moduleRef;
|
|
27
|
+
constructor(moduleRef) {
|
|
28
|
+
this.moduleRef = moduleRef;
|
|
29
|
+
}
|
|
30
|
+
intercept(context, next) {
|
|
31
|
+
const injectionContext = _nestjs_graphql.GqlExecutionContext.create(context).getContext();
|
|
32
|
+
injectionContext[NEST_LOADER_CONTEXT_KEY] ??= {
|
|
33
|
+
contextId: _nestjs_core.ContextIdFactory.create(),
|
|
34
|
+
getLoader: this.getLoader.bind(this, injectionContext)
|
|
35
|
+
};
|
|
36
|
+
return next.handle();
|
|
37
|
+
}
|
|
38
|
+
async getLoader(injectionContext, type) {
|
|
39
|
+
if (injectionContext[type] === void 0) await this.moduleRef.resolve(type, injectionContext[NEST_LOADER_CONTEXT_KEY]?.contextId, { strict: false }).then((nestLoader) => {
|
|
40
|
+
injectionContext[type] = nestLoader.generateDataLoader();
|
|
41
|
+
});
|
|
42
|
+
return injectionContext[type];
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
NestDataLoaderInterceptor = __decorate([(0, _nestjs_common.Injectable)(), __decorateMetadata("design:paramtypes", [typeof _nestjs_core.ModuleRef === "undefined" ? Object : _nestjs_core.ModuleRef])], NestDataLoaderInterceptor);
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/decorators/loader.decorator.ts
|
|
48
|
+
const Loader = (0, _nestjs_common.createParamDecorator)(async (data, context) => {
|
|
49
|
+
const loaderContext = _nestjs_graphql.GqlExecutionContext.create(context).getContext()[NEST_LOADER_CONTEXT_KEY];
|
|
50
|
+
if (loaderContext !== void 0) return loaderContext.getLoader(data);
|
|
51
|
+
throw new _nestjs_common.InternalServerErrorException(`You should provide interceptor ${NestDataLoaderInterceptor.name} globally with ${_nestjs_core.APP_INTERCEPTOR}`);
|
|
52
|
+
});
|
|
53
|
+
//#endregion
|
|
54
|
+
exports.Loader = Loader;
|
|
55
|
+
exports.NestDataLoader = NestDataLoader;
|
|
56
|
+
Object.defineProperty(exports, "NestDataLoaderInterceptor", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function() {
|
|
59
|
+
return NestDataLoaderInterceptor;
|
|
60
|
+
}
|
|
61
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import DataLoader from "dataloader";
|
|
2
|
+
import { CallHandler, ExecutionContext, NestInterceptor, Type, createParamDecorator } from "@nestjs/common";
|
|
3
|
+
import { ContextId, ModuleRef } from "@nestjs/core";
|
|
4
|
+
import { Observable } from "rxjs";
|
|
5
|
+
//#region src/dataloader/data-loader.d.ts
|
|
6
|
+
declare abstract class NestDataLoader<Key extends number | string = number | string, Item = unknown> {
|
|
7
|
+
abstract generateDataLoader(): DataLoader<Key, Item | Item[]>;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/types/loader.data.d.ts
|
|
11
|
+
type LoaderData = Type<NestDataLoader>;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/decorators/loader.decorator.d.ts
|
|
14
|
+
declare const Loader: ReturnType<typeof createParamDecorator<LoaderData>>;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/interceptors/data-loader.interceptor.d.ts
|
|
17
|
+
declare class NestDataLoaderInterceptor implements NestInterceptor {
|
|
18
|
+
private readonly moduleRef;
|
|
19
|
+
constructor(moduleRef: ModuleRef);
|
|
20
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
21
|
+
private getLoader;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/constants.d.ts
|
|
25
|
+
declare const NEST_LOADER_CONTEXT_KEY = "NEST_LOADER_CONTEXT_KEY";
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/types/loader.context.d.ts
|
|
28
|
+
interface LoaderContext {
|
|
29
|
+
contextId: ContextId;
|
|
30
|
+
getLoader(data: LoaderData | string): Promise<DataLoader<number | string, unknown>>;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/types/injection.context.d.ts
|
|
34
|
+
interface InjectionContext {
|
|
35
|
+
[key: string]: DataLoader<number | string, unknown> | LoaderContext | undefined;
|
|
36
|
+
[NEST_LOADER_CONTEXT_KEY]?: LoaderContext;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { type InjectionContext, Loader, type LoaderContext, type LoaderData, NestDataLoader, NestDataLoaderInterceptor };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,32 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
declare abstract class NestDataLoader<Key extends string | number, Item> {
|
|
10
|
-
abstract generateDataLoader(): DataLoader<Key, Item | Item[]>;
|
|
1
|
+
import { CallHandler, ExecutionContext, NestInterceptor, Type, createParamDecorator } from "@nestjs/common";
|
|
2
|
+
import { ContextId, ModuleRef } from "@nestjs/core";
|
|
3
|
+
import DataLoader from "dataloader";
|
|
4
|
+
import { Observable } from "rxjs";
|
|
5
|
+
//#region src/dataloader/data-loader.d.ts
|
|
6
|
+
declare abstract class NestDataLoader<Key extends number | string = number | string, Item = unknown> {
|
|
7
|
+
abstract generateDataLoader(): DataLoader<Key, Item | Item[]>;
|
|
11
8
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
[NEST_LOADER_CONTEXT_KEY]?: LoaderContext;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
declare const Loader: (...dataOrPipes: (LoaderData | _nestjs_common.PipeTransform<any, any> | _nestjs_common.Type<_nestjs_common.PipeTransform<any, any>>)[]) => ParameterDecorator;
|
|
24
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/types/loader.data.d.ts
|
|
11
|
+
type LoaderData = Type<NestDataLoader>;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/decorators/loader.decorator.d.ts
|
|
14
|
+
declare const Loader: ReturnType<typeof createParamDecorator<LoaderData>>;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/interceptors/data-loader.interceptor.d.ts
|
|
25
17
|
declare class NestDataLoaderInterceptor implements NestInterceptor {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
private readonly moduleRef;
|
|
19
|
+
constructor(moduleRef: ModuleRef);
|
|
20
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
21
|
+
private getLoader;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/constants.d.ts
|
|
25
|
+
declare const NEST_LOADER_CONTEXT_KEY = "NEST_LOADER_CONTEXT_KEY";
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/types/loader.context.d.ts
|
|
28
|
+
interface LoaderContext {
|
|
29
|
+
contextId: ContextId;
|
|
30
|
+
getLoader(data: LoaderData | string): Promise<DataLoader<number | string, unknown>>;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/types/injection.context.d.ts
|
|
34
|
+
interface InjectionContext {
|
|
35
|
+
[key: string]: DataLoader<number | string, unknown> | LoaderContext | undefined;
|
|
36
|
+
[NEST_LOADER_CONTEXT_KEY]?: LoaderContext;
|
|
30
37
|
}
|
|
31
|
-
|
|
32
|
-
export { type InjectionContext, Loader, type LoaderContext, type LoaderData, NestDataLoader, NestDataLoaderInterceptor };
|
|
38
|
+
//#endregion
|
|
39
|
+
export { type InjectionContext, Loader, type LoaderContext, type LoaderData, NestDataLoader, NestDataLoaderInterceptor };
|
package/dist/index.mjs
CHANGED
|
@@ -1,107 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
var __async = (__this, __arguments, generator) => {
|
|
6
|
-
return new Promise((resolve, reject) => {
|
|
7
|
-
var fulfilled = (value) => {
|
|
8
|
-
try {
|
|
9
|
-
step(generator.next(value));
|
|
10
|
-
} catch (e) {
|
|
11
|
-
reject(e);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
var rejected = (value) => {
|
|
15
|
-
try {
|
|
16
|
-
step(generator.throw(value));
|
|
17
|
-
} catch (e) {
|
|
18
|
-
reject(e);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
22
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// src/loader.decorator.ts
|
|
27
|
-
import { createParamDecorator, InternalServerErrorException } from "@nestjs/common";
|
|
28
|
-
import { APP_INTERCEPTOR } from "@nestjs/core";
|
|
29
|
-
import { GqlExecutionContext as GqlExecutionContext2 } from "@nestjs/graphql";
|
|
30
|
-
|
|
31
|
-
// src/constants.ts
|
|
32
|
-
var NEST_LOADER_CONTEXT_KEY = "NEST_LOADER_CONTEXT_KEY";
|
|
33
|
-
|
|
34
|
-
// src/nest-loader.interceptor.ts
|
|
35
|
-
import { Injectable } from "@nestjs/common";
|
|
36
|
-
import { ContextIdFactory, ModuleRef } from "@nestjs/core";
|
|
1
|
+
import { Injectable, InternalServerErrorException, createParamDecorator } from "@nestjs/common";
|
|
2
|
+
import { APP_INTERCEPTOR, ContextIdFactory, ModuleRef } from "@nestjs/core";
|
|
37
3
|
import { GqlExecutionContext } from "@nestjs/graphql";
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
4
|
+
//#region src/dataloader/data-loader.ts
|
|
5
|
+
var NestDataLoader = class {};
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/constants.ts
|
|
8
|
+
const NEST_LOADER_CONTEXT_KEY = "NEST_LOADER_CONTEXT_KEY";
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/decorateMetadata.js
|
|
11
|
+
function __decorateMetadata(k, v) {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
13
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/decorate.js
|
|
16
|
+
function __decorate(decorators, target, key, desc) {
|
|
17
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
18
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
19
|
+
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;
|
|
20
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
47
21
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
yield this.moduleRef.resolve(type, (_a = injectionContext[NEST_LOADER_CONTEXT_KEY]) == null ? void 0 : _a.contextId, {
|
|
70
|
-
strict: false
|
|
71
|
-
}).then((nestLoader) => {
|
|
72
|
-
injectionContext[type] = nestLoader.generateDataLoader();
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
return injectionContext[type];
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
__name(_NestDataLoaderInterceptor, "NestDataLoaderInterceptor");
|
|
80
|
-
var NestDataLoaderInterceptor = _NestDataLoaderInterceptor;
|
|
81
|
-
NestDataLoaderInterceptor = _ts_decorate([
|
|
82
|
-
Injectable(),
|
|
83
|
-
_ts_metadata("design:type", Function),
|
|
84
|
-
_ts_metadata("design:paramtypes", [
|
|
85
|
-
typeof ModuleRef === "undefined" ? Object : ModuleRef
|
|
86
|
-
])
|
|
87
|
-
], NestDataLoaderInterceptor);
|
|
88
|
-
|
|
89
|
-
// src/loader.decorator.ts
|
|
90
|
-
var Loader = createParamDecorator((data, context) => __async(null, null, function* () {
|
|
91
|
-
const gqlExecutionContext = GqlExecutionContext2.create(context);
|
|
92
|
-
const injectionContext = gqlExecutionContext.getContext();
|
|
93
|
-
const loaderContext = injectionContext[NEST_LOADER_CONTEXT_KEY];
|
|
94
|
-
if (loaderContext !== void 0) return loaderContext.getLoader(data);
|
|
95
|
-
throw new InternalServerErrorException(`You should provide interceptor ${NestDataLoaderInterceptor.name} globally with ${APP_INTERCEPTOR}`);
|
|
96
|
-
}));
|
|
97
|
-
|
|
98
|
-
// src/nest-dataloader.ts
|
|
99
|
-
var _NestDataLoader = class _NestDataLoader {
|
|
100
|
-
};
|
|
101
|
-
__name(_NestDataLoader, "NestDataLoader");
|
|
102
|
-
var NestDataLoader = _NestDataLoader;
|
|
103
|
-
export {
|
|
104
|
-
Loader,
|
|
105
|
-
NestDataLoader,
|
|
106
|
-
NestDataLoaderInterceptor
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/interceptors/data-loader.interceptor.ts
|
|
24
|
+
let NestDataLoaderInterceptor = class NestDataLoaderInterceptor {
|
|
25
|
+
moduleRef;
|
|
26
|
+
constructor(moduleRef) {
|
|
27
|
+
this.moduleRef = moduleRef;
|
|
28
|
+
}
|
|
29
|
+
intercept(context, next) {
|
|
30
|
+
const injectionContext = GqlExecutionContext.create(context).getContext();
|
|
31
|
+
injectionContext[NEST_LOADER_CONTEXT_KEY] ??= {
|
|
32
|
+
contextId: ContextIdFactory.create(),
|
|
33
|
+
getLoader: this.getLoader.bind(this, injectionContext)
|
|
34
|
+
};
|
|
35
|
+
return next.handle();
|
|
36
|
+
}
|
|
37
|
+
async getLoader(injectionContext, type) {
|
|
38
|
+
if (injectionContext[type] === void 0) await this.moduleRef.resolve(type, injectionContext[NEST_LOADER_CONTEXT_KEY]?.contextId, { strict: false }).then((nestLoader) => {
|
|
39
|
+
injectionContext[type] = nestLoader.generateDataLoader();
|
|
40
|
+
});
|
|
41
|
+
return injectionContext[type];
|
|
42
|
+
}
|
|
107
43
|
};
|
|
44
|
+
NestDataLoaderInterceptor = __decorate([Injectable(), __decorateMetadata("design:paramtypes", [typeof ModuleRef === "undefined" ? Object : ModuleRef])], NestDataLoaderInterceptor);
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/decorators/loader.decorator.ts
|
|
47
|
+
const Loader = createParamDecorator(async (data, context) => {
|
|
48
|
+
const loaderContext = GqlExecutionContext.create(context).getContext()[NEST_LOADER_CONTEXT_KEY];
|
|
49
|
+
if (loaderContext !== void 0) return loaderContext.getLoader(data);
|
|
50
|
+
throw new InternalServerErrorException(`You should provide interceptor ${NestDataLoaderInterceptor.name} globally with ${APP_INTERCEPTOR}`);
|
|
51
|
+
});
|
|
52
|
+
//#endregion
|
|
53
|
+
export { Loader, NestDataLoader, NestDataLoaderInterceptor };
|
package/package.json
CHANGED
|
@@ -1,64 +1,56 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"test": "vitest run",
|
|
58
|
-
"build": "tsup",
|
|
59
|
-
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.spec.ts\"",
|
|
60
|
-
"lint": "tsc",
|
|
61
|
-
"ci": "pnpm lint && pnpm test && pnpm build",
|
|
62
|
-
"release": "pnpm run ci && changeset publish"
|
|
63
|
-
}
|
|
64
|
-
}
|
|
2
|
+
"name": "@gabroberge/nestjs-dataloader",
|
|
3
|
+
"version": "12.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "A NestJS decorator for dataloader",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"dataloader",
|
|
8
|
+
"graphql",
|
|
9
|
+
"nestjs",
|
|
10
|
+
"typescript"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/gabroberge/nestjs-dataloader#readme",
|
|
13
|
+
"bugs": "https://github.com/gabroberge/nestjs-dataloader/issues",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "Gabriel Roberge",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/gabroberge/nestjs-dataloader.git"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "./dist/index.cjs",
|
|
22
|
+
"module": "./dist/index.mjs",
|
|
23
|
+
"types": "./dist/index.d.cts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"import": {
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"default": "./dist/index.mjs"
|
|
29
|
+
},
|
|
30
|
+
"require": {
|
|
31
|
+
"types": "./dist/index.d.cts",
|
|
32
|
+
"default": "./dist/index.cjs"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsdown",
|
|
38
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
39
|
+
"test": "vitest run"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@nestjs/common": "^12.0.1",
|
|
43
|
+
"@nestjs/core": "^12.0.1",
|
|
44
|
+
"@nestjs/graphql": "^14.0.0",
|
|
45
|
+
"@nestjs/testing": "^12.0.1",
|
|
46
|
+
"dataloader": "^2.2.3",
|
|
47
|
+
"rxjs": "^7.8.2"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@nestjs/common": "^12.0.1",
|
|
51
|
+
"@nestjs/core": "^12.0.1",
|
|
52
|
+
"@nestjs/graphql": "^14.0.0",
|
|
53
|
+
"dataloader": "^2.2.3",
|
|
54
|
+
"rxjs": "^7.8.2"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as _nestjs_common from '@nestjs/common';
|
|
2
|
-
import { Type, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
3
|
-
import { ContextId, ModuleRef } from '@nestjs/core';
|
|
4
|
-
import DataLoader from 'dataloader';
|
|
5
|
-
import { Observable } from 'rxjs';
|
|
6
|
-
|
|
7
|
-
declare const NEST_LOADER_CONTEXT_KEY = "NEST_LOADER_CONTEXT_KEY";
|
|
8
|
-
|
|
9
|
-
declare abstract class NestDataLoader<Key extends string | number, Item> {
|
|
10
|
-
abstract generateDataLoader(): DataLoader<Key, Item | Item[]>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type LoaderContext = {
|
|
14
|
-
contextId: ContextId;
|
|
15
|
-
getLoader(data: LoaderData | string): Promise<DataLoader<any, any>>;
|
|
16
|
-
};
|
|
17
|
-
type LoaderData = Type<NestDataLoader<any, any>>;
|
|
18
|
-
type InjectionContext = {
|
|
19
|
-
[key: string]: DataLoader<any, any> | LoaderContext | undefined;
|
|
20
|
-
[NEST_LOADER_CONTEXT_KEY]?: LoaderContext;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
declare const Loader: (...dataOrPipes: (LoaderData | _nestjs_common.PipeTransform<any, any> | _nestjs_common.Type<_nestjs_common.PipeTransform<any, any>>)[]) => ParameterDecorator;
|
|
24
|
-
|
|
25
|
-
declare class NestDataLoaderInterceptor implements NestInterceptor {
|
|
26
|
-
private readonly moduleRef;
|
|
27
|
-
constructor(moduleRef: ModuleRef);
|
|
28
|
-
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
29
|
-
private getLoader;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { type InjectionContext, Loader, type LoaderContext, type LoaderData, NestDataLoader, NestDataLoaderInterceptor };
|
package/dist/index.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
-
var __async = (__this, __arguments, generator) => {
|
|
23
|
-
return new Promise((resolve, reject) => {
|
|
24
|
-
var fulfilled = (value) => {
|
|
25
|
-
try {
|
|
26
|
-
step(generator.next(value));
|
|
27
|
-
} catch (e) {
|
|
28
|
-
reject(e);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
var rejected = (value) => {
|
|
32
|
-
try {
|
|
33
|
-
step(generator.throw(value));
|
|
34
|
-
} catch (e) {
|
|
35
|
-
reject(e);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
39
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// src/index.ts
|
|
44
|
-
var index_exports = {};
|
|
45
|
-
__export(index_exports, {
|
|
46
|
-
Loader: () => Loader,
|
|
47
|
-
NestDataLoader: () => NestDataLoader,
|
|
48
|
-
NestDataLoaderInterceptor: () => NestDataLoaderInterceptor
|
|
49
|
-
});
|
|
50
|
-
module.exports = __toCommonJS(index_exports);
|
|
51
|
-
|
|
52
|
-
// src/loader.decorator.ts
|
|
53
|
-
var import_common2 = require("@nestjs/common");
|
|
54
|
-
var import_core2 = require("@nestjs/core");
|
|
55
|
-
var import_graphql2 = require("@nestjs/graphql");
|
|
56
|
-
|
|
57
|
-
// src/constants.ts
|
|
58
|
-
var NEST_LOADER_CONTEXT_KEY = "NEST_LOADER_CONTEXT_KEY";
|
|
59
|
-
|
|
60
|
-
// src/nest-loader.interceptor.ts
|
|
61
|
-
var import_common = require("@nestjs/common");
|
|
62
|
-
var import_core = require("@nestjs/core");
|
|
63
|
-
var import_graphql = require("@nestjs/graphql");
|
|
64
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
65
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
66
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
67
|
-
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;
|
|
68
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
69
|
-
}
|
|
70
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
71
|
-
function _ts_metadata(k, v) {
|
|
72
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
73
|
-
}
|
|
74
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
75
|
-
var _NestDataLoaderInterceptor = class _NestDataLoaderInterceptor {
|
|
76
|
-
constructor(moduleRef) {
|
|
77
|
-
__publicField(this, "moduleRef");
|
|
78
|
-
this.moduleRef = moduleRef;
|
|
79
|
-
}
|
|
80
|
-
intercept(context, next) {
|
|
81
|
-
const gqlExecutionContext = import_graphql.GqlExecutionContext.create(context);
|
|
82
|
-
const injectionContext = gqlExecutionContext.getContext();
|
|
83
|
-
if (injectionContext[NEST_LOADER_CONTEXT_KEY] === void 0) {
|
|
84
|
-
injectionContext[NEST_LOADER_CONTEXT_KEY] = {
|
|
85
|
-
contextId: import_core.ContextIdFactory.create(),
|
|
86
|
-
getLoader: this.getLoader.bind(this, injectionContext)
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
return next.handle();
|
|
90
|
-
}
|
|
91
|
-
getLoader(injectionContext, type) {
|
|
92
|
-
return __async(this, null, function* () {
|
|
93
|
-
var _a;
|
|
94
|
-
if (injectionContext[type] === void 0) {
|
|
95
|
-
yield this.moduleRef.resolve(type, (_a = injectionContext[NEST_LOADER_CONTEXT_KEY]) == null ? void 0 : _a.contextId, {
|
|
96
|
-
strict: false
|
|
97
|
-
}).then((nestLoader) => {
|
|
98
|
-
injectionContext[type] = nestLoader.generateDataLoader();
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return injectionContext[type];
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
__name(_NestDataLoaderInterceptor, "NestDataLoaderInterceptor");
|
|
106
|
-
var NestDataLoaderInterceptor = _NestDataLoaderInterceptor;
|
|
107
|
-
NestDataLoaderInterceptor = _ts_decorate([
|
|
108
|
-
(0, import_common.Injectable)(),
|
|
109
|
-
_ts_metadata("design:type", Function),
|
|
110
|
-
_ts_metadata("design:paramtypes", [
|
|
111
|
-
typeof import_core.ModuleRef === "undefined" ? Object : import_core.ModuleRef
|
|
112
|
-
])
|
|
113
|
-
], NestDataLoaderInterceptor);
|
|
114
|
-
|
|
115
|
-
// src/loader.decorator.ts
|
|
116
|
-
var Loader = (0, import_common2.createParamDecorator)((data, context) => __async(null, null, function* () {
|
|
117
|
-
const gqlExecutionContext = import_graphql2.GqlExecutionContext.create(context);
|
|
118
|
-
const injectionContext = gqlExecutionContext.getContext();
|
|
119
|
-
const loaderContext = injectionContext[NEST_LOADER_CONTEXT_KEY];
|
|
120
|
-
if (loaderContext !== void 0) return loaderContext.getLoader(data);
|
|
121
|
-
throw new import_common2.InternalServerErrorException(`You should provide interceptor ${NestDataLoaderInterceptor.name} globally with ${import_core2.APP_INTERCEPTOR}`);
|
|
122
|
-
}));
|
|
123
|
-
|
|
124
|
-
// src/nest-dataloader.ts
|
|
125
|
-
var _NestDataLoader = class _NestDataLoader {
|
|
126
|
-
};
|
|
127
|
-
__name(_NestDataLoader, "NestDataLoader");
|
|
128
|
-
var NestDataLoader = _NestDataLoader;
|
|
129
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
130
|
-
0 && (module.exports = {
|
|
131
|
-
Loader,
|
|
132
|
-
NestDataLoader,
|
|
133
|
-
NestDataLoaderInterceptor
|
|
134
|
-
});
|