purplekit 1.0.0
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 +103 -0
- package/bin/dataforge +2 -0
- package/build/src/app.d.ts +2 -0
- package/build/src/app.d.ts.map +1 -0
- package/build/src/app.js +63 -0
- package/build/src/app.js.map +1 -0
- package/build/src/config/constants.d.ts +8 -0
- package/build/src/config/constants.d.ts.map +1 -0
- package/build/src/config/constants.js +16 -0
- package/build/src/config/constants.js.map +1 -0
- package/build/src/config/index.d.ts +4 -0
- package/build/src/config/index.d.ts.map +1 -0
- package/build/src/config/index.js +79 -0
- package/build/src/config/index.js.map +1 -0
- package/build/src/features/createdb.d.ts +21 -0
- package/build/src/features/createdb.d.ts.map +1 -0
- package/build/src/features/createdb.js +80 -0
- package/build/src/features/createdb.js.map +1 -0
- package/build/src/features/dropdb.d.ts +18 -0
- package/build/src/features/dropdb.d.ts.map +1 -0
- package/build/src/features/dropdb.js +70 -0
- package/build/src/features/dropdb.js.map +1 -0
- package/build/src/features/gen.d.ts +84 -0
- package/build/src/features/gen.d.ts.map +1 -0
- package/build/src/features/gen.js +241 -0
- package/build/src/features/gen.js.map +1 -0
- package/build/src/features/index.d.ts +9 -0
- package/build/src/features/index.d.ts.map +1 -0
- package/build/src/features/index.js +20 -0
- package/build/src/features/index.js.map +1 -0
- package/build/src/features/init.d.ts +7 -0
- package/build/src/features/init.d.ts.map +1 -0
- package/build/src/features/init.js +118 -0
- package/build/src/features/init.js.map +1 -0
- package/build/src/features/migrate.d.ts +83 -0
- package/build/src/features/migrate.d.ts.map +1 -0
- package/build/src/features/migrate.js +331 -0
- package/build/src/features/migrate.js.map +1 -0
- package/build/src/features/migration.d.ts +28 -0
- package/build/src/features/migration.d.ts.map +1 -0
- package/build/src/features/migration.js +128 -0
- package/build/src/features/migration.js.map +1 -0
- package/build/src/features/seed.d.ts +9 -0
- package/build/src/features/seed.d.ts.map +1 -0
- package/build/src/features/seed.js +72 -0
- package/build/src/features/seed.js.map +1 -0
- package/build/src/features/status.d.ts +55 -0
- package/build/src/features/status.d.ts.map +1 -0
- package/build/src/features/status.js +229 -0
- package/build/src/features/status.js.map +1 -0
- package/build/src/index.d.ts +4 -0
- package/build/src/index.d.ts.map +1 -0
- package/build/src/index.js +15 -0
- package/build/src/index.js.map +1 -0
- package/build/src/libs/compare-mig.d.ts +27 -0
- package/build/src/libs/compare-mig.d.ts.map +1 -0
- package/build/src/libs/compare-mig.js +215 -0
- package/build/src/libs/compare-mig.js.map +1 -0
- package/build/src/libs/create-ds.d.ts +10 -0
- package/build/src/libs/create-ds.d.ts.map +1 -0
- package/build/src/libs/create-ds.js +56 -0
- package/build/src/libs/create-ds.js.map +1 -0
- package/build/src/libs/get-commands.d.ts +45 -0
- package/build/src/libs/get-commands.d.ts.map +1 -0
- package/build/src/libs/get-commands.js +128 -0
- package/build/src/libs/get-commands.js.map +1 -0
- package/build/src/libs/paths.d.ts +22 -0
- package/build/src/libs/paths.d.ts.map +1 -0
- package/build/src/libs/paths.js +37 -0
- package/build/src/libs/paths.js.map +1 -0
- package/build/src/libs/print.d.ts +5 -0
- package/build/src/libs/print.d.ts.map +1 -0
- package/build/src/libs/print.js +18 -0
- package/build/src/libs/print.js.map +1 -0
- package/build/src/libs/sanitize.d.ts +10 -0
- package/build/src/libs/sanitize.d.ts.map +1 -0
- package/build/src/libs/sanitize.js +19 -0
- package/build/src/libs/sanitize.js.map +1 -0
- package/build/src/libs/seed-entities.d.ts +13 -0
- package/build/src/libs/seed-entities.d.ts.map +1 -0
- package/build/src/libs/seed-entities.js +40 -0
- package/build/src/libs/seed-entities.js.map +1 -0
- package/build/src/types.d.ts +49 -0
- package/build/src/types.d.ts.map +1 -0
- package/build/src/types.js +3 -0
- package/build/src/types.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCheckMigrationCommand = exports.getCreateDbCommand = exports.getDropDbCommand = exports.getDbCheckCommand = exports.getDbTablesCommand = void 0;
|
|
4
|
+
const config_1 = require("../config");
|
|
5
|
+
/**
|
|
6
|
+
* Returns the SQL used to list user/base tables for the given DB type.
|
|
7
|
+
*
|
|
8
|
+
* @param type - Database driver type; defaults to `cfg.TYPE`.
|
|
9
|
+
* @returns Parameter-free SQL query string.
|
|
10
|
+
*/
|
|
11
|
+
const getDbTablesCommand = (type = config_1.cfg.TYPE) => {
|
|
12
|
+
switch (type) {
|
|
13
|
+
case 'postgres':
|
|
14
|
+
return `SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE'`;
|
|
15
|
+
case 'mysql':
|
|
16
|
+
case 'mariadb':
|
|
17
|
+
return `SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE() AND table_type = 'BASE TABLE'`;
|
|
18
|
+
case 'sqlite':
|
|
19
|
+
case 'better-sqlite3':
|
|
20
|
+
return `SELECT name FROM sqlite_master WHERE type = 'table'`;
|
|
21
|
+
case 'oracle':
|
|
22
|
+
return `SELECT table_name FROM user_tables`;
|
|
23
|
+
case 'mssql':
|
|
24
|
+
return `SELECT TABLE_NAME AS table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'`;
|
|
25
|
+
default:
|
|
26
|
+
throw new Error('Unsupported database type');
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.getDbTablesCommand = getDbTablesCommand;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the parameterized SQL used to check whether a database exists.
|
|
32
|
+
*
|
|
33
|
+
* @param type - Database driver type; defaults to `cfg.TYPE`.
|
|
34
|
+
* @returns Parameterized SQL query string.
|
|
35
|
+
* @throws When the type is unsupported (e.g. SQLite uses filesystem checks).
|
|
36
|
+
*/
|
|
37
|
+
const getDbCheckCommand = (type = config_1.cfg.TYPE) => {
|
|
38
|
+
switch (type) {
|
|
39
|
+
case 'postgres':
|
|
40
|
+
return 'SELECT 1 FROM pg_database WHERE DATNAME = $1';
|
|
41
|
+
case 'mysql':
|
|
42
|
+
case 'mariadb':
|
|
43
|
+
return 'SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ?';
|
|
44
|
+
case 'mssql':
|
|
45
|
+
return `SELECT name FROM sys.databases WHERE name = @0`;
|
|
46
|
+
case 'oracle':
|
|
47
|
+
return `SELECT username FROM all_users WHERE username = :1`;
|
|
48
|
+
case 'sqlite':
|
|
49
|
+
case 'better-sqlite3':
|
|
50
|
+
throw new Error('SQLite database existence should be checked via filesystem');
|
|
51
|
+
default:
|
|
52
|
+
throw new Error('Unsupported database type');
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
exports.getDbCheckCommand = getDbCheckCommand;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the SQL used to drop a database for the given DB type.
|
|
58
|
+
*
|
|
59
|
+
* @param name - Database name to drop.
|
|
60
|
+
* @param type - Database driver type; defaults to `cfg.TYPE`.
|
|
61
|
+
* @returns Parameterized or literal SQL query string.
|
|
62
|
+
* @throws When the type is unsupported.
|
|
63
|
+
*/
|
|
64
|
+
const getDropDbCommand = (name, type = config_1.cfg.TYPE) => {
|
|
65
|
+
switch (type) {
|
|
66
|
+
case 'mariadb':
|
|
67
|
+
case 'mysql':
|
|
68
|
+
return `DROP DATABASE IF EXISTS \`${name}\``;
|
|
69
|
+
case 'postgres':
|
|
70
|
+
return `DROP DATABASE IF EXISTS "${name}"`;
|
|
71
|
+
case 'mssql':
|
|
72
|
+
return `DROP DATABASE [${name}]`;
|
|
73
|
+
case 'oracle':
|
|
74
|
+
return `DROP USER "${name}" CASCADE`;
|
|
75
|
+
case 'better-sqlite3':
|
|
76
|
+
case 'sqlite':
|
|
77
|
+
throw new Error('SQLite databases should be dropped by deleting the file');
|
|
78
|
+
default:
|
|
79
|
+
throw new Error('Unsupported database type');
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
exports.getDropDbCommand = getDropDbCommand;
|
|
83
|
+
/**
|
|
84
|
+
* Returns the SQL used to create a database for the given DB type.
|
|
85
|
+
*
|
|
86
|
+
* @param name - Database name to create.
|
|
87
|
+
* @param type - Database driver type; defaults to `cfg.TYPE`.
|
|
88
|
+
* @returns Literal SQL query string for creating the database.
|
|
89
|
+
* @throws When the type is unsupported.
|
|
90
|
+
*/
|
|
91
|
+
const getCreateDbCommand = (name, type = config_1.cfg.TYPE) => {
|
|
92
|
+
switch (type) {
|
|
93
|
+
case 'postgres':
|
|
94
|
+
return `CREATE DATABASE "${name}"`;
|
|
95
|
+
case 'mysql':
|
|
96
|
+
case 'mariadb':
|
|
97
|
+
return `CREATE DATABASE \`${name}\``;
|
|
98
|
+
case 'mssql':
|
|
99
|
+
return `CREATE DATABASE [${name}]`;
|
|
100
|
+
case 'sqlite':
|
|
101
|
+
case 'better-sqlite3':
|
|
102
|
+
throw new Error('SQLite databases are created by opening/creating the file');
|
|
103
|
+
default:
|
|
104
|
+
throw new Error('Unsupported database type');
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
exports.getCreateDbCommand = getCreateDbCommand;
|
|
108
|
+
/**
|
|
109
|
+
* Returns the parameterized SQL used to check if a migration has been applied.
|
|
110
|
+
*
|
|
111
|
+
* @param type - Database driver type; defaults to `cfg.TYPE`.
|
|
112
|
+
* @returns Parameterized SQL query string for TypeORM's `migrations` table.
|
|
113
|
+
* @throws When the type is unsupported.
|
|
114
|
+
*/
|
|
115
|
+
const getCheckMigrationCommand = (type = config_1.cfg.TYPE) => {
|
|
116
|
+
switch (type) {
|
|
117
|
+
case 'postgres':
|
|
118
|
+
return `SELECT 1 FROM migrations WHERE name = $1 LIMIT 1`;
|
|
119
|
+
case 'mysql':
|
|
120
|
+
return `SELECT 1 FROM migrations WHERE name = ? LIMIT 1`;
|
|
121
|
+
case 'mssql':
|
|
122
|
+
return `SELECT TOP 1 1 FROM migrations WHERE name = @0`;
|
|
123
|
+
default:
|
|
124
|
+
throw new Error('Unsupported database type');
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
exports.getCheckMigrationCommand = getCheckMigrationCommand;
|
|
128
|
+
//# sourceMappingURL=get-commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-commands.js","sourceRoot":"","sources":["../../../src/libs/get-commands.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the opinionated migrations root used by Dataforge.
|
|
3
|
+
*
|
|
4
|
+
* @returns Configured migrations directory.
|
|
5
|
+
*/
|
|
6
|
+
declare function getMigrationRoot(): string;
|
|
7
|
+
/**
|
|
8
|
+
* Builds the canonical `migration.ts` path for a migration folder name.
|
|
9
|
+
*
|
|
10
|
+
* @param name - Timestamped migration folder/class name.
|
|
11
|
+
* @returns Path to that migration's `migration.ts` file.
|
|
12
|
+
*/
|
|
13
|
+
declare function getMigrationFile(name: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the file location where a generated migration should be saved.
|
|
16
|
+
*
|
|
17
|
+
* @param name - Timestamped migration folder/class name.
|
|
18
|
+
* @returns Generated migration file location.
|
|
19
|
+
*/
|
|
20
|
+
declare function getMigrationLocation(name: string): string;
|
|
21
|
+
export { getMigrationFile, getMigrationLocation, getMigrationRoot };
|
|
22
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../../src/libs/paths.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,iBAAS,gBAAgB,WAExB;AAED;;;;;GAKG;AACH,iBAAS,gBAAgB,CAAC,IAAI,EAAE,MAAM,UAErC;AAED;;;;;GAKG;AACH,iBAAS,oBAAoB,CAAC,IAAI,EAAE,MAAM,UAEzC;AAED,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getMigrationFile = getMigrationFile;
|
|
7
|
+
exports.getMigrationLocation = getMigrationLocation;
|
|
8
|
+
exports.getMigrationRoot = getMigrationRoot;
|
|
9
|
+
const config_1 = require("../config");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
/**
|
|
12
|
+
* Returns the opinionated migrations root used by Dataforge.
|
|
13
|
+
*
|
|
14
|
+
* @returns Configured migrations directory.
|
|
15
|
+
*/
|
|
16
|
+
function getMigrationRoot() {
|
|
17
|
+
return config_1.cfg.MIGRATIONS_DIR;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Builds the canonical `migration.ts` path for a migration folder name.
|
|
21
|
+
*
|
|
22
|
+
* @param name - Timestamped migration folder/class name.
|
|
23
|
+
* @returns Path to that migration's `migration.ts` file.
|
|
24
|
+
*/
|
|
25
|
+
function getMigrationFile(name) {
|
|
26
|
+
return path_1.default.join(getMigrationRoot(), name, 'migration.ts');
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the file location where a generated migration should be saved.
|
|
30
|
+
*
|
|
31
|
+
* @param name - Timestamped migration folder/class name.
|
|
32
|
+
* @returns Generated migration file location.
|
|
33
|
+
*/
|
|
34
|
+
function getMigrationLocation(name) {
|
|
35
|
+
return getMigrationFile(name);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../../src/libs/paths.ts"],"names":[],"mappings":";;;;;AAgCS,4CAAgB;AAAE,oDAAoB;AAAE,4CAAgB;AAhCjE,qCAA+B;AAC/B,gDAAwB;AAExB;;;;GAIG;AACH,SAAS,gBAAgB;IACvB,OAAO,YAAG,CAAC,cAAc,CAAC;AAC5B,CAAC;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,IAAY;IACpC,OAAO,cAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,IAAY;IACxC,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print.d.ts","sourceRoot":"","sources":["../../../src/libs/print.ts"],"names":[],"mappings":"AAEA,0CAA0C;AAC1C,eAAO,MAAM,KAAK,GAAI,GAAG,MAAM,MAAM,EAAE,SAEtC,CAAC;AAEF,0CAA0C;AAC1C,eAAO,MAAM,MAAM,GAAI,GAAG,MAAM,MAAM,EAAE,SAEvC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.printf = exports.print = void 0;
|
|
7
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
8
|
+
/** Logs a cyan info message to stdout. */
|
|
9
|
+
const print = (...args) => {
|
|
10
|
+
return console.log(picocolors_1.default.cyanBright(args.join(' ')));
|
|
11
|
+
};
|
|
12
|
+
exports.print = print;
|
|
13
|
+
/** Logs a red error message to stdout. */
|
|
14
|
+
const printf = (...args) => {
|
|
15
|
+
return console.log(picocolors_1.default.redBright(args.join(' ')));
|
|
16
|
+
};
|
|
17
|
+
exports.printf = printf;
|
|
18
|
+
//# sourceMappingURL=print.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print.js","sourceRoot":"","sources":["../../../src/libs/print.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA4B;AAE5B,0CAA0C;AACnC,MAAM,KAAK,GAAG,CAAC,GAAG,IAAc,EAAE,EAAE;IACzC,OAAO,OAAO,CAAC,GAAG,CAAC,oBAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC,CAAC;AAFW,QAAA,KAAK,SAEhB;AAEF,0CAA0C;AACnC,MAAM,MAAM,GAAG,CAAC,GAAG,IAAc,EAAE,EAAE;IAC1C,OAAO,OAAO,CAAC,GAAG,CAAC,oBAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC,CAAC;AAFW,QAAA,MAAM,UAEjB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates that `value` contains only letters, numbers, and underscores.
|
|
3
|
+
*
|
|
4
|
+
* @param value - String to validate.
|
|
5
|
+
* @returns The original value when valid.
|
|
6
|
+
* @throws When the value contains disallowed characters.
|
|
7
|
+
*/
|
|
8
|
+
declare const sanitize: (value: string) => string;
|
|
9
|
+
export { sanitize };
|
|
10
|
+
//# sourceMappingURL=sanitize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/libs/sanitize.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,QAAA,MAAM,QAAQ,GAAI,OAAO,MAAM,KAAG,MAKjC,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sanitize = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Validates that `value` contains only letters, numbers, and underscores.
|
|
6
|
+
*
|
|
7
|
+
* @param value - String to validate.
|
|
8
|
+
* @returns The original value when valid.
|
|
9
|
+
* @throws When the value contains disallowed characters.
|
|
10
|
+
*/
|
|
11
|
+
const sanitize = (value) => {
|
|
12
|
+
const regex = new RegExp('^[A-Za-z0-9_]+$');
|
|
13
|
+
const check = regex.test(value);
|
|
14
|
+
if (check)
|
|
15
|
+
return value;
|
|
16
|
+
throw new Error('Only numbers, letters and underscores allowed');
|
|
17
|
+
};
|
|
18
|
+
exports.sanitize = sanitize;
|
|
19
|
+
//# sourceMappingURL=sanitize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.js","sourceRoot":"","sources":["../../../src/libs/sanitize.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAU,EAAE;IACzC,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC;IACxB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;AACnE,CAAC,CAAC;AAEO,4BAAQ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DataSource, EntityTarget, ObjectLiteral } from 'typeorm';
|
|
2
|
+
/**
|
|
3
|
+
* Inserts seed records for an entity while skipping records that already exist.
|
|
4
|
+
* Existing records are detected by the `id` field.
|
|
5
|
+
*
|
|
6
|
+
* @param ds - Initialized TypeORM data source.
|
|
7
|
+
* @param entity - Entity class or schema to seed.
|
|
8
|
+
* @param records - Seed records containing stable `id` values.
|
|
9
|
+
* @param label - Human-readable label used in the seed summary.
|
|
10
|
+
*/
|
|
11
|
+
declare function seedEntities<T extends ObjectLiteral>(ds: DataSource, entity: EntityTarget<T>, records: Record<string, unknown>[], label: string): Promise<void>;
|
|
12
|
+
export { seedEntities };
|
|
13
|
+
//# sourceMappingURL=seed-entities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed-entities.d.ts","sourceRoot":"","sources":["../../../src/libs/seed-entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGlE;;;;;;;;GAQG;AACH,iBAAe,YAAY,CAAC,CAAC,SAAS,aAAa,EACjD,EAAE,EAAE,UAAU,EACd,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAClC,KAAK,EAAE,MAAM,iBAoBd;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.seedEntities = seedEntities;
|
|
13
|
+
const print_1 = require("./print");
|
|
14
|
+
/**
|
|
15
|
+
* Inserts seed records for an entity while skipping records that already exist.
|
|
16
|
+
* Existing records are detected by the `id` field.
|
|
17
|
+
*
|
|
18
|
+
* @param ds - Initialized TypeORM data source.
|
|
19
|
+
* @param entity - Entity class or schema to seed.
|
|
20
|
+
* @param records - Seed records containing stable `id` values.
|
|
21
|
+
* @param label - Human-readable label used in the seed summary.
|
|
22
|
+
*/
|
|
23
|
+
function seedEntities(ds, entity, records, label) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const repo = ds.getRepository(entity);
|
|
26
|
+
let skipped = 0;
|
|
27
|
+
let added = 0;
|
|
28
|
+
for (const record of records) {
|
|
29
|
+
const existing = yield repo.findOne({ where: { id: record.id } });
|
|
30
|
+
if (existing) {
|
|
31
|
+
skipped++;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
yield repo.save(record);
|
|
35
|
+
added++;
|
|
36
|
+
}
|
|
37
|
+
(0, print_1.print)(`Total ${label}: ${records.length}. Seeded ${added} ${label} (skipped ${skipped} existing).`);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=seed-entities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed-entities.js","sourceRoot":"","sources":["../../../src/libs/seed-entities.ts"],"names":[],"mappings":";;;;;;;;;;;AAsCS,oCAAY;AArCrB,mCAAgC;AAEhC;;;;;;;;GAQG;AACH,SAAe,YAAY,CACzB,EAAc,EACd,MAAuB,EACvB,OAAkC,EAClC,KAAa;;QAEb,MAAM,IAAI,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAS,EAAE,CAAC,CAAC;YACzE,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO,EAAE,CAAC;gBACV,SAAS;YACX,CAAC;YAED,MAAM,IAAI,CAAC,IAAI,CAAC,MAAa,CAAC,CAAC;YAC/B,KAAK,EAAE,CAAC;QACV,CAAC;QAED,IAAA,aAAK,EACH,SAAS,KAAK,KAAK,OAAO,CAAC,MAAM,YAAY,KAAK,IAAI,KAAK,aAAa,OAAO,aAAa,CAC7F,CAAC;IACJ,CAAC;CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { EntitySchema, MixedList, DataSourceOptions } from 'typeorm';
|
|
2
|
+
import { Seeder } from 'typeorm-extension';
|
|
3
|
+
export type GENERATE_MIGRATIONS = {
|
|
4
|
+
name?: string;
|
|
5
|
+
force?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type CREATE_DB = {
|
|
8
|
+
name?: string;
|
|
9
|
+
};
|
|
10
|
+
export type DB_STATUS = {
|
|
11
|
+
name?: string;
|
|
12
|
+
};
|
|
13
|
+
export type DROP_DB = {
|
|
14
|
+
name?: string;
|
|
15
|
+
};
|
|
16
|
+
export type MIGRATE = {
|
|
17
|
+
name?: string;
|
|
18
|
+
file?: string;
|
|
19
|
+
db?: string;
|
|
20
|
+
};
|
|
21
|
+
export type MIGRATION = {
|
|
22
|
+
all?: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type SEED = {
|
|
25
|
+
db?: string;
|
|
26
|
+
};
|
|
27
|
+
export type DATAFORGE_CONFIGURATIONS = {
|
|
28
|
+
TYPE: DataSourceOptions['type'];
|
|
29
|
+
ENTITIES: MixedList<string | Function | EntitySchema<any>>;
|
|
30
|
+
SEEDS: (new () => Seeder)[];
|
|
31
|
+
SSL_TYPE: 'light' | 'heavy';
|
|
32
|
+
SSL_MODE: boolean;
|
|
33
|
+
DATABASE_CA_CERT: string;
|
|
34
|
+
DATABASE_HOST: string;
|
|
35
|
+
DATABASE_PORT: number;
|
|
36
|
+
DATABASE_USERNAME: string;
|
|
37
|
+
DATABASE_PASSWORD: string;
|
|
38
|
+
DATABASE_NAME: string;
|
|
39
|
+
SYNCHRONIZE: boolean;
|
|
40
|
+
LOGGING: boolean;
|
|
41
|
+
INITIAL_DATABASE: string;
|
|
42
|
+
};
|
|
43
|
+
export type DATAFORGE_INTERNAL_CONFIGURATIONS = DATAFORGE_CONFIGURATIONS & {
|
|
44
|
+
ROOT: string;
|
|
45
|
+
MIGRATIONS_DIR: string;
|
|
46
|
+
SEEDS_DIR: string;
|
|
47
|
+
MIGRATIONS: MixedList<string | Function>;
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAChC,QAAQ,EAAE,SAAS,CAAC,MAAM,GAAG,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3D,KAAK,EAAE,CAAC,UAAU,MAAM,CAAC,EAAE,CAAC;IAE5B,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC;IAC5B,QAAQ,EAAE,OAAO,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,OAAO,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG,wBAAwB,GAAG;IACzE,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC;CAC1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "purplekit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": ""
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"dataforge": "./bin/dataforge"
|
|
11
|
+
},
|
|
12
|
+
"main": "./build/src/index.js",
|
|
13
|
+
"types": "./build/src/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./build/src/index.d.ts",
|
|
17
|
+
"default": "./build/src/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"bin",
|
|
22
|
+
"build/src",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"test": "mocha",
|
|
27
|
+
"test:build": "npm run build && npm test",
|
|
28
|
+
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"dev": "tsx src/app.ts",
|
|
31
|
+
"dataforge": "node build/src/app.js"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [],
|
|
34
|
+
"author": "",
|
|
35
|
+
"license": "ISC",
|
|
36
|
+
"packageManager": "pnpm@10.15.0",
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@testcontainers/postgresql": "^12.0.4",
|
|
39
|
+
"@types/chai": "^5.2.3",
|
|
40
|
+
"@types/mocha": "^10.0.10",
|
|
41
|
+
"@types/node": "^25.9.3",
|
|
42
|
+
"@types/pg": "^8.20.0",
|
|
43
|
+
"chai": "^6.2.2",
|
|
44
|
+
"mocha": "^11.7.6",
|
|
45
|
+
"pg": "^8.21.0",
|
|
46
|
+
"resolve-tspaths": "^0.8.23",
|
|
47
|
+
"tsc-alias": "^1.8.17",
|
|
48
|
+
"tsconfig-paths": "^4.2.0",
|
|
49
|
+
"tsx": "^4.22.4",
|
|
50
|
+
"typescript": "^6.0.3"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"commander": "^15.0.0",
|
|
54
|
+
"execa": "^9.6.1",
|
|
55
|
+
"mysql2": "^3.22.5",
|
|
56
|
+
"node-sql-parser": "^5.4.0",
|
|
57
|
+
"picocolors": "^1.1.1",
|
|
58
|
+
"prettier": "^3.9.3",
|
|
59
|
+
"reflect-metadata": "^0.2.2",
|
|
60
|
+
"typeorm": "^0.3.0",
|
|
61
|
+
"typeorm-extension": "^3.9.0"
|
|
62
|
+
}
|
|
63
|
+
}
|