@start9labs/start-sdk 0.4.0-beta.50 → 0.4.0-beta.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base/lib/Effects.d.ts +4 -0
- package/base/lib/actions/input/builder/inputSpec.d.ts +129 -8
- package/base/lib/actions/input/builder/inputSpec.js +223 -13
- package/base/lib/actions/input/builder/inputSpec.js.map +1 -1
- package/base/lib/actions/input/builder/inputSpecTools.d.ts +3 -3
- package/base/lib/actions/input/builder/list.d.ts +24 -3
- package/base/lib/actions/input/builder/list.js +26 -5
- package/base/lib/actions/input/builder/list.js.map +1 -1
- package/base/lib/actions/input/builder/value.d.ts +70 -16
- package/base/lib/actions/input/builder/value.js +89 -34
- package/base/lib/actions/input/builder/value.js.map +1 -1
- package/base/lib/actions/input/builder/variants.d.ts +14 -3
- package/base/lib/actions/input/builder/variants.js +22 -7
- package/base/lib/actions/input/builder/variants.js.map +1 -1
- package/base/lib/actions/input/inputSpecConstants.d.ts +203 -5
- package/base/lib/actions/input/inputSpecConstants.js +118 -38
- package/base/lib/actions/input/inputSpecConstants.js.map +1 -1
- package/base/lib/actions/input/inputSpecTypes.d.ts +99 -0
- package/base/lib/actions/input/inputSpecTypes.js +6 -1
- package/base/lib/actions/input/inputSpecTypes.js.map +1 -1
- package/base/lib/actions/setupActions.d.ts +6 -3
- package/base/lib/actions/setupActions.js +7 -4
- package/base/lib/actions/setupActions.js.map +1 -1
- package/base/lib/exver/index.d.ts +233 -2
- package/base/lib/exver/index.js +197 -3
- package/base/lib/exver/index.js.map +1 -1
- package/base/lib/index.d.ts +23 -1
- package/base/lib/index.js +4 -2
- package/base/lib/index.js.map +1 -1
- package/base/lib/inits/setupInit.d.ts +17 -0
- package/base/lib/inits/setupInit.js +7 -0
- package/base/lib/inits/setupInit.js.map +1 -1
- package/base/lib/inits/setupUninit.d.ts +12 -0
- package/base/lib/inits/setupUninit.js +7 -0
- package/base/lib/inits/setupUninit.js.map +1 -1
- package/base/lib/interfaces/Host.js +2 -4
- package/base/lib/interfaces/Host.js.map +1 -1
- package/base/lib/osBindings/GetOutboundGatewayParams.d.ts +4 -0
- package/base/lib/osBindings/GetOutboundGatewayParams.js +3 -0
- package/base/lib/osBindings/GetOutboundGatewayParams.js.map +1 -0
- package/base/lib/osBindings/ServerHostname.d.ts +1 -0
- package/base/lib/osBindings/ServerHostname.js +4 -0
- package/base/lib/osBindings/ServerHostname.js.map +1 -0
- package/base/lib/osBindings/ServerInfo.d.ts +1 -0
- package/base/lib/osBindings/SetServerHostnameParams.d.ts +4 -0
- package/base/lib/osBindings/SetServerHostnameParams.js +4 -0
- package/base/lib/osBindings/SetServerHostnameParams.js.map +1 -0
- package/base/lib/osBindings/SetupExecuteParams.d.ts +3 -1
- package/base/lib/osBindings/SmtpSecurity.d.ts +1 -0
- package/base/lib/osBindings/SmtpSecurity.js +4 -0
- package/base/lib/osBindings/SmtpSecurity.js.map +1 -0
- package/base/lib/osBindings/SmtpValue.d.ts +4 -2
- package/base/lib/osBindings/SmtpValue.js +0 -1
- package/base/lib/osBindings/SmtpValue.js.map +1 -1
- package/base/lib/osBindings/StartOsRecoveryInfo.d.ts +2 -2
- package/base/lib/osBindings/TestSmtpParams.d.ts +4 -2
- package/base/lib/osBindings/TestSmtpParams.js +0 -1
- package/base/lib/osBindings/TestSmtpParams.js.map +1 -1
- package/base/lib/osBindings/index.d.ts +4 -1
- package/base/lib/s9pk/index.d.ts +66 -0
- package/base/lib/s9pk/index.js +70 -1
- package/base/lib/s9pk/index.js.map +1 -1
- package/base/lib/types.d.ts +68 -2
- package/base/lib/types.js +14 -0
- package/base/lib/types.js.map +1 -1
- package/base/lib/util/GetOutboundGateway.d.ts +30 -0
- package/base/lib/util/GetOutboundGateway.js +90 -0
- package/base/lib/util/GetOutboundGateway.js.map +1 -0
- package/base/lib/util/asError.d.ts +8 -0
- package/base/lib/util/asError.js +8 -0
- package/base/lib/util/asError.js.map +1 -1
- package/base/lib/util/deepEqual.d.ts +15 -0
- package/base/lib/util/deepEqual.js +16 -2
- package/base/lib/util/deepEqual.js.map +1 -1
- package/base/lib/util/deepMerge.d.ts +18 -0
- package/base/lib/util/deepMerge.js +18 -0
- package/base/lib/util/deepMerge.js.map +1 -1
- package/base/lib/util/getDefaultString.d.ts +8 -0
- package/base/lib/util/getDefaultString.js +8 -0
- package/base/lib/util/getDefaultString.js.map +1 -1
- package/base/lib/util/graph.d.ts +57 -0
- package/base/lib/util/graph.js +47 -0
- package/base/lib/util/graph.js.map +1 -1
- package/base/lib/util/inMs.d.ts +15 -0
- package/base/lib/util/inMs.js +15 -0
- package/base/lib/util/inMs.js.map +1 -1
- package/base/lib/util/index.d.ts +1 -0
- package/base/lib/util/index.js +3 -1
- package/base/lib/util/index.js.map +1 -1
- package/base/lib/util/ip.d.ts +81 -0
- package/base/lib/util/ip.js +81 -0
- package/base/lib/util/ip.js.map +1 -1
- package/base/lib/util/once.d.ts +13 -0
- package/base/lib/util/once.js +13 -0
- package/base/lib/util/once.js.map +1 -1
- package/base/lib/util/patterns.d.ts +11 -0
- package/base/lib/util/patterns.js +11 -0
- package/base/lib/util/patterns.js.map +1 -1
- package/base/lib/util/regexes.d.ts +38 -0
- package/base/lib/util/regexes.js +38 -0
- package/base/lib/util/regexes.js.map +1 -1
- package/base/lib/util/splitCommand.d.ts +14 -0
- package/base/lib/util/splitCommand.js +15 -2
- package/base/lib/util/splitCommand.js.map +1 -1
- package/base/lib/util/stringFromStdErrOut.d.ts +7 -0
- package/base/lib/util/stringFromStdErrOut.js +7 -0
- package/base/lib/util/stringFromStdErrOut.js.map +1 -1
- package/base/lib/util/typeHelpers.d.ts +35 -0
- package/base/lib/util/typeHelpers.js +7 -0
- package/base/lib/util/typeHelpers.js.map +1 -1
- package/package/lib/StartSdk.d.ts +330 -3
- package/package/lib/StartSdk.js +143 -1
- package/package/lib/StartSdk.js.map +1 -1
- package/package/lib/backup/Backups.d.ts +71 -0
- package/package/lib/backup/Backups.js +69 -0
- package/package/lib/backup/Backups.js.map +1 -1
- package/package/lib/backup/setupBackups.d.ts +14 -0
- package/package/lib/backup/setupBackups.js +9 -0
- package/package/lib/backup/setupBackups.js.map +1 -1
- package/package/lib/health/HealthCheck.d.ts +16 -0
- package/package/lib/health/HealthCheck.js +16 -2
- package/package/lib/health/HealthCheck.js.map +1 -1
- package/package/lib/health/checkFns/HealthCheckResult.d.ts +6 -0
- package/package/lib/health/checkFns/index.d.ts +8 -0
- package/package/lib/health/checkFns/index.js +8 -0
- package/package/lib/health/checkFns/index.js.map +1 -1
- package/package/lib/index.d.ts +2 -2
- package/package/lib/index.js +2 -2
- package/package/lib/index.js.map +1 -1
- package/package/lib/mainFn/CommandController.d.ts +29 -0
- package/package/lib/mainFn/CommandController.js +29 -0
- package/package/lib/mainFn/CommandController.js.map +1 -1
- package/package/lib/mainFn/Daemon.d.ts +38 -2
- package/package/lib/mainFn/Daemon.js +38 -2
- package/package/lib/mainFn/Daemon.js.map +1 -1
- package/package/lib/mainFn/Daemons.d.ts +31 -0
- package/package/lib/mainFn/Daemons.js +13 -0
- package/package/lib/mainFn/Daemons.js.map +1 -1
- package/package/lib/mainFn/Mounts.d.ts +38 -0
- package/package/lib/mainFn/Mounts.js +38 -0
- package/package/lib/mainFn/Mounts.js.map +1 -1
- package/package/lib/mainFn/index.d.ts +1 -0
- package/package/lib/mainFn/index.js +1 -0
- package/package/lib/mainFn/index.js.map +1 -1
- package/package/lib/manifest/setupManifest.d.ts +9 -0
- package/package/lib/manifest/setupManifest.js +9 -0
- package/package/lib/manifest/setupManifest.js.map +1 -1
- package/package/lib/test/output.d.ts +2 -2
- package/package/lib/test/output.js +418 -329
- package/package/lib/test/output.js.map +1 -1
- package/package/lib/test/output.sdk.d.ts +193 -2
- package/package/lib/util/SubContainer.d.ts +46 -0
- package/package/lib/util/SubContainer.js +10 -0
- package/package/lib/util/SubContainer.js.map +1 -1
- package/package/lib/util/fileHelper.d.ts +43 -10
- package/package/lib/util/fileHelper.js +13 -11
- package/package/lib/util/fileHelper.js.map +1 -1
- package/package/lib/version/VersionGraph.d.ts +64 -13
- package/package/lib/version/VersionGraph.js +64 -18
- package/package/lib/version/VersionGraph.js.map +1 -1
- package/package/lib/version/VersionInfo.d.ts +17 -0
- package/package/lib/version/VersionInfo.js +12 -0
- package/package/lib/version/VersionInfo.js.map +1 -1
- package/package/package.json +9 -8
- package/package.json +9 -8
package/base/lib/Effects.d.ts
CHANGED
|
@@ -109,6 +109,10 @@ export type Effects = {
|
|
|
109
109
|
}): Promise<string>;
|
|
110
110
|
/** Returns the IP address of StartOS */
|
|
111
111
|
getOsIp(): Promise<string>;
|
|
112
|
+
/** Returns the effective outbound gateway for this service */
|
|
113
|
+
getOutboundGateway(options: {
|
|
114
|
+
callback?: () => void;
|
|
115
|
+
}): Promise<string>;
|
|
112
116
|
/** Creates an interface bound to a specific host and port to show to the user */
|
|
113
117
|
exportServiceInterface(options: ExportServiceInterfaceParams): Promise<null>;
|
|
114
118
|
/** Returns an exported service interface */
|
|
@@ -1,19 +1,50 @@
|
|
|
1
1
|
import { ValueSpec } from '../inputSpecTypes';
|
|
2
2
|
import { Value } from './value';
|
|
3
3
|
import { Effects } from '../../../Effects';
|
|
4
|
-
import {
|
|
4
|
+
import { z } from 'zod';
|
|
5
5
|
import { DeepPartial } from '../../../types';
|
|
6
6
|
import { InputSpecTools } from './inputSpecTools';
|
|
7
|
+
/** Options passed to a lazy builder function when resolving dynamic form field values. */
|
|
7
8
|
export type LazyBuildOptions<Type> = {
|
|
9
|
+
/** The effects interface for runtime operations (e.g. reading files, querying state). */
|
|
8
10
|
effects: Effects;
|
|
11
|
+
/** Previously saved form data to pre-fill the form with, or `null` for fresh creation. */
|
|
9
12
|
prefill: DeepPartial<Type> | null;
|
|
10
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* A function that lazily produces a value, potentially using effects and prefill data.
|
|
16
|
+
* Used by `dynamic*` variants of {@link Value} to compute form field options at runtime.
|
|
17
|
+
*/
|
|
11
18
|
export type LazyBuild<ExpectedOut, Type> = (options: LazyBuildOptions<Type>) => Promise<ExpectedOut> | ExpectedOut;
|
|
19
|
+
/**
|
|
20
|
+
* Defines which keys to keep when filtering an InputSpec.
|
|
21
|
+
* Use `true` to keep a field as-is, or a nested object to filter sub-fields of an object-typed field.
|
|
22
|
+
*/
|
|
23
|
+
export type FilterKeys<T> = {
|
|
24
|
+
[K in keyof T]?: T[K] extends Record<string, any> ? true | FilterKeys<T[K]> : true;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Computes the resulting type after applying a {@link FilterKeys} shape to a type.
|
|
28
|
+
*/
|
|
29
|
+
export type ApplyFilter<T, F> = {
|
|
30
|
+
[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];
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Computes the union of all valid key-path tuples through a nested type.
|
|
34
|
+
* Each tuple represents a path from root to a field, recursing into object-typed sub-fields.
|
|
35
|
+
*/
|
|
36
|
+
export type KeyPaths<T> = {
|
|
37
|
+
[K in keyof T & string]: T[K] extends any[] ? [K] : T[K] extends Record<string, any> ? [K] | [K, ...KeyPaths<T[K]>] : [K];
|
|
38
|
+
}[keyof T & string];
|
|
39
|
+
/** Extracts the runtime type from an {@link InputSpec}. */
|
|
12
40
|
export type ExtractInputSpecType<A extends InputSpec<Record<string, any>, any>> = A extends InputSpec<infer B, any> ? B : never;
|
|
41
|
+
/** Extracts the static validation type from an {@link InputSpec}. */
|
|
13
42
|
export type ExtractInputSpecStaticValidatedAs<A extends InputSpec<any, Record<string, any>>> = A extends InputSpec<any, infer B> ? B : never;
|
|
43
|
+
/** Maps an object type to a record of {@link Value} entries for use with `InputSpec.of`. */
|
|
14
44
|
export type InputSpecOf<A extends Record<string, any>> = {
|
|
15
45
|
[K in keyof A]: Value<A[K]>;
|
|
16
46
|
};
|
|
47
|
+
/** A value that is either directly provided or lazily computed via a {@link LazyBuild} function. */
|
|
17
48
|
export type MaybeLazyValues<A, T> = LazyBuild<A, T> | A;
|
|
18
49
|
/**
|
|
19
50
|
* InputSpecs are the specs that are used by the os input specification form for this service.
|
|
@@ -73,25 +104,115 @@ export const addNodesSpec = InputSpec.of({ hostname: hostname, port: port });
|
|
|
73
104
|
*/
|
|
74
105
|
export declare class InputSpec<Type extends StaticValidatedAs, StaticValidatedAs extends Record<string, any> = Type> {
|
|
75
106
|
private readonly spec;
|
|
76
|
-
readonly validator:
|
|
107
|
+
readonly validator: z.ZodType<StaticValidatedAs>;
|
|
77
108
|
private constructor();
|
|
78
109
|
_TYPE: Type;
|
|
79
110
|
_PARTIAL: DeepPartial<Type>;
|
|
111
|
+
readonly partialValidator: z.ZodType<DeepPartial<StaticValidatedAs>>;
|
|
112
|
+
/**
|
|
113
|
+
* Builds the runtime form specification and combined Zod validator from this InputSpec's fields.
|
|
114
|
+
*
|
|
115
|
+
* @returns An object containing the resolved `spec` (field specs keyed by name) and a combined `validator`
|
|
116
|
+
*/
|
|
80
117
|
build<OuterType>(options: LazyBuildOptions<OuterType>): Promise<{
|
|
81
118
|
spec: {
|
|
82
119
|
[K in keyof Type]: ValueSpec;
|
|
83
120
|
};
|
|
84
|
-
validator:
|
|
85
|
-
}>;
|
|
86
|
-
addKey<Key extends string, V extends Value<any, any, any>>(key: Key, build: V | ((tools: InputSpecTools<Type>) => V)): InputSpec<Type & {
|
|
87
|
-
[K in Key]: V extends Value<infer T, any, any> ? T : never;
|
|
88
|
-
}, StaticValidatedAs & {
|
|
89
|
-
[K in Key]: V extends Value<any, infer S, any> ? S : never;
|
|
121
|
+
validator: z.ZodType<Type>;
|
|
90
122
|
}>;
|
|
123
|
+
/**
|
|
124
|
+
* Adds multiple fields to this spec at once, returning a new `InputSpec` with extended types.
|
|
125
|
+
*
|
|
126
|
+
* @param build - A record of {@link Value} entries, or a function receiving typed tools that returns one
|
|
127
|
+
*/
|
|
91
128
|
add<AddSpec extends Record<string, Value<any, any, any>>>(build: AddSpec | ((tools: InputSpecTools<Type>) => AddSpec)): InputSpec<Type & {
|
|
92
129
|
[K in keyof AddSpec]: AddSpec[K] extends Value<infer T, any, any> ? T : never;
|
|
93
130
|
}, StaticValidatedAs & {
|
|
94
131
|
[K in keyof AddSpec]: AddSpec[K] extends Value<any, infer S, any> ? S : never;
|
|
95
132
|
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Returns a new InputSpec containing only the specified keys.
|
|
135
|
+
* Use `true` to keep a field as-is, or a nested object to filter sub-fields of object-typed fields.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* const full = InputSpec.of({
|
|
140
|
+
* name: Value.text({ name: 'Name', required: true, default: null }),
|
|
141
|
+
* settings: Value.object({ name: 'Settings' }, InputSpec.of({
|
|
142
|
+
* debug: Value.toggle({ name: 'Debug', default: false }),
|
|
143
|
+
* port: Value.number({ name: 'Port', required: true, default: 8080, integer: true }),
|
|
144
|
+
* })),
|
|
145
|
+
* })
|
|
146
|
+
* const filtered = full.filter({ name: true, settings: { debug: true } })
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
filter<F extends FilterKeys<Type>>(keys: F): InputSpec<ApplyFilter<Type, F> & ApplyFilter<StaticValidatedAs, F>, ApplyFilter<StaticValidatedAs, F>>;
|
|
150
|
+
/**
|
|
151
|
+
* Returns a new InputSpec with the specified keys disabled.
|
|
152
|
+
* Use `true` to disable a field, or a nested object to disable sub-fields of object-typed fields.
|
|
153
|
+
* All fields remain in the spec — disabled fields simply cannot be edited by the user.
|
|
154
|
+
*
|
|
155
|
+
* @param keys - Which fields to disable, using the same shape as {@link FilterKeys}
|
|
156
|
+
* @param message - The reason the fields are disabled, displayed to the user
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* const spec = InputSpec.of({
|
|
161
|
+
* name: Value.text({ name: 'Name', required: true, default: null }),
|
|
162
|
+
* settings: Value.object({ name: 'Settings' }, InputSpec.of({
|
|
163
|
+
* debug: Value.toggle({ name: 'Debug', default: false }),
|
|
164
|
+
* port: Value.number({ name: 'Port', required: true, default: 8080, integer: true }),
|
|
165
|
+
* })),
|
|
166
|
+
* })
|
|
167
|
+
* const disabled = spec.disable({ name: true, settings: { debug: true } }, 'Managed by the system')
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
disable(keys: FilterKeys<Type>, message: string): InputSpec<Type, StaticValidatedAs>;
|
|
171
|
+
/**
|
|
172
|
+
* Resolves a key path to its corresponding display name path.
|
|
173
|
+
* Each key is mapped to the `name` property of its built {@link ValueSpec}.
|
|
174
|
+
* Recurses into `Value.object` sub-specs for nested paths.
|
|
175
|
+
*
|
|
176
|
+
* @param path - Typed tuple of field keys (e.g. `["settings", "debug"]`)
|
|
177
|
+
* @param options - Build options providing effects and prefill data
|
|
178
|
+
* @returns Array of display names (e.g. `["Settings", "Debug"]`)
|
|
179
|
+
*/
|
|
180
|
+
namePath<OuterType>(path: KeyPaths<Type>, options: LazyBuildOptions<OuterType>): Promise<string[]>;
|
|
181
|
+
/**
|
|
182
|
+
* Resolves a key path to the description of the target field.
|
|
183
|
+
* Recurses into `Value.object` sub-specs for nested paths.
|
|
184
|
+
*
|
|
185
|
+
* @param path - Typed tuple of field keys (e.g. `["settings", "debug"]`)
|
|
186
|
+
* @param options - Build options providing effects and prefill data
|
|
187
|
+
* @returns The description string, or `null` if the field has no description or was not found
|
|
188
|
+
*/
|
|
189
|
+
description<OuterType>(path: KeyPaths<Type>, options: LazyBuildOptions<OuterType>): Promise<string | null>;
|
|
190
|
+
/**
|
|
191
|
+
* Returns a new InputSpec filtered to only include keys present in the given partial object.
|
|
192
|
+
* For nested `Value.object` fields, recurses into the partial value to filter sub-fields.
|
|
193
|
+
*
|
|
194
|
+
* @param partial - A deep-partial object whose defined keys determine which fields to keep
|
|
195
|
+
*/
|
|
196
|
+
filterFromPartial(partial: DeepPartial<Type>): InputSpec<DeepPartial<Type> & DeepPartial<StaticValidatedAs>, DeepPartial<StaticValidatedAs>>;
|
|
197
|
+
/**
|
|
198
|
+
* Returns a new InputSpec with fields disabled based on which keys are present in the given partial object.
|
|
199
|
+
* For nested `Value.object` fields, recurses into the partial value to disable sub-fields.
|
|
200
|
+
* All fields remain in the spec — disabled fields simply cannot be edited by the user.
|
|
201
|
+
*
|
|
202
|
+
* @param partial - A deep-partial object whose defined keys determine which fields to disable
|
|
203
|
+
* @param message - The reason the fields are disabled, displayed to the user
|
|
204
|
+
*/
|
|
205
|
+
disableFromPartial(partial: DeepPartial<Type>, message: string): InputSpec<Type, StaticValidatedAs>;
|
|
206
|
+
/**
|
|
207
|
+
* Creates an `InputSpec` from a plain record of {@link Value} entries.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* const spec = InputSpec.of({
|
|
212
|
+
* username: Value.text({ name: 'Username', required: true, default: null }),
|
|
213
|
+
* verbose: Value.toggle({ name: 'Verbose Logging', default: false }),
|
|
214
|
+
* })
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
96
217
|
static of<Spec extends Record<string, Value<any, any>>>(spec: Spec): InputSpec<{ [K in keyof Spec]: Spec[K] extends Value<infer T extends any, any, unknown> ? T : never; }, { [K_1 in keyof Spec]: Spec[K_1] extends Value<any, infer T_1, unknown> ? T_1 : never; }>;
|
|
97
218
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InputSpec = void 0;
|
|
4
|
-
const
|
|
4
|
+
const value_1 = require("./value");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const zod_deep_partial_1 = require("zod-deep-partial");
|
|
5
7
|
const inputSpecTools_1 = require("./inputSpecTools");
|
|
6
8
|
/**
|
|
7
9
|
* InputSpecs are the specs that are used by the os input specification form for this service.
|
|
@@ -65,7 +67,13 @@ class InputSpec {
|
|
|
65
67
|
this.validator = validator;
|
|
66
68
|
this._TYPE = null;
|
|
67
69
|
this._PARTIAL = null;
|
|
70
|
+
this.partialValidator = (0, zod_deep_partial_1.zodDeepPartial)(this.validator);
|
|
68
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Builds the runtime form specification and combined Zod validator from this InputSpec's fields.
|
|
74
|
+
*
|
|
75
|
+
* @returns An object containing the resolved `spec` (field specs keyed by name) and a combined `validator`
|
|
76
|
+
*/
|
|
69
77
|
async build(options) {
|
|
70
78
|
const answer = {};
|
|
71
79
|
const validator = {};
|
|
@@ -76,29 +84,231 @@ class InputSpec {
|
|
|
76
84
|
}
|
|
77
85
|
return {
|
|
78
86
|
spec: answer,
|
|
79
|
-
validator:
|
|
87
|
+
validator: zod_1.z.object(validator),
|
|
80
88
|
};
|
|
81
89
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
v.validator,
|
|
88
|
-
])));
|
|
89
|
-
return new InputSpec(newSpec, newValidator);
|
|
90
|
-
}
|
|
90
|
+
/**
|
|
91
|
+
* Adds multiple fields to this spec at once, returning a new `InputSpec` with extended types.
|
|
92
|
+
*
|
|
93
|
+
* @param build - A record of {@link Value} entries, or a function receiving typed tools that returns one
|
|
94
|
+
*/
|
|
91
95
|
add(build) {
|
|
92
96
|
const addedValues = build instanceof Function ? build((0, inputSpecTools_1.createInputSpecTools)()) : build;
|
|
93
97
|
const newSpec = { ...this.spec, ...addedValues };
|
|
94
|
-
const newValidator =
|
|
98
|
+
const newValidator = zod_1.z.object(Object.fromEntries(Object.entries(newSpec).map(([k, v]) => [
|
|
95
99
|
k,
|
|
96
100
|
v.validator,
|
|
97
101
|
])));
|
|
98
102
|
return new InputSpec(newSpec, newValidator);
|
|
99
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns a new InputSpec containing only the specified keys.
|
|
106
|
+
* Use `true` to keep a field as-is, or a nested object to filter sub-fields of object-typed fields.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* const full = InputSpec.of({
|
|
111
|
+
* name: Value.text({ name: 'Name', required: true, default: null }),
|
|
112
|
+
* settings: Value.object({ name: 'Settings' }, InputSpec.of({
|
|
113
|
+
* debug: Value.toggle({ name: 'Debug', default: false }),
|
|
114
|
+
* port: Value.number({ name: 'Port', required: true, default: 8080, integer: true }),
|
|
115
|
+
* })),
|
|
116
|
+
* })
|
|
117
|
+
* const filtered = full.filter({ name: true, settings: { debug: true } })
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
filter(keys) {
|
|
121
|
+
const newSpec = {};
|
|
122
|
+
for (const k of Object.keys(keys)) {
|
|
123
|
+
const filterVal = keys[k];
|
|
124
|
+
const value = this.spec[k];
|
|
125
|
+
if (!value)
|
|
126
|
+
continue;
|
|
127
|
+
if (filterVal === true) {
|
|
128
|
+
newSpec[k] = value;
|
|
129
|
+
}
|
|
130
|
+
else if (typeof filterVal === 'object' && filterVal !== null) {
|
|
131
|
+
const objectMeta = value._objectSpec;
|
|
132
|
+
if (objectMeta) {
|
|
133
|
+
const filteredInner = objectMeta.inputSpec.filter(filterVal);
|
|
134
|
+
newSpec[k] = value_1.Value.object(objectMeta.params, filteredInner);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
newSpec[k] = value;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const newValidator = zod_1.z.object(Object.fromEntries(Object.entries(newSpec).map(([k, v]) => [k, v.validator])));
|
|
142
|
+
return new InputSpec(newSpec, newValidator);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Returns a new InputSpec with the specified keys disabled.
|
|
146
|
+
* Use `true` to disable a field, or a nested object to disable sub-fields of object-typed fields.
|
|
147
|
+
* All fields remain in the spec — disabled fields simply cannot be edited by the user.
|
|
148
|
+
*
|
|
149
|
+
* @param keys - Which fields to disable, using the same shape as {@link FilterKeys}
|
|
150
|
+
* @param message - The reason the fields are disabled, displayed to the user
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* const spec = InputSpec.of({
|
|
155
|
+
* name: Value.text({ name: 'Name', required: true, default: null }),
|
|
156
|
+
* settings: Value.object({ name: 'Settings' }, InputSpec.of({
|
|
157
|
+
* debug: Value.toggle({ name: 'Debug', default: false }),
|
|
158
|
+
* port: Value.number({ name: 'Port', required: true, default: 8080, integer: true }),
|
|
159
|
+
* })),
|
|
160
|
+
* })
|
|
161
|
+
* const disabled = spec.disable({ name: true, settings: { debug: true } }, 'Managed by the system')
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
disable(keys, message) {
|
|
165
|
+
const newSpec = {};
|
|
166
|
+
for (const k in this.spec) {
|
|
167
|
+
const filterVal = keys[k];
|
|
168
|
+
const value = this.spec[k];
|
|
169
|
+
if (!filterVal) {
|
|
170
|
+
newSpec[k] = value;
|
|
171
|
+
}
|
|
172
|
+
else if (filterVal === true) {
|
|
173
|
+
newSpec[k] = value.withDisabled(message);
|
|
174
|
+
}
|
|
175
|
+
else if (typeof filterVal === 'object' && filterVal !== null) {
|
|
176
|
+
const objectMeta = value._objectSpec;
|
|
177
|
+
if (objectMeta) {
|
|
178
|
+
const disabledInner = objectMeta.inputSpec.disable(filterVal, message);
|
|
179
|
+
newSpec[k] = value_1.Value.object(objectMeta.params, disabledInner);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
newSpec[k] = value.withDisabled(message);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const newValidator = zod_1.z.object(Object.fromEntries(Object.entries(newSpec).map(([k, v]) => [k, v.validator])));
|
|
187
|
+
return new InputSpec(newSpec, newValidator);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Resolves a key path to its corresponding display name path.
|
|
191
|
+
* Each key is mapped to the `name` property of its built {@link ValueSpec}.
|
|
192
|
+
* Recurses into `Value.object` sub-specs for nested paths.
|
|
193
|
+
*
|
|
194
|
+
* @param path - Typed tuple of field keys (e.g. `["settings", "debug"]`)
|
|
195
|
+
* @param options - Build options providing effects and prefill data
|
|
196
|
+
* @returns Array of display names (e.g. `["Settings", "Debug"]`)
|
|
197
|
+
*/
|
|
198
|
+
async namePath(path, options) {
|
|
199
|
+
if (path.length === 0)
|
|
200
|
+
return [];
|
|
201
|
+
const [key, ...rest] = path;
|
|
202
|
+
const value = this.spec[key];
|
|
203
|
+
if (!value)
|
|
204
|
+
return [];
|
|
205
|
+
const built = await value.build(options);
|
|
206
|
+
const name = 'name' in built.spec ? built.spec.name : key;
|
|
207
|
+
if (rest.length === 0)
|
|
208
|
+
return [name];
|
|
209
|
+
const objectMeta = value._objectSpec;
|
|
210
|
+
if (objectMeta) {
|
|
211
|
+
const innerNames = await objectMeta.inputSpec.namePath(rest, options);
|
|
212
|
+
return [name, ...innerNames];
|
|
213
|
+
}
|
|
214
|
+
return [name];
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Resolves a key path to the description of the target field.
|
|
218
|
+
* Recurses into `Value.object` sub-specs for nested paths.
|
|
219
|
+
*
|
|
220
|
+
* @param path - Typed tuple of field keys (e.g. `["settings", "debug"]`)
|
|
221
|
+
* @param options - Build options providing effects and prefill data
|
|
222
|
+
* @returns The description string, or `null` if the field has no description or was not found
|
|
223
|
+
*/
|
|
224
|
+
async description(path, options) {
|
|
225
|
+
if (path.length === 0)
|
|
226
|
+
return null;
|
|
227
|
+
const [key, ...rest] = path;
|
|
228
|
+
const value = this.spec[key];
|
|
229
|
+
if (!value)
|
|
230
|
+
return null;
|
|
231
|
+
if (rest.length === 0) {
|
|
232
|
+
const built = await value.build(options);
|
|
233
|
+
return 'description' in built.spec
|
|
234
|
+
? built.spec.description
|
|
235
|
+
: null;
|
|
236
|
+
}
|
|
237
|
+
const objectMeta = value._objectSpec;
|
|
238
|
+
if (objectMeta) {
|
|
239
|
+
return objectMeta.inputSpec.description(rest, options);
|
|
240
|
+
}
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Returns a new InputSpec filtered to only include keys present in the given partial object.
|
|
245
|
+
* For nested `Value.object` fields, recurses into the partial value to filter sub-fields.
|
|
246
|
+
*
|
|
247
|
+
* @param partial - A deep-partial object whose defined keys determine which fields to keep
|
|
248
|
+
*/
|
|
249
|
+
filterFromPartial(partial) {
|
|
250
|
+
const newSpec = {};
|
|
251
|
+
for (const k of Object.keys(partial)) {
|
|
252
|
+
const value = this.spec[k];
|
|
253
|
+
if (!value)
|
|
254
|
+
continue;
|
|
255
|
+
const objectMeta = value._objectSpec;
|
|
256
|
+
if (objectMeta) {
|
|
257
|
+
const partialVal = partial[k];
|
|
258
|
+
if (typeof partialVal === 'object' && partialVal !== null) {
|
|
259
|
+
const filteredInner = objectMeta.inputSpec.filterFromPartial(partialVal);
|
|
260
|
+
newSpec[k] = value_1.Value.object(objectMeta.params, filteredInner);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
newSpec[k] = value;
|
|
265
|
+
}
|
|
266
|
+
const newValidator = zod_1.z.object(Object.fromEntries(Object.entries(newSpec).map(([k, v]) => [k, v.validator])));
|
|
267
|
+
return new InputSpec(newSpec, newValidator);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Returns a new InputSpec with fields disabled based on which keys are present in the given partial object.
|
|
271
|
+
* For nested `Value.object` fields, recurses into the partial value to disable sub-fields.
|
|
272
|
+
* All fields remain in the spec — disabled fields simply cannot be edited by the user.
|
|
273
|
+
*
|
|
274
|
+
* @param partial - A deep-partial object whose defined keys determine which fields to disable
|
|
275
|
+
* @param message - The reason the fields are disabled, displayed to the user
|
|
276
|
+
*/
|
|
277
|
+
disableFromPartial(partial, message) {
|
|
278
|
+
const newSpec = {};
|
|
279
|
+
for (const k in this.spec) {
|
|
280
|
+
const value = this.spec[k];
|
|
281
|
+
if (!(k in partial)) {
|
|
282
|
+
newSpec[k] = value;
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
const objectMeta = value._objectSpec;
|
|
286
|
+
if (objectMeta) {
|
|
287
|
+
const partialVal = partial[k];
|
|
288
|
+
if (typeof partialVal === 'object' && partialVal !== null) {
|
|
289
|
+
const disabledInner = objectMeta.inputSpec.disableFromPartial(partialVal, message);
|
|
290
|
+
newSpec[k] = value_1.Value.object(objectMeta.params, disabledInner);
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
newSpec[k] = value.withDisabled(message);
|
|
295
|
+
}
|
|
296
|
+
const newValidator = zod_1.z.object(Object.fromEntries(Object.entries(newSpec).map(([k, v]) => [k, v.validator])));
|
|
297
|
+
return new InputSpec(newSpec, newValidator);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Creates an `InputSpec` from a plain record of {@link Value} entries.
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```ts
|
|
304
|
+
* const spec = InputSpec.of({
|
|
305
|
+
* username: Value.text({ name: 'Username', required: true, default: null }),
|
|
306
|
+
* verbose: Value.toggle({ name: 'Verbose Logging', default: false }),
|
|
307
|
+
* })
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
100
310
|
static of(spec) {
|
|
101
|
-
const validator =
|
|
311
|
+
const validator = zod_1.z.object(Object.fromEntries(Object.entries(spec).map(([k, v]) => [k, v.validator])));
|
|
102
312
|
return new InputSpec(spec, validator);
|
|
103
313
|
}
|
|
104
314
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputSpec.js","sourceRoot":"","sources":["../../../../../../base/lib/actions/input/builder/inputSpec.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"inputSpec.js","sourceRoot":"","sources":["../../../../../../base/lib/actions/input/builder/inputSpec.ts"],"names":[],"mapp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AU,CAAC,SAAS,CAAC,kBAAkB,CAC3D,UAAU,EACV,OAAO,CACR,CAAA;oBACD,OAAO,CAAC,CAAC,CAAC,GAAG,aAAK,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;oBAC3D,SAAQ;gBACV,CAAC;YACH,CAAC;YACD,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;QAC1C,CAAC;QACD,MAAM,YAAY,GAAG,OAAC,CAAC,MAAM,CAC3B,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAC1D,CACF,CAAA;QACD,OAAO,IAAI,SAAS,CAAC,OAAc,EAAE,YAAmB,CAAQ,CAAA;IAClE,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,CAA+C,IAAU;QAChE,MAAM,SAAS,GAAG,OAAC,CAAC,MAAM,CACxB,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CACvD,CACF,CAAA;QACD,OAAO,IAAI,SAAS,CAWlB,IAAI,EAAE,SAAgB,CAAC,CAAA;IAC3B,CAAC;CACF;AApVD,8BAoVC"}
|
|
@@ -4,7 +4,7 @@ import { List } from './list';
|
|
|
4
4
|
import { UnionRes, UnionResStaticValidatedAs, Variants } from './variants';
|
|
5
5
|
import { Pattern, RandomString, ValueSpecDatetime, ValueSpecText } from '../inputSpecTypes';
|
|
6
6
|
import { DefaultString } from '../inputSpecTypes';
|
|
7
|
-
import {
|
|
7
|
+
import { z } from 'zod';
|
|
8
8
|
import { ListValueSpecText } from '../inputSpecTypes';
|
|
9
9
|
export interface InputSpecTools<OuterType> {
|
|
10
10
|
Value: BoundValue<OuterType>;
|
|
@@ -145,8 +145,8 @@ export interface BoundValue<OuterType> {
|
|
|
145
145
|
variants: Variants<VariantValues>;
|
|
146
146
|
default: keyof VariantValues & string;
|
|
147
147
|
disabled: string[] | false | string;
|
|
148
|
-
}, OuterType>, validator:
|
|
149
|
-
dynamicHidden<T>(getParser: LazyBuild<
|
|
148
|
+
}, OuterType>, validator: z.ZodType<UnionResStaticValidatedAs<StaticVariantValues>>): Value<UnionRes<VariantValues>, UnionResStaticValidatedAs<StaticVariantValues>, OuterType>;
|
|
149
|
+
dynamicHidden<T>(getParser: LazyBuild<z.ZodType<T>, OuterType>): Value<T, T, OuterType>;
|
|
150
150
|
}
|
|
151
151
|
export interface BoundList<OuterType> {
|
|
152
152
|
text: typeof List.text;
|
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import { InputSpec, LazyBuild } from './inputSpec';
|
|
2
2
|
import { ListValueSpecText, Pattern, RandomString, UniqueBy, ValueSpecList } from '../inputSpecTypes';
|
|
3
|
-
import {
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
/**
|
|
5
|
+
* Builder class for defining list-type form fields.
|
|
6
|
+
*
|
|
7
|
+
* A list presents an interface to add, remove, and reorder items. Items can be
|
|
8
|
+
* either text strings ({@link List.text}) or structured objects ({@link List.obj}).
|
|
9
|
+
*
|
|
10
|
+
* Used with {@link Value.list} to include a list field in an {@link InputSpec}.
|
|
11
|
+
*/
|
|
4
12
|
export declare class List<Type extends StaticValidatedAs, StaticValidatedAs = Type, OuterType = unknown> {
|
|
5
13
|
build: LazyBuild<{
|
|
6
14
|
spec: ValueSpecList;
|
|
7
|
-
validator:
|
|
15
|
+
validator: z.ZodType<Type>;
|
|
8
16
|
}, OuterType>;
|
|
9
|
-
readonly validator:
|
|
17
|
+
readonly validator: z.ZodType<StaticValidatedAs>;
|
|
10
18
|
private constructor();
|
|
11
19
|
readonly _TYPE: Type;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a list of text input items.
|
|
22
|
+
*
|
|
23
|
+
* @param a - List-level options (name, description, min/max length, defaults)
|
|
24
|
+
* @param aSpec - Item-level options (patterns, input mode, masking, generation)
|
|
25
|
+
*/
|
|
12
26
|
static text(a: {
|
|
13
27
|
name: string;
|
|
14
28
|
description?: string | null;
|
|
@@ -49,6 +63,7 @@ export declare class List<Type extends StaticValidatedAs, StaticValidatedAs = Ty
|
|
|
49
63
|
*/
|
|
50
64
|
generate?: null | RandomString;
|
|
51
65
|
}): List<string[], string[], unknown>;
|
|
66
|
+
/** Like {@link List.text} but options are resolved lazily at runtime via a builder function. */
|
|
52
67
|
static dynamicText<OuterType = unknown>(getA: LazyBuild<{
|
|
53
68
|
name: string;
|
|
54
69
|
description?: string | null;
|
|
@@ -67,6 +82,12 @@ export declare class List<Type extends StaticValidatedAs, StaticValidatedAs = Ty
|
|
|
67
82
|
inputmode?: ListValueSpecText['inputmode'];
|
|
68
83
|
};
|
|
69
84
|
}, OuterType>): List<string[], string[], OuterType>;
|
|
85
|
+
/**
|
|
86
|
+
* Creates a list of structured object items, each defined by a nested {@link InputSpec}.
|
|
87
|
+
*
|
|
88
|
+
* @param a - List-level options (name, description, min/max length)
|
|
89
|
+
* @param aSpec - Item-level options (the nested spec, display expression, uniqueness constraint)
|
|
90
|
+
*/
|
|
70
91
|
static obj<Type extends StaticValidatedAs, StaticValidatedAs extends Record<string, any>>(a: {
|
|
71
92
|
name: string;
|
|
72
93
|
description?: string | null;
|
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.List = void 0;
|
|
4
|
-
const
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Builder class for defining list-type form fields.
|
|
7
|
+
*
|
|
8
|
+
* A list presents an interface to add, remove, and reorder items. Items can be
|
|
9
|
+
* either text strings ({@link List.text}) or structured objects ({@link List.obj}).
|
|
10
|
+
*
|
|
11
|
+
* Used with {@link Value.list} to include a list field in an {@link InputSpec}.
|
|
12
|
+
*/
|
|
5
13
|
class List {
|
|
6
14
|
constructor(build, validator) {
|
|
7
15
|
this.build = build;
|
|
8
16
|
this.validator = validator;
|
|
9
17
|
this._TYPE = null;
|
|
10
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a list of text input items.
|
|
21
|
+
*
|
|
22
|
+
* @param a - List-level options (name, description, min/max length, defaults)
|
|
23
|
+
* @param aSpec - Item-level options (patterns, input mode, masking, generation)
|
|
24
|
+
*/
|
|
11
25
|
static text(a, aSpec) {
|
|
12
|
-
const validator =
|
|
26
|
+
const validator = zod_1.z.array(zod_1.z.string());
|
|
13
27
|
return new List(() => {
|
|
14
28
|
const spec = {
|
|
15
29
|
type: 'text',
|
|
@@ -36,8 +50,9 @@ class List {
|
|
|
36
50
|
return { spec: built, validator };
|
|
37
51
|
}, validator);
|
|
38
52
|
}
|
|
53
|
+
/** Like {@link List.text} but options are resolved lazily at runtime via a builder function. */
|
|
39
54
|
static dynamicText(getA) {
|
|
40
|
-
const validator =
|
|
55
|
+
const validator = zod_1.z.array(zod_1.z.string());
|
|
41
56
|
return new List(async (options) => {
|
|
42
57
|
const { spec: aSpec, ...a } = await getA(options);
|
|
43
58
|
const spec = {
|
|
@@ -65,6 +80,12 @@ class List {
|
|
|
65
80
|
return { spec: built, validator };
|
|
66
81
|
}, validator);
|
|
67
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Creates a list of structured object items, each defined by a nested {@link InputSpec}.
|
|
85
|
+
*
|
|
86
|
+
* @param a - List-level options (name, description, min/max length)
|
|
87
|
+
* @param aSpec - Item-level options (the nested spec, display expression, uniqueness constraint)
|
|
88
|
+
*/
|
|
68
89
|
static obj(a, aSpec) {
|
|
69
90
|
return new List(async (options) => {
|
|
70
91
|
const { spec: previousSpecSpec, ...restSpec } = aSpec;
|
|
@@ -91,9 +112,9 @@ class List {
|
|
|
91
112
|
disabled: false,
|
|
92
113
|
...value,
|
|
93
114
|
},
|
|
94
|
-
validator:
|
|
115
|
+
validator: zod_1.z.array(built.validator),
|
|
95
116
|
};
|
|
96
|
-
},
|
|
117
|
+
}, zod_1.z.array(aSpec.spec.validator));
|
|
97
118
|
}
|
|
98
119
|
}
|
|
99
120
|
exports.List = List;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../../../../base/lib/actions/input/builder/list.ts"],"names":[],"mappings":";;;AASA,
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../../../../base/lib/actions/input/builder/list.ts"],"names":[],"mappings":";;;AASA,6BAAuB;AAEvB;;;;;;;GAOG;AACH,MAAa,IAAI;IAKf,YACS,KAMN,EACe,SAAuC;QAPhD,UAAK,GAAL,KAAK,CAMX;QACe,cAAS,GAAT,SAAS,CAA8B;QAEhD,UAAK,GAAS,IAAW,CAAA;IAD/B,CAAC;IAGJ;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CACT,CAOC,EACD,KAgCC;QAED,MAAM,SAAS,GAAG,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAA;QACrC,OAAO,IAAI,IAAI,CAAW,GAAG,EAAE;YAC7B,MAAM,IAAI,GAAG;gBACX,IAAI,EAAE,MAAe;gBACrB,WAAW,EAAE,IAAI;gBACjB,SAAS,EAAE,IAAI;gBACf,SAAS,EAAE,IAAI;gBACf,MAAM,EAAE,KAAK;gBACb,SAAS,EAAE,MAAe;gBAC1B,QAAQ,EAAE,IAAI;gBACd,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,EAAE;gBAC9B,GAAG,KAAK;aACT,CAAA;YACD,MAAM,KAAK,GAA4B;gBACrC,WAAW,EAAE,IAAI;gBACjB,OAAO,EAAE,IAAI;gBACb,OAAO,EA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