@protobase/schema 0.19.16 → 0.21.0
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 +3 -2
- package/dist/internal.d.ts +2 -1
- package/dist/internal.js +2 -1
- package/dist/layout.d.ts +9 -0
- package/dist/layout.js +14 -0
- package/dist/model.d.ts +34 -3
- package/dist/resource-model.d.ts +1 -0
- package/dist/resource-model.js +2 -1
- package/dist/resource.d.ts +6 -0
- package/dist/resource.js +8 -0
- package/dist/view-chart.d.ts +32 -0
- package/dist/view-chart.js +29 -0
- package/dist/view.d.ts +8 -7
- package/dist/view.js +7 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FileOptions, FileProcessor, FileProcessorInput, ImageFormat, ImageVariant, ImageVariantOptions, imageFormats } from "./files/file-options.js";
|
|
2
|
-
import { ActionInputKind, ActionInputModel, ActionModel, ActionRun, AppAddress, BadgeShape, BottomBarItemModel, BottomBarModel, CardFavoriteModel, CardPhotosModel, ChartGranularity, ChartModel, ChartRange, CheckedFilter, CompareOp, CreateModel, CustomSectionModel, DatePreset, DurationLiteral, DurationUnit, EventModel, EventOperation, ExportModel, FieldFormat, FieldModel, FieldPath, FieldType, FieldViewModel, FieldWidgetModel, FileFieldModel, FilterError, FilterErrorCode, FilterExpr, FilterLayout, FilterOf, FilterValue, FilterWidgetModel, GalleryModel, HelpWhen, JsonValue, KeyValue, LayoutItemModel, ListDisplayModel, ListModel, ListQuery, Literal, MapSectionModel, MapView, NavModel, NavRecentModel, NowValue, OrderByItem, RecordMode, RelatedColumnModel, RelatedModel, ResourceModel, SaveFeedback, SaveSearchModel, SearchMatch, SearchResultModel, SearchesOfModel, SectionPresentation, ShowWhen, SignInPromptModel, SignInViewModel, SortSpec, Span, StatusTone, UserMenuItemModel, UserMenuModel, ViewModel } from "./model.js";
|
|
2
|
+
import { ActionInputKind, ActionInputModel, ActionModel, ActionRun, AppAddress, BadgeShape, BottomBarItemModel, BottomBarModel, CardFavoriteModel, CardPhotosModel, ChartGranularity, ChartModel, ChartRange, CheckedFilter, CompareOp, CreateModel, CustomSectionModel, DatePreset, DurationLiteral, DurationUnit, EventModel, EventOperation, ExportModel, FieldFormat, FieldModel, FieldPath, FieldType, FieldViewModel, FieldWidgetModel, FileFieldModel, FilterError, FilterErrorCode, FilterExpr, FilterLayout, FilterOf, FilterValue, FilterWidgetModel, GalleryModel, GroupChartModel, HelpWhen, HistorySectionModel, JsonValue, KeyValue, LayoutItemModel, ListDisplayModel, ListModel, ListQuery, Literal, MapSectionModel, MapView, NavModel, NavRecentModel, NowValue, OrderByItem, PeriodChartModel, RecordMode, RelatedColumnModel, RelatedModel, ResourceModel, SaveFeedback, SaveSearchModel, SearchMatch, SearchResultModel, SearchesOfModel, SectionPresentation, ShowWhen, SignInPromptModel, SignInViewModel, SortSpec, Span, StatusTone, UserMenuItemModel, UserMenuModel, ViewModel } from "./model.js";
|
|
3
3
|
import { AccessAction, AccessContext, AccessFn, AccessResult, AccessUser, FieldAccess, FieldRule } from "./access/types.js";
|
|
4
4
|
import { AnyField, Constraint, Field, FieldMeta, FieldTypeDef } from "./field.js";
|
|
5
5
|
import { RelationField } from "./relation-field.js";
|
|
@@ -9,6 +9,7 @@ import { FieldRefs, FieldsInput, Ref, Refs } from "./refs.js";
|
|
|
9
9
|
import { CreatedOptions, DeletedOptions, EventActor, EventContext, EventHelpers, EventMatch, EventSpec, UndeletedOptions, UpdatedOptions } from "./events/event-helpers.js";
|
|
10
10
|
import { Access, InferRecord, Issue, KeyOf, KeyRefs, RecordKey, RecordOf } from "./resource-types.js";
|
|
11
11
|
import { ResourceBuilder, SearchRef, SearchRefs, Validator, resource } from "./resource.js";
|
|
12
|
+
import { ChartInput, GroupChartInput, PeriodChartInput } from "./view-chart.js";
|
|
12
13
|
import { ListColumn } from "./view-columns.js";
|
|
13
14
|
import { ComponentRef, ViewProps } from "./view-displays.js";
|
|
14
15
|
import { FieldView } from "./view-field.js";
|
|
@@ -38,4 +39,4 @@ import { AccessSource, ResolveOptions, ResolvedAccess, RowFilterOperation, acces
|
|
|
38
39
|
import { restrictModel } from "./access/restrict.js";
|
|
39
40
|
import "./access/index.js";
|
|
40
41
|
import { AssistantAction, AssistantActionRequest, AssistantCardPart, AssistantDiff, AssistantEvent, AssistantMessage, AssistantMessageRequest, AssistantPart, AssistantState, AssistantStep, AssistantStepState, AssistantTablePart, AssistantTextPart, AssistantTone, AssistantWidgetPart } from "./assistant/protocol.js";
|
|
41
|
-
export { type Access, type AccessAction, type AccessContext, type AccessFn, type AccessResult, type AccessSource, type AccessUser, type ActionInputKind, type ActionInputModel, type ActionModel, type ActionRun, type AnyField, 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 CardFavoriteModel, type CardPhotosModel, type ChartGranularity, type ChartModel, type ChartRange, type CheckResult, type CheckedFilter, type CompareOp, type ComponentRef, type Constraint, type CreateModel, type CreatedOptions, type CustomSectionModel, type DatePreset, type DeletedOptions, type DurationLiteral, type DurationUnit, type EvaluateOptions, type EventActor, type EventContext, type EventHelpers, type EventMatch, type EventModel, type EventOperation, type EventSpec, type ExportModel, type Field, type FieldAccess, type FieldFormat, type FieldMeta, type FieldModel, type FieldPath, type FieldRefValue, type FieldRefs, type FieldRule, type FieldType, type FieldTypeDef, type FieldView, type FieldViewModel, type FieldViews, type FieldWidgetModel, type FieldsInput, type FileField, type FileFieldModel, type FileOptions, type FileProcessor, type FileProcessorInput, type FilterError, type FilterErrorCode, type FilterExpr, type FilterLayout, type FilterLimits, type FilterOf, type FilterParse, type FilterValue, type FilterWidgetModel, type GalleryModel, type Grant, type HeldCapability, type HelpWhen, type ImageFormat, type ImageVariant, type ImageVariantOptions, type InferRecord, type Issue, type JsonValue, type KeyOf, type KeyRefs, type KeyType, type KeyValue, type LayoutItemModel, type ListColumn, type ListDisplayModel, type ListModel, type ListQuery, type Literal, type MapSectionModel, type MapView, type NavModel, type NavRecentModel, type NowValue, type OrderByCheck, type OrderByItem, type OrderByParse, type RecordKey, type RecordMode, type RecordOf, type Ref, type Refs, type RelatedColumnModel, type RelatedModel, type RelationField, type ResolveOptions, type ResolvedAccess, type ResourceBuilder, type ResourceModel, type RoleEntry, type RoleLimit, type Roles, type RolesOptions, type RowFilterOperation, type Rule, type SaveFeedback, type SaveSearchModel, type SearchMatch, type SearchRef, type SearchRefs, type SearchResultModel, type SearchesOfModel, type SectionPresentation, type ShowWhen, type SignInAddress, type SignInPromptModel, type SignInStep, type SignInViewModel, type SortSpec, type Span, type StatusTone, type UndeletedOptions, type UpdatedOptions, type UserMenuItemModel, type UserMenuModel, type UserMenuSource, type Validator, type ViewBuilder, type ViewModel, type ViewProps, accessWarnings, addressWords, anonymousRole, appPath, bottomBar, bottomBarErrors, checkFilter, checkOrderBy, checkRecord, createWhere, defineRoles, enumLabel, evaluateFilter, f, fieldRef, fieldsUsedBy, fitsKeyType, imageFormats, keyTypes, layout as l, maxBottomBarItems, parseFilter, parseOrderBy, pickView, printFilter, printOrderBy, readAppPath, readSignInAddress, resolveAccess, resource, restrictModel, rule, signInParams, signInPath, signInRoute, signInSteps, userMenu, view, where };
|
|
42
|
+
export { type Access, type AccessAction, type AccessContext, type AccessFn, type AccessResult, type AccessSource, type AccessUser, type ActionInputKind, type ActionInputModel, type ActionModel, type ActionRun, type AnyField, 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 CardFavoriteModel, type CardPhotosModel, type ChartGranularity, type ChartInput, type ChartModel, type ChartRange, type CheckResult, type CheckedFilter, type CompareOp, type ComponentRef, type Constraint, type CreateModel, type CreatedOptions, type CustomSectionModel, type DatePreset, type DeletedOptions, type DurationLiteral, type DurationUnit, type EvaluateOptions, type EventActor, type EventContext, type EventHelpers, type EventMatch, type EventModel, type EventOperation, type EventSpec, type ExportModel, type Field, type FieldAccess, type FieldFormat, type FieldMeta, type FieldModel, type FieldPath, type FieldRefValue, type FieldRefs, type FieldRule, type FieldType, type FieldTypeDef, type FieldView, type FieldViewModel, type FieldViews, type FieldWidgetModel, type FieldsInput, type FileField, type FileFieldModel, type FileOptions, type FileProcessor, type FileProcessorInput, type FilterError, type FilterErrorCode, type FilterExpr, type FilterLayout, type FilterLimits, type FilterOf, type FilterParse, type FilterValue, type FilterWidgetModel, type GalleryModel, type Grant, type GroupChartInput, type GroupChartModel, type HeldCapability, type HelpWhen, type HistorySectionModel, type ImageFormat, type ImageVariant, type ImageVariantOptions, type InferRecord, type Issue, type JsonValue, type KeyOf, type KeyRefs, type KeyType, type KeyValue, type LayoutItemModel, type ListColumn, type ListDisplayModel, type ListModel, type ListQuery, type Literal, type MapSectionModel, type MapView, type NavModel, type NavRecentModel, type NowValue, type OrderByCheck, type OrderByItem, type OrderByParse, type PeriodChartInput, type PeriodChartModel, type RecordKey, type RecordMode, type RecordOf, type Ref, type Refs, type RelatedColumnModel, type RelatedModel, type RelationField, type ResolveOptions, type ResolvedAccess, type ResourceBuilder, type ResourceModel, type RoleEntry, type RoleLimit, type Roles, type RolesOptions, type RowFilterOperation, type Rule, type SaveFeedback, type SaveSearchModel, type SearchMatch, type SearchRef, type SearchRefs, type SearchResultModel, type SearchesOfModel, type SectionPresentation, type ShowWhen, type SignInAddress, type SignInPromptModel, type SignInStep, type SignInViewModel, type SortSpec, type Span, type StatusTone, type UndeletedOptions, type UpdatedOptions, type UserMenuItemModel, type UserMenuModel, type UserMenuSource, type Validator, type ViewBuilder, type ViewModel, type ViewProps, accessWarnings, addressWords, anonymousRole, appPath, bottomBar, bottomBarErrors, checkFilter, checkOrderBy, checkRecord, createWhere, defineRoles, enumLabel, evaluateFilter, f, fieldRef, fieldsUsedBy, fitsKeyType, imageFormats, keyTypes, layout as l, maxBottomBarItems, parseFilter, parseOrderBy, pickView, printFilter, printOrderBy, readAppPath, readSignInAddress, resolveAccess, resource, restrictModel, rule, signInParams, signInPath, signInRoute, signInSteps, userMenu, view, where };
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { checkedAccept, checkedProvider, parseSize } from "./files/file-options.js";
|
|
2
2
|
import { actionInputErrors, shownInputs } from "./action-inputs.js";
|
|
3
|
+
import { chartFields, isGroupChart } from "./view-chart.js";
|
|
3
4
|
import { boardErrors, cardPhotoLimit, displayFields, tableDisplay } from "./view-displays.js";
|
|
4
5
|
import { fieldRefsIn, isFieldRef, markFieldRefs, unmarkFieldRefs } from "./field-ref.js";
|
|
5
6
|
import { bottomBarFor } from "./bottom-bar.js";
|
|
@@ -15,4 +16,4 @@ import { addressPlaceholders, appHrefError, fillAddress, hrefField, hrefPlacehol
|
|
|
15
16
|
import { AddressCheck, addressErrors } from "./address-errors.js";
|
|
16
17
|
import { applyAssistantEvent, emptyAssistantState } from "./assistant/apply-event.js";
|
|
17
18
|
import { readEventStream } from "./assistant/event-stream.js";
|
|
18
|
-
export { type AddressCheck, type PluginHost, type PluginRequirement, type PropShapes, type RefShape, type SearchTerm, actionInputErrors, addressErrors, addressPlaceholders, appHrefError, applyAssistantEvent, boardErrors, bottomBarFor, cardPhotoLimit, checkEventFilter, checkedAccept, checkedProvider, decodeKey, defaultRecentLimit, displayFields, emptyAssistantState, encodeKey, fieldRefsIn, fillAddress, hrefField, hrefPlaceholders, inRange, isFieldRef, leavesApp, linkActionError, markFieldRefs, matchedSearchField, matchesSearch, navRecentErrors, parseSize, pluginProblem, pruneByShape, readEventStream, redactSecrets, searchTerms, shapes, shownInputs, statusTones, tableDisplay, termMatches, unmarkFieldRefs, webhookResources };
|
|
19
|
+
export { type AddressCheck, type PluginHost, type PluginRequirement, type PropShapes, type RefShape, type SearchTerm, actionInputErrors, addressErrors, addressPlaceholders, appHrefError, applyAssistantEvent, boardErrors, bottomBarFor, cardPhotoLimit, chartFields, checkEventFilter, checkedAccept, checkedProvider, decodeKey, defaultRecentLimit, displayFields, emptyAssistantState, encodeKey, fieldRefsIn, fillAddress, hrefField, hrefPlaceholders, inRange, isFieldRef, isGroupChart, leavesApp, linkActionError, markFieldRefs, matchedSearchField, matchesSearch, navRecentErrors, parseSize, pluginProblem, pruneByShape, readEventStream, redactSecrets, searchTerms, shapes, shownInputs, statusTones, tableDisplay, termMatches, unmarkFieldRefs, webhookResources };
|
package/dist/internal.js
CHANGED
|
@@ -4,6 +4,7 @@ import { checkEventFilter } from "./events/event-models.js";
|
|
|
4
4
|
import { defaultRecentLimit, navRecentErrors, statusTones } from "./nav-recent.js";
|
|
5
5
|
import { actionInputErrors, shownInputs } from "./action-inputs.js";
|
|
6
6
|
import { addressPlaceholders, appHrefError, fillAddress, hrefField, hrefPlaceholders, leavesApp, linkActionError } from "./address-template.js";
|
|
7
|
+
import { chartFields, isGroupChart } from "./view-chart.js";
|
|
7
8
|
import { fieldRefsIn, isFieldRef, markFieldRefs, unmarkFieldRefs } from "./field-ref.js";
|
|
8
9
|
import { boardErrors, cardPhotoLimit, displayFields, tableDisplay } from "./view-displays.js";
|
|
9
10
|
import { bottomBarFor } from "./bottom-bar.js";
|
|
@@ -15,4 +16,4 @@ import { redactSecrets } from "./redact-secrets.js";
|
|
|
15
16
|
import { addressErrors } from "./address-errors.js";
|
|
16
17
|
import { applyAssistantEvent, emptyAssistantState } from "./assistant/apply-event.js";
|
|
17
18
|
import { readEventStream } from "./assistant/event-stream.js";
|
|
18
|
-
export { actionInputErrors, addressErrors, addressPlaceholders, appHrefError, applyAssistantEvent, boardErrors, bottomBarFor, cardPhotoLimit, checkEventFilter, checkedAccept, checkedProvider, decodeKey, defaultRecentLimit, displayFields, emptyAssistantState, encodeKey, fieldRefsIn, fillAddress, hrefField, hrefPlaceholders, inRange, isFieldRef, leavesApp, linkActionError, markFieldRefs, matchedSearchField, matchesSearch, navRecentErrors, parseSize, pluginProblem, pruneByShape, readEventStream, redactSecrets, searchTerms, shapes, shownInputs, statusTones, tableDisplay, termMatches, unmarkFieldRefs, webhookResources };
|
|
19
|
+
export { actionInputErrors, addressErrors, addressPlaceholders, appHrefError, applyAssistantEvent, boardErrors, bottomBarFor, cardPhotoLimit, chartFields, checkEventFilter, checkedAccept, checkedProvider, decodeKey, defaultRecentLimit, displayFields, emptyAssistantState, encodeKey, fieldRefsIn, fillAddress, hrefField, hrefPlaceholders, inRange, isFieldRef, isGroupChart, leavesApp, linkActionError, markFieldRefs, matchedSearchField, matchesSearch, navRecentErrors, parseSize, pluginProblem, pruneByShape, readEventStream, redactSecrets, searchTerms, shapes, shownInputs, statusTones, tableDisplay, termMatches, unmarkFieldRefs, webhookResources };
|
package/dist/layout.d.ts
CHANGED
|
@@ -64,6 +64,15 @@ export declare const layout: {
|
|
|
64
64
|
sidebar?: boolean;
|
|
65
65
|
when?: ShowWhen;
|
|
66
66
|
}) => LayoutItemModel;
|
|
67
|
+
/**
|
|
68
|
+
* The record's changes, newest first: who made each, when, and the fields before and after, only those the user may
|
|
69
|
+
* read. `limit` changes show before Show more (default 10). Needs `.history()` on the resource; a view without a
|
|
70
|
+
* layout shows it last by itself. See [Record history](website/src/content/docs/reference/history.mdx).
|
|
71
|
+
*/
|
|
72
|
+
history: (title?: string, o?: {
|
|
73
|
+
limit?: number;
|
|
74
|
+
when?: ShowWhen;
|
|
75
|
+
}) => LayoutItemModel;
|
|
67
76
|
/**
|
|
68
77
|
* A component of the project, registered in `protobase.ui.tsx` under its name, drawn where it is listed: in the main
|
|
69
78
|
* column, or in the sidebar with `sidebar: true`. The record page stays around it, with its title, breadcrumbs,
|
package/dist/layout.js
CHANGED
|
@@ -80,6 +80,20 @@ const layout = {
|
|
|
80
80
|
...o.when !== void 0 && { when: o.when }
|
|
81
81
|
}),
|
|
82
82
|
/**
|
|
83
|
+
* The record's changes, newest first: who made each, when, and the fields before and after, only those the user may
|
|
84
|
+
* read. `limit` changes show before Show more (default 10). Needs `.history()` on the resource; a view without a
|
|
85
|
+
* layout shows it last by itself. See [Record history](website/src/content/docs/reference/history.mdx).
|
|
86
|
+
*/
|
|
87
|
+
history: (title = "History", o = {}) => {
|
|
88
|
+
if (o.limit !== void 0 && (!Number.isInteger(o.limit) || o.limit < 1)) throw new Error(`l.history "${title}": limit must be a positive whole number`);
|
|
89
|
+
return {
|
|
90
|
+
kind: "history",
|
|
91
|
+
title,
|
|
92
|
+
...o.limit !== void 0 && { limit: o.limit },
|
|
93
|
+
...o.when !== void 0 && { when: o.when }
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
/**
|
|
83
97
|
* A component of the project, registered in `protobase.ui.tsx` under its name, drawn where it is listed: in the main
|
|
84
98
|
* column, or in the sidebar with `sidebar: true`. The record page stays around it, with its title, breadcrumbs,
|
|
85
99
|
* actions and save; the component reads the record with `useLayoutRecord()`.
|
package/dist/model.d.ts
CHANGED
|
@@ -96,6 +96,8 @@ export type ResourceModel = {
|
|
|
96
96
|
owner?: string;
|
|
97
97
|
/** The events its changes raise (`.events()`), the catalogue subscriptions pick from. */
|
|
98
98
|
events?: EventModel[];
|
|
99
|
+
/** Whether every change of its records is kept, with who made it (`.history()`). */
|
|
100
|
+
history?: true;
|
|
99
101
|
};
|
|
100
102
|
/** What happened to a record: `delete` and `undelete` include setting and clearing a soft delete field. */
|
|
101
103
|
export type EventOperation = 'create' | 'update' | 'delete' | 'undelete';
|
|
@@ -636,6 +638,20 @@ export type MapSectionModel = {
|
|
|
636
638
|
/** Whether it shows on the form, the read view or both. */
|
|
637
639
|
when?: ShowWhen;
|
|
638
640
|
};
|
|
641
|
+
/**
|
|
642
|
+
* The record's changes, newest first, with who made each and the fields before and after: only fields the caller may
|
|
643
|
+
* read. Needs `.history()` on the resource. See [Record history](website/src/content/docs/reference/history.mdx).
|
|
644
|
+
*/
|
|
645
|
+
export type HistorySectionModel = {
|
|
646
|
+
/** A history section. */
|
|
647
|
+
kind: 'history';
|
|
648
|
+
/** The section's title. */
|
|
649
|
+
title: string;
|
|
650
|
+
/** How many changes it shows before Show more; 10 when omitted. */
|
|
651
|
+
limit?: number;
|
|
652
|
+
/** Whether it shows on the form, the read view or both. */
|
|
653
|
+
when?: ShowWhen;
|
|
654
|
+
};
|
|
639
655
|
/** How a section shows its fields on the read view: `facts` as a row of key facts; label/value rows when omitted. */
|
|
640
656
|
export type SectionPresentation = 'facts';
|
|
641
657
|
/** An item of the record page (`.layout((r) => ...)` with `l`); see [The record page](website/src/content/docs/reference/ui-config.mdx#the-record-page). */
|
|
@@ -664,7 +680,7 @@ export type LayoutItemModel = {
|
|
|
664
680
|
fields: string[];
|
|
665
681
|
/** Whether it shows on the form, the read view or both. */
|
|
666
682
|
when?: ShowWhen;
|
|
667
|
-
} | RelatedModel | CustomSectionModel | MapSectionModel | GalleryModel;
|
|
683
|
+
} | RelatedModel | CustomSectionModel | MapSectionModel | GalleryModel | HistorySectionModel;
|
|
668
684
|
/**
|
|
669
685
|
* A record's photos as tiles in the main column under `title`, one large and the next few smaller, opening a lightbox
|
|
670
686
|
* that steps through them all: first the record's own file field `image`, then the `image` of the records of
|
|
@@ -687,8 +703,8 @@ export type GalleryModel = {
|
|
|
687
703
|
export type ChartRange = '7d' | '30d' | '90d' | '1y' | 'all';
|
|
688
704
|
/** How long each bar of a list's chart is. */
|
|
689
705
|
export type ChartGranularity = 'hour' | 'day' | 'week' | 'month';
|
|
690
|
-
/** A chart of records over time above a list, following its filters (`.chart(...)`). */
|
|
691
|
-
export type
|
|
706
|
+
/** A chart of records over time above a list, following its filters (`.chart(...)` with `field`). */
|
|
707
|
+
export type PeriodChartModel = {
|
|
692
708
|
/** The date or timestamp field the records are counted by. */
|
|
693
709
|
field: string;
|
|
694
710
|
/** How far back it reaches. */
|
|
@@ -696,6 +712,21 @@ export type ChartModel = {
|
|
|
696
712
|
/** How long each bar is. */
|
|
697
713
|
granularity: ChartGranularity;
|
|
698
714
|
};
|
|
715
|
+
/** A chart of records per value of a field above a list, following its filters (`.chart(...)` with `groupBy`). */
|
|
716
|
+
export type GroupChartModel = {
|
|
717
|
+
/** The field whose values make the groups, such as a status or a relation; not a date. */
|
|
718
|
+
groupBy: string;
|
|
719
|
+
/** Bars, the largest first, or a donut. */
|
|
720
|
+
type: 'bar' | 'donut';
|
|
721
|
+
/** A numeric field each group adds up, instead of counting its records. */
|
|
722
|
+
sum?: string;
|
|
723
|
+
/** A numeric field each group averages, instead of counting its records. */
|
|
724
|
+
average?: string;
|
|
725
|
+
/** How many values it shows, the largest. */
|
|
726
|
+
limit: number;
|
|
727
|
+
};
|
|
728
|
+
/** The chart above a list: records over time, or records per value of a field. */
|
|
729
|
+
export type ChartModel = PeriodChartModel | GroupChartModel;
|
|
699
730
|
/**
|
|
700
731
|
* How the record page opens to a user who may change the record: `edit`, the default, as its form, ready to change;
|
|
701
732
|
* `read` as a read view of label/value tables, with an Edit button to the form; `locked` as the same form, locked until
|
package/dist/resource-model.d.ts
CHANGED
package/dist/resource-model.js
CHANGED
|
@@ -57,7 +57,8 @@ const assembleModel = (state) => {
|
|
|
57
57
|
...state.tenant && { tenant: state.tenant },
|
|
58
58
|
...state.search && { search: [...state.search] },
|
|
59
59
|
...state.searchMatch && Object.keys(state.searchMatch).length > 0 && { searchMatch: { ...state.searchMatch } },
|
|
60
|
-
...state.owner && { owner: state.owner }
|
|
60
|
+
...state.owner && { owner: state.owner },
|
|
61
|
+
...state.history && { history: true }
|
|
61
62
|
};
|
|
62
63
|
};
|
|
63
64
|
const sensitiveProblems = (model) => Object.values(model.fields).filter((field) => field.sensitive).flatMap((field) => [
|
package/dist/resource.d.ts
CHANGED
|
@@ -83,6 +83,12 @@ export declare class ResourceBuilder<F extends FieldsInput = {}, K = never> {
|
|
|
83
83
|
* ```
|
|
84
84
|
*/
|
|
85
85
|
events(define: (e: EventHelpers<RecordOf<F>>, r: FieldRefs<F>) => EventSpec[]): ResourceBuilder<F, K>;
|
|
86
|
+
/**
|
|
87
|
+
* Keeps every change of its records, from the API or elsewhere: the fields before and after, and who made it. The
|
|
88
|
+
* record page shows it as History, and admins list every change as Activity. See
|
|
89
|
+
* [Record history](website/src/content/docs/reference/history.mdx).
|
|
90
|
+
*/
|
|
91
|
+
history(): ResourceBuilder<F, K>;
|
|
86
92
|
/** The code predicates (`match`) of its events, by event name. */
|
|
87
93
|
eventMatches(): Record<string, EventMatch<any>>;
|
|
88
94
|
/**
|
package/dist/resource.js
CHANGED
|
@@ -94,6 +94,14 @@ var ResourceBuilder = class ResourceBuilder {
|
|
|
94
94
|
events(define) {
|
|
95
95
|
return this.next({ events: define(eventHelpers(), this.refs()) });
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Keeps every change of its records, from the API or elsewhere: the fields before and after, and who made it. The
|
|
99
|
+
* record page shows it as History, and admins list every change as Activity. See
|
|
100
|
+
* [Record history](website/src/content/docs/reference/history.mdx).
|
|
101
|
+
*/
|
|
102
|
+
history() {
|
|
103
|
+
return this.next({ history: true });
|
|
104
|
+
}
|
|
97
105
|
/** The code predicates (`match`) of its events, by event name. */
|
|
98
106
|
eventMatches() {
|
|
99
107
|
return eventMatches(this.toModel(), this.state.events ?? []);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ChartGranularity, ChartModel, ChartRange, GroupChartModel } from "./model.js";
|
|
2
|
+
import { Ref } from "./refs.js";
|
|
3
|
+
//#region src/view-chart.d.ts
|
|
4
|
+
/** Records per `granularity` over a date or timestamp `field`. */
|
|
5
|
+
export type PeriodChartInput = {
|
|
6
|
+
/** The date or timestamp field the records are counted by. */
|
|
7
|
+
field: Ref;
|
|
8
|
+
/** How far back it reaches. */
|
|
9
|
+
range: ChartRange;
|
|
10
|
+
/** How long each bar is. */
|
|
11
|
+
granularity: ChartGranularity;
|
|
12
|
+
};
|
|
13
|
+
/** Records per value of `groupBy`, counted, or with `sum` or `average` that of a numeric field. */
|
|
14
|
+
export type GroupChartInput = {
|
|
15
|
+
/** The field whose values make the groups, such as a status or a relation; not a date. */
|
|
16
|
+
groupBy: Ref;
|
|
17
|
+
/** Bars, the default, or a donut. */
|
|
18
|
+
type?: GroupChartModel['type'];
|
|
19
|
+
/** How many values it shows, the largest; default 10. */
|
|
20
|
+
limit?: number;
|
|
21
|
+
/** A numeric field each group adds up, instead of counting its records. */
|
|
22
|
+
sum?: Ref;
|
|
23
|
+
/** A numeric field each group averages, instead of counting its records. */
|
|
24
|
+
average?: Ref;
|
|
25
|
+
};
|
|
26
|
+
/** What `.chart(...)` takes: a chart over time or per value. */
|
|
27
|
+
export type ChartInput = PeriodChartInput | GroupChartInput;
|
|
28
|
+
/** Whether a list's chart counts records per value of a field rather than over time. */
|
|
29
|
+
export declare const isGroupChart: (chart: ChartModel) => chart is GroupChartModel;
|
|
30
|
+
/** The fields a list's chart reads: its date field, or the field it groups by and the one it adds up. */
|
|
31
|
+
export declare const chartFields: (chart: ChartModel) => string[];
|
|
32
|
+
//#endregion
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/view-chart.ts
|
|
2
|
+
const defaultLimit = 10;
|
|
3
|
+
const chartModel = (input) => {
|
|
4
|
+
if (!("groupBy" in input)) return {
|
|
5
|
+
field: input.field.name,
|
|
6
|
+
range: input.range,
|
|
7
|
+
granularity: input.granularity
|
|
8
|
+
};
|
|
9
|
+
if (input.sum && input.average) throw new Error("A chart takes sum or average, not both");
|
|
10
|
+
const limit = input.limit ?? defaultLimit;
|
|
11
|
+
if (!Number.isInteger(limit) || limit < 1) throw new Error(`A chart's limit must be a positive whole number, not ${limit}`);
|
|
12
|
+
return {
|
|
13
|
+
groupBy: input.groupBy.name,
|
|
14
|
+
type: input.type ?? "bar",
|
|
15
|
+
...input.sum && { sum: input.sum.name },
|
|
16
|
+
...input.average && { average: input.average.name },
|
|
17
|
+
limit
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/** Whether a list's chart counts records per value of a field rather than over time. */
|
|
21
|
+
const isGroupChart = (chart) => "groupBy" in chart;
|
|
22
|
+
/** The fields a list's chart reads: its date field, or the field it groups by and the one it adds up. */
|
|
23
|
+
const chartFields = (chart) => isGroupChart(chart) ? [
|
|
24
|
+
chart.groupBy,
|
|
25
|
+
...chart.sum ? [chart.sum] : [],
|
|
26
|
+
...chart.average ? [chart.average] : []
|
|
27
|
+
] : [chart.field];
|
|
28
|
+
//#endregion
|
|
29
|
+
export { chartFields, chartModel, isGroupChart };
|
package/dist/view.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ActionModel,
|
|
1
|
+
import { ActionModel, CreateModel, ExportModel, FilterWidgetModel, HelpWhen, LayoutItemModel, ListDisplayModel, NavModel, NavRecentModel, RecordMode, ResourceModel, SaveFeedback, SaveSearchModel, SignInPromptModel, ViewModel } from "./model.js";
|
|
2
2
|
import { FieldRefs, Ref } from "./refs.js";
|
|
3
3
|
import { actions } from "./view-actions.js";
|
|
4
|
+
import { ChartInput } from "./view-chart.js";
|
|
4
5
|
import { ListColumn, columns } from "./view-columns.js";
|
|
5
6
|
import { displays } from "./view-displays.js";
|
|
6
7
|
import { FieldView } from "./view-field.js";
|
|
@@ -90,12 +91,12 @@ export declare class ViewBuilder<R extends {
|
|
|
90
91
|
* Without it the page shows one section with every field.
|
|
91
92
|
*/
|
|
92
93
|
layout(build: (r: FieldRefs<FieldsOf<R>>) => LayoutItemModel[]): ViewBuilder<R>;
|
|
93
|
-
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
/**
|
|
95
|
+
* A chart above the list, following its filters: records per `granularity` over a date or timestamp `field`, or
|
|
96
|
+
* records per value of `groupBy`, such as a status or a relation, as bars or a donut of the `limit` largest (default
|
|
97
|
+
* 10), counted or with `sum` or `average` that of a numeric field.
|
|
98
|
+
*/
|
|
99
|
+
chart(build: (r: FieldRefs<FieldsOf<R>>) => ChartInput): ViewBuilder<R>;
|
|
99
100
|
/**
|
|
100
101
|
* How the record page opens to a user who may change the record: `edit`, the default, as its form; `read` as a read
|
|
101
102
|
* view, its sections as tables of labels and values, with an Edit button to the form; `locked` as the form, locked
|
package/dist/view.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createRefs, ref } from "./refs.js";
|
|
|
2
2
|
import { isMenuHref } from "./menu-href.js";
|
|
3
3
|
import { navRecentErrors } from "./nav-recent.js";
|
|
4
4
|
import { actions } from "./view-actions.js";
|
|
5
|
+
import { chartModel } from "./view-chart.js";
|
|
5
6
|
import { columns, isListColumn } from "./view-columns.js";
|
|
6
7
|
import { boardErrors, displayErrors, displayFields, displays } from "./view-displays.js";
|
|
7
8
|
import { FieldView } from "./view-field.js";
|
|
@@ -114,14 +115,13 @@ var ViewBuilder = class ViewBuilder {
|
|
|
114
115
|
layout(build) {
|
|
115
116
|
return this.next({ layout: build(this.refs()) });
|
|
116
117
|
}
|
|
117
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* A chart above the list, following its filters: records per `granularity` over a date or timestamp `field`, or
|
|
120
|
+
* records per value of `groupBy`, such as a status or a relation, as bars or a donut of the `limit` largest (default
|
|
121
|
+
* 10), counted or with `sum` or `average` that of a numeric field.
|
|
122
|
+
*/
|
|
118
123
|
chart(build) {
|
|
119
|
-
|
|
120
|
-
return this.next({ chart: {
|
|
121
|
-
field: field.name,
|
|
122
|
-
range,
|
|
123
|
-
granularity
|
|
124
|
-
} });
|
|
124
|
+
return this.next({ chart: chartModel(build(this.refs())) });
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
127
|
* How the record page opens to a user who may change the record: `edit`, the default, as its form; `read` as a read
|