first commit

This commit is contained in:
root
2025-12-05 07:14:11 +00:00
commit 2ed4393eb9
129 changed files with 20524 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
{
"name": "@sigma/common",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"build": "tsc",
"format": "prettier -w src"
},
"exports": {
"import": "./dist/lib.js",
"types": "./dist/lib.d.ts"
},
"dependencies": {
"@nestjs/mapped-types": "^2.1.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.2"
},
"devDependencies": {
"prettier": "^3.6.2",
"typescript": "^5.9.3"
}
}

View File

@@ -0,0 +1,7 @@
import { IsNotEmpty, IsNumber } from "class-validator";
export class CpuInfoDto {
@IsNumber()
@IsNotEmpty()
usage!: number;
}

View File

@@ -0,0 +1,36 @@
import {
IsArray,
IsNotEmpty,
IsOptional,
IsString,
IsUppercase,
Matches,
} from "class-validator";
export class CreateFunctionDto {
@IsNotEmpty()
@IsString()
name!: string;
@IsNotEmpty()
@IsString()
@Matches(
/^\/(?:$|(?:[A-Za-z0-9._~-]+|:[A-Za-z0-9_]+)(?:\/(?:[A-Za-z0-9._~-]+|:[A-Za-z0-9_]+))*)$/,
{
message:
"path must be a valid endpoint path (e.g. / or /hello/world/:id)",
}
)
path!: string;
@IsOptional()
@IsNotEmpty()
@IsString()
code?: string;
@IsOptional()
@IsArray()
@IsString({ each: true })
@IsUppercase({ each: true })
methods?: string[];
}

View File

@@ -0,0 +1,26 @@
import {
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
Min,
} from "class-validator";
export class CreateProjectDto {
@IsNotEmpty()
@IsString()
name!: string;
@IsNotEmpty()
@IsString()
slug!: string;
@IsNotEmpty()
@IsString()
description!: string;
@IsOptional()
@IsNumber()
@Min(1)
cpuTimeQuotaMsPerMinute?: number;
}

View File

@@ -0,0 +1,11 @@
export * from "./cpu-info.dto.js";
export * from "./create-function.dto.js";
export * from "./create-project.dto.js";
export * from "./function.dto.js";
export * from "./project.dto.js";
export * from "./query-project.dto.js";
export * from "./register-user.dto.js";
export * from "./update-function.dto.js";
export * from "./update-project.dto.js";
export * from "./update-user.dto.js";
export * from "./user.dto.js";

View File

@@ -0,0 +1,39 @@
import {
IsArray,
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
} from "class-validator";
export class FunctionDto {
@IsString()
@IsNotEmpty()
_id!: string;
@IsString()
@IsNotEmpty()
name!: string;
@IsString()
@IsNotEmpty()
path!: string;
@IsArray()
methods!: string[];
@IsString()
@IsOptional()
code?: string;
@IsNumber()
invocations!: number;
@IsNumber()
errors!: number;
@IsArray()
logs!: string[];
lastInvocation?: Date;
}

View File

@@ -0,0 +1,45 @@
import { Type } from "class-transformer";
import {
IsArray,
IsDateString,
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
ValidateNested,
} from "class-validator";
import { FunctionDto } from "./function.dto.js";
export class ProjectDto {
@IsNotEmpty()
_id!: string;
@IsNotEmpty()
name!: string;
@IsNotEmpty()
slug!: string;
@IsOptional()
description?: string;
@IsNumber()
cpuTimeQuotaMsPerMinute!: number;
@IsDateString()
cpuTimeWindowStartedAt!: string;
@IsNumber()
cpuTimeUsedMs!: number;
@IsNumber()
functionsInvocationCount!: number;
@IsNumber()
functionsErrorCount!: number;
@IsArray()
@ValidateNested({ each: true })
@Type(() => FunctionDto)
functions!: FunctionDto[];
}

View File

@@ -0,0 +1,4 @@
import { PartialType } from "@nestjs/mapped-types";
import { ProjectDto } from "./project.dto.js";
export class QueryProjectDto extends PartialType(ProjectDto) {}

View File

@@ -0,0 +1,11 @@
import { IsNotEmpty, IsString, MinLength } from "class-validator";
export class RegisterUserDto {
@IsNotEmpty()
@IsString()
username!: string;
@MinLength(8)
@IsString()
password!: string;
}

View File

@@ -0,0 +1,4 @@
import { PartialType } from "@nestjs/mapped-types";
import { CreateFunctionDto } from "./create-function.dto.js";
export class UpdateFunctionDto extends PartialType(CreateFunctionDto) {}

View File

@@ -0,0 +1,4 @@
import { PartialType } from "@nestjs/mapped-types";
import { CreateProjectDto } from "./create-project.dto.js";
export class UpdateProjectDto extends PartialType(CreateProjectDto) {}

View File

@@ -0,0 +1,4 @@
import { PickType } from "@nestjs/mapped-types";
import { RegisterUserDto } from "./register-user.dto.js";
export class UpdateUserDto extends PickType(RegisterUserDto, ["password"]) {}

View File

@@ -0,0 +1,7 @@
import { IsNotEmpty, IsString } from "class-validator";
export class UserDto {
@IsNotEmpty()
@IsString()
username!: string;
}

View File

@@ -0,0 +1 @@
export * from "./dto/dto.js";

View File

@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
}