Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions apps/sim/lib/api/contracts/project-file-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ import { z } from 'zod'
import { persistFileDocResponseSchema } from '@/lib/api/contracts/file-doc'
import { defineRouteContract } from '@/lib/api/contracts/types'

export const projectFileDocParamsSchema = z.object({
const projectFileDocParamsSchema = z.object({
projectId: z.string().min(1),
fileId: z.string().min(1),
})
export type ProjectFileDocParams = z.output<typeof projectFileDocParamsSchema>

export const projectFileDocAccessResponseSchema = z.object({
const projectFileDocAccessResponseSchema = z.object({
projectId: z.string(),
fileId: z.string(),
canRead: z.literal(true),
canWrite: z.boolean(),
docId: z.string().min(1).max(128).nullable(),
})
export type ProjectFileDocAccessResponse = z.output<typeof projectFileDocAccessResponseSchema>

export const projectFileDocAccessContract = defineRouteContract({
method: 'POST',
Expand All @@ -24,11 +22,10 @@ export const projectFileDocAccessContract = defineRouteContract({
response: { mode: 'json', schema: projectFileDocAccessResponseSchema },
})

export const projectFileDocSeedResponseSchema = z.object({
const projectFileDocSeedResponseSchema = z.object({
update: z.string(),
version: z.number().int(),
})
export type ProjectFileDocSeedResponse = z.output<typeof projectFileDocSeedResponseSchema>

export const projectFileDocSeedContract = defineRouteContract({
method: 'POST',
Expand All @@ -37,7 +34,7 @@ export const projectFileDocSeedContract = defineRouteContract({
response: { mode: 'json', schema: projectFileDocSeedResponseSchema },
})

export const projectFileDocPersistBodySchema = z
const projectFileDocPersistBodySchema = z
.object({
docState: z
.string()
Expand All @@ -46,7 +43,6 @@ export const projectFileDocPersistBodySchema = z
expectedVersion: z.number().int().optional(),
})
.strict()
export type ProjectFileDocPersistBody = z.input<typeof projectFileDocPersistBodySchema>

export const projectFileDocPersistContract = defineRouteContract({
method: 'POST',
Expand Down
7 changes: 2 additions & 5 deletions apps/sim/lib/api/contracts/project-file-folders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
export const projectFileFolderParamsSchema = projectFilesParamsSchema.extend({
folderId: nonEmptyIdSchema,
})
export type ProjectFileFolderParams = z.input<typeof projectFileFolderParamsSchema>

export const projectFileFolderRecordSchema = workspaceFileFolderSchema
.omit({ workspaceId: true })
Expand All @@ -28,11 +27,10 @@ export type ProjectFileFolderRecord = z.output<typeof projectFileFolderRecordSch
export const listProjectFileFoldersQuerySchema = listWorkspaceFileFoldersQuerySchema
export type ListProjectFileFoldersQuery = z.output<typeof listProjectFileFoldersQuerySchema>

export const listProjectFileFoldersResponseSchema = z.object({
const listProjectFileFoldersResponseSchema = z.object({
folders: z.array(projectFileFolderRecordSchema),
capabilities: projectFileCapabilitiesSchema,
})
export type ListProjectFileFoldersResponse = z.output<typeof listProjectFileFoldersResponseSchema>

export const listProjectFileFoldersContract = defineRouteContract({
method: 'GET',
Expand All @@ -48,8 +46,7 @@ export type CreateProjectFileFolderBody = z.input<typeof createProjectFileFolder
export const updateProjectFileFolderBodySchema = updateWorkspaceFileFolderBodySchema
export type UpdateProjectFileFolderBody = z.input<typeof updateProjectFileFolderBodySchema>

export const projectFileFolderResponseSchema = z.object({ folder: projectFileFolderRecordSchema })
export type ProjectFileFolderResponse = z.output<typeof projectFileFolderResponseSchema>
const projectFileFolderResponseSchema = z.object({ folder: projectFileFolderRecordSchema })

export const createProjectFileFolderContract = defineRouteContract({
method: 'POST',
Expand Down
15 changes: 4 additions & 11 deletions apps/sim/lib/api/contracts/project-file-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import {
} from '@/lib/api/contracts/workspace-file-folders'
import { renameWorkspaceFileBodySchema } from '@/lib/api/contracts/workspace-files'

export const renameProjectFileBodySchema = renameWorkspaceFileBodySchema.strict()
const renameProjectFileBodySchema = renameWorkspaceFileBodySchema.strict()
export type RenameProjectFileBody = z.input<typeof renameProjectFileBodySchema>

export const renameProjectFileResponseSchema = z.object({ file: projectFileRecordSchema })
export type RenameProjectFileResponse = z.output<typeof renameProjectFileResponseSchema>
const renameProjectFileResponseSchema = z.object({ file: projectFileRecordSchema })

export const renameProjectFileContract = defineRouteContract({
method: 'PATCH',
Expand All @@ -30,7 +29,7 @@ export const renameProjectFileContract = defineRouteContract({
response: { mode: 'json', schema: renameProjectFileResponseSchema },
})

export const moveProjectFileItemsBodySchema = moveWorkspaceFileItemsBodySchema.strict()
const moveProjectFileItemsBodySchema = moveWorkspaceFileItemsBodySchema.strict()
export type MoveProjectFileItemsBody = z.input<typeof moveProjectFileItemsBodySchema>

export const moveProjectFileItemsResponseSchema = z.object({
Expand All @@ -39,7 +38,6 @@ export const moveProjectFileItemsResponseSchema = z.object({
movedFileIds: z.array(nonEmptyIdSchema).describe('Identifiers of moved files.'),
movedFolderIds: z.array(nonEmptyIdSchema).describe('Identifiers of moved folders.'),
})
export type MoveProjectFileItemsResponse = z.output<typeof moveProjectFileItemsResponseSchema>

export const moveProjectFileItemsContract = defineRouteContract({
method: 'POST',
Expand All @@ -66,7 +64,6 @@ export const archiveProjectFileItemsResponseSchema = z.object({
})
.describe('Identifiers of affected file items.'),
})
export type ArchiveProjectFileItemsResponse = z.output<typeof archiveProjectFileItemsResponseSchema>

export const archiveProjectFileItemsContract = defineRouteContract({
method: 'POST',
Expand All @@ -76,11 +73,10 @@ export const archiveProjectFileItemsContract = defineRouteContract({
response: { mode: 'json', schema: archiveProjectFileItemsResponseSchema },
})

export const restoreProjectFileResponseSchema = z.object({
const restoreProjectFileResponseSchema = z.object({
restored: z.literal(true),
file: projectFileRecordSchema,
})
export type RestoreProjectFileResponse = z.output<typeof restoreProjectFileResponseSchema>

export const restoreProjectFileContract = defineRouteContract({
method: 'POST',
Expand All @@ -99,9 +95,6 @@ export const restoreProjectFileFolderResponseSchema = z.object({
})
.describe('Counts of affected file items.'),
})
export type RestoreProjectFileFolderResponse = z.output<
typeof restoreProjectFileFolderResponseSchema
>

export const restoreProjectFileFolderContract = defineRouteContract({
method: 'POST',
Expand Down
9 changes: 3 additions & 6 deletions apps/sim/lib/api/contracts/project-file-uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@ import {
v2UploadTransferSchema,
} from '@/lib/api/contracts/v2/uploads'

export const projectFileUploadParamsSchema = projectFilesParamsSchema.extend({
const projectFileUploadParamsSchema = projectFilesParamsSchema.extend({
uploadId: nonEmptyIdSchema,
})
export type ProjectFileUploadParams = z.input<typeof projectFileUploadParamsSchema>

export const createProjectFileUploadBodySchema = v2CreateFileUploadBodySchema
.omit({ workspaceId: true })
.extend({ folderId: folderIdSchema.nullish() })
.strict()
export type CreateProjectFileUploadBody = z.input<typeof createProjectFileUploadBodySchema>

export const projectFileUploadSessionSchema = z
const projectFileUploadSessionSchema = z
.object({
id: nonEmptyIdSchema,
purpose: z.literal('project_file'),
Expand All @@ -40,14 +38,13 @@ export const projectFileUploadSessionSchema = z
.strict()
export type ProjectFileUploadSession = z.output<typeof projectFileUploadSessionSchema>

export const createProjectFileUploadResponseSchema = z
const createProjectFileUploadResponseSchema = z
.object({
session: projectFileUploadSessionSchema,
uploadToken: z.string().min(1),
transfer: v2UploadTransferSchema,
})
.strict()
export type CreateProjectFileUploadResponse = z.output<typeof createProjectFileUploadResponseSchema>

export const createProjectFileUploadContract = defineRouteContract({
method: 'POST',
Expand Down
20 changes: 4 additions & 16 deletions apps/sim/lib/api/contracts/project-file-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,34 @@ export const projectFileVersionSchema = v2FileVersionSchema.meta({
title: 'Project file version',
description: 'One recorded version of a shared Project file.',
})
export type ProjectFileVersion = z.output<typeof projectFileVersionSchema>
export const projectFileVersionParamsSchema = projectFileParamsSchema.extend({
const projectFileVersionParamsSchema = projectFileParamsSchema.extend({
version: versionNumberPathSchema.describe('Version number.'),
})
export type ProjectFileVersionParams = z.input<typeof projectFileVersionParamsSchema>
export const listProjectFileVersionsQuerySchema = v2ListFileVersionsQuerySchema.omit({
workspaceId: true,
})
export type ListProjectFileVersionsQuery = z.output<typeof listProjectFileVersionsQuerySchema>
export const listProjectFileVersionsResponseSchema = z.object({
const listProjectFileVersionsResponseSchema = z.object({
revision: writtenFileRevisionSchema,
versions: z.array(projectFileVersionSchema),
nextCursor: z.string().nullable(),
})
export type ListProjectFileVersionsResponse = z.output<typeof listProjectFileVersionsResponseSchema>
export const getProjectFileVersionResponseSchema = z.object({ version: projectFileVersionSchema })
export type GetProjectFileVersionResponse = z.output<typeof getProjectFileVersionResponseSchema>
const getProjectFileVersionResponseSchema = z.object({ version: projectFileVersionSchema })
export const revertProjectFileVersionBodySchema = v2RevertFileVersionBodySchema.omit({
workspaceId: true,
})
export type RevertProjectFileVersionBody = z.input<typeof revertProjectFileVersionBodySchema>
export const revertProjectFileVersionResponseSchema = z.object({
const revertProjectFileVersionResponseSchema = z.object({
reverted: z.boolean(),
file: projectFileRecordSchema,
version: projectFileVersionSchema,
revision: writtenFileRevisionSchema,
})
export type RevertProjectFileVersionResponse = z.output<
typeof revertProjectFileVersionResponseSchema
>
export const deleteProjectFileVersionResponseSchema = v2DeleteFileVersionResultSchema.extend({
deleted: z
.literal(true)
.describe(
'The version is no longer available; stored-object cleanup is retried asynchronously when needed.'
),
})
export type DeleteProjectFileVersionResponse = z.output<
typeof deleteProjectFileVersionResponseSchema
>

export const listProjectFileVersionsContract = defineRouteContract({
method: 'GET',
Expand Down
23 changes: 7 additions & 16 deletions apps/sim/lib/api/contracts/project-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ import {
import { FILE_BROWSER_SORTS } from '@/lib/workspace-files/browser'

export const projectFilesParamsSchema = z.object({ id: nonEmptyIdSchema })
export type ProjectFilesParams = z.input<typeof projectFilesParamsSchema>

export const projectFileParamsSchema = projectFilesParamsSchema.extend({ fileId: nonEmptyIdSchema })
export type ProjectFileParams = z.input<typeof projectFileParamsSchema>

export const projectFileRecordSchema = workspaceFileRecordSchema
.omit({ workspaceId: true, storageContext: true, vfsNamespace: true })
Expand All @@ -44,9 +42,8 @@ export const projectFileCapabilitiesSchema = z.object({
canRead: z.boolean(),
canWrite: z.boolean(),
})
export type ProjectFileCapabilities = z.output<typeof projectFileCapabilitiesSchema>

export const listProjectFilesQuerySchema = z
const listProjectFilesQuerySchema = z
.object({
scope: workspaceFileScopeSchema.default('active'),
folderId: folderIdSchema.optional(),
Expand All @@ -64,7 +61,7 @@ export const listProjectFilesQuerySchema = z
})
export type ListProjectFilesQuery = z.output<typeof listProjectFilesQuerySchema>

export const listProjectFilesResponseSchema = z.object({
const listProjectFilesResponseSchema = z.object({
files: z.array(projectFileRecordSchema),
items: z.array(fileBrowserItemSchema),
creators: z.array(fileBrowserCreatorSchema),
Expand All @@ -81,11 +78,10 @@ export const listProjectFilesContract = defineRouteContract({
response: { mode: 'json', schema: listProjectFilesResponseSchema },
})

export const getProjectFileResponseSchema = z.object({
const getProjectFileResponseSchema = z.object({
file: projectFileRecordSchema,
capabilities: projectFileCapabilitiesSchema,
})
export type GetProjectFileResponse = z.output<typeof getProjectFileResponseSchema>

export const getProjectFileContract = defineRouteContract({
method: 'GET',
Expand All @@ -94,7 +90,7 @@ export const getProjectFileContract = defineRouteContract({
response: { mode: 'json', schema: getProjectFileResponseSchema },
})

export const createProjectFileBodySchema = createWorkspaceFileBodySchema.safeExtend({
const createProjectFileBodySchema = createWorkspaceFileBodySchema.safeExtend({
exactName: z.boolean().default(false),
folderPath: z.string().max(4096).optional(),
})
Expand All @@ -108,20 +104,16 @@ export const createProjectFileContract = defineRouteContract({
response: { mode: 'json', schema: getProjectFileResponseSchema, status: 201 },
})

export const updateProjectFileContentBodySchema = updateWorkspaceFileContentBodySchema
const updateProjectFileContentBodySchema = updateWorkspaceFileContentBodySchema
.safeExtend({
expectedRevision: z.string().min(1).max(1024).optional(),
contentType: z.string().trim().min(1).max(255).optional(),
})
.strict()
export type UpdateProjectFileContentBody = z.input<typeof updateProjectFileContentBodySchema>

export const updateProjectFileContentResponseSchema = getProjectFileResponseSchema.safeExtend({
const updateProjectFileContentResponseSchema = getProjectFileResponseSchema.safeExtend({
file: projectFileRecordSchema.extend({ currentVersion: z.number().int().positive() }),
})
export type UpdateProjectFileContentResponse = z.output<
typeof updateProjectFileContentResponseSchema
>

export const updateProjectFileContentContract = defineRouteContract({
method: 'PUT',
Expand All @@ -138,12 +130,11 @@ export const readProjectFileContentContract = defineRouteContract({
response: { mode: 'binary' },
})

export const projectFileArtifactQuerySchema = z.object({
const projectFileArtifactQuerySchema = z.object({
preview: z.enum(['1', '0']).optional(),
v: z.string().max(128).optional(),
t: z.string().max(32).optional(),
})
export type ProjectFileArtifactQuery = z.input<typeof projectFileArtifactQuerySchema>

export const readProjectFileArtifactContract = defineRouteContract({
method: 'GET',
Expand Down
24 changes: 8 additions & 16 deletions apps/sim/lib/api/contracts/v2/project-file-folders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import { defineRouteContract } from '@/lib/api/contracts/types'
import { v2ProjectFilesParamsSchema } from '@/lib/api/contracts/v2/project-files'
import { v2CursorListResponse, v2DataResponse } from '@/lib/api/contracts/v2/shared'

export const v2ProjectFileFolderParamsSchema = v2ProjectFilesParamsSchema.extend({
const v2ProjectFileFolderParamsSchema = v2ProjectFilesParamsSchema.extend({
folderId: nonEmptyIdSchema.describe('Folder identifier within the Project.'),
})
export type V2ProjectFileFolderParams = z.input<typeof v2ProjectFileFolderParamsSchema>

export const v2ProjectFileFolderSchema = projectFileFolderRecordSchema.extend({
const v2ProjectFileFolderSchema = projectFileFolderRecordSchema.extend({
id: nonEmptyIdSchema.describe('Stable folder identifier.'),
owner: projectFileFolderRecordSchema.shape.owner
.extend({
Expand All @@ -36,14 +35,13 @@ export const v2ProjectFileFolderSchema = projectFileFolderRecordSchema.extend({
})
export type V2ProjectFileFolder = z.output<typeof v2ProjectFileFolderSchema>

export const v2ListProjectFileFoldersQuerySchema = listProjectFileFoldersQuerySchema
const v2ListProjectFileFoldersQuerySchema = listProjectFileFoldersQuerySchema
.extend({
scope: listProjectFileFoldersQuerySchema.shape.scope.describe('Folder lifecycle scope.'),
})
.strict()
export type V2ListProjectFileFoldersQuery = z.output<typeof v2ListProjectFileFoldersQuerySchema>

export const v2CreateProjectFileFolderBodySchema = createProjectFileFolderBodySchema
const v2CreateProjectFileFolderBodySchema = createProjectFileFolderBodySchema
.extend({
name: createProjectFileFolderBodySchema.shape.name.describe('Name for the new folder.'),
parentId: nonEmptyIdSchema
Expand All @@ -52,9 +50,8 @@ export const v2CreateProjectFileFolderBodySchema = createProjectFileFolderBodySc
.describe('Parent folder identifier; omit or use null for the root.'),
})
.strict()
export type V2CreateProjectFileFolderBody = z.input<typeof v2CreateProjectFileFolderBodySchema>

export const v2UpdateProjectFileFolderBodySchema = updateProjectFileFolderBodySchema
const v2UpdateProjectFileFolderBodySchema = updateProjectFileFolderBodySchema
.extend({
name: updateProjectFileFolderBodySchema.shape.name.describe(
'New folder name; omit to leave unchanged.'
Expand All @@ -70,15 +67,10 @@ export const v2UpdateProjectFileFolderBodySchema = updateProjectFileFolderBodySc
),
})
.strict()
export type V2UpdateProjectFileFolderBody = z.input<typeof v2UpdateProjectFileFolderBodySchema>

export const v2RestoreProjectFileFolderResponseSchema =
restoreProjectFileFolderResponseSchema.extend({
folder: v2ProjectFileFolderSchema.describe('Restored Project folder.'),
})
export type V2RestoreProjectFileFolderResponse = z.output<
typeof v2RestoreProjectFileFolderResponseSchema
>
const v2RestoreProjectFileFolderResponseSchema = restoreProjectFileFolderResponseSchema.extend({
folder: v2ProjectFileFolderSchema.describe('Restored Project folder.'),
})

export const v2ListProjectFileFoldersContract = defineRouteContract({
method: 'GET',
Expand Down
Loading
Loading