monsqlize 3.3.4 → 3.5.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 +5 -3
- package/README.md +1 -1
- package/changelogs/v3.4.0.md +28 -0
- package/changelogs/v3.5.0.md +23 -0
- package/dist/cjs/cli/data-task.cjs +5 -2
- package/dist/cjs/index.cjs +8983 -7429
- package/dist/cjs/transaction/Transaction.cjs +14 -0
- package/dist/cjs/transaction/TransactionManager.cjs +14 -0
- package/dist/esm/index.mjs +8995 -7441
- package/dist/types/base.d.mts +12 -0
- package/dist/types/base.d.ts +12 -0
- package/dist/types/collection.d.mts +2 -2
- package/dist/types/collection.d.ts +2 -2
- package/dist/types/gridfs.d.mts +146 -0
- package/dist/types/gridfs.d.ts +146 -0
- package/dist/types/index.d.mts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/model.d.mts +4 -2
- package/dist/types/model.d.ts +4 -2
- package/dist/types/monsqlize.d.mts +20 -0
- package/dist/types/monsqlize.d.ts +20 -0
- package/dist/types/runtime.d.mts +9 -0
- package/dist/types/runtime.d.ts +9 -0
- package/dist/types/search-index.d.mts +107 -0
- package/dist/types/search-index.d.ts +107 -0
- package/package.json +5 -2
package/dist/types/base.d.mts
CHANGED
|
@@ -37,6 +37,18 @@ export declare const enum ErrorCodes {
|
|
|
37
37
|
INVALID_PAGINATION = 'INVALID_PAGINATION',
|
|
38
38
|
INVALID_OPERATION = 'INVALID_OPERATION',
|
|
39
39
|
INVALID_VECTOR_SEARCH = 'INVALID_VECTOR_SEARCH',
|
|
40
|
+
INVALID_SEARCH_INDEX_DEFINITION = 'INVALID_SEARCH_INDEX_DEFINITION',
|
|
41
|
+
SEARCH_INDEX_EXISTS = 'SEARCH_INDEX_EXISTS',
|
|
42
|
+
SEARCH_INDEX_NOT_FOUND = 'SEARCH_INDEX_NOT_FOUND',
|
|
43
|
+
SEARCH_INDEX_UNSUPPORTED = 'SEARCH_INDEX_UNSUPPORTED',
|
|
44
|
+
SEARCH_INDEX_BUILD_FAILED = 'SEARCH_INDEX_BUILD_FAILED',
|
|
45
|
+
SEARCH_INDEX_WAIT_TIMEOUT = 'SEARCH_INDEX_WAIT_TIMEOUT',
|
|
46
|
+
GRIDFS_FILE_NOT_FOUND = 'GRIDFS_FILE_NOT_FOUND',
|
|
47
|
+
GRIDFS_FILE_EXISTS = 'GRIDFS_FILE_EXISTS',
|
|
48
|
+
GRIDFS_INTEGRITY_MISMATCH = 'GRIDFS_INTEGRITY_MISMATCH',
|
|
49
|
+
GRIDFS_UPLOAD_INCOMPLETE = 'GRIDFS_UPLOAD_INCOMPLETE',
|
|
50
|
+
GRIDFS_RESUME_MISMATCH = 'GRIDFS_RESUME_MISMATCH',
|
|
51
|
+
GRIDFS_RANGE_INVALID = 'GRIDFS_RANGE_INVALID',
|
|
40
52
|
INVALID_RELATION_SELECT = 'INVALID_RELATION_SELECT',
|
|
41
53
|
RELATION_IN_USE = 'RELATION_IN_USE',
|
|
42
54
|
RELATION_USAGE_UNAVAILABLE = 'RELATION_USAGE_UNAVAILABLE',
|
package/dist/types/base.d.ts
CHANGED
|
@@ -37,6 +37,18 @@ export declare const enum ErrorCodes {
|
|
|
37
37
|
INVALID_PAGINATION = 'INVALID_PAGINATION',
|
|
38
38
|
INVALID_OPERATION = 'INVALID_OPERATION',
|
|
39
39
|
INVALID_VECTOR_SEARCH = 'INVALID_VECTOR_SEARCH',
|
|
40
|
+
INVALID_SEARCH_INDEX_DEFINITION = 'INVALID_SEARCH_INDEX_DEFINITION',
|
|
41
|
+
SEARCH_INDEX_EXISTS = 'SEARCH_INDEX_EXISTS',
|
|
42
|
+
SEARCH_INDEX_NOT_FOUND = 'SEARCH_INDEX_NOT_FOUND',
|
|
43
|
+
SEARCH_INDEX_UNSUPPORTED = 'SEARCH_INDEX_UNSUPPORTED',
|
|
44
|
+
SEARCH_INDEX_BUILD_FAILED = 'SEARCH_INDEX_BUILD_FAILED',
|
|
45
|
+
SEARCH_INDEX_WAIT_TIMEOUT = 'SEARCH_INDEX_WAIT_TIMEOUT',
|
|
46
|
+
GRIDFS_FILE_NOT_FOUND = 'GRIDFS_FILE_NOT_FOUND',
|
|
47
|
+
GRIDFS_FILE_EXISTS = 'GRIDFS_FILE_EXISTS',
|
|
48
|
+
GRIDFS_INTEGRITY_MISMATCH = 'GRIDFS_INTEGRITY_MISMATCH',
|
|
49
|
+
GRIDFS_UPLOAD_INCOMPLETE = 'GRIDFS_UPLOAD_INCOMPLETE',
|
|
50
|
+
GRIDFS_RESUME_MISMATCH = 'GRIDFS_RESUME_MISMATCH',
|
|
51
|
+
GRIDFS_RANGE_INVALID = 'GRIDFS_RANGE_INVALID',
|
|
40
52
|
INVALID_RELATION_SELECT = 'INVALID_RELATION_SELECT',
|
|
41
53
|
RELATION_IN_USE = 'RELATION_IN_USE',
|
|
42
54
|
RELATION_USAGE_UNAVAILABLE = 'RELATION_USAGE_UNAVAILABLE',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChangeStream, Document, FindOptions as MongoFindOptions, Sort } from 'mongodb';
|
|
1
|
+
import type { ChangeStream, Document, FindOptions as MongoFindOptions, Sort } from 'mongodb'; import type { SearchIndexManagement } from './search-index.mjs';
|
|
2
2
|
import type {
|
|
3
3
|
MetaOptions,
|
|
4
4
|
VectorSearchHit,
|
|
@@ -685,7 +685,7 @@ export interface AdminAccessor {
|
|
|
685
685
|
stats(options?: { scale?: number; }): Promise<DbStatsView>;
|
|
686
686
|
}
|
|
687
687
|
|
|
688
|
-
export interface Collection<TSchema = any> {
|
|
688
|
+
export interface Collection<TSchema = any> extends SearchIndexManagement {
|
|
689
689
|
/** Returns the namespace descriptor (iid, db, collection) for this collection. */
|
|
690
690
|
getNamespace(): { iid: string; type: 'mongodb'; db: string; collection: string; pool?: string; };
|
|
691
691
|
/** Returns the underlying native MongoDB Collection object. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChangeStream, Document, FindOptions as MongoFindOptions, Sort } from 'mongodb';
|
|
1
|
+
import type { ChangeStream, Document, FindOptions as MongoFindOptions, Sort } from 'mongodb'; import type { SearchIndexManagement } from './search-index';
|
|
2
2
|
import type {
|
|
3
3
|
MetaOptions,
|
|
4
4
|
VectorSearchHit,
|
|
@@ -685,7 +685,7 @@ export interface AdminAccessor {
|
|
|
685
685
|
stats(options?: { scale?: number; }): Promise<DbStatsView>;
|
|
686
686
|
}
|
|
687
687
|
|
|
688
|
-
export interface Collection<TSchema = any> {
|
|
688
|
+
export interface Collection<TSchema = any> extends SearchIndexManagement {
|
|
689
689
|
/** Returns the namespace descriptor (iid, db, collection) for this collection. */
|
|
690
690
|
getNamespace(): { iid: string; type: 'mongodb'; db: string; collection: string; pool?: string; };
|
|
691
691
|
/** Returns the underlying native MongoDB Collection object. */
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GridFS bucket types.
|
|
3
|
+
* @since v3.5.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ObjectId } from 'mongodb';
|
|
7
|
+
import type { Readable, Writable } from 'node:stream';
|
|
8
|
+
|
|
9
|
+
/** Normalized GridFS file metadata. Driver-private state is omitted. */
|
|
10
|
+
export interface GridFSFileInfo {
|
|
11
|
+
/** `files._id`. */
|
|
12
|
+
id: ObjectId;
|
|
13
|
+
filename: string;
|
|
14
|
+
/** Byte length. Always >= 0. */
|
|
15
|
+
length: number;
|
|
16
|
+
/** Chunk size in bytes. Always > 0. */
|
|
17
|
+
chunkSize: number;
|
|
18
|
+
uploadDate: Date;
|
|
19
|
+
/** Present when the file was stored with a content type. */
|
|
20
|
+
contentType?: string;
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Options for `msq.gridfs()`. `db` and `pool` select the native database. */
|
|
25
|
+
export interface GridFSBucketOpenOptions {
|
|
26
|
+
/** Defaults to the runtime database. */
|
|
27
|
+
db?: string;
|
|
28
|
+
/** Defaults to the runtime connection. A named pool uses that pool's client. */
|
|
29
|
+
pool?: string;
|
|
30
|
+
/** Defaults to 261120 (255 KiB). Must be a positive integer. */
|
|
31
|
+
chunkSizeBytes?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Options for `model.gridfs()`. Pool and database come from the Model. */
|
|
35
|
+
export interface GridFSModelBucketOpenOptions {
|
|
36
|
+
/** Defaults to 261120 (255 KiB). Must be a positive integer. */
|
|
37
|
+
chunkSizeBytes?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** What to do when uploaded content matches an existing visible file. Default `error`. */
|
|
41
|
+
export type GridFSIfExists = 'error' | 'skip' | 'duplicate';
|
|
42
|
+
|
|
43
|
+
export interface GridFSUploadOptions {
|
|
44
|
+
/** Custom `files._id`. An existing id rejects with `GRIDFS_FILE_EXISTS`. */
|
|
45
|
+
id?: ObjectId;
|
|
46
|
+
metadata?: Record<string, unknown>;
|
|
47
|
+
contentType?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Lowercase 64-character sha256 hex. Stored as `metadata.sha256` and used as the idempotency key.
|
|
50
|
+
* When the bytes do not match, upload rejects with `GRIDFS_INTEGRITY_MISMATCH` before the file is visible.
|
|
51
|
+
*/
|
|
52
|
+
sha256?: string;
|
|
53
|
+
/** Default `error`. */
|
|
54
|
+
ifExists?: GridFSIfExists;
|
|
55
|
+
/** Overrides the bucket chunk size for this file only. */
|
|
56
|
+
chunkSizeBytes?: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** `uploadStream` writes `sha256` into metadata and does not support `ifExists`. */
|
|
60
|
+
export interface GridFSUploadStreamOptions extends Omit<GridFSUploadOptions, 'ifExists'> {}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Download target. `revision` follows the driver: `0` is the oldest file with that name,
|
|
64
|
+
* `-1` (default) is the newest.
|
|
65
|
+
*/
|
|
66
|
+
export type GridFSIdOrName = ObjectId | { filename: string; revision?: number };
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Inclusive `start` and exclusive `end`, matching `GridFSBucketReadStreamOptions`.
|
|
70
|
+
* Omitted `start` means 0. Omitted `end` means the file length.
|
|
71
|
+
*/
|
|
72
|
+
export interface GridFSDownloadRange {
|
|
73
|
+
start?: number;
|
|
74
|
+
end?: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface GridFSFindFilesFilter {
|
|
78
|
+
filename?: string;
|
|
79
|
+
[key: string]: unknown;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface GridFSFindFilesOptions {
|
|
83
|
+
/** Positive integer. Omit for no limit. */
|
|
84
|
+
limit?: number;
|
|
85
|
+
/** Non-negative integer. Default 0. */
|
|
86
|
+
skip?: number;
|
|
87
|
+
sort?: Record<string, 1 | -1>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface GridFSDeleteOptions {
|
|
91
|
+
/** Default false. When true, a missing file resolves instead of `GRIDFS_FILE_NOT_FOUND`. */
|
|
92
|
+
ignoreMissing?: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface BeginResumableUploadOptions {
|
|
96
|
+
/** Final byte length. Positive integer. */
|
|
97
|
+
length: number;
|
|
98
|
+
/** Final lowercase sha256 hex. Checked by `finalizeResumableUpload`. */
|
|
99
|
+
sha256: string;
|
|
100
|
+
chunkSizeBytes?: number;
|
|
101
|
+
metadata?: Record<string, unknown>;
|
|
102
|
+
contentType?: string;
|
|
103
|
+
/** Also the id returned as `uploadId` and the final `files._id`. */
|
|
104
|
+
id?: ObjectId;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface BeginResumableUploadResult {
|
|
108
|
+
uploadId: ObjectId;
|
|
109
|
+
/** Next chunk index to write. A new session returns 0. */
|
|
110
|
+
nextChunk: number;
|
|
111
|
+
chunkSizeBytes: number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface AppendChunksResult {
|
|
115
|
+
nextChunk: number;
|
|
116
|
+
bytesAccepted: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Bucket returned by `msq.gridfs()` and `model.gridfs()`.
|
|
121
|
+
* Reads do not consult `writePathPolicy`. Writes use category `gridfs`.
|
|
122
|
+
* `drop` uses category `management`.
|
|
123
|
+
*/
|
|
124
|
+
export interface MonSQLizeGridFSBucket {
|
|
125
|
+
readonly bucketName: string;
|
|
126
|
+
readonly dbName: string;
|
|
127
|
+
readonly chunkSizeBytes: number;
|
|
128
|
+
upload(filename: string, data: Buffer | Uint8Array | Readable, opts?: GridFSUploadOptions): Promise<GridFSFileInfo>;
|
|
129
|
+
uploadStream(filename: string, opts?: GridFSUploadStreamOptions): Writable & { id: ObjectId; done: Promise<GridFSFileInfo> };
|
|
130
|
+
download(idOrName: GridFSIdOrName): Promise<Buffer>;
|
|
131
|
+
downloadStream(idOrName: GridFSIdOrName, range?: GridFSDownloadRange): Readable;
|
|
132
|
+
/** Returns null when the id is absent. */
|
|
133
|
+
getFile(id: ObjectId): Promise<GridFSFileInfo | null>;
|
|
134
|
+
findFiles(filter?: GridFSFindFilesFilter, opts?: GridFSFindFilesOptions): Promise<GridFSFileInfo[]>;
|
|
135
|
+
delete(id: ObjectId, opts?: GridFSDeleteOptions): Promise<void>;
|
|
136
|
+
rename(id: ObjectId, filename: string): Promise<void>;
|
|
137
|
+
/** Drops `<bucket>.files`, `<bucket>.chunks`, and `<bucket>.uploads` when present. */
|
|
138
|
+
drop(): Promise<void>;
|
|
139
|
+
beginResumableUpload(filename: string, opts: BeginResumableUploadOptions): Promise<BeginResumableUploadResult>;
|
|
140
|
+
appendChunks(uploadId: ObjectId, fromChunk: number, data: Buffer | Uint8Array | Readable): Promise<AppendChunksResult>;
|
|
141
|
+
finalizeResumableUpload(uploadId: ObjectId): Promise<GridFSFileInfo>;
|
|
142
|
+
/** Deletes the session and any chunks. A missing or already aborted session resolves. */
|
|
143
|
+
abortResumableUpload(uploadId: ObjectId): Promise<void>;
|
|
144
|
+
/** Creates the standard files/chunks indexes, `metadata.sha256`, and the uploads TTL index. */
|
|
145
|
+
ensureIndexes(): Promise<void>;
|
|
146
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GridFS bucket types.
|
|
3
|
+
* @since v3.5.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ObjectId } from 'mongodb';
|
|
7
|
+
import type { Readable, Writable } from 'node:stream';
|
|
8
|
+
|
|
9
|
+
/** Normalized GridFS file metadata. Driver-private state is omitted. */
|
|
10
|
+
export interface GridFSFileInfo {
|
|
11
|
+
/** `files._id`. */
|
|
12
|
+
id: ObjectId;
|
|
13
|
+
filename: string;
|
|
14
|
+
/** Byte length. Always >= 0. */
|
|
15
|
+
length: number;
|
|
16
|
+
/** Chunk size in bytes. Always > 0. */
|
|
17
|
+
chunkSize: number;
|
|
18
|
+
uploadDate: Date;
|
|
19
|
+
/** Present when the file was stored with a content type. */
|
|
20
|
+
contentType?: string;
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Options for `msq.gridfs()`. `db` and `pool` select the native database. */
|
|
25
|
+
export interface GridFSBucketOpenOptions {
|
|
26
|
+
/** Defaults to the runtime database. */
|
|
27
|
+
db?: string;
|
|
28
|
+
/** Defaults to the runtime connection. A named pool uses that pool's client. */
|
|
29
|
+
pool?: string;
|
|
30
|
+
/** Defaults to 261120 (255 KiB). Must be a positive integer. */
|
|
31
|
+
chunkSizeBytes?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Options for `model.gridfs()`. Pool and database come from the Model. */
|
|
35
|
+
export interface GridFSModelBucketOpenOptions {
|
|
36
|
+
/** Defaults to 261120 (255 KiB). Must be a positive integer. */
|
|
37
|
+
chunkSizeBytes?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** What to do when uploaded content matches an existing visible file. Default `error`. */
|
|
41
|
+
export type GridFSIfExists = 'error' | 'skip' | 'duplicate';
|
|
42
|
+
|
|
43
|
+
export interface GridFSUploadOptions {
|
|
44
|
+
/** Custom `files._id`. An existing id rejects with `GRIDFS_FILE_EXISTS`. */
|
|
45
|
+
id?: ObjectId;
|
|
46
|
+
metadata?: Record<string, unknown>;
|
|
47
|
+
contentType?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Lowercase 64-character sha256 hex. Stored as `metadata.sha256` and used as the idempotency key.
|
|
50
|
+
* When the bytes do not match, upload rejects with `GRIDFS_INTEGRITY_MISMATCH` before the file is visible.
|
|
51
|
+
*/
|
|
52
|
+
sha256?: string;
|
|
53
|
+
/** Default `error`. */
|
|
54
|
+
ifExists?: GridFSIfExists;
|
|
55
|
+
/** Overrides the bucket chunk size for this file only. */
|
|
56
|
+
chunkSizeBytes?: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** `uploadStream` writes `sha256` into metadata and does not support `ifExists`. */
|
|
60
|
+
export interface GridFSUploadStreamOptions extends Omit<GridFSUploadOptions, 'ifExists'> {}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Download target. `revision` follows the driver: `0` is the oldest file with that name,
|
|
64
|
+
* `-1` (default) is the newest.
|
|
65
|
+
*/
|
|
66
|
+
export type GridFSIdOrName = ObjectId | { filename: string; revision?: number };
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Inclusive `start` and exclusive `end`, matching `GridFSBucketReadStreamOptions`.
|
|
70
|
+
* Omitted `start` means 0. Omitted `end` means the file length.
|
|
71
|
+
*/
|
|
72
|
+
export interface GridFSDownloadRange {
|
|
73
|
+
start?: number;
|
|
74
|
+
end?: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface GridFSFindFilesFilter {
|
|
78
|
+
filename?: string;
|
|
79
|
+
[key: string]: unknown;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface GridFSFindFilesOptions {
|
|
83
|
+
/** Positive integer. Omit for no limit. */
|
|
84
|
+
limit?: number;
|
|
85
|
+
/** Non-negative integer. Default 0. */
|
|
86
|
+
skip?: number;
|
|
87
|
+
sort?: Record<string, 1 | -1>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface GridFSDeleteOptions {
|
|
91
|
+
/** Default false. When true, a missing file resolves instead of `GRIDFS_FILE_NOT_FOUND`. */
|
|
92
|
+
ignoreMissing?: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface BeginResumableUploadOptions {
|
|
96
|
+
/** Final byte length. Positive integer. */
|
|
97
|
+
length: number;
|
|
98
|
+
/** Final lowercase sha256 hex. Checked by `finalizeResumableUpload`. */
|
|
99
|
+
sha256: string;
|
|
100
|
+
chunkSizeBytes?: number;
|
|
101
|
+
metadata?: Record<string, unknown>;
|
|
102
|
+
contentType?: string;
|
|
103
|
+
/** Also the id returned as `uploadId` and the final `files._id`. */
|
|
104
|
+
id?: ObjectId;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface BeginResumableUploadResult {
|
|
108
|
+
uploadId: ObjectId;
|
|
109
|
+
/** Next chunk index to write. A new session returns 0. */
|
|
110
|
+
nextChunk: number;
|
|
111
|
+
chunkSizeBytes: number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface AppendChunksResult {
|
|
115
|
+
nextChunk: number;
|
|
116
|
+
bytesAccepted: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Bucket returned by `msq.gridfs()` and `model.gridfs()`.
|
|
121
|
+
* Reads do not consult `writePathPolicy`. Writes use category `gridfs`.
|
|
122
|
+
* `drop` uses category `management`.
|
|
123
|
+
*/
|
|
124
|
+
export interface MonSQLizeGridFSBucket {
|
|
125
|
+
readonly bucketName: string;
|
|
126
|
+
readonly dbName: string;
|
|
127
|
+
readonly chunkSizeBytes: number;
|
|
128
|
+
upload(filename: string, data: Buffer | Uint8Array | Readable, opts?: GridFSUploadOptions): Promise<GridFSFileInfo>;
|
|
129
|
+
uploadStream(filename: string, opts?: GridFSUploadStreamOptions): Writable & { id: ObjectId; done: Promise<GridFSFileInfo> };
|
|
130
|
+
download(idOrName: GridFSIdOrName): Promise<Buffer>;
|
|
131
|
+
downloadStream(idOrName: GridFSIdOrName, range?: GridFSDownloadRange): Readable;
|
|
132
|
+
/** Returns null when the id is absent. */
|
|
133
|
+
getFile(id: ObjectId): Promise<GridFSFileInfo | null>;
|
|
134
|
+
findFiles(filter?: GridFSFindFilesFilter, opts?: GridFSFindFilesOptions): Promise<GridFSFileInfo[]>;
|
|
135
|
+
delete(id: ObjectId, opts?: GridFSDeleteOptions): Promise<void>;
|
|
136
|
+
rename(id: ObjectId, filename: string): Promise<void>;
|
|
137
|
+
/** Drops `<bucket>.files`, `<bucket>.chunks`, and `<bucket>.uploads` when present. */
|
|
138
|
+
drop(): Promise<void>;
|
|
139
|
+
beginResumableUpload(filename: string, opts: BeginResumableUploadOptions): Promise<BeginResumableUploadResult>;
|
|
140
|
+
appendChunks(uploadId: ObjectId, fromChunk: number, data: Buffer | Uint8Array | Readable): Promise<AppendChunksResult>;
|
|
141
|
+
finalizeResumableUpload(uploadId: ObjectId): Promise<GridFSFileInfo>;
|
|
142
|
+
/** Deletes the session and any chunks. A missing or already aborted session resolves. */
|
|
143
|
+
abortResumableUpload(uploadId: ObjectId): Promise<void>;
|
|
144
|
+
/** Creates the standard files/chunks indexes, `metadata.sha256`, and the uploads TTL index. */
|
|
145
|
+
ensureIndexes(): Promise<void>;
|
|
146
|
+
}
|
package/dist/types/index.d.mts
CHANGED
|
@@ -2,12 +2,14 @@ export * from './base.mjs';
|
|
|
2
2
|
export * from './collection.mjs';
|
|
3
3
|
export * from './data-tasks.mjs';
|
|
4
4
|
export * from './expression.mjs';
|
|
5
|
+
export * from './gridfs.mjs';
|
|
5
6
|
export * from './lock.mjs';
|
|
6
7
|
export * from './model.mjs';
|
|
7
8
|
export * from './mongodb.mjs';
|
|
8
9
|
export * from './pool.mjs';
|
|
9
10
|
export * from './runtime.mjs';
|
|
10
11
|
export * from './saga.mjs';
|
|
12
|
+
export * from './search-index.mjs';
|
|
11
13
|
export * from './slow-query-log.mjs';
|
|
12
14
|
export * from './sync.mjs';
|
|
13
15
|
export * from './transaction.mjs';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,12 +2,14 @@ export * from './base';
|
|
|
2
2
|
export * from './collection';
|
|
3
3
|
export * from './data-tasks';
|
|
4
4
|
export * from './expression';
|
|
5
|
+
export * from './gridfs';
|
|
5
6
|
export * from './lock';
|
|
6
7
|
export * from './model';
|
|
7
8
|
export * from './mongodb';
|
|
8
9
|
export * from './pool';
|
|
9
10
|
export * from './runtime';
|
|
10
11
|
export * from './saga';
|
|
12
|
+
export * from './search-index';
|
|
11
13
|
export * from './slow-query-log';
|
|
12
14
|
export * from './sync';
|
|
13
15
|
export * from './transaction';
|
package/dist/types/model.d.mts
CHANGED
|
@@ -1,5 +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
|
+
import type { InferSchema } from 'schema-dsl'; import type { SearchIndexManagement } from './search-index.mjs';
|
|
3
3
|
import type { SchemaDslRuntime } from 'schema-dsl/runtime';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -428,7 +428,7 @@ export type ModelDocument<TDocument = any> = TDocument & Record<string, unknown>
|
|
|
428
428
|
toJSON(): TDocument & Record<string, unknown>;
|
|
429
429
|
};
|
|
430
430
|
|
|
431
|
-
export interface ModelInstance<TDocument = any> {
|
|
431
|
+
export interface ModelInstance<TDocument = any> extends SearchIndexManagement {
|
|
432
432
|
readonly collectionName: string;
|
|
433
433
|
readonly dbName: string;
|
|
434
434
|
readonly poolName?: string;
|
|
@@ -706,6 +706,8 @@ export interface ModelInstance<TDocument = any> {
|
|
|
706
706
|
* Does not drop, rename, or rebuild conflicting indexes.
|
|
707
707
|
*/
|
|
708
708
|
ensureIndexes(options?: ModelEnsureIndexesOptions): Promise<ModelIndexEnsureResult>;
|
|
709
|
+
/** Opens a GridFS bucket bound to this Model's pool and database. Default bucket name is `fs`. @since v3.5.0 */
|
|
710
|
+
gridfs(bucketName?: string, opts?: import('./gridfs.mjs').GridFSModelBucketOpenOptions): import('./gridfs.mjs').MonSQLizeGridFSBucket;
|
|
709
711
|
/**
|
|
710
712
|
* Drops the specified index by name.
|
|
711
713
|
* @param name Index name.
|
package/dist/types/model.d.ts
CHANGED
|
@@ -1,5 +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
|
+
import type { InferSchema } from 'schema-dsl'; import type { SearchIndexManagement } from './search-index';
|
|
3
3
|
import type { SchemaDslRuntime } from 'schema-dsl/runtime';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -428,7 +428,7 @@ export type ModelDocument<TDocument = any> = TDocument & Record<string, unknown>
|
|
|
428
428
|
toJSON(): TDocument & Record<string, unknown>;
|
|
429
429
|
};
|
|
430
430
|
|
|
431
|
-
export interface ModelInstance<TDocument = any> {
|
|
431
|
+
export interface ModelInstance<TDocument = any> extends SearchIndexManagement {
|
|
432
432
|
readonly collectionName: string;
|
|
433
433
|
readonly dbName: string;
|
|
434
434
|
readonly poolName?: string;
|
|
@@ -706,6 +706,8 @@ export interface ModelInstance<TDocument = any> {
|
|
|
706
706
|
* Does not drop, rename, or rebuild conflicting indexes.
|
|
707
707
|
*/
|
|
708
708
|
ensureIndexes(options?: ModelEnsureIndexesOptions): Promise<ModelIndexEnsureResult>;
|
|
709
|
+
/** Opens a GridFS bucket bound to this Model's pool and database. Default bucket name is `fs`. @since v3.5.0 */
|
|
710
|
+
gridfs(bucketName?: string, opts?: import('./gridfs').GridFSModelBucketOpenOptions): import('./gridfs').MonSQLizeGridFSBucket;
|
|
709
711
|
/**
|
|
710
712
|
* Drops the specified index by name.
|
|
711
713
|
* @param name Index name.
|
|
@@ -37,6 +37,7 @@ export interface SSHConfig {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
import type { Collection, CursorValueNormalizer, CursorValueType, DbAccessor, HealthView } from './collection.mjs';
|
|
40
|
+
import type { GridFSBucketOpenOptions, MonSQLizeGridFSBucket } from './gridfs.mjs';
|
|
40
41
|
import type { DataTaskJobError } from './data-tasks.mjs';
|
|
41
42
|
import type { Lock, LockOptions, LockStats } from './lock.mjs';
|
|
42
43
|
import type { ModelAutoIndexOptions, ModelDescriptor, ModelEnsureAllIndexesOptions, ModelIndexEnsureSummary, ModelInstance } from './model.mjs';
|
|
@@ -92,6 +93,12 @@ export type WritePathPolicyRawMode = 'inherit' | 'allow' | 'block';
|
|
|
92
93
|
/** Controls whether collection/database management writes are available under a write path policy. */
|
|
93
94
|
export type WritePathPolicyManagementMode = 'inherit' | 'allow' | 'block';
|
|
94
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Controls GridFS writes. `inherit` follows `mode`, except `model-only` still blocks
|
|
98
|
+
* GridFS writes from every source until the rule is `allow`.
|
|
99
|
+
*/
|
|
100
|
+
export type WritePathPolicyGridfsMode = 'inherit' | 'allow' | 'block';
|
|
101
|
+
|
|
95
102
|
/** Controls violation handling; `warn` logs and allows for migration observation. */
|
|
96
103
|
export type WritePathPolicyViolationAction = 'throw' | 'warn';
|
|
97
104
|
|
|
@@ -103,6 +110,11 @@ export interface WritePathPolicyRule {
|
|
|
103
110
|
raw?: WritePathPolicyRawMode;
|
|
104
111
|
/** Management write policy. `inherit` allows model management and blocks external management in `model-only`. */
|
|
105
112
|
management?: WritePathPolicyManagementMode;
|
|
113
|
+
/**
|
|
114
|
+
* GridFS write policy. Default: `inherit`.
|
|
115
|
+
* `inherit` allows GridFS writes in `allow-both` and blocks them in `model-only` even when `source` is `model`.
|
|
116
|
+
*/
|
|
117
|
+
gridfs?: WritePathPolicyGridfsMode;
|
|
106
118
|
/** Violation action. Default: `throw`. */
|
|
107
119
|
onViolation?: WritePathPolicyViolationAction;
|
|
108
120
|
}
|
|
@@ -324,6 +336,12 @@ export interface MonSQLizeInstance {
|
|
|
324
336
|
* @param name Target database name; omit to use the default database.
|
|
325
337
|
*/
|
|
326
338
|
db(name?: string): DbAccessor;
|
|
339
|
+
/**
|
|
340
|
+
* Open a GridFS bucket. The default bucket name is `fs`.
|
|
341
|
+
* Call after `connect()`; otherwise this throws `NOT_CONNECTED`.
|
|
342
|
+
* @since v3.5.0
|
|
343
|
+
*/
|
|
344
|
+
gridfs(bucketName?: string, opts?: GridFSBucketOpenOptions): MonSQLizeGridFSBucket;
|
|
327
345
|
/**
|
|
328
346
|
* Switch to the given database and return its `collection` and `model` accessors.
|
|
329
347
|
* @param name Target database name.
|
|
@@ -546,6 +564,8 @@ export default class MonSQLize implements MonSQLizeInstance {
|
|
|
546
564
|
collection<TSchema = any>(name: string): Collection<TSchema>;
|
|
547
565
|
collection(name: string): Collection<any>;
|
|
548
566
|
db(name?: string): DbAccessor;
|
|
567
|
+
/** @since v3.5.0 */
|
|
568
|
+
gridfs(bucketName?: string, opts?: GridFSBucketOpenOptions): MonSQLizeGridFSBucket;
|
|
549
569
|
use(name: string): {
|
|
550
570
|
collection: <TSchema = any>(collectionName: string) => Collection<TSchema>;
|
|
551
571
|
model: ModelBindingAccessor;
|
|
@@ -37,6 +37,7 @@ export interface SSHConfig {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
import type { Collection, CursorValueNormalizer, CursorValueType, DbAccessor, HealthView } from './collection';
|
|
40
|
+
import type { GridFSBucketOpenOptions, MonSQLizeGridFSBucket } from './gridfs';
|
|
40
41
|
import type { DataTaskJobError } from './data-tasks';
|
|
41
42
|
import type { Lock, LockOptions, LockStats } from './lock';
|
|
42
43
|
import type { ModelAutoIndexOptions, ModelDescriptor, ModelEnsureAllIndexesOptions, ModelIndexEnsureSummary, ModelInstance } from './model';
|
|
@@ -92,6 +93,12 @@ export type WritePathPolicyRawMode = 'inherit' | 'allow' | 'block';
|
|
|
92
93
|
/** Controls whether collection/database management writes are available under a write path policy. */
|
|
93
94
|
export type WritePathPolicyManagementMode = 'inherit' | 'allow' | 'block';
|
|
94
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Controls GridFS writes. `inherit` follows `mode`, except `model-only` still blocks
|
|
98
|
+
* GridFS writes from every source until the rule is `allow`.
|
|
99
|
+
*/
|
|
100
|
+
export type WritePathPolicyGridfsMode = 'inherit' | 'allow' | 'block';
|
|
101
|
+
|
|
95
102
|
/** Controls violation handling; `warn` logs and allows for migration observation. */
|
|
96
103
|
export type WritePathPolicyViolationAction = 'throw' | 'warn';
|
|
97
104
|
|
|
@@ -103,6 +110,11 @@ export interface WritePathPolicyRule {
|
|
|
103
110
|
raw?: WritePathPolicyRawMode;
|
|
104
111
|
/** Management write policy. `inherit` allows model management and blocks external management in `model-only`. */
|
|
105
112
|
management?: WritePathPolicyManagementMode;
|
|
113
|
+
/**
|
|
114
|
+
* GridFS write policy. Default: `inherit`.
|
|
115
|
+
* `inherit` allows GridFS writes in `allow-both` and blocks them in `model-only` even when `source` is `model`.
|
|
116
|
+
*/
|
|
117
|
+
gridfs?: WritePathPolicyGridfsMode;
|
|
106
118
|
/** Violation action. Default: `throw`. */
|
|
107
119
|
onViolation?: WritePathPolicyViolationAction;
|
|
108
120
|
}
|
|
@@ -324,6 +336,12 @@ export interface MonSQLizeInstance {
|
|
|
324
336
|
* @param name Target database name; omit to use the default database.
|
|
325
337
|
*/
|
|
326
338
|
db(name?: string): DbAccessor;
|
|
339
|
+
/**
|
|
340
|
+
* Open a GridFS bucket. The default bucket name is `fs`.
|
|
341
|
+
* Call after `connect()`; otherwise this throws `NOT_CONNECTED`.
|
|
342
|
+
* @since v3.5.0
|
|
343
|
+
*/
|
|
344
|
+
gridfs(bucketName?: string, opts?: GridFSBucketOpenOptions): MonSQLizeGridFSBucket;
|
|
327
345
|
/**
|
|
328
346
|
* Switch to the given database and return its `collection` and `model` accessors.
|
|
329
347
|
* @param name Target database name.
|
|
@@ -546,6 +564,8 @@ export default class MonSQLize implements MonSQLizeInstance {
|
|
|
546
564
|
collection<TSchema = any>(name: string): Collection<TSchema>;
|
|
547
565
|
collection(name: string): Collection<any>;
|
|
548
566
|
db(name?: string): DbAccessor;
|
|
567
|
+
/** @since v3.5.0 */
|
|
568
|
+
gridfs(bucketName?: string, opts?: GridFSBucketOpenOptions): MonSQLizeGridFSBucket;
|
|
549
569
|
use(name: string): {
|
|
550
570
|
collection: <TSchema = any>(collectionName: string) => Collection<TSchema>;
|
|
551
571
|
model: ModelBindingAccessor;
|
package/dist/types/runtime.d.mts
CHANGED
|
@@ -343,8 +343,17 @@ export declare class ModelInstance<TDocument = any> implements ModelInstanceCont
|
|
|
343
343
|
createIndexes(specs: Array<{ key: unknown; } & Record<string, unknown>>): Promise<string[]>;
|
|
344
344
|
listIndexes(): Promise<Record<string, unknown>[]>;
|
|
345
345
|
ensureIndexes(options?: ModelEnsureIndexesOptions): Promise<ModelIndexEnsureResult>;
|
|
346
|
+
/** @since v3.5.0 */
|
|
347
|
+
gridfs(bucketName?: string, opts?: import('./gridfs.mjs').GridFSModelBucketOpenOptions): import('./gridfs.mjs').MonSQLizeGridFSBucket;
|
|
346
348
|
dropIndex(name: string): Promise<unknown>;
|
|
347
349
|
dropIndexes(): Promise<unknown>;
|
|
350
|
+
createSearchIndex(spec: import('./search-index.mjs').SearchIndexSpec, options?: import('./search-index.mjs').CreateSearchIndexOptions): Promise<import('./search-index.mjs').CreateSearchIndexResult>;
|
|
351
|
+
createSearchIndexes(specs: import('./search-index.mjs').SearchIndexSpec[]): Promise<string[]>;
|
|
352
|
+
listSearchIndexes(options?: import('./search-index.mjs').ListSearchIndexesOptions): Promise<import('./search-index.mjs').SearchIndexInfo[]>;
|
|
353
|
+
getSearchIndex(name: string): Promise<import('./search-index.mjs').SearchIndexInfo>;
|
|
354
|
+
updateSearchIndex(name: string, definition: Record<string, unknown>): Promise<void>;
|
|
355
|
+
dropSearchIndex(name: string, options?: import('./search-index.mjs').DropSearchIndexOptions): Promise<void>;
|
|
356
|
+
waitForSearchIndex(name: string, options?: import('./search-index.mjs').WaitForSearchIndexOptions): Promise<import('./search-index.mjs').SearchIndexInfo>;
|
|
348
357
|
prewarmBookmarks(keyDims?: unknown, pages?: number[]): Promise<BookmarkPrewarmResult>;
|
|
349
358
|
listBookmarks(keyDims?: unknown): Promise<BookmarkListResult>;
|
|
350
359
|
clearBookmarks(keyDims?: unknown): Promise<BookmarkClearResult>;
|
package/dist/types/runtime.d.ts
CHANGED
|
@@ -343,8 +343,17 @@ export declare class ModelInstance<TDocument = any> implements ModelInstanceCont
|
|
|
343
343
|
createIndexes(specs: Array<{ key: unknown; } & Record<string, unknown>>): Promise<string[]>;
|
|
344
344
|
listIndexes(): Promise<Record<string, unknown>[]>;
|
|
345
345
|
ensureIndexes(options?: ModelEnsureIndexesOptions): Promise<ModelIndexEnsureResult>;
|
|
346
|
+
/** @since v3.5.0 */
|
|
347
|
+
gridfs(bucketName?: string, opts?: import('./gridfs').GridFSModelBucketOpenOptions): import('./gridfs').MonSQLizeGridFSBucket;
|
|
346
348
|
dropIndex(name: string): Promise<unknown>;
|
|
347
349
|
dropIndexes(): Promise<unknown>;
|
|
350
|
+
createSearchIndex(spec: import('./search-index').SearchIndexSpec, options?: import('./search-index').CreateSearchIndexOptions): Promise<import('./search-index').CreateSearchIndexResult>;
|
|
351
|
+
createSearchIndexes(specs: import('./search-index').SearchIndexSpec[]): Promise<string[]>;
|
|
352
|
+
listSearchIndexes(options?: import('./search-index').ListSearchIndexesOptions): Promise<import('./search-index').SearchIndexInfo[]>;
|
|
353
|
+
getSearchIndex(name: string): Promise<import('./search-index').SearchIndexInfo>;
|
|
354
|
+
updateSearchIndex(name: string, definition: Record<string, unknown>): Promise<void>;
|
|
355
|
+
dropSearchIndex(name: string, options?: import('./search-index').DropSearchIndexOptions): Promise<void>;
|
|
356
|
+
waitForSearchIndex(name: string, options?: import('./search-index').WaitForSearchIndexOptions): Promise<import('./search-index').SearchIndexInfo>;
|
|
348
357
|
prewarmBookmarks(keyDims?: unknown, pages?: number[]): Promise<BookmarkPrewarmResult>;
|
|
349
358
|
listBookmarks(keyDims?: unknown): Promise<BookmarkListResult>;
|
|
350
359
|
clearBookmarks(keyDims?: unknown): Promise<BookmarkClearResult>;
|