@localness/contract 0.2.0 → 0.4.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/dist/index.d.mts CHANGED
@@ -20,6 +20,28 @@ export declare const releaseMembershipResultSchema: z.ZodObject<{
20
20
  changed: z.ZodNumber;
21
21
  }, z.core.$strip>;
22
22
  export type ReleaseMembershipResult = z.infer<typeof releaseMembershipResultSchema>;
23
+ /**
24
+ * A declared key namespace. Keys are grouped by name — a key belongs to the
25
+ * namespace it starts with, followed by a separator — so this carries no list
26
+ * of keys and never renames one.
27
+ */
28
+ export declare const keyNamespaceSchema: z.ZodObject<{
29
+ id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
30
+ name: z.ZodString;
31
+ sort: z.ZodNumber;
32
+ }, z.core.$strip>;
33
+ export type KeyNamespace = z.infer<typeof keyNamespaceSchema>;
34
+ /** `GET /api/projects/:id/i18n-keys/namespaces` */
35
+ export declare const i18nKeyNamespaceCountsSchema: z.ZodObject<{
36
+ total: z.ZodNumber;
37
+ ungrouped: z.ZodNumber;
38
+ byId: z.ZodRecord<z.ZodString, z.ZodNumber>;
39
+ suggestions: z.ZodArray<z.ZodObject<{
40
+ name: z.ZodString;
41
+ count: z.ZodNumber;
42
+ }, z.core.$strip>>;
43
+ }, z.core.$strip>;
44
+ export type I18nKeyNamespaceCounts = z.infer<typeof i18nKeyNamespaceCountsSchema>;
23
45
  /**
24
46
  * Response shapes of the public `/api/v1` delivery API. Callers outside the
25
47
  * Localness repo (the design-tool plugin, build tooling) validate against
@@ -53,6 +75,12 @@ export declare const deliveryMetaSchema: z.ZodObject<{
53
75
  createdAt: z.ZodOptional<z.ZodString>;
54
76
  updatedAt: z.ZodOptional<z.ZodString>;
55
77
  }, z.core.$strip>>;
78
+ namespace: z.ZodOptional<z.ZodNullable<z.ZodString>>;
79
+ namespaces: z.ZodOptional<z.ZodArray<z.ZodObject<{
80
+ id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
81
+ name: z.ZodString;
82
+ sort: z.ZodNumber;
83
+ }, z.core.$strip>>>;
56
84
  coverage: z.ZodObject<{
57
85
  keys: z.ZodNumber;
58
86
  projectKeys: z.ZodNumber;
package/dist/index.mjs CHANGED
@@ -20,6 +20,29 @@ const releaseMembershipResultSchema = z.object({
20
20
  /** How many ids actually changed; repeating an add reports 0. */
21
21
  changed: z.number()
22
22
  });
23
+ // ../../shared/contract/namespace.ts
24
+ /**
25
+ * A declared key namespace. Keys are grouped by name — a key belongs to the
26
+ * namespace it starts with, followed by a separator — so this carries no list
27
+ * of keys and never renames one.
28
+ */
29
+ const keyNamespaceSchema = z.object({
30
+ id: idSchema,
31
+ name: z.string(),
32
+ sort: z.number()
33
+ });
34
+ /** `GET /api/projects/:id/i18n-keys/namespaces` */
35
+ const i18nKeyNamespaceCountsSchema = z.object({
36
+ total: z.number(),
37
+ ungrouped: z.number(),
38
+ /** Namespace id → keys in it. */
39
+ byId: z.record(z.string(), z.number()),
40
+ /** First segments shared by Ungrouped keys, worth declaring. */
41
+ suggestions: z.array(z.object({
42
+ name: z.string(),
43
+ count: z.number()
44
+ }))
45
+ });
23
46
  // ../../shared/contract/delivery.ts
24
47
  /**
25
48
  * Response shapes of the public `/api/v1` delivery API. Callers outside the
@@ -47,6 +70,13 @@ const deliveryMetaSchema = z.object({
47
70
  release: z.number().nullable(),
48
71
  /** The names `?release=` accepts, which a caller cannot otherwise discover. */
49
72
  releases: z.array(projectReleaseSchema),
73
+ /**
74
+ * The namespace the response is scoped to — its name, or `__ungrouped__` —
75
+ * or null for all keys. Optional: servers before namespaces omit it.
76
+ */
77
+ namespace: z.string().nullable().optional(),
78
+ /** The names `?namespace=` accepts, in display order. */
79
+ namespaces: z.array(keyNamespaceSchema).optional(),
50
80
  coverage: z.object({
51
81
  keys: z.number(),
52
82
  projectKeys: z.number(),
@@ -190,4 +220,4 @@ const capturePageSchema = z.object({
190
220
  releaseIds: z.array(z.number()),
191
221
  tags: z.array(captureTagSchema)
192
222
  });
193
- export { captureKeyHitSchema, captureKeySearchSchema, captureMatchSchema, capturePageSchema, captureTagSchema, createPageResultSchema, deleteTagsResultSchema, deliveryBundleSchema, deliveryKeysSchema, deliveryLocaleSchema, deliveryMetaSchema, deliveryOutdatedSchema, deliveryProjectRefSchema, deliveryProjectsSchema, idSchema, importPageResultSchema, importPageTagsSchema, importedTagSchema, projectReleaseSchema, releaseMembershipResultSchema, uploadResultSchema };
223
+ export { captureKeyHitSchema, captureKeySearchSchema, captureMatchSchema, capturePageSchema, captureTagSchema, createPageResultSchema, deleteTagsResultSchema, deliveryBundleSchema, deliveryKeysSchema, deliveryLocaleSchema, deliveryMetaSchema, deliveryOutdatedSchema, deliveryProjectRefSchema, deliveryProjectsSchema, i18nKeyNamespaceCountsSchema, idSchema, importPageResultSchema, importPageTagsSchema, importedTagSchema, keyNamespaceSchema, projectReleaseSchema, releaseMembershipResultSchema, uploadResultSchema };
package/dist/rules.d.mts CHANGED
@@ -8,8 +8,16 @@ type RowId = string | number;
8
8
  /** Whitespace is not part of the sentence: `'Save\n As'` and `'SaveAs'` collide on purpose. */
9
9
  export declare const fpTranslation: (text: string) => string;
10
10
  /** Keys that only carry a text's fingerprint, awaiting a real name. */
11
- export declare const DRAFT_KEY_PREFIX = "__draft_";
12
- /** What a person sees for a key: a draft key's fingerprint is cut to five characters. */
11
+ export declare const UNNAMED_KEY_PREFIX = "__unnamed_";
12
+ /**
13
+ * The prefix before `__unnamed_`. It collided with the Draft publish status, so
14
+ * it was renamed; keys and clients minted under it still exist, so it is
15
+ * recognised everywhere but never written.
16
+ */
17
+ export declare const LEGACY_DRAFT_KEY_PREFIX = "__draft_";
18
+ /** Whether a key is a placeholder awaiting a real name, under either prefix. */
19
+ export declare const isUnnamedKey: (key: string) => boolean;
20
+ /** What a person sees for a key: an unnamed key's fingerprint is cut to five characters. */
13
21
  export declare function formatI18nKeyDisplay(key: string | null | undefined): string;
14
22
  /**
15
23
  * Which release the workspace is looking at: `'all'`, `'unassigned'`, or one
package/dist/rules.mjs CHANGED
@@ -626,14 +626,24 @@ const fpTranslation = (text) => {
626
626
  return import_spark_md5.default.hash(normalized);
627
627
  };
628
628
  /** Keys that only carry a text's fingerprint, awaiting a real name. */
629
- const DRAFT_KEY_PREFIX = "__draft_";
630
- /** What a person sees for a key: a draft key's fingerprint is cut to five characters. */
629
+ const UNNAMED_KEY_PREFIX = "__unnamed_";
630
+ /**
631
+ * The prefix before `__unnamed_`. It collided with the Draft publish status, so
632
+ * it was renamed; keys and clients minted under it still exist, so it is
633
+ * recognised everywhere but never written.
634
+ */
635
+ const LEGACY_DRAFT_KEY_PREFIX = "__draft_";
636
+ const unnamedPrefixOf = (key) => [UNNAMED_KEY_PREFIX, LEGACY_DRAFT_KEY_PREFIX].find((prefix) => key.startsWith(prefix));
637
+ /** Whether a key is a placeholder awaiting a real name, under either prefix. */
638
+ const isUnnamedKey = (key) => unnamedPrefixOf(key) !== void 0;
639
+ /** What a person sees for a key: an unnamed key's fingerprint is cut to five characters. */
631
640
  function formatI18nKeyDisplay(key) {
632
641
  if (!key) return "";
633
- if (!key.startsWith("__draft_")) return key;
634
- const hash = key.slice(8);
642
+ const prefix = unnamedPrefixOf(key);
643
+ if (!prefix) return key;
644
+ const hash = key.slice(prefix.length);
635
645
  if (hash.length <= 5) return key;
636
- return `${DRAFT_KEY_PREFIX}${hash.slice(0, 5)}`;
646
+ return `${prefix}${hash.slice(0, 5)}`;
637
647
  }
638
648
  /** Ids are compared as strings: a row's ids come back from JSON while a picker emits numbers. */
639
649
  function entryMatchesReleaseFilter(releaseIds, filter) {
@@ -642,4 +652,4 @@ function entryMatchesReleaseFilter(releaseIds, filter) {
642
652
  if (filter === "unassigned") return ids.length === 0;
643
653
  return ids.some((releaseId) => String(releaseId) === String(filter));
644
654
  }
645
- export { DRAFT_KEY_PREFIX, entryMatchesReleaseFilter, formatI18nKeyDisplay, fpTranslation };
655
+ export { LEGACY_DRAFT_KEY_PREFIX, UNNAMED_KEY_PREFIX, entryMatchesReleaseFilter, formatI18nKeyDisplay, fpTranslation, isUnnamedKey };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localness/contract",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Response contracts of the Localness public /api/v1: zod schemas and the types inferred from them.",
5
5
  "license": "Elastic-2.0",
6
6
  "type": "module",