@protobase/schema 0.9.0 → 0.10.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.
@@ -18,6 +18,7 @@ export type ResolveOptions = {
18
18
  */
19
19
  roles?: {
20
20
  can: (capability: any) => Rule;
21
+ definitions?: Record<string, unknown>;
21
22
  };
22
23
  /**
23
24
  * Overrides what an operation without a rule does. Without `roles` the default is `allow`,
@@ -0,0 +1,14 @@
1
+ import { BottomBarModel } from "./model.js";
2
+ //#region src/bottom-bar-errors.d.ts
3
+ /** What the bottom bars may name. Without `roles` (an app whose roles are not declared) any role is accepted. */
4
+ export type BottomBarNames = {
5
+ resources: readonly string[];
6
+ pages: readonly string[];
7
+ roles?: readonly string[];
8
+ };
9
+ /**
10
+ * Why the bottom bars do not fit the app, as messages; empty when they do. Pure, so it can run wherever the config is
11
+ * known: at startup today, when a bundle is built later.
12
+ */
13
+ export declare const bottomBarErrors: (bars: BottomBarModel[], names: BottomBarNames) => string[];
14
+ //#endregion
@@ -0,0 +1,33 @@
1
+ import "./bottom-bar.js";
2
+ //#region src/bottom-bar-errors.ts
3
+ const itemErrors = (item, names) => {
4
+ if (item.kind === "resource" && !names.resources.includes(item.resource)) return [`resource "${item.resource}" does not exist`];
5
+ if (item.kind === "page" && !names.pages.includes(item.page)) return [`page "${item.page}" does not exist`];
6
+ return [];
7
+ };
8
+ const barErrors = (bar, names) => {
9
+ const unknownRoles = names.roles ? bar.roles.filter((role) => !names.roles.includes(role)) : [];
10
+ return [
11
+ ...bar.roles.length === 0 ? ["needs at least one role"] : [],
12
+ ...unknownRoles.map((role) => `role "${role}" is not one of the roles: ${names.roles.join(", ")}`),
13
+ ...bar.items.length === 0 ? ["needs at least one item"] : [],
14
+ ...bar.items.length > 4 ? [`has ${bar.items.length} items; at most 4 fit beside "More"`] : [],
15
+ ...bar.items.flatMap((item) => itemErrors(item, names))
16
+ ].map((error) => `Bottom bar "${bar.label}": ${error}`);
17
+ };
18
+ const overlapErrors = (bars) => bars.flatMap((bar, index) => {
19
+ const earlier = bars.slice(0, index);
20
+ const sameLabel = earlier.some((other) => other.label === bar.label) ? [`Two bottom bars are labelled "${bar.label}"; give each its own label`] : [];
21
+ const shared = bar.roles.flatMap((role) => {
22
+ const other = earlier.find((candidate) => candidate.roles.includes(role));
23
+ return other ? [`Bottom bars "${other.label}" and "${bar.label}" both name role "${role}"; a role belongs to one bottom bar`] : [];
24
+ });
25
+ return [...sameLabel, ...shared];
26
+ });
27
+ /**
28
+ * Why the bottom bars do not fit the app, as messages; empty when they do. Pure, so it can run wherever the config is
29
+ * known: at startup today, when a bundle is built later.
30
+ */
31
+ const bottomBarErrors = (bars, names) => [...bars.flatMap((bar) => barErrors(bar, names)), ...overlapErrors(bars)];
32
+ //#endregion
33
+ export { bottomBarErrors };
@@ -0,0 +1,35 @@
1
+ import { BottomBarItemModel, BottomBarModel } from "./model.js";
2
+ //#region src/bottom-bar.d.ts
3
+ /** The tabs beside the last one, "More", which opens the sidebar: five tabs in all, as on iOS. */
4
+ export declare const maxBottomBarItems = 4;
5
+ declare const items: {
6
+ /** Opens the resource's list. */
7
+ resource: (resource: string, options: {
8
+ label: string;
9
+ icon?: string;
10
+ }) => BottomBarItemModel;
11
+ /** Opens a composed page (`page()` from @protobase/layout). */
12
+ page: (page: string, options: {
13
+ label: string;
14
+ icon?: string;
15
+ }) => BottomBarItemModel;
16
+ /** An address outside the admin, opened in a new tab: `https:`, `http:` or `mailto:`. */
17
+ link: (label: string, href: string, options?: {
18
+ icon?: string;
19
+ }) => BottomBarItemModel;
20
+ };
21
+ /** What the server needs from a `bottomBar(...)` export of the config module. */
22
+ export type BottomBarSource = {
23
+ toBottomBarModel(): BottomBarModel;
24
+ };
25
+ /**
26
+ * Tabs at the bottom of the screen on phones, for the users holding one of `roles`. Export one per group of roles; a
27
+ * role belongs to one bottom bar. `label` names the bar where someone with several switches between them.
28
+ */
29
+ export declare const bottomBar: (options: {
30
+ label: string;
31
+ roles: string[];
32
+ }, build: (m: typeof items) => BottomBarItemModel[]) => BottomBarSource;
33
+ /** The bottom bar of someone working as `role`: the one that names it, since a role belongs to one bar. */
34
+ export declare const bottomBarFor: (bars: readonly BottomBarModel[], role: string | undefined) => BottomBarModel | undefined;
35
+ //#endregion
@@ -0,0 +1,44 @@
1
+ import { isMenuHref } from "./menu-href.js";
2
+ //#region src/bottom-bar.ts
3
+ /** The tabs beside the last one, "More", which opens the sidebar: five tabs in all, as on iOS. */
4
+ const maxBottomBarItems = 4;
5
+ const items = {
6
+ /** Opens the resource's list. */
7
+ resource: (resource, options) => ({
8
+ kind: "resource",
9
+ resource,
10
+ ...options
11
+ }),
12
+ /** Opens a composed page (`page()` from @protobase/layout). */
13
+ page: (page, options) => ({
14
+ kind: "page",
15
+ page,
16
+ ...options
17
+ }),
18
+ /** An address outside the admin, opened in a new tab: `https:`, `http:` or `mailto:`. */
19
+ link: (label, href, options = {}) => {
20
+ if (!isMenuHref(href)) throw new Error(`Bottom bar link "${label}": href must start with https://, http:// or mailto:`);
21
+ return {
22
+ kind: "link",
23
+ label,
24
+ href,
25
+ ...options
26
+ };
27
+ }
28
+ };
29
+ /**
30
+ * Tabs at the bottom of the screen on phones, for the users holding one of `roles`. Export one per group of roles; a
31
+ * role belongs to one bottom bar. `label` names the bar where someone with several switches between them.
32
+ */
33
+ const bottomBar = (options, build) => {
34
+ const model = {
35
+ label: options.label,
36
+ roles: [...options.roles],
37
+ items: build(items)
38
+ };
39
+ return { toBottomBarModel: () => structuredClone(model) };
40
+ };
41
+ /** The bottom bar of someone working as `role`: the one that names it, since a role belongs to one bar. */
42
+ const bottomBarFor = (bars, role) => role === void 0 ? void 0 : bars.find((bar) => bar.roles.includes(role));
43
+ //#endregion
44
+ export { bottomBar, bottomBarFor, maxBottomBarItems };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ActionModel, ActionRun, ChartGranularity, ChartModel, ChartRange, CheckedFilter, CompareOp, DatePreset, DurationLiteral, DurationUnit, EventModel, EventOperation, FieldFormat, FieldModel, FieldPath, FieldType, FieldViewModel, FileFieldModel, FilterError, FilterErrorCode, FilterExpr, FilterOf, FilterValue, FilterWidgetModel, KeyValue, LayoutItemModel, 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, BottomBarItemModel, BottomBarModel, ChartGranularity, ChartModel, ChartRange, CheckedFilter, CompareOp, DatePreset, DurationLiteral, DurationUnit, EventModel, EventOperation, FieldFormat, FieldModel, FieldPath, FieldType, FieldViewModel, FileFieldModel, FilterError, FilterErrorCode, FilterExpr, FilterOf, FilterValue, FilterWidgetModel, KeyValue, LayoutItemModel, 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";
@@ -14,6 +14,8 @@ import { enumLabel } from "./enum-label.js";
14
14
  import { SearchTerm, matchedSearchField, matchesSearch, searchTerms, termMatches } from "./search-match.js";
15
15
  import { defaultRecentLimit, navRecentErrors, statusTones } from "./nav-recent.js";
16
16
  import { UserMenuSource, userMenu } from "./user-menu.js";
17
+ import { BottomBarSource, bottomBar, bottomBarFor, maxBottomBarItems } from "./bottom-bar.js";
18
+ import { BottomBarNames, bottomBarErrors } from "./bottom-bar-errors.js";
17
19
  import { layout } from "./layout.js";
18
20
  import { KeyType, decodeKey, encodeKey, keyTypes } from "./keys.js";
19
21
  import { FilterLimits, FilterParse, parseFilter } from "./filter/parse.js";
@@ -33,4 +35,4 @@ import "./access/index.js";
33
35
  import { AssistantAction, AssistantActionRequest, AssistantCardPart, AssistantDiff, AssistantEvent, AssistantMessage, AssistantMessageRequest, AssistantPart, AssistantState, AssistantStep, AssistantStepState, AssistantTablePart, AssistantTextPart, AssistantTone, AssistantWidgetPart } from "./assistant/protocol.js";
34
36
  import { applyAssistantEvent, emptyAssistantState } from "./assistant/apply-event.js";
35
37
  import { readEventStream } from "./assistant/event-stream.js";
36
- export { type AccessAction, type AccessContext, type AccessFn, type AccessResult, type AccessSource, type AccessUser, type ActionModel, type ActionRun, 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 Capability, type CapabilityAction, type CapabilityScope, type ChartGranularity, type ChartModel, type ChartRange, type CheckResult, type CheckedFilter, type CompareOp, 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 FieldRule, type FieldType, type FieldViewModel, type FileField, type FileFieldModel, type FileProcessor, type FileProcessorInput, type FilterError, type FilterErrorCode, type FilterExpr, type FilterLimits, type FilterOf, type FilterParse, type FilterValue, type FilterWidgetModel, type InferRecord, type KeyType, type KeyValue, type LayoutItemModel, type ListModel, type ListQuery, type Literal, type NavModel, type NavRecentModel, type NowValue, type OrderByCheck, type OrderByItem, type OrderByParse, type RecordKey, type RelatedModel, type ResolveOptions, type ResolvedAccess, type ResourceModel, 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, accessWarnings, applyAssistantEvent, checkEventFilter, checkFilter, checkOrderBy, checkRecord, checkedAccept, checkedProvider, createWhere, decodeKey, defaultRecentLimit, defineRoles, emptyAssistantState, encodeKey, enumLabel, evaluateFilter, f, fieldsUsedBy, keyTypes, layout as l, matchedSearchField, matchesSearch, navRecentErrors, parseFilter, parseOrderBy, parseSize, pickView, printFilter, printOrderBy, readEventStream, resolveAccess, resource, restrictModel, rule, searchTerms, statusTones, termMatches, userMenu, view, webhookResources, where };
38
+ export { type AccessAction, type AccessContext, type AccessFn, type AccessResult, type AccessSource, type AccessUser, type ActionModel, type ActionRun, 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 CapabilityScope, type ChartGranularity, type ChartModel, type ChartRange, type CheckResult, type CheckedFilter, type CompareOp, 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 FieldRule, type FieldType, type FieldViewModel, type FileField, type FileFieldModel, type FileProcessor, type FileProcessorInput, type FilterError, type FilterErrorCode, type FilterExpr, type FilterLimits, type FilterOf, type FilterParse, type FilterValue, type FilterWidgetModel, type InferRecord, type KeyType, type KeyValue, type LayoutItemModel, type ListModel, type ListQuery, type Literal, type NavModel, type NavRecentModel, type NowValue, type OrderByCheck, type OrderByItem, type OrderByParse, type RecordKey, type RelatedModel, type ResolveOptions, type ResolvedAccess, type ResourceModel, 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, accessWarnings, applyAssistantEvent, bottomBar, bottomBarErrors, bottomBarFor, checkEventFilter, checkFilter, checkOrderBy, checkRecord, checkedAccept, checkedProvider, createWhere, decodeKey, defaultRecentLimit, defineRoles, emptyAssistantState, encodeKey, enumLabel, evaluateFilter, f, fieldsUsedBy, keyTypes, layout as l, matchedSearchField, matchesSearch, maxBottomBarItems, navRecentErrors, parseFilter, parseOrderBy, parseSize, pickView, printFilter, printOrderBy, readEventStream, resolveAccess, resource, restrictModel, rule, searchTerms, statusTones, termMatches, userMenu, view, webhookResources, where };
package/dist/index.js CHANGED
@@ -16,6 +16,8 @@ import { webhookResources } from "./webhooks/webhook-resources.js";
16
16
  import { enumLabel } from "./enum-label.js";
17
17
  import { matchedSearchField, matchesSearch, searchTerms, termMatches } from "./search-match.js";
18
18
  import { userMenu } from "./user-menu.js";
19
+ import { bottomBar, bottomBarFor, maxBottomBarItems } from "./bottom-bar.js";
20
+ import { bottomBarErrors } from "./bottom-bar-errors.js";
19
21
  import { decodeKey, encodeKey, keyTypes } from "./keys.js";
20
22
  import { rule } from "./access/rule.js";
21
23
  import { defineRoles } from "./access/roles.js";
@@ -23,4 +25,4 @@ import { pickView } from "./access/pick-view.js";
23
25
  import { restrictModel } from "./access/restrict.js";
24
26
  import { applyAssistantEvent, emptyAssistantState } from "./assistant/apply-event.js";
25
27
  import { readEventStream } from "./assistant/event-stream.js";
26
- export { accessWarnings, applyAssistantEvent, checkEventFilter, checkFilter, checkOrderBy, checkRecord, checkedAccept, checkedProvider, createWhere, decodeKey, defaultRecentLimit, defineRoles, emptyAssistantState, encodeKey, enumLabel, evaluateFilter, f, fieldsUsedBy, keyTypes, layout as l, matchedSearchField, matchesSearch, navRecentErrors, parseFilter, parseOrderBy, parseSize, pickView, printFilter, printOrderBy, readEventStream, resolveAccess, resource, restrictModel, rule, searchTerms, statusTones, termMatches, userMenu, view, webhookResources, where };
28
+ export { accessWarnings, applyAssistantEvent, bottomBar, bottomBarErrors, bottomBarFor, checkEventFilter, checkFilter, checkOrderBy, checkRecord, checkedAccept, checkedProvider, createWhere, decodeKey, defaultRecentLimit, defineRoles, emptyAssistantState, encodeKey, enumLabel, evaluateFilter, f, fieldsUsedBy, keyTypes, layout as l, matchedSearchField, matchesSearch, maxBottomBarItems, navRecentErrors, parseFilter, parseOrderBy, parseSize, pickView, printFilter, printOrderBy, readEventStream, resolveAccess, resource, restrictModel, rule, searchTerms, statusTones, termMatches, userMenu, view, webhookResources, where };
@@ -0,0 +1,5 @@
1
+ //#region src/menu-href.ts
2
+ /** Where a menu link may point: a web or mail address outside the admin, never `javascript:` or a path inside it. */
3
+ const isMenuHref = (href) => /^(https?:\/\/|mailto:)/i.test(href);
4
+ //#endregion
5
+ export { isMenuHref };
package/dist/model.d.ts CHANGED
@@ -218,6 +218,29 @@ export type UserMenuItemModel = {
218
218
  export type UserMenuModel = {
219
219
  items: UserMenuItemModel[];
220
220
  };
221
+ /** A tab of a bottom bar on phones: icon above an explicit label. */
222
+ export type BottomBarItemModel = {
223
+ kind: 'resource';
224
+ resource: string;
225
+ label: string;
226
+ icon?: string;
227
+ } | {
228
+ kind: 'page';
229
+ page: string;
230
+ label: string;
231
+ icon?: string;
232
+ } | {
233
+ kind: 'link';
234
+ label: string;
235
+ href: string;
236
+ icon?: string;
237
+ };
238
+ /** A bottom bar for the users holding one of `roles`; `label` names it in the role view switcher. */
239
+ export type BottomBarModel = {
240
+ label: string;
241
+ roles: string[];
242
+ items: BottomBarItemModel[];
243
+ };
221
244
  /**
222
245
  * The title replaces `title` in search results; `subtitle` is the second line unless the search matched another search
223
246
  * field, which then shows instead. Without a subtitle, the first search field not in the title is the default.
package/dist/user-menu.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { isMenuHref } from "./menu-href.js";
1
2
  //#region src/user-menu.ts
2
3
  const items = {
3
4
  /** Opens the resource's list. A resource in the user menu is left out of the sidebar. */
@@ -14,7 +15,7 @@ const items = {
14
15
  }),
15
16
  /** An address outside the admin, opened in a new tab: `https:`, `http:` or `mailto:`. */
16
17
  link: (label, href, options = {}) => {
17
- if (!/^(https?:\/\/|mailto:)/i.test(href)) throw new Error(`User menu link "${label}": href must start with https://, http:// or mailto:`);
18
+ if (!isMenuHref(href)) throw new Error(`User menu link "${label}": href must start with https://, http:// or mailto:`);
18
19
  return {
19
20
  kind: "link",
20
21
  label,
@@ -13,28 +13,28 @@ export declare const webhookResources: (schema: string, { deliveryLog }?: {
13
13
  }) => {
14
14
  webhookDeliveryLog?: ResourceBuilder<{
15
15
  readonly id: Field<string>;
16
- readonly subscriptionId: Field<string | number>;
17
- readonly tenantId: Field<string | null>;
18
- readonly eventId: Field<string>;
19
- readonly eventType: Field<string>;
16
+ readonly subscription_id: Field<string | number>;
17
+ readonly tenant_id: Field<string | null>;
18
+ readonly event_id: Field<string>;
19
+ readonly event_type: Field<string>;
20
20
  readonly status: Field<"failed" | "delivered">;
21
21
  readonly attempt: Field<number>;
22
- readonly statusCode: Field<number | null>;
22
+ readonly status_code: Field<number | null>;
23
23
  readonly response: Field<string | null>;
24
- readonly durationMs: Field<number>;
24
+ readonly duration_ms: Field<number>;
25
25
  readonly at: Field<string>;
26
26
  }, Ref<"id", string>> | undefined;
27
27
  webhookDeliveryLogView?: ViewBuilder<ResourceBuilder<{
28
28
  readonly id: Field<string>;
29
- readonly subscriptionId: Field<string | number>;
30
- readonly tenantId: Field<string | null>;
31
- readonly eventId: Field<string>;
32
- readonly eventType: Field<string>;
29
+ readonly subscription_id: Field<string | number>;
30
+ readonly tenant_id: Field<string | null>;
31
+ readonly event_id: Field<string>;
32
+ readonly event_type: Field<string>;
33
33
  readonly status: Field<"failed" | "delivered">;
34
34
  readonly attempt: Field<number>;
35
- readonly statusCode: Field<number | null>;
35
+ readonly status_code: Field<number | null>;
36
36
  readonly response: Field<string | null>;
37
- readonly durationMs: Field<number>;
37
+ readonly duration_ms: Field<number>;
38
38
  readonly at: Field<string>;
39
39
  }, Ref<"id", string>>> | undefined;
40
40
  webhookSubscriptions: ResourceBuilder<{
@@ -47,18 +47,18 @@ export declare const webhookResources: (schema: string, { deliveryLog }?: {
47
47
  readonly payload: Field<"full" | "thin">;
48
48
  readonly enabled: Field<boolean>;
49
49
  readonly secret: Field<string>;
50
- readonly previousSecret: null;
51
- readonly previousSecretUntil: null;
52
- readonly tenantId: Field<string | null>;
53
- readonly ownerId: Field<string | null>;
54
- readonly disabledReason: Field<string | null>;
55
- readonly lastSuccessAt: Field<string | null>;
56
- readonly failingSince: Field<string | null>;
57
- readonly createdAt: Field<string>;
58
- readonly updatedAt: Field<string>;
59
- readonly rotateSecret: Field<boolean>;
60
- readonly sendTest: Field<boolean>;
61
- readonly resendFailed: Field<boolean>;
50
+ readonly previous_secret: null;
51
+ readonly previous_secret_until: null;
52
+ readonly tenant_id: Field<string | null>;
53
+ readonly owner_id: Field<string | null>;
54
+ readonly disabled_reason: Field<string | null>;
55
+ readonly last_success_at: Field<string | null>;
56
+ readonly failing_since: Field<string | null>;
57
+ readonly created_at: Field<string>;
58
+ readonly updated_at: Field<string>;
59
+ readonly rotate_secret: Field<boolean>;
60
+ readonly send_test: Field<boolean>;
61
+ readonly resend_failed: Field<boolean>;
62
62
  }, Ref<"id", string>>;
63
63
  webhookSubscriptionsView: ViewBuilder<ResourceBuilder<{
64
64
  readonly id: Field<string>;
@@ -70,43 +70,43 @@ export declare const webhookResources: (schema: string, { deliveryLog }?: {
70
70
  readonly payload: Field<"full" | "thin">;
71
71
  readonly enabled: Field<boolean>;
72
72
  readonly secret: Field<string>;
73
- readonly previousSecret: null;
74
- readonly previousSecretUntil: null;
75
- readonly tenantId: Field<string | null>;
76
- readonly ownerId: Field<string | null>;
77
- readonly disabledReason: Field<string | null>;
78
- readonly lastSuccessAt: Field<string | null>;
79
- readonly failingSince: Field<string | null>;
80
- readonly createdAt: Field<string>;
81
- readonly updatedAt: Field<string>;
82
- readonly rotateSecret: Field<boolean>;
83
- readonly sendTest: Field<boolean>;
84
- readonly resendFailed: Field<boolean>;
73
+ readonly previous_secret: null;
74
+ readonly previous_secret_until: null;
75
+ readonly tenant_id: Field<string | null>;
76
+ readonly owner_id: Field<string | null>;
77
+ readonly disabled_reason: Field<string | null>;
78
+ readonly last_success_at: Field<string | null>;
79
+ readonly failing_since: Field<string | null>;
80
+ readonly created_at: Field<string>;
81
+ readonly updated_at: Field<string>;
82
+ readonly rotate_secret: Field<boolean>;
83
+ readonly send_test: Field<boolean>;
84
+ readonly resend_failed: Field<boolean>;
85
85
  }, Ref<"id", string>>>;
86
86
  webhookDeliveries: ResourceBuilder<{
87
87
  readonly id: Field<string>;
88
- readonly subscriptionId: Field<string | number>;
89
- readonly tenantId: Field<string | null>;
90
- readonly eventType: Field<string>;
91
- readonly eventId: Field<string>;
88
+ readonly subscription_id: Field<string | number>;
89
+ readonly tenant_id: Field<string | null>;
90
+ readonly event_type: Field<string>;
91
+ readonly event_id: Field<string>;
92
92
  readonly status: Field<"waiting" | "failed">;
93
93
  readonly attempt: Field<number>;
94
- readonly nextAttempt: Field<string | null>;
95
- readonly lastError: Field<string | null>;
96
- readonly createdAt: Field<string>;
94
+ readonly next_attempt: Field<string | null>;
95
+ readonly last_error: Field<string | null>;
96
+ readonly created_at: Field<string>;
97
97
  readonly resend: Field<boolean>;
98
98
  }, Ref<"id", string>>;
99
99
  webhookDeliveriesView: ViewBuilder<ResourceBuilder<{
100
100
  readonly id: Field<string>;
101
- readonly subscriptionId: Field<string | number>;
102
- readonly tenantId: Field<string | null>;
103
- readonly eventType: Field<string>;
104
- readonly eventId: Field<string>;
101
+ readonly subscription_id: Field<string | number>;
102
+ readonly tenant_id: Field<string | null>;
103
+ readonly event_type: Field<string>;
104
+ readonly event_id: Field<string>;
105
105
  readonly status: Field<"waiting" | "failed">;
106
106
  readonly attempt: Field<number>;
107
- readonly nextAttempt: Field<string | null>;
108
- readonly lastError: Field<string | null>;
109
- readonly createdAt: Field<string>;
107
+ readonly next_attempt: Field<string | null>;
108
+ readonly last_error: Field<string | null>;
109
+ readonly created_at: Field<string>;
110
110
  readonly resend: Field<boolean>;
111
111
  }, Ref<"id", string>>>;
112
112
  };
@@ -4,7 +4,7 @@ import { layout } from "../layout.js";
4
4
  import { view } from "../view.js";
5
5
  //#region src/webhooks/webhook-resources.ts
6
6
  /** Webhook subscriptions: a row per subscription someone made in the admin app, scoped to their tenant. */
7
- const subscriptionsResource = (schema) => resource("webhookSubscriptions").table(`${schema}.subscriptions`).fields({
7
+ const subscriptionsResource = (schema) => resource("webhook_subscriptions").table(`${schema}.subscriptions`).fields({
8
8
  id: f.uuid().readOnly().dbDefault(),
9
9
  name: f.text().min(1).max(100).filterable().sortable(),
10
10
  events: f.text().min(1).max(2e3),
@@ -14,20 +14,20 @@ const subscriptionsResource = (schema) => resource("webhookSubscriptions").table
14
14
  payload: f.enum(["full", "thin"]).default("full"),
15
15
  enabled: f.boolean().default(true).filterable(),
16
16
  secret: f.text().sensitive().readOnly().dbDefault(),
17
- previousSecret: null,
18
- previousSecretUntil: null,
19
- tenantId: f.text().optional().readOnly(),
20
- ownerId: f.text().optional().readOnly().dbDefault(),
21
- disabledReason: f.text().optional().readOnly(),
22
- lastSuccessAt: f.timestamp().optional().readOnly().sortable(),
23
- failingSince: f.timestamp().optional().readOnly(),
24
- createdAt: f.timestamp().readOnly().dbDefault().sortable(),
25
- updatedAt: f.timestamp().readOnly().dbDefault(),
26
- rotateSecret: f.boolean().default(false),
27
- sendTest: f.boolean().default(false),
28
- resendFailed: f.boolean().default(false)
29
- }).primaryKey((r) => r.id).tenant((r) => r.tenantId).owner((r) => r.ownerId).search((r) => [r.name, r.url]);
30
- const subscriptionsView = view("webhookSubscriptions").names({
17
+ previous_secret: null,
18
+ previous_secret_until: null,
19
+ tenant_id: f.text().optional().readOnly(),
20
+ owner_id: f.text().optional().readOnly().dbDefault(),
21
+ disabled_reason: f.text().optional().readOnly(),
22
+ last_success_at: f.timestamp().optional().readOnly().sortable(),
23
+ failing_since: f.timestamp().optional().readOnly(),
24
+ created_at: f.timestamp().readOnly().dbDefault().sortable(),
25
+ updated_at: f.timestamp().readOnly().dbDefault(),
26
+ rotate_secret: f.boolean().default(false),
27
+ send_test: f.boolean().default(false),
28
+ resend_failed: f.boolean().default(false)
29
+ }).primaryKey((r) => r.id).tenant((r) => r.tenant_id).owner((r) => r.owner_id).search((r) => [r.name, r.url]);
30
+ const subscriptionsView = view("webhook_subscriptions").names({
31
31
  singular: "Webhook subscription",
32
32
  plural: "Webhook subscriptions"
33
33
  }).icon("webhook").title((r) => r.name).help("Sends the app's events to a URL as they happen, signed with Standard Webhooks. It delivers as its owner: only the records and fields they may read.").fields((r) => ({
@@ -40,18 +40,18 @@ const subscriptionsView = view("webhookSubscriptions").names({
40
40
  thin: "Thin"
41
41
  }),
42
42
  secret: r.secret.help("Receivers check the webhook-signature header with it"),
43
- disabledReason: r.disabledReason.label("Disabled because"),
44
- lastSuccessAt: r.lastSuccessAt.label("Last success"),
45
- failingSince: r.failingSince.label("Failing since")
43
+ disabled_reason: r.disabled_reason.label("Disabled because"),
44
+ last_success_at: r.last_success_at.label("Last success"),
45
+ failing_since: r.failing_since.label("Failing since")
46
46
  })).list((r) => ({
47
47
  columns: [
48
48
  r.name,
49
49
  r.events,
50
50
  r.url,
51
51
  r.enabled,
52
- r.lastSuccessAt
52
+ r.last_success_at
53
53
  ],
54
- sort: [[r.createdAt, "desc"]]
54
+ sort: [[r.created_at, "desc"]]
55
55
  })).layout((r) => [
56
56
  layout.section("Subscription", [
57
57
  r.name,
@@ -64,38 +64,38 @@ const subscriptionsView = view("webhookSubscriptions").names({
64
64
  ]),
65
65
  layout.section("Signing", [r.secret]),
66
66
  layout.sidebar([
67
- r.lastSuccessAt,
68
- r.failingSince,
69
- r.disabledReason,
70
- r.createdAt
67
+ r.last_success_at,
68
+ r.failing_since,
69
+ r.disabled_reason,
70
+ r.created_at
71
71
  ]),
72
72
  layout.related("Waiting and failed deliveries", {
73
- resource: "webhookDeliveries",
74
- field: "subscriptionId",
73
+ resource: "webhook_deliveries",
74
+ field: "subscription_id",
75
75
  columns: [
76
- "eventType",
76
+ "event_type",
77
77
  "status",
78
78
  "attempt",
79
- "nextAttempt",
80
- "lastError"
79
+ "next_attempt",
80
+ "last_error"
81
81
  ]
82
82
  })
83
83
  ]).actions((a) => [
84
- a.update("sendTest", {
84
+ a.update("send_test", {
85
85
  label: "Send test event",
86
86
  icon: "send",
87
- set: { sendTest: true }
87
+ set: { send_test: true }
88
88
  }),
89
- a.update("resendFailed", {
89
+ a.update("resend_failed", {
90
90
  label: "Resend failed",
91
91
  icon: "rotate-ccw",
92
- set: { resendFailed: true },
92
+ set: { resend_failed: true },
93
93
  confirm: "Try every failed delivery of this subscription once more?"
94
94
  }),
95
- a.update("rotateSecret", {
95
+ a.update("rotate_secret", {
96
96
  label: "Rotate secret",
97
97
  icon: "key-round",
98
- set: { rotateSecret: true },
98
+ set: { rotate_secret: true },
99
99
  confirm: "Make a new secret? The old one keeps signing too for 24 hours."
100
100
  }),
101
101
  a.update("disable", {
@@ -105,51 +105,51 @@ const subscriptionsView = view("webhookSubscriptions").names({
105
105
  })
106
106
  ]);
107
107
  /** The deliveries of webhook subscriptions that wait for a retry or failed for good: delivery jobs, not a table. */
108
- const deliveriesResource = (schema) => resource("webhookDeliveries").table(`${schema}.deliveries`).fields({
108
+ const deliveriesResource = (schema) => resource("webhook_deliveries").table(`${schema}.deliveries`).fields({
109
109
  id: f.uuid().readOnly(),
110
- subscriptionId: f.relation("webhookSubscriptions").readOnly().filterable(),
111
- tenantId: f.text().optional().readOnly(),
112
- eventType: f.text().readOnly().filterable().sortable(),
113
- eventId: f.text().readOnly().filterable(),
110
+ subscription_id: f.relation("webhook_subscriptions").readOnly().filterable(),
111
+ tenant_id: f.text().optional().readOnly(),
112
+ event_type: f.text().readOnly().filterable().sortable(),
113
+ event_id: f.text().readOnly().filterable(),
114
114
  status: f.enum(["waiting", "failed"]).readOnly().filterable(),
115
115
  attempt: f.integer().readOnly(),
116
- nextAttempt: f.timestamp().optional().readOnly().sortable(),
117
- lastError: f.text().optional().readOnly(),
118
- createdAt: f.timestamp().readOnly().sortable(),
116
+ next_attempt: f.timestamp().optional().readOnly().sortable(),
117
+ last_error: f.text().optional().readOnly(),
118
+ created_at: f.timestamp().readOnly().sortable(),
119
119
  resend: f.boolean()
120
- }).primaryKey((r) => r.id).tenant((r) => r.tenantId).access({
120
+ }).primaryKey((r) => r.id).tenant((r) => r.tenant_id).access({
121
121
  create: () => false,
122
122
  delete: () => false
123
123
  });
124
- const deliveriesView = view("webhookDeliveries").names({
124
+ const deliveriesView = view("webhook_deliveries").names({
125
125
  singular: "Webhook delivery",
126
126
  plural: "Webhook deliveries"
127
- }).icon("send").title((r) => r.eventType).help("Deliveries that wait for their next try or failed for good. A delivery leaves the list once it succeeds.").fields((r) => ({
128
- eventType: r.eventType.label("Event"),
129
- eventId: r.eventId.label("Event id").format("code"),
130
- nextAttempt: r.nextAttempt.label("Next try"),
131
- lastError: r.lastError.label("Last error"),
127
+ }).icon("send").title((r) => r.event_type).help("Deliveries that wait for their next try or failed for good. A delivery leaves the list once it succeeds.").fields((r) => ({
128
+ event_type: r.event_type.label("Event"),
129
+ event_id: r.event_id.label("Event id").format("code"),
130
+ next_attempt: r.next_attempt.label("Next try"),
131
+ last_error: r.last_error.label("Last error"),
132
132
  attempt: r.attempt.label("Tries")
133
133
  })).list((r) => ({
134
134
  columns: [
135
- r.eventType,
136
- r.subscriptionId,
135
+ r.event_type,
136
+ r.subscription_id,
137
137
  r.status,
138
138
  r.attempt,
139
- r.nextAttempt,
140
- r.lastError
139
+ r.next_attempt,
140
+ r.last_error
141
141
  ],
142
- sort: [[r.createdAt, "desc"]]
142
+ sort: [[r.created_at, "desc"]]
143
143
  })).layout((r) => [layout.section("Delivery", [
144
- r.subscriptionId,
145
- r.eventType,
146
- r.eventId,
147
- r.lastError
144
+ r.subscription_id,
145
+ r.event_type,
146
+ r.event_id,
147
+ r.last_error
148
148
  ]), layout.sidebar([
149
149
  r.status,
150
150
  r.attempt,
151
- r.nextAttempt,
152
- r.createdAt
151
+ r.next_attempt,
152
+ r.created_at
153
153
  ])]).actions((a) => [a.update("resend", {
154
154
  label: "Resend",
155
155
  icon: "rotate-ccw",
@@ -157,39 +157,39 @@ const deliveriesView = view("webhookDeliveries").names({
157
157
  confirm: "Try this delivery once more, from now?"
158
158
  })]);
159
159
  /** Every try of every webhook subscription's deliveries, for 30 days (`deliveryLog: true`). */
160
- const deliveryLogResource = (schema) => resource("webhookDeliveryLog").table(`${schema}.delivery_log`).fields({
160
+ const deliveryLogResource = (schema) => resource("webhook_delivery_log").table(`${schema}.delivery_log`).fields({
161
161
  id: f.bigint().readOnly(),
162
- subscriptionId: f.relation("webhookSubscriptions").readOnly().filterable(),
163
- tenantId: f.text().optional().readOnly(),
164
- eventId: f.text().readOnly().filterable(),
165
- eventType: f.text().readOnly().filterable().sortable(),
162
+ subscription_id: f.relation("webhook_subscriptions").readOnly().filterable(),
163
+ tenant_id: f.text().optional().readOnly(),
164
+ event_id: f.text().readOnly().filterable(),
165
+ event_type: f.text().readOnly().filterable().sortable(),
166
166
  status: f.enum(["delivered", "failed"]).readOnly().filterable(),
167
167
  attempt: f.integer().readOnly(),
168
- statusCode: f.integer().optional().readOnly().filterable(),
168
+ status_code: f.integer().optional().readOnly().filterable(),
169
169
  response: f.text().optional().readOnly(),
170
- durationMs: f.integer().readOnly(),
170
+ duration_ms: f.integer().readOnly(),
171
171
  at: f.timestamp().readOnly().filterable().sortable()
172
- }).primaryKey((r) => r.id).tenant((r) => r.tenantId).access({
172
+ }).primaryKey((r) => r.id).tenant((r) => r.tenant_id).access({
173
173
  create: () => false,
174
174
  update: () => false,
175
175
  delete: () => false
176
176
  });
177
- const deliveryLogView = view("webhookDeliveryLog").names({
177
+ const deliveryLogView = view("webhook_delivery_log").names({
178
178
  singular: "Webhook delivery log entry",
179
179
  plural: "Webhook delivery log"
180
- }).icon("scroll-text").title((r) => r.eventType).fields((r) => ({
181
- eventType: r.eventType.label("Event"),
182
- statusCode: r.statusCode.label("Status code"),
183
- durationMs: r.durationMs.label("Duration (ms)"),
180
+ }).icon("scroll-text").title((r) => r.event_type).fields((r) => ({
181
+ event_type: r.event_type.label("Event"),
182
+ status_code: r.status_code.label("Status code"),
183
+ duration_ms: r.duration_ms.label("Duration (ms)"),
184
184
  at: r.at.label("When")
185
185
  })).list((r) => ({
186
186
  columns: [
187
187
  r.at,
188
- r.eventType,
189
- r.subscriptionId,
188
+ r.event_type,
189
+ r.subscription_id,
190
190
  r.status,
191
- r.statusCode,
192
- r.durationMs
191
+ r.status_code,
192
+ r.duration_ms
193
193
  ],
194
194
  sort: [[r.at, "desc"]]
195
195
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/schema",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Resource, field, view and access definitions for Protobase configs.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {