@entifix/core 0.23.4 → 0.23.6

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.
@@ -143,10 +143,16 @@ export declare const JsonBody: Schema.Codec<unknown, unknown>;
143
143
  /** The annotation a body schema carries when it is not JSON on the wire. */
144
144
  export declare const BODY_ENCODING = "entifix/bodyEncoding";
145
145
  /** How a payload travels when it is not decoded as JSON, and under which media type. */
146
- export interface BodyEncoding {
146
+ export type BodyEncoding = {
147
147
  readonly kind: 'text' | 'form';
148
148
  readonly contentType: string;
149
- }
149
+ } | {
150
+ readonly kind: 'binary';
151
+ /** The first of `contentTypes`: what a caller sends when it states none. */
152
+ readonly contentType: string;
153
+ readonly contentTypes: readonly [string, ...string[]];
154
+ readonly maxBytes: number;
155
+ };
150
156
  /**
151
157
  * A payload taken as the exact text that arrived, for an endpoint whose
152
158
  * authentication is a signature over those bytes: a decoded object
@@ -160,6 +166,42 @@ export declare const textBody: (contentType?: string) => Schema.String;
160
166
  * a specification makes post one — an OpenID back-channel logout, say.
161
167
  */
162
168
  export declare const formBody: <const Fields extends Schema.Struct.Fields>(fields: Fields) => Schema.Struct<Fields>;
169
+ /**
170
+ * A binary payload: the raw bytes that arrived, and the media type they were
171
+ * declared as. The type is one of the endpoint's `contentTypes` — anything
172
+ * else is refused `unsupportedMediaType` before a byte is read — but it is the
173
+ * caller's claim, so an endpoint that stores or serves the bytes sniffs them.
174
+ */
175
+ export interface BinaryBody<ContentType extends string = string> {
176
+ readonly bytes: Uint8Array;
177
+ readonly contentType: ContentType;
178
+ }
179
+ /**
180
+ * A payload of raw bytes (not base64 in JSON, which costs a third more), under
181
+ * one of `contentTypes` and at most `maxBytes`. The host reads up to the limit
182
+ * and no further, and refuses a larger body `payloadTooLarge`.
183
+ */
184
+ export declare const binaryBody: <const ContentTypes extends readonly [string, ...string[]]>(options: {
185
+ readonly contentTypes: ContentTypes;
186
+ readonly maxBytes: number;
187
+ }) => Schema.Codec<BinaryBody<ContentTypes[number]>>;
188
+ /** The annotation a success schema carries when the answer is not JSON. */
189
+ export declare const RESPONSE_ENCODING = "entifix/responseEncoding";
190
+ /**
191
+ * A binary answer: the bytes, the media type they are served as, and any
192
+ * headers the endpoint sets beside it — a `Content-Disposition`, a
193
+ * `Content-Security-Policy`. Unless one of them says otherwise the host still
194
+ * answers `Cache-Control: no-store`.
195
+ */
196
+ export interface BinaryReply {
197
+ readonly bytes: Uint8Array;
198
+ readonly contentType: string;
199
+ readonly headers?: Readonly<Record<string, string>>;
200
+ }
201
+ /** The success schema of an endpoint that answers raw bytes. */
202
+ export declare const binaryResponse: () => Schema.Codec<BinaryReply>;
203
+ /** Whether a success schema answers raw bytes rather than JSON. */
204
+ export declare const isBinaryResponse: (schema: Schema.Top) => boolean;
163
205
  /** The wire encoding a payload schema declared, or `undefined` for JSON. */
164
206
  export declare const bodyEncodingOf: (schema: Schema.Top) => BodyEncoding | undefined;
165
207
  export {};
@@ -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;;;;;;;;;;;;;;;;GAgBG;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,SAAS,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAA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,CAAC;AAEF,2EAA2E;AAC3E,eAAO,MAAM,iBAAiB,6BAA6B,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrD;AAED,gEAAgE;AAChE,eAAO,MAAM,cAAc,QAAO,MAAM,CAAC,KAAK,CAAC,WAAW,CAOd,CAAC;AAE7C,mEAAmE;AACnE,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,CAAC,GAAG,KAAG,OAGtC,CAAC;AAEjB,4EAA4E;AAC5E,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,CAAC,GAAG,KAAG,YAAY,GAAG,SAGpC,CAAC"}
@@ -53,6 +53,36 @@ import { extractMetaEntity } from '../entity-definition/helpers/entity-definitio
53
53
  contentType: 'application/x-www-form-urlencoded'
54
54
  }
55
55
  });
56
+ /**
57
+ * A payload of raw bytes (not base64 in JSON, which costs a third more), under
58
+ * one of `contentTypes` and at most `maxBytes`. The host reads up to the limit
59
+ * and no further, and refuses a larger body `payloadTooLarge`.
60
+ */ export const binaryBody = (options)=>{
61
+ if (!Number.isInteger(options.maxBytes) || options.maxBytes <= 0) throw new Error(`binaryBody: maxBytes must be a positive integer, got ${String(options.maxBytes)}`);
62
+ return Schema.Struct({
63
+ bytes: Schema.Uint8Array,
64
+ contentType: Schema.Literals(options.contentTypes)
65
+ }).annotate({
66
+ [BODY_ENCODING]: {
67
+ kind: 'binary',
68
+ contentType: options.contentTypes[0],
69
+ contentTypes: options.contentTypes,
70
+ maxBytes: options.maxBytes
71
+ }
72
+ });
73
+ };
74
+ /** The annotation a success schema carries when the answer is not JSON. */ export const RESPONSE_ENCODING = 'entifix/responseEncoding';
75
+ /** The success schema of an endpoint that answers raw bytes. */ export const binaryResponse = ()=>Schema.Struct({
76
+ bytes: Schema.Uint8Array,
77
+ contentType: Schema.String,
78
+ headers: Schema.optional(Schema.Record(Schema.String, Schema.String))
79
+ }).annotate({
80
+ [RESPONSE_ENCODING]: 'binary'
81
+ });
82
+ /** Whether a success schema answers raw bytes rather than JSON. */ export const isBinaryResponse = (schema)=>{
83
+ var _schema_ast_annotations;
84
+ return ((_schema_ast_annotations = schema.ast.annotations) == null ? void 0 : _schema_ast_annotations[RESPONSE_ENCODING]) === 'binary';
85
+ };
56
86
  /** The wire encoding a payload schema declared, or `undefined` for JSON. */ export const bodyEncodingOf = (schema)=>{
57
87
  var _schema_ast_annotations;
58
88
  return (_schema_ast_annotations = schema.ast.annotations) == null ? void 0 : _schema_ast_annotations[BODY_ENCODING];
@@ -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. 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,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 type BodyEncoding =\n | { readonly kind: 'text' | 'form'; readonly contentType: string }\n | {\n readonly kind: 'binary';\n /** The first of `contentTypes`: what a caller sends when it states none. */\n readonly contentType: string;\n readonly contentTypes: readonly [string, ...string[]];\n readonly maxBytes: number;\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/**\n * A binary payload: the raw bytes that arrived, and the media type they were\n * declared as. The type is one of the endpoint's `contentTypes` — anything\n * else is refused `unsupportedMediaType` before a byte is read — but it is the\n * caller's claim, so an endpoint that stores or serves the bytes sniffs them.\n */\nexport interface BinaryBody<ContentType extends string = string> {\n readonly bytes: Uint8Array;\n readonly contentType: ContentType;\n}\n\n/**\n * A payload of raw bytes (not base64 in JSON, which costs a third more), under\n * one of `contentTypes` and at most `maxBytes`. The host reads up to the limit\n * and no further, and refuses a larger body `payloadTooLarge`.\n */\nexport const binaryBody = <\n const ContentTypes extends readonly [string, ...string[]],\n>(options: {\n readonly contentTypes: ContentTypes;\n readonly maxBytes: number;\n}): Schema.Codec<BinaryBody<ContentTypes[number]>> => {\n if (!Number.isInteger(options.maxBytes) || options.maxBytes <= 0)\n throw new Error(\n `binaryBody: maxBytes must be a positive integer, got ${String(options.maxBytes)}`,\n );\n return Schema.Struct({\n bytes: Schema.Uint8Array,\n contentType: Schema.Literals(options.contentTypes),\n }).annotate({\n [BODY_ENCODING]: {\n kind: 'binary',\n contentType: options.contentTypes[0],\n contentTypes: options.contentTypes,\n maxBytes: options.maxBytes,\n } satisfies BodyEncoding,\n }) as unknown as Schema.Codec<BinaryBody<ContentTypes[number]>>;\n};\n\n/** The annotation a success schema carries when the answer is not JSON. */\nexport const RESPONSE_ENCODING = 'entifix/responseEncoding';\n\n/**\n * A binary answer: the bytes, the media type they are served as, and any\n * headers the endpoint sets beside it — a `Content-Disposition`, a\n * `Content-Security-Policy`. Unless one of them says otherwise the host still\n * answers `Cache-Control: no-store`.\n */\nexport interface BinaryReply {\n readonly bytes: Uint8Array;\n readonly contentType: string;\n readonly headers?: Readonly<Record<string, string>>;\n}\n\n/** The success schema of an endpoint that answers raw bytes. */\nexport const binaryResponse = (): Schema.Codec<BinaryReply> =>\n Schema.Struct({\n bytes: Schema.Uint8Array,\n contentType: Schema.String,\n headers: Schema.optional(Schema.Record(Schema.String, Schema.String)),\n }).annotate({\n [RESPONSE_ENCODING]: 'binary',\n }) as unknown as Schema.Codec<BinaryReply>;\n\n/** Whether a success schema answers raw bytes rather than JSON. */\nexport const isBinaryResponse = (schema: Schema.Top): boolean =>\n (schema.ast.annotations as Record<string, unknown> | undefined)?.[\n RESPONSE_ENCODING\n ] === 'binary';\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","binaryBody","options","Number","isInteger","maxBytes","bytes","Uint8Array","Literals","contentTypes","RESPONSE_ENCODING","binaryResponse","headers","optional","Record","isBinaryResponse","schema","ast","annotations","bodyEncodingOf"],"mappings":"AAAA,SAAsBA,MAAM,EAAEC,oBAAoB,QAAQ,SAAS;AAEnE,SAASC,iBAAiB,QAAQ,4DAA4D;AAmI9F;;;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;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AAE7C,iEAAiE,GACjE,OAAO,MAAMK,mBAAmB,CAACC;QAC9BA;WAAD,EAACA,0BAAAA,OAAOC,GAAG,CAACC,WAAW,qBAAvB,AAACF,uBAAgE,CAC/DN,kBACD,MAAK;EAAS;AAEjB,0EAA0E,GAC1E,OAAO,MAAMS,iBAAiB,CAACH;QAC5BA;YAAAA,0BAAAA,OAAOC,GAAG,CAACC,WAAW,qBAAvB,AAACF,uBAAgE,CAC/DxB,cACD;EAA6B"}
@@ -139,6 +139,25 @@ declare const Internal_base: Schema.Class<Internal, Schema.TaggedStruct<"Interna
139
139
  /** A bug, surfaced as a value. Never carries the bug's text onto a wire. */
140
140
  export declare class Internal extends Internal_base {
141
141
  }
142
+ declare const PayloadTooLarge_base: Schema.Class<PayloadTooLarge, Schema.TaggedStruct<"PayloadTooLarge", {
143
+ readonly maxBytes: Schema.Number;
144
+ }>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"payloadTooLarge", "invalid">>;
145
+ /**
146
+ * A request body larger than its endpoint accepts. Read up to the limit and no
147
+ * further: the bytes past it are never buffered. A host answers `413`.
148
+ */
149
+ export declare class PayloadTooLarge extends PayloadTooLarge_base {
150
+ }
151
+ declare const UnsupportedMediaType_base: Schema.Class<UnsupportedMediaType, Schema.TaggedStruct<"UnsupportedMediaType", {
152
+ readonly accepted: Schema.$Array<Schema.String>;
153
+ }>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"unsupportedMediaType", "invalid">>;
154
+ /**
155
+ * A request body declared as a media type its endpoint does not take. A host
156
+ * answers `415`. The declared type is the caller's claim, not the bytes' — an
157
+ * endpoint that cares what the bytes are still sniffs them.
158
+ */
159
+ export declare class UnsupportedMediaType extends UnsupportedMediaType_base {
160
+ }
142
161
  declare const IdempotencyKeyMissing_base: Schema.Class<IdempotencyKeyMissing, Schema.TaggedStruct<"IdempotencyKeyMissing", Record<never, never>>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"idempotencyKeyMissing", "invalid">>;
143
162
  /** An idempotent route was called without its `Idempotency-Key`. */
144
163
  export declare class IdempotencyKeyMissing extends IdempotencyKeyMissing_base {
@@ -1 +1 @@
1
- {"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/failure/generic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC;;;;;;GAMG;AAEH,kFAAkF;AAClF,eAAO,MAAM,YAAY;;;;EAIvB,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAC;;;;;;;;AAEpD,uEAAuE;AACvE,qBAAa,OAAQ,SAAQ,YAI5B;CAAG;;;;AAEJ,+DAA+D;AAC/D,qBAAa,YAAa,SAAQ,iBAKjC;CAAG;;;;AAEJ;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,oBAOpC;CAAG;;AAEJ,kDAAkD;AAClD,qBAAa,eAAgB,SAAQ,oBAEqB;CAAG;;;;AAE7D,2CAA2C;AAC3C,qBAAa,SAAU,SAAQ,cAM9B;CAAG;;AAEJ;;;;;;;;;;GAUG;AACH,qBAAa,oBAAqB,SAAQ,yBAE+B;CAAG;;;;AAE5E,2CAA2C;AAC3C,qBAAa,QAAS,SAAQ,aAI7B;CAAG;;;;AAEJ,sEAAsE;AACtE,qBAAa,YAAa,SAAQ,iBAIjC;CAAG;;;;;AAEJ;;;;;;;;GAQG;AACH,qBAAa,aAAc,SAAQ,kBAOlC;CAAG;;;;AAEJ,4DAA4D;AAC5D,qBAAa,QAAS,SAAQ,aAK7B;CAAG;;AAEJ,+EAA+E;AAC/E,qBAAa,UAAW,SAAQ,eAG/B;CAAG;;;;AAEJ,6EAA6E;AAC7E,qBAAa,UAAW,SAAQ,eAI/B;CAAG;;;;AAEJ,yCAAyC;AACzC,qBAAa,WAAY,SAAQ,gBAIhC;CAAG;;;;AAEJ,4DAA4D;AAC5D,qBAAa,mBAAoB,SAAQ,wBAIvC;CAAG;;;;AAEL,2CAA2C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AS7E,4DAA4D;AAC5D,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,UAGsB,CAAC"}
@@ -109,6 +109,21 @@ import { defineFailure } from './define.js';
109
109
  }
110
110
  /** A bug, surfaced as a value. Never carries the bug's text onto a wire. */ export class Internal extends defineFailure('internal')()('Internal', 'internal') {
111
111
  }
112
+ /**
113
+ * A request body larger than its endpoint accepts. Read up to the limit and no
114
+ * further: the bytes past it are never buffered. A host answers `413`.
115
+ */ export class PayloadTooLarge extends defineFailure('invalid')()('PayloadTooLarge', 'payloadTooLarge', {
116
+ maxBytes: Schema.Number
117
+ }) {
118
+ }
119
+ /**
120
+ * A request body declared as a media type its endpoint does not take. A host
121
+ * answers `415`. The declared type is the caller's claim, not the bytes' — an
122
+ * endpoint that cares what the bytes are still sniffs them.
123
+ */ export class UnsupportedMediaType extends defineFailure('invalid')()('UnsupportedMediaType', 'unsupportedMediaType', {
124
+ accepted: Schema.Array(Schema.String)
125
+ }) {
126
+ }
112
127
  /** An idempotent route was called without its `Idempotency-Key`. */ export class IdempotencyKeyMissing extends defineFailure('invalid')()('IdempotencyKeyMissing', 'idempotencyKeyMissing') {
113
128
  }
114
129
  /** One `Idempotency-Key` arrived with two different payloads. */ export class IdempotencyKeyReused extends defineFailure('declined')()('IdempotencyKeyReused', 'idempotencyKeyReused') {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/failure/generic.ts"],"sourcesContent":["import { Schema } from 'effect';\n\nimport { defineFailure } from './define.js';\n\n/**\n * The failures every host shares — the ones a framework route, an adapter or a\n * transport raises without knowing the domain it serves. A domain names its\n * own refusals beside these, through the same definers.\n *\n * Each code is permanent: a host's message catalog keys on it.\n */\n\n/** One field a request got wrong. `pointer` locates it, `code` names the rule. */\nexport const FieldProblem = Schema.Struct({\n pointer: Schema.String,\n detail: Schema.String,\n code: Schema.String,\n});\nexport type FieldProblem = typeof FieldProblem.Type;\n\n/** The request breaks rules on its own; every broken one is listed. */\nexport class Invalid extends defineFailure('invalid')<Invalid>()(\n 'Invalid',\n 'invalid',\n { errors: Schema.Array(FieldProblem) },\n) {}\n\n/** A list, filter or sort the query language cannot accept. */\nexport class InvalidQuery extends defineFailure('invalid')<InvalidQuery>()(\n 'InvalidQuery',\n 'invalidQuery',\n { reason: Schema.String },\n { message: ({ reason }) => reason },\n) {}\n\n/**\n * A payload that is not the envelope its reader expected. The sender's fault —\n * a `400` at an HTTP edge and poison on a bus, where redelivering the same\n * bytes produces the same refusal.\n */\nexport class InvalidEnvelope extends defineFailure(\n 'invalid',\n)<InvalidEnvelope>()(\n 'InvalidEnvelope',\n 'invalidEnvelope',\n { reason: Schema.String },\n { message: ({ reason }) => reason },\n) {}\n\n/** No credential, or one that does not verify. */\nexport class Unauthenticated extends defineFailure(\n 'unauthenticated',\n)<Unauthenticated>()('Unauthenticated', 'unauthenticated') {}\n\n/** A verified caller without the grant. */\nexport class Forbidden extends defineFailure('forbidden')<Forbidden>()(\n 'Forbidden',\n 'forbidden',\n // Which grant was missing: diagnostic, not a leak — the caller already\n // knows what it asked to do.\n { permission: Schema.optionalKey(Schema.String) },\n) {}\n\n/**\n * A signed-in caller whose session names no organization, on a route that acts\n * for one. A member of several organizations hits it before choosing one; the\n * code is what a client renders as \"select an organization\" instead of\n * \"forbidden\".\n *\n * Declared here rather than beside the guard that raises it, so every bundle\n * that decodes a problem knows the code: a browser loads no service shell, and\n * an unregistered code decodes as a protocol failure, losing the next step a\n * host registers for it.\n */\nexport class NoActiveOrganization extends defineFailure(\n 'conflict',\n)<NoActiveOrganization>()('NoActiveOrganization', 'noActiveOrganization') {}\n\n/** The addressed record does not exist. */\nexport class NotFound extends defineFailure('notFound')<NotFound>()(\n 'NotFound',\n 'notFound',\n { entity: Schema.optionalKey(Schema.String) },\n) {}\n\n/** A write that would duplicate a value the store declares unique. */\nexport class DuplicateKey extends defineFailure('conflict')<DuplicateKey>()(\n 'DuplicateKey',\n 'duplicateKey',\n { key: Schema.optionalKey(Schema.String) },\n) {}\n\n/**\n * A save named the revision it read, and the record has moved on: someone else\n * saved first (ADR 0032). A `conflict`, not a `contention` — a retry sends the\n * same stale revision and loses again; only a person who has seen the current\n * record can make the save succeed.\n *\n * `current` is the stored revision, so a client can tell \"changed since you read\n * it\" from \"deleted since\" (`NotFound`) without a second request.\n */\nexport class StaleRevision extends defineFailure('conflict')<StaleRevision>()(\n 'StaleRevision',\n 'staleRevision',\n {\n entity: Schema.optionalKey(Schema.String),\n current: Schema.optionalKey(Schema.Number),\n },\n) {}\n\n/** A third party, or a rule over other records, said no. */\nexport class Declined extends defineFailure('declined')<Declined>()(\n 'Declined',\n 'declined',\n { reason: Schema.optionalKey(Schema.String) },\n { message: ({ reason }) => reason ?? '' },\n) {}\n\n/** Lost a race that a retry can win — a claim taken, a transaction aborted. */\nexport class Contention extends defineFailure('contention')<Contention>()(\n 'Contention',\n 'contention',\n) {}\n\n/** The dependency asked for less load. Stops retries wherever it appears. */\nexport class Overloaded extends defineFailure('exhausted')<Overloaded>()(\n 'Overloaded',\n 'overloaded',\n { retryAfterSeconds: Schema.optionalKey(Schema.Number) },\n) {}\n\n/** A dependency could not be reached. */\nexport class Unavailable extends defineFailure('unavailable')<Unavailable>()(\n 'Unavailable',\n 'unavailable',\n { dependency: Schema.optionalKey(Schema.String) },\n) {}\n\n/** The service a proxy forwards to could not be reached. */\nexport class UpstreamUnavailable extends defineFailure(\n 'unavailable',\n)<UpstreamUnavailable>()('UpstreamUnavailable', 'upstreamUnavailable', {\n upstream: Schema.optionalKey(Schema.String),\n}) {}\n\n/** A dependency did not answer in time. */\nexport class Timeout extends defineFailure('timeout')<Timeout>()(\n 'Timeout',\n 'timeout',\n { dependency: Schema.optionalKey(Schema.String) },\n) {}\n\n/**\n * A peer answered something that does not decode — a body that is not a\n * problem, a code nothing registered, a document that does not match its\n * schema.\n */\nexport class ProtocolFailure extends defineFailure(\n 'protocol',\n)<ProtocolFailure>()(\n 'ProtocolFailure',\n 'protocol',\n {\n reason: Schema.String,\n upstreamStatus: Schema.optionalKey(Schema.Number),\n },\n { message: ({ reason }) => reason },\n) {}\n\n/** A bug, surfaced as a value. Never carries the bug's text onto a wire. */\nexport class Internal extends defineFailure('internal')<Internal>()(\n 'Internal',\n 'internal',\n) {}\n\n/** An idempotent route was called without its `Idempotency-Key`. */\nexport class IdempotencyKeyMissing extends defineFailure(\n 'invalid',\n)<IdempotencyKeyMissing>()('IdempotencyKeyMissing', 'idempotencyKeyMissing') {}\n\n/** One `Idempotency-Key` arrived with two different payloads. */\nexport class IdempotencyKeyReused extends defineFailure(\n 'declined',\n)<IdempotencyKeyReused>()('IdempotencyKeyReused', 'idempotencyKeyReused') {}\n\n/** The first request under this `Idempotency-Key` has not finished. */\nexport class IdempotencyKeyInFlight extends defineFailure(\n 'contention',\n)<IdempotencyKeyInFlight>()(\n 'IdempotencyKeyInFlight',\n 'idempotencyKeyInFlight',\n) {}\n\n/**\n * What a store adapter fails with — a datastore, a cache, a bus: the value it\n * guarded already exists, someone else got there first, it could not be\n * reached, it did not answer in time, or it answered something unreadable.\n * A port that talks to storage names this as its failure.\n */\nexport type StoreFailure =\n | DuplicateKey\n | StaleRevision\n | Contention\n | Unavailable\n | Timeout\n | ProtocolFailure;\n\n/**\n * The technical part of {@link StoreFailure}: the store failing to answer, as\n * opposed to answering no. A unit of work rolls back and surfaces these; a\n * business failure — a `DuplicateKey` included — is its abort.\n */\nexport type StoreFault = Exclude<StoreFailure, DuplicateKey | StaleRevision>;\n\nconst STORE_FAULT_TAGS: ReadonlySet<string> = new Set([\n 'Contention',\n 'Unavailable',\n 'Timeout',\n 'ProtocolFailure',\n]);\n\n/** Whether `value` is a {@link StoreFault}, read by tag. */\nexport const isStoreFault = (value: unknown): value is StoreFault =>\n typeof value === 'object' &&\n value !== null &&\n STORE_FAULT_TAGS.has((value as { readonly _tag?: unknown })._tag as string);\n"],"names":["Schema","defineFailure","FieldProblem","Struct","pointer","String","detail","code","Invalid","errors","Array","InvalidQuery","reason","message","InvalidEnvelope","Unauthenticated","Forbidden","permission","optionalKey","NoActiveOrganization","NotFound","entity","DuplicateKey","key","StaleRevision","current","Number","Declined","Contention","Overloaded","retryAfterSeconds","Unavailable","dependency","UpstreamUnavailable","upstream","Timeout","ProtocolFailure","upstreamStatus","Internal","IdempotencyKeyMissing","IdempotencyKeyReused","IdempotencyKeyInFlight","STORE_FAULT_TAGS","Set","isStoreFault","value","has","_tag"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,aAAa,QAAQ,cAAc;AAE5C;;;;;;CAMC,GAED,gFAAgF,GAChF,OAAO,MAAMC,eAAeF,OAAOG,MAAM,CAAC;IACxCC,SAASJ,OAAOK,MAAM;IACtBC,QAAQN,OAAOK,MAAM;IACrBE,MAAMP,OAAOK,MAAM;AACrB,GAAG;AAGH,qEAAqE,GACrE,OAAO,MAAMG,gBAAgBP,cAAc,aACzC,WACA,WACA;IAAEQ,QAAQT,OAAOU,KAAK,CAACR;AAAc;AACpC;AAEH,6DAA6D,GAC7D,OAAO,MAAMS,qBAAqBV,cAAc,aAC9C,gBACA,gBACA;IAAEW,QAAQZ,OAAOK,MAAM;AAAC,GACxB;IAAEQ,SAAS,CAAC,EAAED,MAAM,EAAE,GAAKA;AAAO;AACjC;AAEH;;;;CAIC,GACD,OAAO,MAAME,wBAAwBb,cACnC,aAEA,mBACA,mBACA;IAAEW,QAAQZ,OAAOK,MAAM;AAAC,GACxB;IAAEQ,SAAS,CAAC,EAAED,MAAM,EAAE,GAAKA;AAAO;AACjC;AAEH,gDAAgD,GAChD,OAAO,MAAMG,wBAAwBd,cACnC,qBACmB,mBAAmB;AAAoB;AAE5D,yCAAyC,GACzC,OAAO,MAAMe,kBAAkBf,cAAc,eAC3C,aACA,aACA,uEAAuE;AACvE,6BAA6B;AAC7B;IAAEgB,YAAYjB,OAAOkB,WAAW,CAAClB,OAAOK,MAAM;AAAE;AAC/C;AAEH;;;;;;;;;;CAUC,GACD,OAAO,MAAMc,6BAA6B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aACzC,WACA,WACA;IAAE+B,YAAYhC,OAAOkB,WAAW,CAAClB,OAAOK,MAAM;AAAE;AAC/C;AAEH;;;;CAIC,GACD,OAAO,MAAM+B,wBAAwBnC,cACnC,cAEA,mBACA,YACA;IACEW,QAAQZ,OAAOK,MAAM;IACrBgC,gBAAgBrC,OAAOkB,WAAW,CAAClB,OAAO0B,MAAM;AAClD,GACA;IAAEb,SAAS,CAAC,EAAED,MAAM,EAAE,GAAKA;AAAO;AACjC;AAEH,0EAA0E,GAC1E,OAAO,MAAM0B,iBAAiBrC,cAAc,cAC1C,YACA;AACC;AAEH,kEAAkE,GAClE,OAAO,MAAMsC,8BAA8BtC,cACzC,aACyB,yBAAyB;AAA0B;AAE9E,+DAA+D,GAC/D,OAAO,MAAMuC,6BAA6BvC,cACxC,cACwB,wBAAwB;AAAyB;AAE3E,qEAAqE,GACrE,OAAO,MAAMwC,+BAA+BxC,cAC1C,gBAEA,0BACA;AACC;AAuBH,MAAMyC,mBAAwC,IAAIC,IAAI;IACpD;IACA;IACA;IACA;CACD;AAED,0DAA0D,GAC1D,OAAO,MAAMC,eAAe,CAACC,QAC3B,OAAOA,UAAU,YACjBA,UAAU,QACVH,iBAAiBI,GAAG,CAAC,AAACD,MAAsCE,IAAI,EAAY"}
1
+ {"version":3,"sources":["../../src/failure/generic.ts"],"sourcesContent":["import { Schema } from 'effect';\n\nimport { defineFailure } from './define.js';\n\n/**\n * The failures every host shares — the ones a framework route, an adapter or a\n * transport raises without knowing the domain it serves. A domain names its\n * own refusals beside these, through the same definers.\n *\n * Each code is permanent: a host's message catalog keys on it.\n */\n\n/** One field a request got wrong. `pointer` locates it, `code` names the rule. */\nexport const FieldProblem = Schema.Struct({\n pointer: Schema.String,\n detail: Schema.String,\n code: Schema.String,\n});\nexport type FieldProblem = typeof FieldProblem.Type;\n\n/** The request breaks rules on its own; every broken one is listed. */\nexport class Invalid extends defineFailure('invalid')<Invalid>()(\n 'Invalid',\n 'invalid',\n { errors: Schema.Array(FieldProblem) },\n) {}\n\n/** A list, filter or sort the query language cannot accept. */\nexport class InvalidQuery extends defineFailure('invalid')<InvalidQuery>()(\n 'InvalidQuery',\n 'invalidQuery',\n { reason: Schema.String },\n { message: ({ reason }) => reason },\n) {}\n\n/**\n * A payload that is not the envelope its reader expected. The sender's fault —\n * a `400` at an HTTP edge and poison on a bus, where redelivering the same\n * bytes produces the same refusal.\n */\nexport class InvalidEnvelope extends defineFailure(\n 'invalid',\n)<InvalidEnvelope>()(\n 'InvalidEnvelope',\n 'invalidEnvelope',\n { reason: Schema.String },\n { message: ({ reason }) => reason },\n) {}\n\n/** No credential, or one that does not verify. */\nexport class Unauthenticated extends defineFailure(\n 'unauthenticated',\n)<Unauthenticated>()('Unauthenticated', 'unauthenticated') {}\n\n/** A verified caller without the grant. */\nexport class Forbidden extends defineFailure('forbidden')<Forbidden>()(\n 'Forbidden',\n 'forbidden',\n // Which grant was missing: diagnostic, not a leak — the caller already\n // knows what it asked to do.\n { permission: Schema.optionalKey(Schema.String) },\n) {}\n\n/**\n * A signed-in caller whose session names no organization, on a route that acts\n * for one. A member of several organizations hits it before choosing one; the\n * code is what a client renders as \"select an organization\" instead of\n * \"forbidden\".\n *\n * Declared here rather than beside the guard that raises it, so every bundle\n * that decodes a problem knows the code: a browser loads no service shell, and\n * an unregistered code decodes as a protocol failure, losing the next step a\n * host registers for it.\n */\nexport class NoActiveOrganization extends defineFailure(\n 'conflict',\n)<NoActiveOrganization>()('NoActiveOrganization', 'noActiveOrganization') {}\n\n/** The addressed record does not exist. */\nexport class NotFound extends defineFailure('notFound')<NotFound>()(\n 'NotFound',\n 'notFound',\n { entity: Schema.optionalKey(Schema.String) },\n) {}\n\n/** A write that would duplicate a value the store declares unique. */\nexport class DuplicateKey extends defineFailure('conflict')<DuplicateKey>()(\n 'DuplicateKey',\n 'duplicateKey',\n { key: Schema.optionalKey(Schema.String) },\n) {}\n\n/**\n * A save named the revision it read, and the record has moved on: someone else\n * saved first (ADR 0032). A `conflict`, not a `contention` — a retry sends the\n * same stale revision and loses again; only a person who has seen the current\n * record can make the save succeed.\n *\n * `current` is the stored revision, so a client can tell \"changed since you read\n * it\" from \"deleted since\" (`NotFound`) without a second request.\n */\nexport class StaleRevision extends defineFailure('conflict')<StaleRevision>()(\n 'StaleRevision',\n 'staleRevision',\n {\n entity: Schema.optionalKey(Schema.String),\n current: Schema.optionalKey(Schema.Number),\n },\n) {}\n\n/** A third party, or a rule over other records, said no. */\nexport class Declined extends defineFailure('declined')<Declined>()(\n 'Declined',\n 'declined',\n { reason: Schema.optionalKey(Schema.String) },\n { message: ({ reason }) => reason ?? '' },\n) {}\n\n/** Lost a race that a retry can win — a claim taken, a transaction aborted. */\nexport class Contention extends defineFailure('contention')<Contention>()(\n 'Contention',\n 'contention',\n) {}\n\n/** The dependency asked for less load. Stops retries wherever it appears. */\nexport class Overloaded extends defineFailure('exhausted')<Overloaded>()(\n 'Overloaded',\n 'overloaded',\n { retryAfterSeconds: Schema.optionalKey(Schema.Number) },\n) {}\n\n/** A dependency could not be reached. */\nexport class Unavailable extends defineFailure('unavailable')<Unavailable>()(\n 'Unavailable',\n 'unavailable',\n { dependency: Schema.optionalKey(Schema.String) },\n) {}\n\n/** The service a proxy forwards to could not be reached. */\nexport class UpstreamUnavailable extends defineFailure(\n 'unavailable',\n)<UpstreamUnavailable>()('UpstreamUnavailable', 'upstreamUnavailable', {\n upstream: Schema.optionalKey(Schema.String),\n}) {}\n\n/** A dependency did not answer in time. */\nexport class Timeout extends defineFailure('timeout')<Timeout>()(\n 'Timeout',\n 'timeout',\n { dependency: Schema.optionalKey(Schema.String) },\n) {}\n\n/**\n * A peer answered something that does not decode — a body that is not a\n * problem, a code nothing registered, a document that does not match its\n * schema.\n */\nexport class ProtocolFailure extends defineFailure(\n 'protocol',\n)<ProtocolFailure>()(\n 'ProtocolFailure',\n 'protocol',\n {\n reason: Schema.String,\n upstreamStatus: Schema.optionalKey(Schema.Number),\n },\n { message: ({ reason }) => reason },\n) {}\n\n/** A bug, surfaced as a value. Never carries the bug's text onto a wire. */\nexport class Internal extends defineFailure('internal')<Internal>()(\n 'Internal',\n 'internal',\n) {}\n\n/**\n * A request body larger than its endpoint accepts. Read up to the limit and no\n * further: the bytes past it are never buffered. A host answers `413`.\n */\nexport class PayloadTooLarge extends defineFailure(\n 'invalid',\n)<PayloadTooLarge>()('PayloadTooLarge', 'payloadTooLarge', {\n maxBytes: Schema.Number,\n}) {}\n\n/**\n * A request body declared as a media type its endpoint does not take. A host\n * answers `415`. The declared type is the caller's claim, not the bytes' — an\n * endpoint that cares what the bytes are still sniffs them.\n */\nexport class UnsupportedMediaType extends defineFailure(\n 'invalid',\n)<UnsupportedMediaType>()('UnsupportedMediaType', 'unsupportedMediaType', {\n accepted: Schema.Array(Schema.String),\n}) {}\n\n/** An idempotent route was called without its `Idempotency-Key`. */\nexport class IdempotencyKeyMissing extends defineFailure(\n 'invalid',\n)<IdempotencyKeyMissing>()('IdempotencyKeyMissing', 'idempotencyKeyMissing') {}\n\n/** One `Idempotency-Key` arrived with two different payloads. */\nexport class IdempotencyKeyReused extends defineFailure(\n 'declined',\n)<IdempotencyKeyReused>()('IdempotencyKeyReused', 'idempotencyKeyReused') {}\n\n/** The first request under this `Idempotency-Key` has not finished. */\nexport class IdempotencyKeyInFlight extends defineFailure(\n 'contention',\n)<IdempotencyKeyInFlight>()(\n 'IdempotencyKeyInFlight',\n 'idempotencyKeyInFlight',\n) {}\n\n/**\n * What a store adapter fails with — a datastore, a cache, a bus: the value it\n * guarded already exists, someone else got there first, it could not be\n * reached, it did not answer in time, or it answered something unreadable.\n * A port that talks to storage names this as its failure.\n */\nexport type StoreFailure =\n | DuplicateKey\n | StaleRevision\n | Contention\n | Unavailable\n | Timeout\n | ProtocolFailure;\n\n/**\n * The technical part of {@link StoreFailure}: the store failing to answer, as\n * opposed to answering no. A unit of work rolls back and surfaces these; a\n * business failure — a `DuplicateKey` included — is its abort.\n */\nexport type StoreFault = Exclude<StoreFailure, DuplicateKey | StaleRevision>;\n\nconst STORE_FAULT_TAGS: ReadonlySet<string> = new Set([\n 'Contention',\n 'Unavailable',\n 'Timeout',\n 'ProtocolFailure',\n]);\n\n/** Whether `value` is a {@link StoreFault}, read by tag. */\nexport const isStoreFault = (value: unknown): value is StoreFault =>\n typeof value === 'object' &&\n value !== null &&\n STORE_FAULT_TAGS.has((value as { readonly _tag?: unknown })._tag as string);\n"],"names":["Schema","defineFailure","FieldProblem","Struct","pointer","String","detail","code","Invalid","errors","Array","InvalidQuery","reason","message","InvalidEnvelope","Unauthenticated","Forbidden","permission","optionalKey","NoActiveOrganization","NotFound","entity","DuplicateKey","key","StaleRevision","current","Number","Declined","Contention","Overloaded","retryAfterSeconds","Unavailable","dependency","UpstreamUnavailable","upstream","Timeout","ProtocolFailure","upstreamStatus","Internal","PayloadTooLarge","maxBytes","UnsupportedMediaType","accepted","IdempotencyKeyMissing","IdempotencyKeyReused","IdempotencyKeyInFlight","STORE_FAULT_TAGS","Set","isStoreFault","value","has","_tag"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,aAAa,QAAQ,cAAc;AAE5C;;;;;;CAMC,GAED,gFAAgF,GAChF,OAAO,MAAMC,eAAeF,OAAOG,MAAM,CAAC;IACxCC,SAASJ,OAAOK,MAAM;IACtBC,QAAQN,OAAOK,MAAM;IACrBE,MAAMP,OAAOK,MAAM;AACrB,GAAG;AAGH,qEAAqE,GACrE,OAAO,MAAMG,gBAAgBP,cAAc,aACzC,WACA,WACA;IAAEQ,QAAQT,OAAOU,KAAK,CAACR;AAAc;AACpC;AAEH,6DAA6D,GAC7D,OAAO,MAAMS,qBAAqBV,cAAc,aAC9C,gBACA,gBACA;IAAEW,QAAQZ,OAAOK,MAAM;AAAC,GACxB;IAAEQ,SAAS,CAAC,EAAED,MAAM,EAAE,GAAKA;AAAO;AACjC;AAEH;;;;CAIC,GACD,OAAO,MAAME,wBAAwBb,cACnC,aAEA,mBACA,mBACA;IAAEW,Q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,mBAAwC,IAAIC,IAAI;IACpD;IACA;IACA;IACA;CACD;AAED,0DAA0D,GAC1D,OAAO,MAAMC,eAAe,CAACC,QAC3B,OAAOA,UAAU,YACjBA,UAAU,QACVH,iBAAiBI,GAAG,CAAC,AAACD,MAAsCE,IAAI,EAAY"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/core",
3
- "version": "0.23.4",
3
+ "version": "0.23.6",
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": {