@mikro-orm/entity-generator 7.1.0-dev.14 → 7.1.0-dev.16
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/SourceFile.d.ts +2 -1
- package/SourceFile.js +43 -0
- package/package.json +3 -3
package/SourceFile.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Dictionary, type EmbeddableOptions, type EntityMetadata, type EntityOptions, type EntityProperty, type GenerateOptions, type IndexOptions, type NamingStrategy, type OneToOneOptions, type Platform, type UniqueOptions } from '@mikro-orm/core';
|
|
1
|
+
import { type Dictionary, type EmbeddableOptions, type EntityMetadata, type EntityOptions, type EntityPartitionBy, type EntityProperty, type GenerateOptions, type IndexOptions, type NamingStrategy, type OneToOneOptions, type Platform, type UniqueOptions } from '@mikro-orm/core';
|
|
2
2
|
/**
|
|
3
3
|
* @see https://github.com/tc39/proposal-regexp-unicode-property-escapes#other-examples
|
|
4
4
|
*/
|
|
@@ -30,6 +30,7 @@ export declare class SourceFile {
|
|
|
30
30
|
protected serializeObject(options: {}, wordwrap?: number, spaces?: number, level?: number): string;
|
|
31
31
|
protected serializeValue(val: unknown, wordwrap?: number, spaces?: number, level?: number): unknown;
|
|
32
32
|
protected getEntityDeclOptions(): EntityOptions<unknown>;
|
|
33
|
+
protected getPartitionByDecl(partitionBy: EntityPartitionBy): Dictionary;
|
|
33
34
|
protected getEmbeddableDeclOptions(): EmbeddableOptions<unknown>;
|
|
34
35
|
private getCollectionDecl;
|
|
35
36
|
private getPropertyDecorator;
|
package/SourceFile.js
CHANGED
|
@@ -130,6 +130,9 @@ export class SourceFile {
|
|
|
130
130
|
else if (typeof index.expression === 'function') {
|
|
131
131
|
indexOpt.expression = `${index.expression}`.replace(')=>`', ') => `');
|
|
132
132
|
}
|
|
133
|
+
if (typeof index.where === 'string') {
|
|
134
|
+
indexOpt.where = this.quote(index.where);
|
|
135
|
+
}
|
|
133
136
|
if (isAtEntityLevel && index.properties) {
|
|
134
137
|
indexOpt.properties = Utils.asArray(index.properties).map(prop => this.quote('' + prop));
|
|
135
138
|
}
|
|
@@ -170,6 +173,9 @@ export class SourceFile {
|
|
|
170
173
|
else if (typeof index.expression === 'function') {
|
|
171
174
|
uniqueOpt.expression = `${index.expression}`.replace(')=>`', ') => `');
|
|
172
175
|
}
|
|
176
|
+
if (typeof index.where === 'string') {
|
|
177
|
+
uniqueOpt.where = this.quote(index.where);
|
|
178
|
+
}
|
|
173
179
|
if (isAtEntityLevel && index.properties) {
|
|
174
180
|
uniqueOpt.properties = Utils.asArray(index.properties).map(prop => this.quote('' + prop));
|
|
175
181
|
}
|
|
@@ -475,6 +481,9 @@ export class SourceFile {
|
|
|
475
481
|
if (this.meta.comment) {
|
|
476
482
|
options.comment = this.quote(this.meta.comment);
|
|
477
483
|
}
|
|
484
|
+
if (this.meta.partitionBy) {
|
|
485
|
+
options.partitionBy = this.getPartitionByDecl(this.meta.partitionBy);
|
|
486
|
+
}
|
|
478
487
|
if (this.meta.readonly && !this.meta.virtual) {
|
|
479
488
|
options.readonly = this.meta.readonly;
|
|
480
489
|
}
|
|
@@ -483,6 +492,40 @@ export class SourceFile {
|
|
|
483
492
|
}
|
|
484
493
|
return this.getCollectionDecl(options);
|
|
485
494
|
}
|
|
495
|
+
getPartitionByDecl(partitionBy) {
|
|
496
|
+
const result = { type: this.quote(partitionBy.type) };
|
|
497
|
+
// Introspected metadata from `toEntityPartitionBy` always emits a string or string[];
|
|
498
|
+
// callback-form expressions only exist in hand-written entity metadata. Fail loud if a
|
|
499
|
+
// callback ever reaches the generator — stringifying `fn.toString()` would produce source
|
|
500
|
+
// that re-imports nothing and will not compile.
|
|
501
|
+
if (typeof partitionBy.expression === 'function') {
|
|
502
|
+
throw new Error(`Cannot emit entity source for ${this.meta.className}: partitionBy.expression is a callback. ` +
|
|
503
|
+
`Entity generator expects string or string[] expressions from catalog introspection.`);
|
|
504
|
+
}
|
|
505
|
+
const expression = partitionBy.expression;
|
|
506
|
+
if (Array.isArray(expression)) {
|
|
507
|
+
result.expression = expression.map(key => this.quote(String(key)));
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
result.expression = this.quote(String(expression));
|
|
511
|
+
}
|
|
512
|
+
if (partitionBy.type === 'hash') {
|
|
513
|
+
result.partitions = Array.isArray(partitionBy.partitions)
|
|
514
|
+
? partitionBy.partitions.map(name => this.quote(String(name)))
|
|
515
|
+
: partitionBy.partitions;
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
result.partitions = partitionBy.partitions.map(partition => {
|
|
519
|
+
const entry = {};
|
|
520
|
+
if (partition.name) {
|
|
521
|
+
entry.name = this.quote(partition.name);
|
|
522
|
+
}
|
|
523
|
+
entry.values = this.quote(partition.values);
|
|
524
|
+
return entry;
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
return result;
|
|
528
|
+
}
|
|
486
529
|
getEmbeddableDeclOptions() {
|
|
487
530
|
const options = {};
|
|
488
531
|
const result = this.getCollectionDecl(options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/entity-generator",
|
|
3
|
-
"version": "7.1.0-dev.
|
|
3
|
+
"version": "7.1.0-dev.16",
|
|
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.1.0-dev.
|
|
50
|
+
"@mikro-orm/sql": "7.1.0-dev.16"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@mikro-orm/core": "^7.0.11"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.1.0-dev.
|
|
56
|
+
"@mikro-orm/core": "7.1.0-dev.16"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|