@contractspec/lib.contracts 1.44.1 → 1.45.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/README.md +1 -1
- package/dist/app-config/app-config.feature.js +6 -6
- package/dist/app-config/contracts.d.ts +1 -1
- package/dist/app-config/contracts.js +13 -13
- package/dist/app-config/events.d.ts +8 -8
- package/dist/app-config/events.js +12 -12
- package/dist/app-config/lifecycle-contracts.d.ts +11 -11
- package/dist/app-config/lifecycle-contracts.js +19 -19
- package/dist/app-config/lifecycle.d.ts +2 -2
- package/dist/app-config/runtime.d.ts +3 -3
- package/dist/app-config/spec.d.ts +10 -12
- package/dist/app-config/spec.js +5 -26
- package/dist/capabilities/capabilities.d.ts +4 -11
- package/dist/capabilities/capabilities.js +3 -5
- package/dist/capabilities/openbanking.js +10 -10
- package/dist/client/react/form-render.js +1 -0
- package/dist/contract-registry/schemas.d.ts +8 -8
- package/dist/contract-registry/schemas.js +1 -1
- package/dist/contract-registry/types.d.ts +1 -1
- package/dist/data-views/data-views.js +1 -0
- package/dist/data-views/registry.d.ts +3 -37
- package/dist/data-views/registry.js +4 -66
- package/dist/data-views/runtime.d.ts +1 -1
- package/dist/data-views/runtime.js +2 -0
- package/dist/data-views/spec.d.ts +2 -2
- package/dist/docs/index.d.ts +2 -2
- package/dist/docs/index.js +2 -2
- package/dist/docs/presentations.d.ts +2 -4
- package/dist/docs/presentations.js +2 -4
- package/dist/docs/tech/contracts/ops-to-presentation-linking.docblock.js +1 -1
- package/dist/docs/tech/contracts/tests.docblock.js +1 -1
- package/dist/docs/tech-contracts.docs.js +1 -1
- package/dist/docs/types.d.ts +1 -1
- package/dist/events.d.ts +3 -3
- package/dist/examples/docs/examples.docblock.d.ts +6 -0
- package/dist/examples/docs/examples.docblock.js +165 -0
- package/dist/examples/index.d.ts +5 -0
- package/dist/examples/index.js +6 -0
- package/dist/examples/registry.d.ts +65 -0
- package/dist/examples/registry.js +144 -0
- package/dist/examples/schema.d.ts +282 -0
- package/dist/examples/schema.js +125 -0
- package/dist/examples/types.d.ts +167 -0
- package/dist/examples/types.js +43 -0
- package/dist/examples/validation.d.ts +65 -0
- package/dist/examples/validation.js +144 -0
- package/dist/experiments/docs/experiments.docblock.js +1 -1
- package/dist/experiments/evaluator.d.ts +1 -1
- package/dist/experiments/spec-resolver.d.ts +2 -2
- package/dist/experiments/spec.d.ts +6 -8
- package/dist/experiments/spec.js +5 -23
- package/dist/features/index.d.ts +9 -1
- package/dist/features/index.js +8 -1
- package/dist/features/install.js +2 -2
- package/dist/features/types.d.ts +7 -7
- package/dist/forms/forms.d.ts +2 -2
- package/dist/forms/forms.js +3 -6
- package/dist/index.d.ts +13 -8
- package/dist/index.js +11 -2
- package/dist/install.d.ts +9 -9
- package/dist/integrations/connection.d.ts +1 -1
- package/dist/integrations/integrations.feature.js +8 -8
- package/dist/integrations/openbanking/contracts/accounts.d.ts +66 -66
- package/dist/integrations/openbanking/contracts/accounts.js +3 -3
- package/dist/integrations/openbanking/contracts/balances.d.ts +34 -34
- package/dist/integrations/openbanking/contracts/balances.js +2 -2
- package/dist/integrations/openbanking/contracts/transactions.d.ts +48 -48
- package/dist/integrations/openbanking/contracts/transactions.js +2 -2
- package/dist/integrations/openbanking/models.d.ts +55 -55
- package/dist/integrations/openbanking/openbanking.feature.js +10 -10
- package/dist/integrations/operations.d.ts +102 -102
- package/dist/integrations/operations.js +10 -10
- package/dist/integrations/providers/elevenlabs.js +2 -2
- package/dist/integrations/providers/gcs-storage.js +2 -2
- package/dist/integrations/providers/gmail.js +3 -3
- package/dist/integrations/providers/google-calendar.js +2 -2
- package/dist/integrations/providers/mistral.js +3 -3
- package/dist/integrations/providers/postmark.js +2 -2
- package/dist/integrations/providers/powens.js +4 -4
- package/dist/integrations/providers/qdrant.js +3 -3
- package/dist/integrations/providers/stripe.js +2 -2
- package/dist/integrations/providers/twilio-sms.js +2 -2
- package/dist/integrations/runtime.d.ts +5 -5
- package/dist/integrations/spec.d.ts +3 -5
- package/dist/integrations/spec.js +5 -26
- package/dist/jobs/gcp-cloud-tasks.js +1 -1
- package/dist/jobs/gcp-pubsub.js +1 -1
- package/dist/jobs/handlers/ping-handler.d.ts +3 -3
- package/dist/jobs/handlers/ping-handler.js +2 -2
- package/dist/jobs/memory-queue.js +1 -1
- package/dist/jobs/queue.d.ts +4 -4
- package/dist/jobs/scaleway-sqs-queue.js +2 -2
- package/dist/jsonschema.d.ts +4 -4
- package/dist/knowledge/binding.d.ts +1 -1
- package/dist/knowledge/knowledge.feature.js +8 -8
- package/dist/knowledge/operations.d.ts +66 -66
- package/dist/knowledge/operations.js +12 -12
- package/dist/knowledge/source.d.ts +1 -1
- package/dist/knowledge/spaces/email-threads.js +2 -2
- package/dist/knowledge/spaces/financial-docs.js +2 -2
- package/dist/knowledge/spaces/financial-overview.js +2 -2
- package/dist/knowledge/spaces/product-canon.js +2 -2
- package/dist/knowledge/spaces/support-faq.js +2 -2
- package/dist/knowledge/spaces/uploaded-docs.js +2 -2
- package/dist/knowledge/spec.d.ts +3 -5
- package/dist/knowledge/spec.js +6 -28
- package/dist/llm/exporters.js +2 -2
- package/dist/llm/types.d.ts +4 -4
- package/dist/markdown.js +1 -1
- package/dist/migrations.d.ts +2 -2
- package/dist/migrations.js +7 -9
- package/dist/onboarding-base.d.ts +29 -29
- package/dist/onboarding-base.js +4 -4
- package/dist/openapi.js +9 -2
- package/dist/operations/operation.d.ts +3 -3
- package/dist/operations/registry.d.ts +9 -58
- package/dist/operations/registry.js +17 -93
- package/dist/ownership.d.ts +1 -1
- package/dist/policy/docs/policy.docblock.js +1 -1
- package/dist/policy/engine.js +2 -0
- package/dist/policy/spec.d.ts +1 -1
- package/dist/prompt.d.ts +6 -6
- package/dist/promptRegistry.d.ts +4 -4
- package/dist/promptRegistry.js +2 -5
- package/dist/regenerator/docs/regenerator.docblock.js +1 -1
- package/dist/regenerator/types.d.ts +1 -1
- package/dist/registry.d.ts +3 -2
- package/dist/registry.js +5 -5
- package/dist/resources.d.ts +5 -5
- package/dist/server/graphql-pothos.js +2 -2
- package/dist/server/mcp/registerTools.js +1 -1
- package/dist/server/rest-elysia.d.ts +1 -1
- package/dist/server/rest-elysia.js +1 -1
- package/dist/server/rest-express.d.ts +1 -1
- package/dist/server/rest-express.js +1 -1
- package/dist/server/rest-generic.d.ts +1 -1
- package/dist/server/rest-generic.js +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-mcp.js +1 -1
- package/dist/server/rest-next-pages.d.ts +1 -1
- package/dist/telemetry/docs/telemetry.docblock.js +1 -1
- package/dist/telemetry/spec.d.ts +7 -7
- package/dist/telemetry/spec.js +17 -44
- package/dist/telemetry/tracker.d.ts +2 -2
- package/dist/tests/runner.d.ts +1 -1
- package/dist/tests/spec.d.ts +5 -5
- package/dist/tests/spec.js +3 -5
- package/dist/themes.d.ts +4 -6
- package/dist/themes.js +5 -27
- package/dist/translations/catalog.d.ts +1 -1
- package/dist/types.d.ts +5 -5
- package/dist/workflow/adapters/db-adapter.js +3 -3
- package/dist/workflow/runner.d.ts +4 -2
- package/dist/workflow/spec.d.ts +4 -17
- package/dist/workflow/spec.js +4 -48
- package/dist/workflow/state.d.ts +1 -1
- package/dist/workflow/validation.js +1 -1
- package/dist/workspace-config/contractsrc-schema.d.ts +419 -419
- package/dist/workspace-config/contractsrc-schema.js +86 -86
- package/package.json +19 -12
|
@@ -2,7 +2,6 @@ import { OwnerShipMeta } from "../ownership.js";
|
|
|
2
2
|
import { CapabilityRef } from "../capabilities/capabilities.js";
|
|
3
3
|
import "../capabilities/index.js";
|
|
4
4
|
import { PolicyRef } from "../policy/spec.js";
|
|
5
|
-
import { ExperimentRef } from "../experiments/spec.js";
|
|
6
5
|
import { ThemeRef } from "../themes.js";
|
|
7
6
|
import { IntegrationCategory, IntegrationOwnershipMode } from "../integrations/spec.js";
|
|
8
7
|
import { AppIntegrationBinding } from "../integrations/binding.js";
|
|
@@ -10,13 +9,15 @@ import { AppKnowledgeBinding } from "../knowledge/binding.js";
|
|
|
10
9
|
import { BrandingDefaults, TenantBrandingConfig } from "./branding.js";
|
|
11
10
|
import { Locale, TranslationEntry } from "../translations/catalog.js";
|
|
12
11
|
import { ConfigStatus } from "./lifecycle.js";
|
|
12
|
+
import { SpecContractRegistry } from "../registry.js";
|
|
13
|
+
import { ExperimentRef } from "../experiments/spec.js";
|
|
13
14
|
import { FeatureRef } from "../features/types.js";
|
|
14
15
|
import "../features/index.js";
|
|
15
16
|
|
|
16
17
|
//#region src/app-config/spec.d.ts
|
|
17
18
|
interface SpecPointer {
|
|
18
19
|
key: string;
|
|
19
|
-
version?:
|
|
20
|
+
version?: string;
|
|
20
21
|
}
|
|
21
22
|
interface AppRouteConfig {
|
|
22
23
|
path: string;
|
|
@@ -29,7 +30,7 @@ interface AppRouteConfig {
|
|
|
29
30
|
}
|
|
30
31
|
interface TranslationCatalogPointer {
|
|
31
32
|
key: string;
|
|
32
|
-
version:
|
|
33
|
+
version: string;
|
|
33
34
|
}
|
|
34
35
|
interface AppIntegrationSlot {
|
|
35
36
|
/** Slot identifier unique within the blueprint (e.g., "primaryPayments"). */
|
|
@@ -90,11 +91,8 @@ interface AppBlueprintSpec {
|
|
|
90
91
|
routes?: AppRouteConfig[];
|
|
91
92
|
notes?: string;
|
|
92
93
|
}
|
|
93
|
-
declare class AppBlueprintRegistry {
|
|
94
|
-
|
|
95
|
-
register(spec: AppBlueprintSpec): this;
|
|
96
|
-
list(): AppBlueprintSpec[];
|
|
97
|
-
get(key: string, version?: number): AppBlueprintSpec | undefined;
|
|
94
|
+
declare class AppBlueprintRegistry extends SpecContractRegistry<'app-config', AppBlueprintSpec> {
|
|
95
|
+
constructor(items?: AppBlueprintSpec[]);
|
|
98
96
|
}
|
|
99
97
|
declare function makeAppBlueprintKey(meta: AppBlueprintMeta): string;
|
|
100
98
|
interface TenantAppConfigMeta {
|
|
@@ -102,16 +100,16 @@ interface TenantAppConfigMeta {
|
|
|
102
100
|
tenantId: string;
|
|
103
101
|
appId: string;
|
|
104
102
|
blueprintName: string;
|
|
105
|
-
blueprintVersion:
|
|
103
|
+
blueprintVersion: string;
|
|
106
104
|
environment?: string;
|
|
107
105
|
/** Monotonic version for auditing changes to the tenant config. */
|
|
108
|
-
version:
|
|
106
|
+
version: string;
|
|
109
107
|
status: ConfigStatus;
|
|
110
108
|
createdBy?: string;
|
|
111
109
|
publishedBy?: string;
|
|
112
110
|
publishedAt?: string | Date;
|
|
113
|
-
rolledBackFrom?:
|
|
114
|
-
rolledBackTo?:
|
|
111
|
+
rolledBackFrom?: string;
|
|
112
|
+
rolledBackTo?: string;
|
|
115
113
|
changeSummary?: string;
|
|
116
114
|
createdAt?: string | Date;
|
|
117
115
|
updatedAt?: string | Date;
|
package/dist/app-config/spec.js
CHANGED
|
@@ -1,31 +1,10 @@
|
|
|
1
|
+
import { SpecContractRegistry } from "../registry.js";
|
|
2
|
+
|
|
1
3
|
//#region src/app-config/spec.ts
|
|
2
4
|
const blueprintKey = (meta) => `${meta.key}.v${meta.version}`;
|
|
3
|
-
var AppBlueprintRegistry = class {
|
|
4
|
-
items
|
|
5
|
-
|
|
6
|
-
const key = blueprintKey(spec.meta);
|
|
7
|
-
if (this.items.has(key)) throw new Error(`Duplicate AppBlueprint ${key}`);
|
|
8
|
-
this.items.set(key, spec);
|
|
9
|
-
return this;
|
|
10
|
-
}
|
|
11
|
-
list() {
|
|
12
|
-
return [...this.items.values()];
|
|
13
|
-
}
|
|
14
|
-
get(key, version) {
|
|
15
|
-
if (version != null) return this.items.get(blueprintKey({
|
|
16
|
-
key,
|
|
17
|
-
version
|
|
18
|
-
}));
|
|
19
|
-
let latest;
|
|
20
|
-
let maxVersion = -Infinity;
|
|
21
|
-
for (const spec of this.items.values()) {
|
|
22
|
-
if (spec.meta.key !== key) continue;
|
|
23
|
-
if (spec.meta.version > maxVersion) {
|
|
24
|
-
maxVersion = spec.meta.version;
|
|
25
|
-
latest = spec;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return latest;
|
|
5
|
+
var AppBlueprintRegistry = class extends SpecContractRegistry {
|
|
6
|
+
constructor(items) {
|
|
7
|
+
super("app-config", items);
|
|
29
8
|
}
|
|
30
9
|
};
|
|
31
10
|
function makeAppBlueprintKey(meta) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DocId } from "../docs/registry.js";
|
|
2
1
|
import { OwnerShipMeta } from "../ownership.js";
|
|
3
2
|
|
|
4
3
|
//#region src/capabilities/capabilities.d.ts
|
|
@@ -7,28 +6,22 @@ type CapabilitySurface = 'operation' | 'event' | 'workflow' | 'presentation' | '
|
|
|
7
6
|
interface CapabilitySurfaceRef {
|
|
8
7
|
surface: CapabilitySurface;
|
|
9
8
|
key: string;
|
|
10
|
-
version:
|
|
9
|
+
version: string;
|
|
11
10
|
description?: string;
|
|
12
11
|
}
|
|
13
12
|
interface CapabilityMeta extends OwnerShipMeta {
|
|
14
|
-
/** Stable capability slug (e.g., "payments.stripe"). */
|
|
15
|
-
key: string;
|
|
16
|
-
/** Increment when the capability shape changes. */
|
|
17
|
-
version: number;
|
|
18
13
|
kind: CapabilityKind;
|
|
19
|
-
/** Optional doc block id for governance and navigation. */
|
|
20
|
-
docId?: DocId[];
|
|
21
14
|
}
|
|
22
15
|
interface CapabilityRequirement {
|
|
23
16
|
key: string;
|
|
24
|
-
version?:
|
|
17
|
+
version?: string;
|
|
25
18
|
kind?: CapabilityKind;
|
|
26
19
|
optional?: boolean;
|
|
27
20
|
reason?: string;
|
|
28
21
|
}
|
|
29
22
|
interface CapabilityRef {
|
|
30
23
|
key: string;
|
|
31
|
-
version:
|
|
24
|
+
version: string;
|
|
32
25
|
}
|
|
33
26
|
interface CapabilitySpec {
|
|
34
27
|
meta: CapabilityMeta;
|
|
@@ -39,7 +32,7 @@ declare class CapabilityRegistry {
|
|
|
39
32
|
private readonly items;
|
|
40
33
|
register(spec: CapabilitySpec): this;
|
|
41
34
|
list(): CapabilitySpec[];
|
|
42
|
-
get(key: string, version?:
|
|
35
|
+
get(key: string, version?: string): CapabilitySpec | undefined;
|
|
43
36
|
satisfies(requirement: CapabilityRequirement, additional?: CapabilityRef[] | undefined): boolean;
|
|
44
37
|
}
|
|
45
38
|
declare function capabilityKey(spec: CapabilitySpec): string;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { compareVersions } from "compare-versions";
|
|
2
|
+
|
|
1
3
|
//#region src/capabilities/capabilities.ts
|
|
2
4
|
const capKey = (key, version) => `${key}.v${version}`;
|
|
3
5
|
var CapabilityRegistry = class {
|
|
@@ -14,13 +16,9 @@ var CapabilityRegistry = class {
|
|
|
14
16
|
get(key, version) {
|
|
15
17
|
if (version != null) return this.items.get(capKey(key, version));
|
|
16
18
|
let candidate;
|
|
17
|
-
let max = -Infinity;
|
|
18
19
|
for (const spec of this.items.values()) {
|
|
19
20
|
if (spec.meta.key !== key) continue;
|
|
20
|
-
if (spec.meta.version >
|
|
21
|
-
max = spec.meta.version;
|
|
22
|
-
candidate = spec;
|
|
23
|
-
}
|
|
21
|
+
if (!candidate || compareVersions(spec.meta.version, candidate.meta.version) > 0) candidate = spec;
|
|
24
22
|
}
|
|
25
23
|
return candidate;
|
|
26
24
|
}
|
|
@@ -6,7 +6,7 @@ const TAGS = ["open-banking", "finance"];
|
|
|
6
6
|
const openBankingAccountsReadCapability = {
|
|
7
7
|
meta: {
|
|
8
8
|
key: "openbanking.accounts.read",
|
|
9
|
-
version: 1,
|
|
9
|
+
version: "1.0.0",
|
|
10
10
|
kind: "integration",
|
|
11
11
|
title: "Open Banking Accounts (Read)",
|
|
12
12
|
description: "Provides read-only access to linked bank accounts, including account summaries and metadata.",
|
|
@@ -19,19 +19,19 @@ const openBankingAccountsReadCapability = {
|
|
|
19
19
|
{
|
|
20
20
|
surface: "operation",
|
|
21
21
|
key: "openbanking.accounts.list",
|
|
22
|
-
version: 1,
|
|
22
|
+
version: "1.0.0",
|
|
23
23
|
description: "List bank accounts linked to a Powens open banking connection."
|
|
24
24
|
},
|
|
25
25
|
{
|
|
26
26
|
surface: "operation",
|
|
27
27
|
key: "openbanking.accounts.get",
|
|
28
|
-
version: 1,
|
|
28
|
+
version: "1.0.0",
|
|
29
29
|
description: "Retrieve the canonical bank account record for a specific account."
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
surface: "operation",
|
|
33
33
|
key: "openbanking.accounts.sync",
|
|
34
|
-
version: 1,
|
|
34
|
+
version: "1.0.0",
|
|
35
35
|
description: "Trigger a refresh of bank account metadata from the open banking provider."
|
|
36
36
|
}
|
|
37
37
|
]
|
|
@@ -39,7 +39,7 @@ const openBankingAccountsReadCapability = {
|
|
|
39
39
|
const openBankingTransactionsReadCapability = {
|
|
40
40
|
meta: {
|
|
41
41
|
key: "openbanking.transactions.read",
|
|
42
|
-
version: 1,
|
|
42
|
+
version: "1.0.0",
|
|
43
43
|
kind: "integration",
|
|
44
44
|
title: "Open Banking Transactions (Read)",
|
|
45
45
|
description: "Enables retrieval of transaction history for linked bank accounts via open banking providers.",
|
|
@@ -51,19 +51,19 @@ const openBankingTransactionsReadCapability = {
|
|
|
51
51
|
provides: [{
|
|
52
52
|
surface: "operation",
|
|
53
53
|
key: "openbanking.transactions.list",
|
|
54
|
-
version: 1,
|
|
54
|
+
version: "1.0.0",
|
|
55
55
|
description: "List transactions for a given bank account with optional date filtering."
|
|
56
56
|
}, {
|
|
57
57
|
surface: "operation",
|
|
58
58
|
key: "openbanking.transactions.sync",
|
|
59
|
-
version: 1,
|
|
59
|
+
version: "1.0.0",
|
|
60
60
|
description: "Synchronise transactions from the open banking provider into the canonical ledger."
|
|
61
61
|
}]
|
|
62
62
|
};
|
|
63
63
|
const openBankingBalancesReadCapability = {
|
|
64
64
|
meta: {
|
|
65
65
|
key: "openbanking.balances.read",
|
|
66
|
-
version: 1,
|
|
66
|
+
version: "1.0.0",
|
|
67
67
|
kind: "integration",
|
|
68
68
|
title: "Open Banking Balances (Read)",
|
|
69
69
|
description: "Allows querying of current and available balances for linked bank accounts via open banking providers.",
|
|
@@ -75,12 +75,12 @@ const openBankingBalancesReadCapability = {
|
|
|
75
75
|
provides: [{
|
|
76
76
|
surface: "operation",
|
|
77
77
|
key: "openbanking.balances.get",
|
|
78
|
-
version: 1,
|
|
78
|
+
version: "1.0.0",
|
|
79
79
|
description: "Retrieve the latest known balances for a specified bank account."
|
|
80
80
|
}, {
|
|
81
81
|
surface: "operation",
|
|
82
82
|
key: "openbanking.balances.refresh",
|
|
83
|
-
version: 1,
|
|
83
|
+
version: "1.0.0",
|
|
84
84
|
description: "Force a balance refresh from the open banking provider."
|
|
85
85
|
}]
|
|
86
86
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { buildZodWithRelations, evalPredicate } from "../../forms/forms.js";
|
|
2
|
+
import "../../forms/index.js";
|
|
2
3
|
import React, { useEffect, useMemo, useState } from "react";
|
|
3
4
|
import { Controller, useFieldArray, useForm } from "react-hook-form";
|
|
4
5
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
@@ -41,17 +41,17 @@ declare const ContractRegistryItemSchema: z.ZodObject<{
|
|
|
41
41
|
"contractspec:app-config": "contractspec:app-config";
|
|
42
42
|
"contractspec:knowledge": "contractspec:knowledge";
|
|
43
43
|
}>;
|
|
44
|
-
version: z.
|
|
44
|
+
version: z.ZodString;
|
|
45
45
|
title: z.ZodString;
|
|
46
46
|
description: z.ZodString;
|
|
47
47
|
meta: z.ZodObject<{
|
|
48
48
|
stability: z.ZodEnum<{
|
|
49
|
-
experimental: "experimental";
|
|
50
|
-
beta: "beta";
|
|
51
|
-
stable: "stable";
|
|
52
49
|
deprecated: "deprecated";
|
|
53
50
|
idea: "idea";
|
|
54
51
|
in_creation: "in_creation";
|
|
52
|
+
experimental: "experimental";
|
|
53
|
+
beta: "beta";
|
|
54
|
+
stable: "stable";
|
|
55
55
|
}>;
|
|
56
56
|
owners: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
57
57
|
tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
@@ -90,17 +90,17 @@ declare const ContractRegistryManifestSchema: z.ZodObject<{
|
|
|
90
90
|
"contractspec:app-config": "contractspec:app-config";
|
|
91
91
|
"contractspec:knowledge": "contractspec:knowledge";
|
|
92
92
|
}>;
|
|
93
|
-
version: z.
|
|
93
|
+
version: z.ZodString;
|
|
94
94
|
title: z.ZodString;
|
|
95
95
|
description: z.ZodString;
|
|
96
96
|
meta: z.ZodObject<{
|
|
97
97
|
stability: z.ZodEnum<{
|
|
98
|
-
experimental: "experimental";
|
|
99
|
-
beta: "beta";
|
|
100
|
-
stable: "stable";
|
|
101
98
|
deprecated: "deprecated";
|
|
102
99
|
idea: "idea";
|
|
103
100
|
in_creation: "in_creation";
|
|
101
|
+
experimental: "experimental";
|
|
102
|
+
beta: "beta";
|
|
103
|
+
stable: "stable";
|
|
104
104
|
}>;
|
|
105
105
|
owners: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
106
106
|
tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
@@ -27,7 +27,7 @@ const ContractRegistryFileSchema = z.object({
|
|
|
27
27
|
const ContractRegistryItemSchema = z.object({
|
|
28
28
|
key: z.string().min(1),
|
|
29
29
|
type: ContractRegistryItemTypeSchema,
|
|
30
|
-
version: z.
|
|
30
|
+
version: z.string(),
|
|
31
31
|
title: z.string().min(1),
|
|
32
32
|
description: z.string().min(1),
|
|
33
33
|
meta: z.object({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GroupKeyFn, RegistryFilter } from "../registry-utils.js";
|
|
2
1
|
import { DataViewSpec } from "./spec.js";
|
|
2
|
+
import { SpecContractRegistry } from "../registry.js";
|
|
3
3
|
|
|
4
4
|
//#region src/data-views/registry.d.ts
|
|
5
5
|
|
|
@@ -10,42 +10,8 @@ declare function dataViewKey(spec: DataViewSpec): string;
|
|
|
10
10
|
/**
|
|
11
11
|
* Registry for managing data view specifications.
|
|
12
12
|
*/
|
|
13
|
-
declare class DataViewRegistry {
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Register a data view spec.
|
|
17
|
-
* @throws Error if a spec with the same key already exists.
|
|
18
|
-
*/
|
|
19
|
-
register(spec: DataViewSpec): this;
|
|
20
|
-
/**
|
|
21
|
-
* List all registered data view specs.
|
|
22
|
-
*/
|
|
23
|
-
list(): DataViewSpec[];
|
|
24
|
-
/**
|
|
25
|
-
* Get a data view by key and optional version.
|
|
26
|
-
* If version is not specified, returns the latest version.
|
|
27
|
-
*/
|
|
28
|
-
get(name: string, version?: number): DataViewSpec | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Filter data views by criteria.
|
|
31
|
-
*/
|
|
32
|
-
filter(criteria: RegistryFilter): DataViewSpec[];
|
|
33
|
-
/**
|
|
34
|
-
* List data views with specific tag.
|
|
35
|
-
*/
|
|
36
|
-
listByTag(tag: string): DataViewSpec[];
|
|
37
|
-
/**
|
|
38
|
-
* List data views by owner.
|
|
39
|
-
*/
|
|
40
|
-
listByOwner(owner: string): DataViewSpec[];
|
|
41
|
-
/**
|
|
42
|
-
* Group data views by key function.
|
|
43
|
-
*/
|
|
44
|
-
groupBy(keyFn: GroupKeyFn<DataViewSpec>): Map<string, DataViewSpec[]>;
|
|
45
|
-
/**
|
|
46
|
-
* Get unique tags from all data views.
|
|
47
|
-
*/
|
|
48
|
-
getUniqueTags(): string[];
|
|
13
|
+
declare class DataViewRegistry extends SpecContractRegistry<'data-view', DataViewSpec> {
|
|
14
|
+
constructor(items?: DataViewSpec[]);
|
|
49
15
|
}
|
|
50
16
|
//#endregion
|
|
51
17
|
export { DataViewRegistry, dataViewKey };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SpecContractRegistry } from "../registry.js";
|
|
2
2
|
|
|
3
3
|
//#region src/data-views/registry.ts
|
|
4
|
-
init_registry_utils();
|
|
5
4
|
/**
|
|
6
5
|
* Generate a unique key for a data view spec.
|
|
7
6
|
*/
|
|
@@ -11,70 +10,9 @@ function dataViewKey(spec) {
|
|
|
11
10
|
/**
|
|
12
11
|
* Registry for managing data view specifications.
|
|
13
12
|
*/
|
|
14
|
-
var DataViewRegistry = class {
|
|
15
|
-
items
|
|
16
|
-
|
|
17
|
-
* Register a data view spec.
|
|
18
|
-
* @throws Error if a spec with the same key already exists.
|
|
19
|
-
*/
|
|
20
|
-
register(spec) {
|
|
21
|
-
const key = dataViewKey(spec);
|
|
22
|
-
if (this.items.has(key)) throw new Error(`Duplicate data view ${key}`);
|
|
23
|
-
this.items.set(key, spec);
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* List all registered data view specs.
|
|
28
|
-
*/
|
|
29
|
-
list() {
|
|
30
|
-
return [...this.items.values()];
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Get a data view by key and optional version.
|
|
34
|
-
* If version is not specified, returns the latest version.
|
|
35
|
-
*/
|
|
36
|
-
get(name, version) {
|
|
37
|
-
if (version != null) return this.items.get(`${name}.v${version}`);
|
|
38
|
-
let candidate;
|
|
39
|
-
let max = -Infinity;
|
|
40
|
-
for (const spec of this.items.values()) {
|
|
41
|
-
if (spec.meta.key !== name) continue;
|
|
42
|
-
if (spec.meta.version > max) {
|
|
43
|
-
max = spec.meta.version;
|
|
44
|
-
candidate = spec;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return candidate;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Filter data views by criteria.
|
|
51
|
-
*/
|
|
52
|
-
filter(criteria) {
|
|
53
|
-
return filterBy(this.list(), criteria);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* List data views with specific tag.
|
|
57
|
-
*/
|
|
58
|
-
listByTag(tag) {
|
|
59
|
-
return this.list().filter((d) => d.meta.tags?.includes(tag));
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* List data views by owner.
|
|
63
|
-
*/
|
|
64
|
-
listByOwner(owner) {
|
|
65
|
-
return this.list().filter((d) => d.meta.owners?.includes(owner));
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Group data views by key function.
|
|
69
|
-
*/
|
|
70
|
-
groupBy(keyFn) {
|
|
71
|
-
return groupBy(this.list(), keyFn);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Get unique tags from all data views.
|
|
75
|
-
*/
|
|
76
|
-
getUniqueTags() {
|
|
77
|
-
return getUniqueTags(this.list());
|
|
13
|
+
var DataViewRegistry = class extends SpecContractRegistry {
|
|
14
|
+
constructor(items) {
|
|
15
|
+
super("data-view", items);
|
|
78
16
|
}
|
|
79
17
|
};
|
|
80
18
|
|
|
@@ -18,7 +18,7 @@ declare class DataViewRuntime {
|
|
|
18
18
|
private subscriptions;
|
|
19
19
|
constructor(config: DataViewRuntimeConfig);
|
|
20
20
|
register(spec: DataViewSpec): void;
|
|
21
|
-
getSpec(name: string, version?:
|
|
21
|
+
getSpec(name: string, version?: string): DataViewSpec | undefined;
|
|
22
22
|
executeQuery(specName: string, _params: unknown): Promise<DataViewResult>;
|
|
23
23
|
invalidate(specName: string): void;
|
|
24
24
|
subscribe(specName: string, callback: () => void): () => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ExperimentRef } from "../experiments/spec.js";
|
|
2
1
|
import { DataViewConfig, DataViewMeta, DataViewSource, DataViewStates } from "./types.js";
|
|
2
|
+
import { ExperimentRef } from "../experiments/spec.js";
|
|
3
3
|
|
|
4
4
|
//#region src/data-views/spec.d.ts
|
|
5
5
|
|
|
@@ -22,7 +22,7 @@ interface DataViewSpec {
|
|
|
22
22
|
*/
|
|
23
23
|
interface DataViewRef {
|
|
24
24
|
key: string;
|
|
25
|
-
version:
|
|
25
|
+
version: string;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Helper to define a data view spec with type safety.
|
package/dist/docs/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DocBlock, DocBlockLink, DocKind, DocVisibility } from "./types.js";
|
|
2
|
-
import { DocPresentationOptions, DocPresentationRoute, docBlockToPresentationSpec,
|
|
2
|
+
import { DocPresentationOptions, DocPresentationRoute, docBlockToPresentationSpec, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, mapDocRoutes } from "./presentations.js";
|
|
3
3
|
import { DocId, DocRegistry, defaultDocRegistry, docId, listRegisteredDocBlocks, registerDocBlocks } from "./registry.js";
|
|
4
4
|
import { techContractsDocs } from "./tech-contracts.docs.js";
|
|
5
5
|
import { metaDocs } from "./meta.docs.js";
|
|
6
|
-
export { DocBlock, DocBlockLink, DocId, DocKind, DocPresentationOptions, DocPresentationRoute, DocRegistry, DocVisibility, defaultDocRegistry, docBlockToPresentationSpec,
|
|
6
|
+
export { DocBlock, DocBlockLink, DocId, DocKind, DocPresentationOptions, DocPresentationRoute, DocRegistry, DocVisibility, defaultDocRegistry, docBlockToPresentationSpec, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, docId, listRegisteredDocBlocks, mapDocRoutes, metaDocs, registerDocBlocks, techContractsDocs };
|
package/dist/docs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { docBlockToPresentationSpec,
|
|
1
|
+
import { docBlockToPresentationSpec, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, mapDocRoutes } from "./presentations.js";
|
|
2
2
|
import { DocRegistry, defaultDocRegistry, docId, listRegisteredDocBlocks, registerDocBlocks } from "./registry.js";
|
|
3
3
|
import { techContractsDocs } from "./tech-contracts.docs.js";
|
|
4
4
|
import { metaDocs } from "./meta.docs.js";
|
|
@@ -26,4 +26,4 @@ import "./tech/studio/project-access-teams.docblock.js";
|
|
|
26
26
|
import "./tech/studio/team-invitations.docblock.js";
|
|
27
27
|
import "./tech/llm/llm-integration.docblock.js";
|
|
28
28
|
|
|
29
|
-
export { DocRegistry, defaultDocRegistry, docBlockToPresentationSpec,
|
|
29
|
+
export { DocRegistry, defaultDocRegistry, docBlockToPresentationSpec, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, docId, listRegisteredDocBlocks, mapDocRoutes, metaDocs, registerDocBlocks, techContractsDocs };
|
|
@@ -14,7 +14,7 @@ interface DocPresentationOptions {
|
|
|
14
14
|
/** Default presentation targets. */
|
|
15
15
|
defaultTargets?: PresentationTarget[];
|
|
16
16
|
/** Default version when block.version is not set. */
|
|
17
|
-
defaultVersion?:
|
|
17
|
+
defaultVersion?: string;
|
|
18
18
|
/** Default stability if not provided on the DocBlock. */
|
|
19
19
|
defaultStability?: Stability;
|
|
20
20
|
}
|
|
@@ -24,10 +24,8 @@ interface DocPresentationRoute {
|
|
|
24
24
|
block: DocBlock;
|
|
25
25
|
}
|
|
26
26
|
declare function docBlockToPresentationSpec(block: DocBlock, options?: DocPresentationOptions): PresentationSpec;
|
|
27
|
-
/** @deprecated Use docBlockToPresentationSpec instead */
|
|
28
|
-
declare const docBlockToPresentationV2: typeof docBlockToPresentationSpec;
|
|
29
27
|
declare function docBlocksToPresentationRoutes(blocks: DocBlock[], options?: DocPresentationOptions): DocPresentationRoute[];
|
|
30
28
|
declare function docBlocksToPresentationSpecs(blocks: DocBlock[], options?: DocPresentationOptions): PresentationSpec[];
|
|
31
29
|
declare function mapDocRoutes(routes: DocPresentationRoute[]): [string, PresentationSpec][];
|
|
32
30
|
//#endregion
|
|
33
|
-
export { DocPresentationOptions, DocPresentationRoute, docBlockToPresentationSpec,
|
|
31
|
+
export { DocPresentationOptions, DocPresentationRoute, docBlockToPresentationSpec, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, mapDocRoutes };
|
|
@@ -21,7 +21,7 @@ function buildName(block, namespace) {
|
|
|
21
21
|
}
|
|
22
22
|
function docBlockToPresentationSpec(block, options) {
|
|
23
23
|
const targets = options?.defaultTargets ?? DEFAULT_TARGETS;
|
|
24
|
-
const version = block.version ?? options?.defaultVersion ?? 1;
|
|
24
|
+
const version = block.version ?? options?.defaultVersion ?? "1.0.0";
|
|
25
25
|
const stability = block.stability ?? options?.defaultStability ?? "stable";
|
|
26
26
|
return {
|
|
27
27
|
meta: {
|
|
@@ -44,8 +44,6 @@ function docBlockToPresentationSpec(block, options) {
|
|
|
44
44
|
targets
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
-
/** @deprecated Use docBlockToPresentationSpec instead */
|
|
48
|
-
const docBlockToPresentationV2 = docBlockToPresentationSpec;
|
|
49
47
|
function docBlocksToPresentationRoutes(blocks, options) {
|
|
50
48
|
return blocks.map((block) => ({
|
|
51
49
|
block,
|
|
@@ -61,4 +59,4 @@ function mapDocRoutes(routes) {
|
|
|
61
59
|
}
|
|
62
60
|
|
|
63
61
|
//#endregion
|
|
64
|
-
export { docBlockToPresentationSpec,
|
|
62
|
+
export { docBlockToPresentationSpec, docBlocksToPresentationRoutes, docBlocksToPresentationSpecs, mapDocRoutes };
|
|
@@ -13,7 +13,7 @@ const tech_contracts_ops_to_presentation_linking_DocBlocks = [{
|
|
|
13
13
|
"contracts",
|
|
14
14
|
"ops-to-presentation-linking"
|
|
15
15
|
],
|
|
16
|
-
body: "### Ops ↔ Presentation linking (V2)\n\nThis document explains how operations (OperationSpec) are linked to Presentations (PresentationSpec) via Feature modules.\n\n- Location: `@contractspec/lib.contracts/src/features.ts`\n- Field: `FeatureModuleSpec.opToPresentation?: { op: { name; version }; pres: { name; version } }[]`\n- Validation: `installFeature()` validates that linked ops exist in `OperationSpecRegistry` and linked presentations exist in the registry, and that declared targets are present.\n\nExample:\n\n```ts\nimport type { OperationSpecRegistry } from '@contractspec/lib.contracts/src/registry';\nimport { FeatureRegistry, createFeatureModule } from '@contractspec/lib.contracts';\n\nexport function buildFeaturesWithOps(ops: OperationSpecRegistry) {\n const features = new FeatureRegistry();\n features.register(\n createFeatureModule(\n {\n key: 'myapp.widgets.linkage',\n title: 'Widgets (linked)',\n description: 'Links create/update ops to UI presentations',\n domain: 'widgets',\n tags: ['widgets', 'linkage'],\n stability: 'beta',\n },\n {\n operations: [\n { name: 'widgets.create', version: 1 },\n { name: 'widgets.update', version: 1 },\n ],\n presentations: [{ name: 'myapp.widgets.editor.page', version: 1 }],\n opToPresentation: [\n {\n op: { name: 'widgets.create', version: 1 },\n pres: { name: 'myapp.widgets.editor.page', version: 1 },\n },\n {\n op: { name: 'widgets.update', version: 1 },\n pres: { name: 'myapp.widgets.editor.page', version: 1 },\n },\n ],\n presentationsTargets: [\n {\n name: 'myapp.widgets.editor.page',\n version: 1,\n targets: ['react', 'markdown'],\n },\n ],\n }\n )\n );\n return { features };\n}\n```\n\nNotes\n\n- This enables traceability: the UI flow that realizes an op is discoverable via the feature catalog.\n- Presentations can target multiple outputs (`react`, `markdown`, `application/json`, `application/xml`).\n- Use `renderFeaturePresentation()` to render a descriptor to a given target with a component map.\n"
|
|
16
|
+
body: "### Ops ↔ Presentation linking (V2)\n\nThis document explains how operations (OperationSpec) are linked to Presentations (PresentationSpec) via Feature modules.\n\n- Location: `@contractspec/lib.contracts/src/features.ts`\n- Field: `FeatureModuleSpec.opToPresentation?: { op: { name; version }; pres: { name; version } }[]`\n- Validation: `installFeature()` validates that linked ops exist in `OperationSpecRegistry` and linked presentations exist in the registry, and that declared targets are present.\n\nExample:\n\n```ts\nimport type { OperationSpecRegistry } from '@contractspec/lib.contracts/src/registry';\nimport { FeatureRegistry, createFeatureModule } from '@contractspec/lib.contracts';\n\nexport function buildFeaturesWithOps(ops: OperationSpecRegistry) {\n const features = new FeatureRegistry();\n features.register(\n createFeatureModule(\n {\n key: 'myapp.widgets.linkage',\n title: 'Widgets (linked)',\n description: 'Links create/update ops to UI presentations',\n domain: 'widgets',\n tags: ['widgets', 'linkage'],\n stability: 'beta',\n },\n {\n operations: [\n { name: 'widgets.create', version: '1.0.0' },\n { name: 'widgets.update', version: '1.0.0' },\n ],\n presentations: [{ name: 'myapp.widgets.editor.page', version: '1.0.0' }],\n opToPresentation: [\n {\n op: { name: 'widgets.create', version: '1.0.0' },\n pres: { name: 'myapp.widgets.editor.page', version: '1.0.0' },\n },\n {\n op: { name: 'widgets.update', version: '1.0.0' },\n pres: { name: 'myapp.widgets.editor.page', version: '1.0.0' },\n },\n ],\n presentationsTargets: [\n {\n name: 'myapp.widgets.editor.page',\n version: '1.0.0',\n targets: ['react', 'markdown'],\n },\n ],\n }\n )\n );\n return { features };\n}\n```\n\nNotes\n\n- This enables traceability: the UI flow that realizes an op is discoverable via the feature catalog.\n- Presentations can target multiple outputs (`react`, `markdown`, `application/json`, `application/xml`).\n- Use `renderFeaturePresentation()` to render a descriptor to a given target with a component map.\n"
|
|
17
17
|
}];
|
|
18
18
|
registerDocBlocks(tech_contracts_ops_to_presentation_linking_DocBlocks);
|
|
19
19
|
|
|
@@ -13,7 +13,7 @@ const tech_contracts_tests_DocBlocks = [{
|
|
|
13
13
|
"contracts",
|
|
14
14
|
"tests"
|
|
15
15
|
],
|
|
16
|
-
body: "## TestSpec & TestRunner\n\nUse `TestSpec` to describe end-to-end scenarios for contracts and workflows. Specs live alongside your contracts and exercise the same OperationSpecRegistry handlers the app uses.\n\n- Types & registry: `packages/libs/contracts/src/tests/spec.ts`\n- Runtime runner: `packages/libs/contracts/src/tests/runner.ts`\n- CLI: `contractspec test`\n\n### Structure\n\n```ts\nexport interface TestSpec {\n meta: TestSpecMeta;\n target: TestTarget; // contract or workflow\n fixtures?: Fixture[]; // optional shared setup before each scenario\n scenarios: TestScenario[];\n coverage?: CoverageRequirement;\n}\n```\n\n- `Fixture`: run an operation before the scenario (`operation`, optional `input`)\n- `Action`: operation input that the scenario exercises\n- `Assertion`:\n - `expectOutput` `{ match }` deep-equals the handler output\n - `expectError` `{ messageIncludes? }` ensures an error was thrown\n - `expectEvents` `{ events: [{ name, version, min?, max? }] }` checks emitted events\n\n### Example\n\n```ts\nimport { defineCommand, type TestSpec } from '@contractspec/lib.contracts';\n\nexport const AddNumbersSpec = defineCommand({\n meta: { name: 'math.add', version: 1, /* … */ },\n io: {\n input: AddNumbersInput,\n output: AddNumbersOutput,\n },\n policy: { auth: 'user' },\n});\n\nexport const MathAddTests: TestSpec = {\n meta: {\n name: 'math.add.tests',\n version: 1,\n title: 'Math add scenarios',\n owners: ['@team.math'],\n tags: ['math'],\n stability: StabilityEnum.Experimental,\n },\n target: { type: 'contract', operation: { name: 'math.add' } },\n scenarios: [\n {\n name: 'adds positive numbers',\n when: {\n operation: { name: 'math.add' },\n input: { a: 2, b: 3 },\n },\n then: [\n { type: 'expectOutput', match: { sum: 5 } },\n {\n type: 'expectEvents',\n events: [{ name: 'math.sum_calculated', version: 1, min: 1 }],\n },\n ],\n },\n ],\n};\n```\n\n### Running tests\n\n1. Register the contract handlers in a `OperationSpecRegistry`:\n\n```ts\nexport function createRegistry() {\n const registry = new OperationSpecRegistry();\n registry.register(AddNumbersSpec);\n registry.bind(AddNumbersSpec, addNumbersHandler);\n return registry;\n}\n```\n\n2. Run the CLI:\n\n```\ncontractspec test apps/math/tests/math.add.tests.ts \\\n --registry apps/math/tests/registry.ts\n```\n\n- The CLI loads the TestSpec, instantiates the registry (via the provided module), and executes each scenario via `TestRunner`.\n- `--json` outputs machine-readable results.\n\n### Programmatic usage\n\n```ts\nconst runner = new TestRunner({\n registry,\n createContext: () => ({ actor: 'user', organizationId: 'tenant-1' }),\n});\n\nconst result = await runner.run(MathAddTests);\nconsole.log(result.passed, result.failed);\n```\n\n- `createContext` can supply default `HandlerCtx` values.\n- `beforeEach` / `afterEach` hooks let you seed databases or reset state.\n\n### Best practices\n\n- Keep fixtures idempotent so scenarios can run in parallel in the future.\n- Use `expectEvents` to guard analytics/telemetry expectations.\n- Add specs to `TestRegistry` for discovery and documentation.\n- `coverage` captures desired coverage metrics (enforced by future tooling).\n- Pair TestSpec files with CI using `contractspec test --json` and fail builds when `failed > 0`.\n\n### Mocking with Bun's `vi`\n\n- Pass a single function type to `vi.fn<TFunction>()` so calls retain typed arguments:\n\n```ts\nconst handler = vi.fn<typeof fetch>();\nconst fetchImpl: typeof fetch = ((...args) => handler(...args)) as typeof fetch;\nObject.defineProperty(fetchImpl, 'preconnect', {\n value: vi.fn<typeof fetch.preconnect>(),\n});\n```\n\n- When you need to inspect calls, use the typed mock (`handler.mock.calls`) rather than casting to `any`.\n- Narrow optional request data defensively (e.g., check for headers before reading them) so tests remain type-safe under strict `tsconfig` settings.\n\n"
|
|
16
|
+
body: "## TestSpec & TestRunner\n\nUse `TestSpec` to describe end-to-end scenarios for contracts and workflows. Specs live alongside your contracts and exercise the same OperationSpecRegistry handlers the app uses.\n\n- Types & registry: `packages/libs/contracts/src/tests/spec.ts`\n- Runtime runner: `packages/libs/contracts/src/tests/runner.ts`\n- CLI: `contractspec test`\n\n### Structure\n\n```ts\nexport interface TestSpec {\n meta: TestSpecMeta;\n target: TestTarget; // contract or workflow\n fixtures?: Fixture[]; // optional shared setup before each scenario\n scenarios: TestScenario[];\n coverage?: CoverageRequirement;\n}\n```\n\n- `Fixture`: run an operation before the scenario (`operation`, optional `input`)\n- `Action`: operation input that the scenario exercises\n- `Assertion`:\n - `expectOutput` `{ match }` deep-equals the handler output\n - `expectError` `{ messageIncludes? }` ensures an error was thrown\n - `expectEvents` `{ events: [{ name, version, min?, max? }] }` checks emitted events\n\n### Example\n\n```ts\nimport { defineCommand, type TestSpec } from '@contractspec/lib.contracts';\n\nexport const AddNumbersSpec = defineCommand({\n meta: { name: 'math.add', version: '1.0.0', /* … */ },\n io: {\n input: AddNumbersInput,\n output: AddNumbersOutput,\n },\n policy: { auth: 'user' },\n});\n\nexport const MathAddTests: TestSpec = {\n meta: {\n name: 'math.add.tests',\n version: '1.0.0',\n title: 'Math add scenarios',\n owners: ['@team.math'],\n tags: ['math'],\n stability: StabilityEnum.Experimental,\n },\n target: { type: 'contract', operation: { name: 'math.add' } },\n scenarios: [\n {\n name: 'adds positive numbers',\n when: {\n operation: { name: 'math.add' },\n input: { a: 2, b: 3 },\n },\n then: [\n { type: 'expectOutput', match: { sum: 5 } },\n {\n type: 'expectEvents',\n events: [{ name: 'math.sum_calculated', version: '1.0.0', min: 1 }],\n },\n ],\n },\n ],\n};\n```\n\n### Running tests\n\n1. Register the contract handlers in a `OperationSpecRegistry`:\n\n```ts\nexport function createRegistry() {\n const registry = new OperationSpecRegistry();\n registry.register(AddNumbersSpec);\n registry.bind(AddNumbersSpec, addNumbersHandler);\n return registry;\n}\n```\n\n2. Run the CLI:\n\n```\ncontractspec test apps/math/tests/math.add.tests.ts \\\n --registry apps/math/tests/registry.ts\n```\n\n- The CLI loads the TestSpec, instantiates the registry (via the provided module), and executes each scenario via `TestRunner`.\n- `--json` outputs machine-readable results.\n\n### Programmatic usage\n\n```ts\nconst runner = new TestRunner({\n registry,\n createContext: () => ({ actor: 'user', organizationId: 'tenant-1' }),\n});\n\nconst result = await runner.run(MathAddTests);\nconsole.log(result.passed, result.failed);\n```\n\n- `createContext` can supply default `HandlerCtx` values.\n- `beforeEach` / `afterEach` hooks let you seed databases or reset state.\n\n### Best practices\n\n- Keep fixtures idempotent so scenarios can run in parallel in the future.\n- Use `expectEvents` to guard analytics/telemetry expectations.\n- Add specs to `TestRegistry` for discovery and documentation.\n- `coverage` captures desired coverage metrics (enforced by future tooling).\n- Pair TestSpec files with CI using `contractspec test --json` and fail builds when `failed > 0`.\n\n### Mocking with Bun's `vi`\n\n- Pass a single function type to `vi.fn<TFunction>()` so calls retain typed arguments:\n\n```ts\nconst handler = vi.fn<typeof fetch>();\nconst fetchImpl: typeof fetch = ((...args) => handler(...args)) as typeof fetch;\nObject.defineProperty(fetchImpl, 'preconnect', {\n value: vi.fn<typeof fetch.preconnect>(),\n});\n```\n\n- When you need to inspect calls, use the typed mock (`handler.mock.calls`) rather than casting to `any`.\n- Narrow optional request data defensively (e.g., check for headers before reading them) so tests remain type-safe under strict `tsconfig` settings.\n\n"
|
|
17
17
|
}];
|
|
18
18
|
registerDocBlocks(tech_contracts_tests_DocBlocks);
|
|
19
19
|
|
|
@@ -61,7 +61,7 @@ type Tag = string; // curated list available in code (e.g., 'auth', 'spots')
|
|
|
61
61
|
// For presentations, meta is a Partial<OwnerShipMeta> plus description, name, version
|
|
62
62
|
interface PresentationMeta extends Partial<OwnerShipMeta> {
|
|
63
63
|
name: string;
|
|
64
|
-
version:
|
|
64
|
+
version: string;
|
|
65
65
|
description?: string;
|
|
66
66
|
}
|
|
67
67
|
\`\`\`
|
package/dist/docs/types.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ interface DocBlock {
|
|
|
23
23
|
/** Visibility gate. Defaults to public. */
|
|
24
24
|
visibility?: DocVisibility;
|
|
25
25
|
/** Optional version to allow evolutions without breaking links. Defaults to 1. */
|
|
26
|
-
version?:
|
|
26
|
+
version?: string;
|
|
27
27
|
/** Tags to aid discovery and filtering. */
|
|
28
28
|
tags?: string[];
|
|
29
29
|
/** Owning teams or individuals. */
|
package/dist/events.d.ts
CHANGED
|
@@ -32,13 +32,13 @@ interface EventEnvelope<T> {
|
|
|
32
32
|
/** Event name as published (should match spec.name). */
|
|
33
33
|
key: string;
|
|
34
34
|
/** Event version as published (should match spec.version). */
|
|
35
|
-
version:
|
|
35
|
+
version: string;
|
|
36
36
|
/** Validated payload. */
|
|
37
37
|
payload: T;
|
|
38
38
|
}
|
|
39
|
-
type EventKey = `${string}.v${
|
|
39
|
+
type EventKey = `${string}.v${string}`;
|
|
40
40
|
/** Build a stable string key for an event name/version pair. */
|
|
41
|
-
declare const eventKey: (key: string, version:
|
|
41
|
+
declare const eventKey: (key: string, version: string) => EventKey;
|
|
42
42
|
/** In-memory registry for EventSpec. */
|
|
43
43
|
declare class EventRegistry extends SpecContractRegistry<'event', AnyEventSpec> {
|
|
44
44
|
constructor(items?: AnyEventSpec[]);
|