@localness/contract 0.3.0 → 0.4.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/dist/index.d.mts +37 -0
- package/dist/index.mjs +35 -1
- package/dist/rules.d.mts +10 -2
- package/dist/rules.mjs +16 -6
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -66,6 +66,7 @@ export declare const deliveryMetaSchema: z.ZodObject<{
|
|
|
66
66
|
name: z.ZodString;
|
|
67
67
|
}, z.core.$strip>;
|
|
68
68
|
locales: z.ZodArray<z.ZodString>;
|
|
69
|
+
sourceLocale: z.ZodOptional<z.ZodString>;
|
|
69
70
|
localeFallback: z.ZodString;
|
|
70
71
|
release: z.ZodNullable<z.ZodNumber>;
|
|
71
72
|
releases: z.ZodArray<z.ZodObject<{
|
|
@@ -125,6 +126,42 @@ export declare const deliveryKeysSchema: z.ZodObject<{
|
|
|
125
126
|
generatedAt: z.ZodString;
|
|
126
127
|
}, z.core.$strip>;
|
|
127
128
|
export type DeliveryKeys = z.infer<typeof deliveryKeysSchema>;
|
|
129
|
+
export declare const deliveryLocaleStateNameSchema: z.ZodEnum<{
|
|
130
|
+
outdated: "outdated";
|
|
131
|
+
draft: "draft";
|
|
132
|
+
published: "published";
|
|
133
|
+
unpublished: "unpublished";
|
|
134
|
+
}>;
|
|
135
|
+
export type DeliveryLocaleStateName = z.infer<typeof deliveryLocaleStateNameSchema>;
|
|
136
|
+
/**
|
|
137
|
+
* `GET /api/v1/keys/states` — per-key, per-locale state, drafts included.
|
|
138
|
+
* Unlike every other delivery shape this carries draft text: a read token sees
|
|
139
|
+
* what the editor sees.
|
|
140
|
+
*/
|
|
141
|
+
export declare const deliveryKeyStatesSchema: z.ZodObject<{
|
|
142
|
+
sourceLocale: z.ZodString;
|
|
143
|
+
keys: z.ZodArray<z.ZodObject<{
|
|
144
|
+
id: z.ZodNumber;
|
|
145
|
+
key: z.ZodString;
|
|
146
|
+
releaseIds: z.ZodArray<z.ZodNumber>;
|
|
147
|
+
draft: z.ZodBoolean;
|
|
148
|
+
locales: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
149
|
+
draftText: z.ZodNullable<z.ZodString>;
|
|
150
|
+
publishedText: z.ZodNullable<z.ZodString>;
|
|
151
|
+
state: z.ZodEnum<{
|
|
152
|
+
outdated: "outdated";
|
|
153
|
+
draft: "draft";
|
|
154
|
+
published: "published";
|
|
155
|
+
unpublished: "unpublished";
|
|
156
|
+
}>;
|
|
157
|
+
}, z.core.$strip>>;
|
|
158
|
+
}, z.core.$strip>>;
|
|
159
|
+
total: z.ZodNumber;
|
|
160
|
+
offset: z.ZodNumber;
|
|
161
|
+
limit: z.ZodNumber;
|
|
162
|
+
generatedAt: z.ZodString;
|
|
163
|
+
}, z.core.$strip>;
|
|
164
|
+
export type DeliveryKeyStates = z.infer<typeof deliveryKeyStatesSchema>;
|
|
128
165
|
/**
|
|
129
166
|
* Response shapes of the write half of the public `/api/v1` API, plus the
|
|
130
167
|
* capture reads a design tool needs. Same versioning rule as `delivery.ts`:
|
package/dist/index.mjs
CHANGED
|
@@ -65,6 +65,8 @@ const deliveryMetaSchema = z.object({
|
|
|
65
65
|
name: z.string()
|
|
66
66
|
}),
|
|
67
67
|
locales: z.array(z.string()),
|
|
68
|
+
/** The project's source locale. Optional: servers before it omit it. */
|
|
69
|
+
sourceLocale: z.string().optional(),
|
|
68
70
|
localeFallback: z.string(),
|
|
69
71
|
/** The release the response is scoped to, or null for all keys. */
|
|
70
72
|
release: z.number().nullable(),
|
|
@@ -126,6 +128,38 @@ const deliveryKeysSchema = z.object({
|
|
|
126
128
|
/** ISO 8601. */
|
|
127
129
|
generatedAt: z.string()
|
|
128
130
|
});
|
|
131
|
+
const deliveryLocaleStateNameSchema = z.enum([
|
|
132
|
+
"draft",
|
|
133
|
+
"published",
|
|
134
|
+
"outdated",
|
|
135
|
+
"unpublished"
|
|
136
|
+
]);
|
|
137
|
+
/**
|
|
138
|
+
* `GET /api/v1/keys/states` — per-key, per-locale state, drafts included.
|
|
139
|
+
* Unlike every other delivery shape this carries draft text: a read token sees
|
|
140
|
+
* what the editor sees.
|
|
141
|
+
*/
|
|
142
|
+
const deliveryKeyStatesSchema = z.object({
|
|
143
|
+
sourceLocale: z.string(),
|
|
144
|
+
keys: z.array(z.object({
|
|
145
|
+
id: z.number(),
|
|
146
|
+
key: z.string(),
|
|
147
|
+
releaseIds: z.array(z.number()),
|
|
148
|
+
/** True while the key still has unpublished edits or was never published. */
|
|
149
|
+
draft: z.boolean(),
|
|
150
|
+
locales: z.record(z.string(), z.object({
|
|
151
|
+
draftText: z.string().nullable(),
|
|
152
|
+
publishedText: z.string().nullable(),
|
|
153
|
+
state: deliveryLocaleStateNameSchema
|
|
154
|
+
}))
|
|
155
|
+
})),
|
|
156
|
+
/** Keys in scope, before paging. */
|
|
157
|
+
total: z.number(),
|
|
158
|
+
offset: z.number(),
|
|
159
|
+
limit: z.number(),
|
|
160
|
+
/** ISO 8601. */
|
|
161
|
+
generatedAt: z.string()
|
|
162
|
+
});
|
|
129
163
|
// ../../shared/contract/import.ts
|
|
130
164
|
/**
|
|
131
165
|
* Response shapes of the write half of the public `/api/v1` API, plus the
|
|
@@ -220,4 +254,4 @@ const capturePageSchema = z.object({
|
|
|
220
254
|
releaseIds: z.array(z.number()),
|
|
221
255
|
tags: z.array(captureTagSchema)
|
|
222
256
|
});
|
|
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 };
|
|
257
|
+
export { captureKeyHitSchema, captureKeySearchSchema, captureMatchSchema, capturePageSchema, captureTagSchema, createPageResultSchema, deleteTagsResultSchema, deliveryBundleSchema, deliveryKeyStatesSchema, deliveryKeysSchema, deliveryLocaleSchema, deliveryLocaleStateNameSchema, 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
|
|
12
|
-
/**
|
|
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
|
|
630
|
-
/**
|
|
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
|
-
|
|
634
|
-
|
|
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 `${
|
|
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 {
|
|
655
|
+
export { LEGACY_DRAFT_KEY_PREFIX, UNNAMED_KEY_PREFIX, entryMatchesReleaseFilter, formatI18nKeyDisplay, fpTranslation, isUnnamedKey };
|
package/package.json
CHANGED