From 587951899cfa2d24b463318076e5cebc847b2cdf Mon Sep 17 00:00:00 2001 From: Jacob Mischka Date: Wed, 26 Oct 2022 15:49:12 -0500 Subject: [PATCH] Once again allow action prop in SDK, plan to deprecate soon --- src/classes/IntervalClient.ts | 6 +++--- src/components/displayLink.ts | 6 ++++++ src/examples/app/index.ts | 2 +- src/internalRpcSchema.ts | 10 ++-------- src/ioSchema.ts | 18 ++++++++++++------ src/types.ts | 16 +++++++++++++++- 6 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/classes/IntervalClient.ts b/src/classes/IntervalClient.ts index f79a7b1..502f686 100644 --- a/src/classes/IntervalClient.ts +++ b/src/classes/IntervalClient.ts @@ -24,7 +24,7 @@ import { ActionResultSchema, IOFunctionReturnType, IO_RESPONSE, - LinkProps, + LegacyLinkProps, T_IO_RENDER_INPUT, T_IO_RESPONSE, } from '../ioSchema' @@ -1041,7 +1041,7 @@ export default class IntervalClient { }) }, }), - redirect: (props: LinkProps) => + redirect: (props: LegacyLinkProps) => this.#sendRedirect(transactionId, props), } @@ -1301,7 +1301,7 @@ export default class IntervalClient { }) } - async #sendRedirect(transactionId: string, props: LinkProps) { + async #sendRedirect(transactionId: string, props: LegacyLinkProps) { const response = await this.#send('SEND_REDIRECT', { transactionId, ...props, diff --git a/src/components/displayLink.ts b/src/components/displayLink.ts index cfa729d..70313eb 100644 --- a/src/components/displayLink.ts +++ b/src/components/displayLink.ts @@ -11,6 +11,12 @@ export default function displayLink( route: string params?: SerializableRecord } + // deprecated in favor of `route` + // TODO: Add TS deprecated flag soon + | { + action: string + params?: SerializableRecord + } ) ) { return { diff --git a/src/examples/app/index.ts b/src/examples/app/index.ts index e7903d4..1eb4b84 100644 --- a/src/examples/app/index.ts +++ b/src/examples/app/index.ts @@ -82,7 +82,7 @@ const hello_app = new Page({ rowMenuItems: () => [ { label: 'Hello', - route: 'hello_app/hello_world', + action: 'hello_app/hello_world', }, ], }), diff --git a/src/internalRpcSchema.ts b/src/internalRpcSchema.ts index 9421543..3356d1b 100644 --- a/src/internalRpcSchema.ts +++ b/src/internalRpcSchema.ts @@ -1,6 +1,7 @@ import { z } from 'zod' import { deserializableRecord, + legacyLinkSchema, linkSchema, serializableRecord, } from './ioSchema' @@ -257,14 +258,7 @@ export const wsServerSchema = { z.object({ transactionId: z.string(), }), - z.union([ - linkSchema, - // deprecated in favor of `route` from linkSchema - z.object({ - action: z.string(), - params: serializableRecord.optional(), - }), - ]) + legacyLinkSchema ), returns: z.boolean(), }, diff --git a/src/ioSchema.ts b/src/ioSchema.ts index bc87779..19a680b 100644 --- a/src/ioSchema.ts +++ b/src/ioSchema.ts @@ -279,6 +279,17 @@ export const linkSchema = z.union([ export type LinkProps = z.infer +// TODO: Remove soon +export const legacyLinkSchema = z.union([ + linkSchema, + z.object({ + action: z.string(), + params: serializableRecord.optional(), + }), +]) + +export type LegacyLinkProps = z.infer + export const internalTableRow = z.object({ key: z.string(), data: tableRow, @@ -397,12 +408,7 @@ const DISPLAY_SCHEMA = { z.object({ href: z.string(), }), - // deprecated in favor of `route` in linkSchema - z.object({ - action: z.string(), - params: serializableRecord.optional(), - }), - linkSchema, + legacyLinkSchema, ]) ), state: z.null(), diff --git a/src/types.ts b/src/types.ts index 41b8a2a..971b078 100644 --- a/src/types.ts +++ b/src/types.ts @@ -17,6 +17,7 @@ import type { serializableRecord, ImageSize, SerializableRecord, + LegacyLinkProps, } from './ioSchema' import type { HostSchema } from './internalRpcSchema' import type { IOClient, IOClientRenderValidator } from './classes/IOClient' @@ -218,7 +219,7 @@ export type ActionLogFn = (...args: any[]) => Promise export type NotifyFn = (config: NotifyConfig) => Promise -export type RedirectFn = (props: LinkProps) => Promise +export type RedirectFn = (props: LegacyLinkProps) => Promise export type ResponseHandlerFn = (fn: T_IO_RESPONSE) => void @@ -304,6 +305,13 @@ export type MenuItem = { params?: SerializableRecord disabled?: boolean } + // Deprecated in favor of `route` + // TODO: Add TS deprecation soon + | { + action: string + params?: SerializableRecord + disabled?: boolean + } | { url: string disabled?: boolean @@ -317,6 +325,9 @@ export type ButtonItem = { theme?: 'primary' | 'secondary' | 'danger' } & ( | { route: string; params?: SerializableRecord; disabled?: boolean } + // Deprecated in favor of `route` + // TODO: Add TS deprecation soon + | { action: string; params?: SerializableRecord; disabled?: boolean } | { url: string; disabled?: boolean } | { disabled: true } ) @@ -344,6 +355,9 @@ export type TableColumnResult = } & ({ url: string } | { buffer: Buffer }) url?: string route?: string + // Deprecated in favor of `route` + // TODO: Add TS deprecation soon + action?: string params?: z.infer } | TableCellValue