@lango-project/lango-server 0.2.3 → 0.2.5
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 +22 -3
- package/dist/body_reader.mjs.map +1 -1
- package/dist/builder.mjs +26 -2
- package/dist/builder.mjs.map +1 -1
- package/dist/cli/server.mjs +3 -835
- package/dist/cli/server.mjs.map +1 -1
- package/dist/client_identity.mjs.map +1 -1
- package/dist/database.mjs.map +1 -1
- package/dist/database_action.mjs +71 -0
- package/dist/database_action.mjs.map +1 -0
- package/dist/database_options.mjs.map +1 -1
- package/dist/database_scope.mjs +11 -0
- package/dist/database_scope.mjs.map +1 -1
- package/dist/endpoint.mjs.map +1 -1
- package/dist/error_details.mjs.map +1 -1
- package/dist/execution_failure.mjs +30 -0
- package/dist/execution_failure.mjs.map +1 -0
- package/dist/execution_identity.mjs +103 -0
- package/dist/execution_identity.mjs.map +1 -0
- package/dist/execution_log.mjs +47 -0
- package/dist/execution_log.mjs.map +1 -0
- package/dist/execution_runtime.mjs +201 -0
- package/dist/execution_runtime.mjs.map +1 -0
- package/dist/execution_worker.mjs +41 -0
- package/dist/execution_worker.mjs.map +1 -0
- package/dist/executor.mjs +384 -0
- package/dist/executor.mjs.map +1 -0
- package/dist/group.mjs +15 -0
- package/dist/group.mjs.map +1 -1
- package/dist/http_failure.mjs.map +1 -1
- package/dist/job_configuration.mjs +37 -0
- package/dist/job_configuration.mjs.map +1 -0
- package/dist/job_context.mjs +61 -0
- package/dist/job_context.mjs.map +1 -0
- package/dist/library.mjs +31 -0
- package/dist/library.mjs.map +1 -1
- package/dist/longpoll_broker.mjs.map +1 -1
- package/dist/longpoll_options.mjs.map +1 -1
- package/dist/longpoll_session.mjs.map +1 -1
- package/dist/middleware.mjs +1 -1
- package/dist/middleware.mjs.map +1 -1
- package/dist/module_loader.mjs +44 -0
- package/dist/module_loader.mjs.map +1 -0
- package/dist/options.mjs +12 -1
- package/dist/options.mjs.map +1 -1
- package/dist/origin.mjs.map +1 -1
- package/dist/policy.mjs.map +1 -1
- package/dist/postgres_adapter.mjs +12 -1
- package/dist/postgres_adapter.mjs.map +1 -1
- package/dist/postgres_worker.mjs +67 -5
- package/dist/postgres_worker.mjs.map +1 -1
- package/dist/queue_provider.mjs +52 -0
- package/dist/queue_provider.mjs.map +1 -0
- package/dist/request_identity.mjs.map +1 -1
- package/dist/response.mjs.map +1 -1
- package/dist/route_info.mjs.map +1 -1
- package/dist/route_pattern.mjs.map +1 -1
- package/dist/routes.mjs +36 -1
- package/dist/routes.mjs.map +1 -1
- package/dist/runtime.mjs +65 -25
- package/dist/runtime.mjs.map +1 -1
- package/dist/server.mjs +4 -1
- package/dist/server.mjs.map +1 -1
- package/dist/server_context.mjs.map +1 -1
- package/dist/sqlite_adapter.mjs.map +1 -1
- package/dist/static_files.mjs.map +1 -1
- package/dist/token.mjs.map +1 -1
- package/dist/tokens.mjs.map +1 -1
- package/dist/trace.mjs.map +1 -1
- package/dist/worker.mjs.map +1 -1
- package/docs/jobs.md +123 -0
- package/examples/security/package.json +1 -1
- package/package.json +10 -6
- package/src/builder.lango +22 -0
- package/src/database_action.lango +30 -0
- package/src/database_scope.lango +7 -0
- package/src/execution_failure.lango +14 -0
- package/src/execution_identity.lango +71 -0
- package/src/execution_log.lango +28 -0
- package/src/execution_runtime.lango +135 -0
- package/src/execution_worker.lango +32 -0
- package/src/executor.lango +284 -0
- package/src/group.lango +11 -0
- package/src/job_configuration.lango +29 -0
- package/src/job_context.lango +44 -0
- package/src/library.lango +21 -0
- package/src/middleware.lango +1 -1
- package/src/module_loader.lango +25 -0
- package/src/options.lango +7 -1
- package/src/postgres_adapter.lango +12 -0
- package/src/postgres_worker.lango +54 -3
- package/src/queue_provider.lango +30 -0
- package/src/routes.lango +44 -0
- package/src/runtime.lango +45 -17
- package/src/server.lango +3 -0
- package/dist/cli/.lango/bignumber.mjs +0 -3119
- package/dist/cli/.lango/localization.mjs +0 -108
- package/dist/cli/.lango/runtime.mjs +0 -725
- package/dist/cli/.lango/vendor/i18next.LICENSE +0 -21
- package/dist/cli/.lango/vendor/i18next.mjs +0 -2434
- package/dist/cli/.lango/xmldom/conventions.js +0 -429
- package/dist/cli/.lango/xmldom/dom-parser.js +0 -591
- package/dist/cli/.lango/xmldom/dom.js +0 -3759
- package/dist/cli/.lango/xmldom/entities.js +0 -2171
- package/dist/cli/.lango/xmldom/errors.js +0 -205
- package/dist/cli/.lango/xmldom/grammar.js +0 -559
- package/dist/cli/.lango/xmldom/index.js +0 -41
- package/dist/cli/.lango/xmldom/package.json +0 -1
- package/dist/cli/.lango/xmldom/sax.js +0 -983
- package/dist/cli/.lango/xmldom.LICENSE.md +0 -8
- package/dist/cli/body_reader.mjs +0 -180
- package/dist/cli/body_reader.mjs.map +0 -1
- package/dist/cli/client_identity.mjs +0 -250
- package/dist/cli/client_identity.mjs.map +0 -1
- package/dist/cli/database.mjs +0 -116
- package/dist/cli/database.mjs.map +0 -1
- package/dist/cli/database_options.mjs +0 -83
- package/dist/cli/database_options.mjs.map +0 -1
- package/dist/cli/database_scope.mjs +0 -82
- package/dist/cli/database_scope.mjs.map +0 -1
- package/dist/cli/endpoint.mjs +0 -50
- package/dist/cli/endpoint.mjs.map +0 -1
- package/dist/cli/error_details.mjs +0 -45
- package/dist/cli/error_details.mjs.map +0 -1
- package/dist/cli/longpoll_broker.mjs +0 -215
- package/dist/cli/longpoll_broker.mjs.map +0 -1
- package/dist/cli/longpoll_options.mjs +0 -103
- package/dist/cli/longpoll_options.mjs.map +0 -1
- package/dist/cli/longpoll_session.mjs +0 -136
- package/dist/cli/longpoll_session.mjs.map +0 -1
- package/dist/cli/middleware.mjs +0 -25
- package/dist/cli/middleware.mjs.map +0 -1
- package/dist/cli/options.mjs +0 -203
- package/dist/cli/options.mjs.map +0 -1
- package/dist/cli/origin.mjs +0 -87
- package/dist/cli/origin.mjs.map +0 -1
- package/dist/cli/policy.mjs +0 -121
- package/dist/cli/policy.mjs.map +0 -1
- package/dist/cli/postgres_adapter.mjs +0 -167
- package/dist/cli/postgres_adapter.mjs.map +0 -1
- package/dist/cli/route_pattern.mjs +0 -129
- package/dist/cli/route_pattern.mjs.map +0 -1
- package/dist/cli/routes.mjs +0 -325
- package/dist/cli/routes.mjs.map +0 -1
- package/dist/cli/sqlite_adapter.mjs +0 -163
- package/dist/cli/sqlite_adapter.mjs.map +0 -1
- package/dist/cli/static_files.mjs +0 -224
- package/dist/cli/static_files.mjs.map +0 -1
- package/dist/cli/trace.mjs +0 -53
- package/dist/cli/trace.mjs.map +0 -1
package/dist/postgres_worker.mjs
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
import { ModuleLoader } from "./module_loader.mjs";
|
|
2
|
+
import { errorDetails } from "./error_details.mjs";
|
|
1
3
|
import * as pg from "pg";
|
|
2
4
|
import * as threads from "node:worker_threads";
|
|
5
|
+
import * as modules from "node:module";
|
|
6
|
+
import * as path from "node:path";
|
|
3
7
|
import {
|
|
4
8
|
hostGlobal as __hostGlobal,
|
|
5
9
|
bindContexts as __bindContexts,
|
|
10
|
+
isNumber as __isNumber,
|
|
11
|
+
isString as __isString,
|
|
12
|
+
isBool as __isBool,
|
|
13
|
+
isObject as __isObject,
|
|
14
|
+
isArray as __isArray,
|
|
6
15
|
requireBoolean as __requireBoolean,
|
|
7
16
|
normalize as __normalize,
|
|
8
17
|
finite as __finite,
|
|
18
|
+
call as __call,
|
|
9
19
|
boundary as __boundary,
|
|
10
20
|
requireArity as __requireArity,
|
|
11
21
|
withArity as __withArity,
|
|
@@ -13,6 +23,8 @@ import {
|
|
|
13
23
|
|
|
14
24
|
let state = initialState();
|
|
15
25
|
|
|
26
|
+
let loader = new ModuleLoader();
|
|
27
|
+
|
|
16
28
|
let installed = install();
|
|
17
29
|
function install() {
|
|
18
30
|
let port = threads.workerData.port;
|
|
@@ -29,17 +41,25 @@ function install() {
|
|
|
29
41
|
return null;
|
|
30
42
|
}), [0], "closure")).catch(__withArity(__bindContexts((error) => {
|
|
31
43
|
error = __boundary(error);
|
|
32
|
-
|
|
44
|
+
let sqlError = __requireBoolean(__isString(__normalize(error.code))) && __requireBoolean(error.code.length === 5);
|
|
45
|
+
if (__requireBoolean(__requireBoolean(__normalize(state.transaction) !== null) && __requireBoolean(__requireBoolean(__requireBoolean(__normalize(task.action) !== "invoke") || __requireBoolean(sqlError)) || __requireBoolean(__normalize(state.dead))))) {
|
|
33
46
|
state.transaction = "failed";
|
|
34
47
|
}
|
|
35
|
-
if (__requireBoolean(__requireBoolean(
|
|
48
|
+
if (__requireBoolean(__requireBoolean(__normalize(task.action) !== "invoke") && __requireBoolean(!__requireBoolean(sqlError)))) {
|
|
49
|
+
state.dead = true;
|
|
50
|
+
}
|
|
51
|
+
if (__requireBoolean(__requireBoolean(sqlError) && __requireBoolean(__normalize(error.code.startsWith("08"))))) {
|
|
36
52
|
state.dead = true;
|
|
37
53
|
}
|
|
38
54
|
let position = null;
|
|
55
|
+
let detail = null;
|
|
56
|
+
if (__requireBoolean(__requireBoolean(__normalize(task.action) === "invoke") && __requireBoolean(!__requireBoolean(sqlError)))) {
|
|
57
|
+
detail = errorDetails(error);
|
|
58
|
+
}
|
|
39
59
|
if (__requireBoolean(__normalize(error.position) !== null)) {
|
|
40
60
|
position = __normalize(__hostGlobal(["Number"]).parseInt(__normalize(error.position), 10));
|
|
41
61
|
}
|
|
42
|
-
reply({ failed: true, dead: __normalize(state.dead), code: __normalize(error.code), position: position, state: __normalize(state.transaction) });
|
|
62
|
+
reply({ failed: true, dead: __normalize(state.dead), code: __normalize(error.code), position: position, detail: detail, state: __normalize(state.transaction) });
|
|
43
63
|
return null;
|
|
44
64
|
return null;
|
|
45
65
|
}), [0], "closure"));
|
|
@@ -81,6 +101,8 @@ function execute(task) {
|
|
|
81
101
|
return success(__normalize(result.rows), changes);
|
|
82
102
|
return null;
|
|
83
103
|
}), [0], "closure"));
|
|
104
|
+
} else if (__normalize(task.action) === "invoke") {
|
|
105
|
+
return invoke(task);
|
|
84
106
|
} else if (__normalize(task.action) === "close") {
|
|
85
107
|
return __normalize(state.client.end()).then(__withArity(__bindContexts((ignored) => {
|
|
86
108
|
ignored = __boundary(ignored);
|
|
@@ -93,11 +115,51 @@ function execute(task) {
|
|
|
93
115
|
return null;
|
|
94
116
|
}
|
|
95
117
|
|
|
96
|
-
function
|
|
118
|
+
function invoke(task) {
|
|
119
|
+
__requireArity(arguments.length, [0], "invoke");
|
|
120
|
+
task = __boundary(task);
|
|
121
|
+
let spec = __normalize(task.spec);
|
|
122
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(spec === null) || __requireBoolean(!__requireBoolean(__isString(__normalize(spec.module))))) || __requireBoolean(__normalize(spec.module.startsWith("node:")))) || __requireBoolean(!__requireBoolean(__isString(__normalize(spec.handler)))))) {
|
|
123
|
+
throw "Database extension requires an application module and exported handler";
|
|
124
|
+
}
|
|
125
|
+
let resolver = __normalize(modules.createRequire(__normalize(path.join(threads.workerData.root, "package.json"))));
|
|
126
|
+
let file = __normalize(resolver.resolve(__normalize(spec.module)));
|
|
127
|
+
if (__requireBoolean(!__requireBoolean(__normalize(path.isAbsolute(file))))) {
|
|
128
|
+
throw "Database extension must resolve to an application file";
|
|
129
|
+
}
|
|
130
|
+
return __normalize(loader.target({ module: file, handler: __normalize(spec.handler) })).then(__withArity(__bindContexts((handler) => {
|
|
131
|
+
handler = __boundary(handler);
|
|
132
|
+
let client = __normalize(state.client);
|
|
133
|
+
let executeSql = __withArity(__bindContexts((sql, parameters) => {
|
|
134
|
+
sql = __boundary(sql);
|
|
135
|
+
parameters = __boundary(parameters);
|
|
136
|
+
return __normalize(client.query(sql, parameters)).catch(__withArity(__bindContexts((error) => {
|
|
137
|
+
error = __boundary(error);
|
|
138
|
+
if (__requireBoolean(__normalize(state.transaction) !== null)) {
|
|
139
|
+
state.transaction = "failed";
|
|
140
|
+
}
|
|
141
|
+
throw error;
|
|
142
|
+
return null;
|
|
143
|
+
}), [0], "closure"));
|
|
144
|
+
return null;
|
|
145
|
+
}), [0, 1], "closure");
|
|
146
|
+
let adapter = { executeSql: executeSql };
|
|
147
|
+
return __call(handler, adapter, __normalize(task.input));
|
|
148
|
+
return null;
|
|
149
|
+
}), [0], "closure")).then(__withArity(__bindContexts((value) => {
|
|
150
|
+
value = __boundary(value);
|
|
151
|
+
return success([], null, value);
|
|
152
|
+
return null;
|
|
153
|
+
}), [0], "closure"));
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function success(rows, changes, value = null) {
|
|
97
158
|
__requireArity(arguments.length, [0, 1], "success");
|
|
98
159
|
rows = __boundary(rows);
|
|
99
160
|
changes = __boundary(changes);
|
|
100
|
-
|
|
161
|
+
value = __boundary(value);
|
|
162
|
+
return { failed: false, dead: false, state: __normalize(state.transaction), rows: rows, changes: changes, lastInsertRowid: null, value: value };
|
|
101
163
|
return null;
|
|
102
164
|
}
|
|
103
165
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres_worker.mjs","sources":["postgres_worker.lango"],"sourcesContent":["import js \"pg\" as pg\nimport js \"node:worker_threads\" as threads\nimport js global Atomics\nimport js global Math\nimport js global Number\nimport js global Promise\n\n\nglobal state = initialState()\nglobal installed = install()\n\ninstall()\n port = threads.workerData.port\n port.on(\"message\", (task)\n return chain Promise/resolve(null)\n then(ignored)\n capture task\n return execute(task)\n then(result)\n reply(result)\n return null\n catch(error)\n global state\n if state.transaction != null\n state.transaction = \"failed\"\n if
|
|
1
|
+
{"version":3,"file":"postgres_worker.mjs","sources":["postgres_worker.lango"],"sourcesContent":["import js \"pg\" as pg\nimport js \"node:worker_threads\" as threads\nimport js \"node:module\" as modules\nimport js \"node:path\" as path\nimport \"./module_loader\"\n class ModuleLoader\nimport \"./error_details\"\n errorDetails(error)\nimport js global Atomics\nimport js global Math\nimport js global Number\nimport js global Promise\n\n\nglobal state = initialState()\nglobal loader = new ModuleLoader()\nglobal installed = install()\n\ninstall()\n port = threads.workerData.port\n port.on(\"message\", (task)\n return chain Promise/resolve(null)\n then(ignored)\n capture task\n return execute(task)\n then(result)\n reply(result)\n return null\n catch(error)\n capture task\n global state\n sqlError = is_string(error.code) and error.code.length == 5\n if state.transaction != null and (task.action != \"invoke\" or sqlError or state.dead)\n state.transaction = \"failed\"\n if task.action != \"invoke\" and !sqlError\n state.dead = true\n if sqlError and error.code.startsWith(\"08\")\n state.dead = true\n position = null\n detail = null\n if task.action == \"invoke\" and !sqlError\n detail = errorDetails(error)\n if error.position != null\n position = Number/parseInt(error.position, 10)\n reply({\n failed: true\n dead: state.dead\n code: error.code\n position: position\n detail: detail\n state: state.transaction\n })\n return null\n )\n return null\n\nexecute(task)\n global state\n settings = threads.workerData.settings\n switch task.action\n case \"connect\"\n state.client = new pg/Client({\n connectionString: settings.connection\n connectionTimeoutMillis: Math/min(2147483647, settings.connectTimeoutSeconds * 1000)\n statement_timeout: settings.queryTimeoutMs\n application_name: \"lango-server\"\n })\n client = state.client\n client.on(\"error\", (error)\n global state\n state.dead = true\n )\n return chain client.connect()\n then(ignored)\n return success([], null)\n case \"query\"\n return chain state.client.query({\n text: task.sql\n values: task.parameters\n queryMode: \"extended\"\n })\n then(result)\n global state\n switch result.command\n case \"BEGIN\"\n state.transaction = \"active\"\n case \"COMMIT\"\n case \"ROLLBACK\"\n state.transaction = null\n changes = null\n switch result.command\n case \"INSERT\"\n case \"UPDATE\"\n case \"DELETE\"\n case \"MERGE\"\n changes = result.rowCount\n return success(result.rows, changes)\n case \"invoke\"\n return invoke(task)\n case \"close\"\n return chain state.client.end()\n then(ignored)\n return success([], null)\n else\n throw \"Unknown PostgreSQL operation\"\n\ninvoke(task)\n global state\n global loader\n spec = task.spec\n if spec == null or !is_string(spec.module) or spec.module.startsWith(\"node:\") or !is_string(spec.handler)\n throw \"Database extension requires an application module and exported handler\"\n resolver = modules/createRequire(path/join(threads.workerData.root, \"package.json\"))\n file = resolver.resolve(spec.module)\n if !path/isAbsolute(file)\n throw \"Database extension must resolve to an application file\"\n return chain loader.target({\n module: file\n handler: spec.handler\n })\n then(handler)\n capture task\n global state\n client = state.client\n executeSql = (sql, parameters)\n capture client\n return chain client.query(sql, parameters)\n catch(error)\n global state\n if state.transaction != null\n state.transaction = \"failed\"\n throw error\n adapter = {\n executeSql: executeSql\n }\n return handler(adapter, task.input)\n then(value)\n return success([], null, value)\n\nsuccess(rows, changes, value = null)\n global state\n return {\n failed: false\n dead: false\n state: state.transaction\n rows: rows\n changes: changes\n lastInsertRowid: null\n value: value\n }\n\nreply(result)\n port = threads.workerData.port\n signal = threads.workerData.signal\n port.postMessage(result)\n Atomics/store(signal, 0, 1)\n Atomics/notify(signal, 0)\n return null\n\ninitialState()\n return {\n client: null\n transaction: null\n dead: false\n }\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAcA;;AACA;;AACA;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA;;;;;;;;;AAYA;;;;;;;;;;;;AAQA;;;;;","x_lango_build":{"fingerprint":"5f1a033ebd280c53501bde3241f7d91d6ef3fbb9f429156ce929d802b18f104a","outputHash":"2a24a180c3846f7dd043467b301853e0fc164ad92af493f716139faf7b8ac26e","mapHash":"bb79353e1d011acd4174b953b351e7e4579529e0291f443837c5569741e69aed"}}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as modules from "node:module";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
fromJson as __fromJson,
|
|
5
|
+
toJson as __toJson,
|
|
6
|
+
isNumber as __isNumber,
|
|
7
|
+
isString as __isString,
|
|
8
|
+
isBool as __isBool,
|
|
9
|
+
isObject as __isObject,
|
|
10
|
+
isArray as __isArray,
|
|
11
|
+
entries as __entries,
|
|
12
|
+
requireBoolean as __requireBoolean,
|
|
13
|
+
normalize as __normalize,
|
|
14
|
+
boundary as __boundary,
|
|
15
|
+
requireArity as __requireArity,
|
|
16
|
+
} from "./.lango/runtime.mjs";
|
|
17
|
+
|
|
18
|
+
export function queueProvider(root, spec) {
|
|
19
|
+
__requireArity(arguments.length, [0, 1], "queueProvider");
|
|
20
|
+
root = __boundary(root);
|
|
21
|
+
spec = __boundary(spec);
|
|
22
|
+
if (__requireBoolean(spec === null)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(spec))) || __requireBoolean(__isArray(spec)))) {
|
|
26
|
+
throw "Queue provider must be a map";
|
|
27
|
+
}
|
|
28
|
+
let allowed = ["module", "handler", "options"];
|
|
29
|
+
for (const [key, value] of __entries(spec)) {
|
|
30
|
+
if (__requireBoolean(!__requireBoolean(__normalize(allowed.includes(key))))) {
|
|
31
|
+
throw `Unknown queue provider option: ${key}`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.module)))) || __requireBoolean(__normalize(spec.module) === "")) || __requireBoolean(__normalize(spec.module.startsWith("node:")))) || __requireBoolean(!__requireBoolean(__isString(__normalize(spec.handler))))) || __requireBoolean(__normalize(spec.handler) === ""))) {
|
|
35
|
+
throw "Queue provider requires a module and exported handler";
|
|
36
|
+
}
|
|
37
|
+
let settings = __normalize(spec.options);
|
|
38
|
+
if (__requireBoolean(settings === null)) {
|
|
39
|
+
settings = { };
|
|
40
|
+
}
|
|
41
|
+
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(settings))) || __requireBoolean(__isArray(settings)))) {
|
|
42
|
+
throw "Queue provider options must be a map";
|
|
43
|
+
}
|
|
44
|
+
let resolver = __normalize(modules.createRequire(__normalize(path.join(root, "package.json"))));
|
|
45
|
+
let file = __normalize(resolver.resolve(__normalize(spec.module)));
|
|
46
|
+
if (__requireBoolean(!__requireBoolean(__normalize(path.isAbsolute(file))))) {
|
|
47
|
+
throw "Queue provider must resolve to an application file";
|
|
48
|
+
}
|
|
49
|
+
return { module: file, handler: __normalize(spec.handler), options: __fromJson(__toJson(settings)) };
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=queue_provider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue_provider.mjs","sources":["queue_provider.lango"],"sourcesContent":["import js \"node:module\" as modules\nimport js \"node:path\" as path\n\nexport queueProvider(root, spec)\n\nqueueProvider(root, spec)\n if spec == null\n return null\n if !is_object(spec) or is_array(spec)\n throw \"Queue provider must be a map\"\n allowed = [\"module\", \"handler\", \"options\"]\n for spec as key: value\n if !allowed.includes(key)\n throw \"Unknown queue provider option: ${key}\"\n if !is_string(spec.module) or spec.module == \"\" or spec.module.startsWith(\"node:\") or !is_string(spec.handler) or spec.handler == \"\"\n throw \"Queue provider requires a module and exported handler\"\n settings = spec.options\n if settings == null\n settings = {}\n if !is_object(settings) or is_array(settings)\n throw \"Queue provider options must be a map\"\n resolver = modules/createRequire(path/join(root, \"package.json\"))\n file = resolver.resolve(spec.module)\n if !path/isAbsolute(file)\n throw \"Queue provider must resolve to an application file\"\n return {\n module: file\n handler: spec.handler\n options: from_json(to_json(settings))\n }\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"fbae9be51ef15cc946a94e3a193cf4260428e24b355ebeb7f8dbf9b35460c8bd","outputHash":"7b924822c507d160cee46337842664bf36db83792fb8b5c3c4ebd17365cea184","mapHash":"f64f06a53a58267f697302ffa5702bbe4fbb29526f28ca60043a711e4d5a0e44"}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request_identity.mjs","sources":["request_identity.lango"],"sourcesContent":["export requestIdentity(id, token)\n\nrequestIdentity(id, token)\n identity = \"[${id}] [clientId=${token.clientId?}]\"\n for [\"sessionId\", \"userId\"] as name\n value = token.get(name)\n if value != null\n identity = \"${identity} [${name}=${value}]\"\n return identity\n"],"names":[],"mappings":";;;;;;;AAEA;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"request_identity.mjs","sources":["request_identity.lango"],"sourcesContent":["export requestIdentity(id, token)\n\nrequestIdentity(id, token)\n identity = \"[${id}] [clientId=${token.clientId?}]\"\n for [\"sessionId\", \"userId\"] as name\n value = token.get(name)\n if value != null\n identity = \"${identity} [${name}=${value}]\"\n return identity\n"],"names":[],"mappings":";;;;;;;AAEA;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"d0657657971eb7768a16dc2e8f2c13bf0ad5555d5fa31b0ca7f779e03351dd25","outputHash":"f86a377f9647ef98a57b54007024780d72c58637452b72741638a81cec744607","mapHash":"d0cc4f2ec070f60fd9477fcdf4c0434480d44be85af866d68b6cbdb55e927107"}}
|
package/dist/response.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.mjs","sources":["response.lango"],"sourcesContent":["import js \"node:http\" as http\n\nimport \"./options\"\n contains(items, value)\nimport \"./http_failure\"\n class HttpFailure\nexport class Response()\n methods\n status(code)\n header(name, value)\n result(body)\n reject(status, code)\n\nResponse()\n @status = 200\n @headers = {\n \"content-type\": \"application/json; charset=utf-8\"\n \"cache-control\": \"no-store\"\n }\n\nResponse:status(code)\n if !is_number(code) or code % 1 != 0 or code < 200 or code > 599 or code == 204 or code == 205 or code == 304\n throw \"Response requires a JSON-compatible HTTP status\"\n @status = code\n return @this\n\nResponse:header(name, value)\n if !is_string(name) or !is_string(value)\n throw \"Header name and value must be strings\"\n name = name.toLowerCase()\n if contains([\"x-lango-auth-change\", \"x-lango-need-login\", \"x-lango-token\", \"content-length\", \"transfer-encoding\", \"connection\", \"content-type\"], name)\n throw \"Reserved response header: ${name}\"\n if name.includes(\"\\r\") or name.includes(\"\\n\") or value.includes(\"\\r\") or value.includes(\"\\n\")\n throw \"Invalid response header\"\n http/validateHeaderName(name)\n http/validateHeaderValue(name, value)\n @headers[name] = value\n return @this\n\nResponse:result(body)\n return {\n status: @status\n headers: from_json(to_json(@headers))\n body: body\n }\n\nResponse:reject(status, code)\n throw new HttpFailure(status, code, @headers)\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"response.mjs","sources":["response.lango"],"sourcesContent":["import js \"node:http\" as http\n\nimport \"./options\"\n contains(items, value)\nimport \"./http_failure\"\n class HttpFailure\nexport class Response()\n methods\n status(code)\n header(name, value)\n result(body)\n reject(status, code)\n\nResponse()\n @status = 200\n @headers = {\n \"content-type\": \"application/json; charset=utf-8\"\n \"cache-control\": \"no-store\"\n }\n\nResponse:status(code)\n if !is_number(code) or code % 1 != 0 or code < 200 or code > 599 or code == 204 or code == 205 or code == 304\n throw \"Response requires a JSON-compatible HTTP status\"\n @status = code\n return @this\n\nResponse:header(name, value)\n if !is_string(name) or !is_string(value)\n throw \"Header name and value must be strings\"\n name = name.toLowerCase()\n if contains([\"x-lango-auth-change\", \"x-lango-need-login\", \"x-lango-token\", \"content-length\", \"transfer-encoding\", \"connection\", \"content-type\"], name)\n throw \"Reserved response header: ${name}\"\n if name.includes(\"\\r\") or name.includes(\"\\n\") or value.includes(\"\\r\") or value.includes(\"\\n\")\n throw \"Invalid response header\"\n http/validateHeaderName(name)\n http/validateHeaderValue(name, value)\n @headers[name] = value\n return @this\n\nResponse:result(body)\n return {\n status: @status\n headers: from_json(to_json(@headers))\n body: body\n }\n\nResponse:reject(status, code)\n throw new HttpFailure(status, code, @headers)\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"e0f08a0617bb7e4a14ddd7a82724f4a3d50ca4927eaf9b611bcf3abf8515259d","outputHash":"925375a1a0db2d99d816d7ef9e018e2ae1edf0783ab71de8b0af92d3cbeb4518","mapHash":"506e2c7050fbe6236d22b9e0cbf64e1aed113a7ff954104c224c64f5e05933fc"}}
|
package/dist/route_info.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route_info.mjs","sources":["route_info.lango"],"sourcesContent":["export routeInfo(definitions)\n\nrouteInfo(definitions)\n result = []\n for definitions as route\n kind = route.kind\n if kind == null\n kind = \"endpoint\"\n result.add({\n path: route.path\n kind: kind\n auth: route.auth\n policy: route.policy\n reauthSeconds: route.reauthSeconds\n middleware: route.middleware\n })\n return result\n"],"names":[],"mappings":";;;;;;;AAEA;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"route_info.mjs","sources":["route_info.lango"],"sourcesContent":["export routeInfo(definitions)\n\nrouteInfo(definitions)\n result = []\n for definitions as route\n kind = route.kind\n if kind == null\n kind = \"endpoint\"\n result.add({\n path: route.path\n kind: kind\n auth: route.auth\n policy: route.policy\n reauthSeconds: route.reauthSeconds\n middleware: route.middleware\n })\n return result\n"],"names":[],"mappings":";;;;;;;AAEA;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"0cdab7de4d68736bedcc5c4c4a93f73bd5a436a7259a52b21eb017846896651f","outputHash":"c9a0a89a04b6619c0b764d2a19b93f7dd790a7d1a649a3f6cf597e4a8ce82d40","mapHash":"52b97867041a573580ac49e6e230d8cc683a7560ac5350653f45345f195d61ce"}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route_pattern.mjs","sources":["route_pattern.lango"],"sourcesContent":["import js global RegExp\n\nexport routePattern(path)\nexport matchPath(pattern, path)\nexport moreSpecific(candidate, current)\n\nroutePattern(path)\n if !is_string(path) or !path.startsWith(\"/\") or path.includes(\"?\") or path.includes(\"#\") or path.includes(\"\\\\\") or path.includes(\"//\")\n throw \"Endpoint requires an absolute URL path\"\n if path.includes(\"*\") and (!path.endsWith(\"/*\") or path.indexOf(\"*\") != path.lastIndexOf(\"*\"))\n throw \"Only trailing /* wildcards are supported\"\n segments = path.split(\"/\")\n segments = segments.slice(1)\n wildcard = path.endsWith(\"/*\")\n if wildcard\n segments.pop()\n names = []\n shape = []\n identifier = new RegExp(\"^[A-Za-z_][A-Za-z0-9_]*$\")\n reserved = [\"__proto__\", \"constructor\", \"prototype\"]\n for segments as segment\n if segment.includes(\"{\") or segment.includes(\"}\")\n if !segment.startsWith(\"{\") or !segment.endsWith(\"}\")\n throw \"Path parameters must occupy an entire segment\"\n name = segment.slice(1, -1)\n if !identifier.test(name) or reserved.includes(name)\n throw \"Invalid path parameter name: ${name}\"\n if names.includes(name)\n throw \"Duplicate path parameter: ${name}\"\n names.add(name)\n shape.add(\"{}\")\n else\n shape.add(segment)\n if wildcard\n shape.add(\"*\")\n key = shape.join(\"/\")\n key = \"/${key}\"\n return {\n segments: segments\n wildcard: wildcard\n key: key\n }\n\nmatchPath(pattern, path)\n parts = path.split(\"/\")\n if parts[0] != \"\"\n return null\n parts = parts.slice(1)\n count = pattern.segments.length\n if pattern.wildcard\n if parts.length <= count\n return null\n else\n if parts.length != count\n return null\n parameters = {}\n for pattern.segments as index: segment\n value = parts[index]\n if segment.startsWith(\"{\")\n if value == \"\"\n return null\n name = segment.slice(1, -1)\n parameters[name] = value\n else\n if segment != value\n return null\n return parameters\n\nmoreSpecific(candidate, current)\n if current == null\n return true\n if candidate.wildcard != current.wildcard\n return !candidate.wildcard\n first = candidate.segments\n second = current.segments\n count = first.length\n if second.length < count\n count = second.length\n for range(count) as index\n segment = first[index]\n alternative = second[index]\n literal = !segment.startsWith(\"{\")\n other = !alternative.startsWith(\"{\")\n if literal != other\n return literal\n return first.length > second.length\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"route_pattern.mjs","sources":["route_pattern.lango"],"sourcesContent":["import js global RegExp\n\nexport routePattern(path)\nexport matchPath(pattern, path)\nexport moreSpecific(candidate, current)\n\nroutePattern(path)\n if !is_string(path) or !path.startsWith(\"/\") or path.includes(\"?\") or path.includes(\"#\") or path.includes(\"\\\\\") or path.includes(\"//\")\n throw \"Endpoint requires an absolute URL path\"\n if path.includes(\"*\") and (!path.endsWith(\"/*\") or path.indexOf(\"*\") != path.lastIndexOf(\"*\"))\n throw \"Only trailing /* wildcards are supported\"\n segments = path.split(\"/\")\n segments = segments.slice(1)\n wildcard = path.endsWith(\"/*\")\n if wildcard\n segments.pop()\n names = []\n shape = []\n identifier = new RegExp(\"^[A-Za-z_][A-Za-z0-9_]*$\")\n reserved = [\"__proto__\", \"constructor\", \"prototype\"]\n for segments as segment\n if segment.includes(\"{\") or segment.includes(\"}\")\n if !segment.startsWith(\"{\") or !segment.endsWith(\"}\")\n throw \"Path parameters must occupy an entire segment\"\n name = segment.slice(1, -1)\n if !identifier.test(name) or reserved.includes(name)\n throw \"Invalid path parameter name: ${name}\"\n if names.includes(name)\n throw \"Duplicate path parameter: ${name}\"\n names.add(name)\n shape.add(\"{}\")\n else\n shape.add(segment)\n if wildcard\n shape.add(\"*\")\n key = shape.join(\"/\")\n key = \"/${key}\"\n return {\n segments: segments\n wildcard: wildcard\n key: key\n }\n\nmatchPath(pattern, path)\n parts = path.split(\"/\")\n if parts[0] != \"\"\n return null\n parts = parts.slice(1)\n count = pattern.segments.length\n if pattern.wildcard\n if parts.length <= count\n return null\n else\n if parts.length != count\n return null\n parameters = {}\n for pattern.segments as index: segment\n value = parts[index]\n if segment.startsWith(\"{\")\n if value == \"\"\n return null\n name = segment.slice(1, -1)\n parameters[name] = value\n else\n if segment != value\n return null\n return parameters\n\nmoreSpecific(candidate, current)\n if current == null\n return true\n if candidate.wildcard != current.wildcard\n return !candidate.wildcard\n first = candidate.segments\n second = current.segments\n count = first.length\n if second.length < count\n count = second.length\n for range(count) as index\n segment = first[index]\n alternative = second[index]\n literal = !segment.startsWith(\"{\")\n other = !alternative.startsWith(\"{\")\n if literal != other\n return literal\n return first.length > second.length\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"e6b107976409b75d589924fe9f4106aa3f10b264ea6ee41f218960874ade1d15","outputHash":"f23e79047182dd95bb0a62ca06aac2d8f31ac100a0574bece9eaa3ea963d82f4","mapHash":"6e4499c1aa27aab837169fcf03d5557900e323f1a0ebfcbb1d5c400b4c85910a"}}
|
package/dist/routes.mjs
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
export class Routes {
|
|
31
31
|
#root;
|
|
32
32
|
#items;
|
|
33
|
+
#jobs;
|
|
33
34
|
#events;
|
|
34
35
|
#middlewares;
|
|
35
36
|
constructor(root) {
|
|
@@ -37,6 +38,7 @@ export class Routes {
|
|
|
37
38
|
root = __boundary(root);
|
|
38
39
|
this.#root = __normalize(path.resolve(root));
|
|
39
40
|
this.#items = [];
|
|
41
|
+
this.#jobs = [];
|
|
40
42
|
this.#events = { };
|
|
41
43
|
this.#middlewares = __normalize(__hostGlobal(["Object"]).create(null));
|
|
42
44
|
}
|
|
@@ -65,6 +67,35 @@ export class Routes {
|
|
|
65
67
|
return null;
|
|
66
68
|
return null;
|
|
67
69
|
}
|
|
70
|
+
job(spec) {
|
|
71
|
+
__requireArity(arguments.length, [0], "job");
|
|
72
|
+
spec = __boundary(spec);
|
|
73
|
+
let allowed = ["path", "module", "handler", "queue", "policy", "auth", "reauthSeconds"];
|
|
74
|
+
for (const [key, value] of __entries(spec)) {
|
|
75
|
+
if (__requireBoolean(!__requireBoolean(__normalize(allowed.includes(key))))) {
|
|
76
|
+
throw `Unknown job route option: ${key}`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
let item = new Endpoint(spec);
|
|
80
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(item.path.includes("*"))) || __requireBoolean(__normalize(item.path.includes("{")))) || __requireBoolean(__normalize(item.path.includes("}"))))) {
|
|
81
|
+
throw "Job routes require an exact path";
|
|
82
|
+
}
|
|
83
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.queue)))) || __requireBoolean(__normalize(spec.queue.trim()) !== __normalize(spec.queue))) || __requireBoolean(__normalize(spec.queue) === ""))) {
|
|
84
|
+
throw "Job route requires a queue name";
|
|
85
|
+
}
|
|
86
|
+
for (const other of __normalize(this.#jobs)) {
|
|
87
|
+
if (__requireBoolean(__normalize(other.path) === __normalize(item.path))) {
|
|
88
|
+
throw `Duplicate job route: ${__normalize(item.path)}`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
__add(this.#jobs, { path: __normalize(item.path), module: resolveModule(__normalize(item.module), __normalize(this.#root)), handler: __normalize(item.handler), queue: __normalize(spec.queue), policy: __normalize(item.policy), auth: __normalize(item.auth), reauthSeconds: __normalize(item.reauthSeconds), reauthExplicit: __normalize(item.reauthExplicit), legacyAuth: __normalize(item.legacyAuth) });
|
|
92
|
+
return this;
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
jobs() {
|
|
96
|
+
return __fromJson(__toJson(__normalize(this.#jobs)));
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
68
99
|
addMiddleware(name, spec) {
|
|
69
100
|
__requireArity(arguments.length, [0, 1], "addMiddleware");
|
|
70
101
|
name = __boundary(name);
|
|
@@ -234,7 +265,11 @@ export class Routes {
|
|
|
234
265
|
if (__requireBoolean(reauthSeconds === null)) {
|
|
235
266
|
reauthSeconds = inheritedReauthSeconds;
|
|
236
267
|
}
|
|
237
|
-
if (__normalize(tag.tag()) === "
|
|
268
|
+
if (__normalize(tag.tag()) === "job") {
|
|
269
|
+
attributes(tag, ["path", "module", "handler", "queue", "auth", "policy", "reauthSeconds"]);
|
|
270
|
+
leaf(tag);
|
|
271
|
+
this.job({ path: joinPath(prefix, __normalize(spec.path)), module: resolveModule(mod, directory), handler: __normalize(spec.handler), queue: __normalize(spec.queue), auth: auth, policy: policy, reauthSeconds: reauthSeconds });
|
|
272
|
+
} else if (__normalize(tag.tag()) === "endpoint") {
|
|
238
273
|
attributes(tag, ["path", "module", "handler", "auth", "policy", "reauthSeconds"]);
|
|
239
274
|
leaf(tag);
|
|
240
275
|
this.endpoint({ path: joinPath(prefix, __normalize(spec.path)), module: resolveModule(mod, directory), handler: __normalize(spec.handler), auth: auth, policy: policy, reauthSeconds: reauthSeconds });
|
package/dist/routes.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.mjs","sources":["routes.lango"],"sourcesContent":["import \"./route_pattern\"\n routePattern(path)\nimport \"./options\"\n contains(items, value)\nimport js \"node:fs\" as fs\nimport js \"node:path\" as path\nimport js \"node:module\" as modules\nimport \"./options\"\n attributes(tag, allowed)\nimport js global Object\nimport \"./middleware\"\n middlewareName(name)\nimport \"./endpoint\"\n class Endpoint\n\nimport \"./longpoll_options\"\n longpollOptions(spec)\n\nexport class Routes(root)\n methods\n endpoint(spec)\n addMiddleware(name, spec)\n middlewares()\n longpoll(spec)\n include(spec, auth = null, policy = null, reauthSeconds = null)\n xml(file)\n definitions()\n events()\n event(spec)\n\nRoutes(root)\n @root = path/resolve(root)\n @items = []\n @events = {}\n @middlewares = Object/create(null)\n\nRoutes:endpoint(spec)\n item = new Endpoint(spec)\n checkPath(item.path)\n @items.add({\n path: item.path\n module: resolveModule(item.module, @root)\n handler: item.handler\n auth: item.auth\n policy: item.policy\n reauthSeconds: item.reauthSeconds\n reauthExplicit: item.reauthExplicit\n legacyAuth: item.legacyAuth\n middleware: item.middleware\n })\n return @this\n\nRoutes:checkPath(path)\n pattern = routePattern(path)\n for @items as other\n if other.path == path\n throw \"Duplicate endpoint: ${path}\"\n existing = routePattern(other.path)\n if existing.key == pattern.key\n throw \"Conflicting endpoint pattern: ${path}\"\n return null\n\nRoutes:addMiddleware(name, spec)\n middlewareName(name)\n if Object/hasOwn(@middlewares, name)\n throw \"Duplicate middleware: ${name}\"\n if !is_object(spec) or is_array(spec)\n throw \"Middleware requires a module and exported handler\"\n for spec as key: value\n if key != \"module\" and key != \"handler\" and key != \"validate\"\n throw \"Unknown middleware option: ${key}\"\n if !is_string(spec.handler) or spec.handler == \"\"\n throw \"Middleware handler is required\"\n if spec.validate != null and (!is_string(spec.validate) or spec.validate == \"\")\n throw \"Middleware validate must name an exported function\"\n @middlewares[name] = {\n module: resolveModule(spec.module, @root)\n handler: spec.handler\n validate: spec.validate\n }\n return @this\n\nRoutes:middlewares()\n return from_json(to_json(@middlewares))\n\nRoutes:longpoll(spec)\n item = longpollOptions(spec)\n checkPath(item.path)\n @items.add(item)\n return @this\n\nRoutes:event(spec)\n if !contains([\"register\", \"validate\", \"request\"], spec.name)\n throw \"Unknown event: ${spec.name}\"\n if spec.name in @events\n throw \"Duplicate event: ${spec.name}\"\n if !is_string(spec.handler) or spec.handler == \"\"\n throw \"Event handler is required\"\n @events[spec.name] = {\n module: resolveModule(spec.module, @root)\n handler: spec.handler\n }\n return @this\n\nRoutes:include(spec, auth = null, policy = null, reauthSeconds = null)\n includeAt(spec, @root, \"\", [], auth, policy, reauthSeconds)\n return @this\n\nRoutes:xml(file)\n readXml(path/resolve(file), \"\", @root, [], true)\n return @this\n\nRoutes:definitions()\n return from_json(to_json(@items))\n\nRoutes:events()\n return from_json(to_json(@events))\n\nresolveModule(name, directory)\n if !is_string(name) or name == \"\" or name.startsWith(\"node:\")\n throw \"Application module is required\"\n resolver = modules/createRequire(path/join(directory, \"package.json\"))\n resolved = resolver.resolve(name)\n if !path/isAbsolute(resolved)\n throw \"Application module must resolve to a file: ${name}\"\n return resolved\n\njoinPath(prefix, suffix)\n if !is_string(suffix) or !suffix.startsWith(\"/\")\n throw \"Route path must begin with /\"\n if prefix == \"\" or prefix == \"/\"\n return suffix\n if suffix == \"/\"\n return \"${prefix}/\"\n return \"${prefix}${suffix}\"\n\nRoutes:includeAt(spec, directory, prefix, stack, inheritedAuth = null, inheritedPolicy = null, inheritedReauthSeconds = null)\n if !is_string(spec.module) or spec.module == \"\" or spec.module.startsWith(\".\") or spec.module.startsWith(\"/\") or spec.module.startsWith(\"node:\")\n throw \"Include requires an npm package name\"\n mount = spec.path\n if mount == null\n mount = \"/\"\n if !is_string(mount)\n throw \"Include path must be a string\"\n if mount.includes(\"*\") or mount.includes(\"//\") or mount.includes(\"?\") or mount.includes(\"#\") or mount.includes(\"\\\\\")\n throw \"Invalid include prefix\"\n if mount.endsWith(\"/\") and mount != \"/\"\n mount = mount.slice(0, -1)\n combined = joinPath(prefix, mount)\n if combined == \"/\"\n combined = \"\"\n file = resolveModule(\"${spec.module}/routes.xml\", directory)\n readXml(file, combined, path/dirname(file), stack, false, inheritedAuth, inheritedPolicy, inheritedReauthSeconds)\n return null\n\nRoutes:readXml(file, prefix, directory, stack, allowEvents, inheritedAuth = null, inheritedPolicy = null, inheritedReauthSeconds = null)\n real = fs/realpathSync(file)\n if stack.includes(real)\n throw \"Route include cycle: ${real}\"\n root = xml2obj(fs/readFileSync(real, \"utf8\"))\n if root.tag() != \"routes\"\n throw \"Expected routes root: ${real}\"\n attributes(root, [])\n nextStack = stack.slice()\n nextStack.add(real)\n collect(root, prefix, null, inheritedAuth, directory, nextStack, allowEvents, inheritedPolicy, inheritedReauthSeconds)\n return null\n\nRoutes:collect(parent, prefix, inheritedModule, inheritedAuth, directory, stack, allowEvents, inheritedPolicy = null, inheritedReauthSeconds = null)\n if parent.innerText().trim() != \"\"\n throw \"Route XML cannot contain text\"\n for parent.children() as tag\n spec = tag.attributes()\n mod = spec.module\n auth = spec.auth\n policy = spec.policy\n reauthSeconds = spec.reauthSeconds\n if mod == null\n mod = inheritedModule\n if auth == null and policy == null\n auth = inheritedAuth\n policy = inheritedPolicy\n if reauthSeconds == null\n reauthSeconds = inheritedReauthSeconds\n switch tag.tag()\n case \"endpoint\"\n attributes(tag, [\"path\", \"module\", \"handler\", \"auth\", \"policy\", \"reauthSeconds\"])\n leaf(tag)\n endpoint({\n path: joinPath(prefix, spec.path)\n module: resolveModule(mod, directory)\n handler: spec.handler\n auth: auth\n policy: policy\n reauthSeconds: reauthSeconds\n })\n case \"longpoll\"\n attributes(tag, [\"path\", \"auth\", \"policy\", \"reauthSeconds\", \"waitTimeoutMs\", \"retentionMs\", \"maxMessages\", \"fallback\"])\n leaf(tag)\n spec.path = joinPath(prefix, spec.path)\n spec.auth = auth\n spec.policy = policy\n spec.reauthSeconds = reauthSeconds\n if spec.fallback != null\n spec.fallback = joinPath(prefix, spec.fallback)\n longpoll(spec)\n case \"group\"\n attributes(tag, [\"path\", \"module\", \"auth\", \"policy\", \"reauthSeconds\"])\n collect(tag, joinPath(prefix, spec.path), mod, auth, directory, stack, false, policy, reauthSeconds)\n case \"include\"\n attributes(tag, [\"module\", \"path\"])\n leaf(tag)\n includeAt(spec, directory, prefix, stack, auth, policy, reauthSeconds)\n case \"middleware\"\n attributes(tag, [\"name\", \"module\", \"handler\", \"validate\"])\n leaf(tag)\n if !allowEvents\n throw \"Middleware declarations are only allowed in the application's root routes.xml\"\n addMiddleware(spec.name, {\n module: resolveModule(spec.module, directory)\n handler: spec.handler\n validate: spec.validate\n })\n case \"event\"\n attributes(tag, [\"name\", \"module\", \"handler\"])\n leaf(tag)\n if !allowEvents\n throw \"Events are only allowed in the application's root routes.xml\"\n event({\n name: spec.name\n module: resolveModule(spec.module, directory)\n handler: spec.handler\n })\n else\n attributes(tag, [\"path\", \"module\", \"handler\", \"auth\", \"policy\", \"reauthSeconds\"])\n leaf(tag)\n endpoint({\n path: joinPath(prefix, spec.path)\n module: resolveModule(mod, directory)\n handler: spec.handler\n auth: auth\n policy: policy\n reauthSeconds: reauthSeconds\n middleware: tag.tag()\n })\n return null\n\nleaf(tag)\n if tag.children().length != 0 or tag.innerText().trim() != \"\"\n throw \"Expected an empty ${tag.tag()} element\"\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoGA;;;;;;;;;;;;;;;;AASA;;;;;;;;;;;;;;;;;AAwHA;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"routes.mjs","sources":["routes.lango"],"sourcesContent":["import \"./route_pattern\"\n routePattern(path)\nimport \"./options\"\n contains(items, value)\nimport js \"node:fs\" as fs\nimport js \"node:path\" as path\nimport js \"node:module\" as modules\nimport \"./options\"\n attributes(tag, allowed)\nimport js global Object\nimport \"./middleware\"\n middlewareName(name)\nimport \"./endpoint\"\n class Endpoint\n\nimport \"./longpoll_options\"\n longpollOptions(spec)\n\nexport class Routes(root)\n methods\n endpoint(spec)\n job(spec)\n jobs()\n addMiddleware(name, spec)\n middlewares()\n longpoll(spec)\n include(spec, auth = null, policy = null, reauthSeconds = null)\n xml(file)\n definitions()\n events()\n event(spec)\n\nRoutes(root)\n @root = path/resolve(root)\n @items = []\n @jobs = []\n @events = {}\n @middlewares = Object/create(null)\n\nRoutes:endpoint(spec)\n item = new Endpoint(spec)\n checkPath(item.path)\n @items.add({\n path: item.path\n module: resolveModule(item.module, @root)\n handler: item.handler\n auth: item.auth\n policy: item.policy\n reauthSeconds: item.reauthSeconds\n reauthExplicit: item.reauthExplicit\n legacyAuth: item.legacyAuth\n middleware: item.middleware\n })\n return @this\n\nRoutes:checkPath(path)\n pattern = routePattern(path)\n for @items as other\n if other.path == path\n throw \"Duplicate endpoint: ${path}\"\n existing = routePattern(other.path)\n if existing.key == pattern.key\n throw \"Conflicting endpoint pattern: ${path}\"\n return null\n\nRoutes:job(spec)\n allowed = [\"path\", \"module\", \"handler\", \"queue\", \"policy\", \"auth\", \"reauthSeconds\"]\n for spec as key: value\n if !allowed.includes(key)\n throw \"Unknown job route option: ${key}\"\n item = new Endpoint(spec)\n if item.path.includes(\"*\") or item.path.includes(\"{\") or item.path.includes(\"}\")\n throw \"Job routes require an exact path\"\n if !is_string(spec.queue) or spec.queue.trim() != spec.queue or spec.queue == \"\"\n throw \"Job route requires a queue name\"\n for @jobs as other\n if other.path == item.path\n throw \"Duplicate job route: ${item.path}\"\n @jobs.add({\n path: item.path\n module: resolveModule(item.module, @root)\n handler: item.handler\n queue: spec.queue\n policy: item.policy\n auth: item.auth\n reauthSeconds: item.reauthSeconds\n reauthExplicit: item.reauthExplicit\n legacyAuth: item.legacyAuth\n })\n return @this\n\nRoutes:jobs()\n return from_json(to_json(@jobs))\n\nRoutes:addMiddleware(name, spec)\n middlewareName(name)\n if Object/hasOwn(@middlewares, name)\n throw \"Duplicate middleware: ${name}\"\n if !is_object(spec) or is_array(spec)\n throw \"Middleware requires a module and exported handler\"\n for spec as key: value\n if key != \"module\" and key != \"handler\" and key != \"validate\"\n throw \"Unknown middleware option: ${key}\"\n if !is_string(spec.handler) or spec.handler == \"\"\n throw \"Middleware handler is required\"\n if spec.validate != null and (!is_string(spec.validate) or spec.validate == \"\")\n throw \"Middleware validate must name an exported function\"\n @middlewares[name] = {\n module: resolveModule(spec.module, @root)\n handler: spec.handler\n validate: spec.validate\n }\n return @this\n\nRoutes:middlewares()\n return from_json(to_json(@middlewares))\n\nRoutes:longpoll(spec)\n item = longpollOptions(spec)\n checkPath(item.path)\n @items.add(item)\n return @this\n\nRoutes:event(spec)\n if !contains([\"register\", \"validate\", \"request\"], spec.name)\n throw \"Unknown event: ${spec.name}\"\n if spec.name in @events\n throw \"Duplicate event: ${spec.name}\"\n if !is_string(spec.handler) or spec.handler == \"\"\n throw \"Event handler is required\"\n @events[spec.name] = {\n module: resolveModule(spec.module, @root)\n handler: spec.handler\n }\n return @this\n\nRoutes:include(spec, auth = null, policy = null, reauthSeconds = null)\n includeAt(spec, @root, \"\", [], auth, policy, reauthSeconds)\n return @this\n\nRoutes:xml(file)\n readXml(path/resolve(file), \"\", @root, [], true)\n return @this\n\nRoutes:definitions()\n return from_json(to_json(@items))\n\nRoutes:events()\n return from_json(to_json(@events))\n\nresolveModule(name, directory)\n if !is_string(name) or name == \"\" or name.startsWith(\"node:\")\n throw \"Application module is required\"\n resolver = modules/createRequire(path/join(directory, \"package.json\"))\n resolved = resolver.resolve(name)\n if !path/isAbsolute(resolved)\n throw \"Application module must resolve to a file: ${name}\"\n return resolved\n\njoinPath(prefix, suffix)\n if !is_string(suffix) or !suffix.startsWith(\"/\")\n throw \"Route path must begin with /\"\n if prefix == \"\" or prefix == \"/\"\n return suffix\n if suffix == \"/\"\n return \"${prefix}/\"\n return \"${prefix}${suffix}\"\n\nRoutes:includeAt(spec, directory, prefix, stack, inheritedAuth = null, inheritedPolicy = null, inheritedReauthSeconds = null)\n if !is_string(spec.module) or spec.module == \"\" or spec.module.startsWith(\".\") or spec.module.startsWith(\"/\") or spec.module.startsWith(\"node:\")\n throw \"Include requires an npm package name\"\n mount = spec.path\n if mount == null\n mount = \"/\"\n if !is_string(mount)\n throw \"Include path must be a string\"\n if mount.includes(\"*\") or mount.includes(\"//\") or mount.includes(\"?\") or mount.includes(\"#\") or mount.includes(\"\\\\\")\n throw \"Invalid include prefix\"\n if mount.endsWith(\"/\") and mount != \"/\"\n mount = mount.slice(0, -1)\n combined = joinPath(prefix, mount)\n if combined == \"/\"\n combined = \"\"\n file = resolveModule(\"${spec.module}/routes.xml\", directory)\n readXml(file, combined, path/dirname(file), stack, false, inheritedAuth, inheritedPolicy, inheritedReauthSeconds)\n return null\n\nRoutes:readXml(file, prefix, directory, stack, allowEvents, inheritedAuth = null, inheritedPolicy = null, inheritedReauthSeconds = null)\n real = fs/realpathSync(file)\n if stack.includes(real)\n throw \"Route include cycle: ${real}\"\n root = xml2obj(fs/readFileSync(real, \"utf8\"))\n if root.tag() != \"routes\"\n throw \"Expected routes root: ${real}\"\n attributes(root, [])\n nextStack = stack.slice()\n nextStack.add(real)\n collect(root, prefix, null, inheritedAuth, directory, nextStack, allowEvents, inheritedPolicy, inheritedReauthSeconds)\n return null\n\nRoutes:collect(parent, prefix, inheritedModule, inheritedAuth, directory, stack, allowEvents, inheritedPolicy = null, inheritedReauthSeconds = null)\n if parent.innerText().trim() != \"\"\n throw \"Route XML cannot contain text\"\n for parent.children() as tag\n spec = tag.attributes()\n mod = spec.module\n auth = spec.auth\n policy = spec.policy\n reauthSeconds = spec.reauthSeconds\n if mod == null\n mod = inheritedModule\n if auth == null and policy == null\n auth = inheritedAuth\n policy = inheritedPolicy\n if reauthSeconds == null\n reauthSeconds = inheritedReauthSeconds\n switch tag.tag()\n case \"job\"\n attributes(tag, [\"path\", \"module\", \"handler\", \"queue\", \"auth\", \"policy\", \"reauthSeconds\"])\n leaf(tag)\n job({\n path: joinPath(prefix, spec.path)\n module: resolveModule(mod, directory)\n handler: spec.handler\n queue: spec.queue\n auth: auth\n policy: policy\n reauthSeconds: reauthSeconds\n })\n case \"endpoint\"\n attributes(tag, [\"path\", \"module\", \"handler\", \"auth\", \"policy\", \"reauthSeconds\"])\n leaf(tag)\n endpoint({\n path: joinPath(prefix, spec.path)\n module: resolveModule(mod, directory)\n handler: spec.handler\n auth: auth\n policy: policy\n reauthSeconds: reauthSeconds\n })\n case \"longpoll\"\n attributes(tag, [\"path\", \"auth\", \"policy\", \"reauthSeconds\", \"waitTimeoutMs\", \"retentionMs\", \"maxMessages\", \"fallback\"])\n leaf(tag)\n spec.path = joinPath(prefix, spec.path)\n spec.auth = auth\n spec.policy = policy\n spec.reauthSeconds = reauthSeconds\n if spec.fallback != null\n spec.fallback = joinPath(prefix, spec.fallback)\n longpoll(spec)\n case \"group\"\n attributes(tag, [\"path\", \"module\", \"auth\", \"policy\", \"reauthSeconds\"])\n collect(tag, joinPath(prefix, spec.path), mod, auth, directory, stack, false, policy, reauthSeconds)\n case \"include\"\n attributes(tag, [\"module\", \"path\"])\n leaf(tag)\n includeAt(spec, directory, prefix, stack, auth, policy, reauthSeconds)\n case \"middleware\"\n attributes(tag, [\"name\", \"module\", \"handler\", \"validate\"])\n leaf(tag)\n if !allowEvents\n throw \"Middleware declarations are only allowed in the application's root routes.xml\"\n addMiddleware(spec.name, {\n module: resolveModule(spec.module, directory)\n handler: spec.handler\n validate: spec.validate\n })\n case \"event\"\n attributes(tag, [\"name\", \"module\", \"handler\"])\n leaf(tag)\n if !allowEvents\n throw \"Events are only allowed in the application's root routes.xml\"\n event({\n name: spec.name\n module: resolveModule(spec.module, directory)\n handler: spec.handler\n })\n else\n attributes(tag, [\"path\", \"module\", \"handler\", \"auth\", \"policy\", \"reauthSeconds\"])\n leaf(tag)\n endpoint({\n path: joinPath(prefix, spec.path)\n module: resolveModule(mod, directory)\n handler: spec.handler\n auth: auth\n policy: policy\n reauthSeconds: reauthSeconds\n middleware: tag.tag()\n })\n return null\n\nleaf(tag)\n if tag.children().length != 0 or tag.innerText().trim() != \"\"\n throw \"Expected an empty ${tag.tag()} element\"\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoIA;;;;;;;;;;;;;;;;AASA;;;;;;;;;;;;;;;;;AAoIA;;;;;;;;;;","x_lango_build":{"fingerprint":"ebd91827536b531bc59778347087e4a23854cea16863740a9d40b80e8a34b1dc","outputHash":"c651315b01b7dcbcafa78ecacf7221a3dbe99ee942cf3935677497ef06c561a0","mapHash":"7445f646e4e9daa829b9e3ade7c89f0dfaaf5da5ffc1bdacc4d7912a4319db66"}}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ModuleLoader } from "./module_loader.mjs";
|
|
1
2
|
import { routeInfo } from "./route_info.mjs";
|
|
2
3
|
import { ClientIdentity } from "./client_identity.mjs";
|
|
3
4
|
import { originAllowed } from "./origin.mjs";
|
|
@@ -47,7 +48,8 @@ export class Runtime {
|
|
|
47
48
|
#routes;
|
|
48
49
|
#events;
|
|
49
50
|
#tokens;
|
|
50
|
-
#
|
|
51
|
+
#loader;
|
|
52
|
+
#queueFactory;
|
|
51
53
|
#middlewares;
|
|
52
54
|
#database;
|
|
53
55
|
#clients;
|
|
@@ -68,7 +70,8 @@ export class Runtime {
|
|
|
68
70
|
this.#routes = [];
|
|
69
71
|
this.#events = { };
|
|
70
72
|
this.#tokens = new Tokens(__normalize(definition.settings));
|
|
71
|
-
this.#
|
|
73
|
+
this.#loader = new ModuleLoader();
|
|
74
|
+
this.#queueFactory = null;
|
|
72
75
|
this.#middlewares = __normalize(__hostGlobal(["Object"]).create(null));
|
|
73
76
|
this.#database = new Database(definition.settings.database, definition.settings.root);
|
|
74
77
|
this.#clients = null;
|
|
@@ -80,6 +83,9 @@ export class Runtime {
|
|
|
80
83
|
trace(`Worker ${__normalize(threads.threadId)}: preparing database, middleware, routes and events`);
|
|
81
84
|
let definitions = __normalize(this.#definition.routes);
|
|
82
85
|
let pending = __normalize(this.#database.open());
|
|
86
|
+
if (__requireBoolean(__normalize(this.#definition.queueProvider) !== null)) {
|
|
87
|
+
pending = this.#prepareQueue(pending);
|
|
88
|
+
}
|
|
83
89
|
if (__requireBoolean(__normalize(this.#definition.middlewares) !== null)) {
|
|
84
90
|
for (const [name, spec] of __entries(__normalize(this.#definition.middlewares))) {
|
|
85
91
|
pending = this.#prepareMiddleware(pending, name, spec);
|
|
@@ -105,6 +111,29 @@ export class Runtime {
|
|
|
105
111
|
return null;
|
|
106
112
|
return null;
|
|
107
113
|
}
|
|
114
|
+
#prepareQueue(pending) {
|
|
115
|
+
__requireArity(arguments.length, [0], "prepareQueue");
|
|
116
|
+
pending = __boundary(pending);
|
|
117
|
+
return pending.then(__withArity(__bindContexts((ignored) => {
|
|
118
|
+
ignored = __boundary(ignored);
|
|
119
|
+
return __normalize(this.#loader.target(__normalize(this.#definition.queueProvider)));
|
|
120
|
+
return null;
|
|
121
|
+
}), [0], "closure")).then(__withArity(__bindContexts((factory) => {
|
|
122
|
+
factory = __boundary(factory);
|
|
123
|
+
this.#queueFactory = factory;
|
|
124
|
+
return null;
|
|
125
|
+
return null;
|
|
126
|
+
}), [0], "closure"));
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
#queueSender() {
|
|
130
|
+
if (__requireBoolean(__normalize(this.#queueFactory) === null)) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
let factory = __normalize(this.#queueFactory);
|
|
134
|
+
return __call(factory, __normalize(this.#definition.queueProvider.options));
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
108
137
|
#prepareMiddleware(pending, name, spec) {
|
|
109
138
|
__requireArity(arguments.length, [0, 1, 2], "prepareMiddleware");
|
|
110
139
|
pending = __boundary(pending);
|
|
@@ -184,15 +213,7 @@ export class Runtime {
|
|
|
184
213
|
spec = __boundary(spec);
|
|
185
214
|
let file = __normalize(spec.module);
|
|
186
215
|
trace(`Worker ${__normalize(threads.threadId)}: resolving ${file} export ${__normalize(spec.handler)}`);
|
|
187
|
-
|
|
188
|
-
return __normalize(__hostGlobal(["Promise"]).resolve(exported(__normalize(this.#modules[file]), __normalize(spec.handler))));
|
|
189
|
-
}
|
|
190
|
-
return import(file).then(__withArity(__bindContexts((mod) => {
|
|
191
|
-
mod = __boundary(mod);
|
|
192
|
-
this.#modules[file] = mod;
|
|
193
|
-
return exported(mod, __normalize(spec.handler));
|
|
194
|
-
return null;
|
|
195
|
-
}), [0], "closure"));
|
|
216
|
+
return __normalize(this.#loader.target(spec));
|
|
196
217
|
return null;
|
|
197
218
|
}
|
|
198
219
|
#match(path) {
|
|
@@ -330,6 +351,16 @@ export class Runtime {
|
|
|
330
351
|
fresh = __boundary(fresh);
|
|
331
352
|
restored = __boundary(restored);
|
|
332
353
|
__contextScope.push(__contextSet("token", new Token(claims)));
|
|
354
|
+
let sender = null;
|
|
355
|
+
try {
|
|
356
|
+
sender = this.#queueSender();
|
|
357
|
+
} catch (error) {
|
|
358
|
+
closeScope(__contextGet("db"), false);
|
|
359
|
+
closeClientScope();
|
|
360
|
+
__normalize(__contextGet("log").err(`${requestIdentity(__normalize(__contextGet("request").id), __contextGet("token"))} Queue preparation failed: ${errorDetails(error)}`));
|
|
361
|
+
return failure(500, "InternalServerError");
|
|
362
|
+
}
|
|
363
|
+
__contextScope.push(__contextSet("queue", sender));
|
|
333
364
|
trace(`${requestIdentity(__normalize(__contextGet("request").id), __contextGet("token"))} Matched route ${__normalize(route.path)}; fresh=${fresh}`);
|
|
334
365
|
return __normalize(__hostGlobal(["Promise"]).resolve(null)).then(__withArity(__bindContexts((ignored) => {
|
|
335
366
|
const __contextScope = [];
|
|
@@ -456,9 +487,7 @@ export class Runtime {
|
|
|
456
487
|
}), [0], "closure")).finally(__bindContexts(() => {
|
|
457
488
|
const __contextScope = [];
|
|
458
489
|
try {
|
|
459
|
-
|
|
460
|
-
__contextGet("clientIdentity").closed = true;
|
|
461
|
-
}
|
|
490
|
+
closeClientScope();
|
|
462
491
|
closeScope(__contextGet("db"), false);
|
|
463
492
|
return null;
|
|
464
493
|
} finally {
|
|
@@ -650,6 +679,15 @@ export class Runtime {
|
|
|
650
679
|
__contextScope.push(__contextSet("db", __normalize(this.#database.scope())));
|
|
651
680
|
__contextScope.push(__contextSet("token", new Token(claims, true)));
|
|
652
681
|
__contextScope.push(__contextSet("response", __normalize(__hostGlobal(["Object"]).freeze({ }))));
|
|
682
|
+
let sender = null;
|
|
683
|
+
try {
|
|
684
|
+
sender = this.#queueSender();
|
|
685
|
+
} catch (error) {
|
|
686
|
+
closeScope(__contextGet("db"), false);
|
|
687
|
+
__normalize(__contextGet("log").err(`${requestIdentity(id, __contextGet("token"))} Request event queue preparation failed: ${errorDetails(error)}`));
|
|
688
|
+
return result;
|
|
689
|
+
}
|
|
690
|
+
__contextScope.push(__contextSet("queue", sender));
|
|
653
691
|
let metadata = { input: input, output: output, status: __normalize(result.status) };
|
|
654
692
|
__normalize(threads.parentPort.postMessage({ kind: "prepared", logIdentity: requestIdentity(id, __contextGet("token")), id: id, result: result }));
|
|
655
693
|
return __normalize(__hostGlobal(["Promise"]).resolve(null)).then(__withArity(__bindContexts((ignored) => {
|
|
@@ -706,17 +744,6 @@ export class Runtime {
|
|
|
706
744
|
}
|
|
707
745
|
}
|
|
708
746
|
}
|
|
709
|
-
function exported(mod, name) {
|
|
710
|
-
__requireArity(arguments.length, [0, 1], "exported");
|
|
711
|
-
mod = __boundary(mod);
|
|
712
|
-
name = __boundary(name);
|
|
713
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(mod, name)))) || __requireBoolean(!__requireBoolean(__isKindof(__normalize(mod[name]), Function))))) {
|
|
714
|
-
throw `Handler is not exported: ${name}`;
|
|
715
|
-
}
|
|
716
|
-
return __normalize(mod[name]);
|
|
717
|
-
return null;
|
|
718
|
-
}
|
|
719
|
-
|
|
720
747
|
function failure(status, code) {
|
|
721
748
|
__requireArity(arguments.length, [0, 1], "failure");
|
|
722
749
|
status = __boundary(status);
|
|
@@ -753,6 +780,19 @@ function closeScope(db, strict) {
|
|
|
753
780
|
return null;
|
|
754
781
|
}
|
|
755
782
|
|
|
783
|
+
function closeClientScope() {
|
|
784
|
+
const __contextScope = [];
|
|
785
|
+
try {
|
|
786
|
+
if (__requireBoolean(__contextGet("clientIdentity") !== null)) {
|
|
787
|
+
__contextGet("clientIdentity").closed = true;
|
|
788
|
+
}
|
|
789
|
+
return null;
|
|
790
|
+
return null;
|
|
791
|
+
} finally {
|
|
792
|
+
__contextRestore(__contextScope);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
756
796
|
function needLogin(route, status, reason) {
|
|
757
797
|
const __contextScope = [];
|
|
758
798
|
try {
|