Skip to content

Commit

Permalink
Fix #67
Browse files Browse the repository at this point in the history
  • Loading branch information
Vorlias committed May 17, 2022
1 parent 0f47dfc commit 6822795
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "@rbxts/net",
"version": "3.0.1",
"version": "3.0.2",
"description": "",
"main": "out/init.lua",
"scripts": {
"prepare": "npm run build",
"yalc": "npm run build && yalc push",
"build": "cross-env NODE_ENV=production rbxtsc --verbose",
"build:luau": "cross-env NODE_ENV=production TYPE=Luau rbxtsc --verbose --type=model --rojo=\"luau/build.project.json\"",
"build:docs": "cd docs && npm run build",
Expand Down
50 changes: 25 additions & 25 deletions src/definitions/ServerDefinitionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,21 @@ export class ServerDefinitionBuilder<T extends RemoteDeclarations> {
* The generated remote id is based off the current namespace.
*/

const namespacedId = this.namespace !== NAMESPACE_ROOT ? [this.namespace, id].join(NAMESPACE_SEPARATOR) : id;

if (declaration.Type === "Function") {
let func: ServerFunction;

if (remoteFunctionCache.has(id)) {
return remoteFunctionCache.get(id)!;
if (remoteFunctionCache.has(namespacedId)) {
return remoteFunctionCache.get(namespacedId)!;
} else {
if (declaration.ServerMiddleware) {
func = new ServerFunction(id, declaration.ServerMiddleware);
func = new ServerFunction(namespacedId, declaration.ServerMiddleware);
} else {
func = new ServerFunction(id);
func = new ServerFunction(namespacedId);
}
CollectionService.AddTag(func.GetInstance(), TagId.DefinitionManaged);
remoteFunctionCache.set(id, func);
remoteFunctionCache.set(namespacedId, func);

this.globalMiddleware?.forEach((mw) => func._use(mw));
return func;
Expand All @@ -116,16 +118,16 @@ export class ServerDefinitionBuilder<T extends RemoteDeclarations> {
let asyncFunction: ServerAsyncFunction;

// This should make certain use cases cheaper
if (remoteAsyncFunctionCache.has(id)) {
return remoteAsyncFunctionCache.get(id)!;
if (remoteAsyncFunctionCache.has(namespacedId)) {
return remoteAsyncFunctionCache.get(namespacedId)!;
} else {
if (declaration.ServerMiddleware) {
asyncFunction = new ServerAsyncFunction(id, declaration.ServerMiddleware);
asyncFunction = new ServerAsyncFunction(namespacedId, declaration.ServerMiddleware);
} else {
asyncFunction = new ServerAsyncFunction(id);
asyncFunction = new ServerAsyncFunction(namespacedId);
}
CollectionService.AddTag(asyncFunction.GetInstance(), TagId.DefinitionManaged);
remoteAsyncFunctionCache.set(id, asyncFunction);
remoteAsyncFunctionCache.set(namespacedId, asyncFunction);
}

this.globalMiddleware?.forEach((mw) => asyncFunction._use(mw));
Expand All @@ -134,37 +136,37 @@ export class ServerDefinitionBuilder<T extends RemoteDeclarations> {
let event: ServerEvent;

// This should make certain use cases cheaper
if (remoteEventCache.has(id)) {
return remoteEventCache.get(id)!;
if (remoteEventCache.has(namespacedId)) {
return remoteEventCache.get(namespacedId)!;
} else {
if (declaration.ServerMiddleware) {
event = new ServerEvent(id, declaration.ServerMiddleware);
event = new ServerEvent(namespacedId, declaration.ServerMiddleware);
} else {
event = new ServerEvent(id);
event = new ServerEvent(namespacedId);
}
CollectionService.AddTag(event.GetInstance(), TagId.DefinitionManaged);
remoteEventCache.set(id, event);
remoteEventCache.set(namespacedId, event);
}

this.globalMiddleware?.forEach((mw) => event._use(mw));
return event;
} else if (declaration.Type === "Messaging") {
let event: ExperienceBroadcastEvent;
if (messagingEventCache.has(id)) {
return messagingEventCache.get(id)!;
if (messagingEventCache.has(namespacedId)) {
return messagingEventCache.get(namespacedId)!;
} else {
event = new ExperienceBroadcastEvent(id);
messagingEventCache.set(id, event);
event = new ExperienceBroadcastEvent(namespacedId);
messagingEventCache.set(namespacedId, event);
}

return event;
} else if (declaration.Type === "ExperienceEvent") {
let event: ServerMessagingEvent;
if (messagingServerEventCache.has(id)) {
return messagingServerEventCache.get(id)!;
if (messagingServerEventCache.has(namespacedId)) {
return messagingServerEventCache.get(namespacedId)!;
} else {
event = new ServerMessagingEvent(id);
messagingServerEventCache.set(id, event);
event = new ServerMessagingEvent(namespacedId);
messagingServerEventCache.set(namespacedId, event);
}
return event;
} else {
Expand Down Expand Up @@ -257,8 +259,6 @@ export class ServerDefinitionBuilder<T extends RemoteDeclarations> {
*/
public Get<K extends keyof FilterServerDeclarations<T> & string>(remoteId: K): InferServerRemote<T[K]> {
const item = declarationMap.get(this)![remoteId];
remoteId =
this.namespace !== NAMESPACE_ROOT ? ([this.namespace, remoteId].join(NAMESPACE_SEPARATOR) as K) : remoteId;
assert(item && item.Type, `'${remoteId}' is not defined in this definition.`);
if (
item.Type === "Function" ||
Expand Down

0 comments on commit 6822795

Please sign in to comment.