UNPKG

@decoupled/magic

Version:

870 lines (814 loc) 27.5 kB
import React from 'react'; declare type CacheInvalidationKeysForFunction<T extends Function> = { [K in keyof Function_ArgumentTypes<T>[0]]: true } export declare function cli(...args: any[]): { magicKind: "cli" } /** * Mark a value as editable via the Magic CMS. * Some restrictions: * * - no references to outside objects (this is just a tree) * - only a few types are supported (JSON) * * @param name * @param data * @see https://dev.decoupled.com/docs-magic-cms */ export declare function cms<T>(name: string, data: T): T declare interface DefaultFontFamily { /** * Defaults to `Times New Roman`. */ standard?: string /** * Defaults to `Times New Roman`. */ serif?: string /** * Defaults to `Arial`. */ sansSerif?: string /** * Defaults to `Courier New`. */ monospace?: string /** * Defaults to `Script`. */ cursive?: string /** * Defaults to `Impact`. */ fantasy?: string } /** * Start a development server from code. * This only works if you are editing in Decoupled Studio (VSCode) * or if you have the magic dev server running for this project. * * @param args * @see https://dev.decoupled.com/docs-magic-dev */ export declare function dev( spa: { magicKind: "spa" }, opts: { target?: "browser" | "vscode" } ): void export declare function dev( electron: { magicKind: "electron" }, opts: { stayOnTop?: boolean } ): void export declare function dev( cli: { magicKind: "cli" }, opts: { openInVSCodeTerminal?: boolean } ): void export declare function dev(...args: any[]): void /** * Declares an Electron App (Desktop) * * @param app * @param opts * @see https://dev.decoupled.com/docs-magic-electron */ export declare function electron( app: () => any, opts?: MagicElectronSingleWindowConstructorOptions ): { magicKind: "electron" } declare type Function_ArgumentTypes<T> = T extends (...args: infer A) => infer R ? A : never declare type Function_ReturnType<T> = T extends (...args: infer A) => infer R ? R : never declare type FunctionArgumentsType<T> = T extends (...args: infer A) => any ? A : never declare type FunctionReturnType<T> = T extends (...args: any[]) => infer R ? R : never export declare const funk: T_funk; /** * Declares a server-side Node.js lambda. * Lambdas are stateless and scale as needed. * * @param func * @param opts * @see https://dev.decoupled.com/docs-magic-lambda */ export declare function lambda<T extends Function>( func: T, opts?: LambdaOpts ): { magicKind: "lambda" } & PromisifyFunction<T> export declare interface LambdaOpts {} export declare const Link: React.FC<{ to: React.ReactElement | string children: React.ReactNode }>; export declare const LinkTarget: React.FC<{ /** * Initial component to display inside this LinkTarget */ children?: React.ReactNode }>; export declare type Locale = string export declare function log(...args: any[]): void declare interface MagicElectronSingleWindowConstructorOptions { /** * Window's width in pixels. Default is `800`. */ width?: number /** * Window's height in pixels. Default is `600`. */ height?: number /** * (**required** if y is used) Window's left offset from screen. Default is to * center the window. */ x?: number /** * (**required** if x is used) Window's top offset from screen. Default is to * center the window. */ y?: number /** * The `width` and `height` would be used as web page's size, which means the * actual window's size will include window frame's size and be slightly larger. * Default is `false`. */ useContentSize?: boolean /** * Show window in the center of the screen. */ center?: boolean /** * Window's minimum width. Default is `0`. */ minWidth?: number /** * Window's minimum height. Default is `0`. */ minHeight?: number /** * Window's maximum width. Default is no limit. */ maxWidth?: number /** * Window's maximum height. Default is no limit. */ maxHeight?: number /** * Whether window is resizable. Default is `true`. */ resizable?: boolean /** * Whether window is movable. This is not implemented on Linux. Default is `true`. */ movable?: boolean /** * Whether window is minimizable. This is not implemented on Linux. Default is * `true`. */ minimizable?: boolean /** * Whether window is maximizable. This is not implemented on Linux. Default is * `true`. */ maximizable?: boolean /** * Whether window is closable. This is not implemented on Linux. Default is `true`. */ closable?: boolean /** * Whether the window can be focused. Default is `true`. On Windows setting * `focusable: false` also implies setting `skipTaskbar: true`. On Linux setting * `focusable: false` makes the window stop interacting with wm, so the window will * always stay on top in all workspaces. */ focusable?: boolean /** * Whether the window should always stay on top of other windows. Default is * `false`. */ alwaysOnTop?: boolean /** * Whether the window should show in fullscreen. When explicitly set to `false` the * fullscreen button will be hidden or disabled on macOS. Default is `false`. */ fullscreen?: boolean /** * Whether the window can be put into fullscreen mode. On macOS, also whether the * maximize/zoom button should toggle full screen mode or maximize window. Default * is `true`. */ fullscreenable?: boolean /** * Use pre-Lion fullscreen on macOS. Default is `false`. */ simpleFullscreen?: boolean /** * Whether to show the window in taskbar. Default is `false`. */ skipTaskbar?: boolean /** * The kiosk mode. Default is `false`. */ kiosk?: boolean /** * Default window title. Default is `"Electron"`. If the HTML tag `<title>` is * defined in the HTML file loaded by `loadURL()`, this property will be ignored. */ title?: string /** * The window icon. On Windows it is recommended to use `ICO` icons to get best * visual effects, you can also leave it undefined so the executable's icon will be * used. */ //icon?: NativeImage | string icon?: string // TODO: magicKind: asset /** * Whether window should be shown when created. Default is `true`. */ show?: boolean /** * Whether the renderer should be active when `show` is `false` and it has just * been created. In order for `document.visibilityState` to work correctly on * first load with `show: false` you should set this to `false`. Setting this to * `false` will cause the `ready-to-show` event to not fire. Default is `true`. */ paintWhenInitiallyHidden?: boolean /** * Specify `false` to create a Frameless Window. Default is `true`. */ frame?: boolean /** * Specify parent window. Default is `null`. */ //parent?: BrowserWindow; /** * Whether this is a modal window. This only works when the window is a child * window. Default is `false`. */ modal?: boolean /** * Whether the web view accepts a single mouse-down event that simultaneously * activates the window. Default is `false`. */ acceptFirstMouse?: boolean /** * Whether to hide cursor when typing. Default is `false`. */ disableAutoHideCursor?: boolean /** * Auto hide the menu bar unless the `Alt` key is pressed. Default is `false`. */ autoHideMenuBar?: boolean /** * Enable the window to be resized larger than screen. Only relevant for macOS, as * other OSes allow larger-than-screen windows by default. Default is `false`. */ enableLargerThanScreen?: boolean /** * Window's background color as a hexadecimal value, like `#66CD00` or `#FFF` or * `#80FFFFFF` (alpha in #AARRGGBB format is supported if `transparent` is set to * `true`). Default is `#FFF` (white). */ backgroundColor?: string /** * Whether window should have a shadow. This is only implemented on macOS. Default * is `true`. */ hasShadow?: boolean /** * Set the initial opacity of the window, between 0.0 (fully transparent) and 1.0 * (fully opaque). This is only implemented on Windows and macOS. */ opacity?: number /** * Forces using dark theme for the window, only works on some GTK+3 desktop * environments. Default is `false`. */ darkTheme?: boolean /** * Makes the window transparent. Default is `false`. On Windows, does not work * unless the window is frameless. */ transparent?: boolean /** * The type of window, default is normal window. See more about this below. */ type?: string /** * The style of window title bar. Default is `default`. Possible values are: */ titleBarStyle?: "default" | "hidden" | "hiddenInset" | "customButtonsOnHover" /** * Shows the title in the title bar in full screen mode on macOS for all * `titleBarStyle` options. Default is `false`. */ fullscreenWindowTitle?: boolean /** * Use `WS_THICKFRAME` style for frameless windows on Windows, which adds standard * window frame. Setting it to `false` will remove window shadow and window * animations. Default is `true`. */ thickFrame?: boolean /** * Add a type of vibrancy effect to the window, only on macOS. Can be * `appearance-based`, `light`, `dark`, `titlebar`, `selection`, `menu`, `popover`, * `sidebar`, `medium-light`, `ultra-dark`, `header`, `sheet`, `window`, `hud`, * `fullscreen-ui`, `tooltip`, `content`, `under-window`, or `under-page`. Please * note that using `frame: false` in combination with a vibrancy value requires * that you use a non-default `titleBarStyle` as well. Also note that * `appearance-based`, `light`, `dark`, `medium-light`, and `ultra-dark` have been * deprecated and will be removed in an upcoming version of macOS. */ vibrancy?: | "appearance-based" | "light" | "dark" | "titlebar" | "selection" | "menu" | "popover" | "sidebar" | "medium-light" | "ultra-dark" | "header" | "sheet" | "window" | "hud" | "fullscreen-ui" | "tooltip" | "content" | "under-window" | "under-page" /** * Controls the behavior on macOS when option-clicking the green stoplight button * on the toolbar or by clicking the Window > Zoom menu item. If `true`, the window * will grow to the preferred width of the web page when zoomed, `false` will cause * it to zoom to the width of the screen. This will also affect the behavior when * calling `maximize()` directly. Default is `false`. */ zoomToPageWidth?: boolean /** * Tab group name, allows opening the window as a native tab on macOS 10.12+. * Windows with the same tabbing identifier will be grouped together. This also * adds a native new tab button to your window's tab bar and allows your `app` and * window to receive the `new-window-for-tab` event. */ tabbingIdentifier?: string /** * Settings of web page's features. */ webPreferences?: WebPreferences } /** * The type of the magic.netlify object. * Docs: https://dev.decoupled.com/docs-magic-netlify. */ declare type MagicNetlify = NetlifyTriggers & NetlifyLambdaContextFeatures & NetlifyIdentityFeatures /** * Netlify specific features */ export declare const netlify: MagicNetlify; declare interface NetlifyIdentityFeatures { useIdentity(): any } declare interface NetlifyLambdaContext { clientContext?: any // TODO: complete } declare interface NetlifyLambdaContextFeatures { /** * Use this in the first line within a magic.lambda. * It gives you access to the Netlify Functions Context object * @see: https://dev.decoupled.com/docs-magic-netlify * @see: https://dev.decoupled.com/docs-magic-lambda * @see: https://docs.netlify.com/functions/functions-and-identity/#access-identity-info-via-clientcontext */ useContext(): NetlifyLambdaContext | undefined } /** * @see: https://www.netlify.com/docs/functions/#event-triggered-functions */ declare interface NetlifyTriggers { /** * Triggered when Netlify starts building a site for deployment. */ on( event: "deploy-building", handler: TriggerEventHandler ): { magicKind: "netlify-on-deploy-building" } /** * Triggered when Netlify finishes deploying a site. */ on( event: "deploy-succeeded", handler: TriggerEventHandler ): { magicKind: "netlify-on-deploy-succeeded" } /** * Triggered when a deploy does not complete. */ on( event: "deploy-failed", handler: TriggerEventHandler ): { magicKind: "netlify-on-deploy-failed" } /** * Triggered when a deploy is locked in production and Netlify stops autopublishing deploys. */ on( event: "deploy-locked", handler: TriggerEventHandler ): { magicKind: "netlify-on-deploy-locked" } /** * Triggered when a deploy is unlocked from production and Netlify resumes autopublishing deploys. */ on( event: "deploy-unlocked", handler: TriggerEventHandler ): { magicKind: "netlify-on-deploy-unlocked" } /** * Triggered when a split test is activated. */ on( event: "split-test-activated", handler: TriggerEventHandler ): { magicKind: "netlify-on-split-test-activated" } /** * Triggered when a split test is deactivated. */ on( event: "split-test-deactivated", handler: TriggerEventHandler ): { magicKind: "netlify-on-split-test-deactivated" } /** * Triggered when a split test’s settings change. */ on( event: "split-test-modified", handler: TriggerEventHandler ): { magicKind: "netlify-on-split-test-modified" } /** * Triggered when a form submission is verified for your site. */ on( event: "submission-created", handler: TriggerEventHandler ): { magicKind: "netlify-on-submission-created" } /** * Triggered when an Identity user tries to sign up via Identity. */ on( event: "identity-validate", handler: TriggerEventHandler ): { magicKind: "netlify-on-identity-validate" } /** * Triggered when an Identity user signs up via Netlify Identity. */ on( event: "identity-signup", handler: TriggerEventHandler ): { magicKind: "netlify-on-identity-signup" } /** * Triggered when an Identity user logs in via Netlify */ on( event: "identity-login", handler: TriggerEventHandler ): { magicKind: "netlify-on-identity-login" } } declare type Promise_unboxType<T> = T extends Promise<infer R> ? R : T declare type PromisifyFunction<T extends Function> = ( ...args: FunctionArgumentsType<T> ) => PromisifyValue<FunctionReturnType<T>> declare type PromisifyValue<T> = T extends Promise<any> ? T : Promise<T> /** * Mark a value as sensitive so it doesn't get bundled and shipped to a client-side runtime. * * @param value * @see https://dev.decoupled.com/docs-magic-secret */ export declare function secret<T>(value: T): T /** * Declares a Single Page (Web) Application * * @param app * @param opts * @see https://dev.decoupled.com/docs-magic-spa */ export declare function spa( app: () => any, opts?: any ): { url: string; magicKind: "spa" } declare type T_funk = <F extends Function>( f: F, opts?: T_funk_options<F> ) => T_funk_return<F> declare interface T_funk_options<F extends Function> { volatile?: boolean runtime?: "build" | "client" | "server" | "server.global" refreshAPIKey?: string ttl?: TimeValue cacheInvalidationKeys?: CacheInvalidationKeysForFunction<F> bulk?: T_funk_return // TODO: narrow type based on F /** * Bundle requests within this interval into a bulk() request. * * @description * If a funk has a "bulk" version of itself, then the first call will will * not be sent until "bulkInterval" time has passed. * If any other calls happen within this time window they will be bundled together and, * at the end of the time window, sent via a single call to the bulk funk. * The process will then restart. * @default 100 */ bulkInterval?: TimeValue bulkFor?: T_funk_return // these two are injected __filename?: string __symbol?: string cacheKeys?: any // TODO localeBasedEdgeCache?: boolean } /** * This is the output of magic.funk() */ declare type T_funk_return<T extends Function = Function> = T extends ( ...args: infer A ) => infer R ? ((...args: A) => Promise_unboxType<R>) & { clearCache: (...args: A) => void updateLocally: ( ...args: any[] ) => (data: Promise_unboxType<R>) => Promise_unboxType<R> } & { magicKind: "funk" } : T declare type T_useFunk = <F extends Function>( f: F, opts?: T_useFunk_opts<F> ) => { data: Promise_unboxType<Function_ReturnType<F>>; error?: any } /** * Note: some of these properties are passed through to SWR, which is used * under the hood for things like focus management */ declare interface T_useFunk_opts<F extends Function> { suspense?: boolean staleWhileRevalidate?: boolean ttl?: TimeValue initialData?: Function_ReturnType<F> } /** * number of milliseconds. * or an expression that can be parsed by https://www.npmjs.com/package/ms */ declare type TimeValue = number | string /** * TODO: we should add specialized payload typings for each event type. * This is, unfortunately, under-documented in the Netlify docs for now. * Tracked by: https://github.com/decoupled/magic/issues/1 */ declare type TriggerEventHandler = (payload?: any, site?: any) => void export declare const useFunk: T_useFunk; /** * * @param app * @param opts * @see https://dev.decoupled.com/docs-magic-web */ export declare function web( app: () => any, opts?: any ): { url: string; magicKind: "web" } declare interface WebPreferences { /** * Whether to enable DevTools. If it is set to `false`, can not use * `BrowserWindow.webContents.openDevTools()` to open DevTools. Default is `true`. */ devTools?: boolean /** * Whether node integration is enabled. Default is `false`. */ nodeIntegration?: boolean /** * Whether node integration is enabled in web workers. Default is `false`. More * about this can be found in Multithreading. */ nodeIntegrationInWorker?: boolean /** * Experimental option for enabling Node.js support in sub-frames such as iframes * and child windows. All your preloads will load for every iframe, you can use * `process.isMainFrame` to determine if you are in the main frame or not. */ nodeIntegrationInSubFrames?: boolean /** * Specifies a script that will be loaded before other scripts run in the page. * This script will always have access to node APIs no matter whether node * integration is turned on or off. The value should be the absolute file path to * the script. When node integration is turned off, the preload script can * reintroduce Node global symbols back to the global scope. See example here. */ preload?: string /** * If set, this will sandbox the renderer associated with the window, making it * compatible with the Chromium OS-level sandbox and disabling the Node.js engine. * This is not the same as the `nodeIntegration` option and the APIs available to * the preload script are more limited. Read more about the option here. **Note:** * This option is currently experimental and may change or be removed in future * Electron releases. */ sandbox?: boolean /** * Whether to enable the `remote` module. Default is `true`. */ enableRemoteModule?: boolean /** * Sets the session used by the page. Instead of passing the Session object * directly, you can also choose to use the `partition` option instead, which * accepts a partition string. When both `session` and `partition` are provided, * `session` will be preferred. Default is the default session. */ //session?: Session; /** * Sets the session used by the page according to the session's partition string. * If `partition` starts with `persist:`, the page will use a persistent session * available to all pages in the app with the same `partition`. If there is no * `persist:` prefix, the page will use an in-memory session. By assigning the same * `partition`, multiple pages can share the same session. Default is the default * session. */ partition?: string /** * When specified, web pages with the same `affinity` will run in the same renderer * process. Note that due to reusing the renderer process, certain `webPreferences` * options will also be shared between the web pages even when you specified * different values for them, including but not limited to `preload`, `sandbox` and * `nodeIntegration`. So it is suggested to use exact same `webPreferences` for web * pages with the same `affinity`. _This property is experimental_ */ affinity?: string /** * The default zoom factor of the page, `3.0` represents `300%`. Default is `1.0`. */ zoomFactor?: number /** * Enables JavaScript support. Default is `true`. */ javascript?: boolean /** * When `false`, it will disable the same-origin policy (usually using testing * websites by people), and set `allowRunningInsecureContent` to `true` if this * options has not been set by user. Default is `true`. */ webSecurity?: boolean /** * Allow an https page to run JavaScript, CSS or plugins from http URLs. Default is * `false`. */ allowRunningInsecureContent?: boolean /** * Enables image support. Default is `true`. */ images?: boolean /** * Make TextArea elements resizable. Default is `true`. */ textAreasAreResizable?: boolean /** * Enables WebGL support. Default is `true`. */ webgl?: boolean /** * Whether plugins should be enabled. Default is `false`. */ plugins?: boolean /** * Enables Chromium's experimental features. Default is `false`. */ experimentalFeatures?: boolean /** * Enables scroll bounce (rubber banding) effect on macOS. Default is `false`. */ scrollBounce?: boolean /** * A list of feature strings separated by `,`, like `CSSVariables,KeyboardEventKey` * to enable. The full list of supported feature strings can be found in the * RuntimeEnabledFeatures.json5 file. */ enableBlinkFeatures?: string /** * A list of feature strings separated by `,`, like `CSSVariables,KeyboardEventKey` * to disable. The full list of supported feature strings can be found in the * RuntimeEnabledFeatures.json5 file. */ disableBlinkFeatures?: string /** * Sets the default font for the font-family. */ defaultFontFamily?: DefaultFontFamily /** * Defaults to `16`. */ defaultFontSize?: number /** * Defaults to `13`. */ defaultMonospaceFontSize?: number /** * Defaults to `0`. */ minimumFontSize?: number /** * Defaults to `ISO-8859-1`. */ defaultEncoding?: string /** * Whether to throttle animations and timers when the page becomes background. This * also affects the Page Visibility API. Defaults to `true`. */ backgroundThrottling?: boolean /** * Whether to enable offscreen rendering for the browser window. Defaults to * `false`. See the offscreen rendering tutorial for more details. */ offscreen?: boolean /** * Whether to run Electron APIs and the specified `preload` script in a separate * JavaScript context. Defaults to `false`. The context that the `preload` script * runs in will still have full access to the `document` and `window` globals but * it will use its own set of JavaScript builtins (`Array`, `Object`, `JSON`, etc.) * and will be isolated from any changes made to the global environment by the * loaded page. The Electron API will only be available in the `preload` script and * not the loaded page. This option should be used when loading potentially * untrusted remote content to ensure the loaded content cannot tamper with the * `preload` script and any Electron APIs being used. This option uses the same * technique used by Chrome Content Scripts. You can access this context in the dev * tools by selecting the 'Electron Isolated Context' entry in the combo box at the * top of the Console tab. */ contextIsolation?: boolean /** * Whether to use native `window.open()`. Defaults to `false`. Child windows will * always have node integration disabled unless `nodeIntegrationInSubFrames` is * true. **Note:** This option is currently experimental. */ nativeWindowOpen?: boolean /** * Whether to enable the `<webview>` tag. Defaults to `false`. **Note:** The * `preload` script configured for the `<webview>` will have node integration * enabled when it is executed so you should ensure remote/untrusted content is not * able to create a `<webview>` tag with a possibly malicious `preload` script. You * can use the `will-attach-webview` event on webContents to strip away the * `preload` script and to validate or alter the `<webview>`'s initial settings. */ webviewTag?: boolean /** * A list of strings that will be appended to `process.argv` in the renderer * process of this app. Useful for passing small bits of data down to renderer * process preload scripts. */ additionalArguments?: string[] /** * Whether to enable browser style consecutive dialog protection. Default is * `false`. */ safeDialogs?: boolean /** * The message to display when consecutive dialog protection is triggered. If not * defined the default message would be used, note that currently the default * message is in English and not localized. */ safeDialogsMessage?: string /** * Whether dragging and dropping a file or link onto the page causes a navigation. * Default is `false`. */ navigateOnDragDrop?: boolean /** * Autoplay policy to apply to content in the window, can be * `no-user-gesture-required`, `user-gesture-required`, * `document-user-activation-required`. Defaults to `no-user-gesture-required`. */ autoplayPolicy?: | "no-user-gesture-required" | "user-gesture-required" | "document-user-activation-required" /** * Whether to prevent the window from resizing when entering HTML Fullscreen. * Default is `false`. */ disableHtmlFullscreenWindowResize?: boolean } /** * * @param func * @see https://dev.decoupled.com/docs-magic-webWorker */ export declare function webWorker<T extends Function>( func: T ): PromisifyFunction<T> & { url: string; magicKind: "webWorker" } export { }