public async purgeInstanceHistoryBy()

in src/durableClient/DurableClient.ts [191:254]


    public async purgeInstanceHistoryBy(filter: OrchestrationFilter): Promise<PurgeHistoryResult> {
        let requestUrl: string;
        const { createdTimeFrom, createdTimeTo, runtimeStatus } = filter;
        if (this.clientData.rpcBaseUrl) {
            // Fast local RPC path
            let path = new URL("instances/", this.clientData.rpcBaseUrl).href;
            const query: string[] = [];
            if (createdTimeFrom) {
                query.push(`createdTimeFrom=${createdTimeFrom.toISOString()}`);
            }
            if (createdTimeTo) {
                query.push(`createdTimeTo=${createdTimeTo.toISOString()}`);
            }
            if (runtimeStatus && runtimeStatus.length > 0) {
                const statusList: string = runtimeStatus.map((value) => value.toString()).join(",");
                query.push(`runtimeStatus=${statusList}`);
            }

            if (query.length > 0) {
                path += "?" + query.join("&");
            }

            requestUrl = new URL(path, this.clientData.rpcBaseUrl).href;
        } else {
            // Legacy app frontend path
            const idPlaceholder = this.clientData.managementUrls.id;
            requestUrl = this.clientData.managementUrls.statusQueryGetUri.replace(
                idPlaceholder,
                ""
            );

            if (!(createdTimeFrom instanceof Date)) {
                throw new Error("createdTimeFrom must be a valid Date");
            }

            if (createdTimeFrom) {
                requestUrl += `&${this.createdTimeFromQueryKey}=${createdTimeFrom.toISOString()}`;
            }

            if (createdTimeTo) {
                requestUrl += `&${this.createdTimeToQueryKey}=${createdTimeTo.toISOString()}`;
            }

            if (runtimeStatus && runtimeStatus.length > 0) {
                const statusesString = runtimeStatus
                    .map((value) => value.toString())
                    .reduce((acc, curr, i) => {
                        return acc + (i > 0 ? "," : "") + curr;
                    });

                requestUrl += `&${this.runtimeStatusQueryKey}=${statusesString}`;
            }
        }

        const response = await this.axiosInstance.delete(requestUrl);
        switch (response.status) {
            case 200: // instance found
                return response.data as PurgeHistoryResult;
            case 404: // instance not found
                return new PurgeHistoryResult(0);
            default:
                return Promise.reject(this.createGenericError(response));
        }
    }