{"version":3,"file":"hocuspocus-common.cjs","names":["decoding"],"sources":["../src/auth.ts","../src/CloseEvents.ts","../src/awarenessStatesToArray.ts","../src/routingKey.ts","../src/SkipFurtherHooksError.ts","../src/types.ts"],"sourcesContent":["import * as encoding from \"lib0/encoding\";\nimport * as decoding from \"lib0/decoding\";\nimport type {AuthorizedScope} from \"../../provider/src\"\n\nexport enum AuthMessageType {\n\tToken = 0,\n\tPermissionDenied = 1,\n\tAuthenticated = 2,\n}\n\nexport const writeAuthentication = (\n\tencoder: encoding.Encoder,\n\tauth: string,\n) => {\n\tencoding.writeVarUint(encoder, AuthMessageType.Token);\n\tencoding.writeVarString(encoder, auth);\n};\n\nexport const writePermissionDenied = (\n\tencoder: encoding.Encoder,\n\treason: string,\n) => {\n\tencoding.writeVarUint(encoder, AuthMessageType.PermissionDenied);\n\tencoding.writeVarString(encoder, reason);\n};\n\nexport const writeAuthenticated = (\n\tencoder: encoding.Encoder,\n\tscope: AuthorizedScope,\n) => {\n\tencoding.writeVarUint(encoder, AuthMessageType.Authenticated);\n\tencoding.writeVarString(encoder, scope);\n};\n\nexport const writeTokenSyncRequest = (\n\tencoder: encoding.Encoder,\n) => {\n\tencoding.writeVarUint(encoder, AuthMessageType.Token);\n};\n\nexport const readAuthMessage = (\n\tdecoder: decoding.Decoder,\n\tsendToken: () => void,\n\tpermissionDeniedHandler: (reason: string) => void,\n\tauthenticatedHandler: (scope: string) => void,\n) => {\n\tswitch (decoding.readVarUint(decoder)) {\n\t\tcase AuthMessageType.Token: {\n\t\t\tsendToken();\n\t\t\tbreak;\n\t\t}\n\t\tcase AuthMessageType.PermissionDenied: {\n\t\t\tpermissionDeniedHandler(decoding.readVarString(decoder));\n\t\t\tbreak;\n\t\t}\n\t\tcase AuthMessageType.Authenticated: {\n\t\t\tauthenticatedHandler(decoding.readVarString(decoder));\n\t\t\tbreak;\n\t\t}\n\t\tdefault:\n\t}\n};\n","export interface CloseEvent {\n\tcode: number;\n\treason: string;\n}\n\n/**\n * The server is terminating the connection because a data frame was received\n * that is too large.\n * See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code\n */\nexport const MessageTooBig: CloseEvent = {\n\tcode: 1009,\n\treason: \"Message Too Big\",\n};\n\n/**\n * The server successfully processed the request, asks that the requester reset\n * its document view, and is not returning any content.\n */\nexport const ResetConnection: CloseEvent = {\n\tcode: 4205,\n\treason: \"Reset Connection\",\n};\n\n/**\n * Similar to Forbidden, but specifically for use when authentication is required and has\n * failed or has not yet been provided.\n */\nexport const Unauthorized: CloseEvent = {\n\tcode: 4401,\n\treason: \"Unauthorized\",\n};\n\n/**\n * The request contained valid data and was understood by the server, but the server\n * is refusing action.\n */\nexport const Forbidden: CloseEvent = {\n\tcode: 4403,\n\treason: \"Forbidden\",\n};\n\n/**\n * The server timed out waiting for the request.\n */\nexport const ConnectionTimeout: CloseEvent = {\n\tcode: 4408,\n\treason: \"Connection Timeout\",\n};\n","export const awarenessStatesToArray = (\n\tstates: Map<number, Record<string, any>>,\n) => {\n\treturn Array.from(states.entries()).map(([key, value]) => {\n\t\treturn {\n\t\t\tclientId: key,\n\t\t\t...value,\n\t\t};\n\t});\n};\n","const SEPARATOR = '\\0';\n\nexport function makeRoutingKey(documentName: string, sessionId: string): string {\n\treturn documentName + SEPARATOR + sessionId;\n}\n\nexport function parseRoutingKey(key: string): { documentName: string; sessionId: string | null } {\n\tconst idx = key.indexOf(SEPARATOR);\n\tif (idx === -1) return { documentName: key, sessionId: null };\n\treturn { documentName: key.substring(0, idx), sessionId: key.substring(idx + 1) };\n}\n","export class SkipFurtherHooksError extends Error {\n\tconstructor(message?: string) {\n\t\tsuper(message ?? \"Further hooks skipped\");\n\t\tthis.name = \"SkipFurtherHooksError\";\n\t}\n}\n","/**\n * State of the WebSocket connection.\n * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState\n */\nexport enum WsReadyStates {\n\tConnecting = 0,\n\tOpen = 1,\n\tClosing = 2,\n\tClosed = 3,\n}\n"],"mappings":";;;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