@panneau/protocol 5.0.0-alpha.17 → 5.0.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/compound.d.ts +20 -0
  2. package/dist/compound.d.ts.map +1 -0
  3. package/dist/compound.js +27 -0
  4. package/dist/compound.js.map +1 -0
  5. package/dist/conformance/index.d.ts.map +1 -1
  6. package/dist/conformance/index.js +94 -0
  7. package/dist/conformance/index.js.map +1 -1
  8. package/dist/constants.d.ts +5 -0
  9. package/dist/constants.d.ts.map +1 -1
  10. package/dist/constants.js +6 -1
  11. package/dist/constants.js.map +1 -1
  12. package/dist/index.js +8 -5
  13. package/dist/libraries.d.ts +10 -0
  14. package/dist/libraries.d.ts.map +1 -1
  15. package/dist/libraries.js +8 -1
  16. package/dist/libraries.js.map +1 -1
  17. package/dist/lint.d.ts.map +1 -1
  18. package/dist/lint.js +59 -0
  19. package/dist/lint.js.map +1 -1
  20. package/dist/mock/index.d.ts +28 -1
  21. package/dist/mock/index.d.ts.map +1 -1
  22. package/dist/mock/index.js +65 -6
  23. package/dist/mock/index.js.map +1 -1
  24. package/dist/openapi.d.ts.map +1 -1
  25. package/dist/openapi.js +13 -6
  26. package/dist/openapi.js.map +1 -1
  27. package/dist/rules.d.ts.map +1 -1
  28. package/dist/rules.js +4 -2
  29. package/dist/rules.js.map +1 -1
  30. package/dist/runtime/index.d.ts +3 -1
  31. package/dist/runtime/index.d.ts.map +1 -1
  32. package/dist/runtime/index.js +6 -4
  33. package/dist/schemas/action.d.ts +1 -0
  34. package/dist/schemas/action.d.ts.map +1 -1
  35. package/dist/schemas/action.js +1 -0
  36. package/dist/schemas/action.js.map +1 -1
  37. package/dist/schemas/api.d.ts +15 -0
  38. package/dist/schemas/api.d.ts.map +1 -1
  39. package/dist/schemas/api.js +7 -2
  40. package/dist/schemas/api.js.map +1 -1
  41. package/dist/schemas/common.js +1 -1
  42. package/dist/schemas/common.js.map +1 -1
  43. package/dist/schemas/definition.d.ts +5 -9
  44. package/dist/schemas/definition.d.ts.map +1 -1
  45. package/dist/schemas/definition.js +3 -9
  46. package/dist/schemas/definition.js.map +1 -1
  47. package/dist/schemas/field.js +2 -2
  48. package/dist/schemas/field.js.map +1 -1
  49. package/dist/schemas/index.d.ts +81 -2
  50. package/dist/schemas/index.d.ts.map +1 -1
  51. package/dist/schemas/index.js +11 -3
  52. package/dist/schemas/index.js.map +1 -1
  53. package/dist/schemas/resource.d.ts +1 -0
  54. package/dist/schemas/resource.d.ts.map +1 -1
  55. package/dist/schemas/resource.js +1 -1
  56. package/dist/schemas/resource.js.map +1 -1
  57. package/dist/schemas/widget.d.ts +109 -0
  58. package/dist/schemas/widget.d.ts.map +1 -0
  59. package/dist/schemas/widget.js +74 -0
  60. package/dist/schemas/widget.js.map +1 -0
  61. package/dist/widgets.d.ts +42 -0
  62. package/dist/widgets.d.ts.map +1 -0
  63. package/dist/widgets.js +130 -0
  64. package/dist/widgets.js.map +1 -0
  65. package/package.json +1 -1
  66. package/schema/boot.schema.json +41 -5
  67. package/schema/definition.schema.json +41 -5
  68. package/schema/openapi.json +297 -15
@@ -0,0 +1,20 @@
1
+ import type { Field } from './schemas/field.js';
2
+ /**
3
+ * The shape of a value made of nested fields: an object of its `fields` (`group`), or a list of
4
+ * them (`repeater`).
5
+ */
6
+ export type NestedShape = 'group' | 'repeater';
7
+ /** Whether a field type is built in. */
8
+ export declare function isBuiltInFieldType(type: string): boolean;
9
+ /**
10
+ * Whether a field is a compound field (decision 0065): a type that isn't built in, provided by a
11
+ * plugin, that carries its sub-fields in `fields`.
12
+ */
13
+ export declare function isCompoundField(field: Pick<Field, 'type' | 'fields'>): boolean;
14
+ /**
15
+ * The shape of a field's value when it is made of nested fields: `group` and `repeater` fields,
16
+ * and compound fields, an object of their `fields`, or a list of them with `multiple`
17
+ * (decision 0065). Other fields return `null`.
18
+ */
19
+ export declare function getNestedShape(field: Pick<Field, 'type' | 'fields' | 'multiple'>): NestedShape | null;
20
+ //# sourceMappingURL=compound.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compound.d.ts","sourceRoot":"","sources":["../src/compound.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,UAAU,CAAC;AAE/C,wCAAwC;AACxC,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAExD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,GAAG,OAAO,CAE9E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC1B,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAC,GACnD,WAAW,GAAG,IAAI,CAQpB"}
@@ -0,0 +1,27 @@
1
+ import { BUILT_IN_FIELD_TYPES } from "./constants.js";
2
+ //#region src/compound.ts
3
+ /** Whether a field type is built in. */
4
+ function isBuiltInFieldType(type) {
5
+ return BUILT_IN_FIELD_TYPES.includes(type);
6
+ }
7
+ /**
8
+ * Whether a field is a compound field (decision 0065): a type that isn't built in, provided by a
9
+ * plugin, that carries its sub-fields in `fields`.
10
+ */
11
+ function isCompoundField(field) {
12
+ return field.fields !== void 0 && !isBuiltInFieldType(field.type);
13
+ }
14
+ /**
15
+ * The shape of a field's value when it is made of nested fields: `group` and `repeater` fields,
16
+ * and compound fields, an object of their `fields`, or a list of them with `multiple`
17
+ * (decision 0065). Other fields return `null`.
18
+ */
19
+ function getNestedShape(field) {
20
+ if (field.type === "group" || field.type === "repeater") return field.type;
21
+ if (isCompoundField(field)) return field.multiple === true ? "repeater" : "group";
22
+ return null;
23
+ }
24
+ //#endregion
25
+ export { getNestedShape, isBuiltInFieldType, isCompoundField };
26
+
27
+ //# sourceMappingURL=compound.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compound.js","names":[],"sources":["../src/compound.ts"],"sourcesContent":["// Fields made of other fields: `group`, `repeater`, and the compound fields of plugins\n// (decision 0065). This module doesn't import zod.\nimport { BUILT_IN_FIELD_TYPES } from './constants';\nimport type { Field } from './schemas/field';\n\n/**\n * The shape of a value made of nested fields: an object of its `fields` (`group`), or a list of\n * them (`repeater`).\n */\nexport type NestedShape = 'group' | 'repeater';\n\n/** Whether a field type is built in. */\nexport function isBuiltInFieldType(type: string): boolean {\n return (BUILT_IN_FIELD_TYPES as readonly string[]).includes(type);\n}\n\n/**\n * Whether a field is a compound field (decision 0065): a type that isn't built in, provided by a\n * plugin, that carries its sub-fields in `fields`.\n */\nexport function isCompoundField(field: Pick<Field, 'type' | 'fields'>): boolean {\n return field.fields !== undefined && !isBuiltInFieldType(field.type);\n}\n\n/**\n * The shape of a field's value when it is made of nested fields: `group` and `repeater` fields,\n * and compound fields, an object of their `fields`, or a list of them with `multiple`\n * (decision 0065). Other fields return `null`.\n */\nexport function getNestedShape(\n field: Pick<Field, 'type' | 'fields' | 'multiple'>,\n): NestedShape | null {\n if (field.type === 'group' || field.type === 'repeater') {\n return field.type;\n }\n if (isCompoundField(field)) {\n return field.multiple === true ? 'repeater' : 'group';\n }\n return null;\n}\n"],"mappings":";;;AAYA,SAAgB,mBAAmB,MAAuB;CACtD,OAAQ,qBAA2C,SAAS,IAAI;AACpE;;;;;AAMA,SAAgB,gBAAgB,OAAgD;CAC5E,OAAO,MAAM,WAAW,KAAA,KAAa,CAAC,mBAAmB,MAAM,IAAI;AACvE;;;;;;AAOA,SAAgB,eACZ,OACkB;CAClB,IAAI,MAAM,SAAS,WAAW,MAAM,SAAS,YACzC,OAAO,MAAM;CAEjB,IAAI,gBAAgB,KAAK,GACrB,OAAO,MAAM,aAAa,OAAO,aAAa;CAElD,OAAO;AACX"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":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,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAU9D"}
@@ -3,8 +3,10 @@ import { CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE } from "../constants.js";
3
3
  import { isEqual, isFilled } from "../values.js";
4
4
  import { getLinkTypes } from "../links.js";
5
5
  import { isCursorPage, toSearchParams } from "../query.js";
6
+ import { getWidgetResource, isBuiltInWidgetType } from "../widgets.js";
6
7
  import { isSearchableResource, toSearchQueryParams } from "../search.js";
7
8
  import { formatContextHeader } from "../context.js";
9
+ import { widgetDataSchemas } from "../schemas/widget.js";
8
10
  import { Definition, User } from "../schemas/definition.js";
9
11
  import { ActionResult, ContextOptionsResponse, FieldCheckResponse, ItemResponse, ListResponse, Passkey, Problem, SearchResponse, TwoFactorStatus, UploadSignResponse, WebAuthnOptions } from "../schemas/api.js";
10
12
  import { z } from "zod";
@@ -646,6 +648,56 @@ async function runConformance(options) {
646
648
  if (failure !== null) check.expect(failure.errors?.[parameter] !== void 0, `${toSearchQueryParams(query)}: the 422 problem must have errors.${parameter}.`);
647
649
  }
648
650
  });
651
+ const widgets = () => definition?.dashboard?.widgets ?? [];
652
+ await run("dashboard.widgets", "GET /dashboard/widgets/{widget} answers each widget in the shape of its type", async (check) => {
653
+ const own = widgets().filter((widget) => getWidgetResource(widget) === null);
654
+ if (own.length === 0) {
655
+ check.skip("The dashboard has no widget with data of its own.");
656
+ return;
657
+ }
658
+ for (const widget of own) {
659
+ const reply = await request(`/dashboard/widgets/${encodeURIComponent(widget.id)}`);
660
+ if (reply.status === 403) {
661
+ check.expectProblem(reply, 403);
662
+ continue;
663
+ }
664
+ if (!check.expect(reply.status === 200, `Widget "${widget.id}": expected status 200, got ${reply.status}.`)) continue;
665
+ if (isBuiltInWidgetType(widget.type)) check.expectSchema(widgetDataSchemas[widget.type], reply.body, `The data of the ${widget.type} "${widget.id}"`);
666
+ else check.expect(reply.body !== null && typeof reply.body === "object" && !Array.isArray(reply.body), `The data of the widget "${widget.id}" must be an object.`);
667
+ }
668
+ });
669
+ await run("dashboard.widgets.resource", "The lists of the widgets on a resource answer their query, with a total for a stat", async (check) => {
670
+ const onResource = widgets().flatMap((widget) => {
671
+ const read = getWidgetResource(widget);
672
+ return read !== null ? [{
673
+ widget,
674
+ read
675
+ }] : [];
676
+ });
677
+ if (onResource.length === 0) {
678
+ check.skip("The dashboard has no widget on a resource.");
679
+ return;
680
+ }
681
+ for (const { widget, read } of onResource) {
682
+ const params = new URLSearchParams(read.params);
683
+ params.set("perPage", widget.type === "stat" ? "1" : String(5));
684
+ const reply = await request(`/resources/${encodeURIComponent(read.resource)}?${params.toString()}`);
685
+ if (reply.status === 403) {
686
+ check.expectProblem(reply, 403);
687
+ continue;
688
+ }
689
+ if (!check.expect(reply.status === 200, `Widget "${widget.id}": expected status 200, got ${reply.status}.`)) continue;
690
+ const list = check.expectSchema(ListResponse, reply.body, `The list of the widget "${widget.id}"`);
691
+ if (list !== null && widget.type === "stat") check.expect(typeof list.meta.total === "number", `The list of the stat "${widget.id}" has no meta.total to count.`);
692
+ }
693
+ });
694
+ await run("dashboard.widgets.unknown", "A widget that is not in the dashboard of the user is a 404 problem", async (check) => {
695
+ if (definition?.dashboard === void 0) {
696
+ check.skip("The definition has no dashboard.");
697
+ return;
698
+ }
699
+ check.expectProblem(await request(`/dashboard/widgets/${UNKNOWN}`), 404);
700
+ });
649
701
  const writes = options.writes;
650
702
  let createdId = null;
651
703
  let createdVersion = null;
@@ -924,6 +976,48 @@ async function runConformance(options) {
924
976
  check.expect(duplicated.data.id !== created.data.id, "The copy has the id of the item it copies.");
925
977
  await request(`${resourcePath()}/${encodeURIComponent(duplicated.data.id)}`, { method: "DELETE" });
926
978
  });
979
+ await run("action.undo", "The undo of an undoable action runs, and puts the item back", async (check) => {
980
+ const current = resource;
981
+ if (current === null) {
982
+ check.skip("No resource to test.");
983
+ return;
984
+ }
985
+ if (createdId === null) {
986
+ check.skip("No item was created.");
987
+ return;
988
+ }
989
+ const declared = current.actions ?? [];
990
+ const action = declared.find((candidate) => candidate.id === "delete" && candidate.undoable === true) ?? declared.find((candidate) => candidate.undoable === true && (candidate.kind ?? "server") === "server" && candidate.queued !== true && (candidate.fields ?? []).length === 0 && candidate.scope.some((scope) => scope === "item" || scope === "selection"));
991
+ if (action === void 0) {
992
+ check.skip("The resource has no undoable action without parameters.");
993
+ return;
994
+ }
995
+ const before = await request(itemPath());
996
+ const item = check.expectStatus(before, 200) ? check.expectSchema(ItemResponse, before.body, "The item") : null;
997
+ if (item === null) return;
998
+ const reply = await request(`${resourcePath()}/actions/${encodeURIComponent(action.id)}`, {
999
+ method: "POST",
1000
+ body: JSON.stringify({ selection: { ids: [createdId] } })
1001
+ });
1002
+ if (!check.expectStatus(reply, 200)) return;
1003
+ const undo = check.expectSchema(ActionResult, reply.body, `The result of \`${action.id}\``)?.undo;
1004
+ if (!check.expect(undo !== void 0 && undo.items.includes(createdId), `The result of the undoable \`${action.id}\` has no \`undo\` with the item it changed.`) || undo === void 0) return;
1005
+ const undone = await request(`${resourcePath()}/actions/${encodeURIComponent(undo.action)}`, {
1006
+ method: "POST",
1007
+ body: JSON.stringify({
1008
+ selection: { ids: undo.items },
1009
+ values: undo.params ?? {}
1010
+ })
1011
+ });
1012
+ if (!check.expectStatus(undone, 200)) return;
1013
+ const after = await request(itemPath());
1014
+ if (!check.expect(after.status === 200, "After the undo, the item is not back.")) return;
1015
+ const restored = check.expectSchema(ItemResponse, after.body, "The item after the undo");
1016
+ if (restored === null) return;
1017
+ current.fields.forEach((field) => {
1018
+ check.expect(isEqual(restored.data[field.name], item.data[field.name]), `After the undo, \`${field.name}\` is ${JSON.stringify(restored.data[field.name])}, not ${JSON.stringify(item.data[field.name])}.`);
1019
+ });
1020
+ });
927
1021
  await run("delete", "DELETE /resources/{resource}/{id} deletes the item", async (check) => {
928
1022
  if (createdId === null) {
929
1023
  check.skip("No item was created.");