@larc-iu/plaid-client 0.2.0-alpha.26 → 0.2.0-alpha.29

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/src/services.js CHANGED
@@ -373,11 +373,25 @@ export function serve(client, projectId, serviceInfo, onServiceRequest, extras =
373
373
  // requester has stopped the request, so a service that reports progress
374
374
  // through its work is cancellable without doing anything else. Use
375
375
  // `critical()` around writes to hold it off.
376
+ //
377
+ // A request the server answers 404 for is one it no longer knows (it
378
+ // ended, or the server restarted and forgot it), so nobody is waiting
379
+ // for the work: it counts as a stop, and the next checkpoint throws.
380
+ // Any other failure to send is only logged.
376
381
  progress: (percent, msg, extra) => {
377
382
  scope.raiseIfCancelled();
378
- return reportEvent(requestId, {
383
+ return reportRequestEvent(client, projectId, requestId, {
379
384
  status: 'progress',
380
385
  progress: { percent, message: msg, ...extra },
386
+ }).catch((error) => {
387
+ if (error?.status === 404) {
388
+ if (cancelled.get(requestId) === false) {
389
+ console.warn(`The server no longer knows request ${requestId}, so it is stopped`);
390
+ cancelled.set(requestId, true);
391
+ }
392
+ return;
393
+ }
394
+ console.warn('Failed to report request event:', error.message || error);
381
395
  });
382
396
  },
383
397
  complete: (data) => {
package/src/textEdits.js CHANGED
@@ -53,9 +53,8 @@ export function bodyCodePoints(body) {
53
53
  return lastPoints;
54
54
  }
55
55
 
56
- function opName(op) {
57
- return JSON.stringify(op);
58
- }
56
+ // The op as a refusal names it.
57
+ const opJson = (op) => String(JSON.stringify(op) ?? 'null');
59
58
 
60
59
  /**
61
60
  * The op's type after checking its shape and bounds against a body of `len`
@@ -71,11 +70,14 @@ function checkOp(op, len) {
71
70
  (type === 'replace' && int(index) && int(length) && typeof value === 'string');
72
71
  if (!wellFormed) {
73
72
  throw new Error(
74
- `Malformed text edit operation: ${opName(op)}. Expected {type: "insert", index: int, ` +
73
+ `Malformed text edit operation: ${opJson(op)}. Expected {type: "insert", index: int, ` +
75
74
  `value: string}, {type: "delete", index: int, value: int} or {type: "replace", ` +
76
75
  `index: int, length: int, value: string}`,
77
76
  );
78
77
  }
78
+ if (!(op.side == null || op.side === 'before' || op.side === 'after')) {
79
+ throw new Error(`A text edit's side is "before" or "after": ${opJson(op)}`);
80
+ }
79
81
  const inBounds =
80
82
  type === 'insert'
81
83
  ? index >= 0 && index <= len
@@ -84,7 +86,7 @@ function checkOp(op, len) {
84
86
  : index >= 0 && length >= 0 && index + length <= len;
85
87
  if (!inBounds) {
86
88
  throw new Error(
87
- `Text edit operation out of bounds: ${opName(op)} (text length is ${len} code points)`,
89
+ `Text edit operation out of bounds: ${opJson(op)} (text length is ${len} code points)`,
88
90
  );
89
91
  }
90
92
  return type;