effect-mongodb 0.0.3 → 0.0.5
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/README.md +6 -1
- package/dist/cjs/Collection.js +22 -3
- package/dist/cjs/Collection.js.map +1 -1
- package/dist/cjs/Db.js +5 -19
- package/dist/cjs/Db.js.map +1 -1
- package/dist/cjs/DocumentCollection.js +18 -3
- package/dist/cjs/DocumentCollection.js.map +1 -1
- package/dist/cjs/DocumentFindCursor.js.map +1 -1
- package/dist/cjs/FindCursor.js +1 -5
- package/dist/cjs/FindCursor.js.map +1 -1
- package/dist/cjs/MongoClient.js +5 -4
- package/dist/cjs/MongoClient.js.map +1 -1
- package/dist/cjs/internal/modify-result.js +6 -0
- package/dist/cjs/internal/modify-result.js.map +1 -0
- package/dist/cjs/internal/schema.js +19 -0
- package/dist/cjs/internal/schema.js.map +1 -0
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Collection.d.ts +42 -3
- package/dist/dts/Collection.d.ts.map +1 -1
- package/dist/dts/Db.d.ts +0 -11
- package/dist/dts/Db.d.ts.map +1 -1
- package/dist/dts/DocumentCollection.d.ts +42 -3
- package/dist/dts/DocumentCollection.d.ts.map +1 -1
- package/dist/dts/DocumentFindCursor.d.ts +3 -3
- package/dist/dts/DocumentFindCursor.d.ts.map +1 -1
- package/dist/dts/FindCursor.d.ts +5 -4
- package/dist/dts/FindCursor.d.ts.map +1 -1
- package/dist/dts/MongoClient.d.ts +1 -8
- package/dist/dts/MongoClient.d.ts.map +1 -1
- package/dist/dts/internal/modify-result.d.ts +6 -0
- package/dist/dts/internal/modify-result.d.ts.map +1 -0
- package/dist/dts/internal/schema.d.ts +6 -0
- package/dist/dts/internal/schema.d.ts.map +1 -0
- package/dist/esm/Collection.js +21 -2
- package/dist/esm/Collection.js.map +1 -1
- package/dist/esm/Db.js +3 -15
- package/dist/esm/Db.js.map +1 -1
- package/dist/esm/DocumentCollection.js +17 -2
- package/dist/esm/DocumentCollection.js.map +1 -1
- package/dist/esm/DocumentFindCursor.js.map +1 -1
- package/dist/esm/FindCursor.js +1 -5
- package/dist/esm/FindCursor.js.map +1 -1
- package/dist/esm/MongoClient.js +3 -2
- package/dist/esm/MongoClient.js.map +1 -1
- package/dist/esm/internal/modify-result.js +2 -0
- package/dist/esm/internal/modify-result.js.map +1 -0
- package/dist/esm/internal/schema.js +10 -0
- package/dist/esm/internal/schema.js.map +1 -0
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Collection.ts +203 -31
- package/src/Db.ts +0 -36
- package/src/DocumentCollection.ts +195 -30
- package/src/DocumentFindCursor.ts +9 -23
- package/src/FindCursor.ts +15 -22
- package/src/MongoClient.ts +5 -12
- package/src/internal/modify-result.ts +6 -0
- package/src/internal/schema.ts +12 -0
- package/src/internal/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentFindCursor.js","names":["Data","Effect","F","Stream","FindCursor","MongoError","DocumentFindCursor","TaggedClass","filter","dual","args","isDocumentFindCursor","cursor","project","value","sort","direction","limit","toArray","pipe","tryPromise","try","catch","identity","catchAll","mongoErrorDie","toStream","fromAsyncIterable","mongoErrorStream","typed","schema","x"],"sources":["../../src/DocumentFindCursor.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,CAAC,MAAM,iBAAiB;AAEpC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,OAAO,KAAKC,UAAU,MAAM,iBAAiB;AAC7C,OAAO,KAAKC,UAAU,MAAM,iBAAiB;AAE7C,OAAM,MAAOC,kBAAmB,sBAAQN,IAAI,CAACO,WAAW,CAAC,oBAAoB,CAE3E;AAGF,OAAO,MAAMC,MAAM,
|
|
1
|
+
{"version":3,"file":"DocumentFindCursor.js","names":["Data","Effect","F","Stream","FindCursor","MongoError","DocumentFindCursor","TaggedClass","filter","dual","args","isDocumentFindCursor","cursor","project","value","sort","direction","limit","toArray","pipe","tryPromise","try","catch","identity","catchAll","mongoErrorDie","toStream","fromAsyncIterable","mongoErrorStream","typed","schema","x"],"sources":["../../src/DocumentFindCursor.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,CAAC,MAAM,iBAAiB;AAEpC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,OAAO,KAAKC,UAAU,MAAM,iBAAiB;AAC7C,OAAO,KAAKC,UAAU,MAAM,iBAAiB;AAE7C,OAAM,MAAOC,kBAAmB,sBAAQN,IAAI,CAACO,WAAW,CAAC,oBAAoB,CAE3E;AAGF,OAAO,MAAMC,MAAM,gBAGfN,CAAC,CAACO,IAAI,CACPC,IAAI,IAAKC,oBAAoB,CAACD,IAAI,CAAC,CAAC,CAAC,CAAC,EACvC,CAACE,MAA0B,EAAEJ,MAAwB,KACnD,IAAIF,kBAAkB,CAAC;EAAEM,MAAM,EAAEA,MAAM,CAACA,MAAM,CAACJ,MAAM,CAACA,MAAM;AAAC,CAAE,CAAC,CACnE;AAED,OAAO,MAAMK,OAAO,gBAGhBX,CAAC,CAACO,IAAI,CACPC,IAAI,IAAKC,oBAAoB,CAACD,IAAI,CAAC,CAAC,CAAC,CAAC,EACvC,CAACE,MAA0B,EAAEE,KAAe,KAC1C,IAAIR,kBAAkB,CAAC;EAAEM,MAAM,EAAEA,MAAM,CAACA,MAAM,CAACC,OAAO,CAACC,KAAK;AAAC,CAAE,CAAC,CACnE;AAED,OAAO,MAAMC,IAAI,gBAGbb,CAAC,CAACO,IAAI,CACPC,IAAI,IAAKC,oBAAoB,CAACD,IAAI,CAAC,CAAC,CAAC,CAAC,EACvC,CAACE,MAA0B,EAAEG,IAAmB,EAAEC,SAAyB,KACzE,IAAIV,kBAAkB,CAAC;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C,YAAYzB,kBAAkB","ignoreList":[]}
|
package/dist/esm/FindCursor.js
CHANGED
|
@@ -25,7 +25,6 @@ export const limit = /*#__PURE__*/F.dual(args => isFindCursor(args[0]), (cursor,
|
|
|
25
25
|
cursor: cursor.cursor.limit(value),
|
|
26
26
|
schema: cursor.schema
|
|
27
27
|
}));
|
|
28
|
-
// TODO: add explicit return type for public API
|
|
29
28
|
export const toArray = cursor => {
|
|
30
29
|
const decode = Schema.decodeUnknown(cursor.schema);
|
|
31
30
|
return Effect.tryPromise({
|
|
@@ -33,15 +32,12 @@ export const toArray = cursor => {
|
|
|
33
32
|
catch: F.identity
|
|
34
33
|
}).pipe(Effect.catchAll(MongoError.mongoErrorDie("Unable to get array from mongodb cursor")), Effect.flatMap(Effect.forEach(x => decode(x))));
|
|
35
34
|
};
|
|
36
|
-
// TODO: add explicit return type for public API
|
|
37
35
|
export const toArrayEither = cursor => {
|
|
38
36
|
const decode = Schema.decodeUnknown(cursor.schema);
|
|
39
37
|
return Effect.tryPromise({
|
|
40
38
|
try: () => cursor.cursor.toArray(),
|
|
41
39
|
catch: F.identity
|
|
42
|
-
}).pipe(Effect.catchAll(MongoError.mongoErrorDie("Unable to get array from mongodb cursor")), Effect.flatMap(Effect.forEach(x => F.pipe(
|
|
43
|
-
// keep new line
|
|
44
|
-
decode(x), Effect.mapError(error => Tuple.make(x, error)), Effect.either))));
|
|
40
|
+
}).pipe(Effect.catchAll(MongoError.mongoErrorDie("Unable to get array from mongodb cursor")), Effect.flatMap(Effect.forEach(x => F.pipe(decode(x), Effect.mapError(error => Tuple.make(x, error)), Effect.either))));
|
|
45
41
|
};
|
|
46
42
|
export const toStream = cursor => {
|
|
47
43
|
const decode = Schema.decodeUnknown(cursor.schema);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FindCursor.js","names":["Data","Effect","F","Schema","Stream","Tuple","MongoError","FindCursor","TaggedClass","filter","dual","args","isFindCursor","cursor","schema","project","newSchema","value","sort","direction","limit","toArray","decode","decodeUnknown","tryPromise","try","catch","identity","pipe","catchAll","mongoErrorDie","flatMap","forEach","x","toArrayEither","mapError","error","make","either","toStream","fromAsyncIterable","mongoErrorStream","mapEffect","toStreamEither"],"sources":["../../src/FindCursor.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,OAAO,KAAKC,CAAC,MAAM,iBAAiB;AAEpC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;
|
|
1
|
+
{"version":3,"file":"FindCursor.js","names":["Data","Effect","F","Schema","Stream","Tuple","MongoError","FindCursor","TaggedClass","filter","dual","args","isFindCursor","cursor","schema","project","newSchema","value","sort","direction","limit","toArray","decode","decodeUnknown","tryPromise","try","catch","identity","pipe","catchAll","mongoErrorDie","flatMap","forEach","x","toArrayEither","mapError","error","make","either","toStream","fromAsyncIterable","mongoErrorStream","mapEffect","toStreamEither"],"sources":["../../src/FindCursor.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,OAAO,KAAKC,CAAC,MAAM,iBAAiB;AAEpC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AAGrC,OAAO,KAAKC,UAAU,MAAM,iBAAiB;AAE7C,OAAM,MAAOC,UAAgC,sBAAQP,IAAI,CAACQ,WAAW,CAAC,YAAY,CAGhF;AAGF,OAAO,MAAMC,MAAM,gBAGfP,CAAC,CAACQ,IAAI,CACPC,IAAI,IAAKC,YAAY,CAACD,IAAI,CAAC,CAAC,CAAC,CAAC,EAC/B,CACEE,MAA2B,EAC3BJ,MAAiB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3B,MAAM,CAACA,MAAM,EAAEX,CAAC,CAACyB,QAAQ,CAAC,EACnDvB,MAAM,CAACyB,QAAQ,CAACvB,UAAU,CAACmC,gBAAgB,CAAI,0CAA0C,CAAC,CAAC,EAC3FrC,MAAM,CAACsC,SAAS,CAAET,CAAC,IAAKX,MAAM,CAACW,CAAC,CAAC,CAAC,CACnC;AACH,CAAC;AAED,OAAO,MAAMU,cAAc,GACzB9B,MAA2B,IACiF;EAC5G,MAAMS,MAAM,GAAGnB,MAAM,CAACoB,aAAa,CAACV,MAAM,CAACC,MAAM,CAAC;EAClD,OAAOZ,CAAC,CAAC0B,IAAI,CACXxB,MAAM,CAACoC,iBAAiB,CAAC3B,MAAM,CAACA,MAAM,EAAEX,CAAC,CAACyB,QAAQ,CAAC,EACnDvB,MAAM,CAACyB,QAAQ,CAACvB,UAAU,CAACmC,gBAAgB,CAAI,iDAAiD,CAAC,CAAC,EAClGrC,MAAM,CAACsC,SAAS,CAAET,CAAC,IACjB/B,CAAC,CAAC0B,IAAI;EACJ;EACAN,MAAM,CAACW,CAAC,CAAC,EACThC,MAAM,CAACkC,QAAQ,CAAEC,KAAK,IAAK/B,KAAK,CAACgC,IAAI,CAACJ,CAAC,EAAEG,KAAK,CAAC,CAAC,EAChDnC,MAAM,CAACqC,MAAM,CACd,CACF,CACF;AACH,CAAC;AAED,MAAM1B,YAAY,GAAIqB,CAAU,IAA+BA,CAAC,YAAY1B,UAAU","ignoreList":[]}
|
package/dist/esm/MongoClient.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.0.1
|
|
3
|
+
*/
|
|
1
4
|
import * as Effect from "effect/Effect";
|
|
2
5
|
import * as F from "effect/Function";
|
|
3
6
|
import { MongoClient as MongoClient_ } from "mongodb";
|
|
4
7
|
import * as MongoError from "./MongoError.js";
|
|
5
|
-
import * as Context from "effect/Context";
|
|
6
8
|
export const connect = (url, options) => Effect.promise(() => MongoClient_.connect(url, options)).pipe(Effect.catchAll(MongoError.mongoErrorDie("connect error")));
|
|
7
9
|
export const db = /*#__PURE__*/F.dual(args => isMongoClient(args[0]), (client, dbName, options) => client.db(dbName, options));
|
|
8
10
|
const isMongoClient = x => x instanceof MongoClient_;
|
|
9
|
-
export const Tag = key => Context.GenericTag(key);
|
|
10
11
|
//# sourceMappingURL=MongoClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoClient.js","names":["Effect","F","MongoClient","MongoClient_","MongoError","
|
|
1
|
+
{"version":3,"file":"MongoClient.js","names":["Effect","F","MongoClient","MongoClient_","MongoError","connect","url","options","promise","pipe","catchAll","mongoErrorDie","db","dual","args","isMongoClient","client","dbName","x"],"sources":["../../src/MongoClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,CAAC,MAAM,iBAAiB;AAEpC,SAASC,WAAW,IAAIC,YAAY,QAAQ,SAAS;AACrD,OAAO,KAAKC,UAAU,MAAM,iBAAiB;AAI7C,OAAO,MAAMC,OAAO,GAAGA,CACrBC,GAAW,EACXC,OAA4B,KAE5BP,MAAM,CAACQ,OAAO,CAAC,MAAML,YAAY,CAACE,OAAO,CAACC,GAAG,EAAEC,OAAO,CAAC,CAAC,CAACE,IAAI,CAC3DT,MAAM,CAACU,QAAQ,CAACN,UAAU,CAACO,aAAa,CAAe,eAAe,CAAC,CAAC,CACzE;AAEH,OAAO,MAAMC,EAAE,gBAGXX,CAAC,CAACY,IAAI,CACPC,IAAI,IAAKC,aAAa,CAACD,IAAI,CAAC,CAAC,CAAC,CAAC,EAChC,CAACE,MAAmB,EAAEC,MAAe,EAAEV,OAAmB,KAASS,MAAM,CAACJ,EAAE,CAACK,MAAM,EAAEV,OAAO,CAAC,CAC9F;AAED,MAAMQ,aAAa,GAAIG,CAAU,IAAKA,CAAC,YAAYf,YAAY","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modify-result.js","names":[],"sources":["../../../src/internal/modify-result.ts"],"sourcesContent":[null],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as O from "effect/Option";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
// TODO: there is probably a Schema to do this decode or using typeclass package for traverse
|
|
5
|
+
export const decodeNullableDocument = (schema, value) => Effect.gen(function* (_) {
|
|
6
|
+
if (value === null) return O.none();
|
|
7
|
+
const decoded = yield* _(Schema.decodeUnknown(schema)(value));
|
|
8
|
+
return O.some(decoded);
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","names":["Effect","O","Schema","decodeNullableDocument","schema","value","gen","_","none","decoded","decodeUnknown","some"],"sources":["../../../src/internal/schema.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,CAAC,MAAM,eAAe;AAClC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAGvC;AACA,OAAO,MAAMC,sBAAsB,GAAGA,CAAUC,MAA8B,EAAEC,KAAsB,KACpGL,MAAM,CAACM,GAAG,CAAC,WAAUC,CAAC;EACpB,IAAIF,KAAK,KAAK,IAAI,EAAE,OAAOJ,CAAC,CAACO,IAAI,EAAE;EACnC,MAAMC,OAAO,GAAG,OAAOF,CAAC,CAACL,MAAM,CAACQ,aAAa,CAACN,MAAM,CAAC,CAACC,KAAK,CAAC,CAAC;EAC7D,OAAOJ,CAAC,CAACU,IAAI,CAACF,OAAO,CAAC;AACxB,CAAC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
package/src/Collection.ts
CHANGED
|
@@ -11,15 +11,22 @@ import type {
|
|
|
11
11
|
AggregateOptions,
|
|
12
12
|
BulkWriteOptions,
|
|
13
13
|
Collection as MongoCollection,
|
|
14
|
+
CountDocumentsOptions,
|
|
14
15
|
CreateIndexesOptions,
|
|
15
16
|
DeleteOptions,
|
|
16
17
|
DeleteResult,
|
|
17
18
|
Document,
|
|
19
|
+
DropCollectionOptions,
|
|
20
|
+
DropIndexesOptions,
|
|
21
|
+
EstimatedDocumentCountOptions,
|
|
22
|
+
FindOneAndReplaceOptions,
|
|
18
23
|
FindOptions as MongoFindOptions,
|
|
19
24
|
IndexDescription,
|
|
25
|
+
IndexSpecification,
|
|
20
26
|
InsertManyResult,
|
|
21
27
|
InsertOneOptions,
|
|
22
28
|
InsertOneResult,
|
|
29
|
+
ModifyResult as MongoModifyResult,
|
|
23
30
|
RenameOptions,
|
|
24
31
|
ReplaceOptions,
|
|
25
32
|
UpdateFilter,
|
|
@@ -29,6 +36,8 @@ import type {
|
|
|
29
36
|
import * as AggregationCursor from "./AggregationCursor.js"
|
|
30
37
|
import * as FindCursor from "./FindCursor.js"
|
|
31
38
|
import type { Filter } from "./internal/filter.js"
|
|
39
|
+
import type { ModifyResult } from "./internal/modify-result.js"
|
|
40
|
+
import * as SchemaExt from "./internal/schema.js"
|
|
32
41
|
import * as MongoError from "./MongoError.js"
|
|
33
42
|
|
|
34
43
|
export class Collection<A extends Document, I extends Document = A, R = never> extends Data.TaggedClass("Collection")<{
|
|
@@ -40,30 +49,30 @@ export class Collection<A extends Document, I extends Document = A, R = never> e
|
|
|
40
49
|
export type FindOptions = Omit<MongoFindOptions, "projection">
|
|
41
50
|
|
|
42
51
|
export const find: {
|
|
43
|
-
(
|
|
52
|
+
<I extends Document>(
|
|
53
|
+
filter?: Filter<I>,
|
|
44
54
|
options?: FindOptions
|
|
45
|
-
): <A extends Document,
|
|
55
|
+
): <A extends Document, R>(collection: Collection<A, I, R>) => FindCursor.FindCursor<A, I, R>
|
|
46
56
|
<A extends Document, I extends Document, R>(
|
|
47
57
|
collection: Collection<A, I, R>,
|
|
58
|
+
filter?: Filter<I>,
|
|
48
59
|
options?: FindOptions
|
|
49
60
|
): FindCursor.FindCursor<A, I, R>
|
|
50
61
|
} = F.dual(
|
|
51
62
|
(args) => isCollection(args[0]),
|
|
52
63
|
<A extends Document, I extends Document, R>(
|
|
53
64
|
collection: Collection<A, I, R>,
|
|
65
|
+
filter?: Filter<I>,
|
|
54
66
|
options?: FindOptions
|
|
55
67
|
): FindCursor.FindCursor<A, I, R> =>
|
|
56
68
|
new FindCursor.FindCursor<A, I, R>({
|
|
57
|
-
cursor: collection.collection.find({}, options),
|
|
69
|
+
cursor: collection.collection.find(filter ?? {}, options),
|
|
58
70
|
schema: collection.schema
|
|
59
71
|
})
|
|
60
72
|
)
|
|
61
73
|
|
|
62
74
|
export const findOne: {
|
|
63
|
-
<I extends Document>(
|
|
64
|
-
filter: Filter<I>,
|
|
65
|
-
options?: FindOptions
|
|
66
|
-
): <A extends Document, R>(
|
|
75
|
+
<I extends Document>(filter: Filter<I>, options?: FindOptions): <A extends Document, R>(
|
|
67
76
|
collection: Collection<A, I, R>
|
|
68
77
|
) => Effect.Effect<O.Option<Document>, MongoError.MongoError | ParseResult.ParseError, R>
|
|
69
78
|
<A extends Document, I extends Document, R>(
|
|
@@ -88,10 +97,7 @@ export const findOne: {
|
|
|
88
97
|
)
|
|
89
98
|
|
|
90
99
|
export const insertOne: {
|
|
91
|
-
<A extends Document>(
|
|
92
|
-
doc: A,
|
|
93
|
-
options?: InsertOneOptions
|
|
94
|
-
): <I extends Document, R>(
|
|
100
|
+
<A extends Document>(doc: A, options?: InsertOneOptions): <I extends Document, R>(
|
|
95
101
|
collection: Collection<A, I, R>
|
|
96
102
|
) => Effect.Effect<InsertOneResult, MongoError.MongoError | ParseResult.ParseError, R>
|
|
97
103
|
<A extends Document, I extends Document, R>(
|
|
@@ -111,10 +117,7 @@ export const insertOne: {
|
|
|
111
117
|
))
|
|
112
118
|
|
|
113
119
|
export const insertMany: {
|
|
114
|
-
<A extends Document>(
|
|
115
|
-
docs: Array<A>,
|
|
116
|
-
options?: BulkWriteOptions
|
|
117
|
-
): <I extends Document, R>(
|
|
120
|
+
<A extends Document>(docs: Array<A>, options?: BulkWriteOptions): <I extends Document, R>(
|
|
118
121
|
collection: Collection<A, I, R>
|
|
119
122
|
) => Effect.Effect<InsertManyResult, MongoError.MongoError | ParseResult.ParseError, R>
|
|
120
123
|
<A extends Document, I extends Document, R>(
|
|
@@ -137,10 +140,7 @@ export const insertMany: {
|
|
|
137
140
|
})
|
|
138
141
|
|
|
139
142
|
export const deleteOne: {
|
|
140
|
-
<I extends Document>(
|
|
141
|
-
filter: Filter<I>,
|
|
142
|
-
options?: DeleteOptions
|
|
143
|
-
): <A extends Document, R>(
|
|
143
|
+
<I extends Document>(filter: Filter<I>, options?: DeleteOptions): <A extends Document, R>(
|
|
144
144
|
collection: Collection<A, I, R>
|
|
145
145
|
) => Effect.Effect<DeleteResult, MongoError.MongoError, R>
|
|
146
146
|
<A extends Document, I extends Document, R>(
|
|
@@ -161,10 +161,7 @@ export const deleteOne: {
|
|
|
161
161
|
)
|
|
162
162
|
|
|
163
163
|
export const deleteMany: {
|
|
164
|
-
<I extends Document>(
|
|
165
|
-
filter: Filter<I>,
|
|
166
|
-
options?: DeleteOptions
|
|
167
|
-
): <A extends Document, R>(
|
|
164
|
+
<I extends Document>(filter: Filter<I>, options?: DeleteOptions): <A extends Document, R>(
|
|
168
165
|
collection: Collection<A, I, R>
|
|
169
166
|
) => Effect.Effect<DeleteResult, MongoError.MongoError, R>
|
|
170
167
|
<A extends Document, I extends Document, R>(
|
|
@@ -250,11 +247,82 @@ export const replaceOne: {
|
|
|
250
247
|
)
|
|
251
248
|
)
|
|
252
249
|
|
|
250
|
+
export const findOneAndReplace: {
|
|
251
|
+
<A extends Document, I extends Document>(
|
|
252
|
+
filter: Filter<I>,
|
|
253
|
+
replacement: A,
|
|
254
|
+
options: FindOneAndReplaceOptions & { includeResultMetadata: true }
|
|
255
|
+
): <R>(
|
|
256
|
+
collection: Collection<A, I, R>
|
|
257
|
+
) => Effect.Effect<ModifyResult<A>, MongoError.MongoError | ParseResult.ParseError, R>
|
|
258
|
+
<A extends Document, I extends Document>(
|
|
259
|
+
filter: Filter<I>,
|
|
260
|
+
replacement: A,
|
|
261
|
+
options: FindOneAndReplaceOptions & { includeResultMetadata: false }
|
|
262
|
+
): <R>(
|
|
263
|
+
collection: Collection<A, I, R>
|
|
264
|
+
) => Effect.Effect<O.Option<A>, MongoError.MongoError | ParseResult.ParseError, R>
|
|
265
|
+
<A extends Document, I extends Document>(filter: Filter<I>, replacement: A, options: FindOneAndReplaceOptions): <R>(
|
|
266
|
+
collection: Collection<A, I, R>
|
|
267
|
+
) => Effect.Effect<O.Option<A>, MongoError.MongoError | ParseResult.ParseError, R>
|
|
268
|
+
<A extends Document, I extends Document>(filter: Filter<I>, replacement: A): <R>(
|
|
269
|
+
collection: Collection<A, I, R>
|
|
270
|
+
) => Effect.Effect<O.Option<A>, MongoError.MongoError | ParseResult.ParseError, R>
|
|
271
|
+
<A extends Document, I extends Document, R>(
|
|
272
|
+
collection: Collection<A, I, R>,
|
|
273
|
+
filter: Filter<I>,
|
|
274
|
+
replacement: A,
|
|
275
|
+
options: FindOneAndReplaceOptions & { includeResultMetadata: true }
|
|
276
|
+
): Effect.Effect<ModifyResult<A>, MongoError.MongoError | ParseResult.ParseError, R>
|
|
277
|
+
<A extends Document, I extends Document, R>(
|
|
278
|
+
collection: Collection<A, I, R>,
|
|
279
|
+
filter: Filter<I>,
|
|
280
|
+
replacement: A,
|
|
281
|
+
options: FindOneAndReplaceOptions & { includeResultMetadata: false }
|
|
282
|
+
): Effect.Effect<O.Option<A>, MongoError.MongoError | ParseResult.ParseError, R>
|
|
283
|
+
<A extends Document, I extends Document, R>(
|
|
284
|
+
collection: Collection<A, I, R>,
|
|
285
|
+
filter: Filter<I>,
|
|
286
|
+
replacement: A,
|
|
287
|
+
options: FindOneAndReplaceOptions
|
|
288
|
+
): Effect.Effect<O.Option<A>, MongoError.MongoError | ParseResult.ParseError, R>
|
|
289
|
+
<A extends Document, I extends Document, R>(
|
|
290
|
+
collection: Collection<A, I, R>,
|
|
291
|
+
filter: Filter<I>,
|
|
292
|
+
replacement: A
|
|
293
|
+
): Effect.Effect<O.Option<A>, MongoError.MongoError | ParseResult.ParseError, R>
|
|
294
|
+
} = F.dual(
|
|
295
|
+
(args) => isCollection(args[0]),
|
|
296
|
+
<A extends Document, I extends Document, R>(
|
|
297
|
+
collection: Collection<A, I, R>,
|
|
298
|
+
filter: Filter<I>,
|
|
299
|
+
replacement: A,
|
|
300
|
+
options?: FindOneAndReplaceOptions
|
|
301
|
+
): Effect.Effect<O.Option<A> | ModifyResult<A>, MongoError.MongoError | ParseResult.ParseError, R> =>
|
|
302
|
+
F.pipe(
|
|
303
|
+
// TODO: extract function in Collection
|
|
304
|
+
Schema.encode(collection.schema)(replacement),
|
|
305
|
+
Effect.flatMap((replacement) =>
|
|
306
|
+
Effect.promise(() => collection.collection.findOneAndReplace(filter, replacement, options ?? {}))
|
|
307
|
+
),
|
|
308
|
+
Effect.flatMap((value) =>
|
|
309
|
+
Effect.gen(function*(_) {
|
|
310
|
+
if (options?.includeResultMetadata && !!value) {
|
|
311
|
+
const result = value as unknown as MongoModifyResult<I>
|
|
312
|
+
const maybeValue = yield* _(SchemaExt.decodeNullableDocument(collection.schema, result.value))
|
|
313
|
+
return { ...result, value: maybeValue }
|
|
314
|
+
}
|
|
315
|
+
return yield* _(SchemaExt.decodeNullableDocument(collection.schema, value))
|
|
316
|
+
})
|
|
317
|
+
),
|
|
318
|
+
Effect.catchAllDefect(
|
|
319
|
+
MongoError.mongoErrorDie<O.Option<A> | ModifyResult<A>>("findOneAndReplace error")
|
|
320
|
+
)
|
|
321
|
+
)
|
|
322
|
+
)
|
|
323
|
+
|
|
253
324
|
export const rename: {
|
|
254
|
-
(
|
|
255
|
-
newName: string,
|
|
256
|
-
options?: RenameOptions
|
|
257
|
-
): <A extends Document, I extends Document, R>(
|
|
325
|
+
(newName: string, options?: RenameOptions): <A extends Document, I extends Document, R>(
|
|
258
326
|
collection: Collection<A, I, R>
|
|
259
327
|
) => Effect.Effect<Collection<A, I, R>, MongoError.MongoError, R>
|
|
260
328
|
<A extends Document, I extends Document, R>(
|
|
@@ -276,11 +344,28 @@ export const rename: {
|
|
|
276
344
|
)
|
|
277
345
|
)
|
|
278
346
|
|
|
347
|
+
export const drop: {
|
|
348
|
+
(options?: DropCollectionOptions): <A extends Document, I extends Document, R>(
|
|
349
|
+
collection: Collection<A, I, R>
|
|
350
|
+
) => Effect.Effect<boolean, MongoError.MongoError, R>
|
|
351
|
+
<A extends Document, I extends Document, R>(
|
|
352
|
+
collection: Collection<A, I, R>,
|
|
353
|
+
options?: DropCollectionOptions
|
|
354
|
+
): Effect.Effect<boolean, MongoError.MongoError, R>
|
|
355
|
+
} = F.dual(
|
|
356
|
+
(args) => isCollection(args[0]),
|
|
357
|
+
<A extends Document, I extends Document, R>(
|
|
358
|
+
collection: Collection<A, I, R>,
|
|
359
|
+
options?: DropCollectionOptions
|
|
360
|
+
): Effect.Effect<boolean, MongoError.MongoError, R> =>
|
|
361
|
+
F.pipe(
|
|
362
|
+
Effect.promise(() => collection.collection.drop(options)),
|
|
363
|
+
Effect.catchAllDefect(MongoError.mongoErrorDie<boolean>("drop error"))
|
|
364
|
+
)
|
|
365
|
+
)
|
|
366
|
+
|
|
279
367
|
export const createIndexes: {
|
|
280
|
-
(
|
|
281
|
-
indexSpecs: Array<IndexDescription>,
|
|
282
|
-
options?: CreateIndexesOptions
|
|
283
|
-
): <A extends Document, I extends Document, R>(
|
|
368
|
+
(indexSpecs: Array<IndexDescription>, options?: CreateIndexesOptions): <A extends Document, I extends Document, R>(
|
|
284
369
|
collection: Collection<A, I, R>
|
|
285
370
|
) => Effect.Effect<Array<string>, MongoError.MongoError, R>
|
|
286
371
|
<A extends Document, I extends Document, R>(
|
|
@@ -301,6 +386,51 @@ export const createIndexes: {
|
|
|
301
386
|
)
|
|
302
387
|
)
|
|
303
388
|
|
|
389
|
+
export const createIndex: {
|
|
390
|
+
(indexSpec: IndexSpecification, options?: CreateIndexesOptions): <A extends Document, I extends Document, R>(
|
|
391
|
+
collection: Collection<A, I, R>
|
|
392
|
+
) => Effect.Effect<string, MongoError.MongoError, R>
|
|
393
|
+
<A extends Document, I extends Document, R>(
|
|
394
|
+
collection: Collection<A, I, R>,
|
|
395
|
+
indexSpec: IndexSpecification,
|
|
396
|
+
options?: CreateIndexesOptions
|
|
397
|
+
): Effect.Effect<string, MongoError.MongoError, R>
|
|
398
|
+
} = F.dual(
|
|
399
|
+
(args) => isCollection(args[0]),
|
|
400
|
+
<A extends Document, I extends Document, R>(
|
|
401
|
+
collection: Collection<A, I, R>,
|
|
402
|
+
indexSpec: IndexSpecification,
|
|
403
|
+
options?: CreateIndexesOptions
|
|
404
|
+
): Effect.Effect<string, MongoError.MongoError, R> =>
|
|
405
|
+
F.pipe(
|
|
406
|
+
Effect.promise(() => collection.collection.createIndex(indexSpec, options)),
|
|
407
|
+
Effect.catchAllDefect(MongoError.mongoErrorDie<string>("createIndex error"))
|
|
408
|
+
)
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
export const dropIndex: {
|
|
412
|
+
(indexName: string, options?: DropIndexesOptions): <A extends Document, I extends Document, R>(
|
|
413
|
+
collection: Collection<A, I, R>
|
|
414
|
+
) => Effect.Effect<void, MongoError.MongoError, R>
|
|
415
|
+
<A extends Document, I extends Document, R>(
|
|
416
|
+
collection: Collection<A, I, R>,
|
|
417
|
+
indexName: string,
|
|
418
|
+
options?: DropIndexesOptions
|
|
419
|
+
): Effect.Effect<void, MongoError.MongoError, R>
|
|
420
|
+
} = F.dual(
|
|
421
|
+
(args) => isCollection(args[0]),
|
|
422
|
+
<A extends Document, I extends Document, R>(
|
|
423
|
+
collection: Collection<A, I, R>,
|
|
424
|
+
indexName: string,
|
|
425
|
+
options?: DropIndexesOptions
|
|
426
|
+
): Effect.Effect<void, MongoError.MongoError, R> =>
|
|
427
|
+
F.pipe(
|
|
428
|
+
Effect.promise(() => collection.collection.dropIndex(indexName, options)),
|
|
429
|
+
Effect.asVoid,
|
|
430
|
+
Effect.catchAllDefect(MongoError.mongoErrorDie<void>("dropIndex error"))
|
|
431
|
+
)
|
|
432
|
+
)
|
|
433
|
+
|
|
304
434
|
export const aggregate: {
|
|
305
435
|
<B extends Document, BI extends Document, BR>(
|
|
306
436
|
pipeline: Array<Document>,
|
|
@@ -329,4 +459,46 @@ export const aggregate: {
|
|
|
329
459
|
})
|
|
330
460
|
)
|
|
331
461
|
|
|
462
|
+
export const estimatedDocumentCount: {
|
|
463
|
+
(options?: EstimatedDocumentCountOptions): <A extends Document, I extends Document, R>(
|
|
464
|
+
collection: Collection<A, I, R>
|
|
465
|
+
) => Effect.Effect<number, MongoError.MongoError, R>
|
|
466
|
+
<A extends Document, I extends Document, R>(
|
|
467
|
+
collection: Collection<A, I, R>,
|
|
468
|
+
options?: EstimatedDocumentCountOptions
|
|
469
|
+
): Effect.Effect<number, MongoError.MongoError, R>
|
|
470
|
+
} = F.dual(
|
|
471
|
+
(args) => isCollection(args[0]),
|
|
472
|
+
<A extends Document, I extends Document, R>(
|
|
473
|
+
collection: Collection<A, I, R>,
|
|
474
|
+
options?: EstimatedDocumentCountOptions
|
|
475
|
+
): Effect.Effect<number, MongoError.MongoError, R> =>
|
|
476
|
+
F.pipe(
|
|
477
|
+
Effect.promise(() => collection.collection.estimatedDocumentCount(options)),
|
|
478
|
+
Effect.catchAllDefect(MongoError.mongoErrorDie<number>("estimatedDocumentCount error"))
|
|
479
|
+
)
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
export const countDocuments: {
|
|
483
|
+
<I extends Document>(filter?: Filter<I>, options?: CountDocumentsOptions): <A extends Document, R>(
|
|
484
|
+
collection: Collection<A, I, R>
|
|
485
|
+
) => Effect.Effect<number, MongoError.MongoError, R>
|
|
486
|
+
<A extends Document, I extends Document, R>(
|
|
487
|
+
collection: Collection<A, I, R>,
|
|
488
|
+
filter?: Filter<I>,
|
|
489
|
+
options?: CountDocumentsOptions
|
|
490
|
+
): Effect.Effect<number, MongoError.MongoError, R>
|
|
491
|
+
} = F.dual(
|
|
492
|
+
(args) => isCollection(args[0]),
|
|
493
|
+
<A extends Document, I extends Document, R>(
|
|
494
|
+
collection: Collection<A, I, R>,
|
|
495
|
+
filter?: Filter<I>,
|
|
496
|
+
options?: CountDocumentsOptions
|
|
497
|
+
): Effect.Effect<number, MongoError.MongoError, R> =>
|
|
498
|
+
F.pipe(
|
|
499
|
+
Effect.promise(() => collection.collection.countDocuments(filter, options)),
|
|
500
|
+
Effect.catchAllDefect(MongoError.mongoErrorDie<number>("countDocuments error"))
|
|
501
|
+
)
|
|
502
|
+
)
|
|
503
|
+
|
|
332
504
|
const isCollection = (x: unknown) => x instanceof Collection
|
package/src/Db.ts
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 0.0.1
|
|
3
3
|
*/
|
|
4
|
-
import type * as Brand from "effect/Brand"
|
|
5
|
-
import * as Context from "effect/Context"
|
|
6
4
|
import * as Effect from "effect/Effect"
|
|
7
5
|
import * as F from "effect/Function"
|
|
8
|
-
import * as Layer from "effect/Layer"
|
|
9
6
|
import type * as Schema from "effect/Schema"
|
|
10
7
|
import type { Document, DropCollectionOptions, ListCollectionsOptions } from "mongodb"
|
|
11
8
|
import { Db } from "mongodb"
|
|
12
9
|
import type * as Collection from "./Collection.js"
|
|
13
10
|
import * as DocumentCollection from "./DocumentCollection.js"
|
|
14
11
|
import * as ListCollectionsCursor from "./ListCollectionsCursor.js"
|
|
15
|
-
import * as MongoClient from "./MongoClient.js"
|
|
16
12
|
import * as MongoError from "./MongoError.js"
|
|
17
13
|
|
|
18
14
|
export const documentCollection: {
|
|
@@ -89,35 +85,3 @@ export const dropCollection: {
|
|
|
89
85
|
)
|
|
90
86
|
|
|
91
87
|
const isDb = (x: unknown) => x instanceof Db
|
|
92
|
-
|
|
93
|
-
export type DbService<K extends string> = {
|
|
94
|
-
db: Effect.Effect<Db, MongoError.MongoError>
|
|
95
|
-
} & Brand.Brand<K>
|
|
96
|
-
|
|
97
|
-
export const Tag = <K extends string>(key: K) => Context.GenericTag<DbService<K>>(key)
|
|
98
|
-
export type TagType<K extends string> = ReturnType<typeof Tag<K>>
|
|
99
|
-
|
|
100
|
-
export const fromEffect = <DbK extends string, MongoClientK extends string, E = never, R = never>(
|
|
101
|
-
dbTag: TagType<DbK>,
|
|
102
|
-
clientTag: MongoClient.TagType<MongoClientK>,
|
|
103
|
-
dbName: Effect.Effect<string, E, R>
|
|
104
|
-
) =>
|
|
105
|
-
Layer.effect(
|
|
106
|
-
dbTag,
|
|
107
|
-
Effect.gen(function*(_) {
|
|
108
|
-
const { client } = yield* _(clientTag)
|
|
109
|
-
const dbName_ = yield* _(dbName)
|
|
110
|
-
const db = yield* _(
|
|
111
|
-
client,
|
|
112
|
-
Effect.map((client) => MongoClient.db(client, dbName_)),
|
|
113
|
-
Effect.cached
|
|
114
|
-
)
|
|
115
|
-
return dbTag.of({ db } as DbService<DbK>) // TODO fix cast using branded ctor
|
|
116
|
-
})
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
export const fromConst = <DbK extends string, MongoClientK extends string>(
|
|
120
|
-
dbTag: TagType<DbK>,
|
|
121
|
-
clientTag: MongoClient.TagType<MongoClientK>,
|
|
122
|
-
dbName: string
|
|
123
|
-
) => fromEffect(dbTag, clientTag, Effect.succeed(dbName))
|