spectrum-ts 1.5.0 → 1.7.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spectrum-ts",
3
- "version": "1.5.0",
3
+ "version": "1.7.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -1,490 +0,0 @@
1
- import { Pipe, Tuples, Fn } from 'hotscript';
2
- import z__default from 'zod';
3
-
4
- declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObject<{
5
- type: z__default.ZodLiteral<"text">;
6
- text: z__default.ZodString;
7
- }, z__default.core.$strip>, z__default.ZodObject<{
8
- type: z__default.ZodLiteral<"custom">;
9
- raw: z__default.ZodUnknown;
10
- }, z__default.core.$strip>, z__default.ZodObject<{
11
- type: z__default.ZodLiteral<"attachment">;
12
- name: z__default.ZodString;
13
- mimeType: z__default.ZodString;
14
- size: z__default.ZodOptional<z__default.ZodNumber>;
15
- read: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
16
- stream: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
17
- }, z__default.core.$strip>, z__default.ZodObject<{
18
- type: z__default.ZodLiteral<"contact">;
19
- user: z__default.ZodOptional<z__default.ZodObject<{
20
- __platform: z__default.ZodString;
21
- id: z__default.ZodString;
22
- }, z__default.core.$strip>>;
23
- name: z__default.ZodOptional<z__default.ZodObject<{
24
- formatted: z__default.ZodOptional<z__default.ZodString>;
25
- first: z__default.ZodOptional<z__default.ZodString>;
26
- last: z__default.ZodOptional<z__default.ZodString>;
27
- middle: z__default.ZodOptional<z__default.ZodString>;
28
- prefix: z__default.ZodOptional<z__default.ZodString>;
29
- suffix: z__default.ZodOptional<z__default.ZodString>;
30
- }, z__default.core.$strip>>;
31
- phones: z__default.ZodOptional<z__default.ZodArray<z__default.ZodObject<{
32
- value: z__default.ZodString;
33
- type: z__default.ZodOptional<z__default.ZodEnum<{
34
- mobile: "mobile";
35
- home: "home";
36
- work: "work";
37
- other: "other";
38
- }>>;
39
- }, z__default.core.$strip>>>;
40
- emails: z__default.ZodOptional<z__default.ZodArray<z__default.ZodObject<{
41
- value: z__default.ZodString;
42
- type: z__default.ZodOptional<z__default.ZodEnum<{
43
- home: "home";
44
- work: "work";
45
- other: "other";
46
- }>>;
47
- }, z__default.core.$strip>>>;
48
- addresses: z__default.ZodOptional<z__default.ZodArray<z__default.ZodObject<{
49
- street: z__default.ZodOptional<z__default.ZodString>;
50
- city: z__default.ZodOptional<z__default.ZodString>;
51
- region: z__default.ZodOptional<z__default.ZodString>;
52
- postalCode: z__default.ZodOptional<z__default.ZodString>;
53
- country: z__default.ZodOptional<z__default.ZodString>;
54
- type: z__default.ZodOptional<z__default.ZodEnum<{
55
- home: "home";
56
- work: "work";
57
- other: "other";
58
- }>>;
59
- }, z__default.core.$strip>>>;
60
- org: z__default.ZodOptional<z__default.ZodObject<{
61
- name: z__default.ZodOptional<z__default.ZodString>;
62
- title: z__default.ZodOptional<z__default.ZodString>;
63
- department: z__default.ZodOptional<z__default.ZodString>;
64
- }, z__default.core.$strip>>;
65
- urls: z__default.ZodOptional<z__default.ZodArray<z__default.ZodString>>;
66
- birthday: z__default.ZodOptional<z__default.ZodString>;
67
- note: z__default.ZodOptional<z__default.ZodString>;
68
- photo: z__default.ZodOptional<z__default.ZodObject<{
69
- mimeType: z__default.ZodString;
70
- read: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
71
- }, z__default.core.$strip>>;
72
- raw: z__default.ZodOptional<z__default.ZodUnknown>;
73
- }, z__default.core.$strip>, z__default.ZodObject<{
74
- type: z__default.ZodLiteral<"voice">;
75
- name: z__default.ZodOptional<z__default.ZodString>;
76
- mimeType: z__default.ZodString;
77
- duration: z__default.ZodOptional<z__default.ZodNumber>;
78
- size: z__default.ZodOptional<z__default.ZodNumber>;
79
- read: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
80
- stream: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
81
- }, z__default.core.$strip>, z__default.ZodObject<{
82
- type: z__default.ZodLiteral<"richlink">;
83
- url: z__default.ZodURL;
84
- title: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodOptional<z__default.ZodString>>>;
85
- summary: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodOptional<z__default.ZodString>>>;
86
- cover: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodOptional<z__default.ZodObject<{
87
- mimeType: z__default.ZodOptional<z__default.ZodString>;
88
- read: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
89
- stream: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
90
- }, z__default.core.$strip>>>>;
91
- }, z__default.core.$strip>, z__default.ZodObject<{
92
- type: z__default.ZodLiteral<"reaction">;
93
- emoji: z__default.ZodString;
94
- target: z__default.ZodCustom<Message, Message>;
95
- }, z__default.core.$strip>, z__default.ZodObject<{
96
- type: z__default.ZodLiteral<"group">;
97
- items: z__default.ZodArray<z__default.ZodCustom<Message, Message>>;
98
- }, z__default.core.$strip>, z__default.ZodObject<{
99
- type: z__default.ZodLiteral<"poll">;
100
- title: z__default.ZodString;
101
- options: z__default.ZodArray<z__default.ZodObject<{
102
- title: z__default.ZodString;
103
- }, z__default.core.$strip>>;
104
- }, z__default.core.$strip>, z__default.ZodObject<{
105
- type: z__default.ZodLiteral<"poll_option">;
106
- option: z__default.ZodObject<{
107
- title: z__default.ZodString;
108
- }, z__default.core.$strip>;
109
- poll: z__default.ZodObject<{
110
- type: z__default.ZodLiteral<"poll">;
111
- title: z__default.ZodString;
112
- options: z__default.ZodArray<z__default.ZodObject<{
113
- title: z__default.ZodString;
114
- }, z__default.core.$strip>>;
115
- }, z__default.core.$strip>;
116
- selected: z__default.ZodBoolean;
117
- title: z__default.ZodString;
118
- }, z__default.core.$strip>, z__default.ZodObject<{
119
- type: z__default.ZodLiteral<"effect">;
120
- content: z__default.ZodDiscriminatedUnion<[z__default.ZodObject<{
121
- type: z__default.ZodLiteral<"text">;
122
- text: z__default.ZodString;
123
- }, z__default.core.$strip>, z__default.ZodObject<{
124
- type: z__default.ZodLiteral<"attachment">;
125
- name: z__default.ZodString;
126
- mimeType: z__default.ZodString;
127
- size: z__default.ZodOptional<z__default.ZodNumber>;
128
- read: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
129
- stream: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
130
- }, z__default.core.$strip>], "type">;
131
- effect: z__default.ZodString;
132
- }, z__default.core.$strip>], "type">;
133
- type Content = z__default.infer<typeof contentSchema>;
134
- interface ContentBuilder {
135
- build(): Promise<Content>;
136
- }
137
- type ContentInput = string | ContentBuilder;
138
-
139
- interface User {
140
- readonly __platform: string;
141
- readonly id: string;
142
- }
143
-
144
- interface Space<_Def = unknown> {
145
- readonly __platform: string;
146
- edit(message: OutboundMessage, newContent: ContentInput): Promise<void>;
147
- /**
148
- * Look up a message in this space by its id. Returns `undefined` if the
149
- * platform has no way to resolve the id (e.g. cache miss with no by-id
150
- * SDK fallback). Used to materialize a `Message` for APIs that require one,
151
- * such as `reaction()`.
152
- */
153
- getMessage(id: string): Promise<Message | undefined>;
154
- readonly id: string;
155
- responding<T>(fn: () => T | Promise<T>): Promise<T>;
156
- send(content: ContentInput): Promise<OutboundMessage | undefined>;
157
- send(...content: [ContentInput, ContentInput, ...ContentInput[]]): Promise<OutboundMessage[]>;
158
- startTyping(): Promise<void>;
159
- stopTyping(): Promise<void>;
160
- }
161
-
162
- interface BaseMessage<TPlatform extends string = string, TSender extends User = User, TSpace extends Space = Space> {
163
- content: Content;
164
- readonly id: string;
165
- platform: TPlatform;
166
- react(reaction: string): Promise<void>;
167
- reply(content: ContentInput): Promise<OutboundMessage<TPlatform, TSender, TSpace> | undefined>;
168
- reply(...content: [ContentInput, ContentInput, ...ContentInput[]]): Promise<OutboundMessage<TPlatform, TSender, TSpace>[]>;
169
- space: TSpace;
170
- timestamp: Date;
171
- }
172
- interface InboundMessage<TPlatform extends string = string, TSender extends User = User, TSpace extends Space = Space> extends BaseMessage<TPlatform, TSender, TSpace> {
173
- direction: "inbound";
174
- sender: TSender;
175
- }
176
- interface OutboundMessage<TPlatform extends string = string, TSender extends User = User, TSpace extends Space = Space> extends BaseMessage<TPlatform, TSender, TSpace> {
177
- direction: "outbound";
178
- edit(newContent: ContentInput): Promise<void>;
179
- sender: TSender | undefined;
180
- }
181
- type Message<TPlatform extends string = string, TSender extends User = User, TSpace extends Space = Space> = InboundMessage<TPlatform, TSender, TSpace> | OutboundMessage<TPlatform, TSender, TSpace>;
182
-
183
- /**
184
- * A small per-platform key-value bag, modeled after Swift's `UserDefaults`.
185
- * Untyped writes; typed reads return `undefined` on missing key OR type
186
- * mismatch (no throws). In-memory only.
187
- *
188
- * SDK-internal: reachable from inside `definePlatform` callbacks via the
189
- * `store` field on lifecycle/action/event ctx. Not exposed on the public
190
- * SpectrumInstance or platform narrower.
191
- */
192
- interface Store {
193
- array<T = unknown>(key: string): T[] | undefined;
194
- bool(key: string): boolean | undefined;
195
- clear(): void;
196
- delete(key: string): boolean;
197
- get(key: string): unknown;
198
- has(key: string): boolean;
199
- keys(): string[];
200
- number(key: string): number | undefined;
201
- object<T = Record<string, unknown>>(key: string): T | undefined;
202
- set(key: string, value: unknown): void;
203
- string(key: string): string | undefined;
204
- }
205
-
206
- interface ManagedStream<T> extends AsyncIterable<T> {
207
- close(): Promise<void>;
208
- }
209
- type StreamCleanup = void | (() => void | Promise<void>);
210
- declare function stream<T>(setup: (emit: (value: T) => Promise<void>, end: (error?: unknown) => void) => StreamCleanup | Promise<StreamCleanup>): ManagedStream<T>;
211
- declare function mergeStreams<T>(streams: readonly ManagedStream<T>[]): ManagedStream<T>;
212
- interface Broadcaster<T> {
213
- close(): Promise<void>;
214
- subscribe(): ManagedStream<T>;
215
- }
216
- declare function broadcast<T>(source: ManagedStream<T>): Broadcaster<T>;
217
-
218
- type ResolvedSpace = Pick<Space, "id">;
219
- type SpaceRef = Pick<Space, "id" | "__platform">;
220
- type ResolvedUser = Pick<User, "id">;
221
- type AwaitedReturn<T> = T extends (...args: never[]) => infer R ? Awaited<R> : never;
222
- type NoInferClient<T> = [T][T extends unknown ? 0 : never];
223
- type SchemaInfer<T> = T extends {
224
- schema?: infer S extends z__default.ZodType<object>;
225
- } ? z__default.infer<S> : Record<never, never>;
226
- type InferSchema<TSchema> = TSchema extends z__default.ZodType<object> ? z__default.infer<TSchema> : Record<never, never>;
227
- type InferOptionalSchema<TSchema> = TSchema extends z__default.ZodType<object> ? z__default.infer<TSchema> : never;
228
- type InputSchema<TSchema> = TSchema extends z__default.ZodType<object> ? z__default.input<TSchema> : never;
229
- type EventProducer<TPayload = unknown, TClient = unknown, TConfig = unknown> = (ctx: {
230
- client: NoInferClient<TClient>;
231
- config: TConfig;
232
- store: Store;
233
- }) => AsyncIterable<TPayload>;
234
- type ProviderMessage<TSender extends ResolvedUser = ResolvedUser, TSpace extends ResolvedSpace = ResolvedSpace, TExtra extends object = Record<never, never>> = {
235
- id: string;
236
- content: Content;
237
- sender: TSender;
238
- space: TSpace;
239
- timestamp?: Date;
240
- } & TExtra;
241
- /**
242
- * A message a provider produced — used for both inbound (`events.messages`,
243
- * `getMessage`) and outbound (`send`, `replyToMessage`) flows. Providers
244
- * return their native record shape (including platform extras like
245
- * `partIndex`/`parentId` for iMessage) and the platform `wrapProviderMessage`
246
- * pipeline turns it into a fully-built Message.
247
- *
248
- * `sender` is optional because outbound sends often can't synthesize one
249
- * (the SDK doesn't surface the bot's own handle); inbound providers are
250
- * expected to populate it.
251
- */
252
- type ProviderMessageRecord = {
253
- id: string;
254
- content: Content;
255
- sender?: {
256
- id: string;
257
- } & Record<string, unknown>;
258
- space: {
259
- id: string;
260
- } & Record<string, unknown>;
261
- timestamp?: Date;
262
- } & Record<string, unknown>;
263
- type MergeSchema<TSchema extends z__default.ZodType | undefined, TBase extends object> = TSchema extends z__default.ZodType ? string extends keyof z__default.infer<TSchema> ? TBase : Omit<z__default.infer<TSchema>, keyof TBase> & TBase : TBase;
264
- type SchemaMessage<TUserSchema extends z__default.ZodType | undefined = undefined, TSpaceSchema extends z__default.ZodType | undefined = undefined> = ProviderMessage<MergeSchema<TUserSchema, ResolvedUser>, MergeSchema<TSpaceSchema, ResolvedSpace>>;
265
- type InferEventPayload<T> = T extends (ctx: never) => AsyncIterable<infer P> ? P : never;
266
- type ReservedNames = "stop" | "send" | "__internal" | "__providers";
267
- interface CreateClientContext<_ConfigSchema extends z__default.ZodType<object>> {
268
- config: z__default.infer<_ConfigSchema>;
269
- projectId: string | undefined;
270
- projectSecret: string | undefined;
271
- store: Store;
272
- }
273
- interface PlatformDef<_Name extends string = string, _ConfigSchema extends z__default.ZodType<object> = z__default.ZodType<object>, _UserSchema extends z__default.ZodType<object> | undefined = undefined, _SpaceSchema extends z__default.ZodType<object> | undefined = undefined, _SpaceParamsSchema extends z__default.ZodType<object> | undefined = undefined, _Client = unknown, _ResolvedUser extends ResolvedUser = ResolvedUser, _ResolvedSpace extends ResolvedSpace = ResolvedSpace, _MessageSchema extends z__default.ZodType<object> | undefined = undefined, _MessageType extends ProviderMessage<_ResolvedUser, _ResolvedSpace, InferSchema<_MessageSchema>> = ProviderMessage<_ResolvedUser, _ResolvedSpace, InferSchema<_MessageSchema>>, _Events extends {
274
- messages: EventProducer<_MessageType, _Client, z__default.infer<_ConfigSchema>>;
275
- } = {
276
- messages: EventProducer<_MessageType, _Client, z__default.infer<_ConfigSchema>>;
277
- }> {
278
- actions: {
279
- send: (_: {
280
- space: _ResolvedSpace & SpaceRef;
281
- content: Content;
282
- client: NoInferClient<_Client>;
283
- config: z__default.infer<_ConfigSchema>;
284
- store: Store;
285
- }) => Promise<ProviderMessageRecord>;
286
- startTyping?: (_: {
287
- space: _ResolvedSpace & SpaceRef;
288
- client: NoInferClient<_Client>;
289
- config: z__default.infer<_ConfigSchema>;
290
- store: Store;
291
- }) => Promise<void>;
292
- stopTyping?: (_: {
293
- space: _ResolvedSpace & SpaceRef;
294
- client: NoInferClient<_Client>;
295
- config: z__default.infer<_ConfigSchema>;
296
- store: Store;
297
- }) => Promise<void>;
298
- reactToMessage?: (_: {
299
- space: _ResolvedSpace & SpaceRef;
300
- target: _MessageType;
301
- reaction: string;
302
- client: NoInferClient<_Client>;
303
- config: z__default.infer<_ConfigSchema>;
304
- store: Store;
305
- }) => Promise<void>;
306
- replyToMessage?: (_: {
307
- space: _ResolvedSpace & SpaceRef;
308
- messageId: string;
309
- target: _MessageType;
310
- content: Content;
311
- client: NoInferClient<_Client>;
312
- config: z__default.infer<_ConfigSchema>;
313
- store: Store;
314
- }) => Promise<ProviderMessageRecord>;
315
- editMessage?: (_: {
316
- space: _ResolvedSpace & SpaceRef;
317
- messageId: string;
318
- content: Content;
319
- client: NoInferClient<_Client>;
320
- config: z__default.infer<_ConfigSchema>;
321
- store: Store;
322
- }) => Promise<void>;
323
- getMessage?: (_: {
324
- space: _ResolvedSpace & SpaceRef;
325
- messageId: string;
326
- client: NoInferClient<_Client>;
327
- config: z__default.infer<_ConfigSchema>;
328
- store: Store;
329
- }) => Promise<_MessageType | undefined>;
330
- };
331
- config: _ConfigSchema;
332
- events: _Events;
333
- lifecycle: {
334
- createClient: (ctx: CreateClientContext<_ConfigSchema>) => Promise<_Client>;
335
- destroyClient?: (ctx: {
336
- client: NoInferClient<_Client>;
337
- store: Store;
338
- }) => Promise<void>;
339
- };
340
- message?: {
341
- schema?: _MessageSchema;
342
- };
343
- name: _Name;
344
- space: {
345
- schema?: _SpaceSchema;
346
- params?: _SpaceParamsSchema;
347
- resolve: (_: {
348
- input: {
349
- users: (_ResolvedUser & {
350
- __platform: _Name;
351
- })[];
352
- params?: _SpaceParamsSchema extends z__default.ZodType<object> ? z__default.infer<_SpaceParamsSchema> : undefined;
353
- };
354
- client: NoInferClient<_Client>;
355
- config: z__default.infer<_ConfigSchema>;
356
- store: Store;
357
- }) => Promise<_ResolvedSpace>;
358
- };
359
- user: {
360
- schema?: _UserSchema;
361
- resolve: (_: {
362
- input: {
363
- userID: string;
364
- };
365
- client: NoInferClient<_Client>;
366
- config: z__default.infer<_ConfigSchema>;
367
- store: Store;
368
- }) => Promise<_ResolvedUser>;
369
- };
370
- }
371
- interface AnyPlatformDef {
372
- actions: {
373
- send: (_: any) => Promise<ProviderMessageRecord>;
374
- startTyping?: (_: any) => Promise<void>;
375
- stopTyping?: (_: any) => Promise<void>;
376
- reactToMessage?: (_: any) => Promise<void>;
377
- replyToMessage?: (_: any) => Promise<ProviderMessageRecord>;
378
- editMessage?: (_: any) => Promise<void>;
379
- getMessage?: (_: any) => Promise<any>;
380
- };
381
- config: z__default.ZodType<object>;
382
- events: {
383
- messages: (ctx: any) => AsyncIterable<any>;
384
- [key: string]: (ctx: any) => AsyncIterable<any>;
385
- };
386
- lifecycle: {
387
- createClient: (ctx: any) => Promise<any>;
388
- destroyClient?: (ctx: any) => Promise<void>;
389
- };
390
- message?: {
391
- schema?: z__default.ZodType<object>;
392
- };
393
- name: string;
394
- space: {
395
- schema?: z__default.ZodType<object>;
396
- params?: z__default.ZodType<object>;
397
- resolve: (_: any) => Promise<any>;
398
- };
399
- user: {
400
- schema?: z__default.ZodType<object>;
401
- resolve: (_: any) => Promise<any>;
402
- };
403
- }
404
- interface PlatformProviderConfig<Def extends AnyPlatformDef = AnyPlatformDef> {
405
- readonly __def: Def;
406
- readonly __definition: AnyPlatformDef;
407
- readonly __name: Def["name"];
408
- readonly __tag: "PlatformProviderConfig";
409
- readonly config: unknown;
410
- }
411
- interface MatchesPlatformName<Name extends string> extends Fn {
412
- return: this["arg0"] extends PlatformProviderConfig<infer Def> ? Def["name"] extends Name ? true : false : false;
413
- }
414
- interface ExtractDef extends Fn {
415
- return: this["arg0"] extends PlatformProviderConfig<infer Def> ? Def : never;
416
- }
417
- interface ExtractCustomEventNames extends Fn {
418
- return: this["arg0"] extends AnyPlatformDef ? Exclude<keyof this["arg0"]["events"], "messages" | symbol | number> : never;
419
- }
420
- interface ToCustomEventVariant<EventName extends string> extends Fn {
421
- return: this["arg0"] extends PlatformProviderConfig<infer Def> ? EventName extends keyof Def["events"] ? InferEventPayload<Def["events"][EventName]> & {
422
- platform: Def["name"];
423
- } : never : never;
424
- }
425
- type HasProvider<Providers extends PlatformProviderConfig[], Name extends string> = Pipe<Providers, [Tuples.Some<MatchesPlatformName<Name>>]>;
426
- type AllCustomEventNames<Providers extends PlatformProviderConfig[]> = Pipe<Providers, [
427
- Tuples.Map<ExtractDef>,
428
- Tuples.Map<ExtractCustomEventNames>,
429
- Tuples.ToUnion
430
- ]>;
431
- type UnifiedCustomEvent<Providers extends PlatformProviderConfig[], EventName extends string> = Pipe<Providers, [
432
- Tuples.Map<ToCustomEventVariant<EventName>>,
433
- Tuples.ToUnion
434
- ]>;
435
- type CustomEventStreams<Providers extends PlatformProviderConfig[]> = {
436
- [K in Exclude<AllCustomEventNames<Providers>, ReservedNames> & string]: AsyncIterable<UnifiedCustomEvent<Providers, K>>;
437
- };
438
- type ResolvedSpaceOf<Def extends AnyPlatformDef> = AwaitedReturn<Def["space"]["resolve"]>;
439
- type SchemaSpaceOf<Def extends AnyPlatformDef> = InferOptionalSchema<Def["space"]["schema"]>;
440
- type ResolvedUserOf<Def extends AnyPlatformDef> = AwaitedReturn<Def["user"]["resolve"]>;
441
- type SpaceShapeOf<Def extends AnyPlatformDef> = [SchemaSpaceOf<Def>] extends [
442
- never
443
- ] ? ResolvedSpaceOf<Def> : SchemaSpaceOf<Def>;
444
- type SpaceParamsInputOf<Def extends AnyPlatformDef> = InputSchema<Def["space"]["params"]>;
445
- type SpaceUserLike<Def extends AnyPlatformDef> = PlatformUser<Def> | string;
446
- type SpaceArrayArgs<Def extends AnyPlatformDef> = [
447
- SpaceParamsInputOf<Def>
448
- ] extends [never] ? [users: SpaceUserLike<Def>[]] : [users: SpaceUserLike<Def>[]] | [users: SpaceUserLike<Def>[], params: SpaceParamsInputOf<Def>] | [params: SpaceParamsInputOf<Def>];
449
- type SpaceVarargArgs<Def extends AnyPlatformDef> = [
450
- SpaceParamsInputOf<Def>
451
- ] extends [never] ? SpaceUserLike<Def>[] : SpaceUserLike<Def>[] | [...SpaceUserLike<Def>[], SpaceParamsInputOf<Def>];
452
- type SpaceArgs<Def extends AnyPlatformDef> = SpaceArrayArgs<Def> | SpaceVarargArgs<Def>;
453
- type PlatformSpace<Def extends AnyPlatformDef> = Omit<SpaceShapeOf<Def>, keyof Space> & Space;
454
- type PlatformMessage<Def extends AnyPlatformDef> = Omit<SchemaInfer<Def["message"]>, keyof Message> & Message<Def["name"], PlatformUser<Def>, PlatformSpace<Def>>;
455
- type InboundPlatformMessage<Def extends AnyPlatformDef> = Omit<SchemaInfer<Def["message"]>, keyof InboundMessage> & InboundMessage<Def["name"], PlatformUser<Def>, PlatformSpace<Def>>;
456
- type PlatformUser<Def extends AnyPlatformDef> = Omit<ResolvedUserOf<Def>, keyof User> & User;
457
- type PlatformInstance<Def extends AnyPlatformDef> = {
458
- readonly messages: AsyncIterable<[
459
- PlatformSpace<Def>,
460
- InboundPlatformMessage<Def>
461
- ]>;
462
- space(...args: SpaceArgs<Def>): Promise<PlatformSpace<Def>>;
463
- user(userID: string): Promise<PlatformUser<Def>>;
464
- } & {
465
- [K in Exclude<keyof Def["events"], "messages" | symbol | number> as K extends ReservedNames ? never : K]: AsyncIterable<InferEventPayload<Def["events"][K]>>;
466
- };
467
- interface PlatformRuntime {
468
- client: unknown;
469
- config: unknown;
470
- definition: AnyPlatformDef;
471
- store: Store;
472
- subscribeMessages: () => ManagedStream<[Space, InboundMessage]>;
473
- }
474
- interface SpectrumLike<Providers extends PlatformProviderConfig[] = PlatformProviderConfig[]> {
475
- readonly __internal: {
476
- platforms: Map<string, PlatformRuntime>;
477
- };
478
- readonly __providers: Providers;
479
- }
480
- interface Platform<Def extends AnyPlatformDef> {
481
- config(...args: Record<string, never> extends z__default.input<Def["config"]> ? [config?: z__default.input<Def["config"]>] : [config: z__default.input<Def["config"]>]): PlatformProviderConfig<Def>;
482
- is(input: Message): input is PlatformMessage<Def>;
483
- is(input: Space): input is PlatformSpace<Def>;
484
- is(input: unknown): input is PlatformMessage<Def> | PlatformSpace<Def>;
485
- <Providers extends PlatformProviderConfig[]>(spectrum: SpectrumLike<Providers>): HasProvider<Providers, Def["name"]> extends true ? PlatformInstance<Def> : never;
486
- (space: Space): PlatformSpace<Def>;
487
- (message: Message): PlatformMessage<Def>;
488
- }
489
-
490
- export { type AnyPlatformDef as A, type Broadcaster as B, type ContentInput as C, type EventProducer as E, type InboundMessage as I, type Message as M, type OutboundMessage as O, type Platform as P, type Store as S, type User as U, type PlatformDef as a, type ProviderMessage as b, type SchemaMessage as c, type ManagedStream as d, type ContentBuilder as e, type Content as f, type CreateClientContext as g, type PlatformProviderConfig as h, type SpectrumLike as i, type CustomEventStreams as j, type Space as k, type InboundPlatformMessage as l, type PlatformInstance as m, type PlatformMessage as n, type PlatformRuntime as o, type PlatformSpace as p, type PlatformUser as q, broadcast as r, mergeStreams as s, stream as t };