@orion-js/graphql 4.2.4 → 4.3.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.js CHANGED
@@ -432,7 +432,7 @@ function getScalar_default(fieldType) {
432
432
  throw new Error(`Field type "${fieldType.name}" has no convertion to GraphQLType`);
433
433
  }
434
434
 
435
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/type.js
435
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/type.js
436
436
  function type(input) {
437
437
  if (input === null) {
438
438
  return "Null";
@@ -445,21 +445,21 @@ function type(input) {
445
445
  return typeResult === "AsyncFunction" ? "Promise" : typeResult;
446
446
  }
447
447
 
448
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/isArray.js
448
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/isArray.js
449
449
  var { isArray } = Array;
450
450
 
451
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/isInteger.js
451
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/isInteger.js
452
452
  function _isInteger(n) {
453
453
  return n << 0 === n;
454
454
  }
455
455
  var isInteger = Number.isInteger || _isInteger;
456
456
 
457
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/createPath.js
457
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/createPath.js
458
458
  function createPath(path, delimiter = ".") {
459
459
  return typeof path === "string" ? path.split(delimiter).map((x) => isInteger(x) ? Number(x) : x) : path;
460
460
  }
461
461
 
462
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/equals.js
462
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/equals.js
463
463
  function _indexOf(valueToFind, list) {
464
464
  if (!isArray(list))
465
465
  throw new Error(`Cannot read property 'indexOf' of ${list}`);
@@ -564,7 +564,7 @@ function equals(a, b) {
564
564
  return false;
565
565
  }
566
566
 
567
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isType.js
567
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/isType.js
568
568
  function isType(xType, x) {
569
569
  if (arguments.length === 1) {
570
570
  return (xHolder) => isType(xType, xHolder);
@@ -572,12 +572,12 @@ function isType(xType, x) {
572
572
  return type(x) === xType;
573
573
  }
574
574
 
575
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/compare.js
575
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/compare.js
576
576
  function compare(a, b) {
577
577
  return String(a) === String(b);
578
578
  }
579
579
 
580
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/includes.js
580
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/includes.js
581
581
  function includes(a, list) {
582
582
  let index = -1;
583
583
  const { length } = list;
@@ -587,7 +587,7 @@ function includes(a, list) {
587
587
  return false;
588
588
  }
589
589
 
590
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/omit.js
590
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/omit.js
591
591
  function omit(propsToOmit, obj) {
592
592
  if (arguments.length === 1) return (_obj) => omit(propsToOmit, _obj);
593
593
  if (obj === null || obj === void 0)
@@ -600,7 +600,7 @@ function omit(propsToOmit, obj) {
600
600
  return willReturn;
601
601
  }
602
602
 
603
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isEmpty.js
603
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/isEmpty.js
604
604
  function isEmpty(input) {
605
605
  const inputType = type(input);
606
606
  if (["Undefined", "NaN", "Number", "Null"].includes(inputType))
@@ -1324,60 +1324,78 @@ var createMutation = (options) => {
1324
1324
  };
1325
1325
  var serviceMetadata = /* @__PURE__ */ new WeakMap();
1326
1326
  var internalResolversMetadata = /* @__PURE__ */ new WeakMap();
1327
+ var resolverEntriesByClass = /* @__PURE__ */ new Map();
1328
+ var pendingResolverEntries = {};
1327
1329
  function Resolvers() {
1328
1330
  return (target, context) => {
1329
1331
  Service()(target, context);
1330
1332
  serviceMetadata.set(target, { _serviceType: "resolvers" });
1333
+ if (Object.keys(pendingResolverEntries).length > 0) {
1334
+ resolverEntriesByClass.set(target, pendingResolverEntries);
1335
+ pendingResolverEntries = {};
1336
+ }
1331
1337
  };
1332
1338
  }
1333
1339
  function Query(options = {}) {
1334
1340
  return (method, context) => {
1335
1341
  const propertyKey = String(context.name);
1336
- context.addInitializer(function() {
1337
- const resolvers = internalResolversMetadata.get(this) || {};
1338
- if (context.kind === "method") {
1339
- resolvers[propertyKey] = createResolver2({
1340
- resolverId: propertyKey,
1341
- params: getTargetMetadata(method, propertyKey, "params") || {},
1342
- returns: getTargetMetadata(method, propertyKey, "returns") || "string",
1343
- middlewares: getTargetMetadata(method, propertyKey, "middlewares") || [],
1344
- ...options,
1345
- resolve: this[propertyKey].bind(this)
1346
- });
1347
- }
1348
- if (context.kind === "field") {
1349
- resolvers[propertyKey] = this[propertyKey];
1350
- }
1351
- internalResolversMetadata.set(this, resolvers);
1352
- });
1342
+ if (context.kind === "method") {
1343
+ const params = getTargetMetadata(method, propertyKey, "params") || {};
1344
+ const returns = getTargetMetadata(method, propertyKey, "returns") || "string";
1345
+ const middlewares = getTargetMetadata(method, propertyKey, "middlewares") || [];
1346
+ pendingResolverEntries[propertyKey] = (instance) => createResolver2({
1347
+ resolverId: propertyKey,
1348
+ params,
1349
+ returns,
1350
+ middlewares,
1351
+ ...options,
1352
+ resolve: instance[propertyKey].bind(instance)
1353
+ });
1354
+ }
1355
+ if (context.kind === "field") {
1356
+ pendingResolverEntries[propertyKey] = (instance) => instance[propertyKey];
1357
+ }
1353
1358
  return method;
1354
1359
  };
1355
1360
  }
1356
1361
  function Mutation(options = {}) {
1357
1362
  return (method, context) => {
1358
1363
  const propertyKey = String(context.name);
1359
- context.addInitializer(function() {
1360
- const resolvers = internalResolversMetadata.get(this) || {};
1361
- if (context.kind === "method") {
1362
- resolvers[propertyKey] = createResolver2({
1363
- resolverId: propertyKey,
1364
- params: getTargetMetadata(method, propertyKey, "params") || {},
1365
- returns: getTargetMetadata(method, propertyKey, "returns") || "string",
1366
- middlewares: getTargetMetadata(method, propertyKey, "middlewares") || [],
1367
- ...options,
1368
- mutation: true,
1369
- resolve: this[propertyKey].bind(this)
1370
- });
1371
- }
1372
- if (context.kind === "field") {
1373
- this[propertyKey].mutation = true;
1374
- resolvers[propertyKey] = this[propertyKey];
1375
- }
1376
- internalResolversMetadata.set(this, resolvers);
1377
- });
1364
+ if (context.kind === "method") {
1365
+ const params = getTargetMetadata(method, propertyKey, "params") || {};
1366
+ const returns = getTargetMetadata(method, propertyKey, "returns") || "string";
1367
+ const middlewares = getTargetMetadata(method, propertyKey, "middlewares") || [];
1368
+ pendingResolverEntries[propertyKey] = (instance) => createResolver2({
1369
+ resolverId: propertyKey,
1370
+ params,
1371
+ returns,
1372
+ middlewares,
1373
+ ...options,
1374
+ mutation: true,
1375
+ resolve: instance[propertyKey].bind(instance)
1376
+ });
1377
+ }
1378
+ if (context.kind === "field") {
1379
+ pendingResolverEntries[propertyKey] = (instance) => {
1380
+ instance[propertyKey].mutation = true;
1381
+ return instance[propertyKey];
1382
+ };
1383
+ }
1378
1384
  return method;
1379
1385
  };
1380
1386
  }
1387
+ function registerPendingResolver(propertyKey, setup) {
1388
+ pendingResolverEntries[propertyKey] = setup;
1389
+ }
1390
+ function initializeResolversIfNeeded(instance) {
1391
+ if (internalResolversMetadata.has(instance)) return;
1392
+ const entries = resolverEntriesByClass.get(instance.constructor) || {};
1393
+ const resolvers = {};
1394
+ for (const [key, setup] of Object.entries(entries)) {
1395
+ resolvers[key] = setup(instance);
1396
+ }
1397
+ internalResolversMetadata.set(instance, resolvers);
1398
+ }
1381
1399
  function getServiceResolvers(target) {
1382
1400
  const instance = getInstance(target);
1383
1401
  const className = instance.constructor.name;
@@ -1389,6 +1407,7 @@ function getServiceResolvers(target) {
1389
1407
  if (instanceMetadata._serviceType !== "resolvers") {
1390
1408
  throw new Error(`${errorMessage}. Got class type ${instanceMetadata._serviceType}`);
1391
1409
  }
1410
+ initializeResolversIfNeeded(instance);
1392
1411
  const resolversMap = internalResolversMetadata.get(instance) || {};
1393
1412
  return resolversMap;
1394
1413
  }
@@ -1401,6 +1420,8 @@ import {
1401
1420
  var createModelResolver = createModelResolverFromResolvers;
1402
1421
  var serviceMetadata2 = /* @__PURE__ */ new WeakMap();
1403
1422
  var modelResolversMetadata = /* @__PURE__ */ new WeakMap();
1423
+ var modelResolverEntriesByClass = /* @__PURE__ */ new Map();
1424
+ var pendingModelResolverEntries = {};
1404
1425
  function ModelResolvers(typedSchema, options = {}) {
1405
1426
  return (target, context) => {
1406
1427
  Service2()(target, context);
@@ -1417,37 +1438,47 @@ function ModelResolvers(typedSchema, options = {}) {
1417
1438
  }
1418
1439
  throw new Error(`You must specify a model name for the model resolvers (at: ${className})`);
1419
1440
  })();
1420
- context.addInitializer(function() {
1421
- serviceMetadata2.set(this, {
1422
- _serviceType: "modelResolvers",
1423
- options,
1424
- _modelName: modelName
1425
- });
1441
+ serviceMetadata2.set(target, {
1442
+ _serviceType: "modelResolvers",
1443
+ options,
1444
+ _modelName: modelName
1426
1445
  });
1446
+ if (Object.keys(pendingModelResolverEntries).length > 0) {
1447
+ modelResolverEntriesByClass.set(target, pendingModelResolverEntries);
1448
+ pendingModelResolverEntries = {};
1449
+ }
1427
1450
  };
1428
1451
  }
1429
1452
  function ModelResolver(options = {}) {
1430
1453
  return (method, context) => {
1431
1454
  const propertyKey = String(context.name);
1432
- context.addInitializer(function() {
1433
- const modelResolvers = modelResolversMetadata.get(this) || {};
1434
- if (context.kind === "method") {
1435
- modelResolvers[propertyKey] = createModelResolver({
1436
- params: getTargetMetadata(method, propertyKey, "params") || {},
1437
- returns: getTargetMetadata(method, propertyKey, "returns") || "string",
1438
- middlewares: getTargetMetadata(method, propertyKey, "middlewares") || [],
1439
- ...options,
1440
- resolve: this[propertyKey].bind(this)
1441
- });
1442
- }
1443
- if (context.kind === "field") {
1444
- modelResolvers[propertyKey] = this[propertyKey];
1445
- }
1446
- modelResolversMetadata.set(this, modelResolvers);
1447
- });
1455
+ if (context.kind === "method") {
1456
+ const params = getTargetMetadata(method, propertyKey, "params") || {};
1457
+ const returns = getTargetMetadata(method, propertyKey, "returns") || "string";
1458
+ const middlewares = getTargetMetadata(method, propertyKey, "middlewares") || [];
1459
+ pendingModelResolverEntries[propertyKey] = (instance) => createModelResolver({
1460
+ params,
1461
+ returns,
1462
+ middlewares,
1463
+ ...options,
1464
+ resolve: instance[propertyKey].bind(instance)
1465
+ });
1466
+ }
1467
+ if (context.kind === "field") {
1468
+ pendingModelResolverEntries[propertyKey] = (instance) => instance[propertyKey];
1469
+ }
1448
1470
  return method;
1449
1471
  };
1450
1472
  }
1473
+ function initializeModelResolversIfNeeded(instance) {
1474
+ if (modelResolversMetadata.has(instance)) return;
1475
+ const entries = modelResolverEntriesByClass.get(instance.constructor) || {};
1476
+ const resolvers = {};
1477
+ for (const [key, setup] of Object.entries(entries)) {
1478
+ resolvers[key] = setup(instance);
1479
+ }
1480
+ modelResolversMetadata.set(instance, resolvers);
1481
+ }
1451
1482
  function getServiceModelResolvers(target) {
1452
1483
  const instance = getInstance2(target);
1453
1484
  if (!serviceMetadata2.has(instance.constructor)) {
@@ -1461,6 +1492,7 @@ function getServiceModelResolvers(target) {
1461
1492
  "You must pass a class decorated with @ModelResolvers to getServiceModelResolvers"
1462
1493
  );
1463
1494
  }
1495
+ initializeModelResolversIfNeeded(instance);
1464
1496
  const modelResolversMap = modelResolversMetadata.get(instance) || {};
1465
1497
  return {
1466
1498
  [instanceMetadata._modelName]: modelResolversMap
@@ -1471,31 +1503,33 @@ function getServiceModelResolvers(target) {
1471
1503
  import { getInstance as getInstance3, Service as Service3 } from "@orion-js/services";
1472
1504
  var serviceMetadata3 = /* @__PURE__ */ new WeakMap();
1473
1505
  var subscriptionsMetadata = /* @__PURE__ */ new WeakMap();
1506
+ var subscriptionEntriesByClass = /* @__PURE__ */ new Map();
1507
+ var pendingSubscriptionEntries = {};
1474
1508
  function Subscriptions() {
1475
1509
  return (target, context) => {
1476
1510
  Service3()(target, context);
1477
- context.addInitializer(function() {
1478
- serviceMetadata3.set(this, { _serviceType: "subscriptions" });
1479
- });
1511
+ serviceMetadata3.set(target, { _serviceType: "subscriptions" });
1512
+ if (Object.keys(pendingSubscriptionEntries).length > 0) {
1513
+ subscriptionEntriesByClass.set(target, pendingSubscriptionEntries);
1514
+ pendingSubscriptionEntries = {};
1515
+ }
1480
1516
  };
1481
1517
  }
1482
1518
  function Subscription() {
1483
1519
  return (_method, context) => {
1484
1520
  const propertyKey = String(context.name);
1485
- context.addInitializer(function() {
1486
- const repo = serviceMetadata3.get(this.constructor);
1487
- if (!repo || repo._serviceType !== "subscriptions") {
1488
- throw new Error(
1489
- "You must pass a class decorated with @Subscriptions if you want to use @Subscription"
1490
- );
1491
- }
1492
- const subscriptions = subscriptionsMetadata.get(this) || {};
1493
- subscriptions[propertyKey] = this[propertyKey];
1494
- subscriptionsMetadata.set(this, subscriptions);
1495
- this[propertyKey] = subscriptions[propertyKey];
1496
- });
1521
+ pendingSubscriptionEntries[propertyKey] = (instance) => instance[propertyKey];
1497
1522
  };
1498
1523
  }
1524
+ function initializeSubscriptionsIfNeeded(instance) {
1525
+ if (subscriptionsMetadata.has(instance)) return;
1526
+ const entries = subscriptionEntriesByClass.get(instance.constructor) || {};
1527
+ const subscriptions = {};
1528
+ for (const [key, setup] of Object.entries(entries)) {
1529
+ subscriptions[key] = setup(instance);
1530
+ }
1531
+ subscriptionsMetadata.set(instance, subscriptions);
1532
+ }
1499
1533
  function getServiceSubscriptions(target) {
1500
1534
  const instance = getInstance3(target);
1501
1535
  if (!serviceMetadata3.has(instance.constructor)) {
@@ -1509,6 +1543,7 @@ function getServiceSubscriptions(target) {
1509
1543
  "You must pass a class decorated with @Subscriptions to getServiceSubscriptions"
1510
1544
  );
1511
1545
  }
1546
+ initializeSubscriptionsIfNeeded(instance);
1512
1547
  const subscriptionsMap = subscriptionsMetadata.get(instance) || {};
1513
1548
  return subscriptionsMap;
1514
1549
  }
@@ -1541,6 +1576,7 @@ export {
1541
1576
  getTargetMetadata,
1542
1577
  getWebsockerViewer,
1543
1578
  internalResolversMetadata,
1579
+ registerPendingResolver,
1544
1580
  resolversSchemas_default as resolversSchemas,
1545
1581
  serializeSchema,
1546
1582
  setGetWebsockerViewer,