exupery-core-types 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ import { Async_Value } from "./Async_Value";
2
+ import { Optional_Value } from "./Optional_Value";
3
+ /**
4
+ * A Exupery array.
5
+ * unmutable and minimal by design
6
+ */
7
+ export interface Array<T> {
8
+ /**
9
+ *
10
+ * @param $v callback to transform an individual entry.
11
+ */
12
+ map<NT>($v: ($: T) => NT): Array<NT>;
13
+ /**
14
+ * maps the array to {@link Async_Value} that contains an array
15
+ * @param $v callback that provides an async value. keys are not available.
16
+ */
17
+ async_map<NT>($v: ($: T) => Async_Value<NT>): Async_Value<Array<NT>>;
18
+ /**
19
+ * This method is only to be used by resources
20
+ * iterates over all entries
21
+ *
22
+ * @param $v callback to process the entry
23
+ */
24
+ __for_each($v: ($: T) => void): void;
25
+ /**
26
+ * This method is only to be used by resources
27
+ *
28
+ */
29
+ __get_length(): number;
30
+ /**
31
+ * This method is only to be used by resources
32
+ *
33
+ * @param index
34
+ */
35
+ __get_element_at(index: number): Optional_Value<T>;
36
+ __get_raw_copy(): readonly T[];
37
+ }
package/dist/Array.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,15 @@
1
+ /**
2
+ * A value that will asynchronously become available.
3
+ * Similar to the concept of a promise, but with a smaller API.
4
+ */
5
+ export interface Async_Value<T> {
6
+ /**
7
+ * maps the current async value into a new async value
8
+ * @param $v callback that transforms the actual value into a new Async_Value
9
+ */
10
+ map<NT>($v: ($: T) => Async_Value<NT>): Async_Value<NT>;
11
+ /**
12
+ * This method is only to be used by resources
13
+ */
14
+ __execute($i: ($: T) => void): void;
15
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A computed value is a function without paramters returning the specified type
3
+ * it makes it possible to do the evaluation only when the function is called
4
+ * useful for lazy evaluation or when side effects are needed
5
+ */
6
+ export type Computed_Value<T> = () => T;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,39 @@
1
+ import { Array } from "./Array";
2
+ import { Async_Value } from "./Async_Value";
3
+ import { Optional_Value } from "./Optional_Value";
4
+ export type Key_Value_Pair<T> = {
5
+ readonly 'key': string;
6
+ readonly 'value': T;
7
+ };
8
+ export type Compare_Function<T> = (a: Key_Value_Pair<T>, b: Key_Value_Pair<T>) => number;
9
+ /**
10
+ * A Exupery dictionary.
11
+ * unmutable and minimal by design
12
+ */
13
+ export interface Dictionary<T> {
14
+ /**
15
+ *
16
+ * @param $v callback to transform an individual entry. keys are not available.
17
+ */
18
+ map<NT>($v: ($: T, key: string) => NT): Dictionary<NT>;
19
+ /**
20
+ *
21
+ * @param $v callback that provides an {@link Async_Value}. keys are not available.
22
+ */
23
+ async_map<NT>($v: ($: T) => Async_Value<NT>): Async_Value<Dictionary<NT>>;
24
+ /**
25
+ * This method is only to be used by resources
26
+ * iterates over all entries in a sorted manner
27
+ */
28
+ to_array(compare: Compare_Function<T>): Array<Key_Value_Pair<T>>;
29
+ /**
30
+ * This method is only to be used by resources
31
+ * returns an {@link Optional_Value } of type T reflecting wether the entry existed or not
32
+ *
33
+ * @param key
34
+ */
35
+ __get_entry(key: string): Optional_Value<T>;
36
+ __add_entry_if_not_exists(key: string, value: T): Dictionary<T>;
37
+ __add_entry_overwrite_if_exists(key: string, value: T): Dictionary<T>;
38
+ __remove_entry_if_exists(key: string): Dictionary<T>;
39
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ import { Optional_Value } from "./Optional_Value";
2
+ /**
3
+ * A lookup is similar to a Dictionary, but much more basic.
4
+ * There are only operations to retrieve entries
5
+ */
6
+ export interface Lookup<T> {
7
+ /**
8
+ * This method is only to be used by resources
9
+ * returns an {@link Optional_Value } of type T reflecting wether the entry existed or not
10
+ *
11
+ * @param key
12
+ */
13
+ __get_entry(key: string): Optional_Value<T>;
14
+ }
package/dist/Lookup.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,25 @@
1
+ /**
2
+ * this is literal data type, either [false] or [true, T]
3
+ * the first entry of the tuple is thus 'false' or 'true'. If the first one is 'true',
4
+ * then there is a second one containing the value T
5
+ */
6
+ export type Raw_Optional_Value<T> = readonly [false] | readonly [true, T];
7
+ /**
8
+ * Why this type and not use for example 'null | T'?
9
+ * the 'null | T' is vulnerable. If you have a parametrized function 'foo<T>() null | T' and T is null | number,
10
+ * you cannot discern if a return value is null because of the function or because of the data
11
+ * this 'Optional_Value' type makes it possible to have recursive optional types like this: Optional_Value<Optional_Value<number>>
12
+ */
13
+ export interface Optional_Value<T> {
14
+ /**
15
+ * @param set what to do when the value was set, returns the new type
16
+ * @param not_set what to do when the value was not set, returns the new type
17
+ */
18
+ transform<NT>(set: ($: T) => NT, not_set: () => NT): NT;
19
+ /**
20
+ *
21
+ */
22
+ map<NT>(//this one should be called 'map'
23
+ set: ($: T) => NT): Optional_Value<NT>;
24
+ __raw: Raw_Optional_Value<T>;
25
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,20 @@
1
+ interface Array<T> {
2
+ }
3
+ interface Boolean {
4
+ }
5
+ interface CallableFunction {
6
+ }
7
+ interface Function {
8
+ }
9
+ interface IArguments {
10
+ }
11
+ interface NewableFunction {
12
+ }
13
+ interface Number {
14
+ }
15
+ interface Object {
16
+ }
17
+ interface RegExp {
18
+ }
19
+ interface String {
20
+ }
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,6 @@
1
+ export * from "./Array";
2
+ export * from "./Async_Value";
3
+ export * from "./Computed_Value";
4
+ export * from "./Dictionary";
5
+ export * from "./Lookup";
6
+ export * from "./Optional_Value";
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Array"), exports);
18
+ __exportStar(require("./Async_Value"), exports);
19
+ __exportStar(require("./Computed_Value"), exports);
20
+ __exportStar(require("./Dictionary"), exports);
21
+ __exportStar(require("./Lookup"), exports);
22
+ __exportStar(require("./Optional_Value"), exports);
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "exupery-core-types",
3
+ "version": "0.1.0",
4
+ "license": "Apache-2.0",
5
+ "author": "Corno",
6
+ "description": "core types for Exupery",
7
+ "keywords": [
8
+ "exupery",
9
+ "type system",
10
+ "Dictionary",
11
+ "Array",
12
+ "Async_Value",
13
+ "Optional_Value",
14
+ "Nested",
15
+ "Computed_Value"
16
+ ],
17
+ "homepage": "https://github.com/corno/exupery-core#readme",
18
+ "bugs": {
19
+ "url": "https://github.com/corno/exupery-core/issues"
20
+ },
21
+ "types": "dist/index.d.ts",
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/corno/exupery-core.git"
28
+ }
29
+ }