next-action-plus 1.0.2 → 2.0.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/README.md +862 -280
- package/dist/auth/authjs.d.ts +23 -0
- package/dist/auth/authjs.js +18 -0
- package/dist/auth/better-auth.d.ts +34 -0
- package/dist/auth/better-auth.js +17 -0
- package/dist/auth/clerk.d.ts +20 -0
- package/dist/auth/clerk.js +17 -0
- package/dist/auth/iron-session.d.ts +21 -0
- package/dist/auth/iron-session.js +18 -0
- package/dist/auth/kinde.d.ts +25 -0
- package/dist/auth/kinde.js +19 -0
- package/dist/auth/supabase.d.ts +29 -0
- package/dist/auth/supabase.js +17 -0
- package/dist/auth/workos.d.ts +25 -0
- package/dist/auth/workos.js +17 -0
- package/dist/authorize/casl.d.ts +14 -0
- package/dist/authorize/casl.js +10 -0
- package/dist/authorize/cerbos.d.ts +26 -0
- package/dist/authorize/cerbos.js +10 -0
- package/dist/authorize/openfga.d.ts +20 -0
- package/dist/authorize/openfga.js +10 -0
- package/dist/authorize/oso.d.ts +20 -0
- package/dist/authorize/oso.js +10 -0
- package/dist/authorize/permit.d.ts +14 -0
- package/dist/authorize/permit.js +10 -0
- package/dist/authorize.d.ts +11 -0
- package/dist/authorize.js +2 -0
- package/dist/chunk-2INYDUJR.js +16 -0
- package/dist/chunk-A55FM7D6.js +53 -0
- package/dist/chunk-GFGIJNSY.js +19 -0
- package/dist/chunk-IFAKJ72B.js +16 -0
- package/dist/codemod/bin.js +169 -0
- package/dist/concurrency/lock/memory.d.ts +5 -0
- package/dist/concurrency/lock/memory.js +1 -0
- package/dist/concurrency/lock/postgres.d.ts +9 -0
- package/dist/concurrency/lock/postgres.js +45 -0
- package/dist/concurrency/lock/redis.d.ts +9 -0
- package/dist/concurrency/lock/redis.js +30 -0
- package/dist/concurrency.d.ts +21 -0
- package/dist/concurrency.js +48 -0
- package/dist/conformance.d.ts +29 -0
- package/dist/conformance.js +139 -0
- package/dist/gate.d.ts +17 -0
- package/dist/gate.js +2 -0
- package/dist/i18n/next-intl.d.ts +12 -0
- package/dist/i18n/next-intl.js +11 -0
- package/dist/idempotency.d.ts +12 -0
- package/dist/idempotency.js +28 -0
- package/dist/index-BSA9a_EW.d.ts +22 -0
- package/dist/index-C3Ra6AYj.d.ts +37 -0
- package/dist/index-CZFS0TSh.d.ts +53 -0
- package/dist/index-CuAEDv-H.d.ts +64 -0
- package/dist/index-DJ2Ox9am.d.ts +31 -0
- package/dist/index-DV3R2g7H.d.ts +41 -0
- package/dist/index.d.ts +196 -192
- package/dist/index.js +189 -278
- package/dist/kv/memory.d.ts +5 -0
- package/dist/kv/memory.js +27 -0
- package/dist/kv/redis.d.ts +9 -0
- package/dist/kv/redis.js +23 -0
- package/dist/queue/bullmq.d.ts +18 -0
- package/dist/queue/bullmq.js +14 -0
- package/dist/queue/inngest.d.ts +18 -0
- package/dist/queue/inngest.js +14 -0
- package/dist/queue/qstash.d.ts +19 -0
- package/dist/queue/qstash.js +14 -0
- package/dist/queue/trigger.d.ts +16 -0
- package/dist/queue/trigger.js +11 -0
- package/dist/rate/limit/arcjet.d.ts +19 -0
- package/dist/rate/limit/arcjet.js +15 -0
- package/dist/rate/limit/unkey.d.ts +25 -0
- package/dist/rate/limit/unkey.js +14 -0
- package/dist/rate/limit/upstash.d.ts +18 -0
- package/dist/rate/limit/upstash.js +15 -0
- package/dist/rate/limit.d.ts +12 -0
- package/dist/rate/limit.js +17 -0
- package/dist/react.d.ts +40 -0
- package/dist/react.js +110 -0
- package/dist/security/origin.d.ts +11 -0
- package/dist/security/origin.js +21 -0
- package/dist/security/redact.d.ts +9 -0
- package/dist/security/redact.js +15 -0
- package/dist/security/secret.d.ts +6 -0
- package/dist/security/secret.js +13 -0
- package/dist/spec.d.ts +6 -0
- package/dist/spec.js +1 -0
- package/dist/telemetry/otel.d.ts +11 -0
- package/dist/telemetry/otel.js +25 -0
- package/dist/telemetry/pino.d.ts +12 -0
- package/dist/telemetry/pino.js +18 -0
- package/dist/telemetry/sentry.d.ts +16 -0
- package/dist/telemetry/sentry.js +11 -0
- package/package.json +325 -72
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
type TLockLease = {
|
|
2
|
+
readonly token: number;
|
|
3
|
+
readonly release: () => Promise<void>;
|
|
4
|
+
readonly extend: (props: Readonly<{
|
|
5
|
+
ms: number;
|
|
6
|
+
}>) => Promise<boolean>;
|
|
7
|
+
};
|
|
8
|
+
type TLock = {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly version?: 1;
|
|
11
|
+
readonly acquire: (props: Readonly<{
|
|
12
|
+
key: string;
|
|
13
|
+
leaseMs: number;
|
|
14
|
+
waitMs: number;
|
|
15
|
+
}>) => Promise<TLockLease | null>;
|
|
16
|
+
readonly generation: (props: Readonly<{
|
|
17
|
+
key: string;
|
|
18
|
+
bump?: boolean;
|
|
19
|
+
}>) => Promise<number>;
|
|
20
|
+
};
|
|
21
|
+
type TRedisClient = {
|
|
22
|
+
readonly eval: (props: Readonly<{
|
|
23
|
+
script: string;
|
|
24
|
+
keys: string[];
|
|
25
|
+
args: Array<string | number>;
|
|
26
|
+
}>) => Promise<unknown>;
|
|
27
|
+
};
|
|
28
|
+
type TPostgresClient = {
|
|
29
|
+
readonly query: (props: Readonly<{
|
|
30
|
+
text: string;
|
|
31
|
+
values: unknown[];
|
|
32
|
+
}>) => Promise<{
|
|
33
|
+
rows: Array<Record<string, unknown>>;
|
|
34
|
+
}>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type { TLock as T, TLockLease as a, TPostgresClient as b, TRedisClient as c };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { c as TMiddlewareShape, a as TMiddlewareProps } from './index-DV3R2g7H.js';
|
|
2
|
+
|
|
3
|
+
type TPluginCall<Shape extends TMiddlewareShape = TMiddlewareShape> = Omit<TMiddlewareProps<Shape>, 'next' | 'errors'>;
|
|
4
|
+
type TPluginRead<Value, Shape extends TMiddlewareShape = TMiddlewareShape> = (props: TPluginCall<Shape>) => Value | Promise<Value>;
|
|
5
|
+
type TPluginShape<Ctx extends object> = {
|
|
6
|
+
input: unknown;
|
|
7
|
+
args: readonly unknown[];
|
|
8
|
+
ctx: Ctx;
|
|
9
|
+
meta: object;
|
|
10
|
+
errors: {};
|
|
11
|
+
};
|
|
12
|
+
type TRateLimiter = {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly version?: 1;
|
|
15
|
+
readonly limit: (props: Readonly<{
|
|
16
|
+
key: string;
|
|
17
|
+
cost: number;
|
|
18
|
+
}>) => Promise<{
|
|
19
|
+
success: boolean;
|
|
20
|
+
retryAfterMs?: number;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
type TQueue = {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly version?: 1;
|
|
26
|
+
readonly enqueue: (props: Readonly<{
|
|
27
|
+
name: string;
|
|
28
|
+
payload: unknown;
|
|
29
|
+
dedupe?: {
|
|
30
|
+
id: string;
|
|
31
|
+
};
|
|
32
|
+
delayMs?: number;
|
|
33
|
+
}>) => Promise<{
|
|
34
|
+
id: string;
|
|
35
|
+
}>;
|
|
36
|
+
};
|
|
37
|
+
type TTelemetrySpan = {
|
|
38
|
+
setAttribute: (key: string, value: string | number | boolean) => unknown;
|
|
39
|
+
setStatus: (status: {
|
|
40
|
+
code: number;
|
|
41
|
+
message?: string;
|
|
42
|
+
}) => unknown;
|
|
43
|
+
recordException: (exception: Error) => unknown;
|
|
44
|
+
end: () => void;
|
|
45
|
+
};
|
|
46
|
+
type TGateCheck<User> = (props: Readonly<{
|
|
47
|
+
user: User;
|
|
48
|
+
ctx: object;
|
|
49
|
+
meta: object;
|
|
50
|
+
input: unknown;
|
|
51
|
+
}>) => boolean | Promise<boolean>;
|
|
52
|
+
|
|
53
|
+
export type { TGateCheck as T, TPluginCall as a, TPluginRead as b, TPluginShape as c, TQueue as d, TRateLimiter as e, TTelemetrySpan as f };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
type TSchemaIssue = {
|
|
2
|
+
readonly message: string;
|
|
3
|
+
readonly path?: ReadonlyArray<PropertyKey | {
|
|
4
|
+
readonly key: PropertyKey;
|
|
5
|
+
}> | undefined;
|
|
6
|
+
};
|
|
7
|
+
type TSchemaResult<Output> = {
|
|
8
|
+
readonly value: Output;
|
|
9
|
+
readonly issues?: undefined;
|
|
10
|
+
} | {
|
|
11
|
+
readonly issues: ReadonlyArray<TSchemaIssue>;
|
|
12
|
+
};
|
|
13
|
+
type TSchema<Input = unknown, Output = Input> = {
|
|
14
|
+
readonly '~standard': {
|
|
15
|
+
readonly version: 1;
|
|
16
|
+
readonly vendor: string;
|
|
17
|
+
readonly validate: (value: unknown, options?: {
|
|
18
|
+
readonly libraryOptions?: Record<string, unknown>;
|
|
19
|
+
} | undefined) => TSchemaResult<Output> | Promise<TSchemaResult<Output>>;
|
|
20
|
+
readonly types?: {
|
|
21
|
+
readonly input: Input;
|
|
22
|
+
readonly output: Output;
|
|
23
|
+
} | undefined;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
type TSchemaInput<S> = S extends TSchema ? NonNullable<S['~standard']['types']>['input'] : unknown;
|
|
27
|
+
type TSchemaOutput<S> = S extends TSchema ? NonNullable<S['~standard']['types']>['output'] : unknown;
|
|
28
|
+
|
|
29
|
+
type TErrorCode = 'VALIDATION' | 'UNAUTHORIZED' | 'FORBIDDEN' | 'NOT_FOUND' | 'CONFLICT' | 'RATE_LIMITED' | 'DROPPED' | 'SUPERSEDED' | 'LOCK_TIMEOUT' | 'TIMEOUT' | 'ABORTED' | 'LIMIT' | 'STALE_ACTION' | 'INTERNAL';
|
|
30
|
+
type TErrorPhase = 'limit' | 'validation' | 'middleware' | 'handler' | 'output';
|
|
31
|
+
type TErrorIssue = {
|
|
32
|
+
path: Array<string | number>;
|
|
33
|
+
message: string;
|
|
34
|
+
};
|
|
35
|
+
type TError<Code extends string = string, Data = unknown> = Error & {
|
|
36
|
+
readonly code: Code;
|
|
37
|
+
readonly status: number;
|
|
38
|
+
readonly phase: TErrorPhase | undefined;
|
|
39
|
+
readonly issues: TErrorIssue[];
|
|
40
|
+
readonly data: Data;
|
|
41
|
+
readonly correlationId: string | undefined;
|
|
42
|
+
readonly expose: boolean;
|
|
43
|
+
};
|
|
44
|
+
type TErrorDefinition = {
|
|
45
|
+
readonly status?: number;
|
|
46
|
+
readonly message?: string;
|
|
47
|
+
readonly data?: TSchema;
|
|
48
|
+
};
|
|
49
|
+
type TErrorMap = Record<string, TErrorDefinition>;
|
|
50
|
+
type TErrorUnion<Map extends TErrorMap> = TError<TErrorCode, undefined> | {
|
|
51
|
+
[K in keyof Map & string]: TError<K, Map[K]['data'] extends TSchema ? TSchemaOutput<Map[K]['data']> : undefined>;
|
|
52
|
+
}[keyof Map & string];
|
|
53
|
+
type TErrorFactories<Map extends TErrorMap> = {
|
|
54
|
+
readonly [K in keyof Map & string]: Map[K]['data'] extends TSchema ? (props: Readonly<{
|
|
55
|
+
data: TSchemaInput<Map[K]['data']>;
|
|
56
|
+
message?: string;
|
|
57
|
+
cause?: unknown;
|
|
58
|
+
}>) => TError<K, TSchemaOutput<Map[K]['data']>> : (props?: Readonly<{
|
|
59
|
+
message?: string;
|
|
60
|
+
cause?: unknown;
|
|
61
|
+
}>) => TError<K, undefined>;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type { TSchema as T, TSchemaInput as a, TSchemaIssue as b, TSchemaOutput as c, TSchemaResult as d, TError as e, TErrorCode as f, TErrorDefinition as g, TErrorFactories as h, TErrorIssue as i, TErrorMap as j, TErrorPhase as k, TErrorUnion as l };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { e as TError } from './index-CuAEDv-H.js';
|
|
2
|
+
|
|
3
|
+
interface TResponseLambda {
|
|
4
|
+
readonly data: unknown;
|
|
5
|
+
readonly error: unknown;
|
|
6
|
+
readonly out: unknown;
|
|
7
|
+
}
|
|
8
|
+
type TResponseApply<Lambda extends TResponseLambda, Data, Error> = (Lambda & {
|
|
9
|
+
readonly data: Data;
|
|
10
|
+
readonly error: Error;
|
|
11
|
+
})['out'];
|
|
12
|
+
type TResponseInfo = {
|
|
13
|
+
readonly meta: Record<string, unknown>;
|
|
14
|
+
readonly correlationId: string;
|
|
15
|
+
};
|
|
16
|
+
type TResponse<Lambda extends TResponseLambda = TResponseLambda> = {
|
|
17
|
+
readonly '~lambda'?: Lambda;
|
|
18
|
+
readonly success: (props: Readonly<{
|
|
19
|
+
data: unknown;
|
|
20
|
+
info: TResponseInfo;
|
|
21
|
+
}>) => unknown;
|
|
22
|
+
readonly failure: (props: Readonly<{
|
|
23
|
+
error: TError;
|
|
24
|
+
info: TResponseInfo;
|
|
25
|
+
}>) => unknown;
|
|
26
|
+
readonly ok: (props: Readonly<{
|
|
27
|
+
result: unknown;
|
|
28
|
+
}>) => boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type { TResponse as T, TResponseApply as a, TResponseInfo as b, TResponseLambda as c };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { j as TErrorMap, h as TErrorFactories, e as TError } from './index-CuAEDv-H.js';
|
|
2
|
+
|
|
3
|
+
type TMiddlewareResult<Ctx = {}> = {
|
|
4
|
+
readonly '~result': true;
|
|
5
|
+
readonly '~ctx'?: Ctx;
|
|
6
|
+
} & ({
|
|
7
|
+
readonly ok: true;
|
|
8
|
+
readonly data: unknown;
|
|
9
|
+
readonly input: unknown;
|
|
10
|
+
} | {
|
|
11
|
+
readonly ok: false;
|
|
12
|
+
readonly error: TError;
|
|
13
|
+
readonly input: unknown;
|
|
14
|
+
});
|
|
15
|
+
type TMiddlewareShape = {
|
|
16
|
+
input: unknown;
|
|
17
|
+
args: readonly unknown[];
|
|
18
|
+
ctx: object;
|
|
19
|
+
meta: object;
|
|
20
|
+
errors: TErrorMap;
|
|
21
|
+
};
|
|
22
|
+
type TMiddlewareProps<Shape extends TMiddlewareShape> = Readonly<{
|
|
23
|
+
input: Shape['input'];
|
|
24
|
+
args: Shape['args'];
|
|
25
|
+
ctx: Readonly<Shape['ctx']>;
|
|
26
|
+
meta: Readonly<Shape['meta']>;
|
|
27
|
+
errors: TErrorFactories<Shape['errors']>;
|
|
28
|
+
next: <Ctx extends object = {}>(props?: Readonly<{
|
|
29
|
+
ctx?: Ctx;
|
|
30
|
+
}>) => Promise<TMiddlewareResult<Ctx>>;
|
|
31
|
+
}>;
|
|
32
|
+
type TMiddleware<Shape extends TMiddlewareShape = TMiddlewareShape, Ctx extends object = {}> = (props: TMiddlewareProps<Shape>) => Promise<TMiddlewareResult<Ctx>>;
|
|
33
|
+
type TPlugin<Shape extends TMiddlewareShape = TMiddlewareShape, Ctx extends object = {}, Errors extends TErrorMap = {}, Gate extends boolean = false> = {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly version?: 1;
|
|
36
|
+
readonly gate?: Gate;
|
|
37
|
+
readonly errors?: Errors;
|
|
38
|
+
readonly run: TMiddleware<Shape, Ctx>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type { TMiddleware as T, TMiddlewareProps as a, TMiddlewareResult as b, TMiddlewareShape as c, TPlugin as d };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,214 +1,218 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { e as TError, T as TSchema, j as TErrorMap, c as TSchemaOutput, a as TSchemaInput, h as TErrorFactories, l as TErrorUnion, k as TErrorPhase, i as TErrorIssue } from './index-CuAEDv-H.js';
|
|
2
|
+
export { f as TErrorCode, g as TErrorDefinition, b as TSchemaIssue, d as TSchemaResult } from './index-CuAEDv-H.js';
|
|
3
|
+
import { T as TMiddleware, d as TPlugin } from './index-DV3R2g7H.js';
|
|
4
|
+
export { a as TMiddlewareProps, b as TMiddlewareResult, c as TMiddlewareShape } from './index-DV3R2g7H.js';
|
|
5
|
+
import { T as TResponse, c as TResponseLambda, a as TResponseApply } from './index-DJ2Ox9am.js';
|
|
6
|
+
export { b as TResponseInfo } from './index-DJ2Ox9am.js';
|
|
2
7
|
|
|
3
|
-
type TMiddlewareFn<Ctx extends Record<string, unknown> = Record<string, never>, NextCtx extends Record<string, unknown> = Record<string, never>> = (opts: {
|
|
4
|
-
input: unknown;
|
|
5
|
-
ctx: Readonly<Ctx>;
|
|
6
|
-
next: {
|
|
7
|
-
<NC extends Record<string, unknown> = Record<string, never>>(opts?: {
|
|
8
|
-
ctx?: NC;
|
|
9
|
-
}): Promise<Ctx & NC>;
|
|
10
|
-
};
|
|
11
|
-
}) => Promise<Ctx & NextCtx>;
|
|
12
|
-
|
|
13
|
-
type TIsAny<T> = 0 extends 1 & T ? true : false;
|
|
14
|
-
/**
|
|
15
|
-
* Makes a type disappear if it relies on a missing optional dependency.
|
|
16
|
-
*
|
|
17
|
-
* In practice this is used with `zod` as a peer dependency.
|
|
18
|
-
*/
|
|
19
|
-
type TIfInstalled<T> = TIsAny<T> extends true ? never : T;
|
|
20
8
|
type TPrettify<T> = {
|
|
21
9
|
[K in keyof T]: T[K];
|
|
22
10
|
} & {};
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
type TActionPlusIssue = {
|
|
27
|
-
path: TActionPlusIssuePathSegment[];
|
|
28
|
-
message: string;
|
|
29
|
-
raw?: unknown;
|
|
11
|
+
type TMerge<A, B> = TPrettify<Omit<A, keyof B> & B>;
|
|
12
|
+
type TTypeError<Message extends string> = {
|
|
13
|
+
readonly '~error': Message;
|
|
30
14
|
};
|
|
31
|
-
|
|
32
|
-
type
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
|
|
16
|
+
type TActionDefinition = {
|
|
17
|
+
input: TSchema | undefined;
|
|
18
|
+
args: readonly TSchema[];
|
|
19
|
+
output: TSchema | undefined;
|
|
20
|
+
ctx: object;
|
|
21
|
+
meta: object;
|
|
22
|
+
errors: TErrorMap;
|
|
23
|
+
response: TResponseLambda | undefined;
|
|
24
|
+
gate: 'required' | 'optional' | 'satisfied';
|
|
39
25
|
};
|
|
40
|
-
type
|
|
41
|
-
|
|
42
|
-
|
|
26
|
+
type TActionLimit = {
|
|
27
|
+
depth?: number;
|
|
28
|
+
keys?: number;
|
|
29
|
+
string?: number;
|
|
30
|
+
array?: number;
|
|
31
|
+
file?: {
|
|
32
|
+
size?: number;
|
|
33
|
+
};
|
|
43
34
|
};
|
|
44
|
-
type
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*/
|
|
51
|
-
logger?: false | {
|
|
35
|
+
type TActionOptions = {
|
|
36
|
+
gate?: {
|
|
37
|
+
required?: boolean;
|
|
38
|
+
};
|
|
39
|
+
response?: TResponse<any>;
|
|
40
|
+
log?: false | {
|
|
52
41
|
error: (...args: unknown[]) => void;
|
|
53
42
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* Customize the thrown error when validation fails.
|
|
60
|
-
* The returned Error will be thrown.
|
|
61
|
-
*/
|
|
62
|
-
formatValidationError?: (ctx: TActionPlusValidationErrorContext) => Error;
|
|
63
|
-
/**
|
|
64
|
-
* Customize the thrown error for non-validation failures.
|
|
65
|
-
* If omitted, the original error is re-thrown.
|
|
66
|
-
*/
|
|
67
|
-
formatError?: (ctx: TActionPlusUnknownErrorContext) => Error;
|
|
68
|
-
/**
|
|
69
|
-
* When enabled, include `input`, `parsedInput`, and `ctx` in error details.
|
|
70
|
-
* Off by default because it can accidentally expose sensitive data.
|
|
71
|
-
*/
|
|
72
|
-
includeInputInErrorDetails?: boolean;
|
|
73
|
-
};
|
|
74
|
-
declare class ActionPlusError extends Error {
|
|
75
|
-
code: TActionPlusErrorCode;
|
|
76
|
-
phase?: TActionPlusErrorPhase;
|
|
77
|
-
data?: unknown;
|
|
78
|
-
cause?: unknown;
|
|
79
|
-
constructor(message: string, opts?: {
|
|
80
|
-
code: TActionPlusErrorCode;
|
|
81
|
-
phase?: TActionPlusErrorPhase;
|
|
82
|
-
cause?: unknown;
|
|
83
|
-
data?: unknown;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
declare class ActionPlusValidationError extends ActionPlusError {
|
|
87
|
-
issues: TActionPlusIssue[];
|
|
88
|
-
constructor(message: string, opts: {
|
|
89
|
-
issues: TActionPlusIssue[];
|
|
90
|
-
phase?: TActionPlusErrorPhase;
|
|
91
|
-
cause?: unknown;
|
|
92
|
-
data?: unknown;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
declare const isActionPlusError: (error: unknown) => error is ActionPlusError;
|
|
96
|
-
declare const isActionPlusValidationError: (error: unknown) => error is ActionPlusValidationError;
|
|
97
|
-
|
|
98
|
-
type TGenericSchema = {
|
|
99
|
-
parse: (input: unknown) => unknown;
|
|
100
|
-
safeParse?: (input: unknown) => {
|
|
101
|
-
success: boolean;
|
|
102
|
-
data?: unknown;
|
|
103
|
-
error?: unknown;
|
|
43
|
+
limit?: false | TActionLimit;
|
|
44
|
+
error?: {
|
|
45
|
+
message?: (props: Readonly<{
|
|
46
|
+
error: TError;
|
|
47
|
+
}>) => string | Promise<string>;
|
|
104
48
|
};
|
|
105
49
|
};
|
|
106
|
-
type
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
50
|
+
type TActionState = {
|
|
51
|
+
options: TActionOptions;
|
|
52
|
+
steps: Array<{
|
|
53
|
+
kind: 'input';
|
|
54
|
+
schema: TSchema;
|
|
55
|
+
} | {
|
|
56
|
+
kind: 'use';
|
|
57
|
+
plugin: TPlugin<any, any, any, any>;
|
|
112
58
|
}>;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
readonly input: Input;
|
|
122
|
-
readonly output: Output;
|
|
123
|
-
} | undefined;
|
|
59
|
+
args: readonly TSchema[];
|
|
60
|
+
output: TSchema | undefined;
|
|
61
|
+
meta: Record<string, unknown>;
|
|
62
|
+
errors: TErrorMap;
|
|
63
|
+
response: TResponse | undefined;
|
|
64
|
+
gate: {
|
|
65
|
+
required: boolean;
|
|
66
|
+
satisfied: boolean;
|
|
124
67
|
};
|
|
125
68
|
};
|
|
126
|
-
type
|
|
127
|
-
readonly
|
|
69
|
+
type TActionArgs<A extends readonly TSchema[], Side extends 'input' | 'output'> = {
|
|
70
|
+
-readonly [K in keyof A]: Side extends 'input' ? TSchemaInput<A[K]> : TSchemaOutput<A[K]>;
|
|
128
71
|
};
|
|
129
|
-
type
|
|
130
|
-
|
|
131
|
-
|
|
72
|
+
type TActionShape<D extends TActionDefinition> = {
|
|
73
|
+
input: D['input'] extends TSchema ? TSchemaOutput<D['input']> : unknown;
|
|
74
|
+
args: TActionArgs<D['args'], 'output'>;
|
|
75
|
+
ctx: TPrettify<D['ctx']>;
|
|
76
|
+
meta: TPrettify<D['meta']>;
|
|
77
|
+
errors: D['errors'];
|
|
132
78
|
};
|
|
133
|
-
type
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
79
|
+
type TActionHandlerProps<D extends TActionDefinition> = Readonly<{
|
|
80
|
+
input: TActionShape<D>['input'];
|
|
81
|
+
args: TActionShape<D>['args'];
|
|
82
|
+
ctx: Readonly<TPrettify<D['ctx']>>;
|
|
83
|
+
meta: Readonly<TPrettify<D['meta']>>;
|
|
84
|
+
errors: TErrorFactories<D['errors']>;
|
|
85
|
+
}>;
|
|
86
|
+
type TActionData<D extends TActionDefinition, Output> = D['output'] extends TSchema ? TSchemaOutput<D['output']> : Output;
|
|
87
|
+
type TActionResult<D extends TActionDefinition, Output> = D['response'] extends TResponseLambda ? TResponseApply<D['response'], TActionData<D, Output>, TErrorUnion<D['errors']>> : TActionData<D, Output>;
|
|
88
|
+
type TActionParams<D extends TActionDefinition> = [
|
|
89
|
+
...TActionArgs<D['args'], 'input'>,
|
|
90
|
+
...(D['input'] extends TSchema ? (undefined extends TSchemaInput<D['input']> ? [input?: TSchemaInput<D['input']> | FormData] : [input: TSchemaInput<D['input']> | FormData]) : [input?: unknown])
|
|
91
|
+
];
|
|
92
|
+
type TActionFunction<D extends TActionDefinition, Output> = (...params: TActionParams<D>) => Promise<TActionResult<D, Output>>;
|
|
93
|
+
type TActionHandler<D extends TActionDefinition, Output, Extra = {}> = (props: TPrettify<TActionHandlerProps<D> & Extra>) => Promise<D['output'] extends TSchema ? TSchemaInput<D['output']> : Output>;
|
|
94
|
+
type TActionGateCheck<D extends TActionDefinition> = D['gate'] extends 'required' ? TTypeError<'This action has no gate: add an auth plugin with .use(...) or call .public()'> : unknown;
|
|
95
|
+
type TActionBuilder<D extends TActionDefinition> = {
|
|
96
|
+
readonly input: <const S extends TSchema>(this: D['input'] extends undefined ? unknown : TTypeError<'.input() is already set for this action'>, schema: S) => TActionBuilder<TMerge<D, {
|
|
97
|
+
input: S;
|
|
98
|
+
}>>;
|
|
99
|
+
readonly args: <const A extends readonly TSchema[]>(schemas: A) => TActionBuilder<TMerge<D, {
|
|
100
|
+
args: A;
|
|
101
|
+
}>>;
|
|
102
|
+
readonly output: <const S extends TSchema>(schema: S) => TActionBuilder<TMerge<D, {
|
|
103
|
+
output: S;
|
|
104
|
+
}>>;
|
|
105
|
+
readonly meta: <const M extends Record<string, unknown>>(meta: M) => TActionBuilder<TMerge<D, {
|
|
106
|
+
meta: TMerge<D['meta'], M>;
|
|
107
|
+
}>>;
|
|
108
|
+
readonly errors: <const E extends TErrorMap>(errors: E) => TActionBuilder<TMerge<D, {
|
|
109
|
+
errors: TMerge<D['errors'], E>;
|
|
110
|
+
}>>;
|
|
111
|
+
readonly use: {
|
|
112
|
+
<C extends object = {}>(middleware: TMiddleware<TActionShape<D>, C>): TActionBuilder<TMerge<D, {
|
|
113
|
+
ctx: TMerge<D['ctx'], C>;
|
|
114
|
+
}>>;
|
|
115
|
+
<C extends object = {}, E extends TErrorMap = {}, G extends boolean = false>(plugin: TPlugin<TActionShape<D>, C, E, G>): TActionBuilder<TMerge<D, {
|
|
116
|
+
ctx: TMerge<D['ctx'], C>;
|
|
117
|
+
errors: TMerge<D['errors'], E>;
|
|
118
|
+
gate: G extends true ? 'satisfied' : D['gate'];
|
|
119
|
+
}>>;
|
|
120
|
+
};
|
|
121
|
+
readonly response: <L extends TResponseLambda>(response: TResponse<L>) => TActionBuilder<TMerge<D, {
|
|
122
|
+
response: L;
|
|
123
|
+
}>>;
|
|
124
|
+
readonly public: () => TActionBuilder<TMerge<D, {
|
|
125
|
+
gate: 'satisfied';
|
|
126
|
+
}>>;
|
|
127
|
+
readonly action: <Output>(this: TActionGateCheck<D>, handler: TActionHandler<D, Output>) => TActionFunction<D, Output>;
|
|
128
|
+
readonly actionState: <Output>(this: TActionGateCheck<D>, handler: TActionHandler<D, Output, {
|
|
129
|
+
state: {
|
|
130
|
+
previous: unknown;
|
|
131
|
+
};
|
|
132
|
+
}>) => (...params: [...TActionArgs<D['args'], 'input'>, previous: TActionResult<D, Output> | null | undefined, ...TActionParams<TMerge<D, {
|
|
133
|
+
args: [];
|
|
134
|
+
}>>]) => Promise<TActionResult<D, Output>>;
|
|
139
135
|
};
|
|
140
|
-
type TStandardSchemaV1InferInput<S extends TStandardSchemaV1<any, any>> = S extends TStandardSchemaV1<infer Input, any> ? Input : unknown;
|
|
141
|
-
type TStandardSchemaV1InferOutput<S extends TStandardSchemaV1<any, any>> = S extends TStandardSchemaV1<any, infer Output> ? Output : unknown;
|
|
142
136
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
|
|
137
|
+
declare const actionCreate: <const Required extends boolean = true, Lambda extends TResponseLambda = never>(props?: Omit<TActionOptions, "gate" | "response"> & {
|
|
138
|
+
gate?: {
|
|
139
|
+
required?: Required;
|
|
140
|
+
};
|
|
141
|
+
response?: TResponse<Lambda>;
|
|
142
|
+
}) => TActionBuilder<{
|
|
143
|
+
input: undefined;
|
|
144
|
+
args: [];
|
|
145
|
+
output: undefined;
|
|
146
|
+
ctx: {};
|
|
147
|
+
meta: {};
|
|
148
|
+
errors: {};
|
|
149
|
+
response: [Lambda] extends [never] ? undefined : Lambda;
|
|
150
|
+
gate: Required extends false ? "optional" : "required";
|
|
151
|
+
}>;
|
|
152
|
+
|
|
153
|
+
declare const errorCreate: <Code extends string, Data = undefined>(props: Readonly<{
|
|
154
|
+
code: Code;
|
|
155
|
+
message?: string;
|
|
156
|
+
status?: number;
|
|
157
|
+
phase?: TErrorPhase;
|
|
158
|
+
issues?: TErrorIssue[];
|
|
159
|
+
data?: Data;
|
|
160
|
+
cause?: unknown;
|
|
161
|
+
expose?: boolean;
|
|
162
|
+
correlationId?: string;
|
|
163
|
+
}>) => TError<Code, Data>;
|
|
164
|
+
declare const errorGet: <Code extends string = string>(props: Readonly<{
|
|
165
|
+
error: unknown;
|
|
166
|
+
code?: Code;
|
|
167
|
+
}>) => TError<Code> | undefined;
|
|
168
|
+
|
|
169
|
+
declare const formDecode: (props: Readonly<{
|
|
170
|
+
form: FormData;
|
|
171
|
+
}>) => Record<string, unknown>;
|
|
172
|
+
|
|
173
|
+
declare const schemaParse: <S extends TSchema>(props: Readonly<{
|
|
174
|
+
schema: S;
|
|
175
|
+
value: unknown;
|
|
176
|
+
path?: Array<string | number>;
|
|
177
|
+
}>) => Promise<TSchemaOutput<S>>;
|
|
155
178
|
|
|
156
|
-
declare const
|
|
157
|
-
type TSchemaAvailable = (typeof schemaAvailable)[number];
|
|
158
|
-
type TSchema = TIfInstalled<z.ZodTypeAny> | TIfInstalled<TGenericSchema> | TIfInstalled<TGenericSchemaAsync> | TStandardSchemaV1<any, any>;
|
|
159
|
-
type TInfer<S extends TSchema> = S extends TIfInstalled<z.ZodTypeAny> ? z.infer<S> : S extends TIfInstalled<TGenericSchema> ? ReturnType<S['parse']> : S extends TIfInstalled<TGenericSchemaAsync> ? Awaited<ReturnType<S['parseAsync']>> : S extends TStandardSchemaV1<any, any> ? TStandardSchemaV1InferOutput<S> : never;
|
|
160
|
-
type TInferIn<S extends TSchema> = S extends TIfInstalled<z.ZodTypeAny> ? z.input<S> : S extends TIfInstalled<TGenericSchema> ? Parameters<S['parse']>[0] : S extends TIfInstalled<TGenericSchemaAsync> ? Parameters<S['parseAsync']>[0] : S extends TStandardSchemaV1<any, any> ? TStandardSchemaV1InferInput<S> : never;
|
|
161
|
-
type TInferArray<S extends readonly TSchema[]> = S extends readonly [infer First extends TSchema, ...infer Rest extends TSchema[]] ? [TInfer<First>, ...TInferArray<Rest>] : [];
|
|
162
|
-
type TInferInArray<S extends readonly TSchema[]> = S extends readonly [infer First extends TSchema, ...infer Rest extends TSchema[]] ? [TInferIn<First>, ...TInferInArray<Rest>] : [];
|
|
163
|
-
type TIsFormData<S extends TSchema> = S extends z.ZodTypeAny ? TZodAcceptsFormData<S> : S extends TStandardSchemaV1<infer Input, any> ? (FormData extends Input ? true : false) : false;
|
|
164
|
-
type TFormDataInput<S extends TSchema> = S extends z.ZodTypeAny ? TZodFormDataInput<S> : S extends TStandardSchemaV1<infer Input, any> ? (FormData extends Input ? FormData | TInferIn<S> : TInferIn<S>) : TInferIn<S>;
|
|
165
|
-
type TFormDataCompatibleInput<S extends readonly TSchema[]> = S extends readonly [infer First extends TSchema, ...infer Rest extends TSchema[]] ? (TIsFormData<First> extends true ? FormData : never) | TPrettify<TUnionToIntersection<TInferIn<First>>> | (Rest['length'] extends 0 ? never : TFormDataCompatibleInput<Rest>) : Record<string, never>;
|
|
179
|
+
declare const responseDefine: <Lambda extends TResponseLambda>(props: Omit<TResponse<Lambda>, "~lambda">) => TResponse<Lambda>;
|
|
166
180
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
* @param handler Action handler function
|
|
194
|
-
*/
|
|
195
|
-
action<Output>(handler: (props: {
|
|
196
|
-
parsedInput: Schemas extends (infer S extends TSchema)[] ? TPrettify<TUnionToIntersection<TInfer<S>>> : Record<string, never>;
|
|
197
|
-
ctx: TPrettify<Ctx>;
|
|
198
|
-
}) => Promise<Output>): (input?: Schemas extends [infer S extends TSchema] ? TFormDataInput<S> : Schemas extends (infer _S extends TSchema)[] ? TFormDataCompatibleInput<Schemas> : unknown) => Promise<Output>;
|
|
199
|
-
private normalizeIssuePath;
|
|
200
|
-
private normalizeIssues;
|
|
201
|
-
private formatValidationErrorParts;
|
|
202
|
-
private validateInput;
|
|
203
|
-
private isPlainObject;
|
|
204
|
-
private parseSchema;
|
|
205
|
-
private tryParseSchema;
|
|
206
|
-
private runMiddlewareChain;
|
|
207
|
-
private isValidationError;
|
|
181
|
+
type TResponseError<E> = E extends TError<infer Code, infer Data> ? {
|
|
182
|
+
code: Code;
|
|
183
|
+
message: string;
|
|
184
|
+
issues: E['issues'];
|
|
185
|
+
data: Data;
|
|
186
|
+
correlationId: string | undefined;
|
|
187
|
+
} : never;
|
|
188
|
+
type TResponseTupleOut<Data, Error> = [true, Data] | [false, string, Omit<TResponseError<Error>, 'message'>];
|
|
189
|
+
type TResponseResultOut<Data, Error> = {
|
|
190
|
+
ok: true;
|
|
191
|
+
data: Data;
|
|
192
|
+
} | {
|
|
193
|
+
ok: false;
|
|
194
|
+
error: TResponseError<Error>;
|
|
195
|
+
};
|
|
196
|
+
type TResponseProblemOut<Data, Error> = Data | ({
|
|
197
|
+
type: 'about:blank';
|
|
198
|
+
title: string;
|
|
199
|
+
status: number;
|
|
200
|
+
detail: string;
|
|
201
|
+
} & Omit<TResponseError<Error>, 'message'>);
|
|
202
|
+
interface TResponseTuple extends TResponseLambda {
|
|
203
|
+
readonly out: TResponseTupleOut<this['data'], this['error']>;
|
|
204
|
+
}
|
|
205
|
+
interface TResponseResult extends TResponseLambda {
|
|
206
|
+
readonly out: TResponseResultOut<this['data'], this['error']>;
|
|
208
207
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
208
|
+
interface TResponseProblem extends TResponseLambda {
|
|
209
|
+
readonly out: TResponseProblemOut<this['data'], this['error']>;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
declare const responseTuple: () => TResponse<TResponseTuple>;
|
|
213
|
+
|
|
214
|
+
declare const responseResult: () => TResponse<TResponseResult>;
|
|
215
|
+
|
|
216
|
+
declare const responseProblem: () => TResponse<TResponseProblem>;
|
|
213
217
|
|
|
214
|
-
export {
|
|
218
|
+
export { type TActionBuilder, type TActionData, type TActionDefinition, type TActionFunction, type TActionHandlerProps, type TActionLimit, type TActionOptions, type TActionParams, type TActionResult, type TActionShape, type TActionState, TError, TErrorFactories, TErrorIssue, TErrorMap, TErrorPhase, TErrorUnion, type TMerge, TMiddleware, TPlugin, type TPrettify, TResponse, TResponseApply, type TResponseError, TResponseLambda, type TResponseProblem, type TResponseProblemOut, type TResponseResult, type TResponseResultOut, type TResponseTuple, type TResponseTupleOut, TSchema, TSchemaInput, TSchemaOutput, type TTypeError, actionCreate, errorCreate, errorGet, formDecode, responseDefine, responseProblem, responseResult, responseTuple, schemaParse };
|