monsqlize 3.1.14 → 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 +8 -2
- package/README.md +25 -1
- package/changelogs/v3.2.0.md +24 -0
- package/changelogs/v3.3.0.md +29 -0
- package/dist/cjs/cli/data-task.cjs +13 -2
- package/dist/cjs/index.cjs +701 -58
- package/dist/cjs/transaction/Transaction.cjs +8 -0
- package/dist/cjs/transaction/TransactionManager.cjs +8 -0
- package/dist/esm/index.mjs +702 -58
- package/dist/types/aggregation.d.mts +58 -0
- package/dist/types/aggregation.d.ts +58 -0
- package/dist/types/base.d.mts +4 -0
- package/dist/types/base.d.ts +4 -0
- package/dist/types/collection.d.mts +20 -20
- package/dist/types/collection.d.ts +20 -20
- package/dist/types/model.d.mts +126 -1
- package/dist/types/model.d.ts +126 -1
- package/dist/types/monsqlize.d.mts +28 -9
- package/dist/types/monsqlize.d.ts +28 -9
- package/dist/types/runtime.d.mts +7 -1
- package/dist/types/runtime.d.ts +7 -1
- package/licenses/production-dependencies.json +1 -1
- package/package.json +13 -2
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Meta options for controlling timing/cache info in query results. */
|
|
2
|
+
export interface MetaOptions {
|
|
3
|
+
/** 'op' = operation-level timing only; 'sub' = include sub-step timings (findPage only) */
|
|
4
|
+
level?: 'op' | 'sub';
|
|
5
|
+
/** Include cache hit/miss/ttl info in meta */
|
|
6
|
+
includeCache?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** v1-compatible aggregate options exported from the root package. */
|
|
10
|
+
export interface AggregateOptions {
|
|
11
|
+
cache?: number;
|
|
12
|
+
maxTimeMS?: number;
|
|
13
|
+
allowDiskUse?: boolean;
|
|
14
|
+
collation?: any;
|
|
15
|
+
hint?: string | object;
|
|
16
|
+
comment?: string;
|
|
17
|
+
meta?: boolean | MetaOptions;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Options forwarded to the aggregate execution behind `vectorSearch()`.
|
|
22
|
+
* `meta`, `stream`, and `explain` are intentionally unavailable because
|
|
23
|
+
* `vectorSearch()` always resolves to a stable array of score envelopes.
|
|
24
|
+
*/
|
|
25
|
+
export interface VectorSearchAggregateOptions extends Omit<AggregateOptions, 'meta'> {
|
|
26
|
+
meta?: never;
|
|
27
|
+
stream?: never;
|
|
28
|
+
explain?: never;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Options for a MongoDB `$vectorSearch` aggregation stage. */
|
|
33
|
+
export interface VectorSearchOptions {
|
|
34
|
+
/** Name of the MongoDB Vector Search index. */
|
|
35
|
+
index: string;
|
|
36
|
+
/** Indexed vector field path. */
|
|
37
|
+
path: string;
|
|
38
|
+
/** Query embedding. Every value must be a finite number. */
|
|
39
|
+
queryVector: number[];
|
|
40
|
+
/** Maximum number of scored documents to return. */
|
|
41
|
+
limit: number;
|
|
42
|
+
/** Required for approximate nearest-neighbor search (`exact !== true`). */
|
|
43
|
+
numCandidates?: number;
|
|
44
|
+
/** Set to `true` to request exact nearest-neighbor search. */
|
|
45
|
+
exact?: boolean;
|
|
46
|
+
/** Optional MongoDB Vector Search pre-filter. */
|
|
47
|
+
filter?: Record<string, unknown>;
|
|
48
|
+
/** Fields to return from each matched document. */
|
|
49
|
+
projection?: Record<string, unknown> | string[];
|
|
50
|
+
/** Supported aggregate options; result-shape options are excluded. */
|
|
51
|
+
aggregateOptions?: VectorSearchAggregateOptions;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** A vector-search result that preserves the source document and its score. */
|
|
55
|
+
export interface VectorSearchHit<TDocument = unknown> {
|
|
56
|
+
document: TDocument;
|
|
57
|
+
score: number;
|
|
58
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Meta options for controlling timing/cache info in query results. */
|
|
2
|
+
export interface MetaOptions {
|
|
3
|
+
/** 'op' = operation-level timing only; 'sub' = include sub-step timings (findPage only) */
|
|
4
|
+
level?: 'op' | 'sub';
|
|
5
|
+
/** Include cache hit/miss/ttl info in meta */
|
|
6
|
+
includeCache?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** v1-compatible aggregate options exported from the root package. */
|
|
10
|
+
export interface AggregateOptions {
|
|
11
|
+
cache?: number;
|
|
12
|
+
maxTimeMS?: number;
|
|
13
|
+
allowDiskUse?: boolean;
|
|
14
|
+
collation?: any;
|
|
15
|
+
hint?: string | object;
|
|
16
|
+
comment?: string;
|
|
17
|
+
meta?: boolean | MetaOptions;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Options forwarded to the aggregate execution behind `vectorSearch()`.
|
|
22
|
+
* `meta`, `stream`, and `explain` are intentionally unavailable because
|
|
23
|
+
* `vectorSearch()` always resolves to a stable array of score envelopes.
|
|
24
|
+
*/
|
|
25
|
+
export interface VectorSearchAggregateOptions extends Omit<AggregateOptions, 'meta'> {
|
|
26
|
+
meta?: never;
|
|
27
|
+
stream?: never;
|
|
28
|
+
explain?: never;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Options for a MongoDB `$vectorSearch` aggregation stage. */
|
|
33
|
+
export interface VectorSearchOptions {
|
|
34
|
+
/** Name of the MongoDB Vector Search index. */
|
|
35
|
+
index: string;
|
|
36
|
+
/** Indexed vector field path. */
|
|
37
|
+
path: string;
|
|
38
|
+
/** Query embedding. Every value must be a finite number. */
|
|
39
|
+
queryVector: number[];
|
|
40
|
+
/** Maximum number of scored documents to return. */
|
|
41
|
+
limit: number;
|
|
42
|
+
/** Required for approximate nearest-neighbor search (`exact !== true`). */
|
|
43
|
+
numCandidates?: number;
|
|
44
|
+
/** Set to `true` to request exact nearest-neighbor search. */
|
|
45
|
+
exact?: boolean;
|
|
46
|
+
/** Optional MongoDB Vector Search pre-filter. */
|
|
47
|
+
filter?: Record<string, unknown>;
|
|
48
|
+
/** Fields to return from each matched document. */
|
|
49
|
+
projection?: Record<string, unknown> | string[];
|
|
50
|
+
/** Supported aggregate options; result-shape options are excluded. */
|
|
51
|
+
aggregateOptions?: VectorSearchAggregateOptions;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** A vector-search result that preserves the source document and its score. */
|
|
55
|
+
export interface VectorSearchHit<TDocument = unknown> {
|
|
56
|
+
document: TDocument;
|
|
57
|
+
score: number;
|
|
58
|
+
}
|
package/dist/types/base.d.mts
CHANGED
|
@@ -36,6 +36,10 @@ export declare const enum ErrorCodes {
|
|
|
36
36
|
INVALID_EXPRESSION = 'INVALID_EXPRESSION',
|
|
37
37
|
INVALID_PAGINATION = 'INVALID_PAGINATION',
|
|
38
38
|
INVALID_OPERATION = 'INVALID_OPERATION',
|
|
39
|
+
INVALID_VECTOR_SEARCH = 'INVALID_VECTOR_SEARCH',
|
|
40
|
+
INVALID_RELATION_SELECT = 'INVALID_RELATION_SELECT',
|
|
41
|
+
RELATION_IN_USE = 'RELATION_IN_USE',
|
|
42
|
+
RELATION_USAGE_UNAVAILABLE = 'RELATION_USAGE_UNAVAILABLE',
|
|
39
43
|
INVALID_CURSOR = 'INVALID_CURSOR',
|
|
40
44
|
INVALID_CONFIG = 'INVALID_CONFIG',
|
|
41
45
|
INVALID_MODEL_DEFINITION = 'INVALID_MODEL_DEFINITION',
|
package/dist/types/base.d.ts
CHANGED
|
@@ -36,6 +36,10 @@ export declare const enum ErrorCodes {
|
|
|
36
36
|
INVALID_EXPRESSION = 'INVALID_EXPRESSION',
|
|
37
37
|
INVALID_PAGINATION = 'INVALID_PAGINATION',
|
|
38
38
|
INVALID_OPERATION = 'INVALID_OPERATION',
|
|
39
|
+
INVALID_VECTOR_SEARCH = 'INVALID_VECTOR_SEARCH',
|
|
40
|
+
INVALID_RELATION_SELECT = 'INVALID_RELATION_SELECT',
|
|
41
|
+
RELATION_IN_USE = 'RELATION_IN_USE',
|
|
42
|
+
RELATION_USAGE_UNAVAILABLE = 'RELATION_USAGE_UNAVAILABLE',
|
|
39
43
|
INVALID_CURSOR = 'INVALID_CURSOR',
|
|
40
44
|
INVALID_CONFIG = 'INVALID_CONFIG',
|
|
41
45
|
INVALID_MODEL_DEFINITION = 'INVALID_MODEL_DEFINITION',
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import type { ChangeStream, Document, FindOptions as MongoFindOptions, Sort } from 'mongodb';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import type {
|
|
3
|
+
AggregateOptions,
|
|
4
|
+
MetaOptions,
|
|
5
|
+
VectorSearchHit,
|
|
6
|
+
VectorSearchOptions,
|
|
7
|
+
} from './aggregation.mjs';
|
|
8
|
+
|
|
9
|
+
export type {
|
|
10
|
+
AggregateOptions,
|
|
11
|
+
MetaOptions,
|
|
12
|
+
VectorSearchAggregateOptions,
|
|
13
|
+
VectorSearchHit,
|
|
14
|
+
VectorSearchOptions,
|
|
15
|
+
} from './aggregation.mjs';
|
|
10
16
|
|
|
11
17
|
export type CacheInvalidationOperation =
|
|
12
18
|
| 'find'
|
|
@@ -87,17 +93,6 @@ export interface CountOptions {
|
|
|
87
93
|
meta?: boolean | MetaOptions;
|
|
88
94
|
}
|
|
89
95
|
|
|
90
|
-
/** v1-compatible aggregate options exported from the root package. */
|
|
91
|
-
export interface AggregateOptions {
|
|
92
|
-
cache?: number;
|
|
93
|
-
maxTimeMS?: number;
|
|
94
|
-
allowDiskUse?: boolean;
|
|
95
|
-
collation?: any;
|
|
96
|
-
hint?: string | object;
|
|
97
|
-
comment?: string;
|
|
98
|
-
meta?: boolean | MetaOptions;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
96
|
/** v1-compatible distinct options exported from the root package. */
|
|
102
97
|
export interface DistinctOptions {
|
|
103
98
|
cache?: number;
|
|
@@ -933,9 +928,14 @@ export interface Collection<TSchema = any> {
|
|
|
933
928
|
* @param pipeline - Array of aggregation stage documents.
|
|
934
929
|
* @param options - MongoDB AggregateOptions.
|
|
935
930
|
* @returns AggregateChain that resolves to the result array.
|
|
936
|
-
|
|
931
|
+
*/
|
|
937
932
|
aggregate<TResult = unknown>(pipeline: unknown[] | undefined, options: QueryMetaOption): AggregateChain<TResult, ResultWithMeta<TResult[]>>;
|
|
938
933
|
aggregate<TResult = unknown>(pipeline?: unknown[], options?: unknown): AggregateChain<TResult>;
|
|
934
|
+
/**
|
|
935
|
+
* Searches a MongoDB Vector Search index and returns each document with its score.
|
|
936
|
+
* Requires a compatible MongoDB deployment and a pre-created Vector Search index.
|
|
937
|
+
*/
|
|
938
|
+
vectorSearch<TDocument = TSchema>(options: VectorSearchOptions): Promise<Array<VectorSearchHit<TDocument>>>;
|
|
939
939
|
/** Stream mode: returns a readable stream of page documents when `stream: true`. */
|
|
940
940
|
findPage(options: FindPageOptions<TSchema> & { stream: true }): NodeJS.ReadableStream;
|
|
941
941
|
/** Sync totals mode guarantees `totals.total` and `totals.totalPages` are immediately available. */
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import type { ChangeStream, Document, FindOptions as MongoFindOptions, Sort } from 'mongodb';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import type {
|
|
3
|
+
AggregateOptions,
|
|
4
|
+
MetaOptions,
|
|
5
|
+
VectorSearchHit,
|
|
6
|
+
VectorSearchOptions,
|
|
7
|
+
} from './aggregation';
|
|
8
|
+
|
|
9
|
+
export type {
|
|
10
|
+
AggregateOptions,
|
|
11
|
+
MetaOptions,
|
|
12
|
+
VectorSearchAggregateOptions,
|
|
13
|
+
VectorSearchHit,
|
|
14
|
+
VectorSearchOptions,
|
|
15
|
+
} from './aggregation';
|
|
10
16
|
|
|
11
17
|
export type CacheInvalidationOperation =
|
|
12
18
|
| 'find'
|
|
@@ -87,17 +93,6 @@ export interface CountOptions {
|
|
|
87
93
|
meta?: boolean | MetaOptions;
|
|
88
94
|
}
|
|
89
95
|
|
|
90
|
-
/** v1-compatible aggregate options exported from the root package. */
|
|
91
|
-
export interface AggregateOptions {
|
|
92
|
-
cache?: number;
|
|
93
|
-
maxTimeMS?: number;
|
|
94
|
-
allowDiskUse?: boolean;
|
|
95
|
-
collation?: any;
|
|
96
|
-
hint?: string | object;
|
|
97
|
-
comment?: string;
|
|
98
|
-
meta?: boolean | MetaOptions;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
96
|
/** v1-compatible distinct options exported from the root package. */
|
|
102
97
|
export interface DistinctOptions {
|
|
103
98
|
cache?: number;
|
|
@@ -933,9 +928,14 @@ export interface Collection<TSchema = any> {
|
|
|
933
928
|
* @param pipeline - Array of aggregation stage documents.
|
|
934
929
|
* @param options - MongoDB AggregateOptions.
|
|
935
930
|
* @returns AggregateChain that resolves to the result array.
|
|
936
|
-
|
|
931
|
+
*/
|
|
937
932
|
aggregate<TResult = unknown>(pipeline: unknown[] | undefined, options: QueryMetaOption): AggregateChain<TResult, ResultWithMeta<TResult[]>>;
|
|
938
933
|
aggregate<TResult = unknown>(pipeline?: unknown[], options?: unknown): AggregateChain<TResult>;
|
|
934
|
+
/**
|
|
935
|
+
* Searches a MongoDB Vector Search index and returns each document with its score.
|
|
936
|
+
* Requires a compatible MongoDB deployment and a pre-created Vector Search index.
|
|
937
|
+
*/
|
|
938
|
+
vectorSearch<TDocument = TSchema>(options: VectorSearchOptions): Promise<Array<VectorSearchHit<TDocument>>>;
|
|
939
939
|
/** Stream mode: returns a readable stream of page documents when `stream: true`. */
|
|
940
940
|
findPage(options: FindPageOptions<TSchema> & { stream: true }): NodeJS.ReadableStream;
|
|
941
941
|
/** Sync totals mode guarantees `totals.total` and `totals.totalPages` are immediately available. */
|
package/dist/types/model.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { BookmarkClearResult, BookmarkListResult, BookmarkPrewarmResult, DeleteBatchResult, DeleteResult, IncrementOneResult, IndexCreateResult, InsertBatchResult, InsertManyResult, InsertOneResult, UpdateBatchResult, UpdateResult } from './collection.mjs';
|
|
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
|
|
@@ -50,6 +87,8 @@ export interface RelationConfig {
|
|
|
50
87
|
localField: string;
|
|
51
88
|
foreignField: string;
|
|
52
89
|
single?: boolean;
|
|
90
|
+
/** Default inclusion projection for this relation. Call-site `populate().select` takes precedence. */
|
|
91
|
+
select?: string | string[];
|
|
53
92
|
}
|
|
54
93
|
|
|
55
94
|
export interface PopulateConfig {
|
|
@@ -64,6 +103,71 @@ export interface PopulateConfig {
|
|
|
64
103
|
populate?: string | PopulateConfig | Array<string | PopulateConfig>;
|
|
65
104
|
}
|
|
66
105
|
|
|
106
|
+
/** Vector search options at the Model layer, including Model soft-delete visibility. */
|
|
107
|
+
export interface ModelVectorSearchOptions extends VectorSearchOptions {
|
|
108
|
+
withDeleted?: boolean;
|
|
109
|
+
onlyDeleted?: boolean;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Bounds and filters for inspecting registered, declared inbound Model relations. */
|
|
113
|
+
export interface RelationUsageOptions {
|
|
114
|
+
session?: unknown;
|
|
115
|
+
maxTargets?: number;
|
|
116
|
+
maxSamples?: number;
|
|
117
|
+
includeRelations?: string[];
|
|
118
|
+
excludeRelations?: string[];
|
|
119
|
+
/** Defaults to true so soft-deleted source documents still protect a target. */
|
|
120
|
+
includeSoftDeletedReferences?: boolean;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface RelationUsageEntry {
|
|
124
|
+
sourceModel: string;
|
|
125
|
+
sourceCollection: string;
|
|
126
|
+
relation: string;
|
|
127
|
+
localField: string;
|
|
128
|
+
foreignField: string;
|
|
129
|
+
count: number;
|
|
130
|
+
sampleIds: unknown[];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface RelationUsageCoverage {
|
|
134
|
+
mode: 'registered-declared';
|
|
135
|
+
complete: boolean;
|
|
136
|
+
registryModels: string[];
|
|
137
|
+
checkedModels: string[];
|
|
138
|
+
skipped: Array<{
|
|
139
|
+
sourceModel: string;
|
|
140
|
+
reason: string;
|
|
141
|
+
}>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface RelationUsageReport {
|
|
145
|
+
used: boolean;
|
|
146
|
+
target: {
|
|
147
|
+
matchedCount: number;
|
|
148
|
+
truncated: boolean;
|
|
149
|
+
sampleIds: unknown[];
|
|
150
|
+
};
|
|
151
|
+
checkedRelations: number;
|
|
152
|
+
usages: RelationUsageEntry[];
|
|
153
|
+
coverage: RelationUsageCoverage;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Result from a protected single-document delete after a relation usage check. */
|
|
157
|
+
export interface RelationProtectedDeleteResult<TResult = unknown> {
|
|
158
|
+
result: TResult;
|
|
159
|
+
usage: RelationUsageReport;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Driver delete options plus bounds for the protected relation preflight. */
|
|
163
|
+
export type RelationProtectedDeleteOptions = Omit<RelationUsageOptions, 'includeRelations' | 'excludeRelations'> & {
|
|
164
|
+
/** Protected deletion never permits narrowing the declared-relation scan. */
|
|
165
|
+
includeRelations?: never;
|
|
166
|
+
/** Protected deletion never permits narrowing the declared-relation scan. */
|
|
167
|
+
excludeRelations?: never;
|
|
168
|
+
[key: string]: unknown;
|
|
169
|
+
};
|
|
170
|
+
|
|
67
171
|
export interface VirtualConfig {
|
|
68
172
|
get: (this: Record<string, unknown>) => unknown;
|
|
69
173
|
set?: (this: Record<string, unknown>, value: unknown) => void;
|
|
@@ -385,6 +489,11 @@ export interface ModelInstance<TDocument = any> {
|
|
|
385
489
|
data: Array<ModelDocument<TDocument>>;
|
|
386
490
|
total: number;
|
|
387
491
|
}>;
|
|
492
|
+
/**
|
|
493
|
+
* Runs Vector Search while applying Model soft-delete visibility and hydrating hit documents.
|
|
494
|
+
* The returned order and score are produced by MongoDB Vector Search.
|
|
495
|
+
*/
|
|
496
|
+
vectorSearch(options: ModelVectorSearchOptions): Promise<Array<VectorSearchHit<ModelDocument<TDocument>>>>;
|
|
388
497
|
/**
|
|
389
498
|
* Counts documents matching the query.
|
|
390
499
|
* @param query Optional filter.
|
|
@@ -479,6 +588,20 @@ export interface ModelInstance<TDocument = any> {
|
|
|
479
588
|
* @returns Standard `DeleteResult` object.
|
|
480
589
|
*/
|
|
481
590
|
deleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
591
|
+
/**
|
|
592
|
+
* Reports declared, registered Model relations currently using matching target documents.
|
|
593
|
+
* This is a read-only best-effort scan; inspect `coverage.complete` before relying on it.
|
|
594
|
+
*/
|
|
595
|
+
checkRelationUsage(filter?: unknown, options?: RelationUsageOptions): Promise<RelationUsageReport>;
|
|
596
|
+
/**
|
|
597
|
+
* Deletes one visible target only after a complete declared-relation usage scan finds no references.
|
|
598
|
+
* Existing `deleteOne` behavior is otherwise preserved.
|
|
599
|
+
*/
|
|
600
|
+
deleteOneWithRelations(filter: unknown, options?: RelationProtectedDeleteOptions): Promise<RelationProtectedDeleteResult>;
|
|
601
|
+
/**
|
|
602
|
+
* Physically deletes one target, including soft-deleted documents, only after the same protected scan.
|
|
603
|
+
*/
|
|
604
|
+
forceDeleteWithRelations(filter: unknown, options?: RelationProtectedDeleteOptions): Promise<RelationProtectedDeleteResult>;
|
|
482
605
|
// soft-delete extended methods
|
|
483
606
|
/**
|
|
484
607
|
* Finds matching documents, including soft-deleted documents.
|
|
@@ -653,6 +776,8 @@ export interface ModelInstance<TDocument = any> {
|
|
|
653
776
|
}
|
|
654
777
|
|
|
655
778
|
export declare class Model {
|
|
779
|
+
/** @since v3.3.0 */
|
|
780
|
+
static define<TName extends string, TDocument>(descriptor: ModelDescriptor<TName, TDocument>): void;
|
|
656
781
|
static define<TDocument = Record<string, unknown>>(collectionName: string, definition: ModelDefinition<TDocument>): void;
|
|
657
782
|
static get<TDocument = Record<string, unknown>>(collectionName: string): RegisteredModel<TDocument> | undefined;
|
|
658
783
|
static has(collectionName: string): boolean;
|
package/dist/types/model.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { BookmarkClearResult, BookmarkListResult, BookmarkPrewarmResult, DeleteBatchResult, DeleteResult, IncrementOneResult, IndexCreateResult, InsertBatchResult, InsertManyResult, InsertOneResult, UpdateBatchResult, UpdateResult } from './collection';
|
|
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
|
|
@@ -50,6 +87,8 @@ export interface RelationConfig {
|
|
|
50
87
|
localField: string;
|
|
51
88
|
foreignField: string;
|
|
52
89
|
single?: boolean;
|
|
90
|
+
/** Default inclusion projection for this relation. Call-site `populate().select` takes precedence. */
|
|
91
|
+
select?: string | string[];
|
|
53
92
|
}
|
|
54
93
|
|
|
55
94
|
export interface PopulateConfig {
|
|
@@ -64,6 +103,71 @@ export interface PopulateConfig {
|
|
|
64
103
|
populate?: string | PopulateConfig | Array<string | PopulateConfig>;
|
|
65
104
|
}
|
|
66
105
|
|
|
106
|
+
/** Vector search options at the Model layer, including Model soft-delete visibility. */
|
|
107
|
+
export interface ModelVectorSearchOptions extends VectorSearchOptions {
|
|
108
|
+
withDeleted?: boolean;
|
|
109
|
+
onlyDeleted?: boolean;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Bounds and filters for inspecting registered, declared inbound Model relations. */
|
|
113
|
+
export interface RelationUsageOptions {
|
|
114
|
+
session?: unknown;
|
|
115
|
+
maxTargets?: number;
|
|
116
|
+
maxSamples?: number;
|
|
117
|
+
includeRelations?: string[];
|
|
118
|
+
excludeRelations?: string[];
|
|
119
|
+
/** Defaults to true so soft-deleted source documents still protect a target. */
|
|
120
|
+
includeSoftDeletedReferences?: boolean;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface RelationUsageEntry {
|
|
124
|
+
sourceModel: string;
|
|
125
|
+
sourceCollection: string;
|
|
126
|
+
relation: string;
|
|
127
|
+
localField: string;
|
|
128
|
+
foreignField: string;
|
|
129
|
+
count: number;
|
|
130
|
+
sampleIds: unknown[];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface RelationUsageCoverage {
|
|
134
|
+
mode: 'registered-declared';
|
|
135
|
+
complete: boolean;
|
|
136
|
+
registryModels: string[];
|
|
137
|
+
checkedModels: string[];
|
|
138
|
+
skipped: Array<{
|
|
139
|
+
sourceModel: string;
|
|
140
|
+
reason: string;
|
|
141
|
+
}>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface RelationUsageReport {
|
|
145
|
+
used: boolean;
|
|
146
|
+
target: {
|
|
147
|
+
matchedCount: number;
|
|
148
|
+
truncated: boolean;
|
|
149
|
+
sampleIds: unknown[];
|
|
150
|
+
};
|
|
151
|
+
checkedRelations: number;
|
|
152
|
+
usages: RelationUsageEntry[];
|
|
153
|
+
coverage: RelationUsageCoverage;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Result from a protected single-document delete after a relation usage check. */
|
|
157
|
+
export interface RelationProtectedDeleteResult<TResult = unknown> {
|
|
158
|
+
result: TResult;
|
|
159
|
+
usage: RelationUsageReport;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Driver delete options plus bounds for the protected relation preflight. */
|
|
163
|
+
export type RelationProtectedDeleteOptions = Omit<RelationUsageOptions, 'includeRelations' | 'excludeRelations'> & {
|
|
164
|
+
/** Protected deletion never permits narrowing the declared-relation scan. */
|
|
165
|
+
includeRelations?: never;
|
|
166
|
+
/** Protected deletion never permits narrowing the declared-relation scan. */
|
|
167
|
+
excludeRelations?: never;
|
|
168
|
+
[key: string]: unknown;
|
|
169
|
+
};
|
|
170
|
+
|
|
67
171
|
export interface VirtualConfig {
|
|
68
172
|
get: (this: Record<string, unknown>) => unknown;
|
|
69
173
|
set?: (this: Record<string, unknown>, value: unknown) => void;
|
|
@@ -385,6 +489,11 @@ export interface ModelInstance<TDocument = any> {
|
|
|
385
489
|
data: Array<ModelDocument<TDocument>>;
|
|
386
490
|
total: number;
|
|
387
491
|
}>;
|
|
492
|
+
/**
|
|
493
|
+
* Runs Vector Search while applying Model soft-delete visibility and hydrating hit documents.
|
|
494
|
+
* The returned order and score are produced by MongoDB Vector Search.
|
|
495
|
+
*/
|
|
496
|
+
vectorSearch(options: ModelVectorSearchOptions): Promise<Array<VectorSearchHit<ModelDocument<TDocument>>>>;
|
|
388
497
|
/**
|
|
389
498
|
* Counts documents matching the query.
|
|
390
499
|
* @param query Optional filter.
|
|
@@ -479,6 +588,20 @@ export interface ModelInstance<TDocument = any> {
|
|
|
479
588
|
* @returns Standard `DeleteResult` object.
|
|
480
589
|
*/
|
|
481
590
|
deleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
591
|
+
/**
|
|
592
|
+
* Reports declared, registered Model relations currently using matching target documents.
|
|
593
|
+
* This is a read-only best-effort scan; inspect `coverage.complete` before relying on it.
|
|
594
|
+
*/
|
|
595
|
+
checkRelationUsage(filter?: unknown, options?: RelationUsageOptions): Promise<RelationUsageReport>;
|
|
596
|
+
/**
|
|
597
|
+
* Deletes one visible target only after a complete declared-relation usage scan finds no references.
|
|
598
|
+
* Existing `deleteOne` behavior is otherwise preserved.
|
|
599
|
+
*/
|
|
600
|
+
deleteOneWithRelations(filter: unknown, options?: RelationProtectedDeleteOptions): Promise<RelationProtectedDeleteResult>;
|
|
601
|
+
/**
|
|
602
|
+
* Physically deletes one target, including soft-deleted documents, only after the same protected scan.
|
|
603
|
+
*/
|
|
604
|
+
forceDeleteWithRelations(filter: unknown, options?: RelationProtectedDeleteOptions): Promise<RelationProtectedDeleteResult>;
|
|
482
605
|
// soft-delete extended methods
|
|
483
606
|
/**
|
|
484
607
|
* Finds matching documents, including soft-deleted documents.
|
|
@@ -653,6 +776,8 @@ export interface ModelInstance<TDocument = any> {
|
|
|
653
776
|
}
|
|
654
777
|
|
|
655
778
|
export declare class Model {
|
|
779
|
+
/** @since v3.3.0 */
|
|
780
|
+
static define<TName extends string, TDocument>(descriptor: ModelDescriptor<TName, TDocument>): void;
|
|
656
781
|
static define<TDocument = Record<string, unknown>>(collectionName: string, definition: ModelDefinition<TDocument>): void;
|
|
657
782
|
static get<TDocument = Record<string, unknown>>(collectionName: string): RegisteredModel<TDocument> | undefined;
|
|
658
783
|
static has(collectionName: string): boolean;
|