@panneau/protocol 5.0.0-alpha.4 → 5.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/conformance/index.d.ts.map +1 -1
- package/dist/conformance/index.js +121 -1
- package/dist/conformance/index.js.map +1 -1
- package/dist/constants.d.ts +2 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.js +5 -2
- 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 +2 -2
- package/dist/lint.d.ts.map +1 -1
- package/dist/lint.js +15 -9
- package/dist/lint.js.map +1 -1
- package/dist/mock/example.d.ts.map +1 -1
- package/dist/mock/example.js +8 -0
- package/dist/mock/example.js.map +1 -1
- package/dist/mock/index.d.ts +9 -1
- package/dist/mock/index.d.ts.map +1 -1
- package/dist/mock/index.js +119 -13
- package/dist/mock/index.js.map +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +37 -7
- package/dist/openapi.js.map +1 -1
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +17 -0
- package/dist/rules.js.map +1 -1
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +4 -1
- package/dist/schemas/action.d.ts +17 -1
- package/dist/schemas/action.d.ts.map +1 -1
- package/dist/schemas/api.d.ts +87 -0
- package/dist/schemas/api.d.ts.map +1 -1
- package/dist/schemas/api.js +28 -9
- package/dist/schemas/api.js.map +1 -1
- package/dist/schemas/definition.d.ts +38 -2
- package/dist/schemas/definition.d.ts.map +1 -1
- package/dist/schemas/definition.js +2 -1
- package/dist/schemas/definition.js.map +1 -1
- package/dist/schemas/field.d.ts +24 -1
- package/dist/schemas/field.d.ts.map +1 -1
- package/dist/schemas/field.js +22 -4
- package/dist/schemas/field.js.map +1 -1
- package/dist/schemas/index.d.ts +201 -6
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +4 -2
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/resource.d.ts +36 -2
- package/dist/schemas/resource.d.ts.map +1 -1
- package/dist/schemas/resource.js +3 -1
- package/dist/schemas/resource.js.map +1 -1
- 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/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/package.json +1 -1
- package/schema/boot.schema.json +80 -1
- package/schema/definition.schema.json +80 -1
- package/schema/openapi.json +342 -13
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 { Theme } from './schemas/theme';\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};\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:\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 ...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(400, 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 '/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 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":";;;;;;;AAUA,IAA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;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('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 ...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(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 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, 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 '/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,W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H,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;KACR;MACI,GAAG,eAAe,KAAK,0BAA0B;OAC7C,MAAM;OACN,WAAA;OACA,WAAA;MACJ,CAAC;MACD,UAAU;KACd;KACA,eAAe,SAAS,uBAAuB;MAC3C,MAAM;MACN,SAAS;MACT,SAAA;MACA,SAAA;KACJ,CAAC;KACD,eACI,aACA,qFACA,EAAE,MAAM,SAAS,CACrB;IACJ;IACA,WAAW;KACP,KAAK,GACD,qHACA,IAAI,gBAAgB,CACxB;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"}
|
package/dist/rules.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AA6ED,6EAA6E;AAC7E,wBAAgB,UAAU,CACtB,KAAK,EAAE,IAAI,EAAE,EACb,KAAK,EAAE,OAAO,EACd,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACnC,WAAW,EAAE,CA2Ef;AAuFD;;;;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,6 +1,7 @@
|
|
|
1
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) {
|
|
@@ -26,6 +27,19 @@ function matchesMime(mime, patterns) {
|
|
|
26
27
|
function mediaList(value) {
|
|
27
28
|
return (Array.isArray(value) ? value : [value]).filter(isRecord);
|
|
28
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Whether each image of a value has the crop the `crop` rule asks for (decision 0031): a crop when
|
|
32
|
+
* it is required, and one of the ratios once rendered. An id alone has no crop.
|
|
33
|
+
*/
|
|
34
|
+
function hasCrop(value, rule) {
|
|
35
|
+
return (Array.isArray(value) ? value : [value]).every((entry) => {
|
|
36
|
+
const transform = isRecord(entry) && isRecord(entry.transform) ? entry.transform : {};
|
|
37
|
+
const size = renderedCropSize(transform);
|
|
38
|
+
if (size === null) return rule.required !== true;
|
|
39
|
+
const ratios = rule.ratios ?? [];
|
|
40
|
+
return ratios.length === 0 || ratios.some((ratio) => matchesRatio(size.width, size.height, ratio));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
29
43
|
function toTime(value) {
|
|
30
44
|
if (typeof value !== "string" && typeof value !== "number") return null;
|
|
31
45
|
const time = new Date(value).getTime();
|
|
@@ -70,6 +84,9 @@ function checkRules(rules, value, root = {}) {
|
|
|
70
84
|
case "maxSize":
|
|
71
85
|
valid = mediaList(value).every((media) => typeof media.size !== "number" || media.size <= rule.value);
|
|
72
86
|
break;
|
|
87
|
+
case "crop":
|
|
88
|
+
valid = !isRecord(rule.value) || hasCrop(value, rule.value);
|
|
89
|
+
break;
|
|
73
90
|
case "before":
|
|
74
91
|
case "after": {
|
|
75
92
|
const bound = rule.value;
|
package/dist/rules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.js","names":[],"sources":["../src/rules.ts"],"sourcesContent":["import { evaluateCondition } from './conditions';\nimport { PORTABLE_RULES } from './constants';\nimport type { Field, Rule } from './schemas/field';\nimport { getValue, isFilled, isRecord } from './values';\n\n/** A rule that a value doesn't satisfy. */\nexport interface RuleFailure {\n rule: string;\n /** The rule's parameter (`max: 120` gives `120`). */\n value?: unknown;\n /** The message set on the rule, if any. */\n message?: string;\n}\n\nexport interface CheckOptions {\n /**\n * Locales a `required` localized field must be filled in. Without it, one filled locale is\n * enough.\n */\n locales?: string[];\n /** `create` skips `updateOnly` fields; `update` skips `createOnly` fields. */\n mode?: 'create' | 'update';\n /** Only check the fields present in the values (partial updates). */\n partial?: boolean;\n}\n\ninterface Context extends CheckOptions {\n /** The whole form, for `visibleWhen` and date rules that reference other fields. */\n root: Record<string, unknown>;\n failures: Record<string, RuleFailure[]>;\n}\n\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\nfunction isKnownRule(rule: Rule): boolean {\n return (PORTABLE_RULES as readonly string[]).includes(rule.rule);\n}\n\nfunction failure(rule: Rule): RuleFailure {\n const result: RuleFailure = { rule: rule.rule };\n if ('value' in rule && rule.value !== undefined) {\n result.value = rule.value;\n }\n if (rule.message !== undefined) {\n result.message = rule.message;\n }\n return result;\n}\n\nfunction sizeOf(value: unknown): number | null {\n if (typeof value === 'number') {\n return value;\n }\n if (typeof value === 'string' || Array.isArray(value)) {\n return value.length;\n }\n return null;\n}\n\nfunction matchesMime(mime: string, patterns: string[]): boolean {\n return patterns.some((pattern) => {\n if (pattern.endsWith('/*')) {\n return mime.startsWith(pattern.slice(0, -1));\n }\n return mime === pattern;\n });\n}\n\nfunction mediaList(value: unknown): Record<string, unknown>[] {\n const list = Array.isArray(value) ? value : [value];\n return list.filter(isRecord);\n}\n\nfunction toTime(value: unknown): number | null {\n if (typeof value !== 'string' && typeof value !== 'number') {\n return null;\n }\n const time = new Date(value).getTime();\n return Number.isNaN(time) ? null : time;\n}\n\n/** Checks one value against a field's rules. Returns the rules that fail. */\nexport function checkRules(\n rules: Rule[],\n value: unknown,\n root: Record<string, unknown> = {},\n): RuleFailure[] {\n const failures: RuleFailure[] = [];\n const filled = isFilled(value);\n rules.filter(isKnownRule).forEach((rule) => {\n if (rule.rule === 'required') {\n if (!filled) {\n failures.push(failure(rule));\n }\n return;\n }\n if (!filled) {\n return;\n }\n let valid = true;\n switch (rule.rule) {\n case 'min':\n case 'max': {\n const size = sizeOf(value);\n const limit = rule.value as number;\n valid = size === null || (rule.rule === 'min' ? size >= limit : size <= limit);\n break;\n }\n case 'pattern':\n valid =\n typeof value !== 'string' ||\n new RegExp(rule.value as string, (rule as { flags?: string }).flags).test(\n value,\n );\n break;\n case 'email':\n valid = typeof value !== 'string' || EMAIL.test(value);\n break;\n case 'url':\n valid = typeof value !== 'string' || URL.canParse(value);\n break;\n case 'in': {\n const allowed = rule.value as unknown[];\n const values = Array.isArray(value) ? value : [value];\n valid = values.every((item) => allowed.includes(item));\n break;\n }\n case 'accept':\n valid = mediaList(value).every(\n (media) =>\n typeof media.mime !== 'string' ||\n matchesMime(media.mime, rule.value as string[]),\n );\n break;\n case 'maxSize':\n valid = mediaList(value).every(\n (media) =>\n typeof media.size !== 'number' || media.size <= (rule.value as number),\n );\n break;\n case 'before':\n case 'after': {\n const bound = rule.value as string | { field: string };\n const boundTime = toTime(\n typeof bound === 'string' ? bound : getValue(root, bound.field),\n );\n const time = toTime(value);\n if (boundTime !== null && time !== null) {\n valid = rule.rule === 'before' ? time < boundTime : time > boundTime;\n }\n break;\n }\n }\n if (!valid) {\n failures.push(failure(rule));\n }\n });\n return failures;\n}\n\nfunction addFailures(context: Context, path: string, failures: RuleFailure[]) {\n if (failures.length > 0) {\n context.failures[path] = [...(context.failures[path] ?? []), ...failures];\n }\n}\n\nfunction checkFieldValue(field: Field, value: unknown, path: string, context: Context) {\n const rules = field.rules ?? [];\n if (field.localized === true) {\n const localized = isRecord(value) ? value : {};\n const required = rules.filter((rule) => rule.rule === 'required');\n const others = rules.filter((rule) => rule.rule !== 'required');\n if (required.length > 0) {\n const locales = context.locales;\n if (locales === undefined || locales.length === 0) {\n if (!Object.values(localized).some(isFilled)) {\n addFailures(context, path, required.map(failure));\n }\n } else {\n locales.forEach((locale) => {\n addFailures(\n context,\n `${path}.${locale}`,\n checkRules(required, localized[locale], context.root),\n );\n });\n }\n }\n Object.entries(localized).forEach(([locale, localeValue]) => {\n addFailures(\n context,\n `${path}.${locale}`,\n checkRules(others, localeValue, context.root),\n );\n });\n return;\n }\n\n addFailures(context, path, checkRules(rules, value, context.root));\n\n if (field.type === 'group' && field.fields !== undefined && isRecord(value)) {\n checkFields(field.fields, value, `${path}.`, context);\n }\n if (field.type === 'repeater' && Array.isArray(value)) {\n value.forEach((item, index) => {\n if (!isRecord(item)) {\n return;\n }\n const blockFields =\n field.types !== undefined\n ? field.types.find((type) => type.id === item.type)?.fields\n : field.fields;\n if (blockFields !== undefined) {\n checkFields(blockFields, item, `${path}.${index}.`, context);\n }\n });\n }\n}\n\nfunction checkFields(\n fields: Field[],\n values: Record<string, unknown>,\n prefix: string,\n context: Context,\n) {\n fields.forEach((field) => {\n if (field.readOnly === true) {\n return;\n }\n if (context.mode === 'create' && field.updateOnly === true) {\n return;\n }\n if (context.mode === 'update' && field.createOnly === true) {\n return;\n }\n if (field.visibleWhen !== undefined && !evaluateCondition(field.visibleWhen, values)) {\n return;\n }\n if (context.partial === true && prefix === '' && !(field.name in values)) {\n return;\n }\n checkFieldValue(field, values[field.name], `${prefix}${field.name}`, context);\n });\n}\n\n/**\n * Checks form values against the portable rules of their fields. Returns the failures keyed by\n * the dot path of the value (`title.fr`, `blocks.2.image`), the same keys as validation errors.\n * Hidden and read-only fields are skipped. Rules this version doesn't know are ignored.\n */\nexport function checkValues(\n fields: Field[],\n values: Record<string, unknown>,\n options: CheckOptions = {},\n): Record<string, RuleFailure[]> {\n const context: Context = { ...options, root: values, failures: {} };\n checkFields(fields, values, '', context);\n return context.failures;\n}\n"],"mappings":";;;;AAgCA,IAAM,QAAQ;AAEd,SAAS,YAAY,MAAqB;CACtC,OAAQ,eAAqC,SAAS,KAAK,IAAI;AACnE;AAEA,SAAS,QAAQ,MAAyB;CACtC,MAAM,SAAsB,EAAE,MAAM,KAAK,KAAK;CAC9C,IAAI,WAAW,QAAQ,KAAK,UAAU,KAAA,GAClC,OAAO,QAAQ,KAAK;CAExB,IAAI,KAAK,YAAY,KAAA,GACjB,OAAO,UAAU,KAAK;CAE1B,OAAO;AACX;AAEA,SAAS,OAAO,OAA+B;CAC3C,IAAI,OAAO,UAAU,UACjB,OAAO;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B,KAAA,KAAa,CAAC,kBAAkB,MAAM,aAAa,MAAM,GAC/E;EAEJ,IAAI,QAAQ,YAAY,QAAQ,WAAW,MAAM,EAAE,MAAM,QAAQ,SAC7D;EAEJ,gBAAgB,OAAO,OAAO,MAAM,OAAO,GAAG,SAAS,MAAM,QAAQ,OAAO;CAChF,CAAC;AACL;;;;;;AAOA,SAAgB,YACZ,QACA,QACA,UAAwB,CAAC,GACI;CAC7B,MAAM,UAAmB;EAAE,GAAG;EAAS,MAAM;EAAQ,UAAU,CAAC;CAAE;CAClE,YAAY,QAAQ,QAAQ,IAAI,OAAO;CACvC,OAAO,QAAQ;AACnB"}
|
|
1
|
+
{"version":3,"file":"rules.js","names":[],"sources":["../src/rules.ts"],"sourcesContent":["import { evaluateCondition } from './conditions';\nimport { PORTABLE_RULES } from './constants';\nimport type { Field, Rule } from './schemas/field';\nimport { matchesRatio, renderedCropSize } from './transforms';\nimport { getValue, isFilled, isRecord } from './values';\n\n/** A rule that a value doesn't satisfy. */\nexport interface RuleFailure {\n rule: string;\n /** The rule's parameter (`max: 120` gives `120`). */\n value?: unknown;\n /** The message set on the rule, if any. */\n message?: string;\n}\n\nexport interface CheckOptions {\n /**\n * Locales a `required` localized field must be filled in. Without it, one filled locale is\n * enough.\n */\n locales?: string[];\n /** `create` skips `updateOnly` fields; `update` skips `createOnly` fields. */\n mode?: 'create' | 'update';\n /** Only check the fields present in the values (partial updates). */\n partial?: boolean;\n}\n\ninterface Context extends CheckOptions {\n /** The whole form, for `visibleWhen` and date rules that reference other fields. */\n root: Record<string, unknown>;\n failures: Record<string, RuleFailure[]>;\n}\n\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\nfunction isKnownRule(rule: Rule): boolean {\n return (PORTABLE_RULES as readonly string[]).includes(rule.rule);\n}\n\nfunction failure(rule: Rule): RuleFailure {\n const result: RuleFailure = { rule: rule.rule };\n if ('value' in rule && rule.value !== undefined) {\n result.value = rule.value;\n }\n if (rule.message !== undefined) {\n result.message = rule.message;\n }\n return result;\n}\n\nfunction sizeOf(value: unknown): number | null {\n if (typeof value === 'number') {\n return value;\n }\n if (typeof value === 'string' || Array.isArray(value)) {\n return value.length;\n }\n return null;\n}\n\nfunction matchesMime(mime: string, patterns: string[]): boolean {\n return patterns.some((pattern) => {\n if (pattern.endsWith('/*')) {\n return mime.startsWith(pattern.slice(0, -1));\n }\n return mime === pattern;\n });\n}\n\nfunction mediaList(value: unknown): Record<string, unknown>[] {\n const list = Array.isArray(value) ? value : [value];\n return list.filter(isRecord);\n}\n\n/**\n * Whether each image of a value has the crop the `crop` rule asks for (decision 0031): a crop when\n * it is required, and one of the ratios once rendered. An id alone has no crop.\n */\nfunction hasCrop(value: unknown, rule: { ratios?: string[]; required?: boolean }): boolean {\n const entries = Array.isArray(value) ? value : [value];\n return entries.every((entry) => {\n const transform = isRecord(entry) && isRecord(entry.transform) ? entry.transform : {};\n const size = renderedCropSize(transform);\n if (size === null) {\n return rule.required !== true;\n }\n const ratios = rule.ratios ?? [];\n return (\n ratios.length === 0 ||\n ratios.some((ratio) => matchesRatio(size.width, size.height, ratio))\n );\n });\n}\n\nfunction toTime(value: unknown): number | null {\n if (typeof value !== 'string' && typeof value !== 'number') {\n return null;\n }\n const time = new Date(value).getTime();\n return Number.isNaN(time) ? null : time;\n}\n\n/** Checks one value against a field's rules. Returns the rules that fail. */\nexport function checkRules(\n rules: Rule[],\n value: unknown,\n root: Record<string, unknown> = {},\n): RuleFailure[] {\n const failures: RuleFailure[] = [];\n const filled = isFilled(value);\n rules.filter(isKnownRule).forEach((rule) => {\n if (rule.rule === 'required') {\n if (!filled) {\n failures.push(failure(rule));\n }\n return;\n }\n if (!filled) {\n return;\n }\n let valid = true;\n switch (rule.rule) {\n case 'min':\n case 'max': {\n const size = sizeOf(value);\n const limit = rule.value as number;\n valid = size === null || (rule.rule === 'min' ? size >= limit : size <= limit);\n break;\n }\n case 'pattern':\n valid =\n typeof value !== 'string' ||\n new RegExp(rule.value as string, (rule as { flags?: string }).flags).test(\n value,\n );\n break;\n case 'email':\n valid = typeof value !== 'string' || EMAIL.test(value);\n break;\n case 'url':\n valid = typeof value !== 'string' || URL.canParse(value);\n break;\n case 'in': {\n const allowed = rule.value as unknown[];\n const values = Array.isArray(value) ? value : [value];\n valid = values.every((item) => allowed.includes(item));\n break;\n }\n case 'accept':\n valid = mediaList(value).every(\n (media) =>\n typeof media.mime !== 'string' ||\n matchesMime(media.mime, rule.value as string[]),\n );\n break;\n case 'maxSize':\n valid = mediaList(value).every(\n (media) =>\n typeof media.size !== 'number' || media.size <= (rule.value as number),\n );\n break;\n case 'crop':\n valid = !isRecord(rule.value) || hasCrop(value, rule.value);\n break;\n case 'before':\n case 'after': {\n const bound = rule.value as string | { field: string };\n const boundTime = toTime(\n typeof bound === 'string' ? bound : getValue(root, bound.field),\n );\n const time = toTime(value);\n if (boundTime !== null && time !== null) {\n valid = rule.rule === 'before' ? time < boundTime : time > boundTime;\n }\n break;\n }\n }\n if (!valid) {\n failures.push(failure(rule));\n }\n });\n return failures;\n}\n\nfunction addFailures(context: Context, path: string, failures: RuleFailure[]) {\n if (failures.length > 0) {\n context.failures[path] = [...(context.failures[path] ?? []), ...failures];\n }\n}\n\nfunction checkFieldValue(field: Field, value: unknown, path: string, context: Context) {\n const rules = field.rules ?? [];\n if (field.localized === true) {\n const localized = isRecord(value) ? value : {};\n const required = rules.filter((rule) => rule.rule === 'required');\n const others = rules.filter((rule) => rule.rule !== 'required');\n if (required.length > 0) {\n const locales = context.locales;\n if (locales === undefined || locales.length === 0) {\n if (!Object.values(localized).some(isFilled)) {\n addFailures(context, path, required.map(failure));\n }\n } else {\n locales.forEach((locale) => {\n addFailures(\n context,\n `${path}.${locale}`,\n checkRules(required, localized[locale], context.root),\n );\n });\n }\n }\n Object.entries(localized).forEach(([locale, localeValue]) => {\n addFailures(\n context,\n `${path}.${locale}`,\n checkRules(others, localeValue, context.root),\n );\n });\n return;\n }\n\n addFailures(context, path, checkRules(rules, value, context.root));\n\n if (field.type === 'group' && field.fields !== undefined && isRecord(value)) {\n checkFields(field.fields, value, `${path}.`, context);\n }\n if (field.type === 'repeater' && Array.isArray(value)) {\n value.forEach((item, index) => {\n if (!isRecord(item)) {\n return;\n }\n const blockFields =\n field.types !== undefined\n ? field.types.find((type) => type.id === item.type)?.fields\n : field.fields;\n if (blockFields !== undefined) {\n checkFields(blockFields, item, `${path}.${index}.`, context);\n }\n });\n }\n}\n\nfunction checkFields(\n fields: Field[],\n values: Record<string, unknown>,\n prefix: string,\n context: Context,\n) {\n fields.forEach((field) => {\n if (field.readOnly === true) {\n return;\n }\n if (context.mode === 'create' && field.updateOnly === true) {\n return;\n }\n if (context.mode === 'update' && field.createOnly === true) {\n return;\n }\n if (field.visibleWhen !== undefined && !evaluateCondition(field.visibleWhen, values)) {\n return;\n }\n if (context.partial === true && prefix === '' && !(field.name in values)) {\n return;\n }\n checkFieldValue(field, values[field.name], `${prefix}${field.name}`, context);\n });\n}\n\n/**\n * Checks form values against the portable rules of their fields. Returns the failures keyed by\n * the dot path of the value (`title.fr`, `blocks.2.image`), the same keys as validation errors.\n * Hidden and read-only fields are skipped. Rules this version doesn't know are ignored.\n */\nexport function checkValues(\n fields: Field[],\n values: Record<string, unknown>,\n options: CheckOptions = {},\n): Record<string, RuleFailure[]> {\n const context: Context = { ...options, root: values, failures: {} };\n checkFields(fields, values, '', context);\n return context.failures;\n}\n"],"mappings":";;;;;AAiCA,IAAM,QAAQ;AAEd,SAAS,YAAY,MAAqB;CACtC,OAAQ,eAAqC,SAAS,KAAK,IAAI;AACnE;AAEA,SAAS,QAAQ,MAAyB;CACtC,MAAM,SAAsB,EAAE,MAAM,KAAK,KAAK;CAC9C,IAAI,WAAW,QAAQ,KAAK,UAAU,KAAA,GAClC,OAAO,QAAQ,KAAK;CAExB,IAAI,KAAK,YAAY,KAAA,GACjB,OAAO,UAAU,KAAK;CAE1B,OAAO;AACX;AAEA,SAAS,OAAO,OAA+B;CAC3C,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MAAM,SAAS,cAAc,MAAM,QAAQ,KAAK,GAChD,MAAM,SAAS,MAAM,UAAU;EAC3B,IAAI,CAAC,SAAS,IAAI,GACd;EAEJ,MAAM,cACF,MAAM,UAAU,KAAA,IACV,MAAM,MAAM,MAAM,SAAS,KAAK,OAAO,KAAK,IAAI,CAAC,EAAE,SACnD,MAAM;EAChB,IAAI,gBAAgB,KAAA,GAChB,YAAY,aAAa,MAAM,GAAG,KAAK,GAAG,MAAM,IAAI,OAAO;CAEnE,CAAC;AAET;AAEA,SAAS,YACL,QACA,QACA,QACA,SACF;CACE,OAAO,SAAS,UAAU;EACtB,IAAI,MAAM,aAAa,MACnB;EAEJ,IAAI,QAAQ,SAAS,YAAY,MAAM,eAAe,MAClD;EAEJ,IAAI,QAAQ,SAAS,YAAY,MAAM,eAAe,MAClD;EAEJ,IAAI,MAAM,gBAAgB,KAAA,KAAa,CAAC,kBAAkB,MAAM,aAAa,MAAM,GAC/E;EAEJ,IAAI,QAAQ,YAAY,QAAQ,WAAW,MAAM,EAAE,MAAM,QAAQ,SAC7D;EAEJ,gBAAgB,OAAO,OAAO,MAAM,OAAO,GAAG,SAAS,MAAM,QAAQ,OAAO;CAChF,CAAC;AACL;;;;;;AAOA,SAAgB,YACZ,QACA,QACA,UAAwB,CAAC,GACI;CAC7B,MAAM,UAAmB;EAAE,GAAG;EAAS,MAAM;EAAQ,UAAU,CAAC;CAAE;CAClE,YAAY,QAAQ,QAAQ,IAAI,OAAO;CACvC,OAAO,QAAQ;AACnB"}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -2,9 +2,12 @@ export { PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION } from '../version';
|
|
|
2
2
|
export * from '../constants';
|
|
3
3
|
export { type CheckOptions, type RuleFailure, checkRules, checkValues } from '../rules';
|
|
4
4
|
export { evaluateCondition } from '../conditions';
|
|
5
|
+
export { getMediaLibraries, type MediaLibrariesDefinition } from '../libraries';
|
|
6
|
+
export { matchesRatio, parseRatio, renderedCropSize } from '../transforms';
|
|
5
7
|
export { lintDefinition } from '../lint';
|
|
6
8
|
export type { ValidationIssue } from '../validate';
|
|
7
9
|
export { type FilterRange, type FilterValue, type ListQuery, fromSearchParams, isFilterRange, matchesFilterRange, toSearchParams, } from '../query';
|
|
10
|
+
export { type ReadSearchQueryResult, type SearchQuery, type SearchableResource, SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, isSearchableResource, readSearchQuery, toSearchQueryParams, } from '../search';
|
|
8
11
|
export { getValue, isFilled } from '../values';
|
|
9
12
|
export { isProblem } from '../problem';
|
|
10
13
|
export { type PartialTheme, mergeThemes } from '../themes';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACpE,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EACH,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,cAAc,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,KAAK,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACpE,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,KAAK,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EACH,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,cAAc,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EACH,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,mBAAmB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,KAAK,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/runtime/index.js
CHANGED
|
@@ -2,9 +2,12 @@ import { PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION } from "../version.js";
|
|
|
2
2
|
import { BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LIST_LAYOUTS, PORTABLE_RULES } from "../constants.js";
|
|
3
3
|
import { getValue, isFilled } from "../values.js";
|
|
4
4
|
import { evaluateCondition } from "../conditions.js";
|
|
5
|
+
import { matchesRatio, parseRatio, renderedCropSize } from "../transforms.js";
|
|
5
6
|
import { checkRules, checkValues } from "../rules.js";
|
|
7
|
+
import { getMediaLibraries } from "../libraries.js";
|
|
6
8
|
import { lintDefinition } from "../lint.js";
|
|
7
9
|
import { fromSearchParams, isFilterRange, matchesFilterRange, toSearchParams } from "../query.js";
|
|
10
|
+
import { SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, isSearchableResource, readSearchQuery, toSearchQueryParams } from "../search.js";
|
|
8
11
|
import { isProblem } from "../problem.js";
|
|
9
12
|
import { mergeThemes } from "../themes.js";
|
|
10
|
-
export { BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LIST_LAYOUTS, PORTABLE_RULES, PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION, checkRules, checkValues, evaluateCondition, fromSearchParams, getValue, isFilled, isFilterRange, isProblem, lintDefinition, matchesFilterRange, mergeThemes, toSearchParams };
|
|
13
|
+
export { BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LIST_LAYOUTS, PORTABLE_RULES, PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION, SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, checkRules, checkValues, evaluateCondition, fromSearchParams, getMediaLibraries, getValue, isFilled, isFilterRange, isProblem, isSearchableResource, lintDefinition, matchesFilterRange, matchesRatio, mergeThemes, parseRatio, readSearchQuery, renderedCropSize, toSearchParams, toSearchQueryParams };
|
package/dist/schemas/action.d.ts
CHANGED
|
@@ -98,6 +98,13 @@ export declare const Action: z.ZodObject<{
|
|
|
98
98
|
field: z.ZodString;
|
|
99
99
|
}, z.core.$loose>]>;
|
|
100
100
|
message: z.ZodOptional<z.ZodString>;
|
|
101
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
102
|
+
rule: z.ZodLiteral<"crop">;
|
|
103
|
+
value: z.ZodObject<{
|
|
104
|
+
ratios: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
105
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
106
|
+
}, z.core.$loose>;
|
|
107
|
+
message: z.ZodOptional<z.ZodString>;
|
|
101
108
|
}, z.core.$loose>, z.ZodObject<{
|
|
102
109
|
rule: z.ZodString;
|
|
103
110
|
message: z.ZodOptional<z.ZodString>;
|
|
@@ -118,9 +125,18 @@ export declare const Action: z.ZodObject<{
|
|
|
118
125
|
disabled: z.ZodOptional<z.ZodBoolean>;
|
|
119
126
|
}, z.core.$loose>>>;
|
|
120
127
|
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
121
|
-
resource: z.ZodOptional<z.ZodString
|
|
128
|
+
resource: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
122
129
|
accept: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
130
|
+
ratios: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
131
|
+
rotate: z.ZodOptional<z.ZodBoolean>;
|
|
132
|
+
focalPoint: z.ZodOptional<z.ZodBoolean>;
|
|
133
|
+
transformBase: z.ZodOptional<z.ZodEnum<{
|
|
134
|
+
media: "media";
|
|
135
|
+
original: "original";
|
|
136
|
+
choose: "choose";
|
|
137
|
+
}>>;
|
|
123
138
|
from: z.ZodOptional<z.ZodString>;
|
|
139
|
+
check: z.ZodOptional<z.ZodBoolean>;
|
|
124
140
|
display: z.ZodOptional<z.ZodString>;
|
|
125
141
|
fields: z.ZodOptional<z.ZodArray<typeof Field>>;
|
|
126
142
|
types: z.ZodOptional<z.ZodArray<typeof import("./field").BlockType>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../src/schemas/action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,eAAO,MAAM,WAAW;;;;EAA4C,CAAC;AAErE,eAAO,MAAM,eAAe;;;;;EAA6C,CAAC;AAE1E,eAAO,MAAM,aAAa;;;;;mBAWxB,CAAC;AAEH,eAAO,MAAM,MAAM
|
|
1
|
+
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../src/schemas/action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,eAAO,MAAM,WAAW;;;;EAA4C,CAAC;AAErE,eAAO,MAAM,eAAe;;;;;EAA6C,CAAC;AAE1E,eAAO,MAAM,aAAa;;;;;mBAWxB,CAAC;AAEH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+CwE,CAAC;AAE5F,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AACtD,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAC9D,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAC1D,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAC;AAC5C,qEAAqE;AACrE,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAC"}
|
package/dist/schemas/api.d.ts
CHANGED
|
@@ -217,6 +217,11 @@ export declare const MediaTransform: z.ZodObject<{
|
|
|
217
217
|
x: z.ZodNumber;
|
|
218
218
|
y: z.ZodNumber;
|
|
219
219
|
}, z.core.$loose>>;
|
|
220
|
+
base: z.ZodOptional<z.ZodEnum<{
|
|
221
|
+
media: "media";
|
|
222
|
+
original: "original";
|
|
223
|
+
}>>;
|
|
224
|
+
baseTransform: z.ZodOptional<typeof MediaTransform>;
|
|
220
225
|
}, z.core.$loose>;
|
|
221
226
|
export declare const UploadReference: z.ZodObject<{
|
|
222
227
|
upload: z.ZodString;
|
|
@@ -283,6 +288,26 @@ export declare const MediaInfo: z.ZodObject<{
|
|
|
283
288
|
ready: "ready";
|
|
284
289
|
}>>;
|
|
285
290
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
291
|
+
transform: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
292
|
+
crop: z.ZodOptional<z.ZodObject<{
|
|
293
|
+
x: z.ZodNumber;
|
|
294
|
+
y: z.ZodNumber;
|
|
295
|
+
width: z.ZodNumber;
|
|
296
|
+
height: z.ZodNumber;
|
|
297
|
+
}, z.core.$loose>>;
|
|
298
|
+
rotate: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<90>, z.ZodLiteral<180>, z.ZodLiteral<270>]>>;
|
|
299
|
+
flipX: z.ZodOptional<z.ZodBoolean>;
|
|
300
|
+
flipY: z.ZodOptional<z.ZodBoolean>;
|
|
301
|
+
focalPoint: z.ZodOptional<z.ZodObject<{
|
|
302
|
+
x: z.ZodNumber;
|
|
303
|
+
y: z.ZodNumber;
|
|
304
|
+
}, z.core.$loose>>;
|
|
305
|
+
base: z.ZodOptional<z.ZodEnum<{
|
|
306
|
+
media: "media";
|
|
307
|
+
original: "original";
|
|
308
|
+
}>>;
|
|
309
|
+
baseTransform: z.ZodOptional<typeof MediaTransform>;
|
|
310
|
+
}, z.core.$loose>>>;
|
|
286
311
|
}, z.core.$loose>;
|
|
287
312
|
export declare const MediaItem: z.ZodObject<{
|
|
288
313
|
id: z.ZodString;
|
|
@@ -309,10 +334,31 @@ export declare const MediaItem: z.ZodObject<{
|
|
|
309
334
|
ready: "ready";
|
|
310
335
|
}>>;
|
|
311
336
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
337
|
+
transform: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
338
|
+
crop: z.ZodOptional<z.ZodObject<{
|
|
339
|
+
x: z.ZodNumber;
|
|
340
|
+
y: z.ZodNumber;
|
|
341
|
+
width: z.ZodNumber;
|
|
342
|
+
height: z.ZodNumber;
|
|
343
|
+
}, z.core.$loose>>;
|
|
344
|
+
rotate: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<90>, z.ZodLiteral<180>, z.ZodLiteral<270>]>>;
|
|
345
|
+
flipX: z.ZodOptional<z.ZodBoolean>;
|
|
346
|
+
flipY: z.ZodOptional<z.ZodBoolean>;
|
|
347
|
+
focalPoint: z.ZodOptional<z.ZodObject<{
|
|
348
|
+
x: z.ZodNumber;
|
|
349
|
+
y: z.ZodNumber;
|
|
350
|
+
}, z.core.$loose>>;
|
|
351
|
+
base: z.ZodOptional<z.ZodEnum<{
|
|
352
|
+
media: "media";
|
|
353
|
+
original: "original";
|
|
354
|
+
}>>;
|
|
355
|
+
baseTransform: z.ZodOptional<typeof MediaTransform>;
|
|
356
|
+
}, z.core.$loose>>>;
|
|
312
357
|
}, z.core.$loose>;
|
|
313
358
|
}, z.core.$loose>;
|
|
314
359
|
export declare const MediaReference: z.ZodObject<{
|
|
315
360
|
id: z.ZodString;
|
|
361
|
+
resource: z.ZodOptional<z.ZodString>;
|
|
316
362
|
label: z.ZodOptional<z.ZodString>;
|
|
317
363
|
media: z.ZodOptional<z.ZodObject<{
|
|
318
364
|
type: z.ZodString;
|
|
@@ -335,6 +381,26 @@ export declare const MediaReference: z.ZodObject<{
|
|
|
335
381
|
ready: "ready";
|
|
336
382
|
}>>;
|
|
337
383
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
384
|
+
transform: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
385
|
+
crop: z.ZodOptional<z.ZodObject<{
|
|
386
|
+
x: z.ZodNumber;
|
|
387
|
+
y: z.ZodNumber;
|
|
388
|
+
width: z.ZodNumber;
|
|
389
|
+
height: z.ZodNumber;
|
|
390
|
+
}, z.core.$loose>>;
|
|
391
|
+
rotate: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<90>, z.ZodLiteral<180>, z.ZodLiteral<270>]>>;
|
|
392
|
+
flipX: z.ZodOptional<z.ZodBoolean>;
|
|
393
|
+
flipY: z.ZodOptional<z.ZodBoolean>;
|
|
394
|
+
focalPoint: z.ZodOptional<z.ZodObject<{
|
|
395
|
+
x: z.ZodNumber;
|
|
396
|
+
y: z.ZodNumber;
|
|
397
|
+
}, z.core.$loose>>;
|
|
398
|
+
base: z.ZodOptional<z.ZodEnum<{
|
|
399
|
+
media: "media";
|
|
400
|
+
original: "original";
|
|
401
|
+
}>>;
|
|
402
|
+
baseTransform: z.ZodOptional<typeof MediaTransform>;
|
|
403
|
+
}, z.core.$loose>>>;
|
|
338
404
|
}, z.core.$loose>>;
|
|
339
405
|
transform: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
340
406
|
crop: z.ZodOptional<z.ZodObject<{
|
|
@@ -350,8 +416,26 @@ export declare const MediaReference: z.ZodObject<{
|
|
|
350
416
|
x: z.ZodNumber;
|
|
351
417
|
y: z.ZodNumber;
|
|
352
418
|
}, z.core.$loose>>;
|
|
419
|
+
base: z.ZodOptional<z.ZodEnum<{
|
|
420
|
+
media: "media";
|
|
421
|
+
original: "original";
|
|
422
|
+
}>>;
|
|
423
|
+
baseTransform: z.ZodOptional<typeof MediaTransform>;
|
|
353
424
|
}, z.core.$loose>>>;
|
|
354
425
|
}, z.core.$loose>;
|
|
426
|
+
export declare const FieldCheckRequest: z.ZodObject<{
|
|
427
|
+
value: z.ZodString;
|
|
428
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
429
|
+
id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
430
|
+
values: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
431
|
+
}, z.core.$loose>;
|
|
432
|
+
export declare const FieldCheckResponse: z.ZodObject<{
|
|
433
|
+
available: z.ZodBoolean;
|
|
434
|
+
suggestion: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
435
|
+
prefix: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
436
|
+
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
437
|
+
disabled: z.ZodOptional<z.ZodBoolean>;
|
|
438
|
+
}, z.core.$loose>;
|
|
355
439
|
export declare const Session: z.ZodObject<{
|
|
356
440
|
user: z.ZodObject<{
|
|
357
441
|
id: z.ZodString;
|
|
@@ -359,6 +443,7 @@ export declare const Session: z.ZodObject<{
|
|
|
359
443
|
email: z.ZodOptional<z.ZodString>;
|
|
360
444
|
avatarUrl: z.ZodOptional<z.ZodString>;
|
|
361
445
|
abilities: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
|
|
446
|
+
resource: z.ZodOptional<z.ZodString>;
|
|
362
447
|
}, z.core.$loose>;
|
|
363
448
|
}, z.core.$loose>;
|
|
364
449
|
export declare const SearchResponse: z.ZodObject<{
|
|
@@ -394,6 +479,8 @@ export type Upload = z.infer<typeof Upload>;
|
|
|
394
479
|
export type UploadResponse = z.infer<typeof UploadResponse>;
|
|
395
480
|
export type UploadSignRequest = z.infer<typeof UploadSignRequest>;
|
|
396
481
|
export type UploadSignResponse = z.infer<typeof UploadSignResponse>;
|
|
482
|
+
export type FieldCheckRequest = z.infer<typeof FieldCheckRequest>;
|
|
483
|
+
export type FieldCheckResponse = z.infer<typeof FieldCheckResponse>;
|
|
397
484
|
export type MediaInfo = z.infer<typeof MediaInfo>;
|
|
398
485
|
export type MediaItem = z.infer<typeof MediaItem>;
|
|
399
486
|
export type MediaReference = z.infer<typeof MediaReference>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/schemas/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,IAAI;;;;iBAUX,CAAC;AAEP,eAAO,MAAM,UAAU;;;;;iBAKrB,CAAC;AAEH,eAAO,MAAM,YAAY;;;;;;iBAAgC,CAAC;AAE1D,eAAO,MAAM,YAAY;;;;;;;;;;;;iBAA2D,CAAC;AAErF,eAAO,MAAM,OAAO;;;;;;;;;;;;iBAa6E,CAAC;AAElG,eAAO,MAAM,SAAS;;;;;;;;mBAYpB,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;;;;;;;;iBASxB,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;iBAQ3B,CAAC;AAEH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuBvB,CAAC;AAEH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAUpB,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAoC,CAAC;AAEnE,eAAO,MAAM,cAAc
|
|
1
|
+
{"version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Ac,CAAC,CAAC;AAC5D,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,OAAO,CAAC,CAAC;AAC9C,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAC5D,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC"}
|
package/dist/schemas/api.js
CHANGED
|
@@ -102,8 +102,12 @@ var MediaTransform = z.looseObject({
|
|
|
102
102
|
focalPoint: z.looseObject({
|
|
103
103
|
x: z.number().min(0).max(1),
|
|
104
104
|
y: z.number().min(0).max(1)
|
|
105
|
-
}).optional().meta({ description: "From 0 to 1, relative to the width and height of the upright original image, not of the crop: changing the crop does not move it. Renderers map it into the transformed image and clamp it to the crop." })
|
|
106
|
-
|
|
105
|
+
}).optional().meta({ description: "From 0 to 1, relative to the width and height of the upright original image, not of the crop: changing the crop does not move it. Renderers map it into the transformed image and clamp it to the crop." }),
|
|
106
|
+
base: z.enum(["media", "original"]).optional().meta({ description: "What a transform for one use starts from: the original file by default, or the media's own transform (`media`). With `media`, the crop and the focal point are relative to the media's version instead of the original (decision 0031)." }),
|
|
107
|
+
get baseTransform() {
|
|
108
|
+
return MediaTransform.optional().meta({ description: "With `base: \"media\"`: the media's own transform this one was made on. When the media's transform is no longer the same, clients ask to check the crop, and renderers clamp it." });
|
|
109
|
+
}
|
|
110
|
+
}).meta({ description: "Non-destructive edits of an image, applied in this order: crop, then rotate, then flip. Renderers ignore the keys they don't know, which editor tools can add." });
|
|
107
111
|
var UploadReference = z.looseObject({ upload: z.string().min(1) }).meta({ description: "A file uploaded directly to storage, by the id of its upload: in a file value, such as the `file` of a media, or an action parameter." });
|
|
108
112
|
var StoredFile = z.looseObject({
|
|
109
113
|
name: z.string().meta({ description: "The name of the file, as the user knows it." }),
|
|
@@ -158,26 +162,41 @@ var MediaInfo = z.looseObject({
|
|
|
158
162
|
"ready",
|
|
159
163
|
"failed"
|
|
160
164
|
]).optional().meta({ description: "Where the processing of the file is: `pending` and `processing` until its renditions are made, then `ready` or `failed`. Without it, the media is ready." }),
|
|
161
|
-
metadata: z.record(z.string(), z.unknown()).optional()
|
|
165
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
166
|
+
transform: MediaTransform.nullable().optional().meta({ description: "The media's own transform, from its library, which clients need to draw a transform for one use made over it (decision 0031)." })
|
|
162
167
|
}).meta({ description: "What the backend computed about the file of a media item: the `media` of the items of a `media` resource, and of the values of `media` fields. Read-only: the editable properties of a media are the fields of its resource." });
|
|
163
168
|
var MediaItem = Item.extend({ media: MediaInfo }).meta({ description: "An item of a resource of kind `media`: the values of its fields (`file`, the original, and those of the project), and the `media` the backend computed." });
|
|
164
169
|
var MediaReference = z.looseObject({
|
|
165
170
|
id: Id,
|
|
171
|
+
resource: z.string().optional().meta({ description: "The library of the media. Required for a field that allows several libraries, since ids are unique only within their resource (decision 0027)." }),
|
|
166
172
|
label: z.string().optional().meta({ description: "The `itemTitle` of the media." }),
|
|
167
173
|
media: MediaInfo.optional(),
|
|
168
|
-
transform: MediaTransform.nullable().optional().meta({ description: "The edits of the image for this use only, over
|
|
169
|
-
}).meta({ description: "The value of a `media` field in items: the media, with what lists and fields show, and its edits for this use. Requests send the id, or `{ id, transform }
|
|
174
|
+
transform: MediaTransform.nullable().optional().meta({ description: "The edits of the image for this use only: from the original file, or over the media's own transform with `base: \"media\"`." })
|
|
175
|
+
}).meta({ description: "The value of a `media` or `image` field in items: the media, with what lists and fields show, and its edits for this use. Requests send the id, or `{ id, resource, transform }`: `resource` is required when the field allows several libraries." });
|
|
176
|
+
var FieldCheckRequest = z.looseObject({
|
|
177
|
+
value: z.string().meta({ description: "The value to check, as it is typed." }),
|
|
178
|
+
locale: z.string().optional().meta({ description: "The locale of the value, for a localized field." }),
|
|
179
|
+
id: Id.nullable().optional().meta({ description: "The item being edited, or null when creating one." }),
|
|
180
|
+
values: z.record(z.string(), z.unknown()).optional().meta({ description: "The form's current values, as they would be sent to save, for what the check depends on (a page's parent)." })
|
|
181
|
+
}).meta({ description: "A value of a field with `check`, to check with the backend." });
|
|
182
|
+
var FieldCheckResponse = z.looseObject({
|
|
183
|
+
available: z.boolean().meta({ description: "Whether no other item of the resource, in its scope and the same locale, has the value." }),
|
|
184
|
+
suggestion: z.string().nullable().optional().meta({ description: "An available value close to the one checked, when it is taken." }),
|
|
185
|
+
prefix: z.string().nullable().optional().meta({ description: "What the field shows in front of the value: the start of its URL." }),
|
|
186
|
+
url: z.string().nullable().optional().meta({ description: "The URL the value gives the item, which the field links to." }),
|
|
187
|
+
disabled: z.boolean().optional().meta({ description: "The field doesn't apply to this item (the home page has no slug): the field is read-only." })
|
|
188
|
+
}).meta({ description: "What the backend says about a value: not authoritative, since saving still validates it." });
|
|
170
189
|
var Session = z.looseObject({ user: User });
|
|
171
190
|
var SearchResponse = z.looseObject({ data: z.array(z.looseObject({
|
|
172
|
-
resource: z.string(),
|
|
191
|
+
resource: z.string().meta({ description: "The id of the resource." }),
|
|
173
192
|
items: z.array(Item),
|
|
174
|
-
total: z.number().int().nonnegative().optional()
|
|
175
|
-
})) });
|
|
193
|
+
total: z.number().int().nonnegative().optional().meta({ description: "How many items of the resource match, when the backend counts them: the list of the resource, searched, shows them all." })
|
|
194
|
+
})) }).meta({ description: "The results of the global search: the resources with results, in the order of the definition." });
|
|
176
195
|
var PreviewResponse = z.looseObject({
|
|
177
196
|
url: z.string(),
|
|
178
197
|
expiresAt: z.string().optional()
|
|
179
198
|
});
|
|
180
199
|
//#endregion
|
|
181
|
-
export { ActionItemResult, ActionRequest, ActionResult, ActionRun, ActionRunResponse, Item, ItemResponse, ListResponse, MediaInfo, MediaItem, MediaReference, MediaTransform, Pagination, PreviewResponse, Problem, SearchResponse, Selection, Session, StoredFile, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse };
|
|
200
|
+
export { ActionItemResult, ActionRequest, ActionResult, ActionRun, ActionRunResponse, FieldCheckRequest, FieldCheckResponse, Item, ItemResponse, ListResponse, MediaInfo, MediaItem, MediaReference, MediaTransform, Pagination, PreviewResponse, Problem, SearchResponse, Selection, Session, StoredFile, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse };
|
|
182
201
|
|
|
183
202
|
//# sourceMappingURL=api.js.map
|