mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
feat: add zod-deep-partial, partialValidator on InputSpec, and z.deepPartial re-export
This commit is contained in:
5
container-runtime/package-lock.json
generated
5
container-runtime/package-lock.json
generated
@@ -37,7 +37,7 @@
|
||||
},
|
||||
"../sdk/dist": {
|
||||
"name": "@start9labs/start-sdk",
|
||||
"version": "0.4.0-beta.51",
|
||||
"version": "0.4.0-beta.52",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@iarna/toml": "^3.0.0",
|
||||
@@ -49,7 +49,8 @@
|
||||
"isomorphic-fetch": "^3.0.0",
|
||||
"mime": "^4.0.7",
|
||||
"yaml": "^2.7.1",
|
||||
"zod": "^4.3.6"
|
||||
"zod": "^4.3.6",
|
||||
"zod-deep-partial": "^1.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.4.0",
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Value } from './value'
|
||||
import { _ } from '../../../util'
|
||||
import { Effects } from '../../../Effects'
|
||||
import { z } from 'zod'
|
||||
import { zodDeepPartial } from 'zod-deep-partial'
|
||||
import { DeepPartial } from '../../../types'
|
||||
import { InputSpecTools, createInputSpecTools } from './inputSpecTools'
|
||||
|
||||
@@ -21,6 +22,41 @@ export type LazyBuild<ExpectedOut, Type> = (
|
||||
options: LazyBuildOptions<Type>,
|
||||
) => Promise<ExpectedOut> | ExpectedOut
|
||||
|
||||
/**
|
||||
* Defines which keys to keep when filtering an InputSpec.
|
||||
* Use `true` to keep a field as-is, or a nested object to filter sub-fields of an object-typed field.
|
||||
*/
|
||||
export type FilterKeys<T> = {
|
||||
[K in keyof T]?: T[K] extends Record<string, any>
|
||||
? true | FilterKeys<T[K]>
|
||||
: true
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the resulting type after applying a {@link FilterKeys} shape to a type.
|
||||
*/
|
||||
export type ApplyFilter<T, F> = {
|
||||
[K in Extract<keyof F, keyof T>]: F[K] extends true
|
||||
? T[K]
|
||||
: T[K] extends Record<string, any>
|
||||
? F[K] extends FilterKeys<T[K]>
|
||||
? ApplyFilter<T[K], F[K]>
|
||||
: T[K]
|
||||
: T[K]
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the union of all valid key-path tuples through a nested type.
|
||||
* Each tuple represents a path from root to a field, recursing into object-typed sub-fields.
|
||||
*/
|
||||
export type KeyPaths<T> = {
|
||||
[K in keyof T & string]: T[K] extends any[]
|
||||
? [K]
|
||||
: T[K] extends Record<string, any>
|
||||
? [K] | [K, ...KeyPaths<T[K]>]
|
||||
: [K]
|
||||
}[keyof T & string]
|
||||
|
||||
/** Extracts the runtime type from an {@link InputSpec}. */
|
||||
// prettier-ignore
|
||||
export type ExtractInputSpecType<A extends InputSpec<Record<string, any>, any>> =
|
||||
@@ -111,6 +147,8 @@ export class InputSpec<
|
||||
) {}
|
||||
public _TYPE: Type = null as any as Type
|
||||
public _PARTIAL: DeepPartial<Type> = null as any as DeepPartial<Type>
|
||||
public readonly partialValidator: z.ZodType<DeepPartial<StaticValidatedAs>> =
|
||||
zodDeepPartial(this.validator) as any
|
||||
/**
|
||||
* Builds the runtime form specification and combined Zod validator from this InputSpec's fields.
|
||||
*
|
||||
@@ -139,35 +177,6 @@ export class InputSpec<
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a single named field to this spec, returning a new `InputSpec` with the extended type.
|
||||
*
|
||||
* @param key - The field key name
|
||||
* @param build - A {@link Value} instance, or a function receiving typed tools that returns one
|
||||
*/
|
||||
addKey<Key extends string, V extends Value<any, any, any>>(
|
||||
key: Key,
|
||||
build: V | ((tools: InputSpecTools<Type>) => V),
|
||||
): InputSpec<
|
||||
Type & { [K in Key]: V extends Value<infer T, any, any> ? T : never },
|
||||
StaticValidatedAs & {
|
||||
[K in Key]: V extends Value<any, infer S, any> ? S : never
|
||||
}
|
||||
> {
|
||||
const value =
|
||||
build instanceof Function ? build(createInputSpecTools<Type>()) : build
|
||||
const newSpec = { ...this.spec, [key]: value } as any
|
||||
const newValidator = z.object(
|
||||
Object.fromEntries(
|
||||
Object.entries(newSpec).map(([k, v]) => [
|
||||
k,
|
||||
(v as Value<any>).validator,
|
||||
]),
|
||||
),
|
||||
)
|
||||
return new InputSpec(newSpec, newValidator as any)
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds multiple fields to this spec at once, returning a new `InputSpec` with extended types.
|
||||
*
|
||||
@@ -201,6 +210,241 @@ export class InputSpec<
|
||||
return new InputSpec(newSpec, newValidator as any)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new InputSpec containing only the specified keys.
|
||||
* Use `true` to keep a field as-is, or a nested object to filter sub-fields of object-typed fields.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const full = InputSpec.of({
|
||||
* name: Value.text({ name: 'Name', required: true, default: null }),
|
||||
* settings: Value.object({ name: 'Settings' }, InputSpec.of({
|
||||
* debug: Value.toggle({ name: 'Debug', default: false }),
|
||||
* port: Value.number({ name: 'Port', required: true, default: 8080, integer: true }),
|
||||
* })),
|
||||
* })
|
||||
* const filtered = full.filter({ name: true, settings: { debug: true } })
|
||||
* ```
|
||||
*/
|
||||
filter<F extends FilterKeys<Type>>(
|
||||
keys: F,
|
||||
): InputSpec<
|
||||
ApplyFilter<Type, F> & ApplyFilter<StaticValidatedAs, F>,
|
||||
ApplyFilter<StaticValidatedAs, F>
|
||||
> {
|
||||
const newSpec: Record<string, Value<any>> = {}
|
||||
for (const k of Object.keys(keys)) {
|
||||
const filterVal = (keys as any)[k]
|
||||
const value = (this.spec as any)[k] as Value<any> | undefined
|
||||
if (!value) continue
|
||||
if (filterVal === true) {
|
||||
newSpec[k] = value
|
||||
} else if (typeof filterVal === 'object' && filterVal !== null) {
|
||||
const objectMeta = value._objectSpec
|
||||
if (objectMeta) {
|
||||
const filteredInner = objectMeta.inputSpec.filter(filterVal)
|
||||
newSpec[k] = Value.object(objectMeta.params, filteredInner)
|
||||
} else {
|
||||
newSpec[k] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
const newValidator = z.object(
|
||||
Object.fromEntries(
|
||||
Object.entries(newSpec).map(([k, v]) => [k, v.validator]),
|
||||
),
|
||||
)
|
||||
return new InputSpec(newSpec as any, newValidator as any) as any
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new InputSpec with the specified keys disabled.
|
||||
* Use `true` to disable a field, or a nested object to disable sub-fields of object-typed fields.
|
||||
* All fields remain in the spec — disabled fields simply cannot be edited by the user.
|
||||
*
|
||||
* @param keys - Which fields to disable, using the same shape as {@link FilterKeys}
|
||||
* @param message - The reason the fields are disabled, displayed to the user
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const spec = InputSpec.of({
|
||||
* name: Value.text({ name: 'Name', required: true, default: null }),
|
||||
* settings: Value.object({ name: 'Settings' }, InputSpec.of({
|
||||
* debug: Value.toggle({ name: 'Debug', default: false }),
|
||||
* port: Value.number({ name: 'Port', required: true, default: 8080, integer: true }),
|
||||
* })),
|
||||
* })
|
||||
* const disabled = spec.disable({ name: true, settings: { debug: true } }, 'Managed by the system')
|
||||
* ```
|
||||
*/
|
||||
disable(
|
||||
keys: FilterKeys<Type>,
|
||||
message: string,
|
||||
): InputSpec<Type, StaticValidatedAs> {
|
||||
const newSpec: Record<string, Value<any>> = {}
|
||||
for (const k in this.spec) {
|
||||
const filterVal = (keys as any)[k]
|
||||
const value = (this.spec as any)[k] as Value<any>
|
||||
if (!filterVal) {
|
||||
newSpec[k] = value
|
||||
} else if (filterVal === true) {
|
||||
newSpec[k] = value.withDisabled(message)
|
||||
} else if (typeof filterVal === 'object' && filterVal !== null) {
|
||||
const objectMeta = value._objectSpec
|
||||
if (objectMeta) {
|
||||
const disabledInner = objectMeta.inputSpec.disable(filterVal, message)
|
||||
newSpec[k] = Value.object(objectMeta.params, disabledInner)
|
||||
} else {
|
||||
newSpec[k] = value.withDisabled(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
const newValidator = z.object(
|
||||
Object.fromEntries(
|
||||
Object.entries(newSpec).map(([k, v]) => [k, v.validator]),
|
||||
),
|
||||
)
|
||||
return new InputSpec(newSpec as any, newValidator as any) as any
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a key path to its corresponding display name path.
|
||||
* Each key is mapped to the `name` property of its built {@link ValueSpec}.
|
||||
* Recurses into `Value.object` sub-specs for nested paths.
|
||||
*
|
||||
* @param path - Typed tuple of field keys (e.g. `["settings", "debug"]`)
|
||||
* @param options - Build options providing effects and prefill data
|
||||
* @returns Array of display names (e.g. `["Settings", "Debug"]`)
|
||||
*/
|
||||
async namePath<OuterType>(
|
||||
path: KeyPaths<Type>,
|
||||
options: LazyBuildOptions<OuterType>,
|
||||
): Promise<string[]> {
|
||||
if (path.length === 0) return []
|
||||
const [key, ...rest] = path as [string, ...string[]]
|
||||
const value = (this.spec as any)[key] as Value<any> | undefined
|
||||
if (!value) return []
|
||||
const built = await value.build(options as any)
|
||||
const name =
|
||||
'name' in built.spec ? (built.spec as { name: string }).name : key
|
||||
if (rest.length === 0) return [name]
|
||||
const objectMeta = value._objectSpec
|
||||
if (objectMeta) {
|
||||
const innerNames = await objectMeta.inputSpec.namePath(
|
||||
rest as any,
|
||||
options,
|
||||
)
|
||||
return [name, ...innerNames]
|
||||
}
|
||||
return [name]
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a key path to the description of the target field.
|
||||
* Recurses into `Value.object` sub-specs for nested paths.
|
||||
*
|
||||
* @param path - Typed tuple of field keys (e.g. `["settings", "debug"]`)
|
||||
* @param options - Build options providing effects and prefill data
|
||||
* @returns The description string, or `null` if the field has no description or was not found
|
||||
*/
|
||||
async description<OuterType>(
|
||||
path: KeyPaths<Type>,
|
||||
options: LazyBuildOptions<OuterType>,
|
||||
): Promise<string | null> {
|
||||
if (path.length === 0) return null
|
||||
const [key, ...rest] = path as [string, ...string[]]
|
||||
const value = (this.spec as any)[key] as Value<any> | undefined
|
||||
if (!value) return null
|
||||
if (rest.length === 0) {
|
||||
const built = await value.build(options as any)
|
||||
return 'description' in built.spec
|
||||
? (built.spec as { description: string | null }).description
|
||||
: null
|
||||
}
|
||||
const objectMeta = value._objectSpec
|
||||
if (objectMeta) {
|
||||
return objectMeta.inputSpec.description(rest as any, options)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new InputSpec filtered to only include keys present in the given partial object.
|
||||
* For nested `Value.object` fields, recurses into the partial value to filter sub-fields.
|
||||
*
|
||||
* @param partial - A deep-partial object whose defined keys determine which fields to keep
|
||||
*/
|
||||
filterFromPartial(
|
||||
partial: DeepPartial<Type>,
|
||||
): InputSpec<
|
||||
DeepPartial<Type> & DeepPartial<StaticValidatedAs>,
|
||||
DeepPartial<StaticValidatedAs>
|
||||
> {
|
||||
const newSpec: Record<string, Value<any>> = {}
|
||||
for (const k of Object.keys(partial)) {
|
||||
const value = (this.spec as any)[k] as Value<any> | undefined
|
||||
if (!value) continue
|
||||
const objectMeta = value._objectSpec
|
||||
if (objectMeta) {
|
||||
const partialVal = (partial as any)[k]
|
||||
if (typeof partialVal === 'object' && partialVal !== null) {
|
||||
const filteredInner =
|
||||
objectMeta.inputSpec.filterFromPartial(partialVal)
|
||||
newSpec[k] = Value.object(objectMeta.params, filteredInner)
|
||||
continue
|
||||
}
|
||||
}
|
||||
newSpec[k] = value
|
||||
}
|
||||
const newValidator = z.object(
|
||||
Object.fromEntries(
|
||||
Object.entries(newSpec).map(([k, v]) => [k, v.validator]),
|
||||
),
|
||||
)
|
||||
return new InputSpec(newSpec as any, newValidator as any) as any
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new InputSpec with fields disabled based on which keys are present in the given partial object.
|
||||
* For nested `Value.object` fields, recurses into the partial value to disable sub-fields.
|
||||
* All fields remain in the spec — disabled fields simply cannot be edited by the user.
|
||||
*
|
||||
* @param partial - A deep-partial object whose defined keys determine which fields to disable
|
||||
* @param message - The reason the fields are disabled, displayed to the user
|
||||
*/
|
||||
disableFromPartial(
|
||||
partial: DeepPartial<Type>,
|
||||
message: string,
|
||||
): InputSpec<Type, StaticValidatedAs> {
|
||||
const newSpec: Record<string, Value<any>> = {}
|
||||
for (const k in this.spec) {
|
||||
const value = (this.spec as any)[k] as Value<any>
|
||||
if (!(k in (partial as any))) {
|
||||
newSpec[k] = value
|
||||
continue
|
||||
}
|
||||
const objectMeta = value._objectSpec
|
||||
if (objectMeta) {
|
||||
const partialVal = (partial as any)[k]
|
||||
if (typeof partialVal === 'object' && partialVal !== null) {
|
||||
const disabledInner = objectMeta.inputSpec.disableFromPartial(
|
||||
partialVal,
|
||||
message,
|
||||
)
|
||||
newSpec[k] = Value.object(objectMeta.params, disabledInner)
|
||||
continue
|
||||
}
|
||||
}
|
||||
newSpec[k] = value.withDisabled(message)
|
||||
}
|
||||
const newValidator = z.object(
|
||||
Object.fromEntries(
|
||||
Object.entries(newSpec).map(([k, v]) => [k, v.validator]),
|
||||
),
|
||||
)
|
||||
return new InputSpec(newSpec as any, newValidator as any) as any
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an `InputSpec` from a plain record of {@link Value} entries.
|
||||
*
|
||||
|
||||
@@ -70,6 +70,11 @@ export class Value<
|
||||
) {}
|
||||
public _TYPE: Type = null as any as Type
|
||||
public _PARTIAL: DeepPartial<Type> = null as any as DeepPartial<Type>
|
||||
/** @internal Used by {@link InputSpec.filter} to support nested filtering of object-typed fields. */
|
||||
_objectSpec?: {
|
||||
inputSpec: InputSpec<any, any>
|
||||
params: { name: string; description?: string | null }
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Displays a boolean toggle to enable/disable
|
||||
@@ -987,7 +992,7 @@ export class Value<
|
||||
},
|
||||
spec: InputSpec<Type, StaticValidatedAs>,
|
||||
) {
|
||||
return new Value<Type, StaticValidatedAs>(async (options) => {
|
||||
const value = new Value<Type, StaticValidatedAs>(async (options) => {
|
||||
const built = await spec.build(options as any)
|
||||
return {
|
||||
spec: {
|
||||
@@ -1000,6 +1005,8 @@ export class Value<
|
||||
validator: built.validator,
|
||||
}
|
||||
}, spec.validator)
|
||||
value._objectSpec = { inputSpec: spec, params: a }
|
||||
return value
|
||||
}
|
||||
/**
|
||||
* Displays a file upload input field.
|
||||
@@ -1333,6 +1340,25 @@ export class Value<
|
||||
}, z.any())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new Value that produces the same field spec but with `disabled` set to the given message.
|
||||
* The field remains in the form but cannot be edited by the user.
|
||||
*
|
||||
* @param message - The reason the field is disabled, displayed to the user
|
||||
*/
|
||||
withDisabled(message: string): Value<Type, StaticValidatedAs, OuterType> {
|
||||
const original = this
|
||||
const v = new Value<Type, StaticValidatedAs, OuterType>(async (options) => {
|
||||
const built = await original.build(options)
|
||||
return {
|
||||
spec: { ...built.spec, disabled: message } as ValueSpec,
|
||||
validator: built.validator,
|
||||
}
|
||||
}, this.validator)
|
||||
v._objectSpec = this._objectSpec
|
||||
return v
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the validated output value using a mapping function.
|
||||
* The form field itself remains unchanged, but the value is transformed after validation.
|
||||
|
||||
@@ -16,10 +16,12 @@ export type GetInput<A extends Record<string, any>> = (options: {
|
||||
prefill: T.DeepPartial<A> | null
|
||||
}) => Promise<null | void | undefined | T.DeepPartial<A>>
|
||||
|
||||
export type MaybeFn<T> = T | ((options: { effects: T.Effects }) => Promise<T>)
|
||||
function callMaybeFn<T>(
|
||||
maybeFn: MaybeFn<T>,
|
||||
options: { effects: T.Effects },
|
||||
export type MaybeFn<T, Opts = { effects: T.Effects }> =
|
||||
| T
|
||||
| ((options: Opts) => Promise<T>)
|
||||
function callMaybeFn<T, Opts = { effects: T.Effects }>(
|
||||
maybeFn: MaybeFn<T, Opts>,
|
||||
options: Opts,
|
||||
): Promise<T> {
|
||||
if (maybeFn instanceof Function) {
|
||||
return maybeFn(options)
|
||||
@@ -57,7 +59,13 @@ export class Action<Id extends T.ActionId, Type extends Record<string, any>>
|
||||
private constructor(
|
||||
readonly id: Id,
|
||||
private readonly metadataFn: MaybeFn<T.ActionMetadata>,
|
||||
private readonly inputSpec: MaybeInputSpec<Type>,
|
||||
private readonly inputSpec: MaybeFn<
|
||||
MaybeInputSpec<Type>,
|
||||
{
|
||||
effects: T.Effects
|
||||
prefill: unknown | null
|
||||
}
|
||||
>,
|
||||
private readonly getInputFn: GetInput<Type>,
|
||||
private readonly runFn: Run<Type>,
|
||||
) {}
|
||||
@@ -67,7 +75,13 @@ export class Action<Id extends T.ActionId, Type extends Record<string, any>>
|
||||
>(
|
||||
id: Id,
|
||||
metadata: MaybeFn<Omit<T.ActionMetadata, 'hasInput'>>,
|
||||
inputSpec: InputSpecType,
|
||||
inputSpec: MaybeFn<
|
||||
InputSpecType,
|
||||
{
|
||||
effects: T.Effects
|
||||
prefill: unknown | null
|
||||
}
|
||||
>,
|
||||
getInput: GetInput<ExtractInputSpecType<InputSpecType>>,
|
||||
run: Run<ExtractInputSpecType<InputSpecType>>,
|
||||
): Action<Id, ExtractInputSpecType<InputSpecType>> {
|
||||
@@ -111,9 +125,12 @@ export class Action<Id extends T.ActionId, Type extends Record<string, any>>
|
||||
}): Promise<T.ActionInput> {
|
||||
let spec = {}
|
||||
if (this.inputSpec) {
|
||||
const built = await this.inputSpec.build(options)
|
||||
this.prevInputSpec[options.effects.eventId!] = built
|
||||
spec = built.spec
|
||||
const inputSpec = await callMaybeFn(this.inputSpec, options)
|
||||
const built = await inputSpec?.build(options)
|
||||
if (built) {
|
||||
this.prevInputSpec[options.effects.eventId!] = built
|
||||
spec = built.spec
|
||||
}
|
||||
}
|
||||
return {
|
||||
eventId: options.effects.eventId!,
|
||||
|
||||
@@ -8,6 +8,20 @@ export * as types from './types'
|
||||
export * as T from './types'
|
||||
export * as yaml from 'yaml'
|
||||
export * as inits from './inits'
|
||||
export { z } from 'zod'
|
||||
import { z as _z } from 'zod'
|
||||
import { zodDeepPartial } from 'zod-deep-partial'
|
||||
import { DeepPartial } from './types'
|
||||
|
||||
type ZodDeepPartial = <T>(a: _z.ZodType<T>) => _z.ZodType<DeepPartial<T>>
|
||||
|
||||
export const z: typeof _z & {
|
||||
deepPartial: ZodDeepPartial
|
||||
} = Object.assign(_z, { deepPartial: zodDeepPartial as ZodDeepPartial })
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
export namespace z {
|
||||
export type infer<T extends { _zod: { output: any } }> = T['_zod']['output']
|
||||
export type input<T extends { _zod: { input: any } }> = T['_zod']['input']
|
||||
export type output<T extends { _zod: { output: any } }> = T['_zod']['output']
|
||||
}
|
||||
|
||||
export * as utils from './util'
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export * as inputSpecTypes from './actions/input/inputSpecTypes'
|
||||
import { InputSpec as InputSpecClass } from './actions/input/builder/inputSpec'
|
||||
|
||||
import {
|
||||
DependencyRequirement,
|
||||
@@ -267,3 +268,8 @@ export type AllowReadonly<T> =
|
||||
| {
|
||||
readonly [P in keyof T]: AllowReadonly<T[P]>
|
||||
}
|
||||
|
||||
export type InputSpec<
|
||||
Type extends StaticValidatedAs,
|
||||
StaticValidatedAs extends Record<string, unknown> = Type,
|
||||
> = InputSpecClass<Type, StaticValidatedAs>
|
||||
|
||||
13
sdk/base/package-lock.json
generated
13
sdk/base/package-lock.json
generated
@@ -14,7 +14,8 @@
|
||||
"isomorphic-fetch": "^3.0.0",
|
||||
"mime": "^4.0.7",
|
||||
"yaml": "^2.7.1",
|
||||
"zod": "^4.3.6"
|
||||
"zod": "^4.3.6",
|
||||
"zod-deep-partial": "^1.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.4.0",
|
||||
@@ -5006,9 +5007,19 @@
|
||||
"resolved": "https://registry.npmjs.org/zod/-/zod-4.3.6.tgz",
|
||||
"integrity": "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/colinhacks"
|
||||
}
|
||||
},
|
||||
"node_modules/zod-deep-partial": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/zod-deep-partial/-/zod-deep-partial-1.2.0.tgz",
|
||||
"integrity": "sha512-dXfte+/YN0aFYs0kMGz6xfPQWEYNaKz/LsbfxrbwL+oY3l/aR9HOBTyWCpHZ5AJXMGWKSq+0X0oVPpRliUFcjQ==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"zod": "^4.1.13"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
"isomorphic-fetch": "^3.0.0",
|
||||
"mime": "^4.0.7",
|
||||
"yaml": "^2.7.1",
|
||||
"zod": "^4.3.6"
|
||||
"zod": "^4.3.6",
|
||||
"zod-deep-partial": "^1.2.0"
|
||||
},
|
||||
"prettier": {
|
||||
"trailingComma": "all",
|
||||
|
||||
@@ -91,11 +91,15 @@ function filterUndefined<A>(a: A): A {
|
||||
* @typeParam Raw - The native type the file format parses to (e.g. `Record<string, unknown>` for JSON)
|
||||
* @typeParam Transformed - The application-level type after transformation
|
||||
*/
|
||||
export type Transformers<Raw = unknown, Transformed = unknown> = {
|
||||
export type Transformers<
|
||||
Raw = unknown,
|
||||
Transformed = unknown,
|
||||
Validated extends Transformed = Transformed,
|
||||
> = {
|
||||
/** Transform raw parsed data into the application type */
|
||||
onRead: (value: Raw) => Transformed
|
||||
/** Transform application data back into the raw format for writing */
|
||||
onWrite: (value: Transformed) => Raw
|
||||
onWrite: (value: Validated) => Raw
|
||||
}
|
||||
|
||||
type ToPath = string | { base: PathBase; subpath: string }
|
||||
@@ -483,7 +487,7 @@ export class FileHelper<A> {
|
||||
toFile: (dataIn: Raw) => string,
|
||||
fromFile: (rawData: string) => Raw,
|
||||
validate: (data: Transformed) => A,
|
||||
transformers: Transformers<Raw, Transformed> | undefined,
|
||||
transformers: Transformers<Raw, Transformed, A> | undefined,
|
||||
) {
|
||||
return FileHelper.raw<A>(
|
||||
path,
|
||||
@@ -493,7 +497,12 @@ export class FileHelper<A> {
|
||||
}
|
||||
return toFile(inData as any as Raw)
|
||||
},
|
||||
fromFile,
|
||||
(fileData) => {
|
||||
if (transformers) {
|
||||
return transformers.onRead(fromFile(fileData))
|
||||
}
|
||||
return fromFile(fileData)
|
||||
},
|
||||
validate as (a: unknown) => A,
|
||||
)
|
||||
}
|
||||
@@ -509,12 +518,12 @@ export class FileHelper<A> {
|
||||
static string<A extends Transformed, Transformed = string>(
|
||||
path: ToPath,
|
||||
shape: Validator<Transformed, A>,
|
||||
transformers: Transformers<string, Transformed>,
|
||||
transformers: Transformers<string, Transformed, A>,
|
||||
): FileHelper<A>
|
||||
static string<A extends Transformed, Transformed = string>(
|
||||
path: ToPath,
|
||||
shape?: Validator<Transformed, A>,
|
||||
transformers?: Transformers<string, Transformed>,
|
||||
transformers?: Transformers<string, Transformed, A>,
|
||||
) {
|
||||
return FileHelper.rawTransformed<A, string, Transformed>(
|
||||
path,
|
||||
@@ -531,10 +540,16 @@ export class FileHelper<A> {
|
||||
/**
|
||||
* Create a File Helper for a .json file.
|
||||
*/
|
||||
static json<A>(
|
||||
static json<A>(path: ToPath, shape: Validator<unknown, A>): FileHelper<A>
|
||||
static json<A extends Transformed, Transformed = unknown>(
|
||||
path: ToPath,
|
||||
shape: Validator<unknown, A>,
|
||||
transformers?: Transformers,
|
||||
transformers: Transformers<unknown, Transformed, A>,
|
||||
): FileHelper<A>
|
||||
static json<A extends Transformed, Transformed = unknown>(
|
||||
path: ToPath,
|
||||
shape: Validator<unknown, A>,
|
||||
transformers?: Transformers<unknown, Transformed, A>,
|
||||
) {
|
||||
return FileHelper.rawTransformed(
|
||||
path,
|
||||
@@ -555,12 +570,12 @@ export class FileHelper<A> {
|
||||
static yaml<A extends Transformed, Transformed = Record<string, unknown>>(
|
||||
path: ToPath,
|
||||
shape: Validator<Transformed, A>,
|
||||
transformers: Transformers<Record<string, unknown>, Transformed>,
|
||||
transformers: Transformers<Record<string, unknown>, Transformed, A>,
|
||||
): FileHelper<A>
|
||||
static yaml<A extends Transformed, Transformed = Record<string, unknown>>(
|
||||
path: ToPath,
|
||||
shape: Validator<Transformed, A>,
|
||||
transformers?: Transformers<Record<string, unknown>, Transformed>,
|
||||
transformers?: Transformers<Record<string, unknown>, Transformed, A>,
|
||||
) {
|
||||
return FileHelper.rawTransformed<A, Record<string, unknown>, Transformed>(
|
||||
path,
|
||||
@@ -581,12 +596,12 @@ export class FileHelper<A> {
|
||||
static toml<A extends Transformed, Transformed = Record<string, unknown>>(
|
||||
path: ToPath,
|
||||
shape: Validator<Transformed, A>,
|
||||
transformers: Transformers<Record<string, unknown>, Transformed>,
|
||||
transformers: Transformers<Record<string, unknown>, Transformed, A>,
|
||||
): FileHelper<A>
|
||||
static toml<A extends Transformed, Transformed = Record<string, unknown>>(
|
||||
path: ToPath,
|
||||
shape: Validator<Transformed, A>,
|
||||
transformers?: Transformers<Record<string, unknown>, Transformed>,
|
||||
transformers?: Transformers<Record<string, unknown>, Transformed, A>,
|
||||
) {
|
||||
return FileHelper.rawTransformed<A, Record<string, unknown>, Transformed>(
|
||||
path,
|
||||
@@ -611,13 +626,13 @@ export class FileHelper<A> {
|
||||
path: ToPath,
|
||||
shape: Validator<Transformed, A>,
|
||||
options: INI.EncodeOptions & INI.DecodeOptions,
|
||||
transformers: Transformers<Record<string, unknown>, Transformed>,
|
||||
transformers: Transformers<Record<string, unknown>, Transformed, A>,
|
||||
): FileHelper<A>
|
||||
static ini<A extends Transformed, Transformed = Record<string, unknown>>(
|
||||
path: ToPath,
|
||||
shape: Validator<Transformed, A>,
|
||||
options?: INI.EncodeOptions & INI.DecodeOptions,
|
||||
transformers?: Transformers<Record<string, unknown>, Transformed>,
|
||||
transformers?: Transformers<Record<string, unknown>, Transformed, A>,
|
||||
): FileHelper<A> {
|
||||
return FileHelper.rawTransformed<A, Record<string, unknown>, Transformed>(
|
||||
path,
|
||||
@@ -640,12 +655,12 @@ export class FileHelper<A> {
|
||||
static env<A extends Transformed, Transformed = Record<string, string>>(
|
||||
path: ToPath,
|
||||
shape: Validator<Transformed, A>,
|
||||
transformers: Transformers<Record<string, string>, Transformed>,
|
||||
transformers: Transformers<Record<string, string>, Transformed, A>,
|
||||
): FileHelper<A>
|
||||
static env<A extends Transformed, Transformed = Record<string, string>>(
|
||||
path: ToPath,
|
||||
shape: Validator<Transformed, A>,
|
||||
transformers?: Transformers<Record<string, string>, Transformed>,
|
||||
transformers?: Transformers<Record<string, string>, Transformed, A>,
|
||||
) {
|
||||
return FileHelper.rawTransformed<A, Record<string, string>, Transformed>(
|
||||
path,
|
||||
|
||||
13
sdk/package/package-lock.json
generated
13
sdk/package/package-lock.json
generated
@@ -18,7 +18,8 @@
|
||||
"isomorphic-fetch": "^3.0.0",
|
||||
"mime": "^4.0.7",
|
||||
"yaml": "^2.7.1",
|
||||
"zod": "^4.3.6"
|
||||
"zod": "^4.3.6",
|
||||
"zod-deep-partial": "^1.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.4.0",
|
||||
@@ -5232,9 +5233,19 @@
|
||||
"resolved": "https://registry.npmjs.org/zod/-/zod-4.3.6.tgz",
|
||||
"integrity": "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/colinhacks"
|
||||
}
|
||||
},
|
||||
"node_modules/zod-deep-partial": {
|
||||
"version": "1.4.4",
|
||||
"resolved": "https://registry.npmjs.org/zod-deep-partial/-/zod-deep-partial-1.4.4.tgz",
|
||||
"integrity": "sha512-aWkPl7hVStgE01WzbbSxCgX4O+sSpgt8JOjvFUtMTF75VgL6MhWQbiZi+AWGN85SfSTtI9gsOtL1vInoqfDVaA==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"zod": "^4.1.13"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@
|
||||
"isomorphic-fetch": "^3.0.0",
|
||||
"mime": "^4.0.7",
|
||||
"yaml": "^2.7.1",
|
||||
"zod": "^4.3.6"
|
||||
"zod": "^4.3.6",
|
||||
"zod-deep-partial": "^1.2.0"
|
||||
},
|
||||
"prettier": {
|
||||
"trailingComma": "all",
|
||||
|
||||
3
web/package-lock.json
generated
3
web/package-lock.json
generated
@@ -126,7 +126,8 @@
|
||||
"isomorphic-fetch": "^3.0.0",
|
||||
"mime": "^4.0.7",
|
||||
"yaml": "^2.7.1",
|
||||
"zod": "^4.3.6"
|
||||
"zod": "^4.3.6",
|
||||
"zod-deep-partial": "^1.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.4.0",
|
||||
|
||||
@@ -82,7 +82,6 @@ export class StateService {
|
||||
|
||||
await this.api.execute({
|
||||
guid: this.dataDriveGuid,
|
||||
// @ts-expect-error TODO: backend should make password optional for restore/transfer
|
||||
password: password ? await this.api.encrypt(password) : null,
|
||||
name,
|
||||
hostname,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { ISB } from '@start9labs/start-sdk'
|
||||
|
||||
export async function configBuilderToSpec(
|
||||
builder: ISB.InputSpec<Record<string, unknown>>,
|
||||
) {
|
||||
export async function configBuilderToSpec(builder: ISB.InputSpec<any>) {
|
||||
return builder.build({} as any).then(a => a.spec)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user