@vllnt/convex-slugs 0.1.0 → 0.1.1-canary.1a8d6a3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,87 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format is based on
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
5
+ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.1.1] - Unreleased
8
+
9
+ ### Fixed
10
+
11
+ - `rename` no longer leaves a self-redirect when a slug is renamed back to an
12
+ earlier name (A→B, then B→A left `redirectFor(A) === A` on a live slug). A
13
+ redirect starting at the new live name is now removed.
14
+ - Reserved words are normalized like slugs, so `reservedWords: ["Admin"]` blocks
15
+ `admin` (previously never matched when `foldCase` was on).
16
+ - A `pattern` with the `g` or `y` flag gives the same verdict on every call
17
+ instead of alternating.
18
+ - `@vllnt/convex-slugs/test` type-checks for consumers under `nodenext` and
19
+ `bundler` resolution (`vite/client` reference, `.js` suffixes on relative
20
+ imports).
21
+ - Test files are no longer included in the published package.
22
+ - `register` from `@vllnt/convex-slugs/test` accepts a `convex-test` instance
23
+ built from the host app's schema, as the README shows; it used to require the
24
+ component's own schema type.
25
+
26
+ ### Added
27
+
28
+ - Invalid input is rejected with a `ConvexError`: `INVALID_OPTIONS` from
29
+ `new Slugs(...)` (empty `defaultScope`, `minLength`/`maxLength` that are not
30
+ integers or inverted, a negative `minLength`, or `maxLength < 1`), and
31
+ `INVALID_ARGUMENT` from component mutations (empty `scope`/`resourceRef`,
32
+ invalid `bounds`). A `NaN` `maxLength` used to disable the length cap.
33
+ - The npm package ships `docs/API.md`, `CHANGELOG.md` and `llms.txt`, so the
34
+ docs in `node_modules/@vllnt/convex-slugs/` match the installed version.
35
+ `llms.txt` links to the shipped files with relative paths. `docs/API.md` now
36
+ lists every entry point, the React hooks and the `register` test helper.
37
+
38
+ ### Changed
39
+
40
+ - Docs: README install command targets the stable release, "Testing your app",
41
+ error table, concurrency and normalization limits.
42
+ - Release flow: npm trusted publishing with provenance; `@latest` only from a
43
+ `vX.Y.Z` tag on `main`. Pinned CI actions, pnpm 10 with a release-age gate,
44
+ low-memory dev defaults.
45
+ - Release flow: every push to `main` that changes the package or its shipped
46
+ docs publishes a `canary`; `pnpm test:package` in CI fails when a required
47
+ file is missing from the packed tarball.
48
+ - `package.json` `homepage` points to
49
+ https://oss.vllnt.com/packages/convex-slugs.
50
+
51
+ ## [0.1.0] - 2026-09-01
52
+
53
+ ### Added
54
+
55
+ - First release of `@vllnt/convex-slugs`.
56
+
57
+ ### Hardened (in-place review fixes, 0.1.0)
58
+
59
+ - Configurable input rules on the client: `minLength` (1), `maxLength` (256),
60
+ `pattern?` (charset), and `reservedWords` ([]); empty/whitespace slugs are
61
+ rejected. The component re-guards length at the trust boundary.
62
+ - Typed rejection reasons as a string-literal union — `SLUG_TAKEN`,
63
+ `SLUG_NOT_FOUND`, `SLUG_INVALID`, `SLUG_RESERVED` — on both the Convex
64
+ validator and the client `SlugWriteResult`.
65
+ - Redirect chains collapse: `rename` repoints existing redirects to the live
66
+ slug (A→B→C ⇒ `redirectFor(A) === C`), keeping one row per `(scope, fromSlug)`
67
+ via a new `by_scope_to` index. Reserving a renamed-away slug clears its
68
+ dangling redirect.
69
+ - Registry reads use `.first()` instead of `.unique()` so a stray duplicate row
70
+ degrades to a value rather than throwing.
71
+
72
+ ### Changed
73
+
74
+ - Treat Convex `_generated` output as CLI-owned, exclude it from formatting, and
75
+ expose a dedicated codegen script.
76
+ - Require `convex@^1.45.0` and update `convex-test` to `^0.0.56`.
77
+
78
+ ### Fixed
79
+
80
+ - `release` deletes all `redirects` rows whose `toSlug` equals the released
81
+ slug, so `redirectFor(old)` returns `null` instead of a dead target after
82
+ release.
83
+ - `rename` rejects a self-rename (`fromSlug === toSlug`) with `SLUG_TAKEN`
84
+ before any DB read.
85
+ - `normalizeSlug` applies Unicode NFC before trimming, so visually-identical
86
+ slugs with different compositions collide as expected.
87
+ - `redirectFor` no longer carries a dead `.order("desc")` call.
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  <!-- Badges -->
2
+
2
3
  [![Convex Component](https://img.shields.io/badge/convex-component-EE342F.svg)](https://www.convex.dev/components)
3
4
  [![npm](https://img.shields.io/npm/v/@vllnt/convex-slugs.svg)](https://www.npmjs.com/package/@vllnt/convex-slugs)
4
5
  [![CI](https://github.com/vllnt/convex-slugs/actions/workflows/ci.yml/badge.svg)](https://github.com/vllnt/convex-slugs/actions/workflows/ci.yml)
@@ -15,20 +16,27 @@ const ref = await slugs.resolve(ctx, "ada"); // resourceRef | null
15
16
  ```
16
17
 
17
18
  Reserve a unique string (slug, `@handle`, username) against an opaque
18
- `resourceRef`, enforce uniqueness inside a scope, resolve it back, release it, and
19
- **redirect on rename**. Domain-neutral: article slugs, profile handles, workspace
20
- slugs — any public-URL key.
19
+ `resourceRef`, enforce uniqueness inside a scope, resolve it back, release it,
20
+ and **redirect on rename**. Domain-neutral: article slugs, profile handles,
21
+ workspace slugs — any public-URL key.
21
22
 
22
23
  ## Features
23
24
 
24
- - **Atomic uniqueness** per `(scope, slug)` — rides the Convex mutation transaction, no double-reserve.
25
+ - **Atomic uniqueness** per `(scope, slug)` — rides the Convex mutation
26
+ transaction, no double-reserve.
25
27
  - **Scopes** — global by default, or namespace per tenant / locale / type.
26
- - **Rename + redirects** — renaming records an old → new redirect for link preservation.
27
- - **Chain-safe redirects** — chains collapse (A→B→C ⇒ `redirectFor(A) === C`), one row per source.
28
+ - **Rename + redirects** — renaming records an old → new redirect for link
29
+ preservation.
30
+ - **Chain-safe redirects** — chains collapse (A→B→C ⇒ `redirectFor(A) === C`),
31
+ one row per source.
28
32
  - **Reverse lookup** — find the slug currently held by a `resourceRef`.
29
- - **Case folding + NFC** — case-insensitive (opt-out) and Unicode NFC-normalized to kill homoglyph collisions.
30
- - **Configurable input rules** — length bounds, charset `pattern`, `reservedWords`; typed rejection reasons.
31
- - **Degrades, never throws** — reads use `.first()`; release cleans up inbound redirects; opaque `resourceRef`.
33
+ - **Case folding + NFC** — case-insensitive (opt-out); NFC unifies canonically
34
+ equivalent Unicode spellings, not all look-alike characters.
35
+ - **Configurable input rules** — length bounds, charset `pattern`,
36
+ `reservedWords`; typed rejection reasons.
37
+ - **Typed write rejections** — expected conflicts return
38
+ `{ ok: false, reason }`; invalid configuration and Convex/runtime failures can
39
+ still throw.
32
40
 
33
41
  ## Installation
34
42
 
@@ -36,7 +44,16 @@ slugs — any public-URL key.
36
44
  pnpm add @vllnt/convex-slugs
37
45
  ```
38
46
 
39
- Peer dependency: `convex@^1.41.0` (optionally `react@>=18` for the `./react` hooks).
47
+ Requires `convex@^1.45.0`; React `>=18` is optional for `./react` only. The
48
+ command installs the stable release. Prereleases are published under the
49
+ `canary` tag (`@vllnt/convex-slugs@canary`); pin a resolved canary version for
50
+ reproducible installs.
51
+
52
+ ### For coding agents
53
+
54
+ The docs are bundled in the package at `node_modules/@vllnt/convex-slugs/docs/`,
55
+ next to `llms.txt`, `CHANGELOG.md`, `src/` and `dist/`. They match the installed
56
+ version. Read them before writing code against this package.
40
57
 
41
58
  ## Usage
42
59
 
@@ -60,55 +77,77 @@ import { Slugs } from "@vllnt/convex-slugs";
60
77
  const slugs = new Slugs(components.slugs);
61
78
 
62
79
  export const claim = mutation({
63
- args: { handle: v.string(), userId: v.string() },
64
- handler: (ctx, { handle, userId }) => slugs.reserve(ctx, handle, userId),
80
+ args: { handle: v.string() },
81
+ handler: async (ctx, { handle }) => {
82
+ const identity = await ctx.auth.getUserIdentity();
83
+ if (!identity) throw new Error("Unauthenticated");
84
+ return slugs.reserve(ctx, handle, identity.tokenIdentifier);
85
+ },
65
86
  });
66
87
 
67
88
  export const lookup = query({
68
- args: { handle: v.string() },
69
- handler: (ctx, { handle }) => slugs.resolve(ctx, handle),
89
+ args: { slug: v.string(), scope: v.optional(v.string()) },
90
+ handler: (ctx, { slug }) => slugs.resolve(ctx, slug, "global"),
70
91
  });
71
92
  ```
72
93
 
73
- Client options: `new Slugs(component, { defaultScope = "global", foldCase = true, minLength = 1, maxLength = 256, pattern?, reservedWords = [] })`.
94
+ Client defaults: `defaultScope: "global"`, `foldCase: true`, `minLength: 1`,
95
+ `maxLength: 256`, `reservedWords: []`; `pattern` is optional. Configure these in
96
+ `new Slugs(component, options)`; see [the API reference](docs/API.md).
74
97
 
75
98
  ## API Reference
76
99
 
77
- | Method | Kind | Result |
78
- |--------|------|--------|
79
- | `reserve(ctx, slug, resourceRef, scope?)` | mutation | `{ ok: true }` or `{ ok: false, reason }` (`SLUG_INVALID` \| `SLUG_RESERVED` \| `SLUG_TAKEN`) |
80
- | `release(ctx, slug, scope?)` | mutation | `null` (idempotent) |
81
- | `rename(ctx, fromSlug, toSlug, scope?)` | mutation | `{ ok }` (`SLUG_INVALID` \| `SLUG_NOT_FOUND` \| `SLUG_TAKEN`) |
82
- | `resolve(ctx, slug, scope?)` | query | `resourceRef \| null` |
83
- | `redirectFor(ctx, slug, scope?)` | query | `toSlug \| null` |
84
- | `slugForResource(ctx, resourceRef, scope?)` | query | `slug \| null` |
100
+ | Method | Kind | Result |
101
+ | ------------------------------------------- | -------- | --------------------------------------------------------------------------------------------- |
102
+ | `reserve(ctx, slug, resourceRef, scope?)` | mutation | `{ ok: true }` or `{ ok: false, reason }` (`SLUG_INVALID` \| `SLUG_RESERVED` \| `SLUG_TAKEN`) |
103
+ | `release(ctx, slug, scope?)` | mutation | `null` (idempotent) |
104
+ | `rename(ctx, fromSlug, toSlug, scope?)` | mutation | `{ ok }` (`SLUG_INVALID` \| `SLUG_RESERVED` \| `SLUG_NOT_FOUND` \| `SLUG_TAKEN`) |
105
+ | `resolve(ctx, slug, scope?)` | query | `resourceRef \| null` |
106
+ | `redirectFor(ctx, slug, scope?)` | query | `toSlug \| null` |
107
+ | `slugForResource(ctx, resourceRef, scope?)` | query | `slug \| null` |
85
108
 
86
109
  Full reference: [docs/API.md](docs/API.md).
87
110
 
88
111
  ## React
89
112
 
90
- Optional, tree-shakeable hooks from `@vllnt/convex-slugs/react` — thin wrappers over
91
- `useQuery`; `react` is an optional peer dep. Each takes the host's re-exported
92
- `resolve` query reference.
113
+ Optional, tree-shakeable hooks from `@vllnt/convex-slugs/react` — thin wrappers
114
+ over `useQuery`; `react` is an optional peer dep. Each takes the host's
115
+ re-exported `resolve` query reference.
93
116
 
94
117
  ```tsx
95
118
  import { useSlugAvailable } from "@vllnt/convex-slugs/react";
96
119
  import { api } from "../convex/_generated/api";
97
120
 
98
121
  // `available` is undefined while loading, true when free, false when held.
99
- const { available, resourceRef } = useSlugAvailable(api.handles.resolveHandle, { slug });
122
+ const { available, resourceRef } = useSlugAvailable(api.handles.lookup, {
123
+ slug,
124
+ });
100
125
  ```
101
126
 
102
- | Hook | Returns |
103
- |------|---------|
127
+ | Hook | Returns |
128
+ | ------------------------------------------------ | ----------------------------------------------------------------------------------------------- |
104
129
  | `useSlugAvailable(resolveRef, { slug, scope? })` | `{ available, resourceRef }` — `available` `undefined` while loading, `true` free, `false` held |
105
- | `useResolve(resolveRef, { slug, scope? })` | `resourceRef \| null \| undefined` (`undefined` while loading) |
130
+ | `useResolve(resolveRef, { slug, scope? })` | `resourceRef \| null \| undefined` (`undefined` while loading) |
131
+
132
+ Availability is a lookup hint, not a reservation or validation of length,
133
+ pattern, or reserved words. A concurrent claim can win; always check `reserve`'s
134
+ result. The example intentionally exposes public handles in the global scope
135
+ only.
106
136
 
107
137
  ## Security
108
138
 
109
- - **Auth-agnostic** — the host authenticates the caller, decides who may claim a handle, and passes an opaque `resourceRef`.
110
- - **Opaque refs only** — `resourceRef` and `scope` are arbitrary strings; tables are sandboxed (reached only via the client).
111
- - **Boundary re-guard** — the component re-guards length at the trust boundary even if a caller bypasses the client.
139
+ - **Auth-agnostic** — the host authenticates the caller, decides who may claim a
140
+ handle, and passes an opaque `resourceRef`.
141
+ - **Management authorization** — before `release` or `rename`, verify ownership
142
+ in the host. Authentication alone does not authorize changing another
143
+ subject's slug.
144
+ - **Opaque refs only** — `resourceRef` and `scope` are arbitrary strings; tables
145
+ are sandboxed (reached only via the client).
146
+ - **Boundary re-guard** — the component re-guards length at the trust boundary
147
+ even if a caller bypasses the client.
148
+ - **Uniqueness under concurrency** — each `reserve`/`rename` is one Convex
149
+ mutation (serializable): of simultaneous claims on a slug, one succeeds and
150
+ the rest get `SLUG_TAKEN`.
112
151
 
113
152
  See [docs/API.md](docs/API.md).
114
153
 
@@ -119,20 +158,48 @@ pnpm test # single run
119
158
  pnpm test:coverage # enforced 100% on covered files
120
159
  ```
121
160
 
122
- Tests run against the real component runtime via `convex-test` (`@edge-runtime/vm`), not mocks.
161
+ Tests run against the real component runtime via `convex-test`
162
+ (`@edge-runtime/vm`), not mocks.
163
+
164
+ ### Testing your app
165
+
166
+ `@vllnt/convex-slugs/test` exports `register(t, name = "slugs")` to mount the
167
+ component in a `convex-test` instance. It needs `convex-test` and `vitest` (with
168
+ Vite's `import.meta.glob`) in the consuming app:
169
+
170
+ ```ts
171
+ /// <reference types="vite/client" />
172
+ import { convexTest } from "convex-test";
173
+ import { register } from "@vllnt/convex-slugs/test";
174
+ import schema from "./schema";
175
+
176
+ const t = convexTest(schema, import.meta.glob("./**/*.ts"));
177
+ register(t);
178
+ ```
179
+
180
+ ## Related packages
181
+
182
+ - [`@vllnt/convex-tokens`](https://www.npmjs.com/package/@vllnt/convex-tokens) —
183
+ use it when the key must stay secret (share links, magic links): tokens are
184
+ hashed, expire and can be revoked. A slug is a public, readable name that
185
+ anyone can resolve.
123
186
 
124
187
  ## Contributing
125
188
 
126
- See [CONTRIBUTING.md](CONTRIBUTING.md).
189
+ See
190
+ [CONTRIBUTING.md](https://github.com/vllnt/convex-slugs/blob/main/CONTRIBUTING.md).
127
191
 
128
192
  ## Author
129
193
 
130
- Built by [bntvllnt](https://github.com/bntvllnt) · [bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
131
-
132
- Part of the [@vllnt](https://github.com/vllnt) Convex component fleet — [vllnt.com](https://vllnt.com)
194
+ Built by [bntvllnt](https://github.com/bntvllnt) ·
195
+ [bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
133
196
 
134
197
  If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
135
198
 
136
199
  ## License
137
200
 
138
201
  MIT — see [LICENSE](LICENSE).
202
+
203
+ ---
204
+
205
+ Part of vllnt oss: https://oss.vllnt.com
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAUhE,wEAAwE;AACxE,UAAU,YAAY;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE;QACT,OAAO,EAAE,iBAAiB,CACxB,UAAU,EACV,UAAU,EACV;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,WAAW,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,YAAY,CAAA;SAAE,EAC1E,eAAe,CAChB,CAAC;QACF,OAAO,EAAE,iBAAiB,CACxB,UAAU,EACV,UAAU,EACV;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,EAC/B,IAAI,CACL,CAAC;QACF,MAAM,EAAE,iBAAiB,CACvB,UAAU,EACV,UAAU,EACV;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,YAAY,CAAA;SAAE,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,MAAM,GACb,OAAO,CAAC,eAAe,CAAC,CAY1B;IAED,sDAAsD;IACtD,OAAO,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAK9E;IAED,+DAA+D;IAC/D,WAAW,CACT,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAKxB;IAED,2DAA2D;IAC3D,eAAe,CACb,GAAG,EAAE,WAAW,EAChB,WAAW,EAAE,MAAM,EACnB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAKxB;CACF;AAED,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { ConvexError } from "convex/values";
1
2
  import { DEFAULT_MAX_LENGTH, DEFAULT_MIN_LENGTH, DEFAULT_SCOPE, normalizeSlug, validateSlug, } from "../shared.js";
2
3
  /**
3
4
  * Consumer-facing client for the unique slug / handle registry. The host owns
@@ -16,11 +17,24 @@ export class Slugs {
16
17
  this.component = component;
17
18
  this.defaultScope = options.defaultScope ?? DEFAULT_SCOPE;
18
19
  this.foldCase = options.foldCase ?? true;
20
+ const minLength = options.minLength ?? DEFAULT_MIN_LENGTH;
21
+ const maxLength = options.maxLength ?? DEFAULT_MAX_LENGTH;
22
+ if (this.defaultScope === "" ||
23
+ !Number.isInteger(minLength) ||
24
+ !Number.isInteger(maxLength) ||
25
+ minLength < 0 ||
26
+ maxLength < Math.max(1, minLength)) {
27
+ throw new ConvexError({
28
+ code: "INVALID_OPTIONS",
29
+ message: "Slugs options: defaultScope must be non-empty; minLength and maxLength must be integers with 0 <= minLength <= maxLength and maxLength >= 1",
30
+ });
31
+ }
19
32
  this.constraints = {
20
- minLength: options.minLength ?? DEFAULT_MIN_LENGTH,
21
- maxLength: options.maxLength ?? DEFAULT_MAX_LENGTH,
33
+ minLength,
34
+ maxLength,
22
35
  pattern: options.pattern,
23
- reservedWords: options.reservedWords ?? [],
36
+ // Match reserved words on the same normalized form as slugs.
37
+ reservedWords: (options.reservedWords ?? []).map((w) => this.norm(w)),
24
38
  };
25
39
  }
26
40
  norm(slug) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,YAAY,GACb,MAAM,cAAc,CAAC;AAsEtB;;;;;;;GAOG;AACH,MAAM,OAAO,KAAK;IAMG,SAAS;IALX,YAAY,CAAS;IACrB,QAAQ,CAAU;IAClB,WAAW,CAAkB;IAE9C,YACmB,SAAyB,EAC1C,OAAO,GAAiB,EAAE;yBADT,SAAS;QAG1B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,aAAa,CAAC;QAC1D,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC;QACzC,IAAI,CAAC,WAAW,GAAG;YACjB,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,kBAAkB;YAClD,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,kBAAkB;YAClD,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,EAAE;SAC3C,CAAC;IACJ,CAAC;IAEO,IAAI,CAAC,IAAY;QACvB,OAAO,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAEO,OAAO,CAAC,KAAyB;QACvC,OAAO,KAAK,IAAI,IAAI,CAAC,YAAY,CAAC;IACpC,CAAC;IAED,IAAY,MAAM;QAChB,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS;YACrC,SAAS,EA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C3D,eAAe,CACb,GAAgB,EAChB,WAAmB,EACnB,KAAc;QAEd,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,eAAe,EAAE;YAC1D,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAC1B,WAAW;SACZ,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -45,6 +45,9 @@ export declare const release: import("convex/server").RegisteredMutation<"public
45
45
  * chain A→B→C collapses to A→C), and a single redirect row per `(scope,
46
46
  * fromSlug)` is upserted (patched if present, else inserted) to bound growth.
47
47
  *
48
+ * Any redirect leaving `toSlug` is removed (it is a live name again), so no
49
+ * redirect ever starts at a live slug.
50
+ *
48
51
  * Self-rename (`fromSlug === toSlug`) is rejected with `SLUG_TAKEN` before any
49
52
  * DB read, preventing a self-loop redirect from being created.
50
53
  *
@@ -1 +1 @@
1
- {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;YAUc,cAAc;;;YAYd,YAAY;;;;GAkB5C,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO;;;iBAwBlB,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;YAUe,YAAY;;;YAGZ,cAAc;;;YAYd,gBAAgB;;;;GAwChD,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS;;;;iBAWpB,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;;;;iBAW5B,CAAC"}
1
+ {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AA8BA;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;YAWc,cAAc;;;YAYd,YAAY;;;;GAkB5C,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO;;;iBAyBlB,CAAC;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;YAWe,YAAY;;;YAGZ,cAAc;;;YAYd,gBAAgB;;;;GAoDhD,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS;;;;iBAWpB,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;;;;iBAW5B,CAAC"}
@@ -1,6 +1,24 @@
1
- import { v } from "convex/values";
2
- import { internalMutation, mutation } from "./_generated/server";
3
- import { lengthBounds, reserveResult } from "./validators";
1
+ import { ConvexError, v } from "convex/values";
2
+ import { internalMutation, mutation } from "./_generated/server.js";
3
+ import { lengthBounds, reserveResult } from "./validators.js";
4
+ /**
5
+ * Reject malformed arguments with `ConvexError({ code: "INVALID_ARGUMENT" })`.
6
+ * Expected slug rejections stay typed `{ ok: false, reason }` results; this
7
+ * covers input no correct client sends (empty scope/ref, non-integer bounds).
8
+ */
9
+ function assertArgs(args) {
10
+ const { scope, resourceRef, bounds } = args;
11
+ const badBounds = bounds !== undefined &&
12
+ !(Number.isInteger(bounds.minLength) &&
13
+ Number.isInteger(bounds.maxLength) &&
14
+ bounds.minLength <= bounds.maxLength);
15
+ if (scope === "" || resourceRef === "" || badBounds) {
16
+ throw new ConvexError({
17
+ code: "INVALID_ARGUMENT",
18
+ message: "scope and resourceRef must be non-empty; bounds must be integers with min <= max",
19
+ });
20
+ }
21
+ }
4
22
  /**
5
23
  * Reserve `slug` for `resourceRef` within `scope`. The slug arrives already
6
24
  * normalized by the client; `bounds` re-guards empty/oversized input at the
@@ -19,6 +37,7 @@ export const reserve = mutation({
19
37
  },
20
38
  returns: reserveResult,
21
39
  handler: async (ctx, args) => {
40
+ assertArgs(args);
22
41
  if (args.slug.length < Math.max(1, args.bounds.minLength)) {
23
42
  return { ok: false, reason: "SLUG_INVALID" };
24
43
  }
@@ -60,6 +79,7 @@ export const release = mutation({
60
79
  args: { scope: v.string(), slug: v.string() },
61
80
  returns: v.null(),
62
81
  handler: async (ctx, args) => {
82
+ assertArgs(args);
63
83
  const existing = await ctx.db
64
84
  .query("slugs")
65
85
  .withIndex("by_scope_slug", (q) => q.eq("scope", args.scope).eq("slug", args.slug))
@@ -84,6 +104,9 @@ export const release = mutation({
84
104
  * chain A→B→C collapses to A→C), and a single redirect row per `(scope,
85
105
  * fromSlug)` is upserted (patched if present, else inserted) to bound growth.
86
106
  *
107
+ * Any redirect leaving `toSlug` is removed (it is a live name again), so no
108
+ * redirect ever starts at a live slug.
109
+ *
87
110
  * Self-rename (`fromSlug === toSlug`) is rejected with `SLUG_TAKEN` before any
88
111
  * DB read, preventing a self-loop redirect from being created.
89
112
  *
@@ -100,6 +123,7 @@ export const rename = mutation({
100
123
  },
101
124
  returns: reserveResult,
102
125
  handler: async (ctx, args) => {
126
+ assertArgs(args);
103
127
  if (args.fromSlug === args.toSlug) {
104
128
  return { ok: false, reason: "SLUG_TAKEN" };
105
129
  }
@@ -124,6 +148,15 @@ export const rename = mutation({
124
148
  return { ok: false, reason: "SLUG_TAKEN" };
125
149
  }
126
150
  await ctx.db.patch("slugs", from._id, { slug: args.toSlug });
151
+ // `toSlug` is a live name again: drop its own redirect first, so renaming
152
+ // back (A->B, B->A) cannot repoint it into a self-loop A->A below.
153
+ const stale = await ctx.db
154
+ .query("redirects")
155
+ .withIndex("by_scope_from", (q) => q.eq("scope", args.scope).eq("fromSlug", args.toSlug))
156
+ .collect();
157
+ for (const row of stale) {
158
+ await ctx.db.delete("redirects", row._id);
159
+ }
127
160
  const inbound = await ctx.db
128
161
  .query("redirects")
129
162
  .withIndex("by_scope_to", (q) => q.eq("scope", args.scope).eq("toSlug", args.fromSlug))
@@ -1 +1 @@
1
- {"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,gB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Query, query } from "./_generated/server";
2
+ import { internalQuery, query } from "./_generated/server.js";
3
3
  /**
4
4
  * Resolve `slug` to the `resourceRef` currently holding it within `scope`, or
5
5
  * `null`. Uses `.first()` so a stray duplicate row degrades to one answer
@@ -1 +1 @@
1
- {"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE3D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,CAAC;IAC3B,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE;IAC7C,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;IACtC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,EAAE;aACrB,KAAK,CAAC,OAAO,CAAC;aACd,SAAS,CAAC,eAAe,EAAE,CAAC,CAAC,EAAE,EAAE,CAChC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAChD;aACA,KAAK,EAAE,CAAC;QACX,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC;IAC/C,CAAC;CACF,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC;IAC/B,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC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Ae;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACtC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,CAGrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,eAAe,GAAG,UAAU,GAAG,IAAI,CAmBhF"}
package/dist/shared.js CHANGED
@@ -41,6 +41,11 @@ export function validateSlug(slug, c) {
41
41
  if (slug.length > c.maxLength) {
42
42
  return "SLUG_INVALID";
43
43
  }
44
+ if (c.pattern !== undefined) {
45
+ // A global/sticky RegExp keeps `lastIndex` between calls; reset it so the
46
+ // same slug always gets the same verdict.
47
+ c.pattern.lastIndex = 0;
48
+ }
44
49
  if (c.pattern !== undefined && !c.pattern.test(slug)) {
45
50
  return "SLUG_INVALID";
46
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAEjF,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AAEtC,6DAA6D;AAC7D,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC;AAEtC,yDAAyD;AACzD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAEpC,yDAAyD;AACzD,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAuBtC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,QAAiB;IAC3D,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IAChD,OAAO,QAAQ,CAAC,CAAC,CAAC,UAAU,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C,CAAC,UAAU,CAAC;AAC1D,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,CAAkB;IAC3D,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC;QAC3C,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC;QAC9B,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,IAAI,CAAC,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAC5B,0EAA0E;QAC1E,0CAA0C;QAC1C,CAAC,CAAC,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC;IAC1B,CAAC;IACD,IAAI,CAAC,CAAC,OAAO,KAAK,SAAS,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACrD,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,IAAI,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,OAAO,eAAe,CAAC;IACzB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
package/docs/API.md ADDED
@@ -0,0 +1,151 @@
1
+ # API Reference — @vllnt/convex-slugs
2
+
3
+ **Compatibility:** `convex@^1.45.0`; optional `react@>=18` for `./react`.
4
+
5
+ ## Entry points
6
+
7
+ | Import | Exports |
8
+ | ------------------------------------------ | ------------------------------------------------------------------------ |
9
+ | `@vllnt/convex-slugs` | `Slugs` class; types `SlugsComponent`, `SlugsOptions`, `SlugWriteResult` |
10
+ | `@vllnt/convex-slugs/convex.config` | Component definition (default export) for `app.use(...)` |
11
+ | `@vllnt/convex-slugs/react` | `useSlugAvailable`, `useResolve` (see [React hooks](#react-hooks)) |
12
+ | `@vllnt/convex-slugs/test` | `register(t, name?)` (see [Testing helper](#testing-helper)) |
13
+ | `@vllnt/convex-slugs/_generated/component` | Type `ComponentApi` of the mounted component |
14
+
15
+ `SlugWriteResult` is
16
+ `{ ok: boolean; reason?: "SLUG_TAKEN" | "SLUG_NOT_FOUND" | "SLUG_INVALID" | "SLUG_RESERVED" }`.
17
+ `./convex.config.js` and `./_generated/component.js` are `.js`-suffixed aliases
18
+ of the same entry points. `SlugsComponent` is the shape of `components.slugs`
19
+ that `new Slugs(...)` accepts.
20
+
21
+ Construct the client with the mounted component and optional config:
22
+
23
+ ```ts
24
+ import { Slugs } from "@vllnt/convex-slugs";
25
+ const slugs = new Slugs(components.slugs, {
26
+ defaultScope: "global", // namespace applied when a call omits `scope`
27
+ foldCase: true, // lowercase slugs before store/lookup
28
+ minLength: 1, // reject shorter (after normalization) as SLUG_INVALID
29
+ maxLength: 256, // reject longer as SLUG_INVALID
30
+ pattern: /^[a-z0-9-]+$/, // optional charset; failing it is SLUG_INVALID
31
+ reservedWords: ["admin"], // reject these (normalized) as SLUG_RESERVED
32
+ });
33
+ ```
34
+
35
+ All methods take the host `ctx` (a query or mutation context) as the first
36
+ argument. `scope` is optional and defaults to `defaultScope`.
37
+
38
+ **Normalization pipeline:** raw slug → `String.prototype.normalize("NFC")` →
39
+ `.trim()` → optional `.toLowerCase()` (when `foldCase: true`). This ensures
40
+ visually-identical slugs with different Unicode compositions (e.g. precomposed
41
+ vs. combining-character forms) are treated as the same string.
42
+
43
+ Limits to know: `minLength`/`maxLength` count UTF-16 code units (an emoji is 2),
44
+ and there is no compatibility folding (NFKC), confusable detection, or
45
+ zero-width-character stripping. Use `pattern` (for example `/^[a-z0-9-]+$/`) to
46
+ restrict the alphabet. Reserved words are normalized the same way as slugs, so
47
+ `reservedWords: ["Admin"]` blocks `admin`.
48
+
49
+ ## Validation reasons
50
+
51
+ Expected validation and conflict rejections return `{ ok: false, reason }`. This
52
+ does not cover every failure: invalid regular-expression configuration, Convex
53
+ validation, authorization in host wrappers, and runtime failures can throw.
54
+ `reason` is a typed string-literal union:
55
+
56
+ | Reason | When |
57
+ | ---------------- | ----------------------------------------------------------------------- |
58
+ | `SLUG_INVALID` | Empty/whitespace, outside `minLength`..`maxLength`, or fails `pattern`. |
59
+ | `SLUG_RESERVED` | The normalized slug is in `reservedWords`. |
60
+ | `SLUG_TAKEN` | The slug is already held in the scope. |
61
+ | `SLUG_NOT_FOUND` | `rename` was called for a `fromSlug` that is not held. |
62
+
63
+ Validation runs in the client against the resolved options before any
64
+ round-trip; the component re-guards length at the trust boundary even if a
65
+ caller bypasses the client.
66
+
67
+ ## Errors
68
+
69
+ Malformed input throws a `ConvexError` whose `data.code` is stable:
70
+
71
+ | Code | Thrown by | When |
72
+ | ------------------ | ------------------- | ---------------------------------------------------------------------------------------------------------------------- |
73
+ | `INVALID_OPTIONS` | `new Slugs(...)` | Empty `defaultScope`, or `minLength`/`maxLength` not integers with `0 <= minLength <= maxLength` and `maxLength >= 1`. |
74
+ | `INVALID_ARGUMENT` | component mutations | Empty `scope` or `resourceRef`, or `bounds` that are not integers with `minLength <= maxLength`. |
75
+
76
+ ## Concurrency
77
+
78
+ `reserve` and `rename` each run as one Convex mutation, which is serializable.
79
+ When several callers claim the same slug at once, exactly one succeeds and the
80
+ others receive `SLUG_TAKEN`. Convex indexes are not unique constraints, so
81
+ always claim through these mutations.
82
+
83
+ ## Mutations
84
+
85
+ ### `reserve(ctx, slug, resourceRef, scope?) → { ok, reason? }`
86
+
87
+ Reserve `slug` for `resourceRef`. Returns `{ ok: true }` on success, or
88
+ `{ ok: false, reason }` with `SLUG_INVALID`, `SLUG_RESERVED`, or `SLUG_TAKEN`.
89
+ Reserving a slug that was previously renamed away clears its now-dangling
90
+ redirect (the slug is a live name again).
91
+
92
+ ### `release(ctx, slug, scope?) → null`
93
+
94
+ Release `slug`. Idempotent — releasing an unheld slug is a no-op. Also deletes
95
+ all `redirects` rows whose `toSlug` equals the released slug, so
96
+ `redirectFor(old)` returns `null` after release instead of pointing at a dead
97
+ target.
98
+
99
+ ### `rename(ctx, fromSlug, toSlug, scope?) → { ok, reason? }`
100
+
101
+ Move `fromSlug` to `toSlug` and record an old → new redirect. Returns
102
+ `SLUG_INVALID` (bad `toSlug`), `SLUG_RESERVED` (reserved `toSlug`),
103
+ `SLUG_NOT_FOUND` (`fromSlug` not held), or `SLUG_TAKEN` (`toSlug` already held
104
+ or equals `fromSlug`). Self-rename (`fromSlug === toSlug`) is rejected with
105
+ `SLUG_TAKEN` before any DB read. Existing redirects that pointed at `fromSlug`
106
+ are repointed to `toSlug`, so a chain A→B→C collapses to A→C; at most one
107
+ redirect row is kept per `(scope, fromSlug)`. Renaming back to an earlier name
108
+ (A→B, then B→A) removes the redirect that left A, so a live slug never has a
109
+ redirect and redirects never loop.
110
+
111
+ ## Queries
112
+
113
+ ### `resolve(ctx, slug, scope?) → resourceRef | null`
114
+
115
+ The `resourceRef` currently holding `slug`, or `null`.
116
+
117
+ ### `redirectFor(ctx, slug, scope?) → toSlug | null`
118
+
119
+ If `slug` was renamed away, the live slug it now points to (chains collapsed);
120
+ otherwise `null`.
121
+
122
+ ### `slugForResource(ctx, resourceRef, scope?) → slug | null`
123
+
124
+ The slug currently held by `resourceRef`, or `null`. Assumes one slug per
125
+ `(scope, resourceRef)` (the host reserves at most one).
126
+
127
+ ## React hooks
128
+
129
+ `@vllnt/convex-slugs/react` wraps `useQuery` from `convex/react`. Each hook
130
+ takes the host's own public query that forwards `{ slug, scope? }` to
131
+ `slugs.resolve` and returns `string | null`; the component's internal queries
132
+ cannot be called from a browser.
133
+
134
+ ### `useSlugAvailable(resolveRef, { slug, scope? }) → { available, resourceRef }`
135
+
136
+ `available` is `undefined` while loading, `true` when the slug is free, and
137
+ `false` when held. `resourceRef` is the holder, or `null` when free or loading.
138
+ Availability is a lookup hint: it does not check length, `pattern` or reserved
139
+ words, and a concurrent claim can still win, so always check `reserve`'s result.
140
+
141
+ ### `useResolve(resolveRef, { slug, scope? }) → resourceRef | null | undefined`
142
+
143
+ The holding `resourceRef`, `null` when free, or `undefined` while loading.
144
+
145
+ ## Testing helper
146
+
147
+ ### `register(t, name = "slugs") → void`
148
+
149
+ From `@vllnt/convex-slugs/test`. Mounts the component in a `convex-test`
150
+ instance under `name`. The helper ships as TypeScript source and uses Vite's
151
+ `import.meta.glob`, so the consuming tests need `convex-test` and `vitest`.
package/llms.txt ADDED
@@ -0,0 +1,31 @@
1
+ # @vllnt/convex-slugs
2
+
3
+ > Unique slug and handle registry with rename redirects, as a Convex component
4
+
5
+ `@vllnt/convex-slugs` is a publishable Convex component. It targets `convex@^1.45.0`.
6
+ It stores two sandboxed tables - `slugs` (unique per `(scope, slug)`, mapping to an opaque `resourceRef`) and `redirects` (old to new on rename). Uniqueness rides the Convex mutation transaction. The host owns the resource, auth, and meaning; the component owns only the uniqueness + redirect state. Slugs are case-folded by default.
7
+
8
+ For coding agents: the docs are bundled in the package at `node_modules/@vllnt/convex-slugs/docs/` and match the installed version. Read them before writing code. `README.md`, `CHANGELOG.md` and this file sit at the package root; `src/` and `dist/` hold the source and type declarations of the same version.
9
+
10
+ ## Docs
11
+
12
+ - [README](./README.md): Project overview, installation, usage examples
13
+ - [API Reference](./docs/API.md): Public exports, class methods, return shapes, input validation
14
+ - [Changelog](./CHANGELOG.md): Version history and release notes
15
+ - [Contributing](https://github.com/vllnt/convex-slugs/blob/main/CONTRIBUTING.md): Development setup, validation commands, release workflow
16
+
17
+ ## Examples
18
+
19
+ - [Example component wrapper](https://github.com/vllnt/convex-slugs/blob/main/example/convex/example.ts): Host-app wrapper functions
20
+ - [Example tests](https://github.com/vllnt/convex-slugs/blob/main/example/convex/example.test.ts): End-to-end usage coverage with `convex-test`
21
+
22
+ ## Ecosystem
23
+
24
+ - [vllnt oss](https://oss.vllnt.com/llms.txt): Index of vllnt open-source packages
25
+
26
+ ## Optional
27
+
28
+ - [AGENTS](https://github.com/vllnt/convex-slugs/blob/main/AGENTS.md): Agent instructions for contributors to this repository
29
+ - [Security Policy](https://github.com/vllnt/convex-slugs/blob/main/SECURITY.md): Vulnerability reporting policy
30
+ - [Code of Conduct](https://github.com/vllnt/convex-slugs/blob/main/CODE_OF_CONDUCT.md): Community participation guidelines
31
+ - [License](./LICENSE): MIT license
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "@vllnt/convex-slugs",
3
- "version": "0.1.0",
3
+ "version": "0.1.1-canary.1a8d6a3",
4
4
  "description": "Unique slug and handle registry with rename redirects, as a Convex component",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "packageManager": "pnpm@9.15.4",
7
+ "packageManager": "pnpm@10.34.8",
8
8
  "files": [
9
9
  "dist",
10
- "src"
10
+ "src",
11
+ "docs/API.md",
12
+ "CHANGELOG.md",
13
+ "llms.txt",
14
+ "!src/**/*.test.*",
15
+ "!src/**/*.spec.*"
11
16
  ],
12
17
  "exports": {
13
18
  "./package.json": "./package.json",
@@ -41,17 +46,15 @@
41
46
  "build": "tsc --project ./tsconfig.build.json",
42
47
  "build:codegen": "pnpm codegen && pnpm build",
43
48
  "build:clean": "rm -rf dist *.tsbuildinfo && pnpm build:codegen",
44
- "typecheck": "tsc --noEmit",
45
- "typecheck:ci": "tsc --noEmit --project tsconfig.ci.json",
46
- "lint": "pnpm check:agents && eslint .",
49
+ "typecheck": "tsc --noEmit --incremental --tsBuildInfoFile node_modules/.cache/tsc/typecheck.tsbuildinfo",
50
+ "typecheck:ci": "tsc --noEmit --incremental --tsBuildInfoFile node_modules/.cache/tsc/typecheck-ci.tsbuildinfo --project tsconfig.ci.json",
51
+ "lint": "pnpm check:agents && eslint --cache --cache-location node_modules/.cache/eslint/ .",
47
52
  "test": "vitest run --passWithNoTests",
48
53
  "test:watch": "vitest --typecheck --clearScreen false",
49
54
  "test:coverage": "vitest run --coverage --coverage.reporter=text",
50
55
  "generate:llms": "node scripts/generate-llms.mjs",
56
+ "test:package": "node scripts/test-package.mjs",
51
57
  "preversion": "pnpm install --frozen-lockfile && pnpm build && pnpm test:coverage && pnpm typecheck && pnpm generate:llms",
52
- "prepublishOnly": "npm whoami || npm login",
53
- "alpha": "npm version prerelease --preid alpha && npm publish --tag alpha && git push --follow-tags",
54
- "release": "npm version patch && npm publish && git push --follow-tags",
55
58
  "check:agents": "node -e \"const f=require('node:fs');if(!f.existsSync('AGENTS.md')||f.existsSync('CLAUDE.md')||f.existsSync('.claude'))process.exit(1)\"",
56
59
  "codegen": "pnpm convex codegen --component-dir ./src/component"
57
60
  },
@@ -62,24 +65,24 @@
62
65
  "devDependencies": {
63
66
  "@edge-runtime/vm": "^5.0.0",
64
67
  "@testing-library/react": "^16.3.3",
65
- "@types/react": "^19.2.18",
66
- "@types/react-dom": "^19.2.5",
68
+ "@types/react": "^19.3.0",
69
+ "@types/react-dom": "^19.3.0",
67
70
  "@typescript/native": "npm:typescript@7.0.2",
68
- "@vitest/coverage-v8": "^4.1.11",
69
- "@vllnt/eslint-config": "2.0.0",
71
+ "@vitest/coverage-v8": "^5.1.0",
72
+ "@vllnt/eslint-config": "2.1.0",
70
73
  "@vllnt/typescript": "2.0.0",
71
- "convex": "^1.45.0",
72
- "convex-test": "^0.0.56",
74
+ "convex": "^1.50.0",
75
+ "convex-test": "^0.0.71",
73
76
  "eslint": "^9.39.5",
74
- "jsdom": "^29.1.1",
75
- "prettier": "^3.9.6",
76
- "react": "^19.2.8",
77
- "react-dom": "^19.2.8",
77
+ "jsdom": "^30.1.3",
78
+ "prettier": "^3.10.1",
79
+ "react": "^19.3.1",
80
+ "react-dom": "^19.3.1",
78
81
  "typescript": "npm:@typescript/typescript6@^6.0.2",
79
- "vite": "^8.2.2",
80
- "vitest": "^4.1.11"
82
+ "vite": "^8.3.8",
83
+ "vitest": "^5.1.0"
81
84
  },
82
- "homepage": "https://github.com/vllnt/convex-slugs#readme",
85
+ "homepage": "https://oss.vllnt.com/packages/convex-slugs",
83
86
  "bugs": {
84
87
  "url": "https://github.com/vllnt/convex-slugs/issues"
85
88
  },
@@ -105,11 +108,29 @@
105
108
  "keywords": [
106
109
  "convex",
107
110
  "convex-component",
108
- "slugs"
111
+ "slugs",
112
+ "slug",
113
+ "handle",
114
+ "username",
115
+ "redirect"
109
116
  ],
110
117
  "peerDependenciesMeta": {
111
118
  "react": {
112
119
  "optional": true
113
120
  }
121
+ },
122
+ "pnpm": {
123
+ "overrides": {
124
+ "minimatch@>=7.0.0 <11.0.1": "11.0.5",
125
+ "deepmerge-ts@<8.0.0": "^8.0.0",
126
+ "handlebars@<4.7.10": "^4.7.10"
127
+ },
128
+ "minimumReleaseAge": 10080,
129
+ "minimumReleaseAgeExclude": [
130
+ "@vllnt/*"
131
+ ],
132
+ "ignoredBuiltDependencies": [
133
+ "esbuild"
134
+ ]
114
135
  }
115
136
  }
@@ -1,3 +1,4 @@
1
+ import { ConvexError } from "convex/values";
1
2
  import type {
2
3
  FunctionArgs,
3
4
  FunctionReference,
@@ -99,11 +100,27 @@ export class Slugs {
99
100
  ) {
100
101
  this.defaultScope = options.defaultScope ?? DEFAULT_SCOPE;
101
102
  this.foldCase = options.foldCase ?? true;
103
+ const minLength = options.minLength ?? DEFAULT_MIN_LENGTH;
104
+ const maxLength = options.maxLength ?? DEFAULT_MAX_LENGTH;
105
+ if (
106
+ this.defaultScope === "" ||
107
+ !Number.isInteger(minLength) ||
108
+ !Number.isInteger(maxLength) ||
109
+ minLength < 0 ||
110
+ maxLength < Math.max(1, minLength)
111
+ ) {
112
+ throw new ConvexError({
113
+ code: "INVALID_OPTIONS",
114
+ message:
115
+ "Slugs options: defaultScope must be non-empty; minLength and maxLength must be integers with 0 <= minLength <= maxLength and maxLength >= 1",
116
+ });
117
+ }
102
118
  this.constraints = {
103
- minLength: options.minLength ?? DEFAULT_MIN_LENGTH,
104
- maxLength: options.maxLength ?? DEFAULT_MAX_LENGTH,
119
+ minLength,
120
+ maxLength,
105
121
  pattern: options.pattern,
106
- reservedWords: options.reservedWords ?? [],
122
+ // Match reserved words on the same normalized form as slugs.
123
+ reservedWords: (options.reservedWords ?? []).map((w) => this.norm(w)),
107
124
  };
108
125
  }
109
126
 
@@ -1,6 +1,32 @@
1
- import { v } from "convex/values";
2
- import { internalMutation, mutation } from "./_generated/server";
3
- import { lengthBounds, reserveResult } from "./validators";
1
+ import { ConvexError, v } from "convex/values";
2
+ import { internalMutation, mutation } from "./_generated/server.js";
3
+ import { lengthBounds, reserveResult } from "./validators.js";
4
+
5
+ /**
6
+ * Reject malformed arguments with `ConvexError({ code: "INVALID_ARGUMENT" })`.
7
+ * Expected slug rejections stay typed `{ ok: false, reason }` results; this
8
+ * covers input no correct client sends (empty scope/ref, non-integer bounds).
9
+ */
10
+ function assertArgs(args: {
11
+ scope: string;
12
+ resourceRef?: string;
13
+ bounds?: { minLength: number; maxLength: number };
14
+ }): void {
15
+ const { scope, resourceRef, bounds } = args;
16
+ const badBounds =
17
+ bounds !== undefined &&
18
+ !(
19
+ Number.isInteger(bounds.minLength) &&
20
+ Number.isInteger(bounds.maxLength) &&
21
+ bounds.minLength <= bounds.maxLength
22
+ );
23
+ if (scope === "" || resourceRef === "" || badBounds) {
24
+ throw new ConvexError({
25
+ code: "INVALID_ARGUMENT",
26
+ message: "scope and resourceRef must be non-empty; bounds must be integers with min <= max",
27
+ });
28
+ }
29
+ }
4
30
 
5
31
  /**
6
32
  * Reserve `slug` for `resourceRef` within `scope`. The slug arrives already
@@ -20,6 +46,7 @@ export const reserve = mutation({
20
46
  },
21
47
  returns: reserveResult,
22
48
  handler: async (ctx, args) => {
49
+ assertArgs(args);
23
50
  if (args.slug.length < Math.max(1, args.bounds.minLength)) {
24
51
  return { ok: false, reason: "SLUG_INVALID" as const };
25
52
  }
@@ -66,6 +93,7 @@ export const release = mutation({
66
93
  args: { scope: v.string(), slug: v.string() },
67
94
  returns: v.null(),
68
95
  handler: async (ctx, args) => {
96
+ assertArgs(args);
69
97
  const existing = await ctx.db
70
98
  .query("slugs")
71
99
  .withIndex("by_scope_slug", (q) =>
@@ -95,6 +123,9 @@ export const release = mutation({
95
123
  * chain A→B→C collapses to A→C), and a single redirect row per `(scope,
96
124
  * fromSlug)` is upserted (patched if present, else inserted) to bound growth.
97
125
  *
126
+ * Any redirect leaving `toSlug` is removed (it is a live name again), so no
127
+ * redirect ever starts at a live slug.
128
+ *
98
129
  * Self-rename (`fromSlug === toSlug`) is rejected with `SLUG_TAKEN` before any
99
130
  * DB read, preventing a self-loop redirect from being created.
100
131
  *
@@ -111,6 +142,7 @@ export const rename = mutation({
111
142
  },
112
143
  returns: reserveResult,
113
144
  handler: async (ctx, args) => {
145
+ assertArgs(args);
114
146
  if (args.fromSlug === args.toSlug) {
115
147
  return { ok: false, reason: "SLUG_TAKEN" as const };
116
148
  }
@@ -140,6 +172,18 @@ export const rename = mutation({
140
172
  }
141
173
  await ctx.db.patch("slugs", from._id, { slug: args.toSlug });
142
174
 
175
+ // `toSlug` is a live name again: drop its own redirect first, so renaming
176
+ // back (A->B, B->A) cannot repoint it into a self-loop A->A below.
177
+ const stale = await ctx.db
178
+ .query("redirects")
179
+ .withIndex("by_scope_from", (q) =>
180
+ q.eq("scope", args.scope).eq("fromSlug", args.toSlug),
181
+ )
182
+ .collect();
183
+ for (const row of stale) {
184
+ await ctx.db.delete("redirects", row._id);
185
+ }
186
+
143
187
  const inbound = await ctx.db
144
188
  .query("redirects")
145
189
  .withIndex("by_scope_to", (q) =>
@@ -1,5 +1,5 @@
1
1
  import { v } from "convex/values";
2
- import { internalQuery, query } from "./_generated/server";
2
+ import { internalQuery, query } from "./_generated/server.js";
3
3
 
4
4
  /**
5
5
  * Resolve `slug` to the `resourceRef` currently holding it within `scope`, or
package/src/shared.ts CHANGED
@@ -68,6 +68,11 @@ export function validateSlug(slug: string, c: SlugConstraints): SlugReason | nul
68
68
  if (slug.length > c.maxLength) {
69
69
  return "SLUG_INVALID";
70
70
  }
71
+ if (c.pattern !== undefined) {
72
+ // A global/sticky RegExp keeps `lastIndex` between calls; reset it so the
73
+ // same slug always gets the same verdict.
74
+ c.pattern.lastIndex = 0;
75
+ }
71
76
  if (c.pattern !== undefined && !c.pattern.test(slug)) {
72
77
  return "SLUG_INVALID";
73
78
  }
package/src/test.ts CHANGED
@@ -1,12 +1,18 @@
1
+ /// <reference types="vite/client" />
2
+ import type { GenericSchema, SchemaDefinition } from "convex/server";
1
3
  import type { TestConvex } from "convex-test";
2
- import schema from "./component/schema";
4
+ import schema from "./component/schema.js";
3
5
 
4
6
  const modules = import.meta.glob("./component/**/*.ts");
5
7
 
6
8
  /**
7
9
  * Register this component with a `convex-test` instance so consuming apps can
8
10
  * test integration: `import { register } from "@vllnt/convex-slugs/test"`.
11
+ * `t` may be built from the host app's own schema.
9
12
  */
10
- export function register(t: TestConvex<typeof schema>, name = "slugs"): void {
13
+ export function register<TSchema extends GenericSchema>(
14
+ t: TestConvex<SchemaDefinition<TSchema, boolean>>,
15
+ name = "slugs",
16
+ ): void {
11
17
  t.registerComponent(name, schema, modules);
12
18
  }
@@ -1,115 +0,0 @@
1
- import { convexTest } from "convex-test";
2
- import { describe, expect, test } from "vitest";
3
- import { api, internal } from "./_generated/api";
4
- import schema from "./schema";
5
-
6
- const modules = import.meta.glob("./**/*.ts");
7
- const scope = "global";
8
- const bounds = { minLength: 1, maxLength: 256 };
9
-
10
- function setup() {
11
- return convexTest(schema, modules);
12
- }
13
-
14
- async function reserve(
15
- t: ReturnType<typeof setup>,
16
- slug: string,
17
- resourceRef: string,
18
- ) {
19
- return await t.mutation(api.mutations.reserve, {
20
- scope,
21
- slug,
22
- resourceRef,
23
- bounds,
24
- });
25
- }
26
-
27
- async function rename(
28
- t: ReturnType<typeof setup>,
29
- fromSlug: string,
30
- toSlug: string,
31
- ) {
32
- return await t.mutation(api.mutations.rename, {
33
- scope,
34
- fromSlug,
35
- toSlug,
36
- bounds,
37
- });
38
- }
39
-
40
- describe("slugs component — internal repair and inspection APIs", () => {
41
- test("counts collapsed redirect chains", async () => {
42
- const t = setup();
43
- await reserve(t, "a", "doc");
44
- await rename(t, "a", "b");
45
- await rename(t, "b", "c");
46
- expect(await t.query(internal.queries.countRedirects, { scope })).toBe(2);
47
- });
48
-
49
- test("rename patches a pre-existing redirect row in place", async () => {
50
- const t = setup();
51
- await reserve(t, "src", "r");
52
- await t.mutation(internal.mutations.insertRedirectRaw, {
53
- scope,
54
- fromSlug: "src",
55
- toSlug: "stale",
56
- });
57
- expect(await rename(t, "src", "dst")).toEqual({ ok: true });
58
- expect(
59
- await t.query(api.queries.redirectFor, { scope, slug: "src" }),
60
- ).toBe("dst");
61
- expect(await t.query(internal.queries.countRedirects, { scope })).toBe(1);
62
- });
63
-
64
- test("duplicate slug rows degrade instead of throwing", async () => {
65
- const t = setup();
66
- await reserve(t, "twin", "first");
67
- await t.mutation(internal.mutations.insertRaw, {
68
- scope,
69
- slug: "twin",
70
- resourceRef: "first-dup",
71
- });
72
- expect(await t.query(api.queries.resolve, { scope, slug: "twin" })).toBe(
73
- "first",
74
- );
75
- expect(
76
- await t.query(api.queries.slugForResource, {
77
- scope,
78
- resourceRef: "first",
79
- }),
80
- ).toBe("twin");
81
- expect(await rename(t, "twin", "twin3")).toEqual({ ok: true });
82
- expect(
83
- await t.mutation(api.mutations.release, { scope, slug: "twin" }),
84
- ).toBeNull();
85
- });
86
-
87
- test("repoints and then clears multiple inbound redirects", async () => {
88
- const t = setup();
89
- await reserve(t, "mb", "r1");
90
- await t.mutation(internal.mutations.insertRedirectRaw, {
91
- scope,
92
- fromSlug: "ma",
93
- toSlug: "mb",
94
- });
95
- await t.mutation(internal.mutations.insertRedirectRaw, {
96
- scope,
97
- fromSlug: "mx",
98
- toSlug: "mb",
99
- });
100
- await rename(t, "mb", "mc");
101
- expect(await t.query(api.queries.redirectFor, { scope, slug: "ma" })).toBe(
102
- "mc",
103
- );
104
- expect(await t.query(api.queries.redirectFor, { scope, slug: "mx" })).toBe(
105
- "mc",
106
- );
107
- await t.mutation(api.mutations.release, { scope, slug: "mc" });
108
- expect(
109
- await t.query(api.queries.redirectFor, { scope, slug: "ma" }),
110
- ).toBeNull();
111
- expect(
112
- await t.query(api.queries.redirectFor, { scope, slug: "mx" }),
113
- ).toBeNull();
114
- });
115
- });
@@ -1,110 +0,0 @@
1
- // @vitest-environment jsdom
2
-
3
- /**
4
- * Unit tests for the optional React front-tooling hooks. `convex/react`'s
5
- * `useQuery` is mocked so the hooks are exercised in isolation — no live Convex
6
- * client. Runs under jsdom (per-file pragma above) while the global vitest env
7
- * stays edge-runtime for the backend suite.
8
- */
9
-
10
- import { renderHook } from "@testing-library/react";
11
- import type { FunctionReference } from "convex/server";
12
- import { useQuery } from "convex/react";
13
- import { beforeEach, describe, expect, it, vi } from "vitest";
14
-
15
- import { useResolve, useSlugAvailable } from "./index";
16
-
17
- vi.mock("convex/react", () => ({
18
- useQuery: vi.fn(),
19
- }));
20
-
21
- const mockedUseQuery = vi.mocked(useQuery);
22
-
23
- // A stand-in for the host's re-exported `resolve` query reference. The hooks
24
- // only forward it to `useQuery`, so an opaque cast is sufficient for the test.
25
- const resolveRef = "resolveRef" as unknown as FunctionReference<
26
- "query",
27
- "public",
28
- { slug: string; scope?: string },
29
- string | null
30
- >;
31
-
32
- beforeEach(() => {
33
- mockedUseQuery.mockReset();
34
- });
35
-
36
- describe("useResolve", () => {
37
- it("forwards (ref, args) to useQuery and returns the held resourceRef", () => {
38
- mockedUseQuery.mockReturnValue("user_1");
39
- const args = { slug: "my-handle", scope: "users" };
40
-
41
- const { result } = renderHook(() => useResolve(resolveRef, args));
42
-
43
- expect(mockedUseQuery).toHaveBeenCalledWith(resolveRef, args);
44
- expect(result.current).toBe("user_1");
45
- });
46
-
47
- it("returns undefined while the query is loading", () => {
48
- mockedUseQuery.mockReturnValue(undefined);
49
-
50
- const { result } = renderHook(() =>
51
- useResolve(resolveRef, { slug: "loading" }),
52
- );
53
-
54
- expect(result.current).toBeUndefined();
55
- });
56
-
57
- it("returns null when the slug is free", () => {
58
- mockedUseQuery.mockReturnValue(null);
59
-
60
- const { result } = renderHook(() =>
61
- useResolve(resolveRef, { slug: "free" }),
62
- );
63
-
64
- expect(result.current).toBeNull();
65
- });
66
- });
67
-
68
- describe("useSlugAvailable", () => {
69
- it("forwards (ref, args) to useQuery", () => {
70
- mockedUseQuery.mockReturnValue(null);
71
- const args = { slug: "candidate", scope: "users" };
72
-
73
- renderHook(() => useSlugAvailable(resolveRef, args));
74
-
75
- expect(mockedUseQuery).toHaveBeenCalledWith(resolveRef, args);
76
- });
77
-
78
- it("loading: useQuery undefined -> available undefined, resourceRef null", () => {
79
- mockedUseQuery.mockReturnValue(undefined);
80
-
81
- const { result } = renderHook(() =>
82
- useSlugAvailable(resolveRef, { slug: "loading" }),
83
- );
84
-
85
- expect(result.current.available).toBeUndefined();
86
- expect(result.current.resourceRef).toBeNull();
87
- });
88
-
89
- it("free: useQuery null -> available true, resourceRef null", () => {
90
- mockedUseQuery.mockReturnValue(null);
91
-
92
- const { result } = renderHook(() =>
93
- useSlugAvailable(resolveRef, { slug: "free" }),
94
- );
95
-
96
- expect(result.current.available).toBe(true);
97
- expect(result.current.resourceRef).toBeNull();
98
- });
99
-
100
- it("taken: useQuery string -> available false, resourceRef the holder", () => {
101
- mockedUseQuery.mockReturnValue("user_42");
102
-
103
- const { result } = renderHook(() =>
104
- useSlugAvailable(resolveRef, { slug: "taken" }),
105
- );
106
-
107
- expect(result.current.available).toBe(false);
108
- expect(result.current.resourceRef).toBe("user_42");
109
- });
110
- });