Skip to content

Commit ff4d888

Browse files
committed
Simplify
1 parent b9ad000 commit ff4d888

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

packages/core/src/utils/getActivityLivestreamingMetadata.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { ErrorMessage, InferOutput, ObjectEntries, ObjectIssue, ObjectSchema } from 'valibot';
21
import {
32
any,
43
array,
54
findItem,
65
integer,
6+
is,
77
literal,
88
minValue,
99
nonEmpty,
@@ -15,7 +15,11 @@ import {
1515
string,
1616
transform,
1717
undefinedable,
18-
union
18+
union,
19+
type ErrorMessage,
20+
type ObjectEntries,
21+
type ObjectIssue,
22+
type ObjectSchema
1923
} from 'valibot';
2024

2125
import { type WebChatActivity } from '../types/WebChatActivity';
@@ -50,10 +54,6 @@ function eitherChannelDataOrEntities<
5054
type: literal('streaminfo')
5155
});
5256

53-
function isStreamInfoEntity(value: unknown): value is InferOutput<typeof metadataInEntitiesSchema> {
54-
return safeParse(metadataInEntitiesSchema, value).success;
55-
}
56-
5757
return union([
5858
object({
5959
...activitySchema.entries,
@@ -67,7 +67,10 @@ function eitherChannelDataOrEntities<
6767

6868
// TODO: [P2] valibot@1.1.0 did not infer output type for `filterItem()`, only infer for `findItem()`.
6969
// Bump valibot@latest and see if they solved the issue.
70-
entities: pipe(array(any()), findItem(isStreamInfoEntity))
70+
entities: pipe(
71+
array(any()),
72+
findItem(value => is(metadataInEntitiesSchema, value))
73+
)
7174
}),
7275
transform(({ entities, ...value }) => ({ ...value, streamInfoEntity: entities }))
7376
)

0 commit comments

Comments
 (0)