Skip to content

Commit

Permalink
ESM fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
charlypoly committed Mar 5, 2024
1 parent 6ef61f8 commit 70e4924
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

import { DeferableFunction, DeferredFunction } from "./index.js";
import { DeferableFunction, DeferredFunction } from "./index";

export type ExecutionState =
| "created"
Expand Down
46 changes: 23 additions & 23 deletions src/backend/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ import {
PageResult,
ReRunExecutionResult,
RescheduleExecutionResult,
} from "../backend.js";
} from "../backend";
import {
DeferableFunction,
DeferredFunction,
ExecutionMetadata,
} from "../index.js";
import { error, info } from "../logger.js";
import { getEnv, randomUUID, sleep, stringify } from "../utils.js";
import version from "../version.js";
import { Counter } from "./local/counter.js";
import { KV } from "./local/kv.js";
} from "../index";
import { error, info } from "../logger";
import { getEnv, randomUUID, sleep, stringify } from "../utils";
import version from "../version";
import { Counter } from "./local/counter";
import { KV } from "./local/kv";

interface InternalExecution<F extends DeferableFunction> {
id: string;
Expand Down Expand Up @@ -86,7 +86,7 @@ const banner = `

function paginate<T>(
page: PageRequest | undefined,
records: Map<string, T>,
records: Map<string, T>
): PageResult<T> {
let edges = Array.from(records.keys()).reverse();
let hasNextPage: boolean = false;
Expand Down Expand Up @@ -137,7 +137,7 @@ function paginate<T>(

function isExecutionMatchFilter(
filters: ExecutionFilters | undefined,
execution: InternalExecution<any>,
execution: InternalExecution<any>
): boolean {
if (
filters?.states &&
Expand All @@ -163,13 +163,13 @@ function isExecutionMatchFilter(

if (filters?.metadata && filters.metadata.length > 0 && execution.metadata) {
const metadataFilters = filters.metadata.filter(
(mdFilter) => mdFilter.values.length > 0,
(mdFilter) => mdFilter.values.length > 0
);
if (
!metadataFilters.some((mdFilter) =>
mdFilter.values.some(
(value) => execution.metadata[mdFilter.key] === value,
),
(value) => execution.metadata[mdFilter.key] === value
)
)
) {
return false;
Expand Down Expand Up @@ -264,7 +264,7 @@ async function loop(shouldRun: () => boolean): Promise<void> {
execution.updatedAt = new Date();

return execution;
},
}
);

if (shouldDiscard) {
Expand Down Expand Up @@ -320,7 +320,7 @@ async function loop(shouldRun: () => boolean): Promise<void> {
execution.updatedAt = new Date();
execution.errorCode = errorCode;
return execution;
},
}
);
};

Expand All @@ -342,7 +342,7 @@ export async function enqueue<F extends DeferableFunction>(
args: Parameters<F>,
scheduleFor: Date,
discardAfter: Date | undefined,
metadata: { [key: string]: string } | undefined,
metadata: { [key: string]: string } | undefined
): Promise<EnqueueResult> {
let functionId = functionIdMapping.get(func.__metadata.name);
if (functionId === undefined) {
Expand Down Expand Up @@ -396,7 +396,7 @@ export async function getExecutionResult(id: string): Promise<any> {

export async function cancelExecution(
id: string,
force: boolean,
force: boolean
): Promise<CancelExecutionResult> {
let execution = await executionsStore.get(id);
if (execution === undefined)
Expand All @@ -407,7 +407,7 @@ export async function cancelExecution(
switch (execution.state) {
case "aborting":
throw new ExecutionAbortingAlreadyInProgress(
"aborting execution already in progress",
"aborting execution already in progress"
);
case "created":
execution.state = "cancelled";
Expand All @@ -417,7 +417,7 @@ export async function cancelExecution(
break;
default:
throw new ExecutionNotCancellable(
`cannot cancel execution in "${execution.state}" state`,
`cannot cancel execution in "${execution.state}" state`
);
}
} else {
Expand All @@ -427,7 +427,7 @@ export async function cancelExecution(
break;
default:
throw new ExecutionNotCancellable(
`cannot cancel execution in "${execution.state}" state`,
`cannot cancel execution in "${execution.state}" state`
);
}
}
Expand All @@ -441,7 +441,7 @@ export async function cancelExecution(

export async function rescheduleExecution(
id: string,
scheduleFor: Date,
scheduleFor: Date
): Promise<RescheduleExecutionResult> {
let execution = await executionsStore.get(id);
if (execution === undefined)
Expand All @@ -460,7 +460,7 @@ export async function rescheduleExecution(
}

export async function reRunExecution(
id: string,
id: string
): Promise<ReRunExecutionResult> {
const execution = await executionsStore.get(id);
if (execution === undefined)
Expand All @@ -487,7 +487,7 @@ export async function reRunExecution(

export async function listExecutions(
pageRequest?: PageRequest,
filters?: ExecutionFilters,
filters?: ExecutionFilters
): Promise<ListExecutionsResult> {
const executionIds = await executionsStore.keys();
const data = new Map<string, Execution>();
Expand All @@ -505,7 +505,7 @@ export async function listExecutions(
export async function listExecutionAttempts(
id: string,
pageRequest?: PageRequest,
filters?: ExecutionFilters,
filters?: ExecutionFilters
): Promise<ListExecutionAttemptsResult> {
const executionIds = await executionsStore.keys();
const data = new Map<string, Execution>();
Expand Down
8 changes: 4 additions & 4 deletions src/backend/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import {
PageRequest,
ReRunExecutionResult,
RescheduleExecutionResult,
} from "../backend.js";
import { DeferableFunction, DeferredFunction } from "../index.js";
import { getEnv, stringify } from "../utils.js";
import { HTTPClient, makeHTTPClient } from "./remote/httpClient.js";
} from "../backend";
import { DeferableFunction, DeferredFunction } from "../index";
import { getEnv, stringify } from "../utils";
import { HTTPClient, makeHTTPClient } from "./remote/httpClient";

export interface SingleObjectResponse<T> {
data: T;
Expand Down
6 changes: 3 additions & 3 deletions src/backend/remote/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

import { DeferError } from "../../backend.js";
import { errorMessage } from "../../utils.js";
import VERSION from "../../version.js";
import { DeferError } from "../../backend";
import { errorMessage } from "../../utils";
import VERSION from "../../version";

export type HTTPClient = <T>(
method: string,
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import {
PageRequest,
ReRunExecutionResult,
RescheduleExecutionResult,
} from "./backend.js";
import * as localBackend from "./backend/local.js";
import * as remoteBackend from "./backend/remote.js";
import { jitter } from "./jitter.js";
import { info, warn } from "./logger.js";
import { Duration, fromDurationToDate, getEnv, sleep } from "./utils.js";
} from "./backend";
import * as localBackend from "./backend/local";
import * as remoteBackend from "./backend/remote";
import { jitter } from "./jitter";
import { info, warn } from "./logger";
import { Duration, fromDurationToDate, getEnv, sleep } from "./utils";

const INTERNAL_VERSION = 6;
const RETRY_MAX_ATTEMPTS_PLACEHOLDER = 13;
Expand Down
4 changes: 2 additions & 2 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

import { isDebugEnabled } from "./utils.js";
import { isDebugEnabled } from "./utils";

// source: https://github.com/csquared/node-logfmt/blob/master/lib/stringify.js
// source: https://github.com/csquared/node-logfmt/blob/master/lib/stringify
function fmtData(data: any): string {
var line = "";

Expand Down
8 changes: 4 additions & 4 deletions src/next/asNextRoute.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { NextRequest, NextResponse } from "next/server";
import { DeferError } from "../backend.js";
import { DeferError } from "../backend";
import {
DeferredFunction,
getExecution,
getExecutionResult,
} from "../index.js";
} from "../index";

export interface DeferNextRoute {
GetHandler: (request: NextRequest) => Promise<NextResponse | Response>;
Expand All @@ -18,7 +18,7 @@ interface Options<
proxy?: (request: NextRequest) => Promise<Parameters<F>>;
}

const ResponseJSON = Response.json;
const ResponseJSON = Responseon;

Check failure on line 21 in src/next/asNextRoute.ts

View workflow job for this annotation

GitHub Actions / release

Cannot find name 'Responseon'. Did you mean 'ResponseJSON'?

export function asNextRoute<F extends (...args: any) => Promise<any>>(
deferFn: DeferredFunction<F>,
Expand Down Expand Up @@ -64,7 +64,7 @@ export function asNextRoute<F extends (...args: any) => Promise<any>>(
PostHandler: async (request: NextRequest) => {
const args: any = options?.proxy
? await options.proxy(request)
: await request.json();
: await requeston();

Check failure on line 67 in src/next/asNextRoute.ts

View workflow job for this annotation

GitHub Actions / release

Cannot find name 'requeston'. Did you mean 'request'?
if (Array.isArray(args)) {
// @ts-expect-error Charly: need to be refined
const execution = await deferFn(...args);
Expand Down
4 changes: 2 additions & 2 deletions src/next/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { DeferNextRoute, asNextRoute } from "./asNextRoute.js";
export { UseDeferRoute, useDeferRoute } from "./useDeferRoute.js";
export { DeferNextRoute, asNextRoute } from "./asNextRoute";
export { UseDeferRoute, useDeferRoute } from "./useDeferRoute";
8 changes: 4 additions & 4 deletions src/next/useDeferRoute.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import { useCallback, useRef, useState } from "react";
import type { ExecutionState } from "../backend.js";
import type { DeferredFunction } from "../index.js";
import type { ExecutionState } from "../backend";
import type { DeferredFunction } from "../index";

export type UseDeferRoute<ARA extends boolean, A extends any[], R> = [
execute: (...args: ARA extends true ? any : A) => void,
Expand Down Expand Up @@ -40,7 +40,7 @@ export const useDeferRoute = <
const res = await fetch(`${routePath}?id=${executionId}`, {

Check failure on line 40 in src/next/useDeferRoute.ts

View workflow job for this annotation

GitHub Actions / Bun 1

'res' is assigned a value but never used

Check failure on line 40 in src/next/useDeferRoute.ts

View workflow job for this annotation

GitHub Actions / release

'res' is declared but its value is never read.

Check failure on line 40 in src/next/useDeferRoute.ts

View workflow job for this annotation

GitHub Actions / Node 18

'res' is assigned a value but never used

Check failure on line 40 in src/next/useDeferRoute.ts

View workflow job for this annotation

GitHub Actions / Node 20

'res' is assigned a value but never used
method: "GET",
});
const data = (await res.json()) as any;
const data = (await reson()) as any;

Check failure on line 43 in src/next/useDeferRoute.ts

View workflow job for this annotation

GitHub Actions / release

Cannot find name 'reson'. Did you mean 'res'?
setStatus(data.state);
if (["succeed", "failed"].includes(data.state) && intervalRef.current) {
clearInterval(intervalRef.current);
Expand All @@ -67,7 +67,7 @@ export const useDeferRoute = <
"Content-type": "application/json",
},
});
const data = await result.json();
const data = await resulton();

Check failure on line 70 in src/next/useDeferRoute.ts

View workflow job for this annotation

GitHub Actions / release

Cannot find name 'resulton'. Did you mean 'result'?
intervalRef.current = setInterval(
pollExecution(data.id),
Math.max(500, refreshInterval),
Expand Down
6 changes: 3 additions & 3 deletions tests/backend/local.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
process.env["DEFER_NO_LOCAL_SCHEDULER"] = "1";
process.env["DEFER_NO_BANNER"] = "1";

import { ExecutionNotFound } from "../../src/backend.js";
import { ExecutionNotFound } from "../../src/backend";
import {
cancelExecution,
enqueue,
getExecution,
reRunExecution,
rescheduleExecution,
} from "../../src/backend/local.js";
import { defer } from "../../src/index.js";
} from "../../src/backend/local";
import { defer } from "../../src/index";

const myFunc = async () => console.log("the cake is a lie");
const myDeferedFunc = defer(myFunc);
Expand Down
2 changes: 1 addition & 1 deletion tests/backend/local/counter.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Counter } from "../../../src/backend/local/counter.js";
import { Counter } from "../../../src/backend/local/counter";

describe("incr/1", () => {
describe("increment non existing key", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/backend/local/kv.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KV } from "../../../src/backend/local/kv.js";
import { KV } from "../../../src/backend/local/kv";

describe("set/2", () => {
it("adds value in the store", async () => {
Expand Down
6 changes: 3 additions & 3 deletions tests/backend/remote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ExecutionNotCancellable,
ExecutionNotFound,
ExecutionNotReschedulable,
} from "../../src/backend.js";
} from "../../src/backend";
import {
cancelExecution,
enqueue,
Expand All @@ -16,8 +16,8 @@ import {
listExecutions,
reRunExecution,
rescheduleExecution,
} from "../../src/backend/remote.js";
import { defer } from "../../src/index.js";
} from "../../src/backend/remote";
import { defer } from "../../src/index";

global.fetch = jest.fn();

Expand Down
2 changes: 1 addition & 1 deletion tests/backend/remote/httpClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
makeHTTPClient,
ClientError,
} from "../../../src/backend/remote/httpClient.js";
} from "../../../src/backend/remote/httpClient";

global.fetch = jest.fn();

Expand Down
2 changes: 1 addition & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
listExecutions,
reRunExecution,
rescheduleExecution,
} from "../src/index.js";
} from "../src/index";

var stop: () => Promise<void> | undefined;

Expand Down
2 changes: 1 addition & 1 deletion tests/logger.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { error, info, log, warn } from "../src/logger.js";
import { error, info, log, warn } from "../src/logger";

describe("log/3", () => {
it("test without data", () => {
Expand Down
Loading

0 comments on commit 70e4924

Please sign in to comment.