intor 2.4.12 → 2.4.13
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.
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
import type { LOCALE_PLACEHOLDER } from "../constants";
|
|
2
2
|
import type { Locale, LocaleMessages, Replacement, Rich } from "intor-translator";
|
|
3
|
-
/**
|
|
4
|
-
* =================================================
|
|
5
|
-
* Generated-aware type system for Intor
|
|
6
|
-
* =================================================
|
|
7
|
-
*/
|
|
8
3
|
/**
|
|
9
4
|
* Sentinel key injected by CLI when generated types exist.
|
|
10
|
-
* Used purely for type-level generation detection.
|
|
11
5
|
*/
|
|
12
6
|
export type INTOR_GENERATED_KEY = "__intor_generated__";
|
|
13
7
|
/**
|
|
14
|
-
* Detect
|
|
8
|
+
* Detect generation mode.
|
|
9
|
+
*
|
|
10
|
+
* This works in both source and declaration emit environments.
|
|
15
11
|
*/
|
|
16
|
-
type
|
|
17
|
-
[K in INTOR_GENERATED_KEY]: true;
|
|
18
|
-
} ? true : false;
|
|
12
|
+
type HasGen = INTOR_GENERATED_KEY extends keyof IntorGeneratedTypes ? true : false;
|
|
19
13
|
/**
|
|
20
|
-
* Extract
|
|
21
|
-
*
|
|
14
|
+
* Extract concrete generated config keys safely.
|
|
15
|
+
*
|
|
16
|
+
* - Works even if IntorGeneratedTypes is empty.
|
|
17
|
+
* - Prevents keyof widening issues.
|
|
22
18
|
*/
|
|
23
|
-
type GeneratedConfigKeys = Exclude<keyof IntorGeneratedTypes, INTOR_GENERATED_KEY
|
|
19
|
+
type GeneratedConfigKeys = HasGen extends true ? Exclude<keyof IntorGeneratedTypes & string, INTOR_GENERATED_KEY> : never;
|
|
24
20
|
/**
|
|
25
|
-
* Public
|
|
26
|
-
*
|
|
21
|
+
* Public config key union.
|
|
22
|
+
*
|
|
23
|
+
* - Never resolves to `never`.
|
|
24
|
+
* - Falls back to `string` safely.
|
|
27
25
|
*/
|
|
28
|
-
export type GenConfigKeys =
|
|
26
|
+
export type GenConfigKeys = HasGen extends true ? [GeneratedConfigKeys] extends [never] ? string : GeneratedConfigKeys : string;
|
|
29
27
|
/**
|
|
30
28
|
* Fallback configuration shape (non-generated mode).
|
|
31
29
|
*/
|
|
@@ -36,11 +34,14 @@ type FallbackConfig = {
|
|
|
36
34
|
Rich: Rich;
|
|
37
35
|
};
|
|
38
36
|
/**
|
|
39
|
-
*
|
|
37
|
+
* Safely extract generated config structure.
|
|
38
|
+
*
|
|
39
|
+
* - Never leaks `never` to public API.
|
|
40
|
+
* - Handles malformed generated types defensively.
|
|
40
41
|
*/
|
|
41
|
-
type
|
|
42
|
+
type SafeExtract<T> = T extends {
|
|
42
43
|
Locales: infer L extends string;
|
|
43
|
-
Messages: Record<typeof LOCALE_PLACEHOLDER, infer M>;
|
|
44
|
+
Messages: Record<typeof LOCALE_PLACEHOLDER, infer M extends LocaleMessages[string]>;
|
|
44
45
|
Replacements: infer RE;
|
|
45
46
|
Rich: infer RI;
|
|
46
47
|
} ? {
|
|
@@ -48,17 +49,15 @@ type ExtractGeneratedConfig<T> = T extends {
|
|
|
48
49
|
Messages: Record<L, M>;
|
|
49
50
|
Replacements: RE;
|
|
50
51
|
Rich: RI;
|
|
51
|
-
} :
|
|
52
|
+
} : FallbackConfig;
|
|
52
53
|
/**
|
|
53
|
-
*
|
|
54
|
+
* Main configuration resolver.
|
|
54
55
|
*
|
|
55
|
-
* -
|
|
56
|
-
* -
|
|
57
|
-
|
|
58
|
-
export type GenConfig<CK extends GenConfigKeys> = HasGenerated extends true ? CK extends GeneratedConfigKeys ? ExtractGeneratedConfig<IntorGeneratedTypes[CK]> : never : FallbackConfig;
|
|
59
|
-
/**
|
|
60
|
-
* Derived helpers
|
|
56
|
+
* - Never returns `never`.
|
|
57
|
+
* - Fully declaration-safe.
|
|
58
|
+
* - Stable under generic distribution.
|
|
61
59
|
*/
|
|
60
|
+
export type GenConfig<CK extends GenConfigKeys> = HasGen extends true ? CK extends GeneratedConfigKeys ? SafeExtract<IntorGeneratedTypes[CK]> : FallbackConfig : FallbackConfig;
|
|
62
61
|
export type GenMessages<CK extends GenConfigKeys> = GenConfig<CK>["Messages"];
|
|
63
62
|
export type GenLocale<CK extends GenConfigKeys> = GenConfig<CK>["Locales"];
|
|
64
63
|
export type GenReplacements<CK extends GenConfigKeys> = GenConfig<CK>["Replacements"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intor",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.13",
|
|
4
4
|
"description": "The i18n library for modern JavaScript",
|
|
5
5
|
"author": "Yiming Liao",
|
|
6
6
|
"homepage": "https://intor.dev",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
],
|
|
93
93
|
"sideEffects": false,
|
|
94
94
|
"engines": {
|
|
95
|
-
"node": ">=
|
|
95
|
+
"node": ">=20"
|
|
96
96
|
},
|
|
97
97
|
"scripts": {
|
|
98
98
|
"type": "tsc --noEmit",
|
|
@@ -103,11 +103,10 @@
|
|
|
103
103
|
"test:check": "tsx scripts/check-test-structure.ts",
|
|
104
104
|
"knip": "knip --config .config/knip.config.ts",
|
|
105
105
|
"build": "tsx scripts/build.ts",
|
|
106
|
-
"prepublishOnly": "yarn build"
|
|
107
|
-
"examples:html": "vite --config examples/html/vite.config.ts"
|
|
106
|
+
"prepublishOnly": "yarn build"
|
|
108
107
|
},
|
|
109
108
|
"dependencies": {
|
|
110
|
-
"intor-translator": "1.4.
|
|
109
|
+
"intor-translator": "^1.4.14",
|
|
111
110
|
"logry": "2.1.6",
|
|
112
111
|
"p-limit": "7.2.0"
|
|
113
112
|
},
|
|
@@ -152,6 +151,7 @@
|
|
|
152
151
|
"svelte": "5.46.1",
|
|
153
152
|
"tsc-alias": "1.8.16",
|
|
154
153
|
"tsd": "0.33.0",
|
|
154
|
+
"tsx": "^4.21.0",
|
|
155
155
|
"typescript": "5.8.3",
|
|
156
156
|
"typescript-eslint": "8.32.1",
|
|
157
157
|
"vite": "7.3.0",
|