@panneau/protocol 5.0.0-alpha.3 → 5.0.0-alpha.31
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/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 +801 -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/index.d.ts +4 -4
- package/dist/index.js +19 -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 -3
- package/dist/lint.d.ts.map +1 -1
- package/dist/lint.js +168 -7
- 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 +3 -2
- package/dist/mock/example.d.ts.map +1 -1
- package/dist/mock/example.js +241 -144
- package/dist/mock/example.js.map +1 -1
- package/dist/mock/index.d.ts +79 -7
- package/dist/mock/index.d.ts.map +1 -1
- package/dist/mock/index.js +603 -38
- package/dist/mock/index.js.map +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +392 -144
- package/dist/openapi.js.map +1 -1
- 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 +20 -10
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +13 -3
- package/dist/schemas/action.d.ts +118 -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 +334 -42
- package/dist/schemas/api.d.ts.map +1 -1
- package/dist/schemas/api.js +194 -34
- 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 +341 -28
- package/dist/schemas/definition.d.ts.map +1 -1
- package/dist/schemas/definition.js +65 -19
- package/dist/schemas/definition.js.map +1 -1
- package/dist/schemas/field.d.ts +357 -2
- package/dist/schemas/field.d.ts.map +1 -1
- package/dist/schemas/field.js +160 -20
- package/dist/schemas/field.js.map +1 -1
- package/dist/schemas/index.d.ts +1429 -80
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +60 -10
- 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 +23 -2
- package/dist/schemas/list.d.ts.map +1 -1
- package/dist/schemas/list.js +15 -6
- package/dist/schemas/list.js.map +1 -1
- package/dist/schemas/resource.d.ts +263 -17
- package/dist/schemas/resource.d.ts.map +1 -1
- package/dist/schemas/resource.js +19 -4
- package/dist/schemas/resource.js.map +1 -1
- package/dist/schemas/theme.d.ts +4 -0
- package/dist/schemas/theme.d.ts.map +1 -1
- package/dist/schemas/theme.js +1 -0
- package/dist/schemas/theme.js.map +1 -1
- package/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/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 +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 +6 -3
- package/schema/boot.schema.json +713 -20
- package/schema/definition.schema.json +710 -20
- package/schema/openapi.json +5656 -2229
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.js","names":[],"sources":["../../src/schemas/theme.ts"],"sourcesContent":["import { z } from 'zod';\n\n/** Names of tones, palette colors, components and variants: they become CSS class names. */\nconst Name = z.string().regex(/^[a-z0-9-]+$/);\n\nexport const ThemeTokens = z\n .record(z.string().regex(/^[a-zA-Z0-9_-]+$/), z.string().regex(/^[^{};<]*$/))\n .meta({\n description:\n 'CSS variables without the leading `--`, and their values: `{ \"panneau-color-accent\": \"#05f\" }`. Values cannot contain `{`, `}`, `;` or `<`.',\n });\n\nexport const ToneValues = z.looseObject({\n text: z.string().meta({ description: 'Text and icons on surfaces.' }),\n subtle: z.string().meta({ description: 'Background of the subtle appearance.' }),\n border: z.string().meta({ description: 'Border of the subtle appearance.' }),\n outline: z.string().meta({ description: 'Border of the outline appearance.' }),\n solid: z.string().meta({ description: 'Background of the solid appearance.' }),\n solidHover: z.string().meta({ description: 'Background of the solid appearance on hover.' }),\n solidText: z.string().meta({ description: 'Text on the solid appearance.' }),\n});\n\nexport const ToneInput = z\n .union([\n z.string().meta({ description: 'One color, from which Panneau derives the others.' }),\n ToneValues.extend({ dark: ToneValues.partial().optional() }),\n ])\n .meta({ description: 'A tone: one color, or every value with dark scheme overrides.' });\n\nexport const ThemeFontFace = z\n .looseObject({\n family: z.string().regex(/^[^{}<;\"\\\\]+$/),\n src: z\n .string()\n .regex(/^[^{}<]+$/)\n .meta({\n description: \"The `src` descriptor: `url(/fonts/geist.woff2) format('woff2')`.\",\n }),\n weight: z\n .string()\n .regex(/^[^{}<;]*$/)\n .optional(),\n style: z\n .string()\n .regex(/^[^{}<;]*$/)\n .optional(),\n display: z.enum(['auto', 'block', 'swap', 'fallback', 'optional']).optional(),\n unicodeRange: z\n .string()\n .regex(/^[^{}<;]*$/)\n .optional(),\n })\n .meta({ description: 'A font face, written as an `@font-face` rule.' });\n\nexport const ThemeFontStylesheet = z\n .looseObject({ stylesheet: z.string().min(1) })\n .meta({ description: 'A hosted stylesheet that declares font faces.' });\n\nexport const ThemeFont = z.union([ThemeFontFace, ThemeFontStylesheet]);\n\nconst themeShape = {\n label: z.string().optional(),\n tokens: ThemeTokens.meta({\n description:\n 'Tokens of the light scheme, or of both schemes when `dark` does not set them.',\n }),\n dark: ThemeTokens.optional().meta({ description: 'Tokens that change in the dark scheme.' }),\n palette: z\n .record(Name, z.string().regex(/^[^{};<]*$/))\n .optional()\n .meta({\n description:\n 'Raw colors, written as `--panneau-palette-<name>`: tokens and tones use them with `var(--panneau-palette-<name>)`.',\n }),\n tones: z.record(Name, ToneInput).optional().meta({\n description: 'Tones added or redefined by the theme, applied by `panneau-tone-<name>`.',\n }),\n components: z\n .record(Name, z.looseObject({ variants: z.record(Name, ThemeTokens).optional() }))\n .optional()\n .meta({\n description:\n 'Named variants of components: tokens applied by `panneau-<component>-variant-<name>`.',\n }),\n densities: z\n .looseObject({\n compact: ThemeTokens.optional(),\n comfortable: ThemeTokens.optional(),\n touch: ThemeTokens.optional(),\n })\n .optional()\n .meta({\n description:\n 'Tokens of each density (`panneau-control-height`…), which change with the density of the root.',\n }),\n fonts: z.array(ThemeFont).optional().meta({\n description: 'Font faces and font stylesheets, added to the page once.',\n }),\n};\n\nexport const Theme = z\n .looseObject(themeShape)\n .meta({ description: 'A theme of `@panneau/ui`, as plain data (decision 0024).' });\n\nexport const DefinitionTheme = z\n .looseObject({\n ...themeShape,\n tokens: themeShape.tokens.optional(),\n colorScheme: z.enum(['light', 'dark', 'auto']).optional(),\n density: z.enum(['compact', 'comfortable', 'touch', 'auto']).optional(),\n extends: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .meta({\n description:\n 'Themes registered by plugins, by id, that this theme builds on, in order: its own values override theirs.',\n }),\n })\n .meta({ description: 'The theme of the admin: a theme, built on themes of plugins.' });\n\nexport type ThemeTokens = z.infer<typeof ThemeTokens>;\nexport type ToneValues = z.infer<typeof ToneValues>;\nexport type ToneInput = z.infer<typeof ToneInput>;\nexport type Theme = z.infer<typeof Theme>;\nexport type DefinitionTheme = z.infer<typeof DefinitionTheme>;\nexport type ThemeFontFace = z.infer<typeof ThemeFontFace>;\nexport type ThemeFontStylesheet = z.infer<typeof ThemeFontStylesheet>;\nexport type ThemeFont = z.infer<typeof ThemeFont>;\n"],"mappings":";;;AAGA,IAAM,OAAO,EAAE,OAAO,CAAC,CAAC,MAAM,cAAc;AAE5C,IAAa,cAAc,EACtB,OAAO,EAAE,OAAO,CAAC,CAAC,MAAM,kBAAkB,GAAG,EAAE,OAAO,CAAC,CAAC,MAAM,YAAY,CAAC,CAAC,CAC5E,KAAK,EACF,aACI,kJACR,CAAC;AAEL,IAAa,aAAa,EAAE,YAAY;CACpC,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,aAAa,8BAA8B,CAAC;CACpE,QAAQ,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,aAAa,uCAAuC,CAAC;CAC/E,QAAQ,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,aAAa,mCAAmC,CAAC;CAC3E,SAAS,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,aAAa,oCAAoC,CAAC;CAC7E,OAAO,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,aAAa,sCAAsC,CAAC;CAC7E,YAAY,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,aAAa,+CAA+C,CAAC;CAC3F,WAAW,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,aAAa,gCAAgC,CAAC;AAC/E,CAAC;AAED,IAAa,YAAY,EACpB,MAAM,CACH,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,aAAa,oDAAoD,CAAC,GACpF,WAAW,OAAO,EAAE,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,EAAE,CAAC,CAC/D,CAAC,CAAC,CACD,KAAK,EAAE,aAAa,gEAAgE,CAAC;AAE1F,IAAa,gBAAgB,EACxB,YAAY;CACT,QAAQ,EAAE,OAAO,CAAC,CAAC,MAA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YAAY,SAAS;EAC9B,aAAa,YAAY,SAAS;EAClC,OAAO,YAAY,SAAS;CAChC,CAAC,CAAC,CACD,SAAS,CAAC,CACV,KAAK,EACF,aACI,iGACR,CAAC;CACL,OAAO,EAAE,MAAM,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EACtC,aAAa,2DACjB,CAAC;AACL;AAEA,IAAa,QAAQ,EAChB,YAAY,UAAU,CAAC,CACvB,KAAK,EAAE,aAAa,2DAA2D,CAAC;AAErF,IAAa,kBAAkB,EAC1B,YAAY;CACT,GAAG;CACH,QAAQ,WAAW,OAAO,SAAS;CACnC,aAAa,EAAE,KAAK;EAAC;EAAS;EAAQ;CAAM,CAAC,CAAC,CAAC,SAAS;CACxD,SAAS,EAAE,KAAK;EAAC;EAAW;EAAe;EAAS;CAAM,CAAC,CAAC,CAAC,SAAS;CACtE,SAAS,EACJ,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CACxC,SAAS,CAAC,CACV,KAAK,EACF,aACI,4GACR,CAAC;AACT,CAAC,CAAC,CACD,KAAK,EAAE,aAAa,+DAA+D,CAAC"}
|
|
1
|
+
{"version":3,"file":"theme.js","names":[],"sources":["../../src/schemas/theme.ts"],"sourcesContent":["import { z } from 'zod';\n\n/** Names of tones, palette colors, components and variants: they become CSS class names. */\nconst Name = z.string().regex(/^[a-z0-9-]+$/);\n\nexport const ThemeTokens = z\n .record(z.string().regex(/^[a-zA-Z0-9_-]+$/), z.string().regex(/^[^{};<]*$/))\n .meta({\n description:\n 'CSS variables without the leading `--`, and their values: `{ \"panneau-color-accent\": \"#05f\" }`. Values cannot contain `{`, `}`, `;` or `<`.',\n });\n\nexport const ToneValues = z.looseObject({\n text: z.string().meta({ description: 'Text and icons on surfaces.' }),\n subtle: z.string().meta({ description: 'Background of the subtle appearance.' }),\n border: z.string().meta({ description: 'Border of the subtle appearance.' }),\n outline: z.string().meta({ description: 'Border of the outline appearance.' }),\n solid: z.string().meta({ description: 'Background of the solid appearance.' }),\n solidHover: z.string().meta({ description: 'Background of the solid appearance on hover.' }),\n solidText: z.string().meta({ description: 'Text on the solid appearance.' }),\n});\n\nexport const ToneInput = z\n .union([\n z.string().meta({ description: 'One color, from which Panneau derives the others.' }),\n ToneValues.extend({ dark: ToneValues.partial().optional() }),\n ])\n .meta({ description: 'A tone: one color, or every value with dark scheme overrides.' });\n\nexport const ThemeFontFace = z\n .looseObject({\n family: z.string().regex(/^[^{}<;\"\\\\]+$/),\n src: z\n .string()\n .regex(/^[^{}<]+$/)\n .meta({\n description: \"The `src` descriptor: `url(/fonts/geist.woff2) format('woff2')`.\",\n }),\n weight: z\n .string()\n .regex(/^[^{}<;]*$/)\n .optional(),\n style: z\n .string()\n .regex(/^[^{}<;]*$/)\n .optional(),\n display: z.enum(['auto', 'block', 'swap', 'fallback', 'optional']).optional(),\n unicodeRange: z\n .string()\n .regex(/^[^{}<;]*$/)\n .optional(),\n })\n .meta({ description: 'A font face, written as an `@font-face` rule.' });\n\nexport const ThemeFontStylesheet = z\n .looseObject({ stylesheet: z.string().min(1) })\n .meta({ description: 'A hosted stylesheet that declares font faces.' });\n\nexport const ThemeFont = z.union([ThemeFontFace, ThemeFontStylesheet]);\n\nconst themeShape = {\n label: z.string().optional(),\n tokens: ThemeTokens.meta({\n description:\n 'Tokens of the light scheme, or of both schemes when `dark` does not set them.',\n }),\n dark: ThemeTokens.optional().meta({ description: 'Tokens that change in the dark scheme.' }),\n palette: z\n .record(Name, z.string().regex(/^[^{};<]*$/))\n .optional()\n .meta({\n description:\n 'Raw colors, written as `--panneau-palette-<name>`: tokens and tones use them with `var(--panneau-palette-<name>)`.',\n }),\n tones: z.record(Name, ToneInput).optional().meta({\n description: 'Tones added or redefined by the theme, applied by `panneau-tone-<name>`.',\n }),\n components: z\n .record(Name, z.looseObject({ variants: z.record(Name, ThemeTokens).optional() }))\n .optional()\n .meta({\n description:\n 'Named variants of components: tokens applied by `panneau-<component>-variant-<name>`.',\n }),\n densities: z\n .looseObject({\n compact: ThemeTokens.optional(),\n comfortable: ThemeTokens.optional(),\n touch: ThemeTokens.optional(),\n })\n .optional()\n .meta({\n description:\n 'Tokens of each density (`panneau-control-height`…), which change with the density of the root.',\n }),\n fonts: z.array(ThemeFont).optional().meta({\n description: 'Font faces and font stylesheets, added to the page once.',\n }),\n};\n\nexport const Theme = z\n .looseObject(themeShape)\n .meta({ description: 'A theme of `@panneau/ui`, as plain data (decision 0024).' });\n\nexport const DefinitionTheme = z\n .looseObject({\n ...themeShape,\n tokens: themeShape.tokens.optional(),\n colorScheme: z.enum(['light', 'dark', 'auto']).optional(),\n density: z.enum(['compact', 'comfortable', 'touch', 'auto']).optional(),\n navigation: z.enum(['sidebar', 'dock']).optional().meta({\n description:\n 'Where the app shows the `main` menu: `sidebar` (the default), a column on the left, or `dock`, a dock at the bottom of the window (decision 0076).',\n }),\n extends: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .meta({\n description:\n 'Themes registered by plugins, by id, that this theme builds on, in order: its own values override theirs.',\n }),\n })\n .meta({ description: 'The theme of the admin: a theme, built on themes of plugins.' });\n\nexport type ThemeTokens = z.infer<typeof ThemeTokens>;\nexport type ToneValues = z.infer<typeof ToneValues>;\nexport type ToneInput = z.infer<typeof ToneInput>;\nexport type Theme = z.infer<typeof Theme>;\nexport type DefinitionTheme = z.infer<typeof DefinitionTheme>;\nexport type ThemeFontFace = z.infer<typeof ThemeFontFace>;\nexport type ThemeFontStylesheet = z.infer<typeof ThemeFontStylesheet>;\nexport type ThemeFont = z.infer<typeof ThemeFont>;\n"],"mappings":";;;AAGA,IAAM,OAAO,EAAE,OAAO,CAAC,CAAC,MAAM,cAAc;AAE5C,IAAa,cAAc,EACtB,OAAO,EAAE,OAAO,CAAC,CAAC,MAAM,kBAAkB,GAAG,EAAE,OAAO,CAAC,CAAC,MAAM,YAAY,CAAC,CAAC,CAC5E,KAAK,EACF,aACI,kJACR,CAAC;AAEL,I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S;EAAQ;CAAM,CAAC,CAAC,CAAC,SAAS;CACxD,SAAS,EAAE,KAAK;EAAC;EAAW;EAAe;EAAS;CAAM,CAAC,CAAC,CAAC,SAAS;CACtE,YAAY,EAAE,KAAK,CAAC,WAAW,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EACpD,aACI,qJACR,CAAC;CACD,SAAS,EACJ,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CACxC,SAAS,CAAC,CACV,KAAK,EACF,aACI,4GACR,CAAC;AACT,CAAC,CAAC,CACD,KAAK,EAAE,aAAa,+DAA+D,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const WidgetSettings: z.ZodObject<{
|
|
3
|
+
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"],"mappings":";;;AAIA,IAAM,WAAW,EAAE,OAAO,CAAC,CAAC,MAAM,cAAc;AAEhD,IAAM,aAAa,EAAE,MAAM;CAAC,EAAE,OAAO;CAAG,EAAE,OAAO;CAAG,EAAE,QAAQ;AAAC,CAAC;AAEhE,IAAa,iBAAiB,EACzB,YAAY;CACT,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EACxC,aACI,6QACR,CAAC;CACD,OAAO,EACF,OAAO,EAAE,OAAO,GAAG,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,UAAU,CAAC,CAAC,CAAC,CAAC,CAC9D,SAAS,CAAC,CACV,KAAK,EACF,aACI,oNACR,CAAC;AACT,CAAC,CAAC,CACD,KAAK,EACF,aACI,2IACR,CAAC;AAEL,IAAa,SAAS,EAAE,YAAY;CAChC,IAAI,EACC,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,KAAK,EAAE,aAAa,wDAAwD,CAAC;CAClF,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EACzB,aACI,0IAC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zC,aAAa,kDACjB,CAAC;AACL,CAAC,CAAC,CACD,aAAa,MAAM,YAAY;CAC5B,KAAK,OAAO,SAAS,OAAO,UAAU;EAClC,MAAM,WAAW,KAAK,OAAO,QAAQ;EACrC,IAAI,aAAa,KAAA,KAAa,MAAM,QAAQ,SAAS,MACjD,QAAQ,SAAS;GACb,MAAM;GACN,SAAS;GACT,MAAM;IAAC;IAAU;IAAO;GAAM;EAClC,CAAC;CAET,CAAC;AACL,CAAC,CAAC,CACD,KAAK,EACF,aAAa,8EACjB,CAAC;AAEL,IAAa,iBAAiB,EAAE,YAAY;CACxC,OAAO,EAAE,OAAO;CAChB,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CAC5C,MAAM,EACD,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,CAAC,CACV,KAAK,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"}
|
package/dist/search.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Shortest search, in characters once trimmed: shorter is a `422`. */
|
|
2
|
+
export declare const SEARCH_MIN_LENGTH = 2;
|
|
3
|
+
/** Longest search, in characters. */
|
|
4
|
+
export declare const SEARCH_MAX_LENGTH = 255;
|
|
5
|
+
/** Items per resource without a `limit`. */
|
|
6
|
+
export declare const SEARCH_DEFAULT_LIMIT = 5;
|
|
7
|
+
/** Highest `limit`, and most items of a response, every resource together. */
|
|
8
|
+
export declare const SEARCH_MAX_LIMIT = 20;
|
|
9
|
+
/** What the global search reads of a resource. */
|
|
10
|
+
export interface SearchableResource {
|
|
11
|
+
id: string;
|
|
12
|
+
features?: {
|
|
13
|
+
search?: boolean | undefined;
|
|
14
|
+
} | undefined;
|
|
15
|
+
list?: {
|
|
16
|
+
search?: boolean | undefined;
|
|
17
|
+
} | undefined;
|
|
18
|
+
}
|
|
19
|
+
/** Query of the global search (`GET /search`). */
|
|
20
|
+
export interface SearchQuery {
|
|
21
|
+
q: string;
|
|
22
|
+
/** Items per resource, from 1 to 20. Defaults to 5. */
|
|
23
|
+
limit?: number;
|
|
24
|
+
/** Ids of the searchable resources to search. Defaults to every one. */
|
|
25
|
+
resources?: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Whether a resource is in the global search: its `features.search`, or, without it, whether its
|
|
29
|
+
* list has a search (`list.search`), so one setting serves both (decision 0029).
|
|
30
|
+
*/
|
|
31
|
+
export declare function isSearchableResource(resource: Omit<SearchableResource, 'id'>): boolean;
|
|
32
|
+
/** Serializes a search query: `q=été&limit=20&resources=pages,articles`. */
|
|
33
|
+
export declare function toSearchQueryParams(query: SearchQuery): URLSearchParams;
|
|
34
|
+
/** A search query as a backend reads it: valid, or the messages of its invalid parameters. */
|
|
35
|
+
export type ReadSearchQueryResult = {
|
|
36
|
+
query: Required<SearchQuery>;
|
|
37
|
+
errors?: undefined;
|
|
38
|
+
} | {
|
|
39
|
+
query?: undefined;
|
|
40
|
+
errors: Record<string, string[]>;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Reads the query string of `GET /search`: the reference of how a backend validates it. `q` is
|
|
44
|
+
* trimmed and needs 2 characters; `limit` is an integer from 1 to 20; `resources` lists searchable
|
|
45
|
+
* resources of the definition. Invalid parameters are a `422`, with `errors` keyed by parameter.
|
|
46
|
+
* Without `resources`, every searchable resource is searched, in the order of the definition.
|
|
47
|
+
*/
|
|
48
|
+
export declare function readSearchQuery(params: URLSearchParams, definition: {
|
|
49
|
+
resources: readonly SearchableResource[];
|
|
50
|
+
}): ReadSearchQueryResult;
|
|
51
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,eAAO,MAAM,iBAAiB,IAAI,CAAC;AACnC,qCAAqC;AACrC,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,4CAA4C;AAC5C,eAAO,MAAM,oBAAoB,IAAI,CAAC;AACtC,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,kDAAkD;AAClD,MAAM,WAAW,kBAAkB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;KAAE,GAAG,SAAS,CAAC;IACxD,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;KAAE,GAAG,SAAS,CAAC;CACvD;AAED,kDAAkD;AAClD,MAAM,WAAW,WAAW;IACxB,CAAC,EAAE,MAAM,CAAC;IACV,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACjC;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,GAAG,OAAO,CAEtF;AAED,4EAA4E;AAC5E,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,eAAe,CASvE;AAED,8FAA8F;AAC9F,MAAM,MAAM,qBAAqB,GAC3B;IAAE,KAAK,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAAC,MAAM,CAAC,EAAE,SAAS,CAAA;CAAE,GACpD;IAAE,KAAK,CAAC,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC;AAE9D;;;;;GAKG;AACH,wBAAgB,eAAe,CAC3B,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE;IAAE,SAAS,EAAE,SAAS,kBAAkB,EAAE,CAAA;CAAE,GACzD,qBAAqB,CAyCvB"}
|
package/dist/search.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/search.ts
|
|
2
|
+
/** Shortest search, in characters once trimmed: shorter is a `422`. */
|
|
3
|
+
var SEARCH_MIN_LENGTH = 2;
|
|
4
|
+
/** Longest search, in characters. */
|
|
5
|
+
var SEARCH_MAX_LENGTH = 255;
|
|
6
|
+
/** Items per resource without a `limit`. */
|
|
7
|
+
var SEARCH_DEFAULT_LIMIT = 5;
|
|
8
|
+
/** Highest `limit`, and most items of a response, every resource together. */
|
|
9
|
+
var SEARCH_MAX_LIMIT = 20;
|
|
10
|
+
/**
|
|
11
|
+
* Whether a resource is in the global search: its `features.search`, or, without it, whether its
|
|
12
|
+
* list has a search (`list.search`), so one setting serves both (decision 0029).
|
|
13
|
+
*/
|
|
14
|
+
function isSearchableResource(resource) {
|
|
15
|
+
return resource.features?.search ?? resource.list?.search ?? false;
|
|
16
|
+
}
|
|
17
|
+
/** Serializes a search query: `q=été&limit=20&resources=pages,articles`. */
|
|
18
|
+
function toSearchQueryParams(query) {
|
|
19
|
+
const params = new URLSearchParams({ q: query.q });
|
|
20
|
+
if (query.limit !== void 0) params.set("limit", String(query.limit));
|
|
21
|
+
if (query.resources !== void 0 && query.resources.length > 0) params.set("resources", query.resources.join(","));
|
|
22
|
+
return params;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Reads the query string of `GET /search`: the reference of how a backend validates it. `q` is
|
|
26
|
+
* trimmed and needs 2 characters; `limit` is an integer from 1 to 20; `resources` lists searchable
|
|
27
|
+
* resources of the definition. Invalid parameters are a `422`, with `errors` keyed by parameter.
|
|
28
|
+
* Without `resources`, every searchable resource is searched, in the order of the definition.
|
|
29
|
+
*/
|
|
30
|
+
function readSearchQuery(params, definition) {
|
|
31
|
+
const errors = {};
|
|
32
|
+
const q = (params.get("q") ?? "").trim();
|
|
33
|
+
if (q.length < 2) errors.q = [`The search must have at least 2 characters.`];
|
|
34
|
+
else if (q.length > 255) errors.q = [`The search must have at most 255 characters.`];
|
|
35
|
+
const rawLimit = params.get("limit");
|
|
36
|
+
const limit = rawLimit === null ? 5 : Number(rawLimit);
|
|
37
|
+
if (rawLimit !== null && (!/^\d+$/.test(rawLimit) || limit < 1 || limit > 20)) errors.limit = [`The limit must be an integer from 1 to 20.`];
|
|
38
|
+
const searchable = definition.resources.filter(isSearchableResource).map((resource) => resource.id);
|
|
39
|
+
const rawResources = params.get("resources");
|
|
40
|
+
const asked = rawResources === null ? searchable : rawResources.split(",").map((id) => id.trim()).filter((id) => id !== "");
|
|
41
|
+
const unknown = asked.filter((id) => !searchable.includes(id));
|
|
42
|
+
if (rawResources !== null && (asked.length === 0 || unknown.length > 0)) errors.resources = [unknown.length > 0 ? `These resources are not searchable: ${unknown.join(", ")}.` : "List at least one resource."];
|
|
43
|
+
if (Object.keys(errors).length > 0) return { errors };
|
|
44
|
+
return { query: {
|
|
45
|
+
q,
|
|
46
|
+
limit,
|
|
47
|
+
resources: searchable.filter((id) => asked.includes(id))
|
|
48
|
+
} };
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, isSearchableResource, readSearchQuery, toSearchQueryParams };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","names":[],"sources":["../src/search.ts"],"sourcesContent":["/** Shortest search, in characters once trimmed: shorter is a `422`. */\nexport const SEARCH_MIN_LENGTH = 2;\n/** Longest search, in characters. */\nexport const SEARCH_MAX_LENGTH = 255;\n/** Items per resource without a `limit`. */\nexport const SEARCH_DEFAULT_LIMIT = 5;\n/** Highest `limit`, and most items of a response, every resource together. */\nexport const SEARCH_MAX_LIMIT = 20;\n\n/** What the global search reads of a resource. */\nexport interface SearchableResource {\n id: string;\n features?: { search?: boolean | undefined } | undefined;\n list?: { search?: boolean | undefined } | undefined;\n}\n\n/** Query of the global search (`GET /search`). */\nexport interface SearchQuery {\n q: string;\n /** Items per resource, from 1 to 20. Defaults to 5. */\n limit?: number;\n /** Ids of the searchable resources to search. Defaults to every one. */\n resources?: readonly string[];\n}\n\n/**\n * Whether a resource is in the global search: its `features.search`, or, without it, whether its\n * list has a search (`list.search`), so one setting serves both (decision 0029).\n */\nexport function isSearchableResource(resource: Omit<SearchableResource, 'id'>): boolean {\n return resource.features?.search ?? resource.list?.search ?? false;\n}\n\n/** Serializes a search query: `q=été&limit=20&resources=pages,articles`. */\nexport function toSearchQueryParams(query: SearchQuery): URLSearchParams {\n const params = new URLSearchParams({ q: query.q });\n if (query.limit !== undefined) {\n params.set('limit', String(query.limit));\n }\n if (query.resources !== undefined && query.resources.length > 0) {\n params.set('resources', query.resources.join(','));\n }\n return params;\n}\n\n/** A search query as a backend reads it: valid, or the messages of its invalid parameters. */\nexport type ReadSearchQueryResult =\n | { query: Required<SearchQuery>; errors?: undefined }\n | { query?: undefined; errors: Record<string, string[]> };\n\n/**\n * Reads the query string of `GET /search`: the reference of how a backend validates it. `q` is\n * trimmed and needs 2 characters; `limit` is an integer from 1 to 20; `resources` lists searchable\n * resources of the definition. Invalid parameters are a `422`, with `errors` keyed by parameter.\n * Without `resources`, every searchable resource is searched, in the order of the definition.\n */\nexport function readSearchQuery(\n params: URLSearchParams,\n definition: { resources: readonly SearchableResource[] },\n): ReadSearchQueryResult {\n const errors: Record<string, string[]> = {};\n const q = (params.get('q') ?? '').trim();\n if (q.length < SEARCH_MIN_LENGTH) {\n errors.q = [`The search must have at least ${SEARCH_MIN_LENGTH} characters.`];\n } else if (q.length > SEARCH_MAX_LENGTH) {\n errors.q = [`The search must have at most ${SEARCH_MAX_LENGTH} characters.`];\n }\n\n const rawLimit = params.get('limit');\n const limit = rawLimit === null ? SEARCH_DEFAULT_LIMIT : Number(rawLimit);\n if (rawLimit !== null && (!/^\\d+$/.test(rawLimit) || limit < 1 || limit > SEARCH_MAX_LIMIT)) {\n errors.limit = [`The limit must be an integer from 1 to ${SEARCH_MAX_LIMIT}.`];\n }\n\n const searchable = definition.resources\n .filter(isSearchableResource)\n .map((resource) => resource.id);\n const rawResources = params.get('resources');\n const asked =\n rawResources === null\n ? searchable\n : rawResources\n .split(',')\n .map((id) => id.trim())\n .filter((id) => id !== '');\n const unknown = asked.filter((id) => !searchable.includes(id));\n if (rawResources !== null && (asked.length === 0 || unknown.length > 0)) {\n errors.resources = [\n unknown.length > 0\n ? `These resources are not searchable: ${unknown.join(', ')}.`\n : 'List at least one resource.',\n ];\n }\n\n if (Object.keys(errors).length > 0) {\n return { errors };\n }\n // The order of the definition, without duplicates\n const resources = searchable.filter((id) => asked.includes(id));\n return { query: { q, limit, resources } };\n}\n"],"mappings":";;AACA,IAAa,oBAAoB;;AAEjC,IAAa,oBAAoB;;AAEjC,IAAa,uBAAuB;;AAEpC,IAAa,mBAAmB;;;;;AAsBhC,SAAgB,qBAAqB,UAAmD;CACpF,OAAO,SAAS,UAAU,UAAU,SAAS,MAAM,UAAU;AACjE;;AAGA,SAAgB,oBAAoB,OAAqC;CACrE,MAAM,SAAS,IAAI,gBAAgB,EAAE,GAAG,MAAM,EAAE,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V,WAAW,QAAQ,OAAO,MAAM,SAAS,EAAE,CACjC;CAAU,EAAE;AAC5C"}
|
package/dist/themes.d.ts
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MediaTransform } from './schemas/api.js';
|
|
2
|
+
/** The ratio of `width:height` (`16:9` gives 1.777…), or null when it isn't one. */
|
|
3
|
+
export declare function parseRatio(ratio: string): number | null;
|
|
4
|
+
/**
|
|
5
|
+
* Whether a size has a ratio (decision 0031): its height is within one pixel of its width divided
|
|
6
|
+
* by the ratio, since crops are in whole pixels.
|
|
7
|
+
*/
|
|
8
|
+
export declare function matchesRatio(width: number, height: number, ratio: number | string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The size of the crop of a transform as it is rendered: a quarter turn swaps its width and its
|
|
11
|
+
* height. Null without a crop.
|
|
12
|
+
*/
|
|
13
|
+
export declare function renderedCropSize(transform: Pick<MediaTransform, 'crop' | 'rotate'>): {
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
} | null;
|
|
17
|
+
//# sourceMappingURL=transforms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transforms.d.ts","sourceRoot":"","sources":["../src/transforms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,oFAAoF;AACpF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGvD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAG3F;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC5B,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,QAAQ,CAAC,GACnD;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAQ1C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isRecord } from "./values.js";
|
|
2
|
+
//#region src/transforms.ts
|
|
3
|
+
/** The ratio of `width:height` (`16:9` gives 1.777…), or null when it isn't one. */
|
|
4
|
+
function parseRatio(ratio) {
|
|
5
|
+
const match = /^([1-9][0-9]*):([1-9][0-9]*)$/.exec(ratio);
|
|
6
|
+
return match === null ? null : Number(match[1]) / Number(match[2]);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Whether a size has a ratio (decision 0031): its height is within one pixel of its width divided
|
|
10
|
+
* by the ratio, since crops are in whole pixels.
|
|
11
|
+
*/
|
|
12
|
+
function matchesRatio(width, height, ratio) {
|
|
13
|
+
const value = typeof ratio === "number" ? ratio : parseRatio(ratio);
|
|
14
|
+
return value !== null && value > 0 && Math.abs(width / value - height) <= 1;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The size of the crop of a transform as it is rendered: a quarter turn swaps its width and its
|
|
18
|
+
* height. Null without a crop.
|
|
19
|
+
*/
|
|
20
|
+
function renderedCropSize(transform) {
|
|
21
|
+
const crop = transform.crop;
|
|
22
|
+
if (!isRecord(crop) || typeof crop.width !== "number" || typeof crop.height !== "number") return null;
|
|
23
|
+
return transform.rotate === 90 || transform.rotate === 270 ? {
|
|
24
|
+
width: crop.height,
|
|
25
|
+
height: crop.width
|
|
26
|
+
} : {
|
|
27
|
+
width: crop.width,
|
|
28
|
+
height: crop.height
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { matchesRatio, parseRatio, renderedCropSize };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=transforms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transforms.js","names":[],"sources":["../src/transforms.ts"],"sourcesContent":["import type { MediaTransform } from './schemas/api';\nimport { isRecord } from './values';\n\n/** The ratio of `width:height` (`16:9` gives 1.777…), or null when it isn't one. */\nexport function parseRatio(ratio: string): number | null {\n const match = /^([1-9][0-9]*):([1-9][0-9]*)$/.exec(ratio);\n return match === null ? null : Number(match[1]) / Number(match[2]);\n}\n\n/**\n * Whether a size has a ratio (decision 0031): its height is within one pixel of its width divided\n * by the ratio, since crops are in whole pixels.\n */\nexport function matchesRatio(width: number, height: number, ratio: number | string): boolean {\n const value = typeof ratio === 'number' ? ratio : parseRatio(ratio);\n return value !== null && value > 0 && Math.abs(width / value - height) <= 1;\n}\n\n/**\n * The size of the crop of a transform as it is rendered: a quarter turn swaps its width and its\n * height. Null without a crop.\n */\nexport function renderedCropSize(\n transform: Pick<MediaTransform, 'crop' | 'rotate'>,\n): { width: number; height: number } | null {\n const crop = transform.crop;\n if (!isRecord(crop) || typeof crop.width !== 'number' || typeof crop.height !== 'number') {\n return null;\n }\n return transform.rotate === 90 || transform.rotate === 270\n ? { width: crop.height, height: crop.width }\n : { width: crop.width, height: crop.height };\n}\n"],"mappings":";;;AAIA,SAAgB,WAAW,OAA8B;CACrD,MAAM,QAAQ,gCAAgC,KAAK,KAAK;CACxD,OAAO,UAAU,OAAO,OAAO,OAAO,MAAM,EAAE,IAAI,OAAO,MAAM,EAAE;AACrE;;;;;AAMA,SAAgB,aAAa,OAAe,QAAgB,OAAiC;CACzF,MAAM,QAAQ,OAAO,UAAU,WAAW,QAAQ,WAAW,KAAK;CAClE,OAAO,UAAU,QAAQ,QAAQ,KAAK,KAAK,IAAI,QAAQ,QAAQ,MAAM,KAAK;AAC9E;;;;;AAMA,SAAgB,iBACZ,WACwC;CACxC,MAAM,OAAO,UAAU;CACvB,IAAI,CAAC,SAAS,IAAI,KAAK,OAAO,KAAK,UAAU,YAAY,OAAO,KAAK,WAAW,UAC5E,OAAO;CAEX,OAAO,UAAU,WAAW,MAAM,UAAU,WAAW,MACjD;EAAE,OAAO,KAAK;EAAQ,QAAQ,KAAK;CAAM,IACzC;EAAE,OAAO,KAAK;EAAO,QAAQ,KAAK;CAAO;AACnD"}
|
package/dist/validate.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
|
-
import { BootConfig } from './schemas/boot';
|
|
3
|
-
import { Definition } from './schemas/definition';
|
|
2
|
+
import { BootConfig } from './schemas/boot.js';
|
|
3
|
+
import { Definition } from './schemas/definition.js';
|
|
4
4
|
export interface ValidationIssue {
|
|
5
5
|
/** Dot path of the invalid value (`resources.0.fields.2.type`), empty for the root. */
|
|
6
6
|
path: string;
|
|
@@ -17,7 +17,9 @@ export type ValidationResult<T> = {
|
|
|
17
17
|
export declare function validate<T extends z.ZodType>(schema: T, input: unknown): ValidationResult<z.infer<T>>;
|
|
18
18
|
/**
|
|
19
19
|
* Validates a definition, as returned by `GET /definition`: against the schema, then the
|
|
20
|
-
* references between its parts (see `lintDefinition()`)
|
|
20
|
+
* references between its parts (see `lintDefinition()`), and the settings of field types that
|
|
21
|
+
* the protocol describes (`RichTextSettings`, `DurationSettings`, `DateRangeSettings`,
|
|
22
|
+
* `MoneySettings`, `LinkSettings`, `AddressSettings`).
|
|
21
23
|
*/
|
|
22
24
|
export declare function validateDefinition(input: unknown): ValidationResult<Definition>;
|
|
23
25
|
/**
|
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;EACn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BACzC,mBACI,OAAO,UAAU,CAAC,GAClB,aAAa,OAAO,KAAK,EAAE,WAAW,OAAO,WAAW,EAAE,QAC9D,CACJ;CACJ,CAAC,CACL;CACA,OAAO,OAAO,SAAS,IAAI;EAAE,SAAS;EAAO;CAAO,IAAI;AAC5D;;;;;AAMA,SAAgB,mBAAmB,OAA8C;CAC7E,MAAM,SAAS,SAAS,YAAY,KAAK;CACzC,IAAI,CAAC,OAAO,WAAW,OAAO,KAAK,eAAe,KAAA,GAC9C,OAAO;CAEX,MAAM,SAAS,eAAe,OAAO,KAAK,UAAU,CAAC,CAAC,KAAK,WAAW;EAClE,GAAG;EACH,MAAM,MAAM,SAAS,KAAK,eAAe,cAAc,MAAM;CACjE,EAAE;CACF,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
|
}
|