Skip to content

Commit cdc7e54

Browse files
committed
fix(management-api): input coercion
1 parent 94e9121 commit cdc7e54

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

lib/api/cache-entries.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ export const cacheEntriesRouter = base
4343
z.object({
4444
primaryKey: z.string().describe('The primary cache key to match against'),
4545
restoreKeys: z
46-
.array(z.string())
47-
.optional()
46+
.preprocess((val) => (Array.isArray(val) ? val : [val]), z.array(z.string()).optional())
4847
.describe('Optional fallback keys to try if the primary key does not match'),
49-
scopes: z.array(z.string()).describe('Scopes to search within, checked in order'),
48+
scopes: z
49+
.preprocess((val) => (Array.isArray(val) ? val : [val]), z.array(z.string()))
50+
.describe('Scopes to search within, checked in order'),
5051
repoId: z.string().describe('Repository id to match the cache entry against'),
5152
version: z.string().describe('Cache version identifier'),
5253
}),
@@ -66,7 +67,7 @@ export const cacheEntriesRouter = base
6667
.handler(async ({ input, context }) => {
6768
const cacheEntry = await context.storage.matchCacheEntry({
6869
keys: [input.primaryKey, ...(input.restoreKeys ?? [])],
69-
scopes: input.scopes,
70+
scopes: Array.isArray(input.scopes) ? input.scopes : [input.scopes],
7071
version: input.version,
7172
repoId: input.repoId,
7273
})

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@aws-sdk/s3-request-presigner": "^3.1000.0",
2828
"@google-cloud/storage": "^7.19.0",
2929
"@orpc/client": "^1.13.6",
30+
"@orpc/json-schema": "^1.13.6",
3031
"@orpc/openapi": "^1.13.6",
3132
"@orpc/server": "^1.13.6",
3233
"@orpc/zod": "^1.13.6",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

routes/management-api/[...].ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { onError } from '@orpc/client'
2+
import { SmartCoercionPlugin } from '@orpc/json-schema'
23
import { OpenAPIHandler } from '@orpc/openapi/fetch'
34
import { OpenAPIReferencePlugin } from '@orpc/openapi/plugins'
45
import { CORSPlugin } from '@orpc/server/plugins'
@@ -46,6 +47,9 @@ const handler = new OpenAPIHandler(router, {
4647
docsPath: '/_docs',
4748
specPath: '/_docs/spec.json',
4849
}),
50+
new SmartCoercionPlugin({
51+
schemaConverters: [new ZodToJsonSchemaConverter()],
52+
}),
4953
],
5054
interceptors: [
5155
onError((error) => {

0 commit comments

Comments
 (0)