@mikro-orm/entity-generator 7.1.0-dev.15 → 7.1.0-dev.17
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 +37 -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
|
@@ -481,6 +481,9 @@ export class SourceFile {
|
|
|
481
481
|
if (this.meta.comment) {
|
|
482
482
|
options.comment = this.quote(this.meta.comment);
|
|
483
483
|
}
|
|
484
|
+
if (this.meta.partitionBy) {
|
|
485
|
+
options.partitionBy = this.getPartitionByDecl(this.meta.partitionBy);
|
|
486
|
+
}
|
|
484
487
|
if (this.meta.readonly && !this.meta.virtual) {
|
|
485
488
|
options.readonly = this.meta.readonly;
|
|
486
489
|
}
|
|
@@ -489,6 +492,40 @@ export class SourceFile {
|
|
|
489
492
|
}
|
|
490
493
|
return this.getCollectionDecl(options);
|
|
491
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
|
+
}
|
|
492
529
|
getEmbeddableDeclOptions() {
|
|
493
530
|
const options = {};
|
|
494
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.17",
|
|
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.17"
|
|
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.17"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|