Skip to content

Commit

Permalink
feat(schema, api-client): Migrate variable schemas and types to @keys…
Browse files Browse the repository at this point in the history
…hade/schema (#545)
  • Loading branch information
muntaxir4 authored Nov 20, 2024
1 parent 40008e3 commit 0ee8f9a
Show file tree
Hide file tree
Showing 11 changed files with 681 additions and 189 deletions.
2 changes: 1 addition & 1 deletion packages/api-client/src/controllers/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
RollBackVariableResponse,
UpdateVariableRequest,
UpdateVariableResponse
} from '@api-client/types/variable.types'
} from '@keyshade/schema'

export default class VariableController {
private apiClient: APIClient
Expand Down
131 changes: 0 additions & 131 deletions packages/api-client/src/types/variable.types.d.ts

This file was deleted.

8 changes: 8 additions & 0 deletions packages/schema/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.turbo/
src/
tests/
eslintrc.js
jest.config.ts
tsconfig.json
tsconfig.spec.json
node_modules/
5 changes: 1 addition & 4 deletions packages/schema/src/index.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { z } from 'zod'
import { CreateApiKeySchema, UpdateApiKeySchema } from './api-key'
import { CreateIntegrationSchema, UpdateIntegrationSchema } from './integration'
import { CreateVariableSchema, UpdateVariableSchema } from './variable'
import {
CreateWorkspaceRoleSchema,
UpdateWorkspaceRoleSchema
Expand All @@ -14,15 +13,13 @@ export * from './project/index.types'
export * from './secret/index.types'
export * from './user/index.types'
export * from './workspace/index.types'
export * from './variable/index.types'

export type TCreateApiKey = z.infer<typeof CreateApiKeySchema>
export type TUpdateApiKey = z.infer<typeof UpdateApiKeySchema>

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

export type TCreateVariable = z.infer<typeof CreateVariableSchema>
export type TUpdateVariable = z.infer<typeof UpdateVariableSchema>

export type TCreateWorkspaceRole = z.infer<typeof CreateWorkspaceRoleSchema>
export type TUpdateWorkspaceRole = z.infer<typeof UpdateWorkspaceRoleSchema>
14 changes: 0 additions & 14 deletions packages/schema/src/variable.ts

This file was deleted.

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

export const VariableSchema = z.object({
id: z.string(),
name: z.string(),
slug: z.string(),
createdAt: z.string(),
updatedAt: z.string(),
note: z.string().nullable(),
lastUpdatedById: z.string(),
projectId: z.string(),
project: z.object({
workspaceId: z.string()
}),
versions: z.array(
z.object({
value: z.string(),
environmentId: z.string(),
environment: z.object({
id: z.string(),
slug: z.string()
})
})
)
})

export const CreateVariableRequestSchema = z.object({
projectSlug: z.string(),
name: z.string(),
note: z.string().optional(),
entries: z
.array(
z.object({
value: z.string(),
environmentSlug: z.string()
})
)
.optional()
})

export const CreateVariableResponseSchema = VariableSchema

export const UpdateVariableRequestSchema = z.object({
variableSlug: z.string(),
name: z.string().optional(),
note: z.string().optional(),
entries: z
.array(
z.object({
value: z.string(),
environmentSlug: z.string()
})
)
.optional()
})

export const UpdateVariableResponseSchema = z.object({
variable: VariableSchema.pick({
id: true,
name: true,
slug: true,
note: true
}),
updatedVersions: z.array(
z.object({
value: z.string(),
environmentId: z.string(),
environment: z.object({
id: z.string(),
slug: z.string()
})
})
)
})

export const RollBackVariableRequestSchema = z.object({
variableSlug: z.string(),
version: z.number(),
environmentSlug: z.string()
})

export const RollBackVariableResponseSchema = z.object({
count: z.string()
})

export const DeleteVariableRequestSchema = z.object({
variableSlug: z.string()
})

export const DeleteVariableResponseSchema = z.void()

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

export const GetAllVariablesOfProjectResponseSchema = PageResponseSchema(
VariableSchema.omit({ project: true, versions: true }).extend({
variable: z.object({
lastUpdatedBy: z.object({
id: z.string(),
name: z.string()
})
}),
values: z.array(
z.object({
environment: z.object({
id: z.string(),
name: z.string(),
slug: z.string()
}),
value: z.string(),
version: z.number()
})
)
})
)

export const GetAllVariablesOfEnvironmentRequestSchema = z.object({
projectSlug: z.string(),
environmentSlug: z.string()
})

export const GetAllVariablesOfEnvironmentResponseSchema = z.array(
z.object({
name: z.string(),
value: z.string(),
isPlaintext: z.boolean()
})
)

export const GetRevisionsOfVariableRequestSchema =
PageRequestSchema.partial().extend({
variableSlug: z.string(),
environmentSlug: z.string()
})

export const GetRevisionsOfVariableResponseSchema = PageResponseSchema(
z.object({
id: z.string(),
value: z.string(),
version: z.number(),
variableId: z.string(),
createdOn: z.string(),
createdById: z.string(),
environmentId: z.string()
})
)
Loading

0 comments on commit 0ee8f9a

Please sign in to comment.