@graftland/plugin-remote 0.3.0 → 0.3.2
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/dist/Auth.d.ts +2 -2
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js.map +1 -1
- package/dist/{Bootstrap-MCwivGN1.js → Bootstrap-H9gDsgsC.js} +2 -2
- package/dist/{Contract-CcpSIJm4.js → Contract-DsJtisvL.js} +8 -46
- package/dist/Contract.d.ts +50 -53
- package/dist/Contract.d.ts.map +1 -1
- package/dist/Contract.js +1 -1
- package/dist/Contract.js.map +1 -1
- package/dist/{Errors-oPsTLY7l.js → Errors-DYhsGZcZ.js} +14 -1
- package/dist/Errors.d.ts +19 -0
- package/dist/Errors.d.ts.map +1 -1
- package/dist/Errors.js +14 -1
- package/dist/Errors.js.map +1 -1
- package/dist/{FailureGroup-BcH0XOBi.js → FailureGroup-BgT73AaR.js} +14 -4
- package/dist/{Framing-zaYdOJnT.js → Framing-G9eSaeLb.js} +1 -1
- package/dist/{Graft-BsYq3F-J.js → Graft-B71CPA2Y.js} +46 -35
- package/dist/{Packages-B1TPk8pa.js → Packages-AgoCGotL.js} +23 -26
- package/dist/{Peer-IJgFK6mD.js → Peer-DXeVrGBh.js} +5 -5
- package/dist/{ProcessObservation-DEGrEMfP.js → ProcessObservation-gLgGirYv.js} +1 -1
- package/dist/{ServeLifecycle-CJM0gG5B.js → ServeLifecycle-Bd1FPJ6e.js} +1 -1
- package/dist/Testing.d.ts +4 -4
- package/dist/Testing.d.ts.map +1 -1
- package/dist/Testing.js +10 -4
- package/dist/Testing.js.map +1 -1
- package/dist/Transport.d.ts +2 -2
- package/dist/Transport.d.ts.map +1 -1
- package/dist/Transport.js.map +1 -1
- package/dist/bin.js +48 -47
- package/dist/bin.js.map +1 -1
- package/dist/{childRuntime-DSqtFN9o.js → childRuntime-Bm3iSg_N.js} +30 -26
- package/dist/connectionEnded-BwcxQ7W8.js +54 -0
- package/dist/{entry-SYsx9VNb.js → entry-psOpX3Bj.js} +76 -48
- package/dist/host/auth/bearer.d.ts +1 -2
- package/dist/host/auth/bearer.d.ts.map +1 -1
- package/dist/host/auth/bearer.js +1 -1
- package/dist/host/auth/bearer.js.map +1 -1
- package/dist/host/auth/jwt.d.ts +1 -2
- package/dist/host/auth/jwt.d.ts.map +1 -1
- package/dist/host/auth/jwt.js +1 -1
- package/dist/host/auth/jwt.js.map +1 -1
- package/dist/host/auth/mtls.js +2 -2
- package/dist/host/auth/none.js +1 -1
- package/dist/host/command.d.ts +1 -1
- package/dist/host/command.d.ts.map +1 -1
- package/dist/host/command.js +4 -4
- package/dist/host/command.js.map +1 -1
- package/dist/host/local.d.ts +1 -2
- package/dist/host/local.d.ts.map +1 -1
- package/dist/host/local.js +3 -3
- package/dist/host/local.js.map +1 -1
- package/dist/host/unix.d.ts +1 -1
- package/dist/host/unix.d.ts.map +1 -1
- package/dist/host/unix.js +3 -3
- package/dist/host/unix.js.map +1 -1
- package/dist/host/websocket.d.ts +1 -1
- package/dist/host/websocket.d.ts.map +1 -1
- package/dist/host/websocket.js +3 -3
- package/dist/host/websocket.js.map +1 -1
- package/dist/host/worker.d.ts +1 -2
- package/dist/host/worker.d.ts.map +1 -1
- package/dist/host/worker.js +4 -5
- package/dist/host/worker.js.map +1 -1
- package/dist/{importer-D7zSgqxq.js → importer-Cvf88eAY.js} +5 -8
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/internal/Certificates.js +4 -4
- package/dist/internal/Certificates.js.map +1 -1
- package/dist/internal/FailureGroup.js +3 -2
- package/dist/internal/FailureGroup.js.map +1 -1
- package/dist/internal/assembly.js +9 -2
- package/dist/internal/assembly.js.map +1 -1
- package/dist/internal/auth/mtls.js +1 -1
- package/dist/internal/auth/mtls.js.map +1 -1
- package/dist/internal/auth/tokenCredentials.d.ts +0 -1
- package/dist/internal/auth/tokenCredentials.d.ts.map +1 -1
- package/dist/internal/auth/tokenCredentials.js.map +1 -1
- package/dist/internal/child.js +20 -17
- package/dist/internal/child.js.map +1 -1
- package/dist/internal/childRuntime.js +6 -4
- package/dist/internal/childRuntime.js.map +1 -1
- package/dist/internal/contract.js +26 -0
- package/dist/internal/contract.js.map +1 -0
- package/dist/internal/credentials.d.ts +6 -6
- package/dist/internal/credentials.d.ts.map +1 -1
- package/dist/internal/credentials.js.map +1 -1
- package/dist/internal/directTransport.d.ts +1 -1
- package/dist/internal/entry.d.ts +1 -2
- package/dist/internal/entry.d.ts.map +1 -1
- package/dist/internal/entry.js +4 -14
- package/dist/internal/entry.js.map +1 -1
- package/dist/internal/execution.js +44 -7
- package/dist/internal/execution.js.map +1 -1
- package/dist/internal/host/runner.js +7 -6
- package/dist/internal/host/runner.js.map +1 -1
- package/dist/internal/host.js +5 -5
- package/dist/internal/host.js.map +1 -1
- package/dist/internal/port.d.ts +2 -10
- package/dist/internal/port.js +5 -5
- package/dist/internal/port.js.map +1 -1
- package/dist/internal/release.js +1 -1
- package/dist/internal/release.js.map +1 -1
- package/dist/internal/runner/Connection.d.ts +1 -1
- package/dist/internal/runner/Connection.js +4 -4
- package/dist/internal/runner/Connection.js.map +1 -1
- package/dist/internal/runner/Execution.js +3 -3
- package/dist/internal/runner/Execution.js.map +1 -1
- package/dist/internal/runner/Framing.d.ts +1 -11
- package/dist/internal/runner/Framing.js +1 -1
- package/dist/internal/runner/Framing.js.map +1 -1
- package/dist/internal/runner/Local.js +1 -1
- package/dist/internal/runner/Local.js.map +1 -1
- package/dist/internal/runner/Lock.js +1 -1
- package/dist/internal/runner/Lock.js.map +1 -1
- package/dist/internal/runner/Packages.d.ts +1 -1
- package/dist/internal/runner/Packages.js +22 -25
- package/dist/internal/runner/Packages.js.map +1 -1
- package/dist/internal/runner/Processes.js +7 -9
- package/dist/internal/runner/Processes.js.map +1 -1
- package/dist/internal/runner/Store.js +3 -3
- package/dist/internal/runner/Store.js.map +1 -1
- package/dist/internal/runner/Supervisor.js +46 -47
- package/dist/internal/runner/Supervisor.js.map +1 -1
- package/dist/internal/runner/accept.js +3 -3
- package/dist/internal/runner/accept.js.map +1 -1
- package/dist/internal/runner/model.js +1 -1
- package/dist/internal/runner/model.js.map +1 -1
- package/dist/internal/serve.js +1 -1
- package/dist/internal/serve.js.map +1 -1
- package/dist/internal/services.d.ts +2 -12
- package/dist/internal/services.d.ts.map +1 -1
- package/dist/internal/services.js.map +1 -1
- package/dist/internal/supervisorPlugin.js +1 -1
- package/dist/internal/watchdogMain.js +5 -5
- package/dist/internal/watchdogMain.js.map +1 -1
- package/dist/internal/websocketServer.js +3 -1
- package/dist/internal/websocketServer.js.map +1 -1
- package/dist/internal/workerMain.js +3 -3
- package/dist/{port-Blbh8tms.js → port--3x2zJ4D.js} +8 -8
- package/dist/{release-BY4Mlluy.js → release-DfZPuIcK.js} +1 -1
- package/dist/runner/auth/bearer.js +2 -2
- package/dist/runner/auth/jwt.js +4 -4
- package/dist/runner/auth/jwt.js.map +1 -1
- package/dist/runner/auth/mtls.js +3 -3
- package/dist/runner/auth/none.js +1 -1
- package/dist/runner/index.js +5 -5
- package/dist/runner/stdio.js +3 -3
- package/dist/runner/unix.js +3 -3
- package/dist/runner/websocket.js +4 -4
- package/dist/{socketChannel-KmtzF-9G.js → socketChannel-CJvL2DiB.js} +2 -2
- package/dist/{supervisorPlugin-Inb1S5IV.js → supervisorPlugin-t6Z6PrhD.js} +72 -76
- package/dist/{token-v5ne2I0-.js → token-CYBNNlhS.js} +1 -1
- package/dist/{tokenCredentials-WUJm2AKm.js → tokenCredentials-CbCuk-Rt.js} +3 -3
- package/dist/{websocketServer-MXcCJx0v.js → websocketServer-NQhODlEt.js} +5 -3
- package/dist/{workerChannel-P82YdNjh.js → workerChannel-C8hhBJzA.js} +1 -1
- package/package.json +3 -3
- package/src/Auth.ts +9 -2
- package/src/Contract.ts +67 -51
- package/src/Errors.ts +23 -0
- package/src/Testing.ts +16 -2
- package/src/Transport.ts +6 -2
- package/src/bin.ts +28 -30
- package/src/host/auth/bearer.ts +1 -6
- package/src/host/auth/jwt.ts +1 -6
- package/src/host/command.ts +2 -0
- package/src/host/local.ts +5 -9
- package/src/host/unix.ts +2 -0
- package/src/host/websocket.ts +2 -0
- package/src/host/worker.ts +4 -6
- package/src/index.ts +8 -4
- package/src/internal/Certificates.ts +10 -13
- package/src/internal/FailureGroup.ts +128 -121
- package/src/internal/assembly.ts +19 -10
- package/src/internal/auth/mtls.ts +19 -20
- package/src/internal/auth/tokenCredentials.ts +1 -7
- package/src/internal/child.ts +249 -240
- package/src/internal/childRuntime.ts +84 -81
- package/src/internal/contract.ts +47 -0
- package/src/internal/credentials.ts +12 -9
- package/src/internal/entry.ts +11 -25
- package/src/internal/execution.ts +73 -14
- package/src/internal/host/runner.ts +153 -153
- package/src/internal/host.ts +123 -130
- package/src/internal/port.ts +100 -103
- package/src/internal/release.ts +3 -2
- package/src/internal/runner/Connection.ts +52 -60
- package/src/internal/runner/Execution.ts +163 -164
- package/src/internal/runner/Framing.ts +9 -10
- package/src/internal/runner/Local.ts +26 -27
- package/src/internal/runner/Lock.ts +23 -25
- package/src/internal/runner/Packages.ts +67 -70
- package/src/internal/runner/Processes.ts +89 -92
- package/src/internal/runner/Store.ts +110 -114
- package/src/internal/runner/Supervisor.ts +392 -405
- package/src/internal/runner/accept.ts +76 -84
- package/src/internal/runner/model.ts +20 -21
- package/src/internal/serve.ts +15 -13
- package/src/internal/services.ts +1 -19
- package/src/internal/watchdogMain.ts +16 -11
- package/src/internal/websocketServer.ts +18 -3
- package/src/runner/auth/jwt.ts +10 -6
- package/dist/cleanup-BPWr-5U9.js +0 -13
- package/dist/connectionEnded-DUgcobEd.js +0 -9
- package/dist/internal/childErrors.d.ts +0 -33
- package/dist/internal/childErrors.d.ts.map +0 -1
- package/dist/internal/port.d.ts.map +0 -1
- package/dist/internal/runner/Framing.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"child.js","names":[],"sources":["../../src/internal/child.ts"],"sourcesContent":["import { loadModule } from \"./loadModule\"\nimport { AlreadyLoaded, ActivationFailed } from \"./childErrors\"\nimport { Graft, Plugin, type Fork } from \"@graftland/graft\"\nimport {\n\tArray,\n\tCause,\n\tData,\n\tDeferred,\n\tEffect,\n\tExit,\n\tFiber,\n\tLogger,\n\tMutableRef,\n\tOption,\n\tQueue,\n\tRef,\n\tReferences,\n\tScope,\n\tStream,\n\tSynchronizedRef,\n} from \"effect\"\nimport type { Schema } from \"effect\"\nimport { type RunnerContract } from \"../Contract\"\nimport { Instance, type Identity } from \"../Instance\"\nimport type * as Port from \"./port\"\nimport type { Event, Log, LogEvent } from \"./control\"\n\ntype Peer = Port.Port\ntype ChildEvent = Data.TaggedEnum<{\n\tFailed: { readonly cause: Cause.Cause<unknown> }\n\tWithdrawing: {}\n\tStopped: {}\n}>\nconst ChildEvent = Data.taggedEnum<ChildEvent>()\ntype LogEntry = Omit<typeof Log.Type, \"cause\"> & {\n\treadonly cause: Cause.Cause<unknown>\n}\n\n/** Queue data; serialization belongs to the RPC consumer, outside synchronous logger callbacks. */\nexport const telemetry = (contract: RunnerContract) =>\n\tEffect.gen(function* () {\n\t\tconst events = yield* Queue.bounded<ChildEvent>(2)\n\t\tconst logs = yield* Queue.dropping<LogEntry, Cause.Done>(128)\n\t\tconst dropped = MutableRef.make(0)\n\t\tconst encode = (cause: Cause.Cause<unknown>) =>\n\t\t\tcontract.encodeCause(cause).pipe(Effect.orDie)\n\t\tconst logger = Logger.make((entry) => {\n\t\t\t// Logger callbacks are synchronous; a dropping offer and loss counter cannot suspend.\n\t\t\tconst accepted = Queue.offerUnsafe(logs, {\n\t\t\t\tlevel: entry.logLevel,\n\t\t\t\tmessage: entry.message,\n\t\t\t\tcause: entry.cause,\n\t\t\t\tannotations: entry.fiber.getRef(References.CurrentLogAnnotations),\n\t\t\t})\n\t\t\tif (!accepted) MutableRef.increment(dropped)\n\t\t})\n\t\treturn {\n\t\t\tevents,\n\t\t\tlogs,\n\t\t\tlogger,\n\t\t\teventStream: Stream.fromQueue(events).pipe(\n\t\t\t\tStream.mapEffect((event): Effect.Effect<typeof Event.Type> =>\n\t\t\t\t\tevent._tag === \"Failed\"\n\t\t\t\t\t\t? encode(event.cause).pipe(\n\t\t\t\t\t\t\t\tEffect.map(\n\t\t\t\t\t\t\t\t\t(cause) =>\n\t\t\t\t\t\t\t\t\t\t({\n\t\t\t\t\t\t\t\t\t\t\t_tag: \"Failed\",\n\t\t\t\t\t\t\t\t\t\t\tcause,\n\t\t\t\t\t\t\t\t\t\t}) satisfies typeof Event.Type,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: Effect.succeed(event),\n\t\t\t\t),\n\t\t\t),\n\t\t\tlogStream: Stream.fromQueue(logs).pipe(\n\t\t\t\tStream.mapEffect((entry) =>\n\t\t\t\t\tencode(entry.cause).pipe(\n\t\t\t\t\t\tEffect.map((cause): typeof LogEvent.Type => ({\n\t\t\t\t\t\t\t_tag: \"Log\",\n\t\t\t\t\t\t\tentry: { ...entry, cause },\n\t\t\t\t\t\t\tdropped: MutableRef.get(dropped),\n\t\t\t\t\t\t})),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\tStream.concat(\n\t\t\t\t\tStream.sync((): typeof LogEvent.Type => ({\n\t\t\t\t\t\t_tag: \"LogsEnded\",\n\t\t\t\t\t\tdropped: MutableRef.get(dropped),\n\t\t\t\t\t})),\n\t\t\t\t),\n\t\t\t),\n\t\t}\n\t})\ntype Telemetry = Effect.Success<ReturnType<typeof telemetry>>\ninterface Running {\n\treadonly fork: Pick<Fork.Fork<never, unknown>, \"dispose\" | \"state\">\n\treadonly bridge: Pick<Fork.Fork<never, never>, \"dispose\" | \"state\">\n\treadonly observation: Fiber.Fiber<void>\n\treadonly observedFailure: Ref.Ref<Cause.Cause<unknown>>\n}\ntype Lifecycle = Data.TaggedEnum<{\n\tIdle: {}\n\tLoading: {}\n\tRunning: { readonly running: Running }\n\tWithdrawing: { readonly running: Option.Option<Running> }\n\tDisposing: { readonly running: Option.Option<Running> }\n}>\nconst Lifecycle = Data.taggedEnum<Lifecycle>()\nconst runningOf = (state: Lifecycle): Option.Option<Running> =>\n\tstate._tag === \"Running\"\n\t\t? Option.some(state.running)\n\t\t: state._tag === \"Withdrawing\" || state._tag === \"Disposing\"\n\t\t\t? state.running\n\t\t\t: Option.none()\n\nconst cleanup = (running: Running, retired: boolean) =>\n\tEffect.gen(function* () {\n\t\tconst pluginExit = yield* Effect.exit(running.fork.dispose)\n\t\tconst bridgeExit = yield* Effect.exit(running.bridge.dispose)\n\t\tyield* Fiber.join(running.observation)\n\t\tconst failed = yield* Ref.get(running.observedFailure)\n\t\treturn Array.reduce(\n\t\t\t[bridgeExit, pluginExit],\n\t\t\tretired ? failed : Cause.empty,\n\t\t\t(cause, exit) =>\n\t\t\t\tExit.isFailure(exit)\n\t\t\t\t\t? Cause.combine(\n\t\t\t\t\t\t\tcause,\n\t\t\t\t\t\t\tCause.fromReasons(\n\t\t\t\t\t\t\t\tArray.flatMap(exit.cause.reasons, (reason) =>\n\t\t\t\t\t\t\t\t\treason._tag === \"Fail\"\n\t\t\t\t\t\t\t\t\t\t? reason.error.cause.reasons\n\t\t\t\t\t\t\t\t\t\t: [reason],\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t: cause,\n\t\t)\n\t})\n\nexport const lifecycle = (\n\tcontract: RunnerContract,\n\tpeer: Peer,\n\tidentity: typeof Identity.Type,\n\ttelemetry: Telemetry,\n) =>\n\tEffect.gen(function* () {\n\t\tconst scope = yield* Effect.scope\n\t\tconst instanceScope = yield* Scope.fork(scope)\n\t\tconst releaseExports = yield* Deferred.make<void>()\n\t\tconst state = yield* SynchronizedRef.make<Lifecycle>(Lifecycle.Idle())\n\t\t// This gate represents host consumers draining, not a second lifecycle state.\n\t\tconst release = SynchronizedRef.update(state, (current) =>\n\t\t\tLifecycle.Disposing({ running: runningOf(current) }),\n\t\t).pipe(Effect.andThen(Deferred.succeed(releaseExports, undefined)))\n\n\t\tconst exportBridge = Graft.plugin(\n\t\t\tPlugin.make({\n\t\t\t\tname: `${contract.name}/exports`,\n\t\t\t\tinject: Array.map(contract.provides, (service) => service.key),\n\t\t\t\tapply: () =>\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tfor (const service of contract.provides)\n\t\t\t\t\t\t\tyield* service.serve(peer).pipe(\n\t\t\t\t\t\t\t\tEffect.tapCause((cause) =>\n\t\t\t\t\t\t\t\t\tCause.hasInterruptsOnly(cause)\n\t\t\t\t\t\t\t\t\t\t? Effect.void\n\t\t\t\t\t\t\t\t\t\t: Queue.offer(\n\t\t\t\t\t\t\t\t\t\t\t\ttelemetry.events,\n\t\t\t\t\t\t\t\t\t\t\t\tChildEvent.Failed({ cause }),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tEffect.forkScoped,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\tyield* Effect.addFinalizer(() =>\n\t\t\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\t\t\tconst withdrawing = yield* SynchronizedRef.modify(\n\t\t\t\t\t\t\t\t\tstate,\n\t\t\t\t\t\t\t\t\t(current) =>\n\t\t\t\t\t\t\t\t\t\tcurrent._tag === \"Disposing\"\n\t\t\t\t\t\t\t\t\t\t\t? [false, current]\n\t\t\t\t\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t\t\t\t\t\t\tLifecycle.Withdrawing({\n\t\t\t\t\t\t\t\t\t\t\t\t\t\trunning: runningOf(current),\n\t\t\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tif (withdrawing)\n\t\t\t\t\t\t\t\t\tyield* Queue.offer(telemetry.events, ChildEvent.Withdrawing())\n\t\t\t\t\t\t\t\tyield* Deferred.await(releaseExports)\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t}),\n\t\t\t}),\n\t\t).pipe(Scope.provide(instanceScope))\n\n\t\tconst start = (input: Schema.Json) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\t// Imported clients outlive Load and remain available during plugin cleanup.\n\t\t\t\tfor (const service of contract.inject)\n\t\t\t\t\tyield* service.publish(peer).pipe(\n\t\t\t\t\t\tScope.provide(scope),\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\tActivationFailed.make({\n\t\t\t\t\t\t\t\tdetail: \"Publishing imported services failed\",\n\t\t\t\t\t\t\t\tcause: Cause.fail(error),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\tconst module = yield* loadModule(contract.module)\n\t\t\t\tconst plugin = Plugin.fromModule(module)\n\t\t\t\tif (Option.isNone(plugin))\n\t\t\t\t\treturn yield* ActivationFailed.make({\n\t\t\t\t\t\tdetail: \"The implementation module exports no plugin\",\n\t\t\t\t\t})\n\t\t\t\tconst fork = yield* Graft.plugin(\n\t\t\t\t\t{ ...plugin.value, retry: undefined },\n\t\t\t\t\tinput,\n\t\t\t\t).pipe(\n\t\t\t\t\tEffect.provideService(Instance, identity),\n\t\t\t\t\tScope.provide(instanceScope),\n\t\t\t\t)\n\t\t\t\tconst observedFailure = yield* Ref.make<Cause.Cause<unknown>>(\n\t\t\t\t\tCause.empty,\n\t\t\t\t)\n\t\t\t\tconst observation = yield* fork.state.pipe(\n\t\t\t\t\tStream.runForEach((state) =>\n\t\t\t\t\t\tstate._tag === \"Failed\"\n\t\t\t\t\t\t\t? Ref.set(observedFailure, state.cause)\n\t\t\t\t\t\t\t: Effect.void,\n\t\t\t\t\t),\n\t\t\t\t\tEffect.forkIn(instanceScope),\n\t\t\t\t)\n\t\t\t\tconst bridge = yield* exportBridge\n\t\t\t\treturn { fork, bridge, observedFailure, observation } satisfies Running\n\t\t\t})\n\t\tconst awaitActive = (running: Running) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst first = yield* running.fork.state.pipe(\n\t\t\t\t\tStream.filter((state) => state._tag !== \"Loading\"),\n\t\t\t\t\tStream.runHead,\n\t\t\t\t)\n\t\t\t\tif (Option.isNone(first))\n\t\t\t\t\treturn yield* ActivationFailed.make({\n\t\t\t\t\t\tdetail: \"The remote fork disappeared during startup\",\n\t\t\t\t\t})\n\t\t\t\tif (first.value._tag === \"Failed\")\n\t\t\t\t\treturn yield* Effect.fail(contract.normalizeCause(first.value.cause))\n\t\t\t\tif (first.value._tag !== \"Active\")\n\t\t\t\t\treturn yield* ActivationFailed.make({\n\t\t\t\t\t\tdetail:\n\t\t\t\t\t\t\t\"The remote plugin did not become active; check its declared dependencies\",\n\t\t\t\t\t})\n\t\t\t\tyield* running.fork.state.pipe(\n\t\t\t\t\tStream.runForEach((state) =>\n\t\t\t\t\t\tstate._tag === \"Failed\"\n\t\t\t\t\t\t\t? Queue.offer(\n\t\t\t\t\t\t\t\t\ttelemetry.events,\n\t\t\t\t\t\t\t\t\tChildEvent.Failed({ cause: state.cause }),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: Effect.void,\n\t\t\t\t\t),\n\t\t\t\t\tEffect.forkIn(instanceScope),\n\t\t\t\t)\n\t\t\t\tconst exported = yield* running.bridge.state.pipe(\n\t\t\t\t\tStream.filter(\n\t\t\t\t\t\t(state) =>\n\t\t\t\t\t\t\tstate._tag === \"Active\" ||\n\t\t\t\t\t\t\tstate._tag === \"Failed\" ||\n\t\t\t\t\t\t\tstate._tag === \"Disposed\",\n\t\t\t\t\t),\n\t\t\t\t\tStream.runHead,\n\t\t\t\t)\n\t\t\t\tif (Option.isSome(exported) && exported.value._tag === \"Failed\")\n\t\t\t\t\treturn yield* ActivationFailed.make({\n\t\t\t\t\t\tdetail: \"The remote export bridge failed during startup\",\n\t\t\t\t\t\tcause: exported.value.cause,\n\t\t\t\t\t})\n\t\t\t\tif (Option.isNone(exported) || exported.value._tag !== \"Active\")\n\t\t\t\t\treturn yield* ActivationFailed.make({\n\t\t\t\t\t\tdetail: \"The remote export bridge stopped during startup\",\n\t\t\t\t\t})\n\t\t\t})\n\t\tconst load = (input: Schema.Json) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tyield* SynchronizedRef.updateEffect(state, (current) =>\n\t\t\t\t\tcurrent._tag === \"Idle\"\n\t\t\t\t\t\t? Effect.succeed(Lifecycle.Loading())\n\t\t\t\t\t\t: Effect.fail(AlreadyLoaded.make({})),\n\t\t\t\t)\n\t\t\t\tconst running = yield* start(input)\n\t\t\t\tyield* SynchronizedRef.update(state, (current) =>\n\t\t\t\t\tcurrent._tag === \"Withdrawing\"\n\t\t\t\t\t\t? Lifecycle.Withdrawing({ running: Option.some(running) })\n\t\t\t\t\t\t: current._tag === \"Disposing\"\n\t\t\t\t\t\t\t? Lifecycle.Disposing({ running: Option.some(running) })\n\t\t\t\t\t\t\t: Lifecycle.Running({ running }),\n\t\t\t\t)\n\t\t\t\tyield* awaitActive(running)\n\t\t\t}).pipe(\n\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\tCause.isCause(error)\n\t\t\t\t\t\t? error\n\t\t\t\t\t\t: contract.normalizeCause(Cause.fail(error)),\n\t\t\t\t),\n\t\t\t)\n\t\tconst dispose = Effect.gen(function* () {\n\t\t\tconst previous = yield* SynchronizedRef.get(state)\n\t\t\tyield* release\n\t\t\tconst current = runningOf(previous)\n\t\t\tconst retired = previous._tag === \"Withdrawing\"\n\t\t\tconst cause = Option.isSome(current)\n\t\t\t\t? yield* cleanup(current.value, retired)\n\t\t\t\t: Cause.empty\n\t\t\tyield* Queue.offer(telemetry.events, ChildEvent.Stopped())\n\t\t\tyield* Queue.end(telemetry.logs)\n\t\t\tif (cause.reasons.length > 0)\n\t\t\t\treturn yield* Effect.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AK,CAAC,CAAC,CAAC,CACtC;EACA,MAAM,UAAU,OAAO,MAAM,KAAK;EAClC,OAAO,gBAAgB,OAAO,QAAQ,YACrC,QAAQ,SAAS,gBACd,UAAU,YAAY,EAAE,SAAS,OAAO,KAAK,OAAO,EAAE,CAAC,IACvD,QAAQ,SAAS,cAChB,UAAU,UAAU,EAAE,SAAS,OAAO,KAAK,OAAO,EAAE,CAAC,IACrD,UAAU,QAAQ,EAAE,QAAQ,CAAC,CAClC;EACA,OAAO,YAAY,OAAO;CAC3B,CAAC,CAAC,CAAC,KACF,OAAO,UAAU,UAChB,MAAM,QAAQ,KAAK,IAChB,QACA,SAAS,eAAe,MAAM,KAAK,KAAK,CAAC,CAC7C,CACD;CAcD,OAAO;EAAE;EAAM,SAbC,OAAO,IAAI,aAAa;GACvC,MAAM,WAAW,OAAO,gBAAgB,IAAI,KAAK;GACjD,OAAO;GACP,MAAM,UAAU,UAAU,QAAQ;GAClC,MAAM,UAAU,SAAS,SAAS;GAClC,MAAM,QAAQ,OAAO,OAAO,OAAO,IAChC,OAAO,QAAQ,QAAQ,OAAO,OAAO,IACrC,MAAM;GACT,OAAO,MAAM,MAAM,UAAU,QAAQ,WAAW,QAAQ,CAAC;GACzD,OAAO,MAAM,IAAI,UAAU,IAAI;GAC/B,IAAI,MAAM,QAAQ,SAAS,GAC1B,OAAO,OAAO,OAAO,KAAK,SAAS,eAAe,KAAK,CAAC;EAC1D,CACqB;EAAG;CAAQ;AACjC,CAAC"}
|
|
1
|
+
{"version":3,"file":"child.js","names":[],"sources":["../../src/internal/child.ts"],"sourcesContent":["import { loadModule } from \"./loadModule\"\nimport { AlreadyLoaded, ActivationFailed } from \"./childErrors\"\nimport { Graft, Plugin, type Fork } from \"@graftland/graft\"\nimport {\n\tArray,\n\tCause,\n\tData,\n\tDeferred,\n\tEffect,\n\tExit,\n\tFiber,\n\tLogger,\n\tMutableRef,\n\tOption,\n\tQueue,\n\tRef,\n\tReferences,\n\tScope,\n\tStream,\n\tSynchronizedRef,\n} from \"effect\"\nimport type { Schema } from \"effect\"\nimport { type RunnerContract } from \"./contract\"\nimport { Instance, type Identity } from \"../Instance\"\nimport type * as Port from \"./port\"\nimport type { Event, Log, LogEvent } from \"./control\"\n\ntype Peer = Port.Port\ntype ChildEvent = Data.TaggedEnum<{\n\tFailed: { readonly cause: Cause.Cause<unknown> }\n\tWithdrawing: {}\n\tStopped: {}\n}>\nconst ChildEvent = Data.taggedEnum<ChildEvent>()\ntype LogEntry = Omit<typeof Log.Type, \"cause\"> & {\n\treadonly cause: Cause.Cause<unknown>\n}\n\n/** Queue data; serialization belongs to the RPC consumer, outside synchronous logger callbacks. */\nexport const telemetry = Effect.fnUntraced(function* (\n\tcontract: RunnerContract,\n) {\n\tconst events = yield* Queue.bounded<ChildEvent>(2)\n\tconst logs = yield* Queue.dropping<LogEntry, Cause.Done>(128)\n\tconst dropped = MutableRef.make(0)\n\tconst encode = (cause: Cause.Cause<unknown>) =>\n\t\tcontract.encodeCause(cause).pipe(Effect.orDie)\n\tconst logger = Logger.make((entry) => {\n\t\t// Logger callbacks are synchronous; a dropping offer and loss counter cannot suspend.\n\t\tconst accepted = Queue.offerUnsafe(logs, {\n\t\t\tlevel: entry.logLevel,\n\t\t\tmessage: entry.message,\n\t\t\tcause: entry.cause,\n\t\t\tannotations: entry.fiber.getRef(References.CurrentLogAnnotations),\n\t\t})\n\t\tif (!accepted) MutableRef.increment(dropped)\n\t})\n\treturn {\n\t\tevents,\n\t\tlogs,\n\t\tlogger,\n\t\teventStream: Stream.fromQueue(events).pipe(\n\t\t\tStream.mapEffect((event): Effect.Effect<typeof Event.Type> =>\n\t\t\t\tevent._tag === \"Failed\"\n\t\t\t\t\t? encode(event.cause).pipe(\n\t\t\t\t\t\t\tEffect.map(\n\t\t\t\t\t\t\t\t(cause) =>\n\t\t\t\t\t\t\t\t\t({\n\t\t\t\t\t\t\t\t\t\t_tag: \"Failed\",\n\t\t\t\t\t\t\t\t\t\tcause,\n\t\t\t\t\t\t\t\t\t}) satisfies typeof Event.Type,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t: Effect.succeed(event),\n\t\t\t),\n\t\t),\n\t\tlogStream: Stream.fromQueue(logs).pipe(\n\t\t\tStream.mapEffect((entry) =>\n\t\t\t\tencode(entry.cause).pipe(\n\t\t\t\t\tEffect.map((cause): typeof LogEvent.Type => ({\n\t\t\t\t\t\t_tag: \"Log\",\n\t\t\t\t\t\tentry: { ...entry, cause },\n\t\t\t\t\t\tdropped: MutableRef.get(dropped),\n\t\t\t\t\t})),\n\t\t\t\t),\n\t\t\t),\n\t\t\tStream.concat(\n\t\t\t\tStream.sync((): typeof LogEvent.Type => ({\n\t\t\t\t\t_tag: \"LogsEnded\",\n\t\t\t\t\tdropped: MutableRef.get(dropped),\n\t\t\t\t})),\n\t\t\t),\n\t\t),\n\t}\n})\ntype Telemetry = Effect.Success<ReturnType<typeof telemetry>>\ninterface Running {\n\treadonly fork: Pick<Fork.Fork<never, unknown>, \"dispose\" | \"state\">\n\treadonly bridge: Pick<Fork.Fork<never, never>, \"dispose\" | \"state\">\n\treadonly observation: Fiber.Fiber<void>\n\treadonly observedFailure: Ref.Ref<Cause.Cause<unknown>>\n}\ntype Lifecycle = Data.TaggedEnum<{\n\tIdle: {}\n\tLoading: {}\n\tRunning: { readonly running: Running }\n\tWithdrawing: { readonly running: Option.Option<Running> }\n\tDisposing: { readonly running: Option.Option<Running> }\n}>\nconst Lifecycle = Data.taggedEnum<Lifecycle>()\nconst runningOf = (state: Lifecycle): Option.Option<Running> =>\n\tstate._tag === \"Running\"\n\t\t? Option.some(state.running)\n\t\t: state._tag === \"Withdrawing\" || state._tag === \"Disposing\"\n\t\t\t? state.running\n\t\t\t: Option.none()\n\nconst cleanup = Effect.fnUntraced(function* (\n\trunning: Running,\n\tretired: boolean,\n) {\n\tconst pluginExit = yield* Effect.exit(running.fork.dispose)\n\tconst bridgeExit = yield* Effect.exit(running.bridge.dispose)\n\tyield* Fiber.join(running.observation)\n\tconst failed = yield* Ref.get(running.observedFailure)\n\treturn Array.reduce(\n\t\t[bridgeExit, pluginExit],\n\t\tretired ? failed : Cause.empty,\n\t\t(cause, exit) =>\n\t\t\tExit.isFailure(exit)\n\t\t\t\t? Cause.combine(\n\t\t\t\t\t\tcause,\n\t\t\t\t\t\tCause.fromReasons(\n\t\t\t\t\t\t\tArray.flatMap(exit.cause.reasons, (reason) =>\n\t\t\t\t\t\t\t\treason._tag === \"Fail\" ? reason.error.cause.reasons : [reason],\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t: cause,\n\t)\n})\n\nexport const lifecycle = Effect.fnUntraced(function* (\n\tcontract: RunnerContract,\n\tpeer: Peer,\n\tidentity: typeof Identity.Type,\n\ttelemetry: Telemetry,\n) {\n\tconst scope = yield* Effect.scope\n\tconst instanceScope = yield* Scope.fork(scope)\n\tconst releaseExports = yield* Deferred.make<void>()\n\tconst state = yield* SynchronizedRef.make<Lifecycle>(Lifecycle.Idle())\n\t// This gate represents host consumers draining, not a second lifecycle state.\n\tconst disposing = (current: Lifecycle) =>\n\t\tLifecycle.Disposing({ running: runningOf(current) })\n\tconst release = SynchronizedRef.update(state, disposing).pipe(\n\t\tEffect.andThen(Deferred.succeed(releaseExports, undefined)),\n\t)\n\n\tconst exportBridge = Graft.plugin(\n\t\tPlugin.make({\n\t\t\tname: `${contract.name}/exports`,\n\t\t\tinject: Array.map(contract.provides, (service) => service.key),\n\t\t\tapply: Effect.fnUntraced(function* () {\n\t\t\t\tfor (const service of contract.provides)\n\t\t\t\t\tyield* service.serve(peer).pipe(\n\t\t\t\t\t\tEffect.tapCause((cause) =>\n\t\t\t\t\t\t\tCause.hasInterruptsOnly(cause)\n\t\t\t\t\t\t\t\t? Effect.void\n\t\t\t\t\t\t\t\t: Queue.offer(telemetry.events, ChildEvent.Failed({ cause })),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tEffect.forkScoped,\n\t\t\t\t\t)\n\t\t\t\tyield* Effect.addFinalizer(\n\t\t\t\t\tEffect.fnUntraced(function* () {\n\t\t\t\t\t\tconst withdrawing = yield* SynchronizedRef.modify(\n\t\t\t\t\t\t\tstate,\n\t\t\t\t\t\t\t(current) =>\n\t\t\t\t\t\t\t\tcurrent._tag === \"Disposing\"\n\t\t\t\t\t\t\t\t\t? [false, current]\n\t\t\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t\t\t\t\tLifecycle.Withdrawing({\n\t\t\t\t\t\t\t\t\t\t\t\trunning: runningOf(current),\n\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (withdrawing)\n\t\t\t\t\t\t\tyield* Queue.offer(telemetry.events, ChildEvent.Withdrawing())\n\t\t\t\t\t\tyield* Deferred.await(releaseExports)\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t}),\n\t\t}),\n\t).pipe(Scope.provide(instanceScope))\n\n\tconst start = Effect.fnUntraced(function* (input: Schema.Json) {\n\t\t// Imported clients outlive Load and remain available during plugin cleanup.\n\t\tfor (const service of contract.inject)\n\t\t\tyield* service.publish(peer).pipe(\n\t\t\t\tScope.provide(scope),\n\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\tActivationFailed.make({\n\t\t\t\t\t\tdetail: \"Publishing imported services failed\",\n\t\t\t\t\t\tcause: Cause.fail(error),\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t)\n\t\tconst module = yield* loadModule(contract.module)\n\t\tconst plugin = Plugin.fromModule(module)\n\t\tif (Option.isNone(plugin))\n\t\t\treturn yield* ActivationFailed.make({\n\t\t\t\tdetail: \"The implementation module exports no plugin\",\n\t\t\t})\n\t\tconst fork = yield* Graft.plugin(\n\t\t\t{ ...plugin.value, retry: undefined },\n\t\t\tinput,\n\t\t).pipe(\n\t\t\tEffect.provideService(Instance, identity),\n\t\t\tScope.provide(instanceScope),\n\t\t)\n\t\tconst observedFailure = yield* Ref.make<Cause.Cause<unknown>>(Cause.empty)\n\t\tconst observation = yield* fork.state.pipe(\n\t\t\tStream.runForEach((state) =>\n\t\t\t\tstate._tag === \"Failed\"\n\t\t\t\t\t? Ref.set(observedFailure, state.cause)\n\t\t\t\t\t: Effect.void,\n\t\t\t),\n\t\t\tEffect.forkIn(instanceScope),\n\t\t)\n\t\tconst bridge = yield* exportBridge\n\t\treturn { fork, bridge, observedFailure, observation } satisfies Running\n\t})\n\tconst awaitActive = Effect.fnUntraced(function* (running: Running) {\n\t\tconst first = yield* running.fork.state.pipe(\n\t\t\tStream.filter((state) => state._tag !== \"Loading\"),\n\t\t\tStream.runHead,\n\t\t)\n\t\tif (Option.isNone(first))\n\t\t\treturn yield* ActivationFailed.make({\n\t\t\t\tdetail: \"The remote fork disappeared during startup\",\n\t\t\t})\n\t\tif (first.value._tag === \"Failed\")\n\t\t\treturn yield* Effect.fail(contract.normalizeCause(first.value.cause))\n\t\tif (first.value._tag !== \"Active\")\n\t\t\treturn yield* ActivationFailed.make({\n\t\t\t\tdetail:\n\t\t\t\t\t\"The remote plugin did not become active; check its declared dependencies\",\n\t\t\t})\n\t\tyield* running.fork.state.pipe(\n\t\t\tStream.runForEach((state) =>\n\t\t\t\tstate._tag === \"Failed\"\n\t\t\t\t\t? Queue.offer(\n\t\t\t\t\t\t\ttelemetry.events,\n\t\t\t\t\t\t\tChildEvent.Failed({ cause: state.cause }),\n\t\t\t\t\t\t)\n\t\t\t\t\t: Effect.void,\n\t\t\t),\n\t\t\tEffect.forkIn(instanceScope),\n\t\t)\n\t\tconst exported = yield* running.bridge.state.pipe(\n\t\t\tStream.filter(\n\t\t\t\t(state) =>\n\t\t\t\t\tstate._tag === \"Active\" ||\n\t\t\t\t\tstate._tag === \"Failed\" ||\n\t\t\t\t\tstate._tag === \"Disposed\",\n\t\t\t),\n\t\t\tStream.runHead,\n\t\t)\n\t\tif (Option.isSome(exported) && exported.value._tag === \"Failed\")\n\t\t\treturn yield* ActivationFailed.make({\n\t\t\t\tdetail: \"The remote export bridge failed during startup\",\n\t\t\t\tcause: exported.value.cause,\n\t\t\t})\n\t\tif (Option.isNone(exported) || exported.value._tag !== \"Active\")\n\t\t\treturn yield* ActivationFailed.make({\n\t\t\t\tdetail: \"The remote export bridge stopped during startup\",\n\t\t\t})\n\t})\n\tconst load = Effect.fnUntraced(\n\t\tfunction* (input: Schema.Json) {\n\t\t\tyield* SynchronizedRef.updateEffect(state, (current) =>\n\t\t\t\tcurrent._tag === \"Idle\"\n\t\t\t\t\t? Effect.succeed(Lifecycle.Loading())\n\t\t\t\t\t: Effect.fail(AlreadyLoaded.make({})),\n\t\t\t)\n\t\t\tconst running = yield* start(input)\n\t\t\tconst disposed = yield* SynchronizedRef.modify(\n\t\t\t\tstate,\n\t\t\t\t(current): readonly [boolean, Lifecycle] =>\n\t\t\t\t\tcurrent._tag === \"Withdrawing\"\n\t\t\t\t\t\t? [false, Lifecycle.Withdrawing({ running: Option.some(running) })]\n\t\t\t\t\t\t: current._tag === \"Disposing\"\n\t\t\t\t\t\t\t? [true, Lifecycle.Disposing({ running: Option.some(running) })]\n\t\t\t\t\t\t\t: [false, Lifecycle.Running({ running })],\n\t\t\t)\n\t\t\t// Dispose saw Loading and found nothing to stop; this load owns the cleanup.\n\t\t\tif (disposed) {\n\t\t\t\tconst cause = yield* cleanup(running, false)\n\t\t\t\treturn yield* Effect.fail(\n\t\t\t\t\tCause.combine(\n\t\t\t\t\t\tCause.fail(\n\t\t\t\t\t\t\tActivationFailed.make({\n\t\t\t\t\t\t\t\tdetail: \"The execution was disposed during load\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tcause,\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t}\n\t\t\tyield* awaitActive(running)\n\t\t},\n\t\tEffect.mapError((error) =>\n\t\t\tcontract.normalizeCause(Cause.isCause(error) ? error : Cause.fail(error)),\n\t\t),\n\t)\n\tconst dispose = Effect.gen(function* () {\n\t\t// One transition, so a concurrent Load or export withdrawal cannot slip between read and write.\n\t\tconst previous = yield* SynchronizedRef.getAndUpdate(state, disposing)\n\t\tyield* Deferred.succeed(releaseExports, undefined)\n\t\tconst current = runningOf(previous)\n\t\tconst retired = previous._tag === \"Withdrawing\"\n\t\tconst cause = Option.isSome(current)\n\t\t\t? yield* cleanup(current.value, retired)\n\t\t\t: Cause.empty\n\t\tyield* Queue.offer(telemetry.events, ChildEvent.Stopped())\n\t\tyield* Queue.end(telemetry.logs)\n\t\tif (cause.reasons.length > 0)\n\t\t\treturn yield* Effect.fail(contract.normalizeCause(cause))\n\t})\n\treturn { load, dispose, release }\n})\n"],"mappings":";;;;;;AAiCA,MAAM,aAAa,KAAK,WAAuB;;AAM/C,MAAa,YAAY,OAAO,WAAW,WAC1C,UACC;CACD,MAAM,SAAS,OAAO,MAAM,QAAoB,CAAC;CACjD,MAAM,OAAO,OAAO,MAAM,SAA+B,GAAG;CAC5D,MAAM,UAAU,WAAW,KAAK,CAAC;CACjC,MAAM,UAAU,UACf,SAAS,YAAY,KAAK,CAAC,CAAC,KAAK,OAAO,KAAK;CAW9C,OAAO;EACN;EACA;EACA,QAbc,OAAO,MAAM,UAAU;GAQrC,IAAI,CANa,MAAM,YAAY,MAAM;IACxC,OAAO,MAAM;IACb,SAAS,MAAM;IACf,OAAO,MAAM;IACb,aAAa,MAAM,MAAM,OAAO,WAAW,qBAAqB;GACjE,CACY,GAAG,WAAW,UAAU,OAAO;EAC5C,CAIM;EACL,aAAa,OAAO,UAAU,MAAM,CAAC,CAAC,KACrC,OAAO,WAAW,UACjB,MAAM,SAAS,WACZ,OAAO,MAAM,KAAK,CAAC,CAAC,KACpB,OAAO,KACL,WACC;GACA,MAAM;GACN;EACD,EACF,CACD,IACC,OAAO,QAAQ,KAAK,CACxB,CACD;EACA,WAAW,OAAO,UAAU,IAAI,CAAC,CAAC,KACjC,OAAO,WA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ACjD,MAAM,UAAU,UAAU,QAAQ;GAClC,MAAM,UAAU,SAAS,SAAS;GAClC,MAAM,QAAQ,OAAO,OAAO,OAAO,IAChC,OAAO,QAAQ,QAAQ,OAAO,OAAO,IACrC,MAAM;GACT,OAAO,MAAM,MAAM,UAAU,QAAQ,WAAW,QAAQ,CAAC;GACzD,OAAO,MAAM,IAAI,UAAU,IAAI;GAC/B,IAAI,MAAM,QAAQ,SAAS,GAC1B,OAAO,OAAO,OAAO,KAAK,SAAS,eAAe,KAAK,CAAC;EAC1D,CACqB;EAAG;CAAQ;AACjC,CAAC"}
|
|
@@ -2,6 +2,7 @@ import { loadModule } from "./loadModule.js";
|
|
|
2
2
|
import { ContractNotFound } from "./childErrors.js";
|
|
3
3
|
import { fromModule } from "../Contract.js";
|
|
4
4
|
import { make } from "./port.js";
|
|
5
|
+
import { prepare } from "./contract.js";
|
|
5
6
|
import { endpoints } from "./services.js";
|
|
6
7
|
import { lifecycle, telemetry } from "./child.js";
|
|
7
8
|
import { make as make$1 } from "./runner/Multiplex.js";
|
|
@@ -13,13 +14,13 @@ import { Effect, Logger, Option } from "effect";
|
|
|
13
14
|
import { RpcServer } from "effect/rpc";
|
|
14
15
|
// src/internal/childRuntime.ts
|
|
15
16
|
/** Import a contract in the runner installation; importing this module performs no I/O. */
|
|
16
|
-
const load =
|
|
17
|
+
const load = Effect.fnUntraced(function* (specifier) {
|
|
17
18
|
const module = yield* loadModule(specifier);
|
|
18
19
|
const contract = fromModule(module);
|
|
19
20
|
if (Option.isNone(contract)) return yield* ContractNotFound.make({ module: specifier });
|
|
20
21
|
return contract.value;
|
|
21
22
|
});
|
|
22
|
-
const connect = (contract, channel$1, session, bootstrap)
|
|
23
|
+
const connect = Effect.fnUntraced(function* (contract, channel$1, session, bootstrap) {
|
|
23
24
|
const mux = bootstrap === void 0 ? void 0 : yield* make$1(channel$1);
|
|
24
25
|
return yield* make(mux === void 0 ? channel$1 : channel(mux, 1), {
|
|
25
26
|
session,
|
|
@@ -32,7 +33,8 @@ const connect = (contract, channel$1, session, bootstrap) => Effect.gen(function
|
|
|
32
33
|
});
|
|
33
34
|
});
|
|
34
35
|
/** One execution unit; the executable supplies the platform and Graft services. */
|
|
35
|
-
const run = (
|
|
36
|
+
const run = Effect.fnUntraced(function* (descriptor, channel, session = "local", bootstrap, stop = Effect.never) {
|
|
37
|
+
const contract = prepare(descriptor);
|
|
36
38
|
const telemetry$1 = yield* telemetry(contract);
|
|
37
39
|
const loggers = yield* Logger.CurrentLoggers;
|
|
38
40
|
yield* Effect.gen(function* () {
|
|
@@ -53,7 +55,7 @@ const run = (contract, channel, session = "local", bootstrap, stop = Effect.neve
|
|
|
53
55
|
cause: error.cause
|
|
54
56
|
}))), stop).pipe(Effect.ensuring(instance.release));
|
|
55
57
|
}).pipe(Effect.provideService(Logger.CurrentLoggers, /* @__PURE__ */ new Set([...loggers, telemetry$1.logger])));
|
|
56
|
-
})
|
|
58
|
+
}, Effect.scoped);
|
|
57
59
|
export { load, run };
|
|
58
60
|
|
|
59
61
|
//# sourceMappingURL=childRuntime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"childRuntime.js","names":["Multiplex.make","channel","Port.make","Wire.channel","Services.endpoints","telemetry","Child.telemetry","Child.lifecycle"],"sources":["../../src/internal/childRuntime.ts"],"sourcesContent":["import { loadModule } from \"./loadModule\"\nimport { ContractNotFound } from \"./childErrors\"\nimport type { Graft } from \"@graftland/graft\"\nimport { Effect, Logger, Option } from \"effect\"\nimport { RpcServer } from \"effect/rpc\"\nimport { fromModule, type RunnerContract } from \"../Contract\"\nimport * as Port from \"./port\"\nimport * as Services from \"./services\"\nimport * as Child from \"./child\"\nimport * as Multiplex from \"./runner/Multiplex\"\nimport * as Wire from \"./runner/Wire\"\nimport type { Bootstrap } from \"./runner/Bootstrap\"\nimport { ExecutionError } from \"./runner/model\"\nimport { closedNormally } from \"./runner/connectionEnded\"\nimport { endpoint } from \"./control\"\n\n/** Import a contract in the runner installation; importing this module performs no I/O. */\nexport const load =
|
|
1
|
+
{"version":3,"file":"childRuntime.js","names":["Multiplex.make","channel","Port.make","Wire.channel","Services.endpoints","telemetry","Child.telemetry","Child.lifecycle"],"sources":["../../src/internal/childRuntime.ts"],"sourcesContent":["import { loadModule } from \"./loadModule\"\nimport { ContractNotFound } from \"./childErrors\"\nimport type { Graft } from \"@graftland/graft\"\nimport { Effect, Logger, Option } from \"effect\"\nimport { RpcServer } from \"effect/rpc\"\nimport { fromModule, type RunnerContract } from \"../Contract\"\nimport * as Port from \"./port\"\nimport { prepare, type RunnerContract as PreparedContract } from \"./contract\"\nimport * as Services from \"./services\"\nimport * as Child from \"./child\"\nimport * as Multiplex from \"./runner/Multiplex\"\nimport * as Wire from \"./runner/Wire\"\nimport type { Bootstrap } from \"./runner/Bootstrap\"\nimport { ExecutionError } from \"./runner/model\"\nimport { closedNormally } from \"./runner/connectionEnded\"\nimport { endpoint } from \"./control\"\n\n/** Import a contract in the runner installation; importing this module performs no I/O. */\nexport const load = Effect.fnUntraced(function* (specifier: string) {\n\tconst module = yield* loadModule(specifier)\n\tconst contract = fromModule(module)\n\tif (Option.isNone(contract))\n\t\treturn yield* ContractNotFound.make({ module: specifier })\n\treturn contract.value\n})\n\nconst connect = Effect.fnUntraced(function* (\n\tcontract: PreparedContract,\n\tchannel: Port.Channel,\n\tsession: string,\n\tbootstrap: Bootstrap | undefined,\n) {\n\tconst mux =\n\t\tbootstrap === undefined ? undefined : yield* Multiplex.make(channel)\n\treturn yield* Port.make(mux === undefined ? channel : Wire.channel(mux, 1), {\n\t\tsession,\n\t\tserve: {\n\t\t\t...Services.endpoints(contract.provides),\n\t\t\t[endpoint]: contract.control,\n\t\t},\n\t\tcall: Services.endpoints(contract.inject),\n\t\t...(bootstrap === undefined ? {} : { limits: bootstrap.limits }),\n\t})\n})\n\n/** One execution unit; the executable supplies the platform and Graft services. */\nexport const run: (\n\tdescriptor: RunnerContract,\n\tchannel: Port.Channel,\n\tsession?: string,\n\tbootstrap?: Bootstrap,\n\tstop?: Effect.Effect<unknown, ExecutionError>,\n) => Effect.Effect<void, ExecutionError, Graft.Graft> = Effect.fnUntraced(\n\tfunction* (\n\t\tdescriptor: RunnerContract,\n\t\tchannel: Port.Channel,\n\t\tsession: string = \"local\",\n\t\tbootstrap?: Bootstrap,\n\t\tstop: Effect.Effect<unknown, ExecutionError> = Effect.never,\n\t) {\n\t\tconst contract = prepare(descriptor)\n\t\tconst telemetry = yield* Child.telemetry(contract)\n\t\tconst loggers = yield* Logger.CurrentLoggers\n\t\tyield* Effect.gen(function* () {\n\t\t\tconst peer = yield* connect(contract, channel, session, bootstrap)\n\t\t\tconst instance = yield* Child.lifecycle(\n\t\t\t\tcontract,\n\t\t\t\tpeer,\n\t\t\t\tbootstrap?.identity ?? { id: session, generation: 1 },\n\t\t\t\ttelemetry,\n\t\t\t)\n\t\t\tconst handlers = yield* contract.control.toHandlers({\n\t\t\t\tLoad: ({ input }) => instance.load(input),\n\t\t\t\tDispose: () => instance.dispose,\n\t\t\t\tEvents: () => telemetry.eventStream,\n\t\t\t\tLogs: () => telemetry.logStream,\n\t\t\t})\n\t\t\tyield* RpcServer.make(contract.control, {\n\t\t\t\tdisableFatalDefects: true,\n\t\t\t}).pipe(\n\t\t\t\tEffect.provideContext(handlers),\n\t\t\t\tEffect.provideService(\n\t\t\t\t\tRpcServer.Protocol,\n\t\t\t\t\tpeer.serverProtocol(endpoint),\n\t\t\t\t),\n\t\t\t\tEffect.forkScoped,\n\t\t\t)\n\t\t\tyield* Effect.raceFirst(\n\t\t\t\tpeer.await.pipe(\n\t\t\t\t\tEffect.catchIf(\n\t\t\t\t\t\t(error) => closedNormally(error.cause),\n\t\t\t\t\t\t() => Effect.void,\n\t\t\t\t\t),\n\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\tExecutionError.make({\n\t\t\t\t\t\t\tdetail: \"Child transport failed\",\n\t\t\t\t\t\t\tcause: error.cause,\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\tstop,\n\t\t\t).pipe(\n\t\t\t\t// Release exports before closing the instance scope, including on interruption.\n\t\t\t\tEffect.ensuring(instance.release),\n\t\t\t)\n\t\t}).pipe(\n\t\t\tEffect.provideService(\n\t\t\t\tLogger.CurrentLoggers,\n\t\t\t\tnew Set([...loggers, telemetry.logger]),\n\t\t\t),\n\t\t)\n\t},\n\tEffect.scoped,\n)\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,MAAa,OAAO,OAAO,WAAW,WAAW,WAAmB;CACnE,MAAM,SAAS,OAAO,WAAW,SAAS;CAC1C,MAAM,WAAW,WAAW,MAAM;CAClC,IAAI,OAAO,OAAO,QAAQ,GACzB,OAAO,OAAO,iBAAiB,KAAK,EAAE,QAAQ,UAAU,CAAC;CAC1D,OAAO,SAAS;AACjB,CAAC;AAED,MAAM,UAAU,OAAO,WAAW,WACjC,UACA,WACA,SACA,WACC;CACD,MAAM,MACL,cAAc,KAAA,IAAY,KAAA,IAAY,OAAOA,OAAeC,SAAO;CACpE,OAAO,OAAOC,KAAU,QAAQ,KAAA,IAAYD,YAAUE,QAAa,KAAK,CAAC,GAAG;EAC3E;EACA,OAAO;GACN,GAAGC,UAAmB,SAAS,QAAQ;IACtC,WAAW,SAAS;EACtB;EACA,MAAMA,UAAmB,SAAS,MAAM;EACxC,GAAI,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,UAAU,OAAO;CAC/D,CAAC;AACF,CAAC;;AAGD,MAAa,MAM2C,OAAO,WAC9D,WACC,YACA,SACA,UAAkB,SAClB,WACA,OAA+C,OAAO,OACrD;CACD,MAAM,WAAW,QAAQ,UAAU;CACnC,MAAMC,cAAY,OAAOC,UAAgB,QAAQ;CACjD,MAAM,UAAU,OAAO,OAAO;CAC9B,OAAO,OAAO,IAAI,aAAa;EAC9B,MAAM,OAAO,OAAO,QAAQ,UAAU,SAAS,SAAS,SAAS;EACjE,MAAM,WAAW,OAAOC,UACvB,UACA,MACA,WAAW,YAAY;GAAE,IAAI;GAAS,YAAY;EAAE,GACpDF,WACD;EACA,MAAM,WAAW,OAAO,SAAS,QAAQ,WAAW;GACnD,OAAO,EAAE,YAAY,SAAS,KAAK,KAAK;GACxC,eAAe,SAAS;GACxB,cAAcA,YAAU;GACxB,YAAYA,YAAU;EACvB,CAAC;EACD,OAAO,UAAU,KAAK,SAAS,SAAS,EACvC,qBAAqB,KACtB,CAAC,CAAC,CAAC,KACF,OAAO,eAAe,QAAQ,GAC9B,OAAO,eACN,UAAU,UACV,KAAK,eAAe,QAAQ,CAC7B,GACA,OAAO,UACR;EACA,OAAO,OAAO,UACb,KAAK,MAAM,KACV,OAAO,SACL,UAAU,eAAe,MAAM,KAAK,SAC/B,OAAO,IACd,GACA,OAAO,UAAU,UAChB,eAAe,KAAK;GACnB,QAAQ;GACR,OAAO,MAAM;EACd,CAAC,CACF,CACD,GACA,IACD,CAAC,CAAC,KAED,OAAO,SAAS,SAAS,OAAO,CACjC;CACD,CAAC,CAAC,CAAC,KACF,OAAO,eACN,OAAO,gCACP,IAAI,IAAI,CAAC,GAAG,SAASA,YAAU,MAAM,CAAC,CACvC,CACD;AACD,GACA,OAAO,MACR"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { UndeclaredFailure } from "../Contract.js";
|
|
2
|
+
import { ChildFailure } from "./childErrors.js";
|
|
3
|
+
import { make } from "./control.js";
|
|
4
|
+
import { Cause, Schema } from "effect";
|
|
5
|
+
// src/internal/contract.ts
|
|
6
|
+
/** Control RPCs and child failures belong to the execution protocol, not the public descriptor. */
|
|
7
|
+
const prepare = (contract) => {
|
|
8
|
+
const failure = Schema.Union([
|
|
9
|
+
contract.error,
|
|
10
|
+
UndeclaredFailure,
|
|
11
|
+
ChildFailure
|
|
12
|
+
]);
|
|
13
|
+
const codec = Schema.toCodecJson(Schema.Cause(failure, Schema.Defect({ includeStack: true })));
|
|
14
|
+
const declared = Schema.is(failure);
|
|
15
|
+
const normalizeCause = (cause) => Cause.map(cause, (error) => declared(error) ? error : UndeclaredFailure.make({ original: error }));
|
|
16
|
+
return {
|
|
17
|
+
...contract,
|
|
18
|
+
control: make(codec),
|
|
19
|
+
normalizeCause,
|
|
20
|
+
encodeCause: (cause) => normalizeCause(cause).pipe(Schema.encodeEffect(codec)),
|
|
21
|
+
decodeCause: Schema.decodeUnknownEffect(codec)
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export { prepare };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","names":["Contract.UndeclaredFailure","Control.make"],"sources":["../../src/internal/contract.ts"],"sourcesContent":["import { Cause, Schema } from \"effect\"\nimport * as Contract from \"../Contract\"\nimport { ChildFailure } from \"./childErrors\"\nimport * as Control from \"./control\"\n\n/** Control RPCs and child failures belong to the execution protocol, not the public descriptor. */\nexport const prepare = <\n\tS extends Schema.Top & {\n\t\treadonly Encoded: Schema.Json\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n\tE extends Schema.Top & {\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n>(\n\tcontract: Contract.Contract<S, E>,\n) => {\n\tconst failure = Schema.Union([\n\t\tcontract.error,\n\t\tContract.UndeclaredFailure,\n\t\tChildFailure,\n\t])\n\tconst codec = Schema.toCodecJson(\n\t\tSchema.Cause(failure, Schema.Defect({ includeStack: true })),\n\t)\n\tconst declared = Schema.is(failure)\n\tconst normalizeCause = (cause: Cause.Cause<unknown>) =>\n\t\tCause.map(cause, (error) =>\n\t\t\tdeclared(error)\n\t\t\t\t? error\n\t\t\t\t: Contract.UndeclaredFailure.make({ original: error }),\n\t\t)\n\treturn {\n\t\t...contract,\n\t\tcontrol: Control.make(codec),\n\t\tnormalizeCause,\n\t\tencodeCause: (cause: Cause.Cause<unknown>) =>\n\t\t\tnormalizeCause(cause).pipe(Schema.encodeEffect(codec)),\n\t\tdecodeCause: Schema.decodeUnknownEffect(codec),\n\t}\n}\n\nexport type RunnerContract = ReturnType<\n\ttypeof prepare<Schema.Codec<unknown, Schema.Json>, Schema.Codec<unknown>>\n>\n"],"mappings":";;;;;;AAMA,MAAa,WAWZ,aACI;CACJ,MAAM,UAAU,OAAO,MAAM;EAC5B,SAAS;EACTA;EACA;CACD,CAAC;CACD,MAAM,QAAQ,OAAO,YACpB,OAAO,MAAM,SAAS,OAAO,OAAO,EAAE,cAAc,KAAK,CAAC,CAAC,CAC5D;CACA,MAAM,WAAW,OAAO,GAAG,OAAO;CAClC,MAAM,kBAAkB,UACvB,MAAM,IAAI,QAAQ,UACjB,SAAS,KAAK,IACX,QAAA,kBAC2B,KAAK,EAAE,UAAU,MAAM,CAAC,CACvD;CACD,OAAO;EACN,GAAG;EACH,SAASC,KAAa,KAAK;EAC3B;EACA,cAAc,UACb,eAAe,KAAK,CAAC,CAAC,KAAK,OAAO,aAAa,KAAK,CAAC;EACtD,aAAa,OAAO,oBAAoB,KAAK;CAC9C;AACD"}
|
|
@@ -6,10 +6,12 @@ export type Source<A, D extends ReadonlyArray<Plugin.Dependency>, E = unknown> =
|
|
|
6
6
|
readonly inject: D;
|
|
7
7
|
readonly read: Effect.Effect<A, unknown, NoInfer<Plugin.Required<D>> | Scope.Scope>;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
/** A token value, a file, or a credential effect with declared dependencies. */
|
|
10
|
+
export type Token<D extends ReadonlyArray<Plugin.Dependency>> = string | {
|
|
10
11
|
readonly file: string;
|
|
11
12
|
} | Source<Redacted.Redacted<string>, D>;
|
|
12
|
-
|
|
13
|
+
/** Authentication configuration shared by TypeScript connection descriptions. */
|
|
14
|
+
export type Authentication<D extends ReadonlyArray<Plugin.Dependency>> = {
|
|
13
15
|
readonly name: string;
|
|
14
16
|
readonly config?: unknown;
|
|
15
17
|
} | {
|
|
@@ -30,7 +32,7 @@ type Authentication<D extends ReadonlyArray<Plugin.Dependency>> = {
|
|
|
30
32
|
readonly token: Token<D>;
|
|
31
33
|
};
|
|
32
34
|
};
|
|
33
|
-
type
|
|
35
|
+
export type Connect<D extends ReadonlyArray<Plugin.Dependency> = readonly []> = typeof Connect$1.Encoded extends (infer C) ? C extends {
|
|
34
36
|
readonly local: object;
|
|
35
37
|
} | {
|
|
36
38
|
readonly worker: object;
|
|
@@ -38,7 +40,5 @@ type WithCredentials<C, D extends ReadonlyArray<Plugin.Dependency>> = C extends
|
|
|
38
40
|
readonly command: ReadonlyArray<string>;
|
|
39
41
|
} ? C : Omit<C, "auth"> & {
|
|
40
42
|
readonly auth?: Authentication<D>;
|
|
41
|
-
};
|
|
42
|
-
export type Connect<D extends ReadonlyArray<Plugin.Dependency> = readonly []> = WithCredentials<typeof Connect$1.Encoded, D>;
|
|
43
|
-
export {};
|
|
43
|
+
} : never;
|
|
44
44
|
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.d.ts","names":[],"sources":["../../src/internal/credentials.ts"],"mappings":";;;;YAOY,OAAO,GAAG,UAAU,cAAc,OAAO,aAAa,eAC/D,OAAO,OAAO,GAAG,GAAG,MAAM;WAEjB,QAAQ;WACR,MAAM,OAAO,OACrB,YAEA,QAAQ,OAAO,SAAS,MAAM,MAAM
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","names":[],"sources":["../../src/internal/credentials.ts"],"mappings":";;;;YAOY,OAAO,GAAG,UAAU,cAAc,OAAO,aAAa,eAC/D,OAAO,OAAO,GAAG,GAAG,MAAM;WAEjB,QAAQ;WACR,MAAM,OAAO,OACrB,YAEA,QAAQ,OAAO,SAAS,MAAM,MAAM;;;YAI5B,MAAM,UAAU,cAAc,OAAO;WAC5B;IAAiB,OAAO,SAAS,kBAAkB;;YAE5D,eAAe,UAAU,cAAc,OAAO;WAC5C;WAAuB;;WACvB;aAAiB;;;WAEnB;aACK;aAAuB;MAClC,OAAO,mBAAmB;;WAElB;aAAmB,OAAO,MAAM;;;WAChC;aAAgB,OAAO,MAAM;;;YAC/B,QAAQ,UAAU,cAAc,OAAO,oCACrB,UAAA,uBAAsB,KAChD;WACa;;WACA;;WACA,SAAS;IACrB,IACA,KAAK;WAAwB,OAAO,eAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.js","names":[],"sources":["../../src/internal/credentials.ts"],"sourcesContent":["import { Graft, Plugin } from \"@graftland/graft\"\nimport { Cause, Context, Effect, Redacted, Scope } from \"effect\"\nimport { Credentials, type ClientCertificate, type Prepared } from \"../Auth\"\nimport { CredentialsError } from \"../Errors\"\nimport { prepare } from \"./auth/token\"\nimport type * as Configuration from \"./entryConfig\"\n\nexport type Source<A, D extends ReadonlyArray<Plugin.Dependency>, E = unknown> =\n\t| Effect.Effect<A, E, Scope.Scope>\n\t| {\n\t\t\treadonly inject: D\n\t\t\treadonly read: Effect.Effect<\n\t\t\t\tA,\n\t\t\t\tunknown,\n\t\t\t\tNoInfer<Plugin.Required<D>> | Scope.Scope\n\t\t\t>\n\t }\
|
|
1
|
+
{"version":3,"file":"credentials.js","names":[],"sources":["../../src/internal/credentials.ts"],"sourcesContent":["import { Graft, Plugin } from \"@graftland/graft\"\nimport { Cause, Context, Effect, Redacted, Scope } from \"effect\"\nimport { Credentials, type ClientCertificate, type Prepared } from \"../Auth\"\nimport { CredentialsError } from \"../Errors\"\nimport { prepare } from \"./auth/token\"\nimport type * as Configuration from \"./entryConfig\"\n\nexport type Source<A, D extends ReadonlyArray<Plugin.Dependency>, E = unknown> =\n\t| Effect.Effect<A, E, Scope.Scope>\n\t| {\n\t\t\treadonly inject: D\n\t\t\treadonly read: Effect.Effect<\n\t\t\t\tA,\n\t\t\t\tunknown,\n\t\t\t\tNoInfer<Plugin.Required<D>> | Scope.Scope\n\t\t\t>\n\t }\n/** A token value, a file, or a credential effect with declared dependencies. */\nexport type Token<D extends ReadonlyArray<Plugin.Dependency>> =\n\tstring | { readonly file: string } | Source<Redacted.Redacted<string>, D>\n/** Authentication configuration shared by TypeScript connection descriptions. */\nexport type Authentication<D extends ReadonlyArray<Plugin.Dependency>> =\n\t| { readonly name: string; readonly config?: unknown }\n\t| { readonly none: { readonly identity?: string } }\n\t| {\n\t\t\treadonly mtls:\n\t\t\t\t| { readonly cert: string; readonly key: string }\n\t\t\t\t| Source<ClientCertificate, D>\n\t }\n\t| { readonly bearer: { readonly token: Token<D> } }\n\t| { readonly jwt: { readonly token: Token<D> } }\nexport type Connect<D extends ReadonlyArray<Plugin.Dependency> = readonly []> =\n\ttypeof Configuration.Connect.Encoded extends infer C\n\t\t? C extends\n\t\t\t\t| { readonly local: object }\n\t\t\t\t| { readonly worker: object }\n\t\t\t\t| { readonly command: ReadonlyArray<string> }\n\t\t\t? C\n\t\t\t: Omit<C, \"auth\"> & { readonly auth?: Authentication<D> }\n\t\t: never\n\nconst provider = <A, E, D extends ReadonlyArray<Plugin.Dependency>>(\n\tsource: Source<A, D, E>,\n\tencode: (\n\t\tread: Effect.Effect<A, CredentialsError, Scope.Scope>,\n\t) => typeof Credentials.Service,\n) => {\n\tconst input = Effect.isEffect(source) ? { inject: [], read: source } : source\n\treturn Plugin.make({\n\t\tname: \"remote-effect-credentials\",\n\t\tinject: input.inject,\n\t\tapply: Effect.fnUntraced(function* () {\n\t\t\t// Restore the provider's context without replacing each read's owning scope.\n\t\t\tconst context = yield* Effect.context<\n\t\t\t\tPlugin.Required<D> | Scope.Scope\n\t\t\t>().pipe(Effect.map(Context.omit(Scope.Scope)))\n\t\t\tconst read = input.read.pipe(\n\t\t\t\tEffect.provideContext(context),\n\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\tCredentialsError.make({ cause: Cause.fail(error) }),\n\t\t\t\t),\n\t\t\t)\n\t\t\tyield* Graft.provide(Credentials, encode(read))\n\t\t}),\n\t})\n}\nexport const invocation = <D extends ReadonlyArray<Plugin.Dependency>>(\n\tconnect: Connect<D>,\n) => {\n\tconst auth = connect.auth\n\tif (auth === undefined) return undefined\n\tif (\"mtls\" in auth) {\n\t\tconst source = auth.mtls\n\t\tif (Effect.isEffect(source) || \"read\" in source)\n\t\t\treturn {\n\t\t\t\tplugin: provider(source, (read) => ({\n\t\t\t\t\tkind: \"Certificate\",\n\t\t\t\t\tread: read.pipe(\n\t\t\t\t\t\tEffect.map(\n\t\t\t\t\t\t\t(value): Extract<Prepared, { readonly _tag: \"Certificate\" }> => ({\n\t\t\t\t\t\t\t\t_tag: \"Certificate\",\n\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t})),\n\t\t\t\tconfig: undefined,\n\t\t\t}\n\t}\n\tif (\"bearer\" in auth || \"jwt\" in auth) {\n\t\tconst source = \"bearer\" in auth ? auth.bearer.token : auth.jwt.token\n\t\tif (\n\t\t\ttypeof source !== \"string\" &&\n\t\t\t(Effect.isEffect(source) || \"read\" in source)\n\t\t)\n\t\t\treturn {\n\t\t\t\tplugin: provider(source, (read) => ({\n\t\t\t\t\tkind: \"Authorization\",\n\t\t\t\t\tread: read.pipe(\n\t\t\t\t\t\tEffect.flatMap(prepare),\n\t\t\t\t\t\tEffect.map(\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t): Extract<Prepared, { readonly _tag: \"Authorization\" }> => ({\n\t\t\t\t\t\t\t\t_tag: \"Authorization\",\n\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t})),\n\t\t\t\tconfig: undefined,\n\t\t\t}\n\t}\n\treturn undefined\n}\n"],"mappings":";;;;;;AAyCA,MAAM,YACL,QACA,WAGI;CACJ,MAAM,QAAQ,OAAO,SAAS,MAAM,IAAI;EAAE,QAAQ,CAAC;EAAG,MAAM;CAAO,IAAI;CACvE,OAAO,OAAO,KAAK;EAClB,MAAM;EACN,QAAQ,MAAM;EACd,OAAO,OAAO,WAAW,aAAa;GAErC,MAAM,UAAU,OAAO,OAAO,QAE5B,CAAC,CAAC,KAAK,OAAO,IAAI,QAAQ,KAAK,MAAM,KAAK,CAAC,CAAC;GAC9C,MAAM,OAAO,MAAM,KAAK,KACvB,OAAO,eAAe,OAAO,GAC7B,OAAO,UAAU,UAChB,iBAAiB,KAAK,EAAE,OAAO,MAAM,KAAK,KAAK,EAAE,CAAC,CACnD,CACD;GACA,OAAO,MAAM,QAAQ,aAAa,OAAO,IAAI,CAAC;EAC/C,CAAC;CACF,CAAC;AACF;AACA,MAAa,cACZ,YACI;CACJ,MAAM,OAAO,QAAQ;CACrB,IAAI,SAAS,KAAA,GAAW,OAAO,KAAA;CAC/B,IAAI,UAAU,MAAM;EACnB,MAAM,SAAS,KAAK;EACpB,IAAI,OAAO,SAAS,MAAM,KAAK,UAAU,QACxC,OAAO;GACN,QAAQ,SAAS,SAAS,UAAU;IACnC,MAAM;IACN,MAAM,KAAK,KACV,OAAO,KACL,WAAgE;KAChE,MAAM;KACN;IACD,EACD,CACD;GACD,EAAE;GACF,QAAQ,KAAA;EACT;CACF;CACA,IAAI,YAAY,QAAQ,SAAS,MAAM;EACtC,MAAM,SAAS,YAAY,OAAO,KAAK,OAAO,QAAQ,KAAK,IAAI;EAC/D,IACC,OAAO,WAAW,aACjB,OAAO,SAAS,MAAM,KAAK,UAAU,SAEtC,OAAO;GACN,QAAQ,SAAS,SAAS,UAAU;IACnC,MAAM;IACN,MAAM,KAAK,KACV,OAAO,QAAQ,OAAO,GACtB,OAAO,KAEL,WAC4D;KAC5D,MAAM;KACN;IACD,EACD,CACD;GACD,EAAE;GACF,QAAQ,KAAA;EACT;CACF;AAED"}
|
package/dist/internal/entry.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.ts","names":[],"sources":["../../src/internal/entry.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"entry.d.ts","names":[],"sources":["../../src/internal/entry.ts"],"mappings":";;;;;;qBAuQa"}
|
package/dist/internal/entry.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fromModule } from "../Contract.js";
|
|
2
|
-
import { MissingInstance } from "../Errors.js";
|
|
2
|
+
import { MissingInstance, RemoteEntryError } from "../Errors.js";
|
|
3
3
|
import { LocalTransport, WorkerTransport } from "./directTransport.js";
|
|
4
4
|
import { Host, authentication, hostTransport } from "./entryConfig.js";
|
|
5
5
|
import { CapabilityFailed, host as host$1 } from "./assembly.js";
|
|
@@ -14,20 +14,10 @@ import { Effect, Option, Path, References, Schema, Scope, String } from "effect"
|
|
|
14
14
|
import { SecureRandom } from "effect/crypto";
|
|
15
15
|
import { ChildProcessSpawner } from "effect/process";
|
|
16
16
|
// src/internal/entry.ts
|
|
17
|
-
var EntryError = class extends Schema.TaggedError()("RemoteEntryError", {
|
|
18
|
-
entry: Schema.Option(Schema.String),
|
|
19
|
-
directory: Schema.Option(Schema.String),
|
|
20
|
-
field: Schema.String,
|
|
21
|
-
cause: Schema.Cause(Schema.Unknown, Schema.Unknown)
|
|
22
|
-
}) {
|
|
23
|
-
get message() {
|
|
24
|
-
return `Remote entry ${Option.getOrElse(this.entry, () => "<programmatic>")} failed at ${this.field}`;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
17
|
const boundary = Effect.fnUntraced(function* (field) {
|
|
28
18
|
const entry = yield* Entry.CurrentId;
|
|
29
19
|
const directory = yield* ConfigDirectory;
|
|
30
|
-
return (cause) => Effect.fail(
|
|
20
|
+
return (cause) => Effect.fail(RemoteEntryError.make({
|
|
31
21
|
entry,
|
|
32
22
|
directory,
|
|
33
23
|
field,
|
|
@@ -41,7 +31,7 @@ const resolve = Effect.fnUntraced(function* (reference, field) {
|
|
|
41
31
|
const directory = path.resolve(Option.getOrElse(source, () => "."));
|
|
42
32
|
const resolver = yield* Option.match(existing, {
|
|
43
33
|
onSome: Effect.succeed,
|
|
44
|
-
onNone:
|
|
34
|
+
onNone: Effect.fnUntraced(function* () {
|
|
45
35
|
const importer = yield* make(directory);
|
|
46
36
|
return yield* ModuleResolver.make({
|
|
47
37
|
base: directory,
|
|
@@ -139,6 +129,6 @@ const host = Plugin.make({
|
|
|
139
129
|
],
|
|
140
130
|
apply: load
|
|
141
131
|
});
|
|
142
|
-
export {
|
|
132
|
+
export { boundary, direct, host, launch, loadContract, resolve };
|
|
143
133
|
|
|
144
134
|
//# sourceMappingURL=entry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.js","names":["Importer.make","Contract.fromModule","Configuration.hostTransport","Configuration.authentication","Assembly.host","Configuration.Host"],"sources":["../../src/internal/entry.ts"],"sourcesContent":["import { Graft, Plugin, type Fork } from \"@graftland/graft\"\nimport { ConfigDirectory, Entry, ModuleResolver } from \"@graftland/loader\"\nimport {\n\tCause,\n\tEffect,\n\tOption,\n\tPath,\n\tSchema,\n\tReferences,\n\tScope,\n\tString,\n} from \"effect\"\nimport { ChildProcessSpawner } from \"effect/process\"\nimport * as Contract from \"../Contract\"\nimport { MissingInstance } from \"../Errors\"\nimport { LocalTransport, WorkerTransport } from \"./directTransport\"\nimport * as Configuration from \"./entryConfig\"\nimport * as Assembly from \"./assembly\"\nimport { executionPlugin } from \"./execution\"\nimport { follow } from \"./follow\"\nimport { children } from \"./cleanup\"\nimport { resolveEntry } from \"./runner/Packages\"\nimport type { LocalTarget, WorkerTarget } from \"./runner/Connection\"\nimport type { ExecutionOptions } from \"./execution\"\nimport * as Importer from \"./importer\"\nimport { SecureRandom } from \"effect/crypto\"\n\nexport class EntryError extends Schema.TaggedError<\n\tEntryError,\n\t{ readonly brand: unique symbol }\n>()(\"RemoteEntryError\", {\n\tentry: Schema.Option(Schema.String),\n\tdirectory: Schema.Option(Schema.String),\n\tfield: Schema.String,\n\tcause: Schema.Cause(Schema.Unknown, Schema.Unknown),\n}) {\n\toverride get message() {\n\t\treturn `Remote entry ${Option.getOrElse(this.entry, () => \"<programmatic>\")} failed at ${this.field}`\n\t}\n}\nexport const boundary = Effect.fnUntraced(function* (field: string) {\n\tconst entry = yield* Entry.CurrentId\n\tconst directory = yield* ConfigDirectory\n\treturn (cause: Cause.Cause<unknown>) =>\n\t\tEffect.fail(EntryError.make({ entry, directory, field, cause }))\n})\nexport const resolve = Effect.fnUntraced(function* (\n\treference: Configuration.Reference,\n\tfield: string,\n) {\n\tconst existing = yield* Effect.serviceOption(ModuleResolver.ModuleResolver)\n\tconst path = yield* Path.Path\n\tconst source = yield* ConfigDirectory\n\tconst directory = path.resolve(Option.getOrElse(source, () => \".\"))\n\tconst resolver = yield* Option.match(existing, {\n\t\tonSome: Effect.succeed,\n\t\tonNone: () =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst importer = yield* Importer.make(directory)\n\t\t\t\treturn yield* ModuleResolver.make({\n\t\t\t\t\tbase: directory,\n\t\t\t\t\timporter: (specifier) =>\n\t\t\t\t\t\tString.startsWith(\"@graftland/plugin-remote/\")(specifier)\n\t\t\t\t\t\t\t? import(specifier)\n\t\t\t\t\t\t\t: importer(specifier),\n\t\t\t\t})\n\t\t\t}),\n\t})\n\tconst fail = yield* boundary(field)\n\tconst plugin = yield* resolver\n\t\t.resolve(reference.name)\n\t\t.pipe(Effect.catchCause(fail))\n\treturn { plugin, config: reference.config }\n})\nexport const loadContract = Effect.fnUntraced(function* (specifier: string) {\n\tconst resolver = yield* ModuleResolver.ModuleResolver\n\tconst fail = yield* boundary(\"contract\")\n\treturn yield* resolver.importModule(specifier).pipe(\n\t\tEffect.flatMap((module) =>\n\t\t\tEffect.fromOption(Contract.fromModule(module), () =>\n\t\t\t\tModuleResolver.ModuleInvalid.make({\n\t\t\t\t\tspecifier,\n\t\t\t\t\tcause: \"Expected a default or named remote contract\",\n\t\t\t\t}),\n\t\t\t),\n\t\t),\n\t\tEffect.catchCause(fail),\n\t)\n})\n\n/** Direct execution installs only its execution capability in a private realm. */\nexport const direct = (\n\tprovider: Plugin.Plugin,\n\tconsumer: Plugin.Plugin,\n\tinput: Schema.Json,\n\tkey: typeof LocalTransport | typeof WorkerTransport,\n): Effect.Effect<Fork.Fork<never, unknown>, never, Graft.Graft | Scope.Scope> =>\n\tGraft.plugin(\n\t\tPlugin.make({\n\t\t\tname: \"remote-direct\",\n\t\t\tapply: Effect.fnUntraced(function* () {\n\t\t\t\tconst capability = yield* Graft.plugin(provider)\n\t\t\t\tyield* follow(capability, (cause) =>\n\t\t\t\t\tEffect.fail(Assembly.CapabilityFailed.make({ cause })),\n\t\t\t\t)\n\t\t\t\tconst execution = yield* Graft.plugin(consumer, input)\n\t\t\t\tyield* follow(execution, (cause) =>\n\t\t\t\t\tEffect.fail(Assembly.CapabilityFailed.make({ cause })),\n\t\t\t\t)\n\t\t\t}),\n\t\t}),\n\t\tundefined,\n\t\t{ isolate: [key] },\n\t)\n\ntype Annotations = Readonly<Record<string, unknown>>\nconst directTarget = Effect.fnUntraced(function* <\n\tS extends Schema.Top & {\n\t\treadonly Encoded: Schema.Json\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n\tE extends Schema.Top & {\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n>(\n\tcontract: Contract.Contract<S, E>,\n\tinput: typeof Configuration.Host.Type,\n\tselected: LocalTarget | WorkerTarget,\n\tannotations: Annotations,\n\toptions: ExecutionOptions,\n) {\n\tconst path = yield* Path.Path\n\tconst source = yield* ConfigDirectory\n\tconst directory = path.resolve(Option.getOrElse(source, () => \".\"))\n\tconst module = String.startsWith(\"file:\")(input.contract)\n\t\t? input.contract\n\t\t: yield* resolveEntry(directory, input.contract)\n\tconst capability = yield* resolve(\n\t\t{\n\t\t\tname:\n\t\t\t\tselected._tag === \"Local\"\n\t\t\t\t\t? \"@graftland/plugin-remote/host/local\"\n\t\t\t\t\t: \"@graftland/plugin-remote/host/worker\",\n\t\t},\n\t\t\"connect\",\n\t)\n\treturn yield* direct(\n\t\tcapability.plugin,\n\t\texecutionPlugin(\n\t\t\tcontract,\n\t\t\t{ ...options, contractModule: module },\n\t\t\tselected,\n\t\t\tannotations,\n\t\t),\n\t\tinput.config,\n\t\tselected._tag === \"Local\" ? LocalTransport : WorkerTransport,\n\t)\n})\nconst runnerTarget = Effect.fnUntraced(function* <\n\tS extends Schema.Top & {\n\t\treadonly Encoded: Schema.Json\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n\tE extends Schema.Top & {\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n>(\n\tcontract: Contract.Contract<S, E>,\n\tinput: typeof Configuration.Host.Type,\n\ttarget: Exclude<\n\t\tConfiguration.Connect,\n\t\t{ readonly local: object } | { readonly worker: object }\n\t>,\n\tannotations: Annotations,\n\toptions: ExecutionOptions,\n\tauthOverride: typeof Assembly.Invocation.Type | undefined,\n) {\n\tconst instance =\n\t\ttarget.instance === undefined\n\t\t\t? yield* Entry.CurrentId\n\t\t\t: Option.some(target.instance)\n\tif (Option.isNone(instance)) return yield* MissingInstance.make({})\n\tconst transport = yield* resolve(\n\t\tConfiguration.hostTransport(target),\n\t\t\"connect.transport\",\n\t)\n\tconst auth =\n\t\tauthOverride ??\n\t\t(yield* resolve(\n\t\t\tConfiguration.authentication(\"host\", target.auth),\n\t\t\t\"connect.auth\",\n\t\t))\n\tconst consumer = executionPlugin(\n\t\tcontract,\n\t\toptions,\n\t\t{\n\t\t\t_tag: \"Connector\",\n\t\t\texplicitAuth: target.auth !== undefined,\n\t\t\tinstance: instance.value,\n\t\t\t...(target.lease === undefined ? {} : { lease: target.lease }),\n\t\t\t...(target.margin === undefined ? {} : { margin: target.margin }),\n\t\t\t...(target.expect === undefined ? {} : { expect: target.expect }),\n\t\t},\n\t\tannotations,\n\t)\n\treturn yield* Assembly.host({\n\t\ttransport,\n\t\tauth,\n\t\tconsumer,\n\t\tinput: input.config,\n\t})\n})\n\nexport const launch = Effect.fnUntraced(function* <\n\tS extends Schema.Top & {\n\t\treadonly Encoded: Schema.Json\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n\tE extends Schema.Top & {\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n>(\n\tcontract: Contract.Contract<S, E>,\n\tinput: typeof Configuration.Host.Type,\n\toptions: ExecutionOptions,\n\tauthOverride?: typeof Assembly.Invocation.Type,\n) {\n\tconst annotations = yield* References.CurrentLogAnnotations\n\tconst connect = input.connect\n\tconst scope = yield* children\n\treturn yield* Effect.gen(function* () {\n\t\tif (connect.local !== undefined)\n\t\t\treturn yield* directTarget(\n\t\t\t\tcontract,\n\t\t\t\tinput,\n\t\t\t\t{ _tag: \"Local\", ...connect.local },\n\t\t\t\tannotations,\n\t\t\t\toptions,\n\t\t\t)\n\t\tif (connect.worker !== undefined)\n\t\t\treturn yield* directTarget(\n\t\t\t\tcontract,\n\t\t\t\tinput,\n\t\t\t\t{ _tag: \"Worker\", ...connect.worker },\n\t\t\t\tannotations,\n\t\t\t\toptions,\n\t\t\t)\n\t\treturn yield* runnerTarget(\n\t\t\tcontract,\n\t\t\tinput,\n\t\t\tconnect,\n\t\t\tannotations,\n\t\t\toptions,\n\t\t\tauthOverride,\n\t\t)\n\t}).pipe(Scope.provide(scope))\n})\nconst load = Effect.fnUntraced(function* (\n\tinput: typeof Configuration.Host.Type,\n) {\n\tconst contract = yield* loadContract(input.contract)\n\tconst failConfig = yield* boundary(\"config\")\n\tyield* Schema.decodeEffect(contract.config)(input.config).pipe(\n\t\tEffect.catchCause(failConfig),\n\t)\n\tconst failConnect = yield* boundary(\"connect\")\n\tconst fork = yield* launch(contract, input, {\n\t\tcontractModule: input.contract,\n\t}).pipe(Effect.catchCause(failConnect))\n\tyield* follow(fork, failConnect)\n})\nexport const host = Plugin.make({\n\tname: \"remote\",\n\tconfig: Configuration.Host,\n\tinject: [\n\t\tSecureRandom.SecureRandom,\n\t\tModuleResolver.ModuleResolver,\n\t\tPath.Path,\n\t\tChildProcessSpawner.ChildProcessSpawner,\n\t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A,SACA,YACD;CACD,CAAC,CAAC,CAAC,KAAK,MAAM,QAAQ,KAAK,CAAC;AAC7B,CAAC;AACD,MAAM,OAAO,OAAO,WAAW,WAC9B,OACC;CACD,MAAM,WAAW,OAAO,aAAa,MAAM,QAAQ;CACnD,MAAM,aAAa,OAAO,SAAS,QAAQ;CAC3C,OAAO,OAAO,aAAa,SAAS,MAAM,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC,KACzD,OAAO,WAAW,UAAU,CAC7B;CACA,MAAM,cAAc,OAAO,SAAS,SAAS;CAC7C,MAAM,OAAO,OAAO,OAAO,UAAU,OAAO,EAC3C,gBAAgB,MAAM,SACvB,CAAC,CAAC,CAAC,KAAK,OAAO,WAAW,WAAW,CAAC;CACtC,OAAO,OAAO,MAAM,WAAW;AAChC,CAAC;AACD,MAAa,OAAO,OAAO,KAAK;CAC/B,MAAM;CACN,QAAQC;CACR,QAAQ;EACP,aAAa;EACb,eAAe;EACf,KAAK;EACL,oBAAoB;CACrB;CACA,OAAO;AACR,CAAC"}
|
|
1
|
+
{"version":3,"file":"entry.js","names":["EntryError","Importer.make","Contract.fromModule","Configuration.hostTransport","Configuration.authentication","Assembly.host","Configuration.Host"],"sources":["../../src/internal/entry.ts"],"sourcesContent":["import { Graft, Plugin, type Fork } from \"@graftland/graft\"\nimport { ConfigDirectory, Entry, ModuleResolver } from \"@graftland/loader\"\nimport {\n\tCause,\n\tEffect,\n\tOption,\n\tPath,\n\tSchema,\n\tReferences,\n\tScope,\n\tString,\n} from \"effect\"\nimport { ChildProcessSpawner } from \"effect/process\"\nimport * as Contract from \"../Contract\"\nimport { MissingInstance, RemoteEntryError as EntryError } from \"../Errors\"\nimport { LocalTransport, WorkerTransport } from \"./directTransport\"\nimport * as Configuration from \"./entryConfig\"\nimport * as Assembly from \"./assembly\"\nimport { executionPlugin } from \"./execution\"\nimport { follow } from \"./follow\"\nimport { children } from \"./cleanup\"\nimport { resolveEntry } from \"./runner/Packages\"\nimport type { LocalTarget, WorkerTarget } from \"./runner/Connection\"\nimport type { ExecutionOptions } from \"./execution\"\nimport * as Importer from \"./importer\"\nimport { SecureRandom } from \"effect/crypto\"\n\nexport const boundary = Effect.fnUntraced(function* (field: string) {\n\tconst entry = yield* Entry.CurrentId\n\tconst directory = yield* ConfigDirectory\n\treturn (cause: Cause.Cause<unknown>) =>\n\t\tEffect.fail(EntryError.make({ entry, directory, field, cause }))\n})\nexport const resolve = Effect.fnUntraced(function* (\n\treference: Configuration.Reference,\n\tfield: string,\n) {\n\tconst existing = yield* Effect.serviceOption(ModuleResolver.ModuleResolver)\n\tconst path = yield* Path.Path\n\tconst source = yield* ConfigDirectory\n\tconst directory = path.resolve(Option.getOrElse(source, () => \".\"))\n\tconst resolver = yield* Option.match(existing, {\n\t\tonSome: Effect.succeed,\n\t\tonNone: Effect.fnUntraced(function* () {\n\t\t\tconst importer = yield* Importer.make(directory)\n\t\t\treturn yield* ModuleResolver.make({\n\t\t\t\tbase: directory,\n\t\t\t\timporter: (specifier) =>\n\t\t\t\t\tString.startsWith(\"@graftland/plugin-remote/\")(specifier)\n\t\t\t\t\t\t? import(specifier)\n\t\t\t\t\t\t: importer(specifier),\n\t\t\t})\n\t\t}),\n\t})\n\tconst fail = yield* boundary(field)\n\tconst plugin = yield* resolver\n\t\t.resolve(reference.name)\n\t\t.pipe(Effect.catchCause(fail))\n\treturn { plugin, config: reference.config }\n})\nexport const loadContract = Effect.fnUntraced(function* (specifier: string) {\n\tconst resolver = yield* ModuleResolver.ModuleResolver\n\tconst fail = yield* boundary(\"contract\")\n\treturn yield* resolver.importModule(specifier).pipe(\n\t\tEffect.flatMap((module) =>\n\t\t\tEffect.fromOption(Contract.fromModule(module), () =>\n\t\t\t\tModuleResolver.ModuleInvalid.make({\n\t\t\t\t\tspecifier,\n\t\t\t\t\tcause: \"Expected a default or named remote contract\",\n\t\t\t\t}),\n\t\t\t),\n\t\t),\n\t\tEffect.catchCause(fail),\n\t)\n})\n\n/** Direct execution installs only its execution capability in a private realm. */\nexport const direct = (\n\tprovider: Plugin.Plugin,\n\tconsumer: Plugin.Plugin,\n\tinput: Schema.Json,\n\tkey: typeof LocalTransport | typeof WorkerTransport,\n): Effect.Effect<Fork.Fork<never, unknown>, never, Graft.Graft | Scope.Scope> =>\n\tGraft.plugin(\n\t\tPlugin.make({\n\t\t\tname: \"remote-direct\",\n\t\t\tapply: Effect.fnUntraced(function* () {\n\t\t\t\tconst capability = yield* Graft.plugin(provider)\n\t\t\t\tyield* follow(capability, (cause) =>\n\t\t\t\t\tEffect.fail(Assembly.CapabilityFailed.make({ cause })),\n\t\t\t\t)\n\t\t\t\tconst execution = yield* Graft.plugin(consumer, input)\n\t\t\t\tyield* follow(execution, (cause) =>\n\t\t\t\t\tEffect.fail(Assembly.CapabilityFailed.make({ cause })),\n\t\t\t\t)\n\t\t\t}),\n\t\t}),\n\t\tundefined,\n\t\t{ isolate: [key] },\n\t)\n\ntype Annotations = Readonly<Record<string, unknown>>\nconst directTarget = Effect.fnUntraced(function* <\n\tS extends Schema.Top & {\n\t\treadonly Encoded: Schema.Json\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n\tE extends Schema.Top & {\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n>(\n\tcontract: Contract.Contract<S, E>,\n\tinput: typeof Configuration.Host.Type,\n\tselected: LocalTarget | WorkerTarget,\n\tannotations: Annotations,\n\toptions: ExecutionOptions,\n) {\n\tconst path = yield* Path.Path\n\tconst source = yield* ConfigDirectory\n\tconst directory = path.resolve(Option.getOrElse(source, () => \".\"))\n\tconst module = String.startsWith(\"file:\")(input.contract)\n\t\t? input.contract\n\t\t: yield* resolveEntry(directory, input.contract)\n\tconst capability = yield* resolve(\n\t\t{\n\t\t\tname:\n\t\t\t\tselected._tag === \"Local\"\n\t\t\t\t\t? \"@graftland/plugin-remote/host/local\"\n\t\t\t\t\t: \"@graftland/plugin-remote/host/worker\",\n\t\t},\n\t\t\"connect\",\n\t)\n\treturn yield* direct(\n\t\tcapability.plugin,\n\t\texecutionPlugin(\n\t\t\tcontract,\n\t\t\t{ ...options, contractModule: module },\n\t\t\tselected,\n\t\t\tannotations,\n\t\t),\n\t\tinput.config,\n\t\tselected._tag === \"Local\" ? LocalTransport : WorkerTransport,\n\t)\n})\nconst runnerTarget = Effect.fnUntraced(function* <\n\tS extends Schema.Top & {\n\t\treadonly Encoded: Schema.Json\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n\tE extends Schema.Top & {\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n>(\n\tcontract: Contract.Contract<S, E>,\n\tinput: typeof Configuration.Host.Type,\n\ttarget: Exclude<\n\t\tConfiguration.Connect,\n\t\t{ readonly local: object } | { readonly worker: object }\n\t>,\n\tannotations: Annotations,\n\toptions: ExecutionOptions,\n\tauthOverride: typeof Assembly.Invocation.Type | undefined,\n) {\n\tconst instance =\n\t\ttarget.instance === undefined\n\t\t\t? yield* Entry.CurrentId\n\t\t\t: Option.some(target.instance)\n\tif (Option.isNone(instance)) return yield* MissingInstance.make({})\n\tconst transport = yield* resolve(\n\t\tConfiguration.hostTransport(target),\n\t\t\"connect.transport\",\n\t)\n\tconst auth =\n\t\tauthOverride ??\n\t\t(yield* resolve(\n\t\t\tConfiguration.authentication(\"host\", target.auth),\n\t\t\t\"connect.auth\",\n\t\t))\n\tconst consumer = executionPlugin(\n\t\tcontract,\n\t\toptions,\n\t\t{\n\t\t\t_tag: \"Connector\",\n\t\t\texplicitAuth: target.auth !== undefined,\n\t\t\tinstance: instance.value,\n\t\t\t...(target.lease === undefined ? {} : { lease: target.lease }),\n\t\t\t...(target.margin === undefined ? {} : { margin: target.margin }),\n\t\t\t...(target.expect === undefined ? {} : { expect: target.expect }),\n\t\t},\n\t\tannotations,\n\t)\n\treturn yield* Assembly.host({\n\t\ttransport,\n\t\tauth,\n\t\tconsumer,\n\t\tinput: input.config,\n\t})\n})\n\nexport const launch = Effect.fnUntraced(function* <\n\tS extends Schema.Top & {\n\t\treadonly Encoded: Schema.Json\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n\tE extends Schema.Top & {\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n>(\n\tcontract: Contract.Contract<S, E>,\n\tinput: typeof Configuration.Host.Type,\n\toptions: ExecutionOptions,\n\tauthOverride?: typeof Assembly.Invocation.Type,\n) {\n\tconst annotations = yield* References.CurrentLogAnnotations\n\tconst connect = input.connect\n\tconst scope = yield* children\n\treturn yield* Effect.gen(function* () {\n\t\tif (connect.local !== undefined)\n\t\t\treturn yield* directTarget(\n\t\t\t\tcontract,\n\t\t\t\tinput,\n\t\t\t\t{ _tag: \"Local\", ...connect.local },\n\t\t\t\tannotations,\n\t\t\t\toptions,\n\t\t\t)\n\t\tif (connect.worker !== undefined)\n\t\t\treturn yield* directTarget(\n\t\t\t\tcontract,\n\t\t\t\tinput,\n\t\t\t\t{ _tag: \"Worker\", ...connect.worker },\n\t\t\t\tannotations,\n\t\t\t\toptions,\n\t\t\t)\n\t\treturn yield* runnerTarget(\n\t\t\tcontract,\n\t\t\tinput,\n\t\t\tconnect,\n\t\t\tannotations,\n\t\t\toptions,\n\t\t\tauthOverride,\n\t\t)\n\t}).pipe(Scope.provide(scope))\n})\nconst load = Effect.fnUntraced(function* (\n\tinput: typeof Configuration.Host.Type,\n) {\n\tconst contract = yield* loadContract(input.contract)\n\tconst failConfig = yield* boundary(\"config\")\n\tyield* Schema.decodeEffect(contract.config)(input.config).pipe(\n\t\tEffect.catchCause(failConfig),\n\t)\n\tconst failConnect = yield* boundary(\"connect\")\n\tconst fork = yield* launch(contract, input, {\n\t\tcontractModule: input.contract,\n\t}).pipe(Effect.catchCause(failConnect))\n\tyield* follow(fork, failConnect)\n})\nexport const host = Plugin.make({\n\tname: \"remote\",\n\tconfig: Configuration.Host,\n\tinject: [\n\t\tSecureRandom.SecureRandom,\n\t\tModuleResolver.Modu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AAM,CAAC,CAAC,KACzD,OAAO,WAAW,UAAU,CAC7B;CACA,MAAM,cAAc,OAAO,SAAS,SAAS;CAC7C,MAAM,OAAO,OAAO,OAAO,UAAU,OAAO,EAC3C,gBAAgB,MAAM,SACvB,CAAC,CAAC,CAAC,KAAK,OAAO,WAAW,WAAW,CAAC;CACtC,OAAO,OAAO,MAAM,WAAW;AAChC,CAAC;AACD,MAAa,OAAO,OAAO,KAAK;CAC/B,MAAM;CACN,QAAQC;CACR,QAAQ;EACP,aAAa;EACb,eAAe;EACf,KAAK;EACL,oBAAoB;CACrB;CACA,OAAO;AACR,CAAC"}
|
|
@@ -4,12 +4,18 @@ import { Credentials } from "../Auth.js";
|
|
|
4
4
|
import { acquire } from "./runner/Connection.js";
|
|
5
5
|
import { endpoints } from "./services.js";
|
|
6
6
|
import { dispose, initialize, load } from "./host.js";
|
|
7
|
-
import { MissingInstance, RemoteError, RemoteWithdrawn } from "../Errors.js";
|
|
7
|
+
import { AuthenticationFailed, CredentialsError, LocalTerminationTimeout, MissingInstance, ProcessExited, RemoteEntryError, RemoteError, RemoteWithdrawn, TransportError } from "../Errors.js";
|
|
8
|
+
import { ActivationFailed, AlreadyLoaded, ContractNotFound, ModuleImportFailed } from "./childErrors.js";
|
|
9
|
+
import { errors } from "./assembly.js";
|
|
10
|
+
import { ExecutionError, LeaseExpired, PackageError, RemoteTerminationUnconfirmed, RunnerClosing, SessionAccessDenied, SessionConflict, SessionStopped, StaleSession, StateDirectoryLocked, StateStorageError, TerminationUnconfirmed } from "./runner/model.js";
|
|
11
|
+
import { ReleaseInterrupted } from "./release.js";
|
|
8
12
|
import { UndeclaredFailure } from "../Contract.js";
|
|
9
13
|
import { endpoint } from "./control.js";
|
|
14
|
+
import { prepare } from "./contract.js";
|
|
10
15
|
import { Plugin } from "@graftland/graft";
|
|
11
|
-
import { Array, Cause, Effect, Fiber, Schema, Scope } from "effect";
|
|
16
|
+
import { Array, Cause, Effect, Fiber, PlatformError, Schema, Scope } from "effect";
|
|
12
17
|
import { SecureRandom } from "effect/crypto";
|
|
18
|
+
import { RpcClientError } from "effect/rpc";
|
|
13
19
|
// src/internal/execution.ts
|
|
14
20
|
const dependencies = (target) => target._tag === "Connector" ? [Connector, Credentials] : target._tag === "Local" ? [LocalTransport] : [WorkerTransport];
|
|
15
21
|
/** One owned execution per activation, with explicitly mapped services. */
|
|
@@ -21,23 +27,54 @@ const executionPlugin = (contract, options, configured, annotations = {}) => Plu
|
|
|
21
27
|
...Array.map(contract.inject, (service) => service.key)
|
|
22
28
|
],
|
|
23
29
|
config: Schema.toEncoded(contract.config),
|
|
24
|
-
apply:
|
|
30
|
+
apply: Effect.fnUntraced(function* (input) {
|
|
31
|
+
const prepared = prepare(contract);
|
|
25
32
|
const session = yield* (yield* SecureRandom.SecureRandom).uuidV4();
|
|
26
33
|
const active = yield* acquire(configured, options.contractModule, {
|
|
27
34
|
session,
|
|
28
35
|
serve: endpoints(contract.inject),
|
|
29
36
|
call: {
|
|
30
37
|
...endpoints(contract.provides),
|
|
31
|
-
[endpoint]:
|
|
38
|
+
[endpoint]: prepared.control
|
|
32
39
|
}
|
|
33
|
-
}, initialize(
|
|
40
|
+
}, initialize(prepared), dispose, options.shutdownTimeout ?? "5 seconds");
|
|
34
41
|
yield* load(active, input);
|
|
35
42
|
for (const service of contract.provides) yield* service.publish(active.connection.transport).pipe(Scope.provide(active.connection.resources));
|
|
36
43
|
yield* Plugin.fork(Effect.raceFirst(Fiber.join(active.events), active.remoteFailure.await).pipe(Effect.mapError((error) => publicError(contract.error, error))));
|
|
37
44
|
return () => Effect.succeed(false);
|
|
38
|
-
}
|
|
45
|
+
}, Effect.annotateLogs(annotations), Effect.mapError((error) => publicError(contract.error, error)))
|
|
39
46
|
});
|
|
40
|
-
|
|
47
|
+
/** Failures raised by the host machinery; a permissive declared schema must not claim them. */
|
|
48
|
+
const internalErrors = [
|
|
49
|
+
ProcessExited,
|
|
50
|
+
TransportError,
|
|
51
|
+
LocalTerminationTimeout,
|
|
52
|
+
CredentialsError,
|
|
53
|
+
AuthenticationFailed,
|
|
54
|
+
RemoteEntryError,
|
|
55
|
+
AlreadyLoaded,
|
|
56
|
+
ContractNotFound,
|
|
57
|
+
ModuleImportFailed,
|
|
58
|
+
ActivationFailed,
|
|
59
|
+
PackageError,
|
|
60
|
+
SessionAccessDenied,
|
|
61
|
+
StaleSession,
|
|
62
|
+
LeaseExpired,
|
|
63
|
+
SessionStopped,
|
|
64
|
+
SessionConflict,
|
|
65
|
+
StateStorageError,
|
|
66
|
+
ExecutionError,
|
|
67
|
+
TerminationUnconfirmed,
|
|
68
|
+
RunnerClosing,
|
|
69
|
+
StateDirectoryLocked,
|
|
70
|
+
RemoteTerminationUnconfirmed,
|
|
71
|
+
ReleaseInterrupted,
|
|
72
|
+
RpcClientError.RpcClientError,
|
|
73
|
+
...errors
|
|
74
|
+
];
|
|
75
|
+
const isInternal = (error) => Schema.isSchemaError(error) || PlatformError.isPlatformError(error) || Array.some(internalErrors, (Class) => error instanceof Class);
|
|
76
|
+
const isPublic = (error) => Schema.is(UndeclaredFailure)(error) || Schema.is(RemoteWithdrawn)(error) || Schema.is(RemoteError)(error) || Schema.is(MissingInstance)(error);
|
|
77
|
+
const publicError = (declared, error) => isPublic(error) ? error : !isInternal(error) && Schema.is(declared)(error) ? error : RemoteError.make({ cause: Cause.fail(error) });
|
|
41
78
|
export { executionPlugin, publicError };
|
|
42
79
|
|
|
43
80
|
//# sourceMappingURL=execution.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution.js","names":["Connection.acquire","Services.endpoints","Control.endpoint","Host.initialize","Host.dispose","Host.load","Contract.UndeclaredFailure"],"sources":["../../src/internal/execution.ts"],"sourcesContent":["import { Plugin } from \"@graftland/graft\"\nimport {
|
|
1
|
+
{"version":3,"file":"execution.js","names":["Connection.acquire","Services.endpoints","Control.endpoint","Host.initialize","Host.dispose","Host.load","Errors.ProcessExited","Errors.TransportError","Errors.LocalTerminationTimeout","Errors.CredentialsError","Errors.AuthenticationFailed","Errors.RemoteEntryError","ChildErrors.AlreadyLoaded","ChildErrors.ContractNotFound","ChildErrors.ModuleImportFailed","ChildErrors.ActivationFailed","Model.PackageError","Model.SessionAccessDenied","Model.StaleSession","Model.LeaseExpired","Model.SessionStopped","Model.SessionConflict","Model.StateStorageError","Model.ExecutionError","Model.TerminationUnconfirmed","Model.RunnerClosing","Model.StateDirectoryLocked","Model.RemoteTerminationUnconfirmed","Assembly.errors","Contract.UndeclaredFailure"],"sources":["../../src/internal/execution.ts"],"sourcesContent":["import { Plugin } from \"@graftland/graft\"\nimport {\n\tArray,\n\tCause,\n\tEffect,\n\tFiber,\n\tPlatformError,\n\tSchema,\n\tScope,\n} from \"effect\"\nimport { SecureRandom } from \"effect/crypto\"\nimport { RpcClientError } from \"effect/rpc\"\nimport type {\n\tLocalTarget as Local,\n\tWorkerTarget as Worker,\n} from \"./runner/Connection\"\nimport { Connector } from \"../Transport\"\nimport { LocalTransport, WorkerTransport } from \"./directTransport\"\nimport { Credentials } from \"../Auth\"\nimport type { Duration } from \"effect\"\nimport * as Connection from \"./runner/Connection\"\nimport * as Services from \"./services\"\nimport * as Host from \"./host\"\nimport * as Errors from \"../Errors\"\nimport { RemoteWithdrawn, RemoteError, MissingInstance } from \"../Errors\"\nimport * as ChildErrors from \"./childErrors\"\nimport * as Assembly from \"./assembly\"\nimport * as Model from \"./runner/model\"\nimport { ReleaseInterrupted } from \"./release\"\nimport * as Contract from \"../Contract\"\nimport * as Control from \"./control\"\nimport { prepare } from \"./contract\"\n\nexport interface ExecutionOptions {\n\treadonly contractModule: string\n\treadonly shutdownTimeout?: Duration.Input | undefined\n}\n\nconst dependencies = (\n\ttarget: Local | Worker | Connection.ConfiguredRunner,\n): ReadonlyArray<Plugin.Dependency> =>\n\ttarget._tag === \"Connector\"\n\t\t? [Connector, Credentials]\n\t\t: target._tag === \"Local\"\n\t\t\t? [LocalTransport]\n\t\t\t: [WorkerTransport]\n\n/** One owned execution per activation, with explicitly mapped services. */\nexport const executionPlugin = <\n\tS extends Schema.Top & {\n\t\treadonly Encoded: Schema.Json\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n\tE extends Schema.Top & {\n\t\treadonly DecodingServices: never\n\t\treadonly EncodingServices: never\n\t},\n>(\n\tcontract: Contract.Contract<S, E>,\n\toptions: ExecutionOptions,\n\tconfigured: Local | Worker | Connection.ConfiguredRunner,\n\tannotations: Readonly<Record<string, unknown>> = {},\n): Plugin.Plugin<\n\tS[\"Encoded\"],\n\tS[\"Encoded\"],\n\t| E[\"Type\"]\n\t| Contract.UndeclaredFailure\n\t| RemoteError\n\t| RemoteWithdrawn\n\t| MissingInstance\n> =>\n\tPlugin.make({\n\t\tname: contract.name,\n\t\tinject: [\n\t\t\tSecureRandom.SecureRandom,\n\t\t\t...dependencies(configured),\n\t\t\t...Array.map(contract.inject, (service) => service.key),\n\t\t],\n\t\tconfig: Schema.toEncoded(contract.config),\n\t\tapply: Effect.fnUntraced(\n\t\t\tfunction* (input: Schema.Json) {\n\t\t\t\tconst prepared = prepare(contract)\n\t\t\t\tconst random = yield* SecureRandom.SecureRandom\n\t\t\t\tconst session = yield* random.uuidV4()\n\t\t\t\tconst active = yield* Connection.acquire(\n\t\t\t\t\tconfigured,\n\t\t\t\t\toptions.contractModule,\n\t\t\t\t\t{\n\t\t\t\t\t\tsession,\n\t\t\t\t\t\tserve: Services.endpoints(contract.inject),\n\t\t\t\t\t\tcall: {\n\t\t\t\t\t\t\t...Services.endpoints(contract.provides),\n\t\t\t\t\t\t\t[Control.endpoint]: prepared.control,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tHost.initialize(prepared),\n\t\t\t\t\tHost.dispose,\n\t\t\t\t\toptions.shutdownTimeout ?? \"5 seconds\",\n\t\t\t\t)\n\t\t\t\tyield* Host.load(active, input)\n\t\t\t\tfor (const service of contract.provides)\n\t\t\t\t\tyield* service\n\t\t\t\t\t\t.publish(active.connection.transport)\n\t\t\t\t\t\t.pipe(Scope.provide(active.connection.resources))\n\t\t\t\tyield* Plugin.fork(\n\t\t\t\t\tEffect.raceFirst(\n\t\t\t\t\t\tFiber.join(active.events),\n\t\t\t\t\t\tactive.remoteFailure.await,\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((error) => publicError(contract.error, error)),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\treturn () => Effect.succeed(false)\n\t\t\t},\n\t\t\tEffect.annotateLogs(annotations),\n\t\t\tEffect.mapError((error) => publicError(contract.error, error)),\n\t\t),\n\t})\n\n/** Failures raised by the host machinery; a permissive declared schema must not claim them. */\nconst internalErrors: ReadonlyArray<abstract new (...args: never) => unknown> =\n\t[\n\t\tErrors.ProcessExited,\n\t\tErrors.TransportError,\n\t\tErrors.LocalTerminationTimeout,\n\t\tErrors.CredentialsError,\n\t\tErrors.AuthenticationFailed,\n\t\tErrors.RemoteEntryError,\n\t\tChildErrors.AlreadyLoaded,\n\t\tChildErrors.ContractNotFound,\n\t\tChildErrors.ModuleImportFailed,\n\t\tChildErrors.ActivationFailed,\n\t\tModel.PackageError,\n\t\tModel.SessionAccessDenied,\n\t\tModel.StaleSession,\n\t\tModel.LeaseExpired,\n\t\tModel.SessionStopped,\n\t\tModel.SessionConflict,\n\t\tModel.StateStorageError,\n\t\tModel.ExecutionError,\n\t\tModel.TerminationUnconfirmed,\n\t\tModel.RunnerClosing,\n\t\tModel.StateDirectoryLocked,\n\t\tModel.RemoteTerminationUnconfirmed,\n\t\tReleaseInterrupted,\n\t\tRpcClientError.RpcClientError,\n\t\t...Assembly.errors,\n\t]\nconst isInternal = (error: unknown) =>\n\tSchema.isSchemaError(error) ||\n\tPlatformError.isPlatformError(error) ||\n\tArray.some(internalErrors, (Class) => error instanceof Class)\nconst isPublic = (\n\terror: unknown,\n): error is\n\t| Contract.UndeclaredFailure\n\t| RemoteWithdrawn\n\t| RemoteError\n\t| MissingInstance =>\n\tSchema.is(Contract.UndeclaredFailure)(error) ||\n\tSchema.is(RemoteWithdrawn)(error) ||\n\tSchema.is(RemoteError)(error) ||\n\tSchema.is(MissingInstance)(error)\n\nexport const publicError = <E extends Schema.Top>(\n\tdeclared: E,\n\terror: unknown,\n):\n\t| E[\"Type\"]\n\t| Contract.UndeclaredFailure\n\t| RemoteWithdrawn\n\t| RemoteError\n\t| MissingInstance =>\n\tisPublic(error)\n\t\t? error\n\t\t: // Classify host failures before the declared schema, which may be structural.\n\t\t\t!isInternal(error) && Schema.is(declared)(error)\n\t\t\t? error\n\t\t\t: RemoteError.make({ cause: Cause.fail(error) })\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsCA,MAAM,gBACL,WAEA,OAAO,SAAS,cACb,CAAC,WAAW,WAAW,IACvB,OAAO,SAAS,UACf,CAAC,cAAc,IACf,CAAC,eAAe;;AAGrB,MAAa,mBAWZ,UACA,SACA,YACA,cAAiD,CAAC,MAUlD,OAAO,KAAK;CACX,MAAM,SAAS;CACf,QAAQ;EACP,aAAa;EACb,GAAG,aAAa,UAAU;EAC1B,GAAG,MAAM,IAAI,SAAS,SAAS,YAAY,QAAQ,GAAG;CACvD;CACA,QAAQ,OAAO,UAAU,SAAS,MAAM;CACxC,OAAO,OAAO,WACb,WAAW,OAAoB;EAC9B,MAAM,WAAW,QAAQ,QAAQ;EAEjC,MAAM,UAAU,QAAO,OADD,aAAa,aAAA,CACL,OAAO;EACrC,MAAM,SAAS,OAAOA,QACrB,YACA,QAAQ,gBACR;GACC;GACA,OAAOC,UAAmB,SAAS,MAAM;GACzC,MAAM;IACL,GAAGA,UAAmB,SAAS,QAAQ;KACtCC,WAAmB,SAAS;GAC9B;EACD,GACAC,WAAgB,QAAQ,GACxBC,SACA,QAAQ,mBAAmB,WAC5B;EACA,OAAOC,KAAU,QAAQ,KAAK;EAC9B,KAAK,MAAM,WAAW,SAAS,UAC9B,OAAO,QACL,QAAQ,OAAO,WAAW,SAAS,CAAC,CACpC,KAAK,MAAM,QAAQ,OAAO,WAAW,SAAS,CAAC;EAClD,OAAO,OAAO,KACb,OAAO,UACN,MAAM,KAAK,OAAO,MAAM,GACxB,OAAO,cAAc,KACtB,CAAC,CAAC,KACD,OAAO,UAAU,UAAU,YAAY,SAAS,OAAO,KAAK,CAAC,CAC9D,CACD;EACA,aAAa,OAAO,QAAQ,KAAK;CAClC,GACA,OAAO,aAAa,WAAW,GAC/B,OAAO,UAAU,UAAU,YAAY,SAAS,OAAO,KAAK,CAAC,CAC9D;AACD,CAAC;;AAGF,MAAM,iBACL;CACCC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACAC;CACA;CACA,eAAe;CACf,GAAGC;AACJ;AACD,MAAM,cAAc,UACnB,OAAO,cAAc,KAAK,KAC1B,cAAc,gBAAgB,KAAK,KACnC,MAAM,KAAK,iBAAiB,UAAU,iBAAiB,KAAK;AAC7D,MAAM,YACL,UAMA,OAAO,GAAGC,iBAA0B,CAAC,CAAC,KAAK,KAC3C,OAAO,GAAG,eAAe,CAAC,CAAC,KAAK,KAChC,OAAO,GAAG,WAAW,CAAC,CAAC,KAAK,KAC5B,OAAO,GAAG,eAAe,CAAC,CAAC,KAAK;AAEjC,MAAa,eACZ,UACA,UAOA,SAAS,KAAK,IACX,QAED,CAAC,WAAW,KAAK,KAAK,OAAO,GAAG,QAAQ,CAAC,CAAC,KAAK,IAC7C,QACA,YAAY,KAAK,EAAE,OAAO,MAAM,KAAK,KAAK,EAAE,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { make } from "../FailureGroup.js";
|
|
2
2
|
import { connectWith } from "../assembly.js";
|
|
3
|
-
import { defaults } from "../Limits.js";
|
|
4
3
|
import { ProcessExited, TransportError } from "../../Errors.js";
|
|
4
|
+
import { defaults } from "../Limits.js";
|
|
5
5
|
import { cleanupCause } from "../cleanup.js";
|
|
6
6
|
import { make as make$1 } from "../port.js";
|
|
7
7
|
import { make as make$2 } from "../runner/Multiplex.js";
|
|
@@ -11,7 +11,7 @@ import { awaitTermination, childOf } from "../runner/model.js";
|
|
|
11
11
|
import { Cause, Duration, Effect, Exit, Fiber, Option, Ref, Scope } from "effect";
|
|
12
12
|
import { RpcClient } from "effect/rpc";
|
|
13
13
|
// src/internal/host/runner.ts
|
|
14
|
-
const connect = (target, contractModule, options, resources, processScope)
|
|
14
|
+
const connect = Effect.fnUntraced(function* (target, contractModule, options, resources, processScope) {
|
|
15
15
|
const instance = target.instance;
|
|
16
16
|
const margin = Duration.toMillis(target.margin ?? "5 seconds");
|
|
17
17
|
const channel$1 = yield* connectWith(target.explicitAuth).pipe(Scope.provide(processScope));
|
|
@@ -34,7 +34,7 @@ const connect = (target, contractModule, options, resources, processScope) => Ef
|
|
|
34
34
|
const finishStarted = yield* Ref.make(false);
|
|
35
35
|
const terminate = yield* Effect.cached(Effect.gen(function* () {
|
|
36
36
|
yield* Ref.set(finishStarted, true);
|
|
37
|
-
yield* failures.close;
|
|
37
|
+
const closed = yield* Effect.exit(failures.close);
|
|
38
38
|
const result = yield* awaitTermination(record.handle, session.Dispose(record.handle), record.leaseMillis, margin);
|
|
39
39
|
const { code, signal, stderr, cause } = result.exit;
|
|
40
40
|
yield* Effect.logInfo("Remote execution terminated", {
|
|
@@ -47,7 +47,8 @@ const connect = (target, contractModule, options, resources, processScope) => Ef
|
|
|
47
47
|
"remote.generation": record.handle.generation,
|
|
48
48
|
"remote.termination": result.kind
|
|
49
49
|
}));
|
|
50
|
-
|
|
50
|
+
const failure = Exit.isFailure(closed) ? Cause.combine(closed.cause, result.cause) : result.cause;
|
|
51
|
+
if (failure.reasons.length > 0) return yield* Effect.failCause(cleanupCause(failure));
|
|
51
52
|
}));
|
|
52
53
|
yield* Scope.addFinalizer(processScope, Effect.gen(function* () {
|
|
53
54
|
if (!(yield* Ref.get(finishStarted))) yield* terminate.pipe(Effect.catchCause((cause) => Effect.failCause(cleanupCause(cause))));
|
|
@@ -67,7 +68,7 @@ const connect = (target, contractModule, options, resources, processScope) => Ef
|
|
|
67
68
|
}).pipe(Scope.provide(resources));
|
|
68
69
|
const report = (cause) => Cause.hasInterruptsOnly(cause) ? Effect.void : failures.failCause(Cause.map(cause, (error) => TransportError.make({ cause: Cause.fail(error) })));
|
|
69
70
|
yield* failures.await.pipe(Effect.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Effect.void : peer.fail(TransportError.make({ cause }))), Effect.forkIn(resources));
|
|
70
|
-
yield* failures.run(Fiber.join(renewed).pipe(Effect.catchCause(
|
|
71
|
+
yield* failures.run(Fiber.join(renewed).pipe(Effect.catchCause(Effect.fnUntraced(function* (cause) {
|
|
71
72
|
if (Cause.hasInterruptsOnly(cause)) return;
|
|
72
73
|
const status = yield* Effect.exit(session.Status(record.handle).pipe(Effect.timeout("5 seconds")));
|
|
73
74
|
if (Exit.isSuccess(status) && status.value.phase === "Stopped") {
|
|
@@ -84,7 +85,7 @@ const connect = (target, contractModule, options, resources, processScope) => Ef
|
|
|
84
85
|
resources,
|
|
85
86
|
pid: Option.map(childOf(loaded), (child) => child.pid),
|
|
86
87
|
diagnostics: failures.cause,
|
|
87
|
-
terminate:
|
|
88
|
+
terminate: Effect.fnUntraced(function* () {
|
|
88
89
|
yield* Fiber.interrupt(renewed);
|
|
89
90
|
yield* terminate;
|
|
90
91
|
}),
|