@unbound-app/cli 0.11.0 → 1.1.1

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.
@@ -0,0 +1,133 @@
1
+ import { TSchema } from "typebox";
2
+ /** A value one schema-declared setting holds. */
3
+ type SettingPrimitive = string | number | boolean;
4
+ /** A value any schema-declared setting holds. */
5
+ type SettingValue = SettingPrimitive | string[];
6
+ type OptionLabel = string | {
7
+ title: string;
8
+ subtitle?: string;
9
+ };
10
+ /** A settings.ts predicate: it reads every setting and says whether a row shows or is enabled. */
11
+ type Predicate = (settings: never) => boolean;
12
+ /** Every builder's options; the generated typings narrow them per builder and `displayAs`. */
13
+ export type BuilderOptions = {
14
+ title?: string;
15
+ subtitle?: string;
16
+ hidden?: boolean;
17
+ requiresRestart?: boolean;
18
+ visibleWhen?: string | Predicate;
19
+ disabledWhen?: string | Predicate;
20
+ displayAs?: string;
21
+ default?: SettingValue;
22
+ min?: number;
23
+ max?: number;
24
+ step?: number;
25
+ units?: string[];
26
+ minLength?: number;
27
+ maxLength?: number;
28
+ placeholder?: string;
29
+ alpha?: boolean;
30
+ presets?: string[];
31
+ palette?: boolean;
32
+ maxSize?: number;
33
+ options?: Record<string, OptionLabel>;
34
+ of?: TSchema;
35
+ minItems?: number;
36
+ maxItems?: number;
37
+ action?: string;
38
+ confirm?: string;
39
+ tone?: string;
40
+ };
41
+ /** The options of `defineSettings`. */
42
+ export type DefineOptions = {
43
+ title?: string;
44
+ };
45
+ /**
46
+ * @description Builds a `boolean` setting.
47
+ * @param options Its labels, default and display.
48
+ * @returns Its schema.
49
+ */
50
+ declare function boolean(options: BuilderOptions): TSchema;
51
+ /**
52
+ * @description Builds a `number` setting.
53
+ * @param options Its labels, default, range and display.
54
+ * @returns Its schema.
55
+ */
56
+ declare function number(options: BuilderOptions): TSchema;
57
+ /**
58
+ * @description Builds a whole-number setting.
59
+ * @param options Its labels, default, range and display.
60
+ * @returns Its schema.
61
+ */
62
+ declare function integer(options: BuilderOptions): TSchema;
63
+ /**
64
+ * @description Builds a `string` setting, or with no options an `array` item.
65
+ * @param options Its labels, default, display and the display's options.
66
+ * @returns Its schema.
67
+ */
68
+ declare function string(options?: BuilderOptions): TSchema;
69
+ /**
70
+ * @description Builds a setting holding one of its options' keys, or with only `options` an `array` item.
71
+ * @param options Its labels, default, options and display.
72
+ * @returns Its schema.
73
+ */
74
+ declare function choice(options: BuilderOptions): TSchema;
75
+ /**
76
+ * @description Builds a list setting of `of` items.
77
+ * @param options Its labels, item, limits and display.
78
+ * @returns Its schema.
79
+ */
80
+ declare function array(options: BuilderOptions): TSchema;
81
+ /**
82
+ * @description Builds a section of settings.
83
+ * @param options Its labels and display.
84
+ * @param properties Its settings and buttons.
85
+ * @returns Its schema.
86
+ */
87
+ declare function section(options: BuilderOptions, properties: Record<string, TSchema>): TSchema;
88
+ /**
89
+ * @description Builds a button row that runs an export of src/actions.ts; it stores nothing.
90
+ * @param options Its labels, action, confirmation and display.
91
+ * @returns Its schema.
92
+ */
93
+ declare function button(options: BuilderOptions): TSchema;
94
+ /**
95
+ * @description Builds a notice row that shows a message in its panel; it stores nothing.
96
+ * @param options Its labels, tone and `visibleWhen`.
97
+ * @returns Its schema.
98
+ */
99
+ declare function notice(options: BuilderOptions): TSchema;
100
+ /** The setting builders, one per stored primitive; `displayAs` picks the widget. */
101
+ export declare const setting: {
102
+ boolean: typeof boolean;
103
+ number: typeof number;
104
+ integer: typeof integer;
105
+ string: typeof string;
106
+ choice: typeof choice;
107
+ array: typeof array;
108
+ section: typeof section;
109
+ button: typeof button;
110
+ notice: typeof notice;
111
+ };
112
+ /**
113
+ * @description Declares a plugin's settings: the default export of its settings.ts.
114
+ * @param properties The settings, sections and buttons, built with {@link setting}.
115
+ * @param options The message key of the title of the section holding the top-level settings.
116
+ * @returns The TypeBox object schema, marked as a settings schema.
117
+ */
118
+ export declare function defineSettings(properties: Record<string, TSchema>, options?: DefineOptions): TSchema;
119
+ declare const _default: {
120
+ defineSettings: typeof defineSettings;
121
+ setting: {
122
+ boolean: typeof boolean;
123
+ number: typeof number;
124
+ integer: typeof integer;
125
+ string: typeof string;
126
+ choice: typeof choice;
127
+ array: typeof array;
128
+ section: typeof section;
129
+ button: typeof button;
130
+ notice: typeof notice;
131
+ };
132
+ };
133
+ export { _default as default };
@@ -0,0 +1,169 @@
1
+ import Type$1 from "typebox";
2
+ // src/settings/schema.ts
3
+ function defined(values) {
4
+ return Object.fromEntries(Object.entries(values).filter(([, value]) => value !== void 0));
5
+ }
6
+ function condition(value) {
7
+ return typeof value === "function" ? { predicate: true } : value;
8
+ }
9
+ function meta(kind, displayAs, options, extra = {}) {
10
+ return {
11
+ kind,
12
+ displayAs,
13
+ ...defined({
14
+ title: options.title,
15
+ subtitle: options.subtitle,
16
+ hidden: options.hidden,
17
+ requiresRestart: options.requiresRestart,
18
+ visibleWhen: condition(options.visibleWhen),
19
+ disabledWhen: condition(options.disabledWhen),
20
+ default: options.default,
21
+ ...extra
22
+ })
23
+ };
24
+ }
25
+ function numeric(kind, options) {
26
+ const ranged = options.min !== void 0 && options.max !== void 0;
27
+ return meta(kind, options.displayAs ?? (ranged ? "slider" : "input"), options, {
28
+ minimum: options.min,
29
+ maximum: options.max,
30
+ multipleOf: options.step,
31
+ units: options.units
32
+ });
33
+ }
34
+ function choices({ options = {} }) {
35
+ return Object.entries(options).map(([value, label]) => typeof label === "string" ? {
36
+ const: value,
37
+ title: label
38
+ } : {
39
+ const: value,
40
+ ...label
41
+ });
42
+ }
43
+ /**
44
+ * @description Builds a `boolean` setting.
45
+ * @param options Its labels, default and display.
46
+ * @returns Its schema.
47
+ */
48
+ function boolean(options) {
49
+ return Type$1.Boolean(meta("boolean", options.displayAs ?? "switch", options));
50
+ }
51
+ /**
52
+ * @description Builds a `number` setting.
53
+ * @param options Its labels, default, range and display.
54
+ * @returns Its schema.
55
+ */
56
+ function number(options) {
57
+ return Type$1.Number(numeric("number", options));
58
+ }
59
+ /**
60
+ * @description Builds a whole-number setting.
61
+ * @param options Its labels, default, range and display.
62
+ * @returns Its schema.
63
+ */
64
+ function integer(options) {
65
+ return Type$1.Integer(numeric("integer", options));
66
+ }
67
+ /**
68
+ * @description Builds a `string` setting, or with no options an `array` item.
69
+ * @param options Its labels, default, display and the display's options.
70
+ * @returns Its schema.
71
+ */
72
+ function string(options = {}) {
73
+ return Type$1.String(meta("string", options.displayAs ?? "input", {
74
+ default: "",
75
+ ...options
76
+ }, {
77
+ minLength: options.minLength,
78
+ maxLength: options.maxLength,
79
+ placeholder: options.placeholder,
80
+ alpha: options.alpha,
81
+ presets: options.presets,
82
+ palette: options.palette,
83
+ maxSize: options.maxSize
84
+ }));
85
+ }
86
+ /**
87
+ * @description Builds a setting holding one of its options' keys, or with only `options` an `array` item.
88
+ * @param options Its labels, default, options and display.
89
+ * @returns Its schema.
90
+ */
91
+ function choice(options) {
92
+ const list = choices(options);
93
+ const displayAs = options.displayAs ?? (list.length > 5 ? "picker" : "radio");
94
+ return Type$1.Union(list.map((option) => Type$1.Literal(option.const)), meta("choice", displayAs, options, { options: list }));
95
+ }
96
+ /**
97
+ * @description Builds a list setting of `of` items.
98
+ * @param options Its labels, item, limits and display.
99
+ * @returns Its schema.
100
+ */
101
+ function array(options) {
102
+ const item = Object.fromEntries(Object.entries(options.of ?? {}).filter(([key]) => key !== "default"));
103
+ const displayAs = options.displayAs ?? (item.kind === "choice" ? "checkboxes" : "list");
104
+ return Type$1.Array(Type$1.Unknown(), meta("array", displayAs, {
105
+ default: [],
106
+ ...options
107
+ }, {
108
+ minItems: options.minItems,
109
+ maxItems: options.maxItems,
110
+ of: item
111
+ }));
112
+ }
113
+ /**
114
+ * @description Builds a section of settings.
115
+ * @param options Its labels and display.
116
+ * @param properties Its settings and buttons.
117
+ * @returns Its schema.
118
+ */
119
+ function section(options, properties) {
120
+ return Type$1.Object(properties, meta("section", options.displayAs ?? "group", options));
121
+ }
122
+ /**
123
+ * @description Builds a button row that runs an export of src/actions.ts; it stores nothing.
124
+ * @param options Its labels, action, confirmation and display.
125
+ * @returns Its schema.
126
+ */
127
+ function button(options) {
128
+ return Type$1.Null(meta("button", options.displayAs ?? "button", options, {
129
+ action: options.action,
130
+ confirm: options.confirm
131
+ }));
132
+ }
133
+ /**
134
+ * @description Builds a notice row that shows a message in its panel; it stores nothing.
135
+ * @param options Its labels, tone and `visibleWhen`.
136
+ * @returns Its schema.
137
+ */
138
+ function notice(options) {
139
+ return Type$1.Null(meta("notice", "notice", options, { tone: options.tone ?? "info" }));
140
+ }
141
+ /** The setting builders, one per stored primitive; `displayAs` picks the widget. */
142
+ const setting = {
143
+ boolean,
144
+ number,
145
+ integer,
146
+ string,
147
+ choice,
148
+ array,
149
+ section,
150
+ button,
151
+ notice
152
+ };
153
+ /**
154
+ * @description Declares a plugin's settings: the default export of its settings.ts.
155
+ * @param properties The settings, sections and buttons, built with {@link setting}.
156
+ * @param options The message key of the title of the section holding the top-level settings.
157
+ * @returns The TypeBox object schema, marked as a settings schema.
158
+ */
159
+ function defineSettings(properties, options = {}) {
160
+ return Type$1.Object(properties, defined({
161
+ kind: "settings",
162
+ title: options.title
163
+ }));
164
+ }
165
+ var schema_default = {
166
+ defineSettings,
167
+ setting
168
+ };
169
+ export { schema_default as default, defineSettings, setting };