@metapic/nestjs-utils 1.0.0 → 1.0.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/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/typeorm.d.ts +6 -0
- package/dist/typeorm.d.ts.map +1 -0
- package/dist/typeorm.js +49 -0
- package/dist/typeorm.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ColumnOptions, type PrimaryColumnOptions } from 'typeorm';
|
|
2
|
+
export declare const Column: (options?: ColumnOptions) => (target: object, propertyKey: string | symbol) => void;
|
|
3
|
+
export declare const PrimaryColumn: (options?: PrimaryColumnOptions) => (target: object, propertyKey: string | symbol) => void;
|
|
4
|
+
export declare const PrimaryBinaryUuidColumn: () => ReturnType<typeof PrimaryColumn>;
|
|
5
|
+
export declare const BinaryUuidColumn: (options: Omit<ColumnOptions, "type" | "length" | "generated" | "transformer">) => ReturnType<typeof Column>;
|
|
6
|
+
//# sourceMappingURL=typeorm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeorm.d.ts","sourceRoot":"","sources":["../src/typeorm.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,oBAAoB,EAAyB,MAAM,SAAS,CAAA;AAG9F,eAAO,MAAM,MAAM,GAAI,UAAU,aAAa,MACpC,QAAQ,MAAM,EAAE,aAAa,MAAM,GAAG,MAAM,SAGrD,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,UAAU,oBAAoB,MAClD,QAAQ,MAAM,EAAE,aAAa,MAAM,GAAG,MAAM,SAGrD,CAAA;AAED,eAAO,MAAM,uBAAuB,QAAO,UAAU,CAAC,OAAO,aAAa,CAQtE,CAAA;AAEJ,eAAO,MAAM,gBAAgB,GAC3B,SAAS,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,aAAa,CAAC,KAC5E,UAAU,CAAC,OAAO,MAAM,CAOvB,CAAA"}
|
package/dist/typeorm.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { snakeCase } from 'change-case';
|
|
2
|
+
import * as typeorm from 'typeorm';
|
|
3
|
+
import { parse, stringify, validate } from 'uuid';
|
|
4
|
+
export const Column = (options) => {
|
|
5
|
+
return (target, propertyKey) => {
|
|
6
|
+
typeorm.Column(Object.assign({ name: snakeCase(String(propertyKey)) }, options))(target, propertyKey);
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export const PrimaryColumn = (options) => {
|
|
10
|
+
return (target, propertyKey) => {
|
|
11
|
+
typeorm.PrimaryColumn(Object.assign({ name: snakeCase(String(propertyKey)) }, options))(target, propertyKey);
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export const PrimaryBinaryUuidColumn = () => PrimaryColumn({
|
|
15
|
+
type: 'binary',
|
|
16
|
+
length: 16,
|
|
17
|
+
generated: false,
|
|
18
|
+
transformer: uuidValueTransformer,
|
|
19
|
+
// Since MySQL cannot generate UUIDv7 natively, we disable automatic generation here.
|
|
20
|
+
// default: () => 'UUID_TO_BIN(UUID())',
|
|
21
|
+
});
|
|
22
|
+
export const BinaryUuidColumn = (options) => Column(Object.assign({ type: 'binary', length: 16, generated: false, transformer: uuidValueTransformer }, options));
|
|
23
|
+
/**
|
|
24
|
+
* Inspiration: https://github.com/typeorm/typeorm/issues/3187#issuecomment-2421286827
|
|
25
|
+
* More details: https://github.com/typeorm/typeorm/issues/10542
|
|
26
|
+
*/
|
|
27
|
+
class UuidValueTransformer {
|
|
28
|
+
to(uuid) {
|
|
29
|
+
if (!uuid) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return Buffer.from(parse(uuid));
|
|
33
|
+
}
|
|
34
|
+
from(bin) {
|
|
35
|
+
if (!bin) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
// Handle case where TypeORM passes a string representation as buffer
|
|
39
|
+
if (bin.length === 36) {
|
|
40
|
+
const str = bin.toString('utf8');
|
|
41
|
+
if (validate(str)) {
|
|
42
|
+
return str;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return stringify(bin);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const uuidValueTransformer = new UuidValueTransformer();
|
|
49
|
+
//# sourceMappingURL=typeorm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeorm.js","sourceRoot":"","sources":["../src/typeorm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAElC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AAEjD,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,OAAuB,EAAE,EAAE;IAChD,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,EAAE;QACtD,OAAO,CAAC,MAAM,iBAAG,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAK,OAAO,EAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;IAC3F,CAAC,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAA8B,EAAE,EAAE;IAC9D,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,EAAE;QACtD,OAAO,CAAC,aAAa,iBAAG,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAK,OAAO,EAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;IAClG,CAAC,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAqC,EAAE,CAC5E,aAAa,CAAC;IACZ,IAAI,EAAE,QAAQ;IACd,MAAM,EAAE,EAAE;IACV,SAAS,EAAE,KAAK;IAChB,WAAW,EAAE,oBAAoB;IACjC,qFAAqF;IACrF,wCAAwC;CACzC,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,OAA6E,EAClD,EAAE,CAC7B,MAAM,iBACJ,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,EAAE,EACV,SAAS,EAAE,KAAK,EAChB,WAAW,EAAE,oBAAoB,IAC9B,OAAO,EACV,CAAA;AAEJ;;;GAGG;AACH,MAAM,oBAAoB;IACjB,EAAE,CAAC,IAA+B;QACvC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,IAAI,CAAA;QACb,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IACjC,CAAC;IAEM,IAAI,CAAC,GAA8B;QACxC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO,IAAI,CAAA;QACb,CAAC;QAED,qEAAqE;QACrE,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACtB,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;YAChC,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBAClB,OAAO,GAAG,CAAA;YACZ,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC,GAAG,CAAC,CAAA;IACvB,CAAC;CACF;AAED,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metapic/nestjs-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Utilities and helpers for Nest.js + TypeORM.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./dist/index.js",
|
|
8
|
-
"./swagger": "./dist/swagger.js"
|
|
8
|
+
"./swagger": "./dist/swagger.js",
|
|
9
|
+
"./typeorm": "./dist/typeorm.js"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
11
12
|
"dist/**/*"
|