@shivaedev/server 0.36.0 → 0.37.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 +20 -0
- package/README.md +24 -12
- package/dist/AppModule.d.ts +3 -2
- package/dist/AppModule.d.ts.map +1 -1
- package/dist/adapters/migrationsIn.d.ts +5 -0
- package/dist/adapters/migrationsIn.d.ts.map +1 -0
- package/dist/adapters/migrationsIn.js +10 -0
- package/dist/adapters/migrationsIn.js.map +1 -0
- package/dist/appDatabaseHttp.d.ts +10 -2
- package/dist/appDatabaseHttp.d.ts.map +1 -1
- package/dist/appHost.d.ts +5 -1
- package/dist/appHost.d.ts.map +1 -1
- package/dist/appHostHttp.d.ts +5 -1
- package/dist/appHostHttp.d.ts.map +1 -1
- package/dist/appHostHttp.js +3 -7
- package/dist/appHostHttp.js.map +1 -1
- package/dist/appModules.d.ts +4 -3
- package/dist/appModules.d.ts.map +1 -1
- package/dist/appModules.js +7 -4
- package/dist/appModules.js.map +1 -1
- package/dist/hostRpc.d.ts +5 -1
- package/dist/hostRpc.d.ts.map +1 -1
- package/dist/hostRpcRoutes.d.ts +5 -1
- package/dist/hostRpcRoutes.d.ts.map +1 -1
- package/dist/redactedHost.d.ts +11 -0
- package/dist/redactedHost.d.ts.map +1 -0
- package/dist/redactedHost.js +11 -0
- package/dist/redactedHost.js.map +1 -0
- package/dist/workerHost.d.ts +6 -2
- package/dist/workerHost.d.ts.map +1 -1
- package/dist/workerHost.js +5 -2
- package/dist/workerHost.js.map +1 -1
- package/package.json +29 -29
- package/src/AppModule.ts +4 -3
- package/src/adapters/migrationsIn.ts +12 -0
- package/src/appHostHttp.ts +29 -40
- package/src/appModules.ts +14 -7
- package/src/redactedHost.ts +26 -0
- package/src/workerHost.ts +17 -3
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Effect, Layer } from "effect";
|
|
2
|
+
import type { Rpc, RpcGroup } from "effect/rpc";
|
|
3
|
+
import { RepositoryModels } from "@shivaedev/sql/RepositoryModels.ts";
|
|
4
|
+
import { redactingDiagnostics } from "#adapters/redactingDiagnostics.ts";
|
|
5
|
+
import { hostSensitiveKeys } from "#hostSensitiveKeys.ts";
|
|
6
|
+
import { otlpTracing } from "#otlpTracing.ts";
|
|
7
|
+
import { RedactionPolicy } from "#RedactionPolicy.ts";
|
|
8
|
+
|
|
9
|
+
export type HostSensitivePolicy = Effect.Success<ReturnType<typeof hostSensitiveKeys>>;
|
|
10
|
+
|
|
11
|
+
// Both hosts build their process inside one policy, so repositories declare their models to the same policy that masks every log, error report and exported span.
|
|
12
|
+
export function redactedHost<TRpcs extends Rpc.Any, A, E, R>(
|
|
13
|
+
options: { readonly group?: RpcGroup.RpcGroup<TRpcs>; readonly config?: { readonly sensitiveKeys?: readonly string[] } },
|
|
14
|
+
host: (sensitive: HostSensitivePolicy) => Layer.Layer<A, E, R>,
|
|
15
|
+
) {
|
|
16
|
+
return Layer.unwrap(
|
|
17
|
+
Effect.map(hostSensitiveKeys(options), (sensitive) =>
|
|
18
|
+
host(sensitive).pipe(
|
|
19
|
+
Layer.provide(redactingDiagnostics(sensitive)),
|
|
20
|
+
Layer.provide(otlpTracing),
|
|
21
|
+
Layer.provide(Layer.succeed(RedactionPolicy, sensitive)),
|
|
22
|
+
Layer.provide(Layer.succeed(RepositoryModels, sensitive.models)),
|
|
23
|
+
),
|
|
24
|
+
),
|
|
25
|
+
);
|
|
26
|
+
}
|
package/src/workerHost.ts
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
|
|
2
|
-
import { Layer } from "effect";
|
|
3
|
-
import { type AppDatabaseOptions, appDatabase } from "#appDatabase.ts";
|
|
2
|
+
import { Effect, Layer } from "effect";
|
|
3
|
+
import { type AppDatabaseOptions, appDatabase, type DatabaseConfig } from "#appDatabase.ts";
|
|
4
|
+
import { redactedHost } from "#redactedHost.ts";
|
|
5
|
+
|
|
6
|
+
export interface WorkerHostConfig extends DatabaseConfig {
|
|
7
|
+
readonly sensitiveKeys?: readonly string[];
|
|
8
|
+
}
|
|
4
9
|
|
|
5
10
|
export function workerHost<R, E, TRequirements, TServices, TServiceError, TServiceRequirements, TMigrations = never, TMigrationError = never>(
|
|
6
11
|
options: AppDatabaseOptions<TMigrations, TMigrationError> & {
|
|
12
|
+
readonly config?: WorkerHostConfig;
|
|
7
13
|
readonly workers: Layer.Layer<R, E, TRequirements>;
|
|
8
14
|
readonly services: Layer.Layer<TServices, TServiceError, TServiceRequirements>;
|
|
9
15
|
},
|
|
10
16
|
) {
|
|
11
|
-
|
|
17
|
+
// A worker serves no RPC group, so its policy holds the built-in rules, config.sensitiveKeys and the models its repositories declare as they are built.
|
|
18
|
+
// The host announces readiness itself: an effect composed around the returned Layer runs outside its policy and exporter.
|
|
19
|
+
return redactedHost(options, () =>
|
|
20
|
+
Layer.effectDiscard(Effect.logInfo("Worker ready to take jobs")).pipe(
|
|
21
|
+
Layer.provideMerge(options.workers),
|
|
22
|
+
Layer.provideMerge(options.services),
|
|
23
|
+
Layer.provideMerge(appDatabase(options)),
|
|
24
|
+
),
|
|
25
|
+
).pipe(Layer.provide(NodeCrypto.layer));
|
|
12
26
|
}
|