@panneau/protocol 5.0.0-alpha.27 → 5.0.0-alpha.29
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.map +1 -1
- package/dist/conformance/index.js +30 -4
- package/dist/conformance/index.js.map +1 -1
- package/dist/index.js +3 -2
- package/dist/lint.d.ts +1 -1
- package/dist/lint.d.ts.map +1 -1
- package/dist/lint.js +57 -8
- package/dist/lint.js.map +1 -1
- package/dist/mock/example.d.ts.map +1 -1
- package/dist/mock/example.js +39 -22
- package/dist/mock/example.js.map +1 -1
- package/dist/mock/index.d.ts +3 -1
- package/dist/mock/index.d.ts.map +1 -1
- package/dist/mock/index.js +46 -14
- package/dist/mock/index.js.map +1 -1
- package/dist/resourceTypes.d.ts +39 -0
- package/dist/resourceTypes.d.ts.map +1 -0
- package/dist/resourceTypes.js +34 -0
- package/dist/resourceTypes.js.map +1 -0
- package/dist/rules.d.ts +2 -1
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +3 -2
- 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 +2 -1
- package/dist/schemas/action.d.ts +2 -0
- package/dist/schemas/action.d.ts.map +1 -1
- package/dist/schemas/api.d.ts +6 -0
- package/dist/schemas/api.d.ts.map +1 -1
- package/dist/schemas/api.js +2 -1
- package/dist/schemas/api.js.map +1 -1
- package/dist/schemas/definition.d.ts +10 -0
- package/dist/schemas/definition.d.ts.map +1 -1
- package/dist/schemas/field.d.ts +1 -0
- package/dist/schemas/field.d.ts.map +1 -1
- package/dist/schemas/field.js +1 -0
- package/dist/schemas/field.js.map +1 -1
- package/dist/schemas/index.d.ts +38 -0
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +3 -2
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/layout.d.ts +1 -0
- package/dist/schemas/layout.d.ts.map +1 -1
- package/dist/schemas/layout.js +2 -1
- package/dist/schemas/layout.js.map +1 -1
- package/dist/schemas/resource.d.ts +18 -3
- package/dist/schemas/resource.d.ts.map +1 -1
- package/dist/schemas/resource.js +13 -3
- package/dist/schemas/resource.js.map +1 -1
- package/dist/schemas/theme.d.ts +4 -0
- package/dist/schemas/theme.d.ts.map +1 -1
- package/dist/schemas/theme.js +1 -0
- package/dist/schemas/theme.js.map +1 -1
- package/package.json +1 -1
- package/schema/boot.schema.json +48 -1
- package/schema/definition.schema.json +48 -1
- package/schema/openapi.json +69 -3
package/dist/lint.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ITEM_TYPE_KEY } from "./resourceTypes.js";
|
|
1
2
|
import { RESOURCE_WIDGET_TYPES, WIDGET_RESERVED_QUERY_PARAMS, isBuiltInWidgetType } from "./widgets.js";
|
|
2
3
|
//#region src/lint.ts
|
|
3
4
|
function fieldNames(fields) {
|
|
@@ -27,13 +28,61 @@ function checkLayout(nodes, names, path, issues) {
|
|
|
27
28
|
if (node.children !== void 0) checkLayout(node.children, names, `${nodePath}.children`, issues);
|
|
28
29
|
});
|
|
29
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* The types of a resource (decision 0077): unique ids, fields named apart from those of the
|
|
33
|
+
* resource, and no field `type` in the form, which holds the item's type.
|
|
34
|
+
*/
|
|
35
|
+
function checkTypes(resource, names, path, issues) {
|
|
36
|
+
const ids = /* @__PURE__ */ new Set();
|
|
37
|
+
(resource.types ?? []).forEach((type, index) => {
|
|
38
|
+
const typePath = `${path}.types.${index}`;
|
|
39
|
+
if (ids.has(type.id)) issues.push({
|
|
40
|
+
path: `${typePath}.id`,
|
|
41
|
+
message: `Duplicate type id \`${type.id}\`.`
|
|
42
|
+
});
|
|
43
|
+
ids.add(type.id);
|
|
44
|
+
if (fieldNames(type.fields).size !== type.fields.length) issues.push({
|
|
45
|
+
path: `${typePath}.fields`,
|
|
46
|
+
message: "Field names must be unique."
|
|
47
|
+
});
|
|
48
|
+
type.fields.forEach((field, fieldIndex) => {
|
|
49
|
+
if (names.has(field.name)) issues.push({
|
|
50
|
+
path: `${typePath}.fields.${fieldIndex}.name`,
|
|
51
|
+
message: `The resource already has a field named \`${field.name}\`.`
|
|
52
|
+
});
|
|
53
|
+
else if (field.name === "type") issues.push({
|
|
54
|
+
path: `${typePath}.fields.${fieldIndex}.name`,
|
|
55
|
+
message: `\`${ITEM_TYPE_KEY}\` holds the type of the item.`
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
const typeField = resource.fields.findIndex((field) => field.name === ITEM_TYPE_KEY);
|
|
60
|
+
if (ids.size > 0 && typeField !== -1 && resource.fields[typeField]?.notInForm !== true) issues.push({
|
|
61
|
+
path: `${path}.fields.${typeField}`,
|
|
62
|
+
message: `\`${ITEM_TYPE_KEY}\` holds the type of the item, set when it is created: its field must be \`notInForm\`.`
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** The fields of a resource and of its types, with their paths. */
|
|
66
|
+
function allFields(resource, path) {
|
|
67
|
+
return [...resource.fields.map((field, index) => ({
|
|
68
|
+
field,
|
|
69
|
+
path: `${path}.fields.${index}`
|
|
70
|
+
})), ...(resource.types ?? []).flatMap((type, typeIndex) => type.fields.map((field, index) => ({
|
|
71
|
+
field,
|
|
72
|
+
path: `${path}.types.${typeIndex}.fields.${index}`
|
|
73
|
+
})))];
|
|
74
|
+
}
|
|
30
75
|
function checkResource(resource, path, issues) {
|
|
31
76
|
const names = fieldNames(resource.fields);
|
|
32
77
|
if (names.size !== resource.fields.length) issues.push({
|
|
33
78
|
path: `${path}.fields`,
|
|
34
79
|
message: "Field names must be unique."
|
|
35
80
|
});
|
|
36
|
-
|
|
81
|
+
checkTypes(resource, names, path, issues);
|
|
82
|
+
if (resource.form?.layout !== void 0) {
|
|
83
|
+
const typeNames = (resource.types ?? []).flatMap((type) => [...fieldNames(type.fields)]);
|
|
84
|
+
checkLayout(resource.form.layout, /* @__PURE__ */ new Set([...names, ...typeNames]), `${path}.form.layout`, issues);
|
|
85
|
+
}
|
|
37
86
|
(resource.list?.columns ?? []).forEach((column, index) => {
|
|
38
87
|
if (column.field !== void 0 && !names.has(column.field)) issues.push({
|
|
39
88
|
path: `${path}.list.columns.${index}.field`,
|
|
@@ -76,13 +125,13 @@ function checkResource(resource, path, issues) {
|
|
|
76
125
|
message: "The `file` field of a `media` resource must be a single `file`."
|
|
77
126
|
});
|
|
78
127
|
}
|
|
79
|
-
resource.
|
|
128
|
+
allFields(resource, path).forEach(({ field, path: fieldPath }) => {
|
|
80
129
|
if (field.type === "relation" && field.resource === void 0) issues.push({
|
|
81
|
-
path: `${
|
|
130
|
+
path: `${fieldPath}.resource`,
|
|
82
131
|
message: "A `relation` field needs a `resource`."
|
|
83
132
|
});
|
|
84
133
|
else if (field.type === "relation" && Array.isArray(field.resource)) issues.push({
|
|
85
|
-
path: `${
|
|
134
|
+
path: `${fieldPath}.resource`,
|
|
86
135
|
message: "A `relation` field names one resource."
|
|
87
136
|
});
|
|
88
137
|
});
|
|
@@ -90,7 +139,7 @@ function checkResource(resource, path, issues) {
|
|
|
90
139
|
/**
|
|
91
140
|
* Checks what the schema can't: references between parts of a definition (layout nodes and
|
|
92
141
|
* columns that name existing fields, relations, `media` and `image` fields that name a resource,
|
|
93
|
-
* unique names), and the `file` field of `media` resources.
|
|
142
|
+
* unique names), the types of resources, and the `file` field of `media` resources.
|
|
94
143
|
*/
|
|
95
144
|
function lintDefinition(definition) {
|
|
96
145
|
const issues = [];
|
|
@@ -98,13 +147,13 @@ function lintDefinition(definition) {
|
|
|
98
147
|
const libraries = definition.resources.filter((resource) => resource.kind === "media").map((resource) => resource.id);
|
|
99
148
|
definition.resources.forEach((resource, index) => {
|
|
100
149
|
checkResource(resource, `resources.${index}`, issues);
|
|
101
|
-
resource.
|
|
150
|
+
allFields(resource, `resources.${index}`).forEach(({ field, path }) => {
|
|
102
151
|
if (field.type === "relation" && typeof field.resource === "string" && !resourceIds.has(field.resource)) issues.push({
|
|
103
|
-
path:
|
|
152
|
+
path: `${path}.resource`,
|
|
104
153
|
message: `No resource \`${field.resource}\`.`
|
|
105
154
|
});
|
|
106
155
|
if (field.type === "media" || field.type === "image") {
|
|
107
|
-
const fieldPath =
|
|
156
|
+
const fieldPath = `${path}.resource`;
|
|
108
157
|
if (field.resource === void 0) {
|
|
109
158
|
if (libraries.length === 0) issues.push({
|
|
110
159
|
path: fieldPath,
|
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';\nimport {\n RESOURCE_WIDGET_TYPES,\n WIDGET_RESERVED_QUERY_PARAMS,\n isBuiltInWidgetType,\n} from './widgets';\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 checkWidgets(definition, issues);\n return issues;\n}\n\nconst FILTER_PARAM = /^filter\\[([^\\]]+)\\]/;\n\n/**\n * The widgets of the dashboard (decision 0064): unique ids, and the built-in `stat` and `list` on\n * a resource that exists, with filters of its list. A `stat` counts the items of the list, so the\n * list can't be paged with cursors, which give no total.\n */\nfunction checkWidgets(definition: DefinitionInput, issues: ValidationIssue[]) {\n const ids = new Set<string>();\n (definition.dashboard?.widgets ?? []).forEach((widget, index) => {\n const path = `dashboard.widgets.${index}`;\n if (ids.has(widget.id)) {\n issues.push({ path: `${path}.id`, message: `Duplicate widget id \\`${widget.id}\\`.` });\n }\n ids.add(widget.id);\n if (!isBuiltInWidgetType(widget.type)) {\n return;\n }\n const settings = widget.settings ?? {};\n const onResource = typeof settings.resource === 'string';\n if (!onResource) {\n if (settings.query !== undefined) {\n issues.push({\n path: `${path}.settings.query`,\n message: '`query` goes with a `resource`.',\n });\n }\n return;\n }\n if (!(RESOURCE_WIDGET_TYPES as readonly string[]).includes(widget.type)) {\n issues.push({\n path: `${path}.settings.resource`,\n message: `A \\`${widget.type}\\` widget has data of its own: only \\`stat\\` and \\`list\\` read a resource.`,\n });\n return;\n }\n const resource = definition.resources.find(\n (candidate) => candidate.id === settings.resource,\n );\n if (resource === undefined) {\n issues.push({\n path: `${path}.settings.resource`,\n message: `No resource \\`${String(settings.resource)}\\`.`,\n });\n return;\n }\n if (widget.type === 'stat' && resource.list?.pagination === 'cursor') {\n issues.push({\n path: `${path}.settings.resource`,\n message: `The list of \\`${resource.id}\\` is paged with cursors and has no total: it can't feed a \\`stat\\`.`,\n });\n }\n const filters = new Set((resource.list?.filters ?? []).map((filter) => filter.id));\n Object.keys(settings.query ?? {}).forEach((key) => {\n const filter = FILTER_PARAM.exec(key)?.[1];\n if ((WIDGET_RESERVED_QUERY_PARAMS as readonly string[]).includes(key)) {\n issues.push({\n path: `${path}.settings.query.${key}`,\n message: `The client sets \\`${key}\\`.`,\n });\n } else if (filter !== undefined && !filters.has(filter)) {\n issues.push({\n path: `${path}.settings.query.${key}`,\n message: `The list of \\`${resource.id}\\` has no filter \\`${filter}\\`.`,\n });\n }\n });\n });\n}\n"],"mappings":";;AAQA,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,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mD,SAAS,GAAG,GAChE,OAAO,KAAK;IACR,MAAM,GAAG,KAAK,kBAAkB;IAChC,SAAS,qBAAqB,IAAI;GACtC,CAAC;QACE,IAAI,WAAW,KAAA,KAAa,CAAC,QAAQ,IAAI,MAAM,GAClD,OAAO,KAAK;IACR,MAAM,GAAG,KAAK,kBAAkB;IAChC,SAAS,iBAAiB,SAAS,GAAG,qBAAqB,OAAO;GACtE,CAAC;EAET,CAAC;CACL,CAAC;AACL"}
|
|
1
|
+
{"version":3,"file":"lint.js","names":[],"sources":["../src/lint.ts"],"sourcesContent":["import { ITEM_TYPE_KEY } from './resourceTypes';\nimport type { DefinitionInput, Field, LayoutNode, ResourceInput } from './schemas';\nimport type { ValidationIssue } from './validate';\nimport {\n RESOURCE_WIDGET_TYPES,\n WIDGET_RESERVED_QUERY_PARAMS,\n isBuiltInWidgetType,\n} from './widgets';\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\n/**\n * The types of a resource (decision 0077): unique ids, fields named apart from those of the\n * resource, and no field `type` in the form, which holds the item's type.\n */\nfunction checkTypes(\n resource: ResourceInput,\n names: Set<string>,\n path: string,\n issues: ValidationIssue[],\n) {\n const ids = new Set<string>();\n (resource.types ?? []).forEach((type, index) => {\n const typePath = `${path}.types.${index}`;\n if (ids.has(type.id)) {\n issues.push({ path: `${typePath}.id`, message: `Duplicate type id \\`${type.id}\\`.` });\n }\n ids.add(type.id);\n const own = fieldNames(type.fields);\n if (own.size !== type.fields.length) {\n issues.push({ path: `${typePath}.fields`, message: 'Field names must be unique.' });\n }\n type.fields.forEach((field, fieldIndex) => {\n if (names.has(field.name)) {\n issues.push({\n path: `${typePath}.fields.${fieldIndex}.name`,\n message: `The resource already has a field named \\`${field.name}\\`.`,\n });\n } else if (field.name === ITEM_TYPE_KEY) {\n issues.push({\n path: `${typePath}.fields.${fieldIndex}.name`,\n message: `\\`${ITEM_TYPE_KEY}\\` holds the type of the item.`,\n });\n }\n });\n });\n const typeField = resource.fields.findIndex((field) => field.name === ITEM_TYPE_KEY);\n if (ids.size > 0 && typeField !== -1 && resource.fields[typeField]?.notInForm !== true) {\n issues.push({\n path: `${path}.fields.${typeField}`,\n message: `\\`${ITEM_TYPE_KEY}\\` holds the type of the item, set when it is created: its field must be \\`notInForm\\`.`,\n });\n }\n}\n\n/** The fields of a resource and of its types, with their paths. */\nfunction allFields(resource: ResourceInput, path: string): { field: Field; path: string }[] {\n return [\n ...resource.fields.map((field, index) => ({ field, path: `${path}.fields.${index}` })),\n ...(resource.types ?? []).flatMap((type, typeIndex) =>\n type.fields.map((field, index) => ({\n field,\n path: `${path}.types.${typeIndex}.fields.${index}`,\n })),\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 checkTypes(resource, names, path, issues);\n if (resource.form?.layout !== undefined) {\n // The layout can name the fields of the types: the forms of the other types leave them out.\n const typeNames = (resource.types ?? []).flatMap((type) => [...fieldNames(type.fields)]);\n checkLayout(\n resource.form.layout,\n new Set([...names, ...typeNames]),\n `${path}.form.layout`,\n issues,\n );\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 allFields(resource, path).forEach(({ field, path: fieldPath }) => {\n if (field.type === 'relation' && field.resource === undefined) {\n issues.push({\n path: `${fieldPath}.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: `${fieldPath}.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), the types of resources, 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 allFields(resource, `resources.${index}`).forEach(({ field, path }) => {\n if (\n field.type === 'relation' &&\n typeof field.resource === 'string' &&\n !resourceIds.has(field.resource)\n ) {\n issues.push({\n path: `${path}.resource`,\n message: `No resource \\`${field.resource}\\`.`,\n });\n }\n if (field.type === 'media' || field.type === 'image') {\n const fieldPath = `${path}.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 checkWidgets(definition, issues);\n return issues;\n}\n\nconst FILTER_PARAM = /^filter\\[([^\\]]+)\\]/;\n\n/**\n * The widgets of the dashboard (decision 0064): unique ids, and the built-in `stat` and `list` on\n * a resource that exists, with filters of its list. A `stat` counts the items of the list, so the\n * list can't be paged with cursors, which give no total.\n */\nfunction checkWidgets(definition: DefinitionInput, issues: ValidationIssue[]) {\n const ids = new Set<string>();\n (definition.dashboard?.widgets ?? []).forEach((widget, index) => {\n const path = `dashboard.widgets.${index}`;\n if (ids.has(widget.id)) {\n issues.push({ path: `${path}.id`, message: `Duplicate widget id \\`${widget.id}\\`.` });\n }\n ids.add(widget.id);\n if (!isBuiltInWidgetType(widget.type)) {\n return;\n }\n const settings = widget.settings ?? {};\n const onResource = typeof settings.resource === 'string';\n if (!onResource) {\n if (settings.query !== undefined) {\n issues.push({\n path: `${path}.settings.query`,\n message: '`query` goes with a `resource`.',\n });\n }\n return;\n }\n if (!(RESOURCE_WIDGET_TYPES as readonly string[]).includes(widget.type)) {\n issues.push({\n path: `${path}.settings.resource`,\n message: `A \\`${widget.type}\\` widget has data of its own: only \\`stat\\` and \\`list\\` read a resource.`,\n });\n return;\n }\n const resource = definition.resources.find(\n (candidate) => candidate.id === settings.resource,\n );\n if (resource === undefined) {\n issues.push({\n path: `${path}.settings.resource`,\n message: `No resource \\`${String(settings.resource)}\\`.`,\n });\n return;\n }\n if (widget.type === 'stat' && resource.list?.pagination === 'cursor') {\n issues.push({\n path: `${path}.settings.resource`,\n message: `The list of \\`${resource.id}\\` is paged with cursors and has no total: it can't feed a \\`stat\\`.`,\n });\n }\n const filters = new Set((resource.list?.filters ?? []).map((filter) => filter.id));\n Object.keys(settings.query ?? {}).forEach((key) => {\n const filter = FILTER_PARAM.exec(key)?.[1];\n if ((WIDGET_RESERVED_QUERY_PARAMS as readonly string[]).includes(key)) {\n issues.push({\n path: `${path}.settings.query.${key}`,\n message: `The client sets \\`${key}\\`.`,\n });\n } else if (filter !== undefined && !filters.has(filter)) {\n issues.push({\n path: `${path}.settings.query.${key}`,\n message: `The list of \\`${resource.id}\\` has no filter \\`${filter}\\`.`,\n });\n }\n });\n });\n}\n"],"mappings":";;;AASA,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,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S,MAAM,WAAW,CAAC,EAAA,CAAG,KAAK,WAAW,OAAO,EAAE,CAAC;EACjF,OAAO,KAAK,SAAS,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ;GAC/C,MAAM,SAAS,aAAa,KAAK,GAAG,CAAC,GAAG;GACxC,IAAK,6BAAmD,SAAS,GAAG,GAChE,OAAO,KAAK;IACR,MAAM,GAAG,KAAK,kBAAkB;IAChC,SAAS,qBAAqB,IAAI;GACtC,CAAC;QACE,IAAI,WAAW,KAAA,KAAa,CAAC,QAAQ,IAAI,MAAM,GAClD,OAAO,KAAK;IACR,MAAM,GAAG,KAAK,kBAAkB;IAChC,SAAS,iBAAiB,SAAS,GAAG,qBAAqB,OAAO;GACtE,CAAC;EAET,CAAC;CACL,CAAC;AACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../../src/mock/example.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,uBAAuB,IAAI,eAAe,
|
|
1
|
+
{"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../../src/mock/example.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,uBAAuB,IAAI,eAAe,CAqMzD"}
|
package/dist/mock/example.js
CHANGED
|
@@ -105,37 +105,54 @@ function createExampleDefinition() {
|
|
|
105
105
|
settings: { prefix: "https://example.com/" }
|
|
106
106
|
}
|
|
107
107
|
],
|
|
108
|
-
form: { layout: [
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
type: "tab",
|
|
112
|
-
label: "Contenu",
|
|
108
|
+
form: { layout: [
|
|
109
|
+
{
|
|
110
|
+
type: "tabs",
|
|
113
111
|
children: [{
|
|
114
|
-
type: "
|
|
112
|
+
type: "tab",
|
|
113
|
+
label: "Contenu",
|
|
115
114
|
children: [{
|
|
116
115
|
type: "field",
|
|
117
|
-
name: "title"
|
|
118
|
-
width: 8
|
|
116
|
+
name: "title"
|
|
119
117
|
}, {
|
|
120
118
|
type: "field",
|
|
121
|
-
name: "
|
|
122
|
-
width: 4
|
|
119
|
+
name: "blocks"
|
|
123
120
|
}]
|
|
121
|
+
}]
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
type: "sidebar",
|
|
125
|
+
panel: "save"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
type: "sidebar",
|
|
129
|
+
panel: "errors"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
type: "sidebar",
|
|
133
|
+
panel: "publication",
|
|
134
|
+
label: "Publication",
|
|
135
|
+
children: [{
|
|
136
|
+
type: "field",
|
|
137
|
+
name: "status"
|
|
124
138
|
}, {
|
|
125
139
|
type: "field",
|
|
126
|
-
name: "
|
|
140
|
+
name: "published_at"
|
|
127
141
|
}]
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
type: "sidebar",
|
|
145
|
+
panel: "actions"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
type: "sidebar",
|
|
149
|
+
label: "Pièce jointe",
|
|
150
|
+
children: [{
|
|
151
|
+
type: "field",
|
|
152
|
+
name: "attachment"
|
|
153
|
+
}]
|
|
154
|
+
}
|
|
155
|
+
] },
|
|
139
156
|
list: {
|
|
140
157
|
columns: [
|
|
141
158
|
{
|
package/dist/mock/example.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"example.js","names":[],"sources":["../../src/mock/example.ts"],"sourcesContent":["import type { DefinitionInput } from '../schemas';\n\n/**\n * A small but complete definition: pages with localized titles, a status, a publication date shown\n * for published pages, an author, an attachment and typed blocks, in tabs and a sidebar, plus\n * authors with a photo, and a media library. For tests\n * and stories, with `createMockBackend()`.\n */\nexport function createExampleDefinition(): DefinitionInput {\n return {\n protocol: 1,\n name: 'Test site',\n locale: 'fr',\n locales: ['fr', 'en'],\n api: { baseUrl: '/panneau/api' },\n resources: [\n {\n id: 'pages',\n label: { singular: 'page', plural: 'pages' },\n itemTitle: 'title',\n fields: [\n {\n name: 'title',\n type: 'text',\n label: 'Titre',\n localized: true,\n rules: [{ rule: 'required' }, { rule: 'max', value: 120 }],\n },\n {\n name: 'status',\n type: 'select',\n options: [\n { value: 'draft', label: 'Brouillon' },\n { value: 'published', label: 'Publiée' },\n ],\n rules: [\n { rule: 'required' },\n { rule: 'in', value: ['draft', 'published'] },\n ],\n },\n {\n name: 'published_at',\n type: 'datetime',\n visibleWhen: { field: 'status', equals: 'published' },\n rules: [{ rule: 'required' }],\n },\n { name: 'author', type: 'relation', resource: 'authors' },\n {\n name: 'blocks',\n type: 'repeater',\n types: [\n {\n id: 'text',\n label: 'Texte',\n fields: [\n {\n name: 'body',\n type: 'richtext',\n rules: [{ rule: 'required' }],\n },\n ],\n },\n {\n id: 'image',\n label: 'Image',\n fields: [\n {\n name: 'image',\n type: 'media',\n rules: [\n { rule: 'accept', value: ['image/*'] },\n { rule: 'maxSize', value: 1000 },\n ],\n },\n ],\n },\n ],\n },\n {\n name: 'attachment',\n type: 'file',\n label: 'Pièce jointe',\n rules: [{ rule: 'accept', value: ['application/pdf'] }],\n },\n {\n name: 'slug',\n type: 'slug',\n from: 'title',\n localized: true,\n check: true,\n settings: { prefix: 'https://example.com/' },\n },\n ],\n form: {\n layout: [\n {\n type: 'tabs',\n children: [\n {\n type: 'tab',\n label: 'Contenu',\n children: [\n {\n type: 'row',\n children: [\n { type: 'field', name: 'title', width: 8 },\n { type: 'field', name: 'status', width: 4 },\n ],\n },\n { type: 'field', name: 'blocks' },\n ],\n },\n ],\n },\n {\n type: 'sidebar',\n children: [\n { type: 'field', name: 'published_at' },\n { type: 'field', name: 'attachment' },\n ],\n },\n ],\n },\n list: {\n columns: [\n { field: 'title', sortable: true },\n { field: 'status' },\n { id: 'updated' },\n ],\n filters: [\n { id: 'status', type: 'select' },\n { id: 'published_at', type: 'date-range', label: 'Publication' },\n ],\n sorts: ['title', 'published_at'],\n defaultSort: 'title',\n perPage: 20,\n search: true,\n },\n actions: [\n {\n id: 'publish',\n label: 'Publier',\n scope: ['item', 'selection'],\n placement: ['row', 'toolbar'],\n confirm: { message: 'Publier {count} pages ?' },\n fields: [{ name: 'notify', type: 'boolean' }],\n dryRun: true,\n },\n ],\n abilities: { viewAny: true, create: true },\n },\n {\n id: 'authors',\n label: { singular: 'auteur', plural: 'auteurs' },\n // Titles open the form, without the panel of the details.\n open: 'edit',\n fields: [\n { name: 'name', type: 'text', rules: [{ rule: 'required' }] },\n { name: 'photo', type: 'media', accept: ['image/*'] },\n ],\n },\n {\n id: 'media',\n kind: 'media',\n label: { singular: 'média', plural: 'médias' },\n // Of the built-in item actions, only these, in this order\n itemActions: ['edit', 'delete'],\n itemTitle: 'name',\n fields: [\n {\n name: 'file',\n type: 'file',\n accept: ['image/*', 'video/*', 'application/pdf'],\n rules: [{ rule: 'required' }],\n },\n { name: 'name', type: 'text' },\n { name: 'alt', type: 'text', localized: true },\n ],\n list: {\n filters: [\n {\n id: 'type',\n type: 'select',\n options: [\n { value: 'image', label: 'Images' },\n { value: 'video', label: 'Vidéos' },\n { value: 'document', label: 'Documents' },\n ],\n },\n ],\n search: true,\n },\n abilities: { viewAny: true, create: true },\n },\n ],\n menus: { main: [{ type: 'resources' }, { type: 'link', label: 'Site', url: '/' }] },\n auth: { mode: 'panneau', password: true, providers: [{ id: 'google', label: 'Google' }] },\n uploads: { mode: 'presigned' },\n };\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,0BAA2C;CACvD,OAAO;EACH,UAAU;EACV,MAAM;EACN,QAAQ;EACR,SAAS,CAAC,MAAM,IAAI;EACpB,KA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AQ;IAAS;IAE7C,aAAa,CAAC,QAAQ,QAAQ;IAC9B,WAAW;IACX,QAAQ;KACJ;MACI,MAAM;MACN,MAAM;MACN,QAAQ;OAAC;OAAW;OAAW;MAAiB;MAChD,OAAO,CAAC,EAAE,MAAM,WAAW,CAAC;KAChC;KACA;MAAE,MAAM;MAAQ,MAAM;KAAO;KAC7B;MAAE,MAAM;MAAO,MAAM;MAAQ,WAAW;KAAK;IACjD;IACA,MAAM;KACF,SAAS,CACL;MACI,IAAI;MACJ,MAAM;MACN,SAAS;OACL;QAAE,OAAO;QAAS,OAAO;OAAS;OAClC;QAAE,OAAO;QAAS,OAAO;OAAS;OAClC;QAAE,OAAO;QAAY,OAAO;OAAY;MAC5C;KACJ,CACJ;KACA,QAAQ;IACZ;IACA,WAAW;KAAE,SAAS;KAAM,QAAQ;IAAK;GAC7C;EACJ;EACA,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,YAAY,GAAG;GAAE,MAAM;GAAQ,OAAO;GAAQ,KAAK;EAAI,CAAC,EAAE;EAClF,MAAM;GAAE,MAAM;GAAW,UAAU;GAAM,WAAW,CAAC;IAAE,IAAI;IAAU,OAAO;GAAS,CAAC;EAAE;EACxF,SAAS,EAAE,MAAM,YAAY;CACjC;AACJ"}
|
|
1
|
+
{"version":3,"file":"example.js","names":[],"sources":["../../src/mock/example.ts"],"sourcesContent":["import type { DefinitionInput } from '../schemas';\n\n/**\n * A small but complete definition: pages with localized titles, a status, a publication date shown\n * for published pages, an author, an attachment and typed blocks, in tabs and a sidebar, plus\n * authors with a photo, and a media library. For tests\n * and stories, with `createMockBackend()`.\n */\nexport function createExampleDefinition(): DefinitionInput {\n return {\n protocol: 1,\n name: 'Test site',\n locale: 'fr',\n locales: ['fr', 'en'],\n api: { baseUrl: '/panneau/api' },\n resources: [\n {\n id: 'pages',\n label: { singular: 'page', plural: 'pages' },\n itemTitle: 'title',\n fields: [\n {\n name: 'title',\n type: 'text',\n label: 'Titre',\n localized: true,\n rules: [{ rule: 'required' }, { rule: 'max', value: 120 }],\n },\n {\n name: 'status',\n type: 'select',\n options: [\n { value: 'draft', label: 'Brouillon' },\n { value: 'published', label: 'Publiée' },\n ],\n rules: [\n { rule: 'required' },\n { rule: 'in', value: ['draft', 'published'] },\n ],\n },\n {\n name: 'published_at',\n type: 'datetime',\n visibleWhen: { field: 'status', equals: 'published' },\n rules: [{ rule: 'required' }],\n },\n { name: 'author', type: 'relation', resource: 'authors' },\n {\n name: 'blocks',\n type: 'repeater',\n types: [\n {\n id: 'text',\n label: 'Texte',\n fields: [\n {\n name: 'body',\n type: 'richtext',\n rules: [{ rule: 'required' }],\n },\n ],\n },\n {\n id: 'image',\n label: 'Image',\n fields: [\n {\n name: 'image',\n type: 'media',\n rules: [\n { rule: 'accept', value: ['image/*'] },\n { rule: 'maxSize', value: 1000 },\n ],\n },\n ],\n },\n ],\n },\n {\n name: 'attachment',\n type: 'file',\n label: 'Pièce jointe',\n rules: [{ rule: 'accept', value: ['application/pdf'] }],\n },\n {\n name: 'slug',\n type: 'slug',\n from: 'title',\n localized: true,\n check: true,\n settings: { prefix: 'https://example.com/' },\n },\n ],\n form: {\n layout: [\n {\n type: 'tabs',\n children: [\n {\n type: 'tab',\n label: 'Contenu',\n children: [\n { type: 'field', name: 'title' },\n { type: 'field', name: 'blocks' },\n ],\n },\n ],\n },\n // The panels of its sidebar (decision 0075): Save, the errors after a\n // failed save, the publication with Publish, the actions of the page\n { type: 'sidebar', panel: 'save' },\n { type: 'sidebar', panel: 'errors' },\n {\n type: 'sidebar',\n panel: 'publication',\n label: 'Publication',\n children: [\n { type: 'field', name: 'status' },\n { type: 'field', name: 'published_at' },\n ],\n },\n { type: 'sidebar', panel: 'actions' },\n {\n type: 'sidebar',\n label: 'Pièce jointe',\n children: [{ type: 'field', name: 'attachment' }],\n },\n ],\n },\n list: {\n columns: [\n { field: 'title', sortable: true },\n { field: 'status' },\n { id: 'updated' },\n ],\n filters: [\n { id: 'status', type: 'select' },\n { id: 'published_at', type: 'date-range', label: 'Publication' },\n ],\n sorts: ['title', 'published_at'],\n defaultSort: 'title',\n perPage: 20,\n search: true,\n },\n actions: [\n {\n id: 'publish',\n label: 'Publier',\n scope: ['item', 'selection'],\n placement: ['row', 'toolbar'],\n confirm: { message: 'Publier {count} pages ?' },\n fields: [{ name: 'notify', type: 'boolean' }],\n dryRun: true,\n },\n ],\n abilities: { viewAny: true, create: true },\n },\n {\n id: 'authors',\n label: { singular: 'auteur', plural: 'auteurs' },\n // Titles open the form, without the panel of the details.\n open: 'edit',\n fields: [\n { name: 'name', type: 'text', rules: [{ rule: 'required' }] },\n { name: 'photo', type: 'media', accept: ['image/*'] },\n ],\n },\n {\n id: 'media',\n kind: 'media',\n label: { singular: 'média', plural: 'médias' },\n // Of the built-in item actions, only these, in this order\n itemActions: ['edit', 'delete'],\n itemTitle: 'name',\n fields: [\n {\n name: 'file',\n type: 'file',\n accept: ['image/*', 'video/*', 'application/pdf'],\n rules: [{ rule: 'required' }],\n },\n { name: 'name', type: 'text' },\n { name: 'alt', type: 'text', localized: true },\n ],\n list: {\n filters: [\n {\n id: 'type',\n type: 'select',\n options: [\n { value: 'image', label: 'Images' },\n { value: 'video', label: 'Vidéos' },\n { value: 'document', label: 'Documents' },\n ],\n },\n ],\n search: true,\n },\n abilities: { viewAny: true, create: true },\n },\n ],\n menus: { main: [{ type: 'resources' }, { type: 'link', label: 'Site', url: '/' }] },\n auth: { mode: 'panneau', password: true, providers: [{ id: 'google', label: 'Google' }] },\n uploads: { mode: 'presigned' },\n };\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,0BAA2C;CACvD,OAAO;EACH,UAAU;EACV,MAAM;EACN,QAAQ;EACR,SAAS,CAAC,MAAM,IAAI;EACpB,KAAK,EAAE,SAAS,eAAe;EAC/B,WAAW;GACP;IACI,IAAI;IACJ,OAAO;KAAE,UAAU;KAAQ,QAAQ;IAAQ;IAC3C,WAAW;IACX,QAAQ;KACJ;MACI,MAAM;MACN,MAAM;MAC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QAAQ,QAAQ;IAC9B,WAAW;IACX,QAAQ;KACJ;MACI,MAAM;MACN,MAAM;MACN,QAAQ;OAAC;OAAW;OAAW;MAAiB;MAChD,OAAO,CAAC,EAAE,MAAM,WAAW,CAAC;KAChC;KACA;MAAE,MAAM;MAAQ,MAAM;KAAO;KAC7B;MAAE,MAAM;MAAO,MAAM;MAAQ,WAAW;KAAK;IACjD;IACA,MAAM;KACF,SAAS,CACL;MACI,IAAI;MACJ,MAAM;MACN,SAAS;OACL;QAAE,OAAO;QAAS,OAAO;OAAS;OAClC;QAAE,OAAO;QAAS,OAAO;OAAS;OAClC;QAAE,OAAO;QAAY,OAAO;OAAY;MAC5C;KACJ,CACJ;KACA,QAAQ;IACZ;IACA,WAAW;KAAE,SAAS;KAAM,QAAQ;IAAK;GAC7C;EACJ;EACA,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,YAAY,GAAG;GAAE,MAAM;GAAQ,OAAO;GAAQ,KAAK;EAAI,CAAC,EAAE;EAClF,MAAM;GAAE,MAAM;GAAW,UAAU;GAAM,WAAW,CAAC;IAAE,IAAI;IAAU,OAAO;GAAS,CAAC;EAAE;EACxF,SAAS,EAAE,MAAM,YAAY;CACjC;AACJ"}
|
package/dist/mock/index.d.ts
CHANGED
|
@@ -85,7 +85,9 @@ export interface MockBackend {
|
|
|
85
85
|
* `items` gives its own `abilities`. It reads abilities as clients do (decision 0046): a resource
|
|
86
86
|
* without `viewAny` answers `403` on its list, one without `create` on creates, an item without
|
|
87
87
|
* `view`, `update` or `delete` on those requests; items leave out the values of fields with
|
|
88
|
-
* `view: false`, and writes ignore those of fields with `update: false`.
|
|
88
|
+
* `view: false`, and writes ignore those of fields with `update: false`. A resource with `types`
|
|
89
|
+
* needs the `type` of a new item, among the types it can create, and its items have the fields of
|
|
90
|
+
* their type (decision 0077). Values are checked with
|
|
89
91
|
* the portable rules. Used to test the conformance kit, and to develop frontends without a real
|
|
90
92
|
* backend.
|
|
91
93
|
*/
|
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":"AASA,OAAO,EAAE,KAAK,aAAa,EAAqC,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mock/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,aAAa,EAAqC,MAAM,YAAY,CAAC;AAKnF,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAiB,MAAM,YAAY,CAAC;AAChF,OAAO,KAAK,EAER,UAAU,EAEV,IAAI,EAUP,MAAM,gBAAgB,CAAC;AAKxB,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,QAAQ,CAAC;AAE9D,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElE,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,EAAE,MAAM,KAAK,UAAU,GAAG,IAAI,CAAC;IAC3C;;;;OAIG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B;;;;OAIG;IACH,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACrC;;;OAG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,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/mock/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, ITEM_ACTION_ABILITIES, isBuiltInI
|
|
|
3
3
|
import { isRecord } from "../values.js";
|
|
4
4
|
import { checkValues } from "../rules.js";
|
|
5
5
|
import { getMediaLibraries } from "../libraries.js";
|
|
6
|
+
import { ITEM_TYPE_KEY, getResourceType, getTypeFields, hasResourceTypes } from "../resourceTypes.js";
|
|
6
7
|
import { fromSearchParams, isFilterRange, matchesFilterRange } from "../query.js";
|
|
7
8
|
import { checkWidgetData, getWidgetResource } from "../widgets.js";
|
|
8
9
|
import { readSearchQuery } from "../search.js";
|
|
@@ -209,9 +210,26 @@ function allows(item, actionId) {
|
|
|
209
210
|
function fieldsWithout(resource, ability) {
|
|
210
211
|
return new Set(resource.fields.filter((field) => field.abilities?.[ability] === false).map((field) => field.name));
|
|
211
212
|
}
|
|
212
|
-
/**
|
|
213
|
+
/**
|
|
214
|
+
* The resource as the items of a type see it (decision 0077): with the fields of the type after its
|
|
215
|
+
* own. The resource itself without a type.
|
|
216
|
+
*/
|
|
217
|
+
function withTypeFields(resource, type) {
|
|
218
|
+
return hasResourceTypes(resource) ? {
|
|
219
|
+
...resource,
|
|
220
|
+
fields: getTypeFields(resource, type)
|
|
221
|
+
} : resource;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* A body without the values of the fields the user can't see or update, and of the fields that
|
|
225
|
+
* forms leave out (`notInForm`, decision 0071), which are ignored.
|
|
226
|
+
*/
|
|
213
227
|
function writableValues(resource, body) {
|
|
214
|
-
const ignored = /* @__PURE__ */ new Set([
|
|
228
|
+
const ignored = /* @__PURE__ */ new Set([
|
|
229
|
+
...fieldsWithout(resource, "view"),
|
|
230
|
+
...fieldsWithout(resource, "update"),
|
|
231
|
+
...resource.fields.filter((field) => field.notInForm === true).map((field) => field.name)
|
|
232
|
+
]);
|
|
215
233
|
return Object.fromEntries(Object.entries(body).filter(([key]) => !ignored.has(key)));
|
|
216
234
|
}
|
|
217
235
|
/**
|
|
@@ -223,7 +241,9 @@ function writableValues(resource, body) {
|
|
|
223
241
|
* `items` gives its own `abilities`. It reads abilities as clients do (decision 0046): a resource
|
|
224
242
|
* without `viewAny` answers `403` on its list, one without `create` on creates, an item without
|
|
225
243
|
* `view`, `update` or `delete` on those requests; items leave out the values of fields with
|
|
226
|
-
* `view: false`, and writes ignore those of fields with `update: false`.
|
|
244
|
+
* `view: false`, and writes ignore those of fields with `update: false`. A resource with `types`
|
|
245
|
+
* needs the `type` of a new item, among the types it can create, and its items have the fields of
|
|
246
|
+
* their type (decision 0077). Values are checked with
|
|
227
247
|
* the portable rules. Used to test the conformance kit, and to develop frontends without a real
|
|
228
248
|
* backend.
|
|
229
249
|
*/
|
|
@@ -261,7 +281,7 @@ function createMockBackend(options) {
|
|
|
261
281
|
};
|
|
262
282
|
};
|
|
263
283
|
const present = (resource, item) => {
|
|
264
|
-
const hidden = fieldsWithout(resource, "view");
|
|
284
|
+
const hidden = fieldsWithout(withTypeFields(resource, item[ITEM_TYPE_KEY]), "view");
|
|
265
285
|
return hidden.size === 0 ? item : Object.fromEntries(Object.entries(item).filter(([key]) => !hidden.has(key)));
|
|
266
286
|
};
|
|
267
287
|
definition.resources.forEach((resource) => {
|
|
@@ -595,14 +615,24 @@ function createMockBackend(options) {
|
|
|
595
615
|
}
|
|
596
616
|
if (method === "POST") {
|
|
597
617
|
if (resource.abilities?.create === false) return problem(403, "Items of this resource can’t be created.");
|
|
598
|
-
const
|
|
599
|
-
const
|
|
618
|
+
const raw = await readBody();
|
|
619
|
+
const typed = hasResourceTypes(resource);
|
|
620
|
+
const type = typed ? getResourceType(resource, raw[ITEM_TYPE_KEY]) : void 0;
|
|
621
|
+
if (typed && type === void 0) return problem(422, "The given data was invalid.", {
|
|
622
|
+
type: "urn:panneau:problem:validation",
|
|
623
|
+
errors: { [ITEM_TYPE_KEY]: ["The type is not a type of this resource."] }
|
|
624
|
+
});
|
|
625
|
+
if (type?.abilities?.create === false) return problem(403, "Items of this type can’t be created.");
|
|
626
|
+
const ofType = withTypeFields(resource, type?.id);
|
|
627
|
+
const body = writableValues(ofType, raw);
|
|
628
|
+
const invalid = validationProblem(ofType, body, "create");
|
|
600
629
|
if (invalid !== null) return invalid;
|
|
601
|
-
const { values, problem: unresolved } = resolveValues(
|
|
630
|
+
const { values, problem: unresolved } = resolveValues(ofType, body);
|
|
602
631
|
if (unresolved !== null) return unresolved;
|
|
603
|
-
const item = withOwnTransform(
|
|
632
|
+
const item = withOwnTransform(ofType, makeItem(resource, {
|
|
604
633
|
...values,
|
|
605
|
-
id: void 0
|
|
634
|
+
id: void 0,
|
|
635
|
+
...type !== void 0 ? { [ITEM_TYPE_KEY]: type.id } : {}
|
|
606
636
|
}));
|
|
607
637
|
list.push(item);
|
|
608
638
|
return json(201, { data: present(resource, item) }, etag(item));
|
|
@@ -611,7 +641,7 @@ function createMockBackend(options) {
|
|
|
611
641
|
}
|
|
612
642
|
if (segments[2] === "fields" && segments[4] === "check" && segments.length === 5) {
|
|
613
643
|
if (method !== "POST") return problem(405, "Method not allowed.");
|
|
614
|
-
const field = resource.fields.find((candidate) => candidate.name === segments[3] && candidate.check === true);
|
|
644
|
+
const field = [...resource.fields, ...(resource.types ?? []).flatMap((type) => type.fields)].find((candidate) => candidate.name === segments[3] && candidate.check === true);
|
|
615
645
|
if (field === void 0) return problem(404, "Field not found.");
|
|
616
646
|
const body = await readBody();
|
|
617
647
|
if (typeof body.value !== "string") return problem(422, "The given data was invalid.", {
|
|
@@ -771,13 +801,15 @@ function createMockBackend(options) {
|
|
|
771
801
|
type: "urn:panneau:problem:version-conflict",
|
|
772
802
|
current: present(resource, current)
|
|
773
803
|
});
|
|
774
|
-
const
|
|
775
|
-
const
|
|
804
|
+
const ofType = withTypeFields(resource, current[ITEM_TYPE_KEY]);
|
|
805
|
+
const writable = writableValues(ofType, await readBody());
|
|
806
|
+
const body = hasResourceTypes(resource) ? Object.fromEntries(Object.entries(writable).filter(([key]) => key !== ITEM_TYPE_KEY)) : writable;
|
|
807
|
+
const invalid = validationProblem(ofType, body, "update", current);
|
|
776
808
|
if (invalid !== null) return invalid;
|
|
777
|
-
const { values, problem: unresolved } = resolveValues(
|
|
809
|
+
const { values, problem: unresolved } = resolveValues(ofType, body);
|
|
778
810
|
if (unresolved !== null) return unresolved;
|
|
779
811
|
const updates = Object.fromEntries(Object.entries(values).filter(([key]) => !RESERVED_KEYS.has(key)));
|
|
780
|
-
const updated = withOwnTransform(
|
|
812
|
+
const updated = withOwnTransform(ofType, {
|
|
781
813
|
...current,
|
|
782
814
|
...updates,
|
|
783
815
|
version: current.version === null ? null : String(Number(current.version) + 1)
|