@skedulo/pulse-solution-services 0.0.7 → 0.0.8
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/CHANGELOG.md +8 -0
- package/README.md +96 -23
- package/dist/clients/artifact-client.js +1 -1
- package/dist/clients/base-client.js +1 -1
- package/dist/clients/graphql-client.js +1 -1
- package/dist/constants/graphql-constants.js +1 -0
- package/dist/constants/index.js +1 -1
- package/dist/core/execution-context.js +1 -1
- package/dist/core/execution-options.js +1 -0
- package/dist/core/index.js +1 -1
- package/dist/core/request-context.js +1 -0
- package/dist/core/request-header-constants.js +1 -0
- package/dist/index.d.ts +240 -108
- package/dist/interfaces/api-client.js +1 -0
- package/dist/interfaces/index.js +1 -1
- package/dist/services/batch-processor/fetching-strategies/cursor-based-fetching-strategy.js +1 -1
- package/dist/services/batch-processor/fetching-strategies/date-based-fetching-strategy.js +1 -1
- package/dist/services/graph-batch/graph-batch-config.d.ts +34 -0
- package/dist/services/graph-batch/graph-batch-config.js +1 -0
- package/dist/services/graph-batch/graph-batch.d.ts +56 -0
- package/dist/services/graph-batch/graph-batch.js +1 -0
- package/dist/services/graph-batch/index.d.ts +3 -0
- package/dist/services/graph-batch/index.js +1 -0
- package/dist/services/graph-batch/pagination-strategy.d.ts +5 -0
- package/dist/services/graph-batch/pagination-strategy.js +1 -0
- package/dist/services/graphql/graphql-query-builder.d.ts +6 -4
- package/dist/services/graphql/graphql-query-builder.js +1 -1
- package/dist/services/graphql/graphql-service.d.ts +20 -13
- package/dist/services/graphql/graphql-service.js +1 -1
- package/dist/services/graphql/queries.d.ts +5 -4
- package/dist/services/graphql/queries.js +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/resource-availability/builder/data-service.d.ts +2 -1
- package/dist/services/resource-availability/builder/data-service.js +1 -1
- package/package.json +4 -2
- package/yarn.lock +23 -0
- package/dist/constants/tenant-objects.js +0 -1
- package/dist/services/data-service.js +0 -1
- package/dist/services/resource-availability/object-factory.d.ts +0 -13
- package/dist/services/resource-availability/object-factory.js +0 -1
- package/dist/services/resource-availability/resource-availability-service.d.ts +0 -7
- package/dist/services/resource-availability/resource-availability-service.js +0 -1
- package/dist/services/resource-availability/resource-builder.d.ts +0 -16
- package/dist/services/resource-availability/resource-builder.js +0 -1
- package/dist/services/resource-availability/resource-query-service.d.ts +0 -7
- package/dist/services/resource-availability/resource-query-service.js +0 -1
- package/dist/services/resource-availability/resource-validator.d.ts +0 -29
- package/dist/services/resource-availability/resource-validator.js +0 -1
- /package/dist/{interfaces/resource-availability.js → core/base-config.js} +0 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -47,14 +47,23 @@ yarn add @skedulo/pulse-solution-services
|
|
|
47
47
|
|
|
48
48
|
**From a function**
|
|
49
49
|
```javascript
|
|
50
|
-
const context = ExecutionContext.fromContext(skedToken
|
|
50
|
+
const context = ExecutionContext.fromContext(skedToken, {
|
|
51
|
+
requestSource: "my-cool-project",
|
|
52
|
+
userAgent: "my-cool-function"
|
|
53
|
+
} as ExecutionOptions);
|
|
51
54
|
```
|
|
55
|
+
|
|
56
|
+
The `requestSource` and `userAgent` options are important for observability and debugging, as they set the value for the `X-Skedulo-Source` and `User-Agent` headers that are automatically included in all requests made within this context.
|
|
57
|
+
|
|
52
58
|
**From other execution contexts**
|
|
53
59
|
```javascript
|
|
54
60
|
const context = ExecutionContext.fromCredentials({
|
|
55
61
|
apiServer: user.apiBasePath,
|
|
56
62
|
apiToken: user.accessToken,
|
|
57
|
-
}
|
|
63
|
+
}, {
|
|
64
|
+
requestSource: "my-cool-project",
|
|
65
|
+
userAgent: "my-cool-function"
|
|
66
|
+
} as ExecutionOptions);
|
|
58
67
|
```
|
|
59
68
|
Once initialized, the context object provides access to the various services detailed in subsequent sections.
|
|
60
69
|
### API Clients
|
|
@@ -95,7 +104,7 @@ const updatedVocabularyItem = await context.vocabularyClient.updateVocabularyIte
|
|
|
95
104
|
#### GraphQL Client
|
|
96
105
|
Executes GraphQL queries and mutations against `/graphql/graphql`.
|
|
97
106
|
```javascript
|
|
98
|
-
const queryResult = await context.graphqlClient.
|
|
107
|
+
const queryResult = await context.graphqlClient.execute(queryString, {readOnly: true});
|
|
99
108
|
```
|
|
100
109
|
|
|
101
110
|
#### Config Variable Client
|
|
@@ -378,12 +387,16 @@ await client.delete(
|
|
|
378
387
|
#### Query data
|
|
379
388
|
```javascript
|
|
380
389
|
// Create a query builder for the Resources object
|
|
381
|
-
const queryBuilder = context.newQueryBuilder(
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
390
|
+
const queryBuilder = context.newQueryBuilder({
|
|
391
|
+
objectName: 'Resources',
|
|
392
|
+
operationName: 'fetchJobWithJobAllocations',
|
|
393
|
+
readOnly: true
|
|
394
|
+
});
|
|
395
|
+
queryBuilder.withFields(['UID', 'Name'])
|
|
396
|
+
.withFilter('IsActive == true')
|
|
397
|
+
.withLimit(1)
|
|
398
|
+
.withOffset(1)
|
|
399
|
+
.withOrderBy('Name ASC');
|
|
387
400
|
// Add a child query for Job Allocations
|
|
388
401
|
queryBuilder.withChildQuery('JobAllocations')
|
|
389
402
|
.withFields(['UID', 'Name'])
|
|
@@ -401,6 +414,9 @@ console.log(queryResult.pageInfo.hasNextPage); // true
|
|
|
401
414
|
console.log(queryResult.endCursor); // Mg==
|
|
402
415
|
console.log(queryResult.endOffset); // 1
|
|
403
416
|
```
|
|
417
|
+
|
|
418
|
+
The `X-Graphql-Operation` header is added to all GraphQL requests and contains the value of `operationName`.
|
|
419
|
+
|
|
404
420
|
#### Update data
|
|
405
421
|
```javascript
|
|
406
422
|
const recordsToUpdate = queryResult.records.map((record) => {
|
|
@@ -409,8 +425,17 @@ const recordsToUpdate = queryResult.records.map((record) => {
|
|
|
409
425
|
Name: record.Name + " - Updated"
|
|
410
426
|
}
|
|
411
427
|
});
|
|
412
|
-
const updateResult = await context.graphqlService.
|
|
428
|
+
const updateResult = await context.graphqlService.mutate({
|
|
429
|
+
objectName: 'Resources',
|
|
430
|
+
operation: GraphqlOperations.UPDATE,
|
|
431
|
+
operationName: 'updateResources',
|
|
432
|
+
records: recordsToUpdate,
|
|
433
|
+
bulkOperation: true // optional
|
|
434
|
+
});
|
|
413
435
|
```
|
|
436
|
+
|
|
437
|
+
The `bulkOperation` and `readOnly` options help optimize large-scale mutations and read-heavy queries. When enabled, they automatically add the `X-Skedulo-Bulk-Operation` (for mutations) and `X-Skedulo-Read-Only` (for queries) headers to improve performance.
|
|
438
|
+
|
|
414
439
|
#### Pagination with offset
|
|
415
440
|
```javascript
|
|
416
441
|
while(queryResult.pageInfo.hasNextPage) {
|
|
@@ -462,7 +487,7 @@ The Resource Validator takes a list of resources and jobs, and determines which
|
|
|
462
487
|
```javascript
|
|
463
488
|
// Fetch jobs using GraphQL
|
|
464
489
|
const jobQueryResult = await context
|
|
465
|
-
.newQueryBuilder(
|
|
490
|
+
.newQueryBuilder({ objectName: "Jobs", operationName: "fetchJobs", readOnly: true })
|
|
466
491
|
.withLimit(2)
|
|
467
492
|
.withFields(TenantObjects.Jobs.Fields)
|
|
468
493
|
.execute();
|
|
@@ -578,25 +603,73 @@ if (suggestions) {
|
|
|
578
603
|
|
|
579
604
|
### Batch Service
|
|
580
605
|
The Batch Service offers a flexible and scalable solution for large-scale data processing.
|
|
606
|
+
|
|
607
|
+
#### How to Use
|
|
608
|
+
1. Create a subclass of GraphBatch that encapsulates the specific logic for your batch job.
|
|
609
|
+
2. Override the `start` method to return a configured GraphQLQueryBuilder object. This builder should set up the query fields, filters, and any required ordering.
|
|
610
|
+
3. Override the `execute` method to implement the logic to process each batch of records (e.g., updates, deletes, logging).
|
|
611
|
+
4. Optionally override the `finish` method to perform any final cleanup, such as logging the results or sending notifications.
|
|
612
|
+
5. Run the batch.
|
|
613
|
+
|
|
614
|
+
#### Example
|
|
615
|
+
Below is an example of bulk job update.
|
|
581
616
|
```javascript
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
617
|
+
import {
|
|
618
|
+
GraphBatch,
|
|
619
|
+
GraphqlOperations,
|
|
620
|
+
GraphQLQueryBuilder,
|
|
621
|
+
} from "@skedulo/pulse-solution-services";
|
|
622
|
+
|
|
623
|
+
export class BulkJobUpdate extends GraphBatch {
|
|
624
|
+
public result: string[] = [];
|
|
625
|
+
|
|
626
|
+
// This method is called once at the beginning of the batch process.
|
|
627
|
+
protected async start(): Promise<GraphQLQueryBuilder> {
|
|
628
|
+
const queryBuilder = this.context
|
|
629
|
+
.newQueryBuilder({objectName: "Jobs", operationName: "fetchJobsWithRegion"})
|
|
630
|
+
.withFields(["UID", "Name", "Start"])
|
|
631
|
+
.withOrderBy("Name ASC");
|
|
632
|
+
queryBuilder.withParentQuery("Region").withFields(["UID", "Name"]);
|
|
633
|
+
|
|
634
|
+
return queryBuilder;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// This method is called for each batch of records.
|
|
638
|
+
protected async execute(records: any[]): Promise<void> {
|
|
639
|
+
|
|
640
|
+
const recordsToUpdate = records.map((record) => ({
|
|
641
|
+
UID: record.UID,
|
|
642
|
+
Description: `${record.Name} scheduled for ${new Date(record.Start).toLocaleDateString("en-GB")} in ${record.Region.Name}`,
|
|
643
|
+
}));
|
|
644
|
+
await this.context.graphqlService.mutate({
|
|
645
|
+
objectName: "Jobs",
|
|
646
|
+
operation: GraphqlOperations.UPDATE,
|
|
647
|
+
operationName: "updateJobs",
|
|
648
|
+
records: recordsToUpdate
|
|
649
|
+
});
|
|
650
|
+
this.result.push(...records.map((record) => record.Name));
|
|
651
|
+
}
|
|
590
652
|
|
|
653
|
+
// This method is called once at the end of the batch process.
|
|
654
|
+
protected async finish(): Promise<void> {
|
|
655
|
+
this.context.logger.info(`Processed ${this.result.length} records.`);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
```
|
|
659
|
+
|
|
660
|
+
Run the batch
|
|
661
|
+
```javascript
|
|
591
662
|
const context = ExecutionContext.fromCredentials({
|
|
592
663
|
apiServer: user.apiBasePath,
|
|
593
664
|
apiToken: user.user.accessToken,
|
|
594
665
|
});
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
666
|
+
const batch = new BulkJobUpdate(context, {
|
|
667
|
+
batchSize: 10,
|
|
668
|
+
maxBatches: 10,
|
|
669
|
+
strategy: PaginationStrategy.CURSOR,
|
|
670
|
+
delaySeconds: 1,
|
|
598
671
|
});
|
|
599
|
-
await
|
|
672
|
+
await batch.run();
|
|
600
673
|
```
|
|
601
674
|
|
|
602
675
|
### Cache Service
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,i,n){return new(i||(i=Promise))((function(o,r){function s(t){try{d(n.next(t))}catch(t){r(t)}}function a(t){try{d(n.throw(t))}catch(t){r(t)}}function d(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}d((n=n.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ArtifactClient=void 0;const constants_1=require("../constants"),base_client_1=require("./base-client");class ArtifactClient extends base_client_1.BaseClient{constructor(t,e){super(t),this.artifactType=e,this.baseEndpoint=`artifacts/${this.artifactType}`}list(){return __awaiter(this,void 0,void 0,(function*(){return this.performRequest({endpoint:this.baseEndpoint})}))}get(){return __awaiter(this,arguments,void 0,(function*(t={}){return this.performRequest({endpoint:this.buildEndpoint(t)})}))}create(t,e){return __awaiter(this,void 0,void 0,(function*(){return this.performRequest({method:constants_1.HttpMethod.POST,endpoint:this.buildEndpoint(t),body:e})}))}update(t,e){return __awaiter(this,void 0,void 0,(function*(){return this.performRequest({method:constants_1.HttpMethod.PUT,endpoint:this.buildEndpoint(t),body:e})}))}delete(t){return __awaiter(this,void 0,void 0,(function*(){yield this.performRequest({method:constants_1.HttpMethod.DELETE,endpoint:this.buildEndpoint(t)})}))}buildEndpoint(t){const{objectName:e,viewTypeName:i,name:n,scope:o}=t;let r=this.baseEndpoint;return e&&(r+=`/${e}`),i&&(r+=`/${i}`),n&&(r+=`/${n}`),o&&(r+=`/${o}`),r}}exports.ArtifactClient=ArtifactClient;
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,i,n){return new(i||(i=Promise))((function(o,r){function s(t){try{d(n.next(t))}catch(t){r(t)}}function a(t){try{d(n.throw(t))}catch(t){r(t)}}function d(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}d((n=n.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ArtifactClient=void 0;const constants_1=require("../constants"),base_client_1=require("./base-client");class ArtifactClient extends base_client_1.BaseClient{constructor(t,e,i={}){super(t,i),this.artifactType=e,this.baseEndpoint=`artifacts/${this.artifactType}`}list(){return __awaiter(this,void 0,void 0,(function*(){return this.performRequest({endpoint:this.baseEndpoint})}))}get(){return __awaiter(this,arguments,void 0,(function*(t={}){return this.performRequest({endpoint:this.buildEndpoint(t)})}))}create(t,e){return __awaiter(this,void 0,void 0,(function*(){return this.performRequest({method:constants_1.HttpMethod.POST,endpoint:this.buildEndpoint(t),body:e})}))}update(t,e){return __awaiter(this,void 0,void 0,(function*(){return this.performRequest({method:constants_1.HttpMethod.PUT,endpoint:this.buildEndpoint(t),body:e})}))}delete(t){return __awaiter(this,void 0,void 0,(function*(){yield this.performRequest({method:constants_1.HttpMethod.DELETE,endpoint:this.buildEndpoint(t)})}))}buildEndpoint(t){const{objectName:e,viewTypeName:i,name:n,scope:o}=t;let r=this.baseEndpoint;return e&&(r+=`/${e}`),i&&(r+=`/${i}`),n&&(r+=`/${n}`),o&&(r+=`/${o}`),r}}exports.ArtifactClient=ArtifactClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __decorate=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,
|
|
1
|
+
"use strict";var __decorate=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},__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,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseClient=void 0;const request_header_constants_1=require("../core/request-header-constants"),logging_1=require("../logging");class BaseClient{constructor(e,t={}){this.config=e,this.executionOptions=t}performRequest(e){return __awaiter(this,arguments,void 0,(function*({method:e="GET",endpoint:t,headers:n={},body:r,queryParams:o},i=this.executionOptions){try{const s=Object.assign(Object.assign({},this.getHeaders(i)),n),a=this.buildUrl(t,o),c=yield fetch(a,{method:e,headers:s,body:r&&"GET"!==e?JSON.stringify(r):void 0});let u;const d=c.headers.get("content-type");if(d&&d.includes("application/json")?(u=yield c.json(),u.result&&(u=u.result)):u=yield c.text(),!c.ok)throw new Error(`HTTP error! Status: ${c.status}. Response: ${JSON.stringify(u)}`);return u}catch(e){throw this.handleException(e),e}}))}getHeaders(e){var t,n;const r={Authorization:`Bearer ${this.config.apiToken}`,"Content-Type":"application/json"},o=e.requestSource||(null===(t=this.executionOptions)||void 0===t?void 0:t.requestSource),i=e.userAgent||(null===(n=this.executionOptions)||void 0===n?void 0:n.userAgent);return o&&(r[request_header_constants_1.REQUEST_HEADERS.X_SKEDULO_SOURCE]=o),i&&(r[request_header_constants_1.REQUEST_HEADERS.USER_AGENT]=i),r}buildUrl(e,t){const n=new URL(`${this.config.apiServer}/${e}`);return t&&Object.entries(t).forEach((([e,t])=>{n.searchParams.append(e,t)})),n.toString()}handleException(e){}}exports.BaseClient=BaseClient,__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[Object,Object]),__metadata("design:returntype",Promise)],BaseClient.prototype,"performRequest",null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,n,
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(i,s){function a(t){try{c(r.next(t))}catch(t){s(t)}}function o(t){try{c(r.throw(t))}catch(t){s(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(a,o)}c((r=r.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,arguments,void 0,(function*(t,e={}){return yield this.performRequest({method:http_1.HttpMethod.POST,endpoint:constants_1.TENANT_ENDPOINTS.GRAPHQL,body:{query:t},headers:e})}))}}exports.GraphQLClient=GraphQLClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var GraphqlOperations;Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphqlOperations=void 0,function(e){e.INSERT="insert",e.UPDATE="update",e.DELETE="delete",e.UPSERT="upsert"}(GraphqlOperations||(exports.GraphqlOperations=GraphqlOperations={}));
|
package/dist/constants/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(t,e,r,o){void 0===o&&(o=r);var
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(t,e,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(e,r);n&&!("get"in n?!e.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,o,n)}:function(t,e,r,o){void 0===o&&(o=r),t[o]=e[r]}),__exportStar=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||__createBinding(e,t,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./artifact-constants"),exports),__exportStar(require("./config-var-constants"),exports),__exportStar(require("./graphql-constants"),exports),__exportStar(require("./http"),exports),__exportStar(require("./mobile-notification-constants"),exports),__exportStar(require("./tenant-endpoints"),exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ExecutionContext=void 0;const function_utilities_1=require("@skedulo/function-utilities"),artifact_client_1=require("../clients/artifact-client"),availability_api_client_1=require("../clients/availability-api-client"),config_features_client_1=require("../clients/config-features-client"),config_template_client_1=require("../clients/config-template-client"),config_var_client_1=require("../clients/config-var-client"),geo_api_client_1=require("../clients/geo-api-client"),graphql_client_1=require("../clients/graphql-client"),metadata_client_1=require("../clients/metadata-client"),mobile_notification_client_1=require("../clients/mobile-notification-client"),org_preference_client_1=require("../clients/org-preference-client"),vocabulary_client_1=require("../clients/vocabulary-client"),logger_1=__importDefault(require("../logging/logger")),cache_service_1=require("../services/cache/cache-service"),storage_1=require("../services/cache/storage"),geoservice_1=require("../services/geoservice"),graphql_1=require("../services/graphql"),metadata_service_1=require("../services/metadata-service"),data_service_1=require("../services/resource-availability/builder/data-service"),resource_availability_service_1=require("../services/resource-availability/builder/resource-availability-service"),resource_builder_1=require("../services/resource-availability/builder/resource-builder"),utils_1=require("../utils");class ExecutionContext{constructor(e){this.logger=logger_1.default,this.services=new Map,this.skedContext=e,this.contextData={},this.baseConfig={apiToken:e.auth.token,apiServer:e.auth.baseUrl}}static fromContext(e){return new ExecutionContext(e)}static fromCredentials(e){const
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ExecutionContext=void 0;const function_utilities_1=require("@skedulo/function-utilities"),clients_1=require("../clients"),artifact_client_1=require("../clients/artifact-client"),availability_api_client_1=require("../clients/availability-api-client"),config_features_client_1=require("../clients/config-features-client"),config_template_client_1=require("../clients/config-template-client"),config_var_client_1=require("../clients/config-var-client"),geo_api_client_1=require("../clients/geo-api-client"),graphql_client_1=require("../clients/graphql-client"),metadata_client_1=require("../clients/metadata-client"),mobile_notification_client_1=require("../clients/mobile-notification-client"),org_preference_client_1=require("../clients/org-preference-client"),vocabulary_client_1=require("../clients/vocabulary-client"),logger_1=__importDefault(require("../logging/logger")),cache_service_1=require("../services/cache/cache-service"),storage_1=require("../services/cache/storage"),geoservice_1=require("../services/geoservice"),graphql_1=require("../services/graphql"),metadata_service_1=require("../services/metadata-service"),data_service_1=require("../services/resource-availability/builder/data-service"),resource_availability_service_1=require("../services/resource-availability/builder/resource-availability-service"),resource_builder_1=require("../services/resource-availability/builder/resource-builder"),utils_1=require("../utils"),request_header_constants_1=require("./request-header-constants");class ExecutionContext{constructor(e,i={}){this.logger=logger_1.default,this.services=new Map,this.skedContext=e,this.contextData={},this._executionOptions=i,this.baseConfig={apiToken:e.auth.token,apiServer:e.auth.baseUrl}}static fromContext(e,i={}){return new ExecutionContext(e,i)}static fromCredentials(e,i={}){const t={Authorization:`Bearer ${e.apiToken}`,[request_header_constants_1.REQUEST_HEADERS.SKED_API_SERVER]:e.apiServer},r=(0,function_utilities_1.createSkedContext)(t),n=new ExecutionContext(r,i);return n.baseConfig=Object.assign(Object.assign({},e),n.baseConfig),n}set executionOptions(e){this._executionOptions=Object.assign(Object.assign({},this._executionOptions),e)}get executionOptions(){return this._executionOptions}getOrCreateService(e,i){return this.services.has(e)||this.services.set(e,i()),this.services.get(e)}get configHelper(){return this.getOrCreateService("configHelper",(()=>new utils_1.ConfigHelper(this.skedContext.configVars)))}get baseClient(){return this.getOrCreateService("baseClient",(()=>new clients_1.BaseClient(this.baseConfig,this.executionOptions)))}get graphqlClient(){return this.getOrCreateService("graphqlClient",(()=>new graphql_client_1.GraphQLClient(this.baseConfig,this.executionOptions)))}get graphqlService(){return this.getOrCreateService("graphqlService",(()=>new graphql_1.GraphQLService(this.graphqlClient)))}get metadataClient(){return this.getOrCreateService("metadataClient",(()=>new metadata_client_1.MetadataClient(this.baseConfig,this.executionOptions)))}get metadataService(){return this.getOrCreateService("metadataService",(()=>new metadata_service_1.MetadataService(this.metadataClient)))}get vocabularyClient(){return this.getOrCreateService("vocabularyClient",(()=>new vocabulary_client_1.VocabularyClient(this.baseConfig,this.executionOptions)))}get orgPreferencesClient(){return this.getOrCreateService("orgPreferencesClient",(()=>new org_preference_client_1.OrgPreferenceClient(this.baseConfig,this.executionOptions)))}get configTemplateClient(){return this.getOrCreateService("configTemplateClient",(()=>new config_template_client_1.ConfigTemplateClient(this.baseConfig,this.executionOptions)))}get configFeaturesClient(){return this.getOrCreateService("configFeaturesClient",(()=>new config_features_client_1.ConfigFeaturesClient(this.baseConfig,this.executionOptions)))}get configVarClient(){return this.getOrCreateService("configVarClient",(()=>new config_var_client_1.ConfigVarClient(this.baseConfig,this.executionOptions)))}get mobileNotificationClient(){return this.getOrCreateService("mobileNotificationClient",(()=>new mobile_notification_client_1.MobileNotificationClient(this.baseConfig,this.executionOptions)))}get geoAPIClient(){return this.getOrCreateService("geoAPIClient",(()=>new geo_api_client_1.GeoAPIClient(this.baseConfig,this.executionOptions)))}get availabilityAPIClient(){return this.getOrCreateService("availabilityAPIClient",(()=>new availability_api_client_1.AvailabilityAPIClient(this.baseConfig,this.executionOptions)))}get geoService(){return this.getOrCreateService("geoService",(()=>new geoservice_1.GeoService(this.geoAPIClient)))}get configVarCache(){return this.getOrCreateService("configVarCache",(()=>new cache_service_1.CacheService(new storage_1.ConfigVarCacheStorage(this.configVarClient))))}get inMemoryCache(){return this.getOrCreateService("inMemoryCache",(()=>{const e=new cache_service_1.CacheService(new storage_1.InMemoryCacheStorage);return e.setSecondaryCache(this.configVarCache),e}))}get resourceAvailabilityService(){return this.getOrCreateService("resourceAvailabilityService",(()=>new resource_availability_service_1.ResourceAvailabilityService(this.availabilityAPIClient)))}get dataService(){return this.getOrCreateService("dataService",(()=>new data_service_1.DataService(this.graphqlService)))}get resourceBuilder(){return this.getOrCreateService("resourceBuilder",(()=>new resource_builder_1.ResourceBuilder(this.dataService,this.resourceAvailabilityService)))}newQueryBuilder(e){const i=new graphql_1.GraphQLQueryBuilder(e);return i.setGraphqlService(this.graphqlService),i}newArtifactClient(e){return this.getOrCreateService(`${e}Client`,(()=>new artifact_client_1.ArtifactClient(this.baseConfig,e,this.executionOptions)))}dispose(){this.services.clear()}}exports.ExecutionContext=ExecutionContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ExecutionOptions=void 0;class ExecutionOptions{constructor(t){this.requestSource="",this.userAgent="",t&&Object.assign(this,t)}}exports.ExecutionOptions=ExecutionOptions;
|
package/dist/core/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,
|
|
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("./entity-factory"),exports),__exportStar(require("./execution-context"),exports),__exportStar(require("./request-header-constants"),exports),__exportStar(require("./tenant-entities"),exports),__exportStar(require("./tenant-objects"),exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.RequestContext=void 0;class RequestContext{constructor(e){this.bulkOperation=!1,this.readOnly=!1,this.additionalHeaders={},e&&Object.assign(this,e)}}exports.RequestContext=RequestContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.REQUEST_HEADERS=void 0,exports.REQUEST_HEADERS={X_SKEDULO_BULK_OPERATION:"X-Skedulo-Bulk-Operation",X_SKEDULO_READ_ONLY:"X-Skedulo-Read-Only",X_SKEDULO_SOURCE:"X-Skedulo-Source",X_GRAPHQL_OPERATION:"X-Graphql-Operation",SKED_FUNCTION_EXECUTION_TYPE:"Sked-Function-Execution-Type",SKED_API_SERVER:"sked-api-server",USER_AGENT:"User-Agent"};
|