@lango-project/lango-server 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/README.md +22 -3
  2. package/dist/body_reader.mjs.map +1 -1
  3. package/dist/builder.mjs +26 -2
  4. package/dist/builder.mjs.map +1 -1
  5. package/dist/cli/server.mjs +3 -835
  6. package/dist/cli/server.mjs.map +1 -1
  7. package/dist/client_identity.mjs.map +1 -1
  8. package/dist/database.mjs.map +1 -1
  9. package/dist/database_action.mjs +71 -0
  10. package/dist/database_action.mjs.map +1 -0
  11. package/dist/database_options.mjs.map +1 -1
  12. package/dist/database_scope.mjs +11 -0
  13. package/dist/database_scope.mjs.map +1 -1
  14. package/dist/endpoint.mjs.map +1 -1
  15. package/dist/error_details.mjs.map +1 -1
  16. package/dist/execution_failure.mjs +30 -0
  17. package/dist/execution_failure.mjs.map +1 -0
  18. package/dist/execution_identity.mjs +103 -0
  19. package/dist/execution_identity.mjs.map +1 -0
  20. package/dist/execution_log.mjs +47 -0
  21. package/dist/execution_log.mjs.map +1 -0
  22. package/dist/execution_runtime.mjs +201 -0
  23. package/dist/execution_runtime.mjs.map +1 -0
  24. package/dist/execution_worker.mjs +41 -0
  25. package/dist/execution_worker.mjs.map +1 -0
  26. package/dist/executor.mjs +384 -0
  27. package/dist/executor.mjs.map +1 -0
  28. package/dist/group.mjs +15 -0
  29. package/dist/group.mjs.map +1 -1
  30. package/dist/http_failure.mjs.map +1 -1
  31. package/dist/job_configuration.mjs +37 -0
  32. package/dist/job_configuration.mjs.map +1 -0
  33. package/dist/job_context.mjs +61 -0
  34. package/dist/job_context.mjs.map +1 -0
  35. package/dist/library.mjs +31 -0
  36. package/dist/library.mjs.map +1 -1
  37. package/dist/longpoll_broker.mjs.map +1 -1
  38. package/dist/longpoll_options.mjs.map +1 -1
  39. package/dist/longpoll_session.mjs.map +1 -1
  40. package/dist/middleware.mjs +1 -1
  41. package/dist/middleware.mjs.map +1 -1
  42. package/dist/module_loader.mjs +44 -0
  43. package/dist/module_loader.mjs.map +1 -0
  44. package/dist/options.mjs +12 -1
  45. package/dist/options.mjs.map +1 -1
  46. package/dist/origin.mjs.map +1 -1
  47. package/dist/policy.mjs.map +1 -1
  48. package/dist/postgres_adapter.mjs +12 -1
  49. package/dist/postgres_adapter.mjs.map +1 -1
  50. package/dist/postgres_worker.mjs +67 -5
  51. package/dist/postgres_worker.mjs.map +1 -1
  52. package/dist/queue_provider.mjs +52 -0
  53. package/dist/queue_provider.mjs.map +1 -0
  54. package/dist/request_identity.mjs.map +1 -1
  55. package/dist/response.mjs.map +1 -1
  56. package/dist/route_info.mjs.map +1 -1
  57. package/dist/route_pattern.mjs.map +1 -1
  58. package/dist/routes.mjs +36 -1
  59. package/dist/routes.mjs.map +1 -1
  60. package/dist/runtime.mjs +65 -25
  61. package/dist/runtime.mjs.map +1 -1
  62. package/dist/server.mjs +4 -1
  63. package/dist/server.mjs.map +1 -1
  64. package/dist/server_context.mjs.map +1 -1
  65. package/dist/sqlite_adapter.mjs.map +1 -1
  66. package/dist/static_files.mjs.map +1 -1
  67. package/dist/token.mjs.map +1 -1
  68. package/dist/tokens.mjs.map +1 -1
  69. package/dist/trace.mjs.map +1 -1
  70. package/dist/worker.mjs.map +1 -1
  71. package/docs/jobs.md +123 -0
  72. package/examples/security/package.json +1 -1
  73. package/package.json +10 -6
  74. package/src/builder.lango +22 -0
  75. package/src/database_action.lango +30 -0
  76. package/src/database_scope.lango +7 -0
  77. package/src/execution_failure.lango +14 -0
  78. package/src/execution_identity.lango +71 -0
  79. package/src/execution_log.lango +28 -0
  80. package/src/execution_runtime.lango +135 -0
  81. package/src/execution_worker.lango +32 -0
  82. package/src/executor.lango +284 -0
  83. package/src/group.lango +11 -0
  84. package/src/job_configuration.lango +29 -0
  85. package/src/job_context.lango +44 -0
  86. package/src/library.lango +21 -0
  87. package/src/middleware.lango +1 -1
  88. package/src/module_loader.lango +25 -0
  89. package/src/options.lango +7 -1
  90. package/src/postgres_adapter.lango +12 -0
  91. package/src/postgres_worker.lango +54 -3
  92. package/src/queue_provider.lango +30 -0
  93. package/src/routes.lango +44 -0
  94. package/src/runtime.lango +45 -17
  95. package/src/server.lango +3 -0
  96. package/dist/cli/.lango/bignumber.mjs +0 -3119
  97. package/dist/cli/.lango/localization.mjs +0 -108
  98. package/dist/cli/.lango/runtime.mjs +0 -725
  99. package/dist/cli/.lango/vendor/i18next.LICENSE +0 -21
  100. package/dist/cli/.lango/vendor/i18next.mjs +0 -2434
  101. package/dist/cli/.lango/xmldom/conventions.js +0 -429
  102. package/dist/cli/.lango/xmldom/dom-parser.js +0 -591
  103. package/dist/cli/.lango/xmldom/dom.js +0 -3759
  104. package/dist/cli/.lango/xmldom/entities.js +0 -2171
  105. package/dist/cli/.lango/xmldom/errors.js +0 -205
  106. package/dist/cli/.lango/xmldom/grammar.js +0 -559
  107. package/dist/cli/.lango/xmldom/index.js +0 -41
  108. package/dist/cli/.lango/xmldom/package.json +0 -1
  109. package/dist/cli/.lango/xmldom/sax.js +0 -983
  110. package/dist/cli/.lango/xmldom.LICENSE.md +0 -8
  111. package/dist/cli/body_reader.mjs +0 -180
  112. package/dist/cli/body_reader.mjs.map +0 -1
  113. package/dist/cli/client_identity.mjs +0 -250
  114. package/dist/cli/client_identity.mjs.map +0 -1
  115. package/dist/cli/database.mjs +0 -116
  116. package/dist/cli/database.mjs.map +0 -1
  117. package/dist/cli/database_options.mjs +0 -83
  118. package/dist/cli/database_options.mjs.map +0 -1
  119. package/dist/cli/database_scope.mjs +0 -82
  120. package/dist/cli/database_scope.mjs.map +0 -1
  121. package/dist/cli/endpoint.mjs +0 -50
  122. package/dist/cli/endpoint.mjs.map +0 -1
  123. package/dist/cli/error_details.mjs +0 -45
  124. package/dist/cli/error_details.mjs.map +0 -1
  125. package/dist/cli/longpoll_broker.mjs +0 -215
  126. package/dist/cli/longpoll_broker.mjs.map +0 -1
  127. package/dist/cli/longpoll_options.mjs +0 -103
  128. package/dist/cli/longpoll_options.mjs.map +0 -1
  129. package/dist/cli/longpoll_session.mjs +0 -136
  130. package/dist/cli/longpoll_session.mjs.map +0 -1
  131. package/dist/cli/middleware.mjs +0 -25
  132. package/dist/cli/middleware.mjs.map +0 -1
  133. package/dist/cli/options.mjs +0 -203
  134. package/dist/cli/options.mjs.map +0 -1
  135. package/dist/cli/origin.mjs +0 -87
  136. package/dist/cli/origin.mjs.map +0 -1
  137. package/dist/cli/policy.mjs +0 -121
  138. package/dist/cli/policy.mjs.map +0 -1
  139. package/dist/cli/postgres_adapter.mjs +0 -167
  140. package/dist/cli/postgres_adapter.mjs.map +0 -1
  141. package/dist/cli/route_pattern.mjs +0 -129
  142. package/dist/cli/route_pattern.mjs.map +0 -1
  143. package/dist/cli/routes.mjs +0 -325
  144. package/dist/cli/routes.mjs.map +0 -1
  145. package/dist/cli/sqlite_adapter.mjs +0 -163
  146. package/dist/cli/sqlite_adapter.mjs.map +0 -1
  147. package/dist/cli/static_files.mjs +0 -224
  148. package/dist/cli/static_files.mjs.map +0 -1
  149. package/dist/cli/trace.mjs +0 -53
  150. package/dist/cli/trace.mjs.map +0 -1
package/dist/group.mjs CHANGED
@@ -74,6 +74,21 @@ export class Group {
74
74
  return this;
75
75
  return null;
76
76
  }
77
+ job(spec) {
78
+ __requireArity(arguments.length, [0], "job");
79
+ spec = __boundary(spec);
80
+ let item = this.#merged(spec);
81
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(item.path)))) || __requireBoolean(!__requireBoolean(__normalize(item.path.startsWith("/")))))) {
82
+ throw "Job path must begin with /";
83
+ }
84
+ item.path = `${__normalize(this.#prefix)}${__normalize(item.path)}`;
85
+ if (__requireBoolean(__normalize(item.module) === null)) {
86
+ item.module = __normalize(this.#module);
87
+ }
88
+ __normalize(this.#routes.job(item));
89
+ return this;
90
+ return null;
91
+ }
77
92
  group(spec) {
78
93
  __requireArity(arguments.length, [0], "group");
79
94
  spec = __boundary(spec);
@@ -1 +1 @@
1
- {"version":3,"file":"group.mjs","sources":["group.lango"],"sourcesContent":["import js global Object\n\nexport class Group(routes, spec, prefix = \"\", inheritedModule = null, inheritedAuth = null, inheritedPolicy = null, inheritedReauthSeconds = null)\n methods\n endpoint(spec)\n longpoll(spec)\n group(spec)\n include(spec)\n\nGroup(routes, spec, prefix = \"\", inheritedModule = null, inheritedAuth = null, inheritedPolicy = null, inheritedReauthSeconds = null)\n if !is_string(spec.path) or !spec.path.startsWith(\"/\") or spec.path.endsWith(\"/\") or spec.path.includes(\"*\")\n throw \"Group requires a path without a trailing slash or wildcard\"\n @routes = routes\n @prefix = \"${prefix}${spec.path}\"\n @module = spec.module\n @auth = spec.auth\n @policy = spec.policy\n @reauthSeconds = spec.reauthSeconds\n if @module == null\n @module = inheritedModule\n if @auth == null and @policy == null\n @auth = inheritedAuth\n @policy = inheritedPolicy\n if @reauthSeconds == null\n @reauthSeconds = inheritedReauthSeconds\n\nGroup:endpoint(spec)\n if !is_string(spec.path) or !spec.path.startsWith(\"/\")\n throw \"Endpoint path must begin with /\"\n item = merged(spec)\n item.path = \"${@prefix}${spec.path}\"\n if item.module == null\n item.module = @module\n @routes.endpoint(item)\n return @this\n\nGroup:longpoll(spec)\n item = merged(spec)\n item.path = \"${@prefix}${spec.path}\"\n if item.fallback != null\n item.fallback = \"${@prefix}${item.fallback}\"\n @routes.longpoll(item)\n return @this\n\nGroup:group(spec)\n return new Group(@routes, spec, @prefix, @module, @auth, @policy, @reauthSeconds)\n\nGroup:include(spec)\n mount = spec.path\n if mount == null\n mount = \"/\"\n @routes.include({\n module: spec.module\n path: \"${@prefix}${mount}\"\n }, @auth, @policy, @reauthSeconds)\n return @this\n\nGroup:merged(spec)\n item = Object/assign({}, spec)\n if item.auth == null and item.policy == null\n item.auth = @auth\n item.policy = @policy\n if item.reauthSeconds == null\n item.reauthSeconds = @reauthSeconds\n return item\n"],"names":[],"mappings":";;;;;;;;;;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"group.mjs","sources":["group.lango"],"sourcesContent":["import js global Object\n\nexport class Group(routes, spec, prefix = \"\", inheritedModule = null, inheritedAuth = null, inheritedPolicy = null, inheritedReauthSeconds = null)\n methods\n endpoint(spec)\n job(spec)\n longpoll(spec)\n group(spec)\n include(spec)\n\nGroup(routes, spec, prefix = \"\", inheritedModule = null, inheritedAuth = null, inheritedPolicy = null, inheritedReauthSeconds = null)\n if !is_string(spec.path) or !spec.path.startsWith(\"/\") or spec.path.endsWith(\"/\") or spec.path.includes(\"*\")\n throw \"Group requires a path without a trailing slash or wildcard\"\n @routes = routes\n @prefix = \"${prefix}${spec.path}\"\n @module = spec.module\n @auth = spec.auth\n @policy = spec.policy\n @reauthSeconds = spec.reauthSeconds\n if @module == null\n @module = inheritedModule\n if @auth == null and @policy == null\n @auth = inheritedAuth\n @policy = inheritedPolicy\n if @reauthSeconds == null\n @reauthSeconds = inheritedReauthSeconds\n\nGroup:endpoint(spec)\n if !is_string(spec.path) or !spec.path.startsWith(\"/\")\n throw \"Endpoint path must begin with /\"\n item = merged(spec)\n item.path = \"${@prefix}${spec.path}\"\n if item.module == null\n item.module = @module\n @routes.endpoint(item)\n return @this\n\nGroup:longpoll(spec)\n item = merged(spec)\n item.path = \"${@prefix}${spec.path}\"\n if item.fallback != null\n item.fallback = \"${@prefix}${item.fallback}\"\n @routes.longpoll(item)\n return @this\n\nGroup:job(spec)\n item = merged(spec)\n if !is_string(item.path) or !item.path.startsWith(\"/\")\n throw \"Job path must begin with /\"\n item.path = \"${@prefix}${item.path}\"\n if item.module == null\n item.module = @module\n @routes.job(item)\n return @this\n\nGroup:group(spec)\n return new Group(@routes, spec, @prefix, @module, @auth, @policy, @reauthSeconds)\n\nGroup:include(spec)\n mount = spec.path\n if mount == null\n mount = \"/\"\n @routes.include({\n module: spec.module\n path: \"${@prefix}${mount}\"\n }, @auth, @policy, @reauthSeconds)\n return @this\n\nGroup:merged(spec)\n item = Object/assign({}, spec)\n if item.auth == null and item.policy == null\n item.auth = @auth\n item.policy = @policy\n if item.reauthSeconds == null\n item.reauthSeconds = @reauthSeconds\n return item\n"],"names":[],"mappings":";;;;;;;;;;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"1896e5f0aaba61aa3a5b25866e7d6a74a0375b243997b61d2e1f8979a843ee66","outputHash":"01e971cedc68329978f494d8969b68e080e81c3cd377208ab947f6ef3dff7ef8","mapHash":"f36ef1b37d33c5202fbe9d79c3b7aa8a4a6878fa26495b1d5622ee4b665e54b3"}}
@@ -1 +1 @@
1
- {"version":3,"file":"http_failure.mjs","sources":["http_failure.lango"],"sourcesContent":["import js global RegExp\n\nexport class HttpFailure(status, code, headers, details = null)\n methods\n result()\n\nHttpFailure(status, code, headers, details = null)\n if !is_number(status) or status % 1 != 0 or status < 400 or status > 599\n throw \"Rejected response requires an error status\"\n pattern = new RegExp(\"^[A-Za-z][A-Za-z0-9_]{0,63}$\")\n if !is_string(code) or !pattern.test(code)\n throw \"Rejected response requires an error code\"\n @details = details\n @status = status\n @code = code\n @headers = from_json(to_json(headers))\n if status == 401\n @headers[\"www-authenticate\"] = \"Bearer\"\n\nHttpFailure:result()\n body = {\n error: @code\n }\n if @details != null\n body.needLogin = @details\n return {\n status: @status\n headers: from_json(to_json(@headers))\n body: to_json(body)\n }\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"http_failure.mjs","sources":["http_failure.lango"],"sourcesContent":["import js global RegExp\n\nexport class HttpFailure(status, code, headers, details = null)\n methods\n result()\n\nHttpFailure(status, code, headers, details = null)\n if !is_number(status) or status % 1 != 0 or status < 400 or status > 599\n throw \"Rejected response requires an error status\"\n pattern = new RegExp(\"^[A-Za-z][A-Za-z0-9_]{0,63}$\")\n if !is_string(code) or !pattern.test(code)\n throw \"Rejected response requires an error code\"\n @details = details\n @status = status\n @code = code\n @headers = from_json(to_json(headers))\n if status == 401\n @headers[\"www-authenticate\"] = \"Bearer\"\n\nHttpFailure:result()\n body = {\n error: @code\n }\n if @details != null\n body.needLogin = @details\n return {\n status: @status\n headers: from_json(to_json(@headers))\n body: to_json(body)\n }\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"27bf4949d8254e0e3b9ad6f1b2dbec24cd53246ca82121b35bb97a527da3bea6","outputHash":"117f8ad9e45f7e19015c7b6d09c5ec74c0319f44013f2a3f69aefc23e5081a8c","mapHash":"bd5784a1a45f1f8e01469edc5bcee77afc9ffc63dd91bf5bd71fd02b94910117"}}
@@ -0,0 +1,37 @@
1
+ import { readDeployment } from "./options.mjs";
2
+ import { databaseOptions } from "./database_options.mjs";
3
+ import { Routes } from "./routes.mjs";
4
+ import { policyRegistry, resolvePolicies } from "./policy.mjs";
5
+ import * as path from "node:path";
6
+ import {
7
+ hostGlobalCall as __hostGlobalCall,
8
+ requireBoolean as __requireBoolean,
9
+ normalize as __normalize,
10
+ boundary as __boundary,
11
+ requireArity as __requireArity,
12
+ } from "./.lango/runtime.mjs";
13
+
14
+ export function readDatabaseConfiguration(directory) {
15
+ __requireArity(arguments.length, [0], "readDatabaseConfiguration");
16
+ directory = __boundary(directory);
17
+ let root = __normalize(path.resolve(directory));
18
+ let settings = readDeployment(root, false);
19
+ let workers = 2;
20
+ if (__requireBoolean(__normalize(settings.workers) !== null)) {
21
+ workers = __hostGlobalCall(["Number"], __normalize(settings.workers));
22
+ }
23
+ return databaseOptions(root, __normalize(settings.database), workers);
24
+ return null;
25
+ }
26
+
27
+ export function readJobRoutes(directory) {
28
+ __requireArity(arguments.length, [0], "readJobRoutes");
29
+ directory = __boundary(directory);
30
+ let root = __normalize(path.resolve(directory));
31
+ let settings = readDeployment(root, false);
32
+ let routes = new Routes(root);
33
+ __normalize(routes.xml(__normalize(path.join(root, "routes.xml"))));
34
+ return resolvePolicies(__normalize(routes.jobs()), policyRegistry(__normalize(settings.policies)));
35
+ return null;
36
+ }
37
+ //# sourceMappingURL=job_configuration.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job_configuration.mjs","sources":["job_configuration.lango"],"sourcesContent":["import \"./options\"\n readDeployment(directory, credentials = true)\nimport \"./database_options\"\n databaseOptions(root, spec, workers)\nimport \"./routes\"\n class Routes\nimport \"./policy\"\n policyRegistry(spec)\n resolvePolicies(routes, registry)\nimport js \"node:path\" as path\nimport js global Number\n\nexport readDatabaseConfiguration(directory)\nexport readJobRoutes(directory)\n\nreadDatabaseConfiguration(directory)\n root = path/resolve(directory)\n settings = readDeployment(root, false)\n workers = 2\n if settings.workers != null\n workers = Number(settings.workers)\n return databaseOptions(root, settings.database, workers)\n\nreadJobRoutes(directory)\n root = path/resolve(directory)\n settings = readDeployment(root, false)\n routes = new Routes(root)\n routes.xml(path/join(root, \"routes.xml\"))\n return resolvePolicies(routes.jobs(), policyRegistry(settings.policies))\n"],"names":[],"mappings":";;;;;;;;;;;;;AAeA;;;;;;;;;;;;;AAQA;;;;;;;;;;;","x_lango_build":{"fingerprint":"c1cd5d1e6ae0bbdd595b433c524059744c6683db3e9f615ffe0e77f6be699192","outputHash":"2dee9fb653491ea9fa095988ce01e36acab613710725b05d5a5b514deb4070c7","mapHash":"2a3d582a9d1c731374cbb495cb59b65a3a3c066465f1a446028b3b92b73991c2"}}
@@ -0,0 +1,61 @@
1
+ import { ExecutionFailure } from "./execution_failure.mjs";
2
+ import {
3
+ hostGlobal as __hostGlobal,
4
+ fromJson as __fromJson,
5
+ toJson as __toJson,
6
+ normalize as __normalize,
7
+ boundary as __boundary,
8
+ requireArity as __requireArity,
9
+ } from "./.lango/runtime.mjs";
10
+
11
+ export class JobContext {
12
+ #id;
13
+ #path;
14
+ #queue;
15
+ #attempt;
16
+ #source;
17
+ #checking;
18
+ constructor(task, route) {
19
+ __requireArity(arguments.length, [0, 1], "constructor");
20
+ task = __boundary(task);
21
+ route = __boundary(route);
22
+ this.#id = __normalize(task.id);
23
+ this.#path = __normalize(route.path);
24
+ this.#queue = __normalize(route.queue);
25
+ this.#attempt = __normalize(task.attempt);
26
+ this.#source = __fromJson(__toJson(__normalize(task.source)));
27
+ this.#checking = __normalize(task.authorize) === true;
28
+ __normalize(__hostGlobal(["Object"]).freeze(this));
29
+ }
30
+ get id() {
31
+ return __normalize(this.#id);
32
+ return null;
33
+ }
34
+ get path() {
35
+ return __normalize(this.#path);
36
+ return null;
37
+ }
38
+ get queue() {
39
+ return __normalize(this.#queue);
40
+ return null;
41
+ }
42
+ get attempt() {
43
+ return __normalize(this.#attempt);
44
+ return null;
45
+ }
46
+ get source() {
47
+ return __fromJson(__toJson(__normalize(this.#source)));
48
+ return null;
49
+ }
50
+ get checking() {
51
+ return __normalize(this.#checking);
52
+ return null;
53
+ }
54
+ reject(code) {
55
+ __requireArity(arguments.length, [0], "reject");
56
+ code = __boundary(code);
57
+ throw new ExecutionFailure(code);
58
+ return null;
59
+ }
60
+ }
61
+ //# sourceMappingURL=job_context.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job_context.mjs","sources":["job_context.lango"],"sourcesContent":["import \"./execution_failure\"\n class ExecutionFailure\nimport js global Object\n\nexport class JobContext(task, route)\n properties\n id?\n path?\n queue?\n attempt?\n source?\n checking?\n methods\n reject(code)\n\nJobContext(task, route)\n @id = task.id\n @path = route.path\n @queue = route.queue\n @attempt = task.attempt\n @source = from_json(to_json(task.source))\n @checking = task.authorize == true\n Object/freeze(@this)\n\nJobContext:id?\n return @id\n\nJobContext:path?\n return @path\n\nJobContext:queue?\n return @queue\n\nJobContext:attempt?\n return @attempt\n\nJobContext:source?\n return from_json(to_json(@source))\n\nJobContext:checking?\n return @checking\n\nJobContext:reject(code)\n throw new ExecutionFailure(code)\n"],"names":[],"mappings":";;;;;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"f1ff20c8ed9cd25f37b820c52c20d681401d748d64abcd105106dee3e671c653","outputHash":"4d4a079ab03f8781796aa5b233a6debe2d6b5ac76907364afb31affb9b3d2d32","mapHash":"59e986c40d0fd842903785e288cd23c23c13f49793a73e15e67a47806e123d5a"}}
package/dist/library.mjs CHANGED
@@ -1,6 +1,37 @@
1
1
  import { Server as ServerClass } from "./server.mjs";
2
2
  import { Builder as BuilderClass } from "./builder.mjs";
3
+ import { Executor as ExecutorClass } from "./executor.mjs";
4
+ import { withDatabase as databaseAction } from "./database_action.mjs";
5
+ import { readDatabaseConfiguration as databaseConfig, readJobRoutes as jobRoutes } from "./job_configuration.mjs";
6
+ import {
7
+ boundary as __boundary,
8
+ requireArity as __requireArity,
9
+ } from "./.lango/runtime.mjs";
10
+
3
11
  export let Server = ServerClass;
4
12
 
5
13
  export let Builder = BuilderClass;
14
+
15
+ export let Executor = ExecutorClass;
16
+ export function readDatabaseConfiguration(directory) {
17
+ __requireArity(arguments.length, [0], "readDatabaseConfiguration");
18
+ directory = __boundary(directory);
19
+ return databaseConfig(directory);
20
+ return null;
21
+ }
22
+
23
+ export function readJobRoutes(directory) {
24
+ __requireArity(arguments.length, [0], "readJobRoutes");
25
+ directory = __boundary(directory);
26
+ return jobRoutes(directory);
27
+ return null;
28
+ }
29
+
30
+ export function withDatabase(directory, action) {
31
+ __requireArity(arguments.length, [0, 1], "withDatabase");
32
+ directory = __boundary(directory);
33
+ action = __boundary(action);
34
+ return databaseAction(directory, action);
35
+ return null;
36
+ }
6
37
  //# sourceMappingURL=library.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"library.mjs","sources":["library.lango"],"sourcesContent":["import \"./server\"\n alias ServerClass = class Server\nimport \"./builder\"\n alias BuilderClass = class Builder\n\nexport global Server\nexport global Builder\n\nglobal Server = ServerClass\nglobal Builder = BuilderClass\n"],"names":[],"mappings":";;AAQA;;AACA;;"}
1
+ {"version":3,"file":"library.mjs","sources":["library.lango"],"sourcesContent":["import \"./server\"\n alias ServerClass = class Server\nimport \"./builder\"\n alias BuilderClass = class Builder\nimport \"./executor\"\n alias ExecutorClass = class Executor\nimport \"./database_action\"\n alias databaseAction = withDatabase(directory, action)\nimport \"./job_configuration\"\n alias databaseConfig = readDatabaseConfiguration(directory)\n alias jobRoutes = readJobRoutes(directory)\n\nexport global Server\nexport global Builder\nexport global Executor\nexport readDatabaseConfiguration(directory)\nexport readJobRoutes(directory)\nexport withDatabase(directory, action)\n\nglobal Server = ServerClass\nglobal Builder = BuilderClass\nglobal Executor = ExecutorClass\n\nreadDatabaseConfiguration(directory)\n return databaseConfig(directory)\n\nreadJobRoutes(directory)\n return jobRoutes(directory)\n\nwithDatabase(directory, action)\n return databaseAction(directory, action)\n"],"names":[],"mappings":";;;;;;;;;;AAmBA;;AACA;;AACA;AAEA;;;;;;;AAGA;;;;;;;AAGA;;;;;;;;","x_lango_build":{"fingerprint":"eac8c6b43092a37fe896941966402abedfef9275ba521f0ac5aeb34dc5134638","outputHash":"b6181148ec7d5e5879f8c0e7f0d37fb50b36d9a232f5a05d27a1972e7618cd44","mapHash":"fd2ce25041c5caefaf615924fcf0a370a2aaa195749ff1cda8f897097e7c93a2"}}
@@ -1 +1 @@
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
+ {"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;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"5ebf17dce85e355d34708776bf0765790de340a6386f9fe5a8482ac76f51cd90","outputHash":"30e19fe75f51fb8ac48fecc7e6dec5bfbd36c1333eedc7acf15d88624cd08b19","mapHash":"af20743f7c15bf4472f4c08d33aee5ea6895a4303a5de814d09e9c0ab9156979"}}
@@ -1 +1 @@
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"b848ea68a34ab1b604ac91b94fe591f18c805cf7996a8afe39e51cfaaad742ec","outputHash":"979695cdd0b98c95d81056cc1a4b310fa3f79ec8ee69e8c9ed419d3c67c98ee6","mapHash":"6d8aae83b12acab200293774c5cf82c2d33da2c856910f0cb947099b1be98c55"}}
@@ -1 +1 @@
1
- {"version":3,"file":"longpoll_session.mjs","sources":["longpoll_session.lango"],"sourcesContent":["import js global Promise\nimport js global Buffer\nimport js global Date\nimport js global Math\nimport js global setTimeout\nimport js global clearTimeout\n\nexport class LongpollSession(broker, route, authorize, body)\n methods\n run()\n cancel()\n\nLongpollSession(broker, route, authorize, body)\n @broker = broker\n @route = route\n @authorize = authorize\n @body = body\n @cancelled = false\n @timer = null\n @sleep = null\n @token = null\n @deadline = 0\n @input = null\n @cursor = null\n\nLongpollSession:cancel()\n @cancelled = true\n clearTimeout(@timer)\n if @sleep != null\n @sleep.resolve(null)\n return null\n\nLongpollSession:run()\n try\n @input = from_json(@body)\n input = @input\n if !is_object(input) or is_array(input) or !is_string(input.key) or input.key == \"\" or Buffer/byteLength(input.key) > 1024\n return Promise/resolve(failure(400, \"InvalidLongpollInput\"))\n if input.cursor != null and (!is_string(input.cursor) or input.cursor.length > 512)\n return Promise/resolve(failure(400, \"InvalidLongpollInput\"))\n @cursor = input.cursor\n catch error\n return Promise/resolve(failure(400, \"InvalidJson\"))\n auth = @authorize\n return chain auth(null, null)\n then(result)\n if result.status != 200\n return result\n @token = result.authorization\n @deadline = Date/now() + @route.waitTimeoutMs\n return poll()\n catch(error)\n return failure(503, \"LongpollUnavailable\")\n finally\n cancel()\n\nLongpollSession:poll()\n if @cancelled\n return Promise/resolve(failure(503, \"Unavailable\"))\n return chain @broker.read(@route.path, @input.key, @cursor)\n then(batch)\n if @cancelled\n return failure(503, \"Unavailable\")\n if batch.resyncRequired or batch.messages.length > 0 or Date/now() >= @deadline\n if batch.resyncRequired\n batch.fallback = @route.fallback\n auth = @authorize\n return auth(@token, batch)\n @cursor = batch.cursor\n @sleep = Promise/withResolvers()\n sleep = @sleep\n wake = ()\n capture sleep\n sleep.resolve(null)\n @timer = setTimeout(wake, Math/min(250, Math/max(1, @deadline - Date/now())))\n return chain sleep.promise\n then(ignored)\n return poll()\n\nfailure(status, code)\n return {\n status: status\n headers: {\n \"content-type\": \"application/json; charset=utf-8\"\n \"cache-control\": \"no-store\"\n }\n body: to_json({\n error: code\n })\n }\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA;;;;;;;;"}
1
+ {"version":3,"file":"longpoll_session.mjs","sources":["longpoll_session.lango"],"sourcesContent":["import js global Promise\nimport js global Buffer\nimport js global Date\nimport js global Math\nimport js global setTimeout\nimport js global clearTimeout\n\nexport class LongpollSession(broker, route, authorize, body)\n methods\n run()\n cancel()\n\nLongpollSession(broker, route, authorize, body)\n @broker = broker\n @route = route\n @authorize = authorize\n @body = body\n @cancelled = false\n @timer = null\n @sleep = null\n @token = null\n @deadline = 0\n @input = null\n @cursor = null\n\nLongpollSession:cancel()\n @cancelled = true\n clearTimeout(@timer)\n if @sleep != null\n @sleep.resolve(null)\n return null\n\nLongpollSession:run()\n try\n @input = from_json(@body)\n input = @input\n if !is_object(input) or is_array(input) or !is_string(input.key) or input.key == \"\" or Buffer/byteLength(input.key) > 1024\n return Promise/resolve(failure(400, \"InvalidLongpollInput\"))\n if input.cursor != null and (!is_string(input.cursor) or input.cursor.length > 512)\n return Promise/resolve(failure(400, \"InvalidLongpollInput\"))\n @cursor = input.cursor\n catch error\n return Promise/resolve(failure(400, \"InvalidJson\"))\n auth = @authorize\n return chain auth(null, null)\n then(result)\n if result.status != 200\n return result\n @token = result.authorization\n @deadline = Date/now() + @route.waitTimeoutMs\n return poll()\n catch(error)\n return failure(503, \"LongpollUnavailable\")\n finally\n cancel()\n\nLongpollSession:poll()\n if @cancelled\n return Promise/resolve(failure(503, \"Unavailable\"))\n return chain @broker.read(@route.path, @input.key, @cursor)\n then(batch)\n if @cancelled\n return failure(503, \"Unavailable\")\n if batch.resyncRequired or batch.messages.length > 0 or Date/now() >= @deadline\n if batch.resyncRequired\n batch.fallback = @route.fallback\n auth = @authorize\n return auth(@token, batch)\n @cursor = batch.cursor\n @sleep = Promise/withResolvers()\n sleep = @sleep\n wake = ()\n capture sleep\n sleep.resolve(null)\n @timer = setTimeout(wake, Math/min(250, Math/max(1, @deadline - Date/now())))\n return chain sleep.promise\n then(ignored)\n return poll()\n\nfailure(status, code)\n return {\n status: status\n headers: {\n \"content-type\": \"application/json; charset=utf-8\"\n \"cache-control\": \"no-store\"\n }\n body: to_json({\n error: code\n })\n }\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA;;;;;;;;","x_lango_build":{"fingerprint":"0cf102527804f5168ee6fbc4fd1614bec4e248adc19e3e24fa91f71645b195d8","outputHash":"f9ab2246c452536f330b55c20ab2a9b2b79343dc051d2daa4292d176881e246a","mapHash":"0f02e054d45d5014df0572ce58e6e8a61d7d0dba11d84754d38df91f3cf1b584"}}
@@ -14,7 +14,7 @@ import {
14
14
  export function middlewareName(name) {
15
15
  __requireArity(arguments.length, [0], "middlewareName");
16
16
  name = __boundary(name);
17
- let reserved = ["routes", "endpoint", "longpoll", "group", "include", "event", "middleware"];
17
+ let reserved = ["routes", "endpoint", "longpoll", "job", "group", "include", "event", "middleware"];
18
18
  let pattern = new (__hostGlobal(["RegExp"]))("^[A-Za-z_][A-Za-z0-9_-]*$");
19
19
  if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(name))) || __requireBoolean(!__requireBoolean(__normalize(pattern.test(name))))) || __requireBoolean(__normalize(reserved.includes(name))))) {
20
20
  throw `Invalid or reserved middleware name: ${name}`;
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.mjs","sources":["middleware.lango"],"sourcesContent":["import js global RegExp\n\nexport middlewareName(name)\n\nmiddlewareName(name)\n reserved = [\"routes\", \"endpoint\", \"longpoll\", \"group\", \"include\", \"event\", \"middleware\"]\n pattern = new RegExp(\"^[A-Za-z_][A-Za-z0-9_-]*$\")\n if !is_string(name) or !pattern.test(name) or reserved.includes(name)\n throw \"Invalid or reserved middleware name: ${name}\"\n return name\n"],"names":[],"mappings":";;;;;;;;;;;;;AAIA;;;;;;;;;;;;"}
1
+ {"version":3,"file":"middleware.mjs","sources":["middleware.lango"],"sourcesContent":["import js global RegExp\n\nexport middlewareName(name)\n\nmiddlewareName(name)\n reserved = [\"routes\", \"endpoint\", \"longpoll\", \"job\", \"group\", \"include\", \"event\", \"middleware\"]\n pattern = new RegExp(\"^[A-Za-z_][A-Za-z0-9_-]*$\")\n if !is_string(name) or !pattern.test(name) or reserved.includes(name)\n throw \"Invalid or reserved middleware name: ${name}\"\n return name\n"],"names":[],"mappings":";;;;;;;;;;;;;AAIA;;;;;;;;;;;;","x_lango_build":{"fingerprint":"10ecd19f49d610950fe5226367e8e6875ac3e95d77671b9218c2944b218d5dae","outputHash":"f2b374149ea746d208728bff2d14b9d920b3c7240d3925f5dd0f44b82f6a91cf","mapHash":"6d4418532baeceb103cf175b1016dae86429ac997a4696bba43d628136b70295"}}
@@ -0,0 +1,44 @@
1
+ import {
2
+ hostGlobal as __hostGlobal,
3
+ bindContexts as __bindContexts,
4
+ getClass as __getClass,
5
+ isKindof as __isKindof,
6
+ requireBoolean as __requireBoolean,
7
+ normalize as __normalize,
8
+ boundary as __boundary,
9
+ requireArity as __requireArity,
10
+ withArity as __withArity,
11
+ } from "./.lango/runtime.mjs";
12
+
13
+ export class ModuleLoader {
14
+ #modules;
15
+ constructor() {
16
+ this.#modules = __normalize(__hostGlobal(["Object"]).create(null));
17
+ }
18
+ target(spec) {
19
+ __requireArity(arguments.length, [0], "target");
20
+ spec = __boundary(spec);
21
+ let file = __normalize(spec.module);
22
+ if (__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(__normalize(this.#modules), file)))) {
23
+ return __normalize(__hostGlobal(["Promise"]).resolve(exported(__normalize(this.#modules[file]), __normalize(spec.handler))));
24
+ }
25
+ return import(file).then(__withArity(__bindContexts((mod) => {
26
+ mod = __boundary(mod);
27
+ this.#modules[file] = mod;
28
+ return exported(mod, __normalize(spec.handler));
29
+ return null;
30
+ }), [0], "closure"));
31
+ return null;
32
+ }
33
+ }
34
+ function exported(mod, name) {
35
+ __requireArity(arguments.length, [0, 1], "exported");
36
+ mod = __boundary(mod);
37
+ name = __boundary(name);
38
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(mod, name)))) || __requireBoolean(!__requireBoolean(__isKindof(__normalize(mod[name]), Function))))) {
39
+ throw `Handler is not exported: ${name}`;
40
+ }
41
+ return __normalize(mod[name]);
42
+ return null;
43
+ }
44
+ //# sourceMappingURL=module_loader.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module_loader.mjs","sources":["module_loader.lango"],"sourcesContent":["import js global Object\nimport js global Promise\n\nexport class ModuleLoader()\n methods\n target(spec)\n\nModuleLoader()\n @modules = Object/create(null)\n\nModuleLoader:target(spec)\n file = spec.module\n if Object/hasOwn(@modules, file)\n return Promise/resolve(exported(@modules[file], spec.handler))\n return chain import_module(file)\n then(mod)\n capture file\n capture spec\n @modules[file] = mod\n return exported(mod, spec.handler)\n\nexported(mod, name)\n if !Object/hasOwn(mod, name) or !is_kindof(mod[name], Function)\n throw \"Handler is not exported: ${name}\"\n return mod[name]\n"],"names":[],"mappings":";;;;;;;;;;;;AAGA;;;;;;;;;;;;;;;;;;;;;AAkBA;;;;;;;;;;;","x_lango_build":{"fingerprint":"f9363cd7297a749a496a3ad1829a00fa66ba5208fbb9c0b3e6d561fac9da858c","outputHash":"c285ca92d6ce26a9b146ecc0d52c068badd94eac781892882a93614af89a5ec8","mapHash":"637bc9be83171ba4f68772a221cc176e92360adcc105efc81945be72c42b5189"}}
package/dist/options.mjs CHANGED
@@ -106,6 +106,14 @@ export function options(root, supplied = null) {
106
106
  export function deployment(directory) {
107
107
  __requireArity(arguments.length, [0], "deployment");
108
108
  directory = __boundary(directory);
109
+ return options(directory, readDeployment(directory));
110
+ return null;
111
+ }
112
+
113
+ export function readDeployment(directory, credentials = true) {
114
+ __requireArity(arguments.length, [0], "readDeployment");
115
+ directory = __boundary(directory);
116
+ credentials = __boundary(credentials);
109
117
  let file = __normalize(path.join(directory, "deploy.xml"));
110
118
  let root = __xml2obj(__normalize(fs.readFileSync(file, "utf8")));
111
119
  if (__requireBoolean(__normalize(root.tag()) !== "deploy")) {
@@ -160,6 +168,9 @@ export function deployment(directory) {
160
168
  continue;
161
169
  } else if (name === "jwt") {
162
170
  attributes(tag, ["issuer", "audience", "ttlSeconds", "keyEnv", "keysFile", "activeKeyId"]);
171
+ if (__requireBoolean(!__requireBoolean(credentials))) {
172
+ continue;
173
+ }
163
174
  } else {
164
175
  throw `Unknown deployment section: ${name}`;
165
176
  }
@@ -189,7 +200,7 @@ export function deployment(directory) {
189
200
  }
190
201
  }
191
202
  }
192
- return options(directory, settings);
203
+ return settings;
193
204
  return null;
194
205
  }
195
206
 
@@ -1 +1 @@
1
- {"version":3,"file":"options.mjs","sources":["options.lango"],"sourcesContent":["import \"./policy\"\n policyRegistry(spec)\nimport \"./client_identity\"\n clientOptions(spec, database, origin)\nimport \"./origin\"\n originOptions(spec)\nimport \"./longpoll_options\"\n redisOptions(spec)\nimport \"./database_options\"\n databaseOptions(root, spec, workers)\nimport \"./static_files\"\n staticOptions(root, spec)\nimport js \"node:fs\" as fs\nimport js \"node:path\" as path\nimport js global Object\nimport js global Number\nimport js global process\n\nexport contains(items, value)\nexport options(root, supplied = null)\nexport deployment(directory)\nexport attributes(tag, allowed)\n\nattributes(tag, allowed)\n for tag.attributes() as key: value\n if !allowed.includes(key)\n throw \"Unknown ${tag.tag()} attribute: ${key}\"\n return null\n\noptions(root, supplied = null)\n result = {\n root: path/resolve(root)\n host: \"127.0.0.1\"\n port: 3000\n workers: 2\n maxQueue: 64\n bodyLimit: 2097152\n bodyTimeoutMs: 30000\n requestTimeoutMs: 30000\n eventTimeoutMs: 5000\n startupTimeoutMs: 30000\n shutdownTimeoutMs: 30000\n issuer: \"lango-server\"\n audience: \"lango-client\"\n ttlSeconds: 900\n key: null\n keys: {}\n activeKeyId: \"current\"\n requestEvent: false\n database: null\n redis: null\n static: null\n origin: null\n client: null\n policies: null\n }\n if supplied != null\n for supplied as key: value\n if !Object/hasOwn(result, key) or key == \"root\"\n throw \"Unknown server option: ${key}\"\n result[key] = value\n if !is_string(result.host) or result.host == \"\"\n throw \"Host must be a nonempty string\"\n for [\"port\", \"workers\", \"maxQueue\", \"bodyLimit\", \"bodyTimeoutMs\", \"requestTimeoutMs\", \"eventTimeoutMs\", \"startupTimeoutMs\", \"shutdownTimeoutMs\", \"ttlSeconds\"] as key\n value = result[key]\n if !is_number(value) or !Number/isSafeInteger(value) or value < 0\n throw \"Invalid server option: ${key}\"\n if key != \"port\" and key != \"maxQueue\" and value == 0\n throw \"Server option must be positive: ${key}\"\n if key.endsWith(\"Ms\") and value > 2147483647\n throw \"Timeout exceeds timer limit: ${key}\"\n if result.port > 65535 or result.workers > 128 or result.ttlSeconds > 86400\n throw \"Server option exceeds supported limit\"\n if !is_bool(result.requestEvent)\n throw \"requestEvent must be boolean\"\n for [\"issuer\", \"audience\", \"activeKeyId\"] as key\n if !is_string(result[key]) or result[key] == \"\"\n throw \"Missing JWT option: ${key}\"\n if !is_object(result.keys) or is_array(result.keys)\n throw \"JWT keys must be a map\"\n keys = Object/assign(Object/create(null), result.keys)\n if result.key != null\n keys[result.activeKeyId] = result.key\n if !Object/hasOwn(keys, result.activeKeyId)\n throw \"JWT signing key is required\"\n for keys as id: secret\n if !is_string(secret) or secret.length < 32\n throw \"JWT keys must contain at least 32 characters\"\n result.keys = keys\n result.key = null\n result.policies = policyRegistry(result.policies)\n result.database = databaseOptions(result.root, result.database, result.workers)\n result.redis = redisOptions(result.redis)\n result.static = staticOptions(result.root, result.static)\n result.origin = originOptions(result.origin)\n result.client = clientOptions(result.client, result.database, result.origin)\n return result\n\ndeployment(directory)\n file = path/join(directory, \"deploy.xml\")\n root = xml2obj(fs/readFileSync(file, \"utf8\"))\n if root.tag() != \"deploy\"\n throw \"Expected deploy root\"\n attributes(root, [])\n settings = {}\n seen = []\n for root.children() as tag\n name = tag.tag()\n if seen.includes(name) or (name != \"policies\" and tag.children().length != 0) or tag.innerText().trim() != \"\"\n throw \"Duplicate or nonempty deployment section: ${name}\"\n seen.add(name)\n switch name\n case \"policies\"\n attributes(tag, [\"reauthSeconds\"])\n items = []\n for tag.children() as child\n if child.tag() != \"policy\" or child.children().length != 0 or child.innerText().trim() != \"\"\n throw \"Policies may contain only empty policy elements\"\n attributes(child, [\"name\", \"reauthSeconds\"])\n items.add(child.attributes())\n settings.policies = {\n reauthSeconds: tag.reauthSeconds\n items: items\n }\n continue\n case \"client\"\n attributes(tag, [\"maxAgeSeconds\"])\n settings.client = tag.attributes()\n continue\n case \"origin\"\n attributes(tag, [\"url\", \"urlEnv\", \"required\"])\n settings.origin = tag.attributes()\n continue\n case \"static\"\n attributes(tag, [\"path\", \"directory\", \"index\", \"fallback\", \"runtime\"])\n settings.static = tag.attributes()\n continue\n case \"http\"\n attributes(tag, [\"host\", \"port\", \"bodyLimit\", \"bodyTimeoutMs\"])\n case \"workers\"\n attributes(tag, [\"workers\", \"maxQueue\", \"requestTimeoutMs\", \"startupTimeoutMs\", \"shutdownTimeoutMs\"])\n case \"events\"\n attributes(tag, [\"requestEvent\", \"eventTimeoutMs\"])\n case \"redis\"\n attributes(tag, [\"connectionEnv\", \"namespace\", \"maxPendingPolls\"])\n settings.redis = tag.attributes()\n continue\n case \"database\"\n attributes(tag, [\"type\", \"file\", \"connectionEnv\", \"busyTimeoutMs\", \"queryTimeoutMs\", \"connectTimeoutSeconds\"])\n settings.database = tag.attributes()\n continue\n case \"jwt\"\n attributes(tag, [\"issuer\", \"audience\", \"ttlSeconds\", \"keyEnv\", \"keysFile\", \"activeKeyId\"])\n else\n throw \"Unknown deployment section: ${name}\"\n for tag.attributes() as key: value\n if key == \"keyEnv\"\n settings.key = process.env[value]\n if settings.key == null\n throw \"JWT key environment variable is missing: ${value}\"\n else\n if key == \"keysFile\"\n settings.keys = from_json(fs/readFileSync(path/resolve(directory, value), \"utf8\"))\n else\n if contains([\"host\", \"issuer\", \"audience\", \"activeKeyId\"], key)\n settings[key] = value\n else\n if key == \"requestEvent\"\n if value != \"true\" and value != \"false\"\n throw \"requestEvent must be true or false\"\n settings[key] = value == \"true\"\n else\n settings[key] = Number(value)\n return options(directory, settings)\n\ncontains(items, value)\n return items.includes(value)\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA;;;;;;;;"}
1
+ {"version":3,"file":"options.mjs","sources":["options.lango"],"sourcesContent":["import \"./policy\"\n policyRegistry(spec)\nimport \"./client_identity\"\n clientOptions(spec, database, origin)\nimport \"./origin\"\n originOptions(spec)\nimport \"./longpoll_options\"\n redisOptions(spec)\nimport \"./database_options\"\n databaseOptions(root, spec, workers)\nimport \"./static_files\"\n staticOptions(root, spec)\nimport js \"node:fs\" as fs\nimport js \"node:path\" as path\nimport js global Object\nimport js global Number\nimport js global process\n\nexport contains(items, value)\nexport options(root, supplied = null)\nexport deployment(directory)\nexport attributes(tag, allowed)\nexport readDeployment(directory, credentials = true)\n\nattributes(tag, allowed)\n for tag.attributes() as key: value\n if !allowed.includes(key)\n throw \"Unknown ${tag.tag()} attribute: ${key}\"\n return null\n\noptions(root, supplied = null)\n result = {\n root: path/resolve(root)\n host: \"127.0.0.1\"\n port: 3000\n workers: 2\n maxQueue: 64\n bodyLimit: 2097152\n bodyTimeoutMs: 30000\n requestTimeoutMs: 30000\n eventTimeoutMs: 5000\n startupTimeoutMs: 30000\n shutdownTimeoutMs: 30000\n issuer: \"lango-server\"\n audience: \"lango-client\"\n ttlSeconds: 900\n key: null\n keys: {}\n activeKeyId: \"current\"\n requestEvent: false\n database: null\n redis: null\n static: null\n origin: null\n client: null\n policies: null\n }\n if supplied != null\n for supplied as key: value\n if !Object/hasOwn(result, key) or key == \"root\"\n throw \"Unknown server option: ${key}\"\n result[key] = value\n if !is_string(result.host) or result.host == \"\"\n throw \"Host must be a nonempty string\"\n for [\"port\", \"workers\", \"maxQueue\", \"bodyLimit\", \"bodyTimeoutMs\", \"requestTimeoutMs\", \"eventTimeoutMs\", \"startupTimeoutMs\", \"shutdownTimeoutMs\", \"ttlSeconds\"] as key\n value = result[key]\n if !is_number(value) or !Number/isSafeInteger(value) or value < 0\n throw \"Invalid server option: ${key}\"\n if key != \"port\" and key != \"maxQueue\" and value == 0\n throw \"Server option must be positive: ${key}\"\n if key.endsWith(\"Ms\") and value > 2147483647\n throw \"Timeout exceeds timer limit: ${key}\"\n if result.port > 65535 or result.workers > 128 or result.ttlSeconds > 86400\n throw \"Server option exceeds supported limit\"\n if !is_bool(result.requestEvent)\n throw \"requestEvent must be boolean\"\n for [\"issuer\", \"audience\", \"activeKeyId\"] as key\n if !is_string(result[key]) or result[key] == \"\"\n throw \"Missing JWT option: ${key}\"\n if !is_object(result.keys) or is_array(result.keys)\n throw \"JWT keys must be a map\"\n keys = Object/assign(Object/create(null), result.keys)\n if result.key != null\n keys[result.activeKeyId] = result.key\n if !Object/hasOwn(keys, result.activeKeyId)\n throw \"JWT signing key is required\"\n for keys as id: secret\n if !is_string(secret) or secret.length < 32\n throw \"JWT keys must contain at least 32 characters\"\n result.keys = keys\n result.key = null\n result.policies = policyRegistry(result.policies)\n result.database = databaseOptions(result.root, result.database, result.workers)\n result.redis = redisOptions(result.redis)\n result.static = staticOptions(result.root, result.static)\n result.origin = originOptions(result.origin)\n result.client = clientOptions(result.client, result.database, result.origin)\n return result\n\ndeployment(directory)\n return options(directory, readDeployment(directory))\n\nreadDeployment(directory, credentials = true)\n file = path/join(directory, \"deploy.xml\")\n root = xml2obj(fs/readFileSync(file, \"utf8\"))\n if root.tag() != \"deploy\"\n throw \"Expected deploy root\"\n attributes(root, [])\n settings = {}\n seen = []\n for root.children() as tag\n name = tag.tag()\n if seen.includes(name) or (name != \"policies\" and tag.children().length != 0) or tag.innerText().trim() != \"\"\n throw \"Duplicate or nonempty deployment section: ${name}\"\n seen.add(name)\n switch name\n case \"policies\"\n attributes(tag, [\"reauthSeconds\"])\n items = []\n for tag.children() as child\n if child.tag() != \"policy\" or child.children().length != 0 or child.innerText().trim() != \"\"\n throw \"Policies may contain only empty policy elements\"\n attributes(child, [\"name\", \"reauthSeconds\"])\n items.add(child.attributes())\n settings.policies = {\n reauthSeconds: tag.reauthSeconds\n items: items\n }\n continue\n case \"client\"\n attributes(tag, [\"maxAgeSeconds\"])\n settings.client = tag.attributes()\n continue\n case \"origin\"\n attributes(tag, [\"url\", \"urlEnv\", \"required\"])\n settings.origin = tag.attributes()\n continue\n case \"static\"\n attributes(tag, [\"path\", \"directory\", \"index\", \"fallback\", \"runtime\"])\n settings.static = tag.attributes()\n continue\n case \"http\"\n attributes(tag, [\"host\", \"port\", \"bodyLimit\", \"bodyTimeoutMs\"])\n case \"workers\"\n attributes(tag, [\"workers\", \"maxQueue\", \"requestTimeoutMs\", \"startupTimeoutMs\", \"shutdownTimeoutMs\"])\n case \"events\"\n attributes(tag, [\"requestEvent\", \"eventTimeoutMs\"])\n case \"redis\"\n attributes(tag, [\"connectionEnv\", \"namespace\", \"maxPendingPolls\"])\n settings.redis = tag.attributes()\n continue\n case \"database\"\n attributes(tag, [\"type\", \"file\", \"connectionEnv\", \"busyTimeoutMs\", \"queryTimeoutMs\", \"connectTimeoutSeconds\"])\n settings.database = tag.attributes()\n continue\n case \"jwt\"\n attributes(tag, [\"issuer\", \"audience\", \"ttlSeconds\", \"keyEnv\", \"keysFile\", \"activeKeyId\"])\n if !credentials\n continue\n else\n throw \"Unknown deployment section: ${name}\"\n for tag.attributes() as key: value\n if key == \"keyEnv\"\n settings.key = process.env[value]\n if settings.key == null\n throw \"JWT key environment variable is missing: ${value}\"\n else\n if key == \"keysFile\"\n settings.keys = from_json(fs/readFileSync(path/resolve(directory, value), \"utf8\"))\n else\n if contains([\"host\", \"issuer\", \"audience\", \"activeKeyId\"], key)\n settings[key] = value\n else\n if key == \"requestEvent\"\n if value != \"true\" and value != \"false\"\n throw \"requestEvent must be true or false\"\n settings[key] = value == \"true\"\n else\n settings[key] = Number(value)\n return settings\n\ncontains(items, value)\n return items.includes(value)\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEA;;;;;;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EA;;;;;;;;","x_lango_build":{"fingerprint":"6ef90d96e3672ee0281e3179b2670ad3c7ba482253b5d733bbaf70a847ae1e8a","outputHash":"8cc5a7c400ab56773c84475bb34591d1aa10a354b966debd4e07a13d6eb137fa","mapHash":"d91a7578eafb53cbc3c2e9ef45f9379655636ec5bba62b113bd86c67498e9592"}}
@@ -1 +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;;;;;;;;;;;;;;;;;;;;;;"}
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;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"fb26132791c00588edd62b0701c8b2c78308e429b5d9aeacf5387f7f28831bfc","outputHash":"1cf4b9c511dddfc6f11619596119b6fad4102fca9ca2d81cf2e5a0498d9bffd2","mapHash":"675adca206b9d46239e607ff8a48366634055da2ef0ac2a0933f43e7f573c7b2"}}
@@ -1 +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;;;;;;;;;;;;;;;;;;;;;;;;;"}
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;;;;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"6cf55d96fa8144aaed1279736180375ef1213ca80d4f6a2dbe54666933b5f873","outputHash":"10836d87b0d6389cb8d4effc1e439d85e66d25b09ab64c706d220d46b686dcb7","mapHash":"0a47dafc050fd955a0095a89560a643d9d8b5e9200b1cd6af11ee4fdcb96b415"}}
@@ -42,7 +42,7 @@ export class PostgresAdapter {
42
42
  this.#port = __normalize(channel.port1);
43
43
  let resolver = __normalize(modules.createRequire(__normalize(path.join(root, "package.json"))));
44
44
  let entry = __normalize(resolver.resolve("@lango-project/lango-server"));
45
- 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)] }]));
46
46
  let worker = __normalize(this.#worker);
47
47
  __normalize(worker.on("error", __withArity(__bindContexts((error) => {
48
48
  error = __boundary(error);
@@ -83,6 +83,9 @@ export class PostgresAdapter {
83
83
  if (__requireBoolean(__normalize(result.failed))) {
84
84
  this.#broken = __normalize(result.dead);
85
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
+ }
86
89
  error.code = __normalize(result.code);
87
90
  error.position = __normalize(result.position);
88
91
  error.transactionUnusable = __normalize(this.#state) === "failed";
@@ -98,6 +101,14 @@ export class PostgresAdapter {
98
101
  return this.#exchange({ action: "query", sql: sql, parameters: parameters }, __normalize(this.#timeout));
99
102
  return null;
100
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
+ }
101
112
  begin() {
102
113
  if (__requireBoolean(__requireBoolean(__normalize(this.#depth) === 0) && __requireBoolean(__normalize(this.#state) === null))) {
103
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":";;;;;;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"2d01956e1fbe9daa54e87b965f7f7a107bfd699e664ed0a70dc37a01fc279aff","outputHash":"b09d20882063933ef7c2fe9c84ecbddaba667f2b290551ea489cc588ec731ca1","mapHash":"a6981427630d0e695e4500f08fa0449adf7c4e399e4ef4c19972be3854970c12"}}