@cheetah.js/orm 0.1.120 → 0.1.122
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.
|
@@ -220,26 +220,29 @@ class BunDriverBase {
|
|
|
220
220
|
const columnName = row[columnNameField];
|
|
221
221
|
return constraints
|
|
222
222
|
.filter((c) => this.isForeignKeyConstraint(c, columnName))
|
|
223
|
-
.map((c) => this.parseForeignKeyDefinition(c.consDef))
|
|
223
|
+
.map((c) => this.parseForeignKeyDefinition(c.consDef))
|
|
224
|
+
.filter(Boolean);
|
|
224
225
|
}
|
|
225
226
|
isForeignKeyConstraint(constraint, columnName) {
|
|
226
227
|
return (constraint.type === 'FOREIGN KEY' &&
|
|
227
228
|
constraint.consDef.includes(columnName));
|
|
228
229
|
}
|
|
229
230
|
parseForeignKeyDefinition(consDef) {
|
|
230
|
-
const
|
|
231
|
-
const
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
231
|
+
const quote = this.getIdentifierQuote();
|
|
232
|
+
const escapedQuote = this.escapeRegex(quote);
|
|
233
|
+
const pattern = new RegExp(`REFERENCES\\s+(?:${escapedQuote}([^${escapedQuote}]+)${escapedQuote}|([\\w.]+))\\s*\\(([^)]+)\\)`, 'i');
|
|
234
|
+
const match = consDef.match(pattern);
|
|
235
|
+
if (!match)
|
|
236
|
+
return null;
|
|
237
|
+
const tableName = (match[1] || match[2]).trim();
|
|
238
|
+
const columnName = match[3].split(',')[0].trim().replace(new RegExp(escapedQuote, 'g'), '');
|
|
236
239
|
return {
|
|
237
|
-
referencedColumnName:
|
|
238
|
-
|
|
239
|
-
.trim()
|
|
240
|
-
.replace(new RegExp(q, 'g'), ''),
|
|
241
|
-
referencedTableName: filter[1],
|
|
240
|
+
referencedColumnName: columnName,
|
|
241
|
+
referencedTableName: tableName
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
|
+
escapeRegex(str) {
|
|
245
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
246
|
+
}
|
|
244
247
|
}
|
|
245
248
|
exports.BunDriverBase = BunDriverBase;
|
package/dist/orm.service.d.ts
CHANGED
|
@@ -4,9 +4,6 @@ export declare class OrmService {
|
|
|
4
4
|
private orm;
|
|
5
5
|
private storage;
|
|
6
6
|
private allEntities;
|
|
7
|
-
private resolveLiteralDefault;
|
|
8
|
-
private resolveEnumDefault;
|
|
9
|
-
private resolveDefaultValue;
|
|
10
7
|
constructor(orm: Orm, storage: EntityStorage, entityFile?: string);
|
|
11
8
|
private discoverRelationshipTypes;
|
|
12
9
|
private discoverEnumTypes;
|
package/dist/orm.service.js
CHANGED
|
@@ -50,59 +50,6 @@ const ts_morph_1 = require("ts-morph");
|
|
|
50
50
|
const orm_1 = require("./orm");
|
|
51
51
|
const globby = __importStar(require("globby"));
|
|
52
52
|
let OrmService = class OrmService {
|
|
53
|
-
resolveLiteralDefault(initializer) {
|
|
54
|
-
const kind = initializer.getKind();
|
|
55
|
-
if (kind === ts_morph_1.SyntaxKind.StringLiteral)
|
|
56
|
-
return initializer.getText();
|
|
57
|
-
if (kind === ts_morph_1.SyntaxKind.NumericLiteral)
|
|
58
|
-
return parseFloat(initializer.getText());
|
|
59
|
-
if (kind === ts_morph_1.SyntaxKind.TrueKeyword)
|
|
60
|
-
return true;
|
|
61
|
-
if (kind === ts_morph_1.SyntaxKind.FalseKeyword)
|
|
62
|
-
return false;
|
|
63
|
-
if (kind !== ts_morph_1.SyntaxKind.ArrayLiteralExpression)
|
|
64
|
-
return;
|
|
65
|
-
const elements = initializer.getElements();
|
|
66
|
-
return elements
|
|
67
|
-
.map((element) => {
|
|
68
|
-
const kind = element.getKind();
|
|
69
|
-
if (kind === ts_morph_1.SyntaxKind.StringLiteral ||
|
|
70
|
-
kind === ts_morph_1.SyntaxKind.NumericLiteral ||
|
|
71
|
-
kind === ts_morph_1.SyntaxKind.TrueKeyword ||
|
|
72
|
-
kind === ts_morph_1.SyntaxKind.FalseKeyword ||
|
|
73
|
-
kind === ts_morph_1.SyntaxKind.ArrayLiteralExpression) {
|
|
74
|
-
return this.resolveLiteralDefault(element);
|
|
75
|
-
}
|
|
76
|
-
else if (kind === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
|
|
77
|
-
return this.resolveEnumDefault(element);
|
|
78
|
-
}
|
|
79
|
-
return undefined;
|
|
80
|
-
})
|
|
81
|
-
.filter((value) => typeof value !== 'undefined');
|
|
82
|
-
}
|
|
83
|
-
resolveEnumDefault(initializer) {
|
|
84
|
-
if (initializer.getKind() !== ts_morph_1.SyntaxKind.PropertyAccessExpression)
|
|
85
|
-
return;
|
|
86
|
-
const [enumName, memberName] = initializer.getText().split('.');
|
|
87
|
-
if (!enumName || !memberName)
|
|
88
|
-
return;
|
|
89
|
-
const enumDeclaration = initializer.getSourceFile().getEnum(enumName) ||
|
|
90
|
-
initializer.getSourceFile().getProject().getSourceFiles()
|
|
91
|
-
.map(file => file.getEnum(enumName))
|
|
92
|
-
.find(item => item);
|
|
93
|
-
if (!enumDeclaration)
|
|
94
|
-
return;
|
|
95
|
-
const member = enumDeclaration.getMember(memberName);
|
|
96
|
-
if (!member)
|
|
97
|
-
return;
|
|
98
|
-
const value = member.getValue();
|
|
99
|
-
return typeof value === 'undefined' ? member.getName() : value;
|
|
100
|
-
}
|
|
101
|
-
resolveDefaultValue(initializer) {
|
|
102
|
-
const value = this.resolveLiteralDefault(initializer) ??
|
|
103
|
-
this.resolveEnumDefault(initializer);
|
|
104
|
-
return value;
|
|
105
|
-
}
|
|
106
53
|
constructor(orm, storage, entityFile) {
|
|
107
54
|
this.orm = orm;
|
|
108
55
|
this.storage = storage;
|
|
@@ -127,9 +74,19 @@ let OrmService = class OrmService {
|
|
|
127
74
|
nullables.push(propertyName);
|
|
128
75
|
}
|
|
129
76
|
if (initializer) {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
77
|
+
const initializerKind = initializer.getKind();
|
|
78
|
+
switch (initializerKind) {
|
|
79
|
+
case ts_morph_1.SyntaxKind.StringLiteral:
|
|
80
|
+
defaults[propertyName] = initializer.getText();
|
|
81
|
+
break;
|
|
82
|
+
case ts_morph_1.SyntaxKind.NumericLiteral:
|
|
83
|
+
defaults[propertyName] = parseFloat(initializer.getText());
|
|
84
|
+
break;
|
|
85
|
+
case ts_morph_1.SyntaxKind.NewExpression:
|
|
86
|
+
case ts_morph_1.SyntaxKind.CallExpression:
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
break;
|
|
133
90
|
}
|
|
134
91
|
}
|
|
135
92
|
this.allEntities.set(classDeclaration.getName(), { nullables, defaults });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cheetah.js/orm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.122",
|
|
4
4
|
"description": "A simple ORM for Cheetah.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"bun",
|
|
56
56
|
"value-object"
|
|
57
57
|
],
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "d3f748547f20d75d4102b13139a0554a3db953c8"
|
|
59
59
|
}
|