@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
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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>,
|
package/src/internal/entry.ts
CHANGED
|
@@ -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]:
|
|
80
|
+
[Control.endpoint]: prepared.control,
|
|
79
81
|
},
|
|
80
82
|
},
|
|
81
|
-
Host.initialize(
|
|
83
|
+
Host.initialize(prepared),
|
|
82
84
|
Host.dispose,
|
|
83
85
|
options.shutdownTimeout ?? "5 seconds",
|
|
84
86
|
)
|
package/src/internal/host.ts
CHANGED
|
@@ -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 "
|
|
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> =
|
|
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
|
-
|
|
|
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
|
-
|
|
183
|
-
| ContractModule.UndeclaredFailure
|
|
184
|
-
| ContractModule.ChildFailure
|
|
181
|
+
E["Type"] | ContractModule.UndeclaredFailure | ChildFailure
|
|
185
182
|
> => Cause.isCause(cause),
|
|
186
183
|
Effect.failCause,
|
|
187
184
|
),
|
package/src/internal/services.ts
CHANGED
|
@@ -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
|
|
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"}
|