@panneau/protocol 5.0.0-alpha.0 → 5.0.0-alpha.10
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/README.md +13 -8
- package/dist/conditions.d.ts +1 -1
- package/dist/conformance/index.d.ts.map +1 -1
- package/dist/conformance/index.js +310 -4
- package/dist/conformance/index.js.map +1 -1
- package/dist/constants.d.ts +44 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +128 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +4 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -15
- package/dist/libraries.d.ts +16 -0
- package/dist/libraries.d.ts.map +1 -0
- package/dist/libraries.js +15 -0
- package/dist/libraries.js.map +1 -0
- package/dist/lint.d.ts +4 -3
- package/dist/lint.d.ts.map +1 -1
- package/dist/lint.js +34 -2
- package/dist/lint.js.map +1 -1
- package/dist/mock/example.d.ts +3 -2
- package/dist/mock/example.d.ts.map +1 -1
- package/dist/mock/example.js +223 -138
- package/dist/mock/example.js.map +1 -1
- package/dist/mock/index.d.ts +19 -5
- package/dist/mock/index.d.ts.map +1 -1
- package/dist/mock/index.js +383 -19
- package/dist/mock/index.js.map +1 -1
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +113 -109
- package/dist/openapi.js.map +1 -1
- package/dist/problem.d.ts +7 -0
- package/dist/problem.d.ts.map +1 -0
- package/dist/problem.js +22 -0
- package/dist/problem.js.map +1 -0
- package/dist/query.d.ts +40 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +47 -6
- package/dist/query.js.map +1 -1
- package/dist/rules.d.ts +6 -3
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +51 -9
- package/dist/rules.js.map +1 -1
- package/dist/runtime/index.d.ts +14 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +13 -0
- package/dist/schemas/action.d.ts +69 -13
- package/dist/schemas/action.d.ts.map +1 -1
- package/dist/schemas/action.js +21 -14
- package/dist/schemas/action.js.map +1 -1
- package/dist/schemas/api.d.ts +224 -39
- package/dist/schemas/api.d.ts.map +1 -1
- package/dist/schemas/api.js +125 -31
- package/dist/schemas/api.js.map +1 -1
- package/dist/schemas/boot.d.ts +24 -6
- package/dist/schemas/boot.d.ts.map +1 -1
- package/dist/schemas/boot.js +3 -7
- 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 +222 -20
- package/dist/schemas/definition.d.ts.map +1 -1
- package/dist/schemas/definition.js +16 -11
- package/dist/schemas/definition.js.map +1 -1
- package/dist/schemas/field.d.ts +162 -8
- package/dist/schemas/field.d.ts.map +1 -1
- package/dist/schemas/field.js +69 -49
- package/dist/schemas/field.js.map +1 -1
- package/dist/schemas/index.d.ts +955 -63
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +41 -12
- 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 +1 -4
- package/dist/schemas/layout.d.ts.map +1 -1
- package/dist/schemas/layout.js +1 -13
- package/dist/schemas/layout.js.map +1 -1
- package/dist/schemas/list.d.ts +6 -3
- package/dist/schemas/list.d.ts.map +1 -1
- package/dist/schemas/list.js +3 -9
- package/dist/schemas/list.js.map +1 -1
- package/dist/schemas/resource.d.ts +144 -14
- package/dist/schemas/resource.d.ts.map +1 -1
- package/dist/schemas/resource.js +6 -1
- package/dist/schemas/resource.js.map +1 -1
- package/dist/schemas/theme.d.ts +179 -0
- package/dist/schemas/theme.d.ts.map +1 -0
- package/dist/schemas/theme.js +66 -0
- package/dist/schemas/theme.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 +11 -0
- package/dist/themes.d.ts.map +1 -0
- package/dist/themes.js +80 -0
- package/dist/themes.js.map +1 -0
- 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 +4 -6
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +24 -9
- 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/package.json +12 -3
- package/schema/boot.schema.json +580 -16
- package/schema/definition.schema.json +577 -16
- package/schema/openapi.json +1818 -543
- package/schema/theme.schema.json +234 -0
package/dist/openapi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.js","names":[],"sources":["../src/openapi.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { createSchemaRegistry } from './schemas';\nimport { BootConfig } from './schemas/boot';\nimport { Definition } from './schemas/definition';\nimport { PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION } from './version';\n\ntype JsonObject = Record<string, unknown>;\n\nconst ref = (id: string): JsonObject => ({ $ref: `#/components/schemas/${id}` });\n\nconst json = (schema: JsonObject): JsonObject => ({ 'application/json': { schema } });\n\nconst ok = (description: string, schema?: JsonObject, headers?: JsonObject): JsonObject => ({\n description,\n ...(schema !== undefined ? { content: json(schema) } : {}),\n ...(headers !== undefined ? { headers } : {}),\n});\n\nconst PROBLEMS: Record<number, string> = {\n 401: 'Not authenticated.',\n 403: 'Not allowed.',\n 404: 'Not found.',\n 409: 'Conflict with a business rule.',\n 412: 'Version conflict: `If-Match` does not match the current version, which is in `current`.',\n 422: 'Invalid values: messages are in `errors`, keyed by dot path.',\n};\n\nfunction problems(...statuses: number[]): JsonObject {\n return Object.fromEntries(\n statuses.map((status) => [\n String(status),\n {\n description: PROBLEMS[status],\n content: { [PROBLEM_CONTENT_TYPE]: { schema: ref('Problem') } },\n },\n ]),\n );\n}\n\nconst etag = { ETag: { description: 'The version of the item.', schema: { type: 'string' } } };\n\nconst pathParameter = (name: string, description: string): JsonObject => ({\n name,\n in: 'path',\n required: true,\n description,\n schema: { type: 'string' },\n});\n\nconst queryParameter = (name: string, description: string, schema: JsonObject): JsonObject => ({\n name,\n in: 'query',\n required: false,\n description,\n schema,\n});\n\nconst listParameters = [\n queryParameter('page', 'Page number, from 1.', { type: 'integer', minimum: 1 }),\n queryParameter('perPage', 'Items per page.', { type: 'integer', minimum: 1 }),\n queryParameter('sort', 'Comma-separated fields; a `-` prefix sorts descending.', {\n type: 'string',\n }),\n {\n name: 'filter',\n in: 'query',\n required: false,\n style: 'deepObject',\n explode: true,\n description: '`filter[status]=published`, `filter[tags][]=a`.',\n schema: { type: 'object', additionalProperties: true },\n },\n queryParameter('q', 'Search.', { type: 'string' }),\n queryParameter('fields', 'Comma-separated fields to include in each item.', { type: 'string' }),\n];\n\nconst resource = pathParameter('resource', 'Resource id.');\nconst id = pathParameter('id', 'Item id.');\nconst values = { type: 'object', additionalProperties: true };\n\n/** Component schemas, generated from the protocol's Zod schemas. */\nexport function createComponentSchemas(): Record<string, JsonObject> {\n const { schemas } = z.toJSONSchema(createSchemaRegistry(), {\n io: 'input',\n uri: (schemaId) => `#/components/schemas/${schemaId}`,\n });\n return Object.fromEntries(\n Object.entries(schemas).map(([schemaId, schema]) => {\n const { $schema: _schema, $id: _id, ...rest } = schema as JsonObject;\n return [schemaId, rest];\n }),\n );\n}\n\n/** The JSON Schema of the definition (`GET /definition`). */\nexport function createDefinitionJsonSchema(): JsonObject {\n return {\n $id: 'https://github.com/folkloreinc/panneau-js/blob/v5.x/packages/protocol/schema/definition.schema.json',\n ...(z.toJSONSchema(Definition, {\n io: 'input',\n metadata: createSchemaRegistry(),\n }) as JsonObject),\n };\n}\n\n/** The JSON Schema of the boot config, which a server writes in the page of the app. */\nexport function createBootConfigJsonSchema(): JsonObject {\n return {\n $id: 'https://github.com/folkloreinc/panneau-js/blob/v5.x/packages/protocol/schema/boot.schema.json',\n ...(z.toJSONSchema(BootConfig, {\n io: 'input',\n metadata: createSchemaRegistry(),\n }) as JsonObject),\n };\n}\n\n/** The OpenAPI 3.1 document of the Panneau HTTP API. */\nexport function createOpenApiDocument(): JsonObject {\n return {\n openapi: '3.1.0',\n info: {\n title: 'Panneau protocol',\n version: String(PROTOCOL_VERSION),\n description:\n 'The HTTP API between a Panneau frontend and its backend. Paths are relative to `api.baseUrl` of the definition. Authentication is up to the backend (session cookie or bearer token). Errors use `application/problem+json`.',\n },\n paths: {\n '/definition': {\n get: {\n operationId: 'getDefinition',\n summary: 'The definition for the current user, in the current locale.',\n responses: {\n 200: ok('The definition.', ref('Definition')),\n ...problems(401, 403),\n },\n },\n },\n '/resources/{resource}': {\n parameters: [resource],\n get: {\n operationId: 'listItems',\n parameters: listParameters,\n responses: {\n 200: ok('A page of items.', ref('ListResponse')),\n ...problems(401, 403, 404),\n },\n },\n post: {\n operationId: 'createItem',\n requestBody: { required: true, content: json(values) },\n responses: {\n 201: ok('The created item.', ref('ItemResponse'), etag),\n ...problems(401, 403, 404, 409, 422),\n },\n },\n },\n '/resources/{resource}/{id}': {\n parameters: [resource, id],\n get: {\n operationId: 'getItem',\n responses: {\n 200: ok('The item.', ref('ItemResponse'), etag),\n ...problems(401, 403, 404),\n },\n },\n patch: {\n operationId: 'updateItem',\n description: 'Partial update: only the values sent are changed.',\n parameters: [\n {\n name: 'If-Match',\n in: 'header',\n required: false,\n description: 'The version the client edited.',\n schema: { type: 'string' },\n },\n ],\n requestBody: { required: true, content: json(values) },\n responses: {\n 200: ok('The updated item.', ref('ItemResponse'), etag),\n ...problems(401, 403, 404, 409, 412, 422),\n },\n },\n delete: {\n operationId: 'deleteItem',\n responses: { 204: ok('Deleted.'), ...problems(401, 403, 404, 409) },\n },\n },\n '/resources/{resource}/{id}/preview': {\n parameters: [resource, id],\n post: {\n operationId: 'previewItem',\n requestBody: { required: true, content: json(values) },\n responses: {\n 200: ok('A short-lived preview URL.', ref('PreviewResponse')),\n ...problems(401, 403, 404, 422),\n },\n },\n },\n '/resources/{resource}/actions/{action}': {\n parameters: [resource, pathParameter('action', 'Action id.')],\n post: {\n operationId: 'runAction',\n requestBody: {\n required: true,\n content: {\n ...json(ref('ActionRequest')),\n 'multipart/form-data': { schema: ref('ActionRequest') },\n },\n },\n responses: {\n 200: ok('The result.', ref('ActionResult')),\n 202: ok('The action runs in the background.', ref('ActionRunResponse')),\n ...problems(401, 403, 404, 409, 422),\n },\n },\n },\n '/actions/runs': {\n get: {\n operationId: 'listActionRuns',\n summary: \"The current user's recent runs.\",\n responses: {\n 200: ok('Runs, newest first.', {\n type: 'object',\n required: ['data'],\n properties: { data: { type: 'array', items: ref('ActionRun') } },\n }),\n ...problems(401),\n },\n },\n },\n '/actions/runs/{run}': {\n parameters: [pathParameter('run', 'Run id.')],\n get: {\n operationId: 'getActionRun',\n responses: {\n 200: ok('The run.', ref('ActionRunResponse')),\n ...problems(401, 403, 404),\n },\n },\n delete: {\n operationId: 'cancelActionRun',\n responses: { 204: ok('Cancelled.'), ...problems(401, 403, 404, 409) },\n },\n },\n '/media': {\n get: {\n operationId: 'listMedia',\n parameters: listParameters,\n responses: {\n 200: ok('A page of media.', ref('MediaListResponse')),\n ...problems(401, 403),\n },\n },\n post: {\n operationId: 'uploadMedia',\n requestBody: {\n required: true,\n content: {\n 'multipart/form-data': {\n schema: {\n type: 'object',\n required: ['file'],\n properties: {\n file: {\n type: 'string',\n contentMediaType: 'application/octet-stream',\n },\n name: { type: 'string' },\n tags: { type: 'array', items: { type: 'string' } },\n },\n },\n },\n },\n },\n responses: {\n 201: ok('The created media.', ref('MediaResponse')),\n ...problems(401, 403, 422),\n },\n },\n },\n '/media/tags': {\n get: {\n operationId: 'listMediaTags',\n responses: {\n 200: ok('Tags in use.', {\n type: 'object',\n required: ['data'],\n properties: { data: { type: 'array', items: { type: 'string' } } },\n }),\n ...problems(401, 403),\n },\n },\n },\n '/media/{id}': {\n parameters: [pathParameter('id', 'Media id.')],\n get: {\n operationId: 'getMedia',\n responses: {\n 200: ok('The media.', ref('MediaResponse')),\n ...problems(401, 403, 404),\n },\n },\n patch: {\n operationId: 'updateMedia',\n description: 'Updates metadata, tags or the image `transform`.',\n requestBody: { required: true, content: json(values) },\n responses: {\n 200: ok('The updated media.', ref('MediaResponse')),\n ...problems(401, 403, 404, 422),\n },\n },\n delete: {\n operationId: 'deleteMedia',\n responses: { 204: ok('Moved to the trash.'), ...problems(401, 403, 404, 409) },\n },\n },\n '/media/{id}/file': {\n parameters: [pathParameter('id', 'Media id.')],\n post: {\n operationId: 'replaceMediaFile',\n requestBody: {\n required: true,\n content: {\n 'multipart/form-data': {\n schema: {\n type: 'object',\n required: ['file'],\n properties: {\n file: {\n type: 'string',\n contentMediaType: 'application/octet-stream',\n },\n },\n },\n },\n },\n },\n responses: {\n 200: ok('The media.', ref('MediaResponse')),\n ...problems(401, 403, 404, 422),\n },\n },\n },\n '/media/{id}/restore': {\n parameters: [pathParameter('id', 'Media id.')],\n post: {\n operationId: 'restoreMedia',\n responses: {\n 200: ok('The restored media.', ref('MediaResponse')),\n ...problems(401, 403, 404),\n },\n },\n },\n '/auth/session': {\n get: {\n operationId: 'getSession',\n responses: { 200: ok('The current user.', ref('Session')), ...problems(401) },\n },\n },\n '/auth/login': {\n post: {\n operationId: 'login',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['email', 'password'],\n properties: {\n email: { type: 'string' },\n password: { type: 'string' },\n remember: { type: 'boolean' },\n },\n }),\n },\n responses: {\n 200: ok('Logged in.', ref('Session')),\n 202: ok(\n 'A second factor is required: answer `/auth/two-factor/challenge`.',\n {\n type: 'object',\n properties: { twoFactor: { type: 'boolean', const: true } },\n },\n ),\n ...problems(422),\n },\n },\n },\n '/auth/logout': {\n post: { operationId: 'logout', responses: { 204: ok('Logged out.') } },\n },\n '/auth/providers/{provider}/redirect': {\n parameters: [pathParameter('provider', 'Provider id.')],\n get: {\n operationId: 'redirectToProvider',\n parameters: [\n queryParameter('next', 'Local path to go to after login.', {\n type: 'string',\n }),\n ],\n responses: {\n 302: { description: 'Redirect to the provider.' },\n ...problems(404),\n },\n },\n },\n '/auth/password/forgot': {\n post: {\n operationId: 'forgotPassword',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['email'],\n properties: { email: { type: 'string' } },\n }),\n },\n responses: {\n 204: ok('A reset link was sent, if the account exists.'),\n ...problems(422),\n },\n },\n },\n '/auth/password/reset': {\n post: {\n operationId: 'resetPassword',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['token', 'email', 'password'],\n properties: {\n token: { type: 'string' },\n email: { type: 'string' },\n password: { type: 'string' },\n },\n }),\n },\n responses: { 204: ok('The password was reset.'), ...problems(422) },\n },\n },\n '/auth/two-factor/challenge': {\n post: {\n operationId: 'twoFactorChallenge',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n properties: {\n code: { type: 'string' },\n recoveryCode: { type: 'string' },\n },\n }),\n },\n responses: { 200: ok('Logged in.', ref('Session')), ...problems(422) },\n },\n },\n '/auth/passkeys/options': {\n post: {\n operationId: 'passkeyOptions',\n responses: {\n 200: ok('WebAuthn request options.', {\n type: 'object',\n additionalProperties: true,\n }),\n },\n },\n },\n '/auth/passkeys/login': {\n post: {\n operationId: 'passkeyLogin',\n requestBody: {\n required: true,\n content: json({ type: 'object', additionalProperties: true }),\n },\n responses: { 200: ok('Logged in.', ref('Session')), ...problems(422) },\n },\n },\n '/account': {\n get: {\n operationId: 'getAccount',\n responses: {\n 200: ok('The current user.', {\n type: 'object',\n required: ['data'],\n properties: { data: ref('User') },\n }),\n ...problems(401),\n },\n },\n patch: {\n operationId: 'updateAccount',\n requestBody: { required: true, content: json(values) },\n responses: {\n 200: ok('The updated user.', {\n type: 'object',\n required: ['data'],\n properties: { data: ref('User') },\n }),\n ...problems(401, 422),\n },\n },\n },\n '/search': {\n get: {\n operationId: 'search',\n parameters: [\n {\n ...queryParameter('q', 'Search terms.', { type: 'string' }),\n required: true,\n },\n ],\n responses: {\n 200: ok('Results grouped by resource.', ref('SearchResponse')),\n ...problems(401),\n },\n },\n },\n '/dashboard/widgets/{widget}': {\n parameters: [pathParameter('widget', 'Widget id.')],\n get: {\n operationId: 'getWidgetData',\n responses: {\n 200: ok(\"The widget's data. Its shape depends on the widget type.\", {\n type: 'object',\n additionalProperties: true,\n }),\n ...problems(401, 403, 404),\n },\n },\n },\n },\n components: { schemas: createComponentSchemas() },\n };\n}\n"],"mappings":";;;;;;AASA,IAAM,OAAO,QAA4B,EAAE,MAAM,wBAAwB,KAAK;AAE9E,IAAM,QAAQ,YAAoC,EAAE,oBAAoB,EAAE,OAAO,EAAE;AAEnF,IAAM,MAAM,aAAqB,QAAqB,aAAsC;CACxF;CACA,GAAI,WAAW,KAAA,IAAY,EAAE,SAAS,KAAK,MAAM,EAAE,IAAI,CAAC;CACxD,GAAI,YAAY,KAAA,IAAY,EAAE,QAAQ,IAAI,CAAC;AAC/C;AAEA,IAAM,WAAmC;CACrC,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;AACT;AAEA,SAAS,SAAS,GAAG,UAAgC;CACjD,OAAO,OAAO,YACV,SAAS,KAAK,WAAW,CACrB,OAAO,MAAM,GACb;EACI,aAAa,SAAS;EACtB,SAAS,GAAG,uBAAuB,EAAE,QAAQ,IAAI,SAAS,EAAE,EAAE;CAClE,CACJ,CAAC,CACL;AACJ;AAEA,IAAM,OAAO,EAAE,MAAM;CAAE,aAAa;CAA4B,QAAQ,EAAE,MAAM,SAAS;AAAE,EAAE;AAE7F,IAAM,iBAAiB,MAAc,iBAAqC;CACtE;CACA,IAAI;CACJ,UAAU;CACV;CACA,QAAQ,EAAE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AAa;KACT,UAAU;KACV,SAAS,KAAK;MAAE,MAAM;MAAU,sBAAsB;KAAK,CAAC;IAChE;IACA,WAAW;KAAE,KAAK,GAAG,cAAc,IAAI,SAAS,CAAC;KAAG,GAAG,SAAS,GAAG;IAAE;GACzE,EACJ;GACA,YAAY;IACR,KAAK;KACD,aAAa;KACb,WAAW;MACP,KAAK,GAAG,qBAAqB;OACzB,MAAM;OACN,UAAU,CAAC,MAAM;OACjB,YAAY,EAAE,MAAM,IAAI,MAAM,EAAE;MACpC,CAAC;MACD,GAAG,SAAS,GAAG;KACnB;IACJ;IACA,OAAO;KACH,aAAa;KACb,aAAa;MAAE,UAAU;MAAM,SAAS,KAAK,MAAM;KAAE;KACrD,WAAW;MACP,KAAK,GAAG,qBAAqB;OACzB,MAAM;OACN,UAAU,CAAC,MAAM;OACjB,YAAY,EAAE,MAAM,IAAI,MAAM,EAAE;MACpC,CAAC;MACD,GAAG,SAAS,KAAK,GAAG;KACxB;IACJ;GACJ;GACA,WAAW,EACP,KAAK;IACD,aAAa;IACb,YAAY,CACR;KACI,GAAG,eAAe,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAC;KAC1D,UAAU;IACd,CACJ;IACA,WAAW;KACP,KAAK,GAAG,gCAAgC,IAAI,gBAAgB,CAAC;KAC7D,GAAG,SAAS,GAAG;IACnB;GACJ,EACJ;GACA,+BAA+B;IAC3B,YAAY,CAAC,cAAc,UAAU,YAAY,CAAC;IAClD,KAAK;KACD,aAAa;KACb,WAAW;MACP,KAAK,GAAG,4DAA4D;OAChE,MAAM;OACN,sBAAsB;MAC1B,CAAC;MACD,GAAG,SAAS,KAAK,KAAK,GAAG;KAC7B;IACJ;GACJ;EACJ;EACA,YAAY,EAAE,SAAS,uBAAuB,EAAE;CACpD;AACJ"}
|
|
1
|
+
{"version":3,"file":"openapi.js","names":[],"sources":["../src/openapi.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { createSchemaRegistry } from './schemas';\nimport { BootConfig } from './schemas/boot';\nimport { Definition } from './schemas/definition';\nimport { Theme } from './schemas/theme';\nimport {\n SEARCH_DEFAULT_LIMIT,\n SEARCH_MAX_LENGTH,\n SEARCH_MAX_LIMIT,\n SEARCH_MIN_LENGTH,\n} from './search';\nimport { PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION } from './version';\n\ntype JsonObject = Record<string, unknown>;\n\nconst ref = (id: string): JsonObject => ({ $ref: `#/components/schemas/${id}` });\n\nconst json = (schema: JsonObject): JsonObject => ({ 'application/json': { schema } });\n\nconst ok = (description: string, schema?: JsonObject, headers?: JsonObject): JsonObject => ({\n description,\n ...(schema !== undefined ? { content: json(schema) } : {}),\n ...(headers !== undefined ? { headers } : {}),\n});\n\nconst PROBLEMS: Record<number, string> = {\n 400: 'Bad request, such as a dry run of an action that does not declare `dryRun`.',\n 401: 'Not authenticated.',\n 403: 'Not allowed.',\n 404: 'Not found.',\n 409: 'Conflict with a business rule.',\n 412: 'Version conflict: `If-Match` does not match the current version, which is in `current`.',\n 422: 'Invalid values: messages are in `errors`, keyed by dot path.',\n 429: 'Too many requests: `Retry-After` gives the seconds to wait.',\n};\n\nfunction problems(...statuses: number[]): JsonObject {\n return Object.fromEntries(\n statuses.map((status) => [\n String(status),\n {\n description: PROBLEMS[status],\n content: { [PROBLEM_CONTENT_TYPE]: { schema: ref('Problem') } },\n },\n ]),\n );\n}\n\nconst etag = { ETag: { description: 'The version of the item.', schema: { type: 'string' } } };\n\nconst pathParameter = (name: string, description: string): JsonObject => ({\n name,\n in: 'path',\n required: true,\n description,\n schema: { type: 'string' },\n});\n\nconst queryParameter = (name: string, description: string, schema: JsonObject): JsonObject => ({\n name,\n in: 'query',\n required: false,\n description,\n schema,\n});\n\nconst listParameters = [\n queryParameter('page', 'Page number, from 1.', { type: 'integer', minimum: 1 }),\n queryParameter('perPage', 'Items per page.', { type: 'integer', minimum: 1 }),\n queryParameter(\n 'cursor',\n 'Lists whose `pagination` is `cursor`: the `nextCursor` (or `previousCursor`) of a page, instead of `page`.',\n { type: 'string' },\n ),\n queryParameter('sort', 'Comma-separated fields; a `-` prefix sorts descending.', {\n type: 'string',\n }),\n {\n name: 'filter',\n in: 'query',\n required: false,\n style: 'deepObject',\n explode: true,\n description:\n '`filter[status]=published`; `filter[tags][]=a&filter[tags][]=b` for any of several values; `filter[published_at][from]=2026-01-01&filter[published_at][to]=2026-01-31` for the inclusive bounds of a range filter (`date-range`), without the open end.',\n schema: { type: 'object', additionalProperties: true },\n },\n queryParameter('q', 'Search.', { type: 'string' }),\n queryParameter('fields', 'Comma-separated fields to include in each item.', { type: 'string' }),\n];\n\nconst resource = pathParameter('resource', 'Resource id.');\nconst id = pathParameter('id', 'Item id.');\nconst values = { type: 'object', additionalProperties: true };\n\n/** Component schemas, generated from the protocol's Zod schemas. */\nexport function createComponentSchemas(): Record<string, JsonObject> {\n const { schemas } = z.toJSONSchema(createSchemaRegistry(), {\n io: 'input',\n uri: (schemaId) => `#/components/schemas/${schemaId}`,\n });\n return Object.fromEntries(\n Object.entries(schemas).map(([schemaId, schema]) => {\n const { $schema: _schema, $id: _id, ...rest } = schema as JsonObject;\n return [schemaId, rest];\n }),\n );\n}\n\n/** The JSON Schema of the definition (`GET /definition`). */\nexport function createDefinitionJsonSchema(): JsonObject {\n return {\n $id: 'https://github.com/folkloreinc/panneau-js/blob/v5.x/packages/protocol/schema/definition.schema.json',\n ...(z.toJSONSchema(Definition, {\n io: 'input',\n metadata: createSchemaRegistry(),\n }) as JsonObject),\n };\n}\n\n/** The JSON Schema of a theme, for themes written as JSON files. */\nexport function createThemeJsonSchema(): JsonObject {\n return {\n $id: 'https://github.com/folkloreinc/panneau-js/blob/v5.x/packages/protocol/schema/theme.schema.json',\n ...(z.toJSONSchema(Theme, {\n io: 'input',\n metadata: createSchemaRegistry(),\n }) as JsonObject),\n };\n}\n\n/** The JSON Schema of the boot config, which a server writes in the page of the app. */\nexport function createBootConfigJsonSchema(): JsonObject {\n return {\n $id: 'https://github.com/folkloreinc/panneau-js/blob/v5.x/packages/protocol/schema/boot.schema.json',\n ...(z.toJSONSchema(BootConfig, {\n io: 'input',\n metadata: createSchemaRegistry(),\n }) as JsonObject),\n };\n}\n\n/** The OpenAPI 3.1 document of the Panneau HTTP API. */\nexport function createOpenApiDocument(): JsonObject {\n return {\n openapi: '3.1.0',\n info: {\n title: 'Panneau protocol',\n version: String(PROTOCOL_VERSION),\n description:\n 'The HTTP API between a Panneau frontend and its backend. Paths are relative to `api.baseUrl` of the definition. Authentication is up to the backend (session cookie or bearer token). Errors use `application/problem+json`.',\n },\n paths: {\n '/definition': {\n get: {\n operationId: 'getDefinition',\n summary: 'The definition for the current user, in the current locale.',\n responses: {\n 200: ok('The definition.', ref('Definition')),\n ...problems(401, 403),\n },\n },\n },\n '/resources/{resource}': {\n parameters: [resource],\n get: {\n operationId: 'listItems',\n parameters: listParameters,\n responses: {\n 200: ok('A page of items.', ref('ListResponse')),\n // A `cursor` the backend can't read (decision 0039)\n ...problems(401, 403, 404, 422),\n },\n },\n post: {\n operationId: 'createItem',\n requestBody: { required: true, content: json(values) },\n responses: {\n 201: ok('The created item.', ref('ItemResponse'), etag),\n ...problems(401, 403, 404, 409, 422),\n },\n },\n },\n '/resources/{resource}/{id}': {\n parameters: [resource, id],\n get: {\n operationId: 'getItem',\n responses: {\n 200: ok('The item.', ref('ItemResponse'), etag),\n ...problems(401, 403, 404),\n },\n },\n patch: {\n operationId: 'updateItem',\n description: 'Partial update: only the values sent are changed.',\n parameters: [\n {\n name: 'If-Match',\n in: 'header',\n required: false,\n description: 'The version the client edited.',\n schema: { type: 'string' },\n },\n ],\n requestBody: { required: true, content: json(values) },\n responses: {\n 200: ok('The updated item.', ref('ItemResponse'), etag),\n ...problems(401, 403, 404, 409, 412, 422),\n },\n },\n delete: {\n operationId: 'deleteItem',\n responses: { 204: ok('Deleted.'), ...problems(401, 403, 404, 409) },\n },\n },\n '/resources/{resource}/{id}/duplicate': {\n parameters: [resource, id],\n post: {\n operationId: 'duplicateItem',\n description:\n 'Copies an item, for the built-in `duplicate` (decision 0040). Allowed on the items whose `abilities.duplicate` is `true`.',\n responses: {\n 201: ok('The copy, a new item.', ref('ItemResponse'), etag),\n ...problems(401, 403, 404),\n 409: {\n description:\n 'The copy conflicts with another item, such as a unique value.',\n content: { [PROBLEM_CONTENT_TYPE]: { schema: ref('Problem') } },\n },\n },\n },\n },\n '/resources/{resource}/{id}/preview': {\n parameters: [resource, id],\n post: {\n operationId: 'previewItem',\n requestBody: { required: true, content: json(values) },\n responses: {\n 200: ok('A short-lived preview URL.', ref('PreviewResponse')),\n ...problems(401, 403, 404, 422),\n },\n },\n },\n '/resources/{resource}/actions/{action}': {\n parameters: [resource, pathParameter('action', 'Action id.')],\n post: {\n operationId: 'runAction',\n requestBody: {\n required: true,\n content: {\n ...json(ref('ActionRequest')),\n 'multipart/form-data': { schema: ref('ActionRequest') },\n },\n },\n responses: {\n 200: ok('The result.', ref('ActionResult')),\n 202: ok('The action runs in the background.', ref('ActionRunResponse')),\n ...problems(400, 401, 403, 404, 409, 422),\n },\n },\n },\n '/resources/{resource}/fields/{field}/check': {\n parameters: [resource, pathParameter('field', 'Name of a field with `check`.')],\n post: {\n operationId: 'checkField',\n summary:\n 'Checks a value as it is typed: whether a slug is available, and its URL. With the permission to create, or to update the item `id`.',\n requestBody: { required: true, content: json(ref('FieldCheckRequest')) },\n responses: {\n 200: ok(\n 'What the backend says about the value.',\n ref('FieldCheckResponse'),\n ),\n ...problems(401, 403, 404, 422),\n },\n },\n },\n '/actions/runs': {\n get: {\n operationId: 'listActionRuns',\n summary: \"The current user's recent runs.\",\n responses: {\n 200: ok('Runs, newest first.', {\n type: 'object',\n required: ['data'],\n properties: { data: { type: 'array', items: ref('ActionRun') } },\n }),\n ...problems(401),\n },\n },\n },\n '/actions/runs/{run}': {\n parameters: [pathParameter('run', 'Run id.')],\n get: {\n operationId: 'getActionRun',\n responses: {\n 200: ok('The run.', ref('ActionRunResponse')),\n ...problems(401, 403, 404),\n },\n },\n delete: {\n operationId: 'cancelActionRun',\n responses: { 204: ok('Cancelled.'), ...problems(401, 403, 404, 409) },\n },\n },\n '/uploads/sign': {\n post: {\n operationId: 'signUpload',\n summary:\n \"Signs a request of the browser's S3 client. The first request of a file creates its upload.\",\n requestBody: { required: true, content: json(ref('UploadSignRequest')) },\n responses: {\n 200: ok('The presigned request.', ref('UploadSignResponse')),\n ...problems(401, 403, 404, 422),\n },\n },\n },\n '/uploads/{upload}/complete': {\n parameters: [pathParameter('upload', 'Upload id: `upl_…`.')],\n post: {\n operationId: 'completeUpload',\n summary:\n 'Once the browser completed the upload in storage, checks the object and gives the upload, which values reference.',\n requestBody: {\n required: false,\n content: json({\n type: 'object',\n properties: {\n name: {\n type: 'string',\n description:\n \"The file's name, which the key doesn't keep, since the backend chose it.\",\n },\n },\n }),\n },\n responses: {\n 200: ok('The upload.', ref('UploadResponse')),\n ...problems(401, 403, 404, 422),\n },\n },\n },\n '/auth/session': {\n get: {\n operationId: 'getSession',\n responses: { 200: ok('The current user.', ref('Session')), ...problems(401) },\n },\n },\n '/auth/login': {\n post: {\n operationId: 'login',\n requestBody: {\n required: true,\n content: json({\n description:\n 'An email and a password, or the single secret of `auth.token`.',\n oneOf: [\n {\n type: 'object',\n required: ['email', 'password'],\n properties: {\n email: { type: 'string' },\n password: { type: 'string' },\n remember: { type: 'boolean' },\n },\n },\n {\n type: 'object',\n required: ['token'],\n properties: {\n token: { type: 'string' },\n remember: { type: 'boolean' },\n },\n },\n ],\n }),\n },\n responses: {\n 200: ok('Logged in.', ref('Session')),\n 202: ok(\n 'A second factor is required: answer `/auth/two-factor/challenge`.',\n {\n type: 'object',\n properties: { twoFactor: { type: 'boolean', const: true } },\n },\n ),\n ...problems(422),\n },\n },\n },\n '/auth/logout': {\n post: {\n operationId: 'logout',\n description:\n '`panneau` auth mode. In `external` mode, the browser goes to `auth.logoutUrl` instead.',\n responses: { 204: ok('Logged out.') },\n },\n },\n '/auth/providers/{provider}/redirect': {\n parameters: [pathParameter('provider', 'Provider id.')],\n get: {\n operationId: 'redirectToProvider',\n parameters: [\n queryParameter('next', 'Local path to go to after login.', {\n type: 'string',\n }),\n ],\n responses: {\n 302: { description: 'Redirect to the provider.' },\n ...problems(404),\n },\n },\n },\n '/auth/password/forgot': {\n post: {\n operationId: 'forgotPassword',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['email'],\n properties: { email: { type: 'string' } },\n }),\n },\n responses: {\n 204: ok('A reset link was sent, if the account exists.'),\n ...problems(422),\n },\n },\n },\n '/auth/password/reset': {\n post: {\n operationId: 'resetPassword',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['token', 'email', 'password'],\n properties: {\n token: { type: 'string' },\n email: { type: 'string' },\n password: { type: 'string' },\n },\n }),\n },\n responses: { 204: ok('The password was reset.'), ...problems(422) },\n },\n },\n '/auth/two-factor/challenge': {\n post: {\n operationId: 'twoFactorChallenge',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n properties: {\n code: { type: 'string' },\n recoveryCode: { type: 'string' },\n },\n }),\n },\n responses: { 200: ok('Logged in.', ref('Session')), ...problems(422) },\n },\n },\n '/auth/passkeys/options': {\n post: {\n operationId: 'passkeyOptions',\n responses: {\n 200: ok('WebAuthn request options.', {\n type: 'object',\n additionalProperties: true,\n }),\n },\n },\n },\n '/auth/passkeys/login': {\n post: {\n operationId: 'passkeyLogin',\n requestBody: {\n required: true,\n content: json({ type: 'object', additionalProperties: true }),\n },\n responses: { 200: ok('Logged in.', ref('Session')), ...problems(422) },\n },\n },\n '/account': {\n get: {\n operationId: 'getAccount',\n responses: {\n 200: ok('The current user.', {\n type: 'object',\n required: ['data'],\n properties: { data: ref('User') },\n }),\n ...problems(401),\n },\n },\n patch: {\n operationId: 'updateAccount',\n requestBody: { required: true, content: json(values) },\n responses: {\n 200: ok('The updated user.', {\n type: 'object',\n required: ['data'],\n properties: { data: ref('User') },\n }),\n ...problems(401, 422),\n },\n },\n },\n '/search': {\n get: {\n operationId: 'search',\n parameters: [\n {\n ...queryParameter('q', 'Search terms, trimmed.', {\n type: 'string',\n minLength: SEARCH_MIN_LENGTH,\n maxLength: SEARCH_MAX_LENGTH,\n }),\n required: true,\n },\n queryParameter('limit', 'Items per resource.', {\n type: 'integer',\n minimum: 1,\n maximum: SEARCH_MAX_LIMIT,\n default: SEARCH_DEFAULT_LIMIT,\n }),\n queryParameter(\n 'resources',\n 'Comma-separated ids of the searchable resources to search. Defaults to every one.',\n { type: 'string' },\n ),\n ],\n responses: {\n 200: ok(\n `Results grouped by resource, in the order of the definition: at most \\`limit\\` items per resource, and ${SEARCH_MAX_LIMIT} in all.`,\n ref('SearchResponse'),\n ),\n ...problems(401, 422, 429),\n },\n },\n },\n '/embeds': {\n get: {\n operationId: 'resolveEmbed',\n parameters: [\n {\n ...queryParameter('url', 'The URL to embed.', { type: 'string' }),\n required: true,\n },\n ],\n responses: {\n 200: ok(\n \"The value of an `embed` field for the URL, from its provider's oEmbed.\",\n ref('EmbedResponse'),\n ),\n ...problems(401, 422, 429),\n },\n },\n },\n '/dashboard/widgets/{widget}': {\n parameters: [pathParameter('widget', 'Widget id.')],\n get: {\n operationId: 'getWidgetData',\n responses: {\n 200: ok(\"The widget's data. Its shape depends on the widget type.\", {\n type: 'object',\n additionalProperties: true,\n }),\n ...problems(401, 403, 404),\n },\n },\n },\n },\n components: { schemas: createComponentSchemas() },\n };\n}\n"],"mappings":";;;;;;;;AAgBA,IAAM,OAAO,QAA4B,EAAE,MAAM,wBAAwB,KAAK;AAE9E,IAAM,QAAQ,YAAoC,EAAE,oBAAoB,EAAE,OAAO,EAAE;AAEnF,IAAM,MAAM,aAAqB,QAAqB,aAAsC;CACxF;CACA,GAAI,WAAW,KAAA,IAAY,EAAE,SAAS,KAAK,MAAM,EAAE,IAAI,CAAC;CACxD,GAAI,YAAY,KAAA,IAAY,EAAE,QAAQ,IAAI,CAAC;AAC/C;AAEA,IAAM,WAAmC;CACrC,KAAK;CACL,KAAK;CACL,KAAK;C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EACA,IAAI,eAAe,CACvB;KACA,GAAG,SAAS,KAAK,KAAK,GAAG;IAC7B;GACJ,EACJ;GACA,+BAA+B;IAC3B,YAAY,CAAC,cAAc,UAAU,YAAY,CAAC;IAClD,KAAK;KACD,aAAa;KACb,WAAW;MACP,KAAK,GAAG,4DAA4D;OAChE,MAAM;OACN,sBAAsB;MAC1B,CAAC;MACD,GAAG,SAAS,KAAK,KAAK,GAAG;KAC7B;IACJ;GACJ;EACJ;EACA,YAAY,EAAE,SAAS,uBAAuB,EAAE;CACpD;AACJ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Problem } from './schemas/api.js';
|
|
2
|
+
/**
|
|
3
|
+
* Whether a value is a problem details object (an API error). It checks the same shape as the
|
|
4
|
+
* `Problem` schema, without zod, so that UI packages can detect errors without loading the schemas.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isProblem(value: unknown): value is Problem;
|
|
7
|
+
//# sourceMappingURL=problem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem.d.ts","sourceRoot":"","sources":["../src/problem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAO7C;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAuB1D"}
|
package/dist/problem.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isRecord } from "./values.js";
|
|
2
|
+
//#region src/problem.ts
|
|
3
|
+
var isOptional = (value, check) => value === void 0 || check(value);
|
|
4
|
+
var isString = (value) => typeof value === "string";
|
|
5
|
+
/**
|
|
6
|
+
* Whether a value is a problem details object (an API error). It checks the same shape as the
|
|
7
|
+
* `Problem` schema, without zod, so that UI packages can detect errors without loading the schemas.
|
|
8
|
+
*/
|
|
9
|
+
function isProblem(value) {
|
|
10
|
+
if (!isRecord(value)) return false;
|
|
11
|
+
const { type, title, status, detail, instance, errors, current } = value;
|
|
12
|
+
return isString(type) && isString(title) && Number.isInteger(status) && status >= 400 && status <= 599 && isOptional(detail, isString) && isOptional(instance, isString) && isOptional(errors, (messages) => isRecord(messages) && Object.values(messages).every((list) => Array.isArray(list) && list.every(isString))) && isOptional(current, isItem);
|
|
13
|
+
}
|
|
14
|
+
function isItem(value) {
|
|
15
|
+
if (!isRecord(value)) return false;
|
|
16
|
+
const { id, version, abilities } = value;
|
|
17
|
+
return isString(id) && id !== "" && (version === null || isString(version)) && isRecord(abilities) && Object.values(abilities).every((ability) => typeof ability === "boolean");
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { isProblem };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=problem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem.js","names":[],"sources":["../src/problem.ts"],"sourcesContent":["import type { Problem } from './schemas/api';\nimport { isRecord } from './values';\n\nconst isOptional = (value: unknown, check: (value: unknown) => boolean) =>\n value === undefined || check(value);\nconst isString = (value: unknown) => typeof value === 'string';\n\n/**\n * Whether a value is a problem details object (an API error). It checks the same shape as the\n * `Problem` schema, without zod, so that UI packages can detect errors without loading the schemas.\n */\nexport function isProblem(value: unknown): value is Problem {\n if (!isRecord(value)) {\n return false;\n }\n const { type, title, status, detail, instance, errors, current } = value;\n return (\n isString(type) &&\n isString(title) &&\n Number.isInteger(status) &&\n (status as number) >= 400 &&\n (status as number) <= 599 &&\n isOptional(detail, isString) &&\n isOptional(instance, isString) &&\n isOptional(\n errors,\n (messages) =>\n isRecord(messages) &&\n Object.values(messages).every(\n (list) => Array.isArray(list) && list.every(isString),\n ),\n ) &&\n isOptional(current, isItem)\n );\n}\n\nfunction isItem(value: unknown): boolean {\n if (!isRecord(value)) {\n return false;\n }\n const { id, version, abilities } = value;\n return (\n isString(id) &&\n id !== '' &&\n (version === null || isString(version)) &&\n isRecord(abilities) &&\n Object.values(abilities).every((ability) => typeof ability === 'boolean')\n );\n}\n"],"mappings":";;AAGA,IAAM,cAAc,OAAgB,UAChC,UAAU,KAAA,KAAa,MAAM,KAAK;AACtC,IAAM,YAAY,UAAmB,OAAO,UAAU;;;;;AAMtD,SAAgB,UAAU,OAAkC;CACxD,IAAI,CAAC,SAAS,KAAK,GACf,OAAO;CAEX,MAAM,EAAE,MAAM,OAAO,QAAQ,QAAQ,UAAU,QAAQ,YAAY;CACnE,OACI,SAAS,IAAI,KACb,SAAS,KAAK,KACd,OAAO,UAAU,MAAM,KACtB,UAAqB,OACrB,UAAqB,OACtB,WAAW,QAAQ,QAAQ,KAC3B,WAAW,UAAU,QAAQ,KAC7B,WACI,SACC,aACG,SAAS,QAAQ,KACjB,OAAO,OAAO,QAAQ,CAAC,CAAC,OACnB,SAAS,MAAM,QAAQ,IAAI,KAAK,KAAK,MAAM,QAAQ,CACxD,CACR,KACA,WAAW,SAAS,MAAM;AAElC;AAEA,SAAS,OAAO,OAAyB;CACrC,IAAI,CAAC,SAAS,KAAK,GACf,OAAO;CAEX,MAAM,EAAE,IAAI,SAAS,cAAc;CACnC,OACI,SAAS,EAAE,KACX,OAAO,OACN,YAAY,QAAQ,SAAS,OAAO,MACrC,SAAS,SAAS,KAClB,OAAO,OAAO,SAAS,CAAC,CAAC,OAAO,YAAY,OAAO,YAAY,SAAS;AAEhF"}
|
package/dist/query.d.ts
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The bounds of a range filter (`date-range`), both inclusive. An open end is left out. Sent as
|
|
3
|
+
* `filter[published_at][from]=2026-01-01&filter[published_at][to]=2026-01-31`.
|
|
4
|
+
*/
|
|
5
|
+
export interface FilterRange {
|
|
6
|
+
from?: string | number;
|
|
7
|
+
to?: string | number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The value of a filter: one value (`filter[status]=draft`), a list that matches any of its values
|
|
11
|
+
* (`filter[tags][]=a&filter[tags][]=b`), or the bounds of a range.
|
|
12
|
+
*/
|
|
13
|
+
export type FilterValue = string | number | boolean | Array<string | number | boolean> | FilterRange;
|
|
14
|
+
/** Whether a filter value is the bounds of a range, and not one value or a list of values. */
|
|
15
|
+
export declare function isFilterRange(value: unknown): value is FilterRange;
|
|
16
|
+
/**
|
|
17
|
+
* Whether a value is within the bounds of a range filter, both inclusive: the reference of how a
|
|
18
|
+
* backend reads them. Numbers compare as numbers. Other values compare as strings, on the length of
|
|
19
|
+
* the bound, so that a day (`2026-01-31`) includes the times of that day (`2026-01-31T18:00:00Z`).
|
|
20
|
+
* An empty value is never in a range.
|
|
21
|
+
*/
|
|
22
|
+
export declare function matchesFilterRange(value: unknown, range: FilterRange): boolean;
|
|
2
23
|
/** Query of a list request (`GET /resources/{resource}`). */
|
|
3
24
|
export interface ListQuery {
|
|
4
25
|
page?: number;
|
|
5
26
|
perPage?: number;
|
|
27
|
+
/** The page to get of a list whose `pagination` is `cursor`: `nextCursor` of the page before. */
|
|
28
|
+
cursor?: string;
|
|
6
29
|
/** Fields to sort by, in order. A `-` prefix sorts descending. */
|
|
7
30
|
sort?: string[];
|
|
8
31
|
filter?: Record<string, FilterValue>;
|
|
@@ -12,6 +35,21 @@ export interface ListQuery {
|
|
|
12
35
|
}
|
|
13
36
|
/** Serializes a list query to the protocol's query string format. */
|
|
14
37
|
export declare function toSearchParams(query: ListQuery): URLSearchParams;
|
|
15
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Parses a list query from the protocol's query string format. Filter values stay strings, and the
|
|
40
|
+
* bounds of a range (`filter[id][from]`, `filter[id][to]`) become a `FilterRange`.
|
|
41
|
+
*/
|
|
16
42
|
export declare function fromSearchParams(params: URLSearchParams): ListQuery;
|
|
43
|
+
/** The meta of a page of a list paged with cursors (`pagination: "cursor"`). */
|
|
44
|
+
export interface CursorPageMeta {
|
|
45
|
+
perPage: number;
|
|
46
|
+
nextCursor: string | null;
|
|
47
|
+
previousCursor?: string | null;
|
|
48
|
+
total?: number | null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Whether the meta of a page of a list comes from a list paged with cursors (`nextCursor`), rather
|
|
52
|
+
* than numbered pages (`page`, `lastPage`, `total`).
|
|
53
|
+
*/
|
|
54
|
+
export declare function isCursorPage(meta: object): meta is CursorPageMeta;
|
|
17
55
|
//# sourceMappingURL=query.d.ts.map
|
package/dist/query.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,MAAM,
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,WAAW;IACxB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GACnB,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG,WAAW,CAAC;AAE/E,8FAA8F;AAC9F,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAID;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAe9E;AAED,6DAA6D;AAC7D,MAAM,WAAW,SAAS;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iGAAiG;IACjG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACrC,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,qEAAqE;AACrE,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,eAAe,CAmChE;AAID;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,CAsDnE;AAED,gFAAgF;AAChF,MAAM,WAAW,cAAc;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,cAAc,CAEjE"}
|
package/dist/query.js
CHANGED
|
@@ -1,20 +1,48 @@
|
|
|
1
1
|
//#region src/query.ts
|
|
2
|
+
/** Whether a filter value is the bounds of a range, and not one value or a list of values. */
|
|
3
|
+
function isFilterRange(value) {
|
|
4
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
var RANGE_BOUNDS = ["from", "to"];
|
|
7
|
+
/**
|
|
8
|
+
* Whether a value is within the bounds of a range filter, both inclusive: the reference of how a
|
|
9
|
+
* backend reads them. Numbers compare as numbers. Other values compare as strings, on the length of
|
|
10
|
+
* the bound, so that a day (`2026-01-31`) includes the times of that day (`2026-01-31T18:00:00Z`).
|
|
11
|
+
* An empty value is never in a range.
|
|
12
|
+
*/
|
|
13
|
+
function matchesFilterRange(value, range) {
|
|
14
|
+
if (value === null || value === void 0 || value === "") return false;
|
|
15
|
+
const compare = (bound) => {
|
|
16
|
+
if (typeof value === "number" || typeof bound === "number") return Number(value) - Number(bound);
|
|
17
|
+
const prefix = String(value).slice(0, bound.length);
|
|
18
|
+
return prefix < bound ? -1 : prefix > bound ? 1 : 0;
|
|
19
|
+
};
|
|
20
|
+
return (range.from === void 0 || range.from === "" || compare(range.from) >= 0) && (range.to === void 0 || range.to === "" || compare(range.to) <= 0);
|
|
21
|
+
}
|
|
2
22
|
/** Serializes a list query to the protocol's query string format. */
|
|
3
23
|
function toSearchParams(query) {
|
|
4
24
|
const params = new URLSearchParams();
|
|
5
25
|
if (query.page !== void 0) params.set("page", String(query.page));
|
|
6
26
|
if (query.perPage !== void 0) params.set("perPage", String(query.perPage));
|
|
27
|
+
if (query.cursor !== void 0 && query.cursor !== "") params.set("cursor", query.cursor);
|
|
7
28
|
if (query.sort !== void 0 && query.sort.length > 0) params.set("sort", query.sort.join(","));
|
|
8
29
|
Object.entries(query.filter ?? {}).forEach(([key, value]) => {
|
|
9
30
|
if (Array.isArray(value)) value.forEach((item) => params.append(`filter[${key}][]`, String(item)));
|
|
31
|
+
else if (isFilterRange(value)) RANGE_BOUNDS.forEach((bound) => {
|
|
32
|
+
const limit = value[bound];
|
|
33
|
+
if (limit !== void 0 && limit !== "") params.set(`filter[${key}][${bound}]`, String(limit));
|
|
34
|
+
});
|
|
10
35
|
else params.set(`filter[${key}]`, String(value));
|
|
11
36
|
});
|
|
12
37
|
if (query.q !== void 0 && query.q !== "") params.set("q", query.q);
|
|
13
38
|
if (query.fields !== void 0 && query.fields.length > 0) params.set("fields", query.fields.join(","));
|
|
14
39
|
return params;
|
|
15
40
|
}
|
|
16
|
-
var FILTER_KEY = /^filter\[([^\]]+)\](
|
|
17
|
-
/**
|
|
41
|
+
var FILTER_KEY = /^filter\[([^\]]+)\](?:\[(|from|to)\])?$/;
|
|
42
|
+
/**
|
|
43
|
+
* Parses a list query from the protocol's query string format. Filter values stay strings, and the
|
|
44
|
+
* bounds of a range (`filter[id][from]`, `filter[id][to]`) become a `FilterRange`.
|
|
45
|
+
*/
|
|
18
46
|
function fromSearchParams(params) {
|
|
19
47
|
const query = {};
|
|
20
48
|
const integer = (value) => {
|
|
@@ -25,6 +53,8 @@ function fromSearchParams(params) {
|
|
|
25
53
|
if (page !== void 0) query.page = page;
|
|
26
54
|
const perPage = integer(params.get("perPage"));
|
|
27
55
|
if (perPage !== void 0) query.perPage = perPage;
|
|
56
|
+
const cursor = params.get("cursor");
|
|
57
|
+
if (cursor !== null && cursor !== "") query.cursor = cursor;
|
|
28
58
|
const sort = params.get("sort");
|
|
29
59
|
if (sort !== null && sort !== "") query.sort = sort.split(",").filter((part) => part !== "");
|
|
30
60
|
const q = params.get("q");
|
|
@@ -36,14 +66,25 @@ function fromSearchParams(params) {
|
|
|
36
66
|
if (match?.[1] === void 0) return;
|
|
37
67
|
query.filter ??= {};
|
|
38
68
|
const name = match[1];
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
69
|
+
const current = query.filter[name];
|
|
70
|
+
if (match[2] === "") query.filter[name] = [...Array.isArray(current) ? current : [], value];
|
|
71
|
+
else if (match[2] !== void 0) {
|
|
72
|
+
if (value !== "") query.filter[name] = {
|
|
73
|
+
...isFilterRange(current) ? current : {},
|
|
74
|
+
[match[2]]: value
|
|
75
|
+
};
|
|
42
76
|
} else query.filter[name] = value;
|
|
43
77
|
});
|
|
44
78
|
return query;
|
|
45
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Whether the meta of a page of a list comes from a list paged with cursors (`nextCursor`), rather
|
|
82
|
+
* than numbered pages (`page`, `lastPage`, `total`).
|
|
83
|
+
*/
|
|
84
|
+
function isCursorPage(meta) {
|
|
85
|
+
return "nextCursor" in meta;
|
|
86
|
+
}
|
|
46
87
|
//#endregion
|
|
47
|
-
export { fromSearchParams, toSearchParams };
|
|
88
|
+
export { fromSearchParams, isCursorPage, isFilterRange, matchesFilterRange, toSearchParams };
|
|
48
89
|
|
|
49
90
|
//# sourceMappingURL=query.js.map
|
package/dist/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","names":[],"sources":["../src/query.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"query.js","names":[],"sources":["../src/query.ts"],"sourcesContent":["/**\n * The bounds of a range filter (`date-range`), both inclusive. An open end is left out. Sent as\n * `filter[published_at][from]=2026-01-01&filter[published_at][to]=2026-01-31`.\n */\nexport interface FilterRange {\n from?: string | number;\n to?: string | number;\n}\n\n/**\n * The value of a filter: one value (`filter[status]=draft`), a list that matches any of its values\n * (`filter[tags][]=a&filter[tags][]=b`), or the bounds of a range.\n */\nexport type FilterValue =\n string | number | boolean | Array<string | number | boolean> | FilterRange;\n\n/** Whether a filter value is the bounds of a range, and not one value or a list of values. */\nexport function isFilterRange(value: unknown): value is FilterRange {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nconst RANGE_BOUNDS = ['from', 'to'] as const;\n\n/**\n * Whether a value is within the bounds of a range filter, both inclusive: the reference of how a\n * backend reads them. Numbers compare as numbers. Other values compare as strings, on the length of\n * the bound, so that a day (`2026-01-31`) includes the times of that day (`2026-01-31T18:00:00Z`).\n * An empty value is never in a range.\n */\nexport function matchesFilterRange(value: unknown, range: FilterRange): boolean {\n if (value === null || value === undefined || value === '') {\n return false;\n }\n const compare = (bound: string | number): number => {\n if (typeof value === 'number' || typeof bound === 'number') {\n return Number(value) - Number(bound);\n }\n const prefix = String(value).slice(0, bound.length);\n return prefix < bound ? -1 : prefix > bound ? 1 : 0;\n };\n return (\n (range.from === undefined || range.from === '' || compare(range.from) >= 0) &&\n (range.to === undefined || range.to === '' || compare(range.to) <= 0)\n );\n}\n\n/** Query of a list request (`GET /resources/{resource}`). */\nexport interface ListQuery {\n page?: number;\n perPage?: number;\n /** The page to get of a list whose `pagination` is `cursor`: `nextCursor` of the page before. */\n cursor?: string;\n /** Fields to sort by, in order. A `-` prefix sorts descending. */\n sort?: string[];\n filter?: Record<string, FilterValue>;\n q?: string;\n /** Fields to include in each item. */\n fields?: string[];\n}\n\n/** Serializes a list query to the protocol's query string format. */\nexport function toSearchParams(query: ListQuery): URLSearchParams {\n const params = new URLSearchParams();\n if (query.page !== undefined) {\n params.set('page', String(query.page));\n }\n if (query.perPage !== undefined) {\n params.set('perPage', String(query.perPage));\n }\n if (query.cursor !== undefined && query.cursor !== '') {\n params.set('cursor', query.cursor);\n }\n if (query.sort !== undefined && query.sort.length > 0) {\n params.set('sort', query.sort.join(','));\n }\n Object.entries(query.filter ?? {}).forEach(([key, value]) => {\n if (Array.isArray(value)) {\n value.forEach((item) => params.append(`filter[${key}][]`, String(item)));\n } else if (isFilterRange(value)) {\n RANGE_BOUNDS.forEach((bound) => {\n const limit = value[bound];\n if (limit !== undefined && limit !== '') {\n params.set(`filter[${key}][${bound}]`, String(limit));\n }\n });\n } else {\n params.set(`filter[${key}]`, String(value));\n }\n });\n if (query.q !== undefined && query.q !== '') {\n params.set('q', query.q);\n }\n if (query.fields !== undefined && query.fields.length > 0) {\n params.set('fields', query.fields.join(','));\n }\n return params;\n}\n\nconst FILTER_KEY = /^filter\\[([^\\]]+)\\](?:\\[(|from|to)\\])?$/;\n\n/**\n * Parses a list query from the protocol's query string format. Filter values stay strings, and the\n * bounds of a range (`filter[id][from]`, `filter[id][to]`) become a `FilterRange`.\n */\nexport function fromSearchParams(params: URLSearchParams): ListQuery {\n const query: ListQuery = {};\n const integer = (value: string | null): number | undefined => {\n if (value === null || !/^\\d+$/.test(value)) {\n return undefined;\n }\n return Number.parseInt(value, 10);\n };\n const page = integer(params.get('page'));\n if (page !== undefined) {\n query.page = page;\n }\n const perPage = integer(params.get('perPage'));\n if (perPage !== undefined) {\n query.perPage = perPage;\n }\n const cursor = params.get('cursor');\n if (cursor !== null && cursor !== '') {\n query.cursor = cursor;\n }\n const sort = params.get('sort');\n if (sort !== null && sort !== '') {\n query.sort = sort.split(',').filter((part) => part !== '');\n }\n const q = params.get('q');\n if (q !== null && q !== '') {\n query.q = q;\n }\n const fields = params.get('fields');\n if (fields !== null && fields !== '') {\n query.fields = fields.split(',').filter((part) => part !== '');\n }\n params.forEach((value, key) => {\n const match = FILTER_KEY.exec(key);\n if (match?.[1] === undefined) {\n return;\n }\n query.filter ??= {};\n const name = match[1];\n const current = query.filter[name];\n if (match[2] === '') {\n query.filter[name] = [...(Array.isArray(current) ? current : []), value];\n } else if (match[2] !== undefined) {\n if (value !== '') {\n query.filter[name] = {\n ...(isFilterRange(current) ? current : {}),\n [match[2]]: value,\n };\n }\n } else {\n query.filter[name] = value;\n }\n });\n return query;\n}\n\n/** The meta of a page of a list paged with cursors (`pagination: \"cursor\"`). */\nexport interface CursorPageMeta {\n perPage: number;\n nextCursor: string | null;\n previousCursor?: string | null;\n total?: number | null;\n}\n\n/**\n * Whether the meta of a page of a list comes from a list paged with cursors (`nextCursor`), rather\n * than numbered pages (`page`, `lastPage`, `total`).\n */\nexport function isCursorPage(meta: object): meta is CursorPageMeta {\n return 'nextCursor' in meta;\n}\n"],"mappings":";;AAiBA,SAAgB,cAAc,OAAsC;CAChE,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC9E;AAEA,IAAM,eAAe,CAAC,QAAQ,IAAI;;;;;;;AAQlC,SAAgB,mBAAmB,OAAgB,OAA6B;CAC5E,IAAI,UAAU,QAAQ,UAAU,KAAA,KAAa,UAAU,IACnD,OAAO;CAEX,MAAM,WAAW,UAAmC;EAChD,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAC9C,OAAO,OAAO,KAAK,IAAI,OAAO,KAAK;EAEvC,MAAM,SAAS,OAAO,KAAK,CAAC,CAAC,MAAM,GAAG,MAAM,MAAM;EAClD,OAAO,SAAS,QAAQ,KAAK,SAAS,QAAQ,IAAI;CACtD;CACA,QACK,MAAM,SAAS,KAAA,KAAa,MAAM,SAAS,MAAM,QAAQ,MAAM,IAAI,KAAK,OACxE,MAAM,OAAO,KAAA,KAAa,MAAM,OAAO,MAAM,QAAQ,MAAM,EAAE,KAAK;AAE3E;;AAiBA,SAAgB,eAAe,OAAmC;CAC9D,MAAM,SAAS,IAAI,gBAAgB;CACnC,IAAI,MAAM,SAAS,KAAA,GACf,OAAO,IAAI,QAAQ,OAAO,M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Rule } from './schemas/field.js';
|
|
2
2
|
/** A rule that a value doesn't satisfy. */
|
|
3
3
|
export interface RuleFailure {
|
|
4
4
|
rule: string;
|
|
@@ -18,8 +18,11 @@ export interface CheckOptions {
|
|
|
18
18
|
/** Only check the fields present in the values (partial updates). */
|
|
19
19
|
partial?: boolean;
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
22
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Checks one value against a field's rules. Returns the rules that fail. Rules limited to a `mode`
|
|
23
|
+
* only apply when it is given.
|
|
24
|
+
*/
|
|
25
|
+
export declare function checkRules(rules: Rule[], value: unknown, root?: Record<string, unknown>, mode?: CheckOptions['mode']): RuleFailure[];
|
|
23
26
|
/**
|
|
24
27
|
* Checks form values against the portable rules of their fields. Returns the failures keyed by
|
|
25
28
|
* the dot path of the value (`title.fr`, `blocks.2.image`), the same keys as validation errors.
|
package/dist/rules.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAInD,2CAA2C;AAC3C,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IACzB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,8EAA8E;IAC9E,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC3B,qEAAqE;IACrE,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AA4FD;;;GAGG;AACH,wBAAgB,UAAU,CACtB,KAAK,EAAE,IAAI,EAAE,EACb,KAAK,EAAE,OAAO,EACd,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EAClC,IAAI,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,GAC5B,WAAW,EAAE,CAgFf;AAkGD;;;;GAIG;AACH,wBAAgB,WAAW,CACvB,MAAM,EAAE,KAAK,EAAE,EACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,GAAE,YAAiB,GAC3B,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAI/B"}
|
package/dist/rules.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import { PORTABLE_RULES } from "./
|
|
1
|
+
import { PORTABLE_RULES } from "./constants.js";
|
|
2
2
|
import { getValue, isFilled, isRecord } from "./values.js";
|
|
3
3
|
import { evaluateCondition } from "./conditions.js";
|
|
4
|
+
import { matchesRatio, renderedCropSize } from "./transforms.js";
|
|
4
5
|
//#region src/rules.ts
|
|
5
6
|
var EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
6
7
|
function isKnownRule(rule) {
|
|
7
8
|
return PORTABLE_RULES.includes(rule.rule);
|
|
8
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Whether a rule applies in a mode: a rule with a `mode` applies only in that mode, and not when the
|
|
12
|
+
* mode isn't known.
|
|
13
|
+
*/
|
|
14
|
+
function appliesIn(rule, mode) {
|
|
15
|
+
return rule.mode === void 0 || rule.mode === mode;
|
|
16
|
+
}
|
|
9
17
|
function failure(rule) {
|
|
10
18
|
const result = { rule: rule.rule };
|
|
11
19
|
if ("value" in rule && rule.value !== void 0) result.value = rule.value;
|
|
@@ -23,19 +31,39 @@ function matchesMime(mime, patterns) {
|
|
|
23
31
|
return mime === pattern;
|
|
24
32
|
});
|
|
25
33
|
}
|
|
34
|
+
/** The files of a value, with their MIME type and size: stored files, or chosen ones (`File`). */
|
|
26
35
|
function mediaList(value) {
|
|
27
|
-
return (Array.isArray(value) ? value : [value]).filter(isRecord)
|
|
36
|
+
return (Array.isArray(value) ? value : [value]).filter(isRecord).map((media) => typeof Blob !== "undefined" && media instanceof Blob ? {
|
|
37
|
+
mime: media.type === "" ? void 0 : media.type,
|
|
38
|
+
size: media.size
|
|
39
|
+
} : media);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Whether each image of a value has the crop the `crop` rule asks for (decision 0031): a crop when
|
|
43
|
+
* it is required, and one of the ratios once rendered. An id alone has no crop.
|
|
44
|
+
*/
|
|
45
|
+
function hasCrop(value, rule) {
|
|
46
|
+
return (Array.isArray(value) ? value : [value]).every((entry) => {
|
|
47
|
+
const transform = isRecord(entry) && isRecord(entry.transform) ? entry.transform : {};
|
|
48
|
+
const size = renderedCropSize(transform);
|
|
49
|
+
if (size === null) return rule.required !== true;
|
|
50
|
+
const ratios = rule.ratios ?? [];
|
|
51
|
+
return ratios.length === 0 || ratios.some((ratio) => matchesRatio(size.width, size.height, ratio));
|
|
52
|
+
});
|
|
28
53
|
}
|
|
29
54
|
function toTime(value) {
|
|
30
55
|
if (typeof value !== "string" && typeof value !== "number") return null;
|
|
31
56
|
const time = new Date(value).getTime();
|
|
32
57
|
return Number.isNaN(time) ? null : time;
|
|
33
58
|
}
|
|
34
|
-
/**
|
|
35
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Checks one value against a field's rules. Returns the rules that fail. Rules limited to a `mode`
|
|
61
|
+
* only apply when it is given.
|
|
62
|
+
*/
|
|
63
|
+
function checkRules(rules, value, root = {}, mode) {
|
|
36
64
|
const failures = [];
|
|
37
65
|
const filled = isFilled(value);
|
|
38
|
-
rules.filter(isKnownRule).forEach((rule) => {
|
|
66
|
+
rules.filter((rule) => isKnownRule(rule) && appliesIn(rule, mode)).forEach((rule) => {
|
|
39
67
|
if (rule.rule === "required") {
|
|
40
68
|
if (!filled) failures.push(failure(rule));
|
|
41
69
|
return;
|
|
@@ -59,6 +87,9 @@ function checkRules(rules, value, root = {}) {
|
|
|
59
87
|
case "url":
|
|
60
88
|
valid = typeof value !== "string" || URL.canParse(value);
|
|
61
89
|
break;
|
|
90
|
+
case "json":
|
|
91
|
+
valid = isRecord(value) || Array.isArray(value);
|
|
92
|
+
break;
|
|
62
93
|
case "in": {
|
|
63
94
|
const allowed = rule.value;
|
|
64
95
|
valid = (Array.isArray(value) ? value : [value]).every((item) => allowed.includes(item));
|
|
@@ -70,6 +101,9 @@ function checkRules(rules, value, root = {}) {
|
|
|
70
101
|
case "maxSize":
|
|
71
102
|
valid = mediaList(value).every((media) => typeof media.size !== "number" || media.size <= rule.value);
|
|
72
103
|
break;
|
|
104
|
+
case "crop":
|
|
105
|
+
valid = !isRecord(rule.value) || hasCrop(value, rule.value);
|
|
106
|
+
break;
|
|
73
107
|
case "before":
|
|
74
108
|
case "after": {
|
|
75
109
|
const bound = rule.value;
|
|
@@ -86,8 +120,16 @@ function checkRules(rules, value, root = {}) {
|
|
|
86
120
|
function addFailures(context, path, failures) {
|
|
87
121
|
if (failures.length > 0) context.failures[path] = [...context.failures[path] ?? [], ...failures];
|
|
88
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* The rules of a field that apply in the mode, with those its type implies: `json` for the `json`
|
|
125
|
+
* type.
|
|
126
|
+
*/
|
|
127
|
+
function rulesOf(field, mode) {
|
|
128
|
+
const rules = (field.rules ?? []).filter((rule) => appliesIn(rule, mode));
|
|
129
|
+
return field.type === "json" && !rules.some((rule) => rule.rule === "json") ? [...rules, { rule: "json" }] : rules;
|
|
130
|
+
}
|
|
89
131
|
function checkFieldValue(field, value, path, context) {
|
|
90
|
-
const rules = field.
|
|
132
|
+
const rules = rulesOf(field, context.mode);
|
|
91
133
|
if (field.localized === true) {
|
|
92
134
|
const localized = isRecord(value) ? value : {};
|
|
93
135
|
const required = rules.filter((rule) => rule.rule === "required");
|
|
@@ -97,15 +139,15 @@ function checkFieldValue(field, value, path, context) {
|
|
|
97
139
|
if (locales === void 0 || locales.length === 0) {
|
|
98
140
|
if (!Object.values(localized).some(isFilled)) addFailures(context, path, required.map(failure));
|
|
99
141
|
} else locales.forEach((locale) => {
|
|
100
|
-
addFailures(context, `${path}.${locale}`, checkRules(required, localized[locale], context.root));
|
|
142
|
+
addFailures(context, `${path}.${locale}`, checkRules(required, localized[locale], context.root, context.mode));
|
|
101
143
|
});
|
|
102
144
|
}
|
|
103
145
|
Object.entries(localized).forEach(([locale, localeValue]) => {
|
|
104
|
-
addFailures(context, `${path}.${locale}`, checkRules(others, localeValue, context.root));
|
|
146
|
+
addFailures(context, `${path}.${locale}`, checkRules(others, localeValue, context.root, context.mode));
|
|
105
147
|
});
|
|
106
148
|
return;
|
|
107
149
|
}
|
|
108
|
-
addFailures(context, path, checkRules(rules, value, context.root));
|
|
150
|
+
addFailures(context, path, checkRules(rules, value, context.root, context.mode));
|
|
109
151
|
if (field.type === "group" && field.fields !== void 0 && isRecord(value)) checkFields(field.fields, value, `${path}.`, context);
|
|
110
152
|
if (field.type === "repeater" && Array.isArray(value)) value.forEach((item, index) => {
|
|
111
153
|
if (!isRecord(item)) return;
|