@venizia/ignis-worker 0.5.0-14 → 0.5.0-16
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ApplicationError } from '@venizia/ignis-helpers/core';
|
|
2
2
|
import type { IBffErrorEnvelope, IBffRequestEnvelope, IBffResponseEnvelope } from './common/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Every request built inside the Worker uses this origin. Never `self.location.href`: a `blob:`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fromError, getError,
|
|
1
|
+
import { fromError, getError, ApplicationError, RecordUtility } from '@venizia/ignis-helpers/core';
|
|
2
2
|
import { HTTP } from '@venizia/ignis-helpers/common';
|
|
3
3
|
/**
|
|
4
4
|
* Every request built inside the Worker uses this origin. Never `self.location.href`: a `blob:`
|
|
@@ -89,7 +89,7 @@ export class BffEnvelope {
|
|
|
89
89
|
*/
|
|
90
90
|
static encodeError(opts) {
|
|
91
91
|
const { id, error } = opts;
|
|
92
|
-
const applicationError = isApplicationError(error)
|
|
92
|
+
const applicationError = ApplicationError.isApplicationError(error)
|
|
93
93
|
? error
|
|
94
94
|
: getError({
|
|
95
95
|
statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../../src/envelope/encode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../../src/envelope/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACnG,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAGrD;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AAE5D,+IAA+I;AAC/I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,KAAK,CAAC;YACjE,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,QAAQ,CAAC;gBACP,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAChE,CAAC,CAAC;QAEP,OAAO;YACL,EAAE;YACF,UAAU,EAAE,gBAAgB,CAAC,UAAU;YACvC,KAAK,EAAE;gBACL,IAAI,EAAE,gBAAgB,CAAC,UAAU,CAAC,IAAI;gBACtC,IAAI,EAAE,gBAAgB,CAAC,UAAU,CAAC,IAAI;gBACtC,IAAI,EAAE,gBAAgB,CAAC,UAAU,CAAC,IAAI;aACvC;SACF,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,IAAqC;QACtD,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAC1B,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC;QAEhC,OAAO,SAAS,CAAC;YACf,KAAK,EAAE;gBACL,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI;oBACzB,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI;oBACzB,IAAI,EAAE,aAAa,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;iBAC3D;aACF;SACF,CAAC,CAAC;IACL,CAAC","sourcesContent":["import { fromError, getError, ApplicationError, RecordUtility } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { IBffErrorEnvelope, IBffRequestEnvelope, IBffResponseEnvelope } from './common';\n\n/**\n * Every request built inside the Worker uses this origin. Never `self.location.href`: a `blob:`\n * worker origin is opaque and `new URL(path, blobUrl)` throws, and Hono's `getPath()` mis-parses\n * `file://`. Hono never resolves the host - it string-scans from `indexOf(':') + 4`.\n */\nexport const BFF_SYNTHETIC_ORIGIN = 'http://ignis.internal';\n\n/** Turns `Request`/`Response`/`Error` into plain structured-cloneable shapes and back - none of the three survives `postMessage` as itself. */\nexport class BffEnvelope {\n /**\n * Statuses the Fetch spec forbids a body on - `new Response(body, { status })` throws if `body`\n * is anything but `null` for one of these, even an empty `ArrayBuffer`.\n */\n private static readonly NULL_BODY_STATUSES = new Set([204, 205, 304]);\n\n /**\n * Moves a URL onto the synthetic origin, keeping everything below it. A caller builds a request\n * against the page's real origin (or a relative path resolved against it); `decodeRequest` on the\n * far side always reconstructs on `BFF_SYNTHETIC_ORIGIN`.\n */\n static toSyntheticUrl(opts: { url: string }): string {\n const url = new URL(opts.url);\n\n return `${BFF_SYNTHETIC_ORIGIN}${url.pathname}${url.search}${url.hash}`;\n }\n\n /**\n * `url` overrides the request's own, so the origin rewrite costs nothing: rebuilding the `Request`\n * to change its URL would read the body a second time, and a 10 MB upload would hold 20 MB on the\n * UI thread. Reading the body here disturbs the caller's request exactly as `globalThis.fetch`\n * does with the one it is handed.\n */\n static async encodeRequest(opts: {\n request: Request;\n id: string;\n url?: string;\n }): Promise<IBffRequestEnvelope> {\n const { request, id, url } = opts;\n const hasBody = request.method !== 'GET' && request.method !== 'HEAD';\n\n let body: ArrayBuffer | undefined;\n\n if (hasBody) {\n const buffer = await request.arrayBuffer();\n body = buffer;\n }\n\n return {\n id,\n method: request.method,\n url: url ?? request.url,\n headers: [...request.headers.entries()],\n body,\n };\n }\n\n static decodeRequest(opts: { envelope: IBffRequestEnvelope }): Request {\n const { envelope } = opts;\n\n return new Request(envelope.url, {\n method: envelope.method,\n headers: envelope.headers,\n body: envelope.body,\n });\n }\n\n static async encodeResponse(opts: {\n response: Response;\n id: string;\n }): Promise<IBffResponseEnvelope> {\n const { response, id } = opts;\n const hasBody = !BffEnvelope.NULL_BODY_STATUSES.has(response.status);\n\n let body: ArrayBuffer | undefined;\n\n if (hasBody) {\n const buffer = await response.arrayBuffer();\n body = buffer;\n }\n\n return {\n id,\n status: response.status,\n statusText: response.statusText,\n headers: [...response.headers.entries()],\n body,\n };\n }\n\n static decodeResponse(opts: { envelope: IBffResponseEnvelope }): Response {\n const { envelope } = opts;\n const body = BffEnvelope.NULL_BODY_STATUSES.has(envelope.status)\n ? null\n : (envelope.body ?? null);\n\n return new Response(body, {\n status: envelope.status,\n statusText: envelope.statusText,\n headers: envelope.headers,\n });\n }\n\n /**\n * Builds the shape an error crosses `postMessage` as. An `ApplicationError` cannot cross as itself\n * - a custom `Error` subclass loses its name, its own properties and its prototype through\n * structured clone - so it crosses normalised and `decodeError` rebuilds it on the far side.\n *\n * A foreign error gets `500`, matching what the framework's error middleware gives an UNEXPECTED\n * one on the server. Anything reaching here already escaped the whole HTTP layer.\n */\n static encodeError(opts: { id: string; error: unknown }): IBffErrorEnvelope {\n const { id, error } = opts;\n const applicationError = ApplicationError.isApplicationError(error)\n ? error\n : getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: error instanceof Error ? error.message : String(error),\n });\n\n return {\n id,\n statusCode: applicationError.statusCode,\n error: {\n text: applicationError.normalized.text,\n code: applicationError.normalized.code,\n args: applicationError.normalized.args,\n },\n };\n }\n\n static decodeError(opts: { envelope: IBffErrorEnvelope }): ApplicationError {\n const { envelope } = opts;\n const { args } = envelope.error;\n\n return fromError({\n error: {\n statusCode: envelope.statusCode,\n normalized: {\n text: envelope.error.text,\n code: envelope.error.code,\n args: RecordUtility.isPlainRecord(args) ? args : undefined,\n },\n },\n });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/ignis-worker",
|
|
3
|
-
"version": "0.5.0-
|
|
3
|
+
"version": "0.5.0-16",
|
|
4
4
|
"description": "Browser Web Worker host for the IGNIS framework: the request/response envelope, the transport contract, and WorkerApplication - the layer that listens on `onmessage` instead of a socket, so a RestApplication can serve its controllers with no server anywhere.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"browser",
|
|
@@ -56,14 +56,14 @@
|
|
|
56
56
|
"force-update": "sh ../../scripts/build/force-update.sh"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@venizia/ignis-helpers": "0.5.0-
|
|
60
|
-
"@venizia/ignis-inversion": "0.5.0-
|
|
61
|
-
"@venizia/ignis-kernel": "0.5.0-
|
|
59
|
+
"@venizia/ignis-helpers": "0.5.0-15",
|
|
60
|
+
"@venizia/ignis-inversion": "0.5.0-7",
|
|
61
|
+
"@venizia/ignis-kernel": "0.5.0-16",
|
|
62
62
|
"reflect-metadata": "^0.2.2"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@types/bun": "^1.4.5",
|
|
66
|
-
"@venizia/dev-configs": "0.5.0-
|
|
66
|
+
"@venizia/dev-configs": "0.5.0-13",
|
|
67
67
|
"eslint": "^10.15.0",
|
|
68
68
|
"oxlint": "1.95.0",
|
|
69
69
|
"oxlint-tsgolint": "7.0.2009",
|