@cheetah.js/orm 0.1.121 → 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.
- package/dist/orm.service.d.ts +0 -3
- package/dist/orm.service.js +13 -56
- package/package.json +2 -2
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
|
}
|