@russ-b/nestjs-common-tools 1.14.0 → 1.14.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/README.md +28 -9
- package/dist/class-transformer/index.d.ts +1 -1
- package/dist/class-transformer/index.js +1 -1
- package/dist/class-transformer/index.js.map +1 -1
- package/dist/class-transformer/to-boolean-from-string.decorator.d.ts +3 -0
- package/dist/class-transformer/{to-optional-boolean.decorator.js → to-boolean-from-string.decorator.js} +8 -8
- package/dist/class-transformer/to-boolean-from-string.decorator.js.map +1 -0
- package/package.json +1 -1
- package/dist/class-transformer/to-optional-boolean.decorator.d.ts +0 -3
- package/dist/class-transformer/to-optional-boolean.decorator.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# nestjs-common-tools
|
|
2
|
-
NestJS Common Tools
|
|
3
2
|
|
|
4
3
|
A small toolbox for NestJS with helpers that often come up in day-to-day development.
|
|
5
4
|
|
|
@@ -15,9 +14,25 @@ npm install @russ-b/nestjs-common-tools
|
|
|
15
14
|
|
|
16
15
|
Depending on which features you use, make sure the relevant peer dependencies are also installed in your project.
|
|
17
16
|
|
|
17
|
+
## Public entrypoints
|
|
18
|
+
|
|
19
|
+
This package uses subpath exports for most features.
|
|
20
|
+
|
|
21
|
+
| Import path | What it contains |
|
|
22
|
+
|-------------|------------------|
|
|
23
|
+
| `@russ-b/nestjs-common-tools` | root exports such as `services` |
|
|
24
|
+
| `@russ-b/nestjs-common-tools/class-transformer` | reusable `class-transformer` decorators and helpers |
|
|
25
|
+
| `@russ-b/nestjs-common-tools/modules` | NestJS modules such as `S3Module` |
|
|
26
|
+
| `@russ-b/nestjs-common-tools/validators` | validation decorators and constraints |
|
|
27
|
+
| `@russ-b/nestjs-common-tools/typeorm` | TypeORM filters, helpers, transformers, and types |
|
|
28
|
+
| `@russ-b/nestjs-common-tools/logger` | logger builder and logger-related interfaces/types |
|
|
29
|
+
| `@russ-b/nestjs-common-tools/common/util` | generic utility helpers |
|
|
30
|
+
| `@russ-b/nestjs-common-tools/common/pagination` | pagination DTOs and helpers |
|
|
31
|
+
| `@russ-b/nestjs-common-tools/common/filters` | shared filter exports |
|
|
32
|
+
|
|
18
33
|
## Class Transformer Helpers
|
|
19
34
|
|
|
20
|
-
This package
|
|
35
|
+
This package also exposes small reusable decorators for `class-transformer`.
|
|
21
36
|
|
|
22
37
|
### `ToStringArray`
|
|
23
38
|
|
|
@@ -37,17 +52,17 @@ It will:
|
|
|
37
52
|
- split string values by comma
|
|
38
53
|
- trim extra spaces around items
|
|
39
54
|
- remove empty values
|
|
40
|
-
-
|
|
55
|
+
- normalize a string like `'cars, bikes, boats'` into `['cars', 'bikes', 'boats']`
|
|
41
56
|
|
|
42
|
-
### `
|
|
57
|
+
### `ToBooleanFromString`
|
|
43
58
|
|
|
44
|
-
`
|
|
59
|
+
`ToBooleanFromString()` is useful for DTO fields that may arrive as `'true'` or `'false'` strings and should become real booleans.
|
|
45
60
|
|
|
46
61
|
```typescript
|
|
47
|
-
import {
|
|
62
|
+
import { ToBooleanFromString } from '@russ-b/nestjs-common-tools/class-transformer';
|
|
48
63
|
|
|
49
64
|
export class SearchDto {
|
|
50
|
-
@
|
|
65
|
+
@ToBooleanFromString()
|
|
51
66
|
archived?: boolean;
|
|
52
67
|
}
|
|
53
68
|
```
|
|
@@ -94,7 +109,6 @@ import { S3Module } from '@russ-b/nestjs-common-tools/modules';
|
|
|
94
109
|
region: config.get<string>('AWS_REGION') ?? 'eu-central-1',
|
|
95
110
|
bucket: config.get<string>('S3_BUCKET'),
|
|
96
111
|
endpoint: config.get<string>('S3_ENDPOINT'),
|
|
97
|
-
forcePathStyle: config.get<string>('S3_FORCE_PATH_STYLE') === 'true',
|
|
98
112
|
logger: config.get<string>('S3_DEBUG') === 'true',
|
|
99
113
|
}),
|
|
100
114
|
}),
|
|
@@ -120,8 +134,12 @@ AWS_SECRET_ACCESS_KEY=your-secret-key
|
|
|
120
134
|
S3_BUCKET=my-app-bucket
|
|
121
135
|
```
|
|
122
136
|
|
|
137
|
+
The AWS SDK reads values from process environment, not directly from a `.env` file, so make sure your application loads those variables before creating the client.
|
|
138
|
+
|
|
123
139
|
`endpoint` is optional and is mostly useful for S3-compatible providers such as MinIO or LocalStack.
|
|
124
140
|
|
|
141
|
+
`forcePathStyle` defaults to `true` in this module. That is usually convenient for MinIO and LocalStack. If you want standard AWS virtual-hosted URLs, set `forcePathStyle: false`.
|
|
142
|
+
|
|
125
143
|
### Optional logging
|
|
126
144
|
|
|
127
145
|
By default, the module stays silent and does not write S3 operation logs.
|
|
@@ -239,7 +257,9 @@ A custom validator for NestJS that validates if an entity exists in the database
|
|
|
239
257
|
|
|
240
258
|
```typescript
|
|
241
259
|
// main.ts
|
|
260
|
+
import { NestFactory } from '@nestjs/core';
|
|
242
261
|
import { useContainer } from 'class-validator';
|
|
262
|
+
import { AppModule } from './app.module';
|
|
243
263
|
|
|
244
264
|
async function bootstrap() {
|
|
245
265
|
const app = await NestFactory.create(AppModule);
|
|
@@ -257,7 +277,6 @@ async function bootstrap() {
|
|
|
257
277
|
```typescript
|
|
258
278
|
// app.module.ts
|
|
259
279
|
import { Module } from '@nestjs/common';
|
|
260
|
-
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
261
280
|
import { EntityConstraint } from '@russ-b/nestjs-common-tools/validators';
|
|
262
281
|
|
|
263
282
|
@Module({
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './to-string-array.decorator';
|
|
2
|
-
export * from './to-
|
|
2
|
+
export * from './to-boolean-from-string.decorator';
|
|
@@ -15,5 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./to-string-array.decorator"), exports);
|
|
18
|
-
__exportStar(require("./to-
|
|
18
|
+
__exportStar(require("./to-boolean-from-string.decorator"), exports);
|
|
19
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/class-transformer/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C;AAC5C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/class-transformer/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C;AAC5C,qEAAmD"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.parseBooleanFromStringTransformer = void 0;
|
|
4
|
+
exports.ToBooleanFromString = ToBooleanFromString;
|
|
5
5
|
const class_transformer_1 = require("class-transformer");
|
|
6
|
-
function
|
|
7
|
-
return (0, class_transformer_1.Transform)(exports.
|
|
6
|
+
function ToBooleanFromString() {
|
|
7
|
+
return (0, class_transformer_1.Transform)(exports.parseBooleanFromStringTransformer);
|
|
8
8
|
}
|
|
9
|
-
const
|
|
10
|
-
exports.
|
|
11
|
-
function
|
|
9
|
+
const parseBooleanFromStringTransformer = ({ value, }) => normalizeBooleanFromString(value);
|
|
10
|
+
exports.parseBooleanFromStringTransformer = parseBooleanFromStringTransformer;
|
|
11
|
+
function normalizeBooleanFromString(value) {
|
|
12
12
|
if (value === undefined) {
|
|
13
13
|
return undefined;
|
|
14
14
|
}
|
|
@@ -26,4 +26,4 @@ function normalizeOptionalBoolean(value) {
|
|
|
26
26
|
}
|
|
27
27
|
return value;
|
|
28
28
|
}
|
|
29
|
-
//# sourceMappingURL=to-
|
|
29
|
+
//# sourceMappingURL=to-boolean-from-string.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-boolean-from-string.decorator.js","sourceRoot":"","sources":["../../src/class-transformer/to-boolean-from-string.decorator.ts"],"names":[],"mappings":";;;AAEA,kDAEC;AAJD,yDAAiE;AAEjE,SAAgB,mBAAmB;IACjC,OAAO,IAAA,6BAAS,EAAC,yCAAiC,CAAC,CAAC;AACtD,CAAC;AAEM,MAAM,iCAAiC,GAAG,CAAC,EAChD,KAAK,GACa,EAAW,EAAE,CAAC,0BAA0B,CAAC,KAAK,CAAC,CAAC;AAFvD,QAAA,iCAAiC,qCAEsB;AAEpE,SAAS,0BAA0B,CAAC,KAAc;IAChD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAEnD,IAAI,eAAe,KAAK,MAAM,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,eAAe,KAAK,OAAO,EAAE,CAAC;YAChC,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"to-optional-boolean.decorator.js","sourceRoot":"","sources":["../../src/class-transformer/to-optional-boolean.decorator.ts"],"names":[],"mappings":";;;AAEA,8CAEC;AAJD,yDAAiE;AAEjE,SAAgB,iBAAiB;IAC/B,OAAO,IAAA,6BAAS,EAAC,uCAA+B,CAAC,CAAC;AACpD,CAAC;AAEM,MAAM,+BAA+B,GAAG,CAAC,EAC9C,KAAK,GACa,EAAW,EAAE,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;AAFrD,QAAA,+BAA+B,mCAEsB;AAElE,SAAS,wBAAwB,CAAC,KAAc;IAC9C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAEnD,IAAI,eAAe,KAAK,MAAM,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,eAAe,KAAK,OAAO,EAAE,CAAC;YAChC,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|