From 5fe57125878acae6f25fe7e6ddef3b01b4557380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Thu, 20 Jun 2024 15:13:58 +0200 Subject: [PATCH] [add] helper.password --- lib/plankton/plankton.d.ts | 1705 ++++++++------ lib/plankton/plankton.js | 4528 ++++++++++++++++++++---------------- source/helpers/password.ts | 325 +++ source/services/member.ts | 96 +- source/test/data.json | 186 +- source/test/main.mocha.ts | 45 +- tools/makefile | 5 +- tools/update-plankton | 2 + 8 files changed, 3918 insertions(+), 2974 deletions(-) create mode 100644 source/helpers/password.ts diff --git a/lib/plankton/plankton.d.ts b/lib/plankton/plankton.d.ts index c677f51..369e0a7 100644 --- a/lib/plankton/plankton.d.ts +++ b/lib/plankton/plankton.d.ts @@ -1,15 +1,15 @@ /** * @author fenris */ -type int = number; +declare type int = number; /** * @author fenris */ -type float = number; +declare type float = number; /** * @author fenris */ -type type_date = { +declare type type_date = { year: int; month: int; day: int; @@ -17,7 +17,7 @@ type type_date = { /** * @author fenris */ -type type_time = { +declare type type_time = { hour: int; minute: int; second: int; @@ -25,7 +25,7 @@ type type_time = { /** * @author fenris */ -type type_datetimeobject = { +declare type type_datetimeobject = { date: type_date; time: type_time; }; @@ -44,7 +44,7 @@ declare namespace lib_plankton.base { /** * @author fenris */ -type type_pseudopointer = { +declare type type_pseudopointer = { value: type_value; }; /** @@ -691,6 +691,207 @@ declare namespace lib_plankton.call { seconds: (null | float); }>; } +declare namespace lib_plankton.list { + /** + * @desc returns a certain list of integer numbers + * @param {int} from + * @param {int} to + * @param {int} step; default: 1 + * @author fenris + */ + function range(from: int, to: int, step?: int): Array; + /** + * @desc returns a certain list of integer numbers + * @param {int} length + * @author fenris + */ + function sequence(length: int): Array; + /** + * @author fenris + */ + function from_structure(structure: { + length: int; + }): Array; + /** + * @author fenris + */ + function from_iterator(iterator: any): Array; + /** + * @author fenris + */ + function empty(list: Array): boolean; + /** + * @desc creates a list, which contains pairs of elements from the input lists (corresponding by index) + * @param {boolean} [cut] whether the result list will be as long as the shortest input list or an exception is thrown if they have different lengths; default: true + * @author fenris + */ + function zip(list1: Array, list2: Array, cut?: boolean): Array<{ + first: type_element1; + second: type_element2; + }>; + /** + * @desc checks whether two lists are equal + * @todo define common function "equals" and default predicate to + * @author fenris + */ + function equals(list1: Array, list2: Array, collate?: (element1: type_element, element2: type_element) => boolean): boolean; + /** + * @author fenris + */ + function reversed(list: Array): Array; + /** + * @author fenris + */ + function sorted(list: Array, order: (element1: type_element, element2: type_element) => int): Array; + /** + * @desc creates a list with the elements from the input list, which fulfil a certain predicate + * @author fenris + */ + function keep(list: Array, predicate: (element: type_element, index?: int) => boolean): Array; + /** + * @desc creates a list with the elements from the input list, which do not fulfil a certain predicate + * @author fenris + */ + function drop(list: Array, predicate: (element: type_element, index?: int) => boolean): Array; + /** + * @desc returns a list with no duplicates + * @author fenris + */ + function clean(list: Array, collate?: (x: type_element, y: type_element) => boolean): Array; + /** + * @author fenris + */ + function clone(list: Array): Array; + /** + * @desc creates a binary partition of the list according to a given predicate + * @author fenris + */ + type type_separation = { + yes: Array; + no: Array; + }; + function separate(list: Array, predicate: (element: type_element) => boolean): type_separation; + /** + * die Liste in gleich große Blöcke zerlegen + * + * @author fenris + */ + function split(list: Array, chunk_size: int): Array>; + /** + * @author fenris + */ + function group(list: Array, collate?: (x: type_element, y: type_element) => boolean): Array>; + /** + * @author fenris + */ + function groups_(list: Array, collate?: (x: type_element, y: type_element) => boolean): Array>; + /** + * @author fenris + * @deprecated + */ + function groups(list: Array, sorting: (x: type_element, y: type_element) => int, hashing: (element: type_element) => type_value): Array>; + /** + * @desc searches for the first element in a list, that fulfils a given condition + * @author fenris + */ + function find(list: Array, predicate: (element: type_element) => boolean, null_if_not_found?: boolean): type_element; + /** + * @author fenris + */ + function has(list: Array, predicate: (element: type_element) => boolean): boolean; + /** + * @author fenris + */ + function contains(list: Array, element: type_element, collation?: (element1: type_element, element2: type_element) => boolean): boolean; + /** + * @desc retrieves the element and its index of the list, which has the maximum value + * @author fenris + */ + type type_result_max = { + index: int; + element: type_element; + value: type_value; + }; + function max(list: Array, targetfunction: (element: type_element) => type_value, compare?: (value1: type_value, value2: type_value) => boolean): type_result_max; + /** + * @desc retrieves the element and its index of the list, which has the mininum value + * @author fenris + */ + function min(list: Array, targetfunction: (element: type_element) => type_value, compare?: (value1: type_value, value2: type_value) => boolean): type_result_max; + /** + * @desc retrieves the element of the list, which has the maximum output for a given target-function + * @author fenris + */ + function maxarg(list: Array, targetfunction: (element: type_element) => type_value, compare?: (value1: type_value, value2: type_value) => boolean): type_element; + /** + * @desc retrieves the element of the list, which has the minimum output for a given target-function + * @author fenris + */ + function minarg(list: Array, targetfunction: (element: type_element) => type_value, compare?: (value1: type_value, value2: type_value) => boolean): type_element; + /** + * @desc implements the idea of arithmetic distribution like in "(a+b)·(c+d) = (a·c)+(a·d)+(b·c)+(b·d)" + * example: distribute([[1,2],[3],[4,5,6]]) = [[1,3,4],[1,3,5],[1,3,6],[2,3,4],[2,3,5],[2,3,6]] + * @author fenris + */ + function distribute(lists: Array>): Array>; + /** + * @desc lexicographic order + * @author fenris + * @deprecated + */ + function lex(list1: Array, list2: Array, order?: (element1: type_element, element2: type_element) => int): int; + function lex_lt(list1: Array, list2: Array): boolean; + function lex_gt(list1: Array, list2: Array): boolean; + function lex_le(list1: Array, list2: Array): boolean; + function lex_ge(list1: Array, list2: Array): boolean; + function lex_eq(list1: Array, list2: Array): boolean; + function lex_ne(list1: Array, list2: Array): boolean; + /** + * @author fenris + */ + function filter_inplace(list: Array, predicate: (element: type_element, index?: int) => boolean): void; +} +/** + * @deprecated + */ +declare namespace lib_list { + type type_separation = lib_plankton.list.type_separation; + type type_result_max = lib_plankton.list.type_result_max; + const range: typeof lib_plankton.list.range; + const sequence: typeof lib_plankton.list.sequence; + const from_structure: typeof lib_plankton.list.from_structure; + const from_iterator: typeof lib_plankton.list.from_iterator; + const empty: typeof lib_plankton.list.empty; + const zip: typeof lib_plankton.list.zip; + const equals: typeof lib_plankton.list.equals; + const reversed: typeof lib_plankton.list.reversed; + const sorted: typeof lib_plankton.list.sorted; + const keep: typeof lib_plankton.list.keep; + const drop: typeof lib_plankton.list.drop; + const clean: typeof lib_plankton.list.clean; + const clone: typeof lib_plankton.list.clone; + const separate: typeof lib_plankton.list.separate; + const split: typeof lib_plankton.list.split; + const group: typeof lib_plankton.list.group; + const groups_: typeof lib_plankton.list.groups_; + const groups: typeof lib_plankton.list.groups; + const find: typeof lib_plankton.list.find; + const has: typeof lib_plankton.list.has; + const contains: typeof lib_plankton.list.contains; + const max: typeof lib_plankton.list.max; + const min: typeof lib_plankton.list.min; + const maxarg: typeof lib_plankton.list.maxarg; + const minarg: typeof lib_plankton.list.minarg; + const distribute: typeof lib_plankton.list.distribute; + const lex: typeof lib_plankton.list.lex; + const lex_lt: typeof lib_plankton.list.lex_lt; + const lex_gt: typeof lib_plankton.list.lex_gt; + const lex_le: typeof lib_plankton.list.lex_le; + const lex_ge: typeof lib_plankton.list.lex_ge; + const lex_eq: typeof lib_plankton.list.lex_eq; + const lex_ne: typeof lib_plankton.list.lex_ne; + const filter_inplace: typeof lib_plankton.list.filter_inplace; +} declare namespace lib_plankton.file { /** * @author fenris @@ -722,12 +923,6 @@ declare namespace lib_plankton.file { */ function delete_(path: string): Promise; } -declare namespace lib_plankton.sha256 { - /** - * @author fenris - */ - function get(value: string, secret?: string): string; -} declare namespace lib_plankton.log { /** */ @@ -1046,746 +1241,6 @@ declare var printf: typeof lib_plankton.string.printf; declare var eml_log: any; declare var track_exports: any; declare var make_logger: (prefix: any, current_loglevel: any) => (obj: any, lvl: any) => void; -declare namespace lib_plankton.database { - /** - */ - type type_query = { - template: string; - arguments: Record; - }; - /** - */ - enum enum_type { - boolean = "boolean", - integer = "integer", - string_short = "string_short", - string_medium = "string_medium", - string_long = "string_long", - float = "float" - } - /** - */ - type type_description_create_table = { - name: string; - key_field?: (null | { - name: string; - type?: enum_type; - comment?: (null | string); - auto_increment?: (null | boolean); - description?: (null | string); - }); - data_fields?: Array<{ - name: string; - nullable?: boolean; - type: enum_type; - default?: any; - description?: (null | string); - }>; - constraints?: Array<{ - kind: string; - parameters?: Record; - }>; - description?: (null | string); - }; - /** - */ - type type_description_insert = { - table_name: string; - values: Record; - }; - /** - */ - type type_description_update = { - table_name: string; - values: Record; - condition?: (null | string); - arguments?: (null | Record); - }; - /** - */ - type type_description_delete = { - table_name: string; - condition?: (null | string); - arguments?: (null | Record); - }; - /** - */ - type type_description_select = { - source: string; - fields?: (null | Array); - condition?: (null | string); - group_by?: (null | string); - having?: (null | string); - order_by?: (null | string); - limit?: (null | int); - arguments?: (null | Record); - }; - /** - * rows - */ - type type_result_get = Array>; - /** - * auto insert id - */ - type type_result_put = (null | int); - /** - * number of affected rows - */ - type type_result_set = int; - /** - * @author fenris - */ - type type_database = { - query_free_get: ((query: type_query) => Promise); - query_free_put: ((query: type_query) => Promise); - query_free_set: ((query: type_query) => Promise); - query_create_table: ((description_create_table: type_description_create_table) => Promise); - query_insert: ((description_insert: type_description_insert) => Promise); - query_update: ((description_update: type_description_update) => Promise); - query_delete: ((description_delete: type_description_delete) => Promise); - query_select: ((description_select: type_description_select) => Promise); - }; - /** - */ - type interface_database = database.type_database; -} -declare namespace lib_plankton.database { - /** - * @todo default case? - */ - function sql_common_value_format(value: any): string; - /** - */ - function sql_common_formulation_create_table(description_create_table: type_description_create_table, options?: { - auto_increment_keyword?: string; - omit_comments?: boolean; - type_map?: Record; - wrap_names?: boolean; - }): type_query; - /** - */ - function sql_common_formulation_insert(description_insert: type_description_insert, options?: { - wrap_names?: boolean; - }): type_query; - /** - */ - function sql_common_formulation_update(description_update: type_description_update, options?: { - wrap_names?: boolean; - }): type_query; - /** - */ - function sql_common_formulation_delete(description_delete: type_description_delete, options?: { - wrap_names?: boolean; - }): type_query; - /** - */ - function sql_common_formulation_select(description_select: type_description_select, options?: { - wrap_names?: boolean; - }): type_query; -} -declare namespace lib_plankton.database { - /** - */ - type type_sqlite_subject = { - path: string; - handle: any; - }; - /** - */ - type type_sqlite_parameters = { - path: string; - }; - /** - */ - function sqlite_make(parameters: type_sqlite_parameters): type_sqlite_subject; - /** - * @author fenris - */ - function sqlite_query_free_get(subject: type_sqlite_subject, query: type_query): Promise; - /** - * @author fenris - */ - function sqlite_query_free_put(subject: type_sqlite_subject, query: type_query): Promise; - /** - * @author fenris - */ - function sqlite_query_free_set(subject: type_sqlite_subject, query: type_query): Promise; - /** - */ - function sqlite_formulation_create_table(description_create_table: type_description_create_table): type_query; - /** - */ - function sqlite_query_create_table(subject: type_sqlite_subject, description: type_description_create_table): Promise; - /** - */ - function sqlite_formulation_insert(description_insert: type_description_insert): type_query; - /** - */ - function sqlite_query_insert(subject: type_sqlite_subject, description_insert: type_description_insert): Promise; - /** - */ - function sqlite_formulation_update(description_update: type_description_update): type_query; - /** - */ - function sqlite_query_update(subject: type_sqlite_subject, description_update: type_description_update): Promise; - /** - */ - function sqlite_formulation_delete(description_delete: type_description_delete): type_query; - /** - */ - function sqlite_query_delete(subject: type_sqlite_subject, description_delete: type_description_delete): Promise; - /** - */ - function sqlite_formulation_select(description_select: type_description_select): type_query; - /** - */ - function sqlite_query_select(subject: type_sqlite_subject, description_select: type_description_select): Promise>>; - /** - */ - function sqlite_database(parameters: type_sqlite_parameters): type_database; -} -declare namespace lib_plankton.database { - /** - * @author fenris - */ - class class_sqlite implements interface_database { - private subject; - constructor(parameters: type_sqlite_parameters); - query_free_get(query: any): Promise; - query_free_put(query: any): Promise; - query_free_set(query: any): Promise; - query_create_table(description_create_table: any): Promise; - query_insert(description_insert: any): Promise; - query_update(description_update: any): Promise; - query_delete(description_delete: any): Promise; - query_select(description_select: any): Promise[]>; - } -} -declare namespace lib_plankton.database { - /** - * @todo - */ - type type_postgresql_subject = { - host: string; - port: int; - username: string; - password: string; - schema: string; - client: any; - }; - /** - * @todo - */ - type type_postgresql_parameters = { - host: string; - port?: int; - username: string; - password: string; - schema: string; - }; - /** - * @see https://node-postgres.com/apis/client#new-client - */ - function postgresql_make(parameters: type_postgresql_parameters): type_postgresql_subject; - /** - * @author fenris - * @see https://node-postgres.com/apis/client#clientquery - */ - function postgresql_query_free_get(subject: type_postgresql_subject, query: type_query): Promise; - /** - * @author fenris - * @see https://node-postgres.com/apis/client#clientquery - */ - function postgresql_query_free_put(subject: type_postgresql_subject, query: type_query): Promise; - /** - * @author fenris - * @see https://node-postgres.com/apis/client#clientquery - */ - function postgresql_query_free_set(subject: type_postgresql_subject, query: type_query): Promise; - /** - */ - function postgresql_formulation_create_table(description_create_table: type_description_create_table): type_query; - /** - */ - function postgresql_query_create_table(subject: type_postgresql_subject, description: type_description_create_table): Promise; - /** - */ - function postgresql_formulation_insert(description_insert: type_description_insert): type_query; - /** - */ - function postgresql_query_insert(subject: type_postgresql_subject, description_insert: type_description_insert): Promise; - /** - */ - function postgresql_formulation_update(description_update: type_description_update): type_query; - /** - */ - function postgresql_query_update(subject: type_postgresql_subject, description_update: type_description_update): Promise; - /** - */ - function postgresql_formulation_delete(description_delete: type_description_delete): type_query; - /** - */ - function postgresql_query_delete(subject: type_postgresql_subject, description_delete: type_description_delete): Promise; - /** - */ - function postgresql_formulation_select(description_select: type_description_select): type_query; - /** - */ - function postgresql_query_select(subject: type_postgresql_subject, description_select: type_description_select): Promise>>; - /** - */ - function postgresql_database(parameters: type_postgresql_parameters): type_database; -} -declare namespace lib_plankton.database { - /** - * @author fenris - */ - class class_postgresql implements interface_database { - private subject; - constructor(parameters: type_postgresql_parameters); - query_free_get(query: any): Promise; - query_free_put(query: any): Promise; - query_free_set(query: any): Promise; - query_create_table(description_create_table: any): Promise; - query_insert(description_insert: any): Promise; - query_update(description_update: any): Promise; - query_delete(description_delete: any): Promise; - query_select(description_select: any): Promise[]>; - } -} -declare namespace lib_plankton.database { - /** - * @todo - */ - type type_mysql_subject = { - verbose: boolean; - }; - /** - * @todo - */ - type type_mysql_parameters = { - verbose?: boolean; - }; - /** - */ - function mysql_make(parameters: type_mysql_parameters): type_mysql_subject; - /** - * @author fenris - */ - function mysql_query_free_get(subject: type_mysql_subject, query: type_query): Promise; - /** - * @author fenris - */ - function mysql_query_free_put(subject: type_mysql_subject, query: type_query): Promise; - /** - * @author fenris - */ - function mysql_query_free_set(subject: type_mysql_subject, query: type_query): Promise; - /** - */ - function mysql_formulation_create_table(description_create_table: type_description_create_table): type_query; - /** - */ - function mysql_query_create_table(subject: type_mysql_subject, description: type_description_create_table): Promise; - /** - */ - function mysql_formulation_insert(description_insert: type_description_insert): type_query; - /** - */ - function mysql_query_insert(subject: type_mysql_subject, description_insert: type_description_insert): Promise; - /** - */ - function mysql_formulation_update(description_update: type_description_update): type_query; - /** - */ - function mysql_query_update(subject: type_mysql_subject, description_update: type_description_update): Promise; - /** - */ - function mysql_formulation_delete(description_delete: type_description_delete): type_query; - /** - */ - function mysql_query_delete(subject: type_mysql_subject, description_delete: type_description_delete): Promise; - /** - */ - function mysql_formulation_select(description_select: type_description_select): type_query; - /** - */ - function mysql_query_select(subject: type_mysql_subject, description_select: type_description_select): Promise>>; - /** - */ - function mysql_database(parameters: type_mysql_parameters): type_database; -} -declare namespace lib_plankton.database { - /** - * @author fenris - */ - class class_mysql implements interface_database { - private subject; - constructor(parameters: type_mysql_parameters); - query_free_get(query: any): Promise; - query_free_put(query: any): Promise; - query_free_set(query: any): Promise; - query_create_table(description_create_table: any): Promise; - query_insert(description_insert: any): Promise; - query_update(description_update: any): Promise; - query_delete(description_delete: any): Promise; - query_select(description_select: any): Promise[]>; - } -} -declare namespace lib_plankton.storage { - /** - * implements the idea of a database, which houses datasets (type_value) and manages their access by ids or sth. similar (type_key) - * - * @author fenris - */ - type type_store = { - /** - * shall prepare the storage instance for use - * - * @author fenris - */ - setup(input: type_setup_input): Promise; - /** - * shall insert a new dataset and return its automatically assign key - * - * @author fenris - */ - create(value: type_value): Promise; - /** - * shall modify an existing dataset - * - * @author fenris - */ - update(key: type_key, value: type_value): Promise; - /** - * shall remove an existing dataset - * - * @author fenris - */ - delete(key: type_key): Promise; - /** - * shall get an existing dataset by its key - * - * @author fenris - */ - read(key: type_key): Promise; - /** - * shall list keys and previews of existing datasets, which match a certain search term - * - * @author fenris - */ - search(term?: (null | type_searchterm)): Promise>; - }; - /** - * for class wrappers - */ - type interface_store = type_store; -} -declare namespace lib_plankton.storage { - /** - * implements the idea of a storage without managed keys - * - * @author fenris - */ - type type_chest = { - /** - * shall prepare the storage instance for use - * - * @author fenris - */ - setup(input: type_setup_input): Promise; - /** - * shall remove all items - */ - clear(): Promise; - /** - * shall insert a new or modify an existing dataset and return whether it is new - * - * @author fenris - */ - write(key: type_key, value: type_value): Promise; - /** - * shall remove an existing dataset - * - * @author fenris - */ - delete(key: type_key): Promise; - /** - * shall get an existing dataset by its key - * - * @author fenris - */ - read(key: type_key): Promise; - /** - * shall list keys and previews of existing datasets, which match a certain search term - * - * @author fenris - */ - search(term?: (null | type_searchterm)): Promise>; - }; - /** - * for class wrappers - */ - type interface_chest = type_chest; -} -declare namespace lib_plankton.storage.memory { - /** - * @author fenris - */ - type type_subject = { - data: Record; - }; - /** - */ - type type_parameters = {}; - /** - * @author fenris - */ - function make(parameters: type_parameters): type_subject; - /** - * @author fenris - */ - function clear(subject: type_subject): void; - /** - * @author fenris - */ - function write(subject: type_subject, key: string, value: type_value): boolean; - /** - * @author fenris - */ - function delete_(subject: type_subject, key: string): void; - /** - * @author fenris - */ - function read(subject: type_subject, key: string): type_value; - /** - * @author fenris - */ - function list(subject: type_subject): Array; - /** - * @author fenris - */ - function search(subject: type_subject, term: (null | string)): Array<{ - key: string; - preview: string; - }>; - /** - * @author fenris - */ - function implementation_chest(parameters: type_parameters): type_chest; -} -declare namespace lib_plankton.storage.memory { - /** - * @author fenris - */ - class class_chest implements type_chest { - private subject; - constructor(parameters: type_parameters); - setup(input: any): Promise; - clear(): Promise; - write(key: any, value: any): Promise; - delete(key: any): Promise; - read(key: any): Promise>; - search(term: any): Promise<{ - key: string; - preview: string; - }[]>; - } -} -declare namespace lib_plankton.storage.filesystem { - /** - * @author fenris - */ - type type_subject = { - nodemodule: any; - }; - /** - */ - type type_parameters = {}; - /** - * @author fenris - */ - function make(parameters: type_parameters): type_subject; - /** - */ - function clear(subject: type_subject): Promise; - /** - * @author fenris - */ - function write(subject: type_subject, path: string, content: Buffer): Promise; - /** - * @author fenris - */ - function delete_(subject: type_subject, path: string): Promise; - /** - * @author fenris - */ - function read(subject: type_subject, path: string): Promise; - /** - */ - function implementation_chest(parameters: type_parameters): type_chest; -} -declare namespace lib_plankton.storage.filesystem { - /** - * @author fenris - */ - class class_chest implements type_chest { - private subject; - constructor(parameters: type_parameters); - setup(input: any): Promise; - clear(): Promise; - write(key: any, value: any): Promise; - delete(key: any): Promise; - read(key: any): Promise; - search(searchterm: any): Promise<{ - key: string; - preview: void; - }[]>; - } -} -declare namespace lib_plankton.storage { - /** - */ - type type_sql_table_autokey_search_term = { - expression: string; - arguments: Record; - }; - /** - */ - type type_sql_table_autokey_subject = { - database_implementation: lib_plankton.database.type_database; - table_name: string; - key_name: string; - }; - /** - */ - type type_sql_table_autokey_parameters = { - database_implementation: lib_plankton.database.type_database; - table_name: string; - key_name: string; - }; - /** - */ - function sql_table_autokey_make(parameters: type_sql_table_autokey_parameters): type_sql_table_autokey_subject; - /** - */ - function sql_table_autokey_setup(subject: type_sql_table_autokey_subject, description_create_table: lib_plankton.database.type_description_create_table): Promise; - /** - */ - function sql_table_autokey_create(subject: type_sql_table_autokey_subject, value: Record): Promise; - /** - */ - function sql_table_autokey_update(subject: type_sql_table_autokey_subject, key: int, value: Record): Promise; - /** - */ - function sql_table_autokey_delete(subject: type_sql_table_autokey_subject, key: int): Promise; - /** - */ - function sql_table_autokey_read(subject: type_sql_table_autokey_subject, key: int): Promise>; - /** - * @todo correct preview - */ - function sql_table_autokey_search(subject: type_sql_table_autokey_subject, term: (null | type_sql_table_autokey_search_term)): Promise; - }>>; - /** - */ - function sql_table_autokey_store(parameters: type_sql_table_autokey_parameters): type_store, lib_plankton.database.type_description_create_table, type_sql_table_autokey_search_term, Record>; -} -declare namespace lib_plankton.storage { - /** - * @author fenris - */ - class class_sql_table_autokey implements type_store, lib_plankton.database.type_description_create_table, string, Record> { - private subject; - constructor(parameters: type_sql_table_autokey_parameters); - setup(input: any): Promise; - create(value: any): Promise; - update(key: any, value: any): Promise; - delete(key: any): Promise; - read(key: any): Promise>; - search(term: any): Promise<{ - key: number; - preview: Record; - }[]>; - } -} -declare namespace lib_plankton.storage.sql_table_common { - /** - */ - type type_sql_table_common_search_term = { - expression: string; - arguments: Record; - }; - /** - */ - type type_subject = { - database_implementation: lib_plankton.database.type_database; - table_name: string; - key_names: Array; - }; - /** - */ - type type_parameters = { - database_implementation: lib_plankton.database.type_database; - table_name: string; - key_names: Array; - }; - /** - */ - function make(parameters: type_parameters): type_subject; - /** - */ - function setup(subject: type_subject, description_create_table: lib_plankton.database.type_description_create_table): Promise; - /** - */ - function clear(subject: type_subject): Promise; - /** - * @todo optimize: avoid read - */ - function write(subject: type_subject, key: Array, value: Record): Promise; - /** - */ - function delete_(subject: type_subject, key: Array): Promise; - /** - */ - function read(subject: type_subject, key: Array): Promise>; - /** - * @todo correct preview - */ - function search(subject: type_subject, term: (null | type_sql_table_common_search_term)): Promise; - preview: Record; - }>>; - /** - */ - function chest(parameters: type_parameters): type_chest, Record, lib_plankton.database.type_description_create_table, type_sql_table_common_search_term, Record>; -} -declare namespace lib_plankton.storage.sql_table_common { - /** - * @author fenris - */ - class class_chest implements type_chest, Record, lib_plankton.database.type_description_create_table, type_sql_table_common_search_term, Record> { - private subject; - constructor(parameters: type_parameters); - setup(input: any): Promise; - clear(): Promise; - write(key: any, value: any): Promise; - delete(key: any): Promise; - read(key: any): Promise>; - search(term: any): Promise<{ - key: any[]; - preview: Record; - }[]>; - } -} declare namespace lib_plankton.shape { /** * @todo @@ -2441,6 +1896,752 @@ declare namespace lib_plankton.random { * @author fenris */ } +declare namespace lib_plankton.sha256 { + /** + * @author fenris + */ + function get(value: string, secret?: string): string; +} +declare namespace lib_plankton.database { + /** + */ + type type_query = { + template: string; + arguments: Record; + }; + /** + */ + enum enum_type { + boolean = "boolean", + integer = "integer", + string_short = "string_short", + string_medium = "string_medium", + string_long = "string_long", + float = "float" + } + /** + */ + type type_description_create_table = { + name: string; + key_field?: (null | { + name: string; + type?: enum_type; + comment?: (null | string); + auto_increment?: (null | boolean); + description?: (null | string); + }); + data_fields?: Array<{ + name: string; + nullable?: boolean; + type: enum_type; + default?: any; + description?: (null | string); + }>; + constraints?: Array<{ + kind: string; + parameters?: Record; + }>; + description?: (null | string); + }; + /** + */ + type type_description_insert = { + table_name: string; + values: Record; + }; + /** + */ + type type_description_update = { + table_name: string; + values: Record; + condition?: (null | string); + arguments?: (null | Record); + }; + /** + */ + type type_description_delete = { + table_name: string; + condition?: (null | string); + arguments?: (null | Record); + }; + /** + */ + type type_description_select = { + source: string; + fields?: (null | Array); + condition?: (null | string); + group_by?: (null | string); + having?: (null | string); + order_by?: (null | string); + limit?: (null | int); + arguments?: (null | Record); + }; + /** + * rows + */ + type type_result_get = Array>; + /** + * auto insert id + */ + type type_result_put = (null | int); + /** + * number of affected rows + */ + type type_result_set = int; + /** + * @author fenris + */ + type type_database = { + query_free_get: ((query: type_query) => Promise); + query_free_put: ((query: type_query) => Promise); + query_free_set: ((query: type_query) => Promise); + query_create_table: ((description_create_table: type_description_create_table) => Promise); + query_insert: ((description_insert: type_description_insert) => Promise); + query_update: ((description_update: type_description_update) => Promise); + query_delete: ((description_delete: type_description_delete) => Promise); + query_select: ((description_select: type_description_select) => Promise); + }; + /** + */ + type interface_database = database.type_database; +} +declare namespace lib_plankton.database { + /** + * @todo default case? + */ + function sql_common_value_format(value: any): string; + /** + */ + function sql_common_formulation_create_table(description_create_table: type_description_create_table, options?: { + auto_increment_keyword?: string; + omit_comments?: boolean; + type_map?: Record; + wrap_names?: boolean; + }): type_query; + /** + */ + function sql_common_formulation_insert(description_insert: type_description_insert, options?: { + wrap_names?: boolean; + }): type_query; + /** + */ + function sql_common_formulation_update(description_update: type_description_update, options?: { + wrap_names?: boolean; + }): type_query; + /** + */ + function sql_common_formulation_delete(description_delete: type_description_delete, options?: { + wrap_names?: boolean; + }): type_query; + /** + */ + function sql_common_formulation_select(description_select: type_description_select, options?: { + wrap_names?: boolean; + }): type_query; +} +declare namespace lib_plankton.database { + /** + */ + type type_sqlite_subject = { + path: string; + handle: any; + }; + /** + */ + type type_sqlite_parameters = { + path: string; + }; + /** + */ + function sqlite_make(parameters: type_sqlite_parameters): type_sqlite_subject; + /** + * @author fenris + */ + function sqlite_query_free_get(subject: type_sqlite_subject, query: type_query): Promise; + /** + * @author fenris + */ + function sqlite_query_free_put(subject: type_sqlite_subject, query: type_query): Promise; + /** + * @author fenris + */ + function sqlite_query_free_set(subject: type_sqlite_subject, query: type_query): Promise; + /** + */ + function sqlite_formulation_create_table(description_create_table: type_description_create_table): type_query; + /** + */ + function sqlite_query_create_table(subject: type_sqlite_subject, description: type_description_create_table): Promise; + /** + */ + function sqlite_formulation_insert(description_insert: type_description_insert): type_query; + /** + */ + function sqlite_query_insert(subject: type_sqlite_subject, description_insert: type_description_insert): Promise; + /** + */ + function sqlite_formulation_update(description_update: type_description_update): type_query; + /** + */ + function sqlite_query_update(subject: type_sqlite_subject, description_update: type_description_update): Promise; + /** + */ + function sqlite_formulation_delete(description_delete: type_description_delete): type_query; + /** + */ + function sqlite_query_delete(subject: type_sqlite_subject, description_delete: type_description_delete): Promise; + /** + */ + function sqlite_formulation_select(description_select: type_description_select): type_query; + /** + */ + function sqlite_query_select(subject: type_sqlite_subject, description_select: type_description_select): Promise>>; + /** + */ + function sqlite_database(parameters: type_sqlite_parameters): type_database; +} +declare namespace lib_plankton.database { + /** + * @author fenris + */ + class class_sqlite implements interface_database { + private subject; + constructor(parameters: type_sqlite_parameters); + query_free_get(query: any): Promise; + query_free_put(query: any): Promise; + query_free_set(query: any): Promise; + query_create_table(description_create_table: any): Promise; + query_insert(description_insert: any): Promise; + query_update(description_update: any): Promise; + query_delete(description_delete: any): Promise; + query_select(description_select: any): Promise[]>; + } +} +declare namespace lib_plankton.database { + /** + * @todo + */ + type type_postgresql_subject = { + host: string; + port: int; + username: string; + password: string; + schema: string; + client: any; + }; + /** + * @todo + */ + type type_postgresql_parameters = { + host: string; + port?: int; + username: string; + password: string; + schema: string; + }; + /** + * @see https://node-postgres.com/apis/client#new-client + */ + function postgresql_make(parameters: type_postgresql_parameters): type_postgresql_subject; + /** + * @author fenris + * @see https://node-postgres.com/apis/client#clientquery + */ + function postgresql_query_free_get(subject: type_postgresql_subject, query: type_query): Promise; + /** + * @author fenris + * @see https://node-postgres.com/apis/client#clientquery + */ + function postgresql_query_free_put(subject: type_postgresql_subject, query: type_query): Promise; + /** + * @author fenris + * @see https://node-postgres.com/apis/client#clientquery + */ + function postgresql_query_free_set(subject: type_postgresql_subject, query: type_query): Promise; + /** + */ + function postgresql_formulation_create_table(description_create_table: type_description_create_table): type_query; + /** + */ + function postgresql_query_create_table(subject: type_postgresql_subject, description: type_description_create_table): Promise; + /** + */ + function postgresql_formulation_insert(description_insert: type_description_insert): type_query; + /** + */ + function postgresql_query_insert(subject: type_postgresql_subject, description_insert: type_description_insert): Promise; + /** + */ + function postgresql_formulation_update(description_update: type_description_update): type_query; + /** + */ + function postgresql_query_update(subject: type_postgresql_subject, description_update: type_description_update): Promise; + /** + */ + function postgresql_formulation_delete(description_delete: type_description_delete): type_query; + /** + */ + function postgresql_query_delete(subject: type_postgresql_subject, description_delete: type_description_delete): Promise; + /** + */ + function postgresql_formulation_select(description_select: type_description_select): type_query; + /** + */ + function postgresql_query_select(subject: type_postgresql_subject, description_select: type_description_select): Promise>>; + /** + */ + function postgresql_database(parameters: type_postgresql_parameters): type_database; +} +declare namespace lib_plankton.database { + /** + * @author fenris + */ + class class_postgresql implements interface_database { + private subject; + constructor(parameters: type_postgresql_parameters); + query_free_get(query: any): Promise; + query_free_put(query: any): Promise; + query_free_set(query: any): Promise; + query_create_table(description_create_table: any): Promise; + query_insert(description_insert: any): Promise; + query_update(description_update: any): Promise; + query_delete(description_delete: any): Promise; + query_select(description_select: any): Promise[]>; + } +} +declare namespace lib_plankton.database { + /** + * @todo + */ + type type_mysql_subject = { + verbose: boolean; + }; + /** + * @todo + */ + type type_mysql_parameters = { + verbose?: boolean; + }; + /** + */ + function mysql_make(parameters: type_mysql_parameters): type_mysql_subject; + /** + * @author fenris + */ + function mysql_query_free_get(subject: type_mysql_subject, query: type_query): Promise; + /** + * @author fenris + */ + function mysql_query_free_put(subject: type_mysql_subject, query: type_query): Promise; + /** + * @author fenris + */ + function mysql_query_free_set(subject: type_mysql_subject, query: type_query): Promise; + /** + */ + function mysql_formulation_create_table(description_create_table: type_description_create_table): type_query; + /** + */ + function mysql_query_create_table(subject: type_mysql_subject, description: type_description_create_table): Promise; + /** + */ + function mysql_formulation_insert(description_insert: type_description_insert): type_query; + /** + */ + function mysql_query_insert(subject: type_mysql_subject, description_insert: type_description_insert): Promise; + /** + */ + function mysql_formulation_update(description_update: type_description_update): type_query; + /** + */ + function mysql_query_update(subject: type_mysql_subject, description_update: type_description_update): Promise; + /** + */ + function mysql_formulation_delete(description_delete: type_description_delete): type_query; + /** + */ + function mysql_query_delete(subject: type_mysql_subject, description_delete: type_description_delete): Promise; + /** + */ + function mysql_formulation_select(description_select: type_description_select): type_query; + /** + */ + function mysql_query_select(subject: type_mysql_subject, description_select: type_description_select): Promise>>; + /** + */ + function mysql_database(parameters: type_mysql_parameters): type_database; +} +declare namespace lib_plankton.database { + /** + * @author fenris + */ + class class_mysql implements interface_database { + private subject; + constructor(parameters: type_mysql_parameters); + query_free_get(query: any): Promise; + query_free_put(query: any): Promise; + query_free_set(query: any): Promise; + query_create_table(description_create_table: any): Promise; + query_insert(description_insert: any): Promise; + query_update(description_update: any): Promise; + query_delete(description_delete: any): Promise; + query_select(description_select: any): Promise[]>; + } +} +declare namespace lib_plankton.storage { + /** + * implements the idea of a database, which houses datasets (type_value) and manages their access by ids or sth. similar (type_key) + * + * @author fenris + */ + type type_store = { + /** + * shall prepare the storage instance for use + * + * @author fenris + */ + setup(input: type_setup_input): Promise; + /** + * shall insert a new dataset and return its automatically assign key + * + * @author fenris + */ + create(value: type_value): Promise; + /** + * shall modify an existing dataset + * + * @author fenris + */ + update(key: type_key, value: type_value): Promise; + /** + * shall remove an existing dataset + * + * @author fenris + */ + delete(key: type_key): Promise; + /** + * shall get an existing dataset by its key + * + * @author fenris + */ + read(key: type_key): Promise; + /** + * shall list keys and previews of existing datasets, which match a certain search term + * + * @author fenris + */ + search(term?: (null | type_searchterm)): Promise>; + }; + /** + * for class wrappers + */ + type interface_store = type_store; +} +declare namespace lib_plankton.storage { + /** + * implements the idea of a storage without managed keys + * + * @author fenris + */ + type type_chest = { + /** + * shall prepare the storage instance for use + * + * @author fenris + */ + setup(input: type_setup_input): Promise; + /** + * shall remove all items + */ + clear(): Promise; + /** + * shall insert a new or modify an existing dataset and return whether it is new + * + * @author fenris + */ + write(key: type_key, value: type_value): Promise; + /** + * shall remove an existing dataset + * + * @author fenris + */ + delete(key: type_key): Promise; + /** + * shall get an existing dataset by its key + * + * @author fenris + */ + read(key: type_key): Promise; + /** + * shall list keys and previews of existing datasets, which match a certain search term + * + * @author fenris + */ + search(term?: (null | type_searchterm)): Promise>; + }; + /** + * for class wrappers + */ + type interface_chest = type_chest; +} +declare namespace lib_plankton.storage.memory { + /** + * @author fenris + */ + type type_subject = { + data: Record; + }; + /** + */ + type type_parameters = {}; + /** + * @author fenris + */ + function make(parameters: type_parameters): type_subject; + /** + * @author fenris + */ + function clear(subject: type_subject): void; + /** + * @author fenris + */ + function write(subject: type_subject, key: string, value: type_value): boolean; + /** + * @author fenris + */ + function delete_(subject: type_subject, key: string): void; + /** + * @author fenris + */ + function read(subject: type_subject, key: string): type_value; + /** + * @author fenris + */ + function list(subject: type_subject): Array; + /** + * @author fenris + */ + function search(subject: type_subject, term: (null | string)): Array<{ + key: string; + preview: string; + }>; + /** + * @author fenris + */ + function implementation_chest(parameters: type_parameters): type_chest; +} +declare namespace lib_plankton.storage.memory { + /** + * @author fenris + */ + class class_chest implements type_chest { + private subject; + constructor(parameters: type_parameters); + setup(input: any): Promise; + clear(): Promise; + write(key: any, value: any): Promise; + delete(key: any): Promise; + read(key: any): Promise; + search(term: any): Promise<{ + key: string; + preview: string; + }[]>; + } +} +declare namespace lib_plankton.storage.filesystem { + /** + * @author fenris + */ + type type_subject = { + nodemodule: any; + }; + /** + */ + type type_parameters = {}; + /** + * @author fenris + */ + function make(parameters: type_parameters): type_subject; + /** + */ + function clear(subject: type_subject): Promise; + /** + * @author fenris + */ + function write(subject: type_subject, path: string, content: Buffer): Promise; + /** + * @author fenris + */ + function delete_(subject: type_subject, path: string): Promise; + /** + * @author fenris + */ + function read(subject: type_subject, path: string): Promise; + /** + */ + function implementation_chest(parameters: type_parameters): type_chest; +} +declare namespace lib_plankton.storage.filesystem { + /** + * @author fenris + */ + class class_chest implements type_chest { + private subject; + constructor(parameters: type_parameters); + setup(input: any): Promise; + clear(): Promise; + write(key: any, value: any): Promise; + delete(key: any): Promise; + read(key: any): Promise; + search(searchterm: any): Promise<{ + key: string; + preview: void; + }[]>; + } +} +declare namespace lib_plankton.storage { + /** + */ + type type_sql_table_autokey_search_term = { + expression: string; + arguments: Record; + }; + /** + */ + type type_sql_table_autokey_subject = { + database_implementation: lib_plankton.database.type_database; + table_name: string; + key_name: string; + }; + /** + */ + type type_sql_table_autokey_parameters = { + database_implementation: lib_plankton.database.type_database; + table_name: string; + key_name: string; + }; + /** + */ + function sql_table_autokey_make(parameters: type_sql_table_autokey_parameters): type_sql_table_autokey_subject; + /** + */ + function sql_table_autokey_setup(subject: type_sql_table_autokey_subject, description_create_table: lib_plankton.database.type_description_create_table): Promise; + /** + */ + function sql_table_autokey_create(subject: type_sql_table_autokey_subject, value: Record): Promise; + /** + */ + function sql_table_autokey_update(subject: type_sql_table_autokey_subject, key: int, value: Record): Promise; + /** + */ + function sql_table_autokey_delete(subject: type_sql_table_autokey_subject, key: int): Promise; + /** + */ + function sql_table_autokey_read(subject: type_sql_table_autokey_subject, key: int): Promise>; + /** + * @todo correct preview + */ + function sql_table_autokey_search(subject: type_sql_table_autokey_subject, term: (null | type_sql_table_autokey_search_term)): Promise; + }>>; + /** + */ + function sql_table_autokey_store(parameters: type_sql_table_autokey_parameters): type_store, lib_plankton.database.type_description_create_table, type_sql_table_autokey_search_term, Record>; +} +declare namespace lib_plankton.storage { + /** + * @author fenris + */ + class class_sql_table_autokey implements type_store, lib_plankton.database.type_description_create_table, string, Record> { + private subject; + constructor(parameters: type_sql_table_autokey_parameters); + setup(input: any): Promise; + create(value: any): Promise; + update(key: any, value: any): Promise; + delete(key: any): Promise; + read(key: any): Promise>; + search(term: any): Promise<{ + key: number; + preview: Record; + }[]>; + } +} +declare namespace lib_plankton.storage.sql_table_common { + /** + */ + type type_sql_table_common_search_term = { + expression: string; + arguments: Record; + }; + /** + */ + type type_subject = { + database_implementation: lib_plankton.database.type_database; + table_name: string; + key_names: Array; + }; + /** + */ + type type_parameters = { + database_implementation: lib_plankton.database.type_database; + table_name: string; + key_names: Array; + }; + /** + */ + function make(parameters: type_parameters): type_subject; + /** + */ + function setup(subject: type_subject, description_create_table: lib_plankton.database.type_description_create_table): Promise; + /** + */ + function clear(subject: type_subject): Promise; + /** + * @todo optimize: avoid read + */ + function write(subject: type_subject, key: Array, value: Record): Promise; + /** + */ + function delete_(subject: type_subject, key: Array): Promise; + /** + */ + function read(subject: type_subject, key: Array): Promise>; + /** + * @todo correct preview + */ + function search(subject: type_subject, term: (null | type_sql_table_common_search_term)): Promise; + preview: Record; + }>>; + /** + */ + function chest(parameters: type_parameters): type_chest, Record, lib_plankton.database.type_description_create_table, type_sql_table_common_search_term, Record>; +} +declare namespace lib_plankton.storage.sql_table_common { + /** + * @author fenris + */ + class class_chest implements type_chest, Record, lib_plankton.database.type_description_create_table, type_sql_table_common_search_term, Record> { + private subject; + constructor(parameters: type_parameters); + setup(input: any): Promise; + clear(): Promise; + write(key: any, value: any): Promise; + delete(key: any): Promise; + read(key: any): Promise>; + search(term: any): Promise<{ + key: any[]; + preview: Record; + }[]>; + } +} declare namespace lib_plankton.session { /** */ diff --git a/lib/plankton/plankton.js b/lib/plankton/plankton.js index b783764..04c766d 100644 --- a/lib/plankton/plankton.js +++ b/lib/plankton/plankton.js @@ -1532,6 +1532,492 @@ var lib_plankton; })(call = lib_plankton.call || (lib_plankton.call = {})); })(lib_plankton || (lib_plankton = {})); /* +This file is part of »bacterio-plankton:list«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:list« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:list« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:list«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var list; + (function (list_1) { + /** + * @desc returns a certain list of integer numbers + * @param {int} from + * @param {int} to + * @param {int} step; default: 1 + * @author fenris + */ + function range(from, to, step) { + if (step === void 0) { step = 1; } + var list = []; + for (var value = from; value <= to; value += step) { + list.push(value); + } + return list; + } + list_1.range = range; + /** + * @desc returns a certain list of integer numbers + * @param {int} length + * @author fenris + */ + function sequence(length) { + return range(0, length - 1); + } + list_1.sequence = sequence; + /** + * @author fenris + */ + function from_structure(structure) { + var list = []; + for (var index = 0; index < structure.length; index += 1) { + list.push(structure[index]); + } + return list; + } + list_1.from_structure = from_structure; + /** + * @author fenris + */ + function from_iterator(iterator /* : Iterator*/) { + var list = []; + for (var _i = 0, iterator_1 = iterator; _i < iterator_1.length; _i++) { + var element = iterator_1[_i]; + list.push(element); + } + return list; + } + list_1.from_iterator = from_iterator; + /** + * @author fenris + */ + function empty(list) { + return (list.length <= 0); + } + list_1.empty = empty; + /** + * @desc creates a list, which contains pairs of elements from the input lists (corresponding by index) + * @param {boolean} [cut] whether the result list will be as long as the shortest input list or an exception is thrown if they have different lengths; default: true + * @author fenris + */ + function zip(list1, list2, cut) { + if (cut === void 0) { cut = true; } + var empty1 = empty(list1); + var empty2 = empty(list2); + if (empty1 || empty2) { + if (cut || (empty1 && empty2)) { + return []; + } + else { + var message = "lists have different lengths"; + throw (new Error(message)); + } + } + else { + return ([{ "first": list1[0], "second": list2[0] }] + .concat(zip(list1.slice(1), list2.slice(1), cut))); + } + } + list_1.zip = zip; + /** + * @desc checks whether two lists are equal + * @todo define common function "equals" and default predicate to + * @author fenris + */ + function equals(list1, list2, collate) { + if (collate === void 0) { collate = instance_collate; } + if (list1.length == list2.length) { + return zip(list1, list2, true).every(function (pair) { return collate(pair.first, pair.second); }); + } + else { + return false; + } + } + list_1.equals = equals; + /** + * @author fenris + */ + function reversed(list) { + var list_ = clone(list); + list_.reverse(); + return list_; + } + list_1.reversed = reversed; + /** + * @author fenris + */ + function sorted(list, order) { + var list_ = clone(list); + list_.sort(order); + return list_; + } + list_1.sorted = sorted; + /** + * @desc creates a list with the elements from the input list, which fulfil a certain predicate + * @author fenris + */ + function keep(list, predicate) { + return list.filter(predicate); + } + list_1.keep = keep; + /** + * @desc creates a list with the elements from the input list, which do not fulfil a certain predicate + * @author fenris + */ + function drop(list, predicate) { + return list.filter(function (element, index) { return (!predicate(element, index)); }); + } + list_1.drop = drop; + /** + * @desc returns a list with no duplicates + * @author fenris + */ + function clean(list, collate) { + if (collate === void 0) { collate = instance_collate; } + var list_ = []; + list.forEach(function (element) { + if (!list_.some(function (element_) { return collate(element, element_); })) { + list_.push(element); + } + }); + return list_; + } + list_1.clean = clean; + /** + * @author fenris + */ + function clone(list) { + return keep(list, function (x) { return true; }); + } + list_1.clone = clone; + function separate(list, predicate) { + return (list.reduce(function (seperation, element) { + return (predicate(element) + ? { "yes": seperation.yes.concat([element]), "no": seperation["no"] } + : { "yes": seperation.yes, "no": seperation["no"].concat([element]) }); + }, { "yes": [], "no": [] })); + } + list_1.separate = separate; + ; + /** + * die Liste in gleich große Blöcke zerlegen + * + * @author fenris + */ + function split(list, chunk_size) { + var chunks = []; + var index = 0; + while (index < list.length) { + var chunk = list.slice(index, Math.min(list.length, index + chunk_size)); + index += chunk_size; + chunks.push(chunk); + } + return chunks; + } + list_1.split = split; + /** + * @author fenris + */ + function group(list, collate) { + if (collate === void 0) { collate = instance_collate; } + var result = []; + list.forEach(function (element) { + var target = find(result, function (group) { return collate(group[0], element); }); + if (target == null) { + target = []; + result.push(target); + } + target.push(element); + }); + return result; + } + list_1.group = group; + /** + * @author fenris + */ + function groups_(list, collate) { + if (collate === void 0) { collate = instance_collate; } + var message = "this function is deprecated; please use 'lib_plankton.list.group' instead (beware: it takes other arguments)"; + console.warn(message); + return group(list, collate); + } + list_1.groups_ = groups_; + /** + * @author fenris + * @deprecated + */ + function groups(list, sorting, hashing) { + var message = "this function is deprecated; please use 'lib_plankton.list.group' instead (beware: it takes other arguments)"; + console.warn(message); + list.sort(sorting); + return (groups_(list, function (x, y) { return (hashing(x) == hashing(y)); })); + } + list_1.groups = groups; + /** + * @desc searches for the first element in a list, that fulfils a given condition + * @author fenris + */ + function find(list, predicate, null_if_not_found) { + if (null_if_not_found === void 0) { null_if_not_found = true; } + var result = null; + var found = list.some(function (element, index) { + if (predicate(element)) { + result = element; + return true; + } + else { + return false; + } + }); + if (found) { + return result; + } + else { + if (null_if_not_found) { + return undefined; + } + else { + throw (new Error("no element in the list fulfils the given predicate")); + } + } + } + list_1.find = find; + /** + * @author fenris + */ + function has(list, predicate) { + try { + find(list, predicate, false); + return true; + } + catch (exception) { + return false; + } + } + list_1.has = has; + /** + * @author fenris + */ + function contains(list, element, collation) { + if (collation === void 0) { collation = instance_collate; } + return has(list, function (element_) { return collation(element_, element); }); + } + list_1.contains = contains; + function max(list, targetfunction, compare) { + if (compare === void 0) { compare = instance_compare; } + if (empty(list)) { + var message = "the max-arg of an empty list is not defined"; + throw (new Error(message)); + } + else { + return (list.reduce(function (result, element, index) { + var value = targetfunction(element); + if ((result == null) || (!compare(value, result.value))) { + return { "index": index, "element": element, "value": value }; + } + else { + return result; + } + }, null)); + } + } + list_1.max = max; + /** + * @desc retrieves the element and its index of the list, which has the mininum value + * @author fenris + */ + function min(list, targetfunction, compare) { + if (compare === void 0) { compare = instance_compare; } + return max(list, targetfunction, function (x, y) { return compare(y, x); }); + } + list_1.min = min; + /** + * @desc retrieves the element of the list, which has the maximum output for a given target-function + * @author fenris + */ + function maxarg(list, targetfunction, compare) { + if (compare === void 0) { compare = instance_compare; } + var message = "this function is deprecated; please use 'lib_plankton.list.max' instead (beware: it has a different output)"; + console.warn(message); + return max(list, targetfunction, compare).element; + } + list_1.maxarg = maxarg; + /** + * @desc retrieves the element of the list, which has the minimum output for a given target-function + * @author fenris + */ + function minarg(list, targetfunction, compare) { + if (compare === void 0) { compare = instance_compare; } + var message = "this function is deprecated; please use 'lib_plankton.list.min' instead (beware: it has a different output)"; + console.warn(message); + return min(list, targetfunction, compare).element; + } + list_1.minarg = minarg; + /** + * @desc implements the idea of arithmetic distribution like in "(a+b)·(c+d) = (a·c)+(a·d)+(b·c)+(b·d)" + * example: distribute([[1,2],[3],[4,5,6]]) = [[1,3,4],[1,3,5],[1,3,6],[2,3,4],[2,3,5],[2,3,6]] + * @author fenris + */ + function distribute(lists) { + if (empty(lists)) { + return [[]]; + } + else { + var subresult_1 = distribute(lists.slice(1)); + return (lists[0] + .map(function (element) { return subresult_1.map(function (list) { return [element].concat(list); }); }) + .reduce(function (x, y) { return x.concat(y); }, [])); + } + } + list_1.distribute = distribute; + /** + * @desc lexicographic order + * @author fenris + * @deprecated + */ + function lex(list1, list2, order) { + if (order === void 0) { order = null; } + console.warn("deprecated!"); + if (order == null) { + order = function (x, y) { + if (x < y) { + return -1; + } + else if (x > y) { + return +1; + } + else /*(x == y)*/ { + return 0; + } + }; + } + if (list1.length <= 0) { + if (list2.length <= 0) { + return 0; + } + else { + return -1; + } + } + else { + if (list2.length <= 0) { + return +1; + } + else { + var result = order(list1[0], list2[0]); + if (result == 0) { + return lex(list1.slice(1), list2.slice(1), order); + } + else { + return result; + } + } + } + } + list_1.lex = lex; + function lex_lt(list1, list2) { + return (lex(list1, list2) < 0); + } + list_1.lex_lt = lex_lt; + ; + function lex_gt(list1, list2) { + return (lex(list1, list2) > 0); + } + list_1.lex_gt = lex_gt; + ; + function lex_le(list1, list2) { + return (lex(list1, list2) <= 0); + } + list_1.lex_le = lex_le; + ; + function lex_ge(list1, list2) { + return (lex(list1, list2) >= 0); + } + list_1.lex_ge = lex_ge; + ; + function lex_eq(list1, list2) { + return (lex(list1, list2) == 0); + } + list_1.lex_eq = lex_eq; + ; + function lex_ne(list1, list2) { + return (lex(list1, list2) != 0); + } + list_1.lex_ne = lex_ne; + ; + /** + * @author fenris + */ + function filter_inplace(list, predicate) { + var index = 0; + while (index < list.length) { + var element = list[index]; + if (predicate(element, index)) { + index += 1; + } + else { + list.splice(index, 1); + } + } + } + list_1.filter_inplace = filter_inplace; + })(list = lib_plankton.list || (lib_plankton.list = {})); +})(lib_plankton || (lib_plankton = {})); +/** + * @deprecated + */ +var lib_list; +(function (lib_list) { + lib_list.range = lib_plankton.list.range; + lib_list.sequence = lib_plankton.list.sequence; + lib_list.from_structure = lib_plankton.list.from_structure; + lib_list.from_iterator = lib_plankton.list.from_iterator; + lib_list.empty = lib_plankton.list.empty; + lib_list.zip = lib_plankton.list.zip; + lib_list.equals = lib_plankton.list.equals; + lib_list.reversed = lib_plankton.list.reversed; + lib_list.sorted = lib_plankton.list.sorted; + lib_list.keep = lib_plankton.list.keep; + lib_list.drop = lib_plankton.list.drop; + lib_list.clean = lib_plankton.list.clean; + lib_list.clone = lib_plankton.list.clone; + lib_list.separate = lib_plankton.list.separate; + lib_list.split = lib_plankton.list.split; + lib_list.group = lib_plankton.list.group; + lib_list.groups_ = lib_plankton.list.groups_; + lib_list.groups = lib_plankton.list.groups; + lib_list.find = lib_plankton.list.find; + lib_list.has = lib_plankton.list.has; + lib_list.contains = lib_plankton.list.contains; + lib_list.max = lib_plankton.list.max; + lib_list.min = lib_plankton.list.min; + lib_list.maxarg = lib_plankton.list.maxarg; + lib_list.minarg = lib_plankton.list.minarg; + lib_list.distribute = lib_plankton.list.distribute; + lib_list.lex = lib_plankton.list.lex; + lib_list.lex_lt = lib_plankton.list.lex_lt; + lib_list.lex_gt = lib_plankton.list.lex_gt; + lib_list.lex_le = lib_plankton.list.lex_le; + lib_list.lex_ge = lib_plankton.list.lex_ge; + lib_list.lex_eq = lib_plankton.list.lex_eq; + lib_list.lex_ne = lib_plankton.list.lex_ne; + lib_list.filter_inplace = lib_plankton.list.filter_inplace; +})(lib_list || (lib_list = {})); +/* This file is part of »bacterio-plankton:file«. Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' @@ -1687,41 +2173,6 @@ var lib_plankton; file.delete_ = delete_; })(file = lib_plankton.file || (lib_plankton.file = {})); })(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:sha256«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:sha256« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:sha256« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:sha256«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var sha256; - (function (sha256) { - /** - * @author fenris - */ - function get(value, secret = "") { - const nm_crypto = require("crypto"); - const sha256Hasher = nm_crypto.createHmac("sha256", secret); - const hash = sha256Hasher.update(value).digest("hex"); - return hash; - } - sha256.get = get; - })(sha256 = lib_plankton.sha256 || (lib_plankton.sha256 = {})); -})(lib_plankton || (lib_plankton = {})); var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || @@ -3237,1991 +3688,6 @@ var make_logger = (function () { } return make_logger; })(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -/* -This file is part of »bacterio-plankton:database«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:database« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:database« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:database«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var database; - (function (database) { - /** - */ - let enum_type; - (function (enum_type) { - enum_type["boolean"] = "boolean"; - enum_type["integer"] = "integer"; - enum_type["string_short"] = "string_short"; - enum_type["string_medium"] = "string_medium"; - enum_type["string_long"] = "string_long"; - enum_type["float"] = "float"; - })(enum_type = database.enum_type || (database.enum_type = {})); - })(database = lib_plankton.database || (lib_plankton.database = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:database«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:database« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:database« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:database«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var database; - (function (database) { - /** - * @todo default case? - */ - function sql_common_value_format(value) { - if (value === undefined) { - throw (new Error("can not format undefined")); - } - else { - if (value === null) { - return "NULL"; - } - else { - switch (typeof (value)) { - case "boolean": { - return (value ? "TRUE" : "FALSE"); - break; - } - case "number": { - return value.toString(); - break; - } - case "string": { - return ("'" + value + "'"); - break; - } - } - } - } - } - 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 = {}) { - var _a, _b, _c, _d, _e; - options = Object.assign({ - "auto_increment_keyword": "AUTO INCREMENT", - "omit_comments": false, - "type_map": { - "boolean": "BOOLEAN", - "integer": "INTEGER", - "string_short": "VARCHAR(63)", - "string_medium": "VARCHAR(255)", - "string_long": "TEXT", - "float": "REAL", - }, - "wrap_names": true, - }, options); - return { - "template": lib_plankton.string.coin("CREATE TABLE\n\t{{name}}(\n{{entries}}\n\t){{comment}}\n;", { - "name": wrap_name(description_create_table.name, { "active": options.wrap_names }), - "comment": ((options.omit_comments - || - (((_a = description_create_table.description) !== null && _a !== void 0 ? _a : null) === null)) - ? "" - : lib_plankton.string.coin(" COMMENT '{{comment}}'", { - "comment": description_create_table.description, - })), - "entries": (([] - // key field - .concat((((_b = description_create_table.key_field) !== null && _b !== void 0 ? _b : null) === null) - ? [] - : lib_plankton.string.coin("{{name}} {{parameters}}", { - "name": wrap_name(description_create_table.key_field.name, { "active": options.wrap_names }), - "parameters": (([] - /* - // type - .concat( - [ - options.type_map[description_create_table.key_field.type ?? "integer"], - ] - ) - */ - // auto increment - .concat((((_c = description_create_table.key_field.auto_increment) !== null && _c !== void 0 ? _c : true) === null) - ? [] - : [ - options.auto_increment_keyword, - ]) - // primary key - .concat([ - "PRIMARY KEY", - ])) - .join(" ")), - })) - // data fields - .concat(((_d = description_create_table.data_fields) !== null && _d !== void 0 ? _d : []) - .map((data_field) => { - var _a, _b; - return lib_plankton.string.coin("{{name}} {{parameters}}", { - "name": wrap_name(data_field.name, { "active": options.wrap_names }), - "parameters": (([] - // type - .concat([ - options.type_map[data_field.type], - ]) - // nullability - .concat((!((_a = data_field.nullable) !== null && _a !== void 0 ? _a : false)) - ? [] - : ["NULL"]) - // default - .concat((!data_field.hasOwnProperty("default")) - ? [] - : [ - lib_plankton.string.coin(" DEFAULT {{value}}", { - "value": sql_common_value_format(data_field.default) - }), - ]) - // comment - .concat((options.omit_comments - || - (((_b = data_field.description) !== null && _b !== void 0 ? _b : null) === null)) - ? [] - : [ - lib_plankton.string.coin("COMMENT '{{comment}}'", { - "comment": data_field.description, - }), - ])) - .join(" ")) - }); - })) - // constraints - .concat(((_e = description_create_table.constraints) !== null && _e !== void 0 ? _e : []) - .map((constraint) => { - switch (constraint.kind) { - default: { - throw (new Error("unhandled constraint kind: " + constraint.kind)); - break; - } - case "foreign_key": { - return lib_plankton.string.coin("FOREIGN KEY ({{fields}}) REFERENCES {{reference_name}}({{reference_fields}})", { - "fields": (constraint.parameters["fields"] - .map(x => wrap_name(x, { "active": options.wrap_names })) - .join(",")), - "reference_name": wrap_name(constraint.parameters["reference"]["name"], { "active": options.wrap_names }), - "reference_fields": (constraint.parameters["reference"]["fields"] - .map(x => wrap_name(x, { "active": options.wrap_names })) - .join(",")), - }); - break; - } - case "unique": { - return lib_plankton.string.coin("UNIQUE ({{fields}})", { - "fields": (constraint.parameters["fields"] - .map(x => wrap_name(x, { "active": options.wrap_names })) - .join(",")), - }); - break; - } - } - }))) - .map(x => ("\t\t" + x)) - .join(",\n")), - }), - "arguments": {} - }; - } - database.sql_common_formulation_create_table = sql_common_formulation_create_table; - /** - */ - function sql_common_formulation_insert(description_insert, options = {}) { - options = Object.assign({ - "wrap_names": true, - }, options); - const field_names = Object.keys(description_insert.values); - return { - "template": lib_plankton.string.coin("INSERT INTO {{table_name}}({{schema}}) VALUES ({{values}});", { - "table_name": wrap_name(description_insert.table_name, { "active": options.wrap_names }), - "schema": (field_names - .map((field_name) => lib_plankton.string.coin("{{name}}", { - "name": wrap_name(field_name, { "active": options.wrap_names }), - })) - .join(",")), - "values": (field_names - .map((field_name) => lib_plankton.string.coin("$value_{{name}}", { - "name": field_name, - })) - .join(",")), - }), - "arguments": Object.fromEntries(Object.entries(description_insert.values) - .map(([name, value]) => ([ - lib_plankton.string.coin("value_{{name}}", { - "name": name, - }), - value - ]))), - }; - } - database.sql_common_formulation_insert = sql_common_formulation_insert; - /** - */ - function sql_common_formulation_update(description_update, options = {}) { - var _a, _b; - options = Object.assign({ - "wrap_names": true, - }, options); - const field_names = Object.keys(description_update.values); - return { - "template": lib_plankton.string.coin("UPDATE {{table_name}} SET {{assignments}}{{macro_where}};", { - "table_name": wrap_name(description_update.table_name, { "active": options.wrap_names }), - "assignments": (field_names - .map((field_name) => lib_plankton.string.coin("{{name}} = $value_{{suffix}}", { - "name": wrap_name(field_name, { "active": options.wrap_names }), - "suffix": field_name, - })) - .join(", ")), - "macro_where": ((((_a = description_update.condition) !== null && _a !== void 0 ? _a : null) === null) - ? "" - : lib_plankton.string.coin(" WHERE {{expression}}", { - "expression": description_update.condition, - })), - }), - "arguments": Object.assign(Object.fromEntries(Object.entries(description_update.values) - .map(([name, value]) => ([ - lib_plankton.string.coin("value_{{name}}", { - "name": name, - }), - value - ]))), ((_b = description_update.arguments) !== null && _b !== void 0 ? _b : {})) - }; - } - database.sql_common_formulation_update = sql_common_formulation_update; - /** - */ - function sql_common_formulation_delete(description_delete, options = {}) { - var _a, _b; - options = Object.assign({ - "wrap_names": true, - }, options); - return { - "template": lib_plankton.string.coin("DELETE FROM {{table_name}}{{macro_where}};", { - "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) - ? "" - : lib_plankton.string.coin(" WHERE {{expression}}", { - "expression": description_delete.condition, - })), - }), - "arguments": Object.assign({}, ((_b = description_delete.arguments) !== null && _b !== void 0 ? _b : {})), - }; - } - database.sql_common_formulation_delete = sql_common_formulation_delete; - /** - */ - function sql_common_formulation_select(description_select, options = {}) { - var _a, _b, _c, _d, _e, _f, _g; - options = Object.assign({ - "wrap_names": true, - }, options); - return { - "template": lib_plankton.string.coin("SELECT {{fields}} FROM {{source}}{{macro_where}}{{macro_group_by}}{{macro_having}}{{macro_order_by}}{{macro_limit}};", { - "source": wrap_name(description_select.source, { "active": options.wrap_names }), - "fields": ((((_a = description_select.fields) !== null && _a !== void 0 ? _a : null) === null) - ? "*" - : (description_select.fields - .map(field_name => lib_plankton.string.coin("{{name}}", { "name": wrap_name(field_name, { "active": options.wrap_names }) })) - .join(","))), - "macro_where": ((((_b = description_select.condition) !== null && _b !== void 0 ? _b : null) === null) - ? "" - : lib_plankton.string.coin(" WHERE {{expression}}", { - "expression": description_select.condition, - })), - "macro_group_by": ((((_c = description_select.group_by) !== null && _c !== void 0 ? _c : null) === null) - ? "" - : lib_plankton.string.coin(" GROUP BY {{expression}}", { - "expression": description_select.group_by, - })), - "macro_having": ((((_d = description_select.having) !== null && _d !== void 0 ? _d : null) === null) - ? "" - : lib_plankton.string.coin(" HAVING {{expression}}", { - "expression": description_select.having, - })), - "macro_order_by": ((((_e = description_select.order_by) !== null && _e !== void 0 ? _e : null) === null) - ? "" - : lib_plankton.string.coin(" ORDER BY {{expression}}", { - "expression": description_select.order_by, - })), - "macro_limit": ((((_f = description_select.limit) !== null && _f !== void 0 ? _f : null) === null) - ? "" - : lib_plankton.string.coin(" LIMIT {{expression}}", { - "expression": description_select.limit.toFixed(0), - })), - }), - "arguments": Object.assign({}, ((_g = description_select.arguments) !== null && _g !== void 0 ? _g : {})), - }; - } - database.sql_common_formulation_select = sql_common_formulation_select; - })(database = lib_plankton.database || (lib_plankton.database = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:database«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:database« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:database« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:database«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var database; - (function (database) { - /** - */ - function sqlite_make(parameters) { - return { - "path": parameters.path, - "handle": null, - }; - } - database.sqlite_make = sqlite_make; - /** - */ - function sqlite_init(subject) { - return __awaiter(this, void 0, void 0, function* () { - if (subject.handle === null) { - yield new Promise((resolve, reject) => { - const _nm_sqlite3 = require("sqlite3"); - subject.handle = new _nm_sqlite3.Database(subject.path, (_nm_sqlite3.OPEN_READWRITE | _nm_sqlite3.OPEN_CREATE | _nm_sqlite3.OPEN_FULLMUTEX), () => { resolve(undefined); }); - }); - } - else { - // do nothing - } - return Promise.resolve(undefined); - }); - } - /** - * @author fenris - */ - function sqlite_adjust_query(subject, query) { - const query_adjusted = { - "template": query.template, - "arguments": Object.fromEntries(Object.entries(query.arguments) - .map(([key, value]) => ([ - ("$" + key), - (((value === null) - || - (value === undefined)) - ? null - : ((typeof (value) === "boolean") - ? (value ? "1" : "0") - : value.toString())) - ]))), - }; - lib_plankton.log.debug("database_sqlite_query", { - "original": query, - "adjusted": query_adjusted, - }); - return query_adjusted; - } - /** - * @author fenris - */ - function sqlite_query_free_get(subject, query) { - return __awaiter(this, void 0, void 0, function* () { - yield sqlite_init(subject); - const query_adjusted = sqlite_adjust_query(subject, query); - return (new Promise((resolve, reject) => { - subject.handle.all(query_adjusted.template, query_adjusted.arguments, (error, rows) => { - if (error !== null) { - reject(error); - } - else { - resolve(rows); - } - }); - })); - }); - } - database.sqlite_query_free_get = sqlite_query_free_get; - /** - * @author fenris - */ - function sqlite_query_free_put(subject, query) { - return __awaiter(this, void 0, void 0, function* () { - yield sqlite_init(subject); - const query_adjusted = sqlite_adjust_query(subject, query); - return (new Promise((resolve, reject) => { - subject.handle.run(query_adjusted.template, query_adjusted.arguments, - // this MUST be an old style function - function (error) { - if (error) { - reject(error); - } - else { - resolve(this["lastID"]); - } - }); - })); - }); - } - database.sqlite_query_free_put = sqlite_query_free_put; - /** - * @author fenris - */ - function sqlite_query_free_set(subject, query) { - return __awaiter(this, void 0, void 0, function* () { - yield sqlite_init(subject); - const query_adjusted = sqlite_adjust_query(subject, query); - return (new Promise((resolve, reject) => { - subject.handle.run(query_adjusted.template, query_adjusted.arguments, - // this MUST be an old style function - function (error) { - if (error) { - reject(error); - } - else { - resolve(this["changes"]); - } - }); - })); - }); - } - database.sqlite_query_free_set = sqlite_query_free_set; - /** - */ - function sqlite_formulation_create_table(description_create_table) { - return database.sql_common_formulation_create_table(description_create_table, { - "auto_increment_keyword": "INTEGER NOT NULL AUTOINCREMENT", - "omit_comments": true, - "type_map": { - "boolean": "INTEGER", - "integer": "INTEGER", - "string_short": "TEXT", - "string_medium": "TEXT", - "string_long": "TEXT", - "float": "REAL", - }, - }); - } - database.sqlite_formulation_create_table = sqlite_formulation_create_table; - /** - */ - function sqlite_query_create_table(subject, description) { - return (sqlite_query_free_set(subject, sqlite_formulation_create_table(description)) - .then(x => Promise.resolve(undefined))); - } - database.sqlite_query_create_table = sqlite_query_create_table; - /** - */ - function sqlite_formulation_insert(description_insert) { - return database.sql_common_formulation_insert(description_insert); - } - database.sqlite_formulation_insert = sqlite_formulation_insert; - /** - */ - function sqlite_query_insert(subject, description_insert) { - return sqlite_query_free_put(subject, sqlite_formulation_insert(description_insert)); - } - database.sqlite_query_insert = sqlite_query_insert; - /** - */ - function sqlite_formulation_update(description_update) { - return database.sql_common_formulation_update(description_update); - } - database.sqlite_formulation_update = sqlite_formulation_update; - /** - */ - function sqlite_query_update(subject, description_update) { - return sqlite_query_free_set(subject, sqlite_formulation_update(description_update)); - } - database.sqlite_query_update = sqlite_query_update; - /** - */ - function sqlite_formulation_delete(description_delete) { - return database.sql_common_formulation_delete(description_delete); - } - database.sqlite_formulation_delete = sqlite_formulation_delete; - /** - */ - function sqlite_query_delete(subject, description_delete) { - return sqlite_query_free_set(subject, sqlite_formulation_delete(description_delete)); - } - database.sqlite_query_delete = sqlite_query_delete; - /** - */ - function sqlite_formulation_select(description_select) { - return database.sql_common_formulation_select(description_select); - } - database.sqlite_formulation_select = sqlite_formulation_select; - /** - */ - function sqlite_query_select(subject, description_select) { - return sqlite_query_free_get(subject, sqlite_formulation_select(description_select)); - } - database.sqlite_query_select = sqlite_query_select; - /** - */ - function sqlite_database(parameters) { - const subject = sqlite_make(parameters); - return { - "query_free_get": (query) => sqlite_query_free_get(subject, query), - "query_free_put": (query) => sqlite_query_free_put(subject, query), - "query_free_set": (query) => sqlite_query_free_set(subject, query), - "query_create_table": (description_create_table) => sqlite_query_create_table(subject, description_create_table), - "query_insert": (description_insert) => sqlite_query_insert(subject, description_insert), - "query_update": (description_update) => sqlite_query_update(subject, description_update), - "query_delete": (description_delete) => sqlite_query_delete(subject, description_delete), - "query_select": (description_select) => sqlite_query_select(subject, description_select), - }; - } - database.sqlite_database = sqlite_database; - })(database = lib_plankton.database || (lib_plankton.database = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:database«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:database« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:database« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:database«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var database; - (function (database) { - /** - * @author fenris - */ - class class_sqlite { - constructor(parameters) { this.subject = database.sqlite_make(parameters); } - 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_set(query) { return database.sqlite_query_free_set(this.subject, query); } - query_create_table(description_create_table) { return database.sqlite_query_create_table(this.subject, description_create_table); } - query_insert(description_insert) { return database.sqlite_query_insert(this.subject, description_insert); } - query_update(description_update) { return database.sqlite_query_update(this.subject, description_update); } - query_delete(description_delete) { return database.sqlite_query_delete(this.subject, description_delete); } - query_select(description_select) { return database.sqlite_query_select(this.subject, description_select); } - } - database.class_sqlite = class_sqlite; - })(database = lib_plankton.database || (lib_plankton.database = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:database«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:database« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:database« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:database«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var database; - (function (database) { - /** - * @see https://node-postgres.com/apis/client#new-client - */ - function postgresql_make(parameters) { - var _a; - return { - "host": parameters.host, - "port": ((_a = parameters.port) !== null && _a !== void 0 ? _a : 5432), - "username": parameters.username, - "password": parameters.password, - "schema": parameters.schema, - "client": null, - }; - } - database.postgresql_make = postgresql_make; - /** - */ - function postgresql_init(subject) { - return __awaiter(this, void 0, void 0, function* () { - if (subject.client === null) { - const nm_pg = require("pg"); - subject.client = (new nm_pg.Client({ - "host": subject.host, - "port": subject.port, - "database": subject.schema, - "user": subject.username, - "password": subject.password, - })); - } - else { - // do nothing - } - return Promise.resolve(undefined); - }); - } - /** - * @author fenris - */ - function postgresql_adjust_query(subject, query) { - let query_adjusted = { - "template": query.template, - "arguments": [] - }; - let index = 1; - while (true) { - const regexp = (new RegExp("\\$([a-zA-Z_][0-9a-zA-Z_]*)", "g")); - const matching = regexp.exec(query_adjusted.template); - if (matching === null) { - break; - } - else { - const part = matching[0]; - const name = matching[1]; - query_adjusted.template = (query_adjusted.template.slice(0, matching.index) - + - ("$" + index.toFixed(0)) - + - query_adjusted.template.slice(matching.index + part.length)); - query_adjusted.arguments.push(query.arguments[name]); - index += 1; - } - } - lib_plankton.log.debug("database_postgresql_query", { - "original": query, - "adjusted": query_adjusted, - }); - return query_adjusted; - } - /** - * @author fenris - * @see https://node-postgres.com/apis/client#clientquery - */ - function postgresql_query_free_get(subject, query) { - return __awaiter(this, void 0, void 0, function* () { - yield postgresql_init(subject); - const query_adjusted = postgresql_adjust_query(subject, query); - yield subject.client.connect(); - const result = yield subject.client.query({ - "text": query_adjusted.template, - "values": query_adjusted.arguments, - }); - yield subject.client.end(); - return result["rows"]; - }); - } - database.postgresql_query_free_get = postgresql_query_free_get; - /** - * @author fenris - * @see https://node-postgres.com/apis/client#clientquery - */ - function postgresql_query_free_put(subject, query) { - return __awaiter(this, void 0, void 0, function* () { - yield postgresql_init(subject); - const query_adjusted = postgresql_adjust_query(subject, query); - yield subject.client.connect(); - const result1 = yield subject.client.query({ - "text": query_adjusted.template, - "values": query_adjusted.arguments, - }); - const result2 = yield subject.client.query({ - "text": "LASTVAL();", - "values": {}, - }); - yield subject.client.end(); - return result2["rows"][0]["LASTVAL"]; - }); - } - database.postgresql_query_free_put = postgresql_query_free_put; - /** - * @author fenris - * @see https://node-postgres.com/apis/client#clientquery - */ - function postgresql_query_free_set(subject, query) { - return __awaiter(this, void 0, void 0, function* () { - yield postgresql_init(subject); - const query_adjusted = postgresql_adjust_query(subject, query); - 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"]; - }); - } - database.postgresql_query_free_set = postgresql_query_free_set; - /** - */ - function postgresql_formulation_create_table(description_create_table) { - return database.sql_common_formulation_create_table(description_create_table, { - "auto_increment_keyword": "SERIAL", - "omit_comments": false, - "type_map": { - "boolean": "BOOLEAN", - "integer": "INTEGER", - "string_short": "VARCHAR(63)", - "string_medium": "VARCHAR(255)", - "string_long": "TEXT", - "float": "REAL", - }, - "wrap_names": false, - }); - } - database.postgresql_formulation_create_table = postgresql_formulation_create_table; - /** - */ - function postgresql_query_create_table(subject, description) { - return (postgresql_query_free_set(subject, postgresql_formulation_create_table(description)) - .then(x => Promise.resolve(undefined))); - } - database.postgresql_query_create_table = postgresql_query_create_table; - /** - */ - function postgresql_formulation_insert(description_insert) { - return database.sql_common_formulation_insert(description_insert, { "wrap_names": false }); - } - database.postgresql_formulation_insert = postgresql_formulation_insert; - /** - */ - function postgresql_query_insert(subject, description_insert) { - return postgresql_query_free_put(subject, postgresql_formulation_insert(description_insert)); - } - database.postgresql_query_insert = postgresql_query_insert; - /** - */ - function postgresql_formulation_update(description_update) { - return database.sql_common_formulation_update(description_update, { "wrap_names": false }); - } - database.postgresql_formulation_update = postgresql_formulation_update; - /** - */ - function postgresql_query_update(subject, description_update) { - return postgresql_query_free_set(subject, postgresql_formulation_update(description_update)); - } - database.postgresql_query_update = postgresql_query_update; - /** - */ - function postgresql_formulation_delete(description_delete) { - return database.sql_common_formulation_delete(description_delete, { "wrap_names": false }); - } - database.postgresql_formulation_delete = postgresql_formulation_delete; - /** - */ - function postgresql_query_delete(subject, description_delete) { - return postgresql_query_free_set(subject, postgresql_formulation_delete(description_delete)); - } - database.postgresql_query_delete = postgresql_query_delete; - /** - */ - function postgresql_formulation_select(description_select) { - return database.sql_common_formulation_select(description_select, { "wrap_names": false }); - } - database.postgresql_formulation_select = postgresql_formulation_select; - /** - */ - function postgresql_query_select(subject, description_select) { - return postgresql_query_free_get(subject, postgresql_formulation_select(description_select)); - } - database.postgresql_query_select = postgresql_query_select; - /** - */ - function postgresql_database(parameters) { - const subject = postgresql_make(parameters); - return { - "query_free_get": (query) => postgresql_query_free_get(subject, query), - "query_free_put": (query) => postgresql_query_free_put(subject, query), - "query_free_set": (query) => postgresql_query_free_set(subject, query), - "query_create_table": (description_create_table) => postgresql_query_create_table(subject, description_create_table), - "query_insert": (description_insert) => postgresql_query_insert(subject, description_insert), - "query_update": (description_update) => postgresql_query_update(subject, description_update), - "query_delete": (description_delete) => postgresql_query_delete(subject, description_delete), - "query_select": (description_select) => postgresql_query_select(subject, description_select), - }; - } - database.postgresql_database = postgresql_database; - })(database = lib_plankton.database || (lib_plankton.database = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:database«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:database« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:database« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:database«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var database; - (function (database) { - /** - * @author fenris - */ - class class_postgresql { - constructor(parameters) { this.subject = database.postgresql_make(parameters); } - 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_set(query) { return database.postgresql_query_free_set(this.subject, query); } - query_create_table(description_create_table) { return database.postgresql_query_create_table(this.subject, description_create_table); } - query_insert(description_insert) { return database.postgresql_query_insert(this.subject, description_insert); } - query_update(description_update) { return database.postgresql_query_update(this.subject, description_update); } - query_delete(description_delete) { return database.postgresql_query_delete(this.subject, description_delete); } - query_select(description_select) { return database.postgresql_query_select(this.subject, description_select); } - } - database.class_postgresql = class_postgresql; - })(database = lib_plankton.database || (lib_plankton.database = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:database«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:database« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:database« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:database«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var database; - (function (database) { - /** - */ - function mysql_make(parameters) { - throw (new Error("not implemented")); - } - database.mysql_make = mysql_make; - /** - */ - function mysql_init(subject) { - return __awaiter(this, void 0, void 0, function* () { - throw (new Error("not implemented")); - }); - } - /** - * @author fenris - */ - function mysql_adjust_query(subject, query) { - if (subject.verbose) { - console.info(query); - } - throw (new Error("not implemented")); - } - /** - * @author fenris - */ - function mysql_query_free_get(subject, query) { - return __awaiter(this, void 0, void 0, function* () { - throw (new Error("not implemented")); - }); - } - database.mysql_query_free_get = mysql_query_free_get; - /** - * @author fenris - */ - function mysql_query_free_put(subject, query) { - return __awaiter(this, void 0, void 0, function* () { - throw (new Error("not implemented")); - }); - } - database.mysql_query_free_put = mysql_query_free_put; - /** - * @author fenris - */ - function mysql_query_free_set(subject, query) { - return __awaiter(this, void 0, void 0, function* () { - throw (new Error("not implemented")); - }); - } - database.mysql_query_free_set = mysql_query_free_set; - /** - */ - function mysql_formulation_create_table(description_create_table) { - return database.sql_common_formulation_create_table(description_create_table, { - "auto_increment_keyword": "AUTO INCREMENT", - "omit_comments": false, - "type_map": { - "boolean": "BOOLEAN", - "integer": "INTEGER", - "string_short": "VARCHAR(63)", - "string_medium": "VARCHAR(255)", - "string_long": "TEXT", - "float": "REAL", - }, - }); - } - database.mysql_formulation_create_table = mysql_formulation_create_table; - /** - */ - function mysql_query_create_table(subject, description) { - return (mysql_query_free_set(subject, mysql_formulation_create_table(description)) - .then(x => Promise.resolve(undefined))); - } - database.mysql_query_create_table = mysql_query_create_table; - /** - */ - function mysql_formulation_insert(description_insert) { - return database.sql_common_formulation_insert(description_insert); - } - database.mysql_formulation_insert = mysql_formulation_insert; - /** - */ - function mysql_query_insert(subject, description_insert) { - return mysql_query_free_put(subject, mysql_formulation_insert(description_insert)); - } - database.mysql_query_insert = mysql_query_insert; - /** - */ - function mysql_formulation_update(description_update) { - return database.sql_common_formulation_update(description_update); - } - database.mysql_formulation_update = mysql_formulation_update; - /** - */ - function mysql_query_update(subject, description_update) { - return mysql_query_free_set(subject, mysql_formulation_update(description_update)); - } - database.mysql_query_update = mysql_query_update; - /** - */ - function mysql_formulation_delete(description_delete) { - return database.sql_common_formulation_delete(description_delete); - } - database.mysql_formulation_delete = mysql_formulation_delete; - /** - */ - function mysql_query_delete(subject, description_delete) { - return mysql_query_free_set(subject, mysql_formulation_delete(description_delete)); - } - database.mysql_query_delete = mysql_query_delete; - /** - */ - function mysql_formulation_select(description_select) { - return database.sql_common_formulation_select(description_select); - } - database.mysql_formulation_select = mysql_formulation_select; - /** - */ - function mysql_query_select(subject, description_select) { - return mysql_query_free_get(subject, mysql_formulation_select(description_select)); - } - database.mysql_query_select = mysql_query_select; - /** - */ - function mysql_database(parameters) { - const subject = mysql_make(parameters); - return { - "query_free_get": (query) => mysql_query_free_get(subject, query), - "query_free_put": (query) => mysql_query_free_put(subject, query), - "query_free_set": (query) => mysql_query_free_set(subject, query), - "query_create_table": (description_create_table) => mysql_query_create_table(subject, description_create_table), - "query_insert": (description_insert) => mysql_query_insert(subject, description_insert), - "query_update": (description_update) => mysql_query_update(subject, description_update), - "query_delete": (description_delete) => mysql_query_delete(subject, description_delete), - "query_select": (description_select) => mysql_query_select(subject, description_select), - }; - } - database.mysql_database = mysql_database; - })(database = lib_plankton.database || (lib_plankton.database = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:database«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:database« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:database« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:database«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var database; - (function (database) { - /** - * @author fenris - */ - class class_mysql { - constructor(parameters) { this.subject = database.mysql_make(parameters); } - 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_set(query) { return database.mysql_query_free_set(this.subject, query); } - query_create_table(description_create_table) { return database.mysql_query_create_table(this.subject, description_create_table); } - query_insert(description_insert) { return database.mysql_query_insert(this.subject, description_insert); } - query_update(description_update) { return database.mysql_query_update(this.subject, description_update); } - query_delete(description_delete) { return database.mysql_query_delete(this.subject, description_delete); } - query_select(description_select) { return database.mysql_query_select(this.subject, description_select); } - } - database.class_mysql = class_mysql; - })(database = lib_plankton.database || (lib_plankton.database = {})); -})(lib_plankton || (lib_plankton = {})); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) 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 (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -/* -This file is part of »bacterio-plankton:storage«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:storage« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:storage« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:storage«. If not, see . - */ -/* -This file is part of »bacterio-plankton:storage«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:storage« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:storage« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:storage«. If not, see . - */ -/* -This file is part of »bacterio-plankton:storage«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:storage« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:storage« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:storage«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var storage; - (function (storage) { - var memory; - (function (memory) { - /** - * @author fenris - */ - function make(parameters) { - return { - "data": {} - }; - } - memory.make = make; - /** - * @author fenris - */ - function clear(subject) { - subject.data = {}; - } - memory.clear = clear; - /** - * @author fenris - */ - function write(subject, key, value) { - var exists = (key in subject.data); - subject.data[key] = value; - return exists; - } - memory.write = write; - /** - * @author fenris - */ - function delete_(subject, key) { - if (!(key in subject.data)) { - throw (new Error("no value for key '" + key + "'")); - } - else { - delete subject.data[key]; - } - } - memory.delete_ = delete_; - /** - * @author fenris - */ - function read(subject, key) { - if (!(key in subject.data)) { - throw (new Error("no value for key '" + key + "'")); - } - else { - return subject.data[key]; - } - } - memory.read = read; - /** - * @author fenris - */ - function list(subject) { - return Object.keys(subject.data); - } - memory.list = list; - /** - * @author fenris - */ - function search(subject, term) { - return (list(subject) - .map(function (key) { return ({ "key": key, "preview": key }); })); - } - memory.search = search; - /** - * @author fenris - */ - function implementation_chest(parameters) { - function wrap(core) { - return (new Promise(function (resolve, reject) { resolve(core()); })); - } - var subject = make(parameters); - return { - "setup": function (input) { return Promise.resolve(undefined); }, - "clear": function () { return wrap(function () { return clear(subject); }); }, - "write": function (key, value) { return wrap(function () { return write(subject, key, value); }); }, - "delete": function (key) { return wrap(function () { return delete_(subject, key); }); }, - "read": function (key) { return wrap(function () { return read(subject, key); }); }, - "search": function (term) { return wrap(function () { return search(subject, term); }); } - }; - } - memory.implementation_chest = implementation_chest; - })(memory = storage.memory || (storage.memory = {})); - })(storage = lib_plankton.storage || (lib_plankton.storage = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:storage«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:storage« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:storage« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:storage«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var storage; - (function (storage) { - var memory; - (function (memory) { - /** - * @author fenris - */ - var class_chest = /** @class */ (function () { - function class_chest(parameters) { - this.subject = memory.make(parameters); - } - class_chest.prototype.setup = function (input) { return Promise.resolve(undefined); }; - class_chest.prototype.clear = function () { memory.clear(this.subject); return Promise.resolve(undefined); }; - class_chest.prototype.write = function (key, value) { return Promise.resolve(memory.write(this.subject, key, value)); }; - class_chest.prototype["delete"] = function (key) { memory.delete_(this.subject, key); return Promise.resolve(undefined); }; - class_chest.prototype.read = function (key) { return Promise.resolve(memory.read(this.subject, key)); }; - class_chest.prototype.search = function (term) { return Promise.resolve(memory.search(this.subject, term)); }; - return class_chest; - }()); - memory.class_chest = class_chest; - })(memory = storage.memory || (storage.memory = {})); - })(storage = lib_plankton.storage || (lib_plankton.storage = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:storage«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:storage« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:storage« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:storage«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var storage; - (function (storage) { - var filesystem; - (function (filesystem) { - /** - * @author fenris - */ - function make(parameters) { - return { - "nodemodule": require("fs") - }; - } - filesystem.make = make; - /** - */ - function clear(subject) { - return Promise.reject(new Error("nope")); - } - filesystem.clear = clear; - /** - * @author fenris - */ - function write(subject, path, content) { - return (new Promise(function (resolve, reject) { - var exists = subject.nodemodule.existsSync(path); - subject.nodemodule.writeFile(path, content, {}, function (error) { - if (error === null) { - resolve(exists); - } - else { - reject(error); - } - }); - })); - } - filesystem.write = write; - /** - * @author fenris - */ - function delete_(subject, path) { - return (new Promise(function (resolve, reject) { - subject.nodemodule.unlink(path, function (error) { - if (error === null) { - resolve(undefined); - } - else { - reject(error); - } - }); - })); - } - filesystem.delete_ = delete_; - /** - * @author fenris - */ - function read(subject, path) { - return (new Promise(function (resolve, reject) { - subject.nodemodule.readFile(path, {}, function (error, content) { - if (error === null) { - resolve(content); - } - else { - reject(error); - } - }); - })); - } - filesystem.read = read; - /** - */ - function implementation_chest(parameters) { - var subject = make(parameters); - return { - "setup": function (input) { return Promise.resolve(undefined); }, - "clear": function () { return clear(subject); }, - "write": function (key, value) { return write(subject, key, value); }, - "delete": function (key) { return delete_(subject, key); }, - "read": function (key) { return read(subject, key); }, - "search": function (term) { return Promise.reject("not available"); } - }; - } - filesystem.implementation_chest = implementation_chest; - })(filesystem = storage.filesystem || (storage.filesystem = {})); - })(storage = lib_plankton.storage || (lib_plankton.storage = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:storage«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:storage« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:storage« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:storage«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var storage; - (function (storage) { - var filesystem; - (function (filesystem) { - /** - * @author fenris - */ - var class_chest = /** @class */ (function () { - function class_chest(parameters) { - this.subject = filesystem.make(parameters); - } - class_chest.prototype.setup = function (input) { return Promise.resolve(undefined); }; - class_chest.prototype.clear = function () { return filesystem.clear(this.subject); }; - class_chest.prototype.write = function (key, value) { return filesystem.write(this.subject, key, value); }; - class_chest.prototype["delete"] = function (key) { return filesystem.delete_(this.subject, key); }; - class_chest.prototype.read = function (key) { return filesystem.read(this.subject, key); }; - class_chest.prototype.search = function (searchterm) { return Promise.reject(new Error("not available")); }; - return class_chest; - }()); - filesystem.class_chest = class_chest; - })(filesystem = storage.filesystem || (storage.filesystem = {})); - })(storage = lib_plankton.storage || (lib_plankton.storage = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:storage«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:storage« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:storage« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:storage«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var storage; - (function (storage) { - /** - */ - function sql_table_autokey_make(parameters) { - return { - "database_implementation": parameters.database_implementation, - "table_name": parameters.table_name, - "key_name": parameters.key_name - }; - } - storage.sql_table_autokey_make = sql_table_autokey_make; - /** - */ - function sql_table_autokey_setup(subject, description_create_table) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, subject.database_implementation.query_create_table(description_create_table)]; - }); - }); - } - storage.sql_table_autokey_setup = sql_table_autokey_setup; - /** - */ - function sql_table_autokey_create(subject, value) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, subject.database_implementation.query_insert({ - "table_name": subject.table_name, - "values": value - })]; - }); - }); - } - storage.sql_table_autokey_create = sql_table_autokey_create; - /** - */ - function sql_table_autokey_update(subject, key, value) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, (subject.database_implementation.query_update({ - "table_name": subject.table_name, - "values": value, - "condition": lib_plankton.string.coin("`{{key_name}}` = $key", { - "key_name": subject.key_name - }), - "arguments": { - "key": key - } - }) - .then(function (x) { return Promise.resolve(undefined); }))]; - }); - }); - } - storage.sql_table_autokey_update = sql_table_autokey_update; - /** - */ - function sql_table_autokey_delete(subject, key) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, subject.database_implementation.query_delete({ - "table_name": subject.table_name, - "condition": lib_plankton.string.coin("`{{key_name}}` = $key", { - "key_name": subject.key_name - }), - "arguments": { - "key": key - } - })]; - case 1: - _a.sent(); - return [2 /*return*/, Promise.resolve(undefined)]; - } - }); - }); - } - storage.sql_table_autokey_delete = sql_table_autokey_delete; - /** - */ - function sql_table_autokey_read(subject, key) { - return __awaiter(this, void 0, void 0, function () { - var rows; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, subject.database_implementation.query_select({ - "source": subject.table_name, - "fields": null, - "condition": lib_plankton.string.coin("`{{key_name}}` = $key", { - "key_name": subject.key_name - }), - "arguments": { - "key": key - } - })]; - case 1: - rows = _a.sent(); - if (rows.length < 1) { - return [2 /*return*/, Promise.reject("not found")]; - } - else if (rows.length > 1) { - return [2 /*return*/, Promise.reject("ambiguous")]; - } - else { - delete rows[0][subject.key_name]; - return [2 /*return*/, Promise.resolve(rows[0])]; - } - return [2 /*return*/]; - } - }); - }); - } - storage.sql_table_autokey_read = sql_table_autokey_read; - /** - * @todo correct preview - */ - function sql_table_autokey_search(subject, term) { - return __awaiter(this, void 0, void 0, function () { - var rows; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, subject.database_implementation.query_select({ - "source": subject.table_name, - "fields": null, - "condition": ((term === null) ? null : term.expression), - "arguments": ((term === null) ? null : term.arguments) - })]; - case 1: - rows = _a.sent(); - return [2 /*return*/, Promise.resolve(rows - .map(function (row) { return ({ - "key": row[subject.key_name], - "preview": row - }); }))]; - } - }); - }); - } - storage.sql_table_autokey_search = sql_table_autokey_search; - /** - */ - function sql_table_autokey_store(parameters) { - var subject = sql_table_autokey_make(parameters); - return { - "setup": function (input) { return sql_table_autokey_setup(subject, input); }, - "create": function (value) { return sql_table_autokey_create(subject, value); }, - "update": function (key, value) { return sql_table_autokey_update(subject, key, value); }, - "delete": function (key) { return sql_table_autokey_delete(subject, key); }, - "read": function (key) { return sql_table_autokey_read(subject, key); }, - "search": function (term) { return sql_table_autokey_search(subject, term); } - }; - } - storage.sql_table_autokey_store = sql_table_autokey_store; - })(storage = lib_plankton.storage || (lib_plankton.storage = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:storage«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:storage« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:storage« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:storage«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var storage; - (function (storage) { - /** - * @author fenris - */ - var class_sql_table_autokey = /** @class */ (function () { - function class_sql_table_autokey(parameters) { - this.subject = storage.sql_table_autokey_make(parameters); - } - class_sql_table_autokey.prototype.setup = function (input) { return storage.sql_table_autokey_setup(this.subject, input); }; - class_sql_table_autokey.prototype.create = function (value) { return storage.sql_table_autokey_create(this.subject, value); }; - class_sql_table_autokey.prototype.update = function (key, value) { return storage.sql_table_autokey_update(this.subject, key, value); }; - class_sql_table_autokey.prototype["delete"] = function (key) { return storage.sql_table_autokey_delete(this.subject, key); }; - class_sql_table_autokey.prototype.read = function (key) { return storage.sql_table_autokey_read(this.subject, key); }; - class_sql_table_autokey.prototype.search = function (term) { return storage.sql_table_autokey_search(this.subject, term); }; - return class_sql_table_autokey; - }()); - storage.class_sql_table_autokey = class_sql_table_autokey; - })(storage = lib_plankton.storage || (lib_plankton.storage = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:storage«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:storage« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:storage« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:storage«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var storage; - (function (storage) { - var sql_table_common; - (function (sql_table_common) { - /** - */ - function make(parameters) { - return { - "database_implementation": parameters.database_implementation, - "table_name": parameters.table_name, - "key_names": parameters.key_names - }; - } - sql_table_common.make = make; - /** - */ - function key_condition(subject, key) { - return { - "condition": lib_string.coin("({{clauses}})", { - "clauses": (subject.key_names - .map(function (key_name) { return lib_plankton.string.coin("(`{{name}}` = $key_{{name}})", { - "name": key_name - }); }) - .join(" AND ")) - }), - "arguments": Object.fromEntries(subject.key_names - .map(function (key_name, index) { return ([ - lib_plankton.string.coin("key_{{name}}", { - "name": key_name - }), - key[index] - ]); })) - }; - } - /** - */ - function setup(subject, description_create_table) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, subject.database_implementation.query_create_table(description_create_table)]; - }); - }); - } - sql_table_common.setup = setup; - /** - */ - function clear(subject) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, subject.database_implementation.query_delete({ - "table_name": subject.table_name, - "condition": "TRUE", - "arguments": {} - })]; - case 1: - _a.sent(); - return [2 /*return*/, Promise.resolve(undefined)]; - } - }); - }); - } - sql_table_common.clear = clear; - /** - * @todo optimize: avoid read - */ - function write(subject, key, value) { - return __awaiter(this, void 0, void 0, function () { - var exists, error_1, field_names, condition; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - _a.trys.push([0, 2, , 3]); - return [4 /*yield*/, read(subject, key)]; - case 1: - _a.sent(); - exists = true; - return [3 /*break*/, 3]; - case 2: - error_1 = _a.sent(); - exists = false; - return [3 /*break*/, 3]; - case 3: - field_names = Object.keys(value); - if (!!exists) return [3 /*break*/, 5]; - return [4 /*yield*/, subject.database_implementation.query_insert({ - "table_name": subject.table_name, - "values": Object.assign( - // key - Object.fromEntries(subject.key_names.map(function (key_name, index) { return ([key_name, key[index]]); })), - // value - value) - })]; - case 4: - _a.sent(); - return [3 /*break*/, 7]; - case 5: - condition = key_condition(subject, key); - return [4 /*yield*/, subject.database_implementation.query_update({ - "table_name": subject.table_name, - "values": value, - "condition": condition.condition, - "arguments": condition.arguments - })]; - case 6: - _a.sent(); - _a.label = 7; - case 7: return [2 /*return*/, Promise.resolve(exists)]; - } - }); - }); - } - sql_table_common.write = write; - /** - */ - function delete_(subject, key) { - return __awaiter(this, void 0, void 0, function () { - var condition; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - condition = key_condition(subject, key); - return [4 /*yield*/, subject.database_implementation.query_delete({ - "table_name": subject.table_name, - "condition": condition.condition, - "arguments": condition.arguments - })]; - case 1: - _a.sent(); - return [2 /*return*/, Promise.resolve(undefined)]; - } - }); - }); - } - sql_table_common.delete_ = delete_; - /** - */ - function read(subject, key) { - return __awaiter(this, void 0, void 0, function () { - var condition, rows; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - condition = key_condition(subject, key); - return [4 /*yield*/, subject.database_implementation.query_select({ - "source": subject.table_name, - "fields": null, - "condition": condition.condition, - "arguments": condition.arguments - })]; - case 1: - rows = _a.sent(); - if (rows.length < 1) { - return [2 /*return*/, Promise.reject("not found")]; - } - else if (rows.length > 1) { - return [2 /*return*/, Promise.reject("ambiguous")]; - } - else { - subject.key_names.forEach(function (key_name) { delete rows[0][key_name]; }); - return [2 /*return*/, Promise.resolve(rows[0])]; - } - return [2 /*return*/]; - } - }); - }); - } - sql_table_common.read = read; - /** - * @todo correct preview - */ - function search(subject, term) { - return __awaiter(this, void 0, void 0, function () { - var rows; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, subject.database_implementation.query_select({ - "source": subject.table_name, - "fields": null, - "condition": ((term === null) ? null : term.expression), - "arguments": ((term === null) ? null : term.arguments) - })]; - case 1: - rows = _a.sent(); - return [2 /*return*/, Promise.resolve(rows - .map(function (row) { return ({ - "key": subject.key_names.map(function (name) { return row[name]; }), - "preview": row - }); }))]; - } - }); - }); - } - sql_table_common.search = search; - /** - */ - function chest(parameters) { - var subject = make(parameters); - return { - "setup": function (input) { return setup(subject, input); }, - "clear": function () { return clear(subject); }, - "write": function (key, value) { return write(subject, key, value); }, - "delete": function (key) { return delete_(subject, key); }, - "read": function (key) { return read(subject, key); }, - "search": function (term) { return search(subject, term); } - }; - } - sql_table_common.chest = chest; - })(sql_table_common = storage.sql_table_common || (storage.sql_table_common = {})); - })(storage = lib_plankton.storage || (lib_plankton.storage = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:storage«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:storage« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:storage« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:storage«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var storage; - (function (storage) { - var sql_table_common; - (function (sql_table_common) { - /** - * @author fenris - */ - var class_chest = /** @class */ (function () { - function class_chest(parameters) { - this.subject = sql_table_common.make(parameters); - } - class_chest.prototype.setup = function (input) { return sql_table_common.setup(this.subject, input); }; - class_chest.prototype.clear = function () { return sql_table_common.clear(this.subject); }; - class_chest.prototype.write = function (key, value) { return sql_table_common.write(this.subject, key, value); }; - class_chest.prototype["delete"] = function (key) { return sql_table_common.delete_(this.subject, key); }; - class_chest.prototype.read = function (key) { return sql_table_common.read(this.subject, key); }; - class_chest.prototype.search = function (term) { return sql_table_common.search(this.subject, term); }; - return class_chest; - }()); - sql_table_common.class_chest = class_chest; - })(sql_table_common = storage.sql_table_common || (storage.sql_table_common = {})); - })(storage = lib_plankton.storage || (lib_plankton.storage = {})); -})(lib_plankton || (lib_plankton = {})); /* This file is part of »bacterio-plankton:shape«. @@ -8005,6 +6471,1155 @@ var lib_plankton; */ })(random = lib_plankton.random || (lib_plankton.random = {})); })(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:sha256«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:sha256« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:sha256« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:sha256«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var sha256; + (function (sha256) { + /** + * @author fenris + */ + function get(value, secret = "") { + const nm_crypto = require("crypto"); + const sha256Hasher = nm_crypto.createHmac("sha256", secret); + const hash = sha256Hasher.update(value).digest("hex"); + return hash; + } + sha256.get = get; + })(sha256 = lib_plankton.sha256 || (lib_plankton.sha256 = {})); +})(lib_plankton || (lib_plankton = {})); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +/* +This file is part of »bacterio-plankton:database«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:database« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:database« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:database«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var database; + (function (database) { + /** + */ + let enum_type; + (function (enum_type) { + enum_type["boolean"] = "boolean"; + enum_type["integer"] = "integer"; + enum_type["string_short"] = "string_short"; + enum_type["string_medium"] = "string_medium"; + enum_type["string_long"] = "string_long"; + enum_type["float"] = "float"; + })(enum_type = database.enum_type || (database.enum_type = {})); + })(database = lib_plankton.database || (lib_plankton.database = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:database«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:database« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:database« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:database«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var database; + (function (database) { + /** + * @todo default case? + */ + function sql_common_value_format(value) { + if (value === undefined) { + throw (new Error("can not format undefined")); + } + else { + if (value === null) { + return "NULL"; + } + else { + switch (typeof (value)) { + case "boolean": { + return (value ? "TRUE" : "FALSE"); + break; + } + case "number": { + return value.toString(); + break; + } + case "string": { + return ("'" + value + "'"); + break; + } + } + } + } + } + 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 = {}) { + var _a, _b, _c, _d, _e; + options = Object.assign({ + "auto_increment_keyword": "AUTO INCREMENT", + "omit_comments": false, + "type_map": { + "boolean": "BOOLEAN", + "integer": "INTEGER", + "string_short": "VARCHAR(63)", + "string_medium": "VARCHAR(255)", + "string_long": "TEXT", + "float": "REAL", + }, + "wrap_names": true, + }, options); + return { + "template": lib_plankton.string.coin("CREATE TABLE\n\t{{name}}(\n{{entries}}\n\t){{comment}}\n;", { + "name": wrap_name(description_create_table.name, { "active": options.wrap_names }), + "comment": ((options.omit_comments + || + (((_a = description_create_table.description) !== null && _a !== void 0 ? _a : null) === null)) + ? "" + : lib_plankton.string.coin(" COMMENT '{{comment}}'", { + "comment": description_create_table.description, + })), + "entries": (([] + // key field + .concat((((_b = description_create_table.key_field) !== null && _b !== void 0 ? _b : null) === null) + ? [] + : lib_plankton.string.coin("{{name}} {{parameters}}", { + "name": wrap_name(description_create_table.key_field.name, { "active": options.wrap_names }), + "parameters": (([] + /* + // type + .concat( + [ + options.type_map[description_create_table.key_field.type ?? "integer"], + ] + ) + */ + // auto increment + .concat((((_c = description_create_table.key_field.auto_increment) !== null && _c !== void 0 ? _c : true) === null) + ? [] + : [ + options.auto_increment_keyword, + ]) + // primary key + .concat([ + "PRIMARY KEY", + ])) + .join(" ")), + })) + // data fields + .concat(((_d = description_create_table.data_fields) !== null && _d !== void 0 ? _d : []) + .map((data_field) => { + var _a, _b; + return lib_plankton.string.coin("{{name}} {{parameters}}", { + "name": wrap_name(data_field.name, { "active": options.wrap_names }), + "parameters": (([] + // type + .concat([ + options.type_map[data_field.type], + ]) + // nullability + .concat((!((_a = data_field.nullable) !== null && _a !== void 0 ? _a : false)) + ? [] + : ["NULL"]) + // default + .concat((!data_field.hasOwnProperty("default")) + ? [] + : [ + lib_plankton.string.coin(" DEFAULT {{value}}", { + "value": sql_common_value_format(data_field.default) + }), + ]) + // comment + .concat((options.omit_comments + || + (((_b = data_field.description) !== null && _b !== void 0 ? _b : null) === null)) + ? [] + : [ + lib_plankton.string.coin("COMMENT '{{comment}}'", { + "comment": data_field.description, + }), + ])) + .join(" ")) + }); + })) + // constraints + .concat(((_e = description_create_table.constraints) !== null && _e !== void 0 ? _e : []) + .map((constraint) => { + switch (constraint.kind) { + default: { + throw (new Error("unhandled constraint kind: " + constraint.kind)); + break; + } + case "foreign_key": { + return lib_plankton.string.coin("FOREIGN KEY ({{fields}}) REFERENCES {{reference_name}}({{reference_fields}})", { + "fields": (constraint.parameters["fields"] + .map(x => wrap_name(x, { "active": options.wrap_names })) + .join(",")), + "reference_name": wrap_name(constraint.parameters["reference"]["name"], { "active": options.wrap_names }), + "reference_fields": (constraint.parameters["reference"]["fields"] + .map(x => wrap_name(x, { "active": options.wrap_names })) + .join(",")), + }); + break; + } + case "unique": { + return lib_plankton.string.coin("UNIQUE ({{fields}})", { + "fields": (constraint.parameters["fields"] + .map(x => wrap_name(x, { "active": options.wrap_names })) + .join(",")), + }); + break; + } + } + }))) + .map(x => ("\t\t" + x)) + .join(",\n")), + }), + "arguments": {} + }; + } + database.sql_common_formulation_create_table = sql_common_formulation_create_table; + /** + */ + function sql_common_formulation_insert(description_insert, options = {}) { + options = Object.assign({ + "wrap_names": true, + }, options); + const field_names = Object.keys(description_insert.values); + return { + "template": lib_plankton.string.coin("INSERT INTO {{table_name}}({{schema}}) VALUES ({{values}});", { + "table_name": wrap_name(description_insert.table_name, { "active": options.wrap_names }), + "schema": (field_names + .map((field_name) => lib_plankton.string.coin("{{name}}", { + "name": wrap_name(field_name, { "active": options.wrap_names }), + })) + .join(",")), + "values": (field_names + .map((field_name) => lib_plankton.string.coin("$value_{{name}}", { + "name": field_name, + })) + .join(",")), + }), + "arguments": Object.fromEntries(Object.entries(description_insert.values) + .map(([name, value]) => ([ + lib_plankton.string.coin("value_{{name}}", { + "name": name, + }), + value + ]))), + }; + } + database.sql_common_formulation_insert = sql_common_formulation_insert; + /** + */ + function sql_common_formulation_update(description_update, options = {}) { + var _a, _b; + options = Object.assign({ + "wrap_names": true, + }, options); + const field_names = Object.keys(description_update.values); + return { + "template": lib_plankton.string.coin("UPDATE {{table_name}} SET {{assignments}}{{macro_where}};", { + "table_name": wrap_name(description_update.table_name, { "active": options.wrap_names }), + "assignments": (field_names + .map((field_name) => lib_plankton.string.coin("{{name}} = $value_{{suffix}}", { + "name": wrap_name(field_name, { "active": options.wrap_names }), + "suffix": field_name, + })) + .join(", ")), + "macro_where": ((((_a = description_update.condition) !== null && _a !== void 0 ? _a : null) === null) + ? "" + : lib_plankton.string.coin(" WHERE {{expression}}", { + "expression": description_update.condition, + })), + }), + "arguments": Object.assign(Object.fromEntries(Object.entries(description_update.values) + .map(([name, value]) => ([ + lib_plankton.string.coin("value_{{name}}", { + "name": name, + }), + value + ]))), ((_b = description_update.arguments) !== null && _b !== void 0 ? _b : {})) + }; + } + database.sql_common_formulation_update = sql_common_formulation_update; + /** + */ + function sql_common_formulation_delete(description_delete, options = {}) { + var _a, _b; + options = Object.assign({ + "wrap_names": true, + }, options); + return { + "template": lib_plankton.string.coin("DELETE FROM {{table_name}}{{macro_where}};", { + "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) + ? "" + : lib_plankton.string.coin(" WHERE {{expression}}", { + "expression": description_delete.condition, + })), + }), + "arguments": Object.assign({}, ((_b = description_delete.arguments) !== null && _b !== void 0 ? _b : {})), + }; + } + database.sql_common_formulation_delete = sql_common_formulation_delete; + /** + */ + function sql_common_formulation_select(description_select, options = {}) { + var _a, _b, _c, _d, _e, _f, _g; + options = Object.assign({ + "wrap_names": true, + }, options); + return { + "template": lib_plankton.string.coin("SELECT {{fields}} FROM {{source}}{{macro_where}}{{macro_group_by}}{{macro_having}}{{macro_order_by}}{{macro_limit}};", { + "source": wrap_name(description_select.source, { "active": options.wrap_names }), + "fields": ((((_a = description_select.fields) !== null && _a !== void 0 ? _a : null) === null) + ? "*" + : (description_select.fields + .map(field_name => lib_plankton.string.coin("{{name}}", { "name": wrap_name(field_name, { "active": options.wrap_names }) })) + .join(","))), + "macro_where": ((((_b = description_select.condition) !== null && _b !== void 0 ? _b : null) === null) + ? "" + : lib_plankton.string.coin(" WHERE {{expression}}", { + "expression": description_select.condition, + })), + "macro_group_by": ((((_c = description_select.group_by) !== null && _c !== void 0 ? _c : null) === null) + ? "" + : lib_plankton.string.coin(" GROUP BY {{expression}}", { + "expression": description_select.group_by, + })), + "macro_having": ((((_d = description_select.having) !== null && _d !== void 0 ? _d : null) === null) + ? "" + : lib_plankton.string.coin(" HAVING {{expression}}", { + "expression": description_select.having, + })), + "macro_order_by": ((((_e = description_select.order_by) !== null && _e !== void 0 ? _e : null) === null) + ? "" + : lib_plankton.string.coin(" ORDER BY {{expression}}", { + "expression": description_select.order_by, + })), + "macro_limit": ((((_f = description_select.limit) !== null && _f !== void 0 ? _f : null) === null) + ? "" + : lib_plankton.string.coin(" LIMIT {{expression}}", { + "expression": description_select.limit.toFixed(0), + })), + }), + "arguments": Object.assign({}, ((_g = description_select.arguments) !== null && _g !== void 0 ? _g : {})), + }; + } + database.sql_common_formulation_select = sql_common_formulation_select; + })(database = lib_plankton.database || (lib_plankton.database = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:database«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:database« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:database« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:database«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var database; + (function (database) { + /** + */ + function sqlite_make(parameters) { + return { + "path": parameters.path, + "handle": null, + }; + } + database.sqlite_make = sqlite_make; + /** + */ + function sqlite_init(subject) { + return __awaiter(this, void 0, void 0, function* () { + if (subject.handle === null) { + yield new Promise((resolve, reject) => { + const _nm_sqlite3 = require("sqlite3"); + subject.handle = new _nm_sqlite3.Database(subject.path, (_nm_sqlite3.OPEN_READWRITE | _nm_sqlite3.OPEN_CREATE | _nm_sqlite3.OPEN_FULLMUTEX), () => { resolve(undefined); }); + }); + } + else { + // do nothing + } + return Promise.resolve(undefined); + }); + } + /** + * @author fenris + */ + function sqlite_adjust_query(subject, query) { + const query_adjusted = { + "template": query.template, + "arguments": Object.fromEntries(Object.entries(query.arguments) + .map(([key, value]) => ([ + ("$" + key), + (((value === null) + || + (value === undefined)) + ? null + : ((typeof (value) === "boolean") + ? (value ? "1" : "0") + : value.toString())) + ]))), + }; + lib_plankton.log.debug("database_sqlite_query", { + "original": query, + "adjusted": query_adjusted, + }); + return query_adjusted; + } + /** + * @author fenris + */ + function sqlite_query_free_get(subject, query) { + return __awaiter(this, void 0, void 0, function* () { + yield sqlite_init(subject); + const query_adjusted = sqlite_adjust_query(subject, query); + return (new Promise((resolve, reject) => { + subject.handle.all(query_adjusted.template, query_adjusted.arguments, (error, rows) => { + if (error !== null) { + reject(error); + } + else { + resolve(rows); + } + }); + })); + }); + } + database.sqlite_query_free_get = sqlite_query_free_get; + /** + * @author fenris + */ + function sqlite_query_free_put(subject, query) { + return __awaiter(this, void 0, void 0, function* () { + yield sqlite_init(subject); + const query_adjusted = sqlite_adjust_query(subject, query); + return (new Promise((resolve, reject) => { + subject.handle.run(query_adjusted.template, query_adjusted.arguments, + // this MUST be an old style function + function (error) { + if (error) { + reject(error); + } + else { + resolve(this["lastID"]); + } + }); + })); + }); + } + database.sqlite_query_free_put = sqlite_query_free_put; + /** + * @author fenris + */ + function sqlite_query_free_set(subject, query) { + return __awaiter(this, void 0, void 0, function* () { + yield sqlite_init(subject); + const query_adjusted = sqlite_adjust_query(subject, query); + return (new Promise((resolve, reject) => { + subject.handle.run(query_adjusted.template, query_adjusted.arguments, + // this MUST be an old style function + function (error) { + if (error) { + reject(error); + } + else { + resolve(this["changes"]); + } + }); + })); + }); + } + database.sqlite_query_free_set = sqlite_query_free_set; + /** + */ + function sqlite_formulation_create_table(description_create_table) { + return database.sql_common_formulation_create_table(description_create_table, { + "auto_increment_keyword": "INTEGER NOT NULL AUTOINCREMENT", + "omit_comments": true, + "type_map": { + "boolean": "INTEGER", + "integer": "INTEGER", + "string_short": "TEXT", + "string_medium": "TEXT", + "string_long": "TEXT", + "float": "REAL", + }, + }); + } + database.sqlite_formulation_create_table = sqlite_formulation_create_table; + /** + */ + function sqlite_query_create_table(subject, description) { + return (sqlite_query_free_set(subject, sqlite_formulation_create_table(description)) + .then(x => Promise.resolve(undefined))); + } + database.sqlite_query_create_table = sqlite_query_create_table; + /** + */ + function sqlite_formulation_insert(description_insert) { + return database.sql_common_formulation_insert(description_insert); + } + database.sqlite_formulation_insert = sqlite_formulation_insert; + /** + */ + function sqlite_query_insert(subject, description_insert) { + return sqlite_query_free_put(subject, sqlite_formulation_insert(description_insert)); + } + database.sqlite_query_insert = sqlite_query_insert; + /** + */ + function sqlite_formulation_update(description_update) { + return database.sql_common_formulation_update(description_update); + } + database.sqlite_formulation_update = sqlite_formulation_update; + /** + */ + function sqlite_query_update(subject, description_update) { + return sqlite_query_free_set(subject, sqlite_formulation_update(description_update)); + } + database.sqlite_query_update = sqlite_query_update; + /** + */ + function sqlite_formulation_delete(description_delete) { + return database.sql_common_formulation_delete(description_delete); + } + database.sqlite_formulation_delete = sqlite_formulation_delete; + /** + */ + function sqlite_query_delete(subject, description_delete) { + return sqlite_query_free_set(subject, sqlite_formulation_delete(description_delete)); + } + database.sqlite_query_delete = sqlite_query_delete; + /** + */ + function sqlite_formulation_select(description_select) { + return database.sql_common_formulation_select(description_select); + } + database.sqlite_formulation_select = sqlite_formulation_select; + /** + */ + function sqlite_query_select(subject, description_select) { + return sqlite_query_free_get(subject, sqlite_formulation_select(description_select)); + } + database.sqlite_query_select = sqlite_query_select; + /** + */ + function sqlite_database(parameters) { + const subject = sqlite_make(parameters); + return { + "query_free_get": (query) => sqlite_query_free_get(subject, query), + "query_free_put": (query) => sqlite_query_free_put(subject, query), + "query_free_set": (query) => sqlite_query_free_set(subject, query), + "query_create_table": (description_create_table) => sqlite_query_create_table(subject, description_create_table), + "query_insert": (description_insert) => sqlite_query_insert(subject, description_insert), + "query_update": (description_update) => sqlite_query_update(subject, description_update), + "query_delete": (description_delete) => sqlite_query_delete(subject, description_delete), + "query_select": (description_select) => sqlite_query_select(subject, description_select), + }; + } + database.sqlite_database = sqlite_database; + })(database = lib_plankton.database || (lib_plankton.database = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:database«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:database« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:database« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:database«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var database; + (function (database) { + /** + * @author fenris + */ + class class_sqlite { + constructor(parameters) { this.subject = database.sqlite_make(parameters); } + 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_set(query) { return database.sqlite_query_free_set(this.subject, query); } + query_create_table(description_create_table) { return database.sqlite_query_create_table(this.subject, description_create_table); } + query_insert(description_insert) { return database.sqlite_query_insert(this.subject, description_insert); } + query_update(description_update) { return database.sqlite_query_update(this.subject, description_update); } + query_delete(description_delete) { return database.sqlite_query_delete(this.subject, description_delete); } + query_select(description_select) { return database.sqlite_query_select(this.subject, description_select); } + } + database.class_sqlite = class_sqlite; + })(database = lib_plankton.database || (lib_plankton.database = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:database«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:database« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:database« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:database«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var database; + (function (database) { + /** + * @see https://node-postgres.com/apis/client#new-client + */ + function postgresql_make(parameters) { + var _a; + return { + "host": parameters.host, + "port": ((_a = parameters.port) !== null && _a !== void 0 ? _a : 5432), + "username": parameters.username, + "password": parameters.password, + "schema": parameters.schema, + "client": null, + }; + } + database.postgresql_make = postgresql_make; + /** + */ + function postgresql_init(subject) { + return __awaiter(this, void 0, void 0, function* () { + if (subject.client === null) { + const nm_pg = require("pg"); + subject.client = (new nm_pg.Client({ + "host": subject.host, + "port": subject.port, + "database": subject.schema, + "user": subject.username, + "password": subject.password, + })); + } + else { + // do nothing + } + return Promise.resolve(undefined); + }); + } + /** + * @author fenris + */ + function postgresql_adjust_query(subject, query) { + let query_adjusted = { + "template": query.template, + "arguments": [] + }; + let index = 1; + while (true) { + const regexp = (new RegExp("\\$([a-zA-Z_][0-9a-zA-Z_]*)", "g")); + const matching = regexp.exec(query_adjusted.template); + if (matching === null) { + break; + } + else { + const part = matching[0]; + const name = matching[1]; + query_adjusted.template = (query_adjusted.template.slice(0, matching.index) + + + ("$" + index.toFixed(0)) + + + query_adjusted.template.slice(matching.index + part.length)); + query_adjusted.arguments.push(query.arguments[name]); + index += 1; + } + } + lib_plankton.log.debug("database_postgresql_query", { + "original": query, + "adjusted": query_adjusted, + }); + return query_adjusted; + } + /** + * @author fenris + * @see https://node-postgres.com/apis/client#clientquery + */ + function postgresql_query_free_get(subject, query) { + return __awaiter(this, void 0, void 0, function* () { + yield postgresql_init(subject); + const query_adjusted = postgresql_adjust_query(subject, query); + yield subject.client.connect(); + const result = yield subject.client.query({ + "text": query_adjusted.template, + "values": query_adjusted.arguments, + }); + yield subject.client.end(); + return result["rows"]; + }); + } + database.postgresql_query_free_get = postgresql_query_free_get; + /** + * @author fenris + * @see https://node-postgres.com/apis/client#clientquery + */ + function postgresql_query_free_put(subject, query) { + return __awaiter(this, void 0, void 0, function* () { + yield postgresql_init(subject); + const query_adjusted = postgresql_adjust_query(subject, query); + yield subject.client.connect(); + const result1 = yield subject.client.query({ + "text": query_adjusted.template, + "values": query_adjusted.arguments, + }); + const result2 = yield subject.client.query({ + "text": "LASTVAL();", + "values": {}, + }); + yield subject.client.end(); + return result2["rows"][0]["LASTVAL"]; + }); + } + database.postgresql_query_free_put = postgresql_query_free_put; + /** + * @author fenris + * @see https://node-postgres.com/apis/client#clientquery + */ + function postgresql_query_free_set(subject, query) { + return __awaiter(this, void 0, void 0, function* () { + yield postgresql_init(subject); + const query_adjusted = postgresql_adjust_query(subject, query); + 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"]; + }); + } + database.postgresql_query_free_set = postgresql_query_free_set; + /** + */ + function postgresql_formulation_create_table(description_create_table) { + return database.sql_common_formulation_create_table(description_create_table, { + "auto_increment_keyword": "SERIAL", + "omit_comments": false, + "type_map": { + "boolean": "BOOLEAN", + "integer": "INTEGER", + "string_short": "VARCHAR(63)", + "string_medium": "VARCHAR(255)", + "string_long": "TEXT", + "float": "REAL", + }, + "wrap_names": false, + }); + } + database.postgresql_formulation_create_table = postgresql_formulation_create_table; + /** + */ + function postgresql_query_create_table(subject, description) { + return (postgresql_query_free_set(subject, postgresql_formulation_create_table(description)) + .then(x => Promise.resolve(undefined))); + } + database.postgresql_query_create_table = postgresql_query_create_table; + /** + */ + function postgresql_formulation_insert(description_insert) { + return database.sql_common_formulation_insert(description_insert, { "wrap_names": false }); + } + database.postgresql_formulation_insert = postgresql_formulation_insert; + /** + */ + function postgresql_query_insert(subject, description_insert) { + return postgresql_query_free_put(subject, postgresql_formulation_insert(description_insert)); + } + database.postgresql_query_insert = postgresql_query_insert; + /** + */ + function postgresql_formulation_update(description_update) { + return database.sql_common_formulation_update(description_update, { "wrap_names": false }); + } + database.postgresql_formulation_update = postgresql_formulation_update; + /** + */ + function postgresql_query_update(subject, description_update) { + return postgresql_query_free_set(subject, postgresql_formulation_update(description_update)); + } + database.postgresql_query_update = postgresql_query_update; + /** + */ + function postgresql_formulation_delete(description_delete) { + return database.sql_common_formulation_delete(description_delete, { "wrap_names": false }); + } + database.postgresql_formulation_delete = postgresql_formulation_delete; + /** + */ + function postgresql_query_delete(subject, description_delete) { + return postgresql_query_free_set(subject, postgresql_formulation_delete(description_delete)); + } + database.postgresql_query_delete = postgresql_query_delete; + /** + */ + function postgresql_formulation_select(description_select) { + return database.sql_common_formulation_select(description_select, { "wrap_names": false }); + } + database.postgresql_formulation_select = postgresql_formulation_select; + /** + */ + function postgresql_query_select(subject, description_select) { + return postgresql_query_free_get(subject, postgresql_formulation_select(description_select)); + } + database.postgresql_query_select = postgresql_query_select; + /** + */ + function postgresql_database(parameters) { + const subject = postgresql_make(parameters); + return { + "query_free_get": (query) => postgresql_query_free_get(subject, query), + "query_free_put": (query) => postgresql_query_free_put(subject, query), + "query_free_set": (query) => postgresql_query_free_set(subject, query), + "query_create_table": (description_create_table) => postgresql_query_create_table(subject, description_create_table), + "query_insert": (description_insert) => postgresql_query_insert(subject, description_insert), + "query_update": (description_update) => postgresql_query_update(subject, description_update), + "query_delete": (description_delete) => postgresql_query_delete(subject, description_delete), + "query_select": (description_select) => postgresql_query_select(subject, description_select), + }; + } + database.postgresql_database = postgresql_database; + })(database = lib_plankton.database || (lib_plankton.database = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:database«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:database« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:database« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:database«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var database; + (function (database) { + /** + * @author fenris + */ + class class_postgresql { + constructor(parameters) { this.subject = database.postgresql_make(parameters); } + 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_set(query) { return database.postgresql_query_free_set(this.subject, query); } + query_create_table(description_create_table) { return database.postgresql_query_create_table(this.subject, description_create_table); } + query_insert(description_insert) { return database.postgresql_query_insert(this.subject, description_insert); } + query_update(description_update) { return database.postgresql_query_update(this.subject, description_update); } + query_delete(description_delete) { return database.postgresql_query_delete(this.subject, description_delete); } + query_select(description_select) { return database.postgresql_query_select(this.subject, description_select); } + } + database.class_postgresql = class_postgresql; + })(database = lib_plankton.database || (lib_plankton.database = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:database«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:database« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:database« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:database«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var database; + (function (database) { + /** + */ + function mysql_make(parameters) { + throw (new Error("not implemented")); + } + database.mysql_make = mysql_make; + /** + */ + function mysql_init(subject) { + return __awaiter(this, void 0, void 0, function* () { + throw (new Error("not implemented")); + }); + } + /** + * @author fenris + */ + function mysql_adjust_query(subject, query) { + if (subject.verbose) { + console.info(query); + } + throw (new Error("not implemented")); + } + /** + * @author fenris + */ + function mysql_query_free_get(subject, query) { + return __awaiter(this, void 0, void 0, function* () { + throw (new Error("not implemented")); + }); + } + database.mysql_query_free_get = mysql_query_free_get; + /** + * @author fenris + */ + function mysql_query_free_put(subject, query) { + return __awaiter(this, void 0, void 0, function* () { + throw (new Error("not implemented")); + }); + } + database.mysql_query_free_put = mysql_query_free_put; + /** + * @author fenris + */ + function mysql_query_free_set(subject, query) { + return __awaiter(this, void 0, void 0, function* () { + throw (new Error("not implemented")); + }); + } + database.mysql_query_free_set = mysql_query_free_set; + /** + */ + function mysql_formulation_create_table(description_create_table) { + return database.sql_common_formulation_create_table(description_create_table, { + "auto_increment_keyword": "AUTO INCREMENT", + "omit_comments": false, + "type_map": { + "boolean": "BOOLEAN", + "integer": "INTEGER", + "string_short": "VARCHAR(63)", + "string_medium": "VARCHAR(255)", + "string_long": "TEXT", + "float": "REAL", + }, + }); + } + database.mysql_formulation_create_table = mysql_formulation_create_table; + /** + */ + function mysql_query_create_table(subject, description) { + return (mysql_query_free_set(subject, mysql_formulation_create_table(description)) + .then(x => Promise.resolve(undefined))); + } + database.mysql_query_create_table = mysql_query_create_table; + /** + */ + function mysql_formulation_insert(description_insert) { + return database.sql_common_formulation_insert(description_insert); + } + database.mysql_formulation_insert = mysql_formulation_insert; + /** + */ + function mysql_query_insert(subject, description_insert) { + return mysql_query_free_put(subject, mysql_formulation_insert(description_insert)); + } + database.mysql_query_insert = mysql_query_insert; + /** + */ + function mysql_formulation_update(description_update) { + return database.sql_common_formulation_update(description_update); + } + database.mysql_formulation_update = mysql_formulation_update; + /** + */ + function mysql_query_update(subject, description_update) { + return mysql_query_free_set(subject, mysql_formulation_update(description_update)); + } + database.mysql_query_update = mysql_query_update; + /** + */ + function mysql_formulation_delete(description_delete) { + return database.sql_common_formulation_delete(description_delete); + } + database.mysql_formulation_delete = mysql_formulation_delete; + /** + */ + function mysql_query_delete(subject, description_delete) { + return mysql_query_free_set(subject, mysql_formulation_delete(description_delete)); + } + database.mysql_query_delete = mysql_query_delete; + /** + */ + function mysql_formulation_select(description_select) { + return database.sql_common_formulation_select(description_select); + } + database.mysql_formulation_select = mysql_formulation_select; + /** + */ + function mysql_query_select(subject, description_select) { + return mysql_query_free_get(subject, mysql_formulation_select(description_select)); + } + database.mysql_query_select = mysql_query_select; + /** + */ + function mysql_database(parameters) { + const subject = mysql_make(parameters); + return { + "query_free_get": (query) => mysql_query_free_get(subject, query), + "query_free_put": (query) => mysql_query_free_put(subject, query), + "query_free_set": (query) => mysql_query_free_set(subject, query), + "query_create_table": (description_create_table) => mysql_query_create_table(subject, description_create_table), + "query_insert": (description_insert) => mysql_query_insert(subject, description_insert), + "query_update": (description_update) => mysql_query_update(subject, description_update), + "query_delete": (description_delete) => mysql_query_delete(subject, description_delete), + "query_select": (description_select) => mysql_query_select(subject, description_select), + }; + } + database.mysql_database = mysql_database; + })(database = lib_plankton.database || (lib_plankton.database = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:database«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:database« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:database« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:database«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var database; + (function (database) { + /** + * @author fenris + */ + class class_mysql { + constructor(parameters) { this.subject = database.mysql_make(parameters); } + 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_set(query) { return database.mysql_query_free_set(this.subject, query); } + query_create_table(description_create_table) { return database.mysql_query_create_table(this.subject, description_create_table); } + query_insert(description_insert) { return database.mysql_query_insert(this.subject, description_insert); } + query_update(description_update) { return database.mysql_query_update(this.subject, description_update); } + query_delete(description_delete) { return database.mysql_query_delete(this.subject, description_delete); } + query_select(description_select) { return database.mysql_query_select(this.subject, description_select); } + } + database.class_mysql = class_mysql; + })(database = lib_plankton.database || (lib_plankton.database = {})); +})(lib_plankton || (lib_plankton = {})); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { @@ -8020,7 +7635,878 @@ var __generator = (this && this.__generator) || function (thisArg, body) { function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { 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 (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:storage« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:storage«. If not, see . + */ +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:storage« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:storage«. If not, see . + */ +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:storage« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:storage«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var storage; + (function (storage) { + var memory; + (function (memory) { + /** + * @author fenris + */ + function make(parameters) { + return { + "data": {} + }; + } + memory.make = make; + /** + * @author fenris + */ + function clear(subject) { + subject.data = {}; + } + memory.clear = clear; + /** + * @author fenris + */ + function write(subject, key, value) { + var exists = (key in subject.data); + subject.data[key] = value; + return exists; + } + memory.write = write; + /** + * @author fenris + */ + function delete_(subject, key) { + if (!(key in subject.data)) { + throw (new Error("no value for key '" + key + "'")); + } + else { + delete subject.data[key]; + } + } + memory.delete_ = delete_; + /** + * @author fenris + */ + function read(subject, key) { + if (!(key in subject.data)) { + throw (new Error("no value for key '" + key + "'")); + } + else { + return subject.data[key]; + } + } + memory.read = read; + /** + * @author fenris + */ + function list(subject) { + return Object.keys(subject.data); + } + memory.list = list; + /** + * @author fenris + */ + function search(subject, term) { + return (list(subject) + .map(function (key) { return ({ "key": key, "preview": key }); })); + } + memory.search = search; + /** + * @author fenris + */ + function implementation_chest(parameters) { + function wrap(core) { + return (new Promise(function (resolve, reject) { resolve(core()); })); + } + var subject = make(parameters); + return { + "setup": function (input) { return Promise.resolve(undefined); }, + "clear": function () { return wrap(function () { return clear(subject); }); }, + "write": function (key, value) { return wrap(function () { return write(subject, key, value); }); }, + "delete": function (key) { return wrap(function () { return delete_(subject, key); }); }, + "read": function (key) { return wrap(function () { return read(subject, key); }); }, + "search": function (term) { return wrap(function () { return search(subject, term); }); } + }; + } + memory.implementation_chest = implementation_chest; + })(memory = storage.memory || (storage.memory = {})); + })(storage = lib_plankton.storage || (lib_plankton.storage = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:storage« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:storage«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var storage; + (function (storage) { + var memory; + (function (memory) { + /** + * @author fenris + */ + var class_chest = /** @class */ (function () { + function class_chest(parameters) { + this.subject = memory.make(parameters); + } + class_chest.prototype.setup = function (input) { return Promise.resolve(undefined); }; + class_chest.prototype.clear = function () { memory.clear(this.subject); return Promise.resolve(undefined); }; + class_chest.prototype.write = function (key, value) { return Promise.resolve(memory.write(this.subject, key, value)); }; + class_chest.prototype["delete"] = function (key) { memory.delete_(this.subject, key); return Promise.resolve(undefined); }; + class_chest.prototype.read = function (key) { return Promise.resolve(memory.read(this.subject, key)); }; + class_chest.prototype.search = function (term) { return Promise.resolve(memory.search(this.subject, term)); }; + return class_chest; + }()); + memory.class_chest = class_chest; + })(memory = storage.memory || (storage.memory = {})); + })(storage = lib_plankton.storage || (lib_plankton.storage = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:storage« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:storage«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var storage; + (function (storage) { + var filesystem; + (function (filesystem) { + /** + * @author fenris + */ + function make(parameters) { + return { + "nodemodule": require("fs") + }; + } + filesystem.make = make; + /** + */ + function clear(subject) { + return Promise.reject(new Error("nope")); + } + filesystem.clear = clear; + /** + * @author fenris + */ + function write(subject, path, content) { + return (new Promise(function (resolve, reject) { + var exists = subject.nodemodule.existsSync(path); + subject.nodemodule.writeFile(path, content, {}, function (error) { + if (error === null) { + resolve(exists); + } + else { + reject(error); + } + }); + })); + } + filesystem.write = write; + /** + * @author fenris + */ + function delete_(subject, path) { + return (new Promise(function (resolve, reject) { + subject.nodemodule.unlink(path, function (error) { + if (error === null) { + resolve(undefined); + } + else { + reject(error); + } + }); + })); + } + filesystem.delete_ = delete_; + /** + * @author fenris + */ + function read(subject, path) { + return (new Promise(function (resolve, reject) { + subject.nodemodule.readFile(path, {}, function (error, content) { + if (error === null) { + resolve(content); + } + else { + reject(error); + } + }); + })); + } + filesystem.read = read; + /** + */ + function implementation_chest(parameters) { + var subject = make(parameters); + return { + "setup": function (input) { return Promise.resolve(undefined); }, + "clear": function () { return clear(subject); }, + "write": function (key, value) { return write(subject, key, value); }, + "delete": function (key) { return delete_(subject, key); }, + "read": function (key) { return read(subject, key); }, + "search": function (term) { return Promise.reject("not available"); } + }; + } + filesystem.implementation_chest = implementation_chest; + })(filesystem = storage.filesystem || (storage.filesystem = {})); + })(storage = lib_plankton.storage || (lib_plankton.storage = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:storage« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:storage«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var storage; + (function (storage) { + var filesystem; + (function (filesystem) { + /** + * @author fenris + */ + var class_chest = /** @class */ (function () { + function class_chest(parameters) { + this.subject = filesystem.make(parameters); + } + class_chest.prototype.setup = function (input) { return Promise.resolve(undefined); }; + class_chest.prototype.clear = function () { return filesystem.clear(this.subject); }; + class_chest.prototype.write = function (key, value) { return filesystem.write(this.subject, key, value); }; + class_chest.prototype["delete"] = function (key) { return filesystem.delete_(this.subject, key); }; + class_chest.prototype.read = function (key) { return filesystem.read(this.subject, key); }; + class_chest.prototype.search = function (searchterm) { return Promise.reject(new Error("not available")); }; + return class_chest; + }()); + filesystem.class_chest = class_chest; + })(filesystem = storage.filesystem || (storage.filesystem = {})); + })(storage = lib_plankton.storage || (lib_plankton.storage = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:storage« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:storage«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var storage; + (function (storage) { + /** + */ + function sql_table_autokey_make(parameters) { + return { + "database_implementation": parameters.database_implementation, + "table_name": parameters.table_name, + "key_name": parameters.key_name + }; + } + storage.sql_table_autokey_make = sql_table_autokey_make; + /** + */ + function sql_table_autokey_setup(subject, description_create_table) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, subject.database_implementation.query_create_table(description_create_table)]; + }); + }); + } + storage.sql_table_autokey_setup = sql_table_autokey_setup; + /** + */ + function sql_table_autokey_create(subject, value) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, subject.database_implementation.query_insert({ + "table_name": subject.table_name, + "values": value + })]; + }); + }); + } + storage.sql_table_autokey_create = sql_table_autokey_create; + /** + */ + function sql_table_autokey_update(subject, key, value) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, (subject.database_implementation.query_update({ + "table_name": subject.table_name, + "values": value, + "condition": lib_plankton.string.coin("`{{key_name}}` = $key", { + "key_name": subject.key_name + }), + "arguments": { + "key": key + } + }) + .then(function (x) { return Promise.resolve(undefined); }))]; + }); + }); + } + storage.sql_table_autokey_update = sql_table_autokey_update; + /** + */ + function sql_table_autokey_delete(subject, key) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, subject.database_implementation.query_delete({ + "table_name": subject.table_name, + "condition": lib_plankton.string.coin("`{{key_name}}` = $key", { + "key_name": subject.key_name + }), + "arguments": { + "key": key + } + })]; + case 1: + _a.sent(); + return [2 /*return*/, Promise.resolve(undefined)]; + } + }); + }); + } + storage.sql_table_autokey_delete = sql_table_autokey_delete; + /** + */ + function sql_table_autokey_read(subject, key) { + return __awaiter(this, void 0, void 0, function () { + var rows; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, subject.database_implementation.query_select({ + "source": subject.table_name, + "fields": null, + "condition": lib_plankton.string.coin("`{{key_name}}` = $key", { + "key_name": subject.key_name + }), + "arguments": { + "key": key + } + })]; + case 1: + rows = _a.sent(); + if (rows.length < 1) { + return [2 /*return*/, Promise.reject("not found")]; + } + else if (rows.length > 1) { + return [2 /*return*/, Promise.reject("ambiguous")]; + } + else { + delete rows[0][subject.key_name]; + return [2 /*return*/, Promise.resolve(rows[0])]; + } + return [2 /*return*/]; + } + }); + }); + } + storage.sql_table_autokey_read = sql_table_autokey_read; + /** + * @todo correct preview + */ + function sql_table_autokey_search(subject, term) { + return __awaiter(this, void 0, void 0, function () { + var rows; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, subject.database_implementation.query_select({ + "source": subject.table_name, + "fields": null, + "condition": ((term === null) ? null : term.expression), + "arguments": ((term === null) ? null : term.arguments) + })]; + case 1: + rows = _a.sent(); + return [2 /*return*/, Promise.resolve(rows + .map(function (row) { return ({ + "key": row[subject.key_name], + "preview": row + }); }))]; + } + }); + }); + } + storage.sql_table_autokey_search = sql_table_autokey_search; + /** + */ + function sql_table_autokey_store(parameters) { + var subject = sql_table_autokey_make(parameters); + return { + "setup": function (input) { return sql_table_autokey_setup(subject, input); }, + "create": function (value) { return sql_table_autokey_create(subject, value); }, + "update": function (key, value) { return sql_table_autokey_update(subject, key, value); }, + "delete": function (key) { return sql_table_autokey_delete(subject, key); }, + "read": function (key) { return sql_table_autokey_read(subject, key); }, + "search": function (term) { return sql_table_autokey_search(subject, term); } + }; + } + storage.sql_table_autokey_store = sql_table_autokey_store; + })(storage = lib_plankton.storage || (lib_plankton.storage = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:storage« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:storage«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var storage; + (function (storage) { + /** + * @author fenris + */ + var class_sql_table_autokey = /** @class */ (function () { + function class_sql_table_autokey(parameters) { + this.subject = storage.sql_table_autokey_make(parameters); + } + class_sql_table_autokey.prototype.setup = function (input) { return storage.sql_table_autokey_setup(this.subject, input); }; + class_sql_table_autokey.prototype.create = function (value) { return storage.sql_table_autokey_create(this.subject, value); }; + class_sql_table_autokey.prototype.update = function (key, value) { return storage.sql_table_autokey_update(this.subject, key, value); }; + class_sql_table_autokey.prototype["delete"] = function (key) { return storage.sql_table_autokey_delete(this.subject, key); }; + class_sql_table_autokey.prototype.read = function (key) { return storage.sql_table_autokey_read(this.subject, key); }; + class_sql_table_autokey.prototype.search = function (term) { return storage.sql_table_autokey_search(this.subject, term); }; + return class_sql_table_autokey; + }()); + storage.class_sql_table_autokey = class_sql_table_autokey; + })(storage = lib_plankton.storage || (lib_plankton.storage = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:storage« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:storage«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var storage; + (function (storage) { + var sql_table_common; + (function (sql_table_common) { + /** + */ + function make(parameters) { + return { + "database_implementation": parameters.database_implementation, + "table_name": parameters.table_name, + "key_names": parameters.key_names + }; + } + sql_table_common.make = make; + /** + */ + function key_condition(subject, key) { + return { + "condition": lib_string.coin("({{clauses}})", { + "clauses": (subject.key_names + .map(function (key_name) { return lib_plankton.string.coin("(`{{name}}` = $key_{{name}})", { + "name": key_name + }); }) + .join(" AND ")) + }), + "arguments": Object.fromEntries(subject.key_names + .map(function (key_name, index) { return ([ + lib_plankton.string.coin("key_{{name}}", { + "name": key_name + }), + key[index] + ]); })) + }; + } + /** + */ + function setup(subject, description_create_table) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, subject.database_implementation.query_create_table(description_create_table)]; + }); + }); + } + sql_table_common.setup = setup; + /** + */ + function clear(subject) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, subject.database_implementation.query_delete({ + "table_name": subject.table_name, + "condition": "TRUE", + "arguments": {} + })]; + case 1: + _a.sent(); + return [2 /*return*/, Promise.resolve(undefined)]; + } + }); + }); + } + sql_table_common.clear = clear; + /** + * @todo optimize: avoid read + */ + function write(subject, key, value) { + return __awaiter(this, void 0, void 0, function () { + var exists, error_1, field_names, condition; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 2, , 3]); + return [4 /*yield*/, read(subject, key)]; + case 1: + _a.sent(); + exists = true; + return [3 /*break*/, 3]; + case 2: + error_1 = _a.sent(); + exists = false; + return [3 /*break*/, 3]; + case 3: + field_names = Object.keys(value); + if (!!exists) return [3 /*break*/, 5]; + return [4 /*yield*/, subject.database_implementation.query_insert({ + "table_name": subject.table_name, + "values": Object.assign( + // key + Object.fromEntries(subject.key_names.map(function (key_name, index) { return ([key_name, key[index]]); })), + // value + value) + })]; + case 4: + _a.sent(); + return [3 /*break*/, 7]; + case 5: + condition = key_condition(subject, key); + return [4 /*yield*/, subject.database_implementation.query_update({ + "table_name": subject.table_name, + "values": value, + "condition": condition.condition, + "arguments": condition.arguments + })]; + case 6: + _a.sent(); + _a.label = 7; + case 7: return [2 /*return*/, Promise.resolve(exists)]; + } + }); + }); + } + sql_table_common.write = write; + /** + */ + function delete_(subject, key) { + return __awaiter(this, void 0, void 0, function () { + var condition; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + condition = key_condition(subject, key); + return [4 /*yield*/, subject.database_implementation.query_delete({ + "table_name": subject.table_name, + "condition": condition.condition, + "arguments": condition.arguments + })]; + case 1: + _a.sent(); + return [2 /*return*/, Promise.resolve(undefined)]; + } + }); + }); + } + sql_table_common.delete_ = delete_; + /** + */ + function read(subject, key) { + return __awaiter(this, void 0, void 0, function () { + var condition, rows; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + condition = key_condition(subject, key); + return [4 /*yield*/, subject.database_implementation.query_select({ + "source": subject.table_name, + "fields": null, + "condition": condition.condition, + "arguments": condition.arguments + })]; + case 1: + rows = _a.sent(); + if (rows.length < 1) { + return [2 /*return*/, Promise.reject("not found")]; + } + else if (rows.length > 1) { + return [2 /*return*/, Promise.reject("ambiguous")]; + } + else { + subject.key_names.forEach(function (key_name) { delete rows[0][key_name]; }); + return [2 /*return*/, Promise.resolve(rows[0])]; + } + return [2 /*return*/]; + } + }); + }); + } + sql_table_common.read = read; + /** + * @todo correct preview + */ + function search(subject, term) { + return __awaiter(this, void 0, void 0, function () { + var rows; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, subject.database_implementation.query_select({ + "source": subject.table_name, + "fields": null, + "condition": ((term === null) ? null : term.expression), + "arguments": ((term === null) ? null : term.arguments) + })]; + case 1: + rows = _a.sent(); + return [2 /*return*/, Promise.resolve(rows + .map(function (row) { return ({ + "key": subject.key_names.map(function (name) { return row[name]; }), + "preview": row + }); }))]; + } + }); + }); + } + sql_table_common.search = search; + /** + */ + function chest(parameters) { + var subject = make(parameters); + return { + "setup": function (input) { return setup(subject, input); }, + "clear": function () { return clear(subject); }, + "write": function (key, value) { return write(subject, key, value); }, + "delete": function (key) { return delete_(subject, key); }, + "read": function (key) { return read(subject, key); }, + "search": function (term) { return search(subject, term); } + }; + } + sql_table_common.chest = chest; + })(sql_table_common = storage.sql_table_common || (storage.sql_table_common = {})); + })(storage = lib_plankton.storage || (lib_plankton.storage = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:storage« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:storage«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var storage; + (function (storage) { + var sql_table_common; + (function (sql_table_common) { + /** + * @author fenris + */ + var class_chest = /** @class */ (function () { + function class_chest(parameters) { + this.subject = sql_table_common.make(parameters); + } + class_chest.prototype.setup = function (input) { return sql_table_common.setup(this.subject, input); }; + class_chest.prototype.clear = function () { return sql_table_common.clear(this.subject); }; + class_chest.prototype.write = function (key, value) { return sql_table_common.write(this.subject, key, value); }; + class_chest.prototype["delete"] = function (key) { return sql_table_common.delete_(this.subject, key); }; + class_chest.prototype.read = function (key) { return sql_table_common.read(this.subject, key); }; + class_chest.prototype.search = function (term) { return sql_table_common.search(this.subject, term); }; + return class_chest; + }()); + sql_table_common.class_chest = class_chest; + })(sql_table_common = storage.sql_table_common || (storage.sql_table_common = {})); + })(storage = lib_plankton.storage || (lib_plankton.storage = {})); +})(lib_plankton || (lib_plankton = {})); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + 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 (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { diff --git a/source/helpers/password.ts b/source/helpers/password.ts new file mode 100644 index 0000000..3cda49e --- /dev/null +++ b/source/helpers/password.ts @@ -0,0 +1,325 @@ +/* +Espe | Ein schlichtes Werkzeug zur Mitglieder-Verwaltung | Backend +Copyright (C) 2024 Christian Fraß + +This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public +License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied +warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with this program. If not, see +. + */ + + +namespace _espe.helper.password +{ + + /** + */ + type char = string; + + + /** + */ + type type_settings = { + minimum_length : (null | int); + maximum_length : (null | int); + must_contain_letter : boolean; + must_contain_number : boolean; + must_contain_special_character : boolean; + }; + + + /** + */ + enum enum_character_class { + number_ = "number", + letter = "letter", + special = "special", + } + + + /** + */ + const character_classification : Record> = { + [enum_character_class.number_]: [ + 0x30, + 0x31, + 0x32, + 0x33, + 0x34, + 0x35, + 0x36, + 0x37, + 0x38, + 0x39, + ], + [enum_character_class.letter]: [ + 0x41, + 0x42, + 0x43, + 0x44, + 0x45, + 0x46, + 0x47, + 0x48, + 0x49, + 0x4A, + 0x4B, + 0x4C, + 0x4D, + 0x4E, + 0x4F, + 0x50, + 0x51, + 0x52, + 0x53, + 0x54, + 0x55, + 0x56, + 0x56, + 0x58, + 0x59, + 0x5A, + 0x61, + 0x62, + 0x63, + 0x64, + 0x65, + 0x66, + 0x67, + 0x68, + 0x69, + 0x6A, + 0x6B, + 0x6C, + 0x6D, + 0x6E, + 0x6F, + 0x70, + 0x71, + 0x72, + 0x73, + 0x74, + 0x75, + 0x76, + 0x77, + 0x78, + 0x79, + 0x7A, + ], + [enum_character_class.special]: [ + 0x20, + 0x21, + 0x22, + 0x23, + 0x24, + 0x25, + 0x26, + 0x27, + 0x28, + 0x29, + 0x2A, + 0x2B, + 0x2C, + 0x2D, + 0x2E, + 0x2F, + 0x3A, + 0x3B, + 0x3C, + 0x3D, + 0x3E, + 0x3F, + 0x40, + 0x5B, + 0x5C, + 0x5D, + 0x5E, + 0x5F, + 0x60, + 0x7B, + 0x7C, + 0x7D, + 0x7E, + ], + }; + + + /** + */ + function character_is_number( + character : char + ) : boolean + { + if (character.length !== 1) { + throw (new Error("not a character")); + } + else { + const code : int = character.charCodeAt(0); + return character_classification[enum_character_class.number_].includes(code); + } + } + + + /** + */ + function character_is_letter( + character : char + ) : boolean + { + if (character.length !== 1) { + throw (new Error("not a character")); + } + else { + const code : int = character.charCodeAt(0); + return character_classification[enum_character_class.letter].includes(code); + } + } + + + /** + */ + function character_is_special( + character : char + ) : boolean + { + if (character.length !== 1) { + throw (new Error("not a character")); + } + else { + const code : int = character.charCodeAt(0); + return character_classification[enum_character_class.special].includes(code); + } + } + + + /** + */ + export function validate( + settings : type_settings, + password : string + ) : Array<{incident : string; details : Record}> + { + let flaws : Array<{incident : string; details : Record}> = []; + const characters : Array = password.split(""); + if ( + (settings.minimum_length !== null) + && + (password.length < settings.minimum_length) + ) { + flaws.push( + { + "incident": "too_short", + "details": { + "minimum_length": settings.minimum_length, + "actual_length": password.length, + } + } + ); + } + if ( + (settings.maximum_length !== null) + && + (password.length > settings.maximum_length) + ) { + flaws.push( + { + "incident": "too_long", + "details": { + "maximum_length": settings.maximum_length, + "actual_length": password.length, + } + } + ); + } + if ( + settings.must_contain_letter + && + (! characters.some(character => character_is_letter(character))) + ) { + flaws.push( + { + "incident": "lacks_letter", + "details": { + } + } + ); + } + if ( + settings.must_contain_number + && + (! characters.some(character => character_is_number(character))) + ) { + flaws.push( + { + "incident": "lacks_number", + "details": { + } + } + ); + } + if ( + settings.must_contain_special_character + && + (! characters.some(character => character_is_special(character))) + ) { + flaws.push( + { + "incident": "lacks_special_character", + "details": { + } + } + ); + } + return flaws; + } + + + /** + */ + export function generate( + settings : type_settings + ) : string + { + const count_number : int = (settings.must_contain_number ? 1 : 0); + const count_special : int = (settings.must_contain_special_character ? 1 : 0); + const count_letter_raw : int = ((settings.minimum_length ?? 8) - count_number - count_special); + const count_letter : int = ((settings.must_contain_letter && (count_letter_raw <= 0)) ? 1 : count_letter_raw); + if ( + (settings.maximum_length !== null) + && + ((count_letter + count_number + count_special) > settings.maximum_length) + ) { + throw (new Error("impossible")); + } + else { + return lib_plankton.call.convey( + ( + ([] as Array) + .concat( + lib_plankton.list.sequence(count_letter) + .map(x => lib_plankton.random.choose_uniformly(character_classification[enum_character_class.letter])) + ) + .concat( + lib_plankton.list.sequence(count_number) + .map(x => lib_plankton.random.choose_uniformly(character_classification[enum_character_class.number_])) + ) + .concat( + lib_plankton.list.sequence(count_special) + .map(x => lib_plankton.random.choose_uniformly(character_classification[enum_character_class.special])) + ) + ), + [ + lib_plankton.random.shuffle, + (x : Array) => x.map(y => String.fromCharCode(y)), + (x : Array) => x.join(""), + ] + ); + } + } + +} diff --git a/source/services/member.ts b/source/services/member.ts index d2824a3..8ed0792 100644 --- a/source/services/member.ts +++ b/source/services/member.ts @@ -45,90 +45,26 @@ namespace _espe.service.member /** - * @todo do not export */ - export function validate_password( + function validate_password( password : string ) : Array<{incident : string; details : Record}> { - let flaws : Array<{incident : string; details : Record}> = []; - const settings : { - minimum_length : (null | int); - maximum_length : (null | int); - must_contain_letter : boolean; - must_contain_number : boolean; - must_contain_special_character : boolean; - } = _espe.conf.get().settings.password_policy; - if ( - (settings.minimum_length !== null) - && - (password.length < settings.minimum_length) - ) { - flaws.push( - { - "incident": "too_short", - "details": { - "minimum_length": settings.minimum_length, - "actual_length": password.length, - } - } - ); - } - if ( - (settings.maximum_length !== null) - && - (password.length > settings.maximum_length) - ) { - flaws.push( - { - "incident": "too_long", - "details": { - "maximum_length": settings.maximum_length, - "actual_length": password.length, - } - } - ); - } - if ( - settings.must_contain_letter - && - (! (new RegExp("[a-zA-Z]")).test(password)) - ) { - flaws.push( - { - "incident": "lacks_letter", - "details": { - } - } - ); - } - if ( - settings.must_contain_number - && - (! (new RegExp("[0-9]")).test(password)) - ) { - flaws.push( - { - "incident": "lacks_number", - "details": { - } - } - ); - } - if ( - settings.must_contain_special_character - && - (! (new RegExp("[!?-_.,;/\~%&$'()\\[\\]{}^'#|+*<>=\"`:@]")).test(password)) - ) { - flaws.push( - { - "incident": "lacks_special_character", - "details": { - } - } - ); - } - return flaws; + return _espe.helper.password.validate( + _espe.conf.get().settings.password_policy, + password + ); + } + + + /** + */ + function generate_password( + ) : string + { + return _espe.helper.password.generate( + _espe.conf.get().settings.password_policy + ); } diff --git a/source/test/data.json b/source/test/data.json index 13adc80..8dc194d 100644 --- a/source/test/data.json +++ b/source/test/data.json @@ -1,19 +1,15 @@ { - "service.member.validate_password": { + "helper.password.validate": { "cases": [ { "name": "minimum_length:pass", "input": { - "conf": { - "settings": { - "password_policy": { - "minimum_length": 5, - "maximum_length": null, - "must_contain_letter": false, - "must_contain_number": false, - "must_contain_special_character": false - } - } + "settings": { + "minimum_length": 5, + "maximum_length": null, + "must_contain_letter": false, + "must_contain_number": false, + "must_contain_special_character": false }, "password": "abcde" }, @@ -23,16 +19,12 @@ { "name": "minimum_length:fail", "input": { - "conf": { - "settings": { - "password_policy": { - "minimum_length": 5, - "maximum_length": null, - "must_contain_letter": false, - "must_contain_number": false, - "must_contain_special_character": false - } - } + "settings": { + "minimum_length": 5, + "maximum_length": null, + "must_contain_letter": false, + "must_contain_number": false, + "must_contain_special_character": false }, "password": "abcd" }, @@ -49,16 +41,12 @@ { "name": "maximum_length:pass", "input": { - "conf": { - "settings": { - "password_policy": { - "minimum_length": null, - "maximum_length": 5, - "must_contain_letter": false, - "must_contain_number": false, - "must_contain_special_character": false - } - } + "settings": { + "minimum_length": null, + "maximum_length": 5, + "must_contain_letter": false, + "must_contain_number": false, + "must_contain_special_character": false }, "password": "abcde" }, @@ -68,16 +56,12 @@ { "name": "maximum_length:fail", "input": { - "conf": { - "settings": { - "password_policy": { - "minimum_length": null, - "maximum_length": 5, - "must_contain_letter": false, - "must_contain_number": false, - "must_contain_special_character": false - } - } + "settings": { + "minimum_length": null, + "maximum_length": 5, + "must_contain_letter": false, + "must_contain_number": false, + "must_contain_special_character": false }, "password": "abcdef" }, @@ -94,16 +78,12 @@ { "name": "must_contain_letter:pass", "input": { - "conf": { - "settings": { - "password_policy": { - "minimum_length": null, - "maximum_length": null, - "must_contain_letter": true, - "must_contain_number": false, - "must_contain_special_character": false - } - } + "settings": { + "minimum_length": null, + "maximum_length": null, + "must_contain_letter": true, + "must_contain_number": false, + "must_contain_special_character": false }, "password": "01x34" }, @@ -113,16 +93,12 @@ { "name": "must_contain_letter:fail", "input": { - "conf": { - "settings": { - "password_policy": { - "minimum_length": null, - "maximum_length": null, - "must_contain_letter": true, - "must_contain_number": false, - "must_contain_special_character": false - } - } + "settings": { + "minimum_length": null, + "maximum_length": null, + "must_contain_letter": true, + "must_contain_number": false, + "must_contain_special_character": false }, "password": "01234" }, @@ -137,16 +113,12 @@ { "name": "must_contain_number:pass", "input": { - "conf": { - "settings": { - "password_policy": { - "minimum_length": null, - "maximum_length": null, - "must_contain_letter": false, - "must_contain_number": true, - "must_contain_special_character": false - } - } + "settings": { + "minimum_length": null, + "maximum_length": null, + "must_contain_letter": false, + "must_contain_number": true, + "must_contain_special_character": false }, "password": "ab0de" }, @@ -156,16 +128,12 @@ { "name": "must_contain_number:fail", "input": { - "conf": { - "settings": { - "password_policy": { - "minimum_length": null, - "maximum_length": null, - "must_contain_letter": false, - "must_contain_number": true, - "must_contain_special_character": false - } - } + "settings": { + "minimum_length": null, + "maximum_length": null, + "must_contain_letter": false, + "must_contain_number": true, + "must_contain_special_character": false }, "password": "abcde" }, @@ -180,16 +148,12 @@ { "name": "must_contain_special_character:pass", "input": { - "conf": { - "settings": { - "password_policy": { - "minimum_length": null, - "maximum_length": null, - "must_contain_letter": false, - "must_contain_number": false, - "must_contain_special_character": true - } - } + "settings": { + "minimum_length": null, + "maximum_length": null, + "must_contain_letter": false, + "must_contain_number": false, + "must_contain_special_character": true }, "password": "01.34" }, @@ -199,16 +163,12 @@ { "name": "must_contain_special_character:fail", "input": { - "conf": { - "settings": { - "password_policy": { - "minimum_length": null, - "maximum_length": null, - "must_contain_letter": false, - "must_contain_number": false, - "must_contain_special_character": true - } - } + "settings": { + "minimum_length": null, + "maximum_length": null, + "must_contain_letter": false, + "must_contain_number": false, + "must_contain_special_character": true }, "password": "01234" }, @@ -223,16 +183,12 @@ { "name": "oblique:pass", "input": { - "conf": { - "settings": { - "password_policy": { - "minimum_length": 8, - "maximum_length": 12, - "must_contain_letter": true, - "must_contain_number": true, - "must_contain_special_character": true - } - } + "settings": { + "minimum_length": 8, + "maximum_length": 12, + "must_contain_letter": true, + "must_contain_number": true, + "must_contain_special_character": true }, "password": "eiB@oo7tuu" }, @@ -276,8 +232,12 @@ "input": { "conf": { "settings": { - "target_domain": "testdomain.org", - "prefix_for_numberbased_email_addresses": "wicht-" + "organisation": { + "domain": "testdomain.org" + }, + "misc": { + "prefix_for_veiled_email_addresses": "wicht-" + } } }, "members": [ diff --git a/source/test/main.mocha.ts b/source/test/main.mocha.ts index 85355cb..ea13374 100644 --- a/source/test/main.mocha.ts +++ b/source/test/main.mocha.ts @@ -24,14 +24,14 @@ const _data : Record = lib_plankton.json.decode(nm_fs describe( - "service.member.validate_password", + "helper.password.validate", () => { const data : { cases : Array< { name : string; input : { - conf : any; + settings : any; password : string; }; output : Array< @@ -42,27 +42,56 @@ describe( >; } >; - } = _data["service.member.validate_password"]; + } = _data["helper.password.validate"]; data.cases.forEach( case_ => { it( case_.name, () => { - _espe.conf.inject(case_.input.conf); + // _espe.conf.inject(case_.input.conf); const result : Array< { incident : string; details : Record; } - > = _espe.service.member.validate_password(case_.input.password); + > = _espe.helper.password.validate(case_.input.settings, case_.input.password); nm_assert.deepEqual(result, case_.output); - _espe.conf.inject({}); + // _espe.conf.inject({}); } ); } ); } ); +/* +describe( + "helper.password.generate", + () => { + it( + "test", + () => { + lib_plankton.list.sequence(20).forEach( + () => { + process.stderr.write( + _espe.helper.password.generate( + { + "minimum_length": 8, + "maximum_length": 240, + "must_contain_letter": true, + "must_contain_number": true, + "must_contain_special_character": true, + } + ) + + + "\n" + ); + } + ); + } + ); + } +); + */ describe( "service.member.name_login", () => { @@ -95,6 +124,8 @@ describe( "email_redirect_to_private_address": false, "email_allow_sending": false, "password_image": null, + "password_change_last_attempt": null, + "password_change_token": null, }; const result : string = _espe.service.member.name_login(member_object); nm_assert.equal(result, case_.output); @@ -158,6 +189,8 @@ describe( "email_redirect_to_private_address": member_raw.email_redirect_to_private_address, "email_allow_sending": member_raw.email_allow_sending, "password_image": member_raw.password_image, + "password_change_last_attempt": null, + "password_change_token": null, } ) ), diff --git a/tools/makefile b/tools/makefile index 14bdcfd..471c6f6 100644 --- a/tools/makefile +++ b/tools/makefile @@ -45,6 +45,7 @@ node_modules: ${dir_temp}/espe-core.js ${dir_temp}/espe-core.d.ts: \ ${dir_lib}/plankton/plankton.d.ts \ ${dir_source}/helpers.ts \ + ${dir_source}/helpers/password.ts \ ${dir_source}/database.ts \ ${dir_source}/types.ts \ ${dir_source}/repositories/name_index.ts \ @@ -81,7 +82,7 @@ ${dir_temp}/espe-main-raw.js: \ ${dir_source}/main.ts @ ${cmd_log} "compile | main …" @ ${cmd_mkdir} $(dir $@) - @ tsc --lib es2020 $^ --outFile $@ + @ ${cmd_tsc} --lib es2020 $^ --outFile $@ ${dir_build}/espe: \ ${dir_source}/head.js \ @@ -109,7 +110,7 @@ ${dir_temp}/espe-test-raw.js: \ ${dir_source}/test/main.mocha.ts @ ${cmd_log} "compile | test …" @ ${cmd_mkdir} $(dir $@) - @ tsc --lib es2020 $^ --outFile $@ + @ ${cmd_tsc} --lib es2020 $^ --outFile $@ ${dir_build}/espe-test.mocha.js: \ ${dir_source}/head.js \ diff --git a/tools/update-plankton b/tools/update-plankton index 5e5f938..06d768b 100755 --- a/tools/update-plankton +++ b/tools/update-plankton @@ -7,7 +7,9 @@ dir=lib/plankton modules="" modules="${modules} base" modules="${modules} call" +modules="${modules} list" modules="${modules} file" +modules="${modules} random" modules="${modules} sha256" modules="${modules} database" modules="${modules} storage"