@dws-std/i18n 1.0.0 → 1.1.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.
|
@@ -9,7 +9,7 @@ export type ExceptionCatalog<TDefs extends Record<string, ExceptionEntry<any>>>
|
|
|
9
9
|
* @template TDefs - Shape of the exception definitions map.
|
|
10
10
|
*/
|
|
11
11
|
export interface DefineExceptionCatalogOptions<TDefs extends Record<string, ExceptionEntry<any>>> {
|
|
12
|
-
/** Prefix prepended to every error
|
|
12
|
+
/** Prefix prepended to every error key (e.g. `'dns'` → `'dns.invalidRecordType'`). */
|
|
13
13
|
readonly namespace: string;
|
|
14
14
|
/** Locale used to build the default `message` when no locale is specified. */
|
|
15
15
|
readonly defaultLocale: keyof TDefs[keyof TDefs]['translations'];
|
|
@@ -21,7 +21,7 @@ export interface DefineExceptionCatalogOptions<TDefs extends Record<string, Exce
|
|
|
21
21
|
*
|
|
22
22
|
* Each key in `definitions` becomes a factory function that creates
|
|
23
23
|
* a {@link LocalizedHttpException} pre-filled with the right translations,
|
|
24
|
-
* HTTP status, and error
|
|
24
|
+
* HTTP status, and error key (`namespace.key`).
|
|
25
25
|
*
|
|
26
26
|
* @param options - Namespace, default locale, and exception definitions.
|
|
27
27
|
*
|
|
@@ -31,8 +31,8 @@ export declare class LocalizedHttpException<const TCause = unknown> extends Http
|
|
|
31
31
|
/**
|
|
32
32
|
* Creates a new localized HTTP exception.
|
|
33
33
|
*
|
|
34
|
-
* @param
|
|
34
|
+
* @param key - Application-specific error key (e.g. `'dns.invalidRecordType'`).
|
|
35
35
|
* @param init - Translations, params, status, and cause.
|
|
36
36
|
*/
|
|
37
|
-
constructor(
|
|
37
|
+
constructor(key: string, init: LocalizedHttpExceptionOptions<TCause>);
|
|
38
38
|
}
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ class LocalizedHttpException extends HttpException {
|
|
|
15
15
|
translations;
|
|
16
16
|
params;
|
|
17
17
|
defaultLocale;
|
|
18
|
-
constructor(
|
|
18
|
+
constructor(key, init) {
|
|
19
19
|
super(resolveMessage({
|
|
20
20
|
translations: init.translations,
|
|
21
21
|
params: init.params,
|
|
@@ -23,7 +23,7 @@ class LocalizedHttpException extends HttpException {
|
|
|
23
23
|
}), {
|
|
24
24
|
cause: init.cause,
|
|
25
25
|
status: init.status,
|
|
26
|
-
|
|
26
|
+
key
|
|
27
27
|
});
|
|
28
28
|
this.translations = init.translations;
|
|
29
29
|
this.params = init.params;
|
package/package.json
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
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
|
-
|
|
2
|
+
"name": "@dws-std/i18n",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Type-safe i18n for TypeScript — define localized exception and message catalogs with compile-time validated parameters.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"bun",
|
|
7
|
+
"dws",
|
|
8
|
+
"exception",
|
|
9
|
+
"http-error",
|
|
10
|
+
"i18n",
|
|
11
|
+
"internationalization",
|
|
12
|
+
"l10n",
|
|
13
|
+
"localization",
|
|
14
|
+
"translation"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "Dominus Web Services (DWS)",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/Dominus-Web-Service/std",
|
|
21
|
+
"directory": "packages/i18n"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "bun builder.ts",
|
|
35
|
+
"docs": "bunx typedoc --tsconfig tsconfig.build.json",
|
|
36
|
+
"fmt:check": "oxfmt --check",
|
|
37
|
+
"fmt": "oxfmt",
|
|
38
|
+
"lint:fix": "oxlint --type-aware --type-check --fix ./src",
|
|
39
|
+
"lint:github": "oxlint --type-aware --type-check --format=github ./src",
|
|
40
|
+
"lint": "oxlint --type-aware --type-check ./src",
|
|
41
|
+
"test": "bun test --pass-with-no-tests --coverage"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@dws-std/error": "^2.1.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/bun": "^1.3.10",
|
|
48
|
+
"oxfmt": "0.41.0",
|
|
49
|
+
"oxlint": "1.56.0",
|
|
50
|
+
"oxlint-tsgolint": "0.17.0",
|
|
51
|
+
"typescript": "^5.9.3"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@dws-std/error": "^2.1.0"
|
|
55
|
+
}
|
|
56
56
|
}
|