@plone/client
Advanced tools
Comparing version 1.0.0-alpha.17 to 1.0.0-alpha.18
@@ -11,3 +11,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.0-alpha.17", | ||
"version": "1.0.0-alpha.18", | ||
"repository": { | ||
@@ -14,0 +14,0 @@ "type": "git", |
import { z } from 'zod'; | ||
import { ApiRequestParams, apiRequest } from '../../API'; | ||
import { | ||
PloneClientConfig, | ||
PloneClientConfigSchema, | ||
} from '../../validation/config'; | ||
import { PloneClientConfig } from '../../validation/config'; | ||
import { copyMoveDataSchema as copyDataSchema } from '../../validation/copymove'; | ||
import { CopyMoveResponse as CopyResponse } from '@plone/types'; | ||
export const copyArgsSchema = z.object({ | ||
data: copyDataSchema, | ||
config: PloneClientConfigSchema, | ||
}); | ||
export type CopyArgs = z.infer<typeof copyDataSchema> & { | ||
config: PloneClientConfig; | ||
}; | ||
export type CopyArgs = z.infer<typeof copyArgsSchema>; | ||
export const copy = async ({ | ||
path, | ||
data, | ||
config, | ||
}: CopyArgs): Promise<CopyResponse> => { | ||
const validatedArgs = copyArgsSchema.parse({ | ||
const validatedArgs = copyDataSchema.parse({ | ||
path, | ||
data, | ||
config, | ||
}); | ||
const options: ApiRequestParams = { | ||
config, | ||
data: validatedArgs.data, | ||
config: validatedArgs.config, | ||
}; | ||
return apiRequest('post', '/@copy', options); | ||
const copyPath = `${validatedArgs.path}/@copy`; | ||
return apiRequest('post', copyPath, options); | ||
}; | ||
@@ -36,3 +33,4 @@ | ||
mutationKey: ['post', 'copy'], | ||
mutationFn: ({ data }: Omit<CopyArgs, 'config'>) => copy({ data, config }), | ||
mutationFn: ({ path, data }: Omit<CopyArgs, 'config'>) => | ||
copy({ path, data, config }), | ||
}); |
import { z } from 'zod'; | ||
import { ApiRequestParams, apiRequest } from '../../API'; | ||
import { | ||
PloneClientConfig, | ||
PloneClientConfigSchema, | ||
} from '../../validation/config'; | ||
import { PloneClientConfig } from '../../validation/config'; | ||
import { copyMoveDataSchema as moveDataSchema } from '../../validation/copymove'; | ||
import { CopyMoveResponse as MoveResponse } from '@plone/types'; | ||
export const MoveArgsSchema = z.object({ | ||
path: z.string(), | ||
data: moveDataSchema, | ||
config: PloneClientConfigSchema, | ||
}); | ||
export type MoveArgs = z.infer<typeof moveDataSchema> & { | ||
config: PloneClientConfig; | ||
}; | ||
export type MoveArgs = z.infer<typeof MoveArgsSchema>; | ||
export const move = async ({ | ||
@@ -23,14 +16,13 @@ path, | ||
}: MoveArgs): Promise<MoveResponse> => { | ||
const validatedArgs = MoveArgsSchema.parse({ | ||
const validatedArgs = moveDataSchema.parse({ | ||
path, | ||
data, | ||
config, | ||
}); | ||
const options: ApiRequestParams = { | ||
config, | ||
data: validatedArgs.data, | ||
config: validatedArgs.config, | ||
}; | ||
const movePath = `/${validatedArgs.path}/@move`; | ||
const movePath = `${validatedArgs.path}/@move`; | ||
@@ -37,0 +29,0 @@ return apiRequest('post', movePath, options); |
import { z } from 'zod'; | ||
export const copyMoveDataSchema = z.object({ | ||
source: z.union([z.string(), z.array(z.string())]), | ||
path: z.string(), | ||
data: z.object({ | ||
source: z.union([z.string(), z.array(z.string())]), | ||
}), | ||
}); |
Sorry, the diff of this file is not supported yet
1155181
18327