@primate/core 0.7.4 → 0.8.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/lib/private/App.d.ts +128 -65
- package/lib/private/Bag.d.ts +11 -0
- package/lib/private/Bag.js +31 -0
- package/lib/private/Flags.d.ts +5 -5
- package/lib/private/Flags.js +2 -1
- package/lib/private/app/Facade.client.d.ts +20 -0
- package/lib/private/app/Facade.client.js +30 -0
- package/lib/private/app/{Facade.d.ts → Facade.server.d.ts} +141 -72
- package/lib/private/app/{Facade.js → Facade.server.js} +12 -4
- package/lib/private/build/App.d.ts +0 -2
- package/lib/private/build/App.js +0 -7
- package/lib/private/build/client/index.js +29 -27
- package/lib/private/build/client/plugin/frontend.js +1 -1
- package/lib/private/build/hook.js +0 -3
- package/lib/private/build/server/index.js +5 -18
- package/lib/private/build/server/plugin/native-addons.d.ts +1 -1
- package/lib/private/build/server/plugin/native-addons.js +1 -1
- package/lib/private/client/create-form.d.ts +13 -9
- package/lib/private/client/create-form.js +21 -4
- package/lib/private/client/transport.js +0 -2
- package/lib/private/config/index.d.ts +6 -2
- package/lib/private/config/schema.d.ts +28 -21
- package/lib/private/config/schema.js +5 -3
- package/lib/private/cookie.d.ts +5 -5
- package/lib/private/db/errors.d.ts +82 -82
- package/lib/private/db/migrate/store.d.ts +2 -2
- package/lib/private/db/primary.d.ts +1 -1
- package/lib/private/db/sql.d.ts +1 -1
- package/lib/private/errors.d.ts +80 -68
- package/lib/private/errors.js +22 -0
- package/lib/private/frontend.d.ts +7 -7
- package/lib/private/frontend.js +7 -10
- package/lib/private/i18n/API.d.ts +14 -18
- package/lib/private/i18n/config.client.d.ts +7 -0
- package/lib/private/i18n/config.client.js +130 -0
- package/lib/private/i18n/config.server.d.ts +7 -0
- package/lib/private/i18n/{index/server.js → config.server.js} +31 -23
- package/lib/private/i18n/constant/COOKIE_NAME.d.ts +1 -1
- package/lib/private/i18n/constant/DEFAULT_LOCALE.d.ts +1 -1
- package/lib/private/i18n/constant/DEFAULT_PERSIST_MODE.d.ts +1 -1
- package/lib/private/i18n/constant/PERSIST_HEADER.d.ts +1 -1
- package/lib/private/i18n/constant/PERSIST_METHOD.d.ts +1 -1
- package/lib/private/i18n/constant/PERSIST_STORAGE_KEY.d.ts +1 -1
- package/lib/private/i18n/index.d.ts +42 -0
- package/lib/private/i18n/index.js +6 -0
- package/lib/private/i18n/missing.d.ts +5 -0
- package/lib/private/i18n/missing.js +38 -0
- package/lib/private/i18n/module.js +36 -52
- package/lib/private/i18n/schema.d.ts +4 -4
- package/lib/private/loader.d.ts +5 -0
- package/lib/private/loader.js +28 -0
- package/lib/private/logger.d.ts +1 -1
- package/lib/private/request/RequestBag.d.ts +12 -13
- package/lib/private/request/RequestBag.js +5 -4
- package/lib/private/request/RequestView.d.ts +5 -5
- package/lib/private/request/RequestView.js +0 -1
- package/lib/private/response/view.d.ts +1 -0
- package/lib/private/response/view.js +0 -7
- package/lib/private/route/Handler.d.ts +1 -1
- package/lib/private/route/NarrowedRequest.d.ts +6 -1
- package/lib/private/route/Options.d.ts +2 -1
- package/lib/private/route/hook.d.ts +1 -2
- package/lib/private/route/router.d.ts +9 -9
- package/lib/private/route/router.js +9 -0
- package/lib/private/route.client.d.ts +21 -12
- package/lib/private/route.client.js +9 -4
- package/lib/private/route.d.ts +3 -0
- package/lib/private/route.js +2 -0
- package/lib/private/serve/App.d.ts +2 -13
- package/lib/private/serve/App.js +63 -46
- package/lib/private/serve/Init.d.ts +0 -3
- package/lib/private/server/TAG.d.ts +1 -1
- package/lib/private/session/config.client.d.ts +4 -0
- package/lib/private/session/config.client.js +24 -0
- package/lib/private/session/config.server.d.ts +15 -0
- package/lib/private/session/config.server.js +44 -0
- package/lib/private/session/index.d.ts +2 -14
- package/lib/private/session/index.js +2 -43
- package/lib/private/session/schema.d.ts +5 -5
- package/lib/private/store/PrimaryKey.d.ts +1 -1
- package/lib/private/store.client.d.ts +13 -0
- package/lib/private/store.client.js +9 -0
- package/lib/private/store.d.ts +2 -0
- package/lib/private/target/Manager.d.ts +2 -0
- package/lib/private/target/Manager.js +29 -5
- package/lib/private/target/Target.d.ts +2 -0
- package/lib/public/i18n.d.ts +3 -0
- package/lib/public/{i18n/config.js → i18n.js} +1 -1
- package/lib/public/loader.d.ts +2 -0
- package/lib/public/loader.js +2 -0
- package/lib/public/response.d.ts +1 -1
- package/lib/public/{session/config.d.ts → session.d.ts} +1 -1
- package/lib/public/{session/config.js → session.js} +1 -1
- package/package.json +27 -13
- package/lib/private/app/Facade.browser.d.ts +0 -11
- package/lib/private/app/Facade.browser.js +0 -19
- package/lib/private/build/server/plugin/store.d.ts +0 -4
- package/lib/private/build/server/plugin/store.js +0 -25
- package/lib/private/build/server/plugin/stores.d.ts +0 -4
- package/lib/private/build/server/plugin/stores.js +0 -28
- package/lib/private/i18n/index/client.d.ts +0 -9
- package/lib/private/i18n/index/client.js +0 -152
- package/lib/private/i18n/index/server.d.ts +0 -9
- package/lib/private/i18n/symbol/internal.d.ts +0 -3
- package/lib/private/i18n/symbol/internal.js +0 -3
- package/lib/public/i18n/API.d.ts +0 -2
- package/lib/public/i18n/API.js +0 -2
- package/lib/public/i18n/Catalogs.d.ts +0 -2
- package/lib/public/i18n/Catalogs.js +0 -2
- package/lib/public/i18n/ContextData.d.ts +0 -2
- package/lib/public/i18n/ContextData.js +0 -2
- package/lib/public/i18n/config.d.ts +0 -2
- package/lib/public/i18n/locale.d.ts +0 -2
- package/lib/public/i18n/locale.js +0 -2
- package/lib/public/i18n/sInternal.d.ts +0 -2
- package/lib/public/i18n/sInternal.js +0 -2
- package/lib/public/route/hook.d.ts +0 -2
- package/lib/public/route/hook.js +0 -2
- /package/lib/private/i18n/{index/types.d.ts → types.d.ts} +0 -0
- /package/lib/private/i18n/{index/types.js → types.js} +0 -0
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import DEFAULT_PERSIST_MODE from "#i18n/constant/DEFAULT_PERSIST_MODE";
|
|
2
1
|
import format from "#i18n/format";
|
|
3
2
|
import Formatter from "#i18n/Formatter";
|
|
4
3
|
import resolve from "#i18n/resolve";
|
|
5
4
|
import server_storage from "#i18n/storage";
|
|
6
|
-
import sInternal from "#i18n/symbol/internal";
|
|
7
5
|
import validate from "#i18n/validate";
|
|
8
|
-
import sConfig from "#symbol/config";
|
|
9
6
|
import is from "@rcompat/is";
|
|
10
7
|
export default function i18n(config) {
|
|
11
8
|
const catalogs = config.locales;
|
|
@@ -14,10 +11,9 @@ export default function i18n(config) {
|
|
|
14
11
|
}
|
|
15
12
|
const default_catalog = catalogs[config.defaultLocale];
|
|
16
13
|
const currency = config.currency ?? "USD";
|
|
17
|
-
const
|
|
14
|
+
const locales = Object.keys(catalogs);
|
|
18
15
|
const get_locale = () => {
|
|
19
|
-
const
|
|
20
|
-
const store = storage.getStore();
|
|
16
|
+
const store = server_storage().getStore();
|
|
21
17
|
return store?.locale ?? config.defaultLocale;
|
|
22
18
|
};
|
|
23
19
|
function t(...args) {
|
|
@@ -33,25 +29,37 @@ export default function i18n(config) {
|
|
|
33
29
|
return translated;
|
|
34
30
|
}
|
|
35
31
|
const api = t;
|
|
36
|
-
api
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
Object.defineProperties(api, {
|
|
33
|
+
defaultLocale: {
|
|
34
|
+
value: config.defaultLocale,
|
|
35
|
+
enumerable: true,
|
|
40
36
|
},
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
locales: {
|
|
38
|
+
value: locales,
|
|
39
|
+
enumerable: true,
|
|
40
|
+
},
|
|
41
|
+
catalogs: {
|
|
42
|
+
value: catalogs,
|
|
43
|
+
enumerable: true,
|
|
44
|
+
},
|
|
45
|
+
currency: {
|
|
46
|
+
value: currency,
|
|
47
|
+
enumerable: true,
|
|
48
|
+
},
|
|
49
|
+
locale: {
|
|
50
|
+
value: {
|
|
51
|
+
get: get_locale,
|
|
52
|
+
set: (_locale) => {
|
|
53
|
+
throw new Error("[i18n] locale.set is not supported on server.");
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
enumerable: true,
|
|
57
|
+
},
|
|
58
|
+
restore: {
|
|
59
|
+
value: () => { },
|
|
60
|
+
enumerable: true,
|
|
46
61
|
},
|
|
47
62
|
});
|
|
48
|
-
Object.defineProperty(api, sConfig, {
|
|
49
|
-
get: () => ({ ...config, persist }),
|
|
50
|
-
});
|
|
51
|
-
api.subscribe = (run) => {
|
|
52
|
-
run(api);
|
|
53
|
-
return () => { };
|
|
54
|
-
};
|
|
55
63
|
return api;
|
|
56
64
|
}
|
|
57
|
-
//# sourceMappingURL=server.js.map
|
|
65
|
+
//# sourceMappingURL=config.server.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import locale from "#i18n/locale";
|
|
2
|
+
import type { Dict } from "@rcompat/type";
|
|
3
|
+
export type { default as API } from "#i18n/API";
|
|
4
|
+
export type { default as Catalogs } from "#i18n/Catalogs";
|
|
5
|
+
export type { default as ContextData } from "#i18n/ContextData";
|
|
6
|
+
export type RestoreRequest = {
|
|
7
|
+
cookies?: Dict<string | undefined>;
|
|
8
|
+
};
|
|
9
|
+
export type HeadlessTranslator = {
|
|
10
|
+
(...args: any[]): any;
|
|
11
|
+
defaultLocale: string;
|
|
12
|
+
locales: readonly string[];
|
|
13
|
+
catalogs: Dict;
|
|
14
|
+
currency: string;
|
|
15
|
+
locale: {
|
|
16
|
+
get(): string;
|
|
17
|
+
set(locale: any): void;
|
|
18
|
+
};
|
|
19
|
+
restore(request?: RestoreRequest): void;
|
|
20
|
+
};
|
|
21
|
+
export type LocaleOf<T extends HeadlessTranslator> = T extends {
|
|
22
|
+
locale: {
|
|
23
|
+
get(): infer Locale;
|
|
24
|
+
};
|
|
25
|
+
} ? Locale : string;
|
|
26
|
+
export type SetLocaleOf<T extends HeadlessTranslator> = T extends {
|
|
27
|
+
locale: {
|
|
28
|
+
set(locale: infer Locale): void;
|
|
29
|
+
};
|
|
30
|
+
} ? Locale : never;
|
|
31
|
+
export type BridgedTranslator<T extends HeadlessTranslator> = T & {
|
|
32
|
+
readonly locale: {
|
|
33
|
+
get(): LocaleOf<T>;
|
|
34
|
+
set(locale: SetLocaleOf<T>): void;
|
|
35
|
+
};
|
|
36
|
+
restore(request?: RestoreRequest): void;
|
|
37
|
+
};
|
|
38
|
+
declare const i18n: {
|
|
39
|
+
locale: typeof locale;
|
|
40
|
+
};
|
|
41
|
+
export default i18n;
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const message = "[i18n] is not configured. Add an `i18n` key to config/app.ts.";
|
|
2
|
+
const fail = () => {
|
|
3
|
+
throw new Error(message);
|
|
4
|
+
};
|
|
5
|
+
export default function missing_i18n() {
|
|
6
|
+
const t = (() => fail());
|
|
7
|
+
Object.defineProperties(t, {
|
|
8
|
+
defaultLocale: {
|
|
9
|
+
get: fail,
|
|
10
|
+
enumerable: true,
|
|
11
|
+
},
|
|
12
|
+
locales: {
|
|
13
|
+
get: fail,
|
|
14
|
+
enumerable: true,
|
|
15
|
+
},
|
|
16
|
+
catalogs: {
|
|
17
|
+
get: fail,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
},
|
|
20
|
+
locale: {
|
|
21
|
+
value: {
|
|
22
|
+
get: fail,
|
|
23
|
+
set: (_locale) => fail(),
|
|
24
|
+
},
|
|
25
|
+
enumerable: true,
|
|
26
|
+
},
|
|
27
|
+
currency: {
|
|
28
|
+
get: fail,
|
|
29
|
+
enumerable: true,
|
|
30
|
+
},
|
|
31
|
+
persist: {
|
|
32
|
+
get: fail,
|
|
33
|
+
enumerable: true,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
return t;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=missing.js.map
|
|
@@ -25,6 +25,15 @@ function pick(client, server) {
|
|
|
25
25
|
}
|
|
26
26
|
return undefined;
|
|
27
27
|
}
|
|
28
|
+
function no_content(headers = {}) {
|
|
29
|
+
return new Response(null, {
|
|
30
|
+
headers: {
|
|
31
|
+
...headers,
|
|
32
|
+
"Content-Length": String(0),
|
|
33
|
+
},
|
|
34
|
+
status: http.Status.NO_CONTENT,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
28
37
|
export default function i18n_module(config) {
|
|
29
38
|
const default_locale = config.defaultLocale;
|
|
30
39
|
const locales = Object.keys(config.locales);
|
|
@@ -40,58 +49,26 @@ export default function i18n_module(config) {
|
|
|
40
49
|
}
|
|
41
50
|
return create({
|
|
42
51
|
name: "builtin/i18n",
|
|
43
|
-
setup({ onServe, onHandle
|
|
52
|
+
setup({ onServe, onHandle }) {
|
|
44
53
|
onServe(app => {
|
|
45
54
|
secure = app.secure;
|
|
46
55
|
});
|
|
47
|
-
onHandle(
|
|
56
|
+
onHandle((request, next) => {
|
|
48
57
|
const requested = request.headers.try(PERSIST_HEADER);
|
|
49
|
-
if (requested
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
reject(e);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
// only cookie-persistance is server-supported
|
|
66
|
-
if (persist !== "cookie")
|
|
67
|
-
return new Response(null, {
|
|
68
|
-
headers: {
|
|
69
|
-
"Content-Length": String(0),
|
|
70
|
-
},
|
|
71
|
-
status: http.Status.NO_CONTENT,
|
|
72
|
-
});
|
|
73
|
-
// only accept existing locales
|
|
74
|
-
if (!locales.includes(requested))
|
|
75
|
-
return new Response(null, {
|
|
76
|
-
headers: {
|
|
77
|
-
"Content-Length": String(0),
|
|
78
|
-
},
|
|
79
|
-
status: http.Status.NO_CONTENT,
|
|
58
|
+
if (requested !== undefined) {
|
|
59
|
+
if (persist !== "cookie")
|
|
60
|
+
return no_content();
|
|
61
|
+
if (!locales.includes(requested))
|
|
62
|
+
return no_content();
|
|
63
|
+
const header = cookie(COOKIE_NAME, requested, {
|
|
64
|
+
secure,
|
|
65
|
+
path: "/",
|
|
66
|
+
sameSite: "Strict",
|
|
80
67
|
});
|
|
81
|
-
|
|
82
|
-
secure,
|
|
83
|
-
path: "/",
|
|
84
|
-
sameSite: "Strict",
|
|
85
|
-
});
|
|
86
|
-
return new Response(null, {
|
|
87
|
-
headers: {
|
|
68
|
+
return no_content({
|
|
88
69
|
"Set-Cookie": header,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
status: http.Status.NO_CONTENT,
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
onRoute((request, next) => {
|
|
70
|
+
});
|
|
71
|
+
}
|
|
95
72
|
const accept_language = request.headers.try("Accept-Language") ?? "";
|
|
96
73
|
const client_locales = accept_language
|
|
97
74
|
.split(",")
|
|
@@ -100,15 +77,22 @@ export default function i18n_module(config) {
|
|
|
100
77
|
const cookie_locale = persist === "cookie"
|
|
101
78
|
? request.cookies.try(COOKIE_NAME)
|
|
102
79
|
: undefined;
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
80
|
+
const persisted_locale = cookie_locale !== undefined
|
|
81
|
+
&& locales.includes(cookie_locale)
|
|
82
|
+
? cookie_locale
|
|
83
|
+
: undefined;
|
|
84
|
+
const locale = persisted_locale
|
|
85
|
+
?? pick(client_locales, locales)
|
|
86
|
+
?? default_locale;
|
|
87
|
+
const context = {
|
|
107
88
|
currency,
|
|
108
|
-
mode: persist,
|
|
109
89
|
locale,
|
|
110
90
|
locales,
|
|
111
|
-
|
|
91
|
+
mode: persist,
|
|
92
|
+
};
|
|
93
|
+
return storage().run(context, () => {
|
|
94
|
+
return next(request.set("i18n", context));
|
|
95
|
+
});
|
|
112
96
|
});
|
|
113
97
|
},
|
|
114
98
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
declare const _default: import("pema").ObjectType<import("pema").NormalizeSchemaObject<{
|
|
2
2
|
readonly defaultLocale: import("pema").StringType;
|
|
3
|
-
readonly locales: import("pema").RecordType<import("pema").StringType, import("pema").UnknownType>;
|
|
3
|
+
readonly locales: import("pema").RecordType<import("pema").StringType, import("pema").UnknownType, undefined>;
|
|
4
4
|
readonly currency: import("pema").DefaultType<import("pema").StringType, "USD">;
|
|
5
|
-
readonly persist: import("pema").DefaultType<import("pema").UnionType<[import("pema").LiteralType<"cookie">, import("pema").LiteralType<"localStorage">, import("pema").LiteralType<"sessionStorage">, import("pema").LiteralType<false>]>,
|
|
6
|
-
}>, {
|
|
5
|
+
readonly persist: import("pema").DefaultType<import("pema").UnionType<[import("pema").LiteralType<"cookie", undefined>, import("pema").LiteralType<"localStorage", undefined>, import("pema").LiteralType<"sessionStorage", undefined>, import("pema").LiteralType<false, undefined>], undefined>, "cookie" | "localStorage" | "sessionStorage" | false>;
|
|
6
|
+
}>, undefined, {
|
|
7
7
|
defaultLocale: string;
|
|
8
8
|
locales: Record<string, unknown>;
|
|
9
9
|
currency: string;
|
|
10
|
-
persist:
|
|
10
|
+
persist: "cookie" | "localStorage" | "sessionStorage" | false;
|
|
11
11
|
}>;
|
|
12
12
|
export default _default;
|
|
13
13
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import E from "#errors";
|
|
2
|
+
import assert from "@rcompat/assert";
|
|
3
|
+
import fs from "@rcompat/fs";
|
|
4
|
+
export default function loader(extension, loader) {
|
|
5
|
+
assert.true(loader === "file", E.build_unrecognized_loader(loader));
|
|
6
|
+
const name = `loader-${extension}`;
|
|
7
|
+
const filter = new RegExp(`\\.${extension}$`);
|
|
8
|
+
const Loader = {
|
|
9
|
+
name,
|
|
10
|
+
setup({ onBuild }) {
|
|
11
|
+
onBuild(async (app) => {
|
|
12
|
+
app.plugin("client", {
|
|
13
|
+
name: "static-loader",
|
|
14
|
+
setup(build) {
|
|
15
|
+
build.onLoad({ filter }, async (args) => {
|
|
16
|
+
return {
|
|
17
|
+
contents: await fs.bytes(args.path),
|
|
18
|
+
loader: "file",
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
return Loader;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=loader.js.map
|
package/lib/private/logger.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LogHook } from "#module/Setup";
|
|
2
|
-
declare const Schema: import("pema").DefaultType<import("pema").UnionType<[import("pema").LiteralType<"error">, import("pema").LiteralType<"warn">, import("pema").LiteralType<"info">, import("pema").LiteralType<"trace">]>, "
|
|
2
|
+
declare const Schema: import("pema").DefaultType<import("pema").UnionType<[import("pema").LiteralType<"error", undefined>, import("pema").LiteralType<"warn", undefined>, import("pema").LiteralType<"info", undefined>, import("pema").LiteralType<"trace", undefined>], undefined>, "error" | "info" | "trace" | "warn">;
|
|
3
3
|
export { Schema };
|
|
4
4
|
declare const levels: {
|
|
5
5
|
readonly error: 0;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import symbol from "@rcompat/symbol";
|
|
2
|
-
import type {
|
|
3
|
-
type
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
normalize?: Normalize;
|
|
2
|
+
import type { Dict } from "@rcompat/type";
|
|
3
|
+
type Normalize<T> = (key: keyof T & string) => string;
|
|
4
|
+
type Options<T> = {
|
|
5
|
+
normalize?: Normalize<T>;
|
|
7
6
|
raw?: string;
|
|
8
7
|
};
|
|
9
|
-
export default class RequestBag {
|
|
8
|
+
export default class RequestBag<T extends Dict = Dict<string>> {
|
|
10
9
|
#private;
|
|
11
|
-
[symbol.parse]():
|
|
10
|
+
[symbol.parse](): T;
|
|
12
11
|
/**
|
|
13
12
|
* Create a new RequestBag.
|
|
14
13
|
*
|
|
@@ -16,7 +15,7 @@ export default class RequestBag {
|
|
|
16
15
|
* @param name - Human-readable bag name used in error messages.
|
|
17
16
|
* @param options - Optional `normalize` function and `raw` string.
|
|
18
17
|
*/
|
|
19
|
-
constructor(input:
|
|
18
|
+
constructor(input: T, name: string, options?: Options<T>);
|
|
20
19
|
/**
|
|
21
20
|
* The untouched, original source string for this bag. For example,
|
|
22
21
|
* - `"?a=1&b=2"` for a query bag,
|
|
@@ -32,7 +31,7 @@ export default class RequestBag {
|
|
|
32
31
|
* Iterate over `[key, value]` entries in the bag.
|
|
33
32
|
* Keys are post-normalization; entries with `undefined` values are skipped.
|
|
34
33
|
*/
|
|
35
|
-
[Symbol.iterator](): IterableIterator<
|
|
34
|
+
[Symbol.iterator](): IterableIterator<[keyof T & string, T[keyof T & string]]>;
|
|
36
35
|
/**
|
|
37
36
|
* Get a value by key.
|
|
38
37
|
*
|
|
@@ -40,21 +39,21 @@ export default class RequestBag {
|
|
|
40
39
|
* @returns The defined value.
|
|
41
40
|
* @throws If the key is absent or its value is `undefined`.
|
|
42
41
|
*/
|
|
43
|
-
get(key:
|
|
42
|
+
get<K extends keyof T & string>(key: K): T[K];
|
|
44
43
|
/**
|
|
45
44
|
* Try to get a value by key.
|
|
46
45
|
*
|
|
47
46
|
* @param key - Key to look up (pre-normalization).
|
|
48
47
|
* @returns The value, or `undefined` if absent/undefined.
|
|
49
48
|
*/
|
|
50
|
-
try(key:
|
|
49
|
+
try<K extends keyof T & string>(key: K): T[K] | undefined;
|
|
51
50
|
/**
|
|
52
51
|
* Whether the bag contains a defined value for the key.
|
|
53
52
|
*
|
|
54
53
|
* @param key - Key to test (pre-normalization).
|
|
55
54
|
* @returns `true` if present with a defined value; otherwise `false`.
|
|
56
55
|
*/
|
|
57
|
-
has(key:
|
|
56
|
+
has<K extends keyof T & string>(key: K): boolean;
|
|
58
57
|
/** Returns {@link raw}. Useful in template strings. */
|
|
59
58
|
toString(): string;
|
|
60
59
|
/**
|
|
@@ -62,7 +61,7 @@ export default class RequestBag {
|
|
|
62
61
|
*
|
|
63
62
|
* @returns A shallow null-prototype clone of the bag's contents.
|
|
64
63
|
*/
|
|
65
|
-
toJSON():
|
|
64
|
+
toJSON(): T;
|
|
66
65
|
}
|
|
67
66
|
export {};
|
|
68
67
|
//# sourceMappingURL=RequestBag.d.ts.map
|
|
@@ -28,8 +28,8 @@ export default class RequestBag {
|
|
|
28
28
|
this.#raw = options?.raw ?? "";
|
|
29
29
|
const contents = Object.create(null);
|
|
30
30
|
for (const key of Object.keys(input)) {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
contents[this.#normalize(key)] =
|
|
32
|
+
input[key];
|
|
33
33
|
}
|
|
34
34
|
this.#contents = contents;
|
|
35
35
|
}
|
|
@@ -58,8 +58,9 @@ export default class RequestBag {
|
|
|
58
58
|
*[Symbol.iterator]() {
|
|
59
59
|
for (const k of Object.keys(this.#contents)) {
|
|
60
60
|
const v = this.#contents[k];
|
|
61
|
-
if (v !== undefined)
|
|
61
|
+
if (v !== undefined) {
|
|
62
62
|
yield [k, v];
|
|
63
|
+
}
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
/**
|
|
@@ -100,7 +101,7 @@ export default class RequestBag {
|
|
|
100
101
|
}
|
|
101
102
|
/** Returns {@link raw}. Useful in template strings. */
|
|
102
103
|
toString() {
|
|
103
|
-
return this
|
|
104
|
+
return this.#raw;
|
|
104
105
|
}
|
|
105
106
|
/**
|
|
106
107
|
* JSON view of the normalized bag.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { Dict } from "@rcompat/type";
|
|
1
|
+
import type { Dict, PartialDict } from "@rcompat/type";
|
|
2
2
|
type RequestView = {
|
|
3
3
|
context: Dict;
|
|
4
|
-
cookies:
|
|
5
|
-
headers:
|
|
6
|
-
path:
|
|
7
|
-
query:
|
|
4
|
+
cookies: PartialDict<string>;
|
|
5
|
+
headers: PartialDict<string>;
|
|
6
|
+
path: PartialDict<string>;
|
|
7
|
+
query: PartialDict<string>;
|
|
8
8
|
url: URL;
|
|
9
9
|
};
|
|
10
10
|
export type { RequestView as default };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type ViewOptions from "#client/ViewOptions";
|
|
2
2
|
import type ResponseFunction from "#response/ResponseFunction";
|
|
3
3
|
import type { Dict } from "@rcompat/type";
|
|
4
|
+
declare function view(component: abstract new (...args: any[]) => any, props?: Dict, options?: ViewOptions): ResponseFunction;
|
|
4
5
|
declare function view<Props>(component: (props: Props) => any, props: Props, options?: ViewOptions): ResponseFunction;
|
|
5
6
|
declare function view(component: () => any, props?: Dict, options?: ViewOptions): ResponseFunction;
|
|
6
7
|
declare function view(name: string, props?: Dict, options?: ViewOptions): ResponseFunction;
|
|
@@ -17,13 +17,6 @@ const backmap = {
|
|
|
17
17
|
tsx: "react",
|
|
18
18
|
jsx: "react",
|
|
19
19
|
};
|
|
20
|
-
/**
|
|
21
|
-
* Render a view component using a frontend for the given filename extension
|
|
22
|
-
* @param view path to view
|
|
23
|
-
* @param props props for view
|
|
24
|
-
* @param options rendering options
|
|
25
|
-
* @return Response rendering function
|
|
26
|
-
*/
|
|
27
20
|
function view(name, props, options) {
|
|
28
21
|
const view_name = name;
|
|
29
22
|
return async (app, transfer, request) => {
|
|
@@ -2,6 +2,6 @@ import type ResponseLike from "#response/ResponseLike";
|
|
|
2
2
|
import type NarrowedRequest from "#route/NarrowedRequest";
|
|
3
3
|
import type RouteOptions from "#route/Options";
|
|
4
4
|
import type { MaybePromise } from "@rcompat/type";
|
|
5
|
-
type RouteHandler<O extends RouteOptions = RouteOptions> = (request: NarrowedRequest<O>) => MaybePromise<
|
|
5
|
+
type RouteHandler<O extends RouteOptions = RouteOptions, R extends ResponseLike = ResponseLike> = (request: NarrowedRequest<O>) => MaybePromise<R>;
|
|
6
6
|
export { RouteHandler as default };
|
|
7
7
|
//# sourceMappingURL=Handler.d.ts.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type RequestBag from "#request/RequestBag";
|
|
1
2
|
import type RequestBody from "#request/RequestBody";
|
|
2
3
|
import type RequestFacade from "#request/RequestFacade";
|
|
3
4
|
import type RouteOptions from "#route/Options";
|
|
@@ -16,8 +17,12 @@ type NarrowedBody<O extends RouteOptions, B extends RequestBody> = O extends {
|
|
|
16
17
|
} ? Omit<B, ContentTypeMethod[CT]> & {
|
|
17
18
|
[K in ContentTypeMethod[CT]]: () => Promise<Unpack<T>>;
|
|
18
19
|
} : B;
|
|
19
|
-
type
|
|
20
|
+
type NarrowedPath<O extends RouteOptions> = O extends {
|
|
21
|
+
path: Parsed<infer T>;
|
|
22
|
+
} ? RequestBag<Unpack<T>> : RequestBag;
|
|
23
|
+
type NarrowedRequest<O extends RouteOptions> = Omit<RequestFacade, "body" | "path"> & {
|
|
20
24
|
body: NarrowedBody<O, RequestBody>;
|
|
25
|
+
path: NarrowedPath<O>;
|
|
21
26
|
};
|
|
22
27
|
export type { NarrowedRequest as default };
|
|
23
28
|
//# sourceMappingURL=NarrowedRequest.d.ts.map
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type http from "@rcompat/http";
|
|
2
|
-
import type { Parsed } from "pema";
|
|
2
|
+
import type { ObjectType, Parsed } from "pema";
|
|
3
3
|
type MIME = Omit<typeof http.MIME, "resolve" | "extension">;
|
|
4
4
|
type MIMEValue = MIME[keyof MIME];
|
|
5
5
|
type RouteOptions = {
|
|
6
6
|
contentType?: MIMEValue;
|
|
7
7
|
body?: Parsed<unknown>;
|
|
8
|
+
path?: ObjectType;
|
|
8
9
|
};
|
|
9
10
|
export type { RouteOptions as default };
|
|
10
11
|
//# sourceMappingURL=Options.d.ts.map
|
|
@@ -2,7 +2,6 @@ import type NextRoute from "#module/NextRoute";
|
|
|
2
2
|
import type RequestFacade from "#request/RequestFacade";
|
|
3
3
|
import type ResponseLike from "#response/ResponseLike";
|
|
4
4
|
import type { MaybePromise } from "@rcompat/type";
|
|
5
|
-
type HookFn = (request: RequestFacade, next: NextRoute) => MaybePromise<ResponseLike>;
|
|
5
|
+
export type HookFn = (request: RequestFacade, next: NextRoute) => MaybePromise<ResponseLike>;
|
|
6
6
|
export default function hook(fn: HookFn): HookFn;
|
|
7
|
-
export {};
|
|
8
7
|
//# sourceMappingURL=hook.d.ts.map
|
|
@@ -9,39 +9,39 @@ declare class Router {
|
|
|
9
9
|
getHooks(path: string): RequestHook[];
|
|
10
10
|
verifyHook(path: string): void;
|
|
11
11
|
get(path: string): {
|
|
12
|
-
|
|
12
|
+
connect?: {
|
|
13
13
|
handler: RouteHandler;
|
|
14
14
|
options: RouteOptions;
|
|
15
15
|
} | undefined;
|
|
16
|
-
|
|
16
|
+
delete?: {
|
|
17
17
|
handler: RouteHandler;
|
|
18
18
|
options: RouteOptions;
|
|
19
19
|
} | undefined;
|
|
20
|
-
|
|
20
|
+
get?: {
|
|
21
21
|
handler: RouteHandler;
|
|
22
22
|
options: RouteOptions;
|
|
23
23
|
} | undefined;
|
|
24
|
-
|
|
24
|
+
head?: {
|
|
25
25
|
handler: RouteHandler;
|
|
26
26
|
options: RouteOptions;
|
|
27
27
|
} | undefined;
|
|
28
|
-
|
|
28
|
+
options?: {
|
|
29
29
|
handler: RouteHandler;
|
|
30
30
|
options: RouteOptions;
|
|
31
31
|
} | undefined;
|
|
32
|
-
|
|
32
|
+
patch?: {
|
|
33
33
|
handler: RouteHandler;
|
|
34
34
|
options: RouteOptions;
|
|
35
35
|
} | undefined;
|
|
36
|
-
|
|
36
|
+
post?: {
|
|
37
37
|
handler: RouteHandler;
|
|
38
38
|
options: RouteOptions;
|
|
39
39
|
} | undefined;
|
|
40
|
-
|
|
40
|
+
put?: {
|
|
41
41
|
handler: RouteHandler;
|
|
42
42
|
options: RouteOptions;
|
|
43
43
|
} | undefined;
|
|
44
|
-
|
|
44
|
+
trace?: {
|
|
45
45
|
handler: RouteHandler;
|
|
46
46
|
options: RouteOptions;
|
|
47
47
|
} | undefined;
|