@creamapi/cream
Version:
Concise REST API Maker - An extension library for express to create REST APIs faster
41 lines (40 loc) • 1.55 kB
JavaScript
;
/*
* Copyright 2024 Raul Radu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.HTTP_DYNAMIC_COOKIES = void 0;
exports.DynamicCookie = DynamicCookie;
exports.HTTP_DYNAMIC_COOKIES = Symbol('cream:http:cookies:dynamic');
/**
* This method is used to map an attribute of a class to a specific cookie
* given the cookie options
* @param cookieName the cookie name
* @param opts the options associated with the cookie
* @returns the decorator function that will decorate the class attribute
*/
function DynamicCookie(cookieName, opts = {}) {
return function (target, propertyName) {
let cookies = Reflect.getMetadata(exports.HTTP_DYNAMIC_COOKIES, target) ||
new Array();
let cookie = {
cookieName: cookieName,
propertyName: propertyName,
opts: opts,
};
cookies.push(cookie);
Reflect.defineMetadata(exports.HTTP_DYNAMIC_COOKIES, cookies, target);
};
}