@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.
Files changed (124) hide show
  1. package/dist/{Bootstrap-MCwivGN1.js → Bootstrap-Dr6sX7el.js} +2 -2
  2. package/dist/{Contract-CcpSIJm4.js → Contract-DL2mHvaT.js} +8 -46
  3. package/dist/Contract.d.ts +50 -53
  4. package/dist/Contract.d.ts.map +1 -1
  5. package/dist/Contract.js +1 -1
  6. package/dist/Contract.js.map +1 -1
  7. package/dist/{Errors-oPsTLY7l.js → Errors-BMKmu5Y7.js} +12 -1
  8. package/dist/Errors.d.ts +12 -0
  9. package/dist/Errors.d.ts.map +1 -1
  10. package/dist/Errors.js +12 -1
  11. package/dist/Errors.js.map +1 -1
  12. package/dist/{Graft-BsYq3F-J.js → Graft-CVyueNOf.js} +26 -19
  13. package/dist/{Packages-B1TPk8pa.js → Packages-JNL34JpS.js} +1 -1
  14. package/dist/{Peer-IJgFK6mD.js → Peer-BT7eAGmh.js} +2 -2
  15. package/dist/Testing.d.ts +4 -4
  16. package/dist/Testing.d.ts.map +1 -1
  17. package/dist/Testing.js +10 -4
  18. package/dist/Testing.js.map +1 -1
  19. package/dist/bin.js +7 -7
  20. package/dist/{childRuntime-DSqtFN9o.js → childRuntime-An0HsIzl.js} +7 -6
  21. package/dist/{cleanup-BPWr-5U9.js → cleanup-CXLa1Wd9.js} +1 -1
  22. package/dist/connectionEnded-DCpFCjMX.js +54 -0
  23. package/dist/{entry-SYsx9VNb.js → entry-B89sepMU.js} +13 -22
  24. package/dist/host/auth/bearer.d.ts +1 -2
  25. package/dist/host/auth/bearer.d.ts.map +1 -1
  26. package/dist/host/auth/bearer.js +1 -1
  27. package/dist/host/auth/bearer.js.map +1 -1
  28. package/dist/host/auth/jwt.d.ts +1 -2
  29. package/dist/host/auth/jwt.d.ts.map +1 -1
  30. package/dist/host/auth/jwt.js +1 -1
  31. package/dist/host/auth/jwt.js.map +1 -1
  32. package/dist/host/auth/mtls.js +2 -2
  33. package/dist/host/auth/none.js +1 -1
  34. package/dist/host/command.d.ts +1 -1
  35. package/dist/host/command.d.ts.map +1 -1
  36. package/dist/host/command.js +3 -3
  37. package/dist/host/command.js.map +1 -1
  38. package/dist/host/local.d.ts +1 -2
  39. package/dist/host/local.d.ts.map +1 -1
  40. package/dist/host/local.js +2 -2
  41. package/dist/host/local.js.map +1 -1
  42. package/dist/host/unix.d.ts +1 -1
  43. package/dist/host/unix.d.ts.map +1 -1
  44. package/dist/host/unix.js +3 -3
  45. package/dist/host/unix.js.map +1 -1
  46. package/dist/host/websocket.d.ts +1 -1
  47. package/dist/host/websocket.d.ts.map +1 -1
  48. package/dist/host/websocket.js +3 -3
  49. package/dist/host/websocket.js.map +1 -1
  50. package/dist/host/worker.d.ts +1 -2
  51. package/dist/host/worker.d.ts.map +1 -1
  52. package/dist/host/worker.js +4 -4
  53. package/dist/host/worker.js.map +1 -1
  54. package/dist/{importer-D7zSgqxq.js → importer-Bk6U_sn4.js} +1 -1
  55. package/dist/index.d.ts +2 -3
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +8 -8
  58. package/dist/index.js.map +1 -1
  59. package/dist/internal/auth/tokenCredentials.d.ts +0 -1
  60. package/dist/internal/auth/tokenCredentials.d.ts.map +1 -1
  61. package/dist/internal/auth/tokenCredentials.js.map +1 -1
  62. package/dist/internal/child.js.map +1 -1
  63. package/dist/internal/childRuntime.js +3 -1
  64. package/dist/internal/childRuntime.js.map +1 -1
  65. package/dist/internal/contract.js +26 -0
  66. package/dist/internal/contract.js.map +1 -0
  67. package/dist/internal/credentials.d.ts +6 -6
  68. package/dist/internal/credentials.d.ts.map +1 -1
  69. package/dist/internal/credentials.js.map +1 -1
  70. package/dist/internal/entry.d.ts +1 -2
  71. package/dist/internal/entry.d.ts.map +1 -1
  72. package/dist/internal/entry.js +3 -13
  73. package/dist/internal/entry.js.map +1 -1
  74. package/dist/internal/execution.js +4 -2
  75. package/dist/internal/execution.js.map +1 -1
  76. package/dist/internal/host.js.map +1 -1
  77. package/dist/internal/port.d.ts +2 -10
  78. package/dist/internal/runner/Framing.d.ts +1 -11
  79. package/dist/internal/services.d.ts +2 -12
  80. package/dist/internal/services.d.ts.map +1 -1
  81. package/dist/internal/services.js.map +1 -1
  82. package/dist/internal/supervisorPlugin.js +1 -1
  83. package/dist/internal/workerMain.js +3 -3
  84. package/dist/{port-Blbh8tms.js → port-DSVUY8Bq.js} +1 -1
  85. package/dist/runner/auth/bearer.js +2 -2
  86. package/dist/runner/auth/jwt.js +3 -3
  87. package/dist/runner/auth/mtls.js +2 -2
  88. package/dist/runner/auth/none.js +1 -1
  89. package/dist/runner/index.js +5 -5
  90. package/dist/runner/stdio.js +2 -2
  91. package/dist/runner/unix.js +3 -3
  92. package/dist/runner/websocket.js +4 -4
  93. package/dist/{socketChannel-KmtzF-9G.js → socketChannel-C_ppdSzz.js} +1 -1
  94. package/dist/{supervisorPlugin-Inb1S5IV.js → supervisorPlugin-CivhM7x5.js} +7 -7
  95. package/dist/{token-v5ne2I0-.js → token-Cc_1CTbE.js} +1 -1
  96. package/dist/{tokenCredentials-WUJm2AKm.js → tokenCredentials-CI6mMRRd.js} +3 -3
  97. package/dist/{websocketServer-MXcCJx0v.js → websocketServer-D2Hk7wsA.js} +2 -2
  98. package/dist/{workerChannel-P82YdNjh.js → workerChannel-cmLc13vm.js} +1 -1
  99. package/package.json +3 -3
  100. package/src/Contract.ts +67 -51
  101. package/src/Errors.ts +15 -0
  102. package/src/Testing.ts +16 -2
  103. package/src/host/auth/bearer.ts +1 -6
  104. package/src/host/auth/jwt.ts +1 -6
  105. package/src/host/command.ts +2 -0
  106. package/src/host/local.ts +5 -9
  107. package/src/host/unix.ts +2 -0
  108. package/src/host/websocket.ts +2 -0
  109. package/src/host/worker.ts +4 -6
  110. package/src/index.ts +3 -1
  111. package/src/internal/auth/tokenCredentials.ts +1 -7
  112. package/src/internal/child.ts +1 -1
  113. package/src/internal/childRuntime.ts +4 -2
  114. package/src/internal/contract.ts +47 -0
  115. package/src/internal/credentials.ts +12 -9
  116. package/src/internal/entry.ts +1 -14
  117. package/src/internal/execution.ts +4 -2
  118. package/src/internal/host.ts +8 -11
  119. package/src/internal/services.ts +1 -19
  120. package/dist/connectionEnded-DUgcobEd.js +0 -9
  121. package/dist/internal/childErrors.d.ts +0 -33
  122. package/dist/internal/childErrors.d.ts.map +0 -1
  123. package/dist/internal/port.d.ts.map +0 -1
  124. package/dist/internal/runner/Framing.d.ts.map +0 -1
@@ -15,9 +15,11 @@ export type Source<A, D extends ReadonlyArray<Plugin.Dependency>, E = unknown> =
15
15
  NoInfer<Plugin.Required<D>> | Scope.Scope
16
16
  >
17
17
  }
18
- type Token<D extends ReadonlyArray<Plugin.Dependency>> =
18
+ /** A token value, a file, or a credential effect with declared dependencies. */
19
+ export type Token<D extends ReadonlyArray<Plugin.Dependency>> =
19
20
  string | { readonly file: string } | Source<Redacted.Redacted<string>, D>
20
- type Authentication<D extends ReadonlyArray<Plugin.Dependency>> =
21
+ /** Authentication configuration shared by TypeScript connection descriptions. */
22
+ export type Authentication<D extends ReadonlyArray<Plugin.Dependency>> =
21
23
  | { readonly name: string; readonly config?: unknown }
22
24
  | { readonly none: { readonly identity?: string } }
23
25
  | {
@@ -27,14 +29,15 @@ type Authentication<D extends ReadonlyArray<Plugin.Dependency>> =
27
29
  }
28
30
  | { readonly bearer: { readonly token: Token<D> } }
29
31
  | { readonly jwt: { readonly token: Token<D> } }
30
- type WithCredentials<C, D extends ReadonlyArray<Plugin.Dependency>> = C extends
31
- | { readonly local: object }
32
- | { readonly worker: object }
33
- | { readonly command: ReadonlyArray<string> }
34
- ? C
35
- : Omit<C, "auth"> & { readonly auth?: Authentication<D> }
36
32
  export type Connect<D extends ReadonlyArray<Plugin.Dependency> = readonly []> =
37
- WithCredentials<typeof Configuration.Connect.Encoded, D>
33
+ typeof Configuration.Connect.Encoded extends infer C
34
+ ? C extends
35
+ | { readonly local: object }
36
+ | { readonly worker: object }
37
+ | { readonly command: ReadonlyArray<string> }
38
+ ? C
39
+ : Omit<C, "auth"> & { readonly auth?: Authentication<D> }
40
+ : never
38
41
 
39
42
  const provider = <A, E, D extends ReadonlyArray<Plugin.Dependency>>(
40
43
  source: Source<A, D, E>,
@@ -12,7 +12,7 @@ import {
12
12
  } from "effect"
13
13
  import { ChildProcessSpawner } from "effect/process"
14
14
  import * as Contract from "../Contract"
15
- import { MissingInstance } from "../Errors"
15
+ import { MissingInstance, RemoteEntryError as EntryError } from "../Errors"
16
16
  import { LocalTransport, WorkerTransport } from "./directTransport"
17
17
  import * as Configuration from "./entryConfig"
18
18
  import * as Assembly from "./assembly"
@@ -25,19 +25,6 @@ import type { ExecutionOptions } from "./execution"
25
25
  import * as Importer from "./importer"
26
26
  import { SecureRandom } from "effect/crypto"
27
27
 
28
- export class EntryError extends Schema.TaggedError<
29
- EntryError,
30
- { readonly brand: unique symbol }
31
- >()("RemoteEntryError", {
32
- entry: Schema.Option(Schema.String),
33
- directory: Schema.Option(Schema.String),
34
- field: Schema.String,
35
- cause: Schema.Cause(Schema.Unknown, Schema.Unknown),
36
- }) {
37
- override get message() {
38
- return `Remote entry ${Option.getOrElse(this.entry, () => "<programmatic>")} failed at ${this.field}`
39
- }
40
- }
41
28
  export const boundary = Effect.fnUntraced(function* (field: string) {
42
29
  const entry = yield* Entry.CurrentId
43
30
  const directory = yield* ConfigDirectory
@@ -15,6 +15,7 @@ import * as Host from "./host"
15
15
  import { RemoteWithdrawn, RemoteError, MissingInstance } from "../Errors"
16
16
  import * as Contract from "../Contract"
17
17
  import * as Control from "./control"
18
+ import { prepare } from "./contract"
18
19
 
19
20
  export interface ExecutionOptions {
20
21
  readonly contractModule: string
@@ -65,6 +66,7 @@ export const executionPlugin = <
65
66
  config: Schema.toEncoded(contract.config),
66
67
  apply: (input) =>
67
68
  Effect.gen(function* () {
69
+ const prepared = prepare(contract)
68
70
  const random = yield* SecureRandom.SecureRandom
69
71
  const session = yield* random.uuidV4()
70
72
  const active = yield* Connection.acquire(
@@ -75,10 +77,10 @@ export const executionPlugin = <
75
77
  serve: Services.endpoints(contract.inject),
76
78
  call: {
77
79
  ...Services.endpoints(contract.provides),
78
- [Control.endpoint]: contract.control,
80
+ [Control.endpoint]: prepared.control,
79
81
  },
80
82
  },
81
- Host.initialize(contract),
83
+ Host.initialize(prepared),
82
84
  Host.dispose,
83
85
  options.shutdownTimeout ?? "5 seconds",
84
86
  )
@@ -16,15 +16,16 @@ import { RemoteWithdrawn } from "../Errors"
16
16
  import * as Control from "./control"
17
17
  import { cleanupCause } from "./cleanup"
18
18
  import { Connection } from "./runner/Connection"
19
- import type { Service } from "./services"
19
+ import type { Service } from "../Contract"
20
+ import type { ChildFailure } from "./childErrors"
21
+ import type { prepare } from "./contract"
20
22
 
21
23
  type ErrorSchema = Schema.Top & {
22
24
  readonly DecodingServices: never
23
25
  readonly EncodingServices: never
24
26
  }
25
- type ControlGroup<E extends ErrorSchema> = ContractModule.Contract<
26
- Schema.Codec<unknown, Schema.Json>,
27
- E
27
+ type ControlGroup<E extends ErrorSchema> = ReturnType<
28
+ typeof prepare<Schema.Codec<unknown, Schema.Json>, E>
28
29
  >["control"]
29
30
  interface Contract<E extends ErrorSchema> {
30
31
  readonly control: ControlGroup<E>
@@ -32,9 +33,7 @@ interface Contract<E extends ErrorSchema> {
32
33
  readonly decodeCause: (
33
34
  input: unknown,
34
35
  ) => Effect.Effect<
35
- Cause.Cause<
36
- E["Type"] | ContractModule.UndeclaredFailure | ContractModule.ChildFailure
37
- >,
36
+ Cause.Cause<E["Type"] | ContractModule.UndeclaredFailure | ChildFailure>,
38
37
  Schema.SchemaError
39
38
  >
40
39
  }
@@ -57,7 +56,7 @@ const forwardEvents = <E extends ErrorSchema>(
57
56
  const remoteFailure = yield* FailureGroup.make<
58
57
  | E["Type"]
59
58
  | ContractModule.UndeclaredFailure
60
- | ContractModule.ChildFailure
59
+ | ChildFailure
61
60
  | RemoteWithdrawn
62
61
  >()
63
62
  const events = yield* race(
@@ -179,9 +178,7 @@ export const load = <E extends ErrorSchema>(
179
178
  (
180
179
  cause,
181
180
  ): cause is Cause.Cause<
182
- | E["Type"]
183
- | ContractModule.UndeclaredFailure
184
- | ContractModule.ChildFailure
181
+ E["Type"] | ContractModule.UndeclaredFailure | ChildFailure
185
182
  > => Cause.isCause(cause),
186
183
  Effect.failCause,
187
184
  ),
@@ -1,27 +1,9 @@
1
1
  import { Array, Context, Effect, Record } from "effect"
2
2
  import { Graft } from "@graftland/graft"
3
3
  import { RpcClient, RpcServer } from "effect/rpc"
4
- import type { Scope } from "effect"
5
4
  import type { Rpc, RpcClientError, RpcGroup } from "effect/rpc"
6
- import type * as Port from "./port"
5
+ import type { Service } from "../Contract"
7
6
 
8
- type Peer = Port.Port
9
-
10
- /** RPC types stay inside the descriptor; Graft supplies its dynamic activation context. */
11
- export interface Service<R = never, ClientR = never> {
12
- readonly key: Context.Key<unknown, unknown>
13
- readonly group: Pick<RpcGroup.RpcGroup<Rpc.Any>, "requests">
14
- readonly serve: (
15
- port: Pick<Peer, "serverProtocol">,
16
- ) => Effect.Effect<never, never, R>
17
- readonly publish: (
18
- port: Pick<Peer, "clientProtocol">,
19
- ) => Effect.Effect<
20
- void,
21
- Graft.ServiceConflict,
22
- Graft.Graft | Scope.Scope | ClientR
23
- >
24
- }
25
7
  export const service = <
26
8
  I,
27
9
  S,
@@ -1,9 +0,0 @@
1
- import { c as TransportError } from "./Errors-oPsTLY7l.js";
2
- import { t as EndOfStream } from "./Framing-zaYdOJnT.js";
3
- import { t as Peer } from "./Peer-IJgFK6mD.js";
4
- import { Array, Cause, Effect, Schema } from "effect";
5
- import { Socket } from "effect/socket";
6
- // packages/remote/src/internal/runner/connectionEnded.ts
7
- const closedNormally = (cause) => cause.reasons.length > 0 && Array.every(cause.reasons, (reason) => reason._tag === "Fail" && (Schema.is(TransportError)(reason.error) ? closedNormally(reason.error.cause) : Schema.is(EndOfStream)(reason.error) || Socket.isSocketError(reason.error) && reason.error.reason._tag === "SocketCloseError" && reason.error.reason.code === 1e3));
8
- const connectionEnded = (cause) => Cause.hasInterruptsOnly(cause) || closedNormally(cause) ? Effect.void : Effect.flatMap(Peer, (identity) => Effect.logWarning("Remote host connection failed", cause).pipe(Effect.annotateLogs({ "remote.peer": identity })));
9
- export { connectionEnded as n, closedNormally as t };
@@ -1,33 +0,0 @@
1
- import { Schema } from "effect";
2
- declare const AlreadyLoaded_base: Schema.Class<AlreadyLoaded, Schema.TaggedStruct<"AlreadyLoaded", {}>, import("effect/Cause").YieldableError & {
3
- readonly brand: unique symbol;
4
- }>;
5
- export declare class AlreadyLoaded extends AlreadyLoaded_base {}
6
- declare const ContractNotFound_base: Schema.Class<ContractNotFound, Schema.TaggedStruct<"ContractNotFound", {
7
- readonly module: Schema.String;
8
- }>, import("effect/Cause").YieldableError & {
9
- readonly brand: unique symbol;
10
- }>;
11
- export declare class ContractNotFound extends ContractNotFound_base {
12
- get message(): string;
13
- }
14
- declare const ModuleImportFailed_base: Schema.Class<ModuleImportFailed, Schema.TaggedStruct<"ModuleImportFailed", {
15
- readonly module: Schema.String;
16
- readonly cause: Schema.Defect;
17
- }>, import("effect/Cause").YieldableError & {
18
- readonly brand: unique symbol;
19
- }>;
20
- export declare class ModuleImportFailed extends ModuleImportFailed_base {}
21
- declare const ActivationFailed_base: Schema.Class<ActivationFailed, Schema.TaggedStruct<"ActivationFailed", {
22
- readonly detail: Schema.String;
23
- readonly cause: Schema.optionalKey<Schema.Cause<Schema.Defect, Schema.Defect>>;
24
- }>, import("effect/Cause").YieldableError & {
25
- readonly brand: unique symbol;
26
- }>;
27
- export declare class ActivationFailed extends ActivationFailed_base {
28
- get message(): string;
29
- }
30
- export declare const ChildFailure: Schema.Union<readonly [typeof AlreadyLoaded, typeof ContractNotFound, typeof ModuleImportFailed, typeof ActivationFailed]>;
31
- export type ChildFailure = typeof ChildFailure.Type;
32
- export {};
33
- //# sourceMappingURL=childErrors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"childErrors.d.ts","names":[],"sources":["../../src/internal/childErrors.ts"],"mappings":";;WAImB;;qBAFN,sBAAsB;;;;WAMhB;;qBAFN,yBAAyB;MAIxB;;;;;;WAMK;;qBAFN,2BAA2B;;;;;WASrB;;qBAFN,yBAAyB;MAYxB;;qBAID,cAAY,OAAA,uBAAA,sBAAA,yBAAA,2BAAA;YAMb,sBAAsB,aAAa"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"port.d.ts","names":[],"sources":["../../src/internal/port.ts"],"mappings":";;;;;iBAgDiB;WACP,iBAAiB,qBAAqB,UAAU;WAChD,iBAAiB,qBAAqB,UAAU;WAChD,OAAO,OAAO,cAAc;WAC5B,OAAO,OAAO,mBAAmB,OAAO;WACxC,KAAK,OAAO,aAAa"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Framing.d.ts","names":[],"sources":["../../../src/internal/runner/Framing.ts"],"mappings":";;;;WAImB;;qBAFN,mBAAmB;MAIlB"}