@owlmeans/mongo-resource 0.1.18-rc.0 → 0.1.18-rc.10
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 +49 -14
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/mongo-resource/SKILL.md +52 -18
- package/build/consts.d.ts +8 -4
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +8 -4
- package/build/consts.js.map +1 -1
- package/build/declarations.d.ts.map +1 -1
- package/build/declarations.js +5 -6
- package/build/declarations.js.map +1 -1
- package/build/helper.d.ts.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/resource.d.ts +2 -2
- package/build/resource.d.ts.map +1 -1
- package/build/resource.js +91 -118
- package/build/resource.js.map +1 -1
- package/build/types.d.ts +16 -5
- package/build/types.d.ts.map +1 -1
- package/build/utils/criteria.d.ts +24 -0
- package/build/utils/criteria.d.ts.map +1 -0
- package/build/utils/criteria.js +221 -0
- package/build/utils/criteria.js.map +1 -0
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js +1 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/indexes.d.ts.map +1 -1
- package/build/utils/life-cycle.d.ts.map +1 -1
- package/build/utils/migrations.d.ts.map +1 -1
- package/build/utils/migrations.js +16 -1
- package/build/utils/migrations.js.map +1 -1
- package/build/utils/name.d.ts.map +1 -1
- package/build/utils/refs.d.ts +5 -3
- package/build/utils/refs.d.ts.map +1 -1
- package/build/utils/refs.js +4 -1
- package/build/utils/refs.js.map +1 -1
- package/build/utils/schema.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/consts.ts +8 -4
- package/src/declarations.ts +5 -6
- package/src/index.ts +1 -0
- package/src/resource.ts +115 -144
- package/src/types.ts +17 -5
- package/src/utils/criteria.ts +248 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/migrations.ts +17 -2
- package/src/utils/refs.ts +8 -6
- package/tests/criteria.spec.ts +114 -0
- package/build/.gitkeep +0 -0
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@ MongoDB-backed `Resource<T>` implementation — the primary database resource fo
|
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
- `makeMongoResource<R, T>(alias, dbAlias?, serviceAlias?,
|
|
7
|
+
- `makeMongoResource<R, T>(alias, dbAlias?, serviceAlias?, collectionName?)` — factory for MongoDB resources
|
|
8
8
|
- `MongoResource<T>` — extends `Resource<T>` with MongoDB collection, indexing, field encryption, code migrations and ObjectId references
|
|
9
|
-
- Supports CRUD,
|
|
9
|
+
- Supports CRUD, criteria queries, sorting and paging, AJV schema validation ($jsonSchema collection validators), and field-level locking (encryption)
|
|
10
10
|
- Declared references convert between the string ids records carry and the `ObjectId`s the collection stores — the same way `_id` already does
|
|
11
11
|
- Code migrations run automatically at resource initialization, tracked in a per-database `_owlmeans_migrations` ledger
|
|
12
12
|
- Used for all persistent data models in server applications
|
|
@@ -29,9 +29,7 @@ import type { ResourceMaker } from '@owlmeans/resource'
|
|
|
29
29
|
export interface ProjectResource extends MongoResource<ProjectRecord> {}
|
|
30
30
|
|
|
31
31
|
export const makeProjectResource: ResourceMaker<ProjectRecord, ProjectResource> = (dbAlias, serviceAlias) => {
|
|
32
|
-
const resource = makeMongoResource<ProjectRecord>(
|
|
33
|
-
RES_PROJECT, dbAlias, serviceAlias, makeProjectResource
|
|
34
|
-
)
|
|
32
|
+
const resource = makeMongoResource<ProjectRecord, ProjectResource>(RES_PROJECT, dbAlias, serviceAlias)
|
|
35
33
|
resource.schema = ProjectSchema
|
|
36
34
|
resource.index('entity', { entityId: 1 })
|
|
37
35
|
resource.index('alias', { alias: 1 })
|
|
@@ -50,29 +48,55 @@ Use in a handler:
|
|
|
50
48
|
```typescript
|
|
51
49
|
const projects = context.resource<ProjectResource>(RES_PROJECT)
|
|
52
50
|
const record = await projects.create({ entityId, alias, title })
|
|
53
|
-
const
|
|
51
|
+
const one = await projects.load({ entityId, alias })
|
|
52
|
+
const page = await projects.list({ entityId }, { page: 0, size: 20, sort: ['createdAt'] })
|
|
53
|
+
const open = await projects.count({ status: ['draft', 'active'] })
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
## API
|
|
57
57
|
|
|
58
|
-
### `makeMongoResource<R, T>(alias, dbAlias?, serviceAlias?,
|
|
58
|
+
### `makeMongoResource<R, T>(alias, dbAlias?, serviceAlias?, collectionName?): T`
|
|
59
59
|
|
|
60
60
|
Creates a MongoDB resource. `dbAlias` defaults to `DEFAULT_DB_ALIAS` (`'mongo'`).
|
|
61
61
|
`collectionName` overrides the physical collection name (otherwise `resourcePrefix + alias`).
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
`migration()` and `reference()` are kept in module-scope declarations keyed by alias, so a
|
|
63
|
+
maker that runs more than once for the same alias re-declares the same entries and loses
|
|
64
|
+
nothing.
|
|
64
65
|
|
|
65
66
|
### `MongoResource<T>`
|
|
66
67
|
|
|
67
|
-
Extends `Resource<T>`
|
|
68
|
+
Extends `Resource<T>` with the shared `MigratableResource<MongoTx, MongoResource<T>>` and
|
|
69
|
+
`LockableResource<T>` capabilities, plus:
|
|
68
70
|
- `collection: Collection` — MongoDB collection
|
|
69
71
|
- `db(): Promise<Db>` / `client(): Promise<MongoClient>`
|
|
70
72
|
- `index(name, spec, options?): this` — define a collection index
|
|
71
73
|
- `reference(field, targetAlias?): this` / `references()` — declare that a field stores another record's id (see below)
|
|
72
|
-
- `migration(name, apply, stage?)
|
|
74
|
+
- `migration(name, apply, stage?)` / `migrations()` — register a code migration (see below)
|
|
73
75
|
- `lock(record, fields?)` / `unlock(record, fields?)` — encrypt/decrypt secure fields
|
|
74
76
|
- `getDefaults(): Partial<T>` — default values derived from schema
|
|
75
77
|
|
|
78
|
+
### Criteria, sorting and paging
|
|
79
|
+
|
|
80
|
+
`Criteria<T>` is the portable query shape from [`@owlmeans/resource`](../resource): a bare value
|
|
81
|
+
is equality, a bare array is "any of these", `null` asks for the absence of a value and
|
|
82
|
+
`undefined` is skipped so an untouched filter never empties a list. Every operator in the shared
|
|
83
|
+
vocabulary — `$eq $ne $gt $gte $lt $lte $in $nin $exists $null $like $ilike $regex $startsWith
|
|
84
|
+
$endsWith $between $contains $contained $overlaps`, plus `$and`/`$or`/`$not` — is translated into
|
|
85
|
+
the mongo expression that answers the same question, so one criteria object means the same thing
|
|
86
|
+
here as it does against Postgres or an in-memory store. `$exists` and `$null` both ask whether the
|
|
87
|
+
field *has a value*, not whether the key is present. An operator outside the vocabulary raises
|
|
88
|
+
`UnsupportedArgumentError`.
|
|
89
|
+
|
|
90
|
+
Paging is per call: `list(where, { page, size, sort })`. Mongo pages by default —
|
|
91
|
+
`DEFAULT_PAGE_SIZE` records when no `size` is given — because an unbounded read of a collection is
|
|
92
|
+
not something a caller should get by omission. `list(where, { size: 0 })` asks for the whole
|
|
93
|
+
result set explicitly. `ListResult.total` is always filled; `page` and `size` come back only when
|
|
94
|
+
a limit was applied. `sort` takes field names (ascending) or `{ field, order: 'desc' }`, and `id`
|
|
95
|
+
addresses `_id`.
|
|
96
|
+
|
|
97
|
+
`criteriaToFilter(criteria, refs)` and `sortToMongo(sort)` are exported for code driving
|
|
98
|
+
`resource.collection` directly.
|
|
99
|
+
|
|
76
100
|
### ObjectId references
|
|
77
101
|
|
|
78
102
|
`reference(field, targetAlias?)` declares that a record field references another record's id.
|
|
@@ -100,7 +124,7 @@ The resource then treats the field exactly like `_id`:
|
|
|
100
124
|
|
|
101
125
|
`migration(name, apply, stage?)` registers a code migration, applied once per database in
|
|
102
126
|
declaration order and recorded in the `_owlmeans_migrations` collection (one ledger per
|
|
103
|
-
database
|
|
127
|
+
database, so each database tracks its own).
|
|
104
128
|
|
|
105
129
|
- `MigrationStage.Pre` runs before the validator/index update, `Post` after. On a collection
|
|
106
130
|
created by this very boot, registered migrations are **baselined** (recorded, not run).
|
|
@@ -112,12 +136,23 @@ database — an Entity-layer database tracks its own).
|
|
|
112
136
|
|
|
113
137
|
### `Resource<T>` methods (all implemented)
|
|
114
138
|
|
|
115
|
-
`get`, `load`, `create`, `update`, `save`, `delete`, `
|
|
139
|
+
`get`, `load`, `list`, `count`, `create`, `update`, `save`, `delete`, `take`, `purge`
|
|
140
|
+
|
|
141
|
+
- `get`/`load` take either an id or a `Criteria<T>` with an optional `{ sort }`; `get` throws
|
|
142
|
+
`UnknownRecordError` where `load` answers `null`. An id that is not a mongo id finds nothing
|
|
143
|
+
rather than raising a driver error.
|
|
144
|
+
- `update` replaces the whole record addressed by its `id`; `save` creates when the record
|
|
145
|
+
carries no id and replaces otherwise.
|
|
146
|
+
- `delete(id)` and `take(id)` remove atomically through `findOneAndDelete` and hand the record
|
|
147
|
+
back — `take` throws `UnknownRecordError` on absence where `delete` answers `null`.
|
|
148
|
+
- `purge(where)` is the bulk delete; it refuses an empty criteria object rather than emptying
|
|
149
|
+
the collection.
|
|
150
|
+
- `ttl` is refused with `UnsupportedArgumentError` — a collection has no per-record expiry.
|
|
116
151
|
|
|
117
152
|
### Constants
|
|
118
153
|
|
|
119
154
|
- `DEFAULT_DB_ALIAS` — `'mongo'`
|
|
120
|
-
- `DEFAULT_PAGE_SIZE` — `
|
|
155
|
+
- `DEFAULT_PAGE_SIZE` — `100`
|
|
121
156
|
- `DEF_MIGRATIONS_COLLECTION` — `'_owlmeans_migrations'`
|
|
122
157
|
|
|
123
158
|
## Related Packages
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/mongo-resource",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-
|
|
4
|
+
"version": "0.1.18-rc.10",
|
|
5
|
+
"generatedAt": "2026-09-01T16:28:56.987Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -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.18-rc.
|
|
11
|
+
**Install:** `"@owlmeans/mongo-resource": "^0.1.18-rc.10"` 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,
|
|
@@ -19,11 +19,12 @@ reference**.
|
|
|
19
19
|
|
|
20
20
|
| Export | Description |
|
|
21
21
|
|--------|-------------|
|
|
22
|
-
| `makeMongoResource<R, T>(alias, dbAlias?, serviceAlias?,
|
|
22
|
+
| `makeMongoResource<R, T>(alias, dbAlias?, serviceAlias?, collectionName?)` | The resource factory. Aliases default to `DEFAULT_DB_ALIAS` (`'mongo'`). `collectionName` overrides the collection (else `resourcePrefix + alias`). |
|
|
23
23
|
| `MongoResource<T>` | `Resource<T>` + `collection`, `index`, `reference`/`references`, `migration`/`migrations` (the shared `MigratableResource` capability), `lock`/`unlock`, `getDefaults`. |
|
|
24
24
|
| `MongoDbService`, `MongoTx` | Service contract implemented by `@owlmeans/mongo`; the façade handed to migrations (`db`, `collection`, `use(alias)`, `ref(alias)`). |
|
|
25
25
|
| `MongoReference`, `MongoRefOptions` | A declared ObjectId reference and the `reference()` options (`resource`, `noIndex`). |
|
|
26
26
|
| `marshalReference`, `demarshalReference`, `marshalCriteria`, `identityCriteria`, `isObjectIdHex` | The conversion layer — reuse these wherever raw driver access bypasses the resource. |
|
|
27
|
+
| `criteriaToFilter`, `sortToMongo` | `Criteria<T>` → a mongo filter (references converted, every shared operator rewritten into a mongo expression) and `Sort<T>` → a mongo sort spec. |
|
|
27
28
|
| `convertReferenceField`, `reconcileReferences`, `refMigrationName` | The system reference migration's machinery. |
|
|
28
29
|
| `makeMongoTx`, `makeMongoMigrationStore` | The migration store (ledger) implementation. |
|
|
29
30
|
| `getDeclaration`, `resetDeclarations` | Module-scope migration/reference declarations, keyed by alias. |
|
|
@@ -36,7 +37,7 @@ reference**.
|
|
|
36
37
|
export const makeProjectStoryResource: ResourceMaker<ProjectStoryRecord, ProjectStoryResource> =
|
|
37
38
|
(dbAlias, serviceAlias) => {
|
|
38
39
|
const resource = makeMongoResource<ProjectStoryRecord, ProjectStoryResource>(
|
|
39
|
-
RES_PROJECT_STORY, dbAlias, serviceAlias
|
|
40
|
+
RES_PROJECT_STORY, dbAlias, serviceAlias
|
|
40
41
|
)
|
|
41
42
|
resource.schema = ProjectStorySchema
|
|
42
43
|
resource.reference('projectId', RES_PROJECT)
|
|
@@ -48,10 +49,9 @@ export const makeProjectStoryResource: ResourceMaker<ProjectStoryRecord, Project
|
|
|
48
49
|
context.registerResource(makeProjectStoryResource())
|
|
49
50
|
```
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
silently loses a data transformation.
|
|
52
|
+
`migration()` and `reference()` live in module-scope declarations keyed by alias, so a maker
|
|
53
|
+
that runs more than once for the same alias (a custom maker, a test) re-declares the same
|
|
54
|
+
entries and loses nothing — losing one would silently lose a data transformation.
|
|
55
55
|
|
|
56
56
|
## ObjectId references
|
|
57
57
|
|
|
@@ -59,18 +59,18 @@ A field that stores **another record's id** is declared with `reference(field, t
|
|
|
59
59
|
The resource then behaves for that field exactly as it does for `_id`:
|
|
60
60
|
|
|
61
61
|
- **Records and criteria carry strings; the collection stores `ObjectId`s.** Conversion is
|
|
62
|
-
automatic in `create`/`update`/`save` (write), `get`/`load`/`list`/`delete`/`
|
|
63
|
-
lookup), and in
|
|
64
|
-
`$
|
|
65
|
-
alone.
|
|
62
|
+
automatic in `create`/`update`/`save` (write), `get`/`load`/`list`/`count`/`delete`/`take`/
|
|
63
|
+
`purge` (read and lookup), and in every criteria object — including operator objects,
|
|
64
|
+
`$and`/`$or`/`$not` branches, and arrays of ids (elementwise). `$regex`-style operands are
|
|
65
|
+
left alone.
|
|
66
66
|
- **Writes are strict**: storing a non-24-hex value in a declared reference throws
|
|
67
67
|
`MisshapedRecord('ref:<field>')` — a silent string would reintroduce the mixed-type state.
|
|
68
68
|
Reads and criteria are tolerant: an unconverted legacy string comes back as-is; a non-id
|
|
69
69
|
criteria value simply matches nothing (the auth `userId ?? profileId` fallback relies on
|
|
70
70
|
this).
|
|
71
71
|
- **`id` criteria address `_id`.** Documents never store an `id` field, so `list({ id })` and
|
|
72
|
-
`load(
|
|
73
|
-
|
|
72
|
+
`load(id)` map onto `_id` with conversion; a criteria key naming a declared reference converts
|
|
73
|
+
the same way.
|
|
74
74
|
- **The field is indexed** automatically (`ref_<field>`), unless `noIndex: true` or the
|
|
75
75
|
resource already declares an index with the identical key pattern (mongo forbids two
|
|
76
76
|
indexes over the same keys; a declared unique index wins).
|
|
@@ -115,10 +115,20 @@ with `marshalReference(field, value)` and convert read-back documents' reference
|
|
|
115
115
|
|
|
116
116
|
`resource.migration(name, apply, stage?)` — the shared `MigratableResource` capability from
|
|
117
117
|
[[resource]]. Applied once per database, in declaration order, ledgered in
|
|
118
|
-
`_owlmeans_migrations` (one ledger per database, so
|
|
118
|
+
`_owlmeans_migrations` (one ledger per database, so each database tracks its own).
|
|
119
119
|
|
|
120
120
|
- `Pre` runs **before** the validator is updated and indexes reconcile; `Post` after. A `Pre`
|
|
121
121
|
body writes shapes the *old* validator allows; a `Post` body the *new* one.
|
|
122
|
+
- **A `Pre` body that removes an indexed field must drop that index itself.** Indexes reconcile
|
|
123
|
+
*after* `Pre`, so the old one is still live and still enforcing while the body writes. Renaming
|
|
124
|
+
the field in the `index()` declaration does not help when the index **name** stays the same:
|
|
125
|
+
`updateIndexes` matches by name, sees one already there, and leaves the old key spec alone —
|
|
126
|
+
so the declaration says `{ entityId, slug, kind }` while the collection enforces
|
|
127
|
+
`{ entity, slug, kind }`. `$unset`ing the field then collapses every row onto `{ <field>: null,
|
|
128
|
+
… }`, and on a `unique` index the second row dies with E11000 — mid-migration, after earlier
|
|
129
|
+
collections were already rewritten, leaving the database half-migrated and the boot aborting on
|
|
130
|
+
every restart. Drop the stale index by name in the body first (guard on the key spec so the
|
|
131
|
+
drop is idempotent), and let the reconcile recreate it from the declaration.
|
|
122
132
|
- On a collection this boot just created, every registered migration is **baselined**
|
|
123
133
|
(recorded, not run) — a fresh collection is born at head.
|
|
124
134
|
- **No transactions**: a standalone `mongod` (the dev/CI target) rejects multi-document
|
|
@@ -146,13 +156,37 @@ with `marshalReference(field, value)` and convert read-back documents' reference
|
|
|
146
156
|
|
|
147
157
|
| Method | Semantics |
|
|
148
158
|
|---|---|
|
|
149
|
-
| `create` | refuses a caller-supplied id (`RecordExists`) |
|
|
150
|
-
| `update` | **replaces** the whole record (no merge) |
|
|
151
|
-
| `
|
|
152
|
-
| `load
|
|
159
|
+
| `create` | refuses a caller-supplied id (`RecordExists`); rejects `opts.ttl` (`UnsupportedArgumentError`) |
|
|
160
|
+
| `update` | **replaces** the whole record (no merge), keeping the document's `_id` |
|
|
161
|
+
| `load(id)` / `get(id)` | a string that is not a 24-hex id matches nothing — `load` answers `null` and `get` throws, where handing it to `ObjectId` would raise a driver error at a call site that only asked whether the record exists |
|
|
162
|
+
| `load(where, { sort })` / `get(where, { sort })` | `findOne` with the sort applied, so "the newest matching record" is one round trip |
|
|
153
163
|
| `list` | criteria go through reference conversion; documents never store `id` — use `id` criteria freely, they map to `_id` |
|
|
164
|
+
| `delete` / `take` | one `findOneAndDelete`: the record is handed back by the very operation that removed it, so two callers can never be given the same record. `take` **deletes** and throws `UnknownRecordError` on a miss |
|
|
165
|
+
| `purge` | `deleteMany`; refuses an empty criteria object (`UnsupportedArgumentError('purge:no-criteria')`) rather than emptying the collection |
|
|
154
166
|
| `lock`/`unlock` | encrypt/decrypt `secure: true` schema fields via the db service |
|
|
155
167
|
|
|
168
|
+
## Paging
|
|
169
|
+
|
|
170
|
+
Mongo is **PAGED**: `DEFAULT_PAGE_SIZE` is `100`, so `list(where)` with no `size` returns the first
|
|
171
|
+
100 matches — a collection is unbounded and an unpaged read is an incident waiting for the document
|
|
172
|
+
count to grow. `ListResult.total` counts every match regardless of the window, and
|
|
173
|
+
`list(where, { size: 0 })` is the explicit, greppable ask for the whole result set.
|
|
174
|
+
|
|
175
|
+
## Criteria against a collection
|
|
176
|
+
|
|
177
|
+
`criteriaToFilter` rewrites the shared vocabulary ([[resource]]) into mongo expressions so one
|
|
178
|
+
criteria object selects the same records here as it does in SQL and in memory. Two rewrites are
|
|
179
|
+
worth knowing:
|
|
180
|
+
|
|
181
|
+
- **`$exists` and `$null` compare against `null`**, not mongo's own `$exists`. The shared question
|
|
182
|
+
is whether a field *has a value*, which the other stores answer as `IS NULL` / `value == null`;
|
|
183
|
+
mongo's `$exists` answers whether the key is present, and a key present but null would part the
|
|
184
|
+
three stores over one object.
|
|
185
|
+
- **`$like`/`$ilike` become anchored regular expressions** with `%` as any run and `_` as one
|
|
186
|
+
character; `$between` becomes `$gte`/`$lte`; and `$contains`/`$contained`/`$overlaps` mean over
|
|
187
|
+
an array field exactly what the postgres operators `@>`, `<@` and `&&` mean. An operator mongo
|
|
188
|
+
cannot answer raises `UnsupportedArgumentError` rather than being dropped.
|
|
189
|
+
|
|
156
190
|
## Tests
|
|
157
191
|
|
|
158
192
|
Unit specs (conversion layer): `bun test ./tests` in this package — ungated. Integration
|
package/build/consts.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
export declare const DEFAULT_DB_ALIAS = "mongo";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Page size a `list` call gets when it asks for none. Mongo cannot afford an unbounded read
|
|
4
|
+
* of a collection by omission, so paging is the default here — `list(where, { size: 0 })`
|
|
5
|
+
* asks for the whole result set, explicitly and greppably.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_PAGE_SIZE = 100;
|
|
3
8
|
/**
|
|
4
9
|
* Collection that records which code-registered migrations have already been applied.
|
|
5
10
|
*
|
|
6
|
-
* One ledger per database, which is the right boundary:
|
|
7
|
-
*
|
|
8
|
-
* data and dropping the database drops the ledger with it.
|
|
11
|
+
* One ledger per database, which is the right boundary: it sits beside the data its
|
|
12
|
+
* migrations changed, so dropping the database drops the ledger with it.
|
|
9
13
|
*/
|
|
10
14
|
export declare const DEF_MIGRATIONS_COLLECTION = "_owlmeans_migrations";
|
|
11
15
|
/**
|
package/build/consts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,gBAAgB,UAAU,CAAA;AAEvC,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,gBAAgB,UAAU,CAAA;AAEvC;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,MAAM,CAAA;AAEpC;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,yBAAyB,CAAA;AAE/D;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAAQ,CAAA;AAEvC,eAAO,MAAM,kBAAkB,MAAM,CAAA;AAErC,yFAAyF;AACzF,eAAO,MAAM,mBAAmB,QAAQ,CAAA"}
|
package/build/consts.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
export const DEFAULT_DB_ALIAS = 'mongo';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Page size a `list` call gets when it asks for none. Mongo cannot afford an unbounded read
|
|
4
|
+
* of a collection by omission, so paging is the default here — `list(where, { size: 0 })`
|
|
5
|
+
* asks for the whole result set, explicitly and greppably.
|
|
6
|
+
*/
|
|
7
|
+
export const DEFAULT_PAGE_SIZE = 100;
|
|
3
8
|
/**
|
|
4
9
|
* Collection that records which code-registered migrations have already been applied.
|
|
5
10
|
*
|
|
6
|
-
* One ledger per database, which is the right boundary:
|
|
7
|
-
*
|
|
8
|
-
* data and dropping the database drops the ledger with it.
|
|
11
|
+
* One ledger per database, which is the right boundary: it sits beside the data its
|
|
12
|
+
* migrations changed, so dropping the database drops the ledger with it.
|
|
9
13
|
*/
|
|
10
14
|
export const DEF_MIGRATIONS_COLLECTION = '_owlmeans_migrations';
|
|
11
15
|
/**
|
package/build/consts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AAEvC,MAAM,CAAC,MAAM,iBAAiB,GAAG,
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AAEvC;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAA;AAEpC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,sBAAsB,CAAA;AAE/D;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAA;AAEvC,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAA;AAErC,yFAAyF;AACzF,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declarations.d.ts","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAE3D,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzD,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAA;IACtC,2FAA2F;IAC3F,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;CACxC;
|
|
1
|
+
{"version":3,"file":"declarations.d.ts","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAE3D,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzD,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAA;IACtC,2FAA2F;IAC3F,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;CACxC;AAaD,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,gBAQ9C,CAAA;AAED,8FAA8F;AAC9F,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,IAOlD,CAAA"}
|
package/build/declarations.js
CHANGED
|
@@ -2,12 +2,11 @@ import { createMigrationRegistry } from '@owlmeans/resource';
|
|
|
2
2
|
/**
|
|
3
3
|
* Per-alias migration store, held at module scope rather than on the resource object.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* by alias makes the declarations outlive any number of context switches.
|
|
5
|
+
* A maker may run more than once for the same alias — a custom maker wrapping the built-in
|
|
6
|
+
* one, a maker called again by an app or a spec. Keying the declarations by alias makes
|
|
7
|
+
* that a no-op: every run reads and extends the same registry, so nothing a caller declared
|
|
8
|
+
* by chaining onto an earlier resource object is lost. Losing a migration is silent — the
|
|
9
|
+
* data transformation simply never runs — which is why the store cannot live on the object.
|
|
11
10
|
*/
|
|
12
11
|
const declarations = new Map();
|
|
13
12
|
export const getDeclaration = (alias) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declarations.js","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AAW5D
|
|
1
|
+
{"version":3,"file":"declarations.js","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AAW5D;;;;;;;;GAQG;AACH,MAAM,YAAY,GAAkC,IAAI,GAAG,EAAE,CAAA;AAE7D,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAoB,EAAE;IAChE,IAAI,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACzC,IAAI,WAAW,IAAI,IAAI,EAAE,CAAC;QACxB,WAAW,GAAG,EAAE,UAAU,EAAE,uBAAuB,EAAW,EAAE,UAAU,EAAE,IAAI,GAAG,EAAE,EAAE,CAAA;QACvF,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;IACtC,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA;AAED,8FAA8F;AAC9F,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAAQ,EAAE;IACxD,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,YAAY,CAAC,KAAK,EAAE,CAAA;QAEpB,OAAM;IACR,CAAC;IACD,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC,CAAA"}
|
package/build/helper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,KAAK,CAAA;AAEpD,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,KAAK,CAAA;AAEpD,eAAO,MAAM,qBAAqB,GAAI,QAAQ,SAAS,KAAG,MAAM,EAEgB,CAAA"}
|
package/build/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './consts.js';
|
|
|
3
3
|
export * from './declarations.js';
|
|
4
4
|
export * from './utils/migrations.js';
|
|
5
5
|
export * from './utils/refs.js';
|
|
6
|
+
export * from './utils/criteria.js';
|
|
6
7
|
export * from './resource.js';
|
|
7
8
|
export * from './helper.js';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from './consts.js';
|
|
|
2
2
|
export * from './declarations.js';
|
|
3
3
|
export * from './utils/migrations.js';
|
|
4
4
|
export * from './utils/refs.js';
|
|
5
|
+
export * from './utils/criteria.js';
|
|
5
6
|
export * from './resource.js';
|
|
6
7
|
export * from './helper.js';
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA"}
|
package/build/resource.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ResourceRecord } from '@owlmeans/resource';
|
|
2
2
|
import type { MongoResource } from './types.js';
|
|
3
|
-
export declare const makeMongoResource: <R extends ResourceRecord, T extends MongoResource<R> = MongoResource<R>>(alias: string, dbAlias?: string, serviceAlias?: string,
|
|
3
|
+
export declare const makeMongoResource: <R extends ResourceRecord, T extends MongoResource<R> = MongoResource<R>>(alias: string, dbAlias?: string, serviceAlias?: string, collectionName?: string) => T;
|
|
4
4
|
//# sourceMappingURL=resource.d.ts.map
|
package/build/resource.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACuC,cAAc,EAChE,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EAAmD,aAAa,EAAW,MAAM,YAAY,CAAA;AAkBzG,eAAO,MAAM,iBAAiB,GAC5B,CAAC,SAAS,cAAc,EAAE,CAAC,SAAS,aAAa,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,EAEvE,OAAO,MAAM,EAAE,UAAS,MAAyB,EAAE,eAAc,MAAyB,EAC1F,iBAAiB,MAAM,KACtB,CAsRF,CAAA"}
|