openart-realtime-sdk 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Upstash, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Realtime
2
+
3
+ The easiest way to add realtime features to any Next.js project.
4
+
5
+ ![Project Image](public/thumbnail.png)
6
+
7
+ ## Features
8
+
9
+ - โฐ Setup takes 60 seconds
10
+ - ๐Ÿงจ Clean APIs & first-class TypeScript support
11
+ - โšก Extremely fast, zero dependencies, 1.9kB gzipped
12
+ - ๐Ÿ’ป Deploy anywhere: Vercel, Netlify, etc.
13
+ - ๐Ÿ’Ž 100% type-safe with zod 4 or zod mini
14
+ - โฑ๏ธ Built-in message histories
15
+ - ๐Ÿ”Œ Automatic connection management w/ delivery guarantee
16
+ - ๐Ÿ”‹ Built-in middleware and authentication helpers
17
+ - ๐Ÿ“ถ 100% HTTP-based: Redis streams & SSE
18
+
19
+ ---
20
+
21
+ ## Quickstart
22
+
23
+ Check out the examples in the repository to get started.
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ var useRealtime_js = require('./use-realtime.js');
4
+ var provider_js = require('./provider.js');
5
+
6
+
7
+
8
+ Object.keys(useRealtime_js).forEach(function (k) {
9
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
10
+ enumerable: true,
11
+ get: function () { return useRealtime_js[k]; }
12
+ });
13
+ });
14
+ Object.keys(provider_js).forEach(function (k) {
15
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
16
+ enumerable: true,
17
+ get: function () { return provider_js[k]; }
18
+ });
19
+ });
@@ -0,0 +1,50 @@
1
+ import { EventPayloadUnion, EventPaths, ConnectionStatus, RealtimeMessage } from '../shared/index.cjs';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import React from 'react';
4
+ import 'zod/v4';
5
+ import 'zod/v4/core';
6
+
7
+ interface UseRealtimeOpts<T extends Record<string, unknown>, E extends string> {
8
+ events?: readonly E[];
9
+ onData?: (arg: EventPayloadUnion<T, E>) => void;
10
+ channels?: readonly (string | undefined)[];
11
+ enabled?: boolean;
12
+ }
13
+ declare function useRealtime<T extends Record<string, unknown>, const E extends EventPaths<T>>(opts: UseRealtimeOpts<T, E>): {
14
+ status: ConnectionStatus;
15
+ };
16
+
17
+ type RealtimeContextValue = {
18
+ status: ConnectionStatus;
19
+ register: (id: string, channels: string[], cb: (msg: RealtimeMessage) => void) => void;
20
+ unregister: (id: string) => void;
21
+ };
22
+ declare const RealtimeContext: React.Context<RealtimeContextValue | null>;
23
+ interface RealtimeProviderProps {
24
+ children: React.ReactNode;
25
+ api?: {
26
+ url?: string;
27
+ withCredentials?: boolean;
28
+ };
29
+ maxReconnectAttempts?: number;
30
+ /**
31
+ * Whether to disconnect when the window is hidden (e.g. switched tab).
32
+ * Defaults to true.
33
+ */
34
+ disconnectOnWindowHidden?: boolean;
35
+ /**
36
+ * Delay in ms before disconnecting when window is hidden.
37
+ * Useful to prevent flapping when user quickly switches tabs.
38
+ * Defaults to 5000ms.
39
+ */
40
+ disconnectDelay?: number;
41
+ }
42
+ declare function RealtimeProvider({ children, api, maxReconnectAttempts, disconnectOnWindowHidden, disconnectDelay }: RealtimeProviderProps): react_jsx_runtime.JSX.Element;
43
+ declare function useRealtimeContext(): RealtimeContextValue;
44
+ declare const createRealtime: <T extends Record<string, unknown>>() => {
45
+ useRealtime: <const E extends EventPaths<T>>(opts: UseRealtimeOpts<T, E>) => {
46
+ status: ConnectionStatus;
47
+ };
48
+ };
49
+
50
+ export { RealtimeContext, RealtimeProvider, type RealtimeProviderProps, type UseRealtimeOpts, createRealtime, useRealtime, useRealtimeContext };
@@ -0,0 +1,50 @@
1
+ import { EventPayloadUnion, EventPaths, ConnectionStatus, RealtimeMessage } from '../shared/index.js';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import React from 'react';
4
+ import 'zod/v4';
5
+ import 'zod/v4/core';
6
+
7
+ interface UseRealtimeOpts<T extends Record<string, unknown>, E extends string> {
8
+ events?: readonly E[];
9
+ onData?: (arg: EventPayloadUnion<T, E>) => void;
10
+ channels?: readonly (string | undefined)[];
11
+ enabled?: boolean;
12
+ }
13
+ declare function useRealtime<T extends Record<string, unknown>, const E extends EventPaths<T>>(opts: UseRealtimeOpts<T, E>): {
14
+ status: ConnectionStatus;
15
+ };
16
+
17
+ type RealtimeContextValue = {
18
+ status: ConnectionStatus;
19
+ register: (id: string, channels: string[], cb: (msg: RealtimeMessage) => void) => void;
20
+ unregister: (id: string) => void;
21
+ };
22
+ declare const RealtimeContext: React.Context<RealtimeContextValue | null>;
23
+ interface RealtimeProviderProps {
24
+ children: React.ReactNode;
25
+ api?: {
26
+ url?: string;
27
+ withCredentials?: boolean;
28
+ };
29
+ maxReconnectAttempts?: number;
30
+ /**
31
+ * Whether to disconnect when the window is hidden (e.g. switched tab).
32
+ * Defaults to true.
33
+ */
34
+ disconnectOnWindowHidden?: boolean;
35
+ /**
36
+ * Delay in ms before disconnecting when window is hidden.
37
+ * Useful to prevent flapping when user quickly switches tabs.
38
+ * Defaults to 5000ms.
39
+ */
40
+ disconnectDelay?: number;
41
+ }
42
+ declare function RealtimeProvider({ children, api, maxReconnectAttempts, disconnectOnWindowHidden, disconnectDelay }: RealtimeProviderProps): react_jsx_runtime.JSX.Element;
43
+ declare function useRealtimeContext(): RealtimeContextValue;
44
+ declare const createRealtime: <T extends Record<string, unknown>>() => {
45
+ useRealtime: <const E extends EventPaths<T>>(opts: UseRealtimeOpts<T, E>) => {
46
+ status: ConnectionStatus;
47
+ };
48
+ };
49
+
50
+ export { RealtimeContext, RealtimeProvider, type RealtimeProviderProps, type UseRealtimeOpts, createRealtime, useRealtime, useRealtimeContext };
@@ -0,0 +1,2 @@
1
+ export * from './use-realtime.js';
2
+ export * from './provider.js';
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ var handler_js = require('./handler.js');
4
+ var realtime_js = require('./realtime.js');
5
+
6
+
7
+
8
+ Object.keys(handler_js).forEach(function (k) {
9
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
10
+ enumerable: true,
11
+ get: function () { return handler_js[k]; }
12
+ });
13
+ });
14
+ Object.keys(realtime_js).forEach(function (k) {
15
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
16
+ enumerable: true,
17
+ get: function () { return realtime_js[k]; }
18
+ });
19
+ });
@@ -0,0 +1,86 @@
1
+ import Redis from 'ioredis';
2
+ import * as z from 'zod/v4/core';
3
+ import { Logger, EventPaths, EventPayloadUnion, HistoryArgs, SystemEvent, UserEvent } from '../shared/index.cjs';
4
+ import 'zod/v4';
5
+
6
+ type Schema = Record<string, z.$ZodType | Record<string, unknown>>;
7
+ type HistoryConfig = {
8
+ maxLength?: number;
9
+ expireAfterSecs?: number;
10
+ };
11
+ type Opts = {
12
+ schema?: Schema;
13
+ redis?: Redis | undefined;
14
+ maxDurationSecs?: number;
15
+ verbose?: boolean;
16
+ logger?: Logger;
17
+ history?: HistoryConfig | boolean;
18
+ };
19
+ declare class RealtimeBase<T extends Opts> {
20
+ private channels;
21
+ private _schema;
22
+ private _verbose;
23
+ private _history;
24
+ constructor(data: T);
25
+ private createEventHandlers;
26
+ channel<N extends string>(channel: N, history?: HistoryConfig | boolean): RealtimeChannel<T>;
27
+ }
28
+ type SchemaPaths<T, Prefix extends string = ""> = {
29
+ [K in keyof T]: K extends string ? T[K] extends z.$ZodType ? Prefix extends "" ? K : `${Prefix}${K}` : T[K] extends object ? SchemaPaths<T[K], `${Prefix}${K}.`> : never : never;
30
+ }[keyof T];
31
+ type EventPath<T extends Opts> = T["schema"] extends Schema ? SchemaPaths<T["schema"]> : never;
32
+ type SchemaValue<T, Path extends string> = Path extends `${infer First}.${infer Rest}` ? First extends keyof T ? SchemaValue<T[First], Rest> : never : Path extends keyof T ? T[Path] : never;
33
+ type EventData<T extends Opts, K extends string> = T["schema"] extends Schema ? SchemaValue<T["schema"], K> extends z.$ZodType ? z.infer<SchemaValue<T["schema"], K>> : never : never;
34
+ type HistoryMessage = {
35
+ id: string;
36
+ event: string;
37
+ channel: string;
38
+ data: unknown;
39
+ };
40
+ type SubscribeArgs<T extends Opts, E extends EventPaths<T["schema"]>> = {
41
+ events: readonly E[];
42
+ onData: (arg: EventPayloadUnion<T["schema"], E>) => void;
43
+ history?: boolean | HistoryArgs;
44
+ };
45
+ type RealtimeChannel<T extends Opts> = {
46
+ subscribe: <E extends EventPaths<T["schema"]>>(args: SubscribeArgs<T, E>) => Promise<() => void>;
47
+ unsubscribe: () => void;
48
+ emit: <K extends EventPath<T>>(event: K, data: EventData<T, K>, opts?: {
49
+ history?: HistoryConfig | boolean;
50
+ }) => Promise<void>;
51
+ history: (params?: HistoryArgs) => Promise<HistoryMessage[]>;
52
+ };
53
+ type InferSchemaRecursive<T> = {
54
+ [K in keyof T]: T[K] extends z.$ZodType ? z.infer<T[K]> : T[K] extends object ? InferSchemaRecursive<T[K]> : never;
55
+ };
56
+ type InferSchema<T extends Schema> = InferSchemaRecursive<T>;
57
+ type InferRealtimeEvents<T> = T extends Realtime<infer R> ? NonNullable<R["schema"]> : never;
58
+ type Realtime<T extends Opts> = RealtimeBase<T> & {
59
+ channel: (name: string, history?: HistoryConfig | boolean) => RealtimeChannel<T>;
60
+ } & RealtimeChannel<T>;
61
+ declare const Realtime: new <T extends Opts>(data?: T) => Realtime<T>;
62
+
63
+ declare function handle<T extends Opts>(config: {
64
+ realtime: Realtime<T>;
65
+ /**
66
+ * Maximum number of missed messages to retrieve from history upon reconnection.
67
+ * Defaults to 2000. Increase this if your application expects high message volume
68
+ * and needs to ensure clients catch up on all history after long disconnections.
69
+ * Warning: Setting this too high may cause memory issues on the server.
70
+ */
71
+ maxRecoveryLimit?: number;
72
+ /**
73
+ * Middleware to authorize the request (e.g. check session cookie, check channel permissions).
74
+ * Return a Response to block the request, or nothing to allow.
75
+ */
76
+ middleware?: ({ request, channels, }: {
77
+ request: Request;
78
+ channels: string[];
79
+ }) => Response | void | Promise<Response | void>;
80
+ }): (request: Request) => Promise<Response | void>;
81
+ declare function json(data: SystemEvent | UserEvent): Uint8Array<ArrayBuffer>;
82
+ declare class StreamingResponse extends Response {
83
+ constructor(res: ReadableStream<Uint8Array>, init?: ResponseInit);
84
+ }
85
+
86
+ export { type EventData, type EventPath, type HistoryConfig, type HistoryMessage, type InferRealtimeEvents, type InferSchema, type Opts, Realtime, StreamingResponse, handle, json };
@@ -0,0 +1,86 @@
1
+ import Redis from 'ioredis';
2
+ import * as z from 'zod/v4/core';
3
+ import { Logger, EventPaths, EventPayloadUnion, HistoryArgs, SystemEvent, UserEvent } from '../shared/index.js';
4
+ import 'zod/v4';
5
+
6
+ type Schema = Record<string, z.$ZodType | Record<string, unknown>>;
7
+ type HistoryConfig = {
8
+ maxLength?: number;
9
+ expireAfterSecs?: number;
10
+ };
11
+ type Opts = {
12
+ schema?: Schema;
13
+ redis?: Redis | undefined;
14
+ maxDurationSecs?: number;
15
+ verbose?: boolean;
16
+ logger?: Logger;
17
+ history?: HistoryConfig | boolean;
18
+ };
19
+ declare class RealtimeBase<T extends Opts> {
20
+ private channels;
21
+ private _schema;
22
+ private _verbose;
23
+ private _history;
24
+ constructor(data: T);
25
+ private createEventHandlers;
26
+ channel<N extends string>(channel: N, history?: HistoryConfig | boolean): RealtimeChannel<T>;
27
+ }
28
+ type SchemaPaths<T, Prefix extends string = ""> = {
29
+ [K in keyof T]: K extends string ? T[K] extends z.$ZodType ? Prefix extends "" ? K : `${Prefix}${K}` : T[K] extends object ? SchemaPaths<T[K], `${Prefix}${K}.`> : never : never;
30
+ }[keyof T];
31
+ type EventPath<T extends Opts> = T["schema"] extends Schema ? SchemaPaths<T["schema"]> : never;
32
+ type SchemaValue<T, Path extends string> = Path extends `${infer First}.${infer Rest}` ? First extends keyof T ? SchemaValue<T[First], Rest> : never : Path extends keyof T ? T[Path] : never;
33
+ type EventData<T extends Opts, K extends string> = T["schema"] extends Schema ? SchemaValue<T["schema"], K> extends z.$ZodType ? z.infer<SchemaValue<T["schema"], K>> : never : never;
34
+ type HistoryMessage = {
35
+ id: string;
36
+ event: string;
37
+ channel: string;
38
+ data: unknown;
39
+ };
40
+ type SubscribeArgs<T extends Opts, E extends EventPaths<T["schema"]>> = {
41
+ events: readonly E[];
42
+ onData: (arg: EventPayloadUnion<T["schema"], E>) => void;
43
+ history?: boolean | HistoryArgs;
44
+ };
45
+ type RealtimeChannel<T extends Opts> = {
46
+ subscribe: <E extends EventPaths<T["schema"]>>(args: SubscribeArgs<T, E>) => Promise<() => void>;
47
+ unsubscribe: () => void;
48
+ emit: <K extends EventPath<T>>(event: K, data: EventData<T, K>, opts?: {
49
+ history?: HistoryConfig | boolean;
50
+ }) => Promise<void>;
51
+ history: (params?: HistoryArgs) => Promise<HistoryMessage[]>;
52
+ };
53
+ type InferSchemaRecursive<T> = {
54
+ [K in keyof T]: T[K] extends z.$ZodType ? z.infer<T[K]> : T[K] extends object ? InferSchemaRecursive<T[K]> : never;
55
+ };
56
+ type InferSchema<T extends Schema> = InferSchemaRecursive<T>;
57
+ type InferRealtimeEvents<T> = T extends Realtime<infer R> ? NonNullable<R["schema"]> : never;
58
+ type Realtime<T extends Opts> = RealtimeBase<T> & {
59
+ channel: (name: string, history?: HistoryConfig | boolean) => RealtimeChannel<T>;
60
+ } & RealtimeChannel<T>;
61
+ declare const Realtime: new <T extends Opts>(data?: T) => Realtime<T>;
62
+
63
+ declare function handle<T extends Opts>(config: {
64
+ realtime: Realtime<T>;
65
+ /**
66
+ * Maximum number of missed messages to retrieve from history upon reconnection.
67
+ * Defaults to 2000. Increase this if your application expects high message volume
68
+ * and needs to ensure clients catch up on all history after long disconnections.
69
+ * Warning: Setting this too high may cause memory issues on the server.
70
+ */
71
+ maxRecoveryLimit?: number;
72
+ /**
73
+ * Middleware to authorize the request (e.g. check session cookie, check channel permissions).
74
+ * Return a Response to block the request, or nothing to allow.
75
+ */
76
+ middleware?: ({ request, channels, }: {
77
+ request: Request;
78
+ channels: string[];
79
+ }) => Response | void | Promise<Response | void>;
80
+ }): (request: Request) => Promise<Response | void>;
81
+ declare function json(data: SystemEvent | UserEvent): Uint8Array<ArrayBuffer>;
82
+ declare class StreamingResponse extends Response {
83
+ constructor(res: ReadableStream<Uint8Array>, init?: ResponseInit);
84
+ }
85
+
86
+ export { type EventData, type EventPath, type HistoryConfig, type HistoryMessage, type InferRealtimeEvents, type InferSchema, type Opts, Realtime, StreamingResponse, handle, json };
@@ -0,0 +1,2 @@
1
+ export * from './handler.js';
2
+ export * from './realtime.js';
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ var types = require('./types');
4
+
5
+
6
+
7
+ Object.keys(types).forEach(function (k) {
8
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
9
+ enumerable: true,
10
+ get: function () { return types[k]; }
11
+ });
12
+ });
@@ -0,0 +1,64 @@
1
+ import z from 'zod/v4';
2
+ import z__default from 'zod/v4/core';
3
+
4
+ declare const systemEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
5
+ type: z.ZodLiteral<"connected">;
6
+ channel: z.ZodString;
7
+ cursor: z.ZodOptional<z.ZodString>;
8
+ }, z.core.$strip>, z.ZodObject<{
9
+ type: z.ZodLiteral<"reconnect">;
10
+ timestamp: z.ZodNumber;
11
+ }, z.core.$strip>, z.ZodObject<{
12
+ type: z.ZodLiteral<"error">;
13
+ error: z.ZodString;
14
+ }, z.core.$strip>, z.ZodObject<{
15
+ type: z.ZodLiteral<"disconnected">;
16
+ channels: z.ZodArray<z.ZodString>;
17
+ }, z.core.$strip>, z.ZodObject<{
18
+ type: z.ZodLiteral<"ping">;
19
+ timestamp: z.ZodNumber;
20
+ }, z.core.$strip>], "type">;
21
+ type SystemEvent = z.infer<typeof systemEvent>;
22
+ declare const userEvent: z.ZodObject<{
23
+ id: z.ZodString;
24
+ data: z.ZodUnknown;
25
+ event: z.ZodString;
26
+ channel: z.ZodString;
27
+ }, z.core.$strip>;
28
+ type UserEvent = z.infer<typeof userEvent>;
29
+ type RealtimeMessage = SystemEvent | UserEvent;
30
+ type ConnectionStatus = "connected" | "disconnected" | "error" | "connecting";
31
+ type EventPaths<T, Prefix extends string = "", Depth extends readonly number[] = []> = Depth["length"] extends 10 ? never : {
32
+ [K in keyof T & string]: T[K] extends z__default.$ZodType ? `${Prefix}${K}` : T[K] extends Record<string, unknown> ? EventPaths<T[K], `${Prefix}${K}.`, [...Depth, 0]> : `${Prefix}${K}`;
33
+ }[keyof T & string];
34
+ type EventData<T, K extends string, Depth extends readonly number[] = []> = Depth["length"] extends 10 ? never : K extends `${infer A}.${infer Rest}` ? A extends keyof T ? T[A] extends z__default.$ZodType ? never : EventData<T[A], Rest, [...Depth, 0]> : never : K extends keyof T ? T[K] extends z__default.$ZodType ? T[K] : never : never;
35
+ type EventPayloadUnion<T, E extends string> = E extends unknown ? {
36
+ event: E;
37
+ data: z__default.infer<EventData<T, E>>;
38
+ channel: string;
39
+ } : never;
40
+ type HistoryArgs = {
41
+ limit?: number;
42
+ start?: number;
43
+ end?: number;
44
+ };
45
+ interface Logger {
46
+ info(message: string, ...args: unknown[]): void;
47
+ warn(message: string, ...args: unknown[]): void;
48
+ error(message: string, ...args: unknown[]): void;
49
+ debug?(message: string, ...args: unknown[]): void;
50
+ }
51
+ interface RealtimeConfig {
52
+ /**
53
+ * Enable debug logging
54
+ * @default false
55
+ */
56
+ debug?: boolean;
57
+ /**
58
+ * Custom logger implementation
59
+ * @default console
60
+ */
61
+ logger?: Logger;
62
+ }
63
+
64
+ export { type ConnectionStatus, type EventPaths, type EventPayloadUnion, type HistoryArgs, type Logger, type RealtimeConfig, type RealtimeMessage, type SystemEvent, type UserEvent, systemEvent, userEvent };
@@ -0,0 +1,64 @@
1
+ import z from 'zod/v4';
2
+ import z__default from 'zod/v4/core';
3
+
4
+ declare const systemEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
5
+ type: z.ZodLiteral<"connected">;
6
+ channel: z.ZodString;
7
+ cursor: z.ZodOptional<z.ZodString>;
8
+ }, z.core.$strip>, z.ZodObject<{
9
+ type: z.ZodLiteral<"reconnect">;
10
+ timestamp: z.ZodNumber;
11
+ }, z.core.$strip>, z.ZodObject<{
12
+ type: z.ZodLiteral<"error">;
13
+ error: z.ZodString;
14
+ }, z.core.$strip>, z.ZodObject<{
15
+ type: z.ZodLiteral<"disconnected">;
16
+ channels: z.ZodArray<z.ZodString>;
17
+ }, z.core.$strip>, z.ZodObject<{
18
+ type: z.ZodLiteral<"ping">;
19
+ timestamp: z.ZodNumber;
20
+ }, z.core.$strip>], "type">;
21
+ type SystemEvent = z.infer<typeof systemEvent>;
22
+ declare const userEvent: z.ZodObject<{
23
+ id: z.ZodString;
24
+ data: z.ZodUnknown;
25
+ event: z.ZodString;
26
+ channel: z.ZodString;
27
+ }, z.core.$strip>;
28
+ type UserEvent = z.infer<typeof userEvent>;
29
+ type RealtimeMessage = SystemEvent | UserEvent;
30
+ type ConnectionStatus = "connected" | "disconnected" | "error" | "connecting";
31
+ type EventPaths<T, Prefix extends string = "", Depth extends readonly number[] = []> = Depth["length"] extends 10 ? never : {
32
+ [K in keyof T & string]: T[K] extends z__default.$ZodType ? `${Prefix}${K}` : T[K] extends Record<string, unknown> ? EventPaths<T[K], `${Prefix}${K}.`, [...Depth, 0]> : `${Prefix}${K}`;
33
+ }[keyof T & string];
34
+ type EventData<T, K extends string, Depth extends readonly number[] = []> = Depth["length"] extends 10 ? never : K extends `${infer A}.${infer Rest}` ? A extends keyof T ? T[A] extends z__default.$ZodType ? never : EventData<T[A], Rest, [...Depth, 0]> : never : K extends keyof T ? T[K] extends z__default.$ZodType ? T[K] : never : never;
35
+ type EventPayloadUnion<T, E extends string> = E extends unknown ? {
36
+ event: E;
37
+ data: z__default.infer<EventData<T, E>>;
38
+ channel: string;
39
+ } : never;
40
+ type HistoryArgs = {
41
+ limit?: number;
42
+ start?: number;
43
+ end?: number;
44
+ };
45
+ interface Logger {
46
+ info(message: string, ...args: unknown[]): void;
47
+ warn(message: string, ...args: unknown[]): void;
48
+ error(message: string, ...args: unknown[]): void;
49
+ debug?(message: string, ...args: unknown[]): void;
50
+ }
51
+ interface RealtimeConfig {
52
+ /**
53
+ * Enable debug logging
54
+ * @default false
55
+ */
56
+ debug?: boolean;
57
+ /**
58
+ * Custom logger implementation
59
+ * @default console
60
+ */
61
+ logger?: Logger;
62
+ }
63
+
64
+ export { type ConnectionStatus, type EventPaths, type EventPayloadUnion, type HistoryArgs, type Logger, type RealtimeConfig, type RealtimeMessage, type SystemEvent, type UserEvent, systemEvent, userEvent };
@@ -0,0 +1 @@
1
+ export * from './types';
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "openart-realtime-sdk",
3
+ "version": "1.0.1",
4
+ "author": "OpenArt",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/hui200102/realtime.git"
8
+ },
9
+ "main": "dist/server/index.js",
10
+ "module": "dist/server/index.js",
11
+ "devDependencies": {
12
+ "@types/node": "^24.6.0",
13
+ "@types/react": "^19.1.16",
14
+ "@types/react-dom": "^19.1.9",
15
+ "@types/ioredis-mock": "^8.2.5",
16
+ "tsup": "^8.5.0",
17
+ "typescript": "^5.9.2",
18
+ "vitest": "^2.1.8",
19
+ "tsx": "^4.7.0",
20
+ "@testing-library/react": "^16.1.0",
21
+ "@testing-library/dom": "^10.4.0",
22
+ "jsdom": "^25.0.1",
23
+ "ioredis-mock": "^8.9.0",
24
+ "zod": "^4.1.11"
25
+ },
26
+ "peerDependencies": {
27
+ "ioredis": "^5.4.0",
28
+ "zod": "^3.25.0 || ^4.0.0",
29
+ "react": ">=16.8.0",
30
+ "react-dom": ">=16.8.0"
31
+ },
32
+ "peerDependenciesMeta": {
33
+ "react": {
34
+ "optional": true
35
+ },
36
+ "react-dom": {
37
+ "optional": true
38
+ }
39
+ },
40
+ "exports": {
41
+ ".": {
42
+ "import": {
43
+ "types": "./dist/server/index.d.ts",
44
+ "default": "./dist/server/index.js"
45
+ },
46
+ "require": {
47
+ "types": "./dist/server/index.d.ts",
48
+ "default": "./dist/server/index.js"
49
+ }
50
+ },
51
+ "./client": {
52
+ "import": {
53
+ "types": "./dist/client/index.d.ts",
54
+ "default": "./dist/client/index.js"
55
+ },
56
+ "require": {
57
+ "types": "./dist/client/index.d.ts",
58
+ "default": "./dist/client/index.js"
59
+ }
60
+ }
61
+ },
62
+ "access": "public",
63
+ "description": "An HTTP-based realtime client powered by Redis Streams.",
64
+ "files": [
65
+ "dist"
66
+ ],
67
+ "homepage": "https://github.com/realtime-framework/realtime",
68
+ "keywords": [
69
+ "realtime",
70
+ "serverless"
71
+ ],
72
+ "license": "MIT",
73
+ "scripts": {
74
+ "build": "tsup",
75
+ "prepublishOnly": "npm run build",
76
+ "lint": "tsc",
77
+ "test": "vitest",
78
+ "benchmark": "tsx benchmark/stress.ts",
79
+ "release": "npm publish --access public && git push --follow-tags"
80
+ },
81
+ "type": "module",
82
+ "types": "dist/server/index.d.ts"
83
+ }