ctx-core 4.18.0 → 5.0.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/all/CacheControl_1hour_headers_/index.d.ts +5 -0
- package/all/CacheControl_1hour_headers_/index.js +10 -0
- package/all/CacheControl_5min_headers_/index.d.ts +5 -0
- package/all/CacheControl_5min_headers_/index.js +10 -0
- package/all/ContentType__is_binary_/index.d.ts +1 -0
- package/all/ContentType__is_binary_/index.js +9 -0
- package/all/ContentType_json_headers_/index.d.ts +5 -0
- package/all/ContentType_json_headers_/index.js +10 -0
- package/all/ContentType_svg_headers_/index.d.ts +5 -0
- package/all/ContentType_svg_headers_/index.js +10 -0
- package/all/a_in_idx_a_map/index.d.ts +1 -3
- package/all/a_item/index.d.ts +3 -9
- package/all/a_length/index.d.ts +4 -7
- package/all/a_nowrap/index.d.ts +1 -3
- package/all/a_present/index.d.ts +4 -7
- package/all/a_some/index.d.ts +1 -3
- package/all/and/index.d.ts +3 -9
- package/all/and_call/index.d.ts +4 -8
- package/all/andand/index.d.ts +4 -11
- package/all/andand_or/index.d.ts +6 -8
- package/all/andandfn/index.d.ts +3 -12
- package/all/apply/index.d.ts +2 -2
- package/all/arg_i0_a/index.d.ts +1 -1
- package/all/array_types/index.d.ts +21 -28
- package/all/assign_fn_key_a/index.d.ts +1 -3
- package/all/be/index.d.ts +5 -3
- package/all/be_/index.d.ts +69 -48
- package/all/be_/index.js +39 -76
- package/all/be_/index.test.ts +244 -121
- package/all/be_lock_memosig_triple/index.d.ts +16 -22
- package/all/be_lock_memosig_triple/index.test.ts +47 -36
- package/all/be_memo_pair/index.d.ts +14 -11
- package/all/be_memo_pair/index.js +1 -2
- package/all/be_memo_pair/index.test.ts +47 -31
- package/all/be_memosig_triple/index.d.ts +16 -22
- package/all/be_memosig_triple/index.test.ts +48 -34
- package/all/be_sig_triple/index.d.ts +16 -13
- package/all/be_sig_triple/index.js +2 -3
- package/all/be_sig_triple/index.test.ts +42 -29
- package/all/bind_apply/index.d.ts +3 -3
- package/all/bind_call/index.d.ts +10 -11
- package/all/bind_map_apply/index.d.ts +2 -2
- package/all/bind_map_call/index.d.ts +2 -2
- package/all/call/index.d.ts +3 -3
- package/all/call_assign/index.d.ts +2 -6
- package/all/call_fn_a/index.d.ts +4 -3
- package/all/call_or_fn/index.d.ts +1 -4
- package/all/chain/index.d.ts +4 -8
- package/all/chunk_aa/index.d.ts +3 -5
- package/all/clear_ctx/index.d.ts +1 -3
- package/all/combinators/index.d.ts +12 -49
- package/all/compact/index.d.ts +4 -7
- package/all/compact_a_ctx/index.d.ts +1 -3
- package/all/compare/index.d.ts +1 -3
- package/all/compose/index.d.ts +3 -3
- package/all/concat/index.d.ts +2 -6
- package/all/concat_truthy_a/index.d.ts +3 -4
- package/all/ctx/index.d.ts +18 -2
- package/all/ctx/index.js +20 -8
- package/all/ctx/index.test.ts +33 -7
- package/all/curry/index.d.ts +5 -7
- package/all/curry/index.js +6 -3
- package/all/debounce/index.d.ts +12 -12
- package/all/difference_a/index.d.ts +1 -3
- package/all/difference_by/index.d.ts +3 -4
- package/all/difference_set/index.d.ts +1 -5
- package/all/each/index.d.ts +5 -9
- package/all/ensure/index.d.ts +1 -3
- package/all/ensure__refresh/index.d.ts +1 -3
- package/all/eq/index.d.ts +4 -10
- package/all/eql/index.d.ts +3 -9
- package/all/eql_a/index.d.ts +1 -3
- package/all/eql_fn_a/index.d.ts +1 -3
- package/all/every/index.d.ts +3 -9
- package/all/exclude/index.d.ts +1 -4
- package/all/ext_R_mime/index.d.ts +86 -0
- package/all/ext_R_mime/index.js +86 -0
- package/all/falsy_async_guard/index.d.ts +3 -4
- package/all/falsy_guard/index.d.ts +4 -3
- package/all/fetch__template_pair/index.test.ts +5 -5
- package/all/filter/index.d.ts +4 -12
- package/all/find/index.d.ts +6 -10
- package/all/first/index.d.ts +2 -7
- package/all/flatten/index.d.ts +2 -6
- package/all/flip/index.d.ts +3 -3
- package/all/hasOwnProperty_pick/index.d.ts +4 -4
- package/all/head_arg_a/index.d.ts +4 -3
- package/all/http__headers__assign/index.d.ts +11 -0
- package/all/http__headers__assign/index.js +11 -0
- package/all/idx/index.d.ts +1 -3
- package/all/idx_reject/index.d.ts +3 -9
- package/all/idx_sort_a/index.d.ts +1 -3
- package/all/idx_sort_a__sort_idx_o/index.d.ts +1 -3
- package/all/idx_sort_r_a/index.d.ts +1 -3
- package/all/if_null_set_false/index.d.ts +1 -3
- package/all/ifelse/index.d.ts +5 -3
- package/all/iife/index.d.ts +3 -3
- package/all/index.d.ts +9 -0
- package/all/index.js +9 -0
- package/all/internal_server_error__throw/index.d.ts +5 -0
- package/all/internal_server_error__throw/index.js +7 -0
- package/all/intersection_a/index.d.ts +5 -6
- package/all/intersection_by/index.d.ts +3 -4
- package/all/intersection_set/index.d.ts +1 -3
- package/all/isArray/index.d.ts +2 -2
- package/all/last/index.d.ts +2 -7
- package/all/left_and/index.d.ts +1 -3
- package/all/left_or/index.d.ts +1 -3
- package/all/many_andand/index.d.ts +7 -6
- package/all/many_andand_or/index.d.ts +2 -8
- package/all/map/index.d.ts +4 -18
- package/all/map_andand/index.d.ts +3 -9
- package/all/map_andand_or/index.d.ts +1 -3
- package/all/map_andandfn/index.d.ts +2 -6
- package/all/map_apply/index.d.ts +5 -8
- package/all/map_call/index.d.ts +5 -8
- package/all/map_find/index.d.ts +3 -11
- package/all/map_fn/index.d.ts +1 -4
- package/all/map_obj/index.d.ts +3 -12
- package/all/map_obj_andand/index.d.ts +2 -8
- package/all/merge/index.d.ts +1 -4
- package/all/mixin/index.d.ts +1 -4
- package/all/neq/index.d.ts +2 -6
- package/all/neql/index.d.ts +2 -6
- package/all/noinit/index.d.ts +5 -8
- package/all/not/index.d.ts +3 -9
- package/all/notnot/index.d.ts +2 -4
- package/all/nullish__guard/index.d.ts +3 -4
- package/all/nullish__guard__async/index.d.ts +3 -4
- package/all/nullish__none/index.d.ts +1 -3
- package/all/o_a_present/index.d.ts +2 -6
- package/all/o_some/index.d.ts +1 -3
- package/all/offset_destructure_aa/index.d.ts +1 -3
- package/all/offset_i_slice/index.d.ts +2 -6
- package/all/one_andand/index.d.ts +3 -3
- package/all/one_andand_or/index.d.ts +3 -5
- package/all/or/index.d.ts +6 -17
- package/all/or_property/index.d.ts +1 -5
- package/all/promise_timeout/index.d.ts +4 -4
- package/all/prototype_mixin/index.d.ts +4 -3
- package/all/prototype_mixin/index.js +3 -3
- package/all/push/index.d.ts +2 -6
- package/all/r_val_a/index.d.ts +2 -6
- package/all/rank/index.d.ts +3 -4
- package/all/reduce/index.d.ts +10 -23
- package/all/reject/index.d.ts +7 -14
- package/all/remove/index.d.ts +2 -6
- package/all/remove_idx/index.d.ts +4 -4
- package/all/resolver_curry/index.d.ts +2 -2
- package/all/reverse/index.d.ts +2 -10
- package/all/right_and/index.d.ts +1 -3
- package/all/right_or/index.d.ts +1 -3
- package/all/rmemo/index.js +3 -3
- package/all/rmemo__wait/index.test.ts +1 -1
- package/all/run/index.d.ts +1 -4
- package/all/selector_splice/index.d.ts +1 -3
- package/all/slice/index.d.ts +5 -15
- package/all/slice_arg_a/index.d.ts +3 -12
- package/all/slice_arg_spread_a/index.d.ts +3 -11
- package/all/sort/index.d.ts +4 -14
- package/all/sort_a/index.d.ts +2 -6
- package/all/sort_idx_a/index.d.ts +2 -6
- package/all/sort_idx_o/index.d.ts +2 -6
- package/all/sort_val_a/index.d.ts +2 -6
- package/all/sort_val_a__transition_idx_a/index.d.ts +4 -12
- package/all/sort_val_a__transition_idx_a/index.js +4 -2
- package/all/sparse_a/index.d.ts +1 -3
- package/all/splice/index.d.ts +2 -6
- package/all/spread/index.d.ts +2 -6
- package/all/tap/index.d.ts +1 -3
- package/all/test/index.d.ts +12 -0
- package/all/test/index.js +1 -0
- package/all/throttle/index.d.ts +2 -2
- package/all/throttle/index.js +8 -7
- package/all/tick/index.d.ts +1 -5
- package/all/timeout_promise/index.d.ts +1 -5
- package/all/times/index.d.ts +1 -5
- package/all/tup/index.d.ts +22 -6
- package/all/union_a/index.d.ts +1 -3
- package/all/union_set/index.d.ts +1 -5
- package/all/val/index.d.ts +1 -3
- package/all/value_r/index.d.ts +2 -6
- package/all/weak_r/index.d.ts +3 -3
- package/all/wrap_a/index.d.ts +4 -12
- package/all/wrap_a_item/index.d.ts +4 -3
- package/all/wrap_aa/index.d.ts +2 -8
- package/all/wrap_aa_item/index.d.ts +4 -3
- package/all/wrap_concat/index.d.ts +1 -5
- package/http/index.d.ts +8 -0
- package/http/index.js +8 -0
- package/package.json +35 -10
- package/test/index.d.ts +1 -0
- package/test/index.js +1 -0
package/all/be_/index.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('./index.d.ts').be_config_T} */
|
|
4
|
-
/** @typedef {import('./index.d.ts').Ctx} */
|
|
5
|
-
/** @typedef {import('./index.d.ts').MapCtx} */
|
|
6
|
-
/** @typedef {import('./index.d.ts').be__val__new_T} */
|
|
7
|
-
/** @typedef {import('./index.d.ts').is_source__T} */
|
|
1
|
+
/// <reference types="./index.d.ts" />
|
|
2
|
+
let _undefined
|
|
8
3
|
/**
|
|
9
4
|
* Auto-memoization function for the Ctx.
|
|
10
5
|
*
|
|
@@ -16,27 +11,22 @@
|
|
|
16
11
|
* @private
|
|
17
12
|
*/
|
|
18
13
|
export function be_(val__new, config) {
|
|
19
|
-
let be =
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// 'cir' is used instead of 'circular' to reduce the payload by a few bytes
|
|
33
|
-
be__ctx.set(be.id, 'cir')
|
|
34
|
-
be__ctx.set(be.id, val__new(argv__ctx, be))
|
|
35
|
-
}
|
|
36
|
-
return be__ctx.get(be.id)
|
|
14
|
+
let be = ctx=>{
|
|
15
|
+
let be_map = ctx.s[be.ns]
|
|
16
|
+
/* @if DEBUG **
|
|
17
|
+
// ~ 30 B
|
|
18
|
+
if (!be_map) throw Error('ctx_no_ns: \'' + be.ns + '\'')
|
|
19
|
+
/* @endif */
|
|
20
|
+
if (be_map.has(be.id)) return be_map.get(be.id)
|
|
21
|
+
// circular dependency state
|
|
22
|
+
// if val__new calls this be before returning, 'cir' will be the value of this be
|
|
23
|
+
// 'cir' is used instead of 'circular' to reduce the payload by a few bytes
|
|
24
|
+
be_map.set(be.id, 'cir')
|
|
25
|
+
be_map.set(be.id, val__new(ctx, be))
|
|
26
|
+
return be_map.get(be.id)
|
|
37
27
|
}
|
|
38
28
|
be.id = config?.id ?? be
|
|
39
|
-
be.
|
|
29
|
+
be.ns = config?.ns ?? ''
|
|
40
30
|
be.is_be = true
|
|
41
31
|
return be
|
|
42
32
|
}
|
|
@@ -57,7 +47,7 @@ export { be_ as globalThis__be_ }
|
|
|
57
47
|
* @param {Ctx}ctx
|
|
58
48
|
* @param {Be|string|symbol}be_OR_id
|
|
59
49
|
* @param {unknown}val
|
|
60
|
-
* @param {
|
|
50
|
+
* @param {string}[ns]
|
|
61
51
|
* @returns {unknown}
|
|
62
52
|
* @private
|
|
63
53
|
*/
|
|
@@ -65,80 +55,53 @@ export function ctx__set(
|
|
|
65
55
|
ctx,
|
|
66
56
|
be_OR_id,
|
|
67
57
|
val,
|
|
68
|
-
|
|
58
|
+
ns = be_OR_id.ns ?? ''
|
|
69
59
|
) {
|
|
70
|
-
|
|
71
|
-
if (source__map_ctx) {
|
|
72
|
-
source__map_ctx.set(be_OR_id.id ?? be_OR_id, val)
|
|
73
|
-
}
|
|
60
|
+
ctx.s[ns].set(be_OR_id.id ?? be_OR_id, val)
|
|
74
61
|
}
|
|
75
62
|
/**
|
|
76
63
|
* @param {Ctx}ctx
|
|
77
64
|
* @param {Be|string|symbol}be_OR_id
|
|
65
|
+
* @param {string}[ns]
|
|
78
66
|
*/
|
|
79
67
|
export function ctx__delete(
|
|
80
68
|
ctx,
|
|
81
69
|
be_OR_id,
|
|
70
|
+
ns = be_OR_id.ns ?? ''
|
|
82
71
|
) {
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
ctx__delete(_ctx, be_OR_id)
|
|
86
|
-
}
|
|
72
|
+
if (ns != null) {
|
|
73
|
+
ctx.s[ns].delete(be_OR_id.id ?? be_OR_id)
|
|
87
74
|
} else {
|
|
88
|
-
|
|
75
|
+
for (let _source in ctx.s) {
|
|
76
|
+
ctx.s[_source].delete(be_OR_id.id ?? be_OR_id)
|
|
77
|
+
}
|
|
89
78
|
}
|
|
90
79
|
}
|
|
91
80
|
/**
|
|
92
|
-
* @param {Be|string}
|
|
93
|
-
* @param {Ctx}argv__ctx
|
|
81
|
+
* @param {[Be|string, Ctx]|[Be|string, Ctx, string]}arg_a
|
|
94
82
|
* @returns {boolean}
|
|
95
83
|
* @private
|
|
96
84
|
*/
|
|
97
|
-
export function be__has_(
|
|
98
|
-
return Boolean(
|
|
85
|
+
export function be__has_(...arg_a) {
|
|
86
|
+
return Boolean(be_map__find(...arg_a))
|
|
99
87
|
}
|
|
100
88
|
/**
|
|
101
|
-
* @param {Be
|
|
102
|
-
* @param {Ctx}
|
|
103
|
-
* @
|
|
89
|
+
* @param {Be}be_or_id
|
|
90
|
+
* @param {Ctx}ctx
|
|
91
|
+
* @param {string}[ns]
|
|
92
|
+
* @returns {Ctx}
|
|
104
93
|
* @private
|
|
105
94
|
*/
|
|
106
|
-
export function
|
|
107
|
-
|
|
108
|
-
for (let ctx of argv__ctx) {
|
|
109
|
-
let be__ctx = be__ctx_(be_or_id.id ?? be_or_id, ctx)
|
|
110
|
-
if (be__ctx) return be__ctx
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
if (argv__ctx.has(be_or_id.id ?? be_or_id)) return argv__ctx
|
|
114
|
-
}
|
|
95
|
+
export function be_map__find(be_or_id, ctx, ns = be_or_id.ns ?? '') {
|
|
96
|
+
return ctx.s[ns].has(be_or_id.id ?? be_or_id) ? ctx.s[ns] : _undefined
|
|
115
97
|
}
|
|
116
|
-
export { be__ctx_ as be__has__ctx_ }
|
|
117
98
|
/**
|
|
118
99
|
* @param {Be|string}be_or_id
|
|
119
|
-
* @param {Ctx}
|
|
120
|
-
* @
|
|
121
|
-
* @private
|
|
122
|
-
*/
|
|
123
|
-
export function be__val_(be_or_id, argv__ctx) {
|
|
124
|
-
let be__ctx = be__ctx_(be_or_id, argv__ctx)
|
|
125
|
-
if (be__ctx) return be__ctx.get(be_or_id.id ?? be_or_id)
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* @param {Ctx}argv__ctx
|
|
129
|
-
* @param {is_source__T}is_source_
|
|
100
|
+
* @param {Ctx}ctx
|
|
101
|
+
* @param {string}[ns]
|
|
130
102
|
* @returns {unknown}
|
|
131
103
|
* @private
|
|
132
104
|
*/
|
|
133
|
-
export function
|
|
134
|
-
|
|
135
|
-
for (let ctx of argv__ctx) {
|
|
136
|
-
let source__map_ctx = source__map_ctx_(ctx, is_source_)
|
|
137
|
-
if (source__map_ctx) return source__map_ctx
|
|
138
|
-
}
|
|
139
|
-
} else {
|
|
140
|
-
if (!is_source_ || is_source_(argv__ctx, argv__ctx)) {
|
|
141
|
-
return argv__ctx
|
|
142
|
-
}
|
|
143
|
-
}
|
|
105
|
+
export function be__val_(be_or_id, ctx, ns) {
|
|
106
|
+
return be_map__find(be_or_id, ctx, ns)?.get?.(be_or_id.id ?? be_or_id)
|
|
144
107
|
}
|
package/all/be_/index.test.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { test } from 'uvu'
|
|
2
|
-
import { equal } from 'uvu/assert'
|
|
2
|
+
import { equal, is, throws } from 'uvu/assert'
|
|
3
3
|
import {
|
|
4
4
|
type Be,
|
|
5
5
|
be_,
|
|
6
|
-
be__ctx_,
|
|
7
6
|
be__has_,
|
|
8
7
|
be__val_,
|
|
8
|
+
be_map__find,
|
|
9
|
+
type BeMapO,
|
|
9
10
|
type Ctx,
|
|
10
11
|
ctx__delete,
|
|
11
12
|
ctx__set,
|
|
12
|
-
|
|
13
|
-
type
|
|
13
|
+
type Ctx_s_T,
|
|
14
|
+
type Ctx_s_wide_T,
|
|
15
|
+
type Ctx_wide_T,
|
|
16
|
+
globalThis__be_
|
|
14
17
|
} from '../be_/index.js'
|
|
15
|
-
import { ctx__new } from '../ctx/index.js'
|
|
18
|
+
import { ctx_, ctx__new, ns_ctx__new } from '../ctx/index.js'
|
|
19
|
+
import { Equal, Expect } from '../test/index.js'
|
|
16
20
|
test.after(()=>{
|
|
17
21
|
delete (globalThis as { root_be?:Be<unknown> }).root_be
|
|
18
22
|
})
|
|
@@ -23,7 +27,7 @@ test('globalThis__be_', ()=>{
|
|
|
23
27
|
const be2 = globalThis__be_(()=>1, { id: 'root_be' })
|
|
24
28
|
equal(be2(ctx), 1)
|
|
25
29
|
})
|
|
26
|
-
test('be_|
|
|
30
|
+
test('be_|s|BeMap', ()=>{
|
|
27
31
|
const ctx = ctx__new()
|
|
28
32
|
let incrementer_num = 0
|
|
29
33
|
const incrementer = ()=>++incrementer_num
|
|
@@ -37,77 +41,133 @@ test('be_|Map', ()=>{
|
|
|
37
41
|
root_(ctx) + child_(ctx),
|
|
38
42
|
{ id: 'child1_' })
|
|
39
43
|
equal(root_(ctx), 1)
|
|
40
|
-
equal(ctx.get('root_'), 1)
|
|
44
|
+
equal(ctx.s[''].get('root_'), 1)
|
|
41
45
|
equal(child_(ctx), 3)
|
|
42
|
-
equal(ctx.get('child_'), 3)
|
|
46
|
+
equal(ctx.s[''].get('child_'), 3)
|
|
43
47
|
equal(child1_(ctx), 4)
|
|
44
|
-
equal(ctx.get('child1_'), 4)
|
|
48
|
+
equal(ctx.s[''].get('child1_'), 4)
|
|
45
49
|
})
|
|
46
|
-
test('be_|
|
|
50
|
+
test('be_|ns_ctx__new|-ns', ()=>{
|
|
47
51
|
const ctx0 = ctx__new()
|
|
48
52
|
const ctx1 = ctx__new()
|
|
49
|
-
const ctx =
|
|
50
|
-
const root_ = be_(()=>
|
|
53
|
+
const ctx = ns_ctx__new(ctx0, ctx1)
|
|
54
|
+
const root_ = be_(()=>
|
|
55
|
+
1,
|
|
56
|
+
{ id: 'root_' })
|
|
51
57
|
equal(root_(ctx1), 1)
|
|
52
58
|
equal(root_(ctx), 1)
|
|
53
|
-
equal(ctx0.has(root_.id),
|
|
54
|
-
equal(ctx1.has(root_.id), true)
|
|
55
|
-
const child_ = be_(ctx=>
|
|
59
|
+
equal(ctx0.s[''].has(root_.id), true)
|
|
60
|
+
equal(ctx1.s[''].has(root_.id), true)
|
|
61
|
+
const child_ = be_(ctx=>
|
|
62
|
+
root_(ctx) + 1,
|
|
63
|
+
{ id: 'child_' })
|
|
56
64
|
equal(child_(ctx), 2)
|
|
57
|
-
equal(ctx0.has(child_.id), true)
|
|
58
|
-
equal(ctx1.has(child_.id), false)
|
|
65
|
+
equal(ctx0.s[''].has(child_.id), true)
|
|
66
|
+
equal(ctx1.s[''].has(child_.id), false)
|
|
59
67
|
})
|
|
60
|
-
test('be_|
|
|
68
|
+
test('be_|source_ctx__new', ()=>{
|
|
61
69
|
const ctx0 = ctx__new()
|
|
62
70
|
const ctx1 = ctx__new()
|
|
63
71
|
const ctx2 = ctx__new()
|
|
64
72
|
const ctx3 = ctx__new()
|
|
65
|
-
const ctx =
|
|
66
|
-
const root_ = be_(()=>
|
|
73
|
+
const ctx = ns_ctx__new(ctx0, ctx1, ctx2, ctx3)
|
|
74
|
+
const root_ = be_(()=>
|
|
75
|
+
1,
|
|
76
|
+
{ id: 'root_' })
|
|
67
77
|
equal(root_(ctx3), 1)
|
|
68
78
|
equal(root_(ctx), 1)
|
|
69
|
-
equal(ctx0.has(root_.id),
|
|
70
|
-
equal(ctx1.has(root_.id), false)
|
|
71
|
-
equal(ctx2.has(root_.id), false)
|
|
72
|
-
equal(ctx3.has(root_.id), true)
|
|
79
|
+
equal(ctx0.s[''].has(root_.id), true)
|
|
80
|
+
equal(ctx1.s[''].has(root_.id), false)
|
|
81
|
+
equal(ctx2.s[''].has(root_.id), false)
|
|
82
|
+
equal(ctx3.s[''].has(root_.id), true)
|
|
73
83
|
const child_ = be_(ctx=>root_(ctx) + 1, { id: 'child_' })
|
|
74
84
|
equal(child_(ctx), 2)
|
|
75
|
-
equal(ctx0.has(child_.id), true)
|
|
76
|
-
equal(ctx1.has(child_.id), false)
|
|
77
|
-
equal(ctx2.has(child_.id), false)
|
|
78
|
-
equal(ctx3.has(child_.id), false)
|
|
85
|
+
equal(ctx0.s[''].has(child_.id), true)
|
|
86
|
+
equal(ctx1.s[''].has(child_.id), false)
|
|
87
|
+
equal(ctx2.s[''].has(child_.id), false)
|
|
88
|
+
equal(ctx3.s[''].has(child_.id), false)
|
|
79
89
|
})
|
|
80
|
-
test('be_|
|
|
90
|
+
test('be_|ns', ()=>{
|
|
91
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
81
92
|
const ctx0 = ctx__new()
|
|
82
|
-
const ctx1 =
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
const be__ctx_a:Ctx[] = []
|
|
93
|
+
const ctx1 = ns_ctx__new('ctx1')
|
|
94
|
+
const ctx = ns_ctx__new(ctx0, ctx1)
|
|
95
|
+
const be__ctx_a:Ctx_wide_T<'ctx1'>[] = []
|
|
86
96
|
const root_ = be_(ctx=>{
|
|
87
97
|
be__ctx_a.push(ctx)
|
|
88
98
|
return 1
|
|
89
99
|
}, {
|
|
90
|
-
|
|
100
|
+
ns: 'ctx1',
|
|
91
101
|
id: 'root_'
|
|
92
102
|
})
|
|
93
103
|
equal(root_(ctx), 1)
|
|
94
|
-
equal(be__ctx_a, [
|
|
95
|
-
|
|
96
|
-
equal(
|
|
104
|
+
equal(be__ctx_a, [ctx])
|
|
105
|
+
// @ts-expect-error TS2322
|
|
106
|
+
equal(ctx0.s[''].has(root_.id), false)
|
|
107
|
+
// @ts-expect-error TS2322
|
|
108
|
+
equal(ctx1.s[''], undefined)
|
|
109
|
+
equal(ctx1.s['ctx1'].has(root_.id), true)
|
|
110
|
+
})
|
|
111
|
+
test('be_|ns|types', ()=>{
|
|
112
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
113
|
+
const ctx0 = ctx__new()
|
|
114
|
+
type test_ctx0_s = Expect<Equal<typeof ctx0.s, Ctx_s_T<''>>>
|
|
115
|
+
// @ts-expect-error TS2345
|
|
116
|
+
type test_ctx0_s_fail = Expect<Equal<typeof ctx0.s, Ctx_s_T<'fail'>>>
|
|
117
|
+
type test_ctx0 = Expect<Equal<typeof ctx0, Ctx<''>>>
|
|
118
|
+
// @ts-expect-error TS2345
|
|
119
|
+
type test_ctx0_fail = Expect<Equal<typeof ctx0, Ctx<'fail'>>>
|
|
120
|
+
const ctx1 = ns_ctx__new('ctx1')
|
|
121
|
+
type test_ctx1_s = Expect<Equal<typeof ctx1.s, Ctx_s_T<'ctx1'>>>
|
|
122
|
+
// @ts-expect-error TS2345
|
|
123
|
+
type test_ctx1_fail = Expect<Equal<typeof ctx1, Ctx<'fail'>>>
|
|
124
|
+
// @ts-expect-error TS2345
|
|
125
|
+
type test_ctx1_s_fail = Expect<Equal<typeof ctx1, Ctx_s_T<''|'fail'>>>
|
|
126
|
+
type test_ctx1_w_empty_string = Expect<Equal<typeof ctx1, Ctx<'ctx1'>>>
|
|
127
|
+
type test_ctx1 = Expect<Equal<typeof ctx1, Ctx<'ctx1'>>>
|
|
128
|
+
const ctx = ns_ctx__new(ctx0, ctx1)
|
|
129
|
+
type test_ctx_s_wide_T = Expect<Equal<
|
|
130
|
+
typeof ctx.s, typeof ctx extends Ctx_s_wide_T<''|'ctx1'>
|
|
131
|
+
? typeof ctx.s
|
|
132
|
+
: never>>
|
|
133
|
+
type test_ctx_s_BeMapO = Expect<Equal<
|
|
134
|
+
typeof ctx.s, typeof ctx.s extends BeMapO<''|'ctx1'>
|
|
135
|
+
? typeof ctx.s
|
|
136
|
+
: never>>
|
|
137
|
+
type test_ctx_s = Expect<Equal<typeof ctx.s, Ctx_s_T<''|'ctx1'>>>
|
|
138
|
+
type test_ctx_extends = Expect<Equal<
|
|
139
|
+
typeof ctx, typeof ctx extends Ctx_wide_T<''|'ctx1'>
|
|
140
|
+
? typeof ctx
|
|
141
|
+
: never>>
|
|
142
|
+
type test_ctx_Ctx = Expect<Equal<typeof ctx, Ctx<''|'ctx1'>>>
|
|
143
|
+
const root_ = be_(
|
|
144
|
+
ctx=>{
|
|
145
|
+
type test_be_ctx_argument = Expect<Equal<typeof ctx, Ctx_wide_T<'ctx1'>>>
|
|
146
|
+
return 1
|
|
147
|
+
}, {
|
|
148
|
+
ns: 'ctx1',
|
|
149
|
+
id: 'root_'
|
|
150
|
+
})
|
|
151
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
97
152
|
})
|
|
98
153
|
test('be_|Ctx generic type', ()=>{
|
|
99
|
-
const valid_ctx =
|
|
100
|
-
const val_ = be_<boolean,
|
|
154
|
+
const valid_ctx = ns_ctx__new('test_ns')
|
|
155
|
+
const val_ = be_<boolean, 'test_ns'>(()=>
|
|
156
|
+
true,
|
|
157
|
+
{ id: 'val_', ns: 'test_ns' })
|
|
101
158
|
val_(valid_ctx)
|
|
102
|
-
//
|
|
159
|
+
// @ts-expect-error TS2322
|
|
160
|
+
throws(()=>val_(ctx_()))
|
|
103
161
|
})
|
|
104
162
|
test('be_|Ctx|NestedMapCtx', ()=>{
|
|
105
163
|
const ctx0 = ctx__new()
|
|
106
164
|
const ctx1 = ctx__new()
|
|
107
|
-
ctx1.set('matching', true)
|
|
108
|
-
const ctx =
|
|
109
|
-
const nested__ctx_ = be_<Ctx>(ctx=>
|
|
110
|
-
|
|
165
|
+
ctx1.s[''].set('matching', true)
|
|
166
|
+
const ctx = ns_ctx__new(ctx0, ctx1)
|
|
167
|
+
const nested__ctx_ = be_<[Ctx]>(ctx=>
|
|
168
|
+
[ctx],
|
|
169
|
+
{ id: 'nested__ctx_' })
|
|
170
|
+
equal(nested__ctx_(ctx), [ctx])
|
|
111
171
|
})
|
|
112
172
|
test('be_|circular dependency', ()=>{
|
|
113
173
|
const be0:Be<symbol> = be_(ctx=>be1(ctx))
|
|
@@ -117,117 +177,180 @@ test('be_|circular dependency', ()=>{
|
|
|
117
177
|
equal(be1(ctx), 'cir')
|
|
118
178
|
})
|
|
119
179
|
test('ctx__set', ()=>{
|
|
120
|
-
const ctx0 =
|
|
121
|
-
ctx__set(ctx0, 'key', 1)
|
|
122
|
-
equal(ctx0.get('key'), 1)
|
|
180
|
+
const ctx0 = ns_ctx__new('ctx0')
|
|
123
181
|
const ctx1 = ctx__new()
|
|
124
|
-
const
|
|
125
|
-
ctx__set(
|
|
126
|
-
|
|
127
|
-
equal(ctx0.
|
|
128
|
-
equal(
|
|
182
|
+
const source_ctx = ns_ctx__new(ctx1, ctx0)
|
|
183
|
+
ctx__set(source_ctx, 'key', 2, 'ctx0')
|
|
184
|
+
// @ts-expect-error TS7053
|
|
185
|
+
equal(ctx0.s[''], undefined)
|
|
186
|
+
equal(ctx0.s['ctx0'].get('key'), 2)
|
|
187
|
+
equal(ctx1.s[''].has('key'), false)
|
|
188
|
+
ctx__set(source_ctx, 'key', 1)
|
|
189
|
+
// @ts-expect-error TS7053
|
|
190
|
+
equal(ctx0.s[''], undefined)
|
|
191
|
+
equal(ctx0.s['ctx0'].get('key'), 2)
|
|
192
|
+
equal(ctx1.s[''].get('key'), 1)
|
|
129
193
|
})
|
|
130
194
|
test('ctx__delete|id', ()=>{
|
|
131
195
|
const ctx0 = ctx__new()
|
|
132
196
|
ctx__delete(ctx0, 'key')
|
|
133
|
-
equal(ctx0.has('key'), false)
|
|
134
|
-
ctx0.set('key', true)
|
|
135
|
-
equal(ctx0.get('key'), true)
|
|
197
|
+
equal(ctx0.s[''].has('key'), false)
|
|
198
|
+
ctx0.s[''].set('key', true)
|
|
199
|
+
equal(ctx0.s[''].get('key'), true)
|
|
136
200
|
ctx__delete(ctx0, 'key')
|
|
137
|
-
equal(ctx0.has('key'), false)
|
|
201
|
+
equal(ctx0.s[''].has('key'), false)
|
|
138
202
|
const ctx1 = ctx__new()
|
|
139
|
-
const
|
|
140
|
-
ctx0.set('key', true)
|
|
141
|
-
ctx1.set('key', true)
|
|
142
|
-
equal(ctx0.get('key'), true)
|
|
143
|
-
equal(ctx1.get('key'), true)
|
|
144
|
-
ctx__delete(
|
|
145
|
-
equal(ctx0.has('key'), false)
|
|
146
|
-
equal(ctx1.has('key'),
|
|
203
|
+
const source_ctx = ns_ctx__new(ctx0, ctx1, 'test_source')
|
|
204
|
+
ctx0.s[''].set('key', true)
|
|
205
|
+
ctx1.s[''].set('key', true)
|
|
206
|
+
equal(ctx0.s[''].get('key'), true)
|
|
207
|
+
equal(ctx1.s[''].get('key'), true)
|
|
208
|
+
ctx__delete(source_ctx, 'key')
|
|
209
|
+
equal(ctx0.s[''].has('key'), false)
|
|
210
|
+
equal(ctx1.s[''].has('key'), true)
|
|
211
|
+
source_ctx.s['test_source'].set('key', true)
|
|
212
|
+
equal(source_ctx.s['test_source'].get('key'), true)
|
|
213
|
+
ctx__delete(source_ctx, 'key')
|
|
214
|
+
equal(source_ctx.s['test_source'].get('key'), true)
|
|
215
|
+
ctx__delete(source_ctx, 'key', 'test_source')
|
|
216
|
+
equal(source_ctx.s['test_source'].has('key'), false)
|
|
147
217
|
})
|
|
148
218
|
test('ctx__delete|be', ()=>{
|
|
149
219
|
const ctx0 = ctx__new()
|
|
150
220
|
const num_ = be_(()=>1)
|
|
151
221
|
ctx__delete(ctx0, num_)
|
|
152
|
-
equal(ctx0.has(num_.id), false)
|
|
222
|
+
equal(ctx0.s[''].has(num_.id), false)
|
|
153
223
|
num_(ctx0)
|
|
154
|
-
equal(ctx0.has(num_.id), true)
|
|
224
|
+
equal(ctx0.s[''].has(num_.id), true)
|
|
155
225
|
ctx__delete(ctx0, num_)
|
|
156
|
-
equal(ctx0.has(num_.id), false)
|
|
226
|
+
equal(ctx0.s[''].has(num_.id), false)
|
|
157
227
|
num_(ctx0)
|
|
158
|
-
equal(ctx0.has(num_.id), true)
|
|
228
|
+
equal(ctx0.s[''].has(num_.id), true)
|
|
159
229
|
ctx__delete(ctx0, num_)
|
|
160
|
-
equal(ctx0.has(num_.id), false)
|
|
161
|
-
const ctx1 =
|
|
162
|
-
|
|
163
|
-
const nested__ctx = [ctx0, ctx1]
|
|
230
|
+
equal(ctx0.s[''].has(num_.id), false)
|
|
231
|
+
const ctx1 = ns_ctx__new('ctx1')
|
|
232
|
+
const ns_ctx = ns_ctx__new(ctx0, ctx1)
|
|
164
233
|
num_(ctx0)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
equal(
|
|
168
|
-
|
|
169
|
-
equal(
|
|
170
|
-
|
|
234
|
+
// @ts-expect-error TS7053
|
|
235
|
+
throws(()=>num_(ctx1), Error(`ctx_no_ns: 'ctx1'`))
|
|
236
|
+
equal(ctx0.s[''].has(num_.id), true)
|
|
237
|
+
// @ts-expect-error TS7053
|
|
238
|
+
equal(ctx1.s[''], undefined)
|
|
239
|
+
ctx__delete(ns_ctx, num_)
|
|
240
|
+
equal(ctx0.s[''].has(num_.id), false)
|
|
241
|
+
// @ts-expect-error TS7053
|
|
242
|
+
equal(ctx1.s[''], undefined)
|
|
171
243
|
num_(ctx0)
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
equal(
|
|
175
|
-
|
|
176
|
-
equal(
|
|
177
|
-
|
|
244
|
+
// @ts-expect-error TS7053
|
|
245
|
+
throws(()=>num_(ctx1), `ctx_no_ns: 'ctx1'`)
|
|
246
|
+
equal(ctx0.s[''].has(num_.id), true)
|
|
247
|
+
// @ts-expect-error TS7053
|
|
248
|
+
equal(ctx1.s[''], undefined)
|
|
249
|
+
ctx__delete(ns_ctx, num_)
|
|
250
|
+
equal(ctx0.s[''].has(num_.id), false)
|
|
251
|
+
// @ts-expect-error TS7053
|
|
252
|
+
equal(ctx1.s[''], undefined)
|
|
178
253
|
const is_source__num_ =
|
|
179
|
-
be_(()=>1,
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
equal(ctx1.
|
|
186
|
-
is_source__num_
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
equal(ctx1.
|
|
254
|
+
be_(()=>1,
|
|
255
|
+
{ ns: 'ctx1' })
|
|
256
|
+
is_source__num_(ns_ctx)
|
|
257
|
+
// @ts-expect-error TS2345
|
|
258
|
+
equal(ctx0.s[''].has(is_source__num_.id), false)
|
|
259
|
+
// @ts-expect-error TS7053
|
|
260
|
+
equal(ctx1.s[''], undefined)
|
|
261
|
+
equal(ctx1.s['ctx1'].has(is_source__num_.id), true)
|
|
262
|
+
ctx__delete(ns_ctx, is_source__num_)
|
|
263
|
+
// @ts-expect-error TS2345
|
|
264
|
+
equal(ctx0.s[''].has(is_source__num_.id), false)
|
|
265
|
+
// @ts-expect-error TS7053
|
|
266
|
+
equal(ctx1.s[''], undefined)
|
|
267
|
+
equal(ctx1.s['ctx1'].has(is_source__num_.id), false)
|
|
268
|
+
is_source__num_(ns_ctx)
|
|
269
|
+
// @ts-expect-error TS2345
|
|
270
|
+
equal(ctx0.s[''].has(is_source__num_.id), false)
|
|
271
|
+
// @ts-expect-error TS7053
|
|
272
|
+
equal(ctx1.s[''], undefined)
|
|
273
|
+
equal(ctx1.s['ctx1'].has(is_source__num_.id), true)
|
|
274
|
+
ctx__delete(ns_ctx, is_source__num_)
|
|
275
|
+
// @ts-expect-error TS2345
|
|
276
|
+
equal(ctx0.s[''].has(is_source__num_.id), false)
|
|
277
|
+
// @ts-expect-error TS7053
|
|
278
|
+
equal(ctx1.s[''], undefined)
|
|
279
|
+
equal(ctx1.s['ctx1'].has(is_source__num_.id), false)
|
|
280
|
+
is_source__num_(ns_ctx)
|
|
281
|
+
// @ts-expect-error TS2345
|
|
282
|
+
equal(ctx0.s[''].has(is_source__num_.id), false)
|
|
283
|
+
// @ts-expect-error TS7053
|
|
284
|
+
equal(ctx1.s[''], undefined)
|
|
285
|
+
equal(ctx1.s['ctx1'].has(is_source__num_.id), true)
|
|
286
|
+
ctx__delete(ns_ctx, is_source__num_, '')
|
|
287
|
+
// @ts-expect-error TS2345
|
|
288
|
+
equal(ctx0.s[''].has(is_source__num_.id), false)
|
|
289
|
+
// @ts-expect-error TS7053
|
|
290
|
+
equal(ctx1.s[''], undefined)
|
|
291
|
+
equal(ctx1.s['ctx1'].has(is_source__num_.id), true)
|
|
192
292
|
})
|
|
193
293
|
test('be__has_', ()=>{
|
|
194
294
|
const ctx0 = ctx__new()
|
|
195
295
|
ctx__delete(ctx0, 'key')
|
|
196
296
|
equal(be__has_('key', ctx0), false)
|
|
197
|
-
ctx0.set('key', true)
|
|
297
|
+
ctx0.s[''].set('key', true)
|
|
198
298
|
equal(be__has_('key', ctx0), true)
|
|
199
299
|
ctx__delete(ctx0, 'key')
|
|
200
300
|
equal(be__has_('key', ctx0), false)
|
|
201
301
|
const ctx1 = ctx__new()
|
|
202
|
-
const
|
|
203
|
-
ctx1.set('key', true)
|
|
204
|
-
equal(be__has_('key',
|
|
302
|
+
const source_ctx = ns_ctx__new(ctx0, ctx1, 'test_source')
|
|
303
|
+
ctx1.s[''].set('key', true)
|
|
304
|
+
equal(be__has_('key', source_ctx), false)
|
|
305
|
+
equal(be__has_('key', source_ctx, 'test_source'), false)
|
|
306
|
+
ctx0.s[''].set('key', true)
|
|
307
|
+
equal(be__has_('key', source_ctx), true)
|
|
308
|
+
equal(be__has_('key', source_ctx, 'test_source'), false)
|
|
309
|
+
source_ctx.s.test_source.set('key', true)
|
|
310
|
+
equal(be__has_('key', source_ctx, 'test_source'), true)
|
|
205
311
|
})
|
|
206
|
-
test('
|
|
312
|
+
test('be_map__find', ()=>{
|
|
207
313
|
const ctx0 = ctx__new()
|
|
314
|
+
const be_map0 = ctx0.s['']
|
|
208
315
|
ctx__delete(ctx0, 'key')
|
|
209
|
-
equal(
|
|
210
|
-
ctx0.set('key', true)
|
|
211
|
-
equal(
|
|
316
|
+
equal(be_map__find('key', ctx0), undefined)
|
|
317
|
+
ctx0.s[''].set('key', true)
|
|
318
|
+
equal(be_map__find('key', ctx0), be_map0)
|
|
212
319
|
ctx__delete(ctx0, 'key')
|
|
213
|
-
equal(
|
|
320
|
+
equal(be_map__find('key', ctx0), undefined)
|
|
214
321
|
const ctx1 = ctx__new()
|
|
215
|
-
const
|
|
216
|
-
ctx1
|
|
217
|
-
|
|
322
|
+
const be_map1 = ctx1.s['']
|
|
323
|
+
const source_ctx = ns_ctx__new(ctx0, ctx1, 'test_source')
|
|
324
|
+
is.not(source_ctx.s.test_source, be_map0)
|
|
325
|
+
is.not(source_ctx.s.test_source, be_map1)
|
|
326
|
+
ctx1.s[''].set('key', true)
|
|
327
|
+
equal(be_map__find('key', source_ctx), undefined)
|
|
328
|
+
equal(be_map__find('key', source_ctx, 'test_source'), undefined)
|
|
329
|
+
ctx0.s[''].set('key', true)
|
|
330
|
+
equal(be_map__find('key', source_ctx), be_map0)
|
|
331
|
+
equal(be_map__find('key', source_ctx, 'test_source'), undefined)
|
|
332
|
+
source_ctx.s.test_source.set('key', true)
|
|
333
|
+
equal(be_map__find('key', source_ctx, 'test_source'), source_ctx.s.test_source)
|
|
218
334
|
})
|
|
219
335
|
test('be__val_', ()=>{
|
|
220
|
-
const
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
equal(val_(
|
|
227
|
-
equal(
|
|
336
|
+
const ctx0 = ctx__new()
|
|
337
|
+
const ctx1 = ctx__new()
|
|
338
|
+
const source_ctx = ns_ctx__new(ctx0, ctx1, 'test_source')
|
|
339
|
+
const val_ = be_<boolean>(()=>
|
|
340
|
+
true,
|
|
341
|
+
{ id: 'val_' })
|
|
342
|
+
equal(val_(source_ctx), true)
|
|
343
|
+
equal(source_ctx.s[''].get(val_.id), true)
|
|
344
|
+
equal(be__val_(val_, source_ctx), true)
|
|
345
|
+
equal(be__val_('val_', source_ctx), true)
|
|
346
|
+
ctx__set(source_ctx, val_, false)
|
|
347
|
+
equal(val_(source_ctx), false)
|
|
348
|
+
equal(be__val_(val_, source_ctx), false)
|
|
349
|
+
equal(be__val_('val_', source_ctx), false)
|
|
350
|
+
equal(be__val_(val_, source_ctx, 'test_source'), undefined)
|
|
351
|
+
equal(be__val_('val_', source_ctx, 'test_source'), undefined)
|
|
352
|
+
source_ctx.s.test_source.set('val_', true)
|
|
353
|
+
equal(be__val_(val_, source_ctx, 'test_source'), true)
|
|
354
|
+
equal(be__val_('val_', source_ctx, 'test_source'), true)
|
|
228
355
|
})
|
|
229
356
|
test.run()
|
|
230
|
-
declare const test_ctx_sym:unique symbol
|
|
231
|
-
type test_ctx_T = Ctx&{
|
|
232
|
-
[test_ctx_sym]:unknown
|
|
233
|
-
}
|