@wisemen/nestjs-typeorm 0.0.18 → 0.0.20

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.
@@ -1,5 +1,7 @@
1
+ import { ValueTransformer } from 'typeorm';
1
2
  import { ColumnEmbeddedOptions } from 'typeorm/decorator/options/ColumnEmbeddedOptions.js';
2
3
  export interface EmbeddedColumnOptions extends ColumnEmbeddedOptions {
3
4
  nullable?: boolean;
5
+ transformer?: ValueTransformer;
4
6
  }
5
7
  export declare function EmbeddedColumn(embeddedClass: Function, options?: EmbeddedColumnOptions): PropertyDecorator;
@@ -1,15 +1,20 @@
1
1
  import { applyDecorators } from '@nestjs/common';
2
2
  import { Column } from 'typeorm';
3
3
  import { TransformNullableEmbedded } from './transform-nullable-embedded.js';
4
+ import { TransformEmbedded } from './transform-embedded.js';
4
5
  export function EmbeddedColumn(
5
6
  // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
6
7
  embeddedClass, options) {
7
- const { nullable = false, ...otherOptions } = options ?? {};
8
+ const { nullable = false, transformer, ...otherOptions } = options ?? {};
9
+ const decorators = [
10
+ Column(() => embeddedClass, otherOptions)
11
+ ];
8
12
  if (nullable === true) {
9
- return Column(() => embeddedClass, otherOptions);
13
+ decorators.push(TransformNullableEmbedded());
10
14
  }
11
- else {
12
- return applyDecorators(Column(() => embeddedClass, otherOptions), TransformNullableEmbedded());
15
+ if (transformer !== undefined) {
16
+ decorators.push(TransformEmbedded(transformer));
13
17
  }
18
+ return applyDecorators(...decorators);
14
19
  }
15
20
  //# sourceMappingURL=embedded-column.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"embedded-column.js","sourceRoot":"","sources":["../../lib/columns/embedded-column.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEhC,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAk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;IAED,OAAO,eAAe,CAAC,GAAG,UAAU,CAAC,CAAA;AACvC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { ValueTransformer } from 'typeorm';
2
+ export declare function TransformEmbedded(transformer: ValueTransformer): PropertyDecorator;
@@ -0,0 +1,28 @@
1
+ // eslint-disable-next-line @stylistic/max-len
2
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-function-type */
3
+ import { AfterLoad, AfterInsert, AfterUpdate, BeforeInsert, BeforeUpdate } from 'typeorm';
4
+ export function TransformEmbedded(transformer) {
5
+ return (target, propertyKey) => {
6
+ const transformFrom = function () {
7
+ this[propertyKey] = transformer.from(this[propertyKey]);
8
+ };
9
+ const transformFromMethodName = `__transform_from_${propertyKey.toString()}`;
10
+ target[transformFromMethodName] = transformFrom;
11
+ const afterLoadDecorator = AfterLoad();
12
+ afterLoadDecorator(target, transformFromMethodName);
13
+ const afterInsertDecorator = AfterInsert();
14
+ afterInsertDecorator(target, transformFromMethodName);
15
+ const afterUpdateDecorator = AfterUpdate();
16
+ afterUpdateDecorator(target, transformFromMethodName);
17
+ const transformTo = function () {
18
+ this[propertyKey] = transformer.to(this[propertyKey]);
19
+ };
20
+ const transformToMethodNamee = `__transform_to_${propertyKey.toString()}`;
21
+ target[transformToMethodNamee] = transformTo;
22
+ const beforeInsertDecorator = BeforeInsert();
23
+ beforeInsertDecorator(target, transformToMethodNamee);
24
+ const beforeUpdateDecorator = BeforeUpdate();
25
+ beforeUpdateDecorator(target, transformToMethodNamee);
26
+ };
27
+ }
28
+ //# sourceMappingURL=transform-embedded.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-embedded.js","sourceRoot":"","sources":["../../lib/columns/transform-embedded.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,wGAAwG;AACxG,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAoB,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3G,MAA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0.20",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",