From 901fab3ac4ad20dcbae601cb42d344b60228ea8a Mon Sep 17 00:00:00 2001 From: Fenris Wolf Date: Sat, 21 Sep 2024 10:55:06 +0200 Subject: [PATCH] [upd] plankton --- lib/plankton/plankton.d.ts | 163 ++++++++++++- lib/plankton/plankton.js | 488 ++++++++++++++++++++++++++++++++++++- tools/update-plankton | 1 + 3 files changed, 641 insertions(+), 11 deletions(-) diff --git a/lib/plankton/plankton.d.ts b/lib/plankton/plankton.d.ts index 40d1a07..f0d5ebc 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; }; @@ -45,7 +45,7 @@ declare namespace lib_plankton.base { /** * @author fenris */ -type type_pseudopointer = { +declare type type_pseudopointer = { value: type_value; }; /** @@ -2209,7 +2209,7 @@ declare namespace lib_plankton.storage.memory { clear(): Promise; write(key: any, value: any): Promise; delete(key: any): Promise; - read(key: any): Promise>; + read(key: any): Promise; search(term: any): Promise<{ key: string; preview: string; @@ -4187,6 +4187,155 @@ declare namespace lib_plankton.bcrypt { */ function compare(password_shall_image: string, password_is: string): Promise; } +declare namespace lib_plankton.map { + /** + */ + type type_pair = { + key: type_key; + value: type_value; + }; + /** + * @author fenris + */ + type type_map = { + size: (() => int); + has: ((key: type_key) => boolean); + get: ((key: type_key, fallback?: lib_plankton.pod.type_pod) => type_value); + set: ((key: type_key, value: type_value) => void); + delete: ((key: type_key) => void); + iterate: ((procedure: ((value: type_value, key?: type_key) => void)) => void); + }; +} +declare namespace lib_plankton.map { + /** + */ + function clear(map: type_map): void; + /** + */ + function keys(map: type_map): Array; + /** + */ + function values(map: type_map): Array; + /** + */ + function dump(map: type_map): Array>; + /** + */ + function show(map: type_map, options?: { + show_key?: ((key: type_key) => string); + show_value?: ((value: type_value) => string); + }): string; +} +declare namespace lib_plankton.map.simplemap { + /** + */ + type type_subject = { + data: Record; + }; + /** + */ + function make(options?: { + data?: Record; + }): type_subject; + /** + */ + function size(subject: type_subject): int; + /** + */ + function has(subject: type_subject, key: string): boolean; + /** + */ + function get_safe(subject: type_subject, key: string): lib_plankton.pod.type_pod; + /** + */ + function get(subject: type_subject, key: string, fallback?: lib_plankton.pod.type_pod): type_value; + /** + */ + function set(subject: type_subject, key: string, value: type_value): void; + /** + */ + function delete_(subject: type_subject, key: string): void; + /** + */ + function iterate(subject: type_subject, procedure: ((value?: type_value, key?: string) => void)): void; + /** + */ + function implementation_map(subject: type_subject): type_map; +} +declare namespace lib_plankton.map.hashmap { + /** + * we base the hashmap on a simplemap, whos keys are the hashes and whos values are the key/value-pairs + */ + type type_subject = { + hashing: ((key: type_key) => string); + core: lib_plankton.map.simplemap.type_subject>; + }; + /** + */ + function make(hashing: ((key: type_key) => string), options?: { + pairs?: Array>; + }): type_subject; + /** + */ + function size(subject: type_subject): int; + /** + */ + function has(subject: type_subject, key: type_key): boolean; + /** + */ + function get(subject: type_subject, key: type_key, fallback?: lib_plankton.pod.type_pod): type_value; + /** + */ + function set(subject: type_subject, key: type_key, value: type_value): void; + /** + */ + function delete_(subject: type_subject, key: type_key): void; + /** + */ + function iterate(subject: type_subject, procedure: ((value?: type_value, key?: type_key) => void)): void; + /** + */ + function implementation_map(subject: type_subject): type_map; +} +declare namespace lib_plankton.map.collatemap { + /** + */ + type type_collation = ((key1: type_key, key2: type_key) => boolean); + /** + */ + export type type_subject = { + collation: type_collation; + pairs: Array>; + }; + /** + */ + export function make(collation: type_collation, options?: { + pairs?: Array>; + }): type_subject; + /** + */ + export function size(subject: type_subject): int; + /** + */ + export function has(subject: type_subject, key: type_key): boolean; + /** + * @todo use .find + */ + export function get(subject: type_subject, key: type_key, fallback?: lib_plankton.pod.type_pod): type_value; + /** + */ + export function set(subject: type_subject, key: type_key, value: type_value): void; + /** + */ + export function delete_(subject: type_subject, key: type_key): void; + /** + */ + export function iterate(subject: type_subject, function_: ((value?: type_value, key?: type_key) => void)): void; + /** + */ + export function implementation_map(subject: type_subject): type_map; + export {}; +} declare namespace lib_plankton.base64 { /** * @author fenris diff --git a/lib/plankton/plankton.js b/lib/plankton/plankton.js index 4fa30eb..98156c2 100644 --- a/lib/plankton/plankton.js +++ b/lib/plankton/plankton.js @@ -1568,7 +1568,7 @@ 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]) { @@ -6564,7 +6564,7 @@ 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]) { @@ -9886,7 +9886,7 @@ 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]) { @@ -14462,7 +14462,7 @@ 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]) { @@ -14560,6 +14560,486 @@ var lib_plankton; })(bcrypt = lib_plankton.bcrypt || (lib_plankton.bcrypt = {})); })(lib_plankton || (lib_plankton = {})); /* +This file is part of »bacterio-plankton:map«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:map« 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:map« 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:map«. If not, see . + */ +/* +This file is part of »bacterio-plankton:map«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:map« 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:map« 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:map«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var map; + (function (map_1) { + /** + */ + function clear(map) { + map.iterate(function (value, key) { + map["delete"](key); + }); + } + map_1.clear = clear; + /** + */ + function keys(map) { + var keys = []; + map.iterate(function (value, key) { + keys.push(key); + }); + return keys; + } + map_1.keys = keys; + /** + */ + function values(map) { + var values = []; + map.iterate(function (value, key) { + values.push(value); + }); + return values; + } + map_1.values = values; + /** + */ + function dump(map) { + var pairs = []; + map.iterate(function (value, key) { + pairs.push({ "key": key, "value": value }); + }); + return pairs; + } + map_1.dump = dump; + /** + */ + function show(map, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "show_key": instance_show, + "show_value": instance_show + }, options); + return ("[" + + + (dump(map) + .map(function (_a) { + var key = _a["key"], value = _a["value"]; + return (options.show_key(key) + + + " -> " + + + options.show_value(value)); + }) + .join(", ")) + + + "]"); + } + map_1.show = show; + })(map = lib_plankton.map || (lib_plankton.map = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:map«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:map« 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:map« 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:map«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var map; + (function (map) { + var simplemap; + (function (simplemap) { + /** + */ + function make(options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "data": {} + }, options); + return { + "data": options.data + }; + } + simplemap.make = make; + /** + */ + function size(subject) { + return Object.keys(subject.data).length; + } + simplemap.size = size; + /** + */ + function has(subject, key) { + return (key in subject.data); + } + simplemap.has = has; + /** + */ + function get_safe(subject, key) { + if (key in subject.data) { + return lib_plankton.pod.make_filled(subject.data[key]); + } + else { + return lib_plankton.pod.make_empty(); + } + } + simplemap.get_safe = get_safe; + /** + */ + function get(subject, key, fallback) { + if (fallback === void 0) { fallback = lib_plankton.pod.make_empty(); } + if (key in subject.data) { + return subject.data[key]; + } + else { + if (!lib_plankton.pod.is_filled(fallback)) { + throw (new Error("key not found")); + } + else { + return lib_plankton.pod.cull(fallback); + } + } + } + simplemap.get = get; + /** + */ + function set(subject, key, value) { + subject.data[key] = value; + } + simplemap.set = set; + /** + */ + function delete_(subject, key) { + delete subject.data[key]; + } + simplemap.delete_ = delete_; + /** + */ + function iterate(subject, procedure) { + Object.entries(subject.data).forEach(function (_a) { + var key = _a[0], value = _a[1]; + procedure(value, key); + }); + } + simplemap.iterate = iterate; + /** + */ + function implementation_map(subject) { + return { + "size": function () { return size(subject); }, + "has": function (key) { return has(subject, key); }, + "get": function (key, fallback) { return get(subject, key, fallback); }, + "set": function (key, value) { return set(subject, key, value); }, + "delete": function (key) { return delete_(subject, key); }, + "iterate": function (function_) { return iterate(subject, function_); } + }; + } + simplemap.implementation_map = implementation_map; + })(simplemap = map.simplemap || (map.simplemap = {})); + })(map = lib_plankton.map || (lib_plankton.map = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:map«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:map« 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:map« 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:map«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var map; + (function (map) { + var hashmap; + (function (hashmap) { + /** + */ + function make(hashing, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "pairs": [] + }, options); + var subject = { + "hashing": hashing, + "core": lib_plankton.map.simplemap.make({}) + }; + options.pairs.forEach(function (pair) { + set(subject, pair.key, pair.value); + }); + return subject; + } + hashmap.make = make; + /** + */ + function size(subject) { + return lib_plankton.map.simplemap.size(subject.core); + } + hashmap.size = size; + /** + */ + function has(subject, key) { + return lib_plankton.map.simplemap.has(subject.core, subject.hashing(key)); + } + hashmap.has = has; + /** + */ + function get(subject, key, fallback) { + if (fallback === void 0) { fallback = lib_plankton.pod.make_empty(); } + /* + we have to adjust the fallback argument, so that it can be used in our underlying simplemap core + therefore we pack the value together with any key as dummy + */ + return (lib_plankton.map.simplemap.get(subject.core, subject.hashing(key), lib_plankton.pod.propagate(fallback, function (value) { return ({ + "key": key, + "value": value + }); })) + .value); + } + hashmap.get = get; + /** + */ + function set(subject, key, value) { + var key_ = subject.hashing(key); + return (lib_plankton.map.simplemap.set(subject.core, key_, { "key": key, "value": value })); + } + hashmap.set = set; + /** + */ + function delete_(subject, key) { + return (lib_plankton.map.simplemap.delete_(subject.core, subject.hashing(key))); + } + hashmap.delete_ = delete_; + /** + */ + function iterate(subject, procedure) { + return (lib_plankton.map.simplemap.iterate(subject.core, function (_a, key_) { + var key = _a["key"], value = _a["value"]; + procedure(value, key); + })); + } + hashmap.iterate = iterate; + /** + */ + function implementation_map(subject) { + return { + "size": function () { return size(subject); }, + "has": function (key) { return has(subject, key); }, + "get": function (key, fallback) { return get(subject, key, fallback); }, + "set": function (key, value) { return set(subject, key, value); }, + "delete": function (key) { return delete_(subject, key); }, + "iterate": function (procedure) { return iterate(subject, procedure); } + }; + } + hashmap.implementation_map = implementation_map; + })(hashmap = map.hashmap || (map.hashmap = {})); + })(map = lib_plankton.map || (lib_plankton.map = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:map«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:map« 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:map« 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 +3GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:map«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var map; + (function (map) { + var collatemap; + (function (collatemap) { + /** + */ + function make(collation, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "pairs": [] + }, options); + var subject = { + "collation": collation, + "pairs": [] + }; + options.pairs.forEach(function (pair) { + set(subject, pair.key, pair.value); + }); + return subject; + } + collatemap.make = make; + /** + */ + function size(subject) { + return subject.pairs.length; + } + collatemap.size = size; + /** + */ + function has(subject, key) { + return (subject.pairs.some(function (pair) { return subject.collation(key, pair.key); })); + } + collatemap.has = has; + /** + * @todo use .find + */ + function get(subject, key, fallback) { + var value; + var found = (subject.pairs + .some(function (pair) { + if (subject.collation(key, pair.key)) { + value = pair.value; + return true; + } + else { + return false; + } + })); + if (found) { + return value; + } + else { + if (!lib_plankton.pod.is_filled(fallback)) { + throw (new Error("key not found")); + } + else { + return lib_plankton.pod.cull(fallback); + } + } + } + collatemap.get = get; + /** + */ + function set(subject, key, value) { + var found = (subject.pairs + .some(function (pair) { + if (subject.collation(key, pair.key)) { + // pair.value = value; + return true; + } + else { + return false; + } + })); + if (found) { + // nothing + } + else { + subject.pairs.push({ + "key": key, + "value": value + }); + } + } + collatemap.set = set; + /** + */ + function delete_(subject, key) { + var index; + var found = (subject.pairs + .some(function (pair, index_) { + if (subject.collation(key, pair.key)) { + index = index_; + return true; + } + else { + return false; + } + })); + if (found) { + subject.pairs.splice(index, 1); + } + else { + // do nothing + } + } + collatemap.delete_ = delete_; + /** + */ + function iterate(subject, function_) { + subject.pairs + .forEach(function (pair) { + function_(pair.value, pair.key); + }); + } + collatemap.iterate = iterate; + /** + */ + function implementation_map(subject) { + return { + "size": function () { return size(subject); }, + "has": function (key) { return has(subject, key); }, + "get": function (key, fallback) { return get(subject, key, fallback); }, + "set": function (key, value) { return set(subject, key, value); }, + "delete": function (key) { return delete_(subject, key); }, + "iterate": function (function_) { return iterate(subject, function_); } + }; + } + collatemap.implementation_map = implementation_map; + })(collatemap = map.collatemap || (map.collatemap = {})); + })(map = lib_plankton.map || (lib_plankton.map = {})); +})(lib_plankton || (lib_plankton = {})); +/* This file is part of »bacterio-plankton:base64«. Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' diff --git a/tools/update-plankton b/tools/update-plankton index 8d932fd..8dba347 100755 --- a/tools/update-plankton +++ b/tools/update-plankton @@ -24,6 +24,7 @@ modules="${modules} rest" modules="${modules} server" modules="${modules} args" modules="${modules} bcrypt" +modules="${modules} map" modules="${modules} auth"