@envelop/core 2.4.0-alpha-c0cc559.0 → 3.0.0-alpha-d0d0776.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## `@envelop/core`
2
2
 
3
- This is the core package for Envelop. You can find a complete documentation here: https://github.com/dotansimha/envelop
3
+ This is the core package for Envelop. You can find a complete documentation here: https://github.com/n1ru4l/envelop
4
4
 
5
5
  ### Built-in plugins
6
6
 
package/index.js CHANGED
@@ -22,9 +22,7 @@ function enableIf(condition, plugin) {
22
22
  if (condition) {
23
23
  return typeof plugin === 'function' ? plugin() : plugin;
24
24
  }
25
- else {
26
- return EnableIfBranded.DisabledPlugin;
27
- }
25
+ return EnableIfBranded.DisabledPlugin;
28
26
  }
29
27
 
30
28
  const trackedSchemaSymbol = Symbol('TRACKED_SCHEMA');
@@ -138,7 +136,6 @@ const makeSubscribe = (subscribeFn) => ((...polyArgs) => subscribeFn(getSubscrib
138
136
  function mapAsyncIterator(source, mapper) {
139
137
  const iterator = source[Symbol.asyncIterator]();
140
138
  async function mapResult(result) {
141
- var _a;
142
139
  if (result.done) {
143
140
  return result;
144
141
  }
@@ -147,7 +144,7 @@ function mapAsyncIterator(source, mapper) {
147
144
  }
148
145
  catch (error) {
149
146
  try {
150
- await ((_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator));
147
+ await iterator.return?.();
151
148
  }
152
149
  catch (_error) {
153
150
  /* ignore error */
@@ -163,13 +160,11 @@ function mapAsyncIterator(source, mapper) {
163
160
  return await mapResult(await iterator.next());
164
161
  },
165
162
  async return() {
166
- var _a;
167
- const promise = (_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator);
163
+ const promise = iterator.return?.();
168
164
  return promise ? await mapResult(await promise) : { value: undefined, done: true };
169
165
  },
170
166
  async throw(error) {
171
- var _a;
172
- const promise = (_a = iterator.throw) === null || _a === void 0 ? void 0 : _a.call(iterator);
167
+ const promise = iterator.throw?.();
173
168
  if (promise) {
174
169
  return await mapResult(await promise);
175
170
  }
@@ -220,14 +215,12 @@ function handleStreamOrSingleExecutionResult(payload, fn) {
220
215
  if (isAsyncIterable(payload.result)) {
221
216
  return { onNext: fn };
222
217
  }
223
- else {
224
- fn({
225
- args: payload.args,
226
- result: payload.result,
227
- setResult: payload.setResult,
228
- });
229
- return undefined;
230
- }
218
+ fn({
219
+ args: payload.args,
220
+ result: payload.result,
221
+ setResult: payload.setResult,
222
+ });
223
+ return undefined;
231
224
  }
232
225
  function finalAsyncIterator(source, onFinal) {
233
226
  const iterator = source[Symbol.asyncIterator]();
@@ -245,8 +238,7 @@ function finalAsyncIterator(source, onFinal) {
245
238
  return result;
246
239
  },
247
240
  async return() {
248
- var _a;
249
- const promise = (_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator);
241
+ const promise = iterator.return?.();
250
242
  if (isDone === false) {
251
243
  isDone = true;
252
244
  onFinal();
@@ -254,8 +246,7 @@ function finalAsyncIterator(source, onFinal) {
254
246
  return promise ? await promise : { done: true, value: undefined };
255
247
  },
256
248
  async throw(error) {
257
- var _a;
258
- const promise = (_a = iterator.throw) === null || _a === void 0 ? void 0 : _a.call(iterator);
249
+ const promise = iterator.throw?.();
259
250
  if (promise) {
260
251
  return await promise;
261
252
  }
@@ -282,13 +273,11 @@ function errorAsyncIterator(source, onError) {
282
273
  }
283
274
  },
284
275
  async return() {
285
- var _a;
286
- const promise = (_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator);
276
+ const promise = iterator.return?.();
287
277
  return promise ? await promise : { done: true, value: undefined };
288
278
  },
289
279
  async throw(error) {
290
- var _a;
291
- const promise = (_a = iterator.throw) === null || _a === void 0 ? void 0 : _a.call(iterator);
280
+ const promise = iterator.throw?.();
292
281
  if (promise) {
293
282
  return await promise;
294
283
  }
@@ -299,52 +288,6 @@ function errorAsyncIterator(source, onError) {
299
288
  };
300
289
  return stream;
301
290
  }
302
- function getInMemoryLRUCache({ max = 1000, onDelete = () => { }, } = {}) {
303
- let storage = {};
304
- let keys = [];
305
- return {
306
- get(key) {
307
- return storage[key];
308
- },
309
- set(key, value) {
310
- queueMicrotask(() => {
311
- if (storage[key] != null) {
312
- if (keys.indexOf(key)) {
313
- keys.splice(keys.indexOf(key), 1);
314
- }
315
- }
316
- keys.push(key);
317
- storage[key] = value;
318
- while (keys.length > max) {
319
- const key = keys.shift();
320
- if (key != null) {
321
- onDelete(key, storage[key]);
322
- delete storage[key];
323
- }
324
- }
325
- });
326
- },
327
- delete(key) {
328
- queueMicrotask(() => {
329
- if (storage[key] != null) {
330
- keys.splice(keys.indexOf(key), 1);
331
- onDelete(key, storage[key]);
332
- delete storage[key];
333
- }
334
- });
335
- },
336
- clear() {
337
- queueMicrotask(() => {
338
- storage = {};
339
- keys = [];
340
- });
341
- },
342
- };
343
- }
344
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
345
- function isSourceObject(maybeSource) {
346
- return maybeSource != null && maybeSource.body != null;
347
- }
348
291
 
349
292
  function createEnvelopOrchestrator(plugins) {
350
293
  let schema = null;
@@ -707,7 +650,7 @@ function createEnvelopOrchestrator(plugins) {
707
650
  },
708
651
  args: args,
709
652
  });
710
- if (after === null || after === void 0 ? void 0 : after.onExecuteDone) {
653
+ if (after?.onExecuteDone) {
711
654
  afterCalls.push(after.onExecuteDone);
712
655
  }
713
656
  if (result !== undefined) {
@@ -791,7 +734,7 @@ function createEnvelopOrchestrator(plugins) {
791
734
  };
792
735
  }
793
736
 
794
- const getTimestamp = typeof performance !== 'undefined' && performance.now ? () => performance.now() : () => Date.now();
737
+ const getTimestamp = typeof globalThis !== 'undefined' && globalThis?.performance?.now ? () => performance.now() : () => Date.now();
795
738
  const measure = () => {
796
739
  const start = getTimestamp();
797
740
  return () => {
@@ -951,12 +894,12 @@ const useEnvelop = (envelop) => {
951
894
  };
952
895
  };
953
896
 
954
- const DEFAULT_OPTIONS = {
897
+ const DEFAULT_OPTIONS$1 = {
955
898
  logFn: console.log,
956
899
  };
957
- const useLogger = (rawOptions = DEFAULT_OPTIONS) => {
900
+ const useLogger = (rawOptions = DEFAULT_OPTIONS$1) => {
958
901
  const options = {
959
- DEFAULT_OPTIONS,
902
+ DEFAULT_OPTIONS: DEFAULT_OPTIONS$1,
960
903
  ...rawOptions,
961
904
  };
962
905
  return {
@@ -994,11 +937,11 @@ const useLogger = (rawOptions = DEFAULT_OPTIONS) => {
994
937
 
995
938
  const HR_TO_NS = 1e9;
996
939
  const NS_TO_MS = 1e6;
997
- const DEFAULT_OPTIONS$1 = {
940
+ const DEFAULT_OPTIONS = {
998
941
  onExecutionMeasurement: (args, timing) => console.log(`Operation execution "${args.operationName}" done in ${timing.ms}ms`),
999
942
  onSubscriptionMeasurement: (args, timing) => console.log(`Operation subscription "${args.operationName}" done in ${timing.ms}ms`),
1000
943
  onParsingMeasurement: (source, timing) => console.log(`Parsing "${source}" done in ${timing.ms}ms`),
1001
- onValidationMeasurement: (document, timing) => { var _a, _b; return console.log(`Validation "${((_b = (_a = graphql.getOperationAST(document)) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.value) || '-'}" done in ${timing.ms}ms`); },
944
+ onValidationMeasurement: (document, timing) => console.log(`Validation "${graphql.getOperationAST(document)?.name?.value || '-'}" done in ${timing.ms}ms`),
1002
945
  onResolverMeasurement: (info, timing) => console.log(`\tResolver of "${info.parentType.toString()}.${info.fieldName}" done in ${timing.ms}ms`),
1003
946
  onContextBuildingMeasurement: (timing) => console.log(`Context building done in ${timing.ms}ms`),
1004
947
  };
@@ -1014,7 +957,7 @@ const deltaFrom = (hrtime) => {
1014
957
  };
1015
958
  const useTiming = (rawOptions) => {
1016
959
  const options = {
1017
- ...DEFAULT_OPTIONS$1,
960
+ ...DEFAULT_OPTIONS,
1018
961
  ...(rawOptions || {}),
1019
962
  };
1020
963
  const result = {};
@@ -1149,15 +1092,14 @@ const useAsyncSchema = (schemaPromise) => {
1149
1092
  };
1150
1093
  };
1151
1094
 
1152
- const makeHandleResult = (errorHandler) => ({ result, args }) => {
1153
- var _a;
1154
- if ((_a = result.errors) === null || _a === void 0 ? void 0 : _a.length) {
1095
+ const makeHandleResult$2 = (errorHandler) => ({ result, args }) => {
1096
+ if (result.errors?.length) {
1155
1097
  errorHandler(result.errors, args);
1156
1098
  }
1157
1099
  };
1158
1100
  const useErrorHandler = (errorHandler) => ({
1159
1101
  onExecute() {
1160
- const handleResult = makeHandleResult(errorHandler);
1102
+ const handleResult = makeHandleResult$2(errorHandler);
1161
1103
  return {
1162
1104
  onExecuteDone(payload) {
1163
1105
  return handleStreamOrSingleExecutionResult(payload, handleResult);
@@ -1196,7 +1138,6 @@ class EnvelopError extends graphql.GraphQLError {
1196
1138
  }
1197
1139
  }
1198
1140
  const formatError = (err, message, isDev) => {
1199
- var _a, _b, _c, _d;
1200
1141
  if (err instanceof graphql.GraphQLError) {
1201
1142
  if (
1202
1143
  /** execution error */
@@ -1206,8 +1147,8 @@ const formatError = (err, message, isDev) => {
1206
1147
  return new graphql.GraphQLError(message, err.nodes, err.source, err.positions, err.path, undefined, isDev
1207
1148
  ? {
1208
1149
  originalError: {
1209
- message: (_b = (_a = err.originalError) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : err.message,
1210
- stack: (_d = (_c = err.originalError) === null || _c === void 0 ? void 0 : _c.stack) !== null && _d !== void 0 ? _d : err.stack,
1150
+ message: err.originalError?.message ?? err.message,
1151
+ stack: err.originalError?.stack ?? err.stack,
1211
1152
  },
1212
1153
  }
1213
1154
  : undefined);
@@ -1216,20 +1157,19 @@ const formatError = (err, message, isDev) => {
1216
1157
  }
1217
1158
  return new graphql.GraphQLError(message);
1218
1159
  };
1219
- const makeHandleResult$2 = (format, message, isDev) => ({ result, setResult }) => {
1160
+ const makeHandleResult = (format, message, isDev) => ({ result, setResult }) => {
1220
1161
  if (result.errors != null) {
1221
1162
  setResult({ ...result, errors: result.errors.map(error => format(error, message, isDev)) });
1222
1163
  }
1223
1164
  };
1224
1165
  const useMaskedErrors = (opts) => {
1225
- var _a, _b;
1226
- const format = (_a = opts === null || opts === void 0 ? void 0 : opts.formatError) !== null && _a !== void 0 ? _a : formatError;
1227
- const message = (opts === null || opts === void 0 ? void 0 : opts.errorMessage) || DEFAULT_ERROR_MESSAGE;
1166
+ const format = opts?.formatError ?? formatError;
1167
+ const message = opts?.errorMessage || DEFAULT_ERROR_MESSAGE;
1228
1168
  // eslint-disable-next-line dot-notation
1229
- const isDev = (_b = opts === null || opts === void 0 ? void 0 : opts.isDev) !== null && _b !== void 0 ? _b : (typeof process !== 'undefined' ? process.env['NODE_ENV'] === 'development' : false);
1230
- const handleResult = makeHandleResult$2(format, message, isDev);
1169
+ const isDev = opts?.isDev ?? (typeof process !== 'undefined' ? process.env['NODE_ENV'] === 'development' : false);
1170
+ const handleResult = makeHandleResult(format, message, isDev);
1231
1171
  return {
1232
- onParse: (opts === null || opts === void 0 ? void 0 : opts.handleParseErrors) === true
1172
+ onParse: opts?.handleParseErrors === true
1233
1173
  ? function onParse() {
1234
1174
  return function onParseEnd({ result, replaceParseResult }) {
1235
1175
  if (result instanceof Error) {
@@ -1238,7 +1178,7 @@ const useMaskedErrors = (opts) => {
1238
1178
  };
1239
1179
  }
1240
1180
  : undefined,
1241
- onValidate: (opts === null || opts === void 0 ? void 0 : opts.handleValidationErrors) === true
1181
+ onValidate: opts?.handleValidationErrors === true
1242
1182
  ? function onValidate() {
1243
1183
  return function onValidateEnd({ valid, result, setResult }) {
1244
1184
  if (valid === false) {
@@ -1318,14 +1258,6 @@ const useImmediateIntrospection = () => {
1318
1258
  };
1319
1259
  };
1320
1260
 
1321
- Object.keys(types).forEach(function (k) {
1322
- if (k !== 'default') Object.defineProperty(exports, k, {
1323
- enumerable: true,
1324
- get: function () {
1325
- return types[k];
1326
- }
1327
- });
1328
- });
1329
1261
  exports.DEFAULT_ERROR_MESSAGE = DEFAULT_ERROR_MESSAGE;
1330
1262
  exports.EnvelopError = EnvelopError;
1331
1263
  exports.enableIf = enableIf;
@@ -1334,7 +1266,6 @@ exports.envelopIsIntrospectionSymbol = envelopIsIntrospectionSymbol;
1334
1266
  exports.errorAsyncIterator = errorAsyncIterator;
1335
1267
  exports.finalAsyncIterator = finalAsyncIterator;
1336
1268
  exports.formatError = formatError;
1337
- exports.getInMemoryLRUCache = getInMemoryLRUCache;
1338
1269
  exports.handleStreamOrSingleExecutionResult = handleStreamOrSingleExecutionResult;
1339
1270
  exports.isAsyncIterable = isAsyncIterable;
1340
1271
  exports.isIntrospectionDocument = isIntrospectionDocument;
@@ -1342,7 +1273,6 @@ exports.isIntrospectionOperation = isIntrospectionOperation;
1342
1273
  exports.isIntrospectionOperationString = isIntrospectionOperationString;
1343
1274
  exports.isOperationDefinition = isOperationDefinition;
1344
1275
  exports.isPluginEnabled = isPluginEnabled;
1345
- exports.isSourceObject = isSourceObject;
1346
1276
  exports.makeExecute = makeExecute;
1347
1277
  exports.makeSubscribe = makeSubscribe;
1348
1278
  exports.mapAsyncIterator = mapAsyncIterator;
@@ -1357,3 +1287,9 @@ exports.useMaskedErrors = useMaskedErrors;
1357
1287
  exports.usePayloadFormatter = usePayloadFormatter;
1358
1288
  exports.useSchema = useSchema;
1359
1289
  exports.useTiming = useTiming;
1290
+ for (const k in types) {
1291
+ if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
1292
+ enumerable: true,
1293
+ get: function () { return types[k]; }
1294
+ });
1295
+ }
package/index.mjs CHANGED
@@ -18,9 +18,7 @@ function enableIf(condition, plugin) {
18
18
  if (condition) {
19
19
  return typeof plugin === 'function' ? plugin() : plugin;
20
20
  }
21
- else {
22
- return EnableIfBranded.DisabledPlugin;
23
- }
21
+ return EnableIfBranded.DisabledPlugin;
24
22
  }
25
23
 
26
24
  const trackedSchemaSymbol = Symbol('TRACKED_SCHEMA');
@@ -134,7 +132,6 @@ const makeSubscribe = (subscribeFn) => ((...polyArgs) => subscribeFn(getSubscrib
134
132
  function mapAsyncIterator(source, mapper) {
135
133
  const iterator = source[Symbol.asyncIterator]();
136
134
  async function mapResult(result) {
137
- var _a;
138
135
  if (result.done) {
139
136
  return result;
140
137
  }
@@ -143,7 +140,7 @@ function mapAsyncIterator(source, mapper) {
143
140
  }
144
141
  catch (error) {
145
142
  try {
146
- await ((_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator));
143
+ await iterator.return?.();
147
144
  }
148
145
  catch (_error) {
149
146
  /* ignore error */
@@ -159,13 +156,11 @@ function mapAsyncIterator(source, mapper) {
159
156
  return await mapResult(await iterator.next());
160
157
  },
161
158
  async return() {
162
- var _a;
163
- const promise = (_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator);
159
+ const promise = iterator.return?.();
164
160
  return promise ? await mapResult(await promise) : { value: undefined, done: true };
165
161
  },
166
162
  async throw(error) {
167
- var _a;
168
- const promise = (_a = iterator.throw) === null || _a === void 0 ? void 0 : _a.call(iterator);
163
+ const promise = iterator.throw?.();
169
164
  if (promise) {
170
165
  return await mapResult(await promise);
171
166
  }
@@ -216,14 +211,12 @@ function handleStreamOrSingleExecutionResult(payload, fn) {
216
211
  if (isAsyncIterable(payload.result)) {
217
212
  return { onNext: fn };
218
213
  }
219
- else {
220
- fn({
221
- args: payload.args,
222
- result: payload.result,
223
- setResult: payload.setResult,
224
- });
225
- return undefined;
226
- }
214
+ fn({
215
+ args: payload.args,
216
+ result: payload.result,
217
+ setResult: payload.setResult,
218
+ });
219
+ return undefined;
227
220
  }
228
221
  function finalAsyncIterator(source, onFinal) {
229
222
  const iterator = source[Symbol.asyncIterator]();
@@ -241,8 +234,7 @@ function finalAsyncIterator(source, onFinal) {
241
234
  return result;
242
235
  },
243
236
  async return() {
244
- var _a;
245
- const promise = (_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator);
237
+ const promise = iterator.return?.();
246
238
  if (isDone === false) {
247
239
  isDone = true;
248
240
  onFinal();
@@ -250,8 +242,7 @@ function finalAsyncIterator(source, onFinal) {
250
242
  return promise ? await promise : { done: true, value: undefined };
251
243
  },
252
244
  async throw(error) {
253
- var _a;
254
- const promise = (_a = iterator.throw) === null || _a === void 0 ? void 0 : _a.call(iterator);
245
+ const promise = iterator.throw?.();
255
246
  if (promise) {
256
247
  return await promise;
257
248
  }
@@ -278,13 +269,11 @@ function errorAsyncIterator(source, onError) {
278
269
  }
279
270
  },
280
271
  async return() {
281
- var _a;
282
- const promise = (_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator);
272
+ const promise = iterator.return?.();
283
273
  return promise ? await promise : { done: true, value: undefined };
284
274
  },
285
275
  async throw(error) {
286
- var _a;
287
- const promise = (_a = iterator.throw) === null || _a === void 0 ? void 0 : _a.call(iterator);
276
+ const promise = iterator.throw?.();
288
277
  if (promise) {
289
278
  return await promise;
290
279
  }
@@ -295,52 +284,6 @@ function errorAsyncIterator(source, onError) {
295
284
  };
296
285
  return stream;
297
286
  }
298
- function getInMemoryLRUCache({ max = 1000, onDelete = () => { }, } = {}) {
299
- let storage = {};
300
- let keys = [];
301
- return {
302
- get(key) {
303
- return storage[key];
304
- },
305
- set(key, value) {
306
- queueMicrotask(() => {
307
- if (storage[key] != null) {
308
- if (keys.indexOf(key)) {
309
- keys.splice(keys.indexOf(key), 1);
310
- }
311
- }
312
- keys.push(key);
313
- storage[key] = value;
314
- while (keys.length > max) {
315
- const key = keys.shift();
316
- if (key != null) {
317
- onDelete(key, storage[key]);
318
- delete storage[key];
319
- }
320
- }
321
- });
322
- },
323
- delete(key) {
324
- queueMicrotask(() => {
325
- if (storage[key] != null) {
326
- keys.splice(keys.indexOf(key), 1);
327
- onDelete(key, storage[key]);
328
- delete storage[key];
329
- }
330
- });
331
- },
332
- clear() {
333
- queueMicrotask(() => {
334
- storage = {};
335
- keys = [];
336
- });
337
- },
338
- };
339
- }
340
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
341
- function isSourceObject(maybeSource) {
342
- return maybeSource != null && maybeSource.body != null;
343
- }
344
287
 
345
288
  function createEnvelopOrchestrator(plugins) {
346
289
  let schema = null;
@@ -703,7 +646,7 @@ function createEnvelopOrchestrator(plugins) {
703
646
  },
704
647
  args: args,
705
648
  });
706
- if (after === null || after === void 0 ? void 0 : after.onExecuteDone) {
649
+ if (after?.onExecuteDone) {
707
650
  afterCalls.push(after.onExecuteDone);
708
651
  }
709
652
  if (result !== undefined) {
@@ -787,7 +730,7 @@ function createEnvelopOrchestrator(plugins) {
787
730
  };
788
731
  }
789
732
 
790
- const getTimestamp = typeof performance !== 'undefined' && performance.now ? () => performance.now() : () => Date.now();
733
+ const getTimestamp = typeof globalThis !== 'undefined' && globalThis?.performance?.now ? () => performance.now() : () => Date.now();
791
734
  const measure = () => {
792
735
  const start = getTimestamp();
793
736
  return () => {
@@ -947,12 +890,12 @@ const useEnvelop = (envelop) => {
947
890
  };
948
891
  };
949
892
 
950
- const DEFAULT_OPTIONS = {
893
+ const DEFAULT_OPTIONS$1 = {
951
894
  logFn: console.log,
952
895
  };
953
- const useLogger = (rawOptions = DEFAULT_OPTIONS) => {
896
+ const useLogger = (rawOptions = DEFAULT_OPTIONS$1) => {
954
897
  const options = {
955
- DEFAULT_OPTIONS,
898
+ DEFAULT_OPTIONS: DEFAULT_OPTIONS$1,
956
899
  ...rawOptions,
957
900
  };
958
901
  return {
@@ -990,11 +933,11 @@ const useLogger = (rawOptions = DEFAULT_OPTIONS) => {
990
933
 
991
934
  const HR_TO_NS = 1e9;
992
935
  const NS_TO_MS = 1e6;
993
- const DEFAULT_OPTIONS$1 = {
936
+ const DEFAULT_OPTIONS = {
994
937
  onExecutionMeasurement: (args, timing) => console.log(`Operation execution "${args.operationName}" done in ${timing.ms}ms`),
995
938
  onSubscriptionMeasurement: (args, timing) => console.log(`Operation subscription "${args.operationName}" done in ${timing.ms}ms`),
996
939
  onParsingMeasurement: (source, timing) => console.log(`Parsing "${source}" done in ${timing.ms}ms`),
997
- onValidationMeasurement: (document, timing) => { var _a, _b; return console.log(`Validation "${((_b = (_a = getOperationAST(document)) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.value) || '-'}" done in ${timing.ms}ms`); },
940
+ onValidationMeasurement: (document, timing) => console.log(`Validation "${getOperationAST(document)?.name?.value || '-'}" done in ${timing.ms}ms`),
998
941
  onResolverMeasurement: (info, timing) => console.log(`\tResolver of "${info.parentType.toString()}.${info.fieldName}" done in ${timing.ms}ms`),
999
942
  onContextBuildingMeasurement: (timing) => console.log(`Context building done in ${timing.ms}ms`),
1000
943
  };
@@ -1010,7 +953,7 @@ const deltaFrom = (hrtime) => {
1010
953
  };
1011
954
  const useTiming = (rawOptions) => {
1012
955
  const options = {
1013
- ...DEFAULT_OPTIONS$1,
956
+ ...DEFAULT_OPTIONS,
1014
957
  ...(rawOptions || {}),
1015
958
  };
1016
959
  const result = {};
@@ -1145,15 +1088,14 @@ const useAsyncSchema = (schemaPromise) => {
1145
1088
  };
1146
1089
  };
1147
1090
 
1148
- const makeHandleResult = (errorHandler) => ({ result, args }) => {
1149
- var _a;
1150
- if ((_a = result.errors) === null || _a === void 0 ? void 0 : _a.length) {
1091
+ const makeHandleResult$2 = (errorHandler) => ({ result, args }) => {
1092
+ if (result.errors?.length) {
1151
1093
  errorHandler(result.errors, args);
1152
1094
  }
1153
1095
  };
1154
1096
  const useErrorHandler = (errorHandler) => ({
1155
1097
  onExecute() {
1156
- const handleResult = makeHandleResult(errorHandler);
1098
+ const handleResult = makeHandleResult$2(errorHandler);
1157
1099
  return {
1158
1100
  onExecuteDone(payload) {
1159
1101
  return handleStreamOrSingleExecutionResult(payload, handleResult);
@@ -1192,7 +1134,6 @@ class EnvelopError extends GraphQLError {
1192
1134
  }
1193
1135
  }
1194
1136
  const formatError = (err, message, isDev) => {
1195
- var _a, _b, _c, _d;
1196
1137
  if (err instanceof GraphQLError) {
1197
1138
  if (
1198
1139
  /** execution error */
@@ -1202,8 +1143,8 @@ const formatError = (err, message, isDev) => {
1202
1143
  return new GraphQLError(message, err.nodes, err.source, err.positions, err.path, undefined, isDev
1203
1144
  ? {
1204
1145
  originalError: {
1205
- message: (_b = (_a = err.originalError) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : err.message,
1206
- stack: (_d = (_c = err.originalError) === null || _c === void 0 ? void 0 : _c.stack) !== null && _d !== void 0 ? _d : err.stack,
1146
+ message: err.originalError?.message ?? err.message,
1147
+ stack: err.originalError?.stack ?? err.stack,
1207
1148
  },
1208
1149
  }
1209
1150
  : undefined);
@@ -1212,20 +1153,19 @@ const formatError = (err, message, isDev) => {
1212
1153
  }
1213
1154
  return new GraphQLError(message);
1214
1155
  };
1215
- const makeHandleResult$2 = (format, message, isDev) => ({ result, setResult }) => {
1156
+ const makeHandleResult = (format, message, isDev) => ({ result, setResult }) => {
1216
1157
  if (result.errors != null) {
1217
1158
  setResult({ ...result, errors: result.errors.map(error => format(error, message, isDev)) });
1218
1159
  }
1219
1160
  };
1220
1161
  const useMaskedErrors = (opts) => {
1221
- var _a, _b;
1222
- const format = (_a = opts === null || opts === void 0 ? void 0 : opts.formatError) !== null && _a !== void 0 ? _a : formatError;
1223
- const message = (opts === null || opts === void 0 ? void 0 : opts.errorMessage) || DEFAULT_ERROR_MESSAGE;
1162
+ const format = opts?.formatError ?? formatError;
1163
+ const message = opts?.errorMessage || DEFAULT_ERROR_MESSAGE;
1224
1164
  // eslint-disable-next-line dot-notation
1225
- const isDev = (_b = opts === null || opts === void 0 ? void 0 : opts.isDev) !== null && _b !== void 0 ? _b : (typeof process !== 'undefined' ? process.env['NODE_ENV'] === 'development' : false);
1226
- const handleResult = makeHandleResult$2(format, message, isDev);
1165
+ const isDev = opts?.isDev ?? (typeof process !== 'undefined' ? process.env['NODE_ENV'] === 'development' : false);
1166
+ const handleResult = makeHandleResult(format, message, isDev);
1227
1167
  return {
1228
- onParse: (opts === null || opts === void 0 ? void 0 : opts.handleParseErrors) === true
1168
+ onParse: opts?.handleParseErrors === true
1229
1169
  ? function onParse() {
1230
1170
  return function onParseEnd({ result, replaceParseResult }) {
1231
1171
  if (result instanceof Error) {
@@ -1234,7 +1174,7 @@ const useMaskedErrors = (opts) => {
1234
1174
  };
1235
1175
  }
1236
1176
  : undefined,
1237
- onValidate: (opts === null || opts === void 0 ? void 0 : opts.handleValidationErrors) === true
1177
+ onValidate: opts?.handleValidationErrors === true
1238
1178
  ? function onValidate() {
1239
1179
  return function onValidateEnd({ valid, result, setResult }) {
1240
1180
  if (valid === false) {
@@ -1314,4 +1254,4 @@ const useImmediateIntrospection = () => {
1314
1254
  };
1315
1255
  };
1316
1256
 
1317
- export { DEFAULT_ERROR_MESSAGE, EnvelopError, enableIf, envelop, envelopIsIntrospectionSymbol, errorAsyncIterator, finalAsyncIterator, formatError, getInMemoryLRUCache, handleStreamOrSingleExecutionResult, isAsyncIterable, isIntrospectionDocument, isIntrospectionOperation, isIntrospectionOperationString, isOperationDefinition, isPluginEnabled, isSourceObject, makeExecute, makeSubscribe, mapAsyncIterator, useAsyncSchema, useEnvelop, useErrorHandler, useExtendContext, useImmediateIntrospection, useLazyLoadedSchema, useLogger, useMaskedErrors, usePayloadFormatter, useSchema, useTiming };
1257
+ export { DEFAULT_ERROR_MESSAGE, EnvelopError, enableIf, envelop, envelopIsIntrospectionSymbol, errorAsyncIterator, finalAsyncIterator, formatError, handleStreamOrSingleExecutionResult, isAsyncIterable, isIntrospectionDocument, isIntrospectionOperation, isIntrospectionOperationString, isOperationDefinition, isPluginEnabled, makeExecute, makeSubscribe, mapAsyncIterator, useAsyncSchema, useEnvelop, useErrorHandler, useExtendContext, useImmediateIntrospection, useLazyLoadedSchema, useLogger, useMaskedErrors, usePayloadFormatter, useSchema, useTiming };
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@envelop/core",
3
- "version": "2.4.0-alpha-c0cc559.0",
3
+ "version": "3.0.0-alpha-d0d0776.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
7
7
  },
8
8
  "dependencies": {
9
- "@envelop/types": "2.2.0"
9
+ "@envelop/types": "3.0.0-alpha-d0d0776.0"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "https://github.com/dotansimha/envelop.git",
13
+ "url": "https://github.com/n1ru4l/envelop.git",
14
14
  "directory": "packages/core"
15
15
  },
16
16
  "keywords": [
@@ -32,12 +32,24 @@
32
32
  },
33
33
  "exports": {
34
34
  ".": {
35
- "require": "./index.js",
36
- "import": "./index.mjs"
35
+ "require": {
36
+ "default": "./index.js",
37
+ "types": "./index.d.ts"
38
+ },
39
+ "import": {
40
+ "default": "./index.mjs",
41
+ "types": "./index.d.ts"
42
+ }
37
43
  },
38
44
  "./*": {
39
- "require": "./*.js",
40
- "import": "./*.mjs"
45
+ "require": {
46
+ "default": "./*.js",
47
+ "types": "./*.d.ts"
48
+ },
49
+ "import": {
50
+ "default": "./*.mjs",
51
+ "types": "./*.d.ts"
52
+ }
41
53
  },
42
54
  "./package.json": "./package.json"
43
55
  }
@@ -1,8 +1,8 @@
1
1
  import { Plugin } from '@envelop/types';
2
- import { GraphQLError } from 'graphql';
2
+ import { GraphQLError, GraphQLErrorExtensions } from 'graphql';
3
3
  export declare const DEFAULT_ERROR_MESSAGE = "Unexpected error.";
4
4
  export declare class EnvelopError extends GraphQLError {
5
- constructor(message: string, extensions?: Record<string, any>);
5
+ constructor(message: string, extensions?: GraphQLErrorExtensions);
6
6
  }
7
7
  export declare type FormatErrorHandler = (error: GraphQLError | unknown, message: string, isDev: boolean) => GraphQLError;
8
8
  export declare const formatError: FormatErrorHandler;
package/utils.d.ts CHANGED
@@ -31,16 +31,3 @@ export declare function isAsyncIterable<TType>(maybeAsyncIterable: unknown): may
31
31
  export declare function handleStreamOrSingleExecutionResult<ContextType = DefaultContext>(payload: OnExecuteDoneEventPayload<ContextType>, fn: OnExecuteDoneHookResultOnNextHook<ContextType>): void | OnExecuteDoneHookResult<ContextType>;
32
32
  export declare function finalAsyncIterator<TInput>(source: AsyncIterable<TInput>, onFinal: () => void): AsyncGenerator<TInput>;
33
33
  export declare function errorAsyncIterator<TInput>(source: AsyncIterable<TInput>, onError: (err: unknown) => void): AsyncGenerator<TInput>;
34
- export interface BasicCache<V> {
35
- get(key: string): V | undefined;
36
- set(key: string, value: V): void;
37
- delete(key: string): void;
38
- clear?: () => void;
39
- }
40
- export declare function getInMemoryLRUCache<V>({ max, onDelete, }?: {
41
- max?: number;
42
- onDelete?: (key: string, value: V) => void;
43
- }): BasicCache<V> & {
44
- clear(): void;
45
- };
46
- export declare function isSourceObject(maybeSource: any): maybeSource is Source;