[add] client
Christian Fraß authored 3 years ago
|
1) /*
2) This file is part of »bacterio-plankton:shape«.
3)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
4) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
5) <info@greenscale.de>
6)
7) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
8) it under the terms of the GNU Lesser General Public License as published by
9) the Free Software Foundation, either version 3 of the License, or
10) (at your option) any later version.
11)
12) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
13) but WITHOUT ANY WARRANTY; without even the implied warranty of
14) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15) GNU Lesser General Public License for more details.
16)
17) You should have received a copy of the GNU Lesser General Public License
18) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
19) */
20) var lib_shape;
21) (function (lib_shape) {
22) /**
23) * @author fenris
24) */
25) var _pool = {};
26) /**
27) * @author fenris
28) */
29) var _aliases = {};
30) /**
31) * @author fenris
32) */
33) function list() {
34) return [].concat(Object.keys(_pool)).concat(Object.keys(_aliases));
35) }
36) lib_shape.list = list;
37) /**
38) * @author fenris
39) */
40) function inspection_create() {
41) return {
42) "messages": []
43) };
44) }
45) lib_shape.inspection_create = inspection_create;
46) /**
47) * @author fenris
48) */
49) function inspection_add(main, message) {
50) main.messages.push(message);
51) }
52) lib_shape.inspection_add = inspection_add;
53) /**
54) * @author fenris
55) */
56) function inspection_extend(main, prefix, sub) {
57) main.messages = main.messages.concat(sub.messages.map(message => `${prefix}: ${message}`));
58) }
59) lib_shape.inspection_extend = inspection_extend;
60) /**
61) * @author fenris
62) * @todo check for existing
63) */
64) function register({ "name": name, "make": make, "inspect": _inspect, "stance": _stance, "show": _show, }) {
65) const entry = {
66) "name": name,
67) "make": make,
68) "inspect": _inspect,
69) "stance": _stance,
70) "show": _show,
71) };
72) _pool[name] = entry;
73) }
74) lib_shape.register = register;
75) /**
76) * @author fenris
77) * @todo check for existing
78) */
79) function define_alias({ "name": name, "target": target, }) {
80) const entry = {
81) "name": "alias",
82) "target": target,
83) };
84) _aliases[name] = entry;
85) }
86) lib_shape.define_alias = define_alias;
87) /**
88) * @author fenris
89) * @todo check for existing
90) */
91) /*
92) export function inspect_jstype(
93) inspection,
94) jstype_expected : string,
95) value : any
96) ) : void {
97) let jstype_actual : string = typeof(value);
98) if (jstype_actual === jstype_expected) {
99) // all good
100) }
101) else {
102) inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
103) }
104) }
105) */
106) /**
107) * @author fenris
108) */
109) function make(raw) {
110) const name = raw["name"];
111) if (_aliases.hasOwnProperty(name)) {
112) const alias = _aliases[name];
113) return alias.target;
114) }
115) else {
116) if (_pool.hasOwnProperty(name)) {
117) const entry = _pool[name];
118) const parameters = entry.make(raw["parameters"] || {}, make);
119) return {
120) "name": name,
121) "parameters": parameters,
122) };
123) }
124) else {
125) const message = `no shape registered with name '${name}'`;
126) throw (new Error(message));
127) }
128) }
129) }
130) lib_shape.make = make;
131) /**
132) * @author fenris
133) */
134) function inspect(shape, value) {
135) if (_pool.hasOwnProperty(shape.name)) {
136) const entry = _pool[shape.name];
137) return entry.inspect(shape.parameters, value, inspect);
138) }
139) else {
140) const message = `no shape registered with name '${shape.name}'`;
141) throw (new Error(message));
142) }
143) }
144) lib_shape.inspect = inspect;
145) /**
146) * @author fenris
147) */
148) function check(shape, value) {
149) if (_pool.hasOwnProperty(shape.name)) {
150) const entry = _pool[shape.name];
151) const inspection = inspect(shape, value);
152) inspection.messages
153) .forEach((message) => { console.warn(message); });
154) return (inspection.messages.length === 0);
155) }
156) else {
157) const message = `no shape registered with name '${shape.name}'`;
158) throw (new Error(message));
159) }
160) }
161) lib_shape.check = check;
162) /**
163) * @author fenris
164) */
165) function stance(shape, bindings) {
166) if (_pool.hasOwnProperty(shape.name)) {
167) const entry = _pool[shape.name];
168) return entry.stance(shape.parameters, bindings, stance);
169) }
170) else {
171) const message = `no shape registered with name '${shape.name}'`;
172) throw (new Error(message));
173) }
174) }
175) lib_shape.stance = stance;
176) /**
177) * @author fenris
178) */
179) function show(shape) {
180) if (_pool.hasOwnProperty(shape.name)) {
181) const entry = _pool[shape.name];
182) return entry.show(shape.parameters, show);
183) }
184) else {
185) const message = `no shape registered with name '${shape.name}'`;
186) throw (new Error(message));
187) }
188) }
189) lib_shape.show = show;
190) })(lib_shape || (lib_shape = {}));
191) /*
192) This file is part of »bacterio-plankton:shape«.
193)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
194) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
195) <info@greenscale.de>
196)
197) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
198) it under the terms of the GNU Lesser General Public License as published by
199) the Free Software Foundation, either version 3 of the License, or
200) (at your option) any later version.
201)
202) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
203) but WITHOUT ANY WARRANTY; without even the implied warranty of
204) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
205) GNU Lesser General Public License for more details.
206)
207) You should have received a copy of the GNU Lesser General Public License
208) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
209) */
210) var lib_shape;
211) (function (lib_shape) {
212) /**
213) * @author fenris
214) */
215) function variable_make({ "name": name }) {
216) if (name == undefined) {
217) let message = `mandatory parameter 'name' missing`;
218) throw (new Error(message));
219) }
220) else {
221) return {
222) "name": name,
223) };
224) }
225) }
226) /**
227) * @author fenris
228) */
229) function variable_inspect(parameters, value, _inspect) {
230) let inspection = lib_shape.inspection_create();
231) let message = "cannot inspect a value against a type variable";
232) console.warn(message + "; will just pass ...");
233) // throw (new Error(message));
234) return inspection;
235) }
236) /**
237) * @author fenris
238) */
239) function variable_stance(parameters, bindings, _stance) {
240) if (parameters.name in bindings) {
241) return bindings[parameters.name];
242) }
243) else {
244) return {
245) "name": "variable",
246) "parameters": parameters
247) };
248) }
249) }
250) /**
251) * @author fenris
252) */
253) function variable_show(parameters, _show) {
254) let str;
255) // core
256) {
257) str = ("$" + parameters.name);
258) }
259) return str;
260) }
261) /**
262) * @author fenris
263) */
264) lib_shape.register({
265) "name": "variable",
266) "make": variable_make,
267) "inspect": variable_inspect,
268) "stance": variable_stance,
269) "show": variable_show,
270) });
271) })(lib_shape || (lib_shape = {}));
272) /*
273) This file is part of »bacterio-plankton:shape«.
274)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
275) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
276) <info@greenscale.de>
277)
278) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
279) it under the terms of the GNU Lesser General Public License as published by
280) the Free Software Foundation, either version 3 of the License, or
281) (at your option) any later version.
282)
283) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
284) but WITHOUT ANY WARRANTY; without even the implied warranty of
285) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
286) GNU Lesser General Public License for more details.
287)
288) You should have received a copy of the GNU Lesser General Public License
289) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
290) */
291) var lib_shape;
292) (function (lib_shape) {
293) /**
294) * @author fenris
295) */
296) function function_make({ "soft": soft = false, "shape_input": shape_input, "shape_output": shape_output, "defaultvalue": defaultvalue = undefined, }, _make) {
297) if (shape_input === undefined) {
298) let message = `mandatory parameter 'shape_input' missing`;
299) throw (new Error(message));
300) }
301) if (shape_output === undefined) {
302) let message = `mandatory parameter 'shape_output' missing`;
303) throw (new Error(message));
304) }
305) if (defaultvalue === undefined) {
306) defaultvalue = (soft ? null : (x => x));
307) }
308) return {
309) "soft": soft,
310) "shape_input": _make(shape_input),
311) "shape_output": _make(shape_output),
312) "defaultvalue": defaultvalue,
313) };
314) }
315) /**
316) * @author fenris
317) */
318) function function_stance(parameters, bindings, _stance) {
319) return {
320) "name": "function",
321) "parameters": {
322) "soft": parameters.soft,
323) "shape_input": _stance(parameters.shape_input, bindings),
324) "shape_output": _stance(parameters.shape_output, bindings)
325) }
326) };
327) }
328) /**
329) * @author fenris
330) * @todo closer look not possible?
331) */
332) function function_inspect(parameters, value, _inspect) {
333) let inspection = lib_shape.inspection_create();
334) if (value == undefined) {
335) if (parameters.soft) {
336) // all good
337) }
338) else {
339) lib_shape.inspection_add(inspection, "null is not allowed");
340) }
341) }
342) else {
343) let jstype_actual = typeof (value);
344) let jstype_expected = "function";
345) if (jstype_actual === jstype_expected) {
346) // all good?
347) }
348) else {
349) lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
350) }
351) }
352) return inspection;
353) }
354) /**
355) * @author fenris
356) */
357) function function_show(parameters, _show) {
358) let str;
359) /*
360) // core
361) {
362) str = "function";
363) }
364) // in/out
365) {
366) str += (
367) "<"
368) +
369) [
370) _show(parameters.shape_input),
371) _show(parameters.shape_output),
372) ].join(",")
373) +
374) ">"
375) );
376) }
377) */
378) str = "";
379) str += ("(" + _show(parameters.shape_input) + " => " + _show(parameters.shape_output) + ")");
380) // soft
381) {
382) if (parameters.soft) {
383) str = `~${str}`;
384) }
385) }
386) return str;
387) }
388) /**
389) * @author fenris
390) */
391) lib_shape.register({
392) "name": "function",
393) "make": function_make,
394) "inspect": function_inspect,
395) "stance": function_stance,
396) "show": function_show,
397) });
398) })(lib_shape || (lib_shape = {}));
399) /*
400) This file is part of »bacterio-plankton:shape«.
401)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
402) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
403) <info@greenscale.de>
404)
405) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
406) it under the terms of the GNU Lesser General Public License as published by
407) the Free Software Foundation, either version 3 of the License, or
408) (at your option) any later version.
409)
410) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
411) but WITHOUT ANY WARRANTY; without even the implied warranty of
412) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
413) GNU Lesser General Public License for more details.
414)
415) You should have received a copy of the GNU Lesser General Public License
416) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
417) */
418) var lib_shape;
419) (function (lib_shape) {
420) /**
421) * @author fenris
422) */
423) function void_make({ "soft": soft = true, }) {
424) return {
425) "soft": soft,
426) };
427) }
428) /**
429) * @author fenris
430) */
431) function void_inspect(parameters, value, _inspect) {
432) let inspection = lib_shape.inspection_create();
433) if (value == undefined) {
434) if (parameters.soft) {
435) // all good
436) }
437) else {
438) lib_shape.inspection_add(inspection, "null is not allowed");
439) }
440) }
441) else {
442) // all good
443) }
444) return inspection;
445) }
446) /**
447) * @author fenris
448) */
449) function void_stance(parameters, bindings, _stance) {
450) return {
451) "name": "void",
452) "parameters": parameters
453) };
454) }
455) /**
456) * @author fenris
457) */
458) function void_show(parameters, _show) {
459) let str;
460) // core
461) {
462) str = "void";
463) }
464) // soft
465) {
466) if (parameters.soft) {
467) str = `~${str}`;
468) }
469) }
470) return str;
471) }
472) /**
473) * @author fenris
474) */
475) lib_shape.register({
476) "name": "void",
477) "make": void_make,
478) "inspect": void_inspect,
479) "stance": void_stance,
480) "show": void_show,
481) });
482) })(lib_shape || (lib_shape = {}));
483) /*
484) This file is part of »bacterio-plankton:shape«.
485)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
486) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
487) <info@greenscale.de>
488)
489) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
490) it under the terms of the GNU Lesser General Public License as published by
491) the Free Software Foundation, either version 3 of the License, or
492) (at your option) any later version.
493)
494) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
495) but WITHOUT ANY WARRANTY; without even the implied warranty of
496) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
497) GNU Lesser General Public License for more details.
498)
499) You should have received a copy of the GNU Lesser General Public License
500) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
501) */
502) var lib_shape;
503) (function (lib_shape) {
504) /**
505) * @author fenris
506) */
507) function any_make({ "soft": soft = true, "mutable": mutable = true, "defaultvalue": defaultvalue = null, }) {
508) return {
509) "soft": soft,
510) "mutable": mutable,
511) "defaultvalue": defaultvalue,
512) };
513) }
514) /**
515) * @author fenris
516) */
517) function any_inspect(parameters, value, _inspect) {
518) let inspection = lib_shape.inspection_create();
519) if (value == undefined) {
520) if (parameters.soft) {
521) // all good
522) }
523) else {
524) lib_shape.inspection_add(inspection, "null is not allowed");
525) }
526) }
527) else {
528) // all good
529) }
530) return inspection;
531) }
532) /**
533) * @author fenris
534) */
535) function any_stance(parameters, bindings, _stance) {
536) return {
537) "name": "any",
538) "parameters": parameters
539) };
540) }
541) /**
542) * @author fenris
543) */
544) function any_show(parameters, _show) {
545) let str;
546) // core
547) {
548) str = "any";
549) }
550) // soft
551) {
552) if (parameters.soft) {
553) str = `~${str}`;
554) }
555) }
556) return str;
557) }
558) /**
559) * @author fenris
560) */
561) lib_shape.register({
562) "name": "any",
563) "make": any_make,
564) "inspect": any_inspect,
565) "stance": any_stance,
566) "show": any_show,
567) });
568) })(lib_shape || (lib_shape = {}));
569) /*
570) This file is part of »bacterio-plankton:shape«.
571)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
572) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
573) <info@greenscale.de>
574)
575) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
576) it under the terms of the GNU Lesser General Public License as published by
577) the Free Software Foundation, either version 3 of the License, or
578) (at your option) any later version.
579)
580) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
581) but WITHOUT ANY WARRANTY; without even the implied warranty of
582) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
583) GNU Lesser General Public License for more details.
584)
585) You should have received a copy of the GNU Lesser General Public License
586) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
587) */
588) var lib_shape;
589) (function (lib_shape) {
590) /**
591) * @author fenris
592) */
593) function boolean_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, }) {
594) if (defaultvalue === undefined) {
595) defaultvalue = (soft ? null : false);
596) }
597) return {
598) "soft": soft,
599) "mutable": mutable,
600) "defaultvalue": defaultvalue,
601) };
602) }
603) /**
604) * @author fenris
605) */
606) function boolean_inspect(parameters, value, _inspect) {
607) let inspection = lib_shape.inspection_create();
608) if (value == undefined) {
609) if (parameters.soft) {
610) // all good
611) }
612) else {
613) lib_shape.inspection_add(inspection, "null is not allowed");
614) }
615) }
616) else {
617) let jstype_actual = typeof (value);
618) let jstype_expected = "boolean";
619) if (jstype_actual === jstype_expected) {
620) // all good
621) }
622) else {
623) lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
624) }
625) }
626) return inspection;
627) }
628) /**
629) * @author fenris
630) */
631) function boolean_stance(parameters, bindings, _stance) {
632) return {
633) "name": "boolean",
634) "parameters": parameters
635) };
636) }
637) /**
638) * @author fenris
639) */
640) function boolean_show(parameters, _show) {
641) let str;
642) // core
643) {
644) str = "boolean";
645) }
646) // soft
647) {
648) if (parameters.soft) {
649) str = `~${str}`;
650) }
651) }
652) return str;
653) }
654) /**
655) * @author fenris
656) */
657) lib_shape.register({
658) "name": "boolean",
659) "make": boolean_make,
660) "inspect": boolean_inspect,
661) "stance": boolean_stance,
662) "show": boolean_show,
663) });
664) })(lib_shape || (lib_shape = {}));
665) /*
666) This file is part of »bacterio-plankton:shape«.
667)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
668) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
669) <info@greenscale.de>
670)
671) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
672) it under the terms of the GNU Lesser General Public License as published by
673) the Free Software Foundation, either version 3 of the License, or
674) (at your option) any later version.
675)
676) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
677) but WITHOUT ANY WARRANTY; without even the implied warranty of
678) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
679) GNU Lesser General Public License for more details.
680)
681) You should have received a copy of the GNU Lesser General Public License
682) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
683) */
684) var lib_shape;
685) (function (lib_shape) {
686) /**
687) * @author fenris
688) */
689) function int_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, "minimum": minimum = null, "maximum": maximum = null, }) {
690) if (defaultvalue === undefined) {
691) defaultvalue = (soft ? null : 0);
692) }
693) return {
694) "soft": soft,
695) "mutable": mutable,
696) "defaultvalue": defaultvalue,
697) "minimum": minimum,
698) "maximum": maximum,
699) };
700) }
701) /**
702) * @author fenris
703) */
704) function int_inspect(parameters, value, _inspect) {
705) let inspection = lib_shape.inspection_create();
706) if (value == undefined) {
707) if (parameters.soft) {
708) // all good
709) }
710) else {
711) lib_shape.inspection_add(inspection, "null is not allowed");
712) }
713) }
714) else {
715) let jstype_actual = typeof (value);
716) let jstype_expected = "number";
717) if (jstype_actual === jstype_expected) {
718) if (!isNaN(parseInt(value))) {
719) if ((parameters.minimum === null) || (value >= parameters.minimum)) {
720) if ((parameters.maximum === null) || (value <= parameters.maximum)) {
721) // all good
722) }
723) else {
724) lib_shape.inspection_add(inspection, `value is beyond maximum`);
725) }
726) }
727) else {
728) lib_shape.inspection_add(inspection, `value is below minimum`);
729) }
730) }
731) else {
732) lib_shape.inspection_add(inspection, `value is not parsable into a valid int`);
733) }
734) }
735) else {
736) lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
737) }
738) }
739) return inspection;
740) }
741) /**
742) * @author fenris
743) */
744) function int_stance(parameters, bindings, _stance) {
745) return {
746) "name": "int",
747) "parameters": parameters
748) };
749) }
750) /**
751) * @author fenris
752) */
753) function int_show(parameters, _show) {
754) let str;
755) // core
756) {
757) str = "int";
758) }
759) // soft
760) {
761) if (parameters.soft) {
762) str = `~${str}`;
763) }
764) }
765) return str;
766) }
767) /**
768) * @author fenris
769) */
770) lib_shape.register({
771) "name": "int",
772) "make": int_make,
773) "inspect": int_inspect,
774) "stance": int_stance,
775) "show": int_show,
776) });
777) })(lib_shape || (lib_shape = {}));
778) /*
779) This file is part of »bacterio-plankton:shape«.
780)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
781) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
782) <info@greenscale.de>
783)
784) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
785) it under the terms of the GNU Lesser General Public License as published by
786) the Free Software Foundation, either version 3 of the License, or
787) (at your option) any later version.
788)
789) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
790) but WITHOUT ANY WARRANTY; without even the implied warranty of
791) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
792) GNU Lesser General Public License for more details.
793)
794) You should have received a copy of the GNU Lesser General Public License
795) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
796) */
797) var lib_shape;
798) (function (lib_shape) {
799) /**
800) * @author fenris
801) */
802) function float_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, }) {
803) if (defaultvalue === undefined) {
804) defaultvalue = (soft ? null : 0.0);
805) }
806) return {
807) "soft": soft,
808) "mutable": mutable,
809) "defaultvalue": defaultvalue,
810) };
811) }
812) /**
813) * @author fenris
814) */
815) function float_inspect(parameters, value, _inspect) {
816) let inspection = lib_shape.inspection_create();
817) if (value == undefined) {
818) if (parameters.soft) {
819) // all good
820) }
821) else {
822) lib_shape.inspection_add(inspection, "null is not allowed");
823) }
824) }
825) else {
826) let jstype_actual = typeof (value);
827) let jstype_expected = "number";
828) if (jstype_actual === jstype_expected) {
829) if (!isNaN(parseFloat(value))) {
830) // all good
831) }
832) else {
833) lib_shape.inspection_add(inspection, `value is not parsable into a valid float`);
834) }
835) }
836) else {
837) lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
838) }
839) }
840) return inspection;
841) }
842) /**
843) * @author fenris
844) */
845) function float_stance(parameters, bindings, _stance) {
846) return {
847) "name": "float",
848) "parameters": parameters
849) };
850) }
851) /**
852) * @author fenris
853) */
854) function float_show(parameters, _show) {
855) let str;
856) // core
857) {
858) str = "float";
859) }
860) // soft
861) {
862) if (parameters.soft) {
863) str = `~${str}`;
864) }
865) }
866) return str;
867) }
868) /**
869) * @author fenris
870) */
871) lib_shape.register({
872) "name": "float",
873) "make": float_make,
874) "inspect": float_inspect,
875) "stance": float_stance,
876) "show": float_show,
877) });
878) })(lib_shape || (lib_shape = {}));
879) /*
880) This file is part of »bacterio-plankton:shape«.
881)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
882) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
883) <info@greenscale.de>
884)
885) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
886) it under the terms of the GNU Lesser General Public License as published by
887) the Free Software Foundation, either version 3 of the License, or
888) (at your option) any later version.
889)
890) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
891) but WITHOUT ANY WARRANTY; without even the implied warranty of
892) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
893) GNU Lesser General Public License for more details.
894)
895) You should have received a copy of the GNU Lesser General Public License
896) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
897) */
898) var lib_shape;
899) (function (lib_shape) {
900) /**
901) * @author fenris
902) */
903) function string_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, "long": long = false, }) {
904) if (defaultvalue === undefined) {
905) defaultvalue = (soft ? null : "");
906) }
907) return {
908) "soft": soft,
909) "mutable": mutable,
910) "defaultvalue": defaultvalue,
911) "long": long,
912) };
913) }
914) /**
915) * @author fenris
916) */
917) function string_inspect(parameters, value, _inspect) {
918) let inspection = lib_shape.inspection_create();
919) if (value == undefined) {
920) if (parameters.soft) {
921) // all good
922) }
923) else {
924) lib_shape.inspection_add(inspection, "null is not allowed");
925) }
926) }
927) else {
928) let jstype_actual = typeof (value);
929) let jstype_expected = "string";
930) if (jstype_actual === jstype_expected) {
931) // all good
932) }
933) else {
934) lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
935) }
936) }
937) return inspection;
938) }
939) /**
940) * @author fenris
941) */
942) function string_stance(parameters, bindings, _stance) {
943) return {
944) "name": "string",
945) "parameters": parameters
946) };
947) }
948) /**
949) * @author fenris
950) */
951) function string_show(parameters, _show) {
952) let str;
953) // core
954) {
955) str = "string";
956) }
957) // soft
958) {
959) if (parameters.soft) {
960) str = `~${str}`;
961) }
962) }
963) return str;
964) }
965) /**
966) * @author fenris
967) */
968) lib_shape.register({
969) "name": "string",
970) "make": string_make,
971) "inspect": string_inspect,
972) "stance": string_stance,
973) "show": string_show,
974) });
975) })(lib_shape || (lib_shape = {}));
976) /*
977) This file is part of »bacterio-plankton:shape«.
978)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
979) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
980) <info@greenscale.de>
981)
982) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
983) it under the terms of the GNU Lesser General Public License as published by
984) the Free Software Foundation, either version 3 of the License, or
985) (at your option) any later version.
986)
987) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
988) but WITHOUT ANY WARRANTY; without even the implied warranty of
989) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
990) GNU Lesser General Public License for more details.
991)
992) You should have received a copy of the GNU Lesser General Public License
993) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
994) */
995) var lib_shape;
996) (function (lib_shape) {
997) /**
998) * @author fenris
999) */
1000) function email_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, }) {
1001) if (defaultvalue === undefined) {
1002) defaultvalue = (soft ? null : "");
1003) }
1004) return {
1005) "soft": soft,
1006) "mutable": mutable,
1007) "defaultvalue": defaultvalue,
1008) };
1009) }
1010) /**
1011) * @author fenris
1012) */
1013) function email_inspect(parameters, value, _inspect) {
1014) let inspection = lib_shape.inspection_create();
1015) if (value == undefined) {
1016) if (parameters.soft) {
1017) // all good
1018) }
1019) else {
1020) lib_shape.inspection_add(inspection, "null is not allowed");
1021) }
1022) }
1023) else {
1024) let jstype_actual = typeof (value);
1025) let jstype_expected = "string";
1026) if (jstype_actual === jstype_expected) {
1027) // all good
1028) }
1029) else {
1030) lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
1031) }
1032) }
1033) return inspection;
1034) }
1035) /**
1036) * @author fenris
1037) */
1038) function email_stance(parameters, bindings, _stance) {
1039) return {
1040) "name": "email",
1041) "parameters": parameters
1042) };
1043) }
1044) /**
1045) * @author fenris
1046) */
1047) function email_show(parameters, _show) {
1048) let str;
1049) // core
1050) {
1051) str = "email";
1052) }
1053) // soft
1054) {
1055) if (parameters.soft) {
1056) str = `~${str}`;
1057) }
1058) }
1059) return str;
1060) }
1061) /**
1062) * @author fenris
1063) */
1064) lib_shape.register({
1065) "name": "email",
1066) "make": email_make,
1067) "inspect": email_inspect,
1068) "stance": email_stance,
1069) "show": email_show,
1070) });
1071) })(lib_shape || (lib_shape = {}));
1072) /*
1073) This file is part of »bacterio-plankton:shape«.
1074)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
1075) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
1076) <info@greenscale.de>
1077)
1078) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
1079) it under the terms of the GNU Lesser General Public License as published by
1080) the Free Software Foundation, either version 3 of the License, or
1081) (at your option) any later version.
1082)
1083) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
1084) but WITHOUT ANY WARRANTY; without even the implied warranty of
1085) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1086) GNU Lesser General Public License for more details.
1087)
1088) You should have received a copy of the GNU Lesser General Public License
1089) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
1090) */
1091) var lib_shape;
1092) (function (lib_shape) {
1093) /**
1094) * @author fenris
1095) */
1096) function url_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, "type": type = "link", }) {
1097) if (defaultvalue === undefined) {
1098) defaultvalue = (soft ? null : "");
1099) }
1100) return {
1101) "soft": soft,
1102) "mutable": mutable,
1103) "defaultvalue": defaultvalue,
1104) "type": type,
1105) };
1106) }
1107) /**
1108) * @author fenris
1109) */
1110) function url_inspect(parameters, value, _inspect) {
1111) let inspection = lib_shape.inspection_create();
1112) if (value == undefined) {
1113) if (parameters.soft) {
1114) // all good
1115) }
1116) else {
1117) lib_shape.inspection_add(inspection, "null is not allowed");
1118) }
1119) }
1120) else {
1121) let jstype_actual = typeof (value);
1122) let jstype_expected = "string";
1123) if (jstype_actual === jstype_expected) {
1124) // all good
1125) }
1126) else {
1127) lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
1128) }
1129) }
1130) return inspection;
1131) }
1132) /**
1133) * @author fenris
1134) */
1135) function url_stance(parameters, bindings, _stance) {
1136) return {
1137) "name": "url",
1138) "parameters": parameters
1139) };
1140) }
1141) /**
1142) * @author fenris
1143) */
1144) function url_show(parameters, _show) {
1145) let str;
1146) // core
1147) {
1148) str = "url";
1149) }
1150) // soft
1151) {
1152) if (parameters.soft) {
1153) str = `~${str}`;
1154) }
1155) }
1156) return str;
1157) }
1158) /**
1159) * @author fenris
1160) */
1161) lib_shape.register({
1162) "name": "url",
1163) "make": url_make,
1164) "inspect": url_inspect,
1165) "stance": url_stance,
1166) "show": url_show,
1167) });
1168) })(lib_shape || (lib_shape = {}));
1169) /*
1170) This file is part of »bacterio-plankton:shape«.
1171)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
1172) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
1173) <info@greenscale.de>
1174)
1175) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
1176) it under the terms of the GNU Lesser General Public License as published by
1177) the Free Software Foundation, either version 3 of the License, or
1178) (at your option) any later version.
1179)
1180) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
1181) but WITHOUT ANY WARRANTY; without even the implied warranty of
1182) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1183) GNU Lesser General Public License for more details.
1184)
1185) You should have received a copy of the GNU Lesser General Public License
1186) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
1187) */
1188) var lib_shape;
1189) (function (lib_shape) {
1190) /**
1191) * @author fenris
1192) */
1193) function markdown_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, "type": type = "link", }) {
1194) if (defaultvalue === undefined) {
1195) defaultvalue = (soft ? null : "");
1196) }
1197) return {
1198) "soft": soft,
1199) "mutable": mutable,
1200) "defaultvalue": defaultvalue,
1201) "type": type,
1202) };
1203) }
1204) /**
1205) * @author fenris
1206) */
1207) function markdown_inspect(parameters, value, _inspect) {
1208) let inspection = lib_shape.inspection_create();
1209) if (value == undefined) {
1210) if (parameters.soft) {
1211) // all good
1212) }
1213) else {
1214) lib_shape.inspection_add(inspection, "null is not allowed");
1215) }
1216) }
1217) else {
1218) let jstype_actual = typeof (value);
1219) let jstype_expected = "string";
1220) if (jstype_actual === jstype_expected) {
1221) // all good
1222) }
1223) else {
1224) lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
1225) }
1226) }
1227) return inspection;
1228) }
1229) /**
1230) * @author fenris
1231) */
1232) function markdown_stance(parameters, bindings, _stance) {
1233) return {
1234) "name": "markdown",
1235) "parameters": parameters
1236) };
1237) }
1238) /**
1239) * @author fenris
1240) */
1241) function markdown_show(parameters, _show) {
1242) let str;
1243) // core
1244) {
1245) str = "markdown";
1246) }
1247) // soft
1248) {
1249) if (parameters.soft) {
1250) str = `~${str}`;
1251) }
1252) }
1253) return str;
1254) }
1255) /**
1256) * @author fenris
1257) */
1258) lib_shape.register({
1259) "name": "markdown",
1260) "make": markdown_make,
1261) "inspect": markdown_inspect,
1262) "stance": markdown_stance,
1263) "show": markdown_show,
1264) });
1265) })(lib_shape || (lib_shape = {}));
1266) /*
1267) This file is part of »bacterio-plankton:shape«.
1268)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
1269) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
1270) <info@greenscale.de>
1271)
1272) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
1273) it under the terms of the GNU Lesser General Public License as published by
1274) the Free Software Foundation, either version 3 of the License, or
1275) (at your option) any later version.
1276)
1277) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
1278) but WITHOUT ANY WARRANTY; without even the implied warranty of
1279) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1280) GNU Lesser General Public License for more details.
1281)
1282) You should have received a copy of the GNU Lesser General Public License
1283) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
1284) */
1285) var lib_shape;
1286) (function (lib_shape) {
1287) /**
1288) * @author fenris
1289) */
1290) function time_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, }) {
1291) if (defaultvalue === undefined) {
1292) defaultvalue = (soft ? null : "");
1293) }
1294) return {
1295) "soft": soft,
1296) "mutable": mutable,
1297) "defaultvalue": defaultvalue,
1298) };
1299) }
1300) /**
1301) * @author fenris
1302) */
1303) function time_inspect(parameters, value, _inspect) {
1304) let inspection = lib_shape.inspection_create();
1305) if (value == undefined) {
1306) if (parameters.soft) {
1307) // all good
1308) }
1309) else {
1310) lib_shape.inspection_add(inspection, "null is not allowed");
1311) }
1312) }
1313) else {
1314) let jstype_actual = typeof (value);
1315) let jstype_expected = "object";
1316) if (jstype_actual === jstype_expected) {
1317) // all good?
1318) }
1319) else {
1320) lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
1321) }
1322) }
1323) return inspection;
1324) }
1325) /**
1326) * @author fenris
1327) */
1328) function time_stance(parameters, bindings, _stance) {
1329) return {
1330) "name": "time",
1331) "parameters": parameters
1332) };
1333) }
1334) /**
1335) * @author fenris
1336) */
1337) function time_show(parameters, _show) {
1338) let str;
1339) // core
1340) {
1341) str = "time";
1342) }
1343) // soft
1344) {
1345) if (parameters.soft) {
1346) str = `~${str}`;
1347) }
1348) }
1349) return str;
1350) }
1351) /**
1352) * @author fenris
1353) */
1354) lib_shape.register({
1355) "name": "time",
1356) "make": time_make,
1357) "inspect": time_inspect,
1358) "stance": time_stance,
1359) "show": time_show,
1360) });
1361) })(lib_shape || (lib_shape = {}));
1362) /*
1363) This file is part of »bacterio-plankton:shape«.
1364)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
1365) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
1366) <info@greenscale.de>
1367)
1368) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
1369) it under the terms of the GNU Lesser General Public License as published by
1370) the Free Software Foundation, either version 3 of the License, or
1371) (at your option) any later version.
1372)
1373) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
1374) but WITHOUT ANY WARRANTY; without even the implied warranty of
1375) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1376) GNU Lesser General Public License for more details.
1377)
1378) You should have received a copy of the GNU Lesser General Public License
1379) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
1380) */
1381) var lib_shape;
1382) (function (lib_shape) {
1383) /**
1384) * @author fenris
1385) */
1386) function array_make({ "soft": soft = false, "mutable": mutable = true, "shape_element": shape_element, "defaultvalue": defaultvalue = undefined, }, _make) {
1387) if (shape_element === undefined) {
1388) let message = `mandatory parameter 'shape_element' missing`;
1389) throw (new Error(message));
1390) }
1391) if (defaultvalue === undefined) {
1392) defaultvalue = (soft ? null : []);
1393) }
1394) return {
1395) "soft": soft,
1396) "mutable": mutable,
1397) "shape_element": _make(shape_element),
1398) "defaultvalue": defaultvalue,
1399) };
1400) }
1401) /**
1402) * @author fenris
1403) */
1404) function array_inspect(parameters, value, _inspect) {
1405) let inspection = lib_shape.inspection_create();
1406) if (value == undefined) {
1407) if (parameters.soft) {
1408) // all good
1409) }
1410) else {
1411) lib_shape.inspection_add(inspection, "null is not allowed");
1412) }
1413) }
1414) else {
1415) let jstype_actual = typeof (value);
1416) let jstype_expected = "object";
1417) if (jstype_actual === jstype_expected) {
1418) if (value instanceof Array) {
1419) value.forEach((element, index) => {
1420) lib_shape.inspection_extend(inspection, `element #${index.toFixed(0)}`, _inspect(parameters.shape_element, element));
1421) });
1422) }
1423) else {
1424) lib_shape.inspection_add(inspection, `value does not seem to be an array-instance`);
1425) }
1426) }
1427) else {
1428) lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
1429) }
1430) }
1431) return inspection;
1432) }
1433) /**
1434) * @author fenris
1435) */
1436) function array_stance(parameters, bindings, _stance) {
1437) return {
1438) "name": "array",
1439) "parameters": {
1440) "soft": parameters.soft,
1441) "shape_element": _stance(parameters.shape_element, bindings)
1442) }
1443) };
1444) }
1445) /**
1446) * @author fenris
1447) */
1448) function array_show(parameters, _show) {
1449) let str;
1450) // core
1451) {
1452) str = "array";
1453) }
1454) // shape_element
1455) {
1456) str += ("<"
1457) +
1458) _show(parameters.shape_element)
1459) +
1460) ">");
1461) }
1462) // soft
1463) {
1464) if (parameters.soft) {
1465) str = `~${str}`;
1466) }
1467) }
1468) return str;
1469) }
1470) /**
1471) * @author fenris
1472) */
1473) lib_shape.register({
1474) "name": "array",
1475) "make": array_make,
1476) "inspect": array_inspect,
1477) "stance": array_stance,
1478) "show": array_show,
1479) });
1480) })(lib_shape || (lib_shape = {}));
1481) /*
1482) This file is part of »bacterio-plankton:shape«.
1483)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
1484) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
1485) <info@greenscale.de>
1486)
1487) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
1488) it under the terms of the GNU Lesser General Public License as published by
1489) the Free Software Foundation, either version 3 of the License, or
1490) (at your option) any later version.
1491)
1492) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
1493) but WITHOUT ANY WARRANTY; without even the implied warranty of
1494) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1495) GNU Lesser General Public License for more details.
1496)
1497) You should have received a copy of the GNU Lesser General Public License
1498) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
1499) */
1500) var lib_shape;
1501) (function (lib_shape) {
1502) /**
1503) * @author fenris
1504) */
1505) function enumeration_make({ "soft": soft = false, "mutable": mutable = true, "shape_option": shape_option, "options": options, "defaultvalue": defaultvalue = undefined, }, _make) {
1506) if (shape_option === undefined) {
1507) let message = `mandatory parameter 'shape_option' missing`;
1508) throw (new Error(message));
1509) }
1510) if (options === undefined) {
1511) let message = `mandatory parameter 'options' missing`;
1512) throw (new Error(message));
1513) }
1514) if (defaultvalue === undefined) {
1515) defaultvalue = (soft ? null : options[0].value);
1516) }
1517) return {
1518) "soft": soft,
1519) "mutable": mutable,
1520) "shape_option": _make(shape_option),
1521) "options": options,
1522) "defaultvalue": defaultvalue,
1523) };
1524) }
1525) /**
1526) * @author fenris
1527) */
1528) function enumeration_inspect(parameters, value, _inspect) {
1529) let inspection = lib_shape.inspection_create();
1530) if (value == undefined) {
1531) if (parameters.soft) {
1532) // all good
1533) }
1534) else {
1535) lib_shape.inspection_add(inspection, "null is not allowed");
1536) }
1537) }
1538) else {
1539) lib_shape.inspection_extend(inspection, `given value for enumeration`, _inspect(parameters.shape_option, value));
1540) // TODO: check if corresponding option exists
1541) }
1542) return inspection;
1543) }
1544) /**
1545) * @author fenris
1546) */
1547) function enumeration_stance(parameters, bindings, _stance) {
1548) return {
1549) "name": "enumeration",
1550) "parameters": {
1551) "soft": parameters.soft,
1552) "shape_option": _stance(parameters.shape_option, bindings),
1553) "options": parameters.options,
1554) }
1555) };
1556) }
1557) /**
1558) * @author fenris
1559) */
1560) function enumeration_show(parameters, _show) {
1561) let str;
1562) // core
1563) {
1564) str = "enumeration";
1565) }
1566) // shape_option
1567) {
1568) str += ("<"
1569) +
1570) parameters.options.map(option => String(option)).join(",") + ":" + _show(parameters.shape_option)
1571) +
1572) ">");
1573) }
1574) // soft
1575) {
1576) if (parameters.soft) {
1577) str = `~${str}`;
1578) }
1579) }
1580) return str;
1581) }
1582) /**
1583) * @author fenris
1584) */
1585) lib_shape.register({
1586) "name": "enumeration",
1587) "make": enumeration_make,
1588) "inspect": enumeration_inspect,
1589) "stance": enumeration_stance,
1590) "show": enumeration_show,
1591) });
1592) })(lib_shape || (lib_shape = {}));
1593) /*
1594) This file is part of »bacterio-plankton:shape«.
1595)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
1596) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
1597) <info@greenscale.de>
1598)
1599) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
1600) it under the terms of the GNU Lesser General Public License as published by
1601) the Free Software Foundation, either version 3 of the License, or
1602) (at your option) any later version.
1603)
1604) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
1605) but WITHOUT ANY WARRANTY; without even the implied warranty of
1606) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1607) GNU Lesser General Public License for more details.
1608)
1609) You should have received a copy of the GNU Lesser General Public License
1610) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
1611) */
1612) var lib_shape;
1613) (function (lib_shape) {
1614) /**
1615) * @author fenris
1616) */
1617) function date_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, }) {
1618) if (defaultvalue === undefined) {
1619) defaultvalue = (soft ? null : (new Date(Date.now())));
1620) }
1621) return {
1622) "soft": soft,
1623) "mutable": mutable,
1624) "defaultvalue": defaultvalue,
1625) };
1626) }
1627) /**
1628) * @author fenris
1629) */
1630) function date_inspect(parameters, value, _inspect) {
1631) let inspection = lib_shape.inspection_create();
1632) if (value == undefined) {
1633) if (parameters.soft) {
1634) // all good
1635) }
1636) else {
1637) lib_shape.inspection_add(inspection, "null is not allowed");
1638) }
1639) }
1640) else {
1641) let jstype_actual = typeof (value);
1642) let jstype_expected = "object";
1643) if (jstype_actual === jstype_expected) {
1644) if (value instanceof Date) {
1645) // all gode
1646) }
1647) else {
1648) lib_shape.inspection_add(inspection, `value does not seem to be a date-instance`);
1649) }
1650) }
1651) else {
1652) lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
1653) }
1654) }
1655) return inspection;
1656) }
1657) /**
1658) * @author fenris
1659) */
1660) function date_stance(parameters, bindings, _stance) {
1661) return {
1662) "name": "date",
1663) "parameters": parameters
1664) };
1665) }
1666) /**
1667) * @author fenris
1668) */
1669) function date_show(parameters, _show) {
1670) let str;
1671) // core
1672) {
1673) str = "date";
1674) }
1675) // soft
1676) {
1677) if (parameters.soft) {
1678) str = `~${str}`;
1679) }
1680) }
1681) return str;
1682) }
1683) /**
1684) * @author fenris
1685) */
1686) lib_shape.register({
1687) "name": "date",
1688) "make": date_make,
1689) "inspect": date_inspect,
1690) "stance": date_stance,
1691) "show": date_show,
1692) });
1693) })(lib_shape || (lib_shape = {}));
1694) /*
1695) This file is part of »bacterio-plankton:shape«.
1696)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
1697) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
1698) <info@greenscale.de>
1699)
1700) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
1701) it under the terms of the GNU Lesser General Public License as published by
1702) the Free Software Foundation, either version 3 of the License, or
1703) (at your option) any later version.
1704)
1705) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
1706) but WITHOUT ANY WARRANTY; without even the implied warranty of
1707) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1708) GNU Lesser General Public License for more details.
1709)
1710) You should have received a copy of the GNU Lesser General Public License
1711) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
1712) */
1713) var lib_shape;
1714) (function (lib_shape) {
1715) /**
1716) * @author fenris
1717) */
1718) function record_make({ "soft": soft = false, "mutable": mutable = true, "fields": fields = [], "defaultvalue": defaultvalue = undefined, }, _make) {
1719) let fields_ = (fields
1720) .map((field) => ({ "name": field.name, "shape": _make(field.shape) })));
1721) if (defaultvalue === undefined) {
1722) if (soft) {
1723) defaultvalue = null;
1724) }
1725) else {
1726) defaultvalue = {};
1727) fields_.forEach(field => {
1728) defaultvalue[field.name] = field.shape.parameters["defaultvalue"];
1729) });
1730) }
1731) }
1732) return {
1733) "soft": soft,
1734) "mutable": mutable,
1735) "fields": fields_,
1736) "defaultvalue": defaultvalue,
1737) };
1738) }
1739) /**
1740) * @author fenris
1741) */
1742) function record_inspect(parameters, value, _inspect) {
1743) let inspection = lib_shape.inspection_create();
1744) if (value == undefined) {
1745) if (parameters.soft) {
1746) // all good
1747) }
1748) else {
1749) lib_shape.inspection_add(inspection, "null is not allowed");
1750) }
1751) }
1752) else {
1753) let jstype_actual = typeof (value);
1754) let jstype_expected = "object";
1755) if (jstype_actual === jstype_expected) {
1756) parameters.fields.forEach(field => {
1757) let value_ = value[field.name];
1758) lib_shape.inspection_extend(inspection, `field '${field.name}'`, _inspect(field.shape, value_));
1759) });
1760) }
1761) else {
1762) lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
1763) }
1764) }
1765) return inspection;
1766) }
1767) /**
1768) * @author fenris
1769) */
1770) function record_stance(parameters, bindings, _stance) {
1771) return {
1772) "name": "record",
1773) "parameters": {
1774) "soft": parameters.soft,
1775) "fields": parameters.fields.map(field => {
1776) return {
1777) "name": field.name,
1778) "shape": _stance(field.shape, bindings)
1779) };
1780) })
1781) }
1782) };
1783) }
1784) /**
1785) * @author fenris
1786) */
1787) function record_show(parameters, _show) {
1788) let str;
1789) // core
1790) {
1791) str = "record";
1792) }
1793) // fields
1794) {
1795) str += ("<"
1796) +
1797) parameters.fields.map(field => (field.name + ":" + _show(field.shape))).join(",")
1798) +
1799) ">");
1800) }
1801) // soft
1802) {
1803) if (parameters.soft) {
1804) str = `~${str}`;
1805) }
1806) }
1807) return str;
1808) }
1809) /**
1810) * @author fenris
1811) */
1812) lib_shape.register({
1813) "name": "record",
1814) "make": record_make,
1815) "inspect": record_inspect,
1816) "stance": record_stance,
1817) "show": record_show,
1818) });
1819) })(lib_shape || (lib_shape = {}));
1820) /*
1821) This file is part of »bacterio-plankton:shape«.
1822)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
1823) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
1824) <info@greenscale.de>
1825)
1826) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
1827) it under the terms of the GNU Lesser General Public License as published by
1828) the Free Software Foundation, either version 3 of the License, or
1829) (at your option) any later version.
1830)
1831) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
1832) but WITHOUT ANY WARRANTY; without even the implied warranty of
1833) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1834) GNU Lesser General Public License for more details.
1835)
1836) You should have received a copy of the GNU Lesser General Public License
1837) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
1838) */
1839) var lib_shape;
1840) (function (lib_shape) {
1841) /**
1842) * @author fenris
1843) */
1844) function map_make({ "soft": soft = false, "mutable": mutable = true, "shape_key": shape_key, "shape_value": shape_value, "defaultvalue": defaultvalue = undefined, }, _make) {
1845) if (shape_key === undefined) {
1846) let message = `mandatory parameter 'shape_key' missing`;
1847) throw (new Error(message));
1848) }
1849) if (shape_value === undefined) {
1850) let message = `mandatory parameter 'shape_value' missing`;
1851) throw (new Error(message));
1852) }
1853) if (defaultvalue === undefined) {
1854) defaultvalue = (soft ? null : {});
1855) }
1856) return {
1857) "soft": soft,
1858) "mutable": mutable,
1859) "shape_key": _make(shape_key),
1860) "shape_value": _make(shape_value),
1861) "defaultvalue": defaultvalue,
1862) };
1863) }
1864) /**
1865) * @author fenris
1866) */
1867) function map_stance(parameters, bindings, _stance) {
1868) return {
1869) "name": "map",
1870) "parameters": {
1871) "soft": parameters.soft,
1872) "shape_key": _stance(parameters.shape_key, bindings),
1873) "shape_value": _stance(parameters.shape_value, bindings)
1874) }
1875) };
1876) }
1877) /**
1878) * @author fenris
1879) * @todo closer look not possible?
1880) */
1881) function map_inspect(parameters, value, _inspect) {
1882) let inspection = lib_shape.inspection_create();
1883) if (value == undefined) {
1884) if (parameters.soft) {
1885) // all good
1886) }
1887) else {
1888) lib_shape.inspection_add(inspection, "null is not allowed");
1889) }
1890) }
1891) else {
1892) let jstype_actual = typeof (value);
1893) let jstype_expected = "object";
1894) if (jstype_actual === jstype_expected) {
1895) Object.keys(value).forEach(key => {
1896) lib_shape.inspection_extend(inspection, `key '${key}'`, _inspect(parameters.shape_key, key));
1897) let value_ = value[key];
1898) lib_shape.inspection_extend(inspection, `value for key '${key}'`, _inspect(parameters.shape_value, value_));
1899) });
1900) }
1901) else {
1902) lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
1903) }
1904) }
1905) return inspection;
1906) }
1907) /**
1908) * @author fenris
1909) */
1910) function map_show(parameters, _show) {
1911) let str;
1912) // core
1913) {
1914) str = "map";
1915) }
1916) // in/out
1917) {
1918) str += ("<"
1919) +
1920) [
1921) _show(parameters.shape_key),
1922) _show(parameters.shape_value),
1923) ].join(",")
1924) +
1925) ">");
1926) }
1927) // soft
1928) {
1929) if (parameters.soft) {
1930) str = `~${str}`;
1931) }
1932) }
1933) return str;
1934) }
1935) /**
1936) * @author fenris
1937) */
1938) lib_shape.register({
1939) "name": "map",
1940) "make": map_make,
1941) "inspect": map_inspect,
1942) "stance": map_stance,
1943) "show": map_show,
1944) });
1945) })(lib_shape || (lib_shape = {}));
1946) /*
1947) This file is part of »bacterio-plankton:shape«.
1948)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
1949) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
1950) <info@greenscale.de>
1951)
1952) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
1953) it under the terms of the GNU Lesser General Public License as published by
1954) the Free Software Foundation, either version 3 of the License, or
1955) (at your option) any later version.
1956)
1957) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
1958) but WITHOUT ANY WARRANTY; without even the implied warranty of
1959) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1960) GNU Lesser General Public License for more details.
1961)
1962) You should have received a copy of the GNU Lesser General Public License
1963) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
1964) */
1965) var lib_shape;
1966) (function (lib_shape) {
1967) /**
1968) * @author fenris
1969) */
1970) function maybe_make({ "soft": soft = false, "shape_value": shape_value, "defaultvalue": defaultvalue = undefined, }, _make) {
1971) if (shape_value === undefined) {
1972) let message = `mandatory parameter 'shape_value' missing`;
1973) throw (new Error(message));
1974) }
1975) if (defaultvalue === undefined) {
1976) defaultvalue = (soft ? null : { "kind": "nothing" });
1977) }
1978) return {
1979) "soft": soft,
1980) "shape_value": _make(shape_value),
1981) "defaultvalue": defaultvalue,
1982) };
1983) }
1984) /**
1985) * @author fenris
1986) */
1987) function maybe_inspect(parameters, value, _inspect) {
1988) let inspection = lib_shape.inspection_create();
1989) if (value == undefined) {
1990) if (parameters.soft) {
1991) // all good
1992) }
1993) else {
1994) lib_shape.inspection_add(inspection, "null is not allowed");
1995) }
1996) }
1997) else {
1998) let jstype_actual = typeof (value);
1999) let jstype_expected = "object";
2000) if (jstype_actual === jstype_expected) {
2001) if ("kind" in value) {
2002) // all good?
2003) }
2004) else {
2005) lib_shape.inspection_add(inspection, `field 'kind' missing`);
2006) }
2007) }
2008) else {
2009) lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
2010) }
2011) }
2012) return inspection;
2013) }
2014) /**
2015) * @author fenris
2016) */
2017) function maybe_stance(parameters, bindings, _stance) {
2018) return {
2019) "name": "maybe",
2020) "parameters": {
2021) "soft": parameters.soft,
2022) "shape_value": _stance(parameters.shape_value, bindings)
2023) }
2024) };
2025) }
2026) /**
2027) * @author fenris
2028) */
2029) function maybe_show(parameters, _show) {
2030) let str;
2031) // core
2032) {
2033) str = "maybe";
2034) }
2035) // shape_value
2036) {
2037) str += ("<"
2038) +
2039) _show(parameters.shape_value)
2040) +
2041) ">");
2042) }
2043) // soft
2044) {
2045) if (parameters.soft) {
2046) str = `~${str}`;
2047) }
2048) }
2049) return str;
2050) }
2051) /**
2052) * @author fenris
2053) */
2054) lib_shape.register({
2055) "name": "maybe",
2056) "make": maybe_make,
2057) "inspect": maybe_inspect,
2058) "stance": maybe_stance,
2059) "show": maybe_show,
2060) });
2061) })(lib_shape || (lib_shape = {}));
2062) /*
2063) This file is part of »bacterio-plankton:shape«.
2064)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
2065) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
[add] client
Christian Fraß authored 3 years ago
|
2066) <info@greenscale.de>
2067)
2068) »bacterio-plankton:shape« is free software: you can redistribute it and/or modify
2069) it under the terms of the GNU Lesser General Public License as published by
2070) the Free Software Foundation, either version 3 of the License, or
2071) (at your option) any later version.
2072)
2073) »bacterio-plankton:shape« is distributed in the hope that it will be useful,
2074) but WITHOUT ANY WARRANTY; without even the implied warranty of
2075) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2076) GNU Lesser General Public License for more details.
2077)
2078) You should have received a copy of the GNU Lesser General Public License
2079) along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>.
2080) */
2081) var lib_shape;
2082) (function (lib_shape) {
2083) /**
2084) * @author fenris
2085) */
2086) function promise_make({ "soft": soft = false, "shape_result": shape_result, "shape_reason": shape_reason, "defaultvalue": defaultvalue = undefined, }, _make) {
2087) if (shape_result === undefined) {
2088) let message = `mandatory parameter 'shape_result' missing`;
2089) throw (new Error(message));
2090) }
2091) if (shape_reason === undefined) {
2092) let message = `mandatory parameter 'shape_reason' missing`;
2093) throw (new Error(message));
2094) }
2095) if (defaultvalue === undefined) {
2096) defaultvalue = (soft ? null : Promise.resolve(null));
2097) }
2098) return {
2099) "soft": soft,
2100) "shape_result": _make(shape_result),
2101) "shape_reason": _make(shape_reason),
2102) "defaultvalue": defaultvalue,
2103) };
2104) }
2105) /**
2106) * @author fenris
2107) */
2108) function promise_stance(parameters, bindings, _stance) {
2109) return {
2110) "name": "promise",
2111) "parameters": {
2112) "soft": parameters.soft,
2113) "shape_result": _stance(parameters.shape_result, bindings),
2114) "shape_reason": _stance(parameters.shape_reason, bindings)
2115) }
2116) };
2117) }
2118) /**
2119) * @author fenris
2120) * @todo closer look not possible?
2121) */
2122) function promise_inspect(parameters, value, _inspect) {
2123) let inspection = lib_shape.inspection_create();
2124) if (value == undefined) {
2125) if (parameters.soft) {
2126) // all good
2127) }
2128) else {
2129) lib_shape.inspection_add(inspection, "null is not allowed");
2130) }
2131) }
2132) else {
2133) let jstype_actual = typeof (value);
2134) let jstype_expected = "object";
2135) if (jstype_actual === jstype_expected) {
2136) if (value instanceof Promise /*<any, any>*/) {
2137) // all good?
2138) }
2139) else {
2140) lib_shape.inspection_add(inspection, `values is not an Promise-instance`);
2141) }
2142) }
2143) else {
2144) lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`);
2145) }
2146) }
2147) return inspection;
2148) }
2149) /**
2150) * @author fenris
2151) */
2152) function promise_show(parameters, _show) {
2153) let str;
2154) // core
2155) {
2156) str = "promise";
2157) }
2158) // in/out
2159) {
2160) str += ("<"
2161) +
2162) [
2163) _show(parameters.shape_result),
2164) _show(parameters.shape_reason),
2165) ].join(",")
2166) +
2167) ">");
2168) }
2169) // soft
2170) {
2171) if (parameters.soft) {
2172) str = `~${str}`;
2173) }
2174) }
2175) return str;
2176) }
2177) /**
2178) * @author fenris
2179) */
2180) lib_shape.register({
2181) "name": "promise",
2182) "make": promise_make,
2183) "inspect": promise_inspect,
2184) "stance": promise_stance,
2185) "show": promise_show,
2186) });
2187) })(lib_shape || (lib_shape = {}));
2188) /*
2189) This file is part of »bacterio-plankton:shape«.
2190)
|
[upd] client:lib:plankton
Christian Fraß authored 3 years ago
|
2191) Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|