@ainias42/typeorm-helper 0.0.5 → 0.0.7
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/.prettierrc +1 -1
- package/dist/BaseModel.d.ts +3 -6
- package/dist/BaseModel.js +4 -18
- package/dist/BaseModel.js.map +1 -1
- package/dist/BaseModelWithoutVersion.d.ts +6 -0
- package/dist/BaseModelWithoutVersion.js +40 -0
- package/dist/BaseModelWithoutVersion.js.map +1 -0
- package/dist/DbNamingStrategy.d.ts +2 -2
- package/dist/DbNamingStrategy.js +9 -9
- package/dist/DbNamingStrategy.js.map +1 -1
- package/dist/DefaultSubscriber.d.ts +2 -2
- package/dist/DefaultSubscriber.js +7 -7
- package/dist/DefaultSubscriber.js.map +1 -1
- package/dist/dataSource/dataSource.d.ts +2 -2
- package/dist/dataSource/dataSource.js +1 -1
- package/dist/dataSource/getRepository.d.ts +3 -3
- package/dist/decorators/FileColumn/FileColumn.js +5 -5
- package/dist/decorators/FileColumn/FileTransformer.d.ts +1 -1
- package/dist/decorators/FileColumn/FileWriter.js +5 -2
- package/dist/decorators/FileColumn/FileWriter.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/migration/getCreateTableColumns.js +15 -9
- package/dist/migration/getCreateTableColumns.js.map +1 -1
- package/dist/migration/getCreateTableColumnsV1.js +12 -6
- package/dist/migration/getCreateTableColumnsV1.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.js +3 -0
- package/package.json +36 -32
- package/src/BaseModel.ts +4 -15
- package/src/BaseModelWithoutVersion.ts +16 -0
- package/src/DbNamingStrategy.ts +17 -35
- package/src/DefaultSubscriber.ts +33 -29
- package/src/dataSource/dataSource.ts +3 -3
- package/src/dataSource/getRepository.ts +4 -4
- package/src/decorators/FileColumn/FileColumn.ts +9 -9
- package/src/decorators/FileColumn/FileTransformer.ts +6 -6
- package/src/decorators/FileColumn/FileType.ts +4 -4
- package/src/decorators/FileColumn/FileWriter.ts +8 -6
- package/src/index.ts +1 -0
- package/src/migration/getCreateTableColumns.ts +33 -27
- package/src/migration/getCreateTableColumnsV1.ts +30 -24
- package/stylelint.config.mjs +4 -0
- package/tsconfig.json +2 -11
- package/.eslintrc.cjs +0 -3
package/eslint.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
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
|
-
|
|
2
|
+
"name": "@ainias42/typeorm-helper",
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"description": "",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
14
|
+
"build": "ctix build && tsc && tsc-alias",
|
|
15
|
+
"lint:noCache": "eslint \"src/{**/*,*}.{js,jsx,tsx,ts}\" --max-warnings 0",
|
|
16
|
+
"lint": "npm run lint:noCache -- --cache",
|
|
17
|
+
"lint:fix": "npm run lint -- --fix",
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"prettier": "npm run prettier:list -- --write",
|
|
20
|
+
"prettier:list": "prettier --list-different \"src/**/*.{ts,tsx,js,jsx,json}\"",
|
|
21
|
+
"stylelint": "stylelint --allow-empty-input \"src/**/*.{css,scss}\"",
|
|
22
|
+
"stylelint:fix": "npm run stylelint -- --fix"
|
|
23
|
+
},
|
|
24
|
+
"author": "",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "gitea@git.silas.link:Ainias/libraries.git"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@ainias42/config": "*",
|
|
31
|
+
"@ainias42/js-helper": ">=0.8.19",
|
|
32
|
+
"typeorm": "^0.3.20",
|
|
33
|
+
"reflect-metadata": "^0.2.2"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"prettier": "^3.3.3"
|
|
37
|
+
}
|
|
34
38
|
}
|
package/src/BaseModel.ts
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export class BaseModel {
|
|
4
|
-
@PrimaryGeneratedColumn()
|
|
5
|
-
id: number = -1;
|
|
6
|
-
|
|
7
|
-
@CreateDateColumn()
|
|
8
|
-
createdAt?: Date;
|
|
9
|
-
|
|
10
|
-
@UpdateDateColumn()
|
|
11
|
-
updatedAt?: Date;
|
|
12
|
-
|
|
13
|
-
@DeleteDateColumn()
|
|
14
|
-
deletedAt?: Date;
|
|
1
|
+
import { BaseModelWithoutVersion } from '@/BaseModelWithoutVersion';
|
|
2
|
+
import { VersionColumn } from 'typeorm';
|
|
15
3
|
|
|
4
|
+
export class BaseModel extends BaseModelWithoutVersion {
|
|
16
5
|
@VersionColumn()
|
|
17
|
-
version
|
|
6
|
+
version: number = 0;
|
|
18
7
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CreateDateColumn, DeleteDateColumn, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
|
|
2
|
+
import { DateHelper } from '@ainias42/js-helper';
|
|
3
|
+
|
|
4
|
+
export class BaseModelWithoutVersion {
|
|
5
|
+
@PrimaryGeneratedColumn()
|
|
6
|
+
id: number = -1;
|
|
7
|
+
|
|
8
|
+
@CreateDateColumn()
|
|
9
|
+
createdAt: Date = DateHelper.newDate();
|
|
10
|
+
|
|
11
|
+
@UpdateDateColumn()
|
|
12
|
+
updatedAt: Date = DateHelper.newDate();
|
|
13
|
+
|
|
14
|
+
@DeleteDateColumn()
|
|
15
|
+
deletedAt: Date | null = null;
|
|
16
|
+
}
|
package/src/DbNamingStrategy.ts
CHANGED
|
@@ -1,63 +1,45 @@
|
|
|
1
|
-
import { DefaultNamingStrategy } from
|
|
2
|
-
import type { NamingStrategyInterface, Table } from
|
|
1
|
+
import { DefaultNamingStrategy } from 'typeorm';
|
|
2
|
+
import type { NamingStrategyInterface, Table } from 'typeorm';
|
|
3
3
|
|
|
4
4
|
export class DbNamingStrategy extends DefaultNamingStrategy implements NamingStrategyInterface {
|
|
5
|
-
|
|
6
5
|
private createKey(prefix: string, tableOrName: Table | string, columnNames: string[], suffix?: string): string {
|
|
7
6
|
const clonedColumnNames = [...columnNames];
|
|
8
7
|
clonedColumnNames.sort();
|
|
9
8
|
const tableName = this.getTableName(tableOrName);
|
|
10
|
-
const replacedTableName = tableName.replace(
|
|
11
|
-
let key = `${prefix}_${replacedTableName}_${clonedColumnNames.join(
|
|
12
|
-
if (suffix){
|
|
9
|
+
const replacedTableName = tableName.replace('.', '_');
|
|
10
|
+
let key = `${prefix}_${replacedTableName}_${clonedColumnNames.join('_')}`;
|
|
11
|
+
if (suffix) {
|
|
13
12
|
key += `_${suffix}`;
|
|
14
13
|
}
|
|
15
14
|
return key;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
indexName(tableOrName: Table | string, columnNames: string[], where?: string): string {
|
|
19
|
-
return this.createKey(
|
|
18
|
+
return this.createKey('IDX', tableOrName, columnNames, where);
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
foreignKeyName(
|
|
23
|
-
|
|
24
|
-
columnNames: string[],
|
|
25
|
-
): string {
|
|
26
|
-
return this.createKey("FK", tableOrName, columnNames);
|
|
21
|
+
foreignKeyName(tableOrName: Table | string, columnNames: string[]): string {
|
|
22
|
+
return this.createKey('FK', tableOrName, columnNames);
|
|
27
23
|
}
|
|
28
24
|
|
|
29
|
-
uniqueConstraintName(
|
|
30
|
-
tableOrName: Table | string,
|
|
31
|
-
columnNames: string[],
|
|
32
|
-
): string {
|
|
25
|
+
uniqueConstraintName(tableOrName: Table | string, columnNames: string[]): string {
|
|
33
26
|
// There is a bug in the cli. They use the indexName method to generate unique constraint names
|
|
34
|
-
return this.createKey(
|
|
27
|
+
return this.createKey('IDX', tableOrName, columnNames);
|
|
35
28
|
}
|
|
36
29
|
|
|
37
30
|
primaryKeyName(tableOrName: Table | string, columnNames: string[]): string {
|
|
38
|
-
return this.createKey(
|
|
31
|
+
return this.createKey('PK', tableOrName, columnNames);
|
|
39
32
|
}
|
|
40
33
|
|
|
41
|
-
relationConstraintName(
|
|
42
|
-
|
|
43
|
-
columnNames: string[],
|
|
44
|
-
where?: string,
|
|
45
|
-
): string {
|
|
46
|
-
return this.createKey("REL", tableOrName, columnNames, where);
|
|
34
|
+
relationConstraintName(tableOrName: Table | string, columnNames: string[], where?: string): string {
|
|
35
|
+
return this.createKey('REL', tableOrName, columnNames, where);
|
|
47
36
|
}
|
|
48
37
|
|
|
49
|
-
checkConstraintName(
|
|
50
|
-
tableOrName
|
|
51
|
-
expression: string,
|
|
52
|
-
isEnum?: boolean,
|
|
53
|
-
): string {
|
|
54
|
-
return this.createKey("CHK", tableOrName, [expression], isEnum ? "ENUM" : undefined);
|
|
38
|
+
checkConstraintName(tableOrName: Table | string, expression: string, isEnum?: boolean): string {
|
|
39
|
+
return this.createKey('CHK', tableOrName, [expression], isEnum ? 'ENUM' : undefined);
|
|
55
40
|
}
|
|
56
41
|
|
|
57
|
-
exclusionConstraintName(
|
|
58
|
-
|
|
59
|
-
expression: string,
|
|
60
|
-
): string {
|
|
61
|
-
return this.createKey("XCL", tableOrName, [expression]);
|
|
42
|
+
exclusionConstraintName(tableOrName: Table | string, expression: string): string {
|
|
43
|
+
return this.createKey('XCL', tableOrName, [expression]);
|
|
62
44
|
}
|
|
63
45
|
}
|
package/src/DefaultSubscriber.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
/* eslint-disable class-methods-use-this */
|
|
2
|
-
import { ColumnMetadata } from
|
|
2
|
+
import { ColumnMetadata } from 'typeorm/metadata/ColumnMetadata';
|
|
3
3
|
import {
|
|
4
4
|
EntitySubscriberInterface,
|
|
5
5
|
EventSubscriber,
|
|
6
6
|
InsertEvent,
|
|
7
7
|
ObjectLiteral,
|
|
8
8
|
OptimisticLockVersionMismatchError,
|
|
9
|
-
UpdateEvent
|
|
10
|
-
} from
|
|
11
|
-
import { FileTransformer } from
|
|
12
|
-
import { FileType } from
|
|
13
|
-
import { FileWriter } from
|
|
9
|
+
UpdateEvent,
|
|
10
|
+
} from 'typeorm';
|
|
11
|
+
import { FileTransformer } from '@/decorators/FileColumn/FileTransformer';
|
|
12
|
+
import { FileType } from '@/decorators/FileColumn/FileType';
|
|
13
|
+
import { FileWriter } from '@/decorators/FileColumn/FileWriter';
|
|
14
14
|
|
|
15
15
|
@EventSubscriber()
|
|
16
16
|
export class DefaultSubscriber implements EntitySubscriberInterface {
|
|
17
|
-
|
|
18
17
|
async saveFiles(entity: ObjectLiteral, columns: ColumnMetadata[]) {
|
|
19
18
|
const promises = [];
|
|
20
19
|
for (const column of columns) {
|
|
@@ -27,15 +26,23 @@ export class DefaultSubscriber implements EntitySubscriberInterface {
|
|
|
27
26
|
values = [values];
|
|
28
27
|
single = true;
|
|
29
28
|
}
|
|
30
|
-
promises.push(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
promises.push(
|
|
30
|
+
Promise.all(
|
|
31
|
+
values.map((value) =>
|
|
32
|
+
FileWriter.writeToFile(value.src, transformer.fileOptions.saveDirectory).then(
|
|
33
|
+
(newUrl) => {
|
|
34
|
+
return { ...value, src: newUrl };
|
|
35
|
+
},
|
|
36
|
+
),
|
|
37
|
+
),
|
|
38
|
+
).then((newValues) => {
|
|
39
|
+
if (single) {
|
|
40
|
+
Reflect.set(entity, column.propertyName, newValues[0]);
|
|
41
|
+
} else {
|
|
42
|
+
Reflect.set(entity, column.propertyName, newValues);
|
|
43
|
+
}
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
39
46
|
}
|
|
40
47
|
}
|
|
41
48
|
}
|
|
@@ -45,12 +52,12 @@ export class DefaultSubscriber implements EntitySubscriberInterface {
|
|
|
45
52
|
/**
|
|
46
53
|
* Called before post insertion.
|
|
47
54
|
*/
|
|
48
|
-
async beforeInsert({entity, metadata: {columns}}: InsertEvent<any>) {
|
|
55
|
+
async beforeInsert({ entity, metadata: { columns } }: InsertEvent<any>) {
|
|
49
56
|
if (entity) {
|
|
50
|
-
Reflect.set(entity,
|
|
51
|
-
Reflect.set(entity,
|
|
52
|
-
if (Reflect.get(entity,
|
|
53
|
-
Reflect.set(entity,
|
|
57
|
+
Reflect.set(entity, 'updatedAt', new Date());
|
|
58
|
+
Reflect.set(entity, 'createdAt', new Date());
|
|
59
|
+
if (Reflect.get(entity, 'id') <= 0) {
|
|
60
|
+
Reflect.set(entity, 'id', undefined);
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
await this.saveFiles(entity, columns);
|
|
@@ -65,10 +72,7 @@ export class DefaultSubscriber implements EntitySubscriberInterface {
|
|
|
65
72
|
// is defined in the metadatas of that entity.
|
|
66
73
|
if (event.metadata.versionColumn && event.entity && event.databaseEntity) {
|
|
67
74
|
// Getting the current version of the requested entity update
|
|
68
|
-
const versionFromUpdate = Reflect.get(
|
|
69
|
-
event.entity,
|
|
70
|
-
event.metadata.versionColumn.propertyName
|
|
71
|
-
);
|
|
75
|
+
const versionFromUpdate = Reflect.get(event.entity, event.metadata.versionColumn.propertyName);
|
|
72
76
|
|
|
73
77
|
// Getting the entity's version from the database
|
|
74
78
|
const versionFromDatabase = event.databaseEntity[event.metadata.versionColumn.propertyName];
|
|
@@ -78,17 +82,17 @@ export class DefaultSubscriber implements EntitySubscriberInterface {
|
|
|
78
82
|
throw new OptimisticLockVersionMismatchError(
|
|
79
83
|
event.metadata.name,
|
|
80
84
|
versionFromDatabase,
|
|
81
|
-
versionFromUpdate
|
|
85
|
+
versionFromUpdate,
|
|
82
86
|
);
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
if (event.entity) {
|
|
87
|
-
Reflect.set(event.entity,
|
|
91
|
+
Reflect.set(event.entity, 'updatedAt', new Date());
|
|
88
92
|
}
|
|
89
93
|
|
|
90
|
-
const {columns} = event.metadata;
|
|
91
|
-
const {entity} = event;
|
|
94
|
+
const { columns } = event.metadata;
|
|
95
|
+
const { entity } = event;
|
|
92
96
|
if (entity) {
|
|
93
97
|
await this.saveFiles(entity, columns);
|
|
94
98
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DataSource } from
|
|
2
|
-
import type { DataSourceOptions } from
|
|
1
|
+
import { DataSource } from 'typeorm';
|
|
2
|
+
import type { DataSourceOptions } from 'typeorm/data-source/DataSourceOptions';
|
|
3
3
|
|
|
4
4
|
let dataSource: DataSource | undefined;
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@ export async function initDataSource(options: DataSourceOptions) {
|
|
|
10
10
|
|
|
11
11
|
export function getDataSource() {
|
|
12
12
|
if (!dataSource || !dataSource.isInitialized) {
|
|
13
|
-
throw new Error(
|
|
13
|
+
throw new Error('Data source is not initialized');
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
return dataSource;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getDataSource } from
|
|
2
|
-
import type { EntityTarget } from
|
|
3
|
-
import type { ObjectLiteral } from
|
|
4
|
-
import type { Repository } from
|
|
1
|
+
import { getDataSource } from '@/dataSource/dataSource';
|
|
2
|
+
import type { EntityTarget } from 'typeorm/common/EntityTarget';
|
|
3
|
+
import type { ObjectLiteral } from 'typeorm/common/ObjectLiteral';
|
|
4
|
+
import type { Repository } from 'typeorm';
|
|
5
5
|
|
|
6
6
|
export function getRepository<Entity extends ObjectLiteral>(entity: EntityTarget<Entity>): Repository<Entity> {
|
|
7
7
|
return getDataSource().getRepository<Entity>(entity);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { getMetadataArgsStorage } from
|
|
2
|
-
import type { ColumnMetadataArgs } from
|
|
3
|
-
import type { FileType } from
|
|
1
|
+
import { getMetadataArgsStorage } from 'typeorm';
|
|
2
|
+
import type { ColumnMetadataArgs } from 'typeorm/metadata-args/ColumnMetadataArgs';
|
|
3
|
+
import type { FileType } from '@/decorators/FileColumn/FileType';
|
|
4
4
|
|
|
5
|
-
export function FileColumn(options: { saveDirectory: string
|
|
5
|
+
export function FileColumn(options: { saveDirectory: string; publicPath: string }) {
|
|
6
6
|
return function decorator(object: any, propertyName: string) {
|
|
7
7
|
getMetadataArgsStorage().columns.push({
|
|
8
8
|
target: object.constructor,
|
|
9
9
|
propertyName,
|
|
10
|
-
mode:
|
|
10
|
+
mode: 'regular',
|
|
11
11
|
options: {
|
|
12
|
-
type:
|
|
12
|
+
type: 'json',
|
|
13
13
|
isFile: true,
|
|
14
14
|
nullable: true,
|
|
15
15
|
transformer: {
|
|
@@ -41,7 +41,7 @@ export function FileColumn(options: { saveDirectory: string, publicPath: string
|
|
|
41
41
|
single = true;
|
|
42
42
|
}
|
|
43
43
|
for (const value of values) {
|
|
44
|
-
if (!value.src.startsWith(
|
|
44
|
+
if (!value.src.startsWith('data:')) {
|
|
45
45
|
value.src = options.publicPath + value.src;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -50,8 +50,8 @@ export function FileColumn(options: { saveDirectory: string, publicPath: string
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
return values;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
55
|
},
|
|
56
56
|
} as ColumnMetadataArgs);
|
|
57
57
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { FileType } from
|
|
1
|
+
import type { FileType } from '@/decorators/FileColumn/FileType';
|
|
2
2
|
|
|
3
3
|
export type FileTransformer = {
|
|
4
|
-
isFile: true
|
|
5
|
-
fileOptions: { saveDirectory: string
|
|
6
|
-
to: (value: FileType) => FileType
|
|
7
|
-
from: (value: FileType) => FileType
|
|
8
|
-
}
|
|
4
|
+
isFile: true;
|
|
5
|
+
fileOptions: { saveDirectory: string; publicPath: string };
|
|
6
|
+
to: (value: FileType) => FileType;
|
|
7
|
+
from: (value: FileType) => FileType;
|
|
8
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type FileType = {
|
|
2
|
-
name: string
|
|
3
|
-
src: string
|
|
4
|
-
type: string
|
|
5
|
-
}
|
|
2
|
+
name: string;
|
|
3
|
+
src: string;
|
|
4
|
+
type: string;
|
|
5
|
+
};
|
|
@@ -2,7 +2,6 @@ import { PassThrough, Readable } from 'stream';
|
|
|
2
2
|
import { createWriteStream, existsSync, mkdirSync } from 'fs';
|
|
3
3
|
import crypto from 'crypto';
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
export const FileWriter = {
|
|
7
6
|
async writeToFile(src: string, saveDirectory: string) {
|
|
8
7
|
const base64SearchText = ';base64,';
|
|
@@ -18,28 +17,31 @@ export const FileWriter = {
|
|
|
18
17
|
const fileEnding = src.slice(indexSlash + 1, indexBase64SearchText);
|
|
19
18
|
const data = src.slice(Math.max(0, indexBase64SearchText + base64SearchText.length));
|
|
20
19
|
|
|
21
|
-
const seed = crypto.randomBytes(20);
|
|
20
|
+
const seed = crypto.randomBytes(20) as string | NodeJS.ArrayBufferView;
|
|
22
21
|
const now = new Date();
|
|
23
22
|
|
|
24
23
|
// Month is 0-based. Add 1 to get 1-12
|
|
25
|
-
const name = `${now.getUTCFullYear()}-${now.getUTCMonth() + 1}-${now.getUTCDate()}-${fileType}-${crypto
|
|
24
|
+
const name = `${now.getUTCFullYear()}-${now.getUTCMonth() + 1}-${now.getUTCDate()}-${fileType}-${crypto
|
|
25
|
+
.createHash('sha1')
|
|
26
|
+
.update(seed)
|
|
27
|
+
.digest('hex')}.${fileEnding}`;
|
|
26
28
|
|
|
27
29
|
const dataBuffer = Buffer.from(data, 'base64');
|
|
28
30
|
const inputStream = new Readable();
|
|
29
31
|
const dataStream = new PassThrough();
|
|
30
32
|
|
|
31
33
|
if (!existsSync(saveDirectory)) {
|
|
32
|
-
mkdirSync(saveDirectory, {recursive: true});
|
|
34
|
+
mkdirSync(saveDirectory, { recursive: true });
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
const writeStream = createWriteStream(saveDirectory + name);
|
|
36
38
|
inputStream.pipe(dataStream);
|
|
37
39
|
|
|
38
40
|
inputStream.push(dataBuffer);
|
|
39
|
-
// eslint-disable-next-line unicorn/
|
|
41
|
+
// eslint-disable-next-line unicorn/prefer-single-call
|
|
40
42
|
inputStream.push(null);
|
|
41
43
|
|
|
42
|
-
const resultPromise = new Promise((r) => writeStream.addListener('finish', r));
|
|
44
|
+
const resultPromise = new Promise<void>((r) => writeStream.addListener('finish', r));
|
|
43
45
|
dataStream.pipe(writeStream);
|
|
44
46
|
await resultPromise;
|
|
45
47
|
return name;
|
package/src/index.ts
CHANGED
|
@@ -1,30 +1,36 @@
|
|
|
1
1
|
// Do not change the columns here. It is needed for migration, aka creation of the database
|
|
2
2
|
export function getCreateTableColumns() {
|
|
3
|
-
return [
|
|
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
|
-
|
|
3
|
+
return [
|
|
4
|
+
{
|
|
5
|
+
name: 'id',
|
|
6
|
+
type: 'int',
|
|
7
|
+
isPrimary: true,
|
|
8
|
+
isGenerated: true,
|
|
9
|
+
generationStrategy: 'increment',
|
|
10
|
+
isNullable: false,
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'createdAt',
|
|
14
|
+
type: 'datetime(6)',
|
|
15
|
+
isNullable: false,
|
|
16
|
+
default: 'CURRENT_TIMESTAMP(6)',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'updatedAt',
|
|
20
|
+
type: 'datetime(6)',
|
|
21
|
+
isNullable: false,
|
|
22
|
+
default: 'CURRENT_TIMESTAMP(6)',
|
|
23
|
+
onUpdate: 'CURRENT_TIMESTAMP(6)',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'deletedAt',
|
|
27
|
+
type: 'datetime(6)',
|
|
28
|
+
isNullable: true,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'version',
|
|
32
|
+
type: 'int',
|
|
33
|
+
isNullable: false,
|
|
34
|
+
},
|
|
35
|
+
] as const;
|
|
30
36
|
}
|
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
// Do not change the columns here. It is needed for migration, aka creation of the database
|
|
2
2
|
export function getCreateTableColumnsV1() {
|
|
3
|
-
return [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
3
|
+
return [
|
|
4
|
+
{
|
|
5
|
+
name: 'id',
|
|
6
|
+
type: 'int',
|
|
7
|
+
isPrimary: true,
|
|
8
|
+
isGenerated: true,
|
|
9
|
+
generationStrategy: 'increment',
|
|
10
|
+
isNullable: false,
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'createdAt',
|
|
14
|
+
type: 'datetime',
|
|
15
|
+
isNullable: false,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'updatedAt',
|
|
19
|
+
type: 'datetime',
|
|
20
|
+
isNullable: false,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'deletedAt',
|
|
24
|
+
type: 'datetime(6)',
|
|
25
|
+
isNullable: true,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'version',
|
|
29
|
+
type: 'int',
|
|
30
|
+
isNullable: false,
|
|
31
|
+
},
|
|
32
|
+
] as const;
|
|
27
33
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "@ainias42/
|
|
2
|
+
"extends": "@ainias42/config/tsconfig.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"jsx": "react",
|
|
5
5
|
"module": "commonjs",
|
|
@@ -23,14 +23,5 @@
|
|
|
23
23
|
"include": [
|
|
24
24
|
"src/**/*.tsx",
|
|
25
25
|
"src/**/*.ts"
|
|
26
|
-
]
|
|
27
|
-
"tsc-alias": {
|
|
28
|
-
"resolveFullPaths": true,
|
|
29
|
-
"replacers": {
|
|
30
|
-
"scssReplacer": {
|
|
31
|
-
"enabled": true,
|
|
32
|
-
"file": "../tscReplacers/scssReplacer.cjs"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
26
|
+
]
|
|
36
27
|
}
|
package/.eslintrc.cjs
DELETED