@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.
Files changed (3) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +174 -172
  3. 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. An ID is a prefix plus a UUIDv7 in a compact suffix:
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
- It is the document's one native Payload ID. The package adds no second identifier and no runtime dependencies.
11
+ ## Quick example
10
12
 
11
- ## What changes
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 Articles: CollectionConfig = {
43
- slug: "articles",
44
- fields: [],
20
+ const Categories: CollectionConfig = {
21
+ slug: "categories",
22
+ fields: [{ name: "title", type: "text", required: true }],
45
23
  };
46
24
 
47
- const Users: CollectionConfig = {
48
- slug: "users",
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
- collections: [Articles, Users],
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
- `articles` gets `article_…` IDs and `users` gets `user_…` IDs, with no per-collection configuration. Register `typeId()` after plugins that add collections, so it sees the final collection list.
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
- ## How it works
62
+ ## Why?
61
63
 
62
- The plugin uses Payload's native custom ID mechanism, a top-level field named `id`. It does not change the database adapter. For each managed collection, it:
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
- - prepends an `id` text field whose `defaultValue` generates a TypeID with the collection's prefix;
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
- The plugin runs last (`order` is the maximum), so its `id` field and hooks apply after other plugins.
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
- Each collection's prefix is resolved in this order. The first value that is set wins:
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 `typeId({ collections })` entry for its slug.
76
- 3. The default: a prefix derived from the slug.
92
+ 2. The central `collections` option passed to `typeId()`.
93
+ 3. The automatic prefix from the slug.
77
94
 
78
- ### On the collection: `custom.typeId`
95
+ `custom.typeId` accepts:
79
96
 
80
- | Value | Effect |
81
- | ------- | ----------------------------------------------------------------------------- |
82
- | `"art"` | Use exactly this prefix. Use it when the derived prefix is not what you want. |
83
- | `true` | Derive the prefix from the slug. Same as omitting the value. |
84
- | `false` | Opt out: keep Payload's native ID strategy for this collection. |
85
- | omitted | Use the central entry, or derive the prefix from the slug. |
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
- ### Centrally: `typeId({ collections })`
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: "writer",
94
- users: false,
110
+ authors: "author",
111
+ categories: false,
95
112
  },
96
113
  });
97
114
  ```
98
115
 
99
- Keys are collection slugs that must exist in `config.collections`. An unknown slug throws during setup. A central value applies only when the collection's `custom.typeId` is omitted.
116
+ Precedence for each combination of collection-level and central values:
100
117
 
101
- ### Examples
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
- | Collection `custom.typeId` | Central entry | Result |
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
- A collection-level value always wins. `false` at either level opts the collection out.
133
+ ### Automatic prefixes
112
134
 
113
- ### Globals
135
+ Automatic prefixes use the slug, with the last word singularized by Payload's `formatLabels`:
114
136
 
115
- Globals keep Payload's ID strategy. They accept only `false` or omission. `true` or a prefix string on a Global throws during setup, because Payload does not expose configurable Global document IDs.
137
+ | Collection slug | Prefix |
138
+ | ----------------- | ---------------- |
139
+ | `articles` | `article` |
140
+ | `authors` | `author` |
141
+ | `categories` | `category` |
142
+ | `article-authors` | `article_author` |
116
143
 
117
- ### Obsolete key
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
- `custom.typeid` (lowercase `d`) throws on collections and Globals. Rename it to `custom.typeId`.
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
- ## Prefix derivation
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
- When no explicit prefix applies, the prefix comes from the slug with Payload's own singularization, `formatLabels` from `payload`, the same function Payload uses for admin labels:
150
+ ### Globals
124
151
 
125
- 1. Replace `_` with `-` in the slug, so underscores and hyphens both separate words.
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
- Regular plural nouns derive cleanly:
154
+ ### Obsolete key
130
155
 
131
- | Slug | Derived prefix |
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
- Irregular or uncountable names derive to correct English that may read oddly in an ID. Payload's English rules decide the result:
158
+ ## ID ownership
140
159
 
141
- | Slug | Derived prefix | Recommendation |
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
- Derivation depends on Payload's English rules. A future Payload release could change a derived prefix, and new IDs would follow the new rule. Set explicit prefixes for any collection whose IDs you store, log, or expose.
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
- The plugin rejects a slug whose label contains characters other than letters, or whose multi-word label contains a single letter, because those cannot be split reliably. Because derivation is the default, such a slug fails setup for the whole project until you set a prefix or `false` on it:
166
+ These rules apply to Payload operations. Raw SQL writes are covered by the database guards below.
150
167
 
151
- | Slug | Result |
152
- | ----------- | ----------------------------------------------- |
153
- | `APIKeys` | Rejected. The label splits into single letters. |
154
- | `users-2fa` | Rejected. The label contains a digit. |
168
+ ```ts
169
+ const copy = await payload.duplicate({ collection: "articles", id: article.id });
170
+ copy.id !== article.id; // true
171
+ ```
155
172
 
156
- ## Prefix rules
173
+ Payload's `idType` setting for the database adapter does not need to change.
157
174
 
158
- Explicit prefixes must be 1–63 lowercase ASCII letters or underscores, starting and ending with a letter. Two managed collections that resolve to the same prefix throw during setup, so give one of them an explicit prefix.
175
+ ## Database guards (PostgreSQL)
159
176
 
160
- A managed collection cannot define its own top-level field named `id`. Either set `custom.typeId: false` on it or rename that field before enabling TypeIDs.
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
- ## Using IDs
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
- Create and read documents as usual. Do not pass `id` or `customID`:
187
+ Notes:
165
188
 
166
- ```ts
167
- const article = await payload.create({
168
- collection: "articles",
169
- data: { title: "Getting started with Payload CMS" },
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
- await payload.findByID({ collection: "articles", id: article.id });
173
- ```
195
+ ### Startup requirements
174
196
 
175
- Passing `customID` or `data.id` on create throws. Passing `data.id` on update throws, because the ID does not change.
197
+ Guard installation runs when Payload starts, as a single SQL script:
176
198
 
177
- Relationships use the native ID. Set `relationTo` as usual and pass the related document's `id`.
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
- ### Duplicating documents
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
- `payload.duplicate()` gives the copy a **new** TypeID with the same prefix. The original keeps its ID. The repository's PostgreSQL integration test checks this on every supported Payload version.
206
+ ### What the guards cannot stop
182
207
 
183
- ```ts
184
- const copy = await payload.duplicate({ collection: "articles", id: article.id });
185
- copy.id !== article.id; // true
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
- ### Errors
212
+ Enabling TypeIDs on a populated database is a migration, not a configuration change:
190
213
 
191
- Setup and write errors come from the plugin. Each message names the fix:
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
- | Message (starts with) | Cause and fix |
194
- | ------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
195
- | `... uses the obsolete custom.typeid key` | Rename `custom.typeid` to `custom.typeId`. |
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, "category"); // false
238
+ isTypeId(id, "author"); // false
221
239
 
222
- const uuid = "0188bac7-4afa-78aa-bc3b-bd1eef28d881";
223
- toUUID(fromUUID("article", uuid)) === uuid; // true
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
- | `typeId(options?)` | Creates the Payload plugin. |
229
- | `generateTypeId(prefix)` | Generates a TypeID with a new UUIDv7. |
230
- | `isTypeId(value, expectedPrefix?)` | Validates a TypeID and optionally its prefix. |
231
- | `parseTypeId(value)` | Returns the prefix and canonical UUID. |
232
- | `fromUUID(prefix, uuid)` | Encodes a canonical UUID as a TypeID. |
233
- | `toUUID(value)` | Converts a TypeID to its canonical UUID. |
234
- | `TypeID<Prefix>` | Compile-time type. Not runtime validation. |
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
- `parseTypeId`, `fromUUID`, and `toUUID` throw `TypeError` on invalid input. `isTypeId` returns `false`.
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
- ## Enabling on existing data
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
- - **Generation:** an `INSERT` without `id` receives a TypeID with the table's prefix. The SQL encoder matches `generateTypeId`, and the test suite checks that the two agree.
255
- - **Validation:** a `CHECK` constraint rejects any `id` that is not `prefix_` followed by 26 Base32 characters, with the first character in `0`–`7`. A wrong prefix is rejected too.
256
- - **Immutability:** a trigger rejects any `UPDATE` that changes `id`. Other columns can still be updated.
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
- The guards are idempotent and survive a repeated `push`; the test suite runs twice against the same database to check this. Limits:
266
+ ## Security
259
267
 
260
- - **PostgreSQL only.** Other adapters log a warning at startup and keep only application-level rules.
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
- ## Compatibility
270
+ ## Documentation
266
271
 
267
- | Area | Support |
268
- | ------------- | ----------------------------------------------------------------------------------------------------------------------------- |
269
- | Payload CMS | Peer range `^3.1.1`. PostgreSQL integration tests pass on `3.1.1`, `3.68.4`, `3.71.0`, and `3.94.2`. Payload 4 is unverified. |
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@klnap/payload-typeid",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Type-prefixed UUIDv7 primary keys for Payload CMS.",
5
5
  "type": "module",
6
6
  "private": false,