-
-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): implements cloud function template & templates marketpl…
…ace (#1259) * feat(server): add function template market * refactor(server): refactor auth api(profile/pat) (#1226) * feat(server): add function template market * chore(server: Interface aggregation) * chore(server: add metering) * change some interface --------- Co-authored-by: maslow <wangfugen@126.com>
- Loading branch information
Showing
14 changed files
with
2,301 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
server/src/function-template/dto/create-function-template.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { CreateEnvironmentDto } from '../../application/dto/create-env.dto' | ||
import { CreateDependencyDto } from 'src/dependency/dto/create-dependency.dto' | ||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger' | ||
import { | ||
IsBoolean, | ||
IsIn, | ||
IsNotEmpty, | ||
IsString, | ||
Matches, | ||
MaxLength, | ||
ValidateNested, | ||
} from 'class-validator' | ||
import { Type } from 'class-transformer' | ||
import { HTTP_METHODS } from '../../constants' | ||
import { HttpMethod } from '../../function/entities/cloud-function' | ||
export class FunctionTemplateItemDto { | ||
@ApiProperty({ | ||
description: 'FunctionTemplate item name', | ||
}) | ||
@IsNotEmpty() | ||
@Matches(/^[a-zA-Z0-9_.\-\/]{1,256}$/) | ||
name: string | ||
|
||
@ApiPropertyOptional() | ||
@MaxLength(256) | ||
description?: string | ||
|
||
@ApiProperty({ type: [String], enum: HttpMethod }) | ||
@IsIn(HTTP_METHODS, { each: true }) | ||
methods: HttpMethod[] = [] | ||
|
||
@ApiProperty({ description: 'The source code of the function' }) | ||
@IsNotEmpty() | ||
@IsString() | ||
@MaxLength(1024 * 512) | ||
code: string | ||
|
||
validate() { | ||
return null | ||
} | ||
} | ||
|
||
export class CreateFunctionTemplateDto { | ||
@ApiProperty({ description: 'function template name' }) | ||
@IsNotEmpty() | ||
@IsString() | ||
@MaxLength(64) | ||
name: string | ||
|
||
@ApiProperty({ description: 'Dependencies', type: [CreateDependencyDto] }) | ||
@IsNotEmpty() | ||
@ValidateNested({ each: true }) | ||
@Type(() => CreateDependencyDto) | ||
dependencies: CreateDependencyDto[] | ||
|
||
@ApiProperty({ description: 'environments', type: [CreateEnvironmentDto] }) | ||
@ValidateNested({ each: true }) | ||
@Type(() => CreateEnvironmentDto) | ||
environments: CreateEnvironmentDto[] | ||
|
||
@ApiProperty({ description: 'Private flag' }) | ||
@IsBoolean() | ||
private: boolean | ||
|
||
@ApiPropertyOptional({ description: 'function template description' }) | ||
@IsString() | ||
@MaxLength(256) | ||
description?: string | ||
|
||
@ApiProperty({ | ||
description: 'items of the function template', | ||
type: [FunctionTemplateItemDto], | ||
}) | ||
@IsNotEmpty() | ||
@ValidateNested({ each: true }) | ||
@Type(() => FunctionTemplateItemDto) | ||
items: FunctionTemplateItemDto[] | ||
} |
56 changes: 56 additions & 0 deletions
56
server/src/function-template/dto/update-function-template.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { ObjectId } from 'mongodb' | ||
import { CreateEnvironmentDto } from '../../application/dto/create-env.dto' | ||
import { CreateDependencyDto } from 'src/dependency/dto/create-dependency.dto' | ||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger' | ||
import { | ||
IsBoolean, | ||
IsNotEmpty, | ||
IsString, | ||
Length, | ||
MaxLength, | ||
ValidateNested, | ||
} from 'class-validator' | ||
import { Type } from 'class-transformer' | ||
import { FunctionTemplateItemDto } from './create-function-template.dto' | ||
|
||
export class UpdateFunctionTemplateDto { | ||
@ApiProperty({ description: 'Function template id' }) | ||
@IsNotEmpty() | ||
@Length(24, 24) | ||
functionTemplateId: ObjectId | ||
|
||
@ApiProperty({ description: 'Template name' }) | ||
@IsNotEmpty() | ||
@MaxLength(64) | ||
@IsString() | ||
name: string | ||
|
||
@ApiProperty({ description: 'Dependencies', type: [CreateDependencyDto] }) | ||
@IsNotEmpty() | ||
@ValidateNested({ each: true }) | ||
@Type(() => CreateDependencyDto) | ||
dependencies: CreateDependencyDto[] | ||
|
||
@ApiProperty({ description: 'Environments', type: [CreateEnvironmentDto] }) | ||
@ValidateNested({ each: true }) | ||
@Type(() => CreateEnvironmentDto) | ||
environments: CreateEnvironmentDto[] | ||
|
||
@ApiProperty({ description: 'Private flag' }) | ||
@IsBoolean() | ||
private: boolean | ||
|
||
@ApiPropertyOptional({ description: 'function template description' }) | ||
@IsString() | ||
@MaxLength(256) | ||
description?: string | ||
|
||
@ApiPropertyOptional({ | ||
description: 'items of the function template', | ||
type: [FunctionTemplateItemDto], | ||
}) | ||
@IsNotEmpty() | ||
@ValidateNested({ each: true }) | ||
@Type(() => FunctionTemplateItemDto) | ||
items: FunctionTemplateItemDto[] | ||
} |
17 changes: 17 additions & 0 deletions
17
server/src/function-template/dto/use-function-template.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ApiProperty } from '@nestjs/swagger' | ||
import { IsNotEmpty, Length } from 'class-validator' | ||
import { ObjectId } from 'mongodb' | ||
|
||
export class UseFunctionTemplateDto { | ||
@ApiProperty({ | ||
description: 'The ObjectId of function template', | ||
type: 'string', | ||
}) | ||
@IsNotEmpty() | ||
@Length(24, 24) | ||
functionTemplateId: ObjectId | ||
|
||
@IsNotEmpty() | ||
@ApiProperty() | ||
appid: string | ||
} |
107 changes: 107 additions & 0 deletions
107
server/src/function-template/entities/function-template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger' | ||
import { | ||
CloudFunctionSource, | ||
HttpMethod, | ||
} from 'src/function/entities/cloud-function' | ||
import { EnvironmentVariable } from 'src/application/entities/application-configuration' | ||
import { ObjectId } from 'mongodb' | ||
|
||
export enum RelationState { | ||
Enabled = 'Active', | ||
Disabled = 'Inactive', | ||
} | ||
|
||
export class FunctionTemplate { | ||
@ApiProperty({ type: String }) | ||
_id?: ObjectId | ||
|
||
@ApiProperty({ type: String }) | ||
uid: ObjectId | ||
|
||
@ApiProperty() | ||
name: string | ||
|
||
@ApiProperty() | ||
dependencies: string[] | ||
|
||
@ApiProperty({ isArray: true, type: EnvironmentVariable }) | ||
environments: EnvironmentVariable[] | ||
|
||
@ApiProperty() | ||
private: boolean | ||
|
||
@ApiProperty() | ||
isRecommended: boolean | ||
|
||
@ApiProperty() | ||
description: string | ||
|
||
@ApiProperty() | ||
star: number | ||
|
||
@ApiProperty() | ||
createdAt: Date | ||
|
||
@ApiProperty() | ||
updatedAt: Date | ||
|
||
@ApiPropertyOptional() | ||
tags?: string[] | ||
|
||
@ApiPropertyOptional() | ||
category?: string | ||
} | ||
|
||
export class FunctionTemplateItem { | ||
@ApiProperty({ type: String }) | ||
_id?: ObjectId | ||
|
||
@ApiProperty({ type: String }) | ||
templateId: ObjectId | ||
|
||
@ApiProperty() | ||
name: string | ||
|
||
@ApiProperty() | ||
desc: string | ||
|
||
@ApiProperty() | ||
source: Partial<CloudFunctionSource> | ||
|
||
@ApiProperty({ type: [String], enum: HttpMethod }) | ||
methods: HttpMethod[] | ||
|
||
createdAt: Date | ||
|
||
updatedAt: Date | ||
} | ||
|
||
export class FunctionTemplateStarRelation { | ||
@ApiProperty({ type: String }) | ||
_id?: ObjectId | ||
@ApiProperty({ type: String }) | ||
uid: ObjectId | ||
@ApiProperty({ type: String }) | ||
templateId: ObjectId | ||
@ApiProperty() | ||
createdAt: Date | ||
@ApiProperty() | ||
updatedAt: Date | ||
@ApiProperty({ type: String }) | ||
state?: RelationState | ||
} | ||
|
||
export class FunctionTemplateUseRelation { | ||
@ApiProperty({ type: String }) | ||
_id?: ObjectId | ||
@ApiProperty({ type: String }) | ||
uid: ObjectId | ||
@ApiProperty({ type: String }) | ||
templateId: ObjectId | ||
@ApiProperty() | ||
createdAt: Date | ||
@ApiProperty() | ||
updatedAt: Date | ||
@ApiProperty({ type: String }) | ||
state?: RelationState | ||
} |
Oops, something went wrong.