allow for arbitrary grouping of property values and intro PropertyPage

This commit is contained in:
Matt Hill
2023-05-03 14:56:41 -06:00
parent 8801760aa6
commit e645854d18
4 changed files with 36 additions and 16 deletions

View File

@@ -1,18 +1,16 @@
import { PackagePropertyGroup } from "../types" import { PackagePropertyGroup } from "../types"
import { PropertyPage } from "./PropertyPage"
import { PropertyString } from "./PropertyString" import { PropertyString } from "./PropertyString"
export class PropertyGroup { export class PropertyGroup {
private constructor(readonly data: PackagePropertyGroup) {} private constructor(readonly data: PackagePropertyGroup) {}
static of(options: { static of(options: {
description: string header: string | null
value: (PropertyGroup | PropertyString)[] values: (PropertyPage | PropertyString)[]
name: string
}) { }) {
return new PropertyGroup({ return new PropertyGroup({
type: "object", header: options.header,
name: options.name, value: options.values.map((x) => x.data),
description: options.description,
value: options.value.map((x) => x.data),
}) })
} }
} }

View File

@@ -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),
})
}
}

View File

@@ -19,7 +19,7 @@ export type UnionToIntersection<T> = ((x: T) => any) extends (x: infer R) => any
export function setupProperties<WrapperData>( export function setupProperties<WrapperData>(
fn: (args: { fn: (args: {
wrapperData: WrapperData wrapperData: WrapperData
}) => void | Promise<void> | Promise<(PropertyGroup | PropertyString)[]>, }) => void | Promise<void> | Promise<PropertyGroup[]>,
): ExpectedExports.properties { ): ExpectedExports.properties {
return (async (options) => { return (async (options) => {
const result = await fn( const result = await fn(

View File

@@ -568,7 +568,17 @@ export type KnownError =
"error-code": [number, string] | readonly [number, string] "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 = { export type PackagePropertyString = {
type: "string" type: "string"
name: string name: string
@@ -581,14 +591,8 @@ export type PackagePropertyString = {
/** Hiding the value unless toggled off for field */ /** Hiding the value unless toggled off for field */
masked: boolean masked: boolean
} }
export type PackagePropertyGroup = {
value: PackageProperties[]
type: "object"
name: string
description: string
}
export type Properties = PackageProperties[] export type Properties = PackagePropertyGroup[]
export type Dependency = { export type Dependency = {
id: PackageId id: PackageId