@envelop/core 1.6.2 → 1.6.6-alpha-1e6c37b.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/index.js CHANGED
@@ -135,10 +135,31 @@ function getSubscribeArgs(args) {
135
135
  * Utility function for making a subscribe function that handles polymorphic arguments.
136
136
  */
137
137
  const makeSubscribe = (subscribeFn) => ((...polyArgs) => subscribeFn(getSubscribeArgs(polyArgs)));
138
- async function* mapAsyncIterator(asyncIterable, map) {
139
- for await (const value of asyncIterable) {
140
- yield map(value);
141
- }
138
+ function mapAsyncIterator(source, mapper) {
139
+ const iterable = source[Symbol.asyncIterator]();
140
+ const stream = {
141
+ [Symbol.asyncIterator]() {
142
+ return stream;
143
+ },
144
+ async next() {
145
+ const value = await iterable.next();
146
+ if (value.done) {
147
+ return value;
148
+ }
149
+ return { done: false, value: await mapper(value.value) };
150
+ },
151
+ async return() {
152
+ var _a;
153
+ (_a = iterable.return) === null || _a === void 0 ? void 0 : _a.call(iterable);
154
+ return { done: true, value: undefined };
155
+ },
156
+ async throw(error) {
157
+ var _a;
158
+ (_a = iterable.throw) === null || _a === void 0 ? void 0 : _a.call(iterable, error);
159
+ return { done: true, value: undefined };
160
+ },
161
+ };
162
+ return stream;
142
163
  }
143
164
  function getExecuteArgs(args) {
144
165
  return args.length === 1
@@ -189,21 +210,65 @@ function handleStreamOrSingleExecutionResult(payload, fn) {
189
210
  return undefined;
190
211
  }
191
212
  }
192
- async function* finalAsyncIterator(asyncIterable, onFinal) {
193
- try {
194
- yield* asyncIterable;
195
- }
196
- finally {
197
- onFinal();
198
- }
213
+ function finalAsyncIterator(source, onFinal) {
214
+ const iterable = source[Symbol.asyncIterator]();
215
+ let isDone = false;
216
+ const stream = {
217
+ [Symbol.asyncIterator]() {
218
+ return stream;
219
+ },
220
+ async next() {
221
+ const result = await iterable.next();
222
+ if (result.done && isDone === false) {
223
+ isDone = true;
224
+ onFinal();
225
+ }
226
+ return result;
227
+ },
228
+ async return() {
229
+ var _a;
230
+ (_a = iterable.return) === null || _a === void 0 ? void 0 : _a.call(iterable);
231
+ if (isDone === false) {
232
+ isDone = true;
233
+ onFinal();
234
+ }
235
+ return { done: true, value: undefined };
236
+ },
237
+ async throw(error) {
238
+ var _a;
239
+ (_a = iterable.throw) === null || _a === void 0 ? void 0 : _a.call(iterable, error);
240
+ return { done: true, value: undefined };
241
+ },
242
+ };
243
+ return stream;
199
244
  }
200
- async function* errorAsyncIterator(asyncIterable, onError) {
201
- try {
202
- yield* asyncIterable;
203
- }
204
- catch (err) {
205
- onError(err);
206
- }
245
+ function errorAsyncIterator(source, onError) {
246
+ const iterable = source[Symbol.asyncIterator]();
247
+ const stream = {
248
+ [Symbol.asyncIterator]() {
249
+ return stream;
250
+ },
251
+ async next() {
252
+ try {
253
+ return await iterable.next();
254
+ }
255
+ catch (error) {
256
+ onError(error);
257
+ throw error;
258
+ }
259
+ },
260
+ async return() {
261
+ var _a;
262
+ (_a = iterable.return) === null || _a === void 0 ? void 0 : _a.call(iterable);
263
+ return { done: true, value: undefined };
264
+ },
265
+ async throw(error) {
266
+ var _a;
267
+ (_a = iterable.throw) === null || _a === void 0 ? void 0 : _a.call(iterable, error);
268
+ return { done: true, value: undefined };
269
+ },
270
+ };
271
+ return stream;
207
272
  }
208
273
 
209
274
  function createEnvelopOrchestrator(plugins) {
@@ -628,25 +693,27 @@ function createEnvelopOrchestrator(plugins) {
628
693
  };
629
694
  }
630
695
 
631
- const HR_TO_NS = 1e9;
632
- const NS_TO_MS = 1e6;
633
- const deltaFrom = (hrtime) => {
634
- const delta = process.hrtime(hrtime);
635
- const ns = delta[0] * HR_TO_NS + delta[1];
636
- return ns / NS_TO_MS;
696
+ var _a;
697
+ const getTimestamp = typeof globalThis !== 'undefined' && ((_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.performance) === null || _a === void 0 ? void 0 : _a.now) ? () => performance.now() : () => Date.now();
698
+ const measure = () => {
699
+ const start = getTimestamp();
700
+ return () => {
701
+ const end = getTimestamp();
702
+ return end - start;
703
+ };
637
704
  };
705
+ const tracingSymbol = Symbol('envelopTracing');
638
706
  function traceOrchestrator(orchestrator) {
639
707
  const createTracer = (name, ctx) => {
640
- const hrtime = process.hrtime();
708
+ const end = measure();
641
709
  return () => {
642
- const time = deltaFrom(hrtime);
643
- ctx._envelopTracing[name] = time;
710
+ ctx[tracingSymbol][name] = end();
644
711
  };
645
712
  };
646
713
  return {
647
714
  ...orchestrator,
648
715
  init: (ctx = {}) => {
649
- ctx._envelopTracing = ctx._envelopTracing || {};
716
+ ctx[tracingSymbol] = ctx[tracingSymbol] || {};
650
717
  const done = createTracer('init', ctx || {});
651
718
  try {
652
719
  return orchestrator.init(ctx);
@@ -656,7 +723,7 @@ function traceOrchestrator(orchestrator) {
656
723
  }
657
724
  },
658
725
  parse: (ctx = {}) => {
659
- ctx._envelopTracing = ctx._envelopTracing || {};
726
+ ctx[tracingSymbol] = ctx[tracingSymbol] || {};
660
727
  const actualFn = orchestrator.parse(ctx);
661
728
  return (...args) => {
662
729
  const done = createTracer('parse', ctx);
@@ -669,7 +736,7 @@ function traceOrchestrator(orchestrator) {
669
736
  };
670
737
  },
671
738
  validate: (ctx = {}) => {
672
- ctx._envelopTracing = ctx._envelopTracing || {};
739
+ ctx[tracingSymbol] = ctx[tracingSymbol] || {};
673
740
  const actualFn = orchestrator.validate(ctx);
674
741
  return (...args) => {
675
742
  const done = createTracer('validate', ctx);
@@ -704,7 +771,7 @@ function traceOrchestrator(orchestrator) {
704
771
  result.extensions = result.extensions || {};
705
772
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
706
773
  // @ts-ignore GraphQL.js types contextValue as unknown
707
- result.extensions.envelopTracing = args.contextValue._envelopTracing;
774
+ result.extensions.envelopTracing = args.contextValue[tracingSymbol];
708
775
  }
709
776
  else {
710
777
  // eslint-disable-next-line no-console
@@ -828,8 +895,8 @@ const useLogger = (rawOptions = DEFAULT_OPTIONS) => {
828
895
  };
829
896
  };
830
897
 
831
- const HR_TO_NS$1 = 1e9;
832
- const NS_TO_MS$1 = 1e6;
898
+ const HR_TO_NS = 1e9;
899
+ const NS_TO_MS = 1e6;
833
900
  const DEFAULT_OPTIONS$1 = {
834
901
  onExecutionMeasurement: (args, timing) => console.log(`Operation execution "${args.operationName}" done in ${timing.ms}ms`),
835
902
  onSubscriptionMeasurement: (args, timing) => console.log(`Operation subscription "${args.operationName}" done in ${timing.ms}ms`),
@@ -838,13 +905,13 @@ const DEFAULT_OPTIONS$1 = {
838
905
  onResolverMeasurement: (info, timing) => console.log(`\tResolver of "${info.parentType.toString()}.${info.fieldName}" done in ${timing.ms}ms`),
839
906
  onContextBuildingMeasurement: (timing) => console.log(`Context building done in ${timing.ms}ms`),
840
907
  };
841
- const deltaFrom$1 = (hrtime) => {
908
+ const deltaFrom = (hrtime) => {
842
909
  const delta = process.hrtime(hrtime);
843
- const ns = delta[0] * HR_TO_NS$1 + delta[1];
910
+ const ns = delta[0] * HR_TO_NS + delta[1];
844
911
  return {
845
912
  ns,
846
913
  get ms() {
847
- return ns / NS_TO_MS$1;
914
+ return ns / NS_TO_MS;
848
915
  },
849
916
  };
850
917
  };
@@ -861,7 +928,7 @@ const useTiming = (rawOptions) => {
861
928
  }
862
929
  const contextStartTime = process.hrtime();
863
930
  return () => {
864
- options.onContextBuildingMeasurement(deltaFrom$1(contextStartTime));
931
+ options.onContextBuildingMeasurement(deltaFrom(contextStartTime));
865
932
  };
866
933
  };
867
934
  }
@@ -875,7 +942,7 @@ const useTiming = (rawOptions) => {
875
942
  }
876
943
  const parseStartTime = process.hrtime();
877
944
  return () => {
878
- options.onParsingMeasurement(params.source, deltaFrom$1(parseStartTime));
945
+ options.onParsingMeasurement(params.source, deltaFrom(parseStartTime));
879
946
  };
880
947
  };
881
948
  }
@@ -886,7 +953,7 @@ const useTiming = (rawOptions) => {
886
953
  }
887
954
  const validateStartTime = process.hrtime();
888
955
  return () => {
889
- options.onValidationMeasurement(params.documentAST, deltaFrom$1(validateStartTime));
956
+ options.onValidationMeasurement(params.documentAST, deltaFrom(validateStartTime));
890
957
  };
891
958
  };
892
959
  }
@@ -899,12 +966,12 @@ const useTiming = (rawOptions) => {
899
966
  const executeStartTime = process.hrtime();
900
967
  return {
901
968
  onExecuteDone: () => {
902
- options.onExecutionMeasurement(args, deltaFrom$1(executeStartTime));
969
+ options.onExecutionMeasurement(args, deltaFrom(executeStartTime));
903
970
  },
904
971
  onResolverCalled: ({ info }) => {
905
972
  const resolverStartTime = process.hrtime();
906
973
  return () => {
907
- options.onResolverMeasurement(info, deltaFrom$1(resolverStartTime));
974
+ options.onResolverMeasurement(info, deltaFrom(resolverStartTime));
908
975
  };
909
976
  },
910
977
  };
@@ -918,7 +985,7 @@ const useTiming = (rawOptions) => {
918
985
  const executeStartTime = process.hrtime();
919
986
  return {
920
987
  onExecuteDone: () => {
921
- options.onExecutionMeasurement(args, deltaFrom$1(executeStartTime));
988
+ options.onExecutionMeasurement(args, deltaFrom(executeStartTime));
922
989
  },
923
990
  };
924
991
  };
@@ -933,12 +1000,12 @@ const useTiming = (rawOptions) => {
933
1000
  const subscribeStartTime = process.hrtime();
934
1001
  return {
935
1002
  onSubscribeResult: () => {
936
- options.onSubscriptionMeasurement && options.onSubscriptionMeasurement(args, deltaFrom$1(subscribeStartTime));
1003
+ options.onSubscriptionMeasurement && options.onSubscriptionMeasurement(args, deltaFrom(subscribeStartTime));
937
1004
  },
938
1005
  onResolverCalled: ({ info }) => {
939
1006
  const resolverStartTime = process.hrtime();
940
1007
  return () => {
941
- options.onResolverMeasurement && options.onResolverMeasurement(info, deltaFrom$1(resolverStartTime));
1008
+ options.onResolverMeasurement && options.onResolverMeasurement(info, deltaFrom(resolverStartTime));
942
1009
  };
943
1010
  },
944
1011
  };
@@ -952,7 +1019,7 @@ const useTiming = (rawOptions) => {
952
1019
  const subscribeStartTime = process.hrtime();
953
1020
  return {
954
1021
  onSubscribeResult: () => {
955
- options.onSubscriptionMeasurement && options.onSubscriptionMeasurement(args, deltaFrom$1(subscribeStartTime));
1022
+ options.onSubscriptionMeasurement && options.onSubscriptionMeasurement(args, deltaFrom(subscribeStartTime));
956
1023
  },
957
1024
  };
958
1025
  };
@@ -1008,8 +1075,8 @@ const useExtendContext = (contextFactory) => ({
1008
1075
  },
1009
1076
  });
1010
1077
 
1011
- const makeHandleResult$1 = (formatter) => ({ result, setResult }) => {
1012
- const modified = formatter(result);
1078
+ const makeHandleResult$1 = (formatter) => ({ args, result, setResult, }) => {
1079
+ const modified = formatter(result, args);
1013
1080
  if (modified !== false) {
1014
1081
  setResult(modified);
1015
1082
  }
package/index.mjs CHANGED
@@ -131,10 +131,31 @@ function getSubscribeArgs(args) {
131
131
  * Utility function for making a subscribe function that handles polymorphic arguments.
132
132
  */
133
133
  const makeSubscribe = (subscribeFn) => ((...polyArgs) => subscribeFn(getSubscribeArgs(polyArgs)));
134
- async function* mapAsyncIterator(asyncIterable, map) {
135
- for await (const value of asyncIterable) {
136
- yield map(value);
137
- }
134
+ function mapAsyncIterator(source, mapper) {
135
+ const iterable = source[Symbol.asyncIterator]();
136
+ const stream = {
137
+ [Symbol.asyncIterator]() {
138
+ return stream;
139
+ },
140
+ async next() {
141
+ const value = await iterable.next();
142
+ if (value.done) {
143
+ return value;
144
+ }
145
+ return { done: false, value: await mapper(value.value) };
146
+ },
147
+ async return() {
148
+ var _a;
149
+ (_a = iterable.return) === null || _a === void 0 ? void 0 : _a.call(iterable);
150
+ return { done: true, value: undefined };
151
+ },
152
+ async throw(error) {
153
+ var _a;
154
+ (_a = iterable.throw) === null || _a === void 0 ? void 0 : _a.call(iterable, error);
155
+ return { done: true, value: undefined };
156
+ },
157
+ };
158
+ return stream;
138
159
  }
139
160
  function getExecuteArgs(args) {
140
161
  return args.length === 1
@@ -185,21 +206,65 @@ function handleStreamOrSingleExecutionResult(payload, fn) {
185
206
  return undefined;
186
207
  }
187
208
  }
188
- async function* finalAsyncIterator(asyncIterable, onFinal) {
189
- try {
190
- yield* asyncIterable;
191
- }
192
- finally {
193
- onFinal();
194
- }
209
+ function finalAsyncIterator(source, onFinal) {
210
+ const iterable = source[Symbol.asyncIterator]();
211
+ let isDone = false;
212
+ const stream = {
213
+ [Symbol.asyncIterator]() {
214
+ return stream;
215
+ },
216
+ async next() {
217
+ const result = await iterable.next();
218
+ if (result.done && isDone === false) {
219
+ isDone = true;
220
+ onFinal();
221
+ }
222
+ return result;
223
+ },
224
+ async return() {
225
+ var _a;
226
+ (_a = iterable.return) === null || _a === void 0 ? void 0 : _a.call(iterable);
227
+ if (isDone === false) {
228
+ isDone = true;
229
+ onFinal();
230
+ }
231
+ return { done: true, value: undefined };
232
+ },
233
+ async throw(error) {
234
+ var _a;
235
+ (_a = iterable.throw) === null || _a === void 0 ? void 0 : _a.call(iterable, error);
236
+ return { done: true, value: undefined };
237
+ },
238
+ };
239
+ return stream;
195
240
  }
196
- async function* errorAsyncIterator(asyncIterable, onError) {
197
- try {
198
- yield* asyncIterable;
199
- }
200
- catch (err) {
201
- onError(err);
202
- }
241
+ function errorAsyncIterator(source, onError) {
242
+ const iterable = source[Symbol.asyncIterator]();
243
+ const stream = {
244
+ [Symbol.asyncIterator]() {
245
+ return stream;
246
+ },
247
+ async next() {
248
+ try {
249
+ return await iterable.next();
250
+ }
251
+ catch (error) {
252
+ onError(error);
253
+ throw error;
254
+ }
255
+ },
256
+ async return() {
257
+ var _a;
258
+ (_a = iterable.return) === null || _a === void 0 ? void 0 : _a.call(iterable);
259
+ return { done: true, value: undefined };
260
+ },
261
+ async throw(error) {
262
+ var _a;
263
+ (_a = iterable.throw) === null || _a === void 0 ? void 0 : _a.call(iterable, error);
264
+ return { done: true, value: undefined };
265
+ },
266
+ };
267
+ return stream;
203
268
  }
204
269
 
205
270
  function createEnvelopOrchestrator(plugins) {
@@ -624,25 +689,27 @@ function createEnvelopOrchestrator(plugins) {
624
689
  };
625
690
  }
626
691
 
627
- const HR_TO_NS = 1e9;
628
- const NS_TO_MS = 1e6;
629
- const deltaFrom = (hrtime) => {
630
- const delta = process.hrtime(hrtime);
631
- const ns = delta[0] * HR_TO_NS + delta[1];
632
- return ns / NS_TO_MS;
692
+ var _a;
693
+ const getTimestamp = typeof globalThis !== 'undefined' && ((_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.performance) === null || _a === void 0 ? void 0 : _a.now) ? () => performance.now() : () => Date.now();
694
+ const measure = () => {
695
+ const start = getTimestamp();
696
+ return () => {
697
+ const end = getTimestamp();
698
+ return end - start;
699
+ };
633
700
  };
701
+ const tracingSymbol = Symbol('envelopTracing');
634
702
  function traceOrchestrator(orchestrator) {
635
703
  const createTracer = (name, ctx) => {
636
- const hrtime = process.hrtime();
704
+ const end = measure();
637
705
  return () => {
638
- const time = deltaFrom(hrtime);
639
- ctx._envelopTracing[name] = time;
706
+ ctx[tracingSymbol][name] = end();
640
707
  };
641
708
  };
642
709
  return {
643
710
  ...orchestrator,
644
711
  init: (ctx = {}) => {
645
- ctx._envelopTracing = ctx._envelopTracing || {};
712
+ ctx[tracingSymbol] = ctx[tracingSymbol] || {};
646
713
  const done = createTracer('init', ctx || {});
647
714
  try {
648
715
  return orchestrator.init(ctx);
@@ -652,7 +719,7 @@ function traceOrchestrator(orchestrator) {
652
719
  }
653
720
  },
654
721
  parse: (ctx = {}) => {
655
- ctx._envelopTracing = ctx._envelopTracing || {};
722
+ ctx[tracingSymbol] = ctx[tracingSymbol] || {};
656
723
  const actualFn = orchestrator.parse(ctx);
657
724
  return (...args) => {
658
725
  const done = createTracer('parse', ctx);
@@ -665,7 +732,7 @@ function traceOrchestrator(orchestrator) {
665
732
  };
666
733
  },
667
734
  validate: (ctx = {}) => {
668
- ctx._envelopTracing = ctx._envelopTracing || {};
735
+ ctx[tracingSymbol] = ctx[tracingSymbol] || {};
669
736
  const actualFn = orchestrator.validate(ctx);
670
737
  return (...args) => {
671
738
  const done = createTracer('validate', ctx);
@@ -700,7 +767,7 @@ function traceOrchestrator(orchestrator) {
700
767
  result.extensions = result.extensions || {};
701
768
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
702
769
  // @ts-ignore GraphQL.js types contextValue as unknown
703
- result.extensions.envelopTracing = args.contextValue._envelopTracing;
770
+ result.extensions.envelopTracing = args.contextValue[tracingSymbol];
704
771
  }
705
772
  else {
706
773
  // eslint-disable-next-line no-console
@@ -824,8 +891,8 @@ const useLogger = (rawOptions = DEFAULT_OPTIONS) => {
824
891
  };
825
892
  };
826
893
 
827
- const HR_TO_NS$1 = 1e9;
828
- const NS_TO_MS$1 = 1e6;
894
+ const HR_TO_NS = 1e9;
895
+ const NS_TO_MS = 1e6;
829
896
  const DEFAULT_OPTIONS$1 = {
830
897
  onExecutionMeasurement: (args, timing) => console.log(`Operation execution "${args.operationName}" done in ${timing.ms}ms`),
831
898
  onSubscriptionMeasurement: (args, timing) => console.log(`Operation subscription "${args.operationName}" done in ${timing.ms}ms`),
@@ -834,13 +901,13 @@ const DEFAULT_OPTIONS$1 = {
834
901
  onResolverMeasurement: (info, timing) => console.log(`\tResolver of "${info.parentType.toString()}.${info.fieldName}" done in ${timing.ms}ms`),
835
902
  onContextBuildingMeasurement: (timing) => console.log(`Context building done in ${timing.ms}ms`),
836
903
  };
837
- const deltaFrom$1 = (hrtime) => {
904
+ const deltaFrom = (hrtime) => {
838
905
  const delta = process.hrtime(hrtime);
839
- const ns = delta[0] * HR_TO_NS$1 + delta[1];
906
+ const ns = delta[0] * HR_TO_NS + delta[1];
840
907
  return {
841
908
  ns,
842
909
  get ms() {
843
- return ns / NS_TO_MS$1;
910
+ return ns / NS_TO_MS;
844
911
  },
845
912
  };
846
913
  };
@@ -857,7 +924,7 @@ const useTiming = (rawOptions) => {
857
924
  }
858
925
  const contextStartTime = process.hrtime();
859
926
  return () => {
860
- options.onContextBuildingMeasurement(deltaFrom$1(contextStartTime));
927
+ options.onContextBuildingMeasurement(deltaFrom(contextStartTime));
861
928
  };
862
929
  };
863
930
  }
@@ -871,7 +938,7 @@ const useTiming = (rawOptions) => {
871
938
  }
872
939
  const parseStartTime = process.hrtime();
873
940
  return () => {
874
- options.onParsingMeasurement(params.source, deltaFrom$1(parseStartTime));
941
+ options.onParsingMeasurement(params.source, deltaFrom(parseStartTime));
875
942
  };
876
943
  };
877
944
  }
@@ -882,7 +949,7 @@ const useTiming = (rawOptions) => {
882
949
  }
883
950
  const validateStartTime = process.hrtime();
884
951
  return () => {
885
- options.onValidationMeasurement(params.documentAST, deltaFrom$1(validateStartTime));
952
+ options.onValidationMeasurement(params.documentAST, deltaFrom(validateStartTime));
886
953
  };
887
954
  };
888
955
  }
@@ -895,12 +962,12 @@ const useTiming = (rawOptions) => {
895
962
  const executeStartTime = process.hrtime();
896
963
  return {
897
964
  onExecuteDone: () => {
898
- options.onExecutionMeasurement(args, deltaFrom$1(executeStartTime));
965
+ options.onExecutionMeasurement(args, deltaFrom(executeStartTime));
899
966
  },
900
967
  onResolverCalled: ({ info }) => {
901
968
  const resolverStartTime = process.hrtime();
902
969
  return () => {
903
- options.onResolverMeasurement(info, deltaFrom$1(resolverStartTime));
970
+ options.onResolverMeasurement(info, deltaFrom(resolverStartTime));
904
971
  };
905
972
  },
906
973
  };
@@ -914,7 +981,7 @@ const useTiming = (rawOptions) => {
914
981
  const executeStartTime = process.hrtime();
915
982
  return {
916
983
  onExecuteDone: () => {
917
- options.onExecutionMeasurement(args, deltaFrom$1(executeStartTime));
984
+ options.onExecutionMeasurement(args, deltaFrom(executeStartTime));
918
985
  },
919
986
  };
920
987
  };
@@ -929,12 +996,12 @@ const useTiming = (rawOptions) => {
929
996
  const subscribeStartTime = process.hrtime();
930
997
  return {
931
998
  onSubscribeResult: () => {
932
- options.onSubscriptionMeasurement && options.onSubscriptionMeasurement(args, deltaFrom$1(subscribeStartTime));
999
+ options.onSubscriptionMeasurement && options.onSubscriptionMeasurement(args, deltaFrom(subscribeStartTime));
933
1000
  },
934
1001
  onResolverCalled: ({ info }) => {
935
1002
  const resolverStartTime = process.hrtime();
936
1003
  return () => {
937
- options.onResolverMeasurement && options.onResolverMeasurement(info, deltaFrom$1(resolverStartTime));
1004
+ options.onResolverMeasurement && options.onResolverMeasurement(info, deltaFrom(resolverStartTime));
938
1005
  };
939
1006
  },
940
1007
  };
@@ -948,7 +1015,7 @@ const useTiming = (rawOptions) => {
948
1015
  const subscribeStartTime = process.hrtime();
949
1016
  return {
950
1017
  onSubscribeResult: () => {
951
- options.onSubscriptionMeasurement && options.onSubscriptionMeasurement(args, deltaFrom$1(subscribeStartTime));
1018
+ options.onSubscriptionMeasurement && options.onSubscriptionMeasurement(args, deltaFrom(subscribeStartTime));
952
1019
  },
953
1020
  };
954
1021
  };
@@ -1004,8 +1071,8 @@ const useExtendContext = (contextFactory) => ({
1004
1071
  },
1005
1072
  });
1006
1073
 
1007
- const makeHandleResult$1 = (formatter) => ({ result, setResult }) => {
1008
- const modified = formatter(result);
1074
+ const makeHandleResult$1 = (formatter) => ({ args, result, setResult, }) => {
1075
+ const modified = formatter(result, args);
1009
1076
  if (modified !== false) {
1010
1077
  setResult(modified);
1011
1078
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envelop/core",
3
- "version": "1.6.2",
3
+ "version": "1.6.6-alpha-1e6c37b.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
@@ -38,6 +38,7 @@
38
38
  "./*": {
39
39
  "require": "./*.js",
40
40
  "import": "./*.mjs"
41
- }
41
+ },
42
+ "./package.json": "./package.json"
42
43
  }
43
44
  }
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from '@envelop/types';
2
- export declare type ContextFactoryFn<TResult = unknown> = (currentContext: unknown) => TResult | Promise<TResult>;
2
+ export declare type ContextFactoryFn<TResult = unknown, TCurrent = unknown> = (currentContext: TCurrent) => TResult | Promise<TResult>;
3
3
  declare type UnwrapAsync<T> = T extends Promise<infer U> ? U : T;
4
4
  export declare const useExtendContext: <TContextFactory extends (...args: any[]) => any>(contextFactory: TContextFactory) => Plugin<UnwrapAsync<ReturnType<TContextFactory>>>;
5
5
  export {};
@@ -1,4 +1,4 @@
1
- import { Plugin } from '@envelop/types';
1
+ import { Plugin, TypedExecutionArgs } from '@envelop/types';
2
2
  import { ExecutionResult } from 'graphql';
3
- export declare type FormatterFunction = (result: ExecutionResult<any, any>) => false | ExecutionResult<any, any>;
3
+ export declare type FormatterFunction = (result: ExecutionResult<any, any>, args: TypedExecutionArgs<any>) => false | ExecutionResult<any, any>;
4
4
  export declare const usePayloadFormatter: (formatter: FormatterFunction) => Plugin;
@@ -1,5 +1,7 @@
1
1
  import { ArbitraryObject } from '@envelop/types';
2
2
  import { EnvelopOrchestrator } from './orchestrator';
3
+ declare const tracingSymbol: unique symbol;
3
4
  export declare function traceOrchestrator<TInitialContext extends ArbitraryObject, TPluginsContext extends ArbitraryObject>(orchestrator: EnvelopOrchestrator<TInitialContext, TPluginsContext>): EnvelopOrchestrator<TInitialContext & {
4
- _envelopTracing?: {};
5
+ [tracingSymbol]?: {};
5
6
  }, TPluginsContext>;
7
+ export {};
package/utils.d.ts CHANGED
@@ -9,7 +9,7 @@ export declare function isIntrospectionOperationString(operation: string | Sourc
9
9
  * Utility function for making a subscribe function that handles polymorphic arguments.
10
10
  */
11
11
  export declare const makeSubscribe: (subscribeFn: (args: SubscriptionArgs) => PromiseOrValue<AsyncIterableIterator<ExecutionResult>>) => SubscribeFunction;
12
- export declare function mapAsyncIterator<TInput, TOutput = TInput>(asyncIterable: AsyncIterable<TInput>, map: (input: TInput) => Promise<TOutput> | TOutput): AsyncIterableIterator<TOutput>;
12
+ export declare function mapAsyncIterator<T, O>(source: AsyncIterable<T>, mapper: (input: T) => Promise<O> | O): AsyncGenerator<O>;
13
13
  /**
14
14
  * Utility function for making a execute function that handles polymorphic arguments.
15
15
  */
@@ -29,5 +29,5 @@ export declare function isAsyncIterable<TType>(maybeAsyncIterable: unknown): may
29
29
  * @returns a subscription for streamed results, or undefined in case of an non-async
30
30
  */
31
31
  export declare function handleStreamOrSingleExecutionResult<ContextType = DefaultContext>(payload: OnExecuteDoneEventPayload<ContextType>, fn: OnExecuteDoneHookResultOnNextHook<ContextType>): void | OnExecuteDoneHookResult<ContextType>;
32
- export declare function finalAsyncIterator<TInput>(asyncIterable: AsyncIterable<TInput>, onFinal: () => void): AsyncIterableIterator<TInput>;
33
- export declare function errorAsyncIterator<TInput>(asyncIterable: AsyncIterable<TInput>, onError: (err: unknown) => void): AsyncIterableIterator<TInput>;
32
+ export declare function finalAsyncIterator<TInput>(source: AsyncIterable<TInput>, onFinal: () => void): AsyncGenerator<TInput>;
33
+ export declare function errorAsyncIterator<TInput>(source: AsyncIterable<TInput>, onError: (err: unknown) => void): AsyncGenerator<TInput>;