@owlmeans/resource 0.1.18-rc.5 → 0.1.18-rc.7
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/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/resource",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-08-
|
|
4
|
+
"version": "0.1.18-rc.7",
|
|
5
|
+
"generatedAt": "2026-08-24T21:14:00.098Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -8,13 +8,13 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/resource
|
|
9
9
|
|
|
10
10
|
**Layer:** Core
|
|
11
|
-
**Install:** `"@owlmeans/resource": "^0.1.18-rc.
|
|
11
|
+
**Install:** `"@owlmeans/resource": "^0.1.18-rc.7"` in `dependencies`
|
|
12
12
|
|
|
13
13
|
## Key Exports
|
|
14
14
|
|
|
15
15
|
| Export | Description |
|
|
16
16
|
|--------|-------------|
|
|
17
|
-
| `Resource<T>` | Generic resource contract: `get`/`load`/`list`/`save`/`create`/`update`/`delete`/`pick`. |
|
|
17
|
+
| `Resource<T>` | Generic resource contract: `get`/`load`/`list`/`save`/`create`/`update`/`delete`/`pick`. `list(criteria?, opts?)` paginates through `opts.pager: { page, size, sort }` — there is no `limit`. |
|
|
18
18
|
| `MigratableResource<Tx>` | **Optional migration capability** — `migration(name, apply, stage?)` (chainable) + `migrations()`. Optional the way pub/sub is on redis resources: mongo and postgres extend it, backends with nothing to migrate don't. |
|
|
19
19
|
| `Migration`, `MigrationRegistry`, `MigrationStore`, `MigrationReport`, `MigrationRunOptions` | The framework's contracts. `MigrationStore` is the *migration register* a database implements to track applied migrations (`ensure`/`applied`/`baseline`/`run`). |
|
|
20
20
|
| `createMigrationRegistry<Tx>()` | Storage-agnostic ledger of code-registered migrations per alias. Declaration order = application order; re-registering an identical body is a no-op, a changed body under a used name throws `MigrationConflict`. |
|
|
@@ -38,8 +38,42 @@ import type { Resource } from '@owlmeans/resource'
|
|
|
38
38
|
interface Project { id: string; name: string; entityId: string }
|
|
39
39
|
const projects = ctx.resource<Resource<Project>>('projects')
|
|
40
40
|
const { items } = await projects.list({ entityId: 'abc' })
|
|
41
|
+
|
|
42
|
+
// Pagination and sort ride under `pager` in the SECOND argument — there is NO `limit`,
|
|
43
|
+
// and neither `page` nor `size` exists at the top level of either argument:
|
|
44
|
+
const page2 = await projects.list(
|
|
45
|
+
{ entityId: 'abc' },
|
|
46
|
+
{ pager: { page: 1, size: 20, sort: ['createdAt'] } }
|
|
47
|
+
)
|
|
48
|
+
// page2.pager echoes { page, size, total } for building pagination UI.
|
|
41
49
|
```
|
|
42
50
|
|
|
51
|
+
### Calling the CRUD surface
|
|
52
|
+
|
|
53
|
+
A **write** takes the record as its only data argument, and the id travels inside it. There is no
|
|
54
|
+
`(id, changes)` overload on any of them — passing an id first fails to compile with
|
|
55
|
+
`TS2559: Type 'string' has no properties in common with type 'Partial<...>'`.
|
|
56
|
+
|
|
57
|
+
| Call | Signature | Notes |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| `create(record, opts?)` | `Partial<T> → T` | throws `RecordExists`; implementations may refuse a caller-supplied id |
|
|
60
|
+
| `save(record, opts?)` | `Partial<T> → T` | create-or-replace |
|
|
61
|
+
| `update(record, opts?)` | `Partial<T> → T` | replaces the whole record; throws `UnknownRecordError` |
|
|
62
|
+
|
|
63
|
+
A **read** takes the id first, plus an optional field to look it up by (`opts` is that field name,
|
|
64
|
+
or `{ field, ttl }`):
|
|
65
|
+
|
|
66
|
+
| Call | Signature | Notes |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| `load(id, field?, opts?)` | `string → T \| null` | the miss-tolerant read |
|
|
69
|
+
| `get(id, field?, opts?)` | `string → T` | throws `UnknownRecordError` instead of returning `null` |
|
|
70
|
+
| `list(criteria?, opts?)` | `→ { items, pager }` | |
|
|
71
|
+
| `delete(id \| record, opts?)` | `→ T \| null` | returns what it removed |
|
|
72
|
+
| `pick(id \| record, opts?)` | `→ T` | **also deletes** — it is `delete` that throws on a miss, never a read |
|
|
73
|
+
|
|
74
|
+
Every method returns the record(s) themselves, never a driver result object — there is no
|
|
75
|
+
`rowsAffected`/`rowCount` anywhere on this contract.
|
|
76
|
+
|
|
43
77
|
## The migration framework
|
|
44
78
|
|
|
45
79
|
Migrations are **automatic on app setup**: a backend runs them inside the resource's
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/resource",
|
|
3
|
-
"version": "0.1.18-rc.
|
|
3
|
+
"version": "0.1.18-rc.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@noble/hashes": "^1.5.0",
|
|
25
|
-
"@owlmeans/context": "^0.1.18-rc.
|
|
26
|
-
"@owlmeans/error": "^0.1.18-rc.
|
|
25
|
+
"@owlmeans/context": "^0.1.18-rc.6",
|
|
26
|
+
"@owlmeans/error": "^0.1.18-rc.6",
|
|
27
27
|
"@scure/base": "^2.3.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|