@klnap/payload-typeid 0.3.0 → 0.3.2
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 +12 -0
- package/README.md +174 -172
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- da89ab8: Revise the README: lead with a realistic quick example, state precedence and Globals behavior precisely, separate database guarantees, and document startup requirements and existing-database migration.
|
|
8
|
+
|
|
9
|
+
## 0.3.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 218a64b: Document and test that relationship and version rows reference managed TypeIDs through foreign keys, and state what the database guards cannot stop.
|
|
14
|
+
|
|
3
15
|
## 0.3.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,207 +1,223 @@
|
|
|
1
1
|
# @klnap/payload-typeid
|
|
2
2
|
|
|
3
|
-
Readable, type-prefixed document IDs for Payload CMS.
|
|
3
|
+
Readable, type-prefixed document IDs for Payload CMS.
|
|
4
4
|
|
|
5
5
|
```text
|
|
6
6
|
article_01m8d47saaepfr8kaw7mqdxs1h
|
|
7
|
+
author_01m8d47sabf8ca5x5s9smzr0qz
|
|
8
|
+
category_01m8d47sabeyjvrxppjadz5h5w
|
|
7
9
|
```
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
## Quick example
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Registering `typeId()` manages **every collection** with a TypeID prefix derived from its slug. You do not need to configure each collection. Opt out or override where needed.
|
|
14
|
-
|
|
15
|
-
| Collection | Without `typeId()` | With `typeId()` |
|
|
16
|
-
| -------------------------------------- | ------------------- | ------------------------------------ |
|
|
17
|
-
| `articles` | Payload's native ID | `article_01m8d47saaepfr8kaw7mqdxs1h` |
|
|
18
|
-
| `users` | Payload's native ID | `user_…` |
|
|
19
|
-
| `articles` with `custom.typeId: "art"` | Payload's native ID | `art_…` |
|
|
20
|
-
| `users` with `custom.typeId: false` | Payload's native ID | Payload's native ID |
|
|
21
|
-
|
|
22
|
-
Globals are not affected: they keep Payload's ID strategy.
|
|
23
|
-
|
|
24
|
-
**Upgrading an existing project is a data migration.** Every managed collection changes its ID type and its relationship columns. Existing documents keep their IDs until you migrate them. Before you register `typeId()` on a project with data, either migrate that data or set `custom.typeId: false` on each collection you do not want to change. See [Enabling on existing data](#enabling-on-existing-data).
|
|
25
|
-
|
|
26
|
-
## Installation
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
bun add @klnap/payload-typeid
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
npm install @klnap/payload-typeid
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Quick start
|
|
13
|
+
Register the plugin. Each collection gets a prefix from its slug, with no per-collection configuration:
|
|
37
14
|
|
|
38
15
|
```ts
|
|
16
|
+
// payload.config.ts
|
|
39
17
|
import { buildConfig, type CollectionConfig } from "payload";
|
|
40
18
|
import { typeId } from "@klnap/payload-typeid";
|
|
41
19
|
|
|
42
|
-
const
|
|
43
|
-
slug: "
|
|
44
|
-
fields: [],
|
|
20
|
+
const Categories: CollectionConfig = {
|
|
21
|
+
slug: "categories",
|
|
22
|
+
fields: [{ name: "title", type: "text", required: true }],
|
|
45
23
|
};
|
|
46
24
|
|
|
47
|
-
const
|
|
48
|
-
slug: "
|
|
49
|
-
fields: [],
|
|
25
|
+
const Authors: CollectionConfig = {
|
|
26
|
+
slug: "authors",
|
|
27
|
+
fields: [{ name: "name", type: "text", required: true }],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const Articles: CollectionConfig = {
|
|
31
|
+
slug: "articles",
|
|
32
|
+
fields: [
|
|
33
|
+
{ name: "title", type: "text", required: true },
|
|
34
|
+
{ name: "category", type: "relationship", relationTo: "categories", required: true },
|
|
35
|
+
{ name: "author", type: "relationship", relationTo: "authors", required: true },
|
|
36
|
+
],
|
|
50
37
|
};
|
|
51
38
|
|
|
52
39
|
export default buildConfig({
|
|
53
|
-
|
|
40
|
+
// database, secret, editor, and the rest of your configuration
|
|
41
|
+
collections: [Categories, Authors, Articles],
|
|
54
42
|
plugins: [typeId()],
|
|
55
43
|
});
|
|
56
44
|
```
|
|
57
45
|
|
|
58
|
-
|
|
46
|
+
Use the normal Payload API. Relationships take the related document's `id`:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
const category = await payload.create({ collection: "categories", data: { title: "Guides" } });
|
|
50
|
+
const author = await payload.create({ collection: "authors", data: { name: "Ada" } });
|
|
51
|
+
|
|
52
|
+
const article = await payload.create({
|
|
53
|
+
collection: "articles",
|
|
54
|
+
data: { title: "Getting started", category: category.id, author: author.id },
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
article.id; // for example "article_01m8d47saaepfr8kaw7mqdxs1h"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The ID is the document's only identifier. There is no second public ID field and no lookup table.
|
|
59
61
|
|
|
60
|
-
##
|
|
62
|
+
## Why?
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
Payload's default IDs do not show what kind of record an ID refers to in logs, URLs, or API responses. Projects sometimes add a second, readable identifier for that purpose, which duplicates the key and needs translation. This package keeps one identifier: the readable prefix is part of the native Payload ID.
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
- adds a `beforeChange` hook that keeps the generated ID on create, keeps the stored ID on update, and generates a fresh ID on duplicate;
|
|
66
|
-
- adds a `beforeOperation` guard that rejects `customID` and `data.id` on create and `data.id` on update, because the plugin owns the ID.
|
|
66
|
+
## Features
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
- **Native IDs.** Managed collections use Payload's text ID field. Existing APIs and relationships work unchanged.
|
|
69
|
+
- **Automatic prefixes.** Each collection's prefix comes from its slug, singularized with Payload's own `formatLabels`.
|
|
70
|
+
- **Overrides.** Set a prefix per collection, opt a collection out, or configure all of them in one place.
|
|
71
|
+
- **ID ownership.** IDs are generated on create and duplicate. Callers cannot supply or change them through Payload operations.
|
|
72
|
+
- **PostgreSQL guards.** Triggers and a `CHECK` constraint apply the same rules to raw SQL writes.
|
|
73
|
+
- **Utilities.** Generate, validate, parse, and convert TypeIDs. No runtime dependencies.
|
|
74
|
+
|
|
75
|
+
## Installation
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
bun add @klnap/payload-typeid
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm install @klnap/payload-typeid
|
|
83
|
+
```
|
|
69
84
|
|
|
70
85
|
## Configuration
|
|
71
86
|
|
|
72
|
-
|
|
87
|
+
### Prefixes
|
|
88
|
+
|
|
89
|
+
Each collection's prefix is resolved in this order. The first defined value wins:
|
|
73
90
|
|
|
74
91
|
1. `custom.typeId` on the collection.
|
|
75
|
-
2. The central `
|
|
76
|
-
3. The
|
|
92
|
+
2. The central `collections` option passed to `typeId()`.
|
|
93
|
+
3. The automatic prefix from the slug.
|
|
77
94
|
|
|
78
|
-
|
|
95
|
+
`custom.typeId` accepts:
|
|
79
96
|
|
|
80
|
-
| Value | Effect
|
|
81
|
-
| ------- |
|
|
82
|
-
| `"art"` | Use
|
|
83
|
-
| `true` |
|
|
84
|
-
| `false` | Opt out: keep Payload's native ID strategy
|
|
85
|
-
| omitted | Use the central
|
|
97
|
+
| Value | Effect |
|
|
98
|
+
| ------- | -------------------------------------------------------------------------- |
|
|
99
|
+
| `"art"` | Use this exact prefix. |
|
|
100
|
+
| `true` | Use the automatic prefix, even when the central option sets another value. |
|
|
101
|
+
| `false` | Opt out: keep Payload's native ID strategy. |
|
|
102
|
+
| omitted | Use the central option, or the automatic prefix. |
|
|
86
103
|
|
|
87
|
-
|
|
104
|
+
Configure a whole project in one place with the same values:
|
|
88
105
|
|
|
89
106
|
```ts
|
|
90
107
|
typeId({
|
|
91
108
|
collections: {
|
|
92
109
|
articles: "article",
|
|
93
|
-
authors: "
|
|
94
|
-
|
|
110
|
+
authors: "author",
|
|
111
|
+
categories: false,
|
|
95
112
|
},
|
|
96
113
|
});
|
|
97
114
|
```
|
|
98
115
|
|
|
99
|
-
|
|
116
|
+
Precedence for each combination of collection-level and central values:
|
|
100
117
|
|
|
101
|
-
|
|
118
|
+
| `custom.typeId` | Central value | Result |
|
|
119
|
+
| --------------- | ------------- | ------------------- |
|
|
120
|
+
| omitted | omitted | Automatic prefix |
|
|
121
|
+
| `true` | omitted | Automatic prefix |
|
|
122
|
+
| `true` | `"article"` | Automatic prefix |
|
|
123
|
+
| `true` | `false` | Automatic prefix |
|
|
124
|
+
| `"art"` | `"article"` | `art` |
|
|
125
|
+
| `"art"` | `false` | `art` |
|
|
126
|
+
| omitted | `"article"` | `article` |
|
|
127
|
+
| omitted | `false` | Native ID (opt-out) |
|
|
128
|
+
| `false` | `"article"` | Native ID (opt-out) |
|
|
129
|
+
| `false` | `true` | Native ID (opt-out) |
|
|
102
130
|
|
|
103
|
-
|
|
104
|
-
| -------------------------- | ------------- | -------------------------------- |
|
|
105
|
-
| `"art"` | `"article"` | `art_…` |
|
|
106
|
-
| omitted | `"article"` | `article_…` |
|
|
107
|
-
| `false` | `"article"` | Native ID (opt-out) |
|
|
108
|
-
| omitted | `false` | Native ID (opt-out) |
|
|
109
|
-
| omitted | omitted | Derived prefix, e.g. `article_…` |
|
|
131
|
+
Central keys must be collection slugs in `config.collections`. An unknown key throws during setup.
|
|
110
132
|
|
|
111
|
-
|
|
133
|
+
### Automatic prefixes
|
|
112
134
|
|
|
113
|
-
|
|
135
|
+
Automatic prefixes use the slug, with the last word singularized by Payload's `formatLabels`:
|
|
114
136
|
|
|
115
|
-
|
|
137
|
+
| Collection slug | Prefix |
|
|
138
|
+
| ----------------- | ---------------- |
|
|
139
|
+
| `articles` | `article` |
|
|
140
|
+
| `authors` | `author` |
|
|
141
|
+
| `categories` | `category` |
|
|
142
|
+
| `article-authors` | `article_author` |
|
|
116
143
|
|
|
117
|
-
|
|
144
|
+
Automatic prefixes are convenient but follow Payload's English rules. Set an explicit prefix when a name is irregular, when it is domain-specific, or when the prefix is a stable part of your API. An explicit prefix must be 1–63 lowercase ASCII letters or underscores, starting and ending with a letter.
|
|
118
145
|
|
|
119
|
-
`
|
|
146
|
+
The plugin rejects a slug whose label cannot be split into words reliably (for example `APIKeys` or `users-2fa`). Those collections need an explicit prefix or `false`.
|
|
120
147
|
|
|
121
|
-
|
|
148
|
+
Two managed collections that resolve to the same prefix are rejected during setup. Changing a prefix does not change existing IDs; see [Existing databases](#existing-databases).
|
|
122
149
|
|
|
123
|
-
|
|
150
|
+
### Globals
|
|
124
151
|
|
|
125
|
-
|
|
126
|
-
2. Pass the result through `formatLabels`, which singularizes the last word.
|
|
127
|
-
3. Join the words with `_` and lowercase the result.
|
|
152
|
+
TypeIDs apply to collections only. Globals are accessed by slug and keep Payload's native behavior, so no configuration is needed. Setting `custom.typeId` to `false` on a Global is allowed. Setting it to `true` or to a prefix string throws during setup.
|
|
128
153
|
|
|
129
|
-
|
|
154
|
+
### Obsolete key
|
|
130
155
|
|
|
131
|
-
|
|
132
|
-
| ----------------- | ---------------- |
|
|
133
|
-
| `articles` | `article` |
|
|
134
|
-
| `article-authors` | `article_author` |
|
|
135
|
-
| `ArticleAuthors` | `article_author` |
|
|
136
|
-
| `audit-logs` | `audit_log` |
|
|
137
|
-
| `users` | `user` |
|
|
156
|
+
Use `custom.typeId`. The obsolete `custom.typeid` spelling is rejected on collections and Globals.
|
|
138
157
|
|
|
139
|
-
|
|
158
|
+
## ID ownership
|
|
140
159
|
|
|
141
|
-
|
|
142
|
-
| -------- | -------------- | ---------------------------------------------------------- |
|
|
143
|
-
| `people` | `person` | Acceptable. Set `"person"` if you prefer an explicit name. |
|
|
144
|
-
| `data` | `datum` | Set an explicit prefix such as `"dataset"`. |
|
|
145
|
-
| `dice` | `die` | Set an explicit prefix such as `"roll"`. |
|
|
160
|
+
For managed collections, the plugin owns the ID:
|
|
146
161
|
|
|
147
|
-
|
|
162
|
+
- **Create** generates a TypeID. Passing `id`, `data.id`, or `customID` throws.
|
|
163
|
+
- **Update** cannot change the ID. Passing `data.id` throws.
|
|
164
|
+
- **Duplicate** creates a new TypeID with the same prefix. The original keeps its ID.
|
|
148
165
|
|
|
149
|
-
|
|
166
|
+
These rules apply to Payload operations. Raw SQL writes are covered by the database guards below.
|
|
150
167
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
168
|
+
```ts
|
|
169
|
+
const copy = await payload.duplicate({ collection: "articles", id: article.id });
|
|
170
|
+
copy.id !== article.id; // true
|
|
171
|
+
```
|
|
155
172
|
|
|
156
|
-
|
|
173
|
+
Payload's `idType` setting for the database adapter does not need to change.
|
|
157
174
|
|
|
158
|
-
|
|
175
|
+
## Database guards (PostgreSQL)
|
|
159
176
|
|
|
160
|
-
|
|
177
|
+
For each managed table, the plugin installs database-level rules when Payload starts. They apply to any write to that table, including raw SQL:
|
|
161
178
|
|
|
162
|
-
|
|
179
|
+
| Guarantee | Provided by |
|
|
180
|
+
| ---------------------- | --------------------------------------------------------------- |
|
|
181
|
+
| ID generation | A trigger that creates an ID when an `INSERT` has none. |
|
|
182
|
+
| Format validation | A `CHECK` constraint on the prefix and the 26-character suffix. |
|
|
183
|
+
| Immutability | A trigger that rejects an `UPDATE` changing `id`. |
|
|
184
|
+
| Primary-key uniqueness | Payload's `PRIMARY KEY (id)`. |
|
|
185
|
+
| Referential integrity | Foreign keys from relationship and version tables to `id`. |
|
|
163
186
|
|
|
164
|
-
|
|
187
|
+
Notes:
|
|
165
188
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
189
|
+
- A generated ID is a UUIDv7 in TypeID form. The generator follows RFC 9562 and matches `generateTypeId`.
|
|
190
|
+
- The `CHECK` validates the prefix and the suffix's characters and length. It does not verify the UUID version or variant bits.
|
|
191
|
+
- A correctly formatted ID supplied in a raw `INSERT` is accepted. Payload operations reject supplied IDs; the database does not.
|
|
192
|
+
- The guards cover managed tables only, not other tables in the database.
|
|
193
|
+
- Versions and relationship tables are protected through their foreign keys to the managed `id` columns, not through their own triggers.
|
|
171
194
|
|
|
172
|
-
|
|
173
|
-
```
|
|
195
|
+
### Startup requirements
|
|
174
196
|
|
|
175
|
-
|
|
197
|
+
Guard installation runs when Payload starts, as a single SQL script:
|
|
176
198
|
|
|
177
|
-
|
|
199
|
+
- Each managed table must already exist. The plugin reports a missing table.
|
|
200
|
+
- The database role must be allowed to create functions and triggers and to alter the tables.
|
|
201
|
+
- Existing rows must satisfy the `CHECK`. If they do not, startup fails and no guard is installed. Migrate those rows first.
|
|
202
|
+
- The functions use `gen_random_uuid()`, built into PostgreSQL 13 and later.
|
|
178
203
|
|
|
179
|
-
|
|
204
|
+
These requirements follow from the implementation. They are not covered by a test that changes database privileges or inserts non-matching legacy rows.
|
|
180
205
|
|
|
181
|
-
|
|
206
|
+
### What the guards cannot stop
|
|
182
207
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
copy.id.startsWith("article_"); // true
|
|
187
|
-
```
|
|
208
|
+
A superuser can disable triggers or constraints. `DROP`, `TRUNCATE`, and restoring an older backup bypass all rules. Keep those privileges with migrations and operators.
|
|
209
|
+
|
|
210
|
+
## Existing databases
|
|
188
211
|
|
|
189
|
-
|
|
212
|
+
Enabling TypeIDs on a populated database is a migration, not a configuration change:
|
|
190
213
|
|
|
191
|
-
|
|
214
|
+
- Existing IDs and relationship values are not converted.
|
|
215
|
+
- The ID column type of managed tables and of the references to them changes.
|
|
216
|
+
- Startup fails if existing rows do not match the `CHECK`.
|
|
192
217
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
| `Invalid TypeID configuration ... custom.typeId must be true, false, a prefix string` | The value has another type. Use one of the accepted values. |
|
|
197
|
-
| `Collection "x" cannot derive a TypeID prefix from its slug` | The slug is ambiguous. Set `custom.typeId` to an explicit string, or `false`. |
|
|
198
|
-
| `Collections "a" and "b" resolve to duplicate TypeID prefix` | Two collections share a prefix. Set an explicit prefix on one of them. |
|
|
199
|
-
| `Global "x" cannot use custom.typeId` | Globals accept only `false` or omission. |
|
|
200
|
-
| `TypeID collections references unknown collection` | A central key is not a collection slug in `config.collections`. |
|
|
201
|
-
| `Collection "x" already has a collection-level field named "id"` | Rename that field, or set `custom.typeId: false` on the collection. |
|
|
202
|
-
| `Collection "x" owns its IDs; omit customID and data.id when creating` | Remove `customID` and `data.id` from the create call. |
|
|
203
|
-
| `Collection "x" IDs are immutable; omit data.id when updating` | Remove `data.id` from the update call. |
|
|
204
|
-
| `Register typeId() only once` | Keep a single `typeId()` entry in `plugins`. |
|
|
218
|
+
To keep a collection on its native IDs, set `custom.typeId: false` before the first start with the plugin.
|
|
219
|
+
|
|
220
|
+
After the plugin has activated on a database, setting `custom.typeId: false` does not restore column types, convert IDs, rewrite references, or remove guards.
|
|
205
221
|
|
|
206
222
|
## Utilities
|
|
207
223
|
|
|
@@ -216,60 +232,46 @@ import {
|
|
|
216
232
|
} from "@klnap/payload-typeid";
|
|
217
233
|
|
|
218
234
|
const id: TypeID<"article"> = generateTypeId("article");
|
|
235
|
+
|
|
236
|
+
isTypeId(id); // true
|
|
219
237
|
isTypeId(id, "article"); // true
|
|
220
|
-
isTypeId(id, "
|
|
238
|
+
isTypeId(id, "author"); // false
|
|
221
239
|
|
|
222
|
-
const uuid =
|
|
223
|
-
|
|
240
|
+
const uuid = parseTypeId(id).uuid; // canonical UUID string
|
|
241
|
+
fromUUID("article", uuid) === id; // true
|
|
242
|
+
toUUID(id) === uuid; // true
|
|
224
243
|
```
|
|
225
244
|
|
|
226
|
-
| Export | Description
|
|
227
|
-
| ---------------------------------- |
|
|
228
|
-
| `
|
|
229
|
-
| `
|
|
230
|
-
| `
|
|
231
|
-
| `
|
|
232
|
-
| `
|
|
233
|
-
| `
|
|
234
|
-
| `
|
|
235
|
-
| `TypeIdOptions` | Options accepted by `typeId()`. |
|
|
245
|
+
| Export | Description |
|
|
246
|
+
| ---------------------------------- | ---------------------------------------------------------------------------- |
|
|
247
|
+
| `generateTypeId(prefix)` | Returns a TypeID with a new UUIDv7. |
|
|
248
|
+
| `isTypeId(value, expectedPrefix?)` | Runtime check that `value` is a valid TypeID, optionally with that prefix. |
|
|
249
|
+
| `parseTypeId(value)` | Returns `{ prefix, uuid }`. Throws `TypeError` on invalid input. |
|
|
250
|
+
| `fromUUID(prefix, uuid)` | Encodes a canonical UUID as a TypeID. Accepts UUIDs of any version. |
|
|
251
|
+
| `toUUID(value)` | Returns the canonical UUID of a TypeID. Throws `TypeError` on invalid input. |
|
|
252
|
+
| `TypeID<Prefix>` | Compile-time string type. It does not validate values at runtime. |
|
|
253
|
+
| `TypeIdOptions` | The options type for `typeId()`. |
|
|
236
254
|
|
|
237
|
-
`
|
|
255
|
+
`TypeID<Prefix>` documents intent in your types. Use `isTypeId` to check untrusted input. Generated Payload document types do not know which prefix a collection uses.
|
|
238
256
|
|
|
239
|
-
##
|
|
240
|
-
|
|
241
|
-
Registering `typeId()` on a project with data changes the ID column type of every managed collection and of every relationship that points to it. Existing IDs and relationship values are not migrated automatically.
|
|
242
|
-
|
|
243
|
-
Choose one before you deploy:
|
|
244
|
-
|
|
245
|
-
1. **Migrate.** Back up the database. Write a migration that assigns a TypeID to each existing document and rewrites relationship values to match. Deploy it together with the plugin.
|
|
246
|
-
2. **Opt out.** Set `custom.typeId: false` on each existing collection you do not want to change. Only new collections get TypeIDs.
|
|
247
|
-
|
|
248
|
-
The database guards below run on writes that bypass Payload hooks. Existing data that does not match them blocks startup until it is migrated.
|
|
249
|
-
|
|
250
|
-
## Database guards (PostgreSQL)
|
|
251
|
-
|
|
252
|
-
Payload hooks do not run for raw SQL, so the plugin installs the ID rules in the database as well. For each managed table, on every Payload start:
|
|
257
|
+
## Compatibility
|
|
253
258
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
259
|
+
| Area | Support |
|
|
260
|
+
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
261
|
+
| Payload | Peer range `^3.1.1`. PostgreSQL integration tests run on `3.1.1`, `3.68.4`, `3.71.0`, and the development version (currently `3.94.2`). Other 3.x versions are not tested. Payload 4 is unverified. |
|
|
262
|
+
| Database | PostgreSQL integration tests run on PostgreSQL 16, with the default serial ID strategy and `idType: "uuid"`. Guards are PostgreSQL-only; other adapters log a warning and keep application-level rules. |
|
|
263
|
+
| Node.js | `>=22.14.0`. Payload's own engine requirements also apply. |
|
|
264
|
+
| Module format | ESM only. |
|
|
257
265
|
|
|
258
|
-
|
|
266
|
+
## Security
|
|
259
267
|
|
|
260
|
-
|
|
261
|
-
- **Existing data.** The `CHECK` applies to all rows. If a managed table already holds IDs that do not match, startup fails and no guard is installed. Migrate those rows first (see [Enabling on existing data](#enabling-on-existing-data)).
|
|
262
|
-
- **Scope.** Versions tables (`_<table>_v`) and relationship join tables are not guarded; their IDs belong to Payload.
|
|
263
|
-
- **Fields.** The guards check only `id`. Other constraints and field rules are not changed.
|
|
268
|
+
TypeIDs identify documents. They do not authenticate users or authorize access. Use Payload's access control and your application's authorization for every operation. The UUIDv7 part includes a timestamp, and the prefix reveals the record type, so do not treat IDs as secrets.
|
|
264
269
|
|
|
265
|
-
##
|
|
270
|
+
## Documentation
|
|
266
271
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
| Database | PostgreSQL 16, with the default serial strategy and `idType: "uuid"`. Other adapters are unverified. |
|
|
271
|
-
| Node.js | `>=22.14.0`. Payload's own engine range applies too; Payload `3.94.2` requires `^22.23.5 \|\| ^24.22.3 \|\| >=26.13.1`. |
|
|
272
|
-
| Module format | ESM only. |
|
|
272
|
+
- [Payload custom ID fields](https://payloadcms.com/docs/fields/default-fields#custom-id-fields)
|
|
273
|
+
- [RFC 9562, UUIDv7](https://www.rfc-editor.org/rfc/rfc9562.html#section-5.7)
|
|
274
|
+
- [TypeID format specification](https://github.com/jetify-com/typeid/blob/main/spec/README.md), which this package's encoding follows
|
|
273
275
|
|
|
274
276
|
## License
|
|
275
277
|
|