@panneau/protocol 5.0.0-alpha.15 → 5.0.0-alpha.16

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 (63) hide show
  1. package/dist/addresses.d.ts +23 -0
  2. package/dist/addresses.d.ts.map +1 -0
  3. package/dist/addresses.js +52 -0
  4. package/dist/addresses.js.map +1 -0
  5. package/dist/conformance/index.d.ts.map +1 -1
  6. package/dist/conformance/index.js +109 -0
  7. package/dist/conformance/index.js.map +1 -1
  8. package/dist/constants.d.ts +23 -2
  9. package/dist/constants.d.ts.map +1 -1
  10. package/dist/constants.js +51 -3
  11. package/dist/constants.js.map +1 -1
  12. package/dist/currencies.d.ts +22 -0
  13. package/dist/currencies.d.ts.map +1 -0
  14. package/dist/currencies.js +231 -0
  15. package/dist/currencies.js.map +1 -0
  16. package/dist/index.js +7 -4
  17. package/dist/links.d.ts +38 -0
  18. package/dist/links.d.ts.map +1 -0
  19. package/dist/links.js +65 -0
  20. package/dist/links.js.map +1 -0
  21. package/dist/lint.js +6 -2
  22. package/dist/lint.js.map +1 -1
  23. package/dist/mock/index.d.ts.map +1 -1
  24. package/dist/mock/index.js +11 -2
  25. package/dist/mock/index.js.map +1 -1
  26. package/dist/query.d.ts +4 -0
  27. package/dist/query.d.ts.map +1 -1
  28. package/dist/query.js +23 -7
  29. package/dist/query.js.map +1 -1
  30. package/dist/rules.d.ts +4 -1
  31. package/dist/rules.d.ts.map +1 -1
  32. package/dist/rules.js +165 -7
  33. package/dist/rules.js.map +1 -1
  34. package/dist/runtime/index.d.ts +3 -0
  35. package/dist/runtime/index.d.ts.map +1 -1
  36. package/dist/runtime/index.js +5 -2
  37. package/dist/schemas/action.d.ts +46 -1
  38. package/dist/schemas/action.d.ts.map +1 -1
  39. package/dist/schemas/api.d.ts +43 -3
  40. package/dist/schemas/api.d.ts.map +1 -1
  41. package/dist/schemas/api.js +35 -1
  42. package/dist/schemas/api.js.map +1 -1
  43. package/dist/schemas/definition.d.ts +93 -3
  44. package/dist/schemas/definition.d.ts.map +1 -1
  45. package/dist/schemas/field.d.ts +193 -2
  46. package/dist/schemas/field.d.ts.map +1 -1
  47. package/dist/schemas/field.js +91 -7
  48. package/dist/schemas/field.js.map +1 -1
  49. package/dist/schemas/index.d.ts +445 -14
  50. package/dist/schemas/index.d.ts.map +1 -1
  51. package/dist/schemas/index.js +14 -4
  52. package/dist/schemas/index.js.map +1 -1
  53. package/dist/schemas/list.d.ts +2 -2
  54. package/dist/schemas/resource.d.ts +93 -3
  55. package/dist/schemas/resource.d.ts.map +1 -1
  56. package/dist/validate.d.ts +2 -1
  57. package/dist/validate.d.ts.map +1 -1
  58. package/dist/validate.js +18 -4
  59. package/dist/validate.js.map +1 -1
  60. package/package.json +1 -1
  61. package/schema/boot.schema.json +164 -2
  62. package/schema/definition.schema.json +164 -2
  63. package/schema/openapi.json +611 -5
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["// Constants of the protocol. This module doesn't import zod, so that the main entry point stays\n// light: see `src/index.ts`.\n\n/** Built-in action ids. */\nexport const BUILT_IN_ACTIONS = [\n 'show',\n 'edit',\n 'duplicate',\n 'delete',\n 'restore',\n 'export',\n 'import',\n] as const;\nexport type BuiltInAction = (typeof BUILT_IN_ACTIONS)[number];\n\n/**\n * Built-in `link` actions (decision 0040). Without a `url` or a `route`, the client resolves them\n * to its own routes, and labels them itself when they have no `label`.\n */\nexport const BUILT_IN_LINK_ACTIONS = ['show', 'edit'] as const;\nexport type BuiltInLinkAction = (typeof BUILT_IN_LINK_ACTIONS)[number];\n\n/** Whether an action id is one of the built-in links, `show` and `edit`. */\nexport function isBuiltInLink(id: string): id is BuiltInLinkAction {\n return (BUILT_IN_LINK_ACTIONS as readonly string[]).includes(id);\n}\n\n/**\n * Built-in item actions, in their default order (decision 0040). Every resource has them without\n * declaring them, and clients show each one on the items whose abilities allow it\n * (`ITEM_ACTION_ABILITIES`). A resource's `itemActions` picks some of them, in its order.\n */\nexport const BUILT_IN_ITEM_ACTIONS = ['show', 'edit', 'duplicate', 'delete'] as const;\nexport type BuiltInItemAction = (typeof BUILT_IN_ITEM_ACTIONS)[number];\n\n/** The ability of an item that each built-in item action needs: `true`, or the action is hidden. */\nexport const ITEM_ACTION_ABILITIES: Readonly<Record<BuiltInItemAction, string>> = {\n show: 'view',\n edit: 'update',\n duplicate: 'duplicate',\n delete: 'delete',\n};\n\n/** Whether an action id is one of the built-in item actions. */\nexport function isBuiltInItemAction(id: string): id is BuiltInItemAction {\n return (BUILT_IN_ITEM_ACTIONS as readonly string[]).includes(id);\n}\n\n/** Field types every Panneau frontend renders. Plugins add others. */\nexport const BUILT_IN_FIELD_TYPES = [\n 'text',\n 'textarea',\n 'richtext',\n 'number',\n 'boolean',\n 'date',\n 'datetime',\n 'time',\n 'select',\n 'email',\n 'url',\n 'color',\n 'media',\n 'image',\n 'relation',\n 'group',\n 'repeater',\n 'slug',\n 'tel',\n 'range',\n 'duration',\n 'json',\n 'tags',\n 'embed',\n 'location',\n 'country',\n 'region',\n] as const;\nexport type BuiltInFieldType = (typeof BUILT_IN_FIELD_TYPES)[number];\n\n/** Validation rules that both frontends and backends check. */\nexport const PORTABLE_RULES = [\n 'required',\n 'min',\n 'max',\n 'pattern',\n 'email',\n 'url',\n 'json',\n 'tel',\n 'in',\n 'accept',\n 'maxSize',\n 'before',\n 'after',\n 'crop',\n] as const;\nexport type PortableRule = (typeof PORTABLE_RULES)[number];\n\n/** Layout node types every Panneau frontend renders. */\nexport const BUILT_IN_LAYOUT_NODE_TYPES = [\n 'row',\n 'column',\n 'section',\n 'tabs',\n 'tab',\n 'sidebar',\n 'field',\n 'text',\n 'component',\n] as const;\nexport type BuiltInLayoutNodeType = (typeof BUILT_IN_LAYOUT_NODE_TYPES)[number];\n\n/** List layouts every Panneau frontend renders. Plugins add others. */\nexport const BUILT_IN_LIST_LAYOUTS = ['table', 'cards', 'gallery', 'calendar'] as const;\nexport type BuiltInListLayout = (typeof BUILT_IN_LIST_LAYOUTS)[number];\n\n/**\n * Id of the element that holds the boot config in the page: a\n * `<script type=\"application/json\" id=\"panneau-boot\">` element whose text is the JSON object.\n */\nexport const BOOT_CONFIG_ELEMENT_ID = 'panneau-boot';\n\n/** The elements a block style of a `richtext` field can apply to. */\nexport const RICH_TEXT_STYLE_ELEMENTS = [\n 'p',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'blockquote',\n 'ul',\n 'ol',\n 'li',\n] as const;\n\n/** An element a block style of a `richtext` field can apply to. */\nexport type RichTextStyleElement = (typeof RICH_TEXT_STYLE_ELEMENTS)[number];\n\n/**\n * The first segments of the client routes under `basePath` that Panneau keeps for itself\n * (decision 0019). A param of the context can't be named like one: the context is a prefix of\n * the routes, `{basePath}/{name}/{value}/…` (decision 0045).\n */\nexport const RESERVED_ROUTE_SEGMENTS = [\n 'resources',\n 'pages',\n 'media',\n 'search',\n 'account',\n 'auth',\n] as const;\n\n/** The request header that carries the values of the current context (decision 0045). */\nexport const CONTEXT_HEADER = 'Panneau-Context';\n\n/** The type of the `403` problem of a value of the context that the user can't use. */\nexport const CONTEXT_PROBLEM_TYPE = 'urn:panneau:problem:context';\n\n/**\n * The type of the `403` problem of a user whose email address isn't verified yet, with\n * `auth.emailVerification` (decision 0048). The app shows a page that sends a new link.\n */\nexport const EMAIL_UNVERIFIED_PROBLEM_TYPE = 'urn:panneau:problem:email-unverified';\n\n/**\n * The type of the `403` problem of a user who must have two-factor authentication and hasn't set\n * it up (decision 0049). The app shows its setup.\n */\nexport const TWO_FACTOR_REQUIRED_PROBLEM_TYPE = 'urn:panneau:problem:two-factor-required';\n\n/**\n * The type of the `423` problem of an operation that needs the password, when it wasn't confirmed\n * recently (decision 0049): the app confirms it with `POST /auth/password/confirm`, then runs the\n * operation again.\n */\nexport const PASSWORD_CONFIRMATION_PROBLEM_TYPE = 'urn:panneau:problem:password-confirmation';\n\n/**\n * The paths of the auth pages of the app, under `basePath` (decision 0048), that the links of the\n * backend's emails open:\n *\n * - `resetPassword`, with the `token` and the `email` of a password reset in the query;\n * - `verifyEmail`, with the `token` of an email verification in the query.\n */\n/**\n * The query param of a login with an OAuth provider that failed (decision 0052): the backend comes\n * back to the base path of the app with one of `AUTH_ERROR_CODES`, which the login page says.\n */\nexport const AUTH_ERROR_PARAM = 'authError';\n\n/**\n * Why a login with an OAuth provider failed (decision 0052): the provider failed or the user\n * cancelled, it gave no verified email address, the address isn't in an allowed domain, or no user\n * with this address is allowed in.\n */\nexport const AUTH_ERROR_CODES = ['provider', 'email', 'domain', 'access'] as const;\n\n/** A code of `AUTH_ERROR_CODES`. */\nexport type AuthErrorCode = (typeof AUTH_ERROR_CODES)[number];\n\nexport const AUTH_PAGE_PATHS = {\n resetPassword: 'auth/reset-password',\n verifyEmail: 'auth/verify-email',\n} as const;\n"],"mappings":";;AAIA,IAAa,mBAAmB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;;;;AAOA,IAAa,wBAAwB,CAAC,QAAQ,MAAM;;AAIpD,SAAgB,cAAc,IAAqC;CAC/D,OAAQ,sBAA4C,SAAS,EAAE;AACnE;;;;;;AAOA,IAAa,wBAAwB;CAAC;CAAQ;CAAQ;CAAa;AAAQ;;AAI3E,IAAa,wBAAqE;CAC9E,MAAM;CACN,MAAM;CACN,WAAW;CACX,QAAQ;AACZ;;AAGA,SAAgB,oBAAoB,IAAqC;CACrE,OAAQ,sBAA4C,SAAS,EAAE;AACnE;;AAGA,IAAa,uBAAuB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,iBAAiB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,6BAA6B;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,wBAAwB;CAAC;CAAS;CAAS;CAAW;AAAU;;;;;AAO7E,IAAa,yBAAyB;;AAGtC,IAAa,2BAA2B;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;;;;;AAUA,IAAa,0BAA0B;CACnC;CACA;CACA;CACA;CACA;CACA;AACJ;;AAGA,IAAa,iBAAiB;;AAG9B,IAAa,uBAAuB;;;;;AAMpC,IAAa,gCAAgC;;;;;AAM7C,IAAa,mCAAmC;;;;;;AAOhD,IAAa,qCAAqC;;;;;;;;;;;;AAalD,IAAa,mBAAmB;;;;;;AAOhC,IAAa,mBAAmB;CAAC;CAAY;CAAS;CAAU;AAAQ;AAKxE,IAAa,kBAAkB;CAC3B,eAAe;CACf,aAAa;AACjB"}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["// Constants of the protocol. This module doesn't import zod, so that the main entry point stays\n// light: see `src/index.ts`.\n\n/** Built-in action ids. */\nexport const BUILT_IN_ACTIONS = [\n 'show',\n 'edit',\n 'duplicate',\n 'delete',\n 'restore',\n 'export',\n 'import',\n] as const;\nexport type BuiltInAction = (typeof BUILT_IN_ACTIONS)[number];\n\n/**\n * Built-in `link` actions (decision 0040). Without a `url` or a `route`, the client resolves them\n * to its own routes, and labels them itself when they have no `label`.\n */\nexport const BUILT_IN_LINK_ACTIONS = ['show', 'edit'] as const;\nexport type BuiltInLinkAction = (typeof BUILT_IN_LINK_ACTIONS)[number];\n\n/** Whether an action id is one of the built-in links, `show` and `edit`. */\nexport function isBuiltInLink(id: string): id is BuiltInLinkAction {\n return (BUILT_IN_LINK_ACTIONS as readonly string[]).includes(id);\n}\n\n/**\n * Built-in item actions, in their default order (decision 0040). Every resource has them without\n * declaring them, and clients show each one on the items whose abilities allow it\n * (`ITEM_ACTION_ABILITIES`). A resource's `itemActions` picks some of them, in its order.\n */\nexport const BUILT_IN_ITEM_ACTIONS = ['show', 'edit', 'duplicate', 'delete'] as const;\nexport type BuiltInItemAction = (typeof BUILT_IN_ITEM_ACTIONS)[number];\n\n/** The ability of an item that each built-in item action needs: `true`, or the action is hidden. */\nexport const ITEM_ACTION_ABILITIES: Readonly<Record<BuiltInItemAction, string>> = {\n show: 'view',\n edit: 'update',\n duplicate: 'duplicate',\n delete: 'delete',\n};\n\n/** Whether an action id is one of the built-in item actions. */\nexport function isBuiltInItemAction(id: string): id is BuiltInItemAction {\n return (BUILT_IN_ITEM_ACTIONS as readonly string[]).includes(id);\n}\n\n/** Field types every Panneau frontend renders. Plugins add others. */\nexport const BUILT_IN_FIELD_TYPES = [\n 'text',\n 'textarea',\n 'richtext',\n 'number',\n 'boolean',\n 'date',\n 'datetime',\n 'time',\n 'select',\n 'email',\n 'url',\n 'color',\n 'media',\n 'image',\n 'relation',\n 'group',\n 'repeater',\n 'slug',\n 'tel',\n 'range',\n 'duration',\n 'json',\n 'tags',\n 'embed',\n 'location',\n 'country',\n 'region',\n 'address',\n 'link',\n 'daterange',\n 'money',\n] as const;\nexport type BuiltInFieldType = (typeof BUILT_IN_FIELD_TYPES)[number];\n\n/** Validation rules that both frontends and backends check. */\nexport const PORTABLE_RULES = [\n 'required',\n 'min',\n 'max',\n 'pattern',\n 'email',\n 'url',\n 'json',\n 'tel',\n 'postalCode',\n 'daterange',\n 'money',\n 'in',\n 'accept',\n 'maxSize',\n 'before',\n 'after',\n 'crop',\n 'providers',\n] as const;\nexport type PortableRule = (typeof PORTABLE_RULES)[number];\n\n/** The parts of an `address` value, in the order of the field (decision 0054). */\nexport const ADDRESS_PARTS = ['country', 'street', 'unit', 'city', 'region', 'postalCode'] as const;\n/** A part of an `address` value. */\nexport type AddressPart = (typeof ADDRESS_PARTS)[number];\n\n/** The parts a filled address must have, without `settings.required` (decision 0054). */\nexport const DEFAULT_ADDRESS_REQUIRED_PARTS: readonly AddressPart[] = ['street', 'city', 'country'];\n\n/** The built-in types of `link` values (decision 0055). Sites add others in `settings.types`. */\nexport const BUILT_IN_LINK_TYPES = ['url', 'page', 'email', 'tel', 'file'] as const;\n/** A built-in type of `link` values. */\nexport type BuiltInLinkType = (typeof BUILT_IN_LINK_TYPES)[number];\n\n/** Which bounds of a `daterange` value can be `null` (decision 0053). */\nexport const DATE_RANGE_OPEN_BOUNDS = ['start', 'end', 'both'] as const;\nexport type DateRangeOpenBound = (typeof DATE_RANGE_OPEN_BOUNDS)[number];\n\n/** Layout node types every Panneau frontend renders. */\nexport const BUILT_IN_LAYOUT_NODE_TYPES = [\n 'row',\n 'column',\n 'section',\n 'tabs',\n 'tab',\n 'sidebar',\n 'field',\n 'text',\n 'component',\n] as const;\nexport type BuiltInLayoutNodeType = (typeof BUILT_IN_LAYOUT_NODE_TYPES)[number];\n\n/** List layouts every Panneau frontend renders. Plugins add others. */\nexport const BUILT_IN_LIST_LAYOUTS = ['table', 'cards', 'gallery', 'calendar'] as const;\nexport type BuiltInListLayout = (typeof BUILT_IN_LIST_LAYOUTS)[number];\n\n/**\n * Id of the element that holds the boot config in the page: a\n * `<script type=\"application/json\" id=\"panneau-boot\">` element whose text is the JSON object.\n */\nexport const BOOT_CONFIG_ELEMENT_ID = 'panneau-boot';\n\n/**\n * The units of a `duration` field, from the smallest to the largest: of its value\n * (`settings.unit`), and of the parts its input shows (`settings.precision` and\n * `settings.largestUnit`). A day is 24 hours: no calendar is involved.\n */\nexport const DURATION_UNITS = ['seconds', 'minutes', 'hours', 'days'] as const;\n\n/** A unit of a `duration` field. */\nexport type DurationUnit = (typeof DURATION_UNITS)[number];\n\n/** The elements a block style of a `richtext` field can apply to. */\nexport const RICH_TEXT_STYLE_ELEMENTS = [\n 'p',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'blockquote',\n 'ul',\n 'ol',\n 'li',\n] as const;\n\n/** An element a block style of a `richtext` field can apply to. */\nexport type RichTextStyleElement = (typeof RICH_TEXT_STYLE_ELEMENTS)[number];\n\n/**\n * The first segments of the client routes under `basePath` that Panneau keeps for itself\n * (decision 0019). A param of the context can't be named like one: the context is a prefix of\n * the routes, `{basePath}/{name}/{value}/…` (decision 0045).\n */\nexport const RESERVED_ROUTE_SEGMENTS = [\n 'resources',\n 'pages',\n 'media',\n 'search',\n 'account',\n 'auth',\n] as const;\n\n/** The request header that carries the values of the current context (decision 0045). */\nexport const CONTEXT_HEADER = 'Panneau-Context';\n\n/** The type of the `403` problem of a value of the context that the user can't use. */\nexport const CONTEXT_PROBLEM_TYPE = 'urn:panneau:problem:context';\n\n/**\n * The type of the `403` problem of a user whose email address isn't verified yet, with\n * `auth.emailVerification` (decision 0048). The app shows a page that sends a new link.\n */\nexport const EMAIL_UNVERIFIED_PROBLEM_TYPE = 'urn:panneau:problem:email-unverified';\n\n/**\n * The type of the `403` problem of a user who must have two-factor authentication and hasn't set\n * it up (decision 0049). The app shows its setup.\n */\nexport const TWO_FACTOR_REQUIRED_PROBLEM_TYPE = 'urn:panneau:problem:two-factor-required';\n\n/**\n * The type of the `423` problem of an operation that needs the password, when it wasn't confirmed\n * recently (decision 0049): the app confirms it with `POST /auth/password/confirm`, then runs the\n * operation again.\n */\nexport const PASSWORD_CONFIRMATION_PROBLEM_TYPE = 'urn:panneau:problem:password-confirmation';\n\n/**\n * The paths of the auth pages of the app, under `basePath` (decision 0048), that the links of the\n * backend's emails open:\n *\n * - `resetPassword`, with the `token` and the `email` of a password reset in the query;\n * - `verifyEmail`, with the `token` of an email verification in the query.\n */\n/**\n * The query param of a login with an OAuth provider that failed (decision 0052): the backend comes\n * back to the base path of the app with one of `AUTH_ERROR_CODES`, which the login page says.\n */\nexport const AUTH_ERROR_PARAM = 'authError';\n\n/**\n * Why a login with an OAuth provider failed (decision 0052): the provider failed or the user\n * cancelled, it gave no verified email address, the address isn't in an allowed domain, or no user\n * with this address is allowed in.\n */\nexport const AUTH_ERROR_CODES = ['provider', 'email', 'domain', 'access'] as const;\n\n/** A code of `AUTH_ERROR_CODES`. */\nexport type AuthErrorCode = (typeof AUTH_ERROR_CODES)[number];\n\nexport const AUTH_PAGE_PATHS = {\n resetPassword: 'auth/reset-password',\n verifyEmail: 'auth/verify-email',\n} as const;\n"],"mappings":";;AAIA,IAAa,mBAAmB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;;;;AAOA,IAAa,wBAAwB,CAAC,QAAQ,MAAM;;AAIpD,SAAgB,cAAc,IAAqC;CAC/D,OAAQ,sBAA4C,SAAS,EAAE;AACnE;;;;;;AAOA,IAAa,wBAAwB;CAAC;CAAQ;CAAQ;CAAa;AAAQ;;AAI3E,IAAa,wBAAqE;CAC9E,MAAM;CACN,MAAM;CACN,WAAW;CACX,QAAQ;AACZ;;AAGA,SAAgB,oBAAoB,IAAqC;CACrE,OAAQ,sBAA4C,SAAS,EAAE;AACnE;;AAGA,IAAa,uBAAuB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,iBAAiB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,gBAAgB;CAAC;CAAW;CAAU;CAAQ;CAAQ;CAAU;AAAY;;AAKzF,IAAa,iCAAyD;CAAC;CAAU;CAAQ;AAAS;;AAGlG,IAAa,sBAAsB;CAAC;CAAO;CAAQ;CAAS;CAAO;AAAM;;AAKzE,IAAa,yBAAyB;CAAC;CAAS;CAAO;AAAM;;AAI7D,IAAa,6BAA6B;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,wBAAwB;CAAC;CAAS;CAAS;CAAW;AAAU;;;;;AAO7E,IAAa,yBAAyB;;;;;;AAOtC,IAAa,iBAAiB;CAAC;CAAW;CAAW;CAAS;AAAM;;AAMpE,IAAa,2BAA2B;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;;;;;AAUA,IAAa,0BAA0B;CACnC;CACA;CACA;CACA;CACA;CACA;AACJ;;AAGA,IAAa,iBAAiB;;AAG9B,IAAa,uBAAuB;;;;;AAMpC,IAAa,gCAAgC;;;;;AAM7C,IAAa,mCAAmC;;;;;;AAOhD,IAAa,qCAAqC;;;;;;;;;;;;AAalD,IAAa,mBAAmB;;;;;;AAOhC,IAAa,mBAAmB;CAAC;CAAY;CAAS;CAAU;AAAQ;AAKxE,IAAa,kBAAkB;CAC3B,eAAe;CACf,aAAa;AACjB"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The ISO 4217 codes of the currencies a `money` value can have (decision 0053): the currencies in
3
+ * use, and a few withdrawn recently, which stored amounts may still have. Funds, precious metals
4
+ * and test codes are left out.
5
+ */
6
+ export declare const CURRENCY_CODES: readonly ["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLE", "SLL", "SOS", "SRD", "SSP", "STN", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VED", "VES", "VND", "VUV", "WST", "XAF", "XCD", "XCG", "XOF", "XPF", "YER", "ZAR", "ZMW", "ZWG", "ZWL"];
7
+ export type CurrencyCode = (typeof CURRENCY_CODES)[number];
8
+ /** Whether a string is the ISO 4217 code of a currency that Panneau knows (`CAD`). */
9
+ export declare function isCurrencyCode(code: unknown): code is CurrencyCode;
10
+ /**
11
+ * The number of digits of the minor unit of a currency, its ISO 4217 exponent: 2 for `CAD` (cents),
12
+ * 0 for `JPY`, 3 for `KWD`. A `money` amount is an integer in that unit.
13
+ */
14
+ export declare function getCurrencyDigits(code: string): number;
15
+ /**
16
+ * Turns an amount in major units, as typed (`12.5`), into minor units (`1250`), rounded half away
17
+ * from zero, without the errors of floating point (`1.005` gives `101`).
18
+ */
19
+ export declare function toMinorUnits(amount: number, currency: string): number;
20
+ /** Turns an amount in minor units (`1250`) into major units (`12.5`). */
21
+ export declare function fromMinorUnits(amount: number, currency: string): number;
22
+ //# sourceMappingURL=currencies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currencies.d.ts","sourceRoot":"","sources":["../src/currencies.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,cAAc,knCAcjB,CAAC;AACX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAmC3D,sFAAsF;AACtF,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,YAAY,CAElE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKrE;AAED,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGvE"}
@@ -0,0 +1,231 @@
1
+ //#region src/currencies.ts
2
+ /**
3
+ * The ISO 4217 codes of the currencies a `money` value can have (decision 0053): the currencies in
4
+ * use, and a few withdrawn recently, which stored amounts may still have. Funds, precious metals
5
+ * and test codes are left out.
6
+ */
7
+ var CURRENCY_CODES = [
8
+ "AED",
9
+ "AFN",
10
+ "ALL",
11
+ "AMD",
12
+ "ANG",
13
+ "AOA",
14
+ "ARS",
15
+ "AUD",
16
+ "AWG",
17
+ "AZN",
18
+ "BAM",
19
+ "BBD",
20
+ "BDT",
21
+ "BGN",
22
+ "BHD",
23
+ "BIF",
24
+ "BMD",
25
+ "BND",
26
+ "BOB",
27
+ "BRL",
28
+ "BSD",
29
+ "BTN",
30
+ "BWP",
31
+ "BYN",
32
+ "BZD",
33
+ "CAD",
34
+ "CDF",
35
+ "CHF",
36
+ "CLP",
37
+ "CNY",
38
+ "COP",
39
+ "CRC",
40
+ "CUC",
41
+ "CUP",
42
+ "CVE",
43
+ "CZK",
44
+ "DJF",
45
+ "DKK",
46
+ "DOP",
47
+ "DZD",
48
+ "EGP",
49
+ "ERN",
50
+ "ETB",
51
+ "EUR",
52
+ "FJD",
53
+ "FKP",
54
+ "GBP",
55
+ "GEL",
56
+ "GHS",
57
+ "GIP",
58
+ "GMD",
59
+ "GNF",
60
+ "GTQ",
61
+ "GYD",
62
+ "HKD",
63
+ "HNL",
64
+ "HRK",
65
+ "HTG",
66
+ "HUF",
67
+ "IDR",
68
+ "ILS",
69
+ "INR",
70
+ "IQD",
71
+ "IRR",
72
+ "ISK",
73
+ "JMD",
74
+ "JOD",
75
+ "JPY",
76
+ "KES",
77
+ "KGS",
78
+ "KHR",
79
+ "KMF",
80
+ "KPW",
81
+ "KRW",
82
+ "KWD",
83
+ "KYD",
84
+ "KZT",
85
+ "LAK",
86
+ "LBP",
87
+ "LKR",
88
+ "LRD",
89
+ "LSL",
90
+ "LYD",
91
+ "MAD",
92
+ "MDL",
93
+ "MGA",
94
+ "MKD",
95
+ "MMK",
96
+ "MNT",
97
+ "MOP",
98
+ "MRU",
99
+ "MUR",
100
+ "MVR",
101
+ "MWK",
102
+ "MXN",
103
+ "MYR",
104
+ "MZN",
105
+ "NAD",
106
+ "NGN",
107
+ "NIO",
108
+ "NOK",
109
+ "NPR",
110
+ "NZD",
111
+ "OMR",
112
+ "PAB",
113
+ "PEN",
114
+ "PGK",
115
+ "PHP",
116
+ "PKR",
117
+ "PLN",
118
+ "PYG",
119
+ "QAR",
120
+ "RON",
121
+ "RSD",
122
+ "RUB",
123
+ "RWF",
124
+ "SAR",
125
+ "SBD",
126
+ "SCR",
127
+ "SDG",
128
+ "SEK",
129
+ "SGD",
130
+ "SHP",
131
+ "SLE",
132
+ "SLL",
133
+ "SOS",
134
+ "SRD",
135
+ "SSP",
136
+ "STN",
137
+ "SVC",
138
+ "SYP",
139
+ "SZL",
140
+ "THB",
141
+ "TJS",
142
+ "TMT",
143
+ "TND",
144
+ "TOP",
145
+ "TRY",
146
+ "TTD",
147
+ "TWD",
148
+ "TZS",
149
+ "UAH",
150
+ "UGX",
151
+ "USD",
152
+ "UYU",
153
+ "UZS",
154
+ "VED",
155
+ "VES",
156
+ "VND",
157
+ "VUV",
158
+ "WST",
159
+ "XAF",
160
+ "XCD",
161
+ "XCG",
162
+ "XOF",
163
+ "XPF",
164
+ "YER",
165
+ "ZAR",
166
+ "ZMW",
167
+ "ZWG",
168
+ "ZWL"
169
+ ];
170
+ /**
171
+ * The currencies whose minor unit isn't a hundredth, by their exponent in ISO 4217. The CLDR, which
172
+ * `Intl.NumberFormat` follows, differs for a few cash currencies: amounts follow ISO 4217.
173
+ */
174
+ var CURRENCY_EXPONENTS = {
175
+ BIF: 0,
176
+ CLP: 0,
177
+ DJF: 0,
178
+ GNF: 0,
179
+ ISK: 0,
180
+ JPY: 0,
181
+ KMF: 0,
182
+ KRW: 0,
183
+ PYG: 0,
184
+ RWF: 0,
185
+ UGX: 0,
186
+ UYI: 0,
187
+ VND: 0,
188
+ VUV: 0,
189
+ XAF: 0,
190
+ XOF: 0,
191
+ XPF: 0,
192
+ BHD: 3,
193
+ IQD: 3,
194
+ JOD: 3,
195
+ KWD: 3,
196
+ LYD: 3,
197
+ OMR: 3,
198
+ TND: 3,
199
+ CLF: 4,
200
+ UYW: 4
201
+ };
202
+ /** Whether a string is the ISO 4217 code of a currency that Panneau knows (`CAD`). */
203
+ function isCurrencyCode(code) {
204
+ return typeof code === "string" && CURRENCY_CODES.includes(code);
205
+ }
206
+ /**
207
+ * The number of digits of the minor unit of a currency, its ISO 4217 exponent: 2 for `CAD` (cents),
208
+ * 0 for `JPY`, 3 for `KWD`. A `money` amount is an integer in that unit.
209
+ */
210
+ function getCurrencyDigits(code) {
211
+ return CURRENCY_EXPONENTS[code] ?? 2;
212
+ }
213
+ /**
214
+ * Turns an amount in major units, as typed (`12.5`), into minor units (`1250`), rounded half away
215
+ * from zero, without the errors of floating point (`1.005` gives `101`).
216
+ */
217
+ function toMinorUnits(amount, currency) {
218
+ const digits = getCurrencyDigits(currency);
219
+ const [mantissa = "0", exponent = "0"] = String(Math.abs(amount)).split("e");
220
+ const shifted = Number(`${mantissa}e${String(Number(exponent) + digits)}`);
221
+ return Math.sign(amount) * Math.round(shifted) || 0;
222
+ }
223
+ /** Turns an amount in minor units (`1250`) into major units (`12.5`). */
224
+ function fromMinorUnits(amount, currency) {
225
+ const digits = getCurrencyDigits(currency);
226
+ return Number(`${String(amount)}e-${String(digits)}`);
227
+ }
228
+ //#endregion
229
+ export { CURRENCY_CODES, fromMinorUnits, getCurrencyDigits, isCurrencyCode, toMinorUnits };
230
+
231
+ //# sourceMappingURL=currencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currencies.js","names":[],"sources":["../src/currencies.ts"],"sourcesContent":["/**\n * The ISO 4217 codes of the currencies a `money` value can have (decision 0053): the currencies in\n * use, and a few withdrawn recently, which stored amounts may still have. Funds, precious metals\n * and test codes are left out.\n */\nexport const CURRENCY_CODES = [\n 'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', 'BAM', 'BBD', 'BDT',\n 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN', 'BZD', 'CAD',\n 'CDF', 'CHF', 'CLP', 'CNY', 'COP', 'CRC', 'CUC', 'CUP', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP',\n 'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP', 'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF',\n 'GTQ', 'GYD', 'HKD', 'HNL', 'HRK', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK',\n 'JMD', 'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT', 'LAK',\n 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRU',\n 'MUR', 'MVR', 'MWK', 'MXN', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR',\n 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD', 'RUB', 'RWF', 'SAR',\n 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLE', 'SLL', 'SOS', 'SRD', 'SSP', 'STN', 'SVC',\n 'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX',\n 'USD', 'UYU', 'UZS', 'VED', 'VES', 'VND', 'VUV', 'WST', 'XAF', 'XCD', 'XCG', 'XOF', 'XPF',\n 'YER', 'ZAR', 'ZMW', 'ZWG', 'ZWL',\n] as const; // prettier-ignore\nexport type CurrencyCode = (typeof CURRENCY_CODES)[number];\n\n/**\n * The currencies whose minor unit isn't a hundredth, by their exponent in ISO 4217. The CLDR, which\n * `Intl.NumberFormat` follows, differs for a few cash currencies: amounts follow ISO 4217.\n */\nconst CURRENCY_EXPONENTS: Readonly<Record<string, number>> = {\n BIF: 0,\n CLP: 0,\n DJF: 0,\n GNF: 0,\n ISK: 0,\n JPY: 0,\n KMF: 0,\n KRW: 0,\n PYG: 0,\n RWF: 0,\n UGX: 0,\n UYI: 0,\n VND: 0,\n VUV: 0,\n XAF: 0,\n XOF: 0,\n XPF: 0,\n BHD: 3,\n IQD: 3,\n JOD: 3,\n KWD: 3,\n LYD: 3,\n OMR: 3,\n TND: 3,\n CLF: 4,\n UYW: 4,\n};\n\n/** Whether a string is the ISO 4217 code of a currency that Panneau knows (`CAD`). */\nexport function isCurrencyCode(code: unknown): code is CurrencyCode {\n return typeof code === 'string' && (CURRENCY_CODES as readonly string[]).includes(code);\n}\n\n/**\n * The number of digits of the minor unit of a currency, its ISO 4217 exponent: 2 for `CAD` (cents),\n * 0 for `JPY`, 3 for `KWD`. A `money` amount is an integer in that unit.\n */\nexport function getCurrencyDigits(code: string): number {\n return CURRENCY_EXPONENTS[code] ?? 2;\n}\n\n/**\n * Turns an amount in major units, as typed (`12.5`), into minor units (`1250`), rounded half away\n * from zero, without the errors of floating point (`1.005` gives `101`).\n */\nexport function toMinorUnits(amount: number, currency: string): number {\n const digits = getCurrencyDigits(currency);\n const [mantissa = '0', exponent = '0'] = String(Math.abs(amount)).split('e');\n const shifted = Number(`${mantissa}e${String(Number(exponent) + digits)}`);\n return Math.sign(amount) * Math.round(shifted) || 0;\n}\n\n/** Turns an amount in minor units (`1250`) into major units (`12.5`). */\nexport function fromMinorUnits(amount: number, currency: string): number {\n const digits = getCurrencyDigits(currency);\n return Number(`${String(amount)}e-${String(digits)}`);\n}\n"],"mappings":";;;;;;AAKA,IAAa,iBAAiB;CAC1B;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;AAChC;;;;;AAOA,IAAM,qBAAuD;CACzD,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;AACT;;AAGA,SAAgB,eAAe,MAAqC;CAChE,OAAO,OAAO,SAAS,YAAa,eAAqC,SAAS,IAAI;AAC1F;;;;;AAMA,SAAgB,kBAAkB,MAAsB;CACpD,OAAO,mBAAmB,SAAS;AACvC;;;;;AAMA,SAAgB,aAAa,QAAgB,UAA0B;CACnE,MAAM,SAAS,kBAAkB,QAAQ;CACzC,MAAM,CAAC,WAAW,KAAK,WAAW,OAAO,OAAO,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG;CAC3E,MAAM,UAAU,OAAO,GAAG,SAAS,GAAG,OAAO,OAAO,QAAQ,IAAI,MAAM,GAAG;CACzE,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,MAAM,OAAO,KAAK;AACtD;;AAGA,SAAgB,eAAe,QAAgB,UAA0B;CACrE,MAAM,SAAS,kBAAkB,QAAQ;CACzC,OAAO,OAAO,GAAG,OAAO,MAAM,EAAE,IAAI,OAAO,MAAM,GAAG;AACxD"}
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  import { PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION } from "./version.js";
2
- import { AUTH_ERROR_CODES, AUTH_ERROR_PARAM, AUTH_PAGE_PATHS, BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_ITEM_ACTIONS, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LINK_ACTIONS, BUILT_IN_LIST_LAYOUTS, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, EMAIL_UNVERIFIED_PROBLEM_TYPE, ITEM_ACTION_ABILITIES, PASSWORD_CONFIRMATION_PROBLEM_TYPE, PORTABLE_RULES, RESERVED_ROUTE_SEGMENTS, RICH_TEXT_STYLE_ELEMENTS, TWO_FACTOR_REQUIRED_PROBLEM_TYPE, isBuiltInItemAction, isBuiltInLink } from "./constants.js";
2
+ import { ADDRESS_PARTS, AUTH_ERROR_CODES, AUTH_ERROR_PARAM, AUTH_PAGE_PATHS, BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_ITEM_ACTIONS, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LINK_ACTIONS, BUILT_IN_LINK_TYPES, BUILT_IN_LIST_LAYOUTS, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, DATE_RANGE_OPEN_BOUNDS, DEFAULT_ADDRESS_REQUIRED_PARTS, DURATION_UNITS, EMAIL_UNVERIFIED_PROBLEM_TYPE, ITEM_ACTION_ABILITIES, PASSWORD_CONFIRMATION_PROBLEM_TYPE, PORTABLE_RULES, RESERVED_ROUTE_SEGMENTS, RICH_TEXT_STYLE_ELEMENTS, TWO_FACTOR_REQUIRED_PROBLEM_TYPE, isBuiltInItemAction, isBuiltInLink } from "./constants.js";
3
+ import { CURRENCY_CODES, fromMinorUnits, getCurrencyDigits, isCurrencyCode, toMinorUnits } from "./currencies.js";
4
+ import { POSTAL_CODE_COUNTRIES, getAddressRequiredParts, isAddressPart, isPostalCode, normalizePostalCode } from "./addresses.js";
3
5
  import { getValue, isFilled } from "./values.js";
4
6
  import { evaluateCondition } from "./conditions.js";
7
+ import { getLinkNewTab, getLinkTypes, isBuiltInLinkType, isExternalUrl, resolveLinkNewTab } from "./links.js";
5
8
  import { matchesRatio, parseRatio, renderedCropSize } from "./transforms.js";
6
9
  import { checkRules, checkValues } from "./rules.js";
7
10
  import { getMediaLibraries } from "./libraries.js";
@@ -12,16 +15,16 @@ import { contextBefore, formatContextHeader, parseContextHeader } from "./contex
12
15
  import { isProblem } from "./problem.js";
13
16
  import { mergeThemes } from "./themes.js";
14
17
  import { Abilities, Condition, Id, Option, RouteReference } from "./schemas/common.js";
15
- import { BlockType, Field, RichTextSettings, RichTextStyle, Rule } from "./schemas/field.js";
18
+ import { AddressSettings, BlockType, DateRangeSettings, DurationSettings, Field, LinkSettings, LinkTypeSetting, MoneySettings, RichTextSettings, RichTextStyle, Rule } from "./schemas/field.js";
16
19
  import { LayoutNode } from "./schemas/layout.js";
17
20
  import { Action, ActionConfirm, ActionPlacement, ActionScope } from "./schemas/action.js";
18
21
  import { Column, Filter, ListCalendar, ListDefinition } from "./schemas/list.js";
19
22
  import { Resource, ResourceFeatures } from "./schemas/resource.js";
20
23
  import { DefinitionTheme, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues } from "./schemas/theme.js";
21
24
  import { Auth, AuthProvider, AuthToken, ContextOption, ContextParam, Definition, DefinitionContext, MenuItem, Page, Uploads, User, Widget } from "./schemas/definition.js";
22
- import { ActionItemResult, ActionRequest, ActionResult, ActionRun, ActionRunResponse, ContextOptionsResponse, CursorPagination, EmbedResponse, EmbedValue, FieldCheckRequest, FieldCheckResponse, Item, ItemResponse, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, Pagination, Passkey, PreviewResponse, Problem, RecoveryCodes, SearchResponse, Selection, Session, StoredFile, TwoFactorChallenge, TwoFactorSetup, TwoFactorStatus, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, WebAuthnOptions } from "./schemas/api.js";
25
+ import { ActionItemResult, ActionRequest, ActionResult, ActionRun, ActionRunResponse, AddressValue, ContextOptionsResponse, CursorPagination, DateRangeValue, EmbedResponse, EmbedValue, FieldCheckRequest, FieldCheckResponse, Item, ItemResponse, LinkValue, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, MoneyValue, Pagination, Passkey, PreviewResponse, Problem, RecoveryCodes, SearchResponse, Selection, Session, StoredFile, TwoFactorChallenge, TwoFactorSetup, TwoFactorStatus, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, WebAuthnOptions } from "./schemas/api.js";
23
26
  import { BootConfig } from "./schemas/boot.js";
24
27
  import { createSchemaRegistry, namedSchemas } from "./schemas/index.js";
25
28
  import { validate, validateBootConfig, validateDefinition } from "./validate.js";
26
29
  import { createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createThemeJsonSchema } from "./openapi.js";
27
- export { AUTH_ERROR_CODES, AUTH_ERROR_PARAM, AUTH_PAGE_PATHS, Abilities, Action, ActionConfirm, ActionItemResult, ActionPlacement, ActionRequest, ActionResult, ActionRun, ActionRunResponse, ActionScope, Auth, AuthProvider, AuthToken, BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_ITEM_ACTIONS, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LINK_ACTIONS, BUILT_IN_LIST_LAYOUTS, BlockType, BootConfig, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, Column, Condition, ContextOption, ContextOptionsResponse, ContextParam, CursorPagination, Definition, DefinitionContext, DefinitionTheme, EMAIL_UNVERIFIED_PROBLEM_TYPE, EmbedResponse, EmbedValue, Field, FieldCheckRequest, FieldCheckResponse, Filter, ITEM_ACTION_ABILITIES, Id, Item, ItemResponse, LayoutNode, ListCalendar, ListDefinition, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, MenuItem, Option, PASSWORD_CONFIRMATION_PROBLEM_TYPE, PORTABLE_RULES, PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION, Page, Pagination, Passkey, PreviewResponse, Problem, RESERVED_ROUTE_SEGMENTS, RICH_TEXT_STYLE_ELEMENTS, RecoveryCodes, Resource, ResourceFeatures, RichTextSettings, RichTextStyle, RouteReference, Rule, SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, SearchResponse, Selection, Session, StoredFile, TWO_FACTOR_REQUIRED_PROBLEM_TYPE, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues, TwoFactorChallenge, TwoFactorSetup, TwoFactorStatus, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, Uploads, User, WebAuthnOptions, Widget, checkRules, checkValues, contextBefore, createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createSchemaRegistry, createThemeJsonSchema, evaluateCondition, formatContextHeader, fromSearchParams, getMediaLibraries, getValue, isBuiltInItemAction, isBuiltInLink, isCursorPage, isFilled, isFilterRange, isProblem, isSearchableResource, lintDefinition, matchesFilterRange, matchesRatio, mergeThemes, namedSchemas, parseContextHeader, parseRatio, readSearchQuery, renderedCropSize, toSearchParams, toSearchQueryParams, validate, validateBootConfig, validateDefinition };
30
+ export { ADDRESS_PARTS, AUTH_ERROR_CODES, AUTH_ERROR_PARAM, AUTH_PAGE_PATHS, Abilities, Action, ActionConfirm, ActionItemResult, ActionPlacement, ActionRequest, ActionResult, ActionRun, ActionRunResponse, ActionScope, AddressSettings, AddressValue, Auth, AuthProvider, AuthToken, BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_ITEM_ACTIONS, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LINK_ACTIONS, BUILT_IN_LINK_TYPES, BUILT_IN_LIST_LAYOUTS, BlockType, BootConfig, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, CURRENCY_CODES, Column, Condition, ContextOption, ContextOptionsResponse, ContextParam, CursorPagination, DATE_RANGE_OPEN_BOUNDS, DEFAULT_ADDRESS_REQUIRED_PARTS, DURATION_UNITS, DateRangeSettings, DateRangeValue, Definition, DefinitionContext, DefinitionTheme, DurationSettings, EMAIL_UNVERIFIED_PROBLEM_TYPE, EmbedResponse, EmbedValue, Field, FieldCheckRequest, FieldCheckResponse, Filter, ITEM_ACTION_ABILITIES, Id, Item, ItemResponse, LayoutNode, LinkSettings, LinkTypeSetting, LinkValue, ListCalendar, ListDefinition, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, MenuItem, MoneySettings, MoneyValue, Option, PASSWORD_CONFIRMATION_PROBLEM_TYPE, PORTABLE_RULES, POSTAL_CODE_COUNTRIES, PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION, Page, Pagination, Passkey, PreviewResponse, Problem, RESERVED_ROUTE_SEGMENTS, RICH_TEXT_STYLE_ELEMENTS, RecoveryCodes, Resource, ResourceFeatures, RichTextSettings, RichTextStyle, RouteReference, Rule, SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, SearchResponse, Selection, Session, StoredFile, TWO_FACTOR_REQUIRED_PROBLEM_TYPE, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues, TwoFactorChallenge, TwoFactorSetup, TwoFactorStatus, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, Uploads, User, WebAuthnOptions, Widget, checkRules, checkValues, contextBefore, createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createSchemaRegistry, createThemeJsonSchema, evaluateCondition, formatContextHeader, fromMinorUnits, fromSearchParams, getAddressRequiredParts, getCurrencyDigits, getLinkNewTab, getLinkTypes, getMediaLibraries, getValue, isAddressPart, isBuiltInItemAction, isBuiltInLink, isBuiltInLinkType, isCurrencyCode, isCursorPage, isExternalUrl, isFilled, isFilterRange, isPostalCode, isProblem, isSearchableResource, lintDefinition, matchesFilterRange, matchesRatio, mergeThemes, namedSchemas, normalizePostalCode, parseContextHeader, parseRatio, readSearchQuery, renderedCropSize, resolveLinkNewTab, toMinorUnits, toSearchParams, toSearchQueryParams, validate, validateBootConfig, validateDefinition };
@@ -0,0 +1,38 @@
1
+ import { type BuiltInLinkType } from './constants.js';
2
+ import type { Field } from './schemas/field.js';
3
+ /** A type of a `link` field: a built-in one, or one that a site adds in `settings.types`. */
4
+ export interface LinkType {
5
+ /** `url`, `page`, `email`, `tel`, `file`, or the id of a site's type (`anchor`). */
6
+ id: string;
7
+ /** The name of a site's type. Built-in types are named by the client. */
8
+ label?: string;
9
+ /** A site's type: the pattern its `url` must match. */
10
+ pattern?: string;
11
+ /** A site's type: the placeholder of its input. */
12
+ placeholder?: string;
13
+ }
14
+ /** Which links open in a new tab: as the user chooses, by their type, or none. */
15
+ export type LinkNewTab = 'choose' | 'external' | 'never';
16
+ /** Whether a type of link is built in. */
17
+ export declare function isBuiltInLinkType(type: string): type is BuiltInLinkType;
18
+ /**
19
+ * The types a `link` field offers, in order: those of `settings.types`, or `url`, `email` and
20
+ * `tel`, after `page` when the field has a `resource`. A `page` type without a `resource` is left
21
+ * out, as are entries that aren't a built-in name nor a type with an `id`.
22
+ */
23
+ export declare function getLinkTypes(field: Pick<Field, 'resource' | 'settings'>): LinkType[];
24
+ /** The `newTab` setting of a `link` field: `choose` without one. */
25
+ export declare function getLinkNewTab(field: Pick<Field, 'settings'>): LinkNewTab;
26
+ /** Whether a URL points to another site: `https://…`, `http://…` or `//…`. */
27
+ export declare function isExternalUrl(url: string): boolean;
28
+ /**
29
+ * Whether a link opens in a new tab: the user's choice with `choose`, never with `never`, and with
30
+ * `external`, `true` for `url` and `file` links, `false` for `page`, `email` and `tel` links, and
31
+ * for a site's types, whether their URL points to another site.
32
+ */
33
+ export declare function resolveLinkNewTab(newTab: LinkNewTab, link: {
34
+ type?: unknown;
35
+ url?: unknown;
36
+ newTab?: unknown;
37
+ }): boolean;
38
+ //# sourceMappingURL=links.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG7C,6FAA6F;AAC7F,MAAM,WAAW,QAAQ;IACrB,oFAAoF;IACpF,EAAE,EAAE,MAAM,CAAC;IACX,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,kFAAkF;AAClF,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;AAEzD,0CAA0C;AAC1C,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,eAAe,CAEvE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAAC,GAAG,QAAQ,EAAE,CA8BpF;AAED,oEAAoE;AACpE,wBAAgB,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,UAAU,CAGxE;AAED,8EAA8E;AAC9E,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC7B,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GAC1D,OAAO,CAkBT"}
package/dist/links.js ADDED
@@ -0,0 +1,65 @@
1
+ import { BUILT_IN_LINK_TYPES } from "./constants.js";
2
+ import { isRecord } from "./values.js";
3
+ //#region src/links.ts
4
+ /** Whether a type of link is built in. */
5
+ function isBuiltInLinkType(type) {
6
+ return BUILT_IN_LINK_TYPES.includes(type);
7
+ }
8
+ /**
9
+ * The types a `link` field offers, in order: those of `settings.types`, or `url`, `email` and
10
+ * `tel`, after `page` when the field has a `resource`. A `page` type without a `resource` is left
11
+ * out, as are entries that aren't a built-in name nor a type with an `id`.
12
+ */
13
+ function getLinkTypes(field) {
14
+ const hasPages = field.resource !== void 0;
15
+ const setting = field.settings?.types;
16
+ const entries = Array.isArray(setting) ? setting : [
17
+ ...hasPages ? ["page"] : [],
18
+ "url",
19
+ "email",
20
+ "tel"
21
+ ];
22
+ const types = [];
23
+ entries.forEach((entry) => {
24
+ let type = null;
25
+ if (typeof entry === "string" && isBuiltInLinkType(entry)) type = { id: entry };
26
+ else if (isRecord(entry) && typeof entry.id === "string" && entry.id !== "") type = {
27
+ id: entry.id,
28
+ ...typeof entry.label === "string" ? { label: entry.label } : {},
29
+ ...typeof entry.pattern === "string" ? { pattern: entry.pattern } : {},
30
+ ...typeof entry.placeholder === "string" ? { placeholder: entry.placeholder } : {}
31
+ };
32
+ if (type !== null && (type.id !== "page" || hasPages) && !types.some((other) => other.id === type.id)) types.push(type);
33
+ });
34
+ return types;
35
+ }
36
+ /** The `newTab` setting of a `link` field: `choose` without one. */
37
+ function getLinkNewTab(field) {
38
+ const setting = field.settings?.newTab;
39
+ return setting === "external" || setting === "never" ? setting : "choose";
40
+ }
41
+ /** Whether a URL points to another site: `https://…`, `http://…` or `//…`. */
42
+ function isExternalUrl(url) {
43
+ return /^(https?:)?\/\//i.test(url.trim());
44
+ }
45
+ /**
46
+ * Whether a link opens in a new tab: the user's choice with `choose`, never with `never`, and with
47
+ * `external`, `true` for `url` and `file` links, `false` for `page`, `email` and `tel` links, and
48
+ * for a site's types, whether their URL points to another site.
49
+ */
50
+ function resolveLinkNewTab(newTab, link) {
51
+ if (newTab === "never") return false;
52
+ if (newTab === "choose") return link.newTab === true;
53
+ switch (link.type) {
54
+ case "url":
55
+ case "file": return true;
56
+ case "page":
57
+ case "email":
58
+ case "tel": return false;
59
+ default: return typeof link.url === "string" && isExternalUrl(link.url);
60
+ }
61
+ }
62
+ //#endregion
63
+ export { getLinkNewTab, getLinkTypes, isBuiltInLinkType, isExternalUrl, resolveLinkNewTab };
64
+
65
+ //# sourceMappingURL=links.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"links.js","names":[],"sources":["../src/links.ts"],"sourcesContent":["// The types of `link` values and their new tabs (decision 0055). This module doesn't import zod.\nimport { BUILT_IN_LINK_TYPES, type BuiltInLinkType } from './constants';\nimport type { Field } from './schemas/field';\nimport { isRecord } from './values';\n\n/** A type of a `link` field: a built-in one, or one that a site adds in `settings.types`. */\nexport interface LinkType {\n /** `url`, `page`, `email`, `tel`, `file`, or the id of a site's type (`anchor`). */\n id: string;\n /** The name of a site's type. Built-in types are named by the client. */\n label?: string;\n /** A site's type: the pattern its `url` must match. */\n pattern?: string;\n /** A site's type: the placeholder of its input. */\n placeholder?: string;\n}\n\n/** Which links open in a new tab: as the user chooses, by their type, or none. */\nexport type LinkNewTab = 'choose' | 'external' | 'never';\n\n/** Whether a type of link is built in. */\nexport function isBuiltInLinkType(type: string): type is BuiltInLinkType {\n return (BUILT_IN_LINK_TYPES as readonly string[]).includes(type);\n}\n\n/**\n * The types a `link` field offers, in order: those of `settings.types`, or `url`, `email` and\n * `tel`, after `page` when the field has a `resource`. A `page` type without a `resource` is left\n * out, as are entries that aren't a built-in name nor a type with an `id`.\n */\nexport function getLinkTypes(field: Pick<Field, 'resource' | 'settings'>): LinkType[] {\n const hasPages = field.resource !== undefined;\n const setting = field.settings?.types;\n const entries: unknown[] = Array.isArray(setting)\n ? setting\n : [...(hasPages ? ['page'] : []), 'url', 'email', 'tel'];\n const types: LinkType[] = [];\n entries.forEach((entry) => {\n let type: LinkType | null = null;\n if (typeof entry === 'string' && isBuiltInLinkType(entry)) {\n type = { id: entry };\n } else if (isRecord(entry) && typeof entry.id === 'string' && entry.id !== '') {\n type = {\n id: entry.id,\n ...(typeof entry.label === 'string' ? { label: entry.label } : {}),\n ...(typeof entry.pattern === 'string' ? { pattern: entry.pattern } : {}),\n ...(typeof entry.placeholder === 'string'\n ? { placeholder: entry.placeholder }\n : {}),\n };\n }\n if (\n type !== null &&\n (type.id !== 'page' || hasPages) &&\n !types.some((other) => other.id === type.id)\n ) {\n types.push(type);\n }\n });\n return types;\n}\n\n/** The `newTab` setting of a `link` field: `choose` without one. */\nexport function getLinkNewTab(field: Pick<Field, 'settings'>): LinkNewTab {\n const setting = field.settings?.newTab;\n return setting === 'external' || setting === 'never' ? setting : 'choose';\n}\n\n/** Whether a URL points to another site: `https://…`, `http://…` or `//…`. */\nexport function isExternalUrl(url: string): boolean {\n return /^(https?:)?\\/\\//i.test(url.trim());\n}\n\n/**\n * Whether a link opens in a new tab: the user's choice with `choose`, never with `never`, and with\n * `external`, `true` for `url` and `file` links, `false` for `page`, `email` and `tel` links, and\n * for a site's types, whether their URL points to another site.\n */\nexport function resolveLinkNewTab(\n newTab: LinkNewTab,\n link: { type?: unknown; url?: unknown; newTab?: unknown },\n): boolean {\n if (newTab === 'never') {\n return false;\n }\n if (newTab === 'choose') {\n return link.newTab === true;\n }\n switch (link.type) {\n case 'url':\n case 'file':\n return true;\n case 'page':\n case 'email':\n case 'tel':\n return false;\n default:\n return typeof link.url === 'string' && isExternalUrl(link.url);\n }\n}\n"],"mappings":";;;;AAqBA,SAAgB,kBAAkB,MAAuC;CACrE,OAAQ,oBAA0C,SAAS,IAAI;AACnE;;;;;;AAOA,SAAgB,aAAa,OAAyD;CAClF,MAAM,WAAW,MAAM,aAAa,KAAA;CACpC,MAAM,UAAU,MAAM,UAAU;CAChC,MAAM,UAAqB,MAAM,QAAQ,OAAO,IAC1C,UACA;EAAC,GAAI,WAAW,CAAC,MAAM,IAAI,CAAC;EAAI;EAAO;EAAS;CAAK;CAC3D,MAAM,QAAoB,CAAC;CAC3B,QAAQ,SAAS,UAAU;EACvB,IAAI,OAAwB;EAC5B,IAAI,OAAO,UAAU,YAAY,kBAAkB,KAAK,GACpD,OAAO,EAAE,IAAI,MAAM;OAChB,IAAI,SAAS,KAAK,KAAK,OAAO,MAAM,OAAO,YAAY,MAAM,OAAO,IACvE,OAAO;GACH,IAAI,MAAM;GACV,GAAI,OAAO,MAAM,UAAU,WAAW,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;GAChE,GAAI,OAAO,MAAM,YAAY,WAAW,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;GACtE,GAAI,OAAO,MAAM,gBAAgB,WAC3B,EAAE,aAAa,MAAM,YAAY,IACjC,CAAC;EACX;EAEJ,IACI,SAAS,SACR,KAAK,OAAO,UAAU,aACvB,CAAC,MAAM,MAAM,UAAU,MAAM,OAAO,KAAK,EAAE,GAE3C,MAAM,KAAK,IAAI;CAEvB,CAAC;CACD,OAAO;AACX;;AAGA,SAAgB,cAAc,OAA4C;CACtE,MAAM,UAAU,MAAM,UAAU;CAChC,OAAO,YAAY,cAAc,YAAY,UAAU,UAAU;AACrE;;AAGA,SAAgB,cAAc,KAAsB;CAChD,OAAO,mBAAmB,KAAK,IAAI,KAAK,CAAC;AAC7C;;;;;;AAOA,SAAgB,kBACZ,QACA,MACO;CACP,IAAI,WAAW,SACX,OAAO;CAEX,IAAI,WAAW,UACX,OAAO,KAAK,WAAW;CAE3B,QAAQ,KAAK,MAAb;EACI,KAAK;EACL,KAAK,QACD,OAAO;EACX,KAAK;EACL,KAAK;EACL,KAAK,OACD,OAAO;EACX,SACI,OAAO,OAAO,KAAK,QAAQ,YAAY,cAAc,KAAK,GAAG;CACrE;AACJ"}
package/dist/lint.js CHANGED
@@ -47,9 +47,13 @@ function checkResource(resource, path, issues) {
47
47
  path: `${path}.list.calendar.field`,
48
48
  message: `No field named \`${calendar.field}\`.`
49
49
  });
50
- else if (field.type !== "date" && field.type !== "datetime") issues.push({
50
+ else if (![
51
+ "date",
52
+ "datetime",
53
+ "daterange"
54
+ ].includes(field.type)) issues.push({
51
55
  path: `${path}.list.calendar.field`,
52
- message: "The field of a calendar must be a `date` or a `datetime`."
56
+ message: "The field of a calendar must be a `date`, a `datetime` or a `daterange`."
53
57
  });
54
58
  if (!(resource.list?.filters ?? []).some((candidate) => candidate.id === filter && candidate.type === "date-range")) issues.push({
55
59
  path: `${path}.list.calendar`,
package/dist/lint.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lint.js","names":[],"sources":["../src/lint.ts"],"sourcesContent":["import type { DefinitionInput, Field, LayoutNode, ResourceInput } from './schemas';\nimport type { ValidationIssue } from './validate';\n\nfunction fieldNames(fields: Field[]): Set<string> {\n return new Set(fields.map((field) => field.name));\n}\n\nfunction checkLayout(\n nodes: LayoutNode[],\n names: Set<string>,\n path: string,\n issues: ValidationIssue[],\n) {\n nodes.forEach((node, index) => {\n const nodePath = `${path}.${index}`;\n if (node.type === 'field') {\n if (node.name === undefined) {\n issues.push({ path: nodePath, message: 'A `field` node needs a `name`.' });\n } else if (!names.has(node.name)) {\n issues.push({\n path: `${nodePath}.name`,\n message: `No field named \\`${node.name}\\`.`,\n });\n }\n }\n if (node.type === 'component' && node.component === undefined) {\n issues.push({ path: nodePath, message: 'A `component` node needs a `component`.' });\n }\n if (node.type === 'tabs' && node.children?.some((child) => child.type !== 'tab')) {\n issues.push({\n path: `${nodePath}.children`,\n message: 'The children of `tabs` must be `tab` nodes.',\n });\n }\n if (node.children !== undefined) {\n checkLayout(node.children, names, `${nodePath}.children`, issues);\n }\n });\n}\n\nfunction checkResource(resource: ResourceInput, path: string, issues: ValidationIssue[]) {\n const names = fieldNames(resource.fields);\n if (names.size !== resource.fields.length) {\n issues.push({ path: `${path}.fields`, message: 'Field names must be unique.' });\n }\n if (resource.form?.layout !== undefined) {\n checkLayout(resource.form.layout, names, `${path}.form.layout`, issues);\n }\n (resource.list?.columns ?? []).forEach((column, index) => {\n if (column.field !== undefined && !names.has(column.field)) {\n issues.push({\n path: `${path}.list.columns.${index}.field`,\n message: `No field named \\`${column.field}\\`.`,\n });\n }\n });\n const calendar = resource.list?.calendar;\n if (calendar !== undefined) {\n const field = resource.fields.find((candidate) => candidate.name === calendar.field);\n const filter = calendar.filter ?? calendar.field;\n if (field === undefined) {\n issues.push({\n path: `${path}.list.calendar.field`,\n message: `No field named \\`${calendar.field}\\`.`,\n });\n } else if (field.type !== 'date' && field.type !== 'datetime') {\n issues.push({\n path: `${path}.list.calendar.field`,\n message: 'The field of a calendar must be a `date` or a `datetime`.',\n });\n }\n if (\n !(resource.list?.filters ?? []).some(\n (candidate) => candidate.id === filter && candidate.type === 'date-range',\n )\n ) {\n issues.push({\n path: `${path}.list.calendar`,\n message: `The calendar needs a \\`date-range\\` filter \\`${filter}\\` in the list.`,\n });\n }\n }\n (resource.actions ?? []).forEach((action, index) => {\n if (action.layout !== undefined) {\n checkLayout(\n action.layout,\n fieldNames(action.fields ?? []),\n `${path}.actions.${index}.layout`,\n issues,\n );\n }\n });\n if (resource.kind === 'media') {\n const file = resource.fields.findIndex((field) => field.name === 'file');\n const field = resource.fields[file];\n if (field === undefined) {\n issues.push({\n path: `${path}.fields`,\n message: 'A resource of kind `media` needs a `file` field.',\n });\n } else if (field.type !== 'file' || field.multiple === true) {\n issues.push({\n path: `${path}.fields.${file}`,\n message: 'The `file` field of a `media` resource must be a single `file`.',\n });\n }\n }\n resource.fields.forEach((field, index) => {\n if (field.type === 'relation' && field.resource === undefined) {\n issues.push({\n path: `${path}.fields.${index}.resource`,\n message: 'A `relation` field needs a `resource`.',\n });\n } else if (field.type === 'relation' && Array.isArray(field.resource)) {\n issues.push({\n path: `${path}.fields.${index}.resource`,\n message: 'A `relation` field names one resource.',\n });\n }\n });\n}\n\n/**\n * Checks what the schema can't: references between parts of a definition (layout nodes and\n * columns that name existing fields, relations, `media` and `image` fields that name a resource,\n * unique names), and the `file` field of `media` resources.\n */\nexport function lintDefinition(definition: DefinitionInput): ValidationIssue[] {\n const issues: ValidationIssue[] = [];\n const resourceIds = new Set(definition.resources.map((resource) => resource.id));\n const libraries = definition.resources\n .filter((resource) => resource.kind === 'media')\n .map((resource) => resource.id);\n definition.resources.forEach((resource, index) => {\n checkResource(resource, `resources.${index}`, issues);\n resource.fields.forEach((field, fieldIndex) => {\n if (\n field.type === 'relation' &&\n typeof field.resource === 'string' &&\n !resourceIds.has(field.resource)\n ) {\n issues.push({\n path: `resources.${index}.fields.${fieldIndex}.resource`,\n message: `No resource \\`${field.resource}\\`.`,\n });\n }\n if (field.type === 'media' || field.type === 'image') {\n const fieldPath = `resources.${index}.fields.${fieldIndex}.resource`;\n if (field.resource === undefined) {\n // Every library of the definition (decision 0027).\n if (libraries.length === 0) {\n issues.push({\n path: fieldPath,\n message: `${field.type === 'image' ? 'An' : 'A'} \\`${field.type}\\` field needs a resource of kind \\`media\\`.`,\n });\n }\n } else {\n const named =\n typeof field.resource === 'string' ? [field.resource] : field.resource;\n named.forEach((id, idIndex) => {\n if (!libraries.includes(id)) {\n issues.push({\n path:\n typeof field.resource === 'string'\n ? fieldPath\n : `${fieldPath}.${String(idIndex)}`,\n message: `No resource of kind \\`media\\` named \\`${id}\\`.`,\n });\n }\n });\n }\n }\n });\n });\n return issues;\n}\n"],"mappings":";AAGA,SAAS,WAAW,QAA8B;CAC9C,OAAO,IAAI,IAAI,OAAO,KAAK,UAAU,MAAM,IAAI,CAAC;AACpD;AAEA,SAAS,YACL,OACA,OACA,MACA,QACF;CACE,MAAM,SAAS,MAAM,UAAU;EAC3B,MAAM,WAAW,GAAG,KAAK,GAAG;EAC5B,IAAI,KAAK,SAAS,SAAS;GACvB,IAAI,KAAK,SAAS,KAAA,GACd,OAAO,KAAK;IAAE,MAAM;IAAU,SAAS;GAAiC,CAAC;QACtE,IAAI,CAAC,MAAM,IAAI,KAAK,IAAI,GAC3B,OAAO,KAAK;IACR,MAAM,GAAG,SAAS;IAClB,SAAS,oBAAoB,KAAK,KAAK;GAC3C,CAAC;EAET;EACA,IAAI,KAAK,SAAS,eAAe,KAAK,cAAc,KAAA,GAChD,OAAO,KAAK;GAAE,MAAM;GAAU,SAAS;EAA0C,CAAC;EAEtF,IAAI,KAAK,SAAS,UAAU,KAAK,UAAU,MAAM,UAAU,MAAM,SAAS,KAAK,GAC3E,OAAO,KA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,YAAY,IAAI,MAAM,QAAQ,GAE/B,OAAO,KAAK;IACR,MAAM,aAAa,MAAM,UAAU,WAAW;IAC9C,SAAS,iBAAiB,MAAM,SAAS;GAC7C,CAAC;GAEL,IAAI,MAAM,SAAS,WAAW,MAAM,SAAS,SAAS;IAClD,MAAM,YAAY,aAAa,MAAM,UAAU,WAAW;IAC1D,IAAI,MAAM,aAAa,KAAA,GAEf;SAAA,UAAU,WAAW,GACrB,OAAO,KAAK;MACR,MAAM;MACN,SAAS,GAAG,MAAM,SAAS,UAAU,OAAO,IAAI,KAAK,MAAM,KAAK;KACpE,CAAC;IAAA,OAKL,CADI,OAAO,MAAM,aAAa,WAAW,CAAC,MAAM,QAAQ,IAAI,MAAM,SAAA,CAC5D,SAAS,IAAI,YAAY;KAC3B,IAAI,CAAC,UAAU,SAAS,EAAE,GACtB,OAAO,KAAK;MACR,MACI,OAAO,MAAM,aAAa,WACpB,YACA,GAAG,UAAU,GAAG,OAAO,OAAO;MACxC,SAAS,yCAAyC,GAAG;KACzD,CAAC;IAET,CAAC;GAET;EACJ,CAAC;CACL,CAAC;CACD,OAAO;AACX"}
1
+ {"version":3,"file":"lint.js","names":[],"sources":["../src/lint.ts"],"sourcesContent":["import type { DefinitionInput, Field, LayoutNode, ResourceInput } from './schemas';\nimport type { ValidationIssue } from './validate';\n\nfunction fieldNames(fields: Field[]): Set<string> {\n return new Set(fields.map((field) => field.name));\n}\n\nfunction checkLayout(\n nodes: LayoutNode[],\n names: Set<string>,\n path: string,\n issues: ValidationIssue[],\n) {\n nodes.forEach((node, index) => {\n const nodePath = `${path}.${index}`;\n if (node.type === 'field') {\n if (node.name === undefined) {\n issues.push({ path: nodePath, message: 'A `field` node needs a `name`.' });\n } else if (!names.has(node.name)) {\n issues.push({\n path: `${nodePath}.name`,\n message: `No field named \\`${node.name}\\`.`,\n });\n }\n }\n if (node.type === 'component' && node.component === undefined) {\n issues.push({ path: nodePath, message: 'A `component` node needs a `component`.' });\n }\n if (node.type === 'tabs' && node.children?.some((child) => child.type !== 'tab')) {\n issues.push({\n path: `${nodePath}.children`,\n message: 'The children of `tabs` must be `tab` nodes.',\n });\n }\n if (node.children !== undefined) {\n checkLayout(node.children, names, `${nodePath}.children`, issues);\n }\n });\n}\n\nfunction checkResource(resource: ResourceInput, path: string, issues: ValidationIssue[]) {\n const names = fieldNames(resource.fields);\n if (names.size !== resource.fields.length) {\n issues.push({ path: `${path}.fields`, message: 'Field names must be unique.' });\n }\n if (resource.form?.layout !== undefined) {\n checkLayout(resource.form.layout, names, `${path}.form.layout`, issues);\n }\n (resource.list?.columns ?? []).forEach((column, index) => {\n if (column.field !== undefined && !names.has(column.field)) {\n issues.push({\n path: `${path}.list.columns.${index}.field`,\n message: `No field named \\`${column.field}\\`.`,\n });\n }\n });\n const calendar = resource.list?.calendar;\n if (calendar !== undefined) {\n const field = resource.fields.find((candidate) => candidate.name === calendar.field);\n const filter = calendar.filter ?? calendar.field;\n if (field === undefined) {\n issues.push({\n path: `${path}.list.calendar.field`,\n message: `No field named \\`${calendar.field}\\`.`,\n });\n } else if (!['date', 'datetime', 'daterange'].includes(field.type)) {\n issues.push({\n path: `${path}.list.calendar.field`,\n message: 'The field of a calendar must be a `date`, a `datetime` or a `daterange`.',\n });\n }\n if (\n !(resource.list?.filters ?? []).some(\n (candidate) => candidate.id === filter && candidate.type === 'date-range',\n )\n ) {\n issues.push({\n path: `${path}.list.calendar`,\n message: `The calendar needs a \\`date-range\\` filter \\`${filter}\\` in the list.`,\n });\n }\n }\n (resource.actions ?? []).forEach((action, index) => {\n if (action.layout !== undefined) {\n checkLayout(\n action.layout,\n fieldNames(action.fields ?? []),\n `${path}.actions.${index}.layout`,\n issues,\n );\n }\n });\n if (resource.kind === 'media') {\n const file = resource.fields.findIndex((field) => field.name === 'file');\n const field = resource.fields[file];\n if (field === undefined) {\n issues.push({\n path: `${path}.fields`,\n message: 'A resource of kind `media` needs a `file` field.',\n });\n } else if (field.type !== 'file' || field.multiple === true) {\n issues.push({\n path: `${path}.fields.${file}`,\n message: 'The `file` field of a `media` resource must be a single `file`.',\n });\n }\n }\n resource.fields.forEach((field, index) => {\n if (field.type === 'relation' && field.resource === undefined) {\n issues.push({\n path: `${path}.fields.${index}.resource`,\n message: 'A `relation` field needs a `resource`.',\n });\n } else if (field.type === 'relation' && Array.isArray(field.resource)) {\n issues.push({\n path: `${path}.fields.${index}.resource`,\n message: 'A `relation` field names one resource.',\n });\n }\n });\n}\n\n/**\n * Checks what the schema can't: references between parts of a definition (layout nodes and\n * columns that name existing fields, relations, `media` and `image` fields that name a resource,\n * unique names), and the `file` field of `media` resources.\n */\nexport function lintDefinition(definition: DefinitionInput): ValidationIssue[] {\n const issues: ValidationIssue[] = [];\n const resourceIds = new Set(definition.resources.map((resource) => resource.id));\n const libraries = definition.resources\n .filter((resource) => resource.kind === 'media')\n .map((resource) => resource.id);\n definition.resources.forEach((resource, index) => {\n checkResource(resource, `resources.${index}`, issues);\n resource.fields.forEach((field, fieldIndex) => {\n if (\n field.type === 'relation' &&\n typeof field.resource === 'string' &&\n !resourceIds.has(field.resource)\n ) {\n issues.push({\n path: `resources.${index}.fields.${fieldIndex}.resource`,\n message: `No resource \\`${field.resource}\\`.`,\n });\n }\n if (field.type === 'media' || field.type === 'image') {\n const fieldPath = `resources.${index}.fields.${fieldIndex}.resource`;\n if (field.resource === undefined) {\n // Every library of the definition (decision 0027).\n if (libraries.length === 0) {\n issues.push({\n path: fieldPath,\n message: `${field.type === 'image' ? 'An' : 'A'} \\`${field.type}\\` field needs a resource of kind \\`media\\`.`,\n });\n }\n } else {\n const named =\n typeof field.resource === 'string' ? [field.resource] : field.resource;\n named.forEach((id, idIndex) => {\n if (!libraries.includes(id)) {\n issues.push({\n path:\n typeof field.resource === 'string'\n ? fieldPath\n : `${fieldPath}.${String(idIndex)}`,\n message: `No resource of kind \\`media\\` named \\`${id}\\`.`,\n });\n }\n });\n }\n }\n });\n });\n return issues;\n}\n"],"mappings":";AAGA,SAAS,WAAW,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EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,IAAI,CAAA;KAAE,KAAK,MAAM,CAAC;IACnE;;;OAGG;IACH,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,UAAU,GAAG,IAAI,CAAC;IAC3C;;;;OAIG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B;;;;OAIG;IACH,IAAI,CAAC,EAAE,eAAe,CAAC;CAC1B;AAED,kFAAkF;AAClF,MAAM,WAAW,kBAAkB;IAC/B;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,KAAK,aAAa,EAAE,CAAC;IACnE,6FAA6F;IAC7F,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;CAC5E;AAED,MAAM,WAAW,WAAW;IACxB,oEAAoE;IACpE,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAChF,uCAAuC;IACvC,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,EAAE,CAAC;CACvC;AAqQD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAuwB1E;AAED,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC"}
@@ -72,6 +72,7 @@ var DEFAULT_MESSAGES = {
72
72
  maxSize: () => "This file is too large.",
73
73
  before: () => "This date is too late.",
74
74
  after: () => "This date is too early.",
75
+ providers: (failure) => `This embed must come from ${Array.isArray(failure.value) ? failure.value.join(" or ") : "another provider"}.`,
75
76
  crop: (failure) => {
76
77
  const ratios = isRecord(failure.value) ? failure.value.ratios : void 0;
77
78
  return Array.isArray(ratios) && ratios.length > 0 ? `Crop this image to ${ratios.join(" or ")}.` : "Crop this image.";
@@ -112,12 +113,20 @@ function searchableText(value) {
112
113
  if (isRecord(value)) return Object.values(value).map(searchableText).join(" ");
113
114
  return "";
114
115
  }
116
+ /** What a value sorts by: the start of a `daterange`, the amount of `money`, or its text. */
117
+ function sortValue(value) {
118
+ if (!isRecord(value)) return value;
119
+ if ("start" in value && "end" in value) return value.start ?? value.end;
120
+ if ("currency" in value && typeof value.amount === "number") return value.amount;
121
+ return searchableText(value);
122
+ }
115
123
  function compare(a, b) {
116
- const left = isRecord(a) ? searchableText(a) : a;
117
- const right = isRecord(b) ? searchableText(b) : b;
124
+ const left = sortValue(a);
125
+ const right = sortValue(b);
118
126
  if (left === right) return 0;
119
127
  if (left === void 0 || left === null) return 1;
120
128
  if (right === void 0 || right === null) return -1;
129
+ if (typeof left === "number" && typeof right === "number") return left - right;
121
130
  return String(left).localeCompare(String(right), void 0, { numeric: true });
122
131
  }
123
132
  function applyQuery(items, query) {