@lango-project/lango-server 0.0.0-stage → 0.1.0

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/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +431 -2
  4. package/dist/.lango/bignumber.mjs +3119 -0
  5. package/dist/.lango/runtime.mjs +683 -0
  6. package/dist/.lango/xmldom/conventions.js +429 -0
  7. package/dist/.lango/xmldom/dom-parser.js +591 -0
  8. package/dist/.lango/xmldom/dom.js +3759 -0
  9. package/dist/.lango/xmldom/entities.js +2171 -0
  10. package/dist/.lango/xmldom/errors.js +205 -0
  11. package/dist/.lango/xmldom/grammar.js +559 -0
  12. package/dist/.lango/xmldom/index.js +41 -0
  13. package/dist/.lango/xmldom/package.json +1 -0
  14. package/dist/.lango/xmldom/sax.js +983 -0
  15. package/dist/.lango/xmldom.LICENSE.md +8 -0
  16. package/dist/body_reader.mjs +179 -0
  17. package/dist/body_reader.mjs.map +1 -0
  18. package/dist/builder.mjs +69 -0
  19. package/dist/builder.mjs.map +1 -0
  20. package/dist/cli/.lango/bignumber.mjs +3119 -0
  21. package/dist/cli/.lango/runtime.mjs +683 -0
  22. package/dist/cli/.lango/xmldom/conventions.js +429 -0
  23. package/dist/cli/.lango/xmldom/dom-parser.js +591 -0
  24. package/dist/cli/.lango/xmldom/dom.js +3759 -0
  25. package/dist/cli/.lango/xmldom/entities.js +2171 -0
  26. package/dist/cli/.lango/xmldom/errors.js +205 -0
  27. package/dist/cli/.lango/xmldom/grammar.js +559 -0
  28. package/dist/cli/.lango/xmldom/index.js +41 -0
  29. package/dist/cli/.lango/xmldom/package.json +1 -0
  30. package/dist/cli/.lango/xmldom/sax.js +983 -0
  31. package/dist/cli/.lango/xmldom.LICENSE.md +8 -0
  32. package/dist/cli/body_reader.mjs +179 -0
  33. package/dist/cli/body_reader.mjs.map +1 -0
  34. package/dist/cli/database.mjs +101 -0
  35. package/dist/cli/database.mjs.map +1 -0
  36. package/dist/cli/database_options.mjs +83 -0
  37. package/dist/cli/database_options.mjs.map +1 -0
  38. package/dist/cli/database_scope.mjs +82 -0
  39. package/dist/cli/database_scope.mjs.map +1 -0
  40. package/dist/cli/endpoint.mjs +44 -0
  41. package/dist/cli/endpoint.mjs.map +1 -0
  42. package/dist/cli/options.mjs +165 -0
  43. package/dist/cli/options.mjs.map +1 -0
  44. package/dist/cli/postgres_adapter.mjs +166 -0
  45. package/dist/cli/postgres_adapter.mjs.map +1 -0
  46. package/dist/cli/routes.mjs +233 -0
  47. package/dist/cli/routes.mjs.map +1 -0
  48. package/dist/cli/server.mjs +572 -0
  49. package/dist/cli/server.mjs.map +1 -0
  50. package/dist/cli/sqlite_adapter.mjs +163 -0
  51. package/dist/cli/sqlite_adapter.mjs.map +1 -0
  52. package/dist/database.mjs +101 -0
  53. package/dist/database.mjs.map +1 -0
  54. package/dist/database_options.mjs +83 -0
  55. package/dist/database_options.mjs.map +1 -0
  56. package/dist/database_scope.mjs +82 -0
  57. package/dist/database_scope.mjs.map +1 -0
  58. package/dist/endpoint.mjs +44 -0
  59. package/dist/endpoint.mjs.map +1 -0
  60. package/dist/group.mjs +75 -0
  61. package/dist/group.mjs.map +1 -0
  62. package/dist/library.mjs +6 -0
  63. package/dist/library.mjs.map +1 -0
  64. package/dist/options.mjs +165 -0
  65. package/dist/options.mjs.map +1 -0
  66. package/dist/postgres_adapter.mjs +166 -0
  67. package/dist/postgres_adapter.mjs.map +1 -0
  68. package/dist/postgres_worker.mjs +119 -0
  69. package/dist/postgres_worker.mjs.map +1 -0
  70. package/dist/response.mjs +62 -0
  71. package/dist/response.mjs.map +1 -0
  72. package/dist/routes.mjs +233 -0
  73. package/dist/routes.mjs.map +1 -0
  74. package/dist/runtime.mjs +475 -0
  75. package/dist/runtime.mjs.map +1 -0
  76. package/dist/server.mjs +568 -0
  77. package/dist/server.mjs.map +1 -0
  78. package/dist/sqlite_adapter.mjs +163 -0
  79. package/dist/sqlite_adapter.mjs.map +1 -0
  80. package/dist/token.mjs +106 -0
  81. package/dist/token.mjs.map +1 -0
  82. package/dist/tokens.mjs +76 -0
  83. package/dist/tokens.mjs.map +1 -0
  84. package/dist/worker.mjs +57 -0
  85. package/dist/worker.mjs.map +1 -0
  86. package/package.json +39 -4
  87. package/src/body_reader.lango +113 -0
  88. package/src/builder.lango +53 -0
  89. package/src/database.lango +66 -0
  90. package/src/database_options.lango +57 -0
  91. package/src/database_scope.lango +59 -0
  92. package/src/endpoint.lango +23 -0
  93. package/src/group.lango +47 -0
  94. package/src/library.lango +10 -0
  95. package/src/options.lango +128 -0
  96. package/src/postgres_adapter.lango +138 -0
  97. package/src/postgres_worker.lango +114 -0
  98. package/src/response.lango +42 -0
  99. package/src/routes.lango +160 -0
  100. package/src/runtime.lango +320 -0
  101. package/src/server.lango +432 -0
  102. package/src/sqlite_adapter.lango +127 -0
  103. package/src/token.lango +70 -0
  104. package/src/tokens.lango +70 -0
  105. package/src/worker.lango +43 -0
@@ -0,0 +1,163 @@
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
@@ -0,0 +1 @@
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;;;;;;;;;;;;;;"}
@@ -0,0 +1,101 @@
1
+ import { DatabaseScope } from "./database_scope.mjs";
2
+ import { SqliteAdapter } from "./sqlite_adapter.mjs";
3
+ import { PostgresAdapter } from "./postgres_adapter.mjs";
4
+ import {
5
+ hostGlobal as __hostGlobal,
6
+ contextGet as __contextGet,
7
+ contextSet as __contextSet,
8
+ contextRestore as __contextRestore,
9
+ requireBoolean as __requireBoolean,
10
+ normalize as __normalize,
11
+ boundary as __boundary,
12
+ query as __query,
13
+ requireArity as __requireArity,
14
+ withArity as __withArity,
15
+ } from "./.lango/runtime.mjs";
16
+
17
+ export class Database {
18
+ #root;
19
+ #settings;
20
+ #adapter;
21
+ constructor(settings, root = null) {
22
+ __requireArity(arguments.length, [0], "constructor");
23
+ settings = __boundary(settings);
24
+ root = __boundary(root);
25
+ this.#root = root;
26
+ this.#settings = settings;
27
+ this.#adapter = null;
28
+ }
29
+ open() {
30
+ if (__requireBoolean(__normalize(this.#settings) === null)) {
31
+ return __normalize(__hostGlobal(["Promise"]).resolve(null));
32
+ }
33
+ let name = "node:sqlite";
34
+ if (__requireBoolean(__normalize(this.#settings.type) === "postgresql")) {
35
+ name = "node:worker_threads";
36
+ }
37
+ return import(name).then(__withArity((mod) => {
38
+ const __contextScope = [];
39
+ try {
40
+ mod = __boundary(mod);
41
+ if (__requireBoolean(__normalize(this.#settings.type) === "sqlite")) {
42
+ this.#adapter = new SqliteAdapter(mod, __normalize(this.#settings));
43
+ } else {
44
+ this.#adapter = new PostgresAdapter(mod, __normalize(this.#settings), __normalize(this.#root));
45
+ }
46
+ __contextScope.push(__contextSet("db", this.scope()));
47
+ try {
48
+ let query = __query("select 1", []);
49
+ __normalize(query.execute());
50
+ } finally {
51
+ __normalize(__contextGet("db").finish());
52
+ }
53
+ return null;
54
+ return null;
55
+ } finally {
56
+ __contextRestore(__contextScope);
57
+ }
58
+ }, [0], "closure")).catch(__withArity((error) => {
59
+ const __contextScope = [];
60
+ try {
61
+ error = __boundary(error);
62
+ __normalize(__contextGet("log").err(`Database startup failed: ${error}`));
63
+ this.close();
64
+ throw "Database startup failed; check configuration, compiler version and driver installation";
65
+ return null;
66
+ } finally {
67
+ __contextRestore(__contextScope);
68
+ }
69
+ }, [0], "closure"));
70
+ return null;
71
+ }
72
+ scope() {
73
+ if (__requireBoolean(__normalize(this.#adapter) === null)) {
74
+ return null;
75
+ }
76
+ return new DatabaseScope(__normalize(this.#adapter));
77
+ return null;
78
+ }
79
+ close() {
80
+ if (__requireBoolean(__normalize(this.#adapter) !== null)) {
81
+ __normalize(this.#adapter.close());
82
+ this.#adapter = null;
83
+ }
84
+ return null;
85
+ return null;
86
+ }
87
+ }
88
+ export function prepareDatabase(settings) {
89
+ __requireArity(arguments.length, [0], "prepareDatabase");
90
+ settings = __boundary(settings);
91
+ if (__requireBoolean(__requireBoolean(__requireBoolean(settings === null) || __requireBoolean(__normalize(settings.type) !== "sqlite")) || __requireBoolean(__normalize(settings.file) === ":memory:"))) {
92
+ return __normalize(__hostGlobal(["Promise"]).resolve(null));
93
+ }
94
+ let database = new Database(settings);
95
+ return __normalize(database.open()).finally(() => {
96
+ __normalize(database.close());
97
+ return null;
98
+ });
99
+ return null;
100
+ }
101
+ //# sourceMappingURL=database.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.mjs","sources":["database.lango"],"sourcesContent":["import js global Promise\nimport \"./database_scope\"\n class DatabaseScope\nimport \"./sqlite_adapter\"\n class SqliteAdapter\nimport \"./postgres_adapter\"\n class PostgresAdapter\n\nexport prepareDatabase(settings)\n\nexport class Database(settings, root = null)\n methods\n open()\n scope()\n close()\n\nDatabase(settings, root = null)\n @root = root\n @settings = settings\n @adapter = null\n\nDatabase:open()\n if @settings == null\n return Promise/resolve(null)\n name = \"node:sqlite\"\n if @settings.type == \"postgresql\"\n name = \"node:worker_threads\"\n return chain import_module(name)\n then(mod)\n if @settings.type == \"sqlite\"\n @adapter = new SqliteAdapter(mod, @settings)\n else\n @adapter = new PostgresAdapter(mod, @settings, @root)\n context db = scope()\n try\n query = SQL\n select 1\n query.execute()\n finally\n db.finish()\n return null\n catch(error)\n context log\n log.err(\"Database startup failed: ${error}\")\n close()\n throw \"Database startup failed; check configuration, compiler version and driver installation\"\n\nDatabase:scope()\n if @adapter == null\n return null\n return new DatabaseScope(@adapter)\n\nDatabase:close()\n if @adapter != null\n @adapter.close()\n @adapter = null\n return null\n\nprepareDatabase(settings)\n if settings == null or settings.type != \"sqlite\" or settings.file == \":memory:\"\n return Promise/resolve(null)\n database = new Database(settings)\n return chain database.open()\n finally\n capture database\n database.close()\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA;;;;;;;;;;;;;;"}
@@ -0,0 +1,83 @@
1
+ import * as path from "node:path";
2
+ import {
3
+ hostGlobal as __hostGlobal,
4
+ hostGlobalCall as __hostGlobalCall,
5
+ isNumber as __isNumber,
6
+ isString as __isString,
7
+ isBool as __isBool,
8
+ isObject as __isObject,
9
+ isArray as __isArray,
10
+ entries as __entries,
11
+ requireBoolean as __requireBoolean,
12
+ normalize as __normalize,
13
+ boundary as __boundary,
14
+ requireArity as __requireArity,
15
+ } from "./.lango/runtime.mjs";
16
+
17
+ export function databaseOptions(root, spec, workers) {
18
+ __requireArity(arguments.length, [0, 1, 2], "databaseOptions");
19
+ root = __boundary(root);
20
+ spec = __boundary(spec);
21
+ workers = __boundary(workers);
22
+ let file;
23
+ if (__requireBoolean(spec === null)) {
24
+ return null;
25
+ }
26
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(spec))) || __requireBoolean(__isArray(spec)))) {
27
+ throw "Database configuration must be a map";
28
+ }
29
+ let allowed = [];
30
+ if (__normalize(spec.type) === "sqlite") {
31
+ allowed = ["type", "file", "busyTimeoutMs"];
32
+ } else if (__normalize(spec.type) === "postgresql") {
33
+ allowed = ["type", "connectionEnv", "queryTimeoutMs", "connectTimeoutSeconds"];
34
+ } else {
35
+ throw "Database type must be sqlite or postgresql";
36
+ }
37
+ for (const [key, value] of __entries(spec)) {
38
+ if (__requireBoolean(!__requireBoolean(__normalize(allowed.includes(key))))) {
39
+ throw `Unknown database option: ${key}`;
40
+ }
41
+ }
42
+ if (__requireBoolean(__normalize(spec.type) === "sqlite")) {
43
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.file)))) || __requireBoolean(__normalize(spec.file) === ""))) {
44
+ throw "SQLite database file is required";
45
+ }
46
+ file = __normalize(spec.file);
47
+ if (__requireBoolean(__requireBoolean(file === ":memory:") && __requireBoolean(workers !== 1))) {
48
+ throw "An in-memory SQLite database requires exactly one worker";
49
+ }
50
+ if (__requireBoolean(file !== ":memory:")) {
51
+ file = __normalize(path.resolve(root, file));
52
+ }
53
+ return { type: "sqlite", file: file, busyTimeoutMs: positive(__normalize(spec.busyTimeoutMs), 5000) };
54
+ }
55
+ let name = __normalize(spec.connectionEnv);
56
+ if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(name))) || __requireBoolean(name === "")) || __requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(__normalize(__hostGlobal(["process"]).env), name)))))) {
57
+ throw "PostgreSQL connectionEnv must name an existing environment variable";
58
+ }
59
+ let connection = __normalize(__hostGlobal(["process"]).env[name]);
60
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(connection))) || __requireBoolean(__requireBoolean(!__requireBoolean(__normalize(connection.startsWith("postgresql://")))) && __requireBoolean(!__requireBoolean(__normalize(connection.startsWith("postgres://"))))))) {
61
+ throw "PostgreSQL connectionEnv must contain a PostgreSQL connection URL";
62
+ }
63
+ return { type: "postgresql", connection: connection, queryTimeoutMs: positive(__normalize(spec.queryTimeoutMs), 5000), connectTimeoutSeconds: positive(__normalize(spec.connectTimeoutSeconds), 5) };
64
+ return null;
65
+ }
66
+
67
+ function positive(value, fallback) {
68
+ __requireArity(arguments.length, [0, 1], "positive");
69
+ value = __boundary(value);
70
+ fallback = __boundary(fallback);
71
+ if (__requireBoolean(value === null)) {
72
+ return fallback;
73
+ }
74
+ if (__requireBoolean(__isString(value))) {
75
+ value = __hostGlobalCall(["Number"], value);
76
+ }
77
+ if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isSafeInteger(value)))) || __requireBoolean(value < 1)) || __requireBoolean(value > 2147483647))) {
78
+ throw "Database timeout must be a positive integer within the timer limit";
79
+ }
80
+ return value;
81
+ return null;
82
+ }
83
+ //# sourceMappingURL=database_options.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database_options.mjs","sources":["database_options.lango"],"sourcesContent":["import js \"node:path\" as path\nimport js global Object\nimport js global Number\nimport js global process\n\nexport databaseOptions(root, spec, workers)\n\ndatabaseOptions(root, spec, workers)\n if spec == null\n return null\n if !is_object(spec) or is_array(spec)\n throw \"Database configuration must be a map\"\n allowed = []\n switch spec.type\n case \"sqlite\"\n allowed = [\"type\", \"file\", \"busyTimeoutMs\"]\n case \"postgresql\"\n allowed = [\"type\", \"connectionEnv\", \"queryTimeoutMs\", \"connectTimeoutSeconds\"]\n else\n throw \"Database type must be sqlite or postgresql\"\n for spec as key: value\n if !allowed.includes(key)\n throw \"Unknown database option: ${key}\"\n if spec.type == \"sqlite\"\n if !is_string(spec.file) or spec.file == \"\"\n throw \"SQLite database file is required\"\n file = spec.file\n if file == \":memory:\" and workers != 1\n throw \"An in-memory SQLite database requires exactly one worker\"\n if file != \":memory:\"\n file = path/resolve(root, file)\n return {\n type: \"sqlite\"\n file: file\n busyTimeoutMs: positive(spec.busyTimeoutMs, 5000)\n }\n name = spec.connectionEnv\n if !is_string(name) or name == \"\" or !Object/hasOwn(process.env, name)\n throw \"PostgreSQL connectionEnv must name an existing environment variable\"\n connection = process.env[name]\n if !is_string(connection) or (!connection.startsWith(\"postgresql://\") and !connection.startsWith(\"postgres://\"))\n throw \"PostgreSQL connectionEnv must contain a PostgreSQL connection URL\"\n return {\n type: \"postgresql\"\n connection: connection\n queryTimeoutMs: positive(spec.queryTimeoutMs, 5000)\n connectTimeoutSeconds: positive(spec.connectTimeoutSeconds, 5)\n }\n\npositive(value, fallback)\n if value == null\n return fallback\n if is_string(value)\n value = Number(value)\n if !Number/isSafeInteger(value) or value < 1 or value > 2147483647\n throw \"Database timeout must be a positive integer within the timer limit\"\n return value\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,82 @@
1
+ import {
2
+ hostGlobal as __hostGlobal,
3
+ contextGet as __contextGet,
4
+ contextSet as __contextSet,
5
+ contextRestore as __contextRestore,
6
+ requireBoolean as __requireBoolean,
7
+ normalize as __normalize,
8
+ boundary as __boundary,
9
+ requireArity as __requireArity,
10
+ } from "./.lango/runtime.mjs";
11
+
12
+ export class DatabaseScope {
13
+ parameterStyle;
14
+ #adapter;
15
+ #closed;
16
+ constructor(adapter) {
17
+ __requireArity(arguments.length, [0], "constructor");
18
+ adapter = __boundary(adapter);
19
+ this.#adapter = adapter;
20
+ this.#closed = false;
21
+ this.parameterStyle = __normalize(adapter.parameterStyle);
22
+ }
23
+ execute(sql, parameters) {
24
+ __requireArity(arguments.length, [0, 1], "execute");
25
+ sql = __boundary(sql);
26
+ parameters = __boundary(parameters);
27
+ this.#requireOpen();
28
+ return __normalize(this.#adapter.execute(sql, parameters));
29
+ return null;
30
+ }
31
+ begin() {
32
+ this.#requireOpen();
33
+ return __normalize(this.#adapter.begin());
34
+ return null;
35
+ }
36
+ commit() {
37
+ this.#requireOpen();
38
+ return __normalize(this.#adapter.commit());
39
+ return null;
40
+ }
41
+ rollback() {
42
+ this.#requireOpen();
43
+ return __normalize(this.#adapter.rollback());
44
+ return null;
45
+ }
46
+ transactionState() {
47
+ this.#requireOpen();
48
+ return __normalize(this.#adapter.transactionState());
49
+ return null;
50
+ }
51
+ #requireOpen() {
52
+ if (__requireBoolean(__normalize(this.#closed))) {
53
+ throw new (__hostGlobal(["Error"]))("DatabaseScopeClosed");
54
+ }
55
+ return null;
56
+ return null;
57
+ }
58
+ finish() {
59
+ const __contextScope = [];
60
+ try {
61
+ if (__requireBoolean(__normalize(this.#closed))) {
62
+ return false;
63
+ }
64
+ this.#closed = true;
65
+ let dirty = false;
66
+ try {
67
+ __loop1: while (__requireBoolean(__normalize(this.#adapter.transactionState()) !== null)) {
68
+ dirty = true;
69
+ __normalize(this.#adapter.rollback());
70
+ }
71
+ } catch (error) {
72
+ __normalize(__contextGet("log").err("Database cleanup failed; retiring worker"));
73
+ __normalize(__hostGlobal(["process"]).exit(1));
74
+ }
75
+ return dirty;
76
+ return null;
77
+ } finally {
78
+ __contextRestore(__contextScope);
79
+ }
80
+ }
81
+ }
82
+ //# sourceMappingURL=database_scope.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database_scope.mjs","sources":["database_scope.lango"],"sourcesContent":["import js global Error\nimport js global Object\nimport js global process\n\nexport class DatabaseScope(adapter)\n properties\n parameterStyle\n methods\n execute(sql, parameters)\n begin()\n commit()\n rollback()\n transactionState()\n finish()\n\nDatabaseScope(adapter)\n @adapter = adapter\n @closed = false\n @parameterStyle = adapter.parameterStyle\n\nDatabaseScope:execute(sql, parameters)\n requireOpen()\n return @adapter.execute(sql, parameters)\n\nDatabaseScope:begin()\n requireOpen()\n return @adapter.begin()\n\nDatabaseScope:commit()\n requireOpen()\n return @adapter.commit()\n\nDatabaseScope:rollback()\n requireOpen()\n return @adapter.rollback()\n\nDatabaseScope:transactionState()\n requireOpen()\n return @adapter.transactionState()\n\nDatabaseScope:requireOpen()\n if @closed\n throw new Error(\"DatabaseScopeClosed\")\n return null\n\nDatabaseScope:finish()\n if @closed\n return false\n @closed = true\n dirty = false\n try\n loop while @adapter.transactionState() != null\n dirty = true\n @adapter.rollback()\n catch error\n context log\n log.err(\"Database cleanup failed; retiring worker\")\n process.exit(1)\n return dirty\n"],"names":[],"mappings":";;;;;;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,44 @@
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 class Endpoint {
14
+ path;
15
+ module;
16
+ handler;
17
+ auth;
18
+ constructor(spec) {
19
+ __requireArity(arguments.length, [0], "constructor");
20
+ spec = __boundary(spec);
21
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.path)))) || __requireBoolean(!__requireBoolean(__normalize(spec.path.startsWith("/"))))) || __requireBoolean(__normalize(spec.path.includes("?")))) || __requireBoolean(__normalize(spec.path.includes("#")))) || __requireBoolean(__normalize(spec.path.includes("\\")))) || __requireBoolean(__normalize(spec.path.includes("//"))))) {
22
+ throw "Endpoint requires an absolute URL path";
23
+ }
24
+ if (__requireBoolean(__requireBoolean(__normalize(spec.path.includes("*"))) && __requireBoolean(__requireBoolean(!__requireBoolean(__normalize(spec.path.endsWith("/*")))) || __requireBoolean(__normalize(spec.path.indexOf("*")) !== __normalize(spec.path.lastIndexOf("*")))))) {
25
+ throw "Only trailing /* wildcards are supported";
26
+ }
27
+ for (const key of ["module", "handler"]) {
28
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec[key])))) || __requireBoolean(__normalize(spec[key]) === ""))) {
29
+ throw `Endpoint requires ${key}`;
30
+ }
31
+ }
32
+ this.path = __normalize(spec.path);
33
+ this.module = __normalize(spec.module);
34
+ this.handler = __normalize(spec.handler);
35
+ this.auth = __normalize(spec.auth);
36
+ if (__requireBoolean(__normalize(this.auth) === null)) {
37
+ this.auth = "login";
38
+ }
39
+ if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(this.auth)))) || __requireBoolean(__normalize(this.auth) === "")) || __requireBoolean(__normalize(this.auth.includes(","))))) {
40
+ throw "Endpoint auth must name one permission";
41
+ }
42
+ }
43
+ }
44
+ //# sourceMappingURL=endpoint.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint.mjs","sources":["endpoint.lango"],"sourcesContent":["export class Endpoint(spec)\n properties\n path\n module\n handler\n auth\n\nEndpoint(spec)\n if !is_string(spec.path) or !spec.path.startsWith(\"/\") or spec.path.includes(\"?\") or spec.path.includes(\"#\") or spec.path.includes(\"\\\\\") or spec.path.includes(\"//\")\n throw \"Endpoint requires an absolute URL path\"\n if spec.path.includes(\"*\") and (!spec.path.endsWith(\"/*\") or spec.path.indexOf(\"*\") != spec.path.lastIndexOf(\"*\"))\n throw \"Only trailing /* wildcards are supported\"\n for [\"module\", \"handler\"] as key\n if !is_string(spec[key]) or spec[key] == \"\"\n throw \"Endpoint requires ${key}\"\n @path = spec.path\n @module = spec.module\n @handler = spec.handler\n @auth = spec.auth\n if @auth == null\n @auth = \"login\"\n if !is_string(@auth) or @auth == \"\" or @auth.includes(\",\")\n throw \"Endpoint auth must name one permission\"\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/group.mjs ADDED
@@ -0,0 +1,75 @@
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 class Group {
14
+ #routes;
15
+ #prefix;
16
+ #module;
17
+ #auth;
18
+ constructor(routes, spec, prefix = "", inheritedModule = null, inheritedAuth = null) {
19
+ __requireArity(arguments.length, [0, 1], "constructor");
20
+ routes = __boundary(routes);
21
+ spec = __boundary(spec);
22
+ prefix = __boundary(prefix);
23
+ inheritedModule = __boundary(inheritedModule);
24
+ inheritedAuth = __boundary(inheritedAuth);
25
+ 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("*"))))) {
26
+ throw "Group requires a path without a trailing slash or wildcard";
27
+ }
28
+ this.#routes = routes;
29
+ this.#prefix = `${prefix}${__normalize(spec.path)}`;
30
+ this.#module = __normalize(spec.module);
31
+ this.#auth = __normalize(spec.auth);
32
+ if (__requireBoolean(__normalize(this.#module) === null)) {
33
+ this.#module = inheritedModule;
34
+ }
35
+ if (__requireBoolean(__normalize(this.#auth) === null)) {
36
+ this.#auth = inheritedAuth;
37
+ }
38
+ }
39
+ endpoint(spec) {
40
+ __requireArity(arguments.length, [0], "endpoint");
41
+ spec = __boundary(spec);
42
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.path)))) || __requireBoolean(!__requireBoolean(__normalize(spec.path.startsWith("/")))))) {
43
+ throw "Endpoint path must begin with /";
44
+ }
45
+ let mod = __normalize(spec.module);
46
+ let auth = __normalize(spec.auth);
47
+ if (__requireBoolean(mod === null)) {
48
+ mod = __normalize(this.#module);
49
+ }
50
+ if (__requireBoolean(auth === null)) {
51
+ auth = __normalize(this.#auth);
52
+ }
53
+ __normalize(this.#routes.endpoint({ path: `${__normalize(this.#prefix)}${__normalize(spec.path)}`, module: mod, handler: __normalize(spec.handler), auth: auth }));
54
+ return this;
55
+ return null;
56
+ }
57
+ group(spec) {
58
+ __requireArity(arguments.length, [0], "group");
59
+ spec = __boundary(spec);
60
+ return new Group(__normalize(this.#routes), spec, __normalize(this.#prefix), __normalize(this.#module), __normalize(this.#auth));
61
+ return null;
62
+ }
63
+ include(spec) {
64
+ __requireArity(arguments.length, [0], "include");
65
+ spec = __boundary(spec);
66
+ let mount = __normalize(spec.path);
67
+ if (__requireBoolean(mount === null)) {
68
+ mount = "/";
69
+ }
70
+ __normalize(this.#routes.include({ module: __normalize(spec.module), path: `${__normalize(this.#prefix)}${mount}` }, __normalize(this.#auth)));
71
+ return this;
72
+ return null;
73
+ }
74
+ }
75
+ //# sourceMappingURL=group.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group.mjs","sources":["group.lango"],"sourcesContent":["export class Group(routes, spec, prefix = \"\", inheritedModule = null, inheritedAuth = null)\n methods\n endpoint(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 })\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":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,6 @@
1
+ import { Server as ServerClass } from "./server.mjs";
2
+ import { Builder as BuilderClass } from "./builder.mjs";
3
+ export let Server = ServerClass;
4
+
5
+ export let Builder = BuilderClass;
6
+ //# sourceMappingURL=library.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"library.mjs","sources":["library.lango"],"sourcesContent":["import \"./server\"\n alias ServerClass = class Server\nimport \"./builder\"\n alias BuilderClass = class Builder\n\nexport global Server\nexport global Builder\n\nglobal Server = ServerClass\nglobal Builder = BuilderClass\n"],"names":[],"mappings":";;AAQA;;AACA;;"}