monsqlize 3.2.0 → 3.3.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 +7 -2
- package/README.md +25 -1
- package/changelogs/v3.3.0.md +29 -0
- package/dist/cjs/cli/data-task.cjs +3 -2
- package/dist/cjs/index.cjs +27 -20
- package/dist/esm/index.mjs +28 -20
- package/dist/types/model.d.mts +39 -0
- package/dist/types/model.d.ts +39 -0
- package/dist/types/monsqlize.d.mts +28 -9
- package/dist/types/monsqlize.d.ts +28 -9
- package/dist/types/runtime.d.mts +3 -1
- package/dist/types/runtime.d.ts +3 -1
- package/licenses/production-dependencies.json +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
-
> Summary index — the
|
|
4
|
-
> **Last updated**: 2026-08-
|
|
3
|
+
> Summary index — the newest versioned release details are in [changelogs/v3.3.0.md](./changelogs/v3.3.0.md); the earlier RC note remains an unpublished rehearsal archive.
|
|
4
|
+
> **Last updated**: 2026-08-11
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
+
## Unreleased
|
|
9
|
+
|
|
10
|
+
No changes are currently recorded after v3.3.0.
|
|
11
|
+
|
|
8
12
|
## Version Overview
|
|
9
13
|
|
|
10
14
|
| Version | Date | Summary | Details |
|
|
11
15
|
|---------|------|---------|---------|
|
|
16
|
+
| [v3.3.0](./changelogs/v3.3.0.md) | 2026-08-11 | Minor: static Model schema type inference, schema-dsl 3.0.4, and silent-by-default Pool logging | [View](./changelogs/v3.3.0.md) |
|
|
12
17
|
| [v3.2.0](./changelogs/v3.2.0.md) | 2026-08-07 | Minor: Vector Search APIs, relation-safe Model deletion, and relation projection improvements | [View](./changelogs/v3.2.0.md) |
|
|
13
18
|
| [v3.1.0](./changelogs/v3.1.0.md) | 2026-07-15 | Minor: schema-dsl v3 GA consumption, canonical validation errors, and normalized full-document persistence | [View](./changelogs/v3.1.0.md) |
|
|
14
19
|
| [v3.0.0](./changelogs/v3.0.0.md) | 2026-07-14 | Major: two-instance preview/apply/restore data tasks, write-path policy, runtime-scoped schema DSL, stricter OCC/sync/query contracts, and release recovery controls | [View](./changelogs/v3.0.0.md) |
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Upgrade and security: [Migration Guide](./MIGRATION.md) · [Private Vulnerabilit
|
|
|
14
14
|
|
|
15
15
|
The npm `latest` dist-tag and GitHub Pages are the stable channel; `main` may contain the next release. Pages deployment accepts only a versioned Git tag whose package version is already present on npm, so unpublished APIs are not promoted as stable documentation.
|
|
16
16
|
|
|
17
|
-
This source
|
|
17
|
+
This development source is pinned to verified registry `schema-dsl@3.0.4`. The v3 package remains subject to the full release gate before an immutable tag and npm publication.
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
20
|
npm install monsqlize
|
|
@@ -234,6 +234,30 @@ const user = await User.insertOne({
|
|
|
234
234
|
});
|
|
235
235
|
```
|
|
236
236
|
|
|
237
|
+
### TypeScript Schema Inference
|
|
238
|
+
|
|
239
|
+
For a static object-literal schema, `defineModel()` carries the schema-derived document type from definition through registration to runtime access. Registration remains explicit, so it does not change the process-wide Model registry behavior.
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
import { defineModel, Model } from 'monsqlize';
|
|
243
|
+
|
|
244
|
+
const User = defineModel('users', {
|
|
245
|
+
schema: {
|
|
246
|
+
email: 'email!',
|
|
247
|
+
age: 'number?'
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
Model.define(User);
|
|
252
|
+
|
|
253
|
+
const users = msq.model(User);
|
|
254
|
+
const user = await users.findOne({ email: 'ada@example.com' });
|
|
255
|
+
// user?.email: string
|
|
256
|
+
// user?.age: number | undefined
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Call `Model.define(User)` before `model(User)`, `use(...).model(User)`, or `pool(...).model(User)`. Callback-based or dynamically composed schemas continue to use the existing explicit generic API, such as `msq.model<UserDocument>('users')`; managed fields added by timestamps, soft delete, versioning, relations, or virtuals are not synthesized into this schema-derived type.
|
|
260
|
+
|
|
237
261
|
When a service needs runtime-local custom types, messages, locale, or an already-owned schema-dsl runtime, configure `schemaDsl` on the MonSQLize instance:
|
|
238
262
|
|
|
239
263
|
```js
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# monSQLize v3.3.0
|
|
2
|
+
|
|
3
|
+
> Release date: 2026-08-11
|
|
4
|
+
|
|
5
|
+
## Highlights
|
|
6
|
+
|
|
7
|
+
- Added schema-derived TypeScript document inference for static Model definitions.
|
|
8
|
+
- Made Pool logging silent by default while preserving explicit logger delivery.
|
|
9
|
+
|
|
10
|
+
## Added
|
|
11
|
+
|
|
12
|
+
- Added `defineModel()` and `ModelDescriptor` so object-literal `schema` definitions carry their inferred document type through `Model.define()`, `model()`, `scopedModel()`, `use().model()`, and `pool().model()`.
|
|
13
|
+
- Added CJS, ESM, public-type, compatibility, pack-consumer, and registry-consumer verification for the descriptor API.
|
|
14
|
+
|
|
15
|
+
## Changed
|
|
16
|
+
|
|
17
|
+
- Updated the exact production dependency from `schema-dsl@3.0.0` to `schema-dsl@3.0.4`.
|
|
18
|
+
- Extended current-version validation so README and bilingual dependency-governance documents must match the exact `schema-dsl` version in `package.json`.
|
|
19
|
+
|
|
20
|
+
## Fixed
|
|
21
|
+
|
|
22
|
+
- Forwarded the configured `ConnectionPoolManager` logger to `PoolSelector`, `HealthChecker`, and `PoolStatsManager`.
|
|
23
|
+
- Removed implicit `console` fallback logging from Pool helpers when no logger is configured.
|
|
24
|
+
|
|
25
|
+
## Compatibility boundaries
|
|
26
|
+
|
|
27
|
+
- This is a backward-compatible minor release. Existing string-based Model registration/access, manual TypeScript generics, Pool APIs, and explicit process-wide Model registry lifecycle remain unchanged.
|
|
28
|
+
- `defineModel()` creates a static descriptor; it does not register the Model. Call `Model.define(descriptor)` before binding it through a runtime accessor.
|
|
29
|
+
- Callback or dynamically composed schemas continue to use explicit document generics. Schema-derived types do not synthesize timestamp, soft-delete, version, relation, or virtual fields.
|
|
@@ -31,7 +31,7 @@ var import_node_url = require("node:url");
|
|
|
31
31
|
// package.json
|
|
32
32
|
var package_default = {
|
|
33
33
|
name: "monsqlize",
|
|
34
|
-
version: "3.
|
|
34
|
+
version: "3.3.0",
|
|
35
35
|
description: "TypeScript production data runtime layer for MongoDB today, with cache, transactions, pools, models, sync, and observability",
|
|
36
36
|
type: "commonjs",
|
|
37
37
|
main: "./dist/cjs/index.cjs",
|
|
@@ -52,6 +52,7 @@ var package_default = {
|
|
|
52
52
|
"./package.json": "./package.json"
|
|
53
53
|
},
|
|
54
54
|
files: [
|
|
55
|
+
"changelogs/v3.3.0.md",
|
|
55
56
|
"changelogs/v3.2.0.md",
|
|
56
57
|
"changelogs/v3.1.14.md",
|
|
57
58
|
"changelogs/v3.1.13.md",
|
|
@@ -191,7 +192,7 @@ var package_default = {
|
|
|
191
192
|
"cache-hub": "2.2.4",
|
|
192
193
|
ioredis: "5.11.1",
|
|
193
194
|
mongodb: "6.21.0",
|
|
194
|
-
"schema-dsl": "3.0.
|
|
195
|
+
"schema-dsl": "3.0.4",
|
|
195
196
|
ssh2: "1.17.0"
|
|
196
197
|
},
|
|
197
198
|
overrides: {
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -549,6 +549,9 @@ function normalizePopulateConfig(path5) {
|
|
|
549
549
|
}
|
|
550
550
|
|
|
551
551
|
// src/capabilities/model/model-registry.ts
|
|
552
|
+
function defineModel(collectionName, definition) {
|
|
553
|
+
return { collectionName, definition };
|
|
554
|
+
}
|
|
552
555
|
var Model = class {
|
|
553
556
|
static {
|
|
554
557
|
// collection name → registered model definition
|
|
@@ -563,21 +566,19 @@ var Model = class {
|
|
|
563
566
|
/** Collection names that have been redefined (used by the runtime to trigger hot-reload). */
|
|
564
567
|
this._redefinedNames = /* @__PURE__ */ new Set();
|
|
565
568
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
* Validates the definition and resolves the timestamps option.
|
|
570
|
-
*/
|
|
571
|
-
static define(collectionName, definition) {
|
|
569
|
+
static define(collectionNameOrDescriptor, definition) {
|
|
570
|
+
const collectionName = typeof collectionNameOrDescriptor === "string" ? collectionNameOrDescriptor : collectionNameOrDescriptor.collectionName;
|
|
571
|
+
const modelDefinition = typeof collectionNameOrDescriptor === "string" ? definition : collectionNameOrDescriptor.definition;
|
|
572
572
|
const normalizedName = validateCollectionName(collectionName);
|
|
573
573
|
if (this.registry.has(normalizedName)) {
|
|
574
574
|
throw createError(ErrorCodes.MODEL_ALREADY_EXISTS, `Model '${normalizedName}' is already defined.`);
|
|
575
575
|
}
|
|
576
|
-
validateDefinition(
|
|
577
|
-
|
|
576
|
+
validateDefinition(modelDefinition);
|
|
577
|
+
const resolvedDefinition = modelDefinition;
|
|
578
|
+
processTimestamps(resolvedDefinition);
|
|
578
579
|
this.registry.set(normalizedName, {
|
|
579
580
|
collectionName: normalizedName,
|
|
580
|
-
definition
|
|
581
|
+
definition: resolvedDefinition
|
|
581
582
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
582
583
|
});
|
|
583
584
|
this.bumpRevision(normalizedName);
|
|
@@ -7677,6 +7678,7 @@ var CountQueue = class {
|
|
|
7677
7678
|
};
|
|
7678
7679
|
|
|
7679
7680
|
// src/capabilities/pool/pool-health-checker.ts
|
|
7681
|
+
var SILENT_HEALTH_CHECKER_LOGGER = {};
|
|
7680
7682
|
var HealthChecker = class {
|
|
7681
7683
|
constructor(options = {}) {
|
|
7682
7684
|
this._healthStatus = /* @__PURE__ */ new Map();
|
|
@@ -7686,7 +7688,7 @@ var HealthChecker = class {
|
|
|
7686
7688
|
this._inProgress = /* @__PURE__ */ new Set();
|
|
7687
7689
|
this._started = false;
|
|
7688
7690
|
this._poolManager = options.poolManager ?? null;
|
|
7689
|
-
this._logger = options.logger ??
|
|
7691
|
+
this._logger = options.logger ?? SILENT_HEALTH_CHECKER_LOGGER;
|
|
7690
7692
|
}
|
|
7691
7693
|
register(poolNameOrConfig, configOrClient) {
|
|
7692
7694
|
let poolName;
|
|
@@ -7810,6 +7812,7 @@ var HealthChecker = class {
|
|
|
7810
7812
|
};
|
|
7811
7813
|
|
|
7812
7814
|
// src/capabilities/pool/pool-selector.ts
|
|
7815
|
+
var SILENT_POOL_SELECTOR_LOGGER = {};
|
|
7813
7816
|
var POOL_STRATEGY_ALIASES = {
|
|
7814
7817
|
"round-robin": "roundRobin",
|
|
7815
7818
|
"least-connections": "leastConnections",
|
|
@@ -7823,7 +7826,7 @@ var PoolSelector = class {
|
|
|
7823
7826
|
constructor(options = {}) {
|
|
7824
7827
|
this._roundRobinIndex = /* @__PURE__ */ new Map();
|
|
7825
7828
|
this._strategy = normalizePoolStrategy(options.strategy);
|
|
7826
|
-
this._logger = options.logger ??
|
|
7829
|
+
this._logger = options.logger ?? SILENT_POOL_SELECTOR_LOGGER;
|
|
7827
7830
|
}
|
|
7828
7831
|
select(pools, context) {
|
|
7829
7832
|
if (!pools || pools.length === 0) {
|
|
@@ -7954,11 +7957,12 @@ var PoolSelector = class {
|
|
|
7954
7957
|
};
|
|
7955
7958
|
|
|
7956
7959
|
// src/capabilities/pool/pool-stats-manager.ts
|
|
7960
|
+
var SILENT_POOL_STATS_LOGGER = {};
|
|
7957
7961
|
var PoolStatsManager = class {
|
|
7958
7962
|
constructor(options = {}) {
|
|
7959
7963
|
this._stats = /* @__PURE__ */ new Map();
|
|
7960
7964
|
this._buffer = [];
|
|
7961
|
-
this._logger = options.logger ??
|
|
7965
|
+
this._logger = options.logger ?? SILENT_POOL_STATS_LOGGER;
|
|
7962
7966
|
this._batchInterval = setInterval(() => {
|
|
7963
7967
|
this._flush();
|
|
7964
7968
|
}, 100);
|
|
@@ -8206,9 +8210,9 @@ var ConnectionPoolManager = class {
|
|
|
8206
8210
|
this._fallbackConfig = this.fallback;
|
|
8207
8211
|
this._fallback = this.fallback;
|
|
8208
8212
|
this._pools = this.pools;
|
|
8209
|
-
this._selector = new PoolSelector({ strategy: this.strategy });
|
|
8210
|
-
this._healthChecker = new HealthChecker({ poolManager: this });
|
|
8211
|
-
this._stats = new PoolStatsManager({ logger:
|
|
8213
|
+
this._selector = new PoolSelector({ strategy: this.strategy, logger: this.logger ?? void 0 });
|
|
8214
|
+
this._healthChecker = new HealthChecker({ poolManager: this, logger: this.logger ?? void 0 });
|
|
8215
|
+
this._stats = new PoolStatsManager({ logger: this.logger ?? void 0 });
|
|
8212
8216
|
}
|
|
8213
8217
|
/**
|
|
8214
8218
|
* Add a connection pool.
|
|
@@ -12783,10 +12787,10 @@ function assertCompatPoolExists(poolManager, poolName) {
|
|
|
12783
12787
|
function createPoolScope(runtime, poolName) {
|
|
12784
12788
|
return {
|
|
12785
12789
|
collection: (name) => runtime.scopedCollection(name, { pool: poolName }),
|
|
12786
|
-
model: (
|
|
12790
|
+
model: (model) => runtime.scopedModel(model, { pool: poolName }),
|
|
12787
12791
|
use: (dbName) => ({
|
|
12788
12792
|
collection: (name) => runtime.scopedCollection(name, { pool: poolName, database: dbName }),
|
|
12789
|
-
model: (
|
|
12793
|
+
model: (model) => runtime.scopedModel(model, { pool: poolName, database: dbName })
|
|
12790
12794
|
})
|
|
12791
12795
|
};
|
|
12792
12796
|
}
|
|
@@ -16942,7 +16946,7 @@ var MonSQLizeRuntime = class {
|
|
|
16942
16946
|
requireCompatDbInstance(this);
|
|
16943
16947
|
return {
|
|
16944
16948
|
collection: (collectionName) => this.scopedCollection(collectionName, { database: name }),
|
|
16945
|
-
model: (
|
|
16949
|
+
model: (model) => this.scopedModel(model, { database: name })
|
|
16946
16950
|
};
|
|
16947
16951
|
}
|
|
16948
16952
|
pool(poolName) {
|
|
@@ -16974,7 +16978,8 @@ var MonSQLizeRuntime = class {
|
|
|
16974
16978
|
});
|
|
16975
16979
|
}
|
|
16976
16980
|
// Model accessors ---------------------------------------------------------
|
|
16977
|
-
scopedModel(
|
|
16981
|
+
scopedModel(model, options = {}) {
|
|
16982
|
+
const name = typeof model === "string" ? model : model.collectionName;
|
|
16978
16983
|
const dbInstance = requireCompatDbInstance(this);
|
|
16979
16984
|
if (this._client) {
|
|
16980
16985
|
return this.createModelInstance(name, options);
|
|
@@ -16998,7 +17003,8 @@ var MonSQLizeRuntime = class {
|
|
|
16998
17003
|
schemaEngine: this._schemaDslEngine
|
|
16999
17004
|
});
|
|
17000
17005
|
}
|
|
17001
|
-
model(
|
|
17006
|
+
model(model) {
|
|
17007
|
+
const name = typeof model === "string" ? model : model.collectionName;
|
|
17002
17008
|
if (this._client) {
|
|
17003
17009
|
this.ensureConnected();
|
|
17004
17010
|
return this.createModelInstance(name, {
|
|
@@ -18799,6 +18805,7 @@ MonSQLize.PoolSelector = PoolSelector;
|
|
|
18799
18805
|
MonSQLize.PoolStats = PoolStatsManager;
|
|
18800
18806
|
MonSQLize.validatePoolConfig = validatePoolConfig;
|
|
18801
18807
|
MonSQLize.validatePoolConfigSafe = validatePoolConfigSafe;
|
|
18808
|
+
MonSQLize.defineModel = defineModel;
|
|
18802
18809
|
MonSQLize.Model = Model;
|
|
18803
18810
|
MonSQLize.expr = expr;
|
|
18804
18811
|
MonSQLize.createExpression = createExpression;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -532,6 +532,9 @@ function normalizePopulateConfig(path5) {
|
|
|
532
532
|
}
|
|
533
533
|
|
|
534
534
|
// src/capabilities/model/model-registry.ts
|
|
535
|
+
function defineModel(collectionName, definition) {
|
|
536
|
+
return { collectionName, definition };
|
|
537
|
+
}
|
|
535
538
|
var Model = class {
|
|
536
539
|
static {
|
|
537
540
|
// collection name → registered model definition
|
|
@@ -546,21 +549,19 @@ var Model = class {
|
|
|
546
549
|
/** Collection names that have been redefined (used by the runtime to trigger hot-reload). */
|
|
547
550
|
this._redefinedNames = /* @__PURE__ */ new Set();
|
|
548
551
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
* Validates the definition and resolves the timestamps option.
|
|
553
|
-
*/
|
|
554
|
-
static define(collectionName, definition) {
|
|
552
|
+
static define(collectionNameOrDescriptor, definition) {
|
|
553
|
+
const collectionName = typeof collectionNameOrDescriptor === "string" ? collectionNameOrDescriptor : collectionNameOrDescriptor.collectionName;
|
|
554
|
+
const modelDefinition = typeof collectionNameOrDescriptor === "string" ? definition : collectionNameOrDescriptor.definition;
|
|
555
555
|
const normalizedName = validateCollectionName(collectionName);
|
|
556
556
|
if (this.registry.has(normalizedName)) {
|
|
557
557
|
throw createError(ErrorCodes.MODEL_ALREADY_EXISTS, `Model '${normalizedName}' is already defined.`);
|
|
558
558
|
}
|
|
559
|
-
validateDefinition(
|
|
560
|
-
|
|
559
|
+
validateDefinition(modelDefinition);
|
|
560
|
+
const resolvedDefinition = modelDefinition;
|
|
561
|
+
processTimestamps(resolvedDefinition);
|
|
561
562
|
this.registry.set(normalizedName, {
|
|
562
563
|
collectionName: normalizedName,
|
|
563
|
-
definition
|
|
564
|
+
definition: resolvedDefinition
|
|
564
565
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
565
566
|
});
|
|
566
567
|
this.bumpRevision(normalizedName);
|
|
@@ -7660,6 +7661,7 @@ var CountQueue = class {
|
|
|
7660
7661
|
};
|
|
7661
7662
|
|
|
7662
7663
|
// src/capabilities/pool/pool-health-checker.ts
|
|
7664
|
+
var SILENT_HEALTH_CHECKER_LOGGER = {};
|
|
7663
7665
|
var HealthChecker = class {
|
|
7664
7666
|
constructor(options = {}) {
|
|
7665
7667
|
this._healthStatus = /* @__PURE__ */ new Map();
|
|
@@ -7669,7 +7671,7 @@ var HealthChecker = class {
|
|
|
7669
7671
|
this._inProgress = /* @__PURE__ */ new Set();
|
|
7670
7672
|
this._started = false;
|
|
7671
7673
|
this._poolManager = options.poolManager ?? null;
|
|
7672
|
-
this._logger = options.logger ??
|
|
7674
|
+
this._logger = options.logger ?? SILENT_HEALTH_CHECKER_LOGGER;
|
|
7673
7675
|
}
|
|
7674
7676
|
register(poolNameOrConfig, configOrClient) {
|
|
7675
7677
|
let poolName;
|
|
@@ -7793,6 +7795,7 @@ var HealthChecker = class {
|
|
|
7793
7795
|
};
|
|
7794
7796
|
|
|
7795
7797
|
// src/capabilities/pool/pool-selector.ts
|
|
7798
|
+
var SILENT_POOL_SELECTOR_LOGGER = {};
|
|
7796
7799
|
var POOL_STRATEGY_ALIASES = {
|
|
7797
7800
|
"round-robin": "roundRobin",
|
|
7798
7801
|
"least-connections": "leastConnections",
|
|
@@ -7806,7 +7809,7 @@ var PoolSelector = class {
|
|
|
7806
7809
|
constructor(options = {}) {
|
|
7807
7810
|
this._roundRobinIndex = /* @__PURE__ */ new Map();
|
|
7808
7811
|
this._strategy = normalizePoolStrategy(options.strategy);
|
|
7809
|
-
this._logger = options.logger ??
|
|
7812
|
+
this._logger = options.logger ?? SILENT_POOL_SELECTOR_LOGGER;
|
|
7810
7813
|
}
|
|
7811
7814
|
select(pools, context) {
|
|
7812
7815
|
if (!pools || pools.length === 0) {
|
|
@@ -7937,11 +7940,12 @@ var PoolSelector = class {
|
|
|
7937
7940
|
};
|
|
7938
7941
|
|
|
7939
7942
|
// src/capabilities/pool/pool-stats-manager.ts
|
|
7943
|
+
var SILENT_POOL_STATS_LOGGER = {};
|
|
7940
7944
|
var PoolStatsManager = class {
|
|
7941
7945
|
constructor(options = {}) {
|
|
7942
7946
|
this._stats = /* @__PURE__ */ new Map();
|
|
7943
7947
|
this._buffer = [];
|
|
7944
|
-
this._logger = options.logger ??
|
|
7948
|
+
this._logger = options.logger ?? SILENT_POOL_STATS_LOGGER;
|
|
7945
7949
|
this._batchInterval = setInterval(() => {
|
|
7946
7950
|
this._flush();
|
|
7947
7951
|
}, 100);
|
|
@@ -8189,9 +8193,9 @@ var ConnectionPoolManager = class {
|
|
|
8189
8193
|
this._fallbackConfig = this.fallback;
|
|
8190
8194
|
this._fallback = this.fallback;
|
|
8191
8195
|
this._pools = this.pools;
|
|
8192
|
-
this._selector = new PoolSelector({ strategy: this.strategy });
|
|
8193
|
-
this._healthChecker = new HealthChecker({ poolManager: this });
|
|
8194
|
-
this._stats = new PoolStatsManager({ logger:
|
|
8196
|
+
this._selector = new PoolSelector({ strategy: this.strategy, logger: this.logger ?? void 0 });
|
|
8197
|
+
this._healthChecker = new HealthChecker({ poolManager: this, logger: this.logger ?? void 0 });
|
|
8198
|
+
this._stats = new PoolStatsManager({ logger: this.logger ?? void 0 });
|
|
8195
8199
|
}
|
|
8196
8200
|
/**
|
|
8197
8201
|
* Add a connection pool.
|
|
@@ -12766,10 +12770,10 @@ function assertCompatPoolExists(poolManager, poolName) {
|
|
|
12766
12770
|
function createPoolScope(runtime, poolName) {
|
|
12767
12771
|
return {
|
|
12768
12772
|
collection: (name) => runtime.scopedCollection(name, { pool: poolName }),
|
|
12769
|
-
model: (
|
|
12773
|
+
model: (model) => runtime.scopedModel(model, { pool: poolName }),
|
|
12770
12774
|
use: (dbName) => ({
|
|
12771
12775
|
collection: (name) => runtime.scopedCollection(name, { pool: poolName, database: dbName }),
|
|
12772
|
-
model: (
|
|
12776
|
+
model: (model) => runtime.scopedModel(model, { pool: poolName, database: dbName })
|
|
12773
12777
|
})
|
|
12774
12778
|
};
|
|
12775
12779
|
}
|
|
@@ -16928,7 +16932,7 @@ var MonSQLizeRuntime = class {
|
|
|
16928
16932
|
requireCompatDbInstance(this);
|
|
16929
16933
|
return {
|
|
16930
16934
|
collection: (collectionName) => this.scopedCollection(collectionName, { database: name }),
|
|
16931
|
-
model: (
|
|
16935
|
+
model: (model) => this.scopedModel(model, { database: name })
|
|
16932
16936
|
};
|
|
16933
16937
|
}
|
|
16934
16938
|
pool(poolName) {
|
|
@@ -16960,7 +16964,8 @@ var MonSQLizeRuntime = class {
|
|
|
16960
16964
|
});
|
|
16961
16965
|
}
|
|
16962
16966
|
// Model accessors ---------------------------------------------------------
|
|
16963
|
-
scopedModel(
|
|
16967
|
+
scopedModel(model, options = {}) {
|
|
16968
|
+
const name = typeof model === "string" ? model : model.collectionName;
|
|
16964
16969
|
const dbInstance = requireCompatDbInstance(this);
|
|
16965
16970
|
if (this._client) {
|
|
16966
16971
|
return this.createModelInstance(name, options);
|
|
@@ -16984,7 +16989,8 @@ var MonSQLizeRuntime = class {
|
|
|
16984
16989
|
schemaEngine: this._schemaDslEngine
|
|
16985
16990
|
});
|
|
16986
16991
|
}
|
|
16987
|
-
model(
|
|
16992
|
+
model(model) {
|
|
16993
|
+
const name = typeof model === "string" ? model : model.collectionName;
|
|
16988
16994
|
if (this._client) {
|
|
16989
16995
|
this.ensureConnected();
|
|
16990
16996
|
return this.createModelInstance(name, {
|
|
@@ -18785,6 +18791,7 @@ MonSQLize.PoolSelector = PoolSelector;
|
|
|
18785
18791
|
MonSQLize.PoolStats = PoolStatsManager;
|
|
18786
18792
|
MonSQLize.validatePoolConfig = validatePoolConfig;
|
|
18787
18793
|
MonSQLize.validatePoolConfigSafe = validatePoolConfigSafe;
|
|
18794
|
+
MonSQLize.defineModel = defineModel;
|
|
18788
18795
|
MonSQLize.Model = Model;
|
|
18789
18796
|
MonSQLize.ModelInstance = ModelInstance;
|
|
18790
18797
|
MonSQLize.expr = expr;
|
|
@@ -18874,6 +18881,7 @@ export {
|
|
|
18874
18881
|
dataTasks,
|
|
18875
18882
|
decodeCursor2 as decodeCursor,
|
|
18876
18883
|
index_default as default,
|
|
18884
|
+
defineModel,
|
|
18877
18885
|
encodeCursor2 as encodeCursor,
|
|
18878
18886
|
expr,
|
|
18879
18887
|
generateQueryHash,
|
package/dist/types/model.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BookmarkClearResult, BookmarkListResult, BookmarkPrewarmResult, DeleteBatchResult, DeleteResult, IncrementOneResult, IndexCreateResult, InsertBatchResult, InsertManyResult, InsertOneResult, UpdateBatchResult, UpdateResult, VectorSearchHit, VectorSearchOptions } from './collection.mjs';
|
|
2
|
+
import type { InferSchema } from 'schema-dsl';
|
|
2
3
|
import type { SchemaDslRuntime } from 'schema-dsl/runtime';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -12,6 +13,42 @@ export type ModelSchemaDsl = SchemaDslRuntime['s'];
|
|
|
12
13
|
*/
|
|
13
14
|
export type SchemaDSL = (s: ModelSchemaDsl) => unknown;
|
|
14
15
|
|
|
16
|
+
/**
|
|
17
|
+
* A statically typed Model registration descriptor.
|
|
18
|
+
*
|
|
19
|
+
* The descriptor preserves the document type inferred from an object-literal
|
|
20
|
+
* schema while keeping Model registration explicit at runtime.
|
|
21
|
+
* @since v3.3.0
|
|
22
|
+
*/
|
|
23
|
+
export interface ModelDescriptor<TName extends string = string, TDocument = Record<string, unknown>> {
|
|
24
|
+
readonly collectionName: TName;
|
|
25
|
+
readonly definition: ModelDefinition<TDocument>;
|
|
26
|
+
readonly __document?: TDocument;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Extract the document type carried by a Model descriptor.
|
|
31
|
+
* @since v3.3.0
|
|
32
|
+
*/
|
|
33
|
+
export type InferModelDocument<TDescriptor> = TDescriptor extends ModelDescriptor<string, infer TDocument>
|
|
34
|
+
? TDocument
|
|
35
|
+
: never;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Create a typed Model descriptor from a static object-literal schema.
|
|
39
|
+
*
|
|
40
|
+
* Register the returned descriptor with `Model.define(descriptor)` before
|
|
41
|
+
* binding it through a MonSQLize runtime. Callback schemas continue to use
|
|
42
|
+
* the existing explicit generic APIs because their static shape is not stable.
|
|
43
|
+
* @since v3.3.0
|
|
44
|
+
*/
|
|
45
|
+
export declare function defineModel<
|
|
46
|
+
const TName extends string,
|
|
47
|
+
const TSchema extends Record<string, unknown>,
|
|
48
|
+
>(collectionName: TName, definition: Omit<ModelDefinition<InferSchema<TSchema>>, 'schema'> & {
|
|
49
|
+
schema: TSchema;
|
|
50
|
+
}): ModelDescriptor<TName, InferSchema<TSchema>>;
|
|
51
|
+
|
|
15
52
|
/**
|
|
16
53
|
* Default value for a model field — either a static value or a factory function.
|
|
17
54
|
* @template T Field value type
|
|
@@ -739,6 +776,8 @@ export interface ModelInstance<TDocument = any> {
|
|
|
739
776
|
}
|
|
740
777
|
|
|
741
778
|
export declare class Model {
|
|
779
|
+
/** @since v3.3.0 */
|
|
780
|
+
static define<TName extends string, TDocument>(descriptor: ModelDescriptor<TName, TDocument>): void;
|
|
742
781
|
static define<TDocument = Record<string, unknown>>(collectionName: string, definition: ModelDefinition<TDocument>): void;
|
|
743
782
|
static get<TDocument = Record<string, unknown>>(collectionName: string): RegisteredModel<TDocument> | undefined;
|
|
744
783
|
static has(collectionName: string): boolean;
|
package/dist/types/model.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BookmarkClearResult, BookmarkListResult, BookmarkPrewarmResult, DeleteBatchResult, DeleteResult, IncrementOneResult, IndexCreateResult, InsertBatchResult, InsertManyResult, InsertOneResult, UpdateBatchResult, UpdateResult, VectorSearchHit, VectorSearchOptions } from './collection';
|
|
2
|
+
import type { InferSchema } from 'schema-dsl';
|
|
2
3
|
import type { SchemaDslRuntime } from 'schema-dsl/runtime';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -12,6 +13,42 @@ export type ModelSchemaDsl = SchemaDslRuntime['s'];
|
|
|
12
13
|
*/
|
|
13
14
|
export type SchemaDSL = (s: ModelSchemaDsl) => unknown;
|
|
14
15
|
|
|
16
|
+
/**
|
|
17
|
+
* A statically typed Model registration descriptor.
|
|
18
|
+
*
|
|
19
|
+
* The descriptor preserves the document type inferred from an object-literal
|
|
20
|
+
* schema while keeping Model registration explicit at runtime.
|
|
21
|
+
* @since v3.3.0
|
|
22
|
+
*/
|
|
23
|
+
export interface ModelDescriptor<TName extends string = string, TDocument = Record<string, unknown>> {
|
|
24
|
+
readonly collectionName: TName;
|
|
25
|
+
readonly definition: ModelDefinition<TDocument>;
|
|
26
|
+
readonly __document?: TDocument;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Extract the document type carried by a Model descriptor.
|
|
31
|
+
* @since v3.3.0
|
|
32
|
+
*/
|
|
33
|
+
export type InferModelDocument<TDescriptor> = TDescriptor extends ModelDescriptor<string, infer TDocument>
|
|
34
|
+
? TDocument
|
|
35
|
+
: never;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Create a typed Model descriptor from a static object-literal schema.
|
|
39
|
+
*
|
|
40
|
+
* Register the returned descriptor with `Model.define(descriptor)` before
|
|
41
|
+
* binding it through a MonSQLize runtime. Callback schemas continue to use
|
|
42
|
+
* the existing explicit generic APIs because their static shape is not stable.
|
|
43
|
+
* @since v3.3.0
|
|
44
|
+
*/
|
|
45
|
+
export declare function defineModel<
|
|
46
|
+
const TName extends string,
|
|
47
|
+
const TSchema extends Record<string, unknown>,
|
|
48
|
+
>(collectionName: TName, definition: Omit<ModelDefinition<InferSchema<TSchema>>, 'schema'> & {
|
|
49
|
+
schema: TSchema;
|
|
50
|
+
}): ModelDescriptor<TName, InferSchema<TSchema>>;
|
|
51
|
+
|
|
15
52
|
/**
|
|
16
53
|
* Default value for a model field — either a static value or a factory function.
|
|
17
54
|
* @template T Field value type
|
|
@@ -739,6 +776,8 @@ export interface ModelInstance<TDocument = any> {
|
|
|
739
776
|
}
|
|
740
777
|
|
|
741
778
|
export declare class Model {
|
|
779
|
+
/** @since v3.3.0 */
|
|
780
|
+
static define<TName extends string, TDocument>(descriptor: ModelDescriptor<TName, TDocument>): void;
|
|
742
781
|
static define<TDocument = Record<string, unknown>>(collectionName: string, definition: ModelDefinition<TDocument>): void;
|
|
743
782
|
static get<TDocument = Record<string, unknown>>(collectionName: string): RegisteredModel<TDocument> | undefined;
|
|
744
783
|
static has(collectionName: string): boolean;
|
|
@@ -35,7 +35,7 @@ export interface SSHConfig {
|
|
|
35
35
|
import type { Collection, CursorValueNormalizer, CursorValueType, DbAccessor, HealthView } from './collection.mjs';
|
|
36
36
|
import type { DataTaskJobError } from './data-tasks.mjs';
|
|
37
37
|
import type { Lock, LockOptions, LockStats } from './lock.mjs';
|
|
38
|
-
import type { ModelAutoIndexOptions, ModelEnsureAllIndexesOptions, ModelIndexEnsureSummary, ModelInstance } from './model.mjs';
|
|
38
|
+
import type { ModelAutoIndexOptions, ModelDescriptor, ModelEnsureAllIndexesOptions, ModelIndexEnsureSummary, ModelInstance } from './model.mjs';
|
|
39
39
|
import type { MongoConnectConfig } from './mongodb.mjs';
|
|
40
40
|
import type { ConnectionPoolManagerOptions, PoolConfig, PoolHealthStatus, PoolStats, PoolStrategy } from './pool.mjs';
|
|
41
41
|
import type {
|
|
@@ -70,6 +70,15 @@ import type { SlowQueryLogConfigInput, SlowQueryLogEntry, SlowQueryLogFilter, Sl
|
|
|
70
70
|
import type { ChangeStreamSyncManager, SyncConfig, SyncStats } from './sync.mjs';
|
|
71
71
|
import type { Transaction, TransactionOptions, TransactionStats } from './transaction.mjs';
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Callable model accessor that preserves a descriptor's inferred document type.
|
|
75
|
+
* @since v3.3.0
|
|
76
|
+
*/
|
|
77
|
+
export interface ModelBindingAccessor {
|
|
78
|
+
<TDocument>(descriptor: ModelDescriptor<string, TDocument>): ModelInstance<TDocument>;
|
|
79
|
+
<TDocument = any>(modelName: string): ModelInstance<TDocument>;
|
|
80
|
+
}
|
|
81
|
+
|
|
73
82
|
/** Write path policy mode. `allow-both` preserves the existing collection and model write behavior. */
|
|
74
83
|
export type WritePathPolicyMode = 'allow-both' | 'model-only';
|
|
75
84
|
|
|
@@ -283,7 +292,7 @@ export interface MonSQLizeInstance {
|
|
|
283
292
|
db: (name?: string) => DbAccessor;
|
|
284
293
|
use: (name: string) => {
|
|
285
294
|
collection: <TSchema = any>(collectionName: string) => Collection<TSchema>;
|
|
286
|
-
model:
|
|
295
|
+
model: ModelBindingAccessor;
|
|
287
296
|
};
|
|
288
297
|
instance: MonSQLize;
|
|
289
298
|
}>;
|
|
@@ -315,7 +324,7 @@ export interface MonSQLizeInstance {
|
|
|
315
324
|
*/
|
|
316
325
|
use(name: string): {
|
|
317
326
|
collection: <TSchema = any>(collectionName: string) => Collection<TSchema>;
|
|
318
|
-
model:
|
|
327
|
+
model: ModelBindingAccessor;
|
|
319
328
|
};
|
|
320
329
|
/**
|
|
321
330
|
* Return collection and model accessors for the named connection pool.
|
|
@@ -323,10 +332,10 @@ export interface MonSQLizeInstance {
|
|
|
323
332
|
*/
|
|
324
333
|
pool(poolName: string): {
|
|
325
334
|
collection: <TSchema = any>(name: string) => Collection<TSchema>;
|
|
326
|
-
model:
|
|
335
|
+
model: ModelBindingAccessor;
|
|
327
336
|
use: (dbName: string) => {
|
|
328
337
|
collection: <TSchema = any>(name: string) => Collection<TSchema>;
|
|
329
|
-
model:
|
|
338
|
+
model: ModelBindingAccessor;
|
|
330
339
|
};
|
|
331
340
|
};
|
|
332
341
|
/**
|
|
@@ -341,12 +350,16 @@ export interface MonSQLizeInstance {
|
|
|
341
350
|
* @param name Model name.
|
|
342
351
|
* @param options Optional database or pool scope options.
|
|
343
352
|
*/
|
|
353
|
+
/** @since v3.3.0 */
|
|
354
|
+
scopedModel<TDocument>(descriptor: ModelDescriptor<string, TDocument>, options?: { database?: string; pool?: string; }): ModelInstance<TDocument>;
|
|
344
355
|
scopedModel<TDocument = any>(name: string, options?: { database?: string; pool?: string; }): ModelInstance<TDocument>;
|
|
345
356
|
scopedModel(name: string, options?: { database?: string; pool?: string; }): ModelInstance<any>;
|
|
346
357
|
/**
|
|
347
358
|
* Return the registered model instance for the given model name.
|
|
348
359
|
* @param name Model name used during registration.
|
|
349
360
|
*/
|
|
361
|
+
/** @since v3.3.0 */
|
|
362
|
+
model<TDocument>(descriptor: ModelDescriptor<string, TDocument>): ModelInstance<TDocument>;
|
|
350
363
|
model<TDocument = any>(name: string): ModelInstance<TDocument>;
|
|
351
364
|
model(name: string): ModelInstance<any>;
|
|
352
365
|
/**
|
|
@@ -516,7 +529,7 @@ export default class MonSQLize implements MonSQLizeInstance {
|
|
|
516
529
|
db: (name?: string) => DbAccessor;
|
|
517
530
|
use: (name: string) => {
|
|
518
531
|
collection: <TSchema = any>(collectionName: string) => Collection<TSchema>;
|
|
519
|
-
model:
|
|
532
|
+
model: ModelBindingAccessor;
|
|
520
533
|
};
|
|
521
534
|
instance: MonSQLize;
|
|
522
535
|
}>;
|
|
@@ -529,20 +542,24 @@ export default class MonSQLize implements MonSQLizeInstance {
|
|
|
529
542
|
db(name?: string): DbAccessor;
|
|
530
543
|
use(name: string): {
|
|
531
544
|
collection: <TSchema = any>(collectionName: string) => Collection<TSchema>;
|
|
532
|
-
model:
|
|
545
|
+
model: ModelBindingAccessor;
|
|
533
546
|
};
|
|
534
547
|
pool(poolName: string): {
|
|
535
548
|
collection: <TSchema = any>(name: string) => Collection<TSchema>;
|
|
536
|
-
model:
|
|
549
|
+
model: ModelBindingAccessor;
|
|
537
550
|
use: (dbName: string) => {
|
|
538
551
|
collection: <TSchema = any>(name: string) => Collection<TSchema>;
|
|
539
|
-
model:
|
|
552
|
+
model: ModelBindingAccessor;
|
|
540
553
|
};
|
|
541
554
|
};
|
|
542
555
|
scopedCollection<TSchema = any>(name: string, options?: { database?: string; pool?: string; }): Collection<TSchema>;
|
|
543
556
|
scopedCollection(name: string, options?: { database?: string; pool?: string; }): Collection<any>;
|
|
557
|
+
/** @since v3.3.0 */
|
|
558
|
+
scopedModel<TDocument>(descriptor: ModelDescriptor<string, TDocument>, options?: { database?: string; pool?: string; }): ModelInstance<TDocument>;
|
|
544
559
|
scopedModel<TDocument = any>(name: string, options?: { database?: string; pool?: string; }): ModelInstance<TDocument>;
|
|
545
560
|
scopedModel(name: string, options?: { database?: string; pool?: string; }): ModelInstance<any>;
|
|
561
|
+
/** @since v3.3.0 */
|
|
562
|
+
model<TDocument>(descriptor: ModelDescriptor<string, TDocument>): ModelInstance<TDocument>;
|
|
546
563
|
model<TDocument = any>(name: string): ModelInstance<TDocument>;
|
|
547
564
|
model(name: string): ModelInstance<any>;
|
|
548
565
|
ensureModelIndexes(options?: ModelEnsureAllIndexesOptions): Promise<ModelIndexEnsureSummary>;
|
|
@@ -601,6 +618,8 @@ export default class MonSQLize implements MonSQLizeInstance {
|
|
|
601
618
|
static LockTimeoutError: typeof import('./lock.mjs').LockTimeoutError;
|
|
602
619
|
static DistributedCacheInvalidator: typeof DistributedCacheInvalidator;
|
|
603
620
|
static ConnectionPoolManager: typeof import('./pool.mjs').ConnectionPoolManager;
|
|
621
|
+
/** @since v3.3.0 */
|
|
622
|
+
static defineModel: typeof import('./model.mjs').defineModel;
|
|
604
623
|
static Model: typeof import('./runtime.mjs').Model;
|
|
605
624
|
static ModelInstance: typeof import('./runtime.mjs').ModelInstance;
|
|
606
625
|
static expr: typeof expr;
|
|
@@ -35,7 +35,7 @@ export interface SSHConfig {
|
|
|
35
35
|
import type { Collection, CursorValueNormalizer, CursorValueType, DbAccessor, HealthView } from './collection';
|
|
36
36
|
import type { DataTaskJobError } from './data-tasks';
|
|
37
37
|
import type { Lock, LockOptions, LockStats } from './lock';
|
|
38
|
-
import type { ModelAutoIndexOptions, ModelEnsureAllIndexesOptions, ModelIndexEnsureSummary, ModelInstance } from './model';
|
|
38
|
+
import type { ModelAutoIndexOptions, ModelDescriptor, ModelEnsureAllIndexesOptions, ModelIndexEnsureSummary, ModelInstance } from './model';
|
|
39
39
|
import type { MongoConnectConfig } from './mongodb';
|
|
40
40
|
import type { ConnectionPoolManagerOptions, PoolConfig, PoolHealthStatus, PoolStats, PoolStrategy } from './pool';
|
|
41
41
|
import type {
|
|
@@ -70,6 +70,15 @@ import type { SlowQueryLogConfigInput, SlowQueryLogEntry, SlowQueryLogFilter, Sl
|
|
|
70
70
|
import type { ChangeStreamSyncManager, SyncConfig, SyncStats } from './sync';
|
|
71
71
|
import type { Transaction, TransactionOptions, TransactionStats } from './transaction';
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Callable model accessor that preserves a descriptor's inferred document type.
|
|
75
|
+
* @since v3.3.0
|
|
76
|
+
*/
|
|
77
|
+
export interface ModelBindingAccessor {
|
|
78
|
+
<TDocument>(descriptor: ModelDescriptor<string, TDocument>): ModelInstance<TDocument>;
|
|
79
|
+
<TDocument = any>(modelName: string): ModelInstance<TDocument>;
|
|
80
|
+
}
|
|
81
|
+
|
|
73
82
|
/** Write path policy mode. `allow-both` preserves the existing collection and model write behavior. */
|
|
74
83
|
export type WritePathPolicyMode = 'allow-both' | 'model-only';
|
|
75
84
|
|
|
@@ -283,7 +292,7 @@ export interface MonSQLizeInstance {
|
|
|
283
292
|
db: (name?: string) => DbAccessor;
|
|
284
293
|
use: (name: string) => {
|
|
285
294
|
collection: <TSchema = any>(collectionName: string) => Collection<TSchema>;
|
|
286
|
-
model:
|
|
295
|
+
model: ModelBindingAccessor;
|
|
287
296
|
};
|
|
288
297
|
instance: MonSQLize;
|
|
289
298
|
}>;
|
|
@@ -315,7 +324,7 @@ export interface MonSQLizeInstance {
|
|
|
315
324
|
*/
|
|
316
325
|
use(name: string): {
|
|
317
326
|
collection: <TSchema = any>(collectionName: string) => Collection<TSchema>;
|
|
318
|
-
model:
|
|
327
|
+
model: ModelBindingAccessor;
|
|
319
328
|
};
|
|
320
329
|
/**
|
|
321
330
|
* Return collection and model accessors for the named connection pool.
|
|
@@ -323,10 +332,10 @@ export interface MonSQLizeInstance {
|
|
|
323
332
|
*/
|
|
324
333
|
pool(poolName: string): {
|
|
325
334
|
collection: <TSchema = any>(name: string) => Collection<TSchema>;
|
|
326
|
-
model:
|
|
335
|
+
model: ModelBindingAccessor;
|
|
327
336
|
use: (dbName: string) => {
|
|
328
337
|
collection: <TSchema = any>(name: string) => Collection<TSchema>;
|
|
329
|
-
model:
|
|
338
|
+
model: ModelBindingAccessor;
|
|
330
339
|
};
|
|
331
340
|
};
|
|
332
341
|
/**
|
|
@@ -341,12 +350,16 @@ export interface MonSQLizeInstance {
|
|
|
341
350
|
* @param name Model name.
|
|
342
351
|
* @param options Optional database or pool scope options.
|
|
343
352
|
*/
|
|
353
|
+
/** @since v3.3.0 */
|
|
354
|
+
scopedModel<TDocument>(descriptor: ModelDescriptor<string, TDocument>, options?: { database?: string; pool?: string; }): ModelInstance<TDocument>;
|
|
344
355
|
scopedModel<TDocument = any>(name: string, options?: { database?: string; pool?: string; }): ModelInstance<TDocument>;
|
|
345
356
|
scopedModel(name: string, options?: { database?: string; pool?: string; }): ModelInstance<any>;
|
|
346
357
|
/**
|
|
347
358
|
* Return the registered model instance for the given model name.
|
|
348
359
|
* @param name Model name used during registration.
|
|
349
360
|
*/
|
|
361
|
+
/** @since v3.3.0 */
|
|
362
|
+
model<TDocument>(descriptor: ModelDescriptor<string, TDocument>): ModelInstance<TDocument>;
|
|
350
363
|
model<TDocument = any>(name: string): ModelInstance<TDocument>;
|
|
351
364
|
model(name: string): ModelInstance<any>;
|
|
352
365
|
/**
|
|
@@ -516,7 +529,7 @@ export default class MonSQLize implements MonSQLizeInstance {
|
|
|
516
529
|
db: (name?: string) => DbAccessor;
|
|
517
530
|
use: (name: string) => {
|
|
518
531
|
collection: <TSchema = any>(collectionName: string) => Collection<TSchema>;
|
|
519
|
-
model:
|
|
532
|
+
model: ModelBindingAccessor;
|
|
520
533
|
};
|
|
521
534
|
instance: MonSQLize;
|
|
522
535
|
}>;
|
|
@@ -529,20 +542,24 @@ export default class MonSQLize implements MonSQLizeInstance {
|
|
|
529
542
|
db(name?: string): DbAccessor;
|
|
530
543
|
use(name: string): {
|
|
531
544
|
collection: <TSchema = any>(collectionName: string) => Collection<TSchema>;
|
|
532
|
-
model:
|
|
545
|
+
model: ModelBindingAccessor;
|
|
533
546
|
};
|
|
534
547
|
pool(poolName: string): {
|
|
535
548
|
collection: <TSchema = any>(name: string) => Collection<TSchema>;
|
|
536
|
-
model:
|
|
549
|
+
model: ModelBindingAccessor;
|
|
537
550
|
use: (dbName: string) => {
|
|
538
551
|
collection: <TSchema = any>(name: string) => Collection<TSchema>;
|
|
539
|
-
model:
|
|
552
|
+
model: ModelBindingAccessor;
|
|
540
553
|
};
|
|
541
554
|
};
|
|
542
555
|
scopedCollection<TSchema = any>(name: string, options?: { database?: string; pool?: string; }): Collection<TSchema>;
|
|
543
556
|
scopedCollection(name: string, options?: { database?: string; pool?: string; }): Collection<any>;
|
|
557
|
+
/** @since v3.3.0 */
|
|
558
|
+
scopedModel<TDocument>(descriptor: ModelDescriptor<string, TDocument>, options?: { database?: string; pool?: string; }): ModelInstance<TDocument>;
|
|
544
559
|
scopedModel<TDocument = any>(name: string, options?: { database?: string; pool?: string; }): ModelInstance<TDocument>;
|
|
545
560
|
scopedModel(name: string, options?: { database?: string; pool?: string; }): ModelInstance<any>;
|
|
561
|
+
/** @since v3.3.0 */
|
|
562
|
+
model<TDocument>(descriptor: ModelDescriptor<string, TDocument>): ModelInstance<TDocument>;
|
|
546
563
|
model<TDocument = any>(name: string): ModelInstance<TDocument>;
|
|
547
564
|
model(name: string): ModelInstance<any>;
|
|
548
565
|
ensureModelIndexes(options?: ModelEnsureAllIndexesOptions): Promise<ModelIndexEnsureSummary>;
|
|
@@ -601,6 +618,8 @@ export default class MonSQLize implements MonSQLizeInstance {
|
|
|
601
618
|
static LockTimeoutError: typeof import('./lock').LockTimeoutError;
|
|
602
619
|
static DistributedCacheInvalidator: typeof DistributedCacheInvalidator;
|
|
603
620
|
static ConnectionPoolManager: typeof import('./pool').ConnectionPoolManager;
|
|
621
|
+
/** @since v3.3.0 */
|
|
622
|
+
static defineModel: typeof import('./model').defineModel;
|
|
604
623
|
static Model: typeof import('./runtime').Model;
|
|
605
624
|
static ModelInstance: typeof import('./runtime').ModelInstance;
|
|
606
625
|
static expr: typeof expr;
|
package/dist/types/runtime.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BookmarkClearResult, BookmarkListResult, BookmarkPrewarmResult, DeleteBatchResult, DeleteResult, IncrementOneResult, IndexCreateResult, InsertBatchResult, InsertManyResult, UpdateBatchResult, UpdateResult } from './collection.mjs';
|
|
2
2
|
import type { LoggerLike, ExpressionFunction, ExpressionObject } from './base.mjs';
|
|
3
|
-
import type { ModelDefinition, ModelEnsureIndexesOptions, ModelIndexEnsureResult, ModelInstance as ModelInstanceContract, RegisteredModel, RelationConfig } from './model.mjs';
|
|
3
|
+
import type { ModelDefinition, ModelDescriptor, ModelEnsureIndexesOptions, ModelIndexEnsureResult, ModelInstance as ModelInstanceContract, RegisteredModel, RelationConfig } from './model.mjs';
|
|
4
4
|
import type { LockOptions, LockStats } from './lock.mjs';
|
|
5
5
|
import type { ConnectionPoolManagerOptions, FallbackStrategy, PoolConfig, PoolHealthStatus, PoolRole, PoolStats, PoolStrategy } from './pool.mjs';
|
|
6
6
|
import type { SagaDefinition, SagaOrchestratorOptions, SagaResult, SagaStats, SagaStep } from './saga.mjs';
|
|
@@ -289,6 +289,8 @@ export declare class FunctionCache {
|
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
export declare class Model {
|
|
292
|
+
/** @since v3.3.0 */
|
|
293
|
+
static define<TName extends string, TDocument>(descriptor: ModelDescriptor<TName, TDocument>): void;
|
|
292
294
|
static define<TDocument = any>(name: string, definition: ModelDefinition<TDocument>): void;
|
|
293
295
|
static get<TDocument = any>(name: string): RegisteredModel<TDocument> | undefined;
|
|
294
296
|
static has(name: string): boolean;
|
package/dist/types/runtime.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BookmarkClearResult, BookmarkListResult, BookmarkPrewarmResult, DeleteBatchResult, DeleteResult, IncrementOneResult, IndexCreateResult, InsertBatchResult, InsertManyResult, UpdateBatchResult, UpdateResult } from './collection';
|
|
2
2
|
import type { LoggerLike, ExpressionFunction, ExpressionObject } from './base';
|
|
3
|
-
import type { ModelDefinition, ModelEnsureIndexesOptions, ModelIndexEnsureResult, ModelInstance as ModelInstanceContract, RegisteredModel, RelationConfig } from './model';
|
|
3
|
+
import type { ModelDefinition, ModelDescriptor, ModelEnsureIndexesOptions, ModelIndexEnsureResult, ModelInstance as ModelInstanceContract, RegisteredModel, RelationConfig } from './model';
|
|
4
4
|
import type { LockOptions, LockStats } from './lock';
|
|
5
5
|
import type { ConnectionPoolManagerOptions, FallbackStrategy, PoolConfig, PoolHealthStatus, PoolRole, PoolStats, PoolStrategy } from './pool';
|
|
6
6
|
import type { SagaDefinition, SagaOrchestratorOptions, SagaResult, SagaStats, SagaStep } from './saga';
|
|
@@ -289,6 +289,8 @@ export declare class FunctionCache {
|
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
export declare class Model {
|
|
292
|
+
/** @since v3.3.0 */
|
|
293
|
+
static define<TName extends string, TDocument>(descriptor: ModelDescriptor<TName, TDocument>): void;
|
|
292
294
|
static define<TDocument = any>(name: string, definition: ModelDefinition<TDocument>): void;
|
|
293
295
|
static get<TDocument = any>(name: string): RegisteredModel<TDocument> | undefined;
|
|
294
296
|
static has(name: string): boolean;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
{ "name": "cache-hub", "version": "2.2.4", "license": "Apache-2.0", "source": "package-metadata" },
|
|
6
6
|
{ "name": "ioredis", "version": "5.11.1", "license": "MIT", "source": "package-metadata" },
|
|
7
7
|
{ "name": "mongodb", "version": "6.21.0", "license": "Apache-2.0", "source": "package-metadata" },
|
|
8
|
-
{ "name": "schema-dsl", "version": "3.0.
|
|
8
|
+
{ "name": "schema-dsl", "version": "3.0.4", "license": "Apache-2.0", "source": "package-metadata" },
|
|
9
9
|
{ "name": "ssh2", "version": "1.17.0", "license": "MIT", "source": "LICENSE:d06b5d27bbbbe22c36b1fd88406b1208876e2d37d795f5b8eaed951a459a3111" }
|
|
10
10
|
]
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "monsqlize",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "TypeScript production data runtime layer for MongoDB today, with cache, transactions, pools, models, sync, and observability",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/cjs/index.cjs",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"./package.json": "./package.json"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
|
+
"changelogs/v3.3.0.md",
|
|
24
25
|
"changelogs/v3.2.0.md",
|
|
25
26
|
"changelogs/v3.1.14.md",
|
|
26
27
|
"changelogs/v3.1.13.md",
|
|
@@ -160,7 +161,7 @@
|
|
|
160
161
|
"cache-hub": "2.2.4",
|
|
161
162
|
"ioredis": "5.11.1",
|
|
162
163
|
"mongodb": "6.21.0",
|
|
163
|
-
"schema-dsl": "3.0.
|
|
164
|
+
"schema-dsl": "3.0.4",
|
|
164
165
|
"ssh2": "1.17.0"
|
|
165
166
|
},
|
|
166
167
|
"overrides": {
|