@calcit/procs 0.8.56 → 0.8.58
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 +1 -1
- package/lib/js-cirru.mjs +2 -3
- package/lib/js-record.mjs +22 -0
- package/lib/package.json +1 -1
- package/package.json +1 -1
- package/ts-src/js-cirru.mts +2 -3
- package/ts-src/js-record.mts +22 -0
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ cargo install calcit
|
|
|
35
35
|
- `caps`, for downloading dependencies declared in `deps.cirru`
|
|
36
36
|
- `bundle_calcit`, bundle code if you don't want to use Calcit Editor
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
To use Calcit in GitHub Actions, try [setup-cr](https://github.com/calcit-lang/setup-cr).
|
|
39
39
|
|
|
40
40
|
### Usage
|
|
41
41
|
|
package/lib/js-cirru.mjs
CHANGED
|
@@ -219,9 +219,8 @@ export let extract_cirru_edn = (x, options) => {
|
|
|
219
219
|
if (x.match(/^(-?)\d+(\.\d*$)?/)) {
|
|
220
220
|
return parseFloat(x);
|
|
221
221
|
}
|
|
222
|
-
//
|
|
223
|
-
|
|
224
|
-
return x;
|
|
222
|
+
// strict behavior as Rust semantics
|
|
223
|
+
throw new Error("unknown syntax for EDN");
|
|
225
224
|
}
|
|
226
225
|
if (x instanceof Array) {
|
|
227
226
|
if (x.length === 0) {
|
package/lib/js-record.mjs
CHANGED
|
@@ -150,6 +150,28 @@ export let _$n__PCT__$M_ = (proto, ...xs) => {
|
|
|
150
150
|
throw new Error("Expected prototype to be a record");
|
|
151
151
|
}
|
|
152
152
|
};
|
|
153
|
+
/// update record with new values
|
|
154
|
+
export let _$n_record_$o_with = (proto, ...xs) => {
|
|
155
|
+
if (proto instanceof CalcitRecord) {
|
|
156
|
+
if (xs.length % 2 !== 0) {
|
|
157
|
+
throw new Error("Expected even number of key/value");
|
|
158
|
+
}
|
|
159
|
+
let values = proto.values.slice();
|
|
160
|
+
for (let i = 0; i < xs.length; i += 2) {
|
|
161
|
+
let k = castTag(xs[i]);
|
|
162
|
+
let v = xs[i + 1];
|
|
163
|
+
let idx = findInFields(proto.fields, k);
|
|
164
|
+
if (idx < 0) {
|
|
165
|
+
throw new Error(`Cannot find field ${k} among ${proto.fields}`);
|
|
166
|
+
}
|
|
167
|
+
values[idx] = v;
|
|
168
|
+
}
|
|
169
|
+
return new CalcitRecord(proto.name, proto.fields, values, proto.klass);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
throw new Error("Expected prototype to be a record");
|
|
173
|
+
}
|
|
174
|
+
};
|
|
153
175
|
export let _$n_record_$o_get_name = (x) => {
|
|
154
176
|
if (x instanceof CalcitRecord) {
|
|
155
177
|
return x.name;
|
package/lib/package.json
CHANGED
package/package.json
CHANGED
package/ts-src/js-cirru.mts
CHANGED
|
@@ -216,9 +216,8 @@ export let extract_cirru_edn = (x: CirruEdnFormat, options: CalcitValue): Calcit
|
|
|
216
216
|
if (x.match(/^(-?)\d+(\.\d*$)?/)) {
|
|
217
217
|
return parseFloat(x);
|
|
218
218
|
}
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
return x;
|
|
219
|
+
// strict behavior as Rust semantics
|
|
220
|
+
throw new Error("unknown syntax for EDN");
|
|
222
221
|
}
|
|
223
222
|
if (x instanceof Array) {
|
|
224
223
|
if (x.length === 0) {
|
package/ts-src/js-record.mts
CHANGED
|
@@ -158,6 +158,28 @@ export let _$n__PCT__$M_ = (proto: CalcitValue, ...xs: Array<CalcitValue>): Calc
|
|
|
158
158
|
}
|
|
159
159
|
};
|
|
160
160
|
|
|
161
|
+
/// update record with new values
|
|
162
|
+
export let _$n_record_$o_with = (proto: CalcitValue, ...xs: Array<CalcitValue>): CalcitValue => {
|
|
163
|
+
if (proto instanceof CalcitRecord) {
|
|
164
|
+
if (xs.length % 2 !== 0) {
|
|
165
|
+
throw new Error("Expected even number of key/value");
|
|
166
|
+
}
|
|
167
|
+
let values = proto.values.slice();
|
|
168
|
+
for (let i = 0; i < xs.length; i += 2) {
|
|
169
|
+
let k = castTag(xs[i]);
|
|
170
|
+
let v = xs[i + 1];
|
|
171
|
+
let idx = findInFields(proto.fields, k);
|
|
172
|
+
if (idx < 0) {
|
|
173
|
+
throw new Error(`Cannot find field ${k} among ${proto.fields}`);
|
|
174
|
+
}
|
|
175
|
+
values[idx] = v;
|
|
176
|
+
}
|
|
177
|
+
return new CalcitRecord(proto.name, proto.fields, values, proto.klass);
|
|
178
|
+
} else {
|
|
179
|
+
throw new Error("Expected prototype to be a record");
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
161
183
|
export let _$n_record_$o_get_name = (x: CalcitRecord): CalcitTag => {
|
|
162
184
|
if (x instanceof CalcitRecord) {
|
|
163
185
|
return x.name;
|