@calcit/procs 0.9.3 → 0.9.5

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/lib/js-cirru.mjs CHANGED
@@ -220,11 +220,11 @@ export let extract_cirru_edn = (x, options) => {
220
220
  return parseFloat(x);
221
221
  }
222
222
  // strict behavior as Rust semantics
223
- throw new Error("unknown syntax for EDN");
223
+ throw new Error(`unknown syntax for EDN: ${x}`);
224
224
  }
225
225
  if (x instanceof Array) {
226
226
  if (x.length === 0) {
227
- throw new Error("Cannot be empty");
227
+ throw new Error("Cannot be empty form");
228
228
  }
229
229
  if (x[0] === "{}") {
230
230
  let result = [];
@@ -239,11 +239,11 @@ export let extract_cirru_edn = (x, options) => {
239
239
  result.push(extract_cirru_edn(pair[0], options), extract_cirru_edn(pair[1], options));
240
240
  }
241
241
  else {
242
- throw new Error(`Expected a pair, got size ${pair.length}`);
242
+ throw new Error(`Expected a pair, got: ${pair}`);
243
243
  }
244
244
  }
245
245
  else {
246
- throw new Error(`Expected pairs for map, got ${pair}`);
246
+ throw new Error(`Expected pairs for map, got: ${pair}`);
247
247
  }
248
248
  });
249
249
  return new CalcitSliceMap(result);
@@ -251,7 +251,7 @@ export let extract_cirru_edn = (x, options) => {
251
251
  if (x[0] === "%{}") {
252
252
  let name = x[1];
253
253
  if (typeof name != "string") {
254
- throw new Error("Expected string for record name");
254
+ throw new Error(`Expected string for record name, got: ${name}`);
255
255
  }
256
256
  // put to entries first, sort and then...
257
257
  let entries = [];
@@ -267,15 +267,15 @@ export let extract_cirru_edn = (x, options) => {
267
267
  entries.push([extractFieldTag(pair[0]), extract_cirru_edn(pair[1], options)]);
268
268
  }
269
269
  else {
270
- throw new Error("Expected string as field");
270
+ throw new Error(`Expected string as field, got: ${pair}`);
271
271
  }
272
272
  }
273
273
  else {
274
- throw new Error("Expected pair of size 2");
274
+ throw new Error(`Expected pair of size 2, got: ${pair}`);
275
275
  }
276
276
  }
277
277
  else {
278
- throw new Error("Expected pairs for reocrd");
278
+ throw new Error(`Expected pairs for reocrd, got: ${pair}`);
279
279
  }
280
280
  });
281
281
  entries.sort((a, b) => {
@@ -321,13 +321,13 @@ export let extract_cirru_edn = (x, options) => {
321
321
  }
322
322
  if (x[0] === "quote") {
323
323
  if (x.length !== 2) {
324
- throw new Error("quote expects 1 argument");
324
+ throw new Error(`quote expects 1 argument, got: ${x}`);
325
325
  }
326
326
  return new CalcitCirruQuote(x[1]);
327
327
  }
328
328
  if (x[0] === "::") {
329
329
  if (x.length < 2) {
330
- throw new Error("tuple expects at least 1 value1");
330
+ throw new Error(`tuple expects at least 1 value, got: ${x}`);
331
331
  }
332
332
  return new CalcitTuple(extract_cirru_edn(x[1], options), x
333
333
  .slice(2)
@@ -336,7 +336,7 @@ export let extract_cirru_edn = (x, options) => {
336
336
  }
337
337
  }
338
338
  console.error(x);
339
- throw new Error("Unexpected data from cirru-edn");
339
+ throw new Error(`Unexpected data from EDN: ${x}`);
340
340
  };
341
341
  export let format_cirru_edn = (data, useInline = true) => {
342
342
  if (data == null) {
package/lib/js-list.mjs CHANGED
@@ -112,7 +112,12 @@ export class CalcitSliceList {
112
112
  this.end = value.length;
113
113
  }
114
114
  turnListMode() {
115
- return new CalcitList(initTernaryTreeListFromRange(this.value, this.start, this.end));
115
+ if (this.cachedTreeListRef != null) {
116
+ return this.cachedTreeListRef;
117
+ }
118
+ let ret = new CalcitList(initTernaryTreeListFromRange(this.value, this.start, this.end));
119
+ this.cachedTreeListRef = ret;
120
+ return ret;
116
121
  }
117
122
  len() {
118
123
  return this.end - this.start;
package/lib/js-map.mjs CHANGED
@@ -179,14 +179,20 @@ export class CalcitSliceMap {
179
179
  throw new Error("unknown data for map");
180
180
  }
181
181
  }
182
+ /** convert to tree map when needed, also cached in case converted over and over again */
182
183
  turnMap() {
184
+ if (this.cachedTreeMapRef != null) {
185
+ return this.cachedTreeMapRef;
186
+ }
183
187
  var dict = [];
184
188
  let halfLength = this.chunk.length >> 1;
185
189
  for (let idx = 0; idx < halfLength; idx++) {
186
190
  dict.push([this.chunk[idx << 1], this.chunk[(idx << 1) + 1]]);
187
191
  }
188
192
  let value = initTernaryTreeMapFromArray(dict);
189
- return new CalcitMap(value);
193
+ let ret = new CalcitMap(value);
194
+ this.cachedTreeMapRef = ret;
195
+ return ret;
190
196
  }
191
197
  len() {
192
198
  return this.chunk.length >> 1;
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
6
  "@types/node": "^22.1.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
6
  "@types/node": "^22.1.0",
@@ -217,11 +217,11 @@ export let extract_cirru_edn = (x: CirruEdnFormat, options: CalcitValue): Calcit
217
217
  return parseFloat(x);
218
218
  }
219
219
  // strict behavior as Rust semantics
220
- throw new Error("unknown syntax for EDN");
220
+ throw new Error(`unknown syntax for EDN: ${x}`);
221
221
  }
222
222
  if (x instanceof Array) {
223
223
  if (x.length === 0) {
224
- throw new Error("Cannot be empty");
224
+ throw new Error("Cannot be empty form");
225
225
  }
226
226
  if (x[0] === "{}") {
227
227
  let result: Array<CalcitValue> = [];
@@ -234,10 +234,10 @@ export let extract_cirru_edn = (x: CirruEdnFormat, options: CalcitValue): Calcit
234
234
  if (pair.length === 2) {
235
235
  result.push(extract_cirru_edn(pair[0], options), extract_cirru_edn(pair[1], options));
236
236
  } else {
237
- throw new Error(`Expected a pair, got size ${pair.length}`);
237
+ throw new Error(`Expected a pair, got: ${pair}`);
238
238
  }
239
239
  } else {
240
- throw new Error(`Expected pairs for map, got ${pair}`);
240
+ throw new Error(`Expected pairs for map, got: ${pair}`);
241
241
  }
242
242
  });
243
243
  return new CalcitSliceMap(result);
@@ -245,7 +245,7 @@ export let extract_cirru_edn = (x: CirruEdnFormat, options: CalcitValue): Calcit
245
245
  if (x[0] === "%{}") {
246
246
  let name = x[1];
247
247
  if (typeof name != "string") {
248
- throw new Error("Expected string for record name");
248
+ throw new Error(`Expected string for record name, got: ${name}`);
249
249
  }
250
250
  // put to entries first, sort and then...
251
251
  let entries: Array<[CalcitTag, CalcitValue]> = [];
@@ -259,13 +259,13 @@ export let extract_cirru_edn = (x: CirruEdnFormat, options: CalcitValue): Calcit
259
259
  if (typeof pair[0] === "string") {
260
260
  entries.push([extractFieldTag(pair[0]), extract_cirru_edn(pair[1], options)]);
261
261
  } else {
262
- throw new Error("Expected string as field");
262
+ throw new Error(`Expected string as field, got: ${pair}`);
263
263
  }
264
264
  } else {
265
- throw new Error("Expected pair of size 2");
265
+ throw new Error(`Expected pair of size 2, got: ${pair}`);
266
266
  }
267
267
  } else {
268
- throw new Error("Expected pairs for reocrd");
268
+ throw new Error(`Expected pairs for reocrd, got: ${pair}`);
269
269
  }
270
270
  });
271
271
  entries.sort((a, b) => {
@@ -318,13 +318,13 @@ export let extract_cirru_edn = (x: CirruEdnFormat, options: CalcitValue): Calcit
318
318
  }
319
319
  if (x[0] === "quote") {
320
320
  if (x.length !== 2) {
321
- throw new Error("quote expects 1 argument");
321
+ throw new Error(`quote expects 1 argument, got: ${x}`);
322
322
  }
323
323
  return new CalcitCirruQuote(x[1]);
324
324
  }
325
325
  if (x[0] === "::") {
326
326
  if (x.length < 2) {
327
- throw new Error("tuple expects at least 1 value1");
327
+ throw new Error(`tuple expects at least 1 value, got: ${x}`);
328
328
  }
329
329
  return new CalcitTuple(
330
330
  extract_cirru_edn(x[1], options),
@@ -337,7 +337,7 @@ export let extract_cirru_edn = (x: CirruEdnFormat, options: CalcitValue): Calcit
337
337
  }
338
338
  }
339
339
  console.error(x);
340
- throw new Error("Unexpected data from cirru-edn");
340
+ throw new Error(`Unexpected data from EDN: ${x}`);
341
341
  };
342
342
 
343
343
  export let format_cirru_edn = (data: CalcitValue, useInline: boolean = true): string => {
@@ -123,6 +123,8 @@ export class CalcitSliceList {
123
123
  start: number;
124
124
  end: number;
125
125
  cachedHash: Hash;
126
+ /** reference to converted list */
127
+ cachedTreeListRef: CalcitList;
126
128
  constructor(value: Array<CalcitValue>) {
127
129
  if (value == null) {
128
130
  value = []; // dirty, better handled from outside
@@ -134,7 +136,12 @@ export class CalcitSliceList {
134
136
  this.end = value.length;
135
137
  }
136
138
  turnListMode(): CalcitList {
137
- return new CalcitList(initTernaryTreeListFromRange(this.value, this.start, this.end));
139
+ if (this.cachedTreeListRef != null) {
140
+ return this.cachedTreeListRef;
141
+ }
142
+ let ret = new CalcitList(initTernaryTreeListFromRange(this.value, this.start, this.end));
143
+ this.cachedTreeListRef = ret;
144
+ return ret;
138
145
  }
139
146
  len() {
140
147
  return this.end - this.start;
package/ts-src/js-map.mts CHANGED
@@ -194,6 +194,8 @@ export class CalcitSliceMap {
194
194
  cachedHash: Hash;
195
195
  /** in arrayMode, only flatten values, instead of tree structure */
196
196
  chunk: CalcitValue[];
197
+ /** reference to generated HashMap in tree structure */
198
+ cachedTreeMapRef?: CalcitMap;
197
199
  constructor(value: CalcitValue[]) {
198
200
  if (value == null) {
199
201
  this.chunk = [];
@@ -203,14 +205,20 @@ export class CalcitSliceMap {
203
205
  throw new Error("unknown data for map");
204
206
  }
205
207
  }
208
+ /** convert to tree map when needed, also cached in case converted over and over again */
206
209
  turnMap(): CalcitMap {
210
+ if (this.cachedTreeMapRef != null) {
211
+ return this.cachedTreeMapRef;
212
+ }
207
213
  var dict: Array<[CalcitValue, CalcitValue]> = [];
208
214
  let halfLength = this.chunk.length >> 1;
209
215
  for (let idx = 0; idx < halfLength; idx++) {
210
216
  dict.push([this.chunk[idx << 1], this.chunk[(idx << 1) + 1]]);
211
217
  }
212
218
  let value = initTernaryTreeMapFromArray(dict);
213
- return new CalcitMap(value);
219
+ let ret = new CalcitMap(value);
220
+ this.cachedTreeMapRef = ret;
221
+ return ret;
214
222
  }
215
223
  len() {
216
224
  return this.chunk.length >> 1;