fix(es): Improve sourcemap (#5569)

This commit is contained in:
Donny/강동윤 2022-08-20 12:35:49 +09:00 committed by GitHub
parent 0f5d02568b
commit 2f7e322214
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 913 additions and 5 deletions

View File

@ -0,0 +1,16 @@
{
"sourceMaps": true,
"jsc": {
"target": "es2022",
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"keepClassNames": true
}
}

View File

@ -0,0 +1,36 @@
import { Body, Controller, Delete, Param, Put, UseGuards, UseInterceptors } from '@nestjs/common';
import {
COMMENT_CONTROLLER_ROUTE,
COMMENT_DELETE_ENDPOINT,
COMMENT_UPDATE_ENDPOINT,
} from '@server/constants/controllers';
import { MongooseClassSerializerInterceptor } from '@server/interceptors/MongooseClassSerializerInterceptor';
import { Comment } from '@server/comment/schemas/CommentSchema';
import { CommentService } from '@server/comment/CommentService';
import { JwtAuthGuard } from '@server/auth/guards/JwtAuthGuard';
import { User } from '@server/decorators/UserDecorator';
import { User as UserType } from '@server/user/schemas/UserSchema';
import { UpdateCommentDto } from '@server/comment/dto/UpdateCommentDto';
@Controller(COMMENT_CONTROLLER_ROUTE)
@UseInterceptors(MongooseClassSerializerInterceptor(Comment))
export class CommentController {
constructor(private commentService: CommentService) { }
@UseGuards(JwtAuthGuard)
@Put(COMMENT_UPDATE_ENDPOINT)
public updateComment(
@Param('id') id: string,
@Body() updateCommentDto: UpdateCommentDto,
@User() user: UserType,
) {
return this.commentService.update(id, updateCommentDto, user.id);
}
@UseGuards(JwtAuthGuard)
@Delete(COMMENT_DELETE_ENDPOINT)
public deleteComment(@Param('id') id: string, @User() user: UserType) {
return this.commentService.delete(id, user.id);
}
}

View File

@ -0,0 +1,39 @@
{
"mappings": "AAAA;;;AAAA,SAASA,IAAI,EAAEC,UAAU,EAAEC,MAAM,EAAEC,KAAK,EAAEC,GAAG,EAAEC,SAAS,EAAEC,eAAe,QA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AAI,EAAE,CAAA;;;;eAAO,QAAQ,4BAAR,QAAQ;;GAf3DG,iBAAiB;AAAjBA,iBAAiB;IAF7BhB,UAAU,CAACM,wBAAwB,CAAC;IACpCD,eAAe,CAACI,kCAAkC,CAACC,OAAO,CAAC,CAAC;;;eAErB,cAAc,4BAAd,cAAc;;GADzCM,iBAAiB",
"names": [
"Body",
"Controller",
"Delete",
"Param",
"Put",
"UseGuards",
"UseInterceptors",
"COMMENT_CONTROLLER_ROUTE",
"COMMENT_DELETE_ENDPOINT",
"COMMENT_UPDATE_ENDPOINT",
"MongooseClassSerializerInterceptor",
"Comment",
"CommentService",
"JwtAuthGuard",
"User",
"UserType",
"UpdateCommentDto",
"CommentController",
"constructor",
"commentService",
"updateComment",
"id",
"updateCommentDto",
"user",
"update",
"deleteComment",
"delete"
],
"sources": [
"../../input/CommentControlller.ts"
],
"sourcesContent": [
"import { Body, Controller, Delete, Param, Put, UseGuards, UseInterceptors } from '@nestjs/common';\n\nimport {\n COMMENT_CONTROLLER_ROUTE,\n COMMENT_DELETE_ENDPOINT,\n COMMENT_UPDATE_ENDPOINT,\n} from '@server/constants/controllers';\nimport { MongooseClassSerializerInterceptor } from '@server/interceptors/MongooseClassSerializerInterceptor';\nimport { Comment } from '@server/comment/schemas/CommentSchema';\nimport { CommentService } from '@server/comment/CommentService';\nimport { JwtAuthGuard } from '@server/auth/guards/JwtAuthGuard';\nimport { User } from '@server/decorators/UserDecorator';\nimport { User as UserType } from '@server/user/schemas/UserSchema';\nimport { UpdateCommentDto } from '@server/comment/dto/UpdateCommentDto';\n\n@Controller(COMMENT_CONTROLLER_ROUTE)\n@UseInterceptors(MongooseClassSerializerInterceptor(Comment))\nexport class CommentController {\n constructor(private commentService: CommentService) { }\n\n @UseGuards(JwtAuthGuard)\n @Put(COMMENT_UPDATE_ENDPOINT)\n public updateComment(\n @Param('id') id: string,\n @Body() updateCommentDto: UpdateCommentDto,\n @User() user: UserType,\n ) {\n return this.commentService.update(id, updateCommentDto, user.id);\n }\n\n @UseGuards(JwtAuthGuard)\n @Delete(COMMENT_DELETE_ENDPOINT)\n public deleteComment(@Param('id') id: string, @User() user: UserType) {\n return this.commentService.delete(id, user.id);\n }\n}\n"
],
"version": 3
}

View File

@ -0,0 +1,55 @@
import _ts_decorate from "@swc/helpers/src/_ts_decorate.mjs";
import _ts_metadata from "@swc/helpers/src/_ts_metadata.mjs";
import _ts_param from "@swc/helpers/src/_ts_param.mjs";
import { Body, Controller, Delete, Param, Put, UseGuards, UseInterceptors } from '@nestjs/common';
import { COMMENT_CONTROLLER_ROUTE, COMMENT_DELETE_ENDPOINT, COMMENT_UPDATE_ENDPOINT } from '@server/constants/controllers';
import { MongooseClassSerializerInterceptor } from '@server/interceptors/MongooseClassSerializerInterceptor';
import { Comment } from '@server/comment/schemas/CommentSchema';
import { CommentService } from '@server/comment/CommentService';
import { JwtAuthGuard } from '@server/auth/guards/JwtAuthGuard';
import { User } from '@server/decorators/UserDecorator';
import { User as UserType } from '@server/user/schemas/UserSchema';
import { UpdateCommentDto } from '@server/comment/dto/UpdateCommentDto';
export let CommentController = class CommentController {
constructor(commentService){
this.commentService = commentService;
}
updateComment(id, updateCommentDto, user) {
return this.commentService.update(id, updateCommentDto, user.id);
}
deleteComment(id, user) {
return this.commentService.delete(id, user.id);
}
};
_ts_decorate([
UseGuards(JwtAuthGuard),
Put(COMMENT_UPDATE_ENDPOINT),
_ts_param(0, Param('id')),
_ts_param(1, Body()),
_ts_param(2, User()),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
String,
typeof UpdateCommentDto === "undefined" ? Object : UpdateCommentDto,
typeof UserType === "undefined" ? Object : UserType
])
], CommentController.prototype, "updateComment", null);
_ts_decorate([
UseGuards(JwtAuthGuard),
Delete(COMMENT_DELETE_ENDPOINT),
_ts_param(0, Param('id')),
_ts_param(1, User()),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
String,
typeof UserType === "undefined" ? Object : UserType
])
], CommentController.prototype, "deleteComment", null);
CommentController = _ts_decorate([
Controller(COMMENT_CONTROLLER_ROUTE),
UseInterceptors(MongooseClassSerializerInterceptor(Comment)),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof CommentService === "undefined" ? Object : CommentService
])
], CommentController);

View File

@ -0,0 +1,16 @@
{
"sourceMaps": true,
"jsc": {
"target": "es2022",
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"keepClassNames": true
}
}

View File

@ -0,0 +1,134 @@
import { Model, Connection as MongooseConnection } from 'mongoose';
import {
ForbiddenException,
Injectable,
InternalServerErrorException,
NotFoundException,
} from '@nestjs/common';
import { InjectModel, InjectConnection } from '@nestjs/mongoose';
import { Comment, CommentDocument } from '@server/comment/schemas/CommentSchema';
import { CreateCommentDto } from '@server/comment/dto/CreateCommentDto';
import { UpdateCommentDto } from '@server/comment/dto/UpdateCommentDto';
import { Post, PostDocument } from '@server/post/schemas/PostSchema';
@Injectable()
export class CommentService {
constructor(
@InjectModel(Comment.name) private commentModel: Model<CommentDocument>,
@InjectModel(Post.name) private postModel: Model<PostDocument>,
@InjectConnection() private readonly connection: MongooseConnection,
) {}
async getById(commentId: string): Promise<CommentDocument> {
const comment = await this.commentModel.findById(commentId);
if (!comment) {
throw new NotFoundException();
}
return comment.populate('author');
}
async create(
comment: CreateCommentDto,
postId: string,
userId: string,
): Promise<CommentDocument> {
const session = await this.connection.startSession();
session.startTransaction();
try {
const createdComment = await this.commentModel.create({
...comment,
author: userId,
postId,
});
if (!createdComment) {
throw new InternalServerErrorException('Comment was not created');
}
const { modifiedCount } = await this.postModel.updateOne(
{ _id: createdComment.postId },
{
$push: { comments: createdComment.id },
},
{ useFindAndModify: false },
);
if (modifiedCount === 0) {
throw new InternalServerErrorException('Comment was not created');
}
await session.commitTransaction();
return createdComment.populate('author');
} catch (error) {
await session.abortTransaction();
throw error;
} finally {
session.endSession();
}
}
async update(
commentId: string,
comment: UpdateCommentDto,
userId: string,
): Promise<CommentDocument> {
const { author } = await this.getById(commentId);
if (author.id !== userId) {
throw new ForbiddenException();
}
const updatedComment = await this.commentModel.findByIdAndUpdate(commentId, comment, {
new: true,
});
if (!updatedComment) {
throw new InternalServerErrorException('Comment was not updated');
}
return updatedComment.populate('author');
}
async delete(commentId: string, userId: string): Promise<void> {
const session = await this.connection.startSession();
session.startTransaction();
try {
const { author, postId } = await this.getById(commentId);
if (author.id !== userId) {
throw new ForbiddenException();
}
const { deletedCount } = await this.commentModel.deleteOne({ _id: commentId });
const { modifiedCount } = await this.postModel.updateOne(
{ _id: postId },
{
$pull: { comments: commentId },
},
{ useFindAndModify: false },
);
if (deletedCount === 0 || modifiedCount === 0) {
throw new InternalServerErrorException('Comment was not deleted');
}
await session.commitTransaction();
} catch (error) {
await session.abortTransaction();
throw error;
} finally {
session.endSession();
}
}
}

View File

@ -0,0 +1,61 @@
{
"mappings": "AAAA;;;AAAA,SAASA,KAAK,EAAEC,UAAU,IAAIC,kBAAkB,QAAQ,UAAU,CAAC;AACnE,SACEC,kBAAkB,EAClBC,UAAU,EACVC,4BAA4B,EAC5BC,iBAAiB,QACZ,gBAAgB,CAAC;AACxB,SAASC,WAAW,EAAEC,gBAAgB,QAAQ,kBAAkB,CAAC;AAEjE,SAASC,OAAO,QAAyB,uCAAuC,CAAC;AAGjF,SAASC,IAAI,QAAsB,iCAAiC,CAAC;AAGrE,WAAaC,cAAc,GAApB;IACLC,YACqCC,YAAoC,EACvCC,SAA8B,EACzBC,UAA8B,CACnE;QAHmCF,oBAAAA,YAAoC,CAAA;QACvCC,iBAAAA,SAA8B,CAAA;QACzBC,kBAAAA,UAA8B,CAAA;KACjE;UAEEC,OAAO,CAACC,SAAiB,EAA4B;QACzD,MAAMC,OAAO,GAAG,MAAM,IAAI,CAACL,YAAY,CAACM,QAAQ,CAACF,SAAS,CAAC,AAAC;QAE5D,IAAI,CAACC,OAAO,EAAE;YACZ,MAAM,IAAIZ,iBA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,IAAIU,YAAY,KAAK,CAAC,IAAIhB,aAAa,KAAK,CAAC,EAAE;gBAC7C,MAAM,IAAIxB,4BAA4B,CAAC,yBAAyB,CAAC,CAAC;aACnE;YAED,MAAMmB,OAAO,CAACY,iBAAiB,EAAE,CAAC;SACnC,CAAC,OAAOC,KAAK,EAAE;YACd,MAAMb,OAAO,CAACc,gBAAgB,EAAE,CAAC;YAEjC,MAAMD,KAAK,CAAC;SACb,QAAS;YACRb,OAAO,CAACe,UAAU,EAAE,CAAC;SACtB;KACF;CACF,CAAA;AAtHY5B,cAAc;IAD1BP,UAAU,EAAE;IAGRG,aAAAA,WAAW,CAACE,OAAO,CAACuC,IAAI,CAAC,CAAA;IACzBzC,aAAAA,WAAW,CAACG,IAAI,CAACsC,IAAI,CAAC,CAAA;IACtBxC,aAAAA,gBAAgB,EAAE,CAAA;;;eAF8B,KAAK,4BAAL,KAAK;eACX,KAAK,4BAAL,KAAK;eACC,kBAAkB,4BAAlB,kBAAkB;;GAJ1DG,cAAc",
"names": [
"Model",
"Connection",
"MongooseConnection",
"ForbiddenException",
"Injectable",
"InternalServerErrorException",
"NotFoundException",
"InjectModel",
"InjectConnection",
"Comment",
"Post",
"CommentService",
"constructor",
"commentModel",
"postModel",
"connection",
"getById",
"commentId",
"comment",
"findById",
"populate",
"create",
"postId",
"userId",
"session",
"startSession",
"startTransaction",
"createdComment",
"author",
"modifiedCount",
"updateOne",
"_id",
"$push",
"comments",
"id",
"useFindAndModify",
"commitTransaction",
"error",
"abortTransaction",
"endSession",
"update",
"updatedComment",
"findByIdAndUpdate",
"new",
"delete",
"deletedCount",
"deleteOne",
"$pull",
"name"
],
"sources": [
"../../input/CommentService.ts"
],
"sourcesContent": [
"import { Model, Connection as MongooseConnection } from 'mongoose';\nimport {\n ForbiddenException,\n Injectable,\n InternalServerErrorException,\n NotFoundException,\n} from '@nestjs/common';\nimport { InjectModel, InjectConnection } from '@nestjs/mongoose';\n\nimport { Comment, CommentDocument } from '@server/comment/schemas/CommentSchema';\nimport { CreateCommentDto } from '@server/comment/dto/CreateCommentDto';\nimport { UpdateCommentDto } from '@server/comment/dto/UpdateCommentDto';\nimport { Post, PostDocument } from '@server/post/schemas/PostSchema';\n\n@Injectable()\nexport class CommentService {\n constructor(\n @InjectModel(Comment.name) private commentModel: Model<CommentDocument>,\n @InjectModel(Post.name) private postModel: Model<PostDocument>,\n @InjectConnection() private readonly connection: MongooseConnection,\n ) {}\n\n async getById(commentId: string): Promise<CommentDocument> {\n const comment = await this.commentModel.findById(commentId);\n\n if (!comment) {\n throw new NotFoundException();\n }\n\n return comment.populate('author');\n }\n\n async create(\n comment: CreateCommentDto,\n postId: string,\n userId: string,\n ): Promise<CommentDocument> {\n const session = await this.connection.startSession();\n\n session.startTransaction();\n\n try {\n const createdComment = await this.commentModel.create({\n ...comment,\n author: userId,\n postId,\n });\n\n if (!createdComment) {\n throw new InternalServerErrorException('Comment was not created');\n }\n\n const { modifiedCount } = await this.postModel.updateOne(\n { _id: createdComment.postId },\n {\n $push: { comments: createdComment.id },\n },\n { useFindAndModify: false },\n );\n\n if (modifiedCount === 0) {\n throw new InternalServerErrorException('Comment was not created');\n }\n\n await session.commitTransaction();\n\n return createdComment.populate('author');\n } catch (error) {\n await session.abortTransaction();\n\n throw error;\n } finally {\n session.endSession();\n }\n }\n\n async update(\n commentId: string,\n comment: UpdateCommentDto,\n userId: string,\n ): Promise<CommentDocument> {\n const { author } = await this.getById(commentId);\n\n if (author.id !== userId) {\n throw new ForbiddenException();\n }\n\n const updatedComment = await this.commentModel.findByIdAndUpdate(commentId, comment, {\n new: true,\n });\n\n if (!updatedComment) {\n throw new InternalServerErrorException('Comment was not updated');\n }\n\n return updatedComment.populate('author');\n }\n\n async delete(commentId: string, userId: string): Promise<void> {\n const session = await this.connection.startSession();\n\n session.startTransaction();\n\n try {\n const { author, postId } = await this.getById(commentId);\n\n if (author.id !== userId) {\n throw new ForbiddenException();\n }\n\n const { deletedCount } = await this.commentModel.deleteOne({ _id: commentId });\n\n const { modifiedCount } = await this.postModel.updateOne(\n { _id: postId },\n {\n $pull: { comments: commentId },\n },\n { useFindAndModify: false },\n );\n\n if (deletedCount === 0 || modifiedCount === 0) {\n throw new InternalServerErrorException('Comment was not deleted');\n }\n\n await session.commitTransaction();\n } catch (error) {\n await session.abortTransaction();\n\n throw error;\n } finally {\n session.endSession();\n }\n }\n}\n"
],
"version": 3
}

View File

@ -0,0 +1,111 @@
import _ts_decorate from "@swc/helpers/src/_ts_decorate.mjs";
import _ts_metadata from "@swc/helpers/src/_ts_metadata.mjs";
import _ts_param from "@swc/helpers/src/_ts_param.mjs";
import { Model, Connection as MongooseConnection } from 'mongoose';
import { ForbiddenException, Injectable, InternalServerErrorException, NotFoundException } from '@nestjs/common';
import { InjectModel, InjectConnection } from '@nestjs/mongoose';
import { Comment } from '@server/comment/schemas/CommentSchema';
import { Post } from '@server/post/schemas/PostSchema';
export let CommentService = class CommentService {
constructor(commentModel, postModel, connection){
this.commentModel = commentModel;
this.postModel = postModel;
this.connection = connection;
}
async getById(commentId) {
const comment = await this.commentModel.findById(commentId);
if (!comment) {
throw new NotFoundException();
}
return comment.populate('author');
}
async create(comment, postId, userId) {
const session = await this.connection.startSession();
session.startTransaction();
try {
const createdComment = await this.commentModel.create({
...comment,
author: userId,
postId
});
if (!createdComment) {
throw new InternalServerErrorException('Comment was not created');
}
const { modifiedCount } = await this.postModel.updateOne({
_id: createdComment.postId
}, {
$push: {
comments: createdComment.id
}
}, {
useFindAndModify: false
});
if (modifiedCount === 0) {
throw new InternalServerErrorException('Comment was not created');
}
await session.commitTransaction();
return createdComment.populate('author');
} catch (error) {
await session.abortTransaction();
throw error;
} finally{
session.endSession();
}
}
async update(commentId, comment, userId) {
const { author } = await this.getById(commentId);
if (author.id !== userId) {
throw new ForbiddenException();
}
const updatedComment = await this.commentModel.findByIdAndUpdate(commentId, comment, {
new: true
});
if (!updatedComment) {
throw new InternalServerErrorException('Comment was not updated');
}
return updatedComment.populate('author');
}
async delete(commentId, userId) {
const session = await this.connection.startSession();
session.startTransaction();
try {
const { author , postId } = await this.getById(commentId);
if (author.id !== userId) {
throw new ForbiddenException();
}
const { deletedCount } = await this.commentModel.deleteOne({
_id: commentId
});
const { modifiedCount } = await this.postModel.updateOne({
_id: postId
}, {
$pull: {
comments: commentId
}
}, {
useFindAndModify: false
});
if (deletedCount === 0 || modifiedCount === 0) {
throw new InternalServerErrorException('Comment was not deleted');
}
await session.commitTransaction();
} catch (error) {
await session.abortTransaction();
throw error;
} finally{
session.endSession();
}
}
};
CommentService = _ts_decorate([
Injectable(),
_ts_param(0, InjectModel(Comment.name)),
_ts_param(1, InjectModel(Post.name)),
_ts_param(2, InjectConnection()),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof Model === "undefined" ? Object : Model,
typeof Model === "undefined" ? Object : Model,
typeof MongooseConnection === "undefined" ? Object : MongooseConnection
])
], CommentService);

View File

@ -0,0 +1,16 @@
{
"sourceMaps": true,
"jsc": {
"target": "es2022",
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"keepClassNames": true
}
}

View File

@ -0,0 +1,80 @@
import {
Body,
Controller,
Delete,
Get,
Param,
Post,
Put,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import {
POST_CONTROLLER_ROUTE,
POST_DELETE_ENDPOINT,
POST_GET_ALL_ENDPOINT,
POST_GET_ENDPOINT,
POST_CREATE_COMMENT_ENDPOINT,
POST_CREATE_ENDPOINT,
POST_UPDATE_ENDPOINT,
} from '@server/constants/controllers';
import { MongooseClassSerializerInterceptor } from '@server/interceptors/MongooseClassSerializerInterceptor';
import { Post as PostType } from '@server/post/schemas/PostSchema';
import { PostService } from '@server/post/PostService';
import { CreatePostDto } from '@server/post/dto/CreatePostDto';
import { JwtAuthGuard } from '@server/auth/guards/JwtAuthGuard';
import { User } from '@server/decorators/UserDecorator';
import { User as UserType } from '@server/user/schemas/UserSchema';
import { CreateCommentDto } from '@server/comment/dto/CreateCommentDto';
import { CommentService } from '@server/comment/CommentService';
import { Comment } from '@server/comment/schemas/CommentSchema';
@Controller(POST_CONTROLLER_ROUTE)
@UseInterceptors(MongooseClassSerializerInterceptor(PostType))
export class PostController {
constructor(private postService: PostService, private commentService: CommentService) { }
@Get(POST_GET_ALL_ENDPOINT)
public getPosts() {
return this.postService.getAll();
}
@Get(POST_GET_ENDPOINT)
public getPost(@Param('id') id: string) {
return this.postService.getById(id);
}
@UseGuards(JwtAuthGuard)
@Post(POST_CREATE_ENDPOINT)
public createPost(@Body() createPostDto: CreatePostDto, @User() user: UserType) {
return this.postService.create(createPostDto, user.id);
}
@UseGuards(JwtAuthGuard)
@Put(POST_UPDATE_ENDPOINT)
public updatePost(
@Param('id') id: string,
@Body() updatePostDto: CreatePostDto,
@User() user: UserType,
) {
return this.postService.update(id, updatePostDto, user.id);
}
@UseGuards(JwtAuthGuard)
@Delete(POST_DELETE_ENDPOINT)
public deletePost(@Param('id') id: string, @User() user: UserType) {
return this.postService.delete(id, user.id);
}
@UseInterceptors(MongooseClassSerializerInterceptor(Comment))
@UseGuards(JwtAuthGuard)
@Post(POST_CREATE_COMMENT_ENDPOINT)
public createPostComment(
@Param('id') id: string,
@Body() createCommentDto: CreateCommentDto,
@User() user: UserType,
) {
return this.commentService.create(createCommentDto, id, user.id);
}
}

View File

@ -0,0 +1,58 @@
{
"mappings": "AAAA;;;AAAA,SACIA,IAAI,EACJC,UAAU,EACVC,MAAM,EACNC,GAAG,EACHC,KAAK,EACLC,IAAI,EACJC,GAAG,EACHC,SAAS,EACTC,eAAe,QACZ,gBAAgB,CAAC;AAExB,SACIC,qBAAqB,EACrBC,oBAAoB,EACpBC,qBAAqB,EACrBC,iBAAiB,EACjBC,4BAA4B,EAC5BC,oBAAoB,EACpBC,oBAAoB,QACjB,+BAA+B,CAAC;AACvC,SAASC,kCAAkC,QAAQ,yDAAyD,CAAC;AAC7G,SAASX,IAAI,IAAIY,Q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AgB,4BAAhB,gBAAgB;eAC5B,QAAQ,4BAAR,QAAQ;;GAzCjBK,cAAc;AAAdA,cAAc;IAF1BzB,UAAU,CAACQ,qBAAqB,CAAC;IACjCD,eAAe,CAACQ,kCAAkC,CAACC,QAAQ,CAAC,CAAC;;;eAEzB,WAAW,4BAAX,WAAW;eAA0B,cAAc,4BAAd,cAAc;;GAD3ES,cAAc",
"names": [
"Body",
"Controller",
"Delete",
"Get",
"Param",
"Post",
"Put",
"UseGuards",
"UseInterceptors",
"POST_CONTROLLER_ROUTE",
"POST_DELETE_ENDPOINT",
"POST_GET_ALL_ENDPOINT",
"POST_GET_ENDPOINT",
"POST_CREATE_COMMENT_ENDPOINT",
"POST_CREATE_ENDPOINT",
"POST_UPDATE_ENDPOINT",
"MongooseClassSerializerInterceptor",
"PostType",
"PostService",
"CreatePostDto",
"JwtAuthGuard",
"User",
"UserType",
"CreateCommentDto",
"CommentService",
"Comment",
"PostController",
"constructor",
"postService",
"commentService",
"getPosts",
"getAll",
"getPost",
"id",
"getById",
"createPost",
"createPostDto",
"user",
"create",
"updatePost",
"updatePostDto",
"update",
"deletePost",
"delete",
"createPostComment",
"createCommentDto"
],
"sources": [
"../../input/PistController.ts"
],
"sourcesContent": [
"import {\n Body,\n Controller,\n Delete,\n Get,\n Param,\n Post,\n Put,\n UseGuards,\n UseInterceptors,\n} from '@nestjs/common';\n\nimport {\n POST_CONTROLLER_ROUTE,\n POST_DELETE_ENDPOINT,\n POST_GET_ALL_ENDPOINT,\n POST_GET_ENDPOINT,\n POST_CREATE_COMMENT_ENDPOINT,\n POST_CREATE_ENDPOINT,\n POST_UPDATE_ENDPOINT,\n} from '@server/constants/controllers';\nimport { MongooseClassSerializerInterceptor } from '@server/interceptors/MongooseClassSerializerInterceptor';\nimport { Post as PostType } from '@server/post/schemas/PostSchema';\nimport { PostService } from '@server/post/PostService';\nimport { CreatePostDto } from '@server/post/dto/CreatePostDto';\nimport { JwtAuthGuard } from '@server/auth/guards/JwtAuthGuard';\nimport { User } from '@server/decorators/UserDecorator';\nimport { User as UserType } from '@server/user/schemas/UserSchema';\nimport { CreateCommentDto } from '@server/comment/dto/CreateCommentDto';\nimport { CommentService } from '@server/comment/CommentService';\nimport { Comment } from '@server/comment/schemas/CommentSchema';\n\n@Controller(POST_CONTROLLER_ROUTE)\n@UseInterceptors(MongooseClassSerializerInterceptor(PostType))\nexport class PostController {\n constructor(private postService: PostService, private commentService: CommentService) { }\n\n @Get(POST_GET_ALL_ENDPOINT)\n public getPosts() {\n return this.postService.getAll();\n }\n\n @Get(POST_GET_ENDPOINT)\n public getPost(@Param('id') id: string) {\n return this.postService.getById(id);\n }\n\n @UseGuards(JwtAuthGuard)\n @Post(POST_CREATE_ENDPOINT)\n public createPost(@Body() createPostDto: CreatePostDto, @User() user: UserType) {\n return this.postService.create(createPostDto, user.id);\n }\n\n @UseGuards(JwtAuthGuard)\n @Put(POST_UPDATE_ENDPOINT)\n public updatePost(\n @Param('id') id: string,\n @Body() updatePostDto: CreatePostDto,\n @User() user: UserType,\n ) {\n return this.postService.update(id, updatePostDto, user.id);\n }\n\n @UseGuards(JwtAuthGuard)\n @Delete(POST_DELETE_ENDPOINT)\n public deletePost(@Param('id') id: string, @User() user: UserType) {\n return this.postService.delete(id, user.id);\n }\n\n @UseInterceptors(MongooseClassSerializerInterceptor(Comment))\n @UseGuards(JwtAuthGuard)\n @Post(POST_CREATE_COMMENT_ENDPOINT)\n public createPostComment(\n @Param('id') id: string,\n @Body() createCommentDto: CreateCommentDto,\n @User() user: UserType,\n ) {\n return this.commentService.create(createCommentDto, id, user.id);\n }\n}\n"
],
"version": 3
}

View File

@ -0,0 +1,110 @@
import _ts_decorate from "@swc/helpers/src/_ts_decorate.mjs";
import _ts_metadata from "@swc/helpers/src/_ts_metadata.mjs";
import _ts_param from "@swc/helpers/src/_ts_param.mjs";
import { Body, Controller, Delete, Get, Param, Post, Put, UseGuards, UseInterceptors } from '@nestjs/common';
import { POST_CONTROLLER_ROUTE, POST_DELETE_ENDPOINT, POST_GET_ALL_ENDPOINT, POST_GET_ENDPOINT, POST_CREATE_COMMENT_ENDPOINT, POST_CREATE_ENDPOINT, POST_UPDATE_ENDPOINT } from '@server/constants/controllers';
import { MongooseClassSerializerInterceptor } from '@server/interceptors/MongooseClassSerializerInterceptor';
import { Post as PostType } from '@server/post/schemas/PostSchema';
import { PostService } from '@server/post/PostService';
import { CreatePostDto } from '@server/post/dto/CreatePostDto';
import { JwtAuthGuard } from '@server/auth/guards/JwtAuthGuard';
import { User } from '@server/decorators/UserDecorator';
import { User as UserType } from '@server/user/schemas/UserSchema';
import { CreateCommentDto } from '@server/comment/dto/CreateCommentDto';
import { CommentService } from '@server/comment/CommentService';
import { Comment } from '@server/comment/schemas/CommentSchema';
export let PostController = class PostController {
constructor(postService, commentService){
this.postService = postService;
this.commentService = commentService;
}
getPosts() {
return this.postService.getAll();
}
getPost(id) {
return this.postService.getById(id);
}
createPost(createPostDto, user) {
return this.postService.create(createPostDto, user.id);
}
updatePost(id, updatePostDto, user) {
return this.postService.update(id, updatePostDto, user.id);
}
deletePost(id, user) {
return this.postService.delete(id, user.id);
}
createPostComment(id, createCommentDto, user) {
return this.commentService.create(createCommentDto, id, user.id);
}
};
_ts_decorate([
Get(POST_GET_ALL_ENDPOINT),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [])
], PostController.prototype, "getPosts", null);
_ts_decorate([
Get(POST_GET_ENDPOINT),
_ts_param(0, Param('id')),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
String
])
], PostController.prototype, "getPost", null);
_ts_decorate([
UseGuards(JwtAuthGuard),
Post(POST_CREATE_ENDPOINT),
_ts_param(0, Body()),
_ts_param(1, User()),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof CreatePostDto === "undefined" ? Object : CreatePostDto,
typeof UserType === "undefined" ? Object : UserType
])
], PostController.prototype, "createPost", null);
_ts_decorate([
UseGuards(JwtAuthGuard),
Put(POST_UPDATE_ENDPOINT),
_ts_param(0, Param('id')),
_ts_param(1, Body()),
_ts_param(2, User()),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
String,
typeof CreatePostDto === "undefined" ? Object : CreatePostDto,
typeof UserType === "undefined" ? Object : UserType
])
], PostController.prototype, "updatePost", null);
_ts_decorate([
UseGuards(JwtAuthGuard),
Delete(POST_DELETE_ENDPOINT),
_ts_param(0, Param('id')),
_ts_param(1, User()),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
String,
typeof UserType === "undefined" ? Object : UserType
])
], PostController.prototype, "deletePost", null);
_ts_decorate([
UseInterceptors(MongooseClassSerializerInterceptor(Comment)),
UseGuards(JwtAuthGuard),
Post(POST_CREATE_COMMENT_ENDPOINT),
_ts_param(0, Param('id')),
_ts_param(1, Body()),
_ts_param(2, User()),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
String,
typeof CreateCommentDto === "undefined" ? Object : CreateCommentDto,
typeof UserType === "undefined" ? Object : UserType
])
], PostController.prototype, "createPostComment", null);
PostController = _ts_decorate([
Controller(POST_CONTROLLER_ROUTE),
UseInterceptors(MongooseClassSerializerInterceptor(PostType)),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof PostService === "undefined" ? Object : PostService,
typeof CommentService === "undefined" ? Object : CommentService
])
], PostController);

View File

@ -0,0 +1,16 @@
{
"sourceMaps": true,
"jsc": {
"target": "es2022",
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"keepClassNames": true
}
}

View File

@ -0,0 +1,48 @@
import {
Controller,
Post,
UseGuards,
Body,
Put,
Param,
ForbiddenException,
UseInterceptors,
} from '@nestjs/common';
import {
USER_CONTROLLER_ROUTE,
USER_CREATE_ENDPOINT,
USER_UPDATE_ENDPOINT,
} from '@server/constants/controllers';
import { CreateUserDto } from '@server/user/dto/CreateUserDto';
import { UpdateUserDto } from '@server/user/dto/UpdateUserDto';
import { JwtAuthGuard } from '@server/auth/guards/JwtAuthGuard';
import { User } from '@server/decorators/UserDecorator';
import { User as UserType } from '@server/user/schemas/UserSchema';
import { MongooseClassSerializerInterceptor } from '@server/interceptors/MongooseClassSerializerInterceptor';
import { UserService } from '@server/user/UserService';
@Controller(USER_CONTROLLER_ROUTE)
@UseInterceptors(MongooseClassSerializerInterceptor(UserType))
export class UserController {
constructor(private userService: UserService) { }
@Post(USER_CREATE_ENDPOINT)
async signup(@Body() createUserDto: CreateUserDto) {
return this.userService.create(createUserDto);
}
@UseGuards(JwtAuthGuard)
@Put(USER_UPDATE_ENDPOINT)
async update(
@Param('id') userId: string,
@Body() updateUserDto: UpdateUserDto,
@User() user: UserType,
) {
if (user.id !== userId) {
throw new ForbiddenException();
}
return this.userService.update(userId, updateUserDto);
}
}

View File

@ -0,0 +1,41 @@
{
"mappings": "AAAA;;;AAAA,SACIA,UAAU,EACVC,IAAI,EACJC,SAAS,EACTC,IAAI,EACJC,GAAG,EACHC,KAAK,EACLC,kBAAkB,EAClBC,eAAe,QACZ,gBAAgB,CAAC;AAExB,SACIC,qBAAqB,EACrBC,oBAAoB,EACpBC,oBAAoB,QACjB,+BAA+B,CAAC;AACvC,SAASC,aAAa,QAAQ,gCAAgC,CAAC;AAC/D,SAASC,aAAa,QAAQ,gCAAgC,CAAC;AAC/D,SAASC,YAAY,QAAQ,kCAAkC,CAAC;AAChE,SAASC,IAAI,QAAQ,kCAAkC,CAAC;AACxD,SAASA,IAAI,IAAIC,QAAQ,QAAQ,iCAAiC,CAAC;AACnE,SAASC,kCAAkC,QAAQ,yDAAyD,CAAC;AAC7G,SAASC,WAAW,QAAQ,0BAA0B,CAAC;AAIvD,WAAaC,cAAc,GAApB;IACHC,YAAoBC,WAAwB,CAAE;QAA1BA,mBAAAA,WAAwB,CAAA;KAAK;UAG3CC,MAAM,CAAC,AAAQC,aAA4B,EAAE;QAC/C,OAAO,IAAI,CAACF,WAAW,CAACG,MAAM,CAACD,aAAa,CAAC,CAAC;KACjD;UAIKE,MAAM,CACR,AAAaC,MAAc,EAC3B,AAAQC,aAA4B,EACpC,AAAQC,IAAc,EACxB;QACE,IAAIA,IAAI,CAACC,EAAE,KAAKH,MAAM,EAAE;YACpB,MAAM,IAAInB,kBAAkB,EAAE,CAAC;SAClC;QAED,OAAO,IAAI,CAACc,WAAW,CAACI,MAAM,CAACC,MAAM,EAAEC,aAAa,CAAC,CAAC;KACzD;CACJ,CAAA;;IAlBIzB,IAAI,CAACQ,oBAAoB,CAAC;IACbN,aAAAA,IAAI,EAAE,CAAA;;;eAAgB,aAAa,4BAAb,aAAa;;GAJxCe,cAAc;;IAQtBhB,SAAS,CAACW,YAAY,CAAC;IACvBT,GAAG,CAACM,oBAAoB,CAAC;IAErBL,aAAAA,KAAK,CAAC,IAAI,CAAC,CAAA;IACXF,aAAAA,IAAI,EAAE,CAAA;IACNW,aAAAA,IAAI,EAAE,CAAA;;;;eADgB,aAAa,4BAAb,aAAa;eACtB,QAAQ,4BAAR,QAAQ;;GAbjBI,cAAc;AAAdA,cAAc;IAF1BlB,UAAU,CAACQ,qBAAqB,CAAC;IACjCD,eAAe,CAACS,kCAAkC,CAACD,QAAQ,CAAC,CAAC;;;eAEzB,WAAW,4BAAX,WAAW;;GADnCG,cAAc",
"names": [
"Controller",
"Post",
"UseGuards",
"Body",
"Put",
"Param",
"ForbiddenException",
"UseInterceptors",
"USER_CONTROLLER_ROUTE",
"USER_CREATE_ENDPOINT",
"USER_UPDATE_ENDPOINT",
"CreateUserDto",
"UpdateUserDto",
"JwtAuthGuard",
"User",
"UserType",
"MongooseClassSerializerInterceptor",
"UserService",
"UserController",
"constructor",
"userService",
"signup",
"createUserDto",
"create",
"update",
"userId",
"updateUserDto",
"user",
"id"
],
"sources": [
"../../input/UserController.ts"
],
"sourcesContent": [
"import {\n Controller,\n Post,\n UseGuards,\n Body,\n Put,\n Param,\n ForbiddenException,\n UseInterceptors,\n} from '@nestjs/common';\n\nimport {\n USER_CONTROLLER_ROUTE,\n USER_CREATE_ENDPOINT,\n USER_UPDATE_ENDPOINT,\n} from '@server/constants/controllers';\nimport { CreateUserDto } from '@server/user/dto/CreateUserDto';\nimport { UpdateUserDto } from '@server/user/dto/UpdateUserDto';\nimport { JwtAuthGuard } from '@server/auth/guards/JwtAuthGuard';\nimport { User } from '@server/decorators/UserDecorator';\nimport { User as UserType } from '@server/user/schemas/UserSchema';\nimport { MongooseClassSerializerInterceptor } from '@server/interceptors/MongooseClassSerializerInterceptor';\nimport { UserService } from '@server/user/UserService';\n\n@Controller(USER_CONTROLLER_ROUTE)\n@UseInterceptors(MongooseClassSerializerInterceptor(UserType))\nexport class UserController {\n constructor(private userService: UserService) { }\n\n @Post(USER_CREATE_ENDPOINT)\n async signup(@Body() createUserDto: CreateUserDto) {\n return this.userService.create(createUserDto);\n }\n\n @UseGuards(JwtAuthGuard)\n @Put(USER_UPDATE_ENDPOINT)\n async update(\n @Param('id') userId: string,\n @Body() updateUserDto: UpdateUserDto,\n @User() user: UserType,\n ) {\n if (user.id !== userId) {\n throw new ForbiddenException();\n }\n\n return this.userService.update(userId, updateUserDto);\n }\n}\n"
],
"version": 3
}

View File

@ -0,0 +1,55 @@
import _ts_decorate from "@swc/helpers/src/_ts_decorate.mjs";
import _ts_metadata from "@swc/helpers/src/_ts_metadata.mjs";
import _ts_param from "@swc/helpers/src/_ts_param.mjs";
import { Controller, Post, UseGuards, Body, Put, Param, ForbiddenException, UseInterceptors } from '@nestjs/common';
import { USER_CONTROLLER_ROUTE, USER_CREATE_ENDPOINT, USER_UPDATE_ENDPOINT } from '@server/constants/controllers';
import { CreateUserDto } from '@server/user/dto/CreateUserDto';
import { UpdateUserDto } from '@server/user/dto/UpdateUserDto';
import { JwtAuthGuard } from '@server/auth/guards/JwtAuthGuard';
import { User } from '@server/decorators/UserDecorator';
import { User as UserType } from '@server/user/schemas/UserSchema';
import { MongooseClassSerializerInterceptor } from '@server/interceptors/MongooseClassSerializerInterceptor';
import { UserService } from '@server/user/UserService';
export let UserController = class UserController {
constructor(userService){
this.userService = userService;
}
async signup(createUserDto) {
return this.userService.create(createUserDto);
}
async update(userId, updateUserDto, user) {
if (user.id !== userId) {
throw new ForbiddenException();
}
return this.userService.update(userId, updateUserDto);
}
};
_ts_decorate([
Post(USER_CREATE_ENDPOINT),
_ts_param(0, Body()),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof CreateUserDto === "undefined" ? Object : CreateUserDto
])
], UserController.prototype, "signup", null);
_ts_decorate([
UseGuards(JwtAuthGuard),
Put(USER_UPDATE_ENDPOINT),
_ts_param(0, Param('id')),
_ts_param(1, Body()),
_ts_param(2, User()),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
String,
typeof UpdateUserDto === "undefined" ? Object : UpdateUserDto,
typeof UserType === "undefined" ? Object : UserType
])
], UserController.prototype, "update", null);
UserController = _ts_decorate([
Controller(USER_CONTROLLER_ROUTE),
UseInterceptors(MongooseClassSerializerInterceptor(UserType)),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof UserService === "undefined" ? Object : UserService
])
], UserController);

View File

@ -4,7 +4,7 @@ use scoped_tls::scoped_thread_local;
use serde::{Deserialize, Serialize};
use swc_atoms::{js_word, JsWord};
use swc_common::{
ast_node, util::take::Take, EqIgnoreSpan, Span, Spanned, SyntaxContext, DUMMY_SP,
ast_node, util::take::Take, BytePos, EqIgnoreSpan, Span, Spanned, SyntaxContext, DUMMY_SP,
};
use unicode_id::UnicodeID;
@ -156,6 +156,13 @@ impl Ident {
EQ_IGNORE_SPAN_IGNORE_CTXT.set(&(), op)
}
/// Preserve syntax context while drop `span.lo` and `span.hi`.
pub fn without_loc(mut self) -> Ident {
self.span.lo = BytePos::DUMMY;
self.span.hi = BytePos::DUMMY;
self
}
/// Creates `Id` using `JsWord` and `SyntaxContext` of `self`.
pub fn to_id(&self) -> Id {
(self.sym.clone(), self.span.ctxt)

View File

@ -1293,7 +1293,7 @@ where
fn emit_class_method(&mut self, n: &ClassMethod) -> Result {
self.emit_leading_comments_of_span(n.span(), false)?;
srcmap!(n, true);
// srcmap!(n, true);
for d in &n.function.decorators {
emit!(d);
@ -1370,6 +1370,7 @@ where
Some(&n.function.params),
ListFormat::CommaListElements,
)?;
punct!(")");
if let Some(ty) = &n.function.return_type {

View File

@ -62,7 +62,7 @@ impl ParamMetadata {
Decorator {
span: DUMMY_SP,
expr: Box::new(Expr::Call(CallExpr {
span: DUMMY_SP,
span: decorator_expr.span(),
callee: helper!(ts, ts_param, "__param"),
args: vec![param_index.as_arg(), decorator_expr.as_arg()],
type_args: Default::default(),

View File

@ -122,6 +122,13 @@ impl TscDecorator {
return Expr::Ident(var_name);
}
PropName::Ident(i) => {
return Expr::Lit(Lit::Str(Str {
span: DUMMY_SP,
raw: None,
value: i.sym.clone(),
}))
}
_ => {}
}

View File

@ -1802,9 +1802,10 @@ where
extra_props.push(ident.id.clone());
}
let assign_expr = Box::new(Expr::Assign(AssignExpr {
span: DUMMY_SP,
span: ident.span.with_ctxt(SyntaxContext::empty()),
left: PatOrExpr::Expr(Box::new(
ThisExpr { span: DUMMY_SP }.make_member(ident.id.clone()),
ThisExpr { span: DUMMY_SP }
.make_member(ident.id.clone().without_loc()),
)),
op: op!("="),
right: Box::new(Expr::Ident(ident.id)),