@primate/core 0.6.3 → 0.7.1
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/lib/private/App.d.ts +76 -149
- package/lib/private/App.js +22 -6
- package/lib/private/Flags.d.ts +5 -3
- package/lib/private/Flags.js +4 -2
- package/lib/private/app/Facade.d.ts +77 -156
- package/lib/private/app/Facade.js +4 -1
- package/lib/private/build/App.d.ts +4 -2
- package/lib/private/build/App.js +13 -4
- package/lib/private/build/client/index.js +24 -10
- package/lib/private/build/client/plugin/routes.d.ts +4 -0
- package/lib/private/build/client/plugin/routes.js +77 -0
- package/lib/private/build/hook.js +14 -6
- package/lib/private/build/index.d.ts +3 -2
- package/lib/private/build/index.js +9 -15
- package/lib/private/build/preclient/index.d.ts +3 -0
- package/lib/private/build/preclient/index.js +69 -0
- package/lib/private/build/preclient/plugin/routes.d.ts +4 -0
- package/lib/private/build/preclient/plugin/routes.js +44 -0
- package/lib/private/build/server/index.js +8 -5
- package/lib/private/build/server/plugin/assets.js +3 -3
- package/lib/private/build/server/plugin/native-addons.js +6 -8
- package/lib/private/build/server/plugin/node-imports.js +5 -7
- package/lib/private/build/server/plugin/route-client.d.ts +4 -0
- package/lib/private/build/server/plugin/route-client.js +111 -0
- package/lib/private/build/server/plugin/route.js +3 -10
- package/lib/private/build/server/plugin/virtual-pages.js +3 -3
- package/lib/private/build/server/plugin/virtual-routes.d.ts +2 -1
- package/lib/private/build/server/plugin/virtual-routes.js +27 -8
- package/lib/private/build/server/plugin/wasm.js +3 -2
- package/lib/private/build/shared/intercept.d.ts +4 -0
- package/lib/private/build/shared/intercept.js +29 -0
- package/lib/private/client/Data.d.ts +1 -1
- package/lib/private/client/boot.js +2 -2
- package/lib/private/client/create-form.d.ts +11 -1
- package/lib/private/client/create-form.js +21 -3
- package/lib/private/client/index.d.ts +2 -2
- package/lib/private/client/navigate.d.ts +1 -0
- package/lib/private/client/navigate.js +7 -6
- package/lib/private/client/submit.d.ts +2 -1
- package/lib/private/client/submit.js +8 -7
- package/lib/private/client/{http.d.ts → transport.d.ts} +3 -3
- package/lib/private/client/{http.js → transport.js} +7 -9
- package/lib/private/config/schema.d.ts +5 -13
- package/lib/private/config/schema.js +1 -5
- package/lib/private/db/DB.d.ts +3 -1
- package/lib/private/db/MemoryDB.d.ts +5 -2
- package/lib/private/db/MemoryDB.js +33 -19
- package/lib/private/db/SQLDB.d.ts +23 -0
- package/lib/private/db/SQLDB.js +2 -0
- package/lib/private/db/errors.d.ts +74 -7
- package/lib/private/db/errors.js +31 -7
- package/lib/private/db/migrate/apply.js +8 -9
- package/lib/private/db/migrate/bundle.js +2 -2
- package/lib/private/db/migrate/create.js +18 -20
- package/lib/private/db/migrate/status.js +9 -10
- package/lib/private/db/migrate/store.d.ts +3 -3
- package/lib/private/db/migrate/store.js +5 -5
- package/lib/private/db/test.js +256 -115
- package/lib/private/db/testSQL.d.ts +50 -0
- package/lib/private/db/testSQL.js +196 -0
- package/lib/private/errors.d.ts +66 -9
- package/lib/private/errors.js +37 -16
- package/lib/private/frontend.d.ts +4 -4
- package/lib/private/frontend.js +11 -8
- package/lib/private/i18n/errors.d.ts +7 -1
- package/lib/private/i18n/errors.js +1 -1
- package/lib/private/i18n/index/types.d.ts +1 -1
- package/lib/private/i18n/locale.d.ts +1 -1
- package/lib/private/i18n/module.js +6 -5
- package/lib/private/index.d.ts +10 -2
- package/lib/private/index.js +13 -1
- package/lib/private/logger.d.ts +24 -0
- package/lib/private/logger.js +66 -0
- package/lib/private/module/Setup.d.ts +3 -0
- package/lib/private/module/create.d.ts +2 -1
- package/lib/private/module/create.js +4 -0
- package/lib/private/paths.d.ts +2 -3
- package/lib/private/paths.js +6 -12
- package/lib/private/request/ContentType.d.ts +3 -0
- package/lib/private/request/ContentType.js +2 -0
- package/lib/private/request/RequestBag.d.ts +2 -18
- package/lib/private/request/RequestBag.js +4 -16
- package/lib/private/request/RequestBody.d.ts +20 -28
- package/lib/private/request/RequestBody.js +63 -86
- package/lib/private/request/RequestFacade.d.ts +2 -2
- package/lib/private/request/handle.js +2 -2
- package/lib/private/request/parse.js +2 -4
- package/lib/private/request/route.js +15 -8
- package/lib/private/response/binary.d.ts +2 -2
- package/lib/private/response/binary.js +6 -6
- package/lib/private/response/error.js +6 -2
- package/lib/private/response/json.js +2 -2
- package/lib/private/response/null.d.ts +3 -0
- package/lib/private/response/null.js +6 -0
- package/lib/private/response/redirect.js +4 -3
- package/lib/private/response/respond.js +4 -4
- package/lib/private/response/sse.js +2 -2
- package/lib/private/response/text.js +2 -2
- package/lib/private/route/ContentTypeMap.d.ts +10 -0
- package/lib/private/route/ContentTypeMap.js +2 -0
- package/lib/private/route/Handler.d.ts +3 -2
- package/lib/private/route/NarrowedRequest.d.ts +23 -0
- package/lib/private/route/NarrowedRequest.js +2 -0
- package/lib/private/route/Options.d.ts +6 -1
- package/lib/private/route/Path.d.ts +2 -2
- package/lib/private/route/hook.d.ts +3 -1
- package/lib/private/route/hook.js +1 -2
- package/lib/private/route/router.d.ts +7 -11
- package/lib/private/route/router.js +13 -20
- package/lib/private/route.client.d.ts +36 -0
- package/lib/private/route.client.js +8 -0
- package/lib/private/route.d.ts +21 -5
- package/lib/private/route.js +21 -5
- package/lib/private/serve/App.d.ts +1 -2
- package/lib/private/serve/App.js +64 -58
- package/lib/private/serve/Init.d.ts +2 -0
- package/lib/private/serve/dev-module.js +2 -3
- package/lib/private/serve/index.js +5 -6
- package/lib/private/server/TAG.d.ts +1 -1
- package/lib/private/server/TAG.js +1 -1
- package/lib/private/session/index.d.ts +1 -1
- package/lib/private/session/index.js +3 -2
- package/lib/private/session/module.js +3 -3
- package/lib/private/session/schema.d.ts +3 -3
- package/lib/private/session/schema.js +4 -3
- package/lib/private/store/ExtractRelation.d.ts +7 -0
- package/lib/private/store/ExtractRelation.js +2 -0
- package/lib/private/store/ExtractSchema.d.ts +10 -0
- package/lib/private/{orm → store}/ForeignKey.d.ts +1 -1
- package/lib/private/store/Init.d.ts +13 -0
- package/lib/private/store/Init.js +2 -0
- package/lib/private/{orm/store.d.ts → store/Store.d.ts} +50 -50
- package/lib/private/{orm/store.js → store/Store.js} +163 -107
- package/lib/private/store/StoreInput.d.ts +11 -0
- package/lib/private/store/key.d.ts +8 -0
- package/lib/private/store/key.js +8 -0
- package/lib/private/{orm → store}/parse.d.ts +3 -3
- package/lib/private/{orm → store}/parse.js +7 -2
- package/lib/private/store/relation.d.ts +29 -0
- package/lib/private/store/relation.js +26 -0
- package/lib/private/store.d.ts +24 -0
- package/lib/private/store.js +10 -0
- package/lib/public/db/errors.d.ts +1 -1
- package/lib/public/db/errors.js +1 -1
- package/lib/public/db/testSQL.d.ts +2 -0
- package/lib/public/db/testSQL.js +2 -0
- package/lib/public/db.d.ts +1 -0
- package/lib/public/index.d.ts +1 -0
- package/lib/public/index.js +1 -1
- package/lib/public/response.d.ts +6 -6
- package/lib/public/response.js +4 -1
- package/lib/public/route.client.d.ts +2 -0
- package/lib/public/route.client.js +2 -0
- package/lib/public/store.d.ts +2 -0
- package/lib/public/store.js +2 -0
- package/package.json +24 -17
- package/lib/private/bye.d.ts +0 -3
- package/lib/private/bye.js +0 -4
- package/lib/private/log.d.ts +0 -20
- package/lib/private/log.js +0 -47
- package/lib/private/orm/ExtractSchema.d.ts +0 -9
- package/lib/private/orm/StoreInput.d.ts +0 -10
- package/lib/private/orm/key.d.ts +0 -8
- package/lib/private/orm/key.js +0 -8
- package/lib/private/orm/relation.d.ts +0 -43
- package/lib/private/orm/relation.js +0 -26
- package/lib/private/request/Verb.d.ts +0 -4
- package/lib/private/request/Verb.js +0 -2
- package/lib/private/request/verbs.d.ts +0 -3
- package/lib/private/request/verbs.js +0 -12
- package/lib/private/route/wrap.d.ts +0 -2
- package/lib/private/route/wrap.js +0 -12
- package/lib/public/log.d.ts +0 -2
- package/lib/public/log.js +0 -2
- package/lib/public/orm/key.d.ts +0 -2
- package/lib/public/orm/key.js +0 -2
- package/lib/public/orm/relation.d.ts +0 -2
- package/lib/public/orm/relation.js +0 -2
- package/lib/public/orm/store.d.ts +0 -2
- package/lib/public/orm/store.js +0 -2
- package/lib/public/request/verbs.d.ts +0 -2
- package/lib/public/request/verbs.js +0 -2
- /package/lib/private/{orm → store}/ExtractSchema.js +0 -0
- /package/lib/private/{orm → store}/ForeignKey.js +0 -0
- /package/lib/private/{orm → store}/PrimaryKey.d.ts +0 -0
- /package/lib/private/{orm → store}/PrimaryKey.js +0 -0
- /package/lib/private/{orm → store}/StoreInput.js +0 -0
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
import type DataDict from "#db/DataDict";
|
|
1
2
|
import type DB from "#db/DB";
|
|
2
3
|
import type PK from "#db/PK";
|
|
3
4
|
import type Types from "#db/Types";
|
|
4
|
-
import type
|
|
5
|
-
import type
|
|
6
|
-
import type
|
|
7
|
-
import type
|
|
8
|
-
import type {
|
|
5
|
+
import type ExtractRelations from "#store/ExtractRelation";
|
|
6
|
+
import type ExtractSchema from "#store/ExtractSchema";
|
|
7
|
+
import type Init from "#store/Init";
|
|
8
|
+
import type PrimaryKey from "#store/PrimaryKey";
|
|
9
|
+
import type { ManyRelation, OneRelation, Relation } from "#store/relation";
|
|
10
|
+
import type StoreInput from "#store/StoreInput";
|
|
11
|
+
import type { Dict, Serializable } from "@rcompat/type";
|
|
9
12
|
import type { DefaultType, InferStore, Storable } from "pema";
|
|
10
13
|
import StoreType from "pema/StoreType";
|
|
14
|
+
declare const brand: unique symbol;
|
|
11
15
|
type X<T> = {
|
|
12
16
|
[K in keyof T]: T[K];
|
|
13
17
|
} & {};
|
|
@@ -17,6 +21,7 @@ type OrNull<T> = {
|
|
|
17
21
|
type StringOperators = {
|
|
18
22
|
$like?: string;
|
|
19
23
|
$ilike?: string;
|
|
24
|
+
$in?: string[];
|
|
20
25
|
};
|
|
21
26
|
type NumberOperators = {
|
|
22
27
|
$gt?: number;
|
|
@@ -24,6 +29,7 @@ type NumberOperators = {
|
|
|
24
29
|
$lt?: number;
|
|
25
30
|
$lte?: number;
|
|
26
31
|
$ne?: number;
|
|
32
|
+
$in?: number[];
|
|
27
33
|
};
|
|
28
34
|
type BigIntOperators = {
|
|
29
35
|
$gt?: bigint;
|
|
@@ -31,11 +37,13 @@ type BigIntOperators = {
|
|
|
31
37
|
$lt?: bigint;
|
|
32
38
|
$lte?: bigint;
|
|
33
39
|
$ne?: bigint;
|
|
40
|
+
$in?: bigint[];
|
|
34
41
|
};
|
|
35
42
|
type DateOperators = {
|
|
36
43
|
$before?: Date;
|
|
37
44
|
$after?: Date;
|
|
38
45
|
$ne?: Date;
|
|
46
|
+
$in?: Date[];
|
|
39
47
|
};
|
|
40
48
|
type QueryOperators<T> = T extends string ? (T | StringOperators | null) : T extends number ? (T | NumberOperators | null) : T extends bigint ? (T | BigIntOperators | null) : T extends Date ? (T | DateOperators | null) : (T | null);
|
|
41
49
|
type InferRecord<T extends StoreInput> = InferStore<ExtractSchema<T>>;
|
|
@@ -55,37 +63,30 @@ type Insertable<T extends StoreInput> = Omit<InferRecord<T>, PrimaryKeyField<T>
|
|
|
55
63
|
type PrimaryKeyField<T extends StoreInput> = {
|
|
56
64
|
[K in keyof T]: T[K] extends PrimaryKey<any> ? K : never;
|
|
57
65
|
}[keyof T] & keyof InferRecord<T>;
|
|
66
|
+
type SchemaOf<S> = S extends Store<infer T, any> ? Schema<T> : never;
|
|
67
|
+
type StoreT<S> = S extends Store<infer T, any> ? T : never;
|
|
68
|
+
type RelationTable<R> = R extends OneRelation<infer N, string> ? N : R extends ManyRelation<infer N, string> ? N : never;
|
|
69
|
+
type RelationStore<N extends string> = Store<any, N>;
|
|
70
|
+
type WithQuery<N extends string, S extends RelationStore<N> = RelationStore<N>> = {
|
|
71
|
+
store: S;
|
|
72
|
+
where?: Where<StoreT<S>> & DataDict;
|
|
73
|
+
select?: readonly (keyof Schema<StoreT<S>> & string)[];
|
|
74
|
+
sort?: Sort<Schema<StoreT<S>>> & ReadSort;
|
|
75
|
+
limit?: number;
|
|
76
|
+
};
|
|
77
|
+
type WithInput<R extends Dict<Relation>> = {
|
|
78
|
+
[K in keyof R]?: RelationStore<RelationTable<R[K]>> | WithQuery<RelationTable<R[K]>, RelationStore<RelationTable<R[K]>>>;
|
|
79
|
+
};
|
|
80
|
+
type RelationResult<Rel, W> = Rel extends OneRelation<string, string> ? W extends WithQuery<string, infer S> ? W["select"] extends readonly (keyof SchemaOf<S> & string)[] ? Pick<SchemaOf<S>, W["select"][number]> | null : SchemaOf<S> | null : SchemaOf<W> | null : Rel extends ManyRelation<string, string> ? W extends WithQuery<string, infer S> ? W["select"] extends readonly (keyof SchemaOf<S> & string)[] ? Pick<SchemaOf<S>, W["select"][number]>[] : SchemaOf<S>[] : SchemaOf<W>[] : never;
|
|
81
|
+
type WithRelations<Base, R extends Dict<Relation>, W extends WithInput<R> | undefined> = W extends object ? X<Base & {
|
|
82
|
+
[K in keyof W & keyof R]: RelationResult<R[K], W[K]>;
|
|
83
|
+
}> : Base;
|
|
58
84
|
declare const NUMBER_KEYS: readonly ["u8", "u16", "u32", "i8", "i16", "i32", "f32", "f64"];
|
|
59
85
|
declare const BIGINT_KEYS: readonly ["u64", "u128", "i64", "i128"];
|
|
60
86
|
type NumberKey = typeof NUMBER_KEYS[number];
|
|
61
87
|
type BigIntKey = typeof BIGINT_KEYS[number];
|
|
62
88
|
type PKV<T extends StoreInput> = T[PrimaryKeyField<T>] extends PrimaryKey<infer P> ? P extends Storable<infer D> ? D extends "uuid" | "uuid_v4" | "uuid_v7" ? string : D extends NumberKey ? number : D extends BigIntKey ? bigint : string | number | bigint : string | number | bigint : string | number | bigint;
|
|
63
|
-
type
|
|
64
|
-
where?: Where<T>;
|
|
65
|
-
select?: Select<Schema<T>>;
|
|
66
|
-
sort?: Sort<Schema<T>>;
|
|
67
|
-
limit?: number;
|
|
68
|
-
};
|
|
69
|
-
type With<R extends Dict<Relation>> = {
|
|
70
|
-
[K in keyof R]?: R[K] extends OneRelation<infer S, string> ? WithQuery<S> : R[K] extends ManyRelation<infer S, string> ? WithQuery<S> : never;
|
|
71
|
-
};
|
|
72
|
-
type RelationResult<Rel, Q> = Rel extends OneRelation<infer S, string> ? Q extends {
|
|
73
|
-
select: infer Sel;
|
|
74
|
-
} ? Sel extends Select<Schema<S>> ? Projected<Schema<S>, Sel> | null : Schema<S> | null : Schema<S> | null : Rel extends ManyRelation<infer S, string> ? Q extends {
|
|
75
|
-
select: infer Sel;
|
|
76
|
-
} ? Sel extends Select<Schema<S>> ? Projected<Schema<S>, Sel>[] : Schema<S>[] : Schema<S>[] : never;
|
|
77
|
-
type WithRelations<Base, Relations extends Dict<Relation>, W extends With<Relations> | undefined> = W extends object ? X<Base & {
|
|
78
|
-
[K in keyof W & keyof Relations]: RelationResult<Relations[K], W[K]>;
|
|
79
|
-
}> : Base;
|
|
80
|
-
type Init<S extends StoreInput, R extends Dict<Relation>> = {
|
|
81
|
-
name: string;
|
|
82
|
-
db: DB;
|
|
83
|
-
id?: symbol;
|
|
84
|
-
schema: S;
|
|
85
|
-
relations?: R;
|
|
86
|
-
migrate?: boolean;
|
|
87
|
-
extend?: Dict;
|
|
88
|
-
};
|
|
89
|
+
type ReadSort = Dict<"asc" | "desc">;
|
|
89
90
|
/**
|
|
90
91
|
* Database-backed store.
|
|
91
92
|
*
|
|
@@ -93,22 +94,21 @@ type Init<S extends StoreInput, R extends Dict<Relation>> = {
|
|
|
93
94
|
* document database table/collection. It pairs a Pema schema with a uniform
|
|
94
95
|
* CRUD/query API.
|
|
95
96
|
*/
|
|
96
|
-
export
|
|
97
|
+
export default class Store<T extends StoreInput, N extends string = string> implements Serializable {
|
|
97
98
|
#private;
|
|
99
|
+
[brand]: boolean;
|
|
98
100
|
readonly Schema: Schema<T>;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
};
|
|
101
|
+
static is(x: unknown): x is Store<any, any>;
|
|
102
|
+
constructor(init: Init<T, N>);
|
|
103
|
+
create(): Promise<void>;
|
|
104
|
+
drop(): Promise<void>;
|
|
104
105
|
get infer(): InferRecord<T>;
|
|
105
|
-
get schema():
|
|
106
|
-
get type(): StoreType<ExtractSchema<T>>;
|
|
106
|
+
get schema(): StoreType<ExtractSchema<T>>;
|
|
107
107
|
get migrate(): boolean;
|
|
108
108
|
get id(): symbol;
|
|
109
|
-
get
|
|
109
|
+
get table(): N;
|
|
110
110
|
get pk(): PK;
|
|
111
|
-
get db(): DB
|
|
111
|
+
get db(): DB<unknown>;
|
|
112
112
|
get types(): Types;
|
|
113
113
|
/**
|
|
114
114
|
* Count records
|
|
@@ -128,18 +128,18 @@ export declare class Store<T extends StoreInput, R extends Dict<Relation> = Empt
|
|
|
128
128
|
* - With `with`: augments the record with relations.
|
|
129
129
|
*/
|
|
130
130
|
get(pkv: PKV<T>): Promise<Schema<T>>;
|
|
131
|
-
get<const S extends Select<Schema<T>> | undefined = undefined, const W extends
|
|
131
|
+
get<const S extends Select<Schema<T>> | undefined = undefined, const W extends WithInput<ExtractRelations<T>> | undefined = undefined>(pkv: PKV<T>, options: {
|
|
132
132
|
select?: S;
|
|
133
133
|
with?: W;
|
|
134
|
-
}): Promise<WithRelations<Projected<Schema<T>, S>,
|
|
134
|
+
}): Promise<WithRelations<Projected<Schema<T>, S>, ExtractRelations<T>, W>>;
|
|
135
135
|
/**
|
|
136
136
|
* Try to get a record by primary key.
|
|
137
137
|
*/
|
|
138
138
|
try(pkv: PKV<T>): Promise<Schema<T> | undefined>;
|
|
139
|
-
try<const S extends Select<Schema<T>> | undefined = undefined, const W extends
|
|
139
|
+
try<const S extends Select<Schema<T>> | undefined = undefined, const W extends WithInput<ExtractRelations<T>> | undefined = undefined>(pkv: PKV<T>, options: {
|
|
140
140
|
select?: S;
|
|
141
141
|
with?: W;
|
|
142
|
-
}): Promise<WithRelations<Projected<Schema<T>, S>,
|
|
142
|
+
}): Promise<WithRelations<Projected<Schema<T>, S>, ExtractRelations<T>, W> | undefined>;
|
|
143
143
|
/**
|
|
144
144
|
* Insert a single record.
|
|
145
145
|
*/
|
|
@@ -171,19 +171,19 @@ export declare class Store<T extends StoreInput, R extends Dict<Relation> = Empt
|
|
|
171
171
|
* Find matching records
|
|
172
172
|
*
|
|
173
173
|
*/
|
|
174
|
-
find<const S extends Select<Schema<T>> | undefined = undefined, const W extends
|
|
174
|
+
find<const S extends Select<Schema<T>> | undefined = undefined, const W extends WithInput<ExtractRelations<T>> | undefined = undefined>(options?: {
|
|
175
175
|
where?: Where<T>;
|
|
176
176
|
select?: S;
|
|
177
177
|
sort?: Sort<Schema<T>>;
|
|
178
178
|
limit?: number;
|
|
179
|
+
offset?: number;
|
|
179
180
|
with?: W;
|
|
180
|
-
}): Promise<WithRelations<Projected<Schema<T>, S>,
|
|
181
|
+
}): Promise<WithRelations<Projected<Schema<T>, S>, ExtractRelations<T>, W>[]>;
|
|
181
182
|
toJSON(): {
|
|
182
183
|
type: "object";
|
|
183
184
|
properties: Dict<import("pema").Serialized>;
|
|
184
185
|
};
|
|
185
186
|
extend<A extends Dict>(extensor: (This: this) => A): this & A;
|
|
186
187
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
//# sourceMappingURL=store.d.ts.map
|
|
188
|
+
export {};
|
|
189
|
+
//# sourceMappingURL=Store.d.ts.map
|