@calcit/procs 0.5.37 → 0.5.40

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.
@@ -3,7 +3,7 @@ import { overwriteComparator } from "@calcit/ternary-tree";
3
3
  import { overwriteMapComparator } from "./js-map.mjs";
4
4
  import { CalcitRecord, fieldsEqual } from "./js-record.mjs";
5
5
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
6
- import "./js-primes.mjs";
6
+ import { _$n_compare } from "./js-primes.mjs";
7
7
  import { CalcitList, CalcitSliceList } from "./js-list.mjs";
8
8
  import { CalcitSet, overwriteSetComparator } from "./js-set.mjs";
9
9
  import { CalcitTuple } from "./js-tuple.mjs";
@@ -220,9 +220,10 @@ export let hashFunction = (x) => {
220
220
  return base;
221
221
  }
222
222
  if (x instanceof CalcitSet) {
223
- // TODO not using dirty solution for code
224
223
  let base = defaultHash_set;
225
224
  let values = x.values();
225
+ // sort elements for stable hash result
226
+ values.sort((a, b) => _$n_compare(a, b));
226
227
  for (let idx = 0; idx < values.length; idx++) {
227
228
  let item = values[idx];
228
229
  base = mergeValueHash(base, hashFunction(item));
@@ -249,7 +250,9 @@ export let hashFunction = (x) => {
249
250
  }
250
251
  if (x instanceof CalcitSliceMap) {
251
252
  let base = defaultHash_map;
252
- for (let [k, v] of x.pairs()) {
253
+ let pairs = x.pairs();
254
+ pairs.sort((a, b) => _$n_compare(a[0], b[0]));
255
+ for (let [k, v] of pairs) {
253
256
  base = mergeValueHash(base, hashFunction(k));
254
257
  base = mergeValueHash(base, hashFunction(v));
255
258
  }
@@ -258,7 +261,9 @@ export let hashFunction = (x) => {
258
261
  }
259
262
  if (x instanceof CalcitMap) {
260
263
  let base = defaultHash_map;
261
- for (let [k, v] of x.pairs()) {
264
+ let pairs = x.pairs();
265
+ pairs.sort((a, b) => _$n_compare(a[0], b[0]));
266
+ for (let [k, v] of pairs) {
262
267
  base = mergeValueHash(base, hashFunction(k));
263
268
  base = mergeValueHash(base, hashFunction(v));
264
269
  }
@@ -1,6 +1,6 @@
1
1
  var _a;
2
2
  // CALCIT VERSION
3
- export const calcit_version = "0.5.37";
3
+ export const calcit_version = "0.5.40";
4
4
  import { parse } from "@cirru/parser.ts";
5
5
  import { writeCirruCode } from "@cirru/writer.ts";
6
6
  import "./js-primes.mjs";
@@ -848,7 +848,7 @@ export let aget = (x, name) => {
848
848
  export let aset = (x, name, v) => {
849
849
  return (x[name] = v);
850
850
  };
851
- export let get_env = (name) => {
851
+ export let get_env = (name, v0) => {
852
852
  let v = undefined;
853
853
  if (inNodeJs) {
854
854
  // only available for Node.js
@@ -857,10 +857,13 @@ export let get_env = (name) => {
857
857
  else if (typeof URLSearchParams != null && typeof location != null) {
858
858
  v = new URLSearchParams(location.search).get(name);
859
859
  }
860
- if (v == null) {
861
- console.warn(`(get-env "${name}"): ${v}`);
860
+ if (v != null && v0 != null) {
861
+ console.log(`(get-env ${name}): ${v}`);
862
862
  }
863
- return v;
863
+ if (v == null && v0 == null) {
864
+ console.warn(`(get-env "${name}"): config not found`);
865
+ }
866
+ return v !== null && v !== void 0 ? v : v0;
864
867
  };
865
868
  export let turn_keyword = (x) => {
866
869
  if (typeof x === "string") {
package/lib/js-list.mjs CHANGED
@@ -110,7 +110,10 @@ export class CalcitSliceList {
110
110
  return this.end - this.start;
111
111
  }
112
112
  get(idx) {
113
- return this.value[this.start + idx];
113
+ if (idx >= 0 && this.start + idx < this.end) {
114
+ return this.value[this.start + idx];
115
+ }
116
+ return null;
114
117
  }
115
118
  assoc(idx, v) {
116
119
  return this.turnListMode().assoc(idx, v);
@@ -147,6 +150,10 @@ export class CalcitSliceList {
147
150
  if (to < from) {
148
151
  throw new Error("end index too small");
149
152
  }
153
+ if (from === to) {
154
+ // when it's empty, just return empty list
155
+ return new CalcitSliceList([]);
156
+ }
150
157
  let result = new CalcitSliceList(this.value);
151
158
  result.start = this.start + from;
152
159
  result.end = this.start + to;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.5.37",
3
+ "version": "0.5.40",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
- "@types/node": "^17.0.23",
6
+ "@types/node": "^17.0.29",
7
7
  "typescript": "^4.6.3"
8
8
  },
9
9
  "scripts": {
@@ -5,7 +5,7 @@ import { overwriteMapComparator } from "./js-map.mjs";
5
5
  import { CalcitRecord, fieldsEqual } from "./js-record.mjs";
6
6
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
7
7
 
8
- import { CalcitValue } from "./js-primes.mjs";
8
+ import { CalcitValue, _$n_compare } from "./js-primes.mjs";
9
9
  import { CalcitList, CalcitSliceList } from "./js-list.mjs";
10
10
  import { CalcitSet, overwriteSetComparator } from "./js-set.mjs";
11
11
  import { CalcitTuple } from "./js-tuple.mjs";
@@ -251,9 +251,10 @@ export let hashFunction = (x: CalcitValue): Hash => {
251
251
  return base;
252
252
  }
253
253
  if (x instanceof CalcitSet) {
254
- // TODO not using dirty solution for code
255
254
  let base = defaultHash_set;
256
255
  let values = x.values();
256
+ // sort elements for stable hash result
257
+ values.sort((a, b) => _$n_compare(a, b));
257
258
  for (let idx = 0; idx < values.length; idx++) {
258
259
  let item = values[idx];
259
260
  base = mergeValueHash(base, hashFunction(item));
@@ -280,7 +281,9 @@ export let hashFunction = (x: CalcitValue): Hash => {
280
281
  }
281
282
  if (x instanceof CalcitSliceMap) {
282
283
  let base = defaultHash_map;
283
- for (let [k, v] of x.pairs()) {
284
+ let pairs = x.pairs();
285
+ pairs.sort((a, b) => _$n_compare(a[0], b[0]));
286
+ for (let [k, v] of pairs) {
284
287
  base = mergeValueHash(base, hashFunction(k));
285
288
  base = mergeValueHash(base, hashFunction(v));
286
289
  }
@@ -289,7 +292,10 @@ export let hashFunction = (x: CalcitValue): Hash => {
289
292
  }
290
293
  if (x instanceof CalcitMap) {
291
294
  let base = defaultHash_map;
292
- for (let [k, v] of x.pairs()) {
295
+
296
+ let pairs = x.pairs();
297
+ pairs.sort((a, b) => _$n_compare(a[0], b[0]));
298
+ for (let [k, v] of pairs) {
293
299
  base = mergeValueHash(base, hashFunction(k));
294
300
  base = mergeValueHash(base, hashFunction(v));
295
301
  }
@@ -1,5 +1,5 @@
1
1
  // CALCIT VERSION
2
- export const calcit_version = "0.5.37";
2
+ export const calcit_version = "0.5.40";
3
3
 
4
4
  import { parse, ICirruNode } from "@cirru/parser.ts";
5
5
  import { writeCirruCode } from "@cirru/writer.ts";
@@ -935,7 +935,7 @@ export let aset = (x: any, name: string, v: any): any => {
935
935
  return (x[name] = v);
936
936
  };
937
937
 
938
- export let get_env = (name: string): string => {
938
+ export let get_env = (name: string, v0: string): string => {
939
939
  let v = undefined;
940
940
  if (inNodeJs) {
941
941
  // only available for Node.js
@@ -943,10 +943,13 @@ export let get_env = (name: string): string => {
943
943
  } else if (typeof URLSearchParams != null && typeof location != null) {
944
944
  v = new URLSearchParams(location.search).get(name);
945
945
  }
946
- if (v == null) {
947
- console.warn(`(get-env "${name}"): ${v}`);
946
+ if (v != null && v0 != null) {
947
+ console.log(`(get-env ${name}): ${v}`);
948
948
  }
949
- return v;
949
+ if (v == null && v0 == null) {
950
+ console.warn(`(get-env "${name}"): config not found`);
951
+ }
952
+ return v ?? v0;
950
953
  };
951
954
 
952
955
  export let turn_keyword = (x: CalcitValue): CalcitKeyword => {
@@ -132,7 +132,10 @@ export class CalcitSliceList {
132
132
  return this.end - this.start;
133
133
  }
134
134
  get(idx: number) {
135
- return this.value[this.start + idx];
135
+ if (idx >= 0 && this.start + idx < this.end) {
136
+ return this.value[this.start + idx];
137
+ }
138
+ return null;
136
139
  }
137
140
  assoc(idx: number, v: CalcitValue) {
138
141
  return this.turnListMode().assoc(idx, v);
@@ -166,6 +169,10 @@ export class CalcitSliceList {
166
169
  if (to < from) {
167
170
  throw new Error("end index too small");
168
171
  }
172
+ if (from === to) {
173
+ // when it's empty, just return empty list
174
+ return new CalcitSliceList([]);
175
+ }
169
176
  let result = new CalcitSliceList(this.value);
170
177
  result.start = this.start + from;
171
178
  result.end = this.start + to;