@qp-mongosh/service-provider-core 0.0.0-dev.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/.eslintignore +2 -0
- package/.eslintrc.js +1 -0
- package/AUTHORS +11 -0
- package/LICENSE +201 -0
- package/lib/admin.d.ts +28 -0
- package/lib/admin.js +3 -0
- package/lib/admin.js.map +1 -0
- package/lib/all-fle-types.d.ts +2 -0
- package/lib/all-fle-types.js +3 -0
- package/lib/all-fle-types.js.map +1 -0
- package/lib/all-transport-types.d.ts +1 -0
- package/lib/all-transport-types.js +3 -0
- package/lib/all-transport-types.js.map +1 -0
- package/lib/cli-options.d.ts +43 -0
- package/lib/cli-options.js +3 -0
- package/lib/cli-options.js.map +1 -0
- package/lib/closable.d.ts +4 -0
- package/lib/closable.js +3 -0
- package/lib/closable.js.map +1 -0
- package/lib/connect-info.d.ts +19 -0
- package/lib/connect-info.js +35 -0
- package/lib/connect-info.js.map +1 -0
- package/lib/index.d.ts +31 -0
- package/lib/index.js +56 -0
- package/lib/index.js.map +1 -0
- package/lib/platform.d.ts +6 -0
- package/lib/platform.js +11 -0
- package/lib/platform.js.map +1 -0
- package/lib/printable-bson.d.ts +3 -0
- package/lib/printable-bson.js +82 -0
- package/lib/printable-bson.js.map +1 -0
- package/lib/readable.d.ts +18 -0
- package/lib/readable.js +3 -0
- package/lib/readable.js.map +1 -0
- package/lib/service-provider.d.ts +11 -0
- package/lib/service-provider.js +19 -0
- package/lib/service-provider.js.map +1 -0
- package/lib/shell-auth-options.d.ts +7 -0
- package/lib/shell-auth-options.js +3 -0
- package/lib/shell-auth-options.js.map +1 -0
- package/lib/textencoder-polyfill.d.ts +2 -0
- package/lib/textencoder-polyfill.js +22 -0
- package/lib/textencoder-polyfill.js.map +1 -0
- package/lib/uri-generator.d.ts +8 -0
- package/lib/uri-generator.js +176 -0
- package/lib/uri-generator.js.map +1 -0
- package/lib/writable.d.ts +22 -0
- package/lib/writable.js +3 -0
- package/lib/writable.js.map +1 -0
- package/package.json +54 -0
- package/src/admin.ts +119 -0
- package/src/all-fle-types.ts +17 -0
- package/src/all-transport-types.ts +80 -0
- package/src/cli-options.ts +49 -0
- package/src/closable.ts +14 -0
- package/src/connect-info.spec.ts +192 -0
- package/src/connect-info.ts +57 -0
- package/src/index.ts +62 -0
- package/src/platform.ts +6 -0
- package/src/printable-bson.spec.ts +75 -0
- package/src/printable-bson.ts +103 -0
- package/src/readable.ts +242 -0
- package/src/service-provider.ts +23 -0
- package/src/shell-auth-options.ts +7 -0
- package/src/textencoder-polyfill.spec.ts +11 -0
- package/src/textencoder-polyfill.ts +30 -0
- package/src/uri-generator.spec.ts +481 -0
- package/src/uri-generator.ts +265 -0
- package/src/writable.ts +367 -0
- package/tsconfig.json +12 -0
- package/tsconfig.lint.json +8 -0
package/src/readable.ts
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Document,
|
|
3
|
+
AggregateOptions,
|
|
4
|
+
CountOptions,
|
|
5
|
+
CountDocumentsOptions,
|
|
6
|
+
DistinctOptions,
|
|
7
|
+
EstimatedDocumentCountOptions,
|
|
8
|
+
FindOptions,
|
|
9
|
+
ListCollectionsOptions,
|
|
10
|
+
CollStatsOptions,
|
|
11
|
+
ListIndexesOptions,
|
|
12
|
+
AggregationCursor,
|
|
13
|
+
FindCursor,
|
|
14
|
+
DbOptions,
|
|
15
|
+
ReadPreferenceFromOptions,
|
|
16
|
+
ReadPreferenceLike
|
|
17
|
+
} from './all-transport-types';
|
|
18
|
+
import { ChangeStream, ChangeStreamOptions } from './all-transport-types';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Interface for read operations in the CRUD specification.
|
|
22
|
+
*/
|
|
23
|
+
export default interface Readable {
|
|
24
|
+
/**
|
|
25
|
+
* Run an aggregation pipeline.
|
|
26
|
+
*
|
|
27
|
+
*
|
|
28
|
+
* @param {String} database - The database name.
|
|
29
|
+
* @param {String} collection - The collection name.
|
|
30
|
+
* @param {Array} pipeline - The aggregation pipeline.
|
|
31
|
+
* @param {Document} options - The pipeline options.
|
|
32
|
+
* @param {DbOptions} dbOptions - The database options
|
|
33
|
+
* @returns {Cursor} A cursor.
|
|
34
|
+
*/
|
|
35
|
+
aggregate(
|
|
36
|
+
database: string,
|
|
37
|
+
collection: string,
|
|
38
|
+
pipeline: Document[],
|
|
39
|
+
options?: AggregateOptions,
|
|
40
|
+
dbOptions?: DbOptions): AggregationCursor;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Run an aggregation pipeline on the DB.
|
|
44
|
+
*
|
|
45
|
+
* @param {String} database - The database name.
|
|
46
|
+
* @param {Array} pipeline - The aggregation pipeline.
|
|
47
|
+
* @param {Document} options - The pipeline options.
|
|
48
|
+
* @param {Object} dbOptions - Optional options.
|
|
49
|
+
*
|
|
50
|
+
* @returns {Cursor} A cursor.
|
|
51
|
+
*/
|
|
52
|
+
aggregateDb(
|
|
53
|
+
database: string,
|
|
54
|
+
pipeline: Document[],
|
|
55
|
+
options?: AggregateOptions,
|
|
56
|
+
dbOptions?: DbOptions
|
|
57
|
+
): AggregationCursor;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Returns the count of documents that would match a find() query for the
|
|
61
|
+
* collection or view. The db.collection.count() method does not perform the
|
|
62
|
+
* find() operation but instead counts and returns the number of results
|
|
63
|
+
* that match a query.
|
|
64
|
+
*
|
|
65
|
+
* @param {String} db - the db name
|
|
66
|
+
* @param {String} coll - the collection name
|
|
67
|
+
* @param query
|
|
68
|
+
* @param options
|
|
69
|
+
* @param {DbOptions} dbOptions - The database options
|
|
70
|
+
*
|
|
71
|
+
* @returns {Promise} A promise of the result.
|
|
72
|
+
*/
|
|
73
|
+
count(
|
|
74
|
+
db: string,
|
|
75
|
+
coll: string,
|
|
76
|
+
query?: Document,
|
|
77
|
+
options?: CountOptions,
|
|
78
|
+
dbOptions?: DbOptions): Promise<number>;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get an exact document count from the collection.
|
|
82
|
+
*
|
|
83
|
+
* @param {String} database - The database name.
|
|
84
|
+
* @param {String} collection - The collection name.
|
|
85
|
+
* @param {Document} filter - The filter.
|
|
86
|
+
* @param {Document} options - The count options.
|
|
87
|
+
* @param {DbOptions} dbOptions - The database options
|
|
88
|
+
*
|
|
89
|
+
* @returns {Promise} A promise of the result.
|
|
90
|
+
*/
|
|
91
|
+
countDocuments(
|
|
92
|
+
database: string,
|
|
93
|
+
collection: string,
|
|
94
|
+
filter?: Document,
|
|
95
|
+
options?: CountDocumentsOptions,
|
|
96
|
+
dbOptions?: DbOptions): Promise<number>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Get distinct values for the field.
|
|
100
|
+
*
|
|
101
|
+
* @param {String} database - The database name.
|
|
102
|
+
* @param {String} collection - The collection name.
|
|
103
|
+
* @param {String} fieldName - The field name.
|
|
104
|
+
* @param {Document} filter - The filter.
|
|
105
|
+
* @param {Document} options - The distinct options.
|
|
106
|
+
* @param {DbOptions} dbOptions - The database options
|
|
107
|
+
*
|
|
108
|
+
* @returns {Document}.
|
|
109
|
+
*/
|
|
110
|
+
distinct(
|
|
111
|
+
database: string,
|
|
112
|
+
collection: string,
|
|
113
|
+
fieldName: string,
|
|
114
|
+
filter?: Document,
|
|
115
|
+
options?: DistinctOptions,
|
|
116
|
+
dbOptions?: DbOptions): Promise<Document>;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Get an estimated document count from the collection.
|
|
120
|
+
*
|
|
121
|
+
* @param {String} database - The database name.
|
|
122
|
+
* @param {String} collection - The collection name.
|
|
123
|
+
* @param {Document} options - The count options.
|
|
124
|
+
* @param {DbOptions} dbOptions - The database options
|
|
125
|
+
*
|
|
126
|
+
* @returns {Promise} The promise of the result.
|
|
127
|
+
*/
|
|
128
|
+
estimatedDocumentCount(
|
|
129
|
+
database: string,
|
|
130
|
+
collection: string,
|
|
131
|
+
options?: EstimatedDocumentCountOptions,
|
|
132
|
+
dbOptions?: DbOptions): Promise<number>;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Find documents in the collection.
|
|
136
|
+
*
|
|
137
|
+
* @param {String} database - The database name.
|
|
138
|
+
* @param {String} collection - The collection name.
|
|
139
|
+
* @param {Document} filter - The filter.
|
|
140
|
+
* @param {Document} options - The find options.
|
|
141
|
+
* @param {DbOptions} dbOptions - The database options
|
|
142
|
+
*
|
|
143
|
+
* @returns {Promise} The promise of the cursor.
|
|
144
|
+
*/
|
|
145
|
+
find(
|
|
146
|
+
database: string,
|
|
147
|
+
collection: string,
|
|
148
|
+
filter?: Document,
|
|
149
|
+
options?: FindOptions,
|
|
150
|
+
dbOptions?: DbOptions): FindCursor;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Get currently known topology information.
|
|
154
|
+
*/
|
|
155
|
+
getTopology(): any;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Is the collection capped?
|
|
159
|
+
*
|
|
160
|
+
* @param {String} database - The database name.
|
|
161
|
+
* @param {String} collection - The collection name.
|
|
162
|
+
* @param {DbOptions} dbOptions - The database options
|
|
163
|
+
*
|
|
164
|
+
* @returns {Promise} The promise of the result.
|
|
165
|
+
*/
|
|
166
|
+
isCapped(
|
|
167
|
+
database: string,
|
|
168
|
+
collection: string,
|
|
169
|
+
dbOptions?: DbOptions): Promise<boolean>;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Returns an array that holds a list of documents that identify and
|
|
173
|
+
* describe the existing indexes on the collection.
|
|
174
|
+
*
|
|
175
|
+
* @param {String} database - The db name.
|
|
176
|
+
* @param {String} collection - The collection name.
|
|
177
|
+
* @param options
|
|
178
|
+
* @param {DbOptions} dbOptions - The database options
|
|
179
|
+
*
|
|
180
|
+
* @return {Promise}
|
|
181
|
+
*/
|
|
182
|
+
getIndexes(
|
|
183
|
+
database: string,
|
|
184
|
+
collection: string,
|
|
185
|
+
options: ListIndexesOptions,
|
|
186
|
+
dbOptions?: DbOptions): Promise<Document[]>;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Returns an array of collection infos
|
|
190
|
+
*
|
|
191
|
+
* @param {String} database - The db name.
|
|
192
|
+
* @param {Document} filter - The filter.
|
|
193
|
+
* @param {Document} options - The command options.
|
|
194
|
+
* @param {DbOptions} dbOptions - The database options
|
|
195
|
+
*
|
|
196
|
+
* @return {Promise}
|
|
197
|
+
*/
|
|
198
|
+
listCollections(
|
|
199
|
+
database: string,
|
|
200
|
+
filter?: Document,
|
|
201
|
+
options?: ListCollectionsOptions,
|
|
202
|
+
dbOptions?: DbOptions): Promise<Document[]>;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Create a ReadPreference object from a set of options
|
|
206
|
+
*/
|
|
207
|
+
readPreferenceFromOptions(options?: Omit<ReadPreferenceFromOptions, 'session'>): ReadPreferenceLike | undefined;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Get all the collection statistics.
|
|
211
|
+
*
|
|
212
|
+
* @param {String} database - The db name.
|
|
213
|
+
* @param {String} collection - The collection name.
|
|
214
|
+
* @param {Object} options - The count options.
|
|
215
|
+
* @param {DbOptions} dbOptions - The database options
|
|
216
|
+
*
|
|
217
|
+
* @return {Promise} returns Promise
|
|
218
|
+
*/
|
|
219
|
+
stats(
|
|
220
|
+
database: string,
|
|
221
|
+
collection: string,
|
|
222
|
+
options?: CollStatsOptions,
|
|
223
|
+
dbOptions?: DbOptions
|
|
224
|
+
): Promise<Document>;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Start a change stream cursor on either the client, db, or collection.
|
|
228
|
+
* @param pipeline
|
|
229
|
+
* @param options
|
|
230
|
+
* @param db
|
|
231
|
+
* @param dbOptions
|
|
232
|
+
* @param coll
|
|
233
|
+
*/
|
|
234
|
+
watch(
|
|
235
|
+
pipeline: Document[],
|
|
236
|
+
options: ChangeStreamOptions,
|
|
237
|
+
dbOptions?: DbOptions,
|
|
238
|
+
db?: string,
|
|
239
|
+
coll?: string
|
|
240
|
+
): ChangeStream<Document>;
|
|
241
|
+
}
|
|
242
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MongoshInternalError } from '@qp-mongosh/errors';
|
|
2
|
+
import Admin from './admin';
|
|
3
|
+
import Closable from './closable';
|
|
4
|
+
import makePrintableBson from './printable-bson';
|
|
5
|
+
import Readable from './readable';
|
|
6
|
+
import Writable from './writable';
|
|
7
|
+
import type { bson as BSON } from './index';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Interface for all service providers.
|
|
11
|
+
*/
|
|
12
|
+
export default interface ServiceProvider extends Readable, Writable, Closable, Admin {}
|
|
13
|
+
|
|
14
|
+
export class ServiceProviderCore {
|
|
15
|
+
public bsonLibrary: typeof BSON;
|
|
16
|
+
constructor(bsonLibrary?: typeof BSON) {
|
|
17
|
+
if (bsonLibrary === undefined) {
|
|
18
|
+
throw new MongoshInternalError('BSON Library is undefined.');
|
|
19
|
+
}
|
|
20
|
+
makePrintableBson(bsonLibrary);
|
|
21
|
+
this.bsonLibrary = bsonLibrary;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { textEncodingPolyfill } from './textencoder-polyfill';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
|
|
4
|
+
describe('TextDecoder/TextEncoder polyfill', () => {
|
|
5
|
+
it('does simplistic UTF-8 encoding/decoding', () => {
|
|
6
|
+
const { TextEncoder, TextDecoder } = textEncodingPolyfill();
|
|
7
|
+
// This test was written in winter.
|
|
8
|
+
const str = '☃️';
|
|
9
|
+
expect(new TextDecoder().decode(new TextEncoder().encode(str))).to.equal(str);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// The java-shell doesn't have URL, so we fall back to a pure-JS implementation.
|
|
2
|
+
// And, because it's so much fun, it also doesn't have TextEncoder/TextDecoder,
|
|
3
|
+
// so we need to (crudely) polyfill that as well in order to use that
|
|
4
|
+
// pure-JS implementation.
|
|
5
|
+
if (
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
typeof TextDecoder !== 'function' || typeof TextEncoder !== 'function'
|
|
9
|
+
) {
|
|
10
|
+
// eslint-disable-next-line no-new-func
|
|
11
|
+
Object.assign(Function('return this')(), textEncodingPolyfill());
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Basic encoder/decoder polyfill for java-shell environment (see above)
|
|
15
|
+
function textEncodingPolyfill(): any {
|
|
16
|
+
class TextEncoder {
|
|
17
|
+
encode(string: string): Uint8Array {
|
|
18
|
+
return Buffer.from(string, 'utf8');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class TextDecoder {
|
|
22
|
+
decode(bytes: Uint8Array): string {
|
|
23
|
+
const str = Buffer.from(bytes).toString('utf8');
|
|
24
|
+
return str.slice(+str.startsWith('\ufeff'));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return { TextDecoder, TextEncoder };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { textEncodingPolyfill };
|