@art-suite/art-core-ts-communication-status 0.4.2 → 0.6.0

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
@@ -27,8 +27,7 @@ __export(index_exports, {
27
27
  failure: () => failure,
28
28
  getCommunicationStatus: () => getCommunicationStatus,
29
29
  getCommunicationStatusDetails: () => getCommunicationStatusDetails,
30
- getCommunicationStatusFromHttpStatus: () => getCommunicationStatusFromHttpStatus,
31
- getCommunicationStatusFromHttpStatusOrUndefined: () => getCommunicationStatusFromHttpStatusOrUndefined,
30
+ getCommunicationStatusDetailsOrUndefined: () => getCommunicationStatusDetailsOrUndefined,
32
31
  getCommunicationStatusOrUndefined: () => getCommunicationStatusOrUndefined,
33
32
  getHttpStatus: () => getHttpStatus,
34
33
  isAborted: () => isAborted,
@@ -66,37 +65,156 @@ var pending = "pending";
66
65
  var failure = "failure";
67
66
  var timeoutFailure = "timeoutFailure";
68
67
 
68
+ // ../art-core-ts-types/dist/index.js
69
+ var isObject = (v) => v != null && typeof v === "object";
70
+ var isPlainObject = (v) => {
71
+ if (!isObject(v)) return false;
72
+ if (v.constructor === Object) return true;
73
+ const prototype = Object.getPrototypeOf(v);
74
+ if (prototype === null) return true;
75
+ return null == Object.getPrototypeOf(prototype);
76
+ };
77
+ var isFunction = (obj) => typeof obj === "function";
78
+ var exists = (value) => value != null;
79
+
80
+ // ../art-core-ts-comprehensions/dist/index.js
81
+ var isMap = (source) => source instanceof Map;
82
+ var isArrayIterable = (source) => {
83
+ if (typeof source === "string") return false;
84
+ if (isFunction(source)) return false;
85
+ return source != null && source.length >= 0;
86
+ };
87
+ var isOfIterable = (o) => {
88
+ if (typeof o === "string") return false;
89
+ if (isFunction(o)) return false;
90
+ return isFunction(o[Symbol.iterator] || o.next);
91
+ };
92
+ var returnFirstArg = (a) => a;
93
+ var returnSecondArg = (a, b) => b;
94
+ var iterate = (source, body) => {
95
+ if (exists(source))
96
+ if (isArrayIterable(source)) for (let key = 0, { length } = source; key < length; key++) {
97
+ if (body(source[key], key)) break;
98
+ }
99
+ else if (isPlainObject(source)) for (const key in source) {
100
+ if (body(source[key], key)) break;
101
+ }
102
+ else if (isMap(source)) for (const [key, value] of source.entries()) {
103
+ if (body(value, key)) break;
104
+ }
105
+ else if (isOfIterable(source)) {
106
+ let count = 0;
107
+ for (const value of source) {
108
+ if (body(value, count++)) break;
109
+ }
110
+ } else throw new Error(`Unsupported source type: ${typeof source}`);
111
+ };
112
+ var normalizeBody = (withFunction, options) => {
113
+ let { when, stopWhen } = options;
114
+ if (when && stopWhen) {
115
+ return (v, k) => {
116
+ if (stopWhen(v, k)) return true;
117
+ if (when(v, k)) withFunction(v, k);
118
+ return false;
119
+ };
120
+ }
121
+ if (when) {
122
+ return (v, k) => {
123
+ if (when(v, k)) withFunction(v, k);
124
+ return false;
125
+ };
126
+ }
127
+ if (stopWhen) {
128
+ return (v, k) => {
129
+ if (stopWhen(v, k)) return true;
130
+ withFunction(v, k);
131
+ return false;
132
+ };
133
+ }
134
+ return (v, k) => {
135
+ withFunction(v, k);
136
+ return false;
137
+ };
138
+ };
139
+ var normalizeKeyFunction = (source, options) => options.withKey || (isArrayIterable(source) ? returnFirstArg : returnSecondArg);
140
+ var _each = (source, withFunction, options) => {
141
+ iterate(source, normalizeBody(withFunction, options));
142
+ };
143
+ var normalizedObjectIteration = (source, options) => {
144
+ let { into, with: withFunction } = options;
145
+ if (into == null) into = {};
146
+ let withKey = normalizeKeyFunction(source, options);
147
+ _each(source, (v, k) => into[withKey(v, k)] = withFunction(v, k), options);
148
+ return into;
149
+ };
150
+ var isAcceptedComprehensionOptions = (o) => isPlainObject(o);
151
+ var firstNotUndefined = (into, inject, returning) => {
152
+ if (into === void 0) into = inject;
153
+ if (into === void 0) into = returning;
154
+ return into;
155
+ };
156
+ var normalizeIterationParams = (withOrOptions) => {
157
+ if (isAcceptedComprehensionOptions(withOrOptions)) {
158
+ const { with: withFunction, into, inject, returning, ...rest } = withOrOptions;
159
+ return { ...rest, into: firstNotUndefined(into, inject, returning), with: withFunction ?? returnFirstArg };
160
+ }
161
+ if (isFunction(withOrOptions)) {
162
+ return { with: withOrOptions };
163
+ }
164
+ return { with: returnFirstArg };
165
+ };
166
+ var invokeNormalizedIteration = (normalizedIterationFunction, source, withOrOptions) => normalizedIterationFunction(source, normalizeIterationParams(withOrOptions));
167
+ var object = ((source, withOrOptions) => invokeNormalizedIteration(normalizedObjectIteration, source, withOrOptions));
168
+
69
169
  // src/CommunicationStatusTypes.ts
70
- var communicationStatuses = {
170
+ var communicationStatusesPartials = {
171
+ // HTTP Success Statuses
71
172
  success: { httpStatus: 200 },
173
+ // HTTP Failure Statuses
72
174
  missing: { httpStatus: 404, failure: true },
73
175
  clientFailure: { httpStatus: 400, clientFailure: true, failure: true },
74
176
  clientFailureNotAuthorized: { httpStatus: 403, clientFailure: true, failure: true },
75
177
  serverFailure: { httpStatus: 500, failure: true, serverFailure: true },
76
- networkFailure: { failure: true },
77
- aborted: { failure: true },
78
- pending: {},
79
178
  failure: { httpStatus: 500, failure: true },
80
- timeoutFailure: { failure: true }
179
+ // Non-HTTP Statuses
180
+ pending: { httpStatus: void 0 },
181
+ networkFailure: { httpStatus: void 0, failure: true },
182
+ aborted: { httpStatus: void 0, failure: true },
183
+ timeoutFailure: { httpStatus: void 0, failure: true }
81
184
  };
185
+ var communicationStatuses = object(communicationStatusesPartials, (details, status) => ({
186
+ ...details,
187
+ failure: !!details.failure,
188
+ clientFailure: !!details.clientFailure,
189
+ serverFailure: !!details.serverFailure,
190
+ status,
191
+ communicationStatus: status,
192
+ message: details.httpStatus ? `${status} (${details.httpStatus})` : status
193
+ }));
82
194
  var statusRegex = new RegExp(`^(${Object.keys(communicationStatuses).join("|")})$`);
83
195
 
84
196
  // src/CommunicationStatusTests.ts
85
- var isSuccess = (status) => status === success;
86
- var isFailure = (status) => !!communicationStatuses[status]?.failure;
87
- var isClientFailure = (status) => !!communicationStatuses[status]?.clientFailure;
88
- var isServerFailure = (status) => !!communicationStatuses[status]?.serverFailure;
89
- var isNetworkFailure = (status) => status === networkFailure;
90
- var isNonClientFailure = (status) => isFailure(status) && !isClientFailure(status);
91
- var isClientFailureNotAuthorized = (status) => status === clientFailureNotAuthorized;
92
- var isAborted = (status) => status === aborted;
93
- var isMissing = (status) => status === missing;
94
- var isPending = (status) => status === pending;
95
- var isTimeout = (status) => status === timeoutFailure;
96
- var isRetryableFailure = (status) => isNetworkFailure(status) || isTimeout(status) || isAborted(status);
197
+ var isSuccess = (status) => getCommunicationStatus(status) === success;
198
+ var isFailure = (status) => getCommunicationStatusDetails(status).failure;
199
+ var isClientFailure = (status) => getCommunicationStatusDetails(status).clientFailure;
200
+ var isServerFailure = (status) => getCommunicationStatusDetails(status).serverFailure;
201
+ var isNetworkFailure = (status) => getCommunicationStatus(status) === networkFailure;
202
+ var isNonClientFailure = (status) => {
203
+ const details = getCommunicationStatusDetails(status);
204
+ return details.failure && !details.clientFailure;
205
+ };
206
+ var isClientFailureNotAuthorized = (status) => getCommunicationStatus(status) === clientFailureNotAuthorized;
207
+ var isAborted = (status) => getCommunicationStatus(status) === aborted;
208
+ var isMissing = (status) => getCommunicationStatus(status) === missing;
209
+ var isPending = (status) => getCommunicationStatus(status) === pending;
210
+ var isTimeout = (status) => getCommunicationStatus(status) === timeoutFailure;
211
+ var isRetryableFailure = (status) => {
212
+ const { status: communicationStatus, failure: failure2 } = getCommunicationStatusDetails(status);
213
+ return failure2 && (communicationStatus === networkFailure || communicationStatus === timeoutFailure || communicationStatus === aborted);
214
+ };
97
215
  var isStatusValid = (status) => statusRegex.test(status);
98
216
 
99
- // src/CommunicationStatus.ts
217
+ // src/CommunicationStatusConversions.ts
100
218
  var getCommunicationStatusFromHttpStatusOrUndefined = (httpStatus) => {
101
219
  switch (Math.floor(httpStatus / 100)) {
102
220
  case 2:
@@ -143,15 +261,6 @@ var getCommunicationStatusFromHttpStatus = (httpStatus) => {
143
261
  }
144
262
  return status;
145
263
  };
146
- var getCommunicationStatusDetails = (httpStatus) => {
147
- if (!httpStatus) return { status: networkFailure, message: "network failure" };
148
- const status = getCommunicationStatusFromHttpStatus(httpStatus);
149
- return {
150
- status,
151
- httpStatus,
152
- message: `${status} (${httpStatus})`
153
- };
154
- };
155
264
  var getCommunicationStatusOrUndefined = (status) => {
156
265
  if (status == null) return void 0;
157
266
  if (typeof status === "string") {
@@ -177,10 +286,25 @@ var getCommunicationStatus = (status) => {
177
286
  return communicationStatus;
178
287
  };
179
288
  var getHttpStatus = (status) => {
180
- const httpStatus = communicationStatuses[status]?.httpStatus;
181
- if (!httpStatus) throw new Error(`There is no valid HttpStatus for ${status}.`);
289
+ if (status == null) return void 0;
290
+ const communicationStatus = getCommunicationStatus(status);
291
+ const httpStatus = communicationStatuses[communicationStatus].httpStatus;
292
+ if (httpStatus == null) {
293
+ throw new Error(`There is no valid HttpStatus for ${status}.`);
294
+ }
182
295
  return httpStatus;
183
296
  };
297
+ var getCommunicationStatusDetails = (status) => {
298
+ if (status == null) return void 0;
299
+ const communicationStatus = getCommunicationStatus(status);
300
+ return communicationStatuses[communicationStatus];
301
+ };
302
+ var getCommunicationStatusDetailsOrUndefined = (status) => {
303
+ if (status == null) return void 0;
304
+ const communicationStatus = getCommunicationStatusOrUndefined(status);
305
+ if (communicationStatus == null) return void 0;
306
+ return communicationStatuses[communicationStatus];
307
+ };
184
308
  // Annotate the CommonJS export names for ESM import in node:
185
309
  0 && (module.exports = {
186
310
  aborted,
@@ -190,8 +314,7 @@ var getHttpStatus = (status) => {
190
314
  failure,
191
315
  getCommunicationStatus,
192
316
  getCommunicationStatusDetails,
193
- getCommunicationStatusFromHttpStatus,
194
- getCommunicationStatusFromHttpStatusOrUndefined,
317
+ getCommunicationStatusDetailsOrUndefined,
195
318
  getCommunicationStatusOrUndefined,
196
319
  getHttpStatus,
197
320
  isAborted,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/CommunicationStatusConsts.ts","../src/CommunicationStatusTypes.ts","../src/CommunicationStatusTests.ts","../src/CommunicationStatus.ts"],"sourcesContent":["export * from \"./CommunicationStatus\";\nexport * from \"./CommunicationStatusConsts\";\nexport * from \"./CommunicationStatusTests\";\nexport * from \"./CommunicationStatusTypes\";\n","// Export status constants\nimport type { CommunicationStatus } from './CommunicationStatusTypes'\n\n/**\n * HTTP 2xx responses\n *\n * Client Can Automatically:\n * - Process the successful response\n * - Update UI to reflect success\n *\n * Client Developer Can:\n * - Handle the successful response data\n */\nexport const success: CommunicationStatus = \"success\"\n\n/**\n * Resource not found\n *\n * HTTP Status Codes Covered:\n * - 404: Not Found\n *\n * Client Can Automatically:\n * - notify the user that the resource was not found\n * - prompt the user to request a different resource\n *\n * Client Developer Can:\n * - fix the bad resource paths\n */\nexport const missing: CommunicationStatus = \"missing\"\n\n/**\n * Client-side errors; i.e. the client needs to change the request somehow to succeed\n *\n * HTTP Status Codes Covered:\n * - 400: Bad Request\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 409: Conflict\n * - 422: Unprocessable Entity\n *\n * Client Can Automatically:\n * - Notify the user that the client is experiencing issues\n * - Prompt user to correct invalid input\n *\n * Client Developer Can:\n * - use isClientFailureNotAuthorized to check for 401/403/407/451\n * - fix the request to avoid the 4xx error\n * - validate input before sending requests\n */\nexport const clientFailure: CommunicationStatus = \"clientFailure\"\n\n/**\n * Unauthorized requests; i.e. client needs to change the credentials (or the grants for the current credentials) to succeed\n *\n * HTTP Status Codes Covered:\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 451: Unavailable For Legal Reasons\n *\n * Client Can Automatically:\n * - refresh the request token\n * - prompt the user to re-login\n * - ask the user to contact the administrator for access\n *\n * Client and Server Developer Can:\n * - fix authorization / authentication bugs\n */\nexport const clientFailureNotAuthorized: CommunicationStatus = \"clientFailureNotAuthorized\"\n\n/**\n * Server-side errors; i.e. internal server errors\n *\n * HTTP Status Codes Covered:\n * - 500: Internal Server Error\n * - 502: Bad Gateway\n * - 503: Service Unavailable\n * - 504: Gateway Timeout\n *\n * Client Can Automatically:\n * - Ask the user to try again later\n * - Notify the user that the server is experiencing issues\n * - Implement automatic retry with backoff\n *\n * Client Developer: (probably) can't fix\n *\n * Server Developer Can:\n * - fix the server to avoid the 5xx error\n * - fix server infrastructure to avoid the 5xx error\n */\nexport const serverFailure: CommunicationStatus = \"serverFailure\"\n\n/**\n * Request fails due to network connectivity issues\n *\n * HTTP Status Codes Covered: NONE (server was not reachable)\n *\n * Client Can Automatically:\n * - Prompt the user to fix the network connection\n * - Retry the request when network is available\n * - Monitor network status for recovery\n *\n * Client Developer Can:\n * - fix bad network constants (like address, ports, etc.)\n * - implement offline-first capabilities\n */\nexport const networkFailure: CommunicationStatus = \"networkFailure\"\n\n/**\n * Request was cancelled by client\n *\n * Client Can Automatically:\n * - notify the user that the request was cancelled\n * - prompt the user to try again\n * - cleanup any pending state\n *\n * Client Developer Can:\n * - fix the client to not abort the request unnecessarily\n * - implement proper cleanup on abort\n */\nexport const aborted: CommunicationStatus = \"aborted\"\n\n/**\n * Request is in progress\n *\n * Client Can Automatically:\n * - notify the user that the request is in progress\n * - show the user progress (if available)\n * - allow the user to cancel the request\n *\n * Client Developer Can:\n * - if \"pending\" was not expected, maybe the client needs to `wait` for the request to complete?\n * - implement proper loading states\n */\nexport const pending: CommunicationStatus = \"pending\"\n\n/**\n * Any error response (HTTP 4xx/5xx) or network/abort failures\n *\n * HTTP Status Codes Covered:\n * - 4xx: Client-side errors (except 404)\n * - 5xx: Server-side errors\n * - Network failures\n * - Abort failures\n *\n * Client Can Automatically:\n * - Show appropriate error message to user\n * - Implement generic error handling\n * - Log errors for debugging\n *\n * Client Developer Can:\n * - Use more specific is* functions for targeted error handling\n * - Implement proper error recovery strategies\n */\nexport const failure: CommunicationStatus = \"failure\"\n\n/**\n * Request timed out\n *\n * Client Can Automatically:\n * - notify the user that the request timed out\n * - try again (automatically or via user action)\n *\n * Client Developer Can:\n * - fix the client to not timeoutFailure the request\n * - implement proper timeoutFailure handling\n */\nexport const timeoutFailure: CommunicationStatus = \"timeoutFailure\"\n","interface CommunicationStatusInfo {\n httpStatus?: number\n failure?: boolean\n clientFailure?: boolean\n serverFailure?: boolean\n}\n\nexport const communicationStatuses: Record<string, CommunicationStatusInfo> = {\n success: { httpStatus: 200 },\n missing: { httpStatus: 404, failure: true },\n clientFailure: { httpStatus: 400, clientFailure: true, failure: true },\n clientFailureNotAuthorized: { httpStatus: 403, clientFailure: true, failure: true },\n serverFailure: { httpStatus: 500, failure: true, serverFailure: true },\n networkFailure: { failure: true },\n aborted: { failure: true },\n pending: {},\n failure: { httpStatus: 500, failure: true },\n timeoutFailure: { failure: true }\n}\n\nexport type CommunicationStatuses = typeof communicationStatuses\nexport type CommunicationStatus = keyof CommunicationStatuses\n\n/**\n * RegEx returns true for all valid communication statuses\n */\nexport const statusRegex = new RegExp(`^(${Object.keys(communicationStatuses).join('|')})$`)\n\nexport interface CommunicationStatusDetails {\n status: CommunicationStatus\n httpStatus?: number\n message: string\n}\n","import { communicationStatuses, CommunicationStatus, statusRegex } from './CommunicationStatusTypes'\nimport { success, missing, clientFailure, clientFailureNotAuthorized, serverFailure, networkFailure, aborted, pending, timeoutFailure } from './CommunicationStatusConsts'\n\n// Core status check functions\n/** Returns true for HTTP 2xx responses */\nexport const isSuccess = (status: CommunicationStatus) => status === success\n\n/**\n * Returns true for any error response (HTTP 4xx/5xx) or network/abort failures\n *\n * HTTP Status Codes Covered:\n * - 4xx: Client-side errors (except 404)\n * - 5xx: Server-side errors\n * - Network failures\n * - Abort failures\n *\n * Client Can:\n * - Use a different is* function for more specific checks\n */\nexport const isFailure = (status: CommunicationStatus) => !!communicationStatuses[status]?.failure\n\n/**\n * Returns true for client-side errors\n *\n * HTTP Status Codes Covered:\n * - 400: Bad Request\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 409: Conflict\n * - 422: Unprocessable Entity\n *\n * Client Can Automatically:\n * - Notify the user that the client is experiencing issues\n *\n * Client Developer Can:\n * - use isClientFailureNotAuthorized to check for 401/403/407/451\n * - fix the request to avoid the 4xx error\n*/\nexport const isClientFailure = (status: CommunicationStatus) => !!communicationStatuses[status]?.clientFailure\n\n/**\n * Returns true for server-side errors\n *\n * HTTP Status Codes Covered:\n * - 500: Internal Server Error\n * - 502: Bad Gateway\n * - 503: Service Unavailable\n * - 504: Gateway Timeout\n *\n * Client Can Automatically:\n * - Ask the user to try again later\n * - Notify the user that the server is experiencing issues\n *\n * Client Developer: (probably) can't fix\n *\n * Server Developer Can:\n * - fix the server to avoid the 5xx error\n * - fix server infrastructure to avoid the 5xx error (e.g. Bad Gateway, Service Unavailable, Gateway Timeout)\n*/\nexport const isServerFailure = (status: CommunicationStatus) => !!communicationStatuses[status]?.serverFailure\n\n/**\n * Returns true when request fails due to network connectivity issues\n *\n * HTTP Status Codes Covered: NONE (server was not reachable)\n *\n * Client Can Automatically:\n * - Prompt the user to fix the network connection\n * - Retry the request\n *\n * Client Developer Can:\n * - fix bad network constants (like address, ports, etc.)\n*/\nexport const isNetworkFailure = (status: CommunicationStatus) => status === networkFailure\n\n/** Returns true for server errors, network failures and aborted requests; i.e. the client did nothing wrong (as far as we can tell); client can ask the user to do something OR retry the request */\nexport const isNonClientFailure = (status: CommunicationStatus) => isFailure(status) && !isClientFailure(status)\n\n/**\n * Returns true for unauthorized requests (not authenticated or not authorized)\n *\n * HTTP Status Codes Covered:\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 451: Unavailable For Legal Reasons\n * - 511: Network Authentication Required\n *\n * Client Can Automatically:\n * - refresh the request token\n * - prompt the user to re-login\n * - ask the user to contact the administrator for access\n *\n * Client and Server Developer Can:\n * - fix authorization / authentication bugs\n */\nexport const isClientFailureNotAuthorized = (status: CommunicationStatus) => status === clientFailureNotAuthorized\n\n/**\n * Returns true when request was cancelled by client\n *\n * Client Can Automatically:\n * - notify the user that the request was cancelled\n * - prompt the user to try again\n *\n * Client Developer Can:\n * - fix the client to not abort the request\n */\nexport const isAborted = (status: CommunicationStatus) => status === aborted\n\n/**\n * Returns true when resource not found / not available\n *\n * HTTP Status Codes Covered:\n * - 404: Not Found\n * - 501: Not Implemented\n *\n * Client Can Automatically:\n * - notify the user that the resource was not found\n * - prompt the user to request a different resource\n *\n * Client Developer Can:\n * - fix the bad resource paths\n */\nexport const isMissing = (status: CommunicationStatus) => status === missing\n\n/**\n * Returns true while request is in progress\n *\n * Client Can Automatically:\n * - notify the user that the request is in progress\n * - show the user progress (if available)\n * - allow the user to cancel the request (trigging an \"aborted\" communication status)\n *\n * Client Developer Can:\n * - if \"pending\" was not expected, maybe the client needs to `wait` for the request to complete?\n */\nexport const isPending = (status: CommunicationStatus) => status === pending\n\n/**\n * Returns true if the request timed out\n *\n * Client Can Automatically:\n * - notify the user that the request timed out\n * - try again (automatically or via user action)\n *\n * Client Developer Can:\n * - extend the timeoutFailure duration\n *\n * Server Developer Can:\n * - improve server performance and reliability\n */\nexport const isTimeout = (status: CommunicationStatus) => status === timeoutFailure\n\n/**\n * Returns true if client can safely retry the request\n *\n * A a clearly-retryable failure:\n *\n * - network failure\n * - timeoutFailure\n * - aborted\n *\n * Note: some serverFailures will succeed on retry, but HTTP doesn't return clear indications which ones. To be safe, the client should not retry serverFailures indiscriminately.\n *\n * Client and Server Devs can\n * - investigate network, client and server performance and reliability issues\n */\nexport const isRetryableFailure = (status: CommunicationStatus) => isNetworkFailure(status) || isTimeout(status) || isAborted(status)\n\n/**\n * Returns true if the status is a valid communication status\n */\nexport const isStatusValid = (status: string) => statusRegex.test(status);\n","import { clientFailure, clientFailureNotAuthorized, missing, networkFailure, serverFailure, success } from './CommunicationStatusConsts';\nimport { isStatusValid } from './CommunicationStatusTests';\nimport { CommunicationStatus, CommunicationStatusDetails, communicationStatuses } from './CommunicationStatusTypes';\n\nexport const getCommunicationStatusFromHttpStatusOrUndefined = (httpStatus: number): CommunicationStatus | undefined => {\n switch (Math.floor(httpStatus / 100)) {\n case 2: return success;\n case 3: return missing;\n case 4:\n switch (httpStatus) {\n case 401:\n case 403:\n case 407:\n case 451: return clientFailureNotAuthorized;\n case 404: return missing;\n default: return clientFailure;\n }\n case 5:\n switch (httpStatus) {\n case 502:\n case 503:\n case 504: return networkFailure;\n case 511: return clientFailureNotAuthorized;\n case 501: return missing; // 501 Not Implemented - i.e. it \"does not exist\" currently - i.e. missing\n case 505: // HTTP Version Not Supported - client should change the request\n case 530: return clientFailure;\n default: return serverFailure;\n }\n }\n return undefined;\n};\n\nexport const getCommunicationStatusFromHttpStatus = (httpStatus: number): CommunicationStatus => {\n const status = getCommunicationStatusFromHttpStatusOrUndefined(httpStatus);\n if (!status) {\n throw new Error(`httpStatus ${httpStatus} is not a supported CommunicationStatus.`);\n }\n return status;\n};\n\n/**\n * Returns CommunicationStatusDetails {status, httpStatus, message} given an HTTP status code\n *\n * Throws: Error if the HTTP status code is not supported (i.e. the 100 codes or non HTTP status code numbers)\n *\n * @param httpStatus - The HTTP status code to get the communication status for\n * @returns The communication status for the given HTTP status code\n */\nexport const getCommunicationStatusDetails = (httpStatus?: number): CommunicationStatusDetails => {\n if (!httpStatus) return { status: networkFailure, message: \"network failure\" };\n\n const status = getCommunicationStatusFromHttpStatus(httpStatus);\n\n return {\n status,\n httpStatus,\n message: `${status} (${httpStatus})`\n };\n};\n\nexport const getCommunicationStatusOrUndefined = <T extends number | CommunicationStatus | null | undefined>(\n status: T\n): T extends null | undefined ? undefined : (CommunicationStatus | undefined) => {\n if (status == null) return undefined as any;\n if (typeof status === 'string') {\n if (!isStatusValid(status)) {\n return undefined;\n }\n return status as any;\n }\n if (typeof status === 'number') {\n return getCommunicationStatusFromHttpStatusOrUndefined(status) as any;\n }\n return undefined;\n};\n\nexport const getCommunicationStatus = <T extends number | CommunicationStatus | null | undefined>(\n status: T\n): T extends null | undefined ? undefined : CommunicationStatus => {\n if (status == null) return undefined as any;\n if (typeof status === 'number') {\n return getCommunicationStatusFromHttpStatus(status) as any;\n }\n const communicationStatus: CommunicationStatus | undefined = getCommunicationStatusOrUndefined(status);\n if (!communicationStatus) {\n throw new Error(`${status} is not a valid CommunicationStatus.`);\n }\n return communicationStatus as any;\n};\n\nexport const getHttpStatus = (status: CommunicationStatus): number => {\n const httpStatus = communicationStatuses[status]?.httpStatus;\n if (!httpStatus) throw new Error(`There is no valid HttpStatus for ${status}.`);\n return httpStatus;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,IAAM,UAA+B;AAerC,IAAM,UAA+B;AAsBrC,IAAM,gBAAqC;AAmB3C,IAAM,6BAAkD;AAsBxD,IAAM,gBAAqC;AAgB3C,IAAM,iBAAsC;AAc5C,IAAM,UAA+B;AAcrC,IAAM,UAA+B;AAoBrC,IAAM,UAA+B;AAarC,IAAM,iBAAsC;;;ACjK5C,IAAM,wBAAiE;AAAA,EAC5E,SAAS,EAAE,YAAY,IAAI;AAAA,EAC3B,SAAS,EAAE,YAAY,KAAK,SAAS,KAAK;AAAA,EAC1C,eAAe,EAAE,YAAY,KAAK,eAAe,MAAM,SAAS,KAAK;AAAA,EACrE,4BAA4B,EAAE,YAAY,KAAK,eAAe,MAAM,SAAS,KAAK;AAAA,EAClF,eAAe,EAAE,YAAY,KAAK,SAAS,MAAM,eAAe,KAAK;AAAA,EACrE,gBAAgB,EAAE,SAAS,KAAK;AAAA,EAChC,SAAS,EAAE,SAAS,KAAK;AAAA,EACzB,SAAS,CAAC;AAAA,EACV,SAAS,EAAE,YAAY,KAAK,SAAS,KAAK;AAAA,EAC1C,gBAAgB,EAAE,SAAS,KAAK;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,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/CommunicationStatusConsts.ts","../../art-core-ts-types/src/Types.ts","../../art-core-ts-comprehensions/src/Comprehensions.ts","../../art-core-ts-comprehensions/src/DeepComprehensions.ts","../src/CommunicationStatusTypes.ts","../src/CommunicationStatusTests.ts","../src/CommunicationStatusConversions.ts"],"sourcesContent":["export * from \"./CommunicationStatusConsts\";\nexport * from \"./CommunicationStatusConversions\";\nexport * from \"./CommunicationStatusTests\";\nexport * from \"./CommunicationStatusTypes\";\n","// Export status constants\nimport type { CommunicationStatus } from './CommunicationStatusTypes'\n\n/**\n * HTTP 2xx responses\n *\n * Client Can Automatically:\n * - Process the successful response\n * - Update UI to reflect success\n *\n * Client Developer Can:\n * - Handle the successful response data\n */\nexport const success: CommunicationStatus = \"success\"\n\n/**\n * Resource not found\n *\n * HTTP Status Codes Covered:\n * - 404: Not Found\n *\n * Client Can Automatically:\n * - notify the user that the resource was not found\n * - prompt the user to request a different resource\n *\n * Client Developer Can:\n * - fix the bad resource paths\n */\nexport const missing: CommunicationStatus = \"missing\"\n\n/**\n * Client-side errors; i.e. the client needs to change the request somehow to succeed\n *\n * HTTP Status Codes Covered:\n * - 400: Bad Request\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 409: Conflict\n * - 422: Unprocessable Entity\n *\n * Client Can Automatically:\n * - Notify the user that the client is experiencing issues\n * - Prompt user to correct invalid input\n *\n * Client Developer Can:\n * - use isClientFailureNotAuthorized to check for 401/403/407/451\n * - fix the request to avoid the 4xx error\n * - validate input before sending requests\n */\nexport const clientFailure: CommunicationStatus = \"clientFailure\"\n\n/**\n * Unauthorized requests; i.e. client needs to change the credentials (or the grants for the current credentials) to succeed\n *\n * HTTP Status Codes Covered:\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 451: Unavailable For Legal Reasons\n *\n * Client Can Automatically:\n * - refresh the request token\n * - prompt the user to re-login\n * - ask the user to contact the administrator for access\n *\n * Client and Server Developer Can:\n * - fix authorization / authentication bugs\n */\nexport const clientFailureNotAuthorized: CommunicationStatus = \"clientFailureNotAuthorized\"\n\n/**\n * Server-side errors; i.e. internal server errors\n *\n * HTTP Status Codes Covered:\n * - 500: Internal Server Error\n * - 502: Bad Gateway\n * - 503: Service Unavailable\n * - 504: Gateway Timeout\n *\n * Client Can Automatically:\n * - Ask the user to try again later\n * - Notify the user that the server is experiencing issues\n * - Implement automatic retry with backoff\n *\n * Client Developer: (probably) can't fix\n *\n * Server Developer Can:\n * - fix the server to avoid the 5xx error\n * - fix server infrastructure to avoid the 5xx error\n */\nexport const serverFailure: CommunicationStatus = \"serverFailure\"\n\n/**\n * Request fails due to network connectivity issues\n *\n * HTTP Status Codes Covered: NONE (server was not reachable)\n *\n * Client Can Automatically:\n * - Prompt the user to fix the network connection\n * - Retry the request when network is available\n * - Monitor network status for recovery\n *\n * Client Developer Can:\n * - fix bad network constants (like address, ports, etc.)\n * - implement offline-first capabilities\n */\nexport const networkFailure: CommunicationStatus = \"networkFailure\"\n\n/**\n * Request was cancelled by client\n *\n * Client Can Automatically:\n * - notify the user that the request was cancelled\n * - prompt the user to try again\n * - cleanup any pending state\n *\n * Client Developer Can:\n * - fix the client to not abort the request unnecessarily\n * - implement proper cleanup on abort\n */\nexport const aborted: CommunicationStatus = \"aborted\"\n\n/**\n * Request is in progress\n *\n * Client Can Automatically:\n * - notify the user that the request is in progress\n * - show the user progress (if available)\n * - allow the user to cancel the request\n *\n * Client Developer Can:\n * - if \"pending\" was not expected, maybe the client needs to `wait` for the request to complete?\n * - implement proper loading states\n */\nexport const pending: CommunicationStatus = \"pending\"\n\n/**\n * Any error response (HTTP 4xx/5xx) or network/abort failures\n *\n * HTTP Status Codes Covered:\n * - 4xx: Client-side errors (except 404)\n * - 5xx: Server-side errors\n * - Network failures\n * - Abort failures\n *\n * Client Can Automatically:\n * - Show appropriate error message to user\n * - Implement generic error handling\n * - Log errors for debugging\n *\n * Client Developer Can:\n * - Use more specific is* functions for targeted error handling\n * - Implement proper error recovery strategies\n */\nexport const failure: CommunicationStatus = \"failure\"\n\n/**\n * Request timed out\n *\n * Client Can Automatically:\n * - notify the user that the request timed out\n * - try again (automatically or via user action)\n *\n * Client Developer Can:\n * - fix the client to not timeoutFailure the request\n * - implement proper timeoutFailure handling\n */\nexport const timeoutFailure: CommunicationStatus = \"timeoutFailure\"\n","import { PlainObject } from \"./TypeScriptTypes\"\n\ntype TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array\n\n/*\n\n @isPromise: (obj) => obj? && isFunction(obj.then) && !isFunction obj\n @isRegExp: (obj) => obj.constructor.name == \"RegExp\"\n @isNumber: isNumber = (obj) => typeof obj == \"number\"\n\n isNonNegativeInt: (x) ->\n ((x | 0) == x) &&\n x >= 0\n\n @isError: (obj) => obj? && obj instanceof Error\n @isDate: (obj) => obj?.constructor == Date\n @isString: isString = (obj) => typeof obj == \"string\"\n @isFunction: isFunction = (obj) => typeof obj == \"function\"\n @isEmptyObject: (obj) => Object.keys(obj).length == 0\n @isBoolean: (obj) => obj == true || obj == false\n\n @isArrayBuffer: isArrayBuffer = if global.ArrayBuffer\n (obj) -> obj? && obj.constructor == ArrayBuffer\n else -> false\n @isTypedArray: (obj) -> obj? && obj.length >= 0 && obj.length == (obj.length | 0) && isArrayBuffer obj.buffer\n\n */\n\n/**\n * Returns true if the value is an object. (note, Arrays are objects)\n * This is only false for null, undefined, functions, and primitives like strings, numbers, and booleans.\n * @param v\n * @returns\n */\nexport const isObject = (v: any): v is Record<string, any> => v != null && typeof v === 'object'\n\n/**\n * Returns true if the value is a plain object - i.e. an object who's prototype is Object\n * @param v\n * @returns\n */\nexport const isPlainObject = (v: any): v is PlainObject => {\n if (!isObject(v)) return false\n if (v.constructor === Object) return true // fast pass, but could fail if v was created in a different context with a different instance of Object\n const prototype = Object.getPrototypeOf(v)\n if (prototype === null) return true\n return null == Object.getPrototypeOf(prototype)\n}\n\nexport const asPlainObject = (v: any): PlainObject => isPlainObject(v) ? v : {}\n\nexport const isFunction = (obj: any): obj is Function => typeof obj === \"function\"\nexport const isNumber = (obj: any): obj is number => typeof obj === \"number\"\nexport const isString = (obj: any): obj is string => typeof obj === \"string\"\nexport const isArrayBuffer = (obj: any): obj is ArrayBuffer => obj != null && obj.constructor === ArrayBuffer\nexport const isArray = (obj: any): obj is any[] => Array.isArray(obj)\n\nexport const isPromise = (obj: any): obj is Promise<any> => obj != null && isFunction(obj.then) && !isFunction(obj)\nexport const isRegExp = (obj: any): obj is RegExp => obj?.constructor.name === \"RegExp\"\nexport const isError = (obj: any): obj is Error => obj != null && obj instanceof Error\nexport const isDate = (obj: any): obj is Date => obj?.constructor === Date\nexport const isEmptyObject = (obj: any): obj is Record<string, never> => Object.keys(obj).length === 0\nexport const isBoolean = (obj: any): obj is boolean => obj === true || obj === false\nexport const isTypedArray = (obj: any): obj is TypedArray =>\n obj != null &&\n obj.length >= 0 &&\n obj.length === (obj.length | 0) &&\n isArrayBuffer(obj.buffer)\n\nexport const isNonNegativeInt = (x: number): x is number => ((x | 0) === x) && x >= 0\n\nexport const stringIsPresent = (str: string): boolean => isString(str) && !/^(\\s+|)$/.test(str)\n\nexport const exists = (value: any): boolean => value != null\nexport const doesNotExist = (value: any): boolean => !exists(value)\n\nexport const isNull = (value: any): boolean => value === null\nexport const isNotNull = (value: any): boolean => !isNull(value)\n\nexport const isUndefined = (value: any): boolean => value === undefined\nexport const isNotUndefined = (value: any): boolean => !isUndefined(value)\n\nexport const isNullish = (value: any): boolean => value == null || value == undefined\nexport const isNotNullish = (value: any): boolean => !isNullish(value)\n\n/**\n * present returns true if \"there is a value _present_\"\n *\n * Specifically:\n * - if `value.getPresent()` is a function; it's called and it's value is returned\n * - if `value.present()` is a function; it's called and it's value is returned\n * - else: returns `true` if `!null`, `!undefined` and `!(string with only whitespace)`\n *\n * > Inspired by Ruby's `present?` method\n *\n * @param v\n * @returns\n */\nexport const present = <T>(v: T): v is NonNullable<T> => {\n if (v == null) return false\n if (isFunction((v as any).getPresent)) {\n return (v as any).getPresent()\n } else if (isFunction((v as any).present)) {\n return (v as any).present()\n } else if (isString(v)) {\n return stringIsPresent(v)\n } else return true\n}\n","import { isPlainObject, isFunction, exists } from '@art-suite/art-core-ts-types'\nimport { EachFunction, ArrayFunction, ObjectFunction, ReduceFunction, FindFunction, AnyContainer, ArrayInput, ObjectInput, NotPresent } from './ComprehensionTypes'\n\nconst isMap = (source: any): source is Map<any, any> => source instanceof Map;\nconst isSet = (source: any): source is Set<any> => source instanceof Set;\n\nexport const isArrayIterable = (source: any): source is any[] => {\n if (typeof source === 'string') return false\n if (isFunction(source)) return false\n return source != null && source.length >= 0;\n}\n\nexport const isOfIterable = (o: any): boolean => {\n if (typeof o === 'string') return false\n if (isFunction(o)) return false\n return isFunction(o[Symbol.iterator] || o.next)\n}\n\nconst returnFirstArg = (a: any) => a;\nconst returnSecondArg = (a: any, b: any) => b;\n\nconst emptyOptions = {};\n\ntype CoreIterationFunction = (value: any, key: any) => boolean; // returns true to stop iteration\n\n/**\n * Tight function to abstract away all possible iteration methods based on the source container type.\n *\n * Iterates over the source collection, calling the given function for each element.\n *\n * Stops when the body function returns true.\n * Does NOT return anything. If you need a return value, must set it as a side-effect of the body function.\n *\n * @param source - The collection to iterate (array, object, Map, Set, etc.)\n * @param body - The function to call for each element.\n * @returns void\n */\nconst iterate = (source: any, body: CoreIterationFunction): void => {\n if (exists(source))\n if (isArrayIterable(source)) for (let key = 0, { length } = source; key < length; key++) { if (body(source[key], key)) break; }\n else if (isPlainObject(source)) for (const key in source) { if (body(source[key], key)) break; }\n else if (isMap(source)) for (const [key, value] of source.entries()) { if (body(value, key)) break; }\n // else if (isSet(source)) for (const value of source) { if (body(value, value)) break; }\n else if (isOfIterable(source)) { let count = 0; for (const value of source) { if (body(value, count++)) break; } }\n else throw new Error(`Unsupported source type: ${typeof source}`);\n};\n\n/*\n Returns a function that handles \"with\", \"when\" and \"stopWhen\" comprehension clauses:\n\n 1. Returns true if the \"stopWhen\" is provided and returns true, otherwise returns it will return false\n 2. If stopWhen is false, \"when\" and \"with\" are processed\n 3. If there is no \"when\" or \"when\" returns true, \"with\" is called.\n*/\nconst normalizeBody = (withFunction: (value: any, key: any) => any, options: AcceptedComprehensionOptions): (value: any, key: any) => boolean => {\n let { when, stopWhen } = options;\n if (when && stopWhen) {\n return (v: any, k: any) => {\n if (stopWhen(v, k)) return true;\n if (when(v, k)) withFunction(v, k);\n return false;\n }\n }\n if (when) {\n return (v: any, k: any) => {\n if (when(v, k)) withFunction(v, k);\n return false;\n }\n }\n if (stopWhen) {\n return (v: any, k: any) => {\n if (stopWhen(v, k)) return true;\n withFunction(v, k);\n return false;\n }\n }\n return (v: any, k: any) => { withFunction(v, k); return false; };\n};\n\n\nlet normalizeKeyFunction = (source: any, options: AcceptedComprehensionOptions) =>\n options.withKey || (isArrayIterable(source) ? returnFirstArg : returnSecondArg)\n\nconst _each = (source: any, withFunction: (value: any, key: any) => any, options: AcceptedComprehensionOptions) => {\n iterate(source, normalizeBody(withFunction, options));\n};\n\n//************************************************************************\n// NORMALIZED COMPREHENSION FUNCTIONS\n//************************************************************************\ntype NormalizedIterationFunction = (source: any, options: NormalizedComprehensionOptions) => any;\n\nconst normalizedEach: NormalizedIterationFunction = (source: any, options: NormalizedComprehensionOptions) => {\n _each(source, options.with, options);\n return options.into;\n};\n\nconst normalizedArrayIteration: NormalizedIterationFunction = (source: any, options: NormalizedComprehensionOptions) => {\n let { into, with: withFunction } = options;\n if (into == null) into = [];\n _each(source, (v: any, k: any) => into.push(withFunction(v, k)), options);\n return into;\n};\n\nconst normalizedObjectIteration: NormalizedIterationFunction = (source: any, options: NormalizedComprehensionOptions) => {\n let { into, with: withFunction } = options;\n if (into == null) into = {};\n let withKey = normalizeKeyFunction(source, options);\n _each(source, (v, k) => (into[withKey(v, k)] = withFunction(v, k)), options);\n return into;\n};\n\nconst normalizedReduceIteration: NormalizedIterationFunction = (source: any, options: NormalizedComprehensionOptions) => {\n let { into, with: withFunction } = options;\n let first = into === undefined;\n _each(source, (v: any, k: any) => {\n if (first) { first = false; into = v; }\n else {\n into = withFunction(into, v, k)\n }\n }, options);\n return into;\n};\n\nconst normalizedFindIteration: NormalizedIterationFunction = (source: any, options: NormalizedComprehensionOptions) => {\n let { with: withFunction } = options;\n let { when } = options;\n let found: any | undefined = undefined;\n iterate(\n source,\n when\n ? (v, k) => {\n if (when(v, k)) {\n found = withFunction(v, k);\n return true; // signal to stop iteration\n }\n return false;\n }\n : (v, k) => {\n found = withFunction(v, k) // stops iteration if withFunction returns an value that \"exists\" (is not undefined, non null)\n return found != null;\n }\n );\n return found;\n};\n\n//####################\n// PRIVATE\n//####################\n\n// WithFunction has two signatures: value + key, or for reduce, accumulator + value + key\ntype ValueKeyFunction = (value?: any, key?: any) => any;\ntype AccumulatorValueKeyFunction = (accumulator?: any, value?: any, key?: any) => any;\ntype WithFunction = ValueKeyFunction | AccumulatorValueKeyFunction;\ntype WhenFunction = (value: any, key: any) => any;\ntype WithKeyFunction = (value: any, key: any) => any;\n\ntype AcceptedComprehensionOptions = {\n into?: any;\n inject?: any; // alias for into - used to make \"reduce\" calls make more sense\n returning?: any; // alias for into - used to make \"each\" calls make more sense\n with?: WithFunction;\n when?: WhenFunction;\n withKey?: WithKeyFunction;\n stopWhen?: (value: any, key: any) => any;\n}\n\ntype WithOrOptions = WithFunction | AcceptedComprehensionOptions;\n\nconst isAcceptedComprehensionOptions = (o: any): o is AcceptedComprehensionOptions => isPlainObject(o)\n\n// the 'with' param will always exist when normalized\ntype NormalizedComprehensionOptions = Omit<AcceptedComprehensionOptions, 'with' | 'inject' | 'returning'> & {\n with: WithFunction;\n}\n\n/**\n * Returns the first non-undefined value from into, inject, or returning\n *\n * @param into - The 'into' parameter.\n * @param inject - The 'inject' parameter.\n * @param returning - The 'returning' parameter.\n * @returns The normalized 'into' parameter.\n */\nconst firstNotUndefined = (into: any, inject: any, returning: any) => {\n if (into === undefined) into = inject\n if (into === undefined) into = returning\n return into\n}\n\nconst normalizeIterationParams = (withOrOptions?: WithOrOptions): NormalizedComprehensionOptions => {\n if (isAcceptedComprehensionOptions(withOrOptions)) {\n const { with: withFunction, into, inject, returning, ...rest } = withOrOptions;\n return { ...rest, into: firstNotUndefined(into, inject, returning), with: withFunction ?? returnFirstArg };\n }\n if (isFunction(withOrOptions)) {\n return { with: withOrOptions };\n }\n return { with: returnFirstArg };\n};\n\n/*\nNormalizes input params for the 'iteration' function.\nSince this normalizes multiple params, and therefor would need to return\nan new array or new object otherwise, we pass IN the iteration function\nand pass the params directly to it. This keeps the computed params on the\nstack and doesn't create new objects.\n\nIN signature 1: (iteration, source, withFunction) ->\nIN signature 2: (iteration, source, options) ->\nIN signature 3: (iteration, source) ->\n\nIN:\niteration: (source, into, withFunction, options) -> out\n\n The iteration function is invoked last with the computed args.\n Its results are returned.\n\n IN:\n source: passed directly through from inputs\n into: passed directly through from inputs OR from options.into\n withFunction: passed directly through from inputs OR from options.with\n options: passed directly through from inputs OR {}\n (guaranteed to be set and a plainObject)\n\nsource: the source collection to be iterated over. Passed directly through.\n\ninto: passed through to 'iteration'\nwithFunction: passed through to 'iteration'\noptions: passed through to 'iteration' AND:\n\n into: set 'into' from the options object\n with: set 'withFunction' from the options object\n\nOUT: out\n*/\nconst invokeNormalizedIteration = (\n normalizedIterationFunction: NormalizedIterationFunction,\n source: any,\n withOrOptions: WithOrOptions\n) => normalizedIterationFunction(source, normalizeIterationParams(withOrOptions));\n\n/**\n * Iterates over the provided collection, calling the given function for each element.\n *\n * Unlike other comprehensions, `each` is designed for side effects and does not build a new collection.\n *\n * **Return value:**\n * - If an `into`, `inject`, or `returning` option is provided (or as the second argument), that value is returned (not modified by `each` itself).\n * - If no such value is provided, returns `undefined`.\n *\n * This allows you to use `each` for side effects while optionally threading a value through the iteration.\n *\n * @param source The collection to iterate (array, object, Map, Set, etc.)\n * @param withOrOptions Optional: Either the `into` value or the function to call for each element.\n * @returns The `into`/`inject`/`returning` value if provided, otherwise `undefined`.\n */\nexport const each: EachFunction = ((source: any, withOrOptions: WithOrOptions) => invokeNormalizedIteration(normalizedEach, source, withOrOptions)) as EachFunction;\n\n/**\n * Builds a new array from the provided collection, optionally transforming or filtering elements.\n *\n * Options:\n * - `with`: function to transform each element (like map)\n * - `when`: function to filter elements (like filter)\n * - `into`: array to push results into (default: new array)\n *\n * @param source The collection to iterate (array, object, Map, Set, etc.)\n * @param withOrOptions Optional: `with` function, or options object, or `into` array.\n * @returns The resulting array.\n */\nexport const array: ArrayFunction = ((source: any, withOrOptions: WithOrOptions) => invokeNormalizedIteration(normalizedArrayIteration, source, withOrOptions)) as ArrayFunction;\n\n/**\n * Builds a new object from the provided collection, optionally transforming keys/values or filtering elements.\n *\n * Options:\n * - `with`: function to transform each value\n * - `when`: function to filter elements\n * - `key`/`withKey`: function to determine output keys\n * - `into`: object to assign results into (default: new object)\n *\n * Defaults:\n * - no `with`: uses the source container's \"values\" as the default\n * - no `withKey`: from arrays, uses the values as keys, from objects, uses the keys as keys\n * - no `into`: creates a new object\n *\n * Simplest example use: `object([\"sally\", \"billy\", \"chad\"])` => { \"sally\": \"sally\", \"billy\": \"billy\", \"chad\": \"chad\" }\n *\n * @param source The collection to iterate (array, object, Map, Set, etc.)\n * @param withOrOptions Optional: `with` function, or options object, or `into` object.\n * @returns The resulting object.\n */\nexport const object: ObjectFunction = ((source: any, withOrOptions: WithOrOptions) => invokeNormalizedIteration(normalizedObjectIteration, source, withOrOptions)) as ObjectFunction;\n\n/**\n * Reduces the provided collection to a single value, similar to Array.prototype.reduce.\n *\n * The first element is used as the initial value unless an `into`/`inject`/`returning` option is provided.\n *\n * Options:\n * - `with`: reducer function (receives accumulator, value, key)\n * - `when`: function to filter elements\n * - `into`/`inject`/`returning`: initial value for the reduction\n *\n * @param source The collection to reduce (array, object, Map, Set, etc.)\n * @param withOrOptions Optional: initial value or reducer function or options object.\n * @returns The reduced value.\n */\nexport const reduce: ReduceFunction = ((source: any, withOrOptions: WithOrOptions) => invokeNormalizedIteration(normalizedReduceIteration, source, withOrOptions)) as ReduceFunction;\n\n/**\n * Finds and returns the first value in the collection that matches the given criteria.\n *\n * Options:\n * - `with`: function to transform the found value\n * - `when`: function to filter elements (predicate)\n *\n * @param source The collection to search (array, object, Map, Set, etc.)\n * @param withOrOptions Optional: predicate or options object.\n * @returns The found value, or undefined if not found.\n */\nexport const find: FindFunction = ((source: any, withOrOptions: WithOrOptions) => invokeNormalizedIteration(normalizedFindIteration, source, withOrOptions)) as FindFunction;\n\n\n/**\n * Returns true if the source is a comprehension iterable.\n *\n * A comprehension iterable is any object that can be iterated over.\n *\n * This is different from isFullySupportedComprehensionIterable, which only checks if we can both generate and iterate over the source.\n *\n * NOTE strings are not considered comprehension iterables.\n *\n * @param source - The source to check.\n * @returns True if the source is a comprehension iterable, false otherwise.\n */\nexport const isComprehensionIterable = (source: any): source is AnyContainer<any> =>\n isArrayIterable(source) || isPlainObject(source) || isMap(source) || isSet(source) || isOfIterable(source)\n\n/**\n * Returns true if the source is a fully supported comprehension iterable.\n *\n * Fully supported means we can both generate as well as iterate over the source.\n *\n * This is different from isComprehensionIterable, which only checks if we can iterate over the source.\n *\n * This is useful for cases where we need to know if we can both generate and iterate over the source,\n * such as when we are using the source in a comprehension.\n *\n * Currently, this is only true for arrays and objects. TODO: add Map and Set support.\n * @param source - The source to check.\n * @returns True if the source is a fully supported comprehension iterable, false otherwise.\n */\nexport const isFullySupportedComprehensionIterable = (source: any): source is AnyContainer<any> =>\n isArrayIterable(source) || isPlainObject(source)\n","/**\n * DeepComprehensions is a library that provides a way to map and iterate over deeply nested comprehension iterables.\n *\n * It is useful for cases where you need to map or iterate over a deeply nested comprehension iterable.\n *\n * NOTE: due to their nature, deep comprehensions don't support TypeScript's type inference. You'll need to post-validate or coerce the results to the correct type.\n *\n * TODO: add Map and Set support.\n * TODO: add {when} support. Example usage: deepStripNull = deepMap(obj, {when: v => v !== null})\n */\nimport { isPlainObject } from '@art-suite/art-core-ts-types'\nimport { each, isComprehensionIterable, isFullySupportedComprehensionIterable, isArrayIterable, array, object } from './Comprehensions'\nimport { AnyContainer, FullySupportedContainer, ArrayInput, ObjectInput, NotPresent } from './ComprehensionTypes'\nimport { isFunction } from '@art-suite/art-core-ts-types'\n\nexport type DeepWithFunction = (value: any, key: any) => void\nexport type DeepWhenFunction = (value: any, key: any) => boolean\n\nexport type DeepOptions = {\n when?: DeepWhenFunction\n with?: DeepWithFunction\n}\n\nexport type DeepSecondParameter = DeepWithFunction | DeepOptions\n\n//******************************************************************************************************************\n// HELPERS\n//******************************************************************************************************************\n\nconst defaultWithFunction: DeepWithFunction = v => v\nconst defaultWhenFunction: DeepWhenFunction = () => true\n\ntype DeepOptionsFullSupport = {\n when: DeepWhenFunction\n with: DeepWithFunction\n}\n\nconst normalizeDeepOptions = (options: DeepSecondParameter): DeepOptionsFullSupport => {\n if (isFunction(options)) {\n return { with: options, when: defaultWhenFunction }\n }\n return { with: options.with ?? defaultWithFunction, when: options.when ?? defaultWhenFunction }\n}\n\nconst deepEachR = (obj: AnyContainer<any>, options: DeepOptionsFullSupport) =>\n each(obj, {\n when: options.when,\n with: (value: any, key: any) =>\n isComprehensionIterable(value)\n ? deepEachR(value, options)\n : options.with(value, key)\n })\n\nconst deepMapR = (obj: AnyContainer<any>, options: DeepOptionsFullSupport) =>\n mapInternal(obj, {\n when: options.when, with: (value: any, key: any) =>\n isFullySupportedComprehensionIterable(value)\n ? deepMapR(value, options)\n : options.with(value, key)\n })\n\nconst mapInternal = (source: ArrayInput<any> | ObjectInput<any> | NotPresent, options: DeepOptionsFullSupport) => {\n if (isArrayIterable(source)) return array(source, options)\n if (isPlainObject(source)) return object(source, options)\n throw new Error(`Unsupported source type: ${typeof source}`)\n}\n\n//******************************************************************************************************************\n// EXPORTS\n//******************************************************************************************************************\n/**\n * Maps over a fully supported comprehension iterable, shallowly.\n *\n * Returns the same container type (array or object) as the original object, but with the values mapped.\n *\n * @param source - The source to map over.\n * @param options - the map-function or {with: the map-function, when: the when-function}\n * @returns The mapped container.\n */\nexport const map = (source: ArrayInput<any> | ObjectInput<any> | NotPresent, options: DeepSecondParameter) =>\n mapInternal(source, normalizeDeepOptions(options))\n\n/**\n * Iterates over a fully supported comprehension iterable, and any nested isComprehensionIterable values.\n *\n * withFunction is called for each value that is NOT isComprehensionIterable and true for whenFunction (if provided).\n *\n * whenFunction is called on EVERY value, isComprehensionIterable or not. If it returns false, isComprehensionIterable values will be skipped.\n *\n * @param obj - The object to iterate over.\n * @param options - the with-function or {with: the with-function, when: the when-function}\n * @returns The object.\n */\nexport const deepEach = (obj: AnyContainer<any>, options: DeepSecondParameter) =>\n deepEachR(obj, normalizeDeepOptions(options))\n\n/**\n * Maps over a fully supported comprehension iterable, and any nested fully supported comprehension iterables.\n *\n * Returns the same structure (of fully supported comprehension iterables) as the original object, but with the values mapped.\n * If the source is not a fully supported comprehension iterable, it will return the source unchanged.\n * If the source is a fully supported comprehension iterable, it will return a new fully supported comprehension iterable with the values mapped.\n *\n * whenFunction is called on EVERY value, isComprehensionIterable or not. If it returns false, isComprehensionIterable values will be skipped.\n *\n * @param obj - The object to map over.\n * @param options - the map-function or {with: the map-function, when: the when-function}\n * @returns The mapped object.\n */\nexport const deepMap = (obj: FullySupportedContainer<any>, options: DeepSecondParameter) =>\n deepMapR(obj, normalizeDeepOptions(options))\n","import { object } from '@art-suite/art-core-ts-comprehensions';\n\nconst communicationStatusesPartials = {\n // HTTP Success Statuses\n success: { httpStatus: 200 },\n\n // HTTP Failure Statuses\n missing: { httpStatus: 404, failure: true },\n clientFailure: { httpStatus: 400, clientFailure: true, failure: true },\n clientFailureNotAuthorized: { httpStatus: 403, clientFailure: true, failure: true },\n serverFailure: { httpStatus: 500, failure: true, serverFailure: true },\n failure: { httpStatus: 500, failure: true },\n\n // Non-HTTP Statuses\n pending: { httpStatus: undefined },\n networkFailure: { httpStatus: undefined, failure: true },\n aborted: { httpStatus: undefined, failure: true },\n timeoutFailure: { httpStatus: undefined, failure: true }\n};\n\n/**\n * The core of Art-core-ts-communication-status: A simplified set of statuses as a human-readable and machine-interpretable string\n * representing all the possible communication statuses that are pragmatically actionable.\n */\nexport type CommunicationStatus = keyof typeof communicationStatusesPartials;\n\nexport type HttpOrCommunicationStatus = CommunicationStatus | number;\n\n/**\n * Details about a communication status\n *\n * @param httpStatus - The HTTP status code for the communication status\n * @param failure - Whether the communication status is a failure\n * @param clientFailure - Whether the communication status is a client failure\n * @param serverFailure - Whether the communication status is a server failure\n * @param status - The communication status - alias for communicationStatus\n * @param communicationStatus - The communication status\n */\nexport interface CommunicationStatusDetails {\n httpStatus?: number;\n failure?: boolean;\n clientFailure?: boolean;\n serverFailure?: boolean;\n status: CommunicationStatus;\n communicationStatus: CommunicationStatus;\n message: string;\n}\n\nexport const communicationStatuses: Record<CommunicationStatus, CommunicationStatusDetails> = object(communicationStatusesPartials, (details: any, status) => ({\n ...details,\n failure: !!details.failure,\n clientFailure: !!details.clientFailure,\n serverFailure: !!details.serverFailure,\n status: status as CommunicationStatus,\n communicationStatus: status as CommunicationStatus,\n message: details.httpStatus ? `${status} (${details.httpStatus})` : status\n})) as Record<CommunicationStatus, CommunicationStatusDetails>;\n\nexport type CommunicationStatuses = typeof communicationStatuses;\n\n/**\n * RegEx returns true for all valid communication statuses\n */\nexport const statusRegex = new RegExp(`^(${Object.keys(communicationStatuses).join('|')})$`);\n","import { aborted, clientFailureNotAuthorized, missing, networkFailure, pending, success, timeoutFailure } from './CommunicationStatusConsts';\nimport { getCommunicationStatus, getCommunicationStatusDetails } from './CommunicationStatusConversions';\nimport { HttpOrCommunicationStatus, statusRegex } from './CommunicationStatusTypes';\n\n// Core status check functions\n/** Returns true for HTTP 2xx responses */\nexport const isSuccess = (status: HttpOrCommunicationStatus) => getCommunicationStatus(status) === success;\n\n/**\n * Returns true for any error response (HTTP 4xx/5xx) or network/abort failures\n *\n * HTTP Status Codes Covered:\n * - 4xx: Client-side errors (except 404)\n * - 5xx: Server-side errors\n * - Network failures\n * - Abort failures\n *\n * Client Can:\n * - Use a different is* function for more specific checks\n */\nexport const isFailure = (status: HttpOrCommunicationStatus) => getCommunicationStatusDetails(status).failure;\n\n/**\n * Returns true for client-side errors\n *\n * HTTP Status Codes Covered:\n * - 400: Bad Request\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 409: Conflict\n * - 422: Unprocessable Entity\n *\n * Client Can Automatically:\n * - Notify the user that the client is experiencing issues\n *\n * Client Developer Can:\n * - use isClientFailureNotAuthorized to check for 401/403/407/451\n * - fix the request to avoid the 4xx error\n*/\nexport const isClientFailure = (status: HttpOrCommunicationStatus) => getCommunicationStatusDetails(status).clientFailure;\n\n/**\n * Returns true for server-side errors\n *\n * HTTP Status Codes Covered:\n * - 500: Internal Server Error\n * - 502: Bad Gateway\n * - 503: Service Unavailable\n * - 504: Gateway Timeout\n *\n * Client Can Automatically:\n * - Ask the user to try again later\n * - Notify the user that the server is experiencing issues\n *\n * Client Developer: (probably) can't fix\n *\n * Server Developer Can:\n * - fix the server to avoid the 5xx error\n * - fix server infrastructure to avoid the 5xx error (e.g. Bad Gateway, Service Unavailable, Gateway Timeout)\n*/\nexport const isServerFailure = (status: HttpOrCommunicationStatus) => getCommunicationStatusDetails(status).serverFailure;\n\n/**\n * Returns true when request fails due to network connectivity issues\n *\n * HTTP Status Codes Covered: NONE (server was not reachable)\n *\n * Client Can Automatically:\n * - Prompt the user to fix the network connection\n * - Retry the request\n *\n * Client Developer Can:\n * - fix bad network constants (like address, ports, etc.)\n*/\nexport const isNetworkFailure = (status: HttpOrCommunicationStatus) => getCommunicationStatus(status) === networkFailure;\n\n/** Returns true for server errors, network failures and aborted requests; i.e. the client did nothing wrong (as far as we can tell); client can ask the user to do something OR retry the request */\nexport const isNonClientFailure = (status: HttpOrCommunicationStatus) => {\n const details = getCommunicationStatusDetails(status);\n return details.failure && !details.clientFailure;\n};\n\n/**\n * Returns true for unauthorized requests (not authenticated or not authorized)\n *\n * HTTP Status Codes Covered:\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 451: Unavailable For Legal Reasons\n * - 511: Network Authentication Required\n *\n * Client Can Automatically:\n * - refresh the request token\n * - prompt the user to re-login\n * - ask the user to contact the administrator for access\n *\n * Client and Server Developer Can:\n * - fix authorization / authentication bugs\n */\nexport const isClientFailureNotAuthorized = (status: HttpOrCommunicationStatus) =>\n getCommunicationStatus(status) === clientFailureNotAuthorized;\n\n/**\n * Returns true when request was cancelled by client\n *\n * Client Can Automatically:\n * - notify the user that the request was cancelled\n * - prompt the user to try again\n *\n * Client Developer Can:\n * - fix the client to not abort the request\n */\nexport const isAborted = (status: HttpOrCommunicationStatus) => getCommunicationStatus(status) === aborted;\n\n/**\n * Returns true when resource not found / not available\n *\n * HTTP Status Codes Covered:\n * - 404: Not Found\n * - 501: Not Implemented\n *\n * Client Can Automatically:\n * - notify the user that the resource was not found\n * - prompt the user to request a different resource\n *\n * Client Developer Can:\n * - fix the bad resource paths\n */\nexport const isMissing = (status: HttpOrCommunicationStatus) => getCommunicationStatus(status) === missing;\n\n/**\n * Returns true while request is in progress\n *\n * Client Can Automatically:\n * - notify the user that the request is in progress\n * - show the user progress (if available)\n * - allow the user to cancel the request (trigging an \"aborted\" communication status)\n *\n * Client Developer Can:\n * - if \"pending\" was not expected, maybe the client needs to `wait` for the request to complete?\n */\nexport const isPending = (status: HttpOrCommunicationStatus) => getCommunicationStatus(status) === pending;\n\n/**\n * Returns true if the request timed out\n *\n * Client Can Automatically:\n * - notify the user that the request timed out\n * - try again (automatically or via user action)\n *\n * Client Developer Can:\n * - extend the timeoutFailure duration\n *\n * Server Developer Can:\n * - improve server performance and reliability\n */\nexport const isTimeout = (status: HttpOrCommunicationStatus) => getCommunicationStatus(status) === timeoutFailure;\n\n/**\n * Returns true if client can safely retry the request\n *\n * A a clearly-retryable failure:\n *\n * - network failure\n * - timeoutFailure\n * - aborted\n *\n * Note: some serverFailures will succeed on retry, but HTTP doesn't return clear indications which ones. To be safe, the client should not retry serverFailures indiscriminately.\n *\n * Client and Server Devs can\n * - investigate network, client and server performance and reliability issues\n */\nexport const isRetryableFailure = (status: HttpOrCommunicationStatus) => {\n const { status: communicationStatus, failure } = getCommunicationStatusDetails(status);\n return failure && (communicationStatus === networkFailure || communicationStatus === timeoutFailure || communicationStatus === aborted);\n};\n\n/**\n * Returns true if the status is a valid communication status\n */\nexport const isStatusValid = (status: string) => statusRegex.test(status);\n","import { clientFailure, clientFailureNotAuthorized, missing, networkFailure, serverFailure, success } from './CommunicationStatusConsts';\nimport { isStatusValid } from './CommunicationStatusTests';\nimport { CommunicationStatus, CommunicationStatusDetails, communicationStatuses } from './CommunicationStatusTypes';\n\n//***************************************************************************************************************\n// Private Helpers\n//***************************************************************************************************************\nconst getCommunicationStatusFromHttpStatusOrUndefined = (httpStatus: number): CommunicationStatus | undefined => {\n switch (Math.floor(httpStatus / 100)) {\n case 2: return success;\n case 3: return missing;\n case 4:\n switch (httpStatus) {\n case 401:\n case 403:\n case 407:\n case 451: return clientFailureNotAuthorized;\n case 404: return missing;\n default: return clientFailure;\n }\n case 5:\n switch (httpStatus) {\n case 502:\n case 503:\n case 504: return networkFailure;\n case 511: return clientFailureNotAuthorized;\n case 501: return missing; // 501 Not Implemented - i.e. it \"does not exist\" currently - i.e. missing\n case 505: // HTTP Version Not Supported - client should change the request\n case 530: return clientFailure;\n default: return serverFailure;\n }\n }\n return undefined;\n};\n\nconst getCommunicationStatusFromHttpStatus = (httpStatus: number): CommunicationStatus => {\n const status = getCommunicationStatusFromHttpStatusOrUndefined(httpStatus);\n if (!status) {\n throw new Error(`httpStatus ${httpStatus} is not a supported CommunicationStatus.`);\n }\n return status;\n};\n\n//***************************************************************************************************************\n// Public Functions\n//***************************************************************************************************************\nexport const getCommunicationStatusOrUndefined = <T extends number | CommunicationStatus | null | undefined>(\n status: T\n): T extends null | undefined ? undefined : (CommunicationStatus | undefined) => {\n if (status == null) return undefined as any;\n if (typeof status === 'string') {\n if (!isStatusValid(status)) {\n return undefined;\n }\n return status as any;\n }\n if (typeof status === 'number') {\n return getCommunicationStatusFromHttpStatusOrUndefined(status) as any;\n }\n return undefined;\n};\n\n/*\n * Returns the CommunicationStatus for a given CommunicationStatus or number\n * If the input is null or undefined, returns undefined, otherwise throws an error if the CommunicationStatus or number is not supported\n * @param status - The CommunicationStatus or number to get the CommunicationStatus for\n * @returns The CommunicationStatus for the given CommunicationStatus or number\n */\nexport const getCommunicationStatus = <T extends number | CommunicationStatus | null | undefined>(\n status: T\n): T extends null | undefined ? undefined : CommunicationStatus => {\n if (status == null) return undefined as any;\n if (typeof status === 'number') {\n return getCommunicationStatusFromHttpStatus(status) as any;\n }\n const communicationStatus: CommunicationStatus | undefined = getCommunicationStatusOrUndefined(status);\n if (!communicationStatus) {\n throw new Error(`${status} is not a valid CommunicationStatus.`);\n }\n return communicationStatus as any;\n};\n\n/**\n * Returns the HTTP status code for a given CommunicationStatus or number\n * If the input is null or undefined, returns undefined, otherwise throws an error if the CommunicationStatus or number is not supported\n * @param status - The CommunicationStatus or number to get the HTTP status code for\n * @returns The HTTP status code for the given CommunicationStatus or number\n */\nexport const getHttpStatus = <T extends CommunicationStatus | number | null | undefined>(status: T): T extends null | undefined ? undefined : number => {\n if (status == null) return undefined as any;\n const communicationStatus = getCommunicationStatus(status);\n const httpStatus = communicationStatuses[communicationStatus].httpStatus;\n if (httpStatus == null) {\n throw new Error(`There is no valid HttpStatus for ${status}.`);\n }\n return httpStatus as any;\n};\n\n/**\n * Returns CommunicationStatusDetails {status, httpStatus, message} given an HTTP status code\n *\n * Throws: Error if the HTTP status code is not supported (i.e. the 100 codes or non HTTP status code numbers)\n *\n * @param status - The HTTP status code to get the communication status for\n * @returns The CommunicationStatusDetails for the given status. Note, if an HTTP status is given, it won't necessarily be the httpStatus returned; HTTPStatuses are simplified along with CommunicationStatuses.\n */\nexport const getCommunicationStatusDetails = <T extends number | CommunicationStatus | null | undefined>(status: T):\n T extends null | undefined ? undefined : CommunicationStatusDetails => {\n if (status == null) return undefined as any;\n const communicationStatus = getCommunicationStatus(status);\n return communicationStatuses[communicationStatus] as any;\n};\n\nexport const getCommunicationStatusDetailsOrUndefined = <T extends number | CommunicationStatus | null | undefined>(\n status: T\n): T extends null | undefined ? undefined : (CommunicationStatusDetails | undefined) => {\n if (status == null) return undefined as any;\n const communicationStatus = getCommunicationStatusOrUndefined(status);\n if (communicationStatus == null) return undefined as any;\n return communicationStatuses[communicationStatus] as any;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,IAAM,UAA+B;AAerC,IAAM,UAA+B;AAsBrC,IAAM,gBAAqC;AAmB3C,IAAM,6BAAkD;AAsBxD,IAAM,gBAAqC;AAgB3C,IAAM,iBAAsC;AAc5C,IAAM,UAA+B;AAcrC,IAAM,UAA+B;AAoBrC,IAAM,UAA+B;AAarC,IAAM,iBAAsC;;;ACtI5C,IAAM,WAAW,CAAC,MAAqC,KAAK,QAAQ,OAAO,MAAM;AAOjF,IAAM,gBAAgB,CAAC,MAA6B;AACzD,MAAI,CAAC,SAAS,CAAC,EAAG,QAAO;AACzB,MAAI,EAAE,gBAAgB,OAAQ,QAAO;AACrC,QAAM,YAAY,OAAO,eAAe,CAAC;AACzC,MAAI,cAAc,KAAM,QAAO;AAC/B,SAAO,QAAQ,OAAO,eAAe,SAAS;AAChD;AAIO,IAAM,aAAa,CAAC,QAA8B,OAAO,QAAQ;AAsBjE,IAAM,SAAS,CAAC,UAAwB,SAAS;;;ACtExD,IAAM,QAAQ,CAAC,WAAyC,k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M,sBAAsB,uBAAuB,MAAM;AACzD,SAAO,sBAAsB,mBAAmB;AAClD;AAEO,IAAM,2CAA2C,CACtD,WACsF;AACtF,MAAI,UAAU,KAAM,QAAO;AAC3B,QAAM,sBAAsB,kCAAkC,MAAM;AACpE,MAAI,uBAAuB,KAAM,QAAO;AACxC,SAAO,sBAAsB,mBAAmB;AAClD;","names":["failure"]}
package/dist/index.d.cts CHANGED
@@ -1,36 +1,77 @@
1
- interface CommunicationStatusInfo {
1
+ declare const communicationStatusesPartials: {
2
+ success: {
3
+ httpStatus: number;
4
+ };
5
+ missing: {
6
+ httpStatus: number;
7
+ failure: boolean;
8
+ };
9
+ clientFailure: {
10
+ httpStatus: number;
11
+ clientFailure: boolean;
12
+ failure: boolean;
13
+ };
14
+ clientFailureNotAuthorized: {
15
+ httpStatus: number;
16
+ clientFailure: boolean;
17
+ failure: boolean;
18
+ };
19
+ serverFailure: {
20
+ httpStatus: number;
21
+ failure: boolean;
22
+ serverFailure: boolean;
23
+ };
24
+ failure: {
25
+ httpStatus: number;
26
+ failure: boolean;
27
+ };
28
+ pending: {
29
+ httpStatus: undefined;
30
+ };
31
+ networkFailure: {
32
+ httpStatus: undefined;
33
+ failure: boolean;
34
+ };
35
+ aborted: {
36
+ httpStatus: undefined;
37
+ failure: boolean;
38
+ };
39
+ timeoutFailure: {
40
+ httpStatus: undefined;
41
+ failure: boolean;
42
+ };
43
+ };
44
+ /**
45
+ * The core of Art-core-ts-communication-status: A simplified set of statuses as a human-readable and machine-interpretable string
46
+ * representing all the possible communication statuses that are pragmatically actionable.
47
+ */
48
+ type CommunicationStatus = keyof typeof communicationStatusesPartials;
49
+ type HttpOrCommunicationStatus = CommunicationStatus | number;
50
+ /**
51
+ * Details about a communication status
52
+ *
53
+ * @param httpStatus - The HTTP status code for the communication status
54
+ * @param failure - Whether the communication status is a failure
55
+ * @param clientFailure - Whether the communication status is a client failure
56
+ * @param serverFailure - Whether the communication status is a server failure
57
+ * @param status - The communication status - alias for communicationStatus
58
+ * @param communicationStatus - The communication status
59
+ */
60
+ interface CommunicationStatusDetails {
2
61
  httpStatus?: number;
3
62
  failure?: boolean;
4
63
  clientFailure?: boolean;
5
64
  serverFailure?: boolean;
65
+ status: CommunicationStatus;
66
+ communicationStatus: CommunicationStatus;
67
+ message: string;
6
68
  }
7
- declare const communicationStatuses: Record<string, CommunicationStatusInfo>;
69
+ declare const communicationStatuses: Record<CommunicationStatus, CommunicationStatusDetails>;
8
70
  type CommunicationStatuses = typeof communicationStatuses;
9
- type CommunicationStatus = keyof CommunicationStatuses;
10
71
  /**
11
72
  * RegEx returns true for all valid communication statuses
12
73
  */
13
74
  declare const statusRegex: RegExp;
14
- interface CommunicationStatusDetails {
15
- status: CommunicationStatus;
16
- httpStatus?: number;
17
- message: string;
18
- }
19
-
20
- declare const getCommunicationStatusFromHttpStatusOrUndefined: (httpStatus: number) => CommunicationStatus | undefined;
21
- declare const getCommunicationStatusFromHttpStatus: (httpStatus: number) => CommunicationStatus;
22
- /**
23
- * Returns CommunicationStatusDetails {status, httpStatus, message} given an HTTP status code
24
- *
25
- * Throws: Error if the HTTP status code is not supported (i.e. the 100 codes or non HTTP status code numbers)
26
- *
27
- * @param httpStatus - The HTTP status code to get the communication status for
28
- * @returns The communication status for the given HTTP status code
29
- */
30
- declare const getCommunicationStatusDetails: (httpStatus?: number) => CommunicationStatusDetails;
31
- declare const getCommunicationStatusOrUndefined: <T extends number | CommunicationStatus | null | undefined>(status: T) => T extends null | undefined ? undefined : (CommunicationStatus | undefined);
32
- declare const getCommunicationStatus: <T extends number | CommunicationStatus | null | undefined>(status: T) => T extends null | undefined ? undefined : CommunicationStatus;
33
- declare const getHttpStatus: (status: CommunicationStatus) => number;
34
75
 
35
76
  /**
36
77
  * HTTP 2xx responses
@@ -190,8 +231,28 @@ declare const failure: CommunicationStatus;
190
231
  */
191
232
  declare const timeoutFailure: CommunicationStatus;
192
233
 
234
+ declare const getCommunicationStatusOrUndefined: <T extends number | CommunicationStatus | null | undefined>(status: T) => T extends null | undefined ? undefined : (CommunicationStatus | undefined);
235
+ declare const getCommunicationStatus: <T extends number | CommunicationStatus | null | undefined>(status: T) => T extends null | undefined ? undefined : CommunicationStatus;
236
+ /**
237
+ * Returns the HTTP status code for a given CommunicationStatus or number
238
+ * If the input is null or undefined, returns undefined, otherwise throws an error if the CommunicationStatus or number is not supported
239
+ * @param status - The CommunicationStatus or number to get the HTTP status code for
240
+ * @returns The HTTP status code for the given CommunicationStatus or number
241
+ */
242
+ declare const getHttpStatus: <T extends CommunicationStatus | number | null | undefined>(status: T) => T extends null | undefined ? undefined : number;
243
+ /**
244
+ * Returns CommunicationStatusDetails {status, httpStatus, message} given an HTTP status code
245
+ *
246
+ * Throws: Error if the HTTP status code is not supported (i.e. the 100 codes or non HTTP status code numbers)
247
+ *
248
+ * @param status - The HTTP status code to get the communication status for
249
+ * @returns The CommunicationStatusDetails for the given status. Note, if an HTTP status is given, it won't necessarily be the httpStatus returned; HTTPStatuses are simplified along with CommunicationStatuses.
250
+ */
251
+ declare const getCommunicationStatusDetails: <T extends number | CommunicationStatus | null | undefined>(status: T) => T extends null | undefined ? undefined : CommunicationStatusDetails;
252
+ declare const getCommunicationStatusDetailsOrUndefined: <T extends number | CommunicationStatus | null | undefined>(status: T) => T extends null | undefined ? undefined : (CommunicationStatusDetails | undefined);
253
+
193
254
  /** Returns true for HTTP 2xx responses */
194
- declare const isSuccess: (status: CommunicationStatus) => boolean;
255
+ declare const isSuccess: (status: HttpOrCommunicationStatus) => boolean;
195
256
  /**
196
257
  * Returns true for any error response (HTTP 4xx/5xx) or network/abort failures
197
258
  *
@@ -204,7 +265,7 @@ declare const isSuccess: (status: CommunicationStatus) => boolean;
204
265
  * Client Can:
205
266
  * - Use a different is* function for more specific checks
206
267
  */
207
- declare const isFailure: (status: CommunicationStatus) => boolean;
268
+ declare const isFailure: (status: HttpOrCommunicationStatus) => boolean | undefined;
208
269
  /**
209
270
  * Returns true for client-side errors
210
271
  *
@@ -223,7 +284,7 @@ declare const isFailure: (status: CommunicationStatus) => boolean;
223
284
  * - use isClientFailureNotAuthorized to check for 401/403/407/451
224
285
  * - fix the request to avoid the 4xx error
225
286
  */
226
- declare const isClientFailure: (status: CommunicationStatus) => boolean;
287
+ declare const isClientFailure: (status: HttpOrCommunicationStatus) => boolean | undefined;
227
288
  /**
228
289
  * Returns true for server-side errors
229
290
  *
@@ -243,7 +304,7 @@ declare const isClientFailure: (status: CommunicationStatus) => boolean;
243
304
  * - fix the server to avoid the 5xx error
244
305
  * - fix server infrastructure to avoid the 5xx error (e.g. Bad Gateway, Service Unavailable, Gateway Timeout)
245
306
  */
246
- declare const isServerFailure: (status: CommunicationStatus) => boolean;
307
+ declare const isServerFailure: (status: HttpOrCommunicationStatus) => boolean | undefined;
247
308
  /**
248
309
  * Returns true when request fails due to network connectivity issues
249
310
  *
@@ -256,9 +317,9 @@ declare const isServerFailure: (status: CommunicationStatus) => boolean;
256
317
  * Client Developer Can:
257
318
  * - fix bad network constants (like address, ports, etc.)
258
319
  */
259
- declare const isNetworkFailure: (status: CommunicationStatus) => boolean;
320
+ declare const isNetworkFailure: (status: HttpOrCommunicationStatus) => boolean;
260
321
  /** Returns true for server errors, network failures and aborted requests; i.e. the client did nothing wrong (as far as we can tell); client can ask the user to do something OR retry the request */
261
- declare const isNonClientFailure: (status: CommunicationStatus) => boolean;
322
+ declare const isNonClientFailure: (status: HttpOrCommunicationStatus) => boolean | undefined;
262
323
  /**
263
324
  * Returns true for unauthorized requests (not authenticated or not authorized)
264
325
  *
@@ -277,7 +338,7 @@ declare const isNonClientFailure: (status: CommunicationStatus) => boolean;
277
338
  * Client and Server Developer Can:
278
339
  * - fix authorization / authentication bugs
279
340
  */
280
- declare const isClientFailureNotAuthorized: (status: CommunicationStatus) => boolean;
341
+ declare const isClientFailureNotAuthorized: (status: HttpOrCommunicationStatus) => boolean;
281
342
  /**
282
343
  * Returns true when request was cancelled by client
283
344
  *
@@ -288,7 +349,7 @@ declare const isClientFailureNotAuthorized: (status: CommunicationStatus) => boo
288
349
  * Client Developer Can:
289
350
  * - fix the client to not abort the request
290
351
  */
291
- declare const isAborted: (status: CommunicationStatus) => boolean;
352
+ declare const isAborted: (status: HttpOrCommunicationStatus) => boolean;
292
353
  /**
293
354
  * Returns true when resource not found / not available
294
355
  *
@@ -303,7 +364,7 @@ declare const isAborted: (status: CommunicationStatus) => boolean;
303
364
  * Client Developer Can:
304
365
  * - fix the bad resource paths
305
366
  */
306
- declare const isMissing: (status: CommunicationStatus) => boolean;
367
+ declare const isMissing: (status: HttpOrCommunicationStatus) => boolean;
307
368
  /**
308
369
  * Returns true while request is in progress
309
370
  *
@@ -315,7 +376,7 @@ declare const isMissing: (status: CommunicationStatus) => boolean;
315
376
  * Client Developer Can:
316
377
  * - if "pending" was not expected, maybe the client needs to `wait` for the request to complete?
317
378
  */
318
- declare const isPending: (status: CommunicationStatus) => boolean;
379
+ declare const isPending: (status: HttpOrCommunicationStatus) => boolean;
319
380
  /**
320
381
  * Returns true if the request timed out
321
382
  *
@@ -329,7 +390,7 @@ declare const isPending: (status: CommunicationStatus) => boolean;
329
390
  * Server Developer Can:
330
391
  * - improve server performance and reliability
331
392
  */
332
- declare const isTimeout: (status: CommunicationStatus) => boolean;
393
+ declare const isTimeout: (status: HttpOrCommunicationStatus) => boolean;
333
394
  /**
334
395
  * Returns true if client can safely retry the request
335
396
  *
@@ -344,10 +405,10 @@ declare const isTimeout: (status: CommunicationStatus) => boolean;
344
405
  * Client and Server Devs can
345
406
  * - investigate network, client and server performance and reliability issues
346
407
  */
347
- declare const isRetryableFailure: (status: CommunicationStatus) => boolean;
408
+ declare const isRetryableFailure: (status: HttpOrCommunicationStatus) => boolean | undefined;
348
409
  /**
349
410
  * Returns true if the status is a valid communication status
350
411
  */
351
412
  declare const isStatusValid: (status: string) => boolean;
352
413
 
353
- export { type CommunicationStatus, type CommunicationStatusDetails, type CommunicationStatuses, aborted, clientFailure, clientFailureNotAuthorized, communicationStatuses, failure, getCommunicationStatus, getCommunicationStatusDetails, getCommunicationStatusFromHttpStatus, getCommunicationStatusFromHttpStatusOrUndefined, getCommunicationStatusOrUndefined, getHttpStatus, isAborted, isClientFailure, isClientFailureNotAuthorized, isFailure, isMissing, isNetworkFailure, isNonClientFailure, isPending, isRetryableFailure, isServerFailure, isStatusValid, isSuccess, isTimeout, missing, networkFailure, pending, serverFailure, statusRegex, success, timeoutFailure };
414
+ export { type CommunicationStatus, type CommunicationStatusDetails, type CommunicationStatuses, type HttpOrCommunicationStatus, aborted, clientFailure, clientFailureNotAuthorized, communicationStatuses, failure, getCommunicationStatus, getCommunicationStatusDetails, getCommunicationStatusDetailsOrUndefined, getCommunicationStatusOrUndefined, getHttpStatus, isAborted, isClientFailure, isClientFailureNotAuthorized, isFailure, isMissing, isNetworkFailure, isNonClientFailure, isPending, isRetryableFailure, isServerFailure, isStatusValid, isSuccess, isTimeout, missing, networkFailure, pending, serverFailure, statusRegex, success, timeoutFailure };
package/dist/index.d.ts CHANGED
@@ -1,36 +1,77 @@
1
- interface CommunicationStatusInfo {
1
+ declare const communicationStatusesPartials: {
2
+ success: {
3
+ httpStatus: number;
4
+ };
5
+ missing: {
6
+ httpStatus: number;
7
+ failure: boolean;
8
+ };
9
+ clientFailure: {
10
+ httpStatus: number;
11
+ clientFailure: boolean;
12
+ failure: boolean;
13
+ };
14
+ clientFailureNotAuthorized: {
15
+ httpStatus: number;
16
+ clientFailure: boolean;
17
+ failure: boolean;
18
+ };
19
+ serverFailure: {
20
+ httpStatus: number;
21
+ failure: boolean;
22
+ serverFailure: boolean;
23
+ };
24
+ failure: {
25
+ httpStatus: number;
26
+ failure: boolean;
27
+ };
28
+ pending: {
29
+ httpStatus: undefined;
30
+ };
31
+ networkFailure: {
32
+ httpStatus: undefined;
33
+ failure: boolean;
34
+ };
35
+ aborted: {
36
+ httpStatus: undefined;
37
+ failure: boolean;
38
+ };
39
+ timeoutFailure: {
40
+ httpStatus: undefined;
41
+ failure: boolean;
42
+ };
43
+ };
44
+ /**
45
+ * The core of Art-core-ts-communication-status: A simplified set of statuses as a human-readable and machine-interpretable string
46
+ * representing all the possible communication statuses that are pragmatically actionable.
47
+ */
48
+ type CommunicationStatus = keyof typeof communicationStatusesPartials;
49
+ type HttpOrCommunicationStatus = CommunicationStatus | number;
50
+ /**
51
+ * Details about a communication status
52
+ *
53
+ * @param httpStatus - The HTTP status code for the communication status
54
+ * @param failure - Whether the communication status is a failure
55
+ * @param clientFailure - Whether the communication status is a client failure
56
+ * @param serverFailure - Whether the communication status is a server failure
57
+ * @param status - The communication status - alias for communicationStatus
58
+ * @param communicationStatus - The communication status
59
+ */
60
+ interface CommunicationStatusDetails {
2
61
  httpStatus?: number;
3
62
  failure?: boolean;
4
63
  clientFailure?: boolean;
5
64
  serverFailure?: boolean;
65
+ status: CommunicationStatus;
66
+ communicationStatus: CommunicationStatus;
67
+ message: string;
6
68
  }
7
- declare const communicationStatuses: Record<string, CommunicationStatusInfo>;
69
+ declare const communicationStatuses: Record<CommunicationStatus, CommunicationStatusDetails>;
8
70
  type CommunicationStatuses = typeof communicationStatuses;
9
- type CommunicationStatus = keyof CommunicationStatuses;
10
71
  /**
11
72
  * RegEx returns true for all valid communication statuses
12
73
  */
13
74
  declare const statusRegex: RegExp;
14
- interface CommunicationStatusDetails {
15
- status: CommunicationStatus;
16
- httpStatus?: number;
17
- message: string;
18
- }
19
-
20
- declare const getCommunicationStatusFromHttpStatusOrUndefined: (httpStatus: number) => CommunicationStatus | undefined;
21
- declare const getCommunicationStatusFromHttpStatus: (httpStatus: number) => CommunicationStatus;
22
- /**
23
- * Returns CommunicationStatusDetails {status, httpStatus, message} given an HTTP status code
24
- *
25
- * Throws: Error if the HTTP status code is not supported (i.e. the 100 codes or non HTTP status code numbers)
26
- *
27
- * @param httpStatus - The HTTP status code to get the communication status for
28
- * @returns The communication status for the given HTTP status code
29
- */
30
- declare const getCommunicationStatusDetails: (httpStatus?: number) => CommunicationStatusDetails;
31
- declare const getCommunicationStatusOrUndefined: <T extends number | CommunicationStatus | null | undefined>(status: T) => T extends null | undefined ? undefined : (CommunicationStatus | undefined);
32
- declare const getCommunicationStatus: <T extends number | CommunicationStatus | null | undefined>(status: T) => T extends null | undefined ? undefined : CommunicationStatus;
33
- declare const getHttpStatus: (status: CommunicationStatus) => number;
34
75
 
35
76
  /**
36
77
  * HTTP 2xx responses
@@ -190,8 +231,28 @@ declare const failure: CommunicationStatus;
190
231
  */
191
232
  declare const timeoutFailure: CommunicationStatus;
192
233
 
234
+ declare const getCommunicationStatusOrUndefined: <T extends number | CommunicationStatus | null | undefined>(status: T) => T extends null | undefined ? undefined : (CommunicationStatus | undefined);
235
+ declare const getCommunicationStatus: <T extends number | CommunicationStatus | null | undefined>(status: T) => T extends null | undefined ? undefined : CommunicationStatus;
236
+ /**
237
+ * Returns the HTTP status code for a given CommunicationStatus or number
238
+ * If the input is null or undefined, returns undefined, otherwise throws an error if the CommunicationStatus or number is not supported
239
+ * @param status - The CommunicationStatus or number to get the HTTP status code for
240
+ * @returns The HTTP status code for the given CommunicationStatus or number
241
+ */
242
+ declare const getHttpStatus: <T extends CommunicationStatus | number | null | undefined>(status: T) => T extends null | undefined ? undefined : number;
243
+ /**
244
+ * Returns CommunicationStatusDetails {status, httpStatus, message} given an HTTP status code
245
+ *
246
+ * Throws: Error if the HTTP status code is not supported (i.e. the 100 codes or non HTTP status code numbers)
247
+ *
248
+ * @param status - The HTTP status code to get the communication status for
249
+ * @returns The CommunicationStatusDetails for the given status. Note, if an HTTP status is given, it won't necessarily be the httpStatus returned; HTTPStatuses are simplified along with CommunicationStatuses.
250
+ */
251
+ declare const getCommunicationStatusDetails: <T extends number | CommunicationStatus | null | undefined>(status: T) => T extends null | undefined ? undefined : CommunicationStatusDetails;
252
+ declare const getCommunicationStatusDetailsOrUndefined: <T extends number | CommunicationStatus | null | undefined>(status: T) => T extends null | undefined ? undefined : (CommunicationStatusDetails | undefined);
253
+
193
254
  /** Returns true for HTTP 2xx responses */
194
- declare const isSuccess: (status: CommunicationStatus) => boolean;
255
+ declare const isSuccess: (status: HttpOrCommunicationStatus) => boolean;
195
256
  /**
196
257
  * Returns true for any error response (HTTP 4xx/5xx) or network/abort failures
197
258
  *
@@ -204,7 +265,7 @@ declare const isSuccess: (status: CommunicationStatus) => boolean;
204
265
  * Client Can:
205
266
  * - Use a different is* function for more specific checks
206
267
  */
207
- declare const isFailure: (status: CommunicationStatus) => boolean;
268
+ declare const isFailure: (status: HttpOrCommunicationStatus) => boolean | undefined;
208
269
  /**
209
270
  * Returns true for client-side errors
210
271
  *
@@ -223,7 +284,7 @@ declare const isFailure: (status: CommunicationStatus) => boolean;
223
284
  * - use isClientFailureNotAuthorized to check for 401/403/407/451
224
285
  * - fix the request to avoid the 4xx error
225
286
  */
226
- declare const isClientFailure: (status: CommunicationStatus) => boolean;
287
+ declare const isClientFailure: (status: HttpOrCommunicationStatus) => boolean | undefined;
227
288
  /**
228
289
  * Returns true for server-side errors
229
290
  *
@@ -243,7 +304,7 @@ declare const isClientFailure: (status: CommunicationStatus) => boolean;
243
304
  * - fix the server to avoid the 5xx error
244
305
  * - fix server infrastructure to avoid the 5xx error (e.g. Bad Gateway, Service Unavailable, Gateway Timeout)
245
306
  */
246
- declare const isServerFailure: (status: CommunicationStatus) => boolean;
307
+ declare const isServerFailure: (status: HttpOrCommunicationStatus) => boolean | undefined;
247
308
  /**
248
309
  * Returns true when request fails due to network connectivity issues
249
310
  *
@@ -256,9 +317,9 @@ declare const isServerFailure: (status: CommunicationStatus) => boolean;
256
317
  * Client Developer Can:
257
318
  * - fix bad network constants (like address, ports, etc.)
258
319
  */
259
- declare const isNetworkFailure: (status: CommunicationStatus) => boolean;
320
+ declare const isNetworkFailure: (status: HttpOrCommunicationStatus) => boolean;
260
321
  /** Returns true for server errors, network failures and aborted requests; i.e. the client did nothing wrong (as far as we can tell); client can ask the user to do something OR retry the request */
261
- declare const isNonClientFailure: (status: CommunicationStatus) => boolean;
322
+ declare const isNonClientFailure: (status: HttpOrCommunicationStatus) => boolean | undefined;
262
323
  /**
263
324
  * Returns true for unauthorized requests (not authenticated or not authorized)
264
325
  *
@@ -277,7 +338,7 @@ declare const isNonClientFailure: (status: CommunicationStatus) => boolean;
277
338
  * Client and Server Developer Can:
278
339
  * - fix authorization / authentication bugs
279
340
  */
280
- declare const isClientFailureNotAuthorized: (status: CommunicationStatus) => boolean;
341
+ declare const isClientFailureNotAuthorized: (status: HttpOrCommunicationStatus) => boolean;
281
342
  /**
282
343
  * Returns true when request was cancelled by client
283
344
  *
@@ -288,7 +349,7 @@ declare const isClientFailureNotAuthorized: (status: CommunicationStatus) => boo
288
349
  * Client Developer Can:
289
350
  * - fix the client to not abort the request
290
351
  */
291
- declare const isAborted: (status: CommunicationStatus) => boolean;
352
+ declare const isAborted: (status: HttpOrCommunicationStatus) => boolean;
292
353
  /**
293
354
  * Returns true when resource not found / not available
294
355
  *
@@ -303,7 +364,7 @@ declare const isAborted: (status: CommunicationStatus) => boolean;
303
364
  * Client Developer Can:
304
365
  * - fix the bad resource paths
305
366
  */
306
- declare const isMissing: (status: CommunicationStatus) => boolean;
367
+ declare const isMissing: (status: HttpOrCommunicationStatus) => boolean;
307
368
  /**
308
369
  * Returns true while request is in progress
309
370
  *
@@ -315,7 +376,7 @@ declare const isMissing: (status: CommunicationStatus) => boolean;
315
376
  * Client Developer Can:
316
377
  * - if "pending" was not expected, maybe the client needs to `wait` for the request to complete?
317
378
  */
318
- declare const isPending: (status: CommunicationStatus) => boolean;
379
+ declare const isPending: (status: HttpOrCommunicationStatus) => boolean;
319
380
  /**
320
381
  * Returns true if the request timed out
321
382
  *
@@ -329,7 +390,7 @@ declare const isPending: (status: CommunicationStatus) => boolean;
329
390
  * Server Developer Can:
330
391
  * - improve server performance and reliability
331
392
  */
332
- declare const isTimeout: (status: CommunicationStatus) => boolean;
393
+ declare const isTimeout: (status: HttpOrCommunicationStatus) => boolean;
333
394
  /**
334
395
  * Returns true if client can safely retry the request
335
396
  *
@@ -344,10 +405,10 @@ declare const isTimeout: (status: CommunicationStatus) => boolean;
344
405
  * Client and Server Devs can
345
406
  * - investigate network, client and server performance and reliability issues
346
407
  */
347
- declare const isRetryableFailure: (status: CommunicationStatus) => boolean;
408
+ declare const isRetryableFailure: (status: HttpOrCommunicationStatus) => boolean | undefined;
348
409
  /**
349
410
  * Returns true if the status is a valid communication status
350
411
  */
351
412
  declare const isStatusValid: (status: string) => boolean;
352
413
 
353
- export { type CommunicationStatus, type CommunicationStatusDetails, type CommunicationStatuses, aborted, clientFailure, clientFailureNotAuthorized, communicationStatuses, failure, getCommunicationStatus, getCommunicationStatusDetails, getCommunicationStatusFromHttpStatus, getCommunicationStatusFromHttpStatusOrUndefined, getCommunicationStatusOrUndefined, getHttpStatus, isAborted, isClientFailure, isClientFailureNotAuthorized, isFailure, isMissing, isNetworkFailure, isNonClientFailure, isPending, isRetryableFailure, isServerFailure, isStatusValid, isSuccess, isTimeout, missing, networkFailure, pending, serverFailure, statusRegex, success, timeoutFailure };
414
+ export { type CommunicationStatus, type CommunicationStatusDetails, type CommunicationStatuses, type HttpOrCommunicationStatus, aborted, clientFailure, clientFailureNotAuthorized, communicationStatuses, failure, getCommunicationStatus, getCommunicationStatusDetails, getCommunicationStatusDetailsOrUndefined, getCommunicationStatusOrUndefined, getHttpStatus, isAborted, isClientFailure, isClientFailureNotAuthorized, isFailure, isMissing, isNetworkFailure, isNonClientFailure, isPending, isRetryableFailure, isServerFailure, isStatusValid, isSuccess, isTimeout, missing, networkFailure, pending, serverFailure, statusRegex, success, timeoutFailure };
package/dist/index.js CHANGED
@@ -10,37 +10,156 @@ var pending = "pending";
10
10
  var failure = "failure";
11
11
  var timeoutFailure = "timeoutFailure";
12
12
 
13
+ // ../art-core-ts-types/dist/index.js
14
+ var isObject = (v) => v != null && typeof v === "object";
15
+ var isPlainObject = (v) => {
16
+ if (!isObject(v)) return false;
17
+ if (v.constructor === Object) return true;
18
+ const prototype = Object.getPrototypeOf(v);
19
+ if (prototype === null) return true;
20
+ return null == Object.getPrototypeOf(prototype);
21
+ };
22
+ var isFunction = (obj) => typeof obj === "function";
23
+ var exists = (value) => value != null;
24
+
25
+ // ../art-core-ts-comprehensions/dist/index.js
26
+ var isMap = (source) => source instanceof Map;
27
+ var isArrayIterable = (source) => {
28
+ if (typeof source === "string") return false;
29
+ if (isFunction(source)) return false;
30
+ return source != null && source.length >= 0;
31
+ };
32
+ var isOfIterable = (o) => {
33
+ if (typeof o === "string") return false;
34
+ if (isFunction(o)) return false;
35
+ return isFunction(o[Symbol.iterator] || o.next);
36
+ };
37
+ var returnFirstArg = (a) => a;
38
+ var returnSecondArg = (a, b) => b;
39
+ var iterate = (source, body) => {
40
+ if (exists(source))
41
+ if (isArrayIterable(source)) for (let key = 0, { length } = source; key < length; key++) {
42
+ if (body(source[key], key)) break;
43
+ }
44
+ else if (isPlainObject(source)) for (const key in source) {
45
+ if (body(source[key], key)) break;
46
+ }
47
+ else if (isMap(source)) for (const [key, value] of source.entries()) {
48
+ if (body(value, key)) break;
49
+ }
50
+ else if (isOfIterable(source)) {
51
+ let count = 0;
52
+ for (const value of source) {
53
+ if (body(value, count++)) break;
54
+ }
55
+ } else throw new Error(`Unsupported source type: ${typeof source}`);
56
+ };
57
+ var normalizeBody = (withFunction, options) => {
58
+ let { when, stopWhen } = options;
59
+ if (when && stopWhen) {
60
+ return (v, k) => {
61
+ if (stopWhen(v, k)) return true;
62
+ if (when(v, k)) withFunction(v, k);
63
+ return false;
64
+ };
65
+ }
66
+ if (when) {
67
+ return (v, k) => {
68
+ if (when(v, k)) withFunction(v, k);
69
+ return false;
70
+ };
71
+ }
72
+ if (stopWhen) {
73
+ return (v, k) => {
74
+ if (stopWhen(v, k)) return true;
75
+ withFunction(v, k);
76
+ return false;
77
+ };
78
+ }
79
+ return (v, k) => {
80
+ withFunction(v, k);
81
+ return false;
82
+ };
83
+ };
84
+ var normalizeKeyFunction = (source, options) => options.withKey || (isArrayIterable(source) ? returnFirstArg : returnSecondArg);
85
+ var _each = (source, withFunction, options) => {
86
+ iterate(source, normalizeBody(withFunction, options));
87
+ };
88
+ var normalizedObjectIteration = (source, options) => {
89
+ let { into, with: withFunction } = options;
90
+ if (into == null) into = {};
91
+ let withKey = normalizeKeyFunction(source, options);
92
+ _each(source, (v, k) => into[withKey(v, k)] = withFunction(v, k), options);
93
+ return into;
94
+ };
95
+ var isAcceptedComprehensionOptions = (o) => isPlainObject(o);
96
+ var firstNotUndefined = (into, inject, returning) => {
97
+ if (into === void 0) into = inject;
98
+ if (into === void 0) into = returning;
99
+ return into;
100
+ };
101
+ var normalizeIterationParams = (withOrOptions) => {
102
+ if (isAcceptedComprehensionOptions(withOrOptions)) {
103
+ const { with: withFunction, into, inject, returning, ...rest } = withOrOptions;
104
+ return { ...rest, into: firstNotUndefined(into, inject, returning), with: withFunction ?? returnFirstArg };
105
+ }
106
+ if (isFunction(withOrOptions)) {
107
+ return { with: withOrOptions };
108
+ }
109
+ return { with: returnFirstArg };
110
+ };
111
+ var invokeNormalizedIteration = (normalizedIterationFunction, source, withOrOptions) => normalizedIterationFunction(source, normalizeIterationParams(withOrOptions));
112
+ var object = ((source, withOrOptions) => invokeNormalizedIteration(normalizedObjectIteration, source, withOrOptions));
113
+
13
114
  // src/CommunicationStatusTypes.ts
14
- var communicationStatuses = {
115
+ var communicationStatusesPartials = {
116
+ // HTTP Success Statuses
15
117
  success: { httpStatus: 200 },
118
+ // HTTP Failure Statuses
16
119
  missing: { httpStatus: 404, failure: true },
17
120
  clientFailure: { httpStatus: 400, clientFailure: true, failure: true },
18
121
  clientFailureNotAuthorized: { httpStatus: 403, clientFailure: true, failure: true },
19
122
  serverFailure: { httpStatus: 500, failure: true, serverFailure: true },
20
- networkFailure: { failure: true },
21
- aborted: { failure: true },
22
- pending: {},
23
123
  failure: { httpStatus: 500, failure: true },
24
- timeoutFailure: { failure: true }
124
+ // Non-HTTP Statuses
125
+ pending: { httpStatus: void 0 },
126
+ networkFailure: { httpStatus: void 0, failure: true },
127
+ aborted: { httpStatus: void 0, failure: true },
128
+ timeoutFailure: { httpStatus: void 0, failure: true }
25
129
  };
130
+ var communicationStatuses = object(communicationStatusesPartials, (details, status) => ({
131
+ ...details,
132
+ failure: !!details.failure,
133
+ clientFailure: !!details.clientFailure,
134
+ serverFailure: !!details.serverFailure,
135
+ status,
136
+ communicationStatus: status,
137
+ message: details.httpStatus ? `${status} (${details.httpStatus})` : status
138
+ }));
26
139
  var statusRegex = new RegExp(`^(${Object.keys(communicationStatuses).join("|")})$`);
27
140
 
28
141
  // src/CommunicationStatusTests.ts
29
- var isSuccess = (status) => status === success;
30
- var isFailure = (status) => !!communicationStatuses[status]?.failure;
31
- var isClientFailure = (status) => !!communicationStatuses[status]?.clientFailure;
32
- var isServerFailure = (status) => !!communicationStatuses[status]?.serverFailure;
33
- var isNetworkFailure = (status) => status === networkFailure;
34
- var isNonClientFailure = (status) => isFailure(status) && !isClientFailure(status);
35
- var isClientFailureNotAuthorized = (status) => status === clientFailureNotAuthorized;
36
- var isAborted = (status) => status === aborted;
37
- var isMissing = (status) => status === missing;
38
- var isPending = (status) => status === pending;
39
- var isTimeout = (status) => status === timeoutFailure;
40
- var isRetryableFailure = (status) => isNetworkFailure(status) || isTimeout(status) || isAborted(status);
142
+ var isSuccess = (status) => getCommunicationStatus(status) === success;
143
+ var isFailure = (status) => getCommunicationStatusDetails(status).failure;
144
+ var isClientFailure = (status) => getCommunicationStatusDetails(status).clientFailure;
145
+ var isServerFailure = (status) => getCommunicationStatusDetails(status).serverFailure;
146
+ var isNetworkFailure = (status) => getCommunicationStatus(status) === networkFailure;
147
+ var isNonClientFailure = (status) => {
148
+ const details = getCommunicationStatusDetails(status);
149
+ return details.failure && !details.clientFailure;
150
+ };
151
+ var isClientFailureNotAuthorized = (status) => getCommunicationStatus(status) === clientFailureNotAuthorized;
152
+ var isAborted = (status) => getCommunicationStatus(status) === aborted;
153
+ var isMissing = (status) => getCommunicationStatus(status) === missing;
154
+ var isPending = (status) => getCommunicationStatus(status) === pending;
155
+ var isTimeout = (status) => getCommunicationStatus(status) === timeoutFailure;
156
+ var isRetryableFailure = (status) => {
157
+ const { status: communicationStatus, failure: failure2 } = getCommunicationStatusDetails(status);
158
+ return failure2 && (communicationStatus === networkFailure || communicationStatus === timeoutFailure || communicationStatus === aborted);
159
+ };
41
160
  var isStatusValid = (status) => statusRegex.test(status);
42
161
 
43
- // src/CommunicationStatus.ts
162
+ // src/CommunicationStatusConversions.ts
44
163
  var getCommunicationStatusFromHttpStatusOrUndefined = (httpStatus) => {
45
164
  switch (Math.floor(httpStatus / 100)) {
46
165
  case 2:
@@ -87,15 +206,6 @@ var getCommunicationStatusFromHttpStatus = (httpStatus) => {
87
206
  }
88
207
  return status;
89
208
  };
90
- var getCommunicationStatusDetails = (httpStatus) => {
91
- if (!httpStatus) return { status: networkFailure, message: "network failure" };
92
- const status = getCommunicationStatusFromHttpStatus(httpStatus);
93
- return {
94
- status,
95
- httpStatus,
96
- message: `${status} (${httpStatus})`
97
- };
98
- };
99
209
  var getCommunicationStatusOrUndefined = (status) => {
100
210
  if (status == null) return void 0;
101
211
  if (typeof status === "string") {
@@ -121,10 +231,25 @@ var getCommunicationStatus = (status) => {
121
231
  return communicationStatus;
122
232
  };
123
233
  var getHttpStatus = (status) => {
124
- const httpStatus = communicationStatuses[status]?.httpStatus;
125
- if (!httpStatus) throw new Error(`There is no valid HttpStatus for ${status}.`);
234
+ if (status == null) return void 0;
235
+ const communicationStatus = getCommunicationStatus(status);
236
+ const httpStatus = communicationStatuses[communicationStatus].httpStatus;
237
+ if (httpStatus == null) {
238
+ throw new Error(`There is no valid HttpStatus for ${status}.`);
239
+ }
126
240
  return httpStatus;
127
241
  };
242
+ var getCommunicationStatusDetails = (status) => {
243
+ if (status == null) return void 0;
244
+ const communicationStatus = getCommunicationStatus(status);
245
+ return communicationStatuses[communicationStatus];
246
+ };
247
+ var getCommunicationStatusDetailsOrUndefined = (status) => {
248
+ if (status == null) return void 0;
249
+ const communicationStatus = getCommunicationStatusOrUndefined(status);
250
+ if (communicationStatus == null) return void 0;
251
+ return communicationStatuses[communicationStatus];
252
+ };
128
253
  export {
129
254
  aborted,
130
255
  clientFailure,
@@ -133,8 +258,7 @@ export {
133
258
  failure,
134
259
  getCommunicationStatus,
135
260
  getCommunicationStatusDetails,
136
- getCommunicationStatusFromHttpStatus,
137
- getCommunicationStatusFromHttpStatusOrUndefined,
261
+ getCommunicationStatusDetailsOrUndefined,
138
262
  getCommunicationStatusOrUndefined,
139
263
  getHttpStatus,
140
264
  isAborted,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/CommunicationStatusConsts.ts","../src/CommunicationStatusTypes.ts","../src/CommunicationStatusTests.ts","../src/CommunicationStatus.ts"],"sourcesContent":["// Export status constants\nimport type { CommunicationStatus } from './CommunicationStatusTypes'\n\n/**\n * HTTP 2xx responses\n *\n * Client Can Automatically:\n * - Process the successful response\n * - Update UI to reflect success\n *\n * Client Developer Can:\n * - Handle the successful response data\n */\nexport const success: CommunicationStatus = \"success\"\n\n/**\n * Resource not found\n *\n * HTTP Status Codes Covered:\n * - 404: Not Found\n *\n * Client Can Automatically:\n * - notify the user that the resource was not found\n * - prompt the user to request a different resource\n *\n * Client Developer Can:\n * - fix the bad resource paths\n */\nexport const missing: CommunicationStatus = \"missing\"\n\n/**\n * Client-side errors; i.e. the client needs to change the request somehow to succeed\n *\n * HTTP Status Codes Covered:\n * - 400: Bad Request\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 409: Conflict\n * - 422: Unprocessable Entity\n *\n * Client Can Automatically:\n * - Notify the user that the client is experiencing issues\n * - Prompt user to correct invalid input\n *\n * Client Developer Can:\n * - use isClientFailureNotAuthorized to check for 401/403/407/451\n * - fix the request to avoid the 4xx error\n * - validate input before sending requests\n */\nexport const clientFailure: CommunicationStatus = \"clientFailure\"\n\n/**\n * Unauthorized requests; i.e. client needs to change the credentials (or the grants for the current credentials) to succeed\n *\n * HTTP Status Codes Covered:\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 451: Unavailable For Legal Reasons\n *\n * Client Can Automatically:\n * - refresh the request token\n * - prompt the user to re-login\n * - ask the user to contact the administrator for access\n *\n * Client and Server Developer Can:\n * - fix authorization / authentication bugs\n */\nexport const clientFailureNotAuthorized: CommunicationStatus = \"clientFailureNotAuthorized\"\n\n/**\n * Server-side errors; i.e. internal server errors\n *\n * HTTP Status Codes Covered:\n * - 500: Internal Server Error\n * - 502: Bad Gateway\n * - 503: Service Unavailable\n * - 504: Gateway Timeout\n *\n * Client Can Automatically:\n * - Ask the user to try again later\n * - Notify the user that the server is experiencing issues\n * - Implement automatic retry with backoff\n *\n * Client Developer: (probably) can't fix\n *\n * Server Developer Can:\n * - fix the server to avoid the 5xx error\n * - fix server infrastructure to avoid the 5xx error\n */\nexport const serverFailure: CommunicationStatus = \"serverFailure\"\n\n/**\n * Request fails due to network connectivity issues\n *\n * HTTP Status Codes Covered: NONE (server was not reachable)\n *\n * Client Can Automatically:\n * - Prompt the user to fix the network connection\n * - Retry the request when network is available\n * - Monitor network status for recovery\n *\n * Client Developer Can:\n * - fix bad network constants (like address, ports, etc.)\n * - implement offline-first capabilities\n */\nexport const networkFailure: CommunicationStatus = \"networkFailure\"\n\n/**\n * Request was cancelled by client\n *\n * Client Can Automatically:\n * - notify the user that the request was cancelled\n * - prompt the user to try again\n * - cleanup any pending state\n *\n * Client Developer Can:\n * - fix the client to not abort the request unnecessarily\n * - implement proper cleanup on abort\n */\nexport const aborted: CommunicationStatus = \"aborted\"\n\n/**\n * Request is in progress\n *\n * Client Can Automatically:\n * - notify the user that the request is in progress\n * - show the user progress (if available)\n * - allow the user to cancel the request\n *\n * Client Developer Can:\n * - if \"pending\" was not expected, maybe the client needs to `wait` for the request to complete?\n * - implement proper loading states\n */\nexport const pending: CommunicationStatus = \"pending\"\n\n/**\n * Any error response (HTTP 4xx/5xx) or network/abort failures\n *\n * HTTP Status Codes Covered:\n * - 4xx: Client-side errors (except 404)\n * - 5xx: Server-side errors\n * - Network failures\n * - Abort failures\n *\n * Client Can Automatically:\n * - Show appropriate error message to user\n * - Implement generic error handling\n * - Log errors for debugging\n *\n * Client Developer Can:\n * - Use more specific is* functions for targeted error handling\n * - Implement proper error recovery strategies\n */\nexport const failure: CommunicationStatus = \"failure\"\n\n/**\n * Request timed out\n *\n * Client Can Automatically:\n * - notify the user that the request timed out\n * - try again (automatically or via user action)\n *\n * Client Developer Can:\n * - fix the client to not timeoutFailure the request\n * - implement proper timeoutFailure handling\n */\nexport const timeoutFailure: CommunicationStatus = \"timeoutFailure\"\n","interface CommunicationStatusInfo {\n httpStatus?: number\n failure?: boolean\n clientFailure?: boolean\n serverFailure?: boolean\n}\n\nexport const communicationStatuses: Record<string, CommunicationStatusInfo> = {\n success: { httpStatus: 200 },\n missing: { httpStatus: 404, failure: true },\n clientFailure: { httpStatus: 400, clientFailure: true, failure: true },\n clientFailureNotAuthorized: { httpStatus: 403, clientFailure: true, failure: true },\n serverFailure: { httpStatus: 500, failure: true, serverFailure: true },\n networkFailure: { failure: true },\n aborted: { failure: true },\n pending: {},\n failure: { httpStatus: 500, failure: true },\n timeoutFailure: { failure: true }\n}\n\nexport type CommunicationStatuses = typeof communicationStatuses\nexport type CommunicationStatus = keyof CommunicationStatuses\n\n/**\n * RegEx returns true for all valid communication statuses\n */\nexport const statusRegex = new RegExp(`^(${Object.keys(communicationStatuses).join('|')})$`)\n\nexport interface CommunicationStatusDetails {\n status: CommunicationStatus\n httpStatus?: number\n message: string\n}\n","import { communicationStatuses, CommunicationStatus, statusRegex } from './CommunicationStatusTypes'\nimport { success, missing, clientFailure, clientFailureNotAuthorized, serverFailure, networkFailure, aborted, pending, timeoutFailure } from './CommunicationStatusConsts'\n\n// Core status check functions\n/** Returns true for HTTP 2xx responses */\nexport const isSuccess = (status: CommunicationStatus) => status === success\n\n/**\n * Returns true for any error response (HTTP 4xx/5xx) or network/abort failures\n *\n * HTTP Status Codes Covered:\n * - 4xx: Client-side errors (except 404)\n * - 5xx: Server-side errors\n * - Network failures\n * - Abort failures\n *\n * Client Can:\n * - Use a different is* function for more specific checks\n */\nexport const isFailure = (status: CommunicationStatus) => !!communicationStatuses[status]?.failure\n\n/**\n * Returns true for client-side errors\n *\n * HTTP Status Codes Covered:\n * - 400: Bad Request\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 409: Conflict\n * - 422: Unprocessable Entity\n *\n * Client Can Automatically:\n * - Notify the user that the client is experiencing issues\n *\n * Client Developer Can:\n * - use isClientFailureNotAuthorized to check for 401/403/407/451\n * - fix the request to avoid the 4xx error\n*/\nexport const isClientFailure = (status: CommunicationStatus) => !!communicationStatuses[status]?.clientFailure\n\n/**\n * Returns true for server-side errors\n *\n * HTTP Status Codes Covered:\n * - 500: Internal Server Error\n * - 502: Bad Gateway\n * - 503: Service Unavailable\n * - 504: Gateway Timeout\n *\n * Client Can Automatically:\n * - Ask the user to try again later\n * - Notify the user that the server is experiencing issues\n *\n * Client Developer: (probably) can't fix\n *\n * Server Developer Can:\n * - fix the server to avoid the 5xx error\n * - fix server infrastructure to avoid the 5xx error (e.g. Bad Gateway, Service Unavailable, Gateway Timeout)\n*/\nexport const isServerFailure = (status: CommunicationStatus) => !!communicationStatuses[status]?.serverFailure\n\n/**\n * Returns true when request fails due to network connectivity issues\n *\n * HTTP Status Codes Covered: NONE (server was not reachable)\n *\n * Client Can Automatically:\n * - Prompt the user to fix the network connection\n * - Retry the request\n *\n * Client Developer Can:\n * - fix bad network constants (like address, ports, etc.)\n*/\nexport const isNetworkFailure = (status: CommunicationStatus) => status === networkFailure\n\n/** Returns true for server errors, network failures and aborted requests; i.e. the client did nothing wrong (as far as we can tell); client can ask the user to do something OR retry the request */\nexport const isNonClientFailure = (status: CommunicationStatus) => isFailure(status) && !isClientFailure(status)\n\n/**\n * Returns true for unauthorized requests (not authenticated or not authorized)\n *\n * HTTP Status Codes Covered:\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 451: Unavailable For Legal Reasons\n * - 511: Network Authentication Required\n *\n * Client Can Automatically:\n * - refresh the request token\n * - prompt the user to re-login\n * - ask the user to contact the administrator for access\n *\n * Client and Server Developer Can:\n * - fix authorization / authentication bugs\n */\nexport const isClientFailureNotAuthorized = (status: CommunicationStatus) => status === clientFailureNotAuthorized\n\n/**\n * Returns true when request was cancelled by client\n *\n * Client Can Automatically:\n * - notify the user that the request was cancelled\n * - prompt the user to try again\n *\n * Client Developer Can:\n * - fix the client to not abort the request\n */\nexport const isAborted = (status: CommunicationStatus) => status === aborted\n\n/**\n * Returns true when resource not found / not available\n *\n * HTTP Status Codes Covered:\n * - 404: Not Found\n * - 501: Not Implemented\n *\n * Client Can Automatically:\n * - notify the user that the resource was not found\n * - prompt the user to request a different resource\n *\n * Client Developer Can:\n * - fix the bad resource paths\n */\nexport const isMissing = (status: CommunicationStatus) => status === missing\n\n/**\n * Returns true while request is in progress\n *\n * Client Can Automatically:\n * - notify the user that the request is in progress\n * - show the user progress (if available)\n * - allow the user to cancel the request (trigging an \"aborted\" communication status)\n *\n * Client Developer Can:\n * - if \"pending\" was not expected, maybe the client needs to `wait` for the request to complete?\n */\nexport const isPending = (status: CommunicationStatus) => status === pending\n\n/**\n * Returns true if the request timed out\n *\n * Client Can Automatically:\n * - notify the user that the request timed out\n * - try again (automatically or via user action)\n *\n * Client Developer Can:\n * - extend the timeoutFailure duration\n *\n * Server Developer Can:\n * - improve server performance and reliability\n */\nexport const isTimeout = (status: CommunicationStatus) => status === timeoutFailure\n\n/**\n * Returns true if client can safely retry the request\n *\n * A a clearly-retryable failure:\n *\n * - network failure\n * - timeoutFailure\n * - aborted\n *\n * Note: some serverFailures will succeed on retry, but HTTP doesn't return clear indications which ones. To be safe, the client should not retry serverFailures indiscriminately.\n *\n * Client and Server Devs can\n * - investigate network, client and server performance and reliability issues\n */\nexport const isRetryableFailure = (status: CommunicationStatus) => isNetworkFailure(status) || isTimeout(status) || isAborted(status)\n\n/**\n * Returns true if the status is a valid communication status\n */\nexport const isStatusValid = (status: string) => statusRegex.test(status);\n","import { clientFailure, clientFailureNotAuthorized, missing, networkFailure, serverFailure, success } from './CommunicationStatusConsts';\nimport { isStatusValid } from './CommunicationStatusTests';\nimport { CommunicationStatus, CommunicationStatusDetails, communicationStatuses } from './CommunicationStatusTypes';\n\nexport const getCommunicationStatusFromHttpStatusOrUndefined = (httpStatus: number): CommunicationStatus | undefined => {\n switch (Math.floor(httpStatus / 100)) {\n case 2: return success;\n case 3: return missing;\n case 4:\n switch (httpStatus) {\n case 401:\n case 403:\n case 407:\n case 451: return clientFailureNotAuthorized;\n case 404: return missing;\n default: return clientFailure;\n }\n case 5:\n switch (httpStatus) {\n case 502:\n case 503:\n case 504: return networkFailure;\n case 511: return clientFailureNotAuthorized;\n case 501: return missing; // 501 Not Implemented - i.e. it \"does not exist\" currently - i.e. missing\n case 505: // HTTP Version Not Supported - client should change the request\n case 530: return clientFailure;\n default: return serverFailure;\n }\n }\n return undefined;\n};\n\nexport const getCommunicationStatusFromHttpStatus = (httpStatus: number): CommunicationStatus => {\n const status = getCommunicationStatusFromHttpStatusOrUndefined(httpStatus);\n if (!status) {\n throw new Error(`httpStatus ${httpStatus} is not a supported CommunicationStatus.`);\n }\n return status;\n};\n\n/**\n * Returns CommunicationStatusDetails {status, httpStatus, message} given an HTTP status code\n *\n * Throws: Error if the HTTP status code is not supported (i.e. the 100 codes or non HTTP status code numbers)\n *\n * @param httpStatus - The HTTP status code to get the communication status for\n * @returns The communication status for the given HTTP status code\n */\nexport const getCommunicationStatusDetails = (httpStatus?: number): CommunicationStatusDetails => {\n if (!httpStatus) return { status: networkFailure, message: \"network failure\" };\n\n const status = getCommunicationStatusFromHttpStatus(httpStatus);\n\n return {\n status,\n httpStatus,\n message: `${status} (${httpStatus})`\n };\n};\n\nexport const getCommunicationStatusOrUndefined = <T extends number | CommunicationStatus | null | undefined>(\n status: T\n): T extends null | undefined ? undefined : (CommunicationStatus | undefined) => {\n if (status == null) return undefined as any;\n if (typeof status === 'string') {\n if (!isStatusValid(status)) {\n return undefined;\n }\n return status as any;\n }\n if (typeof status === 'number') {\n return getCommunicationStatusFromHttpStatusOrUndefined(status) as any;\n }\n return undefined;\n};\n\nexport const getCommunicationStatus = <T extends number | CommunicationStatus | null | undefined>(\n status: T\n): T extends null | undefined ? undefined : CommunicationStatus => {\n if (status == null) return undefined as any;\n if (typeof status === 'number') {\n return getCommunicationStatusFromHttpStatus(status) as any;\n }\n const communicationStatus: CommunicationStatus | undefined = getCommunicationStatusOrUndefined(status);\n if (!communicationStatus) {\n throw new Error(`${status} is not a valid CommunicationStatus.`);\n }\n return communicationStatus as any;\n};\n\nexport const getHttpStatus = (status: CommunicationStatus): number => {\n const httpStatus = communicationStatuses[status]?.httpStatus;\n if (!httpStatus) throw new Error(`There is no valid HttpStatus for ${status}.`);\n return httpStatus;\n};\n"],"mappings":";AAaO,IAAM,UAA+B;AAerC,IAAM,UAA+B;AAsBrC,IAAM,gBAAqC;AAmB3C,IAAM,6BAAkD;AAsBxD,IAAM,gBAAqC;AAgB3C,IAAM,iBAAsC;AAc5C,IAAM,UAA+B;AAcrC,IAAM,UAA+B;AAoBrC,IAAM,UAA+B;AAarC,IAAM,iBAAsC;;;ACjK5C,IAAM,wBAAiE;AAAA,EAC5E,SAAS,EAAE,YAAY,IAAI;AAAA,EAC3B,SAAS,EAAE,YAAY,KAAK,SAAS,KAAK;AAAA,EAC1C,eAAe,EAAE,YAAY,KAAK,eAAe,MAAM,SAAS,KAAK;AAAA,EACrE,4BAA4B,EAAE,YAAY,KAAK,eAAe,MAAM,SAAS,KAAK;AAAA,EAClF,eAAe,EAAE,YAAY,KAAK,SAAS,MAAM,eAAe,KAAK;AAAA,EACrE,gBAAgB,EAAE,SAAS,KAAK;AAAA,EAChC,SAAS,EAAE,SAAS,KAAK;AAAA,EACzB,SAAS,CAAC;AAAA,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MAAM,GAAG;AAClD,MAAI,CAAC,WAAY,OAAM,IAAI,MAAM,oCAAoC,MAAM,GAAG;AAC9E,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/CommunicationStatusConsts.ts","../../art-core-ts-types/src/Types.ts","../../art-core-ts-comprehensions/src/Comprehensions.ts","../../art-core-ts-comprehensions/src/DeepComprehensions.ts","../src/CommunicationStatusTypes.ts","../src/CommunicationStatusTests.ts","../src/CommunicationStatusConversions.ts"],"sourcesContent":["// Export status constants\nimport type { CommunicationStatus } from './CommunicationStatusTypes'\n\n/**\n * HTTP 2xx responses\n *\n * Client Can Automatically:\n * - Process the successful response\n * - Update UI to reflect success\n *\n * Client Developer Can:\n * - Handle the successful response data\n */\nexport const success: CommunicationStatus = \"success\"\n\n/**\n * Resource not found\n *\n * HTTP Status Codes Covered:\n * - 404: Not Found\n *\n * Client Can Automatically:\n * - notify the user that the resource was not found\n * - prompt the user to request a different resource\n *\n * Client Developer Can:\n * - fix the bad resource paths\n */\nexport const missing: CommunicationStatus = \"missing\"\n\n/**\n * Client-side errors; i.e. the client needs to change the request somehow to succeed\n *\n * HTTP Status Codes Covered:\n * - 400: Bad Request\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 409: Conflict\n * - 422: Unprocessable Entity\n *\n * Client Can Automatically:\n * - Notify the user that the client is experiencing issues\n * - Prompt user to correct invalid input\n *\n * Client Developer Can:\n * - use isClientFailureNotAuthorized to check for 401/403/407/451\n * - fix the request to avoid the 4xx error\n * - validate input before sending requests\n */\nexport const clientFailure: CommunicationStatus = \"clientFailure\"\n\n/**\n * Unauthorized requests; i.e. client needs to change the credentials (or the grants for the current credentials) to succeed\n *\n * HTTP Status Codes Covered:\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 451: Unavailable For Legal Reasons\n *\n * Client Can Automatically:\n * - refresh the request token\n * - prompt the user to re-login\n * - ask the user to contact the administrator for access\n *\n * Client and Server Developer Can:\n * - fix authorization / authentication bugs\n */\nexport const clientFailureNotAuthorized: CommunicationStatus = \"clientFailureNotAuthorized\"\n\n/**\n * Server-side errors; i.e. internal server errors\n *\n * HTTP Status Codes Covered:\n * - 500: Internal Server Error\n * - 502: Bad Gateway\n * - 503: Service Unavailable\n * - 504: Gateway Timeout\n *\n * Client Can Automatically:\n * - Ask the user to try again later\n * - Notify the user that the server is experiencing issues\n * - Implement automatic retry with backoff\n *\n * Client Developer: (probably) can't fix\n *\n * Server Developer Can:\n * - fix the server to avoid the 5xx error\n * - fix server infrastructure to avoid the 5xx error\n */\nexport const serverFailure: CommunicationStatus = \"serverFailure\"\n\n/**\n * Request fails due to network connectivity issues\n *\n * HTTP Status Codes Covered: NONE (server was not reachable)\n *\n * Client Can Automatically:\n * - Prompt the user to fix the network connection\n * - Retry the request when network is available\n * - Monitor network status for recovery\n *\n * Client Developer Can:\n * - fix bad network constants (like address, ports, etc.)\n * - implement offline-first capabilities\n */\nexport const networkFailure: CommunicationStatus = \"networkFailure\"\n\n/**\n * Request was cancelled by client\n *\n * Client Can Automatically:\n * - notify the user that the request was cancelled\n * - prompt the user to try again\n * - cleanup any pending state\n *\n * Client Developer Can:\n * - fix the client to not abort the request unnecessarily\n * - implement proper cleanup on abort\n */\nexport const aborted: CommunicationStatus = \"aborted\"\n\n/**\n * Request is in progress\n *\n * Client Can Automatically:\n * - notify the user that the request is in progress\n * - show the user progress (if available)\n * - allow the user to cancel the request\n *\n * Client Developer Can:\n * - if \"pending\" was not expected, maybe the client needs to `wait` for the request to complete?\n * - implement proper loading states\n */\nexport const pending: CommunicationStatus = \"pending\"\n\n/**\n * Any error response (HTTP 4xx/5xx) or network/abort failures\n *\n * HTTP Status Codes Covered:\n * - 4xx: Client-side errors (except 404)\n * - 5xx: Server-side errors\n * - Network failures\n * - Abort failures\n *\n * Client Can Automatically:\n * - Show appropriate error message to user\n * - Implement generic error handling\n * - Log errors for debugging\n *\n * Client Developer Can:\n * - Use more specific is* functions for targeted error handling\n * - Implement proper error recovery strategies\n */\nexport const failure: CommunicationStatus = \"failure\"\n\n/**\n * Request timed out\n *\n * Client Can Automatically:\n * - notify the user that the request timed out\n * - try again (automatically or via user action)\n *\n * Client Developer Can:\n * - fix the client to not timeoutFailure the request\n * - implement proper timeoutFailure handling\n */\nexport const timeoutFailure: CommunicationStatus = \"timeoutFailure\"\n","import { PlainObject } from \"./TypeScriptTypes\"\n\ntype TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array\n\n/*\n\n @isPromise: (obj) => obj? && isFunction(obj.then) && !isFunction obj\n @isRegExp: (obj) => obj.constructor.name == \"RegExp\"\n @isNumber: isNumber = (obj) => typeof obj == \"number\"\n\n isNonNegativeInt: (x) ->\n ((x | 0) == x) &&\n x >= 0\n\n @isError: (obj) => obj? && obj instanceof Error\n @isDate: (obj) => obj?.constructor == Date\n @isString: isString = (obj) => typeof obj == \"string\"\n @isFunction: isFunction = (obj) => typeof obj == \"function\"\n @isEmptyObject: (obj) => Object.keys(obj).length == 0\n @isBoolean: (obj) => obj == true || obj == false\n\n @isArrayBuffer: isArrayBuffer = if global.ArrayBuffer\n (obj) -> obj? && obj.constructor == ArrayBuffer\n else -> false\n @isTypedArray: (obj) -> obj? && obj.length >= 0 && obj.length == (obj.length | 0) && isArrayBuffer obj.buffer\n\n */\n\n/**\n * Returns true if the value is an object. (note, Arrays are objects)\n * This is only false for null, undefined, functions, and primitives like strings, numbers, and booleans.\n * @param v\n * @returns\n */\nexport const isObject = (v: any): v is Record<string, any> => v != null && typeof v === 'object'\n\n/**\n * Returns true if the value is a plain object - i.e. an object who's prototype is Object\n * @param v\n * @returns\n */\nexport const isPlainObject = (v: any): v is PlainObject => {\n if (!isObject(v)) return false\n if (v.constructor === Object) return true // fast pass, but could fail if v was created in a different context with a different instance of Object\n const prototype = Object.getPrototypeOf(v)\n if (prototype === null) return true\n return null == Object.getPrototypeOf(prototype)\n}\n\nexport const asPlainObject = (v: any): PlainObject => isPlainObject(v) ? v : {}\n\nexport const isFunction = (obj: any): obj is Function => typeof obj === \"function\"\nexport const isNumber = (obj: any): obj is number => typeof obj === \"number\"\nexport const isString = (obj: any): obj is string => typeof obj === \"string\"\nexport const isArrayBuffer = (obj: any): obj is ArrayBuffer => obj != null && obj.constructor === ArrayBuffer\nexport const isArray = (obj: any): obj is any[] => Array.isArray(obj)\n\nexport const isPromise = (obj: any): obj is Promise<any> => obj != null && isFunction(obj.then) && !isFunction(obj)\nexport const isRegExp = (obj: any): obj is RegExp => obj?.constructor.name === \"RegExp\"\nexport const isError = (obj: any): obj is Error => obj != null && obj instanceof Error\nexport const isDate = (obj: any): obj is Date => obj?.constructor === Date\nexport const isEmptyObject = (obj: any): obj is Record<string, never> => Object.keys(obj).length === 0\nexport const isBoolean = (obj: any): obj is boolean => obj === true || obj === false\nexport const isTypedArray = (obj: any): obj is TypedArray =>\n obj != null &&\n obj.length >= 0 &&\n obj.length === (obj.length | 0) &&\n isArrayBuffer(obj.buffer)\n\nexport const isNonNegativeInt = (x: number): x is number => ((x | 0) === x) && x >= 0\n\nexport const stringIsPresent = (str: string): boolean => isString(str) && !/^(\\s+|)$/.test(str)\n\nexport const exists = (value: any): boolean => value != null\nexport const doesNotExist = (value: any): boolean => !exists(value)\n\nexport const isNull = (value: any): boolean => value === null\nexport const isNotNull = (value: any): boolean => !isNull(value)\n\nexport const isUndefined = (value: any): boolean => value === undefined\nexport const isNotUndefined = (value: any): boolean => !isUndefined(value)\n\nexport const isNullish = (value: any): boolean => value == null || value == undefined\nexport const isNotNullish = (value: any): boolean => !isNullish(value)\n\n/**\n * present returns true if \"there is a value _present_\"\n *\n * Specifically:\n * - if `value.getPresent()` is a function; it's called and it's value is returned\n * - if `value.present()` is a function; it's called and it's value is returned\n * - else: returns `true` if `!null`, `!undefined` and `!(string with only whitespace)`\n *\n * > Inspired by Ruby's `present?` method\n *\n * @param v\n * @returns\n */\nexport const present = <T>(v: T): v is NonNullable<T> => {\n if (v == null) return false\n if (isFunction((v as any).getPresent)) {\n return (v as any).getPresent()\n } else if (isFunction((v as any).present)) {\n return (v as any).present()\n } else if (isString(v)) {\n return stringIsPresent(v)\n } else return true\n}\n","import { isPlainObject, isFunction, exists } from '@art-suite/art-core-ts-types'\nimport { EachFunction, ArrayFunction, ObjectFunction, ReduceFunction, FindFunction, AnyContainer, ArrayInput, ObjectInput, NotPresent } from './ComprehensionTypes'\n\nconst isMap = (source: any): source is Map<any, any> => source instanceof Map;\nconst isSet = (source: any): source is Set<any> => source instanceof Set;\n\nexport const isArrayIterable = (source: any): source is any[] => {\n if (typeof source === 'string') return false\n if (isFunction(source)) return false\n return source != null && source.length >= 0;\n}\n\nexport const isOfIterable = (o: any): boolean => {\n if (typeof o === 'string') return false\n if (isFunction(o)) return false\n return isFunction(o[Symbol.iterator] || o.next)\n}\n\nconst returnFirstArg = (a: any) => a;\nconst returnSecondArg = (a: any, b: any) => b;\n\nconst emptyOptions = {};\n\ntype CoreIterationFunction = (value: any, key: any) => boolean; // returns true to stop iteration\n\n/**\n * Tight function to abstract away all possible iteration methods based on the source container type.\n *\n * Iterates over the source collection, calling the given function for each element.\n *\n * Stops when the body function returns true.\n * Does NOT return anything. If you need a return value, must set it as a side-effect of the body function.\n *\n * @param source - The collection to iterate (array, object, Map, Set, etc.)\n * @param body - The function to call for each element.\n * @returns void\n */\nconst iterate = (source: any, body: CoreIterationFunction): void => {\n if (exists(source))\n if (isArrayIterable(source)) for (let key = 0, { length } = source; key < length; key++) { if (body(source[key], key)) break; }\n else if (isPlainObject(source)) for (const key in source) { if (body(source[key], key)) break; }\n else if (isMap(source)) for (const [key, value] of source.entries()) { if (body(value, key)) break; }\n // else if (isSet(source)) for (const value of source) { if (body(value, value)) break; }\n else if (isOfIterable(source)) { let count = 0; for (const value of source) { if (body(value, count++)) break; } }\n else throw new Error(`Unsupported source type: ${typeof source}`);\n};\n\n/*\n Returns a function that handles \"with\", \"when\" and \"stopWhen\" comprehension clauses:\n\n 1. Returns true if the \"stopWhen\" is provided and returns true, otherwise returns it will return false\n 2. If stopWhen is false, \"when\" and \"with\" are processed\n 3. If there is no \"when\" or \"when\" returns true, \"with\" is called.\n*/\nconst normalizeBody = (withFunction: (value: any, key: any) => any, options: AcceptedComprehensionOptions): (value: any, key: any) => boolean => {\n let { when, stopWhen } = options;\n if (when && stopWhen) {\n return (v: any, k: any) => {\n if (stopWhen(v, k)) return true;\n if (when(v, k)) withFunction(v, k);\n return false;\n }\n }\n if (when) {\n return (v: any, k: any) => {\n if (when(v, k)) withFunction(v, k);\n return false;\n }\n }\n if (stopWhen) {\n return (v: any, k: any) => {\n if (stopWhen(v, k)) return true;\n withFunction(v, k);\n return false;\n }\n }\n return (v: any, k: any) => { withFunction(v, k); return false; };\n};\n\n\nlet normalizeKeyFunction = (source: any, options: AcceptedComprehensionOptions) =>\n options.withKey || (isArrayIterable(source) ? returnFirstArg : returnSecondArg)\n\nconst _each = (source: any, withFunction: (value: any, key: any) => any, options: AcceptedComprehensionOptions) => {\n iterate(source, normalizeBody(withFunction, options));\n};\n\n//************************************************************************\n// NORMALIZED COMPREHENSION FUNCTIONS\n//************************************************************************\ntype NormalizedIterationFunction = (source: any, options: NormalizedComprehensionOptions) => any;\n\nconst normalizedEach: NormalizedIterationFunction = (source: any, options: NormalizedComprehensionOptions) => {\n _each(source, options.with, options);\n return options.into;\n};\n\nconst normalizedArrayIteration: NormalizedIterationFunction = (source: any, options: NormalizedComprehensionOptions) => {\n let { into, with: withFunction } = options;\n if (into == null) into = [];\n _each(source, (v: any, k: any) => into.push(withFunction(v, k)), options);\n return into;\n};\n\nconst normalizedObjectIteration: NormalizedIterationFunction = (source: any, options: NormalizedComprehensionOptions) => {\n let { into, with: withFunction } = options;\n if (into == null) into = {};\n let withKey = normalizeKeyFunction(source, options);\n _each(source, (v, k) => (into[withKey(v, k)] = withFunction(v, k)), options);\n return into;\n};\n\nconst normalizedReduceIteration: NormalizedIterationFunction = (source: any, options: NormalizedComprehensionOptions) => {\n let { into, with: withFunction } = options;\n let first = into === undefined;\n _each(source, (v: any, k: any) => {\n if (first) { first = false; into = v; }\n else {\n into = withFunction(into, v, k)\n }\n }, options);\n return into;\n};\n\nconst normalizedFindIteration: NormalizedIterationFunction = (source: any, options: NormalizedComprehensionOptions) => {\n let { with: withFunction } = options;\n let { when } = options;\n let found: any | undefined = undefined;\n iterate(\n source,\n when\n ? (v, k) => {\n if (when(v, k)) {\n found = withFunction(v, k);\n return true; // signal to stop iteration\n }\n return false;\n }\n : (v, k) => {\n found = withFunction(v, k) // stops iteration if withFunction returns an value that \"exists\" (is not undefined, non null)\n return found != null;\n }\n );\n return found;\n};\n\n//####################\n// PRIVATE\n//####################\n\n// WithFunction has two signatures: value + key, or for reduce, accumulator + value + key\ntype ValueKeyFunction = (value?: any, key?: any) => any;\ntype AccumulatorValueKeyFunction = (accumulator?: any, value?: any, key?: any) => any;\ntype WithFunction = ValueKeyFunction | AccumulatorValueKeyFunction;\ntype WhenFunction = (value: any, key: any) => any;\ntype WithKeyFunction = (value: any, key: any) => any;\n\ntype AcceptedComprehensionOptions = {\n into?: any;\n inject?: any; // alias for into - used to make \"reduce\" calls make more sense\n returning?: any; // alias for into - used to make \"each\" calls make more sense\n with?: WithFunction;\n when?: WhenFunction;\n withKey?: WithKeyFunction;\n stopWhen?: (value: any, key: any) => any;\n}\n\ntype WithOrOptions = WithFunction | AcceptedComprehensionOptions;\n\nconst isAcceptedComprehensionOptions = (o: any): o is AcceptedComprehensionOptions => isPlainObject(o)\n\n// the 'with' param will always exist when normalized\ntype NormalizedComprehensionOptions = Omit<AcceptedComprehensionOptions, 'with' | 'inject' | 'returning'> & {\n with: WithFunction;\n}\n\n/**\n * Returns the first non-undefined value from into, inject, or returning\n *\n * @param into - The 'into' parameter.\n * @param inject - The 'inject' parameter.\n * @param returning - The 'returning' parameter.\n * @returns The normalized 'into' parameter.\n */\nconst firstNotUndefined = (into: any, inject: any, returning: any) => {\n if (into === undefined) into = inject\n if (into === undefined) into = returning\n return into\n}\n\nconst normalizeIterationParams = (withOrOptions?: WithOrOptions): NormalizedComprehensionOptions => {\n if (isAcceptedComprehensionOptions(withOrOptions)) {\n const { with: withFunction, into, inject, returning, ...rest } = withOrOptions;\n return { ...rest, into: firstNotUndefined(into, inject, returning), with: withFunction ?? returnFirstArg };\n }\n if (isFunction(withOrOptions)) {\n return { with: withOrOptions };\n }\n return { with: returnFirstArg };\n};\n\n/*\nNormalizes input params for the 'iteration' function.\nSince this normalizes multiple params, and therefor would need to return\nan new array or new object otherwise, we pass IN the iteration function\nand pass the params directly to it. This keeps the computed params on the\nstack and doesn't create new objects.\n\nIN signature 1: (iteration, source, withFunction) ->\nIN signature 2: (iteration, source, options) ->\nIN signature 3: (iteration, source) ->\n\nIN:\niteration: (source, into, withFunction, options) -> out\n\n The iteration function is invoked last with the computed args.\n Its results are returned.\n\n IN:\n source: passed directly through from inputs\n into: passed directly through from inputs OR from options.into\n withFunction: passed directly through from inputs OR from options.with\n options: passed directly through from inputs OR {}\n (guaranteed to be set and a plainObject)\n\nsource: the source collection to be iterated over. Passed directly through.\n\ninto: passed through to 'iteration'\nwithFunction: passed through to 'iteration'\noptions: passed through to 'iteration' AND:\n\n into: set 'into' from the options object\n with: set 'withFunction' from the options object\n\nOUT: out\n*/\nconst invokeNormalizedIteration = (\n normalizedIterationFunction: NormalizedIterationFunction,\n source: any,\n withOrOptions: WithOrOptions\n) => normalizedIterationFunction(source, normalizeIterationParams(withOrOptions));\n\n/**\n * Iterates over the provided collection, calling the given function for each element.\n *\n * Unlike other comprehensions, `each` is designed for side effects and does not build a new collection.\n *\n * **Return value:**\n * - If an `into`, `inject`, or `returning` option is provided (or as the second argument), that value is returned (not modified by `each` itself).\n * - If no such value is provided, returns `undefined`.\n *\n * This allows you to use `each` for side effects while optionally threading a value through the iteration.\n *\n * @param source The collection to iterate (array, object, Map, Set, etc.)\n * @param withOrOptions Optional: Either the `into` value or the function to call for each element.\n * @returns The `into`/`inject`/`returning` value if provided, otherwise `undefined`.\n */\nexport const each: EachFunction = ((source: any, withOrOptions: WithOrOptions) => invokeNormalizedIteration(normalizedEach, source, withOrOptions)) as EachFunction;\n\n/**\n * Builds a new array from the provided collection, optionally transforming or filtering elements.\n *\n * Options:\n * - `with`: function to transform each element (like map)\n * - `when`: function to filter elements (like filter)\n * - `into`: array to push results into (default: new array)\n *\n * @param source The collection to iterate (array, object, Map, Set, etc.)\n * @param withOrOptions Optional: `with` function, or options object, or `into` array.\n * @returns The resulting array.\n */\nexport const array: ArrayFunction = ((source: any, withOrOptions: WithOrOptions) => invokeNormalizedIteration(normalizedArrayIteration, source, withOrOptions)) as ArrayFunction;\n\n/**\n * Builds a new object from the provided collection, optionally transforming keys/values or filtering elements.\n *\n * Options:\n * - `with`: function to transform each value\n * - `when`: function to filter elements\n * - `key`/`withKey`: function to determine output keys\n * - `into`: object to assign results into (default: new object)\n *\n * Defaults:\n * - no `with`: uses the source container's \"values\" as the default\n * - no `withKey`: from arrays, uses the values as keys, from objects, uses the keys as keys\n * - no `into`: creates a new object\n *\n * Simplest example use: `object([\"sally\", \"billy\", \"chad\"])` => { \"sally\": \"sally\", \"billy\": \"billy\", \"chad\": \"chad\" }\n *\n * @param source The collection to iterate (array, object, Map, Set, etc.)\n * @param withOrOptions Optional: `with` function, or options object, or `into` object.\n * @returns The resulting object.\n */\nexport const object: ObjectFunction = ((source: any, withOrOptions: WithOrOptions) => invokeNormalizedIteration(normalizedObjectIteration, source, withOrOptions)) as ObjectFunction;\n\n/**\n * Reduces the provided collection to a single value, similar to Array.prototype.reduce.\n *\n * The first element is used as the initial value unless an `into`/`inject`/`returning` option is provided.\n *\n * Options:\n * - `with`: reducer function (receives accumulator, value, key)\n * - `when`: function to filter elements\n * - `into`/`inject`/`returning`: initial value for the reduction\n *\n * @param source The collection to reduce (array, object, Map, Set, etc.)\n * @param withOrOptions Optional: initial value or reducer function or options object.\n * @returns The reduced value.\n */\nexport const reduce: ReduceFunction = ((source: any, withOrOptions: WithOrOptions) => invokeNormalizedIteration(normalizedReduceIteration, source, withOrOptions)) as ReduceFunction;\n\n/**\n * Finds and returns the first value in the collection that matches the given criteria.\n *\n * Options:\n * - `with`: function to transform the found value\n * - `when`: function to filter elements (predicate)\n *\n * @param source The collection to search (array, object, Map, Set, etc.)\n * @param withOrOptions Optional: predicate or options object.\n * @returns The found value, or undefined if not found.\n */\nexport const find: FindFunction = ((source: any, withOrOptions: WithOrOptions) => invokeNormalizedIteration(normalizedFindIteration, source, withOrOptions)) as FindFunction;\n\n\n/**\n * Returns true if the source is a comprehension iterable.\n *\n * A comprehension iterable is any object that can be iterated over.\n *\n * This is different from isFullySupportedComprehensionIterable, which only checks if we can both generate and iterate over the source.\n *\n * NOTE strings are not considered comprehension iterables.\n *\n * @param source - The source to check.\n * @returns True if the source is a comprehension iterable, false otherwise.\n */\nexport const isComprehensionIterable = (source: any): source is AnyContainer<any> =>\n isArrayIterable(source) || isPlainObject(source) || isMap(source) || isSet(source) || isOfIterable(source)\n\n/**\n * Returns true if the source is a fully supported comprehension iterable.\n *\n * Fully supported means we can both generate as well as iterate over the source.\n *\n * This is different from isComprehensionIterable, which only checks if we can iterate over the source.\n *\n * This is useful for cases where we need to know if we can both generate and iterate over the source,\n * such as when we are using the source in a comprehension.\n *\n * Currently, this is only true for arrays and objects. TODO: add Map and Set support.\n * @param source - The source to check.\n * @returns True if the source is a fully supported comprehension iterable, false otherwise.\n */\nexport const isFullySupportedComprehensionIterable = (source: any): source is AnyContainer<any> =>\n isArrayIterable(source) || isPlainObject(source)\n","/**\n * DeepComprehensions is a library that provides a way to map and iterate over deeply nested comprehension iterables.\n *\n * It is useful for cases where you need to map or iterate over a deeply nested comprehension iterable.\n *\n * NOTE: due to their nature, deep comprehensions don't support TypeScript's type inference. You'll need to post-validate or coerce the results to the correct type.\n *\n * TODO: add Map and Set support.\n * TODO: add {when} support. Example usage: deepStripNull = deepMap(obj, {when: v => v !== null})\n */\nimport { isPlainObject } from '@art-suite/art-core-ts-types'\nimport { each, isComprehensionIterable, isFullySupportedComprehensionIterable, isArrayIterable, array, object } from './Comprehensions'\nimport { AnyContainer, FullySupportedContainer, ArrayInput, ObjectInput, NotPresent } from './ComprehensionTypes'\nimport { isFunction } from '@art-suite/art-core-ts-types'\n\nexport type DeepWithFunction = (value: any, key: any) => void\nexport type DeepWhenFunction = (value: any, key: any) => boolean\n\nexport type DeepOptions = {\n when?: DeepWhenFunction\n with?: DeepWithFunction\n}\n\nexport type DeepSecondParameter = DeepWithFunction | DeepOptions\n\n//******************************************************************************************************************\n// HELPERS\n//******************************************************************************************************************\n\nconst defaultWithFunction: DeepWithFunction = v => v\nconst defaultWhenFunction: DeepWhenFunction = () => true\n\ntype DeepOptionsFullSupport = {\n when: DeepWhenFunction\n with: DeepWithFunction\n}\n\nconst normalizeDeepOptions = (options: DeepSecondParameter): DeepOptionsFullSupport => {\n if (isFunction(options)) {\n return { with: options, when: defaultWhenFunction }\n }\n return { with: options.with ?? defaultWithFunction, when: options.when ?? defaultWhenFunction }\n}\n\nconst deepEachR = (obj: AnyContainer<any>, options: DeepOptionsFullSupport) =>\n each(obj, {\n when: options.when,\n with: (value: any, key: any) =>\n isComprehensionIterable(value)\n ? deepEachR(value, options)\n : options.with(value, key)\n })\n\nconst deepMapR = (obj: AnyContainer<any>, options: DeepOptionsFullSupport) =>\n mapInternal(obj, {\n when: options.when, with: (value: any, key: any) =>\n isFullySupportedComprehensionIterable(value)\n ? deepMapR(value, options)\n : options.with(value, key)\n })\n\nconst mapInternal = (source: ArrayInput<any> | ObjectInput<any> | NotPresent, options: DeepOptionsFullSupport) => {\n if (isArrayIterable(source)) return array(source, options)\n if (isPlainObject(source)) return object(source, options)\n throw new Error(`Unsupported source type: ${typeof source}`)\n}\n\n//******************************************************************************************************************\n// EXPORTS\n//******************************************************************************************************************\n/**\n * Maps over a fully supported comprehension iterable, shallowly.\n *\n * Returns the same container type (array or object) as the original object, but with the values mapped.\n *\n * @param source - The source to map over.\n * @param options - the map-function or {with: the map-function, when: the when-function}\n * @returns The mapped container.\n */\nexport const map = (source: ArrayInput<any> | ObjectInput<any> | NotPresent, options: DeepSecondParameter) =>\n mapInternal(source, normalizeDeepOptions(options))\n\n/**\n * Iterates over a fully supported comprehension iterable, and any nested isComprehensionIterable values.\n *\n * withFunction is called for each value that is NOT isComprehensionIterable and true for whenFunction (if provided).\n *\n * whenFunction is called on EVERY value, isComprehensionIterable or not. If it returns false, isComprehensionIterable values will be skipped.\n *\n * @param obj - The object to iterate over.\n * @param options - the with-function or {with: the with-function, when: the when-function}\n * @returns The object.\n */\nexport const deepEach = (obj: AnyContainer<any>, options: DeepSecondParameter) =>\n deepEachR(obj, normalizeDeepOptions(options))\n\n/**\n * Maps over a fully supported comprehension iterable, and any nested fully supported comprehension iterables.\n *\n * Returns the same structure (of fully supported comprehension iterables) as the original object, but with the values mapped.\n * If the source is not a fully supported comprehension iterable, it will return the source unchanged.\n * If the source is a fully supported comprehension iterable, it will return a new fully supported comprehension iterable with the values mapped.\n *\n * whenFunction is called on EVERY value, isComprehensionIterable or not. If it returns false, isComprehensionIterable values will be skipped.\n *\n * @param obj - The object to map over.\n * @param options - the map-function or {with: the map-function, when: the when-function}\n * @returns The mapped object.\n */\nexport const deepMap = (obj: FullySupportedContainer<any>, options: DeepSecondParameter) =>\n deepMapR(obj, normalizeDeepOptions(options))\n","import { object } from '@art-suite/art-core-ts-comprehensions';\n\nconst communicationStatusesPartials = {\n // HTTP Success Statuses\n success: { httpStatus: 200 },\n\n // HTTP Failure Statuses\n missing: { httpStatus: 404, failure: true },\n clientFailure: { httpStatus: 400, clientFailure: true, failure: true },\n clientFailureNotAuthorized: { httpStatus: 403, clientFailure: true, failure: true },\n serverFailure: { httpStatus: 500, failure: true, serverFailure: true },\n failure: { httpStatus: 500, failure: true },\n\n // Non-HTTP Statuses\n pending: { httpStatus: undefined },\n networkFailure: { httpStatus: undefined, failure: true },\n aborted: { httpStatus: undefined, failure: true },\n timeoutFailure: { httpStatus: undefined, failure: true }\n};\n\n/**\n * The core of Art-core-ts-communication-status: A simplified set of statuses as a human-readable and machine-interpretable string\n * representing all the possible communication statuses that are pragmatically actionable.\n */\nexport type CommunicationStatus = keyof typeof communicationStatusesPartials;\n\nexport type HttpOrCommunicationStatus = CommunicationStatus | number;\n\n/**\n * Details about a communication status\n *\n * @param httpStatus - The HTTP status code for the communication status\n * @param failure - Whether the communication status is a failure\n * @param clientFailure - Whether the communication status is a client failure\n * @param serverFailure - Whether the communication status is a server failure\n * @param status - The communication status - alias for communicationStatus\n * @param communicationStatus - The communication status\n */\nexport interface CommunicationStatusDetails {\n httpStatus?: number;\n failure?: boolean;\n clientFailure?: boolean;\n serverFailure?: boolean;\n status: CommunicationStatus;\n communicationStatus: CommunicationStatus;\n message: string;\n}\n\nexport const communicationStatuses: Record<CommunicationStatus, CommunicationStatusDetails> = object(communicationStatusesPartials, (details: any, status) => ({\n ...details,\n failure: !!details.failure,\n clientFailure: !!details.clientFailure,\n serverFailure: !!details.serverFailure,\n status: status as CommunicationStatus,\n communicationStatus: status as CommunicationStatus,\n message: details.httpStatus ? `${status} (${details.httpStatus})` : status\n})) as Record<CommunicationStatus, CommunicationStatusDetails>;\n\nexport type CommunicationStatuses = typeof communicationStatuses;\n\n/**\n * RegEx returns true for all valid communication statuses\n */\nexport const statusRegex = new RegExp(`^(${Object.keys(communicationStatuses).join('|')})$`);\n","import { aborted, clientFailureNotAuthorized, missing, networkFailure, pending, success, timeoutFailure } from './CommunicationStatusConsts';\nimport { getCommunicationStatus, getCommunicationStatusDetails } from './CommunicationStatusConversions';\nimport { HttpOrCommunicationStatus, statusRegex } from './CommunicationStatusTypes';\n\n// Core status check functions\n/** Returns true for HTTP 2xx responses */\nexport const isSuccess = (status: HttpOrCommunicationStatus) => getCommunicationStatus(status) === success;\n\n/**\n * Returns true for any error response (HTTP 4xx/5xx) or network/abort failures\n *\n * HTTP Status Codes Covered:\n * - 4xx: Client-side errors (except 404)\n * - 5xx: Server-side errors\n * - Network failures\n * - Abort failures\n *\n * Client Can:\n * - Use a different is* function for more specific checks\n */\nexport const isFailure = (status: HttpOrCommunicationStatus) => getCommunicationStatusDetails(status).failure;\n\n/**\n * Returns true for client-side errors\n *\n * HTTP Status Codes Covered:\n * - 400: Bad Request\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 409: Conflict\n * - 422: Unprocessable Entity\n *\n * Client Can Automatically:\n * - Notify the user that the client is experiencing issues\n *\n * Client Developer Can:\n * - use isClientFailureNotAuthorized to check for 401/403/407/451\n * - fix the request to avoid the 4xx error\n*/\nexport const isClientFailure = (status: HttpOrCommunicationStatus) => getCommunicationStatusDetails(status).clientFailure;\n\n/**\n * Returns true for server-side errors\n *\n * HTTP Status Codes Covered:\n * - 500: Internal Server Error\n * - 502: Bad Gateway\n * - 503: Service Unavailable\n * - 504: Gateway Timeout\n *\n * Client Can Automatically:\n * - Ask the user to try again later\n * - Notify the user that the server is experiencing issues\n *\n * Client Developer: (probably) can't fix\n *\n * Server Developer Can:\n * - fix the server to avoid the 5xx error\n * - fix server infrastructure to avoid the 5xx error (e.g. Bad Gateway, Service Unavailable, Gateway Timeout)\n*/\nexport const isServerFailure = (status: HttpOrCommunicationStatus) => getCommunicationStatusDetails(status).serverFailure;\n\n/**\n * Returns true when request fails due to network connectivity issues\n *\n * HTTP Status Codes Covered: NONE (server was not reachable)\n *\n * Client Can Automatically:\n * - Prompt the user to fix the network connection\n * - Retry the request\n *\n * Client Developer Can:\n * - fix bad network constants (like address, ports, etc.)\n*/\nexport const isNetworkFailure = (status: HttpOrCommunicationStatus) => getCommunicationStatus(status) === networkFailure;\n\n/** Returns true for server errors, network failures and aborted requests; i.e. the client did nothing wrong (as far as we can tell); client can ask the user to do something OR retry the request */\nexport const isNonClientFailure = (status: HttpOrCommunicationStatus) => {\n const details = getCommunicationStatusDetails(status);\n return details.failure && !details.clientFailure;\n};\n\n/**\n * Returns true for unauthorized requests (not authenticated or not authorized)\n *\n * HTTP Status Codes Covered:\n * - 401: Unauthorized\n * - 403: Forbidden\n * - 407: Proxy Authentication Required\n * - 451: Unavailable For Legal Reasons\n * - 511: Network Authentication Required\n *\n * Client Can Automatically:\n * - refresh the request token\n * - prompt the user to re-login\n * - ask the user to contact the administrator for access\n *\n * Client and Server Developer Can:\n * - fix authorization / authentication bugs\n */\nexport const isClientFailureNotAuthorized = (status: HttpOrCommunicationStatus) =>\n getCommunicationStatus(status) === clientFailureNotAuthorized;\n\n/**\n * Returns true when request was cancelled by client\n *\n * Client Can Automatically:\n * - notify the user that the request was cancelled\n * - prompt the user to try again\n *\n * Client Developer Can:\n * - fix the client to not abort the request\n */\nexport const isAborted = (status: HttpOrCommunicationStatus) => getCommunicationStatus(status) === aborted;\n\n/**\n * Returns true when resource not found / not available\n *\n * HTTP Status Codes Covered:\n * - 404: Not Found\n * - 501: Not Implemented\n *\n * Client Can Automatically:\n * - notify the user that the resource was not found\n * - prompt the user to request a different resource\n *\n * Client Developer Can:\n * - fix the bad resource paths\n */\nexport const isMissing = (status: HttpOrCommunicationStatus) => getCommunicationStatus(status) === missing;\n\n/**\n * Returns true while request is in progress\n *\n * Client Can Automatically:\n * - notify the user that the request is in progress\n * - show the user progress (if available)\n * - allow the user to cancel the request (trigging an \"aborted\" communication status)\n *\n * Client Developer Can:\n * - if \"pending\" was not expected, maybe the client needs to `wait` for the request to complete?\n */\nexport const isPending = (status: HttpOrCommunicationStatus) => getCommunicationStatus(status) === pending;\n\n/**\n * Returns true if the request timed out\n *\n * Client Can Automatically:\n * - notify the user that the request timed out\n * - try again (automatically or via user action)\n *\n * Client Developer Can:\n * - extend the timeoutFailure duration\n *\n * Server Developer Can:\n * - improve server performance and reliability\n */\nexport const isTimeout = (status: HttpOrCommunicationStatus) => getCommunicationStatus(status) === timeoutFailure;\n\n/**\n * Returns true if client can safely retry the request\n *\n * A a clearly-retryable failure:\n *\n * - network failure\n * - timeoutFailure\n * - aborted\n *\n * Note: some serverFailures will succeed on retry, but HTTP doesn't return clear indications which ones. To be safe, the client should not retry serverFailures indiscriminately.\n *\n * Client and Server Devs can\n * - investigate network, client and server performance and reliability issues\n */\nexport const isRetryableFailure = (status: HttpOrCommunicationStatus) => {\n const { status: communicationStatus, failure } = getCommunicationStatusDetails(status);\n return failure && (communicationStatus === networkFailure || communicationStatus === timeoutFailure || communicationStatus === aborted);\n};\n\n/**\n * Returns true if the status is a valid communication status\n */\nexport const isStatusValid = (status: string) => statusRegex.test(status);\n","import { clientFailure, clientFailureNotAuthorized, missing, networkFailure, serverFailure, success } from './CommunicationStatusConsts';\nimport { isStatusValid } from './CommunicationStatusTests';\nimport { CommunicationStatus, CommunicationStatusDetails, communicationStatuses } from './CommunicationStatusTypes';\n\n//***************************************************************************************************************\n// Private Helpers\n//***************************************************************************************************************\nconst getCommunicationStatusFromHttpStatusOrUndefined = (httpStatus: number): CommunicationStatus | undefined => {\n switch (Math.floor(httpStatus / 100)) {\n case 2: return success;\n case 3: return missing;\n case 4:\n switch (httpStatus) {\n case 401:\n case 403:\n case 407:\n case 451: return clientFailureNotAuthorized;\n case 404: return missing;\n default: return clientFailure;\n }\n case 5:\n switch (httpStatus) {\n case 502:\n case 503:\n case 504: return networkFailure;\n case 511: return clientFailureNotAuthorized;\n case 501: return missing; // 501 Not Implemented - i.e. it \"does not exist\" currently - i.e. missing\n case 505: // HTTP Version Not Supported - client should change the request\n case 530: return clientFailure;\n default: return serverFailure;\n }\n }\n return undefined;\n};\n\nconst getCommunicationStatusFromHttpStatus = (httpStatus: number): CommunicationStatus => {\n const status = getCommunicationStatusFromHttpStatusOrUndefined(httpStatus);\n if (!status) {\n throw new Error(`httpStatus ${httpStatus} is not a supported CommunicationStatus.`);\n }\n return status;\n};\n\n//***************************************************************************************************************\n// Public Functions\n//***************************************************************************************************************\nexport const getCommunicationStatusOrUndefined = <T extends number | CommunicationStatus | null | undefined>(\n status: T\n): T extends null | undefined ? undefined : (CommunicationStatus | undefined) => {\n if (status == null) return undefined as any;\n if (typeof status === 'string') {\n if (!isStatusValid(status)) {\n return undefined;\n }\n return status as any;\n }\n if (typeof status === 'number') {\n return getCommunicationStatusFromHttpStatusOrUndefined(status) as any;\n }\n return undefined;\n};\n\n/*\n * Returns the CommunicationStatus for a given CommunicationStatus or number\n * If the input is null or undefined, returns undefined, otherwise throws an error if the CommunicationStatus or number is not supported\n * @param status - The CommunicationStatus or number to get the CommunicationStatus for\n * @returns The CommunicationStatus for the given CommunicationStatus or number\n */\nexport const getCommunicationStatus = <T extends number | CommunicationStatus | null | undefined>(\n status: T\n): T extends null | undefined ? undefined : CommunicationStatus => {\n if (status == null) return undefined as any;\n if (typeof status === 'number') {\n return getCommunicationStatusFromHttpStatus(status) as any;\n }\n const communicationStatus: CommunicationStatus | undefined = getCommunicationStatusOrUndefined(status);\n if (!communicationStatus) {\n throw new Error(`${status} is not a valid CommunicationStatus.`);\n }\n return communicationStatus as any;\n};\n\n/**\n * Returns the HTTP status code for a given CommunicationStatus or number\n * If the input is null or undefined, returns undefined, otherwise throws an error if the CommunicationStatus or number is not supported\n * @param status - The CommunicationStatus or number to get the HTTP status code for\n * @returns The HTTP status code for the given CommunicationStatus or number\n */\nexport const getHttpStatus = <T extends CommunicationStatus | number | null | undefined>(status: T): T extends null | undefined ? undefined : number => {\n if (status == null) return undefined as any;\n const communicationStatus = getCommunicationStatus(status);\n const httpStatus = communicationStatuses[communicationStatus].httpStatus;\n if (httpStatus == null) {\n throw new Error(`There is no valid HttpStatus for ${status}.`);\n }\n return httpStatus as any;\n};\n\n/**\n * Returns CommunicationStatusDetails {status, httpStatus, message} given an HTTP status code\n *\n * Throws: Error if the HTTP status code is not supported (i.e. the 100 codes or non HTTP status code numbers)\n *\n * @param status - The HTTP status code to get the communication status for\n * @returns The CommunicationStatusDetails for the given status. Note, if an HTTP status is given, it won't necessarily be the httpStatus returned; HTTPStatuses are simplified along with CommunicationStatuses.\n */\nexport const getCommunicationStatusDetails = <T extends number | CommunicationStatus | null | undefined>(status: T):\n T extends null | undefined ? undefined : CommunicationStatusDetails => {\n if (status == null) return undefined as any;\n const communicationStatus = getCommunicationStatus(status);\n return communicationStatuses[communicationStatus] as any;\n};\n\nexport const getCommunicationStatusDetailsOrUndefined = <T extends number | CommunicationStatus | null | undefined>(\n status: T\n): T extends null | undefined ? undefined : (CommunicationStatusDetails | undefined) => {\n if (status == null) return undefined as any;\n const communicationStatus = getCommunicationStatusOrUndefined(status);\n if (communicationStatus == null) return undefined as any;\n return communicationStatuses[communicationStatus] as any;\n};\n"],"mappings":";AAaO,IAAM,UAA+B;AAerC,IAAM,UAA+B;AAsBrC,IAAM,gBAAqC;AAmB3C,IAAM,6BAAkD;AAsBxD,IAAM,gBAAqC;AAgB3C,IAAM,iBAAsC;AAc5C,IAAM,UAA+B;AAcrC,IAAM,UAA+B;AAoBrC,IAAM,UAA+B;AAarC,IAAM,iBAAsC;;;ACtI5C,IAAM,WAAW,CAAC,MAAqC,KAAK,QAAQ,OAAO,MAAM;AAOjF,IAAM,gBAAgB,CAAC,MAA6B;AACzD,MAAI,CAAC,SAAS,CAAC,EAAG,QAAO;AACzB,MAAI,EAAE,gBAAgB,OAAQ,QAAO;AACrC,QAAM,YAAY,OAAO,eAAe,CAAC;AACzC,MAAI,cAAc,KAAM,QAAO;AAC/B,SAAO,QAAQ,OAAO,eAAe,SAAS;AAChD;AAIO,IAAM,aAAa,CAAC,QAA8B,OAAO,QAAQ;AAsBjE,IAAM,SAAS,CAAC,UAAwB,SAAS;;;ACtExD,IAAM,QAAQ,CAAC,WAAyC,kBAAkB;AAGnE,IAAM,kBAAkB,CAAC,WAAiC;AAC/D,MAAI,OAAO,WAAW,SAAU,QAAO;AACvC,MAAI,WAAW,MAAM,EAAG,QAAO;AAC/B,SAAO,UAAU,QAAQ,OAAO,UAAU;AAC5C;AAEO,IAAM,eAAe,CAAC,MAAoB;AAC/C,MAAI,OAAO,MAAM,SAAU,QAAO;AAClC,MAAI,WAAW,CAAC,EAAG,QAA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,6 @@
1
1
  {
2
2
  "name": "@art-suite/art-core-ts-communication-status",
3
- "version": "0.4.2",
3
+ "version": "0.6.0",
4
4
  "description": "A TypeScript string utility library",
5
5
  "keywords": [],
6
6
  "repository": {