@revojs/storage 0.1.58

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.
@@ -0,0 +1,3 @@
1
+ export type StorageConfig = Record<string, never>;
2
+ declare const _default: import("revojs/module").Module<"storage", StorageConfig, []>;
3
+ export default _default;
@@ -0,0 +1,19 @@
1
+ import { defineModule, useModule } from "revojs/module";
2
+ //#region src/module/index.ts
3
+ var module_default = defineModule({
4
+ name: "storage",
5
+ config: () => ({}),
6
+ setup() {
7
+ const { fromModule } = useModule(import.meta.url);
8
+ return { sources: {
9
+ storage: {
10
+ match: ["**/*.js", "**/*.ts"],
11
+ from: ["./storage"]
12
+ },
13
+ plugins: { from: [fromModule("../plugins")] },
14
+ commands: { from: [fromModule("../commands")] }
15
+ } };
16
+ }
17
+ });
18
+ //#endregion
19
+ export { module_default as default };
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ setup(scope: import("revojs").Scope): Promise<void>;
3
+ };
4
+ export default _default;
@@ -0,0 +1,15 @@
1
+ import { STORAGE_CONTEXT } from "../index.js";
2
+ import { definePlugin, getContext, setContext } from "revojs";
3
+ import storage from "#storage";
4
+ //#region src/plugins/index.ts
5
+ var plugins_default = definePlugin({ async setup(scope) {
6
+ const storages = getContext(scope, STORAGE_CONTEXT);
7
+ for (const [scopeName, files] of Object.entries(storage)) {
8
+ const databases = storages[scopeName] ?? {};
9
+ for (const [key, resolve] of Object.entries(files)) databases[key] = (await resolve())(scope);
10
+ storages[scopeName] = databases;
11
+ }
12
+ setContext(scope, STORAGE_CONTEXT, storages);
13
+ } });
14
+ //#endregion
15
+ export { plugins_default as default };
@@ -0,0 +1,175 @@
1
+ import { CheckConstraint, Column, Database, DeleteStatement, ForeignKeyConstraint, Index, InsertStatement, Migration, PrimaryKeyConstraint, SelectStatement, Table, UniqueConstraint, UniqueIndex, UpdateStatement, type Definition, type DeleteConstraintChange, type DeleteIndexChange, type Session, type Sql, type UpdateColumnChange } from "../index";
2
+ export interface CharOptions {
3
+ length?: number;
4
+ }
5
+ export interface DecimalOptions {
6
+ precision: number;
7
+ scale: number;
8
+ }
9
+ export interface VarcharOptions {
10
+ length?: number;
11
+ }
12
+ export declare abstract class MysqlColumn<TDataType = unknown> extends Column<TDataType> {
13
+ autoincrement<This extends MysqlColumn>(this: This): This & Record<"autoincrement", never>;
14
+ type<TData>(): this & Record<"$type", TData>;
15
+ }
16
+ export declare class BigintColumn extends MysqlColumn<bigint> {
17
+ toSqlType(): string;
18
+ }
19
+ export declare class BinaryColumn extends MysqlColumn<Uint8Array> {
20
+ toSqlType(): string;
21
+ }
22
+ export declare class BooleanColumn extends MysqlColumn<boolean> {
23
+ toSqlType(): string;
24
+ }
25
+ export declare class CharColumn extends MysqlColumn<string> {
26
+ protected $options: CharOptions | undefined;
27
+ constructor(name: string, options?: CharOptions);
28
+ toSqlType(): string;
29
+ }
30
+ export declare class DateColumn extends MysqlColumn<Date> {
31
+ toSqlType(): string;
32
+ }
33
+ export declare class DatetimeColumn extends MysqlColumn<Date> {
34
+ toSqlType(): string;
35
+ }
36
+ export declare class DecimalColumn extends MysqlColumn<string> {
37
+ protected $options: DecimalOptions | undefined;
38
+ constructor(name: string, options?: DecimalOptions);
39
+ toSqlType(): string;
40
+ }
41
+ export declare class DoubleColumn extends MysqlColumn<number> {
42
+ toSqlType(): string;
43
+ }
44
+ export declare class FloatColumn extends MysqlColumn<number> {
45
+ toSqlType(): string;
46
+ }
47
+ export declare class IntColumn extends MysqlColumn<number> {
48
+ toSqlType(): string;
49
+ }
50
+ export declare class JsonColumn extends MysqlColumn {
51
+ toSqlType(): string;
52
+ }
53
+ export declare class LongtextColumn extends MysqlColumn<string> {
54
+ toSqlType(): string;
55
+ }
56
+ export declare class MediumintColumn extends MysqlColumn<number> {
57
+ toSqlType(): string;
58
+ }
59
+ export declare class MediumtextColumn extends MysqlColumn<string> {
60
+ toSqlType(): string;
61
+ }
62
+ export declare class EnumerationColumn extends MysqlColumn<string> {
63
+ toSqlType(): string;
64
+ }
65
+ export declare class RealColumn extends MysqlColumn<number> {
66
+ toSqlType(): string;
67
+ }
68
+ export declare class SerialColumn extends MysqlColumn<number> {
69
+ toSqlType(): string;
70
+ }
71
+ export declare class SmallintColumn extends MysqlColumn<number> {
72
+ toSqlType(): string;
73
+ }
74
+ export declare class TextColumn extends MysqlColumn<string> {
75
+ toSqlType(): string;
76
+ }
77
+ export declare class TimeColumn extends MysqlColumn<string> {
78
+ toSqlType(): string;
79
+ }
80
+ export declare class TimestampColumn extends MysqlColumn<Date> {
81
+ toSqlType(): string;
82
+ }
83
+ export declare class TinyintColumn extends MysqlColumn<number> {
84
+ toSqlType(): string;
85
+ }
86
+ export declare class TinytextColumn extends MysqlColumn<string> {
87
+ toSqlType(): string;
88
+ }
89
+ export declare class VarbinaryColumn extends MysqlColumn<Uint8Array> {
90
+ toSqlType(): string;
91
+ }
92
+ export declare class VarcharColumn extends MysqlColumn<string> {
93
+ protected $options: VarcharOptions | undefined;
94
+ constructor(name: string, options?: VarcharOptions);
95
+ toSqlType(): string;
96
+ }
97
+ export declare class YearColumn extends MysqlColumn<number> {
98
+ toSqlType(): string;
99
+ }
100
+ export declare class MysqlUniqueConstraint extends UniqueConstraint {
101
+ }
102
+ export declare class MysqlCheckConstraint extends CheckConstraint {
103
+ }
104
+ export declare class MysqlPrimaryKeyConstraint extends PrimaryKeyConstraint {
105
+ }
106
+ export declare class MysqlForeignKeyConstraint extends ForeignKeyConstraint {
107
+ }
108
+ export declare class MysqlIndex extends Index {
109
+ algorithm<This>(this: This): This & Record<"algorithm", never>;
110
+ using<This>(this: This): This & Record<"using", never>;
111
+ lock<This>(this: This): This & Record<"lock", never>;
112
+ }
113
+ export declare class MysqlUniqueIndex extends UniqueIndex {
114
+ algorithm<This>(this: This): This & Record<"algorithm", never>;
115
+ using<This>(this: This): This & Record<"using", never>;
116
+ lock<This>(this: This): This & Record<"lock", never>;
117
+ }
118
+ export declare class MysqlSelectStatement<T extends Table | Record<string, Column>> extends SelectStatement<T> {
119
+ }
120
+ export declare class MysqlInsertStatement<T extends Table> extends InsertStatement<T> {
121
+ }
122
+ export declare class MysqlUpdateStatement<T extends Table> extends UpdateStatement<T> {
123
+ }
124
+ export declare class MysqlDeleteStatement<T extends Table> extends DeleteStatement<T> {
125
+ }
126
+ export declare class MysqlTable<TName extends string = string, TColumns extends Record<string, MysqlColumn> = Record<string, MysqlColumn>> extends Table<TName, TColumns> {
127
+ }
128
+ export declare class MysqlMigration extends Migration {
129
+ readonly $dialect = "mysql";
130
+ protected toUpdateColumnChange(change: UpdateColumnChange): Array<string>;
131
+ protected toDeleteConstraintChange(change: DeleteConstraintChange): Array<string>;
132
+ protected toDeleteIndexChange(change: DeleteIndexChange): Array<string>;
133
+ protected quoteIdentifier(value: string): string;
134
+ }
135
+ export declare class MysqlDatabase<T extends Record<string, MysqlTable>> extends Database<T> {
136
+ readonly $migration: MysqlMigration;
137
+ constructor(session: Session, schema: T);
138
+ select<T extends Table | Record<string, Column>>(value: T): MysqlSelectStatement<T>;
139
+ insert<T extends Table>(table: T): MysqlInsertStatement<T>;
140
+ update<T extends Table>(table: T): MysqlUpdateStatement<T>;
141
+ delete<T extends Table>(table: T): MysqlDeleteStatement<T>;
142
+ }
143
+ export declare function bigint(name: string): BigintColumn;
144
+ export declare function binary(name: string): BinaryColumn;
145
+ export declare function boolean(name: string): BooleanColumn;
146
+ export declare function char(name: string, options?: CharOptions): CharColumn;
147
+ export declare function date(name: string): DateColumn;
148
+ export declare function datetime(name: string): DatetimeColumn;
149
+ export declare function decimal(name: string, options?: DecimalOptions): DecimalColumn;
150
+ export declare function double(name: string): DoubleColumn;
151
+ export declare function float(name: string): FloatColumn;
152
+ export declare function int(name: string): IntColumn;
153
+ export declare function json(name: string): JsonColumn;
154
+ export declare function longtext(name: string): LongtextColumn;
155
+ export declare function mediumint(name: string): MediumintColumn;
156
+ export declare function mediumtext(name: string): MediumtextColumn;
157
+ export declare function enumeration(name: string): EnumerationColumn;
158
+ export declare function real(name: string): RealColumn;
159
+ export declare function serial(name: string): SerialColumn;
160
+ export declare function smallint(name: string): SmallintColumn;
161
+ export declare function text(name: string): TextColumn;
162
+ export declare function time(name: string): TimeColumn;
163
+ export declare function timestamp(name: string): TimestampColumn;
164
+ export declare function tinyint(name: string): TinyintColumn;
165
+ export declare function tinytext(name: string): TinytextColumn;
166
+ export declare function varbinary(name: string): VarbinaryColumn;
167
+ export declare function varchar(name: string, options?: VarcharOptions): VarcharColumn;
168
+ export declare function year(name: string): YearColumn;
169
+ export declare function unique(...columns: Array<Column>): MysqlUniqueConstraint;
170
+ export declare function check(value: Sql): MysqlCheckConstraint;
171
+ export declare function primaryKey(...columns: Array<Column>): MysqlPrimaryKeyConstraint;
172
+ export declare function foreignKey(columns: Array<Column>, foreignColumns: Array<Column>): MysqlForeignKeyConstraint;
173
+ export declare function index(...columns: Array<Column>): MysqlIndex;
174
+ export declare function uniqueIndex(...columns: Array<Column>): MysqlUniqueIndex;
175
+ export declare function table<TName extends string, TColumns extends Record<string, MysqlColumn>>(name: TName, columns: TColumns, definitions?: (columns: TColumns) => Array<Definition>): MysqlTable<TName, TColumns> & TColumns;
@@ -0,0 +1,327 @@
1
+ import { CheckConstraint, Column, Database, DeleteStatement, ForeignKeyConstraint, Index, InsertStatement, Migration, PrimaryKeyConstraint, SelectStatement, Table, UniqueConstraint, UniqueIndex, UpdateStatement } from "../index.js";
2
+ //#region src/protocols/mysql.ts
3
+ var MysqlColumn = class extends Column {
4
+ autoincrement() {
5
+ return this;
6
+ }
7
+ type() {
8
+ return this;
9
+ }
10
+ };
11
+ var BigintColumn = class extends MysqlColumn {
12
+ toSqlType() {
13
+ return "bigint";
14
+ }
15
+ };
16
+ var BinaryColumn = class extends MysqlColumn {
17
+ toSqlType() {
18
+ return "binary";
19
+ }
20
+ };
21
+ var BooleanColumn = class extends MysqlColumn {
22
+ toSqlType() {
23
+ return "boolean";
24
+ }
25
+ };
26
+ var CharColumn = class extends MysqlColumn {
27
+ $options;
28
+ constructor(name, options) {
29
+ super(name);
30
+ this.$options = options;
31
+ }
32
+ toSqlType() {
33
+ return this.$options?.length === void 0 ? "char" : `char(${this.$options.length})`;
34
+ }
35
+ };
36
+ var DateColumn = class extends MysqlColumn {
37
+ toSqlType() {
38
+ return "date";
39
+ }
40
+ };
41
+ var DatetimeColumn = class extends MysqlColumn {
42
+ toSqlType() {
43
+ return "datetime";
44
+ }
45
+ };
46
+ var DecimalColumn = class extends MysqlColumn {
47
+ $options;
48
+ constructor(name, options) {
49
+ super(name);
50
+ this.$options = options;
51
+ }
52
+ toSqlType() {
53
+ return this.$options === void 0 ? "decimal" : `decimal(${this.$options.precision}, ${this.$options.scale})`;
54
+ }
55
+ };
56
+ var DoubleColumn = class extends MysqlColumn {
57
+ toSqlType() {
58
+ return "double";
59
+ }
60
+ };
61
+ var FloatColumn = class extends MysqlColumn {
62
+ toSqlType() {
63
+ return "float";
64
+ }
65
+ };
66
+ var IntColumn = class extends MysqlColumn {
67
+ toSqlType() {
68
+ return "int";
69
+ }
70
+ };
71
+ var JsonColumn = class extends MysqlColumn {
72
+ toSqlType() {
73
+ return "json";
74
+ }
75
+ };
76
+ var LongtextColumn = class extends MysqlColumn {
77
+ toSqlType() {
78
+ return "longtext";
79
+ }
80
+ };
81
+ var MediumintColumn = class extends MysqlColumn {
82
+ toSqlType() {
83
+ return "mediumint";
84
+ }
85
+ };
86
+ var MediumtextColumn = class extends MysqlColumn {
87
+ toSqlType() {
88
+ return "mediumtext";
89
+ }
90
+ };
91
+ var EnumerationColumn = class extends MysqlColumn {
92
+ toSqlType() {
93
+ return "enum";
94
+ }
95
+ };
96
+ var RealColumn = class extends MysqlColumn {
97
+ toSqlType() {
98
+ return "real";
99
+ }
100
+ };
101
+ var SerialColumn = class extends MysqlColumn {
102
+ toSqlType() {
103
+ return "serial";
104
+ }
105
+ };
106
+ var SmallintColumn = class extends MysqlColumn {
107
+ toSqlType() {
108
+ return "smallint";
109
+ }
110
+ };
111
+ var TextColumn = class extends MysqlColumn {
112
+ toSqlType() {
113
+ return "text";
114
+ }
115
+ };
116
+ var TimeColumn = class extends MysqlColumn {
117
+ toSqlType() {
118
+ return "time";
119
+ }
120
+ };
121
+ var TimestampColumn = class extends MysqlColumn {
122
+ toSqlType() {
123
+ return "timestamp";
124
+ }
125
+ };
126
+ var TinyintColumn = class extends MysqlColumn {
127
+ toSqlType() {
128
+ return "tinyint";
129
+ }
130
+ };
131
+ var TinytextColumn = class extends MysqlColumn {
132
+ toSqlType() {
133
+ return "tinytext";
134
+ }
135
+ };
136
+ var VarbinaryColumn = class extends MysqlColumn {
137
+ toSqlType() {
138
+ return "varbinary";
139
+ }
140
+ };
141
+ var VarcharColumn = class extends MysqlColumn {
142
+ $options;
143
+ constructor(name, options) {
144
+ super(name);
145
+ this.$options = options;
146
+ }
147
+ toSqlType() {
148
+ return this.$options?.length === void 0 ? "varchar" : `varchar(${this.$options.length})`;
149
+ }
150
+ };
151
+ var YearColumn = class extends MysqlColumn {
152
+ toSqlType() {
153
+ return "year";
154
+ }
155
+ };
156
+ var MysqlUniqueConstraint = class extends UniqueConstraint {};
157
+ var MysqlCheckConstraint = class extends CheckConstraint {};
158
+ var MysqlPrimaryKeyConstraint = class extends PrimaryKeyConstraint {};
159
+ var MysqlForeignKeyConstraint = class extends ForeignKeyConstraint {};
160
+ var MysqlIndex = class extends Index {
161
+ algorithm() {
162
+ return this;
163
+ }
164
+ using() {
165
+ return this;
166
+ }
167
+ lock() {
168
+ return this;
169
+ }
170
+ };
171
+ var MysqlUniqueIndex = class extends UniqueIndex {
172
+ algorithm() {
173
+ return this;
174
+ }
175
+ using() {
176
+ return this;
177
+ }
178
+ lock() {
179
+ return this;
180
+ }
181
+ };
182
+ var MysqlSelectStatement = class extends SelectStatement {};
183
+ var MysqlInsertStatement = class extends InsertStatement {};
184
+ var MysqlUpdateStatement = class extends UpdateStatement {};
185
+ var MysqlDeleteStatement = class extends DeleteStatement {};
186
+ var MysqlTable = class extends Table {};
187
+ var MysqlMigration = class extends Migration {
188
+ $dialect = "mysql";
189
+ toUpdateColumnChange(change) {
190
+ return [...change.before.type !== change.after.type || change.before.notNull !== change.after.notNull ? [this.alterTable(change.table, `MODIFY COLUMN ${this.toCreateColumnChange({
191
+ kind: "createColumn",
192
+ table: change.table,
193
+ column: change.after
194
+ }, true)[0]}`)] : [], ...this.updateColumnConstraints(change.table, change.before, change.after)];
195
+ }
196
+ toDeleteConstraintChange(change) {
197
+ if (change.constraint.kind === "primaryKey") return [this.alterTable(change.table, "DROP PRIMARY KEY")];
198
+ if (change.constraint.kind === "unique") return [this.alterTable(change.table, `DROP INDEX ${this.quoteIdentifier(this.constraintName(change.table, change.constraint))}`)];
199
+ return [this.alterTable(change.table, `DROP ${change.constraint.kind === "foreignKey" ? "FOREIGN KEY" : "CHECK"} ${this.quoteIdentifier(this.constraintName(change.table, change.constraint))}`)];
200
+ }
201
+ toDeleteIndexChange(change) {
202
+ return [`DROP INDEX ${this.quoteIdentifier(this.indexName(change.table, change.index))} ON ${this.quoteIdentifier(change.table)};`];
203
+ }
204
+ quoteIdentifier(value) {
205
+ return `\`${value.replaceAll("`", "``")}\``;
206
+ }
207
+ };
208
+ var MysqlDatabase = class extends Database {
209
+ $migration;
210
+ constructor(session, schema) {
211
+ super(session, schema);
212
+ this.$migration = new MysqlMigration();
213
+ }
214
+ select(value) {
215
+ return new MysqlSelectStatement(this.$session, value);
216
+ }
217
+ insert(table) {
218
+ return new MysqlInsertStatement(this.$session, table);
219
+ }
220
+ update(table) {
221
+ return new MysqlUpdateStatement(this.$session, table);
222
+ }
223
+ delete(table) {
224
+ return new MysqlDeleteStatement(this.$session, table);
225
+ }
226
+ };
227
+ function bigint(name) {
228
+ return new BigintColumn(name);
229
+ }
230
+ function binary(name) {
231
+ return new BinaryColumn(name);
232
+ }
233
+ function boolean(name) {
234
+ return new BooleanColumn(name);
235
+ }
236
+ function char(name, options) {
237
+ return new CharColumn(name, options);
238
+ }
239
+ function date(name) {
240
+ return new DateColumn(name);
241
+ }
242
+ function datetime(name) {
243
+ return new DatetimeColumn(name);
244
+ }
245
+ function decimal(name, options) {
246
+ return new DecimalColumn(name, options);
247
+ }
248
+ function double(name) {
249
+ return new DoubleColumn(name);
250
+ }
251
+ function float(name) {
252
+ return new FloatColumn(name);
253
+ }
254
+ function int(name) {
255
+ return new IntColumn(name);
256
+ }
257
+ function json(name) {
258
+ return new JsonColumn(name);
259
+ }
260
+ function longtext(name) {
261
+ return new LongtextColumn(name);
262
+ }
263
+ function mediumint(name) {
264
+ return new MediumintColumn(name);
265
+ }
266
+ function mediumtext(name) {
267
+ return new MediumtextColumn(name);
268
+ }
269
+ function enumeration(name) {
270
+ return new EnumerationColumn(name);
271
+ }
272
+ function real(name) {
273
+ return new RealColumn(name);
274
+ }
275
+ function serial(name) {
276
+ return new SerialColumn(name);
277
+ }
278
+ function smallint(name) {
279
+ return new SmallintColumn(name);
280
+ }
281
+ function text(name) {
282
+ return new TextColumn(name);
283
+ }
284
+ function time(name) {
285
+ return new TimeColumn(name);
286
+ }
287
+ function timestamp(name) {
288
+ return new TimestampColumn(name);
289
+ }
290
+ function tinyint(name) {
291
+ return new TinyintColumn(name);
292
+ }
293
+ function tinytext(name) {
294
+ return new TinytextColumn(name);
295
+ }
296
+ function varbinary(name) {
297
+ return new VarbinaryColumn(name);
298
+ }
299
+ function varchar(name, options) {
300
+ return new VarcharColumn(name, options);
301
+ }
302
+ function year(name) {
303
+ return new YearColumn(name);
304
+ }
305
+ function unique(...columns) {
306
+ return new MysqlUniqueConstraint(...columns);
307
+ }
308
+ function check(value) {
309
+ return new MysqlCheckConstraint(value);
310
+ }
311
+ function primaryKey(...columns) {
312
+ return new MysqlPrimaryKeyConstraint(...columns);
313
+ }
314
+ function foreignKey(columns, foreignColumns) {
315
+ return new MysqlForeignKeyConstraint(columns, foreignColumns);
316
+ }
317
+ function index(...columns) {
318
+ return new MysqlIndex(...columns);
319
+ }
320
+ function uniqueIndex(...columns) {
321
+ return new MysqlUniqueIndex(...columns);
322
+ }
323
+ function table(name, columns, definitions) {
324
+ return Object.assign(new MysqlTable(name, columns, definitions?.(columns) ?? []), columns);
325
+ }
326
+ //#endregion
327
+ export { BigintColumn, BinaryColumn, BooleanColumn, CharColumn, DateColumn, DatetimeColumn, DecimalColumn, DoubleColumn, EnumerationColumn, FloatColumn, IntColumn, JsonColumn, LongtextColumn, MediumintColumn, MediumtextColumn, MysqlCheckConstraint, MysqlColumn, MysqlDatabase, MysqlDeleteStatement, MysqlForeignKeyConstraint, MysqlIndex, MysqlInsertStatement, MysqlMigration, MysqlPrimaryKeyConstraint, MysqlSelectStatement, MysqlTable, MysqlUniqueConstraint, MysqlUniqueIndex, MysqlUpdateStatement, RealColumn, SerialColumn, SmallintColumn, TextColumn, TimeColumn, TimestampColumn, TinyintColumn, TinytextColumn, VarbinaryColumn, VarcharColumn, YearColumn, bigint, binary, boolean, char, check, date, datetime, decimal, double, enumeration, float, foreignKey, index, int, json, longtext, mediumint, mediumtext, primaryKey, real, serial, smallint, table, text, time, timestamp, tinyint, tinytext, unique, uniqueIndex, varbinary, varchar, year };