@orpc/standard-server 0.0.0-next.fd1ee2a → 0.0.0-next.fdd2389

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 CHANGED
@@ -17,6 +17,9 @@
17
17
  <a href="https://discord.gg/TXEbwRBvQn">
18
18
  <img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
19
19
  </a>
20
+ <a href="https://deepwiki.com/unnoq/orpc">
21
+ <img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
22
+ </a>
20
23
  </div>
21
24
 
22
25
  <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
@@ -30,7 +33,8 @@
30
33
  - **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
31
34
  - **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
32
35
  - **📝 Contract-First Development**: Optionally define your API contract before implementation.
33
- - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more.
36
+ - **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
37
+ - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
34
38
  - **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
35
39
  - **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
36
40
  - **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
@@ -38,7 +42,6 @@
38
42
  - **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
39
43
  - **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
40
44
  - **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
41
- - **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
42
45
 
43
46
  ## Documentation
44
47
 
@@ -50,9 +53,11 @@ You can find the full documentation [here](https://orpc.unnoq.com).
50
53
  - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
51
54
  - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
52
55
  - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
56
+ - [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
53
57
  - [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
54
58
  - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
55
59
  - [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
60
+ - [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
56
61
  - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
57
62
  - [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
58
63
  - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
@@ -1,4 +1,4 @@
1
- import { stringifyJSON, parseEmptyableJSON, isAsyncIteratorObject, isObject } from '@orpc/shared';
1
+ import { stringifyJSON, parseEmptyableJSON, AsyncIteratorClass, isAsyncIteratorObject, isObject } from '@orpc/shared';
2
2
 
3
3
  function toBatchAbortSignal(signals) {
4
4
  const realSignals = signals.filter((signal) => signal !== void 0);
@@ -91,46 +91,56 @@ function toBatchResponse(options) {
91
91
  return {
92
92
  headers: options.headers,
93
93
  status: options.status,
94
- body: async function* () {
95
- try {
96
- for await (const item of options.body) {
97
- yield {
98
- index: item.index,
99
- status: item.status === options.status ? void 0 : item.status,
100
- headers: Object.keys(item.headers).length ? item.headers : void 0,
101
- body: item.body
102
- };
94
+ body: new AsyncIteratorClass(
95
+ async () => {
96
+ const { done, value } = await options.body.next();
97
+ if (done) {
98
+ return { done, value };
99
+ }
100
+ return {
101
+ done,
102
+ value: {
103
+ index: value.index,
104
+ status: value.status === options.status ? void 0 : value.status,
105
+ headers: Object.keys(value.headers).length ? value.headers : void 0,
106
+ body: value.body
107
+ }
108
+ };
109
+ },
110
+ async (reason) => {
111
+ if (reason !== "next") {
112
+ await options.body.return?.();
103
113
  }
104
- } finally {
105
- await options.body.return?.();
106
114
  }
107
- }()
115
+ )
108
116
  };
109
117
  }
110
118
  function parseBatchResponse(response) {
111
119
  const body = response.body;
112
120
  if (isAsyncIteratorObject(body) || Array.isArray(body)) {
113
- return async function* () {
114
- try {
115
- for await (const item of body) {
116
- if (!isObject(item) || !("index" in item) || typeof item.index !== "number") {
117
- throw new TypeError("Invalid batch response", {
118
- cause: item
119
- });
120
- }
121
- yield {
122
- index: item.index,
123
- status: item.status ?? response.status,
124
- headers: item.headers ?? {},
125
- body: item.body
126
- };
121
+ const iterator = (async function* () {
122
+ for await (const item of body) {
123
+ if (!isObject(item) || !("index" in item) || typeof item.index !== "number") {
124
+ throw new TypeError("Invalid batch response", {
125
+ cause: item
126
+ });
127
127
  }
128
- } finally {
129
- if (isAsyncIteratorObject(body)) {
128
+ yield {
129
+ index: item.index,
130
+ status: item.status ?? response.status,
131
+ headers: item.headers ?? {},
132
+ body: item.body
133
+ };
134
+ }
135
+ })();
136
+ return new AsyncIteratorClass(
137
+ () => iterator.next(),
138
+ async (reason) => {
139
+ if (reason !== "next" && isAsyncIteratorObject(body)) {
130
140
  await body.return?.();
131
141
  }
132
142
  }
133
- }();
143
+ );
134
144
  }
135
145
  throw new TypeError("Invalid batch response", {
136
146
  cause: response
package/dist/index.d.mts CHANGED
@@ -53,15 +53,15 @@ type EventMeta = Partial<Pick<EventMessage, 'retry' | 'id' | 'comments'>>;
53
53
  declare function withEventMeta<T extends object>(container: T, meta: EventMeta): T;
54
54
  declare function getEventMeta(container: unknown): EventMeta | undefined;
55
55
 
56
- interface experimental_HibernationEventIteratorCallback {
56
+ interface HibernationEventIteratorCallback {
57
57
  (id: string): void;
58
58
  }
59
- declare class experimental_HibernationEventIterator<T, TReturn = unknown, TNext = unknown> extends AsyncIteratorClass<T, TReturn, TNext> {
59
+ declare class HibernationEventIterator<T, TReturn = unknown, TNext = unknown> extends AsyncIteratorClass<T, TReturn, TNext> {
60
60
  /**
61
61
  * this property is not transferred to the client, so it should be optional for type safety
62
62
  */
63
- readonly hibernationCallback?: experimental_HibernationEventIteratorCallback;
64
- constructor(hibernationCallback: experimental_HibernationEventIteratorCallback);
63
+ readonly hibernationCallback?: HibernationEventIteratorCallback;
64
+ constructor(hibernationCallback: HibernationEventIteratorCallback);
65
65
  }
66
66
 
67
67
  declare function generateContentDisposition(filename: string): string;
@@ -71,5 +71,5 @@ declare function flattenHeader(header: string | readonly string[] | undefined):
71
71
  declare function replicateStandardLazyResponse(response: StandardLazyResponse, count: number): StandardLazyResponse[];
72
72
  declare function isEventIteratorHeaders(headers: StandardHeaders): boolean;
73
73
 
74
- export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, StandardHeaders, StandardLazyResponse, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, experimental_HibernationEventIterator, flattenHeader, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, isEventIteratorHeaders, mergeStandardHeaders, replicateStandardLazyResponse, withEventMeta };
75
- export type { ErrorEventOptions, EventDecoderOptions, EventMessage, EventMeta, experimental_HibernationEventIteratorCallback };
74
+ export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, HibernationEventIterator, StandardHeaders, StandardLazyResponse, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, flattenHeader, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, isEventIteratorHeaders, mergeStandardHeaders, replicateStandardLazyResponse, withEventMeta };
75
+ export type { ErrorEventOptions, EventDecoderOptions, EventMessage, EventMeta, HibernationEventIteratorCallback };
package/dist/index.d.ts CHANGED
@@ -53,15 +53,15 @@ type EventMeta = Partial<Pick<EventMessage, 'retry' | 'id' | 'comments'>>;
53
53
  declare function withEventMeta<T extends object>(container: T, meta: EventMeta): T;
54
54
  declare function getEventMeta(container: unknown): EventMeta | undefined;
55
55
 
56
- interface experimental_HibernationEventIteratorCallback {
56
+ interface HibernationEventIteratorCallback {
57
57
  (id: string): void;
58
58
  }
59
- declare class experimental_HibernationEventIterator<T, TReturn = unknown, TNext = unknown> extends AsyncIteratorClass<T, TReturn, TNext> {
59
+ declare class HibernationEventIterator<T, TReturn = unknown, TNext = unknown> extends AsyncIteratorClass<T, TReturn, TNext> {
60
60
  /**
61
61
  * this property is not transferred to the client, so it should be optional for type safety
62
62
  */
63
- readonly hibernationCallback?: experimental_HibernationEventIteratorCallback;
64
- constructor(hibernationCallback: experimental_HibernationEventIteratorCallback);
63
+ readonly hibernationCallback?: HibernationEventIteratorCallback;
64
+ constructor(hibernationCallback: HibernationEventIteratorCallback);
65
65
  }
66
66
 
67
67
  declare function generateContentDisposition(filename: string): string;
@@ -71,5 +71,5 @@ declare function flattenHeader(header: string | readonly string[] | undefined):
71
71
  declare function replicateStandardLazyResponse(response: StandardLazyResponse, count: number): StandardLazyResponse[];
72
72
  declare function isEventIteratorHeaders(headers: StandardHeaders): boolean;
73
73
 
74
- export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, StandardHeaders, StandardLazyResponse, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, experimental_HibernationEventIterator, flattenHeader, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, isEventIteratorHeaders, mergeStandardHeaders, replicateStandardLazyResponse, withEventMeta };
75
- export type { ErrorEventOptions, EventDecoderOptions, EventMessage, EventMeta, experimental_HibernationEventIteratorCallback };
74
+ export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, HibernationEventIterator, StandardHeaders, StandardLazyResponse, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, flattenHeader, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, isEventIteratorHeaders, mergeStandardHeaders, replicateStandardLazyResponse, withEventMeta };
75
+ export type { ErrorEventOptions, EventDecoderOptions, EventMessage, EventMeta, HibernationEventIteratorCallback };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { isTypescriptObject, AsyncIteratorClass, toArray, once, isAsyncIteratorObject, replicateAsyncIterator } from '@orpc/shared';
1
+ import { isTypescriptObject, AsyncIteratorClass, tryDecodeURIComponent, toArray, once, isAsyncIteratorObject, replicateAsyncIterator } from '@orpc/shared';
2
2
 
3
3
  class EventEncoderError extends TypeError {
4
4
  }
@@ -158,6 +158,9 @@ function encodeEventMessage(message) {
158
158
 
159
159
  const EVENT_SOURCE_META_SYMBOL = Symbol("ORPC_EVENT_SOURCE_META");
160
160
  function withEventMeta(container, meta) {
161
+ if (meta.id === void 0 && meta.retry === void 0 && !meta.comments?.length) {
162
+ return container;
163
+ }
161
164
  if (meta.id !== void 0) {
162
165
  assertEventId(meta.id);
163
166
  }
@@ -182,7 +185,7 @@ function getEventMeta(container) {
182
185
  return isTypescriptObject(container) ? Reflect.get(container, EVENT_SOURCE_META_SYMBOL) : void 0;
183
186
  }
184
187
 
185
- class experimental_HibernationEventIterator extends AsyncIteratorClass {
188
+ class HibernationEventIterator extends AsyncIteratorClass {
186
189
  /**
187
190
  * this property is not transferred to the client, so it should be optional for type safety
188
191
  */
@@ -207,7 +210,7 @@ function generateContentDisposition(filename) {
207
210
  function getFilenameFromContentDisposition(contentDisposition) {
208
211
  const encodedFilenameStarMatch = contentDisposition.match(/filename\*=(UTF-8'')?([^;]*)/i);
209
212
  if (encodedFilenameStarMatch && typeof encodedFilenameStarMatch[2] === "string") {
210
- return decodeURIComponent(encodedFilenameStarMatch[2]);
213
+ return tryDecodeURIComponent(encodedFilenameStarMatch[2]);
211
214
  }
212
215
  const encodedFilenameMatch = contentDisposition.match(/filename="((?:\\"|[^"])*)"/i);
213
216
  if (encodedFilenameMatch && typeof encodedFilenameMatch[1] === "string") {
@@ -248,14 +251,11 @@ function replicateStandardLazyResponse(response, count) {
248
251
  replicated.push({
249
252
  ...response,
250
253
  body: once(async () => {
251
- if (replicatedAsyncIteratorObjects) {
252
- return replicatedAsyncIteratorObjects.shift();
253
- }
254
254
  const body = await (bodyPromise ??= response.body());
255
255
  if (!isAsyncIteratorObject(body)) {
256
256
  return body;
257
257
  }
258
- replicatedAsyncIteratorObjects = replicateAsyncIterator(body, count);
258
+ replicatedAsyncIteratorObjects ??= replicateAsyncIterator(body, count);
259
259
  return replicatedAsyncIteratorObjects.shift();
260
260
  })
261
261
  });
@@ -266,4 +266,4 @@ function isEventIteratorHeaders(headers) {
266
266
  return Boolean(flattenHeader(headers["content-type"])?.startsWith("text/event-stream") && flattenHeader(headers["content-disposition"]) === void 0);
267
267
  }
268
268
 
269
- export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, experimental_HibernationEventIterator, flattenHeader, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, isEventIteratorHeaders, mergeStandardHeaders, replicateStandardLazyResponse, withEventMeta };
269
+ export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, HibernationEventIterator, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, flattenHeader, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, isEventIteratorHeaders, mergeStandardHeaders, replicateStandardLazyResponse, withEventMeta };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/standard-server",
3
3
  "type": "module",
4
- "version": "0.0.0-next.fd1ee2a",
4
+ "version": "0.0.0-next.fdd2389",
5
5
  "license": "MIT",
6
6
  "homepage": "https://unnoq.com",
7
7
  "repository": {
@@ -28,7 +28,7 @@
28
28
  "dist"
29
29
  ],
30
30
  "dependencies": {
31
- "@orpc/shared": "0.0.0-next.fd1ee2a"
31
+ "@orpc/shared": "0.0.0-next.fdd2389"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "unbuild",