@panneau/protocol 5.0.0-alpha.4 → 5.0.0-alpha.41
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/addresses.d.ts +23 -0
- package/dist/addresses.d.ts.map +1 -0
- package/dist/addresses.js +52 -0
- package/dist/addresses.js.map +1 -0
- 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/compound.d.ts +20 -0
- package/dist/compound.d.ts.map +1 -0
- package/dist/compound.js +27 -0
- package/dist/compound.js.map +1 -0
- package/dist/conditions.d.ts +1 -1
- package/dist/conformance/index.d.ts +6 -0
- package/dist/conformance/index.d.ts.map +1 -1
- package/dist/conformance/index.js +970 -11
- package/dist/conformance/index.js.map +1 -1
- package/dist/constants.d.ts +108 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +181 -3
- package/dist/constants.js.map +1 -1
- package/dist/context.d.ts +15 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +34 -0
- package/dist/context.js.map +1 -0
- package/dist/currencies.d.ts +22 -0
- package/dist/currencies.d.ts.map +1 -0
- package/dist/currencies.js +231 -0
- package/dist/currencies.js.map +1 -0
- 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.d.ts +4 -4
- package/dist/index.js +22 -8
- package/dist/libraries.d.ts +33 -0
- package/dist/libraries.d.ts.map +1 -0
- package/dist/libraries.js +59 -0
- package/dist/libraries.js.map +1 -0
- package/dist/links.d.ts +38 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +65 -0
- package/dist/links.js.map +1 -0
- package/dist/lint.d.ts +4 -4
- package/dist/lint.d.ts.map +1 -1
- package/dist/lint.js +540 -15
- package/dist/lint.js.map +1 -1
- package/dist/mock/auth.d.ts +71 -0
- package/dist/mock/auth.d.ts.map +1 -0
- package/dist/mock/auth.js +346 -0
- package/dist/mock/auth.js.map +1 -0
- package/dist/mock/example.d.ts +1 -1
- package/dist/mock/example.d.ts.map +1 -1
- package/dist/mock/example.js +49 -28
- package/dist/mock/example.js.map +1 -1
- package/dist/mock/index.d.ts +96 -5
- package/dist/mock/index.d.ts.map +1 -1
- package/dist/mock/index.js +505 -44
- package/dist/mock/index.js.map +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +462 -50
- package/dist/openapi.js.map +1 -1
- package/dist/periods.d.ts +61 -0
- package/dist/periods.d.ts.map +1 -0
- package/dist/periods.js +130 -0
- package/dist/periods.js.map +1 -0
- package/dist/problem.d.ts +1 -1
- package/dist/query.d.ts +18 -0
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +34 -8
- package/dist/query.js.map +1 -1
- package/dist/resourceTypes.d.ts +39 -0
- package/dist/resourceTypes.d.ts.map +1 -0
- package/dist/resourceTypes.js +34 -0
- package/dist/resourceTypes.js.map +1 -0
- package/dist/rules.d.ts +18 -5
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +233 -15
- package/dist/rules.js.map +1 -1
- package/dist/runtime/index.d.ts +23 -10
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +16 -3
- package/dist/schemas/action.d.ts +119 -10
- package/dist/schemas/action.d.ts.map +1 -1
- package/dist/schemas/action.js +20 -3
- package/dist/schemas/action.js.map +1 -1
- package/dist/schemas/api.d.ts +266 -5
- package/dist/schemas/api.d.ts.map +1 -1
- package/dist/schemas/api.js +134 -16
- package/dist/schemas/api.js.map +1 -1
- package/dist/schemas/boot.d.ts +25 -1
- package/dist/schemas/boot.d.ts.map +1 -1
- package/dist/schemas/boot.js +2 -1
- package/dist/schemas/boot.js.map +1 -1
- package/dist/schemas/common.d.ts +1 -0
- package/dist/schemas/common.d.ts.map +1 -1
- package/dist/schemas/common.js +2 -1
- package/dist/schemas/common.js.map +1 -1
- package/dist/schemas/definition.d.ts +1414 -30
- package/dist/schemas/definition.d.ts.map +1 -1
- package/dist/schemas/definition.js +77 -17
- package/dist/schemas/definition.js.map +1 -1
- package/dist/schemas/field.d.ts +358 -2
- package/dist/schemas/field.d.ts.map +1 -1
- package/dist/schemas/field.js +161 -20
- package/dist/schemas/field.js.map +1 -1
- package/dist/schemas/index.d.ts +5820 -46
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +69 -7
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/jsonRules.d.ts +83 -0
- package/dist/schemas/jsonRules.d.ts.map +1 -0
- package/dist/schemas/jsonRules.js +46 -0
- package/dist/schemas/jsonRules.js.map +1 -0
- package/dist/schemas/layout.d.ts +2 -1
- package/dist/schemas/layout.d.ts.map +1 -1
- package/dist/schemas/layout.js +2 -1
- package/dist/schemas/layout.js.map +1 -1
- package/dist/schemas/list.d.ts +34 -2
- package/dist/schemas/list.d.ts.map +1 -1
- package/dist/schemas/list.js +21 -6
- package/dist/schemas/list.js.map +1 -1
- package/dist/schemas/resource.d.ts +826 -17
- package/dist/schemas/resource.d.ts.map +1 -1
- package/dist/schemas/resource.js +26 -4
- package/dist/schemas/resource.js.map +1 -1
- package/dist/schemas/theme.d.ts +6 -2
- package/dist/schemas/theme.d.ts.map +1 -1
- package/dist/schemas/theme.js +1 -0
- package/dist/schemas/theme.js.map +1 -1
- package/dist/schemas/widget.d.ts +4379 -0
- package/dist/schemas/widget.d.ts.map +1 -0
- package/dist/schemas/widget.js +269 -0
- package/dist/schemas/widget.js.map +1 -0
- package/dist/search.d.ts +51 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +53 -0
- package/dist/search.js.map +1 -0
- package/dist/themes.d.ts +1 -1
- package/dist/transforms.d.ts +17 -0
- package/dist/transforms.d.ts.map +1 -0
- package/dist/transforms.js +34 -0
- package/dist/transforms.js.map +1 -0
- package/dist/validate.d.ts +5 -3
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +36 -2
- package/dist/validate.js.map +1 -1
- package/dist/values.d.ts +5 -1
- package/dist/values.d.ts.map +1 -1
- package/dist/values.js +16 -2
- package/dist/values.js.map +1 -1
- package/dist/widgets.d.ts +232 -0
- package/dist/widgets.d.ts.map +1 -0
- package/dist/widgets.js +630 -0
- package/dist/widgets.js.map +1 -0
- package/package.json +6 -3
- package/schema/boot.schema.json +1461 -104
- package/schema/definition.schema.json +1459 -105
- package/schema/openapi.json +7176 -2000
package/dist/validate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAWlD,MAAM,WAAW,eAAe;IAC5B,uFAAuF;IACvF,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAC1B;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,eAAe,EAAE,CAAA;CAAE,CAAC;AAE/E,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EACxC,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,OAAO,GACf,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAY9B;AAqCD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAwB/E;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAU/E"}
|
package/dist/validate.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { lintDefinition } from "./lint.js";
|
|
2
|
+
import { AddressSettings, DateRangeSettings, DurationSettings, LinkSettings, MoneySettings, RichTextSettings } from "./schemas/field.js";
|
|
2
3
|
import { Definition } from "./schemas/definition.js";
|
|
3
4
|
import { BootConfig } from "./schemas/boot.js";
|
|
4
5
|
//#region src/validate.ts
|
|
@@ -17,14 +18,47 @@ function validate(schema, input) {
|
|
|
17
18
|
}))
|
|
18
19
|
};
|
|
19
20
|
}
|
|
21
|
+
/** The schemas of the settings of the types that the protocol describes. */
|
|
22
|
+
var SETTINGS = {
|
|
23
|
+
richtext: RichTextSettings,
|
|
24
|
+
duration: DurationSettings,
|
|
25
|
+
daterange: DateRangeSettings,
|
|
26
|
+
money: MoneySettings,
|
|
27
|
+
link: LinkSettings,
|
|
28
|
+
address: AddressSettings
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Checks the settings of the fields whose type the protocol describes the settings of (`richtext`,
|
|
32
|
+
* `duration`, `daterange`, `money`, `link`, `address`), nested ones included.
|
|
33
|
+
*/
|
|
34
|
+
function checkFieldSettings(fields, path) {
|
|
35
|
+
return fields.flatMap((field, index) => {
|
|
36
|
+
const fieldPath = `${path}.${String(index)}`;
|
|
37
|
+
const schema = SETTINGS[field.type];
|
|
38
|
+
return [
|
|
39
|
+
...schema !== void 0 && field.settings !== void 0 ? (schema.safeParse(field.settings).error?.issues ?? []).map((issue) => ({
|
|
40
|
+
path: [`${fieldPath}.settings`, ...issue.path.map(String)].join("."),
|
|
41
|
+
message: issue.message
|
|
42
|
+
})) : [],
|
|
43
|
+
...checkFieldSettings(field.fields ?? [], `${fieldPath}.fields`),
|
|
44
|
+
...(field.types ?? []).flatMap((type, typeIndex) => checkFieldSettings(type.fields, `${fieldPath}.types.${String(typeIndex)}.fields`))
|
|
45
|
+
];
|
|
46
|
+
});
|
|
47
|
+
}
|
|
20
48
|
/**
|
|
21
49
|
* Validates a definition, as returned by `GET /definition`: against the schema, then the
|
|
22
|
-
* references between its parts (see `lintDefinition()`)
|
|
50
|
+
* references between its parts (see `lintDefinition()`), and the settings of field types that
|
|
51
|
+
* the protocol describes (`RichTextSettings`, `DurationSettings`, `DateRangeSettings`,
|
|
52
|
+
* `MoneySettings`, `LinkSettings`, `AddressSettings`).
|
|
23
53
|
*/
|
|
24
54
|
function validateDefinition(input) {
|
|
25
55
|
const result = validate(Definition, input);
|
|
26
56
|
if (!result.success) return result;
|
|
27
|
-
const issues = lintDefinition(result.data)
|
|
57
|
+
const issues = [...lintDefinition(result.data), ...result.data.resources.flatMap((resource, index) => [
|
|
58
|
+
...checkFieldSettings(resource.fields, `resources.${String(index)}.fields`),
|
|
59
|
+
...(resource.types ?? []).flatMap((type, typeIndex) => checkFieldSettings(type.fields, `resources.${String(index)}.types.${String(typeIndex)}.fields`)),
|
|
60
|
+
...(resource.actions ?? []).flatMap((action, actionIndex) => checkFieldSettings(action.fields ?? [], `resources.${String(index)}.actions.${String(actionIndex)}.fields`))
|
|
61
|
+
])];
|
|
28
62
|
return issues.length > 0 ? {
|
|
29
63
|
success: false,
|
|
30
64
|
issues
|
package/dist/validate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","names":[],"sources":["../src/validate.ts"],"sourcesContent":["import type { z } from 'zod';\n\nimport { lintDefinition } from './lint';\nimport { BootConfig } from './schemas/boot';\nimport { Definition } from './schemas/definition';\n\nexport interface ValidationIssue {\n /** Dot path of the invalid value (`resources.0.fields.2.type`), empty for the root. */\n path: string;\n message: string;\n}\n\nexport type ValidationResult<T> =\n { success: true; data: T } | { success: false; issues: ValidationIssue[] };\n\n/** Validates a value against one of the protocol's schemas. */\nexport function validate<T extends z.ZodType>(\n schema: T,\n input: unknown,\n): ValidationResult<z.infer<T>> {\n const result = schema.safeParse(input);\n if (result.success) {\n return { success: true, data: result.data };\n }\n return {\n success: false,\n issues: result.error.issues.map((issue) => ({\n path: issue.path.map(String).join('.'),\n message: issue.message,\n })),\n };\n}\n\n/**\n * Validates a definition, as returned by `GET /definition`: against the schema, then the\n * references between its parts (see `lintDefinition()`).\n */\nexport function validateDefinition(input: unknown): ValidationResult<Definition> {\n const result = validate(Definition, input);\n if (!result.success) {\n return result;\n }\n const issues = lintDefinition(result.data);\n return issues.length > 0 ? { success: false, issues } : result;\n}\n\n/**\n * Validates a boot config, as a server writes it in the page: against the schema, then the\n * references between the parts of its inlined definition, if any.\n */\nexport function validateBootConfig(input: unknown): ValidationResult<BootConfig> {\n const result = validate(BootConfig, input);\n if (!result.success || result.data.definition === undefined) {\n return result;\n }\n const issues = lintDefinition(result.data.definition).map((issue) => ({\n ...issue,\n path: issue.path === '' ? 'definition' : `definition.${issue.path}`,\n }));\n return issues.length > 0 ? { success: false, issues } : result;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate.js","names":[],"sources":["../src/validate.ts"],"sourcesContent":["import type { z } from 'zod';\n\nimport { lintDefinition } from './lint';\nimport { BootConfig } from './schemas/boot';\nimport { Definition } from './schemas/definition';\nimport {\n AddressSettings,\n DateRangeSettings,\n DurationSettings,\n type Field,\n LinkSettings,\n MoneySettings,\n RichTextSettings,\n} from './schemas/field';\n\nexport interface ValidationIssue {\n /** Dot path of the invalid value (`resources.0.fields.2.type`), empty for the root. */\n path: string;\n message: string;\n}\n\nexport type ValidationResult<T> =\n { success: true; data: T } | { success: false; issues: ValidationIssue[] };\n\n/** Validates a value against one of the protocol's schemas. */\nexport function validate<T extends z.ZodType>(\n schema: T,\n input: unknown,\n): ValidationResult<z.infer<T>> {\n const result = schema.safeParse(input);\n if (result.success) {\n return { success: true, data: result.data };\n }\n return {\n success: false,\n issues: result.error.issues.map((issue) => ({\n path: issue.path.map(String).join('.'),\n message: issue.message,\n })),\n };\n}\n\n/** The schemas of the settings of the types that the protocol describes. */\nconst SETTINGS: Readonly<Record<string, z.ZodType>> = {\n richtext: RichTextSettings,\n duration: DurationSettings,\n daterange: DateRangeSettings,\n money: MoneySettings,\n link: LinkSettings,\n address: AddressSettings,\n};\n\n/**\n * Checks the settings of the fields whose type the protocol describes the settings of (`richtext`,\n * `duration`, `daterange`, `money`, `link`, `address`), nested ones included.\n */\nfunction checkFieldSettings(fields: readonly Field[], path: string): ValidationIssue[] {\n return fields.flatMap((field, index) => {\n const fieldPath = `${path}.${String(index)}`;\n const schema = SETTINGS[field.type];\n const own =\n schema !== undefined && field.settings !== undefined\n ? (schema.safeParse(field.settings).error?.issues ?? []).map((issue) => ({\n path: [`${fieldPath}.settings`, ...issue.path.map(String)].join('.'),\n message: issue.message,\n }))\n : [];\n return [\n ...own,\n ...checkFieldSettings(field.fields ?? [], `${fieldPath}.fields`),\n ...(field.types ?? []).flatMap((type, typeIndex) =>\n checkFieldSettings(type.fields, `${fieldPath}.types.${String(typeIndex)}.fields`),\n ),\n ];\n });\n}\n\n/**\n * Validates a definition, as returned by `GET /definition`: against the schema, then the\n * references between its parts (see `lintDefinition()`), and the settings of field types that\n * the protocol describes (`RichTextSettings`, `DurationSettings`, `DateRangeSettings`,\n * `MoneySettings`, `LinkSettings`, `AddressSettings`).\n */\nexport function validateDefinition(input: unknown): ValidationResult<Definition> {\n const result = validate(Definition, input);\n if (!result.success) {\n return result;\n }\n const issues = [\n ...lintDefinition(result.data),\n ...result.data.resources.flatMap((resource, index) => [\n ...checkFieldSettings(resource.fields, `resources.${String(index)}.fields`),\n ...(resource.types ?? []).flatMap((type, typeIndex) =>\n checkFieldSettings(\n type.fields,\n `resources.${String(index)}.types.${String(typeIndex)}.fields`,\n ),\n ),\n ...(resource.actions ?? []).flatMap((action, actionIndex) =>\n checkFieldSettings(\n action.fields ?? [],\n `resources.${String(index)}.actions.${String(actionIndex)}.fields`,\n ),\n ),\n ]),\n ];\n return issues.length > 0 ? { success: false, issues } : result;\n}\n\n/**\n * Validates a boot config, as a server writes it in the page: against the schema, then the\n * references between the parts of its inlined definition, if any.\n */\nexport function validateBootConfig(input: unknown): ValidationResult<BootConfig> {\n const result = validate(BootConfig, input);\n if (!result.success || result.data.definition === undefined) {\n return result;\n }\n const issues = lintDefinition(result.data.definition).map((issue) => ({\n ...issue,\n path: issue.path === '' ? 'definition' : `definition.${issue.path}`,\n }));\n return issues.length > 0 ? { success: false, issues } : result;\n}\n"],"mappings":";;;;;;AAyBA,SAAgB,SACZ,QACA,OAC4B;CAC5B,MAAM,SAAS,OAAO,UAAU,KAAK;CACrC,IAAI,OAAO,SACP,OAAO;EAAE,SAAS;EAAM,MAAM,OAAO;CAAK;CAE9C,OAAO;EACH,SAAS;EACT,QAAQ,OAAO,MAAM,OAAO,KAAK,WAAW;GACxC,MAAM,MAAM,KAAK,IAAI,MAAM,CAAC,CAAC,KAAK,GAAG;GACrC,SAAS,MAAM;EACnB,EAAE;CACN;AACJ;;AAGA,IAAM,WAAgD;CAClD,UAAU;CACV,UAAU;CACV,WAAW;CACX,OAAO;CACP,MAAM;CACN,SAAS;AACb;;;;;AAMA,SAAS,mBAAmB,QAA0B,MAAiC;CACnF,OAAO,OAAO,SAAS,OAAO,UAAU;EACpC,MAAM,YAAY,GAAG,KAAK,GAAG,OAAO,KAAK;EACzC,MAAM,SAAS,SAAS,MAAM;EAQ9B,OAAO;GACH,GAPA,WAAW,KAAA,KAAa,MAAM,aAAa,KAAA,KACpC,OAAO,UAAU,MAAM,QAAQ,CAAC,CAAC,OAAO,UAAU,CAAC,EAAA,CAAG,KAAK,WAAW;IACnE,MAAM,CAAC,GAAG,UAAU,YAAY,GAAG,MAAM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F,OAAO,OAAO,SAAS,IAAI;EAAE,SAAS;EAAO;CAAO,IAAI;AAC5D"}
|
package/dist/values.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/** Reads a value at a dot path (`blocks.2.title.fr`). */
|
|
2
2
|
export declare function getValue(values: unknown, path: string): unknown;
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Whether a value counts as filled: not null, not an empty or blank string, not an empty array or
|
|
5
|
+
* plain object. A file (`Blob`, `File`, even empty) is filled. Other collections count by their
|
|
6
|
+
* `length` or `size` (an empty `FileList`, `Map` or `Set` isn't filled); other objects are filled.
|
|
7
|
+
*/
|
|
4
8
|
export declare function isFilled(value: unknown): boolean;
|
|
5
9
|
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
6
10
|
export declare function isEqual(a: unknown, b: unknown): boolean;
|
package/dist/values.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../src/values.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAU/D;AAED
|
|
1
|
+
{"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../src/values.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAU/D;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAyBhD;AAOD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAQvD"}
|
package/dist/values.js
CHANGED
|
@@ -7,14 +7,28 @@ function getValue(values, path) {
|
|
|
7
7
|
return current[key];
|
|
8
8
|
}, values);
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Whether a value counts as filled: not null, not an empty or blank string, not an empty array or
|
|
12
|
+
* plain object. A file (`Blob`, `File`, even empty) is filled. Other collections count by their
|
|
13
|
+
* `length` or `size` (an empty `FileList`, `Map` or `Set` isn't filled); other objects are filled.
|
|
14
|
+
*/
|
|
11
15
|
function isFilled(value) {
|
|
12
16
|
if (value === null || value === void 0) return false;
|
|
13
17
|
if (typeof value === "string") return value.trim() !== "";
|
|
14
18
|
if (Array.isArray(value)) return value.length > 0;
|
|
15
|
-
if (typeof value === "object")
|
|
19
|
+
if (typeof value === "object") {
|
|
20
|
+
if (typeof Blob !== "undefined" && value instanceof Blob) return true;
|
|
21
|
+
if (isPlainObject(value)) return Object.keys(value).length > 0;
|
|
22
|
+
const { length, size } = value;
|
|
23
|
+
if (typeof length === "number") return length > 0;
|
|
24
|
+
return typeof size === "number" ? size > 0 : true;
|
|
25
|
+
}
|
|
16
26
|
return true;
|
|
17
27
|
}
|
|
28
|
+
function isPlainObject(value) {
|
|
29
|
+
const prototype = Object.getPrototypeOf(value);
|
|
30
|
+
return prototype === Object.prototype || prototype === null;
|
|
31
|
+
}
|
|
18
32
|
function isRecord(value) {
|
|
19
33
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
20
34
|
}
|
package/dist/values.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"values.js","names":[],"sources":["../src/values.ts"],"sourcesContent":["/** Reads a value at a dot path (`blocks.2.title.fr`). */\nexport function getValue(values: unknown, path: string): unknown {\n if (path === '') {\n return values;\n }\n return path.split('.').reduce<unknown>((current, key) => {\n if (current === null || typeof current !== 'object') {\n return undefined;\n }\n return (current as Record<string, unknown>)[key];\n }, values);\n}\n\n
|
|
1
|
+
{"version":3,"file":"values.js","names":[],"sources":["../src/values.ts"],"sourcesContent":["/** Reads a value at a dot path (`blocks.2.title.fr`). */\nexport function getValue(values: unknown, path: string): unknown {\n if (path === '') {\n return values;\n }\n return path.split('.').reduce<unknown>((current, key) => {\n if (current === null || typeof current !== 'object') {\n return undefined;\n }\n return (current as Record<string, unknown>)[key];\n }, values);\n}\n\n/**\n * Whether a value counts as filled: not null, not an empty or blank string, not an empty array or\n * plain object. A file (`Blob`, `File`, even empty) is filled. Other collections count by their\n * `length` or `size` (an empty `FileList`, `Map` or `Set` isn't filled); other objects are filled.\n */\nexport function isFilled(value: unknown): boolean {\n if (value === null || value === undefined) {\n return false;\n }\n if (typeof value === 'string') {\n return value.trim() !== '';\n }\n if (Array.isArray(value)) {\n return value.length > 0;\n }\n if (typeof value === 'object') {\n if (typeof Blob !== 'undefined' && value instanceof Blob) {\n return true;\n }\n // A chosen file has no own keys: only plain objects are empty without them.\n if (isPlainObject(value)) {\n return Object.keys(value).length > 0;\n }\n const { length, size } = value as { length?: unknown; size?: unknown };\n if (typeof length === 'number') {\n return length > 0;\n }\n return typeof size === 'number' ? size > 0 : true;\n }\n return true;\n}\n\nfunction isPlainObject(value: object): boolean {\n const prototype: unknown = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nexport function isEqual(a: unknown, b: unknown): boolean {\n if (a === b) {\n return true;\n }\n if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {\n return false;\n }\n return JSON.stringify(a) === JSON.stringify(b);\n}\n"],"mappings":";;AACA,SAAgB,SAAS,QAAiB,MAAuB;CAC7D,IAAI,SAAS,IACT,OAAO;CAEX,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,QAAiB,SAAS,QAAQ;EACrD,IAAI,YAAY,QAAQ,OAAO,YAAY,UACvC;EAEJ,OAAQ,QAAoC;CAChD,GAAG,MAAM;AACb;;;;;;AAOA,SAAgB,SAAS,OAAyB;CAC9C,IAAI,UAAU,QAAQ,UAAU,KAAA,GAC5B,OAAO;CAEX,IAAI,OAAO,UAAU,UACjB,OAAO,MAAM,KAAK,MAAM;CAE5B,IAAI,MAAM,QAAQ,KAAK,GACnB,OAAO,MAAM,SAAS;CAE1B,IAAI,OAAO,UAAU,UAAU;EAC3B,IAAI,OAAO,SAAS,eAAe,iBAAiB,MAChD,OAAO;EAGX,IAAI,cAAc,KAAK,GACnB,OAAO,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS;EAEvC,MAAM,EAAE,QAAQ,SAAS;EACzB,IAAI,OAAO,WAAW,UAClB,OAAO,SAAS;EAEpB,OAAO,OAAO,SAAS,WAAW,OAAO,IAAI;CACjD;CACA,OAAO;AACX;AAEA,SAAS,cAAc,OAAwB;CAC3C,MAAM,YAAqB,OAAO,eAAe,KAAK;CACtD,OAAO,cAAc,OAAO,aAAa,cAAc;AAC3D;AAEA,SAAgB,SAAS,OAAkD;CACvE,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC9E;AAEA,SAAgB,QAAQ,GAAY,GAAqB;CACrD,IAAI,MAAM,GACN,OAAO;CAEX,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,MAAM,QAAQ,MAAM,MACtE,OAAO;CAEX,OAAO,KAAK,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC;AACjD"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { type ListQuery } from './query.js';
|
|
2
|
+
import type { WidgetNumberFormat } from './schemas/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* The widget types that every client draws (decisions 0064 and 0084). Other types are widgets of
|
|
5
|
+
* plugins.
|
|
6
|
+
*/
|
|
7
|
+
export declare const BUILT_IN_WIDGET_TYPES: readonly ["stat", "series", "list", "breakdown", "metric", "table"];
|
|
8
|
+
export type BuiltInWidgetType = (typeof BUILT_IN_WIDGET_TYPES)[number];
|
|
9
|
+
/** The periods of the points of a `series` widget. */
|
|
10
|
+
export declare const WIDGET_SERIES_PERIODS: readonly ["day", "week", "month"];
|
|
11
|
+
export type WidgetSeriesPeriod = (typeof WIDGET_SERIES_PERIODS)[number];
|
|
12
|
+
/** The most items a `list` widget shows: the backend sends the most useful first. */
|
|
13
|
+
export declare const WIDGET_LIST_MAX_ITEMS = 5;
|
|
14
|
+
/** The most items of a `breakdown` widget: the rest is its `other`. */
|
|
15
|
+
export declare const WIDGET_BREAKDOWN_MAX_ITEMS = 10;
|
|
16
|
+
/** The parts of a `metric` that clients draw as bars: the rest goes in "Other" (decision 0089). */
|
|
17
|
+
export declare const WIDGET_METRIC_MAX_PARTS = 5;
|
|
18
|
+
/** The most lines of a `series` (decision 0089): 5 values of a field, and the rest. */
|
|
19
|
+
export declare const WIDGET_SERIES_MAX_SERIES = 6;
|
|
20
|
+
/**
|
|
21
|
+
* The most lines a `series` on resources reads (decision 0089): its `sources`, or the values of
|
|
22
|
+
* its `split`, past which the rest is one line, "Other".
|
|
23
|
+
*/
|
|
24
|
+
export declare const WIDGET_SOURCES_MAX = 5;
|
|
25
|
+
/** The most rows of a `table` widget, and of its `rows` on resources (decision 0089). */
|
|
26
|
+
export declare const WIDGET_TABLE_MAX_ROWS = 8;
|
|
27
|
+
/** The most columns of numbers of a `table` widget, after the column of the labels. */
|
|
28
|
+
export declare const WIDGET_TABLE_MAX_COLUMNS = 6;
|
|
29
|
+
/** How the columns of a `table` align their numbers: `end` by default. */
|
|
30
|
+
export declare const WIDGET_TABLE_ALIGNS: readonly ["start", "end"];
|
|
31
|
+
/** Whether a rise or a fall of a `metric` or a `table` is good news (`settings.goodWhen`). */
|
|
32
|
+
export declare const WIDGET_GOOD_WHEN: readonly ["up", "down"];
|
|
33
|
+
export type WidgetGoodWhen = (typeof WIDGET_GOOD_WHEN)[number];
|
|
34
|
+
/** The options of `Intl.NumberFormat` that a widget's `format` takes (decision 0089). */
|
|
35
|
+
export declare const WIDGET_FORMAT_STYLES: readonly ["decimal", "percent", "currency", "unit"];
|
|
36
|
+
export declare const WIDGET_FORMAT_CURRENCY_DISPLAYS: readonly ["symbol", "narrowSymbol", "code", "name"];
|
|
37
|
+
export declare const WIDGET_FORMAT_UNIT_DISPLAYS: readonly ["short", "narrow", "long"];
|
|
38
|
+
export declare const WIDGET_FORMAT_NOTATIONS: readonly ["standard", "compact"];
|
|
39
|
+
export declare const WIDGET_FORMAT_SIGN_DISPLAYS: readonly ["auto", "always", "exceptZero", "never"];
|
|
40
|
+
/**
|
|
41
|
+
* The units of `Intl.NumberFormat` (the sanctioned units of ECMA-402): a widget's `format` takes
|
|
42
|
+
* one, or two joined by `-per-` (`kilometer-per-hour`).
|
|
43
|
+
*/
|
|
44
|
+
export declare const WIDGET_FORMAT_UNITS: readonly ["acre", "bit", "byte", "celsius", "centimeter", "day", "degree", "fahrenheit", "fluid-ounce", "foot", "gallon", "gigabit", "gigabyte", "gram", "hectare", "hour", "inch", "kilobit", "kilobyte", "kilogram", "kilometer", "liter", "megabit", "megabyte", "meter", "microsecond", "mile", "mile-scandinavian", "milliliter", "millimeter", "millisecond", "minute", "month", "nanosecond", "ounce", "percent", "petabyte", "pound", "second", "stone", "terabit", "terabyte", "week", "yard", "year"];
|
|
45
|
+
/** Whether a string is a unit of `Intl.NumberFormat`, or two joined by `-per-`. */
|
|
46
|
+
export declare function isWidgetUnit(value: unknown): value is string;
|
|
47
|
+
/**
|
|
48
|
+
* The built-in types that can read a resource (`settings.resource`): `stat` and `list` read its
|
|
49
|
+
* list, `series`, `breakdown` and `metric` its aggregates, and a `stat` with a `sum:` measure too.
|
|
50
|
+
*/
|
|
51
|
+
export declare const RESOURCE_WIDGET_TYPES: readonly ["stat", "series", "list", "breakdown", "metric"];
|
|
52
|
+
/** The built-in types that read the aggregates of a resource, grouped by `settings.group`. */
|
|
53
|
+
export declare const GROUPED_WIDGET_TYPES: readonly ["series", "breakdown"];
|
|
54
|
+
/** Query parameters that the client sets on the list of a widget on a resource, never `query`. */
|
|
55
|
+
export declare const WIDGET_RESERVED_QUERY_PARAMS: readonly ["page", "perPage", "cursor"];
|
|
56
|
+
export declare function isBuiltInWidgetType(type: string): type is BuiltInWidgetType;
|
|
57
|
+
/** A widget as the helpers read it: the `Widget` of the definition, or one a backend writes. */
|
|
58
|
+
interface WidgetLike {
|
|
59
|
+
type: string;
|
|
60
|
+
settings?: Record<string, unknown> | undefined;
|
|
61
|
+
}
|
|
62
|
+
/** What a widget reads of `GET /resources/{resource}/aggregate` (decision 0084). */
|
|
63
|
+
export interface WidgetAggregate {
|
|
64
|
+
/** `count`, or `sum:{field}`. */
|
|
65
|
+
measure: string;
|
|
66
|
+
/** `{period}:{date field}` or a field of `groupBy`, for a `series` or a `breakdown`. */
|
|
67
|
+
group: string | null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A built-in widget that reads a resource, with no data of its own (decisions 0064 and 0084): its
|
|
71
|
+
* list, or its aggregates.
|
|
72
|
+
*/
|
|
73
|
+
export interface WidgetResource {
|
|
74
|
+
/** The id of the resource. */
|
|
75
|
+
resource: string;
|
|
76
|
+
/** The `query` of the widget, as query parameters, without `page`, `perPage` and `cursor`. */
|
|
77
|
+
params: URLSearchParams;
|
|
78
|
+
/** The same query, parsed: the query of the list request, and of the link to the list. */
|
|
79
|
+
query: ListQuery;
|
|
80
|
+
/**
|
|
81
|
+
* The measure and the group of the aggregates the widget reads: a `series`, a `breakdown`, and
|
|
82
|
+
* a `stat` with a `sum:` measure. `null` for a `list`, and a `stat` that counts the items of
|
|
83
|
+
* the list (`meta.total`).
|
|
84
|
+
*/
|
|
85
|
+
aggregate: WidgetAggregate | null;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The resource that feeds a built-in widget, its query, and the aggregates it reads: `null` for a
|
|
89
|
+
* widget with data of its own at `GET /dashboard/widgets/{widget}`, and for widgets of plugins.
|
|
90
|
+
*/
|
|
91
|
+
export declare function getWidgetResource(widget: WidgetLike): WidgetResource | null;
|
|
92
|
+
/** The items of a source that call for attention, counted with its query and period. */
|
|
93
|
+
export interface WidgetSourceAlert {
|
|
94
|
+
/** The query of the source with the alert's on top: the request, and the link to the list. */
|
|
95
|
+
params: URLSearchParams;
|
|
96
|
+
query: ListQuery;
|
|
97
|
+
/** What they are, after their count: `failed`. */
|
|
98
|
+
label: string;
|
|
99
|
+
/** Their tone: `danger` by default. */
|
|
100
|
+
tone: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* A source of a widget on several resources (decision 0089): a line of a `series` with
|
|
104
|
+
* `settings.sources`, or a row of a `table` with `settings.rows`.
|
|
105
|
+
*/
|
|
106
|
+
export interface WidgetSource {
|
|
107
|
+
resource: string;
|
|
108
|
+
label: string;
|
|
109
|
+
/** Its query, as query parameters, without `page`, `perPage` and `cursor`; and parsed. */
|
|
110
|
+
params: URLSearchParams;
|
|
111
|
+
query: ListQuery;
|
|
112
|
+
/** `count`, or `sum:{field}`. */
|
|
113
|
+
measure: string;
|
|
114
|
+
/**
|
|
115
|
+
* `{period}:{date field}`: the points of a line of a `series` (its `group`, or the widget's),
|
|
116
|
+
* of the trend of a row of a `table` (its `points`, or the widget's). `null` without one.
|
|
117
|
+
*/
|
|
118
|
+
group: string | null;
|
|
119
|
+
/**
|
|
120
|
+
* The `date-range` filter of its list that gets the period of the overview (its `period`, or
|
|
121
|
+
* the widget's), `false` when it doesn't follow it, `null` when none is named.
|
|
122
|
+
*/
|
|
123
|
+
period: string | false | null;
|
|
124
|
+
/** A line under its label (a line of a `series`). */
|
|
125
|
+
help: string | null;
|
|
126
|
+
/** The tone of its line (a line of a `series`). */
|
|
127
|
+
tone: string | null;
|
|
128
|
+
alert: WidgetSourceAlert | null;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The sources of a widget on several resources (decision 0089): the `sources` of a `series`, at
|
|
132
|
+
* most `WIDGET_SOURCES_MAX`, or the `rows` of a `table`, at most `WIDGET_TABLE_MAX_ROWS`. Each one
|
|
133
|
+
* takes the `group` (`points` for a row) and the `period` of the widget when it has none. Empty for
|
|
134
|
+
* other widgets.
|
|
135
|
+
*/
|
|
136
|
+
export declare function getWidgetSources(widget: WidgetLike): WidgetSource[];
|
|
137
|
+
/**
|
|
138
|
+
* Whether a built-in widget reads resources rather than data of its own at
|
|
139
|
+
* `GET /dashboard/widgets/{widget}`: `settings.resource`, or the `sources` of a `series` or the
|
|
140
|
+
* `rows` of a `table` (decision 0089).
|
|
141
|
+
*/
|
|
142
|
+
export declare function readsResources(widget: WidgetLike): boolean;
|
|
143
|
+
/** What a read of the aggregates of a widget is for, when it combines several (decision 0089). */
|
|
144
|
+
export type WidgetAggregateRole =
|
|
145
|
+
/** The number: of a `metric`, of a row of a `table`. */
|
|
146
|
+
'value'
|
|
147
|
+
/** A line of points: the trend of a `metric` or of a row, a line of a `series`, its total. */
|
|
148
|
+
| 'points'
|
|
149
|
+
/** The parts of a `metric` (`by`), the values of the `split` of a `series`. */
|
|
150
|
+
| 'parts'
|
|
151
|
+
/** The count of the alert of a source. */
|
|
152
|
+
| 'alert';
|
|
153
|
+
/** A read of `GET /resources/{resource}/aggregate` that a combined widget makes. */
|
|
154
|
+
export interface WidgetAggregateRead {
|
|
155
|
+
role: WidgetAggregateRole;
|
|
156
|
+
/** The index of its source (`sources`, `rows`), `null` for the widget's own `resource`. */
|
|
157
|
+
source: number | null;
|
|
158
|
+
resource: string;
|
|
159
|
+
/** The filters and the search of the widget or of its source. */
|
|
160
|
+
query: ListQuery;
|
|
161
|
+
measure: string;
|
|
162
|
+
group: string | null;
|
|
163
|
+
/** The `date-range` filter that gets the period of the overview, as for its source. */
|
|
164
|
+
period: string | false | null;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Whether a widget combines several reads of the aggregates of resources into one card (decision
|
|
168
|
+
* 0089): a `metric` on a resource, a `series` with `split` or `sources`, a `table` with `rows`.
|
|
169
|
+
*/
|
|
170
|
+
export declare function isCombinedWidget(widget: WidgetLike): boolean;
|
|
171
|
+
/**
|
|
172
|
+
* The reads of the aggregates that a combined widget makes, whatever the period (decision 0089).
|
|
173
|
+
* A client adds, with a period, the `value` of each source over the previous period, and for a
|
|
174
|
+
* `split`, a line per value of its `parts`, filtered by it.
|
|
175
|
+
*
|
|
176
|
+
* - `metric`: its `value`, its `points` with `settings.points`, its `parts` with `settings.by`.
|
|
177
|
+
* - `series` with `split`: its total line (`points`), and the `parts` of the field it splits by.
|
|
178
|
+
* - `series` with `sources`: a line per source (`points`), and the count of its alert.
|
|
179
|
+
* - `table` with `rows`: per row, its `value`, its `points`, and the count of its alert.
|
|
180
|
+
*/
|
|
181
|
+
export declare function getWidgetAggregates(widget: WidgetLike): WidgetAggregateRead[];
|
|
182
|
+
/**
|
|
183
|
+
* Whether a widget of the summary of a resource follows its list (decision 0084), and gets its
|
|
184
|
+
* current filters and search: a widget on that resource, or with data of its own, unless its
|
|
185
|
+
* `settings.followsList` is `false`. A widget on another resource doesn't.
|
|
186
|
+
*/
|
|
187
|
+
export declare function followsList(widget: WidgetLike, resource: string): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Whether a widget follows the period of its overview (decision 0084): a built-in widget on a
|
|
190
|
+
* resource with `settings.period`, the list's `date-range` filter that gets its days; in the
|
|
191
|
+
* summary of `summaryOf`, a widget that follows its list, whose `date-range` filter the period is;
|
|
192
|
+
* and a widget with data of its own, which gets the period, unless `settings.period` is `false`.
|
|
193
|
+
*/
|
|
194
|
+
export declare function followsPeriod(widget: WidgetLike, summaryOf?: string): boolean;
|
|
195
|
+
/**
|
|
196
|
+
* The format of the numbers of a widget (decision 0089): the options of `Intl.NumberFormat` among
|
|
197
|
+
* those a widget takes, with valid values, or `undefined` without any. A style without its
|
|
198
|
+
* `currency` or its `unit` is left out, as an unknown key. The `format` of the data, then the
|
|
199
|
+
* `format` of the settings over it, key by key: `readWidgetFormat(data.format, settings.format)`.
|
|
200
|
+
*/
|
|
201
|
+
export declare function readWidgetFormat(...formats: unknown[]): WidgetNumberFormat | undefined;
|
|
202
|
+
/**
|
|
203
|
+
* Checks the data of a widget against the shape of its type (decisions 0064, 0084 and 0089),
|
|
204
|
+
* without the schemas: the paths of the wrong keys (`value`, `points.2.date`), empty when it is
|
|
205
|
+
* right. The data of a widget of a plugin only has to be an object. The dates of a series must go
|
|
206
|
+
* up, one point per period.
|
|
207
|
+
*/
|
|
208
|
+
export declare function checkWidgetData(type: string, data: unknown): string[];
|
|
209
|
+
/**
|
|
210
|
+
* Whether the data of a built-in widget has nothing to show (decision 0089), for
|
|
211
|
+
* `settings.hideEmpty`: a `stat` at 0, a `metric` at 0 that was at 0 or has no previous value, a
|
|
212
|
+
* `series` whose points are all 0, a `breakdown` whose parts and rest are all 0, a `list` without
|
|
213
|
+
* items, a `table` without rows. Data of plugins is never empty.
|
|
214
|
+
*/
|
|
215
|
+
export declare function isWidgetDataEmpty(type: string, data: unknown): boolean;
|
|
216
|
+
/** The change of a number from the previous period (decision 0089). */
|
|
217
|
+
export interface WidgetChange {
|
|
218
|
+
/** The value minus the previous one. */
|
|
219
|
+
difference: number;
|
|
220
|
+
/** The difference against the previous value (`0.12` for 12%): `null` when it was 0. */
|
|
221
|
+
ratio: number | null;
|
|
222
|
+
direction: 'up' | 'down' | 'none';
|
|
223
|
+
}
|
|
224
|
+
/** The change of a number from its value over the previous period (decision 0089). */
|
|
225
|
+
export declare function getWidgetChange(value: number, previous: number): WidgetChange;
|
|
226
|
+
/**
|
|
227
|
+
* The tone of a change (decision 0089): `success` when it goes the way `goodWhen` says is good,
|
|
228
|
+
* `danger` the other way, and none without `goodWhen` or without a change.
|
|
229
|
+
*/
|
|
230
|
+
export declare function getChangeTone(direction: WidgetChange['direction'], goodWhen: unknown): 'success' | 'danger' | null;
|
|
231
|
+
export {};
|
|
232
|
+
//# sourceMappingURL=widgets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgets.d.ts","sourceRoot":"","sources":["../src/widgets.ts"],"names":[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