@panneau/protocol 5.0.0-alpha.12 → 5.0.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/conformance/index.d.ts +6 -0
- package/dist/conformance/index.d.ts.map +1 -1
- package/dist/conformance/index.js +185 -2
- package/dist/conformance/index.js.map +1 -1
- package/dist/constants.d.ts +12 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +22 -2
- package/dist/constants.js.map +1 -1
- package/dist/context.d.ts +15 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +34 -0
- package/dist/context.js.map +1 -0
- package/dist/index.js +6 -5
- package/dist/lint.d.ts.map +1 -1
- package/dist/lint.js +17 -0
- package/dist/lint.js.map +1 -1
- package/dist/mock/index.d.ts +25 -4
- package/dist/mock/index.d.ts.map +1 -1
- package/dist/mock/index.js +129 -29
- package/dist/mock/index.js.map +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +57 -5
- package/dist/openapi.js.map +1 -1
- package/dist/rules.d.ts +6 -0
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +20 -5
- package/dist/rules.js.map +1 -1
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +3 -2
- package/dist/schemas/action.d.ts +2 -0
- package/dist/schemas/action.d.ts.map +1 -1
- package/dist/schemas/api.d.ts +9 -0
- package/dist/schemas/api.d.ts.map +1 -1
- package/dist/schemas/api.js +5 -3
- package/dist/schemas/api.js.map +1 -1
- package/dist/schemas/definition.d.ts +67 -0
- package/dist/schemas/definition.d.ts.map +1 -1
- package/dist/schemas/definition.js +45 -2
- package/dist/schemas/definition.js.map +1 -1
- package/dist/schemas/field.d.ts +3 -0
- package/dist/schemas/field.d.ts.map +1 -1
- package/dist/schemas/field.js +6 -4
- package/dist/schemas/field.js.map +1 -1
- package/dist/schemas/index.d.ts +102 -0
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +9 -4
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/list.d.ts +15 -0
- package/dist/schemas/list.d.ts.map +1 -1
- package/dist/schemas/list.js +13 -5
- package/dist/schemas/list.js.map +1 -1
- package/dist/schemas/resource.d.ts +11 -0
- package/dist/schemas/resource.d.ts.map +1 -1
- package/package.json +1 -1
- package/schema/boot.schema.json +136 -10
- package/schema/definition.schema.json +136 -10
- package/schema/openapi.json +523 -32
package/dist/constants.js
CHANGED
|
@@ -66,7 +66,9 @@ var BUILT_IN_FIELD_TYPES = [
|
|
|
66
66
|
"json",
|
|
67
67
|
"tags",
|
|
68
68
|
"embed",
|
|
69
|
-
"location"
|
|
69
|
+
"location",
|
|
70
|
+
"country",
|
|
71
|
+
"region"
|
|
70
72
|
];
|
|
71
73
|
/** Validation rules that both frontends and backends check. */
|
|
72
74
|
var PORTABLE_RULES = [
|
|
@@ -77,6 +79,7 @@ var PORTABLE_RULES = [
|
|
|
77
79
|
"email",
|
|
78
80
|
"url",
|
|
79
81
|
"json",
|
|
82
|
+
"tel",
|
|
80
83
|
"in",
|
|
81
84
|
"accept",
|
|
82
85
|
"maxSize",
|
|
@@ -122,7 +125,24 @@ var RICH_TEXT_STYLE_ELEMENTS = [
|
|
|
122
125
|
"ol",
|
|
123
126
|
"li"
|
|
124
127
|
];
|
|
128
|
+
/**
|
|
129
|
+
* The first segments of the client routes under `basePath` that Panneau keeps for itself
|
|
130
|
+
* (decision 0019). A param of the context can't be named like one: the context is a prefix of
|
|
131
|
+
* the routes, `{basePath}/{name}/{value}/…` (decision 0045).
|
|
132
|
+
*/
|
|
133
|
+
var RESERVED_ROUTE_SEGMENTS = [
|
|
134
|
+
"resources",
|
|
135
|
+
"pages",
|
|
136
|
+
"media",
|
|
137
|
+
"search",
|
|
138
|
+
"account",
|
|
139
|
+
"auth"
|
|
140
|
+
];
|
|
141
|
+
/** The request header that carries the values of the current context (decision 0045). */
|
|
142
|
+
var CONTEXT_HEADER = "Panneau-Context";
|
|
143
|
+
/** The type of the `403` problem of a value of the context that the user can't use. */
|
|
144
|
+
var CONTEXT_PROBLEM_TYPE = "urn:panneau:problem:context";
|
|
125
145
|
//#endregion
|
|
126
|
-
export { 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, ITEM_ACTION_ABILITIES, PORTABLE_RULES, RICH_TEXT_STYLE_ELEMENTS, isBuiltInItemAction, isBuiltInLink };
|
|
146
|
+
export { 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, ITEM_ACTION_ABILITIES, PORTABLE_RULES, RESERVED_ROUTE_SEGMENTS, RICH_TEXT_STYLE_ELEMENTS, isBuiltInItemAction, isBuiltInLink };
|
|
127
147
|
|
|
128
148
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -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] 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 '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"],"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;AACJ;;AAIA,IAAa,iBAAiB;CAC1B;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"}
|
|
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"],"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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Values of the params of the context, by name. A param without a value is left out. */
|
|
2
|
+
export type ContextValues = Readonly<Record<string, string>>;
|
|
3
|
+
/**
|
|
4
|
+
* The value of the `Panneau-Context` header: the values in the format of a query string, in the
|
|
5
|
+
* order of `names` (the order of the params of the definition) when given. Empty without values.
|
|
6
|
+
*/
|
|
7
|
+
export declare function formatContextHeader(values: Readonly<Record<string, string | null | undefined>>, names?: readonly string[]): string;
|
|
8
|
+
/** The values of a `Panneau-Context` header. The first value of a name wins; empty ones are left out. */
|
|
9
|
+
export declare function parseContextHeader(header: string | null | undefined): ContextValues;
|
|
10
|
+
/**
|
|
11
|
+
* The values of the context in the params before `name`: those that the request of its choices
|
|
12
|
+
* sends, since a param depends on the params before it.
|
|
13
|
+
*/
|
|
14
|
+
export declare function contextBefore(values: ContextValues, names: readonly string[], name: string): ContextValues;
|
|
15
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAGA,yFAAyF;AACzF,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAS7D;;;GAGG;AACH,wBAAgB,mBAAmB,CAC/B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC,EAC3D,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,GAC1B,MAAM,CAMR;AAED,yGAAyG;AACzG,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,aAAa,CAQnF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CACzB,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,IAAI,EAAE,MAAM,GACb,aAAa,CAGf"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/context.ts
|
|
2
|
+
/** Only the values that are set: `null`, `undefined` and empty values are left out. */
|
|
3
|
+
function setValues(values) {
|
|
4
|
+
return Object.entries(values).filter((entry) => typeof entry[1] === "string" && entry[1] !== "");
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The value of the `Panneau-Context` header: the values in the format of a query string, in the
|
|
8
|
+
* order of `names` (the order of the params of the definition) when given. Empty without values.
|
|
9
|
+
*/
|
|
10
|
+
function formatContextHeader(values, names) {
|
|
11
|
+
const entries = setValues(values);
|
|
12
|
+
if (names !== void 0) entries.sort(([a], [b]) => names.indexOf(a) - names.indexOf(b));
|
|
13
|
+
return new URLSearchParams(entries).toString();
|
|
14
|
+
}
|
|
15
|
+
/** The values of a `Panneau-Context` header. The first value of a name wins; empty ones are left out. */
|
|
16
|
+
function parseContextHeader(header) {
|
|
17
|
+
const values = {};
|
|
18
|
+
new URLSearchParams(header ?? "").forEach((value, name) => {
|
|
19
|
+
if (value !== "" && !(name in values)) values[name] = value;
|
|
20
|
+
});
|
|
21
|
+
return values;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The values of the context in the params before `name`: those that the request of its choices
|
|
25
|
+
* sends, since a param depends on the params before it.
|
|
26
|
+
*/
|
|
27
|
+
function contextBefore(values, names, name) {
|
|
28
|
+
const before = names.slice(0, Math.max(0, names.indexOf(name)));
|
|
29
|
+
return Object.fromEntries(setValues(values).filter(([key]) => before.includes(key)));
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { contextBefore, formatContextHeader, parseContextHeader };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["// The current context (decision 0045): the values of its params, in the `Panneau-Context` header\n// and in the prefix of the client routes. This module doesn't import zod.\n\n/** Values of the params of the context, by name. A param without a value is left out. */\nexport type ContextValues = Readonly<Record<string, string>>;\n\n/** Only the values that are set: `null`, `undefined` and empty values are left out. */\nfunction setValues(values: Readonly<Record<string, string | null | undefined>>) {\n return Object.entries(values).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string' && entry[1] !== '',\n );\n}\n\n/**\n * The value of the `Panneau-Context` header: the values in the format of a query string, in the\n * order of `names` (the order of the params of the definition) when given. Empty without values.\n */\nexport function formatContextHeader(\n values: Readonly<Record<string, string | null | undefined>>,\n names?: readonly string[],\n): string {\n const entries = setValues(values);\n if (names !== undefined) {\n entries.sort(([a], [b]) => names.indexOf(a) - names.indexOf(b));\n }\n return new URLSearchParams(entries).toString();\n}\n\n/** The values of a `Panneau-Context` header. The first value of a name wins; empty ones are left out. */\nexport function parseContextHeader(header: string | null | undefined): ContextValues {\n const values: Record<string, string> = {};\n new URLSearchParams(header ?? '').forEach((value, name) => {\n if (value !== '' && !(name in values)) {\n values[name] = value;\n }\n });\n return values;\n}\n\n/**\n * The values of the context in the params before `name`: those that the request of its choices\n * sends, since a param depends on the params before it.\n */\nexport function contextBefore(\n values: ContextValues,\n names: readonly string[],\n name: string,\n): ContextValues {\n const before = names.slice(0, Math.max(0, names.indexOf(name)));\n return Object.fromEntries(setValues(values).filter(([key]) => before.includes(key)));\n}\n"],"mappings":";;AAOA,SAAS,UAAU,QAA6D;CAC5E,OAAO,OAAO,QAAQ,MAAM,CAAC,CAAC,QACzB,UAAqC,OAAO,MAAM,OAAO,YAAY,MAAM,OAAO,EACvF;AACJ;;;;;AAMA,SAAgB,oBACZ,QACA,OACM;CACN,MAAM,UAAU,UAAU,MAAM;CAChC,IAAI,UAAU,KAAA,GACV,QAAQ,MAAM,CAAC,IAAI,CAAC,OAAO,MAAM,QAAQ,CAAC,IAAI,MAAM,QAAQ,CAAC,CAAC;CAElE,OAAO,IAAI,gBAAgB,OAAO,CAAC,CAAC,SAAS;AACjD;;AAGA,SAAgB,mBAAmB,QAAkD;CACjF,MAAM,SAAiC,CAAC;CACxC,IAAI,gBAAgB,UAAU,EAAE,CAAC,CAAC,SAAS,OAAO,SAAS;EACvD,IAAI,UAAU,MAAM,EAAE,QAAQ,SAC1B,OAAO,QAAQ;CAEvB,CAAC;CACD,OAAO;AACX;;;;;AAMA,SAAgB,cACZ,QACA,OACA,MACa;CACb,MAAM,SAAS,MAAM,MAAM,GAAG,KAAK,IAAI,GAAG,MAAM,QAAQ,IAAI,CAAC,CAAC;CAC9D,OAAO,OAAO,YAAY,UAAU,MAAM,CAAC,CAAC,QAAQ,CAAC,SAAS,OAAO,SAAS,GAAG,CAAC,CAAC;AACvF"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION } from "./version.js";
|
|
2
|
-
import { 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, ITEM_ACTION_ABILITIES, PORTABLE_RULES, RICH_TEXT_STYLE_ELEMENTS, isBuiltInItemAction, isBuiltInLink } from "./constants.js";
|
|
2
|
+
import { 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, ITEM_ACTION_ABILITIES, PORTABLE_RULES, RESERVED_ROUTE_SEGMENTS, RICH_TEXT_STYLE_ELEMENTS, isBuiltInItemAction, isBuiltInLink } from "./constants.js";
|
|
3
3
|
import { getValue, isFilled } from "./values.js";
|
|
4
4
|
import { evaluateCondition } from "./conditions.js";
|
|
5
5
|
import { matchesRatio, parseRatio, renderedCropSize } from "./transforms.js";
|
|
@@ -8,19 +8,20 @@ import { getMediaLibraries } from "./libraries.js";
|
|
|
8
8
|
import { lintDefinition } from "./lint.js";
|
|
9
9
|
import { fromSearchParams, isCursorPage, isFilterRange, matchesFilterRange, toSearchParams } from "./query.js";
|
|
10
10
|
import { SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, isSearchableResource, readSearchQuery, toSearchQueryParams } from "./search.js";
|
|
11
|
+
import { contextBefore, formatContextHeader, parseContextHeader } from "./context.js";
|
|
11
12
|
import { isProblem } from "./problem.js";
|
|
12
13
|
import { mergeThemes } from "./themes.js";
|
|
13
14
|
import { Abilities, Condition, Id, Option, RouteReference } from "./schemas/common.js";
|
|
14
15
|
import { BlockType, Field, RichTextSettings, RichTextStyle, Rule } from "./schemas/field.js";
|
|
15
16
|
import { LayoutNode } from "./schemas/layout.js";
|
|
16
17
|
import { Action, ActionConfirm, ActionPlacement, ActionScope } from "./schemas/action.js";
|
|
17
|
-
import { Column, Filter, ListDefinition } from "./schemas/list.js";
|
|
18
|
+
import { Column, Filter, ListCalendar, ListDefinition } from "./schemas/list.js";
|
|
18
19
|
import { Resource, ResourceFeatures } from "./schemas/resource.js";
|
|
19
20
|
import { DefinitionTheme, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues } from "./schemas/theme.js";
|
|
20
|
-
import { Auth, AuthProvider, AuthToken, Definition, MenuItem, Page, Uploads, User, Widget } from "./schemas/definition.js";
|
|
21
|
-
import { ActionItemResult, ActionRequest, ActionResult, ActionRun, ActionRunResponse, CursorPagination, EmbedResponse, EmbedValue, FieldCheckRequest, FieldCheckResponse, Item, ItemResponse, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, Pagination, PreviewResponse, Problem, SearchResponse, Selection, Session, StoredFile, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse } from "./schemas/api.js";
|
|
21
|
+
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, PreviewResponse, Problem, SearchResponse, Selection, Session, StoredFile, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse } from "./schemas/api.js";
|
|
22
23
|
import { BootConfig } from "./schemas/boot.js";
|
|
23
24
|
import { createSchemaRegistry, namedSchemas } from "./schemas/index.js";
|
|
24
25
|
import { validate, validateBootConfig, validateDefinition } from "./validate.js";
|
|
25
26
|
import { createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createThemeJsonSchema } from "./openapi.js";
|
|
26
|
-
export { 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, Column, Condition, CursorPagination, Definition, DefinitionTheme, EmbedResponse, EmbedValue, Field, FieldCheckRequest, FieldCheckResponse, Filter, ITEM_ACTION_ABILITIES, Id, Item, ItemResponse, LayoutNode, ListDefinition, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, MenuItem, Option, PORTABLE_RULES, PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION, Page, Pagination, PreviewResponse, Problem, RICH_TEXT_STYLE_ELEMENTS, Resource, ResourceFeatures, RichTextSettings, RichTextStyle, RouteReference, Rule, SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, SearchResponse, Selection, Session, StoredFile, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, Uploads, User, Widget, checkRules, checkValues, createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createSchemaRegistry, createThemeJsonSchema, evaluateCondition, fromSearchParams, getMediaLibraries, getValue, isBuiltInItemAction, isBuiltInLink, isCursorPage, isFilled, isFilterRange, isProblem, isSearchableResource, lintDefinition, matchesFilterRange, matchesRatio, mergeThemes, namedSchemas, parseRatio, readSearchQuery, renderedCropSize, toSearchParams, toSearchQueryParams, validate, validateBootConfig, validateDefinition };
|
|
27
|
+
export { 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, EmbedResponse, EmbedValue, Field, FieldCheckRequest, FieldCheckResponse, Filter, ITEM_ACTION_ABILITIES, Id, Item, ItemResponse, LayoutNode, ListCalendar, ListDefinition, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, MenuItem, Option, PORTABLE_RULES, PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION, Page, Pagination, PreviewResponse, Problem, RESERVED_ROUTE_SEGMENTS, RICH_TEXT_STYLE_ELEMENTS, Resource, ResourceFeatures, RichTextSettings, RichTextStyle, RouteReference, Rule, SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, SearchResponse, Selection, Session, StoredFile, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, Uploads, User, 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 };
|
package/dist/lint.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAoC,MAAM,WAAW,CAAC;AACnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAoC,MAAM,WAAW,CAAC;AACnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAyHlD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,eAAe,GAAG,eAAe,EAAE,CAgD7E"}
|
package/dist/lint.js
CHANGED
|
@@ -39,6 +39,23 @@ function checkResource(resource, path, issues) {
|
|
|
39
39
|
message: `No field named \`${column.field}\`.`
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
|
+
const calendar = resource.list?.calendar;
|
|
43
|
+
if (calendar !== void 0) {
|
|
44
|
+
const field = resource.fields.find((candidate) => candidate.name === calendar.field);
|
|
45
|
+
const filter = calendar.filter ?? calendar.field;
|
|
46
|
+
if (field === void 0) issues.push({
|
|
47
|
+
path: `${path}.list.calendar.field`,
|
|
48
|
+
message: `No field named \`${calendar.field}\`.`
|
|
49
|
+
});
|
|
50
|
+
else if (field.type !== "date" && field.type !== "datetime") issues.push({
|
|
51
|
+
path: `${path}.list.calendar.field`,
|
|
52
|
+
message: "The field of a calendar must be a `date` or a `datetime`."
|
|
53
|
+
});
|
|
54
|
+
if (!(resource.list?.filters ?? []).some((candidate) => candidate.id === filter && candidate.type === "date-range")) issues.push({
|
|
55
|
+
path: `${path}.list.calendar`,
|
|
56
|
+
message: `The calendar needs a \`date-range\` filter \`${filter}\` in the list.`
|
|
57
|
+
});
|
|
58
|
+
}
|
|
42
59
|
(resource.actions ?? []).forEach((action, index) => {
|
|
43
60
|
if (action.layout !== void 0) checkLayout(action.layout, fieldNames(action.fields ?? []), `${path}.actions.${index}.layout`, issues);
|
|
44
61
|
});
|
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 (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,S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AM,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 (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;AAC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ACD,OAAO;AACX"}
|
package/dist/mock/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ContextValues } from '../context.js';
|
|
2
|
+
import type { ContextOption, DefinitionInput } from '../schemas/index.js';
|
|
2
3
|
import type { EmbedValue, Item } from '../schemas/api.js';
|
|
3
4
|
type Values = Record<string, unknown>;
|
|
4
5
|
export interface MockBackendOptions {
|
|
@@ -19,6 +20,22 @@ export interface MockBackendOptions {
|
|
|
19
20
|
* a video for YouTube and Vimeo URLs, and a link for other web pages.
|
|
20
21
|
*/
|
|
21
22
|
embed?: (url: string) => EmbedValue | null;
|
|
23
|
+
/**
|
|
24
|
+
* The current context, when the definition has `context` (decision 0045). The values of the
|
|
25
|
+
* `Panneau-Context` header are checked against the choices of each param: a value that isn't
|
|
26
|
+
* one is a `403` problem.
|
|
27
|
+
*/
|
|
28
|
+
context?: MockContextOptions;
|
|
29
|
+
}
|
|
30
|
+
/** How the mock backend answers the context of its definition (decision 0045). */
|
|
31
|
+
export interface MockContextOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Every choice of a param without inline `options`, for the values of the params before it.
|
|
34
|
+
* `GET /context/{name}/options?q=` gives the first 20 whose label matches `q`.
|
|
35
|
+
*/
|
|
36
|
+
options?: (name: string, before: ContextValues) => ContextOption[];
|
|
37
|
+
/** Whether an item of a resource is in the context, for lists, items, actions and search. */
|
|
38
|
+
scope?: (resource: string, item: Item, values: ContextValues) => boolean;
|
|
22
39
|
}
|
|
23
40
|
export interface MockBackend {
|
|
24
41
|
/** A `fetch`-compatible function that answers protocol requests. */
|
|
@@ -29,9 +46,13 @@ export interface MockBackend {
|
|
|
29
46
|
/**
|
|
30
47
|
* An in-memory backend that implements the protocol's resource routes: definition, list, show,
|
|
31
48
|
* create, update (with `If-Match`), delete, duplicate and the built-in `delete` action. Its items
|
|
32
|
-
* allow every built-in item action (`view`, `update`, `duplicate`, `delete`)
|
|
33
|
-
*
|
|
34
|
-
*
|
|
49
|
+
* allow every built-in item action (`view`, `update`, `duplicate`, `delete`), unless an item of
|
|
50
|
+
* `items` gives its own `abilities`. It reads abilities as clients do (decision 0046): a resource
|
|
51
|
+
* without `viewAny` answers `403` on its list, one without `create` on creates, an item without
|
|
52
|
+
* `view`, `update` or `delete` on those requests; items leave out the values of fields with
|
|
53
|
+
* `view: false`, and writes ignore those of fields with `update: false`. Values are checked with
|
|
54
|
+
* the portable rules. Used to test the conformance kit, and to develop frontends without a real
|
|
55
|
+
* backend.
|
|
35
56
|
*/
|
|
36
57
|
export declare function createMockBackend(options: MockBackendOptions): MockBackend;
|
|
37
58
|
export { createExampleDefinition } from './example.js';
|
package/dist/mock/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mock/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mock/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,aAAa,EAAqC,MAAM,YAAY,CAAC;AAInF,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAiB,MAAM,YAAY,CAAC;AAChF,OAAO,KAAK,EAER,UAAU,EAEV,IAAI,EAUP,MAAM,gBAAgB,CAAC;AAKxB,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEtC,MAAM,WAAW,kBAAkB;IAC/B,kGAAkG;IAClG,UAAU,EAAE,eAAe,CAAC;IAC5B,mFAAmF;IACnF,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACjC;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,IAAI,CAAA;KAAE,KAAK,MAAM,CAAC;IACnE;;;OAGG;IACH,KAAK,CAAC,EAAE,CAAC,GAAG,EAA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