Skip to content

Commit

Permalink
[New SDK]: 'wasp/server/webSocket'.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martinsos committed Jan 31, 2024
1 parent 51f299e commit bfc7e3b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions waspc/data/Generator/templates/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@
{=! Used by our code, uncodumented (but accessible) for users. =}
{=! Todo(filip): This export becomes problematic once we start supporting different executors =}
"./server/jobs/pgBoss/types": "./dist/server/jobs/pgBoss/types.js",
{=! Used by users, documented. =}
"./server/webSocket": "./dist/server/webSocket/index.js",

{=! Used by the framework client code, reconsider during refactoring. =}
"./client/webSocket/WebSocketProvider": "./dist/client/webSocket/WebSocketProvider.jsx",
Expand All @@ -110,6 +108,9 @@
{=! Public: { type ServerToClientPayload, type ClientToServerPayload, useSocket, useSocketListener } =}
{=! Private: [] =}
"./client/webSocket": "./dist/client/webSocket/index.js",
{=! Public: { type WebSocketDefinition, type WaspSocketData } =}
{=! Private: [server, sdk] =}
"./server/webSocket": "./dist/server/webSocket/index.js",
"./auth": "./dist/auth/index.js",
"./client/auth": "./dist/client/auth/index.js",
"./server/auth": "./dist/server/auth/index.js",
Expand Down
5 changes: 5 additions & 0 deletions waspc/data/Generator/templates/sdk/server/webSocket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { type AuthUser } from 'wasp/auth'

{=& userWebSocketFn.importStatement =}

// Public API
export type WebSocketDefinition<
ClientToServerEvents extends EventsMap = DefaultEventsMap,
ServerToClientEvents extends EventsMap = DefaultEventsMap,
Expand All @@ -31,15 +32,19 @@ export type WebSocketDefinition<
}
) => Promise<void> | void

// PUBLIC API
export interface WaspSocketData {
{=# isAuthEnabled =}
user?: AuthUser
{=/ isAuthEnabled =}
}

// PRIVATE API
export type ServerType = Parameters<WebSocketFn>[0]

// PRIVATE API
export type ClientToServerEvents = Events[0]
// PRIVATE API
export type ServerToClientEvents = Events[1]

type WebSocketFn = typeof {= userWebSocketFn.importIdentifier =}
Expand Down

0 comments on commit bfc7e3b

Please sign in to comment.