Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cli/jitsu-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"chalk": "^5.3.0",
"commander": "^11.0.0",
"cross-fetch": "^4.0.0",
"cuid": "^2.1.8",
"etag": "^1.8.1",
"inquirer": "^9.2.11",
"jest": "^29.7.0",
Expand Down
4 changes: 2 additions & 2 deletions cli/jitsu-cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { homedir } from "os";
import inquirer from "inquirer";
import { existsSync, readdirSync, readFileSync } from "fs";
import { loadPackageJson } from "./shared";
import cuid from "cuid";
import { randomId } from "juava";
import { b, green, red } from "../lib/chalk-code-highlight";
import { getFunctionFromFilePath } from "../lib/compiled-function";
import { loadProjectConfig } from "../lib/project-config";
Expand Down Expand Up @@ -298,7 +298,7 @@ async function deployFunction(
};
}
if (!existingFunctionId) {
const id = cuid();
const id = randomId();
const res = await fetch(`${host}/api/${workspace.id}/config/function`, {
method: "POST",
headers: {
Expand Down
130 changes: 0 additions & 130 deletions libs/juava/src/debounce.ts

This file was deleted.

20 changes: 3 additions & 17 deletions libs/juava/src/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,9 @@ export function deepMerge(target: any, source: any) {
}, target);
}

export function deepCopy<T>(o: T): T {
if (typeof o !== "object") return o;
if (!o) return o;
if (Array.isArray(o)) {
const newO: any[] = [];
for (let i = 0; i < o.length; i++) {
const v = o[i];
newO[i] = !v || typeof v !== "object" ? v : deepCopy(v);
}
return newO as T;
}
const newO: Record<string, any> = {};
for (const [k, v] of Object.entries(o)) {
newO[k] = !v || typeof v !== "object" ? v : deepCopy(v);
}
return newO as T;
}
// ponytail: structuredClone is native; unlike the old hand-rolled copy it throws on
// functions in the tree — callers pass JSON-safe data only
export const deepCopy = <T>(o: T): T => structuredClone(o);

export function isEqual(x: any, y: any) {
const ok = Object.keys,
Expand Down
14 changes: 9 additions & 5 deletions libs/juava/src/singleton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getErrorMessage, getLog, newError, requireDefined } from "./index";
import * as process from "process";
import { debounce } from "./debounce";
const log = getLog("singleton");

export type CachedValue<T> = (
Expand Down Expand Up @@ -74,14 +73,19 @@ export function getSingleton<T>(
return singleton as Singleton<T>;
}

// ponytail: resettable timeout replaces a vendored 130-line lodash debounce —
// each call postpones cleanup to ttlSec after the last access
let cleanupTimer: ReturnType<typeof setTimeout> | undefined;
const scheduleCleanup = () => {
clearTimeout(cleanupTimer);
cleanupTimer = setTimeout(() => clearSingleton(globalName, opts.cleanupFunc), 1000 * opts.ttlSec!);
};

const handleSuccess = (value: T, startedAtTs: number): T => {
global[`singletons_${globalName}`] = {
success: true,
value,
debounceCleanup:
opts.ttlSec && opts.ttlSec > 0
? debounce(() => clearSingleton(globalName, opts.cleanupFunc), 1000 * opts.ttlSec)
: () => {},
debounceCleanup: opts.ttlSec && opts.ttlSec > 0 ? scheduleCleanup : () => {},
};
if (!opts.silent) {
log.atInfo().log(`️⚡️⚡️⚡️ ${globalName} connected in ${Date.now() - startedAtTs}ms!`);
Expand Down
Loading