chore: INput config to remove the transformer

This commit is contained in:
BluJ
2023-04-18 13:38:43 -06:00
parent af1f9b22bd
commit 397401e259
12 changed files with 211 additions and 318 deletions

View File

@@ -1,36 +0,0 @@
import {
PackagePropertiesV2,
PackagePropertyObject,
PackagePropertyString,
Properties as P,
} from "../types";
import { PropertyObject } from "./PropertyObject";
import { PropertyString } from "./PropertyString";
export class Properties<X extends PackagePropertiesV2> {
constructor(readonly data: X) {}
static of<
X extends Record<
string,
| PropertyObject<PackagePropertyObject>
| PropertyString<PackagePropertyString>
>
>(x: X) {
const answer = {} as {
[key in keyof X]: X[key]["data"];
};
for (const [key, value] of x.entries()) {
answer[key] = value.data;
}
return new Properties(answer);
}
build() {
return {
version: 2,
data: this.data,
} satisfies P;
}
}

View File

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

View File

@@ -1,16 +0,0 @@
import { PackagePropertiesV2, PackagePropertyObject } from "../types";
import { Properties } from "./Properties";
export class PropertyObject<X extends PackagePropertyObject> {
private constructor(readonly data: X) {}
static of<X extends Properties<PackagePropertiesV2>>(
description: string,
value: X
) {
return new PropertyObject({
type: "object",
description,
value: value.data,
});
}
}

View File

@@ -1,17 +1,8 @@
import { PackagePropertyString } from "../types";
export class PropertyString<X extends PackagePropertyString> {
private constructor(readonly data: X) {}
static of(value: {
description?: string;
value: string;
/** Let's the ui make this copyable button */
copyable?: boolean;
/** Let the ui create a qr for this field */
qr?: boolean;
/** Hiding the value unless toggled off for field */
masked?: boolean;
}) {
export class PropertyString {
private constructor(readonly data: PackagePropertyString) {}
static of(value: Omit<PackagePropertyString, "type" | "watch">) {
return new PropertyString({
...value,
type: "string",

View File

@@ -1,11 +1,12 @@
import { ExpectedExports, PackagePropertiesV2 } from "../types";
import { ExpectedExports, Properties } from "../types";
import "../util/extensions";
import { Properties } from "./Properties";
export { Properties } from "./Properties";
export { PropertyObject } from "./PropertyObject";
import { PropertyGroup } from "./PropertyGroup";
import { PropertyString } from "./PropertyString";
export { PropertyGroup } from "./PropertyGroup";
export { PropertyString } from "./PropertyString";
export const test = "";
export type UnionToIntersection<T> = ((x: T) => any) extends (x: infer R) => any
? R
: never;
@@ -20,12 +21,13 @@ export type UnionToIntersection<T> = ((x: T) => any) extends (x: infer R) => any
export function setupPropertiesExport(
fn: (
...args: Parameters<ExpectedExports.properties>
) => void | Promise<void> | Promise<Properties<PackagePropertiesV2>>
) => void | Promise<void> | Promise<(PropertyGroup | PropertyString)[]>
): ExpectedExports.properties {
return async (...args: Parameters<ExpectedExports.properties>) => {
return (async (...args) => {
const result = await fn(...args);
if (result) {
return result.build();
const answer: Properties = result.map((x) => x.data);
return answer;
}
};
}) as ExpectedExports.properties;
}