@mikro-orm/entity-generator 7.2.0-dev.9 → 7.2.1-dev.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/EntityGenerator.d.ts +2 -0
- package/EntityGenerator.js +25 -1
- package/README.md +1 -0
- package/SourceFile.d.ts +1 -0
- package/SourceFile.js +41 -2
- package/package.json +4 -4
package/EntityGenerator.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export declare class EntityGenerator {
|
|
|
7
7
|
static register(orm: MikroORM): void;
|
|
8
8
|
generate(options?: GenerateOptions): Promise<string[]>;
|
|
9
9
|
private getEntityMetadata;
|
|
10
|
+
/** Carries introspected RLS state (policies + enablement) from the table onto the entity metadata. */
|
|
11
|
+
private applyRowLevelSecurity;
|
|
10
12
|
private cleanUpReferentialIntegrityRules;
|
|
11
13
|
private matchName;
|
|
12
14
|
private detectManyToManyRelations;
|
package/EntityGenerator.js
CHANGED
|
@@ -100,7 +100,9 @@ export class EntityGenerator {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
const meta = table.getEntityDeclaration(this.#namingStrategy, this.#helper, options.scalarPropertiesForRelations);
|
|
104
|
+
this.applyRowLevelSecurity(meta, table);
|
|
105
|
+
return meta;
|
|
104
106
|
});
|
|
105
107
|
for (const meta of metadata) {
|
|
106
108
|
for (const prop of meta.relations) {
|
|
@@ -159,6 +161,28 @@ export class EntityGenerator {
|
|
|
159
161
|
await options.onProcessedMetadata?.(metadata, this.#platform);
|
|
160
162
|
return metadata;
|
|
161
163
|
}
|
|
164
|
+
/** Carries introspected RLS state (policies + enablement) from the table onto the entity metadata. */
|
|
165
|
+
applyRowLevelSecurity(meta, table) {
|
|
166
|
+
meta.policies = table.getPolicies().map(policy => ({
|
|
167
|
+
name: policy.name,
|
|
168
|
+
command: policy.command,
|
|
169
|
+
type: policy.type,
|
|
170
|
+
roles: policy.roles,
|
|
171
|
+
...(policy.using != null ? { using: policy.using } : {}),
|
|
172
|
+
...(policy.check != null ? { check: policy.check } : {}),
|
|
173
|
+
}));
|
|
174
|
+
if (table.rlsForced) {
|
|
175
|
+
meta.rowLevelSecurity = 'force';
|
|
176
|
+
}
|
|
177
|
+
else if (table.rlsEnabled) {
|
|
178
|
+
meta.rowLevelSecurity = true;
|
|
179
|
+
}
|
|
180
|
+
else if (meta.policies.length > 0) {
|
|
181
|
+
// policies staged but RLS disabled — record it explicitly so a reload does not re-enable RLS via the
|
|
182
|
+
// policies-imply-RLS default
|
|
183
|
+
meta.rowLevelSecurity = false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
162
186
|
cleanUpReferentialIntegrityRules(metadata) {
|
|
163
187
|
// Clear FK rules that match defaults for:
|
|
164
188
|
// 1. FK-as-PK entities (all PKs are FKs) - cascade for both update and delete
|
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@ npm install @mikro-orm/mysql # MySQL
|
|
|
24
24
|
npm install @mikro-orm/mariadb # MariaDB
|
|
25
25
|
npm install @mikro-orm/sqlite # SQLite
|
|
26
26
|
npm install @mikro-orm/libsql # libSQL / Turso
|
|
27
|
+
npm install @mikro-orm/sql-js # sql.js (in-memory SQLite in WASM)
|
|
27
28
|
npm install @mikro-orm/mongodb # MongoDB
|
|
28
29
|
npm install @mikro-orm/mssql # MS SQL Server
|
|
29
30
|
npm install @mikro-orm/oracledb # Oracle
|
package/SourceFile.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export declare class SourceFile {
|
|
|
35
35
|
protected getEntityDeclOptions(): EntityOptions<unknown>;
|
|
36
36
|
private isDiscriminatorPropertyUserDefined;
|
|
37
37
|
protected getPartitionByDecl(partitionBy: EntityPartitionBy): Dictionary;
|
|
38
|
+
protected getPolicyDecl(policy: EntityMetadata['policies'][number]): Dictionary;
|
|
38
39
|
protected getEmbeddableDeclOptions(): EmbeddableOptions<unknown>;
|
|
39
40
|
private getCollectionDecl;
|
|
40
41
|
private getPropertyDecorator;
|
package/SourceFile.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Cascade, Config, DecimalType, ReferenceKind, SCALAR_TYPES, UnknownType, Utils, inspect, } from '@mikro-orm/core';
|
|
2
|
+
import { DatabaseTable } from '@mikro-orm/sql';
|
|
2
3
|
import { parse, relative } from 'node:path';
|
|
3
4
|
import { POSSIBLE_TYPE_IMPORTS } from './CoreImportsHelper.js';
|
|
4
5
|
/**
|
|
@@ -26,11 +27,13 @@ export class SourceFile {
|
|
|
26
27
|
if (this.meta.embeddable || this.meta.collection) {
|
|
27
28
|
if (this.meta.embeddable) {
|
|
28
29
|
const options = this.getEmbeddableDeclOptions();
|
|
29
|
-
|
|
30
|
+
const decl = `@${this.referenceDecoratorImport('Embeddable')}(`;
|
|
31
|
+
ret += `${decl}${Utils.hasObjectKeys(options) ? this.serializeObject(options, 80 - decl.length, 0) : ''})\n`;
|
|
30
32
|
}
|
|
31
33
|
else {
|
|
32
34
|
const options = this.getEntityDeclOptions();
|
|
33
|
-
|
|
35
|
+
const decl = `@${this.referenceDecoratorImport('Entity')}(`;
|
|
36
|
+
ret += `${decl}${Utils.hasObjectKeys(options) ? this.serializeObject(options, 80 - decl.length, 0) : ''})\n`;
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
for (const index of this.meta.indexes) {
|
|
@@ -512,6 +515,21 @@ export class SourceFile {
|
|
|
512
515
|
if (this.meta.partitionBy) {
|
|
513
516
|
options.partitionBy = this.getPartitionByDecl(this.meta.partitionBy);
|
|
514
517
|
}
|
|
518
|
+
// policies imply RLS on reload, so only emit `rowLevelSecurity` when it adds information:
|
|
519
|
+
// `'force'` always, plain `true` only for a deny-all table (enabled with no policies),
|
|
520
|
+
// and explicit `false` only when policies are staged but RLS is disabled
|
|
521
|
+
if (this.meta.rowLevelSecurity === 'force') {
|
|
522
|
+
options.rowLevelSecurity = this.quote('force');
|
|
523
|
+
}
|
|
524
|
+
else if (this.meta.rowLevelSecurity === true && this.meta.policies.length === 0) {
|
|
525
|
+
options.rowLevelSecurity = true;
|
|
526
|
+
}
|
|
527
|
+
else if (this.meta.rowLevelSecurity === false && this.meta.policies.length > 0) {
|
|
528
|
+
options.rowLevelSecurity = false;
|
|
529
|
+
}
|
|
530
|
+
if (this.meta.policies.length > 0) {
|
|
531
|
+
options.policies = this.meta.policies.map(policy => this.getPolicyDecl(policy));
|
|
532
|
+
}
|
|
515
533
|
if (this.meta.readonly && !this.meta.virtual) {
|
|
516
534
|
options.readonly = this.meta.readonly;
|
|
517
535
|
}
|
|
@@ -562,6 +580,27 @@ export class SourceFile {
|
|
|
562
580
|
}
|
|
563
581
|
return result;
|
|
564
582
|
}
|
|
583
|
+
getPolicyDecl(policy) {
|
|
584
|
+
// introspected names are always explicit; the rest is emitted only when it differs from the default
|
|
585
|
+
const result = { name: this.quote(policy.name) };
|
|
586
|
+
if (policy.command && policy.command !== 'all') {
|
|
587
|
+
result.command = this.quote(policy.command);
|
|
588
|
+
}
|
|
589
|
+
if (policy.type && policy.type !== 'permissive') {
|
|
590
|
+
result.type = this.quote(policy.type);
|
|
591
|
+
}
|
|
592
|
+
const roles = policy.roles;
|
|
593
|
+
if (roles && !DatabaseTable.isDefaultPolicyRoles(roles)) {
|
|
594
|
+
result.roles = roles.map(role => this.quote(role));
|
|
595
|
+
}
|
|
596
|
+
if (typeof policy.using === 'string') {
|
|
597
|
+
result.using = this.quote(policy.using);
|
|
598
|
+
}
|
|
599
|
+
if (typeof policy.check === 'string') {
|
|
600
|
+
result.check = this.quote(policy.check);
|
|
601
|
+
}
|
|
602
|
+
return result;
|
|
603
|
+
}
|
|
565
604
|
getEmbeddableDeclOptions() {
|
|
566
605
|
const options = {};
|
|
567
606
|
return this.getCollectionDecl(options, 'discriminator');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/entity-generator",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.1-dev.0",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@mikro-orm/sql": "7.2.
|
|
50
|
+
"@mikro-orm/sql": "7.2.1-dev.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@mikro-orm/core": "^7.
|
|
53
|
+
"@mikro-orm/core": "^7.2.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.
|
|
56
|
+
"@mikro-orm/core": "7.2.1-dev.0"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|