@tenonhq/dovetail-core 0.0.133 → 0.0.135
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/FileUtils.js +14 -0
- package/dist/createRecordCommand.js +18 -2
- package/dist/deleteRecordCommand.js +45 -20
- package/dist/fingerprint.js +44 -5
- package/dist/layoutElements.js +386 -0
- package/dist/reconcileCommand.js +6 -0
- package/dist/recordFolder.js +86 -0
- package/dist/snClient.js +52 -6
- package/dist/tests/createRecordLocalPath.test.js +145 -0
- package/dist/tests/deleteRecordLocalCleanup.test.js +153 -24
- package/dist/tests/fileContextSkipReason.test.js +41 -0
- package/dist/tests/fingerprint.test.js +37 -0
- package/dist/tests/layoutElements.test.js +259 -0
- package/dist/tests/layoutElementsWriteGuards.test.js +113 -0
- package/dist/tests/pushFingerprintedField.test.js +64 -0
- package/dist/tests/recordFolder.test.js +57 -0
- package/dist/tests/snClient.fingerprint.test.js +20 -0
- package/dist/tests/snClient.layoutElements.test.js +133 -0
- package/package.json +3 -3
- package/release-manifest.json +340 -347
- package/skills/dove-delete-record.md +2 -2
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Layout elements (layoutElements.ts): the child rows of a list layout, a form
|
|
3
|
+
// section and a form are mirrored as one ordered, line-per-item text file in the
|
|
4
|
+
// parent layout's folder. Covers config validation, formatting and ordering, the
|
|
5
|
+
// manifest and bulkDownload rewrites, the Table API reads, and the path test
|
|
6
|
+
// push uses to refuse these files.
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const layoutElements_1 = require("../layoutElements");
|
|
9
|
+
const LIST_A = "a".repeat(32);
|
|
10
|
+
const LIST_B = "b".repeat(32);
|
|
11
|
+
const SECTION = "c".repeat(32);
|
|
12
|
+
const FORM = "d".repeat(32);
|
|
13
|
+
const MAIN_SECTION = "e".repeat(32);
|
|
14
|
+
const DETAILS_SECTION = "f".repeat(32);
|
|
15
|
+
function id(n) {
|
|
16
|
+
const s = String(n);
|
|
17
|
+
return "0".repeat(32 - s.length) + s;
|
|
18
|
+
}
|
|
19
|
+
// A reader that answers from in-memory child rows, honoring the IN list, the
|
|
20
|
+
// page size and the offset, and records every call.
|
|
21
|
+
function fakeReader(rowsByTable, parentField) {
|
|
22
|
+
const calls = [];
|
|
23
|
+
const read = async function (table, query, fields, limit, offset) {
|
|
24
|
+
calls.push({ table: table, query: query, fields: fields, limit: limit, offset: offset });
|
|
25
|
+
const m = /^([a-z_]+)IN([0-9a-f,]+)\^ORDERBYsys_id$/.exec(query);
|
|
26
|
+
if (!m)
|
|
27
|
+
throw new Error("unexpected query " + query);
|
|
28
|
+
const ids = m[2].split(",");
|
|
29
|
+
const all = (rowsByTable[table] || [])
|
|
30
|
+
.filter(function (r) { return ids.indexOf(String(r[parentField[table]])) !== -1; })
|
|
31
|
+
.slice()
|
|
32
|
+
.sort(function (x, y) { return String(x.sys_id) < String(y.sys_id) ? -1 : 1; });
|
|
33
|
+
return all.slice(offset, offset + limit);
|
|
34
|
+
};
|
|
35
|
+
return { read: read, calls: calls };
|
|
36
|
+
}
|
|
37
|
+
const PARENT_FIELD = {
|
|
38
|
+
sys_ui_list_element: "list_id",
|
|
39
|
+
sys_ui_element: "sys_ui_section",
|
|
40
|
+
sys_ui_form_section: "sys_ui_form",
|
|
41
|
+
};
|
|
42
|
+
describe("layoutElementTablesFor", function () {
|
|
43
|
+
it("is off by default: no option, no tables", function () {
|
|
44
|
+
expect((0, layoutElements_1.layoutElementTablesFor)(undefined)).toEqual([]);
|
|
45
|
+
expect((0, layoutElements_1.layoutElementTablesFor)({})).toEqual([]);
|
|
46
|
+
expect((0, layoutElements_1.layoutElementTablesFor)({ sys_ui_list: { query: "sys_userISEMPTY" } })).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
it("returns the layout tables that set layoutElements: true", function () {
|
|
49
|
+
const opts = {
|
|
50
|
+
sys_ui_list: { layoutElements: true },
|
|
51
|
+
sys_ui_section: { layoutElements: true },
|
|
52
|
+
sys_ui_form: { layoutElements: true },
|
|
53
|
+
};
|
|
54
|
+
expect((0, layoutElements_1.layoutElementTablesFor)(opts).sort()).toEqual(["sys_ui_form", "sys_ui_list", "sys_ui_section"]);
|
|
55
|
+
});
|
|
56
|
+
it("ignores and reports a value that is not true, or a table that has no layout elements", function () {
|
|
57
|
+
const warnings = [];
|
|
58
|
+
const opts = {
|
|
59
|
+
sys_ui_list: { layoutElements: "yes" },
|
|
60
|
+
sys_ui_section: { layoutElements: false },
|
|
61
|
+
sys_script: { layoutElements: true },
|
|
62
|
+
};
|
|
63
|
+
expect((0, layoutElements_1.layoutElementTablesFor)(opts, function (m) { warnings.push(m); })).toEqual([]);
|
|
64
|
+
expect(warnings.length).toBe(2);
|
|
65
|
+
expect(warnings.join("\n")).toContain("sys_ui_list");
|
|
66
|
+
expect(warnings.join("\n")).toContain("sys_script");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe("formatLayoutElements", function () {
|
|
70
|
+
it("writes a list's columns in position order, one per line, with aggregates", function () {
|
|
71
|
+
const rows = [
|
|
72
|
+
{ sys_id: id(3), list_id: LIST_A, element: "state", position: "2", sum: "false", average_value: "false", min_value: "false", max_value: "false" },
|
|
73
|
+
{ sys_id: id(1), list_id: LIST_A, element: "number", position: "0", sum: "false", average_value: "false", min_value: "false", max_value: "false" },
|
|
74
|
+
{ sys_id: id(2), list_id: LIST_A, element: "assigned_to.name", position: "1", sum: "false", average_value: "false", min_value: "false", max_value: "false" },
|
|
75
|
+
{ sys_id: id(4), list_id: LIST_A, element: "amount", position: "10", sum: "true", average_value: "true", min_value: "false", max_value: "true" },
|
|
76
|
+
];
|
|
77
|
+
expect((0, layoutElements_1.formatLayoutElements)("sys_ui_list", rows)).toBe("number\nassigned_to.name\nstate\namount [sum, average, max]\n");
|
|
78
|
+
});
|
|
79
|
+
it("writes a section's fields in position order with the element type when it adds something", function () {
|
|
80
|
+
const rows = [
|
|
81
|
+
{ sys_id: id(5), sys_ui_section: SECTION, element: ".end_split", type: ".end_split", position: "4" },
|
|
82
|
+
{ sys_id: id(1), sys_ui_section: SECTION, element: ".begin_split", type: ".begin_split", position: "0" },
|
|
83
|
+
{ sys_id: id(2), sys_ui_section: SECTION, element: "name", type: "", position: "1" },
|
|
84
|
+
{ sys_id: id(3), sys_ui_section: SECTION, element: ".split", type: ".split", position: "2" },
|
|
85
|
+
{ sys_id: id(4), sys_ui_section: SECTION, element: "activity.xml", type: "formatter", position: "3" },
|
|
86
|
+
{ sys_id: id(6), sys_ui_section: SECTION, element: "x_cadso_work_task.project", type: "list", position: "5" },
|
|
87
|
+
];
|
|
88
|
+
expect((0, layoutElements_1.formatLayoutElements)("sys_ui_section", rows)).toBe(".begin_split\nname\n.split\nactivity.xml [formatter]\n.end_split\nx_cadso_work_task.project [list]\n");
|
|
89
|
+
});
|
|
90
|
+
it("writes a form's sections in position order by caption", function () {
|
|
91
|
+
const rows = [
|
|
92
|
+
{ sys_id: id(2), sys_ui_form: FORM, position: "1", sys_ui_section: DETAILS_SECTION, "sys_ui_section.sys_id": DETAILS_SECTION, "sys_ui_section.caption": "Details" },
|
|
93
|
+
{ sys_id: id(1), sys_ui_form: FORM, position: "0", sys_ui_section: MAIN_SECTION, "sys_ui_section.sys_id": MAIN_SECTION, "sys_ui_section.caption": "" },
|
|
94
|
+
{ sys_id: id(3), sys_ui_form: FORM, position: "2", sys_ui_section: id(99), "sys_ui_section.sys_id": "", "sys_ui_section.caption": "" },
|
|
95
|
+
];
|
|
96
|
+
expect((0, layoutElements_1.formatLayoutElements)("sys_ui_form", rows)).toBe("(no caption)\nDetails\n(missing section " + id(99) + ")\n");
|
|
97
|
+
});
|
|
98
|
+
it("orders equal positions by the line, then by the row id, so the file is stable across pulls", function () {
|
|
99
|
+
const rows = [
|
|
100
|
+
{ sys_id: id(9), list_id: LIST_A, element: "b", position: "1" },
|
|
101
|
+
{ sys_id: id(8), list_id: LIST_A, element: "a", position: "1" },
|
|
102
|
+
{ sys_id: id(7), list_id: LIST_A, element: "a", position: "1" },
|
|
103
|
+
];
|
|
104
|
+
const once = (0, layoutElements_1.formatLayoutElements)("sys_ui_list", rows);
|
|
105
|
+
expect(once).toBe("a\na\nb\n");
|
|
106
|
+
expect((0, layoutElements_1.formatLayoutElements)("sys_ui_list", rows.slice().reverse())).toBe(once);
|
|
107
|
+
});
|
|
108
|
+
it("writes an empty list as an empty file", function () {
|
|
109
|
+
expect((0, layoutElements_1.formatLayoutElements)("sys_ui_list", [])).toBe("");
|
|
110
|
+
});
|
|
111
|
+
it("reads reference values whether or not the reference link is excluded", function () {
|
|
112
|
+
const rows = [
|
|
113
|
+
{ sys_id: id(1), sys_ui_form: { value: FORM, link: "x" }, position: "0", sys_ui_section: { value: MAIN_SECTION, link: "y" }, "sys_ui_section.sys_id": MAIN_SECTION, "sys_ui_section.caption": "Main" },
|
|
114
|
+
];
|
|
115
|
+
expect((0, layoutElements_1.formatLayoutElements)("sys_ui_form", rows)).toBe("Main\n");
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
describe("addLayoutElementFiles", function () {
|
|
119
|
+
function manifestTables() {
|
|
120
|
+
return {
|
|
121
|
+
sys_ui_list: {
|
|
122
|
+
records: {
|
|
123
|
+
"x_cadso_work_task.Default view": { name: "x_cadso_work_task.Default view", sys_id: LIST_A, files: [{ name: "name", type: "txt" }] },
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
sys_script: {
|
|
127
|
+
records: { "My rule": { name: "My rule", sys_id: id(1), files: [{ name: "script", type: "js" }] } },
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
it("adds the columns file to every record of an enabled table, and nothing else", function () {
|
|
132
|
+
const tables = manifestTables();
|
|
133
|
+
(0, layoutElements_1.addLayoutElementFiles)(tables, ["sys_ui_list"]);
|
|
134
|
+
expect(tables.sys_ui_list.records["x_cadso_work_task.Default view"].files).toEqual([
|
|
135
|
+
{ name: "name", type: "txt" },
|
|
136
|
+
{ name: "columns", type: "txt" },
|
|
137
|
+
]);
|
|
138
|
+
expect(tables.sys_script.records["My rule"].files).toEqual([{ name: "script", type: "js" }]);
|
|
139
|
+
});
|
|
140
|
+
it("is a no-op when the option is off, and idempotent when on", function () {
|
|
141
|
+
const off = manifestTables();
|
|
142
|
+
(0, layoutElements_1.addLayoutElementFiles)(off, []);
|
|
143
|
+
expect(off).toEqual(manifestTables());
|
|
144
|
+
const on = manifestTables();
|
|
145
|
+
(0, layoutElements_1.addLayoutElementFiles)(on, ["sys_ui_list"]);
|
|
146
|
+
(0, layoutElements_1.addLayoutElementFiles)(on, ["sys_ui_list"]);
|
|
147
|
+
expect(on.sys_ui_list.records["x_cadso_work_task.Default view"].files.length).toBe(2);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
describe("splitLayoutElementRequests", function () {
|
|
151
|
+
it("takes the derived files out of the request and remembers which records asked for them", function () {
|
|
152
|
+
const missing = {
|
|
153
|
+
sys_ui_list: {
|
|
154
|
+
[LIST_A]: [{ name: "name", type: "txt" }, { name: "columns", type: "txt" }],
|
|
155
|
+
[LIST_B]: [{ name: "columns", type: "txt" }],
|
|
156
|
+
},
|
|
157
|
+
sys_script: { [id(1)]: [{ name: "script", type: "js" }] },
|
|
158
|
+
};
|
|
159
|
+
const split = (0, layoutElements_1.splitLayoutElementRequests)(missing);
|
|
160
|
+
expect(split.request).toEqual({
|
|
161
|
+
sys_ui_list: { [LIST_A]: [{ name: "name", type: "txt" }], [LIST_B]: [] },
|
|
162
|
+
sys_script: { [id(1)]: [{ name: "script", type: "js" }] },
|
|
163
|
+
});
|
|
164
|
+
expect(split.wanted).toEqual({ sys_ui_list: [LIST_A, LIST_B] });
|
|
165
|
+
// The caller's map is not mutated.
|
|
166
|
+
expect(missing.sys_ui_list[LIST_A].length).toBe(2);
|
|
167
|
+
});
|
|
168
|
+
it("leaves a same-named field of another table alone", function () {
|
|
169
|
+
const missing = { x_custom: { [id(1)]: [{ name: "columns", type: "txt" }] } };
|
|
170
|
+
const split = (0, layoutElements_1.splitLayoutElementRequests)(missing);
|
|
171
|
+
expect(split.request).toEqual(missing);
|
|
172
|
+
expect(split.wanted).toEqual({});
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
describe("readLayoutElements", function () {
|
|
176
|
+
it("reads child rows for every parent, pages through them, and writes empty for a parent with none", async function () {
|
|
177
|
+
const rows = [];
|
|
178
|
+
for (let i = 0; i < 5; i++) {
|
|
179
|
+
rows.push({ sys_id: id(i + 1), list_id: LIST_A, element: "f" + i, position: String(4 - i) });
|
|
180
|
+
}
|
|
181
|
+
const fake = fakeReader({ sys_ui_list_element: rows }, PARENT_FIELD);
|
|
182
|
+
const out = await (0, layoutElements_1.readLayoutElements)(fake.read, "sys_ui_list", [LIST_A, LIST_B], { pageSize: 2, chunkSize: 100 });
|
|
183
|
+
expect(out[LIST_A]).toBe("f4\nf3\nf2\nf1\nf0\n");
|
|
184
|
+
expect(out[LIST_B]).toBe("");
|
|
185
|
+
expect(fake.calls.map(function (c) { return c.offset; })).toEqual([0, 2, 4]);
|
|
186
|
+
expect(fake.calls[0].table).toBe("sys_ui_list_element");
|
|
187
|
+
expect(fake.calls[0].query).toBe("list_idIN" + LIST_A + "," + LIST_B + "^ORDERBYsys_id");
|
|
188
|
+
});
|
|
189
|
+
it("splits a long parent list into several queries", async function () {
|
|
190
|
+
const parents = [];
|
|
191
|
+
for (let i = 0; i < 5; i++)
|
|
192
|
+
parents.push(id(100 + i));
|
|
193
|
+
const fake = fakeReader({ sys_ui_element: [] }, PARENT_FIELD);
|
|
194
|
+
await (0, layoutElements_1.readLayoutElements)(fake.read, "sys_ui_section", parents, { pageSize: 1000, chunkSize: 2 });
|
|
195
|
+
expect(fake.calls.length).toBe(3);
|
|
196
|
+
});
|
|
197
|
+
it("refuses a parent id that is not a record id, before any query runs", async function () {
|
|
198
|
+
const fake = fakeReader({}, PARENT_FIELD);
|
|
199
|
+
await expect((0, layoutElements_1.readLayoutElements)(fake.read, "sys_ui_list", [LIST_A, "x^NQsys_id!=1"], { pageSize: 1000, chunkSize: 100 })).rejects.toThrow(/record id/);
|
|
200
|
+
expect(fake.calls.length).toBe(0);
|
|
201
|
+
});
|
|
202
|
+
it("fails instead of writing an empty file when a read fails", async function () {
|
|
203
|
+
const read = async function () { throw new Error("HTTP 403"); };
|
|
204
|
+
await expect((0, layoutElements_1.readLayoutElements)(read, "sys_ui_list", [LIST_A], { pageSize: 1000, chunkSize: 100 })).rejects.toThrow(/403/);
|
|
205
|
+
});
|
|
206
|
+
it("ignores a returned row whose parent was not asked for", async function () {
|
|
207
|
+
const read = async function () {
|
|
208
|
+
return [{ sys_id: id(1), list_id: LIST_B, element: "stray", position: "0" }];
|
|
209
|
+
};
|
|
210
|
+
const out = await (0, layoutElements_1.readLayoutElements)(read, "sys_ui_list", [LIST_A], { pageSize: 1000, chunkSize: 100 });
|
|
211
|
+
expect(out).toEqual({ [LIST_A]: "" });
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
describe("fillLayoutElementContent", function () {
|
|
215
|
+
it("keys the content by record id, so two layouts with colliding names get their own columns", async function () {
|
|
216
|
+
const tables = {
|
|
217
|
+
sys_ui_list: {
|
|
218
|
+
records: {
|
|
219
|
+
"csm_consumer.Default view (aaaaaaaa)": { name: "csm_consumer.Default view (aaaaaaaa)", sys_id: LIST_A, files: [{ name: "name", type: "txt", content: "csm_consumer" }] },
|
|
220
|
+
"csm_consumer.Default view (bbbbbbbb)": { name: "csm_consumer.Default view (bbbbbbbb)", sys_id: LIST_B, files: [{ name: "name", type: "txt", content: "csm_consumer" }] },
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
const fake = fakeReader({
|
|
225
|
+
sys_ui_list_element: [
|
|
226
|
+
{ sys_id: id(1), list_id: LIST_A, element: "first_name", position: "0" },
|
|
227
|
+
{ sys_id: id(2), list_id: LIST_B, element: "email", position: "0" },
|
|
228
|
+
{ sys_id: id(3), list_id: LIST_B, element: "phone", position: "1" },
|
|
229
|
+
],
|
|
230
|
+
}, PARENT_FIELD);
|
|
231
|
+
await (0, layoutElements_1.fillLayoutElementContent)(tables, { sys_ui_list: [LIST_A, LIST_B] }, fake.read);
|
|
232
|
+
const a = tables.sys_ui_list.records["csm_consumer.Default view (aaaaaaaa)"].files;
|
|
233
|
+
const b = tables.sys_ui_list.records["csm_consumer.Default view (bbbbbbbb)"].files;
|
|
234
|
+
expect(a[a.length - 1]).toEqual({ name: "columns", type: "txt", content: "first_name\n" });
|
|
235
|
+
expect(b[b.length - 1]).toEqual({ name: "columns", type: "txt", content: "email\nphone\n" });
|
|
236
|
+
});
|
|
237
|
+
it("does nothing when no record asked for layout elements", async function () {
|
|
238
|
+
const fake = fakeReader({}, PARENT_FIELD);
|
|
239
|
+
const tables = { sys_ui_list: { records: {} } };
|
|
240
|
+
await (0, layoutElements_1.fillLayoutElementContent)(tables, {}, fake.read);
|
|
241
|
+
expect(fake.calls.length).toBe(0);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
describe("isLayoutElementsFile / isLayoutElementsFilePath", function () {
|
|
245
|
+
it("recognizes the three derived files by table and name", function () {
|
|
246
|
+
expect((0, layoutElements_1.isLayoutElementsFile)("sys_ui_list", "columns", "txt")).toBe(true);
|
|
247
|
+
expect((0, layoutElements_1.isLayoutElementsFile)("sys_ui_section", "fields", "txt")).toBe(true);
|
|
248
|
+
expect((0, layoutElements_1.isLayoutElementsFile)("sys_ui_form", "sections", "txt")).toBe(true);
|
|
249
|
+
expect((0, layoutElements_1.isLayoutElementsFile)("sys_ui_list", "name", "txt")).toBe(false);
|
|
250
|
+
expect((0, layoutElements_1.isLayoutElementsFile)("x_custom", "columns", "txt")).toBe(false);
|
|
251
|
+
});
|
|
252
|
+
it("recognizes a derived file from its path on disk", function () {
|
|
253
|
+
expect((0, layoutElements_1.isLayoutElementsFilePath)("/repo/src/Work/sys_ui_list/x_cadso_work_task.Default view/columns.txt")).toBe(true);
|
|
254
|
+
expect((0, layoutElements_1.isLayoutElementsFilePath)("/repo/src/Work/sys_ui_section/x_cadso_work_task.Default view.Details/fields.txt")).toBe(true);
|
|
255
|
+
expect((0, layoutElements_1.isLayoutElementsFilePath)("/repo/src/Work/sys_ui_form/x_cadso_work_task.Default view/sections.txt")).toBe(true);
|
|
256
|
+
expect((0, layoutElements_1.isLayoutElementsFilePath)("/repo/src/Work/sys_ui_list/x_cadso_work_task.Default view/name.txt")).toBe(false);
|
|
257
|
+
expect((0, layoutElements_1.isLayoutElementsFilePath)("/repo/src/Work/x_custom/rec/columns.txt")).toBe(false);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// A layout elements file (columns.txt, fields.txt, sections.txt) is read from the
|
|
3
|
+
// child rows of a layout; it is not a field of the layout record. Push must
|
|
4
|
+
// refuse it even though the manifest lists it, and a reconcile create must not
|
|
5
|
+
// send it as a field.
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
jest.mock("../Logger", function () {
|
|
11
|
+
return {
|
|
12
|
+
logger: {
|
|
13
|
+
info: jest.fn(),
|
|
14
|
+
debug: jest.fn(),
|
|
15
|
+
warn: jest.fn(),
|
|
16
|
+
error: jest.fn(),
|
|
17
|
+
success: jest.fn(),
|
|
18
|
+
getLogLevel: function () { return "debug"; },
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
jest.mock("../FileLogger", function () {
|
|
23
|
+
return { fileLogger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn(), log: jest.fn() } };
|
|
24
|
+
});
|
|
25
|
+
var mockManifest = null;
|
|
26
|
+
var mockSourcePath = "";
|
|
27
|
+
jest.mock("../config", function () {
|
|
28
|
+
return {
|
|
29
|
+
getManifest: function () { return mockManifest; },
|
|
30
|
+
isMultiScopeManifest: function () { return false; },
|
|
31
|
+
resolveScopeFromPath: function () { return undefined; },
|
|
32
|
+
resolveManifestForScope: function () { return undefined; },
|
|
33
|
+
getSourcePathForScope: function () { return mockSourcePath; },
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
var mockPost = jest.fn();
|
|
37
|
+
jest.mock("../snClient", function () {
|
|
38
|
+
var actual = jest.requireActual("../snClient");
|
|
39
|
+
var client = actual.snClient("https://x.service-now.com/", "u", "p");
|
|
40
|
+
client.client.post = mockPost;
|
|
41
|
+
return Object.assign({}, actual, {
|
|
42
|
+
defaultClient: function () {
|
|
43
|
+
return client;
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
const fs_1 = __importDefault(require("fs"));
|
|
48
|
+
const os_1 = __importDefault(require("os"));
|
|
49
|
+
const path_1 = __importDefault(require("path"));
|
|
50
|
+
const FileUtils_1 = require("../FileUtils");
|
|
51
|
+
const reconcileCommand_1 = require("../reconcileCommand");
|
|
52
|
+
const LIST = "a".repeat(32);
|
|
53
|
+
describe("push refuses layout elements files", function () {
|
|
54
|
+
beforeEach(function () {
|
|
55
|
+
mockManifest = {
|
|
56
|
+
scope: "x_cadso_work",
|
|
57
|
+
tables: {
|
|
58
|
+
sys_ui_list: {
|
|
59
|
+
records: {
|
|
60
|
+
"x_cadso_work_task.Default view": {
|
|
61
|
+
name: "x_cadso_work_task.Default view",
|
|
62
|
+
sys_id: LIST,
|
|
63
|
+
files: [{ name: "name", type: "txt" }, { name: "columns", type: "txt" }],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
it("skips columns.txt with a named reason although the manifest lists it", function () {
|
|
71
|
+
const result = (0, FileUtils_1.getFileContextWithSkipReason)("/project/src/sys_ui_list/x_cadso_work_task.Default view/columns.txt");
|
|
72
|
+
expect(result.context).toBeUndefined();
|
|
73
|
+
expect(result.skipReason).toBe("layout elements, read-only");
|
|
74
|
+
});
|
|
75
|
+
it("still resolves the layout's own field file", function () {
|
|
76
|
+
const result = (0, FileUtils_1.getFileContextWithSkipReason)("/project/src/sys_ui_list/x_cadso_work_task.Default view/name.txt");
|
|
77
|
+
expect(result.skipReason).toBeUndefined();
|
|
78
|
+
expect(result.context && result.context.targetField).toBe("name");
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe("reconcile create leaves layout elements out of the record fields", function () {
|
|
82
|
+
let tmp = "";
|
|
83
|
+
beforeEach(function () {
|
|
84
|
+
mockPost.mockReset();
|
|
85
|
+
mockPost.mockResolvedValue({ status: 201, data: { result: { sys_id: LIST } } });
|
|
86
|
+
tmp = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dove-layout-create-"));
|
|
87
|
+
mockSourcePath = tmp;
|
|
88
|
+
const recordDir = path_1.default.join(tmp, "sys_ui_list", "x_cadso_work_task.Default view");
|
|
89
|
+
fs_1.default.mkdirSync(recordDir, { recursive: true });
|
|
90
|
+
fs_1.default.writeFileSync(path_1.default.join(recordDir, "name.txt"), "x_cadso_work_task");
|
|
91
|
+
fs_1.default.writeFileSync(path_1.default.join(recordDir, "columns.txt"), "number\nstate\n");
|
|
92
|
+
fs_1.default.writeFileSync(path_1.default.join(recordDir, "metaData.json"), JSON.stringify({ name: { value: "x_cadso_work_task" } }));
|
|
93
|
+
});
|
|
94
|
+
afterEach(function () {
|
|
95
|
+
fs_1.default.rmSync(tmp, { recursive: true, force: true });
|
|
96
|
+
});
|
|
97
|
+
it("posts the record without a columns field", async function () {
|
|
98
|
+
const change = {
|
|
99
|
+
kind: "create",
|
|
100
|
+
table: "sys_ui_list",
|
|
101
|
+
scope: "x_cadso_work",
|
|
102
|
+
sys_id: LIST,
|
|
103
|
+
name: "x_cadso_work_task.Default view",
|
|
104
|
+
fieldDeltas: [],
|
|
105
|
+
};
|
|
106
|
+
await (0, reconcileCommand_1.applyCreates)("x_cadso_work", [change], "us1");
|
|
107
|
+
expect(mockPost).toHaveBeenCalled();
|
|
108
|
+
const body = JSON.stringify(mockPost.mock.calls[0][1]);
|
|
109
|
+
expect(body).toContain("x_cadso_work_task");
|
|
110
|
+
expect(body).not.toContain("columns");
|
|
111
|
+
expect(body).not.toContain("number\\nstate");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// A field mirrored as a fingerprint has no content file on disk. A content file
|
|
3
|
+
// for it (script.js left from before `fingerprint` was set; refresh never
|
|
4
|
+
// deletes) used to match the manifest field by name and be pushed over the live
|
|
5
|
+
// bundle. Push now skips it with a warning, through the real getAppFileList and
|
|
6
|
+
// getFileContextWithSkipReason.
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
jest.mock("../Logger", function () {
|
|
9
|
+
return {
|
|
10
|
+
logger: {
|
|
11
|
+
info: jest.fn(),
|
|
12
|
+
debug: jest.fn(),
|
|
13
|
+
warn: jest.fn(),
|
|
14
|
+
error: jest.fn(),
|
|
15
|
+
success: jest.fn(),
|
|
16
|
+
getLogLevel: function () { return "info"; },
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
jest.mock("../FileLogger", function () {
|
|
21
|
+
return { fileLogger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn(), log: jest.fn() } };
|
|
22
|
+
});
|
|
23
|
+
var mockManifest = null;
|
|
24
|
+
jest.mock("../config", function () {
|
|
25
|
+
return {
|
|
26
|
+
getManifest: function () { return mockManifest; },
|
|
27
|
+
isMultiScopeManifest: function () { return false; },
|
|
28
|
+
resolveScopeFromPath: function () { return undefined; },
|
|
29
|
+
resolveManifestForScope: function () { return undefined; },
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
const Logger_1 = require("../Logger");
|
|
33
|
+
const appUtils_1 = require("../appUtils");
|
|
34
|
+
describe("push skips a content file of a fingerprinted field", function () {
|
|
35
|
+
beforeEach(function () {
|
|
36
|
+
Logger_1.logger.warn.mockClear();
|
|
37
|
+
mockManifest = {
|
|
38
|
+
scope: "x_cadso_ui_form",
|
|
39
|
+
tables: {
|
|
40
|
+
sys_ux_lib_source_script: {
|
|
41
|
+
records: {
|
|
42
|
+
Bundle: {
|
|
43
|
+
name: "Bundle",
|
|
44
|
+
sys_id: "f9cd",
|
|
45
|
+
files: [{ name: "script", type: "sha256" }, { name: "source_map", type: "js" }],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
it("warns and pushes nothing for script.js beside a fingerprinted script field", async function () {
|
|
53
|
+
var stale = "/project/src/sys_ux_lib_source_script/Bundle/script.js";
|
|
54
|
+
var records = await (0, appUtils_1.getAppFileList)([stale]);
|
|
55
|
+
expect(records).toEqual([]);
|
|
56
|
+
expect(Logger_1.logger.warn).toHaveBeenCalledWith("Skipped: " + stale + " (fingerprinted field, read-only)");
|
|
57
|
+
});
|
|
58
|
+
it("keeps the record's other fields in the push", async function () {
|
|
59
|
+
var records = await (0, appUtils_1.getAppFileList)(["/project/src/sys_ux_lib_source_script/Bundle/source_map.js"]);
|
|
60
|
+
expect(records.length).toBe(1);
|
|
61
|
+
expect(Object.keys(records[0].fields)).toEqual(["source_map"]);
|
|
62
|
+
expect(Logger_1.logger.warn).not.toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// recordFolder: the manifest key (= folder) of a record by sys_id, and the
|
|
3
|
+
// guard that keeps a destructive caller inside <scope dir>/<table>.
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const recordFolder_1 = require("../recordFolder");
|
|
10
|
+
var SYS_A = "aaaaaaaa1111111111111111111111a1";
|
|
11
|
+
var SYS_B = "bbbbbbbb2222222222222222222222b2";
|
|
12
|
+
function manifestWith(records) {
|
|
13
|
+
var entries = {};
|
|
14
|
+
var keys = Object.keys(records);
|
|
15
|
+
for (var i = 0; i < keys.length; i++) {
|
|
16
|
+
entries[keys[i]] = { name: keys[i], sys_id: records[keys[i]], files: [] };
|
|
17
|
+
}
|
|
18
|
+
return { scope: "x_test", tables: { sys_script_include: { records: entries } } };
|
|
19
|
+
}
|
|
20
|
+
describe("recordFoldersBySysId", function () {
|
|
21
|
+
it("returns the manifest key, not the display name, of the record", function () {
|
|
22
|
+
var man = manifestWith({ "Foo (aaaaaaaa)": SYS_A, "Foo (bbbbbbbb)": SYS_B });
|
|
23
|
+
expect((0, recordFolder_1.recordFoldersBySysId)(man, "sys_script_include", SYS_B)).toEqual(["Foo (bbbbbbbb)"]);
|
|
24
|
+
});
|
|
25
|
+
it("returns nothing for a sys_id, table or manifest it does not have", function () {
|
|
26
|
+
var man = manifestWith({ Foo: SYS_A });
|
|
27
|
+
expect((0, recordFolder_1.recordFoldersBySysId)(man, "sys_script_include", SYS_B)).toEqual([]);
|
|
28
|
+
expect((0, recordFolder_1.recordFoldersBySysId)(man, "sys_script", SYS_A)).toEqual([]);
|
|
29
|
+
expect((0, recordFolder_1.recordFoldersBySysId)(man, "constructor", SYS_A)).toEqual([]);
|
|
30
|
+
expect((0, recordFolder_1.recordFoldersBySysId)(undefined, "sys_script_include", SYS_A)).toEqual([]);
|
|
31
|
+
expect((0, recordFolder_1.recordFoldersBySysId)(man, "sys_script_include", "")).toEqual([]);
|
|
32
|
+
});
|
|
33
|
+
it("returns every key when a corrupt manifest lists the sys_id twice", function () {
|
|
34
|
+
var man = manifestWith({ Foo: SYS_A, Bar: SYS_A });
|
|
35
|
+
expect((0, recordFolder_1.recordFoldersBySysId)(man, "sys_script_include", SYS_A).sort()).toEqual(["Bar", "Foo"]);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe("recordDirFor", function () {
|
|
39
|
+
var scopeDir = path_1.default.resolve("/project/src/UIComponents/x_test");
|
|
40
|
+
it("returns <scope dir>/<table>/<folder> for a record folder", function () {
|
|
41
|
+
expect((0, recordFolder_1.recordDirFor)(scopeDir, "sys_script_include", "Foo (aaaaaaaa)")).toBe(path_1.default.join(scopeDir, "sys_script_include", "Foo (aaaaaaaa)"));
|
|
42
|
+
expect((0, recordFolder_1.recordDirFor)(scopeDir, "sys_script_include", "..Foo")).toBe(path_1.default.join(scopeDir, "sys_script_include", "..Foo"));
|
|
43
|
+
});
|
|
44
|
+
it("refuses a folder that is not a direct child of <scope dir>/<table>", function () {
|
|
45
|
+
expect((0, recordFolder_1.recordDirFor)(scopeDir, "sys_script_include", "..")).toBeUndefined();
|
|
46
|
+
expect((0, recordFolder_1.recordDirFor)(scopeDir, "sys_script_include", ".")).toBeUndefined();
|
|
47
|
+
expect((0, recordFolder_1.recordDirFor)(scopeDir, "sys_script_include", "")).toBeUndefined();
|
|
48
|
+
expect((0, recordFolder_1.recordDirFor)(scopeDir, "sys_script_include", "a/b")).toBeUndefined();
|
|
49
|
+
expect((0, recordFolder_1.recordDirFor)(scopeDir, "sys_script_include", "../../x_other")).toBeUndefined();
|
|
50
|
+
expect((0, recordFolder_1.recordDirFor)(scopeDir, "sys_script_include", path_1.default.resolve("/etc"))).toBeUndefined();
|
|
51
|
+
});
|
|
52
|
+
it("refuses a table that is not a direct child of the scope folder", function () {
|
|
53
|
+
expect((0, recordFolder_1.recordDirFor)(scopeDir, "..", "x_other")).toBeUndefined();
|
|
54
|
+
expect((0, recordFolder_1.recordDirFor)(scopeDir, "", "Foo")).toBeUndefined();
|
|
55
|
+
expect((0, recordFolder_1.recordDirFor)(scopeDir, "a/b", "Foo")).toBeUndefined();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -18,6 +18,7 @@ jest.mock("../Logger", function () {
|
|
|
18
18
|
jest.mock("../FileLogger", function () {
|
|
19
19
|
return { fileLogger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() } };
|
|
20
20
|
});
|
|
21
|
+
const Logger_1 = require("../Logger");
|
|
21
22
|
const snClient_1 = require("../snClient");
|
|
22
23
|
const fingerprint_1 = require("../fingerprint");
|
|
23
24
|
const BUNDLE = "!function(){}();";
|
|
@@ -55,6 +56,25 @@ describe("snClient fingerprint hook", function () {
|
|
|
55
56
|
// The caller's config is not mutated.
|
|
56
57
|
expect(TABLE_OPTIONS.sys_ux_lib_source_script.fingerprint).toEqual(["script"]);
|
|
57
58
|
});
|
|
59
|
+
it("getManifest warns about a malformed fingerprint option instead of dropping it silently", async function () {
|
|
60
|
+
Logger_1.logger.warn.mockClear();
|
|
61
|
+
var manifest = {
|
|
62
|
+
scope: "x_cadso_ui_form",
|
|
63
|
+
tables: {
|
|
64
|
+
sys_ux_lib_source_script: {
|
|
65
|
+
records: { a: { name: "a", sys_id: "1", files: [{ name: "script", type: "js" }] } },
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
var post = jest.fn().mockResolvedValue(okResponse(manifest));
|
|
70
|
+
var c = makeClient(post);
|
|
71
|
+
var options = { sys_ux_lib_source_script: { fingerprint: "script" } };
|
|
72
|
+
var config = { includes: {}, excludes: {}, tableOptions: options };
|
|
73
|
+
var resp = await c.getManifest("x_cadso_ui_form", config);
|
|
74
|
+
expect(Logger_1.logger.warn).toHaveBeenCalledWith(expect.stringContaining("tableOptions.sys_ux_lib_source_script.fingerprint is ignored"));
|
|
75
|
+
// Still ignored: the field is mirrored as content, as before.
|
|
76
|
+
expect(resp.data.result.tables.sys_ux_lib_source_script.records.a.files[0].type).toBe("js");
|
|
77
|
+
});
|
|
58
78
|
it("getMissingFiles strips fingerprint from the request and hashes the downloaded content", async function () {
|
|
59
79
|
var post = jest.fn().mockResolvedValue(okResponse({
|
|
60
80
|
sys_ux_lib_source_script: {
|