crudora 0.2.0 → 0.2.1
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/cli.js +55 -65
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1692 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +404 -0
- package/dist/index.d.ts +404 -15
- package/dist/index.js +1685 -27
- package/dist/index.js.map +1 -1
- package/dist/scripts/copy-assets.js +0 -21
- package/package.json +5 -4
- package/scripts/copy-assets.js +0 -21
- package/dist/core/crudora.d.ts +0 -49
- package/dist/core/crudora.d.ts.map +0 -1
- package/dist/core/crudora.js +0 -370
- package/dist/core/crudora.js.map +0 -1
- package/dist/core/crudoraServer.d.ts +0 -84
- package/dist/core/crudoraServer.d.ts.map +0 -1
- package/dist/core/crudoraServer.js +0 -202
- package/dist/core/crudoraServer.js.map +0 -1
- package/dist/core/drizzleTableBuilder.d.ts +0 -6
- package/dist/core/drizzleTableBuilder.d.ts.map +0 -1
- package/dist/core/drizzleTableBuilder.js +0 -175
- package/dist/core/drizzleTableBuilder.js.map +0 -1
- package/dist/core/model.d.ts +0 -58
- package/dist/core/model.d.ts.map +0 -1
- package/dist/core/model.js +0 -64
- package/dist/core/model.js.map +0 -1
- package/dist/core/repository.d.ts +0 -106
- package/dist/core/repository.d.ts.map +0 -1
- package/dist/core/repository.js +0 -607
- package/dist/core/repository.js.map +0 -1
- package/dist/core/schemaGenerator.d.ts +0 -6
- package/dist/core/schemaGenerator.d.ts.map +0 -1
- package/dist/core/schemaGenerator.js +0 -248
- package/dist/core/schemaGenerator.js.map +0 -1
- package/dist/decorators/model.d.ts +0 -64
- package/dist/decorators/model.d.ts.map +0 -1
- package/dist/decorators/model.js +0 -138
- package/dist/decorators/model.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/types/logger.type.d.ts +0 -7
- package/dist/types/logger.type.d.ts.map +0 -1
- package/dist/types/logger.type.js +0 -3
- package/dist/types/logger.type.js.map +0 -1
- package/dist/types/model.type.d.ts +0 -38
- package/dist/types/model.type.d.ts.map +0 -1
- package/dist/types/model.type.js +0 -3
- package/dist/types/model.type.js.map +0 -1
- package/dist/utils/validation.d.ts +0 -7
- package/dist/utils/validation.d.ts.map +0 -1
- package/dist/utils/validation.js +0 -107
- package/dist/utils/validation.js.map +0 -1
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Dialect } from '../types/model.type';
|
|
2
|
-
import { ModelConstructor } from './model';
|
|
3
|
-
export declare class SchemaGenerator {
|
|
4
|
-
static generateDrizzleSchema(models: ModelConstructor[], dialect: Dialect): string;
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=schemaGenerator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schemaGenerator.d.ts","sourceRoot":"","sources":["../../src/core/schemaGenerator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAA2B,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAmK3C,qBAAa,eAAe;IAC1B,MAAM,CAAC,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM;CAsDnF"}
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SchemaGenerator = void 0;
|
|
4
|
-
const model_1 = require("../decorators/model");
|
|
5
|
-
/** Escape single-quotes and backslashes so the string is safe inside a JS single-quoted literal. */
|
|
6
|
-
function safe(s) {
|
|
7
|
-
return s.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
8
|
-
}
|
|
9
|
-
function pgColumnDef(name, opts) {
|
|
10
|
-
const type = opts.type;
|
|
11
|
-
let col;
|
|
12
|
-
const n = safe(name);
|
|
13
|
-
switch (type) {
|
|
14
|
-
case 'uuid':
|
|
15
|
-
col = `uuid('${n}')`;
|
|
16
|
-
break;
|
|
17
|
-
case 'text':
|
|
18
|
-
col = `text('${n}')`;
|
|
19
|
-
break;
|
|
20
|
-
case 'integer':
|
|
21
|
-
col = `integer('${n}')`;
|
|
22
|
-
break;
|
|
23
|
-
case 'number':
|
|
24
|
-
col = `doublePrecision('${n}')`;
|
|
25
|
-
break;
|
|
26
|
-
case 'boolean':
|
|
27
|
-
col = `boolean('${n}')`;
|
|
28
|
-
break;
|
|
29
|
-
case 'date':
|
|
30
|
-
col = `timestamp('${n}', { mode: 'date' })`;
|
|
31
|
-
break;
|
|
32
|
-
case 'decimal':
|
|
33
|
-
col = `decimal('${n}', { precision: ${opts.precision ?? 10}, scale: ${opts.scale ?? 2} })`;
|
|
34
|
-
break;
|
|
35
|
-
case 'json':
|
|
36
|
-
col = `json('${n}')`;
|
|
37
|
-
break;
|
|
38
|
-
case 'enum':
|
|
39
|
-
col = `text('${n}')`;
|
|
40
|
-
break;
|
|
41
|
-
case 'bigint':
|
|
42
|
-
col = `bigint('${n}', { mode: 'number' })`;
|
|
43
|
-
break;
|
|
44
|
-
case 'serial':
|
|
45
|
-
col = `serial('${n}')`;
|
|
46
|
-
break;
|
|
47
|
-
case 'array':
|
|
48
|
-
col = `text('${n}').array()`;
|
|
49
|
-
break;
|
|
50
|
-
case 'string':
|
|
51
|
-
default:
|
|
52
|
-
col = `varchar('${n}', { length: ${opts.length ?? 255} })`;
|
|
53
|
-
}
|
|
54
|
-
if (opts.primary)
|
|
55
|
-
col += '.primaryKey()';
|
|
56
|
-
if (opts.required && !opts.nullable && opts.type !== 'serial')
|
|
57
|
-
col += '.notNull()';
|
|
58
|
-
if (opts.unique)
|
|
59
|
-
col += '.unique()';
|
|
60
|
-
if (opts.default !== undefined && opts.type !== 'serial')
|
|
61
|
-
col += `.default(${JSON.stringify(opts.default)})`;
|
|
62
|
-
return col;
|
|
63
|
-
}
|
|
64
|
-
function mysqlColumnDef(name, opts) {
|
|
65
|
-
const type = opts.type;
|
|
66
|
-
let col;
|
|
67
|
-
const n = safe(name);
|
|
68
|
-
switch (type) {
|
|
69
|
-
case 'uuid':
|
|
70
|
-
col = `varchar('${n}', { length: 36 })`;
|
|
71
|
-
break;
|
|
72
|
-
case 'text':
|
|
73
|
-
col = `text('${n}')`;
|
|
74
|
-
break;
|
|
75
|
-
case 'integer':
|
|
76
|
-
col = `int('${n}')`;
|
|
77
|
-
break;
|
|
78
|
-
case 'number':
|
|
79
|
-
col = `double('${n}')`;
|
|
80
|
-
break;
|
|
81
|
-
case 'boolean':
|
|
82
|
-
col = `boolean('${n}')`;
|
|
83
|
-
break;
|
|
84
|
-
case 'date':
|
|
85
|
-
col = `datetime('${n}', { mode: 'date' })`;
|
|
86
|
-
break;
|
|
87
|
-
case 'decimal':
|
|
88
|
-
col = `decimal('${n}', { precision: ${opts.precision ?? 10}, scale: ${opts.scale ?? 2} })`;
|
|
89
|
-
break;
|
|
90
|
-
case 'json':
|
|
91
|
-
col = `json('${n}')`;
|
|
92
|
-
break;
|
|
93
|
-
case 'enum':
|
|
94
|
-
col = `mysqlEnum('${n}', [${(opts.enumValues ?? []).map((v) => `'${safe(v)}'`).join(', ')}])`;
|
|
95
|
-
break;
|
|
96
|
-
case 'bigint':
|
|
97
|
-
col = `bigint('${n}', { mode: 'number' })`;
|
|
98
|
-
break;
|
|
99
|
-
case 'serial':
|
|
100
|
-
col = `int('${n}').autoincrement()`;
|
|
101
|
-
break;
|
|
102
|
-
case 'array':
|
|
103
|
-
col = `json('${n}')`;
|
|
104
|
-
break;
|
|
105
|
-
case 'string':
|
|
106
|
-
default:
|
|
107
|
-
col = `varchar('${n}', { length: ${opts.length ?? 255} })`;
|
|
108
|
-
}
|
|
109
|
-
if (opts.primary)
|
|
110
|
-
col += '.primaryKey()';
|
|
111
|
-
if (opts.required && !opts.nullable && opts.type !== 'serial')
|
|
112
|
-
col += '.notNull()';
|
|
113
|
-
if (opts.unique)
|
|
114
|
-
col += '.unique()';
|
|
115
|
-
if (opts.default !== undefined && opts.type !== 'serial')
|
|
116
|
-
col += `.default(${JSON.stringify(opts.default)})`;
|
|
117
|
-
return col;
|
|
118
|
-
}
|
|
119
|
-
function generateModelBlock(modelClass, dialect, schemaVars) {
|
|
120
|
-
const fields = (0, model_1.getFieldMetadata)(modelClass);
|
|
121
|
-
const tableName = modelClass.getTableName();
|
|
122
|
-
const schemaName = modelClass.schema;
|
|
123
|
-
const exportName = modelClass.name.charAt(0).toLowerCase() + modelClass.name.slice(1) + 'Table';
|
|
124
|
-
const columnDef = dialect === 'postgresql' ? pgColumnDef : mysqlColumnDef;
|
|
125
|
-
const cols = [];
|
|
126
|
-
for (const [fieldName, opts] of Object.entries(fields)) {
|
|
127
|
-
cols.push(` ${fieldName}: ${columnDef(fieldName, opts)},`);
|
|
128
|
-
}
|
|
129
|
-
if (modelClass.timestamps !== false) {
|
|
130
|
-
if (dialect === 'postgresql') {
|
|
131
|
-
cols.push(` createdAt: timestamp('createdAt', { mode: 'date' }).defaultNow().notNull(),`);
|
|
132
|
-
cols.push(` updatedAt: timestamp('updatedAt', { mode: 'date' }).defaultNow().notNull(),`);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
cols.push(` createdAt: datetime('createdAt', { mode: 'date' }).notNull(),`);
|
|
136
|
-
cols.push(` updatedAt: datetime('updatedAt', { mode: 'date' }).notNull(),`);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (modelClass.softDelete) {
|
|
140
|
-
if (dialect === 'postgresql') {
|
|
141
|
-
cols.push(` deletedAt: timestamp('deletedAt', { mode: 'date' }),`);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
cols.push(` deletedAt: datetime('deletedAt', { mode: 'date' }),`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
let tableCall;
|
|
148
|
-
if (schemaName) {
|
|
149
|
-
const schemaVar = schemaVars.get(schemaName);
|
|
150
|
-
tableCall = `${schemaVar}.table('${safe(tableName)}', {\n${cols.join('\n')}\n})`;
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
const tableFactory = dialect === 'postgresql' ? 'pgTable' : 'mysqlTable';
|
|
154
|
-
tableCall = `${tableFactory}('${safe(tableName)}', {\n${cols.join('\n')}\n})`;
|
|
155
|
-
}
|
|
156
|
-
return `export const ${exportName} = ${tableCall};\n`;
|
|
157
|
-
}
|
|
158
|
-
class SchemaGenerator {
|
|
159
|
-
static generateDrizzleSchema(models, dialect) {
|
|
160
|
-
const schemaNames = new Set();
|
|
161
|
-
for (const m of models) {
|
|
162
|
-
const s = m.schema;
|
|
163
|
-
if (s)
|
|
164
|
-
schemaNames.add(s);
|
|
165
|
-
}
|
|
166
|
-
// Assign variable names for each schema
|
|
167
|
-
const schemaVars = new Map();
|
|
168
|
-
for (const name of schemaNames) {
|
|
169
|
-
schemaVars.set(name, name + 'Schema');
|
|
170
|
-
}
|
|
171
|
-
// Collect imports
|
|
172
|
-
const coreImports = new Set();
|
|
173
|
-
const schemaFactory = dialect === 'postgresql' ? 'pgSchema' : 'mysqlSchema';
|
|
174
|
-
const tableFactory = dialect === 'postgresql' ? 'pgTable' : 'mysqlTable';
|
|
175
|
-
const pkg = dialect === 'postgresql' ? 'drizzle-orm/pg-core' : 'drizzle-orm/mysql-core';
|
|
176
|
-
if (schemaNames.size > 0)
|
|
177
|
-
coreImports.add(schemaFactory);
|
|
178
|
-
// Check if any model uses default (no schema) tables
|
|
179
|
-
const hasDefaultSchema = models.some((m) => !m.schema);
|
|
180
|
-
if (hasDefaultSchema)
|
|
181
|
-
coreImports.add(tableFactory);
|
|
182
|
-
// Collect column builder imports
|
|
183
|
-
const colImports = new Set();
|
|
184
|
-
for (const modelClass of models) {
|
|
185
|
-
const fields = (0, model_1.getFieldMetadata)(modelClass);
|
|
186
|
-
for (const opts of Object.values(fields)) {
|
|
187
|
-
colImports.add(getColumnImport(opts.type, dialect));
|
|
188
|
-
}
|
|
189
|
-
if (modelClass.timestamps !== false) {
|
|
190
|
-
colImports.add(dialect === 'postgresql' ? 'timestamp' : 'datetime');
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
const allImports = new Set([...coreImports, ...colImports]);
|
|
194
|
-
let output = `// Auto-generated by Crudora — do not edit manually\n`;
|
|
195
|
-
output += `import { ${[...allImports].sort().join(', ')} } from '${pkg}';\n\n`;
|
|
196
|
-
// Schema variable declarations
|
|
197
|
-
for (const [name, varName] of schemaVars) {
|
|
198
|
-
output += `const ${varName} = ${schemaFactory}('${safe(name)}');\n`;
|
|
199
|
-
}
|
|
200
|
-
if (schemaVars.size > 0)
|
|
201
|
-
output += '\n';
|
|
202
|
-
// Model table blocks
|
|
203
|
-
for (const modelClass of models) {
|
|
204
|
-
output += generateModelBlock(modelClass, dialect, schemaVars) + '\n';
|
|
205
|
-
}
|
|
206
|
-
return output;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
exports.SchemaGenerator = SchemaGenerator;
|
|
210
|
-
function getColumnImport(type, dialect) {
|
|
211
|
-
if (dialect === 'postgresql') {
|
|
212
|
-
const map = {
|
|
213
|
-
uuid: 'uuid',
|
|
214
|
-
text: 'text',
|
|
215
|
-
string: 'varchar',
|
|
216
|
-
integer: 'integer',
|
|
217
|
-
number: 'doublePrecision',
|
|
218
|
-
boolean: 'boolean',
|
|
219
|
-
date: 'timestamp',
|
|
220
|
-
decimal: 'decimal',
|
|
221
|
-
json: 'json',
|
|
222
|
-
enum: 'text',
|
|
223
|
-
bigint: 'bigint',
|
|
224
|
-
serial: 'serial',
|
|
225
|
-
array: 'text',
|
|
226
|
-
};
|
|
227
|
-
return map[type] ?? 'varchar';
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
const map = {
|
|
231
|
-
uuid: 'varchar',
|
|
232
|
-
text: 'text',
|
|
233
|
-
string: 'varchar',
|
|
234
|
-
integer: 'int',
|
|
235
|
-
number: 'double',
|
|
236
|
-
boolean: 'boolean',
|
|
237
|
-
date: 'datetime',
|
|
238
|
-
decimal: 'decimal',
|
|
239
|
-
json: 'json',
|
|
240
|
-
enum: 'mysqlEnum',
|
|
241
|
-
bigint: 'bigint',
|
|
242
|
-
serial: 'int',
|
|
243
|
-
array: 'json',
|
|
244
|
-
};
|
|
245
|
-
return map[type] ?? 'varchar';
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
//# sourceMappingURL=schemaGenerator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schemaGenerator.js","sourceRoot":"","sources":["../../src/core/schemaGenerator.ts"],"names":[],"mappings":";;;AAAA,+CAAuD;AAIvD,oGAAoG;AACpG,SAAS,IAAI,CAAC,CAAS;IACrB,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,WAAW,CAAC,IAAY,EAAE,IAAkB;IACnD,MAAM,IAAI,GAAc,IAAI,CAAC,IAAI,CAAC;IAClC,IAAI,GAAW,CAAC;IAEhB,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IACrB,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,MAAM;YACT,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC;YACrB,MAAM;QACR,KAAK,MAAM;YACT,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC;YACrB,MAAM;QACR,KAAK,SAAS;YACZ,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC;YACxB,MAAM;QACR,KAAK,QAAQ;YACX,GAAG,GAAG,oBAAoB,CAAC,IAAI,CAAC;YAChC,MAAM;QACR,KAAK,SAAS;YACZ,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC;YACxB,MAAM;QACR,KAAK,MAAM;YACT,GAAG,GAAG,cAAc,CAAC,sBAAsB,CAAC;YAC5C,MAAM;QACR,KAAK,SAAS;YACZ,GAAG,GAAG,YAAY,CAAC,mBAAmB,IAAI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,EAAE,iBAAiB;YACzB,OAAO,EAAE,SAAS;YAClB,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,SAAS;YAClB,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,QAAQ;YAChB,MAAM,EAAE,QAAQ;YAChB,KAAK,EAAE,MAAM;SACd,CAAC;QACF,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC;IAChC,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,GAA8B;YACrC,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,SAAS;YACjB,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,SAAS;YAClB,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,SAAS;YAClB,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,QAAQ;YAChB,MAAM,EAAE,KAAK;YACb,KAAK,EAAE,MAAM;SACd,CAAC;QACF,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC;IAChC,CAAC;AACH,CAAC"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { FieldOptions, ModelOptions, RelationDefinition } from '../types/model.type';
|
|
3
|
-
export declare function Model(options?: ModelOptions): <T extends {
|
|
4
|
-
new (...args: any[]): {};
|
|
5
|
-
}>(constructor: T) => T;
|
|
6
|
-
export declare function Field(options: FieldOptions): (target: any, context: any) => void;
|
|
7
|
-
export declare function getModelMetadata(target: any): any;
|
|
8
|
-
export declare function getFieldMetadata(target: any): any;
|
|
9
|
-
/**
|
|
10
|
-
* Declares a one-to-many relation.
|
|
11
|
-
* @param model Lazy getter returning the related model constructor.
|
|
12
|
-
* @param foreignKey Column on the **related** table that references this model.
|
|
13
|
-
* @param localKey Column on **this** table (defaults to this model's primary key).
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* class User extends Model {
|
|
17
|
-
* @HasMany(() => Post, 'authorId')
|
|
18
|
-
* posts?: Post[];
|
|
19
|
-
* }
|
|
20
|
-
*/
|
|
21
|
-
export declare function HasMany(model: () => any, foreignKey: string, localKey?: string): (target: any, propertyKey: string) => void;
|
|
22
|
-
/**
|
|
23
|
-
* Declares a one-to-one relation where the FK lives on the related table.
|
|
24
|
-
* @param model Lazy getter returning the related model constructor.
|
|
25
|
-
* @param foreignKey Column on the **related** table that references this model.
|
|
26
|
-
* @param localKey Column on **this** table (defaults to primary key).
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* class User extends Model {
|
|
30
|
-
* @HasOne(() => Profile, 'userId')
|
|
31
|
-
* profile?: Profile;
|
|
32
|
-
* }
|
|
33
|
-
*/
|
|
34
|
-
export declare function HasOne(model: () => any, foreignKey: string, localKey?: string): (target: any, propertyKey: string) => void;
|
|
35
|
-
/**
|
|
36
|
-
* Declares a many-to-one (or one-to-one) relation where the FK lives on **this** table.
|
|
37
|
-
* @param model Lazy getter returning the related model constructor.
|
|
38
|
-
* @param foreignKey Column on **this** table that holds the FK value.
|
|
39
|
-
* @param ownerKey Column on the **related** table being pointed to (defaults to its primary key).
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* class Post extends Model {
|
|
43
|
-
* @BelongsTo(() => User, 'authorId')
|
|
44
|
-
* author?: User;
|
|
45
|
-
* }
|
|
46
|
-
*/
|
|
47
|
-
export declare function BelongsTo(model: () => any, foreignKey: string, ownerKey?: string): (target: any, propertyKey: string) => void;
|
|
48
|
-
/**
|
|
49
|
-
* Declares a many-to-many relation through a pivot/junction model.
|
|
50
|
-
* @param model Lazy getter returning the **related** model constructor.
|
|
51
|
-
* @param pivotModel Lazy getter returning the **pivot** model constructor.
|
|
52
|
-
* @param pivotForeignKey Column on the pivot table that references **this** model.
|
|
53
|
-
* @param pivotRelatedKey Column on the pivot table that references the **related** model.
|
|
54
|
-
* @param localKey Override for this model's local key (defaults to primary key).
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* class User extends Model {
|
|
58
|
-
* @BelongsToMany(() => Role, () => UserRole, 'userId', 'roleId')
|
|
59
|
-
* roles?: Role[];
|
|
60
|
-
* }
|
|
61
|
-
*/
|
|
62
|
-
export declare function BelongsToMany(model: () => any, pivotModel: () => any, pivotForeignKey: string, pivotRelatedKey: string, localKey?: string): (target: any, propertyKey: string) => void;
|
|
63
|
-
export declare function getRelationMetadata(target: any): Record<string, RelationDefinition>;
|
|
64
|
-
//# sourceMappingURL=model.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/decorators/model.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAgB,MAAM,qBAAqB,CAAC;AAKnG,wBAAgB,KAAK,CAAC,OAAO,GAAE,YAAiB,IAC7B,CAAC,SAAS;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA;CAAE,EAAE,aAAa,CAAC,OAQxE;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,YAAY,IACxB,QAAQ,GAAG,EAAE,SAAS,GAAG,UAiB3C;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,GAAG,OAE3C;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,GAAG,OAE3C;AAgBD;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,YArBpD,GAAG,eAAe,MAAM,UAuBlD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,YArCnD,GAAG,eAAe,MAAM,UAuClD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,YArDtD,GAAG,eAAe,MAAM,UAuDlD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,GAAG,EAChB,UAAU,EAAE,MAAM,GAAG,EACrB,eAAe,EAAE,MAAM,EACvB,eAAe,EAAE,MAAM,EACvB,QAAQ,CAAC,EAAE,MAAM,IAEA,QAAQ,GAAG,EAAE,aAAa,MAAM,UAclD;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAEnF"}
|
package/dist/decorators/model.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Model = Model;
|
|
4
|
-
exports.Field = Field;
|
|
5
|
-
exports.getModelMetadata = getModelMetadata;
|
|
6
|
-
exports.getFieldMetadata = getFieldMetadata;
|
|
7
|
-
exports.HasMany = HasMany;
|
|
8
|
-
exports.HasOne = HasOne;
|
|
9
|
-
exports.BelongsTo = BelongsTo;
|
|
10
|
-
exports.BelongsToMany = BelongsToMany;
|
|
11
|
-
exports.getRelationMetadata = getRelationMetadata;
|
|
12
|
-
require("reflect-metadata");
|
|
13
|
-
const MODEL_METADATA_KEY = Symbol('model');
|
|
14
|
-
const FIELD_METADATA_KEY = Symbol('field');
|
|
15
|
-
function Model(options = {}) {
|
|
16
|
-
return function (constructor) {
|
|
17
|
-
Reflect.defineMetadata(MODEL_METADATA_KEY, {
|
|
18
|
-
tableName: options.tableName || constructor.name.toLowerCase(),
|
|
19
|
-
timestamps: options.timestamps !== false,
|
|
20
|
-
constructor
|
|
21
|
-
}, constructor);
|
|
22
|
-
return constructor;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function Field(options) {
|
|
26
|
-
return function (target, context) {
|
|
27
|
-
// Support both old and new decorator syntax
|
|
28
|
-
if (typeof context === 'string') {
|
|
29
|
-
// Old decorator syntax (target, propertyKey)
|
|
30
|
-
const propertyKey = context;
|
|
31
|
-
const existingFields = Reflect.getMetadata(FIELD_METADATA_KEY, target.constructor) || {};
|
|
32
|
-
existingFields[propertyKey] = options;
|
|
33
|
-
Reflect.defineMetadata(FIELD_METADATA_KEY, existingFields, target.constructor);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
// New decorator syntax (target, context)
|
|
37
|
-
const propertyKey = context.name;
|
|
38
|
-
const constructor = target.constructor;
|
|
39
|
-
const existingFields = Reflect.getMetadata(FIELD_METADATA_KEY, constructor) || {};
|
|
40
|
-
existingFields[propertyKey] = options;
|
|
41
|
-
Reflect.defineMetadata(FIELD_METADATA_KEY, existingFields, constructor);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function getModelMetadata(target) {
|
|
46
|
-
return Reflect.getMetadata(MODEL_METADATA_KEY, target);
|
|
47
|
-
}
|
|
48
|
-
function getFieldMetadata(target) {
|
|
49
|
-
return Reflect.getMetadata(FIELD_METADATA_KEY, target) || {};
|
|
50
|
-
}
|
|
51
|
-
// ─── Relation decorators ──────────────────────────────────────────────────────
|
|
52
|
-
const RELATION_METADATA_KEY = Symbol('relations');
|
|
53
|
-
function defineRelation(type, model, foreignKey, relatedKey) {
|
|
54
|
-
return function (target, propertyKey) {
|
|
55
|
-
const constructor = target.constructor;
|
|
56
|
-
const existing = Reflect.getMetadata(RELATION_METADATA_KEY, constructor) || {};
|
|
57
|
-
existing[propertyKey] = { type, model, foreignKey, relatedKey };
|
|
58
|
-
Reflect.defineMetadata(RELATION_METADATA_KEY, existing, constructor);
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Declares a one-to-many relation.
|
|
63
|
-
* @param model Lazy getter returning the related model constructor.
|
|
64
|
-
* @param foreignKey Column on the **related** table that references this model.
|
|
65
|
-
* @param localKey Column on **this** table (defaults to this model's primary key).
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* class User extends Model {
|
|
69
|
-
* @HasMany(() => Post, 'authorId')
|
|
70
|
-
* posts?: Post[];
|
|
71
|
-
* }
|
|
72
|
-
*/
|
|
73
|
-
function HasMany(model, foreignKey, localKey) {
|
|
74
|
-
return defineRelation('hasMany', model, foreignKey, localKey);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Declares a one-to-one relation where the FK lives on the related table.
|
|
78
|
-
* @param model Lazy getter returning the related model constructor.
|
|
79
|
-
* @param foreignKey Column on the **related** table that references this model.
|
|
80
|
-
* @param localKey Column on **this** table (defaults to primary key).
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* class User extends Model {
|
|
84
|
-
* @HasOne(() => Profile, 'userId')
|
|
85
|
-
* profile?: Profile;
|
|
86
|
-
* }
|
|
87
|
-
*/
|
|
88
|
-
function HasOne(model, foreignKey, localKey) {
|
|
89
|
-
return defineRelation('hasOne', model, foreignKey, localKey);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Declares a many-to-one (or one-to-one) relation where the FK lives on **this** table.
|
|
93
|
-
* @param model Lazy getter returning the related model constructor.
|
|
94
|
-
* @param foreignKey Column on **this** table that holds the FK value.
|
|
95
|
-
* @param ownerKey Column on the **related** table being pointed to (defaults to its primary key).
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* class Post extends Model {
|
|
99
|
-
* @BelongsTo(() => User, 'authorId')
|
|
100
|
-
* author?: User;
|
|
101
|
-
* }
|
|
102
|
-
*/
|
|
103
|
-
function BelongsTo(model, foreignKey, ownerKey) {
|
|
104
|
-
return defineRelation('belongsTo', model, foreignKey, ownerKey);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Declares a many-to-many relation through a pivot/junction model.
|
|
108
|
-
* @param model Lazy getter returning the **related** model constructor.
|
|
109
|
-
* @param pivotModel Lazy getter returning the **pivot** model constructor.
|
|
110
|
-
* @param pivotForeignKey Column on the pivot table that references **this** model.
|
|
111
|
-
* @param pivotRelatedKey Column on the pivot table that references the **related** model.
|
|
112
|
-
* @param localKey Override for this model's local key (defaults to primary key).
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* class User extends Model {
|
|
116
|
-
* @BelongsToMany(() => Role, () => UserRole, 'userId', 'roleId')
|
|
117
|
-
* roles?: Role[];
|
|
118
|
-
* }
|
|
119
|
-
*/
|
|
120
|
-
function BelongsToMany(model, pivotModel, pivotForeignKey, pivotRelatedKey, localKey) {
|
|
121
|
-
return function (target, propertyKey) {
|
|
122
|
-
const constructor = target.constructor;
|
|
123
|
-
const existing = Reflect.getMetadata(RELATION_METADATA_KEY, constructor) || {};
|
|
124
|
-
existing[propertyKey] = {
|
|
125
|
-
type: 'belongsToMany',
|
|
126
|
-
model,
|
|
127
|
-
foreignKey: pivotForeignKey,
|
|
128
|
-
relatedKey: localKey,
|
|
129
|
-
pivotModel,
|
|
130
|
-
pivotRelatedKey,
|
|
131
|
-
};
|
|
132
|
-
Reflect.defineMetadata(RELATION_METADATA_KEY, existing, constructor);
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
function getRelationMetadata(target) {
|
|
136
|
-
return Reflect.getMetadata(RELATION_METADATA_KEY, target) || {};
|
|
137
|
-
}
|
|
138
|
-
//# sourceMappingURL=model.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/decorators/model.ts"],"names":[],"mappings":";;AAMA,sBASC;AAED,sBAkBC;AAED,4CAEC;AAED,4CAEC;AA4BD,0BAEC;AAcD,wBAEC;AAcD,8BAEC;AAgBD,sCAqBC;AAED,kDAEC;AAlJD,4BAA0B;AAG1B,MAAM,kBAAkB,GA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E,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,SAAS,EACT,aAAa,EACb,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC3H,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export interface CrudoraLogger {
|
|
2
|
-
error(message: string, context?: Record<string, any>): void;
|
|
3
|
-
warn(message: string, context?: Record<string, any>): void;
|
|
4
|
-
info(message: string, context?: Record<string, any>): void;
|
|
5
|
-
debug(message: string, context?: Record<string, any>): void;
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=logger.type.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.type.d.ts","sourceRoot":"","sources":["../../src/types/logger.type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAC5D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAC3D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAC3D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;CAC7D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.type.js","sourceRoot":"","sources":["../../src/types/logger.type.ts"],"names":[],"mappings":""}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export type FieldType = 'string' | 'text' | 'integer' | 'number' | 'boolean' | 'date' | 'uuid' | 'decimal' | 'json' | 'enum' | 'bigint' | 'serial' | 'array';
|
|
2
|
-
export interface FieldOptions {
|
|
3
|
-
type: FieldType;
|
|
4
|
-
required?: boolean;
|
|
5
|
-
unique?: boolean;
|
|
6
|
-
default?: any;
|
|
7
|
-
length?: number;
|
|
8
|
-
primary?: boolean;
|
|
9
|
-
nullable?: boolean;
|
|
10
|
-
precision?: number;
|
|
11
|
-
scale?: number;
|
|
12
|
-
/** Required when type is 'enum'. Lists the allowed values. */
|
|
13
|
-
enumValues?: string[];
|
|
14
|
-
}
|
|
15
|
-
export interface ModelOptions {
|
|
16
|
-
tableName?: string;
|
|
17
|
-
timestamps?: boolean;
|
|
18
|
-
}
|
|
19
|
-
export type Dialect = 'postgresql' | 'mysql';
|
|
20
|
-
export type RelationType = 'hasOne' | 'hasMany' | 'belongsTo' | 'belongsToMany';
|
|
21
|
-
export interface RelationDefinition {
|
|
22
|
-
type: RelationType;
|
|
23
|
-
/** Lazy model getter — avoids circular-import issues */
|
|
24
|
-
model: () => any;
|
|
25
|
-
/** The foreign-key column name */
|
|
26
|
-
foreignKey: string;
|
|
27
|
-
/**
|
|
28
|
-
* hasOne / hasMany: column on the owning (local) side. Defaults to the model's primary key.
|
|
29
|
-
* belongsTo : column on the related side (the "owner"). Defaults to the related model's primary key.
|
|
30
|
-
* belongsToMany: override for this model's local key (defaults to primary key).
|
|
31
|
-
*/
|
|
32
|
-
relatedKey?: string;
|
|
33
|
-
/** Lazy getter returning the pivot/junction model constructor. */
|
|
34
|
-
pivotModel?: () => any;
|
|
35
|
-
/** Column on the pivot table that points to the **related** model. */
|
|
36
|
-
pivotRelatedKey?: string;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=model.type.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"model.type.d.ts","sourceRoot":"","sources":["../../src/types/model.type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,QAAQ,GACR,MAAM,GACN,SAAS,GACT,QAAQ,GACR,SAAS,GACT,MAAM,GACN,MAAM,GACN,SAAS,GACT,MAAM,GACN,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,OAAO,CAAC;AAEZ,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,MAAM,OAAO,GAAG,YAAY,GAAG,OAAO,CAAC;AAE7C,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,GAAG,eAAe,CAAC;AAEhF,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,YAAY,CAAC;IACnB,wDAAwD;IACxD,KAAK,EAAE,MAAM,GAAG,CAAC;IACjB,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,GAAG,CAAC;IACvB,sEAAsE;IACtE,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B"}
|
package/dist/types/model.type.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"model.type.js","sourceRoot":"","sources":["../../src/types/model.type.ts"],"names":[],"mappings":""}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { Model, ModelConstructor } from '../core/model';
|
|
3
|
-
export declare class ValidationGenerator {
|
|
4
|
-
static generateZodSchema<T extends Model>(modelClass: ModelConstructor<T>): z.ZodType<Partial<T>>;
|
|
5
|
-
static generateStrictZodSchema<T extends Model>(modelClass: ModelConstructor<T>): z.ZodType<any>;
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AA4FxD,qBAAa,mBAAmB;IAC9B,MAAM,CAAC,iBAAiB,CAAC,CAAC,SAAS,KAAK,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAWjG,MAAM,CAAC,uBAAuB,CAAC,CAAC,SAAS,KAAK,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;CAUjG"}
|