Initial commit - Event Planner application
This commit is contained in:
1
node_modules/@nestjs/common/serializer/class-serializer.constants.d.ts
generated
vendored
Normal file
1
node_modules/@nestjs/common/serializer/class-serializer.constants.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const CLASS_SERIALIZER_OPTIONS = "class_serializer:options";
|
||||
4
node_modules/@nestjs/common/serializer/class-serializer.constants.js
generated
vendored
Normal file
4
node_modules/@nestjs/common/serializer/class-serializer.constants.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CLASS_SERIALIZER_OPTIONS = void 0;
|
||||
exports.CLASS_SERIALIZER_OPTIONS = 'class_serializer:options';
|
||||
29
node_modules/@nestjs/common/serializer/class-serializer.interceptor.d.ts
generated
vendored
Normal file
29
node_modules/@nestjs/common/serializer/class-serializer.interceptor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import { ClassSerializerContextOptions } from './class-serializer.interfaces';
|
||||
import { Observable } from 'rxjs';
|
||||
import { CallHandler, ExecutionContext, NestInterceptor } from '../interfaces';
|
||||
import { ClassTransformOptions } from '../interfaces/external/class-transform-options.interface';
|
||||
import { TransformerPackage } from '../interfaces/external/transformer-package.interface';
|
||||
export interface PlainLiteralObject {
|
||||
[key: string]: any;
|
||||
}
|
||||
/**
|
||||
* @publicApi
|
||||
*/
|
||||
export interface ClassSerializerInterceptorOptions extends ClassTransformOptions {
|
||||
transformerPackage?: TransformerPackage;
|
||||
}
|
||||
/**
|
||||
* @publicApi
|
||||
*/
|
||||
export declare class ClassSerializerInterceptor implements NestInterceptor {
|
||||
protected readonly reflector: any;
|
||||
protected readonly defaultOptions: ClassSerializerInterceptorOptions;
|
||||
constructor(reflector: any, defaultOptions?: ClassSerializerInterceptorOptions);
|
||||
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
||||
/**
|
||||
* Serializes responses that are non-null objects nor streamable files.
|
||||
*/
|
||||
serialize(response: PlainLiteralObject | Array<PlainLiteralObject>, options: ClassSerializerContextOptions): PlainLiteralObject | Array<PlainLiteralObject>;
|
||||
transformToPlain(plainOrClass: any, options: ClassSerializerContextOptions): PlainLiteralObject;
|
||||
protected getContextOptions(context: ExecutionContext): ClassSerializerContextOptions | undefined;
|
||||
}
|
||||
77
node_modules/@nestjs/common/serializer/class-serializer.interceptor.js
generated
vendored
Normal file
77
node_modules/@nestjs/common/serializer/class-serializer.interceptor.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ClassSerializerInterceptor = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const operators_1 = require("rxjs/operators");
|
||||
const core_1 = require("../decorators/core");
|
||||
const file_stream_1 = require("../file-stream");
|
||||
const load_package_util_1 = require("../utils/load-package.util");
|
||||
const shared_utils_1 = require("../utils/shared.utils");
|
||||
const class_serializer_constants_1 = require("./class-serializer.constants");
|
||||
let classTransformer = {};
|
||||
// NOTE (external)
|
||||
// We need to deduplicate them here due to the circular dependency
|
||||
// between core and common packages
|
||||
const REFLECTOR = 'Reflector';
|
||||
/**
|
||||
* @publicApi
|
||||
*/
|
||||
let ClassSerializerInterceptor = class ClassSerializerInterceptor {
|
||||
constructor(reflector, defaultOptions = {}) {
|
||||
this.reflector = reflector;
|
||||
this.defaultOptions = defaultOptions;
|
||||
classTransformer =
|
||||
defaultOptions?.transformerPackage ??
|
||||
(0, load_package_util_1.loadPackage)('class-transformer', 'ClassSerializerInterceptor', () => require('class-transformer'));
|
||||
if (!defaultOptions?.transformerPackage) {
|
||||
require('class-transformer');
|
||||
}
|
||||
}
|
||||
intercept(context, next) {
|
||||
const contextOptions = this.getContextOptions(context);
|
||||
const options = {
|
||||
...this.defaultOptions,
|
||||
...contextOptions,
|
||||
};
|
||||
return next
|
||||
.handle()
|
||||
.pipe((0, operators_1.map)((res) => this.serialize(res, options)));
|
||||
}
|
||||
/**
|
||||
* Serializes responses that are non-null objects nor streamable files.
|
||||
*/
|
||||
serialize(response, options) {
|
||||
if (!(0, shared_utils_1.isObject)(response) || response instanceof file_stream_1.StreamableFile) {
|
||||
return response;
|
||||
}
|
||||
return Array.isArray(response)
|
||||
? response.map(item => this.transformToPlain(item, options))
|
||||
: this.transformToPlain(response, options);
|
||||
}
|
||||
transformToPlain(plainOrClass, options) {
|
||||
if (!plainOrClass) {
|
||||
return plainOrClass;
|
||||
}
|
||||
if (!options.type) {
|
||||
return classTransformer.classToPlain(plainOrClass, options);
|
||||
}
|
||||
if (plainOrClass instanceof options.type) {
|
||||
return classTransformer.classToPlain(plainOrClass, options);
|
||||
}
|
||||
const instance = classTransformer.plainToInstance(options.type, plainOrClass, options);
|
||||
return classTransformer.classToPlain(instance, options);
|
||||
}
|
||||
getContextOptions(context) {
|
||||
return this.reflector.getAllAndOverride(class_serializer_constants_1.CLASS_SERIALIZER_OPTIONS, [
|
||||
context.getHandler(),
|
||||
context.getClass(),
|
||||
]);
|
||||
}
|
||||
};
|
||||
exports.ClassSerializerInterceptor = ClassSerializerInterceptor;
|
||||
exports.ClassSerializerInterceptor = ClassSerializerInterceptor = tslib_1.__decorate([
|
||||
(0, core_1.Injectable)(),
|
||||
tslib_1.__param(0, (0, core_1.Inject)(REFLECTOR)),
|
||||
tslib_1.__param(1, (0, core_1.Optional)()),
|
||||
tslib_1.__metadata("design:paramtypes", [Object, Object])
|
||||
], ClassSerializerInterceptor);
|
||||
8
node_modules/@nestjs/common/serializer/class-serializer.interfaces.d.ts
generated
vendored
Normal file
8
node_modules/@nestjs/common/serializer/class-serializer.interfaces.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { ClassTransformOptions } from '../interfaces/external/class-transform-options.interface';
|
||||
import { Type } from '../interfaces';
|
||||
/**
|
||||
* @publicApi
|
||||
*/
|
||||
export interface ClassSerializerContextOptions extends ClassTransformOptions {
|
||||
type?: Type<any>;
|
||||
}
|
||||
2
node_modules/@nestjs/common/serializer/class-serializer.interfaces.js
generated
vendored
Normal file
2
node_modules/@nestjs/common/serializer/class-serializer.interfaces.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
1
node_modules/@nestjs/common/serializer/decorators/index.d.ts
generated
vendored
Normal file
1
node_modules/@nestjs/common/serializer/decorators/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './serialize-options.decorator';
|
||||
4
node_modules/@nestjs/common/serializer/decorators/index.js
generated
vendored
Normal file
4
node_modules/@nestjs/common/serializer/decorators/index.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./serialize-options.decorator"), exports);
|
||||
5
node_modules/@nestjs/common/serializer/decorators/serialize-options.decorator.d.ts
generated
vendored
Normal file
5
node_modules/@nestjs/common/serializer/decorators/serialize-options.decorator.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { ClassSerializerContextOptions } from '../class-serializer.interfaces';
|
||||
/**
|
||||
* @publicApi
|
||||
*/
|
||||
export declare const SerializeOptions: (options: ClassSerializerContextOptions) => import("../../decorators").CustomDecorator<string>;
|
||||
10
node_modules/@nestjs/common/serializer/decorators/serialize-options.decorator.js
generated
vendored
Normal file
10
node_modules/@nestjs/common/serializer/decorators/serialize-options.decorator.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SerializeOptions = void 0;
|
||||
const decorators_1 = require("../../decorators");
|
||||
const class_serializer_constants_1 = require("../class-serializer.constants");
|
||||
/**
|
||||
* @publicApi
|
||||
*/
|
||||
const SerializeOptions = (options) => (0, decorators_1.SetMetadata)(class_serializer_constants_1.CLASS_SERIALIZER_OPTIONS, options);
|
||||
exports.SerializeOptions = SerializeOptions;
|
||||
3
node_modules/@nestjs/common/serializer/index.d.ts
generated
vendored
Normal file
3
node_modules/@nestjs/common/serializer/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './class-serializer.interceptor';
|
||||
export * from './decorators';
|
||||
export * from './class-serializer.interfaces';
|
||||
6
node_modules/@nestjs/common/serializer/index.js
generated
vendored
Normal file
6
node_modules/@nestjs/common/serializer/index.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./class-serializer.interceptor"), exports);
|
||||
tslib_1.__exportStar(require("./decorators"), exports);
|
||||
tslib_1.__exportStar(require("./class-serializer.interfaces"), exports);
|
||||
50
node_modules/@nestjs/common/serializer/standard-schema-serializer.interceptor.d.ts
generated
vendored
Normal file
50
node_modules/@nestjs/common/serializer/standard-schema-serializer.interceptor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
||||
import { Observable } from 'rxjs';
|
||||
import { CallHandler, ExecutionContext, NestInterceptor } from '../interfaces/index.js';
|
||||
import { StandardSchemaSerializerContextOptions } from './standard-schema-serializer.interfaces.js';
|
||||
interface PlainLiteralObject {
|
||||
[key: string]: any;
|
||||
}
|
||||
/**
|
||||
* @publicApi
|
||||
*/
|
||||
export interface StandardSchemaSerializerInterceptorOptions {
|
||||
/**
|
||||
* A default standard schema to use for serialization when no schema
|
||||
* is provided via `@SerializeOptions()`.
|
||||
*/
|
||||
schema?: StandardSchemaV1;
|
||||
/**
|
||||
* Default options forwarded to the schema's `~standard.validate()` call.
|
||||
* Can be overridden per-handler via `@SerializeOptions({ validateOptions })`.
|
||||
*/
|
||||
validateOptions?: StandardSchemaV1.Options;
|
||||
}
|
||||
/**
|
||||
* An interceptor that serializes outgoing responses using a Standard Schema.
|
||||
*
|
||||
* The schema can be provided either:
|
||||
* - As a default option in the interceptor constructor
|
||||
* - Per-handler or per-class via `@SerializeOptions({ schema })` decorator
|
||||
*
|
||||
* When a schema is present, the interceptor validates/transforms the response
|
||||
* through the schema's `~standard.validate()` method. If validation fails,
|
||||
* the issues are thrown as an error.
|
||||
*
|
||||
* @see [Standard Schema](https://github.com/standard-schema/standard-schema)
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export declare class StandardSchemaSerializerInterceptor implements NestInterceptor {
|
||||
protected readonly reflector: any;
|
||||
protected readonly defaultOptions: StandardSchemaSerializerInterceptorOptions;
|
||||
constructor(reflector: any, defaultOptions?: StandardSchemaSerializerInterceptorOptions);
|
||||
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
||||
/**
|
||||
* Serializes responses that are non-null objects nor streamable files.
|
||||
*/
|
||||
serialize(response: PlainLiteralObject | Array<PlainLiteralObject>, schema: StandardSchemaV1 | undefined, validateOptions?: StandardSchemaV1.Options): PlainLiteralObject | Array<PlainLiteralObject> | Promise<PlainLiteralObject | Array<PlainLiteralObject>>;
|
||||
transformToPlain(plainOrClass: any, schema: StandardSchemaV1, validateOptions?: StandardSchemaV1.Options): Promise<PlainLiteralObject>;
|
||||
protected getContextOptions(context: ExecutionContext): StandardSchemaSerializerContextOptions | undefined;
|
||||
}
|
||||
export {};
|
||||
75
node_modules/@nestjs/common/serializer/standard-schema-serializer.interceptor.js
generated
vendored
Normal file
75
node_modules/@nestjs/common/serializer/standard-schema-serializer.interceptor.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
import { __decorate, __metadata, __param } from "tslib";
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Inject, Injectable, Optional } from '../decorators/core/index.js';
|
||||
import { StreamableFile } from '../file-stream/index.js';
|
||||
import { isObject } from '../utils/shared.utils.js';
|
||||
import { CLASS_SERIALIZER_OPTIONS } from './class-serializer.constants.js';
|
||||
// NOTE (external)
|
||||
// We need to deduplicate them here due to the circular dependency
|
||||
// between core and common packages
|
||||
const REFLECTOR = 'Reflector';
|
||||
/**
|
||||
* An interceptor that serializes outgoing responses using a Standard Schema.
|
||||
*
|
||||
* The schema can be provided either:
|
||||
* - As a default option in the interceptor constructor
|
||||
* - Per-handler or per-class via `@SerializeOptions({ schema })` decorator
|
||||
*
|
||||
* When a schema is present, the interceptor validates/transforms the response
|
||||
* through the schema's `~standard.validate()` method. If validation fails,
|
||||
* the issues are thrown as an error.
|
||||
*
|
||||
* @see [Standard Schema](https://github.com/standard-schema/standard-schema)
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
let StandardSchemaSerializerInterceptor = class StandardSchemaSerializerInterceptor {
|
||||
reflector;
|
||||
defaultOptions;
|
||||
constructor(reflector, defaultOptions = {}) {
|
||||
this.reflector = reflector;
|
||||
this.defaultOptions = defaultOptions;
|
||||
}
|
||||
intercept(context, next) {
|
||||
const contextOptions = this.getContextOptions(context);
|
||||
const schema = contextOptions?.schema ?? this.defaultOptions.schema;
|
||||
const validateOptions = contextOptions?.validateOptions ?? this.defaultOptions.validateOptions;
|
||||
return next
|
||||
.handle()
|
||||
.pipe(map((res) => this.serialize(res, schema, validateOptions)));
|
||||
}
|
||||
/**
|
||||
* Serializes responses that are non-null objects nor streamable files.
|
||||
*/
|
||||
serialize(response, schema, validateOptions) {
|
||||
if (!schema || !isObject(response) || response instanceof StreamableFile) {
|
||||
return response;
|
||||
}
|
||||
return Array.isArray(response)
|
||||
? Promise.all(response.map(item => this.transformToPlain(item, schema, validateOptions)))
|
||||
: this.transformToPlain(response, schema, validateOptions);
|
||||
}
|
||||
async transformToPlain(plainOrClass, schema, validateOptions) {
|
||||
if (!plainOrClass) {
|
||||
return plainOrClass;
|
||||
}
|
||||
const result = await schema['~standard'].validate(plainOrClass, validateOptions);
|
||||
if (result.issues) {
|
||||
throw new Error(`Serialization failed: ${result.issues.map(i => i.message).join(', ')}`);
|
||||
}
|
||||
return result.value;
|
||||
}
|
||||
getContextOptions(context) {
|
||||
return this.reflector.getAllAndOverride(CLASS_SERIALIZER_OPTIONS, [
|
||||
context.getHandler(),
|
||||
context.getClass(),
|
||||
]);
|
||||
}
|
||||
};
|
||||
StandardSchemaSerializerInterceptor = __decorate([
|
||||
Injectable(),
|
||||
__param(0, Inject(REFLECTOR)),
|
||||
__param(1, Optional()),
|
||||
__metadata("design:paramtypes", [Object, Object])
|
||||
], StandardSchemaSerializerInterceptor);
|
||||
export { StandardSchemaSerializerInterceptor };
|
||||
18
node_modules/@nestjs/common/serializer/standard-schema-serializer.interfaces.d.ts
generated
vendored
Normal file
18
node_modules/@nestjs/common/serializer/standard-schema-serializer.interfaces.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
||||
/**
|
||||
* Options for the `StandardSchemaSerializerInterceptor`, passed via
|
||||
* `@SerializeOptions({ schema })`.
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export interface StandardSchemaSerializerContextOptions {
|
||||
/**
|
||||
* A standard schema to use for serialization.
|
||||
* Used by `StandardSchemaSerializerInterceptor` to validate/transform the response.
|
||||
*/
|
||||
schema?: StandardSchemaV1;
|
||||
/**
|
||||
* Optional options forwarded to the schema's `~standard.validate()` call.
|
||||
*/
|
||||
validateOptions?: StandardSchemaV1.Options;
|
||||
}
|
||||
1
node_modules/@nestjs/common/serializer/standard-schema-serializer.interfaces.js
generated
vendored
Normal file
1
node_modules/@nestjs/common/serializer/standard-schema-serializer.interfaces.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Reference in New Issue
Block a user