Skip to content

Commit

Permalink
feat(schema, api-client): Migrate project schemas and environment sch…
Browse files Browse the repository at this point in the history
…emas along with their types to @keyshade/schema (keyshade-xyz#538)
  • Loading branch information
muntaxir4 authored Nov 18, 2024
1 parent c24695e commit c468af0
Show file tree
Hide file tree
Showing 14 changed files with 1,145 additions and 212 deletions.
2 changes: 1 addition & 1 deletion packages/api-client/src/controllers/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
GetEnvironmentResponse,
UpdateEnvironmentRequest,
UpdateEnvironmentResponse
} from '@api-client/types/environment.types'
} from '@keyshade/schema'
import { ClientResponse } from '@keyshade/schema'

export default class EnvironmentController {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/controllers/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
UnlinkProjectResponse,
UpdateProjectRequest,
UpdateProjectResponse
} from '@api-client/types/project.types'
} from '@keyshade/schema'
import { parseResponse } from '@api-client/core/response-parser'
import { parsePaginationUrl } from '@api-client/core/pagination-parser'

Expand Down
55 changes: 0 additions & 55 deletions packages/api-client/src/types/environment.types.d.ts

This file was deleted.

87 changes: 0 additions & 87 deletions packages/api-client/src/types/project.types.d.ts

This file was deleted.

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/index.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/index.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 '.'

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
>
1 change: 0 additions & 1 deletion packages/schema/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export * from './api-key'
export * from './auth/auth'

export * from './enums'

export * from './environment'
export * from './integration'
export * from './project'
Expand Down
13 changes: 2 additions & 11 deletions packages/schema/src/index.types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { z } from 'zod'
import { CreateApiKeySchema, UpdateApiKeySchema } from './api-key'
import { CreateEnvironmentSchema, UpdateEnvironmentSchema } from './environment'
import { CreateIntegrationSchema, UpdateIntegrationSchema } from './integration'
import {
CreateProjectSchema,
ForkProjectSchema,
UpdateProjectSchema
} from './project'
import { CreateSecretSchema, UpdateSecretSchema } from './secret'
import { CreateVariableSchema, UpdateVariableSchema } from './variable'
import {
Expand All @@ -23,15 +17,12 @@ 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 * from './environment/index.types'

export type TCreateIntegration = z.infer<typeof CreateIntegrationSchema>
export type TUpdateIntegration = z.infer<typeof UpdateIntegrationSchema>

export type TCreateProject = z.infer<typeof CreateProjectSchema>
export type TUpdateProject = z.infer<typeof UpdateProjectSchema>
export type TForkProject = z.infer<typeof ForkProjectSchema>
export * from './project/index.types'

export type TCreateSecret = z.infer<typeof CreateSecretSchema>
export type TUpdateSecret = z.infer<typeof UpdateSecretSchema>
Expand Down
19 changes: 0 additions & 19 deletions packages/schema/src/project.ts

This file was deleted.

Loading

0 comments on commit c468af0

Please sign in to comment.