@atproto/xrpc-server 0.10.13 → 0.10.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/auth.d.ts +3 -2
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +18 -0
- package/dist/auth.js.map +1 -1
- package/dist/errors.d.ts +7 -14
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +19 -6
- package/dist/errors.js.map +1 -1
- package/dist/server.d.ts +27 -11
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +115 -78
- package/dist/server.js.map +1 -1
- package/dist/stream/frames.d.ts +5 -1
- package/dist/stream/frames.d.ts.map +1 -1
- package/dist/stream/frames.js +32 -5
- package/dist/stream/frames.js.map +1 -1
- package/dist/stream/types.d.ts +18 -44
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/stream/types.js +10 -10
- package/dist/stream/types.js.map +1 -1
- package/dist/types.d.ts +47 -70
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +28 -15
- package/dist/types.js.map +1 -1
- package/dist/util.d.ts +18 -9
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +180 -37
- package/dist/util.js.map +1 -1
- package/package.json +12 -8
- package/src/auth.ts +28 -2
- package/src/errors.ts +23 -7
- package/src/server.ts +307 -111
- package/src/stream/frames.ts +39 -6
- package/src/stream/types.ts +14 -14
- package/src/types.ts +106 -25
- package/src/util.ts +272 -60
- package/tests/_util.ts +62 -5
- package/tests/bodies.test.ts +442 -387
- package/tests/procedures.test.ts +71 -52
- package/tests/queries.test.ts +56 -39
- package/tests/subscriptions.test.ts +234 -221
package/dist/stream/types.d.ts
CHANGED
|
@@ -1,55 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l } from '@atproto/lex-schema';
|
|
2
2
|
export declare enum FrameType {
|
|
3
3
|
Message = 1,
|
|
4
4
|
Error = -1
|
|
5
5
|
}
|
|
6
|
-
export declare const messageFrameHeader:
|
|
7
|
-
op:
|
|
8
|
-
t:
|
|
9
|
-
}, "strip", z.ZodTypeAny, {
|
|
10
|
-
op: FrameType.Message;
|
|
11
|
-
t?: string | undefined;
|
|
12
|
-
}, {
|
|
13
|
-
op: FrameType.Message;
|
|
14
|
-
t?: string | undefined;
|
|
6
|
+
export declare const messageFrameHeader: l.ObjectSchema<{
|
|
7
|
+
readonly op: l.LiteralSchema<FrameType.Message>;
|
|
8
|
+
readonly t: l.OptionalSchema<l.StringSchema<{}>>;
|
|
15
9
|
}>;
|
|
16
|
-
export type MessageFrameHeader =
|
|
17
|
-
export declare const errorFrameHeader:
|
|
18
|
-
op:
|
|
19
|
-
}, "strip", z.ZodTypeAny, {
|
|
20
|
-
op: FrameType.Error;
|
|
21
|
-
}, {
|
|
22
|
-
op: FrameType.Error;
|
|
10
|
+
export type MessageFrameHeader = l.Infer<typeof messageFrameHeader>;
|
|
11
|
+
export declare const errorFrameHeader: l.ObjectSchema<{
|
|
12
|
+
readonly op: l.LiteralSchema<FrameType.Error>;
|
|
23
13
|
}>;
|
|
24
|
-
export declare const errorFrameBody:
|
|
25
|
-
error:
|
|
26
|
-
message:
|
|
27
|
-
}, "strip", z.ZodTypeAny, {
|
|
28
|
-
error: string;
|
|
29
|
-
message?: string | undefined;
|
|
30
|
-
}, {
|
|
31
|
-
error: string;
|
|
32
|
-
message?: string | undefined;
|
|
14
|
+
export declare const errorFrameBody: l.ObjectSchema<{
|
|
15
|
+
readonly error: l.StringSchema<{}>;
|
|
16
|
+
readonly message: l.OptionalSchema<l.StringSchema<{}>>;
|
|
33
17
|
}>;
|
|
34
|
-
export type ErrorFrameHeader =
|
|
18
|
+
export type ErrorFrameHeader = l.Infer<typeof errorFrameHeader>;
|
|
35
19
|
export type ErrorFrameBody<T extends string = string> = {
|
|
36
20
|
error: T;
|
|
37
|
-
} &
|
|
38
|
-
export declare const frameHeader:
|
|
39
|
-
op:
|
|
40
|
-
t:
|
|
41
|
-
}
|
|
42
|
-
op: FrameType.
|
|
43
|
-
t?: string | undefined;
|
|
44
|
-
}, {
|
|
45
|
-
op: FrameType.Message;
|
|
46
|
-
t?: string | undefined;
|
|
47
|
-
}>, z.ZodObject<{
|
|
48
|
-
op: z.ZodLiteral<FrameType.Error>;
|
|
49
|
-
}, "strip", z.ZodTypeAny, {
|
|
50
|
-
op: FrameType.Error;
|
|
51
|
-
}, {
|
|
52
|
-
op: FrameType.Error;
|
|
21
|
+
} & l.Infer<typeof errorFrameBody>;
|
|
22
|
+
export declare const frameHeader: l.UnionSchema<readonly [l.ObjectSchema<{
|
|
23
|
+
readonly op: l.LiteralSchema<FrameType.Message>;
|
|
24
|
+
readonly t: l.OptionalSchema<l.StringSchema<{}>>;
|
|
25
|
+
}>, l.ObjectSchema<{
|
|
26
|
+
readonly op: l.LiteralSchema<FrameType.Error>;
|
|
53
27
|
}>]>;
|
|
54
|
-
export type FrameHeader =
|
|
28
|
+
export type FrameHeader = l.Infer<typeof frameHeader>;
|
|
55
29
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/stream/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/stream/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AAEvC,oBAAY,SAAS;IACnB,OAAO,IAAI;IACX,KAAK,KAAK;CACX;AAED,eAAO,MAAM,kBAAkB;;;EAG7B,CAAA;AACF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAEnE,eAAO,MAAM,gBAAgB;;EAE3B,CAAA;AACF,eAAO,MAAM,cAAc;;;EAGzB,CAAA;AACF,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAC/D,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IAAE,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG,CAAC,CAAC,KAAK,CAC5E,OAAO,cAAc,CACtB,CAAA;AAED,eAAO,MAAM,WAAW;;;;;IAAkD,CAAA;AAC1E,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAA"}
|
package/dist/stream/types.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.frameHeader = exports.errorFrameBody = exports.errorFrameHeader = exports.messageFrameHeader = exports.FrameType = void 0;
|
|
4
|
-
const
|
|
4
|
+
const lex_schema_1 = require("@atproto/lex-schema");
|
|
5
5
|
var FrameType;
|
|
6
6
|
(function (FrameType) {
|
|
7
7
|
FrameType[FrameType["Message"] = 1] = "Message";
|
|
8
8
|
FrameType[FrameType["Error"] = -1] = "Error";
|
|
9
9
|
})(FrameType || (exports.FrameType = FrameType = {}));
|
|
10
|
-
exports.messageFrameHeader =
|
|
11
|
-
op:
|
|
12
|
-
t:
|
|
10
|
+
exports.messageFrameHeader = lex_schema_1.l.object({
|
|
11
|
+
op: lex_schema_1.l.literal(FrameType.Message), // Frame op
|
|
12
|
+
t: lex_schema_1.l.optional(lex_schema_1.l.string()), // Message body type discriminator
|
|
13
13
|
});
|
|
14
|
-
exports.errorFrameHeader =
|
|
15
|
-
op:
|
|
14
|
+
exports.errorFrameHeader = lex_schema_1.l.object({
|
|
15
|
+
op: lex_schema_1.l.literal(FrameType.Error),
|
|
16
16
|
});
|
|
17
|
-
exports.errorFrameBody =
|
|
18
|
-
error:
|
|
19
|
-
message:
|
|
17
|
+
exports.errorFrameBody = lex_schema_1.l.object({
|
|
18
|
+
error: lex_schema_1.l.string(), // Error code
|
|
19
|
+
message: lex_schema_1.l.optional(lex_schema_1.l.string()), // Error message
|
|
20
20
|
});
|
|
21
|
-
exports.frameHeader =
|
|
21
|
+
exports.frameHeader = lex_schema_1.l.union([exports.messageFrameHeader, exports.errorFrameHeader]);
|
|
22
22
|
//# sourceMappingURL=types.js.map
|
package/dist/stream/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/stream/types.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/stream/types.ts"],"names":[],"mappings":";;;AAAA,oDAAuC;AAEvC,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,+CAAW,CAAA;IACX,4CAAU,CAAA;AACZ,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAEY,QAAA,kBAAkB,GAAG,cAAC,CAAC,MAAM,CAAC;IACzC,EAAE,EAAE,cAAC,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,WAAW;IAC7C,CAAC,EAAE,cAAC,CAAC,QAAQ,CAAC,cAAC,CAAC,MAAM,EAAE,CAAC,EAAE,kCAAkC;CAC9D,CAAC,CAAA;AAGW,QAAA,gBAAgB,GAAG,cAAC,CAAC,MAAM,CAAC;IACvC,EAAE,EAAE,cAAC,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC;CAC/B,CAAC,CAAA;AACW,QAAA,cAAc,GAAG,cAAC,CAAC,MAAM,CAAC;IACrC,KAAK,EAAE,cAAC,CAAC,MAAM,EAAE,EAAE,aAAa;IAChC,OAAO,EAAE,cAAC,CAAC,QAAQ,CAAC,cAAC,CAAC,MAAM,EAAE,CAAC,EAAE,gBAAgB;CAClD,CAAC,CAAA;AAMW,QAAA,WAAW,GAAG,cAAC,CAAC,KAAK,CAAC,CAAC,0BAAkB,EAAE,wBAAgB,CAAC,CAAC,CAAA","sourcesContent":["import { l } from '@atproto/lex-schema'\n\nexport enum FrameType {\n Message = 1,\n Error = -1,\n}\n\nexport const messageFrameHeader = l.object({\n op: l.literal(FrameType.Message), // Frame op\n t: l.optional(l.string()), // Message body type discriminator\n})\nexport type MessageFrameHeader = l.Infer<typeof messageFrameHeader>\n\nexport const errorFrameHeader = l.object({\n op: l.literal(FrameType.Error),\n})\nexport const errorFrameBody = l.object({\n error: l.string(), // Error code\n message: l.optional(l.string()), // Error message\n})\nexport type ErrorFrameHeader = l.Infer<typeof errorFrameHeader>\nexport type ErrorFrameBody<T extends string = string> = { error: T } & l.Infer<\n typeof errorFrameBody\n>\n\nexport const frameHeader = l.union([messageFrameHeader, errorFrameHeader])\nexport type FrameHeader = l.Infer<typeof frameHeader>\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IncomingMessage } from 'node:http';
|
|
2
2
|
import { Readable } from 'node:stream';
|
|
3
3
|
import { NextFunction, Request, Response } from 'express';
|
|
4
|
-
import {
|
|
4
|
+
import { l } from '@atproto/lex-schema';
|
|
5
5
|
import { ErrorResult, XRPCError } from './errors';
|
|
6
6
|
import { CalcKeyFn, CalcPointsFn, RateLimiterI } from './rate-limiter';
|
|
7
7
|
export type Awaitable<T> = T | Promise<T>;
|
|
@@ -41,79 +41,39 @@ export type AuthResult = {
|
|
|
41
41
|
credentials: unknown;
|
|
42
42
|
artifacts?: unknown;
|
|
43
43
|
};
|
|
44
|
-
export declare const headersSchema:
|
|
45
|
-
export type Headers =
|
|
46
|
-
export declare const handlerSuccess:
|
|
47
|
-
encoding:
|
|
48
|
-
body:
|
|
49
|
-
headers:
|
|
50
|
-
}, "strip", z.ZodTypeAny, {
|
|
51
|
-
encoding: string;
|
|
52
|
-
body?: any;
|
|
53
|
-
headers?: Record<string, string> | undefined;
|
|
54
|
-
}, {
|
|
55
|
-
encoding: string;
|
|
56
|
-
body?: any;
|
|
57
|
-
headers?: Record<string, string> | undefined;
|
|
44
|
+
export declare const headersSchema: l.DictSchema<l.StringSchema<{}>, l.StringSchema<{}>>;
|
|
45
|
+
export type Headers = l.Infer<typeof headersSchema>;
|
|
46
|
+
export declare const handlerSuccess: l.ObjectSchema<{
|
|
47
|
+
readonly encoding: l.StringSchema<{}>;
|
|
48
|
+
readonly body: l.UnknownSchema;
|
|
49
|
+
readonly headers: l.OptionalSchema<l.DictSchema<l.StringSchema<{}>, l.StringSchema<{}>>>;
|
|
58
50
|
}>;
|
|
59
|
-
export type HandlerSuccess =
|
|
60
|
-
export declare const handlerPipeThroughBuffer:
|
|
61
|
-
encoding:
|
|
62
|
-
buffer:
|
|
63
|
-
headers:
|
|
64
|
-
}, "strip", z.ZodTypeAny, {
|
|
65
|
-
encoding: string;
|
|
66
|
-
buffer: Buffer<ArrayBuffer>;
|
|
67
|
-
headers?: Record<string, string> | undefined;
|
|
68
|
-
}, {
|
|
69
|
-
encoding: string;
|
|
70
|
-
buffer: Buffer<ArrayBuffer>;
|
|
71
|
-
headers?: Record<string, string> | undefined;
|
|
51
|
+
export type HandlerSuccess = l.Infer<typeof handlerSuccess>;
|
|
52
|
+
export declare const handlerPipeThroughBuffer: l.ObjectSchema<{
|
|
53
|
+
readonly encoding: l.StringSchema<{}>;
|
|
54
|
+
readonly buffer: l.CustomSchema<Buffer<ArrayBufferLike>>;
|
|
55
|
+
readonly headers: l.OptionalSchema<l.DictSchema<l.StringSchema<{}>, l.StringSchema<{}>>>;
|
|
72
56
|
}>;
|
|
73
|
-
export type HandlerPipeThroughBuffer =
|
|
74
|
-
export declare const handlerPipeThroughStream:
|
|
75
|
-
encoding:
|
|
76
|
-
stream:
|
|
77
|
-
headers:
|
|
78
|
-
}, "strip", z.ZodTypeAny, {
|
|
79
|
-
encoding: string;
|
|
80
|
-
stream: Readable;
|
|
81
|
-
headers?: Record<string, string> | undefined;
|
|
82
|
-
}, {
|
|
83
|
-
encoding: string;
|
|
84
|
-
stream: Readable;
|
|
85
|
-
headers?: Record<string, string> | undefined;
|
|
57
|
+
export type HandlerPipeThroughBuffer = l.Infer<typeof handlerPipeThroughBuffer>;
|
|
58
|
+
export declare const handlerPipeThroughStream: l.ObjectSchema<{
|
|
59
|
+
readonly encoding: l.StringSchema<{}>;
|
|
60
|
+
readonly stream: l.CustomSchema<Readable>;
|
|
61
|
+
readonly headers: l.OptionalSchema<l.DictSchema<l.StringSchema<{}>, l.StringSchema<{}>>>;
|
|
86
62
|
}>;
|
|
87
|
-
export type HandlerPipeThroughStream =
|
|
88
|
-
export declare const handlerPipeThrough:
|
|
89
|
-
encoding:
|
|
90
|
-
buffer:
|
|
91
|
-
headers:
|
|
92
|
-
}
|
|
93
|
-
encoding:
|
|
94
|
-
|
|
95
|
-
headers
|
|
96
|
-
}, {
|
|
97
|
-
encoding: string;
|
|
98
|
-
buffer: Buffer<ArrayBuffer>;
|
|
99
|
-
headers?: Record<string, string> | undefined;
|
|
100
|
-
}>, z.ZodObject<{
|
|
101
|
-
encoding: z.ZodString;
|
|
102
|
-
stream: z.ZodType<Readable, z.ZodTypeDef, Readable>;
|
|
103
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
104
|
-
}, "strip", z.ZodTypeAny, {
|
|
105
|
-
encoding: string;
|
|
106
|
-
stream: Readable;
|
|
107
|
-
headers?: Record<string, string> | undefined;
|
|
108
|
-
}, {
|
|
109
|
-
encoding: string;
|
|
110
|
-
stream: Readable;
|
|
111
|
-
headers?: Record<string, string> | undefined;
|
|
63
|
+
export type HandlerPipeThroughStream = l.Infer<typeof handlerPipeThroughStream>;
|
|
64
|
+
export declare const handlerPipeThrough: l.UnionSchema<readonly [l.ObjectSchema<{
|
|
65
|
+
readonly encoding: l.StringSchema<{}>;
|
|
66
|
+
readonly buffer: l.CustomSchema<Buffer<ArrayBufferLike>>;
|
|
67
|
+
readonly headers: l.OptionalSchema<l.DictSchema<l.StringSchema<{}>, l.StringSchema<{}>>>;
|
|
68
|
+
}>, l.ObjectSchema<{
|
|
69
|
+
readonly encoding: l.StringSchema<{}>;
|
|
70
|
+
readonly stream: l.CustomSchema<Readable>;
|
|
71
|
+
readonly headers: l.OptionalSchema<l.DictSchema<l.StringSchema<{}>, l.StringSchema<{}>>>;
|
|
112
72
|
}>]>;
|
|
113
|
-
export type HandlerPipeThrough =
|
|
73
|
+
export type HandlerPipeThrough = l.Infer<typeof handlerPipeThrough>;
|
|
114
74
|
export type Auth = void | AuthResult;
|
|
115
75
|
export type Input = void | HandlerInput;
|
|
116
|
-
export type Output = void | HandlerSuccess | ErrorResult;
|
|
76
|
+
export type Output = void | HandlerSuccess | HandlerPipeThrough | ErrorResult;
|
|
117
77
|
export type AuthVerifier<C, A extends AuthResult = AuthResult> = ((ctx: C) => Awaitable<A | ErrorResult>) | ((ctx: C) => Awaitable<A>);
|
|
118
78
|
export type MethodAuthContext<P extends Params = Params> = {
|
|
119
79
|
params: P;
|
|
@@ -161,17 +121,33 @@ export type RouteOptions = {
|
|
|
161
121
|
jsonLimit?: number;
|
|
162
122
|
textLimit?: number;
|
|
163
123
|
};
|
|
124
|
+
export type MethodAuth<A extends Auth = Auth, P extends Params = Params> = MethodAuthVerifier<Extract<A, AuthResult>, P>;
|
|
125
|
+
export type MethodRateLimit<A extends Auth = Auth, P extends Params = Params, I extends Input = Input> = RateLimitOpts<HandlerContext<A, P, I>> | RateLimitOpts<HandlerContext<A, P, I>>[];
|
|
164
126
|
export type MethodConfig<A extends Auth = Auth, P extends Params = Params, I extends Input = Input, O extends Output = Output> = {
|
|
165
127
|
handler: MethodHandler<A, P, I, O>;
|
|
166
|
-
auth?:
|
|
128
|
+
auth?: MethodAuth<A, P>;
|
|
129
|
+
opts?: RouteOptions;
|
|
130
|
+
rateLimit?: MethodRateLimit<A, P, I>;
|
|
131
|
+
};
|
|
132
|
+
export type MethodConfigWithAuth<A extends Auth = Auth, P extends Params = Params, I extends Input = Input, O extends Output = Output> = {
|
|
133
|
+
handler: MethodHandler<A, P, I, O>;
|
|
134
|
+
auth: MethodAuth<A, P>;
|
|
167
135
|
opts?: RouteOptions;
|
|
168
|
-
rateLimit?:
|
|
136
|
+
rateLimit?: MethodRateLimit<A, P, I>;
|
|
169
137
|
};
|
|
170
138
|
export type MethodConfigOrHandler<A extends Auth = Auth, P extends Params = Params, I extends Input = Input, O extends Output = Output> = MethodHandler<A, P, I, O> | MethodConfig<A, P, I, O>;
|
|
171
139
|
export type StreamAuthContext<P extends Params = Params> = {
|
|
172
140
|
params: P;
|
|
173
141
|
req: IncomingMessage;
|
|
174
142
|
};
|
|
143
|
+
export type LexMethodParams<M extends l.Procedure | l.Query | l.Subscription> = l.InferMethodParams<M>;
|
|
144
|
+
export type LexMethodInput<M extends l.Procedure | l.Query> = l.InferMethodInput<M, Readable>;
|
|
145
|
+
export type LexMethodOutput<M extends l.Procedure | l.Query> = l.InferMethodOutput<M, Readable> extends undefined ? l.InferMethodOutput<M, Uint8Array | Readable> | void : l.InferMethodOutput<M, Uint8Array | Readable>;
|
|
146
|
+
export type LexMethodMessage<M extends l.Subscription> = l.InferMethodMessage<M>;
|
|
147
|
+
export type LexMethodHandler<M extends l.Procedure | l.Query, A extends Auth = Auth> = MethodHandler<A, LexMethodParams<M>, LexMethodInput<M>, LexMethodOutput<M>>;
|
|
148
|
+
export type LexMethodConfig<M extends l.Procedure | l.Query, A extends Auth = Auth> = MethodConfig<A, LexMethodParams<M>, LexMethodInput<M>, LexMethodOutput<M>>;
|
|
149
|
+
export type LexSubscriptionHandler<M extends l.Subscription, A extends Auth = Auth> = StreamHandler<Extract<A, AuthResult>, LexMethodParams<M>, LexMethodMessage<M>>;
|
|
150
|
+
export type LexSubscriptionConfig<M extends l.Subscription, A extends Auth = Auth> = StreamConfig<A, LexMethodParams<M>, LexMethodMessage<M>>;
|
|
175
151
|
export type StreamAuthVerifier<A extends AuthResult = AuthResult, P extends Params = Params> = AuthVerifier<StreamAuthContext<P>, A>;
|
|
176
152
|
export type StreamContext<A extends Auth = Auth, P extends Params = Params> = StreamAuthContext<P> & {
|
|
177
153
|
auth: A;
|
|
@@ -183,6 +159,7 @@ export type StreamConfig<A extends Auth = Auth, P extends Params = Params, O = u
|
|
|
183
159
|
handler: StreamHandler<A, P, O>;
|
|
184
160
|
};
|
|
185
161
|
export type StreamConfigOrHandler<A extends Auth = Auth, P extends Params = Params, O = unknown> = StreamHandler<A, P, O> | StreamConfig<A, P, O>;
|
|
162
|
+
export declare function isHandlerSuccess(output: Output): output is HandlerSuccess;
|
|
186
163
|
export declare function isHandlerPipeThroughBuffer(output: Output): output is HandlerPipeThroughBuffer;
|
|
187
164
|
export declare function isHandlerPipeThroughStream(output: Output): output is HandlerPipeThroughStream;
|
|
188
165
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAEtE,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC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AAS,MAAM,GAAG,MAAM,EACzB,CAAC,GAAG,OAAO,IACT,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,CAAC,CAAA;AAElD,MAAM,MAAM,YAAY,CACtB,CAAC,SAAS,IAAI,GAAG,IAAI,EACrB,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,CAAC,GAAG,OAAO,IACT;IACF,IAAI,CAAC,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC,CAAA;IACpD,OAAO,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;CAChC,CAAA;AAED,MAAM,MAAM,qBAAqB,CAC/B,CAAC,SAAS,IAAI,GAAG,IAAI,EACrB,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,CAAC,GAAG,OAAO,IACT,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;AAElD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,cAAc,CAazE;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,GACb,MAAM,IAAI,wBAAwB,CAGpC;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,GACb,MAAM,IAAI,wBAAwB,CAGpC"}
|
package/dist/types.js
CHANGED
|
@@ -2,33 +2,46 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handlerPipeThrough = exports.handlerPipeThroughStream = exports.handlerPipeThroughBuffer = exports.handlerSuccess = exports.headersSchema = void 0;
|
|
4
4
|
exports.isSharedRateLimitOpts = isSharedRateLimitOpts;
|
|
5
|
+
exports.isHandlerSuccess = isHandlerSuccess;
|
|
5
6
|
exports.isHandlerPipeThroughBuffer = isHandlerPipeThroughBuffer;
|
|
6
7
|
exports.isHandlerPipeThroughStream = isHandlerPipeThroughStream;
|
|
7
8
|
const node_stream_1 = require("node:stream");
|
|
8
|
-
const
|
|
9
|
-
exports.headersSchema =
|
|
10
|
-
exports.handlerSuccess =
|
|
11
|
-
encoding:
|
|
12
|
-
body:
|
|
13
|
-
headers:
|
|
9
|
+
const lex_schema_1 = require("@atproto/lex-schema");
|
|
10
|
+
exports.headersSchema = lex_schema_1.l.dict(lex_schema_1.l.string(), lex_schema_1.l.string());
|
|
11
|
+
exports.handlerSuccess = lex_schema_1.l.object({
|
|
12
|
+
encoding: lex_schema_1.l.string(),
|
|
13
|
+
body: lex_schema_1.l.unknown(),
|
|
14
|
+
headers: lex_schema_1.l.optional(exports.headersSchema),
|
|
14
15
|
});
|
|
15
|
-
exports.handlerPipeThroughBuffer =
|
|
16
|
-
encoding:
|
|
17
|
-
buffer:
|
|
18
|
-
headers:
|
|
16
|
+
exports.handlerPipeThroughBuffer = lex_schema_1.l.object({
|
|
17
|
+
encoding: lex_schema_1.l.string(),
|
|
18
|
+
buffer: lex_schema_1.l.custom((v) => v instanceof Buffer, 'Expected a Buffer'),
|
|
19
|
+
headers: lex_schema_1.l.optional(exports.headersSchema),
|
|
19
20
|
});
|
|
20
|
-
exports.handlerPipeThroughStream =
|
|
21
|
-
encoding:
|
|
22
|
-
stream:
|
|
23
|
-
headers:
|
|
21
|
+
exports.handlerPipeThroughStream = lex_schema_1.l.object({
|
|
22
|
+
encoding: lex_schema_1.l.string(),
|
|
23
|
+
stream: lex_schema_1.l.custom((v) => v instanceof node_stream_1.Readable, 'Expected a Readable stream'),
|
|
24
|
+
headers: lex_schema_1.l.optional(exports.headersSchema),
|
|
24
25
|
});
|
|
25
|
-
exports.handlerPipeThrough =
|
|
26
|
+
exports.handlerPipeThrough = lex_schema_1.l.union([
|
|
26
27
|
exports.handlerPipeThroughBuffer,
|
|
27
28
|
exports.handlerPipeThroughStream,
|
|
28
29
|
]);
|
|
29
30
|
function isSharedRateLimitOpts(opts) {
|
|
30
31
|
return typeof opts['name'] === 'string';
|
|
31
32
|
}
|
|
33
|
+
function isHandlerSuccess(output) {
|
|
34
|
+
// We only need to discriminate between possible Output values
|
|
35
|
+
return (output != null &&
|
|
36
|
+
'body' in output && // body is non optional (contrary to what type inference may suggest)
|
|
37
|
+
'encoding' in output &&
|
|
38
|
+
// Allows using objects that extends HandlerSuccess with a "status" field as
|
|
39
|
+
// output, as long as the status is < 400, in order to avoid being confused
|
|
40
|
+
// with ErrorResult objects.
|
|
41
|
+
(!('status' in output) ||
|
|
42
|
+
output.status == null ||
|
|
43
|
+
Number(output.status) < 400));
|
|
44
|
+
}
|
|
32
45
|
function isHandlerPipeThroughBuffer(output) {
|
|
33
46
|
// We only need to discriminate between possible Output values
|
|
34
47
|
return output != null && 'buffer' in output && output['buffer'] !== undefined;
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAmKA,sDAIC;AAoED,gEAKC;AAED,gEAKC;AAtPD,6CAAsC;AAEtC,6BAAuB;AAkDV,QAAA,aAAa,GAAG,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAA;AAIpC,QAAA,cAAc,GAAG,OAAC,CAAC,MAAM,CAAC;IACrC,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;IACpB,IAAI,EAAE,OAAC,CAAC,GAAG,EAAE;IACb,OAAO,EAAE,qBAAa,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAA;AAIW,QAAA,wBAAwB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC/C,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;IACpB,MAAM,EAAE,OAAC,CAAC,UAAU,CAAC,MAAM,CAAC;IAC5B,OAAO,EAAE,qBAAa,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAA;AAIW,QAAA,wBAAwB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC/C,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;IACpB,MAAM,EAAE,OAAC,CAAC,UAAU,CAAC,sBAAQ,CAAC;IAC9B,OAAO,EAAE,qBAAa,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAA;AAIW,QAAA,kBAAkB,GAAG,OAAC,CAAC,KAAK,CAAC;IACxC,gCAAwB;IACxB,gCAAwB;CACzB,CAAC,CAAA;AA+EF,SAAgB,qBAAqB,CAEnC,IAAsB;IACtB,OAAO,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,QAAQ,CAAA;AACzC,CAAC;AAoED,SAAgB,0BAA0B,CACxC,MAAc;IAEd,8DAA8D;IAC9D,OAAO,MAAM,IAAI,IAAI,IAAI,QAAQ,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAA;AAC/E,CAAC;AAED,SAAgB,0BAA0B,CACxC,MAAc;IAEd,8DAA8D;IAC9D,OAAO,MAAM,IAAI,IAAI,IAAI,QAAQ,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAA;AAC/E,CAAC","sourcesContent":["import { IncomingMessage } from 'node:http'\nimport { Readable } from 'node:stream'\nimport { NextFunction, Request, Response } from 'express'\nimport { z } from 'zod'\nimport { ErrorResult, XRPCError } from './errors'\nimport { CalcKeyFn, CalcPointsFn, RateLimiterI } from './rate-limiter'\n\nexport type Awaitable<T> = T | Promise<T>\n\nexport type CatchallHandler = (\n req: Request,\n res: Response,\n next: NextFunction,\n) => unknown\n\nexport type Options = {\n validateResponse?: boolean\n catchall?: CatchallHandler\n payload?: RouteOptions\n rateLimits?: {\n creator: RateLimiterCreator<HandlerContext>\n global?: ServerRateLimitDescription<HandlerContext>[]\n shared?: ServerRateLimitDescription<HandlerContext>[]\n bypass?: (ctx: HandlerContext) => boolean\n }\n /**\n * By default, errors are converted to {@link XRPCError} using\n * {@link XRPCError.fromError} before being rendered. If method handlers throw\n * error objects that are not properly rendered in the HTTP response, this\n * function can be used to properly convert them to {@link XRPCError}. The\n * provided function will typically fallback to the default error conversion\n * (`return XRPCError.fromError(err)`) if the error is not recognized.\n *\n * @note This function should not throw errors.\n */\n errorParser?: (err: unknown) => XRPCError\n}\n\nexport type UndecodedParams = Request['query']\n\nexport type Primitive = string | number | boolean\nexport type Params = { [P in string]?: undefined | Primitive | Primitive[] }\n\nexport type HandlerInput = {\n encoding: string\n body: unknown\n}\n\nexport type AuthResult = {\n credentials: unknown\n artifacts?: unknown\n}\n\nexport const headersSchema = z.record(z.string())\n\nexport type Headers = z.infer<typeof headersSchema>\n\nexport const handlerSuccess = z.object({\n encoding: z.string(),\n body: z.any(),\n headers: headersSchema.optional(),\n})\n\nexport type HandlerSuccess = z.infer<typeof handlerSuccess>\n\nexport const handlerPipeThroughBuffer = z.object({\n encoding: z.string(),\n buffer: z.instanceof(Buffer),\n headers: headersSchema.optional(),\n})\n\nexport type HandlerPipeThroughBuffer = z.infer<typeof handlerPipeThroughBuffer>\n\nexport const handlerPipeThroughStream = z.object({\n encoding: z.string(),\n stream: z.instanceof(Readable),\n headers: headersSchema.optional(),\n})\n\nexport type HandlerPipeThroughStream = z.infer<typeof handlerPipeThroughStream>\n\nexport const handlerPipeThrough = z.union([\n handlerPipeThroughBuffer,\n handlerPipeThroughStream,\n])\n\nexport type HandlerPipeThrough = z.infer<typeof handlerPipeThrough>\n\nexport type Auth = void | AuthResult\nexport type Input = void | HandlerInput\nexport type Output = void | HandlerSuccess | ErrorResult\n\nexport type AuthVerifier<C, A extends AuthResult = AuthResult> =\n | ((ctx: C) => Awaitable<A | ErrorResult>)\n | ((ctx: C) => Awaitable<A>)\n\nexport type MethodAuthContext<P extends Params = Params> = {\n params: P\n req: Request\n res: Response\n}\n\nexport type MethodAuthVerifier<\n A extends AuthResult = AuthResult,\n P extends Params = Params,\n> = AuthVerifier<MethodAuthContext<P>, A>\n\nexport type HandlerContext<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n> = MethodAuthContext<P> & {\n auth: A\n input: I\n resetRouteRateLimits: () => Promise<void>\n}\n\nexport type MethodHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n O extends Output = Output,\n> = (ctx: HandlerContext<A, P, I>) => Awaitable<O | HandlerPipeThrough>\n\nexport type RateLimiterCreator<T extends HandlerContext = HandlerContext> = <\n C extends T = T,\n>(opts: {\n keyPrefix: string\n durationMs: number\n points: number\n calcKey: CalcKeyFn<C>\n calcPoints: CalcPointsFn<C>\n failClosed?: boolean\n}) => RateLimiterI<C>\n\nexport type ServerRateLimitDescription<\n C extends HandlerContext = HandlerContext,\n> = {\n name: string\n durationMs: number\n points: number\n calcKey?: CalcKeyFn<C>\n calcPoints?: CalcPointsFn<C>\n failClosed?: boolean\n}\n\nexport type SharedRateLimitOpts<C extends HandlerContext = HandlerContext> = {\n name: string\n calcKey?: CalcKeyFn<C>\n calcPoints?: CalcPointsFn<C>\n}\n\nexport type RouteRateLimitOpts<C extends HandlerContext = HandlerContext> = {\n durationMs: number\n points: number\n calcKey?: CalcKeyFn<C>\n calcPoints?: CalcPointsFn<C>\n}\n\nexport type RateLimitOpts<C extends HandlerContext = HandlerContext> =\n | SharedRateLimitOpts<C>\n | RouteRateLimitOpts<C>\n\nexport function isSharedRateLimitOpts<\n C extends HandlerContext = HandlerContext,\n>(opts: RateLimitOpts<C>): opts is SharedRateLimitOpts<C> {\n return typeof opts['name'] === 'string'\n}\n\nexport type RouteOptions = {\n blobLimit?: number\n jsonLimit?: number\n textLimit?: number\n}\n\nexport type MethodConfig<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n O extends Output = Output,\n> = {\n handler: MethodHandler<A, P, I, O>\n auth?: MethodAuthVerifier<Extract<A, AuthResult>, P>\n opts?: RouteOptions\n rateLimit?:\n | RateLimitOpts<HandlerContext<A, P, I>>\n | RateLimitOpts<HandlerContext<A, P, I>>[]\n}\n\nexport type MethodConfigOrHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n O extends Output = Output,\n> = MethodHandler<A, P, I, O> | MethodConfig<A, P, I, O>\n\nexport type StreamAuthContext<P extends Params = Params> = {\n params: P\n req: IncomingMessage\n}\n\nexport type StreamAuthVerifier<\n A extends AuthResult = AuthResult,\n P extends Params = Params,\n> = AuthVerifier<StreamAuthContext<P>, A>\n\nexport type StreamContext<\n A extends Auth = Auth,\n P extends Params = Params,\n> = StreamAuthContext<P> & {\n auth: A\n signal: AbortSignal\n}\n\nexport type StreamHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n O = unknown,\n> = (ctx: StreamContext<A, P>) => AsyncIterable<O>\n\nexport type StreamConfig<\n A extends Auth = Auth,\n P extends Params = Params,\n O = unknown,\n> = {\n auth?: StreamAuthVerifier<Extract<A, AuthResult>, P>\n handler: StreamHandler<A, P, O>\n}\n\nexport type StreamConfigOrHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n O = unknown,\n> = StreamHandler<A, P, O> | StreamConfig<A, P, O>\n\nexport function isHandlerPipeThroughBuffer(\n output: Output,\n): output is HandlerPipeThroughBuffer {\n // We only need to discriminate between possible Output values\n return output != null && 'buffer' in output && output['buffer'] !== undefined\n}\n\nexport function isHandlerPipeThroughStream(\n output: Output,\n): output is HandlerPipeThroughStream {\n // We only need to discriminate between possible Output values\n return output != null && 'stream' in output && output['stream'] !== undefined\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAyKA,sDAIC;AAgID,4CAaC;AAED,gEAKC;AAED,gEAKC;AAvUD,6CAAsC;AAEtC,oDAAuC;AAkD1B,QAAA,aAAa,GAAG,cAAC,CAAC,IAAI,CAAC,cAAC,CAAC,MAAM,EAAE,EAAE,cAAC,CAAC,MAAM,EAAE,CAAC,CAAA;AAI9C,QAAA,cAAc,GAAG,cAAC,CAAC,MAAM,CAAC;IACrC,QAA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AM,CAAC,GAAG,GAAG,CAAC,CAC/B,CAAA;AACH,CAAC;AAED,SAAgB,0BAA0B,CACxC,MAAc;IAEd,8DAA8D;IAC9D,OAAO,MAAM,IAAI,IAAI,IAAI,QAAQ,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAA;AAC/E,CAAC;AAED,SAAgB,0BAA0B,CACxC,MAAc;IAEd,8DAA8D;IAC9D,OAAO,MAAM,IAAI,IAAI,IAAI,QAAQ,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAA;AAC/E,CAAC","sourcesContent":["import { IncomingMessage } from 'node:http'\nimport { Readable } from 'node:stream'\nimport { NextFunction, Request, Response } from 'express'\nimport { l } from '@atproto/lex-schema'\nimport { ErrorResult, XRPCError } from './errors'\nimport { CalcKeyFn, CalcPointsFn, RateLimiterI } from './rate-limiter'\n\nexport type Awaitable<T> = T | Promise<T>\n\nexport type CatchallHandler = (\n req: Request,\n res: Response,\n next: NextFunction,\n) => unknown\n\nexport type Options = {\n validateResponse?: boolean\n catchall?: CatchallHandler\n payload?: RouteOptions\n rateLimits?: {\n creator: RateLimiterCreator<HandlerContext>\n global?: ServerRateLimitDescription<HandlerContext>[]\n shared?: ServerRateLimitDescription<HandlerContext>[]\n bypass?: (ctx: HandlerContext) => boolean\n }\n /**\n * By default, errors are converted to {@link XRPCError} using\n * {@link XRPCError.fromError} before being rendered. If method handlers throw\n * error objects that are not properly rendered in the HTTP response, this\n * function can be used to properly convert them to {@link XRPCError}. The\n * provided function will typically fallback to the default error conversion\n * (`return XRPCError.fromError(err)`) if the error is not recognized.\n *\n * @note This function should not throw errors.\n */\n errorParser?: (err: unknown) => XRPCError\n}\n\nexport type UndecodedParams = Request['query']\n\nexport type Primitive = string | number | boolean\nexport type Params = { [P in string]?: undefined | Primitive | Primitive[] }\n\nexport type HandlerInput = {\n encoding: string\n body: unknown\n}\n\nexport type AuthResult = {\n credentials: unknown\n artifacts?: unknown\n}\n\nexport const headersSchema = l.dict(l.string(), l.string())\n\nexport type Headers = l.Infer<typeof headersSchema>\n\nexport const handlerSuccess = l.object({\n encoding: l.string(),\n body: l.unknown(),\n headers: l.optional(headersSchema),\n})\n\nexport type HandlerSuccess = l.Infer<typeof handlerSuccess>\n\nexport const handlerPipeThroughBuffer = l.object({\n encoding: l.string(),\n buffer: l.custom(\n (v): v is Buffer => v instanceof Buffer,\n 'Expected a Buffer',\n ),\n headers: l.optional(headersSchema),\n})\n\nexport type HandlerPipeThroughBuffer = l.Infer<typeof handlerPipeThroughBuffer>\n\nexport const handlerPipeThroughStream = l.object({\n encoding: l.string(),\n stream: l.custom(\n (v): v is Readable => v instanceof Readable,\n 'Expected a Readable stream',\n ),\n headers: l.optional(headersSchema),\n})\n\nexport type HandlerPipeThroughStream = l.Infer<typeof handlerPipeThroughStream>\n\nexport const handlerPipeThrough = l.union([\n handlerPipeThroughBuffer,\n handlerPipeThroughStream,\n])\n\nexport type HandlerPipeThrough = l.Infer<typeof handlerPipeThrough>\n\nexport type Auth = void | AuthResult\nexport type Input = void | HandlerInput\nexport type Output = void | HandlerSuccess | HandlerPipeThrough | ErrorResult\n\nexport type AuthVerifier<C, A extends AuthResult = AuthResult> =\n | ((ctx: C) => Awaitable<A | ErrorResult>)\n | ((ctx: C) => Awaitable<A>)\n\nexport type MethodAuthContext<P extends Params = Params> = {\n params: P\n req: Request\n res: Response\n}\n\nexport type MethodAuthVerifier<\n A extends AuthResult = AuthResult,\n P extends Params = Params,\n> = AuthVerifier<MethodAuthContext<P>, A>\n\nexport type HandlerContext<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n> = MethodAuthContext<P> & {\n auth: A\n input: I\n resetRouteRateLimits: () => Promise<void>\n}\n\nexport type MethodHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n O extends Output = Output,\n> = (ctx: HandlerContext<A, P, I>) => Awaitable<O | HandlerPipeThrough>\n\nexport type RateLimiterCreator<T extends HandlerContext = HandlerContext> = <\n C extends T = T,\n>(opts: {\n keyPrefix: string\n durationMs: number\n points: number\n calcKey: CalcKeyFn<C>\n calcPoints: CalcPointsFn<C>\n failClosed?: boolean\n}) => RateLimiterI<C>\n\nexport type ServerRateLimitDescription<\n C extends HandlerContext = HandlerContext,\n> = {\n name: string\n durationMs: number\n points: number\n calcKey?: CalcKeyFn<C>\n calcPoints?: CalcPointsFn<C>\n failClosed?: boolean\n}\n\nexport type SharedRateLimitOpts<C extends HandlerContext = HandlerContext> = {\n name: string\n calcKey?: CalcKeyFn<C>\n calcPoints?: CalcPointsFn<C>\n}\n\nexport type RouteRateLimitOpts<C extends HandlerContext = HandlerContext> = {\n durationMs: number\n points: number\n calcKey?: CalcKeyFn<C>\n calcPoints?: CalcPointsFn<C>\n}\n\nexport type RateLimitOpts<C extends HandlerContext = HandlerContext> =\n | SharedRateLimitOpts<C>\n | RouteRateLimitOpts<C>\n\nexport function isSharedRateLimitOpts<\n C extends HandlerContext = HandlerContext,\n>(opts: RateLimitOpts<C>): opts is SharedRateLimitOpts<C> {\n return typeof opts['name'] === 'string'\n}\n\nexport type RouteOptions = {\n blobLimit?: number\n jsonLimit?: number\n textLimit?: number\n}\n\nexport type MethodAuth<\n A extends Auth = Auth,\n P extends Params = Params,\n> = MethodAuthVerifier<Extract<A, AuthResult>, P>\n\nexport type MethodRateLimit<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n> =\n | RateLimitOpts<HandlerContext<A, P, I>>\n | RateLimitOpts<HandlerContext<A, P, I>>[]\n\nexport type MethodConfig<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n O extends Output = Output,\n> = {\n handler: MethodHandler<A, P, I, O>\n auth?: MethodAuth<A, P>\n opts?: RouteOptions\n rateLimit?: MethodRateLimit<A, P, I>\n}\n\nexport type MethodConfigWithAuth<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n O extends Output = Output,\n> = {\n handler: MethodHandler<A, P, I, O>\n auth: MethodAuth<A, P>\n opts?: RouteOptions\n rateLimit?: MethodRateLimit<A, P, I>\n}\n\nexport type MethodConfigOrHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n I extends Input = Input,\n O extends Output = Output,\n> = MethodHandler<A, P, I, O> | MethodConfig<A, P, I, O>\n\nexport type StreamAuthContext<P extends Params = Params> = {\n params: P\n req: IncomingMessage\n}\n\nexport type LexMethodParams<M extends l.Procedure | l.Query | l.Subscription> =\n l.InferMethodParams<M>\n\nexport type LexMethodInput<M extends l.Procedure | l.Query> =\n l.InferMethodInput<M, Readable>\n\nexport type LexMethodOutput<M extends l.Procedure | l.Query> =\n l.InferMethodOutput<M, Readable> extends undefined\n ? l.InferMethodOutput<M, Uint8Array | Readable> | void\n : l.InferMethodOutput<M, Uint8Array | Readable>\n\nexport type LexMethodMessage<M extends l.Subscription> = l.InferMethodMessage<M>\n\nexport type LexMethodHandler<\n M extends l.Procedure | l.Query,\n A extends Auth = Auth,\n> = MethodHandler<A, LexMethodParams<M>, LexMethodInput<M>, LexMethodOutput<M>>\n\nexport type LexMethodConfig<\n M extends l.Procedure | l.Query,\n A extends Auth = Auth,\n> = MethodConfig<A, LexMethodParams<M>, LexMethodInput<M>, LexMethodOutput<M>>\n\nexport type LexSubscriptionHandler<\n M extends l.Subscription,\n A extends Auth = Auth,\n> = StreamHandler<\n Extract<A, AuthResult>,\n LexMethodParams<M>,\n LexMethodMessage<M>\n>\n\nexport type LexSubscriptionConfig<\n M extends l.Subscription,\n A extends Auth = Auth,\n> = StreamConfig<A, LexMethodParams<M>, LexMethodMessage<M>>\n\nexport type StreamAuthVerifier<\n A extends AuthResult = AuthResult,\n P extends Params = Params,\n> = AuthVerifier<StreamAuthContext<P>, A>\n\nexport type StreamContext<\n A extends Auth = Auth,\n P extends Params = Params,\n> = StreamAuthContext<P> & {\n auth: A\n signal: AbortSignal\n}\n\nexport type StreamHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n O = unknown,\n> = (ctx: StreamContext<A, P>) => AsyncIterable<O>\n\nexport type StreamConfig<\n A extends Auth = Auth,\n P extends Params = Params,\n O = unknown,\n> = {\n auth?: StreamAuthVerifier<Extract<A, AuthResult>, P>\n handler: StreamHandler<A, P, O>\n}\n\nexport type StreamConfigOrHandler<\n A extends Auth = Auth,\n P extends Params = Params,\n O = unknown,\n> = StreamHandler<A, P, O> | StreamConfig<A, P, O>\n\nexport function isHandlerSuccess(output: Output): output is HandlerSuccess {\n // We only need to discriminate between possible Output values\n return (\n output != null &&\n 'body' in output && // body is non optional (contrary to what type inference may suggest)\n 'encoding' in output &&\n // Allows using objects that extends HandlerSuccess with a \"status\" field as\n // output, as long as the status is < 400, in order to avoid being confused\n // with ErrorResult objects.\n (!('status' in output) ||\n output.status == null ||\n Number(output.status) < 400)\n )\n}\n\nexport function isHandlerPipeThroughBuffer(\n output: Output,\n): output is HandlerPipeThroughBuffer {\n // We only need to discriminate between possible Output values\n return output != null && 'buffer' in output && output['buffer'] !== undefined\n}\n\nexport function isHandlerPipeThroughStream(\n output: Output,\n): output is HandlerPipeThroughStream {\n // We only need to discriminate between possible Output values\n return output != null && 'stream' in output && output['stream'] !== undefined\n}\n"]}
|
package/dist/util.d.ts
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { IncomingMessage, OutgoingMessage } from 'node:http';
|
|
2
|
-
import { Request, Response } from 'express';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { Request as ExpressRequest, Response as ExpressResponse } from 'express';
|
|
3
|
+
import { l } from '@atproto/lex-schema';
|
|
4
|
+
import { type LexXrpcProcedure, type LexXrpcQuery, type LexXrpcSubscription, Lexicons } from '@atproto/lexicon';
|
|
5
|
+
import { ErrorResult } from './errors';
|
|
6
|
+
import { Auth, Input, LexMethodInput, LexMethodOutput, LexMethodParams, Output, Params, RouteOptions, UndecodedParams } from './types';
|
|
7
|
+
export type ParamsVerifierInternal<P extends Params = Params> = (req: IncomingMessage | ExpressRequest) => P;
|
|
8
|
+
export type AuthVerifierInternal<C, A extends Auth = Auth> = (ctx: C) => Promise<Exclude<A, ErrorResult>>;
|
|
9
|
+
export type InputVerifierInternal<I extends Input = Input> = (req: ExpressRequest, res: ExpressResponse) => Promise<I>;
|
|
10
|
+
export type OutputVerifierInternal<O extends Output = Output> = (handleOutput: O) => void;
|
|
5
11
|
export declare const asArray: <T>(arr: T | T[]) => T[];
|
|
6
12
|
export declare function setHeaders(res: OutgoingMessage, headers?: Record<string, string | number>): void;
|
|
7
|
-
export declare function decodeQueryParams(def: LexXrpcProcedure | LexXrpcQuery | LexXrpcSubscription, params: UndecodedParams): Params;
|
|
8
13
|
export declare function decodeQueryParam(type: string, value: unknown): string | number | boolean | undefined;
|
|
9
|
-
export
|
|
10
|
-
export declare function getQueryParams(
|
|
11
|
-
export declare function
|
|
12
|
-
export declare function
|
|
14
|
+
export declare function getSearchParams(url?: string): URLSearchParams | undefined;
|
|
15
|
+
export declare function getQueryParams(req: IncomingMessage | ExpressRequest): UndecodedParams;
|
|
16
|
+
export declare function createLexiconParamsVerifier<P extends Params = Params>(nsid: string, def: LexXrpcQuery | LexXrpcProcedure | LexXrpcSubscription, lexicons: Lexicons): ParamsVerifierInternal<P>;
|
|
17
|
+
export declare function createSchemaParamsVerifier<M extends l.Procedure | l.Query | l.Subscription>(ns: l.Main<M>): ParamsVerifierInternal<LexMethodParams<M>>;
|
|
18
|
+
export declare function createLexiconInputVerifier<I extends Input = Input>(nsid: string, def: LexXrpcProcedure | LexXrpcQuery, options: RouteOptions, lexicons: Lexicons): InputVerifierInternal<I>;
|
|
19
|
+
export declare function createSchemaInputVerifier<M extends l.Procedure | l.Query>(ns: l.Main<M>, options: RouteOptions): InputVerifierInternal<LexMethodInput<M>>;
|
|
20
|
+
export declare function createLexiconOutputVerifier<O extends Output = Output>(nsid: string, def: LexXrpcProcedure | LexXrpcQuery, lexicons: Lexicons): OutputVerifierInternal<O>;
|
|
21
|
+
export declare function createSchemaOutputVerifier<M extends l.Procedure | l.Query>(ns: l.Main<M>): OutputVerifierInternal<LexMethodOutput<M>>;
|
|
13
22
|
export declare function parseReqEncoding(req: IncomingMessage): string;
|
|
14
23
|
export declare function serverTimingHeader(timings: ServerTiming[]): string;
|
|
15
24
|
export declare class ServerTimer implements ServerTiming {
|
|
@@ -26,7 +35,7 @@ export interface ServerTiming {
|
|
|
26
35
|
duration?: number;
|
|
27
36
|
description?: string;
|
|
28
37
|
}
|
|
29
|
-
export declare const parseReqNsid: (req:
|
|
38
|
+
export declare const parseReqNsid: (req: ExpressRequest | IncomingMessage) => string;
|
|
30
39
|
/**
|
|
31
40
|
* Validates and extracts the nsid from an xrpc path
|
|
32
41
|
*/
|
package/dist/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAE5D,OAAO,
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAE5D,OAAO,EACL,OAAO,IAAI,cAAc,EACzB,QAAQ,IAAI,eAAe,EAG5B,MAAM,SAAS,CAAA;AAIhB,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AACvC,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,QAAQ,EAET,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EACL,WAAW,EAIZ,MAAM,UAAU,CAAA;AACjB,OAAO,EACL,IAAI,EACJ,KAAK,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,MAAM,EACN,MAAM,EACN,YAAY,EACZ,eAAe,EAEhB,MAAM,SAAS,CAAA;AAEhB,MAAM,MAAM,sBAAsB,CAA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