@graftland/plugin-remote 0.3.2 → 0.4.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.
Files changed (326) hide show
  1. package/README.md +18 -54
  2. package/README.zh-CN.md +17 -51
  3. package/README.zh-TW.md +17 -51
  4. package/dist/Auth.d.ts.map +1 -1
  5. package/dist/Auth.js.map +1 -1
  6. package/dist/Config.d.ts +1151 -0
  7. package/dist/Config.d.ts.map +1 -0
  8. package/dist/Config.js +183 -0
  9. package/dist/Config.js.map +1 -0
  10. package/dist/Contract.d.ts +1 -1
  11. package/dist/Contract.d.ts.map +1 -1
  12. package/dist/Contract.js +32 -1
  13. package/dist/Contract.js.map +1 -1
  14. package/dist/Instance.d.ts.map +1 -1
  15. package/dist/Instance.js.map +1 -1
  16. package/dist/Testing.d.ts +1 -1
  17. package/dist/Testing.d.ts.map +1 -1
  18. package/dist/Testing.js.map +1 -1
  19. package/dist/Transport.d.ts +1 -1
  20. package/dist/Transport.d.ts.map +1 -1
  21. package/dist/Transport.js.map +1 -1
  22. package/dist/cli.d.ts +4 -0
  23. package/dist/cli.d.ts.map +1 -0
  24. package/dist/cli.js +25 -0
  25. package/dist/cli.js.map +1 -0
  26. package/dist/host/auth/bearer.d.ts +9 -1
  27. package/dist/host/auth/bearer.d.ts.map +1 -1
  28. package/dist/host/auth/bearer.js +4 -2
  29. package/dist/host/auth/bearer.js.map +1 -1
  30. package/dist/host/auth/jwt.d.ts +9 -1
  31. package/dist/host/auth/jwt.d.ts.map +1 -1
  32. package/dist/host/auth/jwt.js +4 -2
  33. package/dist/host/auth/jwt.js.map +1 -1
  34. package/dist/host/auth/mtls.d.ts +10 -7
  35. package/dist/host/auth/mtls.d.ts.map +1 -1
  36. package/dist/host/auth/mtls.js +13 -14
  37. package/dist/host/auth/mtls.js.map +1 -1
  38. package/dist/host/auth/none.d.ts +3 -1
  39. package/dist/host/auth/none.js +7 -5
  40. package/dist/host/auth/none.js.map +1 -1
  41. package/dist/host/command.d.ts +14 -1
  42. package/dist/host/command.d.ts.map +1 -1
  43. package/dist/host/command.js +11 -9
  44. package/dist/host/command.js.map +1 -1
  45. package/dist/host/local.d.ts +2 -1
  46. package/dist/host/local.d.ts.map +1 -1
  47. package/dist/host/local.js +9 -30
  48. package/dist/host/local.js.map +1 -1
  49. package/dist/host/unix.d.ts +6 -1
  50. package/dist/host/unix.d.ts.map +1 -1
  51. package/dist/host/unix.js +13 -9
  52. package/dist/host/unix.js.map +1 -1
  53. package/dist/host/websocket.d.ts +10 -1
  54. package/dist/host/websocket.d.ts.map +1 -1
  55. package/dist/host/websocket.js +11 -8
  56. package/dist/host/websocket.js.map +1 -1
  57. package/dist/host/worker.d.ts +3 -1
  58. package/dist/host/worker.d.ts.map +1 -1
  59. package/dist/host/worker.js +13 -9
  60. package/dist/host/worker.js.map +1 -1
  61. package/dist/index.d.ts +6 -8
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +30 -64
  64. package/dist/index.js.map +1 -1
  65. package/dist/internal/Certificates.js.map +1 -1
  66. package/dist/internal/FailureGroup.js +6 -6
  67. package/dist/internal/FailureGroup.js.map +1 -1
  68. package/dist/internal/Peer.js.map +1 -1
  69. package/dist/internal/{ServeLifecycle.js → RunnerLifecycle.js} +6 -6
  70. package/dist/internal/RunnerLifecycle.js.map +1 -0
  71. package/dist/internal/Supervisor.js.map +1 -1
  72. package/dist/internal/assembly.d.ts +3 -2
  73. package/dist/internal/assembly.js +8 -8
  74. package/dist/internal/assembly.js.map +1 -1
  75. package/dist/internal/auth/config.d.ts +27 -0
  76. package/dist/internal/auth/config.d.ts.map +1 -0
  77. package/dist/internal/auth/config.js +29 -0
  78. package/dist/internal/auth/config.js.map +1 -0
  79. package/dist/internal/auth/mtls.js.map +1 -1
  80. package/dist/internal/auth/token.js.map +1 -1
  81. package/dist/internal/auth/tokenCredentials.d.ts +2 -1
  82. package/dist/internal/auth/tokenCredentials.d.ts.map +1 -1
  83. package/dist/internal/auth/tokenCredentials.js +1 -1
  84. package/dist/internal/auth/tokenCredentials.js.map +1 -1
  85. package/dist/internal/child.js +3 -3
  86. package/dist/internal/child.js.map +1 -1
  87. package/dist/internal/childMain.js +47 -0
  88. package/dist/internal/childMain.js.map +1 -0
  89. package/dist/internal/childRuntime.js +8 -8
  90. package/dist/internal/childRuntime.js.map +1 -1
  91. package/dist/internal/cleanup.js +3 -3
  92. package/dist/internal/cleanup.js.map +1 -1
  93. package/dist/internal/contract.js.map +1 -1
  94. package/dist/internal/credentials.d.ts +3 -2
  95. package/dist/internal/credentials.d.ts.map +1 -1
  96. package/dist/internal/credentials.js +1 -1
  97. package/dist/internal/credentials.js.map +1 -1
  98. package/dist/internal/directTransport.js.map +1 -1
  99. package/dist/internal/entry.d.ts +493 -3
  100. package/dist/internal/entry.d.ts.map +1 -1
  101. package/dist/internal/entry.js +22 -9
  102. package/dist/internal/entry.js.map +1 -1
  103. package/dist/internal/entryConfig.d.ts +2 -202
  104. package/dist/internal/entryConfig.js +2 -136
  105. package/dist/internal/entryConfig.js.map +1 -1
  106. package/dist/internal/execution.d.ts +4 -4
  107. package/dist/internal/execution.js +11 -11
  108. package/dist/internal/execution.js.map +1 -1
  109. package/dist/internal/follow.js +1 -1
  110. package/dist/internal/follow.js.map +1 -1
  111. package/dist/internal/forkTree.js.map +1 -1
  112. package/dist/internal/host/local.js.map +1 -1
  113. package/dist/internal/host/runner.js +4 -4
  114. package/dist/internal/host/runner.js.map +1 -1
  115. package/dist/internal/host.js +2 -2
  116. package/dist/internal/host.js.map +1 -1
  117. package/dist/internal/importer.js +1 -1
  118. package/dist/internal/importer.js.map +1 -1
  119. package/dist/internal/listenerStartup.js +1 -1
  120. package/dist/internal/listenerStartup.js.map +1 -1
  121. package/dist/internal/loadModule.js.map +1 -1
  122. package/dist/internal/platform.js +1 -9
  123. package/dist/internal/port.d.ts +1 -1
  124. package/dist/internal/port.js +2 -2
  125. package/dist/internal/port.js.map +1 -1
  126. package/dist/internal/runner/Bootstrap.js.map +1 -1
  127. package/dist/internal/runner/Connection.d.ts +3 -2
  128. package/dist/internal/runner/Connection.js +6 -6
  129. package/dist/internal/runner/Connection.js.map +1 -1
  130. package/dist/internal/runner/Execution.js +6 -6
  131. package/dist/internal/runner/Execution.js.map +1 -1
  132. package/dist/internal/runner/Local.js +1 -1
  133. package/dist/internal/runner/Local.js.map +1 -1
  134. package/dist/internal/runner/Lock.js.map +1 -1
  135. package/dist/internal/runner/Multiplex.js.map +1 -1
  136. package/dist/internal/runner/Packages.js.map +1 -1
  137. package/dist/internal/runner/ProcessObservation.js.map +1 -1
  138. package/dist/internal/runner/Processes.js.map +1 -1
  139. package/dist/internal/runner/Retention.js.map +1 -1
  140. package/dist/internal/runner/Store.js.map +1 -1
  141. package/dist/internal/runner/Supervisor.js +5 -5
  142. package/dist/internal/runner/Supervisor.js.map +1 -1
  143. package/dist/internal/runner/Watchdog.js.map +1 -1
  144. package/dist/internal/runner/Wire.d.ts +1 -1
  145. package/dist/internal/runner/Wire.js.map +1 -1
  146. package/dist/internal/runner/accept.js +2 -2
  147. package/dist/internal/runner/accept.js.map +1 -1
  148. package/dist/internal/runner/command.js +1 -1
  149. package/dist/internal/runner/command.js.map +1 -1
  150. package/dist/internal/runner/connectionEnded.js +1 -1
  151. package/dist/internal/runner/connectionEnded.js.map +1 -1
  152. package/dist/internal/runner/model.d.ts.map +1 -1
  153. package/dist/internal/runner/model.js.map +1 -1
  154. package/dist/internal/services.d.ts.map +1 -1
  155. package/dist/internal/services.js +1 -1
  156. package/dist/internal/services.js.map +1 -1
  157. package/dist/internal/socketChannel.js.map +1 -1
  158. package/dist/internal/stdioChannel.js.map +1 -1
  159. package/dist/internal/supervisorPlugin.js +48 -1
  160. package/dist/internal/supervisorPlugin.js.map +1 -1
  161. package/dist/internal/transportOptions.d.ts.map +1 -1
  162. package/dist/internal/watchdogMain.js +5 -3
  163. package/dist/internal/watchdogMain.js.map +1 -1
  164. package/dist/internal/websocket.js.map +1 -1
  165. package/dist/internal/websocketServer.js +1 -1
  166. package/dist/internal/websocketServer.js.map +1 -1
  167. package/dist/internal/workerChannel.js.map +1 -1
  168. package/dist/internal/workerMain.js +13 -6
  169. package/dist/internal/workerMain.js.map +1 -1
  170. package/dist/runner/auth/bearer.d.ts +8 -5
  171. package/dist/runner/auth/bearer.d.ts.map +1 -1
  172. package/dist/runner/auth/bearer.js +13 -11
  173. package/dist/runner/auth/bearer.js.map +1 -1
  174. package/dist/runner/auth/jwt.d.ts +30 -17
  175. package/dist/runner/auth/jwt.d.ts.map +1 -1
  176. package/dist/runner/auth/jwt.js +16 -28
  177. package/dist/runner/auth/jwt.js.map +1 -1
  178. package/dist/runner/auth/mtls.d.ts +8 -6
  179. package/dist/runner/auth/mtls.d.ts.map +1 -1
  180. package/dist/runner/auth/mtls.js +13 -29
  181. package/dist/runner/auth/mtls.js.map +1 -1
  182. package/dist/runner/auth/none.d.ts +7 -1
  183. package/dist/runner/auth/none.js +7 -5
  184. package/dist/runner/auth/none.js.map +1 -1
  185. package/dist/runner/index.d.ts +5 -1
  186. package/dist/runner/index.d.ts.map +1 -1
  187. package/dist/runner/index.js +62 -30
  188. package/dist/runner/index.js.map +1 -1
  189. package/dist/runner/stdio.d.ts +6 -1
  190. package/dist/runner/stdio.d.ts.map +1 -1
  191. package/dist/runner/stdio.js +11 -9
  192. package/dist/runner/stdio.js.map +1 -1
  193. package/dist/runner/unix.d.ts +6 -1
  194. package/dist/runner/unix.d.ts.map +1 -1
  195. package/dist/runner/unix.js +10 -8
  196. package/dist/runner/unix.js.map +1 -1
  197. package/dist/runner/websocket.d.ts +24 -1
  198. package/dist/runner/websocket.d.ts.map +1 -1
  199. package/dist/runner/websocket.js +12 -10
  200. package/dist/runner/websocket.js.map +1 -1
  201. package/package.json +14 -12
  202. package/schema.json +2269 -0
  203. package/src/Auth.ts +8 -2
  204. package/src/Config.ts +196 -0
  205. package/src/Contract.ts +12 -3
  206. package/src/Instance.ts +1 -0
  207. package/src/Testing.ts +6 -4
  208. package/src/Transport.ts +12 -3
  209. package/src/cli.ts +60 -0
  210. package/src/host/auth/bearer.ts +1 -0
  211. package/src/host/auth/jwt.ts +1 -0
  212. package/src/host/auth/mtls.ts +7 -12
  213. package/src/host/auth/none.ts +3 -1
  214. package/src/host/command.ts +8 -5
  215. package/src/host/local.ts +4 -2
  216. package/src/host/unix.ts +11 -7
  217. package/src/host/websocket.ts +10 -7
  218. package/src/host/worker.ts +8 -5
  219. package/src/index.ts +36 -23
  220. package/src/internal/Certificates.ts +1 -0
  221. package/src/internal/FailureGroup.ts +5 -3
  222. package/src/internal/Peer.ts +1 -0
  223. package/src/internal/{ServeLifecycle.ts → RunnerLifecycle.ts} +7 -5
  224. package/src/internal/Supervisor.ts +5 -4
  225. package/src/internal/assembly.ts +11 -9
  226. package/src/internal/auth/config.ts +44 -0
  227. package/src/internal/auth/mtls.ts +1 -0
  228. package/src/internal/auth/token.ts +1 -0
  229. package/src/internal/auth/tokenCredentials.ts +4 -2
  230. package/src/internal/child.ts +8 -6
  231. package/src/{bin.ts → internal/childMain.ts} +16 -61
  232. package/src/internal/childRuntime.ts +12 -10
  233. package/src/internal/cleanup.ts +3 -2
  234. package/src/internal/contract.ts +1 -0
  235. package/src/internal/credentials.ts +3 -1
  236. package/src/internal/directTransport.ts +9 -2
  237. package/src/internal/entry.ts +53 -16
  238. package/src/internal/entryConfig.ts +10 -132
  239. package/src/internal/execution.ts +17 -15
  240. package/src/internal/follow.ts +2 -1
  241. package/src/internal/forkTree.ts +2 -1
  242. package/src/internal/host/local.ts +1 -0
  243. package/src/internal/host/runner.ts +7 -5
  244. package/src/internal/host.ts +9 -8
  245. package/src/internal/importer.ts +3 -2
  246. package/src/internal/listenerStartup.ts +4 -2
  247. package/src/internal/loadModule.ts +1 -0
  248. package/src/internal/platform.ts +1 -12
  249. package/src/internal/port.ts +11 -6
  250. package/src/internal/runner/Bootstrap.ts +1 -0
  251. package/src/internal/runner/Connection.ts +13 -11
  252. package/src/internal/runner/Execution.ts +14 -13
  253. package/src/internal/runner/Local.ts +3 -2
  254. package/src/internal/runner/Lock.ts +1 -0
  255. package/src/internal/runner/Multiplex.ts +2 -1
  256. package/src/internal/runner/Packages.ts +7 -5
  257. package/src/internal/runner/ProcessObservation.ts +2 -1
  258. package/src/internal/runner/Processes.ts +3 -1
  259. package/src/internal/runner/Retention.ts +1 -0
  260. package/src/internal/runner/Store.ts +3 -2
  261. package/src/internal/runner/Supervisor.ts +22 -20
  262. package/src/internal/runner/Watchdog.ts +3 -1
  263. package/src/internal/runner/Wire.ts +13 -12
  264. package/src/internal/runner/accept.ts +6 -5
  265. package/src/internal/runner/command.ts +3 -2
  266. package/src/internal/runner/connectionEnded.ts +2 -1
  267. package/src/internal/runner/model.ts +5 -3
  268. package/src/internal/services.ts +9 -2
  269. package/src/internal/socketChannel.ts +2 -1
  270. package/src/internal/stdioChannel.ts +4 -2
  271. package/src/internal/supervisorPlugin.ts +10 -8
  272. package/src/internal/transportOptions.ts +1 -0
  273. package/src/internal/watchdogMain.ts +5 -3
  274. package/src/internal/websocket.ts +5 -2
  275. package/src/internal/websocketServer.ts +6 -4
  276. package/src/internal/workerChannel.ts +1 -0
  277. package/src/internal/workerMain.ts +21 -5
  278. package/src/runner/auth/bearer.ts +10 -6
  279. package/src/runner/auth/jwt.ts +10 -41
  280. package/src/runner/auth/mtls.ts +6 -3
  281. package/src/runner/auth/none.ts +3 -1
  282. package/src/runner/index.ts +102 -11
  283. package/src/runner/stdio.ts +15 -10
  284. package/src/runner/unix.ts +7 -4
  285. package/src/runner/websocket.ts +9 -7
  286. package/dist/Auth-BElTC9_X.js +0 -6
  287. package/dist/Bootstrap-H9gDsgsC.js +0 -9
  288. package/dist/ConfigDirectory-BCC6q2R4.js +0 -5
  289. package/dist/Contract-DsJtisvL.js +0 -83
  290. package/dist/Errors-DYhsGZcZ.js +0 -58
  291. package/dist/FailureGroup-BgT73AaR.js +0 -63
  292. package/dist/Framing-G9eSaeLb.js +0 -61
  293. package/dist/Graft-B71CPA2Y.js +0 -996
  294. package/dist/Packages-AgoCGotL.js +0 -108
  295. package/dist/Peer-DXeVrGBh.js +0 -342
  296. package/dist/ProcessObservation-gLgGirYv.js +0 -38
  297. package/dist/ServeLifecycle-Bd1FPJ6e.js +0 -24
  298. package/dist/Transport-DULzpsgR.js +0 -6
  299. package/dist/WatchdogProtocol-BZmVxrBP.js +0 -17
  300. package/dist/bin.js +0 -28276
  301. package/dist/bin.js.map +0 -1
  302. package/dist/childRuntime-Bm3iSg_N.js +0 -192
  303. package/dist/command-9zrHdbwT.js +0 -7
  304. package/dist/connectionEnded-BwcxQ7W8.js +0 -54
  305. package/dist/directTransport-DrexuPSm.js +0 -5
  306. package/dist/entry-psOpX3Bj.js +0 -736
  307. package/dist/importer-Cvf88eAY.js +0 -344
  308. package/dist/internal/ServeLifecycle.js.map +0 -1
  309. package/dist/internal/entryConfig.d.ts.map +0 -1
  310. package/dist/internal/platform.js.map +0 -1
  311. package/dist/internal/release.js +0 -25
  312. package/dist/internal/release.js.map +0 -1
  313. package/dist/internal/serve.js +0 -60
  314. package/dist/internal/serve.js.map +0 -1
  315. package/dist/port--3x2zJ4D.js +0 -285
  316. package/dist/release-DfZPuIcK.js +0 -23
  317. package/dist/rolldown-runtime-DYf_mQCB.js +0 -34
  318. package/dist/socketChannel-CJvL2DiB.js +0 -3658
  319. package/dist/supervisorPlugin-t6Z6PrhD.js +0 -733
  320. package/dist/token-CYBNNlhS.js +0 -17
  321. package/dist/tokenCredentials-CbCuk-Rt.js +0 -31
  322. package/dist/websocketServer-NQhODlEt.js +0 -60
  323. package/dist/workerChannel-C8hhBJzA.js +0 -27
  324. package/src/internal/release.ts +0 -72
  325. package/src/internal/serve.ts +0 -119
  326. /package/dist/{bin.d.ts → internal/childMain.d.ts} +0 -0
@@ -1,5 +1,7 @@
1
1
  import { Context, Deferred, Effect, Exit, Option, Schema, Scope } from "effect"
2
- import * as Release from "./release"
2
+
3
+ import * as Release from "@graftland/graft/Release"
4
+
3
5
  import type { TransportError } from "../Errors"
4
6
 
5
7
  export class StartupError extends Schema.TaggedError<
@@ -14,13 +16,13 @@ export class StartupError extends Schema.TaggedError<
14
16
  }
15
17
  }
16
18
 
17
- export class ServeLifecycle extends Context.Service<
18
- ServeLifecycle,
19
+ export class RunnerLifecycle extends Context.Service<
20
+ RunnerLifecycle,
19
21
  {
20
22
  readonly ended: Deferred.Deferred<void, TransportError>
21
23
  readonly released: Deferred.Deferred<void, StartupError>
22
24
  }
23
- >()("@graftland/plugin-remote/internal/ServeLifecycle") {}
25
+ >()("@graftland/plugin-remote/internal/RunnerLifecycle") {}
24
26
 
25
27
  export const make = Effect.all({
26
28
  ended: Deferred.make<void, TransportError>(),
@@ -29,7 +31,7 @@ export const make = Effect.all({
29
31
 
30
32
  /** Observe shutdown independently of the loader, which logs child cleanup failures. */
31
33
  export const resources = Effect.fnUntraced(function* (
32
- lifecycle: Option.Option<typeof ServeLifecycle.Service>,
34
+ lifecycle: Option.Option<typeof RunnerLifecycle.Service>,
33
35
  ) {
34
36
  return yield* Effect.acquireRelease(Scope.make(), (scope, exit) =>
35
37
  Release.close(scope, exit).pipe(
@@ -1,9 +1,10 @@
1
1
  /** A listener hands an authenticated byte channel to the supervisor. */
2
- import { Context } from "effect"
3
- import type { Effect, Scope } from "effect"
4
- import type { Peer } from "./Peer"
5
- import type { Channel } from "../Transport"
2
+ import { Context, type Effect, type Scope } from "effect"
3
+
6
4
  import type { TransportError } from "../Errors"
5
+ import type { Channel } from "../Transport"
6
+ import type { Peer } from "./Peer"
7
+
7
8
  export class Supervisor extends Context.Service<
8
9
  Supervisor,
9
10
  {
@@ -1,6 +1,3 @@
1
- import { findSubtree, isSubtreeActive } from "./forkTree"
2
- import { Peer } from "./Peer"
3
- import { Graft, Plugin, type Fork } from "@graftland/graft"
4
1
  import {
5
2
  Array,
6
3
  Context,
@@ -11,12 +8,16 @@ import {
11
8
  Schema,
12
9
  Stream,
13
10
  } from "effect"
11
+
12
+ import { Graft, Plugin, type Fork } from "@graftland/graft"
13
+
14
14
  import {
15
15
  Authenticator,
16
16
  Credentials,
17
17
  type AuthenticatorApi,
18
18
  type CredentialsApi,
19
19
  } from "../Auth"
20
+ import { AuthenticationFailed } from "../Errors"
20
21
  import {
21
22
  Connector,
22
23
  Listener,
@@ -24,11 +25,12 @@ import {
24
25
  type Properties,
25
26
  type Session,
26
27
  } from "../Transport"
27
- import { AuthenticationFailed } from "../Errors"
28
- import { Supervisor } from "./Supervisor"
29
28
  import { follow } from "./follow"
30
- import { connectionEnded, closedNormally } from "./runner/connectionEnded"
31
- import { ServeLifecycle } from "./ServeLifecycle"
29
+ import { findSubtree, isSubtreeActive } from "./forkTree"
30
+ import { Peer } from "./Peer"
31
+ import { closedNormally, connectionEnded } from "./runner/connectionEnded"
32
+ import { RunnerLifecycle } from "./RunnerLifecycle"
33
+ import { Supervisor } from "./Supervisor"
32
34
 
33
35
  export class ListenerConfigError extends Schema.TaggedError<
34
36
  ListenerConfigError,
@@ -291,13 +293,13 @@ export const makeListenerConsumer = (
291
293
  Listener,
292
294
  Authenticator,
293
295
  Supervisor,
294
- Plugin.optional(ServeLifecycle),
296
+ Plugin.optional(RunnerLifecycle),
295
297
  ],
296
298
  apply: Effect.fnUntraced(function* () {
297
299
  const listener = yield* Listener
298
300
  const auth = yield* Authenticator
299
301
  const supervisor = yield* Supervisor
300
- const lifecycle = yield* Effect.serviceOption(ServeLifecycle)
302
+ const lifecycle = yield* Effect.serviceOption(RunnerLifecycle)
301
303
  yield* prepare(listener.properties, auth)
302
304
  yield* compatible(listener.properties, kind(auth)).pipe(
303
305
  Effect.mapError((error) =>
@@ -0,0 +1,44 @@
1
+ import { Duration, Effect, Schema } from "effect"
2
+ import { Jwk } from "effect/jose"
3
+
4
+ export const ClockTolerance = Schema.DurationFromString.check(
5
+ Schema.makeFilter(
6
+ (duration) =>
7
+ Duration.isFinite(duration) && Duration.toMillis(duration) >= 0,
8
+ { expected: "a finite, non-negative duration" },
9
+ ),
10
+ )
11
+ export const Jwt = Schema.Struct({
12
+ issuer: Schema.NonEmptyString,
13
+ audience: Schema.NonEmptyArray(Schema.NonEmptyString),
14
+ algorithms: Schema.NonEmptyArray(Jwk.AsymmetricAlgorithm),
15
+ identityClaim: Schema.NonEmptyString.pipe(
16
+ Schema.withDecodingDefaultKey(Effect.succeed("sub")),
17
+ ),
18
+ clockTolerance: ClockTolerance.pipe(
19
+ Schema.withDecodingDefaultKey(Effect.succeed("5 seconds")),
20
+ ),
21
+ keys: Schema.Union([
22
+ Schema.Struct({
23
+ jwksUrl: Schema.String,
24
+ publicKey: Schema.optionalKey(Schema.Never),
25
+ }),
26
+ Schema.Struct({
27
+ publicKey: Schema.String,
28
+ jwksUrl: Schema.optionalKey(Schema.Never),
29
+ }),
30
+ ]),
31
+ })
32
+
33
+ export const Certificate = Schema.Struct({
34
+ cert: Schema.String,
35
+ key: Schema.String,
36
+ })
37
+ export const Token = Schema.Struct({
38
+ token: Schema.Union([Schema.String, Schema.Struct({ file: Schema.String })]),
39
+ })
40
+ export const Mtls = Schema.Struct({ ca: Schema.String })
41
+ export const Bearer = Schema.Struct({ tokens: Schema.String })
42
+ export const None = Schema.Struct({
43
+ identity: Schema.optionalKey(Schema.String),
44
+ })
@@ -1,4 +1,5 @@
1
1
  import { Array, Cause, Effect, Schema, String } from "effect"
2
+
2
3
  import { AuthenticationFailed } from "../../Errors"
3
4
 
4
5
  // Node JSON-quotes SAN values containing separators, escaping commas inside the value.
@@ -1,4 +1,5 @@
1
1
  import { Effect, Option, Redacted } from "effect"
2
+
2
3
  import { AuthenticationFailed } from "../../Errors"
3
4
 
4
5
  export const invalid = () =>
@@ -1,5 +1,3 @@
1
- import { Graft, Plugin } from "@graftland/graft"
2
- import { ConfigDirectory } from "@graftland/loader"
3
1
  import {
4
2
  Cause,
5
3
  Effect,
@@ -9,6 +7,10 @@ import {
9
7
  Redacted,
10
8
  Schema,
11
9
  } from "effect"
10
+
11
+ import { Graft, Plugin } from "@graftland/graft"
12
+ import { ConfigDirectory } from "@graftland/loader"
13
+
12
14
  import { Credentials, type Prepared } from "../../Auth"
13
15
  import { CredentialsError } from "../../Errors"
14
16
  import { prepare } from "./token"
@@ -1,6 +1,3 @@
1
- import { loadModule } from "./loadModule"
2
- import { AlreadyLoaded, ActivationFailed } from "./childErrors"
3
- import { Graft, Plugin, type Fork } from "@graftland/graft"
4
1
  import {
5
2
  Array,
6
3
  Cause,
@@ -18,12 +15,17 @@ import {
18
15
  Scope,
19
16
  Stream,
20
17
  SynchronizedRef,
18
+ type Schema,
21
19
  } from "effect"
22
- import type { Schema } from "effect"
23
- import { type RunnerContract } from "./contract"
20
+
21
+ import { Graft, Plugin, type Fork } from "@graftland/graft"
22
+
24
23
  import { Instance, type Identity } from "../Instance"
25
- import type * as Port from "./port"
24
+ import { ActivationFailed, AlreadyLoaded } from "./childErrors"
25
+ import { type RunnerContract } from "./contract"
26
26
  import type { Event, Log, LogEvent } from "./control"
27
+ import { loadModule } from "./loadModule"
28
+ import type * as Port from "./port"
27
29
 
28
30
  type Peer = Port.Port
29
31
  type ChildEvent = Data.TaggedEnum<{
@@ -1,64 +1,20 @@
1
1
  #!/usr/bin/env node
2
- /** Runs local children and WebSocket supervisors, and issues their deployment certificates. */
3
- import { Graft } from "@graftland/graft"
4
- import { NodeRuntime } from "@effect/platform-node"
5
- import { Console, Array, Effect, Layer, Logger, Option, Schema } from "effect"
6
- import { Argument, CliError, Command, Flag } from "effect/cli"
2
+ /** Internal executable for local and supervised child runtimes. */
7
3
  import process from "node:process"
8
4
  import { pathToFileURL } from "node:url"
9
- import { platform } from "./internal/platform"
10
- import { bytes } from "./internal/stdioChannel"
11
- import { load, run } from "./internal/childRuntime"
12
- import { Bootstrap } from "./internal/runner/Bootstrap"
13
- import * as Watchdog from "./internal/runner/Watchdog"
14
- import * as Serve from "./internal/serve"
15
- import * as Certificates from "./internal/Certificates"
16
5
 
17
- const serve = Command.make(
18
- "serve",
19
- { config: Flag.String("config") },
20
- ({ config }) => Serve.run(config),
21
- )
22
- const certificates = Command.make(
23
- "certificates",
24
- {
25
- out: Flag.String("out").pipe(
26
- Flag.withDescription("Directory for the CA and issued certificates"),
27
- ),
28
- server: Flag.String("server").pipe(
29
- Flag.atLeast(0),
30
- Flag.withDescription(
31
- "Runner DNS name or IP address; repeat for additional SANs",
32
- ),
33
- ),
34
- identity: Flag.String("identity").pipe(
35
- Flag.atLeast(0),
36
- Flag.withDescription(
37
- "Host identity; repeat to issue multiple client certificates",
38
- ),
39
- ),
40
- days: Flag.Int("days").pipe(
41
- Flag.withDefault(365),
42
- Flag.filter(
43
- (days) => days > 0,
44
- () => "Days must be a positive integer",
45
- ),
46
- ),
47
- force: Flag.Boolean("force").pipe(
48
- Flag.withDefault(false),
49
- Flag.withDescription(
50
- "Replace requested leaf certificates, keeping the existing CA",
51
- ),
52
- ),
53
- },
54
- (options) =>
55
- Certificates.generate(options).pipe(
56
- Effect.andThen(Console.log(`Certificates written to ${options.out}`)),
57
- Effect.catchTag("CertificateExists", (error) =>
58
- CliError.UserError.make({ cause: error, userMessage: error.message }),
59
- ),
60
- ),
61
- )
6
+ import { Array, Effect, Layer, Logger, Option, Schema } from "effect"
7
+ import { Argument, CliError, Command } from "effect/cli"
8
+ import { NodeRuntime } from "@effect/platform-node"
9
+
10
+ import { Graft } from "@graftland/graft"
11
+
12
+ import { load, run } from "./childRuntime"
13
+ import { platform } from "./platform"
14
+ import { Bootstrap } from "./runner/Bootstrap"
15
+ import * as Watchdog from "./runner/Watchdog"
16
+ import { bytes } from "./stdioChannel"
17
+
62
18
  const child = Command.make(
63
19
  "child",
64
20
  {
@@ -87,7 +43,7 @@ const child = Command.make(
87
43
  }),
88
44
  )
89
45
  const cli = Command.make(
90
- "graft-remote",
46
+ "remote-child",
91
47
  {
92
48
  contract: Argument.String("contract").pipe(Argument.optional),
93
49
  session: Argument.String("session").pipe(Argument.withDefault("local")),
@@ -96,14 +52,13 @@ const cli = Command.make(
96
52
  if (Option.isNone(contract))
97
53
  return yield* CliError.UserError.make({
98
54
  cause: "Missing contract module",
99
- userMessage:
100
- "A contract module or the child/serve/certificates subcommand is required",
55
+ userMessage: "A contract module or the child subcommand is required",
101
56
  })
102
57
  const definition = yield* load(contract.value)
103
58
  const channel = yield* bytes
104
59
  return yield* run(definition, channel, session)
105
60
  }),
106
- ).pipe(Command.withSubcommands([child, serve, certificates]))
61
+ ).pipe(Command.withSubcommands([child]))
107
62
 
108
63
  NodeRuntime.runMain(
109
64
  Effect.scoped(
@@ -1,19 +1,21 @@
1
- import { loadModule } from "./loadModule"
2
- import { ContractNotFound } from "./childErrors"
3
- import type { Graft } from "@graftland/graft"
4
1
  import { Effect, Logger, Option } from "effect"
5
2
  import { RpcServer } from "effect/rpc"
3
+
4
+ import type { Graft } from "@graftland/graft"
5
+
6
6
  import { fromModule, type RunnerContract } from "../Contract"
7
- import * as Port from "./port"
8
- import { prepare, type RunnerContract as PreparedContract } from "./contract"
9
- import * as Services from "./services"
10
7
  import * as Child from "./child"
11
- import * as Multiplex from "./runner/Multiplex"
12
- import * as Wire from "./runner/Wire"
8
+ import { ContractNotFound } from "./childErrors"
9
+ import { prepare, type RunnerContract as PreparedContract } from "./contract"
10
+ import { endpoint } from "./control"
11
+ import { loadModule } from "./loadModule"
12
+ import * as Port from "./port"
13
13
  import type { Bootstrap } from "./runner/Bootstrap"
14
- import { ExecutionError } from "./runner/model"
15
14
  import { closedNormally } from "./runner/connectionEnded"
16
- import { endpoint } from "./control"
15
+ import { ExecutionError } from "./runner/model"
16
+ import * as Multiplex from "./runner/Multiplex"
17
+ import * as Wire from "./runner/Wire"
18
+ import * as Services from "./services"
17
19
 
18
20
  /** Import a contract in the runner installation; importing this module performs no I/O. */
19
21
  export const load = Effect.fnUntraced(function* (specifier: string) {
@@ -1,6 +1,7 @@
1
- import { Fork } from "@graftland/graft"
2
1
  import { Array, Cause, Effect, Schema, Scope } from "effect"
3
- import * as Release from "./release"
2
+
3
+ import { Fork } from "@graftland/graft"
4
+ import * as Release from "@graftland/graft/Release"
4
5
 
5
6
  /** Finalizers have no typed failure channel. Keep reasons and their annotations flat. */
6
7
  export const cleanupCause = (cause: Cause.Cause<unknown>): Cause.Cause<never> =>
@@ -1,4 +1,5 @@
1
1
  import { Cause, Schema } from "effect"
2
+
2
3
  import * as Contract from "../Contract"
3
4
  import { ChildFailure } from "./childErrors"
4
5
  import * as Control from "./control"
@@ -1,5 +1,7 @@
1
- import { Graft, Plugin } from "@graftland/graft"
2
1
  import { Cause, Context, Effect, Redacted, Scope } from "effect"
2
+
3
+ import { Graft, Plugin } from "@graftland/graft"
4
+
3
5
  import { Credentials, type ClientCertificate, type Prepared } from "../Auth"
4
6
  import { CredentialsError } from "../Errors"
5
7
  import { prepare } from "./auth/token"
@@ -1,7 +1,14 @@
1
- import { Context } from "effect"
2
- import type { Effect, Option, Scope, PlatformError } from "effect"
1
+ import {
2
+ Context,
3
+ type Effect,
4
+ type Option,
5
+ type PlatformError,
6
+ type Scope,
7
+ } from "effect"
8
+
3
9
  import type { ProcessExited, TransportError } from "../Errors"
4
10
  import type { Channel } from "../Transport"
11
+
5
12
  export interface LocalOptions {
6
13
  readonly command?: readonly [string, ...string[]]
7
14
  readonly contractModule: string
@@ -1,29 +1,30 @@
1
- import { Graft, Plugin, type Fork } from "@graftland/graft"
2
- import { ConfigDirectory, Entry, ModuleResolver } from "@graftland/loader"
3
1
  import {
4
2
  Cause,
5
3
  Effect,
6
4
  Option,
7
5
  Path,
8
- Schema,
9
6
  References,
7
+ Schema,
10
8
  Scope,
11
9
  String,
12
10
  } from "effect"
11
+ import { SecureRandom } from "effect/crypto"
13
12
  import { ChildProcessSpawner } from "effect/process"
13
+
14
+ import { Graft, Plugin, type Fork } from "@graftland/graft"
15
+ import { ConfigDirectory, Entry, ModuleResolver } from "@graftland/loader"
16
+
14
17
  import * as Contract from "../Contract"
15
- import { MissingInstance, RemoteEntryError as EntryError } from "../Errors"
18
+ import { RemoteEntryError as EntryError, MissingInstance } from "../Errors"
19
+ import * as Assembly from "./assembly"
20
+ import { children } from "./cleanup"
16
21
  import { LocalTransport, WorkerTransport } from "./directTransport"
17
22
  import * as Configuration from "./entryConfig"
18
- import * as Assembly from "./assembly"
19
- import { executionPlugin } from "./execution"
23
+ import { executionPlugin, type ExecutionOptions } from "./execution"
20
24
  import { follow } from "./follow"
21
- import { children } from "./cleanup"
22
- import { resolveEntry } from "./runner/Packages"
23
- import type { LocalTarget, WorkerTarget } from "./runner/Connection"
24
- import type { ExecutionOptions } from "./execution"
25
25
  import * as Importer from "./importer"
26
- import { SecureRandom } from "effect/crypto"
26
+ import type { LocalTarget, WorkerTarget } from "./runner/Connection"
27
+ import { resolveEntry } from "./runner/Packages"
27
28
 
28
29
  export const boundary = Effect.fnUntraced(function* (field: string) {
29
30
  const entry = yield* Entry.CurrentId
@@ -77,7 +78,11 @@ export const loadContract = Effect.fnUntraced(function* (specifier: string) {
77
78
  /** Direct execution installs only its execution capability in a private realm. */
78
79
  export const direct = (
79
80
  provider: Plugin.Plugin,
80
- consumer: Plugin.Plugin,
81
+ consumer: Effect.Effect<
82
+ Plugin.Plugin,
83
+ ModuleResolver.ModuleInvalid,
84
+ Scope.Scope
85
+ >,
81
86
  input: Schema.Json,
82
87
  key: typeof LocalTransport | typeof WorkerTransport,
83
88
  ): Effect.Effect<Fork.Fork<never, unknown>, never, Graft.Graft | Scope.Scope> =>
@@ -89,7 +94,8 @@ export const direct = (
89
94
  yield* follow(capability, (cause) =>
90
95
  Effect.fail(Assembly.CapabilityFailed.make({ cause })),
91
96
  )
92
- const execution = yield* Graft.plugin(consumer, input)
97
+ const definition = yield* consumer
98
+ const execution = yield* Graft.plugin(definition, input)
93
99
  yield* follow(execution, (cause) =>
94
100
  Effect.fail(Assembly.CapabilityFailed.make({ cause })),
95
101
  )
@@ -132,17 +138,48 @@ const directTarget = Effect.fnUntraced(function* <
132
138
  },
133
139
  "connect",
134
140
  )
135
- return yield* direct(
136
- capability.plugin,
141
+
142
+ const watch = yield* ModuleResolver.Watch
143
+ const resolver = yield* Effect.serviceOption(ModuleResolver.ModuleResolver)
144
+ const current: Effect.Effect<
145
+ Contract.Contract<Contract.ConfigSchema, Contract.ErrorSchema>,
146
+ ModuleResolver.ModuleInvalid,
147
+ Scope.Scope
148
+ > = Option.isSome(watch) && Option.isSome(resolver)
149
+ ? resolver.value.importModule(module).pipe(
150
+ Effect.flatMap((namespace) =>
151
+ Effect.fromOption(Contract.fromModule(namespace), () =>
152
+ ModuleResolver.ModuleInvalid.make({
153
+ specifier: module,
154
+ cause: "Expected a remote contract",
155
+ }),
156
+ ),
157
+ ),
158
+ )
159
+ : Effect.succeed(contract)
160
+ const loaded = yield* current
161
+ const consumer = Effect.succeed(
137
162
  executionPlugin(
138
- contract,
163
+ loaded,
139
164
  { ...options, contractModule: module },
140
165
  selected,
141
166
  annotations,
142
167
  ),
168
+ )
169
+ if (Option.isSome(watch)) {
170
+ const implementation = String.startsWith("file:")(loaded.module)
171
+ ? loaded.module
172
+ : yield* resolveEntry(directory, loaded.module)
173
+ yield* ModuleResolver.observe([module, implementation])
174
+ }
175
+ const fork = yield* direct(
176
+ capability.plugin,
177
+ consumer,
143
178
  input.config,
144
179
  selected._tag === "Local" ? LocalTransport : WorkerTransport,
145
180
  )
181
+
182
+ return fork
146
183
  })
147
184
  const runnerTarget = Effect.fnUntraced(function* <
148
185
  S extends Schema.Top & {
@@ -1,122 +1,12 @@
1
- import { Effect, Schema } from "effect"
2
- import { PositiveDuration } from "./config"
1
+ import {
2
+ Reference,
3
+ RunnerAuthentication,
4
+ type Authentication,
5
+ type Connect,
6
+ type Listen,
7
+ } from "../Config"
3
8
 
4
- export const Reference = Schema.Struct({
5
- name: Schema.String,
6
- config: Schema.optionalKey(Schema.Unknown),
7
- })
8
- export type Reference = typeof Reference.Type
9
- const absent = Schema.optionalKey(Schema.Never)
10
- const authFields = {
11
- name: absent,
12
- config: absent,
13
- mtls: absent,
14
- bearer: absent,
15
- jwt: absent,
16
- none: absent,
17
- }
18
- export const Authentication = Schema.Union([
19
- Schema.Struct({
20
- ...authFields,
21
- name: Schema.String,
22
- config: Schema.optionalKey(Schema.Unknown),
23
- }),
24
- Schema.Struct({ ...authFields, mtls: Schema.Unknown }),
25
- Schema.Struct({ ...authFields, bearer: Schema.Unknown }),
26
- Schema.Struct({ ...authFields, jwt: Schema.Unknown }),
27
- Schema.Struct({ ...authFields, none: Schema.Unknown }),
28
- ])
29
- const transportFields = {
30
- url: absent,
31
- unix: absent,
32
- command: absent,
33
- stdio: absent,
34
- local: absent,
35
- worker: absent,
36
- transport: absent,
37
- }
38
- const auth = Schema.optionalKey(Authentication)
39
- const common = {
40
- instance: Schema.optionalKey(Schema.String),
41
- lease: Schema.optionalKey(PositiveDuration),
42
- margin: Schema.optionalKey(PositiveDuration),
43
- expect: Schema.optionalKey(
44
- Schema.Struct({
45
- version: Schema.optionalKey(Schema.String),
46
- digest: Schema.optionalKey(Schema.String),
47
- }),
48
- ),
49
- }
50
- const network = {
51
- ...transportFields,
52
- ...common,
53
- auth,
54
- url: Schema.String,
55
- ca: Schema.optionalKey(Schema.String),
56
- servername: Schema.optionalKey(Schema.String),
57
- }
58
- export const Connect = Schema.Union([
59
- Schema.Struct(network),
60
- Schema.Struct({ ...transportFields, ...common, auth, unix: Schema.String }),
61
- Schema.Struct({
62
- ...transportFields,
63
- ...common,
64
- command: Schema.NonEmptyArray(Schema.String),
65
- auth: Schema.optionalKey(
66
- Schema.Never.annotate({
67
- message: "Direct and stdio transports do not accept auth",
68
- }),
69
- ),
70
- cwd: Schema.optionalKey(Schema.String),
71
- env: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
72
- }),
73
- Schema.Struct({
74
- ...transportFields,
75
- auth: Schema.optionalKey(
76
- Schema.Never.annotate({
77
- message: "Direct and stdio transports do not accept auth",
78
- }),
79
- ),
80
- local: Schema.Struct({
81
- command: Schema.optionalKey(Schema.NonEmptyArray(Schema.String)),
82
- }),
83
- }),
84
- Schema.Struct({
85
- ...transportFields,
86
- auth: Schema.optionalKey(
87
- Schema.Never.annotate({
88
- message: "Direct and stdio transports do not accept auth",
89
- }),
90
- ),
91
- worker: Schema.Struct({
92
- execArgv: Schema.optionalKey(Schema.Array(Schema.String)),
93
- }),
94
- }),
95
- Schema.Struct({ ...transportFields, ...common, auth, transport: Reference }),
96
- ])
97
- export type Connect = typeof Connect.Type
98
- export const Listen = Schema.Union([
99
- Schema.Struct({
100
- ...transportFields,
101
- auth,
102
- url: Schema.String,
103
- cert: Schema.optionalKey(Schema.String),
104
- key: Schema.optionalKey(Schema.String),
105
- }),
106
- Schema.Struct({ ...transportFields, auth, unix: Schema.String }),
107
- Schema.Struct({
108
- ...transportFields,
109
- stdio: Schema.Literal(true),
110
- auth: Schema.optionalKey(
111
- Schema.Never.annotate({
112
- message: "Direct and stdio transports do not accept auth",
113
- }),
114
- ),
115
- identity: Schema.optionalKey(Schema.String),
116
- }),
117
- Schema.Struct({ ...transportFields, auth, transport: Reference }),
118
- ])
119
- export type Listen = typeof Listen.Type
9
+ export * from "../Config"
120
10
  const capability = (
121
11
  side: "host" | "runner",
122
12
  name: string,
@@ -124,7 +14,8 @@ const capability = (
124
14
  ): Reference => ({ name: `@graftland/plugin-remote/${side}/${name}`, config })
125
15
  export const authentication = (
126
16
  side: "host" | "runner",
127
- input: typeof Authentication.Type | undefined,
17
+ input:
18
+ typeof Authentication.Type | typeof RunnerAuthentication.Type | undefined,
128
19
  ): Reference => {
129
20
  if (input === undefined) return capability(side, "auth/none", {})
130
21
  if (input.name !== undefined) return input
@@ -169,19 +60,6 @@ export const runnerTransport = (input: Listen): Reference => {
169
60
  return capability("runner", "unix", { path: input.unix })
170
61
  return capability("runner", "stdio", {})
171
62
  }
172
- export const Host = Schema.Struct({
173
- contract: Schema.String,
174
- connect: Connect,
175
- config: Schema.Json.pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
176
- })
177
- export const Runner = Schema.Struct({
178
- root: Schema.String,
179
- state: Schema.String,
180
- lease: Schema.optionalKey(PositiveDuration),
181
- grace: Schema.optionalKey(PositiveDuration),
182
- listen: Schema.Array(Listen),
183
- })
184
-
185
63
  export const runnerAuthentication = (input: Listen): Reference =>
186
64
  input.stdio !== undefined
187
65
  ? capability("runner", "auth/none", {