@h3ravel/arquebus 2.0.0 → 3.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/bin/index.cjs +580 -451
- package/bin/index.js +566 -437
- package/dist/browser/index.cjs +54 -51
- package/dist/browser/index.d.ts +804 -737
- package/dist/browser/index.js +48 -44
- package/dist/concerns/index.cjs +152 -143
- package/dist/concerns/index.d.ts +849 -776
- package/dist/concerns/index.js +143 -133
- package/dist/index.cjs +186 -185
- package/dist/index.d.ts +856 -782
- package/dist/index.js +179 -177
- package/dist/inspector/index.cjs +175 -174
- package/dist/inspector/index.d.ts +0 -1
- package/dist/inspector/index.js +161 -159
- package/dist/migrations/index.cjs +183 -182
- package/dist/migrations/index.d.ts +799 -727
- package/dist/migrations/index.js +172 -170
- package/dist/relations/index.cjs +152 -143
- package/dist/relations/index.d.ts +835 -762
- package/dist/relations/index.js +143 -133
- package/dist/seeders/index.cjs +7 -5
- package/dist/seeders/index.d.ts +797 -724
- package/dist/seeders/index.js +8 -6
- package/dist/{migrations/stubs/stubs → stubs}/migration-js.stub +1 -0
- package/dist/{migrations/stubs/stubs → stubs}/migration-ts.stub +1 -0
- package/dist/{migrations/stubs/stubs → stubs}/migration.create-js.stub +1 -0
- package/dist/{migrations/stubs/stubs → stubs}/migration.create-ts.stub +1 -0
- package/dist/{migrations/stubs/stubs → stubs}/migration.update-js.stub +1 -0
- package/dist/{migrations/stubs/stubs → stubs}/migration.update-ts.stub +1 -0
- package/dist/stubs/model-ts.stub +9 -0
- package/package.json +31 -31
- package/types/builder.ts +1 -1
- package/types/database.ts +69 -0
- package/types/index.ts +3 -0
- package/types/model-builder.ts +132 -0
- package/types/query-builder.ts +0 -1
- package/types/query-methods.ts +0 -1
- package/types/schema.ts +92 -0
- package/types/utils.ts +1 -40
- package/dist/stubs/stubs/model-ts.stub +0 -5
- /package/dist/stubs/{stubs/arquebus.config-js.stub → arquebus.config-js.stub} +0 -0
- /package/dist/stubs/{stubs/arquebus.config-ts.stub → arquebus.config-ts.stub} +0 -0
- /package/dist/stubs/{stubs/model-js.stub → model-js.stub} +0 -0
- /package/dist/stubs/{stubs/seeder-js.stub → seeder-js.stub} +0 -0
- /package/dist/stubs/{stubs/seeder-ts.stub → seeder-ts.stub} +0 -0
package/dist/seeders/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import path$1, { dirname } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
5
6
|
//#region src/seeders/seeder.ts
|
|
6
7
|
var Seeder = class {};
|
|
7
8
|
//#endregion
|
|
@@ -29,16 +30,14 @@ var SeederRunner = class {
|
|
|
29
30
|
this.resolver = resolver;
|
|
30
31
|
}
|
|
31
32
|
path(p) {
|
|
32
|
-
this.paths = Array.from(new Set([...this.paths, p]));
|
|
33
|
+
this.paths = Array.from(/* @__PURE__ */ new Set([...this.paths, p]));
|
|
33
34
|
}
|
|
34
35
|
getPaths() {
|
|
35
36
|
return this.paths;
|
|
36
37
|
}
|
|
37
38
|
resolveConnection(connection) {
|
|
38
|
-
var _getInstance, _ref, _instance$connections;
|
|
39
39
|
const name = connection || this.connection || "default";
|
|
40
|
-
|
|
41
|
-
if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
|
|
40
|
+
if (!!!(this.resolver.getInstance?.() ?? null)?.connections?.[name]) this.resolver.autoLoad().catch(() => {
|
|
42
41
|
/** noop */
|
|
43
42
|
});
|
|
44
43
|
return this.resolver.fire(name);
|
|
@@ -76,7 +75,7 @@ var SeederRunner = class {
|
|
|
76
75
|
}
|
|
77
76
|
};
|
|
78
77
|
//#endregion
|
|
79
|
-
//#region node_modules/.pnpm/tsdown@0.22.
|
|
78
|
+
//#region node_modules/.pnpm/tsdown@0.22.5_tsx@4.23.0_typescript@6.0.3/node_modules/tsdown/esm-shims.js
|
|
80
79
|
const getFilename = () => fileURLToPath(import.meta.url);
|
|
81
80
|
const getDirname = () => path$1.dirname(getFilename());
|
|
82
81
|
const __dirname = /* @__PURE__ */ getDirname();
|
|
@@ -98,7 +97,10 @@ var SeederCreator = class {
|
|
|
98
97
|
getStubPath(type) {
|
|
99
98
|
if (this.customStubPath) return path.join(this.customStubPath, `seeder-${type}.stub`);
|
|
100
99
|
const __dirname = this.getDirname(import.meta);
|
|
101
|
-
|
|
100
|
+
const name = `seeder-${type}.stub`;
|
|
101
|
+
const resolved = [path.join(__dirname, "stubs", name), path.join(__dirname, "../stubs", name)].find((candidate) => existsSync(candidate));
|
|
102
|
+
if (!resolved) throw new Error(`Seeder stub not found: ${name}`);
|
|
103
|
+
return resolved;
|
|
102
104
|
}
|
|
103
105
|
getDirname(meta) {
|
|
104
106
|
if (typeof __dirname !== "undefined") return __dirname;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h3ravel/arquebus",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Arquebus ORM is a Beautiful, expressive ORM inspired by Laravel's Eloquent, designed for TypeScript applications and for the H3ravel Framework.",
|
|
5
5
|
"homepage": "https://h3ravel.toneflix.net/arquebus",
|
|
6
6
|
"bin": {
|
|
@@ -139,8 +139,8 @@
|
|
|
139
139
|
"url": "https://github.com/h3ravel/arquebus.git"
|
|
140
140
|
},
|
|
141
141
|
"engines": {
|
|
142
|
-
"node": ">=
|
|
143
|
-
"pnpm": ">=
|
|
142
|
+
"node": "^20.19.0 || >=22.12.0",
|
|
143
|
+
"pnpm": ">=10"
|
|
144
144
|
},
|
|
145
145
|
"husky": {
|
|
146
146
|
"hooks": {
|
|
@@ -154,46 +154,45 @@
|
|
|
154
154
|
]
|
|
155
155
|
},
|
|
156
156
|
"dependencies": {
|
|
157
|
-
"@h3ravel/
|
|
158
|
-
"@h3ravel/
|
|
159
|
-
"
|
|
157
|
+
"@h3ravel/collect.js": "^5.4.0",
|
|
158
|
+
"@h3ravel/musket": "^2.2.7",
|
|
159
|
+
"@h3ravel/shared": "^2.2.5",
|
|
160
|
+
"@h3ravel/support": "^2.2.5",
|
|
161
|
+
"barrelize": "^1.8.2",
|
|
160
162
|
"chalk": "^5.6.2",
|
|
161
|
-
"chokidar": "^
|
|
162
|
-
"
|
|
163
|
-
"
|
|
164
|
-
"
|
|
165
|
-
"dayjs": "^1.11.18",
|
|
166
|
-
"dotenv": "^17.2.2",
|
|
163
|
+
"chokidar": "^5.0.0",
|
|
164
|
+
"cross-env": "^10.1.0",
|
|
165
|
+
"dayjs": "^1.11.21",
|
|
166
|
+
"dotenv": "^17.4.2",
|
|
167
167
|
"escalade": "^3.2.0",
|
|
168
168
|
"husky": "^9.1.7",
|
|
169
|
-
"knex": "^3.
|
|
170
|
-
"lint-staged": "^
|
|
171
|
-
"mysql2": "^3.
|
|
172
|
-
"pg": "^8.
|
|
169
|
+
"knex": "^3.3.0",
|
|
170
|
+
"lint-staged": "^17.0.8",
|
|
171
|
+
"mysql2": "^3.22.6",
|
|
172
|
+
"pg": "^8.22.0",
|
|
173
173
|
"pluralize": "^8.0.0",
|
|
174
|
-
"radashi": "^12.6.2",
|
|
175
174
|
"resolve-from": "^5.0.0",
|
|
176
|
-
"tedious": "^
|
|
175
|
+
"tedious": "^20.0.0"
|
|
177
176
|
},
|
|
178
177
|
"devDependencies": {
|
|
179
178
|
"@eslint/js": "^10.0.1",
|
|
180
|
-
"@types/node": "^
|
|
179
|
+
"@types/node": "^26.1.1",
|
|
181
180
|
"@types/pluralize": "^0.0.33",
|
|
182
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
183
|
-
"@typescript-eslint/parser": "^8.
|
|
184
|
-
"@vitest/coverage-v8": "^4.1.
|
|
185
|
-
"eslint": "^10.
|
|
186
|
-
"jsdom": "^
|
|
187
|
-
"prettier": "^3.
|
|
181
|
+
"@typescript-eslint/eslint-plugin": "^8.63.0",
|
|
182
|
+
"@typescript-eslint/parser": "^8.63.0",
|
|
183
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
184
|
+
"eslint": "^10.7.0",
|
|
185
|
+
"jsdom": "^29.1.1",
|
|
186
|
+
"prettier": "^3.9.5",
|
|
188
187
|
"sqlite3": "^6.0.1",
|
|
189
|
-
"terser": "^5.
|
|
188
|
+
"terser": "^5.49.0",
|
|
190
189
|
"ts-node": "^10.9.2",
|
|
191
|
-
"tsdown": "^0.22.
|
|
192
|
-
"tsx": "^4.
|
|
190
|
+
"tsdown": "^0.22.5",
|
|
191
|
+
"tsx": "^4.23.0",
|
|
193
192
|
"typescript": "^6.0.3",
|
|
194
|
-
"typescript-eslint": "^8.
|
|
195
|
-
"vite": "^8.
|
|
196
|
-
"vitest": "^4.1.
|
|
193
|
+
"typescript-eslint": "^8.63.0",
|
|
194
|
+
"vite": "^8.1.4",
|
|
195
|
+
"vitest": "^4.1.10"
|
|
197
196
|
},
|
|
198
197
|
"keywords": [
|
|
199
198
|
"arquebus",
|
|
@@ -211,6 +210,7 @@
|
|
|
211
210
|
"license": "MIT",
|
|
212
211
|
"scripts": {
|
|
213
212
|
"build": "tsdown",
|
|
213
|
+
"typecheck": "tsc --noEmit",
|
|
214
214
|
"lint": "eslint . --ext .ts",
|
|
215
215
|
"barrel": "barrelize >/dev/null",
|
|
216
216
|
"postinstall": "pnpm barrel",
|
package/types/builder.ts
CHANGED
|
@@ -33,7 +33,7 @@ export interface IBuilder<M extends Model | BModel, R = ICollection<M> | IModel>
|
|
|
33
33
|
extends BaseBuilder<M, R> {
|
|
34
34
|
connector: IQueryBuilder<M, R> &
|
|
35
35
|
Knex.QueryBuilder & { _statements: any[]; _single: any } & Knex
|
|
36
|
-
asProxy():
|
|
36
|
+
asProxy(): IBuilder<M, R>
|
|
37
37
|
chunk(
|
|
38
38
|
count: number,
|
|
39
39
|
callback: (rows: ICollection<M>) => any,
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Collection as ValueCollection } from '@h3ravel/collect.js'
|
|
2
|
+
import type { Knex } from 'knex'
|
|
3
|
+
|
|
4
|
+
export type DatabaseSchema = object
|
|
5
|
+
export type TableName<Database extends DatabaseSchema> = Extract<keyof Database, string>
|
|
6
|
+
export type TableRow<
|
|
7
|
+
Database extends DatabaseSchema,
|
|
8
|
+
Table extends TableName<Database>,
|
|
9
|
+
> = Database[Table]
|
|
10
|
+
export type TableColumn<
|
|
11
|
+
Database extends DatabaseSchema,
|
|
12
|
+
Table extends TableName<Database>,
|
|
13
|
+
> = Extract<keyof TableRow<Database, Table>, string>
|
|
14
|
+
|
|
15
|
+
export interface TableBuilder<
|
|
16
|
+
Database extends DatabaseSchema,
|
|
17
|
+
Table extends TableName<Database>,
|
|
18
|
+
> {
|
|
19
|
+
where<Column extends TableColumn<Database, Table>>(
|
|
20
|
+
column: Column,
|
|
21
|
+
value: TableRow<Database, Table>[Column] | Knex.Raw,
|
|
22
|
+
): this
|
|
23
|
+
where<Column extends TableColumn<Database, Table>>(
|
|
24
|
+
column: Column,
|
|
25
|
+
operator: string,
|
|
26
|
+
value: TableRow<Database, Table>[Column] | Knex.Raw,
|
|
27
|
+
): this
|
|
28
|
+
where(attributes: Partial<TableRow<Database, Table>>): this
|
|
29
|
+
orWhere<Column extends TableColumn<Database, Table>>(
|
|
30
|
+
column: Column,
|
|
31
|
+
value: TableRow<Database, Table>[Column] | Knex.Raw,
|
|
32
|
+
): this
|
|
33
|
+
whereIn<Column extends TableColumn<Database, Table>>(
|
|
34
|
+
column: Column,
|
|
35
|
+
values: TableRow<Database, Table>[Column][],
|
|
36
|
+
): this
|
|
37
|
+
whereNull(column: TableColumn<Database, Table>): this
|
|
38
|
+
whereNotNull(column: TableColumn<Database, Table>): this
|
|
39
|
+
select(...columns: (TableColumn<Database, Table> | '*')[]): this
|
|
40
|
+
orderBy(
|
|
41
|
+
column: TableColumn<Database, Table>,
|
|
42
|
+
direction?: 'asc' | 'desc' | 'ASC' | 'DESC',
|
|
43
|
+
): this
|
|
44
|
+
limit(count: number): this
|
|
45
|
+
offset(count: number): this
|
|
46
|
+
first(columns?: TableColumn<Database, Table>[]): Promise<TableRow<Database, Table> | undefined>
|
|
47
|
+
get(columns?: TableColumn<Database, Table>[]): Promise<TableRow<Database, Table>[]>
|
|
48
|
+
insert(
|
|
49
|
+
rows: Partial<TableRow<Database, Table>> | Partial<TableRow<Database, Table>>[],
|
|
50
|
+
): Promise<unknown>
|
|
51
|
+
update(values: Partial<TableRow<Database, Table>>): Promise<number>
|
|
52
|
+
delete(): Promise<number>
|
|
53
|
+
count(column?: TableColumn<Database, Table> | '*'): Promise<number>
|
|
54
|
+
min(column: TableColumn<Database, Table>): Promise<number>
|
|
55
|
+
max(column: TableColumn<Database, Table>): Promise<number>
|
|
56
|
+
sum(column: TableColumn<Database, Table>): Promise<number>
|
|
57
|
+
avg(column: TableColumn<Database, Table>): Promise<number>
|
|
58
|
+
pluck<Column extends TableColumn<Database, Table>>(
|
|
59
|
+
column: Column,
|
|
60
|
+
): Promise<ValueCollection<TableRow<Database, Table>[Column]>>
|
|
61
|
+
clone(): TableBuilder<Database, Table>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface TypedArquebus<Database extends DatabaseSchema> {
|
|
65
|
+
table<Table extends TableName<Database>>(
|
|
66
|
+
name: Table,
|
|
67
|
+
connection?: string | null,
|
|
68
|
+
): TableBuilder<Database, Table>
|
|
69
|
+
}
|
package/types/index.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export * from './builder'
|
|
2
2
|
export * from './container'
|
|
3
|
+
export * from './database'
|
|
3
4
|
export * from './generics'
|
|
5
|
+
export * from './model-builder'
|
|
4
6
|
export * from './modeling'
|
|
5
7
|
export * from './query-builder'
|
|
6
8
|
export * from './query-methods'
|
|
9
|
+
export * from './schema'
|
|
7
10
|
export * from './utils'
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { Collection as ValueCollection } from '@h3ravel/collect.js'
|
|
2
|
+
import type { Knex } from 'knex'
|
|
3
|
+
import type Collection from 'src/collection'
|
|
4
|
+
import type Paginator from 'src/paginator'
|
|
5
|
+
import type Model from 'src/model'
|
|
6
|
+
import type { IBuilder } from './builder'
|
|
7
|
+
import type {
|
|
8
|
+
ModelColumn,
|
|
9
|
+
ModelColumnValue,
|
|
10
|
+
ModelInput,
|
|
11
|
+
ModelKey,
|
|
12
|
+
ModelRelationPath,
|
|
13
|
+
QualifiedModelColumn,
|
|
14
|
+
} from './schema'
|
|
15
|
+
|
|
16
|
+
export type QueryOperator =
|
|
17
|
+
| '='
|
|
18
|
+
| '!='
|
|
19
|
+
| '<>'
|
|
20
|
+
| '<'
|
|
21
|
+
| '<='
|
|
22
|
+
| '>'
|
|
23
|
+
| '>='
|
|
24
|
+
| 'like'
|
|
25
|
+
| 'ilike'
|
|
26
|
+
| 'in'
|
|
27
|
+
| 'not in'
|
|
28
|
+
| (string & {})
|
|
29
|
+
|
|
30
|
+
export type QueryValue<Value> = Value | Knex.Raw | ModelBuilder<any>
|
|
31
|
+
|
|
32
|
+
export interface ModelBuilder<M extends Model = Model> {
|
|
33
|
+
query: IBuilder<M>
|
|
34
|
+
[method: string]: any
|
|
35
|
+
where<Column extends ModelColumn<M>>(
|
|
36
|
+
column: Column,
|
|
37
|
+
value: QueryValue<ModelColumnValue<M, Column>>,
|
|
38
|
+
): this
|
|
39
|
+
where<Column extends ModelColumn<M>>(
|
|
40
|
+
column: Column,
|
|
41
|
+
operator: QueryOperator,
|
|
42
|
+
value: QueryValue<ModelColumnValue<M, Column>>,
|
|
43
|
+
): this
|
|
44
|
+
where(attributes: ModelInput<M>): this
|
|
45
|
+
where(callback: (query: ModelBuilder<M>) => unknown): this
|
|
46
|
+
orWhere<Column extends ModelColumn<M>>(
|
|
47
|
+
column: Column,
|
|
48
|
+
value: QueryValue<ModelColumnValue<M, Column>>,
|
|
49
|
+
): this
|
|
50
|
+
orWhere<Column extends ModelColumn<M>>(
|
|
51
|
+
column: Column,
|
|
52
|
+
operator: QueryOperator,
|
|
53
|
+
value: QueryValue<ModelColumnValue<M, Column>>,
|
|
54
|
+
): this
|
|
55
|
+
orWhere(callback: (query: ModelBuilder<M>) => unknown): this
|
|
56
|
+
whereIn<Column extends ModelColumn<M>>(
|
|
57
|
+
column: Column,
|
|
58
|
+
values: ModelColumnValue<M, Column>[],
|
|
59
|
+
): this
|
|
60
|
+
whereNotIn<Column extends ModelColumn<M>>(
|
|
61
|
+
column: Column,
|
|
62
|
+
values: ModelColumnValue<M, Column>[],
|
|
63
|
+
): this
|
|
64
|
+
whereNull(column: ModelColumn<M>): this
|
|
65
|
+
whereNotNull(column: ModelColumn<M>): this
|
|
66
|
+
whereBetween<Column extends ModelColumn<M>>(
|
|
67
|
+
column: Column,
|
|
68
|
+
values: [ModelColumnValue<M, Column>, ModelColumnValue<M, Column>],
|
|
69
|
+
): this
|
|
70
|
+
whereColumn(
|
|
71
|
+
first: QualifiedModelColumn<M>,
|
|
72
|
+
operator: QueryOperator,
|
|
73
|
+
second: QualifiedModelColumn<M>,
|
|
74
|
+
): this
|
|
75
|
+
select(
|
|
76
|
+
...columns: (
|
|
77
|
+
| ModelColumn<M>
|
|
78
|
+
| '*'
|
|
79
|
+
| readonly (ModelColumn<M> | '*')[]
|
|
80
|
+
)[]
|
|
81
|
+
): this
|
|
82
|
+
orderBy(column: ModelColumn<M>, direction?: 'asc' | 'desc' | 'ASC' | 'DESC'): this
|
|
83
|
+
latest(column?: ModelColumn<M>): this
|
|
84
|
+
oldest(column?: ModelColumn<M>): this
|
|
85
|
+
limit(count: number): this
|
|
86
|
+
take(count: number): this
|
|
87
|
+
offset(count: number): this
|
|
88
|
+
skip(count: number): this
|
|
89
|
+
with(
|
|
90
|
+
...relations: (
|
|
91
|
+
| ModelRelationPath<M>
|
|
92
|
+
| readonly ModelRelationPath<M>[]
|
|
93
|
+
| Partial<
|
|
94
|
+
Record<
|
|
95
|
+
ModelRelationPath<M>,
|
|
96
|
+
(query: ModelBuilder<any>) => unknown
|
|
97
|
+
>
|
|
98
|
+
>
|
|
99
|
+
)[]
|
|
100
|
+
): this
|
|
101
|
+
withCount(
|
|
102
|
+
...relations: (ModelRelationPath<M> | readonly ModelRelationPath<M>[])[]
|
|
103
|
+
): this
|
|
104
|
+
first(columns?: ModelColumn<M>[]): Promise<M | null>
|
|
105
|
+
firstOrFail(columns?: ModelColumn<M>[]): Promise<M>
|
|
106
|
+
find(key: ModelKey<M>, columns?: ModelColumn<M>[]): Promise<M | null>
|
|
107
|
+
findOrFail(key: ModelKey<M>, columns?: ModelColumn<M>[]): Promise<M>
|
|
108
|
+
findMany(keys: ModelKey<M>[], columns?: ModelColumn<M>[]): Promise<Collection<M>>
|
|
109
|
+
get(columns?: ModelColumn<M>[]): Promise<Collection<M>>
|
|
110
|
+
all(columns?: ModelColumn<M>[]): Promise<Collection<M>>
|
|
111
|
+
create(attributes?: ModelInput<M>): Promise<M>
|
|
112
|
+
firstOrNew(attributes?: ModelInput<M>, values?: ModelInput<M>): Promise<M>
|
|
113
|
+
firstOrCreate(attributes?: ModelInput<M>, values?: ModelInput<M>): Promise<M>
|
|
114
|
+
updateOrCreate(attributes: ModelInput<M>, values?: ModelInput<M>): Promise<M>
|
|
115
|
+
update(attributes: ModelInput<M>): Promise<number>
|
|
116
|
+
increment(column: ModelColumn<M>, amount?: number, extra?: ModelInput<M>): Promise<number>
|
|
117
|
+
decrement(column: ModelColumn<M>, amount?: number, extra?: ModelInput<M>): Promise<number>
|
|
118
|
+
delete(): Promise<boolean | number>
|
|
119
|
+
forceDelete(): Promise<boolean | number>
|
|
120
|
+
count(column?: ModelColumn<M> | '*'): Promise<number>
|
|
121
|
+
min(column: ModelColumn<M>): Promise<number>
|
|
122
|
+
max(column: ModelColumn<M>): Promise<number>
|
|
123
|
+
sum(column: ModelColumn<M>): Promise<number>
|
|
124
|
+
avg(column: ModelColumn<M>): Promise<number>
|
|
125
|
+
pluck<Column extends ModelColumn<M>>(
|
|
126
|
+
column: Column,
|
|
127
|
+
): Promise<ValueCollection<ModelColumnValue<M, Column>>>
|
|
128
|
+
paginate(page?: number, perPage?: number): Promise<Paginator<M>>
|
|
129
|
+
clone(): ModelBuilder<M>
|
|
130
|
+
getModel(): M
|
|
131
|
+
toSql(): object
|
|
132
|
+
}
|
package/types/query-builder.ts
CHANGED
package/types/query-methods.ts
CHANGED
package/types/schema.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Collection as BaseCollection } from '@h3ravel/collect.js'
|
|
2
|
+
import type Collection from 'src/collection'
|
|
3
|
+
import type { ModelBuilder } from './model-builder'
|
|
4
|
+
import type Model from 'src/model'
|
|
5
|
+
|
|
6
|
+
export type ModelRecord = object
|
|
7
|
+
export type RelationRecord = object
|
|
8
|
+
|
|
9
|
+
export type ModelAttributesOf<M> = M extends { readonly $attributes: infer Attributes }
|
|
10
|
+
? Attributes
|
|
11
|
+
: never
|
|
12
|
+
|
|
13
|
+
export type ModelRelationsOf<M> = M extends { readonly $relations: infer Relations }
|
|
14
|
+
? Relations
|
|
15
|
+
: never
|
|
16
|
+
|
|
17
|
+
export type ModelTableOf<M> = M extends { readonly $table: infer Table extends string }
|
|
18
|
+
? Table
|
|
19
|
+
: string
|
|
20
|
+
|
|
21
|
+
export type ModelColumn<M> = [keyof ModelAttributesOf<M>] extends [never]
|
|
22
|
+
? string
|
|
23
|
+
: Extract<keyof ModelAttributesOf<M>, string>
|
|
24
|
+
export type QualifiedModelColumn<M> =
|
|
25
|
+
| ModelColumn<M>
|
|
26
|
+
| `${ModelTableOf<M>}.${ModelColumn<M>}`
|
|
27
|
+
|
|
28
|
+
export type ModelColumnValue<
|
|
29
|
+
M,
|
|
30
|
+
Column extends string,
|
|
31
|
+
> = Column extends `${string}.${infer Name}`
|
|
32
|
+
? Name extends keyof ModelAttributesOf<M>
|
|
33
|
+
? ModelAttributesOf<M>[Name]
|
|
34
|
+
: never
|
|
35
|
+
: Column extends keyof ModelAttributesOf<M>
|
|
36
|
+
? ModelAttributesOf<M>[Column]
|
|
37
|
+
: never
|
|
38
|
+
|
|
39
|
+
export type ModelInput<M> = Partial<ModelAttributesOf<M>>
|
|
40
|
+
export type ModelData<M> = ModelAttributesOf<M> & Partial<ModelRelationsOf<M>>
|
|
41
|
+
export type ModelRelation<M> = Extract<keyof ModelRelationsOf<M>, string>
|
|
42
|
+
export type ModelRelationPath<M> = [ModelRelation<M>] extends [never]
|
|
43
|
+
? string
|
|
44
|
+
: ModelRelation<M> | `${ModelRelation<M>}.${string}`
|
|
45
|
+
type DeclaredModelKey<M> = 'id' extends keyof ModelAttributesOf<M>
|
|
46
|
+
? Extract<ModelAttributesOf<M>['id'], string | number>
|
|
47
|
+
: never
|
|
48
|
+
export type ModelKey<M> = [DeclaredModelKey<M>] extends [never]
|
|
49
|
+
? string | number
|
|
50
|
+
: DeclaredModelKey<M>
|
|
51
|
+
|
|
52
|
+
export type HydratedModel<
|
|
53
|
+
Attributes extends ModelRecord,
|
|
54
|
+
Relations extends RelationRecord = {},
|
|
55
|
+
Table extends string = string,
|
|
56
|
+
> = Model<Attributes, Relations, Table> & Attributes & Partial<Relations>
|
|
57
|
+
|
|
58
|
+
export type DefinedModel<
|
|
59
|
+
Attributes extends ModelRecord,
|
|
60
|
+
Relations extends RelationRecord = {},
|
|
61
|
+
Table extends string = string,
|
|
62
|
+
> = {
|
|
63
|
+
new (attributes?: Partial<Attributes>): HydratedModel<Attributes, Relations, Table>
|
|
64
|
+
query<M extends Model<any, any, any>>(this: ModelConstructor<M>): ModelBuilder<M>
|
|
65
|
+
on<M extends Model<any, any, any>>(
|
|
66
|
+
this: ModelConstructor<M>,
|
|
67
|
+
connection?: string | null,
|
|
68
|
+
): ModelBuilder<M>
|
|
69
|
+
init<M extends Model<any, any, any>>(
|
|
70
|
+
this: ModelConstructor<M>,
|
|
71
|
+
attributes?: ModelInput<M>,
|
|
72
|
+
): M
|
|
73
|
+
make<M extends Model<any, any, any>>(
|
|
74
|
+
this: ModelConstructor<M>,
|
|
75
|
+
attributes?: ModelInput<M>,
|
|
76
|
+
): M
|
|
77
|
+
booting(): void
|
|
78
|
+
boot(): void
|
|
79
|
+
booted(): void
|
|
80
|
+
setConnectionResolver(resolver: unknown): void
|
|
81
|
+
extend(plugin: (...args: any[]) => any, options: object): void
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export type ModelConstructor<M extends Model<any, any, any> = Model> = {
|
|
85
|
+
new (attributes?: ModelInput<M>): M
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type CollectionItem<C> = C extends Collection<infer Item>
|
|
89
|
+
? Item
|
|
90
|
+
: C extends BaseCollection<infer Item>
|
|
91
|
+
? Item
|
|
92
|
+
: never
|
package/types/utils.ts
CHANGED
|
@@ -1,47 +1,8 @@
|
|
|
1
1
|
import type BModel from 'src/browser/model'
|
|
2
|
-
import type { Collection as BaseCollection } from 'collect.js'
|
|
3
2
|
import type Collection from 'src/collection'
|
|
4
|
-
import type { IBuilder } from './builder'
|
|
5
|
-
import type { IModel } from './modeling'
|
|
6
3
|
import type Model from 'src/model'
|
|
7
|
-
import type { TGeneric } from './generics'
|
|
8
4
|
|
|
9
|
-
export
|
|
10
|
-
extends BaseCollection<T> {
|
|
11
|
-
items?: T[]
|
|
12
|
-
load (...relations: T[]): Promise<ICollection<T>>
|
|
13
|
-
loadAggregate (
|
|
14
|
-
relations: T | T[],
|
|
15
|
-
column: string,
|
|
16
|
-
action?: string | null,
|
|
17
|
-
): Promise<this>
|
|
18
|
-
loadCount (relation: T, column: string): Promise<this>
|
|
19
|
-
loadMax (relation: T, column: string): Promise<this>
|
|
20
|
-
loadMin (relation: T, column: string): Promise<this>
|
|
21
|
-
loadSum (relation: T, column: string): Promise<this>
|
|
22
|
-
loadAvg (relation: T, column: string): Promise<this>
|
|
23
|
-
mapThen (callback: () => void): Promise<any>
|
|
24
|
-
modelKeys (): string[] | number[]
|
|
25
|
-
contains (key: IModel | any, operator?: any, value?: any): boolean
|
|
26
|
-
diff (items: ICollection<T> | any[]): ICollection<T>
|
|
27
|
-
except (keys: any[]): ICollection<T>
|
|
28
|
-
intersect (items: T[]): ICollection<T>
|
|
29
|
-
unique (key?: any, strict?: boolean): ICollection<T>
|
|
30
|
-
find (key: any, defaultValue?: any): any
|
|
31
|
-
fresh (withs?: any[]): Promise<ICollection<T>>
|
|
32
|
-
makeVisible (attributes: string | string[]): this
|
|
33
|
-
makeHidden (attributes: string | string[]): this
|
|
34
|
-
append (attributes: string[]): this
|
|
35
|
-
only (keys: null | any[]): this
|
|
36
|
-
getDictionary (items?: any[]): TGeneric
|
|
37
|
-
toQuery (): IBuilder<T, any>
|
|
38
|
-
toData (): any
|
|
39
|
-
toJSON (): any
|
|
40
|
-
toJson (): string
|
|
41
|
-
toString (): string
|
|
42
|
-
[key: string]: any
|
|
43
|
-
[Symbol.iterator]: () => Iterator<T>
|
|
44
|
-
}
|
|
5
|
+
export type ICollection<T extends Model | BModel> = Collection<T>
|
|
45
6
|
|
|
46
7
|
export interface IPaginatorParams {
|
|
47
8
|
current_page?: number
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|