{"version":3,"file":"define-BScay8x6.mjs","names":["action","serviceAction.notification","linkAction.notification","actionOf","serviceKind.link","serviceKind.action","serviceKind.default_actions","serviceKind.source","specification","serviceKind.specification"],"sources":["../../contract/kinds/service.json","../../contract/fixtures/link-action.json","../../contract/fixtures/service-action.json","../src/kinds/service/samples.ts","../src/kinds/service/input.ts","../src/kinds/service/payload.ts","../src/kinds/service/lifecycle.ts","../src/kinds/service/keys.ts","../src/kinds/service/schema.ts","../src/kinds/service/tracing.ts","../src/kinds/service/specification.ts","../src/kinds/service/define.ts"],"sourcesContent":["","","","/**\n * What tooling offers to run a specification's action with, and tests start\n * from: a fixture of the contract's, as the platform delivers a\n * specification's action (a service's, a link's, or a kind's own), with what\n * names the specification, the link and the action substituted. Each sample\n * is a copy: the fixtures stay as they are.\n */\n\nimport linkAction from \"../../../../contract/fixtures/link-action.json\" with { type: \"json\" };\nimport serviceAction from \"../../../../contract/fixtures/service-action.json\" with { type: \"json\" };\nimport serviceKind from \"../../../../contract/kinds/service.json\" with { type: \"json\" };\nimport { objectOf, type Payload } from \"../../core/payload\";\nimport { textOf } from \"../../core/text\";\nimport type { BoundAction } from \"./specification\";\n\n/** The action a sample is: its slug, which names it, and its type. */\nexport interface SampleAction {\n  slug: string;\n  type: string;\n}\n\n/** A specification's action as the platform delivers it: what names the action's specification and its service's. */\nexport type DeliveredAction = Payload & { specification: Record<string, unknown>; service: { specification: Record<string, unknown> } };\n\n/** The action a sample of `action` asks: a default one of its own type, a custom one of its specification's. */\nexport function sampleActionOf(action: BoundAction): SampleAction {\n  const type = action.isDefault ? action.slug : textOf(objectOf(action.specification).type);\n  return { slug: action.slug, type: type ?? serviceKind.action.type };\n}\n\n/** `delivered` as the action `action` of the specification `slug`: named by its slug, of its type, its specification's slug its own, its service's specification `slug`. */\nexport function specificationSample(delivered: DeliveredAction, slug: string, action: SampleAction): Payload {\n  const sample = structuredClone(delivered);\n  return {\n    ...sample,\n    name: action.slug,\n    slug: action.slug,\n    type: action.type,\n    specification: { ...sample.specification, slug: action.slug },\n    service: { ...sample.service, specification: { ...sample.service.specification, slug } },\n  };\n}\n\n/** A service's action `action` of the specification `slug`. */\nexport function serviceSample(slug: string, action: SampleAction): Payload {\n  return specificationSample(serviceAction.notification, slug, action);\n}\n\n/** A link's action `action` of the link specification `linkSlug`, under the service specification `serviceSlug`. */\nexport function linkSample(serviceSlug: string, linkSlug: string, action: SampleAction): Payload {\n  const sample = specificationSample(linkAction.notification, serviceSlug, action);\n  const link = objectOf(sample.link);\n  return { ...sample, link: { ...link, specification: { ...objectOf(link.specification), slug: linkSlug } } };\n}\n","/**\n * What a specification's action handler gets as its input: the payload's own\n * fields as the platform builds it (infrastructure-service-provisioner\n * `src/services/notificationService.js`, `#buildPayload`): the parameters,\n * the action, the service and its attributes, the link and its attributes on\n * a link's action, the user who asked for it, the package the service is\n * bound to, and the payload's `tags`, `entity_nrn`, `managed` and\n * `trace_context`. Each is as sent, with its id and slug as text; nothing is\n * transformed, so the author's attribute and parameter keys pass through as\n * sent (as the platform rewrites them: `./keys`). The SDK's tools are the\n * handler's context, never its input. A route builds it first of all its\n * middleware but the lifecycle, from the payload it is handed\n * (`serviceInput`), as a body parser does.\n *\n * The parameters are the payload's own wherever a handler reads them: each\n * action's route builds them again right before its handler, after the\n * author's middleware (`payloadParameters`, its guard), so a handler typed by\n * its schemas gets what the platform sent, whatever a middleware passed on.\n */\n\nimport { isJsonObject, objectOf, type Payload } from \"../../core/payload\";\nimport type { Middleware } from \"../../core/run/route\";\nimport { idOf, textOf } from \"../../core/text\";\nimport type { ServicePayload } from \"./payload\";\n\n/** The action a handler answers, as the platform sends it: its id, slug, name, type, status and the action specification it is an instance of. */\nexport interface Action {\n  id: string;\n  slug: string;\n  name: string;\n  /** A default action's type (`create`, `update`, `delete`), else the action specification's, else `custom`. */\n  type: string;\n  status: string;\n  specification: { id: string; slug: string };\n}\n\n/** An entity an action is of (its service, or its link), as the platform sends it, with its attributes. */\nexport interface Entity<Attributes = Record<string, unknown>> extends Record<string, unknown> {\n  id: string;\n  slug: string;\n  /** Its attributes as stored: what its actions' results wrote. */\n  attributes: Attributes;\n}\n\n/** Who asked for the action. */\nexport interface User extends Record<string, unknown> {\n  id: string;\n}\n\n/** The package the service is bound to, as the platform sends it: `{ id, slug, name, revision: { id, version, artifacts: [{ name, type, meta }] } }`, the revision the service runs or is moving to. */\nexport interface BoundPackage extends Record<string, unknown> {\n  id: string;\n  slug: string;\n}\n\n/** What a specification's action handler gets as its input: its parameters typed `Parameters`, its service's attributes `Attributes`. */\nexport interface ServiceInput<Parameters = Record<string, unknown>, Attributes = Record<string, unknown>> {\n  /** The action's parameters. */\n  parameters: Parameters;\n  /** The action, as the platform names it. */\n  action: Action;\n  /** The service the action is of, its attributes the service's. */\n  service: Entity<Attributes>;\n  /** Who asked for the action, when the platform says. */\n  user?: User;\n  /** The package the service is bound to, when it is bound to one. */\n  package?: BoundPackage;\n  /** The payload's tags, as sent, when it carries them. */\n  tags?: Record<string, unknown>;\n  /** The NRN of the entity the action is of, as sent, when the payload carries one. */\n  entity_nrn?: string;\n  /** Whether the platform manages the action, as sent, when the payload says. */\n  managed?: boolean;\n  /** The trace the action continues, as sent, when the payload carries one: the tracing SDK's carrier, `<version>|<trace_id>|<run_id>`. */\n  trace_context?: string;\n}\n\n/** What a link's action handler gets as its input: a specification's action input, with the link the action is of and its attributes `LinkAttributes`. */\nexport interface LinkInput<Parameters = Record<string, unknown>, Attributes = Record<string, unknown>, LinkAttributes = Record<string, unknown>>\n  extends ServiceInput<Parameters, Attributes> {\n  link: Entity<LinkAttributes>;\n}\n\n/** The entity `sent` is, as a handler gets it: its own fields, its id and slug as text, its attributes an object. */\nfunction entityOf(sent: unknown): Entity {\n  const entity = objectOf(sent);\n  return { ...entity, id: idOf(entity.id) ?? \"\", slug: textOf(entity.slug) ?? \"\", attributes: objectOf(entity.attributes) };\n}\n\n/** The action `payload` asks, its fields as text, each empty when it says none. */\nfunction actionOf(payload: ServicePayload): Action {\n  const specification = objectOf(payload.specification);\n  return {\n    id: idOf(payload.id) ?? \"\",\n    slug: textOf(payload.slug) ?? \"\",\n    name: textOf(payload.name) ?? \"\",\n    type: textOf(payload.type) ?? \"\",\n    status: textOf(payload.status) ?? \"\",\n    specification: { id: idOf(specification.id) ?? \"\", slug: textOf(specification.slug) ?? \"\" },\n  };\n}\n\n/** The fields `sent` holds with its id as text, when it is an object; none else. */\nfunction identifiedOf(sent: unknown): Record<string, unknown> & { id: string } {\n  const fields = objectOf(sent);\n  return { ...fields, id: idOf(fields.id) ?? \"\" };\n}\n\n/** The fields the payload holds of the link, of who asked, of the package, its tags, its entity's NRN, whether it is managed and the trace it continues, each only when it is as the field says (an object, the NRN and the carrier text, managed a boolean), so an input has no field the payload does not give. */\nfunction optionalFieldsOf(payload: ServicePayload): Partial<Pick<LinkInput, \"link\" | \"user\" | \"package\" | \"tags\" | \"entity_nrn\" | \"managed\" | \"trace_context\">> {\n  const { package: sentPackage, tags, entity_nrn: entityNrn, managed, trace_context: traceContext } = payload;\n  return {\n    ...(isJsonObject(payload.link) ? { link: entityOf(payload.link) } : {}),\n    ...(isJsonObject(payload.user) ? { user: identifiedOf(payload.user) } : {}),\n    ...(isJsonObject(sentPackage) ? { package: { ...identifiedOf(sentPackage), slug: textOf(sentPackage.slug) ?? \"\" } } : {}),\n    ...(isJsonObject(tags) ? { tags } : {}),\n    ...(typeof entityNrn === \"string\" ? { entity_nrn: entityNrn } : {}),\n    ...(typeof managed === \"boolean\" ? { managed } : {}),\n    ...(typeof traceContext === \"string\" ? { trace_context: traceContext } : {}),\n  };\n}\n\n/** A specification's action input, read from `payload`: the link only on a link's action. */\nexport function serviceInputOf(payload: Payload): ServiceInput & Partial<Pick<LinkInput, \"link\">> {\n  const served = payload as ServicePayload;\n  return { parameters: objectOf(served.parameters), action: actionOf(served), service: entityOf(served.service), ...optionalFieldsOf(served) };\n}\n\n/** Passes on a specification's action input, built from the payload it is handed. */\nexport const serviceInput: Middleware<Payload, ServiceInput> = (payload, context, next) => next(serviceInputOf(payload));\n\n/** The input with its parameters the payload's own, whatever was passed on before: what a handler typed by its schemas reads, a route's guard. */\nexport function payloadParameters<Input extends ServiceInput>(input: Input, payload: Payload): Input {\n  return { ...input, parameters: objectOf((payload as ServicePayload).parameters) };\n}\n","/**\n * What a specification's action says, as the platform sends it: the fields the\n * service reads. Each is optional and read through the base's rules (`textOf`,\n * `idOf`, `objectOf`) and `entityIdOf`, since a payload is the platform's JSON\n * and a field may be absent, null, blank or of another type than it documents.\n */\n\nimport { objectOf, type Payload } from \"../../core/payload\";\nimport { idOf } from \"../../core/text\";\n\n/** The specification an action or an entity is an instance of, as the platform names it. */\nexport interface SpecificationRef {\n  id?: string;\n  slug?: string;\n}\n\n/** An entity an action is of (its service, or its link), as the platform sends it. */\nexport interface PayloadEntity extends Record<string, unknown> {\n  id?: string | number;\n  slug?: string;\n  nrn?: string;\n  /** The entity's own attributes. */\n  attributes?: Record<string, unknown>;\n  /** The specification the entity is an instance of. */\n  specification?: SpecificationRef;\n}\n\n/** The fields of an action's payload the service reads. */\nexport interface ServicePayload extends Payload {\n  /** The action's id: where its lifecycle is reported. */\n  id?: string | number;\n  /** The action's slug. */\n  slug?: string;\n  /** The action's name. */\n  name?: string;\n  /** The action's status: `pending` when it is sent. */\n  status?: string;\n  /** The action's type: a default action's (`create`, `update`, `delete`), or `custom`. */\n  type?: string;\n  /** What the notification is: `service:action:create`. */\n  action?: string;\n  /** The action's specification. */\n  specification?: SpecificationRef;\n  /** The service the action is of. */\n  service?: PayloadEntity | null;\n  /** The link the action is of, on a link's action. */\n  link?: PayloadEntity | null;\n  /** The action's parameters. */\n  parameters?: Record<string, unknown>;\n  /** The entity the action is scoped to. */\n  entity_nrn?: string;\n  /** The schema the platform validates a data action's answer against. */\n  output_schema?: Record<string, unknown>;\n  /** The trace the action continues: the tracing SDK's carrier. */\n  trace_context?: string;\n  /** The event the action is: its kind, and the trace it continues. */\n  event?: { kind?: string; trace?: { trace_id?: string; parent_run_id?: string } };\n  /** Who asked for the action; null when no one did. */\n  user?: { id?: string | number; email?: string } | null;\n  /** The package the service is bound to, absent when it is bound to none. */\n  package?: Record<string, unknown>;\n  /** The action's tags: text, or on a telemetry action numbers for its ids. */\n  tags?: Record<string, unknown>;\n  /** Whether the platform manages the action. */\n  managed?: boolean;\n}\n\n/** The id of the entity `value` is (a service, a link, a user), when it names one. */\nexport function entityIdOf(value: unknown): string | undefined {\n  return idOf(objectOf(value).id);\n}\n\n/** Whether `payload` asks a data action: it carries the schema the platform validates the answer against, so it is answered raw, with no lifecycle. */\nexport function isDataAction(payload: Payload): boolean {\n  const schema = (payload as ServicePayload).output_schema;\n  return schema !== undefined && schema !== null;\n}\n","/**\n * A specification's action lifecycle, reported to the platform around the\n * handler. For a payload with an `id`, at the link's action when the link\n * carries an id, else at the service's:\n *\n * 1. `{\"status\":\"in_progress\"}`; a refusal is a warning, and the action runs.\n * 2. Every line the handler logs from info up (a retried step's warning among\n *    them), as the action's messages (`info`, `warning`, `error`), in the order\n *    logged: one post at a time, the lines logged while one is in flight\n *    together in the next. A debug line is not posted, and a refused post is\n *    told at debug. Every post settles before step 3.\n * 3. On return, `{\"status\":\"success\"}`, with the return as `results` when it\n *    is a plain object. A refusal fails the action with the platform's message.\n * 4. On a throw, or a refused success, `{\"status\":\"failed\"}` with the failure\n *    as an error message, as `failureText` says it; a refusal is a warning.\n *    The throw passes on, so the core answers the failure.\n *\n * A payload that names no action reports nothing, nor does a data action\n * (one with an `output_schema`): it is answered raw, and the platform judges\n * it by what it prints. The lifecycle reports through the platform port\n * itself, bounded by its own timeout and never by the run's cancel signal: a\n * cancelled action, or one the worker stops, is still marked failed. The\n * handler's own `context.api` stays bound to the signal. A log that throws loses\n * its line, never the report.\n */\n\nimport { createApi, type Api, type Resource } from \"../../core/api\";\nimport { failureOf, failureText, messageOf } from \"../../core/errors\";\nimport { written, type Logger } from \"../../core/logger\";\nimport { isJsonObject, type Payload } from \"../../core/payload\";\nimport type { Context } from \"../../core/run/context\";\nimport type { Middleware, Next } from \"../../core/run/route\";\nimport { idOf } from \"../../core/text\";\nimport { entityIdOf, isDataAction, type ServicePayload } from \"./payload\";\n\n/** The level an action's message is posted at. */\nexport type MessageLevel = \"info\" | \"warning\" | \"error\";\n\n/** One of an action's messages, as the platform takes it. */\nexport interface ActionMessage {\n  level: MessageLevel;\n  message: string;\n}\n\n/** A log whose lines are posted too, and that says when every post so far has settled. */\nexport type PostingLog = Logger & { settled(): Promise<void> };\n\n/** The message level each posted log level is posted at. */\nconst MESSAGE_LEVELS: Record<Exclude<keyof Logger, \"debug\">, MessageLevel> = { info: \"info\", warn: \"warning\", error: \"error\" };\n\n/**\n * `log` with each line from info up also posted through `post` at its message\n * level, in the order logged: one post at a time, a line logged while none is\n * in flight at once and the lines logged while one is in flight together in\n * the next, so the platform records them in order and the posts stay as few as\n * its answers allow. A debug line stays on `log`. A post that is refused, or\n * throws, is told on `log` at debug and never stops the ones after it; a log\n * that throws loses the line: a message never fails the action.\n */\nexport function postingLog(log: Logger, post: (messages: ActionMessage[]) => Promise<unknown>): PostingLog {\n  let queued: ActionMessage[] = [];\n  let posting: Promise<void> | undefined;\n  const postedQuietly = async (messages: ActionMessage[]): Promise<void> => {\n    try {\n      await post(messages);\n    } catch (error) {\n      written(() => log.debug(`not posted to the action: ${messageOf(error)}`));\n    }\n  };\n  const drained = async (): Promise<void> => {\n    while (queued.length > 0) {\n      const batch = queued;\n      queued = [];\n      await postedQuietly(batch);\n    }\n    posting = undefined;\n  };\n  const told = (level: Exclude<keyof Logger, \"debug\">) => (message: string): void => {\n    written(() => log[level](message));\n    queued.push({ level: MESSAGE_LEVELS[level], message });\n    posting ??= drained();\n  };\n  return {\n    debug: (message) => written(() => log.debug(message)),\n    info: told(\"info\"),\n    warn: told(\"warn\"),\n    error: told(\"error\"),\n    settled: async () => {\n      await posting;\n    },\n  };\n}\n\n/** What a success reports of the handler's return: the return as `results` when it is a plain object, else nothing. */\nexport function resultsOf(result: unknown): { results?: Record<string, unknown> } {\n  return isJsonObject(result) ? { results: result } : {};\n}\n\n/** The action `payload` is, on `api`: the link's when the link carries an id, else the service's; none without an id of its own, or for a data action. */\nfunction actionOf(payload: Payload, api: Api): Resource | undefined {\n  const served = payload as ServicePayload;\n  const id = idOf(served.id);\n  if (id === undefined || isDataAction(payload)) {\n    return undefined;\n  }\n  const linkId = entityIdOf(served.link);\n  if (linkId !== undefined) {\n    return api.link(linkId).action(id);\n  }\n  const serviceId = entityIdOf(served.service);\n  return serviceId === undefined ? undefined : api.service(serviceId).action(id);\n}\n\n/** Sends `body` to `action`; a refusal is a warning on `log`, `<what>` naming what could not be done. */\nasync function reportedQuietly(action: Resource, body: Record<string, unknown>, log: Logger, what: string): Promise<void> {\n  await action.patch(body).catch((refused: unknown) => written(() => log.warn(`could not mark the action ${what}: ${messageOf(refused)}`)));\n}\n\n/** Runs the inner middleware and the handler with `log`, reporting how they went at `action`. */\nasync function reported(action: Resource, context: Context, log: PostingLog, next: Next): Promise<unknown> {\n  try {\n    const result = await next(undefined, { ...context, log });\n    await log.settled();\n    await action.patch({ status: \"success\", ...resultsOf(result) });\n    return result;\n  } catch (error) {\n    await log.settled();\n    await reportedQuietly(action, { status: \"failed\", messages: [{ level: \"error\", message: failureText(failureOf(error)) }] }, context.log, \"failed\");\n    throw error;\n  }\n}\n\n/** Reports the action's lifecycle around the handler, when the payload it is handed (the first of a route's middleware) names an action, at the run's platform API through its port, unbound from the run's signal. */\nexport const lifecycle: Middleware = async (payload, context, next) => {\n  const action = actionOf(payload, createApi({ fetch: context.api.fetch, credentials: context.credentials }));\n  if (action === undefined) {\n    return next();\n  }\n  await reportedQuietly(action, { status: \"in_progress\" }, context.log, \"in_progress\");\n  const log = postingLog(context.log, (messages) => action.patch({ messages }));\n  return reported(action, context, log, next);\n};\n","/**\n * The keys the platform rewrites. infrastructure-service-provisioner camelCases\n * every key of what it reads from the services API and snake-cases every key of\n * the notification it sends (`src/clients/httpClient.js`, through\n * `@nullplatform/keys-transform-lib-js`, which recurses with no exception), so\n * a key reaches a handler as lodash's `snakeCase(camelCase(key))`, whatever the\n * services API stores. A schema property named otherwise arrives under another\n * name, so it is refused at definition, naming what it would arrive as.\n *\n * The round trip is lodash's word split, ported here for ASCII: apostrophes\n * dropped, then words of letters (an upper-case run before a capitalized word\n * is a word of its own, `URLPath` is `url` and `path`), ordinals (`1st`,\n * `11TH`) and digits (`ipv4` is `ipv` and `4`); anything else separates them.\n * camelCase joins the words lower-cased, each after the first capitalized;\n * snakeCase joins them lower-cased with `_`. A key outside ASCII is refused\n * too: lodash deburrs its letters and splits it by Unicode, which this port\n * does not pin.\n */\n\nimport { isJsonObject, objectOf } from \"../../core/payload\";\n\n/** lodash's word, for ASCII: a capitalized or lower-case word, an upper-case run, an ordinal, or digits; the first alternative that matches at a place wins. */\nconst WORD =\n  /[A-Z]?[a-z]+(?=[^A-Za-z0-9]|[A-Z]|$)|[A-Z]+(?=[^A-Za-z0-9]|[A-Z][a-z]|$)|[A-Z]?[a-z]+|[A-Z]+|\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])|\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])|\\d+/g;\n\n/** What lodash drops from a key before splitting it. */\nconst APOSTROPHE = /'/g;\n\n/** The last code of ASCII. */\nconst ASCII_LAST = 0x7f;\n\n/** The keywords whose value is a schema. */\nconst SCHEMA_KEYWORDS = [\"items\", \"additionalProperties\", \"if\", \"then\", \"else\", \"not\"];\n\n/** The keywords whose value is a list of schemas. */\nconst SCHEMA_LISTS = [\"prefixItems\", \"items\", \"allOf\", \"anyOf\", \"oneOf\"];\n\n/** The keywords whose value maps names to schemas, beside `properties`, whose names are a value's keys. */\nconst SCHEMA_MAPS = [\"$defs\", \"definitions\", \"dependentSchemas\"];\n\n/** The words of `text`, as lodash splits them. */\nfunction wordsOf(text: string): string[] {\n  return text.replace(APOSTROPHE, \"\").match(WORD) ?? [];\n}\n\n/** `word` capitalized: its first letter upper-cased, the rest lower-cased. */\nfunction capitalized(word: string): string {\n  return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();\n}\n\n/** `text` as lodash's camelCase writes it. */\nfunction camelCased(text: string): string {\n  return wordsOf(text)\n    .map((word, index) => (index === 0 ? word.toLowerCase() : capitalized(word)))\n    .join(\"\");\n}\n\n/** `text` as lodash's snakeCase writes it. */\nfunction snakeCased(text: string): string {\n  return wordsOf(text)\n    .map((word) => word.toLowerCase())\n    .join(\"_\");\n}\n\n/** What the ASCII key `key` arrives as: lodash's `snakeCase(camelCase(key))`. */\nexport function arrivalOf(key: string): string {\n  return snakeCased(camelCased(key));\n}\n\n/** Whether `key` is in ASCII. */\nfunction isAscii(key: string): boolean {\n  return Array.from(key).every((character) => character.charCodeAt(0) <= ASCII_LAST);\n}\n\n/** What is wrong with the property `key`: it is outside ASCII, or it arrives as another key. */\nfunction keyProblemOf(key: string): string[] {\n  if (!isAscii(key)) {\n    return [`property \"${key}\" is not ASCII: the platform rewrites it, so name it in ASCII snake_case`];\n  }\n  const arrival = arrivalOf(key);\n  return arrival === key ? [] : [`property \"${key}\" arrives as \"${arrival}\": name it so`];\n}\n\n/** The schemas `schema` holds under its keywords, at its own level. */\nfunction subschemasOf(schema: Record<string, unknown>): unknown[] {\n  return [\n    ...Object.values(objectOf(schema.properties)),\n    ...SCHEMA_KEYWORDS.map((keyword) => schema[keyword]),\n    ...SCHEMA_LISTS.flatMap((keyword) => (Array.isArray(schema[keyword]) ? (schema[keyword] as unknown[]) : [])),\n    ...SCHEMA_MAPS.flatMap((keyword) => Object.values(objectOf(schema[keyword]))),\n  ];\n}\n\n/** What is wrong with the keys `schema` declares, at every depth: each property's key the platform rewrites. */\nfunction keyProblemsIn(schema: unknown): string[] {\n  if (!isJsonObject(schema)) {\n    return [];\n  }\n  return [...Object.keys(objectOf(schema.properties)).flatMap(keyProblemOf), ...subschemasOf(schema).flatMap(keyProblemsIn)];\n}\n\n/** What is wrong with the keys `schema` declares: each property, at every depth of every schema it holds, whose key the platform rewrites, named once. */\nexport function rewrittenKeysOf(schema: unknown): string[] {\n  return [...new Set(keyProblemsIn(schema))];\n}\n","/**\n * The schemas a plugin declares in a specification's body (its attributes, an\n * action's parameters and results): JSON Schema, with the keywords the\n * platform reads in it beside the standard ones. `JSONSchema` is a type to\n * write one with, never a check: a body is published as written. What a\n * schema marks secret is what a trace never carries in clear (`redacted`).\n *\n *   const schema = { type: \"object\", properties: { password: { type: \"string\", secret: true } } } satisfies JSONSchema;\n */\n\nimport { isJsonObject, objectOf } from \"../../core/payload\";\n\n/** The forms of the console a property is shown or edited on. */\nexport type FormRole = \"create\" | \"read\" | \"update\" | \"delete\" | \"list\";\n\n/** A JSON Schema type's name. */\nexport type SchemaType = \"string\" | \"number\" | \"integer\" | \"boolean\" | \"object\" | \"array\" | \"null\";\n\n/** The keywords the platform reads in a JSON Schema, beside the standard ones. */\nexport interface SchemaKeywords {\n  /** Where the property goes among its siblings on a form. */\n  order?: number;\n  /** The forms it is shown on. */\n  visibleOn?: readonly FormRole[];\n  /** The forms it is edited on. */\n  editableOn?: readonly FormRole[];\n  /** Its value is a secret: stored as one, never shown, never traced in clear. */\n  secret?: boolean;\n  /** Two entities are compared by it. */\n  comparable?: boolean;\n  /** It identifies its entity. */\n  identifier?: boolean;\n  /** A value it may take, shown as a hint. */\n  example?: unknown;\n  /** Whether its value is exported to what runs the entity, or how: an environment variable (a secret one with `secret`), a file, a symbolic link. */\n  export?: boolean | { type: \"environment_variable\" | \"file\" | \"symbolic_link\"; target?: string; secret?: boolean };\n  /** Its value is never written by a form. */\n  readOnly?: boolean;\n}\n\n/** JSON Schema as a plugin writes one: the standard keywords, loosely typed, the platform's, and any other the author needs. */\nexport interface JSONSchema extends SchemaKeywords {\n  $schema?: string;\n  $id?: string;\n  $ref?: string;\n  title?: string;\n  description?: string;\n  type?: SchemaType | readonly SchemaType[];\n  $defs?: Record<string, JSONSchema>;\n  definitions?: Record<string, JSONSchema>;\n  properties?: Record<string, JSONSchema>;\n  patternProperties?: Record<string, JSONSchema>;\n  required?: readonly string[];\n  additionalProperties?: boolean | JSONSchema;\n  dependentSchemas?: Record<string, JSONSchema>;\n  prefixItems?: readonly JSONSchema[];\n  items?: JSONSchema | readonly JSONSchema[];\n  enum?: readonly unknown[];\n  const?: unknown;\n  default?: unknown;\n  format?: string;\n  pattern?: string;\n  minimum?: number;\n  maximum?: number;\n  minLength?: number;\n  maxLength?: number;\n  minItems?: number;\n  maxItems?: number;\n  uniqueItems?: boolean;\n  oneOf?: readonly JSONSchema[];\n  anyOf?: readonly JSONSchema[];\n  allOf?: readonly JSONSchema[];\n  not?: JSONSchema;\n  if?: JSONSchema;\n  then?: JSONSchema;\n  else?: JSONSchema;\n  [keyword: string]: unknown;\n}\n\n/** What a secret value is on a trace. */\nconst SECRET = \"[secret]\";\n\n/** The keywords a schema combines others with: a value matches all, any or one of them, so what any of them declares of it may hold. */\nconst COMBINATORS = [\"allOf\", \"anyOf\", \"oneOf\"];\n\n/** The keywords of a schema's conditional: the value is checked against `if`, then against `then` or `else`, so what any of them declares of it may hold. */\nconst CONDITIONALS = [\"if\", \"then\", \"else\"];\n\n/** A schema, as a redaction reads one: an object of keywords. */\ntype Schema = Record<string, unknown>;\n\n/** A schema (anything a keyword holds, which is one when it is an object) and the schema it is written in, the root its local `$ref` points into. */\ninterface Located {\n  schema: unknown;\n  root: Schema;\n}\n\n/** A schema that may declare what a value holds, and the schema it is written in. */\ninterface Branch {\n  schema: Schema;\n  root: Schema;\n}\n\n/** Whether a schema's property is secret: marked so, or exported as a secret. */\nfunction isSecret(property: Schema): boolean {\n  return property.secret === true || objectOf(property.export).secret === true;\n}\n\n/** `value` when it is an array, else none. */\nfunction listOf(value: unknown): unknown[] {\n  return Array.isArray(value) ? value : [];\n}\n\n/** A token of a JSON pointer as written, unescaped: `~1` a slash, `~0` a tilde. */\nfunction unescapedToken(token: string): string {\n  return token.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\");\n}\n\n/** A JSON Pointer's array index: `0`, or a number with no leading zero. */\nconst ARRAY_INDEX = /^(0|[1-9]\\d*)$/;\n\n/** What `node` holds under `token`: an array's item at the index the token writes as JSON Pointer does, an object's own field; none for anything else. */\nfunction childOf(node: unknown, token: string): unknown {\n  if (Array.isArray(node)) {\n    return ARRAY_INDEX.test(token) ? node[Number(token)] : undefined;\n  }\n  return isJsonObject(node) && Object.hasOwn(node, token) ? node[token] : undefined;\n}\n\n/** The fragment of a reference, percent-decoded; none when it is no fragment, or cannot be decoded. */\nfunction fragmentOf(reference: unknown): string | undefined {\n  if (typeof reference !== \"string\" || !reference.startsWith(\"#\")) {\n    return undefined;\n  }\n  try {\n    return decodeURIComponent(reference.slice(1));\n  } catch {\n    return undefined;\n  }\n}\n\n/** What the local `$ref` `reference` points to in `root`, the schema it is written in: the JSON pointer its fragment is, followed token by token; `#` is the root. None for any other reference (another document's, an anchor's) or one that points at nothing. */\nfunction referencedIn(root: Schema, reference: unknown): unknown {\n  const pointer = fragmentOf(reference);\n  if (pointer === \"\") {\n    return root;\n  }\n  if (pointer === undefined || !pointer.startsWith(\"/\")) {\n    return undefined;\n  }\n  return pointer.slice(1).split(\"/\").map(unescapedToken).reduce(childOf, root);\n}\n\n/** The schemas `schema` applies to a value beside itself: those it combines, its conditional's, its dependent schemas, and the one its local `$ref` points to in `root`. */\nfunction appliedBy(schema: Schema, root: Schema): unknown[] {\n  return [\n    ...COMBINATORS.flatMap((keyword) => listOf(schema[keyword])),\n    ...CONDITIONALS.map((keyword) => schema[keyword]),\n    ...Object.values(objectOf(schema.dependentSchemas)),\n    referencedIn(root, schema.$ref),\n  ];\n}\n\n/** `located` when it is a schema, with every schema it applies, at every depth, each once: one `visited` already (a `$ref` cycle, or one another of the same level reached) adds nothing. */\nfunction expanded({ schema, root }: Located, visited: Set<Schema>): Branch[] {\n  if (!isJsonObject(schema) || visited.has(schema)) {\n    return [];\n  }\n  visited.add(schema);\n  return [{ schema, root }, ...appliedBy(schema, root).flatMap((applied) => expanded({ schema: applied, root }, visited))];\n}\n\n/**\n * Each of `located` with every schema it applies, at every depth: each branch\n * that may declare what a value holds, each once per schema it is written in,\n * so a level holds each distinct schema once however many branches reach it,\n * and the walk stays linear in the value's depth.\n */\nfunction branchesOf(located: Located[]): Branch[] {\n  const visited = new Map<Schema, Set<Schema>>();\n  return located.flatMap((each) => {\n    const seen = visited.get(each.root) ?? new Set<Schema>();\n    visited.set(each.root, seen);\n    return expanded(each, seen);\n  });\n}\n\n/** Whether `key` matches the pattern `source`, a regular expression as JSON Schema writes one; a pattern that is none matches nothing. */\nfunction matchesPattern(source: string, key: string): boolean {\n  try {\n    return new RegExp(source, \"u\").test(key);\n  } catch {\n    return false;\n  }\n}\n\n/** What `schema` declares for an object's property `key`: its own in `properties`, and each of `patternProperties` whose pattern `key` matches; else, when neither declares it, `additionalProperties`. */\nfunction declaredFor(schema: Schema, key: string): unknown[] {\n  const properties = objectOf(schema.properties);\n  const named = Object.hasOwn(properties, key) ? [properties[key]] : [];\n  const patterned = Object.entries(objectOf(schema.patternProperties)).filter(([pattern]) => matchesPattern(pattern, key));\n  const declared = [...named, ...patterned.map(([, property]) => property)];\n  return declared.length > 0 ? declared : [schema.additionalProperties];\n}\n\n/** The schemas `branches` declare for an object's property `key`, each where its branch is written. */\nfunction propertySchemasOf(branches: Branch[], key: string): Located[] {\n  return branches.flatMap(({ schema, root }) => declaredFor(schema, key).map((declared) => ({ schema: declared, root })));\n}\n\n/** The schema `schema` declares for an array's item at `index`: its `prefixItems` at that place, else its `items`, one for every item or one per place. */\nfunction itemSchemaOf(schema: Schema, index: number): unknown {\n  const prefix = listOf(schema.prefixItems);\n  if (index < prefix.length) {\n    return prefix[index];\n  }\n  return Array.isArray(schema.items) ? schema.items[index] : schema.items;\n}\n\n/** The schema each of `branches` declares for an array's item at `index`, each where its branch is written. */\nfunction itemSchemasOf(branches: Branch[], index: number): Located[] {\n  return branches.map(({ schema, root }) => ({ schema: itemSchemaOf(schema, index), root }));\n}\n\n/** A property or an item as a trace carries it: `[secret]` when a branch of a schema it is declared by marks it secret, else redacted by them. */\nfunction redactedField(field: unknown, located: Located[]): unknown {\n  const branches = branchesOf(located);\n  return branches.some(({ schema }) => isSecret(schema)) ? SECRET : redactedBy(field, branches);\n}\n\n/** `value` redacted by `branches`, each a schema that may declare what it holds. */\nfunction redactedBy(value: unknown, branches: Branch[]): unknown {\n  if (branches.length === 0) {\n    return value;\n  }\n  if (Array.isArray(value)) {\n    return value.map((item, index) => redactedField(item, itemSchemasOf(branches, index)));\n  }\n  if (!isJsonObject(value)) {\n    return value;\n  }\n  return Object.fromEntries(Object.entries(value).map(([key, field]) => [key, redactedField(field, propertySchemasOf(branches, key))]));\n}\n\n/**\n * `value`, JSON (the payload's parameters, a handler's return as JSON carries\n * it), as a trace carries it: each property any of `schemas` marks secret\n * (`secret`, or `export.secret`) is `[secret]`, at every depth they declare,\n * everything else as it is. A property is declared by an object's\n * `properties`, each `patternProperties` whose pattern it matches, else\n * `additionalProperties`; an item by an array's `prefixItems` at its place,\n * else its `items`, one schema for every item or one per place. Each schema\n * applies every one it combines (`allOf`, `anyOf`, `oneOf`), its conditional's\n * (`if`, `then`, `else`), its `dependentSchemas` and the one its local `$ref`\n * points to (a JSON pointer into the schema it is written in, as\n * `#/$defs/<name>`), at every depth, each once, so a cycle ends; a property is\n * secret when any of them that declares it says so. A reference to another\n * document, or by an anchor, declares nothing. An object is one as the trace\n * adapter reads one (`isJsonObject`). `value` is never changed: what is\n * redacted is a copy.\n */\nexport function redacted(value: unknown, schemas: unknown[]): unknown {\n  return redactedBy(value, branchesOf(schemas.map((schema) => ({ schema, root: objectOf(schema) }))));\n}\n","/**\n * A specification's action traced: the run described from the payload as the\n * platform sends it, which the core opens before the route's middleware, every\n * step of the handler traced and the run's narrative its `context.trace`, and\n * ends with how the action was answered (`Route.describe`).\n *\n * The run is scoped to the NRN the kind says, else the most specific one a\n * service's action carries (the link's, the service's, the payload's own; the\n * NRN carries the rest of the hierarchy), continues the trace the payload's\n * event names or its `trace_context` carries, and is labelled with the\n * package, the action, the service's and the link's ids, the service's slug\n * and the action's id; what the kind says the action is about fills only the\n * labels still undefined. Its actor is the user who asked, by id; its input\n * the parameters, and its results what the handler returned, each with what\n * its schemas mark secret redacted (`redacted`): the answer itself keeps every\n * value. An action with a plan is an instance of its job: the package's slug,\n * `<resource>.<action>`, the package's version. A kind built on the service\n * reads its own entities through `nrnOf` and `about`. Every field is read as\n * text (`textOf`), an id as `idOf` reads it.\n *\n * Tracing never fails an action: a run that cannot be described is not\n * traced, with a warning (the core's, `runOf`).\n */\n\nimport type { Package } from \"../../core/package\";\nimport { objectOf, type Payload } from \"../../core/payload\";\nimport type { Plan } from \"../../core/tracing/plan\";\nimport type { RunDescription, RunSpec } from \"../../core/tracing/port\";\nimport { humanize, parseCarrier } from \"../../core/tracing/sdk\";\nimport { asJson, idOf, textOf } from \"../../core/text\";\nimport { entityIdOf, type ServicePayload } from \"./payload\";\nimport { redacted } from \"./schema\";\n\n/** The schemas that mark what is secret in an action's parameters and in its results: what its trace redacts. */\nexport interface SecretSchemas {\n  parameters: unknown[];\n  results: unknown[];\n}\n\n/** What the trace names an action's run with: whose it is, what it is, and what it declared. */\nexport interface ActionTrace {\n  /** The package the action belongs to: the run's producer, and its job's namespace and version. */\n  package: Package;\n  /** What the action is of (`service`, `link`, or a kind's own): the run's `entity`, unless the payload's event names its kind. */\n  kind: string;\n  /** The action's slug. */\n  action: string;\n  /** The slug of the specification, or the link, the action is of: with the action, its job's name. */\n  resource: string;\n  /** The run's name on screen; the action's slug, made readable, unless given. */\n  title?: string;\n  /** What the action does. */\n  description?: string;\n  /** The steps the action is expected to run: with one, the run is an instance of its job. */\n  plan?: Plan;\n  /** What the run's input parameters and its traced results are redacted by; nothing unless given. */\n  secretSchemas?: SecretSchemas;\n  /** What the kind says the action is about beyond a service's entities, as labels (`<entity>.id`). */\n  about?: (payload: Payload) => Record<string, string | undefined>;\n  /** The NRN the kind scopes the run to; a service's action's (`serviceNrnOf`) unless given. */\n  nrnOf?: (payload: Payload) => string | undefined;\n}\n\n/** The NRN of the most specific entity a service's action carries: the link's, the service's, the payload's own. */\nexport function serviceNrnOf(payload: Payload): string | undefined {\n  const [link, service] = [payload.link, payload.service].map(objectOf);\n  const candidates = [link.nrn, service.entity_nrn, service.nrn, payload.entity_nrn, payload.nrn];\n  return candidates.map(textOf).find((nrn) => nrn !== undefined);\n}\n\n/** The trace the payload's event names it a run of, when it names one. */\nfunction eventTraceOf(payload: ServicePayload): { traceId: string; parentRunId?: string } | undefined {\n  const trace = objectOf(objectOf(payload.event).trace);\n  const traceId = textOf(trace.trace_id);\n  return traceId === undefined ? undefined : { traceId, parentRunId: textOf(trace.parent_run_id) };\n}\n\n/** The trace the action continues: the one its event names, else the one its `trace_context` carries. */\nfunction carrierOf(payload: ServicePayload): { traceId: string; parentRunId?: string } | undefined {\n  const carried = payload.trace_context;\n  return eventTraceOf(payload) ?? (typeof carried === \"string\" ? parseCarrier(carried) : undefined);\n}\n\n/** The run's labels: what it is, whose, the service's and the link's ids, the service's slug and the action's id; what the kind says the action is about fills only those still undefined. */\nfunction labelsOf(payload: ServicePayload, actionTrace: ActionTrace, actionId: string | undefined): Record<string, string | undefined> {\n  const labels: Record<string, string | undefined> = {\n    entity: textOf(objectOf(payload.event).kind) ?? actionTrace.kind,\n    action: actionTrace.action,\n    \"package.slug\": actionTrace.package.slug,\n    \"package.version\": actionTrace.package.version,\n    \"service.id\": entityIdOf(payload.service),\n    \"link.id\": entityIdOf(payload.link),\n    \"service.slug\": textOf(objectOf(payload.service).slug),\n    \"action.id\": actionId,\n  };\n  for (const [name, value] of Object.entries(actionTrace.about?.(payload) ?? {})) {\n    labels[name] ??= value;\n  }\n  return labels;\n}\n\n/** The user who asked for the action, by id only, never by email. */\nfunction actorOf(payload: ServicePayload): RunSpec[\"actor\"] {\n  const id = entityIdOf(payload.user);\n  return id === undefined ? undefined : { kind: \"user\", id };\n}\n\n/** The action's parameters as the run's input, a copy with what `schemas` mark secret redacted; none when it carries none. */\nfunction inputOf(payload: ServicePayload, schemas: unknown[]): RunSpec[\"input\"] {\n  const parameters = { ...objectOf(payload.parameters) };\n  return Object.keys(parameters).length === 0 ? undefined : { parameters: redacted(parameters, schemas) as Record<string, unknown> };\n}\n\n/** The job an action with a plan is an instance of: the package's slug, `<resource>.<action>`, the package's version. */\nfunction jobOf(actionTrace: ActionTrace): RunSpec[\"job\"] {\n  if (actionTrace.plan === undefined) {\n    return undefined;\n  }\n  return { namespace: actionTrace.package.slug, name: `${actionTrace.resource}.${actionTrace.action}`, version: actionTrace.package.version };\n}\n\n/** The run `actionTrace` is for `payload`: its run id the action's, `action-<id>`, or of the moment when it has none. */\nfunction runSpecOf(payload: Payload, actionTrace: ActionTrace): RunSpec {\n  const served = payload as ServicePayload;\n  const actionId = idOf(served.id);\n  const carrier = carrierOf(served);\n  return {\n    producer: actionTrace.package.slug,\n    nrn: (actionTrace.nrnOf ?? serviceNrnOf)(payload),\n    runId: `action-${actionId ?? Date.now()}`,\n    traceId: carrier?.traceId,\n    parentRunId: carrier?.parentRunId,\n    title: actionTrace.title ?? humanize(actionTrace.action),\n    description: actionTrace.description,\n    plan: actionTrace.plan,\n    job: jobOf(actionTrace),\n    labels: labelsOf(served, actionTrace, actionId),\n    actor: actorOf(served),\n    input: inputOf(served, actionTrace.secretSchemas?.parameters ?? []),\n  };\n}\n\n/** What the run traces of the handler's return: its JSON form, as the answer prints it, what `schemas` mark secret redacted; nothing when JSON cannot write it. */\nfunction tracedResultOf(result: unknown, schemas: unknown[]): unknown {\n  try {\n    return redacted(asJson(result), schemas);\n  } catch {\n    return undefined;\n  }\n}\n\n/** How a specification's action is traced, as `actionTrace` names it: the run described from the payload, and its result on the trace its JSON form, what its schemas mark secret redacted. The core opens the run before the route's middleware, and ends it with the answer (`Route.describe`). */\nexport function specificationTracing(actionTrace: ActionTrace): (payload: Payload) => RunDescription {\n  const resultSchemas = actionTrace.secretSchemas?.results ?? [];\n  return (payload) => ({ run: runSpecOf(payload, actionTrace), result: (data) => tracedResultOf(data, resultSchemas) });\n}\n","/**\n * The specification model every specification's sugar builds on (a\n * service's, its links', a scope's): a specification published as its\n * component, its actions bound by their keys and published under it, and the\n * routes that answer them.\n *\n * Keys are names (contract/README.md): the platform derives a specification's\n * slug, and an action specification's, from its `name` once and never\n * changes it, so each is published named by the key its author wrote (a\n * specification by its slug), and a body that names itself otherwise, or a\n * key that is not a slug, is refused at definition; a key the kind defines\n * is the platform's own name. A body goes as its author wrote it, in the\n * API's own case, with the contract's defaults beneath it however deep\n * (contract/kinds/service.json). Its attributes, their schema and its\n * properties are objects when given, for a kind reads them, and none of their\n * keys, nor of a custom action's parameters and results, is one the platform\n * rewrites (`./keys`). Each part is checked (`Checked`) so that a definition\n * names every problem at once; the refusing forms throw them.\n *\n * An action is matched by the specification it is of (its link's when it\n * carries a link, whatever its service's says, else its service's) and by\n * what names it: a default action by its `type`, a custom one by its\n * `specification.slug`. Its route describes its run, which the core opens\n * before its middleware, so what tracing warns never becomes an action's\n * message; then its lifecycle is reported around its input, built from the\n * payload (the service's, or a kind's own) and checked, so what an input\n * refuses is reported failed; then its guard, right before its handler. A data action prints raw. The last route of\n * each specification fails any other action of it, UNKNOWN_ACTION, inside\n * its lifecycle, so the platform hears it.\n */\n\nimport serviceKind from \"../../../../contract/kinds/service.json\" with { type: \"json\" };\nimport { component, ref, type Component } from \"../../core/component\";\nimport { ActionError, refusalText, refuseProblems } from \"../../core/errors\";\nimport { merged } from \"../../core/merge\";\nimport { isSlug, type Package } from \"../../core/package\";\nimport { isJsonObject, objectOf, type Payload } from \"../../core/payload\";\nimport type { Context, Output } from \"../../core/run/context\";\nimport type { Guard, Handler, Middleware, Route } from \"../../core/run/route\";\nimport { textOf } from \"../../core/text\";\nimport { planProblems, type Plan } from \"../../core/tracing/plan\";\nimport { payloadParameters, serviceInput } from \"./input\";\nimport { lifecycle } from \"./lifecycle\";\nimport { rewrittenKeysOf } from \"./keys\";\nimport { isDataAction, type ServicePayload } from \"./payload\";\nimport { specificationTracing, type ActionTrace, type SecretSchemas } from \"./tracing\";\n\n/** An action's handler: a function of the input its route's middleware builds, and of the run's context. */\nexport type ActionHandler<Input> = (input: Input, context: Context) => unknown;\n\n/** An action as its author declares it beside its handler: what the trace tells of it, and a custom one's specification. */\nexport interface ActionDeclaration<Input> {\n  handler: ActionHandler<Input>;\n  /** The run's name on the trace; the action's key, made readable, unless given. Never published. */\n  title?: string;\n  /** What the action does: the run's narrative until the handler says more. Never published. */\n  description?: string;\n  /** The steps the action is expected to run, as the trace's job declares them; `context.trace.step` names them by key. Never published. */\n  plan?: Plan;\n  /** A custom action's action_specification body, as the API takes it; a default action's is the platform's own. */\n  specification?: Record<string, unknown>;\n}\n\n/** What a definition gives under `actions`, by key, each entry as its author wrote it, typed by its kind: one that is no entry (left undefined among them) is refused at definition. */\nexport type DeclaredActions = Readonly<Record<string, unknown>>;\n\n/** An action bound to its specification: what its route answers with, what it publishes, what it tells the trace. */\nexport interface BoundAction {\n  /** Its key: its slug, and its specification's name. */\n  slug: string;\n  /** Its author's handler, of the input its route's middleware builds. */\n  handler: ActionHandler<never>;\n  /** Whether it is one of the platform's default actions, found by its type. */\n  isDefault: boolean;\n  /** A custom action's action_specification body, as published. */\n  specification?: Record<string, unknown>;\n  /** What the trace tells of it. */\n  trace: Pick<ActionTrace, \"title\" | \"description\" | \"plan\"> & { secretSchemas: SecretSchemas };\n}\n\n/** How a specification's actions are bound. */\nexport interface BindRules {\n  /** Whether the specification uses the platform's default actions. */\n  usesDefaults: boolean;\n  /** The platform's default actions, by the key each is bound to: a specification that uses them binds each, and none takes a specification. */\n  defaultActions: readonly string[];\n  /** The kind's definition of an action, beneath its author's specification: an action it defines may be a bare handler, and its key is the platform's own name, a slug or not. */\n  definitionOf?: (slug: string) => Record<string, unknown> | undefined;\n  /** The specification's attributes schema: what it marks secret is redacted in every action's trace, in its parameters and its results. */\n  attributesSchema?: unknown;\n  /** Why an action that gives no specification, and that the kind does not define, cannot be bound, in the kind's words; the service's (`unspecified`) unless given. */\n  unspecifiedOf?: (slug: string) => string;\n}\n\n/** What a specification's action route is built from. */\nexport interface ActionRouteOptions {\n  name: string;\n  match: (payload: Payload) => boolean;\n  action: BoundAction;\n  /** Around the handler, outermost first. */\n  use: Middleware[];\n  /** How the answer prints; a data action raw, any other the envelope, unless given. */\n  output?: Route[\"output\"];\n  /** The run it is traced as: none unless given. */\n  describe?: Route[\"describe\"];\n  /** What its handler gets of what its middleware passed on: as passed unless given. */\n  guard?: Guard;\n  channel: Route[\"channel\"];\n  sample: Payload;\n}\n\n/** What a specification's action is traced with: whose it is, what it is of, and what the kind says of it beyond what its author declares. */\nexport interface TracedActionOptions {\n  /** The package the action belongs to. */\n  package: Package;\n  /** What the action is of, as its trace calls it: `service`, `link`, or a kind's own. */\n  kind: string;\n  /** The slug of the specification the action is of: what its payload names it by, and its job's resource. */\n  slug: string;\n  action: BoundAction;\n  /** What the kind says: the title of an action its author leaves untitled, the NRN its run is scoped to, and what it is about. */\n  trace?: Pick<ActionTrace, \"title\" | \"nrnOf\" | \"about\">;\n}\n\n/** What a specification's action route is built from, beside how it is traced. */\nexport interface SpecificationRouteOptions extends TracedActionOptions {\n  name: string;\n  /** What builds the handler's input from the payload it is handed: the service's (`serviceInput`) unless given, a kind's own. */\n  inputBuilder?: Middleware;\n  /** What checks the input or adds to it after, before the author's middleware: a kind's own; none unless given. */\n  inputChecks?: Middleware[];\n  /** What the handler gets of what the author's middleware passed on, right before it: the input with the payload's own parameters (`payloadParameters`) unless given, a kind's own. */\n  guard?: Guard;\n  /** What the package's channel lets through for it; the specification's unless given. */\n  channel?: NonNullable<Route[\"channel\"]>;\n  sample: Payload;\n}\n\n/** What was built, and what is wrong with what it was built from: a definition with a problem is refused once every part of it is checked. */\nexport interface Checked<Value> {\n  value: Value;\n  problems: string[];\n}\n\n/** What binding one action gives: the action bound, unless it cannot be, and what is wrong with it. */\ninterface Binding {\n  bound?: BoundAction;\n  problems: string[];\n}\n\n/** The API's entity names of what a specification publishes. */\nconst SPECIFICATION_KIND = \"service_specification\";\nconst LINK_KIND = \"link_specification\";\nconst ACTION_KIND = \"action_specification\";\n\n/** Where a link is created and listed, and what its body is over beside its parent. */\nconst { path: linkPath, list: linkList, ...linkDefaults } = serviceKind.link;\n\n/** What an action's entry may declare beside its handler, and the entry as a refusal names it. */\nconst DECLARED = [\"title\", \"description\", \"plan\", \"specification\"];\nconst ENTRY_FIELDS = [\"handler\", ...DECLARED];\nconst DECLARATION = `{ handler, ${DECLARED.map((field) => `${field}?`).join(\", \")} }`;\nconst ENTRY = `a handler function or ${DECLARATION}`;\n\n/** The problem of a body that names itself other than `name`, what it is published as (its slug, its key); none when it names itself so, or not at all. */\nfunction misnamed(body: Record<string, unknown>, name: string, publishedAs: \"slug\" | \"key\"): string[] {\n  return body.name === undefined || body.name === name ? [] : [`specification name \"${String(body.name)}\" must be its ${publishedAs} \"${name}\"`];\n}\n\n/** `problems` as one refusal names them (`refusalText`), `where` naming what they are of; none when there are none. */\nexport function refusalsOf(where: string, problems: string[]): string[] {\n  return problems.length === 0 ? [] : [refusalText(problems, where)];\n}\n\n/** What `checked` built, refused, `where` naming it, when anything is wrong with it. */\nfunction refusedUnless<Value>(where: string, checked: Checked<Value>): Value {\n  refuseProblems(checked.problems, where);\n  return checked.value;\n}\n\n/** What is wrong with the attributes `body` gives: each level of them, down to their schema's properties, that is given and is no object. */\nexport function attributesProblemsOf(body: Record<string, unknown>): string[] {\n  const attributes = body.attributes;\n  const schema = objectOf(attributes).schema;\n  const properties = objectOf(schema).properties;\n  const levels: [unknown, string][] = [\n    [attributes, \"attributes\"],\n    [schema, \"attributes.schema\"],\n    [properties, \"attributes.schema.properties\"],\n  ];\n  return levels.filter(([level]) => level !== undefined && !isJsonObject(level)).map(([, path]) => `specification ${path} must be an object`);\n}\n\n/** The properties of the attributes `body` declares: its schema's; none when it declares none. */\nexport function attributesPropertiesOf(body: unknown): Record<string, unknown> {\n  return objectOf(objectOf(objectOf(objectOf(body).attributes).schema).properties);\n}\n\n/** `body` over `defaults`, however deep, named `name` whatever it says, its name first so describe reads well: what a published body with a name is. */\nexport function namedBody(name: string, defaults: Record<string, unknown>, body: Record<string, unknown>): Record<string, unknown> {\n  const named = merged({ name, ...defaults }, body);\n  named.name = name;\n  return named;\n}\n\n/** The body of the specification `slug` as published: its author's over `defaults`, named by its slug whatever it says; what is wrong with it: its name, its attributes, a key of theirs the platform rewrites. */\nfunction checkedBody(slug: string, body: unknown, defaults: Record<string, unknown>): Checked<Record<string, unknown>> {\n  const problems = isJsonObject(body)\n    ? [...misnamed(body, slug, \"slug\"), ...attributesProblemsOf(body), ...rewrittenKeysOf(objectOf(body.attributes).schema)]\n    : [\"specification must be an object: its body as the API takes it\"];\n  return { value: namedBody(slug, defaults, objectOf(body)), problems };\n}\n\n/** The specification `slug`, a `service_specification` named by it, its body as written over `defaults`; and what is wrong with its body. */\nexport function checkedSpecification(slug: string, body: unknown, defaults: Record<string, unknown>): Checked<Component> {\n  const checked = checkedBody(slug, body, defaults);\n  return { value: component(SPECIFICATION_KIND, slug, checked.value), problems: checked.problems };\n}\n\n/** The specification `slug`, a `service_specification` named by it, its body as written over `defaults`; refused, naming it, when its body is not what it must be. */\nexport function specificationComponent(slug: string, body: Record<string, unknown>, defaults: Record<string, unknown>): Component {\n  return refusedUnless(slug, checkedSpecification(slug, body, defaults));\n}\n\n/** The link `slug` of the specification `parent`, a `link_specification` under it at the link's path and list, its body as written over the link's defaults and naming its parent; and what is wrong with its body. */\nexport function checkedLink(parent: Component, slug: string, body: unknown): Checked<Component> {\n  const checked = checkedBody(slug, body, { ...linkDefaults, specification_id: ref(parent) });\n  return { value: component(LINK_KIND, slug, checked.value, { parent, path: linkPath, list: linkList }), problems: checked.problems };\n}\n\n/** Whether the specification `declared` uses the platform's default actions: its body says true. */\nexport function usesDefaultActions(declared: Component): boolean {\n  return declared.body.use_default_actions === true;\n}\n\n/** The schema of the specification `declared`'s attributes, as its body gives it. */\nexport function attributesSchemaOf(declared: Component): unknown {\n  return objectOf(declared.body.attributes).schema;\n}\n\n/** What the trace tells of an action: what its author declares of it, and what its parameters and its results are redacted by. */\nfunction actionTraceOf(declaration: ActionDeclaration<never>, secretSchemas: SecretSchemas): BoundAction[\"trace\"] {\n  return { title: declaration.title, description: declaration.description, plan: declaration.plan, secretSchemas };\n}\n\n/** What an action's parameters and results are redacted by: the attributes schema, and beside it the schema of each that `specification` declares. */\nfunction secretSchemasOf(attributesSchema: unknown, specification: Record<string, unknown> = {}): SecretSchemas {\n  const schemasOf = (part: string) => [attributesSchema, objectOf(specification[part]).schema].filter(isJsonObject);\n  return { parameters: schemasOf(\"parameters\"), results: schemasOf(\"results\") };\n}\n\n/** What is wrong with an action's plan, as the tracing SDK would refuse it. */\nfunction planProblemsOf(slug: string, plan: unknown): string[] {\n  if (plan === undefined) {\n    return [];\n  }\n  if (!isJsonObject(plan)) {\n    return [`\"${slug}\" plan must be { steps, groups? }`];\n  }\n  return planProblems(plan as unknown as Plan).map((problem) => `\"${slug}\" plan: ${problem}`);\n}\n\n/** What is wrong with what an action's entry declares: a field an action does not take, a plan the trace would refuse, a specification that is no body. */\nfunction declarationProblemsOf(slug: string, declared: Record<string, unknown>): string[] {\n  const foreign = Object.keys(declared).filter((field) => !ENTRY_FIELDS.includes(field));\n  const specification = declared.specification;\n  return [\n    ...(foreign.length === 0 ? [] : [`\"${slug}\" takes ${DECLARATION}, not ${foreign.map((field) => `\"${field}\"`).join(\", \")}`]),\n    ...planProblemsOf(slug, declared.plan),\n    ...(specification === undefined || isJsonObject(specification) ? [] : [`\"${slug}\": specification must be an object: its action_specification body`]),\n  ];\n}\n\n/** A default action: what its trace tells, the attributes' secrets redacted; its specification is the platform's own. */\nfunction defaultBinding(slug: string, declaration: ActionDeclaration<never>, rules: BindRules): Binding {\n  const bound: BoundAction = { slug, handler: declaration.handler, isDefault: true, trace: actionTraceOf(declaration, secretSchemasOf(rules.attributesSchema)) };\n  return { bound, problems: declaration.specification === undefined ? [] : [`\"${slug}\" is a default action: the platform owns its specification`] };\n}\n\n/** Why an action that gives no specification and has no definition cannot be bound, as the service says it: it is no default action, though its key may name one the specification does not use. */\nfunction unspecified(slug: string, rules: BindRules): string {\n  const unused = rules.defaultActions.includes(slug) ? \" (the specification does not use them)\" : \"\";\n  return `\"${slug}\" is not a default action${unused}: give its specification`;\n}\n\n/** What is wrong with the keys an action's own specification declares: each of its parameters' and its results' the platform rewrites. */\nfunction actionKeyProblemsOf(slug: string, authored: Record<string, unknown>): string[] {\n  const schemas = [objectOf(authored.parameters).schema, objectOf(authored.results).schema];\n  return [...new Set(schemas.flatMap(rewrittenKeysOf))].map((problem) => `\"${slug}\": ${problem}`);\n}\n\n/** A custom action: its specification named by its key whatever it says, its author's over the kind's `definition` over the contract's; its trace redacting the attributes' secrets and its parameters'. */\nfunction customBinding(slug: string, declaration: ActionDeclaration<never>, definition: Record<string, unknown> | undefined, rules: BindRules): Binding {\n  if (declaration.specification === undefined && definition === undefined) {\n    return { problems: [rules.unspecifiedOf?.(slug) ?? unspecified(slug, rules)] };\n  }\n  const authored = objectOf(declaration.specification);\n  const specification = namedBody(slug, merged(serviceKind.action, objectOf(definition)), authored);\n  const bound: BoundAction = { slug, handler: declaration.handler, isDefault: false, specification, trace: actionTraceOf(declaration, secretSchemasOf(rules.attributesSchema, specification)) };\n  return { bound, problems: [...misnamed(authored, slug, \"key\").map((problem) => `\"${slug}\": ${problem}`), ...actionKeyProblemsOf(slug, authored)] };\n}\n\n/** The problem of a key that is not a slug, unless the kind defines it: the platform matches the action by the slug it derives from the key. */\nfunction keyProblemsOf(slug: string, definition: Record<string, unknown> | undefined): string[] {\n  return definition !== undefined || isSlug(slug) ? [] : [`\"${slug}\" is not a slug: the platform matches the action by the slug it derives from the key`];\n}\n\n/** The action `entry` declares under `slug`, bound by `rules`, and what is wrong with it. */\nfunction bindingOf(slug: string, entry: unknown, rules: BindRules): Binding {\n  const definition = rules.definitionOf?.(slug);\n  const keyProblems = keyProblemsOf(slug, definition);\n  const declared = typeof entry === \"function\" ? { handler: entry } : entry;\n  if (!isJsonObject(declared) || typeof declared.handler !== \"function\") {\n    return { problems: [...keyProblems, `\"${slug}\" must be ${ENTRY}`] };\n  }\n  const declaration = declared as unknown as ActionDeclaration<never>;\n  const isDefault = rules.usesDefaults && rules.defaultActions.includes(slug);\n  const binding = isDefault ? defaultBinding(slug, declaration, rules) : customBinding(slug, declaration, definition, rules);\n  return { bound: binding.bound, problems: [...keyProblems, ...declarationProblemsOf(slug, declared), ...binding.problems] };\n}\n\n/** Each default action a specification that uses them leaves out. */\nfunction missingDefaultsOf(actions: Record<string, unknown>, rules: BindRules): string[] {\n  const defaults = rules.usesDefaults ? rules.defaultActions : [];\n  return defaults.filter((slug) => !Object.hasOwn(actions, slug)).map((slug) => `no handler for the default action \"${slug}\"`);\n}\n\n/** The actions of a specification, bound by their keys in the order written; and every problem of them, in that order. */\nexport function checkedActions(actions: DeclaredActions, rules: BindRules): Checked<BoundAction[]> {\n  if (!isJsonObject(actions)) {\n    return { value: [], problems: [`actions must be an object: { <key>: ${ENTRY} }`] };\n  }\n  const bindings = Object.entries(actions).map(([slug, entry]) => bindingOf(slug, entry, rules));\n  return {\n    value: bindings.flatMap((binding) => (binding.bound === undefined ? [] : [binding.bound])),\n    problems: [...bindings.flatMap((binding) => binding.problems), ...missingDefaultsOf(actions, rules)],\n  };\n}\n\n/** The actions of a specification, bound by their keys in the order written; every problem refused at once, `where` naming the specification. */\nexport function bindActions(where: string, actions: DeclaredActions, rules: BindRules): BoundAction[] {\n  return refusedUnless(where, checkedActions(actions, rules));\n}\n\n/** The name of the action specification `action` publishes under `parent`: unique in the package. */\nfunction actionNameOf(parent: Component, action: BoundAction): string {\n  return `${parent.name}/${action.slug}`;\n}\n\n/**\n * The action specifications published under `parent`: when it uses the\n * platform's default actions, each default one platform-owned (the platform\n * creates it; publish finds it by its type and never writes it), then each\n * custom one with its body, in the order bound.\n */\nexport function actionComponents(parent: Component, actions: BoundAction[], usesDefaults: boolean): Component[] {\n  const defaults = usesDefaults ? actions.filter((action) => action.isDefault) : [];\n  const custom = actions.filter((action) => !action.isDefault);\n  return [\n    ...defaults.map((action) => component(ACTION_KIND, actionNameOf(parent, action), { type: action.slug }, { parent, owner: \"platform\", identity: \"type\" })),\n    ...custom.map((action) => component(ACTION_KIND, actionNameOf(parent, action), action.specification ?? {}, { parent })),\n  ];\n}\n\n/** What a kind says of how its specifications' actions are bound: whether they use the default actions, whatever a body says, its definitions, and why it cannot bind an action it does not define. */\nexport type KindRules = Partial<Pick<BindRules, \"usesDefaults\" | \"definitionOf\" | \"unspecifiedOf\">>;\n\n/**\n * `actions` bound to the specification `declared` and published under it: the\n * contract's default actions, used as the kind says, else as its body says;\n * its attributes' secrets redacted in every action's trace; the kind's\n * definitions, when it has them, beneath each author's specification. And\n * what is wrong with them.\n */\nexport function boundTo(declared: Component, actions: DeclaredActions, kind: KindRules = {}): Checked<BoundAction[]> {\n  const usesDefaults = kind.usesDefaults ?? usesDefaultActions(declared);\n  const rules: BindRules = {\n    usesDefaults,\n    defaultActions: serviceKind.default_actions,\n    definitionOf: kind.definitionOf,\n    attributesSchema: attributesSchemaOf(declared),\n    unspecifiedOf: kind.unspecifiedOf,\n  };\n  const bound = checkedActions(actions, rules);\n  actionComponents(declared, bound.value, usesDefaults);\n  return bound;\n}\n\n/** The slug of the specification `payload`'s action is of: its link's when it carries a link, else its service's. */\nexport function specificationSlugOf(payload: Payload): string | undefined {\n  const served = payload as ServicePayload;\n  const entity = isJsonObject(served.link) ? served.link : served.service;\n  return textOf(objectOf(objectOf(entity).specification).slug);\n}\n\n/** What names the action `payload` asks, as `action` is found: a default action's type, a custom one's specification's slug. */\nfunction askedOf(payload: Payload, action: BoundAction): string | undefined {\n  const served = payload as ServicePayload;\n  return action.isDefault ? textOf(served.type) : textOf(objectOf(served.specification).slug);\n}\n\n/** A match for the payloads that ask `action` of the specification `specificationSlug`. */\nexport function actionMatch(specificationSlug: string, action: BoundAction): (payload: Payload) => boolean {\n  return (payload) => specificationSlugOf(payload) === specificationSlug && askedOf(payload, action) === action.slug;\n}\n\n/** What the package's channel lets through for a specification's actions: the service source, filtered on its slug. */\nexport function specificationChannel(slug: string): NonNullable<Route[\"channel\"]> {\n  return { source: serviceKind.source, filter: { \"service.specification.slug\": { $eq: slug } } };\n}\n\n/** What it lets through for a link's actions: the service source, filtered on the link's specification's slug, whatever the service's says. */\nexport function linkChannel(slug: string): NonNullable<Route[\"channel\"]> {\n  return { source: serviceKind.source, filter: { \"link.specification.slug\": { $eq: slug } } };\n}\n\n/** How a specification's action prints its answer: a data action raw, as the platform validates it; any other the envelope. */\nfunction outputOf(payload: Payload): Output {\n  return isDataAction(payload) ? \"raw\" : \"envelope\";\n}\n\n/** Any middleware, whatever input it is handed and passes on: what a kind's middleware is before it meets the routes it fits. */\nexport type KindMiddleware = Middleware<never, unknown>;\n\n/**\n * A kind's middleware as the core's routes take it. Each is typed by the\n * input it is handed and the input it passes on, and a kind hands it only to\n * the routes whose middleware before it passes on that input (`KindRoute`):\n * the kind's own, which build the input from the payload, in order, and the\n * author's, typed by the input its routes build. There it is handed what its\n * type says, and what it passes on reaches a middleware or a handler typed\n * for it, so handing it on as the core's middleware is sound. Where a\n * route's handler is typed for a narrower input than the author's\n * middleware (its parameters typed by its schemas where the middleware has\n * any object; a field the middleware leaves optional, required), the\n * middleware is handed that narrower one, an input of its type still, and\n * the route builds or checks the field again after it, right before the\n * handler (its guard, `asRouteGuard`), so what it passes on never reaches\n * the handler otherwise.\n */\nexport function asRouteMiddleware(use: readonly KindMiddleware[]): Middleware[] {\n  return use as unknown as Middleware[];\n}\n\n/** A kind's guard as the core's routes take it, as sound as its middleware (`asRouteMiddleware`): it is handed what the middleware its route runs before it pass on, which is the input it is typed for. */\nexport function asRouteGuard(guard: (input: never, payload: Payload) => unknown): Guard {\n  return guard as unknown as Guard;\n}\n\n/** The route that answers `action` with its handler inside `use`. */\nexport function actionRoute(options: ActionRouteOptions): Route {\n  const { name, match, action, use, output = outputOf, describe, guard, channel, sample } = options;\n  // The handler is declared for the input its route's middleware builds: it meets the route's here, once.\n  return { name, match, use, handler: action.handler as Handler, output, ...(describe && { describe }), ...(guard && { guard }), channel, sample };\n}\n\n/** The run a specification's action is traced as (`Route.describe`): as its author declares it, the kind's title beneath the author's, scoped and labelled as the kind says. */\nexport function actionTracing(options: TracedActionOptions): NonNullable<Route[\"describe\"]> {\n  const { package: declaredPackage, kind, slug, action, trace } = options;\n  return specificationTracing({\n    package: declaredPackage,\n    kind,\n    action: action.slug,\n    resource: slug,\n    ...action.trace,\n    title: action.trace.title ?? trace?.title,\n    nrnOf: trace?.nrnOf,\n    about: trace?.about,\n  });\n}\n\n/** The service's input, as a route's middleware: what builds a specification's action's input unless a kind builds its own. */\nconst [SERVICE_INPUT] = asRouteMiddleware([serviceInput]);\n\n/** The payload's parameters again, as a route's guard: what a specification's action's handler gets unless a kind guards it otherwise. */\nconst PARAMETERS_GUARD = asRouteGuard(payloadParameters);\n\n/** The route that answers the action of a specification: matched as the model says, traced as its run, its lifecycle reported around its input, built from the payload, then the kind's checks; its guard the payload's parameters again, right before its handler, unless the kind says. */\nexport function specificationRoute(options: SpecificationRouteOptions): Route {\n  const { name, slug, action, inputBuilder = SERVICE_INPUT, inputChecks = [], guard = PARAMETERS_GUARD, channel = specificationChannel(slug), sample } = options;\n  const use = [lifecycle, inputBuilder, ...inputChecks];\n  return actionRoute({ name, match: actionMatch(slug, action), action, use, describe: actionTracing(options), guard, channel, sample });\n}\n\n/** What names the action `payload` asks, as an unbound one is named: its specification's slug, else its type. */\nfunction askedNameOf(payload: Payload): string {\n  const served = payload as ServicePayload;\n  return textOf(objectOf(served.specification).slug) ?? textOf(served.type) ?? \"\";\n}\n\n/** The last route of the specification `specificationSlug`: any other action of it fails, UNKNOWN_ACTION, inside its lifecycle. */\nexport function fallbackRoute(specificationSlug: string): Route {\n  return {\n    name: `${specificationSlug}/*`,\n    match: (payload) => specificationSlugOf(payload) === specificationSlug,\n    use: [lifecycle],\n    handler: (payload) => {\n      throw new ActionError(\"UNKNOWN_ACTION\", `no handler for action \"${askedNameOf(payload)}\" of specification \"${specificationSlug}\"`);\n    },\n    output: outputOf,\n  };\n}\n","/**\n * defineService: a service of its package, sugar on definePlugin. A\n * dependency (a database, a bucket, a queue) is a `service_specification`\n * named by the package's slug, its body as its author wrote it over the\n * contract's defaults (contract/kinds/service.json); its actions are bound by\n * their keys and published under it; each link is a `link_specification`\n * under it with actions of its own.\n *\n * Each action is a route, matched as the specification model says\n * (`./specification`), traced as the run it describes, then its lifecycle\n * reported around its input, built from the payload, so what tracing warns\n * never becomes an action's message;\n * then each specification's last route fails any other action of it. The\n * author's own routes come after them. The definition's middleware runs\n * inside each of the service's own action routes, after the service's own\n * middleware, so it is handed the service's action's input (its parameters\n * untyped, each action's being its own) and the platform hears what it\n * throws; each link's own (`links.<key>.use`) runs so inside its link's\n * action routes, typed by the link's input. Each route builds the\n * parameters again from the payload after them, right before the handler\n * typed by its schemas. None runs on a specification's last route, whose\n * handler is the kind's refusal, nor on an author's own route, which runs its\n * own (`route.use`, handed the payload). Every specification's define\n * assembles its plugin so (`specificationPlugin`).\n *\n * Each handler is called `(input, context)`: its input the payload's data,\n * its context the SDK's tools. Its input and its return are typed by the definition's schemas,\n * inferred as written (`const` type parameters) and read by `./values`: a\n * default action's parameters are its entity's attributes, required as the\n * platform keeps them on it, its return `Partial` of them; a custom action's\n * are its own `parameters` schema's, its return its `results` schema's. A\n * link's default actions take the link's attributes; its custom ones are\n * typed by no schema (`LinkEntries`).\n *\n *   export default defineService({\n *     package: { name: \"example-bucket\", version: \"0.1.0\" },\n *     specification: { attributes: { schema: { type: \"object\", properties: { region: { type: \"string\" } } } } },\n *     actions: {\n *       create: async (input) => ({ region: input.parameters.region ?? \"us-east-1\" }),\n *       update: async () => ({}),\n *       delete: async () => ({}),\n *       \"empty-bucket\": { specification: { type: \"custom\" }, handler: async () => ({ emptied: true }) },\n *     },\n *     links: { reader: { actions: { create: async () => ({ policy: \"read\" }), update: async () => ({}), delete: async () => ({}) } } },\n *   });\n */\n\nimport serviceKind from \"../../../../contract/kinds/service.json\" with { type: \"json\" };\nimport type { Component } from \"../../core/component\";\nimport type { Context } from \"../../core/run/context\";\nimport { refuseProblems } from \"../../core/errors\";\nimport { isSlug, packageOf, type Package, type PackageDeclaration } from \"../../core/package\";\nimport { isJsonObject, type Payload } from \"../../core/payload\";\nimport type { AgentOptions } from \"../../core/run/manifest\";\nimport { definePlugin, pluginProblemsOf, type Plugin } from \"../../core/run/plugin\";\nimport { routeUsing, useProblemsOf, type Middleware, type Route } from \"../../core/run/route\";\nimport { textOf } from \"../../core/text\";\nimport type { LinkInput, ServiceInput } from \"./input\";\nimport { linkSample, sampleActionOf, serviceSample, type SampleAction } from \"./samples\";\nimport {\n  asRouteMiddleware,\n  boundTo,\n  checkedLink,\n  checkedSpecification,\n  fallbackRoute,\n  linkChannel,\n  refusalsOf,\n  specificationChannel,\n  specificationRoute,\n  type ActionDeclaration,\n  type BoundAction,\n  type Checked,\n  type DeclaredActions,\n} from \"./specification\";\nimport type { AttributesSchemaOf, CustomResultOf, DefaultParametersOf, PartSchemaOf, ValuesOf } from \"./values\";\n\n/** The platform's default actions, by the key each is bound to (`[ServiceActions.CREATE]: …`): the contract's `default_actions`. */\nexport const ServiceActions = { CREATE: \"create\", UPDATE: \"update\", DELETE: \"delete\" } as const;\n\n/** A default action's key. */\nexport type DefaultActionKey = (typeof ServiceActions)[keyof typeof ServiceActions];\n\n/** Whether the action `Key` of the specification whose body is `Body` is a default one: a default action's key, unless the body uses none (`use_default_actions: false`). */\ntype IsDefault<Key, Body> = Key extends DefaultActionKey ? (Body extends { use_default_actions: false } ? false : true) : false;\n\n/** The attributes a specification whose body is `Body` stores, each optional: what its entity's `attributes` hold; any, untyped, when it declares no schema. */\nexport type StoredAttributesOf<Body> = AttributesSchemaOf<Body> extends undefined ? Record<string, unknown> : Partial<ValuesOf<AttributesSchemaOf<Body>>>;\n\n/** The parameters the action `Key` of the specification whose body is `Body` gets, its own specification `Declared`: a default action's its entity's attributes, as the platform requires them on it; a custom action's its `parameters` schema's. */\nexport type ActionParametersOf<Key, Body, Declared = undefined> =\n  IsDefault<Key, Body> extends true ? DefaultParametersOf<AttributesSchemaOf<Body>, Key> : ValuesOf<PartSchemaOf<Declared, \"parameters\">>;\n\n/** What the action `Key` of the specification whose body is `Body` returns, its own specification `Declared`: a default action `Partial` of its entity's attributes; a custom action its `results` schema's values, `unknown` without one. */\nexport type ActionResultOf<Key, Body, Declared = undefined> = IsDefault<Key, Body> extends true ? StoredAttributesOf<Body> : CustomResultOf<Declared>;\n\n/**\n * What the service's action `Key` gets as its input, the service's body\n * `Body`, the action's own specification `Declared` (a custom one's): the\n * parameters its schemas declare and the service's attributes. A handler\n * written apart from its definition is typed by it:\n *\n *   const create = async (input: ActionInputOf<\"create\", typeof specification>, context: Context): Promise<ActionResultOf<\"create\", typeof specification>> => ({});\n */\nexport interface ActionInputOf<Key, Body, Declared = undefined> extends ServiceInput<ActionParametersOf<Key, Body, Declared>, StoredAttributesOf<Body>> {}\n\n/** What the action `Key` of a link whose body is `LinkBody`, of the service whose body is `Body`, gets as its input: its parameters the link's, the service's attributes and the link's. */\nexport interface LinkActionInputOf<Key, LinkBody, Body> extends LinkInput<ActionParametersOf<Key, LinkBody>, StoredAttributesOf<Body>, StoredAttributesOf<LinkBody>> {}\n\n/** A handler of the input `Input`, and the run's context, that returns `Result`: the return is checked against it, never inferred from it. */\nexport type TypedHandler<Input, Result> = (input: Input, context: Context) => NoInfer<Result> | Promise<NoInfer<Result>>;\n\n/** An action's entry: its handler, or its handler with what it declares beside it, its specification `Declared`. */\nexport type TypedEntry<Input, Result, Declared = undefined> =\n  | TypedHandler<Input, Result>\n  | (Omit<ActionDeclaration<never>, \"handler\" | \"specification\"> & { specification?: Declared; handler: TypedHandler<Input, Result> });\n\n/**\n * The actions a definition declares when TypeScript infers none of their keys:\n * every entry is a handler that reads its input, which TypeScript types only\n * once their keys are fixed. They are the default ones, each optional.\n */\ntype DefaultSpecs = Partial<Record<DefaultActionKey, undefined>>;\n\n/** The service's actions, by key, each typed by its schemas: its own specification `Specs[Key]`, its service's body `Body`. */\nexport type ServiceEntries<Specs, Body> = { [Key in keyof Specs]: TypedEntry<ActionInputOf<Key, Body, Specs[Key]>, ActionResultOf<Key, Body, Specs[Key]>, Specs[Key]> };\n\n/**\n * A handler of the open interface, of the input `Input`. It is declared as a\n * method, whose parameters TypeScript checks both ways, so each default key's\n * own handler type fits it beside them under the same index.\n */\ntype OpenHandler<Input> = { handle(input: Input, context: Context): unknown }[\"handle\"];\n\n/** An entry of the open interface: its handler, or its handler with what it declares beside it. */\ntype OpenEntry<Input> = OpenHandler<Input> | (Omit<ActionDeclaration<never>, \"handler\"> & { handler: OpenHandler<Input> });\n\n/**\n * A link's actions, by key: each default one typed by the link's schemas and\n * its service's, every other the open interface, an entry of the link's\n * input (`LinkInput`) whose schemas the type does not read: TypeScript\n * infers no custom link action's specification, so its handler is annotated by\n * hand, and a value that is no entry does not typecheck.\n */\nexport type LinkEntries<LinkBody, Body> = { [Key in DefaultActionKey]?: TypedEntry<LinkActionInputOf<Key, LinkBody, Body>, ActionResultOf<Key, LinkBody>> } & {\n  [key: string]: OpenEntry<LinkInput> | undefined;\n};\n\n/** What a link's middleware is handed: the input of any action of it, its parameters untyped. */\nexport type LinkMiddlewareInput<LinkBody, Body> = LinkInput<Record<string, unknown>, StoredAttributesOf<Body>, StoredAttributesOf<LinkBody>>;\n\n/** A link of the service whose body is `Body`, by its key under `links`, its own body `LinkBody`. */\nexport interface LinkDefinition<LinkBody = Record<string, unknown>, Body = Record<string, unknown>> {\n  /** The link_specification body, as the API takes it. */\n  specification?: LinkBody;\n  /** What the link answers, by key: its default actions, while it uses them, and its custom ones. */\n  actions: LinkEntries<LinkBody, Body>;\n  /** Around each of its actions' handlers, outermost first, after the kind's own middleware: it is handed the link's action's input, its parameters untyped, which the route builds again right before the handler. */\n  use?: Middleware<LinkMiddlewareInput<LinkBody, Body>>[];\n}\n\n/** What every specification's define takes beside its specification and its actions, its middleware typed by its actions' input `Input`. */\nexport interface SpecificationOptions<Input = Payload> {\n  /** The package it belongs to: its name, version and description (the slug is the name's unless given), the project's own. */\n  package: PackageDeclaration;\n  /** How the package's agent channel reaches the worker. */\n  agent?: AgentOptions;\n  /** Around the handlers of the kind's actions whose input is `Input`, outermost first, after the kind's own middleware (the action reported, its input built): it is handed that input, as those handlers are. Never on a specification's last route, nor on the author's own routes, which run their own. */\n  use?: Middleware<Input>[];\n  /** What else it answers, after its actions, each with its own middleware (`route.use`). */\n  routes?: Route[];\n}\n\n/** The links a definition declares when TypeScript infers none of their names (none gives its specification, and every handler reads its input): any, each of an untyped body. */\ntype UntypedLinks = Record<string, Record<string, unknown>>;\n\n/** What a service's middleware is handed: the input of any of its own actions, its parameters untyped, which the route builds again right before the handler. */\nexport type ServiceMiddlewareInput<Body> = ServiceInput<Record<string, unknown>, StoredAttributesOf<Body>>;\n\n/** What a service is defined by: its body `Body`, each custom action's specification `Specs[key]`, each link's body `Links[key]`. */\nexport interface ServiceDefinition<Body = Record<string, unknown>, Specs = Record<string, unknown>, Links = UntypedLinks>\n  extends SpecificationOptions<ServiceMiddlewareInput<Body>> {\n  /** The service_specification body, as the API takes it; named by the package's slug. */\n  specification: Body;\n  /** What it answers, by key: its default actions, while it uses them, and its custom ones, each typed by its schemas. */\n  actions: ServiceEntries<Specs, Body>;\n  /** Its links, by key. */\n  links?: { [Name in keyof Links]: LinkDefinition<Links[Name], Body> };\n  /** Around each of the service's own actions' handlers, after the kind's own middleware: it is handed the service's action's input, its parameters untyped. Never on a link's action, which runs its link's own. */\n  use?: Middleware<ServiceMiddlewareInput<Body>>[];\n}\n\n/** A route the kind builds to answer an action, and the author's middleware that runs inside it: the one given for the input the route builds, as the core's routes take it (`asRouteMiddleware`); none when the author gives none for it. */\nexport interface KindRoute {\n  route: Route;\n  use?: Middleware[];\n}\n\n/** What a specification's define built of its definition: what it publishes, the routes that answer its actions, each specification's last route, and what is wrong with it, each refusal named by what it is of. */\nexport interface BuiltSpecification {\n  components: Component[];\n  routes: KindRoute[];\n  /** Each specification's last route (`fallbackRoute`), after the action routes: its handler is the kind's refusal, so the author's middleware never runs there. */\n  lastRoutes: Route[];\n  refusals: string[];\n}\n\n/** Who refuses a definition, as its problems are named. */\nconst DEFINER = \"defineService\";\n\n/** A link as a refusal names it. */\nconst LINK = \"{ specification?, actions, use? }\";\n\n/** What a specification is, as its actions' trace calls what they are of. */\ntype SpecificationKind = \"service\" | \"link\";\n\n/** A specification as its routes are built: what it is, its actions, the author's middleware for them, and how its routes are named, let through and offered. */\ninterface RoutedSpecification {\n  kind: SpecificationKind;\n  slug: string;\n  actions: BoundAction[];\n  /** The author's middleware for its actions, typed by the input their routes build. */\n  use: Middleware[] | undefined;\n  channel: NonNullable<Route[\"channel\"]>;\n  nameOf: (actionSlug: string) => string;\n  sampleOf: (action: SampleAction) => Payload;\n}\n\n/** The service's specification as its routes are built: its actions bound and published under it, the definition's middleware `use` around them; and what is wrong with them. */\nfunction routedService(declared: Component, actions: DeclaredActions, use: Middleware[] | undefined): Checked<RoutedSpecification> {\n  const bound = boundTo(declared, actions);\n  const routed: RoutedSpecification = {\n    kind: \"service\",\n    slug: declared.name,\n    actions: bound.value,\n    use,\n    channel: specificationChannel(declared.name),\n    nameOf: (actionSlug) => actionSlug,\n    sampleOf: (action) => serviceSample(declared.name, action),\n  };\n  return { value: routed, problems: bound.problems };\n}\n\n/** The link `slug` of the specification `parent` as its routes are built: published under it, its actions bound and published under the link, its own middleware around them; and what is wrong with its body, its actions and its middleware. */\nfunction routedLink(parent: Component, slug: string, link: LinkDefinition): Checked<RoutedSpecification> {\n  const declared = checkedLink(parent, slug, link.specification ?? {});\n  const bound = boundTo(declared.value, link.actions);\n  const routed: RoutedSpecification = {\n    kind: \"link\",\n    slug,\n    actions: bound.value,\n    use: routeUseOf(link.use),\n    channel: linkChannel(slug),\n    nameOf: (actionSlug) => `${slug}/${actionSlug}`,\n    sampleOf: (action) => linkSample(parent.name, slug, action),\n  };\n  return { value: routed, problems: [...declared.problems, ...bound.problems, ...useProblemsOf(link.use)] };\n}\n\n/**\n * What is wrong with the link `key` of the specification `slug`: a key that\n * is not a slug, the platform matching the link's actions by the slug it\n * derives from it; a key that is its service's, a link's action being matched\n * by its link's slug and a service's by its own; a link that is no object.\n */\nfunction linkProblemsOf(slug: string, key: string, link: unknown): string[] {\n  return [\n    ...(isSlug(key) ? [] : [`link \"${key}\" is not a slug: the platform matches the link's actions by the slug it derives from the key`]),\n    ...(key === slug ? [`link \"${key}\" is named as its service: an action is matched by its link's slug, or else its service's, and here both are \"${key}\"`] : []),\n    ...(isJsonObject(link) ? [] : [`link \"${key}\" must be ${LINK}`]),\n  ];\n}\n\n/** The links a definition gives, by key, each one built that is an object keyed by text apart from its service; and what is wrong with each. */\nfunction linksOf(slug: string, links: unknown): Checked<[string, LinkDefinition][]> {\n  if (links === undefined) {\n    return { value: [], problems: [] };\n  }\n  if (!isJsonObject(links)) {\n    return { value: [], problems: [`links must be an object: { <key>: ${LINK} }`] };\n  }\n  const entries = Object.entries(links);\n  const built = entries.filter(([key, link]) => textOf(key) !== undefined && key !== slug && isJsonObject(link)) as [string, LinkDefinition][];\n  return { value: built, problems: entries.flatMap(([key, link]) => linkProblemsOf(slug, key, link)) };\n}\n\n/** The route that answers `action` of `routed`, as a specification's action is answered, with the author's middleware for it, then its parameters built again from the payload, right before the handler typed by them. */\nfunction routeOf(declaredPackage: Package, routed: RoutedSpecification, action: BoundAction): KindRoute {\n  const route = specificationRoute({\n    package: declaredPackage,\n    kind: routed.kind,\n    slug: routed.slug,\n    name: routed.nameOf(action.slug),\n    action,\n    channel: routed.channel,\n    sample: routed.sampleOf(sampleActionOf(action)),\n  });\n  return { route, use: routed.use };\n}\n\n/** The routes of the specifications' actions: each one's, in order. */\nfunction routesOf(declaredPackage: Package, specifications: RoutedSpecification[]): KindRoute[] {\n  return specifications.flatMap((routed) => routed.actions.map((action) => routeOf(declaredPackage, routed, action)));\n}\n\n/**\n * What the core refuses of a specification's definition: the author's\n * middleware (`use`), agent options and routes as given, their routes first,\n * so a route's problem names its index in `routes` and one named as a route\n * the kind built is given twice.\n */\nfunction coreProblemsOf(definition: Pick<SpecificationOptions, \"agent\" | \"routes\">, use: Middleware[] | undefined, built: BuiltSpecification): string[] {\n  const own: unknown = definition.routes ?? [];\n  const routes = Array.isArray(own) ? [...own, ...built.routes.map((kindRoute) => kindRoute.route), ...built.lastRoutes] : own;\n  return pluginProblemsOf({ use, agent: definition.agent, components: built.components, routes: routes as Route[] });\n}\n\n/** A route the kind builds, with the author's middleware for it inside its own (`routeUsing`): it runs once the action is reported and its input built, before the route's guard. Without any, the route as it is. */\nfunction kindRouteOf({ route, use }: KindRoute): Route {\n  return use === undefined || use.length === 0 ? route : routeUsing(route, [...(route.use ?? []), ...use]);\n}\n\n/** The author's middleware, when given, as the core's routes take it (`asRouteMiddleware`): the definition's is handed to the routes of the kind's own actions, a link's to its link's. */\nexport function routeUseOf<Input>(use: Middleware<Input>[] | undefined): Middleware[] | undefined {\n  return use === undefined ? undefined : asRouteMiddleware(use);\n}\n\n/**\n * The plugin a specification's define (`definer`) builds of `definition` and\n * of what it `built`: its components, the routes that answer its actions,\n * each with the author's middleware for it inside its own, each\n * specification's last route as it is, then the author's own routes as they\n * are. A definition with a problem is refused, naming every one at once: what\n * it built's, then what the core refuses of the definition (`coreProblemsOf`),\n * named by its definer and its package.\n */\nexport function specificationPlugin<Input>(definer: string, declaredPackage: Package, definition: SpecificationOptions<Input>, built: BuiltSpecification): Plugin {\n  const coreProblems = coreProblemsOf(definition, routeUseOf(definition.use), built);\n  refuseProblems([...built.refusals, ...refusalsOf(`${definer}(${declaredPackage.name})`, coreProblems)]);\n  return definePlugin({\n    package: definition.package,\n    agent: definition.agent,\n    components: built.components,\n    routes: [...built.routes.map(kindRouteOf), ...built.lastRoutes, ...(definition.routes ?? [])],\n  });\n}\n\n/**\n * A service of its package: its specification, its actions and its links\n * published, a route per action. A definition with a problem is refused,\n * naming every one at once: the specification's (its body, its actions, its\n * links), each link's (its body, its actions), then the definition's own.\n */\nexport function defineService<const Body extends Record<string, unknown>, const Specs extends Record<string, unknown> = DefaultSpecs, const Links extends Record<string, unknown> = UntypedLinks>(\n  definition: ServiceDefinition<Body, Specs, Links>,\n): Plugin {\n  const declaredPackage = packageOf(DEFINER, definition?.package);\n  const specification = checkedSpecification(declaredPackage.slug, definition.specification, serviceKind.specification);\n  const declared = specification.value;\n  const links = linksOf(declared.name, definition.links);\n  const service = routedService(declared, definition.actions, routeUseOf(definition.use));\n  const routedLinks = links.value.map(([slug, link]) => routedLink(declared, slug, link));\n  const specifications = [service.value, ...routedLinks.map((link) => link.value)];\n  return specificationPlugin(DEFINER, declaredPackage, definition, {\n    components: [declared],\n    routes: routesOf(declaredPackage, specifications),\n    lastRoutes: specifications.map((routed) => fallbackRoute(routed.slug)),\n    refusals: [\n      ...refusalsOf(declared.name, [...specification.problems, ...service.problems, ...links.problems]),\n      ...routedLinks.flatMap((link) => refusalsOf(link.value.slug, link.problems)),\n    ],\n  });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AGyBA,SAAgB,eAAe,UAAmC;CAChE,MAAM,OAAOA,SAAO,YAAYA,SAAO,OAAO,OAAO,SAASA,SAAO,aAAa,CAAC,CAAC,IAAI;CACxF,OAAO;EAAE,MAAMA,SAAO;EAAM,MAAM,QAAA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