@anarchitects/nx-typeorm 0.0.3 → 0.2.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 (109) hide show
  1. package/README.md +203 -43
  2. package/dist/executors/cache-clear/executor.d.ts +6 -0
  3. package/dist/executors/cache-clear/executor.d.ts.map +1 -0
  4. package/dist/executors/cache-clear/executor.js +5 -0
  5. package/dist/executors/cache-clear/schema.json +28 -0
  6. package/dist/executors/ensure-schema/executor.d.ts +1 -5
  7. package/dist/executors/ensure-schema/executor.d.ts.map +1 -1
  8. package/dist/executors/ensure-schema/executor.js +1 -1
  9. package/dist/executors/entity-create/executor.d.ts +6 -0
  10. package/dist/executors/entity-create/executor.d.ts.map +1 -0
  11. package/dist/executors/entity-create/executor.js +15 -0
  12. package/dist/executors/entity-create/schema.json +23 -0
  13. package/dist/executors/generate/executor.d.ts +1 -7
  14. package/dist/executors/generate/executor.d.ts.map +1 -1
  15. package/dist/executors/generate/executor.js +12 -24
  16. package/dist/executors/generate/schema.json +11 -1
  17. package/dist/executors/init/executor.d.ts +6 -0
  18. package/dist/executors/init/executor.d.ts.map +1 -0
  19. package/dist/executors/init/executor.js +24 -0
  20. package/dist/executors/init/schema.json +40 -0
  21. package/dist/executors/migration-create/executor.d.ts +6 -0
  22. package/dist/executors/migration-create/executor.d.ts.map +1 -0
  23. package/dist/executors/migration-create/executor.js +19 -0
  24. package/dist/executors/migration-create/schema.json +31 -0
  25. package/dist/executors/migration-show/executor.d.ts +6 -0
  26. package/dist/executors/migration-show/executor.d.ts.map +1 -0
  27. package/dist/executors/migration-show/executor.js +5 -0
  28. package/dist/executors/migration-show/schema.json +28 -0
  29. package/dist/executors/query/executor.d.ts +6 -0
  30. package/dist/executors/query/executor.d.ts.map +1 -0
  31. package/dist/executors/query/executor.js +9 -0
  32. package/dist/executors/query/schema.json +33 -0
  33. package/dist/executors/revert/executor.d.ts +1 -5
  34. package/dist/executors/revert/executor.d.ts.map +1 -1
  35. package/dist/executors/revert/executor.js +8 -19
  36. package/dist/executors/revert/schema.json +7 -1
  37. package/dist/executors/run/executor.d.ts +1 -6
  38. package/dist/executors/run/executor.d.ts.map +1 -1
  39. package/dist/executors/run/executor.js +7 -18
  40. package/dist/executors/run/schema.json +6 -0
  41. package/dist/executors/schema-drop/executor.d.ts +6 -0
  42. package/dist/executors/schema-drop/executor.d.ts.map +1 -0
  43. package/dist/executors/schema-drop/executor.js +5 -0
  44. package/dist/executors/schema-drop/schema.json +28 -0
  45. package/dist/executors/schema-log/executor.d.ts +6 -0
  46. package/dist/executors/schema-log/executor.d.ts.map +1 -0
  47. package/dist/executors/schema-log/executor.js +5 -0
  48. package/dist/executors/schema-log/schema.json +28 -0
  49. package/dist/executors/schema-sync/executor.d.ts +6 -0
  50. package/dist/executors/schema-sync/executor.d.ts.map +1 -0
  51. package/dist/executors/schema-sync/executor.js +5 -0
  52. package/dist/executors/schema-sync/schema.json +28 -0
  53. package/dist/executors/seed/executor.d.ts +1 -7
  54. package/dist/executors/seed/executor.d.ts.map +1 -1
  55. package/dist/executors/seed/executor.js +1 -1
  56. package/dist/executors/subscriber-create/executor.d.ts +6 -0
  57. package/dist/executors/subscriber-create/executor.d.ts.map +1 -0
  58. package/dist/executors/subscriber-create/executor.js +13 -0
  59. package/dist/executors/subscriber-create/schema.json +23 -0
  60. package/dist/executors/version/executor.d.ts +6 -0
  61. package/dist/executors/version/executor.d.ts.map +1 -0
  62. package/dist/executors/version/executor.js +5 -0
  63. package/dist/executors/version/schema.json +14 -0
  64. package/dist/generators/bootstrap/files/app/env.example__tmpl__ +55 -1
  65. package/dist/generators/bootstrap/files/app/src/data-source.ts__tmpl__ +6 -0
  66. package/dist/generators/bootstrap/files/app/src/typeorm.datasource.ts__tmpl__ +1 -15
  67. package/dist/generators/bootstrap/files/app/tools/typeorm/connection-options.ts__tmpl__ +292 -0
  68. package/dist/generators/bootstrap/files/app/tools/typeorm/datasource.migrations.ts__tmpl__ +2 -7
  69. package/dist/generators/bootstrap/files/lib/project.json.partial__tmpl__ +3 -1
  70. package/dist/generators/bootstrap/generator.d.ts +5 -1
  71. package/dist/generators/bootstrap/generator.d.ts.map +1 -1
  72. package/dist/generators/bootstrap/generator.js +179 -31
  73. package/dist/generators/bootstrap/schema.json +18 -1
  74. package/dist/generators/entity-create/generator.d.ts +4 -0
  75. package/dist/generators/entity-create/generator.d.ts.map +1 -0
  76. package/dist/generators/entity-create/generator.js +70 -0
  77. package/dist/generators/entity-create/schema.json +28 -0
  78. package/dist/generators/init/generator.d.ts +4 -0
  79. package/dist/generators/init/generator.d.ts.map +1 -0
  80. package/dist/generators/init/generator.js +31 -0
  81. package/dist/generators/init/schema.json +18 -0
  82. package/dist/generators/migration-create/generator.d.ts +4 -0
  83. package/dist/generators/migration-create/generator.d.ts.map +1 -0
  84. package/dist/generators/migration-create/generator.js +72 -0
  85. package/dist/generators/migration-create/schema.json +40 -0
  86. package/dist/generators/subscriber-create/generator.d.ts +4 -0
  87. package/dist/generators/subscriber-create/generator.d.ts.map +1 -0
  88. package/dist/generators/subscriber-create/generator.js +70 -0
  89. package/dist/generators/subscriber-create/schema.json +28 -0
  90. package/dist/index.d.ts +19 -0
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +19 -0
  93. package/dist/index.json +72 -0
  94. package/dist/plugin/index.d.ts +9 -0
  95. package/dist/plugin/index.d.ts.map +1 -0
  96. package/dist/plugin/index.js +241 -0
  97. package/dist/plugins/typeorm.d.ts +1 -6
  98. package/dist/plugins/typeorm.d.ts.map +1 -1
  99. package/dist/plugins/typeorm.js +1 -161
  100. package/dist/utils/cli.d.ts +17 -0
  101. package/dist/utils/cli.d.ts.map +1 -0
  102. package/dist/utils/cli.js +55 -0
  103. package/dist/{executors → utils}/shared.d.ts +12 -9
  104. package/dist/utils/shared.d.ts.map +1 -0
  105. package/dist/utils/shared.js +260 -0
  106. package/package.json +6 -7
  107. package/dist/executors/shared.d.ts.map +0 -1
  108. package/dist/executors/shared.js +0 -71
  109. package/dist/generators/bootstrap/files/app/tools/typeorm/datasource.runtime.ts__tmpl__ +0 -9
package/README.md CHANGED
@@ -1,84 +1,244 @@
1
1
  # @anarchitects/nx-typeorm
2
2
 
3
- Nx plugin that gives Rails-like ergonomics for TypeORM projects. It wires common
4
- TypeORM workflows into the Nx task system so you can run migrations, seeds, and
5
- bootstrap new projects without leaving `nx`.
3
+ Nx plugin for TypeORM integration in Nx backend applications and libraries.
4
+ It provides:
6
5
 
7
- ## Purpose
8
-
9
- - Detect TypeORM-enabled projects and infer common Nx targets (run, revert,
10
- seed, ensure-schema).
11
- - Provide thin executors that proxy TypeORM CLI commands through the active
12
- package manager.
13
- - Scaffold applications or libraries with ready-to-use TypeORM wiring, seeds,
14
- and migration directories via `nx g @anarchitects/nx-typeorm:bootstrap`.
6
+ - `nx add` / `init` setup for minimal TypeORM dependencies.
7
+ - `bootstrap` scaffolding for app runtime datasource wiring and library
8
+ infrastructure-persistence templates.
9
+ - name-first scaffold generators for TypeORM file creation workflows.
10
+ - inferred database targets via `createNodesV2`.
11
+ - thin executors that wrap TypeORM CLI workflows.
15
12
 
16
13
  ## Installation
17
14
 
15
+ Use `nx add` so the plugin installs and runs `init` automatically:
16
+
18
17
  ```bash
19
- yarn add -D @anarchitects/nx-typeorm
18
+ nx add @anarchitects/nx-typeorm
20
19
  ```
21
20
 
22
- If you rely on TypeScript seeds or migrations, also add:
21
+ This registers the plugin in `nx.json` and installs minimal dependencies:
22
+ `typeorm` and `reflect-metadata`.
23
+
24
+ You can re-run initialization later:
23
25
 
24
26
  ```bash
25
- yarn add -D ts-node typeorm-ts-node-commonjs
27
+ nx g @anarchitects/nx-typeorm:init
26
28
  ```
27
29
 
28
- ## Usage
30
+ ## Generators
29
31
 
30
- ### Bootstrap a project
32
+ ### `init`
31
33
 
32
34
  ```bash
33
- nx g @anarchitects/nx-typeorm:bootstrap api --withCompose
35
+ nx g @anarchitects/nx-typeorm:init
34
36
  ```
35
37
 
36
- Creates TypeORM configuration files, seed/migration directories, and patches
37
- `app.module.ts` (for Nest apps) to use `TypeOrmModule.forRootAsync`.
38
+ - Registers `@anarchitects/nx-typeorm` in `nx.json > plugins`.
39
+ - Adds `typeorm` and `reflect-metadata`.
38
40
 
39
- ### Run migrations
41
+ ### `bootstrap`
40
42
 
41
43
  ```bash
42
- nx run api:run --transaction=each
44
+ nx g @anarchitects/nx-typeorm:bootstrap --project=api
43
45
  ```
44
46
 
45
- ### Generate a migration
47
+ For applications:
46
48
 
47
- ```bash
48
- nx run api:generate --name AddUsers --driftCheck
49
- ```
49
+ - generates runtime datasource in `src/data-source.ts`.
50
+ - generates compatibility re-export `src/typeorm.datasource.ts`.
51
+ - generates shared connection helper `tools/typeorm/connection-options.ts`.
52
+ - generates TypeORM CLI migration datasource
53
+ `tools/typeorm/datasource.migrations.ts` and seeds under `tools/typeorm`.
54
+ - preserves an existing `tools/typeorm/datasource.migrations.ts` file.
55
+ - generates a DB-specific `env.example` with URL/discrete modes.
56
+ - patches `app.module.ts` only when the app has a Nest module file.
57
+
58
+ For libraries:
59
+
60
+ - generates `schema.ts` and `1700000000000_init_schema.ts` under
61
+ `src/infrastructure-persistence` by default.
62
+ - supports overrides with:
63
+ - `--schemaPath=<relative-path>`
64
+ - `--migrationsDir=<relative-dir>`
65
+ - patches project metadata (`metadata.typeorm`) with schema/domain and paths.
66
+
67
+ Additional bootstrap dependencies are installed during bootstrap:
68
+ `ts-node`, `typeorm-ts-node-commonjs`, `typeorm-ts-node-esm`,
69
+ DB driver package for selected `--db`, and `@nestjs/typeorm` only for Nest
70
+ applications.
71
+
72
+ Supported `--db` values: `postgres`, `postgresql` (normalized to `postgres`),
73
+ `mysql`, `mariadb`, `sqlite`, `better-sqlite3`, `mssql`.
74
+
75
+ Generated app datasources support two connection modes:
76
+
77
+ - `DATABASE_URL`
78
+ - discrete `TYPEORM_*` variables
79
+
80
+ The generated helper rejects mixed mode (setting `DATABASE_URL` together with
81
+ `TYPEORM_*` connection variables) and throws clear validation errors when
82
+ required variables are missing.
50
83
 
51
- ### Revert migrations
84
+ ### Scaffolding generators
85
+
86
+ These are convenience wrappers around existing executors. They are invoked
87
+ manually via `nx g` and are not inferred targets.
88
+
89
+ `migration-create` (alias: `migration`)
52
90
 
53
91
  ```bash
54
- nx run api:revert --count=1
92
+ nx g @anarchitects/nx-typeorm:migration-create --project=api --name="add users"
93
+ nx g @anarchitects/nx-typeorm:migration --project=api --name="add users"
55
94
  ```
56
95
 
57
- ### Ensure schema
96
+ - required: `--project`, `--name`
97
+ - optional: `--directory` (relative to project root), `--outputJs`, `--esm`,
98
+ `--timestamp`, `--args`
99
+ - default output directory:
100
+ - app: `tools/typeorm/migrations`
101
+ - lib: `src/infrastructure-persistence/migrations`
102
+
103
+ `entity-create` (alias: `entity`)
58
104
 
59
105
  ```bash
60
- DATABASE_URL=postgres://... nx run data-access:ensure-schema
106
+ nx g @anarchitects/nx-typeorm:entity-create --project=api --name="user profile"
107
+ nx g @anarchitects/nx-typeorm:entity --project=api --name="user profile"
61
108
  ```
62
109
 
63
- ### Seed data
110
+ - required: `--project`, `--name`
111
+ - optional: `--directory` (relative to project root), `--args`
112
+ - default output directory:
113
+ - app: `src/entities`
114
+ - lib: `src/infrastructure-persistence/entities`
115
+
116
+ `subscriber-create` (alias: `subscriber`)
64
117
 
65
118
  ```bash
66
- nx run api:seed --file tools/typeorm/seeds/index.ts --export runSeed
119
+ nx g @anarchitects/nx-typeorm:subscriber-create --project=api --name="user subscriber"
120
+ nx g @anarchitects/nx-typeorm:subscriber --project=api --name="user subscriber"
67
121
  ```
68
122
 
69
- Each executor forwards any extra CLI arguments to the underlying TypeORM tool,
70
- making it easy to customize behavior.
123
+ - required: `--project`, `--name`
124
+ - optional: `--directory` (relative to project root), `--args`
125
+ - default output directory:
126
+ - app: `src/subscribers`
127
+ - lib: `src/infrastructure-persistence/subscribers`
128
+
129
+ ## Inferred Targets
130
+
131
+ When TypeORM files are detected, the plugin infers:
71
132
 
72
- ## Functionality Overview
133
+ - `db:migrate:generate`
134
+ - `db:migrate:run`
135
+ - `db:migrate:revert`
136
+ - `db:migrate:show`
137
+ - `db:schema:sync`
138
+ - `db:schema:log`
139
+ - `db:cache:clear`
140
+ - `db:ensure-schema`
141
+ - `db:seed` (applications)
73
142
 
74
- - **Executors**: `generate`, `run`, `revert`, `ensure-schema`, and `seed` wrap
75
- TypeORM commands with Nx-friendly ergonomics.
76
- - **Generator**: `bootstrap` lays down TypeORM config, seeds, migrations, and
77
- Nest integration boilerplate.
78
- - **Inference**: Detects TypeORM projects and auto adds sensible default targets
79
- when you run `nx graph` or `nx run` commands.
143
+ Compatibility aliases are also inferred:
80
144
 
81
- ## Tasks
145
+ - `typeorm:generate`
146
+ - `typeorm:run`
147
+ - `typeorm:revert`
148
+ - `typeorm:show`
149
+ - `typeorm:schema:sync`
150
+ - `typeorm:schema:log`
151
+ - `typeorm:cache:clear`
152
+ - `typeorm:ensure-schema`
153
+ - `typeorm:seed` (applications)
82
154
 
83
- - `nx build nx-typeorm` – build the plugin.
84
- - `nx test nx-typeorm` – run Jest unit tests.
155
+ ## Executor Usage
156
+
157
+ Run inferred targets:
158
+
159
+ ```bash
160
+ nx run api:db:migrate:run --transaction=each
161
+ nx run api:db:migrate:generate --name AddUsers
162
+ nx run api:db:migrate:revert --count=2
163
+ nx run api:db:migrate:show
164
+ nx run api:db:schema:sync
165
+ nx run api:db:schema:log
166
+ nx run api:db:cache:clear
167
+ nx run data-access:db:ensure-schema
168
+ nx run api:db:seed --file tools/typeorm/seeds/index.ts
169
+ ```
170
+
171
+ `generate` supports `--check` and compatibility alias `--driftCheck` (mapped to
172
+ TypeORM check mode).
173
+
174
+ Datasource-backed CLI executors (`generate`, `run`, `revert`,
175
+ `migration-show`, `schema-sync`, `schema-log`, `schema-drop`, `query`,
176
+ `cache-clear`) select the TypeORM runner at runtime:
177
+
178
+ - `moduleSystem=auto` (default): detect by nearest `package.json` `type`,
179
+ then project tsconfig module mode, then fall back to CommonJS.
180
+ - `moduleSystem=commonjs`: force `typeorm-ts-node-commonjs`.
181
+ - `moduleSystem=esm`: force `typeorm-ts-node-esm`.
182
+
183
+ When `dataSource` is omitted, datasource-backed executors (`generate`, `run`,
184
+ `revert`, `migration-show`, `schema-sync`, `schema-log`, `schema-drop`,
185
+ `query`, `cache-clear`) and `ensure-schema` infer it from the project with
186
+ this priority:
187
+
188
+ 1. `tools/typeorm/datasource.migrations.ts`
189
+ 2. `tools/typeorm/datasource.migrations.js`
190
+ 3. `src/data-source.ts`
191
+ 4. `src/data-source.js`
192
+ 5. `src/typeorm.datasource.ts`
193
+ 6. `src/typeorm.datasource.js`
194
+
195
+ Override inference at any time with `--dataSource=<relative-or-absolute-path>`.
196
+
197
+ ## TypeORM CLI Coverage
198
+
199
+ Inference is intentionally limited to convention-safe operational commands.
200
+ Scaffolding/meta commands (`migration:create`, `entity:create`,
201
+ `subscriber:create`, `version`, `init`) are executor-only and not inferred.
202
+
203
+ | TypeORM CLI command | nx-typeorm executor | Inferred target |
204
+ | -------------------- | ------------------- | --------------- |
205
+ | `migration:create` | `migration-create` | no |
206
+ | `migration:generate` | `generate` | yes |
207
+ | `migration:run` | `run` | yes |
208
+ | `migration:revert` | `revert` | yes |
209
+ | `migration:show` | `migration-show` | yes |
210
+ | `schema:sync` | `schema-sync` | yes |
211
+ | `schema:log` | `schema-log` | yes |
212
+ | `schema:drop` | `schema-drop` | no |
213
+ | `query` | `query` | no |
214
+ | `cache:clear` | `cache-clear` | yes |
215
+ | `entity:create` | `entity-create` | no |
216
+ | `subscriber:create` | `subscriber-create` | no |
217
+ | `version` | `version` | no |
218
+ | `init` | `init` | no |
219
+
220
+ Manual-only executors are available for explicit wiring in `project.json`.
221
+ This includes risky commands (`query`, `schema:drop`) and non-inferred
222
+ scaffolding/meta commands from the table above.
223
+
224
+ Example manual targets:
225
+
226
+ ```json
227
+ {
228
+ "targets": {
229
+ "db:query": {
230
+ "executor": "@anarchitects/nx-typeorm:query",
231
+ "options": {
232
+ "projectRoot": "apps/api",
233
+ "query": "SELECT 1"
234
+ }
235
+ },
236
+ "db:schema:drop": {
237
+ "executor": "@anarchitects/nx-typeorm:schema-drop",
238
+ "options": {
239
+ "projectRoot": "apps/api"
240
+ }
241
+ }
242
+ }
243
+ }
244
+ ```
@@ -0,0 +1,6 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { CacheClearExecutorOptions } from './schema.js';
3
+ export default function clearCache(options: CacheClearExecutorOptions, context: ExecutorContext): Promise<{
4
+ success: boolean;
5
+ }>;
6
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/cache-clear/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAE7D,wBAA8B,UAAU,CACtC,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE,eAAe;;GASzB"}
@@ -0,0 +1,5 @@
1
+ import { runDataSourceTypeormCommand } from '../../utils/cli.js';
2
+ export default async function clearCache(options, context) {
3
+ const exitCode = await runDataSourceTypeormCommand('cache:clear', options, context);
4
+ return { success: exitCode === 0 };
5
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "title": "TypeORM Cache Clear Executor",
4
+ "type": "object",
5
+ "properties": {
6
+ "projectRoot": {
7
+ "type": "string",
8
+ "description": "Project root when it cannot be inferred from the Nx project configuration."
9
+ },
10
+ "dataSource": {
11
+ "type": "string",
12
+ "description": "Path to the TypeORM data source file used for cache clearing."
13
+ },
14
+ "moduleSystem": {
15
+ "type": "string",
16
+ "enum": ["auto", "commonjs", "esm"],
17
+ "default": "auto",
18
+ "description": "Override module-system detection used to select the TypeORM CLI runner."
19
+ },
20
+ "args": {
21
+ "type": "array",
22
+ "items": {
23
+ "type": "string"
24
+ },
25
+ "description": "Additional CLI arguments passed through to the TypeORM command."
26
+ }
27
+ }
28
+ }
@@ -1,9 +1,5 @@
1
1
  import type { ExecutorContext } from '@nx/devkit';
2
- import { type BaseExecutorOptions } from '../shared.js';
3
- export interface EnsureSchemaExecutorOptions extends Pick<BaseExecutorOptions, 'projectRoot' | 'dataSource'> {
4
- schema?: string;
5
- tsconfig?: string;
6
- }
2
+ import type { EnsureSchemaExecutorOptions } from './schema.js';
7
3
  export default function ensureSchema(options: EnsureSchemaExecutorOptions, context: ExecutorContext): Promise<{
8
4
  success: boolean;
9
5
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/ensure-schema/executor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,2BACf,SAAQ,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,YAAY,CAAC;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAA8B,YAAY,CACxC,OAAO,EAAE,2BAA2B,EACpC,OAAO,EAAE,eAAe;;GAyEzB"}
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/ensure-schema/executor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAQlD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE/D,wBAA8B,YAAY,CACxC,OAAO,EAAE,2BAA2B,EACpC,OAAO,EAAE,eAAe;;GAyEzB"}
@@ -2,7 +2,7 @@ import { existsSync, readFileSync } from 'node:fs';
2
2
  import { resolve } from 'node:path';
3
3
  import { pathToFileURL } from 'node:url';
4
4
  import { logger } from '@nx/devkit';
5
- import { ensureProjectRoot, schemaFilePath, schemaNameFrom, } from '../shared.js';
5
+ import { ensureProjectRoot, schemaFilePath, schemaNameFrom, } from '../../utils/shared.js';
6
6
  export default async function ensureSchema(options, context) {
7
7
  const { absoluteProjectRoot, dataSource: dataSourcePath } = ensureProjectRoot({ projectRoot: options.projectRoot, dataSource: options.dataSource }, context);
8
8
  let schemaName = options.schema?.trim();
@@ -0,0 +1,6 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { EntityCreateExecutorOptions } from './schema.js';
3
+ export default function createEntity(options: EntityCreateExecutorOptions, context: ExecutorContext): Promise<{
4
+ success: boolean;
5
+ }>;
6
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/entity-create/executor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE/D,wBAA8B,YAAY,CACxC,OAAO,EAAE,2BAA2B,EACpC,OAAO,EAAE,eAAe;;GAczB"}
@@ -0,0 +1,15 @@
1
+ import { isAbsolute, join } from 'node:path';
2
+ import { runTypeormCommand } from '../../utils/cli.js';
3
+ import { resolveProjectRoot } from '../../utils/shared.js';
4
+ export default async function createEntity(options, context) {
5
+ const path = options.path?.trim();
6
+ if (!path) {
7
+ throw new Error('Provide an entity path via the path option.');
8
+ }
9
+ const { projectRoot } = resolveProjectRoot(options.projectRoot, context);
10
+ const targetPath = isAbsolute(path) ? path : join(projectRoot, path);
11
+ const exitCode = await runTypeormCommand('entity:create', options, context, [
12
+ targetPath,
13
+ ]);
14
+ return { success: exitCode === 0 };
15
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "title": "TypeORM Entity Create Executor",
4
+ "type": "object",
5
+ "properties": {
6
+ "path": {
7
+ "type": "string",
8
+ "description": "Path of the entity file."
9
+ },
10
+ "projectRoot": {
11
+ "type": "string",
12
+ "description": "Project root when it cannot be inferred from the Nx project configuration."
13
+ },
14
+ "args": {
15
+ "type": "array",
16
+ "items": {
17
+ "type": "string"
18
+ },
19
+ "description": "Additional CLI arguments passed through to the TypeORM command."
20
+ }
21
+ },
22
+ "required": ["path"]
23
+ }
@@ -1,11 +1,5 @@
1
1
  import type { ExecutorContext } from '@nx/devkit';
2
- import { type BaseExecutorOptions } from '../shared.js';
3
- export interface GenerateExecutorOptions extends BaseExecutorOptions {
4
- name: string;
5
- outputPath?: string;
6
- pretty?: boolean;
7
- driftCheck?: boolean;
8
- }
2
+ import type { GenerateExecutorOptions } from './schema.js';
9
3
  export default function runGenerate(options: GenerateExecutorOptions, context: ExecutorContext): Promise<{
10
4
  success: boolean;
11
5
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/generate/executor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAQL,KAAK,mBAAmB,EACzB,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAA8B,WAAW,CACvC,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,eAAe;;GAyCzB"}
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/generate/executor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAQlD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D,wBAA8B,WAAW,CACvC,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,eAAe;;GAiCzB"}
@@ -1,39 +1,27 @@
1
1
  import { mkdirSync } from 'node:fs';
2
2
  import { dirname, join } from 'node:path';
3
- import { getPackageManagerCommand } from '@nx/devkit';
4
- import { defaultMigrationsDirectory, ensureArgs, ensureProjectRoot, normalizeName, projectTypeFor, relativeToWorkspace, splitCommand, } from '../shared.js';
5
- import { spawn } from '../../utils/spawn.js';
3
+ import { defaultMigrationsDirectory, normalizeName, projectTypeFor, resolveProjectRoot, } from '../../utils/shared.js';
4
+ import { runDataSourceTypeormCommand } from '../../utils/cli.js';
6
5
  export default async function runGenerate(options, context) {
7
6
  if (!options.name || options.name.trim().length === 0) {
8
7
  throw new Error('Provide a migration name via the name option.');
9
8
  }
10
9
  const normalizedName = normalizeName(options.name.trim());
11
- const paths = ensureProjectRoot(options, context);
10
+ const { projectRoot } = resolveProjectRoot(options.projectRoot, context);
12
11
  const projectType = projectTypeFor(context);
13
- const outputDirectory = options.outputPath ??
14
- defaultMigrationsDirectory(paths.projectRoot, projectType);
12
+ const outputDirectory = options.outputPath ?? defaultMigrationsDirectory(projectRoot, projectType);
15
13
  const targetPath = join(outputDirectory, normalizedName);
16
14
  mkdirSync(dirname(targetPath), { recursive: true });
17
- const pmc = getPackageManagerCommand();
18
- const execCommand = pmc.exec ?? pmc.dlx ?? 'npx';
19
- const [command, baseArgs] = splitCommand(execCommand);
20
- const args = [
21
- ...baseArgs,
22
- 'typeorm-ts-node-commonjs',
23
- 'migration:generate',
24
- targetPath,
25
- '-d',
26
- relativeToWorkspace(context.root, paths.dataSource),
27
- '-n',
28
- normalizedName,
29
- ];
15
+ const afterDataSourceArgs = [];
30
16
  if (options.pretty ?? true) {
31
- args.push('--pretty');
17
+ afterDataSourceArgs.push('--pretty');
32
18
  }
33
- if (options.driftCheck) {
34
- args.push('--drift-check');
19
+ if (options.driftCheck || options.check) {
20
+ afterDataSourceArgs.push('--check');
35
21
  }
36
- args.push(...ensureArgs(options.args));
37
- const exitCode = await spawn(command, args, { cwd: context.root });
22
+ const exitCode = await runDataSourceTypeormCommand('migration:generate', options, context, {
23
+ beforeDataSourceArgs: [targetPath],
24
+ afterDataSourceArgs,
25
+ });
38
26
  return { success: exitCode === 0 };
39
27
  }
@@ -15,6 +15,12 @@
15
15
  "type": "string",
16
16
  "description": "Path to the TypeORM data source file used for migrations."
17
17
  },
18
+ "moduleSystem": {
19
+ "type": "string",
20
+ "enum": ["auto", "commonjs", "esm"],
21
+ "default": "auto",
22
+ "description": "Override module-system detection used to select the TypeORM CLI runner."
23
+ },
18
24
  "outputPath": {
19
25
  "type": "string",
20
26
  "description": "Directory where generated migrations will be placed."
@@ -26,7 +32,11 @@
26
32
  },
27
33
  "driftCheck": {
28
34
  "type": "boolean",
29
- "description": "Enable drift check before generating migrations."
35
+ "description": "Compatibility alias for TypeORM check mode (`--check`)."
36
+ },
37
+ "check": {
38
+ "type": "boolean",
39
+ "description": "Run TypeORM in check mode (`--check`) and fail when schema drift is detected."
30
40
  },
31
41
  "args": {
32
42
  "type": "array",
@@ -0,0 +1,6 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { InitExecutorOptions } from './schema.js';
3
+ export default function initTypeormProject(options: InitExecutorOptions, context: ExecutorContext): Promise<{
4
+ success: boolean;
5
+ }>;
6
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/init/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,wBAA8B,kBAAkB,CAC9C,OAAO,EAAE,mBAAmB,EAC5B,OAAO,EAAE,eAAe;;GA+BzB"}
@@ -0,0 +1,24 @@
1
+ import { runTypeormCommand } from '../../utils/cli.js';
2
+ export default async function initTypeormProject(options, context) {
3
+ const commandArgs = [];
4
+ if (options.name && options.name.trim().length > 0) {
5
+ commandArgs.push('--name', options.name.trim());
6
+ }
7
+ if (options.database && options.database.trim().length > 0) {
8
+ commandArgs.push('--database', options.database.trim());
9
+ }
10
+ if (options.express) {
11
+ commandArgs.push('--express');
12
+ }
13
+ if (options.docker) {
14
+ commandArgs.push('--docker');
15
+ }
16
+ if (options.manager) {
17
+ commandArgs.push('--manager', options.manager);
18
+ }
19
+ if (options.module) {
20
+ commandArgs.push('--module', options.module);
21
+ }
22
+ const exitCode = await runTypeormCommand('init', options, context, commandArgs);
23
+ return { success: exitCode === 0 };
24
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "title": "TypeORM Init Executor",
4
+ "type": "object",
5
+ "properties": {
6
+ "name": {
7
+ "type": "string",
8
+ "description": "Name of the generated TypeORM project directory."
9
+ },
10
+ "database": {
11
+ "type": "string",
12
+ "description": "Database type passed to TypeORM init."
13
+ },
14
+ "express": {
15
+ "type": "boolean",
16
+ "description": "Generate an Express sample project."
17
+ },
18
+ "docker": {
19
+ "type": "boolean",
20
+ "description": "Generate docker-compose output."
21
+ },
22
+ "manager": {
23
+ "type": "string",
24
+ "enum": ["npm", "yarn"],
25
+ "description": "Package manager used by TypeORM init."
26
+ },
27
+ "module": {
28
+ "type": "string",
29
+ "enum": ["commonjs", "esm"],
30
+ "description": "Module system used by TypeORM init."
31
+ },
32
+ "args": {
33
+ "type": "array",
34
+ "items": {
35
+ "type": "string"
36
+ },
37
+ "description": "Additional CLI arguments passed through to the TypeORM command."
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,6 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ import type { MigrationCreateExecutorOptions } from './schema.js';
3
+ export default function createMigration(options: MigrationCreateExecutorOptions, context: ExecutorContext): Promise<{
4
+ success: boolean;
5
+ }>;
6
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/migration-create/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAElE,wBAA8B,eAAe,CAC3C,OAAO,EAAE,8BAA8B,EACvC,OAAO,EAAE,eAAe;;GA0BzB"}
@@ -0,0 +1,19 @@
1
+ import { runTypeormCommand } from '../../utils/cli.js';
2
+ export default async function createMigration(options, context) {
3
+ const path = options.path?.trim();
4
+ if (!path) {
5
+ throw new Error('Provide a migration path via the path option.');
6
+ }
7
+ const commandArgs = [path];
8
+ if (options.outputJs) {
9
+ commandArgs.push('--outputJs');
10
+ }
11
+ if (options.esm) {
12
+ commandArgs.push('--esm');
13
+ }
14
+ if (typeof options.timestamp === 'number') {
15
+ commandArgs.push('--timestamp', `${options.timestamp}`);
16
+ }
17
+ const exitCode = await runTypeormCommand('migration:create', options, context, commandArgs);
18
+ return { success: exitCode === 0 };
19
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "title": "TypeORM Migration Create Executor",
4
+ "type": "object",
5
+ "properties": {
6
+ "path": {
7
+ "type": "string",
8
+ "description": "Path for the migration file."
9
+ },
10
+ "outputJs": {
11
+ "type": "boolean",
12
+ "description": "Generate JavaScript migration output."
13
+ },
14
+ "esm": {
15
+ "type": "boolean",
16
+ "description": "Generate ESM migration output."
17
+ },
18
+ "timestamp": {
19
+ "type": "number",
20
+ "description": "Custom migration timestamp."
21
+ },
22
+ "args": {
23
+ "type": "array",
24
+ "items": {
25
+ "type": "string"
26
+ },
27
+ "description": "Additional CLI arguments passed through to the TypeORM command."
28
+ }
29
+ },
30
+ "required": ["path"]
31
+ }