@warlock.js/cascade 4.2.11 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/llms-full.txt +20 -1
- package/package.json +4 -4
- package/skills/define-model/SKILL.md +20 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,11 @@ All notable changes to `@warlock.js/cascade` are documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `@warlock.js/*` packages are released in lockstep — every package shares the same version number, so a version below may list only the changes that affected this package.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## 4.4.0 - 2026-06-21
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- **Documented `model.uuid`** — clarified that the accessor returns the model's primary id as `string` (where `model.id` is `string | number`); the name is historical and performs no UUID validation or coercion.
|
|
8
12
|
|
|
9
13
|
## 4.2.11
|
|
10
14
|
|
package/llms-full.txt
CHANGED
|
@@ -925,16 +925,35 @@ export class User extends Model<UserSchema> {
|
|
|
925
925
|
- `static table` matches the migration. Plural, lowercase, snake_case is the convention on both drivers.
|
|
926
926
|
- `static schema` attaches the validator. On every `save()`, the data goes through `userSchema` before it hits the database.
|
|
927
927
|
|
|
928
|
-
## Read state — `.id
|
|
928
|
+
## Read state — `.id`, `.uuid`, and `.get(field)`
|
|
929
929
|
|
|
930
930
|
```ts
|
|
931
931
|
user.id; // direct property — ID is so common cascade exposes it directly
|
|
932
|
+
user.uuid; // the same id, narrowed to `string` (see below)
|
|
932
933
|
user.get("status"); // canonical reader for every other column
|
|
933
934
|
user.get<number>("age"); // TypeScript generic for typed reads
|
|
934
935
|
```
|
|
935
936
|
|
|
936
937
|
Use the direct `.id` property; use `.get("field")` for everything else. Add a typed getter on the model class when the same field is read in many places — turns N typed-cast call sites into one named accessor.
|
|
937
938
|
|
|
939
|
+
### `.id` vs `.uuid` — a TypeScript convenience, same value
|
|
940
|
+
|
|
941
|
+
Both getters return the model's primary id (`this.get("id")`); the only difference is the **static type**:
|
|
942
|
+
|
|
943
|
+
| Accessor | Return type | Use when |
|
|
944
|
+
|---|---|---|
|
|
945
|
+
| `model.id` | `string \| number` | You want the real id type — SQL auto-increment is `number`, MongoDB's ObjectId is `string`. |
|
|
946
|
+
| `model.uuid` | `string` | You want to pass the id to code typed for a single `string` id, without leaking the engine's `string \| number` union everywhere. |
|
|
947
|
+
|
|
948
|
+
`uuid` does **not** validate or coerce the value to a UUID — the name is historical. It simply returns the same id, typed as `string`, so a helper typed for a string id accepts it on either engine:
|
|
949
|
+
|
|
950
|
+
```ts
|
|
951
|
+
function shareLink(modelId: string) { /* ... */ }
|
|
952
|
+
|
|
953
|
+
shareLink(user.uuid); // ✓ typechecks on both Postgres and MongoDB
|
|
954
|
+
shareLink(user.id); // ✗ TS error on SQL: `number` is not assignable to `string`
|
|
955
|
+
```
|
|
956
|
+
|
|
938
957
|
## Write — three update idioms
|
|
939
958
|
|
|
940
959
|
Cascade gives you three ways to update an instance. Knowing when each fits saves you from reaching for the wrong one.
|
package/package.json
CHANGED
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"@mongez/events": "^2.2.6",
|
|
28
28
|
"@mongez/reinforcements": "^3.3.0",
|
|
29
29
|
"@mongez/supportive-is": "^2.1.3",
|
|
30
|
-
"@warlock.js/context": "4.
|
|
31
|
-
"@warlock.js/logger": "4.
|
|
32
|
-
"@warlock.js/seal": "4.
|
|
30
|
+
"@warlock.js/context": "4.4.0",
|
|
31
|
+
"@warlock.js/logger": "4.4.0",
|
|
32
|
+
"@warlock.js/seal": "4.4.0",
|
|
33
33
|
"citty": "^0.2.2",
|
|
34
34
|
"fast-glob": "^3.3.3"
|
|
35
35
|
},
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"bin": {
|
|
41
41
|
"cascade": "bin/cascade.js"
|
|
42
42
|
},
|
|
43
|
-
"version": "4.
|
|
43
|
+
"version": "4.4.0",
|
|
44
44
|
"main": "./cjs/index.cjs",
|
|
45
45
|
"module": "./esm/index.mjs",
|
|
46
46
|
"types": "./esm/index.d.mts",
|
|
@@ -45,16 +45,35 @@ export class User extends Model<UserSchema> {
|
|
|
45
45
|
- `static table` matches the migration. Plural, lowercase, snake_case is the convention on both drivers.
|
|
46
46
|
- `static schema` attaches the validator. On every `save()`, the data goes through `userSchema` before it hits the database.
|
|
47
47
|
|
|
48
|
-
## Read state — `.id
|
|
48
|
+
## Read state — `.id`, `.uuid`, and `.get(field)`
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
51
|
user.id; // direct property — ID is so common cascade exposes it directly
|
|
52
|
+
user.uuid; // the same id, narrowed to `string` (see below)
|
|
52
53
|
user.get("status"); // canonical reader for every other column
|
|
53
54
|
user.get<number>("age"); // TypeScript generic for typed reads
|
|
54
55
|
```
|
|
55
56
|
|
|
56
57
|
Use the direct `.id` property; use `.get("field")` for everything else. Add a typed getter on the model class when the same field is read in many places — turns N typed-cast call sites into one named accessor.
|
|
57
58
|
|
|
59
|
+
### `.id` vs `.uuid` — a TypeScript convenience, same value
|
|
60
|
+
|
|
61
|
+
Both getters return the model's primary id (`this.get("id")`); the only difference is the **static type**:
|
|
62
|
+
|
|
63
|
+
| Accessor | Return type | Use when |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| `model.id` | `string \| number` | You want the real id type — SQL auto-increment is `number`, MongoDB's ObjectId is `string`. |
|
|
66
|
+
| `model.uuid` | `string` | You want to pass the id to code typed for a single `string` id, without leaking the engine's `string \| number` union everywhere. |
|
|
67
|
+
|
|
68
|
+
`uuid` does **not** validate or coerce the value to a UUID — the name is historical. It simply returns the same id, typed as `string`, so a helper typed for a string id accepts it on either engine:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
function shareLink(modelId: string) { /* ... */ }
|
|
72
|
+
|
|
73
|
+
shareLink(user.uuid); // ✓ typechecks on both Postgres and MongoDB
|
|
74
|
+
shareLink(user.id); // ✗ TS error on SQL: `number` is not assignable to `string`
|
|
75
|
+
```
|
|
76
|
+
|
|
58
77
|
## Write — three update idioms
|
|
59
78
|
|
|
60
79
|
Cascade gives you three ways to update an instance. Knowing when each fits saves you from reaching for the wrong one.
|