@bunworks/inngest-realtime 0.1.0 → 0.1.5
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/CHANGELOG.md +6 -6
- package/README.md +1 -1
- package/_virtual/_rolldown/runtime.cjs +29 -0
- package/api.cjs +45 -0
- package/api.cjs.map +1 -0
- package/api.mjs +44 -0
- package/api.mjs.map +1 -0
- package/channel.cjs +67 -0
- package/channel.cjs.map +1 -0
- package/channel.d.cts +19 -0
- package/channel.d.cts.map +1 -0
- package/channel.d.mts +19 -0
- package/channel.d.mts.map +1 -0
- package/channel.mjs +66 -0
- package/channel.mjs.map +1 -0
- package/env.cjs +72 -0
- package/env.cjs.map +1 -0
- package/env.mjs +71 -0
- package/env.mjs.map +1 -0
- package/hooks.cjs +147 -0
- package/hooks.cjs.map +1 -0
- package/hooks.d.cts +70 -0
- package/hooks.d.cts.map +1 -0
- package/hooks.d.mts +70 -0
- package/hooks.d.mts.map +1 -0
- package/hooks.mjs +144 -0
- package/hooks.mjs.map +1 -0
- package/index.cjs +19 -0
- package/index.d.cts +5 -0
- package/index.d.mts +6 -0
- package/index.mjs +7 -0
- package/middleware.cjs +41 -0
- package/middleware.cjs.map +1 -0
- package/middleware.d.cts +29 -0
- package/middleware.d.cts.map +1 -0
- package/middleware.d.mts +29 -0
- package/middleware.d.mts.map +1 -0
- package/middleware.mjs +34 -0
- package/middleware.mjs.map +1 -0
- package/package.json +6 -5
- package/subscribe/StreamFanout.cjs +47 -0
- package/subscribe/StreamFanout.cjs.map +1 -0
- package/subscribe/StreamFanout.mjs +46 -0
- package/subscribe/StreamFanout.mjs.map +1 -0
- package/subscribe/TokenSubscription.cjs +438 -0
- package/subscribe/TokenSubscription.cjs.map +1 -0
- package/subscribe/TokenSubscription.mjs +436 -0
- package/subscribe/TokenSubscription.mjs.map +1 -0
- package/subscribe/helpers.cjs +41 -0
- package/subscribe/helpers.cjs.map +1 -0
- package/subscribe/helpers.d.cts +64 -0
- package/subscribe/helpers.d.cts.map +1 -0
- package/subscribe/helpers.d.mts +64 -0
- package/subscribe/helpers.d.mts.map +1 -0
- package/subscribe/helpers.mjs +40 -0
- package/subscribe/helpers.mjs.map +1 -0
- package/subscribe/index.cjs +1 -0
- package/subscribe/index.d.mts +1 -0
- package/subscribe/index.mjs +3 -0
- package/topic.cjs +30 -0
- package/topic.cjs.map +1 -0
- package/topic.d.cts +19 -0
- package/topic.d.cts.map +1 -0
- package/topic.d.mts +19 -0
- package/topic.d.mts.map +1 -0
- package/topic.mjs +28 -0
- package/topic.mjs.map +1 -0
- package/types.cjs +45 -0
- package/types.cjs.map +1 -0
- package/types.d.cts +241 -0
- package/types.d.cts.map +1 -0
- package/types.d.mts +241 -0
- package/types.d.mts.map +1 -0
- package/types.mjs +39 -0
- package/types.mjs.map +1 -0
- package/util.cjs +72 -0
- package/util.cjs.map +1 -0
- package/util.mjs +69 -0
- package/util.mjs.map +1 -0
- package/CLAUDE.md +0 -69
- package/bun.lock +0 -527
- package/eslint.config.mjs +0 -19
- package/src/api.ts +0 -83
- package/src/channel.ts +0 -122
- package/src/env.d.ts +0 -15
- package/src/env.ts +0 -152
- package/src/hooks.ts +0 -256
- package/src/index.test.ts +0 -840
- package/src/index.ts +0 -4
- package/src/middleware.ts +0 -68
- package/src/subscribe/StreamFanout.ts +0 -82
- package/src/subscribe/TokenSubscription.ts +0 -524
- package/src/subscribe/helpers.ts +0 -153
- package/src/subscribe/index.ts +0 -1
- package/src/topic.ts +0 -51
- package/src/types.ts +0 -499
- package/src/util.ts +0 -104
- package/tsconfig.build.json +0 -7
- package/tsconfig.json +0 -114
- package/tsdown.config.ts +0 -18
- package/vitest.config.ts +0 -22
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Realtime } from "../types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/subscribe/helpers.d.ts
|
|
4
|
+
interface InngestApp {
|
|
5
|
+
apiBaseUrl?: string;
|
|
6
|
+
api?: {
|
|
7
|
+
signingKey?: string;
|
|
8
|
+
signingKeyFallback?: string;
|
|
9
|
+
getSubscriptionToken?: (channelId: string, topics: string[]) => Promise<string>;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Subscribe to a realtime channel
|
|
14
|
+
*/
|
|
15
|
+
declare const subscribe: <const InputChannel extends Realtime.Channel | string, const InputTopics extends (keyof Realtime.Channel.InferTopics<Realtime.Channel.AsChannel<InputChannel>> & string)[], const TToken extends Realtime.Subscribe.Token<Realtime.Channel.AsChannel<InputChannel>, InputTopics>, const TOutput extends Realtime.Subscribe.StreamSubscription<TToken>>(
|
|
16
|
+
/**
|
|
17
|
+
* Subscription token with settings
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
token: {
|
|
21
|
+
/**
|
|
22
|
+
* Inngest app instance
|
|
23
|
+
*/
|
|
24
|
+
app?: InngestApp;
|
|
25
|
+
/**
|
|
26
|
+
* Channel ID or channel object
|
|
27
|
+
*/
|
|
28
|
+
channel: Realtime.Subscribe.InferChannelInput<InputChannel>;
|
|
29
|
+
/**
|
|
30
|
+
* List of topics to subscribe to
|
|
31
|
+
*/
|
|
32
|
+
topics: InputTopics;
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Callback to handle messages
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
callback?: Realtime.Subscribe.Callback<TToken>) => Promise<TOutput>;
|
|
39
|
+
/**
|
|
40
|
+
* Get subscription token
|
|
41
|
+
*/
|
|
42
|
+
declare const getSubscriptionToken: <const InputChannel extends Realtime.Channel | string, const InputTopics extends (keyof Realtime.Channel.InferTopics<Realtime.Channel.AsChannel<InputChannel>> & string)[], const TToken extends Realtime.Subscribe.Token<Realtime.Channel.AsChannel<InputChannel>, InputTopics>>(
|
|
43
|
+
/**
|
|
44
|
+
* Inngest app instance
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
app: InngestApp,
|
|
48
|
+
/**
|
|
49
|
+
* Subscription parameters
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
args: {
|
|
53
|
+
/**
|
|
54
|
+
* Channel ID or channel object
|
|
55
|
+
*/
|
|
56
|
+
channel: Realtime.Subscribe.InferChannelInput<InputChannel>;
|
|
57
|
+
/**
|
|
58
|
+
* List of topics
|
|
59
|
+
*/
|
|
60
|
+
topics: InputTopics;
|
|
61
|
+
}) => Promise<TToken>;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { InngestApp, getSubscriptionToken, subscribe };
|
|
64
|
+
//# sourceMappingURL=helpers.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.cts","names":[],"sources":["../../src/subscribe/helpers.ts"],"mappings":";;;UAIiB,UAAA;EACf,UAAA;EACA,GAAA;IACE,UAAA;IACA,kBAAA;IACA,oBAAA,IACE,SAAA,UACA,MAAA,eACG,OAAA;EAAA;AAAA;;;;cAOI,SAAA,8BACgB,QAAA,CAAS,OAAA,4CACH,QAAA,CAAS,OAAA,CAAQ,WAAA,CAChD,QAAA,CAAS,OAAA,CAAQ,SAAA,CAAU,YAAA,qCAGR,QAAA,CAAS,SAAA,CAAU,KAAA,CACtC,QAAA,CAAS,OAAA,CAAQ,SAAA,CAAU,YAAA,GAC3B,WAAA,yBAEoB,QAAA,CAAS,SAAA,CAAU,kBAAA,CAAmB,MAAA;;;;;AAK5D,KAAA;EAfW;;;EAmBT,GAAA,GAAM,UAAA;EAhBqB;;;EAqB3B,OAAA,EAAS,QAAA,CAAS,SAAA,CAAU,iBAAA,CAAkB,YAAA;EAjB9C;;;EAsBA,MAAA,EAAQ,WAAA;AAAA;;;;;AAMV,QAAA,GAAW,QAAA,CAAS,SAAA,CAAU,QAAA,CAAS,MAAA,MACtC,OAAA,CAAQ,OAAA;;;;cA6CE,oBAAA,8BACgB,QAAA,CAAS,OAAA,4CACH,QAAA,CAAS,OAAA,CAAQ,WAAA,CAChD,QAAA,CAAS,OAAA,CAAQ,SAAA,CAAU,YAAA,qCAGR,QAAA,CAAS,SAAA,CAAU,KAAA,CACtC,QAAA,CAAS,OAAA,CAAQ,SAAA,CAAU,YAAA,GAC3B,WAAA;;;;;AAMF,GAAA,EAAK,UAAA;;;;;AAKL,IAAA;EAlGkD;;;EAsGhD,OAAA,EAAS,QAAA,CAAS,SAAA,CAAU,iBAAA,CAAkB,YAAA;EArGnB;;;EA0G3B,MAAA,EAAQ,WAAA;AAAA,MAET,OAAA,CAAQ,MAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Realtime } from "../types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/subscribe/helpers.d.ts
|
|
4
|
+
interface InngestApp {
|
|
5
|
+
apiBaseUrl?: string;
|
|
6
|
+
api?: {
|
|
7
|
+
signingKey?: string;
|
|
8
|
+
signingKeyFallback?: string;
|
|
9
|
+
getSubscriptionToken?: (channelId: string, topics: string[]) => Promise<string>;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Subscribe to a realtime channel
|
|
14
|
+
*/
|
|
15
|
+
declare const subscribe: <const InputChannel extends Realtime.Channel | string, const InputTopics extends (keyof Realtime.Channel.InferTopics<Realtime.Channel.AsChannel<InputChannel>> & string)[], const TToken extends Realtime.Subscribe.Token<Realtime.Channel.AsChannel<InputChannel>, InputTopics>, const TOutput extends Realtime.Subscribe.StreamSubscription<TToken>>(
|
|
16
|
+
/**
|
|
17
|
+
* Subscription token with settings
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
token: {
|
|
21
|
+
/**
|
|
22
|
+
* Inngest app instance
|
|
23
|
+
*/
|
|
24
|
+
app?: InngestApp;
|
|
25
|
+
/**
|
|
26
|
+
* Channel ID or channel object
|
|
27
|
+
*/
|
|
28
|
+
channel: Realtime.Subscribe.InferChannelInput<InputChannel>;
|
|
29
|
+
/**
|
|
30
|
+
* List of topics to subscribe to
|
|
31
|
+
*/
|
|
32
|
+
topics: InputTopics;
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Callback to handle messages
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
callback?: Realtime.Subscribe.Callback<TToken>) => Promise<TOutput>;
|
|
39
|
+
/**
|
|
40
|
+
* Get subscription token
|
|
41
|
+
*/
|
|
42
|
+
declare const getSubscriptionToken: <const InputChannel extends Realtime.Channel | string, const InputTopics extends (keyof Realtime.Channel.InferTopics<Realtime.Channel.AsChannel<InputChannel>> & string)[], const TToken extends Realtime.Subscribe.Token<Realtime.Channel.AsChannel<InputChannel>, InputTopics>>(
|
|
43
|
+
/**
|
|
44
|
+
* Inngest app instance
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
app: InngestApp,
|
|
48
|
+
/**
|
|
49
|
+
* Subscription parameters
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
args: {
|
|
53
|
+
/**
|
|
54
|
+
* Channel ID or channel object
|
|
55
|
+
*/
|
|
56
|
+
channel: Realtime.Subscribe.InferChannelInput<InputChannel>;
|
|
57
|
+
/**
|
|
58
|
+
* List of topics
|
|
59
|
+
*/
|
|
60
|
+
topics: InputTopics;
|
|
61
|
+
}) => Promise<TToken>;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { InngestApp, getSubscriptionToken, subscribe };
|
|
64
|
+
//# sourceMappingURL=helpers.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.mts","names":[],"sources":["../../src/subscribe/helpers.ts"],"mappings":";;;UAIiB,UAAA;EACf,UAAA;EACA,GAAA;IACE,UAAA;IACA,kBAAA;IACA,oBAAA,IACE,SAAA,UACA,MAAA,eACG,OAAA;EAAA;AAAA;;;;cAOI,SAAA,8BACgB,QAAA,CAAS,OAAA,4CACH,QAAA,CAAS,OAAA,CAAQ,WAAA,CAChD,QAAA,CAAS,OAAA,CAAQ,SAAA,CAAU,YAAA,qCAGR,QAAA,CAAS,SAAA,CAAU,KAAA,CACtC,QAAA,CAAS,OAAA,CAAQ,SAAA,CAAU,YAAA,GAC3B,WAAA,yBAEoB,QAAA,CAAS,SAAA,CAAU,kBAAA,CAAmB,MAAA;;;;;AAK5D,KAAA;EAfW;;;EAmBT,GAAA,GAAM,UAAA;EAhBqB;;;EAqB3B,OAAA,EAAS,QAAA,CAAS,SAAA,CAAU,iBAAA,CAAkB,YAAA;EAjB9C;;;EAsBA,MAAA,EAAQ,WAAA;AAAA;;;;;AAMV,QAAA,GAAW,QAAA,CAAS,SAAA,CAAU,QAAA,CAAS,MAAA,MACtC,OAAA,CAAQ,OAAA;;;;cA6CE,oBAAA,8BACgB,QAAA,CAAS,OAAA,4CACH,QAAA,CAAS,OAAA,CAAQ,WAAA,CAChD,QAAA,CAAS,OAAA,CAAQ,SAAA,CAAU,YAAA,qCAGR,QAAA,CAAS,SAAA,CAAU,KAAA,CACtC,QAAA,CAAS,OAAA,CAAQ,SAAA,CAAU,YAAA,GAC3B,WAAA;;;;;AAMF,GAAA,EAAK,UAAA;;;;;AAKL,IAAA;EAlGkD;;;EAsGhD,OAAA,EAAS,QAAA,CAAS,SAAA,CAAU,iBAAA,CAAkB,YAAA;EArGnB;;;EA0G3B,MAAA,EAAQ,WAAA;AAAA,MAET,OAAA,CAAQ,MAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getEnvVar } from "../env.mjs";
|
|
2
|
+
import { TokenSubscription } from "./TokenSubscription.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/subscribe/helpers.ts
|
|
5
|
+
/**
|
|
6
|
+
* Subscribe to a realtime channel
|
|
7
|
+
*/
|
|
8
|
+
const subscribe = async (token, callback) => {
|
|
9
|
+
const app = token.app;
|
|
10
|
+
const api = app?.api;
|
|
11
|
+
const subscription = new TokenSubscription(token, app?.apiBaseUrl || getEnvVar("INNGEST_BASE_URL") || getEnvVar("INNGEST_API_BASE_URL"), api?.signingKey || getEnvVar("INNGEST_SIGNING_KEY"), api?.signingKeyFallback || getEnvVar("INNGEST_SIGNING_KEY_FALLBACK"));
|
|
12
|
+
const retStream = subscription.getJsonStream();
|
|
13
|
+
const callbackStream = subscription.getJsonStream();
|
|
14
|
+
await subscription.connect();
|
|
15
|
+
const extras = {
|
|
16
|
+
getJsonStream: () => subscription.getJsonStream(),
|
|
17
|
+
getEncodedStream: () => subscription.getEncodedStream()
|
|
18
|
+
};
|
|
19
|
+
if (callback) subscription.useCallback(callback, callbackStream);
|
|
20
|
+
else callbackStream.cancel("Not needed");
|
|
21
|
+
return Object.assign(retStream, extras);
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Get subscription token
|
|
25
|
+
*/
|
|
26
|
+
const getSubscriptionToken = async (app, args) => {
|
|
27
|
+
const channelId = typeof args.channel === "string" ? args.channel : args.channel.name;
|
|
28
|
+
if (!channelId) throw new Error("Channel ID is required to create subscription token");
|
|
29
|
+
const key = await app.api?.getSubscriptionToken?.(channelId, args.topics);
|
|
30
|
+
if (!key) throw new Error("Failed to get subscription token");
|
|
31
|
+
return {
|
|
32
|
+
channel: channelId,
|
|
33
|
+
topics: args.topics,
|
|
34
|
+
key
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { getSubscriptionToken, subscribe };
|
|
40
|
+
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../src/subscribe/helpers.ts"],"sourcesContent":["import { getEnvVar } from \"../env\";\r\nimport type { Realtime } from \"../types\";\r\nimport { TokenSubscription } from \"./TokenSubscription\";\r\n\r\nexport interface InngestApp {\r\n apiBaseUrl?: string;\r\n api?: {\r\n signingKey?: string;\r\n signingKeyFallback?: string;\r\n getSubscriptionToken?: (\r\n channelId: string,\r\n topics: string[],\r\n ) => Promise<string>;\r\n };\r\n}\r\n\r\n/**\r\n * Subscribe to a realtime channel\r\n */\r\nexport const subscribe = async <\r\n const InputChannel extends Realtime.Channel | string,\r\n const InputTopics extends (keyof Realtime.Channel.InferTopics<\r\n Realtime.Channel.AsChannel<InputChannel>\r\n > &\r\n string)[],\r\n const TToken extends Realtime.Subscribe.Token<\r\n Realtime.Channel.AsChannel<InputChannel>,\r\n InputTopics\r\n >,\r\n const TOutput extends Realtime.Subscribe.StreamSubscription<TToken>,\r\n>(\r\n /**\r\n * Subscription token with settings\r\n */\r\n token: {\r\n /**\r\n * Inngest app instance\r\n */\r\n app?: InngestApp;\r\n\r\n /**\r\n * Channel ID or channel object\r\n */\r\n channel: Realtime.Subscribe.InferChannelInput<InputChannel>;\r\n\r\n /**\r\n * List of topics to subscribe to\r\n */\r\n topics: InputTopics;\r\n },\r\n\r\n /**\r\n * Callback to handle messages\r\n */\r\n callback?: Realtime.Subscribe.Callback<TToken>,\r\n): Promise<TOutput> => {\r\n const app = token.app;\r\n const api = app?.api;\r\n\r\n // Allow users to specify public env vars for the target URLs, but do not\r\n // allow this for signing keys, as they should never be on a client.\r\n const maybeApiBaseUrl =\r\n app?.apiBaseUrl ||\r\n getEnvVar(\"INNGEST_BASE_URL\") ||\r\n getEnvVar(\"INNGEST_API_BASE_URL\");\r\n\r\n const maybeSigningKey = api?.signingKey || getEnvVar(\"INNGEST_SIGNING_KEY\");\r\n\r\n const maybeSigningKeyFallback =\r\n api?.signingKeyFallback || getEnvVar(\"INNGEST_SIGNING_KEY_FALLBACK\");\r\n\r\n const subscription = new TokenSubscription(\r\n token as Realtime.Subscribe.Token,\r\n maybeApiBaseUrl,\r\n maybeSigningKey,\r\n maybeSigningKeyFallback,\r\n );\r\n\r\n const retStream = subscription.getJsonStream();\r\n const callbackStream = subscription.getJsonStream();\r\n\r\n await subscription.connect();\r\n\r\n const extras = {\r\n getJsonStream: () => subscription.getJsonStream(),\r\n getEncodedStream: () => subscription.getEncodedStream(),\r\n };\r\n\r\n if (callback) {\r\n subscription.useCallback(callback, callbackStream);\r\n } else {\r\n callbackStream.cancel(\"Not needed\");\r\n }\r\n\r\n return Object.assign(retStream, extras) as unknown as TOutput;\r\n};\r\n\r\n/**\r\n * Get subscription token\r\n */\r\nexport const getSubscriptionToken = async <\r\n const InputChannel extends Realtime.Channel | string,\r\n const InputTopics extends (keyof Realtime.Channel.InferTopics<\r\n Realtime.Channel.AsChannel<InputChannel>\r\n > &\r\n string)[],\r\n const TToken extends Realtime.Subscribe.Token<\r\n Realtime.Channel.AsChannel<InputChannel>,\r\n InputTopics\r\n >,\r\n>(\r\n /**\r\n * Inngest app instance\r\n */\r\n app: InngestApp,\r\n\r\n /**\r\n * Subscription parameters\r\n */\r\n args: {\r\n /**\r\n * Channel ID or channel object\r\n */\r\n channel: Realtime.Subscribe.InferChannelInput<InputChannel>;\r\n\r\n /**\r\n * List of topics\r\n */\r\n topics: InputTopics;\r\n },\r\n): Promise<TToken> => {\r\n const channelId =\r\n typeof args.channel === \"string\" ? args.channel : args.channel.name;\r\n\r\n if (!channelId) {\r\n throw new Error(\"Channel ID is required to create subscription token\");\r\n }\r\n\r\n const key = await app.api?.getSubscriptionToken?.(channelId, args.topics);\r\n\r\n if (!key) {\r\n throw new Error(\"Failed to get subscription token\");\r\n }\r\n\r\n const token = {\r\n channel: channelId,\r\n topics: args.topics,\r\n key,\r\n } as TToken;\r\n\r\n return token;\r\n};\r\n"],"mappings":";;;;;;;AAmBA,MAAa,YAAY,OAevB,OAoBA,aACqB;CACrB,MAAM,MAAM,MAAM;CAClB,MAAM,MAAM,KAAK;CAcjB,MAAM,eAAe,IAAI,kBACvB,OAVA,KAAK,cACL,UAAU,mBAAmB,IAC7B,UAAU,uBAAuB,EAEX,KAAK,cAAc,UAAU,sBAAsB,EAGzE,KAAK,sBAAsB,UAAU,+BAA+B,CAOrE;CAED,MAAM,YAAY,aAAa,eAAe;CAC9C,MAAM,iBAAiB,aAAa,eAAe;AAEnD,OAAM,aAAa,SAAS;CAE5B,MAAM,SAAS;EACb,qBAAqB,aAAa,eAAe;EACjD,wBAAwB,aAAa,kBAAkB;EACxD;AAED,KAAI,SACF,cAAa,YAAY,UAAU,eAAe;KAElD,gBAAe,OAAO,aAAa;AAGrC,QAAO,OAAO,OAAO,WAAW,OAAO;;;;;AAMzC,MAAa,uBAAuB,OAclC,KAKA,SAWoB;CACpB,MAAM,YACJ,OAAO,KAAK,YAAY,WAAW,KAAK,UAAU,KAAK,QAAQ;AAEjE,KAAI,CAAC,UACH,OAAM,IAAI,MAAM,sDAAsD;CAGxE,MAAM,MAAM,MAAM,IAAI,KAAK,uBAAuB,WAAW,KAAK,OAAO;AAEzE,KAAI,CAAC,IACH,OAAM,IAAI,MAAM,mCAAmC;AASrD,QANc;EACZ,SAAS;EACT,QAAQ,KAAK;EACb;EACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const require_helpers = require('./helpers.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { InngestApp, getSubscriptionToken, subscribe } from "./helpers.mjs";
|
package/topic.cjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/topic.ts
|
|
3
|
+
/**
|
|
4
|
+
* Create a topic definition
|
|
5
|
+
*/
|
|
6
|
+
const topic = (id) => {
|
|
7
|
+
return new TopicDefinitionImpl(id);
|
|
8
|
+
};
|
|
9
|
+
var TopicDefinitionImpl = class TopicDefinitionImpl {
|
|
10
|
+
name;
|
|
11
|
+
#schema;
|
|
12
|
+
constructor(name, schema) {
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.#schema = schema;
|
|
15
|
+
}
|
|
16
|
+
type() {
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
schema(schema) {
|
|
20
|
+
return new TopicDefinitionImpl(this.name, schema);
|
|
21
|
+
}
|
|
22
|
+
getSchema() {
|
|
23
|
+
return this.#schema;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.TopicDefinitionImpl = TopicDefinitionImpl;
|
|
29
|
+
exports.topic = topic;
|
|
30
|
+
//# sourceMappingURL=topic.cjs.map
|
package/topic.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"topic.cjs","names":["#schema"],"sources":["../src/topic.ts"],"sourcesContent":["import { type StandardSchemaV1 } from \"@standard-schema/spec\";\r\nimport { type Realtime } from \"./types.js\";\r\n\r\n/**\r\n * Create a topic definition\r\n */\r\nexport const topic: Realtime.Topic.Builder = (\r\n /**\r\n * Topic ID\r\n */\r\n id,\r\n) => {\r\n return new TopicDefinitionImpl(id);\r\n};\r\n\r\nexport class TopicDefinitionImpl<\r\n TTopicId extends string = string,\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n TPublish = any,\r\n TSubscribe = TPublish,\r\n> implements Realtime.Topic.Definition<TTopicId, TPublish, TSubscribe> {\r\n public name: TTopicId;\r\n #schema?: StandardSchemaV1;\r\n\r\n constructor(name: TTopicId, schema?: StandardSchemaV1) {\r\n this.name = name;\r\n this.#schema = schema;\r\n }\r\n\r\n public type<\r\n const UPublish,\r\n const USubscribe = UPublish,\r\n >(): Realtime.Topic.Definition<TTopicId, UPublish, USubscribe> {\r\n return this as Realtime.Topic.Definition<TTopicId, UPublish, USubscribe>;\r\n }\r\n\r\n public schema<const TSchema extends StandardSchemaV1>(\r\n schema: TSchema,\r\n ): Realtime.Topic.Definition<\r\n TTopicId,\r\n StandardSchemaV1.InferInput<TSchema>,\r\n StandardSchemaV1.InferOutput<TSchema>\r\n > {\r\n return new TopicDefinitionImpl(this.name, schema);\r\n }\r\n\r\n public getSchema(): StandardSchemaV1 | undefined {\r\n return this.#schema;\r\n }\r\n}\r\n"],"mappings":";;;;;AAMA,MAAa,SAIX,OACG;AACH,QAAO,IAAI,oBAAoB,GAAG;;AAGpC,IAAa,sBAAb,MAAa,oBAK0D;CACrE,AAAO;CACP;CAEA,YAAY,MAAgB,QAA2B;AACrD,OAAK,OAAO;AACZ,QAAKA,SAAU;;CAGjB,AAAO,OAGwD;AAC7D,SAAO;;CAGT,AAAO,OACL,QAKA;AACA,SAAO,IAAI,oBAAoB,KAAK,MAAM,OAAO;;CAGnD,AAAO,YAA0C;AAC/C,SAAO,MAAKA"}
|
package/topic.d.cts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Realtime } from "./types.cjs";
|
|
2
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
+
|
|
4
|
+
//#region src/topic.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Create a topic definition
|
|
7
|
+
*/
|
|
8
|
+
declare const topic: Realtime.Topic.Builder;
|
|
9
|
+
declare class TopicDefinitionImpl<TTopicId extends string = string, TPublish = any, TSubscribe = TPublish> implements Realtime.Topic.Definition<TTopicId, TPublish, TSubscribe> {
|
|
10
|
+
#private;
|
|
11
|
+
name: TTopicId;
|
|
12
|
+
constructor(name: TTopicId, schema?: StandardSchemaV1);
|
|
13
|
+
type<const UPublish, const USubscribe = UPublish>(): Realtime.Topic.Definition<TTopicId, UPublish, USubscribe>;
|
|
14
|
+
schema<const TSchema extends StandardSchemaV1>(schema: TSchema): Realtime.Topic.Definition<TTopicId, StandardSchemaV1.InferInput<TSchema>, StandardSchemaV1.InferOutput<TSchema>>;
|
|
15
|
+
getSchema(): StandardSchemaV1 | undefined;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { TopicDefinitionImpl, topic };
|
|
19
|
+
//# sourceMappingURL=topic.d.cts.map
|
package/topic.d.cts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"topic.d.cts","names":[],"sources":["../src/topic.ts"],"mappings":";;;;;;AAMA;cAAa,KAAA,EAAO,QAAA,CAAS,KAAA,CAAM,OAAA;AAAA,cAStB,mBAAA,gEAIE,QAAA,aACF,QAAA,CAAS,KAAA,CAAM,UAAA,CAAW,QAAA,EAAU,QAAA,EAAU,UAAA;EAAA;EAClD,IAAA,EAAM,QAAA;cAGD,IAAA,EAAM,QAAA,EAAU,MAAA,GAAS,gBAAA;EAK9B,IAAA,oCAEc,QAAA,CAAA,CAAA,GAChB,QAAA,CAAS,KAAA,CAAM,UAAA,CAAW,QAAA,EAAU,QAAA,EAAU,UAAA;EAI5C,MAAA,uBAA6B,gBAAA,CAAA,CAClC,MAAA,EAAQ,OAAA,GACP,QAAA,CAAS,KAAA,CAAM,UAAA,CAChB,QAAA,EACA,gBAAA,CAAiB,UAAA,CAAW,OAAA,GAC5B,gBAAA,CAAiB,WAAA,CAAY,OAAA;EAKxB,SAAA,CAAA,GAAa,gBAAA;AAAA"}
|
package/topic.d.mts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Realtime } from "./types.mjs";
|
|
2
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
+
|
|
4
|
+
//#region src/topic.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Create a topic definition
|
|
7
|
+
*/
|
|
8
|
+
declare const topic: Realtime.Topic.Builder;
|
|
9
|
+
declare class TopicDefinitionImpl<TTopicId extends string = string, TPublish = any, TSubscribe = TPublish> implements Realtime.Topic.Definition<TTopicId, TPublish, TSubscribe> {
|
|
10
|
+
#private;
|
|
11
|
+
name: TTopicId;
|
|
12
|
+
constructor(name: TTopicId, schema?: StandardSchemaV1);
|
|
13
|
+
type<const UPublish, const USubscribe = UPublish>(): Realtime.Topic.Definition<TTopicId, UPublish, USubscribe>;
|
|
14
|
+
schema<const TSchema extends StandardSchemaV1>(schema: TSchema): Realtime.Topic.Definition<TTopicId, StandardSchemaV1.InferInput<TSchema>, StandardSchemaV1.InferOutput<TSchema>>;
|
|
15
|
+
getSchema(): StandardSchemaV1 | undefined;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { TopicDefinitionImpl, topic };
|
|
19
|
+
//# sourceMappingURL=topic.d.mts.map
|
package/topic.d.mts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"topic.d.mts","names":[],"sources":["../src/topic.ts"],"mappings":";;;;;;AAMA;cAAa,KAAA,EAAO,QAAA,CAAS,KAAA,CAAM,OAAA;AAAA,cAStB,mBAAA,gEAIE,QAAA,aACF,QAAA,CAAS,KAAA,CAAM,UAAA,CAAW,QAAA,EAAU,QAAA,EAAU,UAAA;EAAA;EAClD,IAAA,EAAM,QAAA;cAGD,IAAA,EAAM,QAAA,EAAU,MAAA,GAAS,gBAAA;EAK9B,IAAA,oCAEc,QAAA,CAAA,CAAA,GAChB,QAAA,CAAS,KAAA,CAAM,UAAA,CAAW,QAAA,EAAU,QAAA,EAAU,UAAA;EAI5C,MAAA,uBAA6B,gBAAA,CAAA,CAClC,MAAA,EAAQ,OAAA,GACP,QAAA,CAAS,KAAA,CAAM,UAAA,CAChB,QAAA,EACA,gBAAA,CAAiB,UAAA,CAAW,OAAA,GAC5B,gBAAA,CAAiB,WAAA,CAAY,OAAA;EAKxB,SAAA,CAAA,GAAa,gBAAA;AAAA"}
|
package/topic.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/topic.ts
|
|
2
|
+
/**
|
|
3
|
+
* Create a topic definition
|
|
4
|
+
*/
|
|
5
|
+
const topic = (id) => {
|
|
6
|
+
return new TopicDefinitionImpl(id);
|
|
7
|
+
};
|
|
8
|
+
var TopicDefinitionImpl = class TopicDefinitionImpl {
|
|
9
|
+
name;
|
|
10
|
+
#schema;
|
|
11
|
+
constructor(name, schema) {
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.#schema = schema;
|
|
14
|
+
}
|
|
15
|
+
type() {
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
schema(schema) {
|
|
19
|
+
return new TopicDefinitionImpl(this.name, schema);
|
|
20
|
+
}
|
|
21
|
+
getSchema() {
|
|
22
|
+
return this.#schema;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { TopicDefinitionImpl, topic };
|
|
28
|
+
//# sourceMappingURL=topic.mjs.map
|
package/topic.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"topic.mjs","names":["#schema"],"sources":["../src/topic.ts"],"sourcesContent":["import { type StandardSchemaV1 } from \"@standard-schema/spec\";\r\nimport { type Realtime } from \"./types.js\";\r\n\r\n/**\r\n * Create a topic definition\r\n */\r\nexport const topic: Realtime.Topic.Builder = (\r\n /**\r\n * Topic ID\r\n */\r\n id,\r\n) => {\r\n return new TopicDefinitionImpl(id);\r\n};\r\n\r\nexport class TopicDefinitionImpl<\r\n TTopicId extends string = string,\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n TPublish = any,\r\n TSubscribe = TPublish,\r\n> implements Realtime.Topic.Definition<TTopicId, TPublish, TSubscribe> {\r\n public name: TTopicId;\r\n #schema?: StandardSchemaV1;\r\n\r\n constructor(name: TTopicId, schema?: StandardSchemaV1) {\r\n this.name = name;\r\n this.#schema = schema;\r\n }\r\n\r\n public type<\r\n const UPublish,\r\n const USubscribe = UPublish,\r\n >(): Realtime.Topic.Definition<TTopicId, UPublish, USubscribe> {\r\n return this as Realtime.Topic.Definition<TTopicId, UPublish, USubscribe>;\r\n }\r\n\r\n public schema<const TSchema extends StandardSchemaV1>(\r\n schema: TSchema,\r\n ): Realtime.Topic.Definition<\r\n TTopicId,\r\n StandardSchemaV1.InferInput<TSchema>,\r\n StandardSchemaV1.InferOutput<TSchema>\r\n > {\r\n return new TopicDefinitionImpl(this.name, schema);\r\n }\r\n\r\n public getSchema(): StandardSchemaV1 | undefined {\r\n return this.#schema;\r\n }\r\n}\r\n"],"mappings":";;;;AAMA,MAAa,SAIX,OACG;AACH,QAAO,IAAI,oBAAoB,GAAG;;AAGpC,IAAa,sBAAb,MAAa,oBAK0D;CACrE,AAAO;CACP;CAEA,YAAY,MAAgB,QAA2B;AACrD,OAAK,OAAO;AACZ,QAAKA,SAAU;;CAGjB,AAAO,OAGwD;AAC7D,SAAO;;CAGT,AAAO,OACL,QAKA;AACA,SAAO,IAAI,oBAAoB,KAAK,MAAM,OAAO;;CAGnD,AAAO,YAA0C;AAC/C,SAAO,MAAKA"}
|
package/types.cjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
let zod = require("zod");
|
|
3
|
+
|
|
4
|
+
//#region src/types.ts
|
|
5
|
+
let Realtime;
|
|
6
|
+
(function(_Realtime) {
|
|
7
|
+
_Realtime.messageSchema = zod.z.object({
|
|
8
|
+
channel: zod.z.string().optional(),
|
|
9
|
+
topic: zod.z.string().optional(),
|
|
10
|
+
data: zod.z.any().optional(),
|
|
11
|
+
run_id: zod.z.string().optional(),
|
|
12
|
+
fn_id: zod.z.string().optional(),
|
|
13
|
+
created_at: zod.z.string().optional().transform((v) => v ? new Date(v) : void 0),
|
|
14
|
+
env_id: zod.z.string().optional(),
|
|
15
|
+
stream_id: zod.z.string().optional(),
|
|
16
|
+
kind: zod.z.enum([
|
|
17
|
+
"step",
|
|
18
|
+
"run",
|
|
19
|
+
"data",
|
|
20
|
+
"ping",
|
|
21
|
+
"pong",
|
|
22
|
+
"closing",
|
|
23
|
+
"event",
|
|
24
|
+
"sub",
|
|
25
|
+
"unsub",
|
|
26
|
+
"datastream-start",
|
|
27
|
+
"datastream-end",
|
|
28
|
+
"chunk"
|
|
29
|
+
])
|
|
30
|
+
}).transform(({ data, ...rest }) => {
|
|
31
|
+
return {
|
|
32
|
+
...rest,
|
|
33
|
+
data: data ?? void 0
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
})(Realtime || (Realtime = {}));
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
Object.defineProperty(exports, 'Realtime', {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function () {
|
|
42
|
+
return Realtime;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=types.cjs.map
|
package/types.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","names":["z"],"sources":["../src/types.ts"],"sourcesContent":["import { type StandardSchemaV1 } from \"@standard-schema/spec\";\r\nimport { z } from \"zod\";\r\n\r\nexport namespace Realtime {\r\n export type PublishFn = <\r\n TMessage extends MaybePromise<Realtime.Message.Input>,\r\n >(\r\n message: TMessage,\r\n ) => Promise<Awaited<TMessage>[\"data\"]>;\r\n\r\n export type Token<\r\n TChannel extends Channel | Channel.Definition,\r\n TTopics extends (keyof Channel.InferTopics<\r\n Channel.Definition.AsChannel<TChannel>\r\n > &\r\n string)[] = (keyof Channel.InferTopics<\r\n Channel.Definition.AsChannel<TChannel>\r\n > &\r\n string)[],\r\n > = TChannel extends Channel.Definition\r\n ? Subscribe.Token<Channel.Definition.AsChannel<TChannel>, TTopics>\r\n : TChannel extends Channel\r\n ? Subscribe.Token<TChannel, TTopics>\r\n : never;\r\n\r\n export namespace Subscribe {\r\n export type InferChannelInput<T> = T extends Realtime.Channel.Definition\r\n ? Realtime.Channel.Definition.InferId<T>\r\n : T;\r\n\r\n export type StreamSubscription<\r\n TSubscribeToken extends Token = Token,\r\n TData extends Simplify<Token.InferMessage<TSubscribeToken>> = Simplify<\r\n Token.InferMessage<TSubscribeToken>\r\n >,\r\n > = ReadableStream<TData> & {\r\n /**\r\n * Get a new readable stream from the subscription that delivers JSON chunks.\r\n *\r\n * The stream starts when this function is called and will not contain any\r\n * messages that were sent before this function was called.\r\n */\r\n getJsonStream(): ReadableStream<TData>;\r\n\r\n /**\r\n * Get a new readable stream from the subscription that delivers\r\n * SSE-compatible chunks, which are compatible with the `EventSource` API\r\n * and generally used for streaming data from a server to the browser.\r\n *\r\n * The stream starts when this function is called and will not contain any\r\n * messages that were sent before this function was called.\r\n */\r\n getEncodedStream(): ReadableStream<Uint8Array>;\r\n };\r\n\r\n export type Callback<\r\n TSubscribeToken extends Subscribe.Token = Subscribe.Token,\r\n > = (message: Token.InferMessage<TSubscribeToken>) => void;\r\n\r\n export interface Token<\r\n TChannel extends Channel | Channel.Definition = Channel,\r\n TTopics extends (keyof Channel.InferTopics<TChannel>)[] =\r\n (keyof Channel.InferTopics<TChannel>)[],\r\n > {\r\n // key used to auth - could be undefined as then we can do a cold subscribe\r\n key?: string | undefined;\r\n channel: Realtime.Channel.Definition.AsChannel<TChannel>;\r\n topics: TTopics;\r\n }\r\n\r\n export namespace Token {\r\n export type InferChannel<TToken extends Token> =\r\n TToken extends Token<\r\n infer IChannel,\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n any\r\n >\r\n ? IChannel\r\n : Channel;\r\n\r\n export type InferTopicData<\r\n TToken extends Token,\r\n TChannelTopics extends Record<string, Topic.Definition> =\r\n Channel.InferTopics<Token.InferChannel<TToken>>,\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n > =\r\n TToken extends Token<any, infer ITopics>\r\n ? { [K in ITopics[number]]: TChannelTopics[K] }\r\n : never;\r\n\r\n export type InferMessage<TToken extends Token> = Simplify<\r\n Realtime.Message<\r\n Channel.InferId<Token.InferChannel<TToken>>,\r\n Token.InferTopicData<TToken>\r\n >\r\n >;\r\n }\r\n }\r\n\r\n // We need to use a `Message` type so that we can appropriately type incoming\r\n // and outgoing messages with generics, but we also need to validate these at\r\n // runtime.\r\n //\r\n // Ideally in the future we use protobuf for this, but for now we use Zod.\r\n // This type is used to assert that the Zod schema matches the generic type.\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n // type _AssertMessageSchemaMatchesGeneric = Expect<\r\n // IsEqual<z.output<typeof messageSchema>, Message.Raw>\r\n // >;\r\n\r\n export const messageSchema = z\r\n .object({\r\n channel: z.string().optional(),\r\n topic: z.string().optional(),\r\n data: z.any().optional(),\r\n run_id: z.string().optional(),\r\n fn_id: z.string().optional(),\r\n created_at: z\r\n .string()\r\n .optional()\r\n .transform((v) => (v ? new Date(v) : undefined)),\r\n env_id: z.string().optional(),\r\n stream_id: z.string().optional(),\r\n kind: z.enum([\r\n \"step\",\r\n \"run\",\r\n \"data\",\r\n \"ping\",\r\n \"pong\",\r\n \"closing\",\r\n \"event\",\r\n \"sub\",\r\n \"unsub\",\r\n \"datastream-start\",\r\n \"datastream-end\",\r\n \"chunk\",\r\n ]),\r\n })\r\n .transform(({ data, ...rest }) => {\r\n return {\r\n ...rest,\r\n data: data ?? undefined,\r\n };\r\n });\r\n\r\n // Subscribe (output) msg\r\n export type Message<\r\n TChannelId extends string = string,\r\n TTopics extends Record<string, Realtime.Topic.Definition> = Record<\r\n string,\r\n Realtime.Topic.Definition\r\n >,\r\n > = {\r\n [K in keyof TTopics]:\r\n | {\r\n topic: K;\r\n channel: TChannelId;\r\n data: Realtime.Topic.InferSubscribe<TTopics[K]>;\r\n runId?: string;\r\n fnId?: string;\r\n createdAt: Date;\r\n envId?: string;\r\n kind: \"data\";\r\n }\r\n | {\r\n topic: K;\r\n channel: TChannelId;\r\n data: Realtime.Topic.InferSubscribe<TTopics[K]>;\r\n runId?: string;\r\n fnId?: string;\r\n kind: \"datastream-start\" | \"datastream-end\" | \"chunk\";\r\n streamId: string;\r\n stream: ReadableStream<Realtime.Topic.InferSubscribe<TTopics[K]>>;\r\n };\r\n }[keyof TTopics];\r\n\r\n export namespace Message {\r\n // Publish (input) msg\r\n export type Input<\r\n TChannelId extends string = string,\r\n TTopicId extends string = string,\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n TData = any,\r\n > = {\r\n channel: TChannelId;\r\n topic: TTopicId;\r\n data: TData;\r\n };\r\n\r\n export type Raw<\r\n TChannelId extends string = string,\r\n TTopics extends Record<string, Realtime.Topic.Definition> = Record<\r\n string,\r\n Realtime.Topic.Definition\r\n >,\r\n > = {\r\n [K in keyof TTopics]: {\r\n topic?: K;\r\n stream_id?: string;\r\n data: Realtime.Topic.InferSubscribe<TTopics[K]>;\r\n channel?: TChannelId;\r\n run_id?: string;\r\n fn_id?: string;\r\n created_at?: Date;\r\n env_id?: string;\r\n kind:\r\n | \"step\" // step data\r\n | \"run\" // run results\r\n | \"data\" // misc stream data from `ctx.publish()`\r\n | \"datastream-start\"\r\n | \"datastream-end\"\r\n | \"ping\" // keepalive server -> client\r\n | \"pong\" // keepalive client -> server\r\n | \"closing\" // server is closing connection, client should reconnect\r\n | \"event\" // event sent to inngest\r\n | \"sub\"\r\n | \"unsub\"\r\n | \"chunk\";\r\n };\r\n }[keyof TTopics];\r\n }\r\n\r\n export type Channel<\r\n TChannelId extends string = string,\r\n TTopics extends Record<string, Realtime.Topic.Definition> = Record<\r\n string,\r\n Realtime.Topic.Definition\r\n >,\r\n > = {\r\n [K in\r\n | IsLiteral<keyof TTopics, keyof TTopics, never>\r\n | \"name\"\r\n | \"topics\"]: K extends \"name\"\r\n ? string\r\n : K extends \"topics\"\r\n ? TTopics\r\n : Realtime.Topic<TChannelId, TTopics[K]>;\r\n };\r\n\r\n export namespace Channel {\r\n export type Like = {\r\n channel: string;\r\n topics: string[];\r\n };\r\n\r\n export type InferId<TChannel extends Channel> =\r\n TChannel extends Channel<\r\n infer IId,\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n any\r\n >\r\n ? IId\r\n : string;\r\n\r\n export type AsChannel<T extends Channel | string> = T extends Channel\r\n ? T\r\n : T extends string\r\n ? Realtime.Channel<T>\r\n : never;\r\n\r\n export type InferTopics<\r\n TChannel extends Channel | Channel.Definition,\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n > =\r\n TChannel extends Channel.Definition<any, infer ITopics>\r\n ? ITopics\r\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n TChannel extends Channel<any, infer ITopics>\r\n ? ITopics\r\n : Record<string, Realtime.Topic.Definition>;\r\n\r\n export interface Definition<\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n TChannelBuilderFn extends BuilderFn = (...args: any[]) => string,\r\n TTopics extends Record<string, Topic.Definition> = Record<\r\n string,\r\n Topic.Definition\r\n >,\r\n > {\r\n (\r\n ...args: Parameters<TChannelBuilderFn>\r\n ): Channel<ReturnType<TChannelBuilderFn>, TTopics>;\r\n\r\n addTopic<UTopic extends Topic.Definition>(\r\n topic: UTopic,\r\n ): Definition<TChannelBuilderFn, AddTopic<TTopics, UTopic>>;\r\n\r\n topics: TTopics;\r\n }\r\n\r\n export namespace Definition {\r\n export type InferId<TChannel extends Definition> =\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n TChannel extends Definition<infer IBuilder, any>\r\n ? ReturnType<IBuilder>\r\n : string;\r\n\r\n export type InferTopics<TChannel extends Definition> =\r\n TChannel extends Definition<\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n any,\r\n infer ITopics\r\n >\r\n ? ITopics\r\n : Record<string, Topic.Definition>;\r\n\r\n export type AsChannel<T extends Definition | Channel> =\r\n T extends Definition\r\n ? Channel<InferId<T>, InferTopics<T>>\r\n : T extends Channel\r\n ? T\r\n : never;\r\n }\r\n\r\n export type AddTopic<\r\n TCurr extends Record<string, Topic.Definition>,\r\n TInc extends Topic.Definition,\r\n TIncWrapped extends Record<TInc[\"name\"], TInc> = Record<\r\n TInc[\"name\"],\r\n TInc\r\n >,\r\n > =\r\n IsStringLiteral<keyof TCurr & string> extends true\r\n ? Simplify<Omit<TCurr, TInc[\"name\"]> & TIncWrapped>\r\n : TIncWrapped;\r\n\r\n export type BuilderFn<TChannelId extends string = string> = (\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n ...args: any[]\r\n ) => TChannelId;\r\n\r\n export type Builder = <\r\n const TChannelId extends string,\r\n const TIdInput extends TChannelId | BuilderFn<TChannelId>,\r\n >(\r\n id: TIdInput,\r\n ) => TIdInput extends TChannelId\r\n ? Channel.Definition<() => TIdInput>\r\n : TIdInput extends BuilderFn<TChannelId>\r\n ? Channel.Definition<TIdInput>\r\n : never;\r\n }\r\n\r\n export type Topic<\r\n TChannelId extends string = string,\r\n TTopic extends Topic.Definition = Topic.Definition,\r\n > = (\r\n data: Topic.InferPublish<TTopic>,\r\n ) => Promise<\r\n Realtime.Message.Input<\r\n TChannelId,\r\n Topic.InferId<TTopic>,\r\n Topic.InferPublish<TTopic>\r\n >\r\n >;\r\n\r\n export namespace Topic {\r\n export type Like = {\r\n name: string;\r\n };\r\n\r\n export interface Definition<\r\n TTopicId extends string = string,\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n TPublish = any,\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n _TSubscribe = TPublish,\r\n > {\r\n name: TTopicId;\r\n\r\n // Deliberately doesn't include `USubscribe` typing, as there's no schema\r\n // to perform transformations.\r\n type<const UPublish>(): Definition<TTopicId, UPublish>;\r\n\r\n schema<const TSchema extends StandardSchemaV1>(\r\n schema: TSchema,\r\n ): Definition<\r\n TTopicId,\r\n StandardSchemaV1.InferInput<TSchema>,\r\n StandardSchemaV1.InferOutput<TSchema>\r\n >;\r\n\r\n getSchema(): StandardSchemaV1 | undefined;\r\n }\r\n\r\n export type InferId<TTopic extends Topic.Definition> =\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n TTopic extends Topic.Definition<infer IId, any, any> ? IId : string;\r\n\r\n export type InferPublish<TTopic extends Topic.Definition> =\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n TTopic extends Topic.Definition<any, infer IPublish, any>\r\n ? IPublish\r\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n any;\r\n\r\n export type InferSubscribe<TTopic extends Topic.Definition> =\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n TTopic extends Topic.Definition<any, any, infer ISubscribe>\r\n ? ISubscribe\r\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n any;\r\n\r\n export type Builder = <const TTopicId extends string>(\r\n id: TTopicId,\r\n ) => Topic.Definition<TTopicId>;\r\n }\r\n}\r\n\r\n/**\r\n * Expects that a value resolves to `true`, useful for asserting type checks.\r\n */\r\nexport type Expect<T extends true> = T;\r\n\r\n/**\r\nReturns a boolean for whether the two given types are equal.\r\n\r\n{@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650}\r\n{@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796}\r\n\r\nUse-cases:\r\n- If you want to make a conditional branch based on the result of a comparison of two types.\r\n\r\n@example\r\n```\r\nimport type {IsEqual} from 'type-fest';\r\n\r\n// This type returns a boolean for whether the given array includes the given item.\r\n// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.\r\ntype Includes<Value extends readonly any[], Item> =\r\n\tValue extends readonly [Value[0], ...infer rest]\r\n\t\t? IsEqual<Value[0], Item> extends true\r\n\t\t\t? true\r\n\t\t\t: Includes<rest, Item>\r\n\t\t: false;\r\n```\r\n*/\r\nexport type IsEqual<A, B> =\r\n (<G>() => G extends A ? 1 : 2) extends <G>() => G extends B ? 1 : 2\r\n ? true\r\n : false;\r\n\r\n/**\r\n * Given a type `T`, return `Then` if `T` is a string, number, or symbol\r\n * literal, else `Else`.\r\n *\r\n * `Then` defaults to `true` and `Else` defaults to `false`.\r\n *\r\n * Useful for determining if an object is a generic type or has known keys.\r\n *\r\n * @example\r\n * ```ts\r\n * type IsLiteralType = IsLiteral<\"foo\">; // true\r\n * type IsLiteralType = IsLiteral<string>; // false\r\n *\r\n * type IsLiteralType = IsLiteral<1>; // true\r\n * type IsLiteralType = IsLiteral<number>; // false\r\n *\r\n * type IsLiteralType = IsLiteral<symbol>; // true\r\n * type IsLiteralType = IsLiteral<typeof Symbol.iterator>; // false\r\n *\r\n * type T0 = { foo: string };\r\n * type HasAllKnownKeys = IsLiteral<keyof T0>; // true\r\n *\r\n * type T1 = { [x: string]: any; foo: boolean };\r\n * type HasAllKnownKeys = IsLiteral<keyof T1>; // false\r\n * ```\r\n */\r\nexport type IsLiteral<T, Then = true, Else = false> = string extends T\r\n ? Else\r\n : number extends T\r\n ? Else\r\n : symbol extends T\r\n ? Else\r\n : Then;\r\n\r\n/**\r\n * Returns `true` if the given generic `T` is a string literal, e.g. `\"foo\"`, or\r\n * `false` if it is a string type, e.g. `string`.\r\n *\r\n * Useful for checking whether the keys of an object are known or not.\r\n *\r\n * @example\r\n * ```ts\r\n * // false\r\n * type ObjIsGeneric = IsStringLiteral<keyof Record<string, boolean>>;\r\n *\r\n * // true\r\n * type ObjIsKnown = IsStringLiteral<keyof { foo: boolean; }>; // true\r\n * ```\r\n *\r\n * @internal\r\n */\r\nexport type IsStringLiteral<T extends string> = string extends T ? false : true;\r\n\r\n/**\r\n * Returns the given generic as either itself or a promise of itself.\r\n */\r\nexport type MaybePromise<T> = T | Promise<T>;\r\n\r\nexport type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};\r\n"],"mappings":";;;;;;2BA8G+BA,MAC1B,OAAO;EACN,SAASA,MAAE,QAAQ,CAAC,UAAU;EAC9B,OAAOA,MAAE,QAAQ,CAAC,UAAU;EAC5B,MAAMA,MAAE,KAAK,CAAC,UAAU;EACxB,QAAQA,MAAE,QAAQ,CAAC,UAAU;EAC7B,OAAOA,MAAE,QAAQ,CAAC,UAAU;EAC5B,YAAYA,MACT,QAAQ,CACR,UAAU,CACV,WAAW,MAAO,IAAI,IAAI,KAAK,EAAE,GAAG,OAAW;EAClD,QAAQA,MAAE,QAAQ,CAAC,UAAU;EAC7B,WAAWA,MAAE,QAAQ,CAAC,UAAU;EAChC,MAAMA,MAAE,KAAK;GACX;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD,CAAC;EACH,CAAC,CACD,WAAW,EAAE,MAAM,GAAG,WAAW;AAChC,SAAO;GACL,GAAG;GACH,MAAM,QAAQ;GACf;GACD"}
|