@supalive/core 1.17.0 → 1.18.0
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/dist/index-B3i2G1gr.d.ts +2402 -0
- package/dist/index-B3i2G1gr.d.ts.map +1 -0
- package/dist/index-BHs0EtJk.d.ts +2402 -0
- package/dist/index-BHs0EtJk.d.ts.map +1 -0
- package/dist/index-BMz7jVbX.d.ts +2402 -0
- package/dist/index-BMz7jVbX.d.ts.map +1 -0
- package/dist/index-CjkNEwSc.d.ts +2402 -0
- package/dist/index-CjkNEwSc.d.ts.map +1 -0
- package/dist/index-Cng74DL5.d.ts +2404 -0
- package/dist/index-Cng74DL5.d.ts.map +1 -0
- package/dist/index-yXV5AMh9.d.ts +2416 -0
- package/dist/index-yXV5AMh9.d.ts.map +1 -0
- package/dist/mysql-1ENHI0yX.d.ts +114 -0
- package/dist/mysql-1ENHI0yX.d.ts.map +1 -0
- package/dist/mysql-C6jg1Vpr.d.ts +114 -0
- package/dist/mysql-C6jg1Vpr.d.ts.map +1 -0
- package/dist/mysql-DKR33wfH.d.ts +114 -0
- package/dist/mysql-DKR33wfH.d.ts.map +1 -0
- package/dist/mysql-DcHgRk9f.d.ts +114 -0
- package/dist/mysql-DcHgRk9f.d.ts.map +1 -0
- package/dist/mysql-DnrIJoWL.d.ts +114 -0
- package/dist/mysql-DnrIJoWL.d.ts.map +1 -0
- package/dist/mysql-GsWYd6fG.d.ts +114 -0
- package/dist/mysql-GsWYd6fG.d.ts.map +1 -0
- package/dist/postgres-CFarR3cB.d.ts +118 -0
- package/dist/postgres-CFarR3cB.d.ts.map +1 -0
- package/dist/postgres-CWVM-KKP.d.ts +118 -0
- package/dist/postgres-CWVM-KKP.d.ts.map +1 -0
- package/dist/postgres-D50xpaQ-.d.ts +118 -0
- package/dist/postgres-D50xpaQ-.d.ts.map +1 -0
- package/dist/postgres-tVdgYJkj.d.ts +118 -0
- package/dist/postgres-tVdgYJkj.d.ts.map +1 -0
- package/dist/postgres-yAn2CF7j.d.ts +118 -0
- package/dist/postgres-yAn2CF7j.d.ts.map +1 -0
- package/dist/postgres-yTjQ-Nxk.d.ts +118 -0
- package/dist/postgres-yTjQ-Nxk.d.ts.map +1 -0
- package/dist/src/client/index.d.ts +1 -1
- package/dist/src/client/index.js +1 -1
- package/dist/src/client/index.js.map +1 -1
- package/dist/src/exports/mysql.d.ts +1 -1
- package/dist/src/exports/postgres.d.ts +1 -1
- package/dist/src/exports/procedure.d.ts +1 -1
- package/dist/src/exports/schema-sql.d.ts +1 -1
- package/dist/src/exports/server.d.ts +10 -7
- package/dist/src/exports/server.d.ts.map +1 -1
- package/dist/src/exports/server.js +14 -5
- package/dist/src/exports/server.js.map +1 -1
- package/dist/src/exports/sub-manager-worker-entry.js +1 -1
- package/dist/src/exports/types.d.ts +3 -3
- package/dist/src/exports/types.js +1 -1
- package/dist/sub-worker-dispatch-Cvqarej5.js +826 -0
- package/dist/sub-worker-dispatch-Cvqarej5.js.map +1 -0
- package/dist/sub-worker-dispatch-D-3VPkd4.js +826 -0
- package/dist/sub-worker-dispatch-D-3VPkd4.js.map +1 -0
- package/dist/sub-worker-dispatch-qiSs5Xkm.js.map +1 -1
- package/dist/types_client_rpc-B8jh6MKl.js +154 -0
- package/dist/types_client_rpc-B8jh6MKl.js.map +1 -0
- package/dist/types_client_rpc-BRCAgeyJ.js +155 -0
- package/dist/types_client_rpc-BRCAgeyJ.js.map +1 -0
- package/dist/types_server-B5KQ6PAO.d.ts +692 -0
- package/dist/types_server-B5KQ6PAO.d.ts.map +1 -0
- package/dist/types_server-BJBeSk6n.d.ts +691 -0
- package/dist/types_server-BJBeSk6n.d.ts.map +1 -0
- package/dist/types_server-BXeiSmd8.d.ts +691 -0
- package/dist/types_server-BXeiSmd8.d.ts.map +1 -0
- package/dist/types_server-BnRmctWG.d.ts +699 -0
- package/dist/types_server-BnRmctWG.d.ts.map +1 -0
- package/dist/types_server-C20ibVGu.d.ts +692 -0
- package/dist/types_server-C20ibVGu.d.ts.map +1 -0
- package/dist/types_server-CjjJIQps.d.ts +691 -0
- package/dist/types_server-CjjJIQps.d.ts.map +1 -0
- package/dist/types_server-CjzRPllt.d.ts +691 -0
- package/dist/types_server-CjzRPllt.d.ts.map +1 -0
- package/dist/types_server-Cy4bvdeN.d.ts +691 -0
- package/dist/types_server-Cy4bvdeN.d.ts.map +1 -0
- package/package.json +1 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types_client_rpc-B8jh6MKl.js","names":[],"sources":["../src/db/types_client_rpc.ts"],"sourcesContent":["import z from \"zod\";\n\nexport interface ErrorMessage {\n type: \"error\";\n id?: string;\n error: string;\n code?: string;\n}\n\n// ─── WebSocket Message Schemas ────────────────────────────────────────────────\n// Zod schemas for runtime validation of WebSocket messages\n\nexport const AuthMessageSchema = z.object({\n type: z.literal(\"auth\"),\n data: z.record(z.string(), z.any()).optional(),\n});\n\nexport const CallMessageSchema = z.object({\n type: z.literal(\"call\"),\n // Bounded so a client can't push oversized correlation ids / procedure names\n // through the 100MB WS frame limit and burn CPU/memory before the procedure\n // lookup even runs. A request id is a short client token; a procedure name is\n // a symbol.\n id: z.string().max(128),\n procedure: z.string().max(256),\n input: z.unknown(),\n /**\n * Client read high-water: the largest commit/snapshot ts the client has\n * already observed (from a prior mutation's commitTs or a query's returned\n * `ts`). Decimal string (bigint on the wire). The server routes a query's\n * reads to the replica ONLY when the replica has applied at least this ts —\n * giving read-your-writes + monotonic reads without a signed token. Omitted\n * until the client has observed anything. The server clamps it to its own\n * primary latest, so a client can't pin the primary forever with a bogus value.\n */\n minTs: z.string().max(40).optional(),\n /**\n * W3C `traceparent` for distributed tracing. When the client is running\n * OpenTelemetry it injects the active context here; the server continues the\n * trace so the operation span is a child of the client's. Ignored when tracing\n * isn't enabled server-side. Optional and unauthenticated — purely diagnostic.\n *\n * Bounded: a valid W3C `traceparent` is 55 chars; the cap keeps an\n * unauthenticated field from being used to ship a large blob into\n * `propagation.extract`.\n */\n trace: z.string().max(256).optional(),\n});\n\nexport const SubscribeMessageSchema = z.object({\n type: z.literal(\"subscribe\"),\n id: z.string().max(128),\n procedure: z.string().max(256),\n input: z.unknown(),\n /** W3C `traceparent` (bounded); see {@link CallMessageSchema}. */\n trace: z.string().max(256).optional(),\n});\n\nexport const UnsubscribeMessageSchema = z.object({\n type: z.literal(\"unsubscribe\"),\n subId: z.string(),\n});\n\nexport const ClientMessageSchema = z.union([\n AuthMessageSchema,\n CallMessageSchema,\n SubscribeMessageSchema,\n UnsubscribeMessageSchema,\n]);\n\n// Infer TypeScript types from schemas\nexport type AuthMessage = z.infer<typeof AuthMessageSchema>;\nexport type CallMessage = z.infer<typeof CallMessageSchema>;\nexport type SubscribeMessage = z.infer<typeof SubscribeMessageSchema>;\nexport type UnsubscribeMessage = z.infer<typeof UnsubscribeMessageSchema>;\nexport type ClientMessage = z.infer<typeof ClientMessageSchema>;\n\n// ─── Server Message Schemas ───────────────────────────────────────────────────\n\nexport const ConnectedMessageSchema = z.object({\n type: z.literal(\"connected\"),\n sessionId: z.string(),\n build: z.number().int().nonnegative().optional(),\n});\n\nexport const AuthSuccessMessageSchema = z.object({\n type: z.literal(\"auth:success\"),\n userId: z.string(),\n extra: z.object().optional(),\n build: z.number().int().nonnegative().optional(),\n});\n\nexport const AuthFailedMessageSchema = z.object({\n type: z.literal(\"auth:failed\"),\n message: z.string(),\n extra: z.record(z.string(), z.unknown()).optional(),\n build: z.number().int().nonnegative().optional(),\n});\n\nexport const ResponseMessageSchema = z.object({\n type: z.literal(\"response\"),\n id: z.string(),\n success: z.boolean(),\n data: z.unknown().optional(),\n error: z.string().optional(),\n code: z.string().optional(),\n /**\n * Populated by the server only for a successful `subscribe` response.\n * Carries the canonical, server-computed subscription id so the client\n * can route subsequent `sub:update` / `sub:gone` messages without\n * recomputing the hash locally (which would require the wasm runtime\n * and would not reflect server-side per-procedure `queryIdentity`\n * overrides).\n */\n subId: z.string().optional(),\n /**\n * Observed commit/snapshot ts for a successful `call`. Decimal string\n * (bigint on the wire). For a query it's the snapshot the reads ran at; for a\n * mutation it's the commitTs. The client folds it into its read high-water\n * (see {@link CallMessageSchema.minTs}) so later reads preserve\n * read-your-writes / monotonic reads. Absent for actions and error responses.\n */\n ts: z.string().optional(),\n build: z.number().int().nonnegative().optional(),\n});\n\nexport const SubscriptionUpdateMessageSchema = z.object({\n type: z.literal(\"sub:update\"),\n subId: z.string(),\n data: z.unknown(),\n dataHash: z.string().optional(),\n /**\n * The primary snapshot ts this update's data reflects. Decimal string (bigint\n * on the wire). The client folds it into its read high-water so a later\n * one-shot query can't route to a replica that is behind what the live view\n * already showed (cross-subscription monotonic reads). Present on server-side\n * recomputes; omitted when the update is served straight from cache (no ts\n * handy) — the client simply doesn't advance for those.\n */\n ts: z.string().optional(),\n build: z.number().int().nonnegative().optional(),\n});\n\n/**\n * Notifies a client that a subscription is no longer tracked on the server\n * and will not receive further updates. Sent when, during a sub-manager\n * recovery cycle, the registration record could not be found (e.g. another\n * app-server instance fully unregistered the sub while we were disconnected).\n * The client may choose to re-subscribe or surface the state to the user.\n */\nexport const SubscriptionGoneMessageSchema = z.object({\n type: z.literal(\"sub:gone\"),\n subId: z.string(),\n reason: z.string().optional(),\n build: z.number().int().nonnegative().optional(),\n});\n\n/**\n * Server-driven liveness signal. Sent when the channel has been idle for\n * the configured app-ping interval (default 15s) and again after every\n * outbound message. Pure no-op for the client: receiving any message\n * (including this one) resets the client's inactivity watchdog. The client\n * does NOT reply.\n */\nexport const ServerPingMessageSchema = z.object({\n type: z.literal(\"ping\"),\n build: z.number().int().nonnegative().optional(),\n});\n\nexport const ServerMessageSchema = z.union([\n ConnectedMessageSchema,\n AuthSuccessMessageSchema,\n AuthFailedMessageSchema,\n ResponseMessageSchema,\n SubscriptionUpdateMessageSchema,\n SubscriptionGoneMessageSchema,\n ServerPingMessageSchema,\n]);\n\nexport type ConnectedMessage = z.infer<typeof ConnectedMessageSchema>;\nexport type AuthSuccessMessage = z.infer<typeof AuthSuccessMessageSchema>;\nexport type AuthFailedMessage = z.infer<typeof AuthFailedMessageSchema>;\nexport type ResponseMessage = z.infer<typeof ResponseMessageSchema>;\nexport type SubscriptionUpdateMessage = z.infer<typeof SubscriptionUpdateMessageSchema>;\nexport type SubscriptionGoneMessage = z.infer<typeof SubscriptionGoneMessageSchema>;\nexport type ServerPingMessage = z.infer<typeof ServerPingMessageSchema>;\nexport type ServerMessage = z.infer<typeof ServerMessageSchema>;\n\nexport class AuthenticationError extends Error {\n constructor(\n message: string,\n public extra: Record<string, unknown> = {},\n ) {\n super(message);\n }\n}\n\n/**\n * Helper type to check if a procedure is internal.\n */\nexport type IsInternal<T> = T extends { internal: infer I } ? (I extends true ? true : false) : false;\n\nexport interface Context {\n requestId: string;\n /** Authenticated user info */\n user: {\n userId: string;\n };\n}\n"],"mappings":";;AAYA,MAAa,oBAAoB,EAAE,OAAO;CACxC,MAAM,EAAE,QAAQ,MAAM;CACtB,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS;AAC/C,CAAC;AAED,MAAa,oBAAoB,EAAE,OAAO;CACxC,MAAM,EAAE,QAAQ,MAAM;CAKtB,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG;CACtB,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG;CAC7B,OAAO,EAAE,QAAQ;;;;;;;;;;CAUjB,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS;;;;;;;;;;;CAWnC,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS;AACtC,CAAC;AAED,MAAa,yBAAyB,EAAE,OAAO;CAC7C,MAAM,EAAE,QAAQ,WAAW;CAC3B,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG;CACtB,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG;CAC7B,OAAO,EAAE,QAAQ;;CAEj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CAAC,CAAC,SAAS;CACxB,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS;AACjD,CAAC;AAED,MAAa,kCAAkC,EAAE,OAAO;CACtD,MAAM,EAAE,QAAQ,YAAY;CAC5B,OAAO,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ;CAChB,UAAU,EAAE,OAAO,CAAC,CAAC,SAAS;;;;;;;;;CAS9B,IAAI,EAAE,OAAO,CAAC,CAAC,SAAS;CACxB,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS;AACjD,CAAC;;;;;;;;AASD,MAAa,gCAAgC,EAAE,OAAO;CACpD,MAAM,EAAE,QAAQ,UAAU;CAC1B,OAAO,EAAE,OAAO;CAChB,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;CAC5B,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS;AACjD,CAAC;;;;;;;;AASD,MAAa,0BAA0B,EAAE,OAAO;CAC9C,MAAM,EAAE,QAAQ,MAAM;CACtB,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS;AACjD,CAAC;AAED,MAAa,sBAAsB,EAAE,MAAM;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAWD,IAAa,sBAAb,cAAyC,MAAM;CAGpC;CAFT,YACE,SACA,QAAwC,CAAC,GACzC;EACA,MAAM,OAAO;EAFN,KAAA,QAAA;CAGT;AACF"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
//#region src/db/types_client_rpc.ts
|
|
3
|
+
const AuthMessageSchema = z.object({
|
|
4
|
+
type: z.literal("auth"),
|
|
5
|
+
data: z.record(z.string(), z.any()).optional()
|
|
6
|
+
});
|
|
7
|
+
const CallMessageSchema = z.object({
|
|
8
|
+
type: z.literal("call"),
|
|
9
|
+
id: z.string().max(128),
|
|
10
|
+
procedure: z.string().max(256),
|
|
11
|
+
input: z.unknown(),
|
|
12
|
+
/**
|
|
13
|
+
* Client read high-water: the largest commit/snapshot ts the client has
|
|
14
|
+
* already observed (from a prior mutation's commitTs or a query's returned
|
|
15
|
+
* `ts`). Decimal string (bigint on the wire). The server routes a query's
|
|
16
|
+
* reads to the replica ONLY when the replica has applied at least this ts —
|
|
17
|
+
* giving read-your-writes + monotonic reads without a signed token. Omitted
|
|
18
|
+
* until the client has observed anything. The server clamps it to its own
|
|
19
|
+
* primary latest, so a client can't pin the primary forever with a bogus value.
|
|
20
|
+
*/
|
|
21
|
+
minTs: z.string().max(40).optional(),
|
|
22
|
+
/**
|
|
23
|
+
* W3C `traceparent` for distributed tracing. When the client is running
|
|
24
|
+
* OpenTelemetry it injects the active context here; the server continues the
|
|
25
|
+
* trace so the operation span is a child of the client's. Ignored when tracing
|
|
26
|
+
* isn't enabled server-side. Optional and unauthenticated — purely diagnostic.
|
|
27
|
+
*
|
|
28
|
+
* Bounded: a valid W3C `traceparent` is 55 chars; the cap keeps an
|
|
29
|
+
* unauthenticated field from being used to ship a large blob into
|
|
30
|
+
* `propagation.extract`.
|
|
31
|
+
*/
|
|
32
|
+
trace: z.string().max(256).optional()
|
|
33
|
+
});
|
|
34
|
+
const SubscribeMessageSchema = z.object({
|
|
35
|
+
type: z.literal("subscribe"),
|
|
36
|
+
id: z.string().max(128),
|
|
37
|
+
procedure: z.string().max(256),
|
|
38
|
+
input: z.unknown(),
|
|
39
|
+
/** W3C `traceparent` (bounded); see {@link CallMessageSchema}. */
|
|
40
|
+
trace: z.string().max(256).optional()
|
|
41
|
+
});
|
|
42
|
+
const UnsubscribeMessageSchema = z.object({
|
|
43
|
+
type: z.literal("unsubscribe"),
|
|
44
|
+
subId: z.string()
|
|
45
|
+
});
|
|
46
|
+
const ClientMessageSchema = z.union([
|
|
47
|
+
AuthMessageSchema,
|
|
48
|
+
CallMessageSchema,
|
|
49
|
+
SubscribeMessageSchema,
|
|
50
|
+
UnsubscribeMessageSchema
|
|
51
|
+
]);
|
|
52
|
+
const ConnectedMessageSchema = z.object({
|
|
53
|
+
type: z.literal("connected"),
|
|
54
|
+
sessionId: z.string()
|
|
55
|
+
});
|
|
56
|
+
const AuthSuccessMessageSchema = z.object({
|
|
57
|
+
type: z.literal("auth:success"),
|
|
58
|
+
userId: z.string(),
|
|
59
|
+
extra: z.object().optional()
|
|
60
|
+
});
|
|
61
|
+
const AuthFailedMessageSchema = z.object({
|
|
62
|
+
type: z.literal("auth:failed"),
|
|
63
|
+
message: z.string(),
|
|
64
|
+
extra: z.record(z.string(), z.unknown()).optional()
|
|
65
|
+
});
|
|
66
|
+
const ResponseMessageSchema = z.object({
|
|
67
|
+
type: z.literal("response"),
|
|
68
|
+
id: z.string(),
|
|
69
|
+
success: z.boolean(),
|
|
70
|
+
data: z.unknown().optional(),
|
|
71
|
+
error: z.string().optional(),
|
|
72
|
+
code: z.string().optional(),
|
|
73
|
+
/**
|
|
74
|
+
* Populated by the server only for a successful `subscribe` response.
|
|
75
|
+
* Carries the canonical, server-computed subscription id so the client
|
|
76
|
+
* can route subsequent `sub:update` / `sub:gone` messages without
|
|
77
|
+
* recomputing the hash locally (which would require the wasm runtime
|
|
78
|
+
* and would not reflect server-side per-procedure `queryIdentity`
|
|
79
|
+
* overrides).
|
|
80
|
+
*/
|
|
81
|
+
subId: z.string().optional(),
|
|
82
|
+
/**
|
|
83
|
+
* Observed commit/snapshot ts for a successful `call`. Decimal string
|
|
84
|
+
* (bigint on the wire). For a query it's the snapshot the reads ran at; for a
|
|
85
|
+
* mutation it's the commitTs. The client folds it into its read high-water
|
|
86
|
+
* (see {@link CallMessageSchema.minTs}) so later reads preserve
|
|
87
|
+
* read-your-writes / monotonic reads. Absent for actions and error responses.
|
|
88
|
+
*/
|
|
89
|
+
ts: z.string().optional()
|
|
90
|
+
});
|
|
91
|
+
const SubscriptionUpdateMessageSchema = z.object({
|
|
92
|
+
type: z.literal("sub:update"),
|
|
93
|
+
subId: z.string(),
|
|
94
|
+
data: z.unknown(),
|
|
95
|
+
dataHash: z.string().optional(),
|
|
96
|
+
/**
|
|
97
|
+
* The primary snapshot ts this update's data reflects. Decimal string (bigint
|
|
98
|
+
* on the wire). The client folds it into its read high-water so a later
|
|
99
|
+
* one-shot query can't route to a replica that is behind what the live view
|
|
100
|
+
* already showed (cross-subscription monotonic reads). Present on server-side
|
|
101
|
+
* recomputes; omitted when the update is served straight from cache (no ts
|
|
102
|
+
* handy) — the client simply doesn't advance for those.
|
|
103
|
+
*/
|
|
104
|
+
ts: z.string().optional()
|
|
105
|
+
});
|
|
106
|
+
/**
|
|
107
|
+
* Notifies a client that a subscription is no longer tracked on the server
|
|
108
|
+
* and will not receive further updates. Sent when, during a sub-manager
|
|
109
|
+
* recovery cycle, the registration record could not be found (e.g. another
|
|
110
|
+
* app-server instance fully unregistered the sub while we were disconnected).
|
|
111
|
+
* The client may choose to re-subscribe or surface the state to the user.
|
|
112
|
+
*/
|
|
113
|
+
const SubscriptionGoneMessageSchema = z.object({
|
|
114
|
+
type: z.literal("sub:gone"),
|
|
115
|
+
subId: z.string(),
|
|
116
|
+
reason: z.string().optional()
|
|
117
|
+
});
|
|
118
|
+
/**
|
|
119
|
+
* Server-driven liveness signal. Sent when the channel has been idle for
|
|
120
|
+
* the configured app-ping interval (default 15s) and again after every
|
|
121
|
+
* outbound message. Pure no-op for the client: receiving any message
|
|
122
|
+
* (including this one) resets the client's inactivity watchdog. The client
|
|
123
|
+
* does NOT reply.
|
|
124
|
+
*/
|
|
125
|
+
const ServerPingMessageSchema = z.object({ type: z.literal("ping") });
|
|
126
|
+
/**
|
|
127
|
+
* A build/version tag the server stamps on EVERY outbound message, whatever the
|
|
128
|
+
* `type` (see {@link SupaliveServerConfig.buildNumber}). It rides the union as a
|
|
129
|
+
* shared optional field so a client gets the same "which build is the server on"
|
|
130
|
+
* signal over the WebSocket that the HTTP RPC transport gets from the
|
|
131
|
+
* `x-app-build` response header — one consistent lookup across transports,
|
|
132
|
+
* without changing any per-message behavior. Omitted when the server has no
|
|
133
|
+
* build number configured (e.g. local dev).
|
|
134
|
+
*/
|
|
135
|
+
const ServerMessageMetaSchema = z.object({ build: z.number().int().nonnegative().optional() });
|
|
136
|
+
const ServerMessageSchema = z.union([
|
|
137
|
+
ConnectedMessageSchema,
|
|
138
|
+
AuthSuccessMessageSchema,
|
|
139
|
+
AuthFailedMessageSchema,
|
|
140
|
+
ResponseMessageSchema,
|
|
141
|
+
SubscriptionUpdateMessageSchema,
|
|
142
|
+
SubscriptionGoneMessageSchema,
|
|
143
|
+
ServerPingMessageSchema
|
|
144
|
+
]).and(ServerMessageMetaSchema);
|
|
145
|
+
var AuthenticationError = class extends Error {
|
|
146
|
+
extra;
|
|
147
|
+
constructor(message, extra = {}) {
|
|
148
|
+
super(message);
|
|
149
|
+
this.extra = extra;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
//#endregion
|
|
153
|
+
export { CallMessageSchema as a, ResponseMessageSchema as c, SubscribeMessageSchema as d, SubscriptionGoneMessageSchema as f, AuthenticationError as i, ServerMessageSchema as l, UnsubscribeMessageSchema as m, AuthMessageSchema as n, ClientMessageSchema as o, SubscriptionUpdateMessageSchema as p, AuthSuccessMessageSchema as r, ConnectedMessageSchema as s, AuthFailedMessageSchema as t, ServerPingMessageSchema as u };
|
|
154
|
+
|
|
155
|
+
//# sourceMappingURL=types_client_rpc-BRCAgeyJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types_client_rpc-BRCAgeyJ.js","names":[],"sources":["../src/db/types_client_rpc.ts"],"sourcesContent":["import z from \"zod\";\n\nexport interface ErrorMessage {\n type: \"error\";\n id?: string;\n error: string;\n code?: string;\n}\n\n// ─── WebSocket Message Schemas ────────────────────────────────────────────────\n// Zod schemas for runtime validation of WebSocket messages\n\nexport const AuthMessageSchema = z.object({\n type: z.literal(\"auth\"),\n data: z.record(z.string(), z.any()).optional(),\n});\n\nexport const CallMessageSchema = z.object({\n type: z.literal(\"call\"),\n // Bounded so a client can't push oversized correlation ids / procedure names\n // through the 100MB WS frame limit and burn CPU/memory before the procedure\n // lookup even runs. A request id is a short client token; a procedure name is\n // a symbol.\n id: z.string().max(128),\n procedure: z.string().max(256),\n input: z.unknown(),\n /**\n * Client read high-water: the largest commit/snapshot ts the client has\n * already observed (from a prior mutation's commitTs or a query's returned\n * `ts`). Decimal string (bigint on the wire). The server routes a query's\n * reads to the replica ONLY when the replica has applied at least this ts —\n * giving read-your-writes + monotonic reads without a signed token. Omitted\n * until the client has observed anything. The server clamps it to its own\n * primary latest, so a client can't pin the primary forever with a bogus value.\n */\n minTs: z.string().max(40).optional(),\n /**\n * W3C `traceparent` for distributed tracing. When the client is running\n * OpenTelemetry it injects the active context here; the server continues the\n * trace so the operation span is a child of the client's. Ignored when tracing\n * isn't enabled server-side. Optional and unauthenticated — purely diagnostic.\n *\n * Bounded: a valid W3C `traceparent` is 55 chars; the cap keeps an\n * unauthenticated field from being used to ship a large blob into\n * `propagation.extract`.\n */\n trace: z.string().max(256).optional(),\n});\n\nexport const SubscribeMessageSchema = z.object({\n type: z.literal(\"subscribe\"),\n id: z.string().max(128),\n procedure: z.string().max(256),\n input: z.unknown(),\n /** W3C `traceparent` (bounded); see {@link CallMessageSchema}. */\n trace: z.string().max(256).optional(),\n});\n\nexport const UnsubscribeMessageSchema = z.object({\n type: z.literal(\"unsubscribe\"),\n subId: z.string(),\n});\n\nexport const ClientMessageSchema = z.union([\n AuthMessageSchema,\n CallMessageSchema,\n SubscribeMessageSchema,\n UnsubscribeMessageSchema,\n]);\n\n// Infer TypeScript types from schemas\nexport type AuthMessage = z.infer<typeof AuthMessageSchema>;\nexport type CallMessage = z.infer<typeof CallMessageSchema>;\nexport type SubscribeMessage = z.infer<typeof SubscribeMessageSchema>;\nexport type UnsubscribeMessage = z.infer<typeof UnsubscribeMessageSchema>;\nexport type ClientMessage = z.infer<typeof ClientMessageSchema>;\n\n// ─── Server Message Schemas ───────────────────────────────────────────────────\n\nexport const ConnectedMessageSchema = z.object({\n type: z.literal(\"connected\"),\n sessionId: z.string(),\n});\n\nexport const AuthSuccessMessageSchema = z.object({\n type: z.literal(\"auth:success\"),\n userId: z.string(),\n extra: z.object().optional()\n});\n\nexport const AuthFailedMessageSchema = z.object({\n type: z.literal(\"auth:failed\"),\n message: z.string(),\n extra: z.record(z.string(), z.unknown()).optional()\n});\n\nexport const ResponseMessageSchema = z.object({\n type: z.literal(\"response\"),\n id: z.string(),\n success: z.boolean(),\n data: z.unknown().optional(),\n error: z.string().optional(),\n code: z.string().optional(),\n /**\n * Populated by the server only for a successful `subscribe` response.\n * Carries the canonical, server-computed subscription id so the client\n * can route subsequent `sub:update` / `sub:gone` messages without\n * recomputing the hash locally (which would require the wasm runtime\n * and would not reflect server-side per-procedure `queryIdentity`\n * overrides).\n */\n subId: z.string().optional(),\n /**\n * Observed commit/snapshot ts for a successful `call`. Decimal string\n * (bigint on the wire). For a query it's the snapshot the reads ran at; for a\n * mutation it's the commitTs. The client folds it into its read high-water\n * (see {@link CallMessageSchema.minTs}) so later reads preserve\n * read-your-writes / monotonic reads. Absent for actions and error responses.\n */\n ts: z.string().optional(),\n});\n\nexport const SubscriptionUpdateMessageSchema = z.object({\n type: z.literal(\"sub:update\"),\n subId: z.string(),\n data: z.unknown(),\n dataHash: z.string().optional(),\n /**\n * The primary snapshot ts this update's data reflects. Decimal string (bigint\n * on the wire). The client folds it into its read high-water so a later\n * one-shot query can't route to a replica that is behind what the live view\n * already showed (cross-subscription monotonic reads). Present on server-side\n * recomputes; omitted when the update is served straight from cache (no ts\n * handy) — the client simply doesn't advance for those.\n */\n ts: z.string().optional(),\n});\n\n/**\n * Notifies a client that a subscription is no longer tracked on the server\n * and will not receive further updates. Sent when, during a sub-manager\n * recovery cycle, the registration record could not be found (e.g. another\n * app-server instance fully unregistered the sub while we were disconnected).\n * The client may choose to re-subscribe or surface the state to the user.\n */\nexport const SubscriptionGoneMessageSchema = z.object({\n type: z.literal(\"sub:gone\"),\n subId: z.string(),\n reason: z.string().optional(),\n});\n\n/**\n * Server-driven liveness signal. Sent when the channel has been idle for\n * the configured app-ping interval (default 15s) and again after every\n * outbound message. Pure no-op for the client: receiving any message\n * (including this one) resets the client's inactivity watchdog. The client\n * does NOT reply.\n */\nexport const ServerPingMessageSchema = z.object({\n type: z.literal(\"ping\"),\n});\n\n/**\n * A build/version tag the server stamps on EVERY outbound message, whatever the\n * `type` (see {@link SupaliveServerConfig.buildNumber}). It rides the union as a\n * shared optional field so a client gets the same \"which build is the server on\"\n * signal over the WebSocket that the HTTP RPC transport gets from the\n * `x-app-build` response header — one consistent lookup across transports,\n * without changing any per-message behavior. Omitted when the server has no\n * build number configured (e.g. local dev).\n */\nconst ServerMessageMetaSchema = z.object({\n build: z.number().int().nonnegative().optional(),\n});\n\nexport const ServerMessageSchema = z\n .union([\n ConnectedMessageSchema,\n AuthSuccessMessageSchema,\n AuthFailedMessageSchema,\n ResponseMessageSchema,\n SubscriptionUpdateMessageSchema,\n SubscriptionGoneMessageSchema,\n ServerPingMessageSchema,\n ])\n .and(ServerMessageMetaSchema);\n\nexport type ConnectedMessage = z.infer<typeof ConnectedMessageSchema>;\nexport type AuthSuccessMessage = z.infer<typeof AuthSuccessMessageSchema>;\nexport type AuthFailedMessage = z.infer<typeof AuthFailedMessageSchema>;\nexport type ResponseMessage = z.infer<typeof ResponseMessageSchema>;\nexport type SubscriptionUpdateMessage = z.infer<typeof SubscriptionUpdateMessageSchema>;\nexport type SubscriptionGoneMessage = z.infer<typeof SubscriptionGoneMessageSchema>;\nexport type ServerPingMessage = z.infer<typeof ServerPingMessageSchema>;\nexport type ServerMessage = z.infer<typeof ServerMessageSchema>;\n\nexport class AuthenticationError extends Error {\n constructor(\n message: string,\n public extra: Record<string, unknown> = {},\n ) {\n super(message);\n }\n}\n\n/**\n * Helper type to check if a procedure is internal.\n */\nexport type IsInternal<T> = T extends { internal: infer I } ? (I extends true ? true : false) : false;\n\nexport interface Context {\n requestId: string;\n /** Authenticated user info */\n user: {\n userId: string;\n };\n}\n"],"mappings":";;AAYA,MAAa,oBAAoB,EAAE,OAAO;CACxC,MAAM,EAAE,QAAQ,MAAM;CACtB,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS;AAC/C,CAAC;AAED,MAAa,oBAAoB,EAAE,OAAO;CACxC,MAAM,EAAE,QAAQ,MAAM;CAKtB,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG;CACtB,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG;CAC7B,OAAO,EAAE,QAAQ;;;;;;;;;;CAUjB,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS;;;;;;;;;;;CAWnC,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS;AACtC,CAAC;AAED,MAAa,yBAAyB,EAAE,OAAO;CAC7C,MAAM,EAAE,QAAQ,WAAW;CAC3B,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG;CACtB,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG;CAC7B,OAAO,EAAE,QAAQ;;CAEjB,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS;AACtC,CAAC;AAED,MAAa,2BAA2B,EAAE,OAAO;CAC/C,MAAM,EAAE,QAAQ,aAAa;CAC7B,OAAO,EAAE,OAAO;AAClB,CAAC;AAED,MAAa,sBAAsB,EAAE,MAAM;CACzC;CACA;CACA;CACA;AACF,CAAC;AAWD,MAAa,yBAAyB,EAAE,OAAO;CAC7C,MAAM,EAAE,QAAQ,WAAW;CAC3B,WAAW,EAAE,OAAO;AACtB,CAAC;AAED,MAAa,2BAA2B,EAAE,OAAO;CAC/C,MAAM,EAAE,QAAQ,cAAc;CAC9B,QA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