@streamotter/gateway 0.1.0-rc.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.
- package/LICENSE +21 -0
- package/README.md +158 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/internals.d.ts +6 -0
- package/dist/internals.d.ts.map +1 -0
- package/dist/internals.js +6 -0
- package/dist/internals.js.map +1 -0
- package/dist/management/index.d.ts +26 -0
- package/dist/management/index.d.ts.map +1 -0
- package/dist/management/index.js +354 -0
- package/dist/management/index.js.map +1 -0
- package/dist/runtime/budget.d.ts +24 -0
- package/dist/runtime/budget.d.ts.map +1 -0
- package/dist/runtime/budget.js +56 -0
- package/dist/runtime/budget.js.map +1 -0
- package/dist/runtime/core.d.ts +67 -0
- package/dist/runtime/core.d.ts.map +1 -0
- package/dist/runtime/core.js +34 -0
- package/dist/runtime/core.js.map +1 -0
- package/dist/runtime/gateway.d.ts +117 -0
- package/dist/runtime/gateway.d.ts.map +1 -0
- package/dist/runtime/gateway.js +881 -0
- package/dist/runtime/gateway.js.map +1 -0
- package/dist/runtime/identity.d.ts +28 -0
- package/dist/runtime/identity.d.ts.map +1 -0
- package/dist/runtime/identity.js +92 -0
- package/dist/runtime/identity.js.map +1 -0
- package/dist/runtime/session.d.ts +49 -0
- package/dist/runtime/session.d.ts.map +1 -0
- package/dist/runtime/session.js +299 -0
- package/dist/runtime/session.js.map +1 -0
- package/dist/runtime/subscription.d.ts +65 -0
- package/dist/runtime/subscription.d.ts.map +1 -0
- package/dist/runtime/subscription.js +482 -0
- package/dist/runtime/subscription.js.map +1 -0
- package/dist/runtime/traces.d.ts +26 -0
- package/dist/runtime/traces.d.ts.map +1 -0
- package/dist/runtime/traces.js +98 -0
- package/dist/runtime/traces.js.map +1 -0
- package/dist/runtime/util.d.ts +50 -0
- package/dist/runtime/util.d.ts.map +1 -0
- package/dist/runtime/util.js +148 -0
- package/dist/runtime/util.js.map +1 -0
- package/dist/sources/fixture.d.ts +27 -0
- package/dist/sources/fixture.d.ts.map +1 -0
- package/dist/sources/fixture.js +89 -0
- package/dist/sources/fixture.js.map +1 -0
- package/dist/sources/kafka.d.ts +63 -0
- package/dist/sources/kafka.d.ts.map +1 -0
- package/dist/sources/kafka.js +418 -0
- package/dist/sources/kafka.js.map +1 -0
- package/dist/sources/kafkajs-patch.d.ts +11 -0
- package/dist/sources/kafkajs-patch.d.ts.map +1 -0
- package/dist/sources/kafkajs-patch.js +34 -0
- package/dist/sources/kafkajs-patch.js.map +1 -0
- package/dist/sources/types.d.ts +46 -0
- package/dist/sources/types.d.ts.map +1 -0
- package/dist/sources/types.js +2 -0
- package/dist/sources/types.js.map +1 -0
- package/dist/transport/socketio.d.ts +44 -0
- package/dist/transport/socketio.d.ts.map +1 -0
- package/dist/transport/socketio.js +80 -0
- package/dist/transport/socketio.js.map +1 -0
- package/dist/transport/types.d.ts +10 -0
- package/dist/transport/types.d.ts.map +1 -0
- package/dist/transport/types.js +2 -0
- package/dist/transport/types.js.map +1 -0
- package/package.json +61 -0
- package/src/index.ts +20 -0
- package/src/internals.ts +5 -0
- package/src/management/index.ts +371 -0
- package/src/runtime/budget.ts +60 -0
- package/src/runtime/core.ts +101 -0
- package/src/runtime/gateway.ts +892 -0
- package/src/runtime/identity.ts +99 -0
- package/src/runtime/session.ts +329 -0
- package/src/runtime/subscription.ts +531 -0
- package/src/runtime/traces.ts +102 -0
- package/src/runtime/util.ts +157 -0
- package/src/sources/fixture.ts +95 -0
- package/src/sources/kafka.ts +440 -0
- package/src/sources/kafkajs-patch.ts +41 -0
- package/src/sources/types.ts +42 -0
- package/src/transport/socketio.ts +125 -0
- package/src/transport/types.ts +10 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ChannelContract, ChannelHandlers, DataFrame, ErrorCode, ErrorFrame, GatewayLogger, Limits, Principal, Schema,
|
|
3
|
+
Source, SourceStatus, SubscriptionFrame
|
|
4
|
+
} from "@streamotter/contracts";
|
|
5
|
+
import type { ByteBudget } from "./budget.ts";
|
|
6
|
+
import type { RevocationLog } from "./identity.ts";
|
|
7
|
+
import type { TraceBuffer } from "./traces.ts";
|
|
8
|
+
import type { Semaphore } from "./util.ts";
|
|
9
|
+
import type { SourceAdapter } from "../sources/types.ts";
|
|
10
|
+
|
|
11
|
+
/** Shared services every runtime component needs. */
|
|
12
|
+
export interface GatewayCore {
|
|
13
|
+
readonly projectId: string;
|
|
14
|
+
readonly mode: "development" | "production";
|
|
15
|
+
readonly limits: Limits;
|
|
16
|
+
readonly traces: TraceBuffer;
|
|
17
|
+
readonly router: Router;
|
|
18
|
+
readonly snapshots: Semaphore;
|
|
19
|
+
readonly revocations: RevocationLog;
|
|
20
|
+
readonly logger: GatewayLogger;
|
|
21
|
+
readonly gatewayBudget: ByteBudget;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface RoutedSubscription {
|
|
25
|
+
readonly routingKey: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Routing index from routing identity to the subscriptions capturing it. */
|
|
29
|
+
export class Router<S extends RoutedSubscription = RoutedSubscription> {
|
|
30
|
+
readonly #byKey = new Map<string, Set<S>>();
|
|
31
|
+
|
|
32
|
+
add(subscription: S): void {
|
|
33
|
+
let set = this.#byKey.get(subscription.routingKey);
|
|
34
|
+
if (set === undefined) {
|
|
35
|
+
set = new Set();
|
|
36
|
+
this.#byKey.set(subscription.routingKey, set);
|
|
37
|
+
}
|
|
38
|
+
set.add(subscription);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
remove(subscription: S): void {
|
|
42
|
+
const set = this.#byKey.get(subscription.routingKey);
|
|
43
|
+
if (set === undefined) return;
|
|
44
|
+
set.delete(subscription);
|
|
45
|
+
if (set.size === 0) this.#byKey.delete(subscription.routingKey);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get(routingKey: string): ReadonlySet<S> | undefined {
|
|
49
|
+
return this.#byKey.get(routingKey);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get size(): number {
|
|
53
|
+
let total = 0;
|
|
54
|
+
for (const set of this.#byKey.values()) total += set.size;
|
|
55
|
+
return total;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Routing identity: (project, channel, version, verified tenant, canonical parameters). */
|
|
60
|
+
export function routingKey(channel: string, version: number, tenantId: string, canonicalParams: string): string {
|
|
61
|
+
return JSON.stringify([channel, version, tenantId, canonicalParams]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ChannelRuntime {
|
|
65
|
+
readonly name: string;
|
|
66
|
+
readonly version: number;
|
|
67
|
+
readonly handlers: ChannelHandlers<ChannelContract>;
|
|
68
|
+
readonly paramsSchema: Schema;
|
|
69
|
+
readonly payloadSchema: Schema;
|
|
70
|
+
readonly source: SourceRuntime;
|
|
71
|
+
readonly subscriptions: Set<SubscriptionLike>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface SubscriptionLike {
|
|
75
|
+
onSourceUnavailable(reason: ErrorCode): void;
|
|
76
|
+
onSourceReady(): void;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface SourceRuntime {
|
|
80
|
+
readonly id: string;
|
|
81
|
+
readonly config: Source;
|
|
82
|
+
readonly channels: ChannelRuntime[];
|
|
83
|
+
adapter: SourceAdapter | null;
|
|
84
|
+
status: SourceStatus["status"];
|
|
85
|
+
reason: ErrorCode | undefined;
|
|
86
|
+
readonly ready: boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** What a subscription needs from the connection that owns it. */
|
|
90
|
+
export interface SubscriptionHost {
|
|
91
|
+
readonly connectionId: string;
|
|
92
|
+
readonly principal: Principal;
|
|
93
|
+
readonly connectionBudget: ByteBudget;
|
|
94
|
+
sendState(frame: SubscriptionFrame): void;
|
|
95
|
+
sendData(frame: DataFrame): void;
|
|
96
|
+
sendError(frame: ErrorFrame): void;
|
|
97
|
+
/** False once the connection closed or its authentication expired. */
|
|
98
|
+
canDeliver(): boolean;
|
|
99
|
+
receiptTimedOut(): void;
|
|
100
|
+
removeSubscription(subscriptionId: string): void;
|
|
101
|
+
}
|