@skedulo/pulse-solution-services 0.0.15 → 0.0.17

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 (42) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +113 -9
  3. package/dist/clients/artifact-client.js +1 -1
  4. package/dist/clients/availability-api-client.js +1 -1
  5. package/dist/clients/base-client.js +1 -1
  6. package/dist/clients/config-features-client.js +1 -1
  7. package/dist/clients/config-template-client.js +1 -1
  8. package/dist/clients/config-var-client.js +1 -1
  9. package/dist/clients/files-api-client.js +1 -1
  10. package/dist/clients/geo-api-client.js +1 -1
  11. package/dist/clients/graphql-client.js +1 -1
  12. package/dist/clients/metadata-client.js +1 -1
  13. package/dist/clients/mobile-notification-client.js +1 -1
  14. package/dist/clients/org-preference-client.js +1 -1
  15. package/dist/clients/vocabulary-client.js +1 -1
  16. package/dist/index.d.ts +98 -36
  17. package/dist/logging/decorators/log-method.js +1 -1
  18. package/dist/monitoring/decorators/monitor-call.js +1 -1
  19. package/dist/monitoring/monitoring-manager.js +1 -1
  20. package/dist/services/cache/cache-service.js +1 -1
  21. package/dist/services/cache/storage/config-var-cache-storage.js +1 -1
  22. package/dist/services/cache/storage/in-memory-cache-storage.js +1 -1
  23. package/dist/services/geoservice.js +1 -1
  24. package/dist/services/graph-batch/graph-batch.js +1 -1
  25. package/dist/services/graph-batch/unique-graph-batch.js +1 -1
  26. package/dist/services/graphql/graphql-batch-builder.d.ts +138 -0
  27. package/dist/services/graphql/graphql-batch-builder.js +1 -0
  28. package/dist/services/graphql/graphql-query-batch.d.ts +10 -0
  29. package/dist/services/graphql/graphql-query-batch.js +1 -0
  30. package/dist/services/graphql/graphql-query-builder.d.ts +11 -3
  31. package/dist/services/graphql/graphql-query-builder.js +1 -1
  32. package/dist/services/graphql/graphql-service.d.ts +78 -25
  33. package/dist/services/graphql/graphql-service.js +1 -1
  34. package/dist/services/graphql/queries.d.ts +13 -19
  35. package/dist/services/graphql/queries.js +1 -1
  36. package/dist/services/lock-service.js +1 -1
  37. package/dist/services/metadata-service.js +1 -1
  38. package/dist/services/resource-availability/builder/data-service.js +1 -1
  39. package/dist/services/resource-availability/builder/resource-availability-service.js +1 -1
  40. package/dist/services/resource-availability/builder/resource-builder.js +1 -1
  41. package/package.json +2 -2
  42. package/yarn.lock +642 -517
@@ -1,53 +1,106 @@
1
1
  import { GraphQLClient } from "../../clients/graphql-client";
2
- import { GraphqlMurationParams, GraphqlQueryParams, MutationResult, QueryResult } from "../../interfaces/graphql";
2
+ import { GraphqlMutationParams, GraphqlQueryParams, MutationResult, QueryResult } from "../../interfaces/graphql";
3
+ import { GraphQLQueryBuilder } from "./graphql-query-builder";
3
4
  /**
4
- * A service class for handling GraphQL operations.
5
+ * Service for executing GraphQL queries and mutations.
5
6
  */
6
7
  export declare class GraphQLService {
7
8
  private client;
8
9
  /**
9
- * Creates an instance of GraphQLService.
10
- * @param {GraphQLClient} client - The GraphQL client to use for queries and mutations.
10
+ * Constructor to initialize the GraphQL client.
11
+ * @param {GraphQLClient} client - The GraphQL client instance.
11
12
  */
12
13
  constructor(client: GraphQLClient);
13
14
  /**
14
- * Executes a GraphQL query to fetch records.
15
- * @param {GraphqlQueryParams} params - The query parameters.
16
- * @returns {Promise<QueryResult>} - The query result including records, total count, page info, and cursors.
15
+ * Executes a GraphQL query.
16
+ * @param {GraphqlQueryParams} params - The parameters for the GraphQL query.
17
+ * @returns {Promise<QueryResult>} - The query result containing records and pagination info.
18
+ * @throws {Error} - If the query execution fails.
17
19
  */
18
20
  query(params: GraphqlQueryParams): Promise<QueryResult>;
19
21
  /**
20
- * Performs a mutation operation on the GraphQL API.
21
- * @param {string} objectName - The name of the object.
22
- * @param {HasId[]} records - The records to delete.
23
- * @returns {Promise<any>} - The response from the delete operation.
22
+ * Executes a batch of queries.
23
+ * @param {GraphQLQueryBuilder[]} builders - Array of query builders.
24
+ * @returns {Promise<QueryResult[]>} - Array of query results.
24
25
  */
25
- mutate(params: GraphqlMurationParams): Promise<any>;
26
+ queryBatch(builders: GraphQLQueryBuilder[]): Promise<QueryResult[]>;
26
27
  /**
27
- * Deletes records from the GraphQL API.
28
+ * Executes a batch of GraphQL queries.
29
+ * @param {GraphqlQueryParams[]} paramsArray - An array of query parameters.
30
+ * @returns {Promise<QueryResult[]>} - An array of query results.
31
+ * @throws {Error} - If the batch execution fails.
28
32
  */
29
- delete(params: GraphqlMurationParams): Promise<any>;
33
+ private executeBatchQueries;
30
34
  /**
31
- * Updates records in the GraphQL API.
35
+ * Executes a GraphQL mutation.
36
+ * @param {GraphqlMutationParams} params - The parameters for the GraphQL mutation.
37
+ * @returns {Promise<MutationResult>} - The mutation result containing affected UIDs.
38
+ * @throws {Error} - If the mutation execution fails or the operation is invalid.
32
39
  */
33
- update(params: GraphqlMurationParams): Promise<any>;
40
+ mutate(params: GraphqlMutationParams): Promise<MutationResult>;
34
41
  /**
35
- * Inserts records into the GraphQL API.
42
+ * Executes a batch of GraphQL mutations.
43
+ * @param {GraphqlMutationParams[]} paramsArray - An array of mutation parameters.
44
+ * @returns {Promise<MutationResult[]>} - An array of mutation results.
45
+ * @throws {Error} - If the batch execution fails or if any mutation has empty records.
36
46
  */
37
- insert(params: GraphqlMurationParams): Promise<any>;
47
+ mutateBatch(paramsArray: GraphqlMutationParams[]): Promise<MutationResult[]>;
38
48
  /**
39
- * Extracts job UIDs from a GraphQL mutation response.
40
- * @param {MutationResult} response - The response object.
41
- * @returns {string[]} - An array of job UIDs.
49
+ * Deletes objects using a GraphQL mutation.
50
+ * @param {GraphqlMutationParams} params - The parameters for the delete mutation.
51
+ * @returns {Promise<MutationResult>} - The mutation result containing deleted UIDs.
52
+ * @throws {Error} - If the delete operation fails.
42
53
  */
43
- extractJobUIDs(response: MutationResult): string[];
54
+ delete(params: GraphqlMutationParams): Promise<MutationResult>;
44
55
  /**
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.
56
+ * Updates objects using a GraphQL mutation.
57
+ * @param {GraphqlMutationParams} params - The parameters for the update mutation.
58
+ * @returns {Promise<MutationResult>} - The mutation result containing updated UIDs.
59
+ * @throws {Error} - If the update operation fails.
60
+ */
61
+ update(params: GraphqlMutationParams): Promise<MutationResult>;
62
+ /**
63
+ * Inserts objects using a GraphQL mutation.
64
+ * @param {GraphqlMutationParams} params - The parameters for the insert mutation.
65
+ * @returns {Promise<MutationResult>} - The mutation result containing inserted UIDs.
66
+ * @throws {Error} - If the insert operation fails.
67
+ */
68
+ insert(params: GraphqlMutationParams): Promise<MutationResult>;
69
+ /**
70
+ * Upserts objects using a GraphQL mutation.
71
+ * @param {GraphqlMutationParams} params - The parameters for the upsert mutation, including keyField.
72
+ * @returns {Promise<MutationResult>} - The mutation result containing upserted UIDs.
73
+ * @throws {Error} - If the upsert operation fails.
74
+ */
75
+ upsert(params: GraphqlMutationParams): Promise<MutationResult>;
76
+ /**
77
+ * Extracts UIDs from a mutation response.
78
+ * @param {MutationResult} response - The mutation response containing the schema.
79
+ * @returns {string[]} - An array of UIDs extracted from the response.
80
+ */
81
+ extractUIDs(response: MutationResult): string[];
82
+ /**
83
+ * Converts object name to GraphQL query name format.
84
+ * @param {string} objectName - The object name to convert.
85
+ * @returns {string} - The formatted query name.
48
86
  */
49
87
  private getQueryName;
88
+ /**
89
+ * Generates headers for GraphQL queries.
90
+ * @param {GraphqlQueryParams} params - The query parameters containing operationName and readOnly flag.
91
+ * @returns {Record<string, string>} - The headers for the query request.
92
+ */
50
93
  private getQueryHeaders;
94
+ /**
95
+ * Generates headers for GraphQL mutations.
96
+ * @param {GraphqlMutationParams} params - The mutation parameters containing operationName and optional flags.
97
+ * @returns {Record<string, string>} - The headers for the mutation request.
98
+ */
51
99
  private getMutationHeaders;
100
+ /**
101
+ * Generates operation header for GraphQL requests.
102
+ * @param {string} operationName - The name of the GraphQL operation.
103
+ * @returns {Record<string, string>} - The operation header.
104
+ */
52
105
  private getOperationHeader;
53
106
  }
@@ -1 +1 @@
1
- "use strict";var __decorate=this&&this.__decorate||function(e,t,a,r){var o,n=arguments.length,s=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,a):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,a,r);else for(var i=e.length-1;i>=0;i--)(o=e[i])&&(s=(n<3?o(s):n>3?o(t,a,s):o(t,a))||s);return n>3&&s&&Object.defineProperty(t,a,s),s},__metadata=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};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}async query(e){var t,a,r,o,n,s,i,d,_,c,u,l;e.objectName=this.getQueryName(e.objectName);const p=(0,queries_1.FETCH_RECORDS_QUERY)(e),g=this.getQueryHeaders(e),h=await this.client.execute(p,g),m={records:(null===(a=null===(t=null==h?void 0:h.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==h?void 0:h.data)||void 0===r?void 0:r[e.objectName])||void 0===o?void 0:o.totalCount)||0,pageInfo:(null===(s=null===(n=null==h?void 0:h.data)||void 0===n?void 0:n[e.objectName])||void 0===s?void 0:s.pageInfo)||{}};if(m.records.length>0){const t=(null===(_=null===(d=null===(i=null==h?void 0:h.data)||void 0===i?void 0:i[e.objectName])||void 0===d?void 0:d.edges)||void 0===_?void 0:_.map((e=>e.offset)))||[],a=(null===(l=null===(u=null===(c=null==h?void 0:h.data)||void 0===c?void 0:c[e.objectName])||void 0===u?void 0:u.edges)||void 0===l?void 0:l.map((e=>e.cursor)))||[];m.endOffset=t[t.length-1],m.endCursor=a[a.length-1]}return m}async mutate(e){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 await this.client.execute(t,a)}async delete(e){return e.operation=constants_1.GraphqlOperations.DELETE,this.mutate(e)}async update(e){return e.operation=constants_1.GraphqlOperations.UPDATE,this.mutate(e)}async insert(e){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"),e.suppressChangeEvents&&(t[request_header_constants_1.REQUEST_HEADERS.X_SKEDULO_SUPPRESS_CHANGE_EVENTS]="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
+ "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),h=this.getQueryHeaders(e),v=yield this.client.execute(p,h),g={records:(null===(a=null===(t=null==v?void 0:v.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==v?void 0:v.data)||void 0===r?void 0:r[e.objectName])||void 0===o?void 0:o.totalCount)||0,pageInfo:(null===(i=null===(n=null==v?void 0:v.data)||void 0===n?void 0:n[e.objectName])||void 0===i?void 0:i.pageInfo)||{}};if(g.records.length>0){const t=(null===(u=null===(d=null===(s=null==v?void 0:v.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==v?void 0:v.data)||void 0===c?void 0:c[e.objectName])||void 0===_?void 0:_.edges)||void 0===l?void 0:l.map((e=>e.cursor)))||[];g.endOffset=t[t.length-1],g.endCursor=a[a.length-1]}return g}))}queryBatch(e){return __awaiter(this,void 0,void 0,(function*(){if(!e.length)return[];const t=e.map((e=>e.build()));return this.executeBatchQueries(t)}))}executeBatchQueries(e){return __awaiter(this,void 0,void 0,(function*(){if(!e.length)return[];const t=e.map((e=>{const t=Object.assign(Object.assign({},e),{objectName:this.getQueryName(e.objectName)});return(0,queries_1.FETCH_RECORDS_QUERY)(t)})),a=this.getQueryHeaders(e[0]);return(yield this.client.executeBatch(t,a)).map(((t,a)=>{var r,o,n,i,s,d,u,c,_,l,p,h;const v=e[a],g={records:(null===(o=null===(r=null==t?void 0:t.data)||void 0===r?void 0:r[v.objectName])||void 0===o?void 0:o.edges.map((e=>e.node)))||[],totalCount:(null===(i=null===(n=null==t?void 0:t.data)||void 0===n?void 0:n[v.objectName])||void 0===i?void 0:i.totalCount)||0,pageInfo:(null===(d=null===(s=null==t?void 0:t.data)||void 0===s?void 0:s[v.objectName])||void 0===d?void 0:d.pageInfo)||{}};if(g.records.length>0){const e=(null===(_=null===(c=null===(u=null==t?void 0:t.data)||void 0===u?void 0:u[v.objectName])||void 0===c?void 0:c.edges)||void 0===_?void 0:_.map((e=>e.offset)))||[],a=(null===(h=null===(p=null===(l=null==t?void 0:t.data)||void 0===l?void 0:l[v.objectName])||void 0===p?void 0:p.edges)||void 0===h?void 0:h.map((e=>e.cursor)))||[];g.endOffset=e[e.length-1],g.endCursor=a[a.length-1]}return g}))}))}mutate(e){return __awaiter(this,void 0,void 0,(function*(){if(!e.records||0===e.records.length)return Promise.resolve({data:{schema:{}}});let t="";switch(e.operation){case constants_1.GraphqlOperations.DELETE:t=(0,queries_1.DELETE_OBJECTS_MUTATION)(e);break;case constants_1.GraphqlOperations.INSERT:case constants_1.GraphqlOperations.UPDATE:case constants_1.GraphqlOperations.UPSERT:t=(0,queries_1.MUTATE_OBJECTS_MUTATION)(e);break;default:throw new Error(`Invalid operation: ${e.operation}`)}const a=this.getMutationHeaders(e);return yield this.client.execute(t,a)}))}mutateBatch(e){return __awaiter(this,void 0,void 0,(function*(){if(!e.length)return[];e.forEach(((e,t)=>{if(!e.records||0===e.records.length)throw new Error(`Mutation at index ${t} has empty or null records for operation '${e.operationName}'`)}));const t=e.map((e=>{switch(e.operation){case constants_1.GraphqlOperations.DELETE:return(0,queries_1.DELETE_OBJECTS_MUTATION)(e);case constants_1.GraphqlOperations.INSERT:case constants_1.GraphqlOperations.UPDATE:case constants_1.GraphqlOperations.UPSERT:return(0,queries_1.MUTATE_OBJECTS_MUTATION)(e);default:throw new Error(`Invalid operation: ${e.operation}`)}})),a=this.getMutationHeaders(e[0]);return yield this.client.executeBatch(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)}))}upsert(e){return __awaiter(this,void 0,void 0,(function*(){return e.operation=constants_1.GraphqlOperations.UPSERT,this.mutate(e)}))}extractUIDs(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"),e.suppressChangeEvents&&(t[request_header_constants_1.REQUEST_HEADERS.X_SKEDULO_SUPPRESS_CHANGE_EVENTS]="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",[Array]),__metadata("design:returntype",Promise)],GraphQLService.prototype,"queryBatch",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",[Array]),__metadata("design:returntype",Promise)],GraphQLService.prototype,"mutateBatch",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),__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],GraphQLService.prototype,"upsert",null);
@@ -1,26 +1,20 @@
1
- import { GraphqlMurationParams, GraphqlQueryParams } from "../../interfaces/graphql";
1
+ import { GraphqlMutationParams, GraphqlQueryParams } from "../../interfaces/graphql";
2
2
  /**
3
- * Constructs a GraphQL query for fetching records with specified parameters.
4
- *
5
- * @param params - The query parameters including object name, filter, pagination, ordering, and fields.
6
- * @returns The constructed GraphQL query string.
3
+ * Constructs a GraphQL query to fetch records for a given object.
4
+ * @param {GraphqlQueryParams} params - The parameters for the GraphQL query.
5
+ * @returns {string} - The constructed GraphQL query string.
7
6
  */
8
7
  export declare const FETCH_RECORDS_QUERY: ({ objectName, operationName, filter, first, offset, after, orderBy, fields, }: GraphqlQueryParams) => string;
9
8
  /**
10
- * Constructs a GraphQL mutation for deleting multiple objects.
11
- *
12
- * @param objectName - The name of the object to delete.
13
- * @param operationName - The graphql operation name.
14
- * @param records - The records to be deleted.
15
- * @returns The constructed GraphQL mutation string.
9
+ * Constructs a GraphQL mutation to delete objects.
10
+ * @param {GraphqlMutationParams} params - The parameters for the GraphQL mutation.
11
+ * @returns {string} - The constructed GraphQL mutation string.
16
12
  */
17
- export declare const DELETE_OBJECTS_MUTATION: ({ objectName, operationName, records }: GraphqlMurationParams) => string;
13
+ export declare const DELETE_OBJECTS_MUTATION: ({ objectName, operationName, records }: GraphqlMutationParams) => string;
18
14
  /**
19
- * Constructs a GraphQL mutation for upserting (inserting/updating) multiple objects.
20
- *
21
- * @param objectName - The name of the object to upsert.
22
- * @param records - The records to be upserted.
23
- * @param operation - The operation type ("insert" or "update").
24
- * @returns The constructed GraphQL mutation string.
15
+ * Constructs a GraphQL mutation to insert, update, or upsert objects.
16
+ * @param {GraphqlMutationParams} params - The parameters for the GraphQL mutation.
17
+ * @returns {string} - The constructed GraphQL mutation string.
18
+ * @throws {Error} - If the operation type is invalid.
25
19
  */
26
- export declare const UPSERT_OBJECTS_MUTATION: ({ objectName, operationName, records, operation }: GraphqlMurationParams) => string;
20
+ export declare const MUTATE_OBJECTS_MUTATION: ({ objectName, operationName, records, operation, keyField, }: GraphqlMutationParams) => 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,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
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MUTATE_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:r=0,after:T,orderBy:E,fields:s})=>`\n query ${n} {\n ${e}(${[t?`filter: "${t}"`:"",T?`after: "${T}"`:"",`first: ${o}`,r?`offset: ${r}`:"",E?`orderBy: "${E}"`:""].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 MUTATE_OBJECTS_MUTATION=({objectName:e,operationName:n,records:t,operation:o,keyField:r})=>{let T;return T="upsert"===o?t.map(((n,t)=>`\n alias${t+1}:upsert${e}(\n keyField: "${r||"UID"}",\n input: {\n ${Object.entries(n).map((([e,n])=>`${e}: ${"string"==typeof n?`"${n}"`:n}`)).join(", ")}\n }\n )\n `)).join("\n "):t.map(((n,t)=>`\n alias${t+1}:${o}${e}(\n input: {\n ${Object.entries(n).map((([e,n])=>`${e}: ${"string"==typeof n?`"${n}"`:n}`)).join(", ")}\n }\n )\n `)).join("\n "),`\n mutation ${n} {\n schema {\n ${T}\n }\n }\n `};exports.MUTATE_OBJECTS_MUTATION=MUTATE_OBJECTS_MUTATION;
@@ -1 +1 @@
1
- "use strict";var __decorate=this&&this.__decorate||function(e,t,a,r){var i,o=arguments.length,c=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,a):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,a,r);else for(var n=e.length-1;n>=0;n--)(i=e[n])&&(c=(o<3?i(c):o>3?i(t,a,c):i(t,a))||c);return o>3&&c&&Object.defineProperty(t,a,c),c},__metadata=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},__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}async acquireLock(e){const t="Z_LOCK_"+e.name,a=new Date(Date.now()+e.ttl).toISOString();try{let r=null;try{r=await this.configVarClient.get(t)}catch(e){}if(r){if(r.expiryDate&&new Date<new Date(r.expiryDate))return!1;await this.configVarClient.delete(t)}return await this.configVarClient.create({key:t,value:e.name,configType:"plain-text",description:e.description,expiryDate:a}),!0}catch(t){return logger_1.default.error(`Failed to acquire lock: ${e.name}`),!1}}async releaseLock(e){const t="Z_LOCK_"+e;try{let e=null;try{e=await this.configVarClient.get(t)}catch(e){}e&&await 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);
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);
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MetadataService=void 0;class MetadataService{constructor(t){this.client=t}async getObjectMetadata(t){const e=await this.client.fetchAllMetadata(),a={};for(const c of t){const t=e.find((t=>t.name===c));if(!t)throw new Error(`Metadata mapping not found for object: ${c}`);a[c]=await this.client.fetchObjectMetadata(t.mapping)}return a}getPicklistValues(t){const e=t.fields.filter((t=>"picklist"===t.type)),a={};for(const t of e)a[t.name]=t.values.map((t=>t.value));return a}}exports.MetadataService=MetadataService;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(t,e,a,n){return new(a||(a=Promise))((function(i,r){function c(t){try{s(n.next(t))}catch(t){r(t)}}function o(t){try{s(n.throw(t))}catch(t){r(t)}}function s(t){var e;t.done?i(t.value):(e=t.value,e instanceof a?e:new a((function(t){t(e)}))).then(c,o)}s((n=n.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MetadataService=void 0;class MetadataService{constructor(t){this.client=t}getObjectMetadata(t){return __awaiter(this,void 0,void 0,(function*(){const e=yield this.client.fetchAllMetadata(),a={};for(const n of t){const t=e.find((t=>t.name===n));if(!t)throw new Error(`Metadata mapping not found for object: ${n}`);a[n]=yield this.client.fetchObjectMetadata(t.mapping)}return a}))}getPicklistValues(t){const e=t.fields.filter((t=>"picklist"===t.type)),a={};for(const t of e)a[t.name]=t.values.map((t=>t.value));return a}}exports.MetadataService=MetadataService;
@@ -1 +1 @@
1
- "use strict";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}async getResources(e){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(await t.execute()).records}async getHolidays(e,t,i){const s={},n=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"),n&&r.withFilter(`EndDate >= ${n}`),a&&r.withFilter(`StartDate <= ${a}`);const o=await r.execute();if(s.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(",")}]`),n&&t.withFilter(`EndDate >= ${n}`),a&&t.withFilter(`StartDate <= ${a}`);const i=await t.execute();for(const e of i.records||[])for(const t of e.HolidayRegions||[]){const i=t.RegionId;s[i]||(s[i]=[]),s[i].push(e)}}return s}newQueryBuilder(e){const t=new graphql_1.GraphQLQueryBuilder(e);return t.setGraphqlService(this.graphqlService),t}}exports.DataService=DataService;
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.ResourceAvailabilityService=void 0;class ResourceAvailabilityService{constructor(e){this.availabilityAPIClient=e}async getAvailabilityPatterns(e){const t=await 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;
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;
@@ -1 +1 @@
1
- "use strict";var __decorate=this&&this.__decorate||function(e,t,i,a){var s,r=arguments.length,o=r<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--)(s=e[n])&&(o=(r<3?s(o):r>3?s(t,i,o):s(t,i))||o);return r>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)};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}async build(e){var t,i;if(!e)throw new Error("ResourceBuilder Error: queryParam is required");const a=[],s=await this.dataService.getResources(e);e.resourceIds&&0!==e.resourceIds.size||(e.resourceIds=new Set(s.map((e=>e.UID))));for(const t of s){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&&await this.loadAvailabilityPatterns(a,e);for(const s of a)e.mergeAvailability?s.availabilities=utils_1.DateTimeUtils.mergeEvents(s.availabilities):null===(t=s.availabilities)||void 0===t||t.sort(((e,t)=>e.start.getTime()-t.start.getTime())),e.mergeEvents?s.events=utils_1.DateTimeUtils.mergeEvents(s.events):null===(i=s.events)||void 0===i||i.sort(((e,t)=>e.start.getTime()-t.start.getTime()));return this.buildMore(a)}async loadAvailabilityPatterns(e,t){const i=await 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"}))))}async loadHolidayEvents(e,t){const i=await 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),s=utils_1.DateTimeUtils.getEndOfDate(i.EndDate,e.timezone);a<t.startTime&&(a=t.startTime),s>t.endTime&&(s=t.endTime),e.events.push({id:`${a.toISOString()}_${s.toISOString()}`,name:i.Name,start:a,finish:s,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);
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skedulo/pulse-solution-services",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
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",
@@ -24,7 +24,7 @@
24
24
  "yarn.lock"
25
25
  ],
26
26
  "devDependencies": {
27
- "@tsconfig/node18": "^18.2.4",
27
+ "@tsconfig/node18": "^18.2.2",
28
28
  "@types/uuid": "^10.0.0",
29
29
  "@typescript-eslint/eslint-plugin": "^8.11.0",
30
30
  "@typescript-eslint/parser": "^8.11.0",