exupery-core-internals 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.
- package/dist/imp/private/create_async_registry.d.ts +14 -0
- package/dist/imp/private/create_async_registry.js +51 -0
- package/dist/imp/public/array_literal.d.ts +9 -0
- package/dist/imp/public/array_literal.js +79 -0
- package/dist/imp/public/assert_unreachable.d.ts +15 -0
- package/dist/imp/public/assert_unreachable.js +20 -0
- package/dist/imp/public/block.d.ts +12 -0
- package/dist/imp/public/block.js +17 -0
- package/dist/imp/public/cast_to_async_value_imp.d.ts +8 -0
- package/dist/imp/public/cast_to_async_value_imp.js +29 -0
- package/dist/imp/public/change_context.d.ts +15 -0
- package/dist/imp/public/change_context.js +20 -0
- package/dist/imp/public/dictionary_literal.d.ts +11 -0
- package/dist/imp/public/dictionary_literal.js +114 -0
- package/dist/imp/public/get_location_info.d.ts +13 -0
- package/dist/imp/public/get_location_info.js +80 -0
- package/dist/imp/public/make_async.d.ts +7 -0
- package/dist/imp/public/make_async.js +14 -0
- package/dist/imp/public/not_set.d.ts +8 -0
- package/dist/imp/public/not_set.js +26 -0
- package/dist/imp/public/panic.d.ts +10 -0
- package/dist/imp/public/panic.js +23 -0
- package/dist/imp/public/resolve_async_tuple_2.d.ts +6 -0
- package/dist/imp/public/resolve_async_tuple_2.js +27 -0
- package/dist/imp/public/set.d.ts +7 -0
- package/dist/imp/public/set.js +32 -0
- package/dist/imp/public/switch_state.d.ts +19 -0
- package/dist/imp/public/switch_state.js +23 -0
- package/dist/imp/types/Execute.d.ts +5 -0
- package/dist/imp/types/Execute.js +2 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +29 -0
- package/package.json +32 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type I_Async_Registry = {
|
|
2
|
+
readonly 'register': () => void;
|
|
3
|
+
readonly 'report_finished': () => void;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* this function provides a callback with a counter as parameter
|
|
7
|
+
* when the counter reaches 0, the onEnd callback is called
|
|
8
|
+
*
|
|
9
|
+
* this function is specifically useful for async map functions
|
|
10
|
+
*
|
|
11
|
+
* @param callback this callback creates a scope within which the counter is provided
|
|
12
|
+
* @param onEnd this callback will be called when the counter reaches 0
|
|
13
|
+
*/
|
|
14
|
+
export declare function create_async_registry(registration_phase: ($: I_Async_Registry) => void, on_all_finished: () => void): void;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create_async_registry = create_async_registry;
|
|
4
|
+
/**
|
|
5
|
+
* this function provides a callback with a counter as parameter
|
|
6
|
+
* when the counter reaches 0, the onEnd callback is called
|
|
7
|
+
*
|
|
8
|
+
* this function is specifically useful for async map functions
|
|
9
|
+
*
|
|
10
|
+
* @param callback this callback creates a scope within which the counter is provided
|
|
11
|
+
* @param onEnd this callback will be called when the counter reaches 0
|
|
12
|
+
*/
|
|
13
|
+
function create_async_registry(registration_phase, on_all_finished) {
|
|
14
|
+
let counter = 0;
|
|
15
|
+
/*
|
|
16
|
+
* we need to keep track of if the registration phase is ended or not.
|
|
17
|
+
* it can happen that the counter reaches 0 during the registration phase, specifically if there is no real async calls being made
|
|
18
|
+
* in that case the reportFinished counter is als called during the registration phase.
|
|
19
|
+
* If that happens there should not yet be a call to onEnd().
|
|
20
|
+
*/
|
|
21
|
+
let registration_phase_ended = false;
|
|
22
|
+
let on_all_finished_has_been_called = false;
|
|
23
|
+
function checkStatus() {
|
|
24
|
+
if (registration_phase_ended) {
|
|
25
|
+
if (counter === 0) {
|
|
26
|
+
if (on_all_finished_has_been_called === true) {
|
|
27
|
+
throw new Error("CORE: already ended");
|
|
28
|
+
}
|
|
29
|
+
on_all_finished_has_been_called = true;
|
|
30
|
+
on_all_finished();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
registration_phase({
|
|
35
|
+
register: () => {
|
|
36
|
+
if (on_all_finished_has_been_called) {
|
|
37
|
+
throw new Error("CORE: async call done after context is ready");
|
|
38
|
+
}
|
|
39
|
+
counter += 1;
|
|
40
|
+
},
|
|
41
|
+
report_finished: () => {
|
|
42
|
+
if (counter === 0) {
|
|
43
|
+
throw new Error("CORE: decrement while counter is 0");
|
|
44
|
+
}
|
|
45
|
+
counter -= 1;
|
|
46
|
+
checkStatus();
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
registration_phase_ended = true;
|
|
50
|
+
checkStatus();
|
|
51
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as pt from "exupery-core-types";
|
|
2
|
+
/**
|
|
3
|
+
* returns a Exupery array
|
|
4
|
+
* why is this not the constructor? to call a constructor, you have to use the keyword 'new'. Exupery doesn't use the concept of a class so that keyword should be avoided
|
|
5
|
+
|
|
6
|
+
* @param source An array literal
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function array_literal<T>(source: readonly T[]): pt.Array<T>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.array_literal = array_literal;
|
|
4
|
+
const create_async_registry_1 = require("../private/create_async_registry");
|
|
5
|
+
const cast_to_async_value_imp_1 = require("./cast_to_async_value_imp");
|
|
6
|
+
const not_set_1 = require("./not_set");
|
|
7
|
+
const set_1 = require("./set");
|
|
8
|
+
/**
|
|
9
|
+
* this is an implementation, not public by design
|
|
10
|
+
* If you feel the need to rename this class, don't rename it to 'Array',
|
|
11
|
+
* it will break the 'instanceOf Array' test
|
|
12
|
+
*/
|
|
13
|
+
class Array_Class {
|
|
14
|
+
constructor(data) {
|
|
15
|
+
this.data = data;
|
|
16
|
+
}
|
|
17
|
+
map($v) {
|
|
18
|
+
return array_literal(this.data.map((entry) => {
|
|
19
|
+
return $v(entry);
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
async_map($v) {
|
|
23
|
+
// const elements = source.map($v)
|
|
24
|
+
// let _isGuaranteedToReturnAResult = true
|
|
25
|
+
// source.forEach(($) => {
|
|
26
|
+
// if ($)
|
|
27
|
+
// })
|
|
28
|
+
function array(array, $v) {
|
|
29
|
+
const mapped = array.map($v);
|
|
30
|
+
return (0, cast_to_async_value_imp_1.cast_to_async_value_imp)(($c) => {
|
|
31
|
+
const temp = [];
|
|
32
|
+
(0, create_async_registry_1.create_async_registry)((registry) => {
|
|
33
|
+
mapped.forEach((v) => {
|
|
34
|
+
registry.register();
|
|
35
|
+
v.__execute((v) => {
|
|
36
|
+
temp.push(v);
|
|
37
|
+
registry.report_finished();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}, () => {
|
|
41
|
+
$c(array_literal(temp));
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return array(this.data, $v);
|
|
46
|
+
}
|
|
47
|
+
/////////
|
|
48
|
+
__for_each($i) {
|
|
49
|
+
this.data.forEach(($) => {
|
|
50
|
+
$i($);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
__get_length() {
|
|
54
|
+
return this.data.length;
|
|
55
|
+
}
|
|
56
|
+
__get_element_at(index) {
|
|
57
|
+
if (index < 0 || index >= this.data.length) {
|
|
58
|
+
return (0, not_set_1.not_set)();
|
|
59
|
+
}
|
|
60
|
+
return (0, set_1.set)(this.data[index]);
|
|
61
|
+
}
|
|
62
|
+
__get_raw_copy() {
|
|
63
|
+
return this.data.slice();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* returns a Exupery array
|
|
68
|
+
* why is this not the constructor? to call a constructor, you have to use the keyword 'new'. Exupery doesn't use the concept of a class so that keyword should be avoided
|
|
69
|
+
|
|
70
|
+
* @param source An array literal
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
function array_literal(source) {
|
|
74
|
+
const data = source.slice(); //create a copy
|
|
75
|
+
if (!(data instanceof Array)) {
|
|
76
|
+
throw new Error("invalid input in 'array_literal'");
|
|
77
|
+
}
|
|
78
|
+
return new Array_Class(source);
|
|
79
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* au means 'assert unreachable'. Used in the 'default' clause of switch statements to ensure
|
|
3
|
+
* during compile time that all possible cases have been implemented
|
|
4
|
+
*
|
|
5
|
+
* example:
|
|
6
|
+
*
|
|
7
|
+
* switch (x) {
|
|
8
|
+
* case "5":
|
|
9
|
+
* break
|
|
10
|
+
* default: au(x)
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* @param _x
|
|
14
|
+
*/
|
|
15
|
+
export declare function au<RT>(_x: never): RT;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.au = au;
|
|
4
|
+
/**
|
|
5
|
+
* au means 'assert unreachable'. Used in the 'default' clause of switch statements to ensure
|
|
6
|
+
* during compile time that all possible cases have been implemented
|
|
7
|
+
*
|
|
8
|
+
* example:
|
|
9
|
+
*
|
|
10
|
+
* switch (x) {
|
|
11
|
+
* case "5":
|
|
12
|
+
* break
|
|
13
|
+
* default: au(x)
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* @param _x
|
|
17
|
+
*/
|
|
18
|
+
function au(_x) {
|
|
19
|
+
throw new Error("unreachable");
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* this function allows to create a statement block in an expression (without changing the context)
|
|
4
|
+
*
|
|
5
|
+
* example:
|
|
6
|
+
*
|
|
7
|
+
* const result = 5 + (() => {
|
|
8
|
+
* const intermediate_variable = 4
|
|
9
|
+
* return intermediate_variable
|
|
10
|
+
* })
|
|
11
|
+
*/
|
|
12
|
+
export declare function block<RT>(callback: () => RT): RT;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.block = block;
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* this function allows to create a statement block in an expression (without changing the context)
|
|
7
|
+
*
|
|
8
|
+
* example:
|
|
9
|
+
*
|
|
10
|
+
* const result = 5 + (() => {
|
|
11
|
+
* const intermediate_variable = 4
|
|
12
|
+
* return intermediate_variable
|
|
13
|
+
* })
|
|
14
|
+
*/
|
|
15
|
+
function block(callback) {
|
|
16
|
+
return callback();
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as pt from "exupery-core-types";
|
|
2
|
+
import { Execute } from "../types/Execute";
|
|
3
|
+
/**
|
|
4
|
+
* returns an {@link Async_Value }
|
|
5
|
+
* @param execute the function that produces the eventual value
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function cast_to_async_value_imp<T>(execute: Execute<T>): pt.Async_Value<T>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cast_to_async_value_imp = cast_to_async_value_imp;
|
|
4
|
+
class Async_Value_Class {
|
|
5
|
+
constructor(execute) {
|
|
6
|
+
this.execute = execute;
|
|
7
|
+
}
|
|
8
|
+
map($v) {
|
|
9
|
+
function rewrite(source, rewrite) {
|
|
10
|
+
return cast_to_async_value_imp(((cb) => {
|
|
11
|
+
source((v) => {
|
|
12
|
+
rewrite(v).__execute(cb);
|
|
13
|
+
});
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
return rewrite(this.execute, $v);
|
|
17
|
+
}
|
|
18
|
+
__execute($i) {
|
|
19
|
+
this.execute($i);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* returns an {@link Async_Value }
|
|
24
|
+
* @param execute the function that produces the eventual value
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
function cast_to_async_value_imp(execute) {
|
|
28
|
+
return new Async_Value_Class(execute);
|
|
29
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cc means 'change context'. It creates a new scope in which a variable name can be used again
|
|
3
|
+
* (usually '$', a variable name that indicates the current context in exupery)
|
|
4
|
+
*
|
|
5
|
+
* example:
|
|
6
|
+
*
|
|
7
|
+
* cc($[1], ($) => {
|
|
8
|
+
* //here $[1] has become $
|
|
9
|
+
* })
|
|
10
|
+
*
|
|
11
|
+
* @param input
|
|
12
|
+
* @param callback
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function cc<T, RT>(input: T, callback: (output: T) => RT): RT;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cc = cc;
|
|
4
|
+
/**
|
|
5
|
+
* cc means 'change context'. It creates a new scope in which a variable name can be used again
|
|
6
|
+
* (usually '$', a variable name that indicates the current context in exupery)
|
|
7
|
+
*
|
|
8
|
+
* example:
|
|
9
|
+
*
|
|
10
|
+
* cc($[1], ($) => {
|
|
11
|
+
* //here $[1] has become $
|
|
12
|
+
* })
|
|
13
|
+
*
|
|
14
|
+
* @param input
|
|
15
|
+
* @param callback
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
function cc(input, callback) {
|
|
19
|
+
return callback(input);
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as pt from "exupery-core-types";
|
|
2
|
+
/**
|
|
3
|
+
* returns a Exupery dictionary
|
|
4
|
+
*
|
|
5
|
+
* why is this not the constructor? to call a constructor, you have to use the keyword 'new'. Exupery doesn't use the concept of a class so that keyword should be avoided
|
|
6
|
+
* @param source An object literal
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function dictionary_literal<T>(source: {
|
|
10
|
+
readonly [key: string]: T;
|
|
11
|
+
}): pt.Dictionary<T>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dictionary_literal = dictionary_literal;
|
|
4
|
+
const create_async_registry_1 = require("../private/create_async_registry");
|
|
5
|
+
const cast_to_async_value_imp_1 = require("./cast_to_async_value_imp");
|
|
6
|
+
const set_1 = require("./set");
|
|
7
|
+
const not_set_1 = require("./not_set");
|
|
8
|
+
const array_literal_1 = require("./array_literal");
|
|
9
|
+
/**
|
|
10
|
+
* this is an implementation, not public by design
|
|
11
|
+
*/
|
|
12
|
+
class Dictionary {
|
|
13
|
+
constructor(source) {
|
|
14
|
+
this.source = source;
|
|
15
|
+
}
|
|
16
|
+
map($v) {
|
|
17
|
+
return new Dictionary(this.source.map(($) => {
|
|
18
|
+
return {
|
|
19
|
+
key: $.key,
|
|
20
|
+
value: $v($.value, $.key)
|
|
21
|
+
};
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
async_map($v) {
|
|
25
|
+
function imp(dictionary_as_array, $v) {
|
|
26
|
+
const mapped = dictionary_as_array.map(($) => {
|
|
27
|
+
return {
|
|
28
|
+
key: $.key,
|
|
29
|
+
value: $v($.value),
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
return (0, cast_to_async_value_imp_1.cast_to_async_value_imp)((cb) => {
|
|
33
|
+
const temp = {};
|
|
34
|
+
(0, create_async_registry_1.create_async_registry)((counter) => {
|
|
35
|
+
mapped.map(($) => {
|
|
36
|
+
counter.register();
|
|
37
|
+
$.value.__execute((nv) => {
|
|
38
|
+
temp[$.key] = nv;
|
|
39
|
+
counter.report_finished();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}, () => {
|
|
43
|
+
cb(dictionary_literal(temp));
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return imp(this.source, $v);
|
|
48
|
+
}
|
|
49
|
+
__map_with_key($v) {
|
|
50
|
+
return new Dictionary(this.source.map(($) => {
|
|
51
|
+
return {
|
|
52
|
+
key: $.key,
|
|
53
|
+
value: $v($.value, $.key),
|
|
54
|
+
};
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
to_array(compare) {
|
|
58
|
+
const sorted_keys = this.source.slice().sort(compare);
|
|
59
|
+
return (0, array_literal_1.array_literal)(sorted_keys);
|
|
60
|
+
}
|
|
61
|
+
__get_entry(key) {
|
|
62
|
+
for (let i = 0; i !== this.source.length; i += 1) {
|
|
63
|
+
const element = this.source[i];
|
|
64
|
+
if (element.key === key) {
|
|
65
|
+
return (0, set_1.set)(element.value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return (0, not_set_1.not_set)();
|
|
69
|
+
}
|
|
70
|
+
__add_entry_if_not_exists(key, value) {
|
|
71
|
+
for (let i = 0; i !== this.source.length; i += 1) {
|
|
72
|
+
const element = this.source[i];
|
|
73
|
+
if (element.key === key) {
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return new Dictionary([...this.source, { key: key, value: value }]);
|
|
78
|
+
}
|
|
79
|
+
__add_entry_overwrite_if_exists(key, value) {
|
|
80
|
+
return new Dictionary(this.source.map((entry) => {
|
|
81
|
+
if (entry.key === key) {
|
|
82
|
+
return { key: key, value: value };
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return entry;
|
|
86
|
+
}
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
__remove_entry_if_exists(key) {
|
|
90
|
+
return new Dictionary(this.source.filter((entry) => {
|
|
91
|
+
return entry.key !== key;
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* returns a Exupery dictionary
|
|
97
|
+
*
|
|
98
|
+
* why is this not the constructor? to call a constructor, you have to use the keyword 'new'. Exupery doesn't use the concept of a class so that keyword should be avoided
|
|
99
|
+
* @param source An object literal
|
|
100
|
+
* @returns
|
|
101
|
+
*/
|
|
102
|
+
function dictionary_literal(source) {
|
|
103
|
+
//first we clone the source data so that changes to that source will have no impact on this implementation.
|
|
104
|
+
//only works if the set does not become extremely large
|
|
105
|
+
function create_dictionary_as_array(source) {
|
|
106
|
+
const imp = [];
|
|
107
|
+
Object.keys(source).forEach((key) => {
|
|
108
|
+
imp.push({ key: key, value: source[key] });
|
|
109
|
+
});
|
|
110
|
+
return imp;
|
|
111
|
+
}
|
|
112
|
+
const daa = create_dictionary_as_array(source);
|
|
113
|
+
return new Dictionary(daa);
|
|
114
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type Source_Location = {
|
|
2
|
+
'file': string;
|
|
3
|
+
'line': number;
|
|
4
|
+
'column': number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* provides the source location (filepath and line number) of the source code file where this function is called,
|
|
8
|
+
* or if the depth is bigger than 0, the source location of the function at that stack depth
|
|
9
|
+
* @param depth
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare function get_location_info(depth: number): Source_Location;
|
|
13
|
+
export declare function location_to_string(location: Source_Location): string;
|
|
@@ -0,0 +1,80 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.get_location_info = get_location_info;
|
|
27
|
+
exports.location_to_string = location_to_string;
|
|
28
|
+
const process = __importStar(require("process"));
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @returns the string on the specified line
|
|
33
|
+
*/
|
|
34
|
+
function get_line(e, depth) {
|
|
35
|
+
const regex = /\((.*)\)$/;
|
|
36
|
+
//const regex = /\((.*):(\d+):(\d+)\)$/ //further splitted; file,line,column,
|
|
37
|
+
if (e.stack === undefined) {
|
|
38
|
+
throw new Error("NO STACK INFO");
|
|
39
|
+
}
|
|
40
|
+
const line = e.stack.split("\n")[depth + 2];
|
|
41
|
+
const match = regex.exec(line);
|
|
42
|
+
//determine the path relative to the current working directory
|
|
43
|
+
return path.relative(process.cwd(), (() => {
|
|
44
|
+
if (match === null) {
|
|
45
|
+
const begin = " at /";
|
|
46
|
+
if (line.startsWith(begin)) {
|
|
47
|
+
return path.relative(process.cwd(), line.substring(begin.length - 1));
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error(`COULD NOT PARSE STACK LINE: ${line}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return match[1];
|
|
55
|
+
}
|
|
56
|
+
})());
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* provides the source location (filepath and line number) of the source code file where this function is called,
|
|
60
|
+
* or if the depth is bigger than 0, the source location of the function at that stack depth
|
|
61
|
+
* @param depth
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
function get_location_info(depth) {
|
|
65
|
+
//we create an error, not to be thrown but to be disected for its stack
|
|
66
|
+
const e = new Error(); //don't move this statement to another function, it will change the depth of its stack
|
|
67
|
+
const line = get_line(e, depth);
|
|
68
|
+
const split = line.split(":");
|
|
69
|
+
if (split.length !== 3) {
|
|
70
|
+
throw new Error(`UNEXPECTED LOCATION FORMAT (CHECK THE DEPTH PARAMETER): ${line} (Expected 'file:line:column')`);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
'file': split[0],
|
|
74
|
+
'line': Number(split[1]),
|
|
75
|
+
'column': Number(split[2]),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function location_to_string(location) {
|
|
79
|
+
return `${location.file}:${location.line}:${location.column}`;
|
|
80
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.make_async = make_async;
|
|
4
|
+
const cast_to_async_value_imp_1 = require("./cast_to_async_value_imp");
|
|
5
|
+
/**
|
|
6
|
+
* converts a regular value to a {@link Async_Value}
|
|
7
|
+
* @param $ the value
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
function make_async($) {
|
|
11
|
+
return (0, cast_to_async_value_imp_1.cast_to_async_value_imp)(($c) => {
|
|
12
|
+
$c($);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as pt from "exupery-core-types";
|
|
2
|
+
/**
|
|
3
|
+
* why is this not the constructor? to call a constructor, you have to use the keyword 'new'. Exupery doesn't use the concept of a class so that keyword should be avoided
|
|
4
|
+
|
|
5
|
+
* creates a not set Optional_Value
|
|
6
|
+
* @returns Optional_Value of type T
|
|
7
|
+
*/
|
|
8
|
+
export declare function not_set<T>(): pt.Optional_Value<T>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.not_set = not_set;
|
|
4
|
+
/**
|
|
5
|
+
* this is an implementation, not public by design
|
|
6
|
+
*/
|
|
7
|
+
class Not_Set_Value {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.__raw = [false];
|
|
10
|
+
}
|
|
11
|
+
transform(set, not_set) {
|
|
12
|
+
return not_set();
|
|
13
|
+
}
|
|
14
|
+
map(set) {
|
|
15
|
+
return not_set();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* why is this not the constructor? to call a constructor, you have to use the keyword 'new'. Exupery doesn't use the concept of a class so that keyword should be avoided
|
|
20
|
+
|
|
21
|
+
* creates a not set Optional_Value
|
|
22
|
+
* @returns Optional_Value of type T
|
|
23
|
+
*/
|
|
24
|
+
function not_set() {
|
|
25
|
+
return new Not_Set_Value();
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function panic_for_internal_functions(depth: number, message: string): never;
|
|
2
|
+
/**
|
|
3
|
+
* call this function if an error is en encountered that is unrecoverable
|
|
4
|
+
* and the application should terminate immediately
|
|
5
|
+
* this avoids throwing an Error because those can always be caught, which could lead to
|
|
6
|
+
* misuse of library functionality
|
|
7
|
+
*
|
|
8
|
+
* @param message message to be printed on stderr
|
|
9
|
+
*/
|
|
10
|
+
export declare function panic(message: string): never;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.panic_for_internal_functions = panic_for_internal_functions;
|
|
4
|
+
exports.panic = panic;
|
|
5
|
+
const get_location_info_1 = require("./get_location_info");
|
|
6
|
+
function panic_for_internal_functions(depth, message) {
|
|
7
|
+
const location = (0, get_location_info_1.get_location_info)(depth + 1);
|
|
8
|
+
console.error(`PANIC: ${message} @ ${(0, get_location_info_1.location_to_string)(location)}`);
|
|
9
|
+
const e = new Error();
|
|
10
|
+
console.error(e.stack);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* call this function if an error is en encountered that is unrecoverable
|
|
15
|
+
* and the application should terminate immediately
|
|
16
|
+
* this avoids throwing an Error because those can always be caught, which could lead to
|
|
17
|
+
* misuse of library functionality
|
|
18
|
+
*
|
|
19
|
+
* @param message message to be printed on stderr
|
|
20
|
+
*/
|
|
21
|
+
function panic(message) {
|
|
22
|
+
panic_for_internal_functions(1, message);
|
|
23
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as pt from 'exupery-core-types';
|
|
2
|
+
export type Sync_Tuple_2<T1, T2> = {
|
|
3
|
+
readonly 'first': T1;
|
|
4
|
+
readonly 'second': T2;
|
|
5
|
+
};
|
|
6
|
+
export declare function resolve_async_tuple_2<T1, T2>(first: pt.Async_Value<T1>, second: pt.Async_Value<T2>): pt.Async_Value<Sync_Tuple_2<T1, T2>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolve_async_tuple_2 = resolve_async_tuple_2;
|
|
4
|
+
const cast_to_async_value_imp_1 = require("./cast_to_async_value_imp");
|
|
5
|
+
function resolve_async_tuple_2(first, second) {
|
|
6
|
+
return (0, cast_to_async_value_imp_1.cast_to_async_value_imp)((cb) => {
|
|
7
|
+
let element_1_is_set = false;
|
|
8
|
+
let element_2_is_set = false;
|
|
9
|
+
let elem1;
|
|
10
|
+
let elem2;
|
|
11
|
+
function wrap_up() {
|
|
12
|
+
if (element_1_is_set && element_2_is_set) {
|
|
13
|
+
cb({ first: elem1, second: elem2 });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
first.__execute((val) => {
|
|
17
|
+
elem1 = val;
|
|
18
|
+
element_1_is_set = true;
|
|
19
|
+
wrap_up();
|
|
20
|
+
});
|
|
21
|
+
second.__execute((val) => {
|
|
22
|
+
elem2 = val;
|
|
23
|
+
element_2_is_set = true;
|
|
24
|
+
wrap_up();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.set = set;
|
|
4
|
+
/**
|
|
5
|
+
* this is an implementation, not public by design
|
|
6
|
+
*/
|
|
7
|
+
class Set_Value {
|
|
8
|
+
constructor(source) {
|
|
9
|
+
this.source = source;
|
|
10
|
+
this.__raw = [true, source];
|
|
11
|
+
this.value = source;
|
|
12
|
+
}
|
|
13
|
+
transform(set, not_set) {
|
|
14
|
+
if (this.__raw[0] === true) {
|
|
15
|
+
return set(this.__raw[1]);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return not_set();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
map(if_set) {
|
|
22
|
+
return set(if_set(this.value));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* returns a set {@link Optional_Value}.
|
|
27
|
+
|
|
28
|
+
* @param $ the set value
|
|
29
|
+
*/
|
|
30
|
+
function set($) {
|
|
31
|
+
return new Set_Value($);
|
|
32
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type State<T> = readonly [string | boolean, T];
|
|
2
|
+
/**
|
|
3
|
+
* ss means 'switch state'.
|
|
4
|
+
* used to make the value T the context variable ('$')
|
|
5
|
+
* given a tuple of a string (or boolean) and a value T,
|
|
6
|
+
* the function takes the value T and calls back the callback ($c)
|
|
7
|
+
* notice that the string part is never used
|
|
8
|
+
*
|
|
9
|
+
* example:
|
|
10
|
+
*
|
|
11
|
+
* switch ($.state[0]) {
|
|
12
|
+
* case "on":
|
|
13
|
+
* return ss($.state, ($) => $.value
|
|
14
|
+
* case "off":
|
|
15
|
+
* return ss($.state, ($) => null
|
|
16
|
+
* default: au($.state[0])
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
export declare function ss<T, RT>($: State<T>, $c: ($: T) => RT): RT;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ss = ss;
|
|
4
|
+
/**
|
|
5
|
+
* ss means 'switch state'.
|
|
6
|
+
* used to make the value T the context variable ('$')
|
|
7
|
+
* given a tuple of a string (or boolean) and a value T,
|
|
8
|
+
* the function takes the value T and calls back the callback ($c)
|
|
9
|
+
* notice that the string part is never used
|
|
10
|
+
*
|
|
11
|
+
* example:
|
|
12
|
+
*
|
|
13
|
+
* switch ($.state[0]) {
|
|
14
|
+
* case "on":
|
|
15
|
+
* return ss($.state, ($) => $.value
|
|
16
|
+
* case "off":
|
|
17
|
+
* return ss($.state, ($) => null
|
|
18
|
+
* default: au($.state[0])
|
|
19
|
+
* }
|
|
20
|
+
*/
|
|
21
|
+
function ss($, $c) {
|
|
22
|
+
return $c($[1]);
|
|
23
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./imp/public/dictionary_literal";
|
|
2
|
+
export * from "./imp/public/array_literal";
|
|
3
|
+
export * from "./imp/public/panic";
|
|
4
|
+
export * from "./imp/public/assert_unreachable";
|
|
5
|
+
export * from "./imp/public/change_context";
|
|
6
|
+
export * from "./imp/public/block";
|
|
7
|
+
export * from "./imp/public/switch_state";
|
|
8
|
+
export * from "./imp/public/get_location_info";
|
|
9
|
+
export * from "./imp/public/resolve_async_tuple_2";
|
|
10
|
+
export * from "./imp/public/make_async";
|
|
11
|
+
export * from "./imp/public/cast_to_async_value_imp";
|
|
12
|
+
export * from "./imp/public/set";
|
|
13
|
+
export * from "./imp/public/not_set";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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("./imp/public/dictionary_literal"), exports);
|
|
18
|
+
__exportStar(require("./imp/public/array_literal"), exports);
|
|
19
|
+
__exportStar(require("./imp/public/panic"), exports);
|
|
20
|
+
__exportStar(require("./imp/public/assert_unreachable"), exports);
|
|
21
|
+
__exportStar(require("./imp/public/change_context"), exports);
|
|
22
|
+
__exportStar(require("./imp/public/block"), exports);
|
|
23
|
+
__exportStar(require("./imp/public/switch_state"), exports);
|
|
24
|
+
__exportStar(require("./imp/public/get_location_info"), exports);
|
|
25
|
+
__exportStar(require("./imp/public/resolve_async_tuple_2"), exports);
|
|
26
|
+
__exportStar(require("./imp/public/make_async"), exports);
|
|
27
|
+
__exportStar(require("./imp/public/cast_to_async_value_imp"), exports);
|
|
28
|
+
__exportStar(require("./imp/public/set"), exports);
|
|
29
|
+
__exportStar(require("./imp/public/not_set"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "exupery-core-internals",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "ISC",
|
|
5
|
+
"description": "",
|
|
6
|
+
"author": "Corno",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"exupery",
|
|
9
|
+
"internals",
|
|
10
|
+
"wrapRawDictionary",
|
|
11
|
+
"wrapRawArray"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/corno/exupery-core#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/corno/exupery-core/issues"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"exupery-core-types": "^0.1.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^18.15.3"
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "dist/index.d.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/corno/exupery-core-internals.git"
|
|
31
|
+
}
|
|
32
|
+
}
|