@relkit/app 0.5.0 → 0.5.3
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/app-config.types.d.ts +32 -0
- package/dist/app-config.types.d.ts.map +1 -0
- package/dist/app-config.types.js +2 -0
- package/dist/app-config.types.js.map +1 -0
- package/dist/app-observability.d.ts +21 -0
- package/dist/app-observability.d.ts.map +1 -0
- package/dist/app-observability.js +41 -0
- package/dist/app-observability.js.map +1 -0
- package/dist/app-observability.types.d.ts +18 -0
- package/dist/app-observability.types.d.ts.map +1 -0
- package/dist/app-observability.types.js +2 -0
- package/dist/app-observability.types.js.map +1 -0
- package/dist/app-provider-capabilities.d.ts +3 -0
- package/dist/app-provider-capabilities.d.ts.map +1 -0
- package/dist/{define-app-types.js → app-provider-capabilities.js} +2 -1
- package/dist/app-provider-capabilities.js.map +1 -0
- package/dist/app-provider-normalization.d.ts +32 -0
- package/dist/app-provider-normalization.d.ts.map +1 -0
- package/dist/app-provider-normalization.js +58 -0
- package/dist/app-provider-normalization.js.map +1 -0
- package/dist/{define-app-types.d.ts → app-provider.types.d.ts} +19 -50
- package/dist/app-provider.types.d.ts.map +1 -0
- package/dist/app-provider.types.js +2 -0
- package/dist/app-provider.types.js.map +1 -0
- package/dist/app-validation.d.ts +67 -1
- package/dist/app-validation.d.ts.map +1 -1
- package/dist/app-validation.js +100 -13
- package/dist/app-validation.js.map +1 -1
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -1
- package/dist/config.js.map +1 -1
- package/dist/context-descriptors.d.ts +39 -26
- package/dist/context-descriptors.d.ts.map +1 -1
- package/dist/context-descriptors.js +105 -27
- package/dist/context-descriptors.js.map +1 -1
- package/dist/context-descriptors.types.d.ts +58 -0
- package/dist/context-descriptors.types.d.ts.map +1 -0
- package/dist/context-descriptors.types.js +2 -0
- package/dist/context-descriptors.types.js.map +1 -0
- package/dist/context-resolution-service.d.ts +16 -0
- package/dist/context-resolution-service.d.ts.map +1 -0
- package/dist/context-resolution-service.js +31 -0
- package/dist/context-resolution-service.js.map +1 -0
- package/dist/context-resolution-service.types.d.ts +21 -0
- package/dist/context-resolution-service.types.d.ts.map +1 -0
- package/dist/context-resolution-service.types.js +2 -0
- package/dist/context-resolution-service.types.js.map +1 -0
- package/dist/context-resolver.d.ts +24 -15
- package/dist/context-resolver.d.ts.map +1 -1
- package/dist/context-resolver.js +85 -12
- package/dist/context-resolver.js.map +1 -1
- package/dist/context-resolver.types.d.ts +45 -0
- package/dist/context-resolver.types.d.ts.map +1 -0
- package/dist/context-resolver.types.js +2 -0
- package/dist/context-resolver.types.js.map +1 -0
- package/dist/define-app.d.ts +16 -15
- package/dist/define-app.d.ts.map +1 -1
- package/dist/define-app.js +67 -60
- package/dist/define-app.js.map +1 -1
- package/dist/define-app.types.d.ts +43 -0
- package/dist/define-app.types.d.ts.map +1 -0
- package/dist/define-app.types.js +2 -0
- package/dist/define-app.types.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +25 -18
- package/dist/define-app-types.d.ts.map +0 -1
- package/dist/define-app-types.js.map +0 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** API documentation visibility and domain exclusions.
|
|
2
|
+
* @example const docs: ApiDocsConfig = { enabledInProduction: false };
|
|
3
|
+
*/
|
|
4
|
+
export interface ApiDocsConfig {
|
|
5
|
+
readonly enabledInProduction?: boolean;
|
|
6
|
+
readonly excludeDomains?: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
/** HTTP server settings attached to an application descriptor.
|
|
9
|
+
* @example const server: ServerConfig = { port: 3000, apiDocs: { enabledInProduction: false } };
|
|
10
|
+
*/
|
|
11
|
+
export interface ServerConfig {
|
|
12
|
+
readonly port?: number;
|
|
13
|
+
readonly maxBodyBytes?: number;
|
|
14
|
+
readonly apiDocs?: ApiDocsConfig;
|
|
15
|
+
readonly clientContract?: boolean;
|
|
16
|
+
readonly mcp?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** Inspector settings attached to an application descriptor.
|
|
19
|
+
* @example const inspector: InspectorConfig = { port: 3210 };
|
|
20
|
+
*/
|
|
21
|
+
export interface InspectorConfig {
|
|
22
|
+
readonly port?: number;
|
|
23
|
+
readonly enabledInProduction?: boolean;
|
|
24
|
+
readonly maxPreviewBytes?: number;
|
|
25
|
+
}
|
|
26
|
+
/** Transitional compatibility switches for application authoring.
|
|
27
|
+
* @example const compatibility: AppCompatibilityConfig = { legacyJobs: true };
|
|
28
|
+
*/
|
|
29
|
+
export interface AppCompatibilityConfig {
|
|
30
|
+
readonly legacyJobs?: boolean;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=app-config.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-config.types.d.ts","sourceRoot":"","sources":["../src/app-config.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IACvC,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAClC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IACvC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-config.types.js","sourceRoot":"","sources":["../src/app-config.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Context, Effect, Layer } from "effect";
|
|
2
|
+
import type { AppOperation, AppTelemetryService } from "./app-observability.types.js";
|
|
3
|
+
declare const AppTelemetry_base: Context.ServiceClass<AppTelemetry, "relkit/app/AppTelemetry", AppTelemetryService>;
|
|
4
|
+
/** Injectable observer for application authoring operations.
|
|
5
|
+
* @example Effect.provide(defineAppEffect(options), AppTelemetryLive);
|
|
6
|
+
*/
|
|
7
|
+
export declare class AppTelemetry extends AppTelemetry_base {
|
|
8
|
+
}
|
|
9
|
+
/** Live spans, counts, failures, and durations for application operations.
|
|
10
|
+
* @example Effect.provide(defineAppEffect(options), AppTelemetryLive);
|
|
11
|
+
*/
|
|
12
|
+
export declare const AppTelemetryLive: Layer.Layer<AppTelemetry, never, never>;
|
|
13
|
+
/** Applies an injected observer or the live observer to one operation.
|
|
14
|
+
* @param operation - Fixed operation label.
|
|
15
|
+
* @param effect - Operation to measure.
|
|
16
|
+
* @returns The observed Effect, retaining success, error, and requirements.
|
|
17
|
+
* @example observeApp("define", Effect.succeed(app));
|
|
18
|
+
*/
|
|
19
|
+
export declare function observeApp<A, E, R>(operation: AppOperation, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=app-observability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-observability.d.ts","sourceRoot":"","sources":["../src/app-observability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,OAAO,EAAE,MAAM,EAAQ,KAAK,EAAkB,MAAM,QAAQ,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;;AAEtF;;GAEG;AACH,qBAAa,YAAa,SAAQ,iBAEjC;CAAG;AAEJ;;GAEG;AACH,eAAO,MAAM,gBAAgB,yCAAwD,CAAC;AAQtF;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAChC,SAAS,EAAE,YAAY,EACvB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAC7B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAMxB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Clock, Context, Effect, Exit, Layer, Metric, Option } from "effect";
|
|
2
|
+
/** Injectable observer for application authoring operations.
|
|
3
|
+
* @example Effect.provide(defineAppEffect(options), AppTelemetryLive);
|
|
4
|
+
*/
|
|
5
|
+
export class AppTelemetry extends Context.Service()("relkit/app/AppTelemetry") {
|
|
6
|
+
}
|
|
7
|
+
/** Live spans, counts, failures, and durations for application operations.
|
|
8
|
+
* @example Effect.provide(defineAppEffect(options), AppTelemetryLive);
|
|
9
|
+
*/
|
|
10
|
+
export const AppTelemetryLive = Layer.succeed(AppTelemetry, { observe: observeLive });
|
|
11
|
+
const calls = Metric.counter("relkit_app_operations_total", { incremental: true });
|
|
12
|
+
const failures = Metric.counter("relkit_app_failures_total", { incremental: true });
|
|
13
|
+
const duration = Metric.histogram("relkit_app_duration_ms", {
|
|
14
|
+
boundaries: [0.01, 0.1, 1, 5, 10, 50, 100],
|
|
15
|
+
});
|
|
16
|
+
/** Applies an injected observer or the live observer to one operation.
|
|
17
|
+
* @param operation - Fixed operation label.
|
|
18
|
+
* @param effect - Operation to measure.
|
|
19
|
+
* @returns The observed Effect, retaining success, error, and requirements.
|
|
20
|
+
* @example observeApp("define", Effect.succeed(app));
|
|
21
|
+
*/
|
|
22
|
+
export function observeApp(operation, effect) {
|
|
23
|
+
return Effect.flatMap(Effect.serviceOption(AppTelemetry), (service) => Option.isSome(service)
|
|
24
|
+
? service.value.observe(operation, effect)
|
|
25
|
+
: observeLive(operation, effect));
|
|
26
|
+
}
|
|
27
|
+
/** Records one duration on every exit, including interruption and defects. */
|
|
28
|
+
function observeLive(operation, effect) {
|
|
29
|
+
const attributes = { operation };
|
|
30
|
+
return Effect.withSpan(Effect.gen(function* () {
|
|
31
|
+
const started = yield* Clock.monotonicTimeNanos;
|
|
32
|
+
yield* Metric.update(Metric.withAttributes(calls, attributes), 1);
|
|
33
|
+
return yield* Effect.onExit(effect, (exit) => Effect.gen(function* () {
|
|
34
|
+
const elapsed = Number((yield* Clock.monotonicTimeNanos) - started) / 1_000_000;
|
|
35
|
+
yield* Metric.update(Metric.withAttributes(duration, attributes), Math.max(0, elapsed));
|
|
36
|
+
if (Exit.isFailure(exit))
|
|
37
|
+
yield* Metric.update(Metric.withAttributes(failures, attributes), 1);
|
|
38
|
+
}));
|
|
39
|
+
}), `app.${operation}`);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=app-observability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-observability.js","sourceRoot":"","sources":["../src/app-observability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG7E;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,OAAO,CAAC,OAAO,EAAqC,CACpF,yBAAyB,CAC1B;CAAG;AAEJ;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;AAEtF,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,6BAA6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AAM,OAAO,GAAG,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC,GAAG,OAAO,CAAC,GAAG,SAAS,CAAC;YAChF,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;YACxF,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;gBACtB,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;QACzE,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,CAAC,EACF,OAAO,SAAS,EAAE,CACnB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Effect } from "effect";
|
|
2
|
+
/** Fixed operation labels used for application authoring telemetry.
|
|
3
|
+
* @example const operation: AppOperation = "define";
|
|
4
|
+
*/
|
|
5
|
+
export type AppOperation = "define" | "env.isDefinition" | "id.derive" | "compatibility.normalize" | "alias.assertExclusive" | "constants.define" | "prompt.define" | "context.create" | "context.resolve";
|
|
6
|
+
/** A replaceable observer for application authoring operations.
|
|
7
|
+
* @example const observer: AppTelemetryService = { observe: (_name, effect) => effect };
|
|
8
|
+
*/
|
|
9
|
+
export interface AppTelemetryService {
|
|
10
|
+
/** Surrounds one operation without changing its result.
|
|
11
|
+
* @param operation - A fixed operation label.
|
|
12
|
+
* @param effect - The operation to observe.
|
|
13
|
+
* @returns The observed Effect with its success and error channels intact.
|
|
14
|
+
* @example observer.observe("define", Effect.succeed(app));
|
|
15
|
+
*/
|
|
16
|
+
readonly observe: <A, E, R>(operation: AppOperation, effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=app-observability.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-observability.types.d.ts","sourceRoot":"","sources":["../src/app-observability.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB,QAAQ,GACR,kBAAkB,GAClB,WAAW,GACX,yBAAyB,GACzB,uBAAuB,GACvB,kBAAkB,GAClB,eAAe,GACf,gBAAgB,GAChB,iBAAiB,CAAC;AAEtB;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACxB,SAAS,EAAE,YAAY,EACvB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-observability.types.js","sourceRoot":"","sources":["../src/app-observability.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-provider-capabilities.d.ts","sourceRoot":"","sources":["../src/app-provider-capabilities.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,eAAO,MAAM,yBAAyB,kFAQ5B,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Provider capabilities accepted by application descriptors. */
|
|
1
2
|
export const APP_PROVIDER_CAPABILITIES = [
|
|
2
3
|
"bucket",
|
|
3
4
|
"cache",
|
|
@@ -7,4 +8,4 @@ export const APP_PROVIDER_CAPABILITIES = [
|
|
|
7
8
|
"realtime",
|
|
8
9
|
"agent-state",
|
|
9
10
|
];
|
|
10
|
-
//# sourceMappingURL=
|
|
11
|
+
//# sourceMappingURL=app-provider-capabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-provider-capabilities.js","sourceRoot":"","sources":["../src/app-provider-capabilities.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,QAAQ;IACR,OAAO;IACP,KAAK;IACL,OAAO;IACP,OAAO;IACP,UAAU;IACV,aAAa;CACL,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { AppValidationFailure } from "./app-validation.js";
|
|
3
|
+
import type { AppProviderDefaults, AppProviderInputs } from "./define-app.types.js";
|
|
4
|
+
import type { NormalizedProviderProfiles, ProviderSourceInput } from "@relkit/provider";
|
|
5
|
+
/** Normalizes configured provider profiles in capability order.
|
|
6
|
+
* @param options - Authored provider bindings.
|
|
7
|
+
* @returns Normalized profiles or AppValidationFailure.
|
|
8
|
+
* @example Effect.runSync(normalizeProvidersEffect({}));
|
|
9
|
+
*/
|
|
10
|
+
export declare const normalizeProvidersEffect: (options: AppProviderInputs) => Effect.Effect<Partial<Record<"model" | "event" | "bucket" | "cache" | "job" | "realtime" | "agent-state", NormalizedProviderProfiles<import("@relkit/provider").ProviderAdapter>>>, AppValidationFailure, never>;
|
|
11
|
+
/** Checks default profile selections and returns an immutable copy.
|
|
12
|
+
* @param providers - Normalized available provider profiles.
|
|
13
|
+
* @param defaults - Optional selected profile names.
|
|
14
|
+
* @returns Frozen defaults or AppValidationFailure.
|
|
15
|
+
* @example Effect.runSync(normalizeDefaultsEffect({}, undefined));
|
|
16
|
+
*/
|
|
17
|
+
export declare const normalizeDefaultsEffect: <Providers extends AppProviderInputs>(providers: Partial<Record<"model" | "event" | "bucket" | "cache" | "job" | "realtime" | "agent-state", NormalizedProviderProfiles<import("@relkit/provider").ProviderAdapter>>>, defaults: AppProviderDefaults<Providers> | undefined) => Effect.Effect<Readonly<{
|
|
18
|
+
model?: ["model" extends infer T ? T extends "model" ? T extends keyof Providers ? NonNullable<Providers[T]> : never : never : never] extends [never] ? never : ("model" extends infer T_1 ? T_1 extends "model" ? T_1 extends keyof Providers ? NonNullable<Providers[T_1]> : never : never : never) extends infer T_2 ? T_2 extends ("model" extends infer T_3 ? T_3 extends "model" ? T_3 extends keyof Providers ? NonNullable<Providers[T_3]> : never : never : never) ? T_2 extends ProviderSourceInput ? "default" : Extract<keyof T_2, string> : never : never;
|
|
19
|
+
event?: ["event" extends infer T_4 ? T_4 extends "event" ? T_4 extends keyof Providers ? NonNullable<Providers[T_4]> : never : never : never] extends [never] ? never : ("event" extends infer T_5 ? T_5 extends "event" ? T_5 extends keyof Providers ? NonNullable<Providers[T_5]> : never : never : never) extends infer T_6 ? T_6 extends ("event" extends infer T_7 ? T_7 extends "event" ? T_7 extends keyof Providers ? NonNullable<Providers[T_7]> : never : never : never) ? T_6 extends ProviderSourceInput ? "default" : Extract<keyof T_6, string> : never : never;
|
|
20
|
+
bucket?: ["bucket" extends infer T_8 ? T_8 extends "bucket" ? T_8 extends keyof Providers ? NonNullable<Providers[T_8]> : never : never : never] extends [never] ? never : ("bucket" extends infer T_9 ? T_9 extends "bucket" ? T_9 extends keyof Providers ? NonNullable<Providers[T_9]> : never : never : never) extends infer T_10 ? T_10 extends ("bucket" extends infer T_11 ? T_11 extends "bucket" ? T_11 extends keyof Providers ? NonNullable<Providers[T_11]> : never : never : never) ? T_10 extends ProviderSourceInput ? "default" : Extract<keyof T_10, string> : never : never;
|
|
21
|
+
cache?: ["cache" extends infer T_12 ? T_12 extends "cache" ? T_12 extends keyof Providers ? NonNullable<Providers[T_12]> : never : never : never] extends [never] ? never : ("cache" extends infer T_13 ? T_13 extends "cache" ? T_13 extends keyof Providers ? NonNullable<Providers[T_13]> : never : never : never) extends infer T_14 ? T_14 extends ("cache" extends infer T_15 ? T_15 extends "cache" ? T_15 extends keyof Providers ? NonNullable<Providers[T_15]> : never : never : never) ? T_14 extends ProviderSourceInput ? "default" : Extract<keyof T_14, string> : never : never;
|
|
22
|
+
job?: ["jobs" extends keyof Providers ? NonNullable<Providers[keyof Providers & "jobs"]> : "job" extends keyof Providers ? NonNullable<Providers[keyof Providers & "job"]> : never] extends [never] ? never : ("jobs" extends keyof Providers ? NonNullable<Providers[keyof Providers & "jobs"]> : "job" extends keyof Providers ? NonNullable<Providers[keyof Providers & "job"]> : never) extends infer T_16 ? T_16 extends ("jobs" extends keyof Providers ? NonNullable<Providers[keyof Providers & "jobs"]> : "job" extends keyof Providers ? NonNullable<Providers[keyof Providers & "job"]> : never) ? T_16 extends ProviderSourceInput ? "default" : Extract<keyof T_16, string> : never : never;
|
|
23
|
+
realtime?: ["realtime" extends infer T_17 ? T_17 extends "realtime" ? T_17 extends keyof Providers ? NonNullable<Providers[T_17]> : never : never : never] extends [never] ? never : ("realtime" extends infer T_18 ? T_18 extends "realtime" ? T_18 extends keyof Providers ? NonNullable<Providers[T_18]> : never : never : never) extends infer T_19 ? T_19 extends ("realtime" extends infer T_20 ? T_20 extends "realtime" ? T_20 extends keyof Providers ? NonNullable<Providers[T_20]> : never : never : never) ? T_19 extends ProviderSourceInput ? "default" : Extract<keyof T_19, string> : never : never;
|
|
24
|
+
"agent-state"?: ["agent-state" extends infer T_21 ? T_21 extends "agent-state" ? T_21 extends keyof Providers ? NonNullable<Providers[T_21]> : never : never : never] extends [never] ? never : ("agent-state" extends infer T_22 ? T_22 extends "agent-state" ? T_22 extends keyof Providers ? NonNullable<Providers[T_22]> : never : never : never) extends infer T_23 ? T_23 extends ("agent-state" extends infer T_24 ? T_24 extends "agent-state" ? T_24 extends keyof Providers ? NonNullable<Providers[T_24]> : never : never : never) ? T_23 extends ProviderSourceInput ? "default" : Extract<keyof T_23, string> : never : never;
|
|
25
|
+
}>, AppValidationFailure, never>;
|
|
26
|
+
/** Copies a serializable configuration value through RELKIT's serializer.
|
|
27
|
+
* @param value - Configuration value to copy.
|
|
28
|
+
* @returns A JSON copy or AppValidationFailure.
|
|
29
|
+
* @example Effect.runSync(copyEffect({ port: 3000 }));
|
|
30
|
+
*/
|
|
31
|
+
export declare const copyEffect: <Value>(value: Value) => Effect.Effect<Value, AppValidationFailure, never>;
|
|
32
|
+
//# sourceMappingURL=app-provider-normalization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-provider-normalization.d.ts","sourceRoot":"","sources":["../src/app-provider-normalization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAEV,mBAAmB,EACnB,iBAAiB,EAElB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAExF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,kPAkBpC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GACjC,SAAS,SAAS,iBAAiB;;;;;;;;gCAqBrC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAA0B,KAAK,oEAKrD,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { serializeJson } from "@relkit/contracts";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { defineProviderCapability, normalizeProviderProfiles } from "@relkit/provider";
|
|
4
|
+
import { APP_PROVIDER_CAPABILITIES } from "./app-provider-capabilities.js";
|
|
5
|
+
import { AppValidationFailure } from "./app-validation.js";
|
|
6
|
+
/** Normalizes configured provider profiles in capability order.
|
|
7
|
+
* @param options - Authored provider bindings.
|
|
8
|
+
* @returns Normalized profiles or AppValidationFailure.
|
|
9
|
+
* @example Effect.runSync(normalizeProvidersEffect({}));
|
|
10
|
+
*/
|
|
11
|
+
export const normalizeProvidersEffect = Effect.fn("App.normalizeProviders")((options) => Effect.gen(function* () {
|
|
12
|
+
const result = {};
|
|
13
|
+
for (const capability of APP_PROVIDER_CAPABILITIES) {
|
|
14
|
+
const input = capability === "job" ? (options.jobs ?? options.job) : options[capability];
|
|
15
|
+
if (input !== undefined)
|
|
16
|
+
result[capability] = yield* Effect.try({
|
|
17
|
+
try: () => normalizeProviderProfiles(defineProviderCapability(capability), input),
|
|
18
|
+
catch: failure,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}));
|
|
23
|
+
/** Checks default profile selections and returns an immutable copy.
|
|
24
|
+
* @param providers - Normalized available provider profiles.
|
|
25
|
+
* @param defaults - Optional selected profile names.
|
|
26
|
+
* @returns Frozen defaults or AppValidationFailure.
|
|
27
|
+
* @example Effect.runSync(normalizeDefaultsEffect({}, undefined));
|
|
28
|
+
*/
|
|
29
|
+
export const normalizeDefaultsEffect = Effect.fn("App.normalizeDefaults")((providers, defaults) => Effect.gen(function* () {
|
|
30
|
+
const result = {};
|
|
31
|
+
for (const [rawCapability, selected] of Object.entries(defaults ?? {})) {
|
|
32
|
+
const capability = rawCapability === "jobs" ? "job" : rawCapability;
|
|
33
|
+
if (!APP_PROVIDER_CAPABILITIES.includes(capability))
|
|
34
|
+
return yield* Effect.fail(failure(new TypeError(`Unknown default capability "${capability}"`)));
|
|
35
|
+
const profiles = providers[capability]?.profiles;
|
|
36
|
+
if (typeof selected !== "string" || profiles?.[selected] === undefined)
|
|
37
|
+
return yield* Effect.fail(failure(new TypeError(`defaults.${capability} must reference a configured profile`)));
|
|
38
|
+
result[capability] = selected;
|
|
39
|
+
}
|
|
40
|
+
return (yield* copyEffect(result));
|
|
41
|
+
}));
|
|
42
|
+
/** Copies a serializable configuration value through RELKIT's serializer.
|
|
43
|
+
* @param value - Configuration value to copy.
|
|
44
|
+
* @returns A JSON copy or AppValidationFailure.
|
|
45
|
+
* @example Effect.runSync(copyEffect({ port: 3000 }));
|
|
46
|
+
*/
|
|
47
|
+
export const copyEffect = Effect.fn("App.copy")((value) => Effect.try({
|
|
48
|
+
try: () => JSON.parse(serializeJson(value)),
|
|
49
|
+
catch: failure,
|
|
50
|
+
}));
|
|
51
|
+
/** Keeps original errors available to compatibility adapters. */
|
|
52
|
+
function failure(cause) {
|
|
53
|
+
return new AppValidationFailure({
|
|
54
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
55
|
+
cause,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=app-provider-normalization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-provider-normalization.js","sourceRoot":"","sources":["../src/app-provider-normalization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAS3D;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,EAAE,CAAC,wBAAwB,CAAC,CACzE,CAAC,OAA0B,EAAE,EAAE,CAC7B,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,MAAM,GAAuE,EAAE,CAAC;IACtF,KAAK,MAAM,UAAU,IAAI,yBAAyB,EAAE,CAAC;QACnD,MAAM,KAAK,GAAG,UAAU,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACzF,IAAI,KAAK,KAAK,SAAS;YACrB,MAAM,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;gBACrC,GAAG,EAAE,GAAG,EAAE,CACR,yBAAyB,CACv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;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAQ,KAAY,EAAE,EAAE,CACtE,MAAM,CAAC,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAU;IACpD,KAAK,EAAE,OAAO;CACf,CAAC,CACH,CAAC;AAEF,iEAAiE;AACjE,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,IAAI,oBAAoB,CAAC;QAC9B,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QAC/D,KAAK;KACN,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,29 +1,13 @@
|
|
|
1
|
-
import type { EnvDefinition, EnvShape } from "@relkit/config";
|
|
2
|
-
import type { DescriptorBase, DescriptorMetadata, JsonValue } from "@relkit/contracts";
|
|
3
|
-
import type { TelemetryConfiguration, TelemetryExporterMap } from "@relkit/observability/telemetry";
|
|
4
1
|
import type { NormalizedProviderProfiles, ProviderAdapter, ProviderCapability, ProviderInput, ProviderSourceInput } from "@relkit/provider";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export interface ServerConfig {
|
|
10
|
-
readonly port?: number;
|
|
11
|
-
readonly maxBodyBytes?: number;
|
|
12
|
-
readonly apiDocs?: ApiDocsConfig;
|
|
13
|
-
readonly clientContract?: boolean;
|
|
14
|
-
readonly mcp?: boolean;
|
|
15
|
-
}
|
|
16
|
-
export interface InspectorConfig {
|
|
17
|
-
readonly port?: number;
|
|
18
|
-
readonly enabledInProduction?: boolean;
|
|
19
|
-
readonly maxPreviewBytes?: number;
|
|
20
|
-
}
|
|
21
|
-
export interface AppCompatibilityConfig {
|
|
22
|
-
readonly legacyJobs?: boolean;
|
|
23
|
-
}
|
|
24
|
-
export declare const APP_PROVIDER_CAPABILITIES: readonly ["bucket", "cache", "job", "event", "model", "realtime", "agent-state"];
|
|
2
|
+
import type { APP_PROVIDER_CAPABILITIES } from "./app-provider-capabilities.js";
|
|
3
|
+
/** Provider capabilities accepted by the application descriptor.
|
|
4
|
+
* @example const capability: AppProviderCapability = "cache";
|
|
5
|
+
*/
|
|
25
6
|
export type AppProviderCapability = (typeof APP_PROVIDER_CAPABILITIES)[number];
|
|
26
7
|
type CapabilityInput<Capability extends AppProviderCapability> = ProviderInput<ProviderSourceInput<ProviderAdapter<ProviderCapability<Capability>>>>;
|
|
8
|
+
/** Optional provider bindings for every supported capability.
|
|
9
|
+
* @example const providers: AppProviderInputs = { cache: redisAdapter };
|
|
10
|
+
*/
|
|
27
11
|
export interface AppProviderInputs {
|
|
28
12
|
readonly bucket?: CapabilityInput<"bucket">;
|
|
29
13
|
readonly cache?: CapabilityInput<"cache">;
|
|
@@ -41,7 +25,9 @@ type ProviderInputFor<Providers extends AppProviderInputs, Capability extends Ap
|
|
|
41
25
|
type ProfileFor<Providers extends AppProviderInputs, Capability extends AppProviderCapability> = [
|
|
42
26
|
ProviderInputFor<Providers, Capability>
|
|
43
27
|
] extends [never] ? never : Profile<ProviderInputFor<Providers, Capability>>;
|
|
44
|
-
/** Public
|
|
28
|
+
/** Public default-profile spellings; normalized descriptors use `job`.
|
|
29
|
+
* @example const defaults: AppProviderDefaults<typeof providers> = { cache: "default" };
|
|
30
|
+
*/
|
|
45
31
|
export type AppProviderDefaults<Providers extends AppProviderInputs> = Readonly<{
|
|
46
32
|
[Capability in Exclude<AppProviderCapability, "job">]?: ProfileFor<Providers, Capability>;
|
|
47
33
|
}> & {
|
|
@@ -49,35 +35,18 @@ export type AppProviderDefaults<Providers extends AppProviderInputs> = Readonly<
|
|
|
49
35
|
/** @deprecated Use `jobs`. */
|
|
50
36
|
readonly job?: ProfileFor<Providers, "job">;
|
|
51
37
|
};
|
|
38
|
+
/** Validated default profiles keyed by normalized capability names.
|
|
39
|
+
* @example const defaults: NormalizedAppProviderDefaults<typeof providers> = { cache: "default" };
|
|
40
|
+
*/
|
|
52
41
|
export type NormalizedAppProviderDefaults<Providers extends AppProviderInputs> = Readonly<{
|
|
53
42
|
[Capability in AppProviderCapability]?: ProfileFor<Providers, Capability>;
|
|
54
43
|
}>;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
readonly env: EnvDefinition<Shape>;
|
|
60
|
-
readonly defaults?: AppProviderDefaults<Providers>;
|
|
61
|
-
readonly compatibility?: AppCompatibilityConfig;
|
|
62
|
-
readonly telemetry?: AppTelemetryConfig<Exporters>;
|
|
63
|
-
readonly server?: ServerConfig;
|
|
64
|
-
readonly inspector?: InspectorConfig;
|
|
65
|
-
readonly deployment?: AppDeploymentConfig;
|
|
66
|
-
};
|
|
67
|
-
type AdapterOf<Input> = Input extends ProviderSourceInput<infer Adapter> ? Adapter : Input extends Readonly<Record<string, infer Binding>> ? Binding extends ProviderSourceInput<infer Adapter> ? Adapter : never : never;
|
|
68
|
-
type NormalizedProviders<Providers extends AppProviderInputs> = {
|
|
44
|
+
/** Provider profiles inferred from the authored provider bindings.
|
|
45
|
+
* @example type Profiles = NormalizedProviders<typeof providers>;
|
|
46
|
+
*/
|
|
47
|
+
export type NormalizedProviders<Providers extends AppProviderInputs> = {
|
|
69
48
|
readonly [Capability in AppProviderCapability as [ProviderInputFor<Providers, Capability>] extends [never] ? never : Capability]: NormalizedProviderProfiles<AdapterOf<ProviderInputFor<Providers, Capability>>>;
|
|
70
49
|
};
|
|
71
|
-
|
|
72
|
-
readonly env: EnvDefinition<Shape>;
|
|
73
|
-
readonly defaults: NormalizedAppProviderDefaults<Providers>;
|
|
74
|
-
readonly compatibility: {
|
|
75
|
-
readonly legacyJobs: boolean;
|
|
76
|
-
};
|
|
77
|
-
readonly telemetry?: AppTelemetryConfig<Exporters>;
|
|
78
|
-
readonly server?: ServerConfig;
|
|
79
|
-
readonly inspector?: InspectorConfig;
|
|
80
|
-
readonly deployment?: AppDeploymentConfig;
|
|
81
|
-
};
|
|
50
|
+
type AdapterOf<Input> = Input extends ProviderSourceInput<infer Adapter> ? Adapter : Input extends Readonly<Record<string, infer Binding>> ? Binding extends ProviderSourceInput<infer Adapter> ? Adapter : never : never;
|
|
82
51
|
export {};
|
|
83
|
-
//# sourceMappingURL=
|
|
52
|
+
//# sourceMappingURL=app-provider.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-provider.types.d.ts","sourceRoot":"","sources":["../src/app-provider.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,yBAAyB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/E,KAAK,eAAe,CAAC,UAAU,SAAS,qBAAqB,IAAI,aAAa,CAC5E,mBAAmB,CAAC,eAAe,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAAC,CACrE,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC5C,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IAC1C,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,CAAC,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC;IACvC,8BAA8B;IAC9B,QAAQ,CAAC,GAAG,CAAC,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC;IACtC,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IAC1C,QAAQ,CAAC,KAA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CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;CAC7C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,CAAC,SAAS,SAAS,iBAAiB,IAAI,QAAQ,CAAC;KACvF,UAAU,IAAI,qBAAqB,CAAC,CAAC,EAAE,UAAU,CAAC,SAAS,EAAE,UAAU,CAAC;CAC1E,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,SAAS,SAAS,iBAAiB,IAAI;IACrE,QAAQ,EACN,UAAU,IAAI,qBAAqB,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC5F,KAAK,GACL,UAAU,GACb,0BAA0B,CAAC,SAAS,CAAC,gBAAgB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;CAClF,CAAC;AAEF,KAAK,SAAS,CAAC,KAAK,IAClB,KAAK,SAAS,mBAAmB,CAAC,MAAM,OAAO,CAAC,GAC5C,OAAO,GACP,KAAK,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,GACnD,OAAO,SAAS,mBAAmB,CAAC,MAAM,OAAO,CAAC,GAChD,OAAO,GACP,KAAK,GACP,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-provider.types.js","sourceRoot":"","sources":["../src/app-provider.types.ts"],"names":[],"mappings":""}
|
package/dist/app-validation.d.ts
CHANGED
|
@@ -1,9 +1,75 @@
|
|
|
1
1
|
import { type EnvDefinition, type EnvShape } from "@relkit/config";
|
|
2
|
-
import
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
|
+
import type { AppCompatibilityConfig } from "./define-app.types.js";
|
|
4
|
+
declare const AppValidationFailure_base: Schema.Class<AppValidationFailure, Schema.TaggedStruct<"AppValidationFailure", {
|
|
5
|
+
readonly message: Schema.String;
|
|
6
|
+
readonly cause: Schema.Defect;
|
|
7
|
+
}>, import("effect/Cause").YieldableError>;
|
|
8
|
+
/** Expected invalid application input with the original cause preserved.
|
|
9
|
+
* @example if (error._tag === "AppValidationFailure") console.error(error.message);
|
|
10
|
+
*/
|
|
11
|
+
export declare class AppValidationFailure extends AppValidationFailure_base {
|
|
12
|
+
}
|
|
13
|
+
/** Checks the complete environment descriptor shape in Effect.
|
|
14
|
+
* @param value - Candidate environment descriptor.
|
|
15
|
+
* @returns True for a valid environment definition; no expected failure.
|
|
16
|
+
* @example Effect.runSync(isEnvDefinitionEffect(value));
|
|
17
|
+
*/
|
|
18
|
+
export declare const isEnvDefinitionEffect: (value: unknown) => Effect.Effect<boolean, never, never>;
|
|
19
|
+
/** Synchronous environment descriptor guard.
|
|
20
|
+
* @param value - Candidate environment descriptor.
|
|
21
|
+
* @returns True for a valid environment definition.
|
|
22
|
+
* @example if (isEnvDefinition(value)) console.log(value.shape);
|
|
23
|
+
*/
|
|
3
24
|
export declare function isEnvDefinition(value: unknown): value is EnvDefinition<EnvShape>;
|
|
25
|
+
/** Derives an application ID from a package name in Effect.
|
|
26
|
+
* @param packageName - Scoped or unscoped package name.
|
|
27
|
+
* @returns A normalized ID or AppValidationFailure.
|
|
28
|
+
* @example Effect.runSync(deriveApplicationIdEffect("@acme/orders"));
|
|
29
|
+
*/
|
|
30
|
+
export declare const deriveApplicationIdEffect: (packageName: string) => Effect.Effect<import("@relkit/contracts").StableId, AppValidationFailure, never>;
|
|
31
|
+
/** Synchronous package-name ID adapter.
|
|
32
|
+
* @param packageName - Scoped or unscoped package name.
|
|
33
|
+
* @returns A normalized application ID.
|
|
34
|
+
* @throws The original normalization error for invalid input.
|
|
35
|
+
* @example deriveApplicationId("@acme/orders");
|
|
36
|
+
*/
|
|
4
37
|
export declare function deriveApplicationId(packageName: string): string;
|
|
38
|
+
/** Normalizes the legacy jobs compatibility flag in Effect.
|
|
39
|
+
* @param value - Optional compatibility configuration.
|
|
40
|
+
* @returns A frozen flag object or AppValidationFailure.
|
|
41
|
+
* @example Effect.runSync(normalizeCompatibilityEffect({ legacyJobs: true }));
|
|
42
|
+
*/
|
|
43
|
+
export declare const normalizeCompatibilityEffect: (value: AppCompatibilityConfig | undefined) => Effect.Effect<Readonly<{
|
|
44
|
+
legacyJobs: boolean;
|
|
45
|
+
}>, AppValidationFailure, never>;
|
|
46
|
+
/** Synchronous compatibility normalizer.
|
|
47
|
+
* @param value - Optional compatibility configuration.
|
|
48
|
+
* @returns A frozen legacy-jobs flag object.
|
|
49
|
+
* @throws TypeError for an invalid compatibility flag.
|
|
50
|
+
* @example normalizeCompatibility({ legacyJobs: true });
|
|
51
|
+
*/
|
|
5
52
|
export declare function normalizeCompatibility(value: AppCompatibilityConfig | undefined): {
|
|
6
53
|
readonly legacyJobs: boolean;
|
|
7
54
|
};
|
|
55
|
+
/** Rejects simultaneous current and legacy aliases in Effect.
|
|
56
|
+
* @param value - Record containing optional aliases.
|
|
57
|
+
* @param primary - Current alias name.
|
|
58
|
+
* @param legacy - Legacy alias name.
|
|
59
|
+
* @param label - Diagnostic context.
|
|
60
|
+
* @returns Void or AppValidationFailure.
|
|
61
|
+
* @example Effect.runSync(assertExclusiveAliasEffect(options, "jobs", "job", "defineApp"));
|
|
62
|
+
*/
|
|
63
|
+
export declare const assertExclusiveAliasEffect: (value: Record<string, unknown>, primary: string, legacy: string, label: string) => Effect.Effect<void, AppValidationFailure, never>;
|
|
64
|
+
/** Synchronous alias exclusivity adapter.
|
|
65
|
+
* @param value - Record containing optional aliases.
|
|
66
|
+
* @param primary - Current alias name.
|
|
67
|
+
* @param legacy - Legacy alias name.
|
|
68
|
+
* @param label - Diagnostic context.
|
|
69
|
+
* @returns Nothing when aliases are exclusive.
|
|
70
|
+
* @throws TypeError when both aliases are present.
|
|
71
|
+
* @example assertExclusiveAlias(options, "jobs", "job", "defineApp");
|
|
72
|
+
*/
|
|
8
73
|
export declare function assertExclusiveAlias(value: Record<string, unknown>, primary: string, legacy: string, label: string): void;
|
|
74
|
+
export {};
|
|
9
75
|
//# sourceMappingURL=app-validation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-validation.d.ts","sourceRoot":"","sources":["../src/app-validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"app-validation.d.ts","sourceRoot":"","sources":["../src/app-validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE7E,OAAO,EAAE,MAAM,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;;;;;AAEpE;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,yBAGzC;CAAG;AAEJ;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,0DAmBjC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAAC,QAAQ,CAAC,CAEhF;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,2GAYrC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED;;;;GAIG;AACH,eAAO,MAAM,4BAA4B;;gCAiBxC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,sBAAsB,GAAG,SAAS,GAAG;IACjF,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B,CAEA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,sIAYtC,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,IAAI,CAEN"}
|
package/dist/app-validation.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { isEnvRef } from "@relkit/config";
|
|
2
2
|
import { normalizeId } from "@relkit/contracts";
|
|
3
|
-
|
|
3
|
+
import { Effect, Result, Schema } from "effect";
|
|
4
|
+
import { observeApp } from "./app-observability.js";
|
|
5
|
+
/** Expected invalid application input with the original cause preserved.
|
|
6
|
+
* @example if (error._tag === "AppValidationFailure") console.error(error.message);
|
|
7
|
+
*/
|
|
8
|
+
export class AppValidationFailure extends Schema.TaggedError()("AppValidationFailure", { message: Schema.String, cause: Schema.Defect() }) {
|
|
9
|
+
}
|
|
10
|
+
/** Checks the complete environment descriptor shape in Effect.
|
|
11
|
+
* @param value - Candidate environment descriptor.
|
|
12
|
+
* @returns True for a valid environment definition; no expected failure.
|
|
13
|
+
* @example Effect.runSync(isEnvDefinitionEffect(value));
|
|
14
|
+
*/
|
|
15
|
+
export const isEnvDefinitionEffect = Effect.fn("App.isEnvDefinition")((value) => observeApp("env.isDefinition", Effect.sync(() => {
|
|
4
16
|
if (!isRecord(value) || value.kind !== "env-definition" || !isRecord(value.shape))
|
|
5
17
|
return false;
|
|
6
18
|
return Object.entries(value.shape).every(([name, builder]) => {
|
|
@@ -12,25 +24,100 @@ export function isEnvDefinition(value) {
|
|
|
12
24
|
isEnvRef(reference) &&
|
|
13
25
|
reference.name === name);
|
|
14
26
|
});
|
|
27
|
+
})));
|
|
28
|
+
/** Synchronous environment descriptor guard.
|
|
29
|
+
* @param value - Candidate environment descriptor.
|
|
30
|
+
* @returns True for a valid environment definition.
|
|
31
|
+
* @example if (isEnvDefinition(value)) console.log(value.shape);
|
|
32
|
+
*/
|
|
33
|
+
export function isEnvDefinition(value) {
|
|
34
|
+
return Effect.runSync(isEnvDefinitionEffect(value));
|
|
15
35
|
}
|
|
36
|
+
/** Derives an application ID from a package name in Effect.
|
|
37
|
+
* @param packageName - Scoped or unscoped package name.
|
|
38
|
+
* @returns A normalized ID or AppValidationFailure.
|
|
39
|
+
* @example Effect.runSync(deriveApplicationIdEffect("@acme/orders"));
|
|
40
|
+
*/
|
|
41
|
+
export const deriveApplicationIdEffect = Effect.fn("App.deriveApplicationId")((packageName) => observeApp("id.derive", Effect.try({
|
|
42
|
+
try: () => normalizeId((packageName.startsWith("@") ? packageName.slice(1) : packageName).replaceAll("/", ".")),
|
|
43
|
+
catch: validationFailure,
|
|
44
|
+
})));
|
|
45
|
+
/** Synchronous package-name ID adapter.
|
|
46
|
+
* @param packageName - Scoped or unscoped package name.
|
|
47
|
+
* @returns A normalized application ID.
|
|
48
|
+
* @throws The original normalization error for invalid input.
|
|
49
|
+
* @example deriveApplicationId("@acme/orders");
|
|
50
|
+
*/
|
|
16
51
|
export function deriveApplicationId(packageName) {
|
|
17
|
-
|
|
18
|
-
return normalizeId(normalized.replaceAll("/", "."));
|
|
52
|
+
return runValidation(deriveApplicationIdEffect(packageName));
|
|
19
53
|
}
|
|
54
|
+
/** Normalizes the legacy jobs compatibility flag in Effect.
|
|
55
|
+
* @param value - Optional compatibility configuration.
|
|
56
|
+
* @returns A frozen flag object or AppValidationFailure.
|
|
57
|
+
* @example Effect.runSync(normalizeCompatibilityEffect({ legacyJobs: true }));
|
|
58
|
+
*/
|
|
59
|
+
export const normalizeCompatibilityEffect = Effect.fn("App.normalizeCompatibility")((value) => observeApp("compatibility.normalize", Effect.try({
|
|
60
|
+
try: () => {
|
|
61
|
+
if (value === undefined)
|
|
62
|
+
return Object.freeze({ legacyJobs: false });
|
|
63
|
+
if (!isRecord(value) ||
|
|
64
|
+
(value.legacyJobs !== undefined && typeof value.legacyJobs !== "boolean"))
|
|
65
|
+
throw new TypeError("defineApp compatibility.legacyJobs must be a boolean");
|
|
66
|
+
return Object.freeze({ legacyJobs: value.legacyJobs === true });
|
|
67
|
+
},
|
|
68
|
+
catch: validationFailure,
|
|
69
|
+
})));
|
|
70
|
+
/** Synchronous compatibility normalizer.
|
|
71
|
+
* @param value - Optional compatibility configuration.
|
|
72
|
+
* @returns A frozen legacy-jobs flag object.
|
|
73
|
+
* @throws TypeError for an invalid compatibility flag.
|
|
74
|
+
* @example normalizeCompatibility({ legacyJobs: true });
|
|
75
|
+
*/
|
|
20
76
|
export function normalizeCompatibility(value) {
|
|
21
|
-
|
|
22
|
-
return Object.freeze({ legacyJobs: false });
|
|
23
|
-
if (!isRecord(value) ||
|
|
24
|
-
(value.legacyJobs !== undefined && typeof value.legacyJobs !== "boolean")) {
|
|
25
|
-
throw new TypeError("defineApp compatibility.legacyJobs must be a boolean");
|
|
26
|
-
}
|
|
27
|
-
return Object.freeze({ legacyJobs: value.legacyJobs === true });
|
|
77
|
+
return runValidation(normalizeCompatibilityEffect(value));
|
|
28
78
|
}
|
|
79
|
+
/** Rejects simultaneous current and legacy aliases in Effect.
|
|
80
|
+
* @param value - Record containing optional aliases.
|
|
81
|
+
* @param primary - Current alias name.
|
|
82
|
+
* @param legacy - Legacy alias name.
|
|
83
|
+
* @param label - Diagnostic context.
|
|
84
|
+
* @returns Void or AppValidationFailure.
|
|
85
|
+
* @example Effect.runSync(assertExclusiveAliasEffect(options, "jobs", "job", "defineApp"));
|
|
86
|
+
*/
|
|
87
|
+
export const assertExclusiveAliasEffect = Effect.fn("App.assertExclusiveAlias")((value, primary, legacy, label) => observeApp("alias.assertExclusive", Effect.try({
|
|
88
|
+
try: () => {
|
|
89
|
+
if (value[primary] !== undefined && value[legacy] !== undefined)
|
|
90
|
+
throw new TypeError(`${label} cannot specify both "${primary}" and "${legacy}"`);
|
|
91
|
+
},
|
|
92
|
+
catch: validationFailure,
|
|
93
|
+
})));
|
|
94
|
+
/** Synchronous alias exclusivity adapter.
|
|
95
|
+
* @param value - Record containing optional aliases.
|
|
96
|
+
* @param primary - Current alias name.
|
|
97
|
+
* @param legacy - Legacy alias name.
|
|
98
|
+
* @param label - Diagnostic context.
|
|
99
|
+
* @returns Nothing when aliases are exclusive.
|
|
100
|
+
* @throws TypeError when both aliases are present.
|
|
101
|
+
* @example assertExclusiveAlias(options, "jobs", "job", "defineApp");
|
|
102
|
+
*/
|
|
29
103
|
export function assertExclusiveAlias(value, primary, legacy, label) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
104
|
+
runValidation(assertExclusiveAliasEffect(value, primary, legacy, label));
|
|
105
|
+
}
|
|
106
|
+
/** Maps known synchronous validation errors into the typed channel. */
|
|
107
|
+
function validationFailure(cause) {
|
|
108
|
+
return new AppValidationFailure({
|
|
109
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
110
|
+
cause,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/** Runs a pure validation Effect while preserving old thrown errors. */
|
|
114
|
+
function runValidation(effect) {
|
|
115
|
+
const result = Effect.runSync(Effect.result(effect));
|
|
116
|
+
if (Result.isFailure(result))
|
|
117
|
+
throw result.failure.cause;
|
|
118
|
+
return result.success;
|
|
33
119
|
}
|
|
120
|
+
/** Tests for a non-array object record. */
|
|
34
121
|
function isRecord(value) {
|
|
35
122
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
36
123
|
}
|