From f401f1eee259e215febc5301dc983fc4a4894f15 Mon Sep 17 00:00:00 2001 From: Jeremy Fiel Date: Thu, 17 Oct 2024 16:29:36 -0400 Subject: [PATCH] feat: add typings and interfaces for Overlay Specification v1.0.0 related #1246 --- packages/core/src/types/overlay.ts | 46 ++++++++++++++++++++++++++++ packages/core/src/typings/overlay.ts | 19 ++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 packages/core/src/types/overlay.ts create mode 100644 packages/core/src/typings/overlay.ts diff --git a/packages/core/src/types/overlay.ts b/packages/core/src/types/overlay.ts new file mode 100644 index 0000000000..26decac9f8 --- /dev/null +++ b/packages/core/src/types/overlay.ts @@ -0,0 +1,46 @@ +import { type NodeType, NormalizedScalarSchema, listOf } from '.'; + +const Root: NodeType = { + properties: { + overlay: { type: 'string' }, + info: 'Info', + extends: { type: 'string' }, + actions: listOf('action'), + }, + required: ['overlay', 'info', 'actions'], + extensionsPrefix: 'x-', +}; + +const Info: NodeType = { + properties: { + title: { type: 'string' }, + version: { type: 'string' }, + }, + required: ['title', 'version'], + extensionsPrefix: 'x-', +}; + +const Extends: NormalizedScalarSchema = { + type: 'string', + resolvable: true, +}; + +const Actions: NodeType = listOf('Action'); +const Action: NodeType = { + properties: { + target: { type: 'string' }, + description: { type: 'string' }, + update: {}, // any + remove: { type: 'boolean' }, + }, + required: ['target'], + extensionsPrefix: 'x-', +}; + +export const OverlayTypes: Record = { + Root, + Info, + Extends, + Actions, + Action, +}; diff --git a/packages/core/src/typings/overlay.ts b/packages/core/src/typings/overlay.ts new file mode 100644 index 0000000000..908480b180 --- /dev/null +++ b/packages/core/src/typings/overlay.ts @@ -0,0 +1,19 @@ +export interface InfoObject { + title: string; + version: string; +} + +export interface ActionObject { + target: string; + description?: string; + update?: any; + remove?: boolean; +} +export interface OverlayDefinition { + overlay: '1.0.0'; + info: InfoObject; + extends?: string; + actions: ActionObject[]; +} + +export const VERSION_PATTERN = /^1\.0\.\d+(-.+)?$/;