Skip to content
Merged
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
5 changes: 3 additions & 2 deletions src/app/(outerbase)/local/hooks.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SavedConnectionRawLocalStorage } from "@/app/(theme)/connect/saved-connection-storage";
import { LocalConnectionData, LocalDashboardData, localDb } from "@/indexdb";
import { generateId } from "@/lib/generate-id";
import parseSafeJson from "@/lib/json-safe";
import useSWR, { mutate } from "swr";

Expand All @@ -18,7 +19,7 @@ export function useLocalDashboardList() {
}

export async function createLocalDashboard(boardName: string) {
const id = crypto.randomUUID();
const id = generateId();
const now = Date.now();

const data: LocalDashboardData = {
Expand Down Expand Up @@ -103,7 +104,7 @@ export async function removeLocalConnection(id: string) {
export async function createLocalConnection(
config: SavedConnectionRawLocalStorage
): Promise<LocalConnectionData> {
const id = crypto.randomUUID();
const id = generateId();

const data = {
id,
Expand Down
3 changes: 2 additions & 1 deletion src/app/api/events/insert-tracking-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import StarbaseDriver from "@/drivers/starbase-driver";
import { env } from "@/env";
import { generateId } from "@/lib/generate-id";
import { type TrackEventItem } from "../../../lib/tracking";

export async function insertTrackingRecord(
Expand All @@ -26,7 +27,7 @@ export async function insertTrackingRecord(
(event) =>
"(" +
[
crypto.randomUUID(),
generateId(),
Date.now(),
deviceId,
event.name,
Expand Down
3 changes: 2 additions & 1 deletion src/components/editor/prompt-plugin.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AgentDriverList from "@/drivers/agent/list";
import { generateId } from "@/lib/generate-id";
import { unifiedMergeView } from "@codemirror/merge";
import {
Compartment,
Expand Down Expand Up @@ -73,7 +74,7 @@ class PromptWidget extends WidgetType {
super();

// Generate unique session id for this prompt
const sessionId = crypto.randomUUID();
const sessionId = generateId();

plugin.lock();
this.container = document.createElement("div");
Expand Down
3 changes: 2 additions & 1 deletion src/components/filehandler-picker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { localDb } from "@/indexdb";
import { generateId } from "@/lib/generate-id";
import { cn } from "@/lib/utils";
import { LucideFile, LucideFolderClosed } from "lucide-react";
import { useCallback, useEffect, useState } from "react";
Expand Down Expand Up @@ -52,7 +53,7 @@ async function openFileHandler() {
],
});

const id = crypto.randomUUID();
const id = generateId();
localDb.file_handler.add({ id, handler: newFileHandler }).then();

return id;
Expand Down
3 changes: 2 additions & 1 deletion src/components/gui/schema-editor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useStudioContext } from "@/context/driver-provider";
import { DatabaseTableSchemaChange } from "@/drivers/base-driver";
import { generateId } from "@/lib/generate-id";
import { checkSchemaChange } from "@/lib/sql/sql-generate.schema";
import { LucideCode, LucideCopy, LucidePlus, LucideSave } from "lucide-react";
import { Dispatch, SetStateAction, useCallback, useMemo } from "react";
Expand Down Expand Up @@ -51,7 +52,7 @@ export default function SchemaEditor({
columns: [
...value.columns,
{
key: window.crypto.randomUUID(),
key: generateId(),
old: null,
new: newColumn,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DatabaseTableConstraintChange,
DatabaseTableSchemaChange,
} from "@/drivers/base-driver";
import { generateId } from "@/lib/generate-id";
import { cn } from "@/lib/utils";
import {
LucideArrowUpRight,
Expand Down Expand Up @@ -410,7 +411,7 @@ export default function SchemaEditorConstraintList({
constraints: [
...prev.constraints,
{
id: window.crypto.randomUUID(),
id: generateId(),
new: con,
old: null,
},
Expand Down
3 changes: 2 additions & 1 deletion src/components/gui/table-result/context-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
exportRowsToJson,
exportRowsToSqlInsert,
} from "@/lib/export-helper";
import { generateId } from "@/lib/generate-id";
import { KEY_BINDING } from "@/lib/key-matcher";
import { LucidePlus, LucideTrash2 } from "lucide-react";
import { useCallback } from "react";
Expand Down Expand Up @@ -34,7 +35,7 @@ export default function useTableResultContextMenu({
state: OptimizeTableState;
event: React.MouseEvent;
}) => {
const randomUUID = crypto.randomUUID();
const randomUUID = generateId();
const timestamp = Math.floor(Date.now() / 1000).toString();
const hasFocus = !!state.getFocus();

Expand Down
3 changes: 2 additions & 1 deletion src/components/gui/tabs/schema-editor-tab.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import OpacityLoading from "@/components/gui/loading-opacity";
import { useStudioContext } from "@/context/driver-provider";
import { DatabaseTableSchemaChange } from "@/drivers/base-driver";
import { generateId } from "@/lib/generate-id";
import { createTableSchemaDraft } from "@/lib/sql/sql-generate.schema";
import { cloneDeep } from "lodash";
import { useCallback, useEffect, useMemo, useState } from "react";
Expand Down Expand Up @@ -74,7 +75,7 @@ export default function SchemaEditorTab({
}))
.filter((col) => col.old),
constraints: prev.constraints.map((con) => ({
id: window.crypto.randomUUID(),
id: generateId(),
old: con.old,
new: cloneDeep(con.old),
})),
Expand Down
5 changes: 3 additions & 2 deletions src/core/builtin-tab/open-query-tab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import QueryWindow from "@/components/gui/tabs/query-tab";
import { generateId } from "@/lib/generate-id";
import { Binoculars } from "@phosphor-icons/react";
import { createTabExtension } from "../extension-tab";

Expand All @@ -20,11 +21,11 @@ export const builtinOpenQueryTab = createTabExtension<
if (options?.saved) {
return options.saved.key;
}
return window.crypto.randomUUID();
return generateId();
},
generate: (options) => {
const title = options?.saved
? options.name ?? "Query"
? (options.name ?? "Query")
: "Query " + (QUERY_COUNTER++).toString();

const component = options?.saved ? (
Expand Down
3 changes: 2 additions & 1 deletion src/drivers/agent/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { generateId } from "@/lib/generate-id";
import {
BaseDriver,
DatabaseSchemas,
Expand Down Expand Up @@ -61,7 +62,7 @@ export default abstract class CommonAgentDriverImplementation extends AgentBaseD
option: AgentPromptOption
): Promise<string> {
const session = this.history[previousId ?? ""] ?? {
id: previousId || crypto.randomUUID(),
id: previousId || generateId(),
createdAt: Date.now(),
messages: [],
};
Expand Down
3 changes: 2 additions & 1 deletion src/drivers/board-storage/local.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { DashboardProps } from "@/components/board";
import { ChartValue } from "@/components/chart/chart-type";
import { LocalDashboardData, localDb } from "@/indexdb";
import { generateId } from "@/lib/generate-id";
import { IBoardStorageDriver } from "./base";

export default class LocalBoardStorage implements IBoardStorageDriver {
constructor(protected board: LocalDashboardData) {}

async add(chart: ChartValue): Promise<ChartValue | undefined> {
const id = crypto.randomUUID();
const id = generateId();
const now = Date.now();

const data: ChartValue = {
Expand Down
7 changes: 4 additions & 3 deletions src/drivers/saved-doc/electron-saved-doc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use client";
import { generateId } from "@/lib/generate-id";
import {
SavedDocData,
SavedDocDriver,
Expand Down Expand Up @@ -32,7 +33,7 @@ export default class ElectronSavedDocs implements SavedDocDriver {

this.cacheDocs = {
workspace: [],
}
};

return this.cacheNamespaceList;
} else {
Expand Down Expand Up @@ -60,7 +61,7 @@ export default class ElectronSavedDocs implements SavedDocDriver {
await this.getNamespaces();

const now = Math.floor(Date.now() / 1000);
const id = window.crypto.randomUUID();
const id = generateId();

const namespace = {
id,
Expand Down Expand Up @@ -119,7 +120,7 @@ export default class ElectronSavedDocs implements SavedDocDriver {
(n) => n.id === namespace
)!,
type,
id: window.crypto.randomUUID(),
id: generateId(),
};

if (this.cacheDocs[r.namespace.id]) {
Expand Down
5 changes: 3 additions & 2 deletions src/drivers/saved-doc/indexdb-saved-doc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { localDb } from "@/indexdb";
import { generateId } from "@/lib/generate-id";
import {
SavedDocData,
SavedDocDriver,
Expand All @@ -18,7 +19,7 @@ export default class IndexdbSavedDoc implements SavedDocDriver {

async createNamespace(name: string): Promise<SavedDocNamespace> {
const now = Math.floor(Date.now() / 1000);
const id = window.crypto.randomUUID();
const id = generateId();

await localDb.namespace.add({
id,
Expand Down Expand Up @@ -92,7 +93,7 @@ export default class IndexdbSavedDoc implements SavedDocDriver {
data: SavedDocInput
): Promise<SavedDocData> {
const now = Math.floor(Date.now() / 1000);
const id = window.crypto.randomUUID();
const id = generateId();

const namespaceData = await localDb.namespace.get(namespace);
if (!namespaceData) throw new Error("Namespace does not exist");
Expand Down
13 changes: 13 additions & 0 deletions src/lib/generate-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function generateId() {
if (crypto.randomUUID) {
return crypto.randomUUID();
}

// https://stackoverflow.com/questions/105034/how-do-i-create-a-guid-uuid/2117523#2117523
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) =>

Check warning on line 7 in src/lib/generate-id.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
(
+c ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (+c / 4)))
).toString(16)

Check warning on line 11 in src/lib/generate-id.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 11 in src/lib/generate-id.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
);
}
7 changes: 4 additions & 3 deletions src/lib/sql/sql-generate.schema.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import deepEqual from "deep-equal";
import {
DatabaseTableColumnChange,
DatabaseTableSchema,
DatabaseTableSchemaChange,
} from "@/drivers/base-driver";
import deepEqual from "deep-equal";
import { cloneDeep } from "lodash";
import { generateId } from "../generate-id";

export function checkSchemaColumnChange(change: DatabaseTableColumnChange) {
return !deepEqual(change.old, change.new);
Expand Down Expand Up @@ -33,15 +34,15 @@
new: schema.tableName,
},
columns: schema.columns.map((col) => ({
key: window.crypto.randomUUID(),
key: generateId(),
old: col,
new: cloneDeep(col),
})),
constraints: (schema.constraints ?? []).map((con) => ({
id: window.crypto.randomUUID(),
id: generateId(),
old: con,
new: cloneDeep(con),
})),

Check warning on line 45 in src/lib/sql/sql-generate.schema.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
createScript: schema.createScript,
};
}
3 changes: 2 additions & 1 deletion src/lib/tracking.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { generateId } from "./generate-id";
import { throttleEvent } from "./tracking-throttle";

export interface TrackEventItem {
Expand Down Expand Up @@ -39,7 +40,7 @@ export function sendAnalyticEvents(events: TrackEventItem[]) {

let deviceId = localStorage.getItem("od-id");
if (!deviceId) {
deviceId = crypto.randomUUID();
deviceId = generateId();
localStorage.setItem("od-id", deviceId);
}

Expand Down