@lango-project/lango-server 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/body_reader.mjs.map +1 -1
- package/dist/builder.mjs.map +1 -1
- package/dist/cli/server.mjs +3 -838
- package/dist/cli/server.mjs.map +1 -1
- package/dist/client_identity.mjs.map +1 -1
- package/dist/database.mjs.map +1 -1
- package/dist/database_action.mjs.map +1 -1
- package/dist/database_options.mjs.map +1 -1
- package/dist/database_scope.mjs.map +1 -1
- package/dist/endpoint.mjs.map +1 -1
- package/dist/error_details.mjs.map +1 -1
- package/dist/execution_failure.mjs.map +1 -1
- package/dist/execution_identity.mjs.map +1 -1
- package/dist/execution_log.mjs.map +1 -1
- package/dist/execution_runtime.mjs.map +1 -1
- package/dist/execution_worker.mjs.map +1 -1
- package/dist/executor.mjs.map +1 -1
- package/dist/group.mjs.map +1 -1
- package/dist/http_failure.mjs.map +1 -1
- package/dist/job_configuration.mjs.map +1 -1
- package/dist/job_context.mjs.map +1 -1
- package/dist/library.mjs.map +1 -1
- package/dist/longpoll_broker.mjs.map +1 -1
- package/dist/longpoll_options.mjs.map +1 -1
- package/dist/longpoll_session.mjs.map +1 -1
- package/dist/middleware.mjs.map +1 -1
- package/dist/module_loader.mjs.map +1 -1
- package/dist/options.mjs.map +1 -1
- package/dist/origin.mjs.map +1 -1
- package/dist/policy.mjs.map +1 -1
- package/dist/postgres_adapter.mjs.map +1 -1
- package/dist/postgres_worker.mjs.map +1 -1
- package/dist/queue_provider.mjs.map +1 -1
- package/dist/request_identity.mjs.map +1 -1
- package/dist/response.mjs.map +1 -1
- package/dist/route_info.mjs.map +1 -1
- package/dist/route_pattern.mjs.map +1 -1
- package/dist/routes.mjs.map +1 -1
- package/dist/runtime.mjs.map +1 -1
- package/dist/server.mjs.map +1 -1
- package/dist/server_context.mjs.map +1 -1
- package/dist/sqlite_adapter.mjs.map +1 -1
- package/dist/static_files.mjs.map +1 -1
- package/dist/token.mjs.map +1 -1
- package/dist/tokens.mjs.map +1 -1
- package/dist/trace.mjs.map +1 -1
- package/dist/worker.mjs.map +1 -1
- package/examples/security/package.json +1 -1
- package/package.json +6 -4
- package/dist/cli/.lango/bignumber.mjs +0 -3119
- package/dist/cli/.lango/localization.mjs +0 -108
- package/dist/cli/.lango/runtime.mjs +0 -725
- package/dist/cli/.lango/vendor/i18next.LICENSE +0 -21
- package/dist/cli/.lango/vendor/i18next.mjs +0 -2434
- package/dist/cli/.lango/xmldom/conventions.js +0 -429
- package/dist/cli/.lango/xmldom/dom-parser.js +0 -591
- package/dist/cli/.lango/xmldom/dom.js +0 -3759
- package/dist/cli/.lango/xmldom/entities.js +0 -2171
- package/dist/cli/.lango/xmldom/errors.js +0 -205
- package/dist/cli/.lango/xmldom/grammar.js +0 -559
- package/dist/cli/.lango/xmldom/index.js +0 -41
- package/dist/cli/.lango/xmldom/package.json +0 -1
- package/dist/cli/.lango/xmldom/sax.js +0 -983
- package/dist/cli/.lango/xmldom.LICENSE.md +0 -8
- package/dist/cli/body_reader.mjs +0 -180
- package/dist/cli/body_reader.mjs.map +0 -1
- package/dist/cli/client_identity.mjs +0 -250
- package/dist/cli/client_identity.mjs.map +0 -1
- package/dist/cli/database.mjs +0 -116
- package/dist/cli/database.mjs.map +0 -1
- package/dist/cli/database_options.mjs +0 -83
- package/dist/cli/database_options.mjs.map +0 -1
- package/dist/cli/database_scope.mjs +0 -93
- package/dist/cli/database_scope.mjs.map +0 -1
- package/dist/cli/endpoint.mjs +0 -50
- package/dist/cli/endpoint.mjs.map +0 -1
- package/dist/cli/error_details.mjs +0 -45
- package/dist/cli/error_details.mjs.map +0 -1
- package/dist/cli/longpoll_broker.mjs +0 -215
- package/dist/cli/longpoll_broker.mjs.map +0 -1
- package/dist/cli/longpoll_options.mjs +0 -103
- package/dist/cli/longpoll_options.mjs.map +0 -1
- package/dist/cli/longpoll_session.mjs +0 -136
- package/dist/cli/longpoll_session.mjs.map +0 -1
- package/dist/cli/middleware.mjs +0 -25
- package/dist/cli/middleware.mjs.map +0 -1
- package/dist/cli/options.mjs +0 -214
- package/dist/cli/options.mjs.map +0 -1
- package/dist/cli/origin.mjs +0 -87
- package/dist/cli/origin.mjs.map +0 -1
- package/dist/cli/policy.mjs +0 -121
- package/dist/cli/policy.mjs.map +0 -1
- package/dist/cli/postgres_adapter.mjs +0 -178
- package/dist/cli/postgres_adapter.mjs.map +0 -1
- package/dist/cli/route_pattern.mjs +0 -129
- package/dist/cli/route_pattern.mjs.map +0 -1
- package/dist/cli/routes.mjs +0 -360
- package/dist/cli/routes.mjs.map +0 -1
- package/dist/cli/sqlite_adapter.mjs +0 -163
- package/dist/cli/sqlite_adapter.mjs.map +0 -1
- package/dist/cli/static_files.mjs +0 -224
- package/dist/cli/static_files.mjs.map +0 -1
- package/dist/cli/trace.mjs +0 -53
- package/dist/cli/trace.mjs.map +0 -1
package/dist/cli/routes.mjs
DELETED
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
import { routePattern } from "./route_pattern.mjs";
|
|
2
|
-
import { contains } from "./options.mjs";
|
|
3
|
-
import { attributes } from "./options.mjs";
|
|
4
|
-
import { middlewareName } from "./middleware.mjs";
|
|
5
|
-
import { Endpoint } from "./endpoint.mjs";
|
|
6
|
-
import { longpollOptions } from "./longpoll_options.mjs";
|
|
7
|
-
import * as fs from "node:fs";
|
|
8
|
-
import * as path from "node:path";
|
|
9
|
-
import * as modules from "node:module";
|
|
10
|
-
import {
|
|
11
|
-
hostGlobal as __hostGlobal,
|
|
12
|
-
xml2obj as __xml2obj,
|
|
13
|
-
fromJson as __fromJson,
|
|
14
|
-
toJson as __toJson,
|
|
15
|
-
isNumber as __isNumber,
|
|
16
|
-
isString as __isString,
|
|
17
|
-
isBool as __isBool,
|
|
18
|
-
isObject as __isObject,
|
|
19
|
-
isArray as __isArray,
|
|
20
|
-
includes as __includes,
|
|
21
|
-
entries as __entries,
|
|
22
|
-
add as __add,
|
|
23
|
-
requireBoolean as __requireBoolean,
|
|
24
|
-
normalize as __normalize,
|
|
25
|
-
finite as __finite,
|
|
26
|
-
boundary as __boundary,
|
|
27
|
-
requireArity as __requireArity,
|
|
28
|
-
} from "./.lango/runtime.mjs";
|
|
29
|
-
|
|
30
|
-
export class Routes {
|
|
31
|
-
#root;
|
|
32
|
-
#items;
|
|
33
|
-
#jobs;
|
|
34
|
-
#events;
|
|
35
|
-
#middlewares;
|
|
36
|
-
constructor(root) {
|
|
37
|
-
__requireArity(arguments.length, [0], "constructor");
|
|
38
|
-
root = __boundary(root);
|
|
39
|
-
this.#root = __normalize(path.resolve(root));
|
|
40
|
-
this.#items = [];
|
|
41
|
-
this.#jobs = [];
|
|
42
|
-
this.#events = { };
|
|
43
|
-
this.#middlewares = __normalize(__hostGlobal(["Object"]).create(null));
|
|
44
|
-
}
|
|
45
|
-
endpoint(spec) {
|
|
46
|
-
__requireArity(arguments.length, [0], "endpoint");
|
|
47
|
-
spec = __boundary(spec);
|
|
48
|
-
let item = new Endpoint(spec);
|
|
49
|
-
this.#checkPath(__normalize(item.path));
|
|
50
|
-
__add(this.#items, { path: __normalize(item.path), module: resolveModule(__normalize(item.module), __normalize(this.#root)), handler: __normalize(item.handler), auth: __normalize(item.auth), policy: __normalize(item.policy), reauthSeconds: __normalize(item.reauthSeconds), reauthExplicit: __normalize(item.reauthExplicit), legacyAuth: __normalize(item.legacyAuth), middleware: __normalize(item.middleware) });
|
|
51
|
-
return this;
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
#checkPath(path) {
|
|
55
|
-
__requireArity(arguments.length, [0], "checkPath");
|
|
56
|
-
path = __boundary(path);
|
|
57
|
-
let pattern = routePattern(path);
|
|
58
|
-
for (const other of __normalize(this.#items)) {
|
|
59
|
-
if (__requireBoolean(__normalize(other.path) === path)) {
|
|
60
|
-
throw `Duplicate endpoint: ${path}`;
|
|
61
|
-
}
|
|
62
|
-
let existing = routePattern(__normalize(other.path));
|
|
63
|
-
if (__requireBoolean(__normalize(existing.key) === __normalize(pattern.key))) {
|
|
64
|
-
throw `Conflicting endpoint pattern: ${path}`;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return null;
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
job(spec) {
|
|
71
|
-
__requireArity(arguments.length, [0], "job");
|
|
72
|
-
spec = __boundary(spec);
|
|
73
|
-
let allowed = ["path", "module", "handler", "queue", "policy", "auth", "reauthSeconds"];
|
|
74
|
-
for (const [key, value] of __entries(spec)) {
|
|
75
|
-
if (__requireBoolean(!__requireBoolean(__normalize(allowed.includes(key))))) {
|
|
76
|
-
throw `Unknown job route option: ${key}`;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
let item = new Endpoint(spec);
|
|
80
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(item.path.includes("*"))) || __requireBoolean(__normalize(item.path.includes("{")))) || __requireBoolean(__normalize(item.path.includes("}"))))) {
|
|
81
|
-
throw "Job routes require an exact path";
|
|
82
|
-
}
|
|
83
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.queue)))) || __requireBoolean(__normalize(spec.queue.trim()) !== __normalize(spec.queue))) || __requireBoolean(__normalize(spec.queue) === ""))) {
|
|
84
|
-
throw "Job route requires a queue name";
|
|
85
|
-
}
|
|
86
|
-
for (const other of __normalize(this.#jobs)) {
|
|
87
|
-
if (__requireBoolean(__normalize(other.path) === __normalize(item.path))) {
|
|
88
|
-
throw `Duplicate job route: ${__normalize(item.path)}`;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
__add(this.#jobs, { path: __normalize(item.path), module: resolveModule(__normalize(item.module), __normalize(this.#root)), handler: __normalize(item.handler), queue: __normalize(spec.queue), policy: __normalize(item.policy), auth: __normalize(item.auth), reauthSeconds: __normalize(item.reauthSeconds), reauthExplicit: __normalize(item.reauthExplicit), legacyAuth: __normalize(item.legacyAuth) });
|
|
92
|
-
return this;
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
jobs() {
|
|
96
|
-
return __fromJson(__toJson(__normalize(this.#jobs)));
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
addMiddleware(name, spec) {
|
|
100
|
-
__requireArity(arguments.length, [0, 1], "addMiddleware");
|
|
101
|
-
name = __boundary(name);
|
|
102
|
-
spec = __boundary(spec);
|
|
103
|
-
middlewareName(name);
|
|
104
|
-
if (__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(__normalize(this.#middlewares), name)))) {
|
|
105
|
-
throw `Duplicate middleware: ${name}`;
|
|
106
|
-
}
|
|
107
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(spec))) || __requireBoolean(__isArray(spec)))) {
|
|
108
|
-
throw "Middleware requires a module and exported handler";
|
|
109
|
-
}
|
|
110
|
-
for (const [key, value] of __entries(spec)) {
|
|
111
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(key !== "module") && __requireBoolean(key !== "handler")) && __requireBoolean(key !== "validate"))) {
|
|
112
|
-
throw `Unknown middleware option: ${key}`;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.handler)))) || __requireBoolean(__normalize(spec.handler) === ""))) {
|
|
116
|
-
throw "Middleware handler is required";
|
|
117
|
-
}
|
|
118
|
-
if (__requireBoolean(__requireBoolean(__normalize(spec.validate) !== null) && __requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.validate)))) || __requireBoolean(__normalize(spec.validate) === "")))) {
|
|
119
|
-
throw "Middleware validate must name an exported function";
|
|
120
|
-
}
|
|
121
|
-
this.#middlewares[name] = { module: resolveModule(__normalize(spec.module), __normalize(this.#root)), handler: __normalize(spec.handler), validate: __normalize(spec.validate) };
|
|
122
|
-
return this;
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
middlewares() {
|
|
126
|
-
return __fromJson(__toJson(__normalize(this.#middlewares)));
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
longpoll(spec) {
|
|
130
|
-
__requireArity(arguments.length, [0], "longpoll");
|
|
131
|
-
spec = __boundary(spec);
|
|
132
|
-
let item = longpollOptions(spec);
|
|
133
|
-
this.#checkPath(__normalize(item.path));
|
|
134
|
-
__add(this.#items, item);
|
|
135
|
-
return this;
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
event(spec) {
|
|
139
|
-
__requireArity(arguments.length, [0], "event");
|
|
140
|
-
spec = __boundary(spec);
|
|
141
|
-
if (__requireBoolean(!__requireBoolean(contains(["register", "validate", "request"], __normalize(spec.name))))) {
|
|
142
|
-
throw `Unknown event: ${__normalize(spec.name)}`;
|
|
143
|
-
}
|
|
144
|
-
if (__requireBoolean(__includes(__normalize(spec.name), __normalize(this.#events)))) {
|
|
145
|
-
throw `Duplicate event: ${__normalize(spec.name)}`;
|
|
146
|
-
}
|
|
147
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.handler)))) || __requireBoolean(__normalize(spec.handler) === ""))) {
|
|
148
|
-
throw "Event handler is required";
|
|
149
|
-
}
|
|
150
|
-
this.#events[__normalize(spec.name)] = { module: resolveModule(__normalize(spec.module), __normalize(this.#root)), handler: __normalize(spec.handler) };
|
|
151
|
-
return this;
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
include(spec, auth = null, policy = null, reauthSeconds = null) {
|
|
155
|
-
__requireArity(arguments.length, [0], "include");
|
|
156
|
-
spec = __boundary(spec);
|
|
157
|
-
auth = __boundary(auth);
|
|
158
|
-
policy = __boundary(policy);
|
|
159
|
-
reauthSeconds = __boundary(reauthSeconds);
|
|
160
|
-
this.#includeAt(spec, __normalize(this.#root), "", [], auth, policy, reauthSeconds);
|
|
161
|
-
return this;
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
xml(file) {
|
|
165
|
-
__requireArity(arguments.length, [0], "xml");
|
|
166
|
-
file = __boundary(file);
|
|
167
|
-
this.#readXml(__normalize(path.resolve(file)), "", __normalize(this.#root), [], true);
|
|
168
|
-
return this;
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
definitions() {
|
|
172
|
-
return __fromJson(__toJson(__normalize(this.#items)));
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
events() {
|
|
176
|
-
return __fromJson(__toJson(__normalize(this.#events)));
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
#includeAt(spec, directory, prefix, stack, inheritedAuth = null, inheritedPolicy = null, inheritedReauthSeconds = null) {
|
|
180
|
-
__requireArity(arguments.length, [0, 1, 2, 3], "includeAt");
|
|
181
|
-
spec = __boundary(spec);
|
|
182
|
-
directory = __boundary(directory);
|
|
183
|
-
prefix = __boundary(prefix);
|
|
184
|
-
stack = __boundary(stack);
|
|
185
|
-
inheritedAuth = __boundary(inheritedAuth);
|
|
186
|
-
inheritedPolicy = __boundary(inheritedPolicy);
|
|
187
|
-
inheritedReauthSeconds = __boundary(inheritedReauthSeconds);
|
|
188
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.module)))) || __requireBoolean(__normalize(spec.module) === "")) || __requireBoolean(__normalize(spec.module.startsWith(".")))) || __requireBoolean(__normalize(spec.module.startsWith("/")))) || __requireBoolean(__normalize(spec.module.startsWith("node:"))))) {
|
|
189
|
-
throw "Include requires an npm package name";
|
|
190
|
-
}
|
|
191
|
-
let mount = __normalize(spec.path);
|
|
192
|
-
if (__requireBoolean(mount === null)) {
|
|
193
|
-
mount = "/";
|
|
194
|
-
}
|
|
195
|
-
if (__requireBoolean(!__requireBoolean(__isString(mount)))) {
|
|
196
|
-
throw "Include path must be a string";
|
|
197
|
-
}
|
|
198
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__normalize(mount.includes("*"))) || __requireBoolean(__normalize(mount.includes("//")))) || __requireBoolean(__normalize(mount.includes("?")))) || __requireBoolean(__normalize(mount.includes("#")))) || __requireBoolean(__normalize(mount.includes("\\"))))) {
|
|
199
|
-
throw "Invalid include prefix";
|
|
200
|
-
}
|
|
201
|
-
if (__requireBoolean(__requireBoolean(__normalize(mount.endsWith("/"))) && __requireBoolean(mount !== "/"))) {
|
|
202
|
-
mount = __normalize(mount.slice(0, __finite(-1)));
|
|
203
|
-
}
|
|
204
|
-
let combined = joinPath(prefix, mount);
|
|
205
|
-
if (__requireBoolean(combined === "/")) {
|
|
206
|
-
combined = "";
|
|
207
|
-
}
|
|
208
|
-
let file = resolveModule(`${__normalize(spec.module)}/routes.xml`, directory);
|
|
209
|
-
this.#readXml(file, combined, __normalize(path.dirname(file)), stack, false, inheritedAuth, inheritedPolicy, inheritedReauthSeconds);
|
|
210
|
-
return null;
|
|
211
|
-
return null;
|
|
212
|
-
}
|
|
213
|
-
#readXml(file, prefix, directory, stack, allowEvents, inheritedAuth = null, inheritedPolicy = null, inheritedReauthSeconds = null) {
|
|
214
|
-
__requireArity(arguments.length, [0, 1, 2, 3, 4], "readXml");
|
|
215
|
-
file = __boundary(file);
|
|
216
|
-
prefix = __boundary(prefix);
|
|
217
|
-
directory = __boundary(directory);
|
|
218
|
-
stack = __boundary(stack);
|
|
219
|
-
allowEvents = __boundary(allowEvents);
|
|
220
|
-
inheritedAuth = __boundary(inheritedAuth);
|
|
221
|
-
inheritedPolicy = __boundary(inheritedPolicy);
|
|
222
|
-
inheritedReauthSeconds = __boundary(inheritedReauthSeconds);
|
|
223
|
-
let real = __normalize(fs.realpathSync(file));
|
|
224
|
-
if (__requireBoolean(__normalize(stack.includes(real)))) {
|
|
225
|
-
throw `Route include cycle: ${real}`;
|
|
226
|
-
}
|
|
227
|
-
let root = __xml2obj(__normalize(fs.readFileSync(real, "utf8")));
|
|
228
|
-
if (__requireBoolean(__normalize(root.tag()) !== "routes")) {
|
|
229
|
-
throw `Expected routes root: ${real}`;
|
|
230
|
-
}
|
|
231
|
-
attributes(root, []);
|
|
232
|
-
let nextStack = __normalize(stack.slice());
|
|
233
|
-
__add(nextStack, real);
|
|
234
|
-
this.#collect(root, prefix, null, inheritedAuth, directory, nextStack, allowEvents, inheritedPolicy, inheritedReauthSeconds);
|
|
235
|
-
return null;
|
|
236
|
-
return null;
|
|
237
|
-
}
|
|
238
|
-
#collect(parent, prefix, inheritedModule, inheritedAuth, directory, stack, allowEvents, inheritedPolicy = null, inheritedReauthSeconds = null) {
|
|
239
|
-
__requireArity(arguments.length, [0, 1, 2, 3, 4, 5, 6], "collect");
|
|
240
|
-
parent = __boundary(parent);
|
|
241
|
-
prefix = __boundary(prefix);
|
|
242
|
-
inheritedModule = __boundary(inheritedModule);
|
|
243
|
-
inheritedAuth = __boundary(inheritedAuth);
|
|
244
|
-
directory = __boundary(directory);
|
|
245
|
-
stack = __boundary(stack);
|
|
246
|
-
allowEvents = __boundary(allowEvents);
|
|
247
|
-
inheritedPolicy = __boundary(inheritedPolicy);
|
|
248
|
-
inheritedReauthSeconds = __boundary(inheritedReauthSeconds);
|
|
249
|
-
if (__requireBoolean(__normalize(__normalize(parent.innerText()).trim()) !== "")) {
|
|
250
|
-
throw "Route XML cannot contain text";
|
|
251
|
-
}
|
|
252
|
-
for (const tag of __normalize(parent.children())) {
|
|
253
|
-
let spec = __normalize(tag.attributes());
|
|
254
|
-
let mod = __normalize(spec.module);
|
|
255
|
-
let auth = __normalize(spec.auth);
|
|
256
|
-
let policy = __normalize(spec.policy);
|
|
257
|
-
let reauthSeconds = __normalize(spec.reauthSeconds);
|
|
258
|
-
if (__requireBoolean(mod === null)) {
|
|
259
|
-
mod = inheritedModule;
|
|
260
|
-
}
|
|
261
|
-
if (__requireBoolean(__requireBoolean(auth === null) && __requireBoolean(policy === null))) {
|
|
262
|
-
auth = inheritedAuth;
|
|
263
|
-
policy = inheritedPolicy;
|
|
264
|
-
}
|
|
265
|
-
if (__requireBoolean(reauthSeconds === null)) {
|
|
266
|
-
reauthSeconds = inheritedReauthSeconds;
|
|
267
|
-
}
|
|
268
|
-
if (__normalize(tag.tag()) === "job") {
|
|
269
|
-
attributes(tag, ["path", "module", "handler", "queue", "auth", "policy", "reauthSeconds"]);
|
|
270
|
-
leaf(tag);
|
|
271
|
-
this.job({ path: joinPath(prefix, __normalize(spec.path)), module: resolveModule(mod, directory), handler: __normalize(spec.handler), queue: __normalize(spec.queue), auth: auth, policy: policy, reauthSeconds: reauthSeconds });
|
|
272
|
-
} else if (__normalize(tag.tag()) === "endpoint") {
|
|
273
|
-
attributes(tag, ["path", "module", "handler", "auth", "policy", "reauthSeconds"]);
|
|
274
|
-
leaf(tag);
|
|
275
|
-
this.endpoint({ path: joinPath(prefix, __normalize(spec.path)), module: resolveModule(mod, directory), handler: __normalize(spec.handler), auth: auth, policy: policy, reauthSeconds: reauthSeconds });
|
|
276
|
-
} else if (__normalize(tag.tag()) === "longpoll") {
|
|
277
|
-
attributes(tag, ["path", "auth", "policy", "reauthSeconds", "waitTimeoutMs", "retentionMs", "maxMessages", "fallback"]);
|
|
278
|
-
leaf(tag);
|
|
279
|
-
spec.path = joinPath(prefix, __normalize(spec.path));
|
|
280
|
-
spec.auth = auth;
|
|
281
|
-
spec.policy = policy;
|
|
282
|
-
spec.reauthSeconds = reauthSeconds;
|
|
283
|
-
if (__requireBoolean(__normalize(spec.fallback) !== null)) {
|
|
284
|
-
spec.fallback = joinPath(prefix, __normalize(spec.fallback));
|
|
285
|
-
}
|
|
286
|
-
this.longpoll(spec);
|
|
287
|
-
} else if (__normalize(tag.tag()) === "group") {
|
|
288
|
-
attributes(tag, ["path", "module", "auth", "policy", "reauthSeconds"]);
|
|
289
|
-
this.#collect(tag, joinPath(prefix, __normalize(spec.path)), mod, auth, directory, stack, false, policy, reauthSeconds);
|
|
290
|
-
} else if (__normalize(tag.tag()) === "include") {
|
|
291
|
-
attributes(tag, ["module", "path"]);
|
|
292
|
-
leaf(tag);
|
|
293
|
-
this.#includeAt(spec, directory, prefix, stack, auth, policy, reauthSeconds);
|
|
294
|
-
} else if (__normalize(tag.tag()) === "middleware") {
|
|
295
|
-
attributes(tag, ["name", "module", "handler", "validate"]);
|
|
296
|
-
leaf(tag);
|
|
297
|
-
if (__requireBoolean(!__requireBoolean(allowEvents))) {
|
|
298
|
-
throw "Middleware declarations are only allowed in the application's root routes.xml";
|
|
299
|
-
}
|
|
300
|
-
this.addMiddleware(__normalize(spec.name), { module: resolveModule(__normalize(spec.module), directory), handler: __normalize(spec.handler), validate: __normalize(spec.validate) });
|
|
301
|
-
} else if (__normalize(tag.tag()) === "event") {
|
|
302
|
-
attributes(tag, ["name", "module", "handler"]);
|
|
303
|
-
leaf(tag);
|
|
304
|
-
if (__requireBoolean(!__requireBoolean(allowEvents))) {
|
|
305
|
-
throw "Events are only allowed in the application's root routes.xml";
|
|
306
|
-
}
|
|
307
|
-
this.event({ name: __normalize(spec.name), module: resolveModule(__normalize(spec.module), directory), handler: __normalize(spec.handler) });
|
|
308
|
-
} else {
|
|
309
|
-
attributes(tag, ["path", "module", "handler", "auth", "policy", "reauthSeconds"]);
|
|
310
|
-
leaf(tag);
|
|
311
|
-
this.endpoint({ path: joinPath(prefix, __normalize(spec.path)), module: resolveModule(mod, directory), handler: __normalize(spec.handler), auth: auth, policy: policy, reauthSeconds: reauthSeconds, middleware: __normalize(tag.tag()) });
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
return null;
|
|
315
|
-
return null;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
function resolveModule(name, directory) {
|
|
319
|
-
__requireArity(arguments.length, [0, 1], "resolveModule");
|
|
320
|
-
name = __boundary(name);
|
|
321
|
-
directory = __boundary(directory);
|
|
322
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(name))) || __requireBoolean(name === "")) || __requireBoolean(__normalize(name.startsWith("node:"))))) {
|
|
323
|
-
throw "Application module is required";
|
|
324
|
-
}
|
|
325
|
-
let resolver = __normalize(modules.createRequire(__normalize(path.join(directory, "package.json"))));
|
|
326
|
-
let resolved = __normalize(resolver.resolve(name));
|
|
327
|
-
if (__requireBoolean(!__requireBoolean(__normalize(path.isAbsolute(resolved))))) {
|
|
328
|
-
throw `Application module must resolve to a file: ${name}`;
|
|
329
|
-
}
|
|
330
|
-
return resolved;
|
|
331
|
-
return null;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
function joinPath(prefix, suffix) {
|
|
335
|
-
__requireArity(arguments.length, [0, 1], "joinPath");
|
|
336
|
-
prefix = __boundary(prefix);
|
|
337
|
-
suffix = __boundary(suffix);
|
|
338
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(suffix))) || __requireBoolean(!__requireBoolean(__normalize(suffix.startsWith("/")))))) {
|
|
339
|
-
throw "Route path must begin with /";
|
|
340
|
-
}
|
|
341
|
-
if (__requireBoolean(__requireBoolean(prefix === "") || __requireBoolean(prefix === "/"))) {
|
|
342
|
-
return suffix;
|
|
343
|
-
}
|
|
344
|
-
if (__requireBoolean(suffix === "/")) {
|
|
345
|
-
return `${prefix}/`;
|
|
346
|
-
}
|
|
347
|
-
return `${prefix}${suffix}`;
|
|
348
|
-
return null;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
function leaf(tag) {
|
|
352
|
-
__requireArity(arguments.length, [0], "leaf");
|
|
353
|
-
tag = __boundary(tag);
|
|
354
|
-
if (__requireBoolean(__requireBoolean(__normalize(__normalize(tag.children()).length) !== 0) || __requireBoolean(__normalize(__normalize(tag.innerText()).trim()) !== ""))) {
|
|
355
|
-
throw `Expected an empty ${__normalize(tag.tag())} element`;
|
|
356
|
-
}
|
|
357
|
-
return null;
|
|
358
|
-
return null;
|
|
359
|
-
}
|
|
360
|
-
//# sourceMappingURL=routes.mjs.map
|
package/dist/cli/routes.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routes.mjs","sources":["routes.lango"],"sourcesContent":["import \"./route_pattern\"\n routePattern(path)\nimport \"./options\"\n contains(items, value)\nimport js \"node:fs\" as fs\nimport js \"node:path\" as path\nimport js \"node:module\" as modules\nimport \"./options\"\n attributes(tag, allowed)\nimport js global Object\nimport \"./middleware\"\n middlewareName(name)\nimport \"./endpoint\"\n class Endpoint\n\nimport \"./longpoll_options\"\n longpollOptions(spec)\n\nexport class Routes(root)\n methods\n endpoint(spec)\n job(spec)\n jobs()\n addMiddleware(name, spec)\n middlewares()\n longpoll(spec)\n include(spec, auth = null, policy = null, reauthSeconds = null)\n xml(file)\n definitions()\n events()\n event(spec)\n\nRoutes(root)\n @root = path/resolve(root)\n @items = []\n @jobs = []\n @events = {}\n @middlewares = Object/create(null)\n\nRoutes:endpoint(spec)\n item = new Endpoint(spec)\n checkPath(item.path)\n @items.add({\n path: item.path\n module: resolveModule(item.module, @root)\n handler: item.handler\n auth: item.auth\n policy: item.policy\n reauthSeconds: item.reauthSeconds\n reauthExplicit: item.reauthExplicit\n legacyAuth: item.legacyAuth\n middleware: item.middleware\n })\n return @this\n\nRoutes:checkPath(path)\n pattern = routePattern(path)\n for @items as other\n if other.path == path\n throw \"Duplicate endpoint: ${path}\"\n existing = routePattern(other.path)\n if existing.key == pattern.key\n throw \"Conflicting endpoint pattern: ${path}\"\n return null\n\nRoutes:job(spec)\n allowed = [\"path\", \"module\", \"handler\", \"queue\", \"policy\", \"auth\", \"reauthSeconds\"]\n for spec as key: value\n if !allowed.includes(key)\n throw \"Unknown job route option: ${key}\"\n item = new Endpoint(spec)\n if item.path.includes(\"*\") or item.path.includes(\"{\") or item.path.includes(\"}\")\n throw \"Job routes require an exact path\"\n if !is_string(spec.queue) or spec.queue.trim() != spec.queue or spec.queue == \"\"\n throw \"Job route requires a queue name\"\n for @jobs as other\n if other.path == item.path\n throw \"Duplicate job route: ${item.path}\"\n @jobs.add({\n path: item.path\n module: resolveModule(item.module, @root)\n handler: item.handler\n queue: spec.queue\n policy: item.policy\n auth: item.auth\n reauthSeconds: item.reauthSeconds\n reauthExplicit: item.reauthExplicit\n legacyAuth: item.legacyAuth\n })\n return @this\n\nRoutes:jobs()\n return from_json(to_json(@jobs))\n\nRoutes:addMiddleware(name, spec)\n middlewareName(name)\n if Object/hasOwn(@middlewares, name)\n throw \"Duplicate middleware: ${name}\"\n if !is_object(spec) or is_array(spec)\n throw \"Middleware requires a module and exported handler\"\n for spec as key: value\n if key != \"module\" and key != \"handler\" and key != \"validate\"\n throw \"Unknown middleware option: ${key}\"\n if !is_string(spec.handler) or spec.handler == \"\"\n throw \"Middleware handler is required\"\n if spec.validate != null and (!is_string(spec.validate) or spec.validate == \"\")\n throw \"Middleware validate must name an exported function\"\n @middlewares[name] = {\n module: resolveModule(spec.module, @root)\n handler: spec.handler\n validate: spec.validate\n }\n return @this\n\nRoutes:middlewares()\n return from_json(to_json(@middlewares))\n\nRoutes:longpoll(spec)\n item = longpollOptions(spec)\n checkPath(item.path)\n @items.add(item)\n return @this\n\nRoutes:event(spec)\n if !contains([\"register\", \"validate\", \"request\"], spec.name)\n throw \"Unknown event: ${spec.name}\"\n if spec.name in @events\n throw \"Duplicate event: ${spec.name}\"\n if !is_string(spec.handler) or spec.handler == \"\"\n throw \"Event handler is required\"\n @events[spec.name] = {\n module: resolveModule(spec.module, @root)\n handler: spec.handler\n }\n return @this\n\nRoutes:include(spec, auth = null, policy = null, reauthSeconds = null)\n includeAt(spec, @root, \"\", [], auth, policy, reauthSeconds)\n return @this\n\nRoutes:xml(file)\n readXml(path/resolve(file), \"\", @root, [], true)\n return @this\n\nRoutes:definitions()\n return from_json(to_json(@items))\n\nRoutes:events()\n return from_json(to_json(@events))\n\nresolveModule(name, directory)\n if !is_string(name) or name == \"\" or name.startsWith(\"node:\")\n throw \"Application module is required\"\n resolver = modules/createRequire(path/join(directory, \"package.json\"))\n resolved = resolver.resolve(name)\n if !path/isAbsolute(resolved)\n throw \"Application module must resolve to a file: ${name}\"\n return resolved\n\njoinPath(prefix, suffix)\n if !is_string(suffix) or !suffix.startsWith(\"/\")\n throw \"Route path must begin with /\"\n if prefix == \"\" or prefix == \"/\"\n return suffix\n if suffix == \"/\"\n return \"${prefix}/\"\n return \"${prefix}${suffix}\"\n\nRoutes:includeAt(spec, directory, prefix, stack, inheritedAuth = null, inheritedPolicy = null, inheritedReauthSeconds = null)\n if !is_string(spec.module) or spec.module == \"\" or spec.module.startsWith(\".\") or spec.module.startsWith(\"/\") or spec.module.startsWith(\"node:\")\n throw \"Include requires an npm package name\"\n mount = spec.path\n if mount == null\n mount = \"/\"\n if !is_string(mount)\n throw \"Include path must be a string\"\n if mount.includes(\"*\") or mount.includes(\"//\") or mount.includes(\"?\") or mount.includes(\"#\") or mount.includes(\"\\\\\")\n throw \"Invalid include prefix\"\n if mount.endsWith(\"/\") and mount != \"/\"\n mount = mount.slice(0, -1)\n combined = joinPath(prefix, mount)\n if combined == \"/\"\n combined = \"\"\n file = resolveModule(\"${spec.module}/routes.xml\", directory)\n readXml(file, combined, path/dirname(file), stack, false, inheritedAuth, inheritedPolicy, inheritedReauthSeconds)\n return null\n\nRoutes:readXml(file, prefix, directory, stack, allowEvents, inheritedAuth = null, inheritedPolicy = null, inheritedReauthSeconds = null)\n real = fs/realpathSync(file)\n if stack.includes(real)\n throw \"Route include cycle: ${real}\"\n root = xml2obj(fs/readFileSync(real, \"utf8\"))\n if root.tag() != \"routes\"\n throw \"Expected routes root: ${real}\"\n attributes(root, [])\n nextStack = stack.slice()\n nextStack.add(real)\n collect(root, prefix, null, inheritedAuth, directory, nextStack, allowEvents, inheritedPolicy, inheritedReauthSeconds)\n return null\n\nRoutes:collect(parent, prefix, inheritedModule, inheritedAuth, directory, stack, allowEvents, inheritedPolicy = null, inheritedReauthSeconds = null)\n if parent.innerText().trim() != \"\"\n throw \"Route XML cannot contain text\"\n for parent.children() as tag\n spec = tag.attributes()\n mod = spec.module\n auth = spec.auth\n policy = spec.policy\n reauthSeconds = spec.reauthSeconds\n if mod == null\n mod = inheritedModule\n if auth == null and policy == null\n auth = inheritedAuth\n policy = inheritedPolicy\n if reauthSeconds == null\n reauthSeconds = inheritedReauthSeconds\n switch tag.tag()\n case \"job\"\n attributes(tag, [\"path\", \"module\", \"handler\", \"queue\", \"auth\", \"policy\", \"reauthSeconds\"])\n leaf(tag)\n job({\n path: joinPath(prefix, spec.path)\n module: resolveModule(mod, directory)\n handler: spec.handler\n queue: spec.queue\n auth: auth\n policy: policy\n reauthSeconds: reauthSeconds\n })\n case \"endpoint\"\n attributes(tag, [\"path\", \"module\", \"handler\", \"auth\", \"policy\", \"reauthSeconds\"])\n leaf(tag)\n endpoint({\n path: joinPath(prefix, spec.path)\n module: resolveModule(mod, directory)\n handler: spec.handler\n auth: auth\n policy: policy\n reauthSeconds: reauthSeconds\n })\n case \"longpoll\"\n attributes(tag, [\"path\", \"auth\", \"policy\", \"reauthSeconds\", \"waitTimeoutMs\", \"retentionMs\", \"maxMessages\", \"fallback\"])\n leaf(tag)\n spec.path = joinPath(prefix, spec.path)\n spec.auth = auth\n spec.policy = policy\n spec.reauthSeconds = reauthSeconds\n if spec.fallback != null\n spec.fallback = joinPath(prefix, spec.fallback)\n longpoll(spec)\n case \"group\"\n attributes(tag, [\"path\", \"module\", \"auth\", \"policy\", \"reauthSeconds\"])\n collect(tag, joinPath(prefix, spec.path), mod, auth, directory, stack, false, policy, reauthSeconds)\n case \"include\"\n attributes(tag, [\"module\", \"path\"])\n leaf(tag)\n includeAt(spec, directory, prefix, stack, auth, policy, reauthSeconds)\n case \"middleware\"\n attributes(tag, [\"name\", \"module\", \"handler\", \"validate\"])\n leaf(tag)\n if !allowEvents\n throw \"Middleware declarations are only allowed in the application's root routes.xml\"\n addMiddleware(spec.name, {\n module: resolveModule(spec.module, directory)\n handler: spec.handler\n validate: spec.validate\n })\n case \"event\"\n attributes(tag, [\"name\", \"module\", \"handler\"])\n leaf(tag)\n if !allowEvents\n throw \"Events are only allowed in the application's root routes.xml\"\n event({\n name: spec.name\n module: resolveModule(spec.module, directory)\n handler: spec.handler\n })\n else\n attributes(tag, [\"path\", \"module\", \"handler\", \"auth\", \"policy\", \"reauthSeconds\"])\n leaf(tag)\n endpoint({\n path: joinPath(prefix, spec.path)\n module: resolveModule(mod, directory)\n handler: spec.handler\n auth: auth\n policy: policy\n reauthSeconds: reauthSeconds\n middleware: tag.tag()\n })\n return null\n\nleaf(tag)\n if tag.children().length != 0 or tag.innerText().trim() != \"\"\n throw \"Expected an empty ${tag.tag()} element\"\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoIA;;;;;;;;;;;;;;;;AASA;;;;;;;;;;;;;;;;;AAoIA;;;;;;;;;;"}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
hostGlobal as __hostGlobal,
|
|
5
|
-
hostGlobalCall as __hostGlobalCall,
|
|
6
|
-
isNumber as __isNumber,
|
|
7
|
-
isString as __isString,
|
|
8
|
-
isBool as __isBool,
|
|
9
|
-
isObject as __isObject,
|
|
10
|
-
isArray as __isArray,
|
|
11
|
-
entries as __entries,
|
|
12
|
-
requireBoolean as __requireBoolean,
|
|
13
|
-
normalize as __normalize,
|
|
14
|
-
finite as __finite,
|
|
15
|
-
numericAdd as __numericAdd,
|
|
16
|
-
boundary as __boundary,
|
|
17
|
-
requireArity as __requireArity,
|
|
18
|
-
} from "./.lango/runtime.mjs";
|
|
19
|
-
|
|
20
|
-
export class SqliteAdapter {
|
|
21
|
-
parameterStyle;
|
|
22
|
-
#connection;
|
|
23
|
-
#depth;
|
|
24
|
-
#state;
|
|
25
|
-
constructor(mod, settings) {
|
|
26
|
-
__requireArity(arguments.length, [0, 1], "constructor");
|
|
27
|
-
mod = __boundary(mod);
|
|
28
|
-
settings = __boundary(settings);
|
|
29
|
-
if (__requireBoolean(__normalize(settings.file) !== ":memory:")) {
|
|
30
|
-
__normalize(fs.mkdirSync(__normalize(path.dirname(__normalize(settings.file))), { recursive: true }));
|
|
31
|
-
}
|
|
32
|
-
this.#connection = __normalize(__hostGlobal(["Reflect"]).construct(__normalize(mod.DatabaseSync), [__normalize(settings.file)]));
|
|
33
|
-
this.#depth = 0;
|
|
34
|
-
this.#state = null;
|
|
35
|
-
this.parameterStyle = "named";
|
|
36
|
-
try {
|
|
37
|
-
__normalize(this.#connection.exec(`PRAGMA busy_timeout=${__normalize(settings.busyTimeoutMs)}`));
|
|
38
|
-
__normalize(this.#connection.exec("PRAGMA foreign_keys=ON"));
|
|
39
|
-
let modeQuery = __normalize(this.#connection.prepare("PRAGMA journal_mode"));
|
|
40
|
-
let mode = __normalize(modeQuery.get());
|
|
41
|
-
if (__requireBoolean(__requireBoolean(__normalize(settings.file) !== ":memory:") && __requireBoolean(__normalize(mode.journal_mode) !== "wal"))) {
|
|
42
|
-
__normalize(this.#connection.exec("PRAGMA journal_mode=WAL"));
|
|
43
|
-
}
|
|
44
|
-
} catch (error) {
|
|
45
|
-
__normalize(this.#connection.close());
|
|
46
|
-
throw "SQLite initialization failed";
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
execute(sql, parameters) {
|
|
50
|
-
__requireArity(arguments.length, [0, 1], "execute");
|
|
51
|
-
sql = __boundary(sql);
|
|
52
|
-
parameters = __boundary(parameters);
|
|
53
|
-
let bound = { };
|
|
54
|
-
for (const [name, value] of __entries(parameters)) {
|
|
55
|
-
if (__requireBoolean(__isBool(value))) {
|
|
56
|
-
bound[name] = __hostGlobalCall(["Number"], value);
|
|
57
|
-
} else {
|
|
58
|
-
bound[name] = value;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
let statement = __normalize(this.#connection.prepare(sql));
|
|
62
|
-
__normalize(statement.setReadBigInts(true));
|
|
63
|
-
let columns = __normalize(statement.columns());
|
|
64
|
-
if (__requireBoolean(__normalize(columns.length) > 0)) {
|
|
65
|
-
let records = __normalize(statement.all(bound));
|
|
66
|
-
for (const row of records) {
|
|
67
|
-
for (const [name, value] of __entries(row)) {
|
|
68
|
-
row[name] = normalizeInteger(value);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return { rows: records, changes: null, lastInsertRowid: null };
|
|
72
|
-
}
|
|
73
|
-
let result = __normalize(statement.run(bound));
|
|
74
|
-
let changes = null;
|
|
75
|
-
let generated = null;
|
|
76
|
-
let operation = __normalize(sql.trim());
|
|
77
|
-
operation = __normalize(operation.toLowerCase());
|
|
78
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__normalize(operation.startsWith("insert"))) || __requireBoolean(__normalize(operation.startsWith("update")))) || __requireBoolean(__normalize(operation.startsWith("delete")))) || __requireBoolean(__normalize(operation.startsWith("with"))))) {
|
|
79
|
-
changes = normalizeInteger(__normalize(result.changes));
|
|
80
|
-
}
|
|
81
|
-
if (__requireBoolean(__requireBoolean(__normalize(operation.startsWith("insert"))) && __requireBoolean(changes === 1))) {
|
|
82
|
-
generated = normalizeInteger(__normalize(result.lastInsertRowid));
|
|
83
|
-
}
|
|
84
|
-
return { rows: [], changes: changes, lastInsertRowid: generated };
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
begin() {
|
|
88
|
-
if (__requireBoolean(__requireBoolean(__normalize(this.#depth) === 0) && __requireBoolean(!__requireBoolean(__normalize(this.#connection.isTransaction))))) {
|
|
89
|
-
__normalize(this.#connection.exec("BEGIN"));
|
|
90
|
-
}
|
|
91
|
-
this.#depth = __numericAdd(__normalize(this.#depth), 1);
|
|
92
|
-
if (__requireBoolean(__normalize(this.#state) === null)) {
|
|
93
|
-
this.#state = "active";
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
commit() {
|
|
99
|
-
if (__requireBoolean(__normalize(this.#depth) === 0)) {
|
|
100
|
-
throw new (__hostGlobal(["Error"]))("NoActiveTransaction");
|
|
101
|
-
}
|
|
102
|
-
if (__requireBoolean(__normalize(this.#depth) > 1)) {
|
|
103
|
-
this.#depth = __finite(__normalize(this.#depth) - 1);
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
if (__requireBoolean(__normalize(this.#state) === "rollback_only")) {
|
|
107
|
-
this.rollback();
|
|
108
|
-
throw new (__hostGlobal(["Error"]))("TransactionRolledBack");
|
|
109
|
-
}
|
|
110
|
-
__normalize(this.#connection.exec("COMMIT"));
|
|
111
|
-
this.#depth = 0;
|
|
112
|
-
this.#state = null;
|
|
113
|
-
return null;
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
rollback() {
|
|
117
|
-
if (__requireBoolean(__normalize(this.#depth) > 1)) {
|
|
118
|
-
this.#depth = __finite(__normalize(this.#depth) - 1);
|
|
119
|
-
this.#state = "rollback_only";
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
if (__requireBoolean(__normalize(this.#connection.isTransaction))) {
|
|
123
|
-
__normalize(this.#connection.exec("ROLLBACK"));
|
|
124
|
-
}
|
|
125
|
-
this.#depth = 0;
|
|
126
|
-
this.#state = null;
|
|
127
|
-
return null;
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
transactionState() {
|
|
131
|
-
if (__requireBoolean(!__requireBoolean(__normalize(this.#connection.isTransaction)))) {
|
|
132
|
-
this.#depth = 0;
|
|
133
|
-
this.#state = null;
|
|
134
|
-
}
|
|
135
|
-
if (__requireBoolean(__requireBoolean(__normalize(this.#connection.isTransaction)) && __requireBoolean(__normalize(this.#state) === null))) {
|
|
136
|
-
return "active";
|
|
137
|
-
}
|
|
138
|
-
return __normalize(this.#state);
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
close() {
|
|
142
|
-
__loop1: while (__requireBoolean(this.transactionState() !== null)) {
|
|
143
|
-
this.rollback();
|
|
144
|
-
}
|
|
145
|
-
__normalize(this.#connection.close());
|
|
146
|
-
return null;
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function normalizeInteger(value) {
|
|
151
|
-
__requireArity(arguments.length, [0], "normalizeInteger");
|
|
152
|
-
value = __boundary(value);
|
|
153
|
-
if (__requireBoolean(__normalize(__hostGlobal(["Object"]).prototype.toString.call(value)) !== "[object BigInt]")) {
|
|
154
|
-
return value;
|
|
155
|
-
}
|
|
156
|
-
let number = __hostGlobalCall(["Number"], value);
|
|
157
|
-
if (__requireBoolean(__normalize(__hostGlobal(["Number"]).isSafeInteger(number)))) {
|
|
158
|
-
return number;
|
|
159
|
-
}
|
|
160
|
-
return `${value}`;
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
//# sourceMappingURL=sqlite_adapter.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite_adapter.mjs","sources":["sqlite_adapter.lango"],"sourcesContent":["import js global Error\nimport js \"node:fs\" as fs\nimport js \"node:path\" as path\nimport js global Reflect\nimport js global Object\nimport js global Number\n\nexport class SqliteAdapter(mod, settings)\n properties\n parameterStyle\n methods\n execute(sql, parameters)\n begin()\n commit()\n rollback()\n transactionState()\n close()\n\nSqliteAdapter(mod, settings)\n if settings.file != \":memory:\"\n fs/mkdirSync(path/dirname(settings.file), {\n recursive: true\n })\n @connection = Reflect/construct(mod.DatabaseSync, [settings.file])\n @depth = 0\n @state = null\n @parameterStyle = \"named\"\n try\n @connection.exec(\"PRAGMA busy_timeout=${settings.busyTimeoutMs}\")\n @connection.exec(\"PRAGMA foreign_keys=ON\")\n modeQuery = @connection.prepare(\"PRAGMA journal_mode\")\n mode = modeQuery.get()\n if settings.file != \":memory:\" and mode.journal_mode != \"wal\"\n @connection.exec(\"PRAGMA journal_mode=WAL\")\n catch error\n @connection.close()\n throw \"SQLite initialization failed\"\n\nSqliteAdapter:execute(sql, parameters)\n bound = {}\n for parameters as name: value\n if is_bool(value)\n bound[name] = Number(value)\n else\n bound[name] = value\n statement = @connection.prepare(sql)\n statement.setReadBigInts(true)\n columns = statement.columns()\n if columns.length > 0\n records = statement.all(bound)\n for records as row\n for row as name: value\n row[name] = normalizeInteger(value)\n return {\n rows: records\n changes: null\n lastInsertRowid: null\n }\n result = statement.run(bound)\n changes = null\n generated = null\n operation = sql.trim()\n operation = operation.toLowerCase()\n if operation.startsWith(\"insert\") or operation.startsWith(\"update\") or operation.startsWith(\"delete\") or operation.startsWith(\"with\")\n changes = normalizeInteger(result.changes)\n if operation.startsWith(\"insert\") and changes == 1\n generated = normalizeInteger(result.lastInsertRowid)\n return {\n rows: []\n changes: changes\n lastInsertRowid: generated\n }\n\nSqliteAdapter:begin()\n if @depth == 0 and !@connection.isTransaction\n @connection.exec(\"BEGIN\")\n @depth = @depth + 1\n if @state == null\n @state = \"active\"\n return null\n\nSqliteAdapter:commit()\n if @depth == 0\n throw new Error(\"NoActiveTransaction\")\n if @depth > 1\n @depth = @depth - 1\n return null\n if @state == \"rollback_only\"\n rollback()\n throw new Error(\"TransactionRolledBack\")\n @connection.exec(\"COMMIT\")\n @depth = 0\n @state = null\n return null\n\nSqliteAdapter:rollback()\n if @depth > 1\n @depth = @depth - 1\n @state = \"rollback_only\"\n return null\n if @connection.isTransaction\n @connection.exec(\"ROLLBACK\")\n @depth = 0\n @state = null\n return null\n\nSqliteAdapter:transactionState()\n if !@connection.isTransaction\n @depth = 0\n @state = null\n if @connection.isTransaction and @state == null\n return \"active\"\n return @state\n\nSqliteAdapter:close()\n loop while transactionState() != null\n rollback()\n @connection.close()\n return null\n\nnormalizeInteger(value)\n if Object/prototype/toString/call(value) != \"[object BigInt]\"\n return value\n number = Number(value)\n if Number/isSafeInteger(number)\n return number\n return \"${value}\"\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiHA;;;;;;;;;;;;;;"}
|