lanka 2.2.1 → 2.3.0
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/README.md +2 -2
- package/dist/{ALankaGateway-BrVPaZN5.d.ts → ALankaGateway-CQrEPUHM.d.ts} +1 -15
- package/dist/{LankaError-D6RWNyLM.d.ts → LankaError-CfDmuGKc.d.ts} +17 -0
- package/dist/_extend/index.d.ts +2 -2
- package/dist/_extend/index.js +10 -10
- package/dist/_internal/index.d.ts +3 -3
- package/dist/_internal/index.js +2 -2
- package/dist/{activeRuntime-DxB62KN4.d.ts → activeRuntime-1Zj2m1Sx.d.ts} +1 -1
- package/dist/bootstrap/index.d.ts +5 -5
- package/dist/bootstrap/index.js +3 -3
- package/dist/{chunk-DKLOCKS4.js → chunk-3GQGNG7S.js} +2 -2
- package/dist/{chunk-HVSQOMRE.js → chunk-BIJTUWUD.js} +2 -2
- package/dist/{chunk-G32H73QY.js → chunk-INHAKVSO.js} +17 -1
- package/dist/chunk-INHAKVSO.js.map +1 -0
- package/dist/{chunk-YR4MZXMU.js → chunk-USZ7CFCU.js} +1 -1
- package/dist/chunk-USZ7CFCU.js.map +1 -0
- package/dist/{chunk-CRIRTOLB.js → chunk-VI4DY5PN.js} +2 -2
- package/dist/{chunk-532WVMAF.js → chunk-YEP54YU5.js} +7 -7
- package/dist/{createLanka-AuiMfPL9.d.ts → createLanka-XbyOz9ld.d.ts} +2 -2
- package/dist/errors/index.d.ts +2 -2
- package/dist/errors/index.js +2 -2
- package/dist/gateway/index.d.ts +3 -3
- package/dist/gateway/index.js +127 -66
- package/dist/gateway/index.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +7 -7
- package/dist/{lankaRequestMiddleware-DAC5kCb7.d.ts → lankaRequestMiddleware-CbXc1PAV.d.ts} +3 -1
- package/dist/locator/gateway/lanka-gateway-locator/LankaGatewayLocator.d.ts +1 -1
- package/dist/locator/index.d.ts +1 -1
- package/dist/stream/index.d.ts +4 -4
- package/dist/validation/index.d.ts +1 -1
- package/dist/validation/index.js +3 -3
- package/package.json +1 -1
- package/skills/lanka-core/SKILL.md +14 -10
- package/skills/lanka-core/reference.md +27 -1
- package/skills/lanka-packages/SKILL.md +1 -1
- package/dist/chunk-G32H73QY.js.map +0 -1
- package/dist/chunk-YR4MZXMU.js.map +0 -1
- /package/dist/{chunk-DKLOCKS4.js.map → chunk-3GQGNG7S.js.map} +0 -0
- /package/dist/{chunk-HVSQOMRE.js.map → chunk-BIJTUWUD.js.map} +0 -0
- /package/dist/{chunk-CRIRTOLB.js.map → chunk-VI4DY5PN.js.map} +0 -0
- /package/dist/{chunk-532WVMAF.js.map → chunk-YEP54YU5.js.map} +0 -0
package/dist/stream/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { c as ILankaPlugin } from '../createLanka-
|
|
1
|
+
import { c as ILankaPlugin } from '../createLanka-XbyOz9ld.js';
|
|
2
2
|
import '../createLankaScope-DeElRH-E.js';
|
|
3
3
|
import '../LankaScenarioVMRegistry-CFzCpIFd.js';
|
|
4
4
|
import '../ILankaScenarioVM-DKwjbIRq.js';
|
|
5
5
|
import '../locator/singleton/lanka-singleton-locator/LankaSingletonLocator.js';
|
|
6
6
|
import '../ALankaLocator-BUCCz0Q5.js';
|
|
7
|
-
import '../activeRuntime-
|
|
7
|
+
import '../activeRuntime-1Zj2m1Sx.js';
|
|
8
8
|
import '../ILankaScenario-7J3MoKiY.js';
|
|
9
9
|
import '../LankaScenariosRegistry-DiLN9xwy.js';
|
|
10
10
|
import '../ILankaScenarioMetadata-DgOxvpwx.js';
|
|
11
11
|
import '../ILankaRuntimeConfig-Vl436GWK.js';
|
|
12
12
|
import '../lankaHttpInFlight-Bk1eIuSx.js';
|
|
13
|
-
import '../lankaRequestMiddleware-
|
|
13
|
+
import '../lankaRequestMiddleware-CbXc1PAV.js';
|
|
14
14
|
import '../locator/gateway/lanka-gateway-locator/LankaGatewayLocator.js';
|
|
15
|
-
import '../ALankaGateway-
|
|
15
|
+
import '../ALankaGateway-CQrEPUHM.js';
|
|
16
16
|
import '../lankaStandardValidator-BUFnysK0.js';
|
|
17
17
|
import '@standard-schema/spec';
|
|
18
18
|
import '../ILankaFieldError-D5931-vT.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { I as ILankaValidator, T as TLankaSchema, a as TLankaValidationResult, l as lankaStandardValidator } from '../lankaStandardValidator-BUFnysK0.js';
|
|
2
|
-
import { L as LankaError } from '../LankaError-
|
|
2
|
+
import { L as LankaError } from '../LankaError-CfDmuGKc.js';
|
|
3
3
|
import { I as ILankaFieldError } from '../ILankaFieldError-D5931-vT.js';
|
|
4
4
|
import '@standard-schema/spec';
|
|
5
5
|
|
package/dist/validation/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
lankaStandardValidator
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-BIJTUWUD.js";
|
|
4
4
|
import {
|
|
5
5
|
LankaValidationError
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
6
|
+
} from "../chunk-VI4DY5PN.js";
|
|
7
|
+
import "../chunk-INHAKVSO.js";
|
|
8
8
|
export {
|
|
9
9
|
LankaValidationError,
|
|
10
10
|
lankaStandardValidator
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ license: MIT
|
|
|
5
5
|
metadata:
|
|
6
6
|
author: lankajs
|
|
7
7
|
package: lanka
|
|
8
|
-
version: "2.
|
|
8
|
+
version: "2.3.0"
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
# lanka — core
|
|
@@ -213,6 +213,10 @@ without touching a screen.
|
|
|
213
213
|
|
|
214
214
|
`LankaError` carries a kind: `network` · `timeout` · `aborted` · `http` ·
|
|
215
215
|
`schema` · `domain`. Branch on it. `aborted` is shown to nobody — the user left.
|
|
216
|
+
`isFromBackground` marks a `network` or `aborted` failure of an attempt during
|
|
217
|
+
which the page hid or unloaded — on a mobile WebView, usually the platform cutting
|
|
218
|
+
a frozen request. Segment telemetry by it; do not drop it. Request deadlines
|
|
219
|
+
stop while the app is in the background, so a `timeout` is real slowness.
|
|
216
220
|
|
|
217
221
|
Refuse locally with the same shape rather than a bare throw:
|
|
218
222
|
`Promise.reject(createLankaApiError(400, ["a search needs a term"]))`.
|
|
@@ -292,16 +296,16 @@ decides. Resetting the form erases what they were typing.
|
|
|
292
296
|
|
|
293
297
|
## Symptom → cause
|
|
294
298
|
|
|
295
|
-
| What you see | What it is
|
|
296
|
-
| --------------------------------------------------------------- |
|
|
297
|
-
| a scenario handler never fires | `lanka.bootstrap()` was never awaited, or the ViewModel was built after it
|
|
298
|
-
| a locator name resolves to a refusal | registered after construction, or never registered
|
|
299
|
-
| the screen freezes with no error | a key read through a getter, past the tracking proxy — set `enableAccessTrackingOptimization: false` on that ViewModel
|
|
300
|
-
| "module not found" for `@lanka_di/…` | `@lankajs/tool-di` is not installed, or the alias is missing
|
|
301
|
-
| a test sees another test's events | the instance was replaced without `dispose()` — use `resetLanka()`
|
|
302
|
-
| "lanka used before an instance existed", only in a BUILT bundle | a ViewModel read the locator while its own module was evaluated, ahead of `createLanka` — declare `scenarioHandlers` as a factory (below)
|
|
299
|
+
| What you see | What it is |
|
|
300
|
+
| --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
301
|
+
| a scenario handler never fires | `lanka.bootstrap()` was never awaited, or the ViewModel was built after it |
|
|
302
|
+
| a locator name resolves to a refusal | registered after construction, or never registered |
|
|
303
|
+
| the screen freezes with no error | a key read through a getter, past the tracking proxy — set `enableAccessTrackingOptimization: false` on that ViewModel |
|
|
304
|
+
| "module not found" for `@lanka_di/…` | `@lankajs/tool-di` is not installed, or the alias is missing |
|
|
305
|
+
| a test sees another test's events | the instance was replaced without `dispose()` — use `resetLanka()` |
|
|
306
|
+
| "lanka used before an instance existed", only in a BUILT bundle | a ViewModel read the locator while its own module was evaluated, ahead of `createLanka` — declare `scenarioHandlers` as a factory (below) |
|
|
303
307
|
| "…ran in another evaluation of lanka", after upgrading lanka | the open page kept the old lanka and a module loaded since got the new files — reload the page; restart the dev server if it pre-bundles nothing of lanka |
|
|
304
|
-
| "one was active in this copy and has been cleared" | a timer, a subscription or a request outlived `dispose()` — or the next instance was never created and activated
|
|
308
|
+
| "one was active in this copy and has been cleared" | a timer, a subscription or a request outlived `dispose()` — or the next instance was never created and activated |
|
|
305
309
|
|
|
306
310
|
Do **not** fix the frozen screen by destructuring a value "for the side effect":
|
|
307
311
|
it reads as dead code and the next refactor deletes it.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!-- Generated from core/GUIDE.md by scripts/skills.mjs. Edit the guide. -->
|
|
2
2
|
|
|
3
|
-
> **`lanka@2.
|
|
3
|
+
> **`lanka@2.3.0`** — this document describes that version.
|
|
4
4
|
>
|
|
5
5
|
> Install: `npm install lanka zustand` (the peers are not optional; only npm adds a missing one for you).
|
|
6
6
|
>
|
|
@@ -387,6 +387,13 @@ the framework reaches both at once.
|
|
|
387
387
|
`endpoint(path)` prefixes `apiBaseUrl` and the gateway's `basePath`, normalising
|
|
388
388
|
slashes. Pass an absolute URL and it is used as given.
|
|
389
389
|
|
|
390
|
+
`request(path)` resolves its path through `endpoint()` itself, so
|
|
391
|
+
`request("7")` and `request(endpoint("7"))` reach the same URL. That holds
|
|
392
|
+
because `endpoint()` is idempotent: a path already under `apiBaseUrl` is not
|
|
393
|
+
prefixed again, so a relative base such as `/api` gives `/api/todos`, not
|
|
394
|
+
`/api/api/todos`. The one reading this costs is that a path you write as
|
|
395
|
+
`/api/x` under a base of `/api` means `/api/x`.
|
|
396
|
+
|
|
390
397
|
### Requests and transports
|
|
391
398
|
|
|
392
399
|
A **request kind** decides what a response _is_; the **transport** decides how
|
|
@@ -452,6 +459,25 @@ its own timer into one signal and still tells the two apart: a timed-out request
|
|
|
452
459
|
raises `timeout` and is shown to the user, a caller-aborted one raises `aborted`
|
|
453
460
|
and stays silent, because the user has already left.
|
|
454
461
|
|
|
462
|
+
**The deadline stops while the app is in the background.** A mobile WebView is
|
|
463
|
+
frozen when the user leaves it — an external link, an app switch, a locked
|
|
464
|
+
screen — and timers do not run while it is; an overdue timer fires at once on
|
|
465
|
+
resume. A plain timer therefore reported `timeout` for a request that was never
|
|
466
|
+
slow. Now, when the page is SEEN to hide during the attempt (`visibilitychange`
|
|
467
|
+
to `"hidden"`, or `pagehide`), the deadline pauses, and the rest runs when the
|
|
468
|
+
page shows again. A page already hidden when the request starts runs its clock
|
|
469
|
+
as before — some WebViews report `hidden` from load and never change it. Where
|
|
470
|
+
there is no `document` (Node, SSR, React Native) nothing changes. A request in a
|
|
471
|
+
desktop tab that is switched away from mid-flight is paused the same way.
|
|
472
|
+
|
|
473
|
+
**A failure says whether the app went to the background.** `error.isFromBackground`
|
|
474
|
+
is `true` on a `network` or `aborted` failure that core tagged, of an attempt
|
|
475
|
+
during which the page was seen to hide or unload. It tells WHEN, not why: on a
|
|
476
|
+
mobile WebView the platform usually cut the request; on a desktop tab the server
|
|
477
|
+
may just as well have failed. Segment your error telemetry by it rather than
|
|
478
|
+
dropping what it marks. It is never set on a `timeout` — the deadline already
|
|
479
|
+
stops in the background, so a timeout is real slowness.
|
|
480
|
+
|
|
455
481
|
### Counting requests in flight
|
|
456
482
|
|
|
457
483
|
```ts
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors/lanka-error/LankaError.ts"],"sourcesContent":["import type { ILankaApiError } from \"../_interfaces/ILankaApiError\";\nimport type { ILankaFieldError } from \"../_interfaces/ILankaFieldError\";\n\n/**\n * How a request ended.\n *\n * Six kinds rather than one, for one reason: each demands something DIFFERENT of\n * the interface. A distinction that implies no different behaviour is\n * superfluous, which is why there is no seventh.\n */\nexport type TLankaErrorKind =\n\t/** Never reached the server: dropped link, DNS failure, no network. Offer a retry. */\n\t| \"network\"\n\t/** Reached it; the response never came. Also a retry, but a different message. */\n\t| \"timeout\"\n\t/** Cancelled by the caller. Nothing to show: the user left. */\n\t| \"aborted\"\n\t/** The server answered with an error status; what to show depends on it. */\n\t| \"http\"\n\t/** A response arrived in the wrong shape. A break, not the user's fault. */\n\t| \"schema\"\n\t/** The server refused deliberately and named the reason. Show what it said. */\n\t| \"domain\";\n\nexport interface ILankaErrorInit {\n\tkind: TLankaErrorKind;\n\tmessage: string;\n\t/** HTTP status, when there was one. */\n\tstatus?: number;\n\t/** The domain failure code — what the application branches on. */\n\tcode?: string;\n\t/** Details: server messages, or paths to the fields that failed validation. */\n\tissues?: readonly string[];\n\t/**\n\t * The failures that have an input to be shown at, with the path in segments.\n\t *\n\t * Beside `issues` rather than instead of it: `issues` is the banner's list and\n\t * is promised; this is the form's, and a failure may have either, both or\n\t * neither. Absent means \"nothing here has an address\", not \"unknown\".\n\t */\n\tfields?: readonly ILankaFieldError[];\n\t/**\n\t * The parsed ERROR response body, when there was one and it was JSON.\n\t *\n\t * Travels with the error because a `Response` is read once: without this field\n\t * a plugin extracting the domain failure code would read an already-drained\n\t * stream and get nothing. Core does not look into the body; it carries it.\n\t */\n\tbody?: unknown;\n\t/** The original error, when this one wraps it. */\n\tcause?: unknown;\n}\n\n/**\n * One failure type for every layer of the framework.\n *\n * Without a tagged kind, an app cannot tell a network failure from a timeout,\n * from a broken schema, from a deliberate domain refusal — so it builds its own\n * error contract ON TOP of the framework, and builds it once per application.\n *\n * Implements `ILankaApiError`: `status` and `errors` are present, so code reading\n * them the old way keeps working.\n *\n * What is NOT here: parsing a particular response body format. Which JSON a\n * backend sends is policy, and policy lives in `@lankajs/plugin-http`. Core knows\n * only that it has a failure and must name its kind.\n */\nexport class LankaError extends Error implements ILankaApiError {\n\treadonly kind: TLankaErrorKind;\n\treadonly status?: number;\n\treadonly code?: string;\n\treadonly issues?: readonly string[];\n\t/**\n\t * The failures with an input to be shown at. See `ILankaErrorInit.fields`.\n\t *\n\t * The array given is the array kept — unlike `errors`, which copies `issues`\n\t * on every read. `readonly` carries the promise, and this is read on the way\n\t * to a form, once, where a copy would buy nothing.\n\t */\n\treadonly fields?: readonly ILankaFieldError[];\n\t/** The parsed error response body; core carries it without reading it. */\n\treadonly body?: unknown;\n\n\tconstructor(init: ILankaErrorInit) {\n\t\tsuper(init.message, init.cause === undefined ? undefined : { cause: init.cause });\n\t\tthis.name = \"LankaError\";\n\t\tthis.kind = init.kind;\n\t\tthis.status = init.status;\n\t\tthis.code = init.code;\n\t\tthis.issues = init.issues;\n\t\tthis.fields = init.fields;\n\t\tthis.body = init.body;\n\n\t\t// The prototype chain is pinned explicitly: without it `instanceof` breaks\n\t\t// for a consumer whose bundler downlevels to ES5, and breaks silently —\n\t\t// `catch` simply fails to recognise its own error.\n\t\tObject.setPrototypeOf(this, LankaError.prototype);\n\t}\n\n\t/** The `ILankaApiError` field. The details are the message list. */\n\tget errors(): string[] | undefined {\n\t\treturn this.issues ? [...this.issues] : undefined;\n\t}\n\n\t/**\n\t * Whether to show this to the user.\n\t *\n\t * A cancelled request is the one failure that must NOT be reported: its cause\n\t * is that the user left before the response, and a toast would catch them on\n\t * another screen.\n\t */\n\tget isSilent(): boolean {\n\t\treturn this.kind === \"aborted\";\n\t}\n\n\t/**\n\t * Recognises our error among others.\n\t *\n\t * Checks the name rather than `instanceof` alone: a consumer may end up with\n\t * two copies of the package — adjacent majors in the dependency tree — and\n\t * then `instanceof` answers `false` for an error that is ours by every other\n\t * sign.\n\t */\n\tstatic is(value: unknown): value is LankaError {\n\t\treturn (\n\t\t\tvalue instanceof LankaError || (value instanceof Error && value.name === \"LankaError\")\n\t\t);\n\t}\n}\n"],"mappings":";AAmEO,IAAM,aAAN,MAAM,oBAAmB,MAAgC;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA;AAAA;AAAA,EAEA;AAAA,EAET,YAAY,MAAuB;AAClC,UAAM,KAAK,SAAS,KAAK,UAAU,SAAY,SAAY,EAAE,OAAO,KAAK,MAAM,CAAC;AAChF,SAAK,OAAO;AACZ,SAAK,OAAO,KAAK;AACjB,SAAK,SAAS,KAAK;AACnB,SAAK,OAAO,KAAK;AACjB,SAAK,SAAS,KAAK;AACnB,SAAK,SAAS,KAAK;AACnB,SAAK,OAAO,KAAK;AAKjB,WAAO,eAAe,MAAM,YAAW,SAAS;AAAA,EACjD;AAAA;AAAA,EAGA,IAAI,SAA+B;AAClC,WAAO,KAAK,SAAS,CAAC,GAAG,KAAK,MAAM,IAAI;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAI,WAAoB;AACvB,WAAO,KAAK,SAAS;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,GAAG,OAAqC;AAC9C,WACC,iBAAiB,eAAe,iBAAiB,SAAS,MAAM,SAAS;AAAA,EAE3E;AACD;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/gateway/request/lankaRequestMiddleware.ts"],"sourcesContent":["/**\n * What middleware knows about the request it wraps.\n *\n * `options` is deliberately `unknown`: every transport has its own —\n * `RequestInit` for fetch, something else for the next one. Core does not read\n * them, it passes them along.\n */\nexport interface ILankaRequestContext {\n\treadonly endpoint: string;\n\treadonly options: unknown;\n\t/**\n\t * Which attempt this is, counting from one.\n\t *\n\t * In the context rather than in the middleware itself, because a retry may be\n\t * started by someone other than the one counting: an auth refresh restarts the\n\t * request, and the retrying middleware must not mistake that for its own\n\t * second attempt.\n\t */\n\treadonly attempt: number;\n\t/**\n\t * This attempt's deadline, when middleware assigned one.\n\t *\n\t * Read by CORE before every call into the transport, which is what allows a\n\t * deadline per request class: a file upload and a list read cannot share one\n\t * value, and the policy knows that difference while the framework does not.\n\t */\n\treadonly timeoutMs?: number;\n}\n\n/**\n * A wrapper around a request.\n *\n * ## A wrapper rather than `onRequest` / `onResponse` / `onError`\n *\n * Three hooks cannot express RETRY. `onError` can replace an error but cannot\n * run the request again — and retry plus auth refresh are the two main abilities\n * a request-policy plugin exists for. A wrapper expresses those and everything\n * the hooks expressed.\n *\n * ## Why the objection to `next()` does not carry over\n *\n * On the event bus, middleware that skips `next` SILENCES the event: subscribers\n * do not run and nothing records it. Here, skipping `next` means returning a\n * value instead of a request — and the caller receives that value, so the\n * decision is visible.\n *\n * ## Order\n *\n * Registered first wraps all the rest: it sees the request before everyone and\n * the response after everyone — ordinary layer semantics, where \"outer\" means\n * outer.\n */\nexport type TLankaRequestMiddleware = (\n\tctx: ILankaRequestContext,\n\tnext: (ctx: ILankaRequestContext) => Promise<unknown>,\n) => Promise<unknown>;\n\n/**\n * Folds the chain into one function.\n *\n * An empty chain returns `perform` as-is, with no wrappers and no cost: an app\n * without a request-policy plugin has no middleware at all and must not pay for\n * their absence.\n */\nexport function composeLankaRequestMiddleware(\n\tmiddleware: readonly TLankaRequestMiddleware[],\n\tperform: (ctx: ILankaRequestContext) => Promise<unknown>,\n): (ctx: ILankaRequestContext) => Promise<unknown> {\n\tif (middleware.length === 0) return perform;\n\n\treturn middleware.reduceRight<(ctx: ILankaRequestContext) => Promise<unknown>>(\n\t\t(next, current) => (ctx) => current(ctx, next),\n\t\tperform,\n\t);\n}\n"],"mappings":";AAgEO,SAAS,8BACf,YACA,SACkD;AAClD,MAAI,WAAW,WAAW,EAAG,QAAO;AAEpC,SAAO,WAAW;AAAA,IACjB,CAAC,MAAM,YAAY,CAAC,QAAQ,QAAQ,KAAK,IAAI;AAAA,IAC7C;AAAA,EACD;AACD;","names":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|