@panneau/protocol 5.0.0-alpha.36 → 5.0.0-alpha.38
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/aggregates.d.ts +135 -0
- package/dist/aggregates.d.ts.map +1 -0
- package/dist/aggregates.js +236 -0
- package/dist/aggregates.js.map +1 -0
- package/dist/conformance/index.d.ts.map +1 -1
- package/dist/conformance/index.js +201 -24
- package/dist/conformance/index.js.map +1 -1
- package/dist/dashboards.d.ts +95 -0
- package/dist/dashboards.d.ts.map +1 -0
- package/dist/dashboards.js +140 -0
- package/dist/dashboards.js.map +1 -0
- package/dist/index.js +8 -5
- package/dist/lint.d.ts.map +1 -1
- package/dist/lint.js +249 -15
- package/dist/lint.js.map +1 -1
- package/dist/mock/index.d.ts +27 -8
- package/dist/mock/index.d.ts.map +1 -1
- package/dist/mock/index.js +42 -6
- package/dist/mock/index.js.map +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +77 -3
- package/dist/openapi.js.map +1 -1
- package/dist/periods.d.ts +49 -0
- package/dist/periods.d.ts.map +1 -0
- package/dist/periods.js +93 -0
- package/dist/periods.js.map +1 -0
- package/dist/runtime/index.d.ts +4 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +5 -2
- package/dist/schemas/action.d.ts +1 -0
- package/dist/schemas/action.d.ts.map +1 -1
- package/dist/schemas/definition.d.ts +127 -0
- package/dist/schemas/definition.d.ts.map +1 -1
- package/dist/schemas/definition.js +8 -3
- package/dist/schemas/definition.js.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 +283 -1
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +11 -5
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/list.d.ts +11 -0
- package/dist/schemas/list.d.ts.map +1 -1
- package/dist/schemas/list.js +8 -2
- package/dist/schemas/list.js.map +1 -1
- package/dist/schemas/resource.d.ts +100 -0
- package/dist/schemas/resource.d.ts.map +1 -1
- package/dist/schemas/resource.js +9 -1
- package/dist/schemas/resource.js.map +1 -1
- package/dist/schemas/widget.d.ts +62 -2
- package/dist/schemas/widget.d.ts.map +1 -1
- package/dist/schemas/widget.js +36 -8
- package/dist/schemas/widget.js.map +1 -1
- package/dist/widgets.d.ts +48 -9
- package/dist/widgets.d.ts.map +1 -1
- package/dist/widgets.js +81 -10
- package/dist/widgets.js.map +1 -1
- package/package.json +1 -1
- package/schema/boot.schema.json +235 -66
- package/schema/definition.schema.json +235 -66
- package/schema/openapi.json +508 -7
package/dist/lint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,O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Q,EAAE;GACxD,CAAC;GACD;EACJ;EACA,IAAI,OAAO,SAAS,UAAU,SAAS,MAAM,eAAe,UACxD,OAAO,KAAK;GACR,MAAM,GAAG,KAAK;GACd,SAAS,iBAAiB,SAAS,GAAG;EAC1C,CAAC;EAEL,MAAM,UAAU,IAAI,KAAK,SAAS,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
|
+
{"version":3,"file":"lint.js","names":[],"sources":["../src/lint.ts"],"sourcesContent":["import { parseAggregateGroup, parseAggregateMeasure } from './aggregates';\nimport { DASHBOARD_COMPONENT, HOME_PAGE, getSummaryPeriodFilter } from './dashboards';\nimport { ITEM_TYPE_KEY } from './resourceTypes';\nimport type {\n DefinitionInput,\n Field,\n LayoutNode,\n OverviewPeriod,\n ResourceInput,\n Widget,\n} from './schemas';\nimport type { ValidationIssue } from './validate';\nimport {\n GROUPED_WIDGET_TYPES,\n RESOURCE_WIDGET_TYPES,\n WIDGET_RESERVED_QUERY_PARAMS,\n getWidgetResource,\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\n/** Field types whose values can be summed: numbers, and amounts of `money` of one currency. */\nconst SUMMABLE_TYPES = ['number', 'range', 'duration', 'money'];\n/** Field types whose days can be grouped by. */\nconst DATE_TYPES = ['date', 'datetime'];\n/** Field types whose values are structures that can't be grouped by. */\nconst UNGROUPABLE_TYPES = [\n 'richtext',\n 'media',\n 'image',\n 'file',\n 'group',\n 'repeater',\n 'json',\n 'embed',\n 'location',\n 'address',\n 'link',\n 'daterange',\n 'money',\n];\n\n/**\n * The aggregates of a list (decision 0084): each one names a field of the resource that the user\n * can view, `sum` a number or `money` of one currency, `dates` a date, `groupBy` a value.\n */\nfunction checkAggregates(resource: ResourceInput, path: string, issues: ValidationIssue[]) {\n const aggregates = resource.list?.aggregates;\n if (aggregates === undefined) {\n return;\n }\n const fields = allFields(resource, path).map(({ field }) => field);\n const check = (key: 'sum' | 'groupBy' | 'dates', accepts: (field: Field) => string | null) => {\n (aggregates[key] ?? []).forEach((name, index) => {\n const issuePath = `${path}.list.aggregates.${key}.${index}`;\n const field = fields.find((candidate) => candidate.name === name);\n const message =\n field === undefined\n ? `No field named \\`${name}\\`.`\n : field.abilities?.view === false\n ? `The user can't view \\`${name}\\`: it can't be aggregated.`\n : accepts(field);\n if (message !== null) {\n issues.push({ path: issuePath, message });\n }\n });\n };\n check('sum', (field) => {\n if (!SUMMABLE_TYPES.includes(field.type)) {\n return `\\`${field.name}\\` can't be summed: only \\`number\\`, \\`range\\`, \\`duration\\` and \\`money\\` fields can.`;\n }\n const currency = (field.settings as { currency?: unknown } | undefined)?.currency;\n return field.type === 'money' && typeof currency !== 'string'\n ? `\\`${field.name}\\` can't be summed: amounts add up only in one \\`currency\\`.`\n : null;\n });\n check('dates', (field) =>\n DATE_TYPES.includes(field.type)\n ? null\n : `\\`${field.name}\\` must be a \\`date\\` or a \\`datetime\\` to be grouped by period.`,\n );\n check('groupBy', (field) =>\n UNGROUPABLE_TYPES.includes(field.type)\n ? `The items can't be grouped by a \\`${field.type}\\` field.`\n : null,\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 checkAggregates(resource, path, issues);\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 if (resource.summary !== undefined) {\n const summaryPath = `resources.${index}.summary`;\n const period = resource.summary.period;\n if (period !== undefined) {\n checkPeriod(period, `${summaryPath}.period`, issues);\n if (getSummaryPeriodFilter(resource) === null) {\n issues.push({\n path: `${summaryPath}.period${period.filter !== undefined ? '.filter' : ''}`,\n message:\n period.filter !== undefined\n ? `The list of \\`${resource.id}\\` has no \\`date-range\\` filter \\`${period.filter}\\`.`\n : `The period of a summary is a \\`date-range\\` filter of the list of \\`${resource.id}\\`: it has none.`,\n });\n }\n }\n checkWidgets(definition, resource.summary.widgets, `${summaryPath}.widgets`, issues, {\n summaryOf: resource.id,\n hasPeriod: period !== undefined,\n });\n }\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 // A field without transforms keeps no crop (decision 0087).\n if (field.transforms === false) {\n if (field.ratios !== undefined && field.ratios.length > 0) {\n issues.push({\n path: `${path}.ratios`,\n message: 'A field without transforms has no editor to suggest ratios.',\n });\n }\n field.rules?.forEach((rule, ruleIndex) => {\n if (rule.rule === 'crop') {\n issues.push({\n path: `${path}.rules.${String(ruleIndex)}`,\n message:\n 'A field without transforms keeps no crop for the `crop` rule.',\n });\n }\n });\n }\n }\n });\n });\n checkDashboards(definition, issues);\n return issues;\n}\n\n/**\n * The dashboards (decision 0084): the widgets of each page whose component is the built-in\n * `dashboard`, and those of `dashboard`, the shorthand of the home page, unless `pages.home` has\n * its own, which can't come with them. Only a `dashboard` page has widgets.\n */\nfunction checkDashboards(definition: DefinitionInput, issues: ValidationIssue[]) {\n const home = definition.pages?.[HOME_PAGE];\n const homePeriod =\n (home?.component === DASHBOARD_COMPONENT ? home.period : undefined) ??\n definition.dashboard?.period;\n Object.entries(definition.pages ?? {}).forEach(([id, page]) => {\n if (page.period !== undefined) {\n if (page.component !== DASHBOARD_COMPONENT) {\n issues.push({\n path: `pages.${id}.period`,\n message: `Only a \\`${DASHBOARD_COMPONENT}\\` page has a period.`,\n });\n } else {\n checkPeriod(page.period, `pages.${id}.period`, issues);\n }\n }\n if (page.widgets === undefined) {\n return;\n }\n if (page.component !== DASHBOARD_COMPONENT) {\n issues.push({\n path: `pages.${id}.widgets`,\n message: `Only a \\`${DASHBOARD_COMPONENT}\\` page has widgets.`,\n });\n return;\n }\n checkWidgets(definition, page.widgets, `pages.${id}.widgets`, issues, {\n hasPeriod: (id === HOME_PAGE ? homePeriod : page.period) !== undefined,\n });\n });\n if (definition.dashboard === undefined) {\n return;\n }\n if (definition.dashboard.period !== undefined) {\n if (home?.component === DASHBOARD_COMPONENT && home.period !== undefined) {\n issues.push({\n path: 'dashboard.period',\n message: `\\`pages.${HOME_PAGE}.period\\` replaces it: set only one.`,\n });\n } else {\n checkPeriod(definition.dashboard.period, 'dashboard.period', issues);\n }\n }\n if (home?.component === DASHBOARD_COMPONENT && home.widgets !== undefined) {\n if (definition.dashboard.widgets.length > 0) {\n issues.push({\n path: 'dashboard.widgets',\n message: `\\`pages.${HOME_PAGE}.widgets\\` replaces them: set only one.`,\n });\n }\n return;\n }\n checkWidgets(definition, definition.dashboard.widgets, 'dashboard.widgets', issues, {\n hasPeriod: homePeriod !== undefined,\n });\n}\n\n/** A period (decision 0084): its options once each, and its default among them. */\nfunction checkPeriod(period: OverviewPeriod, path: string, issues: ValidationIssue[]) {\n if (new Set(period.options).size !== period.options.length) {\n issues.push({ path: `${path}.options`, message: 'Each period is offered once.' });\n }\n if (period.default !== undefined && !period.options.includes(period.default)) {\n issues.push({\n path: `${path}.default`,\n message: `\\`${period.default}\\` isn't one of the options.`,\n });\n }\n}\n\nconst FILTER_PARAM = /^filter\\[([^\\]]+)\\]/;\n\n/** The settings of a widget that go with a `resource`. */\nconst RESOURCE_SETTINGS = ['query', 'measure', 'group', 'target'] as const;\n\n/**\n * The measure and the group of a widget on a resource (decision 0084): a `sum:` and a group name\n * aggregates of its list, a `series` needs a period of a date, a `breakdown` a field of `groupBy`,\n * and a `list` has neither.\n */\nfunction checkAggregateSettings(\n widget: { type: string; settings?: Record<string, unknown> | undefined },\n resource: ResourceInput,\n path: string,\n issues: ValidationIssue[],\n) {\n const settings = widget.settings ?? {};\n const aggregates = resource.list?.aggregates ?? {};\n const grouped = (GROUPED_WIDGET_TYPES as readonly string[]).includes(widget.type);\n if (widget.type === 'list') {\n ['measure', 'group'].forEach((key) => {\n if (settings[key] !== undefined) {\n issues.push({\n path: `${path}.settings.${key}`,\n message: `A \\`list\\` shows items: it has no \\`${key}\\`.`,\n });\n }\n });\n return;\n }\n if (settings.measure !== undefined) {\n const measure =\n typeof settings.measure === 'string' ? parseAggregateMeasure(settings.measure) : null;\n if (measure === null) {\n issues.push({\n path: `${path}.settings.measure`,\n message: 'The measure must be `count` or `sum:{field}`.',\n });\n } else if (measure.type === 'sum' && !(aggregates.sum ?? []).includes(measure.field)) {\n issues.push({\n path: `${path}.settings.measure`,\n message: `The list of \\`${resource.id}\\` can't sum \\`${measure.field}\\`: it isn't in the \\`sum\\` of its aggregates.`,\n });\n }\n }\n if (!grouped) {\n if (settings.group !== undefined) {\n issues.push({\n path: `${path}.settings.group`,\n message: `A \\`${widget.type}\\` isn't grouped: only a \\`series\\` and a \\`breakdown\\` are.`,\n });\n }\n return;\n }\n const group = typeof settings.group === 'string' ? parseAggregateGroup(settings.group) : null;\n if (widget.type === 'series') {\n if (group?.type !== 'period') {\n issues.push({\n path: `${path}.settings.group`,\n message:\n 'A `series` on a resource needs a `group` on the period of a date: `day:created_at`.',\n });\n } else if (!(aggregates.dates ?? []).includes(group.field)) {\n issues.push({\n path: `${path}.settings.group`,\n message: `The list of \\`${resource.id}\\` can't group by \\`${group.field}\\`: it isn't in the \\`dates\\` of its aggregates.`,\n });\n }\n return;\n }\n if (group?.type !== 'field') {\n issues.push({\n path: `${path}.settings.group`,\n message: 'A `breakdown` on a resource needs a `group` on a field: `status`.',\n });\n } else if (!(aggregates.groupBy ?? []).includes(group.field)) {\n issues.push({\n path: `${path}.settings.group`,\n message: `The list of \\`${resource.id}\\` can't group by \\`${group.field}\\`: it isn't in the \\`groupBy\\` of its aggregates.`,\n });\n }\n}\n\n/**\n * The widgets of a dashboard or of the summary of a resource (decisions 0064 and 0084): unique ids,\n * and the built-in types on a resource that exists, with filters of its list and aggregates it\n * declares. A `stat` that counts reads the total of the list, so the list can't be paged with\n * cursors, which give no total. Only the widgets of a summary follow its list (`followsList`): those\n * on its resource, and those with data of their own.\n */\nfunction checkWidgets(\n definition: DefinitionInput,\n widgets: Widget[],\n widgetsPath: string,\n issues: ValidationIssue[],\n { summaryOf, hasPeriod = false }: { summaryOf?: string; hasPeriod?: boolean } = {},\n) {\n const ids = new Set<string>();\n widgets.forEach((widget, index) => {\n const path = `${widgetsPath}.${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 const follows = widget.settings?.followsList;\n if (follows !== undefined) {\n const other = getWidgetResource(widget)?.resource;\n if (summaryOf === undefined) {\n issues.push({\n path: `${path}.settings.followsList`,\n message: 'Only the widgets of the summary of a resource follow its list.',\n });\n } else if (other !== undefined && other !== summaryOf) {\n issues.push({\n path: `${path}.settings.followsList`,\n message: `A widget on \\`${other}\\` doesn't follow the list of \\`${summaryOf}\\`.`,\n });\n }\n }\n if (!isBuiltInWidgetType(widget.type)) {\n return;\n }\n const settings = widget.settings ?? {};\n const onResource = typeof settings.resource === 'string';\n if (settings.period !== undefined && !hasPeriod) {\n issues.push({\n path: `${path}.settings.period`,\n message: `Its ${summaryOf !== undefined ? 'summary' : 'dashboard'} has no \\`period\\`.`,\n });\n }\n if (!onResource) {\n if (typeof settings.period === 'string') {\n issues.push({\n path: `${path}.settings.period`,\n message:\n '`period` names a `date-range` filter of the list of its `resource`: without one, it can only be `false`.',\n });\n }\n RESOURCE_SETTINGS.forEach((key) => {\n if (settings[key] !== undefined) {\n issues.push({\n path: `${path}.settings.${key}`,\n message: `\\`${key}\\` goes with a \\`resource\\`.`,\n });\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: it can't 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 (settings.target !== undefined && widget.type !== 'stat') {\n issues.push({\n path: `${path}.settings.target`,\n message: 'Only a `stat` has a `target`.',\n });\n }\n checkAggregateSettings(widget, resource, path, issues);\n const sums = typeof settings.measure === 'string' && settings.measure.startsWith('sum:');\n if (widget.type === 'stat' && !sums && 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\\` that counts.`,\n });\n }\n if (\n typeof settings.period === 'string' &&\n !(resource.list?.filters ?? []).some(\n (filter) => filter.id === settings.period && filter.type === 'date-range',\n )\n ) {\n issues.push({\n path: `${path}.settings.period`,\n message: `The list of \\`${resource.id}\\` has no \\`date-range\\` filter \\`${settings.period}\\`.`,\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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AAQ,SAAS,MAAM,eAAe,UACjE,OAAO,KAAK;GACR,MAAM,GAAG,KAAK;GACd,SAAS,iBAAiB,SAAS,GAAG;EAC1C,CAAC;EAEL,IACI,OAAO,SAAS,WAAW,YAC3B,EAAE,SAAS,MAAM,WAAW,CAAC,EAAA,CAAG,MAC3B,WAAW,OAAO,OAAO,SAAS,UAAU,OAAO,SAAS,YACjE,GAEA,OAAO,KAAK;GACR,MAAM,GAAG,KAAK;GACd,SAAS,iBAAiB,SAAS,GAAG,oCAAoC,SAAS,OAAO;EAC9F,CAAC;EAEL,MAAM,UAAU,IAAI,KAAK,SAAS,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"}
|
package/dist/mock/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type ContextValues } from '../context.js';
|
|
2
|
+
import { type WidgetListQuery } from '../dashboards.js';
|
|
3
|
+
import type { WidgetPeriod } from '../periods.js';
|
|
2
4
|
import type { ContextOption, DefinitionInput } from '../schemas/index.js';
|
|
3
5
|
import type { EmbedValue, Item } from '../schemas/api.js';
|
|
4
6
|
import { type MockAuthOptions } from './auth.js';
|
|
@@ -35,11 +37,16 @@ export interface MockBackendOptions {
|
|
|
35
37
|
*/
|
|
36
38
|
auth?: MockAuthOptions;
|
|
37
39
|
/**
|
|
38
|
-
* The data of `GET /dashboard/widgets/{widget}`, per widget id (decision 0064): the
|
|
39
|
-
* function that returns it for the current context, or a `Response` to answer
|
|
40
|
-
* a slow or failing widget).
|
|
41
|
-
*
|
|
42
|
-
*
|
|
40
|
+
* The data of `GET /dashboard/widgets/{widget}?page={page}`, per widget id (decision 0064): the
|
|
41
|
+
* data, a function that returns it for the current context and page, or a `Response` to answer
|
|
42
|
+
* as is (a `403`, a slow or failing widget). It answers the widgets of every dashboard page
|
|
43
|
+
* (decision 0084), and those of the home page without `page`, and with `?resource={resource}`,
|
|
44
|
+
* those of the summary of a resource, whose functions get the filters and the search of the
|
|
45
|
+
* list. Data that doesn't have the shape of a built-in type is a `500` problem that names the
|
|
46
|
+
* wrong keys, as a backend answers it. Widgets without data, built-in widgets on a resource, and
|
|
47
|
+
* widgets that aren't on the page or in the summary are a `404`; `page` and `resource` together,
|
|
48
|
+
* or a wrong period, are a `422`, and the summary of a resource that can't be listed a `403`.
|
|
49
|
+
* Functions get the period of the overview (decision 0084).
|
|
43
50
|
*/
|
|
44
51
|
widgets?: Record<string, MockWidget>;
|
|
45
52
|
/**
|
|
@@ -57,6 +64,17 @@ export type MockWidget = Response | Record<string, unknown> | ((context: MockWid
|
|
|
57
64
|
export interface MockWidgetContext {
|
|
58
65
|
/** The values of the context of the request. */
|
|
59
66
|
context: ContextValues;
|
|
67
|
+
/**
|
|
68
|
+
* The page of the dashboard of the widget: `home` without `page` in the request, `null` for a
|
|
69
|
+
* widget of a summary.
|
|
70
|
+
*/
|
|
71
|
+
page: string | null;
|
|
72
|
+
/** The resource whose summary holds the widget, or `null` for a widget of a dashboard page. */
|
|
73
|
+
resource: string | null;
|
|
74
|
+
/** In a summary: the filters and the search of the list (`filter[…]`, `q`). Empty otherwise. */
|
|
75
|
+
query: WidgetListQuery;
|
|
76
|
+
/** The period of the overview (`period[option]`, `period[from]`, `period[to]`), or `null`. */
|
|
77
|
+
period: WidgetPeriod | null;
|
|
60
78
|
/** The current items of a resource, in the context. */
|
|
61
79
|
items: (resource: string) => Item[];
|
|
62
80
|
}
|
|
@@ -87,9 +105,10 @@ export interface MockBackend {
|
|
|
87
105
|
* `view`, `update` or `delete` on those requests; items leave out the values of fields with
|
|
88
106
|
* `view: false`, and writes ignore those of fields with `update: false`. A resource with `types`
|
|
89
107
|
* 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).
|
|
91
|
-
*
|
|
92
|
-
*
|
|
108
|
+
* their type (decision 0077). A list with `aggregates` answers
|
|
109
|
+
* `GET /resources/{resource}/aggregate` with `aggregateItems()` (decision 0084). Values are checked
|
|
110
|
+
* with the portable rules. Used to test the conformance kit, and to develop frontends without a
|
|
111
|
+
* real backend.
|
|
93
112
|
*/
|
|
94
113
|
export declare function createMockBackend(options: MockBackendOptions): MockBackend;
|
|
95
114
|
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":"AAUA,OAAO,EAAE,KAAK,aAAa,EAAqC,MAAM,YAAY,CAAC;AACnF,OAAO,EACH,KAAK,eAAe,EAIvB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI/C,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,KA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AQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,gGAAgG;IAChG,KAAK,EAAE,eAAe,CAAC;IACvB,8FAA8F;IAC9F,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,uDAAuD;IACvD,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,EAAE,CAAC;CACvC;AAED,kFAAkF;AAClF,MAAM,WAAW,kBAAkB;IAC/B;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,KAAK,aAAa,EAAE,CAAC;IACnE,6FAA6F;IAC7F,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;CAC5E;AAED,MAAM,WAAW,WAAW;IACxB,oEAAoE;IACpE,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAChF,uCAAuC;IACvC,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,EAAE,CAAC;CACvC;AA2RD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CA08B1E;AAED,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/mock/index.js
CHANGED
|
@@ -6,6 +6,8 @@ import { getMediaLibraries } from "../libraries.js";
|
|
|
6
6
|
import { ITEM_TYPE_KEY, getResourceType, getTypeFields, hasResourceTypes } from "../resourceTypes.js";
|
|
7
7
|
import { fromSearchParams, isFilterRange, matchesFilterRange } from "../query.js";
|
|
8
8
|
import { checkWidgetData, getWidgetResource } from "../widgets.js";
|
|
9
|
+
import { aggregateItems, getFilterRange, readAggregateQuery } from "../aggregates.js";
|
|
10
|
+
import { getDashboardWidgets, getSummaryWidgets, readWidgetDataQuery } from "../dashboards.js";
|
|
9
11
|
import { readSearchQuery } from "../search.js";
|
|
10
12
|
import { contextBefore, parseContextHeader } from "../context.js";
|
|
11
13
|
import { createMockAuth } from "./auth.js";
|
|
@@ -243,9 +245,10 @@ function writableValues(resource, body) {
|
|
|
243
245
|
* `view`, `update` or `delete` on those requests; items leave out the values of fields with
|
|
244
246
|
* `view: false`, and writes ignore those of fields with `update: false`. A resource with `types`
|
|
245
247
|
* 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).
|
|
247
|
-
*
|
|
248
|
-
*
|
|
248
|
+
* their type (decision 0077). A list with `aggregates` answers
|
|
249
|
+
* `GET /resources/{resource}/aggregate` with `aggregateItems()` (decision 0084). Values are checked
|
|
250
|
+
* with the portable rules. Used to test the conformance kit, and to develop frontends without a
|
|
251
|
+
* real backend.
|
|
249
252
|
*/
|
|
250
253
|
function createMockBackend(options) {
|
|
251
254
|
const { definition, items = {} } = options;
|
|
@@ -494,12 +497,26 @@ function createMockBackend(options) {
|
|
|
494
497
|
return values;
|
|
495
498
|
};
|
|
496
499
|
/** The definition for the values of the context: the `value` and `valueLabel` of each param. */
|
|
497
|
-
const answerWidget = async (id, values, inScope) => {
|
|
498
|
-
const
|
|
500
|
+
const answerWidget = async (id, params, values, inScope) => {
|
|
501
|
+
const read = readWidgetDataQuery(params);
|
|
502
|
+
if (read.errors !== void 0) return problem(422, "The given data was invalid.", {
|
|
503
|
+
type: "urn:panneau:problem:validation",
|
|
504
|
+
errors: read.errors
|
|
505
|
+
});
|
|
506
|
+
const current = definitionFor(values);
|
|
507
|
+
if (read.resource !== void 0) {
|
|
508
|
+
const summarized = current.resources.find((candidate) => candidate.id === read.resource);
|
|
509
|
+
if (summarized?.summary !== void 0 && summarized.abilities?.viewAny === false) return problem(403, "This resource can’t be listed.");
|
|
510
|
+
}
|
|
511
|
+
const widget = (read.resource !== void 0 ? getSummaryWidgets(current, read.resource) : getDashboardWidgets(current, read.page)).find((candidate) => candidate.id === id);
|
|
499
512
|
const data = options.widgets?.[id];
|
|
500
513
|
if (widget === void 0 || getWidgetResource(widget) !== null || data === void 0) return problem(404, "Widget not found.");
|
|
501
514
|
const answer = typeof data === "function" ? await data({
|
|
502
515
|
context: values,
|
|
516
|
+
page: read.page ?? null,
|
|
517
|
+
resource: read.resource ?? null,
|
|
518
|
+
query: read.query ?? {},
|
|
519
|
+
period: read.period,
|
|
503
520
|
items: (resource) => inScope(resource, store.get(resource) ?? [])
|
|
504
521
|
}) : data;
|
|
505
522
|
if (answer instanceof Response) return answer;
|
|
@@ -570,7 +587,7 @@ function createMockBackend(options) {
|
|
|
570
587
|
errors: { url: ["This URL can’t be embedded."] }
|
|
571
588
|
});
|
|
572
589
|
}
|
|
573
|
-
if (segments.length === 3 && segments[0] === "dashboard" && segments[1] === "widgets" && method === "GET") return answerWidget(segments[2] ?? "", context, inScope);
|
|
590
|
+
if (segments.length === 3 && segments[0] === "dashboard" && segments[1] === "widgets" && method === "GET") return answerWidget(segments[2] ?? "", url.searchParams, context, inScope);
|
|
574
591
|
if (segments.length === 1 && segments[0] === "search" && method === "GET") return search(url.searchParams, inScope);
|
|
575
592
|
if (segments[0] === "uploads") return handleUploads(segments, method, readBody);
|
|
576
593
|
if (segments[0] !== "resources" || segments[1] === void 0) return problem(404, "Not found.");
|
|
@@ -578,6 +595,25 @@ function createMockBackend(options) {
|
|
|
578
595
|
const list = resource !== void 0 ? store.get(resource.id) : void 0;
|
|
579
596
|
if (resource === void 0 || list === void 0) return problem(404, "Resource not found.");
|
|
580
597
|
const scoped = inScope(resource.id, list);
|
|
598
|
+
if (segments.length === 3 && segments[2] === "aggregate" && method === "GET") {
|
|
599
|
+
if (resource.abilities?.viewAny === false) return problem(403, "This resource can’t be listed.");
|
|
600
|
+
const aggregates = resource.list?.aggregates;
|
|
601
|
+
if (aggregates === void 0) return problem(404, "This resource has no aggregates.");
|
|
602
|
+
const read = readAggregateQuery(url.searchParams, aggregates);
|
|
603
|
+
if (read.errors !== void 0) return problem(422, "The given data was invalid.", {
|
|
604
|
+
type: "urn:panneau:problem:validation",
|
|
605
|
+
errors: read.errors
|
|
606
|
+
});
|
|
607
|
+
const query = fromSearchParams(url.searchParams);
|
|
608
|
+
const group = read.query.group;
|
|
609
|
+
return json(200, aggregateItems(applyQuery(scoped, {
|
|
610
|
+
...query,
|
|
611
|
+
sort: []
|
|
612
|
+
}), read.query, {
|
|
613
|
+
fields: [...resource.fields, ...(resource.types ?? []).flatMap((type) => type.fields)],
|
|
614
|
+
range: group?.type === "period" ? getFilterRange(query, group.field) : void 0
|
|
615
|
+
}));
|
|
616
|
+
}
|
|
581
617
|
if (segments.length === 2) {
|
|
582
618
|
if (method === "GET") {
|
|
583
619
|
if (resource.abilities?.viewAny === false) return problem(403, "This resource can’t be listed.");
|