@depup/typeorm-extension 3.9.0-depup.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.
Files changed (131) hide show
  1. package/LICENSE +21 -0
  2. package/README.MD +674 -0
  3. package/README.md +34 -0
  4. package/bin/cli.cjs +275 -0
  5. package/bin/cli.mjs +273 -0
  6. package/changes.json +22 -0
  7. package/dist/cli/commands/database/create.d.ts +27 -0
  8. package/dist/cli/commands/database/drop.d.ts +23 -0
  9. package/dist/cli/commands/database/index.d.ts +2 -0
  10. package/dist/cli/commands/index.d.ts +2 -0
  11. package/dist/cli/commands/seed/create.d.ts +21 -0
  12. package/dist/cli/commands/seed/index.d.ts +2 -0
  13. package/dist/cli/commands/seed/run.d.ts +24 -0
  14. package/dist/cli/index.d.ts +2 -0
  15. package/dist/data-source/find/index.d.ts +2 -0
  16. package/dist/data-source/find/module.d.ts +3 -0
  17. package/dist/data-source/find/type.d.ts +22 -0
  18. package/dist/data-source/index.d.ts +4 -0
  19. package/dist/data-source/options/index.d.ts +4 -0
  20. package/dist/data-source/options/module.d.ts +8 -0
  21. package/dist/data-source/options/singleton.d.ts +4 -0
  22. package/dist/data-source/options/type.d.ts +26 -0
  23. package/dist/data-source/options/utils/env.d.ts +4 -0
  24. package/dist/data-source/options/utils/index.d.ts +2 -0
  25. package/dist/data-source/options/utils/merge.d.ts +2 -0
  26. package/dist/data-source/singleton.d.ts +5 -0
  27. package/dist/data-source/type.d.ts +2 -0
  28. package/dist/database/driver/cockroachdb.d.ts +4 -0
  29. package/dist/database/driver/index.d.ts +9 -0
  30. package/dist/database/driver/mongodb.d.ts +6 -0
  31. package/dist/database/driver/mssql.d.ts +6 -0
  32. package/dist/database/driver/mysql.d.ts +7 -0
  33. package/dist/database/driver/oracle.d.ts +6 -0
  34. package/dist/database/driver/postgres.d.ts +8 -0
  35. package/dist/database/driver/sqlite.d.ts +3 -0
  36. package/dist/database/driver/types.d.ts +20 -0
  37. package/dist/database/driver/utils/build.d.ts +3 -0
  38. package/dist/database/driver/utils/character-set.d.ts +2 -0
  39. package/dist/database/driver/utils/charset.d.ts +2 -0
  40. package/dist/database/driver/utils/create.d.ts +2 -0
  41. package/dist/database/driver/utils/index.d.ts +4 -0
  42. package/dist/database/index.d.ts +3 -0
  43. package/dist/database/methods/check/index.d.ts +2 -0
  44. package/dist/database/methods/check/module.d.ts +7 -0
  45. package/dist/database/methods/check/types.d.ts +51 -0
  46. package/dist/database/methods/create/index.d.ts +1 -0
  47. package/dist/database/methods/create/module.d.ts +10 -0
  48. package/dist/database/methods/drop/index.d.ts +1 -0
  49. package/dist/database/methods/drop/module.d.ts +10 -0
  50. package/dist/database/methods/index.d.ts +4 -0
  51. package/dist/database/methods/type.d.ts +43 -0
  52. package/dist/database/utils/context.d.ts +3 -0
  53. package/dist/database/utils/index.d.ts +5 -0
  54. package/dist/database/utils/migration.d.ts +2 -0
  55. package/dist/database/utils/query.d.ts +3 -0
  56. package/dist/database/utils/schema.d.ts +3 -0
  57. package/dist/database/utils/type.d.ts +32 -0
  58. package/dist/env/constants.d.ts +68 -0
  59. package/dist/env/index.d.ts +3 -0
  60. package/dist/env/module.d.ts +4 -0
  61. package/dist/env/type.d.ts +36 -0
  62. package/dist/env/utils.d.ts +3 -0
  63. package/dist/errors/base.d.ts +2 -0
  64. package/dist/errors/driver.d.ts +6 -0
  65. package/dist/errors/index.d.ts +3 -0
  66. package/dist/errors/options.d.ts +7 -0
  67. package/dist/helpers/entity/error.d.ts +20 -0
  68. package/dist/helpers/entity/index.d.ts +5 -0
  69. package/dist/helpers/entity/join-columns.d.ts +16 -0
  70. package/dist/helpers/entity/metadata.d.ts +10 -0
  71. package/dist/helpers/entity/property-names.d.ts +11 -0
  72. package/dist/helpers/entity/uniqueness.d.ts +28 -0
  73. package/dist/helpers/index.d.ts +1 -0
  74. package/dist/index.cjs +3258 -0
  75. package/dist/index.cjs.map +1 -0
  76. package/dist/index.d.ts +9 -0
  77. package/dist/index.mjs +3136 -0
  78. package/dist/index.mjs.map +1 -0
  79. package/dist/query/index.d.ts +4 -0
  80. package/dist/query/module.d.ts +5 -0
  81. package/dist/query/parameter/fields/index.d.ts +2 -0
  82. package/dist/query/parameter/fields/module.d.ts +25 -0
  83. package/dist/query/parameter/fields/type.d.ts +6 -0
  84. package/dist/query/parameter/filters/index.d.ts +2 -0
  85. package/dist/query/parameter/filters/module.d.ts +35 -0
  86. package/dist/query/parameter/filters/type.d.ts +12 -0
  87. package/dist/query/parameter/index.d.ts +5 -0
  88. package/dist/query/parameter/pagination/index.d.ts +2 -0
  89. package/dist/query/parameter/pagination/module.d.ts +26 -0
  90. package/dist/query/parameter/pagination/type.d.ts +3 -0
  91. package/dist/query/parameter/relations/index.d.ts +2 -0
  92. package/dist/query/parameter/relations/module.d.ts +27 -0
  93. package/dist/query/parameter/relations/type.d.ts +8 -0
  94. package/dist/query/parameter/sort/index.d.ts +2 -0
  95. package/dist/query/parameter/sort/module.d.ts +26 -0
  96. package/dist/query/parameter/sort/type.d.ts +6 -0
  97. package/dist/query/type.d.ts +16 -0
  98. package/dist/query/utils/alias.d.ts +2 -0
  99. package/dist/query/utils/index.d.ts +3 -0
  100. package/dist/query/utils/key.d.ts +1 -0
  101. package/dist/query/utils/option.d.ts +1 -0
  102. package/dist/seeder/entity.d.ts +42 -0
  103. package/dist/seeder/executor.d.ts +24 -0
  104. package/dist/seeder/factory/index.d.ts +4 -0
  105. package/dist/seeder/factory/manager.d.ts +8 -0
  106. package/dist/seeder/factory/module.d.ts +17 -0
  107. package/dist/seeder/factory/type.d.ts +12 -0
  108. package/dist/seeder/factory/utils.d.ts +7 -0
  109. package/dist/seeder/index.d.ts +6 -0
  110. package/dist/seeder/module.d.ts +5 -0
  111. package/dist/seeder/type.d.ts +44 -0
  112. package/dist/seeder/utils/file-path.d.ts +7 -0
  113. package/dist/seeder/utils/index.d.ts +3 -0
  114. package/dist/seeder/utils/prepare.d.ts +2 -0
  115. package/dist/seeder/utils/template.d.ts +1 -0
  116. package/dist/utils/code-transformation/constants.d.ts +4 -0
  117. package/dist/utils/code-transformation/index.d.ts +2 -0
  118. package/dist/utils/code-transformation/module.d.ts +3 -0
  119. package/dist/utils/entity.d.ts +2 -0
  120. package/dist/utils/file-path.d.ts +9 -0
  121. package/dist/utils/file-system.d.ts +1 -0
  122. package/dist/utils/has-property.d.ts +2 -0
  123. package/dist/utils/index.d.ts +10 -0
  124. package/dist/utils/object.d.ts +2 -0
  125. package/dist/utils/promise.d.ts +1 -0
  126. package/dist/utils/separator.d.ts +3 -0
  127. package/dist/utils/slash.d.ts +2 -0
  128. package/dist/utils/tsconfig/index.d.ts +2 -0
  129. package/dist/utils/tsconfig/module.d.ts +2 -0
  130. package/dist/utils/tsconfig/type.d.ts +13 -0
  131. package/package.json +134 -0
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # @depup/typeorm-extension
2
+
3
+ > Dependency-bumped version of [typeorm-extension](https://www.npmjs.com/package/typeorm-extension)
4
+
5
+ Generated by [DepUp](https://github.com/depup/npm) -- all production
6
+ dependencies bumped to latest versions.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @depup/typeorm-extension
12
+ ```
13
+
14
+ | Field | Value |
15
+ |-------|-------|
16
+ | Original | [typeorm-extension](https://www.npmjs.com/package/typeorm-extension) @ 3.9.0 |
17
+ | Processed | 2026-03-19 |
18
+ | Smoke test | failed |
19
+ | Deps updated | 4 |
20
+
21
+ ## Dependency Changes
22
+
23
+ | Dependency | From | To |
24
+ |------------|------|-----|
25
+ | consola | ^3.4.0 | ^3.4.2 |
26
+ | pascal-case | ^3.1.2 | ^4.0.0 |
27
+ | rapiq | ^0.9.0 | ^1.0.0 |
28
+ | smob | ^1.5.0 | ^1.6.1 |
29
+
30
+ ---
31
+
32
+ Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/typeorm-extension
33
+
34
+ License inherited from the original package.
package/bin/cli.cjs ADDED
@@ -0,0 +1,275 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ require('reflect-metadata');
5
+ var process$1 = require('node:process');
6
+ var yargs = require('yargs');
7
+ var helpers = require('yargs/helpers');
8
+ var consola = require('consola');
9
+ var typeormExtension = require('typeorm-extension');
10
+ var locter = require('locter');
11
+ var fs = require('node:fs');
12
+ var path = require('node:path');
13
+ var pascalCase = require('pascal-case');
14
+
15
+ class DatabaseCreateCommand {
16
+ builder(args) {
17
+ return args.option('preserveFilePaths', {
18
+ default: false,
19
+ type: 'boolean',
20
+ describe: 'This option indicates if file paths should be preserved.'
21
+ }).option('root', {
22
+ alias: 'r',
23
+ default: process.cwd(),
24
+ describe: 'Root directory of the project.'
25
+ }).option('tsconfig', {
26
+ alias: 'tc',
27
+ default: 'tsconfig.json',
28
+ describe: 'Name (or relative path incl. name) of the tsconfig file.'
29
+ }).option('dataSource', {
30
+ alias: 'd',
31
+ default: 'data-source',
32
+ describe: 'Name (or relative path incl. name) of the data-source file.'
33
+ }).option('synchronize', {
34
+ alias: 's',
35
+ default: 'yes',
36
+ describe: 'Create database schema for all entities.',
37
+ choices: [
38
+ 'yes',
39
+ 'no'
40
+ ]
41
+ }).option('initialDatabase', {
42
+ describe: 'Specify the initial database to connect to.'
43
+ });
44
+ }
45
+ async handler(raw) {
46
+ const args = raw;
47
+ let tsconfig;
48
+ let sourcePath = typeormExtension.resolveFilePath(args.dataSource, args.root);
49
+ if (!args.preserveFilePaths) {
50
+ tsconfig = await typeormExtension.readTSConfig(typeormExtension.resolveFilePath(args.root, args.tsconfig));
51
+ sourcePath = await typeormExtension.adjustFilePath(sourcePath, tsconfig);
52
+ }
53
+ const source = typeormExtension.parseFilePath(sourcePath);
54
+ consola.consola.info(`DataSource Directory: ${source.directory}`);
55
+ consola.consola.info(`DataSource Name: ${source.name}`);
56
+ const dataSourceOptions = await typeormExtension.buildDataSourceOptions({
57
+ directory: source.directory,
58
+ dataSourceName: source.name,
59
+ tsconfig,
60
+ preserveFilePaths: args.preserveFilePaths
61
+ });
62
+ const context = {
63
+ ifNotExist: true,
64
+ options: dataSourceOptions,
65
+ synchronize: args.synchronize === 'yes'
66
+ };
67
+ if (typeof args.initialDatabase === 'string' && args.initialDatabase !== '') {
68
+ context.initialDatabase = args.initialDatabase;
69
+ }
70
+ try {
71
+ await typeormExtension.createDatabase(context);
72
+ consola.consola.success('Created database.');
73
+ process.exit(0);
74
+ } catch (e) {
75
+ consola.consola.warn('Failed to create database.');
76
+ consola.consola.error(e);
77
+ process.exit(1);
78
+ }
79
+ }
80
+ constructor(){
81
+ this.command = 'db:create';
82
+ this.describe = 'Create database.';
83
+ }
84
+ }
85
+
86
+ class DatabaseDropCommand {
87
+ builder(args) {
88
+ return args.option('preserveFilePaths', {
89
+ default: false,
90
+ type: 'boolean',
91
+ describe: 'This option indicates if file paths should be preserved.'
92
+ }).option('root', {
93
+ alias: 'r',
94
+ default: process.cwd(),
95
+ describe: 'Root directory of the project.'
96
+ }).option('tsconfig', {
97
+ alias: 'tc',
98
+ default: 'tsconfig.json',
99
+ describe: 'Name (or relative path incl. name) of the tsconfig file.'
100
+ }).option('dataSource', {
101
+ alias: 'd',
102
+ default: 'data-source',
103
+ describe: 'Name (or relative path incl. name) of the data-source file.'
104
+ }).option('initialDatabase', {
105
+ describe: 'Specify the initial database to connect to.'
106
+ });
107
+ }
108
+ async handler(raw) {
109
+ const args = raw;
110
+ let tsconfig;
111
+ let sourcePath = typeormExtension.resolveFilePath(args.dataSource, args.root);
112
+ if (!args.preserveFilePaths) {
113
+ tsconfig = await typeormExtension.readTSConfig(typeormExtension.resolveFilePath(args.root, args.tsconfig));
114
+ sourcePath = await typeormExtension.adjustFilePath(sourcePath, tsconfig);
115
+ }
116
+ const source = typeormExtension.parseFilePath(sourcePath);
117
+ consola.consola.info(`DataSource Directory: ${source.directory}`);
118
+ consola.consola.info(`DataSource Name: ${source.name}`);
119
+ const dataSourceOptions = await typeormExtension.buildDataSourceOptions({
120
+ directory: source.directory,
121
+ dataSourceName: source.name,
122
+ tsconfig,
123
+ preserveFilePaths: args.preserveFilePaths
124
+ });
125
+ const context = {
126
+ ifExist: true,
127
+ options: dataSourceOptions
128
+ };
129
+ if (typeof args.initialDatabase === 'string' && args.initialDatabase !== '') {
130
+ context.initialDatabase = args.initialDatabase;
131
+ }
132
+ try {
133
+ await typeormExtension.dropDatabase(context);
134
+ consola.consola.success('Dropped database.');
135
+ process.exit(0);
136
+ } catch (e) {
137
+ consola.consola.warn('Failed to drop database.');
138
+ consola.consola.error(e);
139
+ process.exit(1);
140
+ }
141
+ }
142
+ constructor(){
143
+ this.command = 'db:drop';
144
+ this.describe = 'Drop database.';
145
+ }
146
+ }
147
+
148
+ class SeedCreateCommand {
149
+ builder(args) {
150
+ return args.option('root', {
151
+ alias: 'r',
152
+ default: process.cwd(),
153
+ describe: 'Root directory of the project.'
154
+ }).option('timestamp', {
155
+ alias: 't',
156
+ type: 'number',
157
+ describe: 'Custom timestamp for the seeder name.'
158
+ }).option('javascript', {
159
+ alias: 'j',
160
+ type: 'boolean',
161
+ default: false,
162
+ describe: 'Generate a seeder file for JavaScript instead of TypeScript.'
163
+ }).option('name', {
164
+ alias: 'n',
165
+ describe: 'Name (or relative path incl. name) of the seeder.',
166
+ demandOption: true
167
+ });
168
+ }
169
+ async handler(raw) {
170
+ const args = raw;
171
+ let timestamp;
172
+ if (Number.isNaN(args.timestamp) || !args.timestamp) {
173
+ timestamp = Date.now();
174
+ } else {
175
+ timestamp = args.timestamp;
176
+ }
177
+ const sourcePath = typeormExtension.parseFilePath(args.name, args.root);
178
+ const dirNameIsDirectory = await typeormExtension.isDirectory(sourcePath.directory);
179
+ if (!dirNameIsDirectory) {
180
+ consola.consola.warn(`The output directory ${sourcePath.directory} does not exist.`);
181
+ process.exit(1);
182
+ }
183
+ const extension = args.javascript ? '.js' : '.ts';
184
+ const nameExtension = locter.getFileNameExtension(sourcePath.name);
185
+ const nameWithoutExtension = locter.removeFileNameExtension(sourcePath.name);
186
+ let fileName;
187
+ if (nameExtension) {
188
+ fileName = `${timestamp}-${sourcePath.name}`;
189
+ } else {
190
+ fileName = `${timestamp}-${sourcePath.name}${extension}`;
191
+ }
192
+ const filePath = sourcePath.directory + path.sep + fileName;
193
+ const template = typeormExtension.buildSeederFileTemplate(nameWithoutExtension, timestamp);
194
+ consola.consola.info(`Seed Directory: ${sourcePath.directory}`);
195
+ consola.consola.info(`Seed FileName: ${fileName}`);
196
+ consola.consola.info(`Seed Name: ${pascalCase.pascalCase(nameWithoutExtension)}`);
197
+ try {
198
+ await fs.promises.writeFile(filePath, template, {
199
+ encoding: 'utf-8'
200
+ });
201
+ } catch (e) {
202
+ consola.consola.warn(`The seed could not be written to the path ${filePath}.`);
203
+ process.exit(1);
204
+ }
205
+ process.exit(0);
206
+ }
207
+ constructor(){
208
+ this.command = 'seed:create';
209
+ this.describe = 'Create a seeder file.';
210
+ }
211
+ }
212
+
213
+ class SeedRunCommand {
214
+ builder(args) {
215
+ return args.option('preserveFilePaths', {
216
+ default: false,
217
+ type: 'boolean',
218
+ describe: 'This option indicates if file paths should be preserved.'
219
+ }).option('root', {
220
+ alias: 'r',
221
+ default: process.cwd(),
222
+ describe: 'Root directory of the project.'
223
+ }).option('tsconfig', {
224
+ alias: 'tc',
225
+ default: 'tsconfig.json',
226
+ describe: 'Name (or relative path incl. name) of the tsconfig file.'
227
+ }).option('dataSource', {
228
+ alias: 'd',
229
+ default: 'data-source',
230
+ describe: 'Name (or relative path incl. name) of the data-source file.'
231
+ }).option('name', {
232
+ alias: 'n',
233
+ describe: 'Name (or relative path incl. name) of the seeder.'
234
+ });
235
+ }
236
+ async handler(raw) {
237
+ const args = raw;
238
+ let tsconfig;
239
+ let sourcePath = typeormExtension.resolveFilePath(args.dataSource, args.root);
240
+ if (!args.preserveFilePaths) {
241
+ tsconfig = await typeormExtension.readTSConfig(args.root);
242
+ sourcePath = await typeormExtension.adjustFilePath(sourcePath, tsconfig);
243
+ args.name = await typeormExtension.adjustFilePath(args.name, tsconfig);
244
+ }
245
+ const source = typeormExtension.parseFilePath(sourcePath);
246
+ consola.consola.info(`DataSource Directory: ${source.directory}`);
247
+ consola.consola.info(`DataSource Name: ${source.name}`);
248
+ const dataSourceOptions = await typeormExtension.buildDataSourceOptions({
249
+ dataSourceName: source.name,
250
+ directory: source.directory,
251
+ tsconfig,
252
+ preserveFilePaths: args.preserveFilePaths
253
+ });
254
+ typeormExtension.setDataSourceOptions(dataSourceOptions);
255
+ if (args.name) {
256
+ consola.consola.info(`Seed Name: ${args.name}`);
257
+ }
258
+ const dataSource = await typeormExtension.useDataSource();
259
+ const executor = new typeormExtension.SeederExecutor(dataSource, {
260
+ root: args.root,
261
+ tsconfig,
262
+ preserveFilePaths: args.preserveFilePaths
263
+ });
264
+ await executor.execute({
265
+ seedName: args.name
266
+ });
267
+ process.exit(0);
268
+ }
269
+ constructor(){
270
+ this.command = 'seed:run';
271
+ this.describe = 'Populate the database with an initial data set or generated data by a factory.';
272
+ }
273
+ }
274
+
275
+ yargs(helpers.hideBin(process$1.argv)).scriptName('typeorm-extension').usage('Usage: $0 <command> [options]').demandCommand(1).command(new DatabaseCreateCommand()).command(new DatabaseDropCommand()).command(new SeedRunCommand()).command(new SeedCreateCommand()).strict().alias('v', 'version').help('h').alias('h', 'help').parse();
package/bin/cli.mjs ADDED
@@ -0,0 +1,273 @@
1
+ #!/usr/bin/env node
2
+ import 'reflect-metadata';
3
+ import process$1 from 'node:process';
4
+ import yargs from 'yargs';
5
+ import { hideBin } from 'yargs/helpers';
6
+ import { consola } from 'consola';
7
+ import { resolveFilePath, readTSConfig, adjustFilePath, parseFilePath, buildDataSourceOptions, createDatabase, dropDatabase, isDirectory, buildSeederFileTemplate, setDataSourceOptions, useDataSource, SeederExecutor } from 'typeorm-extension';
8
+ import { getFileNameExtension, removeFileNameExtension } from 'locter';
9
+ import fs from 'node:fs';
10
+ import path from 'node:path';
11
+ import { pascalCase } from 'pascal-case';
12
+
13
+ class DatabaseCreateCommand {
14
+ builder(args) {
15
+ return args.option('preserveFilePaths', {
16
+ default: false,
17
+ type: 'boolean',
18
+ describe: 'This option indicates if file paths should be preserved.'
19
+ }).option('root', {
20
+ alias: 'r',
21
+ default: process.cwd(),
22
+ describe: 'Root directory of the project.'
23
+ }).option('tsconfig', {
24
+ alias: 'tc',
25
+ default: 'tsconfig.json',
26
+ describe: 'Name (or relative path incl. name) of the tsconfig file.'
27
+ }).option('dataSource', {
28
+ alias: 'd',
29
+ default: 'data-source',
30
+ describe: 'Name (or relative path incl. name) of the data-source file.'
31
+ }).option('synchronize', {
32
+ alias: 's',
33
+ default: 'yes',
34
+ describe: 'Create database schema for all entities.',
35
+ choices: [
36
+ 'yes',
37
+ 'no'
38
+ ]
39
+ }).option('initialDatabase', {
40
+ describe: 'Specify the initial database to connect to.'
41
+ });
42
+ }
43
+ async handler(raw) {
44
+ const args = raw;
45
+ let tsconfig;
46
+ let sourcePath = resolveFilePath(args.dataSource, args.root);
47
+ if (!args.preserveFilePaths) {
48
+ tsconfig = await readTSConfig(resolveFilePath(args.root, args.tsconfig));
49
+ sourcePath = await adjustFilePath(sourcePath, tsconfig);
50
+ }
51
+ const source = parseFilePath(sourcePath);
52
+ consola.info(`DataSource Directory: ${source.directory}`);
53
+ consola.info(`DataSource Name: ${source.name}`);
54
+ const dataSourceOptions = await buildDataSourceOptions({
55
+ directory: source.directory,
56
+ dataSourceName: source.name,
57
+ tsconfig,
58
+ preserveFilePaths: args.preserveFilePaths
59
+ });
60
+ const context = {
61
+ ifNotExist: true,
62
+ options: dataSourceOptions,
63
+ synchronize: args.synchronize === 'yes'
64
+ };
65
+ if (typeof args.initialDatabase === 'string' && args.initialDatabase !== '') {
66
+ context.initialDatabase = args.initialDatabase;
67
+ }
68
+ try {
69
+ await createDatabase(context);
70
+ consola.success('Created database.');
71
+ process.exit(0);
72
+ } catch (e) {
73
+ consola.warn('Failed to create database.');
74
+ consola.error(e);
75
+ process.exit(1);
76
+ }
77
+ }
78
+ constructor(){
79
+ this.command = 'db:create';
80
+ this.describe = 'Create database.';
81
+ }
82
+ }
83
+
84
+ class DatabaseDropCommand {
85
+ builder(args) {
86
+ return args.option('preserveFilePaths', {
87
+ default: false,
88
+ type: 'boolean',
89
+ describe: 'This option indicates if file paths should be preserved.'
90
+ }).option('root', {
91
+ alias: 'r',
92
+ default: process.cwd(),
93
+ describe: 'Root directory of the project.'
94
+ }).option('tsconfig', {
95
+ alias: 'tc',
96
+ default: 'tsconfig.json',
97
+ describe: 'Name (or relative path incl. name) of the tsconfig file.'
98
+ }).option('dataSource', {
99
+ alias: 'd',
100
+ default: 'data-source',
101
+ describe: 'Name (or relative path incl. name) of the data-source file.'
102
+ }).option('initialDatabase', {
103
+ describe: 'Specify the initial database to connect to.'
104
+ });
105
+ }
106
+ async handler(raw) {
107
+ const args = raw;
108
+ let tsconfig;
109
+ let sourcePath = resolveFilePath(args.dataSource, args.root);
110
+ if (!args.preserveFilePaths) {
111
+ tsconfig = await readTSConfig(resolveFilePath(args.root, args.tsconfig));
112
+ sourcePath = await adjustFilePath(sourcePath, tsconfig);
113
+ }
114
+ const source = parseFilePath(sourcePath);
115
+ consola.info(`DataSource Directory: ${source.directory}`);
116
+ consola.info(`DataSource Name: ${source.name}`);
117
+ const dataSourceOptions = await buildDataSourceOptions({
118
+ directory: source.directory,
119
+ dataSourceName: source.name,
120
+ tsconfig,
121
+ preserveFilePaths: args.preserveFilePaths
122
+ });
123
+ const context = {
124
+ ifExist: true,
125
+ options: dataSourceOptions
126
+ };
127
+ if (typeof args.initialDatabase === 'string' && args.initialDatabase !== '') {
128
+ context.initialDatabase = args.initialDatabase;
129
+ }
130
+ try {
131
+ await dropDatabase(context);
132
+ consola.success('Dropped database.');
133
+ process.exit(0);
134
+ } catch (e) {
135
+ consola.warn('Failed to drop database.');
136
+ consola.error(e);
137
+ process.exit(1);
138
+ }
139
+ }
140
+ constructor(){
141
+ this.command = 'db:drop';
142
+ this.describe = 'Drop database.';
143
+ }
144
+ }
145
+
146
+ class SeedCreateCommand {
147
+ builder(args) {
148
+ return args.option('root', {
149
+ alias: 'r',
150
+ default: process.cwd(),
151
+ describe: 'Root directory of the project.'
152
+ }).option('timestamp', {
153
+ alias: 't',
154
+ type: 'number',
155
+ describe: 'Custom timestamp for the seeder name.'
156
+ }).option('javascript', {
157
+ alias: 'j',
158
+ type: 'boolean',
159
+ default: false,
160
+ describe: 'Generate a seeder file for JavaScript instead of TypeScript.'
161
+ }).option('name', {
162
+ alias: 'n',
163
+ describe: 'Name (or relative path incl. name) of the seeder.',
164
+ demandOption: true
165
+ });
166
+ }
167
+ async handler(raw) {
168
+ const args = raw;
169
+ let timestamp;
170
+ if (Number.isNaN(args.timestamp) || !args.timestamp) {
171
+ timestamp = Date.now();
172
+ } else {
173
+ timestamp = args.timestamp;
174
+ }
175
+ const sourcePath = parseFilePath(args.name, args.root);
176
+ const dirNameIsDirectory = await isDirectory(sourcePath.directory);
177
+ if (!dirNameIsDirectory) {
178
+ consola.warn(`The output directory ${sourcePath.directory} does not exist.`);
179
+ process.exit(1);
180
+ }
181
+ const extension = args.javascript ? '.js' : '.ts';
182
+ const nameExtension = getFileNameExtension(sourcePath.name);
183
+ const nameWithoutExtension = removeFileNameExtension(sourcePath.name);
184
+ let fileName;
185
+ if (nameExtension) {
186
+ fileName = `${timestamp}-${sourcePath.name}`;
187
+ } else {
188
+ fileName = `${timestamp}-${sourcePath.name}${extension}`;
189
+ }
190
+ const filePath = sourcePath.directory + path.sep + fileName;
191
+ const template = buildSeederFileTemplate(nameWithoutExtension, timestamp);
192
+ consola.info(`Seed Directory: ${sourcePath.directory}`);
193
+ consola.info(`Seed FileName: ${fileName}`);
194
+ consola.info(`Seed Name: ${pascalCase(nameWithoutExtension)}`);
195
+ try {
196
+ await fs.promises.writeFile(filePath, template, {
197
+ encoding: 'utf-8'
198
+ });
199
+ } catch (e) {
200
+ consola.warn(`The seed could not be written to the path ${filePath}.`);
201
+ process.exit(1);
202
+ }
203
+ process.exit(0);
204
+ }
205
+ constructor(){
206
+ this.command = 'seed:create';
207
+ this.describe = 'Create a seeder file.';
208
+ }
209
+ }
210
+
211
+ class SeedRunCommand {
212
+ builder(args) {
213
+ return args.option('preserveFilePaths', {
214
+ default: false,
215
+ type: 'boolean',
216
+ describe: 'This option indicates if file paths should be preserved.'
217
+ }).option('root', {
218
+ alias: 'r',
219
+ default: process.cwd(),
220
+ describe: 'Root directory of the project.'
221
+ }).option('tsconfig', {
222
+ alias: 'tc',
223
+ default: 'tsconfig.json',
224
+ describe: 'Name (or relative path incl. name) of the tsconfig file.'
225
+ }).option('dataSource', {
226
+ alias: 'd',
227
+ default: 'data-source',
228
+ describe: 'Name (or relative path incl. name) of the data-source file.'
229
+ }).option('name', {
230
+ alias: 'n',
231
+ describe: 'Name (or relative path incl. name) of the seeder.'
232
+ });
233
+ }
234
+ async handler(raw) {
235
+ const args = raw;
236
+ let tsconfig;
237
+ let sourcePath = resolveFilePath(args.dataSource, args.root);
238
+ if (!args.preserveFilePaths) {
239
+ tsconfig = await readTSConfig(args.root);
240
+ sourcePath = await adjustFilePath(sourcePath, tsconfig);
241
+ args.name = await adjustFilePath(args.name, tsconfig);
242
+ }
243
+ const source = parseFilePath(sourcePath);
244
+ consola.info(`DataSource Directory: ${source.directory}`);
245
+ consola.info(`DataSource Name: ${source.name}`);
246
+ const dataSourceOptions = await buildDataSourceOptions({
247
+ dataSourceName: source.name,
248
+ directory: source.directory,
249
+ tsconfig,
250
+ preserveFilePaths: args.preserveFilePaths
251
+ });
252
+ setDataSourceOptions(dataSourceOptions);
253
+ if (args.name) {
254
+ consola.info(`Seed Name: ${args.name}`);
255
+ }
256
+ const dataSource = await useDataSource();
257
+ const executor = new SeederExecutor(dataSource, {
258
+ root: args.root,
259
+ tsconfig,
260
+ preserveFilePaths: args.preserveFilePaths
261
+ });
262
+ await executor.execute({
263
+ seedName: args.name
264
+ });
265
+ process.exit(0);
266
+ }
267
+ constructor(){
268
+ this.command = 'seed:run';
269
+ this.describe = 'Populate the database with an initial data set or generated data by a factory.';
270
+ }
271
+ }
272
+
273
+ yargs(hideBin(process$1.argv)).scriptName('typeorm-extension').usage('Usage: $0 <command> [options]').demandCommand(1).command(new DatabaseCreateCommand()).command(new DatabaseDropCommand()).command(new SeedRunCommand()).command(new SeedCreateCommand()).strict().alias('v', 'version').help('h').alias('h', 'help').parse();
package/changes.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "bumped": {
3
+ "consola": {
4
+ "from": "^3.4.0",
5
+ "to": "^3.4.2"
6
+ },
7
+ "pascal-case": {
8
+ "from": "^3.1.2",
9
+ "to": "^4.0.0"
10
+ },
11
+ "rapiq": {
12
+ "from": "^0.9.0",
13
+ "to": "^1.0.0"
14
+ },
15
+ "smob": {
16
+ "from": "^1.5.0",
17
+ "to": "^1.6.1"
18
+ }
19
+ },
20
+ "timestamp": "2026-03-19T03:04:21.566Z",
21
+ "totalUpdated": 4
22
+ }
@@ -0,0 +1,27 @@
1
+ import type { Arguments, Argv, CommandModule } from 'yargs';
2
+ export interface DatabaseCreateArguments extends Arguments {
3
+ preserveFilePaths: boolean;
4
+ root: string;
5
+ tsconfig: string;
6
+ dataSource: string;
7
+ synchronize: string;
8
+ initialDatabase?: unknown;
9
+ }
10
+ export declare class DatabaseCreateCommand implements CommandModule {
11
+ command: string;
12
+ describe: string;
13
+ builder(args: Argv): Argv<{
14
+ preserveFilePaths: boolean;
15
+ } & {
16
+ root: string;
17
+ } & {
18
+ tsconfig: string;
19
+ } & {
20
+ dataSource: string;
21
+ } & {
22
+ synchronize: string;
23
+ } & {
24
+ initialDatabase: unknown;
25
+ }>;
26
+ handler(raw: Arguments): Promise<void>;
27
+ }
@@ -0,0 +1,23 @@
1
+ import type { Arguments, Argv, CommandModule } from 'yargs';
2
+ export interface DatabaseDropArguments extends Arguments {
3
+ preserveFilePaths: boolean;
4
+ root: string;
5
+ tsconfig: string;
6
+ dataSource: string;
7
+ }
8
+ export declare class DatabaseDropCommand implements CommandModule {
9
+ command: string;
10
+ describe: string;
11
+ builder(args: Argv): Argv<{
12
+ preserveFilePaths: boolean;
13
+ } & {
14
+ root: string;
15
+ } & {
16
+ tsconfig: string;
17
+ } & {
18
+ dataSource: string;
19
+ } & {
20
+ initialDatabase: unknown;
21
+ }>;
22
+ handler(raw: Arguments): Promise<void>;
23
+ }
@@ -0,0 +1,2 @@
1
+ export * from './create';
2
+ export * from './drop';
@@ -0,0 +1,2 @@
1
+ export * from './database';
2
+ export * from './seed';
@@ -0,0 +1,21 @@
1
+ import type { Arguments, Argv, CommandModule } from 'yargs';
2
+ export interface SeedCreateArguments extends Arguments {
3
+ root: string;
4
+ javascript: boolean;
5
+ timestamp?: number;
6
+ name: string;
7
+ }
8
+ export declare class SeedCreateCommand implements CommandModule {
9
+ command: string;
10
+ describe: string;
11
+ builder(args: Argv): Argv<{
12
+ root: string;
13
+ } & {
14
+ timestamp: number | undefined;
15
+ } & {
16
+ javascript: boolean;
17
+ } & {
18
+ name: unknown;
19
+ }>;
20
+ handler(raw: Arguments): Promise<void>;
21
+ }
@@ -0,0 +1,2 @@
1
+ export * from './create';
2
+ export * from './run';