@skedulo/pulse-solution-services 0.0.7 → 0.0.9
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 +12 -0
- package/README.md +139 -23
- package/dist/clients/artifact-client.js +1 -1
- package/dist/clients/base-client.js +1 -1
- package/dist/clients/config-var-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-header-constants.js +1 -0
- package/dist/index.d.ts +327 -118
- package/dist/interfaces/api-client.js +1 -0
- package/dist/interfaces/index.js +1 -1
- package/dist/interfaces/lock-service-interfaces.js +1 -0
- package/dist/interfaces/locking-service-interfaces.js +1 -0
- 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/cache/cache-service.js +1 -1
- package/dist/services/graph-batch/configs/graph-batch-config.d.ts +33 -0
- package/dist/services/graph-batch/configs/graph-batch-config.js +1 -0
- package/dist/services/graph-batch/configs/unique-graph-batch-config.d.ts +39 -0
- package/dist/services/graph-batch/configs/unique-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 +5 -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/graph-batch/unique-graph-batch.d.ts +28 -0
- package/dist/services/graph-batch/unique-graph-batch.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/lock-service.js +1 -0
- package/dist/services/locking-service.js +1 -0
- package/dist/services/resource-availability/builder/data-service.d.ts +2 -1
- package/dist/services/resource-availability/builder/data-service.js +1 -1
- package/dist/utils/datetime-utils.js +1 -1
- package/package.json +9 -5
- package/yarn.lock +402 -199
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __decorate=this&&this.__decorate||function(e,t,a
|
|
1
|
+
"use strict";var __decorate=this&&this.__decorate||function(e,t,r,a){var i,n=arguments.length,o=n<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,r):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,a);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(n<3?i(o):n>3?i(t,r,o):i(t,r))||o);return n>3&&o&&Object.defineProperty(t,r,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,r,a){return new(r||(r=Promise))((function(i,n){function o(e){try{c(a.next(e))}catch(e){n(e)}}function s(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,s)}c((a=a.apply(e,t||[])).next())}))},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CacheService=void 0;const logging_1=require("../../logging"),logger_1=__importDefault(require("../../logging/logger")),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 r=yield this.storage.get(e);if(r)try{const t=JSON.parse(r);return t.expiresAt&&Date.now()>t.expiresAt?(yield this.delete(e),null):this.deserialize(t)}catch(e){return logger_1.default.error("Cache deserialization failed:",e),null}if((null==t?void 0:t.useSecondaryCache)&&this.secondaryCache){const r=yield this.secondaryCache.get(e,t);return null!==r&&(yield this.set(e,r,{ttl:null==t?void 0:t.ttl})),r}return null}))}set(e,t,r){return __awaiter(this,void 0,void 0,(function*(){var a;e=this.addPrefix(e);const i={type:t instanceof Date?"date":typeof t,value:t,expiresAt:Date.now()+(null!==(a=null==r?void 0:r.ttl)&&void 0!==a?a:36e5)},n=JSON.stringify(i);yield this.storage.set(e,n),(null==r?void 0:r.useSecondaryCache)&&this.secondaryCache&&(yield this.secondaryCache.set(e,t,r))}))}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())?(logger_1.default.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,33 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { PaginationStrategy } from "../pagination-strategy";
|
|
3
|
+
/**
|
|
4
|
+
* Default configuration values for `GraphBatchConfig`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_GRAPH_BATCH_CONFIG: GraphBatchConfig;
|
|
7
|
+
/**
|
|
8
|
+
* Schema validation using `zod`
|
|
9
|
+
*/
|
|
10
|
+
export declare const GraphBatchConfigSchema: z.ZodObject<{
|
|
11
|
+
strategy: z.ZodNativeEnum<typeof PaginationStrategy>;
|
|
12
|
+
batchSize: z.ZodDefault<z.ZodNumber>;
|
|
13
|
+
maxBatches: z.ZodDefault<z.ZodNumber>;
|
|
14
|
+
delaySeconds: z.ZodDefault<z.ZodNumber>;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
strategy: PaginationStrategy;
|
|
17
|
+
batchSize: number;
|
|
18
|
+
maxBatches: number;
|
|
19
|
+
delaySeconds: number;
|
|
20
|
+
}, {
|
|
21
|
+
strategy: PaginationStrategy;
|
|
22
|
+
batchSize?: number | undefined;
|
|
23
|
+
maxBatches?: number | undefined;
|
|
24
|
+
delaySeconds?: number | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Configuration options for `GraphBatch`.
|
|
28
|
+
*/
|
|
29
|
+
export type GraphBatchConfig = z.infer<typeof GraphBatchConfigSchema>;
|
|
30
|
+
/**
|
|
31
|
+
* Merges user-provided config with default values.
|
|
32
|
+
*/
|
|
33
|
+
export declare function initializeConfig(config: Partial<GraphBatchConfig> | undefined): GraphBatchConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphBatchConfigSchema=exports.DEFAULT_GRAPH_BATCH_CONFIG=void 0,exports.initializeConfig=initializeConfig;const zod_1=require("zod"),pagination_strategy_1=require("../pagination-strategy");function initializeConfig(e){return exports.GraphBatchConfigSchema.parse(Object.assign(Object.assign({},exports.DEFAULT_GRAPH_BATCH_CONFIG),e))}exports.DEFAULT_GRAPH_BATCH_CONFIG={strategy:pagination_strategy_1.PaginationStrategy.NONE,batchSize:200,maxBatches:100,delaySeconds:0},exports.GraphBatchConfigSchema=zod_1.z.object({strategy:zod_1.z.nativeEnum(pagination_strategy_1.PaginationStrategy),batchSize:zod_1.z.number().min(1).max(200).default(200),maxBatches:zod_1.z.number().min(1).max(500).default(100),delaySeconds:zod_1.z.number().min(0).max(15).default(0)});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Default configuration values for `UniqueGraphBatchConfig`.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_UNIQUE_GRAPH_BATCH_CONFIG: UniqueGraphBatchConfig;
|
|
6
|
+
/**
|
|
7
|
+
* Schema validation for `UniqueGraphBatchConfig`
|
|
8
|
+
*/
|
|
9
|
+
export declare const UniqueGraphBatchConfigSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
10
|
+
strategy: z.ZodNativeEnum<typeof import("..").PaginationStrategy>;
|
|
11
|
+
batchSize: z.ZodDefault<z.ZodNumber>;
|
|
12
|
+
maxBatches: z.ZodDefault<z.ZodNumber>;
|
|
13
|
+
delaySeconds: z.ZodDefault<z.ZodNumber>;
|
|
14
|
+
}, {
|
|
15
|
+
name: z.ZodOptional<z.ZodString>;
|
|
16
|
+
lockTtl: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
}>, "strip", z.ZodTypeAny, {
|
|
18
|
+
strategy: import("..").PaginationStrategy;
|
|
19
|
+
batchSize: number;
|
|
20
|
+
maxBatches: number;
|
|
21
|
+
delaySeconds: number;
|
|
22
|
+
name?: string | undefined;
|
|
23
|
+
lockTtl?: number | undefined;
|
|
24
|
+
}, {
|
|
25
|
+
strategy: import("..").PaginationStrategy;
|
|
26
|
+
name?: string | undefined;
|
|
27
|
+
batchSize?: number | undefined;
|
|
28
|
+
maxBatches?: number | undefined;
|
|
29
|
+
delaySeconds?: number | undefined;
|
|
30
|
+
lockTtl?: number | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Configuration options for `UniqueGraphBatch`.
|
|
34
|
+
*/
|
|
35
|
+
export type UniqueGraphBatchConfig = z.infer<typeof UniqueGraphBatchConfigSchema>;
|
|
36
|
+
/**
|
|
37
|
+
* Merges user-provided config with default values for `UniqueGraphBatch`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function initializeUniqueConfig(config: Partial<UniqueGraphBatchConfig> | undefined): UniqueGraphBatchConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UniqueGraphBatchConfigSchema=exports.DEFAULT_UNIQUE_GRAPH_BATCH_CONFIG=void 0,exports.initializeUniqueConfig=initializeUniqueConfig;const zod_1=require("zod"),graph_batch_config_1=require("./graph-batch-config");function initializeUniqueConfig(e){return exports.UniqueGraphBatchConfigSchema.parse(Object.assign(Object.assign({},exports.DEFAULT_UNIQUE_GRAPH_BATCH_CONFIG),e))}exports.DEFAULT_UNIQUE_GRAPH_BATCH_CONFIG=Object.assign(Object.assign({},graph_batch_config_1.DEFAULT_GRAPH_BATCH_CONFIG),{lockTtl:96e4,name:"UNIQUE-BATCH"}),exports.UniqueGraphBatchConfigSchema=graph_batch_config_1.GraphBatchConfigSchema.extend({name:zod_1.z.string().optional(),lockTtl:zod_1.z.number().min(1e3).optional()});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ExecutionContext } from "../../core";
|
|
2
|
+
import { QueryResult } from "../../interfaces";
|
|
3
|
+
import { GraphQLQueryBuilder } from "../graphql";
|
|
4
|
+
import { GraphBatchConfig } from "./configs/graph-batch-config";
|
|
5
|
+
/**
|
|
6
|
+
* Base class for batch processing with pagination support.
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class GraphBatch {
|
|
9
|
+
protected context: ExecutionContext;
|
|
10
|
+
protected config: GraphBatchConfig;
|
|
11
|
+
protected queryBuilder?: GraphQLQueryBuilder;
|
|
12
|
+
protected queryResult?: QueryResult;
|
|
13
|
+
private startTime;
|
|
14
|
+
constructor(context: ExecutionContext, config?: Partial<GraphBatchConfig>);
|
|
15
|
+
/**
|
|
16
|
+
* Runs the batch process, handling pagination, execution, and accumulation of results.
|
|
17
|
+
*
|
|
18
|
+
* @returns The accumulated result of the batch process.
|
|
19
|
+
*/
|
|
20
|
+
run(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Initializes the query builder. This method must be overridden in subclasses.
|
|
23
|
+
*
|
|
24
|
+
* @returns A configured GraphQL query builder.
|
|
25
|
+
*/
|
|
26
|
+
protected abstract start(): Promise<GraphQLQueryBuilder>;
|
|
27
|
+
/**
|
|
28
|
+
* Processes a batch of records and accumulates the result.
|
|
29
|
+
*
|
|
30
|
+
* @param records The batch of records retrieved from the query.
|
|
31
|
+
*/
|
|
32
|
+
protected abstract execute(records: any[]): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Final cleanup or logging after the batch process completes.
|
|
35
|
+
*/
|
|
36
|
+
protected finish(): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Fetches the next page of data based on the pagination strategy.
|
|
39
|
+
*
|
|
40
|
+
* @returns The result of the query execution.
|
|
41
|
+
*/
|
|
42
|
+
protected fetchNextPage(): Promise<QueryResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if the maximum number of batches has been reached.
|
|
45
|
+
*
|
|
46
|
+
* @param currentBatchCount The number of batches processed so far.
|
|
47
|
+
* @returns `true` if the maximum limit is reached, otherwise `false`.
|
|
48
|
+
*/
|
|
49
|
+
protected isMaxBatchesReached(currentBatchCount: number): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Delays execution for a specified time.
|
|
52
|
+
*
|
|
53
|
+
* @param ms The time in milliseconds to delay.
|
|
54
|
+
*/
|
|
55
|
+
protected delay(ms: number): Promise<void>;
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(a,s){function n(t){try{o(r.next(t))}catch(t){s(t)}}function h(t){try{o(r.throw(t))}catch(t){s(t)}}function o(t){var e;t.done?a(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(n,h)}o((r=r.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphBatch=void 0;const graph_batch_config_1=require("./configs/graph-batch-config"),pagination_strategy_1=require("./pagination-strategy");class GraphBatch{constructor(t,e){this.startTime=new Date,this.context=t,this.config=(0,graph_batch_config_1.initializeConfig)(e),this.startTime=new Date}run(){return __awaiter(this,void 0,void 0,(function*(){var t,e;if(this.queryBuilder=yield this.start(),!this.queryBuilder)throw new Error("Query builder was not defined in start().");this.queryBuilder.withLimit(this.config.batchSize);let i=0,r=!0;for(;r&&!this.isMaxBatchesReached(i)&&(this.queryResult=yield this.fetchNextPage(),this.queryResult.records&&0!==this.queryResult.records.length);)yield this.execute(this.queryResult.records),i++,r=null!==(e=null===(t=this.queryResult.pageInfo)||void 0===t?void 0:t.hasNextPage)&&void 0!==e&&e;yield this.finish()}))}finish(){return __awaiter(this,void 0,void 0,(function*(){this.context.logger.info("Batch process completed.")}))}fetchNextPage(){return __awaiter(this,void 0,void 0,(function*(){var t,e,i;switch(this.config.strategy){case pagination_strategy_1.PaginationStrategy.OFFSET:this.queryResult&&(null===(t=this.queryBuilder)||void 0===t||t.withOffset(this.queryResult.endOffset+1));break;case pagination_strategy_1.PaginationStrategy.CURSOR:this.queryResult&&(null===(e=this.queryBuilder)||void 0===e||e.withCursor(this.queryResult.endCursor));break;case pagination_strategy_1.PaginationStrategy.NONE:default:null===(i=this.queryBuilder)||void 0===i||i.withFilter(`LastModifiedDate < ${this.startTime.toISOString()}`)}return this.queryBuilder.execute()}))}isMaxBatchesReached(t){return!!this.config.maxBatches&&t>=this.config.maxBatches}delay(t){return __awaiter(this,void 0,void 0,(function*(){return new Promise((e=>setTimeout(e,t)))}))}}exports.GraphBatch=GraphBatch;
|
|
@@ -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("./configs/graph-batch-config"),exports),__exportStar(require("./configs/unique-graph-batch-config"),exports),__exportStar(require("./graph-batch"),exports),__exportStar(require("./pagination-strategy"),exports),__exportStar(require("./unique-graph-batch"),exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var PaginationStrategy;Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaginationStrategy=void 0,function(t){t.CURSOR="cursor",t.OFFSET="offset",t.NONE="none"}(PaginationStrategy||(exports.PaginationStrategy=PaginationStrategy={}));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ExecutionContext } from "../../core/execution-context";
|
|
2
|
+
import { GraphQLQueryBuilder } from "../graphql";
|
|
3
|
+
import { UniqueGraphBatchConfig } from "./configs/unique-graph-batch-config";
|
|
4
|
+
import { GraphBatch } from "./graph-batch";
|
|
5
|
+
/**
|
|
6
|
+
* UniqueGraphBatch ensures that only one instance of a batch with the same name can run at a time.
|
|
7
|
+
*/
|
|
8
|
+
export declare class UniqueGraphBatch extends GraphBatch {
|
|
9
|
+
private name;
|
|
10
|
+
private lockTtl;
|
|
11
|
+
constructor(context: ExecutionContext, config?: Partial<UniqueGraphBatchConfig>);
|
|
12
|
+
/**
|
|
13
|
+
* Runs the batch process with lock enforcement.
|
|
14
|
+
*/
|
|
15
|
+
run(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Abstract method implementation - Initialize query builder.
|
|
18
|
+
*/
|
|
19
|
+
protected start(): Promise<GraphQLQueryBuilder>;
|
|
20
|
+
/**
|
|
21
|
+
* Abstract method implementation - Process batch records.
|
|
22
|
+
*/
|
|
23
|
+
protected execute(records: any[]): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Overrides the finish method to ensure lock cleanup.
|
|
26
|
+
*/
|
|
27
|
+
protected finish(): Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))((function(n,a){function o(t){try{s(i.next(t))}catch(t){a(t)}}function c(t){try{s(i.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,c)}s((i=i.apply(t,e||[])).next())}))},__importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.UniqueGraphBatch=void 0;const logger_1=__importDefault(require("../../logging/logger")),graph_batch_1=require("./graph-batch");class UniqueGraphBatch extends graph_batch_1.GraphBatch{constructor(t,e){super(t,e),this.name=(null==e?void 0:e.name)||this.constructor.name,this.name=this.name.toUpperCase().replace(/[^A-Z0-9]/g,"_"),this.lockTtl=(null==e?void 0:e.lockTtl)||96e4}run(){const t=Object.create(null,{run:{get:()=>super.run}});return __awaiter(this,void 0,void 0,(function*(){const e={name:this.name,ttl:this.lockTtl,description:`Lock for batch process: ${this.name}`};try{if(!(yield this.context.lockService.acquireLock(e)))return void logger_1.default.error(`A batch with name '${this.name}' is already running.`);yield t.run.call(this)}catch(t){logger_1.default.error(`Error running batch with name '${this.name}': ${t.message}`)}finally{yield this.context.lockService.releaseLock(this.name)}}))}start(){return __awaiter(this,void 0,void 0,(function*(){throw new Error("Subclasses must implement the 'start' method.")}))}execute(t){return __awaiter(this,void 0,void 0,(function*(){throw new Error("Subclasses must implement the 'execute' method.")}))}finish(){const t=Object.create(null,{finish:{get:()=>super.finish}});return __awaiter(this,void 0,void 0,(function*(){yield t.finish.call(this)}))}}exports.UniqueGraphBatch=UniqueGraphBatch;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GraphqlQueryParams, QueryResult } from "../../interfaces/graphql";
|
|
2
2
|
import { GraphQLService } from "./graphql-service";
|
|
3
3
|
/**
|
|
4
4
|
* A utility class for building GraphQL queries dynamically.
|
|
5
5
|
*/
|
|
6
6
|
export declare class GraphQLQueryBuilder {
|
|
7
7
|
private objectName;
|
|
8
|
+
operationName: string;
|
|
8
9
|
private fields;
|
|
9
10
|
private filters;
|
|
10
11
|
private first?;
|
|
@@ -15,12 +16,13 @@ export declare class GraphQLQueryBuilder {
|
|
|
15
16
|
private childQueries;
|
|
16
17
|
private isParent;
|
|
17
18
|
private graphqlService;
|
|
19
|
+
private queryParams;
|
|
18
20
|
/**
|
|
19
21
|
* Creates an instance of GraphQLQueryBuilder.
|
|
20
|
-
* @param {string}
|
|
22
|
+
* @param {string} graphqlQueryParams - The necessary parameters for the query.
|
|
21
23
|
* @param {boolean} [isParent=false] - Indicates if this query is a parent query.
|
|
22
24
|
*/
|
|
23
|
-
constructor(
|
|
25
|
+
constructor(queryParams: GraphqlQueryParams, isParent?: boolean);
|
|
24
26
|
/**
|
|
25
27
|
* Sets the GraphQL service to use for executing the query.
|
|
26
28
|
*/
|
|
@@ -64,7 +66,7 @@ export declare class GraphQLQueryBuilder {
|
|
|
64
66
|
/**
|
|
65
67
|
* Builds the GraphQL query parameters in a more structured format.
|
|
66
68
|
*/
|
|
67
|
-
build():
|
|
69
|
+
build(): GraphqlQueryParams;
|
|
68
70
|
/**
|
|
69
71
|
* Executes the query using the GraphQL service, with improved error handling.
|
|
70
72
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphQLQueryBuilder=void 0;class GraphQLQueryBuilder{constructor(r
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphQLQueryBuilder=void 0;class GraphQLQueryBuilder{constructor(e,r=!1){this.fields=new Set(["UID"]),this.filters=[],this.parentQueries={},this.childQueries={},this.graphqlService=null,this.queryParams=e,this.objectName=e.objectName.charAt(0).toLowerCase()+e.objectName.slice(1),this.operationName=e.operationName,this.isParent=r}setGraphqlService(e){this.graphqlService=e}withFields(e){return e.forEach((e=>this.fields.add(e))),this}withFilter(e){if(this.isParent)throw new Error("Cannot apply filters to a parent query.");return this.filters.push(e),this}withLimit(e){if(this.isParent)throw new Error("Cannot apply limit to a parent query.");return this.first=e,this}withOffset(e){if(this.isParent)throw new Error("Cannot apply offset to a parent query.");return this.offset=e,this}withOrderBy(e){if(this.isParent)throw new Error("Cannot apply orderBy to a parent query.");return this.orderBy=e,this}withCursor(e){if(this.isParent)throw new Error("Cannot apply cursor to a parent query.");return this.after=e,this}withParentQuery(e){const r=new GraphQLQueryBuilder({objectName:e,operationName:this.operationName},!0);return this.parentQueries[e]=r,r}withChildQuery(e){const r=new GraphQLQueryBuilder({objectName:e,operationName:this.operationName});return this.childQueries[e]=r,r}formatQueryFields(){const e=Object.entries(this.parentQueries).map((([e,r])=>`${e} { ${r.formatQueryFields()} }`)).join(", "),r=Object.entries(this.childQueries).map((([e,r])=>{const t=r.build();return`${e} ${t.filter?`(filter: "${t.filter}")`:""} { ${t.fields} }`})).join(", ");return[...this.fields,e,r].filter(Boolean).join(", ")}build(){return{objectName:this.objectName,operationName:this.operationName,fields:this.formatQueryFields(),filter:this.filters.length>0?this.filters.join(" AND "):void 0,first:this.first,offset:this.offset,orderBy:this.orderBy,after:this.after}}execute(){if(!this.graphqlService)return Promise.reject(new Error("No GraphQL service set for query execution."));const e=this.build();return e.readOnly=this.queryParams.readOnly,this.graphqlService.query(e)}toString(){return`{ ${this.objectName} { ${this.formatQueryFields()} } }`}}exports.GraphQLQueryBuilder=GraphQLQueryBuilder;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLClient } from "../../clients/graphql-client";
|
|
2
|
-
import {
|
|
2
|
+
import { GraphqlMurationParams, GraphqlQueryParams, MutationResult, QueryResult } from "../../interfaces/graphql";
|
|
3
3
|
/**
|
|
4
4
|
* A service class for handling GraphQL operations.
|
|
5
5
|
*/
|
|
@@ -12,35 +12,42 @@ export declare class GraphQLService {
|
|
|
12
12
|
constructor(client: GraphQLClient);
|
|
13
13
|
/**
|
|
14
14
|
* Executes a GraphQL query to fetch records.
|
|
15
|
-
* @param {
|
|
15
|
+
* @param {GraphqlQueryParams} params - The query parameters.
|
|
16
16
|
* @returns {Promise<QueryResult>} - The query result including records, total count, page info, and cursors.
|
|
17
17
|
*/
|
|
18
|
-
query(params:
|
|
18
|
+
query(params: GraphqlQueryParams): Promise<QueryResult>;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Performs a mutation operation on the GraphQL API.
|
|
21
21
|
* @param {string} objectName - The name of the object.
|
|
22
22
|
* @param {HasId[]} records - The records to delete.
|
|
23
23
|
* @returns {Promise<any>} - The response from the delete operation.
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
mutate(params: GraphqlMurationParams): Promise<any>;
|
|
26
|
+
/**
|
|
27
|
+
* Deletes records from the GraphQL API.
|
|
28
|
+
*/
|
|
29
|
+
delete(params: GraphqlMurationParams): Promise<any>;
|
|
26
30
|
/**
|
|
27
31
|
* 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
|
*/
|
|
32
|
-
update(
|
|
33
|
+
update(params: GraphqlMurationParams): Promise<any>;
|
|
33
34
|
/**
|
|
34
35
|
* 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
36
|
*/
|
|
39
|
-
insert(
|
|
37
|
+
insert(params: GraphqlMurationParams): Promise<any>;
|
|
40
38
|
/**
|
|
41
39
|
* Extracts job UIDs from a GraphQL mutation response.
|
|
42
40
|
* @param {MutationResult} response - The response object.
|
|
43
41
|
* @returns {string[]} - An array of job UIDs.
|
|
44
42
|
*/
|
|
45
43
|
extractJobUIDs(response: MutationResult): string[];
|
|
44
|
+
/**
|
|
45
|
+
* Formats the object name to follow GraphQL naming conventions.
|
|
46
|
+
* @param {string} objectName - The object name to format.
|
|
47
|
+
* @returns {string} - The formatted object name.
|
|
48
|
+
*/
|
|
49
|
+
private getQueryName;
|
|
50
|
+
private getQueryHeaders;
|
|
51
|
+
private getMutationHeaders;
|
|
52
|
+
private getOperationHeader;
|
|
46
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __decorate=this&&this.__decorate||function(e,t,
|
|
1
|
+
"use strict";var __decorate=this&&this.__decorate||function(e,t,a,r){var o,n=arguments.length,i=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,a):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,a,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(n<3?o(i):n>3?o(t,a,i):o(t,a))||i);return n>3&&i&&Object.defineProperty(t,a,i),i},__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(o,n){function i(e){try{d(r.next(e))}catch(e){n(e)}}function s(e){try{d(r.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(i,s)}d((r=r.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphQLService=void 0;const constants_1=require("../../constants"),request_header_constants_1=require("../../core/request-header-constants"),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,a,r,o,n,i,s,d,u,c,_,l;e.objectName=this.getQueryName(e.objectName);const p=(0,queries_1.FETCH_RECORDS_QUERY)(e),v=this.getQueryHeaders(e),g=yield this.client.execute(p,v),h={records:(null===(a=null===(t=null==g?void 0:g.data)||void 0===t?void 0:t[e.objectName])||void 0===a?void 0:a.edges.map((e=>e.node)))||[],totalCount:(null===(o=null===(r=null==g?void 0:g.data)||void 0===r?void 0:r[e.objectName])||void 0===o?void 0:o.totalCount)||0,pageInfo:(null===(i=null===(n=null==g?void 0:g.data)||void 0===n?void 0:n[e.objectName])||void 0===i?void 0:i.pageInfo)||{}};if(h.records.length>0){const t=(null===(u=null===(d=null===(s=null==g?void 0:g.data)||void 0===s?void 0:s[e.objectName])||void 0===d?void 0:d.edges)||void 0===u?void 0:u.map((e=>e.offset)))||[],a=(null===(l=null===(_=null===(c=null==g?void 0:g.data)||void 0===c?void 0:c[e.objectName])||void 0===_?void 0:_.edges)||void 0===l?void 0:l.map((e=>e.cursor)))||[];h.endOffset=t[t.length-1],h.endCursor=a[a.length-1]}return h}))}mutate(e){return __awaiter(this,void 0,void 0,(function*(){if(!e.records||0===e.records.length)return Promise.resolve({message:"No records to process"});let t="";switch(e.operation){case constants_1.GraphqlOperations.DELETE:t=(0,queries_1.DELETE_OBJECTS_MUTATION)(e);break;case constants_1.GraphqlOperations.UPDATE:case constants_1.GraphqlOperations.INSERT:t=(0,queries_1.UPSERT_OBJECTS_MUTATION)(e);break;default:throw new Error(`Invalid operation: ${e.operation}`)}const a=this.getMutationHeaders(e);return yield this.client.execute(t,a)}))}delete(e){return __awaiter(this,void 0,void 0,(function*(){return e.operation=constants_1.GraphqlOperations.DELETE,this.mutate(e)}))}update(e){return __awaiter(this,void 0,void 0,(function*(){return e.operation=constants_1.GraphqlOperations.UPDATE,this.mutate(e)}))}insert(e){return __awaiter(this,void 0,void 0,(function*(){return e.operation=constants_1.GraphqlOperations.INSERT,this.mutate(e)}))}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):[]}getQueryName(e){return e.charAt(0).toLowerCase()+e.slice(1)}getQueryHeaders(e){const t=this.getOperationHeader(e.operationName);return e.readOnly&&(t[request_header_constants_1.REQUEST_HEADERS.X_SKEDULO_READ_ONLY]="true"),t}getMutationHeaders(e){const t=this.getOperationHeader(e.operationName);return e.bulkOperation&&(t[request_header_constants_1.REQUEST_HEADERS.X_SKEDULO_BULK_OPERATION]="true"),t}getOperationHeader(e){return{[request_header_constants_1.REQUEST_HEADERS.X_GRAPHQL_OPERATION]:e}}}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",[Object]),__metadata("design:returntype",Promise)],GraphQLService.prototype,"mutate",null),__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],GraphQLService.prototype,"delete",null),__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],GraphQLService.prototype,"update",null),__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],GraphQLService.prototype,"insert",null);
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GraphqlMurationParams, GraphqlQueryParams } from "../../interfaces/graphql";
|
|
2
2
|
/**
|
|
3
3
|
* Constructs a GraphQL query for fetching records with specified parameters.
|
|
4
4
|
*
|
|
5
5
|
* @param params - The query parameters including object name, filter, pagination, ordering, and fields.
|
|
6
6
|
* @returns The constructed GraphQL query string.
|
|
7
7
|
*/
|
|
8
|
-
export declare const FETCH_RECORDS_QUERY: ({ objectName, filter, first, offset, after, orderBy, fields, }:
|
|
8
|
+
export declare const FETCH_RECORDS_QUERY: ({ objectName, operationName, filter, first, offset, after, orderBy, fields, }: GraphqlQueryParams) => string;
|
|
9
9
|
/**
|
|
10
10
|
* Constructs a GraphQL mutation for deleting multiple objects.
|
|
11
11
|
*
|
|
12
12
|
* @param objectName - The name of the object to delete.
|
|
13
|
+
* @param operationName - The graphql operation name.
|
|
13
14
|
* @param records - The records to be deleted.
|
|
14
15
|
* @returns The constructed GraphQL mutation string.
|
|
15
16
|
*/
|
|
16
|
-
export declare const DELETE_OBJECTS_MUTATION: (objectName
|
|
17
|
+
export declare const DELETE_OBJECTS_MUTATION: ({ objectName, operationName, records }: GraphqlMurationParams) => string;
|
|
17
18
|
/**
|
|
18
19
|
* Constructs a GraphQL mutation for upserting (inserting/updating) multiple objects.
|
|
19
20
|
*
|
|
@@ -22,4 +23,4 @@ export declare const DELETE_OBJECTS_MUTATION: (objectName: string, records: HasI
|
|
|
22
23
|
* @param operation - The operation type ("insert" or "update").
|
|
23
24
|
* @returns The constructed GraphQL mutation string.
|
|
24
25
|
*/
|
|
25
|
-
export declare const UPSERT_OBJECTS_MUTATION: (objectName
|
|
26
|
+
export declare const UPSERT_OBJECTS_MUTATION: ({ objectName, operationName, records, operation }: GraphqlMurationParams) => string;
|
|
@@ -1 +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,
|
|
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,operationName:n,filter:t,first:o=200,offset:E=0,after:T,orderBy:r,fields:s})=>`\n query ${n} {\n ${e}(${[t?`filter: "${t}"`:"",T?`after: "${T}"`:"",`first: ${o}`,E?`offset: ${E}`:"",r?`orderBy: "${r}"`:""].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=({objectName:e,operationName:n,records:t})=>`\n mutation ${n} {\n schema {\n ${t.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=({objectName:e,operationName:n,records:t,operation:o})=>`\n mutation ${n} {\n schema {\n ${t.map(((n,t)=>`\n alias${t+1}:${o}${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;
|
package/dist/services/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,
|
|
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("./graph-batch"),exports),__exportStar(require("./graphql"),exports),__exportStar(require("./metadata-service"),exports),__exportStar(require("./resource-availability"),exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __decorate=this&&this.__decorate||function(e,t,r,i){var o,n=arguments.length,a=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,i);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(a=(n<3?o(a):n>3?o(t,r,a):o(t,r))||a);return n>3&&a&&Object.defineProperty(t,r,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,r,i){return new(r||(r=Promise))((function(o,n){function a(e){try{l(i.next(e))}catch(e){n(e)}}function c(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,c)}l((i=i.apply(e,t||[])).next())}))},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LockService=void 0;const logging_1=require("../logging"),logger_1=__importDefault(require("../logging/logger")),KEY_PREFIX="Z_LOCK_";class LockService{constructor(e){this.configVarClient=e}acquireLock(e){return __awaiter(this,void 0,void 0,(function*(){const t="Z_LOCK_"+e.name,r=new Date(Date.now()+e.ttl).toISOString();try{let i=null;try{i=yield this.configVarClient.get(t)}catch(e){}if(i){if(i.expiryDate&&new Date<new Date(i.expiryDate))return!1;yield this.configVarClient.delete(t)}return yield this.configVarClient.create({key:t,value:e.name,configType:"plain-text",description:e.description,expiryDate:r}),!0}catch(t){return logger_1.default.error(`Failed to acquire lock: ${e.name}`),!1}}))}releaseLock(e){return __awaiter(this,void 0,void 0,(function*(){const t="Z_LOCK_"+e;try{let e=null;try{e=yield this.configVarClient.get(t)}catch(e){}e&&(yield this.configVarClient.delete(t))}catch(t){logger_1.default.error(`Failed to release lock: ${e}`)}}))}}exports.LockService=LockService,__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],LockService.prototype,"acquireLock",null),__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],LockService.prototype,"releaseLock",null);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,c){function o(e){try{l(n.next(e))}catch(e){c(e)}}function a(e){try{l(n.throw(e))}catch(e){c(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LockingService=void 0;const KEY_PREFIX="Z_LOCK_";class LockingService{constructor(e){this.configVarClient=e}acquireLock(e){return __awaiter(this,void 0,void 0,(function*(){const t="Z_LOCK_"+e.name,i=new Date(Date.now()+e.ttl).toISOString();try{let n=null;try{n=yield this.configVarClient.get(t)}catch(e){}if(n){if(n.expiryDate&&new Date<new Date(n.expiryDate))return!1;yield this.configVarClient.delete(t)}return yield this.configVarClient.create({key:t,value:e.name,configType:"plain-text",description:e.description,expiryDate:i}),!0}catch(t){return console.error(`Failed to acquire lock: ${e.name}`),!1}}))}releaseLock(e){return __awaiter(this,void 0,void 0,(function*(){const t="Z_LOCK_"+e;try{let e=null;try{e=yield this.configVarClient.get(t)}catch(e){}e&&(yield this.configVarClient.delete(t))}catch(t){console.error(`Failed to release lock: ${e}`)}}))}}exports.LockingService=LockingService;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GraphqlQueryParams } from "../../../interfaces";
|
|
1
2
|
import { GraphQLQueryBuilder, GraphQLService } from "../../graphql";
|
|
2
3
|
import { ResourceQueryParam } from "./resource-query-param";
|
|
3
4
|
export declare class DataService {
|
|
@@ -5,5 +6,5 @@ export declare class DataService {
|
|
|
5
6
|
constructor(graphqlService: GraphQLService);
|
|
6
7
|
getResources(param: ResourceQueryParam): Promise<Record<string, any>[]>;
|
|
7
8
|
getHolidays(regionIds: string[], startTime?: Date, endTime?: Date): Promise<Record<string, any>>;
|
|
8
|
-
newQueryBuilder(
|
|
9
|
+
newQueryBuilder(params: GraphqlQueryParams): GraphQLQueryBuilder;
|
|
9
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,i,
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,a){function r(e){try{c(n.next(e))}catch(e){a(e)}}function o(e){try{c(n.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataService=void 0;const tenant_objects_1=require("../../../core/tenant-objects"),graphql_1=require("../../graphql");class DataService{constructor(e){this.graphqlService=e}getResources(e){return __awaiter(this,void 0,void 0,(function*(){const t=this.newQueryBuilder({objectName:tenant_objects_1.TenantObjects.Resources.Name,operationName:"fetchResourcesWithAvailabilities"});t.withFields(tenant_objects_1.TenantObjects.Resources.Fields).withFilter("IsActive == true"),t.withParentQuery("PrimaryRegion").withFields(tenant_objects_1.TenantObjects.Regions.Fields),e.resourceIds&&e.resourceIds.size>0?t.withFilter(`UID IN ${JSON.stringify(Array.from(e.resourceIds))}`):e.regionIds&&e.regionIds.size>0&&t.withFilter(`PrimaryRegionId IN [${Array.from(e.regionIds).map((e=>`'${e}'`)).join(",")}]`),e.useTag&&t.withChildQuery(tenant_objects_1.TenantObjects.ResourceTags.Name).withParentQuery("Tag").withFields(tenant_objects_1.TenantObjects.Tags.Fields),e.useActivity&&t.withChildQuery(tenant_objects_1.TenantObjects.Activities.Name).withFields(tenant_objects_1.TenantObjects.Activities.Fields),e.useAvailability&&t.withChildQuery(tenant_objects_1.TenantObjects.Availabilities.Name).withFields(tenant_objects_1.TenantObjects.Availabilities.Fields),e.useJobAllocation&&t.withChildQuery(tenant_objects_1.TenantObjects.JobAllocations.Name).withFields(tenant_objects_1.TenantObjects.JobAllocations.Fields).withFilter("Status NOTIN ['Deleted', 'Declined']").withParentQuery("Job").withFields(tenant_objects_1.TenantObjects.Jobs.Fields);return(yield t.execute()).records}))}getHolidays(e,t,i){return __awaiter(this,void 0,void 0,(function*(){const n={},s=t?t.toISOString().split("T")[0]:null,a=i?i.toISOString().split("T")[0]:null,r=this.newQueryBuilder({objectName:tenant_objects_1.TenantObjects.Holidays.Name,operationName:"fetchHolidays"});r.withFields(tenant_objects_1.TenantObjects.Holidays.Fields),r.withFilter("Global == true"),s&&r.withFilter(`EndDate >= ${s}`),a&&r.withFilter(`StartDate <= ${a}`);const o=yield r.execute();if(n.GLOBAL=o.records||[],e&&e.length>0){const t=this.newQueryBuilder({objectName:tenant_objects_1.TenantObjects.Holidays.Name,operationName:"fetchHolidays"});t.withFields(tenant_objects_1.TenantObjects.Holidays.Fields),t.withChildQuery(tenant_objects_1.TenantObjects.HolidayRegions.Name).withFields(tenant_objects_1.TenantObjects.HolidayRegions.Fields).withFilter(`RegionId IN [${e.map((e=>`'${e}'`)).join(",")}]`),s&&t.withFilter(`EndDate >= ${s}`),a&&t.withFilter(`StartDate <= ${a}`);const i=yield t.execute();for(const e of i.records||[])for(const t of e.HolidayRegions||[]){const i=t.RegionId;n[i]||(n[i]=[]),n[i].push(e)}}return n}))}newQueryBuilder(e){const t=new graphql_1.GraphQLQueryBuilder(e);return t.setGraphqlService(this.graphqlService),t}}exports.DataService=DataService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DateTimeUtils=void 0;const
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DateTimeUtils=void 0;const dayjs_1=__importDefault(require("dayjs")),timezone_1=__importDefault(require("dayjs/plugin/timezone")),utc_1=__importDefault(require("dayjs/plugin/utc"));dayjs_1.default.extend(utc_1.default),dayjs_1.default.extend(timezone_1.default);class DateTimeUtils{static toTimezone(t,e){return(0,dayjs_1.default)(t).tz(e).toDate()}static switchTimezone(t,e,a){return e===a?t:(0,dayjs_1.default)(t).tz(e).tz(a).toDate()}static addMinutes(t,e,a){return(0,dayjs_1.default)(t).tz(a).add(e,"minute").toDate()}static addDays(t,e,a){return(0,dayjs_1.default)(t).tz(a).add(e,"day").toDate()}static addMonths(t,e,a){return(0,dayjs_1.default)(t).tz(a).add(e,"month").toDate()}static addYears(t,e,a){return(0,dayjs_1.default)(t).tz(a).add(e,"year").toDate()}static getDate(t,e){return(0,dayjs_1.default)(t).tz(e).startOf("day").toDate()}static getDateFromIsoString(t){return(0,dayjs_1.default)(t).utc().toDate()}static getDateTimeFromIsoString(t){return(0,dayjs_1.default)(t).utc().toDate()}static getStartOfDate(t,e){const a="string"==typeof t?this.getDateFromIsoString(t):t;return(0,dayjs_1.default)(a).tz(e).startOf("day").toDate()}static getEndOfDate(t,e){return this.addDays(this.getStartOfDate(t,e),1,e)}static isIncluding(t,e){return t.start<=e.start&&t.finish>=e.finish}static isOverlapping(t,e){return t.start<e.finish&&t.finish>e.start}static mergeEvents(t){t.sort(((t,e)=>t.start.getTime()-e.start.getTime()));const e=[];let a=null;for(const s of t)a?a.finish>=s.start?(a.finish=s.finish,a.eventType="merged",a.description=a.description?`${a.description}, ${a.name} merged with ${s.name}`:`${a.name} merged with ${s.name}`):(e.push(a),a=s):a=s;return a&&e.push(a),e}}exports.DateTimeUtils=DateTimeUtils;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skedulo/pulse-solution-services",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "A collection of services and utilities to support solution development on the Pulse platform.",
|
|
5
5
|
"author": "Skedulo",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
],
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@tsconfig/node18": "^18.2.2",
|
|
26
|
+
"@types/uuid": "^10.0.0",
|
|
26
27
|
"@typescript-eslint/eslint-plugin": "^8.11.0",
|
|
27
28
|
"@typescript-eslint/parser": "^8.11.0",
|
|
28
29
|
"dts-bundle-generator": "^9.5.1",
|
|
@@ -37,10 +38,13 @@
|
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
40
|
"@skedulo/function-utilities": "^0.0.6",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
41
|
+
"dayjs": "^1.11.13",
|
|
42
|
+
"p-queue": "^8.1.0",
|
|
43
|
+
"timezone": "^1.0.23",
|
|
42
44
|
"typescript": "~5.6.3",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
+
"utc": "^0.1.0",
|
|
46
|
+
"uuid": "8",
|
|
47
|
+
"winston": "^3.17.0",
|
|
48
|
+
"zod": "^3.24.2"
|
|
45
49
|
}
|
|
46
50
|
}
|