@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.
- package/dist/app-config/{contracts.d.ts → app-config.contracts.d.ts} +52 -52
- package/dist/app-config/{contracts.js → app-config.contracts.js} +1 -1
- package/dist/app-config/lifecycle-contracts.d.ts +55 -55
- package/dist/app-config/runtime.d.ts +4 -4
- package/dist/app-config/spec.d.ts +2 -2
- package/dist/capabilities/capabilities.d.ts +64 -5
- package/dist/capabilities/capabilities.js +125 -0
- package/dist/capabilities/context.d.ts +88 -0
- package/dist/capabilities/context.js +87 -0
- package/dist/capabilities/docs/capabilities.docblock.js +191 -2
- package/dist/capabilities/guards.d.ts +110 -0
- package/dist/capabilities/guards.js +146 -0
- package/dist/capabilities/index.d.ts +4 -1
- package/dist/capabilities/index.js +4 -1
- package/dist/capabilities/validation.d.ts +76 -0
- package/dist/capabilities/validation.js +141 -0
- package/dist/client/react/feature-render.d.ts +2 -2
- package/dist/data-views/data-views.d.ts +2 -1
- package/dist/data-views/index.d.ts +2 -1
- package/dist/data-views/registry.d.ts +1 -1
- package/dist/data-views/report/contractVerificationTable.d.ts +10 -0
- package/dist/data-views/report/contractVerificationTable.js +95 -0
- package/dist/data-views/runtime.d.ts +2 -2
- package/dist/data-views/spec.d.ts +2 -8
- package/dist/data-views/types.d.ts +1 -1
- package/dist/docs/capabilities/documentationSystem.capability.d.ts +7 -0
- package/dist/docs/capabilities/documentationSystem.capability.js +71 -0
- package/dist/docs/capabilities/index.d.ts +2 -0
- package/dist/docs/capabilities/index.js +3 -0
- package/dist/docs/commands/docsGenerate.command.d.ts +95 -0
- package/dist/docs/commands/docsGenerate.command.js +142 -0
- package/dist/docs/commands/docsPublish.command.d.ts +64 -0
- package/dist/docs/commands/docsPublish.command.js +107 -0
- package/dist/docs/commands/index.d.ts +3 -0
- package/dist/docs/commands/index.js +4 -0
- package/dist/docs/constants.d.ts +7 -0
- package/dist/docs/constants.js +10 -0
- package/dist/docs/contracts.d.ts +442 -0
- package/dist/docs/contracts.js +58 -0
- package/dist/docs/ensure-docblocks.d.ts +1 -0
- package/dist/docs/ensure-docblocks.js +1 -0
- package/dist/docs/events/docsGenerated.event.d.ts +62 -0
- package/dist/docs/events/docsGenerated.event.js +53 -0
- package/dist/docs/events/docsPublished.event.d.ts +70 -0
- package/dist/docs/events/docsPublished.event.js +57 -0
- package/dist/docs/events/index.d.ts +3 -0
- package/dist/docs/events/index.js +4 -0
- package/dist/docs/forms/docsSearch.form.d.ts +22 -0
- package/dist/docs/forms/docsSearch.form.js +113 -0
- package/dist/docs/forms/index.d.ts +2 -0
- package/dist/docs/forms/index.js +3 -0
- package/dist/docs/index.d.ts +23 -2
- package/dist/docs/index.js +25 -1
- package/dist/docs/presentations/docsLayout.presentation.d.ts +7 -0
- package/dist/docs/presentations/docsLayout.presentation.js +35 -0
- package/dist/docs/presentations/docsReferencePage.presentation.d.ts +7 -0
- package/dist/docs/presentations/docsReferencePage.presentation.js +35 -0
- package/dist/docs/presentations/index.d.ts +3 -0
- package/dist/docs/presentations/index.js +4 -0
- package/dist/docs/queries/contractReference.query.d.ts +217 -0
- package/dist/docs/queries/contractReference.query.js +125 -0
- package/dist/docs/queries/docsIndex.query.d.ts +272 -0
- package/dist/docs/queries/docsIndex.query.js +133 -0
- package/dist/docs/queries/index.d.ts +3 -0
- package/dist/docs/queries/index.js +4 -0
- package/dist/docs/tech/cli.docblock.js +10 -0
- package/dist/docs/tech/docs-system.docblock.d.ts +1 -0
- package/dist/docs/tech/docs-system.docblock.js +128 -0
- package/dist/docs/tech/report-verification-table.docblock.d.ts +1 -0
- package/dist/docs/tech/report-verification-table.docblock.js +50 -0
- package/dist/docs/views/contractReference.dataView.d.ts +7 -0
- package/dist/docs/views/contractReference.dataView.js +80 -0
- package/dist/docs/views/docsIndex.dataView.d.ts +7 -0
- package/dist/docs/views/docsIndex.dataView.js +136 -0
- package/dist/docs/views/exampleCatalog.dataView.d.ts +7 -0
- package/dist/docs/views/exampleCatalog.dataView.js +91 -0
- package/dist/docs/views/index.d.ts +4 -0
- package/dist/docs/views/index.js +5 -0
- package/dist/events.d.ts +80 -14
- package/dist/events.js +33 -3
- package/dist/examples/schema.d.ts +12 -12
- package/dist/examples/types.d.ts +1 -1
- package/dist/experiments/spec.d.ts +9 -6
- package/dist/features/index.d.ts +2 -2
- package/dist/features/install.d.ts +4 -4
- package/dist/features/types.d.ts +28 -32
- package/dist/forms/forms.d.ts +1 -1
- package/dist/index.d.ts +60 -31
- package/dist/index.js +32 -4
- package/dist/install.d.ts +1 -1
- package/dist/integrations/openbanking/contracts/accounts.d.ts +67 -67
- package/dist/integrations/openbanking/contracts/balances.d.ts +35 -35
- package/dist/integrations/openbanking/contracts/transactions.d.ts +49 -49
- package/dist/integrations/openbanking/models.d.ts +55 -55
- package/dist/integrations/operations.d.ts +103 -103
- package/dist/integrations/spec.d.ts +2 -2
- package/dist/jsonschema.d.ts +1 -1
- package/dist/knowledge/operations.d.ts +67 -67
- package/dist/knowledge/spec.d.ts +1 -1
- package/dist/llm/exporters.d.ts +4 -4
- package/dist/llm/types.d.ts +1 -1
- package/dist/markdown.d.ts +2 -2
- package/dist/operations/index.d.ts +4 -1
- package/dist/operations/index.js +4 -1
- package/dist/operations/operation.d.ts +8 -2
- package/dist/operations/registry.d.ts +1 -1
- package/dist/operations/report/getContractVerificationStatus.d.ts +75 -0
- package/dist/operations/report/getContractVerificationStatus.js +96 -0
- package/dist/operations/report/index.d.ts +13 -0
- package/dist/operations/report/index.js +45 -0
- package/dist/ownership.d.ts +133 -8
- package/dist/ownership.js +25 -0
- package/dist/policy/context.d.ts +237 -0
- package/dist/policy/context.js +227 -0
- package/dist/policy/guards.d.ts +145 -0
- package/dist/policy/guards.js +254 -0
- package/dist/policy/index.d.ts +12 -1
- package/dist/policy/index.js +11 -1
- package/dist/policy/spec.d.ts +7 -4
- package/dist/policy/validation.d.ts +67 -0
- package/dist/policy/validation.js +307 -0
- package/dist/presentations/presentations.d.ts +6 -0
- package/dist/presentations/registry.d.ts +1 -1
- package/dist/registry.d.ts +1 -1
- package/dist/serialization/index.d.ts +3 -0
- package/dist/serialization/index.js +3 -0
- package/dist/serialization/serializers.d.ts +40 -0
- package/dist/serialization/serializers.js +148 -0
- package/dist/serialization/types.d.ts +103 -0
- package/dist/serialization/types.js +0 -0
- package/dist/server/rest-elysia.d.ts +1 -1
- package/dist/server/rest-express.d.ts +1 -1
- package/dist/server/rest-generic.d.ts +1 -1
- package/dist/server/rest-next-app.d.ts +1 -1
- package/dist/server/rest-next-mcp.d.ts +1 -1
- package/dist/server/rest-next-pages.d.ts +1 -1
- package/dist/telemetry/spec.d.ts +1 -1
- package/dist/telemetry/tracker.d.ts +3 -2
- package/dist/tests/runner.d.ts +1 -1
- package/dist/tests/spec.d.ts +17 -12
- package/dist/themes.d.ts +8 -5
- package/dist/translations/index.d.ts +6 -0
- package/dist/translations/index.js +5 -0
- package/dist/translations/registry.d.ts +144 -0
- package/dist/translations/registry.js +223 -0
- package/dist/translations/spec.d.ts +126 -0
- package/dist/translations/spec.js +31 -0
- package/dist/translations/validation.d.ts +85 -0
- package/dist/translations/validation.js +328 -0
- package/dist/types.d.ts +142 -16
- package/dist/versioning/index.d.ts +2 -1
- package/dist/versioning/index.js +2 -1
- package/dist/versioning/refs.d.ts +179 -0
- package/dist/versioning/refs.js +161 -0
- package/dist/workflow/context.d.ts +191 -0
- package/dist/workflow/context.js +227 -0
- package/dist/workflow/index.d.ts +6 -3
- package/dist/workflow/index.js +4 -2
- package/dist/workflow/spec.d.ts +4 -11
- package/dist/workflow/validation.d.ts +64 -2
- package/dist/workflow/validation.js +194 -1
- package/dist/workspace-config/contractsrc-schema.d.ts +3 -3
- package/dist/workspace-config/contractsrc-schema.js +1 -0
- package/dist/workspace-config/contractsrc-types.d.ts +7 -8
- package/dist/workspace-config/index.d.ts +2 -2
- 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 { 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
|
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
|
|
package/dist/telemetry/spec.d.ts
CHANGED
|
@@ -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?:
|
|
11
|
-
channel?:
|
|
11
|
+
actor?: Actor;
|
|
12
|
+
channel?: Channel;
|
|
12
13
|
metadata?: Record<string, unknown>;
|
|
13
14
|
}
|
|
14
15
|
interface TelemetryDispatch {
|
package/dist/tests/runner.d.ts
CHANGED
|
@@ -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
|
package/dist/tests/spec.d.ts
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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 {
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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 };
|