@entifix/core 0.23.1 → 0.23.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,10 @@ import type { Entity, EntityConstructor } from '../types/Entity.js';
12
12
  * - `organization` — the same, acting for the session's active organization.
13
13
  * - `crossing` — a service crossing token and `permission`. With
14
14
  * `organization: true` the caller names the organization, because the data's
15
- * owner was handed to it rather than chosen.
15
+ * owner was handed to it rather than chosen. With `caller` it accepts only
16
+ * that named caller's token, never the service's own crossing token: a
17
+ * route a browser-facing host reaches must not open to the coordinator's
18
+ * secret, nor the coordinator's routes to the host's.
16
19
  * - `fleet` — the shared token one service of the fleet presents to another.
17
20
  */
18
21
  /** A permission as `<domain>:<entityKey>:<action>`. */
@@ -31,6 +34,8 @@ export type EndpointGuard = {
31
34
  readonly kind: 'crossing';
32
35
  readonly permission: EndpointPermission;
33
36
  readonly organization: boolean;
37
+ /** The named caller whose token alone this endpoint accepts. */
38
+ readonly caller?: string;
34
39
  } | {
35
40
  readonly kind: 'fleet';
36
41
  };
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAwB,MAAM,QAAQ,CAAC;AAGnE,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEpE;;;;;;;;;;;;;GAaG;AACH,uDAAuD;AACvD,MAAM,MAAM,kBAAkB,GAAG,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;AAEjE,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,SA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AM,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAWnD,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,aAAa,yBAAyB,CAAC;AAEpD,wFAAwF;AACxF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,oBAA0B,KAAG,MAAM,CAAC,MAGzD,CAAC;AAEL;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,CAAC,MAAM,EAChE,QAAQ,MAAM,KACb,MAAM,CAAC,MAAM,CAAC,MAAM,CAMnB,CAAC;AAEL,4EAA4E;AAC5E,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,CAAC,GAAG,KAAG,YAAY,GAAG,SAGpC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/endpoint/endpoint.ts"],"sourcesContent":["import { type Effect, Schema, SchemaTransformation } from 'effect';\n\nimport { extractMetaEntity } from '../entity-definition/helpers/entity-definition-helpers.js';\nimport type {\n EntifixFailure,\n FailureClass,\n TechnicalCategory,\n} from '../failure/failure.js';\nimport type { Entity, EntityConstructor } from '../types/Entity.js';\n\n/**\n * Who may call an endpoint, and with which credential\n * ([ADR 0020](../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)).\n * Exactly one per endpoint. The shell implements each kind once.\n *\n * - `public` — no credential.\n * - `session` — a verified session, and nothing more.\n * - `permission` — a session whose roles grant `permission`.\n * - `organization` — the same, acting for the session's active organization.\n * - `crossing` — a service crossing token and `permission`. With\n * `organization: true` the caller names the organization, because the data's\n * owner was handed to it rather than chosen.\n * - `fleet` — the shared token one service of the fleet presents to another.\n */\n/** A permission as `<domain>:<entityKey>:<action>`. */\nexport type EndpointPermission = `${string}:${string}:${string}`;\n\nexport type EndpointGuard =\n | { readonly kind: 'public' }\n | { readonly kind: 'session' }\n | { readonly kind: 'permission'; readonly permission: EndpointPermission }\n | { readonly kind: 'organization'; readonly permission: EndpointPermission }\n | {\n readonly kind: 'crossing';\n readonly permission: EndpointPermission;\n readonly organization: boolean;\n }\n | { readonly kind: 'fleet' };\n\nexport type EndpointGuardKind = EndpointGuard['kind'];\n\n/**\n * Which layer remembers an `Idempotency-Key`. One write is recorded by one\n * layer, never both: `unit` when the handler writes through a unit of work,\n * which claims the key in the same transaction as the write; `edge` when it\n * does not, and the shell's idempotency store remembers the answer.\n */\nexport type EndpointIdempotency = 'unit' | 'edge';\n\nexport type EndpointMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\n/** A schema, or the fields of a struct — normalised to a schema when served. */\nexport type EndpointSchema = Schema.Top | Schema.Struct.Fields;\n\n/** The schema an {@link EndpointSchema} stands for. */\nexport type SchemaOf<S> = S extends Schema.Top\n ? S\n : S extends Schema.Struct.Fields\n ? Schema.Struct<S>\n : never;\n\ntype TypeOf<S> = SchemaOf<S>['Type'];\n\n/**\n * An endpoint, described with Schema and nothing about HTTP beyond its method\n * and path: no status beyond `accepted`, no content type, no annotation. A cell exports these;\n * the shell turns them into an API.\n */\nexport interface EndpointDescriptor<\n Name extends string = string,\n Method extends EndpointMethod = EndpointMethod,\n Path extends `/${string}` = `/${string}`,\n Params extends EndpointSchema | undefined = EndpointSchema | undefined,\n Query extends EndpointSchema | undefined = EndpointSchema | undefined,\n Payload extends EndpointSchema | undefined = EndpointSchema | undefined,\n Success extends Schema.Top = Schema.Top,\n Errors extends ReadonlyArray<FailureClass> = ReadonlyArray<FailureClass>,\n Guard extends EndpointGuard = EndpointGuard,\n Idempotency extends EndpointIdempotency | undefined =\n EndpointIdempotency | undefined,\n Headers extends EndpointSchema | undefined = EndpointSchema | undefined,\n> {\n readonly name: Name;\n readonly method: Method;\n readonly path: Path;\n readonly params?: Params;\n readonly query?: Query;\n readonly payload?: Payload;\n /**\n * The request headers the handler reads, by lower-case name. Most endpoints\n * declare none: a header an endpoint does not name is not its input.\n */\n readonly headers?: Headers;\n readonly success: Success;\n /**\n * Every business failure the handler may answer with. Only failure classes:\n * a refusal with no category does not compile. Technical failures are not\n * listed — every endpoint may answer with one.\n */\n readonly errors: Errors;\n readonly guard: Guard;\n readonly idempotent?: Idempotency;\n /**\n * The handler answers before the work is done: it started a flow and\n * answers what to follow, served as `202 Accepted` rather than `200`. The\n * only word a descriptor has about a success status, because it is the only\n * one a client branches on (two settle modes, ADR 0022).\n */\n readonly accepted?: boolean;\n /** The `@useCase()` this endpoint serves, when it is a verb. */\n readonly useCase?: string;\n}\n\n/** Any descriptor. */\nexport type AnyEndpoint = EndpointDescriptor<\n string,\n EndpointMethod,\n `/${string}`,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n Schema.Top,\n ReadonlyArray<FailureClass>,\n EndpointGuard,\n EndpointIdempotency | undefined,\n EndpointSchema | undefined\n>;\n\n/**\n * Declare one endpoint. The literal types of its name, path and schemas are\n * kept, so a handler and a client are typed from it.\n */\nexport const defineEndpoint = <\n const Name extends string,\n const Method extends EndpointMethod,\n const Path extends `/${string}`,\n Success extends Schema.Top,\n const Errors extends ReadonlyArray<FailureClass> = readonly [],\n Params extends EndpointSchema | undefined = undefined,\n Query extends EndpointSchema | undefined = undefined,\n Payload extends EndpointSchema | undefined = undefined,\n const Guard extends EndpointGuard = EndpointGuard,\n const Idempotency extends EndpointIdempotency | undefined = undefined,\n Headers extends EndpointSchema | undefined = undefined,\n>(\n descriptor: EndpointDescriptor<\n Name,\n Method,\n Path,\n Params,\n Query,\n Payload,\n Success,\n Errors,\n Guard,\n Idempotency,\n Headers\n >,\n): EndpointDescriptor<\n Name,\n Method,\n Path,\n Params,\n Query,\n Payload,\n Success,\n Errors,\n Guard,\n Idempotency,\n Headers\n> => descriptor;\n\n/** Declare several endpoints, keeping each one's literal types. */\nexport const defineEndpoints = <\n const Endpoints extends ReadonlyArray<AnyEndpoint>,\n>(\n ...endpoints: Endpoints\n): Endpoints => endpoints;\n\n/** A technical failure: a non-answer every endpoint may produce undeclared. */\nexport type TechnicalFailure = EntifixFailure<\n string,\n string,\n TechnicalCategory\n>;\n\n/** The business failures a descriptor declares, as instances. */\nexport type DeclaredFailure<D> =\n D extends EndpointDescriptor<\n string,\n EndpointMethod,\n `/${string}`,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n Schema.Top,\n infer Errors,\n EndpointGuard,\n EndpointIdempotency | undefined\n >\n ? InstanceType<Errors[number]>\n : never;\n\n/** What a handler receives: the decoded parts the descriptor declares. */\nexport type EndpointRequest<D> =\n D extends EndpointDescriptor<\n string,\n EndpointMethod,\n `/${string}`,\n infer Params,\n infer Query,\n infer Payload,\n Schema.Top,\n ReadonlyArray<FailureClass>,\n EndpointGuard,\n EndpointIdempotency | undefined,\n infer Headers\n >\n ? (Params extends EndpointSchema\n ? { readonly params: TypeOf<Params> }\n : unknown) &\n (Query extends EndpointSchema\n ? { readonly query: TypeOf<Query> }\n : unknown) &\n (Payload extends EndpointSchema\n ? { readonly payload: TypeOf<Payload> }\n : unknown) &\n (Headers extends EndpointSchema\n ? { readonly headers: TypeOf<Headers> }\n : unknown)\n : never;\n\n/** What a handler answers with. */\nexport type EndpointSuccess<D> =\n D extends EndpointDescriptor<\n string,\n EndpointMethod,\n `/${string}`,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n infer Success,\n ReadonlyArray<FailureClass>,\n EndpointGuard,\n EndpointIdempotency | undefined\n >\n ? Success['Type']\n : never;\n\n/** A handler for `D`: a plain effect, with no transport in its type. */\nexport type EndpointHandler<D, R> = (\n request: EndpointRequest<D>,\n) => Effect.Effect<\n EndpointSuccess<D>,\n DeclaredFailure<D> | TechnicalFailure,\n R\n>;\n\n/** A descriptor paired with the handler that serves it. */\nexport interface Implemented<D extends AnyEndpoint = AnyEndpoint, R = unknown> {\n readonly descriptor: D;\n readonly handler: EndpointHandler<D, R>;\n}\n\n/**\n * Pair a descriptor with its handler. A handler failing with a business\n * failure the descriptor does not declare does not compile.\n */\nexport const implement = <D extends AnyEndpoint, R>(\n descriptor: D,\n handler: EndpointHandler<D, R>,\n): Implemented<D, R> => ({ descriptor, handler });\n\n/**\n * The entity's key as a literal, checked against `@entity({ key })` when the\n * module loads, so a path built from it cannot name a key the entity does not\n * carry.\n */\nexport const entityKey = <T extends Entity, const K extends string>(\n entityConstructor: EntityConstructor<T>,\n key: K,\n): K => {\n const declared = extractMetaEntity(entityConstructor).key;\n if (declared !== key)\n throw new Error(\n `entityKey(${entityConstructor.name}, '${key}') does not match ` +\n `@entity({ key: ${declared === undefined ? 'undefined' : `'${declared}'`} })`,\n );\n return key;\n};\n\n/**\n * A body an endpoint sends without describing it: whatever the handler\n * answers, as its JSON — `Date`s as ISO strings, `undefined` members dropped,\n * the way `JSON.stringify` writes it. For a record whose shape the entity\n * describes rather than a schema, and for an opaque document such as an\n * OpenAPI one. A body the endpoint can describe should be a schema instead.\n */\nexport const JsonBody: Schema.Codec<unknown, unknown> = Schema.Unknown.pipe(\n Schema.decodeTo(\n Schema.Unknown,\n SchemaTransformation.transform({\n decode: value => value,\n encode: value =>\n value === undefined\n ? null\n : (JSON.parse(JSON.stringify(value)) as unknown),\n }),\n ),\n);\n\n/** The annotation a body schema carries when it is not JSON on the wire. */\nexport const BODY_ENCODING = 'entifix/bodyEncoding';\n\n/** How a payload travels when it is not decoded as JSON, and under which media type. */\nexport interface BodyEncoding {\n readonly kind: 'text' | 'form';\n readonly contentType: string;\n}\n\n/**\n * A payload taken as the exact text that arrived, for an endpoint whose\n * authentication is a signature over those bytes: a decoded object\n * re-serialised is a different byte sequence, and the MAC would not verify.\n * `contentType` is the media type the caller sends — a provider that signs a\n * JSON body still sends `application/json`, and the bytes are what matter.\n */\nexport const textBody = (contentType = 'text/plain'): Schema.String =>\n Schema.String.annotate({\n [BODY_ENCODING]: { kind: 'text', contentType } satisfies BodyEncoding,\n });\n\n/**\n * A form-encoded payload (`application/x-www-form-urlencoded`), for a caller\n * a specification makes post one — an OpenID back-channel logout, say.\n */\nexport const formBody = <const Fields extends Schema.Struct.Fields>(\n fields: Fields,\n): Schema.Struct<Fields> =>\n Schema.Struct(fields).annotate({\n [BODY_ENCODING]: {\n kind: 'form',\n contentType: 'application/x-www-form-urlencoded',\n } satisfies BodyEncoding,\n });\n\n/** The wire encoding a payload schema declared, or `undefined` for JSON. */\nexport const bodyEncodingOf = (schema: Schema.Top): BodyEncoding | undefined =>\n (schema.ast.annotations as Record<string, unknown> | undefined)?.[\n BODY_ENCODING\n ] as BodyEncoding | undefined;\n"],"names":["Schema","SchemaTransformation","extractMetaEntity","defineEndpoint","descriptor","defineEndpoints","endpoints","implement","handler","entityKey","entityConstructor","key","declared","Error","name","undefined","JsonBody","Unknown","pipe","decodeTo","transform","decode","value","encode","JSON","parse","stringify","BODY_ENCODING","textBody","contentType","String","annotate","kind","formBody","fields","Struct","bodyEncodingOf","schema","ast","annotations"],"mappings":"AAAA,SAAsBA,MAAM,EAAEC,oBAAoB,QAAQ,SAAS;AAEnE,SAASC,iBAAiB,QAAQ,4DAA4D;AA8H9F;;;CAGC,GACD,OAAO,MAAMC,iBAAiB,CAa5BC,aAyBGA,WAAW;AAEhB,iEAAiE,GACjE,OAAO,MAAMC,kBAAkB,CAG7B,GAAGC,YACWA,UAAU;AAuF1B;;;CAGC,GACD,OAAO,MAAMC,YAAY,CACvBH,YACAI,UACuB,CAAA;QAAEJ;QAAYI;IAAQ,CAAA,EAAG;AAElD;;;;CAIC,GACD,OAAO,MAAMC,YAAY,CACvBC,mBACAC;IAEA,MAAMC,WAAWV,kBAAkBQ,mBAAmBC,GAAG;IACzD,IAAIC,aAAaD,KACf,MAAM,IAAIE,MACR,CAAC,UAAU,EAAEH,kBAAkBI,IAAI,CAAC,GAAG,EAAEH,IAAI,kBAAkB,CAAC,GAC9D,CAAC,eAAe,EAAEC,aAAaG,YAAY,cAAc,CAAC,CAAC,EAAEH,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC;IAEnF,OAAOD;AACT,EAAE;AAEF;;;;;;CAMC,GACD,OAAO,MAAMK,WAA2ChB,OAAOiB,OAAO,CAACC,IAAI,CACzElB,OAAOmB,QAAQ,CACbnB,OAAOiB,OAAO,EACdhB,qBAAqBmB,SAAS,CAAC;IAC7BC,QAAQC,CAAAA,QAASA;IACjBC,QAAQD,CAAAA,QACNA,UAAUP,YACN,OACCS,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;AACnC,KAEF;AAEF,0EAA0E,GAC1E,OAAO,MAAMK,gBAAgB,uBAAuB;AAQpD;;;;;;CAMC,GACD,OAAO,MAAMC,WAAW,CAACC,cAAc,YAAY,GACjD7B,OAAO8B,MAAM,CAACC,QAAQ,CAAC;QACrB,CAACJ,cAAc,EAAE;YAAEK,MAAM;YAAQH;QAAY;IAC/C,GAAG;AAEL;;;CAGC,GACD,OAAO,MAAMI,WAAW,CACtBC,SAEAlC,OAAOmC,MAAM,CAACD,QAAQH,QAAQ,CAAC;QAC7B,CAACJ,cAAc,EAAE;YACfK,MAAM;YACNH,aAAa;QACf;IACF,GAAG;AAEL,0EAA0E,GAC1E,OAAO,MAAMO,iBAAiB,CAACC;QAC5BA;YAAAA,0BAAAA,OAAOC,GAAG,CAACC,WAAW,qBAAvB,AAACF,uBAAgE,CAC/DV,cACD;EAA6B"}
1
+ {"version":3,"sources":["../../src/endpoint/endpoint.ts"],"sourcesContent":["import { type Effect, Schema, SchemaTransformation } from 'effect';\n\nimport { extractMetaEntity } from '../entity-definition/helpers/entity-definition-helpers.js';\nimport type {\n EntifixFailure,\n FailureClass,\n TechnicalCategory,\n} from '../failure/failure.js';\nimport type { Entity, EntityConstructor } from '../types/Entity.js';\n\n/**\n * Who may call an endpoint, and with which credential\n * ([ADR 0020](../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)).\n * Exactly one per endpoint. The shell implements each kind once.\n *\n * - `public` — no credential.\n * - `session` — a verified session, and nothing more.\n * - `permission` — a session whose roles grant `permission`.\n * - `organization` — the same, acting for the session's active organization.\n * - `crossing` — a service crossing token and `permission`. With\n * `organization: true` the caller names the organization, because the data's\n * owner was handed to it rather than chosen. With `caller` it accepts only\n * that named caller's token, never the service's own crossing token: a\n * route a browser-facing host reaches must not open to the coordinator's\n * secret, nor the coordinator's routes to the host's.\n * - `fleet` — the shared token one service of the fleet presents to another.\n */\n/** A permission as `<domain>:<entityKey>:<action>`. */\nexport type EndpointPermission = `${string}:${string}:${string}`;\n\nexport type EndpointGuard =\n | { readonly kind: 'public' }\n | { readonly kind: 'session' }\n | { readonly kind: 'permission'; readonly permission: EndpointPermission }\n | { readonly kind: 'organization'; readonly permission: EndpointPermission }\n | {\n readonly kind: 'crossing';\n readonly permission: EndpointPermission;\n readonly organization: boolean;\n /** The named caller whose token alone this endpoint accepts. */\n readonly caller?: string;\n }\n | { readonly kind: 'fleet' };\n\nexport type EndpointGuardKind = EndpointGuard['kind'];\n\n/**\n * Which layer remembers an `Idempotency-Key`. One write is recorded by one\n * layer, never both: `unit` when the handler writes through a unit of work,\n * which claims the key in the same transaction as the write; `edge` when it\n * does not, and the shell's idempotency store remembers the answer.\n */\nexport type EndpointIdempotency = 'unit' | 'edge';\n\nexport type EndpointMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\n/** A schema, or the fields of a struct — normalised to a schema when served. */\nexport type EndpointSchema = Schema.Top | Schema.Struct.Fields;\n\n/** The schema an {@link EndpointSchema} stands for. */\nexport type SchemaOf<S> = S extends Schema.Top\n ? S\n : S extends Schema.Struct.Fields\n ? Schema.Struct<S>\n : never;\n\ntype TypeOf<S> = SchemaOf<S>['Type'];\n\n/**\n * An endpoint, described with Schema and nothing about HTTP beyond its method\n * and path: no status beyond `accepted`, no content type, no annotation. A cell exports these;\n * the shell turns them into an API.\n */\nexport interface EndpointDescriptor<\n Name extends string = string,\n Method extends EndpointMethod = EndpointMethod,\n Path extends `/${string}` = `/${string}`,\n Params extends EndpointSchema | undefined = EndpointSchema | undefined,\n Query extends EndpointSchema | undefined = EndpointSchema | undefined,\n Payload extends EndpointSchema | undefined = EndpointSchema | undefined,\n Success extends Schema.Top = Schema.Top,\n Errors extends ReadonlyArray<FailureClass> = ReadonlyArray<FailureClass>,\n Guard extends EndpointGuard = EndpointGuard,\n Idempotency extends EndpointIdempotency | undefined =\n EndpointIdempotency | undefined,\n Headers extends EndpointSchema | undefined = EndpointSchema | undefined,\n> {\n readonly name: Name;\n readonly method: Method;\n readonly path: Path;\n readonly params?: Params;\n readonly query?: Query;\n readonly payload?: Payload;\n /**\n * The request headers the handler reads, by lower-case name. Most endpoints\n * declare none: a header an endpoint does not name is not its input.\n */\n readonly headers?: Headers;\n readonly success: Success;\n /**\n * Every business failure the handler may answer with. Only failure classes:\n * a refusal with no category does not compile. Technical failures are not\n * listed — every endpoint may answer with one.\n */\n readonly errors: Errors;\n readonly guard: Guard;\n readonly idempotent?: Idempotency;\n /**\n * The handler answers before the work is done: it started a flow and\n * answers what to follow, served as `202 Accepted` rather than `200`. The\n * only word a descriptor has about a success status, because it is the only\n * one a client branches on (two settle modes, ADR 0022).\n */\n readonly accepted?: boolean;\n /** The `@useCase()` this endpoint serves, when it is a verb. */\n readonly useCase?: string;\n}\n\n/** Any descriptor. */\nexport type AnyEndpoint = EndpointDescriptor<\n string,\n EndpointMethod,\n `/${string}`,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n Schema.Top,\n ReadonlyArray<FailureClass>,\n EndpointGuard,\n EndpointIdempotency | undefined,\n EndpointSchema | undefined\n>;\n\n/**\n * Declare one endpoint. The literal types of its name, path and schemas are\n * kept, so a handler and a client are typed from it.\n */\nexport const defineEndpoint = <\n const Name extends string,\n const Method extends EndpointMethod,\n const Path extends `/${string}`,\n Success extends Schema.Top,\n const Errors extends ReadonlyArray<FailureClass> = readonly [],\n Params extends EndpointSchema | undefined = undefined,\n Query extends EndpointSchema | undefined = undefined,\n Payload extends EndpointSchema | undefined = undefined,\n const Guard extends EndpointGuard = EndpointGuard,\n const Idempotency extends EndpointIdempotency | undefined = undefined,\n Headers extends EndpointSchema | undefined = undefined,\n>(\n descriptor: EndpointDescriptor<\n Name,\n Method,\n Path,\n Params,\n Query,\n Payload,\n Success,\n Errors,\n Guard,\n Idempotency,\n Headers\n >,\n): EndpointDescriptor<\n Name,\n Method,\n Path,\n Params,\n Query,\n Payload,\n Success,\n Errors,\n Guard,\n Idempotency,\n Headers\n> => descriptor;\n\n/** Declare several endpoints, keeping each one's literal types. */\nexport const defineEndpoints = <\n const Endpoints extends ReadonlyArray<AnyEndpoint>,\n>(\n ...endpoints: Endpoints\n): Endpoints => endpoints;\n\n/** A technical failure: a non-answer every endpoint may produce undeclared. */\nexport type TechnicalFailure = EntifixFailure<\n string,\n string,\n TechnicalCategory\n>;\n\n/** The business failures a descriptor declares, as instances. */\nexport type DeclaredFailure<D> =\n D extends EndpointDescriptor<\n string,\n EndpointMethod,\n `/${string}`,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n Schema.Top,\n infer Errors,\n EndpointGuard,\n EndpointIdempotency | undefined\n >\n ? InstanceType<Errors[number]>\n : never;\n\n/** What a handler receives: the decoded parts the descriptor declares. */\nexport type EndpointRequest<D> =\n D extends EndpointDescriptor<\n string,\n EndpointMethod,\n `/${string}`,\n infer Params,\n infer Query,\n infer Payload,\n Schema.Top,\n ReadonlyArray<FailureClass>,\n EndpointGuard,\n EndpointIdempotency | undefined,\n infer Headers\n >\n ? (Params extends EndpointSchema\n ? { readonly params: TypeOf<Params> }\n : unknown) &\n (Query extends EndpointSchema\n ? { readonly query: TypeOf<Query> }\n : unknown) &\n (Payload extends EndpointSchema\n ? { readonly payload: TypeOf<Payload> }\n : unknown) &\n (Headers extends EndpointSchema\n ? { readonly headers: TypeOf<Headers> }\n : unknown)\n : never;\n\n/** What a handler answers with. */\nexport type EndpointSuccess<D> =\n D extends EndpointDescriptor<\n string,\n EndpointMethod,\n `/${string}`,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n infer Success,\n ReadonlyArray<FailureClass>,\n EndpointGuard,\n EndpointIdempotency | undefined\n >\n ? Success['Type']\n : never;\n\n/** A handler for `D`: a plain effect, with no transport in its type. */\nexport type EndpointHandler<D, R> = (\n request: EndpointRequest<D>,\n) => Effect.Effect<\n EndpointSuccess<D>,\n DeclaredFailure<D> | TechnicalFailure,\n R\n>;\n\n/** A descriptor paired with the handler that serves it. */\nexport interface Implemented<D extends AnyEndpoint = AnyEndpoint, R = unknown> {\n readonly descriptor: D;\n readonly handler: EndpointHandler<D, R>;\n}\n\n/**\n * Pair a descriptor with its handler. A handler failing with a business\n * failure the descriptor does not declare does not compile.\n */\nexport const implement = <D extends AnyEndpoint, R>(\n descriptor: D,\n handler: EndpointHandler<D, R>,\n): Implemented<D, R> => ({ descriptor, handler });\n\n/**\n * The entity's key as a literal, checked against `@entity({ key })` when the\n * module loads, so a path built from it cannot name a key the entity does not\n * carry.\n */\nexport const entityKey = <T extends Entity, const K extends string>(\n entityConstructor: EntityConstructor<T>,\n key: K,\n): K => {\n const declared = extractMetaEntity(entityConstructor).key;\n if (declared !== key)\n throw new Error(\n `entityKey(${entityConstructor.name}, '${key}') does not match ` +\n `@entity({ key: ${declared === undefined ? 'undefined' : `'${declared}'`} })`,\n );\n return key;\n};\n\n/**\n * A body an endpoint sends without describing it: whatever the handler\n * answers, as its JSON — `Date`s as ISO strings, `undefined` members dropped,\n * the way `JSON.stringify` writes it. For a record whose shape the entity\n * describes rather than a schema, and for an opaque document such as an\n * OpenAPI one. A body the endpoint can describe should be a schema instead.\n */\nexport const JsonBody: Schema.Codec<unknown, unknown> = Schema.Unknown.pipe(\n Schema.decodeTo(\n Schema.Unknown,\n SchemaTransformation.transform({\n decode: value => value,\n encode: value =>\n value === undefined\n ? null\n : (JSON.parse(JSON.stringify(value)) as unknown),\n }),\n ),\n);\n\n/** The annotation a body schema carries when it is not JSON on the wire. */\nexport const BODY_ENCODING = 'entifix/bodyEncoding';\n\n/** How a payload travels when it is not decoded as JSON, and under which media type. */\nexport interface BodyEncoding {\n readonly kind: 'text' | 'form';\n readonly contentType: string;\n}\n\n/**\n * A payload taken as the exact text that arrived, for an endpoint whose\n * authentication is a signature over those bytes: a decoded object\n * re-serialised is a different byte sequence, and the MAC would not verify.\n * `contentType` is the media type the caller sends — a provider that signs a\n * JSON body still sends `application/json`, and the bytes are what matter.\n */\nexport const textBody = (contentType = 'text/plain'): Schema.String =>\n Schema.String.annotate({\n [BODY_ENCODING]: { kind: 'text', contentType } satisfies BodyEncoding,\n });\n\n/**\n * A form-encoded payload (`application/x-www-form-urlencoded`), for a caller\n * a specification makes post one — an OpenID back-channel logout, say.\n */\nexport const formBody = <const Fields extends Schema.Struct.Fields>(\n fields: Fields,\n): Schema.Struct<Fields> =>\n Schema.Struct(fields).annotate({\n [BODY_ENCODING]: {\n kind: 'form',\n contentType: 'application/x-www-form-urlencoded',\n } satisfies BodyEncoding,\n });\n\n/** The wire encoding a payload schema declared, or `undefined` for JSON. */\nexport const bodyEncodingOf = (schema: Schema.Top): BodyEncoding | undefined =>\n (schema.ast.annotations as Record<string, unknown> | undefined)?.[\n BODY_ENCODING\n ] as BodyEncoding | undefined;\n"],"names":["Schema","SchemaTransformation","extractMetaEntity","defineEndpoint","descriptor","defineEndpoints","endpoints","implement","handler","entityKey","entityConstructor","key","declared","Error","name","undefined","JsonBody","Unknown","pipe","decodeTo","transform","decode","value","encode","JSON","parse","stringify","BODY_ENCODING","textBody","contentType","String","annotate","kind","formBody","fields","Struct","bodyEncodingOf","schema","ast","annotations"],"mappings":"AAAA,SAAsBA,MAAM,EAAEC,oBAAoB,QAAQ,SAAS;AAEnE,SAASC,iBAAiB,QAAQ,4DAA4D;AAmI9F;;;CAGC,GACD,OAAO,MAAMC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AAMO,iBAAiB,CAACC;QAC5BA;YAAAA,0BAAAA,OAAOC,GAAG,CAACC,WAAW,qBAAvB,AAACF,uBAAgE,CAC/DV,cACD;EAA6B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/core",
3
- "version": "0.23.1",
3
+ "version": "0.23.3",
4
4
  "description": "The entity system: decorators that make a class describe itself, entity serialization, the RSQL query protocol and the wire envelopes.",
5
5
  "license": "MIT",
6
6
  "repository": {