@lango-project/lango-server 0.2.2 → 0.2.4
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 +252 -29
- package/dist/.lango/runtime.mjs +16 -0
- package/dist/body_reader.mjs +15 -14
- package/dist/body_reader.mjs.map +1 -1
- package/dist/builder.mjs +26 -2
- package/dist/builder.mjs.map +1 -1
- package/dist/cli/.lango/runtime.mjs +16 -0
- package/dist/cli/body_reader.mjs +15 -14
- package/dist/cli/body_reader.mjs.map +1 -1
- package/dist/cli/client_identity.mjs +250 -0
- package/dist/cli/client_identity.mjs.map +1 -0
- package/dist/cli/database.mjs +23 -8
- package/dist/cli/database.mjs.map +1 -1
- package/dist/cli/database_scope.mjs +11 -0
- package/dist/cli/database_scope.mjs.map +1 -1
- package/dist/cli/endpoint.mjs +11 -7
- package/dist/cli/endpoint.mjs.map +1 -1
- package/dist/cli/longpoll_broker.mjs +9 -8
- package/dist/cli/longpoll_broker.mjs.map +1 -1
- package/dist/cli/longpoll_options.mjs +8 -7
- package/dist/cli/longpoll_options.mjs.map +1 -1
- package/dist/cli/longpoll_session.mjs +11 -10
- package/dist/cli/longpoll_session.mjs.map +1 -1
- package/dist/cli/middleware.mjs +1 -1
- package/dist/cli/middleware.mjs.map +1 -1
- package/dist/cli/options.mjs +41 -4
- package/dist/cli/options.mjs.map +1 -1
- package/dist/cli/origin.mjs +87 -0
- package/dist/cli/origin.mjs.map +1 -0
- package/dist/cli/policy.mjs +121 -0
- package/dist/cli/policy.mjs.map +1 -0
- package/dist/cli/postgres_adapter.mjs +15 -3
- package/dist/cli/postgres_adapter.mjs.map +1 -1
- package/dist/cli/routes.mjs +69 -18
- package/dist/cli/routes.mjs.map +1 -1
- package/dist/cli/server.mjs +88 -81
- package/dist/cli/server.mjs.map +1 -1
- package/dist/cli/static_files.mjs +5 -4
- package/dist/cli/static_files.mjs.map +1 -1
- package/dist/client_identity.mjs +250 -0
- package/dist/client_identity.mjs.map +1 -0
- package/dist/database.mjs +23 -8
- 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_scope.mjs +11 -0
- package/dist/database_scope.mjs.map +1 -1
- package/dist/endpoint.mjs +11 -7
- package/dist/endpoint.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 +49 -16
- package/dist/group.mjs.map +1 -1
- package/dist/http_failure.mjs +9 -2
- 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 +9 -8
- package/dist/longpoll_broker.mjs.map +1 -1
- package/dist/longpoll_options.mjs +8 -7
- package/dist/longpoll_options.mjs.map +1 -1
- package/dist/longpoll_session.mjs +11 -10
- 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 +41 -4
- package/dist/options.mjs.map +1 -1
- package/dist/origin.mjs +87 -0
- package/dist/origin.mjs.map +1 -0
- package/dist/policy.mjs +121 -0
- package/dist/policy.mjs.map +1 -0
- package/dist/postgres_adapter.mjs +15 -3
- package/dist/postgres_adapter.mjs.map +1 -1
- package/dist/postgres_worker.mjs +82 -19
- 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/response.mjs +1 -1
- package/dist/response.mjs.map +1 -1
- package/dist/route_info.mjs +1 -1
- package/dist/route_info.mjs.map +1 -1
- package/dist/routes.mjs +69 -18
- package/dist/routes.mjs.map +1 -1
- package/dist/runtime.mjs +287 -132
- package/dist/runtime.mjs.map +1 -1
- package/dist/server.mjs +88 -81
- package/dist/server.mjs.map +1 -1
- package/dist/server_context.mjs +21 -9
- package/dist/server_context.mjs.map +1 -1
- package/dist/static_files.mjs +5 -4
- package/dist/static_files.mjs.map +1 -1
- package/dist/token.mjs +34 -7
- package/dist/token.mjs.map +1 -1
- package/dist/tokens.mjs +11 -2
- package/dist/tokens.mjs.map +1 -1
- package/dist/worker.mjs +7 -6
- package/dist/worker.mjs.map +1 -1
- package/docs/jobs.md +123 -0
- package/docs/security.md +420 -0
- package/examples/security/README.md +160 -0
- package/examples/security/deploy.xml +12 -0
- package/examples/security/handlers.lango +610 -0
- package/examples/security/package.json +19 -0
- package/examples/security/passwords.lango +61 -0
- package/examples/security/routes.xml +14 -0
- package/examples/security/schema.lango +91 -0
- package/examples/security/setup.lango +30 -0
- package/package.json +14 -6
- package/src/builder.lango +22 -0
- package/src/client_identity.lango +184 -0
- package/src/database.lango +15 -4
- package/src/database_action.lango +30 -0
- package/src/database_scope.lango +7 -0
- package/src/endpoint.lango +12 -5
- 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 +36 -21
- package/src/http_failure.lango +9 -5
- package/src/job_configuration.lango +29 -0
- package/src/job_context.lango +44 -0
- package/src/library.lango +21 -0
- package/src/longpoll_options.lango +11 -5
- package/src/middleware.lango +1 -1
- package/src/module_loader.lango +25 -0
- package/src/options.lango +41 -2
- package/src/origin.lango +56 -0
- package/src/policy.lango +84 -0
- package/src/postgres_adapter.lango +12 -0
- package/src/postgres_worker.lango +54 -3
- package/src/queue_provider.lango +30 -0
- package/src/response.lango +1 -1
- package/src/route_info.lango +2 -0
- package/src/routes.lango +74 -15
- package/src/runtime.lango +173 -94
- package/src/server.lango +9 -2
- package/src/server_context.lango +10 -2
- package/src/token.lango +26 -5
- package/src/tokens.lango +10 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"origin.mjs","sources":["origin.lango"],"sourcesContent":["import js global Object\nimport js global URL\nimport js global process\n\nexport originOptions(spec)\nexport originAllowed(spec, request)\n\noriginOptions(spec)\n if spec == null\n return null\n if !is_object(spec) or is_array(spec)\n throw \"Origin configuration must be an object\"\n for Object/keys(spec) as name\n if name != \"url\" and name != \"urlEnv\" and name != \"required\"\n throw \"Unknown origin option: ${name}\"\n if spec.url != null and spec.urlEnv != null\n throw \"Origin requires either url or urlEnv, not both\"\n url = spec.url\n if spec.urlEnv != null\n if !is_string(spec.urlEnv) or spec.urlEnv == \"\"\n throw \"Origin urlEnv must name an environment variable\"\n envName = spec.urlEnv\n url = process.env[envName]\n if !is_string(url) or url == \"\"\n throw \"Origin URL is required\"\n parsed = null\n try\n parsed = new URL(url)\n catch error\n throw \"Origin requires an exact HTTP or HTTPS origin\"\n if (parsed.protocol != \"https:\" and parsed.protocol != \"http:\") or parsed.origin != url\n throw \"Origin requires an exact HTTP or HTTPS origin without credentials, path, query or fragment\"\n required = spec.required\n if required == null or required == \"true\"\n required = true\n if required == \"false\"\n required = false\n if !is_bool(required)\n throw \"Origin required must be true or false\"\n return {\n url: url\n required: required\n }\n\noriginAllowed(spec, request)\n if spec == null\n return true\n headers = request.headers\n value = headers.origin\n if value == null\n if spec.required\n return false\n if value != null and value != spec.url\n return false\n site = headers[\"sec-fetch-site\"]\n return site == null or site == \"same-origin\" or site == \"none\"\n"],"names":[],"mappings":";;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/policy.mjs
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hostGlobal as __hostGlobal,
|
|
3
|
+
hostGlobalCall as __hostGlobalCall,
|
|
4
|
+
isNumber as __isNumber,
|
|
5
|
+
isString as __isString,
|
|
6
|
+
isBool as __isBool,
|
|
7
|
+
isObject as __isObject,
|
|
8
|
+
isArray as __isArray,
|
|
9
|
+
entries as __entries,
|
|
10
|
+
requireBoolean as __requireBoolean,
|
|
11
|
+
normalize as __normalize,
|
|
12
|
+
boundary as __boundary,
|
|
13
|
+
requireArity as __requireArity,
|
|
14
|
+
} from "./.lango/runtime.mjs";
|
|
15
|
+
|
|
16
|
+
export function policyOptions(spec) {
|
|
17
|
+
__requireArity(arguments.length, [0], "policyOptions");
|
|
18
|
+
spec = __boundary(spec);
|
|
19
|
+
let name = __normalize(spec.policy);
|
|
20
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(name !== null) && __requireBoolean(__normalize(spec.auth) !== null)) && __requireBoolean(name !== __normalize(spec.auth)))) {
|
|
21
|
+
throw "Endpoint policy and legacy auth cannot disagree";
|
|
22
|
+
}
|
|
23
|
+
let legacy = name === null;
|
|
24
|
+
if (__requireBoolean(name === null)) {
|
|
25
|
+
name = __normalize(spec.auth);
|
|
26
|
+
}
|
|
27
|
+
if (__requireBoolean(name === null)) {
|
|
28
|
+
name = "login";
|
|
29
|
+
}
|
|
30
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(name))) || __requireBoolean(__normalize(name.trim()) === "")) || __requireBoolean(__normalize(name.includes(","))))) {
|
|
31
|
+
throw "Endpoint policy must name one permission";
|
|
32
|
+
}
|
|
33
|
+
let seconds = __normalize(spec.reauthSeconds);
|
|
34
|
+
if (__requireBoolean(seconds === null)) {
|
|
35
|
+
seconds = 0;
|
|
36
|
+
}
|
|
37
|
+
if (__requireBoolean(__isString(seconds))) {
|
|
38
|
+
if (__requireBoolean(__normalize(seconds.trim()) === "")) {
|
|
39
|
+
throw "reauthSeconds cannot be empty";
|
|
40
|
+
}
|
|
41
|
+
seconds = __hostGlobalCall(["Number"], seconds);
|
|
42
|
+
}
|
|
43
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isSafeInteger(seconds)))) || __requireBoolean(seconds < 0)) || __requireBoolean(seconds > 31536000))) {
|
|
44
|
+
throw "reauthSeconds must be an integer between 0 and 31536000";
|
|
45
|
+
}
|
|
46
|
+
if (__requireBoolean(__requireBoolean(seconds > 0) && __requireBoolean(name === "anonymous"))) {
|
|
47
|
+
throw "Anonymous policy cannot require password freshness";
|
|
48
|
+
}
|
|
49
|
+
return { name: name, reauthSeconds: seconds, explicit: __normalize(spec.reauthSeconds) !== null, legacy: legacy };
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function policyRegistry(spec) {
|
|
54
|
+
__requireArity(arguments.length, [0], "policyRegistry");
|
|
55
|
+
spec = __boundary(spec);
|
|
56
|
+
if (__requireBoolean(spec === null)) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(spec))) || __requireBoolean(__isArray(spec)))) {
|
|
60
|
+
throw "Policies must be a map";
|
|
61
|
+
}
|
|
62
|
+
for (const [key, value] of __entries(spec)) {
|
|
63
|
+
if (__requireBoolean(__requireBoolean(key !== "reauthSeconds") && __requireBoolean(key !== "items"))) {
|
|
64
|
+
throw `Unknown policies option: ${key}`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
let base = policyOptions({ policy: "login", reauthSeconds: __normalize(spec.reauthSeconds) });
|
|
68
|
+
let items = __normalize(spec.items);
|
|
69
|
+
if (__requireBoolean(!__requireBoolean(__isArray(items)))) {
|
|
70
|
+
throw "Policies require an items array";
|
|
71
|
+
}
|
|
72
|
+
let result = __normalize(__hostGlobal(["Object"]).create(null));
|
|
73
|
+
for (const item of items) {
|
|
74
|
+
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(item))) || __requireBoolean(__isArray(item)))) {
|
|
75
|
+
throw "Policy must be a map";
|
|
76
|
+
}
|
|
77
|
+
for (const [key, value] of __entries(item)) {
|
|
78
|
+
if (__requireBoolean(__requireBoolean(key !== "name") && __requireBoolean(key !== "reauthSeconds"))) {
|
|
79
|
+
throw `Unknown policy option: ${key}`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
let name = __normalize(item.name);
|
|
83
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(name))) || __requireBoolean(__normalize(name.trim()) !== name)) || __requireBoolean(name === "")) || __requireBoolean(name === "anonymous")) || __requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(result, name))))) {
|
|
84
|
+
throw "Invalid or duplicate policy name";
|
|
85
|
+
}
|
|
86
|
+
let seconds = __normalize(item.reauthSeconds);
|
|
87
|
+
if (__requireBoolean(seconds === null)) {
|
|
88
|
+
seconds = __normalize(base.reauthSeconds);
|
|
89
|
+
}
|
|
90
|
+
let selected = policyOptions({ policy: name, reauthSeconds: seconds });
|
|
91
|
+
result[name] = __normalize(selected.reauthSeconds);
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function resolvePolicies(routes, registry) {
|
|
98
|
+
__requireArity(arguments.length, [0, 1], "resolvePolicies");
|
|
99
|
+
routes = __boundary(routes);
|
|
100
|
+
registry = __boundary(registry);
|
|
101
|
+
if (__requireBoolean(registry === null)) {
|
|
102
|
+
return routes;
|
|
103
|
+
}
|
|
104
|
+
for (const route of routes) {
|
|
105
|
+
if (__requireBoolean(__normalize(route.policy) !== "anonymous")) {
|
|
106
|
+
if (__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(registry, __normalize(route.policy)))))) {
|
|
107
|
+
throw `Undefined route policy: ${__normalize(route.policy)}`;
|
|
108
|
+
}
|
|
109
|
+
let maximum = __normalize(registry[__normalize(route.policy)]);
|
|
110
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(route.reauthExplicit)) && __requireBoolean(maximum > 0)) && __requireBoolean(__requireBoolean(__normalize(route.reauthSeconds) === 0) || __requireBoolean(__normalize(route.reauthSeconds) > maximum)))) {
|
|
111
|
+
throw `Route cannot weaken policy freshness: ${__normalize(route.path)}`;
|
|
112
|
+
}
|
|
113
|
+
if (__requireBoolean(!__requireBoolean(__normalize(route.reauthExplicit)))) {
|
|
114
|
+
route.reauthSeconds = maximum;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return routes;
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=policy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.mjs","sources":["policy.lango"],"sourcesContent":["import js global Number\nimport js global Object\n\nexport policyOptions(spec)\nexport policyRegistry(spec)\nexport resolvePolicies(routes, registry)\n\npolicyOptions(spec)\n name = spec.policy\n if name != null and spec.auth != null and name != spec.auth\n throw \"Endpoint policy and legacy auth cannot disagree\"\n legacy = name == null\n if name == null\n name = spec.auth\n if name == null\n name = \"login\"\n if !is_string(name) or name.trim() == \"\" or name.includes(\",\")\n throw \"Endpoint policy must name one permission\"\n seconds = spec.reauthSeconds\n if seconds == null\n seconds = 0\n if is_string(seconds)\n if seconds.trim() == \"\"\n throw \"reauthSeconds cannot be empty\"\n seconds = Number(seconds)\n if !Number/isSafeInteger(seconds) or seconds < 0 or seconds > 31536000\n throw \"reauthSeconds must be an integer between 0 and 31536000\"\n if seconds > 0 and name == \"anonymous\"\n throw \"Anonymous policy cannot require password freshness\"\n return {\n name: name\n reauthSeconds: seconds\n explicit: spec.reauthSeconds != null\n legacy: legacy\n }\n\npolicyRegistry(spec)\n if spec == null\n return null\n if !is_object(spec) or is_array(spec)\n throw \"Policies must be a map\"\n for spec as key: value\n if key != \"reauthSeconds\" and key != \"items\"\n throw \"Unknown policies option: ${key}\"\n base = policyOptions({\n policy: \"login\"\n reauthSeconds: spec.reauthSeconds\n })\n items = spec.items\n if !is_array(items)\n throw \"Policies require an items array\"\n result = Object/create(null)\n for items as item\n if !is_object(item) or is_array(item)\n throw \"Policy must be a map\"\n for item as key: value\n if key != \"name\" and key != \"reauthSeconds\"\n throw \"Unknown policy option: ${key}\"\n name = item.name\n if !is_string(name) or name.trim() != name or name == \"\" or name == \"anonymous\" or Object/hasOwn(result, name)\n throw \"Invalid or duplicate policy name\"\n seconds = item.reauthSeconds\n if seconds == null\n seconds = base.reauthSeconds\n selected = policyOptions({\n policy: name\n reauthSeconds: seconds\n })\n result[name] = selected.reauthSeconds\n return result\n\nresolvePolicies(routes, registry)\n if registry == null\n return routes\n for routes as route\n if route.policy != \"anonymous\"\n if !Object/hasOwn(registry, route.policy)\n throw \"Undefined route policy: ${route.policy}\"\n maximum = registry[route.policy]\n if route.reauthExplicit and maximum > 0 and (route.reauthSeconds == 0 or route.reauthSeconds > maximum)\n throw \"Route cannot weaken policy freshness: ${route.path}\"\n if !route.reauthExplicit\n route.reauthSeconds = maximum\n return routes\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -3,6 +3,7 @@ import * as path from "node:path";
|
|
|
3
3
|
import * as threads from "node:worker_threads";
|
|
4
4
|
import {
|
|
5
5
|
hostGlobal as __hostGlobal,
|
|
6
|
+
bindContexts as __bindContexts,
|
|
6
7
|
requireBoolean as __requireBoolean,
|
|
7
8
|
normalize as __normalize,
|
|
8
9
|
finite as __finite,
|
|
@@ -41,13 +42,13 @@ export class PostgresAdapter {
|
|
|
41
42
|
this.#port = __normalize(channel.port1);
|
|
42
43
|
let resolver = __normalize(modules.createRequire(__normalize(path.join(root, "package.json"))));
|
|
43
44
|
let entry = __normalize(resolver.resolve("@lango-project/lango-server"));
|
|
44
|
-
this.#worker = __normalize(__hostGlobal(["Reflect"]).construct(__normalize(mod.Worker), [__normalize(path.join(__normalize(path.dirname(entry)), "postgres_worker.mjs")), { workerData: { settings: settings, port: __normalize(channel.port2), signal: __normalize(this.#signal) }, transferList: [__normalize(channel.port2)] }]));
|
|
45
|
+
this.#worker = __normalize(__hostGlobal(["Reflect"]).construct(__normalize(mod.Worker), [__normalize(path.join(__normalize(path.dirname(entry)), "postgres_worker.mjs")), { workerData: { root: root, settings: settings, port: __normalize(channel.port2), signal: __normalize(this.#signal) }, transferList: [__normalize(channel.port2)] }]));
|
|
45
46
|
let worker = __normalize(this.#worker);
|
|
46
|
-
__normalize(worker.on("error", __withArity((error) => {
|
|
47
|
+
__normalize(worker.on("error", __withArity(__bindContexts((error) => {
|
|
47
48
|
error = __boundary(error);
|
|
48
49
|
this.#broken = true;
|
|
49
50
|
return null;
|
|
50
|
-
}, [0], "closure")));
|
|
51
|
+
}), [0], "closure")));
|
|
51
52
|
__normalize(this.#worker.unref());
|
|
52
53
|
__normalize(this.#port.unref());
|
|
53
54
|
try {
|
|
@@ -82,6 +83,9 @@ export class PostgresAdapter {
|
|
|
82
83
|
if (__requireBoolean(__normalize(result.failed))) {
|
|
83
84
|
this.#broken = __normalize(result.dead);
|
|
84
85
|
let error = new (__hostGlobal(["Error"]))("PostgreSQL query failed");
|
|
86
|
+
if (__requireBoolean(__normalize(result.detail) !== null)) {
|
|
87
|
+
error = new (__hostGlobal(["Error"]))(`PostgreSQL extension failed: ${__normalize(result.detail)}`);
|
|
88
|
+
}
|
|
85
89
|
error.code = __normalize(result.code);
|
|
86
90
|
error.position = __normalize(result.position);
|
|
87
91
|
error.transactionUnusable = __normalize(this.#state) === "failed";
|
|
@@ -97,6 +101,14 @@ export class PostgresAdapter {
|
|
|
97
101
|
return this.#exchange({ action: "query", sql: sql, parameters: parameters }, __normalize(this.#timeout));
|
|
98
102
|
return null;
|
|
99
103
|
}
|
|
104
|
+
invoke(spec, input) {
|
|
105
|
+
__requireArity(arguments.length, [0, 1], "invoke");
|
|
106
|
+
spec = __boundary(spec);
|
|
107
|
+
input = __boundary(input);
|
|
108
|
+
let result = this.#exchange({ action: "invoke", spec: spec, input: input }, __normalize(this.#timeout));
|
|
109
|
+
return __normalize(result.value);
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
100
112
|
begin() {
|
|
101
113
|
if (__requireBoolean(__requireBoolean(__normalize(this.#depth) === 0) && __requireBoolean(__normalize(this.#state) === null))) {
|
|
102
114
|
this.execute("BEGIN", []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres_adapter.mjs","sources":["postgres_adapter.lango"],"sourcesContent":["import js \"node:module\" as modules\nimport js \"node:path\" as path\nimport js \"node:worker_threads\" as threads\nimport js global Reflect\nimport js global SharedArrayBuffer\nimport js global Int32Array\nimport js global Atomics\nimport js global Math\nimport js global Error\n\nexport class PostgresAdapter(mod, settings, root)\n properties\n parameterStyle\n methods\n execute(sql, parameters)\n begin()\n commit()\n rollback()\n transactionState()\n close()\n\nPostgresAdapter(mod, settings, root)\n @closed = false\n @broken = false\n @state = null\n @depth = 0\n @rollbackOnly = false\n @parameterStyle = \"postgresql\"\n @timeout = Math/min(2147483647, settings.queryTimeoutMs + 1000)\n @signal = new Int32Array(new SharedArrayBuffer(4))\n channel = Reflect/construct(mod.MessageChannel, [])\n @port = channel.port1\n resolver = modules/createRequire(path/join(root, \"package.json\"))\n entry = resolver.resolve(\"@lango-project/lango-server\")\n @worker = Reflect/construct(mod.Worker, [path/join(path/dirname(entry), \"postgres_worker.mjs\"), {\n workerData: {\n settings: settings\n port: channel.port2\n signal: @signal\n }\n transferList: [channel.port2]\n }])\n worker = @worker\n worker.on(\"error\", (error)\n @broken = true\n )\n @worker.unref()\n @port.unref()\n try\n exchange({\n action: \"connect\"\n }, Math/min(2147483647, settings.connectTimeoutSeconds * 1000 + 1000))\n catch error\n close()\n throw new Error(\"PostgreSQL initialization failed\")\n\nPostgresAdapter:exchange(task, timeout)\n if @closed or @broken\n throw new Error(\"PostgreSQL connection is unavailable\")\n Atomics/store(@signal, 0, 0)\n @port.postMessage(task)\n waited = Atomics/wait(@signal, 0, 0, timeout)\n if waited == \"timed-out\"\n @broken = true\n @worker.terminate()\n throw new Error(\"PostgreSQL operation timed out\")\n reply = threads/receiveMessageOnPort(@port)\n if reply == null\n @broken = true\n throw new Error(\"PostgreSQL response was not received\")\n result = reply.message\n @state = result.state\n if result.failed\n @broken = result.dead\n error = new Error(\"PostgreSQL query failed\")\n error.code = result.code\n error.position = result.position\n error.transactionUnusable = @state == \"failed\"\n throw error\n return result\n\nPostgresAdapter:execute(sql, parameters)\n return exchange({\n action: \"query\"\n sql: sql\n parameters: parameters\n }, @timeout)\n\nPostgresAdapter:begin()\n if @depth == 0 and @state == null\n execute(\"BEGIN\", [])\n @depth = @depth + 1\n return null\n\nPostgresAdapter:commit()\n if @depth == 0\n throw new Error(\"NoActiveTransaction\")\n if @depth > 1\n @depth = @depth - 1\n return null\n if @rollbackOnly or @state == \"failed\"\n rollback()\n throw new Error(\"TransactionRolledBack\")\n execute(\"COMMIT\", [])\n @depth = 0\n return null\n\nPostgresAdapter:rollback()\n if @depth > 1\n @depth = @depth - 1\n @rollbackOnly = true\n return null\n if @state != null\n execute(\"ROLLBACK\", [])\n @depth = 0\n @rollbackOnly = false\n return null\n\nPostgresAdapter:transactionState()\n if @broken\n throw new Error(\"PostgreSQL connection is unavailable\")\n if @rollbackOnly and @state != \"failed\"\n return \"rollback_only\"\n return @state\n\nPostgresAdapter:close()\n if @closed\n return null\n try\n if !@broken\n exchange({\n action: \"close\"\n }, @timeout)\n finally\n @closed = true\n @port.close()\n @worker.terminate()\n return null\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"postgres_adapter.mjs","sources":["postgres_adapter.lango"],"sourcesContent":["import js \"node:module\" as modules\nimport js \"node:path\" as path\nimport js \"node:worker_threads\" as threads\nimport js global Reflect\nimport js global SharedArrayBuffer\nimport js global Int32Array\nimport js global Atomics\nimport js global Math\nimport js global Error\n\nexport class PostgresAdapter(mod, settings, root)\n properties\n parameterStyle\n methods\n execute(sql, parameters)\n invoke(spec, input)\n begin()\n commit()\n rollback()\n transactionState()\n close()\n\nPostgresAdapter(mod, settings, root)\n @closed = false\n @broken = false\n @state = null\n @depth = 0\n @rollbackOnly = false\n @parameterStyle = \"postgresql\"\n @timeout = Math/min(2147483647, settings.queryTimeoutMs + 1000)\n @signal = new Int32Array(new SharedArrayBuffer(4))\n channel = Reflect/construct(mod.MessageChannel, [])\n @port = channel.port1\n resolver = modules/createRequire(path/join(root, \"package.json\"))\n entry = resolver.resolve(\"@lango-project/lango-server\")\n @worker = Reflect/construct(mod.Worker, [path/join(path/dirname(entry), \"postgres_worker.mjs\"), {\n workerData: {\n root: root\n settings: settings\n port: channel.port2\n signal: @signal\n }\n transferList: [channel.port2]\n }])\n worker = @worker\n worker.on(\"error\", (error)\n @broken = true\n )\n @worker.unref()\n @port.unref()\n try\n exchange({\n action: \"connect\"\n }, Math/min(2147483647, settings.connectTimeoutSeconds * 1000 + 1000))\n catch error\n close()\n throw new Error(\"PostgreSQL initialization failed\")\n\nPostgresAdapter:exchange(task, timeout)\n if @closed or @broken\n throw new Error(\"PostgreSQL connection is unavailable\")\n Atomics/store(@signal, 0, 0)\n @port.postMessage(task)\n waited = Atomics/wait(@signal, 0, 0, timeout)\n if waited == \"timed-out\"\n @broken = true\n @worker.terminate()\n throw new Error(\"PostgreSQL operation timed out\")\n reply = threads/receiveMessageOnPort(@port)\n if reply == null\n @broken = true\n throw new Error(\"PostgreSQL response was not received\")\n result = reply.message\n @state = result.state\n if result.failed\n @broken = result.dead\n error = new Error(\"PostgreSQL query failed\")\n if result.detail != null\n error = new Error(\"PostgreSQL extension failed: ${result.detail}\")\n error.code = result.code\n error.position = result.position\n error.transactionUnusable = @state == \"failed\"\n throw error\n return result\n\nPostgresAdapter:execute(sql, parameters)\n return exchange({\n action: \"query\"\n sql: sql\n parameters: parameters\n }, @timeout)\n\nPostgresAdapter:invoke(spec, input)\n result = exchange({\n action: \"invoke\"\n spec: spec\n input: input\n }, @timeout)\n return result.value\n\nPostgresAdapter:begin()\n if @depth == 0 and @state == null\n execute(\"BEGIN\", [])\n @depth = @depth + 1\n return null\n\nPostgresAdapter:commit()\n if @depth == 0\n throw new Error(\"NoActiveTransaction\")\n if @depth > 1\n @depth = @depth - 1\n return null\n if @rollbackOnly or @state == \"failed\"\n rollback()\n throw new Error(\"TransactionRolledBack\")\n execute(\"COMMIT\", [])\n @depth = 0\n return null\n\nPostgresAdapter:rollback()\n if @depth > 1\n @depth = @depth - 1\n @rollbackOnly = true\n return null\n if @state != null\n execute(\"ROLLBACK\", [])\n @depth = 0\n @rollbackOnly = false\n return null\n\nPostgresAdapter:transactionState()\n if @broken\n throw new Error(\"PostgreSQL connection is unavailable\")\n if @rollbackOnly and @state != \"failed\"\n return \"rollback_only\"\n return @state\n\nPostgresAdapter:close()\n if @closed\n return null\n try\n if !@broken\n exchange({\n action: \"close\"\n }, @timeout)\n finally\n @closed = true\n @port.close()\n @worker.terminate()\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/postgres_worker.mjs
CHANGED
|
@@ -1,10 +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,
|
|
9
|
+
bindContexts as __bindContexts,
|
|
10
|
+
isNumber as __isNumber,
|
|
11
|
+
isString as __isString,
|
|
12
|
+
isBool as __isBool,
|
|
13
|
+
isObject as __isObject,
|
|
14
|
+
isArray as __isArray,
|
|
5
15
|
requireBoolean as __requireBoolean,
|
|
6
16
|
normalize as __normalize,
|
|
7
17
|
finite as __finite,
|
|
18
|
+
call as __call,
|
|
8
19
|
boundary as __boundary,
|
|
9
20
|
requireArity as __requireArity,
|
|
10
21
|
withArity as __withArity,
|
|
@@ -12,38 +23,48 @@ import {
|
|
|
12
23
|
|
|
13
24
|
let state = initialState();
|
|
14
25
|
|
|
26
|
+
let loader = new ModuleLoader();
|
|
27
|
+
|
|
15
28
|
let installed = install();
|
|
16
29
|
function install() {
|
|
17
30
|
let port = threads.workerData.port;
|
|
18
|
-
__normalize(port.on("message", __withArity((task) => {
|
|
31
|
+
__normalize(port.on("message", __withArity(__bindContexts((task) => {
|
|
19
32
|
task = __boundary(task);
|
|
20
|
-
return __normalize(__hostGlobal(["Promise"]).resolve(null)).then(__withArity((ignored) => {
|
|
33
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(null)).then(__withArity(__bindContexts((ignored) => {
|
|
21
34
|
ignored = __boundary(ignored);
|
|
22
35
|
return execute(task);
|
|
23
36
|
return null;
|
|
24
|
-
}, [0], "closure")).then(__withArity((result) => {
|
|
37
|
+
}), [0], "closure")).then(__withArity(__bindContexts((result) => {
|
|
25
38
|
result = __boundary(result);
|
|
26
39
|
reply(result);
|
|
27
40
|
return null;
|
|
28
41
|
return null;
|
|
29
|
-
}, [0], "closure")).catch(__withArity((error) => {
|
|
42
|
+
}), [0], "closure")).catch(__withArity(__bindContexts((error) => {
|
|
30
43
|
error = __boundary(error);
|
|
31
|
-
|
|
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))))) {
|
|
32
46
|
state.transaction = "failed";
|
|
33
47
|
}
|
|
34
|
-
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"))))) {
|
|
35
52
|
state.dead = true;
|
|
36
53
|
}
|
|
37
54
|
let position = null;
|
|
55
|
+
let detail = null;
|
|
56
|
+
if (__requireBoolean(__requireBoolean(__normalize(task.action) === "invoke") && __requireBoolean(!__requireBoolean(sqlError)))) {
|
|
57
|
+
detail = errorDetails(error);
|
|
58
|
+
}
|
|
38
59
|
if (__requireBoolean(__normalize(error.position) !== null)) {
|
|
39
60
|
position = __normalize(__hostGlobal(["Number"]).parseInt(__normalize(error.position), 10));
|
|
40
61
|
}
|
|
41
|
-
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) });
|
|
42
63
|
return null;
|
|
43
64
|
return null;
|
|
44
|
-
}, [0], "closure"));
|
|
65
|
+
}), [0], "closure"));
|
|
45
66
|
return null;
|
|
46
|
-
}, [0], "closure")));
|
|
67
|
+
}), [0], "closure")));
|
|
47
68
|
return null;
|
|
48
69
|
return null;
|
|
49
70
|
}
|
|
@@ -55,18 +76,18 @@ function execute(task) {
|
|
|
55
76
|
if (__normalize(task.action) === "connect") {
|
|
56
77
|
state.client = new pg.Client({ connectionString: __normalize(settings.connection), connectionTimeoutMillis: __normalize(__hostGlobal(["Math"]).min(2147483647, __finite(__normalize(settings.connectTimeoutSeconds) * 1000))), statement_timeout: __normalize(settings.queryTimeoutMs), application_name: "lango-server" });
|
|
57
78
|
let client = __normalize(state.client);
|
|
58
|
-
__normalize(client.on("error", __withArity((error) => {
|
|
79
|
+
__normalize(client.on("error", __withArity(__bindContexts((error) => {
|
|
59
80
|
error = __boundary(error);
|
|
60
81
|
state.dead = true;
|
|
61
82
|
return null;
|
|
62
|
-
}, [0], "closure")));
|
|
63
|
-
return __normalize(client.connect()).then(__withArity((ignored) => {
|
|
83
|
+
}), [0], "closure")));
|
|
84
|
+
return __normalize(client.connect()).then(__withArity(__bindContexts((ignored) => {
|
|
64
85
|
ignored = __boundary(ignored);
|
|
65
86
|
return success([], null);
|
|
66
87
|
return null;
|
|
67
|
-
}, [0], "closure"));
|
|
88
|
+
}), [0], "closure"));
|
|
68
89
|
} else if (__normalize(task.action) === "query") {
|
|
69
|
-
return __normalize(state.client.query({ text: __normalize(task.sql), values: __normalize(task.parameters), queryMode: "extended" })).then(__withArity((result) => {
|
|
90
|
+
return __normalize(state.client.query({ text: __normalize(task.sql), values: __normalize(task.parameters), queryMode: "extended" })).then(__withArity(__bindContexts((result) => {
|
|
70
91
|
result = __boundary(result);
|
|
71
92
|
if (__normalize(result.command) === "BEGIN") {
|
|
72
93
|
state.transaction = "active";
|
|
@@ -79,24 +100,66 @@ function execute(task) {
|
|
|
79
100
|
}
|
|
80
101
|
return success(__normalize(result.rows), changes);
|
|
81
102
|
return null;
|
|
82
|
-
}, [0], "closure"));
|
|
103
|
+
}), [0], "closure"));
|
|
104
|
+
} else if (__normalize(task.action) === "invoke") {
|
|
105
|
+
return invoke(task);
|
|
83
106
|
} else if (__normalize(task.action) === "close") {
|
|
84
|
-
return __normalize(state.client.end()).then(__withArity((ignored) => {
|
|
107
|
+
return __normalize(state.client.end()).then(__withArity(__bindContexts((ignored) => {
|
|
85
108
|
ignored = __boundary(ignored);
|
|
86
109
|
return success([], null);
|
|
87
110
|
return null;
|
|
88
|
-
}, [0], "closure"));
|
|
111
|
+
}), [0], "closure"));
|
|
89
112
|
} else {
|
|
90
113
|
throw "Unknown PostgreSQL operation";
|
|
91
114
|
}
|
|
92
115
|
return null;
|
|
93
116
|
}
|
|
94
117
|
|
|
95
|
-
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) {
|
|
96
158
|
__requireArity(arguments.length, [0, 1], "success");
|
|
97
159
|
rows = __boundary(rows);
|
|
98
160
|
changes = __boundary(changes);
|
|
99
|
-
|
|
161
|
+
value = __boundary(value);
|
|
162
|
+
return { failed: false, dead: false, state: __normalize(state.transaction), rows: rows, changes: changes, lastInsertRowid: null, value: value };
|
|
100
163
|
return null;
|
|
101
164
|
}
|
|
102
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;;;;;"}
|
|
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/response.mjs
CHANGED
|
@@ -41,7 +41,7 @@ export class Response {
|
|
|
41
41
|
throw "Header name and value must be strings";
|
|
42
42
|
}
|
|
43
43
|
name = __normalize(name.toLowerCase());
|
|
44
|
-
if (__requireBoolean(contains(["x-lango-token", "content-length", "transfer-encoding", "connection", "content-type"], name))) {
|
|
44
|
+
if (__requireBoolean(contains(["x-lango-auth-change", "x-lango-need-login", "x-lango-token", "content-length", "transfer-encoding", "connection", "content-type"], name))) {
|
|
45
45
|
throw `Reserved response header: ${name}`;
|
|
46
46
|
}
|
|
47
47
|
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__normalize(name.includes("\\r"))) || __requireBoolean(__normalize(name.includes("\n")))) || __requireBoolean(__normalize(value.includes("\\r")))) || __requireBoolean(__normalize(value.includes("\n"))))) {
|
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-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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/route_info.mjs
CHANGED
|
@@ -14,7 +14,7 @@ export function routeInfo(definitions) {
|
|
|
14
14
|
if (__requireBoolean(kind === null)) {
|
|
15
15
|
kind = "endpoint";
|
|
16
16
|
}
|
|
17
|
-
result.push({ path: __normalize(route.path), kind: kind, auth: __normalize(route.auth), middleware: __normalize(route.middleware) });
|
|
17
|
+
result.push({ path: __normalize(route.path), kind: kind, auth: __normalize(route.auth), policy: __normalize(route.policy), reauthSeconds: __normalize(route.reauthSeconds), middleware: __normalize(route.middleware) });
|
|
18
18
|
}
|
|
19
19
|
return result;
|
|
20
20
|
return null;
|
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 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;;;;;;;;;;;;;;;"}
|