@contractspec/lib.contracts 0.0.0-canary-20260119225944 → 0.0.0-canary-20260202053150

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.
Files changed (166) hide show
  1. package/dist/app-config/{contracts.d.ts → app-config.contracts.d.ts} +52 -52
  2. package/dist/app-config/{contracts.js → app-config.contracts.js} +1 -1
  3. package/dist/app-config/lifecycle-contracts.d.ts +55 -55
  4. package/dist/app-config/runtime.d.ts +4 -4
  5. package/dist/app-config/spec.d.ts +2 -2
  6. package/dist/capabilities/capabilities.d.ts +64 -5
  7. package/dist/capabilities/capabilities.js +125 -0
  8. package/dist/capabilities/context.d.ts +88 -0
  9. package/dist/capabilities/context.js +87 -0
  10. package/dist/capabilities/docs/capabilities.docblock.js +191 -2
  11. package/dist/capabilities/guards.d.ts +110 -0
  12. package/dist/capabilities/guards.js +146 -0
  13. package/dist/capabilities/index.d.ts +4 -1
  14. package/dist/capabilities/index.js +4 -1
  15. package/dist/capabilities/validation.d.ts +76 -0
  16. package/dist/capabilities/validation.js +141 -0
  17. package/dist/client/react/feature-render.d.ts +2 -2
  18. package/dist/data-views/data-views.d.ts +2 -1
  19. package/dist/data-views/index.d.ts +2 -1
  20. package/dist/data-views/registry.d.ts +1 -1
  21. package/dist/data-views/report/contractVerificationTable.d.ts +10 -0
  22. package/dist/data-views/report/contractVerificationTable.js +95 -0
  23. package/dist/data-views/runtime.d.ts +2 -2
  24. package/dist/data-views/spec.d.ts +2 -8
  25. package/dist/data-views/types.d.ts +1 -1
  26. package/dist/docs/capabilities/documentationSystem.capability.d.ts +7 -0
  27. package/dist/docs/capabilities/documentationSystem.capability.js +71 -0
  28. package/dist/docs/capabilities/index.d.ts +2 -0
  29. package/dist/docs/capabilities/index.js +3 -0
  30. package/dist/docs/commands/docsGenerate.command.d.ts +95 -0
  31. package/dist/docs/commands/docsGenerate.command.js +142 -0
  32. package/dist/docs/commands/docsPublish.command.d.ts +64 -0
  33. package/dist/docs/commands/docsPublish.command.js +107 -0
  34. package/dist/docs/commands/index.d.ts +3 -0
  35. package/dist/docs/commands/index.js +4 -0
  36. package/dist/docs/constants.d.ts +7 -0
  37. package/dist/docs/constants.js +10 -0
  38. package/dist/docs/contracts.d.ts +442 -0
  39. package/dist/docs/contracts.js +58 -0
  40. package/dist/docs/ensure-docblocks.d.ts +1 -0
  41. package/dist/docs/ensure-docblocks.js +1 -0
  42. package/dist/docs/events/docsGenerated.event.d.ts +62 -0
  43. package/dist/docs/events/docsGenerated.event.js +53 -0
  44. package/dist/docs/events/docsPublished.event.d.ts +70 -0
  45. package/dist/docs/events/docsPublished.event.js +57 -0
  46. package/dist/docs/events/index.d.ts +3 -0
  47. package/dist/docs/events/index.js +4 -0
  48. package/dist/docs/forms/docsSearch.form.d.ts +22 -0
  49. package/dist/docs/forms/docsSearch.form.js +113 -0
  50. package/dist/docs/forms/index.d.ts +2 -0
  51. package/dist/docs/forms/index.js +3 -0
  52. package/dist/docs/index.d.ts +23 -2
  53. package/dist/docs/index.js +25 -1
  54. package/dist/docs/presentations/docsLayout.presentation.d.ts +7 -0
  55. package/dist/docs/presentations/docsLayout.presentation.js +35 -0
  56. package/dist/docs/presentations/docsReferencePage.presentation.d.ts +7 -0
  57. package/dist/docs/presentations/docsReferencePage.presentation.js +35 -0
  58. package/dist/docs/presentations/index.d.ts +3 -0
  59. package/dist/docs/presentations/index.js +4 -0
  60. package/dist/docs/queries/contractReference.query.d.ts +217 -0
  61. package/dist/docs/queries/contractReference.query.js +125 -0
  62. package/dist/docs/queries/docsIndex.query.d.ts +272 -0
  63. package/dist/docs/queries/docsIndex.query.js +133 -0
  64. package/dist/docs/queries/index.d.ts +3 -0
  65. package/dist/docs/queries/index.js +4 -0
  66. package/dist/docs/tech/cli.docblock.js +10 -0
  67. package/dist/docs/tech/docs-system.docblock.d.ts +1 -0
  68. package/dist/docs/tech/docs-system.docblock.js +128 -0
  69. package/dist/docs/tech/report-verification-table.docblock.d.ts +1 -0
  70. package/dist/docs/tech/report-verification-table.docblock.js +50 -0
  71. package/dist/docs/views/contractReference.dataView.d.ts +7 -0
  72. package/dist/docs/views/contractReference.dataView.js +80 -0
  73. package/dist/docs/views/docsIndex.dataView.d.ts +7 -0
  74. package/dist/docs/views/docsIndex.dataView.js +136 -0
  75. package/dist/docs/views/exampleCatalog.dataView.d.ts +7 -0
  76. package/dist/docs/views/exampleCatalog.dataView.js +91 -0
  77. package/dist/docs/views/index.d.ts +4 -0
  78. package/dist/docs/views/index.js +5 -0
  79. package/dist/events.d.ts +80 -14
  80. package/dist/events.js +33 -3
  81. package/dist/examples/schema.d.ts +12 -12
  82. package/dist/examples/types.d.ts +1 -1
  83. package/dist/experiments/spec.d.ts +9 -6
  84. package/dist/features/index.d.ts +2 -2
  85. package/dist/features/install.d.ts +4 -4
  86. package/dist/features/types.d.ts +28 -32
  87. package/dist/forms/forms.d.ts +1 -1
  88. package/dist/index.d.ts +60 -31
  89. package/dist/index.js +32 -4
  90. package/dist/install.d.ts +1 -1
  91. package/dist/integrations/openbanking/contracts/accounts.d.ts +67 -67
  92. package/dist/integrations/openbanking/contracts/balances.d.ts +35 -35
  93. package/dist/integrations/openbanking/contracts/transactions.d.ts +49 -49
  94. package/dist/integrations/openbanking/models.d.ts +55 -55
  95. package/dist/integrations/operations.d.ts +103 -103
  96. package/dist/integrations/spec.d.ts +2 -2
  97. package/dist/jsonschema.d.ts +1 -1
  98. package/dist/knowledge/operations.d.ts +67 -67
  99. package/dist/knowledge/spec.d.ts +1 -1
  100. package/dist/llm/exporters.d.ts +4 -4
  101. package/dist/llm/types.d.ts +1 -1
  102. package/dist/markdown.d.ts +2 -2
  103. package/dist/operations/index.d.ts +4 -1
  104. package/dist/operations/index.js +4 -1
  105. package/dist/operations/operation.d.ts +8 -2
  106. package/dist/operations/registry.d.ts +1 -1
  107. package/dist/operations/report/getContractVerificationStatus.d.ts +75 -0
  108. package/dist/operations/report/getContractVerificationStatus.js +96 -0
  109. package/dist/operations/report/index.d.ts +13 -0
  110. package/dist/operations/report/index.js +45 -0
  111. package/dist/ownership.d.ts +133 -8
  112. package/dist/ownership.js +25 -0
  113. package/dist/policy/context.d.ts +237 -0
  114. package/dist/policy/context.js +227 -0
  115. package/dist/policy/guards.d.ts +145 -0
  116. package/dist/policy/guards.js +254 -0
  117. package/dist/policy/index.d.ts +12 -1
  118. package/dist/policy/index.js +11 -1
  119. package/dist/policy/spec.d.ts +7 -4
  120. package/dist/policy/validation.d.ts +67 -0
  121. package/dist/policy/validation.js +307 -0
  122. package/dist/presentations/presentations.d.ts +6 -0
  123. package/dist/presentations/registry.d.ts +1 -1
  124. package/dist/registry.d.ts +1 -1
  125. package/dist/serialization/index.d.ts +3 -0
  126. package/dist/serialization/index.js +3 -0
  127. package/dist/serialization/serializers.d.ts +40 -0
  128. package/dist/serialization/serializers.js +148 -0
  129. package/dist/serialization/types.d.ts +103 -0
  130. package/dist/serialization/types.js +0 -0
  131. package/dist/server/rest-elysia.d.ts +1 -1
  132. package/dist/server/rest-express.d.ts +1 -1
  133. package/dist/server/rest-generic.d.ts +1 -1
  134. package/dist/server/rest-next-app.d.ts +1 -1
  135. package/dist/server/rest-next-mcp.d.ts +1 -1
  136. package/dist/server/rest-next-pages.d.ts +1 -1
  137. package/dist/telemetry/spec.d.ts +1 -1
  138. package/dist/telemetry/tracker.d.ts +3 -2
  139. package/dist/tests/runner.d.ts +1 -1
  140. package/dist/tests/spec.d.ts +17 -12
  141. package/dist/themes.d.ts +8 -5
  142. package/dist/translations/index.d.ts +6 -0
  143. package/dist/translations/index.js +5 -0
  144. package/dist/translations/registry.d.ts +144 -0
  145. package/dist/translations/registry.js +223 -0
  146. package/dist/translations/spec.d.ts +126 -0
  147. package/dist/translations/spec.js +31 -0
  148. package/dist/translations/validation.d.ts +85 -0
  149. package/dist/translations/validation.js +328 -0
  150. package/dist/types.d.ts +142 -16
  151. package/dist/versioning/index.d.ts +2 -1
  152. package/dist/versioning/index.js +2 -1
  153. package/dist/versioning/refs.d.ts +179 -0
  154. package/dist/versioning/refs.js +161 -0
  155. package/dist/workflow/context.d.ts +191 -0
  156. package/dist/workflow/context.js +227 -0
  157. package/dist/workflow/index.d.ts +6 -3
  158. package/dist/workflow/index.js +4 -2
  159. package/dist/workflow/spec.d.ts +4 -11
  160. package/dist/workflow/validation.d.ts +64 -2
  161. package/dist/workflow/validation.js +194 -1
  162. package/dist/workspace-config/contractsrc-schema.d.ts +3 -3
  163. package/dist/workspace-config/contractsrc-schema.js +1 -0
  164. package/dist/workspace-config/contractsrc-types.d.ts +7 -8
  165. package/dist/workspace-config/index.d.ts +2 -2
  166. package/package.json +52 -9
@@ -0,0 +1,103 @@
1
+ //#region src/serialization/types.d.ts
2
+ /**
3
+ * Serialized types for Server -> Client Component transfer.
4
+ *
5
+ * These are plain JSON-serializable versions of spec types that can be
6
+ * safely passed from Server Components to Client Components in Next.js.
7
+ */
8
+ /** Serialized schema model that can be passed to client components */
9
+ interface SerializedSchemaModel {
10
+ name: string;
11
+ description?: string | null;
12
+ fields: Record<string, SerializedFieldConfig>;
13
+ }
14
+ interface SerializedFieldConfig {
15
+ typeName: string;
16
+ isOptional: boolean;
17
+ isArray?: boolean;
18
+ }
19
+ /** Serialized operation spec for client components */
20
+ interface SerializedOperationSpec {
21
+ meta: {
22
+ key: string;
23
+ version: string;
24
+ stability?: string;
25
+ owners?: string[];
26
+ tags?: string[];
27
+ description?: string;
28
+ goal?: string;
29
+ context?: string;
30
+ };
31
+ io: {
32
+ input: SerializedSchemaModel | null;
33
+ output: SerializedSchemaModel | null;
34
+ };
35
+ policy?: {
36
+ auth?: string;
37
+ };
38
+ }
39
+ /** Serialized event spec for client components */
40
+ interface SerializedEventSpec {
41
+ meta: {
42
+ key: string;
43
+ version: string;
44
+ stability?: string;
45
+ owners?: string[];
46
+ tags?: string[];
47
+ description?: string;
48
+ };
49
+ payload: SerializedSchemaModel | null;
50
+ }
51
+ /** Serialized presentation spec for client components */
52
+ interface SerializedPresentationSpec {
53
+ meta: {
54
+ key: string;
55
+ version: string;
56
+ stability?: string;
57
+ owners?: string[];
58
+ tags?: string[];
59
+ description?: string;
60
+ goal?: string;
61
+ context?: string;
62
+ };
63
+ source: {
64
+ type: string;
65
+ framework?: string;
66
+ componentKey?: string;
67
+ };
68
+ targets?: string[];
69
+ }
70
+ /** Serialized data view spec for client components */
71
+ interface SerializedDataViewSpec {
72
+ meta: {
73
+ key: string;
74
+ version: string;
75
+ stability?: string;
76
+ owners?: string[];
77
+ tags?: string[];
78
+ description?: string;
79
+ title?: string;
80
+ };
81
+ /** Serialized source configuration */
82
+ source?: unknown;
83
+ /** Serialized view configuration */
84
+ view?: unknown;
85
+ }
86
+ /** Serialized form spec for client components */
87
+ interface SerializedFormSpec {
88
+ meta: {
89
+ key: string;
90
+ version?: string;
91
+ stability?: string;
92
+ owners?: string[];
93
+ tags?: string[];
94
+ description?: string;
95
+ title?: string;
96
+ };
97
+ /** Serialized form fields (passed through for display) */
98
+ fields?: unknown;
99
+ /** Serialized form actions (passed through for display) */
100
+ actions?: unknown;
101
+ }
102
+ //#endregion
103
+ export { SerializedDataViewSpec, SerializedEventSpec, SerializedFieldConfig, SerializedFormSpec, SerializedOperationSpec, SerializedPresentationSpec, SerializedSchemaModel };
File without changes
@@ -1,5 +1,5 @@
1
- import { OperationSpecRegistry } from "../operations/registry.js";
2
1
  import { HandlerCtx } from "../types.js";
2
+ import { OperationSpecRegistry } from "../operations/registry.js";
3
3
  import { RestOptions } from "./rest-generic.js";
4
4
  import { Elysia } from "elysia";
5
5
 
@@ -1,5 +1,5 @@
1
- import { OperationSpecRegistry } from "../operations/registry.js";
2
1
  import { HandlerCtx } from "../types.js";
2
+ import { OperationSpecRegistry } from "../operations/registry.js";
3
3
  import { RestOptions } from "./rest-generic.js";
4
4
  import { Request, Router } from "express";
5
5
 
@@ -1,5 +1,5 @@
1
- import { OperationSpecRegistry } from "../operations/registry.js";
2
1
  import { HandlerCtx } from "../types.js";
2
+ import { OperationSpecRegistry } from "../operations/registry.js";
3
3
 
4
4
  //#region src/server/rest-generic.d.ts
5
5
  interface RestOptions {
@@ -1,5 +1,5 @@
1
- import { OperationSpecRegistry } from "../operations/registry.js";
2
1
  import { HandlerCtx } from "../types.js";
2
+ import { OperationSpecRegistry } from "../operations/registry.js";
3
3
  import { RestOptions } from "./rest-generic.js";
4
4
 
5
5
  //#region src/server/rest-next-app.d.ts
@@ -1,5 +1,5 @@
1
- import { OperationSpecRegistry } from "../operations/registry.js";
2
1
  import { HandlerCtx } from "../types.js";
2
+ import { OperationSpecRegistry } from "../operations/registry.js";
3
3
 
4
4
  //#region src/server/rest-next-mcp.d.ts
5
5
  declare function makeNextMcpServerFromRegistry(reg: OperationSpecRegistry, ctxFactory: () => HandlerCtx): {
@@ -1,5 +1,5 @@
1
- import { OperationSpecRegistry } from "../operations/registry.js";
2
1
  import { HandlerCtx } from "../types.js";
2
+ import { OperationSpecRegistry } from "../operations/registry.js";
3
3
  import { RestOptions } from "./rest-generic.js";
4
4
  import { NextApiRequest, NextApiResponse } from "next";
5
5
 
@@ -1,5 +1,5 @@
1
- import { OwnerShipMeta } from "../ownership.js";
2
1
  import { SpecContractRegistry } from "../registry.js";
2
+ import { OwnerShipMeta } from "../ownership.js";
3
3
 
4
4
  //#region src/telemetry/spec.d.ts
5
5
  type TelemetryPrivacyLevel = 'public' | 'internal' | 'pii' | 'sensitive';
@@ -1,5 +1,6 @@
1
1
  import { TelemetryEventDef, TelemetryRegistry, TelemetrySpec } from "./spec.js";
2
2
  import { TelemetryAnomalyMonitor } from "./anomaly.js";
3
+ import { Actor, Channel } from "../types.js";
3
4
 
4
5
  //#region src/telemetry/tracker.d.ts
5
6
  interface TelemetryEventContext {
@@ -7,8 +8,8 @@ interface TelemetryEventContext {
7
8
  organizationId?: string | null;
8
9
  userId?: string | null;
9
10
  sessionId?: string | null;
10
- actor?: 'anonymous' | 'user' | 'admin';
11
- channel?: 'web' | 'mobile' | 'job' | 'agent';
11
+ actor?: Actor;
12
+ channel?: Channel;
12
13
  metadata?: Record<string, unknown>;
13
14
  }
14
15
  interface TelemetryDispatch {
@@ -1,6 +1,6 @@
1
1
  import { Assertion, TestScenario, TestSpec } from "./spec.js";
2
- import { OperationSpecRegistry } from "../operations/registry.js";
3
2
  import { HandlerCtx } from "../types.js";
3
+ import { OperationSpecRegistry } from "../operations/registry.js";
4
4
  import "../index.js";
5
5
 
6
6
  //#region src/tests/runner.d.ts
@@ -1,14 +1,18 @@
1
+ import { OptionalVersionedSpecRef } from "../versioning/refs.js";
1
2
  import { OwnerShipMeta } from "../ownership.js";
2
3
 
3
4
  //#region src/tests/spec.d.ts
4
- interface OperationTargetRef {
5
- key: string;
6
- version?: string;
7
- }
8
- interface WorkflowTargetRef {
9
- key: string;
10
- version?: string;
11
- }
5
+
6
+ /**
7
+ * Reference to an operation to be tested.
8
+ * Version is optional; when omitted, refers to the latest version.
9
+ */
10
+ type OperationTargetRef = OptionalVersionedSpecRef;
11
+ /**
12
+ * Reference to a workflow to be tested.
13
+ * Version is optional; when omitted, refers to the latest version.
14
+ */
15
+ type WorkflowTargetRef = OptionalVersionedSpecRef;
12
16
  type TestTarget = {
13
17
  type: 'operation';
14
18
  operation: OperationTargetRef;
@@ -66,10 +70,11 @@ interface TestSpec {
66
70
  scenarios: TestScenario[];
67
71
  coverage?: CoverageRequirement;
68
72
  }
69
- interface TestSpecRef {
70
- key: string;
71
- version?: string;
72
- }
73
+ /**
74
+ * Reference to a test spec.
75
+ * Version is optional; when omitted, refers to the latest version.
76
+ */
77
+ type TestSpecRef = OptionalVersionedSpecRef;
73
78
  declare class TestRegistry {
74
79
  private readonly items;
75
80
  register(spec: TestSpec): this;
package/dist/themes.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { OwnerShipMeta } from "./ownership.js";
1
+ import { VersionedSpecRef } from "./versioning/refs.js";
2
2
  import { SpecContractRegistry } from "./registry.js";
3
+ import { OwnerShipMeta } from "./ownership.js";
3
4
 
4
5
  //#region src/themes.d.ts
6
+ /** Scope at which a theme can be applied. */
5
7
  type ThemeScope = 'global' | 'tenant' | 'user';
6
8
  interface ThemeToken<T> {
7
9
  value: T;
@@ -39,10 +41,11 @@ interface ThemeSpec {
39
41
  components?: ComponentVariantSpec[];
40
42
  overrides?: ThemeOverride[];
41
43
  }
42
- interface ThemeRef {
43
- key: string;
44
- version: string;
45
- }
44
+ /**
45
+ * Reference to a theme spec.
46
+ * Uses key and version to identify a specific theme.
47
+ */
48
+ type ThemeRef = VersionedSpecRef;
46
49
  declare class ThemeRegistry extends SpecContractRegistry<'theme', ThemeSpec> {
47
50
  constructor(items?: ThemeSpec[]);
48
51
  }
@@ -0,0 +1,6 @@
1
+ import { BlueprintTranslationCatalog, PlatformTranslationCatalog, TranslationCatalogMeta, TranslationEntry } from "./catalog.js";
2
+ import { TenantTranslationOverride } from "./tenant.js";
3
+ import { Locale, MessageKey, MessageVariant, PlaceholderDef, PlaceholderType, PluralCategory, PluralRule, PluralRuleSet, TranslationMessage, TranslationMessages, TranslationMeta, TranslationRef, TranslationSpec, VariantType, defineTranslation } from "./spec.js";
4
+ import { TranslationLookupResult, TranslationRegistry, TranslationRegistryStats } from "./registry.js";
5
+ import { ICUValidationResult, MissingTranslation, TranslationValidationError, TranslationValidationIssue, TranslationValidationLevel, TranslationValidationResult, assertTranslationSpecValid, findAllMissingTranslations, findMissingTranslations, validateICUFormat, validateTranslationRegistry, validateTranslationSpec } from "./validation.js";
6
+ export { type BlueprintTranslationCatalog, ICUValidationResult, Locale, MessageKey, MessageVariant, MissingTranslation, PlaceholderDef, PlaceholderType, type PlatformTranslationCatalog, PluralCategory, PluralRule, PluralRuleSet, TenantTranslationOverride, type TranslationCatalogMeta, type TranslationEntry, TranslationLookupResult, TranslationMessage, TranslationMessages, TranslationMeta, TranslationRef, TranslationRegistry, TranslationRegistryStats, TranslationSpec, TranslationValidationError, TranslationValidationIssue, TranslationValidationLevel, TranslationValidationResult, VariantType, assertTranslationSpecValid, defineTranslation, findAllMissingTranslations, findMissingTranslations, validateICUFormat, validateTranslationRegistry, validateTranslationSpec };
@@ -0,0 +1,5 @@
1
+ import { defineTranslation } from "./spec.js";
2
+ import { TranslationRegistry } from "./registry.js";
3
+ import { TranslationValidationError, assertTranslationSpecValid, findAllMissingTranslations, findMissingTranslations, validateICUFormat, validateTranslationRegistry, validateTranslationSpec } from "./validation.js";
4
+
5
+ export { TranslationRegistry, TranslationValidationError, assertTranslationSpecValid, defineTranslation, findAllMissingTranslations, findMissingTranslations, validateICUFormat, validateTranslationRegistry, validateTranslationSpec };
@@ -0,0 +1,144 @@
1
+ import { Locale, MessageKey, TranslationMessage, TranslationSpec } from "./spec.js";
2
+
3
+ //#region src/translations/registry.d.ts
4
+
5
+ interface TranslationLookupResult {
6
+ spec: TranslationSpec;
7
+ message: TranslationMessage;
8
+ locale: Locale;
9
+ fromFallback: boolean;
10
+ }
11
+ interface TranslationRegistryStats {
12
+ totalSpecs: number;
13
+ locales: Locale[];
14
+ domains: string[];
15
+ totalMessages: number;
16
+ }
17
+ /**
18
+ * Registry for translation specs with locale-aware lookup.
19
+ */
20
+ declare class TranslationRegistry {
21
+ private readonly specs;
22
+ private readonly latestByLocale;
23
+ private readonly locales;
24
+ private readonly domains;
25
+ constructor(items?: TranslationSpec[]);
26
+ /**
27
+ * Register a translation spec.
28
+ *
29
+ * @param spec - Translation spec to register
30
+ */
31
+ register(spec: TranslationSpec): void;
32
+ /**
33
+ * Get a translation spec by key, version, and locale.
34
+ *
35
+ * @param key - Translation spec key
36
+ * @param version - Version string
37
+ * @param locale - Locale code
38
+ * @returns Translation spec or undefined
39
+ */
40
+ get(key: string, version: string, locale: Locale): TranslationSpec | undefined;
41
+ /**
42
+ * Get the latest version of a translation spec for a locale.
43
+ *
44
+ * @param key - Translation spec key
45
+ * @param locale - Locale code
46
+ * @returns Translation spec or undefined
47
+ */
48
+ getLatest(key: string, locale: Locale): TranslationSpec | undefined;
49
+ /**
50
+ * Get a specific message from a translation spec.
51
+ *
52
+ * @param specKey - Translation spec key
53
+ * @param messageKey - Message key within the spec
54
+ * @param locale - Locale code
55
+ * @param version - Optional version (uses latest if not specified)
56
+ * @returns Translation message or undefined
57
+ */
58
+ getMessage(specKey: string, messageKey: MessageKey, locale: Locale, version?: string): TranslationMessage | undefined;
59
+ /**
60
+ * Get a message value with fallback chain support.
61
+ *
62
+ * @param specKey - Translation spec key
63
+ * @param messageKey - Message key within the spec
64
+ * @param locale - Primary locale
65
+ * @param fallbackLocale - Fallback locale (optional, uses spec's fallback if not provided)
66
+ * @param version - Optional version (uses latest if not specified)
67
+ * @returns Translation lookup result or undefined
68
+ */
69
+ getWithFallback(specKey: string, messageKey: MessageKey, locale: Locale, fallbackLocale?: Locale, version?: string): TranslationLookupResult | undefined;
70
+ /**
71
+ * Get a message value string with fallback.
72
+ *
73
+ * Convenience method that returns just the string value or a fallback.
74
+ *
75
+ * @param specKey - Translation spec key
76
+ * @param messageKey - Message key
77
+ * @param locale - Primary locale
78
+ * @param fallback - String to return if message not found (default: messageKey)
79
+ * @returns Message value or fallback
80
+ */
81
+ getValue(specKey: string, messageKey: MessageKey, locale: Locale, fallback?: string): string;
82
+ /**
83
+ * List all locales available for a spec key.
84
+ *
85
+ * @param specKey - Translation spec key
86
+ * @returns Array of available locales
87
+ */
88
+ listLocales(specKey: string): Locale[];
89
+ /**
90
+ * List all translation specs.
91
+ *
92
+ * @returns Array of all registered translation specs
93
+ */
94
+ list(): TranslationSpec[];
95
+ /**
96
+ * List translation specs by locale.
97
+ *
98
+ * @param locale - Locale to filter by
99
+ * @returns Array of translation specs for the locale
100
+ */
101
+ listByLocale(locale: Locale): TranslationSpec[];
102
+ /**
103
+ * List translation specs by domain.
104
+ *
105
+ * @param domain - Domain to filter by
106
+ * @returns Array of translation specs for the domain
107
+ */
108
+ listByDomain(domain: string): TranslationSpec[];
109
+ /**
110
+ * Check if a translation spec exists.
111
+ *
112
+ * @param key - Translation spec key
113
+ * @param locale - Locale code
114
+ * @param version - Optional version
115
+ * @returns True if spec exists
116
+ */
117
+ has(key: string, locale: Locale, version?: string): boolean;
118
+ /**
119
+ * Get all registered locales.
120
+ *
121
+ * @returns Set of all registered locales
122
+ */
123
+ getLocales(): ReadonlySet<Locale>;
124
+ /**
125
+ * Get all registered domains.
126
+ *
127
+ * @returns Set of all registered domains
128
+ */
129
+ getDomains(): ReadonlySet<string>;
130
+ /**
131
+ * Get registry statistics.
132
+ *
133
+ * @returns Registry statistics
134
+ */
135
+ getStats(): TranslationRegistryStats;
136
+ /**
137
+ * Clear all registered specs.
138
+ */
139
+ clear(): void;
140
+ private makeKey;
141
+ private isNewerVersion;
142
+ }
143
+ //#endregion
144
+ export { TranslationLookupResult, TranslationRegistry, TranslationRegistryStats };
@@ -0,0 +1,223 @@
1
+ //#region src/translations/registry.ts
2
+ /**
3
+ * Registry for translation specs with locale-aware lookup.
4
+ */
5
+ var TranslationRegistry = class {
6
+ specs = /* @__PURE__ */ new Map();
7
+ latestByLocale = /* @__PURE__ */ new Map();
8
+ locales = /* @__PURE__ */ new Set();
9
+ domains = /* @__PURE__ */ new Set();
10
+ constructor(items) {
11
+ if (items) for (const spec of items) this.register(spec);
12
+ }
13
+ /**
14
+ * Register a translation spec.
15
+ *
16
+ * @param spec - Translation spec to register
17
+ */
18
+ register(spec) {
19
+ const fullKey = this.makeKey(spec.meta.key, spec.meta.version, spec.locale);
20
+ this.specs.set(fullKey, spec);
21
+ const localeKey = `${spec.meta.key}:${spec.locale}`;
22
+ const existing = this.latestByLocale.get(localeKey);
23
+ if (!existing || this.isNewerVersion(spec.meta.version, existing.meta.version)) this.latestByLocale.set(localeKey, spec);
24
+ this.locales.add(spec.locale);
25
+ this.domains.add(spec.meta.domain);
26
+ }
27
+ /**
28
+ * Get a translation spec by key, version, and locale.
29
+ *
30
+ * @param key - Translation spec key
31
+ * @param version - Version string
32
+ * @param locale - Locale code
33
+ * @returns Translation spec or undefined
34
+ */
35
+ get(key, version, locale) {
36
+ return this.specs.get(this.makeKey(key, version, locale));
37
+ }
38
+ /**
39
+ * Get the latest version of a translation spec for a locale.
40
+ *
41
+ * @param key - Translation spec key
42
+ * @param locale - Locale code
43
+ * @returns Translation spec or undefined
44
+ */
45
+ getLatest(key, locale) {
46
+ return this.latestByLocale.get(`${key}:${locale}`);
47
+ }
48
+ /**
49
+ * Get a specific message from a translation spec.
50
+ *
51
+ * @param specKey - Translation spec key
52
+ * @param messageKey - Message key within the spec
53
+ * @param locale - Locale code
54
+ * @param version - Optional version (uses latest if not specified)
55
+ * @returns Translation message or undefined
56
+ */
57
+ getMessage(specKey, messageKey, locale, version) {
58
+ const spec = version ? this.get(specKey, version, locale) : this.getLatest(specKey, locale);
59
+ if (!spec) return void 0;
60
+ return spec.messages[messageKey];
61
+ }
62
+ /**
63
+ * Get a message value with fallback chain support.
64
+ *
65
+ * @param specKey - Translation spec key
66
+ * @param messageKey - Message key within the spec
67
+ * @param locale - Primary locale
68
+ * @param fallbackLocale - Fallback locale (optional, uses spec's fallback if not provided)
69
+ * @param version - Optional version (uses latest if not specified)
70
+ * @returns Translation lookup result or undefined
71
+ */
72
+ getWithFallback(specKey, messageKey, locale, fallbackLocale, version) {
73
+ const spec = version ? this.get(specKey, version, locale) : this.getLatest(specKey, locale);
74
+ if (spec) {
75
+ const message = spec.messages[messageKey];
76
+ if (message) return {
77
+ spec,
78
+ message,
79
+ locale,
80
+ fromFallback: false
81
+ };
82
+ fallbackLocale = fallbackLocale ?? spec.fallback;
83
+ }
84
+ if (fallbackLocale && fallbackLocale !== locale) {
85
+ const fallbackSpec = version ? this.get(specKey, version, fallbackLocale) : this.getLatest(specKey, fallbackLocale);
86
+ if (fallbackSpec) {
87
+ const message = fallbackSpec.messages[messageKey];
88
+ if (message) return {
89
+ spec: fallbackSpec,
90
+ message,
91
+ locale: fallbackLocale,
92
+ fromFallback: true
93
+ };
94
+ }
95
+ }
96
+ }
97
+ /**
98
+ * Get a message value string with fallback.
99
+ *
100
+ * Convenience method that returns just the string value or a fallback.
101
+ *
102
+ * @param specKey - Translation spec key
103
+ * @param messageKey - Message key
104
+ * @param locale - Primary locale
105
+ * @param fallback - String to return if message not found (default: messageKey)
106
+ * @returns Message value or fallback
107
+ */
108
+ getValue(specKey, messageKey, locale, fallback) {
109
+ return this.getWithFallback(specKey, messageKey, locale)?.message.value ?? fallback ?? messageKey;
110
+ }
111
+ /**
112
+ * List all locales available for a spec key.
113
+ *
114
+ * @param specKey - Translation spec key
115
+ * @returns Array of available locales
116
+ */
117
+ listLocales(specKey) {
118
+ const locales = [];
119
+ for (const [key, spec] of this.specs.entries()) if (key.startsWith(`${specKey}:`)) {
120
+ if (!locales.includes(spec.locale)) locales.push(spec.locale);
121
+ }
122
+ return locales;
123
+ }
124
+ /**
125
+ * List all translation specs.
126
+ *
127
+ * @returns Array of all registered translation specs
128
+ */
129
+ list() {
130
+ return [...this.specs.values()];
131
+ }
132
+ /**
133
+ * List translation specs by locale.
134
+ *
135
+ * @param locale - Locale to filter by
136
+ * @returns Array of translation specs for the locale
137
+ */
138
+ listByLocale(locale) {
139
+ return [...this.specs.values()].filter((s) => s.locale === locale);
140
+ }
141
+ /**
142
+ * List translation specs by domain.
143
+ *
144
+ * @param domain - Domain to filter by
145
+ * @returns Array of translation specs for the domain
146
+ */
147
+ listByDomain(domain) {
148
+ return [...this.specs.values()].filter((s) => s.meta.domain === domain);
149
+ }
150
+ /**
151
+ * Check if a translation spec exists.
152
+ *
153
+ * @param key - Translation spec key
154
+ * @param locale - Locale code
155
+ * @param version - Optional version
156
+ * @returns True if spec exists
157
+ */
158
+ has(key, locale, version) {
159
+ if (version) return this.specs.has(this.makeKey(key, version, locale));
160
+ return this.latestByLocale.has(`${key}:${locale}`);
161
+ }
162
+ /**
163
+ * Get all registered locales.
164
+ *
165
+ * @returns Set of all registered locales
166
+ */
167
+ getLocales() {
168
+ return this.locales;
169
+ }
170
+ /**
171
+ * Get all registered domains.
172
+ *
173
+ * @returns Set of all registered domains
174
+ */
175
+ getDomains() {
176
+ return this.domains;
177
+ }
178
+ /**
179
+ * Get registry statistics.
180
+ *
181
+ * @returns Registry statistics
182
+ */
183
+ getStats() {
184
+ let totalMessages = 0;
185
+ for (const spec of this.specs.values()) totalMessages += Object.keys(spec.messages).length;
186
+ return {
187
+ totalSpecs: this.specs.size,
188
+ locales: [...this.locales],
189
+ domains: [...this.domains],
190
+ totalMessages
191
+ };
192
+ }
193
+ /**
194
+ * Clear all registered specs.
195
+ */
196
+ clear() {
197
+ this.specs.clear();
198
+ this.latestByLocale.clear();
199
+ this.locales.clear();
200
+ this.domains.clear();
201
+ }
202
+ makeKey(key, version, locale) {
203
+ return `${key}:${version}:${locale}`;
204
+ }
205
+ isNewerVersion(a, b) {
206
+ const parseVersion = (v) => {
207
+ const parts = v.split(".").map(Number);
208
+ return {
209
+ major: parts[0] ?? 0,
210
+ minor: parts[1] ?? 0,
211
+ patch: parts[2] ?? 0
212
+ };
213
+ };
214
+ const va = parseVersion(a);
215
+ const vb = parseVersion(b);
216
+ if (va.major !== vb.major) return va.major > vb.major;
217
+ if (va.minor !== vb.minor) return va.minor > vb.minor;
218
+ return va.patch > vb.patch;
219
+ }
220
+ };
221
+
222
+ //#endregion
223
+ export { TranslationRegistry };