@anfenn/dync 1.0.15 → 1.0.16

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/index.cjs CHANGED
@@ -63,8 +63,33 @@ var ApiError = class extends Error {
63
63
  this.cause = cause;
64
64
  }
65
65
  };
66
+ var SyncAction = /* @__PURE__ */ ((SyncAction2) => {
67
+ SyncAction2["Create"] = "create";
68
+ SyncAction2["Update"] = "update";
69
+ SyncAction2["Remove"] = "remove";
70
+ return SyncAction2;
71
+ })(SyncAction || {});
72
+
73
+ // src/createLocalId.ts
74
+ function createLocalId() {
75
+ if (typeof globalThis.crypto?.randomUUID === "function") {
76
+ return globalThis.crypto.randomUUID();
77
+ }
78
+ throw new Error("createLocalId(): crypto.randomUUID is not available");
79
+ }
80
+
81
+ // src/helpers.ts
82
+ function parseApiError(error) {
83
+ if (error instanceof ApiError) {
84
+ return error;
85
+ }
86
+ if (typeof error === "string") {
87
+ return new ApiError(error, false);
88
+ }
89
+ return new ApiError(error.message, isNetworkError(error), error);
90
+ }
66
91
  function isNetworkError(error) {
67
- const message = error.message.toLowerCase();
92
+ const message = error.message?.toLowerCase() ?? "";
68
93
  const name = error.name;
69
94
  if (name === "TypeError" && (message.includes("failed to fetch") || message.includes("network request failed"))) {
70
95
  return true;
@@ -84,32 +109,6 @@ function isNetworkError(error) {
84
109
  }
85
110
  return false;
86
111
  }
87
- function parseApiError(error) {
88
- if (error instanceof ApiError) {
89
- return error;
90
- }
91
- if (error instanceof Error) {
92
- return new ApiError(error.message, isNetworkError(error), error);
93
- }
94
- const message = String(error);
95
- return new ApiError(message, false);
96
- }
97
- var SyncAction = /* @__PURE__ */ ((SyncAction2) => {
98
- SyncAction2["Create"] = "create";
99
- SyncAction2["Update"] = "update";
100
- SyncAction2["Remove"] = "remove";
101
- return SyncAction2;
102
- })(SyncAction || {});
103
-
104
- // src/createLocalId.ts
105
- function createLocalId() {
106
- if (typeof globalThis.crypto?.randomUUID === "function") {
107
- return globalThis.crypto.randomUUID();
108
- }
109
- throw new Error("createLocalId(): crypto.randomUUID is not available");
110
- }
111
-
112
- // src/helpers.ts
113
112
  function sleep(ms, signal) {
114
113
  return new Promise((resolve) => {
115
114
  if (signal?.aborted) {