@skedulo/pulse-solution-services 0.0.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/README.md +161 -0
- package/dist/clients/base-client.js +1 -0
- package/dist/clients/config-var-client.js +1 -0
- package/dist/clients/graphql-client.js +1 -0
- package/dist/clients/index.js +1 -0
- package/dist/clients/metadata-client.js +1 -0
- package/dist/constants/config-var.js +1 -0
- package/dist/constants/http.js +1 -0
- package/dist/constants/index.js +1 -0
- package/dist/constants/tenant-endpoints.js +1 -0
- package/dist/constants/tenant-objects.js +1 -0
- package/dist/core/execution-context.js +1 -0
- package/dist/core/index.js +1 -0
- package/dist/index.d.ts +644 -0
- package/dist/index.js +1 -0
- package/dist/interfaces/config-var.js +1 -0
- package/dist/interfaces/graphql.js +1 -0
- package/dist/interfaces/index.js +1 -0
- package/dist/interfaces/metadata.js +1 -0
- package/dist/logging/decorators/index.d.ts +1 -0
- package/dist/logging/decorators/index.js +1 -0
- package/dist/logging/decorators/log-method.d.ts +7 -0
- package/dist/logging/decorators/log-method.js +1 -0
- package/dist/logging/index.js +1 -0
- package/dist/logging/logger.js +1 -0
- package/dist/services/batch-processor/batch-orchestrator.d.ts +18 -0
- package/dist/services/batch-processor/batch-orchestrator.js +1 -0
- package/dist/services/batch-processor/constants.d.ts +22 -0
- package/dist/services/batch-processor/constants.js +1 -0
- package/dist/services/batch-processor/fetching-strategies/batch-number-fetching-strategy.d.ts +6 -0
- package/dist/services/batch-processor/fetching-strategies/batch-number-fetching-strategy.js +1 -0
- package/dist/services/batch-processor/fetching-strategies/cursor-based-fetching-strategy.d.ts +8 -0
- package/dist/services/batch-processor/fetching-strategies/cursor-based-fetching-strategy.js +1 -0
- package/dist/services/batch-processor/fetching-strategies/date-based-fetching-strategy.d.ts +4 -0
- package/dist/services/batch-processor/fetching-strategies/date-based-fetching-strategy.js +1 -0
- package/dist/services/batch-processor/fetching-strategies/fetching-strategy-factory.d.ts +9 -0
- package/dist/services/batch-processor/fetching-strategies/fetching-strategy-factory.js +1 -0
- package/dist/services/batch-processor/fetching-strategies/index.d.ts +1 -0
- package/dist/services/batch-processor/fetching-strategies/index.js +1 -0
- package/dist/services/batch-processor/index.d.ts +2 -0
- package/dist/services/batch-processor/index.js +1 -0
- package/dist/services/batch-processor/interfaces.d.ts +33 -0
- package/dist/services/batch-processor/interfaces.js +1 -0
- package/dist/services/batch-processor/workers/custom-worker.d.ts +5 -0
- package/dist/services/batch-processor/workers/custom-worker.js +1 -0
- package/dist/services/batch-processor/workers/delete-worker.d.ts +4 -0
- package/dist/services/batch-processor/workers/delete-worker.js +1 -0
- package/dist/services/batch-processor/workers/index.d.ts +2 -0
- package/dist/services/batch-processor/workers/index.js +1 -0
- package/dist/services/batch-processor/workers/update-worker.d.ts +4 -0
- package/dist/services/batch-processor/workers/update-worker.js +1 -0
- package/dist/services/batch-processor/workers/worker-factory.d.ts +6 -0
- package/dist/services/batch-processor/workers/worker-factory.js +1 -0
- package/dist/services/batch-processor/workers/worker-interfaces.d.ts +4 -0
- package/dist/services/batch-processor/workers/worker-interfaces.js +1 -0
- package/dist/services/cache/cache-service.d.ts +70 -0
- package/dist/services/cache/cache-service.js +1 -0
- package/dist/services/cache/index.d.ts +1 -0
- package/dist/services/cache/index.js +1 -0
- package/dist/services/cache/storage/config-var-cache-storage.d.ts +40 -0
- package/dist/services/cache/storage/config-var-cache-storage.js +1 -0
- package/dist/services/cache/storage/in-memory-cache-storage.d.ts +32 -0
- package/dist/services/cache/storage/in-memory-cache-storage.js +1 -0
- package/dist/services/cache/storage/index.d.ts +2 -0
- package/dist/services/cache/storage/index.js +1 -0
- package/dist/services/graphql/graphql-query-builder.d.ts +75 -0
- package/dist/services/graphql/graphql-query-builder.js +1 -0
- package/dist/services/graphql/graphql-service.d.ts +46 -0
- package/dist/services/graphql/graphql-service.js +1 -0
- package/dist/services/graphql/index.d.ts +2 -0
- package/dist/services/graphql/index.js +1 -0
- package/dist/services/graphql/queries.d.ts +25 -0
- package/dist/services/graphql/queries.js +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/metadata-service.js +1 -0
- package/dist/utils/config-helper.js +1 -0
- package/dist/utils/index.js +1 -0
- package/package.json +42 -0
- package/yarn.lock +2836 -0
package/README.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# Pulse Solution Services
|
|
2
|
+
|
|
3
|
+
**@skedulo/pulse-solution-services** provides common services and utilities for building solutions on the Pulse platform.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @skedulo/pulse-solution-services
|
|
9
|
+
```
|
|
10
|
+
or
|
|
11
|
+
```bash
|
|
12
|
+
yarn add @skedulo/pulse-solution-services
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
### Initialize Execution Context
|
|
17
|
+
|
|
18
|
+
**From a function**
|
|
19
|
+
```javascript
|
|
20
|
+
const context = ExecutionContext.fromContext(skedToken);
|
|
21
|
+
```
|
|
22
|
+
**From other execution contexts**
|
|
23
|
+
```javascript
|
|
24
|
+
const context = ExecutionContext.fromCredentials({
|
|
25
|
+
apiServer: user.apiBasePath,
|
|
26
|
+
apiToken: user.user.accessToken,
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
### API Clients
|
|
30
|
+
|
|
31
|
+
**Metadata Client**
|
|
32
|
+
Fetches metadata from `/metadata` endpoints.
|
|
33
|
+
```javascript
|
|
34
|
+
// Calls /metadata endpoint to retrieve all metadata
|
|
35
|
+
const metadata = await context.metadataClient.fetchAllMetadata();
|
|
36
|
+
|
|
37
|
+
// Calls /metadata/{mapping} endpoint to fetches metadata for a specific object
|
|
38
|
+
const jobMetadata = await context.metadataClient.fetchObjectMetadata('job');
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**GraphQL Client**
|
|
42
|
+
Executes GraphQL queries and mutations against `/graphql/graphql`.
|
|
43
|
+
```javascript
|
|
44
|
+
const queryResult = await context.graphqlClient.query(queryParams);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Config Variable Client**
|
|
48
|
+
Provides CRUD and search methods for managing configuration variables.
|
|
49
|
+
```javascript
|
|
50
|
+
// Calls /configuration/extension endpoint to create a configuration var
|
|
51
|
+
await context.configVarClient.create({
|
|
52
|
+
key: "TEST_KEY",
|
|
53
|
+
value: "TEST_VALUE",
|
|
54
|
+
configType: "plain-text",
|
|
55
|
+
description: "TEST_DESCRIPTION",
|
|
56
|
+
});
|
|
57
|
+
// Gets a config var
|
|
58
|
+
const config = await context.configVarClient.get('TEST_KEY');
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### GraphQL Service
|
|
62
|
+
|
|
63
|
+
**Query data**
|
|
64
|
+
```javascript
|
|
65
|
+
// Create a query builder for the Resources object
|
|
66
|
+
const queryBuilder = context.newQueryBuilder('Resources')
|
|
67
|
+
.withFields(['UID', 'Name'])
|
|
68
|
+
.withFilter('IsActive == true')
|
|
69
|
+
.withLimit(1)
|
|
70
|
+
.withOffset(1)
|
|
71
|
+
.withOrderBy('Name ASC');
|
|
72
|
+
// Add a child query for Job Allocations
|
|
73
|
+
queryBuilder.withChildQuery('JobAllocations')
|
|
74
|
+
.withFields(['UID', 'Name'])
|
|
75
|
+
.withParentQuery('Job')
|
|
76
|
+
.withFields(['UID', 'Name']);
|
|
77
|
+
// Add a parent query for Primary Region
|
|
78
|
+
queryBuilder.withParentQuery('PrimaryRegion')
|
|
79
|
+
.withFields(['UID', 'Name']);
|
|
80
|
+
// Finally, execute the query via your GraphQL service
|
|
81
|
+
const queryResult: QueryResult = await context.graphqlService.query(queryBuilder.build());
|
|
82
|
+
|
|
83
|
+
console.log(queryResult.records);
|
|
84
|
+
console.log(queryResult.totalCount); // 5
|
|
85
|
+
console.log(queryResult.pageInfo.hasNextPage); // true
|
|
86
|
+
console.log(queryResult.endCursor); // Mg==
|
|
87
|
+
console.log(queryResult.endOffset); // 1
|
|
88
|
+
```
|
|
89
|
+
**Update data**
|
|
90
|
+
```javascript
|
|
91
|
+
const recordsToUpdate = queryResult.records.map((record) => {
|
|
92
|
+
return {
|
|
93
|
+
UID: record.UID,
|
|
94
|
+
Name: record.Name + " - Updated"
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
const updateResult = await context.graphqlService.update('Resources', recordsToUpdate);
|
|
98
|
+
```
|
|
99
|
+
**Pagination with offset**
|
|
100
|
+
```javascript
|
|
101
|
+
while(queryResult.pageInfo.hasNextPage) {
|
|
102
|
+
queryBuilder.withOffset(queryResult.endOffset + 1);
|
|
103
|
+
queryResult = await context.graphqlService.query(queryBuilder.build());
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
**Pagination with cursor**
|
|
107
|
+
```javascript
|
|
108
|
+
while(queryResult.pageInfo.hasNextPage) {
|
|
109
|
+
queryBuilder.withCursor(queryResult.endCursor);
|
|
110
|
+
queryResult = await context.graphqlService.query(queryBuilder.build());
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Batch Service
|
|
115
|
+
The Batch Service offers a flexible and scalable solution for large-scale data processing.
|
|
116
|
+
```javascript
|
|
117
|
+
const job = {
|
|
118
|
+
CreatedDate: new Date().toISOString(),
|
|
119
|
+
JobType: 'Delete',
|
|
120
|
+
ObjectName: 'Accounts',
|
|
121
|
+
Fields: "UID",
|
|
122
|
+
BatchSize: 100,
|
|
123
|
+
MaximumBatches: 10
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const context = ExecutionContext.fromCredentials({
|
|
127
|
+
apiServer: user.apiBasePath,
|
|
128
|
+
apiToken: user.user.accessToken,
|
|
129
|
+
});
|
|
130
|
+
context.contextData.job = job;
|
|
131
|
+
const orchestrator = new BatchOrchestrator(context, {
|
|
132
|
+
isAsyncProcessing: false,
|
|
133
|
+
});
|
|
134
|
+
await orchestrator.processBatchJob();
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Cache Service
|
|
138
|
+
The Cache Service enables efficient data sharing between function executions and improves performance by reducing redundant operations and API calls.
|
|
139
|
+
```javascript
|
|
140
|
+
// Multi-layer cache
|
|
141
|
+
const metadata: object[] = await context.inMemoryCache.get(
|
|
142
|
+
"METADATA",{
|
|
143
|
+
useSecondaryCache: true,
|
|
144
|
+
}
|
|
145
|
+
)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Logging Utils
|
|
149
|
+
The log method decorator helps streamline debugging by tracking key function executions, including their inputs and outputs.
|
|
150
|
+
```javascript
|
|
151
|
+
class ExampleService {
|
|
152
|
+
@LogMethod("example_space")
|
|
153
|
+
processData(input: string): string {
|
|
154
|
+
return `Processed: ${input}`;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
Two environment variables control logging behavior:
|
|
159
|
+
|
|
160
|
+
- LOG_NAMESPACE: Filters logs by a specific namespace or displays all logs. The namespace for services in this library is PSS.
|
|
161
|
+
- LOG_ENTRY_MAX_LENGTH: Defaults to 120 but can be increased to capture complete input/output data.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __decorate=this&&this.__decorate||function(e,t,n,o){var i,r=arguments.length,a=r<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,o);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(a=(r<3?i(a):r>3?i(t,n,a):i(t,n))||a);return r>3&&a&&Object.defineProperty(t,n,a),a},__metadata=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},__awaiter=this&&this.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function a(e){try{c(o.next(e))}catch(e){r(e)}}function s(e){try{c(o.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseClient=void 0;const logging_1=require("../logging");class BaseClient{constructor(e){this.config=e}getHeaders(){return{Authorization:`Bearer ${this.config.apiToken}`,"Content-Type":"application/json"}}performRequest(e){return __awaiter(this,arguments,void 0,(function*({method:e="GET",endpoint:t,headers:n={},body:o}){try{const i=Object.assign(Object.assign({},this.getHeaders()),n),r=yield fetch(`${this.config.apiServer}/${t}`,{method:e,headers:i,body:o?JSON.stringify(o):void 0});let a;const s=r.headers.get("content-type");if(a=s&&s.includes("application/json")?yield r.json():yield r.text(),!r.ok)throw new Error(`HTTP error! Status: ${r.status}. Response: ${JSON.stringify(a)}`);return a}catch(e){throw this.handleException(e),e}}))}handleException(e){}}exports.BaseClient=BaseClient,__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],BaseClient.prototype,"performRequest",null);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(o,r){function s(t){try{_(i.next(t))}catch(t){r(t)}}function a(t){try{_(i.throw(t))}catch(t){r(t)}}function _(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}_((i=i.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConfigVarClient=void 0;const constants_1=require("../constants"),base_client_1=require("./base-client");class ConfigVarClient extends base_client_1.BaseClient{create(t){return __awaiter(this,void 0,void 0,(function*(){return yield this.performRequest({method:constants_1.HTTP_METHOD.POST,endpoint:constants_1.TENANT_ENDPOINTS.CONFIG_VAR.CREATE,body:t})}))}get(t){return __awaiter(this,void 0,void 0,(function*(){return yield this.performRequest({endpoint:constants_1.TENANT_ENDPOINTS.CONFIG_VAR.GET(t)})}))}update(t){return __awaiter(this,void 0,void 0,(function*(){const e=t.key||"";return delete t.key,yield this.performRequest({method:constants_1.HTTP_METHOD.PATCH,endpoint:constants_1.TENANT_ENDPOINTS.CONFIG_VAR.UPDATE(e),body:{value:t.value,description:t.description}})}))}search(t){return __awaiter(this,void 0,void 0,(function*(){return yield this.performRequest({method:constants_1.HTTP_METHOD.POST,endpoint:constants_1.TENANT_ENDPOINTS.CONFIG_VAR.SEARCH,body:{pageSize:t&&t<1e3?t:1e3}})}))}delete(t){return __awaiter(this,void 0,void 0,(function*(){return yield this.performRequest({method:constants_1.HTTP_METHOD.DELETE,endpoint:constants_1.TENANT_ENDPOINTS.CONFIG_VAR.DELETE(t)})}))}}exports.ConfigVarClient=ConfigVarClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(r,s){function a(t){try{c(i.next(t))}catch(t){s(t)}}function o(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,o)}c((i=i.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphQLClient=void 0;const constants_1=require("../constants"),http_1=require("../constants/http"),base_client_1=require("./base-client");class GraphQLClient extends base_client_1.BaseClient{execute(t){return __awaiter(this,void 0,void 0,(function*(){return yield this.performRequest({method:http_1.HTTP_METHOD.POST,endpoint:constants_1.TENANT_ENDPOINTS.GRAPHQL,body:{query:t}})}))}}exports.GraphQLClient=GraphQLClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,o)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("../services/metadata-service"),exports),__exportStar(require("./base-client"),exports),__exportStar(require("./config-var-client"),exports),__exportStar(require("./graphql-client"),exports),__exportStar(require("./metadata-client"),exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,n,a){return new(n||(n=Promise))((function(i,r){function s(t){try{c(a.next(t))}catch(t){r(t)}}function o(t){try{c(a.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,o)}c((a=a.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MetadataClient=void 0;const constants_1=require("../constants"),base_client_1=require("./base-client");class MetadataClient extends base_client_1.BaseClient{fetchAllMetadata(){return __awaiter(this,void 0,void 0,(function*(){return yield this.performRequest({endpoint:constants_1.TENANT_ENDPOINTS.METADATA.ALL})}))}fetchObjectMetadata(t){return __awaiter(this,void 0,void 0,(function*(){return yield this.performRequest({endpoint:constants_1.TENANT_ENDPOINTS.METADATA.OBJECT(t)})}))}}exports.MetadataClient=MetadataClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CONFIG_VAR_STATUS=exports.CONFIG_VAR_TYPE=void 0,exports.CONFIG_VAR_TYPE={PLAIN_TEXT:"plain-text",SECRET:"secret"},exports.CONFIG_VAR_STATUS={ACTIVE:"active",INACTIVE:"inactive",EXPIRED:"expired"};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.HTTP_METHOD=void 0,exports.HTTP_METHOD={GET:"GET",POST:"POST",PUT:"PUT",DELETE:"DELETE",PATCH:"PATCH"};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,i)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./config-var"),exports),__exportStar(require("./http"),exports),__exportStar(require("./tenant-endpoints"),exports),__exportStar(require("./tenant-objects"),exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TENANT_ENDPOINTS=void 0,exports.TENANT_ENDPOINTS={CONFIG_VAR:{CREATE:"configuration/extension",GET:e=>`configuration/extension/${e}`,UPDATE:e=>`configuration/extension/${e}`,DELETE:e=>`configuration/extension/${e}`,SEARCH:"configuration/extension/search"},GRAPHQL:"graphql/graphql",METADATA:{ALL:"custom/metadata",OBJECT:e=>`custom/metadata/${e}`}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TENANT_OBJECTS=void 0,exports.TENANT_OBJECTS={Accounts:"Accounts",Jobs:"Jobs",JobAllocations:"JobAllocations",Regions:"Regions",Contacts:"Contacts",Locations:"Locations",Resources:"Resources",Tags:"Tags",JobTags:"JobTags",ResourceTags:"ResourceTags",Activities:"Activities",Availabilities:"Availabilities",Holidays:"Holidays",AvailabilityPatterns:"AvailabilityPatterns",AvailabilityPatternResources:"AvailabilityPatternResources",AccountResourceScores:"AccountResourceScores",LocationResourceScores:"LocationResourceScores",Products:"Products",JobProducts:"JobProducts"};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ExecutionContext=void 0;const function_utilities_1=require("@skedulo/function-utilities"),config_var_client_1=require("../clients/config-var-client"),graphql_client_1=require("../clients/graphql-client"),metadata_client_1=require("../clients/metadata-client"),logging_1=require("../logging"),cache_service_1=require("../services/cache/cache-service"),storage_1=require("../services/cache/storage"),graphql_1=require("../services/graphql"),metadata_service_1=require("../services/metadata-service"),utils_1=require("../utils");class ExecutionContext{constructor(e){this.skedContext=e,this.contextData={},this.baseConfig={apiToken:e.auth.token,apiServer:e.auth.baseUrl}}static fromContext(e){return new ExecutionContext(e)}static fromCredentials({apiServer:e,apiToken:t}){const i={Authorization:`Bearer ${t}`,"sked-api-server":e},r=(0,function_utilities_1.createSkedContext)(i);return new ExecutionContext(r)}get logger(){return this._logger=this.lazyInit(this._logger,(()=>new logging_1.Logger))}get configHelper(){return this._configHelper=this.lazyInit(this._configHelper,(()=>new utils_1.ConfigHelper(this.skedContext.configVars)))}get graphqlClient(){return this._graphqlClient=this.lazyInit(this._graphqlClient,(()=>new graphql_client_1.GraphQLClient(this.baseConfig)))}get graphqlService(){return this._graphqlService=this.lazyInit(this._graphqlService,(()=>new graphql_1.GraphQLService(this.graphqlClient)))}newQueryBuilder(e){return new graphql_1.GraphQLQueryBuilder(e)}get metadataClient(){return this._metadataClient=this.lazyInit(this._metadataClient,(()=>new metadata_client_1.MetadataClient(this.baseConfig)))}get metadataService(){return this._metadataService=this.lazyInit(this._metadataService,(()=>new metadata_service_1.MetadataService(this.metadataClient)))}get configVarClient(){return this._configVarClient=this.lazyInit(this._configVarClient,(()=>new config_var_client_1.ConfigVarClient(this.baseConfig)))}get configVarCache(){if(!this._configVarCache){if(!this.configVarClient)throw new Error("ConfigVarClient is not initialized.");this._configVarCache=this.lazyInit(this._configVarCache,(()=>new cache_service_1.CacheService(new storage_1.ConfigVarCacheStorage(this.configVarClient))))}return this._configVarCache}get inMemoryCache(){return this._inMemoryCache||(this._inMemoryCache=this.lazyInit(this._inMemoryCache,(()=>new cache_service_1.CacheService(new storage_1.InMemoryCacheStorage))),this._inMemoryCache.setSecondaryCache(this.configVarCache)),this._inMemoryCache}dispose(){this._logger=void 0,this._configHelper=void 0,this._graphqlClient=void 0,this._graphqlService=void 0,this._metadataClient=void 0,this._metadataService=void 0,this._configVarClient=void 0,this._inMemoryCache=void 0}lazyInit(e,t){return null!=e?e:t()}}exports.ExecutionContext=ExecutionContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,n)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./execution-context"),exports);
|