@mikro-orm/entity-generator 7.1.9-dev.5 → 7.1.9-dev.7
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.js +10 -1
- package/NativeEnumSourceFile.js +4 -1
- package/RoutineSourceFile.js +3 -1
- package/package.json +3 -3
package/EntityGenerator.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EntitySchema, ReferenceKind, types, Utils, } from '@mikro-orm/core';
|
|
2
2
|
import { DatabaseSchema, } from '@mikro-orm/sql';
|
|
3
3
|
import { fs } from '@mikro-orm/core/fs-utils';
|
|
4
|
-
import { dirname, join } from 'node:path';
|
|
4
|
+
import { dirname, join, relative, resolve } from 'node:path';
|
|
5
5
|
import { writeFile } from 'node:fs/promises';
|
|
6
6
|
import { DefineEntitySourceFile } from './DefineEntitySourceFile.js';
|
|
7
7
|
import { EntitySchemaSourceFile } from './EntitySchemaSourceFile.js';
|
|
@@ -62,6 +62,15 @@ export class EntityGenerator {
|
|
|
62
62
|
}
|
|
63
63
|
const files = this.#sources.map(file => [file.getBaseName(), file.generate()]);
|
|
64
64
|
if (options.save) {
|
|
65
|
+
// generated files may only land in the project folder, or under the configured path when
|
|
66
|
+
// that points elsewhere, so a file name can never reach an arbitrary filesystem location
|
|
67
|
+
const allowedRoots = [resolve(this.#config.get('baseDir')), resolve(baseDir)];
|
|
68
|
+
for (const [fileName] of files) {
|
|
69
|
+
const target = resolve(baseDir, fileName);
|
|
70
|
+
if (!allowedRoots.some(root => !relative(root, target).startsWith('..'))) {
|
|
71
|
+
throw new Error(`Cannot generate '${fileName}', it resolves outside of the project folder`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
65
74
|
fs.ensureDir(baseDir);
|
|
66
75
|
const promises = [];
|
|
67
76
|
for (const [fileName, data] of files) {
|
package/NativeEnumSourceFile.js
CHANGED
|
@@ -42,6 +42,9 @@ export class NativeEnumSourceFile extends SourceFile {
|
|
|
42
42
|
return ret;
|
|
43
43
|
}
|
|
44
44
|
getBaseName(extension = '.ts') {
|
|
45
|
-
|
|
45
|
+
// the enum name comes from the database and ends up in a path, so path separators
|
|
46
|
+
// (and anything else that cannot appear in a file name) collapse to `_`
|
|
47
|
+
const name = this.nativeEnum.name.replaceAll(/[^\p{L}\p{N}$_-]+/gu, '_');
|
|
48
|
+
return `${this.options.fileName(name)}${extension}`;
|
|
46
49
|
}
|
|
47
50
|
}
|
package/RoutineSourceFile.js
CHANGED
|
@@ -20,7 +20,9 @@ function quoteMultiline(val) {
|
|
|
20
20
|
}
|
|
21
21
|
function toPascalCase(name) {
|
|
22
22
|
const pascal = name
|
|
23
|
-
|
|
23
|
+
// anything that cannot appear in an identifier acts as a word separator, which keeps
|
|
24
|
+
// path separators out of both the emitted const name and the generated file name
|
|
25
|
+
.split(/[^\p{L}\p{N}$]+/u)
|
|
24
26
|
.filter(Boolean)
|
|
25
27
|
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
|
|
26
28
|
.join('');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/entity-generator",
|
|
3
|
-
"version": "7.1.9-dev.
|
|
3
|
+
"version": "7.1.9-dev.7",
|
|
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.9-dev.
|
|
50
|
+
"@mikro-orm/sql": "7.1.9-dev.7"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@mikro-orm/core": "^7.1.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.1.9-dev.
|
|
56
|
+
"@mikro-orm/core": "7.1.9-dev.7"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|