@vllnt/convex-slugs 0.1.0 → 0.1.1-canary.22e5023
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/README.md +88 -36
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +17 -3
- package/dist/client/index.js.map +1 -1
- package/dist/component/mutations.d.ts +3 -0
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +36 -3
- package/dist/component/mutations.js.map +1 -1
- package/dist/component/queries.js +1 -1
- package/dist/component/queries.js.map +1 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +5 -0
- package/dist/shared.js.map +1 -1
- package/package.json +31 -20
- package/src/client/index.ts +20 -3
- package/src/component/mutations.ts +47 -3
- package/src/component/queries.ts +1 -1
- package/src/shared.ts +5 -0
- package/src/test.ts +2 -1
- package/src/component/component.test.ts +0 -115
- package/src/react/index.test.tsx +0 -110
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<!-- Badges -->
|
|
2
|
+
|
|
2
3
|
[](https://www.convex.dev/components)
|
|
3
4
|
[](https://www.npmjs.com/package/@vllnt/convex-slugs)
|
|
4
5
|
[](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,
|
|
19
|
-
**redirect on rename**. Domain-neutral: article slugs, profile handles,
|
|
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
|
|
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
|
|
27
|
-
|
|
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)
|
|
30
|
-
|
|
31
|
-
- **
|
|
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,10 @@ slugs — any public-URL key.
|
|
|
36
44
|
pnpm add @vllnt/convex-slugs
|
|
37
45
|
```
|
|
38
46
|
|
|
39
|
-
|
|
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.
|
|
40
51
|
|
|
41
52
|
## Usage
|
|
42
53
|
|
|
@@ -60,55 +71,77 @@ import { Slugs } from "@vllnt/convex-slugs";
|
|
|
60
71
|
const slugs = new Slugs(components.slugs);
|
|
61
72
|
|
|
62
73
|
export const claim = mutation({
|
|
63
|
-
args: { handle: v.string()
|
|
64
|
-
handler: (ctx, { handle
|
|
74
|
+
args: { handle: v.string() },
|
|
75
|
+
handler: async (ctx, { handle }) => {
|
|
76
|
+
const identity = await ctx.auth.getUserIdentity();
|
|
77
|
+
if (!identity) throw new Error("Unauthenticated");
|
|
78
|
+
return slugs.reserve(ctx, handle, identity.tokenIdentifier);
|
|
79
|
+
},
|
|
65
80
|
});
|
|
66
81
|
|
|
67
82
|
export const lookup = query({
|
|
68
|
-
args: {
|
|
69
|
-
handler: (ctx, {
|
|
83
|
+
args: { slug: v.string(), scope: v.optional(v.string()) },
|
|
84
|
+
handler: (ctx, { slug }) => slugs.resolve(ctx, slug, "global"),
|
|
70
85
|
});
|
|
71
86
|
```
|
|
72
87
|
|
|
73
|
-
Client
|
|
88
|
+
Client defaults: `defaultScope: "global"`, `foldCase: true`, `minLength: 1`,
|
|
89
|
+
`maxLength: 256`, `reservedWords: []`; `pattern` is optional. Configure these in
|
|
90
|
+
`new Slugs(component, options)`; see [the API reference](docs/API.md).
|
|
74
91
|
|
|
75
92
|
## API Reference
|
|
76
93
|
|
|
77
|
-
| Method
|
|
78
|
-
|
|
79
|
-
| `reserve(ctx, slug, resourceRef, scope?)`
|
|
80
|
-
| `release(ctx, slug, scope?)`
|
|
81
|
-
| `rename(ctx, fromSlug, toSlug, scope?)`
|
|
82
|
-
| `resolve(ctx, slug, scope?)`
|
|
83
|
-
| `redirectFor(ctx, slug, scope?)`
|
|
84
|
-
| `slugForResource(ctx, resourceRef, scope?)` | query
|
|
94
|
+
| Method | Kind | Result |
|
|
95
|
+
| ------------------------------------------- | -------- | --------------------------------------------------------------------------------------------- |
|
|
96
|
+
| `reserve(ctx, slug, resourceRef, scope?)` | mutation | `{ ok: true }` or `{ ok: false, reason }` (`SLUG_INVALID` \| `SLUG_RESERVED` \| `SLUG_TAKEN`) |
|
|
97
|
+
| `release(ctx, slug, scope?)` | mutation | `null` (idempotent) |
|
|
98
|
+
| `rename(ctx, fromSlug, toSlug, scope?)` | mutation | `{ ok }` (`SLUG_INVALID` \| `SLUG_RESERVED` \| `SLUG_NOT_FOUND` \| `SLUG_TAKEN`) |
|
|
99
|
+
| `resolve(ctx, slug, scope?)` | query | `resourceRef \| null` |
|
|
100
|
+
| `redirectFor(ctx, slug, scope?)` | query | `toSlug \| null` |
|
|
101
|
+
| `slugForResource(ctx, resourceRef, scope?)` | query | `slug \| null` |
|
|
85
102
|
|
|
86
103
|
Full reference: [docs/API.md](docs/API.md).
|
|
87
104
|
|
|
88
105
|
## React
|
|
89
106
|
|
|
90
|
-
Optional, tree-shakeable hooks from `@vllnt/convex-slugs/react` — thin wrappers
|
|
91
|
-
`useQuery`; `react` is an optional peer dep. Each takes the host's
|
|
92
|
-
`resolve` query reference.
|
|
107
|
+
Optional, tree-shakeable hooks from `@vllnt/convex-slugs/react` — thin wrappers
|
|
108
|
+
over `useQuery`; `react` is an optional peer dep. Each takes the host's
|
|
109
|
+
re-exported `resolve` query reference.
|
|
93
110
|
|
|
94
111
|
```tsx
|
|
95
112
|
import { useSlugAvailable } from "@vllnt/convex-slugs/react";
|
|
96
113
|
import { api } from "../convex/_generated/api";
|
|
97
114
|
|
|
98
115
|
// `available` is undefined while loading, true when free, false when held.
|
|
99
|
-
const { available, resourceRef } = useSlugAvailable(api.handles.
|
|
116
|
+
const { available, resourceRef } = useSlugAvailable(api.handles.lookup, {
|
|
117
|
+
slug,
|
|
118
|
+
});
|
|
100
119
|
```
|
|
101
120
|
|
|
102
|
-
| Hook
|
|
103
|
-
|
|
121
|
+
| Hook | Returns |
|
|
122
|
+
| ------------------------------------------------ | ----------------------------------------------------------------------------------------------- |
|
|
104
123
|
| `useSlugAvailable(resolveRef, { slug, scope? })` | `{ available, resourceRef }` — `available` `undefined` while loading, `true` free, `false` held |
|
|
105
|
-
| `useResolve(resolveRef, { slug, scope? })`
|
|
124
|
+
| `useResolve(resolveRef, { slug, scope? })` | `resourceRef \| null \| undefined` (`undefined` while loading) |
|
|
125
|
+
|
|
126
|
+
Availability is a lookup hint, not a reservation or validation of length,
|
|
127
|
+
pattern, or reserved words. A concurrent claim can win; always check `reserve`'s
|
|
128
|
+
result. The example intentionally exposes public handles in the global scope
|
|
129
|
+
only.
|
|
106
130
|
|
|
107
131
|
## Security
|
|
108
132
|
|
|
109
|
-
- **Auth-agnostic** — the host authenticates the caller, decides who may claim a
|
|
110
|
-
|
|
111
|
-
- **
|
|
133
|
+
- **Auth-agnostic** — the host authenticates the caller, decides who may claim a
|
|
134
|
+
handle, and passes an opaque `resourceRef`.
|
|
135
|
+
- **Management authorization** — before `release` or `rename`, verify ownership
|
|
136
|
+
in the host. Authentication alone does not authorize changing another
|
|
137
|
+
subject's slug.
|
|
138
|
+
- **Opaque refs only** — `resourceRef` and `scope` are arbitrary strings; tables
|
|
139
|
+
are sandboxed (reached only via the client).
|
|
140
|
+
- **Boundary re-guard** — the component re-guards length at the trust boundary
|
|
141
|
+
even if a caller bypasses the client.
|
|
142
|
+
- **Uniqueness under concurrency** — each `reserve`/`rename` is one Convex
|
|
143
|
+
mutation (serializable): of simultaneous claims on a slug, one succeeds and
|
|
144
|
+
the rest get `SLUG_TAKEN`.
|
|
112
145
|
|
|
113
146
|
See [docs/API.md](docs/API.md).
|
|
114
147
|
|
|
@@ -119,7 +152,24 @@ pnpm test # single run
|
|
|
119
152
|
pnpm test:coverage # enforced 100% on covered files
|
|
120
153
|
```
|
|
121
154
|
|
|
122
|
-
Tests run against the real component runtime via `convex-test`
|
|
155
|
+
Tests run against the real component runtime via `convex-test`
|
|
156
|
+
(`@edge-runtime/vm`), not mocks.
|
|
157
|
+
|
|
158
|
+
### Testing your app
|
|
159
|
+
|
|
160
|
+
`@vllnt/convex-slugs/test` exports `register(t, name = "slugs")` to mount the
|
|
161
|
+
component in a `convex-test` instance. It needs `convex-test` and `vitest` (with
|
|
162
|
+
Vite's `import.meta.glob`) in the consuming app:
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
/// <reference types="vite/client" />
|
|
166
|
+
import { convexTest } from "convex-test";
|
|
167
|
+
import { register } from "@vllnt/convex-slugs/test";
|
|
168
|
+
import schema from "./schema";
|
|
169
|
+
|
|
170
|
+
const t = convexTest(schema, import.meta.glob("./**/*.ts"));
|
|
171
|
+
register(t);
|
|
172
|
+
```
|
|
123
173
|
|
|
124
174
|
## Contributing
|
|
125
175
|
|
|
@@ -127,9 +177,11 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
|
127
177
|
|
|
128
178
|
## Author
|
|
129
179
|
|
|
130
|
-
Built by [bntvllnt](https://github.com/bntvllnt) ·
|
|
180
|
+
Built by [bntvllnt](https://github.com/bntvllnt) ·
|
|
181
|
+
[bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
|
|
131
182
|
|
|
132
|
-
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet —
|
|
183
|
+
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet —
|
|
184
|
+
[vllnt.com](https://vllnt.com)
|
|
133
185
|
|
|
134
186
|
If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
|
|
135
187
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,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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B,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"}
|
package/dist/client/index.js
CHANGED
|
@@ -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
|
|
21
|
-
maxLength
|
|
33
|
+
minLength,
|
|
34
|
+
maxLength,
|
|
22
35
|
pattern: options.pattern,
|
|
23
|
-
|
|
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) {
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAO5C,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,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,kBAAkB,CAAC;QAC1D,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,kBAAkB,CAAC;QAC1D,IACE,IAAI,CAAC,YAAY,KAAK,EAAE;YACxB,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;YAC5B,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;YAC5B,SAAS,GAAG,CAAC;YACb,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,EAClC,CAAC;YACD,MAAM,IAAI,WAAW,CAAC;gBACpB,IAAI,EAAE,iBAAiB;gBACvB,OAAO,EACL,6IA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L,CAAC;IAED,+DAA+D;IAC/D,WAAW,CACT,GAAgB,EAChB,IAAY,EACZ,KAAc;QAEd,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,WAAW,EAAE;YACtD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAC1B,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;SACtB,CAAC,CAAC;IACL,CAAC;IAED,2DAA2D;IAC3D,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":"
|
|
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;
|
|
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,CAAC,MAAM,CAAC,SAAS,CAAC;YAClC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC;YAClC,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,CACrC,CAAC;IACJ,IAAI,KAAK,KAAK,EAAE,IAAI,WAAW,KAAK,EAAE,IAAI,SAAS,EAAE,CAAC;QACpD,MAAM,IAAI,WAAW,CAAC;Y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AAG,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"}
|
|
@@ -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
|
* 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,
|
|
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,wBAAwB,CAAC;AAE9D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,CAAC;IAC3B,IAAI,EAAE,EAAE,KAA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AAS,CAAC,eAAe,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;aAC5D,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF,CAAC,CAAC"}
|
package/dist/shared.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAEjF,eAAO,MAAM,cAAc,UAAU,CAAC;AAEtC,6DAA6D;AAC7D,eAAO,MAAM,aAAa,WAAW,CAAC;AAEtC,yDAAyD;AACzD,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAEpC,yDAAyD;AACzD,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC,iFAAiF;AACjF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC,iDAAiD;AACjD,MAAM,MAAM,UAAU,GAClB,YAAY,GACZ,gBAAgB,GAChB,cAAc,GACd,eAAe,CAAC;AAEpB;;;GAGG;AACH,MAAM,WAAW,eAAe;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,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAEjF,eAAO,MAAM,cAAc,UAAU,CAAC;AAEtC,6DAA6D;AAC7D,eAAO,MAAM,aAAa,WAAW,CAAC;AAEtC,yDAAyD;AACzD,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAEpC,yDAAyD;AACzD,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC,iFAAiF;AACjF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC,iDAAiD;AACjD,MAAM,MAAM,UAAU,GAClB,YAAY,GACZ,gBAAgB,GAChB,cAAc,GACd,eAAe,CAAC;AAEpB;;;GAGG;AACH,MAAM,WAAW,eAAe;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
|
}
|
package/dist/shared.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":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C;IACzB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vllnt/convex-slugs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-canary.22e5023",
|
|
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@
|
|
7
|
+
"packageManager": "pnpm@10.34.8",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
|
-
"src"
|
|
10
|
+
"src",
|
|
11
|
+
"!src/**/*.test.*"
|
|
11
12
|
],
|
|
12
13
|
"exports": {
|
|
13
14
|
"./package.json": "./package.json",
|
|
@@ -41,17 +42,14 @@
|
|
|
41
42
|
"build": "tsc --project ./tsconfig.build.json",
|
|
42
43
|
"build:codegen": "pnpm codegen && pnpm build",
|
|
43
44
|
"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 .",
|
|
45
|
+
"typecheck": "tsc --noEmit --incremental --tsBuildInfoFile node_modules/.cache/tsc/typecheck.tsbuildinfo",
|
|
46
|
+
"typecheck:ci": "tsc --noEmit --incremental --tsBuildInfoFile node_modules/.cache/tsc/typecheck-ci.tsbuildinfo --project tsconfig.ci.json",
|
|
47
|
+
"lint": "pnpm check:agents && eslint --cache --cache-location node_modules/.cache/eslint/ .",
|
|
47
48
|
"test": "vitest run --passWithNoTests",
|
|
48
49
|
"test:watch": "vitest --typecheck --clearScreen false",
|
|
49
50
|
"test:coverage": "vitest run --coverage --coverage.reporter=text",
|
|
50
51
|
"generate:llms": "node scripts/generate-llms.mjs",
|
|
51
52
|
"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
53
|
"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
54
|
"codegen": "pnpm convex codegen --component-dir ./src/component"
|
|
57
55
|
},
|
|
@@ -62,22 +60,22 @@
|
|
|
62
60
|
"devDependencies": {
|
|
63
61
|
"@edge-runtime/vm": "^5.0.0",
|
|
64
62
|
"@testing-library/react": "^16.3.3",
|
|
65
|
-
"@types/react": "^19.
|
|
66
|
-
"@types/react-dom": "^19.
|
|
63
|
+
"@types/react": "^19.3.0",
|
|
64
|
+
"@types/react-dom": "^19.3.0",
|
|
67
65
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
68
|
-
"@vitest/coverage-v8": "^
|
|
66
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
69
67
|
"@vllnt/eslint-config": "2.0.0",
|
|
70
68
|
"@vllnt/typescript": "2.0.0",
|
|
71
|
-
"convex": "^1.
|
|
72
|
-
"convex-test": "^0.0.
|
|
69
|
+
"convex": "^1.48.0",
|
|
70
|
+
"convex-test": "^0.0.65",
|
|
73
71
|
"eslint": "^9.39.5",
|
|
74
|
-
"jsdom": "^
|
|
75
|
-
"prettier": "^3.9.
|
|
76
|
-
"react": "^19.
|
|
77
|
-
"react-dom": "^19.
|
|
72
|
+
"jsdom": "^30.1.3",
|
|
73
|
+
"prettier": "^3.9.10",
|
|
74
|
+
"react": "^19.3.1",
|
|
75
|
+
"react-dom": "^19.3.1",
|
|
78
76
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
79
|
-
"vite": "^8.
|
|
80
|
-
"vitest": "^
|
|
77
|
+
"vite": "^8.3.5",
|
|
78
|
+
"vitest": "^5.0.5"
|
|
81
79
|
},
|
|
82
80
|
"homepage": "https://github.com/vllnt/convex-slugs#readme",
|
|
83
81
|
"bugs": {
|
|
@@ -111,5 +109,18 @@
|
|
|
111
109
|
"react": {
|
|
112
110
|
"optional": true
|
|
113
111
|
}
|
|
112
|
+
},
|
|
113
|
+
"pnpm": {
|
|
114
|
+
"overrides": {
|
|
115
|
+
"deepmerge-ts@<8.0.0": "^8.0.0",
|
|
116
|
+
"handlebars@<4.7.10": "^4.7.10"
|
|
117
|
+
},
|
|
118
|
+
"minimumReleaseAge": 10080,
|
|
119
|
+
"minimumReleaseAgeExclude": [
|
|
120
|
+
"@vllnt/*"
|
|
121
|
+
],
|
|
122
|
+
"ignoredBuiltDependencies": [
|
|
123
|
+
"esbuild"
|
|
124
|
+
]
|
|
114
125
|
}
|
|
115
126
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -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
|
|
104
|
-
maxLength
|
|
119
|
+
minLength,
|
|
120
|
+
maxLength,
|
|
105
121
|
pattern: options.pattern,
|
|
106
|
-
|
|
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) =>
|
package/src/component/queries.ts
CHANGED
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,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
|
-
});
|
package/src/react/index.test.tsx
DELETED
|
@@ -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
|
-
});
|