@contractspec/lib.contracts 1.49.0 → 1.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app-config/contracts.d.ts +51 -51
- package/dist/app-config/events.d.ts +27 -27
- package/dist/app-config/lifecycle-contracts.d.ts +55 -55
- package/dist/app-config/runtime.d.ts +1 -1
- package/dist/app-config/spec.d.ts +1 -1
- 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/runtime.d.ts +1 -1
- package/dist/events.d.ts +79 -13
- package/dist/events.js +33 -3
- package/dist/examples/schema.d.ts +10 -10
- package/dist/experiments/spec.d.ts +7 -4
- package/dist/features/install.d.ts +4 -4
- package/dist/features/types.d.ts +28 -32
- package/dist/index.d.ts +21 -12
- package/dist/index.js +12 -3
- 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 +1 -1
- package/dist/knowledge/operations.d.ts +67 -67
- package/dist/llm/exporters.d.ts +2 -2
- package/dist/markdown.d.ts +1 -1
- package/dist/onboarding-base.d.ts +29 -29
- package/dist/operations/operation.d.ts +6 -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/tests/spec.d.ts +17 -12
- package/dist/themes.d.ts +7 -4
- 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 +140 -14
- 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 +4 -2
- package/dist/workflow/index.js +4 -2
- package/dist/workflow/spec.d.ts +1 -1
- package/dist/workflow/validation.d.ts +64 -2
- package/dist/workflow/validation.js +194 -1
- package/package.json +19 -6
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
//#region src/versioning/refs.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Base reference types for ContractSpec versioning.
|
|
4
|
+
*
|
|
5
|
+
* Provides canonical reference types for linking between specs.
|
|
6
|
+
* Domain-specific refs (OpRef, EventRef, etc.) should alias these
|
|
7
|
+
* base types for consistency and maintainability.
|
|
8
|
+
*
|
|
9
|
+
* @module versioning/refs
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Base reference type for versioned specs.
|
|
13
|
+
* Used to reference any spec by its key and version.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const opRef: VersionedSpecRef = { key: 'auth.login', version: '1.0.0' };
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
interface VersionedSpecRef {
|
|
21
|
+
/** Unique key identifying the spec (e.g., "auth.login", "user.created"). */
|
|
22
|
+
key: string;
|
|
23
|
+
/** Semantic version of the spec (e.g., "1.0.0", "2.1.0"). */
|
|
24
|
+
version: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Base reference type for specs with optional version.
|
|
28
|
+
* When version is omitted, typically refers to the latest version.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // Reference to latest version
|
|
33
|
+
* const latestRef: OptionalVersionedSpecRef = { key: 'auth.login' };
|
|
34
|
+
*
|
|
35
|
+
* // Reference to specific version
|
|
36
|
+
* const specificRef: OptionalVersionedSpecRef = { key: 'auth.login', version: '1.0.0' };
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
interface OptionalVersionedSpecRef {
|
|
40
|
+
/** Unique key identifying the spec. */
|
|
41
|
+
key: string;
|
|
42
|
+
/** Optional semantic version. When omitted, refers to the latest version. */
|
|
43
|
+
version?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Base reference type for unversioned spec keys.
|
|
47
|
+
* Used when only the key is needed without version information.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const featureRef: SpecKeyRef = { key: 'premium-features' };
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
interface SpecKeyRef {
|
|
55
|
+
/** Unique key identifying the spec. */
|
|
56
|
+
key: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Checks if a value is a valid VersionedSpecRef.
|
|
60
|
+
*
|
|
61
|
+
* @param ref - The value to check
|
|
62
|
+
* @returns True if the value has both key and version as strings
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const ref = { key: 'auth.login', version: '1.0.0' };
|
|
67
|
+
* if (isVersionedSpecRef(ref)) {
|
|
68
|
+
* console.log(`Spec: ${ref.key}@${ref.version}`);
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function isVersionedSpecRef(ref: unknown): ref is VersionedSpecRef;
|
|
73
|
+
/**
|
|
74
|
+
* Checks if a value is a valid OptionalVersionedSpecRef.
|
|
75
|
+
*
|
|
76
|
+
* @param ref - The value to check
|
|
77
|
+
* @returns True if the value has a key string and optional version string
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const ref = { key: 'auth.login' };
|
|
82
|
+
* if (isOptionalVersionedSpecRef(ref)) {
|
|
83
|
+
* console.log(`Spec: ${ref.key}${ref.version ? `@${ref.version}` : ''}`);
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
declare function isOptionalVersionedSpecRef(ref: unknown): ref is OptionalVersionedSpecRef;
|
|
88
|
+
/**
|
|
89
|
+
* Checks if a value is a valid SpecKeyRef.
|
|
90
|
+
*
|
|
91
|
+
* @param ref - The value to check
|
|
92
|
+
* @returns True if the value has a key string
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const ref = { key: 'premium-features' };
|
|
97
|
+
* if (isSpecKeyRef(ref)) {
|
|
98
|
+
* console.log(`Feature: ${ref.key}`);
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
declare function isSpecKeyRef(ref: unknown): ref is SpecKeyRef;
|
|
103
|
+
/**
|
|
104
|
+
* Creates a versioned spec reference.
|
|
105
|
+
*
|
|
106
|
+
* @param key - The spec key (e.g., "auth.login")
|
|
107
|
+
* @param version - The semantic version (e.g., "1.0.0")
|
|
108
|
+
* @returns A VersionedSpecRef object
|
|
109
|
+
* @throws {Error} If key or version is empty
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const ref = createVersionedRef('auth.login', '1.0.0');
|
|
114
|
+
* // { key: 'auth.login', version: '1.0.0' }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
declare function createVersionedRef(key: string, version: string): VersionedSpecRef;
|
|
118
|
+
/**
|
|
119
|
+
* Creates an optional versioned spec reference.
|
|
120
|
+
*
|
|
121
|
+
* @param key - The spec key (e.g., "auth.login")
|
|
122
|
+
* @param version - Optional semantic version
|
|
123
|
+
* @returns An OptionalVersionedSpecRef object
|
|
124
|
+
* @throws {Error} If key is empty
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* // Reference to latest version
|
|
129
|
+
* const latestRef = createOptionalRef('auth.login');
|
|
130
|
+
* // { key: 'auth.login' }
|
|
131
|
+
*
|
|
132
|
+
* // Reference to specific version
|
|
133
|
+
* const specificRef = createOptionalRef('auth.login', '1.0.0');
|
|
134
|
+
* // { key: 'auth.login', version: '1.0.0' }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
declare function createOptionalRef(key: string, version?: string): OptionalVersionedSpecRef;
|
|
138
|
+
/**
|
|
139
|
+
* Creates a spec key reference.
|
|
140
|
+
*
|
|
141
|
+
* @param key - The spec key (e.g., "premium-features")
|
|
142
|
+
* @returns A SpecKeyRef object
|
|
143
|
+
* @throws {Error} If key is empty
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const ref = createKeyRef('premium-features');
|
|
148
|
+
* // { key: 'premium-features' }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
declare function createKeyRef(key: string): SpecKeyRef;
|
|
152
|
+
/**
|
|
153
|
+
* Formats a versioned ref as a string key.
|
|
154
|
+
*
|
|
155
|
+
* @param ref - The versioned spec reference
|
|
156
|
+
* @returns A string in the format "key.vversion"
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const str = formatVersionedRefKey({ key: 'auth.login', version: '1.0.0' });
|
|
161
|
+
* // "auth.login.v1.0.0"
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare function formatVersionedRefKey(ref: VersionedSpecRef): string;
|
|
165
|
+
/**
|
|
166
|
+
* Parses a versioned ref string back into a ref object.
|
|
167
|
+
*
|
|
168
|
+
* @param refKey - A string in the format "key.vversion"
|
|
169
|
+
* @returns A VersionedSpecRef or undefined if parsing fails
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const ref = parseVersionedRefKey('auth.login.v1.0.0');
|
|
174
|
+
* // { key: 'auth.login', version: '1.0.0' }
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
declare function parseVersionedRefKey(refKey: string): VersionedSpecRef | undefined;
|
|
178
|
+
//#endregion
|
|
179
|
+
export { OptionalVersionedSpecRef, SpecKeyRef, VersionedSpecRef, createKeyRef, createOptionalRef, createVersionedRef, formatVersionedRefKey, isOptionalVersionedSpecRef, isSpecKeyRef, isVersionedSpecRef, parseVersionedRefKey };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
//#region src/versioning/refs.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a value is a valid VersionedSpecRef.
|
|
4
|
+
*
|
|
5
|
+
* @param ref - The value to check
|
|
6
|
+
* @returns True if the value has both key and version as strings
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const ref = { key: 'auth.login', version: '1.0.0' };
|
|
11
|
+
* if (isVersionedSpecRef(ref)) {
|
|
12
|
+
* console.log(`Spec: ${ref.key}@${ref.version}`);
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
function isVersionedSpecRef(ref) {
|
|
17
|
+
return typeof ref === "object" && ref !== null && "key" in ref && typeof ref.key === "string" && ref.key.length > 0 && "version" in ref && typeof ref.version === "string" && ref.version.length > 0;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Checks if a value is a valid OptionalVersionedSpecRef.
|
|
21
|
+
*
|
|
22
|
+
* @param ref - The value to check
|
|
23
|
+
* @returns True if the value has a key string and optional version string
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const ref = { key: 'auth.login' };
|
|
28
|
+
* if (isOptionalVersionedSpecRef(ref)) {
|
|
29
|
+
* console.log(`Spec: ${ref.key}${ref.version ? `@${ref.version}` : ''}`);
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
function isOptionalVersionedSpecRef(ref) {
|
|
34
|
+
if (typeof ref !== "object" || ref === null) return false;
|
|
35
|
+
if (!("key" in ref)) return false;
|
|
36
|
+
if (typeof ref.key !== "string" || ref.key.length === 0) return false;
|
|
37
|
+
if ("version" in ref && ref.version != null) return typeof ref.version === "string";
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Checks if a value is a valid SpecKeyRef.
|
|
42
|
+
*
|
|
43
|
+
* @param ref - The value to check
|
|
44
|
+
* @returns True if the value has a key string
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const ref = { key: 'premium-features' };
|
|
49
|
+
* if (isSpecKeyRef(ref)) {
|
|
50
|
+
* console.log(`Feature: ${ref.key}`);
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
function isSpecKeyRef(ref) {
|
|
55
|
+
return typeof ref === "object" && ref !== null && "key" in ref && typeof ref.key === "string" && ref.key.length > 0;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Creates a versioned spec reference.
|
|
59
|
+
*
|
|
60
|
+
* @param key - The spec key (e.g., "auth.login")
|
|
61
|
+
* @param version - The semantic version (e.g., "1.0.0")
|
|
62
|
+
* @returns A VersionedSpecRef object
|
|
63
|
+
* @throws {Error} If key or version is empty
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const ref = createVersionedRef('auth.login', '1.0.0');
|
|
68
|
+
* // { key: 'auth.login', version: '1.0.0' }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
function createVersionedRef(key, version) {
|
|
72
|
+
if (!key || key.trim().length === 0) throw new Error("Spec key cannot be empty");
|
|
73
|
+
if (!version || version.trim().length === 0) throw new Error("Spec version cannot be empty");
|
|
74
|
+
return {
|
|
75
|
+
key: key.trim(),
|
|
76
|
+
version: version.trim()
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Creates an optional versioned spec reference.
|
|
81
|
+
*
|
|
82
|
+
* @param key - The spec key (e.g., "auth.login")
|
|
83
|
+
* @param version - Optional semantic version
|
|
84
|
+
* @returns An OptionalVersionedSpecRef object
|
|
85
|
+
* @throws {Error} If key is empty
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* // Reference to latest version
|
|
90
|
+
* const latestRef = createOptionalRef('auth.login');
|
|
91
|
+
* // { key: 'auth.login' }
|
|
92
|
+
*
|
|
93
|
+
* // Reference to specific version
|
|
94
|
+
* const specificRef = createOptionalRef('auth.login', '1.0.0');
|
|
95
|
+
* // { key: 'auth.login', version: '1.0.0' }
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
function createOptionalRef(key, version) {
|
|
99
|
+
if (!key || key.trim().length === 0) throw new Error("Spec key cannot be empty");
|
|
100
|
+
const ref = { key: key.trim() };
|
|
101
|
+
if (version != null && version.trim().length > 0) ref.version = version.trim();
|
|
102
|
+
return ref;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Creates a spec key reference.
|
|
106
|
+
*
|
|
107
|
+
* @param key - The spec key (e.g., "premium-features")
|
|
108
|
+
* @returns A SpecKeyRef object
|
|
109
|
+
* @throws {Error} If key is empty
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const ref = createKeyRef('premium-features');
|
|
114
|
+
* // { key: 'premium-features' }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
function createKeyRef(key) {
|
|
118
|
+
if (!key || key.trim().length === 0) throw new Error("Spec key cannot be empty");
|
|
119
|
+
return { key: key.trim() };
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Formats a versioned ref as a string key.
|
|
123
|
+
*
|
|
124
|
+
* @param ref - The versioned spec reference
|
|
125
|
+
* @returns A string in the format "key.vversion"
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const str = formatVersionedRefKey({ key: 'auth.login', version: '1.0.0' });
|
|
130
|
+
* // "auth.login.v1.0.0"
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
function formatVersionedRefKey(ref) {
|
|
134
|
+
return `${ref.key}.v${ref.version}`;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Parses a versioned ref string back into a ref object.
|
|
138
|
+
*
|
|
139
|
+
* @param refKey - A string in the format "key.vversion"
|
|
140
|
+
* @returns A VersionedSpecRef or undefined if parsing fails
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* const ref = parseVersionedRefKey('auth.login.v1.0.0');
|
|
145
|
+
* // { key: 'auth.login', version: '1.0.0' }
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
function parseVersionedRefKey(refKey) {
|
|
149
|
+
const match = refKey.match(/^(.+)\.v(\d+\.\d+\.\d+(?:-.+)?)$/);
|
|
150
|
+
if (!match) return void 0;
|
|
151
|
+
const key = match[1];
|
|
152
|
+
const version = match[2];
|
|
153
|
+
if (!key || !version) return void 0;
|
|
154
|
+
return {
|
|
155
|
+
key,
|
|
156
|
+
version
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
//#endregion
|
|
161
|
+
export { createKeyRef, createOptionalRef, createVersionedRef, formatVersionedRefKey, isOptionalVersionedSpecRef, isSpecKeyRef, isVersionedSpecRef, parseVersionedRefKey };
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { Step, WorkflowSpec } from "./spec.js";
|
|
2
|
+
import { StepExecution, WorkflowState } from "./state.js";
|
|
3
|
+
|
|
4
|
+
//#region src/workflow/context.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Error thrown when a workflow operation fails.
|
|
8
|
+
*/
|
|
9
|
+
declare class WorkflowContextError extends Error {
|
|
10
|
+
readonly errorType: WorkflowContextErrorType;
|
|
11
|
+
readonly workflowId: string;
|
|
12
|
+
readonly details?: Record<string, unknown>;
|
|
13
|
+
constructor(type: WorkflowContextErrorType, workflowId: string, message: string, details?: Record<string, unknown>);
|
|
14
|
+
}
|
|
15
|
+
type WorkflowContextErrorType = 'invalid_transition' | 'workflow_completed' | 'workflow_failed' | 'step_not_found' | 'guard_rejected' | 'sla_violated';
|
|
16
|
+
interface WorkflowTransitionResult {
|
|
17
|
+
success: boolean;
|
|
18
|
+
previousStep: string;
|
|
19
|
+
currentStep: string;
|
|
20
|
+
status: WorkflowState['status'];
|
|
21
|
+
error?: string;
|
|
22
|
+
}
|
|
23
|
+
interface AvailableTransition {
|
|
24
|
+
from: string;
|
|
25
|
+
to: string;
|
|
26
|
+
label?: string;
|
|
27
|
+
condition?: string;
|
|
28
|
+
}
|
|
29
|
+
interface SlaStatus {
|
|
30
|
+
key: string;
|
|
31
|
+
type: 'workflow' | 'step';
|
|
32
|
+
stepId?: string;
|
|
33
|
+
limitMs: number;
|
|
34
|
+
elapsedMs: number;
|
|
35
|
+
remainingMs: number;
|
|
36
|
+
violated: boolean;
|
|
37
|
+
percentUsed: number;
|
|
38
|
+
}
|
|
39
|
+
interface WorkflowEvent {
|
|
40
|
+
timestamp: Date;
|
|
41
|
+
type: 'step_started' | 'step_completed' | 'step_failed' | 'step_retried' | 'transition';
|
|
42
|
+
stepId?: string;
|
|
43
|
+
fromStep?: string;
|
|
44
|
+
toStep?: string;
|
|
45
|
+
input?: unknown;
|
|
46
|
+
output?: unknown;
|
|
47
|
+
error?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Runtime context for interacting with a workflow instance.
|
|
51
|
+
*
|
|
52
|
+
* Provides a simplified interface over WorkflowRunner for common
|
|
53
|
+
* workflow operations like state access, transitions, and SLA tracking.
|
|
54
|
+
*/
|
|
55
|
+
interface WorkflowContext<TData = Record<string, unknown>> {
|
|
56
|
+
/** Unique workflow instance identifier. */
|
|
57
|
+
readonly workflowId: string;
|
|
58
|
+
/** Workflow spec key. */
|
|
59
|
+
readonly workflowKey: string;
|
|
60
|
+
/** Workflow spec version. */
|
|
61
|
+
readonly workflowVersion: string;
|
|
62
|
+
/** Current step identifier. */
|
|
63
|
+
readonly currentStep: string;
|
|
64
|
+
/** Current workflow status. */
|
|
65
|
+
readonly status: WorkflowState['status'];
|
|
66
|
+
/** Workflow data/state. */
|
|
67
|
+
readonly data: TData;
|
|
68
|
+
/** Execution history. */
|
|
69
|
+
readonly history: readonly StepExecution[];
|
|
70
|
+
/**
|
|
71
|
+
* Get the current workflow state.
|
|
72
|
+
* @returns Full workflow state object
|
|
73
|
+
*/
|
|
74
|
+
getState(): WorkflowState;
|
|
75
|
+
/**
|
|
76
|
+
* Get a value from workflow data.
|
|
77
|
+
* @param key - Data key to retrieve
|
|
78
|
+
* @returns Value or undefined
|
|
79
|
+
*/
|
|
80
|
+
getData<T = unknown>(key: string): T | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Check if workflow is in a terminal state.
|
|
83
|
+
* @returns True if completed, failed, or cancelled
|
|
84
|
+
*/
|
|
85
|
+
isTerminal(): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Check if workflow is running.
|
|
88
|
+
* @returns True if status is 'running'
|
|
89
|
+
*/
|
|
90
|
+
isRunning(): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Get the current step definition.
|
|
93
|
+
* @returns Step definition or undefined
|
|
94
|
+
*/
|
|
95
|
+
getCurrentStepDef(): Step | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Get the retry count for a step.
|
|
98
|
+
* @param stepId - Step to check (defaults to current step)
|
|
99
|
+
* @returns Number of retry attempts
|
|
100
|
+
*/
|
|
101
|
+
getRetryCount(stepId?: string): number;
|
|
102
|
+
/**
|
|
103
|
+
* Check if a transition to a target step is valid.
|
|
104
|
+
* @param toStepId - Target step identifier
|
|
105
|
+
* @returns True if transition is valid from current step
|
|
106
|
+
*/
|
|
107
|
+
canTransition(toStepId: string): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Get all available transitions from current step.
|
|
110
|
+
* @returns Array of available transitions
|
|
111
|
+
*/
|
|
112
|
+
getAvailableTransitions(): AvailableTransition[];
|
|
113
|
+
/**
|
|
114
|
+
* Check if the current step has any outgoing transitions.
|
|
115
|
+
* @returns True if there are outgoing transitions
|
|
116
|
+
*/
|
|
117
|
+
hasNextStep(): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Get remaining time for an SLA constraint.
|
|
120
|
+
* @param slaKey - 'totalDuration' or step ID
|
|
121
|
+
* @returns Remaining milliseconds, or null if no SLA configured
|
|
122
|
+
*/
|
|
123
|
+
getRemainingTime(slaKey: string): number | null;
|
|
124
|
+
/**
|
|
125
|
+
* Check if an SLA constraint has been violated.
|
|
126
|
+
* @param slaKey - 'totalDuration' or step ID
|
|
127
|
+
* @returns True if SLA has been violated
|
|
128
|
+
*/
|
|
129
|
+
isSlaViolated(slaKey: string): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Get status of all SLA constraints.
|
|
132
|
+
* @returns Array of SLA statuses
|
|
133
|
+
*/
|
|
134
|
+
getAllSlaStatuses(): SlaStatus[];
|
|
135
|
+
/**
|
|
136
|
+
* Check if compensation/rollback is available.
|
|
137
|
+
* @returns True if workflow has compensation strategy
|
|
138
|
+
*/
|
|
139
|
+
hasCompensation(): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Get steps that have compensation handlers.
|
|
142
|
+
* @returns Array of step IDs with compensation
|
|
143
|
+
*/
|
|
144
|
+
getCompensableSteps(): string[];
|
|
145
|
+
/**
|
|
146
|
+
* Convert execution history to workflow events.
|
|
147
|
+
* @returns Array of workflow events
|
|
148
|
+
*/
|
|
149
|
+
getEvents(): WorkflowEvent[];
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Creates a workflow context from state and spec.
|
|
153
|
+
*
|
|
154
|
+
* @param state - Current workflow state
|
|
155
|
+
* @param spec - Workflow specification
|
|
156
|
+
* @returns WorkflowContext for interacting with the workflow
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const state = await runner.getState(workflowId);
|
|
161
|
+
* const spec = registry.get(state.workflowName, state.workflowVersion);
|
|
162
|
+
* const ctx = createWorkflowContext(state, spec);
|
|
163
|
+
*
|
|
164
|
+
* console.log('Current step:', ctx.currentStep);
|
|
165
|
+
* console.log('Available transitions:', ctx.getAvailableTransitions());
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
declare function createWorkflowContext<TData = Record<string, unknown>>(state: WorkflowState, spec: WorkflowSpec): WorkflowContext<TData>;
|
|
169
|
+
/**
|
|
170
|
+
* Calculate workflow progress as a percentage.
|
|
171
|
+
*
|
|
172
|
+
* @param ctx - Workflow context
|
|
173
|
+
* @returns Progress percentage (0-100)
|
|
174
|
+
*/
|
|
175
|
+
declare function calculateWorkflowProgress(ctx: WorkflowContext): number;
|
|
176
|
+
/**
|
|
177
|
+
* Get the duration of a workflow in milliseconds.
|
|
178
|
+
*
|
|
179
|
+
* @param ctx - Workflow context
|
|
180
|
+
* @returns Duration in milliseconds
|
|
181
|
+
*/
|
|
182
|
+
declare function getWorkflowDuration(ctx: WorkflowContext): number;
|
|
183
|
+
/**
|
|
184
|
+
* Get the average step duration in milliseconds.
|
|
185
|
+
*
|
|
186
|
+
* @param ctx - Workflow context
|
|
187
|
+
* @returns Average duration or 0 if no completed steps
|
|
188
|
+
*/
|
|
189
|
+
declare function getAverageStepDuration(ctx: WorkflowContext): number;
|
|
190
|
+
//#endregion
|
|
191
|
+
export { AvailableTransition, SlaStatus, WorkflowContext, WorkflowContextError, WorkflowContextErrorType, WorkflowEvent, WorkflowTransitionResult, calculateWorkflowProgress, createWorkflowContext, getAverageStepDuration, getWorkflowDuration };
|