@orpc/server 1.14.11 → 1.14.13
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 +98 -52
- package/dist/adapters/aws-lambda/index.d.mts +46 -0
- package/dist/adapters/aws-lambda/index.d.ts +46 -0
- package/dist/adapters/aws-lambda/index.mjs +40 -0
- package/dist/adapters/bun-ws/index.d.mts +36 -0
- package/dist/adapters/bun-ws/index.d.ts +36 -0
- package/dist/adapters/bun-ws/index.mjs +47 -0
- package/dist/adapters/crossws/index.d.mts +21 -45
- package/dist/adapters/crossws/index.d.ts +21 -45
- package/dist/adapters/crossws/index.mjs +18 -40
- package/dist/adapters/fastify/index.d.mts +53 -0
- package/dist/adapters/fastify/index.d.ts +53 -0
- package/dist/adapters/fastify/index.mjs +52 -0
- package/dist/adapters/fetch/index.d.mts +96 -64
- package/dist/adapters/fetch/index.d.ts +96 -64
- package/dist/adapters/fetch/index.mjs +139 -34
- package/dist/adapters/message-port/index.d.mts +34 -49
- package/dist/adapters/message-port/index.d.ts +34 -49
- package/dist/adapters/message-port/index.mjs +37 -68
- package/dist/adapters/node/index.d.mts +71 -63
- package/dist/adapters/node/index.d.ts +71 -63
- package/dist/adapters/node/index.mjs +113 -36
- package/dist/adapters/standard/index.d.mts +18 -16
- package/dist/adapters/standard/index.d.ts +18 -16
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/standard-peer/index.d.mts +14 -12
- package/dist/adapters/standard-peer/index.d.ts +14 -12
- package/dist/adapters/standard-peer/index.mjs +21 -2
- package/dist/adapters/websocket/index.d.mts +38 -53
- package/dist/adapters/websocket/index.d.ts +38 -53
- package/dist/adapters/websocket/index.mjs +42 -59
- package/dist/adapters/ws/index.d.mts +31 -0
- package/dist/adapters/ws/index.d.ts +31 -0
- package/dist/adapters/ws/index.mjs +41 -0
- package/dist/helpers/index.d.mts +4 -4
- package/dist/helpers/index.d.ts +4 -4
- package/dist/helpers/index.mjs +5 -13
- package/dist/hibernation/index.d.mts +44 -0
- package/dist/hibernation/index.d.ts +44 -0
- package/dist/hibernation/index.mjs +65 -0
- package/dist/index.d.mts +770 -166
- package/dist/index.d.ts +770 -166
- package/dist/index.mjs +399 -306
- package/dist/plugins/index.d.mts +121 -214
- package/dist/plugins/index.d.ts +121 -214
- package/dist/plugins/index.mjs +214 -576
- package/dist/shared/server.7cEtMB30.d.ts +74 -0
- package/dist/shared/server.B8gYOD5g.d.mts +12 -0
- package/dist/shared/server.BqadksTP.d.mts +74 -0
- package/dist/shared/server.C8_sRzQB.d.mts +42 -0
- package/dist/shared/server.CMf4nKky.mjs +230 -0
- package/dist/shared/server.ChyoA9XY.d.ts +42 -0
- package/dist/shared/server.D8IXzfqT.d.ts +32 -0
- package/dist/shared/server.DEBcqOjg.mjs +418 -0
- package/dist/shared/{server.W91HSRkE.mjs → server.DZ5BIITo.mjs} +2 -2
- package/dist/shared/server.DzE6WeuY.d.mts +32 -0
- package/dist/shared/server.EfTOZ2Q7.d.ts +12 -0
- package/dist/shared/server.TEVCLCFC.mjs +39 -0
- package/dist/shared/server.qKsRrdxW.d.mts +193 -0
- package/dist/shared/server.qKsRrdxW.d.ts +193 -0
- package/package.json +56 -26
- package/dist/extensions/callable.d.mts +0 -10
- package/dist/extensions/callable.d.ts +0 -10
- package/dist/extensions/callable.mjs +0 -11
- package/dist/shared/server.15O7oC1p.d.mts +0 -61
- package/dist/shared/server.B4BnEWWm.d.mts +0 -67
- package/dist/shared/server.BhsVw7m7.d.ts +0 -104
- package/dist/shared/server.BoiFpNT7.mjs +0 -224
- package/dist/shared/server.COPVXhDG.mjs +0 -271
- package/dist/shared/server.CX4vUnDk.mjs +0 -11
- package/dist/shared/server.CcR4kgje.d.mts +0 -206
- package/dist/shared/server.CcR4kgje.d.ts +0 -206
- package/dist/shared/server.CnN50DHH.d.ts +0 -67
- package/dist/shared/server.DBs0rrf9.mjs +0 -41
- package/dist/shared/server.DDFizwfU.d.mts +0 -104
- package/dist/shared/server.D_QauotT.mjs +0 -30
- package/dist/shared/server.DofEOwf-.mjs +0 -237
- package/dist/shared/server.m3szVJGU.d.ts +0 -61
package/dist/helpers/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { serialize, parse } from 'cookie';
|
|
2
2
|
|
|
3
3
|
function encodeBase64url(data) {
|
|
4
4
|
const chunkSize = 8192;
|
|
@@ -34,17 +34,10 @@ function setCookie(headers, name, value, options = {}) {
|
|
|
34
34
|
if (headers === void 0) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
const cookieString =
|
|
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).
|
|
37
|
+
const cookieString = serialize(name, value, {
|
|
41
38
|
path: "/",
|
|
42
|
-
...options
|
|
43
|
-
|
|
44
|
-
// prioritize
|
|
45
|
-
value
|
|
46
|
-
// prioritize
|
|
47
|
-
}, options);
|
|
39
|
+
...options
|
|
40
|
+
});
|
|
48
41
|
headers.append("Set-Cookie", cookieString);
|
|
49
42
|
}
|
|
50
43
|
function getCookie(headers, name, options = {}) {
|
|
@@ -55,13 +48,12 @@ function getCookie(headers, name, options = {}) {
|
|
|
55
48
|
if (cookieHeader === null) {
|
|
56
49
|
return void 0;
|
|
57
50
|
}
|
|
58
|
-
return
|
|
51
|
+
return parse(cookieHeader, options)[name];
|
|
59
52
|
}
|
|
60
53
|
function deleteCookie(headers, name, options = {}) {
|
|
61
54
|
return setCookie(headers, name, "", {
|
|
62
55
|
...options,
|
|
63
56
|
maxAge: 0
|
|
64
|
-
// prioritize
|
|
65
57
|
});
|
|
66
58
|
}
|
|
67
59
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
|
2
|
+
import { C as Context, R as Router } from '../shared/server.qKsRrdxW.mjs';
|
|
3
|
+
import { HibernationEventIterator } from '@orpc/standard-server';
|
|
4
|
+
export { HibernationEventIterator, HibernationEventIteratorCallback } from '@orpc/standard-server';
|
|
5
|
+
import { g as StandardHandlerPlugin, e as StandardHandlerOptions } from '../shared/server.BqadksTP.mjs';
|
|
6
|
+
import '@orpc/client';
|
|
7
|
+
import '@orpc/contract';
|
|
8
|
+
import '@orpc/shared';
|
|
9
|
+
|
|
10
|
+
interface EncodeHibernationRPCEventOptions extends StandardRPCJsonSerializerOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The type of event, each type corresponds a different operation
|
|
13
|
+
*
|
|
14
|
+
* - 'message' = 'yield'
|
|
15
|
+
* - 'error' = 'throw'
|
|
16
|
+
* - 'done' = 'return'
|
|
17
|
+
*
|
|
18
|
+
* @default 'message'
|
|
19
|
+
*/
|
|
20
|
+
event?: 'message' | 'error' | 'done';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Encodes a Hibernation RPC Event
|
|
24
|
+
*
|
|
25
|
+
* @see {@link https://orpc.dev/docs/plugins/hibernation Hibernation Plugin}
|
|
26
|
+
*/
|
|
27
|
+
declare function encodeHibernationRPCEvent(id: string, payload: unknown, options?: EncodeHibernationRPCEventOptions): string;
|
|
28
|
+
|
|
29
|
+
interface HibernationPluginContext {
|
|
30
|
+
iterator?: HibernationEventIterator<any>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Enable Hibernation APIs
|
|
34
|
+
*
|
|
35
|
+
* @see {@link https://orpc.dev/docs/plugins/hibernation Hibernation Plugin}
|
|
36
|
+
*/
|
|
37
|
+
declare class HibernationPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
38
|
+
readonly CONTEXT_SYMBOL: symbol;
|
|
39
|
+
order: number;
|
|
40
|
+
init(options: StandardHandlerOptions<T>, _router: Router<any, T>): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { HibernationPlugin, encodeHibernationRPCEvent };
|
|
44
|
+
export type { EncodeHibernationRPCEventOptions, HibernationPluginContext };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
|
2
|
+
import { C as Context, R as Router } from '../shared/server.qKsRrdxW.js';
|
|
3
|
+
import { HibernationEventIterator } from '@orpc/standard-server';
|
|
4
|
+
export { HibernationEventIterator, HibernationEventIteratorCallback } from '@orpc/standard-server';
|
|
5
|
+
import { g as StandardHandlerPlugin, e as StandardHandlerOptions } from '../shared/server.7cEtMB30.js';
|
|
6
|
+
import '@orpc/client';
|
|
7
|
+
import '@orpc/contract';
|
|
8
|
+
import '@orpc/shared';
|
|
9
|
+
|
|
10
|
+
interface EncodeHibernationRPCEventOptions extends StandardRPCJsonSerializerOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The type of event, each type corresponds a different operation
|
|
13
|
+
*
|
|
14
|
+
* - 'message' = 'yield'
|
|
15
|
+
* - 'error' = 'throw'
|
|
16
|
+
* - 'done' = 'return'
|
|
17
|
+
*
|
|
18
|
+
* @default 'message'
|
|
19
|
+
*/
|
|
20
|
+
event?: 'message' | 'error' | 'done';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Encodes a Hibernation RPC Event
|
|
24
|
+
*
|
|
25
|
+
* @see {@link https://orpc.dev/docs/plugins/hibernation Hibernation Plugin}
|
|
26
|
+
*/
|
|
27
|
+
declare function encodeHibernationRPCEvent(id: string, payload: unknown, options?: EncodeHibernationRPCEventOptions): string;
|
|
28
|
+
|
|
29
|
+
interface HibernationPluginContext {
|
|
30
|
+
iterator?: HibernationEventIterator<any>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Enable Hibernation APIs
|
|
34
|
+
*
|
|
35
|
+
* @see {@link https://orpc.dev/docs/plugins/hibernation Hibernation Plugin}
|
|
36
|
+
*/
|
|
37
|
+
declare class HibernationPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
38
|
+
readonly CONTEXT_SYMBOL: symbol;
|
|
39
|
+
order: number;
|
|
40
|
+
init(options: StandardHandlerOptions<T>, _router: Router<any, T>): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { HibernationPlugin, encodeHibernationRPCEvent };
|
|
44
|
+
export type { EncodeHibernationRPCEventOptions, HibernationPluginContext };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { toORPCError } from '@orpc/client';
|
|
2
|
+
import { StandardRPCJsonSerializer } from '@orpc/client/standard';
|
|
3
|
+
import { stringifyJSON } from '@orpc/shared';
|
|
4
|
+
import { getEventMeta, HibernationEventIterator } from '@orpc/standard-server';
|
|
5
|
+
export { HibernationEventIterator } from '@orpc/standard-server';
|
|
6
|
+
import { MessageType } from '@orpc/standard-server-peer';
|
|
7
|
+
|
|
8
|
+
function encodeHibernationRPCEvent(id, payload, options = {}) {
|
|
9
|
+
const { event = "message", ...rest } = options;
|
|
10
|
+
const serializer = new StandardRPCJsonSerializer(rest);
|
|
11
|
+
const data = event === "error" ? toORPCError(payload).toJSON() : payload;
|
|
12
|
+
const [json, meta] = serializer.serialize(data);
|
|
13
|
+
return stringifyJSON({
|
|
14
|
+
i: id,
|
|
15
|
+
t: MessageType.EVENT_ITERATOR,
|
|
16
|
+
p: {
|
|
17
|
+
e: event,
|
|
18
|
+
d: { json, meta: meta.length > 0 ? meta : void 0 },
|
|
19
|
+
m: getEventMeta(payload)
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class HibernationPlugin {
|
|
25
|
+
CONTEXT_SYMBOL = Symbol("ORPC_HIBERNATION_CONTEXT");
|
|
26
|
+
order = 2e6;
|
|
27
|
+
// make sure execute after the batch plugin
|
|
28
|
+
init(options, _router) {
|
|
29
|
+
options.interceptors ??= [];
|
|
30
|
+
options.clientInterceptors ??= [];
|
|
31
|
+
options.interceptors.unshift(async (options2) => {
|
|
32
|
+
const hibernationContext = {};
|
|
33
|
+
const result = await options2.next({
|
|
34
|
+
...options2,
|
|
35
|
+
context: {
|
|
36
|
+
...options2.context,
|
|
37
|
+
[this.CONTEXT_SYMBOL]: hibernationContext
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
if (!result.matched || !hibernationContext.iterator) {
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
...result,
|
|
45
|
+
response: {
|
|
46
|
+
...result.response,
|
|
47
|
+
body: hibernationContext.iterator
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
options.clientInterceptors.unshift(async (options2) => {
|
|
52
|
+
const hibernationContext = options2.context[this.CONTEXT_SYMBOL];
|
|
53
|
+
if (!hibernationContext) {
|
|
54
|
+
throw new TypeError("[HibernationPlugin] Hibernation context has been corrupted or modified by another plugin or interceptor");
|
|
55
|
+
}
|
|
56
|
+
const output = await options2.next();
|
|
57
|
+
if (output instanceof HibernationEventIterator) {
|
|
58
|
+
hibernationContext.iterator = output;
|
|
59
|
+
}
|
|
60
|
+
return output;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { HibernationPlugin, encodeHibernationRPCEvent };
|