aontu 0.9.0 → 0.10.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.
@@ -1 +1 @@
1
- {"version":3,"file":"RefVal.js","sourceRoot":"","sources":["../../../lib/val/RefVal.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;AAUpD,kCAGgB;AAYhB,iCAEiB;AAEjB,oCAAgC;AAEhC,4CAAwC;AACxC,oDAAgD;AAEhD,gCAAkC;AAIlC,MAAM,MAAO,SAAQ,iBAAO;IAK1B,YAAY,GAAU,EAAE,GAAa;QACnC,KAAK,CAAC,EAAE,CAAC,CAAA;QAHX,QAAG,GAAG,GAAG,CAAA;QAIP,IAAI,CAAC,QAAQ,GAAG,IAAI,KAAK,GAAG,CAAA;QAC5B,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;QAEf,KAAK,IAAI,IAAI,IAAI,GAAG,EAAE;YACpB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;SAClB;IACH,CAAC;IAGD,MAAM,CAAC,IAAS;QACd,+BAA+B;QAE/B,IAAI,QAAQ,KAAK,OAAO,IAAI,EAAE;YAC5B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;SACtB;aAEI,IAAI,IAAI,YAAY,eAAS,EAAE;YAClC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;SAC1B;aAEI,IAAI,IAAI,YAAY,MAAM,EAAE;YAC/B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;YAE9B,IAAI,IAAI,CAAC,QAAQ,EAAE;gBACjB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;aACrB;SACF;QAED,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC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il[]>(err: NILS): any {
8
+ if (err instanceof Nil) {
9
+ let v1: any = err.primary || {}
10
+ let v2: any = err.secondary || {}
11
+ err.msg = 'Cannot unify' +
12
+ (0 < err.path?.length ? ' path ' + err.path.join('.') : '') +
13
+ ' ' + (err.url ? 'in ' + err.url : '') + ':\n' +
14
+
15
+ 'LHS: ' +
16
+ (0 < v1.path?.length ? v1.path.join('.') + ':' : '') +
17
+ `<${v1.canon}>:${v1.row}:${v1.col}` + ' ' +
18
+ ((v1.url && v1.url !== err.url) ? ' in ' + v1.url : '') + '\n' +
19
+
20
+ 'RHS: ' +
21
+ (0 < v2.path?.length ? v2.path.join('.') + ':' : '') +
22
+ `<${v2.canon}>:${v2.row}:${v2.col}` + ' ' +
23
+ ((v2.url && v2.url !== err.url) ? ' in ' + v2.url : '') + '\n' +
24
+
25
+ ''
26
+ return err
27
+ }
28
+ else {
29
+ return err.map(n => descErr(n))
30
+ }
31
+ }
32
+
33
+
34
+ export {
35
+ descErr
36
+ }
package/lib/lang.ts CHANGED
@@ -57,8 +57,6 @@ import {
57
57
 
58
58
 
59
59
 
60
- // console.log('TOP', TOP)
61
-
62
60
  class Site {
63
61
  row: number = -1
64
62
  col: number = -1
@@ -187,10 +185,7 @@ let AontuJsonic: Plugin = function aontu(jsonic: Jsonic) {
187
185
  },
188
186
  },
189
187
  evaluate: (r: Rule, op: Op, terms: any) => {
190
- // console.log('LANG EVAL', r.keep, op, terms)
191
188
  let val: Val = opmap[op.name](r, op, terms)
192
- // console.dir(val, { depth: null })
193
-
194
189
  return val
195
190
  }
196
191
  })
@@ -210,8 +205,6 @@ let AontuJsonic: Plugin = function aontu(jsonic: Jsonic) {
210
205
  let valnode: Val = r.node
211
206
  let valtype = typeof valnode
212
207
 
213
- // console.log('VAL RULE', valtype, r.use, r.node)
214
-
215
208
  if ('string' === valtype) {
216
209
  valnode = addpath(new StringVal(r.node), r.keep.path)
217
210
  }
package/lib/op/unite.ts CHANGED
@@ -45,6 +45,10 @@ const unite: Operation = (ctx: Context, a?: Val, b?: Val, whence?: string) => {
45
45
  else if (b instanceof Nil) {
46
46
  out = update(b, a)
47
47
  }
48
+ else if (a instanceof ConjunctVal) {
49
+ // console.log('Q', a.canon, b.canon)
50
+ out = a.unify(b, ctx)
51
+ }
48
52
  else if (
49
53
  b instanceof ConjunctVal ||
50
54
  b instanceof DisjunctVal ||
@@ -52,8 +56,10 @@ const unite: Operation = (ctx: Context, a?: Val, b?: Val, whence?: string) => {
52
56
  b instanceof PrefVal
53
57
  ) {
54
58
 
55
- //console.log('U', a.canon, b.canon)
56
- return b.unify(a, ctx)
59
+ // console.log('U', a.canon, b.canon)
60
+ // return b.unify(a, ctx)
61
+ out = b.unify(a, ctx)
62
+ // console.log('UO', out.canon)
57
63
  }
58
64
 
59
65
  // Exactly equal scalars.
package/lib/unify.ts CHANGED
@@ -67,15 +67,19 @@ class Context {
67
67
 
68
68
 
69
69
  find(ref: RefVal) {
70
- // console.log('FIND', ref.path, ref.peg)
71
-
72
70
  // TODO: relative paths
73
- if (this.root instanceof MapVal && ref.absolute) {
74
- let node: MapVal = this.root
71
+ // if (this.root instanceof MapVal && ref.absolute) {
72
+ if (ref.absolute) {
73
+ let node = this.root
75
74
  let pI = 0
76
- for (; pI < ref.parts.length && node instanceof MapVal; pI++) {
75
+ for (; pI < ref.parts.length; pI++) {
77
76
  let part = ref.parts[pI]
78
- node = node.peg[part]
77
+ if (node instanceof MapVal) {
78
+ node = node.peg[part]
79
+ }
80
+ else {
81
+ break;
82
+ }
79
83
  }
80
84
 
81
85
  if (pI === ref.parts.length) {
@@ -116,6 +120,9 @@ class Unify {
116
120
 
117
121
  let maxdc = 999
118
122
  for (this.dc = 0; this.dc < maxdc && DONE !== res.done; this.dc++) {
123
+ // console.log('\n\nRES', this.dc, res.canon)
124
+ // console.dir(res, { depth: null })
125
+
119
126
  res = unite(ctx, res, TOP)
120
127
  // console.log('U', this.dc, res.canon)
121
128
  ctx = ctx.clone({ root: res })
@@ -20,7 +20,7 @@ import {
20
20
  Nil,
21
21
  } from '../val/Nil'
22
22
 
23
- // import { RefVal } from '../val/RefVal'
23
+ import { RefVal } from '../val/RefVal'
24
24
  import { MapVal } from '../val/MapVal'
25
25
 
26
26
  import {
@@ -53,16 +53,21 @@ class ConjunctVal extends ValBase {
53
53
  }
54
54
 
55
55
  unify(peer: Val, ctx: Context): Val {
56
+ const mark = (Math.random() * 1e7) % 1e6 | 0
57
+ // console.log('CONJUNCT unify', mark, this.done, this.canon, 'peer=', peer.canon)
58
+
56
59
  let done = true
57
60
 
58
61
  // Unify each term of conjunct against peer
59
62
  let upeer: Val[] = []
60
63
 
61
64
  for (let vI = 0; vI < this.peg.length; vI++) {
62
- // upeer[vI] = this.peg[vI].unify(peer, ctx)
63
65
  upeer[vI] = unite(ctx, this.peg[vI], peer)
64
- done = done && DONE === upeer[vI].done
65
- // // console.log('Ca', vI, this.peg[vI].canon, peer.canon, upeer[vI].canon)
66
+
67
+ let prevdone = done
68
+ done = done && (DONE === upeer[vI].done)
69
+
70
+ // console.log('CONJUNCT pud', mark, vI, done, prevdone, '|', upeer[vI].done, upeer[vI].canon)
66
71
 
67
72
  if (upeer[vI] instanceof Nil) {
68
73
  return Nil.make(
@@ -74,12 +79,10 @@ class ConjunctVal extends ValBase {
74
79
  }
75
80
  }
76
81
 
77
- // // console.log('Cb', upeer.map(x => x.canon))
78
-
79
-
80
82
  upeer = norm(upeer)
83
+ // console.log('CONJUNCT upeer', mark, done, upeer.map(p => p.canon))
81
84
 
82
- // console.log('CJ AA', upeer.map(x => x.canon))
85
+ // Unify terms against each other
83
86
 
84
87
  let outvals: Val[] = []
85
88
  let val: Val
@@ -88,8 +91,6 @@ class ConjunctVal extends ValBase {
88
91
  for (let pI = 0; pI < upeer.length; pI++) {
89
92
  let t0 = upeer[pI]
90
93
 
91
- // console.log('CJ unify QQ', mark, uc, 't0', pI, t0.canon)
92
-
93
94
  if (DONE !== t0.done) {
94
95
  let u0 = unite(ctx, t0, TOP)
95
96
 
@@ -97,8 +98,14 @@ class ConjunctVal extends ValBase {
97
98
  DONE !== u0.done
98
99
 
99
100
  // Maps and Lists are still unified so that path refs will work
100
- && !(u0 instanceof MapVal) // TODO: || ListVal - test!
101
+ // TODO: || ListVal - test!
102
+ && !(
103
+ u0 instanceof MapVal
104
+ || u0 instanceof RefVal
105
+ )
101
106
  ) {
107
+
108
+ // console.log('CONJUNCT PUSH A', u0.id, u0.canon)
102
109
  outvals.push(u0)
103
110
  continue next_term
104
111
  }
@@ -107,43 +114,20 @@ class ConjunctVal extends ValBase {
107
114
  }
108
115
  }
109
116
 
110
-
111
117
  let t1 = upeer[pI + 1]
112
118
 
113
- // console.log('CJ unify WW', mark, uc, 't1', pI + 1, t1?.canon)
114
-
115
- // if (
116
- // null == t1 ||
117
- // t0.id === t1.id ||
118
- // t0 instanceof RefVal
119
- // ) {
120
- // if (DONE !== t0.done) {
121
- // let u0 = unite(ctx, t0, TOP)
122
- // // console.log('CJ unify EE', mark, uc, 't0', t0.canon, 'u0', u0.canon)
123
- // outvals.push(u0)
124
- // }
125
- // else {
126
- // outvals.push(t0)
127
- // }
128
- // pI++
129
- // }
130
-
131
- // else if (DONE !== t0.done || DONE != t1.done) {
132
- // if (DONE !== t0.done) {
133
- // let u0 = unite(ctx, t0, TOP)
134
- // // console.log('CJ unify FF', mark, uc, 't0', t0.canon, 'u0', u0.canon)
135
- // outvals.push(u0)
136
- // }
137
- // else {
138
- // outvals.push(t0)
139
- // }
140
- // }
141
-
142
119
  if (null == t1) {
120
+ // console.log('CONJUNCT PUSH B', t0.canon)
121
+ outvals.push(t0)
122
+ }
123
+
124
+ // Can't unite with a RefVal, unless also a RefVal with same path.
125
+ else if (t0 instanceof RefVal && !(t1 instanceof RefVal)) {
126
+ // console.log('CONJUNCT PUSH D', t0.canon)
143
127
  outvals.push(t0)
144
128
  }
129
+
145
130
  else {
146
- // console.log('CJS unify0', t0?.canon, t1?.canon)
147
131
  val = unite(ctx, t0, t1)
148
132
  done = done && DONE === val.done
149
133
 
@@ -157,6 +141,7 @@ class ConjunctVal extends ValBase {
157
141
  }
158
142
 
159
143
  // TODO: t0 should become this to avoid unnecessary repasses
144
+ // console.log('CONJUNCT PUSH C', val.canon)
160
145
  outvals.push(val)
161
146
 
162
147
  pI++
@@ -164,74 +149,28 @@ class ConjunctVal extends ValBase {
164
149
  }
165
150
 
166
151
 
167
- // console.log('CJ BB', outvals.map(x => x.canon))
168
-
169
- // // TODO: FIX: conjuncts get replicated inside each other
170
- // // 1&/x => CV[CV[1&/x]]
171
-
172
- // // Unify each term of conjunct against following sibling,
173
- // // reducing to smallest conjunct or single val
174
- // let outvals: Val[] = 0 < upeer.length ? [upeer[0]] : []
175
-
176
- // let oI = 0
177
- // for (let uI = 1; uI < upeer.length; uI++) {
178
- // // // console.log('Cu', oI, uI, outvals.map(x => x.canon))
179
-
180
- // if (outvals[oI] instanceof ConjunctVal) {
181
- // outvals.splice(oI, 0, ...outvals[oI].peg)
182
- // oI += outvals[oI].peg.length
183
- // done = false
184
- // }
185
- // else {
186
- // outvals[oI] = null == outvals[oI] ? upeer[uI] :
187
- // //outvals[oI].unify(upeer[uI], ctx)
188
- // unite(ctx, outvals[oI], upeer[uI])
189
- // done = done && DONE === outvals[oI].done
190
-
191
- // // Conjuct fails
192
- // if (outvals[oI] instanceof Nil) {
193
- // return outvals[oI]
194
-
195
- // /*
196
- // return Nil.make(
197
- // ctx,
198
- // '&reduce[' + outvals[oI].canon + ',' + upeer[uI].canon + ']',
199
- // outvals[oI],
200
- // upeer[uI]
201
- // )
202
- // */
203
- // }
204
- // }
205
- // }
206
-
207
- // // console.log('Cc', outvals.map(x => x.canon), outvals)
152
+ // console.log('CONJUNCT outvals', mark, outvals.map(v => v.canon))
208
153
 
209
154
  let out: Val
210
155
 
211
- //let why = ''
212
-
213
156
  if (0 === outvals.length) {
214
- //out = Nil.make(ctx, '&empty', this)
215
157
 
216
158
  // Empty conjuncts evaporate.
217
159
  out = TOP
218
- //why += 'A'
219
160
  }
220
161
 
221
162
  // TODO: corrects CV[CV[1&/x]] issue above, but swaps term order!
222
163
  else if (1 === outvals.length) {
223
164
  out = outvals[0]
224
- //why += 'B'
225
165
  }
226
166
  else {
227
167
  out = new ConjunctVal(outvals, ctx)
228
- //why += 'C'
229
168
  }
230
169
 
231
- // // console.log('Cd', why, out.peg)
232
-
233
170
  out.done = done ? DONE : this.done + 1
234
171
 
172
+ // console.log('CONJUNCT out', mark, out.done, out.canon)
173
+
235
174
  return out
236
175
  }
237
176
 
@@ -260,8 +199,9 @@ class ConjunctVal extends ValBase {
260
199
  }
261
200
 
262
201
 
202
+ // Normalize Conjuct:
203
+ // - flatten child conjuncts
263
204
  function norm(terms: Val[]): Val[] {
264
- // console.log('CJ norm', terms.map((t: Val) => t.canon))
265
205
 
266
206
  let expand: Val[] = []
267
207
  for (let tI = 0, pI = 0; tI < terms.length; tI++, pI++) {
package/lib/val/MapVal.ts CHANGED
@@ -68,10 +68,9 @@ class MapVal extends ValBase {
68
68
  // NOTE: order of keys is not preserved!
69
69
  // not possible in any case - consider {a,b} unify {b,a}
70
70
  unify(peer: Val, ctx: Context): Val {
71
- // console.log('QQQ ctx', !!ctx)
72
- if (null == ctx) {
73
- console.trace()
74
- }
71
+ // if (null == ctx) {
72
+ // console.trace()
73
+ // }
75
74
 
76
75
  let done: boolean = true
77
76
  let out: MapVal = TOP === peer ? this : new MapVal({}, ctx)
@@ -90,58 +89,30 @@ class MapVal extends ValBase {
90
89
  out.done = this.done + 1
91
90
 
92
91
  if (this.spread.cj) {
93
- //out.spread.cj =
94
- // DONE !== this.spread.cj.done ? this.spread.cj.unify(TOP, ctx) :
95
- // this.spread.cj
96
92
  out.spread.cj =
97
93
  DONE !== this.spread.cj.done ? unite(ctx, this.spread.cj) :
98
94
  this.spread.cj
99
-
95
+ done = (done && DONE === out.spread.cj.done)
100
96
  }
101
97
 
102
98
 
103
- // console.log(
104
- // (' '.repeat(ctx.path.length)),
105
- // 'MV spread', this.id, peer.id, out.id, '|',
106
- // this.canon, peer.canon, out.canon, '|',
107
- // (this.spread.cj || {}).done,
108
- // (this.spread.cj || {}).canon, (out.spread.cj || {}).canon)
109
-
110
99
  let spread_cj = out.spread.cj || TOP
111
100
 
112
101
  // Always unify children first
113
102
  for (let key in this.peg) {
114
- //let oval = out.peg[key] = this.peg[key].unify(spread_cj, ctx.descend(key))
115
- //let oval =
103
+ // console.log('MAP ukA', key, this.peg[key].canon)
116
104
 
117
105
  out.peg[key] =
118
106
  unite(ctx.descend(key), this.peg[key], spread_cj)
119
107
 
120
- done = (done && DONE === out.peg[key].done)
108
+ // console.log('MAP ukB', key, out.peg[key].canon)
121
109
 
122
- //if (oval instanceof Nil) {
123
- // ctx.err.push(oval)
124
- //}
110
+ done = (done && DONE === out.peg[key].done)
125
111
  }
126
112
 
127
- // console.log(
128
- // (' '.repeat(ctx.path.length)),
129
- // 'MV child ', this.id, peer.id, out.id, '|',
130
- // this.canon, peer.canon, out.canon, '|',
131
- // this.constructor.name,
132
- // peer.constructor.name,
133
- // out.constructor.name,
134
- // )
135
-
136
113
  if (peer instanceof MapVal) {
137
- //let upeer: MapVal = (peer.unify(TOP, ctx) as MapVal)
138
114
  let upeer: MapVal = (unite(ctx, peer) as MapVal)
139
115
 
140
- // console.log(
141
- // (' '.repeat(ctx.path.length)),
142
- // 'MV peer A', this.id, peer.id, out.id, '|',
143
- // Object.keys(this.peg), Object.keys(upeer.peg), Object.keys(out.peg))
144
-
145
116
  for (let peerkey in upeer.peg) {
146
117
  let peerchild = upeer.peg[peerkey]
147
118
  let child = out.peg[peerkey]
@@ -150,47 +121,17 @@ class MapVal extends ValBase {
150
121
  undefined === child ? peerchild :
151
122
  child instanceof Nil ? child :
152
123
  peerchild instanceof Nil ? peerchild :
153
- //child.unify(peerchild, ctx.descend(peerkey))
154
124
  unite(ctx.descend(peerkey), child, peerchild)
155
125
 
156
126
  if (this.spread.cj) {
157
- //out.peg[peerkey] = out.peg[peerkey].unify(spread_cj, ctx)
158
127
  out.peg[peerkey] = unite(ctx, out.peg[peerkey], spread_cj)
159
128
  }
160
129
 
161
130
  done = (done && DONE === oval.done)
162
131
 
163
- if (oval instanceof Nil) {
164
- // ctx.err.push(oval)
165
- }
166
-
167
132
  }
168
-
169
- // console.log(
170
- // (' '.repeat(ctx.path.length)),
171
- // 'MV peer B', this.id, peer.id, out.id, '|',
172
- // Object.keys(this.peg), Object.keys(upeer.peg), Object.keys(out.peg))
173
-
174
- //out.done = done ? DONE : out.done
175
-
176
- // console.log(' '.repeat(W) + 'MV OUT A', this.id, out.done, out.id, out.canon)//this.spread.cj, out.spread.cj)
177
-
178
- // console.log(
179
- // (' '.repeat(ctx.path.length)),
180
- // 'MV out ', this.id, peer.id, out.id, '|',
181
- // this.canon, peer.canon, out.canon, '|',
182
- // this.constructor.name,
183
- // peer.constructor.name,
184
- // out.constructor.name,
185
- // )
186
-
187
-
188
133
  }
189
134
  else if (TOP !== peer) {
190
- //out.done = done ? DONE : out.done
191
-
192
- //return (UNIFIER(out, peer, ctx) as MapVal)
193
-
194
135
  return Nil.make(ctx, 'map', this, peer)
195
136
  }
196
137
 
@@ -198,6 +139,7 @@ class MapVal extends ValBase {
198
139
  return out
199
140
  }
200
141
 
142
+
201
143
  get canon() {
202
144
  let keys = Object.keys(this.peg)
203
145
  return '{' +
@@ -208,6 +150,7 @@ class MapVal extends ValBase {
208
150
  '}'
209
151
  }
210
152
 
153
+
211
154
  gen(ctx: Context) {
212
155
  let out: any = {}
213
156
  for (let p in this.peg) {
@@ -218,9 +161,6 @@ class MapVal extends ValBase {
218
161
  }
219
162
 
220
163
 
221
-
222
-
223
-
224
164
  export {
225
165
  MapVal
226
166
  }
package/lib/val/Nil.ts CHANGED
@@ -27,8 +27,11 @@ class Nil extends ValBase {
27
27
  why: any
28
28
  primary?: Val
29
29
  secondary?: Val
30
+ msg: string = ''
30
31
 
31
32
  // TODO: include Val generating nil, thus capture type
33
+
34
+ // A Nil is an error - should not happen - unify failed
32
35
  static make = (ctx?: Context, why?: any, av?: Val, bv?: Val) => {
33
36
  let nil = new Nil(why, ctx)
34
37
 
package/lib/val/RefVal.ts CHANGED
@@ -41,11 +41,15 @@ class RefVal extends ValBase {
41
41
  absolute: boolean
42
42
  sep = '.'
43
43
 
44
- constructor(peg: any[], abs?: boolean) {
44
+ constructor(peg: any[] | string, abs?: boolean) {
45
45
  super('')
46
46
  this.absolute = true === abs
47
47
  this.parts = []
48
48
 
49
+ if ('string' === typeof peg) {
50
+ peg = peg.split('.')
51
+ }
52
+
49
53
  for (let part of peg) {
50
54
  this.append(part)
51
55
  }
@@ -77,6 +81,7 @@ class RefVal extends ValBase {
77
81
  unify(peer: Val, ctx: Context): Val {
78
82
  let resolved: Val | undefined = null == ctx ? this : ctx.find(this)
79
83
 
84
+ // Don't try to resolve paths forever.
80
85
  // TODO: large amount of reruns needed? why?
81
86
  resolved = null == resolved && 999 < this.done ?
82
87
  Nil.make(ctx, 'no-path', this, peer) : (resolved || this)
@@ -89,6 +94,12 @@ class RefVal extends ValBase {
89
94
  else if (peer instanceof Nil) {
90
95
  out = Nil.make(ctx, 'ref[' + this.peg + ']', this, peer)
91
96
  }
97
+
98
+ // same path
99
+ else if (this.peg === peer.peg) {
100
+ out = this
101
+ }
102
+
92
103
  else {
93
104
  // Ensure RefVal done is incremented
94
105
  this.done = DONE === this.done ? DONE : this.done + 1
@@ -115,7 +126,17 @@ class RefVal extends ValBase {
115
126
  }
116
127
 
117
128
 
118
- gen(_ctx?: Context) {
129
+ gen(ctx?: Context) {
130
+ // throw new Error('REF ' + this.peg)
131
+ if (ctx) {
132
+ ctx.err.push(Nil.make(
133
+ ctx,
134
+ 'ref',
135
+ this.peg,
136
+ undefined,
137
+ ))
138
+ }
139
+
119
140
  return undefined
120
141
  }
121
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aontu",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "main": "dist/aontu.js",
5
5
  "type": "commonjs",
6
6
  "browser": "dist/aontu.min.js",
@@ -50,7 +50,7 @@
50
50
  "@jsonic/path": "^0.6.0"
51
51
  },
52
52
  "devDependencies": {
53
- "@types/jest": "^29.4.0",
53
+ "@types/jest": "^29.4.2",
54
54
  "browserify": "^17.0.0",
55
55
  "esbuild": "^0.17.11",
56
56
  "es-jest": "^2.1.0",
@@ -59,6 +59,6 @@
59
59
  "serve": "^14.2.0",
60
60
  "tinyify": "^4.0.0",
61
61
  "typescript": "^4.9.5",
62
- "@types/node": "^18.14.6"
62
+ "@types/node": "^18.15.3"
63
63
  }
64
64
  }