monsqlize 3.1.0 → 3.2.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 +3 -2
- package/README.md +23 -23
- package/SECURITY.md +1 -1
- package/changelogs/v3.1.11.md +12 -0
- package/changelogs/v3.1.12.md +12 -0
- package/changelogs/v3.1.13.md +12 -0
- package/changelogs/v3.1.14.md +12 -0
- package/changelogs/v3.1.5.md +3 -0
- package/changelogs/v3.1.6.md +4 -0
- package/changelogs/v3.1.7.md +7 -0
- package/changelogs/v3.1.8.md +12 -0
- package/changelogs/v3.2.0.md +24 -0
- package/dist/cjs/cli/data-task.cjs +22 -4
- package/dist/cjs/index.cjs +674 -38
- package/dist/cjs/transaction/Transaction.cjs +8 -0
- package/dist/cjs/transaction/TransactionManager.cjs +8 -0
- package/dist/esm/index.mjs +674 -38
- 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 +87 -1
- package/dist/types/model.d.ts +87 -1
- package/dist/types/runtime.d.mts +4 -0
- package/dist/types/runtime.d.ts +4 -0
- package/package.json +171 -153
|
@@ -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,4 @@
|
|
|
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
2
|
import type { SchemaDslRuntime } from 'schema-dsl/runtime';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -50,6 +50,8 @@ export interface RelationConfig {
|
|
|
50
50
|
localField: string;
|
|
51
51
|
foreignField: string;
|
|
52
52
|
single?: boolean;
|
|
53
|
+
/** Default inclusion projection for this relation. Call-site `populate().select` takes precedence. */
|
|
54
|
+
select?: string | string[];
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
export interface PopulateConfig {
|
|
@@ -64,6 +66,71 @@ export interface PopulateConfig {
|
|
|
64
66
|
populate?: string | PopulateConfig | Array<string | PopulateConfig>;
|
|
65
67
|
}
|
|
66
68
|
|
|
69
|
+
/** Vector search options at the Model layer, including Model soft-delete visibility. */
|
|
70
|
+
export interface ModelVectorSearchOptions extends VectorSearchOptions {
|
|
71
|
+
withDeleted?: boolean;
|
|
72
|
+
onlyDeleted?: boolean;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Bounds and filters for inspecting registered, declared inbound Model relations. */
|
|
76
|
+
export interface RelationUsageOptions {
|
|
77
|
+
session?: unknown;
|
|
78
|
+
maxTargets?: number;
|
|
79
|
+
maxSamples?: number;
|
|
80
|
+
includeRelations?: string[];
|
|
81
|
+
excludeRelations?: string[];
|
|
82
|
+
/** Defaults to true so soft-deleted source documents still protect a target. */
|
|
83
|
+
includeSoftDeletedReferences?: boolean;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface RelationUsageEntry {
|
|
87
|
+
sourceModel: string;
|
|
88
|
+
sourceCollection: string;
|
|
89
|
+
relation: string;
|
|
90
|
+
localField: string;
|
|
91
|
+
foreignField: string;
|
|
92
|
+
count: number;
|
|
93
|
+
sampleIds: unknown[];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface RelationUsageCoverage {
|
|
97
|
+
mode: 'registered-declared';
|
|
98
|
+
complete: boolean;
|
|
99
|
+
registryModels: string[];
|
|
100
|
+
checkedModels: string[];
|
|
101
|
+
skipped: Array<{
|
|
102
|
+
sourceModel: string;
|
|
103
|
+
reason: string;
|
|
104
|
+
}>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface RelationUsageReport {
|
|
108
|
+
used: boolean;
|
|
109
|
+
target: {
|
|
110
|
+
matchedCount: number;
|
|
111
|
+
truncated: boolean;
|
|
112
|
+
sampleIds: unknown[];
|
|
113
|
+
};
|
|
114
|
+
checkedRelations: number;
|
|
115
|
+
usages: RelationUsageEntry[];
|
|
116
|
+
coverage: RelationUsageCoverage;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Result from a protected single-document delete after a relation usage check. */
|
|
120
|
+
export interface RelationProtectedDeleteResult<TResult = unknown> {
|
|
121
|
+
result: TResult;
|
|
122
|
+
usage: RelationUsageReport;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Driver delete options plus bounds for the protected relation preflight. */
|
|
126
|
+
export type RelationProtectedDeleteOptions = Omit<RelationUsageOptions, 'includeRelations' | 'excludeRelations'> & {
|
|
127
|
+
/** Protected deletion never permits narrowing the declared-relation scan. */
|
|
128
|
+
includeRelations?: never;
|
|
129
|
+
/** Protected deletion never permits narrowing the declared-relation scan. */
|
|
130
|
+
excludeRelations?: never;
|
|
131
|
+
[key: string]: unknown;
|
|
132
|
+
};
|
|
133
|
+
|
|
67
134
|
export interface VirtualConfig {
|
|
68
135
|
get: (this: Record<string, unknown>) => unknown;
|
|
69
136
|
set?: (this: Record<string, unknown>, value: unknown) => void;
|
|
@@ -385,6 +452,11 @@ export interface ModelInstance<TDocument = any> {
|
|
|
385
452
|
data: Array<ModelDocument<TDocument>>;
|
|
386
453
|
total: number;
|
|
387
454
|
}>;
|
|
455
|
+
/**
|
|
456
|
+
* Runs Vector Search while applying Model soft-delete visibility and hydrating hit documents.
|
|
457
|
+
* The returned order and score are produced by MongoDB Vector Search.
|
|
458
|
+
*/
|
|
459
|
+
vectorSearch(options: ModelVectorSearchOptions): Promise<Array<VectorSearchHit<ModelDocument<TDocument>>>>;
|
|
388
460
|
/**
|
|
389
461
|
* Counts documents matching the query.
|
|
390
462
|
* @param query Optional filter.
|
|
@@ -479,6 +551,20 @@ export interface ModelInstance<TDocument = any> {
|
|
|
479
551
|
* @returns Standard `DeleteResult` object.
|
|
480
552
|
*/
|
|
481
553
|
deleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
554
|
+
/**
|
|
555
|
+
* Reports declared, registered Model relations currently using matching target documents.
|
|
556
|
+
* This is a read-only best-effort scan; inspect `coverage.complete` before relying on it.
|
|
557
|
+
*/
|
|
558
|
+
checkRelationUsage(filter?: unknown, options?: RelationUsageOptions): Promise<RelationUsageReport>;
|
|
559
|
+
/**
|
|
560
|
+
* Deletes one visible target only after a complete declared-relation usage scan finds no references.
|
|
561
|
+
* Existing `deleteOne` behavior is otherwise preserved.
|
|
562
|
+
*/
|
|
563
|
+
deleteOneWithRelations(filter: unknown, options?: RelationProtectedDeleteOptions): Promise<RelationProtectedDeleteResult>;
|
|
564
|
+
/**
|
|
565
|
+
* Physically deletes one target, including soft-deleted documents, only after the same protected scan.
|
|
566
|
+
*/
|
|
567
|
+
forceDeleteWithRelations(filter: unknown, options?: RelationProtectedDeleteOptions): Promise<RelationProtectedDeleteResult>;
|
|
482
568
|
// soft-delete extended methods
|
|
483
569
|
/**
|
|
484
570
|
* Finds matching documents, including soft-deleted documents.
|
package/dist/types/model.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
2
|
import type { SchemaDslRuntime } from 'schema-dsl/runtime';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -50,6 +50,8 @@ export interface RelationConfig {
|
|
|
50
50
|
localField: string;
|
|
51
51
|
foreignField: string;
|
|
52
52
|
single?: boolean;
|
|
53
|
+
/** Default inclusion projection for this relation. Call-site `populate().select` takes precedence. */
|
|
54
|
+
select?: string | string[];
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
export interface PopulateConfig {
|
|
@@ -64,6 +66,71 @@ export interface PopulateConfig {
|
|
|
64
66
|
populate?: string | PopulateConfig | Array<string | PopulateConfig>;
|
|
65
67
|
}
|
|
66
68
|
|
|
69
|
+
/** Vector search options at the Model layer, including Model soft-delete visibility. */
|
|
70
|
+
export interface ModelVectorSearchOptions extends VectorSearchOptions {
|
|
71
|
+
withDeleted?: boolean;
|
|
72
|
+
onlyDeleted?: boolean;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Bounds and filters for inspecting registered, declared inbound Model relations. */
|
|
76
|
+
export interface RelationUsageOptions {
|
|
77
|
+
session?: unknown;
|
|
78
|
+
maxTargets?: number;
|
|
79
|
+
maxSamples?: number;
|
|
80
|
+
includeRelations?: string[];
|
|
81
|
+
excludeRelations?: string[];
|
|
82
|
+
/** Defaults to true so soft-deleted source documents still protect a target. */
|
|
83
|
+
includeSoftDeletedReferences?: boolean;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface RelationUsageEntry {
|
|
87
|
+
sourceModel: string;
|
|
88
|
+
sourceCollection: string;
|
|
89
|
+
relation: string;
|
|
90
|
+
localField: string;
|
|
91
|
+
foreignField: string;
|
|
92
|
+
count: number;
|
|
93
|
+
sampleIds: unknown[];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface RelationUsageCoverage {
|
|
97
|
+
mode: 'registered-declared';
|
|
98
|
+
complete: boolean;
|
|
99
|
+
registryModels: string[];
|
|
100
|
+
checkedModels: string[];
|
|
101
|
+
skipped: Array<{
|
|
102
|
+
sourceModel: string;
|
|
103
|
+
reason: string;
|
|
104
|
+
}>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface RelationUsageReport {
|
|
108
|
+
used: boolean;
|
|
109
|
+
target: {
|
|
110
|
+
matchedCount: number;
|
|
111
|
+
truncated: boolean;
|
|
112
|
+
sampleIds: unknown[];
|
|
113
|
+
};
|
|
114
|
+
checkedRelations: number;
|
|
115
|
+
usages: RelationUsageEntry[];
|
|
116
|
+
coverage: RelationUsageCoverage;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Result from a protected single-document delete after a relation usage check. */
|
|
120
|
+
export interface RelationProtectedDeleteResult<TResult = unknown> {
|
|
121
|
+
result: TResult;
|
|
122
|
+
usage: RelationUsageReport;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Driver delete options plus bounds for the protected relation preflight. */
|
|
126
|
+
export type RelationProtectedDeleteOptions = Omit<RelationUsageOptions, 'includeRelations' | 'excludeRelations'> & {
|
|
127
|
+
/** Protected deletion never permits narrowing the declared-relation scan. */
|
|
128
|
+
includeRelations?: never;
|
|
129
|
+
/** Protected deletion never permits narrowing the declared-relation scan. */
|
|
130
|
+
excludeRelations?: never;
|
|
131
|
+
[key: string]: unknown;
|
|
132
|
+
};
|
|
133
|
+
|
|
67
134
|
export interface VirtualConfig {
|
|
68
135
|
get: (this: Record<string, unknown>) => unknown;
|
|
69
136
|
set?: (this: Record<string, unknown>, value: unknown) => void;
|
|
@@ -385,6 +452,11 @@ export interface ModelInstance<TDocument = any> {
|
|
|
385
452
|
data: Array<ModelDocument<TDocument>>;
|
|
386
453
|
total: number;
|
|
387
454
|
}>;
|
|
455
|
+
/**
|
|
456
|
+
* Runs Vector Search while applying Model soft-delete visibility and hydrating hit documents.
|
|
457
|
+
* The returned order and score are produced by MongoDB Vector Search.
|
|
458
|
+
*/
|
|
459
|
+
vectorSearch(options: ModelVectorSearchOptions): Promise<Array<VectorSearchHit<ModelDocument<TDocument>>>>;
|
|
388
460
|
/**
|
|
389
461
|
* Counts documents matching the query.
|
|
390
462
|
* @param query Optional filter.
|
|
@@ -479,6 +551,20 @@ export interface ModelInstance<TDocument = any> {
|
|
|
479
551
|
* @returns Standard `DeleteResult` object.
|
|
480
552
|
*/
|
|
481
553
|
deleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
554
|
+
/**
|
|
555
|
+
* Reports declared, registered Model relations currently using matching target documents.
|
|
556
|
+
* This is a read-only best-effort scan; inspect `coverage.complete` before relying on it.
|
|
557
|
+
*/
|
|
558
|
+
checkRelationUsage(filter?: unknown, options?: RelationUsageOptions): Promise<RelationUsageReport>;
|
|
559
|
+
/**
|
|
560
|
+
* Deletes one visible target only after a complete declared-relation usage scan finds no references.
|
|
561
|
+
* Existing `deleteOne` behavior is otherwise preserved.
|
|
562
|
+
*/
|
|
563
|
+
deleteOneWithRelations(filter: unknown, options?: RelationProtectedDeleteOptions): Promise<RelationProtectedDeleteResult>;
|
|
564
|
+
/**
|
|
565
|
+
* Physically deletes one target, including soft-deleted documents, only after the same protected scan.
|
|
566
|
+
*/
|
|
567
|
+
forceDeleteWithRelations(filter: unknown, options?: RelationProtectedDeleteOptions): Promise<RelationProtectedDeleteResult>;
|
|
482
568
|
// soft-delete extended methods
|
|
483
569
|
/**
|
|
484
570
|
* Finds matching documents, including soft-deleted documents.
|
package/dist/types/runtime.d.mts
CHANGED
|
@@ -334,6 +334,7 @@ export declare class ModelInstance<TDocument = any> implements ModelInstanceCont
|
|
|
334
334
|
meta?: import('./collection.mjs').MetaInfo;
|
|
335
335
|
}>;
|
|
336
336
|
findAndCount(query?: unknown, options?: unknown): import('./model.mjs').PopulateProxy<{ data: Array<import('./model.mjs').ModelDocument<TDocument>>; total: number; }>;
|
|
337
|
+
vectorSearch(options: import('./model.mjs').ModelVectorSearchOptions): Promise<Array<import('./collection.mjs').VectorSearchHit<import('./model.mjs').ModelDocument<TDocument>>>>;
|
|
337
338
|
count(query?: unknown, options?: unknown): Promise<number>;
|
|
338
339
|
insertOne(document?: unknown, options?: unknown): Promise<{ acknowledged: boolean; insertedId: any; }>;
|
|
339
340
|
insertMany(documents?: unknown[], options?: unknown): Promise<InsertManyResult>;
|
|
@@ -345,6 +346,9 @@ export declare class ModelInstance<TDocument = any> implements ModelInstanceCont
|
|
|
345
346
|
upsertOne(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
346
347
|
deleteOne(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
347
348
|
deleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
349
|
+
checkRelationUsage(filter?: unknown, options?: import('./model.mjs').RelationUsageOptions): Promise<import('./model.mjs').RelationUsageReport>;
|
|
350
|
+
deleteOneWithRelations(filter: unknown, options?: import('./model.mjs').RelationProtectedDeleteOptions): Promise<import('./model.mjs').RelationProtectedDeleteResult>;
|
|
351
|
+
forceDeleteWithRelations(filter: unknown, options?: import('./model.mjs').RelationProtectedDeleteOptions): Promise<import('./model.mjs').RelationProtectedDeleteResult>;
|
|
348
352
|
createIndex(keys: unknown, options?: unknown): Promise<IndexCreateResult>;
|
|
349
353
|
createIndexes(specs: Array<{ key: unknown; } & Record<string, unknown>>): Promise<string[]>;
|
|
350
354
|
listIndexes(): Promise<Record<string, unknown>[]>;
|
package/dist/types/runtime.d.ts
CHANGED
|
@@ -334,6 +334,7 @@ export declare class ModelInstance<TDocument = any> implements ModelInstanceCont
|
|
|
334
334
|
meta?: import('./collection').MetaInfo;
|
|
335
335
|
}>;
|
|
336
336
|
findAndCount(query?: unknown, options?: unknown): import('./model').PopulateProxy<{ data: Array<import('./model').ModelDocument<TDocument>>; total: number; }>;
|
|
337
|
+
vectorSearch(options: import('./model').ModelVectorSearchOptions): Promise<Array<import('./collection').VectorSearchHit<import('./model').ModelDocument<TDocument>>>>;
|
|
337
338
|
count(query?: unknown, options?: unknown): Promise<number>;
|
|
338
339
|
insertOne(document?: unknown, options?: unknown): Promise<{ acknowledged: boolean; insertedId: any; }>;
|
|
339
340
|
insertMany(documents?: unknown[], options?: unknown): Promise<InsertManyResult>;
|
|
@@ -345,6 +346,9 @@ export declare class ModelInstance<TDocument = any> implements ModelInstanceCont
|
|
|
345
346
|
upsertOne(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
346
347
|
deleteOne(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
347
348
|
deleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
349
|
+
checkRelationUsage(filter?: unknown, options?: import('./model').RelationUsageOptions): Promise<import('./model').RelationUsageReport>;
|
|
350
|
+
deleteOneWithRelations(filter: unknown, options?: import('./model').RelationProtectedDeleteOptions): Promise<import('./model').RelationProtectedDeleteResult>;
|
|
351
|
+
forceDeleteWithRelations(filter: unknown, options?: import('./model').RelationProtectedDeleteOptions): Promise<import('./model').RelationProtectedDeleteResult>;
|
|
348
352
|
createIndex(keys: unknown, options?: unknown): Promise<IndexCreateResult>;
|
|
349
353
|
createIndexes(specs: Array<{ key: unknown; } & Record<string, unknown>>): Promise<string[]>;
|
|
350
354
|
listIndexes(): Promise<Record<string, unknown>[]>;
|