Skip to content

Commit

Permalink
Merge branch 'feat/deno-runtime' into deno/logger
Browse files Browse the repository at this point in the history
  • Loading branch information
d-gubert authored Nov 28, 2023
2 parents af94a9e + f7e0eb1 commit 43f684f
Show file tree
Hide file tree
Showing 1,106 changed files with 176,945 additions and 178,810 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
push:
branches:
- 'alpha'
- 'beta'

jobs:
prepare:
Expand Down
8 changes: 4 additions & 4 deletions deno-runtime/lib/accessors/_test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { beforeEach, describe, it } from 'https://deno.land/[email protected]/testing/bdd.ts';
import { assertEquals } from "https://deno.land/[email protected]/assert/assert_equals.ts";

import { AppAccessors, getProxify } from "./mod.ts";
import { AppAccessors } from "./mod.ts";
import { AppObjectRegistry } from "../../AppObjectRegistry.ts";

describe('AppAccessors', () => {
let appAccessors: AppAccessors;
const proxify = getProxify((r) => Promise.resolve({
const senderFn = (r: object) => Promise.resolve({
id: Math.random().toString(36).substring(2),
jsonrpc: '2.0',
result: r,
serialize() {
return JSON.stringify(this);
}
}));
});

beforeEach(() => {
appAccessors = new AppAccessors(proxify);
appAccessors = new AppAccessors(senderFn);
AppObjectRegistry.clear();
});

Expand Down
64 changes: 41 additions & 23 deletions deno-runtime/lib/accessors/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,9 @@ import type { IApi } from '@rocket.chat/apps-engine/definition/api/IApi.ts';
import type { IVideoConfProvider } from '@rocket.chat/apps-engine/definition/videoConfProviders/IVideoConfProvider.ts';

import * as Messenger from '../messenger.ts';
import { AppObjectRegistry } from "../../AppObjectRegistry.ts";

export const getProxify = (call: typeof Messenger.sendRequest) =>
function proxify<T>(namespace: string): T {
return new Proxy(
{ __kind: namespace }, // debugging purposes
{
get:
(_target: unknown, prop: string) =>
(...params: unknown[]) =>
call({
method: `accessor:${namespace}:${prop}`,
params,
}),
},
) as T;
};
import { AppObjectRegistry } from '../../AppObjectRegistry.ts';

const httpMethods = ['get', 'post', 'put', 'delete', 'head', 'options', 'patch'] as const;

export class AppAccessors {
private defaultAppAccessors?: IAppAccessors;
Expand All @@ -43,7 +29,23 @@ export class AppAccessors {
private persistence?: IPersistence;
private http?: IHttp;

constructor(private readonly proxify: <T>(n: string) => T) {}
private proxify: <T>(namespace: string) => T;

constructor(senderFn: typeof Messenger.sendRequest) {
this.proxify = <T>(namespace: string): T =>
new Proxy(
{ __kind: namespace },
{
get:
(_target: unknown, prop: string) =>
(...params: unknown[]) =>
senderFn({
method: `accessor:${namespace}:${prop}`,
params,
}),
},
) as T;
}

public getEnvironmentRead(): IEnvironmentRead {
if (!this.environmentRead) {
Expand Down Expand Up @@ -72,7 +74,21 @@ export class AppAccessors {
if (!this.configModifier) {
this.configModifier = {
scheduler: this.proxify('getConfigurationModify:scheduler'),
slashCommands: this.proxify('getConfigurationModify:slashCommands'),
slashCommands: {
_proxy: this.proxify('getConfigurationModify:slashCommands'),
modifySlashCommand(slashcommand: ISlashCommand) {
// Store the slashcommand instance to use when the Apps-Engine calls the slashcommand
AppObjectRegistry.set(`slashcommand:${slashcommand.command}`, slashcommand);

return this._proxy.modifySlashCommand(slashcommand);
},
disableSlashCommand(command: string) {
return this._proxy.disableSlashCommand(command);
},
enableSlashCommand(command: string) {
return this._proxy.enableSlashCommand(command);
},
},
serverSettings: this.proxify('getConfigurationModify:serverSettings'),
};
}
Expand All @@ -92,6 +108,8 @@ export class AppAccessors {
provideApi(api: IApi) {
api.endpoints.forEach((endpoint) => {
AppObjectRegistry.set(`api:${endpoint.path}`, endpoint);

endpoint._availableMethods = httpMethods.filter((method) => typeof endpoint[method] === 'function');
});

return this._proxy.provideApi(api);
Expand Down Expand Up @@ -124,8 +142,8 @@ export class AppAccessors {
AppObjectRegistry.set(`slashcommand:${slashcommand.command}`, slashcommand);

return this._proxy.provideSlashCommand(slashcommand);
}
}
},
},
};
}

Expand All @@ -139,7 +157,7 @@ export class AppAccessors {
environmentWriter: this.getEnvironmentWrite(),
reader: this.getReader(),
http: this.getHttp(),
providedApiEndpoints: this.proxify('providedApiEndpoints'),
providedApiEndpoints: this.proxify('api:listApis'),
};
}

Expand Down Expand Up @@ -207,4 +225,4 @@ export class AppAccessors {
}
}

export const AppAccessorsInstance = new AppAccessors(getProxify(Messenger.sendRequest.bind(Messenger)));
export const AppAccessorsInstance = new AppAccessors(Messenger.sendRequest);
2 changes: 1 addition & 1 deletion docs/assets/search.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/classes/App.App.html
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,6 @@ <h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="#icon
<li><a href="../modules/slashcommands_ISlashCommandPreview.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>slashcommands/ISlash<wbr/>Command<wbr/>Preview</span></a></li>
<li><a href="../modules/slashcommands_SlashCommandContext.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>slashcommands/<wbr/>Slash<wbr/>Command<wbr/>Context</span></a></li>
<li><a href="../modules/ui.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>ui</span></a></li>
<li><a href="../modules/ui_IToastMessagePaylaod.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>ui/IToast<wbr/>Message<wbr/>Paylaod</span></a></li>
<li><a href="../modules/ui_IUIActionButtonDescriptor.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>ui/IUIAction<wbr/>Button<wbr/>Descriptor</span></a></li>
<li><a href="../modules/ui_UIActionButtonContext.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>ui/UIAction<wbr/>Button<wbr/>Context</span></a></li>
<li><a href="../modules/uikit.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>uikit</span></a></li>
Expand Down
Loading

0 comments on commit 43f684f

Please sign in to comment.