silgi 0.52.1 → 0.52.2
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/builder.d.mts +1 -21
- package/dist/index.d.mts +1 -3
- package/dist/index.mjs +1 -3
- package/package.json +1 -1
- package/dist/error-mapper.d.mts +0 -32
- package/dist/error-mapper.mjs +0 -63
- package/dist/route-kit.d.mts +0 -48
- package/dist/route-kit.mjs +0 -12
package/dist/builder.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnySchema, InferSchemaInput, InferSchemaOutput } from "./core/schema.mjs";
|
|
2
2
|
import { TaskDef, TaskEvent } from "./core/task.mjs";
|
|
3
|
-
import { ErrorDef, GuardDef, Meta,
|
|
3
|
+
import { ErrorDef, GuardDef, Meta, ProcedureDef, ProcedureType, ResolveContext, Route, WrapDef } from "./types.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/builder.d.ts
|
|
6
6
|
/** Initial builder — no input, no output, no errors yet */
|
|
@@ -9,17 +9,6 @@ interface ProcedureBuilder<TType extends ProcedureType, TBaseCtx extends Record<
|
|
|
9
9
|
$use<TReturn extends Record<string, unknown> | void, TGErrors extends ErrorDef = {}>(guard: GuardDef<any, TReturn, TGErrors>): ProcedureBuilder<TType, TBaseCtx, TReturn extends Record<string, unknown> ? TCtx & TReturn : TCtx, TInput, TGErrors & TErrors>;
|
|
10
10
|
/** Add a wrap middleware — does not change context type */
|
|
11
11
|
$use(wrap: WrapDef<any>): ProcedureBuilder<TType, TBaseCtx, TCtx, TInput, TErrors>;
|
|
12
|
-
/**
|
|
13
|
-
* Add a middleware of unknown variant (`GuardDef | WrapDef`).
|
|
14
|
-
*
|
|
15
|
-
* @remarks
|
|
16
|
-
* Used by factory-pattern builders that accept middleware through a
|
|
17
|
-
* dependency boundary where the concrete variant isn't known at the
|
|
18
|
-
* call site. Context is not enriched — if you need guard-added fields
|
|
19
|
-
* in `.$resolve()`, pass the guard with its concrete type or use
|
|
20
|
-
* `defineRouteKit` to bind the ctx shape up front.
|
|
21
|
-
*/
|
|
22
|
-
$use(mw: MiddlewareDef): ProcedureBuilder<TType, TBaseCtx, TCtx, TInput, TErrors>;
|
|
23
12
|
/** Set input schema */
|
|
24
13
|
$input<TSchema extends AnySchema>(schema: TSchema): ProcedureBuilder<TType, TBaseCtx, TCtx, InferSchemaOutput<TSchema>, TErrors>;
|
|
25
14
|
/** Set output schema — enables return type autocomplete */
|
|
@@ -46,15 +35,6 @@ interface ProcedureBuilderWithOutput<TType extends ProcedureType, TBaseCtx exten
|
|
|
46
35
|
$use<TReturn extends Record<string, unknown> | void, TGErrors extends ErrorDef = {}>(guard: GuardDef<any, TReturn, TGErrors>): ProcedureBuilderWithOutput<TType, TBaseCtx, TReturn extends Record<string, unknown> ? TCtx & TReturn : TCtx, TInput, TOutputResolved, TGErrors & TErrors>;
|
|
47
36
|
/** Add a wrap middleware — does not change context type */
|
|
48
37
|
$use(wrap: WrapDef<any>): ProcedureBuilderWithOutput<TType, TBaseCtx, TCtx, TInput, TOutputResolved, TErrors>;
|
|
49
|
-
/**
|
|
50
|
-
* Add a middleware of unknown variant (`GuardDef | WrapDef`).
|
|
51
|
-
*
|
|
52
|
-
* @remarks
|
|
53
|
-
* Used by factory-pattern builders that accept middleware through a
|
|
54
|
-
* dependency boundary where the concrete variant isn't known at the
|
|
55
|
-
* call site.
|
|
56
|
-
*/
|
|
57
|
-
$use(mw: MiddlewareDef): ProcedureBuilderWithOutput<TType, TBaseCtx, TCtx, TInput, TOutputResolved, TErrors>;
|
|
58
38
|
/** Set typed errors */
|
|
59
39
|
$errors<TNewErrors extends ErrorDef>(errors: TNewErrors): ProcedureBuilderWithOutput<TType, TBaseCtx, TCtx, TInput, TOutputResolved, TNewErrors & TErrors>;
|
|
60
40
|
/** Set route metadata */
|
package/dist/index.d.mts
CHANGED
|
@@ -9,8 +9,6 @@ import { ServeOptions, SilgiServer } from "./core/serve.mjs";
|
|
|
9
9
|
import { Driver, Storage, StorageConfig, StorageValue, initStorage, resetStorage, useStorage } from "./core/storage.mjs";
|
|
10
10
|
import { SilgiConfig, SilgiInstance, silgi } from "./silgi.mjs";
|
|
11
11
|
import { SilgiError, SilgiErrorCode, SilgiErrorJSON, SilgiErrorOptions, isDefinedError, isSilgiError, toSilgiError } from "./core/error.mjs";
|
|
12
|
-
import { DomainErrorMapper, mapDomainErrors } from "./error-mapper.mjs";
|
|
13
|
-
import { GuardDeps, GuardMap, RouteKit, RouteKitDeps, defineRouteKit } from "./route-kit.mjs";
|
|
14
12
|
import { BaseContext } from "./core/context.mjs";
|
|
15
13
|
import { AsyncIteratorClass, mapAsyncIterator } from "./core/iterator.mjs";
|
|
16
14
|
import { EventMeta, getEventMeta, withEventMeta } from "./core/sse.mjs";
|
|
@@ -20,4 +18,4 @@ import { mapInput } from "./map-input.mjs";
|
|
|
20
18
|
import { compileProcedure, compileRouter, createContext } from "./compile.mjs";
|
|
21
19
|
import { ProcedureSummary, collectProcedures, getProcedurePaths, isProcedureDef } from "./core/router-utils.mjs";
|
|
22
20
|
import { LazyRouter, isLazy, lazy, resolveLazy } from "./lazy.mjs";
|
|
23
|
-
export { type AnySchema, AsyncIteratorClass, type BaseContext, type CallableOptions, type ContextBridge, type ConvertOptions, type
|
|
21
|
+
export { type AnySchema, AsyncIteratorClass, type BaseContext, type CallableOptions, type ContextBridge, type ConvertOptions, type Driver, type ErrorDef, type ErrorDefItem, type EventMeta, type FailFn, type GuardDef, type GuardFn, type InferClient, type InferContextFromUse, type InferGuardOutput, type InferSchemaInput, type InferSchemaOutput, type JSONSchema, type LazyRouter, type LifecycleHooks, type Meta, type MiddlewareDef, type ProcedureBuilder, type ProcedureBuilderWithOutput, type ProcedureDef, type ProcedureSummary, type ProcedureType, type ResolveContext, type RouterDef, type ScalarOptions, type ScheduledTaskInfo, type Schema, type SchemaConverter, type SchemaRegistry, type ServeOptions, type SilgiConfig, SilgiError, type SilgiErrorCode, type SilgiErrorJSON, type SilgiErrorOptions, type SilgiInstance, type SilgiServer, type Storage, type StorageConfig, type StorageValue, type TaskDef, type TaskEvent, ValidationError, type WrapDef, type WrapFn, callable, collectCronTasks, collectProcedures, compileProcedure, compileRouter, createContext, createContextBridge, createSchemaRegistry, generateOpenAPI, getEventMeta, getProcedurePaths, getScheduledTasks, initStorage, isDefinedError, isLazy, isProcedureDef, isSilgiError, lazy, lifecycleWrap, mapAsyncIterator, mapInput, resetStorage, resolveLazy, runTask, scalarHTML, schemaToJsonSchema, setTaskAnalytics, silgi, startCronJobs, stopCronJobs, toSilgiError, type, useStorage, validateSchema, withEventMeta };
|
package/dist/index.mjs
CHANGED
|
@@ -8,12 +8,10 @@ import { AsyncIteratorClass, mapAsyncIterator } from "./core/iterator.mjs";
|
|
|
8
8
|
import { getEventMeta, withEventMeta } from "./core/sse.mjs";
|
|
9
9
|
import { createSchemaRegistry, schemaToJsonSchema } from "./core/schema-converter.mjs";
|
|
10
10
|
import { silgi } from "./silgi.mjs";
|
|
11
|
-
import { mapDomainErrors } from "./error-mapper.mjs";
|
|
12
|
-
import { defineRouteKit } from "./route-kit.mjs";
|
|
13
11
|
import { callable } from "./callable.mjs";
|
|
14
12
|
import { lifecycleWrap } from "./lifecycle.mjs";
|
|
15
13
|
import { mapInput } from "./map-input.mjs";
|
|
16
14
|
import { isLazy, lazy, resolveLazy } from "./lazy.mjs";
|
|
17
15
|
import { initStorage, resetStorage, useStorage } from "./core/storage.mjs";
|
|
18
16
|
import { generateOpenAPI, scalarHTML } from "./scalar.mjs";
|
|
19
|
-
export { AsyncIteratorClass, SilgiError, ValidationError, callable, collectCronTasks, collectProcedures, compileProcedure, compileRouter, createContext, createContextBridge, createSchemaRegistry,
|
|
17
|
+
export { AsyncIteratorClass, SilgiError, ValidationError, callable, collectCronTasks, collectProcedures, compileProcedure, compileRouter, createContext, createContextBridge, createSchemaRegistry, generateOpenAPI, getEventMeta, getProcedurePaths, getScheduledTasks, initStorage, isDefinedError, isLazy, isProcedureDef, isSilgiError, lazy, lifecycleWrap, mapAsyncIterator, mapInput, resetStorage, resolveLazy, runTask, scalarHTML, schemaToJsonSchema, setTaskAnalytics, silgi, startCronJobs, stopCronJobs, toSilgiError, type, useStorage, validateSchema, withEventMeta };
|
package/package.json
CHANGED
package/dist/error-mapper.d.mts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { SilgiError } from "./core/error.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/error-mapper.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Map a caught error into a {@link SilgiError}, or return `undefined` to
|
|
6
|
-
* rethrow the original error untouched. `SilgiError` instances always
|
|
7
|
-
* pass through unchanged — the mapper is not invoked for them.
|
|
8
|
-
*/
|
|
9
|
-
type DomainErrorMapper = (error: unknown) => SilgiError | undefined;
|
|
10
|
-
/**
|
|
11
|
-
* Create a resolver wrapper that runs `mapper` on every thrown error.
|
|
12
|
-
*
|
|
13
|
-
* @param mapper - Called with the caught error; return a `SilgiError` to
|
|
14
|
-
* replace it, or `undefined` to rethrow the original.
|
|
15
|
-
* @returns A function that wraps a resolver and applies the mapping.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* const handleErrors = mapDomainErrors((e) => {
|
|
20
|
-
* if (e instanceof MyDomainError) {
|
|
21
|
-
* return new SilgiError(e.code, { status: e.status, message: e.message, defined: true })
|
|
22
|
-
* }
|
|
23
|
-
* })
|
|
24
|
-
*
|
|
25
|
-
* k.$resolve(handleErrors(async ({ input, ctx }) => {
|
|
26
|
-
* return await service.run(input, ctx)
|
|
27
|
-
* }))
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
declare function mapDomainErrors(mapper: DomainErrorMapper): <TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn | Promise<TReturn>) => (...args: TArgs) => Promise<TReturn>;
|
|
31
|
-
//#endregion
|
|
32
|
-
export { DomainErrorMapper, mapDomainErrors };
|
package/dist/error-mapper.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { isSilgiError } from "./core/error.mjs";
|
|
2
|
-
//#region src/error-mapper.ts
|
|
3
|
-
/**
|
|
4
|
-
* mapDomainErrors — convert service-layer errors into SilgiError.
|
|
5
|
-
*
|
|
6
|
-
* @remarks
|
|
7
|
-
* Library service layers typically throw a domain error (no HTTP
|
|
8
|
-
* knowledge), and route handlers convert them to {@link SilgiError}
|
|
9
|
-
* before returning. Writing the same try/catch wrapper in every
|
|
10
|
-
* resolver is boilerplate; `mapDomainErrors` replaces it with a single
|
|
11
|
-
* mapper function that runs on every thrown error.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* class DomainError extends Error {
|
|
16
|
-
* constructor(public code: string, public status: number, message: string) { super(message) }
|
|
17
|
-
* }
|
|
18
|
-
*
|
|
19
|
-
* const toSilgi = mapDomainErrors((e) => {
|
|
20
|
-
* if (e instanceof DomainError) {
|
|
21
|
-
* return new SilgiError(e.code, { status: e.status, message: e.message, defined: true })
|
|
22
|
-
* }
|
|
23
|
-
* })
|
|
24
|
-
*
|
|
25
|
-
* k.$resolve(toSilgi(async ({ input }) => service.doThing(input)))
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
/**
|
|
29
|
-
* Create a resolver wrapper that runs `mapper` on every thrown error.
|
|
30
|
-
*
|
|
31
|
-
* @param mapper - Called with the caught error; return a `SilgiError` to
|
|
32
|
-
* replace it, or `undefined` to rethrow the original.
|
|
33
|
-
* @returns A function that wraps a resolver and applies the mapping.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* const handleErrors = mapDomainErrors((e) => {
|
|
38
|
-
* if (e instanceof MyDomainError) {
|
|
39
|
-
* return new SilgiError(e.code, { status: e.status, message: e.message, defined: true })
|
|
40
|
-
* }
|
|
41
|
-
* })
|
|
42
|
-
*
|
|
43
|
-
* k.$resolve(handleErrors(async ({ input, ctx }) => {
|
|
44
|
-
* return await service.run(input, ctx)
|
|
45
|
-
* }))
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
function mapDomainErrors(mapper) {
|
|
49
|
-
return function wrap(fn) {
|
|
50
|
-
return async (...args) => {
|
|
51
|
-
try {
|
|
52
|
-
return await fn(...args);
|
|
53
|
-
} catch (e) {
|
|
54
|
-
if (isSilgiError(e)) throw e;
|
|
55
|
-
const mapped = mapper(e);
|
|
56
|
-
if (mapped) throw mapped;
|
|
57
|
-
throw e;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
//#endregion
|
|
63
|
-
export { mapDomainErrors };
|
package/dist/route-kit.d.mts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { ErrorDef, GuardDef } from "./types.mjs";
|
|
2
|
-
import { SilgiInstance } from "./silgi.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/route-kit.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Shape of a `guards` map passed to a kit route. Each entry declares the
|
|
7
|
-
* context additions that specific guard contributes.
|
|
8
|
-
*/
|
|
9
|
-
type GuardMap = Record<string, Record<string, unknown> | void>;
|
|
10
|
-
/** Convert a `GuardMap` into the deps object shape passed to kit builders. */
|
|
11
|
-
type GuardDeps<TGuards extends GuardMap> = { [K in keyof TGuards]: GuardDef<any, TGuards[K], ErrorDef> };
|
|
12
|
-
/** Deps injected into a kit route builder — the instance plus the typed guards. */
|
|
13
|
-
type RouteKitDeps<TCtx extends Record<string, unknown>, TGuards extends GuardMap> = {
|
|
14
|
-
s: SilgiInstance<TCtx>;
|
|
15
|
-
} & GuardDeps<TGuards>;
|
|
16
|
-
/**
|
|
17
|
-
* Return value of `defineRouteKit<Ctx>()`.
|
|
18
|
-
*
|
|
19
|
-
* @remarks
|
|
20
|
-
* Use {@link RouteKit.route} to declare a single route that depends on a
|
|
21
|
-
* named set of guards. The kit carries no runtime state — it only
|
|
22
|
-
* binds the ctx shape for inference.
|
|
23
|
-
*/
|
|
24
|
-
interface RouteKit<TCtx extends Record<string, unknown>> {
|
|
25
|
-
/**
|
|
26
|
-
* Declare a route factory.
|
|
27
|
-
*
|
|
28
|
-
* @typeParam TGuards - Map of guard name → context additions. Empty by
|
|
29
|
-
* default; pass an explicit shape when the route depends on guards.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* kit.route<{ auth: { user: User } }>()(({ s, auth }) =>
|
|
34
|
-
* s.$use(auth).$resolve(({ ctx }) => ctx.user)
|
|
35
|
-
* )
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
route: <TGuards extends GuardMap = {}>() => <TReturn>(builder: (deps: RouteKitDeps<TCtx, TGuards>) => TReturn) => (deps: RouteKitDeps<TCtx, TGuards>) => TReturn;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Create a context-bound route kit for isolated packages.
|
|
42
|
-
*
|
|
43
|
-
* @typeParam TCtx - Base context shape the server will provide. Flows
|
|
44
|
-
* into every route's resolver through the injected `s` instance.
|
|
45
|
-
*/
|
|
46
|
-
declare function defineRouteKit<TCtx extends Record<string, unknown>>(): RouteKit<TCtx>;
|
|
47
|
-
//#endregion
|
|
48
|
-
export { GuardDeps, GuardMap, RouteKit, RouteKitDeps, defineRouteKit };
|
package/dist/route-kit.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
//#region src/route-kit.ts
|
|
2
|
-
/**
|
|
3
|
-
* Create a context-bound route kit for isolated packages.
|
|
4
|
-
*
|
|
5
|
-
* @typeParam TCtx - Base context shape the server will provide. Flows
|
|
6
|
-
* into every route's resolver through the injected `s` instance.
|
|
7
|
-
*/
|
|
8
|
-
function defineRouteKit() {
|
|
9
|
-
return { route: () => (builder) => builder };
|
|
10
|
-
}
|
|
11
|
-
//#endregion
|
|
12
|
-
export { defineRouteKit };
|