evikit 2.8.1 → 2.9.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 +7 -12
- package/db.d.ts +19 -17
- package/index.d.ts +167 -158
- package/index.js +236 -231
- package/package.json +1 -1
- package/server.js +668 -668
- package/sqlite.js +59 -54
- package/use-api.d.ts +13 -13
- package/use-api.js +119 -119
package/README.md
CHANGED
|
@@ -232,12 +232,9 @@ import { ErrorPage } from "./routes/error.js";
|
|
|
232
232
|
|
|
233
233
|
acceptLanguages();
|
|
234
234
|
|
|
235
|
-
|
|
236
|
-
export async function prerender(data) {
|
|
237
|
-
return await ssr(App, data);
|
|
238
|
-
}
|
|
235
|
+
export const prerender = ssr(App);
|
|
239
236
|
|
|
240
|
-
/** @
|
|
237
|
+
/** @type {import("evikit").SsrApp} */
|
|
241
238
|
function App({ dehydratedState, i18n }) {
|
|
242
239
|
return h(
|
|
243
240
|
Router,
|
|
@@ -484,12 +481,12 @@ import { QuestionIdGet } from "./types.js";
|
|
|
484
481
|
export const QuestionIdServer = {
|
|
485
482
|
get: endpoint(QuestionIdGet, async ({ input }) => {
|
|
486
483
|
const i18n = await getI18n(input.lang);
|
|
487
|
-
const
|
|
484
|
+
const [question] = db.Question.select({
|
|
488
485
|
with: { Choice: true },
|
|
486
|
+
where: { id: input.id },
|
|
489
487
|
});
|
|
490
488
|
// It maps join results to objects, for example you can get:
|
|
491
|
-
//
|
|
492
|
-
const question = Question.find(({ id }) => id == input.id);
|
|
489
|
+
// question?.Choice[0]?.text
|
|
493
490
|
if (!question) {
|
|
494
491
|
return text(i18n.gettext("Question does not exist"), 404);
|
|
495
492
|
}
|
|
@@ -567,8 +564,7 @@ export const ChoiceServer = {
|
|
|
567
564
|
post: endpoint(ChoicePost, async ({ input }) => {
|
|
568
565
|
const i18n = await getI18n(input.lang);
|
|
569
566
|
|
|
570
|
-
const
|
|
571
|
-
const question = Question.find(({ id }) => id == input.questionId);
|
|
567
|
+
const [question] = db.Question.select({ where: { id: input.questionId } });
|
|
572
568
|
if (!question) {
|
|
573
569
|
return text(i18n.gettext("Question does not exist"), 400);
|
|
574
570
|
}
|
|
@@ -649,8 +645,7 @@ export const VoteServer = {
|
|
|
649
645
|
post: endpoint(VotePost, async ({ input }) => {
|
|
650
646
|
const i18n = await getI18n(input.lang);
|
|
651
647
|
|
|
652
|
-
const
|
|
653
|
-
const choice = Choice.find(({ id }) => id == input.choiceId);
|
|
648
|
+
const [choice] = db.Choice.select({ where: { id: input.choiceId } });
|
|
654
649
|
if (!choice) {
|
|
655
650
|
return text(i18n.gettext("You didn't select a choice"), 400);
|
|
656
651
|
}
|
package/db.d.ts
CHANGED
|
@@ -14,31 +14,17 @@ export type Db<
|
|
|
14
14
|
> = {
|
|
15
15
|
[Table in keyof R]: Table extends keyof F & keyof Schema & string
|
|
16
16
|
? {
|
|
17
|
-
delete(where:
|
|
18
|
-
[K in keyof Schema[Table]["entries"]]?:
|
|
19
|
-
| InferOutput<Schema[Table]["entries"][K]>
|
|
20
|
-
| InferOutput<Schema[Table]["entries"][K]>[];
|
|
21
|
-
}): void;
|
|
17
|
+
delete(where: Where<Schema, Table>): void;
|
|
22
18
|
|
|
23
19
|
select<
|
|
24
|
-
W extends Partial<Join<R, Table>> & {
|
|
25
|
-
where?: {
|
|
26
|
-
[K in keyof Schema[Table]["entries"]]?:
|
|
27
|
-
| InferOutput<Schema[Table]["entries"][K]>
|
|
28
|
-
| InferOutput<Schema[Table]["entries"][K]>[];
|
|
29
|
-
};
|
|
30
|
-
},
|
|
20
|
+
W extends Partial<Join<R, Table>> & { where?: Where<Schema, Table> },
|
|
31
21
|
>(
|
|
32
22
|
props?: W,
|
|
33
23
|
): Select<Schema, R, F, Table, W>[];
|
|
34
24
|
|
|
35
25
|
update(query: {
|
|
36
26
|
set: Partial<InferOutput<Schema[Table]>>;
|
|
37
|
-
where:
|
|
38
|
-
[K in keyof Schema[Table]["entries"]]?:
|
|
39
|
-
| InferOutput<Schema[Table]["entries"][K]>
|
|
40
|
-
| InferOutput<Schema[Table]["entries"][K]>[];
|
|
41
|
-
};
|
|
27
|
+
where: Where<Schema, Table>;
|
|
42
28
|
}): void;
|
|
43
29
|
|
|
44
30
|
upsert(
|
|
@@ -164,6 +150,22 @@ export type Relations<Schema extends Record<string, ObjectSchema<any, any>>> = {
|
|
|
164
150
|
: undefined;
|
|
165
151
|
};
|
|
166
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
|
+
|
|
167
169
|
type OmitExtends<T, U> = {
|
|
168
170
|
[K in keyof T as T[K] extends U ? never : K]: T[K];
|
|
169
171
|
};
|
package/index.d.ts
CHANGED
|
@@ -1,158 +1,167 @@
|
|
|
1
|
-
import type { ClassAttributes, ComponentChildren, JSX, VNode } from "preact";
|
|
2
|
-
|
|
3
|
-
import i18n from "gettext.js";
|
|
4
|
-
|
|
5
|
-
import { flatten, primary, references, relations } from "./db.js";
|
|
6
|
-
import { useApi } from "./use-api.js";
|
|
7
|
-
import { useEnhance } from "./use-enhance.js";
|
|
8
|
-
|
|
9
|
-
export interface DehydratedState {
|
|
10
|
-
queries: { queryHash: string; state: QueryState }[];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface QueryState {
|
|
14
|
-
data: any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
15
|
-
dataUpdatedAt: number;
|
|
16
|
-
error: null | unknown;
|
|
17
|
-
isInvalidated: boolean;
|
|
18
|
-
status: "error" | "loading" | "success";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
) => VNode<
|
|
25
|
-
|
|
26
|
-
export
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
export function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
export
|
|
87
|
-
|
|
88
|
-
export
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
export
|
|
93
|
-
|
|
94
|
-
export const
|
|
95
|
-
export const
|
|
96
|
-
export const
|
|
97
|
-
export const
|
|
98
|
-
export const
|
|
99
|
-
export const
|
|
100
|
-
export const
|
|
101
|
-
export const
|
|
102
|
-
export const
|
|
103
|
-
export const
|
|
104
|
-
export const
|
|
105
|
-
export const
|
|
106
|
-
export const
|
|
107
|
-
export const
|
|
108
|
-
export const
|
|
109
|
-
export const
|
|
110
|
-
export const
|
|
111
|
-
export const
|
|
112
|
-
export const
|
|
113
|
-
export const
|
|
114
|
-
export const
|
|
115
|
-
export const
|
|
116
|
-
export const
|
|
117
|
-
export const
|
|
118
|
-
export const
|
|
119
|
-
export const
|
|
120
|
-
export const
|
|
121
|
-
export const
|
|
122
|
-
export const
|
|
123
|
-
export const
|
|
124
|
-
export const
|
|
125
|
-
export const
|
|
126
|
-
export const
|
|
127
|
-
export const
|
|
128
|
-
export const
|
|
129
|
-
export const
|
|
130
|
-
export const
|
|
131
|
-
export const
|
|
132
|
-
export const
|
|
133
|
-
export const
|
|
134
|
-
export const
|
|
135
|
-
export const
|
|
136
|
-
export const
|
|
137
|
-
export const
|
|
138
|
-
export const
|
|
139
|
-
export const
|
|
140
|
-
export const
|
|
141
|
-
export const
|
|
142
|
-
export const
|
|
143
|
-
export const
|
|
144
|
-
export const
|
|
145
|
-
export const
|
|
146
|
-
export const
|
|
147
|
-
export const
|
|
148
|
-
export const
|
|
149
|
-
export const
|
|
150
|
-
export const
|
|
151
|
-
export const
|
|
152
|
-
export const
|
|
153
|
-
export const
|
|
154
|
-
export const
|
|
155
|
-
export const
|
|
156
|
-
|
|
157
|
-
export
|
|
158
|
-
export
|
|
1
|
+
import type { ClassAttributes, ComponentChildren, JSX, VNode } from "preact";
|
|
2
|
+
|
|
3
|
+
import i18n from "gettext.js";
|
|
4
|
+
|
|
5
|
+
import { flatten, primary, references, relations } from "./db.js";
|
|
6
|
+
import { useApi } from "./use-api.js";
|
|
7
|
+
import { useEnhance } from "./use-enhance.js";
|
|
8
|
+
|
|
9
|
+
export interface DehydratedState {
|
|
10
|
+
queries: { queryHash: string; state: QueryState }[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface QueryState {
|
|
14
|
+
data: any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
15
|
+
dataUpdatedAt: number;
|
|
16
|
+
error: null | unknown;
|
|
17
|
+
isInvalidated: boolean;
|
|
18
|
+
status: "error" | "loading" | "success";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type SsrApp = (props: {
|
|
22
|
+
dehydratedState?: DehydratedState | undefined;
|
|
23
|
+
i18n: i18n.Gettext;
|
|
24
|
+
}) => VNode<any>; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
25
|
+
|
|
26
|
+
export interface SsrResponse {
|
|
27
|
+
data: {
|
|
28
|
+
dehydratedState: DehydratedState;
|
|
29
|
+
lang?: string;
|
|
30
|
+
url: string;
|
|
31
|
+
};
|
|
32
|
+
head: {
|
|
33
|
+
elements: Set<{
|
|
34
|
+
props: Record<string, string>;
|
|
35
|
+
type: string;
|
|
36
|
+
}>;
|
|
37
|
+
lang: string;
|
|
38
|
+
title: string;
|
|
39
|
+
};
|
|
40
|
+
html: string;
|
|
41
|
+
links: Set<string> | undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type H<T extends keyof JSX.IntrinsicElements> = (
|
|
45
|
+
props: (ClassAttributes<HTMLElement> & JSX.IntrinsicElements[T]) | null,
|
|
46
|
+
...children: ComponentChildren[]
|
|
47
|
+
) => VNode<ClassAttributes<HTMLElement> & JSX.IntrinsicElements[T]>;
|
|
48
|
+
|
|
49
|
+
interface SsrProps {
|
|
50
|
+
cookie?: string | undefined;
|
|
51
|
+
lang?: string;
|
|
52
|
+
url: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function dehydrate(
|
|
56
|
+
queryClient: ReturnType<typeof useQueryClient>,
|
|
57
|
+
options: {
|
|
58
|
+
shouldRedactErrors: (error: unknown) => boolean;
|
|
59
|
+
},
|
|
60
|
+
): DehydratedState;
|
|
61
|
+
|
|
62
|
+
export function getI18n(...langs: string[]): Promise<i18n.Gettext>;
|
|
63
|
+
|
|
64
|
+
export function hydrate(
|
|
65
|
+
App: (props: {
|
|
66
|
+
dehydratedState?: DehydratedState | undefined;
|
|
67
|
+
i18n: i18n.Gettext;
|
|
68
|
+
}) => VNode<any>, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
69
|
+
renderTarget: string,
|
|
70
|
+
): Promise<void>;
|
|
71
|
+
|
|
72
|
+
export function Router({
|
|
73
|
+
children,
|
|
74
|
+
dehydratedState,
|
|
75
|
+
i18n,
|
|
76
|
+
}: {
|
|
77
|
+
children?: ComponentChildren;
|
|
78
|
+
dehydratedState?: DehydratedState | undefined;
|
|
79
|
+
i18n: i18n.Gettext;
|
|
80
|
+
}): VNode<any>; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
81
|
+
|
|
82
|
+
/** @deprecated */
|
|
83
|
+
export function ssr(App: SsrApp, props: SsrProps): Promise<SsrResponse>;
|
|
84
|
+
export function ssr(App: SsrApp): (props: SsrProps) => Promise<SsrResponse>;
|
|
85
|
+
|
|
86
|
+
export function useI18n(): i18n.Gettext;
|
|
87
|
+
|
|
88
|
+
export function useQueryClient(): {
|
|
89
|
+
invalidateQueries(): void;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export function useStatus(error: unknown): string;
|
|
93
|
+
|
|
94
|
+
export const a: H<"a">;
|
|
95
|
+
export const address: H<"address">;
|
|
96
|
+
export const article: H<"article">;
|
|
97
|
+
export const aside: H<"aside">;
|
|
98
|
+
export const audio: H<"audio">;
|
|
99
|
+
export const b: H<"b">;
|
|
100
|
+
export const blockquote: H<"blockquote">;
|
|
101
|
+
export const br: H<"br">;
|
|
102
|
+
export const button: H<"button">;
|
|
103
|
+
export const canvas: H<"canvas">;
|
|
104
|
+
export const circle: H<"circle">;
|
|
105
|
+
export const code: H<"code">;
|
|
106
|
+
export const del: H<"del">;
|
|
107
|
+
export const details: H<"details">;
|
|
108
|
+
export const dialog: H<"dialog">;
|
|
109
|
+
export const div: H<"div">;
|
|
110
|
+
export const ellipse: H<"ellipse">;
|
|
111
|
+
export const em: H<"em">;
|
|
112
|
+
export const fieldset: H<"fieldset">;
|
|
113
|
+
export const figcaption: H<"figcaption">;
|
|
114
|
+
export const figure: H<"figure">;
|
|
115
|
+
export const footer: H<"footer">;
|
|
116
|
+
export const form: H<"form">;
|
|
117
|
+
export const h1: H<"h1">;
|
|
118
|
+
export const h2: H<"h2">;
|
|
119
|
+
export const h3: H<"h3">;
|
|
120
|
+
export const h4: H<"h4">;
|
|
121
|
+
export const h5: H<"h5">;
|
|
122
|
+
export const h6: H<"h6">;
|
|
123
|
+
export const header: H<"header">;
|
|
124
|
+
export const hgroup: H<"hgroup">;
|
|
125
|
+
export const hr: H<"hr">;
|
|
126
|
+
export const i: H<"i">;
|
|
127
|
+
export const iframe: H<"iframe">;
|
|
128
|
+
export const img: H<"img">;
|
|
129
|
+
export const input: H<"input">;
|
|
130
|
+
export const ins: H<"ins">;
|
|
131
|
+
export const label: H<"label">;
|
|
132
|
+
export const legend: H<"legend">;
|
|
133
|
+
export const li: H<"li">;
|
|
134
|
+
export const main: H<"main">;
|
|
135
|
+
export const nav: H<"nav">;
|
|
136
|
+
export const ol: H<"ol">;
|
|
137
|
+
export const option: H<"option">;
|
|
138
|
+
export const p: H<"p">;
|
|
139
|
+
export const path: H<"path">;
|
|
140
|
+
export const picture: H<"picture">;
|
|
141
|
+
export const polyline: H<"polyline">;
|
|
142
|
+
export const pre: H<"pre">;
|
|
143
|
+
export const rect: H<"rect">;
|
|
144
|
+
export const section: H<"section">;
|
|
145
|
+
export const select: H<"select">;
|
|
146
|
+
export const small: H<"small">;
|
|
147
|
+
export const source: H<"source">;
|
|
148
|
+
export const span: H<"span">;
|
|
149
|
+
export const strong: H<"strong">;
|
|
150
|
+
export const sub: H<"sub">;
|
|
151
|
+
export const summary: H<"summary">;
|
|
152
|
+
export const sup: H<"sup">;
|
|
153
|
+
export const svg: H<"svg">;
|
|
154
|
+
export const table: H<"table">;
|
|
155
|
+
export const tbody: H<"tbody">;
|
|
156
|
+
export const td: H<"td">;
|
|
157
|
+
export const text: H<"text">;
|
|
158
|
+
export const textarea: H<"textarea">;
|
|
159
|
+
export const th: H<"th">;
|
|
160
|
+
export const thead: H<"thead">;
|
|
161
|
+
export const title: H<"title">;
|
|
162
|
+
export const tr: H<"tr">;
|
|
163
|
+
export const ul: H<"ul">;
|
|
164
|
+
export const video: H<"video">;
|
|
165
|
+
|
|
166
|
+
export { flatten, primary, references, relations };
|
|
167
|
+
export { useApi, useEnhance };
|