@skedulo/pulse-solution-services 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/README.md +321 -25
  3. package/dist/clients/artifact-client.js +1 -1
  4. package/dist/clients/availability-api-client.js +1 -0
  5. package/dist/clients/base-client.js +1 -1
  6. package/dist/clients/geo-api-client.js +1 -0
  7. package/dist/clients/graphql-client.js +1 -1
  8. package/dist/constants/graphql-constants.js +1 -0
  9. package/dist/constants/index.js +1 -1
  10. package/dist/constants/tenant-endpoints.js +1 -1
  11. package/dist/core/entity-factory.js +1 -0
  12. package/dist/core/execution-context.js +1 -1
  13. package/dist/core/execution-options.js +1 -0
  14. package/dist/core/index.js +1 -1
  15. package/dist/core/request-context.js +1 -0
  16. package/dist/core/request-header-constants.js +1 -0
  17. package/dist/core/tenant-objects.js +1 -0
  18. package/dist/index.d.ts +708 -151
  19. package/dist/interfaces/api-client.js +1 -0
  20. package/dist/interfaces/availability.js +1 -0
  21. package/dist/interfaces/geoservice-interfaces.js +1 -0
  22. package/dist/interfaces/index.js +1 -1
  23. package/dist/services/batch-processor/fetching-strategies/cursor-based-fetching-strategy.js +1 -1
  24. package/dist/services/batch-processor/fetching-strategies/date-based-fetching-strategy.js +1 -1
  25. package/dist/services/geoservice.js +1 -0
  26. package/dist/services/graph-batch/graph-batch-config.d.ts +34 -0
  27. package/dist/services/graph-batch/graph-batch-config.js +1 -0
  28. package/dist/services/graph-batch/graph-batch.d.ts +56 -0
  29. package/dist/services/graph-batch/graph-batch.js +1 -0
  30. package/dist/services/graph-batch/index.d.ts +3 -0
  31. package/dist/services/graph-batch/index.js +1 -0
  32. package/dist/services/graph-batch/pagination-strategy.d.ts +5 -0
  33. package/dist/services/graph-batch/pagination-strategy.js +1 -0
  34. package/dist/services/graphql/graphql-query-builder.d.ts +17 -28
  35. package/dist/services/graphql/graphql-query-builder.js +1 -1
  36. package/dist/services/graphql/graphql-service.d.ts +20 -13
  37. package/dist/services/graphql/graphql-service.js +1 -1
  38. package/dist/services/graphql/queries.d.ts +5 -4
  39. package/dist/services/graphql/queries.js +1 -1
  40. package/dist/services/index.js +1 -1
  41. package/dist/services/resource-availability/builder/data-service.d.ts +10 -0
  42. package/dist/services/resource-availability/builder/data-service.js +1 -0
  43. package/dist/services/resource-availability/builder/index.d.ts +3 -0
  44. package/dist/services/resource-availability/builder/index.js +1 -0
  45. package/dist/services/resource-availability/builder/resource-availability-service.d.ts +8 -0
  46. package/dist/services/resource-availability/builder/resource-availability-service.js +1 -0
  47. package/dist/services/resource-availability/builder/resource-builder.d.ts +17 -0
  48. package/dist/services/resource-availability/builder/resource-builder.js +1 -0
  49. package/dist/services/resource-availability/builder/resource-query-param.d.ts +23 -0
  50. package/dist/services/resource-availability/builder/resource-query-param.js +1 -0
  51. package/dist/services/resource-availability/index.d.ts +2 -0
  52. package/dist/services/resource-availability/index.js +1 -0
  53. package/dist/services/resource-availability/validator/index.d.ts +3 -0
  54. package/dist/services/resource-availability/validator/index.js +1 -0
  55. package/dist/services/resource-availability/validator/resource-job-validation.d.ts +11 -0
  56. package/dist/services/resource-availability/validator/resource-job-validation.js +1 -0
  57. package/dist/services/resource-availability/validator/resource-validation-option.d.ts +5 -0
  58. package/dist/services/resource-availability/validator/resource-validation-option.js +1 -0
  59. package/dist/services/resource-availability/validator/resource-validator.d.ts +13 -0
  60. package/dist/services/resource-availability/validator/resource-validator.js +1 -0
  61. package/dist/services/resource-availability/validator/validation-result.d.ts +12 -0
  62. package/dist/services/resource-availability/validator/validation-result.js +1 -0
  63. package/dist/utils/datetime-utils.js +1 -0
  64. package/dist/utils/index.js +1 -1
  65. package/package.json +7 -2
  66. package/yarn.lock +38 -0
  67. package/dist/clients/artifacts/artifact-client.d.ts +0 -19
  68. package/dist/clients/artifacts/artifact-client.js +0 -1
  69. package/dist/clients/artifacts/base-artifact-client.d.ts +0 -14
  70. package/dist/clients/artifacts/base-artifact-client.js +0 -1
  71. package/dist/clients/artifacts/object-based-artifact-client.d.ts +0 -11
  72. package/dist/clients/artifacts/object-based-artifact-client.js +0 -1
  73. package/dist/clients/custom-field-client.js +0 -1
  74. package/dist/clients/custom-schema-client.js +0 -1
  75. package/dist/constants/artifact.js +0 -1
  76. package/dist/constants/config-var.js +0 -1
  77. package/dist/constants/config-variable-constants.js +0 -1
  78. package/dist/constants/mobile-notification.js +0 -1
  79. package/dist/constants/tenant-objects.js +0 -1
  80. /package/dist/{interfaces/custom-field.js → core/base-config.js} +0 -0
  81. /package/dist/{interfaces/custom-schema.js → core/tenant-entities.js} +0 -0
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
@@ -1 +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-template"),exports),__exportStar(require("./config-var"),exports),__exportStar(require("./graphql"),exports),__exportStar(require("./metadata"),exports),__exportStar(require("./mobile-notification"),exports);
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("../core/tenant-entities"),exports),__exportStar(require("./api-client"),exports),__exportStar(require("./availability"),exports),__exportStar(require("./config-template"),exports),__exportStar(require("./config-var"),exports),__exportStar(require("./geoservice-interfaces"),exports),__exportStar(require("./graphql"),exports),__exportStar(require("./metadata"),exports),__exportStar(require("./mobile-notification"),exports);
@@ -1 +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}))}};
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(t,e,o,r){return new(o||(o=Promise))((function(a,i){function n(t){try{s(r.next(t))}catch(t){i(t)}}function c(t){try{s(r.throw(t))}catch(t){i(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(n,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,i,n;const c=t.contextData.job.BatchSize||200,s=(t.contextData.job.Fields||"UID").split(",").map((t=>t.trim()));s.includes("UID")||s.push("UID");let u={objectName:t.contextData.job.ObjectName,operationName:t.contextData.job.ObjectName,first:c,orderBy:t.contextData.job.OrderBy,after:null===(o=null===(e=t.contextData.batchState)||void 0===e?void 0:e.processor)||void 0===o?void 0:o.cursor,filter:t.contextData.job.FilterCondition,fields:s.join("\n")};const d=t.newQueryBuilder(u);d.withFields(s).withLimit(c).withOrderBy(t.contextData.job.OrderBy).withFilter(t.contextData.job.FilterCondition);const l=yield t.graphqlService.query(d.build()),h=l.records,v=l.endCursor;return null===(i=null===(a=null===(r=t.contextData.batchState)||void 0===r?void 0:r.processor)||void 0===a?void 0:a.allCursors)||void 0===i||i.push(v),(null===(n=t.contextData.batchState)||void 0===n?void 0:n.processor)&&(t.contextData.batchState.processor.cursor=v),h}))}};
@@ -1 +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}))}};
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,operationName:t.ObjectName,first:n,filter:i,orderBy:r,fields:a.join("\n")})).records}))}};
@@ -0,0 +1 @@
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(r,n){function o(e){try{l(s.next(e))}catch(e){n(e)}}function a(e){try{l(s.throw(e))}catch(e){n(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((s=s.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GeoService=void 0;const uuid_1=require("uuid");class GeoService{constructor(e){this.sessionId="",this.geoAPIClient=e,this.sessionId=this.generateNewSessionId()}getDistanceMatrix(e,t){return __awaiter(this,void 0,void 0,(function*(){const i=e.map((e=>({lat:parseFloat(this.stripTrailingZeros(e.lat)),lng:parseFloat(this.stripTrailingZeros(e.lng))}))),s=t.map((e=>({lat:parseFloat(this.stripTrailingZeros(e.lat)),lng:parseFloat(this.stripTrailingZeros(e.lng))}))),r=yield this.geoAPIClient.getDistanceMatrix({origins:i,destinations:s});if(!r||!r.matrix||0===r.matrix.length)throw new Error("Failed to retrieve distance matrix data");const n=new Map;for(let o=0;o<e.length;o++)for(let e=0;e<t.length;e++){const t=this.createKey(i[o],s[e]),a=r.matrix[o][e];n.set(t,a)}return n}))}getAddressSuggestions(e){return __awaiter(this,arguments,void 0,(function*(e,t=1){const i=e.sessionId||this.sessionId;e.sessionId||(e.sessionId=this.sessionId);const s=yield this.geoAPIClient.autocompleteAddress(e);if(0===s.predictions.length)return null;const r=s.predictions.slice(0,t);return Promise.all(r.map((e=>this.geoAPIClient.getPlaceDetails({placeId:e.placeId,sessionId:i}))))}))}getTimezone(e){return __awaiter(this,void 0,void 0,(function*(){return(yield this.geoAPIClient.getTimezone(e)).timeZoneId}))}generateNewSessionId(){return(0,uuid_1.v4)()}stripTrailingZeros(e){return parseFloat(e.toFixed(8)).toString()}createKey(e,t){return`${this.stripTrailingZeros(e.lat)},${this.stripTrailingZeros(e.lng)}-${this.stripTrailingZeros(t.lat)},${this.stripTrailingZeros(t.lng)}`}}exports.GeoService=GeoService;
@@ -0,0 +1,34 @@
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
+ 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;
34
+ export {};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_GRAPH_BATCH_CONFIG=void 0,exports.initializeConfig=initializeConfig;const zod_1=require("zod"),pagination_strategy_1=require("./pagination-strategy");exports.DEFAULT_GRAPH_BATCH_CONFIG={strategy:pagination_strategy_1.PaginationStrategy.NONE,batchSize:200,maxBatches:100,delaySeconds:0};const 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)});function initializeConfig(t){return GraphBatchConfigSchema.parse(Object.assign(Object.assign({},exports.DEFAULT_GRAPH_BATCH_CONFIG),t))}
@@ -0,0 +1,56 @@
1
+ import { ExecutionContext } from "../../core";
2
+ import { QueryResult } from "../../interfaces";
3
+ import { GraphQLQueryBuilder } from "../graphql";
4
+ import { GraphBatchConfig } from "./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("./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 Promise.all([]),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,3 @@
1
+ export * from "./graph-batch";
2
+ export * from "./graph-batch-config";
3
+ export * from "./pagination-strategy";
@@ -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("./graph-batch"),exports),__exportStar(require("./graph-batch-config"),exports),__exportStar(require("./pagination-strategy"),exports);
@@ -0,0 +1,5 @@
1
+ export declare enum PaginationStrategy {
2
+ CURSOR = "cursor",
3
+ OFFSET = "offset",
4
+ NONE = "none"
5
+ }
@@ -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={}));
@@ -1,10 +1,11 @@
1
- import { FetchRecordsQueryParams, QueryResult } from "../../interfaces/graphql";
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,75 +16,63 @@ 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} objectName - The name of the object being queried.
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(objectName: string, isParent?: boolean);
25
+ constructor(queryParams: GraphqlQueryParams, isParent?: boolean);
24
26
  /**
25
27
  * Sets the GraphQL service to use for executing the query.
26
- * @param {GraphQLService} graphqlService - The GraphQL service instance.
27
- * @returns {void}
28
28
  */
29
29
  setGraphqlService(graphqlService: GraphQLService): void;
30
30
  /**
31
- * Specifies the fields to be retrieved.
32
- * @param {string[]} fields - The list of fields to select.
33
- * @returns {this} - The query builder instance.
31
+ * Specifies the fields to be retrieved. Prevents duplicates.
34
32
  */
35
33
  withFields(fields: string[]): this;
36
34
  /**
37
35
  * Adds a filter condition to the query.
38
- * @param {string} condition - The filter condition.
39
- * @returns {this} - The query builder instance.
40
36
  */
41
37
  withFilter(condition: string): this;
42
38
  /**
43
39
  * Sets a limit on the number of records to retrieve.
44
- * @param {number} first - The number of records to fetch.
45
- * @returns {this} - The query builder instance.
46
40
  */
47
41
  withLimit(first: number): this;
48
42
  /**
49
43
  * Sets an offset for pagination.
50
- * @param {number} offset - The offset value.
51
- * @returns {this} - The query builder instance.
52
44
  */
53
45
  withOffset(offset: number): this;
54
46
  /**
55
47
  * Sets the order in which records should be retrieved.
56
- * @param {string} orderBy - The field to order by.
57
- * @returns {this} - The query builder instance.
58
48
  */
59
49
  withOrderBy(orderBy: string): this;
60
50
  /**
61
51
  * Applies cursor-based pagination.
62
- * @param {string} after - The cursor position.
63
- * @returns {this} - The query builder instance.
64
52
  */
65
53
  withCursor(after: string): this;
66
54
  /**
67
55
  * Creates a parent query.
68
- * @param {string} objectName - The name of the parent object.
69
- * @returns {GraphQLQueryBuilder} - A new query builder instance for the parent.
70
56
  */
71
57
  withParentQuery(objectName: string): GraphQLQueryBuilder;
72
58
  /**
73
59
  * Creates a child query.
74
- * @param {string} objectName - The name of the child object.
75
- * @returns {GraphQLQueryBuilder} - A new query builder instance for the child.
76
60
  */
77
61
  withChildQuery(objectName: string): GraphQLQueryBuilder;
78
62
  /**
79
- * Builds the GraphQL query parameters.
80
- * @returns {FetchRecordsQueryParams} - The formatted query parameters.
63
+ * Recursively builds the GraphQL query fields, handling nested queries.
81
64
  */
82
- build(): FetchRecordsQueryParams;
65
+ private formatQueryFields;
83
66
  /**
84
- * Executes the query using the GraphQL service.
85
- * @returns {Promise<QueryResult>} - The query result.
86
- * @throws {Error} - If no GraphQL service is set.
67
+ * Builds the GraphQL query parameters in a more structured format.
68
+ */
69
+ build(): GraphqlQueryParams;
70
+ /**
71
+ * Executes the query using the GraphQL service, with improved error handling.
87
72
  */
88
73
  execute(): Promise<QueryResult>;
74
+ /**
75
+ * Generates a string representation of the GraphQL query for debugging.
76
+ */
77
+ toString(): string;
89
78
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphQLQueryBuilder=void 0;class GraphQLQueryBuilder{constructor(r,e=!1){this.fields=[],this.filters=[],this.parentQueries={},this.childQueries={},this.graphqlService=null,this.objectName=r.charAt(0).toLowerCase()+r.slice(1),this.isParent=e}setGraphqlService(r){this.graphqlService=r}withFields(r){return this.fields.push(...r),this}withFilter(r){if(this.isParent)throw new Error("Cannot apply filters to a parent query.");return this.filters.push(r),this}withLimit(r){if(this.isParent)throw new Error("Cannot apply limit to a parent query.");return this.first=r,this}withOffset(r){if(this.isParent)throw new Error("Cannot apply offset to a parent query.");return this.offset=r,this}withOrderBy(r){if(this.isParent)throw new Error("Cannot apply orderBy to a parent query.");return this.orderBy=r,this}withCursor(r){if(this.isParent)throw new Error("Cannot apply cursor to a parent query.");return this.after=r,this}withParentQuery(r){const e=new GraphQLQueryBuilder(r,!0);return this.parentQueries[r]=e,e}withChildQuery(r){const e=new GraphQLQueryBuilder(r);return this.childQueries[r]=e,e}build(){const r=Object.entries(this.parentQueries).map((([r,e])=>`${r} { ${e.build().fields} }`)),e=Object.entries(this.childQueries).map((([r,e])=>{const t=e.build();return`${r}${t.filter?` (filter: "${t.filter}")`:""} { ${t.fields} }`}));return{objectName:this.objectName,fields:[...this.fields,...r,...e].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}}execute(){if(!this.graphqlService)throw new Error("No GraphQL service set for query execution.");return this.graphqlService.query(this.build())}}exports.GraphQLQueryBuilder=GraphQLQueryBuilder;
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 { FetchRecordsQueryParams, HasId, MutationResult, QueryResult } from "../../interfaces/graphql";
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 {FetchRecordsQueryParams} params - The query parameters.
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: FetchRecordsQueryParams): Promise<QueryResult>;
18
+ query(params: GraphqlQueryParams): Promise<QueryResult>;
19
19
  /**
20
- * Deletes records from the GraphQL API.
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
- delete(objectName: string, records: HasId[]): Promise<any>;
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(objectName: string, records: HasId[]): Promise<any>;
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(objectName: string, records: HasId[]): Promise<any>;
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,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);
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 { FetchRecordsQueryParams, HasId } from "../../interfaces/graphql";
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, }: FetchRecordsQueryParams) => string;
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: string, records: HasId[]) => string;
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: string, records: HasId[], operation: string) => string;
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,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;
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;
@@ -1 +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);
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,10 @@
1
+ import { GraphqlQueryParams } from "../../../interfaces";
2
+ import { GraphQLQueryBuilder, GraphQLService } from "../../graphql";
3
+ import { ResourceQueryParam } from "./resource-query-param";
4
+ export declare class DataService {
5
+ private graphqlService;
6
+ constructor(graphqlService: GraphQLService);
7
+ getResources(param: ResourceQueryParam): Promise<Record<string, any>[]>;
8
+ getHolidays(regionIds: string[], startTime?: Date, endTime?: Date): Promise<Record<string, any>>;
9
+ newQueryBuilder(params: GraphqlQueryParams): GraphQLQueryBuilder;
10
+ }
@@ -0,0 +1 @@
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;
@@ -0,0 +1,3 @@
1
+ export * from "./resource-availability-service";
2
+ export * from "./resource-builder";
3
+ export * from "./resource-query-param";
@@ -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("./resource-availability-service"),exports),__exportStar(require("./resource-builder"),exports),__exportStar(require("./resource-query-param"),exports);
@@ -0,0 +1,8 @@
1
+ import { AvailabilityAPIClient } from "../../../clients/availability-api-client";
2
+ import { BaseEvent } from "../../../interfaces";
3
+ import { ResourceQueryParam } from "./resource-query-param";
4
+ export declare class ResourceAvailabilityService {
5
+ private availabilityAPIClient;
6
+ constructor(availabilityAPIClient: AvailabilityAPIClient);
7
+ getAvailabilityPatterns(param: ResourceQueryParam): Promise<Map<string, BaseEvent[]>>;
8
+ }
@@ -0,0 +1 @@
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,t,i,r){return new(i||(i=Promise))((function(a,n){function s(e){try{c(r.next(e))}catch(e){n(e)}}function o(e){try{c(r.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,o)}c((r=r.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResourceAvailabilityService=void 0;class ResourceAvailabilityService{constructor(e){this.availabilityAPIClient=e}getAvailabilityPatterns(e){return __awaiter(this,void 0,void 0,(function*(){const t=yield this.availabilityAPIClient.fetchAvailability({resourceIds:Array.from(e.resourceIds||[]),start:e.startTime.toISOString(),end:e.endTime.toISOString(),mergedAvailabilities:!1,entries:!0}),i=new Map;return t.forEach((e=>{if(!e.entries)return;const t=e.entries.filter((e=>"pattern"===e.type)).map((e=>({id:`${e.start}_${e.end}`,name:`${e.name}(${e.type})`,start:e.start?new Date(e.start):new Date(0),finish:e.end?new Date(e.end):new Date(0),eventType:e.type})));i.set(e.resourceId,t)})),i}))}}exports.ResourceAvailabilityService=ResourceAvailabilityService;
@@ -0,0 +1,17 @@
1
+ import { Resource } from "../../../core/tenant-entities";
2
+ import { DataService } from "./data-service";
3
+ import { ResourceAvailabilityService } from "./resource-availability-service";
4
+ import { ResourceQueryParam } from "./resource-query-param";
5
+ export declare class ResourceBuilder {
6
+ private dataService;
7
+ private availabilityService;
8
+ constructor(dataService: DataService, availabilityService: ResourceAvailabilityService);
9
+ build(queryParam: ResourceQueryParam): Promise<Resource[]>;
10
+ private loadAvailabilityPatterns;
11
+ private loadActivityEvents;
12
+ private loadAvailabilityEvents;
13
+ private loadJobAllocationEvents;
14
+ private loadResourceShiftEvents;
15
+ private loadHolidayEvents;
16
+ protected buildMore(resources: Resource[]): Resource[];
17
+ }
@@ -0,0 +1 @@
1
+ "use strict";var __decorate=this&&this.__decorate||function(e,t,i,a){var r,s=arguments.length,o=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,i):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,a);else for(var n=e.length-1;n>=0;n--)(r=e[n])&&(o=(s<3?r(o):s>3?r(t,i,o):r(t,i))||o);return s>3&&o&&Object.defineProperty(t,i,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,i,a){return new(i||(i=Promise))((function(r,s){function o(e){try{l(a.next(e))}catch(e){s(e)}}function n(e){try{l(a.throw(e))}catch(e){s(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,n)}l((a=a.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResourceBuilder=void 0;const entity_factory_1=require("../../../core/entity-factory"),logging_1=require("../../../logging"),utils_1=require("../../../utils"),resource_query_param_1=require("./resource-query-param");class ResourceBuilder{constructor(e,t){this.dataService=e,this.availabilityService=t}build(e){return __awaiter(this,void 0,void 0,(function*(){var t,i;if(!e)throw new Error("ResourceBuilder Error: queryParam is required");const a=[],r=yield this.dataService.getResources(e);e.resourceIds&&0!==e.resourceIds.size||(e.resourceIds=new Set(r.map((e=>e.UID))));for(const t of r){const i=entity_factory_1.EntityFactory.createResource(t);a.push(i),e.useActivity&&this.loadActivityEvents(t,i),e.useAvailability&&this.loadAvailabilityEvents(t,i),e.useJobAllocation&&this.loadJobAllocationEvents(t,i),e.useResourceShift&&this.loadResourceShiftEvents(t,i),e.useHoliday&&this.loadHolidayEvents(i,e)}e.useAvailabilityPattern&&(yield this.loadAvailabilityPatterns(a,e));for(const r of a)e.mergeAvailability?r.availabilities=utils_1.DateTimeUtils.mergeEvents(r.availabilities):null===(t=r.availabilities)||void 0===t||t.sort(((e,t)=>e.start.getTime()-t.start.getTime())),e.mergeEvents?r.events=utils_1.DateTimeUtils.mergeEvents(r.events):null===(i=r.events)||void 0===i||i.sort(((e,t)=>e.start.getTime()-t.start.getTime()));return this.buildMore(a)}))}loadAvailabilityPatterns(e,t){return __awaiter(this,void 0,void 0,(function*(){const i=yield this.availabilityService.getAvailabilityPatterns(t);for(const t of e)t.availabilities.push(...i.get(t.id)||[])}))}loadActivityEvents(e,t){e.Activities&&t.events.push(...e.Activities.map((e=>({id:e.UID,name:e.Name,start:new Date(e.Start),finish:new Date(e.End),eventType:"activity"}))))}loadAvailabilityEvents(e,t){if(e.availabilities){const i=[],a=[];e.Availabilities.forEach((e=>{e.IsAvailable?i.push(entity_factory_1.EntityFactory.createBaseEvent(e)):a.push(entity_factory_1.EntityFactory.createBaseEvent(e))})),t.availabilities=i,t.events.push(...a)}}loadJobAllocationEvents(e,t){e.JobAllocations&&t.events.push(...e.JobAllocations.map((e=>({id:e.UID,name:e.Name,start:e.Start?new Date(e.Start):void 0,finish:e.End?new Date(e.End):void 0,eventType:"job_allocation"}))))}loadResourceShiftEvents(e,t){e.resourceShifts&&t.events.push(...e.resourceShifts.map((e=>({id:e.id,name:e.name,start:e.start?new Date(e.start):new Date(0),finish:e.finish?new Date(e.finish):new Date(0),eventType:"resource_shift"}))))}loadHolidayEvents(e,t){return __awaiter(this,void 0,void 0,(function*(){const i=yield this.dataService.getHolidays(Array.from(t.regionIds||[]),t.startTime,t.endTime),a=i.GLOBAL||[];i[e.regionId]&&a.push(...i[e.regionId]),a.forEach((i=>{let a=utils_1.DateTimeUtils.getStartOfDate(i.StartDate,e.timezone),r=utils_1.DateTimeUtils.getEndOfDate(i.EndDate,e.timezone);a<t.startTime&&(a=t.startTime),r>t.endTime&&(r=t.endTime),e.events.push({id:`${a.toISOString()}_${r.toISOString()}`,name:i.Name,start:a,finish:r,eventType:"holiday"})}))}))}buildMore(e){return e}}exports.ResourceBuilder=ResourceBuilder,__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[resource_query_param_1.ResourceQueryParam]),__metadata("design:returntype",Promise)],ResourceBuilder.prototype,"build",null);
@@ -0,0 +1,23 @@
1
+ export declare class ResourceQueryParam {
2
+ resourceIds?: Set<string>;
3
+ regionIds?: Set<string>;
4
+ startTime: Date;
5
+ endTime: Date;
6
+ timezone: string;
7
+ respectResourceTimezone: boolean;
8
+ mergeAvailability: boolean;
9
+ mergeEvents: boolean;
10
+ useTag: boolean;
11
+ useJobAllocation: boolean;
12
+ useResourceShift: boolean;
13
+ useActivity: boolean;
14
+ useAvailability: boolean;
15
+ useAvailabilityTemplate: boolean;
16
+ useAvailabilityPattern: boolean;
17
+ useHoliday: boolean;
18
+ excludedJAStatus: Set<string>;
19
+ excludedJobStatus: Set<string>;
20
+ availabilityStatus: Set<string>;
21
+ resourceTypes: Set<string>;
22
+ constructor();
23
+ }
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResourceQueryParam=void 0;class ResourceQueryParam{constructor(){this.useJobAllocation=!0,this.useResourceShift=!0,this.useActivity=!0,this.useAvailability=!0,this.useHoliday=!0,this.mergeAvailability=!0,this.excludedJAStatus=new Set(["Deleted","Declined"]),this.excludedJobStatus=new Set(["Cancelled"]),this.availabilityStatus=new Set(["Approved"]),this.resourceTypes=new Set(["Person","Asset"]),this.useTag=!0,this.startTime=new Date,this.endTime=new Date(Date.now()+12096e5),this.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone,this.respectResourceTimezone=!0,this.mergeEvents=!1,this.useAvailabilityTemplate=!1,this.useAvailabilityPattern=!0}}exports.ResourceQueryParam=ResourceQueryParam;
@@ -0,0 +1,2 @@
1
+ export * from "./builder";
2
+ export * from "./validator";
@@ -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("./builder"),exports),__exportStar(require("./validator"),exports);
@@ -0,0 +1,3 @@
1
+ export * from "./resource-job-validation";
2
+ export * from "./resource-validator";
3
+ export * from "./validation-result";
@@ -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("./resource-job-validation"),exports),__exportStar(require("./resource-validator"),exports),__exportStar(require("./validation-result"),exports);
@@ -0,0 +1,11 @@
1
+ import { BaseEvent, Job, Resource, Tag } from "../../../interfaces";
2
+ import { ResourceValidationOption } from "./resource-validation-option";
3
+ export declare class ResourceJobValidation {
4
+ resource: Partial<Resource>;
5
+ job: Partial<Job>;
6
+ availableEvent: BaseEvent | null;
7
+ conflictEvents: BaseEvent[];
8
+ missingTags: Tag[];
9
+ constructor(resource: Partial<Resource>, job: Partial<Job>, availableEvent?: BaseEvent | null, conflictEvents?: BaseEvent[], missingTags?: Tag[]);
10
+ isQualified(option: ResourceValidationOption): boolean;
11
+ }
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResourceJobValidation=void 0;class ResourceJobValidation{constructor(e,i,s=null,t=[],o=[]){this.resource=e,this.job=i,this.availableEvent=s,this.conflictEvents=t,this.missingTags=o,this.resource={id:e.id,name:e.name},this.job={id:i.id,name:i.name}}isQualified(e){return!(e.checkAvailability&&null===this.availableEvent||e.checkConflict&&0!==this.conflictEvents.length||e.checkTag&&0!==this.missingTags.length)}}exports.ResourceJobValidation=ResourceJobValidation;
@@ -0,0 +1,5 @@
1
+ export interface ResourceValidationOption {
2
+ checkAvailability: boolean;
3
+ checkConflict: boolean;
4
+ checkTag: boolean;
5
+ }
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1,13 @@
1
+ import { Job, Resource } from "../../../interfaces";
2
+ import { ResourceValidationOption } from "./resource-validation-option";
3
+ import { ValidationResult } from "./validation-result";
4
+ export declare class ResourceValidator {
5
+ private readonly option;
6
+ constructor(option: ResourceValidationOption);
7
+ validate(resources: Resource[], jobs: Job[]): ValidationResult;
8
+ private validateResource;
9
+ private findAvailableEvent;
10
+ private findConflictingEvents;
11
+ private findMissingTags;
12
+ private prepareData;
13
+ }
@@ -0,0 +1 @@
1
+ "use strict";var __decorate=this&&this.__decorate||function(t,e,i,a){var o,r=arguments.length,n=r<3?e:null===a?a=Object.getOwnPropertyDescriptor(e,i):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,a);else for(var s=t.length-1;s>=0;s--)(o=t[s])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n},__metadata=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResourceValidator=void 0;const logging_1=require("../../../logging"),utils_1=require("../../../utils"),resource_job_validation_1=require("./resource-job-validation"),validation_result_1=require("./validation-result");class ResourceValidator{constructor(t){this.option=t}validate(t,e){if(!t.length||!e.length)throw new Error("ResourceValidator Error: Resources and jobs must be provided before validation.");this.prepareData(t,e);const i=[];for(const a of e)for(const e of t)i.push(this.validateResource(e,a));return new validation_result_1.ValidationResult(i,this.option)}validateResource(t,e){const i=new resource_job_validation_1.ResourceJobValidation(t,e);return this.option.checkAvailability&&(i.availableEvent=this.findAvailableEvent(t,e)),this.option.checkConflict&&(i.conflictEvents=this.findConflictingEvents(t,e)),this.option.checkTag&&(i.missingTags=this.findMissingTags(t,e)),i}findAvailableEvent(t,e){return t.availabilities.find((t=>utils_1.DateTimeUtils.isIncluding(t,e)))||null}findConflictingEvents(t,e){return t.events.filter((t=>t.id!==e.id&&utils_1.DateTimeUtils.isOverlapping(t,e)))}findMissingTags(t,e){if(!e.tags||!t.tags)return[];const i=new Set(t.tags.map((t=>t.id)));return e.tags.filter((t=>!i.has(t.id)))}prepareData(t,e){for(const e of t)e.tags||(e.tags=[]);for(const t of e)t.id||(t.id=`${t.start}-${t.finish}`),t.name||(t.name=`${t.start}-${t.finish}`),t.tags||(t.tags=[])}}exports.ResourceValidator=ResourceValidator,__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[Array,Array]),__metadata("design:returntype",validation_result_1.ValidationResult)],ResourceValidator.prototype,"validate",null);