@dataverse-to-code/test 0.22.1 → 0.23.0
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/dist/.built +1 -1
- package/dist/cli.js +64 -36
- package/dist/sim.js +62 -36
- package/package.json +1 -1
package/dist/.built
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2026-10-
|
|
1
|
+
2026-10-17T07:43:01.140Z
|
package/dist/cli.js
CHANGED
|
@@ -12009,17 +12009,27 @@ var bare = (id2) => id2.replace(/[{}]/g, "").toLowerCase();
|
|
|
12009
12009
|
var dateOnly = (col) => col.type === "date" || col.behavior === "dateOnly";
|
|
12010
12010
|
var day = (d) => Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
|
|
12011
12011
|
var asDate = (s) => new Date(s.length === 10 ? `${s}T00:00:00Z` : /(Z|[+-]\d\d:?\d\d)$/.test(s) ? s : `${s}Z`);
|
|
12012
|
-
function
|
|
12012
|
+
function option(col, v) {
|
|
12013
|
+
if (typeof v === "number") return v;
|
|
12014
|
+
const text = String(v).trim();
|
|
12015
|
+
if (/^-?\d+$/.test(text)) return Number(text);
|
|
12016
|
+
const matches = col.options.filter((o) => o.label.toLowerCase() === text.toLowerCase());
|
|
12017
|
+
return matches.length > 0 ? matches[0].value : null;
|
|
12018
|
+
}
|
|
12019
|
+
function fromRecord(col, record2, nameOf, tableOf2) {
|
|
12013
12020
|
if (LOOKUP.has(col.type)) {
|
|
12014
12021
|
const id2 = record2[`_${col.name}_value`];
|
|
12015
12022
|
if (typeof id2 !== "string") return null;
|
|
12016
|
-
const table = String(record2[`_${col.name}_value@Microsoft.Dynamics.CRM.lookuplogicalname`] ?? col.target ?? "");
|
|
12023
|
+
const table = String(record2[`_${col.name}_value@Microsoft.Dynamics.CRM.lookuplogicalname`] ?? tableOf2?.(id2) ?? col.target ?? "");
|
|
12017
12024
|
return [{ id: id2, name: nameOf(table, id2), entityType: table }];
|
|
12018
12025
|
}
|
|
12019
12026
|
const v = record2[col.name];
|
|
12020
12027
|
if (v === void 0 || v === null || v === "") return null;
|
|
12021
|
-
if (
|
|
12022
|
-
if (col.type
|
|
12028
|
+
if (col.type === "choice") return option(col, v);
|
|
12029
|
+
if (NUMBER.has(col.type)) return Number(v);
|
|
12030
|
+
if (col.type === "choices") {
|
|
12031
|
+
return (Array.isArray(v) ? v : String(v).split(",").filter(Boolean)).map((o) => option(col, o)).filter((o) => o !== null);
|
|
12032
|
+
}
|
|
12023
12033
|
if (col.type === "yesNo") return v === true || v === "true" || v === 1;
|
|
12024
12034
|
if (DATE.has(col.type)) return asDate(String(v));
|
|
12025
12035
|
return String(v);
|
|
@@ -12369,7 +12379,7 @@ var Store = class {
|
|
|
12369
12379
|
this.tables = tables;
|
|
12370
12380
|
this.newId = newId;
|
|
12371
12381
|
this.lookupColumns = lookupColumns;
|
|
12372
|
-
for (const r2 of records) this.put({ table: r2.table, id: r2.id, values: this.normalise(r2.table, r2.values) });
|
|
12382
|
+
for (const r2 of records) this.put({ table: r2.table, id: r2.id, values: this.normalise(r2.table, r2.values), ...r2.source ? { source: r2.source } : {} });
|
|
12373
12383
|
}
|
|
12374
12384
|
tables;
|
|
12375
12385
|
newId;
|
|
@@ -12394,6 +12404,15 @@ var Store = class {
|
|
|
12394
12404
|
all(table) {
|
|
12395
12405
|
return [...this.records.get(table)?.values() ?? []];
|
|
12396
12406
|
}
|
|
12407
|
+
/** Every record, of every table, as records are written (lookups as col: id, no annotations) and with where it came from: to start again from. */
|
|
12408
|
+
written() {
|
|
12409
|
+
return [...this.records.values()].flatMap((m) => [...m.values()]).map((r2) => ({
|
|
12410
|
+
table: r2.table,
|
|
12411
|
+
id: r2.id,
|
|
12412
|
+
...r2.source ? { source: r2.source } : {},
|
|
12413
|
+
values: Object.fromEntries(Object.entries(r2.values).filter(([k]) => !k.includes("@")).map(([k, v]) => [/^_(.+)_value$/.exec(k)?.[1] ?? k, v]))
|
|
12414
|
+
}));
|
|
12415
|
+
}
|
|
12397
12416
|
get(table, id2) {
|
|
12398
12417
|
return this.records.get(table)?.get(key(id2));
|
|
12399
12418
|
}
|
|
@@ -12410,10 +12429,19 @@ var Store = class {
|
|
|
12410
12429
|
delete(table, id2) {
|
|
12411
12430
|
this.records.get(table)?.delete(key(id2));
|
|
12412
12431
|
}
|
|
12432
|
+
/** A record's name: its primary name, or for a table the form doesn't know (pulled data), its first text value. */
|
|
12413
12433
|
nameOf(table, id2) {
|
|
12414
12434
|
const name2 = this.tables[table]?.primaryName;
|
|
12415
12435
|
const r2 = this.get(table, id2);
|
|
12416
|
-
|
|
12436
|
+
if (!r2) return "";
|
|
12437
|
+
if (name2) return String(r2.values[name2] ?? "");
|
|
12438
|
+
const first = Object.entries(r2.values).find(([k, v]) => typeof v === "string" && !k.startsWith("_") && !k.includes("@"));
|
|
12439
|
+
return first ? String(first[1]) : "";
|
|
12440
|
+
}
|
|
12441
|
+
/** The table that holds a record with this id, if any. */
|
|
12442
|
+
tableOf(id2) {
|
|
12443
|
+
for (const [table, records] of this.records) if (records.has(key(id2))) return table;
|
|
12444
|
+
return void 0;
|
|
12417
12445
|
}
|
|
12418
12446
|
/** The record as the Web API returns it: its id under the primary id name, then the values ($select keeps those named). */
|
|
12419
12447
|
webApi(table, record2, select) {
|
|
@@ -12829,7 +12857,7 @@ var Simulator = class {
|
|
|
12829
12857
|
const record2 = this.store.get(this.pkg.table, id2);
|
|
12830
12858
|
if (!record2) throw new Error(`No ${this.pkg.table} record ${id2} in the offline data.`);
|
|
12831
12859
|
for (const field2 of this.state.values.keys()) {
|
|
12832
|
-
this.state.values.set(field2, fromRecord(this.state.columns.get(field2), record2.values, (t, i) => this.store.nameOf(t, i)));
|
|
12860
|
+
this.state.values.set(field2, fromRecord(this.state.columns.get(field2), record2.values, (t, i) => this.store.nameOf(t, i), (i) => this.store.tableOf(i)));
|
|
12833
12861
|
}
|
|
12834
12862
|
this.state.formType = 2;
|
|
12835
12863
|
this.state.recordId = record2.id;
|
|
@@ -13469,8 +13497,8 @@ function sample(col) {
|
|
|
13469
13497
|
return col.maxLength !== void 0 ? "Test".slice(0, Math.max(1, col.maxLength)) : "Test";
|
|
13470
13498
|
}
|
|
13471
13499
|
function choiceWritten(col, value2) {
|
|
13472
|
-
const
|
|
13473
|
-
return
|
|
13500
|
+
const option2 = col.options.find((o) => o.value === value2);
|
|
13501
|
+
return option2 && col.options.filter((o) => o.label === option2.label).length === 1 ? option2.label : value2;
|
|
13474
13502
|
}
|
|
13475
13503
|
function choiceValue(col, written) {
|
|
13476
13504
|
if (typeof written === "number") return written;
|
|
@@ -14353,8 +14381,8 @@ function toXrm(col, written) {
|
|
|
14353
14381
|
const text = String(written).trim().toLowerCase();
|
|
14354
14382
|
if (["true", "yes", "1"].includes(text)) return true;
|
|
14355
14383
|
if (["false", "no", "0"].includes(text)) return false;
|
|
14356
|
-
const
|
|
14357
|
-
if (
|
|
14384
|
+
const option2 = col.options.find((o) => o.label.toLowerCase() === text);
|
|
14385
|
+
if (option2) return option2.value === 1;
|
|
14358
14386
|
const labels = col.options.map((o) => o.label);
|
|
14359
14387
|
throw new Error(`${col.name}: expected yes or no${labels.length > 0 ? ` (or ${labels.join(" or ")})` : ""}, was "${String(written)}"`);
|
|
14360
14388
|
}
|
|
@@ -44290,10 +44318,10 @@ var HTMLFormElement = class _HTMLFormElement extends HTMLElement {
|
|
|
44290
44318
|
break;
|
|
44291
44319
|
case "SELECT":
|
|
44292
44320
|
let hasSelectedAttribute = false;
|
|
44293
|
-
for (const
|
|
44294
|
-
if (
|
|
44321
|
+
for (const option2 of element2.options) {
|
|
44322
|
+
if (option2.hasAttribute("selected")) {
|
|
44295
44323
|
hasSelectedAttribute = true;
|
|
44296
|
-
|
|
44324
|
+
option2.selected = true;
|
|
44297
44325
|
break;
|
|
44298
44326
|
}
|
|
44299
44327
|
}
|
|
@@ -51566,9 +51594,9 @@ var HTMLSelectElement = class _HTMLSelectElement extends HTMLElement {
|
|
|
51566
51594
|
get value() {
|
|
51567
51595
|
const options3 = QuerySelector.querySelectorAll(this, "option")[items2];
|
|
51568
51596
|
for (let i = 0, max = options3.length; i < max; i++) {
|
|
51569
|
-
const
|
|
51570
|
-
if (
|
|
51571
|
-
return
|
|
51597
|
+
const option2 = options3[i];
|
|
51598
|
+
if (option2[selectedness]) {
|
|
51599
|
+
return option2.value;
|
|
51572
51600
|
}
|
|
51573
51601
|
}
|
|
51574
51602
|
return "";
|
|
@@ -51582,13 +51610,13 @@ var HTMLSelectElement = class _HTMLSelectElement extends HTMLElement {
|
|
|
51582
51610
|
const options3 = QuerySelector.querySelectorAll(this, "option")[items2];
|
|
51583
51611
|
this[selectedIndex] = -1;
|
|
51584
51612
|
for (let i = 0, max = options3.length; i < max; i++) {
|
|
51585
|
-
const
|
|
51586
|
-
if (
|
|
51587
|
-
|
|
51588
|
-
|
|
51613
|
+
const option2 = options3[i];
|
|
51614
|
+
if (option2.value === value2) {
|
|
51615
|
+
option2[selectedness] = true;
|
|
51616
|
+
option2[dirtyness] = true;
|
|
51589
51617
|
this[selectedIndex] = i;
|
|
51590
51618
|
} else {
|
|
51591
|
-
|
|
51619
|
+
option2[selectedness] = false;
|
|
51592
51620
|
}
|
|
51593
51621
|
}
|
|
51594
51622
|
}
|
|
@@ -51638,9 +51666,9 @@ var HTMLSelectElement = class _HTMLSelectElement extends HTMLElement {
|
|
|
51638
51666
|
}
|
|
51639
51667
|
const selectedOptions2 = [];
|
|
51640
51668
|
for (let i = 0, max = options3.length; i < max; i++) {
|
|
51641
|
-
const
|
|
51642
|
-
if (
|
|
51643
|
-
selectedOptions2.push(
|
|
51669
|
+
const option2 = options3[i];
|
|
51670
|
+
if (option2[selectedness]) {
|
|
51671
|
+
selectedOptions2.push(option2);
|
|
51644
51672
|
}
|
|
51645
51673
|
}
|
|
51646
51674
|
options3[selectedOptions] = selectedOptions2;
|
|
@@ -51718,8 +51746,8 @@ var HTMLSelectElement = class _HTMLSelectElement extends HTMLElement {
|
|
|
51718
51746
|
while (childNodes3.length) {
|
|
51719
51747
|
this[removeChild](childNodes3[0]);
|
|
51720
51748
|
}
|
|
51721
|
-
for (const
|
|
51722
|
-
this[appendChild](
|
|
51749
|
+
for (const option2 of options3) {
|
|
51750
|
+
this[appendChild](option2);
|
|
51723
51751
|
}
|
|
51724
51752
|
this[appendChild](element2);
|
|
51725
51753
|
return;
|
|
@@ -51816,15 +51844,15 @@ var HTMLSelectElement = class _HTMLSelectElement extends HTMLElement {
|
|
|
51816
51844
|
}
|
|
51817
51845
|
if (!isMultiple) {
|
|
51818
51846
|
for (let i = 0, max = options3.length; i < max; i++) {
|
|
51819
|
-
const
|
|
51847
|
+
const option2 = options3[i];
|
|
51820
51848
|
if (selectedOption) {
|
|
51821
|
-
|
|
51822
|
-
if (
|
|
51849
|
+
option2[selectedness] = option2 === selectedOption;
|
|
51850
|
+
if (option2 === selectedOption) {
|
|
51823
51851
|
this[selectedIndex] = i;
|
|
51824
51852
|
}
|
|
51825
51853
|
}
|
|
51826
|
-
if (
|
|
51827
|
-
selected.push(
|
|
51854
|
+
if (option2[selectedness]) {
|
|
51855
|
+
selected.push(option2);
|
|
51828
51856
|
}
|
|
51829
51857
|
}
|
|
51830
51858
|
}
|
|
@@ -51832,14 +51860,14 @@ var HTMLSelectElement = class _HTMLSelectElement extends HTMLElement {
|
|
|
51832
51860
|
if (size === 1 && !selected.length) {
|
|
51833
51861
|
this[selectedIndex] = -1;
|
|
51834
51862
|
for (let i = 0, max = options3.length; i < max; i++) {
|
|
51835
|
-
const
|
|
51836
|
-
const parentNode2 =
|
|
51837
|
-
let disabled2 =
|
|
51863
|
+
const option2 = options3[i];
|
|
51864
|
+
const parentNode2 = option2[parentNode];
|
|
51865
|
+
let disabled2 = option2.hasAttributeNS(null, "disabled");
|
|
51838
51866
|
if (parentNode2 && parentNode2[nodeType] === NodeTypeEnum_default.elementNode && parentNode2[tagName] === "OPTGROUP" && parentNode2.hasAttributeNS(null, "disabled")) {
|
|
51839
51867
|
disabled2 = true;
|
|
51840
51868
|
}
|
|
51841
51869
|
if (!disabled2) {
|
|
51842
|
-
|
|
51870
|
+
option2[selectedness] = true;
|
|
51843
51871
|
this[selectedIndex] = i;
|
|
51844
51872
|
break;
|
|
51845
51873
|
}
|
package/dist/sim.js
CHANGED
|
@@ -3539,30 +3539,6 @@ ${cn.comment}` : item.comment;
|
|
|
3539
3539
|
var flowIndicatorChars = new Set(",[]{}");
|
|
3540
3540
|
var invalidAnchorChars = new Set(" ,[]{}\n\r ");
|
|
3541
3541
|
|
|
3542
|
-
// ../../node_modules/yaml/browser/dist/public-api.js
|
|
3543
|
-
function stringify3(value, replacer, options) {
|
|
3544
|
-
let _replacer = null;
|
|
3545
|
-
if (typeof replacer === "function" || Array.isArray(replacer)) {
|
|
3546
|
-
_replacer = replacer;
|
|
3547
|
-
} else if (options === void 0 && replacer) {
|
|
3548
|
-
options = replacer;
|
|
3549
|
-
}
|
|
3550
|
-
if (typeof options === "string")
|
|
3551
|
-
options = options.length;
|
|
3552
|
-
if (typeof options === "number") {
|
|
3553
|
-
const indent = Math.round(options);
|
|
3554
|
-
options = indent < 1 ? void 0 : indent > 8 ? { indent: 8 } : { indent };
|
|
3555
|
-
}
|
|
3556
|
-
if (value === void 0) {
|
|
3557
|
-
const { keepUndefined } = options ?? replacer ?? {};
|
|
3558
|
-
if (!keepUndefined)
|
|
3559
|
-
return void 0;
|
|
3560
|
-
}
|
|
3561
|
-
if (isDocument(value) && !_replacer)
|
|
3562
|
-
return value.toString(options);
|
|
3563
|
-
return new Document(value, _replacer, options).toString(options);
|
|
3564
|
-
}
|
|
3565
|
-
|
|
3566
3542
|
// ../../extension/src/sim/notSimulated.ts
|
|
3567
3543
|
var NotSimulated = class extends Error {
|
|
3568
3544
|
constructor(what) {
|
|
@@ -3617,17 +3593,27 @@ ${cn.comment}` : item.comment;
|
|
|
3617
3593
|
var dateOnly = (col) => col.type === "date" || col.behavior === "dateOnly";
|
|
3618
3594
|
var day = (d) => Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
|
|
3619
3595
|
var asDate = (s) => new Date(s.length === 10 ? `${s}T00:00:00Z` : /(Z|[+-]\d\d:?\d\d)$/.test(s) ? s : `${s}Z`);
|
|
3620
|
-
function
|
|
3596
|
+
function option(col, v) {
|
|
3597
|
+
if (typeof v === "number") return v;
|
|
3598
|
+
const text = String(v).trim();
|
|
3599
|
+
if (/^-?\d+$/.test(text)) return Number(text);
|
|
3600
|
+
const matches = col.options.filter((o) => o.label.toLowerCase() === text.toLowerCase());
|
|
3601
|
+
return matches.length > 0 ? matches[0].value : null;
|
|
3602
|
+
}
|
|
3603
|
+
function fromRecord(col, record, nameOf, tableOf) {
|
|
3621
3604
|
if (LOOKUP.has(col.type)) {
|
|
3622
3605
|
const id = record[`_${col.name}_value`];
|
|
3623
3606
|
if (typeof id !== "string") return null;
|
|
3624
|
-
const table = String(record[`_${col.name}_value@Microsoft.Dynamics.CRM.lookuplogicalname`] ?? col.target ?? "");
|
|
3607
|
+
const table = String(record[`_${col.name}_value@Microsoft.Dynamics.CRM.lookuplogicalname`] ?? tableOf?.(id) ?? col.target ?? "");
|
|
3625
3608
|
return [{ id, name: nameOf(table, id), entityType: table }];
|
|
3626
3609
|
}
|
|
3627
3610
|
const v = record[col.name];
|
|
3628
3611
|
if (v === void 0 || v === null || v === "") return null;
|
|
3629
|
-
if (
|
|
3630
|
-
if (col.type
|
|
3612
|
+
if (col.type === "choice") return option(col, v);
|
|
3613
|
+
if (NUMBER.has(col.type)) return Number(v);
|
|
3614
|
+
if (col.type === "choices") {
|
|
3615
|
+
return (Array.isArray(v) ? v : String(v).split(",").filter(Boolean)).map((o) => option(col, o)).filter((o) => o !== null);
|
|
3616
|
+
}
|
|
3631
3617
|
if (col.type === "yesNo") return v === true || v === "true" || v === 1;
|
|
3632
3618
|
if (DATE.has(col.type)) return asDate(String(v));
|
|
3633
3619
|
return String(v);
|
|
@@ -3709,8 +3695,8 @@ ${cn.comment}` : item.comment;
|
|
|
3709
3695
|
written(field2, value) {
|
|
3710
3696
|
const col = this.sim.state.columns.get(field2);
|
|
3711
3697
|
if (col.type === "choice" && typeof value === "number") {
|
|
3712
|
-
const
|
|
3713
|
-
return
|
|
3698
|
+
const option2 = col.options.find((o) => o.value === value);
|
|
3699
|
+
return option2 && col.options.filter((o) => o.label === option2.label).length === 1 ? option2.label : value;
|
|
3714
3700
|
}
|
|
3715
3701
|
if (Array.isArray(value) && value.length > 0 && typeof value[0] === "object") return value[0].id;
|
|
3716
3702
|
if (value instanceof Date) return display(col, value);
|
|
@@ -3743,8 +3729,28 @@ ${cn.comment}` : item.comment;
|
|
|
3743
3729
|
if (this.saved !== void 0) expect.saved = this.saved;
|
|
3744
3730
|
const acted = new Set(this.sim.log.entries.slice(this.startedAt).filter((e) => e.kind === "rule").map((e) => /^rule "([^"]+)" →/.exec(e.message)?.[1]).filter((n) => !!n));
|
|
3745
3731
|
const covers = [...acted].map((n) => `rule:${this.sim.pkg.table}/${(this.sim.pkg.rules.find((r) => r.name === n)?.file ?? n).replace(/\.rule\.yaml$/, "")}`);
|
|
3746
|
-
const
|
|
3747
|
-
|
|
3732
|
+
const records = this.usedRecords();
|
|
3733
|
+
const given = this.sim.pkg.open || records.length > 0 ? { given: { ...this.sim.pkg.open ? { open: this.sim.pkg.open } : {}, ...records.length > 0 ? { records: records.map(({ table, id, values }) => ({ table, id, values })) } : {} } } : {};
|
|
3734
|
+
const doc = new Document({ kind: "Test", form: this.formRef, ...covers.length > 0 ? { covers } : {}, ...given, cases: [{ name: caseName, steps: this.steps, expect }] });
|
|
3735
|
+
const source = records.find((r) => r.source)?.source;
|
|
3736
|
+
const givenNode = doc.get("given", true);
|
|
3737
|
+
if (source && isMap(givenNode)) {
|
|
3738
|
+
const pair = givenNode.items.find((p) => isScalar(p.key) && p.key.value === "records");
|
|
3739
|
+
if (pair) pair.key.commentBefore = ` ${source}: real data, check before committing`;
|
|
3740
|
+
}
|
|
3741
|
+
return doc.toString();
|
|
3742
|
+
}
|
|
3743
|
+
/** The loaded records the case uses: the one it opens, those its steps put in lookups, and those they point at, in loaded order. */
|
|
3744
|
+
usedRecords() {
|
|
3745
|
+
const all = this.sim.pkg.records;
|
|
3746
|
+
const ids = new Set(all.map((r) => r.id));
|
|
3747
|
+
const refs = (v) => typeof v === "string" && ids.has(v) ? [v] : Array.isArray(v) ? v.flatMap(refs) : [];
|
|
3748
|
+
const used = /* @__PURE__ */ new Set([...this.sim.pkg.open ? [this.sim.pkg.open] : [], ...this.steps.flatMap((s) => "set" in s ? Object.values(s.set).flatMap(refs) : [])]);
|
|
3749
|
+
for (let size2 = -1; size2 !== used.size; ) {
|
|
3750
|
+
size2 = used.size;
|
|
3751
|
+
for (const r of all) if (used.has(r.id)) for (const v of Object.values(r.values)) for (const id of refs(v)) used.add(id);
|
|
3752
|
+
}
|
|
3753
|
+
return all.filter((r) => used.has(r.id));
|
|
3748
3754
|
}
|
|
3749
3755
|
};
|
|
3750
3756
|
|
|
@@ -4169,7 +4175,7 @@ ${cn.comment}` : item.comment;
|
|
|
4169
4175
|
this.tables = tables;
|
|
4170
4176
|
this.newId = newId;
|
|
4171
4177
|
this.lookupColumns = lookupColumns;
|
|
4172
|
-
for (const r of records) this.put({ table: r.table, id: r.id, values: this.normalise(r.table, r.values) });
|
|
4178
|
+
for (const r of records) this.put({ table: r.table, id: r.id, values: this.normalise(r.table, r.values), ...r.source ? { source: r.source } : {} });
|
|
4173
4179
|
}
|
|
4174
4180
|
tables;
|
|
4175
4181
|
newId;
|
|
@@ -4194,6 +4200,15 @@ ${cn.comment}` : item.comment;
|
|
|
4194
4200
|
all(table) {
|
|
4195
4201
|
return [...this.records.get(table)?.values() ?? []];
|
|
4196
4202
|
}
|
|
4203
|
+
/** Every record, of every table, as records are written (lookups as col: id, no annotations) and with where it came from: to start again from. */
|
|
4204
|
+
written() {
|
|
4205
|
+
return [...this.records.values()].flatMap((m) => [...m.values()]).map((r) => ({
|
|
4206
|
+
table: r.table,
|
|
4207
|
+
id: r.id,
|
|
4208
|
+
...r.source ? { source: r.source } : {},
|
|
4209
|
+
values: Object.fromEntries(Object.entries(r.values).filter(([k]) => !k.includes("@")).map(([k, v]) => [/^_(.+)_value$/.exec(k)?.[1] ?? k, v]))
|
|
4210
|
+
}));
|
|
4211
|
+
}
|
|
4197
4212
|
get(table, id) {
|
|
4198
4213
|
return this.records.get(table)?.get(key(id));
|
|
4199
4214
|
}
|
|
@@ -4210,10 +4225,19 @@ ${cn.comment}` : item.comment;
|
|
|
4210
4225
|
delete(table, id) {
|
|
4211
4226
|
this.records.get(table)?.delete(key(id));
|
|
4212
4227
|
}
|
|
4228
|
+
/** A record's name: its primary name, or for a table the form doesn't know (pulled data), its first text value. */
|
|
4213
4229
|
nameOf(table, id) {
|
|
4214
4230
|
const name = this.tables[table]?.primaryName;
|
|
4215
4231
|
const r = this.get(table, id);
|
|
4216
|
-
|
|
4232
|
+
if (!r) return "";
|
|
4233
|
+
if (name) return String(r.values[name] ?? "");
|
|
4234
|
+
const first = Object.entries(r.values).find(([k, v]) => typeof v === "string" && !k.startsWith("_") && !k.includes("@"));
|
|
4235
|
+
return first ? String(first[1]) : "";
|
|
4236
|
+
}
|
|
4237
|
+
/** The table that holds a record with this id, if any. */
|
|
4238
|
+
tableOf(id) {
|
|
4239
|
+
for (const [table, records] of this.records) if (records.has(key(id))) return table;
|
|
4240
|
+
return void 0;
|
|
4217
4241
|
}
|
|
4218
4242
|
/** The record as the Web API returns it: its id under the primary id name, then the values ($select keeps those named). */
|
|
4219
4243
|
webApi(table, record, select) {
|
|
@@ -4629,7 +4653,7 @@ ${cn.comment}` : item.comment;
|
|
|
4629
4653
|
const record = this.store.get(this.pkg.table, id);
|
|
4630
4654
|
if (!record) throw new Error(`No ${this.pkg.table} record ${id} in the offline data.`);
|
|
4631
4655
|
for (const field2 of this.state.values.keys()) {
|
|
4632
|
-
this.state.values.set(field2, fromRecord(this.state.columns.get(field2), record.values, (t, i) => this.store.nameOf(t, i)));
|
|
4656
|
+
this.state.values.set(field2, fromRecord(this.state.columns.get(field2), record.values, (t, i) => this.store.nameOf(t, i), (i) => this.store.tableOf(i)));
|
|
4633
4657
|
}
|
|
4634
4658
|
this.state.formType = 2;
|
|
4635
4659
|
this.state.recordId = record.id;
|
|
@@ -4801,6 +4825,7 @@ ${cn.comment}` : item.comment;
|
|
|
4801
4825
|
button("reset", "Reset"),
|
|
4802
4826
|
button("copyTest", "Copy as test"),
|
|
4803
4827
|
button("loadSeed", "Load from seed"),
|
|
4828
|
+
button("loadPulled", "Load pulled data"),
|
|
4804
4829
|
h("span", { class: "al-sizes", role: "group", "aria-label": "Screen size" }, ...SIZES.map((s) => h("button", { type: "button", "data-al-size": s.size, "aria-pressed": String(s.size === size) }, s.label))),
|
|
4805
4830
|
h("span", { class: "al-themesource" }, typeof document !== "undefined" ? document.body.dataset.themeSource ?? "" : ""),
|
|
4806
4831
|
h("span", { class: "sim-tests", "data-tests-status": "" }, testsText),
|
|
@@ -4933,7 +4958,7 @@ ${cn.comment}` : item.comment;
|
|
|
4933
4958
|
drawLog();
|
|
4934
4959
|
};
|
|
4935
4960
|
const restart = (id) => {
|
|
4936
|
-
const records =
|
|
4961
|
+
const records = sim.store.written();
|
|
4937
4962
|
const next = startPage(root, { ...pkg, records, open: id }, host, post);
|
|
4938
4963
|
page.sim = next.sim;
|
|
4939
4964
|
page.recorder = next.recorder;
|
|
@@ -4954,6 +4979,7 @@ ${cn.comment}` : item.comment;
|
|
|
4954
4979
|
else if (action === "reset") restart(sim.state.recordId);
|
|
4955
4980
|
else if (action === "copyTest") post({ type: "copyTest", yaml: page.recorder.testYaml() });
|
|
4956
4981
|
else if (action === "loadSeed") post({ type: "loadSeed" });
|
|
4982
|
+
else if (action === "loadPulled") post({ type: "loadPulled" });
|
|
4957
4983
|
});
|
|
4958
4984
|
draw();
|
|
4959
4985
|
page.ready = sim.open().then(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dataverse-to-code/test",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Run DataverseToCode project tests (.test.yaml) with Playwright: the offline form simulator in Chromium, a form fixture, and yamlTests(). Works with Microsoft Dataverse; not a Microsoft product.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Simon Allport",
|