@heycar/heycars-map 2.0.0-switchMap7 → 2.0.0-switchMap9

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.
@@ -13,9 +13,14 @@ function assertLatitudeLongitudeLiteral(value) {
13
13
  throw Error(`MyError: expect type LatitudeLongitudeLiteral, actual is: ${JSON.stringify(value)}`);
14
14
  }
15
15
  function assertSnappedPoint(value) {
16
- if (value)
16
+ const error = Error(`MyError: expect type SnappedPoint, actual is: ${JSON.stringify(value)}`);
17
+ if (!value)
18
+ throw error;
19
+ try {
17
20
  assertLatitudeLongitudeLiteral(value.location);
18
- throw Error(`MyError: expect type SnappedPoint, actual is: ${JSON.stringify(value)}`);
21
+ } catch {
22
+ throw error;
23
+ }
19
24
  }
20
25
  function assertSnapToRoadsResponse(value) {
21
26
  const error = Error(
@@ -5,10 +5,10 @@ var __publicField = (obj, key, value) => {
5
5
  return value;
6
6
  };
7
7
  import { sleep } from "../utils/helper.js";
8
- const PING_AMAP_URL = "https://webapi.amap.com/favicon.ico";
8
+ const PING_AMAP_URL = "https://webapi.amap.com/maps";
9
9
  const PING_AMAP_TIMEOUT = 5e3;
10
10
  const PING_AMAP_INTERVAL = 5e3;
11
- const PING_GMAP_URL = "https://maps.googleapis.com/";
11
+ const PING_GMAP_URL = "https://maps.googleapis.com/maps/api/mapsjs/gen_204";
12
12
  const PING_GMAP_TIMEOUT = 5e3;
13
13
  const PING_GMAP_INTERVAL = 5e3;
14
14
  const noop = () => {
@@ -20,14 +20,16 @@ const toUncachableUrl = (url, label = "") => {
20
20
  return parsedUrl.toString();
21
21
  };
22
22
  class PingConnection {
23
- constructor({ timeout, url }) {
23
+ constructor({ timeout, url, fetchOption }) {
24
24
  __publicField(this, "timeout");
25
25
  __publicField(this, "url");
26
+ __publicField(this, "fetchOption");
26
27
  __publicField(this, "status", "pending");
27
28
  __publicField(this, "listeners", /* @__PURE__ */ new Set());
28
29
  __publicField(this, "updatingPromise");
29
30
  this.timeout = timeout;
30
31
  this.url = url;
32
+ this.fetchOption = fetchOption;
31
33
  }
32
34
  // 只有订阅了 onChange 事件,listen 才会更新状态
33
35
  async listen(interval) {
@@ -38,10 +40,10 @@ class PingConnection {
38
40
  }
39
41
  }
40
42
  async updateStatus() {
41
- const { url, timeout } = this;
43
+ const { url, timeout, fetchOption } = this;
42
44
  if (this.updatingPromise)
43
45
  return this.updatingPromise;
44
- return this.updatingPromise = this.check(url, timeout).then((status) => {
46
+ return this.updatingPromise = this.check(url, timeout, fetchOption).then((status) => {
45
47
  this.status = status;
46
48
  this.updatingPromise = void 0;
47
49
  for (const handler of this.listeners) {
@@ -54,13 +56,12 @@ class PingConnection {
54
56
  return status;
55
57
  });
56
58
  }
57
- check(url, timeout) {
59
+ check(url, timeout, fetchOption) {
58
60
  const controller = new AbortController();
59
61
  const timer = setTimeout(() => controller.abort(), timeout);
60
62
  return fetch(toUncachableUrl(url, timeout.toString()), {
61
63
  signal: controller.signal,
62
- method: "HEAD",
63
- mode: "no-cors"
64
+ ...fetchOption
64
65
  }).then(() => "connected").catch(() => "unconnected").finally(() => clearTimeout(timer));
65
66
  }
66
67
  onChange(handler) {
@@ -75,7 +76,10 @@ class PingConnection {
75
76
  }
76
77
  const pingAmapConnection = new PingConnection({
77
78
  timeout: PING_AMAP_TIMEOUT,
78
- url: PING_AMAP_URL
79
+ url: PING_AMAP_URL,
80
+ fetchOption: {
81
+ method: "HEAD"
82
+ }
79
83
  });
80
84
  const pingGmapConnection = new PingConnection({
81
85
  timeout: PING_GMAP_TIMEOUT,
@@ -1,6 +1,6 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.0.0-switchMap7";
3
+ const pkgVersion = "2.0.0-switchMap9";
4
4
  const isEnableLog = (name) => {
5
5
  const searchParam = new URLSearchParams(location.search);
6
6
  return searchParam.has(`log-${name}`);
@@ -13,9 +13,14 @@ function assertLatitudeLongitudeLiteral(value) {
13
13
  throw Error(`MyError: expect type LatitudeLongitudeLiteral, actual is: ${JSON.stringify(value)}`);
14
14
  }
15
15
  function assertSnappedPoint(value) {
16
- if (value)
16
+ const error = Error(`MyError: expect type SnappedPoint, actual is: ${JSON.stringify(value)}`);
17
+ if (!value)
18
+ throw error;
19
+ try {
17
20
  assertLatitudeLongitudeLiteral(value.location);
18
- throw Error(`MyError: expect type SnappedPoint, actual is: ${JSON.stringify(value)}`);
21
+ } catch {
22
+ throw error;
23
+ }
19
24
  }
20
25
  function assertSnapToRoadsResponse(value) {
21
26
  const error = Error(
@@ -5,10 +5,10 @@ var __publicField = (obj, key, value) => {
5
5
  return value;
6
6
  };
7
7
  import { sleep } from "../utils/helper.js";
8
- const PING_AMAP_URL = "https://webapi.amap.com/favicon.ico";
8
+ const PING_AMAP_URL = "https://webapi.amap.com/maps";
9
9
  const PING_AMAP_TIMEOUT = 5e3;
10
10
  const PING_AMAP_INTERVAL = 5e3;
11
- const PING_GMAP_URL = "https://maps.googleapis.com/";
11
+ const PING_GMAP_URL = "https://maps.googleapis.com/maps/api/mapsjs/gen_204";
12
12
  const PING_GMAP_TIMEOUT = 5e3;
13
13
  const PING_GMAP_INTERVAL = 5e3;
14
14
  const noop = () => {
@@ -20,14 +20,16 @@ const toUncachableUrl = (url, label = "") => {
20
20
  return parsedUrl.toString();
21
21
  };
22
22
  class PingConnection {
23
- constructor({ timeout, url }) {
23
+ constructor({ timeout, url, fetchOption }) {
24
24
  __publicField(this, "timeout");
25
25
  __publicField(this, "url");
26
+ __publicField(this, "fetchOption");
26
27
  __publicField(this, "status", "pending");
27
28
  __publicField(this, "listeners", /* @__PURE__ */ new Set());
28
29
  __publicField(this, "updatingPromise");
29
30
  this.timeout = timeout;
30
31
  this.url = url;
32
+ this.fetchOption = fetchOption;
31
33
  }
32
34
  // 只有订阅了 onChange 事件,listen 才会更新状态
33
35
  async listen(interval) {
@@ -38,10 +40,10 @@ class PingConnection {
38
40
  }
39
41
  }
40
42
  async updateStatus() {
41
- const { url, timeout } = this;
43
+ const { url, timeout, fetchOption } = this;
42
44
  if (this.updatingPromise)
43
45
  return this.updatingPromise;
44
- return this.updatingPromise = this.check(url, timeout).then((status) => {
46
+ return this.updatingPromise = this.check(url, timeout, fetchOption).then((status) => {
45
47
  this.status = status;
46
48
  this.updatingPromise = void 0;
47
49
  for (const handler of this.listeners) {
@@ -54,13 +56,12 @@ class PingConnection {
54
56
  return status;
55
57
  });
56
58
  }
57
- check(url, timeout) {
59
+ check(url, timeout, fetchOption) {
58
60
  const controller = new AbortController();
59
61
  const timer = setTimeout(() => controller.abort(), timeout);
60
62
  return fetch(toUncachableUrl(url, timeout.toString()), {
61
63
  signal: controller.signal,
62
- method: "HEAD",
63
- mode: "no-cors"
64
+ ...fetchOption
64
65
  }).then(() => "connected").catch(() => "unconnected").finally(() => clearTimeout(timer));
65
66
  }
66
67
  onChange(handler) {
@@ -75,7 +76,10 @@ class PingConnection {
75
76
  }
76
77
  const pingAmapConnection = new PingConnection({
77
78
  timeout: PING_AMAP_TIMEOUT,
78
- url: PING_AMAP_URL
79
+ url: PING_AMAP_URL,
80
+ fetchOption: {
81
+ method: "HEAD"
82
+ }
79
83
  });
80
84
  const pingGmapConnection = new PingConnection({
81
85
  timeout: PING_GMAP_TIMEOUT,
@@ -1,6 +1,6 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.0.0-switchMap7";
3
+ const pkgVersion = "2.0.0-switchMap9";
4
4
  const isEnableLog = (name) => {
5
5
  const searchParam = new URLSearchParams(location.search);
6
6
  return searchParam.has(`log-${name}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "2.0.0-switchMap7",
3
+ "version": "2.0.0-switchMap9",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "checkVersion": "./bin/checkVersion.js",