@yaks/git 0.0.0-stage → 0.2.36

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.
Files changed (183) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +754 -2
  3. package/_dist/address.d.ts +6 -0
  4. package/_dist/address.d.ts.map +1 -0
  5. package/_dist/checkout_vocab.d.ts +3 -0
  6. package/_dist/checkout_vocab.d.ts.map +1 -0
  7. package/_dist/cites.d.ts +48 -0
  8. package/_dist/cites.d.ts.map +1 -0
  9. package/_dist/commit.d.ts +36 -0
  10. package/_dist/commit.d.ts.map +1 -0
  11. package/_dist/comp.d.ts +29 -0
  12. package/_dist/comp.d.ts.map +1 -0
  13. package/_dist/door.d.ts +29 -0
  14. package/_dist/door.d.ts.map +1 -0
  15. package/_dist/format.d.ts +2 -0
  16. package/_dist/format.d.ts.map +1 -0
  17. package/_dist/hold.d.ts +6 -0
  18. package/_dist/hold.d.ts.map +1 -0
  19. package/_dist/host.d.ts +126 -0
  20. package/_dist/host.d.ts.map +1 -0
  21. package/_dist/http.d.ts +33 -0
  22. package/_dist/http.d.ts.map +1 -0
  23. package/_dist/import.d.ts +13 -0
  24. package/_dist/import.d.ts.map +1 -0
  25. package/_dist/index.d.ts +80 -0
  26. package/_dist/index.d.ts.map +1 -0
  27. package/_dist/land.d.ts +77 -0
  28. package/_dist/land.d.ts.map +1 -0
  29. package/_dist/mod.d.ts +73 -0
  30. package/_dist/mod.d.ts.map +1 -0
  31. package/_dist/objects.d.ts +40 -0
  32. package/_dist/objects.d.ts.map +1 -0
  33. package/_dist/oid.d.ts +24 -0
  34. package/_dist/oid.d.ts.map +1 -0
  35. package/_dist/pack-store.d.ts +9 -0
  36. package/_dist/pack-store.d.ts.map +1 -0
  37. package/_dist/pack.d.ts +26 -0
  38. package/_dist/pack.d.ts.map +1 -0
  39. package/_dist/pkt.d.ts +14 -0
  40. package/_dist/pkt.d.ts.map +1 -0
  41. package/_dist/placement.d.ts +4 -0
  42. package/_dist/placement.d.ts.map +1 -0
  43. package/_dist/plugin.d.ts +43 -0
  44. package/_dist/plugin.d.ts.map +1 -0
  45. package/_dist/project.d.ts +20 -0
  46. package/_dist/project.d.ts.map +1 -0
  47. package/_dist/push.d.ts +42 -0
  48. package/_dist/push.d.ts.map +1 -0
  49. package/_dist/refs.d.ts +81 -0
  50. package/_dist/refs.d.ts.map +1 -0
  51. package/_dist/rewrite.d.ts +35 -0
  52. package/_dist/rewrite.d.ts.map +1 -0
  53. package/_dist/service.d.ts +35 -0
  54. package/_dist/service.d.ts.map +1 -0
  55. package/_dist/sha1.d.ts +11 -0
  56. package/_dist/sha1.d.ts.map +1 -0
  57. package/_dist/source.d.ts +12 -0
  58. package/_dist/source.d.ts.map +1 -0
  59. package/_dist/tools.d.ts +11 -0
  60. package/_dist/tools.d.ts.map +1 -0
  61. package/_dist/tree.d.ts +28 -0
  62. package/_dist/tree.d.ts.map +1 -0
  63. package/_dist/unpack.d.ts +5 -0
  64. package/_dist/unpack.d.ts.map +1 -0
  65. package/_dist/vocab.d.ts +8 -0
  66. package/_dist/vocab.d.ts.map +1 -0
  67. package/_dist/workspace.d.ts +17 -0
  68. package/_dist/workspace.d.ts.map +1 -0
  69. package/address.js +9 -0
  70. package/address.js.map +1 -0
  71. package/address.ts +15 -0
  72. package/cache.js +9 -0
  73. package/cache.js.map +1 -0
  74. package/cache.ts +6 -0
  75. package/checkout.js +18 -0
  76. package/checkout.js.map +1 -0
  77. package/checkout.ts +24 -0
  78. package/checkout_vocab.js +14 -0
  79. package/checkout_vocab.js.map +1 -0
  80. package/checkout_vocab.ts +11 -0
  81. package/cites.js +189 -0
  82. package/cites.js.map +1 -0
  83. package/cites.ts +206 -0
  84. package/commit.js +128 -0
  85. package/commit.js.map +1 -0
  86. package/commit.ts +183 -0
  87. package/comp.js +94 -0
  88. package/comp.js.map +1 -0
  89. package/comp.ts +111 -0
  90. package/deno.json +1 -0
  91. package/door.js +88 -0
  92. package/door.js.map +1 -0
  93. package/door.ts +142 -0
  94. package/format.js +43 -0
  95. package/format.js.map +1 -0
  96. package/format.ts +49 -0
  97. package/hold.js +17 -0
  98. package/hold.js.map +1 -0
  99. package/hold.ts +21 -0
  100. package/host.js +1024 -0
  101. package/host.js.map +1 -0
  102. package/host.ts +1140 -0
  103. package/http.js +268 -0
  104. package/http.js.map +1 -0
  105. package/http.ts +329 -0
  106. package/import.js +141 -0
  107. package/import.js.map +1 -0
  108. package/import.ts +128 -0
  109. package/index.js +496 -0
  110. package/index.js.map +1 -0
  111. package/index.ts +634 -0
  112. package/land.js +788 -0
  113. package/land.js.map +1 -0
  114. package/land.ts +871 -0
  115. package/mod.js +73 -0
  116. package/mod.js.map +1 -0
  117. package/mod.ts +74 -0
  118. package/objects.js +331 -0
  119. package/objects.js.map +1 -0
  120. package/objects.ts +390 -0
  121. package/oid.js +50 -0
  122. package/oid.js.map +1 -0
  123. package/oid.ts +83 -0
  124. package/pack-index.js +103 -0
  125. package/pack-index.js.map +1 -0
  126. package/pack-index.ts +104 -0
  127. package/pack-store.js +216 -0
  128. package/pack-store.js.map +1 -0
  129. package/pack-store.ts +292 -0
  130. package/pack.js +121 -0
  131. package/pack.js.map +1 -0
  132. package/pack.ts +146 -0
  133. package/package.json +78 -4
  134. package/pkt.js +73 -0
  135. package/pkt.js.map +1 -0
  136. package/pkt.ts +93 -0
  137. package/placement.js +44 -0
  138. package/placement.js.map +1 -0
  139. package/placement.ts +38 -0
  140. package/plugin.js +66 -0
  141. package/plugin.js.map +1 -0
  142. package/plugin.ts +88 -0
  143. package/process-cwd.py +57 -0
  144. package/project.js +142 -0
  145. package/project.js.map +1 -0
  146. package/project.ts +151 -0
  147. package/push.js +401 -0
  148. package/push.js.map +1 -0
  149. package/push.ts +451 -0
  150. package/refs.js +176 -0
  151. package/refs.js.map +1 -0
  152. package/refs.ts +285 -0
  153. package/rewrite.js +176 -0
  154. package/rewrite.js.map +1 -0
  155. package/rewrite.ts +173 -0
  156. package/service.js +104 -0
  157. package/service.js.map +1 -0
  158. package/service.ts +194 -0
  159. package/sha1.js +115 -0
  160. package/sha1.js.map +1 -0
  161. package/sha1.ts +146 -0
  162. package/source.js +100 -0
  163. package/source.js.map +1 -0
  164. package/source.ts +116 -0
  165. package/spare.js +108 -0
  166. package/spare.js.map +1 -0
  167. package/spare.ts +94 -0
  168. package/tools.js +278 -0
  169. package/tools.js.map +1 -0
  170. package/tools.ts +310 -0
  171. package/tree.js +105 -0
  172. package/tree.js.map +1 -0
  173. package/tree.ts +132 -0
  174. package/unpack.js +207 -0
  175. package/unpack.js.map +1 -0
  176. package/unpack.ts +210 -0
  177. package/vocab.js +20 -0
  178. package/vocab.js.map +1 -0
  179. package/vocab.json +386 -0
  180. package/vocab.ts +22 -0
  181. package/workspace.js +449 -0
  182. package/workspace.js.map +1 -0
  183. package/workspace.ts +445 -0
package/door.ts ADDED
@@ -0,0 +1,142 @@
1
+ // A repository's door: what a clone or a fetch at a repository's address is
2
+ // answered with, over repositories its host finds by name. The wire is
3
+ // ./http.ts; this decides which address is which door, how a clone is asked
4
+ // for its credential, and what it hears when it is not getting one. Where the
5
+ // refs and the objects are kept, and who may read them, are the host's.
6
+ //
7
+ // A repository is `<name>.git`, and smart HTTP knocks on two addresses under
8
+ // it (`DOORS`). A name holds no dot of its own, so the split is unambiguous.
9
+ // A clone of `<name>/`, the address a browser shows, asks for the
10
+ // advertisement there (`BARE`) and is sent to `<name>.git` by a 301, which git
11
+ // follows and posts its fetch to where it landed
12
+ // (`http.followRedirects=initial`, git's default since 2.11). So the detector
13
+ // is the query, never the user agent: `?service=git-upload-pack` is something
14
+ // no browser asks for, and a site that serves a static `info/refs` serves it
15
+ // to a browser as before.
16
+ //
17
+ // A clone has to be asked for its credential: git sends none unprompted, so a
18
+ // private repository that said 404 would be a 404 to its own owner. So a
19
+ // repository the request may not read answers `401 WWW-Authenticate: Basic`
20
+ // while nobody has proved anything, and git comes back with a password. Once
21
+ // somebody has, the answer is 403, which is terminal: 401 would send git
22
+ // round to ask for the password they already gave correctly. A repository
23
+ // the host does not find is 404 to everyone, credential or not.
24
+ import { advertise, type Refs, SERVICE, uploadPack } from './http.js'
25
+ import type { Objects } from './objects.ts'
26
+ import { RECEIVE } from './http.js'
27
+ import { BARE, DOORS } from './address.js'
28
+ import type { Receiver } from './push.js'
29
+
30
+ export { BARE, DOORS, knocks } from './address.js'
31
+
32
+ /** A repository a request may be answered from: its refs and its objects. */
33
+ export type Repository = { refs: Refs; objects: Objects }
34
+
35
+ /** A repository as its host found it for one request. */
36
+ export type Found = Repository & {
37
+ /** whether this request may read it */
38
+ reads: boolean
39
+ /** whether the request proved who sent it, which makes a refusal final */
40
+ proven: boolean
41
+ receive?: Receiver
42
+ }
43
+
44
+ /** What a door is given by its host. */
45
+ export type Host = {
46
+ /** The repository called `name`, as `req` may see it, or null where there
47
+ * is none. `password` is what a Basic credential carried, the one scheme
48
+ * git offers once challenged; null where the request carried none. */
49
+ find: (
50
+ name: string,
51
+ req: Request,
52
+ password: string | null,
53
+ ) => Promise<Found | null>
54
+ /** what git prints above its password prompt */
55
+ realm: string
56
+ failed?: (reason: unknown) => void
57
+ /** Keeps `work` running after the answer is sent (a Worker's
58
+ * `waitUntil`), and hears its failure: what a push will read, read while
59
+ * its client packs. */
60
+ hold?: (work: Promise<void>) => void
61
+ }
62
+
63
+ // What a clone hears when it is not getting one. Plain text, because the
64
+ // thing reading it is git and not a browser.
65
+ let refusal = (status: number, say: string, more: HeadersInit = {}) =>
66
+ new Response(`git: ${say}\n`, {
67
+ status,
68
+ headers: { 'content-type': 'text/plain; charset=utf-8', ...more },
69
+ })
70
+
71
+ /// password(new Request('http://x', { headers: { authorization: 'Basic ' + btoa('x:tok') } })) -> 'tok'
72
+ /// password(new Request('http://x', { headers: { authorization: 'Basic ' + btoa('x:') } })) -> null
73
+ /// password(new Request('http://x', { headers: { authorization: 'Bearer tok' } })) -> null
74
+ /// password(new Request('http://x')) -> null
75
+ /** The password of a request's Basic credential. Its username is whatever
76
+ * the person typed in front of it, which a token that says whose it is makes
77
+ * decoration. */
78
+ export let password = (req: Request): string | null => {
79
+ let said = /^Basic +(\S+)$/i.exec(req.headers.get('authorization') ?? '')
80
+ if (!said) return null
81
+ let pair
82
+ try {
83
+ pair = atob(said[1])
84
+ } catch {
85
+ return null
86
+ }
87
+ let colon = pair.indexOf(':')
88
+ return colon < 0 ? null : pair.slice(colon + 1) || null
89
+ }
90
+
91
+ // The browser's address, sent to the repository's own with its query.
92
+ let redirect = (req: Request, path: string): Response | null => {
93
+ let bare = BARE.exec(path)
94
+ let url = new URL(req.url)
95
+ if (req.method != 'GET' || !bare) return null
96
+ if (url.searchParams.get('service') != SERVICE) return null
97
+ url.pathname = `/${bare[1]}.git/info/refs`
98
+ return Response.redirect(url, 301)
99
+ }
100
+
101
+ /** The door: a `Response` for a repository's address, `null` for any other,
102
+ * which its host answers as it would without one. */
103
+ export let door =
104
+ (host: Host) => async (req: Request): Promise<Response | null> => {
105
+ let path = new URL(req.url).pathname
106
+ let asked = DOORS.exec(path)
107
+ if (!asked) return redirect(req, path)
108
+ let [, name, at] = asked
109
+ let found = await host.find(name, req, password(req))
110
+ if (!found) return refusal(404, 'no such repository')
111
+ let pushing = at == RECEIVE || at == 'info/refs' &&
112
+ new URL(req.url).searchParams.get('service') == RECEIVE
113
+ if (!found.reads) {
114
+ return found.proven ? refusal(403, 'not your repository') : refusal(
115
+ 401,
116
+ pushing
117
+ ? 'sign in to push to this repository'
118
+ : 'sign in to clone this repository',
119
+ {
120
+ 'www-authenticate': `Basic realm="${host.realm}"`,
121
+ },
122
+ )
123
+ }
124
+ if (pushing && found.receive) {
125
+ let { advertiseReceive, receivePack, warm } = await import('./push.js')
126
+ let hold = host.hold
127
+ return at == 'info/refs'
128
+ ? req.method == 'GET'
129
+ ? advertiseReceive(
130
+ found.refs,
131
+ hold && ((refs) => hold(warm(refs, found.objects))),
132
+ )
133
+ : refusal(405, 'use GET')
134
+ : receivePack(req, found.refs, found.objects, found.receive)
135
+ }
136
+ if (at == RECEIVE) {
137
+ return refusal(403, 'push is unavailable for this repository')
138
+ }
139
+ return at == 'info/refs'
140
+ ? advertise(req)
141
+ : uploadPack(req, found.refs, found.objects, host.failed)
142
+ }
package/format.js ADDED
@@ -0,0 +1,43 @@
1
+ // Deno's explicit file arguments override configuration exclusions unless the
2
+ // exclusions are supplied through --ignore. Deno retains ownership of glob
3
+ // matching, file-type support and all formatting options. A checkout without
4
+ // a Deno config never chose Deno's formatter, so it is not formatted: Deno's
5
+ // defaults would rewrite a Rails app's Markdown and YAML it never authored.
6
+ import { parse } from "@jsr/std__jsonc";
7
+ import * as disk from "@yaks/file/io";
8
+ let object = (value)=>value != null && typeof value == 'object' && !Array.isArray(value);
9
+ let paths = (value)=>Array.isArray(value) ? value.filter((path)=>typeof path == 'string') : [];
10
+ export let formatting = (files, config, file = 'deno.json')=>{
11
+ let root = object(config) ? config : {};
12
+ let fmt = object(root.fmt) ? root.fmt : {};
13
+ return [
14
+ 'fmt',
15
+ '--config',
16
+ file,
17
+ '--permit-no-files',
18
+ ...[
19
+ ...new Set([
20
+ ...paths(root.exclude),
21
+ ...paths(fmt.exclude)
22
+ ])
23
+ ].map((path)=>'--ignore=' + path),
24
+ ...files
25
+ ];
26
+ };
27
+ let read = (path)=>disk.readTextFile(path).catch((e)=>{
28
+ if (disk.isNotFound(e)) return undefined;
29
+ throw e;
30
+ });
31
+ /** The checkout's Deno config, or undefined when it has none. */ export let formatConfig = async (cwd, source = read)=>{
32
+ for (let file of [
33
+ 'deno.json',
34
+ 'deno.jsonc'
35
+ ]){
36
+ let text = await source(disk.join(cwd, file));
37
+ if (text != null) return {
38
+ file,
39
+ config: parse(text) ?? {}
40
+ };
41
+ }
42
+ };
43
+ //# sourceMappingURL=format.js.map
package/format.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sources":["./format.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,2EAA2E;AAC3E,6EAA6E;AAC7E,6EAA6E;AAC7E,4EAA4E;AAC5E,SAAS,KAAK,0BAA8B;AAC5C,YAAY,+BAAoC;AAEhD,IAAI,SAAS,CAAC,QACZ,SAAS,QAAQ,OAAO,SAAS,YAAY,CAAC,MAAM,OAAO,CAAC;AAC9D,IAAI,QAAQ,CAAC,QACX,MAAM,OAAO,CAAC,SACV,MAAM,MAAM,CAAC,CAAC,OAAyB,OAAO,QAAQ,YACtD,EAAE;AAER,OAAO,IAAI,aAAa,CACtB,OACA,QACA,OAAO,WAAW;EAElB,IAAI,OAAO,OAAO,UAAU,SAAS,CAAC;EACtC,IAAI,MAAM,OAAO,KAAK,GAAG,IAAI,KAAK,GAAG,GAAG,CAAC;EACzC,OAAO;IACL;IACA;IACA;IACA;OACG;SAAI,IAAI,IAAI;WAAI,MAAM,KAAK,OAAO;WAAM,MAAM,IAAI,OAAO;OAAE;KAAE,CAC7D,GAAG,CAAC,CAAC,OAAS,cAAc;OAC5B;GACJ;AACH,EAAC;AAED,IAAI,OAAO,CAAC,OACV,KAAK,YAAY,CAAC,MAAM,KAAK,CAAC,CAAC;IAC7B,IAAI,KAAK,UAAU,CAAC,IAAI,OAAO;IAC/B,MAAM;EACR;AAEF,+DAA+D,GAC/D,OAAO,IAAI,eAAe,OACxB,KACA,SAAwD,IAAI;EAE5D,KAAK,IAAI,QAAQ;IAAC;IAAa;GAAa,CAAE;IAC5C,IAAI,OAAO,MAAM,OAAO,KAAK,IAAI,CAAC,KAAK;IACvC,IAAI,QAAQ,MAAM,OAAO;MAAE;MAAM,QAAQ,MAAM,SAAS,CAAC;IAAE;EAC7D;AACF,EAAC"}
package/format.ts ADDED
@@ -0,0 +1,49 @@
1
+ // Deno's explicit file arguments override configuration exclusions unless the
2
+ // exclusions are supplied through --ignore. Deno retains ownership of glob
3
+ // matching, file-type support and all formatting options. A checkout without
4
+ // a Deno config never chose Deno's formatter, so it is not formatted: Deno's
5
+ // defaults would rewrite a Rails app's Markdown and YAML it never authored.
6
+ import { parse } from '@jsr/std__jsonc'
7
+ import * as disk from '@yaks/file/io'
8
+
9
+ let object = (value: unknown): value is Record<string, unknown> =>
10
+ value != null && typeof value == 'object' && !Array.isArray(value)
11
+ let paths = (value: unknown): string[] =>
12
+ Array.isArray(value)
13
+ ? value.filter((path): path is string => typeof path == 'string')
14
+ : []
15
+
16
+ export let formatting = (
17
+ files: string[],
18
+ config: unknown,
19
+ file = 'deno.json',
20
+ ): string[] => {
21
+ let root = object(config) ? config : {}
22
+ let fmt = object(root.fmt) ? root.fmt : {}
23
+ return [
24
+ 'fmt',
25
+ '--config',
26
+ file,
27
+ '--permit-no-files',
28
+ ...[...new Set([...paths(root.exclude), ...paths(fmt.exclude)])]
29
+ .map((path) => '--ignore=' + path),
30
+ ...files,
31
+ ]
32
+ }
33
+
34
+ let read = (path: string) =>
35
+ disk.readTextFile(path).catch((e) => {
36
+ if (disk.isNotFound(e)) return undefined
37
+ throw e
38
+ })
39
+
40
+ /** The checkout's Deno config, or undefined when it has none. */
41
+ export let formatConfig = async (
42
+ cwd: string,
43
+ source: (path: string) => Promise<string | undefined> = read,
44
+ ): Promise<{ file: string; config: unknown } | undefined> => {
45
+ for (let file of ['deno.json', 'deno.jsonc']) {
46
+ let text = await source(disk.join(cwd, file))
47
+ if (text != null) return { file, config: parse(text) ?? {} }
48
+ }
49
+ }
package/hold.js ADDED
@@ -0,0 +1,17 @@
1
+ import * as io from "@yaks/file/io";
2
+ // The land lock of a checkout, a module of its own that imports nothing else
3
+ // from the workspace: a `yak` command takes it before it loads any module of
4
+ // the checkout it may land under (@yaks/cli/yak).
5
+ /** Hold the land lock of the checkout whose Git directory is `gitdir` until
6
+ * the returned release: exclusive for the landing that writes the checkout,
7
+ * shared for a reader that needs it whole. Git's own `index.lock` refuses a
8
+ * second writer instead of waiting for it, so whatever writes the shared
9
+ * checkout's index waits here first. */ export let hold = async (gitdir, exclusive)=>{
10
+ let file = await io.open(`${gitdir}/land.lock`, {
11
+ create: true,
12
+ write: true
13
+ });
14
+ await file.lock(exclusive);
15
+ return ()=>file.close();
16
+ };
17
+ //# sourceMappingURL=hold.js.map
package/hold.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hold.js","sources":["./hold.ts"],"names":[],"mappings":"AAAA,YAAY,6BAAkC;AAC9C,6EAA6E;AAC7E,6EAA6E;AAC7E,kDAAkD;AAElD;;;;sCAIsC,GACtC,OAAO,IAAI,OAAO,OAChB,QACA;EAEA,IAAI,OAAO,MAAM,GAAG,IAAI,CAAC,GAAG,OAAO,UAAU,CAAC,EAAE;IAC9C,QAAQ;IACR,OAAO;EACT;EACA,MAAM,KAAK,IAAI,CAAC;EAChB,OAAO,IAAM,KAAK,KAAK;AACzB,EAAC"}
package/hold.ts ADDED
@@ -0,0 +1,21 @@
1
+ import * as io from '@yaks/file/io'
2
+ // The land lock of a checkout, a module of its own that imports nothing else
3
+ // from the workspace: a `yak` command takes it before it loads any module of
4
+ // the checkout it may land under (@yaks/cli/yak).
5
+
6
+ /** Hold the land lock of the checkout whose Git directory is `gitdir` until
7
+ * the returned release: exclusive for the landing that writes the checkout,
8
+ * shared for a reader that needs it whole. Git's own `index.lock` refuses a
9
+ * second writer instead of waiting for it, so whatever writes the shared
10
+ * checkout's index waits here first. */
11
+ export let hold = async (
12
+ gitdir: string,
13
+ exclusive: boolean,
14
+ ): Promise<() => void> => {
15
+ let file = await io.open(`${gitdir}/land.lock`, {
16
+ create: true,
17
+ write: true,
18
+ })
19
+ await file.lock(exclusive)
20
+ return () => file.close()
21
+ }