@anarchitects/nx-typeorm 0.1.0 → 0.3.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.
@@ -0,0 +1,37 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "title": "TypeORM Migration API Generator",
4
+ "type": "object",
5
+ "properties": {
6
+ "project": {
7
+ "type": "string",
8
+ "description": "Name of the existing Nx library project."
9
+ },
10
+ "name": {
11
+ "type": "string",
12
+ "description": "Migration name. Required when fileMode is \"new\"."
13
+ },
14
+ "fileMode": {
15
+ "type": "string",
16
+ "enum": ["new", "patch-init"],
17
+ "default": "new",
18
+ "description": "Create a new migration file or patch the bootstrap init migration."
19
+ },
20
+ "entityGlob": {
21
+ "type": "string",
22
+ "description": "Glob (relative to project root) used to discover entity files.",
23
+ "default": "src/infrastructure-persistence/entities/**/*.ts"
24
+ },
25
+ "allowMixedMigrations": {
26
+ "type": "boolean",
27
+ "description": "Allow generation when manual and tool-generated migrations coexist.",
28
+ "default": false
29
+ },
30
+ "timestamp": {
31
+ "type": "number",
32
+ "description": "Optional migration timestamp override."
33
+ }
34
+ },
35
+ "required": ["project"],
36
+ "additionalProperties": false
37
+ }
@@ -0,0 +1,4 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ import type { MigrationCreateGeneratorSchema } from './schema.js';
3
+ export default function migrationCreateGenerator(tree: Tree, options: MigrationCreateGeneratorSchema): Promise<void>;
4
+ //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/migration-create/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AAOpB,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAElE,wBAA8B,wBAAwB,CACpD,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,8BAA8B,iBA2BxC"}
@@ -0,0 +1,72 @@
1
+ import { readProjectConfiguration, } from '@nx/devkit';
2
+ import { isAbsolute, join, posix } from 'node:path';
3
+ import createMigration from '../../executors/migration-create/executor.js';
4
+ import { defaultMigrationsDirectory, normalizeName, } from '../../utils/shared.js';
5
+ export default async function migrationCreateGenerator(tree, options) {
6
+ const projectName = requireOption(options.project, 'project');
7
+ const migrationName = normalizeName(requireOption(options.name, 'name'));
8
+ const projectConfig = readProjectConfiguration(tree, projectName);
9
+ const targetDirectory = resolveMigrationDirectory(projectConfig.root, projectConfig.projectType, options.directory);
10
+ const targetPath = join(targetDirectory, migrationName);
11
+ const context = createExecutorContext(tree, projectName);
12
+ const result = await createMigration({
13
+ path: targetPath,
14
+ outputJs: options.outputJs,
15
+ esm: options.esm,
16
+ timestamp: options.timestamp,
17
+ args: options.args,
18
+ }, context);
19
+ if (!result.success) {
20
+ throw new Error('TypeORM migration:create failed.');
21
+ }
22
+ }
23
+ function resolveMigrationDirectory(projectRoot, projectType, directory) {
24
+ if (!directory) {
25
+ return defaultMigrationsDirectory(projectRoot, projectType);
26
+ }
27
+ const normalizedDirectory = normalizeRelativeDirectory(directory);
28
+ return join(projectRoot, normalizedDirectory);
29
+ }
30
+ function normalizeRelativeDirectory(directory) {
31
+ const trimmedDirectory = directory.trim();
32
+ if (trimmedDirectory.length === 0) {
33
+ throw new Error('Provide a non-empty directory when using the directory option.');
34
+ }
35
+ if (isAbsolute(trimmedDirectory)) {
36
+ throw new Error('The directory option must be relative to the project root.');
37
+ }
38
+ const normalizedDirectory = posix
39
+ .normalize(trimmedDirectory.replace(/\\/g, '/').replace(/^\.\//, ''))
40
+ .replace(/^\.\//, '');
41
+ if (normalizedDirectory.length === 0 ||
42
+ normalizedDirectory === '.' ||
43
+ normalizedDirectory === '..' ||
44
+ normalizedDirectory.startsWith('../')) {
45
+ throw new Error('The directory option must stay within the project root.');
46
+ }
47
+ return normalizedDirectory;
48
+ }
49
+ function requireOption(value, optionName) {
50
+ const trimmed = value?.trim();
51
+ if (!trimmed) {
52
+ throw new Error(`Provide a value for the ${optionName} option.`);
53
+ }
54
+ return trimmed;
55
+ }
56
+ function createExecutorContext(tree, projectName) {
57
+ const projectConfig = readProjectConfiguration(tree, projectName);
58
+ return {
59
+ root: tree.root,
60
+ projectName,
61
+ projectsConfigurations: {
62
+ version: 2,
63
+ projects: {
64
+ [projectName]: {
65
+ root: projectConfig.root,
66
+ projectType: projectConfig.projectType,
67
+ targets: projectConfig.targets ?? {},
68
+ },
69
+ },
70
+ },
71
+ };
72
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "title": "TypeORM Migration Create Generator",
4
+ "type": "object",
5
+ "properties": {
6
+ "project": {
7
+ "type": "string",
8
+ "description": "Name of the existing Nx project to scaffold a migration for."
9
+ },
10
+ "name": {
11
+ "type": "string",
12
+ "description": "Migration name. Spaces are normalized to hyphens."
13
+ },
14
+ "directory": {
15
+ "type": "string",
16
+ "description": "Optional directory relative to the project root where the migration should be created."
17
+ },
18
+ "outputJs": {
19
+ "type": "boolean",
20
+ "description": "Generate JavaScript migration output."
21
+ },
22
+ "esm": {
23
+ "type": "boolean",
24
+ "description": "Generate ESM migration output."
25
+ },
26
+ "timestamp": {
27
+ "type": "number",
28
+ "description": "Custom migration timestamp."
29
+ },
30
+ "args": {
31
+ "type": "array",
32
+ "items": {
33
+ "type": "string"
34
+ },
35
+ "description": "Additional CLI arguments passed through to TypeORM."
36
+ }
37
+ },
38
+ "required": ["project", "name"],
39
+ "additionalProperties": false
40
+ }
@@ -0,0 +1,4 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ import type { SubscriberCreateGeneratorSchema } from './schema.js';
3
+ export default function subscriberCreateGenerator(tree: Tree, options: SubscriberCreateGeneratorSchema): Promise<void>;
4
+ //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/subscriber-create/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AAIpB,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAEnE,wBAA8B,yBAAyB,CACrD,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,+BAA+B,iBAuBzC"}
@@ -0,0 +1,70 @@
1
+ import { joinPathFragments, readProjectConfiguration, } from '@nx/devkit';
2
+ import { isAbsolute, posix } from 'node:path';
3
+ import createSubscriber from '../../executors/subscriber-create/executor.js';
4
+ import { normalizeName } from '../../utils/shared.js';
5
+ export default async function subscriberCreateGenerator(tree, options) {
6
+ const projectName = requireOption(options.project, 'project');
7
+ const subscriberName = normalizeName(requireOption(options.name, 'name'));
8
+ const projectConfig = readProjectConfiguration(tree, projectName);
9
+ const targetDirectory = resolveTargetDirectory(projectConfig.projectType, options.directory);
10
+ const context = createExecutorContext(tree, projectName);
11
+ const result = await createSubscriber({
12
+ projectRoot: projectConfig.root,
13
+ path: joinPathFragments(targetDirectory, subscriberName),
14
+ args: options.args,
15
+ }, context);
16
+ if (!result.success) {
17
+ throw new Error('TypeORM subscriber:create failed.');
18
+ }
19
+ }
20
+ function resolveTargetDirectory(projectType, directory) {
21
+ if (!directory) {
22
+ return projectType === 'application'
23
+ ? 'src/subscribers'
24
+ : 'src/infrastructure-persistence/subscribers';
25
+ }
26
+ return normalizeRelativeDirectory(directory);
27
+ }
28
+ function normalizeRelativeDirectory(directory) {
29
+ const trimmedDirectory = directory.trim();
30
+ if (trimmedDirectory.length === 0) {
31
+ throw new Error('Provide a non-empty directory when using the directory option.');
32
+ }
33
+ if (isAbsolute(trimmedDirectory)) {
34
+ throw new Error('The directory option must be relative to the project root.');
35
+ }
36
+ const normalizedDirectory = posix
37
+ .normalize(trimmedDirectory.replace(/\\/g, '/').replace(/^\.\//, ''))
38
+ .replace(/^\.\//, '');
39
+ if (normalizedDirectory.length === 0 ||
40
+ normalizedDirectory === '.' ||
41
+ normalizedDirectory === '..' ||
42
+ normalizedDirectory.startsWith('../')) {
43
+ throw new Error('The directory option must stay within the project root.');
44
+ }
45
+ return normalizedDirectory;
46
+ }
47
+ function requireOption(value, optionName) {
48
+ const trimmed = value?.trim();
49
+ if (!trimmed) {
50
+ throw new Error(`Provide a value for the ${optionName} option.`);
51
+ }
52
+ return trimmed;
53
+ }
54
+ function createExecutorContext(tree, projectName) {
55
+ const projectConfig = readProjectConfiguration(tree, projectName);
56
+ return {
57
+ root: tree.root,
58
+ projectName,
59
+ projectsConfigurations: {
60
+ version: 2,
61
+ projects: {
62
+ [projectName]: {
63
+ root: projectConfig.root,
64
+ projectType: projectConfig.projectType,
65
+ targets: projectConfig.targets ?? {},
66
+ },
67
+ },
68
+ },
69
+ };
70
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "title": "TypeORM Subscriber Create Generator",
4
+ "type": "object",
5
+ "properties": {
6
+ "project": {
7
+ "type": "string",
8
+ "description": "Name of the existing Nx project to scaffold a subscriber for."
9
+ },
10
+ "name": {
11
+ "type": "string",
12
+ "description": "Subscriber name. Spaces are normalized to hyphens."
13
+ },
14
+ "directory": {
15
+ "type": "string",
16
+ "description": "Optional directory relative to the project root where the subscriber should be created."
17
+ },
18
+ "args": {
19
+ "type": "array",
20
+ "items": {
21
+ "type": "string"
22
+ },
23
+ "description": "Additional CLI arguments passed through to TypeORM."
24
+ }
25
+ },
26
+ "required": ["project", "name"],
27
+ "additionalProperties": false
28
+ }
package/dist/index.d.ts CHANGED
@@ -16,5 +16,13 @@ export { default as versionExecutor } from './executors/version/executor.js';
16
16
  export { default as initExecutor } from './executors/init/executor.js';
17
17
  export { default as initGenerator } from './generators/init/generator.js';
18
18
  export { default as bootstrapGenerator } from './generators/bootstrap/generator.js';
19
+ export { default as migrationCreateGenerator } from './generators/migration-create/generator.js';
20
+ export { default as migrationGenerator } from './generators/migration-create/generator.js';
21
+ export { default as migrationApiGenerator } from './generators/migration-api/generator.js';
22
+ export { default as migrationApiLibGenerator } from './generators/migration-api/generator.js';
23
+ export { default as entityCreateGenerator } from './generators/entity-create/generator.js';
24
+ export { default as entityGenerator } from './generators/entity-create/generator.js';
25
+ export { default as subscriberCreateGenerator } from './generators/subscriber-create/generator.js';
26
+ export { default as subscriberGenerator } from './generators/subscriber-create/generator.js';
19
27
  export { default } from './plugin/index.js';
20
28
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AACxF,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AAC9F,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC1F,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACpF,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACpF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACpF,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AACxF,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,2CAA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AAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AAChG,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACpF,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AACjG,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAC3F,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAC3F,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AAC9F,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAC3F,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AACnG,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AAE7F,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -16,4 +16,12 @@ export { default as versionExecutor } from './executors/version/executor.js';
16
16
  export { default as initExecutor } from './executors/init/executor.js';
17
17
  export { default as initGenerator } from './generators/init/generator.js';
18
18
  export { default as bootstrapGenerator } from './generators/bootstrap/generator.js';
19
+ export { default as migrationCreateGenerator } from './generators/migration-create/generator.js';
20
+ export { default as migrationGenerator } from './generators/migration-create/generator.js';
21
+ export { default as migrationApiGenerator } from './generators/migration-api/generator.js';
22
+ export { default as migrationApiLibGenerator } from './generators/migration-api/generator.js';
23
+ export { default as entityCreateGenerator } from './generators/entity-create/generator.js';
24
+ export { default as entityGenerator } from './generators/entity-create/generator.js';
25
+ export { default as subscriberCreateGenerator } from './generators/subscriber-create/generator.js';
26
+ export { default as subscriberGenerator } from './generators/subscriber-create/generator.js';
19
27
  export { default } from './plugin/index.js';
package/dist/index.json CHANGED
@@ -73,6 +73,38 @@
73
73
  "bootstrap": {
74
74
  "implementation": "./generators/bootstrap/generator",
75
75
  "schema": "./generators/bootstrap/schema.json"
76
+ },
77
+ "migration-create": {
78
+ "implementation": "./generators/migration-create/generator",
79
+ "schema": "./generators/migration-create/schema.json"
80
+ },
81
+ "migration": {
82
+ "implementation": "./generators/migration-create/generator",
83
+ "schema": "./generators/migration-create/schema.json"
84
+ },
85
+ "migration-api": {
86
+ "implementation": "./generators/migration-api/generator",
87
+ "schema": "./generators/migration-api/schema.json"
88
+ },
89
+ "migration-api-lib": {
90
+ "implementation": "./generators/migration-api/generator",
91
+ "schema": "./generators/migration-api/schema.json"
92
+ },
93
+ "entity-create": {
94
+ "implementation": "./generators/entity-create/generator",
95
+ "schema": "./generators/entity-create/schema.json"
96
+ },
97
+ "entity": {
98
+ "implementation": "./generators/entity-create/generator",
99
+ "schema": "./generators/entity-create/schema.json"
100
+ },
101
+ "subscriber-create": {
102
+ "implementation": "./generators/subscriber-create/generator",
103
+ "schema": "./generators/subscriber-create/schema.json"
104
+ },
105
+ "subscriber": {
106
+ "implementation": "./generators/subscriber-create/generator",
107
+ "schema": "./generators/subscriber-create/schema.json"
76
108
  }
77
109
  }
78
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anarchitects/nx-typeorm",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Nx plugin providing TypeORM executors, generators, and schema management utilities.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -13,8 +13,7 @@
13
13
  "!**/*.tsbuildinfo"
14
14
  ],
15
15
  "publishConfig": {
16
- "access": "public",
17
- "provenance": false
16
+ "access": "public"
18
17
  },
19
18
  "repository": {
20
19
  "type": "git",
@@ -62,7 +61,7 @@
62
61
  }
63
62
  },
64
63
  "peerDependencies": {
65
- "@nx/devkit": "^22.5.3",
64
+ "@nx/devkit": ">= 19 < 23",
66
65
  "ts-morph": "^22.0.0",
67
66
  "ts-node": "^10.9.1",
68
67
  "typeorm": "^0.3.27"