@powerhousedao/reactor-api 6.0.0-dev.22 → 6.0.0-dev.221
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 +6 -0
- package/dist/index.d.mts +3037 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +6687 -0
- package/dist/index.mjs.map +1 -0
- package/dist/src/packages/https-hooks.d.mts +39 -0
- package/dist/src/packages/https-hooks.d.mts.map +1 -0
- package/dist/src/packages/https-hooks.mjs +79 -0
- package/dist/src/packages/https-hooks.mjs.map +1 -0
- package/dist/src/packages/vite-loader.d.mts +29 -0
- package/dist/src/packages/vite-loader.d.mts.map +1 -0
- package/dist/src/packages/vite-loader.mjs +142 -0
- package/dist/src/packages/vite-loader.mjs.map +1 -0
- package/dist/types-Do4QTfT3.d.mts +37 -0
- package/dist/types-Do4QTfT3.d.mts.map +1 -0
- package/dist/utils-CVrD_vPF.mjs +287 -0
- package/dist/utils-CVrD_vPF.mjs.map +1 -0
- package/package.json +71 -63
- package/dist/codegen.d.ts +0 -4
- package/dist/codegen.d.ts.map +0 -1
- package/dist/codegen.js +0 -38
- package/dist/codegen.js.map +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -14
- package/dist/index.js.map +0 -1
- package/dist/src/config.d.ts +0 -7
- package/dist/src/config.d.ts.map +0 -1
- package/dist/src/config.js +0 -10
- package/dist/src/config.js.map +0 -1
- package/dist/src/graphql/analytics-subgraph.d.ts +0 -14
- package/dist/src/graphql/analytics-subgraph.d.ts.map +0 -1
- package/dist/src/graphql/analytics-subgraph.js +0 -26
- package/dist/src/graphql/analytics-subgraph.js.map +0 -1
- package/dist/src/graphql/auth/index.d.ts +0 -2
- package/dist/src/graphql/auth/index.d.ts.map +0 -1
- package/dist/src/graphql/auth/index.js +0 -2
- package/dist/src/graphql/auth/index.js.map +0 -1
- package/dist/src/graphql/auth/resolvers.d.ts +0 -149
- package/dist/src/graphql/auth/resolvers.d.ts.map +0 -1
- package/dist/src/graphql/auth/resolvers.js +0 -173
- package/dist/src/graphql/auth/resolvers.js.map +0 -1
- package/dist/src/graphql/auth/schema.graphql +0 -173
- package/dist/src/graphql/auth/subgraph.d.ts +0 -177
- package/dist/src/graphql/auth/subgraph.d.ts.map +0 -1
- package/dist/src/graphql/auth/subgraph.js +0 -340
- package/dist/src/graphql/auth/subgraph.js.map +0 -1
- package/dist/src/graphql/base-subgraph.d.ts +0 -20
- package/dist/src/graphql/base-subgraph.d.ts.map +0 -1
- package/dist/src/graphql/base-subgraph.js +0 -34
- package/dist/src/graphql/base-subgraph.js.map +0 -1
- package/dist/src/graphql/document-model-subgraph.d.ts +0 -51
- package/dist/src/graphql/document-model-subgraph.d.ts.map +0 -1
- package/dist/src/graphql/document-model-subgraph.js +0 -104
- package/dist/src/graphql/document-model-subgraph.js.map +0 -1
- package/dist/src/graphql/drive-subgraph.d.ts +0 -25
- package/dist/src/graphql/drive-subgraph.d.ts.map +0 -1
- package/dist/src/graphql/drive-subgraph.js +0 -487
- package/dist/src/graphql/drive-subgraph.js.map +0 -1
- package/dist/src/graphql/graphql-manager.d.ts +0 -47
- package/dist/src/graphql/graphql-manager.d.ts.map +0 -1
- package/dist/src/graphql/graphql-manager.js +0 -433
- package/dist/src/graphql/graphql-manager.js.map +0 -1
- package/dist/src/graphql/index.d.ts +0 -9
- package/dist/src/graphql/index.d.ts.map +0 -1
- package/dist/src/graphql/index.js +0 -9
- package/dist/src/graphql/index.js.map +0 -1
- package/dist/src/graphql/playground.d.ts +0 -2
- package/dist/src/graphql/playground.d.ts.map +0 -1
- package/dist/src/graphql/playground.js +0 -74
- package/dist/src/graphql/playground.js.map +0 -1
- package/dist/src/graphql/reactor/adapters.d.ts +0 -62
- package/dist/src/graphql/reactor/adapters.d.ts.map +0 -1
- package/dist/src/graphql/reactor/adapters.js +0 -270
- package/dist/src/graphql/reactor/adapters.js.map +0 -1
- package/dist/src/graphql/reactor/factory.d.ts +0 -84
- package/dist/src/graphql/reactor/factory.d.ts.map +0 -1
- package/dist/src/graphql/reactor/factory.js +0 -7
- package/dist/src/graphql/reactor/factory.js.map +0 -1
- package/dist/src/graphql/reactor/gen/graphql.d.ts +0 -1242
- package/dist/src/graphql/reactor/gen/graphql.d.ts.map +0 -1
- package/dist/src/graphql/reactor/gen/graphql.js +0 -496
- package/dist/src/graphql/reactor/gen/graphql.js.map +0 -1
- package/dist/src/graphql/reactor/index.d.ts +0 -4
- package/dist/src/graphql/reactor/index.d.ts.map +0 -1
- package/dist/src/graphql/reactor/index.js +0 -4
- package/dist/src/graphql/reactor/index.js.map +0 -1
- package/dist/src/graphql/reactor/operations.graphql +0 -253
- package/dist/src/graphql/reactor/pubsub.d.ts +0 -27
- package/dist/src/graphql/reactor/pubsub.d.ts.map +0 -1
- package/dist/src/graphql/reactor/pubsub.js +0 -93
- package/dist/src/graphql/reactor/pubsub.js.map +0 -1
- package/dist/src/graphql/reactor/requester.d.ts +0 -4
- package/dist/src/graphql/reactor/requester.d.ts.map +0 -1
- package/dist/src/graphql/reactor/requester.js +0 -22
- package/dist/src/graphql/reactor/requester.js.map +0 -1
- package/dist/src/graphql/reactor/requester.with-zod.d.ts +0 -4
- package/dist/src/graphql/reactor/requester.with-zod.d.ts.map +0 -1
- package/dist/src/graphql/reactor/requester.with-zod.js +0 -53
- package/dist/src/graphql/reactor/requester.with-zod.js.map +0 -1
- package/dist/src/graphql/reactor/resolvers.d.ts +0 -175
- package/dist/src/graphql/reactor/resolvers.d.ts.map +0 -1
- package/dist/src/graphql/reactor/resolvers.js +0 -526
- package/dist/src/graphql/reactor/resolvers.js.map +0 -1
- package/dist/src/graphql/reactor/schema.graphql +0 -432
- package/dist/src/graphql/reactor/subgraph.d.ts +0 -47
- package/dist/src/graphql/reactor/subgraph.d.ts.map +0 -1
- package/dist/src/graphql/reactor/subgraph.js +0 -555
- package/dist/src/graphql/reactor/subgraph.js.map +0 -1
- package/dist/src/graphql/reactor/validation.d.ts +0 -102
- package/dist/src/graphql/reactor/validation.d.ts.map +0 -1
- package/dist/src/graphql/reactor/validation.js +0 -73
- package/dist/src/graphql/reactor/validation.js.map +0 -1
- package/dist/src/graphql/system/env/getters.d.ts +0 -2
- package/dist/src/graphql/system/env/getters.d.ts.map +0 -1
- package/dist/src/graphql/system/env/getters.js +0 -4
- package/dist/src/graphql/system/env/getters.js.map +0 -1
- package/dist/src/graphql/system/env/index.d.ts +0 -2
- package/dist/src/graphql/system/env/index.d.ts.map +0 -1
- package/dist/src/graphql/system/env/index.js +0 -5
- package/dist/src/graphql/system/env/index.js.map +0 -1
- package/dist/src/graphql/system/index.d.ts +0 -3
- package/dist/src/graphql/system/index.d.ts.map +0 -1
- package/dist/src/graphql/system/index.js +0 -3
- package/dist/src/graphql/system/index.js.map +0 -1
- package/dist/src/graphql/system/system-subgraph.d.ts +0 -49
- package/dist/src/graphql/system/system-subgraph.d.ts.map +0 -1
- package/dist/src/graphql/system/system-subgraph.js +0 -130
- package/dist/src/graphql/system/system-subgraph.js.map +0 -1
- package/dist/src/graphql/system/types.d.ts +0 -2
- package/dist/src/graphql/system/types.d.ts.map +0 -1
- package/dist/src/graphql/system/types.js +0 -2
- package/dist/src/graphql/system/types.js.map +0 -1
- package/dist/src/graphql/temp-hack-rwa-type-defs.d.ts +0 -57
- package/dist/src/graphql/temp-hack-rwa-type-defs.d.ts.map +0 -1
- package/dist/src/graphql/temp-hack-rwa-type-defs.js +0 -2
- package/dist/src/graphql/temp-hack-rwa-type-defs.js.map +0 -1
- package/dist/src/graphql/types.d.ts +0 -103
- package/dist/src/graphql/types.d.ts.map +0 -1
- package/dist/src/graphql/types.js +0 -2
- package/dist/src/graphql/types.js.map +0 -1
- package/dist/src/graphql/utils.d.ts +0 -26
- package/dist/src/graphql/utils.d.ts.map +0 -1
- package/dist/src/graphql/utils.js +0 -100
- package/dist/src/graphql/utils.js.map +0 -1
- package/dist/src/graphql/websocket.d.ts +0 -3
- package/dist/src/graphql/websocket.d.ts.map +0 -1
- package/dist/src/graphql/websocket.js +0 -15
- package/dist/src/graphql/websocket.js.map +0 -1
- package/dist/src/migrations/001_create_document_permissions.d.ts +0 -4
- package/dist/src/migrations/001_create_document_permissions.d.ts.map +0 -1
- package/dist/src/migrations/001_create_document_permissions.js +0 -91
- package/dist/src/migrations/001_create_document_permissions.js.map +0 -1
- package/dist/src/migrations/index.d.ts +0 -10
- package/dist/src/migrations/index.d.ts.map +0 -1
- package/dist/src/migrations/index.js +0 -56
- package/dist/src/migrations/index.js.map +0 -1
- package/dist/src/packages/import-loader.d.ts +0 -16
- package/dist/src/packages/import-loader.d.ts.map +0 -1
- package/dist/src/packages/import-loader.js +0 -61
- package/dist/src/packages/import-loader.js.map +0 -1
- package/dist/src/packages/import-resolver.d.ts +0 -5
- package/dist/src/packages/import-resolver.d.ts.map +0 -1
- package/dist/src/packages/import-resolver.js +0 -127
- package/dist/src/packages/import-resolver.js.map +0 -1
- package/dist/src/packages/package-manager.d.ts +0 -34
- package/dist/src/packages/package-manager.d.ts.map +0 -1
- package/dist/src/packages/package-manager.js +0 -213
- package/dist/src/packages/package-manager.js.map +0 -1
- package/dist/src/packages/types.d.ts +0 -39
- package/dist/src/packages/types.d.ts.map +0 -1
- package/dist/src/packages/types.js +0 -2
- package/dist/src/packages/types.js.map +0 -1
- package/dist/src/packages/util.d.ts +0 -27
- package/dist/src/packages/util.d.ts.map +0 -1
- package/dist/src/packages/util.js +0 -97
- package/dist/src/packages/util.js.map +0 -1
- package/dist/src/packages/vite-loader.d.ts +0 -24
- package/dist/src/packages/vite-loader.d.ts.map +0 -1
- package/dist/src/packages/vite-loader.js +0 -172
- package/dist/src/packages/vite-loader.js.map +0 -1
- package/dist/src/server.d.ts +0 -73
- package/dist/src/server.d.ts.map +0 -1
- package/dist/src/server.js +0 -431
- package/dist/src/server.js.map +0 -1
- package/dist/src/services/auth.service.d.ts +0 -68
- package/dist/src/services/auth.service.d.ts.map +0 -1
- package/dist/src/services/auth.service.js +0 -199
- package/dist/src/services/auth.service.js.map +0 -1
- package/dist/src/services/document-permission.service.d.ts +0 -201
- package/dist/src/services/document-permission.service.d.ts.map +0 -1
- package/dist/src/services/document-permission.service.js +0 -636
- package/dist/src/services/document-permission.service.js.map +0 -1
- package/dist/src/sync/types.d.ts +0 -10
- package/dist/src/sync/types.d.ts.map +0 -1
- package/dist/src/sync/types.js +0 -2
- package/dist/src/sync/types.js.map +0 -1
- package/dist/src/sync/utils.d.ts +0 -7
- package/dist/src/sync/utils.d.ts.map +0 -1
- package/dist/src/sync/utils.js +0 -78
- package/dist/src/sync/utils.js.map +0 -1
- package/dist/src/tracing.d.ts +0 -4
- package/dist/src/tracing.d.ts.map +0 -1
- package/dist/src/tracing.js +0 -122
- package/dist/src/tracing.js.map +0 -1
- package/dist/src/types.d.ts +0 -18
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -2
- package/dist/src/types.js.map +0 -1
- package/dist/src/utils/auth.d.ts +0 -3
- package/dist/src/utils/auth.d.ts.map +0 -1
- package/dist/src/utils/auth.js +0 -19
- package/dist/src/utils/auth.js.map +0 -1
- package/dist/src/utils/create-schema.d.ts +0 -11
- package/dist/src/utils/create-schema.d.ts.map +0 -1
- package/dist/src/utils/create-schema.js +0 -322
- package/dist/src/utils/create-schema.js.map +0 -1
- package/dist/src/utils/db.d.ts +0 -74
- package/dist/src/utils/db.d.ts.map +0 -1
- package/dist/src/utils/db.js +0 -101
- package/dist/src/utils/db.js.map +0 -1
- package/dist/src/utils/drive-url.d.ts +0 -2
- package/dist/src/utils/drive-url.d.ts.map +0 -1
- package/dist/src/utils/drive-url.js +0 -3
- package/dist/src/utils/drive-url.js.map +0 -1
- package/dist/src/utils/index.d.ts +0 -4
- package/dist/src/utils/index.d.ts.map +0 -1
- package/dist/src/utils/index.js +0 -4
- package/dist/src/utils/index.js.map +0 -1
- package/dist/test/benchmarks/load.bench.d.ts +0 -2
- package/dist/test/benchmarks/load.bench.d.ts.map +0 -1
- package/dist/test/benchmarks/load.bench.js +0 -73
- package/dist/test/benchmarks/load.bench.js.map +0 -1
- package/dist/test/benchmarks/sync.bench.d.ts +0 -2
- package/dist/test/benchmarks/sync.bench.d.ts.map +0 -1
- package/dist/test/benchmarks/sync.bench.js +0 -119
- package/dist/test/benchmarks/sync.bench.js.map +0 -1
- package/dist/test/document-permission.service.test.d.ts +0 -2
- package/dist/test/document-permission.service.test.d.ts.map +0 -1
- package/dist/test/document-permission.service.test.js +0 -480
- package/dist/test/document-permission.service.test.js.map +0 -1
- package/dist/test/drive-handlers.d.ts +0 -4
- package/dist/test/drive-handlers.d.ts.map +0 -1
- package/dist/test/drive-handlers.js +0 -39
- package/dist/test/drive-handlers.js.map +0 -1
- package/dist/test/drive-subgraph-permissions.test.d.ts +0 -2
- package/dist/test/drive-subgraph-permissions.test.d.ts.map +0 -1
- package/dist/test/drive-subgraph-permissions.test.js +0 -195
- package/dist/test/drive-subgraph-permissions.test.js.map +0 -1
- package/dist/test/drive.test.d.ts +0 -2
- package/dist/test/drive.test.d.ts.map +0 -1
- package/dist/test/drive.test.js +0 -142
- package/dist/test/drive.test.js.map +0 -1
- package/dist/test/identity-integration.test.d.ts +0 -2
- package/dist/test/identity-integration.test.d.ts.map +0 -1
- package/dist/test/identity-integration.test.js +0 -349
- package/dist/test/identity-integration.test.js.map +0 -1
- package/dist/test/index.d.ts +0 -3
- package/dist/test/index.d.ts.map +0 -1
- package/dist/test/index.js +0 -3
- package/dist/test/index.js.map +0 -1
- package/dist/test/permissions-integration.test.d.ts +0 -2
- package/dist/test/permissions-integration.test.d.ts.map +0 -1
- package/dist/test/permissions-integration.test.js +0 -421
- package/dist/test/permissions-integration.test.js.map +0 -1
- package/dist/test/pull-responder-transmitter.test.d.ts +0 -2
- package/dist/test/pull-responder-transmitter.test.d.ts.map +0 -1
- package/dist/test/pull-responder-transmitter.test.js +0 -220
- package/dist/test/pull-responder-transmitter.test.js.map +0 -1
- package/dist/test/push-transmitter.test.d.ts +0 -2
- package/dist/test/push-transmitter.test.d.ts.map +0 -1
- package/dist/test/push-transmitter.test.js +0 -179
- package/dist/test/push-transmitter.test.js.map +0 -1
- package/dist/test/reactor-adapters.test.d.ts +0 -2
- package/dist/test/reactor-adapters.test.d.ts.map +0 -1
- package/dist/test/reactor-adapters.test.js +0 -379
- package/dist/test/reactor-adapters.test.js.map +0 -1
- package/dist/test/reactor-client.test.d.ts +0 -2
- package/dist/test/reactor-client.test.d.ts.map +0 -1
- package/dist/test/reactor-client.test.js +0 -212
- package/dist/test/reactor-client.test.js.map +0 -1
- package/dist/test/reactor-resolvers.test.d.ts +0 -2
- package/dist/test/reactor-resolvers.test.d.ts.map +0 -1
- package/dist/test/reactor-resolvers.test.js +0 -261
- package/dist/test/reactor-resolvers.test.js.map +0 -1
- package/dist/test/reactor-subgraph-permissions.test.d.ts +0 -2
- package/dist/test/reactor-subgraph-permissions.test.d.ts.map +0 -1
- package/dist/test/reactor-subgraph-permissions.test.js +0 -400
- package/dist/test/reactor-subgraph-permissions.test.js.map +0 -1
- package/dist/test/router.test.d.ts +0 -2
- package/dist/test/router.test.d.ts.map +0 -1
- package/dist/test/router.test.js +0 -38
- package/dist/test/router.test.js.map +0 -1
- package/dist/test/subscriptions.test.d.ts +0 -2
- package/dist/test/subscriptions.test.d.ts.map +0 -1
- package/dist/test/subscriptions.test.js +0 -246
- package/dist/test/subscriptions.test.js.map +0 -1
- package/dist/test/system.test.d.ts +0 -2
- package/dist/test/system.test.d.ts.map +0 -1
- package/dist/test/system.test.js +0 -211
- package/dist/test/system.test.js.map +0 -1
- package/dist/test/three-reactor-gql-sync.test.d.ts +0 -2
- package/dist/test/three-reactor-gql-sync.test.d.ts.map +0 -1
- package/dist/test/three-reactor-gql-sync.test.js +0 -368
- package/dist/test/three-reactor-gql-sync.test.js.map +0 -1
- package/dist/test/two-reactor-gql-catchup-duplicate.test.d.ts +0 -2
- package/dist/test/two-reactor-gql-catchup-duplicate.test.d.ts.map +0 -1
- package/dist/test/two-reactor-gql-catchup-duplicate.test.js +0 -264
- package/dist/test/two-reactor-gql-catchup-duplicate.test.js.map +0 -1
- package/dist/test/two-reactor-gql-sync.test.d.ts +0 -2
- package/dist/test/two-reactor-gql-sync.test.d.ts.map +0 -1
- package/dist/test/two-reactor-gql-sync.test.js +0 -348
- package/dist/test/two-reactor-gql-sync.test.js.map +0 -1
- package/dist/test/utils/gql-resolver-bridge.d.ts +0 -12
- package/dist/test/utils/gql-resolver-bridge.d.ts.map +0 -1
- package/dist/test/utils/gql-resolver-bridge.js +0 -60
- package/dist/test/utils/gql-resolver-bridge.js.map +0 -1
- package/dist/test/utils.d.ts +0 -10
- package/dist/test/utils.d.ts.map +0 -1
- package/dist/test/utils.js +0 -23
- package/dist/test/utils.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/vitest.config.d.ts +0 -3
- package/dist/vitest.config.d.ts.map +0 -1
- package/dist/vitest.config.js +0 -38
- package/dist/vitest.config.js.map +0 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/packages/https-hooks.d.mts
|
|
2
|
+
/**
|
|
3
|
+
* Node.js module loader hooks that enable importing from HTTP/HTTPS URLs.
|
|
4
|
+
* See: https://nodejs.org/docs/latest-v24.x/api/module.html#import-from-https
|
|
5
|
+
*/
|
|
6
|
+
type ResolveContext = {
|
|
7
|
+
parentURL?: string;
|
|
8
|
+
conditions?: string[];
|
|
9
|
+
};
|
|
10
|
+
type ResolveResult = {
|
|
11
|
+
url: string;
|
|
12
|
+
shortCircuit?: boolean;
|
|
13
|
+
format?: string;
|
|
14
|
+
};
|
|
15
|
+
type NextResolve = (specifier: string, context: ResolveContext) => Promise<ResolveResult>;
|
|
16
|
+
type LoadContext = {
|
|
17
|
+
format?: string;
|
|
18
|
+
};
|
|
19
|
+
type LoadResult = {
|
|
20
|
+
format: string;
|
|
21
|
+
shortCircuit?: boolean;
|
|
22
|
+
source: string;
|
|
23
|
+
};
|
|
24
|
+
type NextLoad = (url: string, context: LoadContext) => Promise<LoadResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Resolve hook: resolves relative specifiers against HTTP/HTTPS parent URLs.
|
|
27
|
+
*/
|
|
28
|
+
declare function resolve(specifier: string, context: ResolveContext, nextResolve: NextResolve): Promise<ResolveResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Load hook: fetches module source from HTTP/HTTPS URLs.
|
|
31
|
+
*/
|
|
32
|
+
declare function load(url: string, context: LoadContext, nextLoad: NextLoad): Promise<LoadResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Path to this hooks file for use with node:module register()
|
|
35
|
+
*/
|
|
36
|
+
declare const httpsHooksPath: string;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { httpsHooksPath, load, resolve };
|
|
39
|
+
//# sourceMappingURL=https-hooks.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"https-hooks.d.mts","names":[],"sources":["../../../src/packages/https-hooks.mts"],"mappings":";;;;;KAQK,cAAA;EAAmB,SAAA;EAAoB,UAAA;AAAA;AAAA,KACvC,aAAA;EACH,GAAA;EACA,YAAA;EACA,MAAA;AAAA;AAAA,KAEG,WAAA,IACH,SAAA,UACA,OAAA,EAAS,cAAA,KACN,OAAA,CAAQ,aAAA;AAAA,KAER,WAAA;EAAgB,MAAA;AAAA;AAAA,KAChB,UAAA;EAAe,MAAA;EAAgB,YAAA;EAAwB,MAAA;AAAA;AAAA,KACvD,QAAA,IAAY,GAAA,UAAa,OAAA,EAAS,WAAA,KAAgB,OAAA,CAAQ,UAAA;;;;iBAKzC,OAAA,CACpB,SAAA,UACA,OAAA,EAAS,cAAA,EACT,WAAA,EAAa,WAAA,GACZ,OAAA,CAAQ,aAAA;;;;iBAsCW,IAAA,CACpB,GAAA,UACA,OAAA,EAAS,WAAA,EACT,QAAA,EAAU,QAAA,GACT,OAAA,CAAQ,UAAA;;;;cA0EE,cAAA"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { get } from "node:http";
|
|
2
|
+
import { get as get$1 } from "node:https";
|
|
3
|
+
//#region src/packages/https-hooks.mts
|
|
4
|
+
/**
|
|
5
|
+
* Resolve hook: resolves relative specifiers against HTTP/HTTPS parent URLs.
|
|
6
|
+
*/
|
|
7
|
+
async function resolve(specifier, context, nextResolve) {
|
|
8
|
+
const { parentURL } = context;
|
|
9
|
+
if (specifier.startsWith("https://") || specifier.startsWith("http://")) return {
|
|
10
|
+
url: specifier,
|
|
11
|
+
shortCircuit: true,
|
|
12
|
+
format: "module"
|
|
13
|
+
};
|
|
14
|
+
if (parentURL && (parentURL.startsWith("https://") || parentURL.startsWith("http://")) && (specifier.startsWith("./") || specifier.startsWith("../"))) return {
|
|
15
|
+
url: new URL(specifier, parentURL).href,
|
|
16
|
+
shortCircuit: true,
|
|
17
|
+
format: "module"
|
|
18
|
+
};
|
|
19
|
+
if (parentURL && (parentURL.startsWith("https://") || parentURL.startsWith("http://"))) {
|
|
20
|
+
const { pathToFileURL } = await import("node:url");
|
|
21
|
+
const localParent = pathToFileURL(process.cwd() + "/").href;
|
|
22
|
+
return nextResolve(specifier, {
|
|
23
|
+
...context,
|
|
24
|
+
parentURL: localParent
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return nextResolve(specifier, context);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Load hook: fetches module source from HTTP/HTTPS URLs.
|
|
31
|
+
*/
|
|
32
|
+
async function load(url, context, nextLoad) {
|
|
33
|
+
if (url.startsWith("https://")) return {
|
|
34
|
+
format: "module",
|
|
35
|
+
shortCircuit: true,
|
|
36
|
+
source: patchCreateRequire(await fetchModule(url, get$1))
|
|
37
|
+
};
|
|
38
|
+
if (url.startsWith("http://")) return {
|
|
39
|
+
format: "module",
|
|
40
|
+
shortCircuit: true,
|
|
41
|
+
source: patchCreateRequire(await fetchModule(url, get))
|
|
42
|
+
};
|
|
43
|
+
return nextLoad(url, context);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Rewrite `createRequire(import.meta.url)` in HTTP-loaded modules so that
|
|
47
|
+
* `createRequire` receives a local file URL instead of an HTTP URL it cannot handle.
|
|
48
|
+
*/
|
|
49
|
+
function patchCreateRequire(source) {
|
|
50
|
+
return source.replace(/createRequire\(import\.meta\.url\)/g, `createRequire(new URL("file://" + process.cwd() + "/"))`);
|
|
51
|
+
}
|
|
52
|
+
function fetchModule(url, getter) {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
getter(url, (res) => {
|
|
55
|
+
if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
56
|
+
const redirectUrl = res.headers.location;
|
|
57
|
+
fetchModule(redirectUrl, redirectUrl.startsWith("https://") ? get$1 : get).then(resolve).catch(reject);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (res.statusCode && res.statusCode >= 400) {
|
|
61
|
+
reject(/* @__PURE__ */ new Error(`Failed to fetch ${url}: ${res.statusCode}`));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
let data = "";
|
|
65
|
+
res.setEncoding("utf8");
|
|
66
|
+
res.on("data", (chunk) => data += chunk);
|
|
67
|
+
res.on("end", () => resolve(data));
|
|
68
|
+
res.on("error", reject);
|
|
69
|
+
}).on("error", reject);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Path to this hooks file for use with node:module register()
|
|
74
|
+
*/
|
|
75
|
+
const httpsHooksPath = import.meta.url;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { httpsHooksPath, load, resolve };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=https-hooks.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"https-hooks.mjs","names":["get","httpGet"],"sources":["../../../src/packages/https-hooks.mts"],"sourcesContent":["import { get as httpGet } from \"node:http\";\nimport { get } from \"node:https\";\n\n/**\n * Node.js module loader hooks that enable importing from HTTP/HTTPS URLs.\n * See: https://nodejs.org/docs/latest-v24.x/api/module.html#import-from-https\n */\n\ntype ResolveContext = { parentURL?: string; conditions?: string[] };\ntype ResolveResult = {\n url: string;\n shortCircuit?: boolean;\n format?: string;\n};\ntype NextResolve = (\n specifier: string,\n context: ResolveContext,\n) => Promise<ResolveResult>;\n\ntype LoadContext = { format?: string };\ntype LoadResult = { format: string; shortCircuit?: boolean; source: string };\ntype NextLoad = (url: string, context: LoadContext) => Promise<LoadResult>;\n\n/**\n * Resolve hook: resolves relative specifiers against HTTP/HTTPS parent URLs.\n */\nexport async function resolve(\n specifier: string,\n context: ResolveContext,\n nextResolve: NextResolve,\n): Promise<ResolveResult> {\n const { parentURL } = context;\n\n // If the specifier is already an HTTP(S) URL, resolve it directly\n if (specifier.startsWith(\"https://\") || specifier.startsWith(\"http://\")) {\n return { url: specifier, shortCircuit: true, format: \"module\" };\n }\n\n // If the parent is an HTTP(S) URL and specifier is relative, resolve against it.\n // Only handle relative specifiers (./ or ../), not bare package specifiers.\n if (\n parentURL &&\n (parentURL.startsWith(\"https://\") || parentURL.startsWith(\"http://\")) &&\n (specifier.startsWith(\"./\") || specifier.startsWith(\"../\"))\n ) {\n const resolved = new URL(specifier, parentURL).href;\n return { url: resolved, shortCircuit: true, format: \"module\" };\n }\n\n // For bare specifiers (e.g. \"document-model\") imported from HTTP modules,\n // Node's default resolver fails because it can't find node_modules from an HTTP parent.\n // Fall back to resolving from the process's working directory instead.\n if (\n parentURL &&\n (parentURL.startsWith(\"https://\") || parentURL.startsWith(\"http://\"))\n ) {\n const { pathToFileURL } = await import(\"node:url\");\n const localParent = pathToFileURL(process.cwd() + \"/\").href;\n return nextResolve(specifier, { ...context, parentURL: localParent });\n }\n\n // Let Node.js handle all other specifiers\n return nextResolve(specifier, context);\n}\n\n/**\n * Load hook: fetches module source from HTTP/HTTPS URLs.\n */\nexport async function load(\n url: string,\n context: LoadContext,\n nextLoad: NextLoad,\n): Promise<LoadResult> {\n // Handle HTTPS URLs\n if (url.startsWith(\"https://\")) {\n const source = await fetchModule(url, get);\n return {\n format: \"module\",\n shortCircuit: true,\n source: patchCreateRequire(source),\n };\n }\n\n // Handle HTTP URLs (for local development)\n if (url.startsWith(\"http://\")) {\n const source = await fetchModule(url, httpGet);\n return {\n format: \"module\",\n shortCircuit: true,\n source: patchCreateRequire(source),\n };\n }\n\n // Let Node.js handle all other URLs\n return nextLoad(url, context);\n}\n\n/**\n * Rewrite `createRequire(import.meta.url)` in HTTP-loaded modules so that\n * `createRequire` receives a local file URL instead of an HTTP URL it cannot handle.\n */\nfunction patchCreateRequire(source: string): string {\n return source.replace(\n /createRequire\\(import\\.meta\\.url\\)/g,\n `createRequire(new URL(\"file://\" + process.cwd() + \"/\"))`,\n );\n}\n\nfunction fetchModule(\n url: string,\n getter: typeof get | typeof httpGet,\n): Promise<string> {\n return new Promise((resolve, reject) => {\n getter(url, (res) => {\n // Handle redirects\n if (\n res.statusCode &&\n res.statusCode >= 300 &&\n res.statusCode < 400 &&\n res.headers.location\n ) {\n const redirectUrl = res.headers.location;\n const redirectGetter = redirectUrl.startsWith(\"https://\")\n ? get\n : httpGet;\n fetchModule(redirectUrl, redirectGetter).then(resolve).catch(reject);\n return;\n }\n\n if (res.statusCode && res.statusCode >= 400) {\n reject(new Error(`Failed to fetch ${url}: ${res.statusCode}`));\n return;\n }\n\n let data = \"\";\n res.setEncoding(\"utf8\");\n res.on(\"data\", (chunk) => (data += chunk));\n res.on(\"end\", () => resolve(data));\n res.on(\"error\", reject);\n }).on(\"error\", reject);\n });\n}\n\n/**\n * Path to this hooks file for use with node:module register()\n */\nexport const httpsHooksPath: string = import.meta.url;\n"],"mappings":";;;;;;AA0BA,eAAsB,QACpB,WACA,SACA,aACwB;CACxB,MAAM,EAAE,cAAc;AAGtB,KAAI,UAAU,WAAW,WAAW,IAAI,UAAU,WAAW,UAAU,CACrE,QAAO;EAAE,KAAK;EAAW,cAAc;EAAM,QAAQ;EAAU;AAKjE,KACE,cACC,UAAU,WAAW,WAAW,IAAI,UAAU,WAAW,UAAU,MACnE,UAAU,WAAW,KAAK,IAAI,UAAU,WAAW,MAAM,EAG1D,QAAO;EAAE,KADQ,IAAI,IAAI,WAAW,UAAU,CAAC;EACvB,cAAc;EAAM,QAAQ;EAAU;AAMhE,KACE,cACC,UAAU,WAAW,WAAW,IAAI,UAAU,WAAW,UAAU,GACpE;EACA,MAAM,EAAE,kBAAkB,MAAM,OAAO;EACvC,MAAM,cAAc,cAAc,QAAQ,KAAK,GAAG,IAAI,CAAC;AACvD,SAAO,YAAY,WAAW;GAAE,GAAG;GAAS,WAAW;GAAa,CAAC;;AAIvE,QAAO,YAAY,WAAW,QAAQ;;;;;AAMxC,eAAsB,KACpB,KACA,SACA,UACqB;AAErB,KAAI,IAAI,WAAW,WAAW,CAE5B,QAAO;EACL,QAAQ;EACR,cAAc;EACd,QAAQ,mBAJK,MAAM,YAAY,KAAKA,MAAI,CAIN;EACnC;AAIH,KAAI,IAAI,WAAW,UAAU,CAE3B,QAAO;EACL,QAAQ;EACR,cAAc;EACd,QAAQ,mBAJK,MAAM,YAAY,KAAKC,IAAQ,CAIV;EACnC;AAIH,QAAO,SAAS,KAAK,QAAQ;;;;;;AAO/B,SAAS,mBAAmB,QAAwB;AAClD,QAAO,OAAO,QACZ,uCACA,0DACD;;AAGH,SAAS,YACP,KACA,QACiB;AACjB,QAAO,IAAI,SAAS,SAAS,WAAW;AACtC,SAAO,MAAM,QAAQ;AAEnB,OACE,IAAI,cACJ,IAAI,cAAc,OAClB,IAAI,aAAa,OACjB,IAAI,QAAQ,UACZ;IACA,MAAM,cAAc,IAAI,QAAQ;AAIhC,gBAAY,aAHW,YAAY,WAAW,WAAW,GACrDD,QACAC,IACoC,CAAC,KAAK,QAAQ,CAAC,MAAM,OAAO;AACpE;;AAGF,OAAI,IAAI,cAAc,IAAI,cAAc,KAAK;AAC3C,2BAAO,IAAI,MAAM,mBAAmB,IAAI,IAAI,IAAI,aAAa,CAAC;AAC9D;;GAGF,IAAI,OAAO;AACX,OAAI,YAAY,OAAO;AACvB,OAAI,GAAG,SAAS,UAAW,QAAQ,MAAO;AAC1C,OAAI,GAAG,aAAa,QAAQ,KAAK,CAAC;AAClC,OAAI,GAAG,SAAS,OAAO;IACvB,CAAC,GAAG,SAAS,OAAO;GACtB;;;;;AAMJ,MAAa,iBAAyB,OAAO,KAAK"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { a as ISubscribablePackageLoader, o as ISubscriptionOptions } from "../../types-Do4QTfT3.mjs";
|
|
2
|
+
import { ILogger } from "document-model";
|
|
3
|
+
import { DocumentModelModule } from "@powerhousedao/shared/document-model";
|
|
4
|
+
import { Logger, ViteDevServer } from "vite";
|
|
5
|
+
import { ProcessorFactoryBuilder, SubgraphClass } from "@powerhousedao/reactor-api";
|
|
6
|
+
|
|
7
|
+
//#region src/packages/vite-loader.d.mts
|
|
8
|
+
declare function createViteLogger(logger: ILogger, prefix?: string): Logger;
|
|
9
|
+
declare class VitePackageLoader implements ISubscribablePackageLoader {
|
|
10
|
+
#private;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
private readonly vite;
|
|
13
|
+
readonly name = "VitePackageLoader";
|
|
14
|
+
static build(vite: ViteDevServer): VitePackageLoader;
|
|
15
|
+
constructor(vite: ViteDevServer);
|
|
16
|
+
private getDocumentModelsPath;
|
|
17
|
+
private getSubgraphsPath;
|
|
18
|
+
private getProcessorsPath;
|
|
19
|
+
loadDocumentModels(identifier: string, immediate?: boolean): Promise<DocumentModelModule[]>;
|
|
20
|
+
loadSubgraphs(identifier: string): Promise<SubgraphClass[]>;
|
|
21
|
+
loadProcessors(identifier: string): Promise<ProcessorFactoryBuilder | null>;
|
|
22
|
+
onDocumentModelsChange(identifier: string, handler: (documentModels: DocumentModelModule[]) => void, options?: ISubscriptionOptions): () => void;
|
|
23
|
+
onSubgraphsChange(identifier: string, handler: (subgraphs: SubgraphClass[]) => void, options?: ISubscriptionOptions): () => void;
|
|
24
|
+
onProcessorsChange(identifier: string, handler: (processors: ProcessorFactoryBuilder | null) => void, options?: ISubscriptionOptions): () => void;
|
|
25
|
+
}
|
|
26
|
+
declare function startViteServer(root: string, logger?: Logger): Promise<ViteDevServer>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { VitePackageLoader, createViteLogger, startViteServer };
|
|
29
|
+
//# sourceMappingURL=vite-loader.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-loader.d.mts","names":[],"sources":["../../../src/packages/vite-loader.mts"],"mappings":";;;;;;;iBAkBgB,gBAAA,CAAiB,MAAA,EAAQ,OAAA,EAAS,MAAA,YAAW,MAAA;AAAA,cAUhD,iBAAA,YAA6B,0BAAA;EAAA;mBACvB,MAAA;EAAA,iBAEA,IAAA;EAAA,SAER,IAAA;EAAA,OAEF,KAAA,CAAM,IAAA,EAAM,aAAA,GAAa,iBAAA;cAIpB,IAAA,EAAM,aAAA;EAAA,QAIV,qBAAA;EAAA,QAIA,gBAAA;EAAA,QAIA,iBAAA;EAID,kBAAA,CAAmB,UAAA,UAAoB,SAAA,aAAiB,OAAA,CAAA,mBAAA;EA2CzD,aAAA,CAAc,UAAA,WAAqB,OAAA,CAAQ,aAAA;EA4B3C,cAAA,CACJ,UAAA,WACC,OAAA,CAAQ,uBAAA;EA+BX,sBAAA,CACE,UAAA,UACA,OAAA,GAAU,cAAA,EAAgB,mBAAA,aAC1B,OAAA,GAAU,oBAAA;EAiBZ,iBAAA,CACE,UAAA,UACA,OAAA,GAAU,SAAA,EAAW,aAAA,aACrB,OAAA,GAAU,oBAAA;EAgBZ,kBAAA,CACE,UAAA,UACA,OAAA,GAAU,UAAA,EAAY,uBAAA,kBACtB,OAAA,GAAU,oBAAA;AAAA;AAAA,iBAiBQ,eAAA,CAAgB,IAAA,UAAc,MAAA,GAAS,MAAA,GAAM,OAAA,CAAA,aAAA"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { a as isSubgraphClass, o as debounce, s as isSubpath } from "../../utils-CVrD_vPF.mjs";
|
|
2
|
+
import { childLogger } from "document-model";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
|
|
5
|
+
import { readPackage } from "read-pkg";
|
|
6
|
+
import { createLogger, createServer } from "vite";
|
|
7
|
+
//#region src/packages/vite-loader.mts
|
|
8
|
+
function createViteLogger(logger, prefix = "") {
|
|
9
|
+
const customLogger = createLogger("info", { prefix });
|
|
10
|
+
customLogger.info = logger.info;
|
|
11
|
+
customLogger.warn = logger.warn;
|
|
12
|
+
customLogger.error = logger.error;
|
|
13
|
+
return customLogger;
|
|
14
|
+
}
|
|
15
|
+
var VitePackageLoader = class VitePackageLoader {
|
|
16
|
+
logger = childLogger(["reactor-api", "vite-loader"]);
|
|
17
|
+
vite;
|
|
18
|
+
name = "VitePackageLoader";
|
|
19
|
+
static build(vite) {
|
|
20
|
+
return new VitePackageLoader(vite);
|
|
21
|
+
}
|
|
22
|
+
constructor(vite) {
|
|
23
|
+
this.vite = vite;
|
|
24
|
+
}
|
|
25
|
+
getDocumentModelsPath(identifier) {
|
|
26
|
+
return path.join(identifier, "./document-models");
|
|
27
|
+
}
|
|
28
|
+
getSubgraphsPath(identifier) {
|
|
29
|
+
return path.join(identifier, "./subgraphs");
|
|
30
|
+
}
|
|
31
|
+
getProcessorsPath(identifier) {
|
|
32
|
+
return path.join(identifier, "./processors");
|
|
33
|
+
}
|
|
34
|
+
loadDocumentModels(identifier, immediate = false) {
|
|
35
|
+
return this.#loadDocumentModelsWithDebounce(immediate, identifier);
|
|
36
|
+
}
|
|
37
|
+
#loadDocumentModelsWithDebounce = debounce(this.#loadDocumentModels.bind(this), 500);
|
|
38
|
+
async #loadDocumentModels(identifier) {
|
|
39
|
+
const fullPath = this.getDocumentModelsPath(identifier);
|
|
40
|
+
this.logger.debug("Loading document models from", fullPath);
|
|
41
|
+
try {
|
|
42
|
+
const localDMs = await this.vite.ssrLoadModule(fullPath);
|
|
43
|
+
const exports = Object.values(localDMs);
|
|
44
|
+
const documentModels = [];
|
|
45
|
+
for (const dm of exports) if (dm.documentModel) documentModels.push(dm);
|
|
46
|
+
this.logger.verbose(` ➜ Loaded ${documentModels.length} Document Models from: ${identifier}`);
|
|
47
|
+
return documentModels;
|
|
48
|
+
} catch (e) {
|
|
49
|
+
this.logger.debug(` ➜ No Document Models found for: ${identifier}`, e);
|
|
50
|
+
}
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
async loadSubgraphs(identifier) {
|
|
54
|
+
const fullPath = this.getSubgraphsPath(identifier);
|
|
55
|
+
this.logger.verbose("Loading subgraphs from", fullPath);
|
|
56
|
+
let localSubgraphs = {};
|
|
57
|
+
try {
|
|
58
|
+
localSubgraphs = await this.vite.ssrLoadModule(fullPath);
|
|
59
|
+
} catch (e) {
|
|
60
|
+
this.logger.debug(` ➜ No Subgraphs found for: ${identifier}`, e);
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
const subgraphs = [];
|
|
64
|
+
for (const [name, subgraph] of Object.entries(localSubgraphs)) {
|
|
65
|
+
const SubgraphClass = subgraph[name];
|
|
66
|
+
if (isSubgraphClass(SubgraphClass)) subgraphs.push(SubgraphClass);
|
|
67
|
+
}
|
|
68
|
+
this.logger.debug(` ➜ Loaded ${subgraphs.length} Subgraphs from: ${identifier}`);
|
|
69
|
+
return subgraphs;
|
|
70
|
+
}
|
|
71
|
+
async loadProcessors(identifier) {
|
|
72
|
+
const fullPath = this.getProcessorsPath(identifier);
|
|
73
|
+
this.logger.verbose("Loading processors from", fullPath);
|
|
74
|
+
try {
|
|
75
|
+
const factory = (await this.vite.ssrLoadModule(fullPath))?.processorFactory;
|
|
76
|
+
if (factory && typeof factory === "function") {
|
|
77
|
+
this.logger.verbose(` ➜ Loaded Processor Factory from: ${identifier}`);
|
|
78
|
+
return factory;
|
|
79
|
+
}
|
|
80
|
+
} catch (e) {
|
|
81
|
+
this.logger.debug(` ➜ No Processor Factory found for: ${identifier}`, e);
|
|
82
|
+
}
|
|
83
|
+
this.logger.verbose(` ➜ No Processor Factory found for: ${identifier}`);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
onDocumentModelsChange(identifier, handler, options) {
|
|
87
|
+
const listener = async (changedPath) => {
|
|
88
|
+
if (isSubpath(this.getDocumentModelsPath(identifier), changedPath)) handler(await this.loadDocumentModels(identifier));
|
|
89
|
+
};
|
|
90
|
+
this.vite.watcher.on("change", listener);
|
|
91
|
+
return () => {
|
|
92
|
+
this.vite.watcher.off("change", listener);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
onSubgraphsChange(identifier, handler, options) {
|
|
96
|
+
const subgraphsPath = this.getSubgraphsPath(identifier);
|
|
97
|
+
const listener = debounce(async (changedPath) => {
|
|
98
|
+
if (isSubpath(subgraphsPath, changedPath)) handler(await this.loadSubgraphs(identifier));
|
|
99
|
+
}, options?.debounce ?? 100);
|
|
100
|
+
this.vite.watcher.on("change", listener);
|
|
101
|
+
return () => {
|
|
102
|
+
this.vite.watcher.off("change", listener);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
onProcessorsChange(identifier, handler, options) {
|
|
106
|
+
const processorsPath = this.getProcessorsPath(identifier);
|
|
107
|
+
const listener = async (changedPath) => {
|
|
108
|
+
if (isSubpath(processorsPath, changedPath)) handler(await this.loadProcessors(identifier));
|
|
109
|
+
};
|
|
110
|
+
this.vite.watcher.on("change", listener);
|
|
111
|
+
return () => {
|
|
112
|
+
this.vite.watcher.off("change", listener);
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
async function startViteServer(root, logger) {
|
|
117
|
+
return await createServer({
|
|
118
|
+
root,
|
|
119
|
+
configFile: false,
|
|
120
|
+
logger,
|
|
121
|
+
server: {
|
|
122
|
+
middlewareMode: true,
|
|
123
|
+
watch: { ignored: ["**/.ph/**"] }
|
|
124
|
+
},
|
|
125
|
+
appType: "custom",
|
|
126
|
+
build: { rollupOptions: { input: [] } },
|
|
127
|
+
resolve: {
|
|
128
|
+
tsconfigPaths: true,
|
|
129
|
+
alias: { [(await readPackage({ cwd: root })).name]: root }
|
|
130
|
+
},
|
|
131
|
+
plugins: [viteCommonjs(), {
|
|
132
|
+
name: "suppress-hmr",
|
|
133
|
+
handleHotUpdate() {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
}]
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
export { VitePackageLoader, createViteLogger, startViteServer };
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=vite-loader.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-loader.mjs","names":["#loadDocumentModelsWithDebounce","#loadDocumentModels"],"sources":["../../../src/packages/vite-loader.mts"],"sourcesContent":["import { viteCommonjs } from \"@originjs/vite-plugin-commonjs\";\nimport type {\n ProcessorFactoryBuilder,\n SubgraphClass,\n} from \"@powerhousedao/reactor-api\";\nimport type { DocumentModelModule } from \"@powerhousedao/shared/document-model\";\nimport { childLogger, type ILogger } from \"document-model\";\nimport path from \"node:path\";\nimport { readPackage } from \"read-pkg\";\nimport type { Logger, ViteDevServer } from \"vite\";\nimport { createLogger, createServer } from \"vite\";\nimport { isSubgraphClass } from \"../graphql/utils.js\";\nimport type {\n ISubscribablePackageLoader,\n ISubscriptionOptions,\n} from \"./types.js\";\nimport { debounce, isSubpath } from \"./util.js\";\n\nexport function createViteLogger(logger: ILogger, prefix = \"\") {\n const customLogger = createLogger(\"info\", {\n prefix,\n });\n customLogger.info = logger.info;\n customLogger.warn = logger.warn;\n customLogger.error = logger.error;\n return customLogger;\n}\n\nexport class VitePackageLoader implements ISubscribablePackageLoader {\n private readonly logger = childLogger([\"reactor-api\", \"vite-loader\"]);\n\n private readonly vite: ViteDevServer;\n\n readonly name = \"VitePackageLoader\";\n\n static build(vite: ViteDevServer) {\n return new VitePackageLoader(vite);\n }\n\n constructor(vite: ViteDevServer) {\n this.vite = vite;\n }\n\n private getDocumentModelsPath(identifier: string): string {\n return path.join(identifier, \"./document-models\");\n }\n\n private getSubgraphsPath(identifier: string): string {\n return path.join(identifier, \"./subgraphs\");\n }\n\n private getProcessorsPath(identifier: string): string {\n return path.join(identifier, \"./processors\");\n }\n\n public loadDocumentModels(identifier: string, immediate = false) {\n return this.#loadDocumentModelsWithDebounce(immediate, identifier);\n }\n\n #loadDocumentModelsWithDebounce = debounce(\n this.#loadDocumentModels.bind(this),\n 500,\n );\n\n async #loadDocumentModels(\n identifier: string,\n ): Promise<DocumentModelModule[]> {\n const fullPath = this.getDocumentModelsPath(identifier);\n this.logger.debug(\"Loading document models from\", fullPath);\n\n try {\n const localDMs = (await this.vite.ssrLoadModule(fullPath)) as Record<\n string,\n DocumentModelModule\n >;\n\n const exports = Object.values(localDMs);\n\n // duck type\n const documentModels: DocumentModelModule[] = [];\n for (const dm of exports) {\n if (dm.documentModel) {\n documentModels.push(dm);\n }\n }\n\n this.logger.verbose(\n ` ➜ Loaded ${documentModels.length} Document Models from: ${identifier}`,\n );\n\n return documentModels;\n } catch (e) {\n this.logger.debug(` ➜ No Document Models found for: ${identifier}`, e);\n }\n\n return [];\n }\n\n async loadSubgraphs(identifier: string): Promise<SubgraphClass[]> {\n const fullPath = this.getSubgraphsPath(identifier);\n\n this.logger.verbose(\"Loading subgraphs from\", fullPath);\n\n let localSubgraphs: Record<string, Record<string, SubgraphClass>> = {};\n try {\n localSubgraphs = await this.vite.ssrLoadModule(fullPath);\n } catch (e) {\n this.logger.debug(` ➜ No Subgraphs found for: ${identifier}`, e);\n return [];\n }\n\n const subgraphs: SubgraphClass[] = [];\n for (const [name, subgraph] of Object.entries(localSubgraphs)) {\n const SubgraphClass = subgraph[name];\n if (isSubgraphClass(SubgraphClass)) {\n subgraphs.push(SubgraphClass);\n }\n }\n\n this.logger.debug(\n ` ➜ Loaded ${subgraphs.length} Subgraphs from: ${identifier}`,\n );\n\n return subgraphs;\n }\n\n async loadProcessors(\n identifier: string,\n ): Promise<ProcessorFactoryBuilder | null> {\n const fullPath = this.getProcessorsPath(identifier);\n\n this.logger.verbose(\"Loading processors from\", fullPath);\n\n try {\n const pkgModule = await this.vite.ssrLoadModule(fullPath);\n\n const factory = (\n pkgModule as Record<string, ProcessorFactoryBuilder | undefined>\n )?.processorFactory;\n\n if (factory && typeof factory === \"function\") {\n this.logger.verbose(\n ` ➜ Loaded Processor Factory from: ${identifier}`,\n );\n return factory;\n }\n } catch (e) {\n this.logger.debug(\n ` ➜ No Processor Factory found for: ${identifier}`,\n e,\n );\n }\n\n this.logger.verbose(` ➜ No Processor Factory found for: ${identifier}`);\n\n // return empty processor factory\n return null;\n }\n\n onDocumentModelsChange(\n identifier: string,\n handler: (documentModels: DocumentModelModule[]) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n const listener = async (changedPath: string) => {\n const documentModelsPath = this.getDocumentModelsPath(identifier);\n if (isSubpath(documentModelsPath, changedPath)) {\n const documentModels = await this.loadDocumentModels(identifier);\n handler(documentModels);\n }\n };\n\n this.vite.watcher.on(\"change\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n };\n }\n\n onSubgraphsChange(\n identifier: string,\n handler: (subgraphs: SubgraphClass[]) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n const subgraphsPath = this.getSubgraphsPath(identifier);\n const listener = debounce(async (changedPath: string) => {\n if (isSubpath(subgraphsPath, changedPath)) {\n const subgraphs = await this.loadSubgraphs(identifier);\n handler(subgraphs);\n }\n }, options?.debounce ?? 100);\n this.vite.watcher.on(\"change\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n };\n }\n\n onProcessorsChange(\n identifier: string,\n handler: (processors: ProcessorFactoryBuilder | null) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n const processorsPath = this.getProcessorsPath(identifier);\n const listener = async (changedPath: string) => {\n if (isSubpath(processorsPath, changedPath)) {\n const processors = await this.loadProcessors(identifier);\n handler(processors);\n }\n };\n this.vite.watcher.on(\"change\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n };\n }\n}\n\nexport async function startViteServer(root: string, logger?: Logger) {\n const packageJson = await readPackage({ cwd: root });\n\n const vite = await createServer({\n root,\n configFile: false,\n logger,\n server: { middlewareMode: true, watch: { ignored: [\"**/.ph/**\"] } },\n appType: \"custom\",\n build: {\n rollupOptions: {\n input: [],\n },\n },\n resolve: {\n tsconfigPaths: true,\n alias: {\n [packageJson.name]: root,\n },\n },\n plugins: [\n viteCommonjs(),\n {\n name: \"suppress-hmr\",\n handleHotUpdate() {\n return []; // return empty array to suppress server refresh\n },\n },\n ],\n });\n\n return vite;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ILogger } from "document-model";
|
|
2
|
+
import { DocumentModelModule } from "@powerhousedao/shared/document-model";
|
|
3
|
+
import { ProcessorFactoryBuilder, SubgraphClass } from "@powerhousedao/reactor-api";
|
|
4
|
+
|
|
5
|
+
//#region src/packages/types.d.ts
|
|
6
|
+
interface IPackageLoader {
|
|
7
|
+
name: string;
|
|
8
|
+
loadDocumentModels(identifier: string, immediate?: boolean): Promise<DocumentModelModule[]>;
|
|
9
|
+
loadSubgraphs(identifier: string, immediate?: boolean): Promise<SubgraphClass[]>;
|
|
10
|
+
loadProcessors(identifier: string, immediate?: boolean): Promise<ProcessorFactoryBuilder | null>;
|
|
11
|
+
}
|
|
12
|
+
interface ISubscriptionOptions {
|
|
13
|
+
debounce?: number;
|
|
14
|
+
}
|
|
15
|
+
interface ISubscribablePackageLoader extends IPackageLoader {
|
|
16
|
+
onDocumentModelsChange?(identifier: string, handler: (documentModels: DocumentModelModule[]) => void, options?: ISubscriptionOptions): () => void;
|
|
17
|
+
onSubgraphsChange?(identifier: string, handler: (subgraphs: SubgraphClass[]) => void, options?: ISubscriptionOptions): () => void;
|
|
18
|
+
onProcessorsChange?(identifier: string, handler: (processors: ProcessorFactoryBuilder | null) => void, options?: ISubscriptionOptions): () => void;
|
|
19
|
+
}
|
|
20
|
+
interface IPackageManager {
|
|
21
|
+
onDocumentModelsChange(handler: (documentModels: Record<string, DocumentModelModule[]>) => void): void;
|
|
22
|
+
}
|
|
23
|
+
type IPackageLoaderOptions = {
|
|
24
|
+
logger?: ILogger;
|
|
25
|
+
};
|
|
26
|
+
type IPackageManagerOptions = {
|
|
27
|
+
packages?: string[];
|
|
28
|
+
configFile?: string;
|
|
29
|
+
};
|
|
30
|
+
type PackageManagerResult = {
|
|
31
|
+
documentModels: DocumentModelModule[];
|
|
32
|
+
subgraphs: Map<string, SubgraphClass[]>;
|
|
33
|
+
processors: Map<string, ProcessorFactoryBuilder[]>;
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { ISubscribablePackageLoader as a, IPackageManagerOptions as i, IPackageLoaderOptions as n, ISubscriptionOptions as o, IPackageManager as r, PackageManagerResult as s, IPackageLoader as t };
|
|
37
|
+
//# sourceMappingURL=types-Do4QTfT3.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-Do4QTfT3.d.mts","names":[],"sources":["../src/packages/types.ts"],"mappings":";;;;;UAOiB,cAAA;EACf,IAAA;EACA,kBAAA,CACE,UAAA,UACA,SAAA,aACC,OAAA,CAAQ,mBAAA;EACX,aAAA,CACE,UAAA,UACA,SAAA,aACC,OAAA,CAAQ,aAAA;EACX,cAAA,CACE,UAAA,UACA,SAAA,aACC,OAAA,CAAQ,uBAAA;AAAA;AAAA,UAGI,oBAAA;EACf,QAAA;AAAA;AAAA,UAGe,0BAAA,SAAmC,cAAA;EAClD,sBAAA,EACE,UAAA,UACA,OAAA,GAAU,cAAA,EAAgB,mBAAA,aAC1B,OAAA,GAAU,oBAAA;EAEZ,iBAAA,EACE,UAAA,UACA,OAAA,GAAU,SAAA,EAAW,aAAA,aACrB,OAAA,GAAU,oBAAA;EAEZ,kBAAA,EACE,UAAA,UACA,OAAA,GAAU,UAAA,EAAY,uBAAA,kBACtB,OAAA,GAAU,oBAAA;AAAA;AAAA,UAIG,eAAA;EACf,sBAAA,CACE,OAAA,GAAU,cAAA,EAAgB,MAAA,SAAe,mBAAA;AAAA;AAAA,KAIjC,qBAAA;EACV,MAAA,GAAS,OAAA;AAAA;AAAA,KAGC,sBAAA;EACV,QAAA;EACA,UAAA;AAAA;AAAA,KAWU,oBAAA;EACV,cAAA,EAAgB,mBAAA;EAChB,SAAA,EAAW,GAAA,SAAY,aAAA;EACvB,UAAA,EAAY,GAAA,SAAY,uBAAA;AAAA"}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { gql } from "graphql-tag";
|
|
2
|
+
import { GraphQLError } from "graphql";
|
|
3
|
+
import { childLogger } from "document-model";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import "node:child_process";
|
|
6
|
+
//#region src/graphql/base-subgraph.ts
|
|
7
|
+
var BaseSubgraph = class {
|
|
8
|
+
name = "example";
|
|
9
|
+
path = "";
|
|
10
|
+
resolvers = { Query: { hello: () => this.name } };
|
|
11
|
+
typeDefs = gql`
|
|
12
|
+
type Query {
|
|
13
|
+
hello: String
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
reactorClient;
|
|
17
|
+
graphqlManager;
|
|
18
|
+
relationalDb;
|
|
19
|
+
syncManager;
|
|
20
|
+
documentPermissionService;
|
|
21
|
+
authorizationService;
|
|
22
|
+
constructor(args) {
|
|
23
|
+
this.reactorClient = args.reactorClient;
|
|
24
|
+
this.graphqlManager = args.graphqlManager;
|
|
25
|
+
this.relationalDb = args.relationalDb;
|
|
26
|
+
this.syncManager = args.syncManager;
|
|
27
|
+
this.documentPermissionService = args.documentPermissionService;
|
|
28
|
+
this.authorizationService = args.authorizationService;
|
|
29
|
+
this.path = args.path ?? "";
|
|
30
|
+
}
|
|
31
|
+
async onSetup() {}
|
|
32
|
+
getParentIdsFn() {
|
|
33
|
+
return async (documentId) => {
|
|
34
|
+
try {
|
|
35
|
+
return (await this.reactorClient.getIncomingRelationships(documentId, "child")).results.map((doc) => doc.header.id);
|
|
36
|
+
} catch {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
hasGlobalAdminAccess(ctx) {
|
|
42
|
+
return !!ctx.isAdmin?.(ctx.user?.address ?? "");
|
|
43
|
+
}
|
|
44
|
+
async canReadDocument(documentId, ctx) {
|
|
45
|
+
if (this.authorizationService) return this.authorizationService.canRead(documentId, ctx.user?.address, this.getParentIdsFn());
|
|
46
|
+
if (this.hasGlobalAdminAccess(ctx)) return true;
|
|
47
|
+
if (this.documentPermissionService) return this.documentPermissionService.canRead(documentId, ctx.user?.address, this.getParentIdsFn());
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
async assertCanRead(documentId, ctx) {
|
|
51
|
+
if (this.authorizationService) {
|
|
52
|
+
if (!await this.authorizationService.canRead(documentId, ctx.user?.address, this.getParentIdsFn())) throw new GraphQLError("Forbidden: insufficient permissions to read this document");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!this.hasGlobalAdminAccess(ctx)) if (this.documentPermissionService) {
|
|
56
|
+
if (!await this.documentPermissionService.canRead(documentId, ctx.user?.address, this.getParentIdsFn())) throw new GraphQLError("Forbidden: insufficient permissions to read this document");
|
|
57
|
+
} else throw new GraphQLError("Forbidden: insufficient permissions to read this document");
|
|
58
|
+
}
|
|
59
|
+
async assertCanWrite(documentId, ctx) {
|
|
60
|
+
if (this.authorizationService) {
|
|
61
|
+
if (!await this.authorizationService.canWrite(documentId, ctx.user?.address, this.getParentIdsFn())) throw new GraphQLError("Forbidden: insufficient permissions to write to this document");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!this.hasGlobalAdminAccess(ctx)) if (this.documentPermissionService) {
|
|
65
|
+
if (!await this.documentPermissionService.canWrite(documentId, ctx.user?.address, this.getParentIdsFn())) throw new GraphQLError("Forbidden: insufficient permissions to write to this document");
|
|
66
|
+
} else throw new GraphQLError("Forbidden: insufficient permissions to write to this document");
|
|
67
|
+
}
|
|
68
|
+
async assertCanExecuteOperation(documentId, operationType, ctx) {
|
|
69
|
+
if (this.authorizationService) {
|
|
70
|
+
if (!await this.authorizationService.canMutate(documentId, operationType, ctx.user?.address, this.getParentIdsFn())) throw new GraphQLError(`Forbidden: insufficient permissions to execute operation "${operationType}" on this document`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!this.documentPermissionService) return;
|
|
74
|
+
if (ctx.isAdmin?.(ctx.user?.address ?? "")) return;
|
|
75
|
+
if (await this.documentPermissionService.isOperationRestricted(documentId, operationType)) {
|
|
76
|
+
if (!await this.documentPermissionService.canExecuteOperation(documentId, operationType, ctx.user?.address)) throw new GraphQLError(`Forbidden: insufficient permissions to execute operation "${operationType}" on this document`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/packages/import-resolver.ts
|
|
82
|
+
/**
|
|
83
|
+
* Attempts to import from suggested Node.js paths
|
|
84
|
+
*/
|
|
85
|
+
async function tryNodeSuggestedPaths(packageName, subPath) {
|
|
86
|
+
const suggestedPaths = [`${packageName}/dist/${subPath}/index.js`, `${packageName}/dist/${subPath}.js`];
|
|
87
|
+
for (const suggestedPath of suggestedPaths) try {
|
|
88
|
+
return await import(
|
|
89
|
+
/* @vite-ignore */
|
|
90
|
+
suggestedPath
|
|
91
|
+
);
|
|
92
|
+
} catch {}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Attempts to resolve package using import.meta.resolve
|
|
97
|
+
*/
|
|
98
|
+
async function tryImportMetaResolve(packageName, subPath) {
|
|
99
|
+
try {
|
|
100
|
+
const resolvedUrl = import.meta.resolve?.(`${packageName}/package.json`);
|
|
101
|
+
if (!resolvedUrl) return null;
|
|
102
|
+
const packageRoot = path.dirname(new URL(resolvedUrl).pathname);
|
|
103
|
+
const pathsToTry = [
|
|
104
|
+
path.join(packageRoot, "dist", subPath, "index.js"),
|
|
105
|
+
path.join(packageRoot, "dist", `${subPath}.js`),
|
|
106
|
+
path.join(packageRoot, subPath, "index.js"),
|
|
107
|
+
path.join(packageRoot, `${subPath}.js`)
|
|
108
|
+
];
|
|
109
|
+
for (const attemptPath of pathsToTry) try {
|
|
110
|
+
return await import(
|
|
111
|
+
/* @vite-ignore */
|
|
112
|
+
attemptPath
|
|
113
|
+
);
|
|
114
|
+
} catch {}
|
|
115
|
+
} catch {}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Resolves symlinks in node_modules to find the real package location
|
|
120
|
+
*/
|
|
121
|
+
async function resolveSymlinkedPaths(packageName, subPath) {
|
|
122
|
+
const packageBaseName = packageName.includes("/") ? packageName.split("/").pop() : packageName;
|
|
123
|
+
const nodeModulesPatterns = [path.join(process.cwd(), "node_modules", packageName), path.join(process.cwd(), "node_modules", packageBaseName || packageName)];
|
|
124
|
+
const workspacePatterns = [];
|
|
125
|
+
for (const nodeModulesPath of nodeModulesPatterns) try {
|
|
126
|
+
const fs = await import("node:fs");
|
|
127
|
+
if (fs.existsSync(nodeModulesPath)) {
|
|
128
|
+
const realPath = fs.realpathSync(nodeModulesPath);
|
|
129
|
+
workspacePatterns.push(path.join(realPath, "dist", subPath, "index.js"), path.join(realPath, "dist", `${subPath}.js`), path.join(realPath, subPath, "index.js"), path.join(realPath, `${subPath}.js`));
|
|
130
|
+
}
|
|
131
|
+
} catch {}
|
|
132
|
+
return workspacePatterns;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Generates common workspace pattern paths
|
|
136
|
+
*/
|
|
137
|
+
function getCommonWorkspacePaths(packageName, subPath) {
|
|
138
|
+
const packageBaseName = packageName.includes("/") ? packageName.split("/").pop() : packageName;
|
|
139
|
+
const commonRoots = [process.cwd(), path.dirname(process.cwd())];
|
|
140
|
+
const workspacePatterns = [];
|
|
141
|
+
for (const root of commonRoots) workspacePatterns.push(path.join(root, "packages", packageBaseName || packageName, "dist", subPath, "index.js"), path.join(root, "packages", packageBaseName || packageName, "dist", `${subPath}.js`));
|
|
142
|
+
return workspacePatterns;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Attempts to import from a list of workspace patterns
|
|
146
|
+
*/
|
|
147
|
+
async function tryWorkspacePatterns(patterns) {
|
|
148
|
+
for (const workspacePath of patterns) try {
|
|
149
|
+
return await import(
|
|
150
|
+
/* @vite-ignore */
|
|
151
|
+
workspacePath
|
|
152
|
+
);
|
|
153
|
+
} catch {}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Attempts to resolve linked packages using various fallback strategies
|
|
158
|
+
*/
|
|
159
|
+
async function resolveLinkedPackage(packageName, subPath) {
|
|
160
|
+
let result = await tryNodeSuggestedPaths(packageName, subPath);
|
|
161
|
+
if (result) return result;
|
|
162
|
+
result = await tryImportMetaResolve(packageName, subPath);
|
|
163
|
+
if (result) return result;
|
|
164
|
+
result = await tryWorkspacePatterns(await resolveSymlinkedPaths(packageName, subPath));
|
|
165
|
+
if (result) return result;
|
|
166
|
+
result = await tryWorkspacePatterns(getCommonWorkspacePaths(packageName, subPath));
|
|
167
|
+
if (result) return result;
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/packages/util.ts
|
|
172
|
+
childLogger(["reactor-api", "packages/util"]);
|
|
173
|
+
/**
|
|
174
|
+
* Tries to import document models from a package. This function cannot throw.
|
|
175
|
+
*/
|
|
176
|
+
async function loadDocumentModels(packageName) {
|
|
177
|
+
return loadDependency(packageName, "document-models");
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Tries to import subgraphs from a package. This function cannot throw.
|
|
181
|
+
*/
|
|
182
|
+
async function loadSubgraphs(packageName) {
|
|
183
|
+
return loadDependency(packageName, "subgraphs");
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Tries to import processors from a package. This function cannot throw.
|
|
187
|
+
*/
|
|
188
|
+
async function loadProcessors(packageName) {
|
|
189
|
+
return loadDependency(packageName, "processors");
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Generic dependency loader - tries to import a dependency from a package. This function cannot throw.
|
|
193
|
+
* Returns null if the dependency cannot be loaded.
|
|
194
|
+
*/
|
|
195
|
+
async function loadDependency(packageName, subPath) {
|
|
196
|
+
const fullPath = `${packageName}/${subPath}`;
|
|
197
|
+
try {
|
|
198
|
+
return await import(
|
|
199
|
+
/* @vite-ignore */
|
|
200
|
+
fullPath
|
|
201
|
+
);
|
|
202
|
+
} catch (e) {
|
|
203
|
+
if (e instanceof Error && "code" in e && (e.code === "ERR_MODULE_NOT_FOUND" || e.code === "ERR_UNSUPPORTED_DIR_IMPORT")) {
|
|
204
|
+
const result = await resolveLinkedPackage(packageName, subPath);
|
|
205
|
+
if (result) return result;
|
|
206
|
+
}
|
|
207
|
+
throw e;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function debounce(func, delay = 250) {
|
|
211
|
+
let timer;
|
|
212
|
+
return (immediate = false, ...args) => {
|
|
213
|
+
if (timer) clearTimeout(timer);
|
|
214
|
+
return new Promise((resolve, reject) => {
|
|
215
|
+
if (immediate) func(...args).then(resolve).catch(reject);
|
|
216
|
+
else timer = setTimeout(() => {
|
|
217
|
+
func(...args).then(resolve).catch(reject);
|
|
218
|
+
}, delay);
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function isSubpath(parent, dir) {
|
|
223
|
+
const relative = path.relative(parent, dir);
|
|
224
|
+
return relative && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
225
|
+
}
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/graphql/utils.ts
|
|
228
|
+
function isSubgraphClass(candidate) {
|
|
229
|
+
if (typeof candidate !== "function") return false;
|
|
230
|
+
let proto = Object.getPrototypeOf(candidate);
|
|
231
|
+
while (proto) {
|
|
232
|
+
if (Object.prototype.isPrototypeOf.call(proto, BaseSubgraph)) return true;
|
|
233
|
+
proto = Object.getPrototypeOf(proto);
|
|
234
|
+
}
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
function buildGraphqlOperations(operations, skip, first) {
|
|
238
|
+
return operations.slice(skip, skip + first).map(buildGraphqlOperation);
|
|
239
|
+
}
|
|
240
|
+
function buildGraphqlOperation(operation) {
|
|
241
|
+
const signer = operation.action.context?.signer;
|
|
242
|
+
return {
|
|
243
|
+
id: operation.id ?? "",
|
|
244
|
+
type: operation.action.type,
|
|
245
|
+
index: operation.index,
|
|
246
|
+
timestampUtcMs: operation.timestampUtcMs,
|
|
247
|
+
hash: operation.hash,
|
|
248
|
+
skip: operation.skip,
|
|
249
|
+
inputText: typeof operation.action.input === "string" ? operation.action.input : JSON.stringify(operation.action.input),
|
|
250
|
+
error: operation.error,
|
|
251
|
+
context: { signer: signer ? {
|
|
252
|
+
user: signer.user,
|
|
253
|
+
app: signer.app,
|
|
254
|
+
signatures: signer.signatures.map((sig) => Array.isArray(sig) ? sig.join(", ") : sig)
|
|
255
|
+
} : void 0 }
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function buildGraphQlDocument(doc) {
|
|
259
|
+
const state = doc.state;
|
|
260
|
+
const initialState = doc.initialState;
|
|
261
|
+
const globalState = "global" in doc.state ? doc.state.global : {};
|
|
262
|
+
return {
|
|
263
|
+
id: doc.header.id,
|
|
264
|
+
name: doc.header.name,
|
|
265
|
+
documentType: doc.header.documentType,
|
|
266
|
+
revision: doc.header.revision.global || 0,
|
|
267
|
+
createdAtUtcIso: doc.header.createdAtUtcIso,
|
|
268
|
+
lastModifiedAtUtcIso: doc.header.lastModifiedAtUtcIso,
|
|
269
|
+
operations: [],
|
|
270
|
+
stateJSON: globalState,
|
|
271
|
+
state,
|
|
272
|
+
initialState
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function buildGraphQlDriveDocument(doc) {
|
|
276
|
+
return {
|
|
277
|
+
...buildGraphQlDocument(doc),
|
|
278
|
+
meta: { preferredEditor: doc.header.meta?.preferredEditor },
|
|
279
|
+
slug: doc.header.slug,
|
|
280
|
+
state: doc.state.global,
|
|
281
|
+
initialState: doc.state.global
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
285
|
+
export { isSubgraphClass as a, loadDocumentModels as c, BaseSubgraph as d, buildGraphqlOperations as i, loadProcessors as l, buildGraphQlDriveDocument as n, debounce as o, buildGraphqlOperation as r, isSubpath as s, buildGraphQlDocument as t, loadSubgraphs as u };
|
|
286
|
+
|
|
287
|
+
//# sourceMappingURL=utils-CVrD_vPF.mjs.map
|