@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
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ExecutionContext } from "../../core";
|
|
2
|
+
import { BatchOrchestratorConfig } from "./interfaces";
|
|
3
|
+
export declare class BatchOrchestrator {
|
|
4
|
+
protected context: ExecutionContext;
|
|
5
|
+
protected config: BatchOrchestratorConfig;
|
|
6
|
+
constructor(context: ExecutionContext, config?: BatchOrchestratorConfig);
|
|
7
|
+
processBatchJob(): Promise<void>;
|
|
8
|
+
protected validateJob(): void;
|
|
9
|
+
protected prepareData(): Promise<void>;
|
|
10
|
+
protected sendWorkerStateToCallbackUrl(): Promise<void>;
|
|
11
|
+
protected getWorkerState(): object;
|
|
12
|
+
protected delay(ms: number): Promise<void>;
|
|
13
|
+
protected processWorker(): Promise<void>;
|
|
14
|
+
protected processNextBatch(): Promise<void>;
|
|
15
|
+
protected postProcess(): Promise<void>;
|
|
16
|
+
protected updateJobStatus(): Promise<void>;
|
|
17
|
+
private isCompleted;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __decorate=this&&this.__decorate||function(t,e,o,a){var n,s=arguments.length,c=s<3?e:null===a?a=Object.getOwnPropertyDescriptor(e,o):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(t,e,o,a);else for(var r=t.length-1;r>=0;r--)(n=t[r])&&(c=(s<3?n(c):s>3?n(e,o,c):n(e,o))||c);return s>3&&c&&Object.defineProperty(e,o,c),c},__metadata=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},__awaiter=this&&this.__awaiter||function(t,e,o,a){return new(o||(o=Promise))((function(n,s){function c(t){try{i(a.next(t))}catch(t){s(t)}}function r(t){try{i(a.throw(t))}catch(t){s(t)}}function i(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(c,r)}i((a=a.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BatchOrchestrator=void 0;const logging_1=require("../../logging"),constants_1=require("./constants"),fetching_strategies_1=require("./fetching-strategies"),workers_1=require("./workers");class BatchOrchestrator{constructor(t,e={isAsyncProcessing:!0}){this.context=t,this.config=e}processBatchJob(){return __awaiter(this,void 0,void 0,(function*(){this.validateJob(),yield this.prepareData(),yield this.processWorker(),yield this.updateJobStatus(),yield this.postProcess()}))}validateJob(){if(!this.context.contextData.job.JobType)throw new Error("JobType is missing in the job configuration.");if(this.context.contextData.job.Status===constants_1.JobStatus.FAILED)throw new Error("Cannot process a failed job.")}prepareData(){return __awaiter(this,void 0,void 0,(function*(){if(this.context.logger.info("Preparing data for the worker"),this.context.contextData.job.CreatedDate||(this.context.contextData.job.CreatedDate=(new Date).toISOString()),this.context.contextData.job.ObjectName){const t=this.context.contextData.job.FetchingStrategy||constants_1.DataFetchingStrategy.DATE_BASED;this.context.contextData.records=yield fetching_strategies_1.FetchingStrategyFactory.getStrategy(t).execute(this.context)}else this.context.logger.info("No input data required for the worker")}))}sendWorkerStateToCallbackUrl(){return __awaiter(this,void 0,void 0,(function*(){this.context.contextData.job.CallbackURL&&(yield fetch(this.context.contextData.job.CallbackURL,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.context.skedContext.auth.token}`},body:JSON.stringify(this.getWorkerState())}))}))}getWorkerState(){var t;return{context:{jobId:this.context.contextData.job.UID,status:this.context.contextData.job.Status},data:this.context.contextData.records,state:null===(t=this.context.contextData.batchState)||void 0===t?void 0:t.worker}}delay(t){return __awaiter(this,void 0,void 0,(function*(){return new Promise((e=>setTimeout(e,t)))}))}processWorker(){return __awaiter(this,void 0,void 0,(function*(){this.context.logger.info("Processing with worker");const t=workers_1.WorkerFactory.getWorker(this.context.contextData.job.JobType),e=this.getWorkerState(),o=yield t.process(this.context,e);this.context.contextData.batchState&&(this.context.contextData.batchState.worker=o),this.context.contextData.job.ProcessedBatches=(this.context.contextData.job.ProcessedBatches||0)+1}))}processNextBatch(){return __awaiter(this,void 0,void 0,(function*(){this.config.isAsyncProcessing?this.processBatchJob():yield this.processBatchJob()}))}postProcess(){return __awaiter(this,void 0,void 0,(function*(){this.context.contextData.job.Status!==constants_1.JobStatus.COMPLETED?(this.context.logger.info("Process next batch"),this.context.contextData.job.DelaySeconds>0&&(yield this.delay(1e3*this.context.contextData.job.DelaySeconds)),yield this.processNextBatch()):this.context.contextData.job.CallbackURL&&(this.context.logger.info("Sending worker state to callback URL"),yield this.sendWorkerStateToCallbackUrl())}))}updateJobStatus(){return __awaiter(this,void 0,void 0,(function*(){this.isCompleted()?(this.context.contextData.job.Status=constants_1.JobStatus.COMPLETED,this.context.contextData.job.CompletedAt=(new Date).toISOString()):this.context.contextData.job.Status===constants_1.JobStatus.QUEUED&&(this.context.contextData.job.Status=constants_1.JobStatus.PROCESSING,this.context.contextData.job.ProcessingAt=(new Date).toISOString())}))}isCompleted(){const t=this.context.contextData.job.ProcessedBatches>=this.context.contextData.job.MaximumBatches,e=!this.context.contextData.records||0===this.context.contextData.records.length,o=this.context.contextData.job.JobType===constants_1.JobType.CUSTOM;return t||!o&&e}}exports.BatchOrchestrator=BatchOrchestrator,__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",Promise)],BatchOrchestrator.prototype,"processBatchJob",null);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const JobStatus: {
|
|
2
|
+
PROCESSING: string;
|
|
3
|
+
QUEUED: string;
|
|
4
|
+
ABORTED: string;
|
|
5
|
+
COMPLETED: string;
|
|
6
|
+
FAILED: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const JobType: {
|
|
9
|
+
DELETE: string;
|
|
10
|
+
UPDATE: string;
|
|
11
|
+
CUSTOM: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const BATCH_JOBS = "BatchJobs";
|
|
14
|
+
export declare const ConfigVars: {
|
|
15
|
+
FAILURE_THRESHOLD: string;
|
|
16
|
+
MAX_CONCURRENT_JOBS: string;
|
|
17
|
+
BATCH_PROCESSOR_URL: string;
|
|
18
|
+
};
|
|
19
|
+
export declare const DataFetchingStrategy: {
|
|
20
|
+
CURSOR_BASED: string;
|
|
21
|
+
DATE_BASED: string;
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataFetchingStrategy=exports.ConfigVars=exports.BATCH_JOBS=exports.JobType=exports.JobStatus=void 0,exports.JobStatus={PROCESSING:"Processing",QUEUED:"Queued",ABORTED:"Aborted",COMPLETED:"Completed",FAILED:"Failed"},exports.JobType={DELETE:"Delete",UPDATE:"Update",CUSTOM:"Custom"},exports.BATCH_JOBS="BatchJobs",exports.ConfigVars={FAILURE_THRESHOLD:"FAILURE_THRESHOLD",MAX_CONCURRENT_JOBS:"MAX_CONCURRENT_JOBS",BATCH_PROCESSOR_URL:"BATCH_PROCESSOR_URL"},exports.DataFetchingStrategy={CURSOR_BASED:"CursorBased",DATE_BASED:"DateBased"};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(a,c){function i(t){try{u(r.next(t))}catch(t){c(t)}}function o(t){try{u(r.throw(t))}catch(t){c(t)}}function u(t){var e;t.done?a(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,o)}u((r=r.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BatchNumberFetchingStrategy=void 0,exports.BatchNumberFetchingStrategy={execute(t){return __awaiter(this,void 0,void 0,(function*(){return[{UID:t.contextData.job.ProcessedBatches}]}))}};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExecutionContext } from "../../../core/execution-context";
|
|
2
|
+
export declare const CursorBasedFetchingStrategy: {
|
|
3
|
+
/**
|
|
4
|
+
* Fetches the next dataset to process based on the job's configuration.
|
|
5
|
+
* Uses cursor if it is not empty; otherwise, fetches the first batch of records.
|
|
6
|
+
*/
|
|
7
|
+
execute(context: ExecutionContext): Promise<import("../../../interfaces/graphql").HasId[]>;
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,o,r){return new(o||(o=Promise))((function(a,n){function i(t){try{s(r.next(t))}catch(t){n(t)}}function c(t){try{s(r.throw(t))}catch(t){n(t)}}function s(t){var e;t.done?a(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(i,c)}s((r=r.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CursorBasedFetchingStrategy=void 0,exports.CursorBasedFetchingStrategy={execute(t){return __awaiter(this,void 0,void 0,(function*(){var e,o,r,a,n,i;const c=t.contextData.job.BatchSize||200,s=(t.contextData.job.Fields||"UID").split(",").map((t=>t.trim()));s.includes("UID")||s.push("UID");t.contextData.job.ObjectName,t.contextData.job.OrderBy,null===(o=null===(e=t.contextData.batchState)||void 0===e?void 0:e.processor)||void 0===o||o.cursor,t.contextData.job.FilterCondition,s.join("\n");const u=t.newQueryBuilder(t.contextData.job.objectName);u.withFields(s).withLimit(c).withOrderBy(t.contextData.job.OrderBy).withFilter(t.contextData.job.FilterCondition);const d=yield t.graphqlService.query(u.build()),l=d.records,h=d.endCursor;return null===(n=null===(a=null===(r=t.contextData.batchState)||void 0===r?void 0:r.processor)||void 0===a?void 0:a.allCursors)||void 0===n||n.push(h),(null===(i=t.contextData.batchState)||void 0===i?void 0:i.processor)&&(t.contextData.batchState.processor.cursor=h),l}))}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,i,r){return new(i||(i=Promise))((function(n,a){function o(e){try{s(r.next(e))}catch(e){a(e)}}function c(e){try{s(r.throw(e))}catch(e){a(e)}}function s(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,c)}s((r=r.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DateBasedFetchingStrategy=void 0,exports.DateBasedFetchingStrategy={execute(e){return __awaiter(this,void 0,void 0,(function*(){const t=e.contextData.job;let i=`LastModifiedDate <= ${t.CreatedDate} `;t.FilterCondition&&(i+=` AND ${t.FilterCondition}`);const r=t.OrderBy||"CreatedDate ASC",n=t.BatchSize||10,a=(t.Fields||"UID").split(",").map((e=>e.trim()));return(yield e.graphqlService.query({objectName:t.ObjectName,first:n,filter:i,orderBy:r,fields:a.join("\n")})).records}))}};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class FetchingStrategyFactory {
|
|
2
|
+
static getStrategy(strategy: string): {
|
|
3
|
+
execute(context: import("../../..").ExecutionContext): Promise<{
|
|
4
|
+
UID: any;
|
|
5
|
+
}[]>;
|
|
6
|
+
} | {
|
|
7
|
+
execute(context: import("../../..").ExecutionContext): Promise<import("../../..").HasId[]>;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FetchingStrategyFactory=void 0;const constants_1=require("../constants"),batch_number_fetching_strategy_1=require("./batch-number-fetching-strategy"),cursor_based_fetching_strategy_1=require("./cursor-based-fetching-strategy"),date_based_fetching_strategy_1=require("./date-based-fetching-strategy");class FetchingStrategyFactory{static getStrategy(t){switch(t){case constants_1.DataFetchingStrategy.CURSOR_BASED:return cursor_based_fetching_strategy_1.CursorBasedFetchingStrategy;case constants_1.DataFetchingStrategy.DATE_BASED:return date_based_fetching_strategy_1.DateBasedFetchingStrategy;default:return batch_number_fetching_strategy_1.BatchNumberFetchingStrategy}}}exports.FetchingStrategyFactory=FetchingStrategyFactory;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./fetching-strategy-factory";
|
|
@@ -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("./fetching-strategy-factory"),exports);
|
|
@@ -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("./batch-orchestrator"),exports),__exportStar(require("./interfaces"),exports);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { HasId } from "../../interfaces/graphql";
|
|
2
|
+
export interface BatchJobSchemaData extends HasId {
|
|
3
|
+
StatusDetails?: string;
|
|
4
|
+
MaximumBatches?: number;
|
|
5
|
+
Status?: string;
|
|
6
|
+
ProcessedBatches?: number;
|
|
7
|
+
ObjectName?: string;
|
|
8
|
+
JobType?: string;
|
|
9
|
+
BatchProcessor?: string;
|
|
10
|
+
CreatedDate?: string;
|
|
11
|
+
FilterCondition?: string;
|
|
12
|
+
OrderBy?: string;
|
|
13
|
+
Fields?: string;
|
|
14
|
+
JobHandler?: string;
|
|
15
|
+
State?: string;
|
|
16
|
+
DelaySeconds?: number;
|
|
17
|
+
CallbackURL?: string;
|
|
18
|
+
ProcessingAt?: string;
|
|
19
|
+
CompletedAt?: string;
|
|
20
|
+
FailedBatches?: number;
|
|
21
|
+
FetchingStrategy?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface BatchOrchestratorConfig {
|
|
24
|
+
isAsyncProcessing?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface BatchState {
|
|
27
|
+
processor?: {
|
|
28
|
+
cursor?: string;
|
|
29
|
+
allCursors?: string[];
|
|
30
|
+
batchNumber?: number;
|
|
31
|
+
};
|
|
32
|
+
worker?: any;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,o,r){return new(o||(o=Promise))((function(n,a){function i(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(i,s)}u((r=r.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomWorker=void 0;class CustomWorker{process(t,e){return __awaiter(this,void 0,void 0,(function*(){const{job:o}=t.contextData;if(o.JobHandler&&o.JobHandler.startsWith("http")){let r=yield fetch(o.JobHandler,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.skedContext.auth.token}`},body:JSON.stringify(e)});if(!r.ok)throw new Error(`Failed to process job: ${r.status} ${r.statusText}`);return yield r.json()}throw new Error("JobHandler is not a valid URL")}))}}exports.CustomWorker=CustomWorker;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,c){function i(e){try{s(n.next(e))}catch(e){c(e)}}function a(e){try{s(n.throw(e))}catch(e){c(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}s((n=n.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DeleteWorker=void 0;class DeleteWorker{process(e){return __awaiter(this,void 0,void 0,(function*(){const{job:t,records:r}=e.contextData;if(r&&0!==r.length)return console.log(`Deleting ${r.length} ${t.ObjectName}...`),e.graphqlService.delete(t.ObjectName,r)}))}}exports.DeleteWorker=DeleteWorker;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,i){void 0===i&&(i=t);var o=Object.getOwnPropertyDescriptor(r,t);o&&!("get"in o?!r.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,i,o)}:function(e,r,t,i){void 0===i&&(i=t),e[i]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./worker-factory"),exports),__exportStar(require("./worker-interfaces"),exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,n,o,r){return new(o||(o=Promise))((function(e,a){function i(t){try{c(r.next(t))}catch(t){a(t)}}function s(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(t){t(n)}))).then(i,s)}c((r=r.apply(t,n||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.UpdateWorker=void 0;class UpdateWorker{process(t){return __awaiter(this,void 0,void 0,(function*(){const{job:n,records:o}=t.contextData,{JobHandler:r}=n,e=r;let a={};for(const t of o){const o=applyTransformation(t,e);if(isFlatObject(o)){const t=n.ObjectName;a[t]||(a[t]=[]),a[t].push(o)}else for(const t in o){a[t]||(a[t]=[]);const n=o[t];Array.isArray(n)?a[t].push(...n):a[t].push(n)}}for(const n in a)a[n]&&0!==a[n].length&&(console.log(`Updating ${a[n].length} ${n}...`),yield t.graphqlService.update(n,a[n]))}))}}function applyTransformation(input,transformFunction){const transformData=eval(transformFunction);return transformData(input)}function isFlatObject(t){for(const n in t)if("object"==typeof t[n]&&null!==t[n])return!1;return!0}exports.UpdateWorker=UpdateWorker;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CustomWorker } from "./custom-worker";
|
|
2
|
+
import { DeleteWorker } from "./delete-worker";
|
|
3
|
+
import { UpdateWorker } from "./update-worker";
|
|
4
|
+
export declare class WorkerFactory {
|
|
5
|
+
static getWorker(jobType: string): CustomWorker | DeleteWorker | UpdateWorker;
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.WorkerFactory=void 0;const constants_1=require("../constants"),custom_worker_1=require("./custom-worker"),delete_worker_1=require("./delete-worker"),update_worker_1=require("./update-worker");class WorkerFactory{static getWorker(e){switch(e){case constants_1.JobType.DELETE:return new delete_worker_1.DeleteWorker;case constants_1.JobType.UPDATE:return new update_worker_1.UpdateWorker;case constants_1.JobType.CUSTOM:return new custom_worker_1.CustomWorker;default:throw new Error(`Unsupported JobType: ${e}`)}}}exports.WorkerFactory=WorkerFactory;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export declare class CacheService<T> {
|
|
2
|
+
private storage;
|
|
3
|
+
private secondaryCache?;
|
|
4
|
+
/**
|
|
5
|
+
* Creates an instance of CacheService.
|
|
6
|
+
* @param {CacheStorage<string>} storage - The cache storage implementation.
|
|
7
|
+
*/
|
|
8
|
+
constructor(storage: CacheStorage<string>);
|
|
9
|
+
/**
|
|
10
|
+
* Sets a secondary cache service to use as a fallback.
|
|
11
|
+
* @param {CacheService<T>} secondaryCache - The secondary cache service.
|
|
12
|
+
* @returns {void}
|
|
13
|
+
*/
|
|
14
|
+
setSecondaryCache(secondaryCache: CacheService<T>): void;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves a cached value by key.
|
|
17
|
+
* If the value is not found, it attempts to retrieve it from a secondary service or loader.
|
|
18
|
+
* @param {string} key - The cache key.
|
|
19
|
+
* @param {object} options - Optional parameters.
|
|
20
|
+
* @param {CacheLoader<T>} [options.loader] - A function to load the value if not cached.
|
|
21
|
+
* @param {boolean} [options.useSecondaryCache] - Whether to use the secondary cache service.
|
|
22
|
+
* @returns {Promise<T | null>} - The cached value or null if not found or expired.
|
|
23
|
+
*/
|
|
24
|
+
get(key: string, options?: CacheOptions<T>): Promise<T | null>;
|
|
25
|
+
/**
|
|
26
|
+
* Stores a value in the cache with an optional TTL.
|
|
27
|
+
* @param {string} key - The cache key.
|
|
28
|
+
* @param {T} value - The value to store.
|
|
29
|
+
* @param {object} options - Optional parameters.
|
|
30
|
+
* @returns {Promise<void>}
|
|
31
|
+
*/
|
|
32
|
+
set(key: string, value: T, options?: CacheOptions<T>): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Deletes a specific key from the cache.
|
|
35
|
+
* @param {string} key - The cache key to delete.
|
|
36
|
+
* @returns {Promise<void>}
|
|
37
|
+
*/
|
|
38
|
+
delete(key: string): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Clears all cache entries.
|
|
41
|
+
* @returns {Promise<void>}
|
|
42
|
+
*/
|
|
43
|
+
clear(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Adds the cache key prefix to a key if it is not already present.
|
|
46
|
+
* @param {string} key - The cache key.
|
|
47
|
+
* @returns {string} - The key with the prefix
|
|
48
|
+
*/
|
|
49
|
+
addPrefix(key: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Deserializes the cached metadata and returns the original value in the correct type.
|
|
52
|
+
* @param {any} metadata - The cached metadata object.
|
|
53
|
+
* @returns {T} - The deserialized value.
|
|
54
|
+
*/
|
|
55
|
+
private deserialize;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Interface for cache storage.
|
|
59
|
+
* This defines the basic storage operations without loader logic.
|
|
60
|
+
*/
|
|
61
|
+
export interface CacheStorage<T = any> {
|
|
62
|
+
set(key: string, value: T): Promise<void>;
|
|
63
|
+
get(key: string): Promise<T | null>;
|
|
64
|
+
delete(key: string): Promise<void>;
|
|
65
|
+
clear(): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
export interface CacheOptions<T> {
|
|
68
|
+
ttl?: number;
|
|
69
|
+
useSecondaryCache?: boolean;
|
|
70
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __decorate=this&&this.__decorate||function(e,t,a,r){var i,n=arguments.length,o=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,a):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,a,r);else for(var c=e.length-1;c>=0;c--)(i=e[c])&&(o=(n<3?i(o):n>3?i(t,a,o):i(t,a))||o);return n>3&&o&&Object.defineProperty(t,a,o),o},__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,a,r){return new(a||(a=Promise))((function(i,n){function o(e){try{s(r.next(e))}catch(e){n(e)}}function c(e){try{s(r.throw(e))}catch(e){n(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(o,c)}s((r=r.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CacheService=void 0;const logging_1=require("../../logging"),KEY_PREFIX="Z_CACHE_",DEFAULT_TTL=36e5;class CacheService{constructor(e){this.storage=e}setSecondaryCache(e){this.secondaryCache=e}get(e,t){return __awaiter(this,void 0,void 0,(function*(){e=this.addPrefix(e);const a=yield this.storage.get(e);if(a)try{const t=JSON.parse(a);return t.expiresAt&&Date.now()>t.expiresAt?(yield this.delete(e),null):this.deserialize(t)}catch(e){return console.error("Cache deserialization failed:",e),null}if((null==t?void 0:t.useSecondaryCache)&&this.secondaryCache){const a=yield this.secondaryCache.get(e,t);return null!==a&&(yield this.set(e,a,{ttl:null==t?void 0:t.ttl})),a}return null}))}set(e,t,a){return __awaiter(this,void 0,void 0,(function*(){var r;e=this.addPrefix(e);const i={type:t instanceof Date?"date":typeof t,value:t,expiresAt:Date.now()+(null!==(r=null==a?void 0:a.ttl)&&void 0!==r?r:36e5)},n=JSON.stringify(i);yield this.storage.set(e,n),(null==a?void 0:a.useSecondaryCache)&&this.secondaryCache&&(yield this.secondaryCache.set(e,t,a))}))}delete(e){return __awaiter(this,void 0,void 0,(function*(){e=this.addPrefix(e),yield this.storage.delete(e)}))}clear(){return __awaiter(this,void 0,void 0,(function*(){yield this.storage.clear()}))}addPrefix(e){return e.startsWith("Z_CACHE_")?e:"Z_CACHE_"+e}deserialize(e){switch(e.type){case"number":return Number(e.value);case"boolean":return Boolean(e.value);case"object":return e.value;case"date":case"datetime":const t=new Date(e.value);return isNaN(t.getTime())?(console.error(`Invalid ${e.type} string:`,e.value),null):t;default:return String(e.value)}}}exports.CacheService=CacheService,__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Object]),__metadata("design:returntype",Promise)],CacheService.prototype,"get",null),__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Object,Object]),__metadata("design:returntype",Promise)],CacheService.prototype,"set",null);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./cache-service";
|
|
@@ -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("./cache-service"),exports);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ConfigVarClient } from "../../../clients";
|
|
2
|
+
import { CacheStorage } from "../cache-service";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of CacheStorage using ConfigVarClient.
|
|
5
|
+
* This class interacts with a configuration variable service to store and retrieve values.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ConfigVarCacheStorage<T = any> implements CacheStorage<T> {
|
|
8
|
+
private configVarClient;
|
|
9
|
+
/**
|
|
10
|
+
* Creates an instance of ConfigVarCacheStorage.
|
|
11
|
+
* @param {ConfigVarClient} configVarService - The client used to interact with the configuration variable service.
|
|
12
|
+
*/
|
|
13
|
+
constructor(configVarService: ConfigVarClient);
|
|
14
|
+
/**
|
|
15
|
+
* Stores a value in the configuration variable service.
|
|
16
|
+
* If the key already exists, it updates the value.
|
|
17
|
+
* @param {string} key - The cache key.
|
|
18
|
+
* @param {T} value - The value to store.
|
|
19
|
+
* @returns {Promise<void>}
|
|
20
|
+
*/
|
|
21
|
+
set(key: string, value: T): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves a cached value by key from the configuration variable service.
|
|
24
|
+
* @param {string} key - The cache key.
|
|
25
|
+
* @returns {Promise<T | null>} - The cached value or null if not found.
|
|
26
|
+
*/
|
|
27
|
+
get(key: string): Promise<T | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Deletes a specific key from the cache.
|
|
30
|
+
* @param {string} key - The cache key to delete.
|
|
31
|
+
* @returns {Promise<void>}
|
|
32
|
+
*/
|
|
33
|
+
delete(key: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Clears all cache entries.
|
|
36
|
+
* Note: This operation is not supported by ConfigVarCacheStorage.
|
|
37
|
+
* @returns {Promise<void>}
|
|
38
|
+
*/
|
|
39
|
+
clear(): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(r,o){function a(t){try{s(i.next(t))}catch(t){o(t)}}function c(t){try{s(i.throw(t))}catch(t){o(t)}}function s(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}s((i=i.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConfigVarCacheStorage=void 0;const constants_1=require("../../../constants");class ConfigVarCacheStorage{constructor(t){this.configVarClient=t}set(t,e){return __awaiter(this,void 0,void 0,(function*(){try{yield this.configVarClient.create({key:t,value:e,configType:constants_1.CONFIG_VAR_TYPE.PLAIN_TEXT})}catch(n){yield this.configVarClient.update({key:t,value:e,configType:constants_1.CONFIG_VAR_TYPE.PLAIN_TEXT})}}))}get(t){return __awaiter(this,void 0,void 0,(function*(){var e;try{const e=yield this.configVarClient.get(t);if(e)return e.value}catch(t){if(null===(e=null==t?void 0:t.message)||void 0===e?void 0:e.includes("not_found"))return null;throw t}return null}))}delete(t){return __awaiter(this,void 0,void 0,(function*(){yield this.configVarClient.delete(t)}))}clear(){return __awaiter(this,void 0,void 0,(function*(){throw new Error("Clear operation is not supported by ConfigVarCacheStorage")}))}}exports.ConfigVarCacheStorage=ConfigVarCacheStorage;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CacheStorage } from "../cache-service";
|
|
2
|
+
/**
|
|
3
|
+
* Implementation of CacheStorage using an in-memory Map.
|
|
4
|
+
* This class provides a simple key-value store that resides in memory.
|
|
5
|
+
*/
|
|
6
|
+
export declare class InMemoryCacheStorage<T = any> implements CacheStorage<T> {
|
|
7
|
+
private cache;
|
|
8
|
+
/**
|
|
9
|
+
* Stores a value in the cache.
|
|
10
|
+
* @param {string} key - The cache key.
|
|
11
|
+
* @param {T} value - The value to store.
|
|
12
|
+
* @returns {Promise<void>}
|
|
13
|
+
*/
|
|
14
|
+
set(key: string, value: T): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves a cached value by key.
|
|
17
|
+
* @param {string} key - The cache key.
|
|
18
|
+
* @returns {Promise<T | null>} - The cached value or null if not found.
|
|
19
|
+
*/
|
|
20
|
+
get(key: string): Promise<T | null>;
|
|
21
|
+
/**
|
|
22
|
+
* Deletes a specific key from the cache.
|
|
23
|
+
* @param {string} key - The cache key to delete.
|
|
24
|
+
* @returns {Promise<void>}
|
|
25
|
+
*/
|
|
26
|
+
delete(key: string): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Clears all cache entries.
|
|
29
|
+
* @returns {Promise<void>}
|
|
30
|
+
*/
|
|
31
|
+
clear(): Promise<void>;
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{s(r.next(e))}catch(e){o(e)}}function c(e){try{s(r.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}s((r=r.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.InMemoryCacheStorage=void 0;class InMemoryCacheStorage{constructor(){this.cache=new Map}set(e,t){return __awaiter(this,void 0,void 0,(function*(){this.cache.set(e,t)}))}get(e){return __awaiter(this,void 0,void 0,(function*(){const t=this.cache.get(e);return t||null}))}delete(e){return __awaiter(this,void 0,void 0,(function*(){this.cache.delete(e)}))}clear(){return __awaiter(this,void 0,void 0,(function*(){this.cache.clear()}))}}exports.InMemoryCacheStorage=InMemoryCacheStorage;
|
|
@@ -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("./config-var-cache-storage"),exports),__exportStar(require("./in-memory-cache-storage"),exports);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { FetchRecordsQueryParams } from "../../interfaces/graphql";
|
|
2
|
+
/**
|
|
3
|
+
* A utility class for building GraphQL queries dynamically.
|
|
4
|
+
*/
|
|
5
|
+
export declare class GraphQLQueryBuilder {
|
|
6
|
+
private objectName;
|
|
7
|
+
private fields;
|
|
8
|
+
private filters;
|
|
9
|
+
private first?;
|
|
10
|
+
private offset?;
|
|
11
|
+
private orderBy?;
|
|
12
|
+
private after?;
|
|
13
|
+
private parentQueries;
|
|
14
|
+
private childQueries;
|
|
15
|
+
private isParent;
|
|
16
|
+
/**
|
|
17
|
+
* Creates an instance of GraphQLQueryBuilder.
|
|
18
|
+
* @param {string} objectName - The name of the object being queried.
|
|
19
|
+
* @param {boolean} [isParent=false] - Indicates if this query is a parent query.
|
|
20
|
+
*/
|
|
21
|
+
constructor(objectName: string, isParent?: boolean);
|
|
22
|
+
/**
|
|
23
|
+
* Specifies the fields to be retrieved.
|
|
24
|
+
* @param {string[]} fields - The list of fields to select.
|
|
25
|
+
* @returns {this} - The query builder instance.
|
|
26
|
+
*/
|
|
27
|
+
withFields(fields: string[]): this;
|
|
28
|
+
/**
|
|
29
|
+
* Adds a filter condition to the query.
|
|
30
|
+
* @param {string} condition - The filter condition.
|
|
31
|
+
* @returns {this} - The query builder instance.
|
|
32
|
+
*/
|
|
33
|
+
withFilter(condition: string): this;
|
|
34
|
+
/**
|
|
35
|
+
* Sets a limit on the number of records to retrieve.
|
|
36
|
+
* @param {number} first - The number of records to fetch.
|
|
37
|
+
* @returns {this} - The query builder instance.
|
|
38
|
+
*/
|
|
39
|
+
withLimit(first: number): this;
|
|
40
|
+
/**
|
|
41
|
+
* Sets an offset for pagination.
|
|
42
|
+
* @param {number} offset - The offset value.
|
|
43
|
+
* @returns {this} - The query builder instance.
|
|
44
|
+
*/
|
|
45
|
+
withOffset(offset: number): this;
|
|
46
|
+
/**
|
|
47
|
+
* Sets the order in which records should be retrieved.
|
|
48
|
+
* @param {string} orderBy - The field to order by.
|
|
49
|
+
* @returns {this} - The query builder instance.
|
|
50
|
+
*/
|
|
51
|
+
withOrderBy(orderBy: string): this;
|
|
52
|
+
/**
|
|
53
|
+
* Applies cursor-based pagination.
|
|
54
|
+
* @param {string} after - The cursor position.
|
|
55
|
+
* @returns {this} - The query builder instance.
|
|
56
|
+
*/
|
|
57
|
+
withCursor(after: string): this;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a parent query.
|
|
60
|
+
* @param {string} objectName - The name of the parent object.
|
|
61
|
+
* @returns {GraphQLQueryBuilder} - A new query builder instance for the parent.
|
|
62
|
+
*/
|
|
63
|
+
withParentQuery(objectName: string): GraphQLQueryBuilder;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a child query.
|
|
66
|
+
* @param {string} objectName - The name of the child object.
|
|
67
|
+
* @returns {GraphQLQueryBuilder} - A new query builder instance for the child.
|
|
68
|
+
*/
|
|
69
|
+
withChildQuery(objectName: string): GraphQLQueryBuilder;
|
|
70
|
+
/**
|
|
71
|
+
* Builds the GraphQL query parameters.
|
|
72
|
+
* @returns {FetchRecordsQueryParams} - The formatted query parameters.
|
|
73
|
+
*/
|
|
74
|
+
build(): FetchRecordsQueryParams;
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphQLQueryBuilder=void 0;class GraphQLQueryBuilder{constructor(t,r=!1){this.fields=[],this.filters=[],this.parentQueries={},this.childQueries={},this.objectName=t.charAt(0).toLowerCase()+t.slice(1),this.isParent=r}withFields(t){return this.fields.push(...t),this}withFilter(t){if(this.isParent)throw new Error("Cannot apply filters to a parent query.");return this.filters.push(t),this}withLimit(t){if(this.isParent)throw new Error("Cannot apply limit to a parent query.");return this.first=t,this}withOffset(t){if(this.isParent)throw new Error("Cannot apply offset to a parent query.");return this.offset=t,this}withOrderBy(t){if(this.isParent)throw new Error("Cannot apply orderBy to a parent query.");return this.orderBy=t,this}withCursor(t){if(this.isParent)throw new Error("Cannot apply cursor to a parent query.");return this.after=t,this}withParentQuery(t){const r=new GraphQLQueryBuilder(t,!0);return this.parentQueries[t]=r,r}withChildQuery(t){const r=new GraphQLQueryBuilder(t);return this.childQueries[t]=r,r}build(){const t=Object.entries(this.parentQueries).map((([t,r])=>`${t} { ${r.build().fields} }`)),r=Object.entries(this.childQueries).map((([t,r])=>{const e=r.build();return`${t}${e.filter?` (filter: "${e.filter}")`:""} { ${e.fields} }`}));return{objectName:this.objectName,fields:[...this.fields,...t,...r].filter(Boolean).join(", "),filter:this.filters.length>0?this.filters.join(" AND "):void 0,first:this.first,offset:this.offset,orderBy:this.orderBy,after:this.after}}}exports.GraphQLQueryBuilder=GraphQLQueryBuilder;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { GraphQLClient } from "../../clients/graphql-client";
|
|
2
|
+
import { FetchRecordsQueryParams, HasId, MutationResult, QueryResult } from "../../interfaces/graphql";
|
|
3
|
+
/**
|
|
4
|
+
* A service class for handling GraphQL operations.
|
|
5
|
+
*/
|
|
6
|
+
export declare class GraphQLService {
|
|
7
|
+
private client;
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of GraphQLService.
|
|
10
|
+
* @param {GraphQLClient} client - The GraphQL client to use for queries and mutations.
|
|
11
|
+
*/
|
|
12
|
+
constructor(client: GraphQLClient);
|
|
13
|
+
/**
|
|
14
|
+
* Executes a GraphQL query to fetch records.
|
|
15
|
+
* @param {FetchRecordsQueryParams} params - The query parameters.
|
|
16
|
+
* @returns {Promise<QueryResult>} - The query result including records, total count, page info, and cursors.
|
|
17
|
+
*/
|
|
18
|
+
query(params: FetchRecordsQueryParams): Promise<QueryResult>;
|
|
19
|
+
/**
|
|
20
|
+
* Deletes records from the GraphQL API.
|
|
21
|
+
* @param {string} objectName - The name of the object.
|
|
22
|
+
* @param {HasId[]} records - The records to delete.
|
|
23
|
+
* @returns {Promise<any>} - The response from the delete operation.
|
|
24
|
+
*/
|
|
25
|
+
delete(objectName: string, records: HasId[]): Promise<any>;
|
|
26
|
+
/**
|
|
27
|
+
* Updates records in the GraphQL API.
|
|
28
|
+
* @param {string} objectName - The name of the object.
|
|
29
|
+
* @param {HasId[]} records - The records to update.
|
|
30
|
+
* @returns {Promise<any>} - The response from the update operation.
|
|
31
|
+
*/
|
|
32
|
+
update(objectName: string, records: HasId[]): Promise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* Inserts records into the GraphQL API.
|
|
35
|
+
* @param {string} objectName - The name of the object.
|
|
36
|
+
* @param {HasId[]} records - The records to insert.
|
|
37
|
+
* @returns {Promise<any>} - The response from the insert operation.
|
|
38
|
+
*/
|
|
39
|
+
insert(objectName: string, records: HasId[]): Promise<any>;
|
|
40
|
+
/**
|
|
41
|
+
* Extracts job UIDs from a GraphQL mutation response.
|
|
42
|
+
* @param {MutationResult} response - The response object.
|
|
43
|
+
* @returns {string[]} - An array of job UIDs.
|
|
44
|
+
*/
|
|
45
|
+
extractJobUIDs(response: MutationResult): string[];
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __decorate=this&&this.__decorate||function(e,t,o,r){var i,n=arguments.length,a=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,o,r);else for(var d=e.length-1;d>=0;d--)(i=e[d])&&(a=(n<3?i(a):n>3?i(t,o,a):i(t,o))||a);return n>3&&a&&Object.defineProperty(t,o,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,o,r){return new(o||(o=Promise))((function(i,n){function a(e){try{s(r.next(e))}catch(e){n(e)}}function d(e){try{s(r.throw(e))}catch(e){n(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(a,d)}s((r=r.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphQLService=void 0;const logging_1=require("../../logging"),queries_1=require("./queries");class GraphQLService{constructor(e){this.client=e}query(e){return __awaiter(this,void 0,void 0,(function*(){var t,o,r,i,n,a,d,s,c,l,u,_;e.objectName=getQueryName(e.objectName);const v=(0,queries_1.FETCH_RECORDS_QUERY)(e),g=yield this.client.execute(v),p={records:(null===(o=null===(t=null==g?void 0:g.data)||void 0===t?void 0:t[e.objectName])||void 0===o?void 0:o.edges.map((e=>e.node)))||[],totalCount:(null===(i=null===(r=null==g?void 0:g.data)||void 0===r?void 0:r[e.objectName])||void 0===i?void 0:i.totalCount)||0,pageInfo:(null===(a=null===(n=null==g?void 0:g.data)||void 0===n?void 0:n[e.objectName])||void 0===a?void 0:a.pageInfo)||{}};if(p.records.length>0){const t=(null===(c=null===(s=null===(d=null==g?void 0:g.data)||void 0===d?void 0:d[e.objectName])||void 0===s?void 0:s.edges)||void 0===c?void 0:c.map((e=>e.offset)))||[],o=(null===(_=null===(u=null===(l=null==g?void 0:g.data)||void 0===l?void 0:l[e.objectName])||void 0===u?void 0:u.edges)||void 0===_?void 0:_.map((e=>e.cursor)))||[];p.endOffset=t[t.length-1],p.endCursor=o[o.length-1]}return p}))}delete(e,t){return __awaiter(this,void 0,void 0,(function*(){if(!t||0===t.length)return Promise.resolve({message:"No records to process"});const o=(0,queries_1.DELETE_OBJECTS_MUTATION)(e,t);return yield this.client.execute(o)}))}update(e,t){return __awaiter(this,void 0,void 0,(function*(){if(!t||0===t.length)return Promise.resolve({message:"No records to process"});const o=(0,queries_1.UPSERT_OBJECTS_MUTATION)(e,t,"update");return yield this.client.execute(o)}))}insert(e,t){return __awaiter(this,void 0,void 0,(function*(){if(!t||0===t.length)return Promise.resolve({message:"No records to process"});const o=(0,queries_1.UPSERT_OBJECTS_MUTATION)(e,t,"insert");return yield this.client.execute(o)}))}extractJobUIDs(e){var t;return(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.schema)?Object.values(e.data.schema):[]}}function getQueryName(e){return e.charAt(0).toLowerCase()+e.slice(1)}exports.GraphQLService=GraphQLService,__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],GraphQLService.prototype,"query",null),__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Array]),__metadata("design:returntype",Promise)],GraphQLService.prototype,"delete",null),__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Array]),__metadata("design:returntype",Promise)],GraphQLService.prototype,"update",null),__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Array]),__metadata("design:returntype",Promise)],GraphQLService.prototype,"insert",null);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,i){void 0===i&&(i=t);var o=Object.getOwnPropertyDescriptor(r,t);o&&!("get"in o?!r.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,i,o)}:function(e,r,t,i){void 0===i&&(i=t),e[i]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./graphql-query-builder"),exports),__exportStar(require("./graphql-service"),exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FetchRecordsQueryParams, HasId } from "../../interfaces/graphql";
|
|
2
|
+
/**
|
|
3
|
+
* Constructs a GraphQL query for fetching records with specified parameters.
|
|
4
|
+
*
|
|
5
|
+
* @param params - The query parameters including object name, filter, pagination, ordering, and fields.
|
|
6
|
+
* @returns The constructed GraphQL query string.
|
|
7
|
+
*/
|
|
8
|
+
export declare const FETCH_RECORDS_QUERY: ({ objectName, filter, first, offset, after, orderBy, fields, }: FetchRecordsQueryParams) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Constructs a GraphQL mutation for deleting multiple objects.
|
|
11
|
+
*
|
|
12
|
+
* @param objectName - The name of the object to delete.
|
|
13
|
+
* @param records - The records to be deleted.
|
|
14
|
+
* @returns The constructed GraphQL mutation string.
|
|
15
|
+
*/
|
|
16
|
+
export declare const DELETE_OBJECTS_MUTATION: (objectName: string, records: HasId[]) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Constructs a GraphQL mutation for upserting (inserting/updating) multiple objects.
|
|
19
|
+
*
|
|
20
|
+
* @param objectName - The name of the object to upsert.
|
|
21
|
+
* @param records - The records to be upserted.
|
|
22
|
+
* @param operation - The operation type ("insert" or "update").
|
|
23
|
+
* @returns The constructed GraphQL mutation string.
|
|
24
|
+
*/
|
|
25
|
+
export declare const UPSERT_OBJECTS_MUTATION: (objectName: string, records: HasId[], operation: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UPSERT_OBJECTS_MUTATION=exports.DELETE_OBJECTS_MUTATION=exports.FETCH_RECORDS_QUERY=void 0;const FETCH_RECORDS_QUERY=({objectName:e,filter:n,first:t=200,offset:E=0,after:T,orderBy:o,fields:s})=>`\n query fetchRecords {\n ${e}(${[n?`filter: "${n}"`:"",T?`after: "${T}"`:"",`first: ${t}`,E?`offset: ${E}`:"",o?`orderBy: "${o}"`:""].filter((e=>e)).join(", ")}) {\n totalCount\n pageInfo{\n hasNextPage\n }\n edges {\n cursor\n offset\n node {\n ${s||"UID"}\n }\n }\n }\n }\n `;exports.FETCH_RECORDS_QUERY=FETCH_RECORDS_QUERY;const DELETE_OBJECTS_MUTATION=(e,n)=>`\n mutation deleteObjects {\n schema {\n ${n.map(((n,t)=>`alias${t+1}:delete${e}(UID: "${n.UID}")`)).join("\n ")}\n }\n }`;exports.DELETE_OBJECTS_MUTATION=DELETE_OBJECTS_MUTATION;const UPSERT_OBJECTS_MUTATION=(e,n,t)=>`\n mutation ${t}Objects {\n schema {\n ${n.map(((n,E)=>`\n alias${E+1}:${t}${e}(input: {\n ${Object.entries(n).map((([e,n])=>`${e}: ${"string"==typeof n?`"${n}"`:n}`)).join(", ")}\n }) \n `)).join("\n ")}\n }\n }`;exports.UPSERT_OBJECTS_MUTATION=UPSERT_OBJECTS_MUTATION;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var i=Object.getOwnPropertyDescriptor(r,t);i&&!("get"in i?!r.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,i)}:function(e,r,t,o){void 0===o&&(o=t),e[o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./batch-processor"),exports),__exportStar(require("./cache"),exports),__exportStar(require("./graphql"),exports),__exportStar(require("./metadata-service"),exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,a,n){return new(a||(a=Promise))((function(i,r){function c(t){try{s(n.next(t))}catch(t){r(t)}}function o(t){try{s(n.throw(t))}catch(t){r(t)}}function s(t){var e;t.done?i(t.value):(e=t.value,e instanceof a?e:new a((function(t){t(e)}))).then(c,o)}s((n=n.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MetadataService=void 0;class MetadataService{constructor(t){this.client=t}getObjectMetadata(t){return __awaiter(this,void 0,void 0,(function*(){const e=(yield this.client.fetchAllMetadata()).result,a={};for(const n of t){const t=e.find((t=>t.name===n));if(!t)throw new Error(`Metadata mapping not found for object: ${n}`);a[n]=(yield this.client.fetchObjectMetadata(t.mapping)).result}return a}))}getPicklistValues(t){const e=t.fields.filter((t=>"picklist"===t.type)),a={};for(const t of e)a[t.name]=t.values.map((t=>t.value));return a}}exports.MetadataService=MetadataService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConfigHelper=void 0;class ConfigHelper{constructor(e){this.vars=e}getNumber(e){let r=this.vars.getVariableValue(e);return isNaN(Number(r))?null:parseInt(r,10)}getJson(e){let r=this.vars.getVariableValue(e);try{return JSON.parse(r)}catch(e){return null}}getString(e){return this.vars.getVariableValue(e)}}exports.ConfigHelper=ConfigHelper;
|
|
@@ -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("./config-helper"),exports);
|