@owlmeans/mongo-resource 0.1.16-rc.0 → 0.1.16
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
CHANGED
|
@@ -128,10 +128,9 @@ database — an Entity-layer database tracks its own).
|
|
|
128
128
|
<!-- owlmeans:agent-guidance:start -->
|
|
129
129
|
## Agent guidance
|
|
130
130
|
|
|
131
|
-
This package ships embedded
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
(`.claude/skills/` and `.github/instructions/`):
|
|
131
|
+
This package ships embedded agent skills under `agent-meta/`. After installing your
|
|
132
|
+
`@owlmeans/*` packages, run the OwlMeans agent-skills installer to place them into
|
|
133
|
+
your project's skill store (`.agents/skills/`):
|
|
135
134
|
|
|
136
135
|
```sh
|
|
137
136
|
npx @owlmeans/agent-skills
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"schemaVersion":
|
|
2
|
+
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/mongo-resource",
|
|
4
|
-
"version": "0.1.16
|
|
5
|
-
"generatedAt": "2026-08-
|
|
4
|
+
"version": "0.1.16",
|
|
5
|
+
"generatedAt": "2026-08-14T10:14:48.849Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -10,14 +10,7 @@
|
|
|
10
10
|
"name": "mongo-resource",
|
|
11
11
|
"category": "package-specific",
|
|
12
12
|
"file": "skills/mongo-resource/SKILL.md",
|
|
13
|
-
"canonicalPath": ".
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"kind": "instruction",
|
|
17
|
-
"name": "mongo-resource",
|
|
18
|
-
"category": "package-specific",
|
|
19
|
-
"file": "instructions/mongo-resource.instructions.md",
|
|
20
|
-
"canonicalPath": ".github/instructions/mongo-resource.instructions.md"
|
|
13
|
+
"canonicalPath": ".agents/skills/mongo-resource/SKILL.md"
|
|
21
14
|
}
|
|
22
15
|
]
|
|
23
16
|
}
|
|
@@ -8,7 +8,7 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/mongo-resource
|
|
9
9
|
|
|
10
10
|
**Layer:** Infra
|
|
11
|
-
**Install:** `"@owlmeans/mongo-resource": "^0.1.16
|
|
11
|
+
**Install:** `"@owlmeans/mongo-resource": "^0.1.16"` in `dependencies` (peers `mongodb`, `ajv`)
|
|
12
12
|
|
|
13
13
|
The Mongo counterpart of [[postgres-resource]]. A collection has no structure of its own, so
|
|
14
14
|
here the resource layer owns the *validator* (`$jsonSchema` from the AJV schema), the indexes,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/mongo-resource",
|
|
3
|
-
"version": "0.1.16
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
"mongodb": "*"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@owlmeans/context": "^0.1.16
|
|
30
|
-
"@owlmeans/resource": "^0.1.16
|
|
31
|
-
"@owlmeans/server-context": "^0.1.16
|
|
29
|
+
"@owlmeans/context": "^0.1.16",
|
|
30
|
+
"@owlmeans/resource": "^0.1.16",
|
|
31
|
+
"@owlmeans/server-context": "^0.1.16"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@owlmeans/dep-config": "workspace:*",
|
|
35
|
-
"@owlmeans/test-integration": "^0.1.16
|
|
35
|
+
"@owlmeans/test-integration": "^0.1.16",
|
|
36
36
|
"@types/bun": "^1.3.14",
|
|
37
37
|
"@types/node": "^26.1.0",
|
|
38
38
|
"mongodb": "^6.9.0",
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: "How to use @owlmeans/mongo-resource — MongoDB-backed Resource with AJV-schema validators, code migrations and ObjectId reference conversion. Use when defining a mongo resource, declaring record references, or writing mongo migrations."
|
|
3
|
-
applyTo: "**/*.ts, **/*.tsx"
|
|
4
|
-
---
|
|
5
|
-
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
6
|
-
|
|
7
|
-
# @owlmeans/mongo-resource
|
|
8
|
-
|
|
9
|
-
**Layer:** Infra
|
|
10
|
-
**Install:** `"@owlmeans/mongo-resource": "^0.1.16-rc.0"` in `dependencies` (peers `mongodb`, `ajv`)
|
|
11
|
-
|
|
12
|
-
## Key Exports
|
|
13
|
-
|
|
14
|
-
| Export | Description |
|
|
15
|
-
|--------|-------------|
|
|
16
|
-
| `makeMongoResource<R, T>(alias, dbAlias?, serviceAlias?, maker?, collectionName?)` | The resource factory (positional args, NOT an options object) |
|
|
17
|
-
| `MongoResource<T>` | `Resource<T>` + `collection`, `index`, `reference`/`references`, `migration`/`migrations`, `lock`/`unlock` |
|
|
18
|
-
| `MongoTx` | Migration façade: `db`, `collection`, `use(alias)`, `ref(alias)` |
|
|
19
|
-
| `marshalReference`, `demarshalReference`, `marshalCriteria`, `identityCriteria`, `isObjectIdHex` | Reference conversion layer — reuse for raw driver access |
|
|
20
|
-
| `getDeclaration`, `resetDeclarations` | Module-scope migration/reference declarations per alias |
|
|
21
|
-
|
|
22
|
-
## Usage
|
|
23
|
-
|
|
24
|
-
```typescript
|
|
25
|
-
export const makeStoryResource: ResourceMaker<StoryRecord, StoryResource> = (dbAlias, serviceAlias) => {
|
|
26
|
-
const resource = makeMongoResource<StoryRecord, StoryResource>(RES_STORY, dbAlias, serviceAlias, makeStoryResource)
|
|
27
|
-
resource.schema = StorySchema
|
|
28
|
-
resource.reference('projectId', RES_PROJECT) // field stores another record's id
|
|
29
|
-
resource.index('code', { projectId: 1, code: 1 }, { sparse: true })
|
|
30
|
-
resource.migration('0001-backfill', async tx => { /* idempotent body */ })
|
|
31
|
-
return resource
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## ObjectId references
|
|
36
|
-
|
|
37
|
-
- `reference(field, targetAlias?)` — records/criteria carry strings, the collection stores
|
|
38
|
-
`ObjectId`s (converted like `_id`); the field gets an automatic index (`ref_<field>`)
|
|
39
|
-
unless an identical key pattern is already declared; the validator declares it `objectId`.
|
|
40
|
-
- Writes are strict (non-24-hex throws `MisshapedRecord`), reads/criteria tolerant. `id`
|
|
41
|
-
criteria map onto `_id`.
|
|
42
|
-
- Declaring one registers the system migration `$ref:<field>@1` (Pre) that converts existing
|
|
43
|
-
strings; the boot additionally probes the collection and repairs drift (the double check).
|
|
44
|
-
Any semantic edit to the shared conversion body must bump the `@N` suffix.
|
|
45
|
-
- NEVER declare business/external keys as references: `entityId`/`entity` slugs, composite
|
|
46
|
-
`profileId`, `credentials.userId` (external key — but `profile.userId` IS a reference),
|
|
47
|
-
Stripe/Cloudflare/GitHub ids, minted slugs/tokens.
|
|
48
|
-
- Raw `resource.collection.*` access bypasses conversion — marshal filters with
|
|
49
|
-
`marshalReference` and stringify read-back ids by hand.
|
|
50
|
-
|
|
51
|
-
## Migrations
|
|
52
|
-
|
|
53
|
-
- `migration(name, apply, stage?)` — applied once per database in declaration order,
|
|
54
|
-
ledgered in `_owlmeans_migrations`. `Pre` runs before validator/index update, `Post` after.
|
|
55
|
-
Fresh collections baseline (record without running).
|
|
56
|
-
- No multi-document transactions (standalone mongod) → bodies MUST be idempotent; the ledger
|
|
57
|
-
claims-then-completes on a unique `(alias, name)` index.
|
|
58
|
-
- Checksums fingerprint the body's source text: keep bodies at module scope; an edited
|
|
59
|
-
applied body raises `MigrationConflict`.
|
|
60
|
-
- `migration()`/`reference()` survive `reinitializeContext` (module-scope declarations);
|
|
61
|
-
`schema`/`index()` survive only when the maker is passed as the 4th factory argument.
|
|
62
|
-
|
|
63
|
-
## Depends On
|
|
64
|
-
|
|
65
|
-
- `@owlmeans/mongo` (service), `@owlmeans/resource` (contracts + migration framework), `@owlmeans/server-context`
|