@orpc/server 2.0.0-beta.3 → 2.0.0-beta.31
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 +71 -101
- package/dist/adapters/aws-lambda/index.d.mts +93 -0
- package/dist/adapters/aws-lambda/index.d.ts +93 -0
- package/dist/adapters/aws-lambda/index.mjs +66 -0
- package/dist/adapters/crossws/index.d.mts +17 -8
- package/dist/adapters/crossws/index.d.ts +17 -8
- package/dist/adapters/crossws/index.mjs +10 -7
- package/dist/adapters/fastify/index.d.mts +85 -0
- package/dist/adapters/fastify/index.d.ts +85 -0
- package/dist/adapters/fastify/index.mjs +66 -0
- package/dist/adapters/fetch/index.d.mts +16 -67
- package/dist/adapters/fetch/index.d.ts +16 -67
- package/dist/adapters/fetch/index.mjs +8 -144
- package/dist/adapters/message-port/index.d.mts +19 -16
- package/dist/adapters/message-port/index.d.ts +19 -16
- package/dist/adapters/message-port/index.mjs +28 -32
- package/dist/adapters/node/index.d.mts +15 -49
- package/dist/adapters/node/index.d.ts +15 -49
- package/dist/adapters/node/index.mjs +9 -120
- package/dist/adapters/standard/index.d.mts +6 -6
- package/dist/adapters/standard/index.d.ts +6 -6
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/adapters/standard-peer/index.d.mts +2 -2
- package/dist/adapters/standard-peer/index.d.ts +2 -2
- package/dist/adapters/websocket/index.d.mts +42 -26
- package/dist/adapters/websocket/index.d.ts +42 -26
- package/dist/adapters/websocket/index.mjs +33 -25
- package/dist/extensions/callable.d.mts +2 -2
- package/dist/extensions/callable.d.ts +2 -2
- package/dist/extensions/callable.mjs +2 -2
- package/dist/helpers/index.d.mts +23 -6
- package/dist/helpers/index.d.ts +23 -6
- package/dist/helpers/index.mjs +13 -5
- package/dist/index.d.mts +311 -16
- package/dist/index.d.ts +311 -16
- package/dist/index.mjs +126 -34
- package/dist/plugins/index.d.mts +241 -32
- package/dist/plugins/index.d.ts +241 -32
- package/dist/plugins/index.mjs +479 -15
- package/dist/shared/server.BhHrioCw.d.ts +34 -0
- package/dist/shared/{server.T9F3bzZx.d.ts → server.C2n16pp0.d.ts} +34 -9
- package/dist/shared/server.Cd4Z1hpV.mjs +69 -0
- package/dist/shared/{server.CrlKQucM.mjs → server.CkButhNT.mjs} +21 -38
- package/dist/shared/{server.B_U9y00a.d.mts → server.CkNnZ5F-.d.mts} +34 -9
- package/dist/shared/{server.BL22TloH.d.mts → server.CwrYlF72.d.mts} +31 -41
- package/dist/shared/{server.BL22TloH.d.ts → server.CwrYlF72.d.ts} +31 -41
- package/dist/shared/server.D0Ipbmdv.d.mts +34 -0
- package/dist/shared/{server.BwHnWUuN.mjs → server.Dh77P3ii.mjs} +17 -10
- package/dist/shared/{server.Pa0F03f_.d.ts → server.Dm0os-OP.d.mts} +24 -12
- package/dist/shared/{server.GDpX6Df8.mjs → server.DpUGXBi2.mjs} +84 -51
- package/dist/shared/{server.EOHJ3NJr.d.ts → server.DrN1Pj1-.d.ts} +3 -3
- package/dist/shared/{server.BsNNjG5J.d.mts → server.DtfwuV6U.d.ts} +24 -12
- package/dist/shared/{server.BB_Ik9Ph.d.mts → server.JbCIPL4P.d.mts} +3 -3
- package/dist/shared/{server.CjOb6ItT.mjs → server.eCTV8Vpp.mjs} +1 -1
- package/package.json +46 -12
- package/dist/shared/server.D_QauotT.mjs +0 -30
package/dist/helpers/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParseOptions,
|
|
1
|
+
import { ParseOptions, SetCookie, StringifyOptions } from 'cookie';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Encodes a Uint8Array to base64url format
|
|
@@ -11,6 +11,8 @@ import { ParseOptions, SerializeOptions } from 'cookie';
|
|
|
11
11
|
* const decoded = decodeBase64url(encoded)
|
|
12
12
|
* expect(new TextDecoder().decode(decoded)).toEqual(text)
|
|
13
13
|
* ```
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://orpc.dev/docs/helpers/base64url | Base64Url Helpers}
|
|
14
16
|
*/
|
|
15
17
|
declare function encodeBase64url(data: Uint8Array): string;
|
|
16
18
|
/**
|
|
@@ -24,10 +26,12 @@ declare function encodeBase64url(data: Uint8Array): string;
|
|
|
24
26
|
* const decoded = decodeBase64url(encoded)
|
|
25
27
|
* expect(new TextDecoder().decode(decoded)).toEqual(text)
|
|
26
28
|
* ```
|
|
29
|
+
*
|
|
30
|
+
* @see {@link https://orpc.dev/docs/helpers/base64url | Base64Url Helpers}
|
|
27
31
|
*/
|
|
28
32
|
declare function decodeBase64url(base64url: string | undefined | null): Uint8Array<ArrayBuffer> | undefined;
|
|
29
33
|
|
|
30
|
-
interface SetCookieOptions extends
|
|
34
|
+
interface SetCookieOptions extends Omit<SetCookie, 'name' | 'value'>, StringifyOptions {
|
|
31
35
|
/**
|
|
32
36
|
* Specifies the value for the [`Path` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.4).
|
|
33
37
|
*
|
|
@@ -36,7 +40,7 @@ interface SetCookieOptions extends SerializeOptions {
|
|
|
36
40
|
path?: string;
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
|
-
* Sets a cookie in the response headers
|
|
43
|
+
* Sets a cookie in the response headers.
|
|
40
44
|
*
|
|
41
45
|
* Does nothing if `headers` is `undefined`.
|
|
42
46
|
*
|
|
@@ -46,9 +50,10 @@ interface SetCookieOptions extends SerializeOptions {
|
|
|
46
50
|
*
|
|
47
51
|
* setCookie(headers, 'sessionId', 'abc123', { httpOnly: true, maxAge: 3600 })
|
|
48
52
|
*
|
|
49
|
-
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123;
|
|
53
|
+
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123; Max-Age=3600; Path=/; HttpOnly')
|
|
50
54
|
* ```
|
|
51
55
|
*
|
|
56
|
+
* @see {@link https://orpc.dev/docs/helpers/cookie | Cookie Helpers}
|
|
52
57
|
*/
|
|
53
58
|
declare function setCookie(headers: Headers | undefined, name: string, value: string, options?: SetCookieOptions): void;
|
|
54
59
|
interface GetCookieOptions extends ParseOptions {
|
|
@@ -66,10 +71,14 @@ interface GetCookieOptions extends ParseOptions {
|
|
|
66
71
|
*
|
|
67
72
|
* expect(sessionId).toEqual('abc123')
|
|
68
73
|
* ```
|
|
74
|
+
*
|
|
75
|
+
* @see {@link https://orpc.dev/docs/helpers/cookie | Cookie Helpers}
|
|
69
76
|
*/
|
|
70
77
|
declare function getCookie(headers: Headers | undefined, name: string, options?: GetCookieOptions): string | undefined;
|
|
71
78
|
/**
|
|
72
79
|
* Deletes a cookie by marking it expired.
|
|
80
|
+
*
|
|
81
|
+
* @see {@link https://orpc.dev/docs/helpers/cookie | Cookie Helpers}
|
|
73
82
|
*/
|
|
74
83
|
declare function deleteCookie(headers: Headers | undefined, name: string, options?: Omit<SetCookieOptions, 'maxAge'>): void;
|
|
75
84
|
|
|
@@ -83,6 +92,8 @@ declare function deleteCookie(headers: Headers | undefined, name: string, option
|
|
|
83
92
|
* const decrypted = await decrypt(encrypted, "test-secret-key")
|
|
84
93
|
* expect(decrypted).toBe("Hello, World!")
|
|
85
94
|
* ```
|
|
95
|
+
*
|
|
96
|
+
* @see {@link https://orpc.dev/docs/helpers/encryption | Encryption Helpers}
|
|
86
97
|
*/
|
|
87
98
|
declare function encrypt(value: string, secret: string): Promise<string>;
|
|
88
99
|
/**
|
|
@@ -95,6 +106,8 @@ declare function encrypt(value: string, secret: string): Promise<string>;
|
|
|
95
106
|
* const decrypted = await decrypt(encrypted, "test-secret-key")
|
|
96
107
|
* expect(decrypted).toBe("Hello, World!")
|
|
97
108
|
* ```
|
|
109
|
+
*
|
|
110
|
+
* @see {@link https://orpc.dev/docs/helpers/encryption | Encryption Helpers}
|
|
98
111
|
*/
|
|
99
112
|
declare function decrypt(encrypted: string | undefined | null, secret: string): Promise<string | undefined>;
|
|
100
113
|
|
|
@@ -105,12 +118,13 @@ declare function decrypt(encrypted: string | undefined | null, secret: string):
|
|
|
105
118
|
* the integrity and authenticity of the data. The signature is appended to
|
|
106
119
|
* the original value, separated by a dot, using base64url encoding (no padding).
|
|
107
120
|
*
|
|
108
|
-
*
|
|
109
121
|
* @example
|
|
110
122
|
* ```ts
|
|
111
123
|
* const signedValue = await sign("user123", "my-secret-key")
|
|
112
124
|
* expect(signedValue).toEqual("user123.oneQsU0r5dvwQFHFEjjV1uOI_IR3gZfkYHij3TRauVA")
|
|
113
125
|
* ```
|
|
126
|
+
*
|
|
127
|
+
* @see {@link https://orpc.dev/docs/helpers/signing | Signing Helpers}
|
|
114
128
|
*/
|
|
115
129
|
declare function sign(value: string, secret: string): Promise<string>;
|
|
116
130
|
/**
|
|
@@ -120,13 +134,14 @@ declare function sign(value: string, secret: string): Promise<string>;
|
|
|
120
134
|
* secret key. If the signature is valid, it returns the original value. If the
|
|
121
135
|
* signature is invalid or the format is incorrect, it returns undefined.
|
|
122
136
|
*
|
|
123
|
-
*
|
|
124
137
|
* @example
|
|
125
138
|
* ```ts
|
|
126
139
|
* const signedValue = "user123.oneQsU0r5dvwQFHFEjjV1uOI_IR3gZfkYHij3TRauVA"
|
|
127
140
|
* const originalValue = await unsign(signedValue, "my-secret-key")
|
|
128
141
|
* expect(originalValue).toEqual("user123")
|
|
129
142
|
* ```
|
|
143
|
+
*
|
|
144
|
+
* @see {@link https://orpc.dev/docs/helpers/signing | Signing Helpers}
|
|
130
145
|
*/
|
|
131
146
|
declare function unsign(signedValue: string | undefined | null, secret: string): Promise<string | undefined>;
|
|
132
147
|
/**
|
|
@@ -142,6 +157,8 @@ declare function unsign(signedValue: string | undefined | null, secret: string):
|
|
|
142
157
|
* const value = getSignedValue(signedValue)
|
|
143
158
|
* expect(value).toEqual("user123")
|
|
144
159
|
* ```
|
|
160
|
+
*
|
|
161
|
+
* @see {@link https://orpc.dev/docs/helpers/signing | Signing Helpers}
|
|
145
162
|
*/
|
|
146
163
|
declare function getSignedValue(signedValue: string | undefined | null): string | undefined;
|
|
147
164
|
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParseOptions,
|
|
1
|
+
import { ParseOptions, SetCookie, StringifyOptions } from 'cookie';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Encodes a Uint8Array to base64url format
|
|
@@ -11,6 +11,8 @@ import { ParseOptions, SerializeOptions } from 'cookie';
|
|
|
11
11
|
* const decoded = decodeBase64url(encoded)
|
|
12
12
|
* expect(new TextDecoder().decode(decoded)).toEqual(text)
|
|
13
13
|
* ```
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://orpc.dev/docs/helpers/base64url | Base64Url Helpers}
|
|
14
16
|
*/
|
|
15
17
|
declare function encodeBase64url(data: Uint8Array): string;
|
|
16
18
|
/**
|
|
@@ -24,10 +26,12 @@ declare function encodeBase64url(data: Uint8Array): string;
|
|
|
24
26
|
* const decoded = decodeBase64url(encoded)
|
|
25
27
|
* expect(new TextDecoder().decode(decoded)).toEqual(text)
|
|
26
28
|
* ```
|
|
29
|
+
*
|
|
30
|
+
* @see {@link https://orpc.dev/docs/helpers/base64url | Base64Url Helpers}
|
|
27
31
|
*/
|
|
28
32
|
declare function decodeBase64url(base64url: string | undefined | null): Uint8Array<ArrayBuffer> | undefined;
|
|
29
33
|
|
|
30
|
-
interface SetCookieOptions extends
|
|
34
|
+
interface SetCookieOptions extends Omit<SetCookie, 'name' | 'value'>, StringifyOptions {
|
|
31
35
|
/**
|
|
32
36
|
* Specifies the value for the [`Path` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.4).
|
|
33
37
|
*
|
|
@@ -36,7 +40,7 @@ interface SetCookieOptions extends SerializeOptions {
|
|
|
36
40
|
path?: string;
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
|
-
* Sets a cookie in the response headers
|
|
43
|
+
* Sets a cookie in the response headers.
|
|
40
44
|
*
|
|
41
45
|
* Does nothing if `headers` is `undefined`.
|
|
42
46
|
*
|
|
@@ -46,9 +50,10 @@ interface SetCookieOptions extends SerializeOptions {
|
|
|
46
50
|
*
|
|
47
51
|
* setCookie(headers, 'sessionId', 'abc123', { httpOnly: true, maxAge: 3600 })
|
|
48
52
|
*
|
|
49
|
-
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123;
|
|
53
|
+
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123; Max-Age=3600; Path=/; HttpOnly')
|
|
50
54
|
* ```
|
|
51
55
|
*
|
|
56
|
+
* @see {@link https://orpc.dev/docs/helpers/cookie | Cookie Helpers}
|
|
52
57
|
*/
|
|
53
58
|
declare function setCookie(headers: Headers | undefined, name: string, value: string, options?: SetCookieOptions): void;
|
|
54
59
|
interface GetCookieOptions extends ParseOptions {
|
|
@@ -66,10 +71,14 @@ interface GetCookieOptions extends ParseOptions {
|
|
|
66
71
|
*
|
|
67
72
|
* expect(sessionId).toEqual('abc123')
|
|
68
73
|
* ```
|
|
74
|
+
*
|
|
75
|
+
* @see {@link https://orpc.dev/docs/helpers/cookie | Cookie Helpers}
|
|
69
76
|
*/
|
|
70
77
|
declare function getCookie(headers: Headers | undefined, name: string, options?: GetCookieOptions): string | undefined;
|
|
71
78
|
/**
|
|
72
79
|
* Deletes a cookie by marking it expired.
|
|
80
|
+
*
|
|
81
|
+
* @see {@link https://orpc.dev/docs/helpers/cookie | Cookie Helpers}
|
|
73
82
|
*/
|
|
74
83
|
declare function deleteCookie(headers: Headers | undefined, name: string, options?: Omit<SetCookieOptions, 'maxAge'>): void;
|
|
75
84
|
|
|
@@ -83,6 +92,8 @@ declare function deleteCookie(headers: Headers | undefined, name: string, option
|
|
|
83
92
|
* const decrypted = await decrypt(encrypted, "test-secret-key")
|
|
84
93
|
* expect(decrypted).toBe("Hello, World!")
|
|
85
94
|
* ```
|
|
95
|
+
*
|
|
96
|
+
* @see {@link https://orpc.dev/docs/helpers/encryption | Encryption Helpers}
|
|
86
97
|
*/
|
|
87
98
|
declare function encrypt(value: string, secret: string): Promise<string>;
|
|
88
99
|
/**
|
|
@@ -95,6 +106,8 @@ declare function encrypt(value: string, secret: string): Promise<string>;
|
|
|
95
106
|
* const decrypted = await decrypt(encrypted, "test-secret-key")
|
|
96
107
|
* expect(decrypted).toBe("Hello, World!")
|
|
97
108
|
* ```
|
|
109
|
+
*
|
|
110
|
+
* @see {@link https://orpc.dev/docs/helpers/encryption | Encryption Helpers}
|
|
98
111
|
*/
|
|
99
112
|
declare function decrypt(encrypted: string | undefined | null, secret: string): Promise<string | undefined>;
|
|
100
113
|
|
|
@@ -105,12 +118,13 @@ declare function decrypt(encrypted: string | undefined | null, secret: string):
|
|
|
105
118
|
* the integrity and authenticity of the data. The signature is appended to
|
|
106
119
|
* the original value, separated by a dot, using base64url encoding (no padding).
|
|
107
120
|
*
|
|
108
|
-
*
|
|
109
121
|
* @example
|
|
110
122
|
* ```ts
|
|
111
123
|
* const signedValue = await sign("user123", "my-secret-key")
|
|
112
124
|
* expect(signedValue).toEqual("user123.oneQsU0r5dvwQFHFEjjV1uOI_IR3gZfkYHij3TRauVA")
|
|
113
125
|
* ```
|
|
126
|
+
*
|
|
127
|
+
* @see {@link https://orpc.dev/docs/helpers/signing | Signing Helpers}
|
|
114
128
|
*/
|
|
115
129
|
declare function sign(value: string, secret: string): Promise<string>;
|
|
116
130
|
/**
|
|
@@ -120,13 +134,14 @@ declare function sign(value: string, secret: string): Promise<string>;
|
|
|
120
134
|
* secret key. If the signature is valid, it returns the original value. If the
|
|
121
135
|
* signature is invalid or the format is incorrect, it returns undefined.
|
|
122
136
|
*
|
|
123
|
-
*
|
|
124
137
|
* @example
|
|
125
138
|
* ```ts
|
|
126
139
|
* const signedValue = "user123.oneQsU0r5dvwQFHFEjjV1uOI_IR3gZfkYHij3TRauVA"
|
|
127
140
|
* const originalValue = await unsign(signedValue, "my-secret-key")
|
|
128
141
|
* expect(originalValue).toEqual("user123")
|
|
129
142
|
* ```
|
|
143
|
+
*
|
|
144
|
+
* @see {@link https://orpc.dev/docs/helpers/signing | Signing Helpers}
|
|
130
145
|
*/
|
|
131
146
|
declare function unsign(signedValue: string | undefined | null, secret: string): Promise<string | undefined>;
|
|
132
147
|
/**
|
|
@@ -142,6 +157,8 @@ declare function unsign(signedValue: string | undefined | null, secret: string):
|
|
|
142
157
|
* const value = getSignedValue(signedValue)
|
|
143
158
|
* expect(value).toEqual("user123")
|
|
144
159
|
* ```
|
|
160
|
+
*
|
|
161
|
+
* @see {@link https://orpc.dev/docs/helpers/signing | Signing Helpers}
|
|
145
162
|
*/
|
|
146
163
|
declare function getSignedValue(signedValue: string | undefined | null): string | undefined;
|
|
147
164
|
|
package/dist/helpers/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseCookie, stringifySetCookie } from 'cookie';
|
|
2
2
|
|
|
3
3
|
function encodeBase64url(data) {
|
|
4
4
|
const chunkSize = 8192;
|
|
@@ -34,10 +34,17 @@ function setCookie(headers, name, value, options = {}) {
|
|
|
34
34
|
if (headers === void 0) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
const cookieString =
|
|
37
|
+
const cookieString = stringifySetCookie({
|
|
38
|
+
// Force path to '/' by default so the cookie is available across the
|
|
39
|
+
// entire app, not just under the directory of the request that set it
|
|
40
|
+
// (which is what browsers do per RFC 6265 §5.1.4 when Path is omitted).
|
|
38
41
|
path: "/",
|
|
39
|
-
...options
|
|
40
|
-
|
|
42
|
+
...options,
|
|
43
|
+
name,
|
|
44
|
+
// prioritize
|
|
45
|
+
value
|
|
46
|
+
// prioritize
|
|
47
|
+
}, options);
|
|
41
48
|
headers.append("Set-Cookie", cookieString);
|
|
42
49
|
}
|
|
43
50
|
function getCookie(headers, name, options = {}) {
|
|
@@ -48,12 +55,13 @@ function getCookie(headers, name, options = {}) {
|
|
|
48
55
|
if (cookieHeader === null) {
|
|
49
56
|
return void 0;
|
|
50
57
|
}
|
|
51
|
-
return
|
|
58
|
+
return parseCookie(cookieHeader, options)[name];
|
|
52
59
|
}
|
|
53
60
|
function deleteCookie(headers, name, options = {}) {
|
|
54
61
|
return setCookie(headers, name, "", {
|
|
55
62
|
...options,
|
|
56
63
|
maxAge: 0
|
|
64
|
+
// prioritize
|
|
57
65
|
});
|
|
58
66
|
}
|
|
59
67
|
|