diff --git a/packages/example-app/app.ts b/packages/example-app/app.ts index 27c500ce5..5ef767868 100755 --- a/packages/example-app/app.ts +++ b/packages/example-app/app.ts @@ -10,8 +10,7 @@ import { RpcController } from './src/controller/rpc.controller.js'; import { ApiConsoleModule } from '@deepkit/api-console-module'; import { OrmBrowserModule } from '@deepkit/orm-browser-module'; import { OpenAPIModule } from 'deepkit-openapi'; -import { provideStorage } from '@deepkit/filesystem/dist/cjs/src/storage.js'; -import { StorageLocalAdapter } from '@deepkit/filesystem/dist/cjs/src/local-adapter.js'; +import { FilesystemLocalAdapter, provideFilesystem } from '@deepkit/filesystem'; const bookStoreCrud = createCrudRoutes([Author, Book]); @@ -19,7 +18,7 @@ new App({ config: Config, providers: [ SQLiteDatabase, MainController, - provideStorage(() => new StorageLocalAdapter({root: 'public'})), + provideFilesystem(() => new FilesystemLocalAdapter({ root: __dirname + '/public' })), ], controllers: [MainController, UsersCommand, RpcController], listeners: [ diff --git a/packages/rpc/src/server/action.ts b/packages/rpc/src/server/action.ts index 971fe168b..bccdaea23 100644 --- a/packages/rpc/src/server/action.ts +++ b/packages/rpc/src/server/action.ts @@ -148,19 +148,7 @@ export class RpcServerAction { throw new Error(`No controller registered for id ${controller}`); } const action = getActions(classType.controller).get(methodName); - - if (!action) { - throw new Error(`Action unknown ${methodName}`); - } - - const controllerAccess: RpcControllerAccess = { - controllerName: controller, actionName: methodName, controllerClassType: classType.controller, - actionGroups: action.groups, actionData: action.data - }; - - if (!await this.hasControllerAccess(controllerAccess)) { - throw new Error(`Access denied to action ${methodName}`); - } + if (!action) throw new Error(`Action unknown ${methodName}`); const methodReflection = ReflectionClass.from(classType.controller).getMethod(methodName); const method = methodReflection.type; @@ -386,8 +374,20 @@ export class RpcServerAction { public async handleAction(message: RpcMessage, response: RpcMessageBuilder) { const body = message.parseBody(); - const controller = this.controllers.get(body.controller); - if (!controller) throw new Error(`No controller registered for id ${body.controller}`); + const classType = this.controllers.get(body.controller); + if (!classType) throw new Error(`No controller registered for id ${body.controller}`); + + const action = getActions(classType.controller).get(body.method); + if (!action) throw new Error(`Action unknown ${body.method}`); + + const controllerAccess: RpcControllerAccess = { + controllerName: body.controller, actionName: body.method, controllerClassType: classType.controller, + actionGroups: action.groups, actionData: action.data + }; + + if (!await this.hasControllerAccess(controllerAccess)) { + throw new Error(`Access denied to action ${body.method}`); + } const types = await this.loadTypes(body.controller, body.method); let value: { args: any[] } = { args: [] }; @@ -402,9 +402,9 @@ export class RpcServerAction { return response.error(error); } - const controllerClassType = this.injector.get(controller.controller, controller.module); + const controllerClassType = this.injector.get(classType.controller, classType.module); if (!controllerClassType) { - response.error(new Error(`No instance of ${getClassName(controller.controller)} found.`)); + response.error(new Error(`No instance of ${getClassName(classType.controller)} found.`)); } // const converted = types.parametersDeserialize(value.args); const errors: ValidationErrorItem[] = []; @@ -474,7 +474,7 @@ export class RpcServerAction { } }; } else if (isObservable(result)) { - this.observables[message.id] = { observable: result, subscriptions: {}, types, classType: controller.controller, method: body.method }; + this.observables[message.id] = { observable: result, subscriptions: {}, types, classType: classType.controller, method: body.method }; let type: ActionObservableTypes = ActionObservableTypes.observable; if (isSubject(result)) { diff --git a/packages/stopwatch/src/stopwatch.ts b/packages/stopwatch/src/stopwatch.ts index b2e372ddb..c12b3e733 100644 --- a/packages/stopwatch/src/stopwatch.ts +++ b/packages/stopwatch/src/stopwatch.ts @@ -112,7 +112,8 @@ export class Stopwatch { } else { if (!zone) return new NoopStopwatchFrame(); context = zone.stopwatchContextId; - if (!context) throw new Error('No Stopwatch context given'); + // might be getting an empty object on some platforms, which we treat as no context (as we start new context only with stopwatchContextId) + if (!context) return new NoopStopwatchFrame(); } const id = ++frameId;