@campxdev/server-shared 1.9.8-alpha.3 → 1.9.8-alpha.5
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/request-store/contexts/graphql-context.d.ts +24 -0
- package/dist/request-store/contexts/graphql-context.d.ts.map +1 -0
- package/dist/request-store/contexts/graphql-context.js +38 -0
- package/dist/request-store/contexts/graphql-context.js.map +1 -0
- package/dist/request-store/contexts/index.d.ts +3 -2
- package/dist/request-store/contexts/index.d.ts.map +1 -1
- package/dist/request-store/contexts/index.js +3 -2
- package/dist/request-store/contexts/index.js.map +1 -1
- package/dist/request-store/graphql-middleware.d.ts +31 -0
- package/dist/request-store/graphql-middleware.d.ts.map +1 -0
- package/dist/request-store/graphql-middleware.js +54 -0
- package/dist/request-store/graphql-middleware.js.map +1 -0
- package/dist/request-store/index.d.ts +2 -1
- package/dist/request-store/index.d.ts.map +1 -1
- package/dist/request-store/index.js +2 -1
- package/dist/request-store/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Request } from 'express';
|
|
2
|
+
import { IRequest } from '../../common/interfaces/context.interface';
|
|
3
|
+
/**
|
|
4
|
+
* Sets the GraphQL request object in the store.
|
|
5
|
+
* This bridges the GraphQL context with the existing AsyncLocalStorage-based request store.
|
|
6
|
+
* @param req - The Express request object from GraphQL context.
|
|
7
|
+
*/
|
|
8
|
+
export declare function setGraphQLRequest(req: Request): void;
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves the GraphQL request object from the store.
|
|
11
|
+
* @returns The Express request object.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getGraphQLRequest(): Request;
|
|
14
|
+
/**
|
|
15
|
+
* Sets a custom GraphQL request object in the store.
|
|
16
|
+
* @param req - The custom request object with GraphQL-specific properties.
|
|
17
|
+
*/
|
|
18
|
+
export declare function setGraphQLCustomRequest(req: IRequest): void;
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the custom GraphQL request object from the store.
|
|
21
|
+
* @returns The custom request object.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getGraphQLCustomRequest(): IRequest;
|
|
24
|
+
//# sourceMappingURL=graphql-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-context.d.ts","sourceRoot":"","sources":["../../../src/request-store/contexts/graphql-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,2CAA2C,CAAC;AAIrE;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAEpD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI,CAE3D;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,QAAQ,CAElD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setGraphQLRequest = setGraphQLRequest;
|
|
4
|
+
exports.getGraphQLRequest = getGraphQLRequest;
|
|
5
|
+
exports.setGraphQLCustomRequest = setGraphQLCustomRequest;
|
|
6
|
+
exports.getGraphQLCustomRequest = getGraphQLCustomRequest;
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const store_config_1 = require("../store-config");
|
|
9
|
+
/**
|
|
10
|
+
* Sets the GraphQL request object in the store.
|
|
11
|
+
* This bridges the GraphQL context with the existing AsyncLocalStorage-based request store.
|
|
12
|
+
* @param req - The Express request object from GraphQL context.
|
|
13
|
+
*/
|
|
14
|
+
function setGraphQLRequest(req) {
|
|
15
|
+
(0, store_config_1.set)(constants_1.EXPRESS_REQUEST, req);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Retrieves the GraphQL request object from the store.
|
|
19
|
+
* @returns The Express request object.
|
|
20
|
+
*/
|
|
21
|
+
function getGraphQLRequest() {
|
|
22
|
+
return (0, store_config_1.get)(constants_1.EXPRESS_REQUEST);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Sets a custom GraphQL request object in the store.
|
|
26
|
+
* @param req - The custom request object with GraphQL-specific properties.
|
|
27
|
+
*/
|
|
28
|
+
function setGraphQLCustomRequest(req) {
|
|
29
|
+
(0, store_config_1.set)(constants_1.EXPRESS_REQUEST, req);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves the custom GraphQL request object from the store.
|
|
33
|
+
* @returns The custom request object.
|
|
34
|
+
*/
|
|
35
|
+
function getGraphQLCustomRequest() {
|
|
36
|
+
return (0, store_config_1.get)(constants_1.EXPRESS_REQUEST);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=graphql-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-context.js","sourceRoot":"","sources":["../../../src/request-store/contexts/graphql-context.ts"],"names":[],"mappings":";;AAUA,8CAEC;AAMD,8CAEC;AAMD,0DAEC;AAMD,0DAEC;AAlCD,4CAA+C;AAC/C,kDAA2C;AAE3C;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,GAAY;IAC5C,IAAA,kBAAG,EAAC,2BAAe,EAAE,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,IAAA,kBAAG,EAAU,2BAAe,CAAC,CAAC;AACvC,CAAC;AAED;;;GAGG;AACH,SAAgB,uBAAuB,CAAC,GAAa;IACnD,IAAA,kBAAG,EAAC,2BAAe,EAAE,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,SAAgB,uBAAuB;IACrC,OAAO,IAAA,kBAAG,EAAC,2BAAe,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export * from './aws-context';
|
|
2
|
-
export * from './express-context';
|
|
3
2
|
export * from './easydms-context';
|
|
3
|
+
export * from './express-context';
|
|
4
|
+
export * from './graphql-context';
|
|
4
5
|
export * from './mongo-context';
|
|
5
6
|
export * from './mysql-context';
|
|
6
7
|
export * from './mysql-credentials-context';
|
|
7
|
-
export * from './user-context';
|
|
8
8
|
export * from './tenant-context';
|
|
9
|
+
export * from './user-context';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/request-store/contexts/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/request-store/contexts/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
|
|
@@ -15,11 +15,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./aws-context"), exports);
|
|
18
|
-
__exportStar(require("./express-context"), exports);
|
|
19
18
|
__exportStar(require("./easydms-context"), exports);
|
|
19
|
+
__exportStar(require("./express-context"), exports);
|
|
20
|
+
__exportStar(require("./graphql-context"), exports);
|
|
20
21
|
__exportStar(require("./mongo-context"), exports);
|
|
21
22
|
__exportStar(require("./mysql-context"), exports);
|
|
22
23
|
__exportStar(require("./mysql-credentials-context"), exports);
|
|
23
|
-
__exportStar(require("./user-context"), exports);
|
|
24
24
|
__exportStar(require("./tenant-context"), exports);
|
|
25
|
+
__exportStar(require("./user-context"), exports);
|
|
25
26
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/request-store/contexts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,oDAAkC;AAClC,oDAAkC;AAClC,kDAAgC;AAChC,kDAAgC;AAChC,8DAA4C;AAC5C,iDAA+B
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/request-store/contexts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,oDAAkC;AAClC,oDAAkC;AAClC,oDAAkC;AAClC,kDAAgC;AAChC,kDAAgC;AAChC,8DAA4C;AAC5C,mDAAiC;AACjC,iDAA+B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GraphQL context middleware that integrates with the existing AsyncLocalStorage store.
|
|
3
|
+
* This allows GraphQL resolvers to use the same request store functions as REST endpoints.
|
|
4
|
+
*
|
|
5
|
+
* Usage in GraphQL module:
|
|
6
|
+
* ```typescript
|
|
7
|
+
* GraphQLModule.forRoot({
|
|
8
|
+
* context: graphqlContextMiddleware,
|
|
9
|
+
* // ... other options
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param contextParams - The GraphQL context parameters containing the request
|
|
14
|
+
* @returns The GraphQL context with the request stored in AsyncLocalStorage
|
|
15
|
+
*/
|
|
16
|
+
export declare const graphqlContextMiddleware: ({ req }: {
|
|
17
|
+
req: any;
|
|
18
|
+
}) => Promise<unknown>;
|
|
19
|
+
/**
|
|
20
|
+
* Synchronous version of GraphQL context middleware for scenarios where
|
|
21
|
+
* async context handling is not needed.
|
|
22
|
+
*
|
|
23
|
+
* @param contextParams - The GraphQL context parameters containing the request
|
|
24
|
+
* @returns The GraphQL context with the request stored in AsyncLocalStorage
|
|
25
|
+
*/
|
|
26
|
+
export declare const graphqlContextMiddlewareSync: ({ req }: {
|
|
27
|
+
req: any;
|
|
28
|
+
}) => {
|
|
29
|
+
req: any;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=graphql-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-middleware.d.ts","sourceRoot":"","sources":["../../src/request-store/graphql-middleware.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,wBAAwB,GAAI,SAAS;IAAE,GAAG,EAAE,GAAG,CAAA;CAAE,qBAc7D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,GAAI,SAAS;IAAE,GAAG,EAAE,GAAG,CAAA;CAAE;;CAYjE,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.graphqlContextMiddlewareSync = exports.graphqlContextMiddleware = void 0;
|
|
4
|
+
const graphql_context_1 = require("./contexts/graphql-context");
|
|
5
|
+
const store_config_1 = require("./store-config");
|
|
6
|
+
/**
|
|
7
|
+
* GraphQL context middleware that integrates with the existing AsyncLocalStorage store.
|
|
8
|
+
* This allows GraphQL resolvers to use the same request store functions as REST endpoints.
|
|
9
|
+
*
|
|
10
|
+
* Usage in GraphQL module:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* GraphQLModule.forRoot({
|
|
13
|
+
* context: graphqlContextMiddleware,
|
|
14
|
+
* // ... other options
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param contextParams - The GraphQL context parameters containing the request
|
|
19
|
+
* @returns The GraphQL context with the request stored in AsyncLocalStorage
|
|
20
|
+
*/
|
|
21
|
+
const graphqlContextMiddleware = ({ req }) => {
|
|
22
|
+
// Get the current store or create a new one
|
|
23
|
+
const currentStore = store_config_1.store.getStore() || new Map();
|
|
24
|
+
// Run the GraphQL context within the store
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
store_config_1.store.run(currentStore, () => {
|
|
27
|
+
// Set the GraphQL request in the AsyncLocalStorage store
|
|
28
|
+
(0, graphql_context_1.setGraphQLRequest)(req);
|
|
29
|
+
// Return the context with the request
|
|
30
|
+
resolve({ req });
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
exports.graphqlContextMiddleware = graphqlContextMiddleware;
|
|
35
|
+
/**
|
|
36
|
+
* Synchronous version of GraphQL context middleware for scenarios where
|
|
37
|
+
* async context handling is not needed.
|
|
38
|
+
*
|
|
39
|
+
* @param contextParams - The GraphQL context parameters containing the request
|
|
40
|
+
* @returns The GraphQL context with the request stored in AsyncLocalStorage
|
|
41
|
+
*/
|
|
42
|
+
const graphqlContextMiddlewareSync = ({ req }) => {
|
|
43
|
+
// Get the current store or create a new one
|
|
44
|
+
const currentStore = store_config_1.store.getStore() || new Map();
|
|
45
|
+
// Run the GraphQL context within the store synchronously
|
|
46
|
+
store_config_1.store.run(currentStore, () => {
|
|
47
|
+
// Set the GraphQL request in the AsyncLocalStorage store
|
|
48
|
+
(0, graphql_context_1.setGraphQLRequest)(req);
|
|
49
|
+
});
|
|
50
|
+
// Return the context with the request
|
|
51
|
+
return { req };
|
|
52
|
+
};
|
|
53
|
+
exports.graphqlContextMiddlewareSync = graphqlContextMiddlewareSync;
|
|
54
|
+
//# sourceMappingURL=graphql-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-middleware.js","sourceRoot":"","sources":["../../src/request-store/graphql-middleware.ts"],"names":[],"mappings":";;;AAAA,gEAA+D;AAC/D,iDAAuC;AAEvC;;;;;;;;;;;;;;GAcG;AACI,MAAM,wBAAwB,GAAG,CAAC,EAAE,GAAG,EAAgB,EAAE,EAAE;IAChE,4CAA4C;IAC5C,MAAM,YAAY,GAAG,oBAAK,CAAC,QAAQ,EAAE,IAAI,IAAI,GAAG,EAAE,CAAC;IAEnD,2CAA2C;IAC3C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,oBAAK,CAAC,GAAG,CAAC,YAAY,EAAE,GAAG,EAAE;YAC3B,yDAAyD;YACzD,IAAA,mCAAiB,EAAC,GAAG,CAAC,CAAC;YAEvB,sCAAsC;YACtC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAdW,QAAA,wBAAwB,4BAcnC;AAEF;;;;;;GAMG;AACI,MAAM,4BAA4B,GAAG,CAAC,EAAE,GAAG,EAAgB,EAAE,EAAE;IACpE,4CAA4C;IAC5C,MAAM,YAAY,GAAG,oBAAK,CAAC,QAAQ,EAAE,IAAI,IAAI,GAAG,EAAE,CAAC;IAEnD,yDAAyD;IACzD,oBAAK,CAAC,GAAG,CAAC,YAAY,EAAE,GAAG,EAAE;QAC3B,yDAAyD;QACzD,IAAA,mCAAiB,EAAC,GAAG,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,sCAAsC;IACtC,OAAO,EAAE,GAAG,EAAE,CAAC;AACjB,CAAC,CAAC;AAZW,QAAA,4BAA4B,gCAYvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/request-store/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/request-store/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC"}
|
|
@@ -14,8 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./contexts"), exports);
|
|
18
|
+
__exportStar(require("./graphql-middleware"), exports);
|
|
17
19
|
__exportStar(require("./request-store"), exports);
|
|
18
20
|
__exportStar(require("./store-config"), exports);
|
|
19
21
|
__exportStar(require("./store.interceptor"), exports);
|
|
20
|
-
__exportStar(require("./contexts"), exports);
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/request-store/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,iDAA+B;AAC/B,sDAAoC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/request-store/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,uDAAqC;AACrC,kDAAgC;AAChC,iDAA+B;AAC/B,sDAAoC"}
|