@graftland/plugin-remote 0.2.0-beta.2 → 0.3.1
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/{Bootstrap-MCwivGN1.js → Bootstrap-Dr6sX7el.js} +2 -2
- package/dist/{Contract-CcpSIJm4.js → Contract-DL2mHvaT.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-BMKmu5Y7.js} +12 -1
- package/dist/Errors.d.ts +12 -0
- package/dist/Errors.d.ts.map +1 -1
- package/dist/Errors.js +12 -1
- package/dist/Errors.js.map +1 -1
- package/dist/{Graft-BsYq3F-J.js → Graft-CVyueNOf.js} +26 -19
- package/dist/{Packages-B1TPk8pa.js → Packages-JNL34JpS.js} +1 -1
- package/dist/{Peer-IJgFK6mD.js → Peer-BT7eAGmh.js} +2 -2
- 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/bin.js +7 -7
- package/dist/{childRuntime-DSqtFN9o.js → childRuntime-An0HsIzl.js} +7 -6
- package/dist/{cleanup-BPWr-5U9.js → cleanup-CXLa1Wd9.js} +1 -1
- package/dist/connectionEnded-DCpFCjMX.js +54 -0
- package/dist/{entry-SYsx9VNb.js → entry-B89sepMU.js} +13 -22
- 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 +3 -3
- 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 +2 -2
- 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 -4
- package/dist/host/worker.js.map +1 -1
- package/dist/{importer-D7zSgqxq.js → importer-Bk6U_sn4.js} +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.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.map +1 -1
- package/dist/internal/childRuntime.js +3 -1
- 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/entry.d.ts +1 -2
- package/dist/internal/entry.d.ts.map +1 -1
- package/dist/internal/entry.js +3 -13
- package/dist/internal/entry.js.map +1 -1
- package/dist/internal/execution.js +4 -2
- package/dist/internal/execution.js.map +1 -1
- package/dist/internal/host.js.map +1 -1
- package/dist/internal/port.d.ts +2 -10
- package/dist/internal/runner/Framing.d.ts +1 -11
- 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/workerMain.js +3 -3
- package/dist/{port-Blbh8tms.js → port-DSVUY8Bq.js} +1 -1
- package/dist/runner/auth/bearer.js +2 -2
- package/dist/runner/auth/jwt.js +3 -3
- package/dist/runner/auth/mtls.js +2 -2
- package/dist/runner/auth/none.js +1 -1
- package/dist/runner/index.js +5 -5
- package/dist/runner/stdio.js +2 -2
- package/dist/runner/unix.js +3 -3
- package/dist/runner/websocket.js +4 -4
- package/dist/{socketChannel-KmtzF-9G.js → socketChannel-C_ppdSzz.js} +1 -1
- package/dist/{supervisorPlugin-Inb1S5IV.js → supervisorPlugin-CivhM7x5.js} +7 -7
- package/dist/{token-v5ne2I0-.js → token-Cc_1CTbE.js} +1 -1
- package/dist/{tokenCredentials-WUJm2AKm.js → tokenCredentials-CI6mMRRd.js} +3 -3
- package/dist/{websocketServer-MXcCJx0v.js → websocketServer-D2Hk7wsA.js} +2 -2
- package/dist/{workerChannel-P82YdNjh.js → workerChannel-cmLc13vm.js} +1 -1
- package/package.json +3 -3
- package/src/Contract.ts +67 -51
- package/src/Errors.ts +15 -0
- package/src/Testing.ts +16 -2
- 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 +3 -1
- package/src/internal/auth/tokenCredentials.ts +1 -7
- package/src/internal/child.ts +1 -1
- package/src/internal/childRuntime.ts +4 -2
- package/src/internal/contract.ts +47 -0
- package/src/internal/credentials.ts +12 -9
- package/src/internal/entry.ts +1 -14
- package/src/internal/execution.ts +4 -2
- package/src/internal/host.ts +8 -11
- package/src/internal/services.ts +1 -19
- 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":"tokenCredentials.js","names":[],"sources":["../../../src/internal/auth/tokenCredentials.ts"],"sourcesContent":["import { Graft, Plugin } from \"@graftland/graft\"\nimport { ConfigDirectory } from \"@graftland/loader\"\nimport {\n\tCause,\n\tEffect,\n\tFileSystem,\n\tOption,\n\tPath,\n\tRedacted,\n\tSchema,\n} from \"effect\"\nimport { Credentials, type Prepared } from \"../../Auth\"\nimport { CredentialsError } from \"../../Errors\"\nimport { prepare } from \"./token\"\n\nexport const Config = Schema.Struct({\n\ttoken: Schema.Union([\n\t\tSchema.RedactedFromValue(Schema.String),\n\t\tSchema.Struct({ file: Schema.String }),\n\t]),\n})\nexport const plugin = (
|
|
1
|
+
{"version":3,"file":"tokenCredentials.js","names":[],"sources":["../../../src/internal/auth/tokenCredentials.ts"],"sourcesContent":["import { Graft, Plugin } from \"@graftland/graft\"\nimport { ConfigDirectory } from \"@graftland/loader\"\nimport {\n\tCause,\n\tEffect,\n\tFileSystem,\n\tOption,\n\tPath,\n\tRedacted,\n\tSchema,\n} from \"effect\"\nimport { Credentials, type Prepared } from \"../../Auth\"\nimport { CredentialsError } from \"../../Errors\"\nimport { prepare } from \"./token\"\n\nexport const Config = Schema.Struct({\n\ttoken: Schema.Union([\n\t\tSchema.RedactedFromValue(Schema.String),\n\t\tSchema.Struct({ file: Schema.String }),\n\t]),\n})\nexport const plugin = (name: string) =>\n\tPlugin.make({\n\t\tname,\n\t\tconfig: Config,\n\t\tinject: [FileSystem.FileSystem, Path.Path],\n\t\tapply: Effect.fnUntraced(function* (config) {\n\t\t\tconst fs = yield* FileSystem.FileSystem\n\t\t\tconst path = yield* Path.Path\n\t\t\tconst directory = yield* ConfigDirectory\n\t\t\tconst token = config.token\n\t\t\tconst read = Redacted.isRedacted(token)\n\t\t\t\t? Effect.succeed(token)\n\t\t\t\t: fs\n\t\t\t\t\t\t.readFileString(\n\t\t\t\t\t\t\tpath.resolve(\n\t\t\t\t\t\t\t\tOption.getOrElse(directory, () => \".\"),\n\t\t\t\t\t\t\t\ttoken.file,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.pipe(Effect.map(Redacted.make))\n\t\t\tyield* Graft.provide(Credentials, {\n\t\t\t\tkind: \"Authorization\",\n\t\t\t\tread: read.pipe(\n\t\t\t\t\tEffect.flatMap(prepare),\n\t\t\t\t\tEffect.mapBoth({\n\t\t\t\t\t\tonSuccess: (\n\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t): Extract<Prepared, { readonly _tag: \"Authorization\" }> => ({\n\t\t\t\t\t\t\t_tag: \"Authorization\",\n\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tonFailure: (error) =>\n\t\t\t\t\t\t\tCredentialsError.make({ cause: Cause.fail(error) }),\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t})\n\t\t}),\n\t})\n"],"mappings":";;;;;;;AAeA,MAAa,SAAS,OAAO,OAAO,EACnC,OAAO,OAAO,MAAM,CACnB,OAAO,kBAAkB,OAAO,MAAM,GACtC,OAAO,OAAO,EAAE,MAAM,OAAO,OAAO,CAAC,CACtC,CAAC,EACF,CAAC;AACD,MAAa,UAAU,SACtB,OAAO,KAAK;CACX;CACA,QAAQ;CACR,QAAQ,CAAC,WAAW,YAAY,KAAK,IAAI;CACzC,OAAO,OAAO,WAAW,WAAW,QAAQ;EAC3C,MAAM,KAAK,OAAO,WAAW;EAC7B,MAAM,OAAO,OAAO,KAAK;EACzB,MAAM,YAAY,OAAO;EACzB,MAAM,QAAQ,OAAO;EACrB,MAAM,OAAO,SAAS,WAAW,KAAK,IACnC,OAAO,QAAQ,KAAK,IACpB,GACC,eACA,KAAK,QACJ,OAAO,UAAU,iBAAiB,GAAG,GACrC,MAAM,IACP,CACD,CAAC,CACA,KAAK,OAAO,IAAI,SAAS,IAAI,CAAC;EAClC,OAAO,MAAM,QAAQ,aAAa;GACjC,MAAM;GACN,MAAM,KAAK,KACV,OAAO,QAAQ,OAAO,GACtB,OAAO,QAAQ;IACd,YACC,WAC4D;KAC5D,MAAM;KACN;IACD;IACA,YAAY,UACX,iBAAiB,KAAK,EAAE,OAAO,MAAM,KAAK,KAAK,EAAE,CAAC;GACpD,CAAC,CACF;EACD,CAAC;CACF,CAAC;AACF,CAAC"}
|
|
@@ -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.fail(contract.normalizeCause(cause))\n\t\t})\n\t\treturn { load, dispose, release }\n\t})\n"],"mappings":";;;;;;AAiCA,MAAM,aAAa,KAAK,WAAuB;;AAM/C,MAAa,aAAa,aACzB,OAAO,IAAI,aAAa;CACvB,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,WAAW,UACjB,OAAO,MAAM,KAAK,CAAC,CAAC,KACnB,OAAO,KAAK,WAAiC;GAC5C,MAAM;GACN,OAAO;IAAE,GAAG;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+
{"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.fail(contract.normalizeCause(cause))\n\t\t})\n\t\treturn { load, dispose, release }\n\t})\n"],"mappings":";;;;;;AAiCA,MAAM,aAAa,KAAK,WAAuB;;AAM/C,MAAa,aAAa,aACzB,OAAO,IAAI,aAAa;CACvB,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,WAAW,UACjB,OAAO,MAAM,KAAK,CAAC,CAAC,KACnB,OAAO,KAAK,WAAiC;GAC5C,MAAM;GACN,OAAO;IAAE,GAAG;IAAO;GAAM;GACzB,SAAS,WAAW,IAAI,OAAO;EAChC,EAAE,CACH,CACD,GACA,OAAO,OACN,OAAO,YAAkC;GACxC,MAAM;GACN,SAAS,WAAW,IAAI,OAAO;EAChC,EAAE,CACH,CACD;CACD;AACD,CAAC;AAeF,MAAM,YAAY,KAAK,WAAsB;AAC7C,MAAM,aAAa,UAClB,MAAM,SAAS,YACZ,OAAO,KAAK,MAAM,OAAO,IACzB,MAAM,SAAS,iBAA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cAAc,KAAK,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"}
|
|
@@ -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";
|
|
@@ -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 = (descriptor, channel, session = "local", bootstrap, stop = Effect.never) => Effect.scoped(Effect.gen(function* () {
|
|
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* () {
|
|
@@ -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 = (specifier: string) =>\n\tEffect.gen(function* () {\n\t\tconst module = yield* loadModule(specifier)\n\t\tconst contract = fromModule(module)\n\t\tif (Option.isNone(contract))\n\t\t\treturn yield* ContractNotFound.make({ module: specifier })\n\t\treturn contract.value\n\t})\n\nconst connect = (\n\tcontract:
|
|
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 = (specifier: string) =>\n\tEffect.gen(function* () {\n\t\tconst module = yield* loadModule(specifier)\n\t\tconst contract = fromModule(module)\n\t\tif (Option.isNone(contract))\n\t\t\treturn yield* ContractNotFound.make({ module: specifier })\n\t\treturn contract.value\n\t})\n\nconst connect = (\n\tcontract: PreparedContract,\n\tchannel: Port.Channel,\n\tsession: string,\n\tbootstrap: Bootstrap | undefined,\n) =>\n\tEffect.gen(function* () {\n\t\tconst mux =\n\t\t\tbootstrap === undefined ? undefined : yield* Multiplex.make(channel)\n\t\treturn yield* Port.make(\n\t\t\tmux === undefined ? channel : Wire.channel(mux, 1),\n\t\t\t{\n\t\t\t\tsession,\n\t\t\t\tserve: {\n\t\t\t\t\t...Services.endpoints(contract.provides),\n\t\t\t\t\t[endpoint]: contract.control,\n\t\t\t\t},\n\t\t\t\tcall: Services.endpoints(contract.inject),\n\t\t\t\t...(bootstrap === undefined ? {} : { limits: bootstrap.limits }),\n\t\t\t},\n\t\t)\n\t})\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 = \"local\",\n\tbootstrap?: Bootstrap,\n\tstop: Effect.Effect<unknown, ExecutionError> = Effect.never,\n): Effect.Effect<void, ExecutionError, Graft.Graft> =>\n\tEffect.scoped(\n\t\tEffect.gen(function* () {\n\t\t\tconst contract = prepare(descriptor)\n\t\t\tconst telemetry = yield* Child.telemetry(contract)\n\t\t\tconst loggers = yield* Logger.CurrentLoggers\n\t\t\tyield* Effect.gen(function* () {\n\t\t\t\tconst peer = yield* connect(contract, channel, session, bootstrap)\n\t\t\t\tconst instance = yield* Child.lifecycle(\n\t\t\t\t\tcontract,\n\t\t\t\t\tpeer,\n\t\t\t\t\tbootstrap?.identity ?? { id: session, generation: 1 },\n\t\t\t\t\ttelemetry,\n\t\t\t\t)\n\t\t\t\tconst handlers = yield* contract.control.toHandlers({\n\t\t\t\t\tLoad: ({ input }) => instance.load(input),\n\t\t\t\t\tDispose: () => instance.dispose,\n\t\t\t\t\tEvents: () => telemetry.eventStream,\n\t\t\t\t\tLogs: () => telemetry.logStream,\n\t\t\t\t})\n\t\t\t\tyield* RpcServer.make(contract.control, {\n\t\t\t\t\tdisableFatalDefects: true,\n\t\t\t\t}).pipe(\n\t\t\t\t\tEffect.provideContext(handlers),\n\t\t\t\t\tEffect.provideService(\n\t\t\t\t\t\tRpcServer.Protocol,\n\t\t\t\t\t\tpeer.serverProtocol(endpoint),\n\t\t\t\t\t),\n\t\t\t\t\tEffect.forkScoped,\n\t\t\t\t)\n\t\t\t\tyield* Effect.raceFirst(\n\t\t\t\t\tpeer.await.pipe(\n\t\t\t\t\t\tEffect.catchIf(\n\t\t\t\t\t\t\t(error) => closedNormally(error.cause),\n\t\t\t\t\t\t\t() => Effect.void,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\tExecutionError.make({\n\t\t\t\t\t\t\t\tdetail: \"Child transport failed\",\n\t\t\t\t\t\t\t\tcause: error.cause,\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\tstop,\n\t\t\t\t).pipe(\n\t\t\t\t\t// Release exports before closing the instance scope, including on interruption.\n\t\t\t\t\tEffect.ensuring(instance.release),\n\t\t\t\t)\n\t\t\t}).pipe(\n\t\t\t\tEffect.provideService(\n\t\t\t\t\tLogger.CurrentLoggers,\n\t\t\t\t\tnew Set([...loggers, telemetry.logger]),\n\t\t\t\t),\n\t\t\t)\n\t\t}),\n\t)\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,MAAa,QAAQ,cACpB,OAAO,IAAI,aAAa;CACvB,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;AAEF,MAAM,WACL,UACA,WACA,SACA,cAEA,OAAO,IAAI,aAAa;CACvB,MAAM,MACL,cAAc,KAAA,IAAY,KAAA,IAAY,OAAOA,OAAeC,SAAO;CACpE,OAAO,OAAOC,KACb,QAAQ,KAAA,IAAYD,YAAUE,QAAa,KAAK,CAAC,GACjD;EACC;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,CACD;AACD,CAAC;;AAGF,MAAa,OACZ,YACA,SACA,UAAU,SACV,WACA,OAA+C,OAAO,UAEtD,OAAO,OACN,OAAO,IAAI,aAAa;CACvB,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,CAAC,CACF"}
|
|
@@ -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":";;;;;;qBAwQa"}
|
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,
|
|
@@ -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],\n\tapply: load,\n})\n"],"mappings":";;;;;;;;;;;;;;;;AA2BA,IAAa,aAAb,cAAgC,OAAO,YAGrC,CAAC,CAAC,oBAAoB;CACvB,OAAO,OAAO,OAAO,OAAO,MAAM;CAClC,WAAW,OAAO,OAAO,OAAO,MAAM;CACtC,OAAO,OAAO;CACd,OAAO,OAAO,MAAM,OAAO,SAAS,OAAO,OAAO;AACnD,CAAC,CAAC,CAAC;CACF,IAAa,UAAU;EACtB,OAAO,gBAAgB,OAAO,UAAU,KAAK,aAAa,gBAAgB,EAAE,aA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,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: () =>\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],\n\tapply: load,\n})\n"],"mappings":";;;;;;;;;;;;;;;;AA2BA,MAAa,WAAW,OAAO,WAAW,WAAW,OAAe;CACnE,MAAM,QAAQ,OAAO,MAAM;CAC3B,MAAM,YAAY,OAAO;CACzB,QAAQ,UACP,OAAO,KAAKA,iBAAW,KAAK;EAAE;EAAO;EAAW;EAAO;CAAM,CAAC,CAAC;AACjE,CAAC;AACD,MAAa,UA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Aa;EACb,eAAe;EACf,KAAK;EACL,oBAAoB;CACrB;CACA,OAAO;AACR,CAAC"}
|
|
@@ -7,6 +7,7 @@ import { dispose, initialize, load } from "./host.js";
|
|
|
7
7
|
import { MissingInstance, RemoteError, RemoteWithdrawn } from "../Errors.js";
|
|
8
8
|
import { UndeclaredFailure } from "../Contract.js";
|
|
9
9
|
import { endpoint } from "./control.js";
|
|
10
|
+
import { prepare } from "./contract.js";
|
|
10
11
|
import { Plugin } from "@graftland/graft";
|
|
11
12
|
import { Array, Cause, Effect, Fiber, Schema, Scope } from "effect";
|
|
12
13
|
import { SecureRandom } from "effect/crypto";
|
|
@@ -22,15 +23,16 @@ const executionPlugin = (contract, options, configured, annotations = {}) => Plu
|
|
|
22
23
|
],
|
|
23
24
|
config: Schema.toEncoded(contract.config),
|
|
24
25
|
apply: (input) => Effect.gen(function* () {
|
|
26
|
+
const prepared = prepare(contract);
|
|
25
27
|
const session = yield* (yield* SecureRandom.SecureRandom).uuidV4();
|
|
26
28
|
const active = yield* acquire(configured, options.contractModule, {
|
|
27
29
|
session,
|
|
28
30
|
serve: endpoints(contract.inject),
|
|
29
31
|
call: {
|
|
30
32
|
...endpoints(contract.provides),
|
|
31
|
-
[endpoint]:
|
|
33
|
+
[endpoint]: prepared.control
|
|
32
34
|
}
|
|
33
|
-
}, initialize(
|
|
35
|
+
}, initialize(prepared), dispose, options.shutdownTimeout ?? "5 seconds");
|
|
34
36
|
yield* load(active, input);
|
|
35
37
|
for (const service of contract.provides) yield* service.publish(active.connection.transport).pipe(Scope.provide(active.connection.resources));
|
|
36
38
|
yield* Plugin.fork(Effect.raceFirst(Fiber.join(active.events), active.remoteFailure.await).pipe(Effect.mapError((error) => publicError(contract.error, error))));
|
|
@@ -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 { Array, Cause, Effect, Fiber, Schema, Scope } from \"effect\"\nimport { SecureRandom } from \"effect/crypto\"\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 { RemoteWithdrawn, RemoteError, MissingInstance } from \"../Errors\"\nimport * as Contract from \"../Contract\"\nimport * as Control from \"./control\"\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: (input) =>\n\t\t\tEffect.gen(function* () {\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]:
|
|
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 { Array, Cause, Effect, Fiber, Schema, Scope } from \"effect\"\nimport { SecureRandom } from \"effect/crypto\"\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 { RemoteWithdrawn, RemoteError, MissingInstance } from \"../Errors\"\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: (input) =>\n\t\t\tEffect.gen(function* () {\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}).pipe(\n\t\t\t\tEffect.annotateLogs(annotations),\n\t\t\t\tEffect.mapError((error) => publicError(contract.error, error)),\n\t\t\t),\n\t})\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\tSchema.is(declared)(error)\n\t\t? error\n\t\t: Schema.is(Contract.UndeclaredFailure)(error) ||\n\t\t\t Schema.is(RemoteWithdrawn)(error) ||\n\t\t\t Schema.is(RemoteError)(error) ||\n\t\t\t Schema.is(MissingInstance)(error)\n\t\t\t? error\n\t\t\t: RemoteError.make({ cause: Cause.fail(error) })\n"],"mappings":";;;;;;;;;;;;;;AAwBA,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,QAAQ,UACP,OAAO,IAAI,aAAa;EACvB,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,CAAC,CAAC,CAAC,KACF,OAAO,aAAa,WAAW,GAC/B,OAAO,UAAU,UAAU,YAAY,SAAS,OAAO,KAAK,CAAC,CAC9D;AACF,CAAC;AAEF,MAAa,eACZ,UACA,UAOA,OAAO,GAAG,QAAQ,CAAC,CAAC,KAAK,IACtB,QACA,OAAO,GAAGC,iBAA0B,CAAC,CAAC,KAAK,KAC1C,OAAO,GAAG,eAAe,CAAC,CAAC,KAAK,KAChC,OAAO,GAAG,WAAW,CAAC,CAAC,KAAK,KAC5B,OAAO,GAAG,eAAe,CAAC,CAAC,KAAK,IAChC,QACA,YAAY,KAAK,EAAE,OAAO,MAAM,KAAK,KAAK,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.js","names":["FailureGroup.make","Control.endpoint"],"sources":["../../src/internal/host.ts"],"sourcesContent":["import * as FailureGroup from \"./FailureGroup\"\nimport * as ContractModule from \"../Contract\"\nimport {\n\tCause,\n\tArray,\n\tDeferred,\n\tEffect,\n\tRef,\n\tOption,\n\tSchema,\n\tScope,\n\tStream,\n} from \"effect\"\nimport { RpcClient, type RpcClientError } from \"effect/rpc\"\nimport { RemoteWithdrawn } from \"../Errors\"\nimport * as Control from \"./control\"\nimport { cleanupCause } from \"./cleanup\"\nimport { Connection } from \"./runner/Connection\"\nimport type { Service } from \"./
|
|
1
|
+
{"version":3,"file":"host.js","names":["FailureGroup.make","Control.endpoint"],"sources":["../../src/internal/host.ts"],"sourcesContent":["import * as FailureGroup from \"./FailureGroup\"\nimport * as ContractModule from \"../Contract\"\nimport {\n\tCause,\n\tArray,\n\tDeferred,\n\tEffect,\n\tRef,\n\tOption,\n\tSchema,\n\tScope,\n\tStream,\n} from \"effect\"\nimport { RpcClient, type RpcClientError } from \"effect/rpc\"\nimport { RemoteWithdrawn } from \"../Errors\"\nimport * as Control from \"./control\"\nimport { cleanupCause } from \"./cleanup\"\nimport { Connection } from \"./runner/Connection\"\nimport type { Service } from \"../Contract\"\nimport type { ChildFailure } from \"./childErrors\"\nimport type { prepare } from \"./contract\"\n\ntype ErrorSchema = Schema.Top & {\n\treadonly DecodingServices: never\n\treadonly EncodingServices: never\n}\ntype ControlGroup<E extends ErrorSchema> = ReturnType<\n\ttypeof prepare<Schema.Codec<unknown, Schema.Json>, E>\n>[\"control\"]\ninterface Contract<E extends ErrorSchema> {\n\treadonly control: ControlGroup<E>\n\treadonly inject: ReadonlyArray<Service>\n\treadonly decodeCause: (\n\t\tinput: unknown,\n\t) => Effect.Effect<\n\t\tCause.Cause<E[\"Type\"] | ContractModule.UndeclaredFailure | ChildFailure>,\n\t\tSchema.SchemaError\n\t>\n}\ntype Client<E extends ErrorSchema> = RpcClient.FromGroup<\n\tControlGroup<E>,\n\tRpcClientError.RpcClientError\n>\nconst race = <A, E, R>(\n\tconnection: Connection[\"Service\"],\n\teffect: Effect.Effect<A, E, R>,\n) => Effect.raceFirst(effect, connection.transport.failure)\n\nconst forwardEvents = <E extends ErrorSchema>(\n\tcontract: Contract<E>,\n\tclient: Client<E>,\n\tconnection: Connection[\"Service\"],\n) =>\n\tEffect.gen(function* () {\n\t\tconst stopped = yield* Deferred.make<void>()\n\t\tconst remoteFailure = yield* FailureGroup.make<\n\t\t\t| E[\"Type\"]\n\t\t\t| ContractModule.UndeclaredFailure\n\t\t\t| ChildFailure\n\t\t\t| RemoteWithdrawn\n\t\t>()\n\t\tconst events = yield* race(\n\t\t\tconnection,\n\t\t\tclient.Events().pipe(\n\t\t\t\tStream.runForEach((event) => {\n\t\t\t\t\tswitch (event._tag) {\n\t\t\t\t\t\tcase \"Stopped\":\n\t\t\t\t\t\t\treturn Deferred.succeed(stopped, undefined)\n\t\t\t\t\t\tcase \"Withdrawing\":\n\t\t\t\t\t\t\treturn remoteFailure.fail(RemoteWithdrawn.make({}))\n\t\t\t\t\t\tcase \"Failed\":\n\t\t\t\t\t\t\treturn contract\n\t\t\t\t\t\t\t\t.decodeCause(event.cause)\n\t\t\t\t\t\t\t\t.pipe(Effect.flatMap((cause) => remoteFailure.failCause(cause)))\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t),\n\t\t).pipe(\n\t\t\tEffect.tapCause(connection.transport.report),\n\t\t\tEffect.forkIn(connection.resources),\n\t\t)\n\t\treturn { stopped, remoteFailure, events }\n\t})\nconst forwardLogs = <E extends ErrorSchema>(\n\tcontract: Contract<E>,\n\tclient: Client<E>,\n\tconnection: Connection[\"Service\"],\n) =>\n\tEffect.gen(function* () {\n\t\tconst logsEnded = yield* Deferred.make<void>()\n\t\tconst reportedDrops = yield* Ref.make(0)\n\t\tyield* race(\n\t\t\tconnection,\n\t\t\tclient.Logs().pipe(\n\t\t\t\tStream.runForEach((event) =>\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tconst previous = yield* Ref.getAndSet(reportedDrops, event.dropped)\n\t\t\t\t\t\tif (event.dropped > previous)\n\t\t\t\t\t\t\tyield* Effect.logWarning(\"Remote logs were dropped\").pipe(\n\t\t\t\t\t\t\t\tEffect.annotateLogs({\n\t\t\t\t\t\t\t\t\t...(Option.isSome(connection.pid)\n\t\t\t\t\t\t\t\t\t\t? { \"remote.pid\": connection.pid.value }\n\t\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\t\t\"remote.logs.dropped\": event.dropped - previous,\n\t\t\t\t\t\t\t\t\t\"remote.logs.droppedTotal\": event.dropped,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\tif (event._tag === \"LogsEnded\") {\n\t\t\t\t\t\t\tyield* Deferred.succeed(logsEnded, undefined)\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst entry = event.entry\n\t\t\t\t\t\tconst cause = yield* contract.decodeCause(entry.cause)\n\t\t\t\t\t\tyield* Effect.logWithLevel(\n\t\t\t\t\t\t\tentry.level === \"All\" || entry.level === \"None\"\n\t\t\t\t\t\t\t\t? \"Info\"\n\t\t\t\t\t\t\t\t: entry.level,\n\t\t\t\t\t\t)(\n\t\t\t\t\t\t\t...(Array.isArray(entry.message)\n\t\t\t\t\t\t\t\t? entry.message\n\t\t\t\t\t\t\t\t: [entry.message]),\n\t\t\t\t\t\t\tcause,\n\t\t\t\t\t\t).pipe(\n\t\t\t\t\t\t\tEffect.annotateLogs({\n\t\t\t\t\t\t\t\t...(Option.isSome(connection.pid)\n\t\t\t\t\t\t\t\t\t? { \"remote.pid\": connection.pid.value }\n\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\t...(connection.threadId === undefined\n\t\t\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t\t\t: { \"remote.threadId\": connection.threadId }),\n\t\t\t\t\t\t\t\t\"remote.annotations\": entry.annotations,\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),\n\t\t).pipe(\n\t\t\tEffect.tapCause(connection.transport.report),\n\t\t\tEffect.forkIn(connection.resources),\n\t\t)\n\t\treturn logsEnded\n\t})\nexport const initialize = <E extends ErrorSchema>(contract: Contract<E>) =>\n\tEffect.gen(function* () {\n\t\tconst connection = yield* Connection\n\t\tconst client = yield* RpcClient.make(contract.control).pipe(\n\t\t\tEffect.provideService(\n\t\t\t\tRpcClient.Protocol,\n\t\t\t\tconnection.transport.clientProtocol(Control.endpoint),\n\t\t\t),\n\t\t\tScope.provide(connection.resources),\n\t\t)\n\t\tfor (const service of contract.inject)\n\t\t\tyield* service\n\t\t\t\t.serve(connection.transport)\n\t\t\t\t.pipe(\n\t\t\t\t\tEffect.tapCause(connection.transport.report),\n\t\t\t\t\tEffect.forkIn(connection.resources),\n\t\t\t\t)\n\t\tconst events = yield* forwardEvents(contract, client, connection)\n\t\tconst logsEnded = yield* forwardLogs(contract, client, connection)\n\t\treturn { connection, client, ...events, logsEnded }\n\t})\ntype Active<E extends ErrorSchema> = Effect.Success<\n\tReturnType<typeof initialize<E>>\n>\nexport const load = <E extends ErrorSchema>(\n\tactive: Active<E>,\n\tinput: Schema.Json,\n) =>\n\trace(\n\t\tactive.connection,\n\t\tEffect.raceFirst(\n\t\t\tactive.client\n\t\t\t\t.Load({ input })\n\t\t\t\t.pipe(\n\t\t\t\t\tEffect.catchIf(\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tcause,\n\t\t\t\t\t\t): cause is Cause.Cause<\n\t\t\t\t\t\t\tE[\"Type\"] | ContractModule.UndeclaredFailure | ChildFailure\n\t\t\t\t\t\t> => Cause.isCause(cause),\n\t\t\t\t\t\tEffect.failCause,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\tactive.remoteFailure.await,\n\t\t),\n\t)\nexport const dispose = <E extends ErrorSchema>(active: Active<E>) =>\n\tEffect.gen(function* () {\n\t\tconst result = yield* race(\n\t\t\tactive.connection,\n\t\t\tactive.client\n\t\t\t\t.Dispose()\n\t\t\t\t.pipe(Effect.catchIf(Cause.isCause, Effect.succeed)),\n\t\t)\n\t\tconst cause = Cause.isCause(result) ? result : Cause.empty\n\t\t// A remote cleanup failure still permits the bounded event and log tail to drain.\n\t\tyield* race(\n\t\t\tactive.connection,\n\t\t\tDeferred.await(active.stopped).pipe(\n\t\t\t\tEffect.andThen(Deferred.await(active.logsEnded)),\n\t\t\t),\n\t\t).pipe(Effect.onError(() => Effect.failCause(cleanupCause(cause))))\n\t\treturn cause\n\t})\n"],"mappings":";;;;;;;;AA2CA,MAAM,QACL,YACA,WACI,OAAO,UAAU,QAAQ,WAAW,UAAU,OAAO;AAE1D,MAAM,iBACL,UACA,QACA,eAEA,OAAO,IAAI,aAAa;CACvB,MAAM,UAAU,OAAO,SAAS,KAAW;CAC3C,MAAM,gBAAgB,OAAOA,KAK3B;CAqBF,OAAO;EAAE;EAAS;EAAe,QAAA,OApBX,KACrB,YACA,OAAO,OAAO,CAAC,CAAC,KACf,OAAO,YAAY,UAAU;GAC5B,QAAQ,MAAM,MAAd;IACC,KAAK,WACJ,OAAO,SAAS,QAAQ,SAAS,KAAA,CAAS;IAC3C,KAAK,eACJ,OAAO,cAAc,KAAK,gBAAgB,KAAK,CAAC,CAAC,CAAC;IACnD,KAAK,UACJ,OAAO,SACL,YAAY,MAAM,KAAK,CAAC,CACxB,KAAK,OAAO,SAAS,UAAU,cAAc,UAAU,KAAK,CAAC,CAAC;GAClE;EACD,CAAC,CACF,CACD,CAAC,CAAC,KACD,OAAO,SAAS,WAAW,UAAU,MAAM,GAC3C,OAAO,OAAO,WAAW,SAAS,CACnC;CACwC;AACzC,CAAC;AACF,MAAM,eACL,UACA,QACA,eAEA,OAAO,IAAI,aAAa;CACvB,MAAM,YAAY,OAAO,SAAS,KAAW;CAC7C,MAAM,gBAAgB,OAAO,IAAI,KAAK,CAAC;CACvC,OAAO,KACN,YACA,OAAO,KAAK,CAAC,CAAC,KACb,OAAO,YAAY,UAClB,OAAO,IAAI,aAAa;EACvB,MAAM,WAAW,OAAO,IAAI,UAAU,eAAe,MAAM,OAAO;EAClE,IAAI,MAAM,UAAU,UACnB,OAAO,OAAO,WAAW,0BAA0B,CAAC,CAAC,KACpD,OAAO,aAA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Ac,UAAU,QAAQ,UAAU;CAChE,MAAM,YAAY,OAAO,YAAY,UAAU,QAAQ,UAAU;CACjE,OAAO;EAAE;EAAY;EAAQ,GAAG;EAAQ;CAAU;AACnD,CAAC;AAIF,MAAa,QACZ,QACA,UAEA,KACC,OAAO,YACP,OAAO,UACN,OAAO,OACL,KAAK,EAAE,MAAM,CAAC,CAAC,CACf,KACA,OAAO,SAEL,UAGI,MAAM,QAAQ,KAAK,GACxB,OAAO,SACR,CACD,GACD,OAAO,cAAc,KACtB,CACD;AACD,MAAa,WAAkC,WAC9C,OAAO,IAAI,aAAa;CACvB,MAAM,SAAS,OAAO,KACrB,OAAO,YACP,OAAO,OACL,QAAQ,CAAC,CACT,KAAK,OAAO,QAAQ,MAAM,SAAS,OAAO,OAAO,CAAC,CACrD;CACA,MAAM,QAAQ,MAAM,QAAQ,MAAM,IAAI,SAAS,MAAM;CAErD,OAAO,KACN,OAAO,YACP,SAAS,MAAM,OAAO,OAAO,CAAC,CAAC,KAC9B,OAAO,QAAQ,SAAS,MAAM,OAAO,SAAS,CAAC,CAChD,CACD,CAAC,CAAC,KAAK,OAAO,cAAc,OAAO,UAAU,aAAa,KAAK,CAAC,CAAC,CAAC;CAClE,OAAO;AACR,CAAC"}
|
package/dist/internal/port.d.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { Channel } from "../Transport.js";
|
|
2
|
-
import
|
|
2
|
+
import "../Errors.js";
|
|
3
3
|
import "./Limits.js";
|
|
4
4
|
import { Context, Effect, Scope } from "effect";
|
|
5
|
-
import { Rpc, RpcClient, RpcGroup, RpcServer } from "effect/rpc";
|
|
6
|
-
export interface Port {
|
|
7
|
-
readonly clientProtocol: (endpoint: string) => RpcClient.Protocol["Service"];
|
|
8
|
-
readonly serverProtocol: (endpoint: string) => RpcServer.Protocol["Service"];
|
|
9
|
-
readonly await: Effect.Effect<never, TransportError>;
|
|
10
|
-
readonly fail: (error: TransportError) => Effect.Effect<void>;
|
|
11
|
-
readonly end: Effect.Effect<void, TransportError>;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=port.d.ts.map
|
|
5
|
+
import { Rpc, RpcClient, RpcGroup, RpcServer } from "effect/rpc";
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
import { Effect, Result, Schema } from "effect";
|
|
2
|
-
declare const FrameError_base: Schema.Class<FrameError, Schema.TaggedStruct<"FrameError", {
|
|
3
|
-
readonly detail: Schema.String;
|
|
4
|
-
}>, import("effect/Cause").YieldableError & {
|
|
5
|
-
readonly brand: unique symbol;
|
|
6
|
-
}>;
|
|
7
|
-
export declare class FrameError extends FrameError_base {
|
|
8
|
-
get message(): string;
|
|
9
|
-
}
|
|
10
|
-
export {};
|
|
11
|
-
//# sourceMappingURL=Framing.d.ts.map
|
|
1
|
+
import { Effect, Result, Schema } from "effect";
|
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Context, Effect, Scope } from "effect";
|
|
1
|
+
import { Service } from "../Contract.js";
|
|
2
|
+
import { Context } from "effect";
|
|
4
3
|
import { Rpc, RpcClient, RpcClientError, RpcGroup } from "effect/rpc";
|
|
5
|
-
type Peer = Port;
|
|
6
|
-
/** RPC types stay inside the descriptor; Graft supplies its dynamic activation context. */
|
|
7
|
-
export interface Service<R = never, ClientR = never> {
|
|
8
|
-
readonly key: Context.Key<unknown, unknown>;
|
|
9
|
-
readonly group: Pick<RpcGroup.RpcGroup<Rpc.Any>, "requests">;
|
|
10
|
-
readonly serve: (port: Pick<Peer, "serverProtocol">) => Effect.Effect<never, never, R>;
|
|
11
|
-
readonly publish: (port: Pick<Peer, "clientProtocol">) => Effect.Effect<void, Graft.ServiceConflict, Graft.Graft | Scope.Scope | ClientR>;
|
|
12
|
-
}
|
|
13
4
|
export declare const service: <I, S, R extends Rpc.Any, H extends RpcGroup.HandlersFrom<R>>(key: Context.Key<I, S>, group: RpcGroup.RpcGroup<R>, mapping: {
|
|
14
5
|
readonly toHandlers: (value: S) => H;
|
|
15
6
|
readonly fromClient: (client: RpcClient.RpcClient<R, RpcClientError.RpcClientError>) => S;
|
|
16
7
|
}) => Service<RpcGroup.HandlersServices<R, H> | Rpc.Middleware<R> | Rpc.ServicesServer<R>, Rpc.MiddlewareClient<R>>;
|
|
17
|
-
export {};
|
|
18
8
|
//# sourceMappingURL=services.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.d.ts","names":[
|
|
1
|
+
{"version":3,"file":"services.d.ts","names":[],"sources":["../../src/internal/services.ts"],"mappings":";;;qBAMa,UACZ,GACA,GACA,UAAU,IAAI,KACd,UAAU,SAAS,aAAa,IAAE,KAE7B,QAAQ,IAAI,GAAG,IAAE,OACf,SAAS,SAAS,IAAE;WAEjB,aAAa,OAAO,MAAM;WAC1B,aACR,QAAQ,UAAU,UAAU,GAAG,eAAe,oBAC1C;MAEJ,QACF,SAAS,iBAAiB,GAAG,KAAK,IAAI,WAAW,KAAK,IAAI,eAAe,IACzE,IAAI,iBAAiB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.js","names":[],"sources":["../../src/internal/services.ts"],"sourcesContent":["import { Array, Context, Effect, Record } from \"effect\"\nimport { Graft } from \"@graftland/graft\"\nimport { RpcClient, RpcServer } from \"effect/rpc\"\nimport type {
|
|
1
|
+
{"version":3,"file":"services.js","names":[],"sources":["../../src/internal/services.ts"],"sourcesContent":["import { Array, Context, Effect, Record } from \"effect\"\nimport { Graft } from \"@graftland/graft\"\nimport { RpcClient, RpcServer } from \"effect/rpc\"\nimport type { Rpc, RpcClientError, RpcGroup } from \"effect/rpc\"\nimport type { Service } from \"../Contract\"\n\nexport const service = <\n\tI,\n\tS,\n\tR extends Rpc.Any,\n\tH extends RpcGroup.HandlersFrom<R>,\n>(\n\tkey: Context.Key<I, S>,\n\tgroup: RpcGroup.RpcGroup<R>,\n\tmapping: {\n\t\treadonly toHandlers: (value: S) => H\n\t\treadonly fromClient: (\n\t\t\tclient: RpcClient.RpcClient<R, RpcClientError.RpcClientError>,\n\t\t) => S\n\t},\n): Service<\n\tRpcGroup.HandlersServices<R, H> | Rpc.Middleware<R> | Rpc.ServicesServer<R>,\n\tRpc.MiddlewareClient<R>\n> => ({\n\tkey,\n\tgroup,\n\tserve: Effect.fnUntraced(function* (port) {\n\t\t// Graft admits the activation from this descriptor's key before serving it.\n\t\tconst context = yield* Effect.context<never>()\n\t\tconst value = yield* Effect.fromOption(\n\t\t\tContext.getOption(context, key),\n\t\t).pipe(Effect.orDie)\n\t\tconst handlers = yield* group.toHandlers(mapping.toHandlers(value))\n\t\treturn yield* RpcServer.make(group, { disableFatalDefects: true }).pipe(\n\t\t\tEffect.provideContext(handlers),\n\t\t\tEffect.provideService(RpcServer.Protocol, port.serverProtocol(key.key)),\n\t\t)\n\t}),\n\tpublish: Effect.fnUntraced(function* (port) {\n\t\tconst client = yield* RpcClient.make(group).pipe(\n\t\t\tEffect.provideService(RpcClient.Protocol, port.clientProtocol(key.key)),\n\t\t)\n\t\tyield* Graft.provide(key, mapping.fromClient(client))\n\t}),\n})\nexport const endpoints = (services: ReadonlyArray<Service>) =>\n\tRecord.fromEntries(\n\t\tArray.map(\n\t\t\tservices,\n\t\t\t(service) =>\n\t\t\t\t[service.key.key, service.group] satisfies readonly [\n\t\t\t\t\tstring,\n\t\t\t\t\tService[\"group\"],\n\t\t\t\t],\n\t\t),\n\t)\n"],"mappings":";;;;AAMA,MAAa,WAMZ,KACA,OACA,aASK;CACL;CACA;CACA,OAAO,OAAO,WAAW,WAAW,MAAM;EAEzC,MAAM,UAAU,OAAO,OAAO,QAAe;EAC7C,MAAM,QAAQ,OAAO,OAAO,WAC3B,QAAQ,UAAU,SAAS,GAAG,CAC/B,CAAC,CAAC,KAAK,OAAO,KAAK;EACnB,MAAM,WAAW,OAAO,MAAM,WAAW,QAAQ,WAAW,KAAK,CAAC;EAClE,OAAO,OAAO,UAAU,KAAK,OAAO,EAAE,qBAAqB,KAAK,CAAC,CAAC,CAAC,KAClE,OAAO,eAAe,QAAQ,GAC9B,OAAO,eAAe,UAAU,UAAU,KAAK,eAAe,IAAI,GAAG,CAAC,CACvE;CACD,CAAC;CACD,SAAS,OAAO,WAAW,WAAW,MAAM;EAC3C,MAAM,SAAS,OAAO,UAAU,KAAK,KAAK,CAAC,CAAC,KAC3C,OAAO,eAAe,UAAU,UAAU,KAAK,eAAe,IAAI,GAAG,CAAC,CACvE;EACA,OAAO,MAAM,QAAQ,KAAK,QAAQ,WAAW,MAAM,CAAC;CACrD,CAAC;AACF;AACA,MAAa,aAAa,aACzB,OAAO,YACN,MAAM,IACL,WACC,YACA,CAAC,QAAQ,IAAI,KAAK,QAAQ,KAAK,CAIjC,CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as Config, n as default } from "../supervisorPlugin-
|
|
1
|
+
export { t as Config, n as default } from "../supervisorPlugin-CivhM7x5.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { r as layer } from "../Graft-
|
|
2
|
-
import { n as run, r as platform, t as load } from "../childRuntime-
|
|
3
|
-
import { n as Bootstrap, t as make } from "../workerChannel-
|
|
1
|
+
import { r as layer } from "../Graft-CVyueNOf.js";
|
|
2
|
+
import { n as run, r as platform, t as load } from "../childRuntime-An0HsIzl.js";
|
|
3
|
+
import { n as Bootstrap, t as make } from "../workerChannel-cmLc13vm.js";
|
|
4
4
|
import { Effect, Layer, Schema } from "effect";
|
|
5
5
|
import { NodeRuntime } from "@effect/platform-node";
|
|
6
6
|
import { parentPort, workerData } from "node:worker_threads";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as EndOfStream } from "./Framing-zaYdOJnT.js";
|
|
2
2
|
import { t as make$1 } from "./FailureGroup-BcH0XOBi.js";
|
|
3
|
-
import {
|
|
3
|
+
import { l as TransportError } from "./Errors-BMKmu5Y7.js";
|
|
4
4
|
import { Array, Cause, Context, Data, Deferred, Effect, Fiber, HashMap, Option, Queue, Record, Result, Schema, Stream, TxQueue, TxRef } from "effect";
|
|
5
5
|
import { RpcClient, RpcClientError, RpcSerialization, RpcServer } from "effect/rpc";
|
|
6
6
|
// packages/remote/src/internal/Limits.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as provide, l as make } from "../../Graft-
|
|
1
|
+
import { a as provide, l as make } from "../../Graft-CVyueNOf.js";
|
|
2
2
|
import { t as Authenticator } from "../../Auth-BElTC9_X.js";
|
|
3
3
|
import { t as ConfigDirectory } from "../../ConfigDirectory-BCC6q2R4.js";
|
|
4
|
-
import { r as read, t as invalid } from "../../token-
|
|
4
|
+
import { r as read, t as invalid } from "../../token-Cc_1CTbE.js";
|
|
5
5
|
import { Array, Effect, FileSystem, Option, Path, Record, Redacted, Schema } from "effect";
|
|
6
6
|
import { Digest } from "effect/crypto";
|
|
7
7
|
import { Hex } from "effect/encoding";
|