@lango-project/lango-server 0.2.0 → 0.2.3

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 (121) hide show
  1. package/README.md +290 -27
  2. package/dist/.lango/runtime.mjs +24 -1
  3. package/dist/body_reader.mjs +15 -14
  4. package/dist/body_reader.mjs.map +1 -1
  5. package/dist/cli/.lango/runtime.mjs +24 -1
  6. package/dist/cli/body_reader.mjs +15 -14
  7. package/dist/cli/body_reader.mjs.map +1 -1
  8. package/dist/cli/client_identity.mjs +250 -0
  9. package/dist/cli/client_identity.mjs.map +1 -0
  10. package/dist/cli/database.mjs +23 -8
  11. package/dist/cli/database.mjs.map +1 -1
  12. package/dist/cli/endpoint.mjs +11 -7
  13. package/dist/cli/endpoint.mjs.map +1 -1
  14. package/dist/cli/error_details.mjs +45 -0
  15. package/dist/cli/error_details.mjs.map +1 -0
  16. package/dist/cli/longpoll_broker.mjs +9 -8
  17. package/dist/cli/longpoll_broker.mjs.map +1 -1
  18. package/dist/cli/longpoll_options.mjs +8 -7
  19. package/dist/cli/longpoll_options.mjs.map +1 -1
  20. package/dist/cli/longpoll_session.mjs +11 -10
  21. package/dist/cli/longpoll_session.mjs.map +1 -1
  22. package/dist/cli/options.mjs +29 -3
  23. package/dist/cli/options.mjs.map +1 -1
  24. package/dist/cli/origin.mjs +87 -0
  25. package/dist/cli/origin.mjs.map +1 -0
  26. package/dist/cli/policy.mjs +121 -0
  27. package/dist/cli/policy.mjs.map +1 -0
  28. package/dist/cli/postgres_adapter.mjs +3 -2
  29. package/dist/cli/postgres_adapter.mjs.map +1 -1
  30. package/dist/cli/routes.mjs +33 -17
  31. package/dist/cli/routes.mjs.map +1 -1
  32. package/dist/cli/server.mjs +148 -101
  33. package/dist/cli/server.mjs.map +1 -1
  34. package/dist/cli/static_files.mjs +7 -4
  35. package/dist/cli/static_files.mjs.map +1 -1
  36. package/dist/cli/trace.mjs +53 -0
  37. package/dist/cli/trace.mjs.map +1 -0
  38. package/dist/client_identity.mjs +250 -0
  39. package/dist/client_identity.mjs.map +1 -0
  40. package/dist/database.mjs +23 -8
  41. package/dist/database.mjs.map +1 -1
  42. package/dist/endpoint.mjs +11 -7
  43. package/dist/endpoint.mjs.map +1 -1
  44. package/dist/error_details.mjs +45 -0
  45. package/dist/error_details.mjs.map +1 -0
  46. package/dist/group.mjs +34 -16
  47. package/dist/group.mjs.map +1 -1
  48. package/dist/http_failure.mjs +9 -2
  49. package/dist/http_failure.mjs.map +1 -1
  50. package/dist/longpoll_broker.mjs +9 -8
  51. package/dist/longpoll_broker.mjs.map +1 -1
  52. package/dist/longpoll_options.mjs +8 -7
  53. package/dist/longpoll_options.mjs.map +1 -1
  54. package/dist/longpoll_session.mjs +11 -10
  55. package/dist/longpoll_session.mjs.map +1 -1
  56. package/dist/options.mjs +29 -3
  57. package/dist/options.mjs.map +1 -1
  58. package/dist/origin.mjs +87 -0
  59. package/dist/origin.mjs.map +1 -0
  60. package/dist/policy.mjs +121 -0
  61. package/dist/policy.mjs.map +1 -0
  62. package/dist/postgres_adapter.mjs +3 -2
  63. package/dist/postgres_adapter.mjs.map +1 -1
  64. package/dist/postgres_worker.mjs +15 -14
  65. package/dist/postgres_worker.mjs.map +1 -1
  66. package/dist/request_identity.mjs +22 -0
  67. package/dist/request_identity.mjs.map +1 -0
  68. package/dist/response.mjs +1 -1
  69. package/dist/response.mjs.map +1 -1
  70. package/dist/route_info.mjs +1 -1
  71. package/dist/route_info.mjs.map +1 -1
  72. package/dist/routes.mjs +33 -17
  73. package/dist/routes.mjs.map +1 -1
  74. package/dist/runtime.mjs +241 -110
  75. package/dist/runtime.mjs.map +1 -1
  76. package/dist/server.mjs +148 -101
  77. package/dist/server.mjs.map +1 -1
  78. package/dist/server_context.mjs +21 -9
  79. package/dist/server_context.mjs.map +1 -1
  80. package/dist/static_files.mjs +7 -4
  81. package/dist/static_files.mjs.map +1 -1
  82. package/dist/token.mjs +34 -7
  83. package/dist/token.mjs.map +1 -1
  84. package/dist/tokens.mjs +11 -2
  85. package/dist/tokens.mjs.map +1 -1
  86. package/dist/trace.mjs +53 -0
  87. package/dist/trace.mjs.map +1 -0
  88. package/dist/worker.mjs +8 -6
  89. package/dist/worker.mjs.map +1 -1
  90. package/docs/security.md +420 -0
  91. package/examples/security/README.md +160 -0
  92. package/examples/security/deploy.xml +12 -0
  93. package/examples/security/handlers.lango +610 -0
  94. package/examples/security/package.json +19 -0
  95. package/examples/security/passwords.lango +61 -0
  96. package/examples/security/routes.xml +14 -0
  97. package/examples/security/schema.lango +91 -0
  98. package/examples/security/setup.lango +30 -0
  99. package/package.json +12 -6
  100. package/src/client_identity.lango +184 -0
  101. package/src/database.lango +15 -4
  102. package/src/endpoint.lango +12 -5
  103. package/src/error_details.lango +21 -0
  104. package/src/group.lango +25 -21
  105. package/src/http_failure.lango +9 -5
  106. package/src/longpoll_options.lango +11 -5
  107. package/src/options.lango +34 -1
  108. package/src/origin.lango +56 -0
  109. package/src/policy.lango +84 -0
  110. package/src/request_identity.lango +9 -0
  111. package/src/response.lango +1 -1
  112. package/src/route_info.lango +2 -0
  113. package/src/routes.lango +30 -15
  114. package/src/runtime.lango +149 -77
  115. package/src/server.lango +48 -7
  116. package/src/server_context.lango +10 -2
  117. package/src/static_files.lango +3 -0
  118. package/src/token.lango +26 -5
  119. package/src/tokens.lango +10 -3
  120. package/src/trace.lango +23 -0
  121. package/src/worker.lango +1 -0
@@ -0,0 +1,45 @@
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
@@ -0,0 +1 @@
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;;;;;;;;;;;;;;;"}
package/dist/group.mjs CHANGED
@@ -16,13 +16,17 @@ export class Group {
16
16
  #prefix;
17
17
  #module;
18
18
  #auth;
19
- constructor(routes, spec, prefix = "", inheritedModule = null, inheritedAuth = null) {
19
+ #policy;
20
+ #reauthSeconds;
21
+ constructor(routes, spec, prefix = "", inheritedModule = null, inheritedAuth = null, inheritedPolicy = null, inheritedReauthSeconds = null) {
20
22
  __requireArity(arguments.length, [0, 1], "constructor");
21
23
  routes = __boundary(routes);
22
24
  spec = __boundary(spec);
23
25
  prefix = __boundary(prefix);
24
26
  inheritedModule = __boundary(inheritedModule);
25
27
  inheritedAuth = __boundary(inheritedAuth);
28
+ inheritedPolicy = __boundary(inheritedPolicy);
29
+ inheritedReauthSeconds = __boundary(inheritedReauthSeconds);
26
30
  if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.path)))) || __requireBoolean(!__requireBoolean(__normalize(spec.path.startsWith("/"))))) || __requireBoolean(__normalize(spec.path.endsWith("/")))) || __requireBoolean(__normalize(spec.path.includes("*"))))) {
27
31
  throw "Group requires a path without a trailing slash or wildcard";
28
32
  }
@@ -30,11 +34,17 @@ export class Group {
30
34
  this.#prefix = `${prefix}${__normalize(spec.path)}`;
31
35
  this.#module = __normalize(spec.module);
32
36
  this.#auth = __normalize(spec.auth);
37
+ this.#policy = __normalize(spec.policy);
38
+ this.#reauthSeconds = __normalize(spec.reauthSeconds);
33
39
  if (__requireBoolean(__normalize(this.#module) === null)) {
34
40
  this.#module = inheritedModule;
35
41
  }
36
- if (__requireBoolean(__normalize(this.#auth) === null)) {
42
+ if (__requireBoolean(__requireBoolean(__normalize(this.#auth) === null) && __requireBoolean(__normalize(this.#policy) === null))) {
37
43
  this.#auth = inheritedAuth;
44
+ this.#policy = inheritedPolicy;
45
+ }
46
+ if (__requireBoolean(__normalize(this.#reauthSeconds) === null)) {
47
+ this.#reauthSeconds = inheritedReauthSeconds;
38
48
  }
39
49
  }
40
50
  endpoint(spec) {
@@ -43,26 +53,20 @@ export class Group {
43
53
  if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.path)))) || __requireBoolean(!__requireBoolean(__normalize(spec.path.startsWith("/")))))) {
44
54
  throw "Endpoint path must begin with /";
45
55
  }
46
- let mod = __normalize(spec.module);
47
- let auth = __normalize(spec.auth);
48
- if (__requireBoolean(mod === null)) {
49
- mod = __normalize(this.#module);
50
- }
51
- if (__requireBoolean(auth === null)) {
52
- auth = __normalize(this.#auth);
56
+ let item = this.#merged(spec);
57
+ item.path = `${__normalize(this.#prefix)}${__normalize(spec.path)}`;
58
+ if (__requireBoolean(__normalize(item.module) === null)) {
59
+ item.module = __normalize(this.#module);
53
60
  }
54
- __normalize(this.#routes.endpoint({ path: `${__normalize(this.#prefix)}${__normalize(spec.path)}`, module: mod, handler: __normalize(spec.handler), auth: auth, middleware: __normalize(spec.middleware) }));
61
+ __normalize(this.#routes.endpoint(item));
55
62
  return this;
56
63
  return null;
57
64
  }
58
65
  longpoll(spec) {
59
66
  __requireArity(arguments.length, [0], "longpoll");
60
67
  spec = __boundary(spec);
61
- let item = __normalize(__hostGlobal(["Object"]).assign({ }, spec));
68
+ let item = this.#merged(spec);
62
69
  item.path = `${__normalize(this.#prefix)}${__normalize(spec.path)}`;
63
- if (__requireBoolean(__normalize(item.auth) === null)) {
64
- item.auth = __normalize(this.#auth);
65
- }
66
70
  if (__requireBoolean(__normalize(item.fallback) !== null)) {
67
71
  item.fallback = `${__normalize(this.#prefix)}${__normalize(item.fallback)}`;
68
72
  }
@@ -73,7 +77,7 @@ export class Group {
73
77
  group(spec) {
74
78
  __requireArity(arguments.length, [0], "group");
75
79
  spec = __boundary(spec);
76
- return new Group(__normalize(this.#routes), spec, __normalize(this.#prefix), __normalize(this.#module), __normalize(this.#auth));
80
+ return new Group(__normalize(this.#routes), spec, __normalize(this.#prefix), __normalize(this.#module), __normalize(this.#auth), __normalize(this.#policy), __normalize(this.#reauthSeconds));
77
81
  return null;
78
82
  }
79
83
  include(spec) {
@@ -83,9 +87,23 @@ export class Group {
83
87
  if (__requireBoolean(mount === null)) {
84
88
  mount = "/";
85
89
  }
86
- __normalize(this.#routes.include({ module: __normalize(spec.module), path: `${__normalize(this.#prefix)}${mount}` }, __normalize(this.#auth)));
90
+ __normalize(this.#routes.include({ module: __normalize(spec.module), path: `${__normalize(this.#prefix)}${mount}` }, __normalize(this.#auth), __normalize(this.#policy), __normalize(this.#reauthSeconds)));
87
91
  return this;
88
92
  return null;
89
93
  }
94
+ #merged(spec) {
95
+ __requireArity(arguments.length, [0], "merged");
96
+ spec = __boundary(spec);
97
+ let item = __normalize(__hostGlobal(["Object"]).assign({ }, spec));
98
+ if (__requireBoolean(__requireBoolean(__normalize(item.auth) === null) && __requireBoolean(__normalize(item.policy) === null))) {
99
+ item.auth = __normalize(this.#auth);
100
+ item.policy = __normalize(this.#policy);
101
+ }
102
+ if (__requireBoolean(__normalize(item.reauthSeconds) === null)) {
103
+ item.reauthSeconds = __normalize(this.#reauthSeconds);
104
+ }
105
+ return item;
106
+ return null;
107
+ }
90
108
  }
91
109
  //# sourceMappingURL=group.mjs.map
@@ -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)\n methods\n endpoint(spec)\n longpoll(spec)\n group(spec)\n include(spec)\n\nGroup(routes, spec, prefix = \"\", inheritedModule = null, inheritedAuth = 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 if @module == null\n @module = inheritedModule\n if @auth == null\n @auth = inheritedAuth\n\nGroup:endpoint(spec)\n if !is_string(spec.path) or !spec.path.startsWith(\"/\")\n throw \"Endpoint path must begin with /\"\n mod = spec.module\n auth = spec.auth\n if mod == null\n mod = @module\n if auth == null\n auth = @auth\n @routes.endpoint({\n path: \"${@prefix}${spec.path}\"\n module: mod\n handler: spec.handler\n auth: auth\n middleware: spec.middleware\n })\n return @this\n\nGroup:longpoll(spec)\n item = Object/assign({}, spec)\n item.path = \"${@prefix}${spec.path}\"\n if item.auth == null\n item.auth = @auth\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)\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)\n return @this\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 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -15,14 +15,16 @@ import {
15
15
  } from "./.lango/runtime.mjs";
16
16
 
17
17
  export class HttpFailure {
18
+ #details;
18
19
  #status;
19
20
  #code;
20
21
  #headers;
21
- constructor(status, code, headers) {
22
+ constructor(status, code, headers, details = null) {
22
23
  __requireArity(arguments.length, [0, 1, 2], "constructor");
23
24
  status = __boundary(status);
24
25
  code = __boundary(code);
25
26
  headers = __boundary(headers);
27
+ details = __boundary(details);
26
28
  if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isNumber(status))) || __requireBoolean(__finite(status % 1) !== 0)) || __requireBoolean(status < 400)) || __requireBoolean(status > 599))) {
27
29
  throw "Rejected response requires an error status";
28
30
  }
@@ -30,6 +32,7 @@ export class HttpFailure {
30
32
  if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(code))) || __requireBoolean(!__requireBoolean(__normalize(pattern.test(code)))))) {
31
33
  throw "Rejected response requires an error code";
32
34
  }
35
+ this.#details = details;
33
36
  this.#status = status;
34
37
  this.#code = code;
35
38
  this.#headers = __fromJson(__toJson(headers));
@@ -38,7 +41,11 @@ export class HttpFailure {
38
41
  }
39
42
  }
40
43
  result() {
41
- return { status: __normalize(this.#status), headers: __fromJson(__toJson(__normalize(this.#headers))), body: __toJson({ error: __normalize(this.#code) }) };
44
+ let body = { error: __normalize(this.#code) };
45
+ if (__requireBoolean(__normalize(this.#details) !== null)) {
46
+ body.needLogin = __normalize(this.#details);
47
+ }
48
+ return { status: __normalize(this.#status), headers: __fromJson(__toJson(__normalize(this.#headers))), body: __toJson(body) };
42
49
  return null;
43
50
  }
44
51
  }
@@ -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)\n methods\n result()\n\nHttpFailure(status, code, headers)\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 @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 return {\n status: @status\n headers: from_json(to_json(@headers))\n body: to_json({\n error: @code\n })\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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -6,6 +6,7 @@ import * as modules from "node:module";
6
6
  import {
7
7
  hostGlobal as __hostGlobal,
8
8
  hostGlobalCall as __hostGlobalCall,
9
+ bindContexts as __bindContexts,
9
10
  fromJson as __fromJson,
10
11
  toJson as __toJson,
11
12
  isNumber as __isNumber,
@@ -65,11 +66,11 @@ export class LongpollBroker {
65
66
  let name = __normalize(config.connectionEnv);
66
67
  this.#client = __normalize(redis.createClient({ url: __normalize(__hostGlobal(["process"]).env[name]), disableOfflineQueue: true, commandsQueueMaxLength: 2048, socket: { connectTimeout: 2000, reconnectStrategy: 500 } }));
67
68
  let client = __normalize(this.#client);
68
- __normalize(client.on("error", __withArity((error) => {
69
+ __normalize(client.on("error", __withArity(__bindContexts((error) => {
69
70
  error = __boundary(error);
70
71
  return null;
71
72
  return null;
72
- }, [0], "closure")));
73
+ }), [0], "closure")));
73
74
  return bounded(__normalize(client.connect()), 3000);
74
75
  return null;
75
76
  }
@@ -136,7 +137,7 @@ export class LongpollBroker {
136
137
  }
137
138
  }
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] }));
139
- return bounded(pending, 3000).then(__withArity((raw) => {
140
+ return bounded(pending, 3000).then(__withArity(__bindContexts((raw) => {
140
141
  raw = __boundary(raw);
141
142
  let result = __normalize(__hostGlobal(["JSON"]).parse(raw));
142
143
  if (__requireBoolean(__normalize(result.resyncRequired) === true)) {
@@ -154,7 +155,7 @@ export class LongpollBroker {
154
155
  }
155
156
  return { messages: messages, cursor: __normalize(result.cursor), resyncRequired: false };
156
157
  return null;
157
- }, [0], "closure"));
158
+ }), [0], "closure"));
158
159
  return null;
159
160
  }
160
161
  }
@@ -200,15 +201,15 @@ function bounded(pending, ms) {
200
201
  pending = __boundary(pending);
201
202
  ms = __boundary(ms);
202
203
  let expired = __normalize(__hostGlobal(["Promise"]).withResolvers());
203
- let fail = () => {
204
+ let fail = __bindContexts(() => {
204
205
  __normalize(expired.reject("RedisUnavailable"));
205
206
  return null;
206
- };
207
+ });
207
208
  let timer = __hostGlobalCall(["setTimeout"], fail, ms);
208
- return __normalize(__hostGlobal(["Promise"]).race([pending, __normalize(expired.promise)])).finally(() => {
209
+ return __normalize(__hostGlobal(["Promise"]).race([pending, __normalize(expired.promise)])).finally(__bindContexts(() => {
209
210
  __hostGlobalCall(["clearTimeout"], timer);
210
211
  return null;
211
- });
212
+ }));
212
213
  return null;
213
214
  }
214
215
  //# sourceMappingURL=longpoll_broker.mjs.map
@@ -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;;;;;;;;;;;;;;;;;"}
@@ -1,3 +1,4 @@
1
+ import { policyOptions } from "./policy.mjs";
1
2
  import {
2
3
  hostGlobal as __hostGlobal,
3
4
  hostGlobalCall as __hostGlobalCall,
@@ -16,20 +17,20 @@ import {
16
17
  export function longpollOptions(spec) {
17
18
  __requireArity(arguments.length, [0], "longpollOptions");
18
19
  spec = __boundary(spec);
19
- let result = { kind: "longpoll", path: __normalize(spec.path), auth: "login", waitTimeoutMs: 20000, retentionMs: 300000, maxMessages: 1000, fallback: null };
20
+ let result = { kind: "longpoll", path: __normalize(spec.path), auth: null, policy: null, reauthSeconds: 0, waitTimeoutMs: 20000, retentionMs: 300000, maxMessages: 1000, fallback: null };
20
21
  for (const [key, value] of __entries(spec)) {
21
22
  if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(result, key)))) || __requireBoolean(key === "kind"))) {
22
23
  throw `Unknown longpoll option: ${key}`;
23
24
  }
24
25
  result[key] = value;
25
26
  }
26
- if (__requireBoolean(__normalize(result.auth) === null)) {
27
- result.auth = "login";
28
- }
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);
29
33
  validPath(__normalize(result.path));
30
- if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(result.auth)))) || __requireBoolean(__normalize(result.auth) === "")) || __requireBoolean(__normalize(result.auth.includes(","))))) {
31
- throw "Longpoll auth must name one permission";
32
- }
33
34
  if (__requireBoolean(__normalize(result.fallback) !== null)) {
34
35
  validPath(__normalize(result.fallback));
35
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"longpoll_options.mjs","sources":["longpoll_options.lango"],"sourcesContent":["import 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: \"login\"\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 if result.auth == null\n result.auth = \"login\"\n validPath(result.path)\n if !is_string(result.auth) or result.auth == \"\" or result.auth.includes(\",\")\n throw \"Longpoll auth must name one permission\"\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":";;;;;;;;;;;;;;;AAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  hostGlobal as __hostGlobal,
3
3
  hostGlobalCall as __hostGlobalCall,
4
+ bindContexts as __bindContexts,
4
5
  fromJson as __fromJson,
5
6
  toJson as __toJson,
6
7
  isNumber as __isNumber,
@@ -72,7 +73,7 @@ export class LongpollSession {
72
73
  return __normalize(__hostGlobal(["Promise"]).resolve(failure(400, "InvalidJson")));
73
74
  }
74
75
  let auth = __normalize(this.#authorize);
75
- return __call(auth, null, null).then(__withArity((result) => {
76
+ return __call(auth, null, null).then(__withArity(__bindContexts((result) => {
76
77
  result = __boundary(result);
77
78
  if (__requireBoolean(__normalize(result.status) !== 200)) {
78
79
  return result;
@@ -81,21 +82,21 @@ export class LongpollSession {
81
82
  this.#deadline = __numericAdd(__normalize(__hostGlobal(["Date"]).now()), __normalize(this.#route.waitTimeoutMs));
82
83
  return this.#poll();
83
84
  return null;
84
- }, [0], "closure")).catch(__withArity((error) => {
85
+ }), [0], "closure")).catch(__withArity(__bindContexts((error) => {
85
86
  error = __boundary(error);
86
87
  return failure(503, "LongpollUnavailable");
87
88
  return null;
88
- }, [0], "closure")).finally(() => {
89
+ }), [0], "closure")).finally(__bindContexts(() => {
89
90
  this.cancel();
90
91
  return null;
91
- });
92
+ }));
92
93
  return null;
93
94
  }
94
95
  #poll() {
95
96
  if (__requireBoolean(__normalize(this.#cancelled))) {
96
97
  return __normalize(__hostGlobal(["Promise"]).resolve(failure(503, "Unavailable")));
97
98
  }
98
- return __normalize(this.#broker.read(__normalize(this.#route.path), __normalize(this.#input.key), __normalize(this.#cursor))).then(__withArity((batch) => {
99
+ return __normalize(this.#broker.read(__normalize(this.#route.path), __normalize(this.#input.key), __normalize(this.#cursor))).then(__withArity(__bindContexts((batch) => {
99
100
  batch = __boundary(batch);
100
101
  if (__requireBoolean(__normalize(this.#cancelled))) {
101
102
  return failure(503, "Unavailable");
@@ -110,18 +111,18 @@ export class LongpollSession {
110
111
  this.#cursor = __normalize(batch.cursor);
111
112
  this.#sleep = __normalize(__hostGlobal(["Promise"]).withResolvers());
112
113
  let sleep = __normalize(this.#sleep);
113
- let wake = () => {
114
+ let wake = __bindContexts(() => {
114
115
  __normalize(sleep.resolve(null));
115
116
  return null;
116
- };
117
+ });
117
118
  this.#timer = __hostGlobalCall(["setTimeout"], wake, __normalize(__hostGlobal(["Math"]).min(250, __normalize(__hostGlobal(["Math"]).max(1, __finite(__normalize(this.#deadline) - __normalize(__hostGlobal(["Date"]).now())))))));
118
- return __normalize(sleep.promise).then(__withArity((ignored) => {
119
+ return __normalize(sleep.promise).then(__withArity(__bindContexts((ignored) => {
119
120
  ignored = __boundary(ignored);
120
121
  return this.#poll();
121
122
  return null;
122
- }, [0], "closure"));
123
+ }), [0], "closure"));
123
124
  return null;
124
- }, [0], "closure"));
125
+ }), [0], "closure"));
125
126
  return null;
126
127
  }
127
128
  }
@@ -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;;;;;;;;"}
package/dist/options.mjs CHANGED
@@ -1,3 +1,6 @@
1
+ import { policyRegistry } from "./policy.mjs";
2
+ import { clientOptions } from "./client_identity.mjs";
3
+ import { originOptions } from "./origin.mjs";
1
4
  import { redisOptions } from "./longpoll_options.mjs";
2
5
  import { databaseOptions } from "./database_options.mjs";
3
6
  import { staticOptions } from "./static_files.mjs";
@@ -38,7 +41,7 @@ export function options(root, supplied = null) {
38
41
  __requireArity(arguments.length, [0], "options");
39
42
  root = __boundary(root);
40
43
  supplied = __boundary(supplied);
41
- let result = { root: __normalize(path.resolve(root)), host: "127.0.0.1", port: 3000, workers: 2, maxQueue: 64, bodyLimit: 2097152, bodyTimeoutMs: 30000, requestTimeoutMs: 30000, eventTimeoutMs: 5000, startupTimeoutMs: 30000, shutdownTimeoutMs: 30000, issuer: "lango-server", audience: "lango-client", ttlSeconds: 900, key: null, keys: { }, activeKeyId: "current", requestEvent: false, database: null, redis: null, static: null };
44
+ let result = { root: __normalize(path.resolve(root)), host: "127.0.0.1", port: 3000, workers: 2, maxQueue: 64, bodyLimit: 2097152, bodyTimeoutMs: 30000, requestTimeoutMs: 30000, eventTimeoutMs: 5000, startupTimeoutMs: 30000, shutdownTimeoutMs: 30000, issuer: "lango-server", audience: "lango-client", ttlSeconds: 900, key: null, keys: { }, activeKeyId: "current", requestEvent: false, database: null, redis: null, static: null, origin: null, client: null, policies: null };
42
45
  if (__requireBoolean(supplied !== null)) {
43
46
  for (const [key, value] of __entries(supplied)) {
44
47
  if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(result, key)))) || __requireBoolean(key === "root"))) {
@@ -90,9 +93,12 @@ export function options(root, supplied = null) {
90
93
  }
91
94
  result.keys = keys;
92
95
  result.key = null;
96
+ result.policies = policyRegistry(__normalize(result.policies));
93
97
  result.database = databaseOptions(__normalize(result.root), __normalize(result.database), __normalize(result.workers));
94
98
  result.redis = redisOptions(__normalize(result.redis));
95
99
  result.static = staticOptions(__normalize(result.root), __normalize(result.static));
100
+ result.origin = originOptions(__normalize(result.origin));
101
+ result.client = clientOptions(__normalize(result.client), __normalize(result.database), __normalize(result.origin));
96
102
  return result;
97
103
  return null;
98
104
  }
@@ -110,11 +116,31 @@ export function deployment(directory) {
110
116
  let seen = [];
111
117
  for (const tag of __normalize(root.children())) {
112
118
  let name = __normalize(tag.tag());
113
- if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(seen.includes(name))) || __requireBoolean(__normalize(__normalize(tag.children()).length) !== 0)) || __requireBoolean(__normalize(__normalize(tag.innerText()).trim()) !== ""))) {
119
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(seen.includes(name))) || __requireBoolean(__requireBoolean(name !== "policies") && __requireBoolean(__normalize(__normalize(tag.children()).length) !== 0))) || __requireBoolean(__normalize(__normalize(tag.innerText()).trim()) !== ""))) {
114
120
  throw `Duplicate or nonempty deployment section: ${name}`;
115
121
  }
116
122
  seen.push(name);
117
- if (name === "static") {
123
+ if (name === "policies") {
124
+ attributes(tag, ["reauthSeconds"]);
125
+ let items = [];
126
+ for (const child of __normalize(tag.children())) {
127
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(child.tag()) !== "policy") || __requireBoolean(__normalize(__normalize(child.children()).length) !== 0)) || __requireBoolean(__normalize(__normalize(child.innerText()).trim()) !== ""))) {
128
+ throw "Policies may contain only empty policy elements";
129
+ }
130
+ attributes(child, ["name", "reauthSeconds"]);
131
+ items.push(__normalize(child.attributes()));
132
+ }
133
+ settings.policies = { reauthSeconds: __normalize(tag.reauthSeconds), items: items };
134
+ continue;
135
+ } else if (name === "client") {
136
+ attributes(tag, ["maxAgeSeconds"]);
137
+ settings.client = __normalize(tag.attributes());
138
+ continue;
139
+ } else if (name === "origin") {
140
+ attributes(tag, ["url", "urlEnv", "required"]);
141
+ settings.origin = __normalize(tag.attributes());
142
+ continue;
143
+ } else if (name === "static") {
118
144
  attributes(tag, ["path", "directory", "index", "fallback", "runtime"]);
119
145
  settings.static = __normalize(tag.attributes());
120
146
  continue;
@@ -1 +1 @@
1
- {"version":3,"file":"options.mjs","sources":["options.lango"],"sourcesContent":["import \"./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 }\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.database = databaseOptions(result.root, result.database, result.workers)\n result.redis = redisOptions(result.redis)\n result.static = staticOptions(result.root, result.static)\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 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 \"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":";;;;;;;;;;;;;;;;;;;;;;;AAiBA;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA;;;;;;;;"}
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;;;;;;;;"}