arcanajs 3.0.0 → 4.0.0
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/arcanajs.client.js +2 -0
- package/dist/arcanajs.client.js.map +1 -0
- package/dist/arcanajs.js +2 -1
- package/dist/arcanajs.js.LICENSE.txt +14 -0
- package/dist/arcanajs.js.map +1 -1
- package/dist/arcanox.js +2 -0
- package/dist/arcanox.js.map +1 -0
- package/dist/cli/commands/db.d.ts +1 -0
- package/dist/cli/commands/make.d.ts +1 -0
- package/dist/cli/commands/migrate.d.ts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/lib/arcanox/Model.d.ts +203 -0
- package/dist/lib/arcanox/QueryBuilder.d.ts +141 -0
- package/dist/lib/arcanox/adapters/MongoAdapter.d.ts +22 -0
- package/dist/lib/arcanox/adapters/MySQLAdapter.d.ts +27 -0
- package/dist/lib/arcanox/adapters/PostgresAdapter.d.ts +27 -0
- package/dist/lib/arcanox/extensions/MongoExtensions.d.ts +33 -0
- package/dist/lib/arcanox/factory/Factory.d.ts +26 -0
- package/dist/lib/arcanox/factory/index.d.ts +1 -0
- package/dist/lib/arcanox/index.d.ts +13 -0
- package/dist/lib/arcanox/providers/DatabaseProvider.d.ts +5 -0
- package/dist/lib/arcanox/relations/BelongsTo.d.ts +11 -0
- package/dist/lib/arcanox/relations/BelongsToMany.d.ts +15 -0
- package/dist/lib/arcanox/relations/HasMany.d.ts +11 -0
- package/dist/lib/arcanox/relations/HasOne.d.ts +11 -0
- package/dist/lib/arcanox/relations/Relation.d.ts +14 -0
- package/dist/lib/arcanox/schema/Blueprint.d.ts +183 -0
- package/dist/lib/arcanox/schema/Migration.d.ts +76 -0
- package/dist/lib/arcanox/schema/Schema.d.ts +49 -0
- package/dist/lib/arcanox/schema/index.d.ts +4 -0
- package/dist/lib/arcanox/seeder/Seeder.d.ts +13 -0
- package/dist/lib/arcanox/seeder/index.d.ts +1 -0
- package/dist/lib/arcanox/support/Macroable.d.ts +19 -0
- package/dist/lib/arcanox/types.d.ts +76 -0
- package/dist/lib/index.arcanox.d.ts +6 -0
- package/dist/lib/index.client.d.ts +11 -0
- package/dist/lib/{index.d.ts → index.server.d.ts} +7 -11
- package/dist/lib/server/ArcanaJSServer.d.ts +35 -9
- package/dist/lib/server/Container.d.ts +31 -0
- package/dist/lib/server/MiddlewareBinder.d.ts +4 -0
- package/dist/lib/server/ResponseHandlerMiddleware.d.ts +0 -25
- package/dist/lib/server/Router.d.ts +12 -3
- package/dist/lib/server/http/FormRequest.d.ts +10 -0
- package/dist/lib/server/http/JsonResource.d.ts +13 -0
- package/dist/lib/server/http/Middleware.d.ts +4 -0
- package/dist/lib/server/support/ServiceProvider.d.ts +13 -0
- package/dist/lib/server/utils/dynamicRequire.d.ts +6 -0
- package/dist/lib/server/validation/ValidationException.d.ts +5 -0
- package/dist/lib/server/validation/Validator.d.ts +12 -0
- package/package.json +32 -7
- package/dist/lib/global.d.ts +0 -61
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type { ColumnDefinition } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Column definition builder - fluent interface for defining columns
|
|
4
|
+
*/
|
|
5
|
+
export declare class ColumnBuilder {
|
|
6
|
+
private definition;
|
|
7
|
+
constructor(name: string, type: string, length?: number);
|
|
8
|
+
/**
|
|
9
|
+
* Make column nullable
|
|
10
|
+
*/
|
|
11
|
+
nullable(): this;
|
|
12
|
+
/**
|
|
13
|
+
* Set default value
|
|
14
|
+
*/
|
|
15
|
+
default(value: any): this;
|
|
16
|
+
/**
|
|
17
|
+
* Make column unique
|
|
18
|
+
*/
|
|
19
|
+
unique(): this;
|
|
20
|
+
/**
|
|
21
|
+
* Make column primary key
|
|
22
|
+
*/
|
|
23
|
+
primary(): this;
|
|
24
|
+
/**
|
|
25
|
+
* Make column auto-increment
|
|
26
|
+
*/
|
|
27
|
+
autoIncrement(): this;
|
|
28
|
+
/**
|
|
29
|
+
* Make column unsigned (for numbers)
|
|
30
|
+
*/
|
|
31
|
+
unsigned(): this;
|
|
32
|
+
/**
|
|
33
|
+
* Get the column definition
|
|
34
|
+
*/
|
|
35
|
+
getDefinition(): ColumnDefinition;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Foreign key definition builder
|
|
39
|
+
*/
|
|
40
|
+
export declare class ForeignKeyBuilder {
|
|
41
|
+
private column;
|
|
42
|
+
private referencedTable?;
|
|
43
|
+
private referencedColumn?;
|
|
44
|
+
private onDeleteAction?;
|
|
45
|
+
private onUpdateAction?;
|
|
46
|
+
constructor(column: string);
|
|
47
|
+
/**
|
|
48
|
+
* Set referenced table and column
|
|
49
|
+
*/
|
|
50
|
+
references(column: string): this;
|
|
51
|
+
/**
|
|
52
|
+
* Set referenced table
|
|
53
|
+
*/
|
|
54
|
+
on(table: string): this;
|
|
55
|
+
/**
|
|
56
|
+
* Set ON DELETE action
|
|
57
|
+
*/
|
|
58
|
+
onDelete(action: "CASCADE" | "SET NULL" | "RESTRICT" | "NO ACTION"): this;
|
|
59
|
+
/**
|
|
60
|
+
* Set ON UPDATE action
|
|
61
|
+
*/
|
|
62
|
+
onUpdate(action: "CASCADE" | "SET NULL" | "RESTRICT" | "NO ACTION"): this;
|
|
63
|
+
/**
|
|
64
|
+
* Get foreign key SQL
|
|
65
|
+
*/
|
|
66
|
+
toSQL(): string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Blueprint - defines table structure
|
|
70
|
+
* Arcanox's Schema Blueprint
|
|
71
|
+
*/
|
|
72
|
+
export declare class Blueprint {
|
|
73
|
+
private tableName;
|
|
74
|
+
private columns;
|
|
75
|
+
private indexes;
|
|
76
|
+
private foreignKeys;
|
|
77
|
+
private primaryKeys;
|
|
78
|
+
constructor(tableName: string);
|
|
79
|
+
/**
|
|
80
|
+
* Add auto-incrementing ID column
|
|
81
|
+
*/
|
|
82
|
+
id(name?: string): ColumnBuilder;
|
|
83
|
+
/**
|
|
84
|
+
* Add UUID column
|
|
85
|
+
*/
|
|
86
|
+
uuid(name?: string): ColumnBuilder;
|
|
87
|
+
/**
|
|
88
|
+
* Add string column
|
|
89
|
+
*/
|
|
90
|
+
string(name: string, length?: number): ColumnBuilder;
|
|
91
|
+
/**
|
|
92
|
+
* Add text column
|
|
93
|
+
*/
|
|
94
|
+
text(name: string): ColumnBuilder;
|
|
95
|
+
/**
|
|
96
|
+
* Add integer column
|
|
97
|
+
*/
|
|
98
|
+
integer(name: string): ColumnBuilder;
|
|
99
|
+
/**
|
|
100
|
+
* Add big integer column
|
|
101
|
+
*/
|
|
102
|
+
bigInteger(name: string): ColumnBuilder;
|
|
103
|
+
/**
|
|
104
|
+
* Add decimal column
|
|
105
|
+
*/
|
|
106
|
+
decimal(name: string, precision?: number, scale?: number): ColumnBuilder;
|
|
107
|
+
/**
|
|
108
|
+
* Add float column
|
|
109
|
+
*/
|
|
110
|
+
float(name: string): ColumnBuilder;
|
|
111
|
+
/**
|
|
112
|
+
* Add double column
|
|
113
|
+
*/
|
|
114
|
+
double(name: string): ColumnBuilder;
|
|
115
|
+
/**
|
|
116
|
+
* Add boolean column
|
|
117
|
+
*/
|
|
118
|
+
boolean(name: string): ColumnBuilder;
|
|
119
|
+
/**
|
|
120
|
+
* Add date column
|
|
121
|
+
*/
|
|
122
|
+
date(name: string): ColumnBuilder;
|
|
123
|
+
/**
|
|
124
|
+
* Add datetime column
|
|
125
|
+
*/
|
|
126
|
+
datetime(name: string): ColumnBuilder;
|
|
127
|
+
/**
|
|
128
|
+
* Add timestamp column
|
|
129
|
+
*/
|
|
130
|
+
timestamp(name: string): ColumnBuilder;
|
|
131
|
+
/**
|
|
132
|
+
* Add created_at and updated_at timestamps
|
|
133
|
+
*/
|
|
134
|
+
timestamps(): void;
|
|
135
|
+
/**
|
|
136
|
+
* Add deleted_at timestamp for soft deletes
|
|
137
|
+
*/
|
|
138
|
+
softDeletes(name?: string): ColumnBuilder;
|
|
139
|
+
/**
|
|
140
|
+
* Add JSON column
|
|
141
|
+
*/
|
|
142
|
+
json(name: string): ColumnBuilder;
|
|
143
|
+
/**
|
|
144
|
+
* Add enum column
|
|
145
|
+
*/
|
|
146
|
+
enum(name: string, values: string[]): ColumnBuilder;
|
|
147
|
+
/**
|
|
148
|
+
* Add foreign key constraint
|
|
149
|
+
*/
|
|
150
|
+
foreign(column: string): ForeignKeyBuilder;
|
|
151
|
+
/**
|
|
152
|
+
* Add index
|
|
153
|
+
*/
|
|
154
|
+
index(columns: string | string[], name?: string): void;
|
|
155
|
+
/**
|
|
156
|
+
* Add unique index
|
|
157
|
+
*/
|
|
158
|
+
unique(columns: string | string[], name?: string): void;
|
|
159
|
+
/**
|
|
160
|
+
* Set primary key
|
|
161
|
+
*/
|
|
162
|
+
primary(columns: string | string[]): void;
|
|
163
|
+
/**
|
|
164
|
+
* Get all columns
|
|
165
|
+
*/
|
|
166
|
+
getColumns(): ColumnDefinition[];
|
|
167
|
+
/**
|
|
168
|
+
* Get table name
|
|
169
|
+
*/
|
|
170
|
+
getTableName(): string;
|
|
171
|
+
/**
|
|
172
|
+
* Get indexes
|
|
173
|
+
*/
|
|
174
|
+
getIndexes(): {
|
|
175
|
+
columns: string[];
|
|
176
|
+
unique: boolean;
|
|
177
|
+
name?: string;
|
|
178
|
+
}[];
|
|
179
|
+
/**
|
|
180
|
+
* Get foreign keys
|
|
181
|
+
*/
|
|
182
|
+
getForeignKeys(): ForeignKeyBuilder[];
|
|
183
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Migration class
|
|
3
|
+
* All migrations should extend this class and implement up() and down() methods
|
|
4
|
+
*/
|
|
5
|
+
export declare abstract class Migration {
|
|
6
|
+
/**
|
|
7
|
+
* Run the migration
|
|
8
|
+
*/
|
|
9
|
+
abstract up(): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Reverse the migration
|
|
12
|
+
*/
|
|
13
|
+
abstract down(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Migration status
|
|
17
|
+
*/
|
|
18
|
+
export interface MigrationStatus {
|
|
19
|
+
name: string;
|
|
20
|
+
batch: number;
|
|
21
|
+
ranAt: Date;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Migration record in database
|
|
25
|
+
*/
|
|
26
|
+
export interface MigrationRecord {
|
|
27
|
+
id?: number;
|
|
28
|
+
migration: string;
|
|
29
|
+
batch: number;
|
|
30
|
+
created_at?: Date;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Migration Runner - executes migrations
|
|
34
|
+
*/
|
|
35
|
+
export declare class MigrationRunner {
|
|
36
|
+
private adapter;
|
|
37
|
+
private migrationsTable;
|
|
38
|
+
private migrationsPath;
|
|
39
|
+
constructor(adapter: any, migrationsPath: string);
|
|
40
|
+
/**
|
|
41
|
+
* Ensure migrations table exists
|
|
42
|
+
*/
|
|
43
|
+
private ensureMigrationsTable;
|
|
44
|
+
/**
|
|
45
|
+
* Get all ran migrations
|
|
46
|
+
*/
|
|
47
|
+
private getRanMigrations;
|
|
48
|
+
/**
|
|
49
|
+
* Get pending migrations
|
|
50
|
+
*/
|
|
51
|
+
private getPendingMigrations;
|
|
52
|
+
/**
|
|
53
|
+
* Run pending migrations
|
|
54
|
+
*/
|
|
55
|
+
run(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Rollback last batch of migrations
|
|
58
|
+
*/
|
|
59
|
+
rollback(steps?: number): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Reset all migrations
|
|
62
|
+
*/
|
|
63
|
+
reset(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Reset and re-run all migrations
|
|
66
|
+
*/
|
|
67
|
+
fresh(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Get migration status
|
|
70
|
+
*/
|
|
71
|
+
status(): Promise<MigrationStatus[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Load migration class from file
|
|
74
|
+
*/
|
|
75
|
+
private loadMigration;
|
|
76
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { DatabaseAdapter } from "../types";
|
|
2
|
+
import { Blueprint } from "./Blueprint";
|
|
3
|
+
/**
|
|
4
|
+
* Schema - ArcnanJS schema builder
|
|
5
|
+
* Provides fluent interface for creating and modifying database tables
|
|
6
|
+
*/
|
|
7
|
+
export declare class Schema {
|
|
8
|
+
private static adapter;
|
|
9
|
+
/**
|
|
10
|
+
* Set the database adapter
|
|
11
|
+
*/
|
|
12
|
+
static setAdapter(adapter: DatabaseAdapter): void;
|
|
13
|
+
/**
|
|
14
|
+
* Create a new table
|
|
15
|
+
*/
|
|
16
|
+
static create(tableName: string, callback: (table: Blueprint) => void): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Modify an existing table
|
|
19
|
+
*/
|
|
20
|
+
static table(tableName: string, callback: (table: Blueprint) => void): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Drop a table
|
|
23
|
+
*/
|
|
24
|
+
static drop(tableName: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Drop a table if it exists
|
|
27
|
+
*/
|
|
28
|
+
static dropIfExists(tableName: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Rename a table
|
|
31
|
+
*/
|
|
32
|
+
static rename(from: string, to: string): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Check if a table exists
|
|
35
|
+
*/
|
|
36
|
+
static hasTable(tableName: string): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Check if a column exists in a table
|
|
39
|
+
*/
|
|
40
|
+
static hasColumn(tableName: string, columnName: string): Promise<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* Get all tables
|
|
43
|
+
*/
|
|
44
|
+
static getTables(): Promise<string[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Get all columns for a table
|
|
47
|
+
*/
|
|
48
|
+
static getColumns(tableName: string): Promise<string[]>;
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Seeder } from "./Seeder";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Macroable trait
|
|
3
|
+
* Allows adding custom methods to a class at runtime
|
|
4
|
+
*/
|
|
5
|
+
export declare class Macroable {
|
|
6
|
+
protected static macros: Record<string, Function>;
|
|
7
|
+
/**
|
|
8
|
+
* Register a custom macro
|
|
9
|
+
*/
|
|
10
|
+
static macro(name: string, macro: Function): void;
|
|
11
|
+
/**
|
|
12
|
+
* Mix another object into the class
|
|
13
|
+
*/
|
|
14
|
+
static mixin(mixin: Record<string, Function>): void;
|
|
15
|
+
/**
|
|
16
|
+
* Check if macro exists
|
|
17
|
+
*/
|
|
18
|
+
static hasMacro(name: string): boolean;
|
|
19
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database connection interface
|
|
3
|
+
*/
|
|
4
|
+
export interface Connection {
|
|
5
|
+
query(sql: string, params?: any[]): Promise<any>;
|
|
6
|
+
execute(sql: string, params?: any[]): Promise<any>;
|
|
7
|
+
close(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Database adapter interface - implements database-specific operations
|
|
11
|
+
*/
|
|
12
|
+
export interface DatabaseAdapter {
|
|
13
|
+
connect(config: DatabaseConfig): Promise<Connection>;
|
|
14
|
+
disconnect(): Promise<void>;
|
|
15
|
+
createTable(tableName: string, columns: ColumnDefinition[]): Promise<void>;
|
|
16
|
+
dropTable(tableName: string): Promise<void>;
|
|
17
|
+
hasTable(tableName: string): Promise<boolean>;
|
|
18
|
+
hasColumn(tableName: string, columnName: string): Promise<boolean>;
|
|
19
|
+
select(table: string, options: SelectOptions): Promise<any[]>;
|
|
20
|
+
insert(table: string, data: Record<string, any>): Promise<any>;
|
|
21
|
+
update(table: string, id: any, data: Record<string, any>): Promise<any>;
|
|
22
|
+
delete(table: string, id: any): Promise<boolean>;
|
|
23
|
+
beginTransaction(): Promise<void>;
|
|
24
|
+
commit(): Promise<void>;
|
|
25
|
+
rollback(): Promise<void>;
|
|
26
|
+
raw(query: string, params?: any[]): Promise<any>;
|
|
27
|
+
}
|
|
28
|
+
export interface DatabaseConfig {
|
|
29
|
+
type: "postgres" | "mysql" | "mongodb";
|
|
30
|
+
host: string;
|
|
31
|
+
port: number;
|
|
32
|
+
database: string;
|
|
33
|
+
username?: string;
|
|
34
|
+
password?: string;
|
|
35
|
+
ssl?: boolean;
|
|
36
|
+
pool?: {
|
|
37
|
+
min?: number;
|
|
38
|
+
max?: number;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export interface ColumnDefinition {
|
|
42
|
+
name: string;
|
|
43
|
+
type: string;
|
|
44
|
+
length?: number;
|
|
45
|
+
nullable?: boolean;
|
|
46
|
+
default?: any;
|
|
47
|
+
unique?: boolean;
|
|
48
|
+
primary?: boolean;
|
|
49
|
+
autoIncrement?: boolean;
|
|
50
|
+
unsigned?: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface SelectOptions {
|
|
53
|
+
columns?: string[];
|
|
54
|
+
where?: WhereClause[];
|
|
55
|
+
orderBy?: OrderByClause[];
|
|
56
|
+
limit?: number;
|
|
57
|
+
offset?: number;
|
|
58
|
+
joins?: JoinClause[];
|
|
59
|
+
}
|
|
60
|
+
export interface WhereClause {
|
|
61
|
+
column: string;
|
|
62
|
+
operator: "=" | "!=" | ">" | "<" | ">=" | "<=" | "LIKE" | "IN" | "NOT IN" | "BETWEEN" | "IS NULL" | "IS NOT NULL";
|
|
63
|
+
value: any;
|
|
64
|
+
boolean?: "AND" | "OR";
|
|
65
|
+
}
|
|
66
|
+
export interface OrderByClause {
|
|
67
|
+
column: string;
|
|
68
|
+
direction: "ASC" | "DESC";
|
|
69
|
+
}
|
|
70
|
+
export interface JoinClause {
|
|
71
|
+
type: "INNER" | "LEFT" | "RIGHT";
|
|
72
|
+
table: string;
|
|
73
|
+
first: string;
|
|
74
|
+
operator: string;
|
|
75
|
+
second: string;
|
|
76
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Macroable, Model, MongoAdapter, MySQLAdapter, PostgresAdapter, QueryBuilder, } from "./arcanox";
|
|
2
|
+
export type { DatabaseAdapter, DatabaseConfig } from "./arcanox";
|
|
3
|
+
export { Blueprint, Migration, MigrationRunner, Schema, } from "./arcanox/schema";
|
|
4
|
+
export type { MigrationStatus } from "./arcanox/schema";
|
|
5
|
+
export { Factory } from "./arcanox/factory";
|
|
6
|
+
export { Seeder } from "./arcanox/seeder";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { default as Body } from "./shared/components/Body";
|
|
2
|
+
export { default as Head } from "./shared/components/Head";
|
|
3
|
+
export { default as Link } from "./shared/components/Link";
|
|
4
|
+
export { default as NavLink } from "./shared/components/NavLink";
|
|
5
|
+
export { default as Page } from "./shared/components/Page";
|
|
6
|
+
export { default as hydrateArcanaJS } from "./client/index";
|
|
7
|
+
export { default as useLocation } from "./shared/hooks/useLocation";
|
|
8
|
+
export { default as usePage } from "./shared/hooks/usePage";
|
|
9
|
+
export { default as useParams } from "./shared/hooks/useParams";
|
|
10
|
+
export { default as useQuery } from "./shared/hooks/useQuery";
|
|
11
|
+
export { default as useRouter } from "./shared/hooks/useRouter";
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { Express } from "express";
|
|
2
2
|
import ArcanaJSServer, { ArcanaJSConfig } from "./server/ArcanaJSServer";
|
|
3
|
-
export { default as Body } from "./shared/components/Body";
|
|
4
|
-
export { default as Head } from "./shared/components/Head";
|
|
5
|
-
export { default as Link } from "./shared/components/Link";
|
|
6
|
-
export { default as NavLink } from "./shared/components/NavLink";
|
|
7
|
-
export { default as Page } from "./shared/components/Page";
|
|
8
|
-
export { default as hydrateArcanaJS } from "./client/index";
|
|
9
|
-
export { default as useLocation } from "./shared/hooks/useLocation";
|
|
10
|
-
export { default as usePage } from "./shared/hooks/usePage";
|
|
11
|
-
export { default as useParams } from "./shared/hooks/useParams";
|
|
12
|
-
export { default as useQuery } from "./shared/hooks/useQuery";
|
|
13
|
-
export { default as useRouter } from "./shared/hooks/useRouter";
|
|
14
3
|
export { default as ArcanaJSServer } from "./server/ArcanaJSServer";
|
|
4
|
+
export { Container } from "./server/Container";
|
|
15
5
|
export { Express, NextFunction, Request, Response } from "express";
|
|
6
|
+
export { FormRequest } from "./server/http/FormRequest";
|
|
7
|
+
export { JsonResource } from "./server/http/JsonResource";
|
|
8
|
+
export type { Middleware } from "./server/http/Middleware";
|
|
16
9
|
export { default as Route } from "./server/Router";
|
|
10
|
+
export { ServiceProvider } from "./server/support/ServiceProvider";
|
|
11
|
+
export { ValidationException } from "./server/validation/ValidationException";
|
|
12
|
+
export { Validator } from "./server/validation/Validator";
|
|
17
13
|
/**
|
|
18
14
|
* Create an ArcanaJS server with the given Express app
|
|
19
15
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Express, RequestHandler } from "express";
|
|
2
2
|
import React from "react";
|
|
3
|
+
import { ServiceProvider } from "./support/ServiceProvider";
|
|
3
4
|
export interface ArcanaJSConfig<TDb = any> {
|
|
4
5
|
port?: number | string;
|
|
5
6
|
views?: Record<string, React.FC<any>>;
|
|
@@ -18,30 +19,55 @@ export interface ArcanaJSConfig<TDb = any> {
|
|
|
18
19
|
dbConnect?: () => Promise<TDb> | TDb;
|
|
19
20
|
/** Automatically register SIGINT/SIGTERM handlers to call stop(). Default: true */
|
|
20
21
|
autoHandleSignals?: boolean;
|
|
22
|
+
/** Service providers to load */
|
|
23
|
+
providers?: (new (app: ArcanaJSServer) => ServiceProvider)[];
|
|
21
24
|
}
|
|
22
25
|
declare global {
|
|
23
26
|
namespace Express {
|
|
24
|
-
interface
|
|
27
|
+
interface Response {
|
|
25
28
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
29
|
+
* Sends a success response with a standard format.
|
|
30
|
+
*
|
|
31
|
+
* @param data - The data payload to include in the response (default: {}).
|
|
32
|
+
* @param message - A descriptive message for the success (default: "Success").
|
|
33
|
+
* @param status - The HTTP status code to return (default: 200).
|
|
34
|
+
* @returns The Express Response object.
|
|
28
35
|
*/
|
|
29
|
-
|
|
36
|
+
success: (data?: string | object | null, message?: string, status?: number) => Response;
|
|
37
|
+
/**
|
|
38
|
+
* Sends an error response with a standard format.
|
|
39
|
+
*
|
|
40
|
+
* @param message - A descriptive message for the error (default: "Error").
|
|
41
|
+
* @param status - The HTTP status code to return (default: 500).
|
|
42
|
+
* @param error - Additional error details or object (default: null).
|
|
43
|
+
* @param data - Optional data payload to include in the error response (default: null).
|
|
44
|
+
* @returns The Express Response object.
|
|
45
|
+
*/
|
|
46
|
+
error: (message?: string, status?: number, error?: string | object | null, data?: string | object | null) => Response;
|
|
47
|
+
/**
|
|
48
|
+
* Renders a React page using ArcanaJS SSR.
|
|
49
|
+
*
|
|
50
|
+
* @param page - The name of the page component to render.
|
|
51
|
+
* @param data - Initial data to pass to the page component (default: {}).
|
|
52
|
+
* @param params - Route parameters (default: {}).
|
|
53
|
+
* @returns The Express Response object.
|
|
54
|
+
*/
|
|
55
|
+
renderPage(page: string, data?: any, params?: Record<string, string>): Response;
|
|
30
56
|
}
|
|
31
57
|
}
|
|
32
58
|
}
|
|
59
|
+
import { Container } from "./Container";
|
|
33
60
|
declare class ArcanaJSServer<TDb = any> {
|
|
34
61
|
app: Express;
|
|
62
|
+
container: Container;
|
|
35
63
|
private config;
|
|
36
64
|
private serverInstance?;
|
|
37
65
|
private _sigintHandler?;
|
|
38
66
|
private _sigtermHandler?;
|
|
67
|
+
private providers;
|
|
39
68
|
constructor(config: ArcanaJSConfig<TDb>);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* { client?: any, db?: any, close: async () => void }
|
|
43
|
-
*/
|
|
44
|
-
private normalizeDb;
|
|
69
|
+
private registerProviders;
|
|
70
|
+
private bootProviders;
|
|
45
71
|
private initialize;
|
|
46
72
|
private loadViewsFromContext;
|
|
47
73
|
private loadViewsFromAlias;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
export type ClassConstructor<T = any> = new (...args: any[]) => T;
|
|
3
|
+
export type FactoryFunction<T = any> = (container: Container) => T;
|
|
4
|
+
export declare class Container {
|
|
5
|
+
private static instance;
|
|
6
|
+
private bindings;
|
|
7
|
+
private singletons;
|
|
8
|
+
constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Get the global container instance
|
|
11
|
+
*/
|
|
12
|
+
static getInstance(): Container;
|
|
13
|
+
/**
|
|
14
|
+
* Bind a class or factory to the container
|
|
15
|
+
*/
|
|
16
|
+
bind<T>(key: string | ClassConstructor<T>, value: ClassConstructor<T> | FactoryFunction<T>): void;
|
|
17
|
+
/**
|
|
18
|
+
* Bind a singleton to the container
|
|
19
|
+
*/
|
|
20
|
+
singleton<T>(key: string | ClassConstructor<T>, value: ClassConstructor<T> | FactoryFunction<T>): void;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve a dependency from the container
|
|
23
|
+
*/
|
|
24
|
+
make<T>(key: string | ClassConstructor<T>): T;
|
|
25
|
+
/**
|
|
26
|
+
* Instantiate a class, resolving its dependencies
|
|
27
|
+
*/
|
|
28
|
+
private build;
|
|
29
|
+
private isConstructor;
|
|
30
|
+
}
|
|
31
|
+
export declare const container: Container;
|
|
@@ -1,27 +1,2 @@
|
|
|
1
1
|
import type { NextFunction, Request, Response } from "express";
|
|
2
|
-
declare global {
|
|
3
|
-
namespace Express {
|
|
4
|
-
interface Response {
|
|
5
|
-
/**
|
|
6
|
-
* Sends a success response with a standard format.
|
|
7
|
-
*
|
|
8
|
-
* @param data - The data payload to include in the response (default: {}).
|
|
9
|
-
* @param message - A descriptive message for the success (default: "Success").
|
|
10
|
-
* @param status - The HTTP status code to return (default: 200).
|
|
11
|
-
* @returns The Express Response object.
|
|
12
|
-
*/
|
|
13
|
-
success: (data?: string | object | null, message?: string, status?: number) => Response;
|
|
14
|
-
/**
|
|
15
|
-
* Sends an error response with a standard format.
|
|
16
|
-
*
|
|
17
|
-
* @param message - A descriptive message for the error (default: "Error").
|
|
18
|
-
* @param status - The HTTP status code to return (default: 500).
|
|
19
|
-
* @param error - Additional error details or object (default: null).
|
|
20
|
-
* @param data - Optional data payload to include in the error response (default: null).
|
|
21
|
-
* @returns The Express Response object.
|
|
22
|
-
*/
|
|
23
|
-
error: (message?: string, status?: number, error?: string | object | null, data?: string | object | null) => Response;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
2
|
export declare const responseHandler: (req: Request, res: Response, next: NextFunction) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import express, { Router as ExpressRouter
|
|
1
|
+
import express, { Router as ExpressRouter } from "express";
|
|
2
2
|
/**
|
|
3
3
|
* Provides Routing syntax for defining routes with prefixes, middlewares, and groups
|
|
4
4
|
*/
|
|
@@ -14,7 +14,7 @@ export declare class Router {
|
|
|
14
14
|
/**
|
|
15
15
|
* Add middleware to the current stack
|
|
16
16
|
*/
|
|
17
|
-
middleware(...middleware:
|
|
17
|
+
middleware(...middleware: any[]): Router;
|
|
18
18
|
/**
|
|
19
19
|
* Add prefix to the current stack
|
|
20
20
|
*/
|
|
@@ -47,6 +47,11 @@ export declare class Router {
|
|
|
47
47
|
* Define an OPTIONS route
|
|
48
48
|
*/
|
|
49
49
|
options(path: string, ...args: any[]): Router;
|
|
50
|
+
/**
|
|
51
|
+
* Define a resource route
|
|
52
|
+
* Registers index, create, store, show, edit, update, destroy routes
|
|
53
|
+
*/
|
|
54
|
+
resource(path: string, controller: any): Router;
|
|
50
55
|
/**
|
|
51
56
|
* Get the underlying Express router
|
|
52
57
|
*/
|
|
@@ -63,6 +68,10 @@ export declare class Router {
|
|
|
63
68
|
* Add a route to the router
|
|
64
69
|
*/
|
|
65
70
|
private _addRoute;
|
|
71
|
+
/**
|
|
72
|
+
* Resolve middleware to RequestHandler
|
|
73
|
+
*/
|
|
74
|
+
private _resolveMiddleware;
|
|
66
75
|
/**
|
|
67
76
|
* Build the full path with prefixes
|
|
68
77
|
*/
|
|
@@ -78,7 +87,7 @@ export declare class Router {
|
|
|
78
87
|
export declare class Route {
|
|
79
88
|
private static _router;
|
|
80
89
|
static create(): Router;
|
|
81
|
-
static middleware(...middleware:
|
|
90
|
+
static middleware(...middleware: any[]): Router;
|
|
82
91
|
static prefix(prefix: string): Router;
|
|
83
92
|
static group(callback: (router: Router) => void): Router;
|
|
84
93
|
static get(path: string, ...args: any[]): Router;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Request } from "express";
|
|
2
|
+
export declare abstract class FormRequest {
|
|
3
|
+
protected req: Request;
|
|
4
|
+
constructor(req: Request);
|
|
5
|
+
abstract rules(): Record<string, string>;
|
|
6
|
+
authorize(): boolean;
|
|
7
|
+
validate(): Promise<Record<string, any>>;
|
|
8
|
+
input(key: string, defaultValue?: any): any;
|
|
9
|
+
all(): any;
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class JsonResource {
|
|
2
|
+
resource: any;
|
|
3
|
+
constructor(resource: any);
|
|
4
|
+
static make(resource: any): JsonResource;
|
|
5
|
+
static collection(resource: any[]): AnonymousResourceCollection;
|
|
6
|
+
resolve(request?: any): any;
|
|
7
|
+
toArray(request?: any): any;
|
|
8
|
+
}
|
|
9
|
+
export declare class AnonymousResourceCollection extends JsonResource {
|
|
10
|
+
collects: any;
|
|
11
|
+
constructor(resource: any[], collects: any);
|
|
12
|
+
resolve(request?: any): any;
|
|
13
|
+
}
|