@yuneta/gobj-ui 7.26.21 → 7.26.22
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/gobj-ui.cjs.js +66 -15
- package/dist/gobj-ui.es.js +66 -15
- package/package.json +1 -1
- package/src/c_yui_schema_editor.js +25 -13
- package/src/schema_editor_reload.wiring.test.js +32 -0
- package/src/schema_import.js +22 -0
- package/src/schema_import.test.js +29 -0
- package/src/schema_model.js +24 -0
- package/src/schema_model.test.js +19 -0
- package/src/schema_validate.js +17 -0
- package/src/schema_validate.test.js +33 -0
package/dist/gobj-ui.cjs.js
CHANGED
|
@@ -25091,6 +25091,24 @@ function moved_orders(list) {
|
|
|
25091
25091
|
}
|
|
25092
25092
|
return writes;
|
|
25093
25093
|
}
|
|
25094
|
+
/***************************************************************
|
|
25095
|
+
* The TWO name rules of the treedb (SDK 7.26.9):
|
|
25096
|
+
*
|
|
25097
|
+
* a TOPIC name is a directory and a key: not empty, not "."
|
|
25098
|
+
* or "..", no '/' and no '`' (tranger2_name_is_identifier());
|
|
25099
|
+
* a COLUMN name (a column id, a hook, an fkey) is only a key:
|
|
25100
|
+
* not empty and no '`' (treedb_col_name_is_identifier()).
|
|
25101
|
+
*
|
|
25102
|
+
* Said here as in C, so the editor refuses what the treedb will.
|
|
25103
|
+
***************************************************************/
|
|
25104
|
+
function topic_name_breaks_the_rule(name) {
|
|
25105
|
+
let s = String(name === void 0 || name === null ? "" : name);
|
|
25106
|
+
return s === "" || s === "." || s === ".." || s.includes("/") || s.includes("`");
|
|
25107
|
+
}
|
|
25108
|
+
function col_name_breaks_the_rule(name) {
|
|
25109
|
+
let s = String(name === void 0 || name === null ? "" : name);
|
|
25110
|
+
return s === "" || s.includes("`");
|
|
25111
|
+
}
|
|
25094
25112
|
//#endregion
|
|
25095
25113
|
//#region src/treedb_topic_keys.js
|
|
25096
25114
|
/***********************************************************************
|
|
@@ -72670,6 +72688,8 @@ function validate_schema(treedb, options) {
|
|
|
72670
72688
|
if (treedb.topics.length === 0) add("warning", "schema has no topic", "", "", "");
|
|
72671
72689
|
for (let topic of treedb.topics) {
|
|
72672
72690
|
let col_names = topic.cols.map((c) => c.name);
|
|
72691
|
+
if (topic_name_breaks_the_rule(topic.name)) add("error", "topic name breaks the name rule", topic.name, "", topic.name);
|
|
72692
|
+
for (let col of topic.cols) if (col_name_breaks_the_rule(col.name)) add("error", "column name breaks the name rule", topic.name, col.name, col.name);
|
|
72673
72693
|
if (topic.cols.length === 0) add("error", "topic has no column", topic.name, "", "");
|
|
72674
72694
|
let pkey = topic.pkey || "id";
|
|
72675
72695
|
if (col_names.indexOf(pkey) < 0) add("error", "pkey names no column", topic.name, "", pkey);
|
|
@@ -72687,6 +72707,10 @@ function validate_schema(treedb, options) {
|
|
|
72687
72707
|
let hook = col_hook(col.record);
|
|
72688
72708
|
if (!hook || Object.keys(hook).length === 0) add("error", "hook has no mapping", topic.name, col.name, "");
|
|
72689
72709
|
else for (let [child_topic, fkey_col] of Object.entries(hook)) {
|
|
72710
|
+
if (col_name_breaks_the_rule(fkey_col)) {
|
|
72711
|
+
add("error", "column name breaks the name rule", topic.name, col.name, `${child_topic}.${fkey_col}`);
|
|
72712
|
+
continue;
|
|
72713
|
+
}
|
|
72690
72714
|
let child = topic_by_name[child_topic];
|
|
72691
72715
|
if (!child) {
|
|
72692
72716
|
add("error", "hook names no topic", topic.name, col.name, child_topic);
|
|
@@ -73594,6 +73618,24 @@ function plan_import(treedb, incoming, options) {
|
|
|
73594
73618
|
conflicts
|
|
73595
73619
|
};
|
|
73596
73620
|
}
|
|
73621
|
+
for (let in_topic of incoming.topics) {
|
|
73622
|
+
let name = (in_topic || {}).id;
|
|
73623
|
+
if (name && topic_name_breaks_the_rule(name)) conflicts.push({
|
|
73624
|
+
code: "topic name breaks the name rule",
|
|
73625
|
+
topic: name,
|
|
73626
|
+
col: ""
|
|
73627
|
+
});
|
|
73628
|
+
for (let in_col of incoming_cols(in_topic || {})) if (col_name_breaks_the_rule(in_col.name)) conflicts.push({
|
|
73629
|
+
code: "column name breaks the name rule",
|
|
73630
|
+
topic: name || "",
|
|
73631
|
+
col: in_col.name
|
|
73632
|
+
});
|
|
73633
|
+
}
|
|
73634
|
+
if (conflicts.length > 0) return {
|
|
73635
|
+
writes,
|
|
73636
|
+
summary,
|
|
73637
|
+
conflicts
|
|
73638
|
+
};
|
|
73597
73639
|
let stored_topics = {};
|
|
73598
73640
|
for (let topic of treedb && treedb.topics || []) stored_topics[topic.name] = topic;
|
|
73599
73641
|
let seen_topics = {};
|
|
@@ -74324,6 +74366,7 @@ var PRIVATE_DATA$1 = {
|
|
|
74324
74366
|
dialog: null,
|
|
74325
74367
|
dialog_gen: 0,
|
|
74326
74368
|
dialog_kind: "",
|
|
74369
|
+
dialog_content: null,
|
|
74327
74370
|
save_queue: null,
|
|
74328
74371
|
save_return: "",
|
|
74329
74372
|
save_wrote: false,
|
|
@@ -74387,14 +74430,17 @@ function mt_destroy$1(gobj) {
|
|
|
74387
74430
|
* Local Methods
|
|
74388
74431
|
***************************/
|
|
74389
74432
|
/************************************************************
|
|
74390
|
-
*
|
|
74391
|
-
*
|
|
74392
|
-
*
|
|
74393
|
-
*
|
|
74394
|
-
* a generic "cannot create topic".
|
|
74433
|
+
* A name the treedb refuses (the two name rules of
|
|
74434
|
+
* schema_model.js), said at once: the error carries its key as
|
|
74435
|
+
* a LITERAL (so a consumer's validate-locales sees it), and the
|
|
74436
|
+
* name field is marked aria-invalid for a reader.
|
|
74395
74437
|
************************************************************/
|
|
74396
|
-
function
|
|
74397
|
-
|
|
74438
|
+
function refuse_bad_name(gobj, $message) {
|
|
74439
|
+
let priv = gobj.priv;
|
|
74440
|
+
let $value = priv.dialog_content ? priv.dialog_content.querySelector("[data-name=\"value\"]") : null;
|
|
74441
|
+
if ($value) $value.setAttribute("aria-invalid", "true");
|
|
74442
|
+
yui_shell_show_error(yui_shell_of(gobj), $message, { t: i18next.t });
|
|
74443
|
+
return -1;
|
|
74398
74444
|
}
|
|
74399
74445
|
/***************************************************************
|
|
74400
74446
|
* The frame: a toolbar that never changes place, a notice line
|
|
@@ -75859,6 +75905,7 @@ function close_dialog(gobj) {
|
|
|
75859
75905
|
let dialog = priv.dialog;
|
|
75860
75906
|
priv.dialog = null;
|
|
75861
75907
|
priv.dialog_kind = "";
|
|
75908
|
+
priv.dialog_content = null;
|
|
75862
75909
|
priv.export_view = null;
|
|
75863
75910
|
try {
|
|
75864
75911
|
dialog.close();
|
|
@@ -75871,6 +75918,7 @@ function open_dialog(gobj, $content, title, logical, title_prefix) {
|
|
|
75871
75918
|
close_dialog(gobj);
|
|
75872
75919
|
priv.dialog_gen = priv.model_gen;
|
|
75873
75920
|
priv.dialog_kind = logical;
|
|
75921
|
+
priv.dialog_content = $content;
|
|
75874
75922
|
priv.dialog = yui_shell_show_modal(yui_shell_of(gobj), $content, {
|
|
75875
75923
|
dialog: true,
|
|
75876
75924
|
title,
|
|
@@ -75880,6 +75928,7 @@ function open_dialog(gobj, $content, title, logical, title_prefix) {
|
|
|
75880
75928
|
on_close: () => {
|
|
75881
75929
|
priv.dialog = null;
|
|
75882
75930
|
priv.dialog_kind = "";
|
|
75931
|
+
priv.dialog_content = null;
|
|
75883
75932
|
priv.export_view = null;
|
|
75884
75933
|
}
|
|
75885
75934
|
});
|
|
@@ -77908,10 +77957,11 @@ function ac_save_column(gobj, event, kw, src) {
|
|
|
77908
77957
|
yui_shell_show_error(yui_shell_of(gobj), "a column needs a name", { t: i18next.t });
|
|
77909
77958
|
return -1;
|
|
77910
77959
|
}
|
|
77911
|
-
if (kw.creating &&
|
|
77912
|
-
|
|
77913
|
-
|
|
77914
|
-
|
|
77960
|
+
if (kw.creating && col_name_breaks_the_rule(String(values.value).trim())) return refuse_bad_name(gobj, (0, _yuneta_gobj_js.createElement2)([
|
|
77961
|
+
"span",
|
|
77962
|
+
{ i18n: "invalid column name" },
|
|
77963
|
+
(0, i18next.t)("invalid column name")
|
|
77964
|
+
]));
|
|
77915
77965
|
if (kw.creating && find_col(priv.model, priv.treedb_id, kw.topic, String(values.value).trim())) {
|
|
77916
77966
|
yui_shell_show_error(yui_shell_of(gobj), "that column is already there", { t: i18next.t });
|
|
77917
77967
|
return -1;
|
|
@@ -78166,10 +78216,11 @@ function ac_save_topic(gobj, event, kw, src) {
|
|
|
78166
78216
|
yui_shell_show_error(yui_shell_of(gobj), "a topic needs a name", { t: i18next.t });
|
|
78167
78217
|
return -1;
|
|
78168
78218
|
}
|
|
78169
|
-
if (
|
|
78170
|
-
|
|
78171
|
-
|
|
78172
|
-
|
|
78219
|
+
if (topic_name_breaks_the_rule(name)) return refuse_bad_name(gobj, (0, _yuneta_gobj_js.createElement2)([
|
|
78220
|
+
"span",
|
|
78221
|
+
{ i18n: "invalid topic name" },
|
|
78222
|
+
(0, i18next.t)("invalid topic name")
|
|
78223
|
+
]));
|
|
78173
78224
|
if (find_topic(priv.model, priv.treedb_id, name)) {
|
|
78174
78225
|
yui_shell_show_error(yui_shell_of(gobj), "that topic is already there", { t: i18next.t });
|
|
78175
78226
|
return -1;
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -25086,6 +25086,24 @@ function moved_orders(list) {
|
|
|
25086
25086
|
}
|
|
25087
25087
|
return writes;
|
|
25088
25088
|
}
|
|
25089
|
+
/***************************************************************
|
|
25090
|
+
* The TWO name rules of the treedb (SDK 7.26.9):
|
|
25091
|
+
*
|
|
25092
|
+
* a TOPIC name is a directory and a key: not empty, not "."
|
|
25093
|
+
* or "..", no '/' and no '`' (tranger2_name_is_identifier());
|
|
25094
|
+
* a COLUMN name (a column id, a hook, an fkey) is only a key:
|
|
25095
|
+
* not empty and no '`' (treedb_col_name_is_identifier()).
|
|
25096
|
+
*
|
|
25097
|
+
* Said here as in C, so the editor refuses what the treedb will.
|
|
25098
|
+
***************************************************************/
|
|
25099
|
+
function topic_name_breaks_the_rule(name) {
|
|
25100
|
+
let s = String(name === void 0 || name === null ? "" : name);
|
|
25101
|
+
return s === "" || s === "." || s === ".." || s.includes("/") || s.includes("`");
|
|
25102
|
+
}
|
|
25103
|
+
function col_name_breaks_the_rule(name) {
|
|
25104
|
+
let s = String(name === void 0 || name === null ? "" : name);
|
|
25105
|
+
return s === "" || s.includes("`");
|
|
25106
|
+
}
|
|
25089
25107
|
//#endregion
|
|
25090
25108
|
//#region src/treedb_topic_keys.js
|
|
25091
25109
|
/***********************************************************************
|
|
@@ -72665,6 +72683,8 @@ function validate_schema(treedb, options) {
|
|
|
72665
72683
|
if (treedb.topics.length === 0) add("warning", "schema has no topic", "", "", "");
|
|
72666
72684
|
for (let topic of treedb.topics) {
|
|
72667
72685
|
let col_names = topic.cols.map((c) => c.name);
|
|
72686
|
+
if (topic_name_breaks_the_rule(topic.name)) add("error", "topic name breaks the name rule", topic.name, "", topic.name);
|
|
72687
|
+
for (let col of topic.cols) if (col_name_breaks_the_rule(col.name)) add("error", "column name breaks the name rule", topic.name, col.name, col.name);
|
|
72668
72688
|
if (topic.cols.length === 0) add("error", "topic has no column", topic.name, "", "");
|
|
72669
72689
|
let pkey = topic.pkey || "id";
|
|
72670
72690
|
if (col_names.indexOf(pkey) < 0) add("error", "pkey names no column", topic.name, "", pkey);
|
|
@@ -72682,6 +72702,10 @@ function validate_schema(treedb, options) {
|
|
|
72682
72702
|
let hook = col_hook(col.record);
|
|
72683
72703
|
if (!hook || Object.keys(hook).length === 0) add("error", "hook has no mapping", topic.name, col.name, "");
|
|
72684
72704
|
else for (let [child_topic, fkey_col] of Object.entries(hook)) {
|
|
72705
|
+
if (col_name_breaks_the_rule(fkey_col)) {
|
|
72706
|
+
add("error", "column name breaks the name rule", topic.name, col.name, `${child_topic}.${fkey_col}`);
|
|
72707
|
+
continue;
|
|
72708
|
+
}
|
|
72685
72709
|
let child = topic_by_name[child_topic];
|
|
72686
72710
|
if (!child) {
|
|
72687
72711
|
add("error", "hook names no topic", topic.name, col.name, child_topic);
|
|
@@ -73589,6 +73613,24 @@ function plan_import(treedb, incoming, options) {
|
|
|
73589
73613
|
conflicts
|
|
73590
73614
|
};
|
|
73591
73615
|
}
|
|
73616
|
+
for (let in_topic of incoming.topics) {
|
|
73617
|
+
let name = (in_topic || {}).id;
|
|
73618
|
+
if (name && topic_name_breaks_the_rule(name)) conflicts.push({
|
|
73619
|
+
code: "topic name breaks the name rule",
|
|
73620
|
+
topic: name,
|
|
73621
|
+
col: ""
|
|
73622
|
+
});
|
|
73623
|
+
for (let in_col of incoming_cols(in_topic || {})) if (col_name_breaks_the_rule(in_col.name)) conflicts.push({
|
|
73624
|
+
code: "column name breaks the name rule",
|
|
73625
|
+
topic: name || "",
|
|
73626
|
+
col: in_col.name
|
|
73627
|
+
});
|
|
73628
|
+
}
|
|
73629
|
+
if (conflicts.length > 0) return {
|
|
73630
|
+
writes,
|
|
73631
|
+
summary,
|
|
73632
|
+
conflicts
|
|
73633
|
+
};
|
|
73592
73634
|
let stored_topics = {};
|
|
73593
73635
|
for (let topic of treedb && treedb.topics || []) stored_topics[topic.name] = topic;
|
|
73594
73636
|
let seen_topics = {};
|
|
@@ -74319,6 +74361,7 @@ var PRIVATE_DATA$1 = {
|
|
|
74319
74361
|
dialog: null,
|
|
74320
74362
|
dialog_gen: 0,
|
|
74321
74363
|
dialog_kind: "",
|
|
74364
|
+
dialog_content: null,
|
|
74322
74365
|
save_queue: null,
|
|
74323
74366
|
save_return: "",
|
|
74324
74367
|
save_wrote: false,
|
|
@@ -74382,14 +74425,17 @@ function mt_destroy$1(gobj) {
|
|
|
74382
74425
|
* Local Methods
|
|
74383
74426
|
***************************/
|
|
74384
74427
|
/************************************************************
|
|
74385
|
-
*
|
|
74386
|
-
*
|
|
74387
|
-
*
|
|
74388
|
-
*
|
|
74389
|
-
* a generic "cannot create topic".
|
|
74428
|
+
* A name the treedb refuses (the two name rules of
|
|
74429
|
+
* schema_model.js), said at once: the error carries its key as
|
|
74430
|
+
* a LITERAL (so a consumer's validate-locales sees it), and the
|
|
74431
|
+
* name field is marked aria-invalid for a reader.
|
|
74390
74432
|
************************************************************/
|
|
74391
|
-
function
|
|
74392
|
-
|
|
74433
|
+
function refuse_bad_name(gobj, $message) {
|
|
74434
|
+
let priv = gobj.priv;
|
|
74435
|
+
let $value = priv.dialog_content ? priv.dialog_content.querySelector("[data-name=\"value\"]") : null;
|
|
74436
|
+
if ($value) $value.setAttribute("aria-invalid", "true");
|
|
74437
|
+
yui_shell_show_error(yui_shell_of(gobj), $message, { t });
|
|
74438
|
+
return -1;
|
|
74393
74439
|
}
|
|
74394
74440
|
/***************************************************************
|
|
74395
74441
|
* The frame: a toolbar that never changes place, a notice line
|
|
@@ -75854,6 +75900,7 @@ function close_dialog(gobj) {
|
|
|
75854
75900
|
let dialog = priv.dialog;
|
|
75855
75901
|
priv.dialog = null;
|
|
75856
75902
|
priv.dialog_kind = "";
|
|
75903
|
+
priv.dialog_content = null;
|
|
75857
75904
|
priv.export_view = null;
|
|
75858
75905
|
try {
|
|
75859
75906
|
dialog.close();
|
|
@@ -75866,6 +75913,7 @@ function open_dialog(gobj, $content, title, logical, title_prefix) {
|
|
|
75866
75913
|
close_dialog(gobj);
|
|
75867
75914
|
priv.dialog_gen = priv.model_gen;
|
|
75868
75915
|
priv.dialog_kind = logical;
|
|
75916
|
+
priv.dialog_content = $content;
|
|
75869
75917
|
priv.dialog = yui_shell_show_modal(yui_shell_of(gobj), $content, {
|
|
75870
75918
|
dialog: true,
|
|
75871
75919
|
title,
|
|
@@ -75875,6 +75923,7 @@ function open_dialog(gobj, $content, title, logical, title_prefix) {
|
|
|
75875
75923
|
on_close: () => {
|
|
75876
75924
|
priv.dialog = null;
|
|
75877
75925
|
priv.dialog_kind = "";
|
|
75926
|
+
priv.dialog_content = null;
|
|
75878
75927
|
priv.export_view = null;
|
|
75879
75928
|
}
|
|
75880
75929
|
});
|
|
@@ -77903,10 +77952,11 @@ function ac_save_column(gobj, event, kw, src) {
|
|
|
77903
77952
|
yui_shell_show_error(yui_shell_of(gobj), "a column needs a name", { t });
|
|
77904
77953
|
return -1;
|
|
77905
77954
|
}
|
|
77906
|
-
if (kw.creating &&
|
|
77907
|
-
|
|
77908
|
-
|
|
77909
|
-
|
|
77955
|
+
if (kw.creating && col_name_breaks_the_rule(String(values.value).trim())) return refuse_bad_name(gobj, createElement2([
|
|
77956
|
+
"span",
|
|
77957
|
+
{ i18n: "invalid column name" },
|
|
77958
|
+
t("invalid column name")
|
|
77959
|
+
]));
|
|
77910
77960
|
if (kw.creating && find_col(priv.model, priv.treedb_id, kw.topic, String(values.value).trim())) {
|
|
77911
77961
|
yui_shell_show_error(yui_shell_of(gobj), "that column is already there", { t });
|
|
77912
77962
|
return -1;
|
|
@@ -78161,10 +78211,11 @@ function ac_save_topic(gobj, event, kw, src) {
|
|
|
78161
78211
|
yui_shell_show_error(yui_shell_of(gobj), "a topic needs a name", { t });
|
|
78162
78212
|
return -1;
|
|
78163
78213
|
}
|
|
78164
|
-
if (
|
|
78165
|
-
|
|
78166
|
-
|
|
78167
|
-
|
|
78214
|
+
if (topic_name_breaks_the_rule(name)) return refuse_bad_name(gobj, createElement2([
|
|
78215
|
+
"span",
|
|
78216
|
+
{ i18n: "invalid topic name" },
|
|
78217
|
+
t("invalid topic name")
|
|
78218
|
+
]));
|
|
78168
78219
|
if (find_topic(priv.model, priv.treedb_id, name)) {
|
|
78169
78220
|
yui_shell_show_error(yui_shell_of(gobj), "that topic is already there", { t });
|
|
78170
78221
|
return -1;
|
package/package.json
CHANGED
|
@@ -140,6 +140,8 @@ import {
|
|
|
140
140
|
parse_fkey_ref,
|
|
141
141
|
next_order,
|
|
142
142
|
moved_orders,
|
|
143
|
+
topic_name_breaks_the_rule,
|
|
144
|
+
col_name_breaks_the_rule,
|
|
143
145
|
} from "./schema_model.js";
|
|
144
146
|
import {validate_schema, validate_model, has_errors} from "./schema_validate.js";
|
|
145
147
|
import {topic_descs} from "./schema_descs.js";
|
|
@@ -250,6 +252,7 @@ let PRIVATE_DATA = {
|
|
|
250
252
|
dialog: null,
|
|
251
253
|
dialog_gen: 0, /* the model_gen the open dialog was built on */
|
|
252
254
|
dialog_kind: "", /* the logical class of the open dialog */
|
|
255
|
+
dialog_content: null, /* the content of the open dialog (its name field is marked) */
|
|
253
256
|
|
|
254
257
|
/* A write, or a plan of them, in flight */
|
|
255
258
|
save_queue: null,
|
|
@@ -362,15 +365,21 @@ function mt_destroy(gobj)
|
|
|
362
365
|
|
|
363
366
|
|
|
364
367
|
/************************************************************
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
* a generic "cannot create topic".
|
|
368
|
+
* A name the treedb refuses (the two name rules of
|
|
369
|
+
* schema_model.js), said at once: the error carries its key as
|
|
370
|
+
* a LITERAL (so a consumer's validate-locales sees it), and the
|
|
371
|
+
* name field is marked aria-invalid for a reader.
|
|
370
372
|
************************************************************/
|
|
371
|
-
function
|
|
373
|
+
function refuse_bad_name(gobj, $message)
|
|
372
374
|
{
|
|
373
|
-
|
|
375
|
+
let priv = gobj.priv;
|
|
376
|
+
let $value = priv.dialog_content?
|
|
377
|
+
priv.dialog_content.querySelector('[data-name="value"]') : null;
|
|
378
|
+
if($value) {
|
|
379
|
+
$value.setAttribute("aria-invalid", "true");
|
|
380
|
+
}
|
|
381
|
+
yui_shell_show_error(yui_shell_of(gobj), $message, {t: t});
|
|
382
|
+
return -1;
|
|
374
383
|
}
|
|
375
384
|
|
|
376
385
|
/***************************************************************
|
|
@@ -1870,6 +1879,7 @@ function close_dialog(gobj)
|
|
|
1870
1879
|
let dialog = priv.dialog;
|
|
1871
1880
|
priv.dialog = null;
|
|
1872
1881
|
priv.dialog_kind = "";
|
|
1882
|
+
priv.dialog_content = null;
|
|
1873
1883
|
priv.export_view = null;
|
|
1874
1884
|
try {
|
|
1875
1885
|
dialog.close();
|
|
@@ -1885,6 +1895,7 @@ function open_dialog(gobj, $content, title, logical, title_prefix)
|
|
|
1885
1895
|
close_dialog(gobj);
|
|
1886
1896
|
priv.dialog_gen = priv.model_gen;
|
|
1887
1897
|
priv.dialog_kind = logical;
|
|
1898
|
+
priv.dialog_content = $content;
|
|
1888
1899
|
priv.dialog = yui_shell_show_modal(yui_shell_of(gobj), $content, {
|
|
1889
1900
|
dialog: true,
|
|
1890
1901
|
title: title,
|
|
@@ -1894,6 +1905,7 @@ function open_dialog(gobj, $content, title, logical, title_prefix)
|
|
|
1894
1905
|
on_close: () => {
|
|
1895
1906
|
priv.dialog = null;
|
|
1896
1907
|
priv.dialog_kind = "";
|
|
1908
|
+
priv.dialog_content = null;
|
|
1897
1909
|
priv.export_view = null;
|
|
1898
1910
|
}
|
|
1899
1911
|
});
|
|
@@ -4038,9 +4050,9 @@ function ac_save_column(gobj, event, kw, src)
|
|
|
4038
4050
|
yui_shell_show_error(yui_shell_of(gobj), "a column needs a name", {t: t});
|
|
4039
4051
|
return -1;
|
|
4040
4052
|
}
|
|
4041
|
-
if(kw.creating &&
|
|
4042
|
-
|
|
4043
|
-
|
|
4053
|
+
if(kw.creating && col_name_breaks_the_rule(String(values.value).trim())) {
|
|
4054
|
+
return refuse_bad_name(gobj, createElement2(
|
|
4055
|
+
["span", {i18n: "invalid column name"}, t("invalid column name")]));
|
|
4044
4056
|
}
|
|
4045
4057
|
if(kw.creating && find_col(priv.model, priv.treedb_id, kw.topic, String(values.value).trim())) {
|
|
4046
4058
|
yui_shell_show_error(yui_shell_of(gobj), "that column is already there", {t: t});
|
|
@@ -4349,9 +4361,9 @@ function ac_save_topic(gobj, event, kw, src)
|
|
|
4349
4361
|
yui_shell_show_error(yui_shell_of(gobj), "a topic needs a name", {t: t});
|
|
4350
4362
|
return -1;
|
|
4351
4363
|
}
|
|
4352
|
-
if(
|
|
4353
|
-
|
|
4354
|
-
|
|
4364
|
+
if(topic_name_breaks_the_rule(name)) {
|
|
4365
|
+
return refuse_bad_name(gobj, createElement2(
|
|
4366
|
+
["span", {i18n: "invalid topic name"}, t("invalid topic name")]));
|
|
4355
4367
|
}
|
|
4356
4368
|
if(find_topic(priv.model, priv.treedb_id, name)) {
|
|
4357
4369
|
yui_shell_show_error(yui_shell_of(gobj), "that topic is already there", {t: t});
|
|
@@ -1716,3 +1716,35 @@ describe("the reason a load failed", () => {
|
|
|
1716
1716
|
expect($detail.getAttribute("data-i18n")).toBe("cannot reach the treedb");
|
|
1717
1717
|
});
|
|
1718
1718
|
});
|
|
1719
|
+
|
|
1720
|
+
|
|
1721
|
+
/*
|
|
1722
|
+
* The two name rules (REV-CLOUD V14.2): a name the treedb refuses is
|
|
1723
|
+
* said at once, with its key, and nothing is written; a '/' in a column
|
|
1724
|
+
* is not refused (a column is a key, not a directory).
|
|
1725
|
+
*/
|
|
1726
|
+
describe("names the treedb refuses", () => {
|
|
1727
|
+
test("a column x`y is refused with its key; kids/all is written", () => {
|
|
1728
|
+
const {editor, host} = build("names_col", "db/users");
|
|
1729
|
+
gobj_send_event(editor, "EV_SAVE_COLUMN", {
|
|
1730
|
+
creating: true, topic: "users", values: {value: "x`y", type: "string"}
|
|
1731
|
+
}, host);
|
|
1732
|
+
expect(take("update-node").length).toBe(0);
|
|
1733
|
+
expect(shown.length).toBe(1);
|
|
1734
|
+
expect(shown[0].getAttribute("data-i18n")).toBe("invalid column name");
|
|
1735
|
+
start_a_write(editor, host, "kids/all");
|
|
1736
|
+
});
|
|
1737
|
+
|
|
1738
|
+
test("a topic a/b or .. is refused with its key", () => {
|
|
1739
|
+
const {editor, host} = build("names_topic", "db");
|
|
1740
|
+
for(const name of ["a/b", ".."]) {
|
|
1741
|
+
shown.length = 0;
|
|
1742
|
+
gobj_send_event(editor, "EV_SAVE_TOPIC", {
|
|
1743
|
+
creating: true, topic: "", values: {value: name}
|
|
1744
|
+
}, host);
|
|
1745
|
+
expect(take("update-node").length).toBe(0);
|
|
1746
|
+
expect(shown.length).toBe(1);
|
|
1747
|
+
expect(shown[0].getAttribute("data-i18n")).toBe("invalid topic name");
|
|
1748
|
+
}
|
|
1749
|
+
});
|
|
1750
|
+
});
|
package/src/schema_import.js
CHANGED
|
@@ -31,6 +31,8 @@ import {
|
|
|
31
31
|
as_json,
|
|
32
32
|
is_empty_value,
|
|
33
33
|
fkey_ref,
|
|
34
|
+
topic_name_breaks_the_rule,
|
|
35
|
+
col_name_breaks_the_rule,
|
|
34
36
|
} from "./schema_model.js";
|
|
35
37
|
|
|
36
38
|
|
|
@@ -204,6 +206,26 @@ function plan_import(treedb, incoming, options)
|
|
|
204
206
|
return {writes: writes, summary: summary, conflicts: conflicts};
|
|
205
207
|
}
|
|
206
208
|
|
|
209
|
+
/*
|
|
210
|
+
* Names the treedb refuses (the two name rules of schema_model.js)
|
|
211
|
+
* stop the plan BEFORE any write: run through, the backend refused
|
|
212
|
+
* them half way, with the writes before them already done.
|
|
213
|
+
*/
|
|
214
|
+
for(let in_topic of incoming.topics) {
|
|
215
|
+
let name = (in_topic || {}).id;
|
|
216
|
+
if(name && topic_name_breaks_the_rule(name)) {
|
|
217
|
+
conflicts.push({code: "topic name breaks the name rule", topic: name, col: ""});
|
|
218
|
+
}
|
|
219
|
+
for(let in_col of incoming_cols(in_topic || {})) {
|
|
220
|
+
if(col_name_breaks_the_rule(in_col.name)) {
|
|
221
|
+
conflicts.push({code: "column name breaks the name rule", topic: name || "", col: in_col.name});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if(conflicts.length > 0) {
|
|
226
|
+
return {writes: writes, summary: summary, conflicts: conflicts};
|
|
227
|
+
}
|
|
228
|
+
|
|
207
229
|
let stored_topics = {};
|
|
208
230
|
for(let topic of ((treedb && treedb.topics) || [])) {
|
|
209
231
|
stored_topics[topic.name] = topic;
|
|
@@ -253,3 +253,32 @@ describe("the empty collections the store answers with", () => {
|
|
|
253
253
|
expect(plan_import(stored, incoming).writes).toEqual([]);
|
|
254
254
|
});
|
|
255
255
|
});
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
describe("names the treedb refuses stop the plan before any write (REV-CLOUD V14.2)", () => {
|
|
259
|
+
test("a topic a/b, a topic .., a column x`y: conflicts, no writes", () => {
|
|
260
|
+
let plan = plan_import(null, {
|
|
261
|
+
id: "db", schema_version: "1",
|
|
262
|
+
topics: [
|
|
263
|
+
{id: "a/b", pkey: "id", cols: {id: {id: "id", type: "string"}}},
|
|
264
|
+
{id: "..", pkey: "id", cols: {id: {id: "id", type: "string"}}},
|
|
265
|
+
{id: "ok", pkey: "id", cols: {"id": {id: "id", type: "string"},
|
|
266
|
+
"x`y": {id: "x`y", type: "string"}}},
|
|
267
|
+
]
|
|
268
|
+
});
|
|
269
|
+
expect(plan.writes).toEqual([]);
|
|
270
|
+
let codes = plan.conflicts.map((c) => c.code);
|
|
271
|
+
expect(codes.filter((c) => c === "topic name breaks the name rule").length).toBe(2);
|
|
272
|
+
expect(codes).toContain("column name breaks the name rule");
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test("a '/' in a column and a leading '.' in a topic are imported", () => {
|
|
276
|
+
let plan = plan_import(null, {
|
|
277
|
+
id: "db", schema_version: "1",
|
|
278
|
+
topics: [{id: ".hidden", pkey: "id",
|
|
279
|
+
cols: {"id": {id: "id", type: "string"}, "kids/all": {id: "kids/all", type: "dict"}}}]
|
|
280
|
+
});
|
|
281
|
+
expect(plan.conflicts).toEqual([]);
|
|
282
|
+
expect(plan.writes.length).toBeGreaterThan(0);
|
|
283
|
+
});
|
|
284
|
+
});
|
package/src/schema_model.js
CHANGED
|
@@ -515,8 +515,32 @@ function moved_orders(list)
|
|
|
515
515
|
return writes;
|
|
516
516
|
}
|
|
517
517
|
|
|
518
|
+
/***************************************************************
|
|
519
|
+
* The TWO name rules of the treedb (SDK 7.26.9):
|
|
520
|
+
*
|
|
521
|
+
* a TOPIC name is a directory and a key: not empty, not "."
|
|
522
|
+
* or "..", no '/' and no '`' (tranger2_name_is_identifier());
|
|
523
|
+
* a COLUMN name (a column id, a hook, an fkey) is only a key:
|
|
524
|
+
* not empty and no '`' (treedb_col_name_is_identifier()).
|
|
525
|
+
*
|
|
526
|
+
* Said here as in C, so the editor refuses what the treedb will.
|
|
527
|
+
***************************************************************/
|
|
528
|
+
function topic_name_breaks_the_rule(name)
|
|
529
|
+
{
|
|
530
|
+
let s = String(name === undefined || name === null ? "" : name);
|
|
531
|
+
return s === "" || s === "." || s === ".." || s.includes("/") || s.includes("`");
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function col_name_breaks_the_rule(name)
|
|
535
|
+
{
|
|
536
|
+
let s = String(name === undefined || name === null ? "" : name);
|
|
537
|
+
return s === "" || s.includes("`");
|
|
538
|
+
}
|
|
539
|
+
|
|
518
540
|
|
|
519
541
|
export {
|
|
542
|
+
topic_name_breaks_the_rule,
|
|
543
|
+
col_name_breaks_the_rule,
|
|
520
544
|
DEFAULT_ORDER,
|
|
521
545
|
REF_SEP,
|
|
522
546
|
parse_fkey_ref,
|
package/src/schema_model.test.js
CHANGED
|
@@ -256,3 +256,22 @@ describe("is_empty_value — what the store answers when a blob was never set",
|
|
|
256
256
|
expect(is_empty_value(false)).toBe(false);
|
|
257
257
|
});
|
|
258
258
|
});
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
describe("the two name rules", async () => {
|
|
262
|
+
const { topic_name_breaks_the_rule, col_name_breaks_the_rule } = await import("./schema_model.js");
|
|
263
|
+
test("as C: topic = tranger2_name_is_identifier(), column = treedb_col_name_is_identifier()", () => {
|
|
264
|
+
for(let n of ["", ".", "..", "a/b", "a`b"]) {
|
|
265
|
+
expect(topic_name_breaks_the_rule(n)).toBe(true);
|
|
266
|
+
}
|
|
267
|
+
for(let n of ["users", ".hidden", "a.b"]) {
|
|
268
|
+
expect(topic_name_breaks_the_rule(n)).toBe(false);
|
|
269
|
+
}
|
|
270
|
+
for(let n of ["", "a`b"]) {
|
|
271
|
+
expect(col_name_breaks_the_rule(n)).toBe(true);
|
|
272
|
+
}
|
|
273
|
+
for(let n of ["id", "kids/all", "..", ".x"]) {
|
|
274
|
+
expect(col_name_breaks_the_rule(n)).toBe(false);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
});
|
package/src/schema_validate.js
CHANGED
|
@@ -32,6 +32,8 @@ import {
|
|
|
32
32
|
col_hook,
|
|
33
33
|
col_enum,
|
|
34
34
|
topic_pkey2s,
|
|
35
|
+
topic_name_breaks_the_rule,
|
|
36
|
+
col_name_breaks_the_rule,
|
|
35
37
|
} from "./schema_model.js";
|
|
36
38
|
|
|
37
39
|
|
|
@@ -100,6 +102,16 @@ function validate_schema(treedb, options)
|
|
|
100
102
|
for(let topic of treedb.topics) {
|
|
101
103
|
let col_names = topic.cols.map(c => c.name);
|
|
102
104
|
|
|
105
|
+
/* A name the treedb refuses: the topic is left out when it opens. */
|
|
106
|
+
if(topic_name_breaks_the_rule(topic.name)) {
|
|
107
|
+
add("error", "topic name breaks the name rule", topic.name, "", topic.name);
|
|
108
|
+
}
|
|
109
|
+
for(let col of topic.cols) {
|
|
110
|
+
if(col_name_breaks_the_rule(col.name)) {
|
|
111
|
+
add("error", "column name breaks the name rule", topic.name, col.name, col.name);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
103
115
|
if(topic.cols.length === 0) {
|
|
104
116
|
add("error", "topic has no column", topic.name, "", "");
|
|
105
117
|
}
|
|
@@ -143,6 +155,11 @@ function validate_schema(treedb, options)
|
|
|
143
155
|
add("error", "hook has no mapping", topic.name, col.name, "");
|
|
144
156
|
} else {
|
|
145
157
|
for(let [child_topic, fkey_col] of Object.entries(hook)) {
|
|
158
|
+
if(col_name_breaks_the_rule(fkey_col)) {
|
|
159
|
+
add("error", "column name breaks the name rule", topic.name, col.name,
|
|
160
|
+
`${child_topic}.${fkey_col}`);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
146
163
|
let child = topic_by_name[child_topic];
|
|
147
164
|
if(!child) {
|
|
148
165
|
add("error", "hook names no topic", topic.name, col.name,
|
|
@@ -287,3 +287,36 @@ describe("only one hook may name a fkey column", () => {
|
|
|
287
287
|
expect(dup[0].severity).toBe("error");
|
|
288
288
|
});
|
|
289
289
|
});
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
describe("the two name rules (REV-CLOUD V14.2)", () => {
|
|
293
|
+
test("a column with the delimiter is an error; a '/' in a column is fine", () => {
|
|
294
|
+
let bad = validate_schema(schema({extra_col:
|
|
295
|
+
{id: "db.users.x`y", value: "x`y", order: 3, type: "string",
|
|
296
|
+
flag: ["persistent"], topics: ["topics^db.users^cols"]}}));
|
|
297
|
+
expect(codes(bad)).toContain("column name breaks the name rule");
|
|
298
|
+
let fine = validate_schema(schema({extra_col:
|
|
299
|
+
{id: "db.users.kids/all", value: "kids/all", order: 3, type: "string",
|
|
300
|
+
flag: ["persistent"], topics: ["topics^db.users^cols"]}}));
|
|
301
|
+
expect(codes(fine)).not.toContain("column name breaks the name rule");
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
test("a topic named with '/' or '..' is an error; a leading '.' is not", () => {
|
|
305
|
+
for(let [name, wanted] of [["a/b", true], ["..", true], [".hidden", false]]) {
|
|
306
|
+
let treedb = build_schema_model({
|
|
307
|
+
treedbs: [{id: "db", schema_version: 1}],
|
|
308
|
+
topics: [{id: `db.${name}`, value: name, order: 1, pkey: "id",
|
|
309
|
+
topic_version: 1, treedbs: ["treedbs^db^topics"]}],
|
|
310
|
+
cols: [{id: `db.${name}.id`, value: "id", order: 1, type: "string",
|
|
311
|
+
flag: ["persistent"], topics: [`topics^db.${name}^cols`]}],
|
|
312
|
+
}).treedbs[0];
|
|
313
|
+
expect(codes(validate_schema(treedb)).includes("topic name breaks the name rule"))
|
|
314
|
+
.toBe(wanted);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test("a hook mapping to an fkey column with the delimiter is an error", () => {
|
|
319
|
+
let found = validate_schema(schema({hook: {users: "dep`artments"}}));
|
|
320
|
+
expect(codes(found)).toContain("column name breaks the name rule");
|
|
321
|
+
});
|
|
322
|
+
});
|