@atls/nestjs-dataloader 0.0.4 → 0.0.6

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/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Установка
2
+
3
+ ```bash
4
+ yarn add @atls/nestjs-dataloader
5
+ ```
6
+
7
+ # Использование
8
+
9
+ 1. Импортируйте DataLoaderModule в ваш модуль:
10
+
11
+ ```typescript
12
+ import { DataLoaderModule } from '@atls/nestjs-dataloader'
13
+
14
+ @Module({
15
+ imports: [DataLoaderModule],
16
+ })
17
+ export class AppModule {}
18
+ ```
19
+
20
+ 2. Создайте свой кастомный DataLoader:
21
+
22
+ ```typescript
23
+ import * as DataLoader from 'dataloader'
24
+ import { Injectable } from '@nestjs/common'
25
+ @Injectable()
26
+ export class MyDataLoader extends DataLoader<string, string> {
27
+ constructor() {
28
+ super(async (keys: string[]) => {
29
+ / Ваш код для загрузки данных пачками
30
+ })
31
+ }
32
+ }
33
+ ```
34
+
35
+ 3. Зарегистрируйте ваш DataLoader в провайдерах:
36
+
37
+ ```typescript
38
+ import { MyDataLoader } from './my-dataloader'
39
+
40
+ @Module({
41
+ providers: [MyDataLoader],
42
+ })
43
+ export class AppModule {}
44
+ ```
45
+
46
+ 4. Инжектируйте DataLoader в резолверы и сервисы:
47
+
48
+ ```typescript
49
+ import { MyDataLoader } from './my-dataloader'
50
+
51
+ @Injectable()
52
+ export class MyService {
53
+ constructor(private readonly dataLoader: MyDataLoader) {}
54
+
55
+ async getData(key: string) {
56
+ return this.dataLoader.load(key)
57
+ }
58
+ }
59
+ ```
@@ -0,0 +1 @@
1
+ export declare const GET_LOADER_CONTEXT_KEY: string;
@@ -0,0 +1,2 @@
1
+ export * from './order-result-by-key.decorator';
2
+ export * from './loader.decorator';
@@ -0,0 +1 @@
1
+ export declare const Loader: (type: string) => ParameterDecorator;
@@ -0,0 +1 @@
1
+ export declare const OrderResultByKey: (key?: string, defaultValue?: undefined) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
@@ -0,0 +1,3 @@
1
+ export * from './interceptors';
2
+ export * from './decorators';
3
+ export * from './interfaces';
@@ -0,0 +1,10 @@
1
+ import { CallHandler } from '@nestjs/common';
2
+ import { ExecutionContext } from '@nestjs/common';
3
+ import { NestInterceptor } from '@nestjs/common';
4
+ import { ModuleRef } from '@nestjs/core';
5
+ import { Observable } from 'rxjs';
6
+ export declare class DataLoaderInterceptor implements NestInterceptor {
7
+ private readonly moduleRef;
8
+ constructor(moduleRef: ModuleRef);
9
+ intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
10
+ }
@@ -0,0 +1 @@
1
+ export * from './data-loader.interceptor';
@@ -0,0 +1 @@
1
+ export * from './nest-dataloader.interfaces';
@@ -0,0 +1,4 @@
1
+ import DataLoader from 'dataloader';
2
+ export interface NestDataLoader {
3
+ generateDataLoader(): DataLoader<any, any>;
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atls/nestjs-dataloader",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "license": "BSD-3-Clause",
5
5
  "main": "dist/index.js",
6
6
  "files": [