alepha 0.20.6 → 0.20.8
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/AGENTS.md +0 -1
- package/CLAUDE.md +0 -1
- package/assets/agents-template.md +0 -1
- package/dist/api/audits/index.browser.js +1 -0
- package/dist/api/audits/index.browser.js.map +1 -1
- package/dist/api/audits/index.d.ts +370 -355
- package/dist/api/audits/index.d.ts.map +1 -1
- package/dist/api/audits/index.js +1 -0
- package/dist/api/audits/index.js.map +1 -1
- package/dist/api/files/index.browser.js +1 -0
- package/dist/api/files/index.browser.js.map +1 -1
- package/dist/api/files/index.d.ts +179 -170
- package/dist/api/files/index.d.ts.map +1 -1
- package/dist/api/files/index.js +1 -0
- package/dist/api/files/index.js.map +1 -1
- package/dist/api/jobs/index.browser.js +7 -0
- package/dist/api/jobs/index.browser.js.map +1 -1
- package/dist/api/jobs/index.d.ts +259 -250
- package/dist/api/jobs/index.d.ts.map +1 -1
- package/dist/api/jobs/index.js +21 -3
- package/dist/api/jobs/index.js.map +1 -1
- package/dist/api/keys/index.d.ts +198 -192
- package/dist/api/keys/index.d.ts.map +1 -1
- package/dist/api/keys/index.js +1 -0
- package/dist/api/keys/index.js.map +1 -1
- package/dist/api/notifications/index.d.ts +246 -245
- package/dist/api/notifications/index.d.ts.map +1 -1
- package/dist/api/organizations/index.d.ts +100 -97
- package/dist/api/organizations/index.d.ts.map +1 -1
- package/dist/api/parameters/index.d.ts +323 -320
- package/dist/api/parameters/index.d.ts.map +1 -1
- package/dist/api/payments/index.d.ts +431 -376
- package/dist/api/payments/index.d.ts.map +1 -1
- package/dist/api/payments/index.js +202 -87
- package/dist/api/payments/index.js.map +1 -1
- package/dist/api/subscriptions/index.d.ts +1695 -0
- package/dist/api/subscriptions/index.d.ts.map +1 -0
- package/dist/api/subscriptions/index.js +1919 -0
- package/dist/api/subscriptions/index.js.map +1 -0
- package/dist/api/users/index.d.ts +857 -841
- package/dist/api/users/index.d.ts.map +1 -1
- package/dist/api/verifications/index.d.ts +128 -127
- package/dist/api/verifications/index.d.ts.map +1 -1
- package/dist/bucket/index.d.ts +3 -2
- package/dist/bucket/index.d.ts.map +1 -1
- package/dist/cache/core/index.d.ts +114 -4
- package/dist/cache/core/index.d.ts.map +1 -1
- package/dist/cache/core/index.js +181 -15
- package/dist/cache/core/index.js.map +1 -1
- package/dist/cache/core/index.workerd.js +181 -15
- package/dist/cache/core/index.workerd.js.map +1 -1
- package/dist/cache/database/index.d.ts +20 -19
- package/dist/cache/database/index.d.ts.map +1 -1
- package/dist/cache/redis/index.d.ts +3 -2
- package/dist/cache/redis/index.d.ts.map +1 -1
- package/dist/cli/core/index.d.ts +116 -132
- package/dist/cli/core/index.d.ts.map +1 -1
- package/dist/cli/core/index.js +75 -7
- package/dist/cli/core/index.js.map +1 -1
- package/dist/cli/devtools/index.d.ts +3 -2
- package/dist/cli/devtools/index.d.ts.map +1 -1
- package/dist/cli/platform/index.d.ts +346 -290
- package/dist/cli/platform/index.d.ts.map +1 -1
- package/dist/cli/platform/index.js +105 -6
- package/dist/cli/platform/index.js.map +1 -1
- package/dist/cli/vendor/index.d.ts +12 -11
- package/dist/cli/vendor/index.d.ts.map +1 -1
- package/dist/command/index.d.ts +5 -4
- package/dist/command/index.d.ts.map +1 -1
- package/dist/core/index.browser.js +1 -1
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +119 -118
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.native.js +1 -1
- package/dist/core/index.native.js.map +1 -1
- package/dist/core/index.workerd.js +1 -1
- package/dist/core/index.workerd.js.map +1 -1
- package/dist/crypto/index.d.ts +3 -2
- package/dist/crypto/index.d.ts.map +1 -1
- package/dist/email/core/index.d.ts +3 -2
- package/dist/email/core/index.d.ts.map +1 -1
- package/dist/email/smtp/index.d.ts +7 -6
- package/dist/email/smtp/index.d.ts.map +1 -1
- package/dist/lock/core/index.d.ts +5 -4
- package/dist/lock/core/index.d.ts.map +1 -1
- package/dist/logger/index.d.ts +10 -9
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/mcp/index.d.ts +9 -8
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/orm/core/index.browser.js +9 -3
- package/dist/orm/core/index.browser.js.map +1 -1
- package/dist/orm/core/index.bun.js +31 -10
- package/dist/orm/core/index.bun.js.map +1 -1
- package/dist/orm/core/index.d.ts +33 -14
- package/dist/orm/core/index.d.ts.map +1 -1
- package/dist/orm/core/index.js +31 -10
- package/dist/orm/core/index.js.map +1 -1
- package/dist/orm/postgres/index.d.ts +6 -5
- package/dist/orm/postgres/index.d.ts.map +1 -1
- package/dist/queue/core/index.d.ts +5 -4
- package/dist/queue/core/index.d.ts.map +1 -1
- package/dist/queue/redis/index.d.ts +3 -2
- package/dist/queue/redis/index.d.ts.map +1 -1
- package/dist/react/form/index.d.ts +5 -0
- package/dist/react/form/index.d.ts.map +1 -1
- package/dist/react/form/index.js +6 -4
- package/dist/react/form/index.js.map +1 -1
- package/dist/react/i18n/index.d.ts +2 -1
- package/dist/react/i18n/index.d.ts.map +1 -1
- package/dist/react/router/index.d.ts +206 -205
- package/dist/react/router/index.d.ts.map +1 -1
- package/dist/react/ui/index.d.ts +11 -11
- package/dist/react/ui/index.d.ts.map +1 -1
- package/dist/scheduler/index.d.ts +3 -2
- package/dist/scheduler/index.d.ts.map +1 -1
- package/dist/security/index.browser.js +29 -1
- package/dist/security/index.browser.js.map +1 -1
- package/dist/security/index.d.ts +82 -35
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +56 -3
- package/dist/security/index.js.map +1 -1
- package/dist/server/auth/index.d.ts +163 -158
- package/dist/server/auth/index.d.ts.map +1 -1
- package/dist/server/auth/index.js +16 -4
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/core/index.d.ts +35 -34
- package/dist/server/core/index.d.ts.map +1 -1
- package/dist/server/cors/index.d.ts +7 -6
- package/dist/server/cors/index.d.ts.map +1 -1
- package/dist/server/health/index.d.ts +16 -15
- package/dist/server/health/index.d.ts.map +1 -1
- package/dist/server/links/index.d.ts +51 -50
- package/dist/server/links/index.d.ts.map +1 -1
- package/dist/server/rate-limit/index.d.ts +6 -5
- package/dist/server/rate-limit/index.d.ts.map +1 -1
- package/dist/server/swagger/index.d.ts +2 -1
- package/dist/server/swagger/index.d.ts.map +1 -1
- package/dist/topic/redis/index.d.ts +3 -2
- package/dist/topic/redis/index.d.ts.map +1 -1
- package/package.json +16 -32
- package/src/api/audits/entities/audits.ts +1 -0
- package/src/api/files/entities/files.ts +1 -0
- package/src/api/jobs/__tests__/$job.spec.ts +92 -40
- package/src/api/jobs/entities/jobExecutionEntity.ts +1 -0
- package/src/api/jobs/providers/JobProvider.ts +20 -5
- package/src/api/jobs/schemas/jobConfigAtom.ts +5 -0
- package/src/api/keys/entities/apiKeyEntity.ts +1 -0
- package/src/api/payments/controllers/MockCheckoutController.ts +146 -0
- package/src/api/payments/index.ts +3 -0
- package/src/api/payments/providers/MemoryPaymentProvider.ts +9 -4
- package/src/api/payments/providers/PaymentProvider.ts +25 -9
- package/src/api/payments/services/PaymentService.ts +3 -0
- package/src/api/subscriptions/__tests__/BillingService.spec.ts +218 -0
- package/src/api/subscriptions/__tests__/SubscriptionService.spec.ts +278 -0
- package/src/api/subscriptions/controllers/AdminSubscriptionController.ts +212 -0
- package/src/api/subscriptions/controllers/SubscriptionController.ts +189 -0
- package/src/api/subscriptions/entities/subscriptionEvents.ts +54 -0
- package/src/api/subscriptions/entities/subscriptions.ts +68 -0
- package/src/api/subscriptions/index.ts +133 -0
- package/src/api/subscriptions/jobs/SubscriptionJobs.ts +382 -0
- package/src/api/subscriptions/middleware/$requireLimit.ts +50 -0
- package/src/api/subscriptions/middleware/$requirePlan.ts +49 -0
- package/src/api/subscriptions/notifications/SubscriptionNotifications.ts +110 -0
- package/src/api/subscriptions/schemas/cancelSubscriptionSchema.ts +8 -0
- package/src/api/subscriptions/schemas/changePlanSchema.ts +9 -0
- package/src/api/subscriptions/schemas/createSubscriptionSchema.ts +11 -0
- package/src/api/subscriptions/schemas/entitlementsSchema.ts +21 -0
- package/src/api/subscriptions/schemas/mrrSchema.ts +13 -0
- package/src/api/subscriptions/schemas/planDefinitionSchema.ts +71 -0
- package/src/api/subscriptions/schemas/planResourceSchema.ts +25 -0
- package/src/api/subscriptions/schemas/subscriptionEventResourceSchema.ts +8 -0
- package/src/api/subscriptions/schemas/subscriptionQuerySchema.ts +19 -0
- package/src/api/subscriptions/schemas/subscriptionResourceSchema.ts +6 -0
- package/src/api/subscriptions/schemas/subscriptionSettingsSchema.ts +32 -0
- package/src/api/subscriptions/schemas/subscriptionStatsSchema.ts +23 -0
- package/src/api/subscriptions/services/BillingService.ts +437 -0
- package/src/api/subscriptions/services/SubscriptionConfig.ts +56 -0
- package/src/api/subscriptions/services/SubscriptionService.ts +867 -0
- package/src/api/subscriptions/services/UsageService.ts +118 -0
- package/src/cache/core/__tests__/$cache.memory.spec.ts +450 -0
- package/src/cache/core/__tests__/$cache.swr.spec.ts +394 -0
- package/src/cache/core/index.ts +16 -0
- package/src/cache/core/primitives/$cache.ts +347 -21
- package/src/cli/core/tasks/BuildCloudflareTask.ts +16 -0
- package/src/cli/core/templates/agentMd.ts +39 -4
- package/src/cli/core/templates/biomeJson.ts +25 -1
- package/src/cli/core/templates/saasAdminLayoutTsx.ts +2 -2
- package/src/cli/platform/__tests__/CloudflareAdapter.spec.ts +117 -0
- package/src/cli/platform/adapters/CloudflareAdapter.ts +104 -7
- package/src/cli/platform/atoms/platformOptions.ts +13 -0
- package/src/cli/platform/schemas/platform.ts +1 -0
- package/src/cli/platform/services/CloudflareApi.ts +61 -0
- package/src/cli/platform/services/PlatformOrchestrator.ts +9 -4
- package/src/core/__tests__/$module.spec.ts +2 -2
- package/src/core/primitives/$module.ts +4 -4
- package/src/mcp/providers/McpServerProvider.ts +1 -1
- package/src/orm/core/providers/DatabaseTypeProvider.ts +9 -3
- package/src/orm/core/providers/drivers/DatabaseProvider.ts +1 -1
- package/src/orm/core/schemas/insertSchema.ts +10 -2
- package/src/orm/core/services/Repository.ts +27 -7
- package/src/react/form/hooks/useFormState.ts +8 -1
- package/src/react/form/index.ts +10 -1
- package/src/react/form/services/FormModel.ts +9 -3
- package/src/security/atoms/currentTenantAtom.ts +34 -0
- package/src/security/index.browser.ts +1 -0
- package/src/security/index.ts +12 -1
- package/src/security/primitives/$issuer.ts +17 -1
- package/src/security/providers/SecurityProvider.ts +37 -0
- package/src/server/auth/__tests__/validateRedirectUri.spec.ts +78 -0
- package/src/server/auth/providers/ServerAuthProvider.ts +21 -5
- package/tsconfig.base.json +2 -1
- package/dist/react/websocket/index.d.ts +0 -117
- package/dist/react/websocket/index.d.ts.map +0 -1
- package/dist/react/websocket/index.js +0 -108
- package/dist/react/websocket/index.js.map +0 -1
- package/dist/websocket/index.browser.js +0 -848
- package/dist/websocket/index.browser.js.map +0 -1
- package/dist/websocket/index.d.ts +0 -876
- package/dist/websocket/index.d.ts.map +0 -1
- package/dist/websocket/index.js +0 -1185
- package/dist/websocket/index.js.map +0 -1
- package/src/react/websocket/hooks/useRoom.tsx +0 -251
- package/src/react/websocket/index.ts +0 -7
- package/src/websocket/__tests__/$channel.spec.ts +0 -30
- package/src/websocket/__tests__/$websocket-new.spec.ts +0 -195
- package/src/websocket/__tests__/RoomManager.spec.ts +0 -146
- package/src/websocket/__tests__/websocket-integration.spec.ts +0 -951
- package/src/websocket/errors/WebSocketError.ts +0 -34
- package/src/websocket/index.browser.ts +0 -25
- package/src/websocket/index.shared.ts +0 -8
- package/src/websocket/index.ts +0 -85
- package/src/websocket/interfaces/WebSocketInterfaces.ts +0 -252
- package/src/websocket/primitives/$channel.ts +0 -131
- package/src/websocket/primitives/$websocket.ts +0 -107
- package/src/websocket/providers/NodeWebSocketServerProvider.ts +0 -617
- package/src/websocket/providers/WebSocketServerProvider.ts +0 -56
- package/src/websocket/services/RoomManager.ts +0 -160
- package/src/websocket/services/WebSocketClient.ts +0 -642
- package/src/websocket/services/WebSocketTopicService.ts +0 -108
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { AlephaError } from "alepha";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Base WebSocket error class
|
|
5
|
-
*/
|
|
6
|
-
export class WebSocketError extends AlephaError {
|
|
7
|
-
constructor(
|
|
8
|
-
message: string,
|
|
9
|
-
public readonly code?: number,
|
|
10
|
-
) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.name = "WebSocketError";
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Error thrown when WebSocket connection fails
|
|
18
|
-
*/
|
|
19
|
-
export class WebSocketConnectionError extends WebSocketError {
|
|
20
|
-
constructor(message: string, code?: number) {
|
|
21
|
-
super(message, code);
|
|
22
|
-
this.name = "WebSocketConnectionError";
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Error thrown when WebSocket message validation fails
|
|
28
|
-
*/
|
|
29
|
-
export class WebSocketValidationError extends WebSocketError {
|
|
30
|
-
constructor(message: string) {
|
|
31
|
-
super(message);
|
|
32
|
-
this.name = "WebSocketValidationError";
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { $module, type Alepha } from "alepha";
|
|
2
|
-
import { AlephaTopic } from "alepha/topic";
|
|
3
|
-
import { $channel } from "./primitives/$channel.ts";
|
|
4
|
-
import { $websocket } from "./primitives/$websocket.ts";
|
|
5
|
-
import { WebSocketClient } from "./services/WebSocketClient.ts";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* alepha/websocket (Browser)
|
|
9
|
-
*
|
|
10
|
-
* Browser-side WebSocket client module. Provides WebSocketClient service
|
|
11
|
-
* for managing WebSocket connections from the browser.
|
|
12
|
-
*
|
|
13
|
-
* For React applications, use alepha/react/websocket with the useRoom hook.
|
|
14
|
-
*/
|
|
15
|
-
export * from "./index.shared.ts";
|
|
16
|
-
|
|
17
|
-
export const AlephaWebSocket = $module({
|
|
18
|
-
name: "alepha.websocket",
|
|
19
|
-
primitives: [$channel, $websocket],
|
|
20
|
-
services: [WebSocketClient],
|
|
21
|
-
register: (alepha: Alepha) => {
|
|
22
|
-
alepha.with(AlephaTopic);
|
|
23
|
-
alepha.with(WebSocketClient);
|
|
24
|
-
},
|
|
25
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from "./errors/WebSocketError.ts";
|
|
2
|
-
export * from "./interfaces/WebSocketInterfaces.ts";
|
|
3
|
-
export * from "./primitives/$channel.ts";
|
|
4
|
-
export * from "./primitives/$websocket.ts";
|
|
5
|
-
export * from "./providers/WebSocketServerProvider.ts";
|
|
6
|
-
export * from "./services/RoomManager.ts";
|
|
7
|
-
export * from "./services/WebSocketClient.ts";
|
|
8
|
-
export * from "./services/WebSocketTopicService.ts";
|
package/src/websocket/index.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { $module, type Alepha } from "alepha";
|
|
2
|
-
import { AlephaServer } from "alepha/server";
|
|
3
|
-
import { AlephaTopic } from "alepha/topic";
|
|
4
|
-
import { $channel } from "./primitives/$channel.ts";
|
|
5
|
-
import { $websocket } from "./primitives/$websocket.ts";
|
|
6
|
-
import { NodeWebSocketServerProvider } from "./providers/NodeWebSocketServerProvider.ts";
|
|
7
|
-
import { WebSocketServerProvider } from "./providers/WebSocketServerProvider.ts";
|
|
8
|
-
import { RoomManager } from "./services/RoomManager.ts";
|
|
9
|
-
import { WebSocketTopicService } from "./services/WebSocketTopicService.ts";
|
|
10
|
-
|
|
11
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
declare module "alepha" {
|
|
14
|
-
interface Hooks {
|
|
15
|
-
/**
|
|
16
|
-
* Fires when a WebSocket connection is established
|
|
17
|
-
*/
|
|
18
|
-
"websocket:connect": {
|
|
19
|
-
connectionId: string;
|
|
20
|
-
path: string;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Fires when a WebSocket connection is closed
|
|
25
|
-
*/
|
|
26
|
-
"websocket:disconnect": {
|
|
27
|
-
connectionId: string;
|
|
28
|
-
path: string;
|
|
29
|
-
code?: number;
|
|
30
|
-
reason?: string;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Fires when a WebSocket message is received
|
|
35
|
-
*/
|
|
36
|
-
"websocket:message": {
|
|
37
|
-
connectionId: string;
|
|
38
|
-
path: string;
|
|
39
|
-
message: any;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Fires when a WebSocket error occurs
|
|
44
|
-
*/
|
|
45
|
-
"websocket:error": {
|
|
46
|
-
connectionId: string;
|
|
47
|
-
path: string;
|
|
48
|
-
error: Error;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
54
|
-
|
|
55
|
-
export * from "./index.shared.ts";
|
|
56
|
-
export * from "./providers/NodeWebSocketServerProvider.ts";
|
|
57
|
-
|
|
58
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Real-time bidirectional communication.
|
|
62
|
-
*
|
|
63
|
-
* **Features:**
|
|
64
|
-
* - WebSocket server definition
|
|
65
|
-
* - Named communication channels
|
|
66
|
-
* - Type-safe message handling
|
|
67
|
-
* - Connection lifecycle management
|
|
68
|
-
* - Room/channel grouping
|
|
69
|
-
* - Browser compatibility
|
|
70
|
-
*
|
|
71
|
-
* @module alepha.websocket
|
|
72
|
-
*/
|
|
73
|
-
export const AlephaWebSocket = $module({
|
|
74
|
-
name: "alepha.websocket",
|
|
75
|
-
primitives: [$channel, $websocket],
|
|
76
|
-
services: [WebSocketServerProvider, RoomManager, WebSocketTopicService],
|
|
77
|
-
variants: [NodeWebSocketServerProvider],
|
|
78
|
-
imports: [AlephaServer, AlephaTopic],
|
|
79
|
-
register: (alepha: Alepha) => {
|
|
80
|
-
alepha.with({
|
|
81
|
-
provide: WebSocketServerProvider,
|
|
82
|
-
use: NodeWebSocketServerProvider,
|
|
83
|
-
});
|
|
84
|
-
},
|
|
85
|
-
});
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import type { Static } from "alepha";
|
|
2
|
-
import type { ChannelPrimitive, TWSObject } from "../primitives/$channel.ts";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* WebSocket connection interface
|
|
6
|
-
*/
|
|
7
|
-
export interface WebSocketConnection {
|
|
8
|
-
/**
|
|
9
|
-
* Unique connection ID
|
|
10
|
-
*/
|
|
11
|
-
id: string;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* User ID (if authenticated and security module is used)
|
|
15
|
-
*/
|
|
16
|
-
userId?: string;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Channel path this connection belongs to
|
|
20
|
-
*/
|
|
21
|
-
channelPath: string;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Room IDs that this connection is currently in
|
|
25
|
-
*/
|
|
26
|
-
roomIds: string[];
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Send a message to this connection
|
|
30
|
-
*/
|
|
31
|
-
send(message: any): Promise<void>;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Close this connection
|
|
35
|
-
*/
|
|
36
|
-
close(code?: number, reason?: string): Promise<void>;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Connection metadata (custom data)
|
|
40
|
-
*/
|
|
41
|
-
metadata?: Record<string, any>;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Connection state
|
|
45
|
-
*/
|
|
46
|
-
readyState: WebSocketState;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* WebSocket state enum
|
|
51
|
-
*/
|
|
52
|
-
export enum WebSocketState {
|
|
53
|
-
CONNECTING = 0,
|
|
54
|
-
OPEN = 1,
|
|
55
|
-
CLOSING = 2,
|
|
56
|
-
CLOSED = 3,
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* WebSocket endpoint configuration (server-side)
|
|
61
|
-
*/
|
|
62
|
-
export interface WebSocketPrimitiveOptions<
|
|
63
|
-
TClient extends TWSObject,
|
|
64
|
-
TServer extends TWSObject,
|
|
65
|
-
> {
|
|
66
|
-
/**
|
|
67
|
-
* Channel definition with schema and path
|
|
68
|
-
*/
|
|
69
|
-
channel: ChannelPrimitive<TClient, TServer>;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Handler for incoming messages from clients
|
|
73
|
-
*/
|
|
74
|
-
handler: WebSocketHandler<TClient, TServer>;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Optional connection handler (called when a client connects)
|
|
78
|
-
*/
|
|
79
|
-
onConnect?: (params: {
|
|
80
|
-
/**
|
|
81
|
-
* Unique connection ID of the client
|
|
82
|
-
*/
|
|
83
|
-
connectionId: string;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* User ID of the connected client (if authenticated and security module is used)
|
|
87
|
-
*/
|
|
88
|
-
userId?: string;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Room IDs that the client is connecting to
|
|
92
|
-
*/
|
|
93
|
-
roomIds: string[];
|
|
94
|
-
}) => Promise<void> | void;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Optional disconnection handler (called when a client disconnects)
|
|
98
|
-
*/
|
|
99
|
-
onDisconnect?: (params: {
|
|
100
|
-
/**
|
|
101
|
-
* Unique connection ID of the client
|
|
102
|
-
*/
|
|
103
|
-
connectionId: string;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* User ID of the connected client (if authenticated and security module is used)
|
|
107
|
-
*/
|
|
108
|
-
userId?: string;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Room IDs that the client was connected to
|
|
112
|
-
*/
|
|
113
|
-
roomIds: string[];
|
|
114
|
-
}) => Promise<void> | void;
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Change WebSocket server provider (for custom implementations)
|
|
118
|
-
*/
|
|
119
|
-
provider?: any;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Whether to enforce security (authentication, authorization) on this WebSocket endpoint
|
|
123
|
-
* Requires alepha/security integration
|
|
124
|
-
*/
|
|
125
|
-
secure?: boolean;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Limit number of connections per user (if authenticated)
|
|
129
|
-
*/
|
|
130
|
-
maxConnectionsPerUser?: number;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* WebSocket message handler
|
|
135
|
-
*/
|
|
136
|
-
export type WebSocketHandler<
|
|
137
|
-
TClient extends TWSObject,
|
|
138
|
-
TServer extends TWSObject,
|
|
139
|
-
> = (
|
|
140
|
-
context: WebSocketHandlerContext<TClient, TServer>,
|
|
141
|
-
) => Promise<void> | void;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* WebSocket handler context
|
|
145
|
-
*/
|
|
146
|
-
export interface WebSocketHandlerContext<
|
|
147
|
-
TClient extends TWSObject,
|
|
148
|
-
TServer extends TWSObject,
|
|
149
|
-
> {
|
|
150
|
-
/**
|
|
151
|
-
* Unique connection ID of the client
|
|
152
|
-
*/
|
|
153
|
-
connectionId: string;
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* User ID of the connected client (if authenticated and security module is used)
|
|
157
|
-
*/
|
|
158
|
-
userId?: string;
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Room ID that the client sent the message from
|
|
162
|
-
*/
|
|
163
|
-
roomId: string;
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* The parsed and validated message from the client
|
|
167
|
-
*/
|
|
168
|
-
message: Static<TServer>;
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Reply function tailored to current context (connectionId, roomId)
|
|
172
|
-
*/
|
|
173
|
-
reply: (options: {
|
|
174
|
-
/**
|
|
175
|
-
* Message to send
|
|
176
|
-
*/
|
|
177
|
-
message: Static<TClient>;
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Optional: specify room ID to send to (defaults to sender's room ID)
|
|
181
|
-
*/
|
|
182
|
-
roomId?: string;
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Optional: exclude the sender connection from receiving the message
|
|
186
|
-
* Will populate exceptConnectionIds with sender connection ID behind the scenes
|
|
187
|
-
*/
|
|
188
|
-
exceptSelf?: boolean;
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Optional: exclude specific connection IDs from receiving the message
|
|
192
|
-
*/
|
|
193
|
-
exceptConnectionIds?: string[];
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Optional: exclude specific user IDs from receiving the message
|
|
197
|
-
* Requires alepha/security integration
|
|
198
|
-
*/
|
|
199
|
-
exceptUserIds?: string[];
|
|
200
|
-
}) => Promise<void>;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Emit options for sending messages from the server
|
|
205
|
-
*/
|
|
206
|
-
export interface EmitOptions<TClient extends TWSObject> {
|
|
207
|
-
/**
|
|
208
|
-
* Message to send to clients
|
|
209
|
-
*/
|
|
210
|
-
message: Static<TClient>;
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Room ID to send the message to
|
|
214
|
-
*/
|
|
215
|
-
roomId?: string;
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Room IDs to send the message to
|
|
219
|
-
*/
|
|
220
|
-
roomIds?: string[];
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* User ID to send the message to (if authenticated)
|
|
224
|
-
*/
|
|
225
|
-
userId?: string;
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* User IDs to send the message to (if authenticated)
|
|
229
|
-
*/
|
|
230
|
-
userIds?: string[];
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Connection ID to send the message to
|
|
234
|
-
*/
|
|
235
|
-
connectionId?: string;
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Connection IDs to send the message to
|
|
239
|
-
*/
|
|
240
|
-
connectionIds?: string[];
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Optional: exclude specific connection IDs from receiving the message
|
|
244
|
-
*/
|
|
245
|
-
exceptConnectionIds?: string[];
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Optional: exclude specific user IDs from receiving the message
|
|
249
|
-
* Requires alepha/security integration
|
|
250
|
-
*/
|
|
251
|
-
exceptUserIds?: string[];
|
|
252
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createPrimitive,
|
|
3
|
-
KIND,
|
|
4
|
-
Primitive,
|
|
5
|
-
type TObject,
|
|
6
|
-
type TString,
|
|
7
|
-
type TUnion,
|
|
8
|
-
} from "alepha";
|
|
9
|
-
|
|
10
|
-
export type TWSObject = TObject | TUnion;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Channel primitive options
|
|
14
|
-
*/
|
|
15
|
-
export interface ChannelPrimitiveOptions<
|
|
16
|
-
TClient extends TWSObject,
|
|
17
|
-
TServer extends TWSObject,
|
|
18
|
-
> {
|
|
19
|
-
/**
|
|
20
|
-
* WebSocket endpoint path (e.g., "/ws/chat")
|
|
21
|
-
*/
|
|
22
|
-
path: string;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Optional description for documentation
|
|
26
|
-
*/
|
|
27
|
-
description?: string;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Message schemas for bidirectional communication
|
|
31
|
-
*/
|
|
32
|
-
schema: {
|
|
33
|
-
/**
|
|
34
|
-
* Optional room ID schema validation
|
|
35
|
-
* Default: t.text() (any string)
|
|
36
|
-
* Can be enforced at application level: t.uuid(), t.regex(/^[a-f0-9\-]{36}$/)
|
|
37
|
-
*/
|
|
38
|
-
roomId?: TString;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Messages from server to client
|
|
42
|
-
* This is what clients will receive
|
|
43
|
-
*/
|
|
44
|
-
in: TClient;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Messages from client to server
|
|
48
|
-
* This is what the server will receive
|
|
49
|
-
*/
|
|
50
|
-
out: TServer;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Defines a WebSocket channel with specified client and server message schemas.
|
|
56
|
-
*
|
|
57
|
-
* Channels must be defined as class properties to be registered in the Alepha context.
|
|
58
|
-
* They define the "vocabulary" for communication - the schema for messages flowing
|
|
59
|
-
* in both directions (server→client and client→server).
|
|
60
|
-
*
|
|
61
|
-
* @example Server-side with $websocket
|
|
62
|
-
* ```typescript
|
|
63
|
-
* class ChatController {
|
|
64
|
-
* // Channel must be defined inside a class
|
|
65
|
-
* chatChannel = $channel({
|
|
66
|
-
* path: "/ws/chat",
|
|
67
|
-
* description: "Real-time chat channel",
|
|
68
|
-
* schema: {
|
|
69
|
-
* // Server → Client messages
|
|
70
|
-
* in: t.union([
|
|
71
|
-
* t.object({
|
|
72
|
-
* type: t.const("append"),
|
|
73
|
-
* content: t.text(),
|
|
74
|
-
* username: t.text()
|
|
75
|
-
* }),
|
|
76
|
-
* t.object({
|
|
77
|
-
* type: t.const("system"),
|
|
78
|
-
* message: t.text()
|
|
79
|
-
* })
|
|
80
|
-
* ]),
|
|
81
|
-
* // Client → Server messages
|
|
82
|
-
* out: t.object({
|
|
83
|
-
* content: t.text()
|
|
84
|
-
* })
|
|
85
|
-
* }
|
|
86
|
-
* });
|
|
87
|
-
*
|
|
88
|
-
* chat = $websocket({
|
|
89
|
-
* channel: this.chatChannel,
|
|
90
|
-
* handler: async ({ message, reply }) => {
|
|
91
|
-
* await reply({
|
|
92
|
-
* message: { type: "append", content: message.content, username: "user" }
|
|
93
|
-
* });
|
|
94
|
-
* }
|
|
95
|
-
* });
|
|
96
|
-
* }
|
|
97
|
-
* ```
|
|
98
|
-
*
|
|
99
|
-
* @example Browser-side with useRoom
|
|
100
|
-
* ```typescript
|
|
101
|
-
* // Define channel in a class for browser context
|
|
102
|
-
* class ChatClient {
|
|
103
|
-
* chatChannel = $channel({
|
|
104
|
-
* path: "/ws/chat",
|
|
105
|
-
* schema: { in: inSchema, out: outSchema }
|
|
106
|
-
* });
|
|
107
|
-
* }
|
|
108
|
-
*
|
|
109
|
-
* // Use in React component
|
|
110
|
-
* function Chat() {
|
|
111
|
-
* const client = useInject(ChatClient);
|
|
112
|
-
* const chat = useRoom({ roomId: "lobby", channel: client.chatChannel, handler: ... }, []);
|
|
113
|
-
* }
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
export const $channel = <TClient extends TWSObject, TServer extends TWSObject>(
|
|
117
|
-
options: ChannelPrimitiveOptions<TClient, TServer>,
|
|
118
|
-
): ChannelPrimitive<TClient, TServer> => {
|
|
119
|
-
return createPrimitive(ChannelPrimitive<TClient, TServer>, options);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
123
|
-
|
|
124
|
-
export class ChannelPrimitive<
|
|
125
|
-
TClient extends TWSObject,
|
|
126
|
-
TServer extends TWSObject,
|
|
127
|
-
> extends Primitive<ChannelPrimitiveOptions<TClient, TServer>> {
|
|
128
|
-
// Channels are just schema definitions - no initialization logic needed
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
$channel[KIND] = ChannelPrimitive;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { $inject, createPrimitive, KIND, Primitive } from "alepha";
|
|
2
|
-
import type {
|
|
3
|
-
EmitOptions,
|
|
4
|
-
WebSocketPrimitiveOptions,
|
|
5
|
-
} from "../interfaces/WebSocketInterfaces.ts";
|
|
6
|
-
import { WebSocketServerProvider } from "../providers/WebSocketServerProvider.ts";
|
|
7
|
-
import type { TWSObject } from "./$channel.ts";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Defines a WebSocket server endpoint for a specific channel.
|
|
11
|
-
*
|
|
12
|
-
* Server-side only. Creates a WebSocket endpoint that:
|
|
13
|
-
* - Accepts connections from clients
|
|
14
|
-
* - Validates incoming messages against the channel schema
|
|
15
|
-
* - Provides room-based messaging
|
|
16
|
-
* - Integrates with alepha/security for authentication (optional)
|
|
17
|
-
* - Supports horizontal scaling via alepha/topic
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* class ChatController {
|
|
22
|
-
* chat = $websocket({
|
|
23
|
-
* channel: chatChannel,
|
|
24
|
-
* handler: async ({ connectionId, userId, roomId, message, reply }) => {
|
|
25
|
-
* // Broadcast to all in room except sender
|
|
26
|
-
* await reply({
|
|
27
|
-
* message: {
|
|
28
|
-
* type: "append",
|
|
29
|
-
* username: userId,
|
|
30
|
-
* content: message.content
|
|
31
|
-
* },
|
|
32
|
-
* exceptSelf: true
|
|
33
|
-
* });
|
|
34
|
-
* }
|
|
35
|
-
* });
|
|
36
|
-
*
|
|
37
|
-
* async broadcastAnnouncement(roomId: string, text: string) {
|
|
38
|
-
* await this.chat.emit({
|
|
39
|
-
* roomId,
|
|
40
|
-
* message: {
|
|
41
|
-
* type: "append",
|
|
42
|
-
* username: "System",
|
|
43
|
-
* content: text
|
|
44
|
-
* }
|
|
45
|
-
* });
|
|
46
|
-
* }
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export const $websocket = <
|
|
51
|
-
TClient extends TWSObject,
|
|
52
|
-
TServer extends TWSObject,
|
|
53
|
-
>(
|
|
54
|
-
options: WebSocketPrimitiveOptions<TClient, TServer>,
|
|
55
|
-
): WebSocketPrimitive<TClient, TServer> => {
|
|
56
|
-
return createPrimitive(WebSocketPrimitive<TClient, TServer>, options);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
60
|
-
|
|
61
|
-
export class WebSocketPrimitive<
|
|
62
|
-
TClient extends TWSObject,
|
|
63
|
-
TServer extends TWSObject,
|
|
64
|
-
> extends Primitive<WebSocketPrimitiveOptions<TClient, TServer>> {
|
|
65
|
-
protected readonly webSocketServerProvider = $inject(WebSocketServerProvider);
|
|
66
|
-
|
|
67
|
-
protected onInit() {
|
|
68
|
-
this.webSocketServerProvider.registerEndpoint(this.options);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Emit message to clients
|
|
73
|
-
*
|
|
74
|
-
* Send messages from the server to connected clients based on targeting criteria.
|
|
75
|
-
* Messages are distributed across all server instances via pub/sub.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```typescript
|
|
79
|
-
* // Send to specific room
|
|
80
|
-
* await websocket.emit({
|
|
81
|
-
* roomId: "room-123",
|
|
82
|
-
* message: { type: "update", data: {...} }
|
|
83
|
-
* });
|
|
84
|
-
*
|
|
85
|
-
* // Send to specific user (all their connections)
|
|
86
|
-
* await websocket.emit({
|
|
87
|
-
* userId: "user-456",
|
|
88
|
-
* message: { type: "notification", text: "Hello!" }
|
|
89
|
-
* });
|
|
90
|
-
*
|
|
91
|
-
* // Send to multiple rooms, except certain users
|
|
92
|
-
* await websocket.emit({
|
|
93
|
-
* roomIds: ["room-1", "room-2"],
|
|
94
|
-
* exceptUserIds: ["user-123"],
|
|
95
|
-
* message: { type: "broadcast", content: "System announcement" }
|
|
96
|
-
* });
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
public async emit(options: EmitOptions<TClient>): Promise<void> {
|
|
100
|
-
await this.webSocketServerProvider.emit(
|
|
101
|
-
this.options.channel.options.path,
|
|
102
|
-
options,
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
$websocket[KIND] = WebSocketPrimitive;
|