@luckystack/devkit 0.1.9 → 0.2.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.
@@ -1,65 +1,65 @@
1
- /* eslint-disable unicorn/no-abusive-eslint-disable */
2
- /* eslint-disable */
3
-
4
- //@ts-ignore We replace {{REL_PATH}} with the relative path to the project root at scaffold time.
5
- import { AuthProps, SessionLayout } from '{{REL_PATH}}config';
6
- //@ts-ignore We replace {{REL_PATH}} with the relative path to the project root at scaffold time.
7
- import { Functions, SyncServerResponse, MaybePromise, SyncServerStreamEmitter, SyncBroadcastStreamEmitter, SyncStreamToEmitter } from '{{REL_PATH}}src/_sockets/apiTypes.generated';
8
-
9
- export const auth: AuthProps = {
10
- login: true,
11
- additional: []
12
- };
13
-
14
- export interface SyncParams {
15
- clientInput: {
16
- // Define the data shape sent from the client e.g.
17
- // message: string;
18
- // targetUserId: string;
19
- };
20
- user: SessionLayout; // session data of the user who called the sync event
21
- functions: Functions; // functions object
22
- roomCode: string; // room code
23
- //? Stream primitives — pick whichever audience matches your use case:
24
- //? stream → originator only (cheapest)
25
- //? broadcastStream → every socket in the receiver room (live AI chat, collab)
26
- //? streamTo → specific session tokens only (selective subscribers)
27
- stream: SyncServerStreamEmitter;
28
- broadcastStream: SyncBroadcastStreamEmitter;
29
- streamTo: SyncStreamToEmitter;
30
- //? Aborts on client-side cancel (`syncRequest({ signal })`) or socket
31
- //? disconnect. Check `abortSignal.aborted` in long-running loops and bail
32
- //? out — already-emitted chunks are not unsent, but new ones are
33
- //? short-circuited automatically by the stream emitters.
34
- abortSignal: AbortSignal;
35
- //? Awaitable backpressure helper. Resolves once the worst-case write
36
- //? buffer across affected sockets drops below the threshold (default 1 MB).
37
- //? Use opt-in between batches of stream chunks to keep memory bounded.
38
- flushPressure: (options?: { thresholdBytes?: number }) => Promise<void>;
39
- }
40
-
41
- export const main = ({ }: SyncParams): MaybePromise<SyncServerResponse> => {
42
- // THIS FILE RUNS JUST ONCE ON THE SERVER
43
-
44
- // Stream payload types are generated from your stream(...) calls.
45
- // stream({ phase: 'validate', progress: 10 }); // → originator only
46
- // broadcastStream({ chunk: 'hello' }); // → everyone in the room
47
- // streamTo([adminToken], { audit: 'event' }); // → specific tokens
48
-
49
- // For LLM token streams, coalesce small pieces with createStreamThrottle:
50
- // import { createStreamThrottle } from '@luckystack/sync';
51
- // const throttle = createStreamThrottle({ flushEveryMs: 50, flushAtChars: 32 });
52
- // for await (const piece of aiStream) throttle.push(piece.text, broadcastStream);
53
- // throttle.flush(broadcastStream);
54
-
55
- // Return { status: 'error', message: '...' } OR { status: 'error', errorCode: '...' }
56
- // Returning error here aborts the full sync flow.
57
-
58
- // Please validate clientInput here and dont just send the data back to the other clients
59
- // optional: database action or something else
60
-
61
- return {
62
- status: 'success',
63
- // Add any data you want to broadcast to clients
64
- };
1
+ /* eslint-disable unicorn/no-abusive-eslint-disable */
2
+ /* eslint-disable */
3
+
4
+ //@ts-ignore We replace {{REL_PATH}} with the relative path to the project root at scaffold time.
5
+ import { AuthProps, SessionLayout } from '{{REL_PATH}}config';
6
+ //@ts-ignore We replace {{REL_PATH}} with the relative path to the project root at scaffold time.
7
+ import { Functions, SyncServerResponse, MaybePromise, SyncServerStreamEmitter, SyncBroadcastStreamEmitter, SyncStreamToEmitter } from '{{REL_PATH}}src/_sockets/apiTypes.generated';
8
+
9
+ export const auth: AuthProps = {
10
+ login: true,
11
+ additional: []
12
+ };
13
+
14
+ export interface SyncParams {
15
+ clientInput: {
16
+ // Define the data shape sent from the client e.g.
17
+ // message: string;
18
+ // targetUserId: string;
19
+ };
20
+ user: SessionLayout; // session data of the user who called the sync event
21
+ functions: Functions; // functions object
22
+ roomCode: string; // room code
23
+ //? Stream primitives — pick whichever audience matches your use case:
24
+ //? stream → originator only (cheapest)
25
+ //? broadcastStream → every socket in the receiver room (live AI chat, collab)
26
+ //? streamTo → specific session tokens only (selective subscribers)
27
+ stream: SyncServerStreamEmitter;
28
+ broadcastStream: SyncBroadcastStreamEmitter;
29
+ streamTo: SyncStreamToEmitter;
30
+ //? Aborts on client-side cancel (`syncRequest({ signal })`) or socket
31
+ //? disconnect. Check `abortSignal.aborted` in long-running loops and bail
32
+ //? out — already-emitted chunks are not unsent, but new ones are
33
+ //? short-circuited automatically by the stream emitters.
34
+ abortSignal: AbortSignal;
35
+ //? Awaitable backpressure helper. Resolves once the worst-case write
36
+ //? buffer across affected sockets drops below the threshold (default 1 MB).
37
+ //? Use opt-in between batches of stream chunks to keep memory bounded.
38
+ flushPressure: (options?: { thresholdBytes?: number }) => Promise<void>;
39
+ }
40
+
41
+ export const main = ({ }: SyncParams): MaybePromise<SyncServerResponse> => {
42
+ // THIS FILE RUNS JUST ONCE ON THE SERVER
43
+
44
+ // Stream payload types are generated from your stream(...) calls.
45
+ // stream({ phase: 'validate', progress: 10 }); // → originator only
46
+ // broadcastStream({ chunk: 'hello' }); // → everyone in the room
47
+ // streamTo([adminToken], { audit: 'event' }); // → specific tokens
48
+
49
+ // For LLM token streams, coalesce small pieces with createStreamThrottle:
50
+ // import { createStreamThrottle } from '@luckystack/sync';
51
+ // const throttle = createStreamThrottle({ flushEveryMs: 50, flushAtChars: 32 });
52
+ // for await (const piece of aiStream) throttle.push(piece.text, broadcastStream);
53
+ // throttle.flush(broadcastStream);
54
+
55
+ // Return { status: 'error', message: '...' } OR { status: 'error', errorCode: '...' }
56
+ // Returning error here aborts the full sync flow.
57
+
58
+ // Please validate clientInput here and dont just send the data back to the other clients
59
+ // optional: database action or something else
60
+
61
+ return {
62
+ status: 'success',
63
+ // Add any data you want to broadcast to clients
64
+ };
65
65
  };