@protobase/schema 0.68.0 → 0.68.2

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.
@@ -11,7 +11,8 @@ export type AddressCheck = {
11
11
  createPages?: ReadonlySet<string>;
12
12
  };
13
13
  /**
14
- * What is wrong with a link's address against these models: an unknown resource or page, a `{field}` the record it sits
14
+ * What is wrong with a link's address against these models: an unknown resource or page, a filter, order or values
15
+ * beside a resource taken from the record (`'{field}'`), a `{field}` the record it sits
15
16
  * on does not have, a filter or order naming fields the resource does not have, or create values for fields it does not
16
17
  * have, unless its view opens a create page, which reads them. Empty when it can be followed.
17
18
  */
@@ -1,4 +1,4 @@
1
- import { addressPlaceholders } from "./address-template.js";
1
+ import { addressPlaceholders, resourceField } from "./address-template.js";
2
2
  import { parseFilter } from "./filter/parse.js";
3
3
  import { checkFilter } from "./filter/check.js";
4
4
  import { checkOrderBy, parseOrderBy } from "./filter/order-by.js";
@@ -30,7 +30,8 @@ const orderErrors = (model, orderBy) => {
30
30
  return checked.ok ? [] : checked.errors.map((error) => `orderBy: ${error.message}`);
31
31
  };
32
32
  /**
33
- * What is wrong with a link's address against these models: an unknown resource or page, a `{field}` the record it sits
33
+ * What is wrong with a link's address against these models: an unknown resource or page, a filter, order or values
34
+ * beside a resource taken from the record (`'{field}'`), a `{field}` the record it sits
34
35
  * on does not have, a filter or order naming fields the resource does not have, or create values for fields it does not
35
36
  * have, unless its view opens a create page, which reads them. Empty when it can be followed.
36
37
  */
@@ -39,6 +40,7 @@ const addressErrors = (to, { models, pages, source, createPages }) => {
39
40
  if (!source) return [`"{${name}}" takes a value from the record, but the link sits on none`];
40
41
  return Object.hasOwn(source.fields, name) ? [] : [`"{${name}}" is not a field of ${source.name}`];
41
42
  });
43
+ if (to.kind !== "page" && resourceField(to) !== void 0) return (to.kind === "list" ? to.filter !== void 0 || to.orderBy !== void 0 : to.kind === "create" && to.values !== void 0) ? [...placeholders, `a link whose resource comes from the record ("${to.resource}") names no filter, order or values`] : placeholders;
42
44
  switch (to.kind) {
43
45
  case "page": return pages && !pages.has(to.page) ? [`unknown page "${to.page}"`] : [];
44
46
  case "list":
@@ -1,10 +1,12 @@
1
1
  import { AppAddress } from "./model.js";
2
2
  //#region src/address-template.d.ts
3
+ /** The field a link's address takes its resource from, when its `resource` is only `{field}`, as `'{name}'`. */
4
+ export declare const resourceField: (to: AppAddress) => string | undefined;
3
5
  /** The fields whose values a link's address takes from the record, from its `{field}` placeholders. */
4
6
  export declare const addressPlaceholders: (to: AppAddress) => string[];
5
7
  /** The fields an href takes from the record, from its `{field}` placeholders. */
6
8
  export declare const hrefPlaceholders: (href: string) => string[];
7
- /** `to` with every `{field}` in its key, filter, order or values replaced by the record's value; a missing value becomes empty. */
9
+ /** `to` with every `{field}` in its resource, key, filter, order or values replaced by the record's value; a missing value becomes empty. */
8
10
  export declare const fillAddress: (to: AppAddress, record?: Record<string, unknown>) => AppAddress;
9
11
  /**
10
12
  * Whether an href leaves the app: it starts with a scheme (`https:`, `mailto:`) or `//`. A path inside the app is an
@@ -1,33 +1,40 @@
1
1
  //#region src/address-template.ts
2
2
  const placeholder = /\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
3
3
  const names = (text) => [...text.matchAll(placeholder)].map((match) => match[1]);
4
+ /** The field a link's address takes its resource from, when its `resource` is only `{field}`, as `'{name}'`. */
5
+ const resourceField = (to) => to.kind === "page" ? void 0 : /^\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(to.resource)?.[1];
4
6
  const templated = (to) => {
5
- if (to.kind === "record") return (Array.isArray(to.key) ? to.key : [to.key]).filter((part) => typeof part === "string");
6
- if (to.kind === "list") return [to.filter, to.orderBy].filter((part) => part !== void 0);
7
- if (to.kind === "create") return Object.values(to.values ?? {});
8
- return [];
7
+ if (to.kind === "page") return [];
8
+ const resource = resourceField(to) === void 0 ? [] : [to.resource];
9
+ if (to.kind === "record") return [...resource, ...(Array.isArray(to.key) ? to.key : [to.key]).filter((part) => typeof part === "string")];
10
+ if (to.kind === "list") return [...resource, ...[to.filter, to.orderBy].filter((part) => part !== void 0)];
11
+ return [...resource, ...Object.values(to.values ?? {})];
9
12
  };
10
13
  /** The fields whose values a link's address takes from the record, from its `{field}` placeholders. */
11
14
  const addressPlaceholders = (to) => [...new Set(templated(to).flatMap(names))];
12
15
  /** The fields an href takes from the record, from its `{field}` placeholders. */
13
16
  const hrefPlaceholders = (href) => [...new Set(names(href))];
14
17
  const fill = (text, record) => text.replace(placeholder, (_, name) => record[name] === null || record[name] === void 0 ? "" : String(record[name]));
15
- /** `to` with every `{field}` in its key, filter, order or values replaced by the record's value; a missing value becomes empty. */
18
+ /** `to` with every `{field}` in its resource, key, filter, order or values replaced by the record's value; a missing value becomes empty. */
16
19
  const fillAddress = (to, record = {}) => {
20
+ if (to.kind === "page") return to;
21
+ const resource = resourceField(to) === void 0 ? to.resource : fill(to.resource, record);
17
22
  if (to.kind === "record") {
18
23
  const part = (value) => typeof value === "string" ? fill(value, record) : value;
19
24
  return {
20
25
  ...to,
26
+ resource,
21
27
  key: Array.isArray(to.key) ? to.key.map(part) : part(to.key)
22
28
  };
23
29
  }
24
- if (to.kind === "create") return to.values ? {
30
+ if (to.kind === "create") return {
25
31
  ...to,
26
- values: Object.fromEntries(Object.entries(to.values).map(([name, value]) => [name, fill(value, record)]))
27
- } : to;
28
- if (to.kind !== "list") return to;
32
+ resource,
33
+ ...to.values && { values: Object.fromEntries(Object.entries(to.values).map(([name, value]) => [name, fill(value, record)])) }
34
+ };
29
35
  return {
30
36
  ...to,
37
+ resource,
31
38
  ...to.filter !== void 0 && { filter: fill(to.filter, record) },
32
39
  ...to.orderBy !== void 0 && { orderBy: fill(to.orderBy, record) }
33
40
  };
@@ -50,4 +57,4 @@ const linkActionError = (label, run) => {
50
57
  return label.includes("{host}") ? "the label names {host}, which only a link with an href has" : void 0;
51
58
  };
52
59
  //#endregion
53
- export { addressPlaceholders, appHrefError, fillAddress, hrefField, hrefPlaceholders, leavesApp, linkActionError };
60
+ export { addressPlaceholders, appHrefError, fillAddress, hrefField, hrefPlaceholders, leavesApp, linkActionError, resourceField };
@@ -19,7 +19,7 @@ import { PluginHost, PluginRequirement, inRange, pluginProblem } from "./plugin-
19
19
  import { redactSecrets } from "./redact-secrets.js";
20
20
  import { firstPartyCodeKey } from "./first-party-code.js";
21
21
  import { updateSetErrors, updateValues } from "./update-set.js";
22
- import { addressPlaceholders, appHrefError, fillAddress, hrefField, hrefPlaceholders, leavesApp, linkActionError } from "./address-template.js";
22
+ import { addressPlaceholders, appHrefError, fillAddress, hrefField, hrefPlaceholders, leavesApp, linkActionError, resourceField } from "./address-template.js";
23
23
  import { promptError, promptFields, renderPrompt } from "./ai-prompt.js";
24
24
  import { FormulaNode, parseFormula } from "./computed/formula.js";
25
25
  import { AddressCheck, addressErrors } from "./address-errors.js";
@@ -45,4 +45,4 @@ import { builtInFieldTypes } from "./built-in-field-types.js";
45
45
  import { CallCandidate, CallClientMessage, CallDescription, CallGuestLink, CallGuestRefusal, CallGuestState, CallLeftReason, CallLobbyGuest, CallMode, CallRemoteTrack, CallResume, CallRosterMember, CallServerMessage, CallTrackRequest, CallTrackSource, CallVideoLayer } from "./calls/call-protocol.js";
46
46
  import { guestCallsPath } from "./calls/call-guests.js";
47
47
  import { CallRing, callsChannelEvent, declineWord, ringNotice, ringsPath } from "./calls/call-rings.js";
48
- export { type AddressCheck, type Availability, type CallCandidate, type CallClientMessage, type CallDescription, type CallGuestLink, type CallGuestRefusal, type CallGuestState, type CallLeftReason, type CallLobbyGuest, type CallMode, type CallRemoteTrack, type CallResume, type CallRing, type CallRosterMember, type CallServerMessage, type CallTrackRequest, type CallTrackSource, type CallVideoLayer, type FormulaNode, type Locale, type MobileReleaseAnswer, type PersonStatus, type PluginHost, type PluginRequirement, type PropShapes, type RefShape, type ReleaseBinding, type SearchTerm, type StatusInput, type WorkflowTypeEntry, type WorkflowTypeList, actionConditionError, actionInputErrors, addressErrors, addressPlaceholders, apiOriginMeta, appHrefError, applyAssistantEvent, authBasePath, availabilities, boardErrors, bottomBarFor, builtInFieldTypes, callsChannelEvent, capacitorOrigin, cardPhotoLimit, chartFields, checkEventFilter, checkedAccept, checkedProvider, confirmationMinutes, datesErrors, declineWord, decodeKey, defaultRecentLimit, deviceIdParam, devicesPath, displayFields, emailCodeMinutes, emptyAssistantState, encodeKey, fieldRefsIn, fillAddress, firstPartyCodeKey, guestCallsPath, heldStatus, historyIdParam, historyIdPattern, historyPath, hrefField, hrefPlaceholders, humanize, inRange, isFieldRef, isGroupChart, isLocale, labelFieldOf, layoutItems, leavesApp, linkActionError, listColumnNames, locales, markFieldRefs, matchedSearchField, matchesSearch, maxStatusText, mobileReleaseBasePath, mobileReleaseParams, mobileReleasePath, mobileReleaseQuery, mobileReleasesPath, navRecentErrors, parseCapability, parseFormula, parseSize, parseTable, pickLocale, pluginProblem, promptError, promptFields, pruneByShape, pushRecord, readEventStream, recordTitle, recordTitleField, redactSecrets, releaseManifestFile, releaseStatementContext, releaseStatementFile, renderPrompt, ringNotice, ringsPath, searchTerms, serviceWorkerFile, shapes, shownInputs, statusPath, statusTextProblem, statusTones, tableDisplay, termMatches, unmarkFieldRefs, updateSetErrors, updateValues, viewOfList, webhookResources, workflowResources, workflowTypesPath };
48
+ export { type AddressCheck, type Availability, type CallCandidate, type CallClientMessage, type CallDescription, type CallGuestLink, type CallGuestRefusal, type CallGuestState, type CallLeftReason, type CallLobbyGuest, type CallMode, type CallRemoteTrack, type CallResume, type CallRing, type CallRosterMember, type CallServerMessage, type CallTrackRequest, type CallTrackSource, type CallVideoLayer, type FormulaNode, type Locale, type MobileReleaseAnswer, type PersonStatus, type PluginHost, type PluginRequirement, type PropShapes, type RefShape, type ReleaseBinding, type SearchTerm, type StatusInput, type WorkflowTypeEntry, type WorkflowTypeList, actionConditionError, actionInputErrors, addressErrors, addressPlaceholders, apiOriginMeta, appHrefError, applyAssistantEvent, authBasePath, availabilities, boardErrors, bottomBarFor, builtInFieldTypes, callsChannelEvent, capacitorOrigin, cardPhotoLimit, chartFields, checkEventFilter, checkedAccept, checkedProvider, confirmationMinutes, datesErrors, declineWord, decodeKey, defaultRecentLimit, deviceIdParam, devicesPath, displayFields, emailCodeMinutes, emptyAssistantState, encodeKey, fieldRefsIn, fillAddress, firstPartyCodeKey, guestCallsPath, heldStatus, historyIdParam, historyIdPattern, historyPath, hrefField, hrefPlaceholders, humanize, inRange, isFieldRef, isGroupChart, isLocale, labelFieldOf, layoutItems, leavesApp, linkActionError, listColumnNames, locales, markFieldRefs, matchedSearchField, matchesSearch, maxStatusText, mobileReleaseBasePath, mobileReleaseParams, mobileReleasePath, mobileReleaseQuery, mobileReleasesPath, navRecentErrors, parseCapability, parseFormula, parseSize, parseTable, pickLocale, pluginProblem, promptError, promptFields, pruneByShape, pushRecord, readEventStream, recordTitle, recordTitleField, redactSecrets, releaseManifestFile, releaseStatementContext, releaseStatementFile, renderPrompt, resourceField, ringNotice, ringsPath, searchTerms, serviceWorkerFile, shapes, shownInputs, statusPath, statusTextProblem, statusTones, tableDisplay, termMatches, unmarkFieldRefs, updateSetErrors, updateValues, viewOfList, webhookResources, workflowResources, workflowTypesPath };
package/dist/internal.js CHANGED
@@ -1,4 +1,4 @@
1
- import { addressPlaceholders, appHrefError, fillAddress, hrefField, hrefPlaceholders, leavesApp, linkActionError } from "./address-template.js";
1
+ import { addressPlaceholders, appHrefError, fillAddress, hrefField, hrefPlaceholders, leavesApp, linkActionError, resourceField } from "./address-template.js";
2
2
  import { promptError, promptFields, renderPrompt } from "./ai-prompt.js";
3
3
  import { parseFormula } from "./computed/formula.js";
4
4
  import { checkedAccept, checkedProvider, parseSize } from "./files/file-options.js";
@@ -44,4 +44,4 @@ import { listColumnNames } from "./list-columns.js";
44
44
  import { builtInFieldTypes } from "./built-in-field-types.js";
45
45
  import { guestCallsPath } from "./calls/call-guests.js";
46
46
  import { callsChannelEvent, declineWord, ringNotice, ringsPath } from "./calls/call-rings.js";
47
- export { actionConditionError, actionInputErrors, addressErrors, addressPlaceholders, apiOriginMeta, appHrefError, applyAssistantEvent, authBasePath, availabilities, boardErrors, bottomBarFor, builtInFieldTypes, callsChannelEvent, capacitorOrigin, cardPhotoLimit, chartFields, checkEventFilter, checkedAccept, checkedProvider, confirmationMinutes, datesErrors, declineWord, decodeKey, defaultRecentLimit, deviceIdParam, devicesPath, displayFields, emailCodeMinutes, emptyAssistantState, encodeKey, fieldRefsIn, fillAddress, firstPartyCodeKey, guestCallsPath, heldStatus, historyIdParam, historyIdPattern, historyPath, hrefField, hrefPlaceholders, humanize, inRange, isFieldRef, isGroupChart, isLocale, labelFieldOf, layoutItems, leavesApp, linkActionError, listColumnNames, locales, markFieldRefs, matchedSearchField, matchesSearch, maxStatusText, mobileReleaseBasePath, mobileReleaseParams, mobileReleasePath, mobileReleaseQuery, mobileReleasesPath, navRecentErrors, parseCapability, parseFormula, parseSize, parseTable, pickLocale, pluginProblem, promptError, promptFields, pruneByShape, pushRecord, readEventStream, recordTitle, recordTitleField, redactSecrets, releaseManifestFile, releaseStatementContext, releaseStatementFile, renderPrompt, ringNotice, ringsPath, searchTerms, serviceWorkerFile, shapes, shownInputs, statusPath, statusTextProblem, statusTones, tableDisplay, termMatches, unmarkFieldRefs, updateSetErrors, updateValues, viewOfList, webhookResources, workflowResources, workflowTypesPath };
47
+ export { actionConditionError, actionInputErrors, addressErrors, addressPlaceholders, apiOriginMeta, appHrefError, applyAssistantEvent, authBasePath, availabilities, boardErrors, bottomBarFor, builtInFieldTypes, callsChannelEvent, capacitorOrigin, cardPhotoLimit, chartFields, checkEventFilter, checkedAccept, checkedProvider, confirmationMinutes, datesErrors, declineWord, decodeKey, defaultRecentLimit, deviceIdParam, devicesPath, displayFields, emailCodeMinutes, emptyAssistantState, encodeKey, fieldRefsIn, fillAddress, firstPartyCodeKey, guestCallsPath, heldStatus, historyIdParam, historyIdPattern, historyPath, hrefField, hrefPlaceholders, humanize, inRange, isFieldRef, isGroupChart, isLocale, labelFieldOf, layoutItems, leavesApp, linkActionError, listColumnNames, locales, markFieldRefs, matchedSearchField, matchesSearch, maxStatusText, mobileReleaseBasePath, mobileReleaseParams, mobileReleasePath, mobileReleaseQuery, mobileReleasesPath, navRecentErrors, parseCapability, parseFormula, parseSize, parseTable, pickLocale, pluginProblem, promptError, promptFields, pruneByShape, pushRecord, readEventStream, recordTitle, recordTitleField, redactSecrets, releaseManifestFile, releaseStatementContext, releaseStatementFile, renderPrompt, resourceField, ringNotice, ringsPath, searchTerms, serviceWorkerFile, shapes, shownInputs, statusPath, statusTextProblem, statusTones, tableDisplay, termMatches, unmarkFieldRefs, updateSetErrors, updateValues, viewOfList, webhookResources, workflowResources, workflowTypesPath };
package/dist/model.d.ts CHANGED
@@ -317,6 +317,8 @@ export type FieldViewModel = {
317
317
  helpWhen?: HelpWhen;
318
318
  /** When the field shows on the record page: always, the default, only on its form or only on its read view. */
319
319
  when?: ShowWhen;
320
+ /** Left off the create form, so a create leaves it empty or to its default; the server refuses it on a field a create needs. */
321
+ notOnCreate?: true;
320
322
  /** The question a form or a list cell asks before the field's value first changes; cancelling keeps the value. */
321
323
  confirm?: string;
322
324
  /** How the value is shown. */
@@ -1157,6 +1159,8 @@ export type NavRecentModel = {
1157
1159
  export type NavModel = {
1158
1160
  /** Hide the resource from the sidebar, for line or link tables. */
1159
1161
  hidden?: boolean;
1162
+ /** Show the entry only to whoever the list offers New, for a list that is there to make records, such as the tables users add. */
1163
+ creatorsOnly?: true;
1160
1164
  /** The sidebar group it sits in; its database schema when omitted. */
1161
1165
  group?: string;
1162
1166
  /** Where it sorts within its group. */
@@ -27,6 +27,12 @@ export declare class FieldView<N extends string = string, V = unknown> {
27
27
  * view and locked form; `always` when omitted. Its lists, cards and filters show it either way.
28
28
  */
29
29
  when(when: ShowWhen): FieldView<N, V>;
30
+ /**
31
+ * Leaves the field off the create form, for one that makes sense only once the record exists, such as a choice among
32
+ * records added after it; the create leaves it empty or to its default, and the record page shows it as usual. The
33
+ * server stops at startup on a field a create needs: not optional and with no default.
34
+ */
35
+ notOnCreate(): FieldView<N, V>;
30
36
  /**
31
37
  * Asks `question` before a person changes the value in a form or a list cell, such as a flag that is easy to set by
32
38
  * mistake: once as the value first moves away from the saved one, not on every key. Cancelling keeps the value. See
@@ -33,6 +33,14 @@ var FieldView = class FieldView {
33
33
  return this.with({ when });
34
34
  }
35
35
  /**
36
+ * Leaves the field off the create form, for one that makes sense only once the record exists, such as a choice among
37
+ * records added after it; the create leaves it empty or to its default, and the record page shows it as usual. The
38
+ * server stops at startup on a field a create needs: not optional and with no default.
39
+ */
40
+ notOnCreate() {
41
+ return this.with({ notOnCreate: true });
42
+ }
43
+ /**
36
44
  * Asks `question` before a person changes the value in a form or a list cell, such as a flag that is easy to set by
37
45
  * mistake: once as the value first moves away from the saved one, not on every key. Cancelling keeps the value. See
38
46
  * [Confirming a change](docs/website/src/content/docs/reference/ui-config.mdx#confirming-a-change).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/schema",
3
- "version": "0.68.0",
3
+ "version": "0.68.2",
4
4
  "description": "Resource, field, view and access definitions for Protobase configs.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {