@venizia/ignis-worker 0.2.0-9 → 0.2.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 +133 -0
- package/dist/cjs/applications/common/index.d.ts +2 -0
- package/dist/cjs/applications/common/index.d.ts.map +1 -0
- package/dist/cjs/applications/common/index.js +18 -0
- package/dist/cjs/applications/common/index.js.map +1 -0
- package/dist/cjs/applications/common/types.d.ts +10 -0
- package/dist/cjs/applications/common/types.d.ts.map +1 -0
- package/dist/cjs/applications/common/types.js.map +1 -0
- package/dist/cjs/applications/index.d.ts +1 -0
- package/dist/cjs/applications/index.d.ts.map +1 -1
- package/dist/cjs/applications/index.js +1 -0
- package/dist/cjs/applications/index.js.map +1 -1
- package/dist/cjs/applications/worker.d.ts +18 -6
- package/dist/cjs/applications/worker.d.ts.map +1 -1
- package/dist/cjs/applications/worker.js +21 -6
- package/dist/cjs/applications/worker.js.map +1 -1
- package/dist/cjs/envelope/common/index.d.ts +2 -0
- package/dist/cjs/envelope/common/index.d.ts.map +1 -0
- package/dist/cjs/envelope/common/index.js +18 -0
- package/dist/cjs/envelope/common/index.js.map +1 -0
- package/dist/cjs/envelope/common/types.d.ts.map +1 -0
- package/dist/cjs/envelope/common/types.js +3 -0
- package/dist/{esm/envelope → cjs/envelope/common}/types.js.map +1 -1
- package/dist/cjs/envelope/encode.d.ts +1 -1
- package/dist/cjs/envelope/encode.d.ts.map +1 -1
- package/dist/cjs/envelope/index.d.ts +1 -1
- package/dist/cjs/envelope/index.d.ts.map +1 -1
- package/dist/cjs/envelope/index.js +1 -1
- package/dist/cjs/envelope/index.js.map +1 -1
- package/dist/cjs/transport/shared/common/constants.d.ts +14 -0
- package/dist/cjs/transport/shared/common/constants.d.ts.map +1 -0
- package/dist/cjs/transport/shared/common/constants.js +19 -0
- package/dist/cjs/transport/shared/common/constants.js.map +1 -0
- package/dist/cjs/transport/shared/common/index.d.ts +3 -0
- package/dist/cjs/transport/shared/common/index.d.ts.map +1 -0
- package/dist/cjs/transport/shared/common/index.js +19 -0
- package/dist/cjs/transport/shared/common/index.js.map +1 -0
- package/dist/cjs/transport/shared/common/types.d.ts +35 -0
- package/dist/cjs/transport/shared/common/types.d.ts.map +1 -0
- package/dist/cjs/transport/shared/common/types.js +3 -0
- package/dist/cjs/transport/shared/common/types.js.map +1 -0
- package/dist/cjs/transport/shared/index.d.ts +4 -0
- package/dist/cjs/transport/shared/index.d.ts.map +1 -0
- package/dist/cjs/transport/shared/index.js +11 -0
- package/dist/cjs/transport/shared/index.js.map +1 -0
- package/dist/cjs/transport/{shared.d.ts → shared/transport.d.ts} +3 -18
- package/dist/cjs/transport/shared/transport.d.ts.map +1 -0
- package/dist/cjs/transport/{shared.js → shared/transport.js} +22 -34
- package/dist/cjs/transport/shared/transport.js.map +1 -0
- package/dist/cjs/transport/worker.d.ts.map +1 -1
- package/dist/cjs/transport/worker.js +2 -1
- package/dist/cjs/transport/worker.js.map +1 -1
- package/dist/esm/applications/common/index.d.ts +2 -0
- package/dist/esm/applications/common/index.d.ts.map +1 -0
- package/dist/esm/applications/common/index.js +2 -0
- package/dist/esm/applications/common/index.js.map +1 -0
- package/dist/esm/applications/common/types.d.ts +10 -0
- package/dist/esm/applications/common/types.d.ts.map +1 -0
- package/dist/esm/applications/common/types.js.map +1 -0
- package/dist/esm/applications/index.d.ts +1 -0
- package/dist/esm/applications/index.d.ts.map +1 -1
- package/dist/esm/applications/index.js +1 -0
- package/dist/esm/applications/index.js.map +1 -1
- package/dist/esm/applications/worker.d.ts +18 -6
- package/dist/esm/applications/worker.d.ts.map +1 -1
- package/dist/esm/applications/worker.js +23 -8
- package/dist/esm/applications/worker.js.map +1 -1
- package/dist/esm/envelope/common/index.d.ts +2 -0
- package/dist/esm/envelope/common/index.d.ts.map +1 -0
- package/dist/esm/envelope/common/index.js +2 -0
- package/dist/esm/envelope/common/index.js.map +1 -0
- package/dist/esm/envelope/common/types.d.ts.map +1 -0
- package/dist/esm/envelope/common/types.js +2 -0
- package/dist/{cjs/envelope → esm/envelope/common}/types.js.map +1 -1
- package/dist/esm/envelope/encode.d.ts +1 -1
- package/dist/esm/envelope/encode.d.ts.map +1 -1
- package/dist/esm/envelope/index.d.ts +1 -1
- package/dist/esm/envelope/index.d.ts.map +1 -1
- package/dist/esm/envelope/index.js +1 -1
- package/dist/esm/envelope/index.js.map +1 -1
- package/dist/esm/package.json +6 -0
- package/dist/esm/transport/index.d.ts +1 -1
- package/dist/esm/transport/index.js +1 -1
- package/dist/esm/transport/shared/common/constants.d.ts +14 -0
- package/dist/esm/transport/shared/common/constants.d.ts.map +1 -0
- package/dist/esm/transport/shared/common/constants.js +14 -0
- package/dist/esm/transport/shared/common/constants.js.map +1 -0
- package/dist/esm/transport/shared/common/index.d.ts +3 -0
- package/dist/esm/transport/shared/common/index.d.ts.map +1 -0
- package/dist/esm/transport/shared/common/index.js +3 -0
- package/dist/esm/transport/shared/common/index.js.map +1 -0
- package/dist/esm/transport/shared/common/types.d.ts +35 -0
- package/dist/esm/transport/shared/common/types.d.ts.map +1 -0
- package/dist/esm/transport/shared/common/types.js +2 -0
- package/dist/esm/transport/shared/common/types.js.map +1 -0
- package/dist/esm/transport/shared/index.d.ts +4 -0
- package/dist/esm/transport/shared/index.d.ts.map +1 -0
- package/dist/esm/transport/shared/index.js +6 -0
- package/dist/esm/transport/shared/index.js.map +1 -0
- package/dist/esm/transport/{shared.d.ts → shared/transport.d.ts} +3 -18
- package/dist/esm/transport/shared/transport.d.ts.map +1 -0
- package/dist/esm/transport/{shared.js → shared/transport.js} +6 -17
- package/dist/esm/transport/shared/transport.js.map +1 -0
- package/dist/esm/transport/worker.d.ts.map +1 -1
- package/dist/esm/transport/worker.js +2 -1
- package/dist/esm/transport/worker.js.map +1 -1
- package/package.json +10 -10
- package/dist/cjs/envelope/types.d.ts.map +0 -1
- package/dist/cjs/transport/shared.d.ts.map +0 -1
- package/dist/cjs/transport/shared.js.map +0 -1
- package/dist/esm/envelope/types.d.ts.map +0 -1
- package/dist/esm/transport/shared.d.ts.map +0 -1
- package/dist/esm/transport/shared.js.map +0 -1
- /package/dist/cjs/{envelope → applications/common}/types.js +0 -0
- /package/dist/cjs/envelope/{types.d.ts → common/types.d.ts} +0 -0
- /package/dist/esm/{envelope → applications/common}/types.js +0 -0
- /package/dist/esm/envelope/{types.d.ts → common/types.d.ts} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# @venizia/ignis-worker
|
|
2
|
+
|
|
3
|
+
Runs an IGNIS application inside a browser Web Worker. The page calls it like an HTTP API, and
|
|
4
|
+
nothing crosses a network: requests travel over `postMessage`.
|
|
5
|
+
|
|
6
|
+
Use it to build a Backend for Frontend (BFF) - a backend that serves one user interface and lives in
|
|
7
|
+
that interface's own tab. Your controllers, services and repositories are the same classes a server
|
|
8
|
+
application uses; only the host changes.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
bun add @venizia/ignis-worker @venizia/ignis-kernel hono @hono/zod-openapi
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Add `@venizia/ignis-connectors` and a driver when the BFF needs a database, for example
|
|
17
|
+
`@electric-sql/pglite` for Postgres stored in the browser.
|
|
18
|
+
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
Inside the Worker, extend `WorkerApplication` and call `listen()` instead of `start()`:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// worker.ts
|
|
25
|
+
import { z } from '@hono/zod-openapi';
|
|
26
|
+
import { BaseRestController, controller, get, jsonResponse } from '@venizia/ignis-kernel';
|
|
27
|
+
import { WorkerApplication } from '@venizia/ignis-worker';
|
|
28
|
+
import type { Context } from 'hono';
|
|
29
|
+
|
|
30
|
+
@controller({ path: '/notes' })
|
|
31
|
+
class NoteController extends BaseRestController {
|
|
32
|
+
constructor() {
|
|
33
|
+
super({ scope: NoteController.name });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
override binding() {}
|
|
37
|
+
|
|
38
|
+
@get({
|
|
39
|
+
configs: {
|
|
40
|
+
path: '/',
|
|
41
|
+
responses: jsonResponse({ schema: z.array(z.object({ title: z.string() })) }),
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
list(context: Context) {
|
|
45
|
+
return context.json([{ title: 'Answered inside the Worker' }]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
class BffApplication extends WorkerApplication {
|
|
50
|
+
getAppInfo() {
|
|
51
|
+
return { name: 'bff', version: '1.0.0', description: 'A BFF in a Worker' };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
staticConfigure() {}
|
|
55
|
+
setupMiddlewares() {}
|
|
56
|
+
postConfigure() {}
|
|
57
|
+
|
|
58
|
+
preConfigure() {
|
|
59
|
+
this.controller(NoteController);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const application = new BffApplication({
|
|
64
|
+
scope: BffApplication.name,
|
|
65
|
+
config: { path: { base: '/api', isStrict: false }, error: { environment: 'development' } },
|
|
66
|
+
});
|
|
67
|
+
application.init();
|
|
68
|
+
await application.listen();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
On the page, create a transport and send it a `Request`:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
// page.ts
|
|
75
|
+
import { SharedBffTransport } from '@venizia/ignis-worker';
|
|
76
|
+
|
|
77
|
+
const bff = new SharedBffTransport({
|
|
78
|
+
createWorker: () => new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' }),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const response = await bff.fetch({ request: new Request('http://ignis.internal/api/notes') });
|
|
82
|
+
console.log(response.status, await response.json()); // 200 [ { title: 'Answered inside the Worker' } ]
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
A Worker has no `process.env`, so set `config.error.environment` yourself. `listen()` queues any
|
|
86
|
+
request that arrives while the application is still booting.
|
|
87
|
+
|
|
88
|
+
## Make an existing client use it
|
|
89
|
+
|
|
90
|
+
Most HTTP clients do not accept a custom fetcher. `installBffFetch` answers the page's global `fetch`
|
|
91
|
+
for every URL under `basePath` and leaves every other call on the network:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { installBffFetch } from '@venizia/ignis-worker';
|
|
95
|
+
|
|
96
|
+
installBffFetch({ transport: bff, basePath: '/api' });
|
|
97
|
+
|
|
98
|
+
await fetch('/api/notes'); // answered by the Worker
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Install it before the code that calls `fetch` starts. It returns a function that uninstalls it.
|
|
102
|
+
|
|
103
|
+
## What it exports
|
|
104
|
+
|
|
105
|
+
| Export | What it does |
|
|
106
|
+
|---|---|
|
|
107
|
+
| `WorkerApplication` | A `RestApplication` host with `listen({ scope? })` and `stop()` in place of a socket |
|
|
108
|
+
| `SharedBffTransport` | One Worker per origin. It elects one tab with the Web Locks API and forwards the other tabs' requests over a `BroadcastChannel`. Use it by default |
|
|
109
|
+
| `WorkerBffTransport` | One Worker per transport, for a BFF that holds no origin-exclusive resource |
|
|
110
|
+
| `InProcessBffTransport` | No Worker - the same envelope round trip in one thread, for tests |
|
|
111
|
+
| `installBffFetch` | Routes the global `fetch` into a transport |
|
|
112
|
+
| `BffEnvelope`, `BFF_SYNTHETIC_ORIGIN` | The request, response and error envelopes that cross `postMessage` |
|
|
113
|
+
|
|
114
|
+
`SharedBffTransport` exists because a database like PGlite in OPFS holds an exclusive per-origin
|
|
115
|
+
handle. A second tab starting its own Worker could not open it.
|
|
116
|
+
|
|
117
|
+
The package has one entry point, `@venizia/ignis-worker`. `hono` and `@hono/zod-openapi` are its only
|
|
118
|
+
peers, and both are required.
|
|
119
|
+
|
|
120
|
+
## Where it sits
|
|
121
|
+
|
|
122
|
+
Depends on `@venizia/ignis-kernel`, `@venizia/ignis-helpers` and `@venizia/ignis-inversion`. It is the
|
|
123
|
+
browser sibling of `@venizia/ignis`; neither depends on the other, and it does not depend on
|
|
124
|
+
`@venizia/ignis-connectors`.
|
|
125
|
+
|
|
126
|
+
## Links
|
|
127
|
+
|
|
128
|
+
- [Example: browser-bff](https://github.com/VENIZIA-AI/ignis/tree/main/examples/browser-bff) - a controller answering from PGlite in OPFS, with no server
|
|
129
|
+
- [Changelog: the browser-pure kernel](https://ignis.venizia.ai/changelogs/2026-08-13-browser-pure-kernel)
|
|
130
|
+
- [Changelog: a BFF shared across tabs](https://ignis.venizia.ai/changelogs/2026-08-19-browser-bff-multi-tab)
|
|
131
|
+
- [All changelogs](https://ignis.venizia.ai/changelogs/)
|
|
132
|
+
|
|
133
|
+
MIT licensed - see [LICENSE.md](https://github.com/VENIZIA-AI/ignis/blob/main/LICENSE.md).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/applications/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/applications/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IApplicationConfigs } from '@venizia/ignis-kernel';
|
|
2
|
+
/**
|
|
3
|
+
* What a Web Worker host configures on top of the kernel's shape. `host`/`port` stay off this
|
|
4
|
+
* interface on purpose - `@venizia/ignis`'s `IServerApplicationConfigs` is the one with a socket.
|
|
5
|
+
*/
|
|
6
|
+
export interface IWorkerApplicationConfigs extends IApplicationConfigs {
|
|
7
|
+
/** Bound as `CoreBindings.APPLICATION_PROJECT_ROOT` when `getProjectRoot()` resolves it, and shared with `ModuleUtility`; default is the host's own working directory when one exists, else `''`. */
|
|
8
|
+
projectRoot?: string;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/applications/common/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEjE;;;GAGG;AACH,MAAM,WAAW,yBAA0B,SAAQ,mBAAmB;IACpE,qMAAqM;IACrM,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/applications/common/types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/applications/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/applications/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
|
|
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common"), exports);
|
|
17
18
|
__exportStar(require("./worker"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/applications/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/applications/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RestApplication } from '@venizia/ignis-kernel';
|
|
2
2
|
import type { Env, Schema } from 'hono';
|
|
3
|
+
import type { IWorkerApplicationConfigs } from './common';
|
|
3
4
|
/**
|
|
4
5
|
* Structural shape of the two globals `listen()` can attach to. Never `DedicatedWorkerGlobalScope`:
|
|
5
6
|
* naming it emits it into the published `.d.ts` and forces every consumer to compile with
|
|
@@ -19,12 +20,23 @@ export interface IWorkerMessageScope {
|
|
|
19
20
|
* reason the DI helpers and `RestComponent` sit in the kernel.
|
|
20
21
|
*/
|
|
21
22
|
export declare abstract class WorkerApplication<AppEnv extends Env = Env, AppSchema extends Schema = {}, BasePath extends string = '/'> extends RestApplication<AppEnv, AppSchema, BasePath> {
|
|
23
|
+
/** Widened by this layer, the only one with an optional `projectRoot` to read. Assigned by the base constructor - `declare` so no field initializer runs here and overwrites it with `undefined`. */
|
|
24
|
+
protected configs: IWorkerApplicationConfigs;
|
|
22
25
|
/** Resolves once the router tree is mounted - what an envelope arriving during boot waits on. */
|
|
23
26
|
private servingPromise?;
|
|
24
27
|
/** The whole `listen()` call, kept so a second one is a no-op instead of a second listener. */
|
|
25
28
|
private listenPromise?;
|
|
26
29
|
private detachFromScope?;
|
|
27
30
|
private isStopped;
|
|
31
|
+
/**
|
|
32
|
+
* `configs.projectRoot` wins, else the host's own working directory - read as
|
|
33
|
+
* `globalThis.process?.cwd?.()`, never a bare `process.cwd()`, because a real browser Worker has no
|
|
34
|
+
* such global and this class ships there. Bound AND shared with `ModuleUtility` (through the
|
|
35
|
+
* purity-safe `ProjectRootRegistry`), the same seam `ServerApplication` gives a socket host. No
|
|
36
|
+
* `node_modules` check here, unlike that host: a browser has no filesystem to check, and `node:fs`
|
|
37
|
+
* would bundle a Node builtin straight into a Worker.
|
|
38
|
+
*/
|
|
39
|
+
getProjectRoot(): string;
|
|
28
40
|
/**
|
|
29
41
|
* Every failure here is posted back as an `IBffErrorEnvelope`, the failed `postMessage` included:
|
|
30
42
|
* an exception nobody posts leaves the UI waiting out the transport timeout.
|
|
@@ -53,14 +65,14 @@ export declare abstract class WorkerApplication<AppEnv extends Env = Env, AppSch
|
|
|
53
65
|
scope?: MessagePort | IWorkerMessageScope;
|
|
54
66
|
}): Promise<void>;
|
|
55
67
|
/**
|
|
56
|
-
* The counterpart to `listen()`, and to `ServerApplication.stop()`:
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
68
|
+
* The counterpart to `listen()`, and to `ServerApplication.stop()`: runs the post-stop hooks, then
|
|
69
|
+
* closes every datasource the boot configured. Without it the OPFS exclusive lock a PGlite holds
|
|
70
|
+
* is never released - the next Worker then fails with `NoModificationAllowedError` until a full
|
|
71
|
+
* page reload. The Vite recipe is `import.meta.hot?.dispose(() => application.stop())`.
|
|
60
72
|
*
|
|
61
73
|
* Detaches BEFORE draining, unlike the server: here the listener IS the socket, and a request
|
|
62
|
-
* admitted while
|
|
63
|
-
*
|
|
74
|
+
* admitted while a datasource is closing has nothing left to run against. A stopped application
|
|
75
|
+
* is not restartable - build a new one.
|
|
64
76
|
*/
|
|
65
77
|
stop(): Promise<void>;
|
|
66
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/applications/worker.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/applications/worker.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGxC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,WAAW,CAAC,GAAG,IAAI,CAAC;IACjF,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI,CAAC;IACjF,mBAAmB,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI,CAAC;IACrF,KAAK,CAAC,IAAI,IAAI,CAAC;CAChB;AAED;;;;;GAKG;AACH,8BAAsB,iBAAiB,CACrC,MAAM,SAAS,GAAG,GAAG,GAAG,EACxB,SAAS,SAAS,MAAM,GAAG,EAAE,EAC7B,QAAQ,SAAS,MAAM,GAAG,GAAG,CAC7B,SAAQ,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC;IACpD,qMAAqM;IACrM,UAAkB,OAAO,EAAE,yBAAyB,CAAC;IAErD,iGAAiG;IACjG,OAAO,CAAC,cAAc,CAAC,CAAgB;IACvC,+FAA+F;IAC/F,OAAO,CAAC,aAAa,CAAC,CAAgB;IACtC,OAAO,CAAC,eAAe,CAAC,CAAa;IACrC,OAAO,CAAC,SAAS,CAAS;IAE1B;;;;;;;OAOG;IACM,cAAc,IAAI,MAAM;IASjC;;;OAGG;YACW,aAAa;IAoC3B,kKAAkK;IAClK,OAAO,CAAC,iBAAiB;IAgBzB,kIAAkI;YACpH,YAAY;IAW1B;;;;;OAKG;YACW,eAAe;IAqC7B,OAAO,CAAC,QAAQ;IAsChB;;;;;;OAMG;IACG,MAAM,CAAC,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,WAAW,GAAG,mBAAmB,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBjF;;;;;;;;;OASG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAW5B"}
|
|
@@ -16,6 +16,20 @@ class WorkerApplication extends ignis_kernel_1.RestApplication {
|
|
|
16
16
|
super(...arguments);
|
|
17
17
|
this.isStopped = false;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* `configs.projectRoot` wins, else the host's own working directory - read as
|
|
21
|
+
* `globalThis.process?.cwd?.()`, never a bare `process.cwd()`, because a real browser Worker has no
|
|
22
|
+
* such global and this class ships there. Bound AND shared with `ModuleUtility` (through the
|
|
23
|
+
* purity-safe `ProjectRootRegistry`), the same seam `ServerApplication` gives a socket host. No
|
|
24
|
+
* `node_modules` check here, unlike that host: a browser has no filesystem to check, and `node:fs`
|
|
25
|
+
* would bundle a Node builtin straight into a Worker.
|
|
26
|
+
*/
|
|
27
|
+
getProjectRoot() {
|
|
28
|
+
const projectRoot = this.configs.projectRoot ?? globalThis.process?.cwd?.() ?? '';
|
|
29
|
+
this.bind({ key: ignis_kernel_1.CoreBindings.APPLICATION_PROJECT_ROOT }).toValue(projectRoot);
|
|
30
|
+
core_1.ProjectRootRegistry.set({ projectRoot });
|
|
31
|
+
return projectRoot;
|
|
32
|
+
}
|
|
19
33
|
/**
|
|
20
34
|
* Every failure here is posted back as an `IBffErrorEnvelope`, the failed `postMessage` included:
|
|
21
35
|
* an exception nobody posts leaves the UI waiting out the transport timeout.
|
|
@@ -154,20 +168,21 @@ class WorkerApplication extends ignis_kernel_1.RestApplication {
|
|
|
154
168
|
return this.listenPromise;
|
|
155
169
|
}
|
|
156
170
|
/**
|
|
157
|
-
* The counterpart to `listen()`, and to `ServerApplication.stop()`:
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
171
|
+
* The counterpart to `listen()`, and to `ServerApplication.stop()`: runs the post-stop hooks, then
|
|
172
|
+
* closes every datasource the boot configured. Without it the OPFS exclusive lock a PGlite holds
|
|
173
|
+
* is never released - the next Worker then fails with `NoModificationAllowedError` until a full
|
|
174
|
+
* page reload. The Vite recipe is `import.meta.hot?.dispose(() => application.stop())`.
|
|
161
175
|
*
|
|
162
176
|
* Detaches BEFORE draining, unlike the server: here the listener IS the socket, and a request
|
|
163
|
-
* admitted while
|
|
164
|
-
*
|
|
177
|
+
* admitted while a datasource is closing has nothing left to run against. A stopped application
|
|
178
|
+
* is not restartable - build a new one.
|
|
165
179
|
*/
|
|
166
180
|
async stop() {
|
|
167
181
|
this.isStopped = true;
|
|
168
182
|
this.detachFromScope?.();
|
|
169
183
|
this.detachFromScope = undefined;
|
|
170
184
|
await this.executePostStopHooks();
|
|
185
|
+
await this.closeDataSources();
|
|
171
186
|
this.logger.for(this.stop.name).info('Worker application STOPPED');
|
|
172
187
|
}
|
|
173
188
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/applications/worker.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/applications/worker.ts"],"names":[],"mappings":";;;AAAA,sDAA4E;AAC5E,0DAAqD;AACrD,wDAAsE;AAEtE,8CAAgD;AAiBhD;;;;;GAKG;AACH,MAAsB,iBAIpB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,IAAI,EAAE,KAAK,IAAK,UAAkC,CAAC;QAErD,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAEzB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAC1C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC,CAAC;QAElF,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAEtB,IAAI,CAAC,eAAe,EAAE,EAAE,CAAC;QACzB,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QAEjC,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAClC,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAE9B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IACrE,CAAC;CACF;AAvOD,8CAuOC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/envelope/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/envelope/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/envelope/common/types.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEvD,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,gBAAgB,CAAC;IAC1B,+EAA+E;IAC/E,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CACxD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/envelope/common/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ApplicationError } from '@venizia/ignis-helpers/core';
|
|
2
|
-
import type { IBffErrorEnvelope, IBffRequestEnvelope, IBffResponseEnvelope } from './
|
|
2
|
+
import type { IBffErrorEnvelope, IBffRequestEnvelope, IBffResponseEnvelope } from './common';
|
|
3
3
|
/**
|
|
4
4
|
* Every request built inside the Worker uses this origin. Never `self.location.href`: a `blob:`
|
|
5
5
|
* worker origin is opaque and `new URL(path, blobUrl)` throws, and Hono's `getPath()` mis-parses
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../src/envelope/encode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAGpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../src/envelope/encode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAGpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAE7F;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,0BAA0B,CAAC;AAE5D,+IAA+I;AAC/I,qBAAa,WAAW;IACtB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAA4B;IAEtE;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM;IAKpD;;;;;OAKG;WACU,aAAa,CAAC,IAAI,EAAE;QAC/B,OAAO,EAAE,OAAO,CAAC;QACjB,EAAE,EAAE,MAAM,CAAC;QACX,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAahC,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,mBAAmB,CAAA;KAAE,GAAG,OAAO;WAUzD,cAAc,CAAC,IAAI,EAAE;QAChC,QAAQ,EAAE,QAAQ,CAAC;QACnB,EAAE,EAAE,MAAM,CAAC;KACZ,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAajC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,oBAAoB,CAAA;KAAE,GAAG,QAAQ;IAazE;;;;;;;OAOG;IACH,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,GAAG,iBAAiB;IAoB3E,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,iBAAiB,CAAA;KAAE,GAAG,gBAAgB;CAc5E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
|
|
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common"), exports);
|
|
17
18
|
__exportStar(require("./encode"), exports);
|
|
18
|
-
__exportStar(require("./types"), exports);
|
|
19
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const DEFAULT_CHANNEL_NAME = "ignis.bff";
|
|
2
|
+
export declare const DEFAULT_TIMEOUT_MS = 30000;
|
|
3
|
+
/** Which part this tab plays. `ELECTING` is the brief window before the lock answers. */
|
|
4
|
+
export declare class BffRoles {
|
|
5
|
+
static readonly ELECTING = "electing";
|
|
6
|
+
static readonly LEADER = "leader";
|
|
7
|
+
static readonly FOLLOWER = "follower";
|
|
8
|
+
}
|
|
9
|
+
export declare class ChannelMessageKinds {
|
|
10
|
+
static readonly REQUEST = "ignis.bff.request";
|
|
11
|
+
static readonly RESPONSE = "ignis.bff.response";
|
|
12
|
+
static readonly ERROR = "ignis.bff.error";
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../src/transport/shared/common/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAChD,eAAO,MAAM,kBAAkB,QAAS,CAAC;AAEzC,yFAAyF;AACzF,qBAAa,QAAQ;IACnB,MAAM,CAAC,QAAQ,CAAC,QAAQ,cAAc;IACtC,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAClC,MAAM,CAAC,QAAQ,CAAC,QAAQ,cAAc;CACvC;AAED,qBAAa,mBAAmB;IAC9B,MAAM,CAAC,QAAQ,CAAC,OAAO,uBAAuB;IAC9C,MAAM,CAAC,QAAQ,CAAC,QAAQ,wBAAwB;IAChD,MAAM,CAAC,QAAQ,CAAC,KAAK,qBAAqB;CAC3C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChannelMessageKinds = exports.BffRoles = exports.DEFAULT_TIMEOUT_MS = exports.DEFAULT_CHANNEL_NAME = void 0;
|
|
4
|
+
exports.DEFAULT_CHANNEL_NAME = 'ignis.bff';
|
|
5
|
+
exports.DEFAULT_TIMEOUT_MS = 30_000;
|
|
6
|
+
/** Which part this tab plays. `ELECTING` is the brief window before the lock answers. */
|
|
7
|
+
class BffRoles {
|
|
8
|
+
static { this.ELECTING = 'electing'; }
|
|
9
|
+
static { this.LEADER = 'leader'; }
|
|
10
|
+
static { this.FOLLOWER = 'follower'; }
|
|
11
|
+
}
|
|
12
|
+
exports.BffRoles = BffRoles;
|
|
13
|
+
class ChannelMessageKinds {
|
|
14
|
+
static { this.REQUEST = 'ignis.bff.request'; }
|
|
15
|
+
static { this.RESPONSE = 'ignis.bff.response'; }
|
|
16
|
+
static { this.ERROR = 'ignis.bff.error'; }
|
|
17
|
+
}
|
|
18
|
+
exports.ChannelMessageKinds = ChannelMessageKinds;
|
|
19
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/transport/shared/common/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,WAAW,CAAC;AACnC,QAAA,kBAAkB,GAAG,MAAM,CAAC;AAEzC,yFAAyF;AACzF,MAAa,QAAQ;aACH,aAAQ,GAAG,UAAU,CAAC;aACtB,WAAM,GAAG,QAAQ,CAAC;aAClB,aAAQ,GAAG,UAAU,CAAC;;AAHxC,4BAIC;AAED,MAAa,mBAAmB;aACd,YAAO,GAAG,mBAAmB,CAAC;aAC9B,aAAQ,GAAG,oBAAoB,CAAC;aAChC,UAAK,GAAG,iBAAiB,CAAC;;AAH5C,kDAIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/transport/shared/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constants"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/transport/shared/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,0CAAwB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { TConstValue } from '@venizia/ignis-helpers/common';
|
|
2
|
+
import type { IBffErrorEnvelope, IBffRequestEnvelope, IBffResponseEnvelope } from '../../../envelope/common';
|
|
3
|
+
import { BffRoles, ChannelMessageKinds } from './constants';
|
|
4
|
+
export type TBffRole = TConstValue<typeof BffRoles>;
|
|
5
|
+
/**
|
|
6
|
+
* There is deliberately no "a new leader is ready" broadcast. A follower cannot act on one safely:
|
|
7
|
+
* BroadcastChannel does not order messages across senders, so a request posted around the moment of
|
|
8
|
+
* promotion may well be answered by the new leader - and a follower that failed its in-flight
|
|
9
|
+
* requests on hearing the announcement would turn some of those successes into errors. The request
|
|
10
|
+
* timeout is the one honest answer for that window.
|
|
11
|
+
*/
|
|
12
|
+
export type TChannelMessage = {
|
|
13
|
+
kind: typeof ChannelMessageKinds.REQUEST;
|
|
14
|
+
envelope: IBffRequestEnvelope;
|
|
15
|
+
} | {
|
|
16
|
+
kind: typeof ChannelMessageKinds.RESPONSE;
|
|
17
|
+
envelope: IBffResponseEnvelope;
|
|
18
|
+
} | {
|
|
19
|
+
kind: typeof ChannelMessageKinds.ERROR;
|
|
20
|
+
envelope: IBffErrorEnvelope;
|
|
21
|
+
};
|
|
22
|
+
export interface IPendingRequest {
|
|
23
|
+
resolve: (response: Response) => void;
|
|
24
|
+
reject: (error: unknown) => void;
|
|
25
|
+
release: () => void;
|
|
26
|
+
}
|
|
27
|
+
export interface ISharedBffTransportOptions {
|
|
28
|
+
/** Builds the Worker. Called ONLY by whichever tab wins the election - the others never start one. */
|
|
29
|
+
createWorker: () => Worker;
|
|
30
|
+
/** Distinguishes independent BFFs on one origin. The lock name is derived from it. */
|
|
31
|
+
channelName?: string;
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
scope?: string;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/transport/shared/common/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE5D,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,OAAO,mBAAmB,CAAC,OAAO,CAAC;IAAC,QAAQ,EAAE,mBAAmB,CAAA;CAAE,GAC3E;IAAE,IAAI,EAAE,OAAO,mBAAmB,CAAC,QAAQ,CAAC;IAAC,QAAQ,EAAE,oBAAoB,CAAA;CAAE,GAC7E;IAAE,IAAI,EAAE,OAAO,mBAAmB,CAAC,KAAK,CAAC;IAAC,QAAQ,EAAE,iBAAiB,CAAA;CAAE,CAAC;AAE5E,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IACtC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACjC,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,0BAA0B;IACzC,sGAAsG;IACtG,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,sFAAsF;IACtF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/transport/shared/common/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/transport/shared/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,YAAY,EAAE,0BAA0B,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SharedBffTransport = exports.BffRoles = void 0;
|
|
4
|
+
// `export * from './common'` would also publish five module-private names - `DEFAULT_CHANNEL_NAME`,
|
|
5
|
+
// `DEFAULT_TIMEOUT_MS`, `ChannelMessageKinds`, `TChannelMessage`, `IPendingRequest` - through
|
|
6
|
+
// `transport/index.ts`.
|
|
7
|
+
var constants_1 = require("./common/constants");
|
|
8
|
+
Object.defineProperty(exports, "BffRoles", { enumerable: true, get: function () { return constants_1.BffRoles; } });
|
|
9
|
+
var transport_1 = require("./transport");
|
|
10
|
+
Object.defineProperty(exports, "SharedBffTransport", { enumerable: true, get: function () { return transport_1.SharedBffTransport; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/transport/shared/index.ts"],"names":[],"mappings":";;;AAAA,oGAAoG;AACpG,8FAA8F;AAC9F,wBAAwB;AACxB,gDAA8C;AAArC,qGAAA,QAAQ,OAAA;AAEjB,yCAAiD;AAAxC,+GAAA,kBAAkB,OAAA"}
|
|
@@ -1,21 +1,6 @@
|
|
|
1
1
|
import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
/** Which part this tab plays. `ELECTING` is the brief window before the lock answers. */
|
|
5
|
-
export declare class BffRoles {
|
|
6
|
-
static readonly ELECTING = "electing";
|
|
7
|
-
static readonly LEADER = "leader";
|
|
8
|
-
static readonly FOLLOWER = "follower";
|
|
9
|
-
}
|
|
10
|
-
export type TBffRole = TConstValue<typeof BffRoles>;
|
|
11
|
-
export interface ISharedBffTransportOptions {
|
|
12
|
-
/** Builds the Worker. Called ONLY by whichever tab wins the election - the others never start one. */
|
|
13
|
-
createWorker: () => Worker;
|
|
14
|
-
/** Distinguishes independent BFFs on one origin. The lock name is derived from it. */
|
|
15
|
-
channelName?: string;
|
|
16
|
-
timeoutMs?: number;
|
|
17
|
-
scope?: string;
|
|
18
|
-
}
|
|
2
|
+
import type { IBffTransport } from '../common/types';
|
|
3
|
+
import type { ISharedBffTransportOptions, TBffRole } from './common';
|
|
19
4
|
/**
|
|
20
5
|
* One BFF for every tab of an origin, instead of one per tab.
|
|
21
6
|
*
|
|
@@ -99,4 +84,4 @@ export declare class SharedBffTransport extends BaseHelper implements IBffTransp
|
|
|
99
84
|
private readonly handleChannelMessage;
|
|
100
85
|
private serveAsLeader;
|
|
101
86
|
}
|
|
102
|
-
//# sourceMappingURL=
|
|
87
|
+
//# sourceMappingURL=transport.d.ts.map
|