@eleven-am/pondsocket-nest 0.0.136 → 0.0.138
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/README.md +141 -541
- package/dist/context/context.d.ts +41 -0
- package/dist/context/context.js +238 -0
- package/{decorators → dist/decorators}/onConnectionRequest.js +2 -2
- package/{decorators → dist/decorators}/onEvent.js +2 -2
- package/{decorators → dist/decorators}/onJoinRequest.js +2 -2
- package/{decorators → dist/decorators}/onLeave.js +3 -4
- package/{decorators → dist/decorators}/onOutgoingEvent.js +10 -2
- package/{helpers → dist/helpers}/createParamDecorator.js +4 -3
- package/{helpers → dist/helpers}/misc.d.ts +1 -1
- package/dist/helpers/misc.js +27 -0
- package/dist/index.d.ts +6 -0
- package/{index.js → dist/index.js} +1 -0
- package/dist/managers/outgoingEvent.d.ts +5 -0
- package/{modules → dist/modules}/pondSocket.js +4 -5
- package/dist/performers/action.d.ts +8 -0
- package/dist/performers/action.js +121 -0
- package/dist/performers/errors.d.ts +4 -0
- package/dist/performers/errors.js +43 -0
- package/dist/performers/response.d.ts +5 -0
- package/dist/performers/response.js +65 -0
- package/{services → dist/services}/pondSocket.d.ts +12 -4
- package/dist/services/pondSocket.js +288 -0
- package/dist/types.d.ts +113 -0
- package/package.json +57 -46
- package/context/context.d.ts +0 -27
- package/context/context.js +0 -103
- package/helpers/misc.js +0 -13
- package/index.d.ts +0 -5
- package/managers/outgoingEvent.d.ts +0 -5
- package/performers/action.d.ts +0 -5
- package/performers/action.js +0 -89
- package/performers/errors.d.ts +0 -2
- package/performers/errors.js +0 -37
- package/performers/narrow.d.ts +0 -7
- package/performers/narrow.js +0 -21
- package/performers/response.d.ts +0 -3
- package/performers/response.js +0 -62
- package/services/pondSocket.js +0 -190
- package/types.d.ts +0 -64
- /package/{constants.d.ts → dist/constants.d.ts} +0 -0
- /package/{constants.js → dist/constants.js} +0 -0
- /package/{decorators → dist/decorators}/channel.d.ts +0 -0
- /package/{decorators → dist/decorators}/channel.js +0 -0
- /package/{decorators → dist/decorators}/channelInstance.d.ts +0 -0
- /package/{decorators → dist/decorators}/channelInstance.js +0 -0
- /package/{decorators → dist/decorators}/endpoint.d.ts +0 -0
- /package/{decorators → dist/decorators}/endpoint.js +0 -0
- /package/{decorators → dist/decorators}/endpointInstance.d.ts +0 -0
- /package/{decorators → dist/decorators}/endpointInstance.js +0 -0
- /package/{decorators → dist/decorators}/getChannel.d.ts +0 -0
- /package/{decorators → dist/decorators}/getChannel.js +0 -0
- /package/{decorators → dist/decorators}/getConnectionContext.d.ts +0 -0
- /package/{decorators → dist/decorators}/getConnectionContext.js +0 -0
- /package/{decorators → dist/decorators}/getConnectionHeaders.d.ts +0 -0
- /package/{decorators → dist/decorators}/getConnectionHeaders.js +0 -0
- /package/{decorators → dist/decorators}/getContext.d.ts +0 -0
- /package/{decorators → dist/decorators}/getContext.js +0 -0
- /package/{decorators → dist/decorators}/getEventContext.d.ts +0 -0
- /package/{decorators → dist/decorators}/getEventContext.js +0 -0
- /package/{decorators → dist/decorators}/getEventParams.d.ts +0 -0
- /package/{decorators → dist/decorators}/getEventParams.js +0 -0
- /package/{decorators → dist/decorators}/getEventPayload.d.ts +0 -0
- /package/{decorators → dist/decorators}/getEventPayload.js +0 -0
- /package/{decorators → dist/decorators}/getEventQuery.d.ts +0 -0
- /package/{decorators → dist/decorators}/getEventQuery.js +0 -0
- /package/{decorators → dist/decorators}/getJoinContext.d.ts +0 -0
- /package/{decorators → dist/decorators}/getJoinContext.js +0 -0
- /package/{decorators → dist/decorators}/getJoinParams.d.ts +0 -0
- /package/{decorators → dist/decorators}/getJoinParams.js +0 -0
- /package/{decorators → dist/decorators}/getLeaveEvent.d.ts +0 -0
- /package/{decorators → dist/decorators}/getLeaveEvent.js +0 -0
- /package/{decorators → dist/decorators}/getUserAssigns.d.ts +0 -0
- /package/{decorators → dist/decorators}/getUserAssigns.js +0 -0
- /package/{decorators → dist/decorators}/getUserData.d.ts +0 -0
- /package/{decorators → dist/decorators}/getUserData.js +0 -0
- /package/{decorators → dist/decorators}/getUserPresence.d.ts +0 -0
- /package/{decorators → dist/decorators}/getUserPresence.js +0 -0
- /package/{decorators → dist/decorators}/index.d.ts +0 -0
- /package/{decorators → dist/decorators}/index.js +0 -0
- /package/{decorators → dist/decorators}/onConnectionRequest.d.ts +0 -0
- /package/{decorators → dist/decorators}/onEvent.d.ts +0 -0
- /package/{decorators → dist/decorators}/onJoinRequest.d.ts +0 -0
- /package/{decorators → dist/decorators}/onLeave.d.ts +0 -0
- /package/{decorators → dist/decorators}/onOutgoingEvent.d.ts +0 -0
- /package/{decorators → dist/decorators}/useGuards.d.ts +0 -0
- /package/{decorators → dist/decorators}/useGuards.js +0 -0
- /package/{decorators → dist/decorators}/usePipes.d.ts +0 -0
- /package/{decorators → dist/decorators}/usePipes.js +0 -0
- /package/{helpers → dist/helpers}/createContextParamDecorator.d.ts +0 -0
- /package/{helpers → dist/helpers}/createContextParamDecorator.js +0 -0
- /package/{helpers → dist/helpers}/createParamDecorator.d.ts +0 -0
- /package/{managers → dist/managers}/channel.d.ts +0 -0
- /package/{managers → dist/managers}/channel.js +0 -0
- /package/{managers → dist/managers}/channelInstance.d.ts +0 -0
- /package/{managers → dist/managers}/channelInstance.js +0 -0
- /package/{managers → dist/managers}/class.d.ts +0 -0
- /package/{managers → dist/managers}/class.js +0 -0
- /package/{managers → dist/managers}/connection.d.ts +0 -0
- /package/{managers → dist/managers}/connection.js +0 -0
- /package/{managers → dist/managers}/createMetadataManager.d.ts +0 -0
- /package/{managers → dist/managers}/createMetadataManager.js +0 -0
- /package/{managers → dist/managers}/endpoint.d.ts +0 -0
- /package/{managers → dist/managers}/endpoint.js +0 -0
- /package/{managers → dist/managers}/endpointInstance.d.ts +0 -0
- /package/{managers → dist/managers}/endpointInstance.js +0 -0
- /package/{managers → dist/managers}/event.d.ts +0 -0
- /package/{managers → dist/managers}/event.js +0 -0
- /package/{managers → dist/managers}/guards.d.ts +0 -0
- /package/{managers → dist/managers}/guards.js +0 -0
- /package/{managers → dist/managers}/handlers.d.ts +0 -0
- /package/{managers → dist/managers}/handlers.js +0 -0
- /package/{managers → dist/managers}/join.d.ts +0 -0
- /package/{managers → dist/managers}/join.js +0 -0
- /package/{managers → dist/managers}/leave.d.ts +0 -0
- /package/{managers → dist/managers}/leave.js +0 -0
- /package/{managers → dist/managers}/method.d.ts +0 -0
- /package/{managers → dist/managers}/method.js +0 -0
- /package/{managers → dist/managers}/outgoingEvent.js +0 -0
- /package/{managers → dist/managers}/parametres.d.ts +0 -0
- /package/{managers → dist/managers}/parametres.js +0 -0
- /package/{managers → dist/managers}/pipes.d.ts +0 -0
- /package/{managers → dist/managers}/pipes.js +0 -0
- /package/{managers → dist/managers}/property.d.ts +0 -0
- /package/{managers → dist/managers}/property.js +0 -0
- /package/{modules → dist/modules}/pondSocket.d.ts +0 -0
- /package/{types.js → dist/types.js} +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AnyPondSchema, AssignsOf, EventPayload, EventReplyPayload, EventsOf, JoinParamsOf, Params, PondEvent, PondMessage, PresenceOf, ServerActions, UserData } from '@eleven-am/pondsocket-common';
|
|
2
|
+
import { NestContext } from '../types';
|
|
3
|
+
export declare class Context<Schema extends AnyPondSchema = AnyPondSchema, Path extends string = string, EventName extends Extract<keyof EventsOf<Schema>, string> = Extract<keyof EventsOf<Schema>, string>> {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(context: NestContext<Schema, Path, EventName>, instance: any, propertyKey: string);
|
|
6
|
+
get joinContext(): import("@eleven-am/pondsocket").JoinContext<Path, Schema> | null;
|
|
7
|
+
get eventContext(): import("@eleven-am/pondsocket").EventContext<Path, Schema, EventName> | null;
|
|
8
|
+
get outgoingContext(): import("@eleven-am/pondsocket").OutgoingContext<Path, Schema, EventName, ServerActions.SYSTEM | ServerActions.BROADCAST | ServerActions.ERROR | ServerActions.CONNECT> | null;
|
|
9
|
+
get connectionContext(): import("@eleven-am/pondsocket").ConnectionContext<Path> | null;
|
|
10
|
+
get leaveEvent(): import("@eleven-am/pondsocket").LeaveEvent | null;
|
|
11
|
+
get payload(): EventPayload<EventsOf<Schema>, EventName> | EventReplyPayload<EventsOf<Schema>, EventName> | PondMessage | null;
|
|
12
|
+
get action(): ServerActions.BROADCAST | ServerActions.SYSTEM | ServerActions.ERROR | ServerActions.CONNECT | null;
|
|
13
|
+
get params(): Params<Path>;
|
|
14
|
+
get query(): Record<string, string>;
|
|
15
|
+
get joinParams(): JoinParamsOf<Schema> | null;
|
|
16
|
+
get presence(): PresenceOf<Schema>;
|
|
17
|
+
get assigns(): AssignsOf<Schema>;
|
|
18
|
+
get user(): UserData<PresenceOf<Schema>, AssignsOf<Schema>>;
|
|
19
|
+
get channel(): import("@eleven-am/pondsocket").Channel<AnyPondSchema> | null;
|
|
20
|
+
get event(): PondEvent<string> | null;
|
|
21
|
+
getClass(): any;
|
|
22
|
+
getHandler(): any;
|
|
23
|
+
getInstance(): any;
|
|
24
|
+
getMethod(): string;
|
|
25
|
+
accept(assigns?: Partial<AssignsOf<Schema>>): this;
|
|
26
|
+
decline(message?: string, status?: number): this;
|
|
27
|
+
assign(assigns: Partial<AssignsOf<Schema>>): this;
|
|
28
|
+
reply(payload: EventReplyPayload<EventsOf<Schema>, EventName>): this;
|
|
29
|
+
reply<Event extends Extract<keyof EventsOf<Schema>, string>>(event: Event, payload: EventReplyPayload<EventsOf<Schema>, Event>): this;
|
|
30
|
+
broadcast<Event extends Extract<keyof EventsOf<Schema>, string>>(event: Event, payload: EventPayload<EventsOf<Schema>, Event>): this;
|
|
31
|
+
broadcastFrom<Event extends Extract<keyof EventsOf<Schema>, string>>(event: Event, payload: EventPayload<EventsOf<Schema>, Event>): this;
|
|
32
|
+
broadcastTo<Event extends Extract<keyof EventsOf<Schema>, string>>(event: Event, payload: EventPayload<EventsOf<Schema>, Event>, users: string | string[]): this;
|
|
33
|
+
trackPresence(presence: PresenceOf<Schema>): this;
|
|
34
|
+
updatePresence(presence: Partial<PresenceOf<Schema>>): this;
|
|
35
|
+
evictUser(reason: string, userId?: string): this;
|
|
36
|
+
removePresence(userId?: string): this;
|
|
37
|
+
transform(payload: EventPayload<EventsOf<Schema>, EventName> | EventReplyPayload<EventsOf<Schema>, EventName>): this;
|
|
38
|
+
block(): this;
|
|
39
|
+
addData(key: string, value: unknown): void;
|
|
40
|
+
getData(key: string): {} | null;
|
|
41
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _Context_instances, _Context_data, _Context_context, _Context_instance, _Context_propertyKey, _Context_getChannelContext;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Context = void 0;
|
|
16
|
+
class Context {
|
|
17
|
+
constructor(context, instance, propertyKey) {
|
|
18
|
+
_Context_instances.add(this);
|
|
19
|
+
_Context_data.set(this, {});
|
|
20
|
+
_Context_context.set(this, void 0);
|
|
21
|
+
_Context_instance.set(this, void 0);
|
|
22
|
+
_Context_propertyKey.set(this, void 0);
|
|
23
|
+
__classPrivateFieldSet(this, _Context_context, context, "f");
|
|
24
|
+
__classPrivateFieldSet(this, _Context_instance, instance, "f");
|
|
25
|
+
__classPrivateFieldSet(this, _Context_propertyKey, propertyKey, "f");
|
|
26
|
+
}
|
|
27
|
+
get joinContext() {
|
|
28
|
+
var _a;
|
|
29
|
+
return (_a = __classPrivateFieldGet(this, _Context_context, "f").join) !== null && _a !== void 0 ? _a : null;
|
|
30
|
+
}
|
|
31
|
+
get eventContext() {
|
|
32
|
+
var _a;
|
|
33
|
+
return (_a = __classPrivateFieldGet(this, _Context_context, "f").event) !== null && _a !== void 0 ? _a : null;
|
|
34
|
+
}
|
|
35
|
+
get outgoingContext() {
|
|
36
|
+
var _a;
|
|
37
|
+
return (_a = __classPrivateFieldGet(this, _Context_context, "f").outgoing) !== null && _a !== void 0 ? _a : null;
|
|
38
|
+
}
|
|
39
|
+
get connectionContext() {
|
|
40
|
+
var _a;
|
|
41
|
+
return (_a = __classPrivateFieldGet(this, _Context_context, "f").connection) !== null && _a !== void 0 ? _a : null;
|
|
42
|
+
}
|
|
43
|
+
get leaveEvent() {
|
|
44
|
+
var _a;
|
|
45
|
+
return (_a = __classPrivateFieldGet(this, _Context_context, "f").leave) !== null && _a !== void 0 ? _a : null;
|
|
46
|
+
}
|
|
47
|
+
get payload() {
|
|
48
|
+
var _a, _b, _c, _d;
|
|
49
|
+
return (_d = (_b = (_a = this.eventContext) === null || _a === void 0 ? void 0 : _a.payload) !== null && _b !== void 0 ? _b : (_c = this.outgoingContext) === null || _c === void 0 ? void 0 : _c.payload) !== null && _d !== void 0 ? _d : null;
|
|
50
|
+
}
|
|
51
|
+
get action() {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
return (_b = (_a = this.outgoingContext) === null || _a === void 0 ? void 0 : _a.action) !== null && _b !== void 0 ? _b : null;
|
|
54
|
+
}
|
|
55
|
+
get params() {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
return ((_b = (_a = this.event) === null || _a === void 0 ? void 0 : _a.params) !== null && _b !== void 0 ? _b : {});
|
|
58
|
+
}
|
|
59
|
+
get query() {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
return (_b = (_a = this.event) === null || _a === void 0 ? void 0 : _a.query) !== null && _b !== void 0 ? _b : {};
|
|
62
|
+
}
|
|
63
|
+
get joinParams() {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
return (_b = (_a = this.joinContext) === null || _a === void 0 ? void 0 : _a.joinParams) !== null && _b !== void 0 ? _b : null;
|
|
66
|
+
}
|
|
67
|
+
get presence() {
|
|
68
|
+
return this.user.presence;
|
|
69
|
+
}
|
|
70
|
+
get assigns() {
|
|
71
|
+
return this.user.assigns;
|
|
72
|
+
}
|
|
73
|
+
get user() {
|
|
74
|
+
var _a, _b, _c, _d, _e;
|
|
75
|
+
if (this.connectionContext) {
|
|
76
|
+
const user = {
|
|
77
|
+
id: this.connectionContext.clientId,
|
|
78
|
+
assigns: {},
|
|
79
|
+
presence: {},
|
|
80
|
+
};
|
|
81
|
+
return user;
|
|
82
|
+
}
|
|
83
|
+
else if (this.leaveEvent) {
|
|
84
|
+
return this.leaveEvent.user;
|
|
85
|
+
}
|
|
86
|
+
const user = (_d = (_b = (_a = this.joinContext) === null || _a === void 0 ? void 0 : _a.user) !== null && _b !== void 0 ? _b : (_c = this.eventContext) === null || _c === void 0 ? void 0 : _c.user) !== null && _d !== void 0 ? _d : (_e = this.outgoingContext) === null || _e === void 0 ? void 0 : _e.user;
|
|
87
|
+
if (!user) {
|
|
88
|
+
throw new Error('PondSocket context does not contain a user');
|
|
89
|
+
}
|
|
90
|
+
return user;
|
|
91
|
+
}
|
|
92
|
+
get channel() {
|
|
93
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
94
|
+
return (_h = (_f = (_d = (_b = (_a = this.joinContext) === null || _a === void 0 ? void 0 : _a.channel) !== null && _b !== void 0 ? _b : (_c = this.eventContext) === null || _c === void 0 ? void 0 : _c.channel) !== null && _d !== void 0 ? _d : (_e = this.outgoingContext) === null || _e === void 0 ? void 0 : _e.channel) !== null && _f !== void 0 ? _f : (_g = this.leaveEvent) === null || _g === void 0 ? void 0 : _g.channel) !== null && _h !== void 0 ? _h : null;
|
|
95
|
+
}
|
|
96
|
+
get event() {
|
|
97
|
+
var _a, _b, _c, _d, _e, _f;
|
|
98
|
+
if (this.connectionContext) {
|
|
99
|
+
const event = {
|
|
100
|
+
params: this.connectionContext.params,
|
|
101
|
+
query: this.connectionContext.query,
|
|
102
|
+
payload: {},
|
|
103
|
+
event: 'CONNECTION',
|
|
104
|
+
};
|
|
105
|
+
return event;
|
|
106
|
+
}
|
|
107
|
+
return (_f = (_d = (_b = (_a = this.joinContext) === null || _a === void 0 ? void 0 : _a.event) !== null && _b !== void 0 ? _b : (_c = this.eventContext) === null || _c === void 0 ? void 0 : _c.event) !== null && _d !== void 0 ? _d : (_e = this.outgoingContext) === null || _e === void 0 ? void 0 : _e.event) !== null && _f !== void 0 ? _f : null;
|
|
108
|
+
}
|
|
109
|
+
getClass() {
|
|
110
|
+
return __classPrivateFieldGet(this, _Context_instance, "f").constructor;
|
|
111
|
+
}
|
|
112
|
+
getHandler() {
|
|
113
|
+
return __classPrivateFieldGet(this, _Context_instance, "f")[__classPrivateFieldGet(this, _Context_propertyKey, "f")];
|
|
114
|
+
}
|
|
115
|
+
getInstance() {
|
|
116
|
+
return __classPrivateFieldGet(this, _Context_instance, "f");
|
|
117
|
+
}
|
|
118
|
+
getMethod() {
|
|
119
|
+
return __classPrivateFieldGet(this, _Context_propertyKey, "f");
|
|
120
|
+
}
|
|
121
|
+
accept(assigns) {
|
|
122
|
+
var _a;
|
|
123
|
+
const context = (_a = this.joinContext) !== null && _a !== void 0 ? _a : this.connectionContext;
|
|
124
|
+
if (!context) {
|
|
125
|
+
throw new Error('accept() is only available for connection and join handlers');
|
|
126
|
+
}
|
|
127
|
+
context.accept(assigns);
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
decline(message, status) {
|
|
131
|
+
var _a;
|
|
132
|
+
const context = (_a = this.joinContext) !== null && _a !== void 0 ? _a : this.connectionContext;
|
|
133
|
+
if (!context) {
|
|
134
|
+
throw new Error('decline() is only available for connection and join handlers');
|
|
135
|
+
}
|
|
136
|
+
context.decline(message, status);
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
assign(assigns) {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
const context = (_b = (_a = this.joinContext) !== null && _a !== void 0 ? _a : this.eventContext) !== null && _b !== void 0 ? _b : this.connectionContext;
|
|
142
|
+
if (!context) {
|
|
143
|
+
throw new Error('assign() is not available for this handler');
|
|
144
|
+
}
|
|
145
|
+
context.assign(assigns);
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
reply(eventOrPayload, payload) {
|
|
149
|
+
var _a, _b;
|
|
150
|
+
const context = (_b = (_a = this.joinContext) !== null && _a !== void 0 ? _a : this.eventContext) !== null && _b !== void 0 ? _b : this.connectionContext;
|
|
151
|
+
if (!context) {
|
|
152
|
+
throw new Error('reply() is not available for this handler');
|
|
153
|
+
}
|
|
154
|
+
if (typeof eventOrPayload !== 'string') {
|
|
155
|
+
if (!this.eventContext) {
|
|
156
|
+
throw new Error('reply(payload) is only available for event handlers');
|
|
157
|
+
}
|
|
158
|
+
const replyToCurrentEvent = this.eventContext.reply.bind(this.eventContext);
|
|
159
|
+
replyToCurrentEvent(this.eventContext.event.event, eventOrPayload);
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
const reply = context.reply.bind(context);
|
|
163
|
+
reply(eventOrPayload, payload !== null && payload !== void 0 ? payload : {});
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
broadcast(event, payload) {
|
|
167
|
+
__classPrivateFieldGet(this, _Context_instances, "m", _Context_getChannelContext).call(this, 'broadcast').broadcast(event, payload);
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
broadcastFrom(event, payload) {
|
|
171
|
+
__classPrivateFieldGet(this, _Context_instances, "m", _Context_getChannelContext).call(this, 'broadcastFrom').broadcastFrom(event, payload);
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
broadcastTo(event, payload, users) {
|
|
175
|
+
__classPrivateFieldGet(this, _Context_instances, "m", _Context_getChannelContext).call(this, 'broadcastTo').broadcastTo(event, payload, users);
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
trackPresence(presence) {
|
|
179
|
+
var _a;
|
|
180
|
+
const context = (_a = this.joinContext) !== null && _a !== void 0 ? _a : this.eventContext;
|
|
181
|
+
if (!context) {
|
|
182
|
+
throw new Error('trackPresence() is only available for join and event handlers');
|
|
183
|
+
}
|
|
184
|
+
context.trackPresence(presence);
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
updatePresence(presence) {
|
|
188
|
+
if (!this.eventContext) {
|
|
189
|
+
throw new Error('updatePresence() is only available for event handlers');
|
|
190
|
+
}
|
|
191
|
+
this.eventContext.updatePresence(presence);
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
evictUser(reason, userId) {
|
|
195
|
+
if (!this.eventContext) {
|
|
196
|
+
throw new Error('evictUser() is only available for event handlers');
|
|
197
|
+
}
|
|
198
|
+
this.eventContext.evictUser(reason, userId);
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
removePresence(userId) {
|
|
202
|
+
if (!this.eventContext) {
|
|
203
|
+
throw new Error('removePresence() is only available for event handlers');
|
|
204
|
+
}
|
|
205
|
+
this.eventContext.removePresence(userId);
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
transform(payload) {
|
|
209
|
+
if (!this.outgoingContext) {
|
|
210
|
+
throw new Error('transform() is only available for outgoing handlers');
|
|
211
|
+
}
|
|
212
|
+
this.outgoingContext.transform(payload);
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
block() {
|
|
216
|
+
if (!this.outgoingContext) {
|
|
217
|
+
throw new Error('block() is only available for outgoing handlers');
|
|
218
|
+
}
|
|
219
|
+
this.outgoingContext.block();
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
addData(key, value) {
|
|
223
|
+
__classPrivateFieldGet(this, _Context_data, "f")[key] = value;
|
|
224
|
+
}
|
|
225
|
+
getData(key) {
|
|
226
|
+
var _a;
|
|
227
|
+
return (_a = __classPrivateFieldGet(this, _Context_data, "f")[key]) !== null && _a !== void 0 ? _a : null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
exports.Context = Context;
|
|
231
|
+
_Context_data = new WeakMap(), _Context_context = new WeakMap(), _Context_instance = new WeakMap(), _Context_propertyKey = new WeakMap(), _Context_instances = new WeakSet(), _Context_getChannelContext = function _Context_getChannelContext(method) {
|
|
232
|
+
var _a;
|
|
233
|
+
const context = (_a = this.joinContext) !== null && _a !== void 0 ? _a : this.eventContext;
|
|
234
|
+
if (!context) {
|
|
235
|
+
throw new Error(`${method}() is only available for join and event handlers`);
|
|
236
|
+
}
|
|
237
|
+
return context;
|
|
238
|
+
};
|
|
@@ -19,10 +19,10 @@ function OnConnectionRequest() {
|
|
|
19
19
|
const { set } = (0, connection_1.manageConnection)(target);
|
|
20
20
|
set('', (instance, moduleRef, globalGuards, globalPipes, ctx) => __awaiter(this, void 0, void 0, function* () {
|
|
21
21
|
try {
|
|
22
|
-
yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, ctx);
|
|
22
|
+
yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, ctx, 'connection');
|
|
23
23
|
}
|
|
24
24
|
catch (error) {
|
|
25
|
-
(0, errors_1.performErrors)(error, ctx);
|
|
25
|
+
(0, errors_1.performErrors)(error, ctx, 'connection');
|
|
26
26
|
}
|
|
27
27
|
}));
|
|
28
28
|
};
|
|
@@ -19,10 +19,10 @@ function OnEvent(event = '*') {
|
|
|
19
19
|
const { set } = (0, event_1.manageEvent)(target);
|
|
20
20
|
set(event, (instance, moduleRef, globalGuards, globalPipes, ctx) => __awaiter(this, void 0, void 0, function* () {
|
|
21
21
|
try {
|
|
22
|
-
yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, ctx);
|
|
22
|
+
yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, ctx, 'event');
|
|
23
23
|
}
|
|
24
24
|
catch (error) {
|
|
25
|
-
(0, errors_1.performErrors)(error, ctx);
|
|
25
|
+
(0, errors_1.performErrors)(error, ctx, 'event');
|
|
26
26
|
}
|
|
27
27
|
}));
|
|
28
28
|
};
|
|
@@ -19,10 +19,10 @@ function OnJoinRequest() {
|
|
|
19
19
|
const { set } = (0, join_1.manageJoin)(target);
|
|
20
20
|
set('', (instance, moduleRef, globalGuards, globalPipes, ctx) => __awaiter(this, void 0, void 0, function* () {
|
|
21
21
|
try {
|
|
22
|
-
yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, ctx);
|
|
22
|
+
yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, ctx, 'join');
|
|
23
23
|
}
|
|
24
24
|
catch (error) {
|
|
25
|
-
(0, errors_1.performErrors)(error, ctx);
|
|
25
|
+
(0, errors_1.performErrors)(error, ctx, 'join');
|
|
26
26
|
}
|
|
27
27
|
}));
|
|
28
28
|
};
|
|
@@ -10,20 +10,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.OnLeave = OnLeave;
|
|
13
|
-
const common_1 = require("@nestjs/common");
|
|
14
13
|
const leave_1 = require("../managers/leave");
|
|
15
14
|
const action_1 = require("../performers/action");
|
|
16
|
-
const
|
|
15
|
+
const errors_1 = require("../performers/errors");
|
|
17
16
|
function OnLeave() {
|
|
18
17
|
return (target, propertyKey, descriptor) => {
|
|
19
18
|
const originalMethod = descriptor.value;
|
|
20
19
|
const { set } = (0, leave_1.manageLeave)(target);
|
|
21
20
|
set('', (instance, moduleRef, globalGuards, globalPipes, leaveEvent) => __awaiter(this, void 0, void 0, function* () {
|
|
22
21
|
try {
|
|
23
|
-
yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, leaveEvent);
|
|
22
|
+
yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, leaveEvent, 'leave');
|
|
24
23
|
}
|
|
25
24
|
catch (err) {
|
|
26
|
-
|
|
25
|
+
(0, errors_1.logHandlerError)(err, 'leave', propertyKey);
|
|
27
26
|
}
|
|
28
27
|
}));
|
|
29
28
|
};
|
|
@@ -11,12 +11,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.OnOutgoingEvent = OnOutgoingEvent;
|
|
13
13
|
const outgoingEvent_1 = require("../managers/outgoingEvent");
|
|
14
|
+
const action_1 = require("../performers/action");
|
|
15
|
+
const errors_1 = require("../performers/errors");
|
|
14
16
|
function OnOutgoingEvent(event = '*') {
|
|
15
17
|
return (target, propertyKey, descriptor) => {
|
|
16
18
|
const originalMethod = descriptor.value;
|
|
17
19
|
const { set } = (0, outgoingEvent_1.manageOutgoingEvent)(target);
|
|
18
|
-
set(event, (instance,
|
|
19
|
-
|
|
20
|
+
set(event, (instance, moduleRef, globalGuards, globalPipes, ctx) => __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
try {
|
|
22
|
+
yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, ctx, 'outgoing');
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
(0, errors_1.logHandlerError)(error, 'outgoing', propertyKey);
|
|
26
|
+
ctx.block();
|
|
27
|
+
}
|
|
20
28
|
}));
|
|
21
29
|
};
|
|
22
30
|
}
|
|
@@ -19,9 +19,9 @@ function wrapTransform(metadata, data, handler) {
|
|
|
19
19
|
const value = yield handler(data, context, metadata);
|
|
20
20
|
const classTransforms = (0, pipes_1.managePipes)(context.getClass()).get();
|
|
21
21
|
const methodTransforms = (0, pipes_1.managePipes)(context.getInstance(), context.getMethod()).get();
|
|
22
|
-
const transformers = globalPipes
|
|
22
|
+
const transformers = yield Promise.all(globalPipes
|
|
23
23
|
.concat(classTransforms, methodTransforms)
|
|
24
|
-
.map((Transformer) => (0, misc_1.retrieveInstance)(moduleRef, Transformer));
|
|
24
|
+
.map((Transformer) => (0, misc_1.retrieveInstance)(moduleRef, Transformer)));
|
|
25
25
|
const argumentMetadata = {
|
|
26
26
|
metatype: metadata,
|
|
27
27
|
type: 'body',
|
|
@@ -36,7 +36,8 @@ function wrapTransform(metadata, data, handler) {
|
|
|
36
36
|
function createParamDecorator(callback) {
|
|
37
37
|
return (data) => (target, propertyKey, index) => {
|
|
38
38
|
const { set } = (0, parametres_1.manageParameters)(target, propertyKey);
|
|
39
|
-
const
|
|
39
|
+
const parameterTypes = Reflect.getMetadata('design:paramtypes', target, propertyKey);
|
|
40
|
+
const type = parameterTypes === null || parameterTypes === void 0 ? void 0 : parameterTypes[index];
|
|
40
41
|
set(index, wrapTransform(type, data, callback));
|
|
41
42
|
};
|
|
42
43
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ModuleRef } from '@nestjs/core';
|
|
2
2
|
import { Constructor } from '../types';
|
|
3
|
-
export declare function retrieveInstance<Interface>(moduleRef: ModuleRef,
|
|
3
|
+
export declare function retrieveInstance<Interface>(moduleRef: ModuleRef, Type: Constructor<Interface>): Promise<Interface>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.retrieveInstance = retrieveInstance;
|
|
13
|
+
function retrieveInstance(moduleRef, Type) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
try {
|
|
16
|
+
return moduleRef.get(Type, { strict: false });
|
|
17
|
+
}
|
|
18
|
+
catch (_a) {
|
|
19
|
+
try {
|
|
20
|
+
return yield moduleRef.resolve(Type, undefined, { strict: false });
|
|
21
|
+
}
|
|
22
|
+
catch (_b) {
|
|
23
|
+
throw new Error(`Unable to resolve ${Type.name}. Register it in the PondSocketModule providers array.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './decorators';
|
|
2
|
+
export * from './modules/pondSocket';
|
|
3
|
+
export * from './services/pondSocket';
|
|
4
|
+
export * from './helpers/createParamDecorator';
|
|
5
|
+
export { Context } from './context/context';
|
|
6
|
+
export type { AsyncFactoryResult, AsyncMetadata, CanActivate, Constructor, Metadata, NestContext, ParamDecoratorCallback, PondEventContext, PondEventHandler, PondEventPayload, PondCoreEventContext, PondCoreJoinContext, PondCoreOutgoingContext, PondConnectionContext, PondJoinContext, PondOutgoingContext, PondResponse, PondResponseFor, PondSchemaAssigns, PondSchemaPresence, } from './types';
|
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.Context = void 0;
|
|
18
18
|
__exportStar(require("./decorators"), exports);
|
|
19
19
|
__exportStar(require("./modules/pondSocket"), exports);
|
|
20
|
+
__exportStar(require("./services/pondSocket"), exports);
|
|
20
21
|
__exportStar(require("./helpers/createParamDecorator"), exports);
|
|
21
22
|
var context_1 = require("./context/context");
|
|
22
23
|
Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.Context; } });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { OutgoingContext } from '@eleven-am/pondsocket/types';
|
|
2
|
+
export declare function manageOutgoingEvent(target: unknown): {
|
|
3
|
+
get(): import("../types").HandlerData<OutgoingContext<string, import("@eleven-am/pondsocket/types").AnyPondSchema, string, import("@eleven-am/pondsocket/types").ServerActions.SYSTEM | import("@eleven-am/pondsocket/types").ServerActions.BROADCAST | import("@eleven-am/pondsocket/types").ServerActions.ERROR | import("@eleven-am/pondsocket/types").ServerActions.CONNECT>>[];
|
|
4
|
+
set(path: string, value: import("../types").HandlerFunction<OutgoingContext<string, import("@eleven-am/pondsocket/types").AnyPondSchema, string, import("@eleven-am/pondsocket/types").ServerActions.SYSTEM | import("@eleven-am/pondsocket/types").ServerActions.BROADCAST | import("@eleven-am/pondsocket/types").ServerActions.ERROR | import("@eleven-am/pondsocket/types").ServerActions.CONNECT>>): void;
|
|
5
|
+
};
|
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.PondSocketModule = void 0;
|
|
13
|
-
const nestjs_discovery_1 = require("@golevelup/nestjs-discovery");
|
|
14
13
|
const core_1 = require("@nestjs/core");
|
|
15
14
|
const guards_1 = require("../managers/guards");
|
|
16
15
|
const pipes_1 = require("../managers/pipes");
|
|
@@ -23,7 +22,7 @@ class PondSocketModule {
|
|
|
23
22
|
var _a, _b, _c;
|
|
24
23
|
return new pondSocket_1.PondSocketService(moduleRef, discovery, adapterHost, (_a = metadata.guards) !== null && _a !== void 0 ? _a : [], (_b = metadata.pipes) !== null && _b !== void 0 ? _b : [], (_c = metadata.isExclusiveSocketServer) !== null && _c !== void 0 ? _c : false, metadata.backend, metadata.maxMessageSize, metadata.heartbeatInterval);
|
|
25
24
|
},
|
|
26
|
-
inject: [core_1.ModuleRef, core_1.HttpAdapterHost,
|
|
25
|
+
inject: [core_1.ModuleRef, core_1.HttpAdapterHost, core_1.DiscoveryService],
|
|
27
26
|
};
|
|
28
27
|
return this.buildModule(pondSocketProvider, metadata);
|
|
29
28
|
}
|
|
@@ -35,7 +34,7 @@ class PondSocketModule {
|
|
|
35
34
|
const resolvedMetadata = yield metadata.useFactory(...args);
|
|
36
35
|
return new pondSocket_1.PondSocketService(moduleRef, discovery, adapterHost, (_a = metadata.guards) !== null && _a !== void 0 ? _a : [], (_b = metadata.pipes) !== null && _b !== void 0 ? _b : [], (_c = metadata.isExclusiveSocketServer) !== null && _c !== void 0 ? _c : false, resolvedMetadata.backend, resolvedMetadata.maxMessageSize, resolvedMetadata.heartbeatInterval);
|
|
37
36
|
}),
|
|
38
|
-
inject: [core_1.ModuleRef, core_1.HttpAdapterHost,
|
|
37
|
+
inject: [core_1.ModuleRef, core_1.HttpAdapterHost, core_1.DiscoveryService, ...(metadata.inject || [])],
|
|
39
38
|
};
|
|
40
39
|
return this.buildModule(pondSocketProvider, metadata);
|
|
41
40
|
}
|
|
@@ -45,9 +44,9 @@ class PondSocketModule {
|
|
|
45
44
|
pipes = [...new Set([...localPipes, ...pipes])];
|
|
46
45
|
guards = [...new Set([...localGuards, ...guards])];
|
|
47
46
|
return {
|
|
48
|
-
exports,
|
|
47
|
+
exports: [pondSocket_1.PondSocketService, ...exports],
|
|
49
48
|
global: isGlobal,
|
|
50
|
-
imports: [...imports,
|
|
49
|
+
imports: [...imports, core_1.DiscoveryModule],
|
|
51
50
|
module: PondSocketModule,
|
|
52
51
|
providers: [
|
|
53
52
|
provider,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AnyPondChannelDefinition, ConnectionContext, EventContext, JoinContext, LeaveEvent, OutgoingContext, PondEndpointDefinition } from '@eleven-am/pondsocket/types';
|
|
2
|
+
import type { PipeTransform } from '@nestjs/common';
|
|
3
|
+
import type { ModuleRef } from '@nestjs/core';
|
|
4
|
+
import { CanActivate, Constructor, PondLifecycle, PondResponse } from '../types';
|
|
5
|
+
type HandlerInput = LeaveEvent | JoinContext<string> | EventContext<string> | ConnectionContext<string> | OutgoingContext<string>;
|
|
6
|
+
type HandlerDefinition = AnyPondChannelDefinition | PondEndpointDefinition;
|
|
7
|
+
export declare function performAction(instance: any, moduleRef: ModuleRef, globalGuards: Constructor<CanActivate>[], globalPipes: Constructor<PipeTransform>[], originalMethod: (...args: any[]) => Promise<PondResponse | null | undefined | void> | PondResponse | null | undefined | void, propertyKey: string, input: HandlerInput, lifecycle: PondLifecycle, activeDefinition?: HandlerDefinition): Promise<void>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.performAction = performAction;
|
|
13
|
+
const pondsocket_common_1 = require("@eleven-am/pondsocket-common");
|
|
14
|
+
const context_1 = require("../context/context");
|
|
15
|
+
const misc_1 = require("../helpers/misc");
|
|
16
|
+
const guards_1 = require("../managers/guards");
|
|
17
|
+
const parametres_1 = require("../managers/parametres");
|
|
18
|
+
const response_1 = require("./response");
|
|
19
|
+
function retrieveParameters(context, globalPipes, moduleRef, activeDefinition) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
const managedParameters = (0, parametres_1.manageParameters)(context.getInstance(), context.getMethod()).get();
|
|
23
|
+
const boundParameters = ((_a = (0, pondsocket_common_1.getPondMetadata)(context.getInstance(), pondsocket_common_1.pondParameterMetadataKey)) !== null && _a !== void 0 ? _a : []).filter(({ propertyKey }) => propertyKey === context.getMethod());
|
|
24
|
+
boundParameters.forEach(({ definition }) => {
|
|
25
|
+
if (definition !== activeDefinition) {
|
|
26
|
+
throw new Error(`${context.getClass().name}.${context.getMethod()} uses GetContext() from a different PondSocket definition`);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const parameters = [
|
|
30
|
+
...managedParameters,
|
|
31
|
+
...boundParameters.map(({ index }) => ({
|
|
32
|
+
index,
|
|
33
|
+
callback: () => Promise.resolve(context),
|
|
34
|
+
})),
|
|
35
|
+
];
|
|
36
|
+
const decoratedIndices = new Set(parameters.map(({ index }) => index));
|
|
37
|
+
if (decoratedIndices.size !== parameters.length) {
|
|
38
|
+
throw new Error(`${context.getClass().name}.${context.getMethod()} has multiple PondSocket decorators on the same parameter`);
|
|
39
|
+
}
|
|
40
|
+
const reflectedTypes = Reflect.getMetadata('design:paramtypes', context.getInstance(), context.getMethod());
|
|
41
|
+
const highestDecoratedIndex = parameters.reduce((highest, { index }) => Math.max(highest, index), -1);
|
|
42
|
+
const parameterCount = Math.max((_b = reflectedTypes === null || reflectedTypes === void 0 ? void 0 : reflectedTypes.length) !== null && _b !== void 0 ? _b : 0, context.getHandler().length, highestDecoratedIndex + 1);
|
|
43
|
+
for (let index = 0; index < parameterCount; index++) {
|
|
44
|
+
if (!decoratedIndices.has(index)) {
|
|
45
|
+
throw new Error(`${context.getClass().name}.${context.getMethod()} parameter at index ${index} must use a PondSocket parameter decorator`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const values = Array.from({ length: parameterCount });
|
|
49
|
+
const resolved = yield Promise.all(parameters.map((_a) => __awaiter(this, [_a], void 0, function* ({ callback, index }) {
|
|
50
|
+
return ({
|
|
51
|
+
index,
|
|
52
|
+
value: yield callback(context, globalPipes, moduleRef),
|
|
53
|
+
});
|
|
54
|
+
})));
|
|
55
|
+
resolved.forEach(({ index, value }) => {
|
|
56
|
+
values[index] = value;
|
|
57
|
+
});
|
|
58
|
+
return values;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function performGuards(moduleRef, globalGuards, context) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const classGuards = (0, guards_1.manageGuards)(context.getClass()).get();
|
|
64
|
+
const methodGuards = (0, guards_1.manageGuards)(context.getInstance(), context.getMethod()).get();
|
|
65
|
+
const guards = yield Promise.all(globalGuards
|
|
66
|
+
.concat(classGuards, methodGuards)
|
|
67
|
+
.map((Guard) => (0, misc_1.retrieveInstance)(moduleRef, Guard)));
|
|
68
|
+
for (const guard of guards) {
|
|
69
|
+
if (!(yield guard.canActivate(context))) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function getNestContext(context, lifecycle) {
|
|
77
|
+
switch (lifecycle) {
|
|
78
|
+
case 'connection':
|
|
79
|
+
return { connection: context };
|
|
80
|
+
case 'join':
|
|
81
|
+
return { join: context };
|
|
82
|
+
case 'event':
|
|
83
|
+
return { event: context };
|
|
84
|
+
case 'outgoing':
|
|
85
|
+
return { outgoing: context };
|
|
86
|
+
case 'leave':
|
|
87
|
+
return { leave: context };
|
|
88
|
+
default:
|
|
89
|
+
throw new Error(`Unsupported PondSocket lifecycle: ${String(lifecycle)}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function rejectGuard(input, lifecycle) {
|
|
93
|
+
if (lifecycle === 'join' || lifecycle === 'connection') {
|
|
94
|
+
input.decline('Unauthorized', 403);
|
|
95
|
+
}
|
|
96
|
+
else if (lifecycle === 'event') {
|
|
97
|
+
input.reply(pondsocket_common_1.ErrorTypes.UNAUTHORIZED_BROADCAST, {
|
|
98
|
+
code: pondsocket_common_1.ErrorTypes.UNAUTHORIZED_BROADCAST,
|
|
99
|
+
message: 'Unauthorized',
|
|
100
|
+
status: 403,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
else if (lifecycle === 'outgoing') {
|
|
104
|
+
input.block();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function performAction(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, input, lifecycle, activeDefinition) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const context = new context_1.Context(getNestContext(input, lifecycle), instance, propertyKey);
|
|
110
|
+
const canProceed = yield performGuards(moduleRef, globalGuards, context);
|
|
111
|
+
if (!canProceed) {
|
|
112
|
+
rejectGuard(input, lifecycle);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const data = yield originalMethod.apply(instance, yield retrieveParameters(context, globalPipes, moduleRef, activeDefinition));
|
|
116
|
+
if (lifecycle === 'outgoing') {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
(0, response_1.performResponse)(context.user.id, context.channel, data, input, lifecycle);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ConnectionContext, EventContext, JoinContext } from '@eleven-am/pondsocket/types';
|
|
2
|
+
import { PondLifecycle } from '../types';
|
|
3
|
+
export declare function performErrors(error: unknown, response: ConnectionContext<string> | JoinContext<string> | EventContext<string>, lifecycle: 'connection' | 'join' | 'event'): EventContext<string, import("@eleven-am/pondsocket-common").AnyPondSchema, string> | JoinContext<string, import("@eleven-am/pondsocket-common").AnyPondSchema> | ConnectionContext<string> | undefined;
|
|
4
|
+
export declare function logHandlerError(error: unknown, lifecycle: PondLifecycle, propertyKey: string | symbol): void;
|