From e645854d188ccd65a0b681cebcfc788072b3be49 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Wed, 3 May 2023 14:56:41 -0600 Subject: [PATCH] allow for arbitrary grouping of property values and intro PropertyPage --- lib/properties/PropertyGroup.ts | 12 +++++------- lib/properties/PropertyPage.ts | 18 ++++++++++++++++++ lib/properties/index.ts | 2 +- lib/types.ts | 20 ++++++++++++-------- 4 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 lib/properties/PropertyPage.ts diff --git a/lib/properties/PropertyGroup.ts b/lib/properties/PropertyGroup.ts index 26a8dc2..749295b 100644 --- a/lib/properties/PropertyGroup.ts +++ b/lib/properties/PropertyGroup.ts @@ -1,18 +1,16 @@ import { PackagePropertyGroup } from "../types" +import { PropertyPage } from "./PropertyPage" import { PropertyString } from "./PropertyString" export class PropertyGroup { private constructor(readonly data: PackagePropertyGroup) {} static of(options: { - description: string - value: (PropertyGroup | PropertyString)[] - name: string + header: string | null + values: (PropertyPage | PropertyString)[] }) { return new PropertyGroup({ - type: "object", - name: options.name, - description: options.description, - value: options.value.map((x) => x.data), + header: options.header, + value: options.values.map((x) => x.data), }) } } diff --git a/lib/properties/PropertyPage.ts b/lib/properties/PropertyPage.ts new file mode 100644 index 0000000..8efa3d9 --- /dev/null +++ b/lib/properties/PropertyPage.ts @@ -0,0 +1,18 @@ +import { PackagePropertyPage } from "../types" +import { PropertyGroup } from "./PropertyGroup" + +export class PropertyPage { + private constructor(readonly data: PackagePropertyPage) {} + static of(options: { + name: string + description: string | null + groups: PropertyGroup[] + }) { + return new PropertyPage({ + type: "page", + name: options.name, + description: options.description, + value: options.groups.map((x) => x.data), + }) + } +} diff --git a/lib/properties/index.ts b/lib/properties/index.ts index ee33f38..1c7c057 100644 --- a/lib/properties/index.ts +++ b/lib/properties/index.ts @@ -19,7 +19,7 @@ export type UnionToIntersection = ((x: T) => any) extends (x: infer R) => any export function setupProperties( fn: (args: { wrapperData: WrapperData - }) => void | Promise | Promise<(PropertyGroup | PropertyString)[]>, + }) => void | Promise | Promise, ): ExpectedExports.properties { return (async (options) => { const result = await fn( diff --git a/lib/types.ts b/lib/types.ts index c185041..98729e1 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -568,7 +568,17 @@ export type KnownError = "error-code": [number, string] | readonly [number, string] } -export type PackageProperties = PackagePropertyGroup | PackagePropertyString +export type PackagePropertyGroup = { + header: string | null + value: PackageProperties[] +} +export type PackageProperties = PackagePropertyPage | PackagePropertyString +export type PackagePropertyPage = { + type: "page" + name: string + description: string | null + value: Properties +} export type PackagePropertyString = { type: "string" name: string @@ -581,14 +591,8 @@ export type PackagePropertyString = { /** Hiding the value unless toggled off for field */ masked: boolean } -export type PackagePropertyGroup = { - value: PackageProperties[] - type: "object" - name: string - description: string -} -export type Properties = PackageProperties[] +export type Properties = PackagePropertyGroup[] export type Dependency = { id: PackageId