@rocicorp/zero 1.4.0-canary.6 → 1.5.0-canary.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/out/zero/package.js +1 -1
- package/out/zero/package.js.map +1 -1
- package/out/zero-cache/src/auth/auth.d.ts +1 -1
- package/out/zero-cache/src/auth/auth.d.ts.map +1 -1
- package/out/zero-cache/src/auth/auth.js +1 -1
- package/out/zero-cache/src/auth/auth.js.map +1 -1
- package/out/zero-cache/src/auth/write-authorizer.d.ts +1 -1
- package/out/zero-cache/src/auth/write-authorizer.d.ts.map +1 -1
- package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
- package/out/zero-cache/src/config/normalize.d.ts.map +1 -1
- package/out/zero-cache/src/config/normalize.js +8 -0
- package/out/zero-cache/src/config/normalize.js.map +1 -1
- package/out/zero-cache/src/config/zero-config.d.ts +8 -4
- package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
- package/out/zero-cache/src/config/zero-config.js +28 -6
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/custom/fetch.d.ts +1 -1
- package/out/zero-cache/src/custom/fetch.d.ts.map +1 -1
- package/out/zero-cache/src/custom/fetch.js +2 -2
- package/out/zero-cache/src/custom/fetch.js.map +1 -1
- package/out/zero-cache/src/custom-queries/transform-query.d.ts +21 -7
- package/out/zero-cache/src/custom-queries/transform-query.d.ts.map +1 -1
- package/out/zero-cache/src/custom-queries/transform-query.js +26 -9
- package/out/zero-cache/src/custom-queries/transform-query.js.map +1 -1
- package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
- package/out/zero-cache/src/server/change-streamer.js +2 -1
- package/out/zero-cache/src/server/change-streamer.js.map +1 -1
- package/out/zero-cache/src/server/runner/run-worker.d.ts.map +1 -1
- package/out/zero-cache/src/server/runner/run-worker.js +5 -2
- package/out/zero-cache/src/server/runner/run-worker.js.map +1 -1
- package/out/zero-cache/src/server/syncer.js +3 -3
- package/out/zero-cache/src/server/syncer.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/change-source.js +24 -20
- package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts +258 -45
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.js +119 -83
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/init.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/init.js +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/shard.js +2 -1
- package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts +1 -0
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
- package/out/zero-cache/src/services/http-service.d.ts +1 -0
- package/out/zero-cache/src/services/http-service.d.ts.map +1 -1
- package/out/zero-cache/src/services/http-service.js +5 -4
- package/out/zero-cache/src/services/http-service.js.map +1 -1
- package/out/zero-cache/src/services/life-cycle.d.ts +1 -1
- package/out/zero-cache/src/services/life-cycle.d.ts.map +1 -1
- package/out/zero-cache/src/services/life-cycle.js +1 -2
- package/out/zero-cache/src/services/life-cycle.js.map +1 -1
- package/out/zero-cache/src/services/mutagen/mutagen.d.ts +1 -1
- package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
- package/out/zero-cache/src/services/mutagen/mutagen.js +1 -1
- package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
- package/out/zero-cache/src/services/mutagen/pusher.d.ts +4 -3
- package/out/zero-cache/src/services/mutagen/pusher.d.ts.map +1 -1
- package/out/zero-cache/src/services/mutagen/pusher.js +57 -38
- package/out/zero-cache/src/services/mutagen/pusher.js.map +1 -1
- package/out/zero-cache/src/services/shadow-sync/shadow-sync-service.js +2 -1
- package/out/zero-cache/src/services/shadow-sync/shadow-sync-service.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/client-handler.js +1 -1
- package/out/zero-cache/src/services/view-syncer/client-handler.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/connection-context-manager.d.ts +39 -27
- package/out/zero-cache/src/services/view-syncer/connection-context-manager.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/connection-context-manager.js +138 -102
- package/out/zero-cache/src/services/view-syncer/connection-context-manager.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.d.ts +6 -0
- package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.js +8 -0
- package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +3 -3
- package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.js +115 -86
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-cache/src/workers/syncer-ws-message-handler.d.ts +1 -1
- package/out/zero-cache/src/workers/syncer-ws-message-handler.d.ts.map +1 -1
- package/out/zero-cache/src/workers/syncer-ws-message-handler.js +7 -7
- package/out/zero-cache/src/workers/syncer-ws-message-handler.js.map +1 -1
- package/out/zero-cache/src/workers/syncer.d.ts +1 -1
- package/out/zero-cache/src/workers/syncer.d.ts.map +1 -1
- package/out/zero-cache/src/workers/syncer.js +11 -10
- package/out/zero-cache/src/workers/syncer.js.map +1 -1
- package/out/zero-client/src/client/connection.d.ts +15 -7
- package/out/zero-client/src/client/connection.d.ts.map +1 -1
- package/out/zero-client/src/client/connection.js.map +1 -1
- package/out/zero-client/src/client/crud-impl.d.ts +1 -1
- package/out/zero-client/src/client/crud-impl.d.ts.map +1 -1
- package/out/zero-client/src/client/crud-impl.js +1 -1
- package/out/zero-client/src/client/crud-impl.js.map +1 -1
- package/out/zero-client/src/client/crud.d.ts +1 -1
- package/out/zero-client/src/client/crud.d.ts.map +1 -1
- package/out/zero-client/src/client/crud.js +1 -1
- package/out/zero-client/src/client/crud.js.map +1 -1
- package/out/zero-client/src/client/keys.d.ts +1 -1
- package/out/zero-client/src/client/keys.d.ts.map +1 -1
- package/out/zero-client/src/client/keys.js.map +1 -1
- package/out/zero-client/src/client/make-replicache-mutators.js +1 -1
- package/out/zero-client/src/client/make-replicache-mutators.js.map +1 -1
- package/out/zero-client/src/client/mutation-tracker.d.ts +2 -1
- package/out/zero-client/src/client/mutation-tracker.d.ts.map +1 -1
- package/out/zero-client/src/client/mutation-tracker.js +3 -3
- package/out/zero-client/src/client/mutation-tracker.js.map +1 -1
- package/out/zero-client/src/client/version.js +1 -1
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.js +2 -2
- package/out/zero-client/src/client/zero.js.map +1 -1
- package/out/zero-client/src/types/client-state.d.ts +1 -1
- package/out/zero-client/src/types/client-state.d.ts.map +1 -1
- package/out/zero-protocol/src/custom-queries.js +1 -1
- package/out/zero-protocol/src/down.js +1 -1
- package/out/zero-protocol/src/error-kind-enum.d.ts +1 -2
- package/out/zero-protocol/src/error-kind-enum.d.ts.map +1 -1
- package/out/zero-protocol/src/error-kind-enum.js.map +1 -1
- package/out/zero-protocol/src/mutate-server.d.ts +165 -0
- package/out/zero-protocol/src/mutate-server.d.ts.map +1 -0
- package/out/zero-protocol/src/mutate-server.js +24 -0
- package/out/zero-protocol/src/mutate-server.js.map +1 -0
- package/out/zero-protocol/src/mutation.d.ts +229 -0
- package/out/zero-protocol/src/mutation.d.ts.map +1 -0
- package/out/zero-protocol/src/mutation.js +112 -0
- package/out/zero-protocol/src/mutation.js.map +1 -0
- package/out/zero-protocol/src/mutations-patch.js +1 -1
- package/out/zero-protocol/src/mutations-patch.js.map +1 -1
- package/out/zero-protocol/src/push.d.ts +3 -234
- package/out/zero-protocol/src/push.d.ts.map +1 -1
- package/out/zero-protocol/src/push.js +3 -114
- package/out/zero-protocol/src/push.js.map +1 -1
- package/out/zero-protocol/src/query-server.d.ts +150 -0
- package/out/zero-protocol/src/query-server.d.ts.map +1 -0
- package/out/zero-protocol/src/query-server.js +16 -0
- package/out/zero-protocol/src/query-server.js.map +1 -0
- package/out/zero-protocol/src/up.js +1 -1
- package/out/zero-server/src/mod.d.ts +4 -2
- package/out/zero-server/src/mod.d.ts.map +1 -1
- package/out/zero-server/src/process-mutations.d.ts +41 -4
- package/out/zero-server/src/process-mutations.d.ts.map +1 -1
- package/out/zero-server/src/process-mutations.js +52 -35
- package/out/zero-server/src/process-mutations.js.map +1 -1
- package/out/zero-server/src/push-processor.d.ts +3 -3
- package/out/zero-server/src/push-processor.d.ts.map +1 -1
- package/out/zero-server/src/push-processor.js.map +1 -1
- package/out/zero-server/src/queries/process-queries.d.ts +22 -52
- package/out/zero-server/src/queries/process-queries.d.ts.map +1 -1
- package/out/zero-server/src/queries/process-queries.js +50 -49
- package/out/zero-server/src/queries/process-queries.js.map +1 -1
- package/out/zero-server/src/zql-database.js.map +1 -1
- package/out/zero-types/src/default-types.d.ts +1 -0
- package/out/zero-types/src/default-types.d.ts.map +1 -1
- package/out/zql/src/builder/builder.d.ts.map +1 -1
- package/out/zql/src/builder/builder.js +17 -7
- package/out/zql/src/builder/builder.js.map +1 -1
- package/out/zql/src/ivm/cap.d.ts +32 -0
- package/out/zql/src/ivm/cap.d.ts.map +1 -0
- package/out/zql/src/ivm/cap.js +205 -0
- package/out/zql/src/ivm/cap.js.map +1 -0
- package/out/zql/src/ivm/constraint.js +1 -1
- package/out/zql/src/ivm/flipped-join.d.ts.map +1 -1
- package/out/zql/src/ivm/flipped-join.js +61 -15
- package/out/zql/src/ivm/flipped-join.js.map +1 -1
- package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
- package/out/zql/src/ivm/memory-source.js +3 -4
- package/out/zql/src/ivm/memory-source.js.map +1 -1
- package/out/zql/src/ivm/schema.d.ts +8 -0
- package/out/zql/src/ivm/schema.d.ts.map +1 -1
- package/out/zql/src/ivm/take.js +2 -2
- package/out/zql/src/mutate/mutator-registry.js.map +1 -1
- package/out/zql/src/mutate/mutator.d.ts +11 -2
- package/out/zql/src/mutate/mutator.d.ts.map +1 -1
- package/out/zql/src/mutate/mutator.js.map +1 -1
- package/out/zql/src/query/query-registry.d.ts +9 -2
- package/out/zql/src/query/query-registry.d.ts.map +1 -1
- package/out/zql/src/query/query-registry.js.map +1 -1
- package/out/zqlite/src/table-source.d.ts.map +1 -1
- package/out/zqlite/src/table-source.js +4 -1
- package/out/zqlite/src/table-source.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,24 @@ import { type Auth, type ValidateLegacyJWT } from '../../auth/auth.ts';
|
|
|
5
5
|
import type { ZeroConfig } from '../../config/zero-config.ts';
|
|
6
6
|
import type { ConnectParams } from '../../workers/connect-params.ts';
|
|
7
7
|
export type ConnectionState = 'provisional' | 'validated';
|
|
8
|
+
/**
|
|
9
|
+
* Normalized user identity shared by live connection state and group auth state.
|
|
10
|
+
* `id: null` means logged out.
|
|
11
|
+
*/
|
|
12
|
+
export type UserState = {
|
|
13
|
+
readonly id: string | null;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Delineates the two paths for validating a connection: either server can validate
|
|
17
|
+
* the user's identity and return a definitive userID to trust, or we fall back to
|
|
18
|
+
* trusting the one provided by the client in the incoming query params.
|
|
19
|
+
*/
|
|
20
|
+
export type ConnectionValidation = {
|
|
21
|
+
kind: 'client-fallback';
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'server-validated';
|
|
24
|
+
validatedUserID: string | null;
|
|
25
|
+
};
|
|
8
26
|
/**
|
|
9
27
|
* Identifies one live websocket for a client slot.
|
|
10
28
|
*/
|
|
@@ -14,16 +32,16 @@ export type ConnectionSelector = {
|
|
|
14
32
|
};
|
|
15
33
|
type FetchConfig = ZeroConfig['query'];
|
|
16
34
|
export type HeaderOptions = {
|
|
17
|
-
apiKey?: string | undefined;
|
|
18
|
-
customHeaders?: Record<string, string
|
|
19
|
-
allowedClientHeaders?: readonly string[] | undefined;
|
|
20
|
-
cookie?: string | undefined;
|
|
21
|
-
origin?: string | undefined;
|
|
35
|
+
readonly apiKey?: string | undefined;
|
|
36
|
+
readonly customHeaders?: Readonly<Record<string, string>> | undefined;
|
|
37
|
+
readonly allowedClientHeaders?: readonly string[] | undefined;
|
|
38
|
+
readonly cookie?: string | undefined;
|
|
39
|
+
readonly origin?: string | undefined;
|
|
22
40
|
};
|
|
23
41
|
export type ConnectionFetchContext = {
|
|
24
|
-
url: string | undefined;
|
|
25
|
-
allowedUrlPatterns: URLPattern[] | undefined;
|
|
26
|
-
headerOptions: HeaderOptions;
|
|
42
|
+
readonly url: string | undefined;
|
|
43
|
+
readonly allowedUrlPatterns: readonly URLPattern[] | undefined;
|
|
44
|
+
readonly headerOptions: HeaderOptions;
|
|
27
45
|
};
|
|
28
46
|
/**
|
|
29
47
|
* A snapshot of one live connection tracked by the manager.
|
|
@@ -31,19 +49,19 @@ export type ConnectionFetchContext = {
|
|
|
31
49
|
* `revalidateAt` is only populated while the connection is `validated`.
|
|
32
50
|
*/
|
|
33
51
|
export type ConnectionContext = {
|
|
34
|
-
state: ConnectionState;
|
|
52
|
+
readonly state: ConnectionState;
|
|
35
53
|
readonly clientID: string;
|
|
36
54
|
readonly wsID: string;
|
|
37
|
-
readonly
|
|
38
|
-
auth: Auth | undefined;
|
|
55
|
+
readonly user: UserState;
|
|
56
|
+
readonly auth: Auth | undefined;
|
|
39
57
|
readonly profileID: string | null;
|
|
40
58
|
readonly baseCookie: string | null;
|
|
41
59
|
readonly protocolVersion: number;
|
|
42
|
-
revision: number;
|
|
43
|
-
revalidateAt: number | undefined;
|
|
60
|
+
readonly revision: number;
|
|
61
|
+
readonly revalidateAt: number | undefined;
|
|
44
62
|
readonly insertionOrder: number;
|
|
45
63
|
readonly queryContext: ConnectionFetchContext;
|
|
46
|
-
readonly
|
|
64
|
+
readonly mutateContext: ConnectionFetchContext;
|
|
47
65
|
};
|
|
48
66
|
/**
|
|
49
67
|
* Group-scoped auth state shared across the live connections.
|
|
@@ -51,22 +69,18 @@ export type ConnectionContext = {
|
|
|
51
69
|
* The background connection is the validated connection currently used for
|
|
52
70
|
* shared background work. Retransform happens on a group level, and uses
|
|
53
71
|
* the background connection's credential to refetch the latest queries.
|
|
54
|
-
*
|
|
55
|
-
* Since auth can be pinned to logged-out users, `userID` can be undefined
|
|
56
|
-
* even after validation.
|
|
57
72
|
*/
|
|
58
73
|
export type GroupAuthState = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
maintenanceNotBeforeAt: number | undefined;
|
|
74
|
+
readonly pinnedUser: UserState | undefined;
|
|
75
|
+
readonly backgroundConnection: ConnectionSelector | undefined;
|
|
76
|
+
readonly retransformAt: number | undefined;
|
|
77
|
+
readonly maintenanceNotBeforeAt: number | undefined;
|
|
64
78
|
};
|
|
65
79
|
export type ConnectionContextManager = {
|
|
66
80
|
registerConnection(selector: ConnectionSelector, connectParams: ConnectParams, auth?: Auth): Readonly<ConnectionContext>;
|
|
67
81
|
initConnection(selector: ConnectionSelector, body: InitConnectionBody): Readonly<ConnectionContext>;
|
|
68
82
|
updateAuth(selector: ConnectionSelector, body: UpdateAuthBody): Promise<Readonly<ConnectionContext>>;
|
|
69
|
-
validateConnection(selector: ConnectionSelector, revision: number): Readonly<{
|
|
83
|
+
validateConnection(selector: ConnectionSelector, revision: number, validation: ConnectionValidation): Readonly<{
|
|
70
84
|
connection: ConnectionContext;
|
|
71
85
|
group: GroupAuthState;
|
|
72
86
|
}> | undefined;
|
|
@@ -90,10 +104,8 @@ export type ConnectionContextManager = {
|
|
|
90
104
|
*
|
|
91
105
|
* Connections are registered as `provisional`, optionally backfilled with
|
|
92
106
|
* `initConnection` metadata, and then promoted to `validated` once their
|
|
93
|
-
*
|
|
107
|
+
* effective `userID` is confirmed as valid. The manager also tracks which
|
|
94
108
|
* validated connection currently serves as the group's background connection.
|
|
95
|
-
*
|
|
96
|
-
* This is intentionally side-effect free.
|
|
97
109
|
*/
|
|
98
110
|
export declare class ConnectionContextManagerImpl implements ConnectionContextManager {
|
|
99
111
|
#private;
|
|
@@ -126,7 +138,7 @@ export declare class ConnectionContextManagerImpl implements ConnectionContextMa
|
|
|
126
138
|
* background connection if none is currently available. If the websocket is
|
|
127
139
|
* gone by the time async validation finishes, this becomes a no-op.
|
|
128
140
|
*/
|
|
129
|
-
validateConnection(selector: ConnectionSelector, revision: number): Readonly<{
|
|
141
|
+
validateConnection(selector: ConnectionSelector, revision: number, validation: ConnectionValidation): Readonly<{
|
|
130
142
|
connection: ConnectionContext;
|
|
131
143
|
group: GroupAuthState;
|
|
132
144
|
}> | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-context-manager.d.ts","sourceRoot":"","sources":["../../../../../../zero-cache/src/services/view-syncer/connection-context-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,0CAA0C,CAAC;AAGjF,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,8CAA8C,CAAC;AACjF,OAAO,EAGL,KAAK,IAAI,EACT,KAAK,iBAAiB,EACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,6BAA6B,CAAC;AAG5D,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,iCAAiC,CAAC;AAEnE,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG,WAAW,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;AAEvC,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"connection-context-manager.d.ts","sourceRoot":"","sources":["../../../../../../zero-cache/src/services/view-syncer/connection-context-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,0CAA0C,CAAC;AAGjF,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,8CAA8C,CAAC;AACjF,OAAO,EAGL,KAAK,IAAI,EACT,KAAK,iBAAiB,EACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,6BAA6B,CAAC;AAG5D,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,iCAAiC,CAAC;AAEnE,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG,WAAW,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;CAAC,CAAC;AAErD;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAC5B;IAAC,IAAI,EAAE,iBAAiB,CAAA;CAAC,GACzB;IAAC,IAAI,EAAE,kBAAkB,CAAC;IAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;CAAC,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;A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;QACxB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;KACxC;CA0PF"}
|
|
@@ -9,20 +9,17 @@ import { authEquals, resolveAuth } from "../../auth/auth.js";
|
|
|
9
9
|
*
|
|
10
10
|
* Connections are registered as `provisional`, optionally backfilled with
|
|
11
11
|
* `initConnection` metadata, and then promoted to `validated` once their
|
|
12
|
-
*
|
|
12
|
+
* effective `userID` is confirmed as valid. The manager also tracks which
|
|
13
13
|
* validated connection currently serves as the group's background connection.
|
|
14
|
-
*
|
|
15
|
-
* This is intentionally side-effect free.
|
|
16
14
|
*/
|
|
17
15
|
var ConnectionContextManagerImpl = class {
|
|
18
16
|
#lc;
|
|
19
17
|
#connections = /* @__PURE__ */ new Map();
|
|
20
18
|
#group = {
|
|
21
|
-
|
|
19
|
+
pinnedUser: void 0,
|
|
22
20
|
backgroundConnection: void 0,
|
|
23
21
|
retransformAt: void 0,
|
|
24
|
-
maintenanceNotBeforeAt: void 0
|
|
25
|
-
validated: false
|
|
22
|
+
maintenanceNotBeforeAt: void 0
|
|
26
23
|
};
|
|
27
24
|
#validateLegacyJWT;
|
|
28
25
|
#now;
|
|
@@ -48,49 +45,39 @@ var ConnectionContextManagerImpl = class {
|
|
|
48
45
|
*/
|
|
49
46
|
registerConnection(selector, connectParams, auth) {
|
|
50
47
|
this.#removeConnection(selector);
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
const getContext = (type) => {
|
|
49
|
+
const config = type === "query" ? this.#queryConfig : this.#pushConfig;
|
|
50
|
+
return {
|
|
51
|
+
url: config?.url?.[0],
|
|
52
|
+
allowedUrlPatterns: config?.url?.map(compileUrlPattern),
|
|
53
|
+
headerOptions: {
|
|
54
|
+
customHeaders: void 0,
|
|
55
|
+
origin: connectParams.origin,
|
|
56
|
+
apiKey: config?.apiKey,
|
|
57
|
+
allowedClientHeaders: cloneAllowedClientHeaders(config?.allowedClientHeaders),
|
|
58
|
+
cookie: config?.forwardCookies ? connectParams.httpCookie : void 0
|
|
59
|
+
}
|
|
60
|
+
};
|
|
56
61
|
};
|
|
57
62
|
const connection = {
|
|
58
63
|
state: "provisional",
|
|
59
64
|
clientID: connectParams.clientID,
|
|
60
65
|
wsID: connectParams.wsID,
|
|
61
66
|
revision: 0,
|
|
62
|
-
|
|
67
|
+
user: { id: connectParams.userID ?? null },
|
|
63
68
|
auth,
|
|
64
69
|
profileID: connectParams.profileID,
|
|
65
70
|
baseCookie: connectParams.baseCookie,
|
|
66
71
|
protocolVersion: connectParams.protocolVersion,
|
|
67
72
|
revalidateAt: void 0,
|
|
68
|
-
queryContext:
|
|
69
|
-
|
|
70
|
-
allowedUrlPatterns: this.#queryConfig?.url?.map(compileUrlPattern),
|
|
71
|
-
headerOptions: {
|
|
72
|
-
...sharedHeaders,
|
|
73
|
-
apiKey: this.#queryConfig?.apiKey,
|
|
74
|
-
allowedClientHeaders: this.#queryConfig?.allowedClientHeaders,
|
|
75
|
-
cookie: this.#queryConfig?.forwardCookies ? connectParams.httpCookie : void 0
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
pushContext: {
|
|
79
|
-
url: this.#pushConfig?.url?.[0],
|
|
80
|
-
allowedUrlPatterns: this.#pushConfig?.url?.map(compileUrlPattern),
|
|
81
|
-
headerOptions: {
|
|
82
|
-
...sharedHeaders,
|
|
83
|
-
apiKey: this.#pushConfig?.apiKey,
|
|
84
|
-
allowedClientHeaders: this.#pushConfig?.allowedClientHeaders,
|
|
85
|
-
cookie: this.#pushConfig?.forwardCookies ? connectParams.httpCookie : void 0
|
|
86
|
-
}
|
|
87
|
-
},
|
|
73
|
+
queryContext: getContext("query"),
|
|
74
|
+
mutateContext: getContext("mutate"),
|
|
88
75
|
insertionOrder: ++this.#nextInsertionOrder
|
|
89
76
|
};
|
|
90
|
-
this.#
|
|
77
|
+
this.#storeConnection(connection);
|
|
91
78
|
this.#refreshBackgroundConnectionContext();
|
|
92
79
|
this.#updateBackgroundRetransformDeadline(false);
|
|
93
|
-
return
|
|
80
|
+
return connection;
|
|
94
81
|
}
|
|
95
82
|
/**
|
|
96
83
|
* Backfills `initConnection` data for sockets that were registered before the
|
|
@@ -100,13 +87,36 @@ var ConnectionContextManagerImpl = class {
|
|
|
100
87
|
*/
|
|
101
88
|
initConnection(selector, body) {
|
|
102
89
|
const connection = this.#mustGetConnectionContext(selector);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (body.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
90
|
+
let queryContext = connection.queryContext;
|
|
91
|
+
let mutateContext = connection.mutateContext;
|
|
92
|
+
if (body.userQueryURL) queryContext = {
|
|
93
|
+
...queryContext,
|
|
94
|
+
url: body.userQueryURL
|
|
95
|
+
};
|
|
96
|
+
if (body.userQueryHeaders) queryContext = {
|
|
97
|
+
...queryContext,
|
|
98
|
+
headerOptions: {
|
|
99
|
+
...queryContext.headerOptions,
|
|
100
|
+
customHeaders: cloneCustomHeaders(body.userQueryHeaders)
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
if (body.userPushURL) mutateContext = {
|
|
104
|
+
...mutateContext,
|
|
105
|
+
url: body.userPushURL
|
|
106
|
+
};
|
|
107
|
+
if (body.userPushHeaders) mutateContext = {
|
|
108
|
+
...mutateContext,
|
|
109
|
+
headerOptions: {
|
|
110
|
+
...mutateContext.headerOptions,
|
|
111
|
+
customHeaders: cloneCustomHeaders(body.userPushHeaders)
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
return this.#demoteConnection({
|
|
115
|
+
...connection,
|
|
116
|
+
revision: connection.revision + 1,
|
|
117
|
+
queryContext,
|
|
118
|
+
mutateContext
|
|
119
|
+
});
|
|
110
120
|
}
|
|
111
121
|
/**
|
|
112
122
|
* A material auth change demotes the connection back to provisional until it
|
|
@@ -114,14 +124,17 @@ var ConnectionContextManagerImpl = class {
|
|
|
114
124
|
*/
|
|
115
125
|
async updateAuth(selector, body) {
|
|
116
126
|
const connection = this.#mustGetConnectionContext(selector);
|
|
117
|
-
const nextAuth = await resolveAuth(this.#lc, connection.auth, connection.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
connection.revision
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return
|
|
127
|
+
const nextAuth = await resolveAuth(this.#lc, connection.auth, connection.user.id, body.auth, this.#validateLegacyJWT);
|
|
128
|
+
if (!authEquals(connection.auth, nextAuth)) return this.#demoteConnection({
|
|
129
|
+
...connection,
|
|
130
|
+
auth: nextAuth,
|
|
131
|
+
revision: connection.revision + 1
|
|
132
|
+
});
|
|
133
|
+
if (nextAuth === connection.auth) return connection;
|
|
134
|
+
return this.#storeConnection({
|
|
135
|
+
...connection,
|
|
136
|
+
auth: nextAuth
|
|
137
|
+
});
|
|
125
138
|
}
|
|
126
139
|
/**
|
|
127
140
|
* Validates one connection against the group's pinned `userID`.
|
|
@@ -132,7 +145,7 @@ var ConnectionContextManagerImpl = class {
|
|
|
132
145
|
* background connection if none is currently available. If the websocket is
|
|
133
146
|
* gone by the time async validation finishes, this becomes a no-op.
|
|
134
147
|
*/
|
|
135
|
-
validateConnection(selector, revision) {
|
|
148
|
+
validateConnection(selector, revision, validation) {
|
|
136
149
|
const connection = this.#getConnectionContext(selector);
|
|
137
150
|
if (!connection) return;
|
|
138
151
|
if (connection.revision !== revision) {
|
|
@@ -143,21 +156,34 @@ var ConnectionContextManagerImpl = class {
|
|
|
143
156
|
});
|
|
144
157
|
return;
|
|
145
158
|
}
|
|
146
|
-
|
|
159
|
+
let validatedUserState;
|
|
160
|
+
if (validation.kind === "server-validated") {
|
|
161
|
+
validatedUserState = { id: validation.validatedUserID };
|
|
162
|
+
if (connection.user.id !== validatedUserState.id) throw new ProtocolErrorWithLevel({
|
|
163
|
+
kind: Unauthorized,
|
|
164
|
+
message: "Connection userID does not match validated server userID.",
|
|
165
|
+
origin: ZeroCache
|
|
166
|
+
}, "warn");
|
|
167
|
+
}
|
|
168
|
+
const incomingUserState = validatedUserState ?? connection.user;
|
|
169
|
+
if (this.#group.pinnedUser !== void 0 && this.#group.pinnedUser.id !== incomingUserState.id) throw new ProtocolErrorWithLevel({
|
|
147
170
|
kind: Unauthorized,
|
|
148
171
|
message: "Client groups are pinned to a single userID. Connection userID does not match existing client group userID.",
|
|
149
172
|
origin: ZeroCache
|
|
150
173
|
}, "warn");
|
|
151
|
-
if (
|
|
152
|
-
this.#group
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
174
|
+
if (this.#group.pinnedUser === void 0) this.#setGroup({
|
|
175
|
+
...this.#group,
|
|
176
|
+
pinnedUser: incomingUserState
|
|
177
|
+
});
|
|
178
|
+
const validatedConnection = this.#storeConnection({
|
|
179
|
+
...connection,
|
|
180
|
+
state: "validated",
|
|
181
|
+
revalidateAt: this.#nextRevalidateAt()
|
|
182
|
+
});
|
|
183
|
+
this.#refreshBackgroundConnectionContext(validatedConnection);
|
|
158
184
|
this.#updateBackgroundRetransformDeadline(false);
|
|
159
185
|
return {
|
|
160
|
-
connection:
|
|
186
|
+
connection: validatedConnection,
|
|
161
187
|
group: this.getGroupState()
|
|
162
188
|
};
|
|
163
189
|
}
|
|
@@ -177,25 +203,28 @@ var ConnectionContextManagerImpl = class {
|
|
|
177
203
|
markBackgroundRetransformSuccess(selector, revision) {
|
|
178
204
|
const backgroundConnection = this.#getBackgroundConnectionContext();
|
|
179
205
|
if (!backgroundConnection) return;
|
|
180
|
-
if (
|
|
206
|
+
if (backgroundConnection.clientID !== selector.clientID || backgroundConnection.wsID !== selector.wsID || backgroundConnection.revision !== revision) return;
|
|
181
207
|
this.#updateBackgroundRetransformDeadline(true);
|
|
182
208
|
}
|
|
183
209
|
deferMaintenance(kind) {
|
|
184
210
|
const intervalMs = kind === "revalidate" ? this.#revalidateIntervalMs : this.#retransformIntervalMs;
|
|
185
211
|
if (intervalMs === void 0) return;
|
|
186
|
-
this.#
|
|
212
|
+
this.#setGroup({
|
|
213
|
+
...this.#group,
|
|
214
|
+
maintenanceNotBeforeAt: Math.max(this.#group.maintenanceNotBeforeAt ?? 0, this.#now() + intervalMs)
|
|
215
|
+
});
|
|
187
216
|
}
|
|
188
217
|
/** Returns the current live record for a client slot, if any. */
|
|
189
218
|
getConnectionContext(selector) {
|
|
190
|
-
return
|
|
219
|
+
return this.#getConnectionContext(selector);
|
|
191
220
|
}
|
|
192
221
|
/** Returns the live record for one websocket or throws if it is unavailable. */
|
|
193
222
|
mustGetConnectionContext(selector) {
|
|
194
|
-
return
|
|
223
|
+
return this.#mustGetConnectionContext(selector);
|
|
195
224
|
}
|
|
196
225
|
/** Returns the current background connection, if one exists. */
|
|
197
226
|
getBackgroundConnectionContext() {
|
|
198
|
-
return
|
|
227
|
+
return this.#getBackgroundConnectionContext();
|
|
199
228
|
}
|
|
200
229
|
mustGetBackgroundConnectionContext() {
|
|
201
230
|
const backgroundConnection = this.#getBackgroundConnectionContext();
|
|
@@ -208,7 +237,7 @@ var ConnectionContextManagerImpl = class {
|
|
|
208
237
|
}
|
|
209
238
|
/** Returns the shared group auth state. */
|
|
210
239
|
getGroupState() {
|
|
211
|
-
return
|
|
240
|
+
return this.#group;
|
|
212
241
|
}
|
|
213
242
|
/**
|
|
214
243
|
* Reports which maintenance work is currently due.
|
|
@@ -224,7 +253,7 @@ var ConnectionContextManagerImpl = class {
|
|
|
224
253
|
let earliestDeadlineAt = this.#group.retransformAt;
|
|
225
254
|
for (const connection of this.#connections.values()) {
|
|
226
255
|
if (connection.state !== "validated" || connection.revalidateAt === void 0) continue;
|
|
227
|
-
if (connection.revalidateAt <= now) dueRevalidations.push(
|
|
256
|
+
if (connection.revalidateAt <= now) dueRevalidations.push(connection);
|
|
228
257
|
earliestDeadlineAt = minDefined(earliestDeadlineAt, connection.revalidateAt);
|
|
229
258
|
}
|
|
230
259
|
const dueRetransform = this.#group.retransformAt !== void 0 && this.#group.retransformAt <= now;
|
|
@@ -252,17 +281,20 @@ var ConnectionContextManagerImpl = class {
|
|
|
252
281
|
});
|
|
253
282
|
return;
|
|
254
283
|
}
|
|
255
|
-
const snapshot = snapshotConnection(connection);
|
|
256
284
|
this.#connections.delete(connection.clientID);
|
|
257
285
|
this.#refreshBackgroundConnectionContext();
|
|
258
286
|
this.#updateBackgroundRetransformDeadline(false);
|
|
259
|
-
return
|
|
287
|
+
return connection;
|
|
260
288
|
}
|
|
261
289
|
#demoteConnection(connection) {
|
|
262
|
-
|
|
263
|
-
|
|
290
|
+
const demotedConnection = this.#storeConnection({
|
|
291
|
+
...connection,
|
|
292
|
+
state: "provisional",
|
|
293
|
+
revalidateAt: void 0
|
|
294
|
+
});
|
|
264
295
|
this.#refreshBackgroundConnectionContext();
|
|
265
296
|
this.#updateBackgroundRetransformDeadline(false);
|
|
297
|
+
return demotedConnection;
|
|
266
298
|
}
|
|
267
299
|
/**
|
|
268
300
|
* Keeps the background connection sticky while it remains validated.
|
|
@@ -277,10 +309,10 @@ var ConnectionContextManagerImpl = class {
|
|
|
277
309
|
const currentBackgroundConnection = this.#getBackgroundConnectionContext();
|
|
278
310
|
if (currentBackgroundConnection?.clientID === preferred.clientID && currentBackgroundConnection.wsID === preferred.wsID) return;
|
|
279
311
|
if (currentBackgroundConnection !== void 0) return;
|
|
280
|
-
this.#
|
|
312
|
+
this.#setBackgroundConnection({
|
|
281
313
|
clientID: preferred.clientID,
|
|
282
314
|
wsID: preferred.wsID
|
|
283
|
-
};
|
|
315
|
+
});
|
|
284
316
|
this.#lc.debug?.("Selected background connection for shared auth work", {
|
|
285
317
|
clientID: preferred.clientID,
|
|
286
318
|
wsID: preferred.wsID,
|
|
@@ -291,10 +323,10 @@ var ConnectionContextManagerImpl = class {
|
|
|
291
323
|
}
|
|
292
324
|
if (this.#getBackgroundConnectionContext()?.state === "validated") return;
|
|
293
325
|
const nextBackgroundConnection = [...this.#connections.values()].filter((connection) => connection.state === "validated").sort(comparePreferredValidatedConnection).at(0);
|
|
294
|
-
this.#
|
|
326
|
+
this.#setBackgroundConnection(nextBackgroundConnection ? {
|
|
295
327
|
clientID: nextBackgroundConnection.clientID,
|
|
296
328
|
wsID: nextBackgroundConnection.wsID
|
|
297
|
-
} : void 0;
|
|
329
|
+
} : void 0);
|
|
298
330
|
if (nextBackgroundConnection) this.#lc.debug?.("Selected background connection for shared auth work", {
|
|
299
331
|
clientID: nextBackgroundConnection.clientID,
|
|
300
332
|
wsID: nextBackgroundConnection.wsID,
|
|
@@ -322,6 +354,21 @@ var ConnectionContextManagerImpl = class {
|
|
|
322
354
|
}, "warn");
|
|
323
355
|
return connection;
|
|
324
356
|
}
|
|
357
|
+
#storeConnection(connection) {
|
|
358
|
+
this.#connections.set(connection.clientID, connection);
|
|
359
|
+
return connection;
|
|
360
|
+
}
|
|
361
|
+
#setGroup(group) {
|
|
362
|
+
this.#group = group;
|
|
363
|
+
return group;
|
|
364
|
+
}
|
|
365
|
+
#setBackgroundConnection(backgroundConnection) {
|
|
366
|
+
if (sameConnectionSelector(this.#group.backgroundConnection, backgroundConnection)) return;
|
|
367
|
+
this.#setGroup({
|
|
368
|
+
...this.#group,
|
|
369
|
+
backgroundConnection: backgroundConnection ? { ...backgroundConnection } : void 0
|
|
370
|
+
});
|
|
371
|
+
}
|
|
325
372
|
/**
|
|
326
373
|
* Keeps the group background retransform deadline coherent with current
|
|
327
374
|
* schedulability.
|
|
@@ -333,41 +380,21 @@ var ConnectionContextManagerImpl = class {
|
|
|
333
380
|
*/
|
|
334
381
|
#updateBackgroundRetransformDeadline(reset) {
|
|
335
382
|
if (!this.#getBackgroundConnectionContext() || this.#retransformIntervalMs === void 0) {
|
|
336
|
-
this.#group.retransformAt
|
|
383
|
+
if (this.#group.retransformAt !== void 0) this.#setGroup({
|
|
384
|
+
...this.#group,
|
|
385
|
+
retransformAt: void 0
|
|
386
|
+
});
|
|
337
387
|
return;
|
|
338
388
|
}
|
|
339
|
-
if (reset || this.#group.retransformAt === void 0) this.#
|
|
389
|
+
if (reset || this.#group.retransformAt === void 0) this.#setGroup({
|
|
390
|
+
...this.#group,
|
|
391
|
+
retransformAt: this.#now() + this.#retransformIntervalMs
|
|
392
|
+
});
|
|
340
393
|
}
|
|
341
394
|
#nextRevalidateAt() {
|
|
342
395
|
return this.#revalidateIntervalMs === void 0 ? void 0 : this.#now() + this.#revalidateIntervalMs;
|
|
343
396
|
}
|
|
344
397
|
};
|
|
345
|
-
function snapshotConnection(connection) {
|
|
346
|
-
if (!connection) return;
|
|
347
|
-
return {
|
|
348
|
-
...connection,
|
|
349
|
-
queryContext: {
|
|
350
|
-
...connection.queryContext,
|
|
351
|
-
headerOptions: {
|
|
352
|
-
...connection.queryContext.headerOptions,
|
|
353
|
-
customHeaders: connection.queryContext.headerOptions.customHeaders ? { ...connection.queryContext.headerOptions.customHeaders } : void 0
|
|
354
|
-
}
|
|
355
|
-
},
|
|
356
|
-
pushContext: {
|
|
357
|
-
...connection.pushContext,
|
|
358
|
-
headerOptions: {
|
|
359
|
-
...connection.pushContext.headerOptions,
|
|
360
|
-
customHeaders: connection.pushContext.headerOptions.customHeaders ? { ...connection.pushContext.headerOptions.customHeaders } : void 0
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
function snapshotGroup(group) {
|
|
366
|
-
return {
|
|
367
|
-
...group,
|
|
368
|
-
backgroundConnection: group.backgroundConnection ? { ...group.backgroundConnection } : void 0
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
398
|
function compareByInsertionOrder(a, b) {
|
|
372
399
|
return a.insertionOrder - b.insertionOrder || a.wsID.localeCompare(b.wsID);
|
|
373
400
|
}
|
|
@@ -379,6 +406,15 @@ function minDefined(a, b) {
|
|
|
379
406
|
if (b === void 0) return a;
|
|
380
407
|
return Math.min(a, b);
|
|
381
408
|
}
|
|
409
|
+
function sameConnectionSelector(a, b) {
|
|
410
|
+
return a?.clientID === b?.clientID && a?.wsID === b?.wsID;
|
|
411
|
+
}
|
|
412
|
+
function cloneCustomHeaders(headers) {
|
|
413
|
+
return headers ? { ...headers } : void 0;
|
|
414
|
+
}
|
|
415
|
+
function cloneAllowedClientHeaders(headers) {
|
|
416
|
+
return headers ? [...headers] : void 0;
|
|
417
|
+
}
|
|
382
418
|
//#endregion
|
|
383
419
|
export { ConnectionContextManagerImpl };
|
|
384
420
|
|