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.
Files changed (193) hide show
  1. package/all/CacheControl_1hour_headers_/index.d.ts +5 -0
  2. package/all/CacheControl_1hour_headers_/index.js +10 -0
  3. package/all/CacheControl_5min_headers_/index.d.ts +5 -0
  4. package/all/CacheControl_5min_headers_/index.js +10 -0
  5. package/all/ContentType__is_binary_/index.d.ts +1 -0
  6. package/all/ContentType__is_binary_/index.js +9 -0
  7. package/all/ContentType_json_headers_/index.d.ts +5 -0
  8. package/all/ContentType_json_headers_/index.js +10 -0
  9. package/all/ContentType_svg_headers_/index.d.ts +5 -0
  10. package/all/ContentType_svg_headers_/index.js +10 -0
  11. package/all/a_in_idx_a_map/index.d.ts +1 -3
  12. package/all/a_item/index.d.ts +3 -9
  13. package/all/a_length/index.d.ts +4 -7
  14. package/all/a_nowrap/index.d.ts +1 -3
  15. package/all/a_present/index.d.ts +4 -7
  16. package/all/a_some/index.d.ts +1 -3
  17. package/all/and/index.d.ts +3 -9
  18. package/all/and_call/index.d.ts +4 -8
  19. package/all/andand/index.d.ts +4 -11
  20. package/all/andand_or/index.d.ts +6 -8
  21. package/all/andandfn/index.d.ts +3 -12
  22. package/all/apply/index.d.ts +2 -2
  23. package/all/arg_i0_a/index.d.ts +1 -1
  24. package/all/array_types/index.d.ts +21 -28
  25. package/all/assign_fn_key_a/index.d.ts +1 -3
  26. package/all/be/index.d.ts +5 -3
  27. package/all/be_/index.d.ts +69 -48
  28. package/all/be_/index.js +39 -76
  29. package/all/be_/index.test.ts +244 -121
  30. package/all/be_lock_memosig_triple/index.d.ts +16 -22
  31. package/all/be_lock_memosig_triple/index.test.ts +47 -36
  32. package/all/be_memo_pair/index.d.ts +14 -11
  33. package/all/be_memo_pair/index.js +1 -2
  34. package/all/be_memo_pair/index.test.ts +47 -31
  35. package/all/be_memosig_triple/index.d.ts +16 -22
  36. package/all/be_memosig_triple/index.test.ts +48 -34
  37. package/all/be_sig_triple/index.d.ts +16 -13
  38. package/all/be_sig_triple/index.js +2 -3
  39. package/all/be_sig_triple/index.test.ts +42 -29
  40. package/all/bind_apply/index.d.ts +3 -3
  41. package/all/bind_call/index.d.ts +10 -11
  42. package/all/bind_map_apply/index.d.ts +2 -2
  43. package/all/bind_map_call/index.d.ts +2 -2
  44. package/all/call/index.d.ts +3 -3
  45. package/all/call_assign/index.d.ts +2 -6
  46. package/all/call_fn_a/index.d.ts +4 -3
  47. package/all/call_or_fn/index.d.ts +1 -4
  48. package/all/chain/index.d.ts +4 -8
  49. package/all/chunk_aa/index.d.ts +3 -5
  50. package/all/clear_ctx/index.d.ts +1 -3
  51. package/all/combinators/index.d.ts +12 -49
  52. package/all/compact/index.d.ts +4 -7
  53. package/all/compact_a_ctx/index.d.ts +1 -3
  54. package/all/compare/index.d.ts +1 -3
  55. package/all/compose/index.d.ts +3 -3
  56. package/all/concat/index.d.ts +2 -6
  57. package/all/concat_truthy_a/index.d.ts +3 -4
  58. package/all/ctx/index.d.ts +18 -2
  59. package/all/ctx/index.js +20 -8
  60. package/all/ctx/index.test.ts +33 -7
  61. package/all/curry/index.d.ts +5 -7
  62. package/all/curry/index.js +6 -3
  63. package/all/debounce/index.d.ts +12 -12
  64. package/all/difference_a/index.d.ts +1 -3
  65. package/all/difference_by/index.d.ts +3 -4
  66. package/all/difference_set/index.d.ts +1 -5
  67. package/all/each/index.d.ts +5 -9
  68. package/all/ensure/index.d.ts +1 -3
  69. package/all/ensure__refresh/index.d.ts +1 -3
  70. package/all/eq/index.d.ts +4 -10
  71. package/all/eql/index.d.ts +3 -9
  72. package/all/eql_a/index.d.ts +1 -3
  73. package/all/eql_fn_a/index.d.ts +1 -3
  74. package/all/every/index.d.ts +3 -9
  75. package/all/exclude/index.d.ts +1 -4
  76. package/all/ext_R_mime/index.d.ts +86 -0
  77. package/all/ext_R_mime/index.js +86 -0
  78. package/all/falsy_async_guard/index.d.ts +3 -4
  79. package/all/falsy_guard/index.d.ts +4 -3
  80. package/all/fetch__template_pair/index.test.ts +5 -5
  81. package/all/filter/index.d.ts +4 -12
  82. package/all/find/index.d.ts +6 -10
  83. package/all/first/index.d.ts +2 -7
  84. package/all/flatten/index.d.ts +2 -6
  85. package/all/flip/index.d.ts +3 -3
  86. package/all/hasOwnProperty_pick/index.d.ts +4 -4
  87. package/all/head_arg_a/index.d.ts +4 -3
  88. package/all/http__headers__assign/index.d.ts +11 -0
  89. package/all/http__headers__assign/index.js +11 -0
  90. package/all/idx/index.d.ts +1 -3
  91. package/all/idx_reject/index.d.ts +3 -9
  92. package/all/idx_sort_a/index.d.ts +1 -3
  93. package/all/idx_sort_a__sort_idx_o/index.d.ts +1 -3
  94. package/all/idx_sort_r_a/index.d.ts +1 -3
  95. package/all/if_null_set_false/index.d.ts +1 -3
  96. package/all/ifelse/index.d.ts +5 -3
  97. package/all/iife/index.d.ts +3 -3
  98. package/all/index.d.ts +9 -0
  99. package/all/index.js +9 -0
  100. package/all/internal_server_error__throw/index.d.ts +5 -0
  101. package/all/internal_server_error__throw/index.js +7 -0
  102. package/all/intersection_a/index.d.ts +5 -6
  103. package/all/intersection_by/index.d.ts +3 -4
  104. package/all/intersection_set/index.d.ts +1 -3
  105. package/all/isArray/index.d.ts +2 -2
  106. package/all/last/index.d.ts +2 -7
  107. package/all/left_and/index.d.ts +1 -3
  108. package/all/left_or/index.d.ts +1 -3
  109. package/all/many_andand/index.d.ts +7 -6
  110. package/all/many_andand_or/index.d.ts +2 -8
  111. package/all/map/index.d.ts +4 -18
  112. package/all/map_andand/index.d.ts +3 -9
  113. package/all/map_andand_or/index.d.ts +1 -3
  114. package/all/map_andandfn/index.d.ts +2 -6
  115. package/all/map_apply/index.d.ts +5 -8
  116. package/all/map_call/index.d.ts +5 -8
  117. package/all/map_find/index.d.ts +3 -11
  118. package/all/map_fn/index.d.ts +1 -4
  119. package/all/map_obj/index.d.ts +3 -12
  120. package/all/map_obj_andand/index.d.ts +2 -8
  121. package/all/merge/index.d.ts +1 -4
  122. package/all/mixin/index.d.ts +1 -4
  123. package/all/neq/index.d.ts +2 -6
  124. package/all/neql/index.d.ts +2 -6
  125. package/all/noinit/index.d.ts +5 -8
  126. package/all/not/index.d.ts +3 -9
  127. package/all/notnot/index.d.ts +2 -4
  128. package/all/nullish__guard/index.d.ts +3 -4
  129. package/all/nullish__guard__async/index.d.ts +3 -4
  130. package/all/nullish__none/index.d.ts +1 -3
  131. package/all/o_a_present/index.d.ts +2 -6
  132. package/all/o_some/index.d.ts +1 -3
  133. package/all/offset_destructure_aa/index.d.ts +1 -3
  134. package/all/offset_i_slice/index.d.ts +2 -6
  135. package/all/one_andand/index.d.ts +3 -3
  136. package/all/one_andand_or/index.d.ts +3 -5
  137. package/all/or/index.d.ts +6 -17
  138. package/all/or_property/index.d.ts +1 -5
  139. package/all/promise_timeout/index.d.ts +4 -4
  140. package/all/prototype_mixin/index.d.ts +4 -3
  141. package/all/prototype_mixin/index.js +3 -3
  142. package/all/push/index.d.ts +2 -6
  143. package/all/r_val_a/index.d.ts +2 -6
  144. package/all/rank/index.d.ts +3 -4
  145. package/all/reduce/index.d.ts +10 -23
  146. package/all/reject/index.d.ts +7 -14
  147. package/all/remove/index.d.ts +2 -6
  148. package/all/remove_idx/index.d.ts +4 -4
  149. package/all/resolver_curry/index.d.ts +2 -2
  150. package/all/reverse/index.d.ts +2 -10
  151. package/all/right_and/index.d.ts +1 -3
  152. package/all/right_or/index.d.ts +1 -3
  153. package/all/rmemo/index.js +3 -3
  154. package/all/rmemo__wait/index.test.ts +1 -1
  155. package/all/run/index.d.ts +1 -4
  156. package/all/selector_splice/index.d.ts +1 -3
  157. package/all/slice/index.d.ts +5 -15
  158. package/all/slice_arg_a/index.d.ts +3 -12
  159. package/all/slice_arg_spread_a/index.d.ts +3 -11
  160. package/all/sort/index.d.ts +4 -14
  161. package/all/sort_a/index.d.ts +2 -6
  162. package/all/sort_idx_a/index.d.ts +2 -6
  163. package/all/sort_idx_o/index.d.ts +2 -6
  164. package/all/sort_val_a/index.d.ts +2 -6
  165. package/all/sort_val_a__transition_idx_a/index.d.ts +4 -12
  166. package/all/sort_val_a__transition_idx_a/index.js +4 -2
  167. package/all/sparse_a/index.d.ts +1 -3
  168. package/all/splice/index.d.ts +2 -6
  169. package/all/spread/index.d.ts +2 -6
  170. package/all/tap/index.d.ts +1 -3
  171. package/all/test/index.d.ts +12 -0
  172. package/all/test/index.js +1 -0
  173. package/all/throttle/index.d.ts +2 -2
  174. package/all/throttle/index.js +8 -7
  175. package/all/tick/index.d.ts +1 -5
  176. package/all/timeout_promise/index.d.ts +1 -5
  177. package/all/times/index.d.ts +1 -5
  178. package/all/tup/index.d.ts +22 -6
  179. package/all/union_a/index.d.ts +1 -3
  180. package/all/union_set/index.d.ts +1 -5
  181. package/all/val/index.d.ts +1 -3
  182. package/all/value_r/index.d.ts +2 -6
  183. package/all/weak_r/index.d.ts +3 -3
  184. package/all/wrap_a/index.d.ts +4 -12
  185. package/all/wrap_a_item/index.d.ts +4 -3
  186. package/all/wrap_aa/index.d.ts +2 -8
  187. package/all/wrap_aa_item/index.d.ts +4 -3
  188. package/all/wrap_concat/index.d.ts +1 -5
  189. package/http/index.d.ts +8 -0
  190. package/http/index.js +8 -0
  191. package/package.json +35 -10
  192. package/test/index.d.ts +1 -0
  193. package/test/index.js +1 -0
package/all/be_/index.js CHANGED
@@ -1,10 +1,5 @@
1
- /** @typedef {import('./index.d.ts').Be} */
2
- /** @typedef {import('./index.d.ts').be_} */
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 = argv__ctx=>{
20
- let flat__argv__ctx = argv__ctx.flat && argv__ctx.flat(Infinity)
21
- let be__ctx =
22
- flat__argv__ctx
23
- ? flat__argv__ctx.find(ctx=>ctx.has(be.id))
24
- : argv__ctx.has(be.id) && argv__ctx
25
- if (!be__ctx) {
26
- be__ctx =
27
- flat__argv__ctx
28
- ? flat__argv__ctx.find(ctx=>!be.is_source_ || be.is_source_(ctx, argv__ctx))
29
- : (!be.is_source_ || be.is_source_(argv__ctx, argv__ctx)) && argv__ctx
30
- // circular dependency state
31
- // if val__new calls this be before returning, 'cir' will be the value of this be
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.is_source_ = config?.is_source_
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 {is_source__T}[is_source_]
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
- is_source_ = be_OR_id.is_source_
58
+ ns = be_OR_id.ns ?? ''
69
59
  ) {
70
- let source__map_ctx = source__map_ctx_(ctx, is_source_)
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 (Array.isArray(ctx)) {
84
- for (let _ctx of ctx) {
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
- ctx.delete(be_OR_id.id ?? be_OR_id)
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}be_or_id
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_(be_or_id, argv__ctx) {
98
- return Boolean(be__ctx_(be_or_id, argv__ctx))
85
+ export function be__has_(...arg_a) {
86
+ return Boolean(be_map__find(...arg_a))
99
87
  }
100
88
  /**
101
- * @param {Be|string}be_or_id
102
- * @param {Ctx}argv__ctx
103
- * @returns {MapCtx}
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 be__ctx_(be_or_id, argv__ctx) {
107
- if (Array.isArray(argv__ctx)) {
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}argv__ctx
120
- * @returns {unknown}
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 source__map_ctx_(argv__ctx, is_source_) {
134
- if (Array.isArray(argv__ctx)) {
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
  }
@@ -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
- globalThis__be_,
13
- type MapCtx
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_|Map', ()=>{
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_|simple array', ()=>{
50
+ test('be_|ns_ctx__new|-ns', ()=>{
47
51
  const ctx0 = ctx__new()
48
52
  const ctx1 = ctx__new()
49
- const ctx = [ctx0, ctx1]
50
- const root_ = be_(()=>1, { id: 'root_' })
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), false)
54
- equal(ctx1.has(root_.id), true)
55
- const child_ = be_(ctx=>root_(ctx) + 1, { id: 'child_' })
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_|nested array', ()=>{
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 = [[[ctx0], ctx1], [ctx2, ctx3]]
66
- const root_ = be_(()=>1, { id: 'root_' })
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), false)
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_|is_source_', ()=>{
90
+ test('be_|ns', ()=>{
91
+ /* eslint-disable @typescript-eslint/no-unused-vars */
81
92
  const ctx0 = ctx__new()
82
- const ctx1 = ctx__new()
83
- ctx1.set('matching', true)
84
- const ctx = [ctx0, ctx1]
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
- is_source_: map_ctx=>!!map_ctx.get('matching'),
100
+ ns: 'ctx1',
91
101
  id: 'root_'
92
102
  })
93
103
  equal(root_(ctx), 1)
94
- equal(be__ctx_a, [[ctx0, ctx1]])
95
- equal(ctx0.has(root_.id), false)
96
- equal(ctx1.has(root_.id), true)
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 = ctx__new() as test_ctx_T
100
- const val_ = be_<boolean, test_ctx_T>(()=>true, { id: 'val_' })
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
- // val_(ctx_()) // type error
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 = [ctx0, ctx1]
109
- const nested__ctx_ = be_<Ctx>(ctx=>[ctx], { id: 'nested__ctx_' })
110
- equal(nested__ctx_(ctx), [[ctx0, ctx1]])
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 = ctx__new()
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 ctx_a = [ctx1, ctx0]
125
- ctx__set(ctx_a, 'key', 2,
126
- (map_ctx:MapCtx)=>map_ctx.get('key') != null)
127
- equal(ctx0.get('key'), 2)
128
- equal(ctx1.has('key'), false)
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 nested__ctx = [ctx0, ctx1]
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(nested__ctx, 'key')
145
- equal(ctx0.has('key'), false)
146
- equal(ctx1.has('key'), false)
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 = ctx__new()
162
- ctx1.set('ctx1', true)
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
- num_(ctx1)
166
- equal(ctx0.has(num_.id), true)
167
- equal(ctx1.has(num_.id), true)
168
- ctx__delete(nested__ctx, num_)
169
- equal(ctx0.has(num_.id), false)
170
- equal(ctx1.has(num_.id), false)
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
- num_(ctx1)
173
- equal(ctx0.has(num_.id), true)
174
- equal(ctx1.has(num_.id), true)
175
- ctx__delete(nested__ctx, num_)
176
- equal(ctx0.has(num_.id), false)
177
- equal(ctx1.has(num_.id), false)
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, { is_source_: ctx=>!!ctx.get('ctx1') })
180
- is_source__num_(nested__ctx)
181
- equal(ctx0.has(is_source__num_.id), false)
182
- equal(ctx1.has(is_source__num_.id), true)
183
- ctx__delete(nested__ctx, is_source__num_)
184
- equal(ctx0.has(is_source__num_.id), false)
185
- equal(ctx1.has(is_source__num_.id), false)
186
- is_source__num_(nested__ctx)
187
- equal(ctx0.has(is_source__num_.id), false)
188
- equal(ctx1.has(is_source__num_.id), true)
189
- ctx__delete(nested__ctx, is_source__num_)
190
- equal(ctx0.has(is_source__num_.id), false)
191
- equal(ctx1.has(is_source__num_.id), false)
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 nested__ctx = [ctx0, ctx1]
203
- ctx1.set('key', true)
204
- equal(be__has_('key', nested__ctx), true)
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('be__ctx_', ()=>{
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(be__ctx_('key', ctx0), undefined)
210
- ctx0.set('key', true)
211
- equal(be__ctx_('key', ctx0), ctx0)
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(be__ctx_('key', ctx0), undefined)
320
+ equal(be_map__find('key', ctx0), undefined)
214
321
  const ctx1 = ctx__new()
215
- const nested__ctx = [ctx0, ctx1]
216
- ctx1.set('key', true)
217
- equal(be__ctx_('key', nested__ctx), ctx1)
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 ctx = ctx__new()
221
- const val_ = be_<boolean>(()=>true, { id: 'val_' })
222
- equal(val_(ctx), true)
223
- equal(ctx.get(val_.id), true)
224
- equal(be__val_(val_, ctx), true)
225
- ctx__set(ctx, val_, false)
226
- equal(val_(ctx), false)
227
- equal(be__val_(val_, ctx), false)
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
- }