@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
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ContractCapability, CapabilityRequirement } from "./contract.js";
|
|
2
|
+
/**
|
|
3
|
+
* Hooks for contract authoring lifecycle events.
|
|
4
|
+
* These hooks allow contract authors to react to changes in capabilities and requirements.
|
|
5
|
+
*
|
|
6
|
+
* Note: These are authoring-time hooks only. They do not execute workflows or resolve providers.
|
|
7
|
+
* They are purely for notification and validation during contract construction.
|
|
8
|
+
*/
|
|
9
|
+
export interface ContractBuilderHooks {
|
|
10
|
+
/**
|
|
11
|
+
* Called when a capability is added to the contract.
|
|
12
|
+
*/
|
|
13
|
+
onCapabilityAdded?(capability: ContractCapability): void;
|
|
14
|
+
/**
|
|
15
|
+
* Called when a capability is removed from the contract.
|
|
16
|
+
*/
|
|
17
|
+
onCapabilityRemoved?(capabilityId: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* Called when a capability is modified (detached and re-attached).
|
|
20
|
+
*/
|
|
21
|
+
onCapabilityChanged?(oldCapability: ContractCapability, newCapability: ContractCapability): void;
|
|
22
|
+
/**
|
|
23
|
+
* Called when a requirement is added to the contract.
|
|
24
|
+
*/
|
|
25
|
+
onCapabilityRequired?(requirement: CapabilityRequirement): void;
|
|
26
|
+
/**
|
|
27
|
+
* Called when a requirement is removed from the contract.
|
|
28
|
+
*/
|
|
29
|
+
onCapabilityRequirementRemoved?(name: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Called when a requirement is modified.
|
|
32
|
+
*/
|
|
33
|
+
onCapabilityRequirementChanged?(oldRequirement: CapabilityRequirement, newRequirement: CapabilityRequirement): void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Contract builder hooks manager.
|
|
37
|
+
*/
|
|
38
|
+
export declare class ContractBuilderHooksManager {
|
|
39
|
+
private hooks;
|
|
40
|
+
/**
|
|
41
|
+
* Register hooks for contract builder events.
|
|
42
|
+
*/
|
|
43
|
+
register(hooks: Partial<ContractBuilderHooks>): void;
|
|
44
|
+
/**
|
|
45
|
+
* Call the onCapabilityAdded hook if registered.
|
|
46
|
+
*/
|
|
47
|
+
callOnCapabilityAdded(capability: ContractCapability): void;
|
|
48
|
+
/**
|
|
49
|
+
* Call the onCapabilityRemoved hook if registered.
|
|
50
|
+
*/
|
|
51
|
+
callOnCapabilityRemoved(capabilityId: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Call the onCapabilityChanged hook if registered.
|
|
54
|
+
*/
|
|
55
|
+
callOnCapabilityChanged(oldCapability: ContractCapability, newCapability: ContractCapability): void;
|
|
56
|
+
/**
|
|
57
|
+
* Call the onCapabilityRequired hook if registered.
|
|
58
|
+
*/
|
|
59
|
+
callOnCapabilityRequired(requirement: CapabilityRequirement): void;
|
|
60
|
+
/**
|
|
61
|
+
* Call the onCapabilityRequirementRemoved hook if registered.
|
|
62
|
+
*/
|
|
63
|
+
callOnCapabilityRequirementRemoved(name: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Call the onCapabilityRequirementChanged hook if registered.
|
|
66
|
+
*/
|
|
67
|
+
callOnCapabilityRequirementChanged(oldRequirement: CapabilityRequirement, newRequirement: CapabilityRequirement): void;
|
|
68
|
+
/**
|
|
69
|
+
* Clear all registered hooks.
|
|
70
|
+
*/
|
|
71
|
+
clear(): void;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE/E;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,iBAAiB,CAAC,CAAC,UAAU,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAEzD;;OAEG;IACH,mBAAmB,CAAC,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAEjD;;OAEG;IACH,mBAAmB,CAAC,CAAC,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAEjG;;OAEG;IACH,oBAAoB,CAAC,CAAC,WAAW,EAAE,qBAAqB,GAAG,IAAI,CAAC;IAEhE;;OAEG;IACH,8BAA8B,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpD;;OAEG;IACH,8BAA8B,CAAC,CAAC,cAAc,EAAE,qBAAqB,EAAE,cAAc,EAAE,qBAAqB,GAAG,IAAI,CAAC;CACrH;AAED;;GAEG;AACH,qBAAa,2BAA2B;IACtC,OAAO,CAAC,KAAK,CAA4B;IAEzC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,IAAI;IAIpD;;OAEG;IACH,qBAAqB,CAAC,UAAU,EAAE,kBAAkB,GAAG,IAAI;IAI3D;;OAEG;IACH,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAInD;;OAEG;IACH,uBAAuB,CAAC,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,kBAAkB,GAAG,IAAI;IAInG;;OAEG;IACH,wBAAwB,CAAC,WAAW,EAAE,qBAAqB,GAAG,IAAI;IAIlE;;OAEG;IACH,kCAAkC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAItD;;OAEG;IACH,kCAAkC,CAAC,cAAc,EAAE,qBAAqB,EAAE,cAAc,EAAE,qBAAqB,GAAG,IAAI;IAItH;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd"}
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract builder hooks manager.
|
|
3
|
+
*/
|
|
4
|
+
export class ContractBuilderHooksManager {
|
|
5
|
+
hooks = {};
|
|
6
|
+
/**
|
|
7
|
+
* Register hooks for contract builder events.
|
|
8
|
+
*/
|
|
9
|
+
register(hooks) {
|
|
10
|
+
this.hooks = { ...this.hooks, ...hooks };
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Call the onCapabilityAdded hook if registered.
|
|
14
|
+
*/
|
|
15
|
+
callOnCapabilityAdded(capability) {
|
|
16
|
+
this.hooks.onCapabilityAdded?.(capability);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Call the onCapabilityRemoved hook if registered.
|
|
20
|
+
*/
|
|
21
|
+
callOnCapabilityRemoved(capabilityId) {
|
|
22
|
+
this.hooks.onCapabilityRemoved?.(capabilityId);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Call the onCapabilityChanged hook if registered.
|
|
26
|
+
*/
|
|
27
|
+
callOnCapabilityChanged(oldCapability, newCapability) {
|
|
28
|
+
this.hooks.onCapabilityChanged?.(oldCapability, newCapability);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Call the onCapabilityRequired hook if registered.
|
|
32
|
+
*/
|
|
33
|
+
callOnCapabilityRequired(requirement) {
|
|
34
|
+
this.hooks.onCapabilityRequired?.(requirement);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Call the onCapabilityRequirementRemoved hook if registered.
|
|
38
|
+
*/
|
|
39
|
+
callOnCapabilityRequirementRemoved(name) {
|
|
40
|
+
this.hooks.onCapabilityRequirementRemoved?.(name);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Call the onCapabilityRequirementChanged hook if registered.
|
|
44
|
+
*/
|
|
45
|
+
callOnCapabilityRequirementChanged(oldRequirement, newRequirement) {
|
|
46
|
+
this.hooks.onCapabilityRequirementChanged?.(oldRequirement, newRequirement);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Clear all registered hooks.
|
|
50
|
+
*/
|
|
51
|
+
clear() {
|
|
52
|
+
this.hooks = {};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAyCA;;GAEG;AACH,MAAM,OAAO,2BAA2B;IAC9B,KAAK,GAAyB,EAAE,CAAC;IAEzC;;OAEG;IACH,QAAQ,CAAC,KAAoC;QAC3C,IAAI,CAAC,KAAK,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,qBAAqB,CAAC,UAA8B;QAClD,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,uBAAuB,CAAC,YAAoB;QAC1C,IAAI,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,YAAY,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,uBAAuB,CAAC,aAAiC,EAAE,aAAiC;QAC1F,IAAI,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACjE,CAAC;IAED;;OAEG;IACH,wBAAwB,CAAC,WAAkC;QACzD,IAAI,CAAC,KAAK,CAAC,oBAAoB,EAAE,CAAC,WAAW,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,kCAAkC,CAAC,IAAY;QAC7C,IAAI,CAAC,KAAK,CAAC,8BAA8B,EAAE,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,kCAAkC,CAAC,cAAqC,EAAE,cAAqC;QAC7G,IAAI,CAAC,KAAK,CAAC,8BAA8B,EAAE,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IAC9E,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { createContract, createContractBuilder, capability, requirement, type Contract, type ContractCapability, type CapabilityEffect, type CapabilityRequirement, CapabilityBuilder, RequirementBuilder, ContractBuilder } from "./contract.js";
|
|
2
|
+
export { validateContract, type ValidationResult } from "./validate.js";
|
|
3
|
+
export { diffContracts, type ContractDiff, type RequirementChange } from "./diff.js";
|
|
4
|
+
export { contractToManifest, getContractRequirements } from "./manifest.js";
|
|
5
|
+
export { isCapabilityCompatible, satisfiesVersionConstraint } from "./compatibility.js";
|
|
6
|
+
export { ContractBuilderHooksManager, type ContractBuilderHooks } from "./hooks.js";
|
|
7
|
+
export { generateTypescriptServer } from "./generators/typescript-server.js";
|
|
8
|
+
export { generatePythonServer } from "./generators/python-server.js";
|
|
9
|
+
export { generateCapabilitySkeleton, generateEventSkeleton } from "./generators/stubs.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,QAAQ,EAAE,KAAK,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAClP,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,2BAA2B,EAAE,KAAK,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { createContract, createContractBuilder, capability, requirement, CapabilityBuilder, RequirementBuilder, ContractBuilder } from "./contract.js";
|
|
2
|
+
export { validateContract } from "./validate.js";
|
|
3
|
+
export { diffContracts } from "./diff.js";
|
|
4
|
+
export { contractToManifest, getContractRequirements } from "./manifest.js";
|
|
5
|
+
export { isCapabilityCompatible, satisfiesVersionConstraint } from "./compatibility.js";
|
|
6
|
+
export { ContractBuilderHooksManager } from "./hooks.js";
|
|
7
|
+
export { generateTypescriptServer } from "./generators/typescript-server.js";
|
|
8
|
+
export { generatePythonServer } from "./generators/python-server.js";
|
|
9
|
+
export { generateCapabilitySkeleton, generateEventSkeleton } from "./generators/stubs.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,UAAU,EAAE,WAAW,EAA6F,iBAAiB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAClP,OAAO,EAAE,gBAAgB,EAAyB,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,aAAa,EAA6C,MAAM,WAAW,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,2BAA2B,EAA6B,MAAM,YAAY,CAAC;AACpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AppPortManifest } from "@appport/protocol";
|
|
2
|
+
import type { Contract } from "./contract.js";
|
|
3
|
+
/**
|
|
4
|
+
* Convert a portable Contract to an AppPortManifest.
|
|
5
|
+
* This allows manifests to be generated directly from contracts
|
|
6
|
+
* for use with client generation and other tools.
|
|
7
|
+
*/
|
|
8
|
+
export declare function contractToManifest(contract: Contract): AppPortManifest;
|
|
9
|
+
/**
|
|
10
|
+
* Extract required capabilities from a contract.
|
|
11
|
+
*
|
|
12
|
+
* This provides the requirements separately from the manifest,
|
|
13
|
+
* allowing applications to understand their external dependencies.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getContractRequirements(contract: Contract): Array<{
|
|
16
|
+
name: string;
|
|
17
|
+
versionConstraint: string;
|
|
18
|
+
purpose?: string;
|
|
19
|
+
provider?: {
|
|
20
|
+
applicationId?: string;
|
|
21
|
+
};
|
|
22
|
+
}>;
|
|
23
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA+C,MAAM,mBAAmB,CAAC;AAEtG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,GAAG,eAAe,CAwItE;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,GAAG,KAAK,CAAC;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACvC,CAAC,CAOD"}
|
package/dist/manifest.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { PROTOCOL_ID } from "@appport/protocol";
|
|
2
|
+
/**
|
|
3
|
+
* Convert a portable Contract to an AppPortManifest.
|
|
4
|
+
* This allows manifests to be generated directly from contracts
|
|
5
|
+
* for use with client generation and other tools.
|
|
6
|
+
*/
|
|
7
|
+
export function contractToManifest(contract) {
|
|
8
|
+
// Group capabilities by name
|
|
9
|
+
const capsByName = new Map();
|
|
10
|
+
for (const cap of contract.capabilities) {
|
|
11
|
+
const key = cap.name;
|
|
12
|
+
const existing = capsByName.get(key);
|
|
13
|
+
if (existing) {
|
|
14
|
+
// Add version to existing capability
|
|
15
|
+
existing.versions.push(cap.version);
|
|
16
|
+
existing.definitions.push({
|
|
17
|
+
version: cap.version,
|
|
18
|
+
description: cap.description,
|
|
19
|
+
kind: cap.kind || "request",
|
|
20
|
+
inputSchema: cap.input,
|
|
21
|
+
outputSchema: cap.output,
|
|
22
|
+
authorization: cap.authorization || [],
|
|
23
|
+
idempotency: cap.idempotency,
|
|
24
|
+
concurrency: cap.concurrency,
|
|
25
|
+
timeoutMs: cap.timeoutMs,
|
|
26
|
+
emits: cap.emits,
|
|
27
|
+
deprecated: cap.deprecated
|
|
28
|
+
});
|
|
29
|
+
// Update latestVersion and top-level info if this is the latest
|
|
30
|
+
if (cap.version > existing.latestVersion && !cap.deprecated) {
|
|
31
|
+
existing.latestVersion = cap.version;
|
|
32
|
+
existing.inputSchema = cap.input;
|
|
33
|
+
existing.outputSchema = cap.output;
|
|
34
|
+
existing.authorization = cap.authorization || [];
|
|
35
|
+
existing.description = cap.description;
|
|
36
|
+
existing.idempotency = cap.idempotency;
|
|
37
|
+
existing.concurrency = cap.concurrency;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// Create new capability entry
|
|
42
|
+
const entry = {
|
|
43
|
+
name: cap.name,
|
|
44
|
+
versions: [cap.version],
|
|
45
|
+
latestVersion: cap.version,
|
|
46
|
+
description: cap.description,
|
|
47
|
+
kind: cap.kind || "request",
|
|
48
|
+
inputSchema: cap.input,
|
|
49
|
+
outputSchema: cap.output,
|
|
50
|
+
authorization: cap.authorization || [],
|
|
51
|
+
idempotency: cap.idempotency,
|
|
52
|
+
concurrency: cap.concurrency,
|
|
53
|
+
definitions: [
|
|
54
|
+
{
|
|
55
|
+
version: cap.version,
|
|
56
|
+
description: cap.description,
|
|
57
|
+
kind: cap.kind || "request",
|
|
58
|
+
inputSchema: cap.input,
|
|
59
|
+
outputSchema: cap.output,
|
|
60
|
+
authorization: cap.authorization || [],
|
|
61
|
+
idempotency: cap.idempotency,
|
|
62
|
+
concurrency: cap.concurrency,
|
|
63
|
+
timeoutMs: cap.timeoutMs,
|
|
64
|
+
emits: cap.emits,
|
|
65
|
+
deprecated: cap.deprecated
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
};
|
|
69
|
+
capsByName.set(key, entry);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Group events by name
|
|
73
|
+
const eventsByName = new Map();
|
|
74
|
+
for (const event of contract.events) {
|
|
75
|
+
const key = event.name;
|
|
76
|
+
const existing = eventsByName.get(key);
|
|
77
|
+
if (existing) {
|
|
78
|
+
existing.versions.push(event.version);
|
|
79
|
+
existing.definitions.push({
|
|
80
|
+
version: event.version,
|
|
81
|
+
description: event.description,
|
|
82
|
+
payloadSchema: event.payload,
|
|
83
|
+
authorization: event.authorization || [],
|
|
84
|
+
deprecated: event.deprecated
|
|
85
|
+
});
|
|
86
|
+
if (event.version > existing.latestVersion && !event.deprecated) {
|
|
87
|
+
existing.latestVersion = event.version;
|
|
88
|
+
existing.payloadSchema = event.payload;
|
|
89
|
+
existing.authorization = event.authorization || [];
|
|
90
|
+
existing.description = event.description;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const entry = {
|
|
95
|
+
name: event.name,
|
|
96
|
+
versions: [event.version],
|
|
97
|
+
latestVersion: event.version,
|
|
98
|
+
description: event.description,
|
|
99
|
+
payloadSchema: event.payload,
|
|
100
|
+
authorization: event.authorization || [],
|
|
101
|
+
definitions: [
|
|
102
|
+
{
|
|
103
|
+
version: event.version,
|
|
104
|
+
description: event.description,
|
|
105
|
+
payloadSchema: event.payload,
|
|
106
|
+
authorization: event.authorization || [],
|
|
107
|
+
deprecated: event.deprecated
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
};
|
|
111
|
+
eventsByName.set(key, entry);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Sort versions in each capability and event
|
|
115
|
+
for (const cap of capsByName.values()) {
|
|
116
|
+
cap.versions.sort((a, b) => a - b);
|
|
117
|
+
cap.definitions.sort((a, b) => a.version - b.version);
|
|
118
|
+
}
|
|
119
|
+
for (const event of eventsByName.values()) {
|
|
120
|
+
event.versions.sort((a, b) => a - b);
|
|
121
|
+
event.definitions.sort((a, b) => a.version - b.version);
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
protocol: PROTOCOL_ID,
|
|
125
|
+
application: contract.application,
|
|
126
|
+
capabilities: Array.from(capsByName.values()),
|
|
127
|
+
events: Array.from(eventsByName.values()),
|
|
128
|
+
transports: [
|
|
129
|
+
{ kind: "http", endpoint: "/appport" },
|
|
130
|
+
{ kind: "websocket", endpoint: "/appport" }
|
|
131
|
+
]
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Extract required capabilities from a contract.
|
|
136
|
+
*
|
|
137
|
+
* This provides the requirements separately from the manifest,
|
|
138
|
+
* allowing applications to understand their external dependencies.
|
|
139
|
+
*/
|
|
140
|
+
export function getContractRequirements(contract) {
|
|
141
|
+
return (contract.requires || []).map(req => ({
|
|
142
|
+
name: req.name,
|
|
143
|
+
versionConstraint: req.versionConstraint,
|
|
144
|
+
purpose: req.purpose,
|
|
145
|
+
provider: req.provider
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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,EAAE,QAAQ,CAAC,WAAW;QACjC,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;QAC7C,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;QACzC,UAAU,EAAE;YACV,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE;YACtC,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE;SAC5C;KACF,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAkB;IAMxD,OAAO,CAAC,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC3C,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;QACxC,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,QAAQ,EAAE,GAAG,CAAC,QAAQ;KACvB,CAAC,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Contract } from "./contract.js";
|
|
2
|
+
export interface ValidationIssue {
|
|
3
|
+
level: "error" | "warning";
|
|
4
|
+
message: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ValidationResult {
|
|
8
|
+
valid: boolean;
|
|
9
|
+
issues: ValidationIssue[];
|
|
10
|
+
}
|
|
11
|
+
export declare function validateContract(contract: Contract): ValidationResult;
|
|
12
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAA4D,MAAM,eAAe,CAAC;AAExG,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B;AA0DD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,gBAAgB,CAmNrE"}
|
package/dist/validate.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { isValidApplicationId, validateName } from "@appport/protocol";
|
|
2
|
+
/**
|
|
3
|
+
* Validate a semantic version constraint.
|
|
4
|
+
* Supports: "1", "^1", "~1.2", ">=1", etc.
|
|
5
|
+
*/
|
|
6
|
+
function validateVersionConstraint(constraint) {
|
|
7
|
+
if (!constraint || typeof constraint !== "string") {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
// Simple validation: must start with a digit or a valid semver operator
|
|
11
|
+
const validPattern = /^(>=|<=|>|<|~|\^)?(\d+)(\.(\d+))?(\.(\d+))?(-[a-zA-Z0-9]+)?(\+[a-zA-Z0-9]+)?$/;
|
|
12
|
+
return validPattern.test(constraint.trim());
|
|
13
|
+
}
|
|
14
|
+
function validateJSONSchema(schema) {
|
|
15
|
+
const issues = [];
|
|
16
|
+
if (!schema || typeof schema !== "object") {
|
|
17
|
+
issues.push({ level: "error", message: "Schema must be an object" });
|
|
18
|
+
return issues;
|
|
19
|
+
}
|
|
20
|
+
const s = schema;
|
|
21
|
+
// Check for valid JSON Schema keywords
|
|
22
|
+
const validKeywords = [
|
|
23
|
+
"type",
|
|
24
|
+
"properties",
|
|
25
|
+
"items",
|
|
26
|
+
"required",
|
|
27
|
+
"additionalProperties",
|
|
28
|
+
"minLength",
|
|
29
|
+
"maxLength",
|
|
30
|
+
"minimum",
|
|
31
|
+
"maximum",
|
|
32
|
+
"pattern",
|
|
33
|
+
"format",
|
|
34
|
+
"enum",
|
|
35
|
+
"description",
|
|
36
|
+
"default",
|
|
37
|
+
"$ref",
|
|
38
|
+
"allOf",
|
|
39
|
+
"anyOf",
|
|
40
|
+
"oneOf",
|
|
41
|
+
"not"
|
|
42
|
+
];
|
|
43
|
+
for (const key of Object.keys(s)) {
|
|
44
|
+
if (!validKeywords.includes(key) && !key.startsWith("x-")) {
|
|
45
|
+
issues.push({ level: "warning", message: `Unknown schema keyword: ${key}` });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return issues;
|
|
49
|
+
}
|
|
50
|
+
export function validateContract(contract) {
|
|
51
|
+
const issues = [];
|
|
52
|
+
// Validate protocol
|
|
53
|
+
if (!contract.protocol || contract.protocol !== "appport/1") {
|
|
54
|
+
issues.push({
|
|
55
|
+
level: "error",
|
|
56
|
+
message: `Protocol must be "appport/1", got "${contract.protocol}"`
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
// Validate application
|
|
60
|
+
if (!contract.application) {
|
|
61
|
+
issues.push({ level: "error", message: "Application is required" });
|
|
62
|
+
return { valid: false, issues };
|
|
63
|
+
}
|
|
64
|
+
const { application } = contract;
|
|
65
|
+
if (!application.id) {
|
|
66
|
+
issues.push({
|
|
67
|
+
level: "error",
|
|
68
|
+
message: "Application ID is required",
|
|
69
|
+
path: "application.id"
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else if (!isValidApplicationId(application.id)) {
|
|
73
|
+
issues.push({
|
|
74
|
+
level: "error",
|
|
75
|
+
message: `Application ID "${application.id}" is not a valid reverse-domain identifier`,
|
|
76
|
+
path: "application.id"
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (!application.name) {
|
|
80
|
+
issues.push({
|
|
81
|
+
level: "error",
|
|
82
|
+
message: "Application name is required",
|
|
83
|
+
path: "application.name"
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (!application.version) {
|
|
87
|
+
issues.push({
|
|
88
|
+
level: "error",
|
|
89
|
+
message: "Application version is required",
|
|
90
|
+
path: "application.version"
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
// Validate capabilities
|
|
94
|
+
if (Array.isArray(contract.capabilities)) {
|
|
95
|
+
const capabilityNames = new Set();
|
|
96
|
+
for (const cap of contract.capabilities) {
|
|
97
|
+
const capPath = `capabilities[${cap.name}@${cap.version}]`;
|
|
98
|
+
if (!cap.name) {
|
|
99
|
+
issues.push({ level: "error", message: "Capability name is required", path: capPath });
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const nameError = validateName(cap.name);
|
|
103
|
+
if (!nameError.valid) {
|
|
104
|
+
issues.push({ level: "error", message: nameError.reason || "Invalid name", path: capPath });
|
|
105
|
+
}
|
|
106
|
+
if (!Number.isInteger(cap.version) || cap.version < 1) {
|
|
107
|
+
issues.push({
|
|
108
|
+
level: "error",
|
|
109
|
+
message: "Capability version must be a positive integer",
|
|
110
|
+
path: `${capPath}.version`
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (!cap.input) {
|
|
114
|
+
issues.push({
|
|
115
|
+
level: "error",
|
|
116
|
+
message: "Capability input schema is required",
|
|
117
|
+
path: `${capPath}.input`
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
issues.push(...validateJSONSchema(cap.input).map(i => ({ ...i, path: `${capPath}.input` })));
|
|
122
|
+
}
|
|
123
|
+
if (!cap.output) {
|
|
124
|
+
issues.push({
|
|
125
|
+
level: "error",
|
|
126
|
+
message: "Capability output schema is required",
|
|
127
|
+
path: `${capPath}.output`
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
issues.push(...validateJSONSchema(cap.output).map(i => ({ ...i, path: `${capPath}.output` })));
|
|
132
|
+
}
|
|
133
|
+
// Check for duplicate capability versions
|
|
134
|
+
const capKey = `${cap.name}@${cap.version}`;
|
|
135
|
+
if (capabilityNames.has(capKey)) {
|
|
136
|
+
issues.push({
|
|
137
|
+
level: "error",
|
|
138
|
+
message: `Duplicate capability: ${capKey}`,
|
|
139
|
+
path: capPath
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
capabilityNames.add(capKey);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Validate events
|
|
146
|
+
if (Array.isArray(contract.events)) {
|
|
147
|
+
const eventNames = new Set();
|
|
148
|
+
for (const event of contract.events) {
|
|
149
|
+
const eventPath = `events[${event.name}@${event.version}]`;
|
|
150
|
+
if (!event.name) {
|
|
151
|
+
issues.push({ level: "error", message: "Event name is required", path: eventPath });
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const nameError = validateName(event.name);
|
|
155
|
+
if (!nameError.valid) {
|
|
156
|
+
issues.push({ level: "error", message: nameError.reason || "Invalid name", path: eventPath });
|
|
157
|
+
}
|
|
158
|
+
if (!Number.isInteger(event.version) || event.version < 1) {
|
|
159
|
+
issues.push({
|
|
160
|
+
level: "error",
|
|
161
|
+
message: "Event version must be a positive integer",
|
|
162
|
+
path: `${eventPath}.version`
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
if (!event.payload) {
|
|
166
|
+
issues.push({
|
|
167
|
+
level: "error",
|
|
168
|
+
message: "Event payload schema is required",
|
|
169
|
+
path: `${eventPath}.payload`
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
issues.push(...validateJSONSchema(event.payload).map(i => ({ ...i, path: `${eventPath}.payload` })));
|
|
174
|
+
}
|
|
175
|
+
// Check for duplicate event versions
|
|
176
|
+
const eventKey = `${event.name}@${event.version}`;
|
|
177
|
+
if (eventNames.has(eventKey)) {
|
|
178
|
+
issues.push({
|
|
179
|
+
level: "error",
|
|
180
|
+
message: `Duplicate event: ${eventKey}`,
|
|
181
|
+
path: eventPath
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
eventNames.add(eventKey);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Validate requirements
|
|
188
|
+
if (Array.isArray(contract.requires)) {
|
|
189
|
+
const requirementNames = new Set();
|
|
190
|
+
for (const req of contract.requires) {
|
|
191
|
+
const reqPath = `requires[${req.name}]`;
|
|
192
|
+
if (!req.name) {
|
|
193
|
+
issues.push({ level: "error", message: "Requirement name is required", path: reqPath });
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const nameError = validateName(req.name);
|
|
197
|
+
if (!nameError.valid) {
|
|
198
|
+
issues.push({ level: "error", message: nameError.reason || "Invalid name", path: reqPath });
|
|
199
|
+
}
|
|
200
|
+
if (!req.versionConstraint) {
|
|
201
|
+
issues.push({
|
|
202
|
+
level: "error",
|
|
203
|
+
message: "Requirement version constraint is required",
|
|
204
|
+
path: `${reqPath}.versionConstraint`
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
else if (!validateVersionConstraint(req.versionConstraint)) {
|
|
208
|
+
issues.push({
|
|
209
|
+
level: "error",
|
|
210
|
+
message: `Invalid version constraint: "${req.versionConstraint}"`,
|
|
211
|
+
path: `${reqPath}.versionConstraint`
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
// Validate optional provider constraint
|
|
215
|
+
if (req.provider?.applicationId && !isValidApplicationId(req.provider.applicationId)) {
|
|
216
|
+
issues.push({
|
|
217
|
+
level: "error",
|
|
218
|
+
message: `Invalid provider application ID: "${req.provider.applicationId}"`,
|
|
219
|
+
path: `${reqPath}.provider.applicationId`
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
// Check for duplicate requirement names
|
|
223
|
+
if (requirementNames.has(req.name)) {
|
|
224
|
+
issues.push({
|
|
225
|
+
level: "error",
|
|
226
|
+
message: `Duplicate requirement: ${req.name}`,
|
|
227
|
+
path: reqPath
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
requirementNames.add(req.name);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
valid: issues.filter(i => i.level === "error").length === 0,
|
|
235
|
+
issues
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,YAAY,EAGb,MAAM,mBAAmB,CAAC;AAc3B;;;GAGG;AACH,SAAS,yBAAyB,CAAC,UAAkB;IACnD,IAAI,CAAC,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,wEAAwE;IACxE,MAAM,YAAY,GAAG,+EAA+E,CAAC;IACrG,OAAO,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAe;IACzC,MAAM,MAAM,GAAsB,EAAE,CAAC;IAErC,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,0BAA0B,EAAE,CAAC,CAAC;QACrE,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,GAAG,MAAiC,CAAC;IAE5C,uCAAuC;IACvC,MAAM,aAAa,GAAG;QACpB,MAAM;QACN,YAAY;QACZ,OAAO;QACP,UAAU;QACV,sBAAsB;QACtB,WAAW;QACX,WAAW;QACX,SAAS;QACT,SAAS;QACT,SAAS;QACT,QAAQ;QACR,MAAM;QACN,aAAa;QACb,SAAS;QACT,MAAM;QACN,OAAO;QACP,OAAO;QACP,OAAO;QACP,KAAK;KACN,CAAC;IAEF,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACjC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI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;YACL,CAAC;YACD,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;IACF,CAAC;IAED,OAAO;QACN,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC;QAC3D,MAAM;KACN,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@appport/contract-builder",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Contract builder for creating AppPort application contracts.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": { "type": "git", "url": "git+https://github.com/rkendel1/appport.git", "directory": "packages/contract-builder" },
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -b",
|
|
22
|
+
"clean": "tsc -b --clean"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@appport/protocol": "1.0.0",
|
|
26
|
+
"@appport/schema": "1.0.0"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": { "access": "public" }
|
|
29
|
+
}
|