@panneau/protocol 5.0.0-alpha.16 → 5.0.0-alpha.18
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 +94 -0
- package/dist/conformance/index.js.map +1 -1
- package/dist/constants.d.ts +5 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +6 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.js +7 -5
- package/dist/libraries.d.ts +10 -0
- package/dist/libraries.d.ts.map +1 -1
- package/dist/libraries.js +8 -1
- package/dist/libraries.js.map +1 -1
- package/dist/lint.d.ts.map +1 -1
- package/dist/lint.js +59 -0
- package/dist/lint.js.map +1 -1
- package/dist/mock/index.d.ts +20 -1
- package/dist/mock/index.d.ts.map +1 -1
- package/dist/mock/index.js +51 -1
- package/dist/mock/index.js.map +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +13 -6
- package/dist/openapi.js.map +1 -1
- package/dist/runtime/index.d.ts +2 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +5 -4
- package/dist/schemas/action.d.ts +1 -0
- package/dist/schemas/action.d.ts.map +1 -1
- package/dist/schemas/action.js +1 -0
- package/dist/schemas/action.js.map +1 -1
- package/dist/schemas/api.d.ts +15 -0
- package/dist/schemas/api.d.ts.map +1 -1
- package/dist/schemas/api.js +6 -1
- package/dist/schemas/api.js.map +1 -1
- package/dist/schemas/common.js +1 -1
- package/dist/schemas/common.js.map +1 -1
- package/dist/schemas/definition.d.ts +5 -9
- package/dist/schemas/definition.d.ts.map +1 -1
- package/dist/schemas/definition.js +3 -9
- package/dist/schemas/definition.js.map +1 -1
- package/dist/schemas/index.d.ts +81 -2
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +11 -3
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/resource.d.ts +1 -0
- package/dist/schemas/resource.d.ts.map +1 -1
- package/dist/schemas/resource.js +1 -1
- package/dist/schemas/resource.js.map +1 -1
- package/dist/schemas/widget.d.ts +109 -0
- package/dist/schemas/widget.d.ts.map +1 -0
- package/dist/schemas/widget.js +74 -0
- package/dist/schemas/widget.js.map +1 -0
- package/dist/widgets.d.ts +42 -0
- package/dist/widgets.d.ts.map +1 -0
- package/dist/widgets.js +130 -0
- package/dist/widgets.js.map +1 -0
- package/package.json +1 -1
- package/schema/boot.schema.json +41 -5
- package/schema/definition.schema.json +41 -5
- package/schema/openapi.json +294 -12
package/dist/schemas/index.js
CHANGED
|
@@ -6,7 +6,8 @@ import { Action, ActionConfirm, ActionPlacement, ActionScope } from "./action.js
|
|
|
6
6
|
import { Column, Filter, ListCalendar, ListDefinition } from "./list.js";
|
|
7
7
|
import { Resource, ResourceFeatures } from "./resource.js";
|
|
8
8
|
import { DefinitionTheme, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues } from "./theme.js";
|
|
9
|
-
import {
|
|
9
|
+
import { ListWidgetData, ListWidgetItem, SeriesPoint, SeriesWidgetData, StatWidgetData, Widget, WidgetBadge, WidgetSettings, widgetDataSchemas } from "./widget.js";
|
|
10
|
+
import { Auth, AuthProvider, AuthToken, ContextOption, ContextParam, Definition, DefinitionContext, MenuItem, Page, Uploads, User } from "./definition.js";
|
|
10
11
|
import { ActionItemResult, ActionRequest, ActionResult, ActionRun, ActionRunResponse, AddressValue, ContextOptionsResponse, CursorPagination, DateRangeValue, EmbedResponse, EmbedValue, FieldCheckRequest, FieldCheckResponse, Item, ItemResponse, LinkValue, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, MoneyValue, Pagination, Passkey, PreviewResponse, Problem, RecoveryCodes, SearchResponse, Selection, Session, StoredFile, TwoFactorChallenge, TwoFactorSetup, TwoFactorStatus, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, WebAuthnOptions } from "./api.js";
|
|
11
12
|
import { BootConfig } from "./boot.js";
|
|
12
13
|
import { z } from "zod";
|
|
@@ -46,6 +47,7 @@ var namedSchemas = {
|
|
|
46
47
|
Auth,
|
|
47
48
|
MenuItem,
|
|
48
49
|
Page,
|
|
50
|
+
WidgetSettings,
|
|
49
51
|
Widget,
|
|
50
52
|
Uploads,
|
|
51
53
|
ContextOption,
|
|
@@ -100,7 +102,13 @@ var namedSchemas = {
|
|
|
100
102
|
AddressValue,
|
|
101
103
|
LinkValue,
|
|
102
104
|
DateRangeValue,
|
|
103
|
-
MoneyValue
|
|
105
|
+
MoneyValue,
|
|
106
|
+
WidgetBadge,
|
|
107
|
+
StatWidgetData,
|
|
108
|
+
SeriesPoint,
|
|
109
|
+
SeriesWidgetData,
|
|
110
|
+
ListWidgetItem,
|
|
111
|
+
ListWidgetData
|
|
104
112
|
};
|
|
105
113
|
/** A registry of the named schemas, used to reference them by name in generated files. */
|
|
106
114
|
function createSchemaRegistry() {
|
|
@@ -113,6 +121,6 @@ function createSchemaRegistry() {
|
|
|
113
121
|
return registry;
|
|
114
122
|
}
|
|
115
123
|
//#endregion
|
|
116
|
-
export { Abilities, Action, ActionConfirm, ActionItemResult, ActionPlacement, ActionRequest, ActionResult, ActionRun, ActionRunResponse, ActionScope, AddressSettings, AddressValue, Auth, AuthProvider, AuthToken, BlockType, BootConfig, Column, Condition, ContextOption, ContextOptionsResponse, ContextParam, CursorPagination, DateRangeSettings, DateRangeValue, Definition, DefinitionContext, DefinitionTheme, DurationSettings, EmbedResponse, EmbedValue, Field, FieldCheckRequest, FieldCheckResponse, Filter, Id, Item, ItemResponse, LayoutNode, LinkSettings, LinkTypeSetting, LinkValue, ListCalendar, ListDefinition, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, MenuItem, MoneySettings, MoneyValue, Option, Page, Pagination, Passkey, PreviewResponse, Problem, RecoveryCodes, Resource, ResourceFeatures, RichTextSettings, RichTextStyle, RouteReference, Rule, SearchResponse, Selection, Session, StoredFile, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues, TwoFactorChallenge, TwoFactorSetup, TwoFactorStatus, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, Uploads, User, WebAuthnOptions, Widget, createSchemaRegistry, namedSchemas };
|
|
124
|
+
export { Abilities, Action, ActionConfirm, ActionItemResult, ActionPlacement, ActionRequest, ActionResult, ActionRun, ActionRunResponse, ActionScope, AddressSettings, AddressValue, Auth, AuthProvider, AuthToken, BlockType, BootConfig, Column, Condition, ContextOption, ContextOptionsResponse, ContextParam, CursorPagination, DateRangeSettings, DateRangeValue, Definition, DefinitionContext, DefinitionTheme, DurationSettings, EmbedResponse, EmbedValue, Field, FieldCheckRequest, FieldCheckResponse, Filter, Id, Item, ItemResponse, LayoutNode, LinkSettings, LinkTypeSetting, LinkValue, ListCalendar, ListDefinition, ListResponse, ListWidgetData, ListWidgetItem, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, MenuItem, MoneySettings, MoneyValue, Option, Page, Pagination, Passkey, PreviewResponse, Problem, RecoveryCodes, Resource, ResourceFeatures, RichTextSettings, RichTextStyle, RouteReference, Rule, SearchResponse, Selection, SeriesPoint, SeriesWidgetData, Session, StatWidgetData, StoredFile, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues, TwoFactorChallenge, TwoFactorSetup, TwoFactorStatus, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, Uploads, User, WebAuthnOptions, Widget, WidgetBadge, WidgetSettings, createSchemaRegistry, namedSchemas, widgetDataSchemas };
|
|
117
125
|
|
|
118
126
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/schemas/index.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { Action, ActionConfirm, ActionPlacement, ActionScope } from './action';\nimport {\n ActionItemResult,\n ActionRequest,\n ActionResult,\n ActionRun,\n ActionRunResponse,\n AddressValue,\n ContextOptionsResponse,\n CursorPagination,\n DateRangeValue,\n EmbedResponse,\n EmbedValue,\n FieldCheckRequest,\n FieldCheckResponse,\n Item,\n ItemResponse,\n LinkValue,\n ListResponse,\n LocationValue,\n MediaInfo,\n MediaItem,\n MediaReference,\n MediaTransform,\n MoneyValue,\n Pagination,\n Passkey,\n PreviewResponse,\n Problem,\n RecoveryCodes,\n SearchResponse,\n Selection,\n Session,\n StoredFile,\n TwoFactorChallenge,\n TwoFactorSetup,\n TwoFactorStatus,\n Upload,\n UploadReference,\n UploadResponse,\n UploadSignRequest,\n UploadSignResponse,\n WebAuthnOptions,\n} from './api';\nimport { Abilities, Condition, Id, Option, RouteReference } from './common';\nimport {\n Auth,\n AuthProvider,\n AuthToken,\n ContextOption,\n ContextParam,\n Definition,\n DefinitionContext,\n MenuItem,\n Page,\n Uploads,\n User,\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/schemas/index.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { Action, ActionConfirm, ActionPlacement, ActionScope } from './action';\nimport {\n ActionItemResult,\n ActionRequest,\n ActionResult,\n ActionRun,\n ActionRunResponse,\n AddressValue,\n ContextOptionsResponse,\n CursorPagination,\n DateRangeValue,\n EmbedResponse,\n EmbedValue,\n FieldCheckRequest,\n FieldCheckResponse,\n Item,\n ItemResponse,\n LinkValue,\n ListResponse,\n LocationValue,\n MediaInfo,\n MediaItem,\n MediaReference,\n MediaTransform,\n MoneyValue,\n Pagination,\n Passkey,\n PreviewResponse,\n Problem,\n RecoveryCodes,\n SearchResponse,\n Selection,\n Session,\n StoredFile,\n TwoFactorChallenge,\n TwoFactorSetup,\n TwoFactorStatus,\n Upload,\n UploadReference,\n UploadResponse,\n UploadSignRequest,\n UploadSignResponse,\n WebAuthnOptions,\n} from './api';\nimport { Abilities, Condition, Id, Option, RouteReference } from './common';\nimport {\n Auth,\n AuthProvider,\n AuthToken,\n ContextOption,\n ContextParam,\n Definition,\n DefinitionContext,\n MenuItem,\n Page,\n Uploads,\n User,\n} from './definition';\nimport {\n AddressSettings,\n BlockType,\n DateRangeSettings,\n DurationSettings,\n Field,\n LinkSettings,\n LinkTypeSetting,\n MoneySettings,\n RichTextSettings,\n RichTextStyle,\n Rule,\n} from './field';\nimport { actionJsonRules } from './jsonRules';\nimport { LayoutNode } from './layout';\nimport { Column, Filter, ListCalendar, ListDefinition } from './list';\nimport { Resource, ResourceFeatures } from './resource';\nimport {\n DefinitionTheme,\n Theme,\n ThemeFont,\n ThemeFontFace,\n ThemeFontStylesheet,\n ThemeTokens,\n ToneInput,\n ToneValues,\n} from './theme';\nimport {\n ListWidgetData,\n ListWidgetItem,\n SeriesPoint,\n SeriesWidgetData,\n StatWidgetData,\n Widget,\n WidgetBadge,\n WidgetSettings,\n} from './widget';\n\nexport * from './common';\nexport * from './field';\nexport * from './layout';\nexport * from './list';\nexport * from './action';\nexport * from './resource';\nexport * from './theme';\nexport * from './widget';\nexport * from './definition';\nexport * from './api';\nexport * from './boot';\n\n/** The named schemas of the protocol, as they appear in the generated JSON Schema and OpenAPI files. */\nexport const namedSchemas = {\n Id,\n Abilities,\n RouteReference,\n Condition,\n Option,\n Rule,\n BlockType,\n Field,\n RichTextStyle,\n RichTextSettings,\n LinkTypeSetting,\n LinkSettings,\n AddressSettings,\n DateRangeSettings,\n MoneySettings,\n DurationSettings,\n LayoutNode,\n Column,\n Filter,\n ListCalendar,\n ListDefinition,\n ActionScope,\n ActionPlacement,\n ActionConfirm,\n Action,\n ResourceFeatures,\n Resource,\n User,\n AuthProvider,\n AuthToken,\n Auth,\n MenuItem,\n Page,\n WidgetSettings,\n Widget,\n Uploads,\n ContextOption,\n ContextParam,\n DefinitionContext,\n ThemeTokens,\n ToneValues,\n ToneInput,\n ThemeFontFace,\n ThemeFontStylesheet,\n ThemeFont,\n Theme,\n DefinitionTheme,\n Definition,\n Item,\n Pagination,\n CursorPagination,\n ItemResponse,\n ListResponse,\n Problem,\n Selection,\n ActionRequest,\n ActionItemResult,\n ActionResult,\n ActionRun,\n ActionRunResponse,\n MediaTransform,\n StoredFile,\n UploadReference,\n Upload,\n UploadResponse,\n UploadSignRequest,\n UploadSignResponse,\n FieldCheckRequest,\n FieldCheckResponse,\n MediaInfo,\n MediaItem,\n MediaReference,\n Session,\n TwoFactorChallenge,\n TwoFactorStatus,\n TwoFactorSetup,\n RecoveryCodes,\n WebAuthnOptions,\n Passkey,\n SearchResponse,\n ContextOptionsResponse,\n PreviewResponse,\n EmbedValue,\n EmbedResponse,\n LocationValue,\n AddressValue,\n LinkValue,\n DateRangeValue,\n MoneyValue,\n WidgetBadge,\n StatWidgetData,\n SeriesPoint,\n SeriesWidgetData,\n ListWidgetItem,\n ListWidgetData,\n} satisfies Record<string, z.ZodType>;\n\n/** A registry of the named schemas, used to reference them by name in generated files. */\nexport function createSchemaRegistry() {\n const registry = z.registry<{ id: string } & Record<string, unknown>>();\n Object.entries(namedSchemas).forEach(([id, schema]) => registry.add(schema, { id }));\n // Checks that Zod makes in code, which the JSON Schema of the definition must make too.\n registry.add(Action, { id: 'Action', ...actionJsonRules });\n return registry;\n}\n"],"mappings":";;;;;;;;;;;;;;;AA+GA,IAAa,eAAe;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAGA,SAAgB,uBAAuB;CACnC,MAAM,WAAW,EAAE,SAAmD;CACtE,OAAO,QAAQ,YAAY,CAAC,CAAC,SAAS,CAAC,IAAI,YAAY,SAAS,IAAI,QAAQ,EAAE,GAAG,CAAC,CAAC;CAEnF,SAAS,IAAI,QAAQ;EAAE,IAAI;EAAU,GAAG;CAAgB,CAAC;CACzD,OAAO;AACX"}
|
|
@@ -526,6 +526,7 @@ export declare const Resource: z.ZodObject<{
|
|
|
526
526
|
}, z.core.$loose>>>;
|
|
527
527
|
queued: z.ZodOptional<z.ZodBoolean>;
|
|
528
528
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
529
|
+
undoable: z.ZodOptional<z.ZodBoolean>;
|
|
529
530
|
url: z.ZodOptional<z.ZodString>;
|
|
530
531
|
route: z.ZodOptional<z.ZodString>;
|
|
531
532
|
component: z.ZodOptional<z.ZodString>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/schemas/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGtC,eAAO,MAAM,gBAAgB;;;;;;;;;;;iBAmB3B,CAAC;AAEH,eAAO,MAAM,QAAQ
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/schemas/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGtC,eAAO,MAAM,gBAAgB;;;;;;;;;;;iBAmB3B,CAAC;AAEH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6C6C,CAAC;AAEnE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAChE,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC;AAChD,sEAAsE;AACtE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC"}
|
package/dist/schemas/resource.js
CHANGED
|
@@ -25,7 +25,7 @@ var Resource = z.looseObject({
|
|
|
25
25
|
icon: z.string().optional(),
|
|
26
26
|
itemTitle: z.string().optional().meta({ description: "The field used as the title of an item, in lists and pickers." }),
|
|
27
27
|
itemSubtitle: z.string().optional().meta({ description: "The field shown under the title of an item, in search results, cards and pickers." }),
|
|
28
|
-
itemImage: z.string().optional().meta({ description: "The field that holds the image of an item (a media or a URL), in search results,
|
|
28
|
+
itemImage: z.string().optional().meta({ description: "The field that holds the image of an item (a media, a file or a URL), in search results, pickers, the gallery and the thumbnails of the table. Defaults to the item's `media` in a resource of kind `media` (decision 0061)." }),
|
|
29
29
|
open: z.union([z.enum(["panel", "edit"]), z.string().min(1)]).optional().meta({ description: "Where an item's title goes, in its list and wherever the app links to the item (decision 0040). `panel`, the default: the show route, with the item's details in a panel next to the list. `edit`: its edit form, and the show route redirects there. Clients treat a value they don't know as `panel`." }),
|
|
30
30
|
itemActions: z.array(z.string().min(1)).optional().meta({ description: "The built-in item actions the resource shows, in their order (decision 0040): some of `show`, `edit`, `duplicate` and `delete`. Defaults to all four. Each one is shown on the items whose abilities allow it (`view`, `update`, `duplicate`, `delete`). `[]` shows none. Clients ignore ids they don't know." }),
|
|
31
31
|
fields: z.array(Field),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.js","names":[],"sources":["../../src/schemas/resource.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { Action } from './action';\nimport { Abilities } from './common';\nimport { BlockType, Field } from './field';\nimport { LayoutNode } from './layout';\nimport { ListDefinition } from './list';\n\nexport const ResourceFeatures = z.looseObject({\n drafts: z.boolean().optional(),\n revisions: z.boolean().optional(),\n preview: z\n .union([\n z.null(),\n z.looseObject({\n mode: z.enum(['component', 'iframe']),\n component: z\n .string()\n .optional()\n .meta({ description: '`component`: the plugin preview.' }),\n }),\n ])\n .optional(),\n search: z.boolean().optional().meta({\n description:\n 'Whether the resource is in the global search. Defaults to whether its list has a search (`list.search`).',\n }),\n});\n\nexport const Resource = z\n .looseObject({\n id: z.string().min(1),\n kind: z.string().min(1).optional().meta({\n description:\n \"What the resource is. `media`: a library of media (decision 0026), with a `file` field and a `media` on each item. Without it, an ordinary resource. Clients treat a kind they don't know as an ordinary resource.\",\n }),\n label: z.looseObject({ singular: z.string(), plural: z.string() }),\n description: z.string().optional(),\n icon: z.string().optional(),\n itemTitle: z\n .string()\n .optional()\n .meta({ description: 'The field used as the title of an item, in lists and pickers.' }),\n itemSubtitle: z.string().optional().meta({\n description:\n 'The field shown under the title of an item, in search results, cards and pickers.',\n }),\n itemImage: z.string().optional().meta({\n description:\n
|
|
1
|
+
{"version":3,"file":"resource.js","names":[],"sources":["../../src/schemas/resource.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { Action } from './action';\nimport { Abilities } from './common';\nimport { BlockType, Field } from './field';\nimport { LayoutNode } from './layout';\nimport { ListDefinition } from './list';\n\nexport const ResourceFeatures = z.looseObject({\n drafts: z.boolean().optional(),\n revisions: z.boolean().optional(),\n preview: z\n .union([\n z.null(),\n z.looseObject({\n mode: z.enum(['component', 'iframe']),\n component: z\n .string()\n .optional()\n .meta({ description: '`component`: the plugin preview.' }),\n }),\n ])\n .optional(),\n search: z.boolean().optional().meta({\n description:\n 'Whether the resource is in the global search. Defaults to whether its list has a search (`list.search`).',\n }),\n});\n\nexport const Resource = z\n .looseObject({\n id: z.string().min(1),\n kind: z.string().min(1).optional().meta({\n description:\n \"What the resource is. `media`: a library of media (decision 0026), with a `file` field and a `media` on each item. Without it, an ordinary resource. Clients treat a kind they don't know as an ordinary resource.\",\n }),\n label: z.looseObject({ singular: z.string(), plural: z.string() }),\n description: z.string().optional(),\n icon: z.string().optional(),\n itemTitle: z\n .string()\n .optional()\n .meta({ description: 'The field used as the title of an item, in lists and pickers.' }),\n itemSubtitle: z.string().optional().meta({\n description:\n 'The field shown under the title of an item, in search results, cards and pickers.',\n }),\n itemImage: z.string().optional().meta({\n description:\n \"The field that holds the image of an item (a media, a file or a URL), in search results, pickers, the gallery and the thumbnails of the table. Defaults to the item's `media` in a resource of kind `media` (decision 0061).\",\n }),\n open: z\n .union([z.enum(['panel', 'edit']), z.string().min(1)])\n .optional()\n .meta({\n description:\n \"Where an item's title goes, in its list and wherever the app links to the item (decision 0040). `panel`, the default: the show route, with the item's details in a panel next to the list. `edit`: its edit form, and the show route redirects there. Clients treat a value they don't know as `panel`.\",\n }),\n itemActions: z.array(z.string().min(1)).optional().meta({\n description:\n \"The built-in item actions the resource shows, in their order (decision 0040): some of `show`, `edit`, `duplicate` and `delete`. Defaults to all four. Each one is shown on the items whose abilities allow it (`view`, `update`, `duplicate`, `delete`). `[]` shows none. Clients ignore ids they don't know.\",\n }),\n fields: z.array(Field),\n form: z.looseObject({ layout: z.array(LayoutNode).optional() }).optional(),\n list: ListDefinition.optional(),\n actions: z.array(Action).optional(),\n abilities: Abilities.optional(),\n features: ResourceFeatures.optional(),\n types: z\n .array(BlockType)\n .optional()\n .meta({ description: 'Variants of the resource, each with its own extra fields.' }),\n settings: z.record(z.string(), z.unknown()).optional(),\n })\n .meta({ description: 'A set of items managed in the admin.' });\n\nexport type ResourceFeatures = z.infer<typeof ResourceFeatures>;\nexport type Resource = z.infer<typeof Resource>;\n/** A resource as a backend writes it, before defaults are applied. */\nexport type ResourceInput = z.input<typeof Resource>;\n"],"mappings":";;;;;;;AAQA,IAAa,mBAAmB,EAAE,YAAY;CAC1C,QAAQ,EAAE,QAAQ,CAAC,CAAC,SAAS;CAC7B,WAAW,EAAE,QAAQ,CAAC,CAAC,SAAS;CAChC,SAAS,EACJ,MAAM,CACH,EAAE,KAAK,GACP,EAAE,YAAY;EACV,MAAM,EAAE,KAAK,CAAC,aAAa,QAAQ,CAAC;EACpC,WAAW,EACN,OAAO,CAAC,CACR,SAAS,CAAC,CACV,KAAK,EAAE,aAAa,mCAAmC,CAAC;CACjE,CAAC,CACL,CAAC,CAAC,CACD,SAAS;CACd,QAAQ,EAAE,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAChC,aACI,2GACR,CAAC;AACL,CAAC;AAED,IAAa,WAAW,EACnB,YAAY;CACT,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACpB,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EACpC,aACI,qNACR,CAAC;CACD,OAAO,EAAE,YAAY;EAAE,UAAU,EAAE,OAAO;EAAG,QAAQ,EAAE,O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
|
+
resource: z.ZodOptional<z.ZodString>;
|
|
4
|
+
query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>]>>>;
|
|
5
|
+
}, z.core.$loose>;
|
|
6
|
+
export declare const Widget: z.ZodObject<{
|
|
7
|
+
id: z.ZodString;
|
|
8
|
+
type: z.ZodString;
|
|
9
|
+
label: z.ZodOptional<z.ZodString>;
|
|
10
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
settings: z.ZodOptional<z.ZodObject<{
|
|
12
|
+
resource: z.ZodOptional<z.ZodString>;
|
|
13
|
+
query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>]>>>;
|
|
14
|
+
}, z.core.$loose>>;
|
|
15
|
+
}, z.core.$loose>;
|
|
16
|
+
export declare const WidgetBadge: z.ZodObject<{
|
|
17
|
+
label: z.ZodString;
|
|
18
|
+
tone: z.ZodOptional<z.ZodString>;
|
|
19
|
+
}, z.core.$loose>;
|
|
20
|
+
export declare const StatWidgetData: z.ZodObject<{
|
|
21
|
+
value: z.ZodNumber;
|
|
22
|
+
help: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
23
|
+
tone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
24
|
+
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
25
|
+
}, z.core.$loose>;
|
|
26
|
+
export declare const SeriesPoint: z.ZodObject<{
|
|
27
|
+
date: z.ZodString;
|
|
28
|
+
value: z.ZodNumber;
|
|
29
|
+
}, z.core.$loose>;
|
|
30
|
+
export declare const SeriesWidgetData: z.ZodObject<{
|
|
31
|
+
period: z.ZodEnum<{
|
|
32
|
+
day: "day";
|
|
33
|
+
week: "week";
|
|
34
|
+
month: "month";
|
|
35
|
+
}>;
|
|
36
|
+
points: z.ZodArray<z.ZodObject<{
|
|
37
|
+
date: z.ZodString;
|
|
38
|
+
value: z.ZodNumber;
|
|
39
|
+
}, z.core.$loose>>;
|
|
40
|
+
total: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
41
|
+
}, z.core.$loose>;
|
|
42
|
+
export declare const ListWidgetItem: z.ZodObject<{
|
|
43
|
+
title: z.ZodString;
|
|
44
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
45
|
+
meta: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
46
|
+
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
47
|
+
badge: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
48
|
+
label: z.ZodString;
|
|
49
|
+
tone: z.ZodOptional<z.ZodString>;
|
|
50
|
+
}, z.core.$loose>>>;
|
|
51
|
+
}, z.core.$loose>;
|
|
52
|
+
export declare const ListWidgetData: z.ZodObject<{
|
|
53
|
+
items: z.ZodArray<z.ZodObject<{
|
|
54
|
+
title: z.ZodString;
|
|
55
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
56
|
+
meta: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
57
|
+
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
58
|
+
badge: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
59
|
+
label: z.ZodString;
|
|
60
|
+
tone: z.ZodOptional<z.ZodString>;
|
|
61
|
+
}, z.core.$loose>>>;
|
|
62
|
+
}, z.core.$loose>>;
|
|
63
|
+
empty: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
64
|
+
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
65
|
+
}, z.core.$loose>;
|
|
66
|
+
/** The schema of the data of each built-in widget type. */
|
|
67
|
+
export declare const widgetDataSchemas: {
|
|
68
|
+
readonly stat: z.ZodObject<{
|
|
69
|
+
value: z.ZodNumber;
|
|
70
|
+
help: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
71
|
+
tone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
72
|
+
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
73
|
+
}, z.core.$loose>;
|
|
74
|
+
readonly series: z.ZodObject<{
|
|
75
|
+
period: z.ZodEnum<{
|
|
76
|
+
day: "day";
|
|
77
|
+
week: "week";
|
|
78
|
+
month: "month";
|
|
79
|
+
}>;
|
|
80
|
+
points: z.ZodArray<z.ZodObject<{
|
|
81
|
+
date: z.ZodString;
|
|
82
|
+
value: z.ZodNumber;
|
|
83
|
+
}, z.core.$loose>>;
|
|
84
|
+
total: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
85
|
+
}, z.core.$loose>;
|
|
86
|
+
readonly list: z.ZodObject<{
|
|
87
|
+
items: z.ZodArray<z.ZodObject<{
|
|
88
|
+
title: z.ZodString;
|
|
89
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
90
|
+
meta: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
91
|
+
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
92
|
+
badge: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
93
|
+
label: z.ZodString;
|
|
94
|
+
tone: z.ZodOptional<z.ZodString>;
|
|
95
|
+
}, z.core.$loose>>>;
|
|
96
|
+
}, z.core.$loose>>;
|
|
97
|
+
empty: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
98
|
+
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
99
|
+
}, z.core.$loose>;
|
|
100
|
+
};
|
|
101
|
+
export type WidgetSettings = z.infer<typeof WidgetSettings>;
|
|
102
|
+
export type Widget = z.infer<typeof Widget>;
|
|
103
|
+
export type WidgetBadge = z.infer<typeof WidgetBadge>;
|
|
104
|
+
export type StatWidgetData = z.infer<typeof StatWidgetData>;
|
|
105
|
+
export type SeriesPoint = z.infer<typeof SeriesPoint>;
|
|
106
|
+
export type SeriesWidgetData = z.infer<typeof SeriesWidgetData>;
|
|
107
|
+
export type ListWidgetItem = z.infer<typeof ListWidgetItem>;
|
|
108
|
+
export type ListWidgetData = z.infer<typeof ListWidgetData>;
|
|
109
|
+
//# sourceMappingURL=widget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../../src/schemas/widget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,eAAO,MAAM,cAAc;;;iBAiBrB,CAAC;AAEP,eAAO,MAAM,MAAM;;;;;;;;;iBAejB,CAAC;AAEH,eAAO,MAAM,WAAW;;;iBAE8C,CAAC;AAEvE,eAAO,MAAM,cAAc;;;;;iBAgByD,CAAC;AAErF,eAAO,MAAM,WAAW;;;iBAMtB,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;;;iBAyBvB,CAAC;AAEP,eAAO,MAAM,cAAc;;;;;;;;;iBAUzB,CAAC;AAEH,eAAO,MAAM,cAAc;;;;;;;;;;;;;iBAiB4D,CAAC;AAExF,2DAA2D;AAC3D,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAIpB,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAC5D,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAC;AAC5C,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AACtD,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAC5D,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AACtD,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAChE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAC5D,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { WIDGET_SERIES_PERIODS } from "../widgets.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/schemas/widget.ts
|
|
4
|
+
var ToneName = z.string().regex(/^[a-z0-9-]+$/);
|
|
5
|
+
var QueryValue = z.union([
|
|
6
|
+
z.string(),
|
|
7
|
+
z.number(),
|
|
8
|
+
z.boolean()
|
|
9
|
+
]);
|
|
10
|
+
var WidgetSettings = z.looseObject({
|
|
11
|
+
resource: z.string().min(1).optional().meta({ description: "Built-in `stat` and `list`: the resource whose list feeds the widget. The client reads `GET /resources/{resource}` with `query`: a `stat` counts its items (`meta.total`), a `list` shows its first items. Such a widget has no data at `GET /dashboard/widgets/{widget}`." }),
|
|
12
|
+
query: z.record(z.string(), z.union([QueryValue, z.array(QueryValue)])).optional().meta({ description: "With `resource`: the query of the list, as its query parameters (`{ \"filter[status]\": \"to-judge\", \"sort\": \"-created_at\" }`), and of the link to the list. The client sets `page`, `perPage` and `cursor`." })
|
|
13
|
+
}).meta({ description: "The settings of a widget: `resource` and `query` for the built-in `stat` and `list` on a resource, anything else for widgets of plugins." });
|
|
14
|
+
var Widget = z.looseObject({
|
|
15
|
+
id: z.string().min(1).meta({ description: "Unique in the dashboard: the `{widget}` of its route." }),
|
|
16
|
+
type: z.string().min(1).meta({ description: "Built-in: `stat` (a number), `series` (a line over days, weeks or months) and `list` (a few items). Other types are widgets of plugins." }),
|
|
17
|
+
label: z.string().optional(),
|
|
18
|
+
width: z.number().int().min(1).max(12).optional().meta({ description: "Columns of a grid of 12. Defaults to 3 for a `stat`, 6 for others. One column on a phone." }),
|
|
19
|
+
settings: WidgetSettings.optional()
|
|
20
|
+
});
|
|
21
|
+
var WidgetBadge = z.looseObject({
|
|
22
|
+
label: z.string(),
|
|
23
|
+
tone: ToneName.optional()
|
|
24
|
+
}).meta({ description: "A badge: a word, in a tone of the theme." });
|
|
25
|
+
var StatWidgetData = z.looseObject({
|
|
26
|
+
value: z.number().meta({ description: "The number, in large type." }),
|
|
27
|
+
help: z.string().nullable().optional().meta({ description: "A line under the number, translated: `3 more than last week`." }),
|
|
28
|
+
tone: ToneName.nullable().optional().meta({ description: "A tone of the theme, only when the number calls for attention (`warning`, `danger`): neutral otherwise, and at 0." }),
|
|
29
|
+
url: z.string().nullable().optional().meta({ description: "Where the widget links: the list of what it counts." })
|
|
30
|
+
}).meta({ description: "The data of a `stat` widget: a number (decision 0064)." });
|
|
31
|
+
var SeriesPoint = z.looseObject({
|
|
32
|
+
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).meta({ description: "The first day of the period: `2026-10-05`." }),
|
|
33
|
+
value: z.number()
|
|
34
|
+
});
|
|
35
|
+
var SeriesWidgetData = z.looseObject({
|
|
36
|
+
period: z.enum(WIDGET_SERIES_PERIODS).meta({ description: "The period of each point." }),
|
|
37
|
+
points: z.array(SeriesPoint).meta({ description: "One point per period, the dates going up. Periods without a value are points at 0." }),
|
|
38
|
+
total: z.number().nullable().optional().meta({ description: "The total over the points, shown with the line." })
|
|
39
|
+
}).superRefine((data, context) => {
|
|
40
|
+
data.points.forEach((point, index) => {
|
|
41
|
+
const previous = data.points[index - 1];
|
|
42
|
+
if (previous !== void 0 && point.date <= previous.date) context.addIssue({
|
|
43
|
+
code: "custom",
|
|
44
|
+
message: "The dates of the points must go up.",
|
|
45
|
+
path: [
|
|
46
|
+
"points",
|
|
47
|
+
index,
|
|
48
|
+
"date"
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}).meta({ description: "The data of a `series` widget: a line of values per period (decision 0064)." });
|
|
53
|
+
var ListWidgetItem = z.looseObject({
|
|
54
|
+
title: z.string(),
|
|
55
|
+
description: z.string().nullable().optional(),
|
|
56
|
+
meta: z.string().nullable().optional().meta({ description: "A short fact at the end of the item: `12 answers`." }),
|
|
57
|
+
url: z.string().nullable().optional(),
|
|
58
|
+
badge: WidgetBadge.nullable().optional()
|
|
59
|
+
});
|
|
60
|
+
var ListWidgetData = z.looseObject({
|
|
61
|
+
items: z.array(ListWidgetItem).max(5).meta({ description: `At most 5 items, the most useful first.` }),
|
|
62
|
+
empty: z.string().nullable().optional().meta({ description: "The message without items, translated: `No open contests.`" }),
|
|
63
|
+
url: z.string().nullable().optional().meta({ description: "Where \"See all\" links, under the items." })
|
|
64
|
+
}).meta({ description: "The data of a `list` widget: a few items (decision 0064)." });
|
|
65
|
+
/** The schema of the data of each built-in widget type. */
|
|
66
|
+
var widgetDataSchemas = {
|
|
67
|
+
stat: StatWidgetData,
|
|
68
|
+
series: SeriesWidgetData,
|
|
69
|
+
list: ListWidgetData
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
export { ListWidgetData, ListWidgetItem, SeriesPoint, SeriesWidgetData, StatWidgetData, Widget, WidgetBadge, WidgetSettings, widgetDataSchemas };
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=widget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.js","names":[],"sources":["../../src/schemas/widget.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { WIDGET_LIST_MAX_ITEMS, WIDGET_SERIES_PERIODS } from '../widgets';\n\nconst ToneName = z.string().regex(/^[a-z0-9-]+$/);\n\nconst QueryValue = z.union([z.string(), z.number(), z.boolean()]);\n\nexport const WidgetSettings = z\n .looseObject({\n resource: z.string().min(1).optional().meta({\n description:\n 'Built-in `stat` and `list`: the resource whose list feeds the widget. The client reads `GET /resources/{resource}` with `query`: a `stat` counts its items (`meta.total`), a `list` shows its first items. Such a widget has no data at `GET /dashboard/widgets/{widget}`.',\n }),\n query: z\n .record(z.string(), z.union([QueryValue, z.array(QueryValue)]))\n .optional()\n .meta({\n description:\n 'With `resource`: the query of the list, as its query parameters (`{ \"filter[status]\": \"to-judge\", \"sort\": \"-created_at\" }`), and of the link to the list. The client sets `page`, `perPage` and `cursor`.',\n }),\n })\n .meta({\n description:\n 'The settings of a widget: `resource` and `query` for the built-in `stat` and `list` on a resource, anything else for widgets of plugins.',\n });\n\nexport const Widget = z.looseObject({\n id: z\n .string()\n .min(1)\n .meta({ description: 'Unique in the dashboard: the `{widget}` of its route.' }),\n type: z.string().min(1).meta({\n description:\n 'Built-in: `stat` (a number), `series` (a line over days, weeks or months) and `list` (a few items). Other types are widgets of plugins.',\n }),\n label: z.string().optional(),\n width: z.number().int().min(1).max(12).optional().meta({\n description:\n 'Columns of a grid of 12. Defaults to 3 for a `stat`, 6 for others. One column on a phone.',\n }),\n settings: WidgetSettings.optional(),\n});\n\nexport const WidgetBadge = z\n .looseObject({ label: z.string(), tone: ToneName.optional() })\n .meta({ description: 'A badge: a word, in a tone of the theme.' });\n\nexport const StatWidgetData = z\n .looseObject({\n value: z.number().meta({ description: 'The number, in large type.' }),\n help: z.string().nullable().optional().meta({\n description: 'A line under the number, translated: `3 more than last week`.',\n }),\n tone: ToneName.nullable().optional().meta({\n description:\n 'A tone of the theme, only when the number calls for attention (`warning`, `danger`): neutral otherwise, and at 0.',\n }),\n url: z\n .string()\n .nullable()\n .optional()\n .meta({ description: 'Where the widget links: the list of what it counts.' }),\n })\n .meta({ description: 'The data of a `stat` widget: a number (decision 0064).' });\n\nexport const SeriesPoint = z.looseObject({\n date: z\n .string()\n .regex(/^\\d{4}-\\d{2}-\\d{2}$/)\n .meta({ description: 'The first day of the period: `2026-10-05`.' }),\n value: z.number(),\n});\n\nexport const SeriesWidgetData = z\n .looseObject({\n period: z.enum(WIDGET_SERIES_PERIODS).meta({ description: 'The period of each point.' }),\n points: z.array(SeriesPoint).meta({\n description:\n 'One point per period, the dates going up. Periods without a value are points at 0.',\n }),\n total: z.number().nullable().optional().meta({\n description: 'The total over the points, shown with the line.',\n }),\n })\n .superRefine((data, context) => {\n data.points.forEach((point, index) => {\n const previous = data.points[index - 1];\n if (previous !== undefined && point.date <= previous.date) {\n context.addIssue({\n code: 'custom',\n message: 'The dates of the points must go up.',\n path: ['points', index, 'date'],\n });\n }\n });\n })\n .meta({\n description: 'The data of a `series` widget: a line of values per period (decision 0064).',\n });\n\nexport const ListWidgetItem = z.looseObject({\n title: z.string(),\n description: z.string().nullable().optional(),\n meta: z\n .string()\n .nullable()\n .optional()\n .meta({ description: 'A short fact at the end of the item: `12 answers`.' }),\n url: z.string().nullable().optional(),\n badge: WidgetBadge.nullable().optional(),\n});\n\nexport const ListWidgetData = z\n .looseObject({\n items: z\n .array(ListWidgetItem)\n .max(WIDGET_LIST_MAX_ITEMS)\n .meta({\n description: `At most ${WIDGET_LIST_MAX_ITEMS} items, the most useful first.`,\n }),\n empty: z.string().nullable().optional().meta({\n description: 'The message without items, translated: `No open contests.`',\n }),\n url: z\n .string()\n .nullable()\n .optional()\n .meta({ description: 'Where \"See all\" links, under the items.' }),\n })\n .meta({ description: 'The data of a `list` widget: a few items (decision 0064).' });\n\n/** The schema of the data of each built-in widget type. */\nexport const widgetDataSchemas = {\n stat: StatWidgetData,\n series: SeriesWidgetData,\n list: ListWidgetData,\n} as const;\n\nexport type WidgetSettings = z.infer<typeof WidgetSettings>;\nexport type Widget = z.infer<typeof Widget>;\nexport type WidgetBadge = z.infer<typeof WidgetBadge>;\nexport type StatWidgetData = z.infer<typeof StatWidgetData>;\nexport type SeriesPoint = z.infer<typeof SeriesPoint>;\nexport type SeriesWidgetData = z.infer<typeof SeriesWidgetData>;\nexport type ListWidgetItem = z.infer<typeof ListWidgetItem>;\nexport type ListWidgetData = z.infer<typeof ListWidgetData>;\n"],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AAK,EAAE,aAAa,qDAAqD,CAAC;CAC/E,KAAK,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CACpC,OAAO,YAAY,SAAS,CAAC,CAAC,SAAS;AAC3C,CAAC;AAED,IAAa,iBAAiB,EACzB,YAAY;CACT,OAAO,EACF,MAAM,cAAc,CAAC,CACrB,IAAA,CAAyB,CAAC,CAC1B,KAAK,EACF,aAAa,0CACjB,CAAC;CACL,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EACzC,aAAa,6DACjB,CAAC;CACD,KAAK,EACA,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,CAAC,CACV,KAAK,EAAE,aAAa,4CAA0C,CAAC;AACxE,CAAC,CAAC,CACD,KAAK,EAAE,aAAa,4DAA4D,CAAC;;AAGtF,IAAa,oBAAoB;CAC7B,MAAM;CACN,QAAQ;CACR,MAAM;AACV"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ListQuery } from './query.js';
|
|
2
|
+
/** The widget types that every client draws (decision 0064). Other types are widgets of plugins. */
|
|
3
|
+
export declare const BUILT_IN_WIDGET_TYPES: readonly ["stat", "series", "list"];
|
|
4
|
+
export type BuiltInWidgetType = (typeof BUILT_IN_WIDGET_TYPES)[number];
|
|
5
|
+
/** The periods of the points of a `series` widget. */
|
|
6
|
+
export declare const WIDGET_SERIES_PERIODS: readonly ["day", "week", "month"];
|
|
7
|
+
export type WidgetSeriesPeriod = (typeof WIDGET_SERIES_PERIODS)[number];
|
|
8
|
+
/** The most items a `list` widget shows: the backend sends the most useful first. */
|
|
9
|
+
export declare const WIDGET_LIST_MAX_ITEMS = 5;
|
|
10
|
+
/** The built-in types that can read the list of a resource (`settings.resource`). */
|
|
11
|
+
export declare const RESOURCE_WIDGET_TYPES: readonly ["stat", "list"];
|
|
12
|
+
/** Query parameters that the client sets on the list of a widget on a resource, never `query`. */
|
|
13
|
+
export declare const WIDGET_RESERVED_QUERY_PARAMS: readonly ["page", "perPage", "cursor"];
|
|
14
|
+
export declare function isBuiltInWidgetType(type: string): type is BuiltInWidgetType;
|
|
15
|
+
/** A widget as the helpers read it: the `Widget` of the definition, or one a backend writes. */
|
|
16
|
+
interface WidgetLike {
|
|
17
|
+
type: string;
|
|
18
|
+
settings?: Record<string, unknown> | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** A built-in widget that reads the list of a resource, with no data of its own (decision 0064). */
|
|
21
|
+
export interface WidgetResource {
|
|
22
|
+
/** The id of the resource. */
|
|
23
|
+
resource: string;
|
|
24
|
+
/** The `query` of the widget, as query parameters, without `page`, `perPage` and `cursor`. */
|
|
25
|
+
params: URLSearchParams;
|
|
26
|
+
/** The same query, parsed: the query of the list request, and of the link to the list. */
|
|
27
|
+
query: ListQuery;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The resource whose list feeds a built-in `stat` or `list` widget, and its query: `null` for a
|
|
31
|
+
* widget with data of its own at `GET /dashboard/widgets/{widget}`, and for widgets of plugins.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getWidgetResource(widget: WidgetLike): WidgetResource | null;
|
|
34
|
+
/**
|
|
35
|
+
* Checks the data of a widget against the shape of its type (decision 0064), without the schemas:
|
|
36
|
+
* the paths of the wrong keys (`value`, `points.2.date`), empty when it is right. The data of a
|
|
37
|
+
* widget of a plugin only has to be an object. The dates of a series must go up, one point per
|
|
38
|
+
* period.
|
|
39
|
+
*/
|
|
40
|
+
export declare function checkWidgetData(type: string, data: unknown): string[];
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=widgets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgets.d.ts","sourceRoot":"","sources":["../src/widgets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAoB,MAAM,SAAS,CAAC;AAG3D,oGAAoG;AACpG,eAAO,MAAM,qBAAqB,qCAAsC,CAAC;AAEzE,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvE,sDAAsD;AACtD,eAAO,MAAM,qBAAqB,mCAAoC,CAAC;AAEvE,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE,qFAAqF;AACrF,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,qFAAqF;AACrF,eAAO,MAAM,qBAAqB,2BAA4B,CAAC;AAE/D,kGAAkG;AAClG,eAAO,MAAM,4BAA4B,wCAAyC,CAAC;AAEnF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,iBAAiB,CAE3E;AAED,gGAAgG;AAChG,UAAU,UAAU;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CAClD;AAED,oGAAoG;AACpG,MAAM,WAAW,cAAc;IAC3B,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,8FAA8F;IAC9F,MAAM,EAAE,eAAe,CAAC;IACxB,0FAA0F;IAC1F,KAAK,EAAE,SAAS,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,cAAc,GAAG,IAAI,CA4B3E;AAwGD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,CAcrE"}
|
package/dist/widgets.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { isRecord } from "./values.js";
|
|
2
|
+
import { fromSearchParams } from "./query.js";
|
|
3
|
+
//#region src/widgets.ts
|
|
4
|
+
/** The widget types that every client draws (decision 0064). Other types are widgets of plugins. */
|
|
5
|
+
var BUILT_IN_WIDGET_TYPES = [
|
|
6
|
+
"stat",
|
|
7
|
+
"series",
|
|
8
|
+
"list"
|
|
9
|
+
];
|
|
10
|
+
/** The periods of the points of a `series` widget. */
|
|
11
|
+
var WIDGET_SERIES_PERIODS = [
|
|
12
|
+
"day",
|
|
13
|
+
"week",
|
|
14
|
+
"month"
|
|
15
|
+
];
|
|
16
|
+
/** The most items a `list` widget shows: the backend sends the most useful first. */
|
|
17
|
+
var WIDGET_LIST_MAX_ITEMS = 5;
|
|
18
|
+
/** The built-in types that can read the list of a resource (`settings.resource`). */
|
|
19
|
+
var RESOURCE_WIDGET_TYPES = ["stat", "list"];
|
|
20
|
+
/** Query parameters that the client sets on the list of a widget on a resource, never `query`. */
|
|
21
|
+
var WIDGET_RESERVED_QUERY_PARAMS = [
|
|
22
|
+
"page",
|
|
23
|
+
"perPage",
|
|
24
|
+
"cursor"
|
|
25
|
+
];
|
|
26
|
+
function isBuiltInWidgetType(type) {
|
|
27
|
+
return BUILT_IN_WIDGET_TYPES.includes(type);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The resource whose list feeds a built-in `stat` or `list` widget, and its query: `null` for a
|
|
31
|
+
* widget with data of its own at `GET /dashboard/widgets/{widget}`, and for widgets of plugins.
|
|
32
|
+
*/
|
|
33
|
+
function getWidgetResource(widget) {
|
|
34
|
+
const resource = widget.settings?.resource;
|
|
35
|
+
if (!RESOURCE_WIDGET_TYPES.includes(widget.type) || typeof resource !== "string" || resource === "") return null;
|
|
36
|
+
const params = new URLSearchParams();
|
|
37
|
+
const query = widget.settings?.query;
|
|
38
|
+
if (isRecord(query)) Object.entries(query).forEach(([key, value]) => {
|
|
39
|
+
if (WIDGET_RESERVED_QUERY_PARAMS.includes(key)) return;
|
|
40
|
+
(Array.isArray(value) ? value : [value]).forEach((entry) => {
|
|
41
|
+
if (typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean") params.append(key, String(entry));
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
resource,
|
|
46
|
+
params,
|
|
47
|
+
query: fromSearchParams(params)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
var DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
51
|
+
var TONE = /^[a-z0-9-]+$/;
|
|
52
|
+
var isNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
53
|
+
/** Whether a key is missing, `null`, or passes the check. */
|
|
54
|
+
function optional(data, key, check) {
|
|
55
|
+
return data[key] === void 0 || data[key] === null || check(data[key]);
|
|
56
|
+
}
|
|
57
|
+
var isString = (value) => typeof value === "string";
|
|
58
|
+
var isTone = (value) => isString(value) && TONE.test(value);
|
|
59
|
+
function checkStat(data) {
|
|
60
|
+
const wrong = [];
|
|
61
|
+
if (!isNumber(data.value)) wrong.push("value");
|
|
62
|
+
if (!optional(data, "help", isString)) wrong.push("help");
|
|
63
|
+
if (!optional(data, "tone", isTone)) wrong.push("tone");
|
|
64
|
+
if (!optional(data, "url", isString)) wrong.push("url");
|
|
65
|
+
return wrong;
|
|
66
|
+
}
|
|
67
|
+
function checkSeries(data) {
|
|
68
|
+
const wrong = [];
|
|
69
|
+
if (!WIDGET_SERIES_PERIODS.includes(data.period)) wrong.push("period");
|
|
70
|
+
if (!Array.isArray(data.points)) wrong.push("points");
|
|
71
|
+
else {
|
|
72
|
+
let previous = "";
|
|
73
|
+
data.points.forEach((point, index) => {
|
|
74
|
+
if (!isRecord(point)) {
|
|
75
|
+
wrong.push(`points.${index}`);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (!isString(point.date) || !DATE.test(point.date) || point.date <= previous) wrong.push(`points.${index}.date`);
|
|
79
|
+
else previous = point.date;
|
|
80
|
+
if (!isNumber(point.value)) wrong.push(`points.${index}.value`);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (!optional(data, "total", isNumber)) wrong.push("total");
|
|
84
|
+
return wrong;
|
|
85
|
+
}
|
|
86
|
+
function checkList(data) {
|
|
87
|
+
const wrong = [];
|
|
88
|
+
if (!Array.isArray(data.items) || data.items.length > 5) wrong.push("items");
|
|
89
|
+
else data.items.forEach((item, index) => {
|
|
90
|
+
if (!isRecord(item)) {
|
|
91
|
+
wrong.push(`items.${index}`);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!isString(item.title)) wrong.push(`items.${index}.title`);
|
|
95
|
+
[
|
|
96
|
+
"description",
|
|
97
|
+
"meta",
|
|
98
|
+
"url"
|
|
99
|
+
].forEach((key) => {
|
|
100
|
+
if (!optional(item, key, isString)) wrong.push(`items.${index}.${key}`);
|
|
101
|
+
});
|
|
102
|
+
const badge = item.badge;
|
|
103
|
+
if (badge !== void 0 && badge !== null) {
|
|
104
|
+
if (!isRecord(badge) || !isString(badge.label)) wrong.push(`items.${index}.badge`);
|
|
105
|
+
else if (!optional(badge, "tone", isTone)) wrong.push(`items.${index}.badge.tone`);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
if (!optional(data, "empty", isString)) wrong.push("empty");
|
|
109
|
+
if (!optional(data, "url", isString)) wrong.push("url");
|
|
110
|
+
return wrong;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Checks the data of a widget against the shape of its type (decision 0064), without the schemas:
|
|
114
|
+
* the paths of the wrong keys (`value`, `points.2.date`), empty when it is right. The data of a
|
|
115
|
+
* widget of a plugin only has to be an object. The dates of a series must go up, one point per
|
|
116
|
+
* period.
|
|
117
|
+
*/
|
|
118
|
+
function checkWidgetData(type, data) {
|
|
119
|
+
if (!isRecord(data)) return [""];
|
|
120
|
+
switch (type) {
|
|
121
|
+
case "stat": return checkStat(data);
|
|
122
|
+
case "series": return checkSeries(data);
|
|
123
|
+
case "list": return checkList(data);
|
|
124
|
+
default: return [];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
export { BUILT_IN_WIDGET_TYPES, RESOURCE_WIDGET_TYPES, WIDGET_LIST_MAX_ITEMS, WIDGET_RESERVED_QUERY_PARAMS, WIDGET_SERIES_PERIODS, checkWidgetData, getWidgetResource, isBuiltInWidgetType };
|
|
129
|
+
|
|
130
|
+
//# sourceMappingURL=widgets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgets.js","names":[],"sources":["../src/widgets.ts"],"sourcesContent":["import { type ListQuery, fromSearchParams } from './query';\nimport { isRecord } from './values';\n\n/** The widget types that every client draws (decision 0064). Other types are widgets of plugins. */\nexport const BUILT_IN_WIDGET_TYPES = ['stat', 'series', 'list'] as const;\n\nexport type BuiltInWidgetType = (typeof BUILT_IN_WIDGET_TYPES)[number];\n\n/** The periods of the points of a `series` widget. */\nexport const WIDGET_SERIES_PERIODS = ['day', 'week', 'month'] as const;\n\nexport type WidgetSeriesPeriod = (typeof WIDGET_SERIES_PERIODS)[number];\n\n/** The most items a `list` widget shows: the backend sends the most useful first. */\nexport const WIDGET_LIST_MAX_ITEMS = 5;\n\n/** The built-in types that can read the list of a resource (`settings.resource`). */\nexport const RESOURCE_WIDGET_TYPES = ['stat', 'list'] as const;\n\n/** Query parameters that the client sets on the list of a widget on a resource, never `query`. */\nexport const WIDGET_RESERVED_QUERY_PARAMS = ['page', 'perPage', 'cursor'] as const;\n\nexport function isBuiltInWidgetType(type: string): type is BuiltInWidgetType {\n return (BUILT_IN_WIDGET_TYPES as readonly string[]).includes(type);\n}\n\n/** A widget as the helpers read it: the `Widget` of the definition, or one a backend writes. */\ninterface WidgetLike {\n type: string;\n settings?: Record<string, unknown> | undefined;\n}\n\n/** A built-in widget that reads the list of a resource, with no data of its own (decision 0064). */\nexport interface WidgetResource {\n /** The id of the resource. */\n resource: string;\n /** The `query` of the widget, as query parameters, without `page`, `perPage` and `cursor`. */\n params: URLSearchParams;\n /** The same query, parsed: the query of the list request, and of the link to the list. */\n query: ListQuery;\n}\n\n/**\n * The resource whose list feeds a built-in `stat` or `list` widget, and its query: `null` for a\n * widget with data of its own at `GET /dashboard/widgets/{widget}`, and for widgets of plugins.\n */\nexport function getWidgetResource(widget: WidgetLike): WidgetResource | null {\n const resource = widget.settings?.resource;\n if (\n !(RESOURCE_WIDGET_TYPES as readonly string[]).includes(widget.type) ||\n typeof resource !== 'string' ||\n resource === ''\n ) {\n return null;\n }\n const params = new URLSearchParams();\n const query = widget.settings?.query;\n if (isRecord(query)) {\n Object.entries(query).forEach(([key, value]) => {\n if ((WIDGET_RESERVED_QUERY_PARAMS as readonly string[]).includes(key)) {\n return;\n }\n (Array.isArray(value) ? value : [value]).forEach((entry) => {\n if (\n typeof entry === 'string' ||\n typeof entry === 'number' ||\n typeof entry === 'boolean'\n ) {\n params.append(key, String(entry));\n }\n });\n });\n }\n return { resource, params, query: fromSearchParams(params) };\n}\n\nconst DATE = /^\\d{4}-\\d{2}-\\d{2}$/;\nconst TONE = /^[a-z0-9-]+$/;\n\nconst isNumber = (value: unknown): value is number =>\n typeof value === 'number' && Number.isFinite(value);\n\n/** Whether a key is missing, `null`, or passes the check. */\nfunction optional(\n data: Record<string, unknown>,\n key: string,\n check: (value: unknown) => boolean,\n): boolean {\n return data[key] === undefined || data[key] === null || check(data[key]);\n}\n\nconst isString = (value: unknown): value is string => typeof value === 'string';\nconst isTone = (value: unknown): boolean => isString(value) && TONE.test(value);\n\nfunction checkStat(data: Record<string, unknown>): string[] {\n const wrong: string[] = [];\n if (!isNumber(data.value)) {\n wrong.push('value');\n }\n if (!optional(data, 'help', isString)) {\n wrong.push('help');\n }\n if (!optional(data, 'tone', isTone)) {\n wrong.push('tone');\n }\n if (!optional(data, 'url', isString)) {\n wrong.push('url');\n }\n return wrong;\n}\n\nfunction checkSeries(data: Record<string, unknown>): string[] {\n const wrong: string[] = [];\n if (!(WIDGET_SERIES_PERIODS as readonly unknown[]).includes(data.period)) {\n wrong.push('period');\n }\n if (!Array.isArray(data.points)) {\n wrong.push('points');\n } else {\n let previous = '';\n data.points.forEach((point: unknown, index) => {\n if (!isRecord(point)) {\n wrong.push(`points.${index}`);\n return;\n }\n if (!isString(point.date) || !DATE.test(point.date) || point.date <= previous) {\n wrong.push(`points.${index}.date`);\n } else {\n previous = point.date;\n }\n if (!isNumber(point.value)) {\n wrong.push(`points.${index}.value`);\n }\n });\n }\n if (!optional(data, 'total', isNumber)) {\n wrong.push('total');\n }\n return wrong;\n}\n\nfunction checkList(data: Record<string, unknown>): string[] {\n const wrong: string[] = [];\n if (!Array.isArray(data.items) || data.items.length > WIDGET_LIST_MAX_ITEMS) {\n wrong.push('items');\n } else {\n data.items.forEach((item: unknown, index) => {\n if (!isRecord(item)) {\n wrong.push(`items.${index}`);\n return;\n }\n if (!isString(item.title)) {\n wrong.push(`items.${index}.title`);\n }\n ['description', 'meta', 'url'].forEach((key) => {\n if (!optional(item, key, isString)) {\n wrong.push(`items.${index}.${key}`);\n }\n });\n const badge = item.badge;\n if (badge !== undefined && badge !== null) {\n if (!isRecord(badge) || !isString(badge.label)) {\n wrong.push(`items.${index}.badge`);\n } else if (!optional(badge, 'tone', isTone)) {\n wrong.push(`items.${index}.badge.tone`);\n }\n }\n });\n }\n if (!optional(data, 'empty', isString)) {\n wrong.push('empty');\n }\n if (!optional(data, 'url', isString)) {\n wrong.push('url');\n }\n return wrong;\n}\n\n/**\n * Checks the data of a widget against the shape of its type (decision 0064), without the schemas:\n * the paths of the wrong keys (`value`, `points.2.date`), empty when it is right. The data of a\n * widget of a plugin only has to be an object. The dates of a series must go up, one point per\n * period.\n */\nexport function checkWidgetData(type: string, data: unknown): string[] {\n if (!isRecord(data)) {\n return [''];\n }\n switch (type) {\n case 'stat':\n return checkStat(data);\n case 'series':\n return checkSeries(data);\n case 'list':\n return checkList(data);\n default:\n return [];\n }\n}\n"],"mappings":";;;;AAIA,IAAa,wBAAwB;CAAC;CAAQ;CAAU;AAAM;;AAK9D,IAAa,wBAAwB;CAAC;CAAO;CAAQ;AAAO;;AAK5D,IAAa,wBAAwB;;AAGrC,IAAa,wBAAwB,CAAC,QAAQ,MAAM;;AAGpD,IAAa,+BAA+B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AAG,KAAK;EAE1C,CAAC;EACD,MAAM,QAAQ,KAAK;EACnB,IAAI,UAAU,KAAA,KAAa,UAAU,MAAM;GACvC,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS,MAAM,KAAK,GACzC,MAAM,KAAK,SAAS,MAAM,OAAO;QAC9B,IAAI,CAAC,SAAS,OAAO,QAAQ,MAAM,GACtC,MAAM,KAAK,SAAS,MAAM,YAAY;EAE9C;CACJ,CAAC;CAEL,IAAI,CAAC,SAAS,MAAM,SAAS,QAAQ,GACjC,MAAM,KAAK,OAAO;CAEtB,IAAI,CAAC,SAAS,MAAM,OAAO,QAAQ,GAC/B,MAAM,KAAK,KAAK;CAEpB,OAAO;AACX;;;;;;;AAQA,SAAgB,gBAAgB,MAAc,MAAyB;CACnE,IAAI,CAAC,SAAS,IAAI,GACd,OAAO,CAAC,EAAE;CAEd,QAAQ,MAAR;EACI,KAAK,QACD,OAAO,UAAU,IAAI;EACzB,KAAK,UACD,OAAO,YAAY,IAAI;EAC3B,KAAK,QACD,OAAO,UAAU,IAAI;EACzB,SACI,OAAO,CAAC;CAChB;AACJ"}
|
package/package.json
CHANGED
package/schema/boot.schema.json
CHANGED
|
@@ -1285,6 +1285,9 @@
|
|
|
1285
1285
|
"dryRun": {
|
|
1286
1286
|
"type": "boolean"
|
|
1287
1287
|
},
|
|
1288
|
+
"undoable": {
|
|
1289
|
+
"type": "boolean"
|
|
1290
|
+
},
|
|
1288
1291
|
"url": {
|
|
1289
1292
|
"type": "string"
|
|
1290
1293
|
},
|
|
@@ -1671,11 +1674,7 @@
|
|
|
1671
1674
|
"maximum": 12
|
|
1672
1675
|
},
|
|
1673
1676
|
"settings": {
|
|
1674
|
-
"
|
|
1675
|
-
"propertyNames": {
|
|
1676
|
-
"type": "string"
|
|
1677
|
-
},
|
|
1678
|
-
"additionalProperties": {}
|
|
1677
|
+
"$ref": "#/$defs/WidgetSettings"
|
|
1679
1678
|
}
|
|
1680
1679
|
},
|
|
1681
1680
|
"required": [
|
|
@@ -1684,6 +1683,43 @@
|
|
|
1684
1683
|
],
|
|
1685
1684
|
"additionalProperties": {}
|
|
1686
1685
|
},
|
|
1686
|
+
"WidgetSettings": {
|
|
1687
|
+
"type": "object",
|
|
1688
|
+
"properties": {
|
|
1689
|
+
"resource": {
|
|
1690
|
+
"type": "string",
|
|
1691
|
+
"minLength": 1
|
|
1692
|
+
},
|
|
1693
|
+
"query": {
|
|
1694
|
+
"type": "object",
|
|
1695
|
+
"propertyNames": {
|
|
1696
|
+
"type": "string"
|
|
1697
|
+
},
|
|
1698
|
+
"additionalProperties": {
|
|
1699
|
+
"anyOf": [
|
|
1700
|
+
{
|
|
1701
|
+
"type": [
|
|
1702
|
+
"string",
|
|
1703
|
+
"number",
|
|
1704
|
+
"boolean"
|
|
1705
|
+
]
|
|
1706
|
+
},
|
|
1707
|
+
{
|
|
1708
|
+
"type": "array",
|
|
1709
|
+
"items": {
|
|
1710
|
+
"type": [
|
|
1711
|
+
"string",
|
|
1712
|
+
"number",
|
|
1713
|
+
"boolean"
|
|
1714
|
+
]
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
]
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
},
|
|
1721
|
+
"additionalProperties": {}
|
|
1722
|
+
},
|
|
1687
1723
|
"Uploads": {
|
|
1688
1724
|
"type": "object",
|
|
1689
1725
|
"properties": {
|