@superjackfruitlabs/treaty-contracts 0.0.15 → 0.0.16
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/data/contracts/compat-exceptions.json +1 -20
- package/data/contracts/registry.json +4 -0
- package/data/fixtures/http/superpipeline/agent-work.v1.cases.json +236 -1
- package/data/fixtures/superpipeline-run-checkpoint/canonical.json +98 -0
- package/data/fixtures/superpipeline-run-checkpoint/selection.json +1633 -0
- package/data/manifest.json +10 -6
- package/data/schemas/http/superpipeline/agent-work.v1.openapi.json +36 -0
- package/data/schemas/superpipeline-api/card-repositories.v1.json +31 -0
- package/data/schemas/superpipeline-api/run-checkpoint-policy.v2.json +114 -0
- package/data/schemas/superpipeline-api/run-checkpoint-selection.v1.json +49 -0
- package/dist/cases.js +5 -1
- package/dist/http.d.ts +27 -6
- package/dist/http.js +113 -0
- package/dist/openapi-doc.d.ts +2 -0
- package/dist/openapi-doc.js +16 -5
- package/dist/schemas.js +33 -0
- package/package.json +1 -1
package/data/manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"treaty": "0.0.
|
|
2
|
+
"treaty": "0.0.16",
|
|
3
3
|
"files": {
|
|
4
4
|
"schemas/agentpod-local/registered-worker-capsule.v1.json": "396c150ba570ce2666439b904045e23ce4cc0e8ae3eab2af21538e6c3e04cf83",
|
|
5
5
|
"schemas/agentpod-local/registered-worker-result.v2.json": "113ef212593ce40a6054aca842ee142a8a1532f4267612c338151290f8d7d479",
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"schemas/common/error.v1.json": "bf394682949b3b9d64f60d6d1aac34b5a8151e2873bf71bf0b1fff570d1a9e42",
|
|
8
8
|
"schemas/common/flat-error.v1.json": "e2b29fa64f3f479db00d71979707005781acefb423200f7d7daa38d987b02720",
|
|
9
9
|
"schemas/http/accounts/plane.v1.openapi.json": "ac3ccb463405b70189e9c17a126274e0fbcbfe2c231a9858b8f24769dbc20c13",
|
|
10
|
-
"schemas/http/superpipeline/agent-work.v1.openapi.json": "
|
|
10
|
+
"schemas/http/superpipeline/agent-work.v1.openapi.json": "1736381bf84bef062fa3628d30b0acbb4aec7da72b6677e76cbf9617fc6db204",
|
|
11
11
|
"schemas/http/superpipeline/approvals.v1.openapi.json": "c3377531be7ea7e1b51086357cd01fa2cadeba4f7ba87b3d8e2645a0652b57f1",
|
|
12
12
|
"schemas/http/superpipeline/decisions.v1.openapi.json": "3c5c4111459e39d1d52bd5bcab63b239f015ecc8fce3815fa74965d401c9f0bf",
|
|
13
13
|
"schemas/matrix/dev.agentpod.check.failed.v2.json": "85980dda5fdd78bc6e4eb4f99d7a47b5af22165a07f27b5cfd72b5f06dfc001d",
|
|
@@ -57,9 +57,12 @@
|
|
|
57
57
|
"schemas/superbench/registration-observe-operation.v2.json": "d3dcb941b175d981ac7ea37462df688b4f9b5ec3f276f909113485984ba1fd94",
|
|
58
58
|
"schemas/superbench/registration-observe-response.v2.json": "ebfc640749c96b6304378f51b51e4cf5b3690de1993d3e06f3acfd6062ce4bb4",
|
|
59
59
|
"schemas/superbench/response.v2.json": "64e72583a3e75da94534e28985d01ab9ac12b5bfbc25c37487f975e93a8a0053",
|
|
60
|
+
"schemas/superpipeline-api/card-repositories.v1.json": "7e76392601993df40b9cf2de53a2ee6b5d0800db9f27b30012738257836dc7bd",
|
|
60
61
|
"schemas/superpipeline-api/checkpoint-settlement.v1.json": "e3d509c26c089f2c0a7a5960a743f0e399ec10a63903d162daf5fc7b2f6853f9",
|
|
61
62
|
"schemas/superpipeline-api/run-checkpoint-policy.v1.json": "bfe207f1a331355ab74e62aeb64e34600ce5ab2aa976d1f3390210acf72fd921",
|
|
63
|
+
"schemas/superpipeline-api/run-checkpoint-policy.v2.json": "7d9d1a9dafc2f1023f4759f9f2dbc4e15fa13d48350f0853c2cdaf8f6183cbb9",
|
|
62
64
|
"schemas/superpipeline-api/run-checkpoint-receipt.v1.json": "65301974904f301341d6de0d990c120d2074cb4cf5052c1f7f767033a1cc002c",
|
|
65
|
+
"schemas/superpipeline-api/run-checkpoint-selection.v1.json": "e8a9f924bdcf1af1b4d6a87a2863552fd2948fd551170059f343a1366b3c3bb3",
|
|
63
66
|
"schemas/superpipeline-api/run-checkpoint.v1.json": "66682c9b1fe84a0b1a4a124ee6daaf32caa1f8a900c98e73e5c0c9e6beeaf1e3",
|
|
64
67
|
"schemas/superpipeline/attention.pending.v1.json": "9af09e2358fe33210d793c315387e012e709c858569dac37c109a2388efcea55",
|
|
65
68
|
"schemas/superpipeline/card.ready.v1.json": "5e72e151ffd3a6ca3b90d9864250aaf1fa0d9b171b2718d6847efd17d0b5237c",
|
|
@@ -88,7 +91,7 @@
|
|
|
88
91
|
"fixtures/ecosystem-identity/token_claims.json": "106b78f3452250aea869fa5abea1cfd06318a309c0f6887abf39eb3fd909dcec",
|
|
89
92
|
"fixtures/ecosystem-identity/token_vectors.json": "48f1c3fd8c2385e4e84a2d77a695f2c7c727aa43167f1e651d74d0d9f24811c6",
|
|
90
93
|
"fixtures/http/accounts/plane.v1.cases.json": "532d47331fed253ff92f819b553e24561e876f14babe5df1ea29b0d26c8f962d",
|
|
91
|
-
"fixtures/http/superpipeline/agent-work.v1.cases.json": "
|
|
94
|
+
"fixtures/http/superpipeline/agent-work.v1.cases.json": "48462c8ab72dacaf0d6d4a52d8369ba206275240d9fe6b723013b8f267bfe9dc",
|
|
92
95
|
"fixtures/http/superpipeline/approvals.v1.cases.json": "dc493038b0f35a07622833152df3f00880087eb93ce4aa2b2fa8324b16498e8d",
|
|
93
96
|
"fixtures/http/superpipeline/decisions.v1.cases.json": "51cbfdac3cfd4e29b1b54aa4722f37e64f62f95b26e9e71136f7039e1d4f6c6b",
|
|
94
97
|
"fixtures/matrix-events/examples.json": "9d361f1aaf408273f0ce939c57fa81cf4f0fa5b144446136d790c8d46805d297",
|
|
@@ -111,11 +114,12 @@
|
|
|
111
114
|
"fixtures/superbench-consumers/cases.json": "47e70557154fd86129f20a93923bb450cee5f4e634e0bf3b45514417d90e749d",
|
|
112
115
|
"fixtures/superbench-consumers/producer-scenarios.json": "3639938bad9a0c81a4fffe956b4840ca10b7213838aca1cc3ee2370517a2a217",
|
|
113
116
|
"fixtures/superpipeline-events/examples.json": "0b1ba9dcc65e42e638589a61340aad3022adb229e897983cc8ebb31953365916",
|
|
114
|
-
"fixtures/superpipeline-run-checkpoint/canonical.json": "
|
|
117
|
+
"fixtures/superpipeline-run-checkpoint/canonical.json": "7e62ceb2c8b4442cc2e7b8159f54ed61ec52178336b791ac52b1289ed22d4098",
|
|
115
118
|
"fixtures/superpipeline-run-checkpoint/cases.json": "142a253b37405eebf912579fee1ad5329b8be7bb375a6a5e3930864690780519",
|
|
116
119
|
"fixtures/superpipeline-run-checkpoint/producer-scenarios.json": "c29a7073b74e64da23939652ea11e8c658f355b73e6b4e5936ba31a7690e8d36",
|
|
117
|
-
"
|
|
120
|
+
"fixtures/superpipeline-run-checkpoint/selection.json": "2e49baa9389304fa750164cfe18e38ecfa69ad5cdd440eaf468130484274158f",
|
|
121
|
+
"contracts/compat-exceptions.json": "791d8eaae15404a3f710ff40f35816789392e19e21abfaf544886a45c6999a49",
|
|
118
122
|
"contracts/error-codes.json": "142b310b3cc51a427f6bc3884db0080dbdba6ad964184ef6c1ab78dcc216b7d7",
|
|
119
|
-
"contracts/registry.json": "
|
|
123
|
+
"contracts/registry.json": "a05744db23d559a34fd1a7292095abd14103085ce25c7ee1f064431dec4bc6c5"
|
|
120
124
|
}
|
|
121
125
|
}
|
|
@@ -2299,6 +2299,14 @@
|
|
|
2299
2299
|
}
|
|
2300
2300
|
}
|
|
2301
2301
|
}
|
|
2302
|
+
},
|
|
2303
|
+
"repositories": {
|
|
2304
|
+
"$ref": "../../superpipeline-api/card-repositories.v1.json#/properties/repositories",
|
|
2305
|
+
"description": "Proposed. The repositories this card chose from a stage allowlist (run-checkpoint-policy.v2), sorted. Absent: the card names none. Fixed once the card's bench exists."
|
|
2306
|
+
},
|
|
2307
|
+
"primaryRepository": {
|
|
2308
|
+
"$ref": "../../superpipeline-api/card-repositories.v1.json#/properties/primaryRepository",
|
|
2309
|
+
"description": "Proposed. One of `repositories`: where the card's work starts. Only with `repositories`."
|
|
2302
2310
|
}
|
|
2303
2311
|
}
|
|
2304
2312
|
},
|
|
@@ -2361,6 +2369,10 @@
|
|
|
2361
2369
|
"checkpointPolicy": {
|
|
2362
2370
|
"$ref": "../../superpipeline-api/run-checkpoint-policy.v1.json"
|
|
2363
2371
|
},
|
|
2372
|
+
"cardCheckpointPolicy": {
|
|
2373
|
+
"$ref": "../../superpipeline-api/run-checkpoint-policy.v2.json",
|
|
2374
|
+
"description": "Proposed. The checkpoint policy of a stage whose cards choose their repositories from its allowlist. Never together with `checkpointPolicy`. Offered only to a claimant whose `checkpointProtocols` lists superpipeline.checkpoint-claim.v2."
|
|
2375
|
+
},
|
|
2364
2376
|
"key": {
|
|
2365
2377
|
"type": "string"
|
|
2366
2378
|
},
|
|
@@ -2556,6 +2568,10 @@
|
|
|
2556
2568
|
},
|
|
2557
2569
|
"admissionState": {
|
|
2558
2570
|
"const": "pending"
|
|
2571
|
+
},
|
|
2572
|
+
"selection": {
|
|
2573
|
+
"$ref": "../../superpipeline-api/run-checkpoint-selection.v1.json",
|
|
2574
|
+
"description": "Proposed, claim protocol v2. Present only when the stage has `cardCheckpointPolicy`: how its allowlist was narrowed for this card. `policy` is then the narrowed checkpoint-policy.v1 and `policyDigest` its digest; the reader recomputes both from the stage policy and refuses any difference."
|
|
2559
2575
|
}
|
|
2560
2576
|
}
|
|
2561
2577
|
},
|
|
@@ -3297,6 +3313,22 @@
|
|
|
3297
3313
|
"checkpointProtocol": {
|
|
3298
3314
|
"const": "superpipeline.checkpoint-claim.v1"
|
|
3299
3315
|
},
|
|
3316
|
+
"checkpointProtocols": {
|
|
3317
|
+
"type": "array",
|
|
3318
|
+
"minItems": 1,
|
|
3319
|
+
"maxItems": 8,
|
|
3320
|
+
"uniqueItems": true,
|
|
3321
|
+
"items": {
|
|
3322
|
+
"enum": [
|
|
3323
|
+
"superpipeline.checkpoint-claim.v1",
|
|
3324
|
+
"superpipeline.checkpoint-claim.v2"
|
|
3325
|
+
]
|
|
3326
|
+
},
|
|
3327
|
+
"contains": {
|
|
3328
|
+
"const": "superpipeline.checkpoint-claim.v1"
|
|
3329
|
+
},
|
|
3330
|
+
"description": "Proposed. Every checkpoint claim protocol this claimant speaks, sent beside `checkpointProtocol` (which a server that predates this field still reads; without it this field is INVALID_INPUT). A stage with `cardCheckpointPolicy` is offered only when this lists superpipeline.checkpoint-claim.v2."
|
|
3331
|
+
},
|
|
3300
3332
|
"checkpointOnly": {
|
|
3301
3333
|
"type": "boolean"
|
|
3302
3334
|
}
|
|
@@ -3707,6 +3739,10 @@
|
|
|
3707
3739
|
"type": "string",
|
|
3708
3740
|
"pattern": "^[a-f0-9]{64}$"
|
|
3709
3741
|
},
|
|
3742
|
+
"selection": {
|
|
3743
|
+
"$ref": "../../superpipeline-api/run-checkpoint-selection.v1.json",
|
|
3744
|
+
"description": "Proposed. The selection frozen with the claim, when the stage's cards choose; `policy` is then the narrowed policy."
|
|
3745
|
+
},
|
|
3710
3746
|
"binding": {
|
|
3711
3747
|
"$ref": "../../superpipeline-api/run-checkpoint.v1.json#/properties/binding"
|
|
3712
3748
|
},
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"additionalProperties": false,
|
|
4
|
+
"required": ["repositories"],
|
|
5
|
+
"properties": {
|
|
6
|
+
"repositories": {
|
|
7
|
+
"type": "array",
|
|
8
|
+
"minItems": 1,
|
|
9
|
+
"maxItems": 32,
|
|
10
|
+
"uniqueItems": true,
|
|
11
|
+
"description": "Repository names from the stage allowlist, sorted, unique.",
|
|
12
|
+
"items": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"minLength": 1,
|
|
15
|
+
"maxLength": 64,
|
|
16
|
+
"pattern": "^[a-z0-9][a-z0-9_-]{0,63}(?![\\s\\S])"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"primaryRepository": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"minLength": 1,
|
|
22
|
+
"maxLength": 64,
|
|
23
|
+
"pattern": "^[a-z0-9][a-z0-9_-]{0,63}(?![\\s\\S])",
|
|
24
|
+
"description": "Optional. One of `repositories`: where the card's work starts."
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
28
|
+
"$id": "https://raw.githubusercontent.com/SuperJackfruitLabs/treaty/main/schemas/superpipeline-api/card-repositories.v1.json",
|
|
29
|
+
"title": "PROPOSED repositories a card chooses for its bench",
|
|
30
|
+
"description": "A card's narrowing of a stage allowlist (run-checkpoint-policy.v2). It names repositories by their policy name only: never a provider, a URL or a clone identity. Absent means the card names none. Fixed once the card's bench exists."
|
|
31
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"additionalProperties": false,
|
|
4
|
+
"required": [
|
|
5
|
+
"version",
|
|
6
|
+
"kind",
|
|
7
|
+
"repositorySelection",
|
|
8
|
+
"allowUnchanged",
|
|
9
|
+
"repositories",
|
|
10
|
+
"checkpointRepository",
|
|
11
|
+
"reporterPrincipalId",
|
|
12
|
+
"nodeId",
|
|
13
|
+
"executors"
|
|
14
|
+
],
|
|
15
|
+
"properties": {
|
|
16
|
+
"version": {
|
|
17
|
+
"const": "superpipeline.checkpoint-policy.v2"
|
|
18
|
+
},
|
|
19
|
+
"kind": {
|
|
20
|
+
"const": "superbench"
|
|
21
|
+
},
|
|
22
|
+
"repositorySelection": {
|
|
23
|
+
"const": "card",
|
|
24
|
+
"description": "Cards choose a subset of `repositories`. A stage whose repositories are fixed keeps checkpoint-policy.v1."
|
|
25
|
+
},
|
|
26
|
+
"allowUnchanged": {
|
|
27
|
+
"type": "boolean"
|
|
28
|
+
},
|
|
29
|
+
"repositories": {
|
|
30
|
+
"type": "array",
|
|
31
|
+
"minItems": 1,
|
|
32
|
+
"maxItems": 32,
|
|
33
|
+
"items": {
|
|
34
|
+
"type": "object",
|
|
35
|
+
"additionalProperties": false,
|
|
36
|
+
"required": ["name", "provider", "repository"],
|
|
37
|
+
"properties": {
|
|
38
|
+
"name": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"minLength": 1,
|
|
41
|
+
"maxLength": 64,
|
|
42
|
+
"pattern": "^[a-z0-9][a-z0-9_-]{0,63}(?![\\s\\S])"
|
|
43
|
+
},
|
|
44
|
+
"provider": {
|
|
45
|
+
"enum": ["forge", "github"]
|
|
46
|
+
},
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"minLength": 1,
|
|
50
|
+
"maxLength": 200,
|
|
51
|
+
"pattern": "^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+(?![\\s\\S])"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"description": "The allowlist: every repository a card on this stage may choose. Sorted by name, names unique."
|
|
56
|
+
},
|
|
57
|
+
"checkpointRepository": {
|
|
58
|
+
"type": "string",
|
|
59
|
+
"minLength": 1,
|
|
60
|
+
"maxLength": 64,
|
|
61
|
+
"pattern": "^[a-z0-9][a-z0-9_-]{0,63}(?![\\s\\S])",
|
|
62
|
+
"description": "One of `repositories`. The repository a card's work starts in when the card names no primary and chose this one."
|
|
63
|
+
},
|
|
64
|
+
"reporterPrincipalId": {
|
|
65
|
+
"type": "string",
|
|
66
|
+
"pattern": "^prn_[A-Za-z0-9]{6,}(?![\\s\\S])",
|
|
67
|
+
"maxLength": 80
|
|
68
|
+
},
|
|
69
|
+
"nodeId": {
|
|
70
|
+
"type": "string",
|
|
71
|
+
"minLength": 1,
|
|
72
|
+
"maxLength": 128
|
|
73
|
+
},
|
|
74
|
+
"executors": {
|
|
75
|
+
"type": "array",
|
|
76
|
+
"minItems": 1,
|
|
77
|
+
"maxItems": 32,
|
|
78
|
+
"items": {
|
|
79
|
+
"type": "object",
|
|
80
|
+
"additionalProperties": false,
|
|
81
|
+
"required": ["agentId", "stationId"],
|
|
82
|
+
"properties": {
|
|
83
|
+
"agentId": {
|
|
84
|
+
"type": "string",
|
|
85
|
+
"pattern": "^agt_[A-Za-z0-9]{6,}(?![\\s\\S])",
|
|
86
|
+
"maxLength": 80
|
|
87
|
+
},
|
|
88
|
+
"stationId": {
|
|
89
|
+
"type": "string",
|
|
90
|
+
"minLength": 1,
|
|
91
|
+
"maxLength": 128
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"defaultRepositories": {
|
|
97
|
+
"type": "array",
|
|
98
|
+
"minItems": 1,
|
|
99
|
+
"maxItems": 32,
|
|
100
|
+
"uniqueItems": true,
|
|
101
|
+
"description": "Optional. What a card that names no repository gets. Sorted, unique, a subset of `repositories`; holds `checkpointRepository` unless it has exactly one member.",
|
|
102
|
+
"items": {
|
|
103
|
+
"type": "string",
|
|
104
|
+
"minLength": 1,
|
|
105
|
+
"maxLength": 64,
|
|
106
|
+
"pattern": "^[a-z0-9][a-z0-9_-]{0,63}(?![\\s\\S])"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
111
|
+
"$id": "https://raw.githubusercontent.com/SuperJackfruitLabs/treaty/main/schemas/superpipeline-api/run-checkpoint-policy.v2.json",
|
|
112
|
+
"title": "PROPOSED checkpoint policy for a stage whose cards choose their repositories",
|
|
113
|
+
"description": "A stage policy whose `repositories` is an allowlist a card narrows. Structural validity grants no authority. Relations JSON Schema cannot state (sorted unique names, checkpointRepository and defaultRepositories inside the allowlist, a default that resolves a start repository) are in fixtures/superpipeline-run-checkpoint/selection.json."
|
|
114
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"additionalProperties": false,
|
|
4
|
+
"required": [
|
|
5
|
+
"version",
|
|
6
|
+
"stagePolicyDigest",
|
|
7
|
+
"source",
|
|
8
|
+
"repositories",
|
|
9
|
+
"checkpointRepository"
|
|
10
|
+
],
|
|
11
|
+
"properties": {
|
|
12
|
+
"version": {
|
|
13
|
+
"const": "superpipeline.checkpoint-selection.v1"
|
|
14
|
+
},
|
|
15
|
+
"stagePolicyDigest": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"pattern": "^[a-f0-9]{64}(?![\\s\\S])",
|
|
18
|
+
"description": "Canonical SHA256 of the stage's run-checkpoint-policy.v2 at claim."
|
|
19
|
+
},
|
|
20
|
+
"source": {
|
|
21
|
+
"enum": ["card", "default", "single"],
|
|
22
|
+
"description": "`card`: the card named them. `default`: the stage's defaultRepositories. `single`: the allowlist has one repository."
|
|
23
|
+
},
|
|
24
|
+
"repositories": {
|
|
25
|
+
"type": "array",
|
|
26
|
+
"minItems": 1,
|
|
27
|
+
"maxItems": 32,
|
|
28
|
+
"uniqueItems": true,
|
|
29
|
+
"description": "The chosen names, sorted, unique; exactly the narrowed policy's repository names.",
|
|
30
|
+
"items": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"minLength": 1,
|
|
33
|
+
"maxLength": 64,
|
|
34
|
+
"pattern": "^[a-z0-9][a-z0-9_-]{0,63}(?![\\s\\S])"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"checkpointRepository": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"minLength": 1,
|
|
40
|
+
"maxLength": 64,
|
|
41
|
+
"pattern": "^[a-z0-9][a-z0-9_-]{0,63}(?![\\s\\S])",
|
|
42
|
+
"description": "One of `repositories`; equal to the narrowed policy's checkpointRepository."
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
46
|
+
"$id": "https://raw.githubusercontent.com/SuperJackfruitLabs/treaty/main/schemas/superpipeline-api/run-checkpoint-selection.v1.json",
|
|
47
|
+
"title": "PROPOSED frozen repository selection of a checkpoint claim",
|
|
48
|
+
"description": "Recorded with the claim beside the narrowed checkpoint-policy.v1 the claim carries. A consumer recomputes the narrowing from the stage policy and refuses any difference."
|
|
49
|
+
}
|
package/dist/cases.js
CHANGED
|
@@ -8,7 +8,11 @@ export function resolvePointer(doc, pointer) {
|
|
|
8
8
|
.slice(1)
|
|
9
9
|
.split("/")
|
|
10
10
|
.map((t) => decodeURIComponent(t).replaceAll("~1", "/").replaceAll("~0", "~"))
|
|
11
|
-
.reduce((node, t) => (
|
|
11
|
+
.reduce((node, t) => Array.isArray(node)
|
|
12
|
+
? node[Number(t)]
|
|
13
|
+
: isObject(node)
|
|
14
|
+
? node[t]
|
|
15
|
+
: undefined, doc);
|
|
12
16
|
}
|
|
13
17
|
export function isCases(value) {
|
|
14
18
|
if (!isObject(value) ||
|
package/dist/http.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP contracts: OpenAPI 3.1 documents under schemas/http/, read as data.
|
|
3
|
-
*
|
|
4
|
-
* Only `application/json` bodies are contracted. A response with no content accepts only an
|
|
5
|
-
* empty body.
|
|
6
|
-
*/
|
|
7
1
|
import { type Method } from "./openapi-doc.ts";
|
|
8
2
|
import { type Bundle, type Result } from "./schemas.ts";
|
|
9
3
|
export interface Operation {
|
|
@@ -18,6 +12,15 @@ export interface Operation {
|
|
|
18
12
|
/** Status (or `default`, `4XX`) → pointer to the body's schema, or null for no body. */
|
|
19
13
|
responses: Record<string, string | null>;
|
|
20
14
|
errorCodes: string[];
|
|
15
|
+
/** Path, query and header parameters, path-level ones merged in; the operation's own win. */
|
|
16
|
+
parameters?: Parameter[];
|
|
17
|
+
}
|
|
18
|
+
export interface Parameter {
|
|
19
|
+
in: "path" | "query" | "header" | "cookie";
|
|
20
|
+
name: string;
|
|
21
|
+
required: boolean;
|
|
22
|
+
/** JSON pointer, within the document, to the parameter's schema. */
|
|
23
|
+
schema?: string;
|
|
21
24
|
}
|
|
22
25
|
export interface Api {
|
|
23
26
|
/** Repository path of the document. */
|
|
@@ -36,3 +39,21 @@ export declare function openApi(bundle: Bundle, path: string): Api;
|
|
|
36
39
|
export declare function matchRoute(api: Api, method: string, path: string): string | undefined;
|
|
37
40
|
export declare function validateRequest(bundle: Bundle, api: Api, operationId: string, body: unknown): Result;
|
|
38
41
|
export declare function validateResponse(bundle: Bundle, api: Api, operationId: string, status: number, body: unknown): Result;
|
|
42
|
+
export interface ParameterValues {
|
|
43
|
+
path?: Record<string, string>;
|
|
44
|
+
/** A repeated query key arrives as an array. */
|
|
45
|
+
query?: Record<string, string | string[]>;
|
|
46
|
+
/** Header names compare case-insensitively. */
|
|
47
|
+
header?: Record<string, string>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Checks a request's path, query and header values against an operation's parameters. Values
|
|
51
|
+
* arrive as text and are converted to their schema's type first; a parameter the contract does
|
|
52
|
+
* not name is ignored, as readers ignore what they do not know.
|
|
53
|
+
*/
|
|
54
|
+
export declare function validateParameters(bundle: Bundle, api: Api, operationId: string, values: ParameterValues): Result;
|
|
55
|
+
/** The operation a request reaches and its path parameter values, decoded; or undefined. */
|
|
56
|
+
export declare function routeParams(api: Api, method: string, path: string): {
|
|
57
|
+
operationId: string;
|
|
58
|
+
path: Record<string, string>;
|
|
59
|
+
} | undefined;
|
package/dist/http.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Only `application/json` bodies are contracted. A response with no content accepts only an
|
|
5
5
|
* empty body.
|
|
6
6
|
*/
|
|
7
|
+
import { resolvePointer } from "./cases.js";
|
|
7
8
|
import { bodySchemaPointer, documentOperations, isObject, } from "./openapi-doc.js";
|
|
8
9
|
import { validatorFor } from "./schemas.js";
|
|
9
10
|
function stringArray(value) {
|
|
@@ -20,12 +21,30 @@ export function operations(doc) {
|
|
|
20
21
|
for (const [status, response] of Object.entries(op.node.responses))
|
|
21
22
|
responses[status] =
|
|
22
23
|
bodySchemaPointer(doc, response, `${op.pointer}/responses/${status}`) ?? null;
|
|
24
|
+
const parameters = [];
|
|
25
|
+
for (const [key, param] of op.parameters) {
|
|
26
|
+
const where = param.in;
|
|
27
|
+
if (where !== "path" &&
|
|
28
|
+
where !== "query" &&
|
|
29
|
+
where !== "header" &&
|
|
30
|
+
where !== "cookie")
|
|
31
|
+
continue;
|
|
32
|
+
const at = op.parameterPointers.get(key);
|
|
33
|
+
parameters.push({
|
|
34
|
+
in: where,
|
|
35
|
+
name: String(param.name),
|
|
36
|
+
// A path parameter is always required (OpenAPI 3.1 §4.8.12.1).
|
|
37
|
+
required: where === "path" || param.required === true,
|
|
38
|
+
...(at && isObject(param.schema) ? { schema: `${at}/schema` } : {}),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
23
41
|
return {
|
|
24
42
|
id: op.key,
|
|
25
43
|
method: op.method,
|
|
26
44
|
path: op.path,
|
|
27
45
|
...(request ? { request } : {}),
|
|
28
46
|
requestRequired: op.requestBody?.node.required === true,
|
|
47
|
+
parameters,
|
|
29
48
|
responses,
|
|
30
49
|
errorCodes: stringArray(op.node["x-treaty-error-codes"]),
|
|
31
50
|
};
|
|
@@ -145,3 +164,97 @@ export function validateResponse(bundle, api, operationId, status, body) {
|
|
|
145
164
|
};
|
|
146
165
|
return check(bundle, api, pointer, body, `${operationId}'s ${key}`);
|
|
147
166
|
}
|
|
167
|
+
function schemaType(schema) {
|
|
168
|
+
if (!isObject(schema))
|
|
169
|
+
return [];
|
|
170
|
+
const t = schema.type;
|
|
171
|
+
return Array.isArray(t)
|
|
172
|
+
? t.filter((x) => typeof x === "string")
|
|
173
|
+
: typeof t === "string"
|
|
174
|
+
? [t]
|
|
175
|
+
: [];
|
|
176
|
+
}
|
|
177
|
+
/** A value from a URL is text; turn it into what its schema says, or leave it for the validator to refuse. */
|
|
178
|
+
function convert(raw, schema) {
|
|
179
|
+
const types = schemaType(schema);
|
|
180
|
+
if ((types.includes("integer") || types.includes("number")) &&
|
|
181
|
+
/^-?\d+(\.\d+)?$/.test(raw))
|
|
182
|
+
return Number(raw);
|
|
183
|
+
if (types.includes("boolean") && (raw === "true" || raw === "false"))
|
|
184
|
+
return raw === "true";
|
|
185
|
+
return raw;
|
|
186
|
+
}
|
|
187
|
+
function rawValue(values, param) {
|
|
188
|
+
if (param.in === "path")
|
|
189
|
+
return values.path?.[param.name];
|
|
190
|
+
if (param.in === "query")
|
|
191
|
+
return values.query?.[param.name];
|
|
192
|
+
if (param.in === "header") {
|
|
193
|
+
const want = param.name.toLowerCase();
|
|
194
|
+
const found = Object.entries(values.header ?? {}).find(([k]) => k.toLowerCase() === want);
|
|
195
|
+
return found?.[1];
|
|
196
|
+
}
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Checks a request's path, query and header values against an operation's parameters. Values
|
|
201
|
+
* arrive as text and are converted to their schema's type first; a parameter the contract does
|
|
202
|
+
* not name is ignored, as readers ignore what they do not know.
|
|
203
|
+
*/
|
|
204
|
+
export function validateParameters(bundle, api, operationId, values) {
|
|
205
|
+
const op = find(api, operationId);
|
|
206
|
+
const doc = bundle.files.get(api.path);
|
|
207
|
+
const errors = [];
|
|
208
|
+
for (const param of op.parameters ?? []) {
|
|
209
|
+
const raw = rawValue(values, param);
|
|
210
|
+
const label = `${param.in} parameter ${param.name}`;
|
|
211
|
+
if (raw === undefined) {
|
|
212
|
+
if (param.required)
|
|
213
|
+
errors.push(`${label} is required`);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (!param.schema)
|
|
217
|
+
continue;
|
|
218
|
+
const schema = resolvePointer(doc, param.schema);
|
|
219
|
+
const value = schemaType(schema).includes("array")
|
|
220
|
+
? (Array.isArray(raw) ? raw : [raw]).map((v) => convert(v, isObject(schema) ? schema.items : undefined))
|
|
221
|
+
: convert(Array.isArray(raw) ? (raw[0] ?? "") : raw, schema);
|
|
222
|
+
const result = validatorFor(bundle, `${api.path}#${param.schema}`)(value);
|
|
223
|
+
for (const e of result.errors)
|
|
224
|
+
errors.push(`${label}: ${e}`);
|
|
225
|
+
}
|
|
226
|
+
return { valid: errors.length === 0, errors };
|
|
227
|
+
}
|
|
228
|
+
/** The operation a request reaches and its path parameter values, decoded; or undefined. */
|
|
229
|
+
export function routeParams(api, method, path) {
|
|
230
|
+
const operationId = matchRoute(api, method, path);
|
|
231
|
+
if (!operationId)
|
|
232
|
+
return undefined;
|
|
233
|
+
const op = find(api, operationId);
|
|
234
|
+
const template = segments(op.path);
|
|
235
|
+
const actual = segments(path);
|
|
236
|
+
const values = {};
|
|
237
|
+
for (const [i, part] of template.entries()) {
|
|
238
|
+
if (!part.includes("{"))
|
|
239
|
+
continue;
|
|
240
|
+
const names = [];
|
|
241
|
+
const pattern = part
|
|
242
|
+
.split(/(\{[^}]+\})/)
|
|
243
|
+
.map((piece) => {
|
|
244
|
+
const m = /^\{([^}]+)\}$/.exec(piece);
|
|
245
|
+
if (m?.[1]) {
|
|
246
|
+
names.push(m[1]);
|
|
247
|
+
return "([^/]+)";
|
|
248
|
+
}
|
|
249
|
+
return escapeRegex(piece);
|
|
250
|
+
})
|
|
251
|
+
.join("");
|
|
252
|
+
const match = new RegExp(`^${pattern}$`).exec(actual[i] ?? "");
|
|
253
|
+
for (const [j, name] of names.entries()) {
|
|
254
|
+
const v = match?.[j + 1];
|
|
255
|
+
if (v !== undefined)
|
|
256
|
+
values[name] = v;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return { operationId, path: values };
|
|
260
|
+
}
|
package/dist/openapi-doc.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface DocOperation {
|
|
|
27
27
|
node: Node;
|
|
28
28
|
/** Path-level and operation-level parameters, resolved; the operation's win by `in` and `name`. */
|
|
29
29
|
parameters: Map<string, Node>;
|
|
30
|
+
/** Where each of those parameters sits in the document, by the same `in:name` key. */
|
|
31
|
+
parameterPointers: Map<string, string>;
|
|
30
32
|
/** The request body, resolved, or undefined. */
|
|
31
33
|
requestBody?: {
|
|
32
34
|
node: Node;
|
package/dist/openapi-doc.js
CHANGED
|
@@ -52,13 +52,19 @@ export function bodySchemaPointer(doc, holder, pointer) {
|
|
|
52
52
|
return undefined;
|
|
53
53
|
return `${resolved.pointer}/content/${token(JSON_MEDIA)}/schema`;
|
|
54
54
|
}
|
|
55
|
-
function resolvedParameters(doc, list, pointer, into) {
|
|
55
|
+
function resolvedParameters(doc, list, pointer, into, pointers) {
|
|
56
56
|
if (!Array.isArray(list))
|
|
57
57
|
return;
|
|
58
58
|
for (const [i, entry] of list.entries()) {
|
|
59
|
-
const
|
|
60
|
-
|
|
59
|
+
const resolved = deref(doc, entry, `${pointer}/${i}`);
|
|
60
|
+
const p = resolved?.node;
|
|
61
|
+
if (resolved &&
|
|
62
|
+
p &&
|
|
63
|
+
typeof p.name === "string" &&
|
|
64
|
+
typeof p.in === "string") {
|
|
61
65
|
into.set(`${p.in}:${p.name}`, p);
|
|
66
|
+
pointers.set(`${p.in}:${p.name}`, resolved.pointer);
|
|
67
|
+
}
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
70
|
export function documentOperations(doc) {
|
|
@@ -75,8 +81,12 @@ export function documentOperations(doc) {
|
|
|
75
81
|
continue;
|
|
76
82
|
const pointer = `${itemPointer}/${method}`;
|
|
77
83
|
const parameters = new Map();
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
const parameterPointers = new Map();
|
|
85
|
+
for (const [list, at] of [
|
|
86
|
+
[item.parameters, `${itemPointer}/parameters`],
|
|
87
|
+
[op.parameters, `${pointer}/parameters`],
|
|
88
|
+
])
|
|
89
|
+
resolvedParameters(doc, list, at, parameters, parameterPointers);
|
|
80
90
|
const requestBody = op.requestBody === undefined
|
|
81
91
|
? undefined
|
|
82
92
|
: deref(doc, op.requestBody, `${pointer}/requestBody`);
|
|
@@ -89,6 +99,7 @@ export function documentOperations(doc) {
|
|
|
89
99
|
pointer,
|
|
90
100
|
node: op,
|
|
91
101
|
parameters,
|
|
102
|
+
parameterPointers,
|
|
92
103
|
...(requestBody ? { requestBody } : {}),
|
|
93
104
|
});
|
|
94
105
|
}
|
package/dist/schemas.js
CHANGED
|
@@ -40,6 +40,37 @@ function register(bundle, validator) {
|
|
|
40
40
|
validator.addSchema(doc, id);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The validator indexes a document's subschemas by walking its objects, but not its arrays, so a
|
|
45
|
+
* pointer through an array (an OpenAPI parameter, `parameters/0/schema`) would not resolve.
|
|
46
|
+
* Registering the node the pointer reaches, under its full address, makes any pointer resolve;
|
|
47
|
+
* its own relative `$ref`s still resolve against the document.
|
|
48
|
+
*/
|
|
49
|
+
function registerAt(bundle, validator, where, base, pointer) {
|
|
50
|
+
const path = where.startsWith(SCHEMA_BASE)
|
|
51
|
+
? where.slice(SCHEMA_BASE.length)
|
|
52
|
+
: where;
|
|
53
|
+
let node = bundle.files.get(path);
|
|
54
|
+
let throughArray = false;
|
|
55
|
+
for (const raw of pointer.slice(1).split("/")) {
|
|
56
|
+
const t = raw.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
57
|
+
if (Array.isArray(node)) {
|
|
58
|
+
throughArray = true;
|
|
59
|
+
node = node[Number(t)];
|
|
60
|
+
}
|
|
61
|
+
else
|
|
62
|
+
node = isObject(node) ? node[t] : undefined;
|
|
63
|
+
}
|
|
64
|
+
// Only a pointer through an array needs this; the walk already indexes every other subschema.
|
|
65
|
+
if (!throughArray || !isObject(node))
|
|
66
|
+
return;
|
|
67
|
+
try {
|
|
68
|
+
validator.addSchema(node, `${base}#${fragment(pointer)}`);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// Already indexed by the walk: nothing to add.
|
|
72
|
+
}
|
|
73
|
+
}
|
|
43
74
|
/** Schemas whose `$id` is not the address of their own path: each is a copy or a move gone wrong. */
|
|
44
75
|
export function misplacedIds(bundle) {
|
|
45
76
|
const wrong = [];
|
|
@@ -73,6 +104,8 @@ export function validatorFor(bundle, ref) {
|
|
|
73
104
|
};
|
|
74
105
|
const validator = new Validator(target, "2020-12", false);
|
|
75
106
|
register(bundle, validator);
|
|
107
|
+
if (pointer !== undefined)
|
|
108
|
+
registerAt(bundle, validator, where, base, pointer);
|
|
76
109
|
const check = (value) => {
|
|
77
110
|
try {
|
|
78
111
|
const result = validator.validate(value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superjackfruitlabs/treaty-contracts",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "Every contract between Super Jackfruit Labs products as data, with validators and a CLI that checks a repository against them.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|