@shivaedev/server 0.20.2 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +50 -5
- package/dist/AppHostFactory.d.ts +2 -2
- package/dist/AppHostFactory.d.ts.map +1 -1
- package/dist/UnixSocketRequest.d.ts +3 -0
- package/dist/UnixSocketRequest.d.ts.map +1 -0
- package/dist/UnixSocketRequest.js +3 -0
- package/dist/UnixSocketRequest.js.map +1 -0
- package/dist/adapters/hostHttpServices.d.ts +3 -0
- package/dist/adapters/hostHttpServices.d.ts.map +1 -0
- package/dist/adapters/hostHttpServices.js +6 -0
- package/dist/adapters/hostHttpServices.js.map +1 -0
- package/dist/adapters/nodeHttpServer.d.ts +3 -1
- package/dist/adapters/nodeHttpServer.d.ts.map +1 -1
- package/dist/adapters/nodeHttpServer.js +36 -7
- package/dist/adapters/nodeHttpServer.js.map +1 -1
- package/dist/adapters/socketState.d.ts +3 -0
- package/dist/adapters/socketState.d.ts.map +1 -0
- package/dist/adapters/socketState.js +24 -0
- package/dist/adapters/socketState.js.map +1 -0
- package/dist/adapters/unixHttpServer.d.ts +11 -0
- package/dist/adapters/unixHttpServer.d.ts.map +1 -0
- package/dist/adapters/unixHttpServer.js +56 -0
- package/dist/adapters/unixHttpServer.js.map +1 -0
- package/dist/appDatabase.js +1 -1
- package/dist/appDatabase.js.map +1 -1
- package/dist/appHost.d.ts +3 -6
- package/dist/appHost.d.ts.map +1 -1
- package/dist/appHost.js +2 -2
- package/dist/appHost.js.map +1 -1
- package/dist/appHostHttp.d.ts +345 -111
- package/dist/appHostHttp.d.ts.map +1 -1
- package/dist/appHostHttp.js +7 -7
- package/dist/appHostHttp.js.map +1 -1
- package/dist/hostOptions.d.ts +12 -2
- package/dist/hostOptions.d.ts.map +1 -1
- package/dist/hostRpc.d.ts +21 -1
- package/dist/hostRpc.d.ts.map +1 -1
- package/dist/hostRpc.js +2 -1
- package/dist/hostRpc.js.map +1 -1
- package/dist/hostRpcRoutes.d.ts +36 -7
- package/dist/hostRpcRoutes.d.ts.map +1 -1
- package/dist/hostRpcRoutes.js +11 -6
- package/dist/hostRpcRoutes.js.map +1 -1
- package/dist/hostSensitiveKeys.d.ts +12 -0
- package/dist/hostSensitiveKeys.d.ts.map +1 -0
- package/dist/hostSensitiveKeys.js +8 -0
- package/dist/hostSensitiveKeys.js.map +1 -0
- package/dist/hostTransport.d.ts +2 -0
- package/dist/hostTransport.d.ts.map +1 -1
- package/dist/hostTransport.js +2 -1
- package/dist/hostTransport.js.map +1 -1
- package/dist/hostVersionLayer.d.ts +2 -0
- package/dist/hostVersionLayer.d.ts.map +1 -0
- package/dist/hostVersionLayer.js +8 -0
- package/dist/hostVersionLayer.js.map +1 -0
- package/dist/socketRpc.d.ts.map +1 -1
- package/dist/socketRpc.js +2 -1
- package/dist/socketRpc.js.map +1 -1
- package/dist/testing/adapters/hostProcess.d.ts +1 -0
- package/dist/testing/adapters/hostProcess.d.ts.map +1 -1
- package/dist/testing/adapters/hostProcess.js +27 -0
- package/dist/testing/adapters/hostProcess.js.map +1 -1
- package/dist/testing/hostProcess.d.ts +4 -2
- package/dist/testing/hostProcess.d.ts.map +1 -1
- package/dist/testing/hostProcess.js +9 -2
- package/dist/testing/hostProcess.js.map +1 -1
- package/dist/testing/hostProcessChild.d.ts +1 -0
- package/dist/testing/hostProcessChild.d.ts.map +1 -1
- package/dist/testing/hostProcessChild.js +5 -1
- package/dist/testing/hostProcessChild.js.map +1 -1
- package/dist/testing/hostProcessProtocol.d.ts +3 -0
- package/dist/testing/hostProcessProtocol.d.ts.map +1 -1
- package/dist/testing/hostProcessProtocol.js +1 -0
- package/dist/testing/hostProcessProtocol.js.map +1 -1
- package/dist/testing/hostTime.d.ts +9 -0
- package/dist/testing/hostTime.d.ts.map +1 -0
- package/dist/testing/hostTime.js +27 -0
- package/dist/testing/hostTime.js.map +1 -0
- package/package.json +15 -15
- package/src/AppHostFactory.ts +8 -8
- package/src/UnixSocketRequest.ts +3 -0
- package/src/adapters/hostHttpServices.ts +10 -0
- package/src/adapters/nodeHttpServer.ts +40 -7
- package/src/adapters/socketState.ts +22 -0
- package/src/adapters/unixHttpServer.ts +74 -0
- package/src/appDatabase.ts +1 -1
- package/src/appHost.ts +21 -23
- package/src/appHostHttp.ts +7 -7
- package/src/hostOptions.ts +11 -6
- package/src/hostRpc.ts +6 -1
- package/src/hostRpcRoutes.ts +14 -5
- package/src/hostSensitiveKeys.ts +11 -0
- package/src/hostTransport.ts +9 -2
- package/src/hostVersionLayer.ts +8 -0
- package/src/socketRpc.ts +2 -1
- package/src/testing/adapters/hostProcess.ts +27 -0
- package/src/testing/hostProcess.ts +12 -3
- package/src/testing/hostProcessChild.ts +6 -1
- package/src/testing/hostProcessProtocol.ts +1 -0
- package/src/testing/hostTime.ts +33 -0
|
@@ -2,7 +2,7 @@ import { Effect, Redacted, Schema } from "effect";
|
|
|
2
2
|
import { forkHost, hostResponse, receiveHostMessage, stopHost } from "#testing/adapters/hostProcess.ts";
|
|
3
3
|
import { collectHostReadouts } from "#testing/adapters/hostProcessReadouts.ts";
|
|
4
4
|
import { HostProcessError } from "./HostProcessError.js";
|
|
5
|
-
import { HostReady, HostSignal } from "./hostProcessProtocol.js";
|
|
5
|
+
import { HostPrepared, HostReady, HostSignal } from "./hostProcessProtocol.js";
|
|
6
6
|
export const hostProcess = Effect.fn("HostProcess.hostProcess")(function* (options) {
|
|
7
7
|
const databaseUrl = options.databaseUrl;
|
|
8
8
|
const database = databaseUrl === undefined
|
|
@@ -10,9 +10,16 @@ export const hostProcess = Effect.fn("HostProcess.hostProcess")(function* (optio
|
|
|
10
10
|
: yield* Effect.promise(() => import("@shivaedev/test-sql/server/disconnectProxy.ts")).pipe(Effect.flatMap(({ disconnectProxy }) => disconnectProxy(Redacted.value(databaseUrl))));
|
|
11
11
|
const child = yield* Effect.acquireRelease(Effect.try({ catch: (cause) => new HostProcessError({ cause, operation: "launch" }), try: () => forkHost(options, database?.url) }), (acquired) => Effect.promise(() => stopHost(acquired)));
|
|
12
12
|
const read = collectHostReadouts(child);
|
|
13
|
+
if (options.beforeStart !== undefined) {
|
|
14
|
+
yield* Effect.tryPromise({
|
|
15
|
+
catch: (cause) => new HostProcessError({ cause, operation: "launch" }),
|
|
16
|
+
try: (signal) => receiveHostMessage(child, HostPrepared, signal),
|
|
17
|
+
});
|
|
18
|
+
yield* options.beforeStart;
|
|
19
|
+
}
|
|
13
20
|
const { pid, url } = yield* Effect.tryPromise({
|
|
14
21
|
catch: (cause) => new HostProcessError({ cause, operation: "launch" }),
|
|
15
|
-
try: (signal) => receiveHostMessage(child, HostReady, signal),
|
|
22
|
+
try: (signal) => receiveHostMessage(child, HostReady, signal, options.beforeStart === undefined ? undefined : () => child.kill("SIGUSR2")),
|
|
16
23
|
});
|
|
17
24
|
function response(path) {
|
|
18
25
|
return Effect.tryPromise({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcess.js","sourceRoot":"","sources":["../../src/testing/hostProcess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,QAAQ,EAA2B,YAAY,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACjI,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"hostProcess.js","sourceRoot":"","sources":["../../src/testing/hostProcess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,QAAQ,EAA2B,YAAY,EAAE,kBAAkB,EAAE,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EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;YACtE,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,CACf,kBAAkB,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE;gBAC3H,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACvB,CAAC,CAAC;SACH,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QACvB,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACjD,GAAG;KACH,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { HttpServer } from "effect/http";
|
|
3
3
|
import { HostProcessError } from "#testing/HostProcessError.ts";
|
|
4
|
+
export declare const awaitHostStart: Effect.Effect<void, HostProcessError, never>;
|
|
4
5
|
export declare const reportHostReady: Effect.Effect<void, HostProcessError, HttpServer.HttpServer>;
|
|
5
6
|
export declare function acknowledgeHostSignal(signal: NodeJS.Signals): Effect.Effect<void, HostProcessError, never>;
|
|
6
7
|
//# sourceMappingURL=hostProcessChild.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcessChild.d.ts","sourceRoot":"","sources":["../../src/testing/hostProcessChild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,eAAO,MAAM,eAAe,8DAO3B,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,gDAK3D"}
|
|
1
|
+
{"version":3,"file":"hostProcessChild.d.ts","sourceRoot":"","sources":["../../src/testing/hostProcessChild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,eAAO,MAAM,cAAc,8CAGzB,CAAC;AAEH,eAAO,MAAM,eAAe,8DAO3B,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,gDAK3D"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { HttpServer } from "effect/http";
|
|
3
|
-
import { sendHostMessage, sendHostReady } from "#testing/adapters/hostProcess.ts";
|
|
3
|
+
import { sendHostMessage, sendHostReady, waitForHostStart } from "#testing/adapters/hostProcess.ts";
|
|
4
4
|
import { HostProcessError } from "#testing/HostProcessError.ts";
|
|
5
|
+
export const awaitHostStart = Effect.tryPromise({
|
|
6
|
+
catch: (cause) => new HostProcessError({ cause, operation: "launch" }),
|
|
7
|
+
try: waitForHostStart,
|
|
8
|
+
});
|
|
5
9
|
export const reportHostReady = HttpServer.HttpServer.pipe(Effect.flatMap((server) => Effect.tryPromise({
|
|
6
10
|
catch: (cause) => new HostProcessError({ cause, operation: "launch" }),
|
|
7
11
|
try: () => sendHostReady(HttpServer.formatAddress(server.address)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcessChild.js","sourceRoot":"","sources":["../../src/testing/hostProcessChild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,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,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;KAC3D,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -4,6 +4,9 @@ export declare const HostReady: Schema.Struct<{
|
|
|
4
4
|
readonly type: Schema.Literal<"host-ready">;
|
|
5
5
|
readonly url: Schema.String;
|
|
6
6
|
}>;
|
|
7
|
+
export declare const HostPrepared: Schema.Struct<{
|
|
8
|
+
readonly type: Schema.Literal<"host-prepared">;
|
|
9
|
+
}>;
|
|
7
10
|
export declare const HostSignal: Schema.Struct<{
|
|
8
11
|
readonly signal: Schema.String;
|
|
9
12
|
readonly type: Schema.Literal<"host-signal">;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcessProtocol.d.ts","sourceRoot":"","sources":["../../src/testing/hostProcessProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,SAAS;;;;EAAgG,CAAC;AACvH,eAAO,MAAM,UAAU;;;EAAgF,CAAC;AACxG,eAAO,MAAM,YAAY;;;;;EAKvB,CAAC"}
|
|
1
|
+
{"version":3,"file":"hostProcessProtocol.d.ts","sourceRoot":"","sources":["../../src/testing/hostProcessProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,SAAS;;;;EAAgG,CAAC;AACvH,eAAO,MAAM,YAAY;;EAA2D,CAAC;AACrF,eAAO,MAAM,UAAU;;;EAAgF,CAAC;AACxG,eAAO,MAAM,YAAY;;;;;EAKvB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
export const HostReady = Schema.Struct({ pid: Schema.Number, type: Schema.Literal("host-ready"), url: Schema.String });
|
|
3
|
+
export const HostPrepared = Schema.Struct({ type: Schema.Literal("host-prepared") });
|
|
3
4
|
export const HostSignal = Schema.Struct({ signal: Schema.String, type: Schema.Literal("host-signal") });
|
|
4
5
|
export const HostReadouts = Schema.Struct({
|
|
5
6
|
activeWork: Schema.Array(Schema.String),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostProcessProtocol.js","sourceRoot":"","sources":["../../src/testing/hostProcessProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AACvH,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;AACxG,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;IACvC,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;IACvC,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;IAC9C,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC;CACrC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"hostProcessProtocol.js","sourceRoot":"","sources":["../../src/testing/hostProcessProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AACvH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;AACrF,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;AACxG,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;IACvC,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;IACvC,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;IAC9C,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC;CACrC,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Duration, Effect, Layer } from "effect";
|
|
2
|
+
import { WorkerReleaseTesting } from "@shivaedev/sql/testing/WorkerRelease.ts";
|
|
3
|
+
export declare const hostTime: () => Effect.Effect<{
|
|
4
|
+
layer: Layer.Layer<WorkerReleaseTesting, never, never>;
|
|
5
|
+
timePasses: (duration: Duration.Input, options?: {
|
|
6
|
+
readonly poll?: boolean;
|
|
7
|
+
}) => Effect.Effect<void, import("effect/Schema").SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
8
|
+
}, never, never>;
|
|
9
|
+
//# sourceMappingURL=hostTime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostTime.d.ts","sourceRoot":"","sources":["../../src/testing/hostTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAE/E,eAAO,MAAM,QAAQ;;2BAiBI,QAAQ,CAAC,KAAK,YAAY;QAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE;gBAW5E,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Effect, Layer } from "effect";
|
|
2
|
+
import { TestClock } from "effect/testing";
|
|
3
|
+
import { WorkerReleaseTesting } from "@shivaedev/sql/testing/WorkerRelease.ts";
|
|
4
|
+
export const hostTime = Effect.fn("HostTime.hostTime")(function* () {
|
|
5
|
+
const clock = yield* TestClock.testClockWith(Effect.succeed);
|
|
6
|
+
const ticks = new Set();
|
|
7
|
+
return {
|
|
8
|
+
layer: Layer.succeed(WorkerReleaseTesting, {
|
|
9
|
+
clock,
|
|
10
|
+
register: (tick) => Effect.acquireRelease(Effect.sync(() => {
|
|
11
|
+
ticks.add(tick);
|
|
12
|
+
}), () => Effect.sync(() => {
|
|
13
|
+
ticks.delete(tick);
|
|
14
|
+
})).pipe(Effect.asVoid),
|
|
15
|
+
}),
|
|
16
|
+
timePasses: (duration, options) => Effect.gen(function* () {
|
|
17
|
+
yield* clock.adjust(duration);
|
|
18
|
+
for (const tick of ticks) {
|
|
19
|
+
yield* tick.heartbeat;
|
|
20
|
+
if (options?.poll !== false) {
|
|
21
|
+
yield* tick.poll;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=hostTime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostTime.js","sourceRoot":"","sources":["../../src/testing/hostTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ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,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "The Effect application host: HTTP and RPC serving, health, OTLP export, database and migrations, and development mode",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -46,25 +46,25 @@
|
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@shivaedev/changes": "0.9.0",
|
|
49
|
-
"@shivaedev/contract": "0.
|
|
50
|
-
"@shivaedev/errors": "0.
|
|
49
|
+
"@shivaedev/contract": "0.35.0",
|
|
50
|
+
"@shivaedev/errors": "0.8.0",
|
|
51
51
|
"@shivaedev/http": "0.5.0",
|
|
52
|
-
"@shivaedev/identity": "0.
|
|
52
|
+
"@shivaedev/identity": "0.23.1",
|
|
53
53
|
"@shivaedev/local-postgres": "0.12.0",
|
|
54
|
-
"@shivaedev/sql": "0.
|
|
54
|
+
"@shivaedev/sql": "0.36.1"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@effect/platform-node": "4.0.6",
|
|
58
58
|
"@effect/sql-pg": "4.0.6",
|
|
59
59
|
"@effect/vitest": "4.0.6",
|
|
60
|
-
"@shivaedev/access": "0.4.
|
|
61
|
-
"@shivaedev/admin": "0.19.
|
|
62
|
-
"@shivaedev/jobs": "0.
|
|
63
|
-
"@shivaedev/quality": "0.
|
|
64
|
-
"@shivaedev/rate-limit": "0.3.
|
|
65
|
-
"@shivaedev/test-kits": "0.
|
|
66
|
-
"@shivaedev/test-sql": "0.
|
|
67
|
-
"@shivaedev/test-story": "0.
|
|
60
|
+
"@shivaedev/access": "0.4.2",
|
|
61
|
+
"@shivaedev/admin": "0.19.5",
|
|
62
|
+
"@shivaedev/jobs": "0.34.0",
|
|
63
|
+
"@shivaedev/quality": "0.59.0",
|
|
64
|
+
"@shivaedev/rate-limit": "0.3.3",
|
|
65
|
+
"@shivaedev/test-kits": "0.2.2",
|
|
66
|
+
"@shivaedev/test-sql": "0.19.0",
|
|
67
|
+
"@shivaedev/test-story": "0.37.1",
|
|
68
68
|
"@types/node": "24.19.2",
|
|
69
69
|
"better-auth": "1.7.14",
|
|
70
70
|
"effect": "4.0.6",
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"@effect/platform-node": "4.0.6",
|
|
77
77
|
"@effect/sql-pg": "4.0.6",
|
|
78
78
|
"@effect/vitest": "4.0.6",
|
|
79
|
-
"@shivaedev/admin": "0.19.
|
|
80
|
-
"@shivaedev/test-sql": "0.
|
|
79
|
+
"@shivaedev/admin": "0.19.5",
|
|
80
|
+
"@shivaedev/test-sql": "0.19.0",
|
|
81
81
|
"better-auth": "1.7.14",
|
|
82
82
|
"effect": "4.0.6"
|
|
83
83
|
},
|
package/src/AppHostFactory.ts
CHANGED
|
@@ -13,10 +13,10 @@ type PreflightHost<THost extends Layer.Any, TServices, TError, TRequirements> =
|
|
|
13
13
|
|
|
14
14
|
export interface AppHostFactory {
|
|
15
15
|
<
|
|
16
|
-
TRpcs extends Rpc.Any,
|
|
17
|
-
THandlers,
|
|
18
|
-
THandlerError,
|
|
19
|
-
THandlerRequirements,
|
|
16
|
+
TRpcs extends Rpc.Any = never,
|
|
17
|
+
THandlers = never,
|
|
18
|
+
THandlerError = never,
|
|
19
|
+
THandlerRequirements = never,
|
|
20
20
|
TServices = never,
|
|
21
21
|
TServiceError = never,
|
|
22
22
|
TServiceRequirements = never,
|
|
@@ -72,10 +72,10 @@ export interface AppHostFactory {
|
|
|
72
72
|
>;
|
|
73
73
|
|
|
74
74
|
<
|
|
75
|
-
TRpcs extends Rpc.Any,
|
|
76
|
-
THandlers,
|
|
77
|
-
THandlerError,
|
|
78
|
-
THandlerRequirements,
|
|
75
|
+
TRpcs extends Rpc.Any = never,
|
|
76
|
+
THandlers = never,
|
|
77
|
+
THandlerError = never,
|
|
78
|
+
THandlerRequirements = never,
|
|
79
79
|
TServices = never,
|
|
80
80
|
TServiceError = never,
|
|
81
81
|
TServiceRequirements = never,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
|
|
2
|
+
import { Effect, FileSystem, Layer, Option } from "effect";
|
|
3
|
+
|
|
4
|
+
export const hostHttpServices = Layer.unwrap(
|
|
5
|
+
Effect.map(Effect.serviceOption(FileSystem.FileSystem), (fileSystem) =>
|
|
6
|
+
Option.isSome(fileSystem)
|
|
7
|
+
? Layer.merge(NodeHttpServer.layerHttpServices, Layer.succeed(FileSystem.FileSystem, fileSystem.value))
|
|
8
|
+
: NodeHttpServer.layerHttpServices,
|
|
9
|
+
),
|
|
10
|
+
);
|
|
@@ -1,28 +1,61 @@
|
|
|
1
1
|
import { createServer } from "node:http";
|
|
2
2
|
import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
|
|
3
|
-
import { Config, type Duration, Effect, Layer } from "effect";
|
|
3
|
+
import { Config, type Duration, Effect, Layer, Scope } from "effect";
|
|
4
|
+
import { HttpServer } from "effect/http";
|
|
5
|
+
import { hostHttpServices } from "#adapters/hostHttpServices.ts";
|
|
6
|
+
import { unixHttpServer } from "#adapters/unixHttpServer.ts";
|
|
4
7
|
|
|
5
8
|
export function nodeHttpServer(
|
|
6
9
|
host: string,
|
|
7
10
|
config?: {
|
|
8
11
|
readonly port?: number;
|
|
12
|
+
readonly socketPath?: string;
|
|
9
13
|
readonly gracefulShutdownTimeout?: Duration.Input;
|
|
10
14
|
readonly disablePreemptiveShutdown?: boolean;
|
|
11
15
|
readonly maxBodySize?: number;
|
|
12
16
|
},
|
|
13
17
|
) {
|
|
14
|
-
return Layer.
|
|
18
|
+
return Layer.effect(
|
|
19
|
+
HttpServer.HttpServer,
|
|
15
20
|
Effect.gen(function* () {
|
|
16
|
-
const
|
|
17
|
-
|
|
21
|
+
const socketPath = config?.socketPath;
|
|
22
|
+
const options = {
|
|
18
23
|
gracefulShutdownTimeout: config?.gracefulShutdownTimeout,
|
|
19
|
-
host,
|
|
20
|
-
port,
|
|
21
24
|
websocket: config?.maxBodySize === undefined ? undefined : { maxPayload: socketPayloadLimit(config.maxBodySize) },
|
|
22
25
|
...(config?.disablePreemptiveShutdown === undefined ? {} : { disablePreemptiveShutdown: config.disablePreemptiveShutdown }),
|
|
26
|
+
};
|
|
27
|
+
if (socketPath === undefined) {
|
|
28
|
+
const port = config?.port ?? (yield* Config.Int("PORT").pipe(Config.withDefault(3000)));
|
|
29
|
+
return yield* NodeHttpServer.make(createServer, { ...options, host, port });
|
|
30
|
+
}
|
|
31
|
+
const listeners = yield* Scope.fork(yield* Scope.Scope, "parallel");
|
|
32
|
+
const socketScope = yield* Scope.fork(listeners, "sequential");
|
|
33
|
+
const unix = yield* unixHttpServer(socketPath, options).pipe(Scope.provide(socketScope));
|
|
34
|
+
// Socket preparation emits filesystem events; keep TCP closed until it finishes.
|
|
35
|
+
const tcpScope = yield* Scope.fork(listeners, "sequential");
|
|
36
|
+
const tcp =
|
|
37
|
+
config?.port === undefined
|
|
38
|
+
? undefined
|
|
39
|
+
: yield* NodeHttpServer.make(createServer, {
|
|
40
|
+
...options,
|
|
41
|
+
host,
|
|
42
|
+
port: config.port,
|
|
43
|
+
}).pipe(Scope.provide(tcpScope));
|
|
44
|
+
return HttpServer.make({
|
|
45
|
+
address: tcp?.address ?? unix.address,
|
|
46
|
+
serve: (handler, middleware) =>
|
|
47
|
+
Effect.gen(function* () {
|
|
48
|
+
const servingListeners = yield* Scope.fork(yield* Scope.Scope, "parallel");
|
|
49
|
+
const unixServing = yield* Scope.fork(servingListeners, "sequential");
|
|
50
|
+
yield* (middleware === undefined ? unix.serve(handler) : unix.serve(handler, middleware)).pipe(Scope.provide(unixServing));
|
|
51
|
+
if (tcp !== undefined) {
|
|
52
|
+
const serving = yield* Scope.fork(servingListeners, "sequential");
|
|
53
|
+
yield* (middleware === undefined ? tcp.serve(handler) : tcp.serve(handler, middleware)).pipe(Scope.provide(serving));
|
|
54
|
+
}
|
|
55
|
+
}),
|
|
23
56
|
});
|
|
24
57
|
}),
|
|
25
|
-
);
|
|
58
|
+
).pipe(Layer.provideMerge(hostHttpServices));
|
|
26
59
|
}
|
|
27
60
|
|
|
28
61
|
function socketPayloadLimit(bytes: number) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createConnection } from "node:net";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
|
|
4
|
+
export function socketState(path: string) {
|
|
5
|
+
return Effect.callback<"live" | "missing" | "stale", Error>((resume) => {
|
|
6
|
+
const socket = createConnection(path);
|
|
7
|
+
socket.once("connect", () => {
|
|
8
|
+
socket.destroy();
|
|
9
|
+
resume(Effect.succeed("live"));
|
|
10
|
+
});
|
|
11
|
+
socket.once("error", (cause: NodeJS.ErrnoException) => {
|
|
12
|
+
if (cause.code === "ENOENT") {
|
|
13
|
+
resume(Effect.succeed("missing"));
|
|
14
|
+
} else if (cause.code === "ECONNREFUSED") {
|
|
15
|
+
resume(Effect.succeed("stale"));
|
|
16
|
+
} else {
|
|
17
|
+
resume(Effect.fail(cause));
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return Effect.sync(() => socket.destroy());
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
|
|
3
|
+
import { Duration, Effect, FileSystem, Path, Scope } from "effect";
|
|
4
|
+
import { HttpServer } from "effect/http";
|
|
5
|
+
import * as NetAddress from "effect/net/NetAddress";
|
|
6
|
+
import { socketState } from "#adapters/socketState.ts";
|
|
7
|
+
import { UnixSocketRequest } from "#UnixSocketRequest.ts";
|
|
8
|
+
|
|
9
|
+
export const unixHttpServer = Effect.fn("Server.unixHttpServer")(function* (path: string, options: NodeHttpServer.Options) {
|
|
10
|
+
const fs = yield* FileSystem.FileSystem;
|
|
11
|
+
const paths = yield* Path.Path;
|
|
12
|
+
const root = paths.dirname(path);
|
|
13
|
+
const scope = yield* Scope.Scope;
|
|
14
|
+
function occupied() {
|
|
15
|
+
return new Error(`A listener is already running at ${path}. Stop it before starting another.`);
|
|
16
|
+
}
|
|
17
|
+
return yield* Effect.scoped(
|
|
18
|
+
Effect.gen(function* () {
|
|
19
|
+
const lock = paths.join(root, `.${paths.basename(path)}.starting`);
|
|
20
|
+
yield* Effect.acquireRelease(
|
|
21
|
+
fs.makeDirectory(lock, { mode: 0o700 }).pipe(
|
|
22
|
+
Effect.catchIf(
|
|
23
|
+
(error) => error.reason._tag === "AlreadyExists",
|
|
24
|
+
() =>
|
|
25
|
+
Effect.fail(new Error(`${occupied().message} A startup lock exists at ${lock}; remove it only if its startup was forcibly killed.`)),
|
|
26
|
+
),
|
|
27
|
+
),
|
|
28
|
+
() => fs.remove(lock, { recursive: true }).pipe(Effect.orDie),
|
|
29
|
+
);
|
|
30
|
+
const state = yield* socketState(path);
|
|
31
|
+
if (state === "live") {
|
|
32
|
+
return yield* Effect.fail(occupied());
|
|
33
|
+
}
|
|
34
|
+
if (state === "stale") {
|
|
35
|
+
if ((yield* fs.stat(path)).type !== "Socket") {
|
|
36
|
+
return yield* Effect.fail(new Error(`The Unix socket path is not a socket: ${path}`));
|
|
37
|
+
}
|
|
38
|
+
yield* fs.remove(path, { force: true });
|
|
39
|
+
}
|
|
40
|
+
// Short private names preserve owner-only access within the public pathname budget.
|
|
41
|
+
const staging = yield* fs.makeTempDirectoryScoped({ directory: root, prefix: ".s" });
|
|
42
|
+
const pending = paths.join(staging, "s");
|
|
43
|
+
const node = createServer();
|
|
44
|
+
const server = yield* NodeHttpServer.make(() => node, {
|
|
45
|
+
...options,
|
|
46
|
+
path: pending,
|
|
47
|
+
}).pipe(Scope.provide(scope));
|
|
48
|
+
yield* fs.chmod(pending, 0o600);
|
|
49
|
+
// Unpublish before Node closes its private bind path.
|
|
50
|
+
yield* Effect.acquireRelease(fs.rename(pending, path), () => fs.remove(path, { force: true }).pipe(Effect.orDie)).pipe(Scope.provide(scope));
|
|
51
|
+
return withUnixRequests({ ...server, address: NetAddress.unixPathAddress(path) }, node, options);
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
function withUnixRequests(server: HttpServer.HttpServer["Service"], node: ReturnType<typeof createServer>, options: NodeHttpServer.Options) {
|
|
57
|
+
return HttpServer.make({
|
|
58
|
+
address: server.address,
|
|
59
|
+
serve: (handler, middleware) =>
|
|
60
|
+
Effect.gen(function* () {
|
|
61
|
+
const unix = handler.pipe(Effect.provideService(UnixSocketRequest, true));
|
|
62
|
+
yield* middleware === undefined ? server.serve(unix) : server.serve(unix, middleware);
|
|
63
|
+
yield* Effect.addFinalizer(() =>
|
|
64
|
+
Effect.sync(() => {
|
|
65
|
+
const deadline = setTimeout(
|
|
66
|
+
() => node.closeAllConnections(),
|
|
67
|
+
Duration.toMillis(Duration.fromInputUnsafe(options.gracefulShutdownTimeout ?? "20 seconds")),
|
|
68
|
+
);
|
|
69
|
+
node.once("close", () => clearTimeout(deadline));
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
72
|
+
}),
|
|
73
|
+
});
|
|
74
|
+
}
|
package/src/appDatabase.ts
CHANGED
|
@@ -36,7 +36,7 @@ export function appDatabase<R, E = never>(options: AppDatabaseOptions<R, E>) {
|
|
|
36
36
|
const migrations = options.migrations;
|
|
37
37
|
const worker =
|
|
38
38
|
migrations.mode === "wait" && migrations.release !== undefined
|
|
39
|
-
? Layer.effect(WorkerRelease, coordinateWorkerRelease(migrations.release, migrations.pollInterval, migrations.table))
|
|
39
|
+
? Layer.effect(WorkerRelease, coordinateWorkerRelease(migrations.release, migrations.pollInterval, migrations.table)).pipe(Layer.provide(clock))
|
|
40
40
|
: Layer.empty;
|
|
41
41
|
const base = Layer.merge(pool, live);
|
|
42
42
|
const changes = options.config?.changes;
|
package/src/appHost.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
|
|
2
2
|
import { Effect, Layer } from "effect";
|
|
3
3
|
import type { Rpc } from "effect/rpc";
|
|
4
|
-
import { schemaSensitiveKeys } from "@shivaedev/errors/schemaSensitiveKeys.ts";
|
|
5
4
|
import { isSensitiveKey } from "@shivaedev/errors/sensitive.ts";
|
|
6
|
-
import type { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
|
|
7
5
|
import type { AppHostFactory } from "#AppHostFactory.ts";
|
|
8
6
|
import type { AppHostInput, HostPreflight } from "#AppHostInput.ts";
|
|
9
7
|
import { appDatabase, type DatabaseConfig } from "#appDatabase.ts";
|
|
10
8
|
import { appHostHttp, deferredHost, migratedHost } from "#appHostHttp.ts";
|
|
11
9
|
import type { HostCoreOptions, HostPolicy, HostRouteRequirements, HostRoutes } from "#hostOptions.ts";
|
|
10
|
+
import { hostSensitiveKeys } from "#hostSensitiveKeys.ts";
|
|
12
11
|
import type { MigrationOptions } from "#MigrationOptions.ts";
|
|
13
12
|
import { redactingDiagnostics } from "#redactingDiagnostics.ts";
|
|
14
13
|
|
|
@@ -18,10 +17,10 @@ export interface AppDatabaseOptions<R = never, E = never> {
|
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
export type AppHostOptions<
|
|
21
|
-
TRpcs extends Rpc.Any,
|
|
22
|
-
THandlers,
|
|
23
|
-
THandlerError,
|
|
24
|
-
THandlerRequirements,
|
|
20
|
+
TRpcs extends Rpc.Any = never,
|
|
21
|
+
THandlers = never,
|
|
22
|
+
THandlerError = never,
|
|
23
|
+
THandlerRequirements = never,
|
|
25
24
|
TServices = never,
|
|
26
25
|
TServiceError = never,
|
|
27
26
|
TServiceRequirements = never,
|
|
@@ -34,17 +33,17 @@ export type AppHostOptions<
|
|
|
34
33
|
TMigrationError = never,
|
|
35
34
|
> = HostPreflight<TPreflight, TPreflightError, TPreflightRequirements> &
|
|
36
35
|
HostCoreOptions<TRpcs, THandlers, THandlerError, THandlerRequirements, TServices, TServiceError, TServiceRequirements> &
|
|
37
|
-
HostRoutes<TRouteError, TRouteRequirements> &
|
|
36
|
+
HostRoutes<TRouteError, TRouteRequirements> &
|
|
37
|
+
HostPolicy & {
|
|
38
38
|
readonly migrations: AppDatabaseOptions<TMigrations, TMigrationError>["migrations"];
|
|
39
39
|
readonly policy?: undefined;
|
|
40
|
-
readonly sessions: Layer.Layer<SessionPolicy>;
|
|
41
40
|
};
|
|
42
41
|
|
|
43
42
|
export type AppLocalHostOptions<
|
|
44
|
-
TRpcs extends Rpc.Any,
|
|
45
|
-
THandlers,
|
|
46
|
-
THandlerError,
|
|
47
|
-
THandlerRequirements,
|
|
43
|
+
TRpcs extends Rpc.Any = never,
|
|
44
|
+
THandlers = never,
|
|
45
|
+
THandlerError = never,
|
|
46
|
+
THandlerRequirements = never,
|
|
48
47
|
TServices = never,
|
|
49
48
|
TServiceError = never,
|
|
50
49
|
TServiceRequirements = never,
|
|
@@ -64,10 +63,10 @@ export type AppLocalHostOptions<
|
|
|
64
63
|
};
|
|
65
64
|
|
|
66
65
|
export type AppHttpHostOptions<
|
|
67
|
-
TRpcs extends Rpc.Any,
|
|
68
|
-
THandlers,
|
|
69
|
-
THandlerError,
|
|
70
|
-
THandlerRequirements,
|
|
66
|
+
TRpcs extends Rpc.Any = never,
|
|
67
|
+
THandlers = never,
|
|
68
|
+
THandlerError = never,
|
|
69
|
+
THandlerRequirements = never,
|
|
71
70
|
TServices = never,
|
|
72
71
|
TServiceError = never,
|
|
73
72
|
TServiceRequirements = never,
|
|
@@ -81,10 +80,10 @@ export type AppHttpHostOptions<
|
|
|
81
80
|
HostRoutes<TRouteError, TRouteRequirements> &
|
|
82
81
|
HostPolicy & { readonly migrations?: undefined };
|
|
83
82
|
export const appHost: AppHostFactory = <
|
|
84
|
-
TRpcs extends Rpc.Any,
|
|
85
|
-
THandlers,
|
|
86
|
-
THandlerError,
|
|
87
|
-
THandlerRequirements,
|
|
83
|
+
TRpcs extends Rpc.Any = never,
|
|
84
|
+
THandlers = never,
|
|
85
|
+
THandlerError = never,
|
|
86
|
+
THandlerRequirements = never,
|
|
88
87
|
TServices = never,
|
|
89
88
|
TServiceError = never,
|
|
90
89
|
TServiceRequirements = never,
|
|
@@ -122,9 +121,8 @@ export const appHost: AppHostFactory = <
|
|
|
122
121
|
startup === undefined
|
|
123
122
|
? Layer.empty
|
|
124
123
|
: Layer.unwrap(
|
|
125
|
-
Effect.map(
|
|
126
|
-
|
|
127
|
-
(sensitive) => startup.pipe(Layer.provide(redactingDiagnostics(sensitive))),
|
|
124
|
+
Effect.map("application" in options ? Effect.succeed(isSensitiveKey) : hostSensitiveKeys(options), (sensitive) =>
|
|
125
|
+
startup.pipe(Layer.provide(redactingDiagnostics(sensitive))),
|
|
128
126
|
),
|
|
129
127
|
);
|
|
130
128
|
if ("application" in options) {
|
package/src/appHostHttp.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
|
|
2
1
|
import { Effect, Layer } from "effect";
|
|
3
2
|
import { HttpRouter, HttpServer } from "effect/http";
|
|
4
3
|
import type { Rpc } from "effect/rpc";
|
|
5
|
-
import {
|
|
4
|
+
import { hostHttpServices } from "#adapters/hostHttpServices.ts";
|
|
6
5
|
import { nodeHttpServer } from "#adapters/nodeHttpServer.ts";
|
|
7
6
|
import type { appDatabase } from "#appDatabase.ts";
|
|
8
7
|
import type { AppHttpHostOptions } from "#appHost.ts";
|
|
@@ -12,6 +11,7 @@ import { hostApplicationRoutes } from "#hostApplicationRoutes.ts";
|
|
|
12
11
|
import { hostAssets } from "#hostAssets.ts";
|
|
13
12
|
import type { HostOptions, HostPolicy, HostRouteRequirements } from "#hostOptions.ts";
|
|
14
13
|
import { hostRpcRoutes } from "#hostRpcRoutes.ts";
|
|
14
|
+
import { hostSensitiveKeys } from "#hostSensitiveKeys.ts";
|
|
15
15
|
import { hostTransport } from "#hostTransport.ts";
|
|
16
16
|
import type { MigrationOptions } from "#MigrationOptions.ts";
|
|
17
17
|
import { nativeClientOrigins } from "#nativeClientOrigins.ts";
|
|
@@ -43,14 +43,14 @@ export function appHostHttp<
|
|
|
43
43
|
> &
|
|
44
44
|
HostPolicy,
|
|
45
45
|
) {
|
|
46
|
+
const assets = options.assets === undefined ? Layer.empty : hostAssets(options.assets);
|
|
46
47
|
return Layer.unwrap(
|
|
47
|
-
Effect.map(
|
|
48
|
+
Effect.map(hostSensitiveKeys(options), (sensitive) =>
|
|
48
49
|
Layer.unwrap(
|
|
49
50
|
Effect.gen(function* () {
|
|
50
51
|
const transport = yield* hostTransport(options);
|
|
51
52
|
const { bodySize, host, trustedProxy, nativeOrigins } = transport;
|
|
52
|
-
const routes = hostRpcRoutes(options, transport, sensitive);
|
|
53
|
-
const assets = options.assets === undefined ? Layer.empty : hostAssets(options.assets);
|
|
53
|
+
const routes = options.group === undefined ? Layer.empty : hostRpcRoutes(options, transport, sensitive);
|
|
54
54
|
const application = Layer.mergeAll(options.services ?? Layer.empty);
|
|
55
55
|
const sessions = Layer.mergeAll(Layer.empty, ...(options.sessions === undefined ? [] : [options.sessions]));
|
|
56
56
|
const server = nodeHttpServer(host, { ...options.config, maxBodySize: bodySize });
|
|
@@ -62,14 +62,14 @@ export function appHostHttp<
|
|
|
62
62
|
assets,
|
|
63
63
|
applicationRoutes,
|
|
64
64
|
).pipe(
|
|
65
|
-
Layer.provide(nativeClientOrigins(nativeOrigins, trustedProxy, false, options.rpcPath)),
|
|
65
|
+
Layer.provide(options.group === undefined ? Layer.empty : nativeClientOrigins(nativeOrigins, trustedProxy, false, options.rpcPath)),
|
|
66
66
|
Layer.provide(nativeClientOrigins(nativeOrigins, trustedProxy, options.nativeOrigins === undefined ? "preflight" : true)),
|
|
67
67
|
);
|
|
68
68
|
return Layer.unwrap(
|
|
69
69
|
HttpRouter.toHttpEffect(httpRoutes).pipe(
|
|
70
70
|
Effect.map((handler) => HttpServer.serve(handler).pipe(HttpServer.withLogAddress, Layer.provideMerge(server))),
|
|
71
71
|
),
|
|
72
|
-
).pipe(Layer.provideMerge(application), Layer.provide(sessions), Layer.provideMerge(
|
|
72
|
+
).pipe(Layer.provideMerge(application), Layer.provide(sessions), Layer.provideMerge(hostHttpServices));
|
|
73
73
|
}),
|
|
74
74
|
).pipe(Layer.provide(redactingDiagnostics(sensitive)), Layer.provide(otlpTracing), Layer.provide(Layer.succeed(RedactionPolicy, sensitive))),
|
|
75
75
|
),
|
package/src/hostOptions.ts
CHANGED
|
@@ -12,7 +12,9 @@ export type HostCoreOptions<TRpcs extends Rpc.Any, THandlers, THandlerError, THa
|
|
|
12
12
|
readonly assets?: string | AssetOptions;
|
|
13
13
|
readonly browserErrors?: BrowserErrorOptions;
|
|
14
14
|
readonly config?: AppDatabaseOptions["config"] & {
|
|
15
|
+
readonly buildVersion?: string;
|
|
15
16
|
readonly port?: number;
|
|
17
|
+
readonly socketPath?: string;
|
|
16
18
|
readonly host?: string;
|
|
17
19
|
readonly trustedProxy?: string;
|
|
18
20
|
readonly maxBodySize?: number;
|
|
@@ -20,14 +22,16 @@ export type HostCoreOptions<TRpcs extends Rpc.Any, THandlers, THandlerError, THa
|
|
|
20
22
|
readonly disablePreemptiveShutdown?: boolean;
|
|
21
23
|
readonly gracefulShutdownTimeout?: Duration.Input;
|
|
22
24
|
};
|
|
23
|
-
readonly group: RpcGroup.RpcGroup<TRpcs>;
|
|
24
|
-
readonly handlers: Layer.Layer<THandlers, THandlerError, THandlerRequirements>;
|
|
25
25
|
readonly nativeOrigins?: readonly string[];
|
|
26
26
|
readonly rpcPath?: HttpRouter.PathInput;
|
|
27
27
|
} & (
|
|
28
|
-
| { readonly
|
|
29
|
-
|
|
|
30
|
-
)
|
|
28
|
+
| { readonly group: RpcGroup.RpcGroup<TRpcs>; readonly handlers: Layer.Layer<THandlers, THandlerError, THandlerRequirements> }
|
|
29
|
+
| { readonly group?: never; readonly handlers?: never }
|
|
30
|
+
) &
|
|
31
|
+
(
|
|
32
|
+
| { readonly services: Layer.Layer<TServices, TServiceError, TServiceRequirements> }
|
|
33
|
+
| ([TServices | TServiceError | TServiceRequirements] extends [never] ? { readonly services?: never } : never)
|
|
34
|
+
);
|
|
31
35
|
|
|
32
36
|
export interface HostRoutes<TRouteError = never, TRouteRequirements = HostRouteRequirements> {
|
|
33
37
|
readonly routes?: Layer.Layer<never, TRouteError, TRouteRequirements>;
|
|
@@ -48,4 +52,5 @@ export type HostOptions<
|
|
|
48
52
|
|
|
49
53
|
export type HostPolicy =
|
|
50
54
|
| { readonly policy?: undefined; readonly sessions: Layer.Layer<SessionPolicy> }
|
|
51
|
-
| { readonly policy: "loopback"; readonly sessions?: never }
|
|
55
|
+
| { readonly policy: "loopback"; readonly sessions?: never }
|
|
56
|
+
| { readonly group?: never; readonly policy?: undefined; readonly sessions?: never };
|