@vllnt/convex-slugs 0.2.0-canary.c3e0d93 → 0.2.0

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 CHANGED
@@ -4,34 +4,20 @@ All notable changes to this project are documented here. The format is based on
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
5
5
  adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [0.2.0] - Unreleased
8
-
9
- ### Breaking
10
-
11
- Inputs that 0.1.0 accepted now throw a `ConvexError`:
12
-
13
- - `INVALID_OPTIONS` from `new Slugs(...)`: an empty `defaultScope`, a
14
- `minLength` or `maxLength` that is not an integer (for example `1.5` or
15
- `NaN`), a negative `minLength`, `minLength > maxLength`, or `maxLength < 1`.
16
- A `NaN` `maxLength` used to disable the length cap.
17
- - `INVALID_ARGUMENT` from the component mutations `reserve`, `release` and
18
- `rename`: an empty `scope`, an empty `resourceRef` (`reserve`), or `bounds`
19
- that are not integers or have `minLength > maxLength`. Rows that 0.1.0 stored
20
- under scope `""` can no longer be released or renamed.
7
+ ## [0.2.0] - 2026-11-28
21
8
 
22
9
  ### Fixed
23
10
 
24
11
  - `rename` no longer leaves a self-redirect when a slug is renamed back to an
25
12
  earlier name (A→B, then B→A left `redirectFor(A) === A` on a live slug). A
26
- redirect starting at the new live name is now removed.
27
- - Reserved words are normalized like slugs, so `reservedWords: ["Admin"]` blocks
28
- `admin` (previously never matched when `foldCase` was on).
13
+ redirect starting at the new live name is now removed. Rows 0.1.0 already
14
+ wrote stay until that slug is renamed again or released: call `resolve`
15
+ before `redirectFor`, as the README's `profileBySlug` example does.
29
16
  - A `pattern` with the `g` or `y` flag gives the same verdict on every call
30
17
  instead of alternating.
31
18
  - `@vllnt/convex-slugs/test` type-checks for consumers under `nodenext` and
32
19
  `bundler` resolution (`vite/client` reference, `.js` suffixes on relative
33
20
  imports).
34
- - Test files are no longer included in the published package.
35
21
  - `register` from `@vllnt/convex-slugs/test` accepts a `convex-test` instance
36
22
  built from the host app's schema, as the README shows; it used to require the
37
23
  component's own schema type.
@@ -40,47 +26,60 @@ Inputs that 0.1.0 accepted now throw a `ConvexError`:
40
26
 
41
27
  - The npm package ships `docs/API.md`, `CHANGELOG.md` and `llms.txt`, so the
42
28
  docs in `node_modules/@vllnt/convex-slugs/` match the installed version.
43
- `llms.txt` links to the shipped files with relative paths. `docs/API.md` now
44
- lists every entry point, the React hooks and the `register` test helper.
29
+ `llms.txt` links to the shipped files with relative paths. `docs/API.md` lists
30
+ every entry point, the React hooks and the `register` test helper.
45
31
 
46
32
  ### Changed
47
33
 
48
- - Docs: README install command targets the stable release, "Testing your app",
49
- error table, concurrency and normalization limits.
50
- - Release flow: npm trusted publishing with provenance; `@latest` only from a
51
- `vX.Y.Z` tag on `main`. Pinned CI actions, pnpm 10 with a release-age gate,
52
- low-memory dev defaults.
53
- - Release flow: every push to `main` that changes the package or its shipped
54
- docs publishes a `canary`; `pnpm test:package` in CI fails when a required
55
- file is missing from the packed tarball.
56
- - `package.json` `homepage` points to
57
- https://oss.vllnt.com/packages/convex-slugs.
58
- - Docs: README "Related packages" lists only packages this one works with in
59
- code, which is none; the hint to use `@vllnt/convex-tokens` for secret keys
60
- moved to the intro.
61
- - Release flow: canary and stable publishes run `pnpm test:package` first; it
62
- type-checks every entry point and imports every runtime entry point,
63
- including `./react` with React 18.
64
- - Docs: README rewritten in the shared @vllnt section order (When to use, Quick
65
- start, API table, Common tasks, Errors and fixes, Limits and gotchas,
66
- Compatibility, Links); `docs/API.md` has one heading per export and method;
67
- `llms.txt` has When to use, an errors link and the Ecosystem block last;
68
- TSDoc on every public export.
69
- - Docs contract test: `pnpm lint` checks the README, `docs/API.md`, `llms.txt`
70
- and `CHANGELOG.md` in the repository, and `pnpm test:package` checks them in
71
- the installed tarball, checks every export against the built types and
72
- type-checks and runs the README examples. `pnpm check:links` requests every
73
- external docs link.
74
- - `package.json` `description` is now "Convex component for unique slugs,
34
+ The first four entries reject input that 0.1.0 accepted; each says what to do:
35
+
36
+ - `new Slugs(...)` throws a `ConvexError` with code `INVALID_OPTIONS` for an
37
+ empty `defaultScope`, a `minLength` or `maxLength` that is not an integer
38
+ (for example `1.5`, `NaN` or `Infinity`), a negative `minLength`,
39
+ `minLength > maxLength`, or `maxLength < 1`. A `NaN` or `Infinity`
40
+ `maxLength` used to disable the length cap. A `new Slugs` at module top level
41
+ throws when Convex loads that file, so every function in it fails. Fix the
42
+ options; for "no client limit" use `maxLength: 1024`, the component's cap.
43
+ - The component mutations `reserve`, `release` and `rename` throw a
44
+ `ConvexError` with code `INVALID_ARGUMENT` for an empty `scope`, an empty
45
+ `resourceRef` (`reserve`), or `bounds` that are not integers or have
46
+ `minLength > maxLength`. Rows that 0.1.0 stored under scope `""` can no longer
47
+ be released or renamed. Pass a non-empty `scope` (or omit it for
48
+ `defaultScope`) and a non-empty `resourceRef`.
49
+ - `reserve` and `rename` cap what they write at 1024 UTF-16 code units
50
+ (`string.length`), whatever `maxLength` or `bounds` say. A longer slug or
51
+ `toSlug` returns `{ ok: false, reason: "SLUG_INVALID" }`; a longer `scope`
52
+ (`reserve`, `rename`) or `resourceRef` (`reserve`) throws `INVALID_ARGUMENT`.
53
+ Shorten such values; `new Slugs` still accepts a `maxLength` over 1024, but
54
+ the component rejects the longer slugs. Rows stored over the cap before 0.2.0
55
+ stay readable, and `release` still removes them. Updating such a row: `rename`
56
+ from an over-cap slug to a shorter one works; `reserve` or `rename` onto an
57
+ over-cap slug returns `SLUG_INVALID` and leaves the row; `reserve` and
58
+ `rename` in an over-cap scope throw `INVALID_ARGUMENT`; a row with an over-cap
59
+ `resourceRef` keeps it when renamed.
60
+ - Reserved words are normalized like slugs (NFC, `trim()`, and lowercase unless
61
+ `foldCase: false`), so `reservedWords: ["Admin"]` now blocks `admin` with
62
+ `SLUG_RESERVED` (0.1.0 never matched it while `foldCase` was on). Remove a
63
+ word from `reservedWords` if it must stay claimable.
64
+ - `engines.node` is now `>=20` (was `>=18`): the lowest supported `convex`,
65
+ 1.45, needs Node.js 20, and convex 1.49 and newer need Node.js 22. Use
66
+ Node.js 20 or later. The peer range stays `convex@^1.45.0`.
67
+ - Release flow: `@latest` now comes only from a pushed `vX.Y.Z` tag on `main`
68
+ (was a manual workflow run with a version-bump input). A `canary` now
69
+ publishes on every push to `main` (was only pushes touching `src/`,
70
+ `package.json`, the lockfile or the publish workflow, and only while a
71
+ repository variable enabled it).
72
+ - Docs: README, `docs/API.md` and `llms.txt` rewritten to cover every export,
73
+ reason and error code, limit and gotcha; TSDoc on every public export.
74
+ - `package.json`: `description` is now "Convex component for unique slugs,
75
75
  handles and usernames per scope, with rename redirects, a TypeScript client
76
- and React hooks."; `keywords` now list 11 search terms.
77
- - Release flow: the 7-day release-age gate moved from the `package.json` `pnpm`
78
- field, which pnpm 10 ignores, to `pnpm-workspace.yaml`, so installs refuse
79
- versions newer than 7 days (`@vllnt/*` excluded). Renovate waits 7 days too.
80
- - Release flow: `pnpm test:package` copies that release-age gate into its temp
81
- consumer install.
82
- - CI: the Lint job runs `scripts/test-check-package-contents.sh`, which now also
83
- checks that `.test.mts` and `.test.cts` files are kept out of the tarball.
76
+ and React hooks.", `keywords` list 11 search terms, and `homepage` points to
77
+ https://oss.vllnt.com/packages/convex-slugs.
78
+ - Internal: CI, release and docs checks, tooling and more tests.
79
+
80
+ ### Removed
81
+
82
+ - Test files are no longer included in the published package.
84
83
 
85
84
  ## [0.1.0] - 2026-09-01
86
85
 
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Convex component for unique slugs, handles and usernames per scope, with rename redirects, a TypeScript client and React hooks.
4
4
 
5
+ ![Slug Registry — @vllnt/convex-slugs](https://raw.githubusercontent.com/vllnt/convex-slugs/main/.github/assets/thumbnail.png)
6
+
5
7
  ## For coding agents
6
8
 
7
9
  Docs for the installed version are in `node_modules/@vllnt/convex-slugs/`:
@@ -199,22 +201,22 @@ export function HandleField() {
199
201
  `reserve` and `rename` do not throw for expected rejections. They return
200
202
  `{ ok: false, reason }`:
201
203
 
202
- | `reason` | Cause | Fix |
203
- | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
204
- | `SLUG_INVALID` | After normalization the slug is empty, outside `minLength`..`maxLength`, or fails `pattern` | Show the rule to the user; for `rename` only `toSlug` is checked |
205
- | `SLUG_RESERVED` | The normalized slug is in `reservedWords` | Ask for another slug |
206
- | `SLUG_TAKEN` | The slug is held in the scope (by anyone, including the same `resourceRef`), or `rename` got `fromSlug === toSlug` after normalization | Ask for another slug; for `rename`, skip the call when both names normalize to the same slug |
207
- | `SLUG_NOT_FOUND` | `rename` got a `fromSlug` that is not held in the scope | Read the current slug with `slugForResource` and rename that one |
204
+ | `reason` | Cause | Fix |
205
+ | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
206
+ | `SLUG_INVALID` | After normalization the slug is empty, outside `minLength`..`maxLength`, fails `pattern`, or is over the component's cap of 1024 UTF-16 code units (`string.length`) | Show the rule to the user; for `rename` only `toSlug` is checked. Keep `maxLength` at 1024 or less so the client rule matches the cap |
207
+ | `SLUG_RESERVED` | The normalized slug is in `reservedWords` | Ask for another slug |
208
+ | `SLUG_TAKEN` | The slug is held in the scope (by anyone, including the same `resourceRef`), or `rename` got `fromSlug === toSlug` after normalization | Ask for another slug; for `rename`, skip the call when both names normalize to the same slug |
209
+ | `SLUG_NOT_FOUND` | `rename` got a `fromSlug` that is not held in the scope | Read the current slug with `slugForResource` and rename that one |
208
210
 
209
211
  Invalid input throws a `ConvexError` whose `data` is `{ code, message }`; the
210
212
  host sees the code as `error.data.code`. `reserve` and `rename` check the slug in
211
213
  the client first, so a slug that fails those checks returns `SLUG_INVALID` (or
212
214
  `SLUG_RESERVED`) before the component sees an empty scope.
213
215
 
214
- | Code | Message | Cause | Fix |
215
- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |
216
- | `INVALID_OPTIONS` | `Slugs options: defaultScope must be non-empty; minLength and maxLength must be integers with 0 <= minLength <= maxLength and maxLength >= 1` | `new Slugs(...)` got an empty `defaultScope`, a non-integer or negative `minLength`, a non-integer `maxLength`, or `maxLength` below `max(1, minLength)` | Fix the options. A `new Slugs` at module top level throws when Convex loads that file, so every function in it fails |
217
- | `INVALID_ARGUMENT` | `scope and resourceRef must be non-empty; bounds must be integers with min <= max` | `reserve`, `release` or `rename` got `scope: ""`, or `reserve` got `resourceRef: ""`; or a direct component call passed `bounds` that are not integers with `minLength <= maxLength` | Pass a non-empty scope (or omit it for `defaultScope`) and a non-empty `resourceRef` |
216
+ | Code | Message | Cause | Fix |
217
+ | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------- |
218
+ | `INVALID_OPTIONS` | `Slugs options: defaultScope must be non-empty; minLength and maxLength must be integers with 0 <= minLength <= maxLength and maxLength >= 1` | `new Slugs(...)` got an empty `defaultScope`, a non-integer or negative `minLength`, a non-integer `maxLength`, or `maxLength` below `max(1, minLength)` | Fix the options. A `new Slugs` at module top level throws when Convex loads that file, so every function in it fails |
219
+ | `INVALID_ARGUMENT` | `scope and resourceRef must be non-empty, and at most 1024 UTF-16 code units on reserve and rename; bounds must be integers with min <= max` | `reserve`, `release` or `rename` got `scope: ""`, or `reserve` got `resourceRef: ""`; `reserve` or `rename` got a `scope`, or `reserve` a `resourceRef`, over 1024 UTF-16 code units; or a direct component call passed `bounds` that are not integers with `minLength <= maxLength` | Pass a non-empty scope (or omit it for `defaultScope`) and a non-empty `resourceRef`, each at most 1024 UTF-16 code units |
218
220
 
219
221
  Arguments of the wrong type are rejected by Convex argument validation before
220
222
  the component runs.
@@ -231,6 +233,20 @@ the component runs.
231
233
  Defaults: `minLength: 1`, `maxLength: 256`,
232
234
  `defaultScope: "global"`, `foldCase: true`, `reservedWords: []`, no
233
235
  `pattern`. An empty slug is always `SLUG_INVALID`, even with `minLength: 0`.
236
+ - The component caps what `reserve` and `rename` write at 1024 UTF-16 code
237
+ units (`string.length`, counted like `maxLength`), whatever `maxLength` or
238
+ `bounds` say: a longer slug returns `SLUG_INVALID`, and a longer `scope` or
239
+ `resourceRef` throws `INVALID_ARGUMENT`. For example 512 😀 (1024 units)
240
+ passes and 513 (1026 units) is rejected. `new Slugs` still accepts a
241
+ `maxLength` over 1024, but slugs longer than 1024 are rejected by the
242
+ component. `release` and the queries are not capped.
243
+ - Rows that a version before 0.2.0 stored with a slug, `scope` or
244
+ `resourceRef` over 1024 units stay readable with `resolve`, `redirectFor`
245
+ and `slugForResource`, and `release` removes them. `rename` from such a slug
246
+ to a shorter one works and records the redirect; `reserve` or `rename` onto
247
+ such a slug returns `SLUG_INVALID`; `reserve` and `rename` in such a scope
248
+ throw `INVALID_ARGUMENT`. A row with a long `resourceRef` keeps it when
249
+ renamed.
234
250
  - `pattern` and `reservedWords` run against the normalized slug, so with
235
251
  `foldCase: true` a pattern of `/^[a-z]+$/` accepts `"ADA"`.
236
252
  - `release` is idempotent and always returns `null`: releasing a slug that is
@@ -261,8 +277,8 @@ the component runs.
261
277
  - Peer dependency: `convex@^1.45.0`. CI runs the unit tests on the locked convex
262
278
  version (1.51.0), and type-checks and runs the packed package against convex
263
279
  1.45.0.
264
- - Node.js: convex 1.45 to 1.48 require Node.js 20 or later; convex 1.49 and
265
- newer require Node.js 22 or later. ES modules only.
280
+ - Node.js: `engines.node` is `>=20`. convex 1.45 to 1.48 require Node.js 20 or
281
+ later; convex 1.49 and newer require Node.js 22 or later. ES modules only.
266
282
  - `Slugs` runs in Convex queries, mutations and actions: it only calls
267
283
  `ctx.runQuery` and `ctx.runMutation`.
268
284
  - React: optional peer `react@>=18`, used only by `@vllnt/convex-slugs/react`.
@@ -334,7 +350,7 @@ one slug.
334
350
  are callable only from the host's own functions. A host that calls
335
351
  `components.slugs` directly instead of through `Slugs` skips normalization,
336
352
  `pattern` and reserved words; the component then only rejects an empty slug
337
- and one outside the `bounds` the caller passes.
353
+ and one outside the `bounds` the caller passes or over the 1024-unit cap.
338
354
  - Each `reserve` and `rename` is one Convex mutation (serializable): of
339
355
  simultaneous claims on one slug, one succeeds and the others get
340
356
  `SLUG_TAKEN`.
@@ -17,7 +17,11 @@ export interface SlugsOptions {
17
17
  foldCase?: boolean;
18
18
  /** Minimum slug length after normalization. Default `1`. */
19
19
  minLength?: number;
20
- /** Maximum slug length after normalization. Default `256`. */
20
+ /**
21
+ * Maximum slug length after normalization, in UTF-16 code units. Default
22
+ * `256`. A value over 1024 is accepted, but the component still returns
23
+ * `SLUG_INVALID` for a slug over 1024 code units.
24
+ */
21
25
  maxLength?: number;
22
26
  /** Allowed charset; a slug failing it is rejected `SLUG_INVALID`. Default: none. */
23
27
  pattern?: RegExp;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,sDAAsD;AAEtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,mDAAmD;AACnD,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,OAAO,CAAC;IACZ;;;OAGG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED,yDAAyD;AACzD,MAAM,WAAW,YAAY;IAC3B,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sFAAsF;IACtF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oFAAoF;IACpF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0FAA0F;IAC1F,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,sDAAsD;AAEtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,mDAAmD;AACnD,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,OAAO,CAAC;IACZ;;;OAGG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED,yDAAyD;AACzD,MAAM,WAAW,YAAY;IAC3B,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sFAAsF;IACtF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oFAAoF;IACpF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0FAA0F;IAC1F,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B"}
@@ -5,7 +5,9 @@
5
5
  * redirect row is removed (the slug is a live name again).
6
6
  *
7
7
  * @returns `{ ok: true }`, or `{ ok: false, reason }` where reason is
8
- * `SLUG_INVALID` (empty/over length) or `SLUG_TAKEN` (already held in scope).
8
+ * `SLUG_INVALID` (empty, outside `bounds` or over {@link MAX_INPUT_LENGTH}) or
9
+ * `SLUG_TAKEN` (already held in scope).
10
+ * @throws `INVALID_ARGUMENT` for an empty, or over-cap, `scope` or `resourceRef`.
9
11
  */
10
12
  export declare const reserve: import("convex/server").RegisteredMutation<"public", {
11
13
  bounds: {
@@ -51,9 +53,15 @@ export declare const release: import("convex/server").RegisteredMutation<"public
51
53
  * Self-rename (`fromSlug === toSlug`) is rejected with `SLUG_TAKEN` before any
52
54
  * DB read, preventing a self-loop redirect from being created.
53
55
  *
56
+ * `fromSlug` is not size-capped: it is only a lookup key, so a value over the
57
+ * cap writes nothing unless an older version stored it, and renaming such a
58
+ * legacy row to a short `toSlug` is the way to bring it under the cap.
59
+ *
54
60
  * @returns `{ ok: true }`, or `{ ok: false, reason }` where reason is
55
- * `SLUG_INVALID` (empty/over length `toSlug`), `SLUG_NOT_FOUND` (`fromSlug` not
56
- * held), or `SLUG_TAKEN` (`toSlug` already held or equals `fromSlug`).
61
+ * `SLUG_INVALID` (empty, outside `bounds` or over {@link MAX_INPUT_LENGTH}
62
+ * `toSlug`), `SLUG_NOT_FOUND` (`fromSlug` not held), or `SLUG_TAKEN` (`toSlug`
63
+ * already held or equals `fromSlug`).
64
+ * @throws `INVALID_ARGUMENT` for an empty, or over-cap, `scope`.
57
65
  */
58
66
  export declare const rename: import("convex/server").RegisteredMutation<"public", {
59
67
  bounds: {
@@ -1 +1 @@
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
+ {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAwDA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;YAWc,cAAc;;;YASd,YAAY;;;;GAkB5C,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO;;;iBAyBlB,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;YAWe,YAAY;;;YAGZ,cAAc;;;YASd,gBAAgB;;;;GAoDhD,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS;;;;iBAWpB,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;;;;iBAW5B,CAAC"}
@@ -1,24 +1,42 @@
1
1
  import { ConvexError, v } from "convex/values";
2
2
  import { internalMutation, mutation } from "./_generated/server.js";
3
3
  import { lengthBounds, reserveResult } from "./validators.js";
4
+ /**
5
+ * Hard cap, in UTF-16 code units (`string.length`), on the slug, `scope` and
6
+ * `resourceRef` that `reserve` and `rename` write. It holds whatever `bounds`
7
+ * the caller passes. `release` and the queries do not apply it, so rows stored
8
+ * by an older version with longer values stay readable and removable.
9
+ */
10
+ const MAX_INPUT_LENGTH = 1024;
4
11
  /**
5
12
  * Reject malformed arguments with `ConvexError({ code: "INVALID_ARGUMENT" })`.
6
13
  * Expected slug rejections stay typed `{ ok: false, reason }` results; this
7
- * covers input no correct client sends (empty scope/ref, non-integer bounds).
14
+ * covers input no correct client sends (empty scope/ref, non-integer bounds,
15
+ * and on writes a scope or ref over {@link MAX_INPUT_LENGTH}).
8
16
  */
9
17
  function assertArgs(args) {
10
18
  const { scope, resourceRef, bounds } = args;
11
- const badBounds = bounds !== undefined &&
19
+ // Only `reserve` and `rename` pass `bounds`; they are the size-capped writes.
20
+ const isWrite = bounds !== undefined;
21
+ const badBounds = isWrite &&
12
22
  !(Number.isInteger(bounds.minLength) &&
13
23
  Number.isInteger(bounds.maxLength) &&
14
24
  bounds.minLength <= bounds.maxLength);
15
- if (scope === "" || resourceRef === "" || badBounds) {
25
+ const oversized = isWrite &&
26
+ (scope.length > MAX_INPUT_LENGTH ||
27
+ (resourceRef ?? "").length > MAX_INPUT_LENGTH);
28
+ if (scope === "" || resourceRef === "" || badBounds || oversized) {
16
29
  throw new ConvexError({
17
30
  code: "INVALID_ARGUMENT",
18
- message: "scope and resourceRef must be non-empty; bounds must be integers with min <= max",
31
+ message: `scope and resourceRef must be non-empty, and at most ${String(MAX_INPUT_LENGTH)} UTF-16 code units on reserve and rename; bounds must be integers with min <= max`,
19
32
  });
20
33
  }
21
34
  }
35
+ /** Whether a slug to be written is empty, outside `bounds`, or over the cap. */
36
+ function slugOutOfBounds(slug, bounds) {
37
+ return (slug.length < Math.max(1, bounds.minLength) ||
38
+ slug.length > Math.min(bounds.maxLength, MAX_INPUT_LENGTH));
39
+ }
22
40
  /**
23
41
  * Reserve `slug` for `resourceRef` within `scope`. The slug arrives already
24
42
  * normalized by the client; `bounds` re-guards empty/oversized input at the
@@ -26,7 +44,9 @@ function assertArgs(args) {
26
44
  * redirect row is removed (the slug is a live name again).
27
45
  *
28
46
  * @returns `{ ok: true }`, or `{ ok: false, reason }` where reason is
29
- * `SLUG_INVALID` (empty/over length) or `SLUG_TAKEN` (already held in scope).
47
+ * `SLUG_INVALID` (empty, outside `bounds` or over {@link MAX_INPUT_LENGTH}) or
48
+ * `SLUG_TAKEN` (already held in scope).
49
+ * @throws `INVALID_ARGUMENT` for an empty, or over-cap, `scope` or `resourceRef`.
30
50
  */
31
51
  export const reserve = mutation({
32
52
  args: {
@@ -38,10 +58,7 @@ export const reserve = mutation({
38
58
  returns: reserveResult,
39
59
  handler: async (ctx, args) => {
40
60
  assertArgs(args);
41
- if (args.slug.length < Math.max(1, args.bounds.minLength)) {
42
- return { ok: false, reason: "SLUG_INVALID" };
43
- }
44
- if (args.slug.length > args.bounds.maxLength) {
61
+ if (slugOutOfBounds(args.slug, args.bounds)) {
45
62
  return { ok: false, reason: "SLUG_INVALID" };
46
63
  }
47
64
  const existing = await ctx.db
@@ -110,9 +127,15 @@ export const release = mutation({
110
127
  * Self-rename (`fromSlug === toSlug`) is rejected with `SLUG_TAKEN` before any
111
128
  * DB read, preventing a self-loop redirect from being created.
112
129
  *
130
+ * `fromSlug` is not size-capped: it is only a lookup key, so a value over the
131
+ * cap writes nothing unless an older version stored it, and renaming such a
132
+ * legacy row to a short `toSlug` is the way to bring it under the cap.
133
+ *
113
134
  * @returns `{ ok: true }`, or `{ ok: false, reason }` where reason is
114
- * `SLUG_INVALID` (empty/over length `toSlug`), `SLUG_NOT_FOUND` (`fromSlug` not
115
- * held), or `SLUG_TAKEN` (`toSlug` already held or equals `fromSlug`).
135
+ * `SLUG_INVALID` (empty, outside `bounds` or over {@link MAX_INPUT_LENGTH}
136
+ * `toSlug`), `SLUG_NOT_FOUND` (`fromSlug` not held), or `SLUG_TAKEN` (`toSlug`
137
+ * already held or equals `fromSlug`).
138
+ * @throws `INVALID_ARGUMENT` for an empty, or over-cap, `scope`.
116
139
  */
117
140
  export const rename = mutation({
118
141
  args: {
@@ -127,10 +150,7 @@ export const rename = mutation({
127
150
  if (args.fromSlug === args.toSlug) {
128
151
  return { ok: false, reason: "SLUG_TAKEN" };
129
152
  }
130
- if (args.toSlug.length < Math.max(1, args.bounds.minLength)) {
131
- return { ok: false, reason: "SLUG_INVALID" };
132
- }
133
- if (args.toSlug.length > args.bounds.maxLength) {
153
+ if (slugOutOfBounds(args.toSlug, args.bounds)) {
134
154
  return { ok: false, reason: "SLUG_INVALID" };
135
155
  }
136
156
  const from = await ctx.db
@@ -1 +1 @@
1
- {"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE9D;;;;GAIG;AACH,SAAS,UAAU,CAAC,IAInB;IACC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC5C,MAAM,SAAS,GACb,MAAM,KAAK,SAAS;QACpB,CAAC,CACC,MAAM,CAAC,SAAS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E,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE;IACjB,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;SAC9B,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;IAChD,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE;IACrE,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE;IACjB,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE;YAC/B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC,CAAC"}
package/docs/API.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # API Reference — @vllnt/convex-slugs
2
2
 
3
- **Compatibility:** `convex@^1.45.0`; optional `react@>=18` for `./react`.
3
+ **Compatibility:** `convex@^1.45.0`; optional `react@>=18` for `./react`;
4
+ Node.js 20 or later (`engines.node` `>=20`).
4
5
 
5
6
  ## Entry points
6
7
 
@@ -61,10 +62,12 @@ Claims `slug` for `resourceRef`. Returns `{ ok: true }`, or `{ ok: false, reason
61
62
  with `SLUG_INVALID`, `SLUG_RESERVED` or `SLUG_TAKEN`. `SLUG_TAKEN` is returned
62
63
  whenever the slug is held in the scope, also when the same `resourceRef` holds
63
64
  it. Reserving a slug that was renamed away deletes the redirect that started at
64
- it. Throws `INVALID_ARGUMENT` for `scope: ""` or `resourceRef: ""`, unless the
65
- slug already failed the client checks: then it returns `SLUG_INVALID` (or
66
- `SLUG_RESERVED`) without calling the component. One `resourceRef` may hold
67
- several slugs.
65
+ it. Throws `INVALID_ARGUMENT` for `scope: ""` or `resourceRef: ""`, or a
66
+ `scope` or `resourceRef` over 1024 UTF-16 code units, unless the slug already
67
+ failed the client checks: then it returns `SLUG_INVALID` (or `SLUG_RESERVED`)
68
+ without calling the component. A slug over 1024 UTF-16 code units returns
69
+ `SLUG_INVALID` from the component even when `maxLength` is larger (see
70
+ [Limits](#limits)). One `resourceRef` may hold several slugs.
68
71
 
69
72
  ### `release`
70
73
 
@@ -89,7 +92,8 @@ options. Checks, in order:
89
92
 
90
93
  1. `toSlug` fails the options: `SLUG_INVALID` or `SLUG_RESERVED` (client).
91
94
  2. `fromSlug === toSlug` after normalization: `SLUG_TAKEN`, before any read.
92
- 3. `toSlug` outside the length bounds: `SLUG_INVALID` (component).
95
+ 3. `toSlug` outside the length bounds or over 1024 UTF-16 code units:
96
+ `SLUG_INVALID` (component).
93
97
  4. `fromSlug` not held: `SLUG_NOT_FOUND`.
94
98
  5. `toSlug` held: `SLUG_TAKEN`.
95
99
 
@@ -97,7 +101,9 @@ On success, redirects that pointed at `fromSlug` are repointed to `toSlug`, so a
97
101
  chain A -> B -> C leaves A -> C and B -> C. At most one redirect row exists per
98
102
  `(scope, fromSlug)`. A redirect that started at `toSlug` is deleted, so renaming
99
103
  back (A -> B, then B -> A) leaves only B -> A and no redirect starts at a live
100
- slug. Throws `INVALID_ARGUMENT` for `scope: ""`.
104
+ slug. Throws `INVALID_ARGUMENT` for `scope: ""` or a `scope` over 1024 UTF-16
105
+ code units. `fromSlug` is not capped, so a slug an older version stored over
106
+ the cap can be renamed to a shorter one.
101
107
 
102
108
  ### `resolve`
103
109
 
@@ -149,7 +155,9 @@ interface SlugsOptions {
149
155
 
150
156
  `new Slugs` throws `INVALID_OPTIONS` unless `defaultScope` is non-empty,
151
157
  `minLength` and `maxLength` are integers, `minLength >= 0`, and
152
- `maxLength >= max(1, minLength)`. A `pattern` with the `g` or `y` flag is reset
158
+ `maxLength >= max(1, minLength)`. A `maxLength` over 1024 is accepted, but the
159
+ component still returns `SLUG_INVALID` for a slug over 1024 UTF-16 code units
160
+ (see [Limits](#limits)). A `pattern` with the `g` or `y` flag is reset
153
161
  before each test, so the same slug always gets the same verdict.
154
162
 
155
163
  ### `SlugWriteResult`
@@ -221,12 +229,12 @@ the mounted component, the same shape as `SlugsComponent`.
221
229
 
222
230
  `reserve` and `rename` return `{ ok: false, reason }` instead of throwing:
223
231
 
224
- | Reason | When |
225
- | ---------------- | ------------------------------------------------------------------------------------------- |
226
- | `SLUG_INVALID` | After normalization the slug is empty, outside `minLength`..`maxLength`, or fails `pattern` |
227
- | `SLUG_RESERVED` | The normalized slug is in the normalized `reservedWords` |
228
- | `SLUG_TAKEN` | The slug is held in the scope, or `rename` got `fromSlug === toSlug` after normalization |
229
- | `SLUG_NOT_FOUND` | `rename` got a `fromSlug` that is not held in the scope |
232
+ | Reason | When |
233
+ | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
234
+ | `SLUG_INVALID` | After normalization the slug is empty, outside `minLength`..`maxLength`, fails `pattern`, or is over 1024 UTF-16 code units (component cap) |
235
+ | `SLUG_RESERVED` | The normalized slug is in the normalized `reservedWords` |
236
+ | `SLUG_TAKEN` | The slug is held in the scope, or `rename` got `fromSlug === toSlug` after normalization |
237
+ | `SLUG_NOT_FOUND` | `rename` got a `fromSlug` that is not held in the scope |
230
238
 
231
239
  Causes and fixes are in the README's
232
240
  [Errors and fixes](../README.md#errors-and-fixes) table.
@@ -235,16 +243,37 @@ Causes and fixes are in the README's
235
243
 
236
244
  Invalid input throws a `ConvexError` whose `data` is `{ code, message }`:
237
245
 
238
- | Code | Thrown by | When |
239
- | ------------------ | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
240
- | `INVALID_OPTIONS` | `new Slugs(...)` | Empty `defaultScope`, or `minLength`/`maxLength` not integers with `minLength >= 0` and `maxLength >= max(1, minLength)` |
241
- | `INVALID_ARGUMENT` | component mutations `reserve`, `release`, `rename` | Empty `scope`, empty `resourceRef` (`reserve`), or `bounds` that are not integers with `minLength <= maxLength` |
246
+ | Code | Thrown by | When |
247
+ | ------------------ | -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
248
+ | `INVALID_OPTIONS` | `new Slugs(...)` | Empty `defaultScope`, or `minLength`/`maxLength` not integers with `minLength >= 0` and `maxLength >= max(1, minLength)` |
249
+ | `INVALID_ARGUMENT` | component mutations `reserve`, `release`, `rename` | Empty `scope`, empty `resourceRef` (`reserve`), a `scope` or `resourceRef` over 1024 UTF-16 code units (`reserve`, `rename`), or `bounds` that are not integers with `minLength <= maxLength` |
242
250
 
243
251
  The client always sends integer bounds from its validated options, so through
244
- `Slugs` only an empty `scope` or `resourceRef` raises `INVALID_ARGUMENT`. The
252
+ `Slugs` only an empty `scope` or `resourceRef`, or one over 1024 UTF-16 code
253
+ units, raises `INVALID_ARGUMENT`. The
245
254
  queries do not throw for an empty scope. Arguments of the wrong type are
246
255
  rejected by Convex argument validation.
247
256
 
257
+ ## Limits
258
+
259
+ `reserve` and `rename` cap what they write at 1024 UTF-16 code units
260
+ (`string.length`), the same counting as `minLength` and `maxLength`. The cap
261
+ holds whatever `maxLength` or `bounds` say:
262
+
263
+ | Input | Over 1024 code units |
264
+ | --------------------------------------- | ------------------------- |
265
+ | `slug` (`reserve`), `toSlug` (`rename`) | returns `SLUG_INVALID` |
266
+ | `scope` (`reserve`, `rename`) | throws `INVALID_ARGUMENT` |
267
+ | `resourceRef` (`reserve`) | throws `INVALID_ARGUMENT` |
268
+
269
+ A value of exactly 1024 passes. 😀 counts 2, so 512 😀 pass and 513 are
270
+ rejected, although that is only 513 code points. `release`, `fromSlug` and the
271
+ queries are not capped. Rows a version before 0.2.0 stored over the cap stay
272
+ readable through `resolve`, `redirectFor` and `slugForResource`, and `release`
273
+ removes them. Renaming such a slug to a shorter one works; `reserve` or
274
+ `rename` onto it returns `SLUG_INVALID`, and writes in such a scope throw
275
+ `INVALID_ARGUMENT`.
276
+
248
277
  ## Normalization
249
278
 
250
279
  Every slug argument goes through `String.prototype.normalize("NFC")`, then
package/llms.txt CHANGED
@@ -15,6 +15,9 @@ mutation transaction. Slugs are normalized with NFC, `trim()` and (by default)
15
15
  `SLUG_RESERVED`, `SLUG_TAKEN`, `SLUG_NOT_FOUND`) instead of throwing. Invalid
16
16
  input throws `ConvexError` with `data.code` `INVALID_OPTIONS` or
17
17
  `INVALID_ARGUMENT`. Defaults: scope `"global"`, `minLength` 1, `maxLength` 256.
18
+ `reserve` and `rename` cap writes at 1024 UTF-16 code units (`string.length`):
19
+ a longer slug returns `SLUG_INVALID`, a longer `scope` or `resourceRef` throws
20
+ `INVALID_ARGUMENT`; `release` and the queries are not capped.
18
21
  The host owns auth and the meaning of the opaque `resourceRef`. React hooks
19
22
  `useSlugAvailable` and `useResolve` take the host's own public query.
20
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vllnt/convex-slugs",
3
- "version": "0.2.0-canary.c3e0d93",
3
+ "version": "0.2.0",
4
4
  "description": "Convex component for unique slugs, handles and usernames per scope, with rename redirects, a TypeScript client and React hooks.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -67,17 +67,15 @@
67
67
  },
68
68
  "devDependencies": {
69
69
  "@edge-runtime/vm": "^5.0.0",
70
- "@testing-library/react": "^16.3.3",
71
70
  "@types/react": "^19.3.0",
72
71
  "@types/react-dom": "^19.3.0",
73
72
  "@typescript/native": "npm:typescript@7.0.2",
74
73
  "@vitest/coverage-v8": "^5.1.1",
75
- "@vllnt/eslint-config": "2.1.0",
76
- "@vllnt/typescript": "3.0.0",
74
+ "@vllnt/eslint-config": "2.2.0",
75
+ "@vllnt/typescript": "3.0.1",
77
76
  "convex": "^1.51.0",
78
77
  "convex-test": "^0.0.73",
79
78
  "eslint": "^10.15.0",
80
- "jsdom": "^31.0.1",
81
79
  "prettier": "^3.10.1",
82
80
  "react": "^19.3.1",
83
81
  "react-dom": "^19.3.1",
@@ -102,7 +100,7 @@
102
100
  "url": "https://github.com/vllnt/convex-slugs"
103
101
  },
104
102
  "engines": {
105
- "node": ">=18"
103
+ "node": ">=20"
106
104
  },
107
105
  "publishConfig": {
108
106
  "access": "public"
@@ -20,7 +20,11 @@ export interface SlugsOptions {
20
20
  foldCase?: boolean;
21
21
  /** Minimum slug length after normalization. Default `1`. */
22
22
  minLength?: number;
23
- /** Maximum slug length after normalization. Default `256`. */
23
+ /**
24
+ * Maximum slug length after normalization, in UTF-16 code units. Default
25
+ * `256`. A value over 1024 is accepted, but the component still returns
26
+ * `SLUG_INVALID` for a slug over 1024 code units.
27
+ */
24
28
  maxLength?: number;
25
29
  /** Allowed charset; a slug failing it is rejected `SLUG_INVALID`. Default: none. */
26
30
  pattern?: RegExp;
@@ -2,10 +2,19 @@ import { ConvexError, v } from "convex/values";
2
2
  import { internalMutation, mutation } from "./_generated/server.js";
3
3
  import { lengthBounds, reserveResult } from "./validators.js";
4
4
 
5
+ /**
6
+ * Hard cap, in UTF-16 code units (`string.length`), on the slug, `scope` and
7
+ * `resourceRef` that `reserve` and `rename` write. It holds whatever `bounds`
8
+ * the caller passes. `release` and the queries do not apply it, so rows stored
9
+ * by an older version with longer values stay readable and removable.
10
+ */
11
+ const MAX_INPUT_LENGTH = 1024;
12
+
5
13
  /**
6
14
  * Reject malformed arguments with `ConvexError({ code: "INVALID_ARGUMENT" })`.
7
15
  * Expected slug rejections stay typed `{ ok: false, reason }` results; this
8
- * covers input no correct client sends (empty scope/ref, non-integer bounds).
16
+ * covers input no correct client sends (empty scope/ref, non-integer bounds,
17
+ * and on writes a scope or ref over {@link MAX_INPUT_LENGTH}).
9
18
  */
10
19
  function assertArgs(args: {
11
20
  scope: string;
@@ -13,21 +22,38 @@ function assertArgs(args: {
13
22
  bounds?: { minLength: number; maxLength: number };
14
23
  }): void {
15
24
  const { scope, resourceRef, bounds } = args;
25
+ // Only `reserve` and `rename` pass `bounds`; they are the size-capped writes.
26
+ const isWrite = bounds !== undefined;
16
27
  const badBounds =
17
- bounds !== undefined &&
28
+ isWrite &&
18
29
  !(
19
30
  Number.isInteger(bounds.minLength) &&
20
31
  Number.isInteger(bounds.maxLength) &&
21
32
  bounds.minLength <= bounds.maxLength
22
33
  );
23
- if (scope === "" || resourceRef === "" || badBounds) {
34
+ const oversized =
35
+ isWrite &&
36
+ (scope.length > MAX_INPUT_LENGTH ||
37
+ (resourceRef ?? "").length > MAX_INPUT_LENGTH);
38
+ if (scope === "" || resourceRef === "" || badBounds || oversized) {
24
39
  throw new ConvexError({
25
40
  code: "INVALID_ARGUMENT",
26
- message: "scope and resourceRef must be non-empty; bounds must be integers with min <= max",
41
+ message: `scope and resourceRef must be non-empty, and at most ${String(MAX_INPUT_LENGTH)} UTF-16 code units on reserve and rename; bounds must be integers with min <= max`,
27
42
  });
28
43
  }
29
44
  }
30
45
 
46
+ /** Whether a slug to be written is empty, outside `bounds`, or over the cap. */
47
+ function slugOutOfBounds(
48
+ slug: string,
49
+ bounds: { minLength: number; maxLength: number },
50
+ ): boolean {
51
+ return (
52
+ slug.length < Math.max(1, bounds.minLength) ||
53
+ slug.length > Math.min(bounds.maxLength, MAX_INPUT_LENGTH)
54
+ );
55
+ }
56
+
31
57
  /**
32
58
  * Reserve `slug` for `resourceRef` within `scope`. The slug arrives already
33
59
  * normalized by the client; `bounds` re-guards empty/oversized input at the
@@ -35,7 +61,9 @@ function assertArgs(args: {
35
61
  * redirect row is removed (the slug is a live name again).
36
62
  *
37
63
  * @returns `{ ok: true }`, or `{ ok: false, reason }` where reason is
38
- * `SLUG_INVALID` (empty/over length) or `SLUG_TAKEN` (already held in scope).
64
+ * `SLUG_INVALID` (empty, outside `bounds` or over {@link MAX_INPUT_LENGTH}) or
65
+ * `SLUG_TAKEN` (already held in scope).
66
+ * @throws `INVALID_ARGUMENT` for an empty, or over-cap, `scope` or `resourceRef`.
39
67
  */
40
68
  export const reserve = mutation({
41
69
  args: {
@@ -47,10 +75,7 @@ export const reserve = mutation({
47
75
  returns: reserveResult,
48
76
  handler: async (ctx, args) => {
49
77
  assertArgs(args);
50
- if (args.slug.length < Math.max(1, args.bounds.minLength)) {
51
- return { ok: false, reason: "SLUG_INVALID" as const };
52
- }
53
- if (args.slug.length > args.bounds.maxLength) {
78
+ if (slugOutOfBounds(args.slug, args.bounds)) {
54
79
  return { ok: false, reason: "SLUG_INVALID" as const };
55
80
  }
56
81
  const existing = await ctx.db
@@ -129,9 +154,15 @@ export const release = mutation({
129
154
  * Self-rename (`fromSlug === toSlug`) is rejected with `SLUG_TAKEN` before any
130
155
  * DB read, preventing a self-loop redirect from being created.
131
156
  *
157
+ * `fromSlug` is not size-capped: it is only a lookup key, so a value over the
158
+ * cap writes nothing unless an older version stored it, and renaming such a
159
+ * legacy row to a short `toSlug` is the way to bring it under the cap.
160
+ *
132
161
  * @returns `{ ok: true }`, or `{ ok: false, reason }` where reason is
133
- * `SLUG_INVALID` (empty/over length `toSlug`), `SLUG_NOT_FOUND` (`fromSlug` not
134
- * held), or `SLUG_TAKEN` (`toSlug` already held or equals `fromSlug`).
162
+ * `SLUG_INVALID` (empty, outside `bounds` or over {@link MAX_INPUT_LENGTH}
163
+ * `toSlug`), `SLUG_NOT_FOUND` (`fromSlug` not held), or `SLUG_TAKEN` (`toSlug`
164
+ * already held or equals `fromSlug`).
165
+ * @throws `INVALID_ARGUMENT` for an empty, or over-cap, `scope`.
135
166
  */
136
167
  export const rename = mutation({
137
168
  args: {
@@ -146,10 +177,7 @@ export const rename = mutation({
146
177
  if (args.fromSlug === args.toSlug) {
147
178
  return { ok: false, reason: "SLUG_TAKEN" as const };
148
179
  }
149
- if (args.toSlug.length < Math.max(1, args.bounds.minLength)) {
150
- return { ok: false, reason: "SLUG_INVALID" as const };
151
- }
152
- if (args.toSlug.length > args.bounds.maxLength) {
180
+ if (slugOutOfBounds(args.toSlug, args.bounds)) {
153
181
  return { ok: false, reason: "SLUG_INVALID" as const };
154
182
  }
155
183
  const from = await ctx.db