@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.
- package/CHANGELOG.md +5 -0
- package/README.md +113 -9
- package/dist/clients/artifact-client.js +1 -1
- package/dist/clients/availability-api-client.js +1 -1
- package/dist/clients/base-client.js +1 -1
- package/dist/clients/config-features-client.js +1 -1
- package/dist/clients/config-template-client.js +1 -1
- package/dist/clients/config-var-client.js +1 -1
- package/dist/clients/files-api-client.js +1 -1
- package/dist/clients/geo-api-client.js +1 -1
- package/dist/clients/graphql-client.js +1 -1
- package/dist/clients/metadata-client.js +1 -1
- package/dist/clients/mobile-notification-client.js +1 -1
- package/dist/clients/org-preference-client.js +1 -1
- package/dist/clients/vocabulary-client.js +1 -1
- package/dist/index.d.ts +98 -36
- package/dist/logging/decorators/log-method.js +1 -1
- package/dist/monitoring/decorators/monitor-call.js +1 -1
- package/dist/monitoring/monitoring-manager.js +1 -1
- package/dist/services/cache/cache-service.js +1 -1
- package/dist/services/cache/storage/config-var-cache-storage.js +1 -1
- package/dist/services/cache/storage/in-memory-cache-storage.js +1 -1
- package/dist/services/geoservice.js +1 -1
- package/dist/services/graph-batch/graph-batch.js +1 -1
- package/dist/services/graph-batch/unique-graph-batch.js +1 -1
- package/dist/services/graphql/graphql-batch-builder.d.ts +138 -0
- package/dist/services/graphql/graphql-batch-builder.js +1 -0
- package/dist/services/graphql/graphql-query-batch.d.ts +10 -0
- package/dist/services/graphql/graphql-query-batch.js +1 -0
- package/dist/services/graphql/graphql-query-builder.d.ts +11 -3
- package/dist/services/graphql/graphql-query-builder.js +1 -1
- package/dist/services/graphql/graphql-service.d.ts +78 -25
- package/dist/services/graphql/graphql-service.js +1 -1
- package/dist/services/graphql/queries.d.ts +13 -19
- package/dist/services/graphql/queries.js +1 -1
- package/dist/services/lock-service.js +1 -1
- package/dist/services/metadata-service.js +1 -1
- package/dist/services/resource-availability/builder/data-service.js +1 -1
- package/dist/services/resource-availability/builder/resource-availability-service.js +1 -1
- package/dist/services/resource-availability/builder/resource-builder.js +1 -1
- package/package.json +2 -2
- package/yarn.lock +642 -517
|
@@ -1,53 +1,106 @@
|
|
|
1
1
|
import { GraphQLClient } from "../../clients/graphql-client";
|
|
2
|
-
import {
|
|
2
|
+
import { GraphqlMutationParams, GraphqlQueryParams, MutationResult, QueryResult } from "../../interfaces/graphql";
|
|
3
|
+
import { GraphQLQueryBuilder } from "./graphql-query-builder";
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* Service for executing GraphQL queries and mutations.
|
|
5
6
|
*/
|
|
6
7
|
export declare class GraphQLService {
|
|
7
8
|
private client;
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @param {GraphQLClient} client - The GraphQL client
|
|
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
|
|
15
|
-
* @param {GraphqlQueryParams} params - The query
|
|
16
|
-
* @returns {Promise<QueryResult>} - The query result
|
|
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
|
-
*
|
|
21
|
-
* @param {
|
|
22
|
-
* @
|
|
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
|
-
|
|
26
|
+
queryBatch(builders: GraphQLQueryBuilder[]): Promise<QueryResult[]>;
|
|
26
27
|
/**
|
|
27
|
-
*
|
|
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
|
-
|
|
33
|
+
private executeBatchQueries;
|
|
30
34
|
/**
|
|
31
|
-
*
|
|
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
|
-
|
|
40
|
+
mutate(params: GraphqlMutationParams): Promise<MutationResult>;
|
|
34
41
|
/**
|
|
35
|
-
*
|
|
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
|
-
|
|
47
|
+
mutateBatch(paramsArray: GraphqlMutationParams[]): Promise<MutationResult[]>;
|
|
38
48
|
/**
|
|
39
|
-
*
|
|
40
|
-
* @param {
|
|
41
|
-
* @returns {
|
|
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
|
-
|
|
54
|
+
delete(params: GraphqlMutationParams): Promise<MutationResult>;
|
|
44
55
|
/**
|
|
45
|
-
*
|
|
46
|
-
* @param {
|
|
47
|
-
* @returns {
|
|
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,
|
|
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 {
|
|
1
|
+
import { GraphqlMutationParams, GraphqlQueryParams } from "../../interfaces/graphql";
|
|
2
2
|
/**
|
|
3
|
-
* Constructs a GraphQL query
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
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
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
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 }:
|
|
13
|
+
export declare const DELETE_OBJECTS_MUTATION: ({ objectName, operationName, records }: GraphqlMutationParams) => string;
|
|
18
14
|
/**
|
|
19
|
-
* Constructs a GraphQL mutation
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
22
|
-
* @
|
|
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
|
|
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.
|
|
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,
|
|
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}
|
|
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}
|
|
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}
|
|
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
|
|
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.
|
|
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.
|
|
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",
|