@protobase/schema 0.13.4 → 0.14.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.
Files changed (57) hide show
  1. package/dist/access/capability.d.ts +3 -0
  2. package/dist/access/index.d.ts +3 -3
  3. package/dist/access/resolve.d.ts +13 -0
  4. package/dist/access/role-entry.d.ts +5 -0
  5. package/dist/access/roles.d.ts +14 -0
  6. package/dist/access/roles.js +11 -0
  7. package/dist/access/rule.d.ts +10 -0
  8. package/dist/access/rule.js +10 -0
  9. package/dist/access/types.d.ts +11 -0
  10. package/dist/assistant/protocol.d.ts +67 -2
  11. package/dist/bottom-bar-errors.d.ts +3 -0
  12. package/dist/bottom-bar.d.ts +3 -1
  13. package/dist/bottom-bar.js +2 -1
  14. package/dist/events/event-helpers.d.ts +41 -8
  15. package/dist/events/event-helpers.js +1 -3
  16. package/dist/field-ref.d.ts +1 -0
  17. package/dist/field.d.ts +54 -1
  18. package/dist/field.js +16 -0
  19. package/dist/fields.d.ts +31 -0
  20. package/dist/fields.js +31 -0
  21. package/dist/file-field.d.ts +6 -1
  22. package/dist/file-field.js +6 -1
  23. package/dist/files/file-options.d.ts +17 -0
  24. package/dist/filter/check.d.ts +5 -0
  25. package/dist/filter/evaluate.d.ts +1 -0
  26. package/dist/filter/order-by.d.ts +14 -0
  27. package/dist/filter/order-by.js +2 -0
  28. package/dist/filter/parse.d.ts +16 -2
  29. package/dist/filter/parse.js +8 -2
  30. package/dist/filter/where.d.ts +61 -0
  31. package/dist/filter/where.js +34 -0
  32. package/dist/index.d.ts +16 -24
  33. package/dist/index.js +6 -18
  34. package/dist/internal.d.ts +17 -0
  35. package/dist/internal.js +17 -0
  36. package/dist/keys.d.ts +1 -0
  37. package/dist/layout.d.ts +15 -0
  38. package/dist/layout.js +15 -0
  39. package/dist/model.d.ts +344 -6
  40. package/dist/refs.d.ts +6 -0
  41. package/dist/relation-field.d.ts +5 -0
  42. package/dist/relation-field.js +5 -0
  43. package/dist/resource-types.d.ts +18 -0
  44. package/dist/resource.d.ts +94 -6
  45. package/dist/resource.js +75 -2
  46. package/dist/user-menu.d.ts +5 -1
  47. package/dist/user-menu.js +4 -1
  48. package/dist/view-actions.d.ts +1 -0
  49. package/dist/view-displays.d.ts +3 -0
  50. package/dist/view-field.d.ts +14 -1
  51. package/dist/view-field.js +7 -0
  52. package/dist/view-widgets.d.ts +7 -0
  53. package/dist/view-widgets.js +7 -0
  54. package/dist/view.d.ts +52 -4
  55. package/dist/view.js +39 -2
  56. package/dist/webhooks/webhook-resources.js +1 -1
  57. package/package.json +3 -2
package/dist/view.js CHANGED
@@ -1,18 +1,25 @@
1
1
  import { createRefs, ref } from "./refs.js";
2
- import { displayErrors, displayFields, displays } from "./view-displays.js";
3
2
  import { navRecentErrors } from "./nav-recent.js";
4
3
  import { actions } from "./view-actions.js";
4
+ import { displayErrors, displayFields, displays } from "./view-displays.js";
5
5
  import { FieldView } from "./view-field.js";
6
6
  import { widgets } from "./view-widgets.js";
7
7
  //#region src/view.ts
8
+ /**
9
+ * A view of a resource, as `view(...)` starts it: how the admin shows it. Each method returns a new view, so one view
10
+ * can build on another. See [UI config](website/src/content/docs/reference/ui-config.mdx).
11
+ */
8
12
  var ViewBuilder = class ViewBuilder {
9
13
  state;
14
+ /** @internal */
10
15
  constructor(state) {
11
16
  this.state = state;
12
17
  }
18
+ /** What a record and the records are called, such as "New repair" and "Repairs"; the resource name in words by default. */
13
19
  names(names) {
14
20
  return this.next({ names });
15
21
  }
22
+ /** An icon name carried in `/meta`, for apps that draw their own shell; the admin picks sidebar icons by resource name. */
16
23
  icon(icon) {
17
24
  return this.next({ icon });
18
25
  }
@@ -36,13 +43,15 @@ var ViewBuilder = class ViewBuilder {
36
43
  ...subtitle && { subtitle: subtitle.name }
37
44
  } });
38
45
  }
39
- /** Where the resource sits in the sidebar; `recent` lists a few of its records under the entry (see https://docs.protobase.net/reference/sidebar/). */
46
+ /** Where the resource sits in the sidebar; `recent` lists a few of its records under the entry (see [Sidebar](website/src/content/docs/reference/sidebar.md#recent-records)). */
40
47
  nav(nav) {
41
48
  return this.next({ nav });
42
49
  }
50
+ /** A line under the list's title. */
43
51
  help(help) {
44
52
  return this.next({ help });
45
53
  }
54
+ /** Hints per field, such as `{ total: r.total.prefix('€').decimals(2) }`; calls add up. */
46
55
  fields(build) {
47
56
  const built = build(createRefs((name) => new FieldView(name)));
48
57
  const fields = Object.fromEntries(Object.values(built).map((v) => [v.name, v.props]));
@@ -68,12 +77,21 @@ var ViewBuilder = class ViewBuilder {
68
77
  if (errors.length > 0) throw new Error(`View "${this.state.resource}": ${errors.join("; ")}`);
69
78
  return this.next({ list });
70
79
  }
80
+ /**
81
+ * The filter widgets above the list, in order, each on a `.filterable()` field: `w.facets`, `w.dateRange`, `w.range`,
82
+ * `w.toggle` and `w.flags`. Together they write the list's `?filter=`.
83
+ */
71
84
  filters(build) {
72
85
  return this.next({ filters: build(this.refs(), widgets) });
73
86
  }
87
+ /**
88
+ * The record page, as items of `l` in order: sections, sidebar cards, related records, maps and custom components.
89
+ * Without it the page shows one section with every field.
90
+ */
74
91
  layout(build) {
75
92
  return this.next({ layout: build(this.refs()) });
76
93
  }
94
+ /** A chart of records per `granularity` over a date or timestamp `field` above the list, following its filters. */
77
95
  chart(build) {
78
96
  const { field, range, granularity } = build(this.refs());
79
97
  return this.next({ chart: {
@@ -82,9 +100,14 @@ var ViewBuilder = class ViewBuilder {
82
100
  granularity
83
101
  } });
84
102
  }
103
+ /** Where the record page shows that it saved: a toast (the default) or the Save button. */
85
104
  saveFeedback(saveFeedback) {
86
105
  return this.next({ saveFeedback });
87
106
  }
107
+ /**
108
+ * The named actions of the record page's action rail, which composed pages can put on buttons too: `a.update`,
109
+ * `a.remove` and `a.link` need no code, `a.action` runs a handler the app registers.
110
+ */
88
111
  actions(build) {
89
112
  return this.next({ actions: build(actions) });
90
113
  }
@@ -115,6 +138,20 @@ var ViewBuilder = class ViewBuilder {
115
138
  });
116
139
  }
117
140
  };
141
+ /**
142
+ * Starts the view of a resource: how the admin shows it. Pass the resource's type, so every field reference (`r.status`)
143
+ * is checked against it. See [UI config](website/src/content/docs/reference/ui-config.mdx).
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * import { view } from '@protobase/schema'
148
+ * import type { repairs } from './data'
149
+ *
150
+ * export const repairsView = view<typeof repairs>('repairs')
151
+ * .names({ singular: 'Repair', plural: 'Repairs' })
152
+ * .list((r) => ({ columns: [r.number, r.status, r.booked_on], sort: [[r.booked_on, 'desc']] }))
153
+ * ```
154
+ */
118
155
  const view = (resource) => new ViewBuilder({
119
156
  resource,
120
157
  fields: {},
@@ -1,7 +1,7 @@
1
1
  import { f } from "../fields.js";
2
2
  import { resource } from "../resource.js";
3
- import { layout } from "../layout.js";
4
3
  import { view } from "../view.js";
4
+ import { layout } from "../layout.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
7
  const subscriptionsResource = (schema) => resource("webhook_subscriptions").table(`${schema}.subscriptions`).fields({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/schema",
3
- "version": "0.13.4",
3
+ "version": "0.14.1",
4
4
  "description": "Resource, field, view and access definitions for Protobase configs.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -15,7 +15,8 @@
15
15
  "node": ">=22.12.0"
16
16
  },
17
17
  "exports": {
18
- ".": "./dist/index.js"
18
+ ".": "./dist/index.js",
19
+ "./internal": "./dist/internal.js"
19
20
  },
20
21
  "types": "./dist/index.d.ts",
21
22
  "files": [