@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
package/dist/index.d.ts
CHANGED
|
@@ -316,7 +316,7 @@ export declare class ConfigTemplateClient extends BaseClient {
|
|
|
316
316
|
* @param {string} templateId - The template ID.
|
|
317
317
|
* @returns {Promise<any[]>} - A promise resolving to an array of configuration values.
|
|
318
318
|
*/
|
|
319
|
-
|
|
319
|
+
getTemplateValues(templateId: string): Promise<any[]>;
|
|
320
320
|
/**
|
|
321
321
|
* Updates or Inserts configuration template values.
|
|
322
322
|
* @param {string} templateId - The template ID.
|
|
@@ -567,11 +567,12 @@ export interface GraphqlParams {
|
|
|
567
567
|
objectName: string;
|
|
568
568
|
operationName: string;
|
|
569
569
|
}
|
|
570
|
-
export interface
|
|
570
|
+
export interface GraphqlMutationParams extends GraphqlParams {
|
|
571
571
|
records: HasId[];
|
|
572
|
-
operation
|
|
572
|
+
operation?: GraphqlOperations;
|
|
573
573
|
bulkOperation?: boolean;
|
|
574
574
|
suppressChangeEvents?: boolean;
|
|
575
|
+
keyField?: string;
|
|
575
576
|
}
|
|
576
577
|
export interface GraphqlQueryParams extends GraphqlParams {
|
|
577
578
|
first?: number;
|
|
@@ -595,6 +596,7 @@ export interface MutationResult {
|
|
|
595
596
|
[alias: string]: string;
|
|
596
597
|
};
|
|
597
598
|
};
|
|
599
|
+
errors?: object[];
|
|
598
600
|
}
|
|
599
601
|
export interface GraphQLRequest {
|
|
600
602
|
query: string;
|
|
@@ -606,7 +608,7 @@ export interface GraphQLRequest {
|
|
|
606
608
|
*/
|
|
607
609
|
export declare class GraphQLClient extends BaseClient {
|
|
608
610
|
/**
|
|
609
|
-
* Executes a GraphQL query or mutation.
|
|
611
|
+
* Executes a single GraphQL query or mutation.
|
|
610
612
|
* @param {string | GraphQLRequest} graphqlQuery - The GraphQL query or mutation string.
|
|
611
613
|
* @param {Record<string, string>} headers - Additional headers to include in the request.
|
|
612
614
|
* @returns {Promise<GraphQlResponse>} - The response from the GraphQL API.
|
|
@@ -614,13 +616,13 @@ export declare class GraphQLClient extends BaseClient {
|
|
|
614
616
|
*/
|
|
615
617
|
execute(graphqlQuery: string | GraphQLRequest, headers?: Record<string, string>): Promise<GraphQlResponse>;
|
|
616
618
|
/**
|
|
617
|
-
* Executes a GraphQL
|
|
618
|
-
* @param {string | GraphQLRequest}
|
|
619
|
+
* Executes a batch of GraphQL queries or mutations.
|
|
620
|
+
* @param {Array<string | GraphQLRequest>} graphqlQueries - An array of GraphQL queries or mutations.
|
|
619
621
|
* @param {Record<string, string>} headers - Additional headers to include in the request.
|
|
620
|
-
* @returns {Promise<GraphQlResponse>} -
|
|
621
|
-
* @throws {Error} - If the request fails or if there are errors in the
|
|
622
|
+
* @returns {Promise<GraphQlResponse[]>} - An array of responses from the GraphQL API.
|
|
623
|
+
* @throws {Error} - If the request fails or if there are errors in any of the responses.
|
|
622
624
|
*/
|
|
623
|
-
executeBatch(
|
|
625
|
+
executeBatch(graphqlQueries: Array<string | GraphQLRequest>, headers?: Record<string, string>): Promise<GraphQlResponse[]>;
|
|
624
626
|
protected handleResponseData(responseData: any): void;
|
|
625
627
|
}
|
|
626
628
|
/**
|
|
@@ -1039,54 +1041,106 @@ export declare class GeoService {
|
|
|
1039
1041
|
createKey(origin: LatLng, destination: LatLng): string;
|
|
1040
1042
|
}
|
|
1041
1043
|
/**
|
|
1042
|
-
*
|
|
1044
|
+
* Service for executing GraphQL queries and mutations.
|
|
1043
1045
|
*/
|
|
1044
1046
|
export declare class GraphQLService {
|
|
1045
1047
|
private client;
|
|
1046
1048
|
/**
|
|
1047
|
-
*
|
|
1048
|
-
* @param {GraphQLClient} client - The GraphQL client
|
|
1049
|
+
* Constructor to initialize the GraphQL client.
|
|
1050
|
+
* @param {GraphQLClient} client - The GraphQL client instance.
|
|
1049
1051
|
*/
|
|
1050
1052
|
constructor(client: GraphQLClient);
|
|
1051
1053
|
/**
|
|
1052
|
-
* Executes a GraphQL query
|
|
1053
|
-
* @param {GraphqlQueryParams} params - The query
|
|
1054
|
-
* @returns {Promise<QueryResult>} - The query result
|
|
1054
|
+
* Executes a GraphQL query.
|
|
1055
|
+
* @param {GraphqlQueryParams} params - The parameters for the GraphQL query.
|
|
1056
|
+
* @returns {Promise<QueryResult>} - The query result containing records and pagination info.
|
|
1057
|
+
* @throws {Error} - If the query execution fails.
|
|
1055
1058
|
*/
|
|
1056
1059
|
query(params: GraphqlQueryParams): Promise<QueryResult>;
|
|
1057
1060
|
/**
|
|
1058
|
-
*
|
|
1059
|
-
* @param {
|
|
1060
|
-
* @
|
|
1061
|
-
|
|
1061
|
+
* Executes a batch of queries.
|
|
1062
|
+
* @param {GraphQLQueryBuilder[]} builders - Array of query builders.
|
|
1063
|
+
* @returns {Promise<QueryResult[]>} - Array of query results.
|
|
1064
|
+
*/
|
|
1065
|
+
queryBatch(builders: GraphQLQueryBuilder[]): Promise<QueryResult[]>;
|
|
1066
|
+
/**
|
|
1067
|
+
* Executes a batch of GraphQL queries.
|
|
1068
|
+
* @param {GraphqlQueryParams[]} paramsArray - An array of query parameters.
|
|
1069
|
+
* @returns {Promise<QueryResult[]>} - An array of query results.
|
|
1070
|
+
* @throws {Error} - If the batch execution fails.
|
|
1071
|
+
*/
|
|
1072
|
+
private executeBatchQueries;
|
|
1073
|
+
/**
|
|
1074
|
+
* Executes a GraphQL mutation.
|
|
1075
|
+
* @param {GraphqlMutationParams} params - The parameters for the GraphQL mutation.
|
|
1076
|
+
* @returns {Promise<MutationResult>} - The mutation result containing affected UIDs.
|
|
1077
|
+
* @throws {Error} - If the mutation execution fails or the operation is invalid.
|
|
1078
|
+
*/
|
|
1079
|
+
mutate(params: GraphqlMutationParams): Promise<MutationResult>;
|
|
1080
|
+
/**
|
|
1081
|
+
* Executes a batch of GraphQL mutations.
|
|
1082
|
+
* @param {GraphqlMutationParams[]} paramsArray - An array of mutation parameters.
|
|
1083
|
+
* @returns {Promise<MutationResult[]>} - An array of mutation results.
|
|
1084
|
+
* @throws {Error} - If the batch execution fails or if any mutation has empty records.
|
|
1062
1085
|
*/
|
|
1063
|
-
|
|
1086
|
+
mutateBatch(paramsArray: GraphqlMutationParams[]): Promise<MutationResult[]>;
|
|
1064
1087
|
/**
|
|
1065
|
-
* Deletes
|
|
1088
|
+
* Deletes objects using a GraphQL mutation.
|
|
1089
|
+
* @param {GraphqlMutationParams} params - The parameters for the delete mutation.
|
|
1090
|
+
* @returns {Promise<MutationResult>} - The mutation result containing deleted UIDs.
|
|
1091
|
+
* @throws {Error} - If the delete operation fails.
|
|
1066
1092
|
*/
|
|
1067
|
-
delete(params:
|
|
1093
|
+
delete(params: GraphqlMutationParams): Promise<MutationResult>;
|
|
1068
1094
|
/**
|
|
1069
|
-
* Updates
|
|
1095
|
+
* Updates objects using a GraphQL mutation.
|
|
1096
|
+
* @param {GraphqlMutationParams} params - The parameters for the update mutation.
|
|
1097
|
+
* @returns {Promise<MutationResult>} - The mutation result containing updated UIDs.
|
|
1098
|
+
* @throws {Error} - If the update operation fails.
|
|
1070
1099
|
*/
|
|
1071
|
-
update(params:
|
|
1100
|
+
update(params: GraphqlMutationParams): Promise<MutationResult>;
|
|
1072
1101
|
/**
|
|
1073
|
-
* Inserts
|
|
1102
|
+
* Inserts objects using a GraphQL mutation.
|
|
1103
|
+
* @param {GraphqlMutationParams} params - The parameters for the insert mutation.
|
|
1104
|
+
* @returns {Promise<MutationResult>} - The mutation result containing inserted UIDs.
|
|
1105
|
+
* @throws {Error} - If the insert operation fails.
|
|
1074
1106
|
*/
|
|
1075
|
-
insert(params:
|
|
1107
|
+
insert(params: GraphqlMutationParams): Promise<MutationResult>;
|
|
1076
1108
|
/**
|
|
1077
|
-
*
|
|
1078
|
-
* @param {
|
|
1079
|
-
* @returns {
|
|
1109
|
+
* Upserts objects using a GraphQL mutation.
|
|
1110
|
+
* @param {GraphqlMutationParams} params - The parameters for the upsert mutation, including keyField.
|
|
1111
|
+
* @returns {Promise<MutationResult>} - The mutation result containing upserted UIDs.
|
|
1112
|
+
* @throws {Error} - If the upsert operation fails.
|
|
1080
1113
|
*/
|
|
1081
|
-
|
|
1114
|
+
upsert(params: GraphqlMutationParams): Promise<MutationResult>;
|
|
1082
1115
|
/**
|
|
1083
|
-
*
|
|
1084
|
-
* @param {
|
|
1085
|
-
* @returns {string} -
|
|
1116
|
+
* Extracts UIDs from a mutation response.
|
|
1117
|
+
* @param {MutationResult} response - The mutation response containing the schema.
|
|
1118
|
+
* @returns {string[]} - An array of UIDs extracted from the response.
|
|
1119
|
+
*/
|
|
1120
|
+
extractUIDs(response: MutationResult): string[];
|
|
1121
|
+
/**
|
|
1122
|
+
* Converts object name to GraphQL query name format.
|
|
1123
|
+
* @param {string} objectName - The object name to convert.
|
|
1124
|
+
* @returns {string} - The formatted query name.
|
|
1086
1125
|
*/
|
|
1087
1126
|
private getQueryName;
|
|
1127
|
+
/**
|
|
1128
|
+
* Generates headers for GraphQL queries.
|
|
1129
|
+
* @param {GraphqlQueryParams} params - The query parameters containing operationName and readOnly flag.
|
|
1130
|
+
* @returns {Record<string, string>} - The headers for the query request.
|
|
1131
|
+
*/
|
|
1088
1132
|
private getQueryHeaders;
|
|
1133
|
+
/**
|
|
1134
|
+
* Generates headers for GraphQL mutations.
|
|
1135
|
+
* @param {GraphqlMutationParams} params - The mutation parameters containing operationName and optional flags.
|
|
1136
|
+
* @returns {Record<string, string>} - The headers for the mutation request.
|
|
1137
|
+
*/
|
|
1089
1138
|
private getMutationHeaders;
|
|
1139
|
+
/**
|
|
1140
|
+
* Generates operation header for GraphQL requests.
|
|
1141
|
+
* @param {string} operationName - The name of the GraphQL operation.
|
|
1142
|
+
* @returns {Record<string, string>} - The operation header.
|
|
1143
|
+
*/
|
|
1090
1144
|
private getOperationHeader;
|
|
1091
1145
|
}
|
|
1092
1146
|
/**
|
|
@@ -1108,7 +1162,7 @@ export declare class GraphQLQueryBuilder {
|
|
|
1108
1162
|
private queryParams;
|
|
1109
1163
|
/**
|
|
1110
1164
|
* Creates an instance of GraphQLQueryBuilder.
|
|
1111
|
-
* @param {
|
|
1165
|
+
* @param {GraphqlQueryParams} queryParams - The parameters for the query.
|
|
1112
1166
|
* @param {boolean} [isParent=false] - Indicates if this query is a parent query.
|
|
1113
1167
|
*/
|
|
1114
1168
|
constructor(queryParams: GraphqlQueryParams, isParent?: boolean);
|
|
@@ -1153,13 +1207,21 @@ export declare class GraphQLQueryBuilder {
|
|
|
1153
1207
|
*/
|
|
1154
1208
|
private formatQueryFields;
|
|
1155
1209
|
/**
|
|
1156
|
-
* Builds the GraphQL query parameters in a
|
|
1210
|
+
* Builds the GraphQL query parameters in a structured format.
|
|
1157
1211
|
*/
|
|
1158
1212
|
build(): GraphqlQueryParams;
|
|
1159
1213
|
/**
|
|
1160
|
-
* Executes the query using the GraphQL service
|
|
1214
|
+
* Executes the query using the GraphQL service.
|
|
1161
1215
|
*/
|
|
1162
1216
|
execute(): Promise<QueryResult>;
|
|
1217
|
+
/**
|
|
1218
|
+
* Executes all queries for the configured object, fetching records from the specified page range, up to a maximum of 20 pages.
|
|
1219
|
+
* @param {number} [fromPage=1] - The starting page number (1-based, defaults to 1).
|
|
1220
|
+
* @param {number} [toPage=20] - The ending page number (defaults to 20, capped at 20).
|
|
1221
|
+
* @returns {Promise<QueryResult>} - A query result containing all records in the page range and pagination info.
|
|
1222
|
+
* @throws {Error} - If the query execution fails, no GraphQL service is set, or invalid page parameters are provided.
|
|
1223
|
+
*/
|
|
1224
|
+
executeAll(fromPage?: number, toPage?: number): Promise<QueryResult>;
|
|
1163
1225
|
/**
|
|
1164
1226
|
* Generates a string representation of the GraphQL query for debugging.
|
|
1165
1227
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LogMethod=LogMethod;const logging_utils_1=require("../logging-utils"),PULSE_SOLUTION_NAMESPACE="PSS",COLORS={RESET:"[0m",GREEN:"[32m",YELLOW:"[33m",RED:"[31m",CYAN:"[36m",MAGENTA:"[35m"};function LogMethod(t=PULSE_SOLUTION_NAMESPACE){return function(e,
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,n,e,o){return new(e||(e=Promise))((function(r,i){function s(t){try{O(o.next(t))}catch(t){i(t)}}function E(t){try{O(o.throw(t))}catch(t){i(t)}}function O(t){var n;t.done?r(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(s,E)}O((o=o.apply(t,n||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LogMethod=LogMethod;const logging_utils_1=require("../logging-utils"),PULSE_SOLUTION_NAMESPACE="PSS",COLORS={RESET:"[0m",GREEN:"[32m",YELLOW:"[33m",RED:"[31m",CYAN:"[36m",MAGENTA:"[35m"};function LogMethod(t=PULSE_SOLUTION_NAMESPACE){return function(n,e,o){const r=o.value,i=process.env.LOG_NAMESPACE||"";if(!i)return o;const s=parseInt(process.env.LOG_ENTRY_MAX_LENGTH||"120",10),E=i===t||"ALL"===i.toUpperCase();function O(t,n,e,o,r){const i=(new Date).toISOString(),E="ERROR"===o?COLORS.RED:"INPUT"===o?COLORS.CYAN:COLORS.MAGENTA;console.log(`${COLORS.GREEN}[${t.toUpperCase()}]${COLORS.RESET} | ${COLORS.YELLOW}${i}${COLORS.RESET} | ${COLORS.GREEN}${PULSE_SOLUTION_NAMESPACE}${COLORS.RESET} | ${n.constructor.name} | ${e} - ${E}${o}${COLORS.RESET}: ${function(t){if(!t)return"";const n=(0,logging_utils_1.maskSensitiveData)(t);return n.length>s?`${n.substring(0,s-3)}...`:n}(r)}`)}return o.value=function(...t){return __awaiter(this,void 0,void 0,(function*(){E&&O("info",this,e.toString(),"INPUT",t);try{const n=yield Promise.resolve(r.apply(this,t));return E&&O("info",this,e.toString(),"OUTPUT",n),n}catch(t){throw O("error",this,e.toString(),"ERROR",t.message||t),t}}))},o}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MonitorCall=MonitorCall;const monitoring_registry_1=require("../monitoring-registry");function MonitorCall(
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,n,r,o){return new(r||(r=Promise))((function(e,i){function a(t){try{c(o.next(t))}catch(t){i(t)}}function u(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r((function(t){t(n)}))).then(a,u)}c((o=o.apply(t,n||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MonitorCall=MonitorCall;const monitoring_registry_1=require("../monitoring-registry");function MonitorCall(t){return function(n,r,o){const e=o.value;return o.value=function(...o){return __awaiter(this,void 0,void 0,(function*(){const i=t||`${n.constructor.name}.${r}`;return(0,monitoring_registry_1.getGlobalMonitorManager)().measure(i,(()=>__awaiter(this,void 0,void 0,(function*(){return e.apply(this,o)}))))}))},o}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MonitoringManager=void 0;const logger_1=__importDefault(require("../logging/logger"));class MonitoringManager{constructor(t={}){this.totalCalls=0,this.methodCallCounts={},this.methodExecutionTimes={},this.concurrentRequests=0,this.peakConcurrentRequests=0,this.startTime=Date.now(),this.violations={},this.thresholds=t}
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,o,s){return new(o||(o=Promise))((function(i,n){function a(t){try{r(s.next(t))}catch(t){n(t)}}function l(t){try{r(s.throw(t))}catch(t){n(t)}}function r(t){var e;t.done?i(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(a,l)}r((s=s.apply(t,e||[])).next())}))},__importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MonitoringManager=void 0;const logger_1=__importDefault(require("../logging/logger"));class MonitoringManager{constructor(t={}){this.totalCalls=0,this.methodCallCounts={},this.methodExecutionTimes={},this.concurrentRequests=0,this.peakConcurrentRequests=0,this.startTime=Date.now(),this.violations={},this.thresholds=t}measure(t,e){return __awaiter(this,void 0,void 0,(function*(){this.incrementTotalCallsCount(),this.incrementMethodCount(t),this.trackConcurrentRequest(1,t);const o=Date.now();let s;try{s=yield e()}finally{this.trackConcurrentRequest(-1,t)}const i=Date.now()-o;return this.trackExecutionTime(t,i),this.checkMethodDuration(t,i),s}))}trackConcurrentRequest(t,e){this.concurrentRequests+=t,this.peakConcurrentRequests=Math.max(this.peakConcurrentRequests,this.concurrentRequests),this.thresholds.maxConcurrentRequests&&this.peakConcurrentRequests>this.thresholds.maxConcurrentRequests&&this.handleViolation("maxConcurrentRequests",`Method ${e} max concurrent requests exceeded: ${this.peakConcurrentRequests} (Allowed: ${this.thresholds.maxConcurrentRequests})`)}getExecutionMetrics(){return{totalCalls:this.totalCalls,totalExecutionTimeMs:Date.now()-this.startTime,peakConcurrentRequests:this.peakConcurrentRequests,methodCallCounts:Object.assign({},this.methodCallCounts),methodExecutionTimes:Object.assign({},this.methodExecutionTimes),violations:Object.values(this.violations)}}incrementTotalCallsCount(){this.totalCalls++,this.thresholds.totalCalls&&this.totalCalls>this.thresholds.totalCalls&&this.handleViolation("totalCalls",`Total calls limit exceeded: ${this.totalCalls} (Allowed: ${this.thresholds.totalCalls})`)}incrementMethodCount(t){var e;this.methodCallCounts[t]=(null!==(e=this.methodCallCounts[t])&&void 0!==e?e:0)+1;const o=`methodCallLimit:${t}`,s=this.thresholds.maxMethodCalls;s&&this.methodCallCounts[t]>s&&this.handleViolation(o,`Method [${t}] call limit exceeded: ${this.methodCallCounts[t]} (Allowed: ${s})`)}trackExecutionTime(t,e){this.methodExecutionTimes[t]||(this.methodExecutionTimes[t]={totalTime:0,count:0,min:Number.MAX_VALUE,max:0});const o=this.methodExecutionTimes[t];o.totalTime+=e,o.count+=1,o.min=Math.min(o.min,e),o.max=Math.max(o.max,e)}checkMethodDuration(t,e){const o=this.thresholds.maxMethodExecutionTimeMs,s=`methodDurationLimit:${t}`;o&&e>o&&this.handleViolation(s,`Method [${t}] exceeded duration limit: ${e}ms (Allowed: ${o}ms)`)}handleViolation(t,e){if(this.violations[t]=e,this.thresholds.throwOnViolation)throw new Error(e);logger_1.default.warn(`[Violation] ${e}`)}}exports.MonitoringManager=MonitoringManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __decorate=this&&this.__decorate||function(e,t,a
|
|
1
|
+
"use strict";var __decorate=this&&this.__decorate||function(e,t,r,a){var i,n=arguments.length,o=n<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,r):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,a);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(n<3?i(o):n>3?i(t,r,o):i(t,r))||o);return n>3&&o&&Object.defineProperty(t,r,o),o},__metadata=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},__awaiter=this&&this.__awaiter||function(e,t,r,a){return new(r||(r=Promise))((function(i,n){function o(e){try{c(a.next(e))}catch(e){n(e)}}function s(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,s)}c((a=a.apply(e,t||[])).next())}))},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CacheService=void 0;const logging_1=require("../../logging"),logger_1=__importDefault(require("../../logging/logger")),KEY_PREFIX="Z_CACHE_",DEFAULT_TTL=36e5;class CacheService{constructor(e){this.storage=e}setSecondaryCache(e){this.secondaryCache=e}get(e,t){return __awaiter(this,void 0,void 0,(function*(){e=this.addPrefix(e);const r=yield this.storage.get(e);if(r)try{const t=JSON.parse(r);return t.expiresAt&&Date.now()>t.expiresAt?(yield this.delete(e),null):this.deserialize(t)}catch(e){return logger_1.default.error("Cache deserialization failed:",e),null}if((null==t?void 0:t.useSecondaryCache)&&this.secondaryCache){const r=yield this.secondaryCache.get(e,t);return null!==r&&(yield this.set(e,r,{ttl:null==t?void 0:t.ttl})),r}return null}))}set(e,t,r){return __awaiter(this,void 0,void 0,(function*(){var a;e=this.addPrefix(e);const i={type:t instanceof Date?"date":typeof t,value:t,expiresAt:Date.now()+(null!==(a=null==r?void 0:r.ttl)&&void 0!==a?a:36e5)},n=JSON.stringify(i);yield this.storage.set(e,n),(null==r?void 0:r.useSecondaryCache)&&this.secondaryCache&&(yield this.secondaryCache.set(e,t,r))}))}delete(e){return __awaiter(this,void 0,void 0,(function*(){e=this.addPrefix(e),yield this.storage.delete(e)}))}clear(){return __awaiter(this,void 0,void 0,(function*(){yield this.storage.clear()}))}addPrefix(e){return e.startsWith("Z_CACHE_")?e:"Z_CACHE_"+e}deserialize(e){switch(e.type){case"number":return Number(e.value);case"boolean":return Boolean(e.value);case"object":return e.value;case"date":case"datetime":const t=new Date(e.value);return isNaN(t.getTime())?(logger_1.default.error(`Invalid ${e.type} string:`,e.value),null):t;default:return String(e.value)}}}exports.CacheService=CacheService,__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Object]),__metadata("design:returntype",Promise)],CacheService.prototype,"get",null),__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Object,Object]),__metadata("design:returntype",Promise)],CacheService.prototype,"set",null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConfigVarCacheStorage=void 0;const config_var_constants_1=require("../../../constants/config-var-constants");class ConfigVarCacheStorage{constructor(
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(o,r){function a(t){try{s(i.next(t))}catch(t){r(t)}}function c(t){try{s(i.throw(t))}catch(t){r(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}s((i=i.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConfigVarCacheStorage=void 0;const config_var_constants_1=require("../../../constants/config-var-constants");class ConfigVarCacheStorage{constructor(t){this.configVarClient=t}set(t,e){return __awaiter(this,void 0,void 0,(function*(){try{yield this.configVarClient.create({key:t,value:e,configType:config_var_constants_1.ConfigVariableType.PLAIN_TEXT})}catch(n){yield this.configVarClient.update({key:t,value:e,configType:config_var_constants_1.ConfigVariableType.PLAIN_TEXT})}}))}get(t){return __awaiter(this,void 0,void 0,(function*(){var e;try{const e=yield this.configVarClient.get(t);if(e)return e.value}catch(t){if(null===(e=null==t?void 0:t.message)||void 0===e?void 0:e.includes("not_found"))return null;throw t}return null}))}delete(t){return __awaiter(this,void 0,void 0,(function*(){yield this.configVarClient.delete(t)}))}clear(){return __awaiter(this,void 0,void 0,(function*(){throw new Error("Clear operation is not supported by ConfigVarCacheStorage")}))}}exports.ConfigVarCacheStorage=ConfigVarCacheStorage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.InMemoryCacheStorage=void 0;class InMemoryCacheStorage{constructor(){this.cache=new Map}
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{s(r.next(e))}catch(e){o(e)}}function c(e){try{s(r.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}s((r=r.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.InMemoryCacheStorage=void 0;class InMemoryCacheStorage{constructor(){this.cache=new Map}set(e,t){return __awaiter(this,void 0,void 0,(function*(){this.cache.set(e,t)}))}get(e){return __awaiter(this,void 0,void 0,(function*(){const t=this.cache.get(e);return t||null}))}delete(e){return __awaiter(this,void 0,void 0,(function*(){this.cache.delete(e)}))}clear(){return __awaiter(this,void 0,void 0,(function*(){this.cache.clear()}))}}exports.InMemoryCacheStorage=InMemoryCacheStorage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";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()}
|
|
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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphBatch=void 0;const graph_batch_config_1=require("./configs/graph-batch-config"),pagination_strategy_1=require("./pagination-strategy");class GraphBatch{constructor(t,e){this.startTime=new Date,this.context=t,this.config=(0,graph_batch_config_1.initializeConfig)(e),this.startTime=new Date}
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(a,s){function n(t){try{o(r.next(t))}catch(t){s(t)}}function h(t){try{o(r.throw(t))}catch(t){s(t)}}function o(t){var e;t.done?a(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(n,h)}o((r=r.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphBatch=void 0;const graph_batch_config_1=require("./configs/graph-batch-config"),pagination_strategy_1=require("./pagination-strategy");class GraphBatch{constructor(t,e){this.startTime=new Date,this.context=t,this.config=(0,graph_batch_config_1.initializeConfig)(e),this.startTime=new Date}run(){return __awaiter(this,void 0,void 0,(function*(){var t,e;if(this.queryBuilder=yield this.start(),!this.queryBuilder)throw new Error("Query builder was not defined in start().");this.queryBuilder.withLimit(this.config.batchSize);let i=0,r=!0;for(;r&&!this.isMaxBatchesReached(i)&&(this.queryResult=yield this.fetchNextPage(),this.queryResult.records&&0!==this.queryResult.records.length);)yield this.execute(this.queryResult.records),i++,this.config.delaySeconds&&!this.isMaxBatchesReached(i)&&(yield this.delay(1e3*this.config.delaySeconds)),r=null!==(e=null===(t=this.queryResult.pageInfo)||void 0===t?void 0:t.hasNextPage)&&void 0!==e&&e;yield this.finish()}))}finish(){return __awaiter(this,void 0,void 0,(function*(){this.context.logger.info("Batch process completed.")}))}fetchNextPage(){return __awaiter(this,void 0,void 0,(function*(){var t,e,i;switch(this.config.strategy){case pagination_strategy_1.PaginationStrategy.OFFSET:this.queryResult&&(null===(t=this.queryBuilder)||void 0===t||t.withOffset(this.queryResult.endOffset+1));break;case pagination_strategy_1.PaginationStrategy.CURSOR:this.queryResult&&(null===(e=this.queryBuilder)||void 0===e||e.withCursor(this.queryResult.endCursor));break;case pagination_strategy_1.PaginationStrategy.NONE:default:null===(i=this.queryBuilder)||void 0===i||i.withFilter(`LastModifiedDate < ${this.startTime.toISOString()}`)}return this.queryBuilder.execute()}))}isMaxBatchesReached(t){return!!this.config.maxBatches&&t>=this.config.maxBatches}delay(t){return __awaiter(this,void 0,void 0,(function*(){return new Promise((e=>setTimeout(e,t)))}))}}exports.GraphBatch=GraphBatch;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))((function(n,a){function o(t){try{s(i.next(t))}catch(t){a(t)}}function c(t){try{s(i.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,c)}s((i=i.apply(t,e||[])).next())}))},__importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.UniqueGraphBatch=void 0;const logger_1=__importDefault(require("../../logging/logger")),graph_batch_1=require("./graph-batch");class UniqueGraphBatch extends graph_batch_1.GraphBatch{constructor(t,e){super(t,e),this.name=(null==e?void 0:e.name)||this.constructor.name,this.name=this.name.toUpperCase().replace(/[^A-Z0-9]/g,"_"),this.lockTtl=(null==e?void 0:e.lockTtl)||96e4}run(){const t=Object.create(null,{run:{get:()=>super.run}});return __awaiter(this,void 0,void 0,(function*(){const e={name:this.name,ttl:this.lockTtl,description:`Lock for batch process: ${this.name}`};try{if(!(yield this.context.lockService.acquireLock(e)))return void logger_1.default.error(`A batch with name '${this.name}' is already running.`);yield t.run.call(this)}catch(t){logger_1.default.error(`Error running batch with name '${this.name}': ${t.message}`)}finally{yield this.context.lockService.releaseLock(this.name)}}))}start(){return __awaiter(this,void 0,void 0,(function*(){throw new Error("Subclasses must implement the 'start' method.")}))}execute(t){return __awaiter(this,void 0,void 0,(function*(){throw new Error("Subclasses must implement the 'execute' method.")}))}finish(){const t=Object.create(null,{finish:{get:()=>super.finish}});return __awaiter(this,void 0,void 0,(function*(){yield t.finish.call(this)}))}}exports.UniqueGraphBatch=UniqueGraphBatch;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { GraphQLService } from "./graphql-service";
|
|
2
|
+
import { GraphqlQueryParams, QueryResult, MutationResult } from "../../interfaces/graphql";
|
|
3
|
+
/**
|
|
4
|
+
* A utility class for building GraphQL queries or mutations dynamically.
|
|
5
|
+
*/
|
|
6
|
+
export declare class GraphQLQueryBuilder {
|
|
7
|
+
private objectName;
|
|
8
|
+
operationName: string;
|
|
9
|
+
private operationType;
|
|
10
|
+
private fields;
|
|
11
|
+
private filters;
|
|
12
|
+
private input;
|
|
13
|
+
private first?;
|
|
14
|
+
private offset?;
|
|
15
|
+
private orderBy?;
|
|
16
|
+
private after?;
|
|
17
|
+
private parentQueries;
|
|
18
|
+
private childQueries;
|
|
19
|
+
private isParent;
|
|
20
|
+
private graphqlService;
|
|
21
|
+
private queryParams;
|
|
22
|
+
/**
|
|
23
|
+
* Creates an instance of GraphQLQueryBuilder.
|
|
24
|
+
* @param queryParams - The parameters for the query or mutation.
|
|
25
|
+
* @param isParent - Indicates if this is a parent query.
|
|
26
|
+
*/
|
|
27
|
+
constructor(queryParams: GraphqlQueryParams, isParent?: boolean);
|
|
28
|
+
/**
|
|
29
|
+
* Sets the GraphQL service to use for executing the operation.
|
|
30
|
+
* @param graphqlService - The GraphQL service instance.
|
|
31
|
+
* @returns The query builder instance for chaining.
|
|
32
|
+
*/
|
|
33
|
+
setGraphqlService(graphqlService: GraphQLService): this;
|
|
34
|
+
/**
|
|
35
|
+
* Specifies the fields to be retrieved. Prevents duplicates.
|
|
36
|
+
* @param fields - Array of field names to include.
|
|
37
|
+
* @returns The query builder instance for chaining.
|
|
38
|
+
*/
|
|
39
|
+
withFields(fields: string[]): this;
|
|
40
|
+
/**
|
|
41
|
+
* Adds a filter condition to the query.
|
|
42
|
+
* @param condition - The filter condition string.
|
|
43
|
+
* @returns The query builder instance for chaining.
|
|
44
|
+
* @throws Error if applied to a mutation or parent query.
|
|
45
|
+
*/
|
|
46
|
+
withFilter(condition: string): this;
|
|
47
|
+
/**
|
|
48
|
+
* Sets the input object for a mutation.
|
|
49
|
+
* @param input - The mutation input object.
|
|
50
|
+
* @returns The query builder instance for chaining.
|
|
51
|
+
* @throws Error if applied to a query.
|
|
52
|
+
*/
|
|
53
|
+
withInput(input: Record<string, any>): this;
|
|
54
|
+
/**
|
|
55
|
+
* Sets a limit on the number of records to retrieve.
|
|
56
|
+
* @param first - The maximum number of records.
|
|
57
|
+
* @returns The query builder instance for chaining.
|
|
58
|
+
* @throws Error if applied to a mutation or parent query.
|
|
59
|
+
*/
|
|
60
|
+
withLimit(first: number): this;
|
|
61
|
+
/**
|
|
62
|
+
* Sets an offset for pagination.
|
|
63
|
+
* @param offset - The number of records to skip.
|
|
64
|
+
* @returns The query builder instance for chaining.
|
|
65
|
+
* @throws Error if applied to a mutation or parent query.
|
|
66
|
+
*/
|
|
67
|
+
withOffset(offset: number): this;
|
|
68
|
+
/**
|
|
69
|
+
* Sets the order in which records should be retrieved.
|
|
70
|
+
* @param orderBy - The field to order by.
|
|
71
|
+
* @returns The query builder instance for chaining.
|
|
72
|
+
* @throws Error if applied to a mutation or parent query.
|
|
73
|
+
*/
|
|
74
|
+
withOrderBy(orderBy: string): this;
|
|
75
|
+
/**
|
|
76
|
+
* Applies cursor-based pagination.
|
|
77
|
+
* @param after - The cursor to paginate after.
|
|
78
|
+
* @returns The query builder instance for chaining.
|
|
79
|
+
* @throws Error if applied to a mutation or parent query.
|
|
80
|
+
*/
|
|
81
|
+
withCursor(after: string): this;
|
|
82
|
+
/**
|
|
83
|
+
* Creates a parent query.
|
|
84
|
+
* @param objectName - The name of the parent object.
|
|
85
|
+
* @returns The parent query builder instance.
|
|
86
|
+
*/
|
|
87
|
+
withParentQuery(objectName: string): GraphQLQueryBuilder;
|
|
88
|
+
/**
|
|
89
|
+
* Creates a child query.
|
|
90
|
+
* @param objectName - The name of the child object.
|
|
91
|
+
* @returns The child query builder instance.
|
|
92
|
+
*/
|
|
93
|
+
withChildQuery(objectName: string): GraphQLQueryBuilder;
|
|
94
|
+
/**
|
|
95
|
+
* Recursively builds the GraphQL query fields, handling nested queries.
|
|
96
|
+
* @returns The formatted fields string.
|
|
97
|
+
*/
|
|
98
|
+
private formatQueryFields;
|
|
99
|
+
/**
|
|
100
|
+
* Builds the GraphQL operation parameters.
|
|
101
|
+
* @returns The structured query or mutation parameters.
|
|
102
|
+
*/
|
|
103
|
+
build(): GraphqlQueryParams;
|
|
104
|
+
/**
|
|
105
|
+
* Executes the query or mutation.
|
|
106
|
+
* @returns A promise resolving to the operation result.
|
|
107
|
+
* @throws Error if no GraphQL service is set.
|
|
108
|
+
*/
|
|
109
|
+
execute(): Promise<QueryResult | MutationResult>;
|
|
110
|
+
/**
|
|
111
|
+
* Generates a string representation of the GraphQL operation for debugging.
|
|
112
|
+
* @returns The formatted operation string.
|
|
113
|
+
*/
|
|
114
|
+
toString(): string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* A utility class for building and executing a batch of GraphQL queries and mutations.
|
|
118
|
+
*/
|
|
119
|
+
export declare class GraphQLBatchBuilder {
|
|
120
|
+
private operations;
|
|
121
|
+
/**
|
|
122
|
+
* Adds a query or mutation to the batch.
|
|
123
|
+
* @param builder - The GraphQLQueryBuilder instance for the query or mutation.
|
|
124
|
+
* @returns The batch builder instance for chaining.
|
|
125
|
+
*/
|
|
126
|
+
add(builder: GraphQLQueryBuilder): this;
|
|
127
|
+
/**
|
|
128
|
+
* Executes the batch of queries and mutations.
|
|
129
|
+
* @returns A promise resolving to an array of query or mutation results.
|
|
130
|
+
* @throws Error if no operations are added or if GraphQL service is missing.
|
|
131
|
+
*/
|
|
132
|
+
execute(): Promise<(QueryResult | MutationResult)[]>;
|
|
133
|
+
/**
|
|
134
|
+
* Generates a string representation of the batch for debugging.
|
|
135
|
+
* @returns A string containing all operations in the batch.
|
|
136
|
+
*/
|
|
137
|
+
toString(): string;
|
|
138
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))((function(o,s){function n(t){try{h(i.next(t))}catch(t){s(t)}}function a(t){try{h(i.throw(t))}catch(t){s(t)}}function h(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(n,a)}h((i=i.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphQLBatchBuilder=exports.GraphQLQueryBuilder=void 0;const graphql_1=require("../../interfaces/graphql");class GraphQLQueryBuilder{constructor(t,e=!1){if(this.fields=new Set(["UID"]),this.filters=[],this.input=null,this.parentQueries={},this.childQueries={},this.graphqlService=null,!t.objectName||!t.operationName)throw new Error("objectName and operationName are required.");this.queryParams=t,this.objectName=t.objectName.charAt(0).toLowerCase()+t.objectName.slice(1),this.operationName=t.operationName,this.operationType=t.operationType||"query",this.isParent=e}setGraphqlService(t){return this.graphqlService=t,this}withFields(t){return t.forEach((t=>this.fields.add(t))),this}withFilter(t){if("mutation"===this.operationType)throw new Error("Cannot apply filters to a mutation.");if(this.isParent)throw new Error(`Cannot apply filters to parent query for object: ${this.objectName}`);return this.filters.push(t),this}withInput(t){if("query"===this.operationType)throw new Error("Cannot apply input to a query.");if(!t||0===Object.keys(t).length)throw new Error("Mutation input cannot be empty.");return this.input=t,this}withLimit(t){if("mutation"===this.operationType)throw new Error("Cannot apply limit to a mutation.");if(this.isParent)throw new Error(`Cannot apply limit to parent query for object: ${this.objectName}`);return this.first=t,this}withOffset(t){if("mutation"===this.operationType)throw new Error("Cannot apply offset to a mutation.");if(this.isParent)throw new Error(`Cannot apply offset to parent query for object: ${this.objectName}`);return this.offset=t,this}withOrderBy(t){if("mutation"===this.operationType)throw new Error("Cannot apply orderBy to a mutation.");if(this.isParent)throw new Error(`Cannot apply orderBy to parent query for object: ${this.objectName}`);return this.orderBy=t,this}withCursor(t){if("mutation"===this.operationType)throw new Error("Cannot apply cursor to a mutation.");if(this.isParent)throw new Error(`Cannot apply cursor to parent query for object: ${this.objectName}`);return this.after=t,this}withParentQuery(t){const e=new GraphQLQueryBuilder({objectName:t,operationName:this.operationName,operationType:this.operationType},!0);return this.parentQueries[t]=e,e}withChildQuery(t){const e=new GraphQLQueryBuilder({objectName:t,operationName:this.operationName,operationType:this.operationType});return this.childQueries[t]=e,e}formatQueryFields(){const t=[...this.fields];for(const[e,r]of Object.entries(this.parentQueries))t.push(`${e} { ${r.formatQueryFields()} }`);for(const[e,r]of Object.entries(this.childQueries)){const i=r.build(),o=i.filter?`(filter: "${i.filter}")`:"";t.push(`${e} ${o} { ${i.fields||"UID"} }`)}return t.filter(Boolean).join(", ")}build(){const t={objectName:this.objectName,operationName:this.operationName,operationType:this.operationType,fields:this.formatQueryFields(),readOnly:this.queryParams.readOnly};return"query"===this.operationType?(t.filter=this.filters.length>0?this.filters.join(" AND "):void 0,t.first=this.first,t.offset=this.offset,t.orderBy=this.orderBy,t.after=this.after):t.input=this.input||void 0,t}execute(){var t;if(!this.graphqlService)throw new Error(`No GraphQL service set for ${this.operationType} execution on ${this.objectName}.`);const e=this.build();if("mutation"===this.operationType){const r={objectName:this.objectName,operationName:this.operationName,operation:(null===(t=this.input)||void 0===t?void 0:t.operation)||graphql_1.GraphqlOperations.UPDATE,records:this.input?[this.input]:[],fields:e.fields?e.fields.split(", "):["UID"]};return this.graphqlService.mutate(r)}return this.graphqlService.query(e)}toString(){const t=[];"query"===this.operationType?(this.first&&t.push(`first: ${this.first}`),this.offset&&t.push(`offset: ${this.offset}`),this.orderBy&&t.push(`orderBy: "${this.orderBy}"`),this.after&&t.push(`after: "${this.after}"`),this.filters.length&&t.push(`filter: "${this.filters.join(" AND ")}"`)):this.input&&t.push(`input: ${JSON.stringify(this.input)}`);const e=t.length?`(${t.join(", ")})`:"";return`${this.operationType} ${this.operationName} { ${this.objectName}${e} { ${this.formatQueryFields()} } }`}}exports.GraphQLQueryBuilder=GraphQLQueryBuilder;class GraphQLBatchBuilder{constructor(){this.operations=[]}add(t){return this.operations.push(t),this}execute(){return __awaiter(this,void 0,void 0,(function*(){if(!this.operations.length)return[];const t=this.operations[0].graphqlService;if(!t)throw new Error("No GraphQL service set for batch execution.");if(this.operations.some((e=>e.graphqlService!==t)))throw new Error("All operations must use the same GraphQL service.");const e=this.operations.map((t=>t.build()));return t.executeBatch(e)}))}toString(){return this.operations.map((t=>t.toString())).join("\n")}}exports.GraphQLBatchBuilder=GraphQLBatchBuilder;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { QueryResult } from "../../interfaces";
|
|
2
|
+
import { GraphQLQueryBuilder } from "./graphql-query-builder";
|
|
3
|
+
export declare class GraphQLQueryBatch {
|
|
4
|
+
/**
|
|
5
|
+
* Executes a batch of queries.
|
|
6
|
+
* @param {GraphQLQueryBuilder[]} builders - Array of query builders.
|
|
7
|
+
* @returns {Promise<QueryResult[]>} - Array of query results.
|
|
8
|
+
*/
|
|
9
|
+
execute(builders: GraphQLQueryBuilder[]): Promise<QueryResult[]>;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(a,c){function i(t){try{u(n.next(t))}catch(t){c(t)}}function o(t){try{u(n.throw(t))}catch(t){c(t)}}function u(t){var e;t.done?a(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(i,o)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphQLQueryBatch=void 0;class GraphQLQueryBatch{execute(t){return __awaiter(this,void 0,void 0,(function*(){if(!t.length)return[];const e=t[0].graphqlService;if(!e)throw new Error("No GraphQL service set for batch execution.");const r=t.map((t=>t.build()));return e.queryBatch(r)}))}}exports.GraphQLQueryBatch=GraphQLQueryBatch;
|
|
@@ -19,7 +19,7 @@ export declare class GraphQLQueryBuilder {
|
|
|
19
19
|
private queryParams;
|
|
20
20
|
/**
|
|
21
21
|
* Creates an instance of GraphQLQueryBuilder.
|
|
22
|
-
* @param {
|
|
22
|
+
* @param {GraphqlQueryParams} queryParams - The parameters for the query.
|
|
23
23
|
* @param {boolean} [isParent=false] - Indicates if this query is a parent query.
|
|
24
24
|
*/
|
|
25
25
|
constructor(queryParams: GraphqlQueryParams, isParent?: boolean);
|
|
@@ -64,13 +64,21 @@ export declare class GraphQLQueryBuilder {
|
|
|
64
64
|
*/
|
|
65
65
|
private formatQueryFields;
|
|
66
66
|
/**
|
|
67
|
-
* Builds the GraphQL query parameters in a
|
|
67
|
+
* Builds the GraphQL query parameters in a structured format.
|
|
68
68
|
*/
|
|
69
69
|
build(): GraphqlQueryParams;
|
|
70
70
|
/**
|
|
71
|
-
* Executes the query using the GraphQL service
|
|
71
|
+
* Executes the query using the GraphQL service.
|
|
72
72
|
*/
|
|
73
73
|
execute(): Promise<QueryResult>;
|
|
74
|
+
/**
|
|
75
|
+
* Executes all queries for the configured object, fetching records from the specified page range, up to a maximum of 20 pages.
|
|
76
|
+
* @param {number} [fromPage=1] - The starting page number (1-based, defaults to 1).
|
|
77
|
+
* @param {number} [toPage=20] - The ending page number (defaults to 20, capped at 20).
|
|
78
|
+
* @returns {Promise<QueryResult>} - A query result containing all records in the page range and pagination info.
|
|
79
|
+
* @throws {Error} - If the query execution fails, no GraphQL service is set, or invalid page parameters are provided.
|
|
80
|
+
*/
|
|
81
|
+
executeAll(fromPage?: number, toPage?: number): Promise<QueryResult>;
|
|
74
82
|
/**
|
|
75
83
|
* Generates a string representation of the GraphQL query for debugging.
|
|
76
84
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphQLQueryBuilder=void 0;class GraphQLQueryBuilder{constructor(e,
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,r,i){return new(r||(r=Promise))((function(s,a){function o(e){try{h(i.next(e))}catch(e){a(e)}}function n(e){try{h(i.throw(e))}catch(e){a(e)}}function h(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,n)}h((i=i.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphQLQueryBuilder=void 0;class GraphQLQueryBuilder{constructor(e,t=!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=t}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 t=new GraphQLQueryBuilder({objectName:e,operationName:this.operationName},!0);return this.parentQueries[e]=t,t}withChildQuery(e){const t=new GraphQLQueryBuilder({objectName:e,operationName:this.operationName});return this.childQueries[e]=t,t}formatQueryFields(){const e=Object.entries(this.parentQueries).map((([e,t])=>`${e} { ${t.formatQueryFields()} }`)).join(", "),t=Object.entries(this.childQueries).map((([e,t])=>{const r=t.build();return`${e} ${r.filter?`(filter: "${r.filter}")`:""} { ${r.fields||"UID"} }`})).join(", ");return[...this.fields,e,t].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,readOnly:this.queryParams.readOnly}}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)}executeAll(){return __awaiter(this,arguments,void 0,(function*(e=1,t=20){if(!this.graphqlService)throw new Error("No GraphQL service set for query execution.");if(e<1)throw new Error("fromPage must be at least 1.");if(t<e)throw new Error("toPage must be greater than or equal to fromPage.");const r=Math.min(t,20),i=this.build(),s=yield this.graphqlService.query(i),a=s.totalCount;if(0===a)return{records:[],totalCount:0,pageInfo:{hasNextPage:!1},endCursor:"",endOffset:0};const o=this.first||200,n=Math.ceil(a/o),h=Math.min(r,n);if(0===Math.max(0,h-e+1))return{records:[],totalCount:a,pageInfo:{hasNextPage:h<n},endCursor:"",endOffset:(e-1)*o};const u=[];for(let t=e-1;t<h;t++){const e=new GraphQLQueryBuilder({objectName:this.objectName,operationName:this.operationName,readOnly:this.queryParams.readOnly});e.setGraphqlService(this.graphqlService),e.fields=new Set(this.fields),e.filters=[...this.filters],e.first=o,e.offset=t*o,e.orderBy=this.orderBy,e.after=this.after,u.push(e)}const l=yield this.graphqlService.queryBatch(u),f=l.flatMap((e=>e.records)),c=l[l.length-1];return{records:f,totalCount:s.totalCount,pageInfo:c.pageInfo,endCursor:c.endCursor,endOffset:c.endOffset}}))}toString(){return`{ ${this.objectName} { ${this.formatQueryFields()} } }`}}exports.GraphQLQueryBuilder=GraphQLQueryBuilder;
|