[upd] plankton
This commit is contained in:
parent
057b682bdc
commit
c53837ebfe
53
lib/plankton/plankton.d.ts
vendored
53
lib/plankton/plankton.d.ts
vendored
|
|
@ -1,11 +1,11 @@
|
||||||
/**
|
/**
|
||||||
* @author fenris
|
* @author fenris
|
||||||
*/
|
*/
|
||||||
declare type int = number;
|
type int = number;
|
||||||
/**
|
/**
|
||||||
* @author fenris
|
* @author fenris
|
||||||
*/
|
*/
|
||||||
declare type float = number;
|
type float = number;
|
||||||
declare class Buffer {
|
declare class Buffer {
|
||||||
constructor(x: string, modifier?: string);
|
constructor(x: string, modifier?: string);
|
||||||
toString(modifier?: string): string;
|
toString(modifier?: string): string;
|
||||||
|
|
@ -19,7 +19,7 @@ declare namespace lib_plankton.base {
|
||||||
/**
|
/**
|
||||||
* @author fenris
|
* @author fenris
|
||||||
*/
|
*/
|
||||||
declare type type_pseudopointer<type_value> = {
|
type type_pseudopointer<type_value> = {
|
||||||
value: type_value;
|
value: type_value;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
|
|
@ -1969,7 +1969,7 @@ declare namespace lib_plankton.storage.memory {
|
||||||
clear(): Promise<void>;
|
clear(): Promise<void>;
|
||||||
write(key: any, value: any): Promise<boolean>;
|
write(key: any, value: any): Promise<boolean>;
|
||||||
delete(key: any): Promise<void>;
|
delete(key: any): Promise<void>;
|
||||||
read(key: any): Promise<type_item>;
|
read(key: any): Promise<Awaited<type_item>>;
|
||||||
search(term: any): Promise<{
|
search(term: any): Promise<{
|
||||||
key: string;
|
key: string;
|
||||||
preview: string;
|
preview: string;
|
||||||
|
|
@ -2693,6 +2693,51 @@ declare namespace lib_plankton.map.collatemap {
|
||||||
export function implementation_map<type_key, type_value>(subject: type_subject<type_key, type_value>): type_map<type_key, type_value>;
|
export function implementation_map<type_key, type_value>(subject: type_subject<type_key, type_value>): type_map<type_key, type_value>;
|
||||||
export {};
|
export {};
|
||||||
}
|
}
|
||||||
|
declare namespace lib_plankton.cache {
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
type type_result<type_value> = {
|
||||||
|
retrieved: boolean;
|
||||||
|
value: type_value;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
type type_entry<type_value> = {
|
||||||
|
value: type_value;
|
||||||
|
expiry: (null | float);
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
type type_subject<type_value> = lib_plankton.storage.type_chest<string, type_entry<type_value>, void, any, any>;
|
||||||
|
}
|
||||||
|
declare namespace lib_plankton.cache {
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function make<type_value>({ "chest": chest, }?: {
|
||||||
|
chest?: lib_plankton.storage.type_chest<string, type_entry<type_value>, void, any, any>;
|
||||||
|
}): type_subject<type_value>;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function init<type_value>(subject: type_subject<type_value>): Promise<void>;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function clear<type_value>(subject: type_subject<type_value>): Promise<void>;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function invalidate<type_value>(subject: type_subject<type_value>, key: string): Promise<void>;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function query<type_value>(subject: type_subject<type_value>, key: string, lifetime: (null | float), retrieve: (() => Promise<type_value>)): Promise<type_result<type_value>>;
|
||||||
|
/**
|
||||||
|
* syntactic sugar: if the information, whether the value was retrieved, is irrelevant
|
||||||
|
*/
|
||||||
|
function get<type_value>(subject: type_subject<type_value>, key: string, lifetime: (null | float), retrieve: (() => Promise<type_value>)): Promise<type_value>;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function get_complex<type_input, type_value>(cache: type_subject<type_value>, group: string, input: type_input, lifetime: (null | float), retrieve: ((input: type_input) => Promise<type_value>), { "encode_input": encode_input, }?: {
|
||||||
|
encode_input?: ((input: type_input) => string);
|
||||||
|
}): Promise<type_value>;
|
||||||
|
}
|
||||||
declare namespace lib_plankton.complex {
|
declare namespace lib_plankton.complex {
|
||||||
/**
|
/**
|
||||||
* @author fenris
|
* @author fenris
|
||||||
|
|
|
||||||
|
|
@ -2151,7 +2151,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||||
function step(op) {
|
function step(op) {
|
||||||
if (f) throw new TypeError("Generator is already executing.");
|
if (f) throw new TypeError("Generator is already executing.");
|
||||||
while (_) try {
|
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 (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||||
switch (op[0]) {
|
switch (op[0]) {
|
||||||
|
|
@ -8710,6 +8710,136 @@ var lib_plankton;
|
||||||
})(map = lib_plankton.map || (lib_plankton.map = {}));
|
})(map = lib_plankton.map || (lib_plankton.map = {}));
|
||||||
})(lib_plankton || (lib_plankton = {}));
|
})(lib_plankton || (lib_plankton = {}));
|
||||||
/*
|
/*
|
||||||
|
This file is part of »bacterio-plankton:cache«.
|
||||||
|
|
||||||
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||||
|
<info@greenscale.de>
|
||||||
|
|
||||||
|
»bacterio-plankton:cache« 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:cache« 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:cache«. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
This file is part of »bacterio-plankton:cache«.
|
||||||
|
|
||||||
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||||
|
<info@greenscale.de>
|
||||||
|
|
||||||
|
»bacterio-plankton:cache« 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:cache« 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:cache«. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
var lib_plankton;
|
||||||
|
(function (lib_plankton) {
|
||||||
|
var cache;
|
||||||
|
(function (cache_1) {
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function make({ "chest": chest = lib_plankton.storage.memory.implementation_chest({}), } = {}) {
|
||||||
|
return chest;
|
||||||
|
}
|
||||||
|
cache_1.make = make;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function init(subject) {
|
||||||
|
return subject.setup(undefined);
|
||||||
|
}
|
||||||
|
cache_1.init = init;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function clear(subject) {
|
||||||
|
return subject.clear();
|
||||||
|
}
|
||||||
|
cache_1.clear = clear;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function invalidate(subject, key) {
|
||||||
|
return subject.delete(key);
|
||||||
|
}
|
||||||
|
cache_1.invalidate = invalidate;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
async function query(subject, key, lifetime, retrieve) {
|
||||||
|
const now = lib_plankton.base.get_current_timestamp();
|
||||||
|
return ((subject.read(key)
|
||||||
|
.then((entry) => Promise.resolve({
|
||||||
|
"found": true,
|
||||||
|
"entry": entry,
|
||||||
|
}))
|
||||||
|
.catch(() => Promise.resolve({
|
||||||
|
"found": false,
|
||||||
|
"entry": null,
|
||||||
|
})))
|
||||||
|
.then((item) => {
|
||||||
|
if ((!item.found)
|
||||||
|
||
|
||||||
|
((item.entry.expiry !== null)
|
||||||
|
&&
|
||||||
|
(item.entry.expiry <= now))) {
|
||||||
|
lib_plankton.log.info("plankton.cache.unknown_or_expired", {
|
||||||
|
"key": key,
|
||||||
|
});
|
||||||
|
return (retrieve()
|
||||||
|
.then((value) => (subject.write(key, {
|
||||||
|
"value": value,
|
||||||
|
"expiry": ((lifetime === null)
|
||||||
|
?
|
||||||
|
null
|
||||||
|
:
|
||||||
|
(now + lifetime))
|
||||||
|
})
|
||||||
|
.then(() => Promise.resolve({
|
||||||
|
"retrieved": true,
|
||||||
|
"value": value
|
||||||
|
})))));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lib_plankton.log.info("plankton.cache.known_and_valid", {
|
||||||
|
"key": key,
|
||||||
|
});
|
||||||
|
return Promise.resolve({
|
||||||
|
"retrieved": false,
|
||||||
|
"value": item.entry.value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
cache_1.query = query;
|
||||||
|
/**
|
||||||
|
* syntactic sugar: if the information, whether the value was retrieved, is irrelevant
|
||||||
|
*/
|
||||||
|
function get(subject, key, lifetime, retrieve) {
|
||||||
|
return (query(subject, key, lifetime, retrieve)
|
||||||
|
.then(result => Promise.resolve(result.value)));
|
||||||
|
}
|
||||||
|
cache_1.get = get;
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function get_complex(cache, group, input, lifetime, retrieve, { "encode_input": encode_input = (input => JSON.stringify(input)), } = {}) {
|
||||||
|
return get(cache, (group + "." + encode_input(input)), lifetime, () => retrieve(input));
|
||||||
|
}
|
||||||
|
cache_1.get_complex = get_complex;
|
||||||
|
})(cache = lib_plankton.cache || (lib_plankton.cache = {}));
|
||||||
|
})(lib_plankton || (lib_plankton = {}));
|
||||||
|
/*
|
||||||
This file is part of »bacterio-plankton:complex«.
|
This file is part of »bacterio-plankton:complex«.
|
||||||
|
|
||||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||||
|
|
@ -9449,6 +9579,12 @@ var lib_plankton;
|
||||||
* @author fenris
|
* @author fenris
|
||||||
*/
|
*/
|
||||||
class class_relation {
|
class class_relation {
|
||||||
|
/**
|
||||||
|
* @author fenris
|
||||||
|
*/
|
||||||
|
check(value, reference) {
|
||||||
|
return this.predicate(value, reference);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @author fenris
|
* @author fenris
|
||||||
*/
|
*/
|
||||||
|
|
@ -9458,12 +9594,6 @@ var lib_plankton;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* @author fenris
|
|
||||||
*/
|
|
||||||
check(value, reference) {
|
|
||||||
return this.predicate(value, reference);
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* @author fenris
|
* @author fenris
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue