efront 4.5.3 → 4.5.7

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.
Files changed (48) hide show
  1. package/#/345/233/275/351/231/205/345/214/226.yml +84 -9
  2. package/apps/pivot/api.yml +2 -1
  3. package/apps/pivot/cert/main.xht +38 -18
  4. package/apps/pivot/cert/orders.xht +8 -39
  5. package/apps/pivot/cert/update.xht +35 -2
  6. package/coms/basic/#loader.js +4 -3
  7. package/coms/basic/YAML.js +1 -1
  8. package/coms/basic/awaitable.js +6 -2
  9. package/coms/{zimoli → basic}/data.js +10 -8
  10. package/coms/basic/data.md +48 -0
  11. package/coms/basic/data_test.js +12 -0
  12. package/coms/basic/parseYML.js +13 -6
  13. package/coms/basic/parseYML_test.js +5 -1
  14. package/coms/basic/refilm_decode.js +1 -0
  15. package/coms/compile/Javascript.js +9 -43
  16. package/coms/compile/common.js +51 -8
  17. package/coms/compile/patchlist.js +4 -0
  18. package/coms/compile/patchname.js +4 -0
  19. package/coms/compile/scanner2.js +2 -2
  20. package/coms/compile/translate.js +2 -1
  21. package/coms/compile//347/264/240/351/246/250.js +4 -3
  22. package/coms/compile//347/264/240/351/246/250_test.js +1 -0
  23. package/coms/docs/helps.js +1 -1
  24. package/coms/pivot/acme2.js +103 -19
  25. package/coms/pivot/pedit.js +7 -9
  26. package/coms/reptile/alert.js +1 -0
  27. package/coms/reptile/detectWithExtension.js +2 -1
  28. package/coms/reptile/localStorage.js +4 -0
  29. package/coms/reptile/on.js +4 -0
  30. package/coms/reptile/onmounted.js +1 -0
  31. package/coms/reptile/sessionStorage.js +1 -0
  32. package/coms/reptile/window.js +65 -0
  33. package/coms/zimoli/alert.js +32 -31
  34. package/coms/zimoli/button.less +8 -1
  35. package/coms/zimoli/confirm.js +22 -10
  36. package/coms/zimoli/model.js +28 -14
  37. package/coms/zimoli/model.less +45 -2
  38. package/coms/zimoli/selectDate.js +2 -2
  39. package/coms/zimoli/view.less +1 -2
  40. package/docs//345/267/245/345/205/267//345/233/275/351/231/205/345/214/226.xht +50 -9
  41. package/package.json +2 -3
  42. package/public/efront.js +1 -2
  43. package/readme-en.md +0 -2
  44. package/readme.md +0 -2
  45. package/coms/zimoli/data_test.js +0 -35
  46. /package/coms/{zimoli → basic}/LoadingArray.js +0 -0
  47. /package/coms/{zimoli → basic}/fromBase64.js +0 -0
  48. /package/coms/{zimoli → basic}/toBase64.js +0 -0
@@ -1,17 +1,95 @@
1
+ - zh-CN: 搜索
2
+ en: Search
3
+
4
+ - zh-CN: 发现不同的翻译
5
+ en: Discovering different translations
6
+
7
+ - zh-CN: 确定
8
+ en: Confirm
9
+
10
+ - zh-CN: 导出完成
11
+ en: Export completed
12
+
13
+ - zh-CN: 继续
14
+ en: Continue
15
+
16
+ - zh-CN: 确认
17
+ en: Confirm
18
+
19
+ - zh-CN: 用于$1的证书不可用
20
+ en: Certificate not available for $1
21
+
22
+ - zh-CN: 当前环境无法启用证书更新服务,nodeJs版本为$1
23
+ en: "The current environment cannot enable certificate update service, nodeJs version is $1"
24
+
25
+ - zh-CN: "$1中,由$2引用了如下$3个路径:"
26
+ en: "In $1, $2 references the following $3 paths:"
27
+
28
+ - zh-CN: "读取出错了,路径:"
29
+ en: "Error reading, path:"
30
+
31
+ - zh-CN: 创建账户
32
+ en: Create account
33
+
34
+ - zh-CN: 已创建账户
35
+ en: Account created
36
+
37
+ - zh-CN: 您已创建账户,请确认是否重新创建?
38
+ en: "You have created an account, please confirm if you want to create it again?"
39
+
40
+ - zh-CN: 创建订单
41
+ en: Create order
42
+
43
+ - zh-CN: 订单信息
44
+ en: Order information
45
+
46
+ - zh-CN: 证书列表
47
+ en: Certificate List
48
+
49
+ - zh-CN: 更新服务
50
+ en: Update Services
51
+
52
+ - zh-CN: 证书已更新!
53
+ en: The certificate has been updated!
54
+
55
+ - zh-CN: 更新失败!
56
+ en: Update failed!
57
+
58
+ - zh-CN: 保存成功
59
+ en: Save successful
60
+
61
+ - zh-CN: 替换证书是在不重启服务器的情况下,替换当前服务器的证书
62
+ en: "Replacing a certificate is replacing the current server's certificate without restarting the server"
63
+
64
+ - zh-CN: 替换完成!
65
+ en: Replacement completed!
66
+
67
+ - zh-CN: 上次更新时间
68
+ en: Last update time
69
+
70
+ - zh-CN: 下次更新时间
71
+ en: Next update time
72
+
73
+ - zh-CN: 自动更新周期
74
+ en: Automatic update cycle
75
+
76
+ - zh-CN: 是否开启计划
77
+ en: Do you want to start the plan
78
+
1
79
  - zh-CN: 端口异常
2
80
  en: Port abnormality
3
81
 
4
82
  - zh-CN: 分配地址失败
5
83
  en: Address allocation failed
6
84
 
7
- - zh-CN: 电子邮箱地址应包含符号“@”
85
+ - zh-CN: "电子邮箱地址应包含符号“@”"
8
86
  en: "The email address should contain the symbol \"@\""
9
87
 
10
88
  - zh-CN: "@符号前应有内容"
11
89
  en: "There should be content before the symbol \"@\""
12
90
 
13
91
  - zh-CN: "@符号后应有内容"
14
- en: "There should be content after the symbol\"@\""
92
+ en: "There should be content after the symbol \"@\""
15
93
 
16
94
  - zh-CN: 私钥
17
95
  en: Private key
@@ -367,8 +445,8 @@
367
445
  - zh-CN: 状态错误
368
446
  en: Status error
369
447
 
370
- - zh-CN: 路径<gray>$1</gray>不存在
371
- en: Path<gray>$1</gray>does not exist
448
+ - zh-CN: 路径$1不存在
449
+ en: Path $1 does not exist
372
450
 
373
451
  - zh-CN: 只在主线程中使用
374
452
  en: Only used in the main thread
@@ -1285,8 +1363,8 @@
1285
1363
  - zh-CN: 导出到文件
1286
1364
  en: Export to file
1287
1365
 
1288
- - zh-CN: 国际化翻译缺失:
1289
- en: "Lack of international translation:"
1366
+ - zh-CN: 翻译缺失:
1367
+ en: "Lack of translation:"
1290
1368
 
1291
1369
  - zh-CN: "翻译:"
1292
1370
  en: "Translation:"
@@ -1732,9 +1810,6 @@
1732
1810
  - zh-CN: 登录中
1733
1811
  en: Logging in
1734
1812
 
1735
- - zh-CN: 确定
1736
- en: Confirm
1737
-
1738
1813
  - zh-CN: 取消
1739
1814
  en: Cancel
1740
1815
 
@@ -8,6 +8,7 @@
8
8
  list: options :::type
9
9
  edit: options :::type-:key?:value
10
10
  add: options :::type-:key+:value
11
+ patch: options :::type-:key*:value
11
12
  params: options ::params-:key
12
13
  invoke: options ::invoke-:key?:params
13
14
  version: options ::version
@@ -18,7 +19,7 @@
18
19
  room: options ::link-:id
19
20
  care: options ::care-:id
20
21
  cast: options ::cast-:id?:msg
21
- setauth|: options ::setauth-/.well-known/acme-challenge/:token?:token.:thumb
22
+ setauth|: options ::setauth-:auth?:info
22
23
  unique: options ::unique
23
24
  unique-save: options ::unique-:data
24
25
  recert: options ::recert
@@ -45,7 +45,12 @@
45
45
  appearance: none;
46
46
  border: none;
47
47
  }
48
+
49
+ loading {
50
+ z-index: 3;
51
+ }
48
52
  </style>
53
+ <loading -if="!finished"></loading>
49
54
  <div -if="!enabled"></div>
50
55
  <form on-submit="nosubmit" renderid=box>
51
56
  <xmenu head #menubar -src="(m,i) in menus" @active="activeMenu(m,i)"></xmenu>
@@ -74,22 +79,25 @@
74
79
  var private_key, public_key;
75
80
  var unique;
76
81
  var loadUnique = async function () {
77
- unique = await data.from("unique");
78
- await acme2.makeUnique(unique);
79
- if (menuIndex === 0) {
80
- if (acme2.orders?.length) activeMenu(menus[2], 2);
81
- else if (acme2.kid) activeMenu(menus[1], 1);
82
+ try {
83
+ unique = await data.from("unique");
84
+ await acme2.makeUnique(unique);
85
+ if (menuIndex === 0) {
86
+ if (acme2.orders?.length) activeMenu(menus[2], 2);
87
+ else if (acme2.kid) activeMenu(menus[1], 1);
88
+ }
89
+ extend(formdata, acme2);
90
+ } finally {
91
+ finished = true;
82
92
  }
83
- extend(formdata, acme2);
84
93
  };
85
-
94
+ var finished = false;
86
95
  var publicKey, privateKey;
87
96
  loadUnique().then(render.digest).then(lazy(async function () {
88
97
  box.reshape();
89
98
  bar.reshape();
90
99
  var certlist = await plist.load('cert');
91
- formdata.domain = certlist.map(c => c.hostname).join("\r\n");
92
- render.digest();
100
+ acme2.domain = formdata.domain = certlist.map(c => c.hostname).join("\r\n");
93
101
  }));
94
102
  var a = button;
95
103
  var xmenu = menu;
@@ -102,10 +110,18 @@
102
110
  };
103
111
  var openOrder = async function (event, href) {
104
112
  event.preventDefault();
105
- }
113
+ };
114
+ var uploadOnly = async function (o, extra) {
115
+ var domains = o.identifiers.map(d => d.value);
116
+ for (var d of domains) {
117
+ await pedit.patch("cert", d, extra);
118
+ }
119
+ };
120
+ var setauth = (auth, info) => data.from("setauth", { auth, info });
121
+
106
122
  var menus = [
107
123
  {
108
- "name": "创建账户",
124
+ "name": i18n`创建账户`,
109
125
  fields: refilm`
110
126
  $公钥/public_key/单击生成 ${function (elem) {
111
127
  var { data, field } = elem;
@@ -127,10 +143,13 @@
127
143
  }}
128
144
  `,
129
145
  get message() {
130
- return formdata.kid ? "已创建账户" : '';
146
+ return formdata.kid ? i18n`已创建账户` : '';
131
147
  },
132
148
  actions: {
133
149
  async 创建账户(actived) {
150
+ if (formdata.kid) {
151
+ if (!await confirm(i18n`您已创建账户,请确认是否重新创建?`)) return;
152
+ }
134
153
  var params = submit(actived.fields, formdata);
135
154
  await saveUnique(params);
136
155
  formdata.kid = await acme2.newAccount(params);
@@ -139,7 +158,7 @@
139
158
  }
140
159
  },
141
160
  {
142
- "name": "创建订单",
161
+ "name": i18n`创建订单`,
143
162
  get disabled() {
144
163
  return !!formdata.kid;
145
164
  },
@@ -150,25 +169,26 @@
150
169
  actions: {
151
170
  async 创建订单(actived) {
152
171
  var params = submit(actived.fields, formdata);
153
- var order = await acme2.newOrder(params);
172
+ await acme2.newOrder(params);
154
173
  await saveUnique();
155
174
  activeMenu(menus[2], 2);
156
175
  }
157
176
  }
158
177
  },
159
178
  {
160
- name: "订单信息",
179
+ name: i18n`订单信息`,
161
180
  src: '/cert/orders',
162
181
  get params() {
163
- return { orders: acme2.orders, saveUnique };
182
+ return { orders: acme2.orders, saveUnique, setauth, uploadOnly };
164
183
  }
165
184
  },
166
185
  {
167
- name: "证书列表",
186
+ name: i18n`证书列表`,
168
187
  src: "/cert/list",
169
188
  },
170
189
  {
171
- name: "更新服务",
190
+ name: i18n`更新服务`,
191
+ params: { saveUnique, uploadOnly, setauth },
172
192
  src: "/cert/update",
173
193
  }
174
194
  ];
@@ -10,22 +10,11 @@
10
10
 
11
11
  &>xmenu[horizonal] {
12
12
  width: 100%;
13
- margin-bottom: -2px;
13
+ margin-bottom: -1px;
14
14
  z-index: 1;
15
15
  border-bottom: none;
16
16
  box-shadow: none;
17
-
18
- &:after {
19
- content: "";
20
- display: block;
21
- position: absolute;
22
- left: 0;
23
- bottom: 0;
24
- right: 0;
25
- height: 0;
26
- border-bottom: --border;
27
- z-index: -1;
28
- }
17
+ background: none;
29
18
 
30
19
  .actived {
31
20
  background: #fff;
@@ -110,7 +99,7 @@
110
99
  };
111
100
 
112
101
  function main(params) {
113
- var { orders = [], saveUnique } = params;
102
+ var { orders = [], saveUnique, setauth, uploadOnly } = params;
114
103
  orders = orders.map(acme2.parseOrder);
115
104
  if (orders.length) orders[0].actived = true;
116
105
  var page = document.createElement('orders');
@@ -148,28 +137,12 @@
148
137
  this.order = shallowClone(o);
149
138
  },
150
139
  async auditOrder(o) {
151
- a: for (var a of o.authorizations) {
152
- var b = await acme2.audit(a);
153
- if (b.challenges) {
154
- for (var c of b.challenges) {
155
- if (c.type === 'http-01') {
156
- if (c.status !== 'pending') continue a;
157
- await data.from("setauth", { token: c.token, thumb: await acme2.thumbprint() });
158
- await acme2.requestURL(c.url, {});
159
- continue a;
160
- }
161
- }
162
- }
163
- alert("无法找到可用的提审方案" + b.identifier?.value, 'warn');
164
- }
165
- await wait(600);
140
+ await acme2.auditOrder(o, setauth);
166
141
  if (this.order === o) await this.openOrder(this.order);
167
142
  },
143
+
168
144
  async finalize(o) {
169
- var domains = o.identifiers.map(d => d.value);
170
- var kp = await acme2.createKeyPair();
171
- var csr = await acme2.createCSR(domains, kp[0]);
172
- var order = await acme2.requestURL(o.finalize, { csr });
145
+ await acme2.finalizeOrder(o, uploadOnly);
173
146
  order = extend({}, o, order);
174
147
  if (o === this.order) o = this.order = order;
175
148
  render.digest();
@@ -181,9 +154,7 @@
181
154
  }
182
155
  else {
183
156
  cert = await data.fromURL(cert);
184
- }
185
- for (var d of domains) {
186
- pedit.update("cert", d, { hostname: d, private: kp[0], public: kp[1], cert, oid: o.oid })
157
+ await uploadOnly(o, { cert });
187
158
  }
188
159
  if (this.order === o) this.order = extend({}, o, order);
189
160
  },
@@ -217,9 +188,7 @@
217
188
  },
218
189
  async upload(o) {
219
190
  var cert = await data.fromURL(o.certificate);
220
- for (var d of o.identifiers) {
221
- await pedit.merge("cert", d.value, { cert });
222
- }
191
+ await uploadOnly(o, { cert });
223
192
  o.shouldupload = false;
224
193
  o.removable = true;
225
194
  }
@@ -1,7 +1,40 @@
1
- <div><button @click="updateCert()">更新证书</button></div>
1
+ <form onsubmit="event.preventDefault()">
2
+ <div body>
3
+ <field -repeat="f in fields" -src="[f,acme2]"></field>
4
+ </div>
5
+ <div foot>
6
+ <a confirm @click="autoUpdate()">执行更新</a>
7
+ <a @click="updateCert()">替换证书</a>
8
+ <button @click="saveSchadule()">保存计划</button>
9
+ </div>
10
+ </form>
2
11
  <script>
12
+ var form = view;
13
+ var a = button;
14
+ var fields = refilm`$上次更新时间/lastUpdateTime date
15
+ 下次更新时间/nextUpdateTime date
16
+ 自动更新周期/schadulePeriod 天/int
17
+ 是否开启计划/schaduleEnabled swap
18
+ `;
19
+ var page = this;
20
+ var [{ saveUnique, setauth, uploadOnly }] = arguments;
21
+ var autoUpdate = async function () {
22
+ var o = await acme2.autoUpdate(acme2.domain, setauth, uploadOnly);
23
+ await saveUnique();
24
+ if (o.status === 'valid') {
25
+ alert(i18n`证书已更新!`, "success");
26
+ }
27
+ else {
28
+ alert(i18n`更新失败!`, 'error');
29
+ }
30
+ };
31
+ var saveSchadule = async function () {
32
+ await saveUnique();
33
+ alert(i18n`保存成功`, "success");
34
+ };
3
35
  var updateCert = async function () {
36
+ if (!await confirm(i18n`替换证书是在不重启服务器的情况下,替换当前服务器的证书`)) return;
4
37
  await data.from("recert");
5
- alert("更新完成!", 'success');
38
+ alert(i18n`替换完成!`, 'success');
6
39
  };
7
40
  </script>
@@ -458,16 +458,17 @@ var createModule = function (exec, originNames, compiledNames, prebuilds = {}) {
458
458
  if (argName === 'import_meta') {
459
459
  return new Meta(exec.file);
460
460
  }
461
- if (/^(?:window|global|undefined)$/.test(argName)) return window[argName];
461
+ if (/^(?:window|global(This)?|undefined)$/.test(argName)) return window[argName];
462
462
  if (argName === "require") {
463
+ var r1 = window.require;
463
464
  let r = function (refer) {
464
- if (refer.length) return window.require(refer);
465
+ if (refer.length) return r1(refer);
465
466
  var mod = required[refer];
466
467
  if ("created" in mod) return mod.created;
467
468
  var c = mod.created = createModule(mod, mod.args || [], mod.argNames, prebuilds);
468
469
  return c;
469
470
  };
470
- for (let k in window.require) r[k] = window.require[k];
471
+ for (let k in r1) r[k] = r1[k];
471
472
  return r;
472
473
  }
473
474
  if (argName === "define") return window[argName] || function (m_name, requires, exec) {
@@ -1,5 +1,5 @@
1
1
  var string = function (a) {
2
- if (/^#|\s#|\:(\s|$)|[\[\]\{\}\'\",\r\n\u2028\u2029]/i.test(a)) {
2
+ if (/^#|\s#|\:(\s|$)|[\[\]\{\}\'\"@,\r\n\u2028\u2029]/i.test(a)) {
3
3
  a = strings.encode(a, '"', false);
4
4
  }
5
5
  return a;
@@ -3,20 +3,21 @@
3
3
  * 占用onload onerror complete then 共4个属性
4
4
  * @param {Element|Object|any} image;
5
5
  */
6
- function awaitable(image) {
6
+ function awaitable(image, seeker) {
7
7
  if (image.complete || image.then) return image;
8
8
  var oks = [];
9
9
  var ohs = [];
10
10
  var resolved = false,
11
11
  errored = false,
12
12
  error = null;
13
+ var result = image;
13
14
  var fire = function () {
14
15
  if (resolved || errored) {
15
16
  var _oks = oks.splice(0, oks.length);
16
17
  var _ohs = ohs.splice(0, ohs.length);
17
18
  if (errored) for (var o of _ohs) o(error);
18
19
  delete image.then;
19
- if (resolved) for (var o of _oks) o(image);
20
+ if (resolved) for (var o of _oks) o(result);
20
21
  image.then = then;
21
22
  }
22
23
  };
@@ -28,6 +29,9 @@ function awaitable(image) {
28
29
  image.onload = function () {
29
30
  if (resolved || errored) return;
30
31
  resolved = true;
32
+ if (isHandled(seeker)) {
33
+ result = seek(image, seeker);
34
+ }
31
35
  if (!image.complete) image.complete = true;
32
36
  fire();
33
37
  };
@@ -47,7 +47,8 @@ function encodeStructure(array) {
47
47
  body
48
48
  };
49
49
  }
50
- const pagePathName = location.pathname;
50
+ var { location, navigator, window, document } = this;
51
+ const pagePathName = location ? location.pathname : '';
51
52
  const dataSourceMap = {};
52
53
  const sourceDataId = 'datasource' + pagePathName;
53
54
  const userPrefix = ';';
@@ -318,7 +319,7 @@ function parseConfig(api) {
318
319
  required
319
320
  };
320
321
  }
321
- var isWorseIE = /msie\s+[2-9]/i.test(navigator.userAgent);
322
+ var isWorseIE = navigator && /msie\s+[2-9]/i.test(navigator.userAgent);
322
323
  var parseData = function (sourceText) {
323
324
  if (/^\s*<[^\s\'\"\`]/i.test(sourceText)) {
324
325
  if (!isWorseIE && window.DOMParser) {
@@ -326,6 +327,7 @@ var parseData = function (sourceText) {
326
327
  return new window.DOMParser().parseFromString(sourceText, "text/html");
327
328
  } catch (e) { }
328
329
  }
330
+ if (!document) throw new Error("当前环境不支持处理xml数据!");
329
331
  // XML 格式
330
332
  var { implementation } = document;
331
333
  if (implementation.createHTMLDocument) var doc = implementation.createHTMLDocument("");
@@ -862,21 +864,21 @@ var data = {
862
864
  },
863
865
  fromApi(api, params, parse) {
864
866
  var p = privates.fromApi(api, params);
865
- p.id = api.id;
867
+ if (isEmpty(params)) p.id = api.id;
866
868
  return this.createResponse(p, parse);
867
869
  },
868
870
  postURL(url, data, parse) {
869
871
  var p = privates.loadIgnoreConfig("post", url, data);
870
- p.id = "post " + url;
872
+ p.id = url;
871
873
  return this.createResponse(p, parse);
872
874
  },
873
875
  fromURL(url, parse) {
874
876
  var p = privates.loadIgnoreConfig('get', url);
875
- p.id = "get " + url;
877
+ p.id = url;
876
878
  return this.createResponse(p, parse);
877
879
  },
878
880
  createResponse(p, parse) {
879
- var id = parse instanceof Function ? getInstanceId() : 0;
881
+ var id = !p.id || parse instanceof Function ? getInstanceId() : 0;
880
882
  if (id) this.removeInstance(id);
881
883
  var pid = p.id;
882
884
  var response = this.getInstance(id || pid);
@@ -886,8 +888,8 @@ var data = {
886
888
  response.loading_promise = p;
887
889
  p = p.then((data) => {
888
890
  response.loading = null;
891
+ if (parse instanceof Function) data = parse(data);
889
892
  if (id) {
890
- data = parse(data);
891
893
  this.setInstance(id, data, false);
892
894
  this.removeInstance(id);
893
895
  } else {
@@ -910,7 +912,7 @@ var data = {
910
912
  p.loading = response.loading = p.loading;
911
913
  return p;
912
914
  }, oncatch);
913
- p.id = sid;
915
+ if (!isEmpty(params)) p.id = sid;
914
916
  var response = this.createResponse(p, parse);
915
917
  return response;
916
918
  },
@@ -0,0 +1,48 @@
1
+ 用于简化网络请求的封装。在浏览器环境中正常可用,nodejs环境下目前仅部分功能可用,且与浏览器有出入。
2
+
3
+ ## 配置
4
+
5
+ 在nodejs环境中暂不能从xml数据中查询子节点的数据,传入的选择器将干扰最终得到的数据
6
+ ```javascript
7
+ // 请求名与请求方法、请求路径的映射关系,双层结构
8
+ // 每个请求名将生成一个接口对象(apiObj)
9
+ // 基础路径 头信息?:
10
+ // 请求的标识1(requestId): 方法1 路径1
11
+ // 请求的标识2(requestId): 方法2 路径2
12
+ // 请求的标识3(requestId): 方法3 路径2
13
+ data.setConfig(requestMap)
14
+ // 在浏览器环境中可传入相对路径,nodejs环境中暂未测试
15
+ data.loadConfig(configUrl)
16
+ ```
17
+ * 前边两个方法都是把配置加载到全局,下面的方法将生成一个新的请求工具,但生成的功能只有请求网络的功能,返回结果不会包装成周期存储的实例
18
+
19
+ ```javascript
20
+ data.enrich(requestMap);
21
+ data.enrich(configUrl);
22
+ ```
23
+
24
+ ## 请求网络
25
+ * 不使用`await`时返回结果是周期存储的数据实例,网络请求后会用返回的数据填充这个实例。
26
+ * 使用`await`时结果是返回的数据。
27
+ ```javascript
28
+ data.fromURL(url)
29
+ data.postURL(url,params)
30
+ data.fromApi(apiObj)
31
+ data.from(自动识别参数类型)
32
+ // 以上几个方法均可以用 await 等待请求的结果
33
+ await data.from(...);
34
+ ```
35
+
36
+ ## 周期存储
37
+
38
+ 当sessionStorage和localStorage可用时,可将数据的生命周期延长
39
+ 如果rememberWithStorage传入false,不延长
40
+ 否则,如果!!rememberWithStorage为false,只存储到sessionStorage
41
+ 否则,即!!rememberWithStorage为true,存储到localStorage
42
+ * 在nodejs环境中记忆周期未做延长,程序退出即消失
43
+ ```javascript
44
+ var instance1 = data.getInstance(instanceId);
45
+ data.setInstance(instanceId,obj2,rememberWithStorage?);
46
+ obj2的数据将同步到instance1
47
+ 这两个方法可以在不同作用域中同步数据,也可用于页面或组件传参
48
+ ```
@@ -0,0 +1,12 @@
1
+ data.setConfig({
2
+ 'http://baidu.com/ a=`1&b=c': {
3
+ 'baidu': 'get .'
4
+ }
5
+ });
6
+
7
+ var baiduapi = await data.getApi("baidu");
8
+ assert(baiduapi.base, "http://baidu.com/")
9
+ assert(baiduapi.id, "baidu")
10
+ assert(baiduapi.headers.a, "`1")
11
+ assert(baiduapi.headers.b, "c")
12
+ assert(baiduapi.method, "get")
@@ -1,5 +1,10 @@
1
1
 
2
2
  var strings = require("./strings");
3
+ var decode = strings.decode;
4
+ var decodeString = function (str) {
5
+ if (/^[^"']|^""[\s\S]+/.test(str)) return str.replace(/""/g, '"');
6
+ return decode(str);
7
+ };
3
8
  var eval2 = function (data) {
4
9
  if (typeof data === 'string') data = data.replace(/(\r\n|\r|\n)$/, '');
5
10
  if (!data) return null;
@@ -10,7 +15,7 @@ var eval2 = function (data) {
10
15
  /^[\+\-]?(\d+|\d*\.\d+|\d+\.)(e[\-\+]?\d+)?$/i.test(data) ||
11
16
  /^(0b[01]+|0x[\da-f]+|0o[0-7]+)$/i.test(data)
12
17
  ) data = parseNumber(data);
13
- else data = strings.decode(data);
18
+ else data = decodeString(data);
14
19
  return data;
15
20
  };
16
21
  var scan = function (text) {
@@ -23,7 +28,7 @@ var scan = function (text) {
23
28
  var jsonlikes = [];
24
29
  var push = function (value) {
25
30
  if (data && prop === undefined && jsonlikes[jsonlikes.length - 1] === '{') {
26
- prop = strings.decode(data);
31
+ prop = decodeString(data);
27
32
  data = '';
28
33
  }
29
34
  if (!value) {
@@ -58,9 +63,10 @@ var scan = function (text) {
58
63
  };
59
64
  while (rows.length) {
60
65
  var row = rows.shift();
61
-
66
+ isjson = false;
62
67
  if (/^['"]$/.test(rowtype)) {
63
- if (jsonlikes.length) {
68
+ var isjson = !!jsonlikes.length || !data
69
+ if (isjson) {
64
70
  var reg = new RegExp(/\\[\s\S]|/.source + rowtype, 'g');
65
71
  var index = -1;
66
72
  do {
@@ -78,6 +84,7 @@ var scan = function (text) {
78
84
  continue;
79
85
  }
80
86
  data += row.slice(0, index + +!!jsonlikes.length);
87
+ if (index == 0 && !data) data = rowtype + rowtype;
81
88
  row = row.slice(index + 1);
82
89
  if (!row) push();
83
90
  else unshift(spacesize, row);
@@ -160,7 +167,7 @@ var scan = function (text) {
160
167
  var pre = row[0];
161
168
  row = row.slice(1);
162
169
  if (pre === ":") {
163
- prop = strings.decode(data);
170
+ prop = decodeString(data);
164
171
  data = '';
165
172
  }
166
173
  else {
@@ -208,7 +215,7 @@ var scan = function (text) {
208
215
  if (value) {
209
216
  unshift(spacesize + 1, value);
210
217
  }
211
- prop = strings.decode(prop);
218
+ prop = decodeString(prop);
212
219
  span = spacesize;
213
220
  parents = parents.slice(0, span + 1);
214
221
  continue;
@@ -2,7 +2,6 @@ var fs = require("fs");
2
2
  var path = require("path");
3
3
  var fullpath = path.join(__dirname, "../../.github/workflows/npmpublish.yml");
4
4
  var text = fs.readFileSync(fullpath).toString();
5
- var parseYML = require("./parseYML");
6
5
  var test = function (source, expect) {
7
6
  var result = parseYML(source);
8
7
  var same = assert(result, expect);
@@ -74,3 +73,8 @@ test(`
74
73
  c: d
75
74
  "a:": b
76
75
  `, { c: "d", "a:": "b" });
76
+
77
+ test(`"@"`, "@")
78
+ test(`"\\"@\\""`, "\"@\"")
79
+ test(`@""@""`, "@\"@\"")
80
+ test(`""@""`, "\"@\"")