@lango-project/lango-server 0.2.4 → 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 +8 -0
- package/dist/body_reader.mjs.map +1 -1
- package/dist/builder.mjs.map +1 -1
- package/dist/cli/server.mjs +3 -838
- 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.map +1 -1
- package/dist/database_options.mjs.map +1 -1
- 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.map +1 -1
- package/dist/execution_identity.mjs.map +1 -1
- package/dist/execution_log.mjs.map +1 -1
- package/dist/execution_runtime.mjs.map +1 -1
- package/dist/execution_worker.mjs.map +1 -1
- package/dist/executor.mjs.map +1 -1
- package/dist/group.mjs.map +1 -1
- package/dist/http_failure.mjs.map +1 -1
- package/dist/job_configuration.mjs.map +1 -1
- package/dist/job_context.mjs.map +1 -1
- 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.map +1 -1
- package/dist/module_loader.mjs.map +1 -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.map +1 -1
- package/dist/postgres_worker.mjs.map +1 -1
- package/dist/queue_provider.mjs.map +1 -1
- 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.map +1 -1
- package/dist/runtime.mjs.map +1 -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/examples/security/package.json +1 -1
- package/package.json +6 -4
- 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 -93
- 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 -214
- 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 -178
- 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 -360
- 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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"database_options.mjs","sources":["database_options.lango"],"sourcesContent":["import js \"node:path\" as path\nimport js global Object\nimport js global Number\nimport js global process\n\nexport databaseOptions(root, spec, workers)\n\ndatabaseOptions(root, spec, workers)\n if spec == null\n return null\n if !is_object(spec) or is_array(spec)\n throw \"Database configuration must be a map\"\n allowed = []\n switch spec.type\n case \"sqlite\"\n allowed = [\"type\", \"file\", \"busyTimeoutMs\"]\n case \"postgresql\"\n allowed = [\"type\", \"connectionEnv\", \"queryTimeoutMs\", \"connectTimeoutSeconds\"]\n else\n throw \"Database type must be sqlite or postgresql\"\n for spec as key: value\n if !allowed.includes(key)\n throw \"Unknown database option: ${key}\"\n if spec.type == \"sqlite\"\n if !is_string(spec.file) or spec.file == \"\"\n throw \"SQLite database file is required\"\n file = spec.file\n if file == \":memory:\" and workers != 1\n throw \"An in-memory SQLite database requires exactly one worker\"\n if file != \":memory:\"\n file = path/resolve(root, file)\n return {\n type: \"sqlite\"\n file: file\n busyTimeoutMs: positive(spec.busyTimeoutMs, 5000)\n }\n name = spec.connectionEnv\n if !is_string(name) or name == \"\" or !Object/hasOwn(process.env, name)\n throw \"PostgreSQL connectionEnv must name an existing environment variable\"\n connection = process.env[name]\n if !is_string(connection) or (!connection.startsWith(\"postgresql://\") and !connection.startsWith(\"postgres://\"))\n throw \"PostgreSQL connectionEnv must contain a PostgreSQL connection URL\"\n return {\n type: \"postgresql\"\n connection: connection\n queryTimeoutMs: positive(spec.queryTimeoutMs, 5000)\n connectTimeoutSeconds: positive(spec.connectTimeoutSeconds, 5)\n }\n\npositive(value, fallback)\n if value == null\n return fallback\n if is_string(value)\n value = Number(value)\n if !Number/isSafeInteger(value) or value < 1 or value > 2147483647\n throw \"Database timeout must be a positive integer within the timer limit\"\n return value\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
hostGlobal as __hostGlobal,
|
|
3
|
-
contextGet as __contextGet,
|
|
4
|
-
contextSet as __contextSet,
|
|
5
|
-
contextRestore as __contextRestore,
|
|
6
|
-
requireBoolean as __requireBoolean,
|
|
7
|
-
normalize as __normalize,
|
|
8
|
-
boundary as __boundary,
|
|
9
|
-
requireArity as __requireArity,
|
|
10
|
-
} from "./.lango/runtime.mjs";
|
|
11
|
-
|
|
12
|
-
export class DatabaseScope {
|
|
13
|
-
parameterStyle;
|
|
14
|
-
#adapter;
|
|
15
|
-
#closed;
|
|
16
|
-
constructor(adapter) {
|
|
17
|
-
__requireArity(arguments.length, [0], "constructor");
|
|
18
|
-
adapter = __boundary(adapter);
|
|
19
|
-
this.#adapter = adapter;
|
|
20
|
-
this.#closed = false;
|
|
21
|
-
this.parameterStyle = __normalize(adapter.parameterStyle);
|
|
22
|
-
}
|
|
23
|
-
execute(sql, parameters) {
|
|
24
|
-
__requireArity(arguments.length, [0, 1], "execute");
|
|
25
|
-
sql = __boundary(sql);
|
|
26
|
-
parameters = __boundary(parameters);
|
|
27
|
-
this.#requireOpen();
|
|
28
|
-
return __normalize(this.#adapter.execute(sql, parameters));
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
invoke(spec, input) {
|
|
32
|
-
__requireArity(arguments.length, [0, 1], "invoke");
|
|
33
|
-
spec = __boundary(spec);
|
|
34
|
-
input = __boundary(input);
|
|
35
|
-
this.#requireOpen();
|
|
36
|
-
if (__requireBoolean(__normalize(this.parameterStyle) !== "postgresql")) {
|
|
37
|
-
throw "Database extensions require PostgreSQL";
|
|
38
|
-
}
|
|
39
|
-
return __normalize(this.#adapter.invoke(spec, input));
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
begin() {
|
|
43
|
-
this.#requireOpen();
|
|
44
|
-
return __normalize(this.#adapter.begin());
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
commit() {
|
|
48
|
-
this.#requireOpen();
|
|
49
|
-
return __normalize(this.#adapter.commit());
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
rollback() {
|
|
53
|
-
this.#requireOpen();
|
|
54
|
-
return __normalize(this.#adapter.rollback());
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
transactionState() {
|
|
58
|
-
this.#requireOpen();
|
|
59
|
-
return __normalize(this.#adapter.transactionState());
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
#requireOpen() {
|
|
63
|
-
if (__requireBoolean(__normalize(this.#closed))) {
|
|
64
|
-
throw new (__hostGlobal(["Error"]))("DatabaseScopeClosed");
|
|
65
|
-
}
|
|
66
|
-
return null;
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
finish() {
|
|
70
|
-
const __contextScope = [];
|
|
71
|
-
try {
|
|
72
|
-
if (__requireBoolean(__normalize(this.#closed))) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
this.#closed = true;
|
|
76
|
-
let dirty = false;
|
|
77
|
-
try {
|
|
78
|
-
__loop1: while (__requireBoolean(__normalize(this.#adapter.transactionState()) !== null)) {
|
|
79
|
-
dirty = true;
|
|
80
|
-
__normalize(this.#adapter.rollback());
|
|
81
|
-
}
|
|
82
|
-
} catch (error) {
|
|
83
|
-
__normalize(__contextGet("log").err("Database cleanup failed; retiring worker"));
|
|
84
|
-
__normalize(__hostGlobal(["process"]).exit(1));
|
|
85
|
-
}
|
|
86
|
-
return dirty;
|
|
87
|
-
return null;
|
|
88
|
-
} finally {
|
|
89
|
-
__contextRestore(__contextScope);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=database_scope.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"database_scope.mjs","sources":["database_scope.lango"],"sourcesContent":["import js global Error\nimport js global Object\nimport js global process\n\nexport class DatabaseScope(adapter)\n properties\n parameterStyle\n methods\n execute(sql, parameters)\n invoke(spec, input)\n begin()\n commit()\n rollback()\n transactionState()\n finish()\n\nDatabaseScope(adapter)\n @adapter = adapter\n @closed = false\n @parameterStyle = adapter.parameterStyle\n\nDatabaseScope:execute(sql, parameters)\n requireOpen()\n return @adapter.execute(sql, parameters)\n\nDatabaseScope:invoke(spec, input)\n requireOpen()\n if @parameterStyle != \"postgresql\"\n throw \"Database extensions require PostgreSQL\"\n return @adapter.invoke(spec, input)\n\nDatabaseScope:begin()\n requireOpen()\n return @adapter.begin()\n\nDatabaseScope:commit()\n requireOpen()\n return @adapter.commit()\n\nDatabaseScope:rollback()\n requireOpen()\n return @adapter.rollback()\n\nDatabaseScope:transactionState()\n requireOpen()\n return @adapter.transactionState()\n\nDatabaseScope:requireOpen()\n if @closed\n throw new Error(\"DatabaseScopeClosed\")\n return null\n\nDatabaseScope:finish()\n if @closed\n return false\n @closed = true\n dirty = false\n try\n loop while @adapter.transactionState() != null\n dirty = true\n @adapter.rollback()\n catch error\n context log\n log.err(\"Database cleanup failed; retiring worker\")\n process.exit(1)\n return dirty\n"],"names":[],"mappings":";;;;;;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/cli/endpoint.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { policyOptions } from "./policy.mjs";
|
|
2
|
-
import { routePattern } from "./route_pattern.mjs";
|
|
3
|
-
import { middlewareName } from "./middleware.mjs";
|
|
4
|
-
import {
|
|
5
|
-
isNumber as __isNumber,
|
|
6
|
-
isString as __isString,
|
|
7
|
-
isBool as __isBool,
|
|
8
|
-
isObject as __isObject,
|
|
9
|
-
isArray as __isArray,
|
|
10
|
-
requireBoolean as __requireBoolean,
|
|
11
|
-
normalize as __normalize,
|
|
12
|
-
boundary as __boundary,
|
|
13
|
-
requireArity as __requireArity,
|
|
14
|
-
} from "./.lango/runtime.mjs";
|
|
15
|
-
|
|
16
|
-
export class Endpoint {
|
|
17
|
-
path;
|
|
18
|
-
module;
|
|
19
|
-
handler;
|
|
20
|
-
auth;
|
|
21
|
-
policy;
|
|
22
|
-
reauthSeconds;
|
|
23
|
-
reauthExplicit;
|
|
24
|
-
legacyAuth;
|
|
25
|
-
middleware;
|
|
26
|
-
constructor(spec) {
|
|
27
|
-
__requireArity(arguments.length, [0], "constructor");
|
|
28
|
-
spec = __boundary(spec);
|
|
29
|
-
routePattern(__normalize(spec.path));
|
|
30
|
-
for (const key of ["module", "handler"]) {
|
|
31
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec[key])))) || __requireBoolean(__normalize(spec[key]) === ""))) {
|
|
32
|
-
throw `Endpoint requires ${key}`;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
this.path = __normalize(spec.path);
|
|
36
|
-
this.module = __normalize(spec.module);
|
|
37
|
-
this.handler = __normalize(spec.handler);
|
|
38
|
-
this.middleware = __normalize(spec.middleware);
|
|
39
|
-
if (__requireBoolean(__normalize(this.middleware) !== null)) {
|
|
40
|
-
middlewareName(__normalize(this.middleware));
|
|
41
|
-
}
|
|
42
|
-
let selected = policyOptions(spec);
|
|
43
|
-
this.policy = __normalize(selected.name);
|
|
44
|
-
this.auth = __normalize(selected.name);
|
|
45
|
-
this.reauthSeconds = __normalize(selected.reauthSeconds);
|
|
46
|
-
this.reauthExplicit = __normalize(selected.explicit);
|
|
47
|
-
this.legacyAuth = __normalize(selected.legacy);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=endpoint.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint.mjs","sources":["endpoint.lango"],"sourcesContent":["import \"./policy\"\n policyOptions(spec)\nimport \"./route_pattern\"\n routePattern(path)\nimport \"./middleware\"\n middlewareName(name)\n\nexport class Endpoint(spec)\n properties\n path\n module\n handler\n auth\n policy\n reauthSeconds\n reauthExplicit\n legacyAuth\n middleware\n\nEndpoint(spec)\n routePattern(spec.path)\n for [\"module\", \"handler\"] as key\n if !is_string(spec[key]) or spec[key] == \"\"\n throw \"Endpoint requires ${key}\"\n @path = spec.path\n @module = spec.module\n @handler = spec.handler\n @middleware = spec.middleware\n if @middleware != null\n middlewareName(@middleware)\n selected = policyOptions(spec)\n @policy = selected.name\n @auth = selected.name\n @reauthSeconds = selected.reauthSeconds\n @reauthExplicit = selected.explicit\n @legacyAuth = selected.legacy\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isNumber as __isNumber,
|
|
3
|
-
isString as __isString,
|
|
4
|
-
isBool as __isBool,
|
|
5
|
-
isObject as __isObject,
|
|
6
|
-
isArray as __isArray,
|
|
7
|
-
requireBoolean as __requireBoolean,
|
|
8
|
-
normalize as __normalize,
|
|
9
|
-
boundary as __boundary,
|
|
10
|
-
requireArity as __requireArity,
|
|
11
|
-
} from "./.lango/runtime.mjs";
|
|
12
|
-
|
|
13
|
-
export function errorDetails(error) {
|
|
14
|
-
__requireArity(arguments.length, [0], "errorDetails");
|
|
15
|
-
error = __boundary(error);
|
|
16
|
-
if (__requireBoolean(__isObject(error))) {
|
|
17
|
-
if (__requireBoolean(__requireBoolean(__isString(__normalize(error.stack))) && __requireBoolean(__normalize(error.stack) !== ""))) {
|
|
18
|
-
return __normalize(error.stack);
|
|
19
|
-
}
|
|
20
|
-
if (__requireBoolean(__requireBoolean(__isString(__normalize(error.message))) && __requireBoolean(__normalize(error.message) !== ""))) {
|
|
21
|
-
return __normalize(error.message);
|
|
22
|
-
}
|
|
23
|
-
if (__requireBoolean(__isString(__normalize(error.code)))) {
|
|
24
|
-
return __normalize(error.code);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return `${error}`;
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function errorMessage(error) {
|
|
32
|
-
__requireArity(arguments.length, [0], "errorMessage");
|
|
33
|
-
error = __boundary(error);
|
|
34
|
-
if (__requireBoolean(__isObject(error))) {
|
|
35
|
-
if (__requireBoolean(__requireBoolean(__isString(__normalize(error.message))) && __requireBoolean(__normalize(error.message) !== ""))) {
|
|
36
|
-
return __normalize(error.message);
|
|
37
|
-
}
|
|
38
|
-
if (__requireBoolean(__isString(__normalize(error.code)))) {
|
|
39
|
-
return __normalize(error.code);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return `${error}`;
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=error_details.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error_details.mjs","sources":["error_details.lango"],"sourcesContent":["export errorDetails(error)\nexport errorMessage(error)\n\nerrorDetails(error)\n if is_object(error)\n if is_string(error.stack) and error.stack != \"\"\n return error.stack\n if is_string(error.message) and error.message != \"\"\n return error.message\n if is_string(error.code)\n return error.code\n return \"${error}\"\n\n\nerrorMessage(error)\n if is_object(error)\n if is_string(error.message) and error.message != \"\"\n return error.message\n if is_string(error.code)\n return error.code\n return \"${error}\"\n"],"names":[],"mappings":";;;;;;;;;;;;AAGA;;;;;;;;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;"}
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import * as redis from "redis";
|
|
2
|
-
import * as crypto from "node:crypto";
|
|
3
|
-
import * as fs from "node:fs";
|
|
4
|
-
import * as path from "node:path";
|
|
5
|
-
import * as modules from "node:module";
|
|
6
|
-
import {
|
|
7
|
-
hostGlobal as __hostGlobal,
|
|
8
|
-
hostGlobalCall as __hostGlobalCall,
|
|
9
|
-
bindContexts as __bindContexts,
|
|
10
|
-
fromJson as __fromJson,
|
|
11
|
-
toJson as __toJson,
|
|
12
|
-
isNumber as __isNumber,
|
|
13
|
-
isString as __isString,
|
|
14
|
-
isBool as __isBool,
|
|
15
|
-
isObject as __isObject,
|
|
16
|
-
isArray as __isArray,
|
|
17
|
-
requireBoolean as __requireBoolean,
|
|
18
|
-
normalize as __normalize,
|
|
19
|
-
boundary as __boundary,
|
|
20
|
-
requireArity as __requireArity,
|
|
21
|
-
withArity as __withArity,
|
|
22
|
-
} from "./.lango/runtime.mjs";
|
|
23
|
-
|
|
24
|
-
export class LongpollBroker {
|
|
25
|
-
#routes;
|
|
26
|
-
#settings;
|
|
27
|
-
#client;
|
|
28
|
-
#script;
|
|
29
|
-
#root;
|
|
30
|
-
#lango;
|
|
31
|
-
constructor(settings, routes) {
|
|
32
|
-
__requireArity(arguments.length, [0, 1], "constructor");
|
|
33
|
-
settings = __boundary(settings);
|
|
34
|
-
routes = __boundary(routes);
|
|
35
|
-
this.#routes = __normalize(__hostGlobal(["Object"]).create(null));
|
|
36
|
-
for (const item of routes) {
|
|
37
|
-
if (__requireBoolean(__normalize(item.kind) === "longpoll")) {
|
|
38
|
-
this.#routes[__normalize(item.path)] = item;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
this.#settings = __normalize(settings.redis);
|
|
42
|
-
this.#client = null;
|
|
43
|
-
this.#script = null;
|
|
44
|
-
if (__requireBoolean(__requireBoolean(__normalize(__normalize(__hostGlobal(["Object"]).keys(__normalize(this.#routes))).length) > 0) && __requireBoolean(__normalize(this.#settings) === null))) {
|
|
45
|
-
throw "Longpoll routes require Redis configuration";
|
|
46
|
-
}
|
|
47
|
-
this.#root = __normalize(settings.root);
|
|
48
|
-
}
|
|
49
|
-
route(path) {
|
|
50
|
-
__requireArity(arguments.length, [0], "route");
|
|
51
|
-
path = __boundary(path);
|
|
52
|
-
if (__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(__normalize(this.#routes), path)))) {
|
|
53
|
-
return __normalize(this.#routes[path]);
|
|
54
|
-
}
|
|
55
|
-
return null;
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
open() {
|
|
59
|
-
if (__requireBoolean(__normalize(__normalize(__hostGlobal(["Object"]).keys(__normalize(this.#routes))).length) === 0)) {
|
|
60
|
-
return __normalize(__hostGlobal(["Promise"]).resolve(null));
|
|
61
|
-
}
|
|
62
|
-
let resolver = __normalize(modules.createRequire(__normalize(path.join(__normalize(this.#root), "package.json"))));
|
|
63
|
-
let entry = __normalize(resolver.resolve("@lango-project/lango-server"));
|
|
64
|
-
this.#script = __normalize(fs.readFileSync(__normalize(path.join(__normalize(path.dirname(entry)), "../src/longpoll.lua")), "utf8"));
|
|
65
|
-
let config = __normalize(this.#settings);
|
|
66
|
-
let name = __normalize(config.connectionEnv);
|
|
67
|
-
this.#client = __normalize(redis.createClient({ url: __normalize(__hostGlobal(["process"]).env[name]), disableOfflineQueue: true, commandsQueueMaxLength: 2048, socket: { connectTimeout: 2000, reconnectStrategy: 500 } }));
|
|
68
|
-
let client = __normalize(this.#client);
|
|
69
|
-
__normalize(client.on("error", __withArity(__bindContexts((error) => {
|
|
70
|
-
error = __boundary(error);
|
|
71
|
-
return null;
|
|
72
|
-
return null;
|
|
73
|
-
}), [0], "closure")));
|
|
74
|
-
return bounded(__normalize(client.connect()), 3000);
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
close() {
|
|
78
|
-
if (__requireBoolean(__requireBoolean(__normalize(this.#client) !== null) && __requireBoolean(__normalize(this.#client.isOpen)))) {
|
|
79
|
-
__normalize(this.#client.destroy());
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
publish(path, key, data) {
|
|
85
|
-
__requireArity(arguments.length, [0, 1, 2], "publish");
|
|
86
|
-
path = __boundary(path);
|
|
87
|
-
key = __boundary(key);
|
|
88
|
-
data = __boundary(data);
|
|
89
|
-
let body = __normalize(__hostGlobal(["JSON"]).stringify(data));
|
|
90
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(body))) || __requireBoolean(__normalize(__hostGlobal(["Buffer"]).byteLength(body)) > 262144))) {
|
|
91
|
-
return __normalize(__hostGlobal(["Promise"]).reject("Longpoll message must be JSON within 262144 bytes"));
|
|
92
|
-
}
|
|
93
|
-
return this.#execute("publish", path, key, null, body);
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
cursor(path, key) {
|
|
97
|
-
__requireArity(arguments.length, [0, 1], "cursor");
|
|
98
|
-
path = __boundary(path);
|
|
99
|
-
key = __boundary(key);
|
|
100
|
-
return this.#execute("cursor", path, key, null, "");
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
read(path, key, cursor) {
|
|
104
|
-
__requireArity(arguments.length, [0, 1, 2], "read");
|
|
105
|
-
path = __boundary(path);
|
|
106
|
-
key = __boundary(key);
|
|
107
|
-
cursor = __boundary(cursor);
|
|
108
|
-
return this.#execute("read", path, key, cursor, "");
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
#execute(operation, path, key, cursor, body) {
|
|
112
|
-
__requireArity(arguments.length, [0, 1, 2, 3, 4], "execute");
|
|
113
|
-
operation = __boundary(operation);
|
|
114
|
-
path = __boundary(path);
|
|
115
|
-
key = __boundary(key);
|
|
116
|
-
cursor = __boundary(cursor);
|
|
117
|
-
body = __boundary(body);
|
|
118
|
-
let item = this.route(path);
|
|
119
|
-
if (__requireBoolean(item === null)) {
|
|
120
|
-
return __normalize(__hostGlobal(["Promise"]).reject("Unknown longpoll path"));
|
|
121
|
-
}
|
|
122
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(key))) || __requireBoolean(key === "")) || __requireBoolean(__normalize(__hostGlobal(["Buffer"]).byteLength(key)) > 1024))) {
|
|
123
|
-
return __normalize(__hostGlobal(["Promise"]).reject("Longpoll key must contain 1 to 1024 bytes"));
|
|
124
|
-
}
|
|
125
|
-
if (__requireBoolean(__requireBoolean(__normalize(this.#client) === null) || __requireBoolean(!__requireBoolean(__normalize(this.#client.isReady))))) {
|
|
126
|
-
return __normalize(__hostGlobal(["Promise"]).reject("RedisUnavailable"));
|
|
127
|
-
}
|
|
128
|
-
let hash = __normalize(crypto.createHash("sha256"));
|
|
129
|
-
__normalize(hash.update(__toJson([__normalize(this.#settings.namespace), path, key])));
|
|
130
|
-
let channel = __normalize(hash.digest("hex"));
|
|
131
|
-
let prefix = `lango:longpoll:{${channel}}`;
|
|
132
|
-
let position = { generation: "", id: "0-0" };
|
|
133
|
-
if (__requireBoolean(cursor !== null)) {
|
|
134
|
-
position = decode(cursor, channel);
|
|
135
|
-
if (__requireBoolean(position === null)) {
|
|
136
|
-
return __normalize(__hostGlobal(["Promise"]).resolve({ resyncRequired: true }));
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
let pending = __normalize(this.#client.eval(__normalize(this.#script), { keys: [`${prefix}:stream`, `${prefix}:meta`], arguments: [operation, __normalize(crypto.randomUUID()), `${__normalize(item.retentionMs)}`, `${__normalize(item.maxMessages)}`, __normalize(position.generation), __normalize(position.id), body] }));
|
|
140
|
-
return bounded(pending, 3000).then(__withArity(__bindContexts((raw) => {
|
|
141
|
-
raw = __boundary(raw);
|
|
142
|
-
let result = __normalize(__hostGlobal(["JSON"]).parse(raw));
|
|
143
|
-
if (__requireBoolean(__normalize(result.resyncRequired) === true)) {
|
|
144
|
-
return result;
|
|
145
|
-
}
|
|
146
|
-
result.cursor = encode(channel, __normalize(result.generation), __normalize(result.id));
|
|
147
|
-
if (__requireBoolean(operation !== "read")) {
|
|
148
|
-
return __normalize(result.cursor);
|
|
149
|
-
}
|
|
150
|
-
let messages = [];
|
|
151
|
-
if (__requireBoolean(__isArray(__normalize(result.messages)))) {
|
|
152
|
-
for (const message of __normalize(result.messages)) {
|
|
153
|
-
messages.push({ id: encode(channel, __normalize(result.generation), __normalize(message.id)), data: __normalize(__hostGlobal(["JSON"]).parse(__normalize(message.data))) });
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return { messages: messages, cursor: __normalize(result.cursor), resyncRequired: false };
|
|
157
|
-
return null;
|
|
158
|
-
}), [0], "closure"));
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
function encode(channel, generation, id) {
|
|
163
|
-
__requireArity(arguments.length, [0, 1, 2], "encode");
|
|
164
|
-
channel = __boundary(channel);
|
|
165
|
-
generation = __boundary(generation);
|
|
166
|
-
id = __boundary(id);
|
|
167
|
-
let buffer = __normalize(__hostGlobal(["Buffer"]).from(__toJson([channel, generation, id])));
|
|
168
|
-
return __normalize(buffer.toString("base64url"));
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function decode(cursor, channel) {
|
|
173
|
-
__requireArity(arguments.length, [0, 1], "decode");
|
|
174
|
-
cursor = __boundary(cursor);
|
|
175
|
-
channel = __boundary(channel);
|
|
176
|
-
let buffer;
|
|
177
|
-
let parts;
|
|
178
|
-
let pattern;
|
|
179
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(cursor))) || __requireBoolean(__normalize(cursor.length) > 512))) {
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
try {
|
|
183
|
-
buffer = __normalize(__hostGlobal(["Buffer"]).from(cursor, "base64url"));
|
|
184
|
-
parts = __fromJson(__normalize(buffer.toString("utf8")));
|
|
185
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isArray(parts))) || __requireBoolean(__normalize(parts.length) !== 3)) || __requireBoolean(__normalize(parts[0]) !== channel)) || __requireBoolean(!__requireBoolean(__isString(__normalize(parts[1]))))) || __requireBoolean(!__requireBoolean(__isString(__normalize(parts[2])))))) {
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
pattern = new (__hostGlobal(["RegExp"]))("^(0|[1-9][0-9]{0,18})-(0|[1-9][0-9]{0,18})$");
|
|
189
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(pattern.test(__normalize(parts[2]))))) || __requireBoolean(__normalize(__normalize(parts[2]).length) > 40))) {
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
return { generation: __normalize(parts[1]), id: __normalize(parts[2]) };
|
|
193
|
-
} catch (error) {
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function bounded(pending, ms) {
|
|
200
|
-
__requireArity(arguments.length, [0, 1], "bounded");
|
|
201
|
-
pending = __boundary(pending);
|
|
202
|
-
ms = __boundary(ms);
|
|
203
|
-
let expired = __normalize(__hostGlobal(["Promise"]).withResolvers());
|
|
204
|
-
let fail = __bindContexts(() => {
|
|
205
|
-
__normalize(expired.reject("RedisUnavailable"));
|
|
206
|
-
return null;
|
|
207
|
-
});
|
|
208
|
-
let timer = __hostGlobalCall(["setTimeout"], fail, ms);
|
|
209
|
-
return __normalize(__hostGlobal(["Promise"]).race([pending, __normalize(expired.promise)])).finally(__bindContexts(() => {
|
|
210
|
-
__hostGlobalCall(["clearTimeout"], timer);
|
|
211
|
-
return null;
|
|
212
|
-
}));
|
|
213
|
-
return null;
|
|
214
|
-
}
|
|
215
|
-
//# sourceMappingURL=longpoll_broker.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"longpoll_broker.mjs","sources":["longpoll_broker.lango"],"sourcesContent":["import js \"redis\" as redis\nimport js \"node:crypto\" as crypto\nimport js \"node:fs\" as fs\nimport js \"node:path\" as path\nimport js \"node:module\" as modules\nimport js global Buffer\nimport js global Promise\nimport js global process\nimport js global JSON\nimport js global RegExp\nimport js global Object\nimport js global setTimeout\nimport js global clearTimeout\n\nexport class LongpollBroker(settings, routes)\n methods\n open()\n close()\n route(path)\n publish(path, key, data)\n cursor(path, key)\n read(path, key, cursor)\n\nLongpollBroker(settings, routes)\n @routes = Object/create(null)\n for routes as item\n if item.kind == \"longpoll\"\n @routes[item.path] = item\n @settings = settings.redis\n @client = null\n @script = null\n if Object/keys(@routes).length > 0 and @settings == null\n throw \"Longpoll routes require Redis configuration\"\n @root = settings.root\n\nLongpollBroker:route(path)\n if Object/hasOwn(@routes, path)\n return @routes[path]\n return null\n\nLongpollBroker:open()\n if Object/keys(@routes).length == 0\n return Promise/resolve(null)\n resolver = modules/createRequire(path/join(@root, \"package.json\"))\n entry = resolver.resolve(\"@lango-project/lango-server\")\n @script = fs/readFileSync(path/join(path/dirname(entry), \"../src/longpoll.lua\"), \"utf8\")\n config = @settings\n name = config.connectionEnv\n @client = redis/createClient({\n url: process.env[name]\n disableOfflineQueue: true\n commandsQueueMaxLength: 2048\n socket: {\n connectTimeout: 2000\n reconnectStrategy: 500\n }\n })\n client = @client\n client.on(\"error\", (error)\n return null\n )\n return bounded(client.connect(), 3000)\n\nLongpollBroker:close()\n if @client != null and @client.isOpen\n @client.destroy()\n return null\n\nLongpollBroker:publish(path, key, data)\n body = JSON/stringify(data)\n if !is_string(body) or Buffer/byteLength(body) > 262144\n return Promise/reject(\"Longpoll message must be JSON within 262144 bytes\")\n return execute(\"publish\", path, key, null, body)\n\nLongpollBroker:cursor(path, key)\n return execute(\"cursor\", path, key, null, \"\")\n\nLongpollBroker:read(path, key, cursor)\n return execute(\"read\", path, key, cursor, \"\")\n\nLongpollBroker:execute(operation, path, key, cursor, body)\n item = route(path)\n if item == null\n return Promise/reject(\"Unknown longpoll path\")\n if !is_string(key) or key == \"\" or Buffer/byteLength(key) > 1024\n return Promise/reject(\"Longpoll key must contain 1 to 1024 bytes\")\n if @client == null or !@client.isReady\n return Promise/reject(\"RedisUnavailable\")\n hash = crypto/createHash(\"sha256\")\n hash.update(to_json([@settings.namespace, path, key]))\n channel = hash.digest(\"hex\")\n prefix = \"lango:longpoll:{${channel}}\"\n position = {\n generation: \"\"\n id: \"0-0\"\n }\n if cursor != null\n position = decode(cursor, channel)\n if position == null\n return Promise/resolve({\n resyncRequired: true\n })\n pending = @client.eval(@script, {\n keys: [\"${prefix}:stream\", \"${prefix}:meta\"]\n arguments: [operation, crypto/randomUUID(), \"${item.retentionMs}\", \"${item.maxMessages}\", position.generation, position.id, body]\n })\n return chain bounded(pending, 3000)\n then(raw)\n capture channel\n capture operation\n result = JSON/parse(raw)\n if result.resyncRequired == true\n return result\n result.cursor = encode(channel, result.generation, result.id)\n if operation != \"read\"\n return result.cursor\n messages = []\n if is_array(result.messages)\n for result.messages as message\n messages.add({\n id: encode(channel, result.generation, message.id)\n data: JSON/parse(message.data)\n })\n return {\n messages: messages\n cursor: result.cursor\n resyncRequired: false\n }\n\nencode(channel, generation, id)\n buffer = Buffer/from(to_json([channel, generation, id]))\n return buffer.toString(\"base64url\")\n\ndecode(cursor, channel)\n if !is_string(cursor) or cursor.length > 512\n return null\n try\n buffer = Buffer/from(cursor, \"base64url\")\n parts = from_json(buffer.toString(\"utf8\"))\n if !is_array(parts) or parts.length != 3 or parts[0] != channel or !is_string(parts[1]) or !is_string(parts[2])\n return null\n pattern = new RegExp(\"^(0|[1-9][0-9]{0,18})-(0|[1-9][0-9]{0,18})$\")\n if !pattern.test(parts[2]) or parts[2].length > 40\n return null\n return {\n generation: parts[1]\n id: parts[2]\n }\n catch error\n return null\n\nbounded(pending, ms)\n expired = Promise/withResolvers()\n fail = ()\n capture expired\n expired.reject(\"RedisUnavailable\")\n timer = setTimeout(fail, ms)\n return chain Promise/race([pending, expired.promise])\n finally\n capture timer\n clearTimeout(timer)\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAcA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmHA;;;;;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { policyOptions } from "./policy.mjs";
|
|
2
|
-
import {
|
|
3
|
-
hostGlobal as __hostGlobal,
|
|
4
|
-
hostGlobalCall as __hostGlobalCall,
|
|
5
|
-
isNumber as __isNumber,
|
|
6
|
-
isString as __isString,
|
|
7
|
-
isBool as __isBool,
|
|
8
|
-
isObject as __isObject,
|
|
9
|
-
isArray as __isArray,
|
|
10
|
-
entries as __entries,
|
|
11
|
-
requireBoolean as __requireBoolean,
|
|
12
|
-
normalize as __normalize,
|
|
13
|
-
boundary as __boundary,
|
|
14
|
-
requireArity as __requireArity,
|
|
15
|
-
} from "./.lango/runtime.mjs";
|
|
16
|
-
|
|
17
|
-
export function longpollOptions(spec) {
|
|
18
|
-
__requireArity(arguments.length, [0], "longpollOptions");
|
|
19
|
-
spec = __boundary(spec);
|
|
20
|
-
let result = { kind: "longpoll", path: __normalize(spec.path), auth: null, policy: null, reauthSeconds: 0, waitTimeoutMs: 20000, retentionMs: 300000, maxMessages: 1000, fallback: null };
|
|
21
|
-
for (const [key, value] of __entries(spec)) {
|
|
22
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(result, key)))) || __requireBoolean(key === "kind"))) {
|
|
23
|
-
throw `Unknown longpoll option: ${key}`;
|
|
24
|
-
}
|
|
25
|
-
result[key] = value;
|
|
26
|
-
}
|
|
27
|
-
let selected = policyOptions(result);
|
|
28
|
-
result.policy = __normalize(selected.name);
|
|
29
|
-
result.auth = __normalize(selected.name);
|
|
30
|
-
result.reauthSeconds = __normalize(selected.reauthSeconds);
|
|
31
|
-
result.reauthExplicit = __normalize(spec.reauthSeconds) !== null;
|
|
32
|
-
result.legacyAuth = __normalize(selected.legacy);
|
|
33
|
-
validPath(__normalize(result.path));
|
|
34
|
-
if (__requireBoolean(__normalize(result.fallback) !== null)) {
|
|
35
|
-
validPath(__normalize(result.fallback));
|
|
36
|
-
}
|
|
37
|
-
let limits = { waitTimeoutMs: 60000, retentionMs: 86400000, maxMessages: 10000 };
|
|
38
|
-
for (const [key, limit] of __entries(limits)) {
|
|
39
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isNumber(__normalize(result[key])))) && __requireBoolean(!__requireBoolean(__isString(__normalize(result[key])))))) {
|
|
40
|
-
throw `Invalid longpoll option: ${key}`;
|
|
41
|
-
}
|
|
42
|
-
let value = __hostGlobalCall(["Number"], __normalize(result[key]));
|
|
43
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isSafeInteger(value)))) || __requireBoolean(value < 1)) || __requireBoolean(value > limit))) {
|
|
44
|
-
throw `Invalid longpoll option: ${key}`;
|
|
45
|
-
}
|
|
46
|
-
result[key] = value;
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function validPath(value) {
|
|
53
|
-
__requireArity(arguments.length, [0], "validPath");
|
|
54
|
-
value = __boundary(value);
|
|
55
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(value))) || __requireBoolean(!__requireBoolean(__normalize(value.startsWith("/"))))) || __requireBoolean(__normalize(value.includes("*")))) || __requireBoolean(__normalize(value.includes("{")))) || __requireBoolean(__normalize(value.includes("}")))) || __requireBoolean(__normalize(value.includes("?")))) || __requireBoolean(__normalize(value.includes("#")))) || __requireBoolean(__normalize(value.includes("\\")))) || __requireBoolean(__normalize(value.includes("//"))))) {
|
|
56
|
-
throw "Longpoll requires an exact absolute URL path";
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function redisOptions(spec) {
|
|
63
|
-
__requireArity(arguments.length, [0], "redisOptions");
|
|
64
|
-
spec = __boundary(spec);
|
|
65
|
-
if (__requireBoolean(spec === null)) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(spec))) || __requireBoolean(__isArray(spec)))) {
|
|
69
|
-
throw "Redis configuration must be a map";
|
|
70
|
-
}
|
|
71
|
-
let allowed = ["connectionEnv", "namespace", "maxPendingPolls"];
|
|
72
|
-
for (const [key, value] of __entries(spec)) {
|
|
73
|
-
if (__requireBoolean(!__requireBoolean(__normalize(allowed.includes(key))))) {
|
|
74
|
-
throw `Unknown Redis option: ${key}`;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.connectionEnv)))) || __requireBoolean(__normalize(spec.connectionEnv) === "")) || __requireBoolean(!__requireBoolean(__isString(__normalize(spec.namespace))))) || __requireBoolean(__normalize(spec.namespace) === "")) || __requireBoolean(spec.namespace.length > 128))) {
|
|
78
|
-
throw "Redis requires connectionEnv and namespace";
|
|
79
|
-
}
|
|
80
|
-
let name = __normalize(spec.connectionEnv);
|
|
81
|
-
let value = __normalize(__hostGlobal(["process"]).env[name]);
|
|
82
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(value))) || __requireBoolean(value === ""))) {
|
|
83
|
-
throw "Redis connection environment variable is missing";
|
|
84
|
-
}
|
|
85
|
-
let url = new (__hostGlobal(["URL"]))(value);
|
|
86
|
-
let protocols = ["redis:", "rediss:"];
|
|
87
|
-
if (__requireBoolean(!__requireBoolean(__normalize(protocols.includes(__normalize(url.protocol)))))) {
|
|
88
|
-
throw "Redis requires a redis:// or rediss:// URL";
|
|
89
|
-
}
|
|
90
|
-
let maximum = 1024;
|
|
91
|
-
if (__requireBoolean(__normalize(spec.maxPendingPolls) !== null)) {
|
|
92
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isNumber(__normalize(spec.maxPendingPolls)))) && __requireBoolean(!__requireBoolean(__isString(__normalize(spec.maxPendingPolls)))))) {
|
|
93
|
-
throw "Invalid Redis maxPendingPolls";
|
|
94
|
-
}
|
|
95
|
-
maximum = __hostGlobalCall(["Number"], __normalize(spec.maxPendingPolls));
|
|
96
|
-
}
|
|
97
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isSafeInteger(maximum)))) || __requireBoolean(maximum < 1)) || __requireBoolean(maximum > 10000))) {
|
|
98
|
-
throw "Invalid Redis maxPendingPolls";
|
|
99
|
-
}
|
|
100
|
-
return { connectionEnv: __normalize(spec.connectionEnv), namespace: __normalize(spec.namespace), maxPendingPolls: maximum };
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
//# sourceMappingURL=longpoll_options.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"longpoll_options.mjs","sources":["longpoll_options.lango"],"sourcesContent":["import \"./policy\"\n policyOptions(spec)\nimport js global Number\nimport js global Object\nimport js global process\nimport js global URL\n\nexport longpollOptions(spec)\nexport redisOptions(spec)\n\nlongpollOptions(spec)\n result = {\n kind: \"longpoll\"\n path: spec.path\n auth: null\n policy: null\n reauthSeconds: 0\n waitTimeoutMs: 20000\n retentionMs: 300000\n maxMessages: 1000\n fallback: null\n }\n for spec as key: value\n if !Object/hasOwn(result, key) or key == \"kind\"\n throw \"Unknown longpoll option: ${key}\"\n result[key] = value\n selected = policyOptions(result)\n result.policy = selected.name\n result.auth = selected.name\n result.reauthSeconds = selected.reauthSeconds\n result.reauthExplicit = spec.reauthSeconds != null\n result.legacyAuth = selected.legacy\n validPath(result.path)\n if result.fallback != null\n validPath(result.fallback)\n limits = {\n waitTimeoutMs: 60000\n retentionMs: 86400000\n maxMessages: 10000\n }\n for limits as key: limit\n if !is_number(result[key]) and !is_string(result[key])\n throw \"Invalid longpoll option: ${key}\"\n value = Number(result[key])\n if !Number/isSafeInteger(value) or value < 1 or value > limit\n throw \"Invalid longpoll option: ${key}\"\n result[key] = value\n return result\n\nvalidPath(value)\n if !is_string(value) or !value.startsWith(\"/\") or value.includes(\"*\") or value.includes(\"{\") or value.includes(\"}\") or value.includes(\"?\") or value.includes(\"#\") or value.includes(\"\\\\\") or value.includes(\"//\")\n throw \"Longpoll requires an exact absolute URL path\"\n return null\n\nredisOptions(spec)\n if spec == null\n return null\n if !is_object(spec) or is_array(spec)\n throw \"Redis configuration must be a map\"\n allowed = [\"connectionEnv\", \"namespace\", \"maxPendingPolls\"]\n for spec as key: value\n if !allowed.includes(key)\n throw \"Unknown Redis option: ${key}\"\n if !is_string(spec.connectionEnv) or spec.connectionEnv == \"\" or !is_string(spec.namespace) or spec.namespace == \"\" or spec.namespace.length > 128\n throw \"Redis requires connectionEnv and namespace\"\n name = spec.connectionEnv\n value = process.env[name]\n if !is_string(value) or value == \"\"\n throw \"Redis connection environment variable is missing\"\n url = new URL(value)\n protocols = [\"redis:\", \"rediss:\"]\n if !protocols.includes(url.protocol)\n throw \"Redis requires a redis:// or rediss:// URL\"\n maximum = 1024\n if spec.maxPendingPolls != null\n if !is_number(spec.maxPendingPolls) and !is_string(spec.maxPendingPolls)\n throw \"Invalid Redis maxPendingPolls\"\n maximum = Number(spec.maxPendingPolls)\n if !Number/isSafeInteger(maximum) or maximum < 1 or maximum > 10000\n throw \"Invalid Redis maxPendingPolls\"\n return {\n connectionEnv: spec.connectionEnv\n namespace: spec.namespace\n maxPendingPolls: maximum\n }\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA;;;;;;;;;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|