-
Notifications
You must be signed in to change notification settings - Fork 3
/
pathsInterfaces.ts
76 lines (67 loc) · 2.34 KB
/
pathsInterfaces.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
import sqlite3 from 'better-sqlite3';
import * as t from 'io-ts';
import {path} from 'static-path';
// export const filenamePath = path('/media/:filename');
export const mediaPath = path('/media/:bookmarkId');
export const bookmarkPath = path('/bookmark');
export const bookmarkIdPath = path('/bookmark/:id');
export const backupPath = path('/backup/:bookmarkId');
export const commentPath = path('/comment/:commentId');
export const tokenPath = path('/auth/token');
export const tokensPath = path('/auth/tokens');
export const mergePath = path('/merge/:fromId/:toId');
export type Db = ReturnType<typeof sqlite3>;
export function uniqueConstraintError(e: unknown): boolean {
return e instanceof sqlite3.SqliteError && e.code === 'SQLITE_CONSTRAINT_UNIQUE';
}
/**
* We need someting like `FullRow` because sql-ts emits my tables' `id` as
* `null|number` because I don't have to specify an `INTEGER PRIMARY KEY` when
* *inserting*, as SQLite will make it for me. However, when *selecting*, the
* `INTEGER PRIMARY KEY` field *will* be present.
*
* The below says "*All* keys are required and non-nullable".
*/
export type FullRow<T> = {
[k in keyof T] -?: NonNullable<T[k]>
};
export type Selected<T> = FullRow<T>|undefined;
export type SelectedAll<T> = FullRow<T>[];
export const AddBookmarkOrCommentPayload = t.intersection([
t.type({
_type: t.literal('addBookmarkOrComment'),
url: t.string,
title: t.string,
comment: t.string,
}),
// Above are REQUIRED. Below are OPTIONAL (`partial`)
t.partial({
html: t.string,
quote: t.boolean,
}),
]);
// the above is a runtime const. The below is a compile-time type. This is ok, I promise.
export type AddBookmarkOrCommentPayload = t.TypeOf<typeof AddBookmarkOrCommentPayload>;
export const AddCommentOnlyPayload = t.type({
_type: t.literal('addCommentOnly'),
id: t.number,
comment: t.string,
});
export const AddHtmlPayload = t.type({
_type: t.literal('addHtml'),
id: t.number,
html: t.string,
});
export const AskForHtmlPayload = t.type({
id: t.union([t.number, t.bigint]),
htmlWanted: t.boolean,
});
export type AskForHtmlPayload = t.TypeOf<typeof AskForHtmlPayload>;
export const Env = t.type({
GITHUB_CLIENT_ID: t.string,
GITHUB_CLIENT_SECRET: t.string,
SESSION_SECRET: t.string,
GITHUB_ID_ALLOWLIST: t.string,
URL: t.string,
});
export type Env = t.TypeOf<typeof Env>;