@powerhousedao/reactor-api 6.1.0-staging.0 → 6.1.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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="54de2de8-0918-5f80-961f-f2a72e390510")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="1eaae07d-8390-5f83-830a-b936b5c219db")}catch(e){}}();
3
3
  import { a as isSubgraphClass, c as loadDocumentModels, d as BaseSubgraph, i as buildGraphqlOperations, l as loadProcessors, n as buildGraphQlDriveDocument, o as debounce, r as buildGraphqlOperation, t as buildGraphQlDocument, u as loadSubgraphs } from "./utils-BFkbSO_H.mjs";
4
4
  import { AnalyticsQueryEngine } from "@powerhousedao/analytics-engine-core";
5
5
  import { AnalyticsModel, AnalyticsResolvers, typedefs } from "@powerhousedao/analytics-engine-graphql";
@@ -522,7 +522,7 @@ async function createGatewayAdapter(type, logger) {
522
522
  async function createHttpAdapter(type) {
523
523
  switch (type) {
524
524
  case "express": {
525
- const { createExpressHttpAdapter } = await import("./adapter-http-express-DO4ui7AV.mjs");
525
+ const { createExpressHttpAdapter } = await import("./adapter-http-express-D5OpUIbV.mjs");
526
526
  return createExpressHttpAdapter();
527
527
  }
528
528
  case "fastify": {
@@ -4413,10 +4413,10 @@ const ADMIN_USERS = getAdminUsers();
4413
4413
  //#endregion
4414
4414
  //#region src/graphql/system/version.ts
4415
4415
  function getVersion() {
4416
- return "6.1.0-staging.0";
4416
+ return "6.1.0";
4417
4417
  }
4418
4418
  function getGitHash() {
4419
- return "0d24fc6cf7535480366d00b1655c11a1699c19c3";
4419
+ return "2cfa316d304b9f205414f95576f6171a5460a838";
4420
4420
  }
4421
4421
  function getGitUrl() {
4422
4422
  return buildTreeUrl(getGitHash());
@@ -4446,6 +4446,19 @@ var SystemSubgraph = class extends BaseSubgraph {
4446
4446
  //#endregion
4447
4447
  //#region src/packages/http-loader.ts
4448
4448
  /**
4449
+ * Extract subgraph classes from the imported subgraphs/index.mjs module shape.
4450
+ *
4451
+ * The published bundle uses `export * as Foo from "./file"`, which Node turns
4452
+ * into `{ Foo: <namespace>, … }`. The inner namespace's keys come from the
4453
+ * source file's named exports — typically `Subgraph` / `default` / the class
4454
+ * name itself — so the shape varies. Flatten one level and keep callables.
4455
+ *
4456
+ * Exported for direct unit testing against synthetic module shapes.
4457
+ */
4458
+ function extractSubgraphsFromModule(module) {
4459
+ return Object.values(module).flatMap((namespace) => Object.values(namespace)).filter((s) => typeof s === "function");
4460
+ }
4461
+ /**
4449
4462
  * Loads document models, subgraphs, and processors from an HTTP registry.
4450
4463
  * Uses Node.js module loader hooks to import directly from HTTP URLs.
4451
4464
  *
@@ -4506,12 +4519,7 @@ var HttpPackageLoader = class {
4506
4519
  if (!this.isValidPackageName(packageName)) throw new Error(`Invalid package name: ${packageName}`);
4507
4520
  const url = `${this.registryUrl}-/cdn/${packageSpec}/node/subgraphs/index.mjs`;
4508
4521
  this.logger.verbose(`Importing subgraphs from: ${url}`);
4509
- const module = await import(url);
4510
- const subgraphs = new Array();
4511
- for (const [key, value] of Object.entries(module)) {
4512
- const subgraph = value[key];
4513
- if (subgraph && typeof subgraph === "function") subgraphs.push(subgraph);
4514
- }
4522
+ const subgraphs = extractSubgraphsFromModule(await import(url));
4515
4523
  this.logger.verbose(`Loaded ${subgraphs.length} subgraphs from ${packageName}`);
4516
4524
  return subgraphs;
4517
4525
  }
@@ -4659,6 +4667,26 @@ var ImportPackageLoader = class {
4659
4667
  };
4660
4668
  //#endregion
4661
4669
  //#region src/packages/package-manager.ts
4670
+ /**
4671
+ * A loader throwing "this package isn't mine to load" is normal — loaders are
4672
+ * fallbacks for each other. These shapes mean "not found here", not "broken".
4673
+ *
4674
+ * `ERR_MODULE_NOT_FOUND` is ambiguous: it can mean either (a) the loader's own
4675
+ * entry import for `pkg` failed (expected — the package isn't installed
4676
+ * locally), or (b) the entry loaded successfully but a *transitive* bare
4677
+ * import inside it couldn't resolve (real error — the bundle is broken). We
4678
+ * distinguish by checking whether the error names the package we asked for —
4679
+ * either bare (`'pkg'`) or as a subpath (`'pkg/subgraphs'`), since loaders
4680
+ * import sub-entries like `${pkg}/subgraphs` / `${pkg}/document-models`.
4681
+ */
4682
+ function isExpectedLoaderMiss(error, pkg) {
4683
+ if (!(error instanceof Error)) return false;
4684
+ const code = error.code;
4685
+ if (code === "ERR_UNSUPPORTED_DIR_IMPORT") return true;
4686
+ if (error.message.startsWith("Invalid package name:")) return true;
4687
+ if (code === "ERR_MODULE_NOT_FOUND") return error.message.includes(`'${pkg}'`) || error.message.includes(`"${pkg}"`) || error.message.includes(`'${pkg}/`) || error.message.includes(`"${pkg}/`);
4688
+ return false;
4689
+ }
4662
4690
  function getUniqueDocumentModels(...documentModels) {
4663
4691
  const uniqueModels = /* @__PURE__ */ new Map();
4664
4692
  for (const models of documentModels) for (const model of models) uniqueModels.set(model.documentModel.global.id, model);
@@ -4709,14 +4737,22 @@ var PackageManager = class {
4709
4737
  documentModelModuleMap.set("reactor-drive", [reactorDriveDocumentModelModule]);
4710
4738
  for (const pkg of packages) {
4711
4739
  const allDocumentModels = [];
4740
+ const failures = [];
4741
+ let succeeded = false;
4712
4742
  for (const loader of this.loaders) try {
4713
4743
  const documentModels = await loader.loadDocumentModels(pkg);
4714
4744
  allDocumentModels.push(...documentModels);
4715
4745
  this.logger.info(`[${loader.name}] Loaded document models from package @pkg: @documentModels`, pkg, documentModels.map((dm) => dm.documentModel.global.id));
4746
+ succeeded = true;
4716
4747
  break;
4717
4748
  } catch (error) {
4749
+ failures.push({
4750
+ loader: loader.name,
4751
+ error
4752
+ });
4718
4753
  this.logger.debug(`[${loader.name}] Failed to load document models from package @pkg: @error`, pkg, error);
4719
4754
  }
4755
+ this.maybeWarnAllLoadersFailed("document models", pkg, succeeded, failures);
4720
4756
  documentModelModuleMap.set(pkg, allDocumentModels);
4721
4757
  }
4722
4758
  return documentModelModuleMap;
@@ -4726,13 +4762,21 @@ var PackageManager = class {
4726
4762
  const subgraphsMap = /* @__PURE__ */ new Map();
4727
4763
  for (const pkg of packages) {
4728
4764
  const allSubgraphs = [];
4765
+ const failures = [];
4766
+ let succeeded = false;
4729
4767
  for (const loader of this.loaders) try {
4730
4768
  const subgraphs = await loader.loadSubgraphs(pkg);
4731
4769
  allSubgraphs.push(...subgraphs);
4770
+ succeeded = true;
4732
4771
  break;
4733
4772
  } catch (error) {
4773
+ failures.push({
4774
+ loader: loader.name,
4775
+ error
4776
+ });
4734
4777
  this.logger.debug(`[${loader.name}] Failed to load subgraphs from package ${pkg}`, error);
4735
4778
  }
4779
+ this.maybeWarnAllLoadersFailed("subgraphs", pkg, succeeded, failures);
4736
4780
  subgraphsMap.set(pkg, allSubgraphs);
4737
4781
  }
4738
4782
  return subgraphsMap;
@@ -4742,18 +4786,35 @@ var PackageManager = class {
4742
4786
  const processorsMap = /* @__PURE__ */ new Map();
4743
4787
  for (const pkg of packages) {
4744
4788
  const allProcessors = [];
4789
+ const failures = [];
4790
+ let succeeded = false;
4745
4791
  for (const loader of this.loaders) try {
4746
4792
  const processors = await loader.loadProcessors(pkg);
4747
4793
  if (processors) allProcessors.push(processors);
4794
+ succeeded = true;
4748
4795
  break;
4749
4796
  } catch (error) {
4797
+ failures.push({
4798
+ loader: loader.name,
4799
+ error
4800
+ });
4750
4801
  this.logger.debug(`[${loader.name}] Failed to load processors from package ${pkg}`, error);
4751
4802
  }
4803
+ this.maybeWarnAllLoadersFailed("processors", pkg, succeeded, failures);
4752
4804
  processorsMap.set(pkg, allProcessors);
4753
4805
  }
4754
4806
  this.updateProcessorsMap(processorsMap);
4755
4807
  return processorsMap;
4756
4808
  }
4809
+ maybeWarnAllLoadersFailed(kind, pkg, succeeded, failures) {
4810
+ if (succeeded || failures.length === 0) return;
4811
+ const realFailures = failures.filter(({ error }) => !isExpectedLoaderMiss(error, pkg));
4812
+ if (realFailures.length === 0) return;
4813
+ const details = realFailures.map(({ loader, error }) => {
4814
+ return ` [${loader}] ${error instanceof Error ? error.message : String(error)}`;
4815
+ }).join("\n");
4816
+ this.logger.warn(`All package loaders failed to load ${kind} from @pkg:\n@details`, pkg, details);
4817
+ }
4757
4818
  async updateDocumentModelsForPackage(pkg) {
4758
4819
  this.logger.debug(`Updating document models for package: ${pkg}`);
4759
4820
  const documentModels = await this.loadDocumentModels([pkg]);
@@ -4764,7 +4825,12 @@ var PackageManager = class {
4764
4825
  subscribePackages(packages) {
4765
4826
  const unsubs = [];
4766
4827
  for (const pkg of packages) {
4767
- if (!this.debouncedUpdateCallbacks.has(pkg)) this.debouncedUpdateCallbacks.set(pkg, debounce(() => this.updateDocumentModelsForPackage(pkg), 1e3));
4828
+ if (!this.debouncedUpdateCallbacks.has(pkg)) {
4829
+ const debouncedFn = debounce(() => this.updateDocumentModelsForPackage(pkg), 1e3);
4830
+ this.debouncedUpdateCallbacks.set(pkg, () => {
4831
+ debouncedFn();
4832
+ });
4833
+ }
4768
4834
  const debouncedCallback = this.debouncedUpdateCallbacks.get(pkg);
4769
4835
  for (const loader of this.loaders) if (loader.onDocumentModelsChange) {
4770
4836
  const unsub = loader.onDocumentModelsChange(pkg, debouncedCallback);
@@ -4946,11 +5012,11 @@ async function down(db) {
4946
5012
  * Custom migration provider that loads migrations from imported modules
4947
5013
  */
4948
5014
  var StaticMigrationProvider = class {
4949
- async getMigrations() {
4950
- return {
5015
+ getMigrations() {
5016
+ return Promise.resolve({
4951
5017
  "001_create_document_permissions": _001_create_document_permissions_exports,
4952
5018
  "002_add_document_protection": _002_add_document_protection_exports
4953
- };
5019
+ });
4954
5020
  }
4955
5021
  };
4956
5022
  /**
@@ -5042,7 +5108,7 @@ var AuthorizationService = class {
5042
5108
  * - Owner → yes
5043
5109
  * - Has ADMIN grant → yes
5044
5110
  */
5045
- async canManage(documentId, userAddress, getParentIds) {
5111
+ async canManage(documentId, userAddress, _getParentIds) {
5046
5112
  if (this.isSupremeAdmin(userAddress)) return true;
5047
5113
  if (!userAddress) return false;
5048
5114
  const owner = await this.documentPermissionService.getDocumentOwner(documentId);
@@ -5773,24 +5839,28 @@ function setupEventListeners(pkgManager, graphqlManager, reactorProcessorManager
5773
5839
  }
5774
5840
  graphqlManager.regenerateDocumentModelSubgraphs();
5775
5841
  });
5776
- pkgManager.onSubgraphsChange(async (packagedSubgraphs) => {
5777
- for (const [, subgraphs] of packagedSubgraphs) for (const subgraph of subgraphs) await graphqlManager.registerSubgraph(subgraph, "graphql");
5778
- await graphqlManager.updateRouter();
5842
+ pkgManager.onSubgraphsChange((packagedSubgraphs) => {
5843
+ (async () => {
5844
+ for (const [, subgraphs] of packagedSubgraphs) for (const subgraph of subgraphs) await graphqlManager.registerSubgraph(subgraph, "graphql");
5845
+ await graphqlManager.updateRouter();
5846
+ })();
5779
5847
  });
5780
- pkgManager.onProcessorsChange(async (processors) => {
5781
- for (const [packageName, fns] of processors) {
5782
- await reactorProcessorManager.unregisterFactory(packageName);
5783
- const validBuilders = fns.map((fn) => fn(module)).filter((factory) => factory !== null && typeof factory === "function");
5784
- if (!validBuilders.length) continue;
5785
- await reactorProcessorManager.registerFactory(packageName, async (driveHeader) => (await Promise.all(validBuilders.map(async (driveFactory) => {
5786
- try {
5787
- return await driveFactory(driveHeader);
5788
- } catch (e) {
5789
- defaultLogger.error(`Error creating processor for drive ${driveHeader.id}:`, e);
5790
- return [];
5791
- }
5792
- }))).flat());
5793
- }
5848
+ pkgManager.onProcessorsChange((processors) => {
5849
+ (async () => {
5850
+ for (const [packageName, fns] of processors) {
5851
+ await reactorProcessorManager.unregisterFactory(packageName);
5852
+ const validBuilders = fns.map((fn) => fn(module)).filter((factory) => factory !== null && typeof factory === "function");
5853
+ if (!validBuilders.length) continue;
5854
+ await reactorProcessorManager.registerFactory(packageName, async (driveHeader) => (await Promise.all(validBuilders.map(async (driveFactory) => {
5855
+ try {
5856
+ return await driveFactory(driveHeader);
5857
+ } catch (e) {
5858
+ defaultLogger.error(`Error creating processor for drive ${driveHeader.id}:`, e);
5859
+ return [];
5860
+ }
5861
+ }))).flat());
5862
+ }
5863
+ })();
5794
5864
  });
5795
5865
  }
5796
5866
  /**
@@ -6045,20 +6115,21 @@ async function initializeAndStartAPI(clientInitializer, options, processorApp) {
6045
6115
  //#region src/services/package-storage.ts
6046
6116
  var InMemoryPackageStorage = class {
6047
6117
  packages = /* @__PURE__ */ new Map();
6048
- async get(name) {
6049
- return this.packages.get(name);
6118
+ get(name) {
6119
+ return Promise.resolve(this.packages.get(name));
6050
6120
  }
6051
- async getAll() {
6052
- return Array.from(this.packages.values());
6121
+ getAll() {
6122
+ return Promise.resolve(Array.from(this.packages.values()));
6053
6123
  }
6054
- async set(name, info) {
6124
+ set(name, info) {
6055
6125
  this.packages.set(name, info);
6126
+ return Promise.resolve();
6056
6127
  }
6057
- async delete(name) {
6058
- return this.packages.delete(name);
6128
+ delete(name) {
6129
+ return Promise.resolve(this.packages.delete(name));
6059
6130
  }
6060
- async has(name) {
6061
- return this.packages.has(name);
6131
+ has(name) {
6132
+ return Promise.resolve(this.packages.has(name));
6062
6133
  }
6063
6134
  };
6064
6135
  //#endregion
@@ -6141,7 +6212,7 @@ var PackageManagementService = class {
6141
6212
  }
6142
6213
  };
6143
6214
  //#endregion
6144
- export { ADMIN_USERS, ActionContextInputSchema, ActionInputSchema, AddRelationshipDocument, AnalyticsSubgraph, AttachmentInputSchema, AuthService, AuthSubgraph, BaseSubgraph, ChannelMetaInputSchema, CreateDocumentDocument, CreateEmptyDocumentDocument, DeleteDocumentDocument, DeleteDocumentsDocument, DocumentChangeType, DocumentChangeTypeSchema, DocumentChangesDocument, DocumentOperationsFilterInputSchema, DocumentPermissionService, FindDocumentsDocument, GetDocumentDocument, GetDocumentIncomingRelationshipsDocument, GetDocumentModelsDocument, GetDocumentOperationsDocument, GetDocumentOutgoingRelationshipsDocument, GetDocumentWithOperationsDocument, GetJobStatusDocument, GraphQLManager, HttpDocumentModelLoader, HttpPackageLoader, ImportPackageLoader, InMemoryPackageStorage, JobChangesDocument, MoveRelationshipDocument, MutateDocumentAsyncDocument, MutateDocumentDocument, OperationContextInputSchema, OperationInputSchema, OperationWithContextInputSchema, OperationsFilterInputSchema, PackageManagementService, PackageManager, PackagesSubgraph, PagingInputSchema, PhDocumentFieldsFragmentDoc, PollSyncEnvelopesDocument, PropagationMode, PropagationModeSchema, PushSyncEnvelopesDocument, ReactorSignerAppInputSchema, ReactorSignerInputSchema, ReactorSignerUserInputSchema, ReactorSubgraph, RemoteCursorInputSchema, RemoteFilterInputSchema, RemoveRelationshipDocument, RenameDocumentDocument, SearchFilterInputSchema, SetPreferredEditorDocument, SyncEnvelopeInputSchema, SyncEnvelopeType, SyncEnvelopeTypeSchema, SystemSubgraph, TouchChannelDocument, TouchChannelInputSchema, ViewFilterInputSchema, buildGraphQlDocument, buildGraphQlDriveDocument, buildGraphqlOperation, buildGraphqlOperations, buildSubgraphSchemaModule, createAuthFetchMiddleware, createGatewayAdapter, createHttpAdapter, createMergedSchema, createReactorGraphQLClient, createSchema, definedNonNullAnySchema, driveIdFromUrl, generateDocumentModelSchema, getAuthContext, getDbClient, getDocumentModelSchemaName, getDocumentModelTypeDefs, getGitHash, getGitUrl, getSdk, getUniqueDocumentModels, getVersion, initAnalyticsStoreSql, initializeAndStartAPI, isDefinedNonNullAny, isSubgraphClass, parseDriveUrl, renderGraphqlPlayground };
6215
+ export { ADMIN_USERS, ActionContextInputSchema, ActionInputSchema, AddRelationshipDocument, AnalyticsSubgraph, AttachmentInputSchema, AuthService, AuthSubgraph, BaseSubgraph, ChannelMetaInputSchema, CreateDocumentDocument, CreateEmptyDocumentDocument, DeleteDocumentDocument, DeleteDocumentsDocument, DocumentChangeType, DocumentChangeTypeSchema, DocumentChangesDocument, DocumentOperationsFilterInputSchema, DocumentPermissionService, FindDocumentsDocument, GetDocumentDocument, GetDocumentIncomingRelationshipsDocument, GetDocumentModelsDocument, GetDocumentOperationsDocument, GetDocumentOutgoingRelationshipsDocument, GetDocumentWithOperationsDocument, GetJobStatusDocument, GraphQLManager, HttpDocumentModelLoader, HttpPackageLoader, ImportPackageLoader, InMemoryPackageStorage, JobChangesDocument, MoveRelationshipDocument, MutateDocumentAsyncDocument, MutateDocumentDocument, OperationContextInputSchema, OperationInputSchema, OperationWithContextInputSchema, OperationsFilterInputSchema, PackageManagementService, PackageManager, PackagesSubgraph, PagingInputSchema, PhDocumentFieldsFragmentDoc, PollSyncEnvelopesDocument, PropagationMode, PropagationModeSchema, PushSyncEnvelopesDocument, ReactorSignerAppInputSchema, ReactorSignerInputSchema, ReactorSignerUserInputSchema, ReactorSubgraph, RemoteCursorInputSchema, RemoteFilterInputSchema, RemoveRelationshipDocument, RenameDocumentDocument, SearchFilterInputSchema, SetPreferredEditorDocument, SyncEnvelopeInputSchema, SyncEnvelopeType, SyncEnvelopeTypeSchema, SystemSubgraph, TouchChannelDocument, TouchChannelInputSchema, ViewFilterInputSchema, buildGraphQlDocument, buildGraphQlDriveDocument, buildGraphqlOperation, buildGraphqlOperations, buildSubgraphSchemaModule, createAuthFetchMiddleware, createGatewayAdapter, createHttpAdapter, createMergedSchema, createReactorGraphQLClient, createSchema, definedNonNullAnySchema, driveIdFromUrl, extractSubgraphsFromModule, generateDocumentModelSchema, getAuthContext, getDbClient, getDocumentModelSchemaName, getDocumentModelTypeDefs, getGitHash, getGitUrl, getSdk, getUniqueDocumentModels, getVersion, initAnalyticsStoreSql, initializeAndStartAPI, isDefinedNonNullAny, isExpectedLoaderMiss, isSubgraphClass, parseDriveUrl, renderGraphqlPlayground };
6145
6216
 
6146
6217
  //# sourceMappingURL=index.mjs.map
6147
- //# debugId=54de2de8-0918-5f80-961f-f2a72e390510
6218
+ //# debugId=1eaae07d-8390-5f83-830a-b936b5c219db