@meghjs/core 0.5.0 → 0.5.2
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 +39 -29
- package/dist/common/helpers.d.ts +0 -1
- package/dist/common/helpers.js +0 -1
- package/dist/common/helpers.js.map +1 -1
- package/dist/config/config.js +1 -2
- package/dist/config/config.js.map +1 -1
- package/dist/core/application.d.ts +0 -6
- package/dist/core/application.js +2 -10
- package/dist/core/application.js.map +1 -1
- package/dist/core/router.js +2 -1
- package/dist/core/router.js.map +1 -1
- package/dist/di/container.d.ts +50 -6
- package/dist/di/container.js +183 -29
- package/dist/di/container.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/openapi/branding.d.ts +29 -0
- package/dist/openapi/branding.js +41 -0
- package/dist/openapi/branding.js.map +1 -0
- package/dist/openapi/openapi.d.ts +8 -0
- package/dist/openapi/openapi.js.map +1 -1
- package/dist/orm/casts.d.ts +6 -1
- package/dist/orm/casts.js +18 -7
- package/dist/orm/casts.js.map +1 -1
- package/dist/orm/config.d.ts +63 -0
- package/dist/orm/config.js +127 -0
- package/dist/orm/config.js.map +1 -0
- package/dist/orm/connect.d.ts +11 -0
- package/dist/orm/connect.js +147 -0
- package/dist/orm/connect.js.map +1 -0
- package/dist/orm/connection.d.ts +9 -5
- package/dist/orm/connection.js +41 -14
- package/dist/orm/connection.js.map +1 -1
- package/dist/orm/core.d.ts +43 -0
- package/dist/orm/core.js +23 -0
- package/dist/orm/core.js.map +1 -0
- package/dist/orm/db.d.ts +171 -0
- package/dist/orm/db.js +534 -0
- package/dist/orm/db.js.map +1 -0
- package/dist/orm/decorators.d.ts +143 -0
- package/dist/orm/decorators.js +243 -0
- package/dist/orm/decorators.js.map +1 -0
- package/dist/orm/engine.d.ts +8 -0
- package/dist/orm/engine.js +8 -0
- package/dist/orm/engine.js.map +1 -0
- package/dist/orm/has-relation.d.ts +31 -0
- package/dist/orm/has-relation.js +77 -0
- package/dist/orm/has-relation.js.map +1 -0
- package/dist/orm/index.d.ts +12 -4
- package/dist/orm/index.js +41 -1
- package/dist/orm/index.js.map +1 -1
- package/dist/orm/migrations.d.ts +27 -0
- package/dist/orm/migrations.js +40 -16
- package/dist/orm/migrations.js.map +1 -1
- package/dist/orm/model.d.ts +55 -6
- package/dist/orm/model.js +82 -16
- package/dist/orm/model.js.map +1 -1
- package/dist/orm/naming.d.ts +19 -0
- package/dist/orm/naming.js +96 -0
- package/dist/orm/naming.js.map +1 -0
- package/dist/orm/paging.d.ts +22 -0
- package/dist/orm/paging.js +32 -0
- package/dist/orm/paging.js.map +1 -0
- package/dist/orm/pivot.js +3 -2
- package/dist/orm/pivot.js.map +1 -1
- package/dist/orm/plugin.d.ts +2 -0
- package/dist/orm/plugin.js +50 -0
- package/dist/orm/plugin.js.map +1 -0
- package/dist/orm/query.d.ts +125 -10
- package/dist/orm/query.js +289 -47
- package/dist/orm/query.js.map +1 -1
- package/dist/orm/relations.d.ts +11 -2
- package/dist/orm/relations.js +14 -2
- package/dist/orm/relations.js.map +1 -1
- package/dist/orm/schema.d.ts +229 -0
- package/dist/orm/schema.js +645 -0
- package/dist/orm/schema.js.map +1 -0
- package/dist/orm/state.d.ts +4 -1
- package/dist/orm/state.js +29 -12
- package/dist/orm/state.js.map +1 -1
- package/dist/orm/types.d.ts +18 -5
- package/dist/plugins/builtin.d.ts +2 -0
- package/dist/plugins/builtin.js +12 -0
- package/dist/plugins/builtin.js.map +1 -0
- package/dist/plugins/registry.d.ts +5 -3
- package/dist/plugins/registry.js +14 -4
- package/dist/plugins/registry.js.map +1 -1
- package/package.json +6 -7
- package/dist/common/utils/di-utils.d.ts +0 -1
- package/dist/common/utils/di-utils.js +0 -20
- package/dist/common/utils/di-utils.js.map +0 -1
package/dist/orm/relations.js
CHANGED
|
@@ -22,15 +22,17 @@ exports.hasMany = hasMany;
|
|
|
22
22
|
exports.hasOne = hasOne;
|
|
23
23
|
exports.belongsTo = belongsTo;
|
|
24
24
|
exports.belongsToMany = belongsToMany;
|
|
25
|
+
exports.declareRelation = declareRelation;
|
|
25
26
|
exports.isRelationMarker = isRelationMarker;
|
|
26
27
|
exports.snakeCase = snakeCase;
|
|
27
28
|
exports.getRelations = getRelations;
|
|
28
29
|
exports.getRelation = getRelation;
|
|
30
|
+
const decorators_1 = require("./decorators");
|
|
29
31
|
/** Brand of a relation marker. */
|
|
30
32
|
exports.RELATION = Symbol("megh.orm.relation");
|
|
31
33
|
function marker(def) {
|
|
32
34
|
const kind = def.kind === "hasMany" || def.kind === "belongsToMany" ? "many" : "one";
|
|
33
|
-
const out = { [exports.RELATION]: { kind, def } };
|
|
35
|
+
const out = { [exports.RELATION]: { kind, type: def.kind, def } };
|
|
34
36
|
if (def.kind === "belongsToMany") {
|
|
35
37
|
out.withPivot = (...columns) => {
|
|
36
38
|
def.pivot.columns.push(...columns);
|
|
@@ -79,6 +81,10 @@ function belongsToMany(related, options = {}) {
|
|
|
79
81
|
pivot: { ...options, columns: [] },
|
|
80
82
|
});
|
|
81
83
|
}
|
|
84
|
+
/** A relation definition, as the relation decorators record it. */
|
|
85
|
+
function declareRelation(kind, related, options = {}) {
|
|
86
|
+
return { kind, related, ...options };
|
|
87
|
+
}
|
|
82
88
|
function isRelationMarker(value) {
|
|
83
89
|
return !!value && typeof value === "object" && exports.RELATION in value;
|
|
84
90
|
}
|
|
@@ -89,12 +95,18 @@ function snakeCase(name) {
|
|
|
89
95
|
.toLowerCase();
|
|
90
96
|
}
|
|
91
97
|
const cache = new WeakMap();
|
|
92
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* Relations of a model class: those declared with decorators, and those
|
|
100
|
+
* declared as field initializers, read once from a probe instance.
|
|
101
|
+
*/
|
|
93
102
|
function getRelations(cls) {
|
|
94
103
|
let defs = cache.get(cls);
|
|
95
104
|
if (defs)
|
|
96
105
|
return defs;
|
|
97
106
|
defs = new Map();
|
|
107
|
+
for (const [name, declared] of (0, decorators_1.getModelMetadata)(cls)?.relations ?? []) {
|
|
108
|
+
defs.set(name, resolve(cls, name, declared));
|
|
109
|
+
}
|
|
98
110
|
const probe = new cls();
|
|
99
111
|
for (const [name, value] of Object.entries(probe)) {
|
|
100
112
|
if (!isRelationMarker(value))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relations.js","sourceRoot":"","sources":["../../src/orm/relations.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;
|
|
1
|
+
{"version":3,"file":"relations.js","sourceRoot":"","sources":["../../src/orm/relations.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAuIH,0BAMC;AAGD,wBAMC;AASD,8BAMC;AAWD,sCASC;AAGD,0CAMC;AAED,4CAEC;AAED,8BAKC;AAQD,oCAkBC;AAsDD,kCAOC;AAlSD,6CAAgD;AAEhD,kCAAkC;AACrB,QAAA,QAAQ,GAAkB,MAAM,CAAC,mBAAmB,CAAC,CAAC;AA8GnE,SAAS,MAAM,CAAC,GAAqB;IACnC,MAAM,IAAI,GACR,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,GAAG,CAAC,IAAI,KAAK,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1E,MAAM,GAAG,GAAQ,EAAE,CAAC,gBAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;IAC/D,IAAI,GAAG,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;QACjC,GAAG,CAAC,SAAS,GAAG,CAAC,GAAG,OAAiB,EAAE,EAAE;YACvC,GAAG,CAAC,KAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;YACpC,OAAO,GAAG,CAAC;QACb,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;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IAAI,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK;QAC9D,QAAQ,EAAE,QAAQ,CAAC,QAAQ,IAAI,KAAK;KACrC,CAAC;AACJ,CAAC;AAED,SAAgB,WAAW,CACzB,GAA8C,EAC9C,IAAY;IAEZ,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,cAAc,GAAG,CAAC,IAAI,qBAAqB,IAAI,GAAG,CAAC,CAAC;IAC9E,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Megh's schema builder, for migrations:
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* export default defineMigration({
|
|
6
|
+
* async up(schema) {
|
|
7
|
+
* await schema.create("users", (table) => {
|
|
8
|
+
* table.id();
|
|
9
|
+
* table.string("email").unique();
|
|
10
|
+
* table.foreignId("team_id").constrained().cascadeOnDelete();
|
|
11
|
+
* table.timestamps();
|
|
12
|
+
* });
|
|
13
|
+
* },
|
|
14
|
+
* async down(schema) {
|
|
15
|
+
* await schema.drop("users");
|
|
16
|
+
* },
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Each column type maps to the right SQL type for the database, and
|
|
21
|
+
* statements a database can't run as written (foreign keys on MySQL, renames
|
|
22
|
+
* on SQL Server, unique columns added to SQLite tables) are issued the way
|
|
23
|
+
* that database needs.
|
|
24
|
+
*/
|
|
25
|
+
import type { Kysely } from "kysely";
|
|
26
|
+
import type { ColumnType } from "./decorators";
|
|
27
|
+
export type SchemaDialect = "postgres" | "mysql" | "sqlite" | "mssql";
|
|
28
|
+
export type ReferentialAction = "cascade" | "set null" | "restrict" | "no action" | "set default";
|
|
29
|
+
/** Which database `db` talks to, from its Kysely adapter. */
|
|
30
|
+
export declare function dialectOf(db: Kysely<any>): SchemaDialect;
|
|
31
|
+
export declare class SchemaError extends Error {
|
|
32
|
+
constructor(message: string);
|
|
33
|
+
}
|
|
34
|
+
type SchemaColumnType = ColumnType | "increments" | "bigIncrements";
|
|
35
|
+
interface ColumnState {
|
|
36
|
+
nullable: boolean;
|
|
37
|
+
unique: boolean;
|
|
38
|
+
primary: boolean;
|
|
39
|
+
autoIncrement: boolean;
|
|
40
|
+
default?: {
|
|
41
|
+
value: unknown;
|
|
42
|
+
} | {
|
|
43
|
+
current: true;
|
|
44
|
+
};
|
|
45
|
+
references?: {
|
|
46
|
+
table: string;
|
|
47
|
+
column: string;
|
|
48
|
+
};
|
|
49
|
+
onDelete?: ReferentialAction;
|
|
50
|
+
onUpdate?: ReferentialAction;
|
|
51
|
+
}
|
|
52
|
+
/** A column being added. Columns are NOT NULL unless marked `nullable()`. */
|
|
53
|
+
export declare class ColumnDefinition {
|
|
54
|
+
readonly name: string;
|
|
55
|
+
readonly type: SchemaColumnType;
|
|
56
|
+
/** @internal */
|
|
57
|
+
readonly params: {
|
|
58
|
+
length?: number;
|
|
59
|
+
precision?: number;
|
|
60
|
+
scale?: number;
|
|
61
|
+
};
|
|
62
|
+
/** @internal */
|
|
63
|
+
readonly state: ColumnState;
|
|
64
|
+
constructor(name: string, type: SchemaColumnType,
|
|
65
|
+
/** @internal */
|
|
66
|
+
params?: {
|
|
67
|
+
length?: number;
|
|
68
|
+
precision?: number;
|
|
69
|
+
scale?: number;
|
|
70
|
+
});
|
|
71
|
+
/** Allow NULL. */
|
|
72
|
+
nullable(value?: boolean): this;
|
|
73
|
+
unique(): this;
|
|
74
|
+
primary(): this;
|
|
75
|
+
/** The value the database fills in when an insert leaves the column out. */
|
|
76
|
+
default(value: unknown): this;
|
|
77
|
+
/** Default to the current time. */
|
|
78
|
+
useCurrent(): this;
|
|
79
|
+
/** A column the database numbers itself. */
|
|
80
|
+
autoIncrement(): this;
|
|
81
|
+
/**
|
|
82
|
+
* A foreign key to `"table.column"`, or to `"table"` (its `id`).
|
|
83
|
+
*/
|
|
84
|
+
references(target: string): this;
|
|
85
|
+
/**
|
|
86
|
+
* A foreign key to `table` (default: from the column name, `user_id` →
|
|
87
|
+
* `users`) and its `column` (default `id`).
|
|
88
|
+
*/
|
|
89
|
+
constrained(table?: string, column?: string): this;
|
|
90
|
+
onDelete(action: ReferentialAction): this;
|
|
91
|
+
onUpdate(action: ReferentialAction): this;
|
|
92
|
+
/** Delete this row when the referenced row is deleted. */
|
|
93
|
+
cascadeOnDelete(): this;
|
|
94
|
+
/** Set this column to NULL when the referenced row is deleted. */
|
|
95
|
+
nullOnDelete(): this;
|
|
96
|
+
}
|
|
97
|
+
/** A foreign key on existing columns: `table.foreign("user_id").references("users.id")`. */
|
|
98
|
+
export declare class ForeignKeyDefinition {
|
|
99
|
+
readonly columns: string[];
|
|
100
|
+
readonly name: string;
|
|
101
|
+
/** @internal */
|
|
102
|
+
target?: {
|
|
103
|
+
table: string;
|
|
104
|
+
column: string;
|
|
105
|
+
};
|
|
106
|
+
/** @internal */
|
|
107
|
+
deleteAction?: ReferentialAction;
|
|
108
|
+
/** @internal */
|
|
109
|
+
updateAction?: ReferentialAction;
|
|
110
|
+
constructor(columns: string[], name: string);
|
|
111
|
+
references(target: string): this;
|
|
112
|
+
onDelete(action: ReferentialAction): this;
|
|
113
|
+
onUpdate(action: ReferentialAction): this;
|
|
114
|
+
cascadeOnDelete(): this;
|
|
115
|
+
}
|
|
116
|
+
type Command = {
|
|
117
|
+
kind: "index";
|
|
118
|
+
columns: string[];
|
|
119
|
+
name: string;
|
|
120
|
+
unique: boolean;
|
|
121
|
+
} | {
|
|
122
|
+
kind: "primary";
|
|
123
|
+
columns: string[];
|
|
124
|
+
name: string;
|
|
125
|
+
} | {
|
|
126
|
+
kind: "foreign";
|
|
127
|
+
key: ForeignKeyDefinition;
|
|
128
|
+
} | {
|
|
129
|
+
kind: "dropColumn";
|
|
130
|
+
name: string;
|
|
131
|
+
} | {
|
|
132
|
+
kind: "renameColumn";
|
|
133
|
+
from: string;
|
|
134
|
+
to: string;
|
|
135
|
+
} | {
|
|
136
|
+
kind: "dropIndex";
|
|
137
|
+
name: string;
|
|
138
|
+
} | {
|
|
139
|
+
kind: "dropForeign";
|
|
140
|
+
name: string;
|
|
141
|
+
};
|
|
142
|
+
/** The columns and indexes of a table being created or changed. */
|
|
143
|
+
export declare class Blueprint {
|
|
144
|
+
readonly table: string;
|
|
145
|
+
/** @internal */
|
|
146
|
+
readonly columns: ColumnDefinition[];
|
|
147
|
+
/** @internal */
|
|
148
|
+
readonly commands: Command[];
|
|
149
|
+
constructor(table: string);
|
|
150
|
+
private add;
|
|
151
|
+
/** Auto-increment integer primary key, `id` by default. */
|
|
152
|
+
id(name?: string): ColumnDefinition;
|
|
153
|
+
/** Auto-increment integer primary key. */
|
|
154
|
+
increments(name: string): ColumnDefinition;
|
|
155
|
+
/** Auto-increment 64-bit primary key. PostgreSQL and MySQL drivers return it as a string. */
|
|
156
|
+
bigIncrements(name: string): ColumnDefinition;
|
|
157
|
+
/** `VARCHAR(length)`, 255 by default (`NVARCHAR` on SQL Server). */
|
|
158
|
+
string(name: string, length?: number): ColumnDefinition;
|
|
159
|
+
text(name: string): ColumnDefinition;
|
|
160
|
+
integer(name: string): ColumnDefinition;
|
|
161
|
+
bigInteger(name: string): ColumnDefinition;
|
|
162
|
+
float(name: string): ColumnDefinition;
|
|
163
|
+
double(name: string): ColumnDefinition;
|
|
164
|
+
/** Exact number with `precision` digits, `scale` after the point. */
|
|
165
|
+
decimal(name: string, precision?: number, scale?: number): ColumnDefinition;
|
|
166
|
+
boolean(name: string): ColumnDefinition;
|
|
167
|
+
date(name: string): ColumnDefinition;
|
|
168
|
+
/** Date and time without a time zone. */
|
|
169
|
+
datetime(name: string): ColumnDefinition;
|
|
170
|
+
/** Date and time with a time zone where the database has one (PostgreSQL, SQL Server). */
|
|
171
|
+
timestamp(name: string): ColumnDefinition;
|
|
172
|
+
time(name: string): ColumnDefinition;
|
|
173
|
+
/** JSON (`JSONB` on PostgreSQL, text on SQLite and SQL Server). */
|
|
174
|
+
json(name: string): ColumnDefinition;
|
|
175
|
+
uuid(name: string): ColumnDefinition;
|
|
176
|
+
binary(name: string): ColumnDefinition;
|
|
177
|
+
/** An integer column for a foreign key. Chain `.constrained()` to add the constraint. */
|
|
178
|
+
foreignId(name: string): ColumnDefinition;
|
|
179
|
+
/** Nullable `created_at` and `updated_at`, which `@CreatedAt` / `@UpdatedAt` fill in. */
|
|
180
|
+
timestamps(): void;
|
|
181
|
+
/** A nullable `deleted_at` for soft deletes (`@DeletedAt`). */
|
|
182
|
+
softDeletes(name?: string): ColumnDefinition;
|
|
183
|
+
index(columns: string | string[], name?: string): void;
|
|
184
|
+
unique(columns: string | string[], name?: string): void;
|
|
185
|
+
/** A primary key over several columns. */
|
|
186
|
+
primary(columns: string[], name?: string): void;
|
|
187
|
+
/** A foreign key on existing columns. */
|
|
188
|
+
foreign(columns: string | string[], name?: string): ForeignKeyDefinition;
|
|
189
|
+
dropColumn(...names: string[]): void;
|
|
190
|
+
renameColumn(from: string, to: string): void;
|
|
191
|
+
/** Drop an index by name, or by the columns it was created on. */
|
|
192
|
+
dropIndex(nameOrColumns: string | string[]): void;
|
|
193
|
+
/** Drop a unique index by name, or by its columns. */
|
|
194
|
+
dropUnique(nameOrColumns: string | string[]): void;
|
|
195
|
+
/** Drop a foreign key by name, or by its columns. */
|
|
196
|
+
dropForeign(nameOrColumns: string | string[]): void;
|
|
197
|
+
dropTimestamps(): void;
|
|
198
|
+
dropSoftDeletes(name?: string): void;
|
|
199
|
+
/** @internal `users_email_unique`, the name Megh gives indexes and keys. */
|
|
200
|
+
indexName(columns: string[], suffix: string): string;
|
|
201
|
+
}
|
|
202
|
+
/** Creates, changes and drops tables. Migrations defined with `defineMigration` receive one. */
|
|
203
|
+
export declare class Schema {
|
|
204
|
+
private readonly db;
|
|
205
|
+
readonly dialect: SchemaDialect;
|
|
206
|
+
constructor(db: Kysely<any>);
|
|
207
|
+
/** Create a table. */
|
|
208
|
+
create(table: string, define: (table: Blueprint) => void): Promise<void>;
|
|
209
|
+
/** Change a table: add columns, drop or rename them, add or drop indexes and keys. */
|
|
210
|
+
table(table: string, define: (table: Blueprint) => void): Promise<void>;
|
|
211
|
+
/** Drop a table. */
|
|
212
|
+
drop(table: string): Promise<void>;
|
|
213
|
+
/** Drop a table if it exists. */
|
|
214
|
+
dropIfExists(table: string): Promise<void>;
|
|
215
|
+
/** Rename a table. */
|
|
216
|
+
rename(from: string, to: string): Promise<void>;
|
|
217
|
+
/** Whether `table` exists. */
|
|
218
|
+
hasTable(table: string): Promise<boolean>;
|
|
219
|
+
/** Whether `table` has `column`. */
|
|
220
|
+
hasColumn(table: string, column: string): Promise<boolean>;
|
|
221
|
+
/** Run a SQL statement as written, for what the builder doesn't cover. */
|
|
222
|
+
raw(statement: string): Promise<void>;
|
|
223
|
+
private type;
|
|
224
|
+
private columnConstraints;
|
|
225
|
+
private actions;
|
|
226
|
+
private checkedKey;
|
|
227
|
+
private run;
|
|
228
|
+
}
|
|
229
|
+
export {};
|