@owlmeans/mongo-resource 0.1.18-rc.2 → 0.1.18-rc.21
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 +232 -71
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/mongo-resource/SKILL.md +80 -30
- 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/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/migrations.d.ts.map +1 -1
- package/build/utils/migrations.js +16 -1
- package/build/utils/migrations.js.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/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
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { UnsupportedArgumentError } from '@owlmeans/resource';
|
|
2
|
+
import { marshalCriteria } from './refs.js';
|
|
3
|
+
/**
|
|
4
|
+
* Operators mongo speaks natively and that mean the same thing here as they do in SQL and in
|
|
5
|
+
* the in-memory engine. Everything else in the shared vocabulary is rewritten below into a
|
|
6
|
+
* mongo expression with the same meaning — a criteria object has to answer identically
|
|
7
|
+
* whichever store it reaches.
|
|
8
|
+
*/
|
|
9
|
+
const NATIVE = new Set(['$eq', '$ne', '$gt', '$gte', '$lt', '$lte', '$in', '$nin', '$regex']);
|
|
10
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
11
|
+
/**
|
|
12
|
+
* A SQL `LIKE` pattern as an anchored regular expression: `%` is any run, `_` is one
|
|
13
|
+
* character, and `\` escapes either. The mapping is the one the in-memory engine applies, so
|
|
14
|
+
* the same pattern selects the same records against a collection.
|
|
15
|
+
*/
|
|
16
|
+
const likeToRegExp = (pattern) => {
|
|
17
|
+
let source = '';
|
|
18
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
19
|
+
const char = pattern[index];
|
|
20
|
+
if (char === '\\' && index + 1 < pattern.length) {
|
|
21
|
+
source += escapeRegExp(pattern[++index]);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (char === '%') {
|
|
25
|
+
source += '.*';
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (char === '_') {
|
|
29
|
+
source += '.';
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
source += escapeRegExp(char);
|
|
33
|
+
}
|
|
34
|
+
return `^${source}$`;
|
|
35
|
+
};
|
|
36
|
+
const asArray = (operand) => Array.isArray(operand) ? operand : [operand];
|
|
37
|
+
/**
|
|
38
|
+
* One operator as the mongo field expression that answers it.
|
|
39
|
+
*
|
|
40
|
+
* `$exists` and `$null` both become a comparison against `null`, not mongo's own `$exists`:
|
|
41
|
+
* the shared vocabulary asks whether a field *has a value*, which the relational and
|
|
42
|
+
* in-memory stores answer as `IS NULL` / `value == null`. Mongo's `$exists` answers a
|
|
43
|
+
* different question — whether the key is present — and a key present but null would part
|
|
44
|
+
* the three stores over one criteria object.
|
|
45
|
+
*
|
|
46
|
+
* @throws {UnsupportedArgumentError} on an operator this store cannot answer.
|
|
47
|
+
*/
|
|
48
|
+
const operatorToFilter = (field, operator, operand) => {
|
|
49
|
+
if (NATIVE.has(operator)) {
|
|
50
|
+
return { [operator]: operand };
|
|
51
|
+
}
|
|
52
|
+
switch (operator) {
|
|
53
|
+
case '$exists':
|
|
54
|
+
return operand === false ? { $eq: null } : { $ne: null };
|
|
55
|
+
case '$null':
|
|
56
|
+
return operand === false ? { $ne: null } : { $eq: null };
|
|
57
|
+
case '$like':
|
|
58
|
+
return { $regex: likeToRegExp(`${operand}`) };
|
|
59
|
+
case '$ilike':
|
|
60
|
+
return { $regex: likeToRegExp(`${operand}`), $options: 'i' };
|
|
61
|
+
case '$startsWith':
|
|
62
|
+
return { $regex: `^${escapeRegExp(`${operand}`)}` };
|
|
63
|
+
case '$endsWith':
|
|
64
|
+
return { $regex: `${escapeRegExp(`${operand}`)}$` };
|
|
65
|
+
case '$between':
|
|
66
|
+
if (!Array.isArray(operand) || operand.length !== 2) {
|
|
67
|
+
throw new UnsupportedArgumentError(`criteria:$between:${field}`);
|
|
68
|
+
}
|
|
69
|
+
return { $gte: operand[0], $lte: operand[1] };
|
|
70
|
+
/** Array membership, mirroring the postgres array operators `@>`, `<@` and `&&`. */
|
|
71
|
+
case '$contains':
|
|
72
|
+
return { $all: asArray(operand) };
|
|
73
|
+
case '$contained':
|
|
74
|
+
/**
|
|
75
|
+
* Nothing outside the operand list may appear in the field. The `$ne: null` keeps an
|
|
76
|
+
* absent field out of the result — `$not` alone is satisfied by a document that has no
|
|
77
|
+
* such field at all, where the relational store answers NULL and matches nothing.
|
|
78
|
+
*/
|
|
79
|
+
return { $not: { $elemMatch: { $nin: asArray(operand) } }, $ne: null };
|
|
80
|
+
case '$overlaps':
|
|
81
|
+
return { $in: asArray(operand) };
|
|
82
|
+
default:
|
|
83
|
+
throw new UnsupportedArgumentError(`criteria-operator:${operator}`);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* An object naming at least one `$` key is a spec, not a value to compare against. A Date and
|
|
88
|
+
* an array are values even though both are objects.
|
|
89
|
+
*/
|
|
90
|
+
const isOperatorSpec = (value) => value != null && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date)
|
|
91
|
+
&& Object.keys(value).some(key => key.startsWith('$'));
|
|
92
|
+
/**
|
|
93
|
+
* One field's criteria as mongo conditions. Operators that translate into the same mongo key —
|
|
94
|
+
* `$like` and `$startsWith` both produce `$regex` — are emitted as separate conditions rather
|
|
95
|
+
* than merged, so neither silently overwrites the other.
|
|
96
|
+
*/
|
|
97
|
+
const fieldConditions = (field, spec) => {
|
|
98
|
+
const merged = {};
|
|
99
|
+
const conditions = [];
|
|
100
|
+
for (const [operator, operand] of Object.entries(spec)) {
|
|
101
|
+
if (operand === undefined) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const fragment = operatorToFilter(field, operator, operand);
|
|
105
|
+
if (Object.keys(fragment).some(key => key in merged)) {
|
|
106
|
+
conditions.push({ [field]: fragment });
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
Object.assign(merged, fragment);
|
|
110
|
+
}
|
|
111
|
+
if (Object.keys(merged).length > 0) {
|
|
112
|
+
conditions.unshift({ [field]: merged });
|
|
113
|
+
}
|
|
114
|
+
return conditions;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Flatten the conditions into one filter document. Mongo reads sibling keys as a conjunction,
|
|
118
|
+
* so only the ones that would overwrite an earlier key — two `$regex` expressions over the
|
|
119
|
+
* same field, say — need an explicit `$and`.
|
|
120
|
+
*/
|
|
121
|
+
const flatten = (conditions) => {
|
|
122
|
+
const filter = {};
|
|
123
|
+
const conflicting = [];
|
|
124
|
+
for (const condition of conditions) {
|
|
125
|
+
if (Object.keys(condition).some(key => key in filter)) {
|
|
126
|
+
conflicting.push(condition);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
Object.assign(filter, condition);
|
|
130
|
+
}
|
|
131
|
+
if (conflicting.length > 0) {
|
|
132
|
+
filter.$and = [...(Array.isArray(filter.$and) ? filter.$and : []), ...conflicting];
|
|
133
|
+
}
|
|
134
|
+
return filter;
|
|
135
|
+
};
|
|
136
|
+
const build = (criteria) => {
|
|
137
|
+
const conditions = [];
|
|
138
|
+
for (const [key, raw] of Object.entries(criteria ?? {})) {
|
|
139
|
+
/**
|
|
140
|
+
* An untouched filter must never empty a list, so `undefined` is skipped rather than
|
|
141
|
+
* compared. `null` asks for the absence of a value.
|
|
142
|
+
*/
|
|
143
|
+
if (raw === undefined) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (key === '$and' || key === '$or') {
|
|
147
|
+
const parts = (Array.isArray(raw) ? raw : [raw])
|
|
148
|
+
.map(part => build(part))
|
|
149
|
+
.filter(part => part.length > 0)
|
|
150
|
+
.map(part => flatten(part));
|
|
151
|
+
if (parts.length > 0) {
|
|
152
|
+
conditions.push(key === '$and' ? { $and: parts } : { $or: parts });
|
|
153
|
+
}
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (key === '$not') {
|
|
157
|
+
const inner = build(raw);
|
|
158
|
+
if (inner.length > 0) {
|
|
159
|
+
/** Mongo has no top level `$not`; `$nor` over a single branch is its negation. */
|
|
160
|
+
conditions.push({ $nor: [flatten(inner)] });
|
|
161
|
+
}
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (raw === null) {
|
|
165
|
+
conditions.push({ [key]: { $eq: null } });
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (isOperatorSpec(raw)) {
|
|
169
|
+
conditions.push(...fieldConditions(key, raw));
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (Array.isArray(raw)) {
|
|
173
|
+
/**
|
|
174
|
+
* A bare array means "any of these", exactly as it does against a relational store.
|
|
175
|
+
* Exact array equality stays reachable as `{ $eq: [...] }`.
|
|
176
|
+
*/
|
|
177
|
+
conditions.push({ [key]: { $in: raw } });
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
conditions.push({ [key]: raw });
|
|
181
|
+
}
|
|
182
|
+
return conditions;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Translate `Criteria<T>` into the filter a collection takes.
|
|
186
|
+
*
|
|
187
|
+
* Two passes: the shared operator vocabulary becomes mongo expressions, then
|
|
188
|
+
* {@link marshalCriteria} converts the values addressed at `_id` or at a declared reference
|
|
189
|
+
* into `ObjectId`s and maps the `id` alias onto `_id`. Both halves are needed — a criteria
|
|
190
|
+
* object carries string ids and portable operators, a collection stores neither.
|
|
191
|
+
*
|
|
192
|
+
* An empty result is an empty filter, which matches everything. Callers that must not act on
|
|
193
|
+
* "everything" — `purge` — check for it themselves.
|
|
194
|
+
*
|
|
195
|
+
* @throws {UnsupportedArgumentError}
|
|
196
|
+
*/
|
|
197
|
+
export const criteriaToFilter = (criteria, refs) => {
|
|
198
|
+
const conditions = build(criteria);
|
|
199
|
+
if (conditions.length < 1) {
|
|
200
|
+
return {};
|
|
201
|
+
}
|
|
202
|
+
return marshalCriteria(flatten(conditions), refs) ?? {};
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Translate `Sort<T>[]` into a mongo sort document. A bare field name is ascending, and `id`
|
|
206
|
+
* addresses `_id` — documents never store an `id` field, so sorting by the name records carry
|
|
207
|
+
* would silently order by nothing.
|
|
208
|
+
*/
|
|
209
|
+
export const sortToMongo = (sort) => {
|
|
210
|
+
if (sort == null || sort.length < 1) {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
return sort.reduce((order, entry) => {
|
|
214
|
+
const [field, direction] = typeof entry === 'string'
|
|
215
|
+
? [entry, 1]
|
|
216
|
+
: [entry.field, entry.order === 'desc' ? -1 : 1];
|
|
217
|
+
order[field === 'id' ? '_id' : field] = direction;
|
|
218
|
+
return order;
|
|
219
|
+
}, {});
|
|
220
|
+
};
|
|
221
|
+
//# sourceMappingURL=criteria.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"criteria.js","sourceRoot":"","sources":["../../src/utils/criteria.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAK7D,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAE3C;;;;;GAKG;AACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAA;AAE7F,MAAM,YAAY,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAA;AAE5F;;;;GAIG;AACH,MAAM,YAAY,GAAG,CAAC,OAAe,EAAU,EAAE;IAC/C,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACpD,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAE,CAAA;QAC5B,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;YAChD,MAAM,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,CAAE,CAAC,CAAA;YACzC,SAAQ;QACV,CAAC;QACD,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YAAC,MAAM,IAAI,IAAI,CAAC;YAAC,SAAQ;QAAC,CAAC;QAC9C,IAAI,IAAI,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AC/B,cAAc,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA"}
|
package/build/utils/index.js
CHANGED
package/build/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/utils/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,QAAQ,EAA6B,cAAc,EAAkB,MAAM,oBAAoB,CAAA;AAC7G,OAAO,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAK7C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/utils/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,QAAQ,EAA6B,cAAc,EAAkB,MAAM,oBAAoB,CAAA;AAC7G,OAAO,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAK7C,OAAO,KAAK,EAAiC,OAAO,EAAE,MAAM,aAAa,CAAA;AAmBzE;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,OAClB,EAAE,cAAc,UAAU,UAAU,QAAQ,WAAW,YAAY,CAAC,GAAG,CAAC,QAAQ,MAAM,KACzF,OA6BF,CAAA;AAqBD;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,OAC9B,EAAE,MAAM,OAAO,SAAQ,MAAM,KAChC,cAAc,CAAC,OAAO,CAwFxB,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DEF_MIGRATION_POLL, DEF_MIGRATION_WAIT, DEF_MIGRATIONS_COLLECTION, MONGO_DUPLICATE_KEY } from '../consts.js';
|
|
2
|
+
import { DEFAULT_DB_ALIAS } from '../consts.js';
|
|
2
3
|
import { mongoCollectionName } from './name.js';
|
|
3
4
|
const isDuplicateKey = (error) => error?.code === MONGO_DUPLICATE_KEY;
|
|
4
5
|
/**
|
|
@@ -15,7 +16,21 @@ export const makeMongoTx = (db, collection, config, context, self) => {
|
|
|
15
16
|
if (alias == null || alias === self) {
|
|
16
17
|
return collection.collectionName;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
// Name the target's collection from the target's OWN db config. Resources registered under
|
|
20
|
+
// different db aliases can share one database while carrying different `resourcePrefix`es, and
|
|
21
|
+
// naming one of them with this migration's config silently addresses a collection that does not
|
|
22
|
+
// exist — reads come back empty and writes create a decoy beside the real thing.
|
|
23
|
+
const target = context.resource(alias);
|
|
24
|
+
let targetConfig = config;
|
|
25
|
+
try {
|
|
26
|
+
const mongo = context.service(target.serviceAlias ?? target.dbAlias ?? DEFAULT_DB_ALIAS);
|
|
27
|
+
targetConfig = mongo.config(target.dbAlias ?? DEFAULT_DB_ALIAS) ?? config;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// A resource whose service is not reachable from here keeps the caller's config — the
|
|
31
|
+
// historical behaviour, and correct whenever both share one alias.
|
|
32
|
+
}
|
|
33
|
+
return mongoCollectionName(targetConfig, target);
|
|
19
34
|
};
|
|
20
35
|
return {
|
|
21
36
|
db,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/utils/migrations.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,kBAAkB,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,mBAAmB,EACvF,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAc/C,MAAM,cAAc,GAAG,CAAC,KAAc,EAAW,EAAE,CAChD,KAAkC,EAAE,IAAI,KAAK,mBAAmB,CAAA;AAEnE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,EAAM,EAAE,UAAsB,EAAE,MAAgB,EAAE,OAA0B,EAAE,IAAY,EACjF,EAAE;IACX,MAAM,GAAG,GAAG,CAAC,KAAc,EAAU,EAAE;QACrC,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACpC,OAAO,UAAU,CAAC,cAAc,CAAA;QAClC,CAAC;QAED,
|
|
1
|
+
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/utils/migrations.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,kBAAkB,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,mBAAmB,EACvF,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAc/C,MAAM,cAAc,GAAG,CAAC,KA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;oBACpB,KAAK,EAAE,SAAS,CAAC,KAAK;oBACtB,QAAQ,EAAE,SAAS,CAAC,QAAQ;oBAC5B,QAAQ,EAAE,KAAK;oBACf,SAAS,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC;oBAC5B,WAAW,EAAE,IAAI;oBACjB,UAAU,EAAE,IAAI;iBACjB,CAAC,CAAA;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;oBAC3B,MAAM,KAAK,CAAA;gBACb,CAAC;gBAED,OAAO,MAAM,YAAY,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,CAAA;YAC5D,CAAC;YAED,IAAI,CAAC;gBACH,MAAM,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;YAC3B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf;;;;mBAIG;gBACH,MAAM,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;gBAChF,MAAM,KAAK,CAAA;YACb,CAAC;YAED,MAAM,MAAM,EAAE,CAAC,SAAS,CACtB,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,EAC/B,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,IAAI,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,EAAE,CACxE,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|
package/build/utils/refs.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ListCriteria } from '@owlmeans/resource';
|
|
2
1
|
import type { Collection, Document } from 'mongodb';
|
|
3
2
|
import type { MongoReference, MongoTx } from '../types.js';
|
|
4
3
|
export declare const isObjectIdHex: (value: unknown) => value is string;
|
|
@@ -19,7 +18,7 @@ export declare const demarshalReference: (value: unknown) => unknown;
|
|
|
19
18
|
/** Convert every declared reference of a fetched document back to string ids, in place. */
|
|
20
19
|
export declare const demarshalRefs: <T extends {}>(record: T, refs: Map<string, MongoReference>) => T;
|
|
21
20
|
/**
|
|
22
|
-
* Convert
|
|
21
|
+
* Convert a mongo filter the way records are converted: values addressed at `_id` or at a
|
|
23
22
|
* declared reference become `ObjectId`s, and the `id` alias records actually carry is
|
|
24
23
|
* mapped onto `_id` — documents never store `id`, so before this mapping such criteria
|
|
25
24
|
* silently matched nothing.
|
|
@@ -27,8 +26,11 @@ export declare const demarshalRefs: <T extends {}>(record: T, refs: Map<string,
|
|
|
27
26
|
* Tolerant by design: a value that is not 24 hex passes through unconverted. Criteria are
|
|
28
27
|
* matched against the collection, and against an `ObjectId` typed field a stray string
|
|
29
28
|
* matches nothing — which is exactly what it matched before the field was converted.
|
|
29
|
+
*
|
|
30
|
+
* Operators arrive already in mongo's own vocabulary — {@link criteriaToFilter} translates
|
|
31
|
+
* the portable one first, so this pass only has to convert values.
|
|
30
32
|
*/
|
|
31
|
-
export declare const marshalCriteria: (criteria:
|
|
33
|
+
export declare const marshalCriteria: (criteria: Document | undefined, refs: Map<string, MongoReference>) => Document | undefined;
|
|
32
34
|
/**
|
|
33
35
|
* Criteria for addressing a single record by a field — `get`/`load`/`update`/`delete`.
|
|
34
36
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../src/utils/refs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../src/utils/refs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAS1D,eAAO,MAAM,aAAa,UAAW,OAAO,KAAG,KAAK,IAAI,MACR,CAAA;AAEhD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,UAAW,MAAM,SAAS,OAAO,KAAG,OAehE,CAAA;AAED,kGAAkG;AAClG,eAAO,MAAM,kBAAkB,UAAW,OAAO,KAAG,OASnD,CAAA;AAED,2FAA2F;AAC3F,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,EAAE,UAAU,CAAC,QAAQ,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,KAAG,CAY1F,CAAA;AA4BD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,aAChB,QAAQ,GAAG,SAAS,QAAQ,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,KAChE,QAAQ,GAAG,SAkBb,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,UACpB,MAAM,MAAM,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,KAC3D,QAYF,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,UAAW,MAAM,KAAG,MAA2B,CAAA;AAE5E,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,UAAW,MAAM,UAAgB,OAAO,KAAG,OAAO,CAAC,IAAI,CAEnF,CAAA;AAeD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qBAAqB,eAAsB,UAAU,SAAS,MAAM,KAAG,OAAO,CAAC,MAAM,CAmBjG,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,eAClB,UAAU,QAAQ,cAAc,EAAE,SAAS,MAAM,KAC5D,OAAO,CAAC,IAAI,CAcd,CAAA"}
|
package/build/utils/refs.js
CHANGED
|
@@ -77,7 +77,7 @@ const marshalCriteriaValue = (value) => {
|
|
|
77
77
|
return value;
|
|
78
78
|
};
|
|
79
79
|
/**
|
|
80
|
-
* Convert
|
|
80
|
+
* Convert a mongo filter the way records are converted: values addressed at `_id` or at a
|
|
81
81
|
* declared reference become `ObjectId`s, and the `id` alias records actually carry is
|
|
82
82
|
* mapped onto `_id` — documents never store `id`, so before this mapping such criteria
|
|
83
83
|
* silently matched nothing.
|
|
@@ -85,6 +85,9 @@ const marshalCriteriaValue = (value) => {
|
|
|
85
85
|
* Tolerant by design: a value that is not 24 hex passes through unconverted. Criteria are
|
|
86
86
|
* matched against the collection, and against an `ObjectId` typed field a stray string
|
|
87
87
|
* matches nothing — which is exactly what it matched before the field was converted.
|
|
88
|
+
*
|
|
89
|
+
* Operators arrive already in mongo's own vocabulary — {@link criteriaToFilter} translates
|
|
90
|
+
* the portable one first, so this pass only has to convert values.
|
|
88
91
|
*/
|
|
89
92
|
export const marshalCriteria = (criteria, refs) => {
|
|
90
93
|
if (criteria == null) {
|
package/build/utils/refs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refs.js","sourceRoot":"","sources":["../../src/utils/refs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"refs.js","sourceRoot":"","sources":["../../src/utils/refs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAKlC;;;;GAIG;AACH,MAAM,KAAK,GAAG,mBAAmB,CAAA;AAEjC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAc,EAAmB,EAAE,CAC/D,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAE,KAAc,EAAW,EAAE;IACzE,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO,KAAK,CAAA;IACd,CAAC;IACD,IAAI,KAAK,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
|
{
|
|
2
2
|
"name": "@owlmeans/mongo-resource",
|
|
3
|
-
"version": "0.1.18-rc.
|
|
3
|
+
"version": "0.1.18-rc.21",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"mongodb": "*"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@owlmeans/context": "^0.1.18-rc.
|
|
30
|
-
"@owlmeans/resource": "^0.1.18-rc.
|
|
31
|
-
"@owlmeans/server-context": "^0.1.18-rc.
|
|
29
|
+
"@owlmeans/context": "^0.1.18-rc.17",
|
|
30
|
+
"@owlmeans/resource": "^0.1.18-rc.18",
|
|
31
|
+
"@owlmeans/server-context": "^0.1.18-rc.21"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@owlmeans/dep-config": "workspace:*",
|
|
35
|
-
"@owlmeans/test-integration": "^0.1.18-rc.
|
|
36
|
-
"@types/bun": "^1.
|
|
35
|
+
"@owlmeans/test-integration": "^0.1.18-rc.17",
|
|
36
|
+
"@types/bun": "^1.4.0",
|
|
37
37
|
"@types/node": "^26.1.0",
|
|
38
38
|
"mongodb": "^7.5.0",
|
|
39
39
|
"nodemon": "^3.1.14",
|
package/src/consts.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
|
|
2
2
|
export const DEFAULT_DB_ALIAS = 'mongo'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Page size a `list` call gets when it asks for none. Mongo cannot afford an unbounded read
|
|
6
|
+
* of a collection by omission, so paging is the default here — `list(where, { size: 0 })`
|
|
7
|
+
* asks for the whole result set, explicitly and greppably.
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_PAGE_SIZE = 100
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* Collection that records which code-registered migrations have already been applied.
|
|
8
13
|
*
|
|
9
|
-
* One ledger per database, which is the right boundary:
|
|
10
|
-
*
|
|
11
|
-
* data and dropping the database drops the ledger with it.
|
|
14
|
+
* One ledger per database, which is the right boundary: it sits beside the data its
|
|
15
|
+
* migrations changed, so dropping the database drops the ledger with it.
|
|
12
16
|
*/
|
|
13
17
|
export const DEF_MIGRATIONS_COLLECTION = '_owlmeans_migrations'
|
|
14
18
|
|
package/src/declarations.ts
CHANGED
|
@@ -12,12 +12,11 @@ export interface MongoDeclaration {
|
|
|
12
12
|
/**
|
|
13
13
|
* Per-alias migration store, held at module scope rather than on the resource object.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* by alias makes the declarations outlive any number of context switches.
|
|
15
|
+
* A maker may run more than once for the same alias — a custom maker wrapping the built-in
|
|
16
|
+
* one, a maker called again by an app or a spec. Keying the declarations by alias makes
|
|
17
|
+
* that a no-op: every run reads and extends the same registry, so nothing a caller declared
|
|
18
|
+
* by chaining onto an earlier resource object is lost. Losing a migration is silent — the
|
|
19
|
+
* data transformation simply never runs — which is why the store cannot live on the object.
|
|
21
20
|
*/
|
|
22
21
|
const declarations: Map<string, MongoDeclaration> = new Map()
|
|
23
22
|
|