@localness/contract 0.4.4 → 0.5.1
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 +12 -0
- package/dist/index.d.mts +35 -20
- package/dist/index.mjs +22 -24
- package/dist/key-convention-C-urfySC.mjs +108 -0
- package/dist/rules.d.mts +62 -0
- package/dist/rules.mjs +45 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,18 @@ const meta: DeliveryMeta = deliveryMetaSchema.parse(await res.json())
|
|
|
10
10
|
|
|
11
11
|
`zod` ^4 is a peer dependency.
|
|
12
12
|
|
|
13
|
+
## Rules
|
|
14
|
+
|
|
15
|
+
`@localness/contract/rules` holds the pure rules a client must apply the way the server does: `fpTranslation` (the text fingerprint behind unnamed keys), `checkI18nKey` (why a key name breaks the project's key convention, with `KEY_VIOLATION_TEXT`) and `namespaceOf` (which declared namespace a key belongs to: names are relative to the project's key prefix). The convention and the namespace names come from `GET /api/v1/meta` (`keyConvention`, `namespaces`). It does not need `zod`.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { checkI18nKey, namespaceOf } from '@localness/contract/rules'
|
|
19
|
+
|
|
20
|
+
const { keyConvention, namespaces } = meta
|
|
21
|
+
checkI18nKey('shop_login_title', keyConvention) // []
|
|
22
|
+
namespaceOf('shop_login_title', namespaces.map((ns) => ns.name), keyConvention.prefix) // 'login'
|
|
23
|
+
```
|
|
24
|
+
|
|
13
25
|
## Locale files
|
|
14
26
|
|
|
15
27
|
`@localness/contract/locale-file` reads and writes one-JSON-per-locale files exactly as Localness git-sync does: flat or nested keys, edits in place (key order, indentation, comments and line endings are kept), new keys appended. The `localness` CLI uses it, so a file written by either one is identical. It does not need `zod`.
|
package/dist/index.d.mts
CHANGED
|
@@ -21,9 +21,10 @@ export declare const releaseMembershipResultSchema: z.ZodObject<{
|
|
|
21
21
|
}, z.core.$strip>;
|
|
22
22
|
export type ReleaseMembershipResult = z.infer<typeof releaseMembershipResultSchema>;
|
|
23
23
|
/**
|
|
24
|
-
* A declared key namespace. Keys are grouped by name —
|
|
25
|
-
* namespace it starts with, followed by a
|
|
26
|
-
* of keys and never
|
|
24
|
+
* A declared key namespace. Keys are grouped by name — after the project's key
|
|
25
|
+
* prefix, a key belongs to the namespace it starts with, followed by a boundary
|
|
26
|
+
* (`namespaceOf` in `/rules`) — so this carries no list of keys and never
|
|
27
|
+
* renames one.
|
|
27
28
|
*/
|
|
28
29
|
export declare const keyNamespaceSchema: z.ZodObject<{
|
|
29
30
|
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
@@ -59,6 +60,23 @@ export declare const deliveryOutdatedSchema: z.ZodObject<{
|
|
|
59
60
|
outdated: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
|
|
60
61
|
}, z.core.$strip>;
|
|
61
62
|
export type DeliveryOutdated = z.infer<typeof deliveryOutdatedSchema>;
|
|
63
|
+
/**
|
|
64
|
+
* The project's key naming rules, for clients that name keys themselves and
|
|
65
|
+
* group them by namespace (`checkI18nKey` and `namespaceOf` in `/rules`).
|
|
66
|
+
* `prefix` is without its trailing separator; `''` means no prefix.
|
|
67
|
+
*/
|
|
68
|
+
export declare const deliveryKeyConventionSchema: z.ZodObject<{
|
|
69
|
+
prefix: z.ZodString;
|
|
70
|
+
separator: z.ZodString;
|
|
71
|
+
style: z.ZodEnum<{
|
|
72
|
+
snake_case: "snake_case";
|
|
73
|
+
camelCase: "camelCase";
|
|
74
|
+
none: "none";
|
|
75
|
+
}>;
|
|
76
|
+
maxDepth: z.ZodNumber;
|
|
77
|
+
guidance: z.ZodNullable<z.ZodString>;
|
|
78
|
+
}, z.core.$strip>;
|
|
79
|
+
export type DeliveryKeyConvention = z.infer<typeof deliveryKeyConventionSchema>;
|
|
62
80
|
/** `GET /api/v1/meta` — what a caller holding only a token learns first. */
|
|
63
81
|
export declare const deliveryMetaSchema: z.ZodObject<{
|
|
64
82
|
project: z.ZodObject<{
|
|
@@ -82,6 +100,17 @@ export declare const deliveryMetaSchema: z.ZodObject<{
|
|
|
82
100
|
name: z.ZodString;
|
|
83
101
|
sort: z.ZodNumber;
|
|
84
102
|
}, z.core.$strip>>>;
|
|
103
|
+
keyConvention: z.ZodOptional<z.ZodObject<{
|
|
104
|
+
prefix: z.ZodString;
|
|
105
|
+
separator: z.ZodString;
|
|
106
|
+
style: z.ZodEnum<{
|
|
107
|
+
snake_case: "snake_case";
|
|
108
|
+
camelCase: "camelCase";
|
|
109
|
+
none: "none";
|
|
110
|
+
}>;
|
|
111
|
+
maxDepth: z.ZodNumber;
|
|
112
|
+
guidance: z.ZodNullable<z.ZodString>;
|
|
113
|
+
}, z.core.$strip>>;
|
|
85
114
|
coverage: z.ZodObject<{
|
|
86
115
|
keys: z.ZodNumber;
|
|
87
116
|
projectKeys: z.ZodNumber;
|
|
@@ -413,6 +442,7 @@ export declare const keyViolationSchema: z.ZodEnum<{
|
|
|
413
442
|
prefix: "prefix";
|
|
414
443
|
charset: "charset";
|
|
415
444
|
segment: "segment";
|
|
445
|
+
separator: "separator";
|
|
416
446
|
case: "case";
|
|
417
447
|
depth: "depth";
|
|
418
448
|
}>;
|
|
@@ -433,6 +463,7 @@ export declare const keyNameSuggestionSchema: z.ZodObject<{
|
|
|
433
463
|
prefix: "prefix";
|
|
434
464
|
charset: "charset";
|
|
435
465
|
segment: "segment";
|
|
466
|
+
separator: "separator";
|
|
436
467
|
case: "case";
|
|
437
468
|
depth: "depth";
|
|
438
469
|
}>>;
|
|
@@ -442,20 +473,4 @@ export declare const keyNameSuggestionSchema: z.ZodObject<{
|
|
|
442
473
|
sameSourceText: z.ZodBoolean;
|
|
443
474
|
}, z.core.$strip>>;
|
|
444
475
|
}, z.core.$strip>;
|
|
445
|
-
export type KeyNameSuggestion = z.infer<typeof keyNameSuggestionSchema>;
|
|
446
|
-
/**
|
|
447
|
-
* `GET /api/v1/key-convention` — the project's key naming rules, so a client
|
|
448
|
-
* can name keys itself instead of calling `suggest-name` once per text.
|
|
449
|
-
* `prefix` is without its trailing separator; `''` means no prefix.
|
|
450
|
-
*/
|
|
451
|
-
export declare const keyConventionSchema: z.ZodObject<{
|
|
452
|
-
prefix: z.ZodString;
|
|
453
|
-
separator: z.ZodString;
|
|
454
|
-
style: z.ZodEnum<{
|
|
455
|
-
snake_case: "snake_case";
|
|
456
|
-
camelCase: "camelCase";
|
|
457
|
-
}>;
|
|
458
|
-
maxDepth: z.ZodNumber;
|
|
459
|
-
prompt: z.ZodNullable<z.ZodString>;
|
|
460
|
-
}, z.core.$strip>;
|
|
461
|
-
export type KeyConventionInfo = z.infer<typeof keyConventionSchema>;
|
|
476
|
+
export type KeyNameSuggestion = z.infer<typeof keyNameSuggestionSchema>;
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { i as KEY_VIOLATION_VALUES, t as KEY_STYLE_VALUES } from "./key-convention-C-urfySC.mjs";
|
|
1
2
|
import { z } from "zod/v4";
|
|
2
3
|
// ../../shared/contract/release.ts
|
|
3
4
|
/** A row id, which the API sends as a number but the UI also carries as text. */
|
|
@@ -22,9 +23,10 @@ const releaseMembershipResultSchema = z.object({
|
|
|
22
23
|
});
|
|
23
24
|
// ../../shared/contract/namespace.ts
|
|
24
25
|
/**
|
|
25
|
-
* A declared key namespace. Keys are grouped by name —
|
|
26
|
-
* namespace it starts with, followed by a
|
|
27
|
-
* of keys and never
|
|
26
|
+
* A declared key namespace. Keys are grouped by name — after the project's key
|
|
27
|
+
* prefix, a key belongs to the namespace it starts with, followed by a boundary
|
|
28
|
+
* (`namespaceOf` in `/rules`) — so this carries no list of keys and never
|
|
29
|
+
* renames one.
|
|
28
30
|
*/
|
|
29
31
|
const keyNamespaceSchema = z.object({
|
|
30
32
|
id: idSchema,
|
|
@@ -58,6 +60,19 @@ const deliveryLocaleSchema = z.record(z.string(), z.string());
|
|
|
58
60
|
const deliveryOutdatedSchema = z.object({
|
|
59
61
|
/** locale → keys */
|
|
60
62
|
outdated: z.record(z.string(), z.array(z.string())) });
|
|
63
|
+
/**
|
|
64
|
+
* The project's key naming rules, for clients that name keys themselves and
|
|
65
|
+
* group them by namespace (`checkI18nKey` and `namespaceOf` in `/rules`).
|
|
66
|
+
* `prefix` is without its trailing separator; `''` means no prefix.
|
|
67
|
+
*/
|
|
68
|
+
const deliveryKeyConventionSchema = z.object({
|
|
69
|
+
prefix: z.string(),
|
|
70
|
+
separator: z.string(),
|
|
71
|
+
style: z.enum(KEY_STYLE_VALUES),
|
|
72
|
+
maxDepth: z.number(),
|
|
73
|
+
/** The project's naming guidance, or null when unset. */
|
|
74
|
+
guidance: z.string().nullable()
|
|
75
|
+
});
|
|
61
76
|
/** `GET /api/v1/meta` — what a caller holding only a token learns first. */
|
|
62
77
|
const deliveryMetaSchema = z.object({
|
|
63
78
|
project: z.object({
|
|
@@ -79,6 +94,8 @@ const deliveryMetaSchema = z.object({
|
|
|
79
94
|
namespace: z.string().nullable().optional(),
|
|
80
95
|
/** The names `?namespace=` accepts, in display order. */
|
|
81
96
|
namespaces: z.array(keyNamespaceSchema).optional(),
|
|
97
|
+
/** Optional: servers before it omit it. */
|
|
98
|
+
keyConvention: deliveryKeyConventionSchema.optional(),
|
|
82
99
|
coverage: z.object({
|
|
83
100
|
keys: z.number(),
|
|
84
101
|
projectKeys: z.number(),
|
|
@@ -286,13 +303,7 @@ const keyDraftConflictSchema = z.object({
|
|
|
286
303
|
locales: z.array(z.string()),
|
|
287
304
|
key: deliveryKeyStateSchema
|
|
288
305
|
});
|
|
289
|
-
const keyViolationSchema = z.enum(
|
|
290
|
-
"prefix",
|
|
291
|
-
"charset",
|
|
292
|
-
"segment",
|
|
293
|
-
"case",
|
|
294
|
-
"depth"
|
|
295
|
-
]);
|
|
306
|
+
const keyViolationSchema = z.enum(KEY_VIOLATION_VALUES);
|
|
296
307
|
/**
|
|
297
308
|
* `POST /api/v1/keys/suggest-name` — the web app's AI key naming, under the
|
|
298
309
|
* project's key convention. `key` is empty when the text has nothing nameable.
|
|
@@ -314,17 +325,4 @@ const keyNameSuggestionSchema = z.object({
|
|
|
314
325
|
sameSourceText: z.boolean()
|
|
315
326
|
}))
|
|
316
327
|
});
|
|
317
|
-
|
|
318
|
-
* `GET /api/v1/key-convention` — the project's key naming rules, so a client
|
|
319
|
-
* can name keys itself instead of calling `suggest-name` once per text.
|
|
320
|
-
* `prefix` is without its trailing separator; `''` means no prefix.
|
|
321
|
-
*/
|
|
322
|
-
const keyConventionSchema = z.object({
|
|
323
|
-
prefix: z.string(),
|
|
324
|
-
separator: z.string(),
|
|
325
|
-
style: z.enum(["snake_case", "camelCase"]),
|
|
326
|
-
maxDepth: z.number(),
|
|
327
|
-
/** The project's naming guidance for the AI, or null when unset. */
|
|
328
|
-
prompt: z.string().nullable()
|
|
329
|
-
});
|
|
330
|
-
export { captureKeyHitSchema, captureKeySearchSchema, captureMatchSchema, capturePageSchema, captureTagSchema, createPageResultSchema, deleteTagsResultSchema, deliveryBundleSchema, deliveryKeyStateSchema, deliveryKeyStatesSchema, deliveryKeysSchema, deliveryLocaleSchema, deliveryLocaleStateNameSchema, deliveryMetaSchema, deliveryOutdatedSchema, deliveryProjectRefSchema, deliveryProjectsSchema, i18nKeyNamespaceCountsSchema, idSchema, importPageResultSchema, importPageTagsSchema, importedTagSchema, keyConventionSchema, keyDraftConflictSchema, keyNameSuggestionSchema, keyNamespaceSchema, keyViolationSchema, keyWriteResultSchema, projectReleaseSchema, releaseMembershipResultSchema, uploadResultSchema };
|
|
328
|
+
export { captureKeyHitSchema, captureKeySearchSchema, captureMatchSchema, capturePageSchema, captureTagSchema, createPageResultSchema, deleteTagsResultSchema, deliveryBundleSchema, deliveryKeyConventionSchema, deliveryKeyStateSchema, deliveryKeyStatesSchema, deliveryKeysSchema, deliveryLocaleSchema, deliveryLocaleStateNameSchema, deliveryMetaSchema, deliveryOutdatedSchema, deliveryProjectRefSchema, deliveryProjectsSchema, i18nKeyNamespaceCountsSchema, idSchema, importPageResultSchema, importPageTagsSchema, importedTagSchema, keyDraftConflictSchema, keyNameSuggestionSchema, keyNamespaceSchema, keyViolationSchema, keyWriteResultSchema, projectReleaseSchema, releaseMembershipResultSchema, uploadResultSchema };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// ../../shared/contract/key-convention.ts
|
|
2
|
+
/**
|
|
3
|
+
* The per-project rules an i18n key has to follow. Pure, so a client that
|
|
4
|
+
* names keys itself checks them exactly the way the server does.
|
|
5
|
+
*/
|
|
6
|
+
const KEY_STYLE_VALUES = [
|
|
7
|
+
"snake_case",
|
|
8
|
+
"camelCase",
|
|
9
|
+
"none"
|
|
10
|
+
];
|
|
11
|
+
const KEY_VIOLATION_VALUES = [
|
|
12
|
+
"prefix",
|
|
13
|
+
"charset",
|
|
14
|
+
"segment",
|
|
15
|
+
"separator",
|
|
16
|
+
"case",
|
|
17
|
+
"depth"
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* Errors make a key unusable as a name; warnings are the project's style, which
|
|
21
|
+
* legacy keys may never have followed, so nothing refuses a key over them.
|
|
22
|
+
*/
|
|
23
|
+
const KEY_VIOLATION_LEVEL = {
|
|
24
|
+
prefix: "error",
|
|
25
|
+
charset: "error",
|
|
26
|
+
segment: "error",
|
|
27
|
+
separator: "warning",
|
|
28
|
+
case: "warning",
|
|
29
|
+
depth: "warning"
|
|
30
|
+
};
|
|
31
|
+
const KEY_VIOLATION_TEXT = {
|
|
32
|
+
prefix: "Missing the project key prefix",
|
|
33
|
+
charset: "Uses characters other than letters, digits, \".\", \"_\" and \"-\"",
|
|
34
|
+
segment: "Has an empty segment",
|
|
35
|
+
separator: "Uses a separator other than the configured one",
|
|
36
|
+
case: "Does not match the configured casing",
|
|
37
|
+
depth: "Has more levels than the convention suggests"
|
|
38
|
+
};
|
|
39
|
+
function keyViolationErrors(violations) {
|
|
40
|
+
return violations.filter((one) => KEY_VIOLATION_LEVEL[one] === "error");
|
|
41
|
+
}
|
|
42
|
+
function keyViolationWarnings(violations) {
|
|
43
|
+
return violations.filter((one) => KEY_VIOLATION_LEVEL[one] === "warning");
|
|
44
|
+
}
|
|
45
|
+
/** Characters any key may use to join its parts, whatever the configured separator. */
|
|
46
|
+
const KEY_BOUNDARY = [
|
|
47
|
+
".",
|
|
48
|
+
"_",
|
|
49
|
+
"-"
|
|
50
|
+
];
|
|
51
|
+
const WORD_PATTERN = {
|
|
52
|
+
snake_case: /^[a-z0-9]+$/,
|
|
53
|
+
camelCase: /^[a-z][A-Za-z0-9]*$/
|
|
54
|
+
};
|
|
55
|
+
function boundaryChars(separator) {
|
|
56
|
+
return /* @__PURE__ */ new Set([...KEY_BOUNDARY, ...separator]);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The characters that start a new level. In a snake_case project whose
|
|
60
|
+
* separator is not `_`, the underscore joins words inside one level.
|
|
61
|
+
*/
|
|
62
|
+
function levelChars(convention) {
|
|
63
|
+
const chars = boundaryChars(convention.separator);
|
|
64
|
+
if (convention.style === "snake_case" && !convention.separator.includes("_")) chars.delete("_");
|
|
65
|
+
return chars;
|
|
66
|
+
}
|
|
67
|
+
function splitOn(text, chars) {
|
|
68
|
+
const parts = [""];
|
|
69
|
+
for (const char of text) if (chars.has(char)) parts.push("");
|
|
70
|
+
else parts[parts.length - 1] += char;
|
|
71
|
+
return parts;
|
|
72
|
+
}
|
|
73
|
+
/** How many levels a key path has under the convention. */
|
|
74
|
+
function keyDepth(path, convention) {
|
|
75
|
+
return path ? splitOn(path, levelChars(convention)).length : 0;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Pure: every way `key` breaks the convention, in the order worth fixing. Use
|
|
79
|
+
* `KEY_VIOLATION_LEVEL` to tell what must block from what is only advice.
|
|
80
|
+
*
|
|
81
|
+
* An empty key is **legal** (a symbol-only source text has no name), so it is
|
|
82
|
+
* not a violation here — callers treat it as "cannot name", not as an error.
|
|
83
|
+
*
|
|
84
|
+
* The prefix itself is exempt: it is copied verbatim from the project settings,
|
|
85
|
+
* so the configured rules govern the path that follows it. Any boundary
|
|
86
|
+
* character may follow it, so legacy keys that joined it differently still count.
|
|
87
|
+
*/
|
|
88
|
+
function checkI18nKey(key, convention) {
|
|
89
|
+
if (!key) return [];
|
|
90
|
+
const { prefix, separator, style, maxDepth } = convention;
|
|
91
|
+
if (!separator) return [];
|
|
92
|
+
const boundary = boundaryChars(separator);
|
|
93
|
+
const violations = [];
|
|
94
|
+
const prefixed = Boolean(prefix) && key.startsWith(prefix) && boundary.has(key.charAt(prefix.length));
|
|
95
|
+
if (prefix && !prefixed) violations.push("prefix");
|
|
96
|
+
const path = prefixed ? key.slice(prefix.length + 1) : key;
|
|
97
|
+
const allowed = (char) => /[0-9a-zA-Z]/.test(char) || boundary.has(char);
|
|
98
|
+
if ([...path].some((char) => !allowed(char))) violations.push("charset");
|
|
99
|
+
if (splitOn(path, boundary).some((word) => word === "")) violations.push("segment");
|
|
100
|
+
const levels = levelChars(convention);
|
|
101
|
+
if ([...path].some((char) => levels.has(char) && !separator.includes(char))) violations.push("separator");
|
|
102
|
+
if (style !== "none") {
|
|
103
|
+
if (splitOn(path, boundary).some((word) => word && !WORD_PATTERN[style].test(word))) violations.push("case");
|
|
104
|
+
}
|
|
105
|
+
if (keyDepth(path, convention) > maxDepth) violations.push("depth");
|
|
106
|
+
return violations;
|
|
107
|
+
}
|
|
108
|
+
export { checkI18nKey as a, keyViolationWarnings as c, KEY_VIOLATION_VALUES as i, KEY_VIOLATION_LEVEL as n, keyDepth as o, KEY_VIOLATION_TEXT as r, keyViolationErrors as s, KEY_STYLE_VALUES as t };
|
package/dist/rules.d.mts
CHANGED
|
@@ -1,3 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The per-project rules an i18n key has to follow. Pure, so a client that
|
|
3
|
+
* names keys itself checks them exactly the way the server does.
|
|
4
|
+
*/
|
|
5
|
+
export declare const KEY_STYLE_VALUES: readonly ["snake_case", "camelCase", "none"];
|
|
6
|
+
export type KeyStyle = (typeof KEY_STYLE_VALUES)[number];
|
|
7
|
+
export type KeyConvention = {
|
|
8
|
+
/** Without the trailing separator; `''` means no prefix. */
|
|
9
|
+
prefix: string;
|
|
10
|
+
/** The suggested joint between levels. Must be non-empty — the settings schema enforces it. */
|
|
11
|
+
separator: string;
|
|
12
|
+
/** `none` leaves casing to the project, for keys named before the convention existed. */
|
|
13
|
+
style: KeyStyle;
|
|
14
|
+
/** The suggested number of levels after the prefix. */
|
|
15
|
+
maxDepth: number;
|
|
16
|
+
};
|
|
17
|
+
export declare const KEY_VIOLATION_VALUES: readonly ["prefix", "charset", "segment", "separator", "case", "depth"];
|
|
18
|
+
/** Why a key does not follow the convention. Sent to the client as a code. */
|
|
19
|
+
export type KeyViolation = (typeof KEY_VIOLATION_VALUES)[number];
|
|
20
|
+
/**
|
|
21
|
+
* Errors make a key unusable as a name; warnings are the project's style, which
|
|
22
|
+
* legacy keys may never have followed, so nothing refuses a key over them.
|
|
23
|
+
*/
|
|
24
|
+
export declare const KEY_VIOLATION_LEVEL: Record<KeyViolation, 'error' | 'warning'>;
|
|
25
|
+
export declare const KEY_VIOLATION_TEXT: Record<KeyViolation, string>;
|
|
26
|
+
export declare function keyViolationErrors(violations: KeyViolation[]): KeyViolation[];
|
|
27
|
+
export declare function keyViolationWarnings(violations: KeyViolation[]): KeyViolation[];
|
|
28
|
+
/** How many levels a key path has under the convention. */
|
|
29
|
+
export declare function keyDepth(path: string, convention: KeyConvention): number;
|
|
30
|
+
/**
|
|
31
|
+
* Pure: every way `key` breaks the convention, in the order worth fixing. Use
|
|
32
|
+
* `KEY_VIOLATION_LEVEL` to tell what must block from what is only advice.
|
|
33
|
+
*
|
|
34
|
+
* An empty key is **legal** (a symbol-only source text has no name), so it is
|
|
35
|
+
* not a violation here — callers treat it as "cannot name", not as an error.
|
|
36
|
+
*
|
|
37
|
+
* The prefix itself is exempt: it is copied verbatim from the project settings,
|
|
38
|
+
* so the configured rules govern the path that follows it. Any boundary
|
|
39
|
+
* character may follow it, so legacy keys that joined it differently still count.
|
|
40
|
+
*/
|
|
41
|
+
export declare function checkI18nKey(key: string, convention: KeyConvention): KeyViolation[];
|
|
42
|
+
/**
|
|
43
|
+
* Which declared namespace a key belongs to. Names are relative to the
|
|
44
|
+
* project's key prefix: a key belongs to the namespace that what follows its
|
|
45
|
+
* prefix starts with, followed by a boundary character. Pure, so a client
|
|
46
|
+
* groups keys exactly the way the server does.
|
|
47
|
+
*
|
|
48
|
+
* Any boundary counts, not just the project's `keySeparator`: imports flatten
|
|
49
|
+
* nested JSON with `.`, so one project routinely holds both `s2w_a` and `s2w.a`.
|
|
50
|
+
*/
|
|
51
|
+
export declare const NAMESPACE_BOUNDARY: readonly ["_", ".", "-", ":", "/"];
|
|
52
|
+
/**
|
|
53
|
+
* The key without the project's prefix and the boundary after it. A key that
|
|
54
|
+
* does not carry the prefix comes back whole, so imported or legacy keys still
|
|
55
|
+
* group by the same relative names.
|
|
56
|
+
*/
|
|
57
|
+
export declare function stripProjectPrefix(key: string, projectPrefix: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Names are relative to the project prefix. Case-sensitive, like keys. The
|
|
60
|
+
* longest name wins should two ever both match.
|
|
61
|
+
*/
|
|
62
|
+
export declare function namespaceOf(key: string, names: readonly string[], projectPrefix: string): string | null;
|
|
1
63
|
/**
|
|
2
64
|
* Rules a client must apply the same way the server does. A draft key is named
|
|
3
65
|
* after the text it was created from, so a plugin and the server that disagree
|
package/dist/rules.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { a as checkI18nKey, c as keyViolationWarnings, i as KEY_VIOLATION_VALUES, n as KEY_VIOLATION_LEVEL, o as keyDepth, r as KEY_VIOLATION_TEXT, s as keyViolationErrors, t as KEY_STYLE_VALUES } from "./key-convention-C-urfySC.mjs";
|
|
1
2
|
// \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
@@ -20,7 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
20
21
|
value: mod,
|
|
21
22
|
enumerable: true
|
|
22
23
|
}) : target, mod));
|
|
23
|
-
// ../../shared/contract/
|
|
24
|
+
// ../../shared/contract/key-namespace.ts
|
|
24
25
|
var import_spark_md5 = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
25
26
|
(function(factory) {
|
|
26
27
|
if (typeof exports === "object") module.exports = factory();
|
|
@@ -620,6 +621,48 @@ var import_spark_md5 = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((
|
|
|
620
621
|
return SparkMD5;
|
|
621
622
|
});
|
|
622
623
|
})))(), 1);
|
|
624
|
+
/**
|
|
625
|
+
* Which declared namespace a key belongs to. Names are relative to the
|
|
626
|
+
* project's key prefix: a key belongs to the namespace that what follows its
|
|
627
|
+
* prefix starts with, followed by a boundary character. Pure, so a client
|
|
628
|
+
* groups keys exactly the way the server does.
|
|
629
|
+
*
|
|
630
|
+
* Any boundary counts, not just the project's `keySeparator`: imports flatten
|
|
631
|
+
* nested JSON with `.`, so one project routinely holds both `s2w_a` and `s2w.a`.
|
|
632
|
+
*/
|
|
633
|
+
const NAMESPACE_BOUNDARY = [
|
|
634
|
+
"_",
|
|
635
|
+
".",
|
|
636
|
+
"-",
|
|
637
|
+
":",
|
|
638
|
+
"/"
|
|
639
|
+
];
|
|
640
|
+
const BOUNDARY = new Set(NAMESPACE_BOUNDARY);
|
|
641
|
+
function startsWithBoundary(text, head) {
|
|
642
|
+
return Boolean(head) && text.startsWith(head) && BOUNDARY.has(text.charAt(head.length));
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* The key without the project's prefix and the boundary after it. A key that
|
|
646
|
+
* does not carry the prefix comes back whole, so imported or legacy keys still
|
|
647
|
+
* group by the same relative names.
|
|
648
|
+
*/
|
|
649
|
+
function stripProjectPrefix(key, projectPrefix) {
|
|
650
|
+
return startsWithBoundary(key, projectPrefix) ? key.slice(projectPrefix.length + 1) : key;
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Names are relative to the project prefix. Case-sensitive, like keys. The
|
|
654
|
+
* longest name wins should two ever both match.
|
|
655
|
+
*/
|
|
656
|
+
function namespaceOf(key, names, projectPrefix) {
|
|
657
|
+
const path = stripProjectPrefix(key, projectPrefix);
|
|
658
|
+
let best = null;
|
|
659
|
+
for (const name of names) {
|
|
660
|
+
if (!startsWithBoundary(path, name)) continue;
|
|
661
|
+
if (!best || name.length > best.length) best = name;
|
|
662
|
+
}
|
|
663
|
+
return best;
|
|
664
|
+
}
|
|
665
|
+
// ../../shared/contract/rules.ts
|
|
623
666
|
/** Whitespace is not part of the sentence: `'Save\n As'` and `'SaveAs'` collide on purpose. */
|
|
624
667
|
const fpTranslation = (text) => {
|
|
625
668
|
const normalized = text.replace(/\s+/g, "").trim();
|
|
@@ -652,4 +695,4 @@ function entryMatchesReleaseFilter(releaseIds, filter) {
|
|
|
652
695
|
if (filter === "unassigned") return ids.length === 0;
|
|
653
696
|
return ids.some((releaseId) => String(releaseId) === String(filter));
|
|
654
697
|
}
|
|
655
|
-
export { LEGACY_DRAFT_KEY_PREFIX, UNNAMED_KEY_PREFIX, entryMatchesReleaseFilter, formatI18nKeyDisplay, fpTranslation, isUnnamedKey };
|
|
698
|
+
export { KEY_STYLE_VALUES, KEY_VIOLATION_LEVEL, KEY_VIOLATION_TEXT, KEY_VIOLATION_VALUES, LEGACY_DRAFT_KEY_PREFIX, NAMESPACE_BOUNDARY, UNNAMED_KEY_PREFIX, checkI18nKey, entryMatchesReleaseFilter, formatI18nKeyDisplay, fpTranslation, isUnnamedKey, keyDepth, keyViolationErrors, keyViolationWarnings, namespaceOf, stripProjectPrefix };
|
package/package.json
CHANGED