@currentjs/gen 0.5.3 → 0.5.5
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/CHANGELOG.md +8 -0
- package/dist/commands/migrateCommit.js +11 -5
- package/dist/generators/domainLayerGenerator.js +7 -8
- package/dist/generators/dtoGenerator.js +5 -6
- package/dist/generators/storeGenerator.d.ts +14 -0
- package/dist/generators/storeGenerator.js +147 -32
- package/dist/generators/templateGenerator.d.ts +15 -0
- package/dist/generators/templateGenerator.js +215 -10
- package/dist/generators/templates/storeTemplates.js +24 -17
- package/dist/utils/migrationUtils.d.ts +11 -5
- package/dist/utils/migrationUtils.js +72 -27
- package/dist/utils/typeUtils.d.ts +29 -1
- package/dist/utils/typeUtils.js +103 -9
- package/package.json +1 -1
package/dist/utils/typeUtils.js
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ROW_TYPE_MAPPING = exports.TYPE_MAPPING = void 0;
|
|
7
7
|
exports.capitalize = capitalize;
|
|
8
|
+
exports.parseFieldType = parseFieldType;
|
|
9
|
+
exports.isValueObjectFieldType = isValueObjectFieldType;
|
|
10
|
+
exports.getReferencedValueObjects = getReferencedValueObjects;
|
|
8
11
|
exports.mapType = mapType;
|
|
9
12
|
exports.isAggregateReference = isAggregateReference;
|
|
10
13
|
exports.mapRowType = mapRowType;
|
|
@@ -33,28 +36,119 @@ exports.ROW_TYPE_MAPPING = {
|
|
|
33
36
|
datetime: 'string',
|
|
34
37
|
date: 'string',
|
|
35
38
|
id: 'number',
|
|
36
|
-
json: '
|
|
37
|
-
array: '
|
|
38
|
-
object: '
|
|
39
|
+
json: 'any',
|
|
40
|
+
array: 'any[]',
|
|
41
|
+
object: 'any',
|
|
39
42
|
enum: 'string'
|
|
40
43
|
};
|
|
41
44
|
function capitalize(str) {
|
|
42
45
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
43
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Parse a YAML field type string into its structural components.
|
|
49
|
+
* Handles simple types ("Money"), array types ("Money[]"), union types ("Foo | Bar"),
|
|
50
|
+
* and array-of-union types ("(Foo | Bar)[]").
|
|
51
|
+
*/
|
|
52
|
+
function parseFieldType(typeStr) {
|
|
53
|
+
const trimmed = typeStr.trim();
|
|
54
|
+
// Array of union: "(Foo | Bar)[]"
|
|
55
|
+
if (trimmed.startsWith('(') && trimmed.endsWith(')[]')) {
|
|
56
|
+
const inner = trimmed.slice(1, -3).trim();
|
|
57
|
+
const parts = inner.split('|').map(p => p.trim()).filter(Boolean);
|
|
58
|
+
return { baseTypes: parts, isArray: true, isUnion: true };
|
|
59
|
+
}
|
|
60
|
+
if (trimmed.endsWith('[]')) {
|
|
61
|
+
const base = trimmed.slice(0, -2).trim();
|
|
62
|
+
return { baseTypes: [base], isArray: true, isUnion: false };
|
|
63
|
+
}
|
|
64
|
+
if (trimmed.includes('|')) {
|
|
65
|
+
const parts = trimmed.split('|').map(p => p.trim()).filter(Boolean);
|
|
66
|
+
return { baseTypes: parts, isArray: false, isUnion: true };
|
|
67
|
+
}
|
|
68
|
+
return { baseTypes: [trimmed], isArray: false, isUnion: false };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns true when any base type in the (possibly compound) type expression is a known value object.
|
|
72
|
+
*/
|
|
73
|
+
function isValueObjectFieldType(typeStr, valueObjects) {
|
|
74
|
+
const { baseTypes } = parseFieldType(typeStr);
|
|
75
|
+
return baseTypes.some(bt => {
|
|
76
|
+
const cap = capitalize(bt);
|
|
77
|
+
return valueObjects instanceof Set ? valueObjects.has(cap) : valueObjects.has(cap);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns the set of value object names referenced in a (possibly compound) type expression.
|
|
82
|
+
*/
|
|
83
|
+
function getReferencedValueObjects(typeStr, valueObjects) {
|
|
84
|
+
const { baseTypes } = parseFieldType(typeStr);
|
|
85
|
+
const result = new Set();
|
|
86
|
+
for (const bt of baseTypes) {
|
|
87
|
+
const cap = capitalize(bt);
|
|
88
|
+
const has = valueObjects instanceof Set ? valueObjects.has(cap) : valueObjects.has(cap);
|
|
89
|
+
if (has)
|
|
90
|
+
result.add(cap);
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
44
94
|
/**
|
|
45
95
|
* Map a YAML field type to TypeScript type, resolving aggregates and value objects by name.
|
|
96
|
+
* Supports compound types: "Foo[]" -> "Foo[]", "Foo | Bar" -> "Foo | Bar".
|
|
46
97
|
*/
|
|
47
98
|
function mapType(yamlType, aggregates, valueObjects) {
|
|
48
|
-
var _a;
|
|
99
|
+
var _a, _b;
|
|
100
|
+
// Simple aggregate reference (no compound syntax)
|
|
49
101
|
if (aggregates === null || aggregates === void 0 ? void 0 : aggregates.has(yamlType))
|
|
50
102
|
return yamlType;
|
|
103
|
+
const parsed = parseFieldType(yamlType);
|
|
104
|
+
// Array of union of value objects: "(Foo | Bar)[]"
|
|
105
|
+
if (parsed.isArray && parsed.isUnion) {
|
|
106
|
+
const resolvedParts = parsed.baseTypes.map(bt => {
|
|
107
|
+
var _a;
|
|
108
|
+
const cap = capitalize(bt);
|
|
109
|
+
if (valueObjects) {
|
|
110
|
+
const has = valueObjects instanceof Set ? valueObjects.has(cap) : valueObjects.has(cap);
|
|
111
|
+
if (has)
|
|
112
|
+
return cap;
|
|
113
|
+
}
|
|
114
|
+
return (_a = exports.TYPE_MAPPING[bt]) !== null && _a !== void 0 ? _a : 'any';
|
|
115
|
+
});
|
|
116
|
+
return `(${resolvedParts.join(' | ')})[]`;
|
|
117
|
+
}
|
|
118
|
+
// Array of value objects: "Foo[]"
|
|
119
|
+
if (parsed.isArray) {
|
|
120
|
+
const [base] = parsed.baseTypes;
|
|
121
|
+
const capitalizedBase = capitalize(base);
|
|
122
|
+
if (valueObjects) {
|
|
123
|
+
const has = valueObjects instanceof Set ? valueObjects.has(capitalizedBase) : valueObjects.has(capitalizedBase);
|
|
124
|
+
if (has)
|
|
125
|
+
return `${capitalizedBase}[]`;
|
|
126
|
+
}
|
|
127
|
+
// Fall back: treat as plain mapped type array
|
|
128
|
+
return `${(_a = exports.TYPE_MAPPING[base]) !== null && _a !== void 0 ? _a : 'any'}[]`;
|
|
129
|
+
}
|
|
130
|
+
// Union of value objects: "Foo | Bar"
|
|
131
|
+
if (parsed.isUnion) {
|
|
132
|
+
const resolvedParts = parsed.baseTypes.map(bt => {
|
|
133
|
+
var _a;
|
|
134
|
+
const cap = capitalize(bt);
|
|
135
|
+
if (valueObjects) {
|
|
136
|
+
const has = valueObjects instanceof Set ? valueObjects.has(cap) : valueObjects.has(cap);
|
|
137
|
+
if (has)
|
|
138
|
+
return cap;
|
|
139
|
+
}
|
|
140
|
+
return (_a = exports.TYPE_MAPPING[bt]) !== null && _a !== void 0 ? _a : 'any';
|
|
141
|
+
});
|
|
142
|
+
return resolvedParts.join(' | ');
|
|
143
|
+
}
|
|
144
|
+
// Simple type
|
|
51
145
|
const capitalizedType = capitalize(yamlType);
|
|
52
146
|
if (valueObjects) {
|
|
53
147
|
const has = valueObjects instanceof Set ? valueObjects.has(capitalizedType) : valueObjects.has(capitalizedType);
|
|
54
148
|
if (has)
|
|
55
149
|
return capitalizedType;
|
|
56
150
|
}
|
|
57
|
-
return (
|
|
151
|
+
return (_b = exports.TYPE_MAPPING[yamlType]) !== null && _b !== void 0 ? _b : 'any';
|
|
58
152
|
}
|
|
59
153
|
/**
|
|
60
154
|
* Check if a YAML field type references another aggregate entity.
|
|
@@ -63,14 +157,14 @@ function isAggregateReference(yamlType, aggregates) {
|
|
|
63
157
|
return !!(aggregates === null || aggregates === void 0 ? void 0 : aggregates.has(yamlType));
|
|
64
158
|
}
|
|
65
159
|
/**
|
|
66
|
-
* Map a YAML type to the store row TypeScript type
|
|
160
|
+
* Map a YAML type to the store row TypeScript type.
|
|
161
|
+
* Value objects (including compound types) become "string" (stored as JSON).
|
|
67
162
|
*/
|
|
68
163
|
function mapRowType(yamlType, valueObjects) {
|
|
69
164
|
var _a;
|
|
70
165
|
if (valueObjects) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (has)
|
|
166
|
+
// Any compound type containing a VO name is stored as JSON string
|
|
167
|
+
if (isValueObjectFieldType(yamlType, valueObjects))
|
|
74
168
|
return 'string';
|
|
75
169
|
}
|
|
76
170
|
return (_a = exports.ROW_TYPE_MAPPING[yamlType]) !== null && _a !== void 0 ? _a : 'string';
|