ts-prorm-orm 1.2.2 → 2.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/CHANGELOG.md +209 -0
- package/README.md +32 -24
- package/dist/compliance/index.d.ts +2 -0
- package/dist/compliance/index.js +13 -1
- package/dist/connection-manager.js +13 -1
- package/dist/core/expressions.d.ts +58 -0
- package/dist/core/expressions.js +83 -0
- package/dist/core/hooks-manager.d.ts +179 -0
- package/dist/core/hooks-manager.js +291 -0
- package/dist/core/types.d.ts +235 -0
- package/dist/core/types.js +9 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.js +11 -1
- package/dist/diagrams/chen-diagram.d.ts +15 -12
- package/dist/diagrams/chen-diagram.js +76 -85
- package/dist/diagrams/class-diagram.d.ts +9 -8
- package/dist/diagrams/class-diagram.js +60 -82
- package/dist/diagrams/core/index.d.ts +13 -0
- package/dist/diagrams/core/index.js +33 -0
- package/dist/diagrams/core/layout.d.ts +104 -0
- package/dist/diagrams/core/layout.js +223 -0
- package/dist/diagrams/{svg-dom.d.ts → core/svg.d.ts} +8 -20
- package/dist/diagrams/{svg-dom.js → core/svg.js} +21 -29
- package/dist/diagrams/core/theme.d.ts +84 -0
- package/dist/diagrams/core/theme.js +62 -0
- package/dist/diagrams/dependency-diagram.d.ts +15 -14
- package/dist/diagrams/dependency-diagram.js +71 -105
- package/dist/diagrams/er-diagram.d.ts +13 -26
- package/dist/diagrams/er-diagram.js +180 -259
- package/dist/diagrams/flow-diagram.d.ts +16 -11
- package/dist/diagrams/flow-diagram.js +96 -91
- package/dist/diagrams/gantt-diagram.d.ts +10 -5
- package/dist/diagrams/gantt-diagram.js +77 -103
- package/dist/diagrams/index-diagram.d.ts +10 -10
- package/dist/diagrams/index-diagram.js +106 -116
- package/dist/diagrams/index.d.ts +6 -9
- package/dist/diagrams/index.js +9 -24
- package/dist/diagrams/migration-diagram.d.ts +8 -4
- package/dist/diagrams/migration-diagram.js +189 -161
- package/dist/diagrams/model-diagram.d.ts +34 -34
- package/dist/diagrams/model-diagram.js +106 -485
- package/dist/diagrams/package-diagram.d.ts +9 -6
- package/dist/diagrams/package-diagram.js +64 -101
- package/dist/diagrams/relational-diagram.d.ts +12 -10
- package/dist/diagrams/relational-diagram.js +87 -114
- package/dist/diagrams/schemadoc-diagram.d.ts +8 -8
- package/dist/diagrams/schemadoc-diagram.js +71 -93
- package/dist/diagrams/sequence-diagram.d.ts +10 -10
- package/dist/diagrams/sequence-diagram.js +64 -89
- package/dist/diagrams/state-diagram.d.ts +10 -9
- package/dist/diagrams/state-diagram.js +69 -92
- package/dist/diagrams/tree-diagram.d.ts +11 -5
- package/dist/diagrams/tree-diagram.js +41 -65
- package/dist/dialects/clickhouse/index.js +15 -0
- package/dist/dialects/cockroachdb/index.d.ts +1 -1
- package/dist/dialects/cockroachdb/index.js +32 -63
- package/dist/dialects/db2/index.js +23 -8
- package/dist/dialects/dialect.d.ts +29 -5
- package/dist/dialects/duckdb/index.js +9 -2
- package/dist/dialects/hana/index.js +22 -5
- package/dist/dialects/lock-clause-helper.d.ts +167 -0
- package/dist/dialects/lock-clause-helper.js +316 -0
- package/dist/dialects/mariadb/index.d.ts +7 -4
- package/dist/dialects/mariadb/index.js +36 -60
- package/dist/dialects/mssql/index.js +34 -3
- package/dist/dialects/mysql/index.d.ts +1 -1
- package/dist/dialects/mysql/index.js +17 -45
- package/dist/dialects/oracle/index.d.ts +14 -3
- package/dist/dialects/oracle/index.js +66 -36
- package/dist/dialects/order-expression-helper.d.ts +72 -0
- package/dist/dialects/order-expression-helper.js +154 -0
- package/dist/dialects/partial-index.d.ts +52 -0
- package/dist/dialects/partial-index.js +251 -0
- package/dist/dialects/postgres/index.d.ts +1 -1
- package/dist/dialects/postgres/index.js +43 -68
- package/dist/dialects/redshift/index.js +9 -2
- package/dist/dialects/snowflake/index.js +17 -0
- package/dist/dialects/spanner/index.js +7 -2
- package/dist/dialects/sqlite/driver.d.ts +55 -0
- package/dist/dialects/sqlite/driver.js +102 -0
- package/dist/dialects/sqlite/index.d.ts +1 -1
- package/dist/dialects/sqlite/index.js +49 -27
- package/dist/graph/base-graph-dialect.d.ts +24 -3
- package/dist/graph/base-graph-dialect.js +43 -2
- package/dist/graph/dgraph/index.js +6 -0
- package/dist/graph/gremlin/index.d.ts +6 -0
- package/dist/graph/gremlin/index.js +12 -1
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/neo4j/index.d.ts +2 -0
- package/dist/graph/neo4j/index.js +6 -1
- package/dist/graph/types.d.ts +12 -1
- package/dist/index.d.ts +13 -4
- package/dist/index.js +54 -7
- package/dist/logging/index.d.ts +10 -0
- package/dist/logging/index.js +23 -0
- package/dist/logging/query-logging.d.ts +82 -0
- package/dist/logging/query-logging.js +102 -0
- package/dist/models/decorators.d.ts +39 -3
- package/dist/models/decorators.js +74 -0
- package/dist/models/eager-load.d.ts +99 -0
- package/dist/models/eager-load.js +348 -5
- package/dist/models/indexes.d.ts +3 -2
- package/dist/models/indexes.js +7 -1
- package/dist/models/model.js +69 -43
- package/dist/prorm.d.ts +175 -409
- package/dist/prorm.js +1142 -557
- package/dist/query-builders/order-limit-builder.js +12 -10
- package/dist/query-builders/sql-compiler.d.ts +10 -3
- package/dist/query-builders/sql-compiler.js +14 -43
- package/dist/query-interface.d.ts +2 -1
- package/dist/sql-constants.d.ts +44 -0
- package/dist/sql-constants.js +138 -1
- package/dist/types/index.d.ts +53 -17
- package/dist/types/index.js +10 -15
- package/dist/types/query-types.d.ts +26 -0
- package/dist/types/query-types.js +30 -0
- package/package.json +32 -5
- package/dist/decorators/belongs-to-many.js +0 -115
- package/dist/decorators/belongs-to.js +0 -115
- package/dist/decorators/has-many.js +0 -127
- package/dist/decorators/has-one.js +0 -116
- package/dist/diagrams/palette.d.ts +0 -138
- package/dist/diagrams/palette.js +0 -194
- package/dist/hooks/hooks-manager.d.ts +0 -189
- package/dist/hooks/hooks-manager.js +0 -350
- package/dist/hooks/index.d.ts +0 -8
- package/dist/hooks/index.js +0 -37
- /package/dist/{logging.d.ts → logging/logger.d.ts} +0 -0
- /package/dist/{logging.js → logging/logger.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-prorm-orm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "Malcolm Stone",
|
|
@@ -29,16 +29,36 @@
|
|
|
29
29
|
"require": "./dist/index.js",
|
|
30
30
|
"types": "./dist/index.d.ts"
|
|
31
31
|
},
|
|
32
|
+
"./cache": {
|
|
33
|
+
"types": "./dist/cache/index.d.ts",
|
|
34
|
+
"import": "./dist/cache/index.js",
|
|
35
|
+
"require": "./dist/cache/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./audit": {
|
|
38
|
+
"types": "./dist/audit/index.d.ts",
|
|
39
|
+
"import": "./dist/audit/index.js",
|
|
40
|
+
"require": "./dist/audit/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./graph": {
|
|
43
|
+
"types": "./dist/graph/index.d.ts",
|
|
44
|
+
"import": "./dist/graph/index.js",
|
|
45
|
+
"require": "./dist/graph/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./prisma-migrate": {
|
|
48
|
+
"types": "./dist/prisma-migrate/index.d.ts",
|
|
49
|
+
"import": "./dist/prisma-migrate/index.js",
|
|
50
|
+
"require": "./dist/prisma-migrate/index.js"
|
|
51
|
+
},
|
|
32
52
|
"./package.json": "./package.json"
|
|
33
53
|
},
|
|
34
54
|
"scripts": {
|
|
35
|
-
"build": "tsc",
|
|
55
|
+
"build": "npm run clean && tsc",
|
|
36
56
|
"clean": "rm -rf dist",
|
|
37
57
|
"dev": "tsc --watch",
|
|
38
58
|
"test": "jest",
|
|
39
59
|
"test:legacy": "node dist/test.js",
|
|
40
60
|
"test:watch": "jest --watch",
|
|
41
|
-
"test:coverage": "jest --coverage",
|
|
61
|
+
"test:coverage": "jest --coverage --maxWorkers=50%",
|
|
42
62
|
"model:create": "ts-node src/cli.ts model:create",
|
|
43
63
|
"model:create:help": "ts-node src/cli.ts help",
|
|
44
64
|
"diagram:model": "ts-node src/cli.ts diagram:model",
|
|
@@ -55,7 +75,8 @@
|
|
|
55
75
|
"prepublishOnly": "npm run build && npm run check:package && npm run test",
|
|
56
76
|
"prepare": "husky",
|
|
57
77
|
"docs:reference": "typedoc",
|
|
58
|
-
"check:package": "node scripts/check-package.mjs"
|
|
78
|
+
"check:package": "node scripts/check-package.mjs",
|
|
79
|
+
"build:incremental": "tsc"
|
|
59
80
|
},
|
|
60
81
|
"bin": {
|
|
61
82
|
"prorm": "dist/cli.js",
|
|
@@ -180,7 +201,13 @@
|
|
|
180
201
|
"jest-junit"
|
|
181
202
|
],
|
|
182
203
|
"workerIdleMemoryLimit": "256MB",
|
|
183
|
-
"coverageProvider": "v8"
|
|
204
|
+
"coverageProvider": "v8",
|
|
205
|
+
"collectCoverageFrom": [
|
|
206
|
+
"src/**/*.ts",
|
|
207
|
+
"!src/test.ts",
|
|
208
|
+
"!src/models/virtual-field-example.ts",
|
|
209
|
+
"!src/**/*.d.ts"
|
|
210
|
+
]
|
|
184
211
|
},
|
|
185
212
|
"jest-junit": {
|
|
186
213
|
"outputDirectory": ".",
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* BelongsToMany decorator for the ORM.
|
|
4
|
-
*
|
|
5
|
-
* Defines a many-to-many relationship between models via a join table/model.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
*
|
|
9
|
-
* @BelongsToMany(() => Role, { through: 'user_roles' })
|
|
10
|
-
* roles: Role[];
|
|
11
|
-
*
|
|
12
|
-
* @BelongsToMany(() => Role, { through: UserRole, as: 'assignedRoles' })
|
|
13
|
-
* assignedRoles: Role[];
|
|
14
|
-
*
|
|
15
|
-
* // With options
|
|
16
|
-
* @BelongsToMany(() => Tag, {
|
|
17
|
-
* through: 'post_tags',
|
|
18
|
-
* foreignKey: 'post_id',
|
|
19
|
-
* otherKey: 'tag_id',
|
|
20
|
-
* onDelete: 'CASCADE'
|
|
21
|
-
* })
|
|
22
|
-
* tags: Tag[];
|
|
23
|
-
*/
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.getBelongsToMany = getBelongsToMany;
|
|
26
|
-
exports.getAllBelongsToMany = getAllBelongsToMany;
|
|
27
|
-
exports.BelongsToMany = BelongsToMany;
|
|
28
|
-
exports.processBelongsToManyDecorators = processBelongsToManyDecorators;
|
|
29
|
-
// ==================== Metadata Storage ====================
|
|
30
|
-
const BELONGS_TO_MANY_KEY = '__orm_belongs_to_many__';
|
|
31
|
-
/**
|
|
32
|
-
* Get all @BelongsToMany annotations attached to a model constructor.
|
|
33
|
-
*/
|
|
34
|
-
function getBelongsToMany(target) {
|
|
35
|
-
return target[BELONGS_TO_MANY_KEY] || [];
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Get all belongsToMany associations including inherited ones.
|
|
39
|
-
*/
|
|
40
|
-
function getAllBelongsToMany(target) {
|
|
41
|
-
const associations = [];
|
|
42
|
-
let current = target;
|
|
43
|
-
while (current && current.prototype) {
|
|
44
|
-
const meta = getBelongsToMany(current);
|
|
45
|
-
associations.push(...meta);
|
|
46
|
-
current = Object.getPrototypeOf(current);
|
|
47
|
-
if (current === Object.prototype)
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
return associations;
|
|
51
|
-
}
|
|
52
|
-
// ==================== Decorator ====================
|
|
53
|
-
/**
|
|
54
|
-
* Define a many-to-many relationship.
|
|
55
|
-
*
|
|
56
|
-
* This decorator stores metadata on the model class that can be used
|
|
57
|
-
* by the ORM to establish the association at model initialization time.
|
|
58
|
-
*
|
|
59
|
-
* @param target - A function that returns the target model class
|
|
60
|
-
* @param options - Configuration for the association (through is required)
|
|
61
|
-
*/
|
|
62
|
-
function BelongsToMany(target, options) {
|
|
63
|
-
return function (prototype, propertyKey) {
|
|
64
|
-
const ModelClass = prototype.constructor;
|
|
65
|
-
if (!ModelClass[BELONGS_TO_MANY_KEY]) {
|
|
66
|
-
ModelClass[BELONGS_TO_MANY_KEY] = [];
|
|
67
|
-
}
|
|
68
|
-
ModelClass[BELONGS_TO_MANY_KEY].push({
|
|
69
|
-
target,
|
|
70
|
-
options: {
|
|
71
|
-
as: options.as || propertyKey.toString(),
|
|
72
|
-
through: options.through,
|
|
73
|
-
foreignKey: options.foreignKey,
|
|
74
|
-
otherKey: options.otherKey,
|
|
75
|
-
constraints: options.constraints,
|
|
76
|
-
onDelete: options.onDelete,
|
|
77
|
-
onUpdate: options.onUpdate,
|
|
78
|
-
targetKey: options.targetKey,
|
|
79
|
-
sourceKey: options.sourceKey,
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Process @BelongsToMany decorators and create association configuration.
|
|
86
|
-
*
|
|
87
|
-
* Call this to get the raw association definitions from decorators.
|
|
88
|
-
*
|
|
89
|
-
* @param ModelClass - The model class with @BelongsToMany decorators
|
|
90
|
-
* @returns Array of association configurations
|
|
91
|
-
*/
|
|
92
|
-
function processBelongsToManyDecorators(ModelClass) {
|
|
93
|
-
const decorators = getAllBelongsToMany(ModelClass);
|
|
94
|
-
return decorators.map(({ target, options }) => {
|
|
95
|
-
const targetModel = target();
|
|
96
|
-
const foreignKey = typeof options.foreignKey === 'string'
|
|
97
|
-
? options.foreignKey
|
|
98
|
-
: options.foreignKey?.name
|
|
99
|
-
? options.foreignKey.name
|
|
100
|
-
: `${ModelClass.name}Id`;
|
|
101
|
-
return {
|
|
102
|
-
source: ModelClass,
|
|
103
|
-
target: targetModel,
|
|
104
|
-
foreignKey,
|
|
105
|
-
as: options.as || '',
|
|
106
|
-
options,
|
|
107
|
-
};
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
exports.default = {
|
|
111
|
-
BelongsToMany,
|
|
112
|
-
getBelongsToMany,
|
|
113
|
-
getAllBelongsToMany,
|
|
114
|
-
processBelongsToManyDecorators,
|
|
115
|
-
};
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* BelongsTo decorator for the ORM.
|
|
4
|
-
*
|
|
5
|
-
* Defines a many-to-one (inverse of hasOne/hasMany) relationship between models.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
*
|
|
9
|
-
* @BelongsTo(() => User)
|
|
10
|
-
* user: User;
|
|
11
|
-
*
|
|
12
|
-
* @BelongsTo(() => User, { as: 'author' })
|
|
13
|
-
* author: User;
|
|
14
|
-
*
|
|
15
|
-
* // With options
|
|
16
|
-
* @BelongsTo(() => Category, {
|
|
17
|
-
* foreignKey: { name: 'category_id', allowNull: false },
|
|
18
|
-
* onDelete: 'CASCADE'
|
|
19
|
-
* })
|
|
20
|
-
* category: Category;
|
|
21
|
-
*
|
|
22
|
-
* // Self-referential
|
|
23
|
-
* @BelongsTo(() => User, { as: 'manager', foreignKey: 'manager_id' })
|
|
24
|
-
* manager: User;
|
|
25
|
-
*/
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.getBelongsTo = getBelongsTo;
|
|
28
|
-
exports.getAllBelongsTo = getAllBelongsTo;
|
|
29
|
-
exports.BelongsTo = BelongsTo;
|
|
30
|
-
exports.processBelongsToDecorators = processBelongsToDecorators;
|
|
31
|
-
// ==================== Metadata Storage ====================
|
|
32
|
-
const BELONGS_TO_KEY = '__orm_belongs_to__';
|
|
33
|
-
/**
|
|
34
|
-
* Get all @BelongsTo annotations attached to a model constructor.
|
|
35
|
-
*/
|
|
36
|
-
function getBelongsTo(target) {
|
|
37
|
-
return target[BELONGS_TO_KEY] || [];
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Get all belongsTo associations including inherited ones.
|
|
41
|
-
*/
|
|
42
|
-
function getAllBelongsTo(target) {
|
|
43
|
-
const associations = [];
|
|
44
|
-
let current = target;
|
|
45
|
-
while (current && current.prototype) {
|
|
46
|
-
const meta = getBelongsTo(current);
|
|
47
|
-
associations.push(...meta);
|
|
48
|
-
current = Object.getPrototypeOf(current);
|
|
49
|
-
if (current === Object.prototype)
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
return associations;
|
|
53
|
-
}
|
|
54
|
-
// ==================== Decorator ====================
|
|
55
|
-
/**
|
|
56
|
-
* Define a many-to-one relationship.
|
|
57
|
-
*
|
|
58
|
-
* This decorator stores metadata on the model class that can be used
|
|
59
|
-
* by the ORM to establish the association at model initialization time.
|
|
60
|
-
*
|
|
61
|
-
* @param target - A function that returns the target model class
|
|
62
|
-
* @param options - Optional configuration for the association
|
|
63
|
-
*/
|
|
64
|
-
function BelongsTo(target, options = {}) {
|
|
65
|
-
return function (prototype, propertyKey) {
|
|
66
|
-
const ModelClass = prototype.constructor;
|
|
67
|
-
if (!ModelClass[BELONGS_TO_KEY]) {
|
|
68
|
-
ModelClass[BELONGS_TO_KEY] = [];
|
|
69
|
-
}
|
|
70
|
-
ModelClass[BELONGS_TO_KEY].push({
|
|
71
|
-
target,
|
|
72
|
-
options: {
|
|
73
|
-
as: options.as || propertyKey.toString(),
|
|
74
|
-
foreignKey: options.foreignKey,
|
|
75
|
-
constraints: options.constraints,
|
|
76
|
-
onDelete: options.onDelete,
|
|
77
|
-
onUpdate: options.onUpdate,
|
|
78
|
-
targetKey: options.targetKey,
|
|
79
|
-
sourceKey: options.sourceKey,
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Process @BelongsTo decorators and create association configuration.
|
|
86
|
-
*
|
|
87
|
-
* Call this to get the raw association definitions from decorators.
|
|
88
|
-
*
|
|
89
|
-
* @param ModelClass - The model class with @BelongsTo decorators
|
|
90
|
-
* @returns Array of association configurations
|
|
91
|
-
*/
|
|
92
|
-
function processBelongsToDecorators(ModelClass) {
|
|
93
|
-
const decorators = getAllBelongsTo(ModelClass);
|
|
94
|
-
return decorators.map(({ target, options }) => {
|
|
95
|
-
const targetModel = target();
|
|
96
|
-
const foreignKey = typeof options.foreignKey === 'string'
|
|
97
|
-
? options.foreignKey
|
|
98
|
-
: options.foreignKey?.name
|
|
99
|
-
? options.foreignKey.name
|
|
100
|
-
: `${targetModel.name}Id`;
|
|
101
|
-
return {
|
|
102
|
-
source: ModelClass,
|
|
103
|
-
target: targetModel,
|
|
104
|
-
foreignKey,
|
|
105
|
-
as: options.as || '',
|
|
106
|
-
options,
|
|
107
|
-
};
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
exports.default = {
|
|
111
|
-
BelongsTo,
|
|
112
|
-
getBelongsTo,
|
|
113
|
-
getAllBelongsTo,
|
|
114
|
-
processBelongsToDecorators,
|
|
115
|
-
};
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* HasMany decorator for the ORM.
|
|
4
|
-
*
|
|
5
|
-
* Defines a one-to-many relationship between models.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
*
|
|
9
|
-
* @HasMany(() => Post)
|
|
10
|
-
* posts: Post[];
|
|
11
|
-
*
|
|
12
|
-
* @HasMany(() => Post, { as: 'articles' })
|
|
13
|
-
* articles: Post[];
|
|
14
|
-
*
|
|
15
|
-
* // With options
|
|
16
|
-
* @HasMany(() => Order, {
|
|
17
|
-
* foreignKey: { name: 'user_id', allowNull: false },
|
|
18
|
-
* onDelete: 'CASCADE',
|
|
19
|
-
* through: 'user_orders' // For belongsToMany
|
|
20
|
-
* })
|
|
21
|
-
* orders: Order[];
|
|
22
|
-
*
|
|
23
|
-
* // Self-referential
|
|
24
|
-
* @HasMany(() => Category, { as: 'children', foreignKey: 'parent_id' })
|
|
25
|
-
* children: Category[];
|
|
26
|
-
*
|
|
27
|
-
* // Nested hasMany with scope
|
|
28
|
-
* @HasMany(() => Comment, {
|
|
29
|
-
* as: 'replies',
|
|
30
|
-
* foreignKey: 'parent_id',
|
|
31
|
-
* scope: { deleted: false }
|
|
32
|
-
* })
|
|
33
|
-
* replies: Comment[];
|
|
34
|
-
*/
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.getHasMany = getHasMany;
|
|
37
|
-
exports.getAllHasMany = getAllHasMany;
|
|
38
|
-
exports.HasMany = HasMany;
|
|
39
|
-
exports.processHasManyDecorators = processHasManyDecorators;
|
|
40
|
-
// ==================== Metadata Storage ====================
|
|
41
|
-
const HAS_MANY_KEY = '__orm_has_many__';
|
|
42
|
-
/**
|
|
43
|
-
* Get all @HasMany annotations attached to a model constructor.
|
|
44
|
-
*/
|
|
45
|
-
function getHasMany(target) {
|
|
46
|
-
return target[HAS_MANY_KEY] || [];
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Get all hasMany associations including inherited ones.
|
|
50
|
-
*/
|
|
51
|
-
function getAllHasMany(target) {
|
|
52
|
-
const associations = [];
|
|
53
|
-
let current = target;
|
|
54
|
-
while (current && current.prototype) {
|
|
55
|
-
const meta = getHasMany(current);
|
|
56
|
-
associations.push(...meta);
|
|
57
|
-
current = Object.getPrototypeOf(current);
|
|
58
|
-
if (current === Object.prototype)
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
return associations;
|
|
62
|
-
}
|
|
63
|
-
// ==================== Decorator ====================
|
|
64
|
-
/**
|
|
65
|
-
* Define a one-to-many relationship.
|
|
66
|
-
*
|
|
67
|
-
* This decorator stores metadata on the model class that can be used
|
|
68
|
-
* by the ORM to establish the association at model initialization time.
|
|
69
|
-
*
|
|
70
|
-
* @param target - A function that returns the target model class
|
|
71
|
-
* @param options - Optional configuration for the association
|
|
72
|
-
*/
|
|
73
|
-
function HasMany(target, options = {}) {
|
|
74
|
-
return function (prototype, propertyKey) {
|
|
75
|
-
const ModelClass = prototype.constructor;
|
|
76
|
-
if (!ModelClass[HAS_MANY_KEY]) {
|
|
77
|
-
ModelClass[HAS_MANY_KEY] = [];
|
|
78
|
-
}
|
|
79
|
-
ModelClass[HAS_MANY_KEY].push({
|
|
80
|
-
target,
|
|
81
|
-
options: {
|
|
82
|
-
as: options.as || propertyKey.toString(),
|
|
83
|
-
foreignKey: options.foreignKey,
|
|
84
|
-
constraints: options.constraints,
|
|
85
|
-
onDelete: options.onDelete,
|
|
86
|
-
onUpdate: options.onUpdate,
|
|
87
|
-
targetKey: options.targetKey,
|
|
88
|
-
sourceKey: options.sourceKey,
|
|
89
|
-
scope: options.scope,
|
|
90
|
-
through: options.through,
|
|
91
|
-
inverse: options.inverse,
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Process @HasMany decorators and create association configuration.
|
|
98
|
-
*
|
|
99
|
-
* Call this to get the raw association definitions from decorators.
|
|
100
|
-
*
|
|
101
|
-
* @param ModelClass - The model class with @HasMany decorators
|
|
102
|
-
* @returns Array of association configurations
|
|
103
|
-
*/
|
|
104
|
-
function processHasManyDecorators(ModelClass) {
|
|
105
|
-
const decorators = getAllHasMany(ModelClass);
|
|
106
|
-
return decorators.map(({ target, options }) => {
|
|
107
|
-
const targetModel = target();
|
|
108
|
-
const foreignKey = typeof options.foreignKey === 'string'
|
|
109
|
-
? options.foreignKey
|
|
110
|
-
: options.foreignKey?.name
|
|
111
|
-
? options.foreignKey.name
|
|
112
|
-
: `${ModelClass.name}Id`;
|
|
113
|
-
return {
|
|
114
|
-
source: ModelClass,
|
|
115
|
-
target: targetModel,
|
|
116
|
-
foreignKey,
|
|
117
|
-
as: options.as || '',
|
|
118
|
-
options,
|
|
119
|
-
};
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
exports.default = {
|
|
123
|
-
HasMany,
|
|
124
|
-
getHasMany,
|
|
125
|
-
getAllHasMany,
|
|
126
|
-
processHasManyDecorators,
|
|
127
|
-
};
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* HasOne decorator for the ORM.
|
|
4
|
-
*
|
|
5
|
-
* Defines a one-to-one relationship between models.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
*
|
|
9
|
-
* @HasOne(() => Profile)
|
|
10
|
-
* profile: Profile;
|
|
11
|
-
*
|
|
12
|
-
* @HasOne(() => Profile, { as: 'userProfile' })
|
|
13
|
-
* userProfile: Profile;
|
|
14
|
-
*
|
|
15
|
-
* // With options
|
|
16
|
-
* @HasOne(() => Profile, {
|
|
17
|
-
* foreignKey: { name: 'user_id', allowNull: false },
|
|
18
|
-
* onDelete: 'CASCADE'
|
|
19
|
-
* })
|
|
20
|
-
* profile: Profile;
|
|
21
|
-
*
|
|
22
|
-
* // Self-referential
|
|
23
|
-
* @HasOne(() => User, { as: 'manager', foreignKey: 'manager_id' })
|
|
24
|
-
* manager: User;
|
|
25
|
-
*/
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.getHasOne = getHasOne;
|
|
28
|
-
exports.getAllHasOne = getAllHasOne;
|
|
29
|
-
exports.HasOne = HasOne;
|
|
30
|
-
exports.processHasOneDecorators = processHasOneDecorators;
|
|
31
|
-
// ==================== Metadata Storage ====================
|
|
32
|
-
const HAS_ONE_KEY = '__orm_has_one__';
|
|
33
|
-
/**
|
|
34
|
-
* Get all @HasOne annotations attached to a model constructor.
|
|
35
|
-
*/
|
|
36
|
-
function getHasOne(target) {
|
|
37
|
-
return target[HAS_ONE_KEY] || [];
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Get all hasOne associations including inherited ones.
|
|
41
|
-
*/
|
|
42
|
-
function getAllHasOne(target) {
|
|
43
|
-
const associations = [];
|
|
44
|
-
let current = target;
|
|
45
|
-
while (current && current.prototype) {
|
|
46
|
-
const meta = getHasOne(current);
|
|
47
|
-
associations.push(...meta);
|
|
48
|
-
current = Object.getPrototypeOf(current);
|
|
49
|
-
if (current === Object.prototype)
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
return associations;
|
|
53
|
-
}
|
|
54
|
-
// ==================== Decorator ====================
|
|
55
|
-
/**
|
|
56
|
-
* Define a one-to-one relationship.
|
|
57
|
-
*
|
|
58
|
-
* This decorator stores metadata on the model class that can be used
|
|
59
|
-
* by the ORM to establish the association at model initialization time.
|
|
60
|
-
*
|
|
61
|
-
* @param target - A function that returns the target model class
|
|
62
|
-
* @param options - Optional configuration for the association
|
|
63
|
-
*/
|
|
64
|
-
function HasOne(target, options = {}) {
|
|
65
|
-
return function (prototype, propertyKey) {
|
|
66
|
-
const ModelClass = prototype.constructor;
|
|
67
|
-
if (!ModelClass[HAS_ONE_KEY]) {
|
|
68
|
-
ModelClass[HAS_ONE_KEY] = [];
|
|
69
|
-
}
|
|
70
|
-
ModelClass[HAS_ONE_KEY].push({
|
|
71
|
-
target,
|
|
72
|
-
options: {
|
|
73
|
-
as: options.as || propertyKey.toString(),
|
|
74
|
-
foreignKey: options.foreignKey,
|
|
75
|
-
constraints: options.constraints,
|
|
76
|
-
onDelete: options.onDelete,
|
|
77
|
-
onUpdate: options.onUpdate,
|
|
78
|
-
targetKey: options.targetKey,
|
|
79
|
-
sourceKey: options.sourceKey,
|
|
80
|
-
inverse: options.inverse,
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Process @HasOne decorators and create association configuration.
|
|
87
|
-
*
|
|
88
|
-
* Call this to get the raw association definitions from decorators.
|
|
89
|
-
*
|
|
90
|
-
* @param ModelClass - The model class with @HasOne decorators
|
|
91
|
-
* @returns Array of association configurations
|
|
92
|
-
*/
|
|
93
|
-
function processHasOneDecorators(ModelClass) {
|
|
94
|
-
const decorators = getAllHasOne(ModelClass);
|
|
95
|
-
return decorators.map(({ target, options }) => {
|
|
96
|
-
const targetModel = target();
|
|
97
|
-
const foreignKey = typeof options.foreignKey === 'string'
|
|
98
|
-
? options.foreignKey
|
|
99
|
-
: options.foreignKey?.name
|
|
100
|
-
? options.foreignKey.name
|
|
101
|
-
: `${ModelClass.name}Id`;
|
|
102
|
-
return {
|
|
103
|
-
source: ModelClass,
|
|
104
|
-
target: targetModel,
|
|
105
|
-
foreignKey,
|
|
106
|
-
as: options.as || '',
|
|
107
|
-
options,
|
|
108
|
-
};
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
exports.default = {
|
|
112
|
-
HasOne,
|
|
113
|
-
getHasOne,
|
|
114
|
-
getAllHasOne,
|
|
115
|
-
processHasOneDecorators,
|
|
116
|
-
};
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared accent-color and theme resolution for the diagram generators.
|
|
3
|
-
*
|
|
4
|
-
* `--color <name>` (or a custom hex string) picks an accent palette used for
|
|
5
|
-
* header bars / banners / entity colors.
|
|
6
|
-
* `--theme light|dark` picks a background/text theme.
|
|
7
|
-
*
|
|
8
|
-
* Both are genuinely applied by ModelDiagram, ERDiagram, RelationalDiagram,
|
|
9
|
-
* SchemaDocDiagram, ChenDiagram (and MigrationDiagram) — changing either flag
|
|
10
|
-
* changes real fill/stroke values in the generated SVG.
|
|
11
|
-
*
|
|
12
|
-
* ─── Industry design system ────────────────────────────────────────────────
|
|
13
|
-
* The DEFAULT look is the "Industry" blueprint design: a #f2f2f3 ground, white
|
|
14
|
-
* cards, hairline dividers, square corners, a solid #5980a6 accent header bar,
|
|
15
|
-
* and Barlow / Barlow Condensed / JetBrains Mono typography. The old vibrant
|
|
16
|
-
* multi-stop gradient palettes are retained as explicit `--color` overrides,
|
|
17
|
-
* but `industry` is now `ACCENT_PALETTES[0]` (the fallback of `resolveAccent`).
|
|
18
|
-
*
|
|
19
|
-
* The exported API is intentionally stable — `AccentPalette` / `ThemeColors`
|
|
20
|
-
* keep their existing fields (new fields are additive & optional), and
|
|
21
|
-
* `resolveAccent` / `resolveTheme` / `rotatedPalettes` keep their signatures —
|
|
22
|
-
* so sibling generators and other callers that import them keep working.
|
|
23
|
-
*/
|
|
24
|
-
export interface AccentPalette {
|
|
25
|
-
name: string;
|
|
26
|
-
/** Darkest gradient stop / primary header color (also used as a solid fill) */
|
|
27
|
-
from: string;
|
|
28
|
-
/** Mid gradient stop — the canonical solid accent fill in the Industry look */
|
|
29
|
-
mid: string;
|
|
30
|
-
/** Lightest gradient stop (used for 3-stop gradients / light accents) */
|
|
31
|
-
to: string;
|
|
32
|
-
/** Light background tint (badges, footers) */
|
|
33
|
-
light: string;
|
|
34
|
-
/** Readable text color on `light` background */
|
|
35
|
-
text: string;
|
|
36
|
-
/** Secondary accent (blueprint two-tone; FK marks, alt entities) */
|
|
37
|
-
accent2?: string;
|
|
38
|
-
/** Light tint of the secondary accent */
|
|
39
|
-
accent2Light?: string;
|
|
40
|
-
/** Readable text on `accent2Light` */
|
|
41
|
-
accent2Text?: string;
|
|
42
|
-
}
|
|
43
|
-
export declare const INDUSTRY: {
|
|
44
|
-
readonly ground: "#f2f2f3";
|
|
45
|
-
readonly surface: "#e9e9ea";
|
|
46
|
-
readonly card: "#ffffff";
|
|
47
|
-
readonly text: "#1d1f20";
|
|
48
|
-
readonly muted: "#7a7a7d";
|
|
49
|
-
readonly accent: "#5980a6";
|
|
50
|
-
readonly accent2: "#728fab";
|
|
51
|
-
readonly accentLight: "#eef6ff";
|
|
52
|
-
readonly accentText: "#2c455d";
|
|
53
|
-
readonly accent2Light: "#d6ebff";
|
|
54
|
-
readonly accent2Text: "#314457";
|
|
55
|
-
/** Hairline divider — rgba(29,31,32,0.16) */
|
|
56
|
-
readonly divider: "rgba(29,31,32,0.16)";
|
|
57
|
-
readonly neutral: {
|
|
58
|
-
readonly 100: "#f5f5f8";
|
|
59
|
-
readonly 200: "#e7e7ea";
|
|
60
|
-
readonly 300: "#d4d4d7";
|
|
61
|
-
readonly 400: "#b7b7ba";
|
|
62
|
-
readonly 500: "#98989b";
|
|
63
|
-
readonly 600: "#7a7a7d";
|
|
64
|
-
readonly 700: "#5d5d60";
|
|
65
|
-
readonly 800: "#424244";
|
|
66
|
-
readonly 900: "#2b2b2d";
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
export declare const FONTS: {
|
|
70
|
-
/** headings & labels */
|
|
71
|
-
readonly heading: "\"Barlow Condensed\", system-ui, sans-serif";
|
|
72
|
-
/** body copy */
|
|
73
|
-
readonly body: "\"Barlow\", system-ui, sans-serif";
|
|
74
|
-
/** code / types / mono */
|
|
75
|
-
readonly mono: "ui-monospace, \"JetBrains Mono\", \"SF Mono\", Menlo, monospace";
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* A Google-Fonts @import so browser-rendered SVGs pick up Barlow / Barlow
|
|
79
|
-
* Condensed / JetBrains Mono. Non-browser renderers fall back to the system
|
|
80
|
-
* fonts declared alongside each family in `FONTS`.
|
|
81
|
-
*/
|
|
82
|
-
export declare const FONT_IMPORT = "@import url('https://fonts.googleapis.com/css2?family=Barlow:wght@400;500;600;700&family=Barlow+Condensed:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');";
|
|
83
|
-
/** Constraint / cardinality badge tints in the Industry system. */
|
|
84
|
-
export declare const BADGE_TINTS: {
|
|
85
|
-
/** PK / UQ — accent tint */
|
|
86
|
-
readonly accent: {
|
|
87
|
-
readonly bg: "#eef6ff";
|
|
88
|
-
readonly fg: "#2c455d";
|
|
89
|
-
};
|
|
90
|
-
/** FK — accent-2 tint */
|
|
91
|
-
readonly accent2: {
|
|
92
|
-
readonly bg: "#d6ebff";
|
|
93
|
-
readonly fg: "#314457";
|
|
94
|
-
};
|
|
95
|
-
/** NN / AI / TS — neutral tint */
|
|
96
|
-
readonly neutral: {
|
|
97
|
-
readonly bg: "#f5f5f8";
|
|
98
|
-
readonly fg: "#424244";
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
export declare const ACCENT_PALETTES: AccentPalette[];
|
|
102
|
-
/**
|
|
103
|
-
* Resolve a `--color` flag value to a concrete palette.
|
|
104
|
-
* Accepts a named palette (case-insensitive) or a hex color string.
|
|
105
|
-
* Falls back to the default Industry palette.
|
|
106
|
-
*/
|
|
107
|
-
export declare function resolveAccent(color?: string): AccentPalette;
|
|
108
|
-
/** The secondary accent for a resolved palette, with an Industry fallback. */
|
|
109
|
-
export declare function accent2Of(p: AccentPalette): {
|
|
110
|
-
color: string;
|
|
111
|
-
light: string;
|
|
112
|
-
text: string;
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Rotate the palette list so it starts at the resolved accent (used by
|
|
116
|
-
* ERDiagram / RelationalDiagram to color multiple entities while still honoring
|
|
117
|
-
* --color for the first/primary entity).
|
|
118
|
-
*/
|
|
119
|
-
export declare function rotatedPalettes(color?: string): AccentPalette[];
|
|
120
|
-
export interface ThemeColors {
|
|
121
|
-
/** Outer page/canvas background */
|
|
122
|
-
canvasBg: string;
|
|
123
|
-
/** Card / entity-box background */
|
|
124
|
-
cardBg: string;
|
|
125
|
-
/** Alternating row background (even rows use cardBg) */
|
|
126
|
-
rowAlt: string;
|
|
127
|
-
/** Column-header strip background */
|
|
128
|
-
colHeaderBg: string;
|
|
129
|
-
/** Primary body text color */
|
|
130
|
-
textPrimary: string;
|
|
131
|
-
/** Secondary/muted text color */
|
|
132
|
-
textSecondary: string;
|
|
133
|
-
/** Hairline border/divider color */
|
|
134
|
-
border: string;
|
|
135
|
-
/** Footer bar background */
|
|
136
|
-
footerBg: string;
|
|
137
|
-
}
|
|
138
|
-
export declare function resolveTheme(theme?: 'light' | 'dark'): ThemeColors;
|