Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions data/types/CookieValueMetadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { SameSite } from "../../types/SameSite";

export class CookieValueMetadata {
private readonly _cookieName: string;
private readonly _parameterIndex: number;
private readonly _domain: string | undefined;
private readonly _httpOnly: boolean | undefined;
private readonly _maxAge: number | undefined;
private readonly _path: string | undefined;
private readonly _sameSite: SameSite | undefined;
private readonly _secure: boolean | undefined;
private readonly _expires: string | undefined;

constructor(
cookieName: string,
parameterIndex: number,
domain: string | undefined,
httpOnly: boolean | undefined,
maxAge: number | undefined,
path: string | undefined,
sameSite: SameSite | undefined,
secure: boolean | undefined,
expires: string | undefined
) {
this._cookieName = cookieName;
this._parameterIndex = parameterIndex;
this._domain = domain;
this._httpOnly = httpOnly;
this._maxAge = maxAge;
this._path = path;
this._sameSite = sameSite;
this._secure = secure;
this._expires = expires;
}

get cookieName(): string {
return this._cookieName;
}

get parameterIndex(): number {
return this._parameterIndex;
}

get domain(): string | undefined {
return this._domain;
}

get httpOnly(): boolean | undefined {
return this._httpOnly;
}

get maxAge(): number | undefined {
return this._maxAge;
}

get path(): string | undefined {
return this._path;
}

get sameSite(): SameSite | undefined {
return this._sameSite;
}

get secure(): boolean | undefined {
return this._secure;
}

get expires(): string | undefined {
return this._expires;
}
}
13 changes: 13 additions & 0 deletions data/utils/CookieValueMetadataUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'reflect-metadata';
import {CookieValueMetadata} from "../types/CookieValueMetadata";


export class CookieValueMetadataUtils {
public static getCookieMetadata(target: Object, propertyKey: string | symbol | undefined): CookieValueMetadata | undefined {
return Reflect.getMetadata('cookieValueMetadata', target, propertyKey || 'default');
}

public static setCookieMetadata(metadata: CookieValueMetadata, target: Object, propertyKey: string | symbol | undefined): void {
Reflect.defineMetadata('cookieValueMetadata', metadata, target, propertyKey || 'default');
}
}
24 changes: 24 additions & 0 deletions data/utils/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions data/utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"reflect-metadata": "^0.2.1"
}
}
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"reflect-metadata": "^0.2.1"
}
}
22 changes: 22 additions & 0 deletions request/CookieValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {CookieValueMetadataUtils} from "../data/utils/CookieValueMetadataUtils";
import {CookieValueMetadata} from "../data/types/CookieValueMetadata.ts";


export const CookieValue = (cookieName: string): ParameterDecorator => {
return (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => {
const key = propertyKey || 'default';
const metadata: CookieValueMetadata = new CookieValueMetadata(
cookieName,
parameterIndex,
undefined, // domain
undefined, // httpOnly
undefined, // maxAge
undefined, // path
undefined, // sameSite
undefined, // secure
undefined // expires
);

CookieValueMetadataUtils.setCookieMetadata(metadata, cookieName, propertyKey);
}
}