evikit 2.9.2 → 2.10.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/README.md +11 -19
- package/db.d.ts +255 -255
- package/index.d.ts +19 -1
- package/index.js +41 -7
- package/package.json +1 -1
- package/sqlite.js +576 -576
package/README.md
CHANGED
|
@@ -180,7 +180,7 @@ export function ErrorPage({ children, error }) {
|
|
|
180
180
|
useTitle(status);
|
|
181
181
|
|
|
182
182
|
return main(
|
|
183
|
-
|
|
183
|
+
{ id: "main" },
|
|
184
184
|
p({ class: "nav" }, a({ href: "/" }, i18n.gettext("Questions"))),
|
|
185
185
|
h1({ class: "title" }, status),
|
|
186
186
|
children,
|
|
@@ -221,9 +221,7 @@ export function api() {
|
|
|
221
221
|
Add a Preact router at `src/app.js` (uncomment the routes one-by-one when we add them later):
|
|
222
222
|
|
|
223
223
|
```js
|
|
224
|
-
import {
|
|
225
|
-
import { h } from "preact";
|
|
226
|
-
import { Route } from "preact-iso";
|
|
224
|
+
import { route, ssr } from "evikit";
|
|
227
225
|
|
|
228
226
|
import { acceptLanguages } from "./lib/index.js";
|
|
229
227
|
import { ErrorPage } from "./routes/error.js";
|
|
@@ -232,21 +230,11 @@ import { ErrorPage } from "./routes/error.js";
|
|
|
232
230
|
|
|
233
231
|
acceptLanguages();
|
|
234
232
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return h(
|
|
241
|
-
Router,
|
|
242
|
-
props,
|
|
243
|
-
// h(Route, { component: HomePage, path: "/" }),
|
|
244
|
-
// h(Route, { component: QuestionIdPage, path: "/question/:id" }),
|
|
245
|
-
h(Route, { component: ErrorPage, default: true }),
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
hydrate(App, "#app");
|
|
233
|
+
export const prerender = ssr(
|
|
234
|
+
{ ErrorPage },
|
|
235
|
+
// route("/", HomePage),
|
|
236
|
+
// route("/question/:id", QuestionIdPage),
|
|
237
|
+
);
|
|
250
238
|
```
|
|
251
239
|
|
|
252
240
|
#### HTML entry point
|
|
@@ -386,6 +374,8 @@ export const HomeGet = {
|
|
|
386
374
|
};
|
|
387
375
|
```
|
|
388
376
|
|
|
377
|
+
> 😉 Note: for live refresh to know when data changes, use columns from `schema` in `outputs`, instead of writing `string()` or `number()` anew.
|
|
378
|
+
|
|
389
379
|
Code the API server endpoint in `src/routes/api/server.js`:
|
|
390
380
|
|
|
391
381
|
```js
|
|
@@ -523,6 +513,8 @@ export function QuestionIdPage() {
|
|
|
523
513
|
}
|
|
524
514
|
|
|
525
515
|
return main(
|
|
516
|
+
{ id: "main" },
|
|
517
|
+
|
|
526
518
|
h1({ class: "title" }, title),
|
|
527
519
|
|
|
528
520
|
// VOTE_FORM: replace with form view from the "Vote for choice" section.
|
package/db.d.ts
CHANGED
|
@@ -1,255 +1,255 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
InferInput,
|
|
3
|
-
InferMetadata,
|
|
4
|
-
InferOutput,
|
|
5
|
-
MetadataAction,
|
|
6
|
-
ObjectSchema,
|
|
7
|
-
} from "valibot";
|
|
8
|
-
|
|
9
|
-
export type Db<
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
-
Schema extends Record<string, ObjectSchema<any, any>>,
|
|
12
|
-
R extends Relations<Schema> = Relations<Schema>,
|
|
13
|
-
F extends Flatten<Schema> = Flatten<Schema>,
|
|
14
|
-
> = {
|
|
15
|
-
[Table in keyof R]: Table extends keyof F & keyof Schema & string
|
|
16
|
-
? {
|
|
17
|
-
delete(where: Where<Schema, Table>): void;
|
|
18
|
-
|
|
19
|
-
select<
|
|
20
|
-
W extends Partial<Join<R, Table>> & { where?: Where<Schema, Table> },
|
|
21
|
-
>(
|
|
22
|
-
props?: W,
|
|
23
|
-
): Select<Schema, R, F, Table, W>[];
|
|
24
|
-
|
|
25
|
-
update(query: {
|
|
26
|
-
set: Partial<InferOutput<Schema[Table]>>;
|
|
27
|
-
where: Where<Schema, Table>;
|
|
28
|
-
}): void;
|
|
29
|
-
|
|
30
|
-
upsert(
|
|
31
|
-
...values: InferInput<Schema[Table]>[]
|
|
32
|
-
): InferOutput<Schema[Table]>[];
|
|
33
|
-
}
|
|
34
|
-
: never;
|
|
35
|
-
} & {
|
|
36
|
-
schema: Schema;
|
|
37
|
-
subscribe(onMessage: ({ table }: { table: string }) => void): () => void;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export type Flatten<
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
-
Schema extends Record<string, ObjectSchema<any, any>>,
|
|
43
|
-
R extends Relations<Schema> = Relations<Schema>,
|
|
44
|
-
> = {
|
|
45
|
-
[Self in keyof R]: Self extends string
|
|
46
|
-
? UnionToIntersection<
|
|
47
|
-
{
|
|
48
|
-
[Own in keyof R[Self]]: Own extends string
|
|
49
|
-
? {
|
|
50
|
-
[Other in keyof R[Self][Own]]: Other extends string
|
|
51
|
-
? R[Self][Own][Other] extends Record<string, { name: string }>
|
|
52
|
-
? {
|
|
53
|
-
[
|
|
54
|
-
Its in keyof R[Self][Own][Other] as R[Self][Own][Other][Its]["name"]
|
|
55
|
-
]: Its extends string
|
|
56
|
-
? R[Self][Own][Other][Its]
|
|
57
|
-
: never;
|
|
58
|
-
}
|
|
59
|
-
: never
|
|
60
|
-
: never;
|
|
61
|
-
}[keyof R[Self][Own]]
|
|
62
|
-
: never;
|
|
63
|
-
}[keyof R[Self]]
|
|
64
|
-
>
|
|
65
|
-
: never;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export type Join<Relations, Self extends keyof Relations> = UnionToIntersection<
|
|
69
|
-
{
|
|
70
|
-
[Own in keyof Relations[Self]]: Own extends string
|
|
71
|
-
? {
|
|
72
|
-
[Other in keyof Relations[Self][Own]]: Other extends keyof Relations
|
|
73
|
-
? {
|
|
74
|
-
[Its in keyof Relations[Self][Own][Other]]: Its extends string
|
|
75
|
-
? Relations[Self][Own][Other] extends Record<
|
|
76
|
-
string,
|
|
77
|
-
{ name: string }
|
|
78
|
-
>
|
|
79
|
-
? {
|
|
80
|
-
// Turning this into partial record would cause infinite depth.
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
|
|
82
|
-
with: {
|
|
83
|
-
[K in Relations[Self][Own][Other][Its]["name"]]?:
|
|
84
|
-
Join<Relations, Other> | true;
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
: never
|
|
88
|
-
: never;
|
|
89
|
-
}[keyof Relations[Self][Own][Other]]
|
|
90
|
-
: never;
|
|
91
|
-
}[keyof Relations[Self][Own]]
|
|
92
|
-
: never;
|
|
93
|
-
}[keyof Relations[Self]]
|
|
94
|
-
>;
|
|
95
|
-
|
|
96
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
|
-
export type Relations<Schema extends Record<string, ObjectSchema<any, any>>> = {
|
|
98
|
-
[Self in keyof Schema]: Self extends string
|
|
99
|
-
? OmitExtendsRecordUndefined<{
|
|
100
|
-
[Own in keyof Schema[Self]["entries"]]: Own extends string
|
|
101
|
-
? OmitExtendsRecordUndefined<{
|
|
102
|
-
[Other in keyof Schema]: Other extends string
|
|
103
|
-
? OmitExtendsUndefined<{
|
|
104
|
-
[Its in keyof Schema[Other]["entries"]]: Its extends string
|
|
105
|
-
? InferMetadata<Schema[Self]["entries"][Own]> extends {
|
|
106
|
-
key: Schema[Other]["entries"][Its];
|
|
107
|
-
references: Schema[Other];
|
|
108
|
-
}
|
|
109
|
-
? Schema[Other] extends InferMetadata<
|
|
110
|
-
Schema[Self]["entries"][Own]
|
|
111
|
-
>["references"]
|
|
112
|
-
? Schema[Other]["entries"][Its] extends InferMetadata<
|
|
113
|
-
Schema[Self]["entries"][Own]
|
|
114
|
-
>["key"]
|
|
115
|
-
? {
|
|
116
|
-
Its: Its;
|
|
117
|
-
name: Rewrite<Self, Own, Other, Its>;
|
|
118
|
-
Other: Other;
|
|
119
|
-
Own: Own;
|
|
120
|
-
type: "references";
|
|
121
|
-
}
|
|
122
|
-
: undefined
|
|
123
|
-
: undefined
|
|
124
|
-
: InferMetadata<Schema[Other]["entries"][Its]> extends {
|
|
125
|
-
key: Schema[Self]["entries"][Own];
|
|
126
|
-
references: Schema[Self];
|
|
127
|
-
}
|
|
128
|
-
? Schema[Self] extends InferMetadata<
|
|
129
|
-
Schema[Other]["entries"][Its]
|
|
130
|
-
>["references"]
|
|
131
|
-
? Schema[Self]["entries"][Own] extends InferMetadata<
|
|
132
|
-
Schema[Other]["entries"][Its]
|
|
133
|
-
>["key"]
|
|
134
|
-
? {
|
|
135
|
-
Its: Its;
|
|
136
|
-
name: Rewrite<Self, Own, Other, Its>;
|
|
137
|
-
Other: Other;
|
|
138
|
-
Own: Own;
|
|
139
|
-
type: "referencedBy";
|
|
140
|
-
}
|
|
141
|
-
: undefined
|
|
142
|
-
: undefined
|
|
143
|
-
: undefined
|
|
144
|
-
: undefined;
|
|
145
|
-
}>
|
|
146
|
-
: undefined;
|
|
147
|
-
}>
|
|
148
|
-
: undefined;
|
|
149
|
-
}>
|
|
150
|
-
: undefined;
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
export type Where<
|
|
154
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
155
|
-
Schema extends Record<string, ObjectSchema<any, any>>,
|
|
156
|
-
Table extends keyof Schema,
|
|
157
|
-
> = {
|
|
158
|
-
[K in keyof Schema[Table]["entries"]]?:
|
|
159
|
-
| InferOutput<Schema[Table]["entries"][K]>
|
|
160
|
-
| InferOutput<Schema[Table]["entries"][K]>[]
|
|
161
|
-
| Partial<
|
|
162
|
-
Record<
|
|
163
|
-
"gt" | "gte" | "lt" | "lte" | "not",
|
|
164
|
-
InferOutput<Schema[Table]["entries"][K]>
|
|
165
|
-
>
|
|
166
|
-
>;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
type OmitExtends<T, U> = {
|
|
170
|
-
[K in keyof T as T[K] extends U ? never : K]: T[K];
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
type OmitExtendsRecordUndefined<T> = OmitExtends<T, Record<string, undefined>>;
|
|
174
|
-
|
|
175
|
-
type OmitExtendsUndefined<T> = OmitExtends<T, undefined>;
|
|
176
|
-
|
|
177
|
-
type Rewrite<
|
|
178
|
-
Self extends string,
|
|
179
|
-
Own extends string,
|
|
180
|
-
Other extends string,
|
|
181
|
-
Its extends string,
|
|
182
|
-
> =
|
|
183
|
-
// Image.id, Question.imageId -> Image.Question.
|
|
184
|
-
Its extends `${Uncapitalize<Self>}${Capitalize<Own>}`
|
|
185
|
-
? Other
|
|
186
|
-
: // Question.quizId, Quiz.id -> Question.Quiz.
|
|
187
|
-
Own extends `${Uncapitalize<Other>}${Capitalize<Its>}`
|
|
188
|
-
? Other
|
|
189
|
-
: // Quiz.coverId, Image.id -> Quiz.cover.
|
|
190
|
-
Own extends `${infer R}${Capitalize<Its>}`
|
|
191
|
-
? R
|
|
192
|
-
: // Image.id, Quiz.coverId -> Image.CoverQuiz.
|
|
193
|
-
Its extends `${infer R}${Capitalize<Own>}`
|
|
194
|
-
? `${Capitalize<R>}${Other}`
|
|
195
|
-
: never;
|
|
196
|
-
|
|
197
|
-
type Select<
|
|
198
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
199
|
-
Schema extends Record<string, ObjectSchema<any, any>>,
|
|
200
|
-
R extends Relations<Schema> = Relations<Schema>,
|
|
201
|
-
F extends Flatten<Schema> = Flatten<Schema>,
|
|
202
|
-
Table extends keyof F & keyof Schema = keyof F & keyof Schema,
|
|
203
|
-
W extends Join<R, Table> = Join<R, Table>,
|
|
204
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
205
|
-
> = W extends { with: any }
|
|
206
|
-
? InferOutput<Schema[Table]> & {
|
|
207
|
-
[K in keyof W["with"]]: K extends keyof F[Table]
|
|
208
|
-
? F[Table][K] extends {
|
|
209
|
-
Other: keyof F & keyof Schema;
|
|
210
|
-
type: "referencedBy";
|
|
211
|
-
}
|
|
212
|
-
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
213
|
-
(W["with"][K] extends { with: any }
|
|
214
|
-
? Select<Schema, R, F, F[Table][K]["Other"], W["with"][K]>
|
|
215
|
-
: InferOutput<Schema[F[Table][K]["Other"]]>)[]
|
|
216
|
-
: F[Table][K] extends {
|
|
217
|
-
Other: keyof F & keyof Schema;
|
|
218
|
-
type: "references";
|
|
219
|
-
}
|
|
220
|
-
? | undefined
|
|
221
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
222
|
-
| (W["with"][K] extends { with: any }
|
|
223
|
-
? Select<Schema, R, F, F[Table][K]["Other"], W["with"][K]>
|
|
224
|
-
: InferOutput<Schema[F[Table][K]["Other"]]>)
|
|
225
|
-
: never
|
|
226
|
-
: never;
|
|
227
|
-
}
|
|
228
|
-
: InferOutput<Schema[Table]>;
|
|
229
|
-
|
|
230
|
-
// https://www.geeksforgeeks.org/typescript/union-type-to-intersection-type-in-typescript/
|
|
231
|
-
type UnionToIntersection<U> = (
|
|
232
|
-
U extends object ? (k: U) => void : never
|
|
233
|
-
) extends (k: infer I) => void
|
|
234
|
-
? I
|
|
235
|
-
: never;
|
|
236
|
-
|
|
237
|
-
export function flatten<
|
|
238
|
-
Schema extends Record<string, ObjectSchema<any, any>>, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
239
|
-
>(relations: Relations<Schema>): Flatten<Schema>;
|
|
240
|
-
|
|
241
|
-
export function primary<T>(): MetadataAction<T, { primary: true }>;
|
|
242
|
-
|
|
243
|
-
export function references<
|
|
244
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
245
|
-
R extends { entries: any },
|
|
246
|
-
K extends keyof R["entries"],
|
|
247
|
-
T,
|
|
248
|
-
>(
|
|
249
|
-
references: R,
|
|
250
|
-
key: K,
|
|
251
|
-
): MetadataAction<T, { key: R["entries"][K]; references: R }>;
|
|
252
|
-
|
|
253
|
-
export function relations<
|
|
254
|
-
Schema extends Record<string, ObjectSchema<any, any>>, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
255
|
-
>(schema: Schema): Relations<Schema>;
|
|
1
|
+
import type {
|
|
2
|
+
InferInput,
|
|
3
|
+
InferMetadata,
|
|
4
|
+
InferOutput,
|
|
5
|
+
MetadataAction,
|
|
6
|
+
ObjectSchema,
|
|
7
|
+
} from "valibot";
|
|
8
|
+
|
|
9
|
+
export type Db<
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
Schema extends Record<string, ObjectSchema<any, any>>,
|
|
12
|
+
R extends Relations<Schema> = Relations<Schema>,
|
|
13
|
+
F extends Flatten<Schema> = Flatten<Schema>,
|
|
14
|
+
> = {
|
|
15
|
+
[Table in keyof R]: Table extends keyof F & keyof Schema & string
|
|
16
|
+
? {
|
|
17
|
+
delete(where: Where<Schema, Table>): void;
|
|
18
|
+
|
|
19
|
+
select<
|
|
20
|
+
W extends Partial<Join<R, Table>> & { where?: Where<Schema, Table> },
|
|
21
|
+
>(
|
|
22
|
+
props?: W,
|
|
23
|
+
): Select<Schema, R, F, Table, W>[];
|
|
24
|
+
|
|
25
|
+
update(query: {
|
|
26
|
+
set: Partial<InferOutput<Schema[Table]>>;
|
|
27
|
+
where: Where<Schema, Table>;
|
|
28
|
+
}): void;
|
|
29
|
+
|
|
30
|
+
upsert(
|
|
31
|
+
...values: InferInput<Schema[Table]>[]
|
|
32
|
+
): InferOutput<Schema[Table]>[];
|
|
33
|
+
}
|
|
34
|
+
: never;
|
|
35
|
+
} & {
|
|
36
|
+
schema: Schema;
|
|
37
|
+
subscribe(onMessage: ({ table }: { table: string }) => void): () => void;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type Flatten<
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
Schema extends Record<string, ObjectSchema<any, any>>,
|
|
43
|
+
R extends Relations<Schema> = Relations<Schema>,
|
|
44
|
+
> = {
|
|
45
|
+
[Self in keyof R]: Self extends string
|
|
46
|
+
? UnionToIntersection<
|
|
47
|
+
{
|
|
48
|
+
[Own in keyof R[Self]]: Own extends string
|
|
49
|
+
? {
|
|
50
|
+
[Other in keyof R[Self][Own]]: Other extends string
|
|
51
|
+
? R[Self][Own][Other] extends Record<string, { name: string }>
|
|
52
|
+
? {
|
|
53
|
+
[
|
|
54
|
+
Its in keyof R[Self][Own][Other] as R[Self][Own][Other][Its]["name"]
|
|
55
|
+
]: Its extends string
|
|
56
|
+
? R[Self][Own][Other][Its]
|
|
57
|
+
: never;
|
|
58
|
+
}
|
|
59
|
+
: never
|
|
60
|
+
: never;
|
|
61
|
+
}[keyof R[Self][Own]]
|
|
62
|
+
: never;
|
|
63
|
+
}[keyof R[Self]]
|
|
64
|
+
>
|
|
65
|
+
: never;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type Join<Relations, Self extends keyof Relations> = UnionToIntersection<
|
|
69
|
+
{
|
|
70
|
+
[Own in keyof Relations[Self]]: Own extends string
|
|
71
|
+
? {
|
|
72
|
+
[Other in keyof Relations[Self][Own]]: Other extends keyof Relations
|
|
73
|
+
? {
|
|
74
|
+
[Its in keyof Relations[Self][Own][Other]]: Its extends string
|
|
75
|
+
? Relations[Self][Own][Other] extends Record<
|
|
76
|
+
string,
|
|
77
|
+
{ name: string }
|
|
78
|
+
>
|
|
79
|
+
? {
|
|
80
|
+
// Turning this into partial record would cause infinite depth.
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
|
|
82
|
+
with: {
|
|
83
|
+
[K in Relations[Self][Own][Other][Its]["name"]]?:
|
|
84
|
+
Join<Relations, Other> | true;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
: never
|
|
88
|
+
: never;
|
|
89
|
+
}[keyof Relations[Self][Own][Other]]
|
|
90
|
+
: never;
|
|
91
|
+
}[keyof Relations[Self][Own]]
|
|
92
|
+
: never;
|
|
93
|
+
}[keyof Relations[Self]]
|
|
94
|
+
>;
|
|
95
|
+
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
|
+
export type Relations<Schema extends Record<string, ObjectSchema<any, any>>> = {
|
|
98
|
+
[Self in keyof Schema]: Self extends string
|
|
99
|
+
? OmitExtendsRecordUndefined<{
|
|
100
|
+
[Own in keyof Schema[Self]["entries"]]: Own extends string
|
|
101
|
+
? OmitExtendsRecordUndefined<{
|
|
102
|
+
[Other in keyof Schema]: Other extends string
|
|
103
|
+
? OmitExtendsUndefined<{
|
|
104
|
+
[Its in keyof Schema[Other]["entries"]]: Its extends string
|
|
105
|
+
? InferMetadata<Schema[Self]["entries"][Own]> extends {
|
|
106
|
+
key: Schema[Other]["entries"][Its];
|
|
107
|
+
references: Schema[Other];
|
|
108
|
+
}
|
|
109
|
+
? Schema[Other] extends InferMetadata<
|
|
110
|
+
Schema[Self]["entries"][Own]
|
|
111
|
+
>["references"]
|
|
112
|
+
? Schema[Other]["entries"][Its] extends InferMetadata<
|
|
113
|
+
Schema[Self]["entries"][Own]
|
|
114
|
+
>["key"]
|
|
115
|
+
? {
|
|
116
|
+
Its: Its;
|
|
117
|
+
name: Rewrite<Self, Own, Other, Its>;
|
|
118
|
+
Other: Other;
|
|
119
|
+
Own: Own;
|
|
120
|
+
type: "references";
|
|
121
|
+
}
|
|
122
|
+
: undefined
|
|
123
|
+
: undefined
|
|
124
|
+
: InferMetadata<Schema[Other]["entries"][Its]> extends {
|
|
125
|
+
key: Schema[Self]["entries"][Own];
|
|
126
|
+
references: Schema[Self];
|
|
127
|
+
}
|
|
128
|
+
? Schema[Self] extends InferMetadata<
|
|
129
|
+
Schema[Other]["entries"][Its]
|
|
130
|
+
>["references"]
|
|
131
|
+
? Schema[Self]["entries"][Own] extends InferMetadata<
|
|
132
|
+
Schema[Other]["entries"][Its]
|
|
133
|
+
>["key"]
|
|
134
|
+
? {
|
|
135
|
+
Its: Its;
|
|
136
|
+
name: Rewrite<Self, Own, Other, Its>;
|
|
137
|
+
Other: Other;
|
|
138
|
+
Own: Own;
|
|
139
|
+
type: "referencedBy";
|
|
140
|
+
}
|
|
141
|
+
: undefined
|
|
142
|
+
: undefined
|
|
143
|
+
: undefined
|
|
144
|
+
: undefined;
|
|
145
|
+
}>
|
|
146
|
+
: undefined;
|
|
147
|
+
}>
|
|
148
|
+
: undefined;
|
|
149
|
+
}>
|
|
150
|
+
: undefined;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export type Where<
|
|
154
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
155
|
+
Schema extends Record<string, ObjectSchema<any, any>>,
|
|
156
|
+
Table extends keyof Schema,
|
|
157
|
+
> = {
|
|
158
|
+
[K in keyof Schema[Table]["entries"]]?:
|
|
159
|
+
| InferOutput<Schema[Table]["entries"][K]>
|
|
160
|
+
| InferOutput<Schema[Table]["entries"][K]>[]
|
|
161
|
+
| Partial<
|
|
162
|
+
Record<
|
|
163
|
+
"gt" | "gte" | "lt" | "lte" | "not",
|
|
164
|
+
InferOutput<Schema[Table]["entries"][K]>
|
|
165
|
+
>
|
|
166
|
+
>;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
type OmitExtends<T, U> = {
|
|
170
|
+
[K in keyof T as T[K] extends U ? never : K]: T[K];
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
type OmitExtendsRecordUndefined<T> = OmitExtends<T, Record<string, undefined>>;
|
|
174
|
+
|
|
175
|
+
type OmitExtendsUndefined<T> = OmitExtends<T, undefined>;
|
|
176
|
+
|
|
177
|
+
type Rewrite<
|
|
178
|
+
Self extends string,
|
|
179
|
+
Own extends string,
|
|
180
|
+
Other extends string,
|
|
181
|
+
Its extends string,
|
|
182
|
+
> =
|
|
183
|
+
// Image.id, Question.imageId -> Image.Question.
|
|
184
|
+
Its extends `${Uncapitalize<Self>}${Capitalize<Own>}`
|
|
185
|
+
? Other
|
|
186
|
+
: // Question.quizId, Quiz.id -> Question.Quiz.
|
|
187
|
+
Own extends `${Uncapitalize<Other>}${Capitalize<Its>}`
|
|
188
|
+
? Other
|
|
189
|
+
: // Quiz.coverId, Image.id -> Quiz.cover.
|
|
190
|
+
Own extends `${infer R}${Capitalize<Its>}`
|
|
191
|
+
? R
|
|
192
|
+
: // Image.id, Quiz.coverId -> Image.CoverQuiz.
|
|
193
|
+
Its extends `${infer R}${Capitalize<Own>}`
|
|
194
|
+
? `${Capitalize<R>}${Other}`
|
|
195
|
+
: never;
|
|
196
|
+
|
|
197
|
+
type Select<
|
|
198
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
199
|
+
Schema extends Record<string, ObjectSchema<any, any>>,
|
|
200
|
+
R extends Relations<Schema> = Relations<Schema>,
|
|
201
|
+
F extends Flatten<Schema> = Flatten<Schema>,
|
|
202
|
+
Table extends keyof F & keyof Schema = keyof F & keyof Schema,
|
|
203
|
+
W extends Join<R, Table> = Join<R, Table>,
|
|
204
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
205
|
+
> = W extends { with: any }
|
|
206
|
+
? InferOutput<Schema[Table]> & {
|
|
207
|
+
[K in keyof W["with"]]: K extends keyof F[Table]
|
|
208
|
+
? F[Table][K] extends {
|
|
209
|
+
Other: keyof F & keyof Schema;
|
|
210
|
+
type: "referencedBy";
|
|
211
|
+
}
|
|
212
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
213
|
+
(W["with"][K] extends { with: any }
|
|
214
|
+
? Select<Schema, R, F, F[Table][K]["Other"], W["with"][K]>
|
|
215
|
+
: InferOutput<Schema[F[Table][K]["Other"]]>)[]
|
|
216
|
+
: F[Table][K] extends {
|
|
217
|
+
Other: keyof F & keyof Schema;
|
|
218
|
+
type: "references";
|
|
219
|
+
}
|
|
220
|
+
? | undefined
|
|
221
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
222
|
+
| (W["with"][K] extends { with: any }
|
|
223
|
+
? Select<Schema, R, F, F[Table][K]["Other"], W["with"][K]>
|
|
224
|
+
: InferOutput<Schema[F[Table][K]["Other"]]>)
|
|
225
|
+
: never
|
|
226
|
+
: never;
|
|
227
|
+
}
|
|
228
|
+
: InferOutput<Schema[Table]>;
|
|
229
|
+
|
|
230
|
+
// https://www.geeksforgeeks.org/typescript/union-type-to-intersection-type-in-typescript/
|
|
231
|
+
type UnionToIntersection<U> = (
|
|
232
|
+
U extends object ? (k: U) => void : never
|
|
233
|
+
) extends (k: infer I) => void
|
|
234
|
+
? I
|
|
235
|
+
: never;
|
|
236
|
+
|
|
237
|
+
export function flatten<
|
|
238
|
+
Schema extends Record<string, ObjectSchema<any, any>>, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
239
|
+
>(relations: Relations<Schema>): Flatten<Schema>;
|
|
240
|
+
|
|
241
|
+
export function primary<T>(): MetadataAction<T, { primary: true }>;
|
|
242
|
+
|
|
243
|
+
export function references<
|
|
244
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
245
|
+
R extends { entries: any },
|
|
246
|
+
K extends keyof R["entries"],
|
|
247
|
+
T,
|
|
248
|
+
>(
|
|
249
|
+
references: R,
|
|
250
|
+
key: K,
|
|
251
|
+
): MetadataAction<T, { key: R["entries"][K]; references: R }>;
|
|
252
|
+
|
|
253
|
+
export function relations<
|
|
254
|
+
Schema extends Record<string, ObjectSchema<any, any>>, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
255
|
+
>(schema: Schema): Relations<Schema>;
|
package/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface QueryState {
|
|
|
14
14
|
data: any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
15
15
|
dataUpdatedAt: number;
|
|
16
16
|
error: null | unknown;
|
|
17
|
+
fromEventSource: boolean;
|
|
17
18
|
isInvalidated: boolean;
|
|
18
19
|
status: "error" | "loading" | "success";
|
|
19
20
|
}
|
|
@@ -61,6 +62,7 @@ export function dehydrate(
|
|
|
61
62
|
|
|
62
63
|
export function getI18n(...langs: string[]): Promise<i18n.Gettext>;
|
|
63
64
|
|
|
65
|
+
/** @deprecated */
|
|
64
66
|
export function hydrate(
|
|
65
67
|
App: (props: {
|
|
66
68
|
dehydratedState?: DehydratedState | undefined;
|
|
@@ -69,6 +71,12 @@ export function hydrate(
|
|
|
69
71
|
renderTarget: string,
|
|
70
72
|
): Promise<void>;
|
|
71
73
|
|
|
74
|
+
export function route(
|
|
75
|
+
path: string,
|
|
76
|
+
component: () => VNode<any>, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
77
|
+
): { component: typeof component; path: string };
|
|
78
|
+
|
|
79
|
+
/** @deprecated */
|
|
72
80
|
export function Router({
|
|
73
81
|
children,
|
|
74
82
|
dehydratedState,
|
|
@@ -80,8 +88,18 @@ export function Router({
|
|
|
80
88
|
}): VNode<any>; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
81
89
|
|
|
82
90
|
/** @deprecated */
|
|
83
|
-
export function ssr(App: SsrApp): (props: SsrProps) => Promise<SsrResponse>;
|
|
84
91
|
export function ssr(App: SsrApp, props: SsrProps): Promise<SsrResponse>;
|
|
92
|
+
/** @deprecated */
|
|
93
|
+
export function ssr(App: SsrApp): (props: SsrProps) => Promise<SsrResponse>;
|
|
94
|
+
export function ssr(
|
|
95
|
+
props: {
|
|
96
|
+
ErrorPage: (props: {
|
|
97
|
+
children?: import("preact").ComponentChildren;
|
|
98
|
+
error?: unknown;
|
|
99
|
+
}) => VNode<any>; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
100
|
+
},
|
|
101
|
+
...routes: ReturnType<typeof route>[]
|
|
102
|
+
): (props: SsrProps) => Promise<SsrResponse>;
|
|
85
103
|
|
|
86
104
|
export function useI18n(): i18n.Gettext;
|
|
87
105
|
|