Comparing version 3.0.0-alpha.0 to 3.0.0-alpha.1
@@ -289,3 +289,3 @@ import { Dict, Intersect, MaybeArray, Awaitable, Extract } from 'cosmokit'; | ||
} | ||
export interface Executable extends Executable.Payload { | ||
declare interface Executable extends Executable.Payload { | ||
} | ||
@@ -347,14 +347,23 @@ declare class Executable<S = any, T = any> { | ||
type TableType<S, T extends TableLike<S>> = T extends Keys<S> ? S[T] : T extends Selection<infer U> ? U : never; | ||
type TableMap1<S, M extends readonly Keys<S>[]> = Intersect<M extends readonly (infer K extends Keys<S>)[] ? { | ||
[P in K]: TableType<S, P>; | ||
} : never>; | ||
type TableMap2<S, U extends Dict<TableLike<S>>> = { | ||
[K in keyof U]: TableType<S, U[K]>; | ||
}; | ||
type JoinParameters<S, U extends readonly Keys<S>[]> = U extends readonly [infer K extends Keys<S>, ...infer R] ? [Row<S[K]>, ...JoinParameters<S, Extract<R, readonly Keys<S>[]>>] : []; | ||
type JoinCallback1<S, U extends readonly Keys<S>[]> = (...args: JoinParameters<S, U>) => Eval.Expr<boolean>; | ||
type JoinCallback2<S, U extends Dict<TableLike<S>>> = (args: { | ||
[K in keyof U]: Row<TableType<S, U[K]>>; | ||
}) => Eval.Expr<boolean>; | ||
export class Database<S = any, C extends Context = Context> extends Service<C> { | ||
export namespace Join1 { | ||
export type Input<S> = readonly Keys<S>[]; | ||
export type Output<S, U extends Input<S>> = Intersect<U extends readonly (infer K extends Keys<S>)[] ? { | ||
[P in K]: TableType<S, P>; | ||
} : never>; | ||
type Parameters<S, U extends Input<S>> = U extends readonly [infer K extends Keys<S>, ...infer R] ? [Row<S[K]>, ...Parameters<S, Extract<R, Input<S>>>] : []; | ||
export type Predicate<S, U extends Input<S>> = (...args: Parameters<S, U>) => Eval.Expr<boolean>; | ||
} | ||
export namespace Join2 { | ||
export type Input<S> = Dict<TableLike<S>>; | ||
export type Output<S, U extends Input<S>> = { | ||
[K in keyof U]: TableType<S, U[K]>; | ||
}; | ||
type Parameters<S, U extends Input<S>> = { | ||
[K in keyof U]: Row<TableType<S, U[K]>>; | ||
}; | ||
export type Predicate<S, U extends Input<S>> = (args: Parameters<S, U>) => Eval.Expr<boolean>; | ||
} | ||
export class Database<S = any, C extends Context = Context> extends Service<undefined, C> { | ||
static [Service.provide]: string; | ||
static [Service.immediate]: boolean; | ||
tables: { | ||
@@ -368,3 +377,2 @@ [K in Keys<S>]: Model<S[K]>; | ||
private stashed; | ||
constructor(ctx?: C); | ||
connect<T = undefined>(driver: Driver.Constructor<T>, ...args: Spread<T>): Promise<void>; | ||
@@ -379,4 +387,4 @@ refresh(): void; | ||
select<T extends Keys<S>>(table: T, query?: Query<S[T]>): Selection<S[T]>; | ||
join<U extends readonly Keys<S>[]>(tables: U, callback?: JoinCallback1<S, U>, optional?: boolean[]): Selection<TableMap1<S, U>>; | ||
join<U extends Dict<TableLike<S>>>(tables: U, callback?: JoinCallback2<S, U>, optional?: Dict<boolean, Keys<U>>): Selection<TableMap2<S, U>>; | ||
join<U extends Join1.Input<S>>(tables: U, callback?: Join1.Predicate<S, U>, optional?: boolean[]): Selection<Join1.Output<S, U>>; | ||
join<U extends Join2.Input<S>>(tables: U, callback?: Join2.Predicate<S, U>, optional?: Dict<boolean, Keys<U>>): Selection<Join2.Output<S, U>>; | ||
get<T extends Keys<S>, K extends Keys<S[T]>>(table: T, query: Query<S[T]>, cursor?: Driver.Cursor<K>): Promise<Pick<S[T], K>[]>; | ||
@@ -383,0 +391,0 @@ eval<T extends Keys<S>, U>(table: T, expr: Selection.Callback<S[T], U, true>, query?: Query<S[T]>): Promise<U>; |
{ | ||
"name": "minato", | ||
"version": "3.0.0-alpha.0", | ||
"version": "3.0.0-alpha.1", | ||
"description": "Type Driven Database Framework", | ||
@@ -45,5 +45,5 @@ "type": "module", | ||
"dependencies": { | ||
"cordis": "^3.9.1", | ||
"cordis": "^3.11.0", | ||
"cosmokit": "^1.5.2" | ||
} | ||
} |
@@ -17,26 +17,39 @@ import { Dict, Intersect, makeArray, MaybeArray, valueMap } from 'cosmokit' | ||
type TableMap1<S, M extends readonly Keys<S>[]> = Intersect< | ||
| M extends readonly (infer K extends Keys<S>)[] | ||
? { [P in K]: TableType<S, P> } | ||
: never | ||
> | ||
export namespace Join1 { | ||
export type Input<S> = readonly Keys<S>[] | ||
type TableMap2<S, U extends Dict<TableLike<S>>> = { | ||
[K in keyof U]: TableType<S, U[K]> | ||
export type Output<S, U extends Input<S>> = Intersect< | ||
| U extends readonly (infer K extends Keys<S>)[] | ||
? { [P in K]: TableType<S, P> } | ||
: never | ||
> | ||
type Parameters<S, U extends Input<S>> = | ||
| U extends readonly [infer K extends Keys<S>, ...infer R] | ||
? [Row<S[K]>, ...Parameters<S, Extract<R, Input<S>>>] | ||
: [] | ||
export type Predicate<S, U extends Input<S>> = (...args: Parameters<S, U>) => Eval.Expr<boolean> | ||
} | ||
type JoinParameters<S, U extends readonly Keys<S>[]> = | ||
| U extends readonly [infer K extends Keys<S>, ...infer R] | ||
? [Row<S[K]>, ...JoinParameters<S, Extract<R, readonly Keys<S>[]>>] | ||
: [] | ||
export namespace Join2 { | ||
export type Input<S> = Dict<TableLike<S>> | ||
type JoinCallback1<S, U extends readonly Keys<S>[]> = (...args: JoinParameters<S, U>) => Eval.Expr<boolean> | ||
export type Output<S, U extends Input<S>> = { | ||
[K in keyof U]: TableType<S, U[K]> | ||
} | ||
type JoinCallback2<S, U extends Dict<TableLike<S>>> = (args: { | ||
[K in keyof U]: Row<TableType<S, U[K]>> | ||
}) => Eval.Expr<boolean> | ||
type Parameters<S, U extends Input<S>> = { | ||
[K in keyof U]: Row<TableType<S, U[K]>> | ||
} | ||
export type Predicate<S, U extends Input<S>> = (args: Parameters<S, U>) => Eval.Expr<boolean> | ||
} | ||
const kTransaction = Symbol('transaction') | ||
export class Database<S = any, C extends Context = Context> extends Service<C> { | ||
export class Database<S = any, C extends Context = Context> extends Service<undefined, C> { | ||
static [Service.provide] = 'model' | ||
static [Service.immediate] = true | ||
public tables: { [K in Keys<S>]: Model<S[K]> } = Object.create(null) | ||
@@ -50,6 +63,2 @@ public drivers: Record<keyof any, Driver> = Object.create(null) | ||
constructor(ctx?: C) { | ||
super(ctx, 'model', true) | ||
} | ||
async connect<T = undefined>(driver: Driver.Constructor<T>, ...args: Spread<T>) { | ||
@@ -110,4 +119,4 @@ this.ctx.plugin(driver, args[0] as any) | ||
join<U extends readonly Keys<S>[]>(tables: U, callback?: JoinCallback1<S, U>, optional?: boolean[]): Selection<TableMap1<S, U>> | ||
join<U extends Dict<TableLike<S>>>(tables: U, callback?: JoinCallback2<S, U>, optional?: Dict<boolean, Keys<U>>): Selection<TableMap2<S, U>> | ||
join<U extends Join1.Input<S>>(tables: U, callback?: Join1.Predicate<S, U>, optional?: boolean[]): Selection<Join1.Output<S, U>> | ||
join<U extends Join2.Input<S>>(tables: U, callback?: Join2.Predicate<S, U>, optional?: Dict<boolean, Keys<U>>): Selection<Join2.Output<S, U>> | ||
join(tables: any, query?: any, optional?: any) { | ||
@@ -114,0 +123,0 @@ if (Array.isArray(tables)) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
3384
0
184498
Updatedcordis@^3.11.0