From 1b92032c732b35ca63c4578571f717c987193c10 Mon Sep 17 00:00:00 2001 From: uasan Date: Thu, 13 Jun 2024 21:12:04 +0200 Subject: [PATCH] Init --- package.json | 2 +- src/compiler/entities/api/handler.js | 5 +---- src/compiler/worker/config.js | 2 +- src/interfaces/postgres/sql.ts | 1 + src/interfaces/security/decorators.ts | 2 +- src/runtime/postgres/query/sql.js | 6 ++++++ src/runtime/security/decorators.js | 8 +++++++- tsconfig.json | 2 +- 8 files changed, 19 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 0a175e3..92fda56 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "#compiler/*": "./src/compiler/*" }, "dependencies": { - "typescript": "next", + "typescript": "5.5.1-rc", "@types/node": "latest", "uWebSockets.js": "uNetworking/uWebSockets.js#v20.42.0", "@uah/postgres": "file:../../Postgres" diff --git a/src/compiler/entities/api/handler.js b/src/compiler/entities/api/handler.js index a6fea5d..bfbb007 100644 --- a/src/compiler/entities/api/handler.js +++ b/src/compiler/entities/api/handler.js @@ -16,10 +16,7 @@ import { factoryAwaitStatement, factoryPropertyParenthesized, } from '../../helpers/expression.js'; -import { - factoryStatement, - factoryTryStatement, -} from '../../helpers/statements.js'; +import { factoryTryStatement } from '../../helpers/statements.js'; import { getAwaitedType, getReturnType, diff --git a/src/compiler/worker/config.js b/src/compiler/worker/config.js index ec06d14..6440553 100644 --- a/src/compiler/worker/config.js +++ b/src/compiler/worker/config.js @@ -36,7 +36,7 @@ export const compilerOptions = { jsx: ts.JsxEmit.Preserve, module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ESNext, - moduleDetection: 'force', + moduleDetection: ts.ModuleDetectionKind.Force, useDefineForClassFields: true, exactOptionalPropertyTypes: false, forceConsistentCasingInFileNames: true, diff --git a/src/interfaces/postgres/sql.ts b/src/interfaces/postgres/sql.ts index 67231a7..611bb70 100644 --- a/src/interfaces/postgres/sql.ts +++ b/src/interfaces/postgres/sql.ts @@ -4,6 +4,7 @@ export interface SQL { asObject(): this; asValue(): this; asBlob(): this; + asValues(): this; sql(strings: TemplateStringsArray, ...params: unknown[]): this; sql( diff --git a/src/interfaces/security/decorators.ts b/src/interfaces/security/decorators.ts index 7f67e34..f2e6dba 100644 --- a/src/interfaces/security/decorators.ts +++ b/src/interfaces/security/decorators.ts @@ -1,5 +1,5 @@ import type { ServerContext } from '../server/context.ts'; export declare function Permission( - rule: (context: ServerContext, payload?: any) => Promise + rule: (context: ServerContext, payload?: any) => boolean | Promise ): (target: unknown, context: ClassMethodDecoratorContext) => void; diff --git a/src/runtime/postgres/query/sql.js b/src/runtime/postgres/query/sql.js index d9955cc..a8b9dd3 100644 --- a/src/runtime/postgres/query/sql.js +++ b/src/runtime/postgres/query/sql.js @@ -4,6 +4,7 @@ import { FETCH_ONE_VALUE, TYPE_BLOB, TYPE_NATIVE, + FETCH_VALUES, } from '@uah/postgres/src/constants.js'; import { concat } from './utils.js'; @@ -43,6 +44,11 @@ export class SQL { return this; } + asValues() { + this.mode = FETCH_VALUES | TYPE_NATIVE; + return this; + } + asBlob() { this.mode = FETCH_ONE_VALUE | TYPE_BLOB; return this; diff --git a/src/runtime/security/decorators.js b/src/runtime/security/decorators.js index fa20821..1d538ae 100644 --- a/src/runtime/security/decorators.js +++ b/src/runtime/security/decorators.js @@ -1 +1,7 @@ -export function Permission() {} +import { Forbidden } from '../exceptions/Forbidden.js'; + +export async function Permission(context, rule, payload) { + if ((await rule(context, payload)) !== true) { + throw new Forbidden(); + } +} diff --git a/tsconfig.json b/tsconfig.json index 269d94d..cba53ec 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "lib": [ "ESNext" ], - "types": [ + "typeRoots": [ "@types/node", "@uah/server" ],