Skip to content

Commit 5d96853

Browse files
committed
fix(schema): allow multiple search results
1 parent ceeb116 commit 5d96853

File tree

5 files changed

+38
-20
lines changed

5 files changed

+38
-20
lines changed

packages/schema/dist/schemas.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ export declare const ApiCliWhoamiResponseSchema: import("arktype/internal/varian
3030
};
3131
}, {}>;
3232
export declare const ApiSearchResponseSchema: import("arktype/internal/variants/object.ts").ObjectType<{
33-
results: [{
33+
results: {
3434
score: number;
3535
slug?: string | undefined;
3636
displayName?: string | undefined;
3737
version?: string | null | undefined;
38-
}];
38+
}[];
3939
}, {}>;
4040
export declare const ApiSkillMetaResponseSchema: import("arktype/internal/variants/object.ts").ObjectType<{
4141
latestVersion?: {

packages/schema/dist/schemas.js

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

packages/schema/dist/schemas.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/schema/src/schemas.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
import { describe, expect, it } from 'vitest'
44
import { parseArk } from './ark'
5-
import { CliPublishRequestSchema, LockfileSchema, WellKnownConfigSchema } from './schemas'
5+
import {
6+
ApiSearchResponseSchema,
7+
CliPublishRequestSchema,
8+
LockfileSchema,
9+
WellKnownConfigSchema,
10+
} from './schemas'
611

712
describe('@clawdhub/schema', () => {
813
it('parses lockfile records', () => {
@@ -67,4 +72,21 @@ describe('@clawdhub/schema', () => {
6772
it('throws labeled errors', () => {
6873
expect(() => parseArk(LockfileSchema, null, 'Lockfile')).toThrow(/Lockfile:/)
6974
})
75+
76+
it('parses search results arrays', () => {
77+
expect(parseArk(ApiSearchResponseSchema, { results: [] }, 'Search')).toEqual({ results: [] })
78+
79+
const parsed = parseArk(
80+
ApiSearchResponseSchema,
81+
{
82+
results: [
83+
{ slug: 'a', displayName: 'A', version: '1.0.0', score: 0.9 },
84+
{ slug: 'b', displayName: 'B', version: null, score: 0.1 },
85+
],
86+
},
87+
'Search',
88+
)
89+
expect(parsed.results).toHaveLength(2)
90+
expect(parsed.results[0]?.slug).toBe('a')
91+
})
7092
})

packages/schema/src/schemas.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ export const ApiCliWhoamiResponseSchema = type({
3535
})
3636

3737
export const ApiSearchResponseSchema = type({
38-
results: [
39-
{
40-
slug: 'string?',
41-
displayName: 'string?',
42-
version: 'string|null?',
43-
score: 'number',
44-
},
45-
],
38+
results: type({
39+
slug: 'string?',
40+
displayName: 'string?',
41+
version: 'string|null?',
42+
score: 'number',
43+
}).array(),
4644
})
4745

4846
export const ApiSkillMetaResponseSchema = type({

0 commit comments

Comments
 (0)