lanka 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{LankaError-B1HtuIkw.d.ts → LankaError-xpI-qj35.d.ts} +15 -2
- package/dist/_extend/index.js +3 -3
- package/dist/bootstrap/index.js +3 -3
- package/dist/{chunk-LMKLLEHA.js → chunk-ECM2HZHS.js} +5 -5
- package/dist/{chunk-5MAQVBI2.js → chunk-GK3E4CVW.js} +4 -4
- package/dist/{chunk-D5WKKEIR.js → chunk-GV5DUYST.js} +17 -7
- package/dist/chunk-GV5DUYST.js.map +1 -0
- package/dist/errors/index.d.ts +2 -3
- package/dist/gateway/index.js +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +3 -3
- package/dist/validation/index.d.ts +13 -8
- package/dist/validation/index.js +2 -1
- package/package.json +1 -1
- package/skills/lanka-core/SKILL.md +1 -1
- package/skills/lanka-core/reference.md +1 -1
- package/skills/lanka-packages/SKILL.md +1 -1
- package/dist/ILankaApiError-zI_2bNs0.d.ts +0 -16
- package/dist/chunk-D5WKKEIR.js.map +0 -1
- /package/dist/{chunk-LMKLLEHA.js.map → chunk-ECM2HZHS.js.map} +0 -0
- /package/dist/{chunk-5MAQVBI2.js.map → chunk-GK3E4CVW.js.map} +0 -0
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Structural API-error shape read by consumer code.
|
|
3
|
+
*
|
|
4
|
+
* `status` is OPTIONAL: a network drop and an aborted request carry no status,
|
|
5
|
+
* and three of the six `LankaError` kinds have none.
|
|
6
|
+
*
|
|
7
|
+
* `LankaError` implements this interface, so consumers may read `status` and
|
|
8
|
+
* `errors` off any thrown framework error.
|
|
9
|
+
*/
|
|
10
|
+
interface ILankaApiError {
|
|
11
|
+
status?: number;
|
|
12
|
+
errors?: string[];
|
|
13
|
+
message?: string;
|
|
14
|
+
}
|
|
2
15
|
|
|
3
16
|
/**
|
|
4
17
|
* How a request ended.
|
|
@@ -83,4 +96,4 @@ declare class LankaError extends Error implements ILankaApiError {
|
|
|
83
96
|
static is(value: unknown): value is LankaError;
|
|
84
97
|
}
|
|
85
98
|
|
|
86
|
-
export { type ILankaErrorInit as I, LankaError as L, type TLankaErrorKind as T };
|
|
99
|
+
export { type ILankaErrorInit as I, LankaError as L, type TLankaErrorKind as T, type ILankaApiError as a };
|
package/dist/_extend/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
LankaGatewayLocator,
|
|
3
3
|
LankaScenarioLocator,
|
|
4
4
|
createLankaScope
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-GK3E4CVW.js";
|
|
6
6
|
import {
|
|
7
7
|
LankaScenarioVMRegistry,
|
|
8
8
|
LankaScenariosRegistry
|
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
composeLankaRequestMiddleware
|
|
12
12
|
} from "../chunk-YR4MZXMU.js";
|
|
13
|
+
import "../chunk-C2HP7CRD.js";
|
|
14
|
+
import "../chunk-D27MREPB.js";
|
|
13
15
|
import {
|
|
14
16
|
createLankaLocatorProxy
|
|
15
17
|
} from "../chunk-DTO27QFR.js";
|
|
@@ -18,8 +20,6 @@ import {
|
|
|
18
20
|
LankaSharedStoreLocator,
|
|
19
21
|
LankaSingletonLocator
|
|
20
22
|
} from "../chunk-UE2C76OR.js";
|
|
21
|
-
import "../chunk-C2HP7CRD.js";
|
|
22
|
-
import "../chunk-D27MREPB.js";
|
|
23
23
|
import "../chunk-BGVDPDX4.js";
|
|
24
24
|
export {
|
|
25
25
|
ALankaLocator,
|
package/dist/bootstrap/index.js
CHANGED
|
@@ -3,15 +3,15 @@ import {
|
|
|
3
3
|
createLanka,
|
|
4
4
|
resetActiveLanka,
|
|
5
5
|
startLanka
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-ECM2HZHS.js";
|
|
7
7
|
import "../chunk-UGXSGQPW.js";
|
|
8
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-GK3E4CVW.js";
|
|
9
9
|
import "../chunk-O5ROO7QF.js";
|
|
10
10
|
import "../chunk-XESL274R.js";
|
|
11
11
|
import "../chunk-UJEC7H6K.js";
|
|
12
|
-
import "../chunk-UE2C76OR.js";
|
|
13
12
|
import "../chunk-C2HP7CRD.js";
|
|
14
13
|
import "../chunk-D27MREPB.js";
|
|
14
|
+
import "../chunk-UE2C76OR.js";
|
|
15
15
|
import "../chunk-BGVDPDX4.js";
|
|
16
16
|
export {
|
|
17
17
|
ALankaPlugin,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
LankaGatewayLocator,
|
|
6
6
|
LankaScenarioLocator,
|
|
7
7
|
createLankaScope
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-GK3E4CVW.js";
|
|
9
9
|
import {
|
|
10
10
|
LankaScenarioVMRegistry,
|
|
11
11
|
LankaScenariosRegistry
|
|
@@ -16,13 +16,13 @@ import {
|
|
|
16
16
|
import {
|
|
17
17
|
createInFlightCounter
|
|
18
18
|
} from "./chunk-UJEC7H6K.js";
|
|
19
|
+
import {
|
|
20
|
+
lankaLogger
|
|
21
|
+
} from "./chunk-C2HP7CRD.js";
|
|
19
22
|
import {
|
|
20
23
|
LankaSharedStoreLocator,
|
|
21
24
|
LankaSingletonLocator
|
|
22
25
|
} from "./chunk-UE2C76OR.js";
|
|
23
|
-
import {
|
|
24
|
-
lankaLogger
|
|
25
|
-
} from "./chunk-C2HP7CRD.js";
|
|
26
26
|
import {
|
|
27
27
|
getActiveRuntime,
|
|
28
28
|
setActiveRuntime
|
|
@@ -720,4 +720,4 @@ export {
|
|
|
720
720
|
resetActiveLanka,
|
|
721
721
|
ALankaPlugin
|
|
722
722
|
};
|
|
723
|
-
//# sourceMappingURL=chunk-
|
|
723
|
+
//# sourceMappingURL=chunk-ECM2HZHS.js.map
|
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
ALankaScenario,
|
|
3
3
|
LankaScenariosRegistry
|
|
4
4
|
} from "./chunk-O5ROO7QF.js";
|
|
5
|
+
import {
|
|
6
|
+
lankaLogger
|
|
7
|
+
} from "./chunk-C2HP7CRD.js";
|
|
5
8
|
import {
|
|
6
9
|
ALankaLocator,
|
|
7
10
|
caseConvert,
|
|
8
11
|
findExportedClass
|
|
9
12
|
} from "./chunk-UE2C76OR.js";
|
|
10
|
-
import {
|
|
11
|
-
lankaLogger
|
|
12
|
-
} from "./chunk-C2HP7CRD.js";
|
|
13
13
|
|
|
14
14
|
// src/locator/gateway/lanka-gateway-locator/LankaGatewayLocator.ts
|
|
15
15
|
import * as GatewaysModule from "@lanka_di/Gateways";
|
|
@@ -136,4 +136,4 @@ export {
|
|
|
136
136
|
LankaScenarioLocator,
|
|
137
137
|
createLankaScope
|
|
138
138
|
};
|
|
139
|
-
//# sourceMappingURL=chunk-
|
|
139
|
+
//# sourceMappingURL=chunk-GK3E4CVW.js.map
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LankaError
|
|
3
|
+
} from "./chunk-Q7QESSYF.js";
|
|
4
|
+
|
|
1
5
|
// src/validation/lanka-validation-error/LankaValidationError.ts
|
|
2
|
-
var LankaValidationError = class extends
|
|
3
|
-
status;
|
|
4
|
-
errors;
|
|
6
|
+
var LankaValidationError = class _LankaValidationError extends LankaError {
|
|
5
7
|
constructor(message, errors = []) {
|
|
6
|
-
super(
|
|
8
|
+
super({
|
|
9
|
+
kind: "schema",
|
|
10
|
+
message,
|
|
11
|
+
status: 422,
|
|
12
|
+
issues: errors.length > 0 ? errors : [message]
|
|
13
|
+
});
|
|
7
14
|
this.name = "LankaValidationError";
|
|
8
|
-
this.
|
|
9
|
-
|
|
15
|
+
Object.setPrototypeOf(this, _LankaValidationError.prototype);
|
|
16
|
+
}
|
|
17
|
+
/** Always present here, unlike the base's optional list. */
|
|
18
|
+
get errors() {
|
|
19
|
+
return [...this.issues ?? []];
|
|
10
20
|
}
|
|
11
21
|
};
|
|
12
22
|
|
|
@@ -51,4 +61,4 @@ export {
|
|
|
51
61
|
LankaValidationError,
|
|
52
62
|
lankaStandardValidator
|
|
53
63
|
};
|
|
54
|
-
//# sourceMappingURL=chunk-
|
|
64
|
+
//# sourceMappingURL=chunk-GV5DUYST.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/validation/lanka-validation-error/LankaValidationError.ts","../src/validation/lanka-standard-validator/lankaStandardValidator.ts"],"sourcesContent":["import { LankaError } from \"../../errors/lanka-error/LankaError\";\n\n/**\n * The validation port's failure: a body the schema refused.\n *\n * A `LankaError` of kind `schema`, so that `LankaError.is` and everything built\n * on it — the HTTP policy's error middleware, an application branching on\n * `kind` — see a refused body the way they see the request layer's own\n * \"200 that was not JSON\". It used to extend `Error` directly, and a consumer\n * that told a contract drift from a network failure by `kind` never saw it.\n *\n * `name` stays `LankaValidationError` and `status` stays 422: both are what a\n * consumer's existing `catch` reads, and the message list is `errors`.\n */\nexport class LankaValidationError extends LankaError {\n\tconstructor(message: string, errors: string[] = []) {\n\t\tsuper({\n\t\t\tkind: \"schema\",\n\t\t\tmessage,\n\t\t\tstatus: 422,\n\t\t\tissues: errors.length > 0 ? errors : [message],\n\t\t});\n\t\tthis.name = \"LankaValidationError\";\n\t\tObject.setPrototypeOf(this, LankaValidationError.prototype);\n\t}\n\n\t/** Always present here, unlike the base's optional list. */\n\toverride get errors(): string[] {\n\t\treturn [...(this.issues ?? [])];\n\t}\n}\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { LankaValidationError } from \"../lanka-validation-error/LankaValidationError\";\nimport type { TLankaValidationResult } from \"../_types/TLankaValidationResult\";\n\n/**\n * Response body validation with any Standard Schema implementation.\n *\n * An abstraction typed by one library cannot be implemented by another, which is\n * the whole reason a validation port exists. Standard Schema is the shared\n * interface implemented by zod 4, valibot, arktype and others.\n *\n * `@standard-schema/spec` contains TYPES ONLY and adds no bytes to a build, so it\n * is a regular dependency rather than another peer.\n *\n * No adapter classes: a schema describes itself, and\n * `schema[\"~standard\"].validate(data)` is the whole protocol.\n */\n\n/** A schema the port understands: any Standard Schema implementation. */\nexport type TLankaSchema<TOutput = unknown> = StandardSchemaV1<unknown, TOutput>;\n\nexport interface ILankaValidator {\n\t/** Validates and returns the parsed value, or throws. */\n\tvalidate<TOutput>(schema: TLankaSchema<TOutput>, data: unknown, context: string): TOutput;\n\t/** Validates and returns an outcome, throwing nothing. */\n\tvalidateSafe<TOutput>(\n\t\tschema: TLankaSchema<TOutput>,\n\t\tdata: unknown,\n\t): TLankaValidationResult<TOutput>;\n}\n\n/**\n * A field path plus a message.\n *\n * The path is assembled WHOLE — `items.0.id`, not `id`. Without the index and the\n * parent the message points nowhere when the list has twenty items.\n */\nfunction describeIssue(issue: StandardSchemaV1.Issue): string {\n\tconst path = (issue.path ?? [])\n\t\t.map((segment) =>\n\t\t\ttypeof segment === \"object\" && segment !== null && \"key\" in segment\n\t\t\t\t? String(segment.key)\n\t\t\t\t: String(segment),\n\t\t)\n\t\t.join(\".\");\n\n\treturn path ? `${path}: ${issue.message}` : issue.message;\n}\n\nfunction runSync<TOutput>(\n\tschema: TLankaSchema<TOutput>,\n\tdata: unknown,\n): StandardSchemaV1.Result<TOutput> {\n\tconst result = schema[\"~standard\"].validate(data);\n\n\t// Standard Schema allows returning a promise. A synchronous port cannot await\n\t// it, and answering \"fine\" would let UNVALIDATED data through — a check that\n\t// cannot fail reporting success.\n\tif (result instanceof Promise) {\n\t\tthrow new LankaValidationError(\n\t\t\t\"The schema is asynchronous and the validation port is synchronous. Parse \" +\n\t\t\t\t\"such data by hand: passing it silently would be worse than failing.\",\n\t\t\t[],\n\t\t);\n\t}\n\n\treturn result;\n}\n\nexport const lankaStandardValidator: ILankaValidator = Object.freeze<ILankaValidator>({\n\tvalidate<TOutput>(schema: TLankaSchema<TOutput>, data: unknown, context: string): TOutput {\n\t\tconst result = runSync(schema, data);\n\n\t\tif (result.issues) {\n\t\t\tthrow new LankaValidationError(\n\t\t\t\t`Validation failed for ${context}`,\n\t\t\t\tresult.issues.map(describeIssue),\n\t\t\t);\n\t\t}\n\n\t\treturn result.value;\n\t},\n\n\tvalidateSafe<TOutput>(\n\t\tschema: TLankaSchema<TOutput>,\n\t\tdata: unknown,\n\t): TLankaValidationResult<TOutput> {\n\t\tconst result = runSync(schema, data);\n\n\t\tif (result.issues) {\n\t\t\treturn { success: false, errors: result.issues.map(describeIssue) };\n\t\t}\n\n\t\treturn { success: true, data: result.value };\n\t},\n});\n"],"mappings":";;;;;AAcO,IAAM,uBAAN,MAAM,8BAA6B,WAAW;AAAA,EACpD,YAAY,SAAiB,SAAmB,CAAC,GAAG;AACnD,UAAM;AAAA,MACL,MAAM;AAAA,MACN;AAAA,MACA,QAAQ;AAAA,MACR,QAAQ,OAAO,SAAS,IAAI,SAAS,CAAC,OAAO;AAAA,IAC9C,CAAC;AACD,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,sBAAqB,SAAS;AAAA,EAC3D;AAAA;AAAA,EAGA,IAAa,SAAmB;AAC/B,WAAO,CAAC,GAAI,KAAK,UAAU,CAAC,CAAE;AAAA,EAC/B;AACD;;;ACOA,SAAS,cAAc,OAAuC;AAC7D,QAAM,QAAQ,MAAM,QAAQ,CAAC,GAC3B;AAAA,IAAI,CAAC,YACL,OAAO,YAAY,YAAY,YAAY,QAAQ,SAAS,UACzD,OAAO,QAAQ,GAAG,IAClB,OAAO,OAAO;AAAA,EAClB,EACC,KAAK,GAAG;AAEV,SAAO,OAAO,GAAG,IAAI,KAAK,MAAM,OAAO,KAAK,MAAM;AACnD;AAEA,SAAS,QACR,QACA,MACmC;AACnC,QAAM,SAAS,OAAO,WAAW,EAAE,SAAS,IAAI;AAKhD,MAAI,kBAAkB,SAAS;AAC9B,UAAM,IAAI;AAAA,MACT;AAAA,MAEA,CAAC;AAAA,IACF;AAAA,EACD;AAEA,SAAO;AACR;AAEO,IAAM,yBAA0C,OAAO,OAAwB;AAAA,EACrF,SAAkB,QAA+B,MAAe,SAA0B;AACzF,UAAM,SAAS,QAAQ,QAAQ,IAAI;AAEnC,QAAI,OAAO,QAAQ;AAClB,YAAM,IAAI;AAAA,QACT,yBAAyB,OAAO;AAAA,QAChC,OAAO,OAAO,IAAI,aAAa;AAAA,MAChC;AAAA,IACD;AAEA,WAAO,OAAO;AAAA,EACf;AAAA,EAEA,aACC,QACA,MACkC;AAClC,UAAM,SAAS,QAAQ,QAAQ,IAAI;AAEnC,QAAI,OAAO,QAAQ;AAClB,aAAO,EAAE,SAAS,OAAO,QAAQ,OAAO,OAAO,IAAI,aAAa,EAAE;AAAA,IACnE;AAEA,WAAO,EAAE,SAAS,MAAM,MAAM,OAAO,MAAM;AAAA,EAC5C;AACD,CAAC;","names":[]}
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { L as LankaError } from '../LankaError-
|
|
2
|
-
export { I as ILankaErrorInit, T as TLankaErrorKind } from '../LankaError-
|
|
3
|
-
export { I as ILankaApiError } from '../ILankaApiError-zI_2bNs0.js';
|
|
1
|
+
import { L as LankaError } from '../LankaError-xpI-qj35.js';
|
|
2
|
+
export { a as ILankaApiError, I as ILankaErrorInit, T as TLankaErrorKind } from '../LankaError-xpI-qj35.js';
|
|
4
3
|
export { T as TLankaErrorHandler } from '../TLankaErrorHandler-Yfqtdh1M.js';
|
|
5
4
|
|
|
6
5
|
/**
|
package/dist/gateway/index.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { ILankaHostConfig, createLankaHost, getLankaFlags, getLankaHost } from '
|
|
|
5
5
|
export { I as ILankaFlags, a as ILankaHost, b as ILankaRuntimeConfig } from './ILankaRuntimeConfig-Vl436GWK.js';
|
|
6
6
|
export { I as ILankaLocatorConfig } from './LankaSharedStoreLocator-zS2kLu-S.js';
|
|
7
7
|
export { lankaLogger } from './logger/index.js';
|
|
8
|
-
export { I as ILankaErrorInit, L as LankaError, T as TLankaErrorKind } from './LankaError-
|
|
8
|
+
export { I as ILankaErrorInit, L as LankaError, T as TLankaErrorKind } from './LankaError-xpI-qj35.js';
|
|
9
9
|
import './createLankaScope-BiFxNQgl.js';
|
|
10
10
|
import './activeRuntime-B336NU5I.js';
|
|
11
11
|
import './ILankaScenarioVM-DUsI-fSc.js';
|
|
@@ -18,4 +18,3 @@ import './lankaHttpInFlight-Bk1eIuSx.js';
|
|
|
18
18
|
import './lankaRequestMiddleware-DAC5kCb7.js';
|
|
19
19
|
import './ALankaSharedStore-B7uepuuk.js';
|
|
20
20
|
import 'zustand/vanilla';
|
|
21
|
-
import './ILankaApiError-zI_2bNs0.js';
|
package/dist/index.js
CHANGED
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
createLanka,
|
|
7
7
|
resetActiveLanka,
|
|
8
8
|
startLanka
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-ECM2HZHS.js";
|
|
10
10
|
import "./chunk-UGXSGQPW.js";
|
|
11
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-GK3E4CVW.js";
|
|
12
12
|
import "./chunk-O5ROO7QF.js";
|
|
13
13
|
import {
|
|
14
14
|
createLankaHost
|
|
@@ -20,13 +20,13 @@ import {
|
|
|
20
20
|
import {
|
|
21
21
|
getLankaHost
|
|
22
22
|
} from "./chunk-RKYKK6MN.js";
|
|
23
|
-
import "./chunk-UE2C76OR.js";
|
|
24
23
|
import {
|
|
25
24
|
lankaLogger
|
|
26
25
|
} from "./chunk-C2HP7CRD.js";
|
|
27
26
|
import {
|
|
28
27
|
getLankaFlags
|
|
29
28
|
} from "./chunk-D27MREPB.js";
|
|
29
|
+
import "./chunk-UE2C76OR.js";
|
|
30
30
|
import "./chunk-BGVDPDX4.js";
|
|
31
31
|
export {
|
|
32
32
|
ALankaPlugin,
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
export { I as ILankaValidator, T as TLankaSchema, a as TLankaValidationResult, l as lankaStandardValidator } from '../lankaStandardValidator-CL-r-zEV.js';
|
|
2
|
-
import {
|
|
2
|
+
import { L as LankaError } from '../LankaError-xpI-qj35.js';
|
|
3
3
|
import '@standard-schema/spec';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* The validation port's failure: a body the schema refused.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* the
|
|
8
|
+
* A `LankaError` of kind `schema`, so that `LankaError.is` and everything built
|
|
9
|
+
* on it — the HTTP policy's error middleware, an application branching on
|
|
10
|
+
* `kind` — see a refused body the way they see the request layer's own
|
|
11
|
+
* "200 that was not JSON". It used to extend `Error` directly, and a consumer
|
|
12
|
+
* that told a contract drift from a network failure by `kind` never saw it.
|
|
13
|
+
*
|
|
14
|
+
* `name` stays `LankaValidationError` and `status` stays 422: both are what a
|
|
15
|
+
* consumer's existing `catch` reads, and the message list is `errors`.
|
|
11
16
|
*/
|
|
12
|
-
declare class LankaValidationError extends
|
|
13
|
-
status: number;
|
|
14
|
-
errors: string[];
|
|
17
|
+
declare class LankaValidationError extends LankaError {
|
|
15
18
|
constructor(message: string, errors?: string[]);
|
|
19
|
+
/** Always present here, unlike the base's optional list. */
|
|
20
|
+
get errors(): string[];
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
export { LankaValidationError };
|
package/dist/validation/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!-- Generated from core/GUIDE.md by scripts/skills.mjs. Edit the guide. -->
|
|
2
2
|
|
|
3
|
-
> **`lanka@1.1.
|
|
3
|
+
> **`lanka@1.1.1`** — this document describes that version.
|
|
4
4
|
>
|
|
5
5
|
> Install: `npm install lanka react zustand` (the peers are not optional; only npm adds a missing one for you).
|
|
6
6
|
>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Structural API-error shape read by consumer code.
|
|
3
|
-
*
|
|
4
|
-
* `status` is OPTIONAL: a network drop and an aborted request carry no status,
|
|
5
|
-
* and three of the six `LankaError` kinds have none.
|
|
6
|
-
*
|
|
7
|
-
* `LankaError` implements this interface, so consumers may read `status` and
|
|
8
|
-
* `errors` off any thrown framework error.
|
|
9
|
-
*/
|
|
10
|
-
interface ILankaApiError {
|
|
11
|
-
status?: number;
|
|
12
|
-
errors?: string[];
|
|
13
|
-
message?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type { ILankaApiError as I };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/validation/lanka-validation-error/LankaValidationError.ts","../src/validation/lanka-standard-validator/lankaStandardValidator.ts"],"sourcesContent":["import { ILankaApiError } from \"../../errors/_interfaces/ILankaApiError\";\n\n/**\n * What a schema refused, as an error a screen can catch by type.\n *\n * The one case where a class is the answer by itself: `instanceof` needs a\n * prototype. It carries the field errors a form renders, so a caller branches on\n * the type rather than parsing a message.\n */\nexport class LankaValidationError extends Error implements ILankaApiError {\n\tstatus: number;\n\terrors: string[];\n\n\tconstructor(message: string, errors: string[] = []) {\n\t\tsuper(message);\n\t\tthis.name = \"LankaValidationError\";\n\t\tthis.status = 422;\n\t\tthis.errors = errors.length > 0 ? errors : [message];\n\t}\n}\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { LankaValidationError } from \"../lanka-validation-error/LankaValidationError\";\nimport type { TLankaValidationResult } from \"../_types/TLankaValidationResult\";\n\n/**\n * Response body validation with any Standard Schema implementation.\n *\n * An abstraction typed by one library cannot be implemented by another, which is\n * the whole reason a validation port exists. Standard Schema is the shared\n * interface implemented by zod 4, valibot, arktype and others.\n *\n * `@standard-schema/spec` contains TYPES ONLY and adds no bytes to a build, so it\n * is a regular dependency rather than another peer.\n *\n * No adapter classes: a schema describes itself, and\n * `schema[\"~standard\"].validate(data)` is the whole protocol.\n */\n\n/** A schema the port understands: any Standard Schema implementation. */\nexport type TLankaSchema<TOutput = unknown> = StandardSchemaV1<unknown, TOutput>;\n\nexport interface ILankaValidator {\n\t/** Validates and returns the parsed value, or throws. */\n\tvalidate<TOutput>(schema: TLankaSchema<TOutput>, data: unknown, context: string): TOutput;\n\t/** Validates and returns an outcome, throwing nothing. */\n\tvalidateSafe<TOutput>(\n\t\tschema: TLankaSchema<TOutput>,\n\t\tdata: unknown,\n\t): TLankaValidationResult<TOutput>;\n}\n\n/**\n * A field path plus a message.\n *\n * The path is assembled WHOLE — `items.0.id`, not `id`. Without the index and the\n * parent the message points nowhere when the list has twenty items.\n */\nfunction describeIssue(issue: StandardSchemaV1.Issue): string {\n\tconst path = (issue.path ?? [])\n\t\t.map((segment) =>\n\t\t\ttypeof segment === \"object\" && segment !== null && \"key\" in segment\n\t\t\t\t? String(segment.key)\n\t\t\t\t: String(segment),\n\t\t)\n\t\t.join(\".\");\n\n\treturn path ? `${path}: ${issue.message}` : issue.message;\n}\n\nfunction runSync<TOutput>(\n\tschema: TLankaSchema<TOutput>,\n\tdata: unknown,\n): StandardSchemaV1.Result<TOutput> {\n\tconst result = schema[\"~standard\"].validate(data);\n\n\t// Standard Schema allows returning a promise. A synchronous port cannot await\n\t// it, and answering \"fine\" would let UNVALIDATED data through — a check that\n\t// cannot fail reporting success.\n\tif (result instanceof Promise) {\n\t\tthrow new LankaValidationError(\n\t\t\t\"The schema is asynchronous and the validation port is synchronous. Parse \" +\n\t\t\t\t\"such data by hand: passing it silently would be worse than failing.\",\n\t\t\t[],\n\t\t);\n\t}\n\n\treturn result;\n}\n\nexport const lankaStandardValidator: ILankaValidator = Object.freeze<ILankaValidator>({\n\tvalidate<TOutput>(schema: TLankaSchema<TOutput>, data: unknown, context: string): TOutput {\n\t\tconst result = runSync(schema, data);\n\n\t\tif (result.issues) {\n\t\t\tthrow new LankaValidationError(\n\t\t\t\t`Validation failed for ${context}`,\n\t\t\t\tresult.issues.map(describeIssue),\n\t\t\t);\n\t\t}\n\n\t\treturn result.value;\n\t},\n\n\tvalidateSafe<TOutput>(\n\t\tschema: TLankaSchema<TOutput>,\n\t\tdata: unknown,\n\t): TLankaValidationResult<TOutput> {\n\t\tconst result = runSync(schema, data);\n\n\t\tif (result.issues) {\n\t\t\treturn { success: false, errors: result.issues.map(describeIssue) };\n\t\t}\n\n\t\treturn { success: true, data: result.value };\n\t},\n});\n"],"mappings":";AASO,IAAM,uBAAN,cAAmC,MAAgC;AAAA,EACzE;AAAA,EACA;AAAA,EAEA,YAAY,SAAiB,SAAmB,CAAC,GAAG;AACnD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,SAAS,OAAO,SAAS,IAAI,SAAS,CAAC,OAAO;AAAA,EACpD;AACD;;;ACkBA,SAAS,cAAc,OAAuC;AAC7D,QAAM,QAAQ,MAAM,QAAQ,CAAC,GAC3B;AAAA,IAAI,CAAC,YACL,OAAO,YAAY,YAAY,YAAY,QAAQ,SAAS,UACzD,OAAO,QAAQ,GAAG,IAClB,OAAO,OAAO;AAAA,EAClB,EACC,KAAK,GAAG;AAEV,SAAO,OAAO,GAAG,IAAI,KAAK,MAAM,OAAO,KAAK,MAAM;AACnD;AAEA,SAAS,QACR,QACA,MACmC;AACnC,QAAM,SAAS,OAAO,WAAW,EAAE,SAAS,IAAI;AAKhD,MAAI,kBAAkB,SAAS;AAC9B,UAAM,IAAI;AAAA,MACT;AAAA,MAEA,CAAC;AAAA,IACF;AAAA,EACD;AAEA,SAAO;AACR;AAEO,IAAM,yBAA0C,OAAO,OAAwB;AAAA,EACrF,SAAkB,QAA+B,MAAe,SAA0B;AACzF,UAAM,SAAS,QAAQ,QAAQ,IAAI;AAEnC,QAAI,OAAO,QAAQ;AAClB,YAAM,IAAI;AAAA,QACT,yBAAyB,OAAO;AAAA,QAChC,OAAO,OAAO,IAAI,aAAa;AAAA,MAChC;AAAA,IACD;AAEA,WAAO,OAAO;AAAA,EACf;AAAA,EAEA,aACC,QACA,MACkC;AAClC,UAAM,SAAS,QAAQ,QAAQ,IAAI;AAEnC,QAAI,OAAO,QAAQ;AAClB,aAAO,EAAE,SAAS,OAAO,QAAQ,OAAO,OAAO,IAAI,aAAa,EAAE;AAAA,IACnE;AAEA,WAAO,EAAE,SAAS,MAAM,MAAM,OAAO,MAAM;AAAA,EAC5C;AACD,CAAC;","names":[]}
|
|
File without changes
|
|
File without changes
|