@gate-forge/http-contract 0.1.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 UKD
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # @gate-forge/http-contract
2
+
3
+ Framework-neutral canonical HTTP contract for Gateforge (ADR 0004): the
4
+ strict `HttpContractFact` schema, typed outcome codes, canonical
5
+ path/method normalization, and the deterministic frontend-call ↔
6
+ server-route join engine.
7
+
8
+ This package owns **no framework parsing** (detector packs own that) and
9
+ **no classification** (`@gate-forge/core` owns that). Every export is a pure
10
+ function; identical inputs produce byte-identical outputs under any input
11
+ permutation.
12
+
13
+ ## Contract facts
14
+
15
+ A fact is one discovered HTTP surface, serialized by detector packs as
16
+ GPP/3 resources of kind `http.contract` (evidence-only; never classified
17
+ directly, never a business resource):
18
+
19
+ ```ts
20
+ interface HttpContractFact {
21
+ schemaVersion: 1;
22
+ role: 'server-route' | 'frontend-call';
23
+ method: 'GET'|'HEAD'|'POST'|'PUT'|'PATCH'|'DELETE'|'OPTIONS'|'ANY';
24
+ normalizedPath: string; // canonical positional form
25
+ rawPath: string; // exactly as written in source
26
+ framework: string; // 'fastapi' | 'fetch' | 'axios' | ...
27
+ handlerSymbol?: string; // server routes
28
+ requestSchemaSymbols?: string[];
29
+ responseSchemaSymbols?: string[];
30
+ callsites?: string[]; // frontend calls
31
+ source: { file: string; line: number; col: number };
32
+ }
33
+ ```
34
+
35
+ ## Canonical normalization (ADR 0004 D2)
36
+
37
+ `normalizeHttpPath` strips query/fragment, collapses slashes, converts
38
+ `${expr}` and FastAPI `{name}` / `{name:type}` to `{}`, `{name:path}`
39
+ converters and `*` catch-alls to `{*}`, and canonicalizes absolute URLs
40
+ only for configured same-origin hosts. Parameter names are **never** part
41
+ of an identity. Unresolvable shapes return `HTTP_PATH_DYNAMIC` — never a
42
+ guess.
43
+
44
+ `normalizeHttpMethod` uppercases concrete verbs and returns `null` for
45
+ dynamic methods (callers must emit `HTTP_METHOD_DYNAMIC`; defaulting to
46
+ `GET` is forbidden).
47
+
48
+ ## Join engine (ADR 0004 D3, phase 3 literal precedence)
49
+
50
+ `joinFrontendCalls(routes, calls)` implements exactly-one cardinality:
51
+ equal method, equal segment count, position-wise match where a frontend
52
+ `{}` matches any single route segment and a route `{*}` matches one or
53
+ more trailing segments.
54
+
55
+ Candidates are then partitioned by match quality before the exactly-one
56
+ check (**literal precedence**): a match is *literal* when it consumed no
57
+ slot generality — every position is exact segment equality, counting a
58
+ route `{}` mirrored by the call's own `{}` — and *parameter* otherwise
59
+ (route `{}` absorbing a call literal, a call `{}` relaxed onto a route
60
+ literal, or any `{*}` absorption; a wildcard match is never literal). If
61
+ any literal matches exist they are THE candidates; parameter-only matches
62
+ are considered only when zero literal matches exist.
63
+
64
+ Why: routers resolve literal path segments before parameterized ones at
65
+ runtime (FastAPI included), so `/messages/search` never reaches
66
+ `/messages/{}` with `id="search"`. The static join mirrors that runtime
67
+ truth: a template call `/messages/${id}` joins `/messages/{}` despite
68
+ literal siblings, and a literal call joins the literal route.
69
+
70
+ Zero matches → `FRONTEND_ROUTE_UNWIRED`; more than one distinct surviving
71
+ candidate (in either tier) → `FRONTEND_ROUTE_AMBIGUOUS`. There is no
72
+ scoring and no first-match-wins beyond the documented partition. Duplicate
73
+ identical routes collapse into one endpoint carrying every source.
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Typed outcome codes for the HTTP contract compiler (ADR 0004 D4).
3
+ *
4
+ * These codes are stable free-form strings, matching the existing
5
+ * unresolved/findings convention (`no_tablename_source`,
6
+ * `inherited_tablename_unresolved`, ...). Detectors emit them as
7
+ * `UnresolvedReason.code` / `Finding.code`; the verdict engine uses
8
+ * `HTTP_OBSERVATION_UNTRUSTED` as a verdict reason. They are deliberately
9
+ * NOT a closed core enum: adding a code is additive and versioned by the
10
+ * detector that emits it.
11
+ */
12
+ /** A path expression the detector cannot resolve to positional shape. */
13
+ export declare const HTTP_PATH_DYNAMIC = "HTTP_PATH_DYNAMIC";
14
+ /** A method expression the detector cannot resolve to a concrete verb. */
15
+ export declare const HTTP_METHOD_DYNAMIC = "HTTP_METHOD_DYNAMIC";
16
+ /** A FastAPI router prefix/include prefix that is not a provable literal. */
17
+ export declare const FASTAPI_PREFIX_UNRESOLVED = "FASTAPI_PREFIX_UNRESOLVED";
18
+ /** A frontend call whose target (host/URL) cannot be resolved statically. */
19
+ export declare const FRONTEND_CALL_TARGET_UNRESOLVED = "FRONTEND_CALL_TARGET_UNRESOLVED";
20
+ /** A frontend call with no matching backend route. */
21
+ export declare const FRONTEND_ROUTE_UNWIRED = "FRONTEND_ROUTE_UNWIRED";
22
+ /**
23
+ * A frontend call matching more than one distinct backend route within the
24
+ * surviving literal-precedence tier (see `join.ts`): literal matches shadow
25
+ * parameter matches, and even after that partition the join refuses to
26
+ * guess between distinct survivors.
27
+ */
28
+ export declare const FRONTEND_ROUTE_AMBIGUOUS = "FRONTEND_ROUTE_AMBIGUOUS";
29
+ /** An endpoint whose business semantics no positive rule could decide. */
30
+ export declare const ENDPOINT_SEMANTICS_UNRESOLVED = "ENDPOINT_SEMANTICS_UNRESOLVED";
31
+ /** An endpoint that cannot be linked to exactly one business resource. */
32
+ export declare const ENDPOINT_RESOURCE_LINK_UNRESOLVED = "ENDPOINT_RESOURCE_LINK_UNRESOLVED";
33
+ /**
34
+ * A runtime HTTP observation that cannot be trusted (suite-submitted
35
+ * network record, missing run binding, wrong provenance).
36
+ */
37
+ export declare const HTTP_OBSERVATION_UNTRUSTED = "HTTP_OBSERVATION_UNTRUSTED";
38
+ /** Every typed outcome code defined by this package. */
39
+ export declare const HTTP_BLOCK_CODES: readonly ["HTTP_PATH_DYNAMIC", "HTTP_METHOD_DYNAMIC", "FASTAPI_PREFIX_UNRESOLVED", "FRONTEND_CALL_TARGET_UNRESOLVED", "FRONTEND_ROUTE_UNWIRED", "FRONTEND_ROUTE_AMBIGUOUS", "ENDPOINT_SEMANTICS_UNRESOLVED", "ENDPOINT_RESOURCE_LINK_UNRESOLVED", "HTTP_OBSERVATION_UNTRUSTED"];
40
+ export type HttpBlockCode = (typeof HTTP_BLOCK_CODES)[number];
41
+ //# sourceMappingURL=codes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../src/codes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,yEAAyE;AACzE,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AAErD,0EAA0E;AAC1E,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AAEzD,6EAA6E;AAC7E,eAAO,MAAM,yBAAyB,8BAA8B,CAAC;AAErE,6EAA6E;AAC7E,eAAO,MAAM,+BAA+B,oCAAoC,CAAC;AAEjF,sDAAsD;AACtD,eAAO,MAAM,sBAAsB,2BAA2B,CAAC;AAE/D;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,6BAA6B,CAAC;AAEnE,0EAA0E;AAC1E,eAAO,MAAM,6BAA6B,kCAAkC,CAAC;AAE7E,0EAA0E;AAC1E,eAAO,MAAM,iCAAiC,sCAAsC,CAAC;AAErF;;;GAGG;AACH,eAAO,MAAM,0BAA0B,+BAA+B,CAAC;AAEvE,wDAAwD;AACxD,eAAO,MAAM,gBAAgB,iRAUnB,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC"}
package/dist/codes.js ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Typed outcome codes for the HTTP contract compiler (ADR 0004 D4).
3
+ *
4
+ * These codes are stable free-form strings, matching the existing
5
+ * unresolved/findings convention (`no_tablename_source`,
6
+ * `inherited_tablename_unresolved`, ...). Detectors emit them as
7
+ * `UnresolvedReason.code` / `Finding.code`; the verdict engine uses
8
+ * `HTTP_OBSERVATION_UNTRUSTED` as a verdict reason. They are deliberately
9
+ * NOT a closed core enum: adding a code is additive and versioned by the
10
+ * detector that emits it.
11
+ */
12
+ /** A path expression the detector cannot resolve to positional shape. */
13
+ export const HTTP_PATH_DYNAMIC = 'HTTP_PATH_DYNAMIC';
14
+ /** A method expression the detector cannot resolve to a concrete verb. */
15
+ export const HTTP_METHOD_DYNAMIC = 'HTTP_METHOD_DYNAMIC';
16
+ /** A FastAPI router prefix/include prefix that is not a provable literal. */
17
+ export const FASTAPI_PREFIX_UNRESOLVED = 'FASTAPI_PREFIX_UNRESOLVED';
18
+ /** A frontend call whose target (host/URL) cannot be resolved statically. */
19
+ export const FRONTEND_CALL_TARGET_UNRESOLVED = 'FRONTEND_CALL_TARGET_UNRESOLVED';
20
+ /** A frontend call with no matching backend route. */
21
+ export const FRONTEND_ROUTE_UNWIRED = 'FRONTEND_ROUTE_UNWIRED';
22
+ /**
23
+ * A frontend call matching more than one distinct backend route within the
24
+ * surviving literal-precedence tier (see `join.ts`): literal matches shadow
25
+ * parameter matches, and even after that partition the join refuses to
26
+ * guess between distinct survivors.
27
+ */
28
+ export const FRONTEND_ROUTE_AMBIGUOUS = 'FRONTEND_ROUTE_AMBIGUOUS';
29
+ /** An endpoint whose business semantics no positive rule could decide. */
30
+ export const ENDPOINT_SEMANTICS_UNRESOLVED = 'ENDPOINT_SEMANTICS_UNRESOLVED';
31
+ /** An endpoint that cannot be linked to exactly one business resource. */
32
+ export const ENDPOINT_RESOURCE_LINK_UNRESOLVED = 'ENDPOINT_RESOURCE_LINK_UNRESOLVED';
33
+ /**
34
+ * A runtime HTTP observation that cannot be trusted (suite-submitted
35
+ * network record, missing run binding, wrong provenance).
36
+ */
37
+ export const HTTP_OBSERVATION_UNTRUSTED = 'HTTP_OBSERVATION_UNTRUSTED';
38
+ /** Every typed outcome code defined by this package. */
39
+ export const HTTP_BLOCK_CODES = [
40
+ HTTP_PATH_DYNAMIC,
41
+ HTTP_METHOD_DYNAMIC,
42
+ FASTAPI_PREFIX_UNRESOLVED,
43
+ FRONTEND_CALL_TARGET_UNRESOLVED,
44
+ FRONTEND_ROUTE_UNWIRED,
45
+ FRONTEND_ROUTE_AMBIGUOUS,
46
+ ENDPOINT_SEMANTICS_UNRESOLVED,
47
+ ENDPOINT_RESOURCE_LINK_UNRESOLVED,
48
+ HTTP_OBSERVATION_UNTRUSTED,
49
+ ];
50
+ //# sourceMappingURL=codes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codes.js","sourceRoot":"","sources":["../src/codes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,yEAAyE;AACzE,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAErD,0EAA0E;AAC1E,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAEzD,6EAA6E;AAC7E,MAAM,CAAC,MAAM,yBAAyB,GAAG,2BAA2B,CAAC;AAErE,6EAA6E;AAC7E,MAAM,CAAC,MAAM,+BAA+B,GAAG,iCAAiC,CAAC;AAEjF,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAC;AAEnE,0EAA0E;AAC1E,MAAM,CAAC,MAAM,6BAA6B,GAAG,+BAA+B,CAAC;AAE7E,0EAA0E;AAC1E,MAAM,CAAC,MAAM,iCAAiC,GAAG,mCAAmC,CAAC;AAErF;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,4BAA4B,CAAC;AAEvE,wDAAwD;AACxD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,iBAAiB;IACjB,mBAAmB;IACnB,yBAAyB;IACzB,+BAA+B;IAC/B,sBAAsB;IACtB,wBAAwB;IACxB,6BAA6B;IAC7B,iCAAiC;IACjC,0BAA0B;CAClB,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `@gate-forge/http-contract` — framework-neutral canonical HTTP contract
3
+ * (ADR 0004): strict fact schemas, typed outcome codes, path/method
4
+ * normalization, and the deterministic frontend-call/server-route join.
5
+ *
6
+ * This package is deliberately narrow: no framework parsing (detectors own
7
+ * that), no classification (core owns that), no I/O. Everything is a pure
8
+ * function so identical inputs produce byte-identical outputs.
9
+ */
10
+ export { FASTAPI_PREFIX_UNRESOLVED, FRONTEND_CALL_TARGET_UNRESOLVED, FRONTEND_ROUTE_AMBIGUOUS, FRONTEND_ROUTE_UNWIRED, ENDPOINT_RESOURCE_LINK_UNRESOLVED, ENDPOINT_SEMANTICS_UNRESOLVED, HTTP_METHOD_DYNAMIC, HTTP_OBSERVATION_UNTRUSTED, HTTP_PATH_DYNAMIC, HTTP_BLOCK_CODES, type HttpBlockCode, } from './codes.js';
11
+ export { HTTP_CONTRACT_SCHEMA_VERSION, HTTP_CONTRACT_KIND, HTTP_ENDPOINT_KIND, HTTP_METHODS, HttpContractFactSchema, HttpContractRoleSchema, HttpContractSchemaVersionField, HttpLocationSchema, HttpMethodSchema, type HttpContractFact, type HttpContractRole, type HttpLocation, type HttpMethod, } from './schema.js';
12
+ export { HTTP_CONTRACT_VERSION, } from './version.js';
13
+ export { HTTP_PARAM_SLOT, HTTP_WILDCARD_SLOT, normalizeHttpMethod, normalizeHttpPath, pathSegments, type NormalizePathDynamic, type NormalizePathOk, type NormalizePathOptions, type NormalizePathResult, } from './normalize.js';
14
+ export { canonicalEndpointIdentity, endpointResourceName, joinFrontendCalls, routeMatchKind, routeMatchesCall, type EndpointIdentity, type JoinBlock, type JoinedEndpoint, type JoinResult, type RouteMatchKind, } from './join.js';
15
+ export { derivePathResourceName } from './linkage.js';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,yBAAyB,EACzB,+BAA+B,EAC/B,wBAAwB,EACxB,sBAAsB,EACtB,iCAAiC,EACjC,6BAA6B,EAC7B,mBAAmB,EACnB,0BAA0B,EAC1B,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,sBAAsB,EACtB,sBAAsB,EACtB,8BAA8B,EAC9B,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,UAAU,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qBAAqB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,yBAAyB,EACzB,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,cAAc,GACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `@gate-forge/http-contract` — framework-neutral canonical HTTP contract
3
+ * (ADR 0004): strict fact schemas, typed outcome codes, path/method
4
+ * normalization, and the deterministic frontend-call/server-route join.
5
+ *
6
+ * This package is deliberately narrow: no framework parsing (detectors own
7
+ * that), no classification (core owns that), no I/O. Everything is a pure
8
+ * function so identical inputs produce byte-identical outputs.
9
+ */
10
+ export { FASTAPI_PREFIX_UNRESOLVED, FRONTEND_CALL_TARGET_UNRESOLVED, FRONTEND_ROUTE_AMBIGUOUS, FRONTEND_ROUTE_UNWIRED, ENDPOINT_RESOURCE_LINK_UNRESOLVED, ENDPOINT_SEMANTICS_UNRESOLVED, HTTP_METHOD_DYNAMIC, HTTP_OBSERVATION_UNTRUSTED, HTTP_PATH_DYNAMIC, HTTP_BLOCK_CODES, } from './codes.js';
11
+ export { HTTP_CONTRACT_SCHEMA_VERSION, HTTP_CONTRACT_KIND, HTTP_ENDPOINT_KIND, HTTP_METHODS, HttpContractFactSchema, HttpContractRoleSchema, HttpContractSchemaVersionField, HttpLocationSchema, HttpMethodSchema, } from './schema.js';
12
+ export { HTTP_CONTRACT_VERSION, } from './version.js';
13
+ export { HTTP_PARAM_SLOT, HTTP_WILDCARD_SLOT, normalizeHttpMethod, normalizeHttpPath, pathSegments, } from './normalize.js';
14
+ export { canonicalEndpointIdentity, endpointResourceName, joinFrontendCalls, routeMatchKind, routeMatchesCall, } from './join.js';
15
+ export { derivePathResourceName } from './linkage.js';
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,yBAAyB,EACzB,+BAA+B,EAC/B,wBAAwB,EACxB,sBAAsB,EACtB,iCAAiC,EACjC,6BAA6B,EAC7B,mBAAmB,EACnB,0BAA0B,EAC1B,iBAAiB,EACjB,gBAAgB,GAEjB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,sBAAsB,EACtB,sBAAsB,EACtB,8BAA8B,EAC9B,kBAAkB,EAClB,gBAAgB,GAKjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qBAAqB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,GAKb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,yBAAyB,EACzB,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,GAMjB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC"}
package/dist/join.d.ts ADDED
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Deterministic one-to-one join engine (ADR 0004 D3).
3
+ *
4
+ * A frontend consumption exists only when one frontend-call fact joins
5
+ * exactly one distinct backend route identity: equal uppercase method,
6
+ * position-wise segment match where a frontend `{}` matches any single
7
+ * route segment (param or literal) and a trailing route `{*}` matches one
8
+ * or more trailing call segments.
9
+ *
10
+ * LITERAL PRECEDENCE (phase 3 refinement). Positional candidates are
11
+ * partitioned by match quality before the exactly-one check:
12
+ *
13
+ * - A match is *literal* when it consumed no slot generality: every
14
+ * matched position is exact segment equality — literal==literal, or the
15
+ * call's own `{}` mirrored by the route's `{}` (the route then declares
16
+ * exactly the shape the call already has; nothing is absorbed beyond
17
+ * what the call itself carries).
18
+ * - A match is *parameter* otherwise: a route `{}` absorbed a call
19
+ * literal, a call `{}` was relaxed onto a route literal, or any `{*}`
20
+ * absorption happened. A wildcard match is never a literal match.
21
+ *
22
+ * If any literal matches exist they are THE candidates; parameter-only
23
+ * matches are considered only when zero literal matches exist. This
24
+ * mirrors runtime routing truth: FastAPI — like every major router —
25
+ * resolves literal path segments before parameterized ones, so a request
26
+ * to `/messages/search` always hits the literal route and never reaches
27
+ * `/messages/{}` with id="search". The static join must agree: a
28
+ * template call `/messages/${id}` joins `/messages/{}` despite literal
29
+ * siblings, and a literal call `/messages/unread-count` joins only the
30
+ * literal route.
31
+ *
32
+ * Never guess: zero selected candidates and multiple distinct selected
33
+ * candidates (in either tier) are typed blocks — there is no scoring, no
34
+ * fuzzy distance, and no first-match-wins beyond the documented partition.
35
+ *
36
+ * The result is a pure function of the input facts: identical inputs in
37
+ * any permutation produce byte-identical output (total order everywhere).
38
+ */
39
+ import { FRONTEND_ROUTE_AMBIGUOUS, FRONTEND_ROUTE_UNWIRED, HTTP_METHOD_DYNAMIC } from './codes.js';
40
+ import type { HttpContractFact, HttpLocation, HttpMethod } from './schema.js';
41
+ /** Canonical identity of an endpoint: `<METHOD> <canonicalPath>`. */
42
+ export type EndpointIdentity = string;
43
+ /** Canonical identity string for a method/path pair. */
44
+ export declare function canonicalEndpointIdentity(method: HttpMethod, canonicalPath: string): EndpointIdentity;
45
+ /**
46
+ * Deterministic, collision-safe endpoint resource name (ADR 0004 D1):
47
+ * `http-<method>-<path-slug>-<sha8>`. The slug keeps reports readable; the
48
+ * identity hash suffix makes distinct endpoints collision-free even when
49
+ * sanitization would coincide (dot vs dash), and is invariant under
50
+ * parameter-name changes because it hashes the canonical form.
51
+ */
52
+ export declare function endpointResourceName(method: HttpMethod, canonicalPath: string): string;
53
+ /** One joined endpoint: a route identity plus every fact on either side. */
54
+ export interface JoinedEndpoint {
55
+ method: HttpMethod;
56
+ canonicalPath: string;
57
+ identity: EndpointIdentity;
58
+ /** Resource name for the compiled `http.endpoint` resource (ADR 0004 D1). */
59
+ resourceName: string;
60
+ /** Every distinct server-route fact carrying this identity (duplicates collapsed). */
61
+ routes: HttpContractFact[];
62
+ /** Every frontend-call fact joined to this identity, source order sorted. */
63
+ calls: HttpContractFact[];
64
+ }
65
+ /** A typed, source-located join failure. */
66
+ export interface JoinBlock {
67
+ code: typeof FRONTEND_ROUTE_UNWIRED | typeof FRONTEND_ROUTE_AMBIGUOUS | typeof HTTP_METHOD_DYNAMIC;
68
+ detail: string;
69
+ location: HttpLocation;
70
+ /** Identity candidates for ambiguity blocks — the surviving
71
+ * literal-precedence tier, sorted; empty otherwise. */
72
+ candidates: EndpointIdentity[];
73
+ }
74
+ export interface JoinResult {
75
+ /** Joined endpoints, sorted by identity. */
76
+ endpoints: JoinedEndpoint[];
77
+ /** Typed blocks (unwired/ambiguous/dynamic-method), deterministically sorted. */
78
+ blocks: JoinBlock[];
79
+ }
80
+ /**
81
+ * Match-quality tier of one route/call pair (LITERAL PRECEDENCE).
82
+ *
83
+ * - `'literal'` — matched with zero slot generality: every matched position
84
+ * is exact segment equality (literal==literal, or the call's own `{}`
85
+ * mirrored by the route's `{}`; the route consumed nothing beyond what
86
+ * the call itself declares).
87
+ * - `'parameter'` — matched, but at least one position exercised slot
88
+ * generality: a route `{}` absorbed a call literal, a call `{}` was
89
+ * relaxed onto a route literal, or the trailing route `{*}` absorbed one
90
+ * or more call segments. A wildcard match is never a literal match.
91
+ * - `null` — no positional match at all.
92
+ */
93
+ export type RouteMatchKind = 'literal' | 'parameter';
94
+ /**
95
+ * Classifies one call/route pair by match quality, or returns `null` when
96
+ * the pair does not match under the documented positional rules. Pure and
97
+ * order-independent; `routeMatchesCall` is exactly `kind !== null`.
98
+ */
99
+ export declare function routeMatchKind(route: HttpContractFact, call: HttpContractFact): RouteMatchKind | null;
100
+ /** Whether one call fact can join one route fact at all. */
101
+ export declare function routeMatchesCall(route: HttpContractFact, call: HttpContractFact): boolean;
102
+ /**
103
+ * Joins frontend-call facts against server-route facts.
104
+ *
105
+ * Candidate selection applies LITERAL PRECEDENCE (see the module
106
+ * docstring): literal matches shadow parameter matches, mirroring how
107
+ * routers resolve literal segments before parameterized ones at runtime.
108
+ *
109
+ * `ANY` routes participate in the inventory (they carry exposure evidence)
110
+ * but never join: a catch-all registration cannot prove which concrete
111
+ * method the frontend exercised. Calls with a non-concrete method produce
112
+ * `HTTP_METHOD_DYNAMIC` blocks.
113
+ */
114
+ export declare function joinFrontendCalls(routes: readonly HttpContractFact[], calls: readonly HttpContractFact[]): JoinResult;
115
+ //# sourceMappingURL=join.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join.d.ts","sourceRoot":"","sources":["../src/join.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAIH,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9E,qEAAqE;AACrE,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEtC,wDAAwD;AACxD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,GAAG,gBAAgB,CAErG;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAkBtF;AAED,4EAA4E;AAC5E,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,UAAU,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,6EAA6E;IAC7E,YAAY,EAAE,MAAM,CAAC;IACrB,sFAAsF;IACtF,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,6EAA6E;IAC7E,KAAK,EAAE,gBAAgB,EAAE,CAAC;CAC3B;AAED,4CAA4C;AAC5C,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,OAAO,sBAAsB,GAAG,OAAO,wBAAwB,GAAG,OAAO,mBAAmB,CAAC;IACnG,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,YAAY,CAAC;IACvB;2DACuD;IACvD,UAAU,EAAE,gBAAgB,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,UAAU;IACzB,4CAA4C;IAC5C,SAAS,EAAE,cAAc,EAAE,CAAC;IAC5B,iFAAiF;IACjF,MAAM,EAAE,SAAS,EAAE,CAAC;CACrB;AAmCD;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,WAAW,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,gBAAgB,GAAG,cAAc,GAAG,IAAI,CAsBrG;AAED,4DAA4D;AAC5D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAEzF;AAQD;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,gBAAgB,EAAE,EACnC,KAAK,EAAE,SAAS,gBAAgB,EAAE,GACjC,UAAU,CAyFZ"}