generated from kontent-ai/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
32 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,6 @@ export const ErrorMessage = z | |
}) | ||
.readonly(); | ||
|
||
type ErrorMessage = z.infer<typeof ErrorMessage>; | ||
|
||
const ClientInitV1Request = z | ||
.object({ | ||
type: z.literal('init-request'), | ||
|
@@ -24,8 +22,6 @@ const ClientInitV1Request = z | |
}) | ||
.readonly(); | ||
|
||
type ClientInitV1Request = z.infer<typeof ClientInitV1Request>; | ||
|
||
const ClientInitV1Response = z | ||
.object({ | ||
type: z.literal('init-response'), | ||
|
@@ -54,10 +50,9 @@ const ClientInitV1Response = z | |
requestId: z.string().uuid(), | ||
version: z.literal('1.0.0'), | ||
}) | ||
.or(ErrorMessage) | ||
.readonly(); | ||
|
||
type ClientInitV1Response = z.infer<typeof ClientInitV1Response>; | ||
|
||
const ClientInitV2Request = z | ||
.object({ | ||
type: z.literal('init-request'), | ||
|
@@ -67,8 +62,6 @@ const ClientInitV2Request = z | |
}) | ||
.readonly(); | ||
|
||
type ClientInitV2Request = z.infer<typeof ClientInitV2Request>; | ||
|
||
const ClientInitV2Response = z | ||
.object({ | ||
type: z.literal('init-response'), | ||
|
@@ -81,10 +74,9 @@ const ClientInitV2Response = z | |
requestId: z.string().uuid(), | ||
version: z.literal('2.0.0'), | ||
}) | ||
.or(ErrorMessage) | ||
.readonly(); | ||
|
||
type ClientInitV2Response = z.infer<typeof ClientInitV2Response>; | ||
|
||
const GetV1Request = z | ||
.object({ | ||
type: z.literal('get-request'), | ||
|
@@ -94,50 +86,41 @@ const GetV1Request = z | |
}) | ||
.readonly(); | ||
|
||
type GetV1Request = z.infer<typeof GetV1Request>; | ||
|
||
const GetV1Response = z | ||
.object({ | ||
type: z.literal('get-response'), | ||
requestId: z.string().uuid(), | ||
version: z.literal('1.0.0'), | ||
payload: z.null(), | ||
}) | ||
.or(ErrorMessage) | ||
.readonly(); | ||
|
||
type GetV1Response = z.infer<typeof GetV1Response>; | ||
|
||
const HostPingV1Request = z.object({ | ||
type: z.literal('ping-request'), | ||
const HostItemDeletedRequest = z.object({ | ||
type: z.literal('item-deleted-request'), | ||
requestId: z.string().uuid(), | ||
version: z.literal('1.0.0'), | ||
payload: z.boolean(), | ||
payload: z.object({ itemId: z.string().uuid() }).readonly(), | ||
}); | ||
|
||
type HostPingV1Request = z.infer<typeof HostPingV1Request>; | ||
|
||
export type CustomAppMessage = | ||
| [ClientInitV1Request, ClientInitV1Response | ErrorMessage] | ||
| [ClientInitV2Request, ClientInitV2Response | ErrorMessage] | ||
| [GetV1Request, GetV1Response | ErrorMessage]; | ||
|
||
export type Schema = { | ||
client: { | ||
'[email protected]': { | ||
request: ClientInitV1Request; | ||
response: ClientInitV1Response; | ||
request: z.infer<typeof ClientInitV1Request>; | ||
response: z.infer<typeof ClientInitV1Response>; | ||
}; | ||
'[email protected]': { | ||
request: ClientInitV2Request; | ||
response: ClientInitV2Response; | ||
request: z.infer<typeof ClientInitV2Request>; | ||
response: z.infer<typeof ClientInitV2Response>; | ||
}; | ||
'[email protected]': { | ||
request: GetV1Request; | ||
response: GetV1Response; | ||
request: z.infer<typeof GetV1Request>; | ||
response: z.infer<typeof GetV1Response>; | ||
}; | ||
}; | ||
host: { | ||
'ping@1.0.0': { | ||
request: HostPingV1Request; | ||
'item-deleted@1.0.0': { | ||
request: z.infer<typeof HostItemDeletedRequest>; | ||
response: null; | ||
}; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,7 @@ | ||
import type { CustomAppMessage } from './iframeSchema'; | ||
import type { Schema } from './iframeSchema'; | ||
|
||
export type GetRequestModelFor< | ||
TType extends CustomAppMessage[0]['type'], | ||
TVersion extends CustomAppMessage[0]['version'], | ||
> = CustomAppMessage[0] extends infer TMessage | ||
? TMessage extends { readonly type: TType; readonly version: TVersion } | ||
? TMessage | ||
: never | ||
: never; | ||
export type AllClientResponses = Schema['client'][keyof Schema['client']]['response']; | ||
|
||
export type GetResponseModelFor< | ||
TType extends CustomAppMessage[0]['type'], | ||
TVersion extends CustomAppMessage[0]['version'], | ||
> = CustomAppMessage extends infer TPair | ||
? TPair extends [unknown, unknown] | ||
? TPair[0] extends { readonly type: TType; readonly version: TVersion } | ||
? TPair[1] | ||
: never | ||
: never | ||
: never; | ||
export type AllHostRequests = Schema['host'][keyof Schema['host']]['request']; | ||
|
||
export type AllIncomingMessages = AllClientResponses | AllHostRequests; |