@calcit/procs 0.5.28 → 0.5.29

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ### Calcit Scripting Language
2
2
 
3
- > Spiritually dialect of ClojureScript. Built with Rust. Also compiles to JavaScript ES Modules.
3
+ > Semantically a dialect of ClojureScript. Built with Rust. Compiles to JavaScript ES Modules.
4
4
 
5
5
  - Home http://calcit-lang.org/
6
6
  - API Doc http://apis.calcit-lang.org/
@@ -286,7 +286,7 @@ let hashFunction = (x) => {
286
286
  };
287
287
  // Dirty code to change ternary-tree behavior
288
288
  overwriteHashGenerator(hashFunction);
289
- export let toString = (x, escaped) => {
289
+ export let toString = (x, escaped, disableJsDataWarning = false) => {
290
290
  if (x == null) {
291
291
  return "nil";
292
292
  }
@@ -320,25 +320,27 @@ export let toString = (x, escaped) => {
320
320
  return x.toString();
321
321
  }
322
322
  if (x instanceof CalcitList || x instanceof CalcitSliceList) {
323
- return x.toString();
323
+ return x.toString(false, disableJsDataWarning);
324
324
  }
325
325
  if (x instanceof CalcitMap || x instanceof CalcitSliceMap) {
326
- return x.toString();
326
+ return x.toString(false, disableJsDataWarning);
327
327
  }
328
328
  if (x instanceof CalcitSet) {
329
- return x.toString();
329
+ return x.toString(disableJsDataWarning);
330
330
  }
331
331
  if (x instanceof CalcitRecord) {
332
- return x.toString();
332
+ return x.toString(disableJsDataWarning);
333
333
  }
334
334
  if (x instanceof CalcitRef) {
335
335
  return x.toString();
336
336
  }
337
337
  if (x instanceof CalcitTuple) {
338
- return x.toString();
338
+ return x.toString(disableJsDataWarning);
339
+ }
340
+ if (!disableJsDataWarning) {
341
+ console.warn("Unknown structure to string, better use `console.log`", x);
339
342
  }
340
- console.warn("Unknown structure to string, better use `console.log`", x);
341
- return `${x}`;
343
+ return `(#js ${JSON.stringify(x)})`;
342
344
  };
343
345
  export let to_js_data = (x, addColon = false) => {
344
346
  if (x == null) {
@@ -1,6 +1,6 @@
1
1
  var _a;
2
2
  // CALCIT VERSION
3
- export const calcit_version = "0.5.28";
3
+ export const calcit_version = "0.5.29";
4
4
  import "@calcit/ternary-tree";
5
5
  import { parse } from "@cirru/parser.ts";
6
6
  import { writeCirruCode } from "@cirru/writer.ts";
@@ -31,15 +31,15 @@ export let load_console_formatter_$x_ = () => {
31
31
  return [
32
32
  "div",
33
33
  { style: "color: hsl(280, 80%, 60%, 0.4)" },
34
- obj.toString(true),
34
+ obj.toString(true, true),
35
35
  ["span", { style: "font-size: 80%; vertical-align: 0.7em; color: hsl(280, 80%, 60%, 0.8)" }, `${obj.len()}`],
36
36
  ];
37
37
  }
38
38
  if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
39
- return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString(true)];
39
+ return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString(true, true)];
40
40
  }
41
41
  if (obj instanceof CalcitSet) {
42
- return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString()];
42
+ return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString(true)];
43
43
  }
44
44
  if (obj instanceof CalcitRecord) {
45
45
  let ret = ["div", { style: "color: hsl(280, 80%, 60%)" }, `%{} ${obj.name}`];
package/lib/js-list.mjs CHANGED
@@ -40,14 +40,14 @@ export class CalcitList {
40
40
  slice(from, to) {
41
41
  return new CalcitList(ternaryTree.slice(this.value, from, to));
42
42
  }
43
- toString(shorter = false) {
43
+ toString(shorter = false, disableJsDataWarning = false) {
44
44
  let result = "";
45
45
  for (let item of this.items()) {
46
46
  if (shorter && isNestedCalcitData(item)) {
47
47
  result = `${result} ${tipNestedCalcitData(item)}`;
48
48
  }
49
49
  else {
50
- result = `${result} ${toString(item, true)}`;
50
+ result = `${result} ${toString(item, true, disableJsDataWarning)}`;
51
51
  }
52
52
  }
53
53
  return `([]${result})`;
@@ -152,14 +152,14 @@ export class CalcitSliceList {
152
152
  result.end = this.start + to;
153
153
  return result;
154
154
  }
155
- toString(shorter = false) {
155
+ toString(shorter = false, disableJsDataWarning = false) {
156
156
  let result = "";
157
157
  for (let item of this.items()) {
158
158
  if (shorter && isNestedCalcitData(item)) {
159
159
  result = `${result} ${tipNestedCalcitData(item)}`;
160
160
  }
161
161
  else {
162
- result = `${result} ${toString(item, true)}`;
162
+ result = `${result} ${toString(item, true, disableJsDataWarning)}`;
163
163
  }
164
164
  }
165
165
  return `([]${result})`;
package/lib/js-map.mjs CHANGED
@@ -46,16 +46,16 @@ export class CalcitMap {
46
46
  }
47
47
  return new CalcitMap(ret);
48
48
  }
49
- toString(shorter = false) {
49
+ toString(shorter = false, disableJsDataWarning = false) {
50
50
  let itemsCode = "";
51
51
  for (let [k, v] of this.pairs()) {
52
52
  if (shorter) {
53
- let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true);
54
- let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true);
53
+ let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true, disableJsDataWarning);
54
+ let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true, disableJsDataWarning);
55
55
  itemsCode = `${itemsCode} (${keyPart} ${valuePart})`;
56
56
  }
57
57
  else {
58
- itemsCode = `${itemsCode} (${toString(k, true)} ${toString(v, true)})`;
58
+ itemsCode = `${itemsCode} (${toString(k, true, disableJsDataWarning)} ${toString(v, true, disableJsDataWarning)})`;
59
59
  }
60
60
  }
61
61
  return `({}${itemsCode})`;
@@ -233,16 +233,16 @@ export class CalcitSliceMap {
233
233
  return this.turnMap().dissoc(...args);
234
234
  }
235
235
  }
236
- toString(shorter = false) {
236
+ toString(shorter = false, disableJsDataWarning = false) {
237
237
  let itemsCode = "";
238
238
  for (let [k, v] of this.pairs()) {
239
239
  if (shorter) {
240
- let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true);
241
- let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true);
240
+ let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true, disableJsDataWarning);
241
+ let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true, disableJsDataWarning);
242
242
  itemsCode = `${itemsCode} (${keyPart} ${valuePart})`;
243
243
  }
244
244
  else {
245
- itemsCode = `${itemsCode} (${toString(k, true)} ${toString(v, true)})`;
245
+ itemsCode = `${itemsCode} (${toString(k, true, disableJsDataWarning)} ${toString(v, true, disableJsDataWarning)})`;
246
246
  }
247
247
  }
248
248
  return `({}${itemsCode})`;
package/lib/js-record.mjs CHANGED
@@ -51,10 +51,10 @@ export class CalcitRecord {
51
51
  let idx = this.findIndex(k);
52
52
  return idx >= 0;
53
53
  }
54
- toString() {
54
+ toString(disableJsDataWarning = false) {
55
55
  let ret = "(%{} " + this.name;
56
56
  for (let idx = 0; idx < this.fields.length; idx++) {
57
- ret += " (" + this.fields[idx] + " " + toString(this.values[idx], true) + ")";
57
+ ret += " (" + this.fields[idx] + " " + toString(this.values[idx], true, disableJsDataWarning) + ")";
58
58
  }
59
59
  return ret + ")";
60
60
  }
package/lib/js-set.mjs CHANGED
@@ -83,10 +83,10 @@ export class CalcitSet {
83
83
  let result = dissocMap(this.value, x0);
84
84
  return new CalcitSet(result);
85
85
  }
86
- toString() {
86
+ toString(disableJsDataWarning = false) {
87
87
  let itemsCode = "";
88
88
  for (let k of ternaryTree.toKeys(this.value)) {
89
- itemsCode = `${itemsCode} ${toString(k, true)}`;
89
+ itemsCode = `${itemsCode} ${toString(k, true, disableJsDataWarning)}`;
90
90
  }
91
91
  return `(#{}${itemsCode})`;
92
92
  }
package/lib/js-tuple.mjs CHANGED
@@ -1,5 +1,6 @@
1
- import "./js-primes.mjs";
2
1
  import "@calcit/ternary-tree";
2
+ import "./js-primes.mjs";
3
+ import { toString } from "./calcit-data.mjs";
3
4
  export class CalcitTuple {
4
5
  constructor(a, b) {
5
6
  this.fst = a;
@@ -28,7 +29,7 @@ export class CalcitTuple {
28
29
  throw new Error("Tuple only have 2 elements");
29
30
  }
30
31
  }
31
- toString() {
32
- return `(&tuple ${this.fst.toString()} ${this.snd.toString()})`;
32
+ toString(disableJsDataWarning = false) {
33
+ return `(&tuple ${toString(this.fst, false, disableJsDataWarning)} ${toString(this.snd, false, disableJsDataWarning)})`;
33
34
  }
34
35
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.5.28",
3
+ "version": "0.5.29",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
6
  "@types/node": "^17.0.23",
7
- "typescript": "^4.6.2"
7
+ "typescript": "^4.6.3"
8
8
  },
9
9
  "scripts": {
10
10
  "compile": "rm -rfv lib/* && tsc",
@@ -319,7 +319,7 @@ let hashFunction = (x: CalcitValue): Hash => {
319
319
  // Dirty code to change ternary-tree behavior
320
320
  overwriteHashGenerator(hashFunction);
321
321
 
322
- export let toString = (x: CalcitValue, escaped: boolean): string => {
322
+ export let toString = (x: CalcitValue, escaped: boolean, disableJsDataWarning: boolean = false): string => {
323
323
  if (x == null) {
324
324
  return "nil";
325
325
  }
@@ -351,26 +351,28 @@ export let toString = (x: CalcitValue, escaped: boolean): string => {
351
351
  return x.toString();
352
352
  }
353
353
  if (x instanceof CalcitList || x instanceof CalcitSliceList) {
354
- return x.toString();
354
+ return x.toString(false, disableJsDataWarning);
355
355
  }
356
356
  if (x instanceof CalcitMap || x instanceof CalcitSliceMap) {
357
- return x.toString();
357
+ return x.toString(false, disableJsDataWarning);
358
358
  }
359
359
  if (x instanceof CalcitSet) {
360
- return x.toString();
360
+ return x.toString(disableJsDataWarning);
361
361
  }
362
362
  if (x instanceof CalcitRecord) {
363
- return x.toString();
363
+ return x.toString(disableJsDataWarning);
364
364
  }
365
365
  if (x instanceof CalcitRef) {
366
366
  return x.toString();
367
367
  }
368
368
  if (x instanceof CalcitTuple) {
369
- return x.toString();
369
+ return x.toString(disableJsDataWarning);
370
370
  }
371
371
 
372
- console.warn("Unknown structure to string, better use `console.log`", x);
373
- return `${x}`;
372
+ if (!disableJsDataWarning) {
373
+ console.warn("Unknown structure to string, better use `console.log`", x);
374
+ }
375
+ return `(#js ${JSON.stringify(x)})`;
374
376
  };
375
377
 
376
378
  export let to_js_data = (x: CalcitValue, addColon: boolean = false): any => {
@@ -1,5 +1,5 @@
1
1
  // CALCIT VERSION
2
- export const calcit_version = "0.5.28";
2
+ export const calcit_version = "0.5.29";
3
3
 
4
4
  import { overwriteComparator, initTernaryTreeMap } from "@calcit/ternary-tree";
5
5
  import { parse, ICirruNode } from "@cirru/parser.ts";
@@ -44,15 +44,15 @@ export let load_console_formatter_$x_ = () => {
44
44
  return [
45
45
  "div",
46
46
  { style: "color: hsl(280, 80%, 60%, 0.4)" },
47
- obj.toString(true),
47
+ obj.toString(true, true),
48
48
  ["span", { style: "font-size: 80%; vertical-align: 0.7em; color: hsl(280, 80%, 60%, 0.8)" }, `${obj.len()}`],
49
49
  ];
50
50
  }
51
51
  if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
52
- return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString(true)];
52
+ return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString(true, true)];
53
53
  }
54
54
  if (obj instanceof CalcitSet) {
55
- return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString()];
55
+ return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString(true)];
56
56
  }
57
57
  if (obj instanceof CalcitRecord) {
58
58
  let ret: any[] = ["div", { style: "color: hsl(280, 80%, 60%)" }, `%{} ${obj.name}`];
@@ -58,13 +58,13 @@ export class CalcitList {
58
58
  slice(from: number, to: number) {
59
59
  return new CalcitList(ternaryTree.slice(this.value, from, to));
60
60
  }
61
- toString(shorter = false): string {
61
+ toString(shorter = false, disableJsDataWarning: boolean = false): string {
62
62
  let result = "";
63
63
  for (let item of this.items()) {
64
64
  if (shorter && isNestedCalcitData(item)) {
65
65
  result = `${result} ${tipNestedCalcitData(item)}`;
66
66
  } else {
67
- result = `${result} ${toString(item, true)}`;
67
+ result = `${result} ${toString(item, true, disableJsDataWarning)}`;
68
68
  }
69
69
  }
70
70
  return `([]${result})`;
@@ -171,13 +171,13 @@ export class CalcitSliceList {
171
171
  result.end = this.start + to;
172
172
  return result;
173
173
  }
174
- toString(shorter = false): string {
174
+ toString(shorter = false, disableJsDataWarning = false): string {
175
175
  let result = "";
176
176
  for (let item of this.items()) {
177
177
  if (shorter && isNestedCalcitData(item)) {
178
178
  result = `${result} ${tipNestedCalcitData(item)}`;
179
179
  } else {
180
- result = `${result} ${toString(item, true)}`;
180
+ result = `${result} ${toString(item, true, disableJsDataWarning)}`;
181
181
  }
182
182
  }
183
183
  return `([]${result})`;
package/ts-src/js-map.mts CHANGED
@@ -66,15 +66,15 @@ export class CalcitMap {
66
66
  }
67
67
  return new CalcitMap(ret);
68
68
  }
69
- toString(shorter = false) {
69
+ toString(shorter = false, disableJsDataWarning = false) {
70
70
  let itemsCode = "";
71
71
  for (let [k, v] of this.pairs()) {
72
72
  if (shorter) {
73
- let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true);
74
- let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true);
73
+ let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true, disableJsDataWarning);
74
+ let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true, disableJsDataWarning);
75
75
  itemsCode = `${itemsCode} (${keyPart} ${valuePart})`;
76
76
  } else {
77
- itemsCode = `${itemsCode} (${toString(k, true)} ${toString(v, true)})`;
77
+ itemsCode = `${itemsCode} (${toString(k, true, disableJsDataWarning)} ${toString(v, true, disableJsDataWarning)})`;
78
78
  }
79
79
  }
80
80
  return `({}${itemsCode})`;
@@ -252,15 +252,15 @@ export class CalcitSliceMap {
252
252
  return this.turnMap().dissoc(...args);
253
253
  }
254
254
  }
255
- toString(shorter = false) {
255
+ toString(shorter = false, disableJsDataWarning = false) {
256
256
  let itemsCode = "";
257
257
  for (let [k, v] of this.pairs()) {
258
258
  if (shorter) {
259
- let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true);
260
- let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true);
259
+ let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true, disableJsDataWarning);
260
+ let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true, disableJsDataWarning);
261
261
  itemsCode = `${itemsCode} (${keyPart} ${valuePart})`;
262
262
  } else {
263
- itemsCode = `${itemsCode} (${toString(k, true)} ${toString(v, true)})`;
263
+ itemsCode = `${itemsCode} (${toString(k, true, disableJsDataWarning)} ${toString(v, true, disableJsDataWarning)})`;
264
264
  }
265
265
  }
266
266
  return `({}${itemsCode})`;
@@ -54,10 +54,10 @@ export class CalcitRecord {
54
54
  let idx = this.findIndex(k);
55
55
  return idx >= 0;
56
56
  }
57
- toString(): string {
57
+ toString(disableJsDataWarning: boolean = false): string {
58
58
  let ret = "(%{} " + this.name;
59
59
  for (let idx = 0; idx < this.fields.length; idx++) {
60
- ret += " (" + this.fields[idx] + " " + toString(this.values[idx], true) + ")";
60
+ ret += " (" + this.fields[idx] + " " + toString(this.values[idx], true, disableJsDataWarning) + ")";
61
61
  }
62
62
  return ret + ")";
63
63
  }
package/ts-src/js-set.mts CHANGED
@@ -105,10 +105,10 @@ export class CalcitSet {
105
105
  return new CalcitSet(result);
106
106
  }
107
107
 
108
- toString() {
108
+ toString(disableJsDataWarning: boolean = false) {
109
109
  let itemsCode = "";
110
110
  for (let k of ternaryTree.toKeys(this.value)) {
111
- itemsCode = `${itemsCode} ${toString(k, true)}`;
111
+ itemsCode = `${itemsCode} ${toString(k, true, disableJsDataWarning)}`;
112
112
  }
113
113
  return `(#{}${itemsCode})`;
114
114
  }
@@ -1,7 +1,8 @@
1
- import { CalcitValue } from "./js-primes.mjs";
2
-
3
1
  import { Hash } from "@calcit/ternary-tree";
4
2
 
3
+ import { CalcitValue } from "./js-primes.mjs";
4
+ import { toString } from "./calcit-data.mjs";
5
+
5
6
  export class CalcitTuple {
6
7
  fst: CalcitValue;
7
8
  snd: CalcitValue;
@@ -29,7 +30,7 @@ export class CalcitTuple {
29
30
  throw new Error("Tuple only have 2 elements");
30
31
  }
31
32
  }
32
- toString(): string {
33
- return `(&tuple ${this.fst.toString()} ${this.snd.toString()})`;
33
+ toString(disableJsDataWarning: boolean = false): string {
34
+ return `(&tuple ${toString(this.fst, false, disableJsDataWarning)} ${toString(this.snd, false, disableJsDataWarning)})`;
34
35
  }
35
36
  }
@@ -1,3 +0,0 @@
1
- {
2
- "typescript.tsdk": "node_modules/typescript/lib"
3
- }