@leed-ai/git-gateway-core 0.0.0-stage → 0.1.1-next.20261122193358
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 +201 -0
- package/README.md +35 -2
- package/dist/actions/apply-commit-actions.d.ts +20 -0
- package/dist/actions/apply-commit-actions.js +101 -0
- package/dist/actions/apply-commit-actions.js.map +1 -0
- package/dist/bytes.d.ts +13 -0
- package/dist/bytes.js +49 -0
- package/dist/bytes.js.map +1 -0
- package/dist/commit/build-commit.d.ts +14 -0
- package/dist/commit/build-commit.js +57 -0
- package/dist/commit/build-commit.js.map +1 -0
- package/dist/core-error.d.ts +18 -0
- package/dist/core-error.js +30 -0
- package/dist/core-error.js.map +1 -0
- package/dist/git-object-CYJdrUC-.d.ts +67 -0
- package/dist/idempotency/find-idempotent-commit.d.ts +18 -0
- package/dist/idempotency/find-idempotent-commit.js +59 -0
- package/dist/idempotency/find-idempotent-commit.js.map +1 -0
- package/dist/merge/merge-trees.d.ts +12 -0
- package/dist/merge/merge-trees.js +148 -0
- package/dist/merge/merge-trees.js.map +1 -0
- package/dist/objects/commit-object.d.ts +25 -0
- package/dist/objects/commit-object.js +119 -0
- package/dist/objects/commit-object.js.map +1 -0
- package/dist/objects/commit-parents.d.ts +12 -0
- package/dist/objects/commit-parents.js +32 -0
- package/dist/objects/commit-parents.js.map +1 -0
- package/dist/objects/hash-object.d.ts +8 -0
- package/dist/objects/hash-object.js +23 -0
- package/dist/objects/hash-object.js.map +1 -0
- package/dist/objects/tree-object.d.ts +16 -0
- package/dist/objects/tree-object.js +92 -0
- package/dist/objects/tree-object.js.map +1 -0
- package/dist/pack/apply-delta.d.ts +10 -0
- package/dist/pack/apply-delta.js +71 -0
- package/dist/pack/apply-delta.js.map +1 -0
- package/dist/pack/bit-reader.d.ts +21 -0
- package/dist/pack/bit-reader.js +77 -0
- package/dist/pack/bit-reader.js.map +1 -0
- package/dist/pack/deflate-constants.d.ts +11 -0
- package/dist/pack/deflate-constants.js +156 -0
- package/dist/pack/deflate-constants.js.map +1 -0
- package/dist/pack/deflate-tables.d.ts +15 -0
- package/dist/pack/deflate-tables.js +41 -0
- package/dist/pack/deflate-tables.js.map +1 -0
- package/dist/pack/deflate.d.ts +5 -0
- package/dist/pack/deflate.js +20 -0
- package/dist/pack/deflate.js.map +1 -0
- package/dist/pack/huffman.d.ts +16 -0
- package/dist/pack/huffman.js +38 -0
- package/dist/pack/huffman.js.map +1 -0
- package/dist/pack/inflate-output.d.ts +20 -0
- package/dist/pack/inflate-output.js +75 -0
- package/dist/pack/inflate-output.js.map +1 -0
- package/dist/pack/pack-entry-header.d.ts +27 -0
- package/dist/pack/pack-entry-header.js +82 -0
- package/dist/pack/pack-entry-header.js.map +1 -0
- package/dist/pack/pack-scanner.d.ts +47 -0
- package/dist/pack/pack-scanner.js +170 -0
- package/dist/pack/pack-scanner.js.map +1 -0
- package/dist/pack/read-pack.d.ts +24 -0
- package/dist/pack/read-pack.js +194 -0
- package/dist/pack/read-pack.js.map +1 -0
- package/dist/pack/stream-inflater.d.ts +41 -0
- package/dist/pack/stream-inflater.js +218 -0
- package/dist/pack/stream-inflater.js.map +1 -0
- package/dist/pack/write-pack.d.ts +17 -0
- package/dist/pack/write-pack.js +55 -0
- package/dist/pack/write-pack.js.map +1 -0
- package/dist/pack/zlib-inflate.d.ts +16 -0
- package/dist/pack/zlib-inflate.js +117 -0
- package/dist/pack/zlib-inflate.js.map +1 -0
- package/dist/package-name.d.ts +3 -0
- package/dist/package-name.js +6 -0
- package/dist/package-name.js.map +1 -0
- package/dist/pkt-line/decode.d.ts +9 -0
- package/dist/pkt-line/decode.js +37 -0
- package/dist/pkt-line/decode.js.map +1 -0
- package/dist/pkt-line/encode.d.ts +18 -0
- package/dist/pkt-line/encode.js +38 -0
- package/dist/pkt-line/encode.js.map +1 -0
- package/dist/pkt-line/length-header.d.ts +17 -0
- package/dist/pkt-line/length-header.js +44 -0
- package/dist/pkt-line/length-header.js.map +1 -0
- package/dist/pkt-line/pkt-line-reader.d.ts +35 -0
- package/dist/pkt-line/pkt-line-reader.js +111 -0
- package/dist/pkt-line/pkt-line-reader.js.map +1 -0
- package/dist/receive-pack/encode-request.d.ts +9 -0
- package/dist/receive-pack/encode-request.js +28 -0
- package/dist/receive-pack/encode-request.js.map +1 -0
- package/dist/receive-pack/parse-request.d.ts +36 -0
- package/dist/receive-pack/parse-request.js +118 -0
- package/dist/receive-pack/parse-request.js.map +1 -0
- package/dist/receive-pack/report-status.d.ts +35 -0
- package/dist/receive-pack/report-status.js +102 -0
- package/dist/receive-pack/report-status.js.map +1 -0
- package/dist/receive-pack/side-band.d.ts +29 -0
- package/dist/receive-pack/side-band.js +56 -0
- package/dist/receive-pack/side-band.js.map +1 -0
- package/dist/schemas/build-commit.d.ts +150 -0
- package/dist/schemas/build-commit.js +105 -0
- package/dist/schemas/build-commit.js.map +1 -0
- package/dist/schemas/commit-actions.d.ts +87 -0
- package/dist/schemas/commit-actions.js +66 -0
- package/dist/schemas/commit-actions.js.map +1 -0
- package/dist/schemas/core-error-body.d.ts +148 -0
- package/dist/schemas/core-error-body.js +130 -0
- package/dist/schemas/core-error-body.js.map +1 -0
- package/dist/schemas/git-object.d.ts +2 -0
- package/dist/schemas/git-object.js +101 -0
- package/dist/schemas/git-object.js.map +1 -0
- package/dist/schemas/idempotency-lookup.d.ts +14 -0
- package/dist/schemas/idempotency-lookup.js +29 -0
- package/dist/schemas/idempotency-lookup.js.map +1 -0
- package/dist/schemas/packet.d.ts +32 -0
- package/dist/schemas/packet.js +68 -0
- package/dist/schemas/packet.js.map +1 -0
- package/dist/schemas/receive-pack.d.ts +59 -0
- package/dist/schemas/receive-pack.js +115 -0
- package/dist/schemas/receive-pack.js.map +1 -0
- package/dist/schemas/ref-advertisement.d.ts +33 -0
- package/dist/schemas/ref-advertisement.js +55 -0
- package/dist/schemas/ref-advertisement.js.map +1 -0
- package/dist/schemas/report-status.d.ts +38 -0
- package/dist/schemas/report-status.js +61 -0
- package/dist/schemas/report-status.js.map +1 -0
- package/dist/schemas/tree-edit.d.ts +78 -0
- package/dist/schemas/tree-edit.js +99 -0
- package/dist/schemas/tree-edit.js.map +1 -0
- package/dist/schemas/tree-merge.d.ts +48 -0
- package/dist/schemas/tree-merge.js +64 -0
- package/dist/schemas/tree-merge.js.map +1 -0
- package/dist/schemas/upload-pack.d.ts +25 -0
- package/dist/schemas/upload-pack.js +56 -0
- package/dist/schemas/upload-pack.js.map +1 -0
- package/dist/smart-http/git-http-client.d.ts +52 -0
- package/dist/smart-http/git-http-client.js +104 -0
- package/dist/smart-http/git-http-client.js.map +1 -0
- package/dist/smart-http/ref-advertisement.d.ts +16 -0
- package/dist/smart-http/ref-advertisement.js +103 -0
- package/dist/smart-http/ref-advertisement.js.map +1 -0
- package/dist/tree/edit-tree.d.ts +12 -0
- package/dist/tree/edit-tree.js +40 -0
- package/dist/tree/edit-tree.js.map +1 -0
- package/dist/tree/path-rules.d.ts +15 -0
- package/dist/tree/path-rules.js +33 -0
- package/dist/tree/path-rules.js.map +1 -0
- package/dist/tree/tree-overlay.d.ts +50 -0
- package/dist/tree/tree-overlay.js +147 -0
- package/dist/tree/tree-overlay.js.map +1 -0
- package/dist/tree/tree-reader.d.ts +2 -0
- package/dist/tree/tree-reader.js +34 -0
- package/dist/tree/tree-reader.js.map +1 -0
- package/dist/tree-reader-CK9ScndQ.d.ts +19 -0
- package/dist/upload-pack/encode-request.d.ts +9 -0
- package/dist/upload-pack/encode-request.js +28 -0
- package/dist/upload-pack/encode-request.js.map +1 -0
- package/dist/upload-pack/parse-response.d.ts +17 -0
- package/dist/upload-pack/parse-response.js +111 -0
- package/dist/upload-pack/parse-response.js.map +1 -0
- package/package.json +323 -4
- package/src/actions/apply-commit-actions.ts +105 -0
- package/src/bytes.ts +56 -0
- package/src/commit/build-commit.ts +41 -0
- package/src/core-error.ts +35 -0
- package/src/idempotency/find-idempotent-commit.ts +71 -0
- package/src/merge/merge-trees.ts +143 -0
- package/src/objects/commit-object.ts +128 -0
- package/src/objects/commit-parents.ts +34 -0
- package/src/objects/hash-object.ts +20 -0
- package/src/objects/tree-object.ts +89 -0
- package/src/pack/apply-delta.ts +81 -0
- package/src/pack/bit-reader.ts +80 -0
- package/src/pack/deflate-constants.ts +24 -0
- package/src/pack/deflate-tables.ts +60 -0
- package/src/pack/deflate.ts +24 -0
- package/src/pack/huffman.ts +45 -0
- package/src/pack/inflate-output.ts +87 -0
- package/src/pack/pack-entry-header.ts +75 -0
- package/src/pack/pack-scanner.ts +230 -0
- package/src/pack/read-pack.ts +232 -0
- package/src/pack/stream-inflater.ts +251 -0
- package/src/pack/write-pack.ts +54 -0
- package/src/pack/zlib-inflate.ts +139 -0
- package/src/package-name.ts +4 -0
- package/src/pkt-line/decode.ts +35 -0
- package/src/pkt-line/encode.ts +39 -0
- package/src/pkt-line/length-header.ts +47 -0
- package/src/pkt-line/pkt-line-reader.ts +131 -0
- package/src/receive-pack/encode-request.ts +29 -0
- package/src/receive-pack/parse-request.ts +163 -0
- package/src/receive-pack/report-status.ts +113 -0
- package/src/receive-pack/side-band.ts +74 -0
- package/src/schemas/build-commit.ts +143 -0
- package/src/schemas/commit-actions.ts +82 -0
- package/src/schemas/core-error-body.ts +164 -0
- package/src/schemas/git-object.ts +132 -0
- package/src/schemas/idempotency-lookup.ts +35 -0
- package/src/schemas/packet.ts +68 -0
- package/src/schemas/receive-pack.ts +191 -0
- package/src/schemas/ref-advertisement.ts +83 -0
- package/src/schemas/report-status.ts +75 -0
- package/src/schemas/tree-edit.ts +113 -0
- package/src/schemas/tree-merge.ts +76 -0
- package/src/schemas/upload-pack.ts +92 -0
- package/src/smart-http/git-http-client.ts +149 -0
- package/src/smart-http/ref-advertisement.ts +100 -0
- package/src/tree/edit-tree.ts +42 -0
- package/src/tree/path-rules.ts +41 -0
- package/src/tree/tree-overlay.ts +174 -0
- package/src/tree/tree-reader.ts +39 -0
- package/src/upload-pack/encode-request.ts +28 -0
- package/src/upload-pack/parse-response.ts +108 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @leed-ai/git-gateway-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Platform-free git primitives for git-gateway: pkt-line, receive-pack parsing, object encoding, packs, tree editing, file-level merge.
|
|
4
|
+
|
|
5
|
+
Part of [git-gateway](https://github.com/leed-ai/git-gateway). Status: in development; see the [design](https://github.com/leed-ai/git-gateway/blob/main/docs/design.md).
|
|
6
|
+
|
|
7
|
+
Peer dependencies: `zod` (`^4`). Install them alongside this package.
|
|
8
|
+
|
|
9
|
+
No Cloudflare imports: everything runs in Bun, Node and Workers. Each module is its own export (`@leed-ai/git-gateway-core/<module>`), named exports only:
|
|
10
|
+
|
|
11
|
+
| Module | What it does |
|
|
12
|
+
| ------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
13
|
+
| `pkt-line/encode`, `pkt-line/decode`, `pkt-line/pkt-line-reader` | pkt-line framing: encode, decode a buffer, read a stream one packet at a time and hand the rest on. |
|
|
14
|
+
| `receive-pack/parse-request` | Parses the leading commands, capabilities, push options and shallow lines of a git-receive-pack body without reading the pack, and returns a stream that replays the body. Bounded: at most 10000 shallow lines and commands, 100 push options and `maxHeadBytes` (8 MiB) before the pack; the body is cancelled on failure. |
|
|
15
|
+
| `receive-pack/encode-request`, `receive-pack/report-status`, `receive-pack/side-band` | Builds receive-pack requests; parses and writes report-status (`ok` / `ng <ref> <reason>`, `ERR`) with no side-band, side-band (1000-byte packets) or side-band-64k framing. |
|
|
16
|
+
| `objects/hash-object`, `objects/tree-object`, `objects/commit-object` | Blob, tree and commit encoding and decoding with ids identical to `git hash-object`. |
|
|
17
|
+
| `pack/write-pack`, `pack/deflate` | Undeltified version 2 packs, zlib via `CompressionStream`; they pass `git index-pack --strict`. |
|
|
18
|
+
| `tree/edit-tree`, `tree/tree-overlay`, `tree/tree-reader` | Path edits of a tree that read only the directories along the edited paths (through a `readTree` callback) and rewrite only what changed. |
|
|
19
|
+
| `actions/apply-commit-actions` | Commit actions with GitLab Commits API semantics (create, update, upsert, delete, move, chmod), text or base64, and no-op detection. Rule failures throw the contract `GatewayError`. |
|
|
20
|
+
| `merge/merge-trees` | File-level three-way merge of trees against a merge base; conflicts come back as a sorted path list. Agrees with the contract's reference merge. |
|
|
21
|
+
| `idempotency/find-idempotent-commit` | Finds the commit carrying a `Gateway-Idempotency-Key:` trailer within a bounded history window. |
|
|
22
|
+
| `commit/build-commit` | Builds a commit from actions without a clone: the objects to pack and the ref update to push. |
|
|
23
|
+
|
|
24
|
+
Protocol and object problems throw a `CoreError` (`core-error`) whose `body` is a `CoreErrorBody`.
|
|
25
|
+
|
|
26
|
+
## Tests
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
bun run test # unit and property tests, with the 90 % line-coverage gate
|
|
30
|
+
bun run test:conformance # against the real git binary (GIT_BINARY overrides `git`)
|
|
31
|
+
bun run test:mutation # Stryker mutation testing (nightly in CI)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
Apache-2.0
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ActionsResult, ApplyActionsInput } from "../schemas/commit-actions.js";
|
|
2
|
+
import { n as TreeReader } from "../tree-reader-CK9ScndQ.js";
|
|
3
|
+
/**
|
|
4
|
+
* Applies commit actions to a tree with GitLab Commits API semantics (plus upsert), in order,
|
|
5
|
+
* each to the result of the one before, reading only the directories along the paths the actions
|
|
6
|
+
* name:
|
|
7
|
+
*
|
|
8
|
+
* - create: fails with path_exists if the path is a file or directory, path_conflict if a parent is a file;
|
|
9
|
+
* - update: fails with path_not_found unless the path is a file; keeps its mode;
|
|
10
|
+
* - upsert: creates or replaces (keeping the mode); path_exists for a directory, path_conflict for a file parent;
|
|
11
|
+
* - delete: fails with path_not_found unless the path is a file; empty directories disappear;
|
|
12
|
+
* - move: `previousPath` must be a file (path_not_found) and `path` free (path_exists / path_conflict) once
|
|
13
|
+
* the source has left; keeps the mode and, without `content`, the blob;
|
|
14
|
+
* - chmod: sets 100755 or 100644 on an existing file (path_not_found otherwise); symbolic links are left as they are.
|
|
15
|
+
*
|
|
16
|
+
* Content is UTF-8 text or base64. A result equal to the base tree is reported as `noop`.
|
|
17
|
+
* Rule failures throw a contract GatewayError; nothing is returned partially applied.
|
|
18
|
+
*/
|
|
19
|
+
export declare function applyCommitActions(input: ApplyActionsInput, reader: TreeReader): Promise<ActionsResult>;
|
|
20
|
+
//# sourceMappingURL=apply-commit-actions.d.ts.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { createObject } from "../objects/hash-object.js";
|
|
2
|
+
import { ApplyActionsInput } from "../schemas/commit-actions.js";
|
|
3
|
+
import { requireFile, requireFree } from "../tree/path-rules.js";
|
|
4
|
+
import { TreeOverlay } from "../tree/tree-overlay.js";
|
|
5
|
+
import "../tree/tree-reader.js";
|
|
6
|
+
import { decodeContent } from "@leed-ai/git-gateway-contract/reference/bytes";
|
|
7
|
+
// src/actions/apply-commit-actions.ts
|
|
8
|
+
/** Applies actions to an overlay, collecting the blobs they write. */
|
|
9
|
+
var ActionApplier = class {
|
|
10
|
+
overlay;
|
|
11
|
+
blobs = /* @__PURE__ */ new Map();
|
|
12
|
+
constructor(overlay) {
|
|
13
|
+
this.overlay = overlay;
|
|
14
|
+
}
|
|
15
|
+
async blob(content, encoding) {
|
|
16
|
+
const object = await createObject("blob", decodeContent(content, encoding));
|
|
17
|
+
this.blobs.set(object.sha, object);
|
|
18
|
+
return object.sha;
|
|
19
|
+
}
|
|
20
|
+
async apply(action) {
|
|
21
|
+
const { overlay } = this;
|
|
22
|
+
switch (action.action) {
|
|
23
|
+
case "create":
|
|
24
|
+
await requireFree(overlay, action.path);
|
|
25
|
+
await overlay.set(action.path, "100644", await this.blob(action.content, action.encoding));
|
|
26
|
+
return;
|
|
27
|
+
case "update": {
|
|
28
|
+
const existing = await requireFile(overlay, action.path);
|
|
29
|
+
await overlay.set(action.path, fileMode(existing), await this.blob(action.content, action.encoding));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
case "upsert": {
|
|
33
|
+
const state = await overlay.stat(action.path);
|
|
34
|
+
const existing = state.kind === "file" && state.entry.mode !== "160000" ? state.entry : void 0;
|
|
35
|
+
if (existing === void 0) await requireFree(overlay, action.path);
|
|
36
|
+
const mode = existing === void 0 ? "100644" : fileMode(existing);
|
|
37
|
+
await overlay.set(action.path, mode, await this.blob(action.content, action.encoding));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
case "delete":
|
|
41
|
+
await requireFile(overlay, action.path);
|
|
42
|
+
await overlay.remove(action.path);
|
|
43
|
+
return;
|
|
44
|
+
case "move": {
|
|
45
|
+
const existing = await requireFile(overlay, action.previousPath);
|
|
46
|
+
await overlay.remove(action.previousPath);
|
|
47
|
+
await requireFree(overlay, action.path);
|
|
48
|
+
const sha = action.content === void 0 ? existing.sha : await this.blob(action.content, action.encoding);
|
|
49
|
+
await overlay.set(action.path, fileMode(existing), sha);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
case "chmod": {
|
|
53
|
+
const existing = await requireFile(overlay, action.path);
|
|
54
|
+
if (existing.mode === "120000") return;
|
|
55
|
+
const mode = action.executeFilemode ? "100755" : "100644";
|
|
56
|
+
if (mode !== existing.mode) await overlay.set(action.path, mode, existing.sha);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
/** The mode of a file entry; callers have ruled out directories and submodules. */
|
|
63
|
+
function fileMode(entry) {
|
|
64
|
+
return entry.mode === "100755" || entry.mode === "120000" ? entry.mode : "100644";
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Applies commit actions to a tree with GitLab Commits API semantics (plus upsert), in order,
|
|
68
|
+
* each to the result of the one before, reading only the directories along the paths the actions
|
|
69
|
+
* name:
|
|
70
|
+
*
|
|
71
|
+
* - create: fails with path_exists if the path is a file or directory, path_conflict if a parent is a file;
|
|
72
|
+
* - update: fails with path_not_found unless the path is a file; keeps its mode;
|
|
73
|
+
* - upsert: creates or replaces (keeping the mode); path_exists for a directory, path_conflict for a file parent;
|
|
74
|
+
* - delete: fails with path_not_found unless the path is a file; empty directories disappear;
|
|
75
|
+
* - move: `previousPath` must be a file (path_not_found) and `path` free (path_exists / path_conflict) once
|
|
76
|
+
* the source has left; keeps the mode and, without `content`, the blob;
|
|
77
|
+
* - chmod: sets 100755 or 100644 on an existing file (path_not_found otherwise); symbolic links are left as they are.
|
|
78
|
+
*
|
|
79
|
+
* Content is UTF-8 text or base64. A result equal to the base tree is reported as `noop`.
|
|
80
|
+
* Rule failures throw a contract GatewayError; nothing is returned partially applied.
|
|
81
|
+
*/
|
|
82
|
+
async function applyCommitActions(input, reader) {
|
|
83
|
+
const { tree, actions } = ApplyActionsInput.parse(input);
|
|
84
|
+
const base = tree ?? "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
|
85
|
+
const applier = new ActionApplier(new TreeOverlay(reader, tree));
|
|
86
|
+
for (const action of actions) await applier.apply(action);
|
|
87
|
+
const written = await applier.overlay.write();
|
|
88
|
+
if (written.tree === base) return {
|
|
89
|
+
status: "noop",
|
|
90
|
+
tree: base
|
|
91
|
+
};
|
|
92
|
+
const blobs = [...applier.blobs.values()].filter((blob) => written.referenced.has(blob.sha));
|
|
93
|
+
return {
|
|
94
|
+
status: "changed",
|
|
95
|
+
tree: written.tree,
|
|
96
|
+
objects: [...blobs, ...written.objects]
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export { applyCommitActions };
|
|
100
|
+
|
|
101
|
+
//# sourceMappingURL=apply-commit-actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-commit-actions.js","names":[],"sources":["../../src/actions/apply-commit-actions.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { decodeContent } from '@leed-ai/git-gateway-contract/reference/bytes';\nimport type { CommitAction } from '@leed-ai/git-gateway-contract/schemas/commit-action';\n\nimport { createObject } from '../objects/hash-object.ts';\nimport { ApplyActionsInput, type ActionsResult } from '../schemas/commit-actions.ts';\nimport type { GitObject, GitTreeEntry } from '../schemas/git-object.ts';\nimport { requireFile, requireFree } from '../tree/path-rules.ts';\nimport { TreeOverlay } from '../tree/tree-overlay.ts';\nimport { EMPTY_TREE_SHA, type TreeReader } from '../tree/tree-reader.ts';\n\ntype FileEntryMode = '100644' | '100755' | '120000';\n\n/** Applies actions to an overlay, collecting the blobs they write. */\nclass ActionApplier {\n readonly blobs = new Map<string, GitObject>();\n\n constructor(readonly overlay: TreeOverlay) {}\n\n async blob(content: string, encoding: 'text' | 'base64'): Promise<string> {\n const object = await createObject('blob', decodeContent(content, encoding));\n this.blobs.set(object.sha, object);\n return object.sha;\n }\n\n async apply(action: CommitAction): Promise<void> {\n const { overlay } = this;\n switch (action.action) {\n case 'create':\n await requireFree(overlay, action.path);\n await overlay.set(action.path, '100644', await this.blob(action.content, action.encoding));\n return;\n case 'update': {\n const existing = await requireFile(overlay, action.path);\n await overlay.set(action.path, fileMode(existing), await this.blob(action.content, action.encoding));\n return;\n }\n case 'upsert': {\n const state = await overlay.stat(action.path);\n const existing = state.kind === 'file' && state.entry.mode !== '160000' ? state.entry : undefined;\n if (existing === undefined) await requireFree(overlay, action.path);\n const mode = existing === undefined ? '100644' : fileMode(existing);\n await overlay.set(action.path, mode, await this.blob(action.content, action.encoding));\n return;\n }\n case 'delete':\n await requireFile(overlay, action.path);\n await overlay.remove(action.path);\n return;\n case 'move': {\n const existing = await requireFile(overlay, action.previousPath);\n // The source leaves first, so a file may move beneath its own old path (a → a/b).\n await overlay.remove(action.previousPath);\n await requireFree(overlay, action.path);\n const sha =\n action.content === undefined ? existing.sha : await this.blob(action.content, action.encoding);\n await overlay.set(action.path, fileMode(existing), sha);\n return;\n }\n case 'chmod': {\n const existing = await requireFile(overlay, action.path);\n // A symbolic link has no executable bit; git records it as 120000 either way.\n if (existing.mode === '120000') return;\n const mode = action.executeFilemode ? '100755' : '100644';\n if (mode !== existing.mode) await overlay.set(action.path, mode, existing.sha);\n return;\n }\n }\n }\n}\n\n/** The mode of a file entry; callers have ruled out directories and submodules. */\nfunction fileMode(entry: GitTreeEntry): FileEntryMode {\n return entry.mode === '100755' || entry.mode === '120000' ? entry.mode : '100644';\n}\n\n/**\n * Applies commit actions to a tree with GitLab Commits API semantics (plus upsert), in order,\n * each to the result of the one before, reading only the directories along the paths the actions\n * name:\n *\n * - create: fails with path_exists if the path is a file or directory, path_conflict if a parent is a file;\n * - update: fails with path_not_found unless the path is a file; keeps its mode;\n * - upsert: creates or replaces (keeping the mode); path_exists for a directory, path_conflict for a file parent;\n * - delete: fails with path_not_found unless the path is a file; empty directories disappear;\n * - move: `previousPath` must be a file (path_not_found) and `path` free (path_exists / path_conflict) once\n * the source has left; keeps the mode and, without `content`, the blob;\n * - chmod: sets 100755 or 100644 on an existing file (path_not_found otherwise); symbolic links are left as they are.\n *\n * Content is UTF-8 text or base64. A result equal to the base tree is reported as `noop`.\n * Rule failures throw a contract GatewayError; nothing is returned partially applied.\n */\nexport async function applyCommitActions(\n input: ApplyActionsInput,\n reader: TreeReader,\n): Promise<ActionsResult> {\n const { tree, actions } = ApplyActionsInput.parse(input);\n const base = tree ?? EMPTY_TREE_SHA;\n const applier = new ActionApplier(new TreeOverlay(reader, tree));\n for (const action of actions) await applier.apply(action);\n const written = await applier.overlay.write();\n if (written.tree === base) return { status: 'noop', tree: base };\n const blobs = [...applier.blobs.values()].filter((blob) => written.referenced.has(blob.sha));\n return { status: 'changed', tree: written.tree, objects: [...blobs, ...written.objects] };\n}\n"],"mappings":";;;;;;;;AAcA,IAAM,gBAAN,MAAoB;CAGG;CAFrB,wBAAiB,IAAI,IAAuB;CAE5C,YAAY,SAA+B;EAAtB,KAAA,UAAA;CAAuB;CAE5C,MAAM,KAAK,SAAiB,UAA8C;EACxE,MAAM,SAAS,MAAM,aAAa,QAAQ,cAAc,SAAS,QAAQ,CAAC;EAC1E,KAAK,MAAM,IAAI,OAAO,KAAK,MAAM;EACjC,OAAO,OAAO;CAChB;CAEA,MAAM,MAAM,QAAqC;EAC/C,MAAM,EAAE,YAAY;EACpB,QAAQ,OAAO,QAAf;GACE,KAAK;IACH,MAAM,YAAY,SAAS,OAAO,IAAI;IACtC,MAAM,QAAQ,IAAI,OAAO,MAAM,UAAU,MAAM,KAAK,KAAK,OAAO,SAAS,OAAO,QAAQ,CAAC;IACzF;GACF,KAAK,UAAU;IACb,MAAM,WAAW,MAAM,YAAY,SAAS,OAAO,IAAI;IACvD,MAAM,QAAQ,IAAI,OAAO,MAAM,SAAS,QAAQ,GAAG,MAAM,KAAK,KAAK,OAAO,SAAS,OAAO,QAAQ,CAAC;IACnG;GACF;GACA,KAAK,UAAU;IACb,MAAM,QAAQ,MAAM,QAAQ,KAAK,OAAO,IAAI;IAC5C,MAAM,WAAW,MAAM,SAAS,UAAU,MAAM,MAAM,SAAS,WAAW,MAAM,QAAQ,KAAA;IACxF,IAAI,aAAa,KAAA,GAAW,MAAM,YAAY,SAAS,OAAO,IAAI;IAClE,MAAM,OAAO,aAAa,KAAA,IAAY,WAAW,SAAS,QAAQ;IAClE,MAAM,QAAQ,IAAI,OAAO,MAAM,MAAM,MAAM,KAAK,KAAK,OAAO,SAAS,OAAO,QAAQ,CAAC;IACrF;GACF;GACA,KAAK;IACH,MAAM,YAAY,SAAS,OAAO,IAAI;IACtC,MAAM,QAAQ,OAAO,OAAO,IAAI;IAChC;GACF,KAAK,QAAQ;IACX,MAAM,WAAW,MAAM,YAAY,SAAS,OAAO,YAAY;IAE/D,MAAM,QAAQ,OAAO,OAAO,YAAY;IACxC,MAAM,YAAY,SAAS,OAAO,IAAI;IACtC,MAAM,MACJ,OAAO,YAAY,KAAA,IAAY,SAAS,MAAM,MAAM,KAAK,KAAK,OAAO,SAAS,OAAO,QAAQ;IAC/F,MAAM,QAAQ,IAAI,OAAO,MAAM,SAAS,QAAQ,GAAG,GAAG;IACtD;GACF;GACA,KAAK,SAAS;IACZ,MAAM,WAAW,MAAM,YAAY,SAAS,OAAO,IAAI;IAEvD,IAAI,SAAS,SAAS,UAAU;IAChC,MAAM,OAAO,OAAO,kBAAkB,WAAW;IACjD,IAAI,SAAS,SAAS,MAAM,MAAM,QAAQ,IAAI,OAAO,MAAM,MAAM,SAAS,GAAG;IAC7E;GACF;EACF;CACF;AACF;;AAGA,SAAS,SAAS,OAAoC;CACpD,OAAO,MAAM,SAAS,YAAY,MAAM,SAAS,WAAW,MAAM,OAAO;AAC3E;;;;;;;;;;;;;;;;;AAkBA,eAAsB,mBACpB,OACA,QACwB;CACxB,MAAM,EAAE,MAAM,YAAY,kBAAkB,MAAM,KAAK;CACvD,MAAM,OAAO,QAAA;CACb,MAAM,UAAU,IAAI,cAAc,IAAI,YAAY,QAAQ,IAAI,CAAC;CAC/D,KAAK,MAAM,UAAU,SAAS,MAAM,QAAQ,MAAM,MAAM;CACxD,MAAM,UAAU,MAAM,QAAQ,QAAQ,MAAM;CAC5C,IAAI,QAAQ,SAAS,MAAM,OAAO;EAAE,QAAQ;EAAQ,MAAM;CAAK;CAC/D,MAAM,QAAQ,CAAC,GAAG,QAAQ,MAAM,OAAO,CAAC,CAAC,CAAC,QAAQ,SAAS,QAAQ,WAAW,IAAI,KAAK,GAAG,CAAC;CAC3F,OAAO;EAAE,QAAQ;EAAW,MAAM,QAAQ;EAAM,SAAS,CAAC,GAAG,OAAO,GAAG,QAAQ,OAAO;CAAE;AAC1F"}
|
package/dist/bytes.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** The bytes of several arrays, one after another. */
|
|
2
|
+
export declare function concatBytes(parts: readonly Uint8Array[]): Uint8Array;
|
|
3
|
+
/** The 20 raw bytes of a 40-character lowercase hex object id. */
|
|
4
|
+
export declare function hexToBytes(hex: string): Uint8Array;
|
|
5
|
+
/** Lowercase hex of some bytes. */
|
|
6
|
+
export declare function bytesToHex(bytes: Uint8Array): string;
|
|
7
|
+
/** The raw SHA-1 digest of some bytes, through Web Crypto (Bun, Node, Workers and browsers). */
|
|
8
|
+
export declare function sha1Bytes(bytes: Uint8Array): Promise<Uint8Array>;
|
|
9
|
+
/** Reads a whole byte stream into one array. */
|
|
10
|
+
export declare function readAllBytes(stream: ReadableStream<Uint8Array>): Promise<Uint8Array>;
|
|
11
|
+
/** A byte stream that yields the given chunks and ends. */
|
|
12
|
+
export declare function streamOf(...chunks: readonly Uint8Array[]): ReadableStream<Uint8Array>;
|
|
13
|
+
//# sourceMappingURL=bytes.d.ts.map
|
package/dist/bytes.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/bytes.ts
|
|
2
|
+
/** The bytes of several arrays, one after another. */
|
|
3
|
+
function concatBytes(parts) {
|
|
4
|
+
let length = 0;
|
|
5
|
+
for (const part of parts) length += part.length;
|
|
6
|
+
const out = new Uint8Array(length);
|
|
7
|
+
let offset = 0;
|
|
8
|
+
for (const part of parts) {
|
|
9
|
+
out.set(part, offset);
|
|
10
|
+
offset += part.length;
|
|
11
|
+
}
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
/** The 20 raw bytes of a 40-character lowercase hex object id. */
|
|
15
|
+
function hexToBytes(hex) {
|
|
16
|
+
const out = new Uint8Array(hex.length / 2);
|
|
17
|
+
for (let index = 0; index < out.length; index += 1) out[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
/** Lowercase hex of some bytes. */
|
|
21
|
+
function bytesToHex(bytes) {
|
|
22
|
+
let hex = "";
|
|
23
|
+
for (const byte of bytes) hex += byte.toString(16).padStart(2, "0");
|
|
24
|
+
return hex;
|
|
25
|
+
}
|
|
26
|
+
/** The raw SHA-1 digest of some bytes, through Web Crypto (Bun, Node, Workers and browsers). */
|
|
27
|
+
async function sha1Bytes(bytes) {
|
|
28
|
+
return new Uint8Array(await crypto.subtle.digest("SHA-1", bytes));
|
|
29
|
+
}
|
|
30
|
+
/** Reads a whole byte stream into one array. */
|
|
31
|
+
async function readAllBytes(stream) {
|
|
32
|
+
const chunks = [];
|
|
33
|
+
const reader = stream.getReader();
|
|
34
|
+
for (let next = await reader.read(); !next.done; next = await reader.read()) chunks.push(next.value);
|
|
35
|
+
return concatBytes(chunks);
|
|
36
|
+
}
|
|
37
|
+
/** A byte stream that yields the given chunks and ends. */
|
|
38
|
+
function streamOf(...chunks) {
|
|
39
|
+
let index = 0;
|
|
40
|
+
return new ReadableStream({ pull(controller) {
|
|
41
|
+
const chunk = chunks[index];
|
|
42
|
+
index += 1;
|
|
43
|
+
if (chunk === void 0) controller.close();
|
|
44
|
+
else controller.enqueue(chunk);
|
|
45
|
+
} });
|
|
46
|
+
}
|
|
47
|
+
export { bytesToHex, concatBytes, hexToBytes, readAllBytes, sha1Bytes, streamOf };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.js","names":[],"sources":["../src/bytes.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/** The bytes of several arrays, one after another. */\nexport function concatBytes(parts: readonly Uint8Array[]): Uint8Array {\n let length = 0;\n for (const part of parts) length += part.length;\n const out = new Uint8Array(length);\n let offset = 0;\n for (const part of parts) {\n out.set(part, offset);\n offset += part.length;\n }\n return out;\n}\n\n/** The 20 raw bytes of a 40-character lowercase hex object id. */\nexport function hexToBytes(hex: string): Uint8Array {\n const out = new Uint8Array(hex.length / 2);\n for (let index = 0; index < out.length; index += 1) {\n out[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);\n }\n return out;\n}\n\n/** Lowercase hex of some bytes. */\nexport function bytesToHex(bytes: Uint8Array): string {\n let hex = '';\n for (const byte of bytes) hex += byte.toString(16).padStart(2, '0');\n return hex;\n}\n\n/** The raw SHA-1 digest of some bytes, through Web Crypto (Bun, Node, Workers and browsers). */\nexport async function sha1Bytes(bytes: Uint8Array): Promise<Uint8Array> {\n return new Uint8Array(await crypto.subtle.digest('SHA-1', bytes));\n}\n\n/** Reads a whole byte stream into one array. */\nexport async function readAllBytes(stream: ReadableStream<Uint8Array>): Promise<Uint8Array> {\n const chunks: Uint8Array[] = [];\n const reader = stream.getReader();\n for (let next = await reader.read(); !next.done; next = await reader.read()) chunks.push(next.value);\n return concatBytes(chunks);\n}\n\n/** A byte stream that yields the given chunks and ends. */\nexport function streamOf(...chunks: readonly Uint8Array[]): ReadableStream<Uint8Array> {\n let index = 0;\n return new ReadableStream<Uint8Array>({\n pull(controller) {\n const chunk = chunks[index];\n index += 1;\n if (chunk === undefined) controller.close();\n else controller.enqueue(chunk);\n },\n });\n}\n"],"mappings":";;AAGA,SAAgB,YAAY,OAA0C;CACpE,IAAI,SAAS;CACb,KAAK,MAAM,QAAQ,OAAO,UAAU,KAAK;CACzC,MAAM,MAAM,IAAI,WAAW,MAAM;CACjC,IAAI,SAAS;CACb,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,IAAI,MAAM,MAAM;EACpB,UAAU,KAAK;CACjB;CACA,OAAO;AACT;;AAGA,SAAgB,WAAW,KAAyB;CAClD,MAAM,MAAM,IAAI,WAAW,IAAI,SAAS,CAAC;CACzC,KAAK,IAAI,QAAQ,GAAG,QAAQ,IAAI,QAAQ,SAAS,GAC/C,IAAI,SAAS,OAAO,SAAS,IAAI,MAAM,QAAQ,GAAG,QAAQ,IAAI,CAAC,GAAG,EAAE;CAEtE,OAAO;AACT;;AAGA,SAAgB,WAAW,OAA2B;CACpD,IAAI,MAAM;CACV,KAAK,MAAM,QAAQ,OAAO,OAAO,KAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG;CAClE,OAAO;AACT;;AAGA,eAAsB,UAAU,OAAwC;CACtE,OAAO,IAAI,WAAW,MAAM,OAAO,OAAO,OAAO,SAAS,KAAK,CAAC;AAClE;;AAGA,eAAsB,aAAa,QAAyD;CAC1F,MAAM,SAAuB,CAAC;CAC9B,MAAM,SAAS,OAAO,UAAU;CAChC,KAAK,IAAI,OAAO,MAAM,OAAO,KAAK,GAAG,CAAC,KAAK,MAAM,OAAO,MAAM,OAAO,KAAK,GAAG,OAAO,KAAK,KAAK,KAAK;CACnG,OAAO,YAAY,MAAM;AAC3B;;AAGA,SAAgB,SAAS,GAAG,QAA2D;CACrF,IAAI,QAAQ;CACZ,OAAO,IAAI,eAA2B,EACpC,KAAK,YAAY;EACf,MAAM,QAAQ,OAAO;EACrB,SAAS;EACT,IAAI,UAAU,KAAA,GAAW,WAAW,MAAM;OACrC,WAAW,QAAQ,KAAK;CAC/B,EACF,CAAC;AACH"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BuildCommitInput, BuiltCommit } from "../schemas/build-commit.js";
|
|
2
|
+
import { n as TreeReader } from "../tree-reader-CK9ScndQ.js";
|
|
3
|
+
/**
|
|
4
|
+
* Builds a commit from actions without a clone: applies the actions to the base commit's tree
|
|
5
|
+
* (reading only the directories they touch), then writes a commit whose parent is the base, with
|
|
6
|
+
* the caller's author, committer and message and a "Gateway-Idempotency-Key:" trailer appended.
|
|
7
|
+
*
|
|
8
|
+
* Returns `noop` when the actions leave the tree unchanged; otherwise the commit, the objects to
|
|
9
|
+
* pack (new blobs, new trees, then the commit) and the ref update naming the old head, so the
|
|
10
|
+
* server refuses the push if the branch moved in the meantime. Rule failures throw a contract
|
|
11
|
+
* GatewayError; nothing is written either way.
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildCommit(input: BuildCommitInput, reader: TreeReader): Promise<BuiltCommit>;
|
|
14
|
+
//# sourceMappingURL=build-commit.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { applyCommitActions } from "../actions/apply-commit-actions.js";
|
|
2
|
+
import { createCommit } from "../objects/commit-object.js";
|
|
3
|
+
import { BuildCommitInput } from "../schemas/build-commit.js";
|
|
4
|
+
import { ZERO_SHA } from "@leed-ai/git-gateway-contract/schemas/sha";
|
|
5
|
+
import { appendIdempotencyTrailer } from "@leed-ai/git-gateway-contract/reference/trailer";
|
|
6
|
+
// src/commit/build-commit.ts
|
|
7
|
+
/**
|
|
8
|
+
* Builds a commit from actions without a clone: applies the actions to the base commit's tree
|
|
9
|
+
* (reading only the directories they touch), then writes a commit whose parent is the base, with
|
|
10
|
+
* the caller's author, committer and message and a "Gateway-Idempotency-Key:" trailer appended.
|
|
11
|
+
*
|
|
12
|
+
* Returns `noop` when the actions leave the tree unchanged; otherwise the commit, the objects to
|
|
13
|
+
* pack (new blobs, new trees, then the commit) and the ref update naming the old head, so the
|
|
14
|
+
* server refuses the push if the branch moved in the meantime. Rule failures throw a contract
|
|
15
|
+
* GatewayError; nothing is written either way.
|
|
16
|
+
*/
|
|
17
|
+
async function buildCommit(input, reader) {
|
|
18
|
+
const parsed = BuildCommitInput.parse(input);
|
|
19
|
+
const { base } = parsed;
|
|
20
|
+
const applied = await applyCommitActions({
|
|
21
|
+
tree: base?.tree ?? null,
|
|
22
|
+
actions: parsed.actions
|
|
23
|
+
}, reader);
|
|
24
|
+
if (applied.status === "noop") return {
|
|
25
|
+
status: "noop",
|
|
26
|
+
head: base?.sha ?? null
|
|
27
|
+
};
|
|
28
|
+
const author = {
|
|
29
|
+
...parsed.author,
|
|
30
|
+
date: parsed.date
|
|
31
|
+
};
|
|
32
|
+
const committer = {
|
|
33
|
+
...parsed.committer ?? parsed.author,
|
|
34
|
+
date: parsed.date
|
|
35
|
+
};
|
|
36
|
+
const { object, commit } = await createCommit({
|
|
37
|
+
tree: applied.tree,
|
|
38
|
+
parents: base === null ? [] : [base.sha],
|
|
39
|
+
author,
|
|
40
|
+
committer,
|
|
41
|
+
message: appendIdempotencyTrailer(parsed.message, parsed.idempotencyKey)
|
|
42
|
+
});
|
|
43
|
+
const oldSha = (parsed.oldSha === void 0 ? base?.sha : parsed.oldSha) ?? ZERO_SHA;
|
|
44
|
+
return {
|
|
45
|
+
status: "ready",
|
|
46
|
+
commit,
|
|
47
|
+
refUpdate: {
|
|
48
|
+
ref: `refs/heads/${parsed.branch}`,
|
|
49
|
+
oldSha,
|
|
50
|
+
newSha: commit.sha
|
|
51
|
+
},
|
|
52
|
+
objects: [...applied.objects, object]
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export { buildCommit };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=build-commit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-commit.js","names":[],"sources":["../../src/commit/build-commit.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { appendIdempotencyTrailer } from '@leed-ai/git-gateway-contract/reference/trailer';\nimport { ZERO_SHA } from '@leed-ai/git-gateway-contract/schemas/sha';\n\nimport { applyCommitActions } from '../actions/apply-commit-actions.ts';\nimport { createCommit } from '../objects/commit-object.ts';\nimport { BuildCommitInput, type BuiltCommit } from '../schemas/build-commit.ts';\nimport type { TreeReader } from '../tree/tree-reader.ts';\n\n/**\n * Builds a commit from actions without a clone: applies the actions to the base commit's tree\n * (reading only the directories they touch), then writes a commit whose parent is the base, with\n * the caller's author, committer and message and a \"Gateway-Idempotency-Key:\" trailer appended.\n *\n * Returns `noop` when the actions leave the tree unchanged; otherwise the commit, the objects to\n * pack (new blobs, new trees, then the commit) and the ref update naming the old head, so the\n * server refuses the push if the branch moved in the meantime. Rule failures throw a contract\n * GatewayError; nothing is written either way.\n */\nexport async function buildCommit(input: BuildCommitInput, reader: TreeReader): Promise<BuiltCommit> {\n const parsed = BuildCommitInput.parse(input);\n const { base } = parsed;\n const applied = await applyCommitActions({ tree: base?.tree ?? null, actions: parsed.actions }, reader);\n if (applied.status === 'noop') return { status: 'noop', head: base?.sha ?? null };\n const author = { ...parsed.author, date: parsed.date };\n const committer = { ...(parsed.committer ?? parsed.author), date: parsed.date };\n const { object, commit } = await createCommit({\n tree: applied.tree,\n parents: base === null ? [] : [base.sha],\n author,\n committer,\n message: appendIdempotencyTrailer(parsed.message, parsed.idempotencyKey),\n });\n const oldSha = (parsed.oldSha === undefined ? base?.sha : parsed.oldSha) ?? ZERO_SHA;\n return {\n status: 'ready',\n commit,\n refUpdate: { ref: `refs/heads/${parsed.branch}`, oldSha, newSha: commit.sha },\n objects: [...applied.objects, object],\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,eAAsB,YAAY,OAAyB,QAA0C;CACnG,MAAM,SAAS,iBAAiB,MAAM,KAAK;CAC3C,MAAM,EAAE,SAAS;CACjB,MAAM,UAAU,MAAM,mBAAmB;EAAE,MAAM,MAAM,QAAQ;EAAM,SAAS,OAAO;CAAQ,GAAG,MAAM;CACtG,IAAI,QAAQ,WAAW,QAAQ,OAAO;EAAE,QAAQ;EAAQ,MAAM,MAAM,OAAO;CAAK;CAChF,MAAM,SAAS;EAAE,GAAG,OAAO;EAAQ,MAAM,OAAO;CAAK;CACrD,MAAM,YAAY;EAAE,GAAI,OAAO,aAAa,OAAO;EAAS,MAAM,OAAO;CAAK;CAC9E,MAAM,EAAE,QAAQ,WAAW,MAAM,aAAa;EAC5C,MAAM,QAAQ;EACd,SAAS,SAAS,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG;EACvC;EACA;EACA,SAAS,yBAAyB,OAAO,SAAS,OAAO,cAAc;CACzE,CAAC;CACD,MAAM,UAAU,OAAO,WAAW,KAAA,IAAY,MAAM,MAAM,OAAO,WAAW;CAC5E,OAAO;EACL,QAAQ;EACR;EACA,WAAW;GAAE,KAAK,cAAc,OAAO;GAAU;GAAQ,QAAQ,OAAO;EAAI;EAC5E,SAAS,CAAC,GAAG,QAAQ,SAAS,MAAM;CACtC;AACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CoreErrorBody, CoreErrorCode } from "./schemas/core-error-body.js";
|
|
2
|
+
/** The body of the core error with a given code. */
|
|
3
|
+
export type CoreErrorOf<C extends CoreErrorCode> = Extract<CoreErrorBody, {
|
|
4
|
+
code: C;
|
|
5
|
+
}>;
|
|
6
|
+
/** The error the core library throws for protocol and object problems; `body` is a {@link CoreErrorBody}. */
|
|
7
|
+
export declare class CoreError<C extends CoreErrorCode = CoreErrorCode> extends Error {
|
|
8
|
+
readonly name = "CoreError";
|
|
9
|
+
readonly body: CoreErrorOf<C>;
|
|
10
|
+
constructor(body: CoreErrorOf<C>);
|
|
11
|
+
/** The error's code. */
|
|
12
|
+
get code(): C;
|
|
13
|
+
}
|
|
14
|
+
/** Builds a {@link CoreError} from a code, message and details, validating them against the schema. */
|
|
15
|
+
export declare function coreError<C extends CoreErrorCode>(code: C, message: string, details: CoreErrorOf<C>['details']): CoreError;
|
|
16
|
+
/** True when `thrown` is a {@link CoreError}, and has `code` when one is given. */
|
|
17
|
+
export declare function isCoreError(thrown: unknown, code?: CoreErrorCode): thrown is CoreError;
|
|
18
|
+
//# sourceMappingURL=core-error.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CoreErrorBody } from "./schemas/core-error-body.js";
|
|
2
|
+
// src/core-error.ts
|
|
3
|
+
/** The error the core library throws for protocol and object problems; `body` is a {@link CoreErrorBody}. */
|
|
4
|
+
var CoreError = class extends Error {
|
|
5
|
+
name = "CoreError";
|
|
6
|
+
body;
|
|
7
|
+
constructor(body) {
|
|
8
|
+
super(body.message);
|
|
9
|
+
this.body = body;
|
|
10
|
+
}
|
|
11
|
+
/** The error's code. */
|
|
12
|
+
get code() {
|
|
13
|
+
return this.body.code;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/** Builds a {@link CoreError} from a code, message and details, validating them against the schema. */
|
|
17
|
+
function coreError(code, message, details) {
|
|
18
|
+
return new CoreError(CoreErrorBody.parse({
|
|
19
|
+
code,
|
|
20
|
+
message,
|
|
21
|
+
details
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
/** True when `thrown` is a {@link CoreError}, and has `code` when one is given. */
|
|
25
|
+
function isCoreError(thrown, code) {
|
|
26
|
+
return thrown instanceof CoreError && (code === void 0 || thrown.code === code);
|
|
27
|
+
}
|
|
28
|
+
export { CoreError, coreError, isCoreError };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=core-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-error.js","names":[],"sources":["../src/core-error.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { CoreErrorBody, type CoreErrorCode } from './schemas/core-error-body.ts';\n\n/** The body of the core error with a given code. */\nexport type CoreErrorOf<C extends CoreErrorCode> = Extract<CoreErrorBody, { code: C }>;\n\n/** The error the core library throws for protocol and object problems; `body` is a {@link CoreErrorBody}. */\nexport class CoreError<C extends CoreErrorCode = CoreErrorCode> extends Error {\n override readonly name = 'CoreError';\n readonly body: CoreErrorOf<C>;\n\n constructor(body: CoreErrorOf<C>) {\n super(body.message);\n this.body = body;\n }\n\n /** The error's code. */\n get code(): C {\n return this.body.code;\n }\n}\n\n/** Builds a {@link CoreError} from a code, message and details, validating them against the schema. */\nexport function coreError<C extends CoreErrorCode>(\n code: C,\n message: string,\n details: CoreErrorOf<C>['details'],\n): CoreError {\n return new CoreError(CoreErrorBody.parse({ code, message, details }));\n}\n\n/** True when `thrown` is a {@link CoreError}, and has `code` when one is given. */\nexport function isCoreError(thrown: unknown, code?: CoreErrorCode): thrown is CoreError {\n return thrown instanceof CoreError && (code === undefined || thrown.code === code);\n}\n"],"mappings":";;;AAOA,IAAa,YAAb,cAAwE,MAAM;CAC5E,OAAyB;CACzB;CAEA,YAAY,MAAsB;EAChC,MAAM,KAAK,OAAO;EAClB,KAAK,OAAO;CACd;;CAGA,IAAI,OAAU;EACZ,OAAO,KAAK,KAAK;CACnB;AACF;;AAGA,SAAgB,UACd,MACA,SACA,SACW;CACX,OAAO,IAAI,UAAU,cAAc,MAAM;EAAE;EAAM;EAAS;CAAQ,CAAC,CAAC;AACtE;;AAGA,SAAgB,YAAY,QAAiB,MAA2C;CACtF,OAAO,kBAAkB,cAAc,SAAS,KAAA,KAAa,OAAO,SAAS;AAC/E"}
|