Skip to content

Commit

Permalink
feat(schema): Add environment schemas and types along with tests. Als…
Browse files Browse the repository at this point in the history
…o modify project schemas to reflect new environment
  • Loading branch information
muntaxir4 authored and rajdip-b committed Nov 18, 2024
1 parent 1e58b39 commit 974d811
Show file tree
Hide file tree
Showing 8 changed files with 429 additions and 23 deletions.
8 changes: 0 additions & 8 deletions packages/schema/src/environment.ts

This file was deleted.

56 changes: 56 additions & 0 deletions packages/schema/src/environment/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { z } from 'zod'
import { PageRequestSchema, PageResponseSchema } from '@/pagination/pagination'

export const EnvironmentSchema = z.object({
id: z.string(),
name: z.string(),
slug: z.string(),
description: z.string().nullable(),
createdAt: z.string(),
updatedAt: z.string(),
lastUpdatedById: z.string(),
projectId: z.string()
})

export const CreateEnvironmentRequestSchema = z.object({
name: z.string(),
description: z.string().optional(),
projectId: z.string()
})

export const CreateEnvironmentResponseSchema = EnvironmentSchema

export const UpdateEnvironmentRequestSchema =
CreateEnvironmentRequestSchema.omit({ projectId: true })
.partial()
.extend({ slug: z.string() })

export const UpdateEnvironmentResponseSchema = EnvironmentSchema

export const GetEnvironmentRequestSchema = z.object({
slug: z.string()
})

export const GetEnvironmentResponseSchema = EnvironmentSchema

export const GetAllEnvironmentsOfProjectRequestSchema =
PageRequestSchema.extend({
projectSlug: z.string()
})

export const GetAllEnvironmentsOfProjectResponseSchema = PageResponseSchema(
EnvironmentSchema.extend({
lastUpdatedBy: z.object({
id: z.string(),
name: z.string(),
email: z.string(),
profilePictureUrl: z.string().nullable()
})
})
)

export const DeleteEnvironmentRequestSchema = z.object({
slug: z.string()
})

export const DeleteEnvironmentResponseSchema = z.void()
54 changes: 54 additions & 0 deletions packages/schema/src/environment/environment.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { z } from 'zod'
import {
EnvironmentSchema,
CreateEnvironmentRequestSchema,
CreateEnvironmentResponseSchema,
UpdateEnvironmentRequestSchema,
UpdateEnvironmentResponseSchema,
GetEnvironmentRequestSchema,
GetEnvironmentResponseSchema,
GetAllEnvironmentsOfProjectRequestSchema,
GetAllEnvironmentsOfProjectResponseSchema,
DeleteEnvironmentRequestSchema,
DeleteEnvironmentResponseSchema
} from './environment'

export type Environment = z.infer<typeof EnvironmentSchema>

export type CreateEnvironmentRequest = z.infer<
typeof CreateEnvironmentRequestSchema
>

export type CreateEnvironmentResponse = z.infer<
typeof CreateEnvironmentResponseSchema
>

export type UpdateEnvironmentRequest = z.infer<
typeof UpdateEnvironmentRequestSchema
>

export type UpdateEnvironmentResponse = z.infer<
typeof UpdateEnvironmentResponseSchema
>

export type GetEnvironmentRequest = z.infer<typeof GetEnvironmentRequestSchema>

export type GetEnvironmentResponse = z.infer<
typeof GetEnvironmentResponseSchema
>

export type GetAllEnvironmentsOfProjectRequest = z.infer<
typeof GetAllEnvironmentsOfProjectRequestSchema
>

export type GetAllEnvironmentsOfProjectResponse = z.infer<
typeof GetAllEnvironmentsOfProjectResponseSchema
>

export type DeleteEnvironmentRequest = z.infer<
typeof DeleteEnvironmentRequestSchema
>

export type DeleteEnvironmentResponse = z.infer<
typeof DeleteEnvironmentResponseSchema
>
3 changes: 2 additions & 1 deletion packages/schema/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export * from './api-key'

export * from './auth/auth'

export * from './environment'
export * from './environment/environment'

export * from './integration'

export * from './project/project'
Expand Down
5 changes: 2 additions & 3 deletions packages/schema/src/index.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { z } from 'zod'
import { CreateApiKeySchema, UpdateApiKeySchema } from './api-key'
import { CreateEnvironmentSchema, UpdateEnvironmentSchema } from './environment'
import { CreateIntegrationSchema, UpdateIntegrationSchema } from './integration'
import { CreateSecretSchema, UpdateSecretSchema } from './secret'
import { CreateVariableSchema, UpdateVariableSchema } from './variable'
Expand All @@ -18,8 +17,8 @@ export type TUpdateApiKey = z.infer<typeof UpdateApiKeySchema>
// Export types from auth.types.ts
export * from './auth/auth.types'

export type TCreateEnvironment = z.infer<typeof CreateEnvironmentSchema>
export type TUpdateEnvironment = z.infer<typeof UpdateEnvironmentSchema>
// Export types from environment.types.ts
export * from './environment/environment.types'

export type TCreateIntegration = z.infer<typeof CreateIntegrationSchema>
export type TUpdateIntegration = z.infer<typeof UpdateIntegrationSchema>
Expand Down
4 changes: 2 additions & 2 deletions packages/schema/src/project/project.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from 'zod'
import { PageRequestSchema, PageResponseSchema } from '@/pagination/pagination'
import { CreateEnvironmentSchema } from '@/environment'
import { CreateEnvironmentRequestSchema } from '@/environment/environment'
import { projectAccessLevelEnum } from '@/enums'

export const ProjectSchema = z
Expand Down Expand Up @@ -31,7 +31,7 @@ export const CreateProjectRequestSchema = z.object({
workspaceSlug: z.string(),
description: z.string().optional(),
storePrivateKey: z.boolean().optional(),
environments: CreateEnvironmentSchema.array().optional(),
environments: CreateEnvironmentRequestSchema.array().optional(),
accessLevel: projectAccessLevelEnum
})

Expand Down
Loading

0 comments on commit 974d811

Please sign in to comment.