@an5/orm 1.0.8 → 1.0.9
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/README.md +167 -175
- package/dist/an5Metadata.js +64 -0
- package/dist/an5Orm.d.ts +92 -3
- package/dist/an5Orm.js +697 -206
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/generator/src/code-generator.d.ts +14 -13
- package/dist/generator/src/code-generator.js +249 -225
- package/dist/generator/src/dotnet-generator.d.ts +13 -11
- package/dist/generator/src/dotnet-generator.js +872 -546
- package/dist/generator/src/index.d.ts +1 -1
- package/dist/generator/src/index.js +104 -88
- package/dist/generator/src/metadata-generator.d.ts +11 -8
- package/dist/generator/src/metadata-generator.js +104 -90
- package/dist/generator/src/parser.d.ts +11 -11
- package/dist/generator/src/parser.js +206 -206
- package/dist/generator/src/python-generator.d.ts +19 -9
- package/dist/generator/src/python-generator.js +345 -105
- package/dist/generator/src/types.d.ts +27 -27
- package/dist/generator/src/types.js +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +19 -8
- package/dist/logger.js +1 -1
- package/dist/migration-core.d.ts +87 -0
- package/dist/migration-core.js +692 -0
- package/dist/scripts/release-cli.d.ts +2 -2
- package/dist/scripts/release-cli.js +115 -115
- package/dist/sql-utils.d.ts +3 -1
- package/dist/sql-utils.js +94 -24
- package/generator/src/code-generator.ts +259 -230
- package/generator/src/dotnet-generator.ts +882 -544
- package/generator/src/golang-generator.ts +1242 -0
- package/generator/src/index.ts +111 -116
- package/generator/src/metadata-generator.ts +116 -101
- package/generator/src/parser.ts +202 -202
- package/generator/src/python-generator.ts +424 -114
- package/generator/src/types.ts +29 -29
- package/package.json +12 -6
|
@@ -1,206 +1,206 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SchemaParser = void 0;
|
|
7
|
-
exports.sqlTypeToTs = sqlTypeToTs;
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
// SQL Server type → TypeScript type mapping
|
|
11
|
-
const AN5_TO_TS = {
|
|
12
|
-
// String types
|
|
13
|
-
'NVARCHAR': 'string',
|
|
14
|
-
'VARCHAR': 'string',
|
|
15
|
-
'CHAR': 'string',
|
|
16
|
-
'NCHAR': 'string',
|
|
17
|
-
'TEXT': 'string',
|
|
18
|
-
'NTEXT': 'string',
|
|
19
|
-
'XML': 'string',
|
|
20
|
-
// Numeric types
|
|
21
|
-
'INT': 'number',
|
|
22
|
-
'SMALLINT': 'number',
|
|
23
|
-
'TINYINT': 'number',
|
|
24
|
-
'BIGINT': 'number | bigint',
|
|
25
|
-
'FLOAT': 'number',
|
|
26
|
-
'REAL': 'number',
|
|
27
|
-
'DECIMAL': 'number',
|
|
28
|
-
'NUMERIC': 'number',
|
|
29
|
-
'MONEY': 'number',
|
|
30
|
-
'SMALLMONEY': 'number',
|
|
31
|
-
// Boolean
|
|
32
|
-
'BIT': 'boolean',
|
|
33
|
-
// Date types
|
|
34
|
-
'DATETIME': 'Date',
|
|
35
|
-
'DATETIME2': 'Date',
|
|
36
|
-
'SMALLDATETIME': 'Date',
|
|
37
|
-
'DATE': 'Date',
|
|
38
|
-
'TIME': 'Date',
|
|
39
|
-
'DATETIMEOFFSET': 'Date',
|
|
40
|
-
// Binary types
|
|
41
|
-
'VARBINARY': 'Buffer',
|
|
42
|
-
'BINARY': 'Buffer',
|
|
43
|
-
'IMAGE': 'Buffer',
|
|
44
|
-
// Other
|
|
45
|
-
'UNIQUEIDENTIFIER': 'string',
|
|
46
|
-
'SQL_VARIANT': 'any',
|
|
47
|
-
'ROWVERSION': 'Buffer',
|
|
48
|
-
'HIERARCHYID': 'string',
|
|
49
|
-
'GEOGRAPHY': 'string',
|
|
50
|
-
'GEOMETRY': 'string',
|
|
51
|
-
'VECTOR': 'number[] | string',
|
|
52
|
-
};
|
|
53
|
-
// Parse base type from "NVARCHAR(255)" → "NVARCHAR"
|
|
54
|
-
function parseSqlType(raw) {
|
|
55
|
-
const match = raw.match(/^(\w+)(?:\((.+)\))?$/);
|
|
56
|
-
if (!match)
|
|
57
|
-
return { base: raw, params: '' };
|
|
58
|
-
return { base: match[1].toUpperCase(), params: match[2] || '' };
|
|
59
|
-
}
|
|
60
|
-
// Map SQL Server type to TypeScript type
|
|
61
|
-
function sqlTypeToTs(sqlType) {
|
|
62
|
-
const { base } = parseSqlType(sqlType);
|
|
63
|
-
return AN5_TO_TS[base] || 'any';
|
|
64
|
-
}
|
|
65
|
-
class SchemaParser {
|
|
66
|
-
constructor(schemaDir) {
|
|
67
|
-
this.schemaDir = schemaDir;
|
|
68
|
-
this.schemaText = '';
|
|
69
|
-
}
|
|
70
|
-
async parse() {
|
|
71
|
-
this.loadSchema();
|
|
72
|
-
const lines = this.schemaText.split('\n');
|
|
73
|
-
const models = [];
|
|
74
|
-
let currentModel = null;
|
|
75
|
-
for (let line of lines) {
|
|
76
|
-
line = line.trim();
|
|
77
|
-
if (!line || line.startsWith('//'))
|
|
78
|
-
continue;
|
|
79
|
-
const modelHeaderMatch = line.match(/^model\s+(\w+)\s*\{/);
|
|
80
|
-
if (modelHeaderMatch) {
|
|
81
|
-
const modelName = modelHeaderMatch[1];
|
|
82
|
-
currentModel = {
|
|
83
|
-
name: modelName,
|
|
84
|
-
tableName: modelName.toLowerCase() + 's',
|
|
85
|
-
schemaName: 'dbo',
|
|
86
|
-
fields: [],
|
|
87
|
-
relations: []
|
|
88
|
-
};
|
|
89
|
-
models.push(currentModel);
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (line === '}') {
|
|
93
|
-
currentModel = null;
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
if (currentModel) {
|
|
97
|
-
this.parseModelLine(line, currentModel);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
this.postProcessRelations(models);
|
|
101
|
-
return models;
|
|
102
|
-
}
|
|
103
|
-
loadSchema() {
|
|
104
|
-
if (fs_1.default.existsSync(this.schemaDir)) {
|
|
105
|
-
const files = fs_1.default.readdirSync(this.schemaDir).filter(f => f.endsWith('.an5'));
|
|
106
|
-
for (const file of files) {
|
|
107
|
-
this.schemaText += fs_1.default.readFileSync(path_1.default.join(this.schemaDir, file), 'utf8') + '\n';
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
throw new Error(`No schema directory found at ${this.schemaDir}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
parseModelLine(line, model) {
|
|
115
|
-
if (line.startsWith('@@map')) {
|
|
116
|
-
const mapMatch = line.match(/@@map\("(.+)"\)/);
|
|
117
|
-
if (mapMatch)
|
|
118
|
-
model.tableName = mapMatch[1];
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (line.startsWith('@@schema')) {
|
|
122
|
-
const schemaMatch = line.match(/@@schema\("(.+)"\)/);
|
|
123
|
-
if (schemaMatch)
|
|
124
|
-
model.schemaName = schemaMatch[1];
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
if (line.startsWith('@@unique')) {
|
|
128
|
-
const uniqueMatch = line.match(/@@unique\(\[([\w,\s]+)\]\)/);
|
|
129
|
-
if (uniqueMatch) {
|
|
130
|
-
const fields = uniqueMatch[1].split(',').map(f => f.trim());
|
|
131
|
-
model.compoundUniques = model.compoundUniques || [];
|
|
132
|
-
model.compoundUniques.push(fields);
|
|
133
|
-
}
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
if (line.startsWith('@@description')) {
|
|
137
|
-
const descMatch = line.match(/@@description\("(.+)"\)/);
|
|
138
|
-
if (descMatch)
|
|
139
|
-
model.description = descMatch[1];
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (line.startsWith('@@'))
|
|
143
|
-
return;
|
|
144
|
-
const parts = line.split(/\s+/);
|
|
145
|
-
const fieldName = parts[0];
|
|
146
|
-
let fieldType = parts[1];
|
|
147
|
-
if (!fieldName || !fieldType)
|
|
148
|
-
return;
|
|
149
|
-
const isArray = fieldType.endsWith('[]');
|
|
150
|
-
const isOptional = fieldType.endsWith('?');
|
|
151
|
-
const cleanType = fieldType.replace('[]', '').replace('?', '');
|
|
152
|
-
// Parse SQL Server type (e.g., "NVARCHAR(255)" → base="NVARCHAR")
|
|
153
|
-
const { base: sqlBase } = parseSqlType(cleanType);
|
|
154
|
-
let tsType = 'any';
|
|
155
|
-
let isRelation = false;
|
|
156
|
-
// Check if it's a known SQL Server type
|
|
157
|
-
if (AN5_TO_TS[sqlBase]) {
|
|
158
|
-
tsType = sqlTypeToTs(cleanType);
|
|
159
|
-
}
|
|
160
|
-
else if (cleanType[0] === cleanType[0].toUpperCase() && !cleanType.includes('(')) {
|
|
161
|
-
// Uppercase without parens = likely a relation to another model
|
|
162
|
-
tsType = cleanType;
|
|
163
|
-
isRelation = true;
|
|
164
|
-
}
|
|
165
|
-
if (isRelation) {
|
|
166
|
-
let foreignKey = '', localKey = '', relationName = '';
|
|
167
|
-
const nameMatch = line.match(/@relation\("(\w+)"/);
|
|
168
|
-
if (nameMatch)
|
|
169
|
-
relationName = nameMatch[1];
|
|
170
|
-
const relationMatch = line.match(/@relation\((?:.*fields:\s*\[(\w+)\],)?\s*(?:.*references:\s*\[(\w+)\],?)?.*\)/);
|
|
171
|
-
if (relationMatch) {
|
|
172
|
-
foreignKey = relationMatch[1] || '';
|
|
173
|
-
localKey = relationMatch[2] || '';
|
|
174
|
-
}
|
|
175
|
-
model.relations.push({ name: fieldName, type: tsType, isArray, isOptional, foreignKey, localKey, relationName });
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
const hasDefault = line.includes('@default') || line.includes('@updatedAt') || line.includes('@id');
|
|
179
|
-
const isId = line.includes('@id');
|
|
180
|
-
let description;
|
|
181
|
-
const descMatch = line.match(/@description\("(.+)"\)/);
|
|
182
|
-
if (descMatch)
|
|
183
|
-
description = descMatch[1];
|
|
184
|
-
model.fields.push({ name: fieldName, type: tsType, sqlType: cleanType, isOptional, hasDefault, isId, description });
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
postProcessRelations(models) {
|
|
188
|
-
for (const model of models) {
|
|
189
|
-
for (const rel of model.relations) {
|
|
190
|
-
if (!rel.foreignKey || !rel.localKey) {
|
|
191
|
-
const targetModel = models.find(m => m.name === rel.type);
|
|
192
|
-
if (targetModel) {
|
|
193
|
-
let opposite = rel.relationName ?
|
|
194
|
-
targetModel.relations.find(r => r.type === model.name && r.relationName === rel.relationName && r.foreignKey && r.localKey) :
|
|
195
|
-
targetModel.relations.find(r => r.type === model.name && r.foreignKey && r.localKey);
|
|
196
|
-
if (opposite) {
|
|
197
|
-
rel.foreignKey = opposite.foreignKey;
|
|
198
|
-
rel.localKey = opposite.localKey;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
exports.SchemaParser = SchemaParser;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SchemaParser = void 0;
|
|
7
|
+
exports.sqlTypeToTs = sqlTypeToTs;
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
// SQL Server type → TypeScript type mapping
|
|
11
|
+
const AN5_TO_TS = {
|
|
12
|
+
// String types
|
|
13
|
+
'NVARCHAR': 'string',
|
|
14
|
+
'VARCHAR': 'string',
|
|
15
|
+
'CHAR': 'string',
|
|
16
|
+
'NCHAR': 'string',
|
|
17
|
+
'TEXT': 'string',
|
|
18
|
+
'NTEXT': 'string',
|
|
19
|
+
'XML': 'string',
|
|
20
|
+
// Numeric types
|
|
21
|
+
'INT': 'number',
|
|
22
|
+
'SMALLINT': 'number',
|
|
23
|
+
'TINYINT': 'number',
|
|
24
|
+
'BIGINT': 'number | bigint',
|
|
25
|
+
'FLOAT': 'number',
|
|
26
|
+
'REAL': 'number',
|
|
27
|
+
'DECIMAL': 'number',
|
|
28
|
+
'NUMERIC': 'number',
|
|
29
|
+
'MONEY': 'number',
|
|
30
|
+
'SMALLMONEY': 'number',
|
|
31
|
+
// Boolean
|
|
32
|
+
'BIT': 'boolean',
|
|
33
|
+
// Date types
|
|
34
|
+
'DATETIME': 'Date',
|
|
35
|
+
'DATETIME2': 'Date',
|
|
36
|
+
'SMALLDATETIME': 'Date',
|
|
37
|
+
'DATE': 'Date',
|
|
38
|
+
'TIME': 'Date',
|
|
39
|
+
'DATETIMEOFFSET': 'Date',
|
|
40
|
+
// Binary types
|
|
41
|
+
'VARBINARY': 'Buffer',
|
|
42
|
+
'BINARY': 'Buffer',
|
|
43
|
+
'IMAGE': 'Buffer',
|
|
44
|
+
// Other
|
|
45
|
+
'UNIQUEIDENTIFIER': 'string',
|
|
46
|
+
'SQL_VARIANT': 'any',
|
|
47
|
+
'ROWVERSION': 'Buffer',
|
|
48
|
+
'HIERARCHYID': 'string',
|
|
49
|
+
'GEOGRAPHY': 'string',
|
|
50
|
+
'GEOMETRY': 'string',
|
|
51
|
+
'VECTOR': 'number[] | string',
|
|
52
|
+
};
|
|
53
|
+
// Parse base type from "NVARCHAR(255)" → "NVARCHAR"
|
|
54
|
+
function parseSqlType(raw) {
|
|
55
|
+
const match = raw.match(/^(\w+)(?:\((.+)\))?$/);
|
|
56
|
+
if (!match)
|
|
57
|
+
return { base: raw, params: '' };
|
|
58
|
+
return { base: match[1].toUpperCase(), params: match[2] || '' };
|
|
59
|
+
}
|
|
60
|
+
// Map SQL Server type to TypeScript type
|
|
61
|
+
function sqlTypeToTs(sqlType) {
|
|
62
|
+
const { base } = parseSqlType(sqlType);
|
|
63
|
+
return AN5_TO_TS[base] || 'any';
|
|
64
|
+
}
|
|
65
|
+
class SchemaParser {
|
|
66
|
+
constructor(schemaDir) {
|
|
67
|
+
this.schemaDir = schemaDir;
|
|
68
|
+
this.schemaText = '';
|
|
69
|
+
}
|
|
70
|
+
async parse() {
|
|
71
|
+
this.loadSchema();
|
|
72
|
+
const lines = this.schemaText.split('\n');
|
|
73
|
+
const models = [];
|
|
74
|
+
let currentModel = null;
|
|
75
|
+
for (let line of lines) {
|
|
76
|
+
line = line.trim();
|
|
77
|
+
if (!line || line.startsWith('//'))
|
|
78
|
+
continue;
|
|
79
|
+
const modelHeaderMatch = line.match(/^model\s+(\w+)\s*\{/);
|
|
80
|
+
if (modelHeaderMatch) {
|
|
81
|
+
const modelName = modelHeaderMatch[1];
|
|
82
|
+
currentModel = {
|
|
83
|
+
name: modelName,
|
|
84
|
+
tableName: modelName.toLowerCase() + 's',
|
|
85
|
+
schemaName: 'dbo',
|
|
86
|
+
fields: [],
|
|
87
|
+
relations: []
|
|
88
|
+
};
|
|
89
|
+
models.push(currentModel);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (line === '}') {
|
|
93
|
+
currentModel = null;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (currentModel) {
|
|
97
|
+
this.parseModelLine(line, currentModel);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
this.postProcessRelations(models);
|
|
101
|
+
return models;
|
|
102
|
+
}
|
|
103
|
+
loadSchema() {
|
|
104
|
+
if (fs_1.default.existsSync(this.schemaDir)) {
|
|
105
|
+
const files = fs_1.default.readdirSync(this.schemaDir).filter(f => f.endsWith('.an5'));
|
|
106
|
+
for (const file of files) {
|
|
107
|
+
this.schemaText += fs_1.default.readFileSync(path_1.default.join(this.schemaDir, file), 'utf8') + '\n';
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
throw new Error(`No schema directory found at ${this.schemaDir}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
parseModelLine(line, model) {
|
|
115
|
+
if (line.startsWith('@@map')) {
|
|
116
|
+
const mapMatch = line.match(/@@map\("(.+)"\)/);
|
|
117
|
+
if (mapMatch)
|
|
118
|
+
model.tableName = mapMatch[1];
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (line.startsWith('@@schema')) {
|
|
122
|
+
const schemaMatch = line.match(/@@schema\("(.+)"\)/);
|
|
123
|
+
if (schemaMatch)
|
|
124
|
+
model.schemaName = schemaMatch[1];
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (line.startsWith('@@unique')) {
|
|
128
|
+
const uniqueMatch = line.match(/@@unique\(\[([\w,\s]+)\]\)/);
|
|
129
|
+
if (uniqueMatch) {
|
|
130
|
+
const fields = uniqueMatch[1].split(',').map(f => f.trim());
|
|
131
|
+
model.compoundUniques = model.compoundUniques || [];
|
|
132
|
+
model.compoundUniques.push(fields);
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (line.startsWith('@@description')) {
|
|
137
|
+
const descMatch = line.match(/@@description\("(.+)"\)/);
|
|
138
|
+
if (descMatch)
|
|
139
|
+
model.description = descMatch[1];
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (line.startsWith('@@'))
|
|
143
|
+
return;
|
|
144
|
+
const parts = line.split(/\s+/);
|
|
145
|
+
const fieldName = parts[0];
|
|
146
|
+
let fieldType = parts[1];
|
|
147
|
+
if (!fieldName || !fieldType)
|
|
148
|
+
return;
|
|
149
|
+
const isArray = fieldType.endsWith('[]');
|
|
150
|
+
const isOptional = fieldType.endsWith('?');
|
|
151
|
+
const cleanType = fieldType.replace('[]', '').replace('?', '');
|
|
152
|
+
// Parse SQL Server type (e.g., "NVARCHAR(255)" → base="NVARCHAR")
|
|
153
|
+
const { base: sqlBase } = parseSqlType(cleanType);
|
|
154
|
+
let tsType = 'any';
|
|
155
|
+
let isRelation = false;
|
|
156
|
+
// Check if it's a known SQL Server type
|
|
157
|
+
if (AN5_TO_TS[sqlBase]) {
|
|
158
|
+
tsType = sqlTypeToTs(cleanType);
|
|
159
|
+
}
|
|
160
|
+
else if (cleanType[0] === cleanType[0].toUpperCase() && !cleanType.includes('(')) {
|
|
161
|
+
// Uppercase without parens = likely a relation to another model
|
|
162
|
+
tsType = cleanType;
|
|
163
|
+
isRelation = true;
|
|
164
|
+
}
|
|
165
|
+
if (isRelation) {
|
|
166
|
+
let foreignKey = '', localKey = '', relationName = '';
|
|
167
|
+
const nameMatch = line.match(/@relation\("(\w+)"/);
|
|
168
|
+
if (nameMatch)
|
|
169
|
+
relationName = nameMatch[1];
|
|
170
|
+
const relationMatch = line.match(/@relation\((?:.*fields:\s*\[(\w+)\],)?\s*(?:.*references:\s*\[(\w+)\],?)?.*\)/);
|
|
171
|
+
if (relationMatch) {
|
|
172
|
+
foreignKey = relationMatch[1] || '';
|
|
173
|
+
localKey = relationMatch[2] || '';
|
|
174
|
+
}
|
|
175
|
+
model.relations.push({ name: fieldName, type: tsType, isArray, isOptional, foreignKey, localKey, relationName });
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const hasDefault = line.includes('@default') || line.includes('@updatedAt') || line.includes('@id');
|
|
179
|
+
const isId = line.includes('@id');
|
|
180
|
+
let description;
|
|
181
|
+
const descMatch = line.match(/@description\("(.+)"\)/);
|
|
182
|
+
if (descMatch)
|
|
183
|
+
description = descMatch[1];
|
|
184
|
+
model.fields.push({ name: fieldName, type: tsType, sqlType: cleanType, isOptional, hasDefault, isId, description });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
postProcessRelations(models) {
|
|
188
|
+
for (const model of models) {
|
|
189
|
+
for (const rel of model.relations) {
|
|
190
|
+
if (!rel.foreignKey || !rel.localKey) {
|
|
191
|
+
const targetModel = models.find(m => m.name === rel.type);
|
|
192
|
+
if (targetModel) {
|
|
193
|
+
let opposite = rel.relationName ?
|
|
194
|
+
targetModel.relations.find(r => r.type === model.name && r.relationName === rel.relationName && r.foreignKey && r.localKey) :
|
|
195
|
+
targetModel.relations.find(r => r.type === model.name && r.foreignKey && r.localKey);
|
|
196
|
+
if (opposite) {
|
|
197
|
+
rel.foreignKey = opposite.foreignKey;
|
|
198
|
+
rel.localKey = opposite.localKey;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
exports.SchemaParser = SchemaParser;
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import { Model } from './types';
|
|
2
|
-
export declare class PythonGenerator {
|
|
3
|
-
private outputPath;
|
|
4
|
-
constructor(outputPath: string);
|
|
5
|
-
generate(models: Model[]): void;
|
|
6
|
-
private
|
|
7
|
-
private
|
|
8
|
-
private
|
|
9
|
-
|
|
1
|
+
import { Model } from './types';
|
|
2
|
+
export declare class PythonGenerator {
|
|
3
|
+
private outputPath;
|
|
4
|
+
constructor(outputPath: string);
|
|
5
|
+
generate(models: Model[]): void;
|
|
6
|
+
private getPyFilterType;
|
|
7
|
+
private generateOrmTypes;
|
|
8
|
+
private generateMetadata;
|
|
9
|
+
private mapPyType;
|
|
10
|
+
private generateModels;
|
|
11
|
+
private generateClient;
|
|
12
|
+
private generateInit;
|
|
13
|
+
private getAllPropertyVariations;
|
|
14
|
+
private formatFields;
|
|
15
|
+
private pyString;
|
|
16
|
+
private toCamelCase;
|
|
17
|
+
private toSnakeCase;
|
|
18
|
+
private capitalize;
|
|
19
|
+
}
|