@protobase/schema 0.12.10 → 0.12.11
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/dist/index.d.ts +2 -2
- package/dist/model.d.ts +12 -1
- package/dist/view-displays.d.ts +5 -3
- package/dist/view-displays.js +7 -4
- package/dist/view-field.d.ts +9 -1
- package/dist/view-field.js +23 -0
- package/dist/view.js +2 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionModel, ActionRun, AppAddress, BottomBarItemModel, BottomBarModel, ChartGranularity, ChartModel, ChartRange, CheckedFilter, CompareOp, CustomSectionModel, DatePreset, DurationLiteral, DurationUnit, EventModel, EventOperation, FieldFormat, FieldModel, FieldPath, FieldType, FieldViewModel, FieldWidgetModel, FileFieldModel, FilterError, FilterErrorCode, FilterExpr, FilterLayout, FilterOf, FilterValue, FilterWidgetModel, JsonValue, KeyValue, LayoutItemModel, ListDisplayModel, ListModel, ListQuery, Literal, NavModel, NavRecentModel, NowValue, OrderByItem, RelatedModel, ResourceModel, SaveFeedback, SearchMatch, SearchResultModel, SortSpec, Span, StatusTone, UserMenuItemModel, UserMenuModel, ViewModel } from "./model.js";
|
|
1
|
+
import { ActionModel, ActionRun, AppAddress, BadgeShape, BottomBarItemModel, BottomBarModel, ChartGranularity, ChartModel, ChartRange, CheckedFilter, CompareOp, CustomSectionModel, DatePreset, DurationLiteral, DurationUnit, EventModel, EventOperation, FieldFormat, FieldModel, FieldPath, FieldType, FieldViewModel, FieldWidgetModel, FileFieldModel, FilterError, FilterErrorCode, FilterExpr, FilterLayout, FilterOf, FilterValue, FilterWidgetModel, JsonValue, KeyValue, LayoutItemModel, ListDisplayModel, ListModel, ListQuery, Literal, NavModel, NavRecentModel, NowValue, OrderByItem, RelatedModel, ResourceModel, SaveFeedback, SearchMatch, SearchResultModel, SortSpec, Span, StatusTone, UserMenuItemModel, UserMenuModel, ViewModel } from "./model.js";
|
|
2
2
|
import { AccessAction, AccessContext, AccessFn, AccessResult, AccessUser, FieldAccess, FieldRule } from "./access/types.js";
|
|
3
3
|
import { FileProcessor, FileProcessorInput, checkedAccept, checkedProvider, parseSize } from "./files/file-options.js";
|
|
4
4
|
import { Field } from "./field.js";
|
|
@@ -44,4 +44,4 @@ import "./access/index.js";
|
|
|
44
44
|
import { AssistantAction, AssistantActionRequest, AssistantCardPart, AssistantDiff, AssistantEvent, AssistantMessage, AssistantMessageRequest, AssistantPart, AssistantState, AssistantStep, AssistantStepState, AssistantTablePart, AssistantTextPart, AssistantTone, AssistantWidgetPart } from "./assistant/protocol.js";
|
|
45
45
|
import { applyAssistantEvent, emptyAssistantState } from "./assistant/apply-event.js";
|
|
46
46
|
import { readEventStream } from "./assistant/event-stream.js";
|
|
47
|
-
export { type AccessAction, type AccessContext, type AccessFn, type AccessResult, type AccessSource, type AccessUser, type ActionModel, type ActionRun, type AddressCheck, type AppAddress, type AssistantAction, type AssistantActionRequest, type AssistantCardPart, type AssistantDiff, type AssistantEvent, type AssistantMessage, type AssistantMessageRequest, type AssistantPart, type AssistantState, type AssistantStep, type AssistantStepState, type AssistantTablePart, type AssistantTextPart, type AssistantTone, type AssistantWidgetPart, type BottomBarItemModel, type BottomBarModel, type BottomBarNames, type BottomBarSource, type Capability, type CapabilityAction, type CapabilityLimit, type CapabilityScope, type ChartGranularity, type ChartModel, type ChartRange, type CheckResult, type CheckedFilter, type CompareOp, type ComponentRef, type CustomSectionModel, type DatePreset, type DurationLiteral, type DurationUnit, type EvaluateOptions, type EventActor, type EventContext, type EventHelpers, type EventMatch, type EventModel, type EventOperation, type EventSpec, type Field, type FieldAccess, type FieldFormat, type FieldModel, type FieldPath, type FieldRefValue, type FieldRule, type FieldType, type FieldViewModel, type FieldWidgetModel, type FileField, type FileFieldModel, type FileProcessor, type FileProcessorInput, type FilterError, type FilterErrorCode, type FilterExpr, type FilterLayout, type FilterLimits, type FilterOf, type FilterParse, type FilterValue, type FilterWidgetModel, type InferRecord, type JsonValue, type KeyType, type KeyValue, type LayoutItemModel, type ListDisplayModel, type ListModel, type ListQuery, type Literal, type NavModel, type NavRecentModel, type NowValue, type OrderByCheck, type OrderByItem, type OrderByParse, type PluginHost, type PluginRequirement, type PropShapes, type RecordKey, type RefShape, type RelatedModel, type ResolveOptions, type ResolvedAccess, type ResourceModel, type RoleEntry, type RoleLimit, type Roles, type RolesOptions, type RowFilterOperation, type Rule, type SaveFeedback, type SearchMatch, type SearchResultModel, type SearchTerm, type SortSpec, type Span, type StatusTone, type UserMenuItemModel, type UserMenuModel, type UserMenuSource, type ViewModel, type ViewProps, accessWarnings, addressErrors, addressPlaceholders, addressWords, anonymousRole, appHrefError, appPath, applyAssistantEvent, bottomBar, bottomBarErrors, bottomBarFor, checkEventFilter, checkFilter, checkOrderBy, checkRecord, checkedAccept, checkedProvider, createWhere, decodeKey, defaultRecentLimit, defineRoles, displayFields, emptyAssistantState, encodeKey, enumLabel, evaluateFilter, f, fieldRef, fieldRefsIn, fieldsUsedBy, fillAddress, hrefPlaceholders, inRange, isFieldRef, keyTypes, layout as l, leavesApp, markFieldRefs, matchedSearchField, matchesSearch, maxBottomBarItems, navRecentErrors, parseFilter, parseOrderBy, parseSize, pickView, pluginProblem, printFilter, printOrderBy, pruneByShape, readAppPath, readEventStream, redactSecrets, resolveAccess, resource, restrictModel, rule, searchTerms, shapes, statusTones, tableDisplay, termMatches, unmarkFieldRefs, userMenu, view, webhookResources, where };
|
|
47
|
+
export { type AccessAction, type AccessContext, type AccessFn, type AccessResult, type AccessSource, type AccessUser, type ActionModel, type ActionRun, type AddressCheck, type AppAddress, type AssistantAction, type AssistantActionRequest, type AssistantCardPart, type AssistantDiff, type AssistantEvent, type AssistantMessage, type AssistantMessageRequest, type AssistantPart, type AssistantState, type AssistantStep, type AssistantStepState, type AssistantTablePart, type AssistantTextPart, type AssistantTone, type AssistantWidgetPart, type BadgeShape, type BottomBarItemModel, type BottomBarModel, type BottomBarNames, type BottomBarSource, type Capability, type CapabilityAction, type CapabilityLimit, type CapabilityScope, type ChartGranularity, type ChartModel, type ChartRange, type CheckResult, type CheckedFilter, type CompareOp, type ComponentRef, type CustomSectionModel, type DatePreset, type DurationLiteral, type DurationUnit, type EvaluateOptions, type EventActor, type EventContext, type EventHelpers, type EventMatch, type EventModel, type EventOperation, type EventSpec, type Field, type FieldAccess, type FieldFormat, type FieldModel, type FieldPath, type FieldRefValue, type FieldRule, type FieldType, type FieldViewModel, type FieldWidgetModel, type FileField, type FileFieldModel, type FileProcessor, type FileProcessorInput, type FilterError, type FilterErrorCode, type FilterExpr, type FilterLayout, type FilterLimits, type FilterOf, type FilterParse, type FilterValue, type FilterWidgetModel, type InferRecord, type JsonValue, type KeyType, type KeyValue, type LayoutItemModel, type ListDisplayModel, type ListModel, type ListQuery, type Literal, type NavModel, type NavRecentModel, type NowValue, type OrderByCheck, type OrderByItem, type OrderByParse, type PluginHost, type PluginRequirement, type PropShapes, type RecordKey, type RefShape, type RelatedModel, type ResolveOptions, type ResolvedAccess, type ResourceModel, type RoleEntry, type RoleLimit, type Roles, type RolesOptions, type RowFilterOperation, type Rule, type SaveFeedback, type SearchMatch, type SearchResultModel, type SearchTerm, type SortSpec, type Span, type StatusTone, type UserMenuItemModel, type UserMenuModel, type UserMenuSource, type ViewModel, type ViewProps, accessWarnings, addressErrors, addressPlaceholders, addressWords, anonymousRole, appHrefError, appPath, applyAssistantEvent, bottomBar, bottomBarErrors, bottomBarFor, checkEventFilter, checkFilter, checkOrderBy, checkRecord, checkedAccept, checkedProvider, createWhere, decodeKey, defaultRecentLimit, defineRoles, displayFields, emptyAssistantState, encodeKey, enumLabel, evaluateFilter, f, fieldRef, fieldRefsIn, fieldsUsedBy, fillAddress, hrefPlaceholders, inRange, isFieldRef, keyTypes, layout as l, leavesApp, markFieldRefs, matchedSearchField, matchesSearch, maxBottomBarItems, navRecentErrors, parseFilter, parseOrderBy, parseSize, pickView, pluginProblem, printFilter, printOrderBy, pruneByShape, readAppPath, readEventStream, redactSecrets, resolveAccess, resource, restrictModel, rule, searchTerms, shapes, statusTones, tableDisplay, termMatches, unmarkFieldRefs, userMenu, view, webhookResources, where };
|
package/dist/model.d.ts
CHANGED
|
@@ -115,15 +115,24 @@ export type FieldViewModel = {
|
|
|
115
115
|
help?: string;
|
|
116
116
|
format?: FieldFormat;
|
|
117
117
|
prefix?: string;
|
|
118
|
+
/** Text after a number wherever it is shown, such as a unit: `m²` shows `120 m²`. */
|
|
119
|
+
suffix?: string;
|
|
118
120
|
decimals?: number;
|
|
121
|
+
/** An icon before the value on a card's meta row, by the names actions take (`ruler`); an unknown name shows none. */
|
|
122
|
+
icon?: string;
|
|
119
123
|
/** What an enum value reads as wherever it is shown; a value without one reads as itself in words (`enumLabel`). */
|
|
120
124
|
valueLabels?: Record<string, string>;
|
|
125
|
+
/** A hex colour per enum value that fills its badge, such as `{ a: '#00a651' }`; a value without one keeps its tone. */
|
|
126
|
+
valueColors?: Record<string, string>;
|
|
127
|
+
/** `arrow` draws the field's badges as arrows pointing right, as on a rating scale such as the EU energy label. */
|
|
128
|
+
badgeShape?: BadgeShape;
|
|
121
129
|
/**
|
|
122
130
|
* The field type a plugin registers (`definePlugin({ fields })`) that shows and edits this field, with its props;
|
|
123
131
|
* without that plugin, or for a storage type it does not show, the field shows as it would without it.
|
|
124
132
|
*/
|
|
125
133
|
widget?: FieldWidgetModel;
|
|
126
134
|
};
|
|
135
|
+
export type BadgeShape = 'arrow';
|
|
127
136
|
/** A field type by the name a plugin registers it under, and the plain data it is given. */
|
|
128
137
|
export type FieldWidgetModel = {
|
|
129
138
|
name: string;
|
|
@@ -131,7 +140,8 @@ export type FieldWidgetModel = {
|
|
|
131
140
|
};
|
|
132
141
|
/**
|
|
133
142
|
* A way to show a list besides its table: a card per record, its content the built-in one or a component's (`card`),
|
|
134
|
-
* or a project component (`custom`) drawing the rows the list page loads.
|
|
143
|
+
* or a project component (`custom`) drawing the rows the list page loads. A card's `flags` are boolean fields shown as
|
|
144
|
+
* small badges of their labels when true. `name` is what the address names (`?display=cards`); `label` and `icon` are its switch's.
|
|
135
145
|
*/
|
|
136
146
|
export type ListDisplayModel = {
|
|
137
147
|
kind: 'cards';
|
|
@@ -143,6 +153,7 @@ export type ListDisplayModel = {
|
|
|
143
153
|
subtitle?: string;
|
|
144
154
|
badge?: string;
|
|
145
155
|
meta?: string[];
|
|
156
|
+
flags?: string[];
|
|
146
157
|
card?: string;
|
|
147
158
|
} | {
|
|
148
159
|
kind: 'custom';
|
package/dist/view-displays.d.ts
CHANGED
|
@@ -19,9 +19,10 @@ export declare const displays: {
|
|
|
19
19
|
/**
|
|
20
20
|
* A card per record: `image`, a file field shown as a picture across the card's top, then `title` (default: the
|
|
21
21
|
* view's title) over `subtitle`, `badge` drawn as a badge with its value labels, and a few small `meta` fields such as
|
|
22
|
-
* dates.
|
|
23
|
-
* card
|
|
24
|
-
* built-in one. Named `cards` unless `name` says
|
|
22
|
+
* dates. `flags` are boolean fields shown as small badges of their labels when true, such as a garden or parking.
|
|
23
|
+
* With `card`, a component of the project or a plugin draws each card's content instead, from the row of those
|
|
24
|
+
* fields (`{ row }`); without it, or when it throws, the card is the built-in one. Named `cards` unless `name` says
|
|
25
|
+
* otherwise.
|
|
25
26
|
*/
|
|
26
27
|
cards: (fields: {
|
|
27
28
|
image?: Ref;
|
|
@@ -29,6 +30,7 @@ export declare const displays: {
|
|
|
29
30
|
subtitle?: Ref;
|
|
30
31
|
badge?: Ref;
|
|
31
32
|
meta?: Ref[];
|
|
33
|
+
flags?: Ref[];
|
|
32
34
|
}, o?: Naming & {
|
|
33
35
|
card?: ComponentRef<never>;
|
|
34
36
|
}) => ListDisplayModel;
|
package/dist/view-displays.js
CHANGED
|
@@ -15,9 +15,10 @@ const displays = {
|
|
|
15
15
|
/**
|
|
16
16
|
* A card per record: `image`, a file field shown as a picture across the card's top, then `title` (default: the
|
|
17
17
|
* view's title) over `subtitle`, `badge` drawn as a badge with its value labels, and a few small `meta` fields such as
|
|
18
|
-
* dates.
|
|
19
|
-
* card
|
|
20
|
-
* built-in one. Named `cards` unless `name` says
|
|
18
|
+
* dates. `flags` are boolean fields shown as small badges of their labels when true, such as a garden or parking.
|
|
19
|
+
* With `card`, a component of the project or a plugin draws each card's content instead, from the row of those
|
|
20
|
+
* fields (`{ row }`); without it, or when it throws, the card is the built-in one. Named `cards` unless `name` says
|
|
21
|
+
* otherwise.
|
|
21
22
|
*/
|
|
22
23
|
cards: (fields, o = {}) => ({
|
|
23
24
|
kind: "cards",
|
|
@@ -28,6 +29,7 @@ const displays = {
|
|
|
28
29
|
...fields.subtitle && { subtitle: fields.subtitle.name },
|
|
29
30
|
...fields.badge && { badge: fields.badge.name },
|
|
30
31
|
...fields.meta && { meta: fields.meta.map((ref) => ref.name) },
|
|
32
|
+
...fields.flags && { flags: fields.flags.map((ref) => ref.name) },
|
|
31
33
|
...o.card && { card: customComponent(o.card, "d.cards card") }
|
|
32
34
|
}),
|
|
33
35
|
/**
|
|
@@ -61,7 +63,8 @@ const displayFields = (display) => display.kind === "cards" ? [
|
|
|
61
63
|
display.title,
|
|
62
64
|
display.subtitle,
|
|
63
65
|
display.badge,
|
|
64
|
-
...display.meta ?? []
|
|
66
|
+
...display.meta ?? [],
|
|
67
|
+
...display.flags ?? []
|
|
65
68
|
].filter((name) => name !== void 0) : [...display.fields, ...fieldRefsIn(display.props)];
|
|
66
69
|
//#endregion
|
|
67
70
|
export { customComponent, displayErrors, displayFields, displays, tableDisplay };
|
package/dist/view-field.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FieldFormat, FieldViewModel, JsonValue } from "./model.js";
|
|
1
|
+
import { BadgeShape, FieldFormat, FieldViewModel, JsonValue } from "./model.js";
|
|
2
2
|
//#region src/view-field.d.ts
|
|
3
3
|
export declare class FieldView<N extends string = string, V = unknown> {
|
|
4
4
|
readonly name: N;
|
|
@@ -8,9 +8,17 @@ export declare class FieldView<N extends string = string, V = unknown> {
|
|
|
8
8
|
help(help: string): FieldView<N, V>;
|
|
9
9
|
format(format: FieldFormat): FieldView<N, V>;
|
|
10
10
|
prefix(prefix: string): FieldView<N, V>;
|
|
11
|
+
/** Text after a number wherever it is shown, such as a unit: `.suffix(' m²')`. */
|
|
12
|
+
suffix(suffix: string): FieldView<N, V>;
|
|
11
13
|
decimals(decimals: number): FieldView<N, V>;
|
|
12
14
|
/** Labels for an enum's values, such as `{ co_signer: 'Co-signer' }`; values left out read as themselves in words. */
|
|
13
15
|
valueLabels(labels: { readonly [P in Extract<V, string>]?: string; }): FieldView<N, V>;
|
|
16
|
+
/** A hex colour per enum value that fills its badge, such as `{ a: '#00a651' }`; values left out keep their tone. */
|
|
17
|
+
valueColors(colors: { readonly [P in Extract<V, string>]?: string; }): FieldView<N, V>;
|
|
18
|
+
/** `arrow` draws the field's badges as arrows pointing right, as on a rating scale such as the EU energy label. */
|
|
19
|
+
badgeShape(badgeShape: BadgeShape): FieldView<N, V>;
|
|
20
|
+
/** An icon before the value on a card's meta row, by the names actions take, such as `ruler`. */
|
|
21
|
+
icon(icon: string): FieldView<N, V>;
|
|
14
22
|
/**
|
|
15
23
|
* Shows and edits the field with the field type a plugin registers under `name` (`definePlugin({ fields })`), given
|
|
16
24
|
* `props`, such as `r.score.widget('rating', { max: 5 })`. Without that plugin, or when the field type does not show
|
package/dist/view-field.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
//#region src/view-field.ts
|
|
2
|
+
const hexColor = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
2
3
|
var FieldView = class FieldView {
|
|
3
4
|
name;
|
|
4
5
|
props;
|
|
@@ -18,6 +19,10 @@ var FieldView = class FieldView {
|
|
|
18
19
|
prefix(prefix) {
|
|
19
20
|
return this.with({ prefix });
|
|
20
21
|
}
|
|
22
|
+
/** Text after a number wherever it is shown, such as a unit: `.suffix(' m²')`. */
|
|
23
|
+
suffix(suffix) {
|
|
24
|
+
return this.with({ suffix });
|
|
25
|
+
}
|
|
21
26
|
decimals(decimals) {
|
|
22
27
|
return this.with({ decimals });
|
|
23
28
|
}
|
|
@@ -28,6 +33,24 @@ var FieldView = class FieldView {
|
|
|
28
33
|
...labels
|
|
29
34
|
} });
|
|
30
35
|
}
|
|
36
|
+
/** A hex colour per enum value that fills its badge, such as `{ a: '#00a651' }`; values left out keep their tone. */
|
|
37
|
+
valueColors(colors) {
|
|
38
|
+
const entries = Object.entries(colors);
|
|
39
|
+
const wrong = entries.find(([, color]) => !hexColor.test(color));
|
|
40
|
+
if (wrong) throw new Error(`Field "${this.name}": value colour "${wrong[1]}" of "${wrong[0]}" is not a hex colour such as #00a651`);
|
|
41
|
+
return this.with({ valueColors: {
|
|
42
|
+
...this.props.valueColors,
|
|
43
|
+
...Object.fromEntries(entries)
|
|
44
|
+
} });
|
|
45
|
+
}
|
|
46
|
+
/** `arrow` draws the field's badges as arrows pointing right, as on a rating scale such as the EU energy label. */
|
|
47
|
+
badgeShape(badgeShape) {
|
|
48
|
+
return this.with({ badgeShape });
|
|
49
|
+
}
|
|
50
|
+
/** An icon before the value on a card's meta row, by the names actions take, such as `ruler`. */
|
|
51
|
+
icon(icon) {
|
|
52
|
+
return this.with({ icon });
|
|
53
|
+
}
|
|
31
54
|
/**
|
|
32
55
|
* Shows and edits the field with the field type a plugin registers under `name` (`definePlugin({ fields })`), given
|
|
33
56
|
* `props`, such as `r.score.widget('rating', { max: 5 })`. Without that plugin, or when the field type does not show
|
package/dist/view.js
CHANGED
|
@@ -98,6 +98,8 @@ var ViewBuilder = class ViewBuilder {
|
|
|
98
98
|
const unknown = displayFields(display).find((name) => !Object.hasOwn(resource.fields, name));
|
|
99
99
|
if (unknown !== void 0) throw new Error(`View "${this.state.resource}": display "${display.name}" names field "${unknown}", which the resource does not have`);
|
|
100
100
|
if (display.kind === "cards" && display.image !== void 0 && resource.fields[display.image].type !== "file") throw new Error(`View "${this.state.resource}": display "${display.name}" shows "${display.image}" as its image, which is not a file field`);
|
|
101
|
+
const flag = display.kind === "cards" ? display.flags?.find((name) => resource.fields[name].type !== "boolean") : void 0;
|
|
102
|
+
if (flag !== void 0) throw new Error(`View "${this.state.resource}": display "${display.name}" shows "${flag}" as a flag, which is not a boolean field`);
|
|
101
103
|
}
|
|
102
104
|
const recentErrors = resource && nav?.recent ? navRecentErrors(nav.recent, resource) : [];
|
|
103
105
|
if (recentErrors.length > 0) throw new Error(`View "${this.state.resource}": nav.recent ${recentErrors.join("; ")}`);
|