@calcit/procs 0.8.57 → 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/lib/js-record.mjs +22 -0
- package/lib/package.json +1 -1
- package/package.json +1 -1
- package/ts-src/js-record.mts +22 -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-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;
|