@zapier/kitcore 0.10.0 → 0.10.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @zapier/kitcore
2
2
 
3
+ ## 0.10.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 0e38143: Method-lifecycle observers (`onMethodStart` / `onMethodEnd`) are now isolated from the methods they observe. A throwing observer is logged and ignored instead of breaking the method call, and a throw in one observer no longer stops its siblings from running. Paginated methods also fire `onMethodEnd` in the same microtask the call settles, including when the first page fails, matching non-paginated methods.
8
+
3
9
  ## 0.10.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -270,13 +270,34 @@ function buildRegistry({
270
270
  }
271
271
 
272
272
  // src/utils/build-hooks.ts
273
+ var isolated = /* @__PURE__ */ new WeakSet();
274
+ function isolate(observer) {
275
+ if (!observer) return void 0;
276
+ if (isolated.has(observer)) return observer;
277
+ const wrapped = (ctx) => {
278
+ try {
279
+ observer(ctx);
280
+ } catch (error) {
281
+ console.error(
282
+ "[core] A method-lifecycle observer threw and was ignored. Observers are fire-and-forget and must not throw.",
283
+ error
284
+ );
285
+ }
286
+ };
287
+ isolated.add(wrapped);
288
+ return wrapped;
289
+ }
273
290
  function composeVoid(existing, added) {
274
- if (!existing) return added;
275
- if (!added) return existing;
276
- return (ctx) => {
277
- existing(ctx);
278
- added(ctx);
291
+ const wrappedExisting = isolate(existing);
292
+ const wrappedAdded = isolate(added);
293
+ if (!wrappedExisting) return wrappedAdded;
294
+ if (!wrappedAdded) return wrappedExisting;
295
+ const composed = (ctx) => {
296
+ wrappedExisting(ctx);
297
+ wrappedAdded(ctx);
279
298
  };
299
+ isolated.add(composed);
300
+ return composed;
280
301
  }
281
302
  function buildHooks(existing, added) {
282
303
  const result = {};
@@ -1025,24 +1046,27 @@ function createPaginatedFunction(coreFn, options) {
1025
1046
  return result.value;
1026
1047
  });
1027
1048
  if (hooks?.onMethodEnd) {
1028
- firstPagePromise.then(() => {
1029
- hooks.onMethodEnd({
1030
- methodName: functionName,
1031
- args,
1032
- isPaginated: true,
1033
- depth,
1034
- durationMs: Date.now() - startTime
1035
- });
1036
- }).catch((error) => {
1037
- hooks.onMethodEnd({
1038
- methodName: functionName,
1039
- args,
1040
- isPaginated: true,
1041
- depth,
1042
- durationMs: Date.now() - startTime,
1043
- error: error instanceof Error ? error : new Error(String(error))
1044
- });
1045
- });
1049
+ firstPagePromise.then(
1050
+ () => {
1051
+ hooks.onMethodEnd({
1052
+ methodName: functionName,
1053
+ args,
1054
+ isPaginated: true,
1055
+ depth,
1056
+ durationMs: Date.now() - startTime
1057
+ });
1058
+ },
1059
+ (error) => {
1060
+ hooks.onMethodEnd({
1061
+ methodName: functionName,
1062
+ args,
1063
+ isPaginated: true,
1064
+ depth,
1065
+ durationMs: Date.now() - startTime,
1066
+ error: error instanceof Error ? error : new Error(String(error))
1067
+ });
1068
+ }
1069
+ );
1046
1070
  }
1047
1071
  const pageStream = async function* () {
1048
1072
  yield await firstPagePromise;