mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-30 21:01:54 +08:00
## Stack Auth → Hexclave rename — PR 5 (internal symbols, paths,
packages, brand strings)
PR 5 finishes the **internal / non-wire** half of the Stack→Hexclave
rename. It only touches things where nothing outside the repo depends on
the exact name: internal symbols, file/dir names, the
`@stackframe/template` package, and residual brand strings. Plan +
progress are in `HEXCLAVE-RENAME-PR5-PLAN.md`.
Every step was verified green (`pnpm typecheck` + `pnpm lint`, 28/28)
and committed as its own checkpoint, then a fan-out of review agents
audited all commits and the findings were fixed.
### What changed
- **Internal symbols** (`@hexclave/shared`, `packages/template`, apps):
`stack*`/`Stack*` → `hexclave*`/`Hexclave*` — incl.
`stackGlobalsSymbol`, the `_Stack*AppImpl` classes,
`stackAppInternalsSymbol`, `StackContext`, `getStackStripe`, etc. The
`stack*App` local-variable convention
(`stackServerApp`/`stackClientApp`/…) was renamed across 175
source/example/doc files.
- **File renames**: `hexclave-handler/provider/context.tsx`,
`backend/hexclave.tsx`, `internal-tool/hexclave.ts`,
`hexclave-app-internals.ts`.
- **Directory renames**: `lib/hexclave-app`, `hexclave-companion`,
`[...hexclave]` route segment, `skills/hexclave`,
`dashboard/src/hexclave`, and the package dirs
**`packages/{next,shared,ui,sc,cli}`** (dropping the `stack-` prefix to
match the `@hexclave/*` npm names).
- **Packages**: `@stackframe/template` → `@hexclave/template`; **deleted
`packages/init-stack`** (onboarding lives in `@hexclave/cli init`; the
published npm package is untouched).
- **Brand strings**: reworded `Stack Auth`/`Stack dashboard` prose in
code + docs-mintlify, renamed `hexclave-app.mdx`/`use-hexclave-app.mdx`
with redirects, regenerated OpenAPI, updated coupled e2e assertions;
`doctor`/`init` now prefer `hexclave.config.ts`.
### Intentionally kept (verified, not oversights)
Wire/compat identifiers (`x-stack-*` headers, `stack-*` cookies,
`STACK_*` env names, `*.stack-auth.com`, `stackauth_`, `ask_stack_auth`,
query params), public `Stack*` SDK aliases, crypto/JWT/vault
domain-separation tags, `*-brand-sentinel`s, the
`Symbol.for("StackAuth--…")` string, `_stack_sync_metadata`, Postgres
`stackframe` / docker image names, the `stack-auth-logo*.svg` (used by
the rebrand modal), and `migration.mdx` / "formerly known as Stack Auth"
notes. False positives (Phosphor `StackIcon`/`StackSimple`, `TanStack`,
`OrbStack`, `stackable`/`Stacked` charts) left alone.
### Review pass
Six review agents audited all commits. Found + fixed one real bug — a
build script (`bundle-type-definitions.ts`) hardcoded the old
`lib/stack-app` glob path (not an import, so typecheck/lint were blind),
silently emptying the dashboard AI type bundle — plus stale comments, a
dead CI env var, and stale `.gitignore`/`.dockerignore` entries.
Cross-cutting audit confirmed **zero wire-compat identifiers were
accidentally renamed**.
### ⚠️ Verification note
`typecheck` + `lint` are fully green locally. The **e2e suite was not
run** (needs a live backend+DB), so the brand-string assertion +
OpenAPI-regen changes are verified by grep/codegen only — please let CI
exercise e2e to confirm.
### Base-branch note
This branch was forked from the local-only `cl/friendly-lewin-72293f`
(not on origin, no separate PR), so this PR against `dev` also carries
that branch's ~11 preceding Hexclave-rename commits (config-file rename,
env-var dual-read, AI setup-prompt rebrand). If those should land
separately, re-parent before merge.
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Finishes the internal Stack Auth → Hexclave rename and cleans up
remaining stragglers, including dev-tool and prompt copy. All changes
are internal-only; public/wire APIs remain unchanged. Re-merged `dev`
and resolved the payments create-purchase-url conflict.
- **Refactors**
- Internal symbols: stack*/Stack* → hexclave*/Hexclave* (e.g.,
`getHexclaveServerApp` via `@/hexclave`, `getHexclaveStripe`,
`hexclaveAppInternalsSymbol`, `hexclaveSchemaInfo`, Prisma
`__hexclave_*`, `data-hexclave-handler-page`, Stripe mock
`hexclavePortPrefix`).
- Files/dirs: moved to `lib/hexclave-app`; handler route
`[...hexclave]`; backend entry `src/hexclave.tsx`; dashboard internals
`hexclave-app-internals`; companion `hexclave-companion`; dropped
`stack-` prefix across package dirs
(`packages/{shared,ui,sc,cli,next}`); workflows/emulator paths now
`packages/cli`; Quetzal codegen env at `packages/next/.env.local`.
- Packages/docs: `@stackframe/template` → `@hexclave/template`; removed
`packages/init-stack`; regenerated OpenAPI and updated docs
slugs/redirects for hexclave-app/use-hexclave-app.
- Brand strings/prompts: reworded remaining “Stack” dashboard strings to
Hexclave; updated dev-tool copy and prompts; `doctor/init` now prefer
`hexclave.config.ts`. Kept all wire-compat identifiers and public
aliases (`x-stack-*`, `stack-*` cookies, `STACK_*` env,
`*.stack-auth.com`, `Stack*` SDK names).
- Rebased/merged onto latest `dev`: retained `@hexclave/template`, kept
`src` in published files, refreshed setup-prompt imports and docs JSON,
adopted 1.0.5 version bumps, and re-merged `dev` again (resolved
`create-purchase-url` with `getHexclaveStripe`).
- **Bug Fixes**
- Restored dashboard AI type bundle by pointing the glob to
`packages/template/src/lib/hexclave-app`.
- Addressed rename leftovers: updated lingering `@/stack` imports and
CSS selector, fixed schema/meta and port-prefix expansions, and aligned
emulator commands to `packages/cli`.
- CI/build: removed a dead env var and stale ignore entries; fixed
Docker by renaming `STACK_SKIP_TEMPLATE_GENERATION` →
`HEXCLAVE_SKIP_TEMPLATE_GENERATION`.
<sup>Written for commit 3c1af3bff3.
Summary will update on new commits.</sup>
<a
href="https://cubic.dev/pr/hexclave/hexclave/pull/1547?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
249 lines
9.4 KiB
TypeScript
249 lines
9.4 KiB
TypeScript
import { remainder } from "./math";
|
|
|
|
export function typedIncludes<T extends readonly any[]>(arr: T, item: unknown): item is T[number] {
|
|
return arr.includes(item);
|
|
}
|
|
import.meta.vitest?.test("typedIncludes", ({ expect }) => {
|
|
const arr = [1, 2, 3] as const;
|
|
expect(typedIncludes(arr, 1)).toBe(true);
|
|
expect(typedIncludes(arr, 4)).toBe(false);
|
|
expect(typedIncludes(arr, "1")).toBe(false);
|
|
|
|
const strArr = ["a", "b", "c"] as const;
|
|
expect(typedIncludes(strArr, "a")).toBe(true);
|
|
expect(typedIncludes(strArr, "d")).toBe(false);
|
|
});
|
|
|
|
export function enumerate<T extends readonly any[]>(arr: T): [number, T[number]][] {
|
|
return arr.map((item, index) => [index, item]);
|
|
}
|
|
import.meta.vitest?.test("enumerate", ({ expect }) => {
|
|
expect(enumerate([])).toEqual([]);
|
|
expect(enumerate([1, 2, 3])).toEqual([[0, 1], [1, 2], [2, 3]]);
|
|
expect(enumerate(["a", "b", "c"])).toEqual([[0, "a"], [1, "b"], [2, "c"]]);
|
|
});
|
|
|
|
export function isShallowEqual(a: readonly any[], b: readonly any[]): boolean {
|
|
if (a.length !== b.length) return false;
|
|
for (let i = 0; i < a.length; i++) {
|
|
if (a[i] !== b[i]) return false;
|
|
}
|
|
return true;
|
|
}
|
|
import.meta.vitest?.test("isShallowEqual", ({ expect }) => {
|
|
expect(isShallowEqual([], [])).toBe(true);
|
|
expect(isShallowEqual([1, 2, 3], [1, 2, 3])).toBe(true);
|
|
expect(isShallowEqual([1, 2, 3], [1, 2, 4])).toBe(false);
|
|
expect(isShallowEqual([1, 2, 3], [1, 2])).toBe(false);
|
|
expect(isShallowEqual([1, 2], [1, 2, 3])).toBe(false);
|
|
// Test with objects (reference equality)
|
|
const obj1 = { a: 1 };
|
|
const obj2 = { a: 1 };
|
|
expect(isShallowEqual([obj1], [obj1])).toBe(true);
|
|
expect(isShallowEqual([obj1], [obj2])).toBe(false);
|
|
});
|
|
|
|
/**
|
|
* Ponyfill for ES2023's findLastIndex.
|
|
*/
|
|
export function findLastIndex<T>(arr: readonly T[], predicate: (item: T) => boolean): number {
|
|
for (let i = arr.length - 1; i >= 0; i--) {
|
|
if (predicate(arr[i])) return i;
|
|
}
|
|
return -1;
|
|
}
|
|
import.meta.vitest?.test("findLastIndex", ({ expect }) => {
|
|
expect(findLastIndex([], () => true)).toBe(-1);
|
|
expect(findLastIndex([1, 2, 3, 4, 5], x => x % 2 === 0)).toBe(3); // 4 is at index 3
|
|
expect(findLastIndex([1, 2, 3, 4, 5], x => x > 10)).toBe(-1);
|
|
expect(findLastIndex([1, 2, 3, 2, 1], x => x === 2)).toBe(3);
|
|
expect(findLastIndex([1, 2, 3], x => x === 1)).toBe(0);
|
|
});
|
|
|
|
export function groupBy<T extends any, K>(
|
|
arr: Iterable<T>,
|
|
key: (item: T) => K,
|
|
): Map<K, T[]> {
|
|
const result = new Map<K, T[]>;
|
|
for (const item of arr) {
|
|
const k = key(item);
|
|
if (result.get(k) === undefined) result.set(k, []);
|
|
result.get(k)!.push(item);
|
|
}
|
|
return result;
|
|
}
|
|
import.meta.vitest?.test("groupBy", ({ expect }) => {
|
|
expect(groupBy([], (x) => x)).toEqual(new Map());
|
|
|
|
const numbers = [1, 2, 3, 4, 5, 6];
|
|
const grouped = groupBy(numbers, (n) => n % 2 === 0 ? "even" : "odd");
|
|
expect(grouped.get("even")).toEqual([2, 4, 6]);
|
|
expect(grouped.get("odd")).toEqual([1, 3, 5]);
|
|
|
|
// Check the actual lengths of the words to ensure our test is correct
|
|
const words = ["apple", "banana", "cherry", "date", "elderberry"];
|
|
|
|
const byLength = groupBy(words, (w) => w.length);
|
|
// Adjust expectations based on actual word lengths
|
|
expect(byLength.get(5)).toEqual(["apple"]);
|
|
expect(byLength.get(6)).toEqual(["banana", "cherry"]);
|
|
expect(byLength.get(4)).toEqual(["date"]);
|
|
expect(byLength.get(10)).toEqual(["elderberry"]);
|
|
});
|
|
|
|
export function range(endExclusive: number): number[];
|
|
export function range(startInclusive: number, endExclusive: number): number[];
|
|
export function range(startInclusive: number, endExclusive: number, step: number): number[];
|
|
export function range(startInclusive: number, endExclusive?: number, step?: number): number[] {
|
|
if (endExclusive === undefined) {
|
|
endExclusive = startInclusive;
|
|
startInclusive = 0;
|
|
}
|
|
if (step === undefined) step = 1;
|
|
|
|
const result = [];
|
|
for (let i = startInclusive; step > 0 ? (i < endExclusive) : (i > endExclusive); i += step) {
|
|
result.push(i);
|
|
}
|
|
return result;
|
|
}
|
|
import.meta.vitest?.test("range", ({ expect }) => {
|
|
expect(range(5)).toEqual([0, 1, 2, 3, 4]);
|
|
expect(range(2, 5)).toEqual([2, 3, 4]);
|
|
expect(range(1, 10, 2)).toEqual([1, 3, 5, 7, 9]);
|
|
expect(range(5, 0, -1)).toEqual([5, 4, 3, 2, 1]);
|
|
expect(range(0, 0)).toEqual([]);
|
|
expect(range(0, 10, 3)).toEqual([0, 3, 6, 9]);
|
|
});
|
|
|
|
|
|
export function rotateLeft(arr: readonly any[], n: number): any[] {
|
|
if (arr.length === 0) return [];
|
|
const index = remainder(n, arr.length);
|
|
return [...arr.slice(index), ...arr.slice(0, index)];
|
|
}
|
|
import.meta.vitest?.test("rotateLeft", ({ expect }) => {
|
|
expect(rotateLeft([], 1)).toEqual([]);
|
|
expect(rotateLeft([1, 2, 3, 4, 5], 0)).toEqual([1, 2, 3, 4, 5]);
|
|
expect(rotateLeft([1, 2, 3, 4, 5], 1)).toEqual([2, 3, 4, 5, 1]);
|
|
expect(rotateLeft([1, 2, 3, 4, 5], 3)).toEqual([4, 5, 1, 2, 3]);
|
|
expect(rotateLeft([1, 2, 3, 4, 5], 5)).toEqual([1, 2, 3, 4, 5]);
|
|
expect(rotateLeft([1, 2, 3, 4, 5], 6)).toEqual([2, 3, 4, 5, 1]);
|
|
});
|
|
|
|
export function rotateRight(arr: readonly any[], n: number): any[] {
|
|
return rotateLeft(arr, -n);
|
|
}
|
|
import.meta.vitest?.test("rotateRight", ({ expect }) => {
|
|
expect(rotateRight([], 1)).toEqual([]);
|
|
expect(rotateRight([1, 2, 3, 4, 5], 0)).toEqual([1, 2, 3, 4, 5]);
|
|
expect(rotateRight([1, 2, 3, 4, 5], 1)).toEqual([5, 1, 2, 3, 4]);
|
|
expect(rotateRight([1, 2, 3, 4, 5], 3)).toEqual([3, 4, 5, 1, 2]);
|
|
expect(rotateRight([1, 2, 3, 4, 5], 5)).toEqual([1, 2, 3, 4, 5]);
|
|
expect(rotateRight([1, 2, 3, 4, 5], 6)).toEqual([5, 1, 2, 3, 4]);
|
|
});
|
|
|
|
|
|
export function shuffle<T>(arr: readonly T[]): T[] {
|
|
const result = [...arr];
|
|
for (let i = result.length - 1; i > 0; i--) {
|
|
const j = Math.floor(Math.random() * (i + 1));
|
|
[result[i], result[j]] = [result[j], result[i]];
|
|
}
|
|
return result;
|
|
}
|
|
import.meta.vitest?.test("shuffle", ({ expect }) => {
|
|
// Test empty array
|
|
expect(shuffle([])).toEqual([]);
|
|
|
|
// Test single element array
|
|
expect(shuffle([1])).toEqual([1]);
|
|
|
|
// Test that shuffle returns a new array
|
|
const original = [1, 2, 3, 4, 5];
|
|
const shuffled = shuffle(original);
|
|
expect(shuffled).not.toBe(original);
|
|
|
|
// Test that all elements are preserved
|
|
expect(shuffled.sort((a, b) => a - b)).toEqual(original);
|
|
|
|
// Test with a larger array to ensure randomness
|
|
// This is a probabilistic test, but it's very unlikely to fail
|
|
const large = Array.from({ length: 100 }, (_, i) => i);
|
|
const shuffledLarge = shuffle(large);
|
|
expect(shuffledLarge).not.toEqual(large);
|
|
expect(shuffledLarge.sort((a, b) => a - b)).toEqual(large);
|
|
});
|
|
|
|
|
|
export function outerProduct<T, U>(arr1: readonly T[], arr2: readonly U[]): [T, U][] {
|
|
return arr1.flatMap((item1) => arr2.map((item2) => [item1, item2] as [T, U]));
|
|
}
|
|
import.meta.vitest?.test("outerProduct", ({ expect }) => {
|
|
expect(outerProduct([], [])).toEqual([]);
|
|
expect(outerProduct([1], [])).toEqual([]);
|
|
expect(outerProduct([], [1])).toEqual([]);
|
|
expect(outerProduct([1], [2])).toEqual([[1, 2]]);
|
|
expect(outerProduct([1, 2], [3, 4])).toEqual([[1, 3], [1, 4], [2, 3], [2, 4]]);
|
|
expect(outerProduct(["a", "b"], [1, 2])).toEqual([["a", 1], ["a", 2], ["b", 1], ["b", 2]]);
|
|
});
|
|
|
|
export function unique<T>(arr: readonly T[]): T[] {
|
|
return [...new Set(arr)];
|
|
}
|
|
import.meta.vitest?.test("unique", ({ expect }) => {
|
|
expect(unique([])).toEqual([]);
|
|
expect(unique([1, 2, 3])).toEqual([1, 2, 3]);
|
|
expect(unique([1, 2, 2, 3, 1, 3])).toEqual([1, 2, 3]);
|
|
// Test with objects (reference equality)
|
|
const obj = { a: 1 };
|
|
expect(unique([obj, obj])).toEqual([obj]);
|
|
// Test with different types
|
|
expect(unique([1, "1", true, 1, "1", true])).toEqual([1, "1", true]);
|
|
});
|
|
|
|
|
|
export function getChunks<T>(arr: readonly T[], size: number): T[][] {
|
|
const result: T[][] = [];
|
|
if (size <= 0) return result;
|
|
for (let i = 0; i < arr.length; i += size) {
|
|
result.push(arr.slice(i, i + size));
|
|
}
|
|
return result;
|
|
}
|
|
import.meta.vitest?.test("getChunks", ({ expect }) => {
|
|
expect(getChunks([], 2)).toEqual([]);
|
|
expect(getChunks([1], 2)).toEqual([[1]]);
|
|
expect(getChunks([1, 2], 2)).toEqual([[1, 2]]);
|
|
expect(getChunks([1, 2, 3], 2)).toEqual([[1, 2], [3]]);
|
|
expect(getChunks([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]]);
|
|
expect(getChunks([1, 2, 3, 4], 3)).toEqual([[1, 2, 3], [4]]);
|
|
expect(getChunks([1, 2, 3], 0)).toEqual([]);
|
|
expect(getChunks([1, 2, 3], -1)).toEqual([]);
|
|
});
|
|
|
|
export function isStringArray(arr: unknown): arr is string[] {
|
|
return Array.isArray(arr) && arr.every((item) => typeof item === "string");
|
|
}
|
|
export function isNumberArray(arr: unknown): arr is number[] {
|
|
return Array.isArray(arr) && arr.every((item) => typeof item === "number");
|
|
}
|
|
export function isBooleanArray(arr: unknown): arr is boolean[] {
|
|
return Array.isArray(arr) && arr.every((item) => typeof item === "boolean");
|
|
}
|
|
export function isObjectArray(arr: unknown): arr is object[] {
|
|
return Array.isArray(arr) && arr.every((item) => typeof item === "object" && item !== null);
|
|
}
|
|
import.meta.vitest?.test("is<Type>Array", ({ expect }) => {
|
|
expect(isStringArray([])).toBe(true);
|
|
expect(isNumberArray([1, 2, 3])).toBe(true);
|
|
expect(isBooleanArray([true, false, true])).toBe(true);
|
|
expect(isObjectArray([{ a: 1 }, { b: 2 }, { c: 3 }])).toBe(true);
|
|
expect(isStringArray([1, 2, 3])).toBe(false);
|
|
expect(isNumberArray(["a", "b", "c"])).toBe(false);
|
|
expect(isBooleanArray([1, 2, 3])).toBe(false);
|
|
expect(isObjectArray([1, 2, 3])).toBe(false);
|
|
expect(isObjectArray([{ a: 1 }, null, { b: 2 }])).toBe(false);
|
|
expect(isObjectArray([{ a: 1 }, undefined, { b: 2 }])).toBe(false);
|
|
});
|