Compare commits

..

No commits in common. "71c803107c3e55fa81af4550c7390a46f26cf239" and "c124997a5845dc88fa34190c3e0f6767fbd99978" have entirely different histories.

11 changed files with 872 additions and 457 deletions

View file

@ -1017,9 +1017,9 @@
} }
}, },
"node_modules/pg": { "node_modules/pg": {
"version": "8.12.0", "version": "8.11.5",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.12.0.tgz", "resolved": "https://registry.npmjs.org/pg/-/pg-8.11.5.tgz",
"integrity": "sha512-A+LHUSnwnxrnL/tZ+OLfqR1SxLN3c/pgDztZ47Rpbsd4jUytsTtwQo/TLPRzPJMp/1pbhYVhH9cuSZLAajNfjQ==", "integrity": "sha512-jqgNHSKL5cbDjFlHyYsCXmQDrfIX/3RsNwYqpd4N0Kt8niLuNoRNH+aazv6cOd43gPh9Y4DjQCtb+X0MH0Hvnw==",
"dependencies": { "dependencies": {
"pg-connection-string": "^2.6.4", "pg-connection-string": "^2.6.4",
"pg-pool": "^3.6.2", "pg-pool": "^3.6.2",

View file

@ -10,7 +10,6 @@ var NativeQuery = (module.exports = function (config, values, callback) {
this.text = config.text this.text = config.text
this.values = config.values this.values = config.values
this.name = config.name this.name = config.name
this.queryMode = config.queryMode
this.callback = config.callback this.callback = config.callback
this.state = 'new' this.state = 'new'
this._arrayMode = config.rowMode === 'array' this._arrayMode = config.rowMode === 'array'
@ -160,8 +159,6 @@ NativeQuery.prototype.submit = function (client) {
} }
var vals = this.values.map(utils.prepareValue) var vals = this.values.map(utils.prepareValue)
client.native.query(this.text, vals, after) client.native.query(this.text, vals, after)
} else if (this.queryMode === 'extended') {
client.native.query(this.text, [], after)
} else { } else {
client.native.query(this.text, after) client.native.query(this.text, after)
} }

View file

@ -16,7 +16,6 @@ class Query extends EventEmitter {
this.rows = config.rows this.rows = config.rows
this.types = config.types this.types = config.types
this.name = config.name this.name = config.name
this.queryMode = config.queryMode
this.binary = config.binary this.binary = config.binary
// use unique portal name each time // use unique portal name each time
this.portal = config.portal || '' this.portal = config.portal || ''
@ -33,10 +32,6 @@ class Query extends EventEmitter {
} }
requiresPreparation() { requiresPreparation() {
if (this.queryMode === 'extended') {
return true
}
// named queries must always be prepared // named queries must always be prepared
if (this.name) { if (this.name) {
return true return true

View file

@ -1,6 +1,6 @@
{ {
"name": "pg", "name": "pg",
"version": "8.12.0", "version": "8.11.5",
"description": "PostgreSQL client - pure javascript & libpq with the same API", "description": "PostgreSQL client - pure javascript & libpq with the same API",
"keywords": [ "keywords": [
"database", "database",
@ -34,7 +34,7 @@
"pg-copy-streams": "0.3.0", "pg-copy-streams": "0.3.0",
"typescript": "^4.0.3", "typescript": "^4.0.3",
"workerd": "^1.20230419.0", "workerd": "^1.20230419.0",
"wrangler": "3.58.0" "wrangler": "^2.16.0"
}, },
"optionalDependencies": { "optionalDependencies": {
"pg-cloudflare": "^1.1.1" "pg-cloudflare": "^1.1.1"
@ -58,5 +58,5 @@
"engines": { "engines": {
"node": ">= 8.0.0" "node": ">= 8.0.0"
}, },
"gitHead": "0f42880861951970e193d31359508d460a67d25a" "gitHead": "a37a93bf7990220517a40cf16b8e72d4c3e6cef5"
} }

View file

@ -5,7 +5,7 @@
"packages": { "packages": {
"": { "": {
"dependencies": { "dependencies": {
"pg": "^8.12.0", "pg": "^8.11.5",
"sqlite3": "^5.1.7" "sqlite3": "^5.1.7"
}, },
"devDependencies": { "devDependencies": {
@ -1029,9 +1029,9 @@
} }
}, },
"node_modules/pg": { "node_modules/pg": {
"version": "8.12.0", "version": "8.11.5",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.12.0.tgz", "resolved": "https://registry.npmjs.org/pg/-/pg-8.11.5.tgz",
"integrity": "sha512-A+LHUSnwnxrnL/tZ+OLfqR1SxLN3c/pgDztZ47Rpbsd4jUytsTtwQo/TLPRzPJMp/1pbhYVhH9cuSZLAajNfjQ==", "integrity": "sha512-jqgNHSKL5cbDjFlHyYsCXmQDrfIX/3RsNwYqpd4N0Kt8niLuNoRNH+aazv6cOd43gPh9Y4DjQCtb+X0MH0Hvnw==",
"dependencies": { "dependencies": {
"pg-connection-string": "^2.6.4", "pg-connection-string": "^2.6.4",
"pg-pool": "^3.6.2", "pg-pool": "^3.6.2",

View file

@ -6,7 +6,7 @@
"yaml": "^2.4.1" "yaml": "^2.4.1"
}, },
"dependencies": { "dependencies": {
"pg": "^8.12.0", "pg": "^8.11.5",
"sqlite3": "^5.1.7" "sqlite3": "^5.1.7"
} }
} }

View file

@ -1,15 +1,15 @@
/** /**
* @author fenris * @author fenris
*/ */
type int = number; declare type int = number;
/** /**
* @author fenris * @author fenris
*/ */
type float = number; declare type float = number;
/** /**
* @author fenris * @author fenris
*/ */
type type_date = { declare type type_date = {
year: int; year: int;
month: int; month: int;
day: int; day: int;
@ -17,7 +17,7 @@ type type_date = {
/** /**
* @author fenris * @author fenris
*/ */
type type_time = { declare type type_time = {
hour: int; hour: int;
minute: int; minute: int;
second: int; second: int;
@ -25,7 +25,7 @@ type type_time = {
/** /**
* @author fenris * @author fenris
*/ */
type type_datetimeobject = { declare type type_datetimeobject = {
date: type_date; date: type_date;
time: type_time; time: type_time;
}; };
@ -44,7 +44,7 @@ declare namespace lib_plankton.base {
/** /**
* @author fenris * @author fenris
*/ */
type type_pseudopointer<type_value> = { declare type type_pseudopointer<type_value> = {
value: type_value; value: type_value;
}; };
/** /**
@ -1988,7 +1988,6 @@ declare namespace lib_plankton.database {
type type_description_insert = { type type_description_insert = {
table_name: string; table_name: string;
values: Record<string, any>; values: Record<string, any>;
returning?: (null | string);
}; };
/** /**
*/ */
@ -2033,7 +2032,6 @@ declare namespace lib_plankton.database {
* @author fenris * @author fenris
*/ */
type type_database = { type type_database = {
wrap_name: ((name: string) => string);
query_free_get: ((query: type_query) => Promise<type_result_get>); query_free_get: ((query: type_query) => Promise<type_result_get>);
query_free_put: ((query: type_query) => Promise<type_result_put>); query_free_put: ((query: type_query) => Promise<type_result_put>);
query_free_set: ((query: type_query) => Promise<type_result_set>); query_free_set: ((query: type_query) => Promise<type_result_set>);
@ -2055,32 +2053,30 @@ declare namespace lib_plankton.database {
/** /**
*/ */
function sql_common_formulation_create_table(description_create_table: type_description_create_table, options?: { function sql_common_formulation_create_table(description_create_table: type_description_create_table, options?: {
auto_increment_keyword?: (null | string); auto_increment_keyword?: string;
auto_increment_special?: (null | string);
omit_comments?: boolean; omit_comments?: boolean;
type_map?: Record<enum_type, string>; type_map?: Record<enum_type, string>;
wrap_name?: ((name: string) => string); wrap_names?: boolean;
}): type_query; }): type_query;
/** /**
*/ */
function sql_common_formulation_insert(description_insert: type_description_insert, options?: { function sql_common_formulation_insert(description_insert: type_description_insert, options?: {
wrap_name?: ((name: string) => string); wrap_names?: boolean;
set_returning?: boolean;
}): type_query; }): type_query;
/** /**
*/ */
function sql_common_formulation_update(description_update: type_description_update, options?: { function sql_common_formulation_update(description_update: type_description_update, options?: {
wrap_name?: ((name: string) => string); wrap_names?: boolean;
}): type_query; }): type_query;
/** /**
*/ */
function sql_common_formulation_delete(description_delete: type_description_delete, options?: { function sql_common_formulation_delete(description_delete: type_description_delete, options?: {
wrap_name?: ((name: string) => string); wrap_names?: boolean;
}): type_query; }): type_query;
/** /**
*/ */
function sql_common_formulation_select(description_select: type_description_select, options?: { function sql_common_formulation_select(description_select: type_description_select, options?: {
wrap_name?: ((name: string) => string); wrap_names?: boolean;
}): type_query; }): type_query;
} }
declare namespace lib_plankton.database { declare namespace lib_plankton.database {
@ -2098,9 +2094,6 @@ declare namespace lib_plankton.database {
/** /**
*/ */
function sqlite_make(parameters: type_sqlite_parameters): type_sqlite_subject; function sqlite_make(parameters: type_sqlite_parameters): type_sqlite_subject;
/**
*/
function sqlite_wrap_name(name: string): string;
/** /**
* @author fenris * @author fenris
*/ */
@ -2154,7 +2147,6 @@ declare namespace lib_plankton.database {
class class_sqlite implements interface_database { class class_sqlite implements interface_database {
private subject; private subject;
constructor(parameters: type_sqlite_parameters); constructor(parameters: type_sqlite_parameters);
wrap_name(name: any): string;
query_free_get(query: any): Promise<type_result_get>; query_free_get(query: any): Promise<type_result_get>;
query_free_put(query: any): Promise<number>; query_free_put(query: any): Promise<number>;
query_free_set(query: any): Promise<number>; query_free_set(query: any): Promise<number>;
@ -2175,7 +2167,7 @@ declare namespace lib_plankton.database {
username: string; username: string;
password: string; password: string;
schema: string; schema: string;
pool: (null | any); client: any;
}; };
/** /**
* @todo * @todo
@ -2188,24 +2180,22 @@ declare namespace lib_plankton.database {
schema: string; schema: string;
}; };
/** /**
* @see https://node-postgres.com/apis/client#new-client
*/ */
function postgresql_make(parameters: type_postgresql_parameters): type_postgresql_subject; function postgresql_make(parameters: type_postgresql_parameters): type_postgresql_subject;
/**
*/
function postgresql_wrap_name(name: string): string;
/** /**
* @author fenris * @author fenris
* @see https://node-postgres.com/apis/pool#poolquery * @see https://node-postgres.com/apis/client#clientquery
*/ */
function postgresql_query_free_get(subject: type_postgresql_subject, query: type_query): Promise<type_result_get>; function postgresql_query_free_get(subject: type_postgresql_subject, query: type_query): Promise<type_result_get>;
/** /**
* @author fenris * @author fenris
* @see https://node-postgres.com/apis/pool#poolquery * @see https://node-postgres.com/apis/client#clientquery
*/ */
function postgresql_query_free_put(subject: type_postgresql_subject, query: type_query): Promise<type_result_put>; function postgresql_query_free_put(subject: type_postgresql_subject, query: type_query): Promise<type_result_put>;
/** /**
* @author fenris * @author fenris
* @see https://node-postgres.com/apis/pool#poolquery * @see https://node-postgres.com/apis/client#clientquery
*/ */
function postgresql_query_free_set(subject: type_postgresql_subject, query: type_query): Promise<type_result_set>; function postgresql_query_free_set(subject: type_postgresql_subject, query: type_query): Promise<type_result_set>;
/** /**
@ -2249,7 +2239,6 @@ declare namespace lib_plankton.database {
class class_postgresql implements interface_database { class class_postgresql implements interface_database {
private subject; private subject;
constructor(parameters: type_postgresql_parameters); constructor(parameters: type_postgresql_parameters);
wrap_name(name: any): string;
query_free_get(query: any): Promise<type_result_get>; query_free_get(query: any): Promise<type_result_get>;
query_free_put(query: any): Promise<number>; query_free_put(query: any): Promise<number>;
query_free_set(query: any): Promise<number>; query_free_set(query: any): Promise<number>;
@ -2276,9 +2265,6 @@ declare namespace lib_plankton.database {
/** /**
*/ */
function mysql_make(parameters: type_mysql_parameters): type_mysql_subject; function mysql_make(parameters: type_mysql_parameters): type_mysql_subject;
/**
*/
function mysql_wrap_name(name: string): string;
/** /**
* @author fenris * @author fenris
*/ */
@ -2332,7 +2318,6 @@ declare namespace lib_plankton.database {
class class_mysql implements interface_database { class class_mysql implements interface_database {
private subject; private subject;
constructor(parameters: type_mysql_parameters); constructor(parameters: type_mysql_parameters);
wrap_name(name: any): string;
query_free_get(query: any): Promise<type_result_get>; query_free_get(query: any): Promise<type_result_get>;
query_free_put(query: any): Promise<number>; query_free_put(query: any): Promise<number>;
query_free_set(query: any): Promise<number>; query_free_set(query: any): Promise<number>;
@ -2502,7 +2487,7 @@ declare namespace lib_plankton.storage.memory {
clear(): Promise<void>; clear(): Promise<void>;
write(key: any, value: any): Promise<boolean>; write(key: any, value: any): Promise<boolean>;
delete(key: any): Promise<void>; delete(key: any): Promise<void>;
read(key: any): Promise<Awaited<type_item>>; read(key: any): Promise<type_item>;
search(term: any): Promise<{ search(term: any): Promise<{
key: string; key: string;
preview: string; preview: string;

View file

@ -2207,7 +2207,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function verb(n) { return function (v) { return step([n, v]); }; } function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) { function step(op) {
if (f) throw new TypeError("Generator is already executing."); if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try { while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value]; if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) { switch (op[0]) {
@ -6790,13 +6790,22 @@ var lib_plankton;
} }
} }
database.sql_common_value_format = sql_common_value_format; database.sql_common_value_format = sql_common_value_format;
/**
*/
function wrap_name(name, options = {}) {
options = Object.assign({
"active": true,
}, options);
return (options.active
? ("`" + name + "`")
: name);
}
/** /**
*/ */
function sql_common_formulation_create_table(description_create_table, options = {}) { function sql_common_formulation_create_table(description_create_table, options = {}) {
var _a, _b, _c, _d, _e, _f; var _a, _b, _c, _d, _e;
options = Object.assign({ options = Object.assign({
"auto_increment_keyword": "AUTO INCREMENT", "auto_increment_keyword": "AUTO INCREMENT",
"auto_increment_special": null,
"omit_comments": false, "omit_comments": false,
"type_map": { "type_map": {
"boolean": "BOOLEAN", "boolean": "BOOLEAN",
@ -6806,11 +6815,11 @@ var lib_plankton;
"string_long": "TEXT", "string_long": "TEXT",
"float": "REAL", "float": "REAL",
}, },
"wrap_name": (x => x), "wrap_names": true,
}, options); }, options);
return { return {
"template": lib_plankton.string.coin("CREATE TABLE IF NOT EXISTS\n\t{{name}}(\n{{entries}}\n\t){{comment}}\n;", { "template": lib_plankton.string.coin("CREATE TABLE\n\t{{name}}(\n{{entries}}\n\t){{comment}}\n;", {
"name": options.wrap_name(description_create_table.name), "name": wrap_name(description_create_table.name, { "active": options.wrap_names }),
"comment": ((options.omit_comments "comment": ((options.omit_comments
|| ||
(((_a = description_create_table.description) !== null && _a !== void 0 ? _a : null) === null)) (((_a = description_create_table.description) !== null && _a !== void 0 ? _a : null) === null))
@ -6823,42 +6832,34 @@ var lib_plankton;
.concat((((_b = description_create_table.key_field) !== null && _b !== void 0 ? _b : null) === null) .concat((((_b = description_create_table.key_field) !== null && _b !== void 0 ? _b : null) === null)
? [] ? []
: lib_plankton.string.coin("{{name}} {{parameters}}", { : lib_plankton.string.coin("{{name}} {{parameters}}", {
"name": options.wrap_name(description_create_table.key_field.name), "name": wrap_name(description_create_table.key_field.name, { "active": options.wrap_names }),
"parameters": (((options.auto_increment_special === null) "parameters": (([]
? /*
([]
// type // type
.concat([ .concat(
options.type_map[(_c = description_create_table.key_field.type) !== null && _c !== void 0 ? _c : "integer"], [
]) options.type_map[description_create_table.key_field.type ?? "integer"],
// nullability ]
.concat([ )
"NOT NULL", */
// auto increment
.concat((((_c = description_create_table.key_field.auto_increment) !== null && _c !== void 0 ? _c : true) === null)
? []
: [
options.auto_increment_keyword,
]) ])
// primary key // primary key
.concat([ .concat([
"PRIMARY KEY", "PRIMARY KEY",
])
// auto increment
.concat((((_d = description_create_table.key_field.auto_increment) !== null && _d !== void 0 ? _d : true) === null)
?
[]
:
[
options.auto_increment_keyword,
])) ]))
:
[
options.auto_increment_special
])
.join(" ")), .join(" ")),
})) }))
// data fields // data fields
.concat(((_e = description_create_table.data_fields) !== null && _e !== void 0 ? _e : []) .concat(((_d = description_create_table.data_fields) !== null && _d !== void 0 ? _d : [])
.map((data_field) => { .map((data_field) => {
var _a, _b; var _a, _b;
return lib_plankton.string.coin("{{name}} {{parameters}}", { return lib_plankton.string.coin("{{name}} {{parameters}}", {
"name": options.wrap_name(data_field.name), "name": wrap_name(data_field.name, { "active": options.wrap_names }),
"parameters": (([] "parameters": (([]
// type // type
.concat([ .concat([
@ -6890,7 +6891,7 @@ var lib_plankton;
}); });
})) }))
// constraints // constraints
.concat(((_f = description_create_table.constraints) !== null && _f !== void 0 ? _f : []) .concat(((_e = description_create_table.constraints) !== null && _e !== void 0 ? _e : [])
.map((constraint) => { .map((constraint) => {
switch (constraint.kind) { switch (constraint.kind) {
default: { default: {
@ -6900,11 +6901,11 @@ var lib_plankton;
case "foreign_key": { case "foreign_key": {
return lib_plankton.string.coin("FOREIGN KEY ({{fields}}) REFERENCES {{reference_name}}({{reference_fields}})", { return lib_plankton.string.coin("FOREIGN KEY ({{fields}}) REFERENCES {{reference_name}}({{reference_fields}})", {
"fields": (constraint.parameters["fields"] "fields": (constraint.parameters["fields"]
.map(x => options.wrap_name(x)) .map(x => wrap_name(x, { "active": options.wrap_names }))
.join(",")), .join(",")),
"reference_name": options.wrap_name(constraint.parameters["reference"]["name"]), "reference_name": wrap_name(constraint.parameters["reference"]["name"], { "active": options.wrap_names }),
"reference_fields": (constraint.parameters["reference"]["fields"] "reference_fields": (constraint.parameters["reference"]["fields"]
.map(x => options.wrap_name(x)) .map(x => wrap_name(x, { "active": options.wrap_names }))
.join(",")), .join(",")),
}); });
break; break;
@ -6912,7 +6913,7 @@ var lib_plankton;
case "unique": { case "unique": {
return lib_plankton.string.coin("UNIQUE ({{fields}})", { return lib_plankton.string.coin("UNIQUE ({{fields}})", {
"fields": (constraint.parameters["fields"] "fields": (constraint.parameters["fields"]
.map(x => options.wrap_name(x)) .map(x => wrap_name(x, { "active": options.wrap_names }))
.join(",")), .join(",")),
}); });
break; break;
@ -6930,16 +6931,15 @@ var lib_plankton;
*/ */
function sql_common_formulation_insert(description_insert, options = {}) { function sql_common_formulation_insert(description_insert, options = {}) {
options = Object.assign({ options = Object.assign({
"wrap_name": (x => x), "wrap_names": true,
"set_returning": false,
}, options); }, options);
const field_names = Object.keys(description_insert.values); const field_names = Object.keys(description_insert.values);
return { return {
"template": lib_plankton.string.coin("INSERT INTO {{table_name}}({{schema}}) VALUES ({{values}}){{returning}};", { "template": lib_plankton.string.coin("INSERT INTO {{table_name}}({{schema}}) VALUES ({{values}});", {
"table_name": options.wrap_name(description_insert.table_name), "table_name": wrap_name(description_insert.table_name, { "active": options.wrap_names }),
"schema": (field_names "schema": (field_names
.map((field_name) => lib_plankton.string.coin("{{name}}", { .map((field_name) => lib_plankton.string.coin("{{name}}", {
"name": options.wrap_name(field_name), "name": wrap_name(field_name, { "active": options.wrap_names }),
})) }))
.join(",")), .join(",")),
"values": (field_names "values": (field_names
@ -6947,15 +6947,6 @@ var lib_plankton;
"name": field_name, "name": field_name,
})) }))
.join(",")), .join(",")),
"returning": ((options.set_returning
&&
((description_insert.returning !== undefined)
&&
(description_insert.returning !== null)))
?
(" RETURNING " + description_insert.returning)
:
""),
}), }),
"arguments": Object.fromEntries(Object.entries(description_insert.values) "arguments": Object.fromEntries(Object.entries(description_insert.values)
.map(([name, value]) => ([ .map(([name, value]) => ([
@ -6972,15 +6963,15 @@ var lib_plankton;
function sql_common_formulation_update(description_update, options = {}) { function sql_common_formulation_update(description_update, options = {}) {
var _a, _b; var _a, _b;
options = Object.assign({ options = Object.assign({
"wrap_name": (x => x), "wrap_names": true,
}, options); }, options);
const field_names = Object.keys(description_update.values); const field_names = Object.keys(description_update.values);
return { return {
"template": lib_plankton.string.coin("UPDATE {{table_name}} SET {{assignments}}{{macro_where}};", { "template": lib_plankton.string.coin("UPDATE {{table_name}} SET {{assignments}}{{macro_where}};", {
"table_name": options.wrap_name(description_update.table_name), "table_name": wrap_name(description_update.table_name, { "active": options.wrap_names }),
"assignments": (field_names "assignments": (field_names
.map((field_name) => lib_plankton.string.coin("{{name}} = $value_{{suffix}}", { .map((field_name) => lib_plankton.string.coin("{{name}} = $value_{{suffix}}", {
"name": options.wrap_name(field_name), "name": wrap_name(field_name, { "active": options.wrap_names }),
"suffix": field_name, "suffix": field_name,
})) }))
.join(", ")), .join(", ")),
@ -7005,11 +6996,11 @@ var lib_plankton;
function sql_common_formulation_delete(description_delete, options = {}) { function sql_common_formulation_delete(description_delete, options = {}) {
var _a, _b; var _a, _b;
options = Object.assign({ options = Object.assign({
"wrap_name": (x => x), "wrap_names": true,
}, options); }, options);
return { return {
"template": lib_plankton.string.coin("DELETE FROM {{table_name}}{{macro_where}};", { "template": lib_plankton.string.coin("DELETE FROM {{table_name}}{{macro_where}};", {
"table_name": options.wrap_name(description_delete.table_name), "table_name": wrap_name(description_delete.table_name, { "active": options.wrap_names }),
"macro_where": ((((_a = description_delete.condition) !== null && _a !== void 0 ? _a : null) === null) "macro_where": ((((_a = description_delete.condition) !== null && _a !== void 0 ? _a : null) === null)
? "" ? ""
: lib_plankton.string.coin(" WHERE {{expression}}", { : lib_plankton.string.coin(" WHERE {{expression}}", {
@ -7025,15 +7016,15 @@ var lib_plankton;
function sql_common_formulation_select(description_select, options = {}) { function sql_common_formulation_select(description_select, options = {}) {
var _a, _b, _c, _d, _e, _f, _g; var _a, _b, _c, _d, _e, _f, _g;
options = Object.assign({ options = Object.assign({
"wrap_name": (x => x), "wrap_names": true,
}, options); }, options);
return { return {
"template": lib_plankton.string.coin("SELECT {{fields}} FROM {{source}}{{macro_where}}{{macro_group_by}}{{macro_having}}{{macro_order_by}}{{macro_limit}};", { "template": lib_plankton.string.coin("SELECT {{fields}} FROM {{source}}{{macro_where}}{{macro_group_by}}{{macro_having}}{{macro_order_by}}{{macro_limit}};", {
"source": options.wrap_name(description_select.source), "source": wrap_name(description_select.source, { "active": options.wrap_names }),
"fields": ((((_a = description_select.fields) !== null && _a !== void 0 ? _a : null) === null) "fields": ((((_a = description_select.fields) !== null && _a !== void 0 ? _a : null) === null)
? "*" ? "*"
: (description_select.fields : (description_select.fields
.map(field_name => lib_plankton.string.coin("{{name}}", { "name": options.wrap_name(field_name) })) .map(field_name => lib_plankton.string.coin("{{name}}", { "name": wrap_name(field_name, { "active": options.wrap_names }) }))
.join(","))), .join(","))),
"macro_where": ((((_b = description_select.condition) !== null && _b !== void 0 ? _b : null) === null) "macro_where": ((((_b = description_select.condition) !== null && _b !== void 0 ? _b : null) === null)
? "" ? ""
@ -7099,12 +7090,6 @@ var lib_plankton;
}; };
} }
database.sqlite_make = sqlite_make; database.sqlite_make = sqlite_make;
/**
*/
function sqlite_wrap_name(name) {
return ("`" + name + "`");
}
database.sqlite_wrap_name = sqlite_wrap_name;
/** /**
*/ */
function sqlite_init(subject) { function sqlite_init(subject) {
@ -7213,8 +7198,7 @@ var lib_plankton;
*/ */
function sqlite_formulation_create_table(description_create_table) { function sqlite_formulation_create_table(description_create_table) {
return database.sql_common_formulation_create_table(description_create_table, { return database.sql_common_formulation_create_table(description_create_table, {
"auto_increment_keyword": "AUTOINCREMENT", "auto_increment_keyword": "INTEGER NOT NULL AUTOINCREMENT",
"auto_increment_special": null,
"omit_comments": true, "omit_comments": true,
"type_map": { "type_map": {
"boolean": "INTEGER", "boolean": "INTEGER",
@ -7224,7 +7208,6 @@ var lib_plankton;
"string_long": "TEXT", "string_long": "TEXT",
"float": "REAL", "float": "REAL",
}, },
"wrap_name": sqlite_wrap_name,
}); });
} }
database.sqlite_formulation_create_table = sqlite_formulation_create_table; database.sqlite_formulation_create_table = sqlite_formulation_create_table;
@ -7238,9 +7221,7 @@ var lib_plankton;
/** /**
*/ */
function sqlite_formulation_insert(description_insert) { function sqlite_formulation_insert(description_insert) {
return database.sql_common_formulation_insert(description_insert, { return database.sql_common_formulation_insert(description_insert);
"wrap_name": sqlite_wrap_name,
});
} }
database.sqlite_formulation_insert = sqlite_formulation_insert; database.sqlite_formulation_insert = sqlite_formulation_insert;
/** /**
@ -7252,9 +7233,7 @@ var lib_plankton;
/** /**
*/ */
function sqlite_formulation_update(description_update) { function sqlite_formulation_update(description_update) {
return database.sql_common_formulation_update(description_update, { return database.sql_common_formulation_update(description_update);
"wrap_name": sqlite_wrap_name,
});
} }
database.sqlite_formulation_update = sqlite_formulation_update; database.sqlite_formulation_update = sqlite_formulation_update;
/** /**
@ -7266,9 +7245,7 @@ var lib_plankton;
/** /**
*/ */
function sqlite_formulation_delete(description_delete) { function sqlite_formulation_delete(description_delete) {
return database.sql_common_formulation_delete(description_delete, { return database.sql_common_formulation_delete(description_delete);
"wrap_name": sqlite_wrap_name,
});
} }
database.sqlite_formulation_delete = sqlite_formulation_delete; database.sqlite_formulation_delete = sqlite_formulation_delete;
/** /**
@ -7280,9 +7257,7 @@ var lib_plankton;
/** /**
*/ */
function sqlite_formulation_select(description_select) { function sqlite_formulation_select(description_select) {
return database.sql_common_formulation_select(description_select, { return database.sql_common_formulation_select(description_select);
"wrap_name": sqlite_wrap_name,
});
} }
database.sqlite_formulation_select = sqlite_formulation_select; database.sqlite_formulation_select = sqlite_formulation_select;
/** /**
@ -7296,7 +7271,6 @@ var lib_plankton;
function sqlite_database(parameters) { function sqlite_database(parameters) {
const subject = sqlite_make(parameters); const subject = sqlite_make(parameters);
return { return {
"wrap_name": (name) => sqlite_wrap_name(name),
"query_free_get": (query) => sqlite_query_free_get(subject, query), "query_free_get": (query) => sqlite_query_free_get(subject, query),
"query_free_put": (query) => sqlite_query_free_put(subject, query), "query_free_put": (query) => sqlite_query_free_put(subject, query),
"query_free_set": (query) => sqlite_query_free_set(subject, query), "query_free_set": (query) => sqlite_query_free_set(subject, query),
@ -7338,7 +7312,6 @@ var lib_plankton;
*/ */
class class_sqlite { class class_sqlite {
constructor(parameters) { this.subject = database.sqlite_make(parameters); } constructor(parameters) { this.subject = database.sqlite_make(parameters); }
wrap_name(name) { return database.sqlite_wrap_name(name); }
query_free_get(query) { return database.sqlite_query_free_get(this.subject, query); } query_free_get(query) { return database.sqlite_query_free_get(this.subject, query); }
query_free_put(query) { return database.sqlite_query_free_put(this.subject, query); } query_free_put(query) { return database.sqlite_query_free_put(this.subject, query); }
query_free_set(query) { return database.sqlite_query_free_set(this.subject, query); } query_free_set(query) { return database.sqlite_query_free_set(this.subject, query); }
@ -7375,6 +7348,7 @@ var lib_plankton;
var database; var database;
(function (database) { (function (database) {
/** /**
* @see https://node-postgres.com/apis/client#new-client
*/ */
function postgresql_make(parameters) { function postgresql_make(parameters) {
var _a; var _a;
@ -7384,24 +7358,17 @@ var lib_plankton;
"username": parameters.username, "username": parameters.username,
"password": parameters.password, "password": parameters.password,
"schema": parameters.schema, "schema": parameters.schema,
"pool": null, "client": null,
}; };
} }
database.postgresql_make = postgresql_make; database.postgresql_make = postgresql_make;
/** /**
*/ */
function postgresql_wrap_name(name) {
return ("" + name + "");
}
database.postgresql_wrap_name = postgresql_wrap_name;
/**
* https://node-postgres.com/apis/pool
*/
function postgresql_init(subject) { function postgresql_init(subject) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (subject.pool === null) { if (subject.client === null) {
const nm_pg = require("pg"); const nm_pg = require("pg");
subject.pool = (new nm_pg.Pool({ subject.client = (new nm_pg.Client({
"host": subject.host, "host": subject.host,
"port": subject.port, "port": subject.port,
"database": subject.schema, "database": subject.schema,
@ -7450,54 +7417,58 @@ var lib_plankton;
} }
/** /**
* @author fenris * @author fenris
* @see https://node-postgres.com/apis/pool#poolquery * @see https://node-postgres.com/apis/client#clientquery
*/ */
function postgresql_query_free_get(subject, query) { function postgresql_query_free_get(subject, query) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
yield postgresql_init(subject); yield postgresql_init(subject);
const query_adjusted = postgresql_adjust_query(subject, query); const query_adjusted = postgresql_adjust_query(subject, query);
const result = yield subject.pool.query({ yield subject.client.connect();
const result = yield subject.client.query({
"text": query_adjusted.template, "text": query_adjusted.template,
"values": query_adjusted.arguments, "values": query_adjusted.arguments,
}); });
yield subject.client.end();
return result["rows"]; return result["rows"];
}); });
} }
database.postgresql_query_free_get = postgresql_query_free_get; database.postgresql_query_free_get = postgresql_query_free_get;
/** /**
* @author fenris * @author fenris
* @see https://node-postgres.com/apis/pool#poolquery * @see https://node-postgres.com/apis/client#clientquery
*/ */
function postgresql_query_free_put(subject, query) { function postgresql_query_free_put(subject, query) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
yield postgresql_init(subject); yield postgresql_init(subject);
const query_adjusted = postgresql_adjust_query(subject, query); const query_adjusted = postgresql_adjust_query(subject, query);
const result = yield subject.pool.query(query_adjusted.template, query_adjusted.arguments); yield subject.client.connect();
if (result["rows"].length <= 0) { const result1 = yield subject.client.query({
return null; "text": query_adjusted.template,
} "values": query_adjusted.arguments,
else { });
const x = result["rows"][0]; const result2 = yield subject.client.query({
const keys = Object.keys(x); "text": "LASTVAL();",
if (keys.length <= 0) { "values": {},
return null; });
} yield subject.client.end();
else { return result2["rows"][0]["LASTVAL"];
return x[Object.keys(x)[0]];
}
}
}); });
} }
database.postgresql_query_free_put = postgresql_query_free_put; database.postgresql_query_free_put = postgresql_query_free_put;
/** /**
* @author fenris * @author fenris
* @see https://node-postgres.com/apis/pool#poolquery * @see https://node-postgres.com/apis/client#clientquery
*/ */
function postgresql_query_free_set(subject, query) { function postgresql_query_free_set(subject, query) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
yield postgresql_init(subject); yield postgresql_init(subject);
const query_adjusted = postgresql_adjust_query(subject, query); const query_adjusted = postgresql_adjust_query(subject, query);
const result = yield subject.pool.query(query_adjusted.template, query_adjusted.arguments); yield subject.client.connect();
const result = yield subject.client.query({
"text": query_adjusted.template,
"values": query_adjusted.arguments,
});
yield subject.client.end();
return result["rowCount"]; return result["rowCount"];
}); });
} }
@ -7506,8 +7477,7 @@ var lib_plankton;
*/ */
function postgresql_formulation_create_table(description_create_table) { function postgresql_formulation_create_table(description_create_table) {
return database.sql_common_formulation_create_table(description_create_table, { return database.sql_common_formulation_create_table(description_create_table, {
"auto_increment_keyword": "", "auto_increment_keyword": "SERIAL",
"auto_increment_special": "SERIAL",
"omit_comments": false, "omit_comments": false,
"type_map": { "type_map": {
"boolean": "BOOLEAN", "boolean": "BOOLEAN",
@ -7517,7 +7487,7 @@ var lib_plankton;
"string_long": "TEXT", "string_long": "TEXT",
"float": "REAL", "float": "REAL",
}, },
"wrap_name": postgresql_wrap_name, "wrap_names": false,
}); });
} }
database.postgresql_formulation_create_table = postgresql_formulation_create_table; database.postgresql_formulation_create_table = postgresql_formulation_create_table;
@ -7531,10 +7501,7 @@ var lib_plankton;
/** /**
*/ */
function postgresql_formulation_insert(description_insert) { function postgresql_formulation_insert(description_insert) {
return database.sql_common_formulation_insert(description_insert, { return database.sql_common_formulation_insert(description_insert, { "wrap_names": false });
"wrap_name": postgresql_wrap_name,
"set_returning": true
});
} }
database.postgresql_formulation_insert = postgresql_formulation_insert; database.postgresql_formulation_insert = postgresql_formulation_insert;
/** /**
@ -7546,9 +7513,7 @@ var lib_plankton;
/** /**
*/ */
function postgresql_formulation_update(description_update) { function postgresql_formulation_update(description_update) {
return database.sql_common_formulation_update(description_update, { return database.sql_common_formulation_update(description_update, { "wrap_names": false });
"wrap_name": postgresql_wrap_name,
});
} }
database.postgresql_formulation_update = postgresql_formulation_update; database.postgresql_formulation_update = postgresql_formulation_update;
/** /**
@ -7560,9 +7525,7 @@ var lib_plankton;
/** /**
*/ */
function postgresql_formulation_delete(description_delete) { function postgresql_formulation_delete(description_delete) {
return database.sql_common_formulation_delete(description_delete, { return database.sql_common_formulation_delete(description_delete, { "wrap_names": false });
"wrap_name": postgresql_wrap_name,
});
} }
database.postgresql_formulation_delete = postgresql_formulation_delete; database.postgresql_formulation_delete = postgresql_formulation_delete;
/** /**
@ -7574,9 +7537,7 @@ var lib_plankton;
/** /**
*/ */
function postgresql_formulation_select(description_select) { function postgresql_formulation_select(description_select) {
return database.sql_common_formulation_select(description_select, { return database.sql_common_formulation_select(description_select, { "wrap_names": false });
"wrap_name": postgresql_wrap_name,
});
} }
database.postgresql_formulation_select = postgresql_formulation_select; database.postgresql_formulation_select = postgresql_formulation_select;
/** /**
@ -7590,7 +7551,6 @@ var lib_plankton;
function postgresql_database(parameters) { function postgresql_database(parameters) {
const subject = postgresql_make(parameters); const subject = postgresql_make(parameters);
return { return {
"wrap_name": (name) => postgresql_wrap_name(name),
"query_free_get": (query) => postgresql_query_free_get(subject, query), "query_free_get": (query) => postgresql_query_free_get(subject, query),
"query_free_put": (query) => postgresql_query_free_put(subject, query), "query_free_put": (query) => postgresql_query_free_put(subject, query),
"query_free_set": (query) => postgresql_query_free_set(subject, query), "query_free_set": (query) => postgresql_query_free_set(subject, query),
@ -7632,7 +7592,6 @@ var lib_plankton;
*/ */
class class_postgresql { class class_postgresql {
constructor(parameters) { this.subject = database.postgresql_make(parameters); } constructor(parameters) { this.subject = database.postgresql_make(parameters); }
wrap_name(name) { return database.postgresql_wrap_name(name); }
query_free_get(query) { return database.postgresql_query_free_get(this.subject, query); } query_free_get(query) { return database.postgresql_query_free_get(this.subject, query); }
query_free_put(query) { return database.postgresql_query_free_put(this.subject, query); } query_free_put(query) { return database.postgresql_query_free_put(this.subject, query); }
query_free_set(query) { return database.postgresql_query_free_set(this.subject, query); } query_free_set(query) { return database.postgresql_query_free_set(this.subject, query); }
@ -7674,12 +7633,6 @@ var lib_plankton;
throw (new Error("not implemented")); throw (new Error("not implemented"));
} }
database.mysql_make = mysql_make; database.mysql_make = mysql_make;
/**
*/
function mysql_wrap_name(name) {
return ("`" + name + "`");
}
database.mysql_wrap_name = mysql_wrap_name;
/** /**
*/ */
function mysql_init(subject) { function mysql_init(subject) {
@ -7737,7 +7690,6 @@ var lib_plankton;
"string_long": "TEXT", "string_long": "TEXT",
"float": "REAL", "float": "REAL",
}, },
"wrap_name": mysql_wrap_name,
}); });
} }
database.mysql_formulation_create_table = mysql_formulation_create_table; database.mysql_formulation_create_table = mysql_formulation_create_table;
@ -7751,9 +7703,7 @@ var lib_plankton;
/** /**
*/ */
function mysql_formulation_insert(description_insert) { function mysql_formulation_insert(description_insert) {
return database.sql_common_formulation_insert(description_insert, { return database.sql_common_formulation_insert(description_insert);
"wrap_name": mysql_wrap_name,
});
} }
database.mysql_formulation_insert = mysql_formulation_insert; database.mysql_formulation_insert = mysql_formulation_insert;
/** /**
@ -7765,9 +7715,7 @@ var lib_plankton;
/** /**
*/ */
function mysql_formulation_update(description_update) { function mysql_formulation_update(description_update) {
return database.sql_common_formulation_update(description_update, { return database.sql_common_formulation_update(description_update);
"wrap_name": mysql_wrap_name,
});
} }
database.mysql_formulation_update = mysql_formulation_update; database.mysql_formulation_update = mysql_formulation_update;
/** /**
@ -7779,9 +7727,7 @@ var lib_plankton;
/** /**
*/ */
function mysql_formulation_delete(description_delete) { function mysql_formulation_delete(description_delete) {
return database.sql_common_formulation_delete(description_delete, { return database.sql_common_formulation_delete(description_delete);
"wrap_name": mysql_wrap_name,
});
} }
database.mysql_formulation_delete = mysql_formulation_delete; database.mysql_formulation_delete = mysql_formulation_delete;
/** /**
@ -7793,9 +7739,7 @@ var lib_plankton;
/** /**
*/ */
function mysql_formulation_select(description_select) { function mysql_formulation_select(description_select) {
return database.sql_common_formulation_select(description_select, { return database.sql_common_formulation_select(description_select);
"wrap_name": mysql_wrap_name,
});
} }
database.mysql_formulation_select = mysql_formulation_select; database.mysql_formulation_select = mysql_formulation_select;
/** /**
@ -7809,7 +7753,6 @@ var lib_plankton;
function mysql_database(parameters) { function mysql_database(parameters) {
const subject = mysql_make(parameters); const subject = mysql_make(parameters);
return { return {
"wrap_name": (name) => mysql_wrap_name(name),
"query_free_get": (query) => mysql_query_free_get(subject, query), "query_free_get": (query) => mysql_query_free_get(subject, query),
"query_free_put": (query) => mysql_query_free_put(subject, query), "query_free_put": (query) => mysql_query_free_put(subject, query),
"query_free_set": (query) => mysql_query_free_set(subject, query), "query_free_set": (query) => mysql_query_free_set(subject, query),
@ -7851,7 +7794,6 @@ var lib_plankton;
*/ */
class class_mysql { class class_mysql {
constructor(parameters) { this.subject = database.mysql_make(parameters); } constructor(parameters) { this.subject = database.mysql_make(parameters); }
wrap_name(name) { return database.mysql_wrap_name(name); }
query_free_get(query) { return database.mysql_query_free_get(this.subject, query); } query_free_get(query) { return database.mysql_query_free_get(this.subject, query); }
query_free_put(query) { return database.mysql_query_free_put(this.subject, query); } query_free_put(query) { return database.mysql_query_free_put(this.subject, query); }
query_free_set(query) { return database.mysql_query_free_set(this.subject, query); } query_free_set(query) { return database.mysql_query_free_set(this.subject, query); }
@ -7879,7 +7821,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function verb(n) { return function (v) { return step([n, v]); }; } function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) { function step(op) {
if (f) throw new TypeError("Generator is already executing."); if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try { while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value]; if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) { switch (op[0]) {
@ -8292,8 +8234,7 @@ var lib_plankton;
return __generator(this, function (_a) { return __generator(this, function (_a) {
return [2 /*return*/, subject.database_implementation.query_insert({ return [2 /*return*/, subject.database_implementation.query_insert({
"table_name": subject.table_name, "table_name": subject.table_name,
"values": value, "values": value
"returning": subject.key_name
})]; })];
}); });
}); });
@ -8307,8 +8248,8 @@ var lib_plankton;
return [2 /*return*/, (subject.database_implementation.query_update({ return [2 /*return*/, (subject.database_implementation.query_update({
"table_name": subject.table_name, "table_name": subject.table_name,
"values": value, "values": value,
"condition": lib_plankton.string.coin("{{key_name}} = $key", { "condition": lib_plankton.string.coin("`{{key_name}}` = $key", {
"key_name": subject.database_implementation.wrap_name(subject.key_name) "key_name": subject.key_name
}), }),
"arguments": { "arguments": {
"key": key "key": key
@ -8327,8 +8268,8 @@ var lib_plankton;
switch (_a.label) { switch (_a.label) {
case 0: return [4 /*yield*/, subject.database_implementation.query_delete({ case 0: return [4 /*yield*/, subject.database_implementation.query_delete({
"table_name": subject.table_name, "table_name": subject.table_name,
"condition": lib_plankton.string.coin("{{key_name}} = $key", { "condition": lib_plankton.string.coin("`{{key_name}}` = $key", {
"key_name": subject.database_implementation.wrap_name(subject.key_name) "key_name": subject.key_name
}), }),
"arguments": { "arguments": {
"key": key "key": key
@ -8352,8 +8293,8 @@ var lib_plankton;
case 0: return [4 /*yield*/, subject.database_implementation.query_select({ case 0: return [4 /*yield*/, subject.database_implementation.query_select({
"source": subject.table_name, "source": subject.table_name,
"fields": null, "fields": null,
"condition": lib_plankton.string.coin("{{key_name}} = $key", { "condition": lib_plankton.string.coin("`{{key_name}}` = $key", {
"key_name": subject.database_implementation.wrap_name(subject.key_name) "key_name": subject.key_name
}), }),
"arguments": { "arguments": {
"key": key "key": key
@ -8501,9 +8442,8 @@ var lib_plankton;
return { return {
"condition": lib_string.coin("({{clauses}})", { "condition": lib_string.coin("({{clauses}})", {
"clauses": (subject.key_names "clauses": (subject.key_names
.map(function (key_name) { return lib_plankton.string.coin("({{name1}} = $key_{{name2}})", { .map(function (key_name) { return lib_plankton.string.coin("(`{{name}}` = $key_{{name}})", {
"name1": subject.database_implementation.wrap_name(key_name), "name": key_name
"name2": key_name
}); }) }); })
.join(" AND ")) .join(" AND "))
}), }),
@ -8752,7 +8692,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function verb(n) { return function (v) { return step([n, v]); }; } function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) { function step(op) {
if (f) throw new TypeError("Generator is already executing."); if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try { while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value]; if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) { switch (op[0]) {
@ -10062,8 +10002,7 @@ var lib_plankton;
} }
} }
const body = ([http.enum_method.post, http.enum_method.put, http.enum_method.patch].includes(method) const body = ([http.enum_method.post, http.enum_method.put, http.enum_method.patch].includes(method)
// @ts-ignore ? Buffer["from"](lines.join(linebreak))
? Buffer.from(lines.join(linebreak))
: null); : null);
const request = { const request = {
// TODO // TODO
@ -10124,8 +10063,7 @@ var lib_plankton;
headers[key.toLowerCase()] = value; headers[key.toLowerCase()] = value;
} }
} }
// @ts-ignore const body = Buffer["from"](lines.join(linebreak));
const body = Buffer.from(lines.join(linebreak));
const response = { const response = {
// TODO // TODO
"version": version, "version": version,

View file

@ -221,7 +221,8 @@ namespace _espe.conf
conf_raw : any conf_raw : any
) : void ) : void
{ {
const version : int = (conf_raw["version"] ?? 4); switch (conf_raw["version"]) {
case 1: {
_data = { _data = {
"general": ( "general": (
((node_general) => ({ ((node_general) => ({
@ -229,69 +230,17 @@ namespace _espe.conf
"verification_secret": (node_general["verification_secret"] ?? null), "verification_secret": (node_general["verification_secret"] ?? null),
})) (conf_raw["general"] ?? {}) })) (conf_raw["general"] ?? {})
), ),
"log": ( "log": [
(() => {
switch (version) {
case 1: {
return [
{ {
"kind": "stdout", "kind": "stdout",
"data": { "data": {
"threshold": ((conf_raw["general"] ?? {})["verbosity"] ?? "notice"), "threshold": ((conf_raw["general"] ?? {})["verbosity"] ?? "notice"),
} }
}, },
]; ],
break;
}
case 2:
case 3:
case 4: {
const node_log = (
conf_raw["log"]
??
[
{
"kind": "stdout",
"data": {
}
},
]
);
return (
node_log.map(
(node_log_entry : any) => ({
"kind": node_log_entry["kind"],
"data": Object.assign(
{
"format": "human_readable",
"threshold": "notice",
},
(node_log_entry["data"] ?? {})
)
})
)
);
break;
}
}
}) ()
),
"server": ( "server": (
((node_server) => ({ ((node_server) => ({
"host": (() => { "host": "::",
switch (version) {
case 1:
case 2:
case 3: {
return "::";
break;
}
case 4: {
return (node_server["host"] ?? "::");
break
}
}
}) (),
"port": (node_server["port"] ?? 4916), "port": (node_server["port"] ?? 4916),
"path_base": (node_server["path_base"] ?? ""), "path_base": (node_server["path_base"] ?? ""),
})) (conf_raw["server"] ?? {}) })) (conf_raw["server"] ?? {})
@ -435,15 +384,10 @@ namespace _espe.conf
})) (conf_raw["settings"] ?? {}) })) (conf_raw["settings"] ?? {})
), ),
"admins": (conf_raw["admins"] ?? []), "admins": (conf_raw["admins"] ?? []),
"outputs": (() => { "outputs": (
switch (version) { ((node_output) => (
case 1:
case 2: {
const node_output = (conf_raw["output"] ?? {});
return (
("authelia" in node_output) ("authelia" in node_output)
? ? [
[
{ {
"kind": "authelia_file", "kind": "authelia_file",
"data": { "data": {
@ -451,19 +395,571 @@ namespace _espe.conf
} }
} }
] ]
: : [
[
] ]
); )) (conf_raw["output"] ?? {})
),
};
break;
}
case 2: {
_data = {
"general": (
((node_general) => ({
"language": (node_general["language"] ?? null),
"verification_secret": (node_general["verification_secret"] ?? null),
})) (conf_raw["general"] ?? {})
),
"log": (
((node_log) => node_log.map(
(node_log_entry : any) => ({
"kind": node_log_entry["kind"],
"data": Object.assign(
{
"format": "human_readable",
"threshold": "notice",
},
(node_log_entry["data"] ?? {})
)
})
)) (
conf_raw["log"]
??
[
{
"kind": "console",
"data": {
}
},
]
)
),
"server": (
((node_server) => ({
"host": "::",
"port": (node_server["port"] ?? 4916),
"path_base": (node_server["path_base"] ?? ""),
})) (conf_raw["server"] ?? {})
),
"database": (
((node_database) => {
const kind : string = (node_database["kind"] ?? "sqlite");
const node_database_data_raw = (node_database["data"] ?? {});
switch (kind) {
case "sqlite": {
return {
"kind": kind,
"data": {
"path": (node_database_data_raw["path"] ?? "data.sqlite"),
}
};
break;
}
case "postgresql": {
return {
"kind": kind,
"data": node_database_data_raw,
};
break;
}
default: {
throw (new Error("unhandled"));
break;
}
}
}) (conf_raw["database"] ?? {})
),
"email_sending": (
((node_email_sending) => {
const kind : string = (node_email_sending["kind"] ?? "console");
const data_raw = (node_email_sending["data"] ?? {});
switch (kind) {
case "regular": {
return {
"kind": kind,
"data": {
"smtp_credentials": (data_raw["smtp_credentials"] ?? null),
"sender": data_raw["sender"],
}
};
break;
}
case "redirect": {
return {
"kind": kind,
"data": {
"smtp_credentials": (data_raw["smtp_credentials"] ?? null),
"sender": data_raw["sender"],
"target": data_raw["target"],
}
};
break;
}
case "console": {
return {
"kind": kind,
"data": {
}
};
break;
}
case "drop": {
return {
"kind": kind,
"data": {
}
};
break;
}
default: {
throw (new Error("unhandled"));
break;
}
}
}) (conf_raw["email_sending"] ?? {})
),
"session_management": (
((node_session_management) => ({
"in_memory": (node_session_management["in_memory"] ?? true),
"drop_all_at_start": (node_session_management["drop_all_at_start"] ?? true),
"lifetime": (node_session_management["lifetime"] ?? 900),
})) (conf_raw["session_management"] ?? {})
),
"settings": (
((node_settings) => ({
"organisation": {
"name": ((node_settings["organisation"] ?? {})["name"] ?? "Example Orginsation"), // TODO: mandatory?
"domain": ((node_settings["organisation"] ?? {})["domain"] ?? "example.org"), // TODO: mandatory?
},
"misc": (
((node_settings_misc) => ({
"prefix_for_veiled_email_addresses": (node_settings_misc["prefix_for_veiled_email_addresses"] ?? "member-"),
"facultative_membership_number": (node_settings_misc["facultative_membership_number"] ?? false),
"auto_register": (node_settings_misc["auto_register"] ?? false),
})) (node_settings["misc"] ?? {})
),
"summon_email": (
((node_settings_summon_email) => ({
"remark": (node_settings_summon_email["remark"] ?? null),
})) (node_settings["summon_email"] ?? {})
),
"password_policy": (
((node_settings_password_policy) => ({
"minimum_length": (
("minimum_length" in node_settings_password_policy)
? node_settings_password_policy["minimum_length"]
: 8
),
"maximum_length": (
("maximum_length" in node_settings_password_policy)
? node_settings_password_policy["maximum_length"]
: 240
),
"must_contain_letter": (node_settings_password_policy["must_contain_letter"] ?? true),
"must_contain_number": (node_settings_password_policy["must_contain_number"] ?? true),
"must_contain_special_character": (node_settings_password_policy["must_contain_special_character"] ?? true),
})) (node_settings["password_policy"] ?? {})
),
"password_change": (
((node_settings_password_change) => ({
"cooldown_time": (node_settings_password_change["cooldown_time"] ?? 86400),
})) (node_settings["password_change"] ?? {})
),
"name_index": (
((node_settings_password_policy) => ({
"veil": (node_settings_password_policy["veil"] ?? true),
"salt": (node_settings_password_policy["salt"] ?? ""),
})) (node_settings["name_index"] ?? {})
),
"connections": (
((node_settings_connections) => ({
"frontend_url_base": (node_settings_connections["frontend_url_base"] ?? null),
"login_url": (node_settings_connections["login_url"] ?? null),
})) (node_settings["connections"] ?? {})
),
})) (conf_raw["settings"] ?? {})
),
"admins": (conf_raw["admins"] ?? []),
"outputs": (
((node_output) => (
("authelia" in node_output)
? [
{
"kind": "authelia_file",
"data": {
"path": node_output["authelia"],
}
}
]
: [
]
)) (conf_raw["output"] ?? {})
),
};
break; break;
} }
case 3: { case 3: {
return (conf_raw["outputs"] ?? []); _data = {
"general": (
((node_general) => ({
"language": (node_general["language"] ?? null),
"verification_secret": (node_general["verification_secret"] ?? null),
})) (conf_raw["general"] ?? {})
),
"log": (
((node_log) => node_log.map(
(node_log_entry : any) => ({
"kind": node_log_entry["kind"],
"data": Object.assign(
{
"format": "human_readable",
"threshold": "notice",
},
(node_log_entry["data"] ?? {})
)
})
)) (
conf_raw["log"]
??
[
{
"kind": "console",
"data": {
}
},
]
)
),
"server": (
((node_server) => ({
"host": "::",
"port": (node_server["port"] ?? 4916),
"path_base": (node_server["path_base"] ?? ""),
})) (conf_raw["server"] ?? {})
),
"database": (
((node_database) => {
const kind : string = (node_database["kind"] ?? "sqlite");
const node_database_data_raw = (node_database["data"] ?? {});
switch (kind) {
case "sqlite": {
return {
"kind": kind,
"data": {
"path": (node_database_data_raw["path"] ?? "data.sqlite"),
}
};
break;
}
case "postgresql": {
return {
"kind": kind,
"data": node_database_data_raw,
};
break;
}
default: {
throw (new Error("unhandled"));
break;
}
}
}) (conf_raw["database"] ?? {})
),
"email_sending": (
((node_email_sending) => {
const kind : string = (node_email_sending["kind"] ?? "console");
const data_raw = (node_email_sending["data"] ?? {});
switch (kind) {
case "regular": {
return {
"kind": kind,
"data": {
"smtp_credentials": (data_raw["smtp_credentials"] ?? null),
"sender": data_raw["sender"],
}
};
break;
}
case "redirect": {
return {
"kind": kind,
"data": {
"smtp_credentials": (data_raw["smtp_credentials"] ?? null),
"sender": data_raw["sender"],
"target": data_raw["target"],
}
};
break;
}
case "console": {
return {
"kind": kind,
"data": {
}
};
break;
}
case "drop": {
return {
"kind": kind,
"data": {
}
};
break;
}
default: {
throw (new Error("unhandled"));
break;
}
}
}) (conf_raw["email_sending"] ?? {})
),
"session_management": (
((node_session_management) => ({
"in_memory": (node_session_management["in_memory"] ?? true),
"drop_all_at_start": (node_session_management["drop_all_at_start"] ?? true),
"lifetime": (node_session_management["lifetime"] ?? 900),
})) (conf_raw["session_management"] ?? {})
),
"settings": (
((node_settings) => ({
"organisation": {
"name": ((node_settings["organisation"] ?? {})["name"] ?? "Example Orginsation"), // TODO: mandatory?
"domain": ((node_settings["organisation"] ?? {})["domain"] ?? "example.org"), // TODO: mandatory?
},
"misc": (
((node_settings_misc) => ({
"prefix_for_veiled_email_addresses": (node_settings_misc["prefix_for_veiled_email_addresses"] ?? "member-"),
"facultative_membership_number": (node_settings_misc["facultative_membership_number"] ?? false),
"auto_register": (node_settings_misc["auto_register"] ?? false),
})) (node_settings["misc"] ?? {})
),
"summon_email": (
((node_settings_summon_email) => ({
"remark": (node_settings_summon_email["remark"] ?? null),
})) (node_settings["summon_email"] ?? {})
),
"password_policy": (
((node_settings_password_policy) => ({
"minimum_length": (
("minimum_length" in node_settings_password_policy)
? node_settings_password_policy["minimum_length"]
: 8
),
"maximum_length": (
("maximum_length" in node_settings_password_policy)
? node_settings_password_policy["maximum_length"]
: 240
),
"must_contain_letter": (node_settings_password_policy["must_contain_letter"] ?? true),
"must_contain_number": (node_settings_password_policy["must_contain_number"] ?? true),
"must_contain_special_character": (node_settings_password_policy["must_contain_special_character"] ?? true),
})) (node_settings["password_policy"] ?? {})
),
"password_change": (
((node_settings_password_change) => ({
"cooldown_time": (node_settings_password_change["cooldown_time"] ?? 86400),
})) (node_settings["password_change"] ?? {})
),
"name_index": (
((node_settings_password_policy) => ({
"veil": (node_settings_password_policy["veil"] ?? true),
"salt": (node_settings_password_policy["salt"] ?? ""),
})) (node_settings["name_index"] ?? {})
),
"connections": (
((node_settings_connections) => ({
"frontend_url_base": (node_settings_connections["frontend_url_base"] ?? null),
"login_url": (node_settings_connections["login_url"] ?? null),
})) (node_settings["connections"] ?? {})
),
})) (conf_raw["settings"] ?? {})
),
"admins": (conf_raw["admins"] ?? []),
"outputs": (conf_raw["outputs"] ?? []),
};
break; break;
} }
case 4: { case 4: {
const node_outputs = (conf_raw["outputs"] ?? []); _data = {
return node_outputs.map( "general": (
((node_general) => ({
"language": (node_general["language"] ?? null),
"verification_secret": (node_general["verification_secret"] ?? null),
})) (conf_raw["general"] ?? {})
),
"log": (
((node_log) => node_log.map(
(node_log_entry : any) => ({
"kind": node_log_entry["kind"],
"data": Object.assign(
{
"format": "human_readable",
"threshold": "notice",
},
(node_log_entry["data"] ?? {})
)
})
)) (
conf_raw["log"]
??
[
{
"kind": "console",
"data": {
}
},
]
)
),
"server": (
((node_server) => ({
"host": (node_server["host"] ?? "::"),
"port": (node_server["port"] ?? 4916),
"path_base": (node_server["path_base"] ?? ""),
})) (conf_raw["server"] ?? {})
),
"database": (
((node_database) => {
const kind : string = (node_database["kind"] ?? "sqlite");
const node_database_data_raw = (node_database["data"] ?? {});
switch (kind) {
case "sqlite": {
return {
"kind": kind,
"data": {
"path": (node_database_data_raw["path"] ?? "data.sqlite"),
}
};
break;
}
case "postgresql": {
return {
"kind": kind,
"data": node_database_data_raw,
};
break;
}
default: {
throw (new Error("unhandled"));
break;
}
}
}) (conf_raw["database"] ?? {})
),
"email_sending": (
((node_email_sending) => {
const kind : string = (node_email_sending["kind"] ?? "console");
const data_raw = (node_email_sending["data"] ?? {});
switch (kind) {
case "regular": {
return {
"kind": kind,
"data": {
"smtp_credentials": (data_raw["smtp_credentials"] ?? null),
"sender": data_raw["sender"],
}
};
break;
}
case "redirect": {
return {
"kind": kind,
"data": {
"smtp_credentials": (data_raw["smtp_credentials"] ?? null),
"sender": data_raw["sender"],
"target": data_raw["target"],
}
};
break;
}
case "console": {
return {
"kind": kind,
"data": {
}
};
break;
}
case "drop": {
return {
"kind": kind,
"data": {
}
};
break;
}
default: {
throw (new Error("unhandled"));
break;
}
}
}) (conf_raw["email_sending"] ?? {})
),
"session_management": (
((node_session_management) => ({
"in_memory": (node_session_management["in_memory"] ?? true),
"drop_all_at_start": (node_session_management["drop_all_at_start"] ?? true),
"lifetime": (node_session_management["lifetime"] ?? 900),
})) (conf_raw["session_management"] ?? {})
),
"settings": (
((node_settings) => ({
"organisation": {
"name": ((node_settings["organisation"] ?? {})["name"] ?? "Example Orginsation"), // TODO: mandatory?
"domain": ((node_settings["organisation"] ?? {})["domain"] ?? "example.org"), // TODO: mandatory?
},
"misc": (
((node_settings_misc) => ({
"prefix_for_veiled_email_addresses": (node_settings_misc["prefix_for_veiled_email_addresses"] ?? "member-"),
"facultative_membership_number": (node_settings_misc["facultative_membership_number"] ?? false),
"auto_register": (node_settings_misc["auto_register"] ?? false),
})) (node_settings["misc"] ?? {})
),
"summon_email": (
((node_settings_summon_email) => ({
"remark": (node_settings_summon_email["remark"] ?? null),
})) (node_settings["summon_email"] ?? {})
),
"password_policy": (
((node_settings_password_policy) => ({
"minimum_length": (
("minimum_length" in node_settings_password_policy)
? node_settings_password_policy["minimum_length"]
: 8
),
"maximum_length": (
("maximum_length" in node_settings_password_policy)
? node_settings_password_policy["maximum_length"]
: 240
),
"must_contain_letter": (node_settings_password_policy["must_contain_letter"] ?? true),
"must_contain_number": (node_settings_password_policy["must_contain_number"] ?? true),
"must_contain_special_character": (node_settings_password_policy["must_contain_special_character"] ?? true),
})) (node_settings["password_policy"] ?? {})
),
"password_change": (
((node_settings_password_change) => ({
"cooldown_time": (node_settings_password_change["cooldown_time"] ?? 86400),
})) (node_settings["password_change"] ?? {})
),
"name_index": (
((node_settings_password_policy) => ({
"veil": (node_settings_password_policy["veil"] ?? true),
"salt": (node_settings_password_policy["salt"] ?? ""),
})) (node_settings["name_index"] ?? {})
),
"connections": (
((node_settings_connections) => ({
"frontend_url_base": (node_settings_connections["frontend_url_base"] ?? null),
"login_url": (node_settings_connections["login_url"] ?? null),
})) (node_settings["connections"] ?? {})
),
})) (conf_raw["settings"] ?? {})
),
"admins": (conf_raw["admins"] ?? []),
"outputs": (
((node_outputs) => node_outputs.map(
(output_description : {kind : string; data : any;}) => { (output_description : {kind : string; data : any;}) => {
const kind : string = output_description["kind"]; const kind : string = output_description["kind"];
const node_options_data_raw = (output_description["data"] ?? {}); const node_options_data_raw = (output_description["data"] ?? {});
@ -509,12 +1005,16 @@ namespace _espe.conf
} }
} }
} }
); )) (conf_raw["outputs"] ?? [])
),
};
break;
}
default: {
throw (new Error("invalid conf version: " + conf_raw["version"]));
break; break;
} }
} }
}) (),
};
} }

View file

@ -341,7 +341,7 @@ async function main(
break; break;
} }
case "arc": { case "arc": {
return (() => _espe.service.member.output_arc(output_description.data)); return (() => _espe.service.member.output_authelia_call(output_description.data));
break; break;
} }
} }

View file

@ -937,7 +937,7 @@ namespace _espe.service.member
/** /**
*/ */
export async function output_arc( export async function output_authelia_call(
output_parameters : { output_parameters : {
http_scheme : ("http" | "https"); http_scheme : ("http" | "https");
http_host : string; http_host : string;
@ -987,7 +987,7 @@ namespace _espe.service.member
); );
if (http_response.status_code !== 200) { if (http_response.status_code !== 200) {
lib_plankton.log.warning( lib_plankton.log.warning(
"output_arcback_failed", "output_authelia_callback_failed",
{ {
"http_response_status_code": http_response.status_code, "http_response_status_code": http_response.status_code,
} }