@appport/contract-builder 1.0.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 +396 -0
- package/dist/compatibility.d.ts +24 -0
- package/dist/compatibility.d.ts.map +1 -0
- package/dist/compatibility.js +86 -0
- package/dist/compatibility.js.map +1 -0
- package/dist/contract.d.ts +258 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +316 -0
- package/dist/contract.js.map +1 -0
- package/dist/diff.d.ts +32 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +110 -0
- package/dist/diff.js.map +1 -0
- package/dist/generators/python-server.d.ts +13 -0
- package/dist/generators/python-server.d.ts.map +1 -0
- package/dist/generators/python-server.js +193 -0
- package/dist/generators/python-server.js.map +1 -0
- package/dist/generators/stubs.d.ts +10 -0
- package/dist/generators/stubs.d.ts.map +1 -0
- package/dist/generators/stubs.js +58 -0
- package/dist/generators/stubs.js.map +1 -0
- package/dist/generators/typescript-server.d.ts +12 -0
- package/dist/generators/typescript-server.d.ts.map +1 -0
- package/dist/generators/typescript-server.js +190 -0
- package/dist/generators/typescript-server.js.map +1 -0
- package/dist/hooks.d.ts +73 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +55 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +23 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +148 -0
- package/dist/manifest.js.map +1 -0
- package/dist/validate.d.ts +12 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +238 -0
- package/dist/validate.js.map +1 -0
- package/package.json +29 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import type { JSONSchema } from "@appport/protocol";
|
|
2
|
+
import { type ContractBuilderHooks } from "./hooks.js";
|
|
3
|
+
/**
|
|
4
|
+
* Effect descriptor: what state changes a capability produces.
|
|
5
|
+
*/
|
|
6
|
+
export interface CapabilityEffect {
|
|
7
|
+
type: string;
|
|
8
|
+
description: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Contract capability definition - simpler than CapabilityManifestEntry.
|
|
12
|
+
* Represents a single version of a capability.
|
|
13
|
+
*/
|
|
14
|
+
export interface ContractCapability {
|
|
15
|
+
name: string;
|
|
16
|
+
version: number;
|
|
17
|
+
description?: string;
|
|
18
|
+
purpose?: string;
|
|
19
|
+
kind?: "request" | "stream";
|
|
20
|
+
input: JSONSchema;
|
|
21
|
+
output: JSONSchema;
|
|
22
|
+
authority?: string;
|
|
23
|
+
authorization?: string[];
|
|
24
|
+
effects?: CapabilityEffect[];
|
|
25
|
+
idempotency?: "supported" | "unsupported";
|
|
26
|
+
concurrency?: {
|
|
27
|
+
mode: "parallel";
|
|
28
|
+
} | {
|
|
29
|
+
mode: "serialized";
|
|
30
|
+
} | {
|
|
31
|
+
mode: "keyed";
|
|
32
|
+
key: string;
|
|
33
|
+
};
|
|
34
|
+
timeoutMs?: number;
|
|
35
|
+
emits?: string[];
|
|
36
|
+
deprecated?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Contract event definition.
|
|
40
|
+
*/
|
|
41
|
+
export interface ContractEvent {
|
|
42
|
+
name: string;
|
|
43
|
+
version: number;
|
|
44
|
+
description?: string;
|
|
45
|
+
payload: JSONSchema;
|
|
46
|
+
authorization?: string[];
|
|
47
|
+
deprecated?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Contract stream definition.
|
|
51
|
+
*/
|
|
52
|
+
export interface ContractStream {
|
|
53
|
+
name: string;
|
|
54
|
+
version: number;
|
|
55
|
+
description?: string;
|
|
56
|
+
input: JSONSchema;
|
|
57
|
+
item: JSONSchema;
|
|
58
|
+
authorization?: string[];
|
|
59
|
+
deprecated?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Application metadata for contract.
|
|
63
|
+
*/
|
|
64
|
+
export interface ContractApplication {
|
|
65
|
+
id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
version: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
documentation?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Capability requirement: declares a capability this application requires from another application.
|
|
73
|
+
* Supports version constraints (e.g., ^1, ~1.2, >=2) to enable dynamic composition.
|
|
74
|
+
*/
|
|
75
|
+
export interface CapabilityRequirement {
|
|
76
|
+
name: string;
|
|
77
|
+
versionConstraint: string;
|
|
78
|
+
purpose?: string;
|
|
79
|
+
provider?: {
|
|
80
|
+
applicationId?: string;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* A portable AppPort application contract.
|
|
85
|
+
* This is the canonical machine-readable format.
|
|
86
|
+
*/
|
|
87
|
+
export interface Contract {
|
|
88
|
+
protocol: string;
|
|
89
|
+
application: ContractApplication;
|
|
90
|
+
capabilities: ContractCapability[];
|
|
91
|
+
events: ContractEvent[];
|
|
92
|
+
streams?: ContractStream[];
|
|
93
|
+
requires?: CapabilityRequirement[];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Create a new contract with sensible defaults.
|
|
97
|
+
*/
|
|
98
|
+
export declare function createContract(application: ContractApplication): Contract;
|
|
99
|
+
/**
|
|
100
|
+
* Requirement builder for fluent API.
|
|
101
|
+
* Provides methods to construct a capability requirement step-by-step.
|
|
102
|
+
*/
|
|
103
|
+
export declare class RequirementBuilder {
|
|
104
|
+
private requirement;
|
|
105
|
+
constructor(name: string, versionConstraint: string);
|
|
106
|
+
/**
|
|
107
|
+
* Set the purpose of this requirement.
|
|
108
|
+
*/
|
|
109
|
+
purpose(text: string): RequirementBuilder;
|
|
110
|
+
/**
|
|
111
|
+
* Constrain the provider to a specific application ID.
|
|
112
|
+
*/
|
|
113
|
+
from(applicationId: string): RequirementBuilder;
|
|
114
|
+
/**
|
|
115
|
+
* Build and return the requirement.
|
|
116
|
+
*/
|
|
117
|
+
build(): CapabilityRequirement;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Create a new requirement builder.
|
|
121
|
+
*/
|
|
122
|
+
export declare function requirement(name: string, versionConstraint: string): RequirementBuilder;
|
|
123
|
+
/**
|
|
124
|
+
* Capability builder for fluent API.
|
|
125
|
+
* Provides methods to construct a capability step-by-step.
|
|
126
|
+
*/
|
|
127
|
+
export declare class CapabilityBuilder {
|
|
128
|
+
private capability;
|
|
129
|
+
constructor(name: string, version: string | number);
|
|
130
|
+
/**
|
|
131
|
+
* Set the purpose of this capability.
|
|
132
|
+
*/
|
|
133
|
+
purpose(text: string): CapabilityBuilder;
|
|
134
|
+
/**
|
|
135
|
+
* Set the input schema.
|
|
136
|
+
*/
|
|
137
|
+
input(schema: JSONSchema): CapabilityBuilder;
|
|
138
|
+
/**
|
|
139
|
+
* Set the output schema.
|
|
140
|
+
*/
|
|
141
|
+
output(schema: JSONSchema): CapabilityBuilder;
|
|
142
|
+
/**
|
|
143
|
+
* Set the authority (domain) this capability belongs to.
|
|
144
|
+
*/
|
|
145
|
+
authority(auth: string): CapabilityBuilder;
|
|
146
|
+
/**
|
|
147
|
+
* Add a required authorization scope.
|
|
148
|
+
*/
|
|
149
|
+
requiresScope(scope: string): CapabilityBuilder;
|
|
150
|
+
/**
|
|
151
|
+
* Add an effect this capability produces.
|
|
152
|
+
*/
|
|
153
|
+
effect(effect: CapabilityEffect): CapabilityBuilder;
|
|
154
|
+
/**
|
|
155
|
+
* Add an event this capability emits.
|
|
156
|
+
*/
|
|
157
|
+
emits(event: string): CapabilityBuilder;
|
|
158
|
+
/**
|
|
159
|
+
* Set a description.
|
|
160
|
+
*/
|
|
161
|
+
description(text: string): CapabilityBuilder;
|
|
162
|
+
/**
|
|
163
|
+
* Set the kind (request or stream).
|
|
164
|
+
*/
|
|
165
|
+
kind(kind: "request" | "stream"): CapabilityBuilder;
|
|
166
|
+
/**
|
|
167
|
+
* Build and return the capability.
|
|
168
|
+
*/
|
|
169
|
+
build(): ContractCapability;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Create a new capability builder.
|
|
173
|
+
*/
|
|
174
|
+
export declare function capability(name: string, version: string | number): CapabilityBuilder;
|
|
175
|
+
/**
|
|
176
|
+
* Contract builder for managing capabilities and attachment.
|
|
177
|
+
* Extends the Contract interface with builder methods.
|
|
178
|
+
*/
|
|
179
|
+
export declare class ContractBuilder implements Contract {
|
|
180
|
+
protocol: string;
|
|
181
|
+
application: ContractApplication;
|
|
182
|
+
capabilities: ContractCapability[];
|
|
183
|
+
events: ContractEvent[];
|
|
184
|
+
streams?: ContractStream[];
|
|
185
|
+
requires: CapabilityRequirement[];
|
|
186
|
+
private hooksManager;
|
|
187
|
+
constructor(contract: Contract);
|
|
188
|
+
/**
|
|
189
|
+
* Register hooks for contract builder events.
|
|
190
|
+
*/
|
|
191
|
+
hooks(hooks: Partial<ContractBuilderHooks>): this;
|
|
192
|
+
/**
|
|
193
|
+
* Create a new capability builder for this contract.
|
|
194
|
+
*/
|
|
195
|
+
capability(name: string, version: string | number): CapabilityBuilder;
|
|
196
|
+
/**
|
|
197
|
+
* Create a new requirement builder for this contract.
|
|
198
|
+
*/
|
|
199
|
+
requirement(name: string, versionConstraint: string): RequirementBuilder;
|
|
200
|
+
/**
|
|
201
|
+
* Attach a capability to this contract.
|
|
202
|
+
*/
|
|
203
|
+
attach(capability: ContractCapability): this;
|
|
204
|
+
/**
|
|
205
|
+
* Detach a capability from this contract by ID (name@version format).
|
|
206
|
+
*/
|
|
207
|
+
detach(capabilityId: string): this;
|
|
208
|
+
/**
|
|
209
|
+
* Get a capability by ID (name@version format).
|
|
210
|
+
*/
|
|
211
|
+
getCapability(capabilityId: string): ContractCapability | undefined;
|
|
212
|
+
/**
|
|
213
|
+
* List all capabilities (provided capabilities).
|
|
214
|
+
*/
|
|
215
|
+
listCapabilities(): ContractCapability[];
|
|
216
|
+
/**
|
|
217
|
+
* List all provided capabilities (alias for listCapabilities).
|
|
218
|
+
*/
|
|
219
|
+
listProvidedCapabilities(): ContractCapability[];
|
|
220
|
+
/**
|
|
221
|
+
* Add a required capability to this contract.
|
|
222
|
+
*/
|
|
223
|
+
addRequirement(requirement: CapabilityRequirement): this;
|
|
224
|
+
/**
|
|
225
|
+
* Remove a required capability from this contract.
|
|
226
|
+
*/
|
|
227
|
+
removeRequirement(name: string): this;
|
|
228
|
+
/**
|
|
229
|
+
* Get a requirement by capability name.
|
|
230
|
+
*/
|
|
231
|
+
getRequirement(name: string): CapabilityRequirement | undefined;
|
|
232
|
+
/**
|
|
233
|
+
* List all required capabilities.
|
|
234
|
+
*/
|
|
235
|
+
listRequiredCapabilities(): CapabilityRequirement[];
|
|
236
|
+
/**
|
|
237
|
+
* Check if this contract requires a specific capability.
|
|
238
|
+
*/
|
|
239
|
+
requiresCapability(name: string): boolean;
|
|
240
|
+
/**
|
|
241
|
+
* Check if this contract has (provides) a capability.
|
|
242
|
+
*/
|
|
243
|
+
hasCapability(capabilityId: string): boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Provide a capability (check if provided).
|
|
246
|
+
* This is a query method to check if a capability is provided.
|
|
247
|
+
*/
|
|
248
|
+
provides(capabilityId: string): boolean;
|
|
249
|
+
/**
|
|
250
|
+
* Get capability ID in the format "name@version".
|
|
251
|
+
*/
|
|
252
|
+
private getCapabilityId;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Create a new contract builder with sensible defaults.
|
|
256
|
+
*/
|
|
257
|
+
export declare function createContractBuilder(application: ContractApplication): ContractBuilder;
|
|
258
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAA+B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/dist/contract.js
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { ContractBuilderHooksManager } from "./hooks.js";
|
|
2
|
+
/**
|
|
3
|
+
* Create a new contract with sensible defaults.
|
|
4
|
+
*/
|
|
5
|
+
export function createContract(application) {
|
|
6
|
+
return {
|
|
7
|
+
protocol: "appport/1",
|
|
8
|
+
application,
|
|
9
|
+
capabilities: [],
|
|
10
|
+
events: [],
|
|
11
|
+
streams: [],
|
|
12
|
+
requires: []
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Requirement builder for fluent API.
|
|
17
|
+
* Provides methods to construct a capability requirement step-by-step.
|
|
18
|
+
*/
|
|
19
|
+
export class RequirementBuilder {
|
|
20
|
+
requirement;
|
|
21
|
+
constructor(name, versionConstraint) {
|
|
22
|
+
this.requirement = {
|
|
23
|
+
name,
|
|
24
|
+
versionConstraint
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Set the purpose of this requirement.
|
|
29
|
+
*/
|
|
30
|
+
purpose(text) {
|
|
31
|
+
this.requirement.purpose = text;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Constrain the provider to a specific application ID.
|
|
36
|
+
*/
|
|
37
|
+
from(applicationId) {
|
|
38
|
+
if (!this.requirement.provider) {
|
|
39
|
+
this.requirement.provider = {};
|
|
40
|
+
}
|
|
41
|
+
this.requirement.provider.applicationId = applicationId;
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Build and return the requirement.
|
|
46
|
+
*/
|
|
47
|
+
build() {
|
|
48
|
+
return { ...this.requirement };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create a new requirement builder.
|
|
53
|
+
*/
|
|
54
|
+
export function requirement(name, versionConstraint) {
|
|
55
|
+
return new RequirementBuilder(name, versionConstraint);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Capability builder for fluent API.
|
|
59
|
+
* Provides methods to construct a capability step-by-step.
|
|
60
|
+
*/
|
|
61
|
+
export class CapabilityBuilder {
|
|
62
|
+
capability;
|
|
63
|
+
constructor(name, version) {
|
|
64
|
+
this.capability = {
|
|
65
|
+
name,
|
|
66
|
+
version: typeof version === "string" ? parseInt(version, 10) : version,
|
|
67
|
+
input: { type: "object", properties: {} },
|
|
68
|
+
output: { type: "object", properties: {} }
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Set the purpose of this capability.
|
|
73
|
+
*/
|
|
74
|
+
purpose(text) {
|
|
75
|
+
this.capability.purpose = text;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Set the input schema.
|
|
80
|
+
*/
|
|
81
|
+
input(schema) {
|
|
82
|
+
this.capability.input = schema;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Set the output schema.
|
|
87
|
+
*/
|
|
88
|
+
output(schema) {
|
|
89
|
+
this.capability.output = schema;
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Set the authority (domain) this capability belongs to.
|
|
94
|
+
*/
|
|
95
|
+
authority(auth) {
|
|
96
|
+
this.capability.authority = auth;
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Add a required authorization scope.
|
|
101
|
+
*/
|
|
102
|
+
requiresScope(scope) {
|
|
103
|
+
if (!this.capability.authorization) {
|
|
104
|
+
this.capability.authorization = [];
|
|
105
|
+
}
|
|
106
|
+
this.capability.authorization.push(scope);
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Add an effect this capability produces.
|
|
111
|
+
*/
|
|
112
|
+
effect(effect) {
|
|
113
|
+
if (!this.capability.effects) {
|
|
114
|
+
this.capability.effects = [];
|
|
115
|
+
}
|
|
116
|
+
this.capability.effects.push(effect);
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Add an event this capability emits.
|
|
121
|
+
*/
|
|
122
|
+
emits(event) {
|
|
123
|
+
if (!this.capability.emits) {
|
|
124
|
+
this.capability.emits = [];
|
|
125
|
+
}
|
|
126
|
+
this.capability.emits.push(event);
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Set a description.
|
|
131
|
+
*/
|
|
132
|
+
description(text) {
|
|
133
|
+
this.capability.description = text;
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Set the kind (request or stream).
|
|
138
|
+
*/
|
|
139
|
+
kind(kind) {
|
|
140
|
+
this.capability.kind = kind;
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Build and return the capability.
|
|
145
|
+
*/
|
|
146
|
+
build() {
|
|
147
|
+
return { ...this.capability };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Create a new capability builder.
|
|
152
|
+
*/
|
|
153
|
+
export function capability(name, version) {
|
|
154
|
+
return new CapabilityBuilder(name, version);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Contract builder for managing capabilities and attachment.
|
|
158
|
+
* Extends the Contract interface with builder methods.
|
|
159
|
+
*/
|
|
160
|
+
export class ContractBuilder {
|
|
161
|
+
protocol;
|
|
162
|
+
application;
|
|
163
|
+
capabilities;
|
|
164
|
+
events;
|
|
165
|
+
streams;
|
|
166
|
+
requires;
|
|
167
|
+
hooksManager;
|
|
168
|
+
constructor(contract) {
|
|
169
|
+
this.protocol = contract.protocol;
|
|
170
|
+
this.application = contract.application;
|
|
171
|
+
this.capabilities = contract.capabilities;
|
|
172
|
+
this.events = contract.events;
|
|
173
|
+
this.streams = contract.streams;
|
|
174
|
+
this.requires = contract.requires || [];
|
|
175
|
+
this.hooksManager = new ContractBuilderHooksManager();
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Register hooks for contract builder events.
|
|
179
|
+
*/
|
|
180
|
+
hooks(hooks) {
|
|
181
|
+
this.hooksManager.register(hooks);
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Create a new capability builder for this contract.
|
|
186
|
+
*/
|
|
187
|
+
capability(name, version) {
|
|
188
|
+
return new CapabilityBuilder(name, version);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Create a new requirement builder for this contract.
|
|
192
|
+
*/
|
|
193
|
+
requirement(name, versionConstraint) {
|
|
194
|
+
return new RequirementBuilder(name, versionConstraint);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Attach a capability to this contract.
|
|
198
|
+
*/
|
|
199
|
+
attach(capability) {
|
|
200
|
+
// Check if capability with same name and version already exists
|
|
201
|
+
const id = this.getCapabilityId(capability.name, capability.version);
|
|
202
|
+
const existing = this.capabilities.find(c => this.getCapabilityId(c.name, c.version) === id);
|
|
203
|
+
if (existing) {
|
|
204
|
+
throw new Error(`Capability ${id} is already attached to this contract`);
|
|
205
|
+
}
|
|
206
|
+
this.capabilities.push(capability);
|
|
207
|
+
this.hooksManager.callOnCapabilityAdded(capability);
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Detach a capability from this contract by ID (name@version format).
|
|
212
|
+
*/
|
|
213
|
+
detach(capabilityId) {
|
|
214
|
+
const index = this.capabilities.findIndex(c => this.getCapabilityId(c.name, c.version) === capabilityId);
|
|
215
|
+
if (index === -1) {
|
|
216
|
+
throw new Error(`Capability ${capabilityId} not found in this contract`);
|
|
217
|
+
}
|
|
218
|
+
this.capabilities.splice(index, 1);
|
|
219
|
+
this.hooksManager.callOnCapabilityRemoved(capabilityId);
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Get a capability by ID (name@version format).
|
|
224
|
+
*/
|
|
225
|
+
getCapability(capabilityId) {
|
|
226
|
+
return this.capabilities.find(c => this.getCapabilityId(c.name, c.version) === capabilityId);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* List all capabilities (provided capabilities).
|
|
230
|
+
*/
|
|
231
|
+
listCapabilities() {
|
|
232
|
+
return [...this.capabilities];
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* List all provided capabilities (alias for listCapabilities).
|
|
236
|
+
*/
|
|
237
|
+
listProvidedCapabilities() {
|
|
238
|
+
return [...this.capabilities];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Add a required capability to this contract.
|
|
242
|
+
*/
|
|
243
|
+
addRequirement(requirement) {
|
|
244
|
+
// Check if requirement already exists
|
|
245
|
+
const existing = this.requires.find(r => r.name === requirement.name);
|
|
246
|
+
if (existing) {
|
|
247
|
+
throw new Error(`Requirement for ${requirement.name} already exists in this contract`);
|
|
248
|
+
}
|
|
249
|
+
this.requires.push(requirement);
|
|
250
|
+
this.hooksManager.callOnCapabilityRequired(requirement);
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Remove a required capability from this contract.
|
|
255
|
+
*/
|
|
256
|
+
removeRequirement(name) {
|
|
257
|
+
const index = this.requires.findIndex(r => r.name === name);
|
|
258
|
+
if (index === -1) {
|
|
259
|
+
throw new Error(`Requirement for ${name} not found in this contract`);
|
|
260
|
+
}
|
|
261
|
+
this.requires.splice(index, 1);
|
|
262
|
+
this.hooksManager.callOnCapabilityRequirementRemoved(name);
|
|
263
|
+
return this;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Get a requirement by capability name.
|
|
267
|
+
*/
|
|
268
|
+
getRequirement(name) {
|
|
269
|
+
return this.requires.find(r => r.name === name);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* List all required capabilities.
|
|
273
|
+
*/
|
|
274
|
+
listRequiredCapabilities() {
|
|
275
|
+
return [...this.requires];
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Check if this contract requires a specific capability.
|
|
279
|
+
*/
|
|
280
|
+
requiresCapability(name) {
|
|
281
|
+
return this.requires.some(r => r.name === name);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Check if this contract has (provides) a capability.
|
|
285
|
+
*/
|
|
286
|
+
hasCapability(capabilityId) {
|
|
287
|
+
return this.getCapability(capabilityId) !== undefined;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Provide a capability (check if provided).
|
|
291
|
+
* This is a query method to check if a capability is provided.
|
|
292
|
+
*/
|
|
293
|
+
provides(capabilityId) {
|
|
294
|
+
return this.hasCapability(capabilityId);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Get capability ID in the format "name@version".
|
|
298
|
+
*/
|
|
299
|
+
getCapabilityId(name, version) {
|
|
300
|
+
return `${name}@${version}`;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Create a new contract builder with sensible defaults.
|
|
305
|
+
*/
|
|
306
|
+
export function createContractBuilder(application) {
|
|
307
|
+
return new ContractBuilder({
|
|
308
|
+
protocol: "appport/1",
|
|
309
|
+
application,
|
|
310
|
+
capabilities: [],
|
|
311
|
+
events: [],
|
|
312
|
+
streams: [],
|
|
313
|
+
requires: []
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAA6B,MAAM,YAAY,CAAC;AA8FpF;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,WAAgC;IAC7D,OAAO;QACL,QAAQ,EAAE,WAAW;QACrB,WAAW;QACX,YAAY,EAAE,EAAE;QAChB,MAAM,EAAE,EAAE;QAC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AAW;QACX,YAAY,EAAE,EAAE;QAChB,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,EAAE;QACX,QAAQ,EAAE,EAAE;KACb,CAAC,CAAC;AACL,CAAC"}
|
package/dist/diff.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Contract } from "./contract.js";
|
|
2
|
+
export type CapabilityChangeType = "added" | "removed" | "modified";
|
|
3
|
+
export type EventChangeType = "added" | "removed" | "modified";
|
|
4
|
+
export type RequirementChangeType = "added" | "removed" | "modified";
|
|
5
|
+
export interface CapabilityChange {
|
|
6
|
+
type: CapabilityChangeType;
|
|
7
|
+
name: string;
|
|
8
|
+
version: number;
|
|
9
|
+
breaking?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface EventChange {
|
|
12
|
+
type: EventChangeType;
|
|
13
|
+
name: string;
|
|
14
|
+
version: number;
|
|
15
|
+
}
|
|
16
|
+
export interface RequirementChange {
|
|
17
|
+
type: RequirementChangeType;
|
|
18
|
+
name: string;
|
|
19
|
+
versionConstraint?: string;
|
|
20
|
+
breaking?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface ContractDiff {
|
|
23
|
+
capabilities: CapabilityChange[];
|
|
24
|
+
events: EventChange[];
|
|
25
|
+
requirements: RequirementChange[];
|
|
26
|
+
hasBreakingChanges: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Compare two contracts and produce a diff.
|
|
30
|
+
*/
|
|
31
|
+
export declare function diffContracts(from: Contract, to: Contract): ContractDiff;
|
|
32
|
+
//# sourceMappingURL=diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,SAAS,GAAG,UAAU,CAAC;AACpE,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,SAAS,GAAG,UAAU,CAAC;AAC/D,MAAM,MAAM,qBAAqB,GAAG,OAAO,GAAG,SAAS,GAAG,UAAU,CAAC;AAErE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,oBAAoB,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,eAAe,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,qBAAqB,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,gBAAgB,EAAE,CAAC;IACjC,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAClC,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,GAAG,YAAY,CAoIxE"}
|