@nebulahome/package-sdk 0.0.0-stage → 1.0.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.
- package/CHANGELOG.md +33 -0
- package/LICENSE +21 -0
- package/README.md +141 -2
- package/dist/chunks/context.d.ts +369 -0
- package/dist/chunks/host.js +53 -0
- package/dist/chunks/json.d.ts +657 -0
- package/dist/chunks/node-build.js +13075 -0
- package/dist/chunks/node-build2.js +2 -0
- package/dist/chunks/node-config.js +6886 -0
- package/dist/chunks/node-pack.js +3455 -0
- package/dist/chunks/node-problems.js +54 -0
- package/dist/chunks/props.d.ts +68 -0
- package/dist/chunks/version.js +12 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +144 -0
- package/dist/components.d.ts +381 -0
- package/dist/components.js +210 -0
- package/dist/index.d.ts +205 -0
- package/dist/index.js +243 -0
- package/dist/server.d.ts +30 -0
- package/dist/server.js +17 -0
- package/dist/styles.css +549 -0
- package/dist/testing.d.ts +117 -0
- package/dist/testing.js +608 -0
- package/dist/ui.d.ts +320 -0
- package/dist/ui.js +180 -0
- package/dist/vite.d.ts +88 -0
- package/dist/vite.js +3 -0
- package/package.json +110 -3
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { r as hostMember, t as COMPONENTS_MODULE } from "./chunks/host.js";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
//#region src/components/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* `@nebulahome/package-sdk/components`: the part of the interface's design system a package may
|
|
6
|
+
* draw with (PACKAGES_DOCS.md 7.1), lent at run time like React. A convenience, never a
|
|
7
|
+
* constraint: a package may draw anything, with any CSS.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* An action.
|
|
11
|
+
*
|
|
12
|
+
* @param props - A native button's attributes, a variant and a size.
|
|
13
|
+
* @returns The button.
|
|
14
|
+
*/
|
|
15
|
+
function Button(props) {
|
|
16
|
+
return createElement(hostMember(COMPONENTS_MODULE, "Button", "1.0"), props);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* An action with an icon and no text.
|
|
20
|
+
*
|
|
21
|
+
* @param props - What it does, its glyph, its variant and size.
|
|
22
|
+
* @returns The button.
|
|
23
|
+
*/
|
|
24
|
+
function IconButton(props) {
|
|
25
|
+
return createElement(hostMember(COMPONENTS_MODULE, "IconButton", "1.0"), props);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A catalogue icon.
|
|
29
|
+
*
|
|
30
|
+
* @param props - Its id and size.
|
|
31
|
+
* @returns The icon.
|
|
32
|
+
*/
|
|
33
|
+
function Icon(props) {
|
|
34
|
+
return createElement(hostMember(COMPONENTS_MODULE, "Icon", "1.0"), props);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A short state.
|
|
38
|
+
*
|
|
39
|
+
* @param props - Its tone, size and text.
|
|
40
|
+
* @returns The badge.
|
|
41
|
+
*/
|
|
42
|
+
function Badge(props) {
|
|
43
|
+
return createElement(hostMember(COMPONENTS_MODULE, "Badge", "1.0"), props);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A titled section.
|
|
47
|
+
*
|
|
48
|
+
* @param props - Its title, action and content.
|
|
49
|
+
* @returns The panel.
|
|
50
|
+
*/
|
|
51
|
+
function Panel(props) {
|
|
52
|
+
return createElement(hostMember(COMPONENTS_MODULE, "Panel", "1.0"), props);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A row of a panel.
|
|
56
|
+
*
|
|
57
|
+
* @param props - Its title, note and control.
|
|
58
|
+
* @returns The row.
|
|
59
|
+
*/
|
|
60
|
+
function PanelRow(props) {
|
|
61
|
+
return createElement(hostMember(COMPONENTS_MODULE, "PanelRow", "1.0"), props);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A note under a panel.
|
|
65
|
+
*
|
|
66
|
+
* @param props - What it says.
|
|
67
|
+
* @returns The note.
|
|
68
|
+
*/
|
|
69
|
+
function PanelNote(props) {
|
|
70
|
+
return createElement(hostMember(COMPONENTS_MODULE, "PanelNote", "1.0"), props);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A card's two-line heading, as the dashboard's own cards draw it.
|
|
74
|
+
*
|
|
75
|
+
* @param props - Its title, subtitle and tail.
|
|
76
|
+
* @returns The heading.
|
|
77
|
+
*/
|
|
78
|
+
function CardHeading(props) {
|
|
79
|
+
return createElement(hostMember(COMPONENTS_MODULE, "CardHeading", "1.0"), props);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A reading as a number and its unit.
|
|
83
|
+
*
|
|
84
|
+
* @param props - The number, its unit and size.
|
|
85
|
+
* @returns The figure.
|
|
86
|
+
*/
|
|
87
|
+
function Figure(props) {
|
|
88
|
+
return createElement(hostMember(COMPONENTS_MODULE, "Figure", "1.0"), props);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A state at a glance.
|
|
92
|
+
*
|
|
93
|
+
* @param props - Its tone and meaning.
|
|
94
|
+
* @returns The dot.
|
|
95
|
+
*/
|
|
96
|
+
function StatusDot(props) {
|
|
97
|
+
return createElement(hostMember(COMPONENTS_MODULE, "StatusDot", "1.0"), props);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* How far something has come.
|
|
101
|
+
*
|
|
102
|
+
* @param props - The percentage and what it is.
|
|
103
|
+
* @returns The bar.
|
|
104
|
+
*/
|
|
105
|
+
function ProgressBar(props) {
|
|
106
|
+
return createElement(hostMember(COMPONENTS_MODULE, "ProgressBar", "1.0"), props);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* An explanation behind a small `i`.
|
|
110
|
+
*
|
|
111
|
+
* @param props - The explanation.
|
|
112
|
+
* @returns The hint.
|
|
113
|
+
*/
|
|
114
|
+
function Hint(props) {
|
|
115
|
+
return createElement(hostMember(COMPONENTS_MODULE, "Hint", "1.0"), props);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A labelled text input.
|
|
119
|
+
*
|
|
120
|
+
* @param props - An input's attributes, its label and what it says under it.
|
|
121
|
+
* @returns The field.
|
|
122
|
+
*/
|
|
123
|
+
function TextField(props) {
|
|
124
|
+
return createElement(hostMember(COMPONENTS_MODULE, "TextField", "1.0"), props);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A labelled choice from a list.
|
|
128
|
+
*
|
|
129
|
+
* @param props - Its label, options and value.
|
|
130
|
+
* @returns The field.
|
|
131
|
+
*/
|
|
132
|
+
function SelectField(props) {
|
|
133
|
+
return createElement(hostMember(COMPONENTS_MODULE, "SelectField", "1.0"), props);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* On or off.
|
|
137
|
+
*
|
|
138
|
+
* @param props - Its label and state.
|
|
139
|
+
* @returns The switch.
|
|
140
|
+
*/
|
|
141
|
+
function Switch(props) {
|
|
142
|
+
return createElement(hostMember(COMPONENTS_MODULE, "Switch", "1.0"), props);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* One of a few, side by side.
|
|
146
|
+
*
|
|
147
|
+
* @param props - Its label, options and value.
|
|
148
|
+
* @returns The control.
|
|
149
|
+
*/
|
|
150
|
+
function Segmented(props) {
|
|
151
|
+
return createElement(hostMember(COMPONENTS_MODULE, "Segmented", "1.0"), {
|
|
152
|
+
...props,
|
|
153
|
+
/**
|
|
154
|
+
* Hands the choice on, as the value it is.
|
|
155
|
+
*
|
|
156
|
+
* @param value - The choice.
|
|
157
|
+
*/
|
|
158
|
+
onChange: (value) => {
|
|
159
|
+
const chosen = props.options.find((option) => option.value === value);
|
|
160
|
+
if (chosen !== void 0) props.onChange(chosen.value);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* A value in a range.
|
|
166
|
+
*
|
|
167
|
+
* @param props - Its label, range, value and how it is written.
|
|
168
|
+
* @returns The slider.
|
|
169
|
+
*/
|
|
170
|
+
function Slider(props) {
|
|
171
|
+
return createElement(hostMember(COMPONENTS_MODULE, "Slider", "1.0"), props);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* A value by steps.
|
|
175
|
+
*
|
|
176
|
+
* @param props - Its label, range, step and how it is written.
|
|
177
|
+
* @returns The stepper.
|
|
178
|
+
*/
|
|
179
|
+
function Stepper(props) {
|
|
180
|
+
return createElement(hostMember(COMPONENTS_MODULE, "Stepper", "1.0"), props);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* A coloured tag.
|
|
184
|
+
*
|
|
185
|
+
* @param props - Its colour and text.
|
|
186
|
+
* @returns The tag.
|
|
187
|
+
*/
|
|
188
|
+
function TagChip(props) {
|
|
189
|
+
return createElement(hostMember(COMPONENTS_MODULE, "TagChip", "1.0"), props);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* A dialog, drawn inside the package's scope.
|
|
193
|
+
*
|
|
194
|
+
* @param props - Whether it is open, its title, content and buttons.
|
|
195
|
+
* @returns The dialog.
|
|
196
|
+
*/
|
|
197
|
+
function Modal(props) {
|
|
198
|
+
return createElement(hostMember(COMPONENTS_MODULE, "Modal", "1.0"), props);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Joins class names, resolving Tailwind conflicts: the later class wins.
|
|
202
|
+
*
|
|
203
|
+
* @param classes - Classes, conditions, lists of them.
|
|
204
|
+
* @returns The class names.
|
|
205
|
+
*/
|
|
206
|
+
function cn(...classes) {
|
|
207
|
+
return hostMember(COMPONENTS_MODULE, "cn", "1.0")(...classes);
|
|
208
|
+
}
|
|
209
|
+
//#endregion
|
|
210
|
+
export { Badge, Button, CardHeading, Figure, Hint, Icon, IconButton, Modal, Panel, PanelNote, PanelRow, ProgressBar, Segmented, SelectField, Slider, StatusDot, Stepper, Switch, TagChip, TextField, cn };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { $ as PlaybackState, A as SecretOptions, B as field, C as ListField, D as NumberOptions, E as NumberField, F as TextOptions, G as CapabilityState, H as CapabilityCommands, I as TimestampField, J as CustomValue, K as CapabilityStates, L as TimestampOptions, M as ShownWhen, N as Simplify, O as OptionField, P as TextField, Q as LawnMowerActivity, R as ValueField, S as FormValues, T as NoFields, U as CapabilityName, V as CapabilityCommand, W as CapabilityParams, X as EntityStateClass, Y as DeclaredCapabilities, Z as ImageContentType, _ as ChoiceOption, a as SettingsOf, at as VacuumActivity, b as Field, c as CommandDeclaration, ct as EntityDomain, d as EntityTypeDefinition, dt as isEntityId, et as ReportedCapabilityState, f as ValuesOf, ft as parseEntityId, g as ChoiceField, h as BooleanOptions, i as SettingsDefinition, it as ThermostatMode, j as SettingField, k as SecretField, l as CommandDeclarations, lt as EntityId, m as BooleanField, n as JsonPrimitive, nt as SelectOption, o as defineSettings, ot as VacuumRoom, p as defineEntityType, q as CommandableCapability, r as JsonValue, rt as ThermostatAction, s as ArgsOf, st as ENTITY_DOMAINS, t as JsonObject, tt as ReportedStates, u as CommandsOf, ut as ParsedEntityId, v as ChoiceOptions, w as ListOptions, x as Fields, y as EntityValues, z as ValueOfField } from "./chunks/json.js";
|
|
2
|
+
import { a as PageProps, c as CardSize, d as defineCard, i as PackageComponent, l as OptionsOf, n as EntityViewProps, o as CardDefinition, r as Loader, s as CardPadding, t as CardProps, u as SizeOf } from "./chunks/props.js";
|
|
3
|
+
//#region src/definitions/containers.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* `defineContainer` and `defineCompose`: what a package runs beside or instead of its process
|
|
6
|
+
* (PACKAGES_DOCS.md 4.7, 4.8). The supervisor runs them on the platform's network, keeps them up,
|
|
7
|
+
* and removes them with the package.
|
|
8
|
+
*/
|
|
9
|
+
/** A value one of the package's settings gives: `{setup.webPort}`. */
|
|
10
|
+
type SettingPlaceholder = `{setup.${string}}`;
|
|
11
|
+
/** An entry kept only while one of the settings holds one of the values. */
|
|
12
|
+
type When = {
|
|
13
|
+
readonly key: string;
|
|
14
|
+
readonly equals: readonly (string | boolean)[];
|
|
15
|
+
};
|
|
16
|
+
/** A port: a number, or one of the settings. */
|
|
17
|
+
type ContainerPort = number | SettingPlaceholder;
|
|
18
|
+
/** How far a container must have come before one that depends on it starts. */
|
|
19
|
+
type ContainerCondition = 'started' | 'healthy';
|
|
20
|
+
/** A container, as declared. */
|
|
21
|
+
type ContainerDefinition<TId extends string = string> = {
|
|
22
|
+
readonly kind: 'container';
|
|
23
|
+
/** Names the container and its folder: `^[a-z][a-z0-9-]{1,31}$`. */
|
|
24
|
+
readonly id: TId;
|
|
25
|
+
readonly name: string;
|
|
26
|
+
/** The image, without a tag: `koenkk/zigbee2mqtt`, `ghcr.io/owner/app`. */
|
|
27
|
+
readonly image: string;
|
|
28
|
+
/** The oldest release it works with: the newest of that major is installed. */
|
|
29
|
+
readonly minVersion: string;
|
|
30
|
+
/** Paths inside the container; where they live is the platform's, in its data directory. */
|
|
31
|
+
readonly volumes?: readonly {
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly path: string;
|
|
34
|
+
/** Left out of backups: what can be made again. */
|
|
35
|
+
readonly isCache?: boolean;
|
|
36
|
+
}[];
|
|
37
|
+
/** Its environment; `{setup.x}` and `{platform.…}` are filled in. */
|
|
38
|
+
readonly env?: Readonly<Record<string, string | {
|
|
39
|
+
readonly value: string;
|
|
40
|
+
readonly when: When;
|
|
41
|
+
}>>;
|
|
42
|
+
/** Devices of the host it is given, under `/dev`. */
|
|
43
|
+
readonly devices?: readonly {
|
|
44
|
+
readonly host: string;
|
|
45
|
+
readonly container: string;
|
|
46
|
+
readonly when?: When;
|
|
47
|
+
}[];
|
|
48
|
+
/** Ports published when the platform is on a bridge network. */
|
|
49
|
+
readonly ports?: readonly {
|
|
50
|
+
readonly container: ContainerPort;
|
|
51
|
+
readonly host: ContainerPort;
|
|
52
|
+
readonly protocol?: 'tcp' | 'udp';
|
|
53
|
+
readonly when?: When;
|
|
54
|
+
}[];
|
|
55
|
+
/** Files written into a volume once, when missing. */
|
|
56
|
+
readonly seed?: readonly {
|
|
57
|
+
readonly volume: string;
|
|
58
|
+
readonly path: string;
|
|
59
|
+
readonly content: string;
|
|
60
|
+
}[];
|
|
61
|
+
/** The topics it uses on the house's broker, which a username of its own is held to. */
|
|
62
|
+
readonly mqttTopics?: readonly string[];
|
|
63
|
+
/** The port of its own web page, which the interface links to. */
|
|
64
|
+
readonly webPort?: ContainerPort;
|
|
65
|
+
readonly webPortWhen?: When;
|
|
66
|
+
/** The command, instead of the image's: each argument on its own. */
|
|
67
|
+
readonly command?: readonly string[];
|
|
68
|
+
/** How the platform knows it is ready: `test` is `CMD …` or `CMD-SHELL …`. */
|
|
69
|
+
readonly healthcheck?: {
|
|
70
|
+
readonly test: readonly string[];
|
|
71
|
+
readonly intervalMs?: number;
|
|
72
|
+
readonly timeoutMs?: number;
|
|
73
|
+
readonly retries?: number;
|
|
74
|
+
readonly startPeriodMs?: number;
|
|
75
|
+
};
|
|
76
|
+
/** Containers of the same package it starts after, and how far each must have come. */
|
|
77
|
+
readonly dependsOn?: Readonly<Record<string, ContainerCondition>>;
|
|
78
|
+
};
|
|
79
|
+
/** A compose file, as declared. */
|
|
80
|
+
type ComposeDefinition = {
|
|
81
|
+
readonly kind: 'compose';
|
|
82
|
+
/** The file, next to the config: `./compose.yaml`. */
|
|
83
|
+
readonly file: string;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Declares a container the package runs.
|
|
87
|
+
*
|
|
88
|
+
* @param container - Its image, release, volumes, environment and the rest.
|
|
89
|
+
* @returns The container, for `definePackage`'s `containers`.
|
|
90
|
+
*/
|
|
91
|
+
export declare function defineContainer<const TId extends string>(container: Omit<ContainerDefinition<TId>, 'kind'>): ContainerDefinition<TId>;
|
|
92
|
+
/**
|
|
93
|
+
* Declares a compose file the package runs instead of declared containers.
|
|
94
|
+
*
|
|
95
|
+
* @param compose - Where the file is.
|
|
96
|
+
* @returns The compose file, for `definePackage`'s `compose`.
|
|
97
|
+
*/
|
|
98
|
+
export declare function defineCompose(compose: Omit<ComposeDefinition, 'kind'>): ComposeDefinition;
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/definitions/bound-props.d.ts
|
|
101
|
+
/** The props of the component of the card with this id. */
|
|
102
|
+
type CardPropsFor<TCards extends readonly CardDefinition[], TId extends string> = CardProps<Extract<TCards[number], {
|
|
103
|
+
readonly id: TId;
|
|
104
|
+
}>>;
|
|
105
|
+
/** The props of the view of the entity type with this id. */
|
|
106
|
+
type EntityViewPropsFor<TTypes extends readonly EntityTypeDefinition[], TId extends string> = EntityViewProps<Extract<TTypes[number], {
|
|
107
|
+
readonly id: TId;
|
|
108
|
+
}>>;
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/definitions/page.d.ts
|
|
111
|
+
/** An entry of the page in the interface's sidebar. */
|
|
112
|
+
type SidebarEntry = {
|
|
113
|
+
/** What it says; the package's name when not given. At most 32 characters. */
|
|
114
|
+
readonly label?: string;
|
|
115
|
+
/** A catalogue icon id; the package's logo when not given. */
|
|
116
|
+
readonly icon?: string;
|
|
117
|
+
};
|
|
118
|
+
/** The package's page, as declared. */
|
|
119
|
+
type PageDefinition = {
|
|
120
|
+
readonly kind: 'page';
|
|
121
|
+
readonly component: Loader<PageProps>;
|
|
122
|
+
readonly sidebar?: SidebarEntry;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Declares the package's page. A package has at most one: `ui.page` is a single field.
|
|
126
|
+
*
|
|
127
|
+
* @param page - Its component's loader, and its sidebar entry if any.
|
|
128
|
+
* @returns The page, for `definePackage`'s `ui.page`.
|
|
129
|
+
*/
|
|
130
|
+
export declare function definePage(page: Omit<PageDefinition, 'kind'>): PageDefinition;
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/definitions/package.d.ts
|
|
133
|
+
/** What the store files a package under. */
|
|
134
|
+
type PackageCategory = 'protocol' | 'media' | 'security' | 'energy' | 'climate' | 'visualisation' | 'automation' | 'other';
|
|
135
|
+
/** What a package needs besides itself. */
|
|
136
|
+
type PackageRequires = {
|
|
137
|
+
/** The platform, by npm range. */
|
|
138
|
+
readonly platform?: string;
|
|
139
|
+
/** Packages, by id and range. */
|
|
140
|
+
readonly packages?: Readonly<Record<string, string>>;
|
|
141
|
+
/** Services, by name, whoever provides them. */
|
|
142
|
+
readonly services?: readonly string[];
|
|
143
|
+
};
|
|
144
|
+
/** The components a package draws, bound to what it declares. */
|
|
145
|
+
type PackageUi<TCards extends readonly CardDefinition[], TTypes extends readonly EntityTypeDefinition[]> = {
|
|
146
|
+
/** Its own page. */
|
|
147
|
+
readonly page?: PageDefinition;
|
|
148
|
+
/** A component for every declared card, by its id. */
|
|
149
|
+
readonly cards?: { readonly [TId in TCards[number]['id']]: Loader<CardPropsFor<TCards, TId>>; };
|
|
150
|
+
/** Views of the entity types it draws itself, by their ids. */
|
|
151
|
+
readonly entityViews?: { readonly [TId in TTypes[number]['id']]?: Loader<EntityViewPropsFor<TTypes, TId>>; };
|
|
152
|
+
};
|
|
153
|
+
/** What every package says, whatever it runs. */
|
|
154
|
+
type PackageBase<TCards extends readonly CardDefinition[], TTypes extends readonly EntityTypeDefinition[]> = {
|
|
155
|
+
/** `^[a-z][a-z0-9-]{1,63}$`, not one of the platform's names. */
|
|
156
|
+
readonly id: string;
|
|
157
|
+
readonly name: string;
|
|
158
|
+
readonly description: string;
|
|
159
|
+
readonly category: PackageCategory;
|
|
160
|
+
/** The NebulaHome versions it works with, as an npm range: `^1.4.0`. */
|
|
161
|
+
readonly platform: string;
|
|
162
|
+
/** Its colour in the store, `#RRGGBB`. */
|
|
163
|
+
readonly color?: `#${string}`;
|
|
164
|
+
/** A file next to the config: `./logo.svg`. */
|
|
165
|
+
readonly logo?: string | {
|
|
166
|
+
readonly path: string;
|
|
167
|
+
readonly padding?: number;
|
|
168
|
+
};
|
|
169
|
+
readonly url?: string;
|
|
170
|
+
/** `owner/name` on GitHub; read from `package.json` when not given. */
|
|
171
|
+
readonly repository?: string;
|
|
172
|
+
/** The server's entry module, next to the config: `./src/server/index.ts`. */
|
|
173
|
+
readonly server?: string;
|
|
174
|
+
readonly settings?: SettingsDefinition;
|
|
175
|
+
readonly cards?: TCards;
|
|
176
|
+
readonly entityTypes?: TTypes;
|
|
177
|
+
readonly requires?: PackageRequires;
|
|
178
|
+
readonly provides?: readonly string[];
|
|
179
|
+
readonly ui?: PackageUi<TCards, TTypes>;
|
|
180
|
+
};
|
|
181
|
+
/** What `definePackage` takes: declared containers, or a compose file, or neither. */
|
|
182
|
+
type PackageConfig<TCards extends readonly CardDefinition[] = readonly CardDefinition[], TTypes extends readonly EntityTypeDefinition[] = readonly EntityTypeDefinition[]> = PackageBase<TCards, TTypes> & ({
|
|
183
|
+
readonly containers?: readonly ContainerDefinition[];
|
|
184
|
+
readonly compose?: never;
|
|
185
|
+
} | {
|
|
186
|
+
readonly compose: ComposeDefinition;
|
|
187
|
+
readonly containers?: never;
|
|
188
|
+
});
|
|
189
|
+
/** A package, as declared. */
|
|
190
|
+
type PackageDefinition<TCards extends readonly CardDefinition[] = readonly CardDefinition[], TTypes extends readonly EntityTypeDefinition[] = readonly EntityTypeDefinition[]> = PackageConfig<TCards, TTypes> & {
|
|
191
|
+
readonly kind: 'package';
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* Declares the package: `nebula.config.ts`'s default export.
|
|
195
|
+
*
|
|
196
|
+
* @param config - What it is, what it declares, and the components it draws.
|
|
197
|
+
* @returns The package, which the build writes the manifest from.
|
|
198
|
+
*/
|
|
199
|
+
export declare function definePackage<const TCards extends readonly CardDefinition[] = readonly [], const TTypes extends readonly EntityTypeDefinition[] = readonly []>(config: PackageConfig<TCards, TTypes>): PackageDefinition<TCards, TTypes>;
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/version.d.ts
|
|
202
|
+
/** The SDK's own version, `1.0.0`. */
|
|
203
|
+
export declare const SDK_VERSION: string;
|
|
204
|
+
//#endregion
|
|
205
|
+
export { type ArgsOf, type BooleanField, type BooleanOptions, type CapabilityCommand, type CapabilityCommands, type CapabilityName, type CapabilityParams, type CapabilityState, type CapabilityStates, type CardDefinition, type CardPadding, type CardProps, type CardSize, type ChoiceField, type ChoiceOption, type ChoiceOptions, type CommandDeclaration, type CommandDeclarations, type CommandableCapability, type CommandsOf, type ComposeDefinition, type ContainerCondition, type ContainerDefinition, type ContainerPort, type CustomValue, type DeclaredCapabilities, ENTITY_DOMAINS, type EntityDomain, type EntityId, type EntityStateClass, type EntityTypeDefinition, type EntityValues, type EntityViewProps, type Field, type Fields, type FormValues, type ImageContentType, type JsonObject, type JsonPrimitive, type JsonValue, type LawnMowerActivity, type ListField, type ListOptions, type Loader, type NoFields, type NumberField, type NumberOptions, type OptionField, type OptionsOf, type PackageCategory, type PackageComponent, type PackageConfig, type PackageDefinition, type PackageRequires, type PackageUi, type PageDefinition, type PageProps, type ParsedEntityId, type PlaybackState, type ReportedCapabilityState, type ReportedStates, type SecretField, type SecretOptions, type SelectOption, type SettingField, type SettingPlaceholder, type SettingsDefinition, type SettingsOf, type ShownWhen, type SidebarEntry, type Simplify, type SizeOf, type TextField, type TextOptions, type ThermostatAction, type ThermostatMode, type TimestampField, type TimestampOptions, type VacuumActivity, type VacuumRoom, type ValueField, type ValueOfField, type ValuesOf, type When, defineCard, defineEntityType, defineSettings, field, isEntityId, parseEntityId };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { t as SDK_VERSION } from "./chunks/version.js";
|
|
2
|
+
//#region src/definitions/card.ts
|
|
3
|
+
/**
|
|
4
|
+
* Declares a card.
|
|
5
|
+
*
|
|
6
|
+
* @param card - Its id, name, icon, sizes and options.
|
|
7
|
+
* @returns The card, for `definePackage`'s `cards` and for its component's props.
|
|
8
|
+
*/
|
|
9
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
10
|
+
function defineCard(card) {
|
|
11
|
+
return {
|
|
12
|
+
...card,
|
|
13
|
+
kind: "card"
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/definitions/containers.ts
|
|
18
|
+
/**
|
|
19
|
+
* Declares a container the package runs.
|
|
20
|
+
*
|
|
21
|
+
* @param container - Its image, release, volumes, environment and the rest.
|
|
22
|
+
* @returns The container, for `definePackage`'s `containers`.
|
|
23
|
+
*/
|
|
24
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
25
|
+
function defineContainer(container) {
|
|
26
|
+
return {
|
|
27
|
+
...container,
|
|
28
|
+
kind: "container"
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Declares a compose file the package runs instead of declared containers.
|
|
33
|
+
*
|
|
34
|
+
* @param compose - Where the file is.
|
|
35
|
+
* @returns The compose file, for `definePackage`'s `compose`.
|
|
36
|
+
*/
|
|
37
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
38
|
+
function defineCompose(compose) {
|
|
39
|
+
return {
|
|
40
|
+
...compose,
|
|
41
|
+
kind: "compose"
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/definitions/entity-type.ts
|
|
46
|
+
/**
|
|
47
|
+
* Declares an entity type.
|
|
48
|
+
*
|
|
49
|
+
* @param type - Its id, name, icon, state and commands.
|
|
50
|
+
* @returns The type, for `definePackage`'s `entityTypes`, the server's `ctx.custom` and its view.
|
|
51
|
+
*/
|
|
52
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
53
|
+
function defineEntityType(type) {
|
|
54
|
+
return {
|
|
55
|
+
...type,
|
|
56
|
+
kind: "entityType"
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/definitions/package.ts
|
|
61
|
+
/**
|
|
62
|
+
* Declares the package: `nebula.config.ts`'s default export.
|
|
63
|
+
*
|
|
64
|
+
* @param config - What it is, what it declares, and the components it draws.
|
|
65
|
+
* @returns The package, which the build writes the manifest from.
|
|
66
|
+
*/
|
|
67
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
68
|
+
function definePackage(config) {
|
|
69
|
+
return {
|
|
70
|
+
...config,
|
|
71
|
+
kind: "package"
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/definitions/page.ts
|
|
76
|
+
/**
|
|
77
|
+
* Declares the package's page. A package has at most one: `ui.page` is a single field.
|
|
78
|
+
*
|
|
79
|
+
* @param page - Its component's loader, and its sidebar entry if any.
|
|
80
|
+
* @returns The page, for `definePackage`'s `ui.page`.
|
|
81
|
+
*/
|
|
82
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
83
|
+
function definePage(page) {
|
|
84
|
+
return {
|
|
85
|
+
...page,
|
|
86
|
+
kind: "page"
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/definitions/settings.ts
|
|
91
|
+
/**
|
|
92
|
+
* Declares a package's settings, at most 32 fields, by their keys.
|
|
93
|
+
*
|
|
94
|
+
* @param fields - The fields, built with `field`.
|
|
95
|
+
* @returns The settings, for `definePackage` and for the types of `ctx.settings`.
|
|
96
|
+
*/
|
|
97
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
98
|
+
function defineSettings(fields) {
|
|
99
|
+
return {
|
|
100
|
+
kind: "settings",
|
|
101
|
+
fields
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/entities.ts
|
|
106
|
+
/**
|
|
107
|
+
* Entity identifiers: `<domain>.<object id>`, as the platform writes them everywhere - in its
|
|
108
|
+
* API, on its bus, in automations. A package never composes one by hand: the server's
|
|
109
|
+
* `ctx.entityId` does, and these read one back.
|
|
110
|
+
*/
|
|
111
|
+
/** The kinds of thing an entity is. */
|
|
112
|
+
const ENTITY_DOMAINS = [
|
|
113
|
+
"light",
|
|
114
|
+
"switch",
|
|
115
|
+
"sensor",
|
|
116
|
+
"binary_sensor",
|
|
117
|
+
"cover",
|
|
118
|
+
"lock",
|
|
119
|
+
"climate",
|
|
120
|
+
"media_player",
|
|
121
|
+
"camera",
|
|
122
|
+
"button",
|
|
123
|
+
"update",
|
|
124
|
+
"lawn_mower",
|
|
125
|
+
"select",
|
|
126
|
+
"number",
|
|
127
|
+
"vacuum",
|
|
128
|
+
"image",
|
|
129
|
+
"custom",
|
|
130
|
+
"alias"
|
|
131
|
+
];
|
|
132
|
+
/** The shape of an entity identifier: a domain, a dot, an object id. */
|
|
133
|
+
const ENTITY_ID_PATTERN = /^([a-z][a-z0-9_]{0,31})\.([a-z][a-z0-9_]{0,63})$/;
|
|
134
|
+
/**
|
|
135
|
+
* Says whether a word is one of the platform's domains.
|
|
136
|
+
*
|
|
137
|
+
* @param value - The word.
|
|
138
|
+
* @returns True when it is.
|
|
139
|
+
*/
|
|
140
|
+
function isDomain(value) {
|
|
141
|
+
return ENTITY_DOMAINS.some((domain) => domain === value);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Reads an entity identifier.
|
|
145
|
+
*
|
|
146
|
+
* @param entityId - The identifier.
|
|
147
|
+
* @returns Its domain and object id, or undefined when it is not one.
|
|
148
|
+
*/
|
|
149
|
+
function parseEntityId(entityId) {
|
|
150
|
+
const match = ENTITY_ID_PATTERN.exec(entityId);
|
|
151
|
+
const domain = match?.[1];
|
|
152
|
+
const objectId = match?.[2];
|
|
153
|
+
return domain === void 0 || objectId === void 0 || !isDomain(domain) ? void 0 : {
|
|
154
|
+
domain,
|
|
155
|
+
objectId
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Says whether a value is an entity identifier.
|
|
160
|
+
*
|
|
161
|
+
* @param value - The value.
|
|
162
|
+
* @returns True when it is a string the platform would take as one.
|
|
163
|
+
*/
|
|
164
|
+
function isEntityId(value) {
|
|
165
|
+
return typeof value === "string" && parseEntityId(value) !== void 0;
|
|
166
|
+
}
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/fields.ts
|
|
169
|
+
/** The field builders. */
|
|
170
|
+
const field = {
|
|
171
|
+
/**
|
|
172
|
+
* A text: free, or held to a length and a pattern.
|
|
173
|
+
*
|
|
174
|
+
* @param options - Its label and limits.
|
|
175
|
+
* @returns The field.
|
|
176
|
+
*/
|
|
177
|
+
text: (options) => ({
|
|
178
|
+
...options,
|
|
179
|
+
kind: "text"
|
|
180
|
+
}),
|
|
181
|
+
/**
|
|
182
|
+
* A secret: stored sealed, handed to the process open, never sent to a browser.
|
|
183
|
+
*
|
|
184
|
+
* @param options - Its label and limits.
|
|
185
|
+
* @returns The field.
|
|
186
|
+
*/
|
|
187
|
+
secret: (options) => ({
|
|
188
|
+
...options,
|
|
189
|
+
kind: "secret"
|
|
190
|
+
}),
|
|
191
|
+
/**
|
|
192
|
+
* A number, optionally whole and within a range.
|
|
193
|
+
*
|
|
194
|
+
* @param options - Its label, range and unit.
|
|
195
|
+
* @returns The field.
|
|
196
|
+
*/
|
|
197
|
+
number: (options) => ({
|
|
198
|
+
...options,
|
|
199
|
+
kind: "number"
|
|
200
|
+
}),
|
|
201
|
+
/**
|
|
202
|
+
* On or off.
|
|
203
|
+
*
|
|
204
|
+
* @param options - Its label.
|
|
205
|
+
* @returns The field.
|
|
206
|
+
*/
|
|
207
|
+
boolean: (options) => ({
|
|
208
|
+
...options,
|
|
209
|
+
kind: "boolean"
|
|
210
|
+
}),
|
|
211
|
+
/**
|
|
212
|
+
* One of a fixed list.
|
|
213
|
+
*
|
|
214
|
+
* @param options - Its label and its choices, 1 to 64.
|
|
215
|
+
* @returns The field.
|
|
216
|
+
*/
|
|
217
|
+
choice: (options) => ({
|
|
218
|
+
...options,
|
|
219
|
+
kind: "choice"
|
|
220
|
+
}),
|
|
221
|
+
/**
|
|
222
|
+
* Several texts - addresses, topics - each held to the same pattern.
|
|
223
|
+
*
|
|
224
|
+
* @param options - Its label and limits.
|
|
225
|
+
* @returns The field.
|
|
226
|
+
*/
|
|
227
|
+
list: (options) => ({
|
|
228
|
+
...options,
|
|
229
|
+
kind: "list"
|
|
230
|
+
}),
|
|
231
|
+
/**
|
|
232
|
+
* An instant, as ISO 8601 text: an entity's state or a command's argument, never a form's.
|
|
233
|
+
*
|
|
234
|
+
* @param options - Its label.
|
|
235
|
+
* @returns The field.
|
|
236
|
+
*/
|
|
237
|
+
timestamp: (options) => ({
|
|
238
|
+
...options,
|
|
239
|
+
kind: "timestamp"
|
|
240
|
+
})
|
|
241
|
+
};
|
|
242
|
+
//#endregion
|
|
243
|
+
export { ENTITY_DOMAINS, SDK_VERSION, defineCard, defineCompose, defineContainer, defineEntityType, definePackage, definePage, defineSettings, field, isEntityId, parseEntityId };
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { i as SettingsDefinition } from "./chunks/json.js";
|
|
2
|
+
import { A as StandardSchemaV1, C as StateChange, D as Schema, E as SafeParser, O as SchemaIssue, S as SettingsChange, T as Unsubscribe, _ as ServerContext, a as CustomEntityInput, b as ServiceCallFunction, c as EntityInput, d as Logger, f as ReportOptions, g as RpcMethod, h as RpcCaller, i as CustomEntities, k as StandardResult, l as EntitySnapshot, m as RpcCall, n as CapabilityEntityInput, o as DeviceInput, p as RpcAccess, r as CustomCommand, s as EntityFilter, t as Awaitable, u as LogMethod, v as ServerSettings, w as SyncResult, x as ServiceProvide, y as ServiceCall } from "./chunks/context.js";
|
|
3
|
+
//#region src/server/index.d.ts
|
|
4
|
+
/** What stops what `start` opened. */
|
|
5
|
+
export type Stop = () => Awaitable<void>;
|
|
6
|
+
/** What a server is: what it starts with, and the settings it reads. */
|
|
7
|
+
export type ServerDefinition<TSettings extends SettingsDefinition | undefined = undefined> = {
|
|
8
|
+
/** Says to the runner what this is. */
|
|
9
|
+
readonly kind: 'nebula.server';
|
|
10
|
+
/** The SDK version it was built with: the runner refuses a newer major than its own. */
|
|
11
|
+
readonly sdk: string;
|
|
12
|
+
/** The package's settings, for the types of `ctx.settings`. */
|
|
13
|
+
readonly settings?: TSettings;
|
|
14
|
+
/**
|
|
15
|
+
* Starts the package: registers its devices, methods and services, and opens what it runs.
|
|
16
|
+
*
|
|
17
|
+
* @param ctx - What the platform hands it.
|
|
18
|
+
* @returns What stops it, when there is anything to stop.
|
|
19
|
+
*/
|
|
20
|
+
readonly start: (ctx: ServerContext<TSettings>) => Awaitable<Stop | undefined>;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Declares a package's server: the default export of its entry module.
|
|
24
|
+
*
|
|
25
|
+
* @param server - Its settings, if it reads them, and its `start`.
|
|
26
|
+
* @returns The server, stamped with the SDK version it was built with.
|
|
27
|
+
*/
|
|
28
|
+
export declare function defineServer<TSettings extends SettingsDefinition | undefined = undefined>(server: Omit<ServerDefinition<TSettings>, 'kind' | 'sdk'>): ServerDefinition<TSettings>;
|
|
29
|
+
//#endregion
|
|
30
|
+
export type { Awaitable, CapabilityEntityInput, CustomCommand, CustomEntities, CustomEntityInput, DeviceInput, EntityFilter, EntityInput, EntitySnapshot, LogMethod, Logger, ReportOptions, RpcAccess, RpcCall, RpcCaller, RpcMethod, SafeParser, Schema, SchemaIssue, ServerContext, ServerSettings, ServiceCall, ServiceCallFunction, ServiceProvide, SettingsChange, StandardResult, StandardSchemaV1, StateChange, SyncResult, Unsubscribe };
|