@orpc/standard-server
Advanced tools
Comparing version 0.0.0-next.7e41bc4 to 0.0.0-next.92faaf9
@@ -13,4 +13,2 @@ // src/event-source/errors.ts | ||
}; | ||
var UnknownEvent = class extends ErrorEvent { | ||
}; | ||
@@ -21,18 +19,16 @@ // src/event-source/decoder.ts | ||
const message = { | ||
data: "", | ||
data: void 0, | ||
event: void 0, | ||
id: void 0, | ||
retry: void 0 | ||
retry: void 0, | ||
comments: [] | ||
}; | ||
for (const line of lines) { | ||
const index = line.indexOf(": "); | ||
if (index === -1) { | ||
throw new EventDecoderError(`Invalid EventSource message line: ${line}`); | ||
} | ||
const key = line.slice(0, index); | ||
const value = line.slice(index + 2); | ||
if (key !== "data" && key in message && message[key] !== void 0) { | ||
throw new EventDecoderError(`Duplicate EventSource message key: ${key}`); | ||
} | ||
if (key === "data") { | ||
const index = line.indexOf(":"); | ||
const key = index === -1 ? line : line.slice(0, index); | ||
const value = index === -1 ? "" : line.slice(index + 1).replace(/^\s/, ""); | ||
if (index === 0) { | ||
message.comments.push(value); | ||
} else if (key === "data") { | ||
message.data ??= ""; | ||
message.data += `${value} | ||
@@ -46,11 +42,8 @@ `; | ||
const maybeInteger = Number.parseInt(value); | ||
if (!Number.isInteger(maybeInteger) || maybeInteger < 0 || maybeInteger.toString() !== value) { | ||
throw new EventDecoderError(`Invalid EventSource message retry value: ${value}`); | ||
if (Number.isInteger(maybeInteger) && maybeInteger >= 0 && maybeInteger.toString() === value) { | ||
message.retry = maybeInteger; | ||
} | ||
message.retry = maybeInteger; | ||
} else { | ||
throw new EventDecoderError(`Unknown EventSource message key: ${key}`); | ||
} | ||
} | ||
message.data = message.data.replace(/\n$/, ""); | ||
message.data = message.data?.replace(/\n$/, ""); | ||
return message; | ||
@@ -69,8 +62,5 @@ } | ||
} | ||
const completes = this.incomplete.slice(0, lastCompleteIndex + 2).split(/\n{2,}/); | ||
const completes = this.incomplete.slice(0, lastCompleteIndex).split(/\n\n/); | ||
this.incomplete = this.incomplete.slice(lastCompleteIndex + 2); | ||
for (const encoded of completes) { | ||
if (!encoded) { | ||
continue; | ||
} | ||
const message = decodeEventMessage(`${encoded} | ||
@@ -86,3 +76,5 @@ | ||
end() { | ||
this.feed("\n\n"); | ||
if (this.incomplete) { | ||
throw new EventDecoderError("EventSource ended before complete"); | ||
} | ||
} | ||
@@ -128,3 +120,3 @@ }; | ||
function encodeEventData(data) { | ||
const lines = data ? data.split(/\n/) : [""]; | ||
const lines = data?.split(/\n/) ?? []; | ||
let output = ""; | ||
@@ -160,6 +152,4 @@ for (const line of lines) { | ||
// src/event-source/meta.ts | ||
import { isTypescriptObject } from "@orpc/shared"; | ||
var EVENT_SOURCE_META_SYMBOL = Symbol("ORPC_EVENT_SOURCE_META"); | ||
function isEventMetaContainer(value) { | ||
return !!value && (typeof value === "object" || typeof value === "function"); | ||
} | ||
function withEventMeta(container, meta) { | ||
@@ -182,3 +172,3 @@ if (meta.id !== void 0) { | ||
function getEventMeta(container) { | ||
return isEventMetaContainer(container) ? Reflect.get(container, EVENT_SOURCE_META_SYMBOL) : void 0; | ||
return isTypescriptObject(container) ? Reflect.get(container, EVENT_SOURCE_META_SYMBOL) : void 0; | ||
} | ||
@@ -188,25 +178,2 @@ | ||
import { contentDisposition, parse } from "@tinyhttp/content-disposition"; | ||
function once(fn) { | ||
let cached; | ||
return () => { | ||
if (cached) { | ||
return cached.result; | ||
} | ||
const result = fn(); | ||
cached = { result }; | ||
return result; | ||
}; | ||
} | ||
function parseEmptyableJSON(text) { | ||
if (!text) { | ||
return void 0; | ||
} | ||
return JSON.parse(text); | ||
} | ||
function isAsyncIteratorObject(maybe) { | ||
if (!maybe || typeof maybe !== "object") { | ||
return false; | ||
} | ||
return Symbol.asyncIterator in maybe && typeof maybe[Symbol.asyncIterator] === "function"; | ||
} | ||
export { | ||
@@ -218,3 +185,2 @@ ErrorEvent, | ||
EventEncoderError, | ||
UnknownEvent, | ||
assertEventId, | ||
@@ -228,9 +194,5 @@ assertEventName, | ||
getEventMeta, | ||
isAsyncIteratorObject, | ||
isEventMetaContainer, | ||
once, | ||
parse as parseContentDisposition, | ||
parseEmptyableJSON, | ||
withEventMeta | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,1 @@ | ||
import type { JsonValue } from 'type-fest'; | ||
export declare class EventEncoderError extends TypeError { | ||
@@ -8,10 +7,8 @@ } | ||
message?: string; | ||
data?: undefined | JsonValue; | ||
data?: unknown; | ||
} | ||
export declare class ErrorEvent extends Error { | ||
data: undefined | JsonValue; | ||
data: unknown; | ||
constructor(options?: ErrorEventOptions); | ||
} | ||
export declare class UnknownEvent extends ErrorEvent { | ||
} | ||
//# sourceMappingURL=errors.d.ts.map |
import type { EventMessage } from './types'; | ||
export type EventMeta = Partial<Pick<EventMessage, 'retry' | 'id'>>; | ||
export declare function isEventMetaContainer(value: unknown): value is Record<PropertyKey, unknown>; | ||
export declare function withEventMeta<T extends object>(container: T, meta: EventMeta): T; | ||
export declare function getEventMeta(container: unknown): EventMeta | undefined; | ||
//# sourceMappingURL=meta.d.ts.map |
export interface EventMessage { | ||
event: string | undefined; | ||
id: string | undefined; | ||
data: string; | ||
data: string | undefined; | ||
/** | ||
@@ -9,3 +9,4 @@ * The number of milliseconds to wait before retrying the event source if error occurs. | ||
retry: number | undefined; | ||
comments: string[]; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
@@ -1,7 +0,5 @@ | ||
import type { JsonValue } from 'type-fest'; | ||
export type { JsonValue }; | ||
export interface StandardHeaders { | ||
[key: string]: string | string[] | undefined; | ||
} | ||
export type StandardBody = undefined | JsonValue | Blob | URLSearchParams | FormData | AsyncIterator<JsonValue | void, JsonValue | void, undefined>; | ||
export type StandardBody = undefined | unknown | Blob | URLSearchParams | FormData | AsyncIterator<unknown | void, unknown | void, undefined>; | ||
export interface StandardRequest { | ||
@@ -8,0 +6,0 @@ /** |
@@ -1,6 +0,2 @@ | ||
import type { JsonValue } from 'type-fest'; | ||
export declare function once<T extends () => any>(fn: T): () => ReturnType<T>; | ||
export declare function parseEmptyableJSON(text: string): JsonValue | undefined; | ||
export declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>; | ||
export { contentDisposition, parse as parseContentDisposition } from '@tinyhttp/content-disposition'; | ||
//# sourceMappingURL=utils.d.ts.map |
{ | ||
"name": "@orpc/standard-server", | ||
"type": "module", | ||
"version": "0.0.0-next.7e41bc4", | ||
"version": "0.0.0-next.92faaf9", | ||
"license": "MIT", | ||
@@ -32,3 +32,3 @@ "homepage": "https://unnoq.com", | ||
"@tinyhttp/content-disposition": "^2.2.2", | ||
"type-fest": "^4.34.1" | ||
"@orpc/shared": "0.0.0-next.92faaf9" | ||
}, | ||
@@ -35,0 +35,0 @@ "scripts": { |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
14229
13
1
69
261
+ Added@orpc/shared@0.0.0-next.92faaf9(transitive)
+ Addedradash@12.1.0(transitive)
- Removedtype-fest@^4.34.1