//------------------------------------------------------------------ // Proxy Script Generated by Delphi Microservices Container 4.3.20 // Do not modify this code! // Generated at: 2025-04-26 18.08.37 //------------------------------------------------------------------ export class SynchUtilsRPCProxy { __baseUrl = ""; constructor(baseUrl) { this.__baseUrl = baseUrl; } get baseUrl() { return this.__baseUrl; } __getJsonRpcRequest(jsonrpcRequestMethod, params) { let json = this.__getJsonRpcNotification(jsonrpcRequestMethod, params); json["id"] = Math.trunc(Math.random() * 100000); return json; } __getJsonRpcNotification(jsonrpcRequestMethod, params) { return { "jsonrpc": "2.0", "method": jsonrpcRequestMethod, "params": params }; } __internalFetch(type, baseUrl, jsonrpcMethod, params) { let jsonbody = null; if (type === 'notification') { jsonbody = this.__getJsonRpcNotification(jsonrpcMethod, params); } else if (type === 'request') { jsonbody = this.__getJsonRpcRequest(jsonrpcMethod, params); } return fetch(baseUrl, { "method": "POST", "body": JSON.stringify(jsonbody), "headers": { "content-type": "application/json", "accept": "application/json" } }).then(data => { switch (data.status) { case 200: { return data.json(); } case 204: { //no content return null; } default: { return data.json(); } } }); } __jsonRpcResponsePromise(type, baseUrl, method, params) { switch (type) { case "request": { return new Promise((resolve, reject) => { this.__internalFetch('request', this.baseUrl, method, params).then(jsonresp => { if ("result" in jsonresp) { resolve(jsonresp.result) } else if ("error" in jsonresp) { reject(jsonresp.error) } else { throw new Error("Invalid JSON-RPC response"); } }); }) break; } case "notification": { return new Promise((resolve, reject) => { this.__internalFetch('notification', this.baseUrl, method, params).then(jsonresp => { if (jsonresp !== null && "error" in jsonresp) { reject(jsonresp.error); } else { resolve(); } }); }) break; } default: { throw new Error("JSON-RPC message must be 'request' or 'notification' [Actual: '" + type + '"]'); } } } // Following methods are automatically generated // Invokes [function TryAcquireLock(const Token: string; const LockIdentifier: string; const LockTTL: Int64; const LockData: TJsonObject): string] // Tries to acquire an exclusive lock on `LockIdentifier` for a max of `LockTTL` minutes, optionally attaching the data contained in `LockData`. // TryAcquireLock calls cannot be nested - a subsequent call with same LockIdentifier tryies to re-acquire the lock and will raise an exception if can't. // If the lock has been acquired, TryAcquireLock returns a (a random string) that need to be used to estend or release the lock. // If cannot acquire lock, returns the const string "error" tryAcquireLock(token, lockIdentifier, lockTtl, lockData) { return this.__jsonRpcResponsePromise('request', this.__baseUrl, 'TryAcquireLock',{ "token": token, "lockIdentifier": lockIdentifier, "lockTtl": lockTtl, "lockData": lockData }); } // Invokes [function ExtendLock(const Token: string; const LockTTL: Int64; const LockHandle: string): Boolean] // Allows to extend the LockTTL for an owned-lock. LockExtender is the token returned by the TryAcquireLock call. Lock extension starts from "now" for LockTTL seconds. extendLock(token, lockTtl, lockHandle) { return this.__jsonRpcResponsePromise('request', this.__baseUrl, 'ExtendLock',{ "token": token, "lockTtl": lockTtl, "lockHandle": lockHandle }); } // Invokes [function GetLockData(const Token: string; const LockIdentifier: string): TJsonObject] // Get the lock data from an exclusive lock (owned, or not owned, by the user). If the lock doesn't exist, an exception raise. getLockData(token, lockIdentifier) { return this.__jsonRpcResponsePromise('request', this.__baseUrl, 'GetLockData',{ "token": token, "lockIdentifier": lockIdentifier }); } // Invokes [function GetLockExpiration(const Token: string; const LockIdentifier: string): Int64] // Returns the time remaining for the natural exclusive lock expiration and the LockData.If the lock doesn't exists property "expires_in" is -1. getLockExpiration(token, lockIdentifier) { return this.__jsonRpcResponsePromise('request', this.__baseUrl, 'GetLockExpiration',{ "token": token, "lockIdentifier": lockIdentifier }); } // Invokes [function GetExclusiveLockQueueName(const Token: string; const LockIdentifier: string): string] // Returns the system queue where any change to the lock status is published. getExclusiveLockQueueName(token, lockIdentifier) { return this.__jsonRpcResponsePromise('request', this.__baseUrl, 'GetExclusiveLockQueueName',{ "token": token, "lockIdentifier": lockIdentifier }); } // Invokes [function ReleaseLock(const Token: string; const LockHandle: string): Boolean] // Release an owned exclusive lock and return true. If the lock doesn't exist or is not owned by the current user, return false. releaseLock(token, lockHandle) { return this.__jsonRpcResponsePromise('request', this.__baseUrl, 'ReleaseLock',{ "token": token, "lockHandle": lockHandle }); } // Invokes [function GetLocks(const Token: string): TJsonObject] // Returns all active locks - only ADMIN and MONITOR roles can call this method getLocks(token) { return this.__jsonRpcResponsePromise('request', this.__baseUrl, 'GetLocks',{ "token": token }); } // Invokes [function Login(const UserName: string; const Password: string): TJsonObject] // Returns the JWT token which can be used to call all other methods. login(userName, password) { return this.__jsonRpcResponsePromise('request', this.__baseUrl, 'Login',{ "userName": userName, "password": password }); } // Invokes [function RefreshToken(const Token: string): TJsonObject] // Extends the expiration time of a still-valid token. Clients must use the token returned instead of the previous one. refreshToken(token) { return this.__jsonRpcResponsePromise('request', this.__baseUrl, 'RefreshToken',{ "token": token }); } } //end