@lango-project/lango-server 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +8 -0
  2. package/dist/body_reader.mjs.map +1 -1
  3. package/dist/builder.mjs.map +1 -1
  4. package/dist/cli/server.mjs +3 -838
  5. package/dist/cli/server.mjs.map +1 -1
  6. package/dist/client_identity.mjs.map +1 -1
  7. package/dist/database.mjs.map +1 -1
  8. package/dist/database_action.mjs.map +1 -1
  9. package/dist/database_options.mjs.map +1 -1
  10. package/dist/database_scope.mjs.map +1 -1
  11. package/dist/endpoint.mjs.map +1 -1
  12. package/dist/error_details.mjs.map +1 -1
  13. package/dist/execution_failure.mjs.map +1 -1
  14. package/dist/execution_identity.mjs.map +1 -1
  15. package/dist/execution_log.mjs.map +1 -1
  16. package/dist/execution_runtime.mjs.map +1 -1
  17. package/dist/execution_worker.mjs.map +1 -1
  18. package/dist/executor.mjs.map +1 -1
  19. package/dist/group.mjs.map +1 -1
  20. package/dist/http_failure.mjs.map +1 -1
  21. package/dist/job_configuration.mjs.map +1 -1
  22. package/dist/job_context.mjs.map +1 -1
  23. package/dist/library.mjs.map +1 -1
  24. package/dist/longpoll_broker.mjs.map +1 -1
  25. package/dist/longpoll_options.mjs.map +1 -1
  26. package/dist/longpoll_session.mjs.map +1 -1
  27. package/dist/middleware.mjs.map +1 -1
  28. package/dist/module_loader.mjs.map +1 -1
  29. package/dist/options.mjs.map +1 -1
  30. package/dist/origin.mjs.map +1 -1
  31. package/dist/policy.mjs.map +1 -1
  32. package/dist/postgres_adapter.mjs.map +1 -1
  33. package/dist/postgres_worker.mjs.map +1 -1
  34. package/dist/queue_provider.mjs.map +1 -1
  35. package/dist/request_identity.mjs.map +1 -1
  36. package/dist/response.mjs.map +1 -1
  37. package/dist/route_info.mjs.map +1 -1
  38. package/dist/route_pattern.mjs.map +1 -1
  39. package/dist/routes.mjs.map +1 -1
  40. package/dist/runtime.mjs.map +1 -1
  41. package/dist/server.mjs.map +1 -1
  42. package/dist/server_context.mjs.map +1 -1
  43. package/dist/sqlite_adapter.mjs.map +1 -1
  44. package/dist/static_files.mjs.map +1 -1
  45. package/dist/token.mjs.map +1 -1
  46. package/dist/tokens.mjs.map +1 -1
  47. package/dist/trace.mjs.map +1 -1
  48. package/dist/worker.mjs.map +1 -1
  49. package/examples/security/package.json +1 -1
  50. package/package.json +6 -4
  51. package/dist/cli/.lango/bignumber.mjs +0 -3119
  52. package/dist/cli/.lango/localization.mjs +0 -108
  53. package/dist/cli/.lango/runtime.mjs +0 -725
  54. package/dist/cli/.lango/vendor/i18next.LICENSE +0 -21
  55. package/dist/cli/.lango/vendor/i18next.mjs +0 -2434
  56. package/dist/cli/.lango/xmldom/conventions.js +0 -429
  57. package/dist/cli/.lango/xmldom/dom-parser.js +0 -591
  58. package/dist/cli/.lango/xmldom/dom.js +0 -3759
  59. package/dist/cli/.lango/xmldom/entities.js +0 -2171
  60. package/dist/cli/.lango/xmldom/errors.js +0 -205
  61. package/dist/cli/.lango/xmldom/grammar.js +0 -559
  62. package/dist/cli/.lango/xmldom/index.js +0 -41
  63. package/dist/cli/.lango/xmldom/package.json +0 -1
  64. package/dist/cli/.lango/xmldom/sax.js +0 -983
  65. package/dist/cli/.lango/xmldom.LICENSE.md +0 -8
  66. package/dist/cli/body_reader.mjs +0 -180
  67. package/dist/cli/body_reader.mjs.map +0 -1
  68. package/dist/cli/client_identity.mjs +0 -250
  69. package/dist/cli/client_identity.mjs.map +0 -1
  70. package/dist/cli/database.mjs +0 -116
  71. package/dist/cli/database.mjs.map +0 -1
  72. package/dist/cli/database_options.mjs +0 -83
  73. package/dist/cli/database_options.mjs.map +0 -1
  74. package/dist/cli/database_scope.mjs +0 -93
  75. package/dist/cli/database_scope.mjs.map +0 -1
  76. package/dist/cli/endpoint.mjs +0 -50
  77. package/dist/cli/endpoint.mjs.map +0 -1
  78. package/dist/cli/error_details.mjs +0 -45
  79. package/dist/cli/error_details.mjs.map +0 -1
  80. package/dist/cli/longpoll_broker.mjs +0 -215
  81. package/dist/cli/longpoll_broker.mjs.map +0 -1
  82. package/dist/cli/longpoll_options.mjs +0 -103
  83. package/dist/cli/longpoll_options.mjs.map +0 -1
  84. package/dist/cli/longpoll_session.mjs +0 -136
  85. package/dist/cli/longpoll_session.mjs.map +0 -1
  86. package/dist/cli/middleware.mjs +0 -25
  87. package/dist/cli/middleware.mjs.map +0 -1
  88. package/dist/cli/options.mjs +0 -214
  89. package/dist/cli/options.mjs.map +0 -1
  90. package/dist/cli/origin.mjs +0 -87
  91. package/dist/cli/origin.mjs.map +0 -1
  92. package/dist/cli/policy.mjs +0 -121
  93. package/dist/cli/policy.mjs.map +0 -1
  94. package/dist/cli/postgres_adapter.mjs +0 -178
  95. package/dist/cli/postgres_adapter.mjs.map +0 -1
  96. package/dist/cli/route_pattern.mjs +0 -129
  97. package/dist/cli/route_pattern.mjs.map +0 -1
  98. package/dist/cli/routes.mjs +0 -360
  99. package/dist/cli/routes.mjs.map +0 -1
  100. package/dist/cli/sqlite_adapter.mjs +0 -163
  101. package/dist/cli/sqlite_adapter.mjs.map +0 -1
  102. package/dist/cli/static_files.mjs +0 -224
  103. package/dist/cli/static_files.mjs.map +0 -1
  104. package/dist/cli/trace.mjs +0 -53
  105. package/dist/cli/trace.mjs.map +0 -1
@@ -1,178 +0,0 @@
1
- import * as modules from "node:module";
2
- import * as path from "node:path";
3
- import * as threads from "node:worker_threads";
4
- import {
5
- hostGlobal as __hostGlobal,
6
- bindContexts as __bindContexts,
7
- requireBoolean as __requireBoolean,
8
- normalize as __normalize,
9
- finite as __finite,
10
- numericAdd as __numericAdd,
11
- boundary as __boundary,
12
- requireArity as __requireArity,
13
- withArity as __withArity,
14
- } from "./.lango/runtime.mjs";
15
-
16
- export class PostgresAdapter {
17
- parameterStyle;
18
- #closed;
19
- #broken;
20
- #state;
21
- #depth;
22
- #rollbackOnly;
23
- #timeout;
24
- #signal;
25
- #port;
26
- #lango;
27
- #worker;
28
- constructor(mod, settings, root) {
29
- __requireArity(arguments.length, [0, 1, 2], "constructor");
30
- mod = __boundary(mod);
31
- settings = __boundary(settings);
32
- root = __boundary(root);
33
- this.#closed = false;
34
- this.#broken = false;
35
- this.#state = null;
36
- this.#depth = 0;
37
- this.#rollbackOnly = false;
38
- this.parameterStyle = "postgresql";
39
- this.#timeout = __normalize(__hostGlobal(["Math"]).min(2147483647, __numericAdd(__normalize(settings.queryTimeoutMs), 1000)));
40
- this.#signal = new (__hostGlobal(["Int32Array"]))(new (__hostGlobal(["SharedArrayBuffer"]))(4));
41
- let channel = __normalize(__hostGlobal(["Reflect"]).construct(__normalize(mod.MessageChannel), []));
42
- this.#port = __normalize(channel.port1);
43
- let resolver = __normalize(modules.createRequire(__normalize(path.join(root, "package.json"))));
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: { root: root, settings: settings, port: __normalize(channel.port2), signal: __normalize(this.#signal) }, transferList: [__normalize(channel.port2)] }]));
46
- let worker = __normalize(this.#worker);
47
- __normalize(worker.on("error", __withArity(__bindContexts((error) => {
48
- error = __boundary(error);
49
- this.#broken = true;
50
- return null;
51
- }), [0], "closure")));
52
- __normalize(this.#worker.unref());
53
- __normalize(this.#port.unref());
54
- try {
55
- this.#exchange({ action: "connect" }, __normalize(__hostGlobal(["Math"]).min(2147483647, __numericAdd(__finite(__normalize(settings.connectTimeoutSeconds) * 1000), 1000))));
56
- } catch (error) {
57
- this.close();
58
- throw new (__hostGlobal(["Error"]))("PostgreSQL initialization failed");
59
- }
60
- }
61
- #exchange(task, timeout) {
62
- __requireArity(arguments.length, [0, 1], "exchange");
63
- task = __boundary(task);
64
- timeout = __boundary(timeout);
65
- if (__requireBoolean(__requireBoolean(__normalize(this.#closed)) || __requireBoolean(__normalize(this.#broken)))) {
66
- throw new (__hostGlobal(["Error"]))("PostgreSQL connection is unavailable");
67
- }
68
- __normalize(__hostGlobal(["Atomics"]).store(__normalize(this.#signal), 0, 0));
69
- __normalize(this.#port.postMessage(task));
70
- let waited = __normalize(__hostGlobal(["Atomics"]).wait(__normalize(this.#signal), 0, 0, timeout));
71
- if (__requireBoolean(waited === "timed-out")) {
72
- this.#broken = true;
73
- __normalize(this.#worker.terminate());
74
- throw new (__hostGlobal(["Error"]))("PostgreSQL operation timed out");
75
- }
76
- let reply = __normalize(threads.receiveMessageOnPort(__normalize(this.#port)));
77
- if (__requireBoolean(reply === null)) {
78
- this.#broken = true;
79
- throw new (__hostGlobal(["Error"]))("PostgreSQL response was not received");
80
- }
81
- let result = __normalize(reply.message);
82
- this.#state = __normalize(result.state);
83
- if (__requireBoolean(__normalize(result.failed))) {
84
- this.#broken = __normalize(result.dead);
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
- }
89
- error.code = __normalize(result.code);
90
- error.position = __normalize(result.position);
91
- error.transactionUnusable = __normalize(this.#state) === "failed";
92
- throw error;
93
- }
94
- return result;
95
- return null;
96
- }
97
- execute(sql, parameters) {
98
- __requireArity(arguments.length, [0, 1], "execute");
99
- sql = __boundary(sql);
100
- parameters = __boundary(parameters);
101
- return this.#exchange({ action: "query", sql: sql, parameters: parameters }, __normalize(this.#timeout));
102
- return null;
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
- }
112
- begin() {
113
- if (__requireBoolean(__requireBoolean(__normalize(this.#depth) === 0) && __requireBoolean(__normalize(this.#state) === null))) {
114
- this.execute("BEGIN", []);
115
- }
116
- this.#depth = __numericAdd(__normalize(this.#depth), 1);
117
- return null;
118
- return null;
119
- }
120
- commit() {
121
- if (__requireBoolean(__normalize(this.#depth) === 0)) {
122
- throw new (__hostGlobal(["Error"]))("NoActiveTransaction");
123
- }
124
- if (__requireBoolean(__normalize(this.#depth) > 1)) {
125
- this.#depth = __finite(__normalize(this.#depth) - 1);
126
- return null;
127
- }
128
- if (__requireBoolean(__requireBoolean(__normalize(this.#rollbackOnly)) || __requireBoolean(__normalize(this.#state) === "failed"))) {
129
- this.rollback();
130
- throw new (__hostGlobal(["Error"]))("TransactionRolledBack");
131
- }
132
- this.execute("COMMIT", []);
133
- this.#depth = 0;
134
- return null;
135
- return null;
136
- }
137
- rollback() {
138
- if (__requireBoolean(__normalize(this.#depth) > 1)) {
139
- this.#depth = __finite(__normalize(this.#depth) - 1);
140
- this.#rollbackOnly = true;
141
- return null;
142
- }
143
- if (__requireBoolean(__normalize(this.#state) !== null)) {
144
- this.execute("ROLLBACK", []);
145
- }
146
- this.#depth = 0;
147
- this.#rollbackOnly = false;
148
- return null;
149
- return null;
150
- }
151
- transactionState() {
152
- if (__requireBoolean(__normalize(this.#broken))) {
153
- throw new (__hostGlobal(["Error"]))("PostgreSQL connection is unavailable");
154
- }
155
- if (__requireBoolean(__requireBoolean(__normalize(this.#rollbackOnly)) && __requireBoolean(__normalize(this.#state) !== "failed"))) {
156
- return "rollback_only";
157
- }
158
- return __normalize(this.#state);
159
- return null;
160
- }
161
- close() {
162
- if (__requireBoolean(__normalize(this.#closed))) {
163
- return null;
164
- }
165
- try {
166
- if (__requireBoolean(!__requireBoolean(__normalize(this.#broken)))) {
167
- this.#exchange({ action: "close" }, __normalize(this.#timeout));
168
- }
169
- } finally {
170
- this.#closed = true;
171
- __normalize(this.#port.close());
172
- __normalize(this.#worker.terminate());
173
- }
174
- return null;
175
- return null;
176
- }
177
- }
178
- //# sourceMappingURL=postgres_adapter.mjs.map
@@ -1 +0,0 @@
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,129 +0,0 @@
1
- import {
2
- hostGlobal as __hostGlobal,
3
- isNumber as __isNumber,
4
- isString as __isString,
5
- isBool as __isBool,
6
- isObject as __isObject,
7
- isArray as __isArray,
8
- entries as __entries,
9
- range as __range,
10
- requireBoolean as __requireBoolean,
11
- normalize as __normalize,
12
- finite as __finite,
13
- boundary as __boundary,
14
- requireArity as __requireArity,
15
- } from "./.lango/runtime.mjs";
16
-
17
- export function routePattern(path) {
18
- __requireArity(arguments.length, [0], "routePattern");
19
- path = __boundary(path);
20
- if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(path))) || __requireBoolean(!__requireBoolean(__normalize(path.startsWith("/"))))) || __requireBoolean(__normalize(path.includes("?")))) || __requireBoolean(__normalize(path.includes("#")))) || __requireBoolean(__normalize(path.includes("\\")))) || __requireBoolean(__normalize(path.includes("//"))))) {
21
- throw "Endpoint requires an absolute URL path";
22
- }
23
- if (__requireBoolean(__requireBoolean(__normalize(path.includes("*"))) && __requireBoolean(__requireBoolean(!__requireBoolean(__normalize(path.endsWith("/*")))) || __requireBoolean(__normalize(path.indexOf("*")) !== __normalize(path.lastIndexOf("*")))))) {
24
- throw "Only trailing /* wildcards are supported";
25
- }
26
- let segments = __normalize(path.split("/"));
27
- segments = __normalize(segments.slice(1));
28
- let wildcard = __normalize(path.endsWith("/*"));
29
- if (__requireBoolean(wildcard)) {
30
- __normalize(segments.pop());
31
- }
32
- let names = [];
33
- let shape = [];
34
- let identifier = new (__hostGlobal(["RegExp"]))("^[A-Za-z_][A-Za-z0-9_]*$");
35
- let reserved = ["__proto__", "constructor", "prototype"];
36
- for (const segment of segments) {
37
- if (__requireBoolean(__requireBoolean(__normalize(segment.includes("{"))) || __requireBoolean(__normalize(segment.includes("}"))))) {
38
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(segment.startsWith("{")))) || __requireBoolean(!__requireBoolean(__normalize(segment.endsWith("}")))))) {
39
- throw "Path parameters must occupy an entire segment";
40
- }
41
- let name = __normalize(segment.slice(1, __finite(-1)));
42
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(identifier.test(name)))) || __requireBoolean(__normalize(reserved.includes(name))))) {
43
- throw `Invalid path parameter name: ${name}`;
44
- }
45
- if (__requireBoolean(__normalize(names.includes(name)))) {
46
- throw `Duplicate path parameter: ${name}`;
47
- }
48
- names.push(name);
49
- shape.push("{}");
50
- } else {
51
- shape.push(segment);
52
- }
53
- }
54
- if (__requireBoolean(wildcard)) {
55
- shape.push("*");
56
- }
57
- let key = __normalize(shape.join("/"));
58
- key = `/${key}`;
59
- return { segments: segments, wildcard: wildcard, key: key };
60
- return null;
61
- }
62
-
63
- export function matchPath(pattern, path) {
64
- __requireArity(arguments.length, [0, 1], "matchPath");
65
- pattern = __boundary(pattern);
66
- path = __boundary(path);
67
- let parts = __normalize(path.split("/"));
68
- if (__requireBoolean(__normalize(parts[0]) !== "")) {
69
- return null;
70
- }
71
- parts = __normalize(parts.slice(1));
72
- let count = pattern.segments.length;
73
- if (__requireBoolean(__normalize(pattern.wildcard))) {
74
- if (__requireBoolean(__normalize(parts.length) <= count)) {
75
- return null;
76
- }
77
- } else {
78
- if (__requireBoolean(__normalize(parts.length) !== count)) {
79
- return null;
80
- }
81
- }
82
- let parameters = { };
83
- for (const [index, segment] of __entries(__normalize(pattern.segments))) {
84
- let value = __normalize(parts[index]);
85
- if (__requireBoolean(__normalize(segment.startsWith("{")))) {
86
- if (__requireBoolean(value === "")) {
87
- return null;
88
- }
89
- let name = __normalize(segment.slice(1, __finite(-1)));
90
- parameters[name] = value;
91
- } else {
92
- if (__requireBoolean(segment !== value)) {
93
- return null;
94
- }
95
- }
96
- }
97
- return parameters;
98
- return null;
99
- }
100
-
101
- export function moreSpecific(candidate, current) {
102
- __requireArity(arguments.length, [0, 1], "moreSpecific");
103
- candidate = __boundary(candidate);
104
- current = __boundary(current);
105
- if (__requireBoolean(current === null)) {
106
- return true;
107
- }
108
- if (__requireBoolean(__normalize(candidate.wildcard) !== __normalize(current.wildcard))) {
109
- return !__requireBoolean(__normalize(candidate.wildcard));
110
- }
111
- let first = __normalize(candidate.segments);
112
- let second = __normalize(current.segments);
113
- let count = __normalize(first.length);
114
- if (__requireBoolean(__normalize(second.length) < count)) {
115
- count = __normalize(second.length);
116
- }
117
- for (const index of __range(0, count)) {
118
- let segment = __normalize(first[index]);
119
- let alternative = __normalize(second[index]);
120
- let literal = !__requireBoolean(__normalize(segment.startsWith("{")));
121
- let other = !__requireBoolean(__normalize(alternative.startsWith("{")));
122
- if (__requireBoolean(literal !== other)) {
123
- return literal;
124
- }
125
- }
126
- return __normalize(first.length) > __normalize(second.length);
127
- return null;
128
- }
129
- //# sourceMappingURL=route_pattern.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"route_pattern.mjs","sources":["route_pattern.lango"],"sourcesContent":["import js global RegExp\n\nexport routePattern(path)\nexport matchPath(pattern, path)\nexport moreSpecific(candidate, current)\n\nroutePattern(path)\n if !is_string(path) or !path.startsWith(\"/\") or path.includes(\"?\") or path.includes(\"#\") or path.includes(\"\\\\\") or path.includes(\"//\")\n throw \"Endpoint requires an absolute URL path\"\n if path.includes(\"*\") and (!path.endsWith(\"/*\") or path.indexOf(\"*\") != path.lastIndexOf(\"*\"))\n throw \"Only trailing /* wildcards are supported\"\n segments = path.split(\"/\")\n segments = segments.slice(1)\n wildcard = path.endsWith(\"/*\")\n if wildcard\n segments.pop()\n names = []\n shape = []\n identifier = new RegExp(\"^[A-Za-z_][A-Za-z0-9_]*$\")\n reserved = [\"__proto__\", \"constructor\", \"prototype\"]\n for segments as segment\n if segment.includes(\"{\") or segment.includes(\"}\")\n if !segment.startsWith(\"{\") or !segment.endsWith(\"}\")\n throw \"Path parameters must occupy an entire segment\"\n name = segment.slice(1, -1)\n if !identifier.test(name) or reserved.includes(name)\n throw \"Invalid path parameter name: ${name}\"\n if names.includes(name)\n throw \"Duplicate path parameter: ${name}\"\n names.add(name)\n shape.add(\"{}\")\n else\n shape.add(segment)\n if wildcard\n shape.add(\"*\")\n key = shape.join(\"/\")\n key = \"/${key}\"\n return {\n segments: segments\n wildcard: wildcard\n key: key\n }\n\nmatchPath(pattern, path)\n parts = path.split(\"/\")\n if parts[0] != \"\"\n return null\n parts = parts.slice(1)\n count = pattern.segments.length\n if pattern.wildcard\n if parts.length <= count\n return null\n else\n if parts.length != count\n return null\n parameters = {}\n for pattern.segments as index: segment\n value = parts[index]\n if segment.startsWith(\"{\")\n if value == \"\"\n return null\n name = segment.slice(1, -1)\n parameters[name] = value\n else\n if segment != value\n return null\n return parameters\n\nmoreSpecific(candidate, current)\n if current == null\n return true\n if candidate.wildcard != current.wildcard\n return !candidate.wildcard\n first = candidate.segments\n second = current.segments\n count = first.length\n if second.length < count\n count = second.length\n for range(count) as index\n segment = first[index]\n alternative = second[index]\n literal = !segment.startsWith(\"{\")\n other = !alternative.startsWith(\"{\")\n if literal != other\n return literal\n return first.length > second.length\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}