effect-mongodb 0.0.5 → 0.1.1
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 +80 -13
- package/dist/cjs/AggregationCursor.js.map +1 -1
- package/dist/cjs/Collection.js +13 -16
- package/dist/cjs/Collection.js.map +1 -1
- package/dist/cjs/Db.js.map +1 -1
- package/dist/cjs/DocumentAggregationCursor.js.map +1 -1
- package/dist/cjs/DocumentCollection.js +4 -3
- package/dist/cjs/DocumentCollection.js.map +1 -1
- package/dist/cjs/DocumentFindCursor.js.map +1 -1
- package/dist/cjs/FindCursor.js.map +1 -1
- package/dist/cjs/ListCollectionsCursor.js.map +1 -1
- package/dist/cjs/MongoClient.js +4 -1
- package/dist/cjs/MongoClient.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/AggregationCursor.d.ts +1 -1
- package/dist/dts/AggregationCursor.d.ts.map +1 -1
- package/dist/dts/Collection.d.ts +12 -11
- package/dist/dts/Collection.d.ts.map +1 -1
- package/dist/dts/Db.d.ts +2 -3
- package/dist/dts/Db.d.ts.map +1 -1
- package/dist/dts/DocumentAggregationCursor.d.ts +2 -2
- package/dist/dts/DocumentAggregationCursor.d.ts.map +1 -1
- package/dist/dts/DocumentCollection.d.ts +8 -8
- package/dist/dts/DocumentCollection.d.ts.map +1 -1
- package/dist/dts/DocumentFindCursor.d.ts +1 -1
- package/dist/dts/DocumentFindCursor.d.ts.map +1 -1
- package/dist/dts/FindCursor.d.ts.map +1 -1
- package/dist/dts/ListCollectionsCursor.d.ts +1 -1
- package/dist/dts/ListCollectionsCursor.d.ts.map +1 -1
- package/dist/dts/MongoClient.d.ts +8 -0
- package/dist/dts/MongoClient.d.ts.map +1 -1
- package/dist/esm/AggregationCursor.js.map +1 -1
- package/dist/esm/Collection.js +13 -16
- package/dist/esm/Collection.js.map +1 -1
- package/dist/esm/Db.js.map +1 -1
- package/dist/esm/DocumentAggregationCursor.js.map +1 -1
- package/dist/esm/DocumentCollection.js +4 -3
- package/dist/esm/DocumentCollection.js.map +1 -1
- package/dist/esm/DocumentFindCursor.js.map +1 -1
- package/dist/esm/FindCursor.js.map +1 -1
- package/dist/esm/ListCollectionsCursor.js.map +1 -1
- package/dist/esm/MongoClient.js +2 -0
- package/dist/esm/MongoClient.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +2 -2
- package/src/AggregationCursor.ts +2 -2
- package/src/Collection.ts +34 -30
- package/src/Db.ts +2 -3
- package/src/DocumentAggregationCursor.ts +3 -3
- package/src/DocumentCollection.ts +18 -15
- package/src/DocumentFindCursor.ts +2 -2
- package/src/FindCursor.ts +7 -3
- package/src/ListCollectionsCursor.ts +2 -2
- package/src/MongoClient.ts +21 -0
- package/src/internal/version.ts +1 -1
|
@@ -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;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,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S,MAAM,GAAGnB,MAAM,CAACoB,aAAa,CAACV,MAAM,CAACC,MAAM,CAAC;EAClD,OAAOb,MAAM,CAACuB,UAAU,CAAC;IAAEC,GAAG,EAAEA,CAAA,KAAMZ,MAAM,CAACA,MAAM,CAACQ,OAAO,EAAE;IAAEK,KAAK,EAAExB,CAAC,CAACyB;EAAQ,CAAE,CAAC,CAACC,IAAI,CACtF3B,MAAM,CAAC4B,QAAQ,CAACvB,UAAU,CAACwB,aAAa,
|
|
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,KACO,IAAIF,UAAU,CAAC;EAAEM,MAAM,EAAEA,MAAM,CAACA,MAAM,CAACJ,MAAM,CAACA,MAAM,CAAC;EAAEK,MAAM,EAAED,MAA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,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":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListCollectionsCursor.js","names":["Data","Effect","F","Stream","MongoError","ListCollectionsCursor","TaggedClass","toArray","cursor","pipe","tryPromise","try","catch","identity","catchAll","mongoErrorDie","_tag","toStream","fromAsyncIterable","mongoErrorStream"],"sources":["../../src/ListCollectionsCursor.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,CAAC,MAAM,iBAAiB;AACpC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAKvC,OAAO,KAAKC,UAAU,MAAM,iBAAiB;AAO7C,OAAM,MAAOC,qBAEX,sBAAQL,IAAI,CAACM,WAAW,CAAC,uBAAuB,CAEhD;AAQF,OAAO,MAAMC,OAAO,GAClBC,MAAgC,IAEhCN,CAAC,CAACO,IAAI,CACJR,MAAM,CAACS,UAAU,CAAC;EAAEC,GAAG,EAAEA,CAAA,KAAMH,MAAM,CAACA,MAAM,CAACD,OAAO,EAAE;EAAEK,KAAK,EAAEV,CAAC,CAACW;AAAQ,CAAE,CAAC,EAC5EZ,MAAM,CAACa,QAAQ,CAACV,UAAU,CAACW,aAAa,
|
|
1
|
+
{"version":3,"file":"ListCollectionsCursor.js","names":["Data","Effect","F","Stream","MongoError","ListCollectionsCursor","TaggedClass","toArray","cursor","pipe","tryPromise","try","catch","identity","catchAll","mongoErrorDie","_tag","toStream","fromAsyncIterable","mongoErrorStream"],"sources":["../../src/ListCollectionsCursor.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,CAAC,MAAM,iBAAiB;AACpC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAKvC,OAAO,KAAKC,UAAU,MAAM,iBAAiB;AAO7C,OAAM,MAAOC,qBAEX,sBAAQL,IAAI,CAACM,WAAW,CAAC,uBAAuB,CAEhD;AAQF,OAAO,MAAMC,OAAO,GAClBC,MAAgC,IAEhCN,CAAC,CAACO,IAAI,CACJR,MAAM,CAACS,UAAU,CAAC;EAAEC,GAAG,EAAEA,CAAA,KAAMH,MAAM,CAACA,MAAM,CAACD,OAAO,EAAE;EAAEK,KAAK,EAAEV,CAAC,CAACW;AAAQ,CAAE,CAAC,EAC5EZ,MAAM,CAACa,QAAQ,CAACV,UAAU,CAACW,aAAa,CAAW,GAAGP,MAAM,CAACQ,IAAI,gBAAgB,CAAC,CAAC,CACpF;AAEH,OAAO,MAAMC,QAAQ,GACnBT,MAAgC,IAEhCN,CAAC,CAACO,IAAI,CACJN,MAAM,CAACe,iBAAiB,CAACV,MAAM,CAACA,MAAM,EAAEN,CAAC,CAACW,QAAQ,CAAC,EACnDV,MAAM,CAACW,QAAQ,CAACV,UAAU,CAACe,gBAAgB,CAAI,GAAGX,MAAM,CAACQ,IAAI,iBAAiB,CAAC,CAAC,CACjF","ignoreList":[]}
|
package/dist/esm/MongoClient.js
CHANGED
|
@@ -6,6 +6,8 @@ import * as F from "effect/Function";
|
|
|
6
6
|
import { MongoClient as MongoClient_ } from "mongodb";
|
|
7
7
|
import * as MongoError from "./MongoError.js";
|
|
8
8
|
export const connect = (url, options) => Effect.promise(() => MongoClient_.connect(url, options)).pipe(Effect.catchAll(MongoError.mongoErrorDie("connect error")));
|
|
9
|
+
export const close = /*#__PURE__*/F.dual(args => isMongoClient(args[0]), (client, force) => Effect.promise(() => client.close(force)).pipe(Effect.catchAll(MongoError.mongoErrorDie("close error"))));
|
|
10
|
+
export const connectScoped = (url, options) => Effect.acquireRelease(connect(url, options), client => close(client, options?.forceClose).pipe(Effect.orDie));
|
|
9
11
|
export const db = /*#__PURE__*/F.dual(args => isMongoClient(args[0]), (client, dbName, options) => client.db(dbName, options));
|
|
10
12
|
const isMongoClient = x => x instanceof MongoClient_;
|
|
11
13
|
//# sourceMappingURL=MongoClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoClient.js","names":["Effect","F","MongoClient","MongoClient_","MongoError","connect","url","options","promise","pipe","catchAll","mongoErrorDie","
|
|
1
|
+
{"version":3,"file":"MongoClient.js","names":["Effect","F","MongoClient","MongoClient_","MongoError","connect","url","options","promise","pipe","catchAll","mongoErrorDie","close","dual","args","isMongoClient","client","force","connectScoped","acquireRelease","forceClose","orDie","db","dbName","x"],"sources":["../../src/MongoClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,CAAC,MAAM,iBAAiB;AAGpC,SAASC,WAAW,I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@@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect-mongodb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "A MongoDB toolkit for Effect",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"homepage": "https://github.com/doubleloop-io/effect-mongodb",
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"effect": "^3.10.14",
|
|
16
|
-
"mongodb": "^6.
|
|
16
|
+
"mongodb": "^6.9.0"
|
|
17
17
|
},
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"provenance": true
|
package/src/AggregationCursor.ts
CHANGED
|
@@ -17,10 +17,10 @@ export class AggregationCursor<A, I = A, R = never> extends Data.TaggedClass("Ag
|
|
|
17
17
|
|
|
18
18
|
export const toArray = <A, I, R>(
|
|
19
19
|
cursor: AggregationCursor<A, I, R>
|
|
20
|
-
): Effect.Effect<
|
|
20
|
+
): Effect.Effect<Array<A>, MongoError.MongoError | ParseResult.ParseError, R> => {
|
|
21
21
|
const decode = Schema.decodeUnknown(cursor.schema)
|
|
22
22
|
return Effect.tryPromise({ try: () => cursor.cursor.toArray(), catch: F.identity }).pipe(
|
|
23
|
-
Effect.catchAll(MongoError.mongoErrorDie<
|
|
23
|
+
Effect.catchAll(MongoError.mongoErrorDie<Array<A>>("Unable to get array from mongodb aggregate cursor")),
|
|
24
24
|
Effect.flatMap(Effect.forEach((x) => decode(x)))
|
|
25
25
|
)
|
|
26
26
|
}
|
package/src/Collection.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 0.0.1
|
|
3
3
|
*/
|
|
4
|
+
import * as Array from "effect/Array"
|
|
4
5
|
import * as Data from "effect/Data"
|
|
5
6
|
import * as Effect from "effect/Effect"
|
|
6
7
|
import * as F from "effect/Function"
|
|
7
|
-
import * as O from "effect/Option"
|
|
8
|
+
import type * as O from "effect/Option"
|
|
8
9
|
import type * as ParseResult from "effect/ParseResult"
|
|
9
10
|
import * as Schema from "effect/Schema"
|
|
10
11
|
import type {
|
|
@@ -44,6 +45,7 @@ export class Collection<A extends Document, I extends Document = A, R = never> e
|
|
|
44
45
|
collection: MongoCollection
|
|
45
46
|
schema: Schema.Schema<A, I, R>
|
|
46
47
|
}> {
|
|
48
|
+
readonly encode = Schema.encode(this.schema)
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
export type FindOptions = Omit<MongoFindOptions, "projection">
|
|
@@ -74,12 +76,12 @@ export const find: {
|
|
|
74
76
|
export const findOne: {
|
|
75
77
|
<I extends Document>(filter: Filter<I>, options?: FindOptions): <A extends Document, R>(
|
|
76
78
|
collection: Collection<A, I, R>
|
|
77
|
-
) => Effect.Effect<O.Option<
|
|
79
|
+
) => Effect.Effect<O.Option<A>, MongoError.MongoError | ParseResult.ParseError, R>
|
|
78
80
|
<A extends Document, I extends Document, R>(
|
|
79
81
|
collection: Collection<A, I, R>,
|
|
80
82
|
filter: Filter<I>,
|
|
81
83
|
options?: FindOptions
|
|
82
|
-
): Effect.Effect<O.Option<
|
|
84
|
+
): Effect.Effect<O.Option<A>, MongoError.MongoError | ParseResult.ParseError, R>
|
|
83
85
|
} = F.dual(
|
|
84
86
|
(args) => isCollection(args[0]),
|
|
85
87
|
<A extends Document, I extends Document, R>(
|
|
@@ -89,8 +91,7 @@ export const findOne: {
|
|
|
89
91
|
): Effect.Effect<O.Option<A>, MongoError.MongoError | ParseResult.ParseError, R> =>
|
|
90
92
|
Effect.gen(function*(_) {
|
|
91
93
|
const value = yield* _(Effect.promise(() => collection.collection.findOne(filter, options)))
|
|
92
|
-
|
|
93
|
-
return O.none()
|
|
94
|
+
return yield* _(SchemaExt.decodeNullableDocument(collection.schema, value))
|
|
94
95
|
}).pipe(
|
|
95
96
|
Effect.catchAllDefect(MongoError.mongoErrorDie<O.Option<A>>("findOne error"))
|
|
96
97
|
)
|
|
@@ -111,29 +112,28 @@ export const insertOne: {
|
|
|
111
112
|
options?: InsertOneOptions
|
|
112
113
|
): Effect.Effect<InsertOneResult, MongoError.MongoError | ParseResult.ParseError, R> =>
|
|
113
114
|
F.pipe(
|
|
114
|
-
|
|
115
|
+
collection.encode(doc),
|
|
115
116
|
Effect.flatMap((doc) => Effect.promise(() => collection.collection.insertOne(doc, options))),
|
|
116
117
|
Effect.catchAllDefect(MongoError.mongoErrorDie<InsertOneResult>("insertOne error"))
|
|
117
118
|
))
|
|
118
119
|
|
|
119
120
|
export const insertMany: {
|
|
120
|
-
<A extends Document>(docs:
|
|
121
|
+
<A extends Document>(docs: ReadonlyArray<A>, options?: BulkWriteOptions): <I extends Document, R>(
|
|
121
122
|
collection: Collection<A, I, R>
|
|
122
123
|
) => Effect.Effect<InsertManyResult, MongoError.MongoError | ParseResult.ParseError, R>
|
|
123
124
|
<A extends Document, I extends Document, R>(
|
|
124
125
|
collection: Collection<A, I, R>,
|
|
125
|
-
docs:
|
|
126
|
+
docs: ReadonlyArray<A>,
|
|
126
127
|
options?: BulkWriteOptions
|
|
127
128
|
): Effect.Effect<InsertManyResult, MongoError.MongoError | ParseResult.ParseError, R>
|
|
128
129
|
} = F.dual((args) => isCollection(args[0]), <A extends Document, I extends Document, R>(
|
|
129
130
|
collection: Collection<A, I, R>,
|
|
130
|
-
docs:
|
|
131
|
+
docs: ReadonlyArray<A>,
|
|
131
132
|
options?: BulkWriteOptions
|
|
132
133
|
): Effect.Effect<InsertManyResult, MongoError.MongoError | ParseResult.ParseError, R> => {
|
|
133
|
-
const encode = Schema.encode(collection.schema)
|
|
134
134
|
return F.pipe(
|
|
135
135
|
docs,
|
|
136
|
-
Effect.forEach((doc) => encode(doc)),
|
|
136
|
+
Effect.forEach((doc) => collection.encode(doc)),
|
|
137
137
|
Effect.flatMap((docs) => Effect.promise(() => collection.collection.insertMany(docs, options))),
|
|
138
138
|
Effect.catchAllDefect(MongoError.mongoErrorDie<InsertManyResult>("insertMany error"))
|
|
139
139
|
)
|
|
@@ -184,7 +184,7 @@ export const deleteMany: {
|
|
|
184
184
|
export const updateMany: {
|
|
185
185
|
<I extends Document>(
|
|
186
186
|
filter: Filter<I>,
|
|
187
|
-
update: UpdateFilter<I> |
|
|
187
|
+
update: UpdateFilter<I> | ReadonlyArray<Document>,
|
|
188
188
|
options?: UpdateOptions
|
|
189
189
|
): <A extends Document, R>(
|
|
190
190
|
collection: Collection<A, I, R>
|
|
@@ -192,7 +192,7 @@ export const updateMany: {
|
|
|
192
192
|
<A extends Document, I extends Document, R>(
|
|
193
193
|
collection: Collection<A, I, R>,
|
|
194
194
|
filter: Filter<I>,
|
|
195
|
-
update: UpdateFilter<I> |
|
|
195
|
+
update: UpdateFilter<I> | ReadonlyArray<Document>,
|
|
196
196
|
options?: UpdateOptions
|
|
197
197
|
): Effect.Effect<UpdateResult, MongoError.MongoError, R>
|
|
198
198
|
} = F.dual(
|
|
@@ -200,14 +200,16 @@ export const updateMany: {
|
|
|
200
200
|
<A extends Document, I extends Document, R>(
|
|
201
201
|
collection: Collection<A, I, R>,
|
|
202
202
|
filter: Filter<I>,
|
|
203
|
-
update: UpdateFilter<I> |
|
|
203
|
+
update: UpdateFilter<I> | ReadonlyArray<Document>,
|
|
204
204
|
options?: UpdateOptions
|
|
205
205
|
): Effect.Effect<UpdateResult, MongoError.MongoError, R> =>
|
|
206
206
|
Effect.promise(() =>
|
|
207
|
-
collection.collection.updateMany(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
collection.collection.updateMany(
|
|
208
|
+
filter,
|
|
209
|
+
Array.isArray(update) ? [...update] : update as UpdateFilter<Document>,
|
|
210
|
+
options
|
|
211
|
+
)
|
|
212
|
+
).pipe(Effect.catchAllDefect(MongoError.mongoErrorDie<UpdateResult>("updateMany error")))
|
|
211
213
|
)
|
|
212
214
|
|
|
213
215
|
export const replaceOne: {
|
|
@@ -238,8 +240,7 @@ export const replaceOne: {
|
|
|
238
240
|
R
|
|
239
241
|
> =>
|
|
240
242
|
F.pipe(
|
|
241
|
-
|
|
242
|
-
Schema.encode(collection.schema)(replacement),
|
|
243
|
+
collection.encode(replacement),
|
|
243
244
|
Effect.flatMap((replacement) =>
|
|
244
245
|
Effect.promise(() => collection.collection.replaceOne(filter, replacement, options))
|
|
245
246
|
),
|
|
@@ -300,8 +301,7 @@ export const findOneAndReplace: {
|
|
|
300
301
|
options?: FindOneAndReplaceOptions
|
|
301
302
|
): Effect.Effect<O.Option<A> | ModifyResult<A>, MongoError.MongoError | ParseResult.ParseError, R> =>
|
|
302
303
|
F.pipe(
|
|
303
|
-
|
|
304
|
-
Schema.encode(collection.schema)(replacement),
|
|
304
|
+
collection.encode(replacement),
|
|
305
305
|
Effect.flatMap((replacement) =>
|
|
306
306
|
Effect.promise(() => collection.collection.findOneAndReplace(filter, replacement, options ?? {}))
|
|
307
307
|
),
|
|
@@ -365,23 +365,26 @@ export const drop: {
|
|
|
365
365
|
)
|
|
366
366
|
|
|
367
367
|
export const createIndexes: {
|
|
368
|
-
(
|
|
368
|
+
(
|
|
369
|
+
indexSpecs: ReadonlyArray<IndexDescription>,
|
|
370
|
+
options?: CreateIndexesOptions
|
|
371
|
+
): <A extends Document, I extends Document, R>(
|
|
369
372
|
collection: Collection<A, I, R>
|
|
370
373
|
) => Effect.Effect<Array<string>, MongoError.MongoError, R>
|
|
371
374
|
<A extends Document, I extends Document, R>(
|
|
372
375
|
collection: Collection<A, I, R>,
|
|
373
|
-
indexSpecs:
|
|
376
|
+
indexSpecs: ReadonlyArray<IndexDescription>,
|
|
374
377
|
options?: CreateIndexesOptions
|
|
375
378
|
): Effect.Effect<Array<string>, MongoError.MongoError, R>
|
|
376
379
|
} = F.dual(
|
|
377
380
|
(args) => isCollection(args[0]),
|
|
378
381
|
<A extends Document, I extends Document, R>(
|
|
379
382
|
collection: Collection<A, I, R>,
|
|
380
|
-
indexSpecs:
|
|
383
|
+
indexSpecs: ReadonlyArray<IndexDescription>,
|
|
381
384
|
options?: CreateIndexesOptions
|
|
382
385
|
): Effect.Effect<Array<string>, MongoError.MongoError, R> =>
|
|
383
386
|
F.pipe(
|
|
384
|
-
Effect.promise(() => collection.collection.createIndexes(indexSpecs, options)),
|
|
387
|
+
Effect.promise(() => collection.collection.createIndexes([...indexSpecs], options)),
|
|
385
388
|
Effect.catchAllDefect(MongoError.mongoErrorDie<Array<string>>("createIndexes error"))
|
|
386
389
|
)
|
|
387
390
|
)
|
|
@@ -408,6 +411,7 @@ export const createIndex: {
|
|
|
408
411
|
)
|
|
409
412
|
)
|
|
410
413
|
|
|
414
|
+
// TODO: review return type. Should we return Document like mongodb driver?
|
|
411
415
|
export const dropIndex: {
|
|
412
416
|
(indexName: string, options?: DropIndexesOptions): <A extends Document, I extends Document, R>(
|
|
413
417
|
collection: Collection<A, I, R>
|
|
@@ -433,7 +437,7 @@ export const dropIndex: {
|
|
|
433
437
|
|
|
434
438
|
export const aggregate: {
|
|
435
439
|
<B extends Document, BI extends Document, BR>(
|
|
436
|
-
pipeline:
|
|
440
|
+
pipeline: ReadonlyArray<Document>,
|
|
437
441
|
schema: Schema.Schema<B, BI, BR>,
|
|
438
442
|
options?: AggregateOptions
|
|
439
443
|
): <A extends Document, I extends Document, R>(
|
|
@@ -441,7 +445,7 @@ export const aggregate: {
|
|
|
441
445
|
) => AggregationCursor.AggregationCursor<B, BI, BR>
|
|
442
446
|
<A extends Document, I extends Document, R, B extends Document, BI extends Document, BR>(
|
|
443
447
|
collection: Collection<A, I, R>,
|
|
444
|
-
pipeline:
|
|
448
|
+
pipeline: ReadonlyArray<Document>,
|
|
445
449
|
schema: Schema.Schema<B, BI, BR>,
|
|
446
450
|
options?: AggregateOptions
|
|
447
451
|
): AggregationCursor.AggregationCursor<B, BI, BR>
|
|
@@ -449,12 +453,12 @@ export const aggregate: {
|
|
|
449
453
|
(args) => isCollection(args[0]),
|
|
450
454
|
<A extends Document, I extends Document, R, B extends Document, BI extends Document, BR>(
|
|
451
455
|
collection: Collection<A, I, R>,
|
|
452
|
-
pipeline:
|
|
456
|
+
pipeline: ReadonlyArray<Document>,
|
|
453
457
|
schema: Schema.Schema<B, BI, BR>,
|
|
454
458
|
options?: AggregateOptions
|
|
455
459
|
): AggregationCursor.AggregationCursor<B, BI, BR> =>
|
|
456
460
|
new AggregationCursor.AggregationCursor<B, BI, BR>({
|
|
457
|
-
cursor: collection.collection.aggregate(pipeline, options),
|
|
461
|
+
cursor: collection.collection.aggregate([...pipeline], options),
|
|
458
462
|
schema
|
|
459
463
|
})
|
|
460
464
|
)
|
package/src/Db.ts
CHANGED
|
@@ -42,7 +42,7 @@ export const collection: {
|
|
|
42
42
|
)
|
|
43
43
|
|
|
44
44
|
export const listCollections: {
|
|
45
|
-
(
|
|
45
|
+
(db: Db): ListCollectionsCursor.ListCollectionsCursor
|
|
46
46
|
(filter: Document): (db: Db) => ListCollectionsCursor.ListCollectionsCursor
|
|
47
47
|
(
|
|
48
48
|
filter: Document,
|
|
@@ -52,7 +52,6 @@ export const listCollections: {
|
|
|
52
52
|
filter: Document,
|
|
53
53
|
options: Exclude<ListCollectionsOptions, "nameOnly"> & { nameOnly: false }
|
|
54
54
|
): (db: Db) => ListCollectionsCursor.FullListCollectionsCursor
|
|
55
|
-
(db: Db): ListCollectionsCursor.ListCollectionsCursor
|
|
56
55
|
(db: Db, filter: Document): ListCollectionsCursor.ListCollectionsCursor
|
|
57
56
|
(
|
|
58
57
|
db: Db,
|
|
@@ -71,7 +70,7 @@ export const listCollections: {
|
|
|
71
70
|
)
|
|
72
71
|
|
|
73
72
|
export const dropCollection: {
|
|
74
|
-
(name: string): (db: Db) => Effect.Effect<boolean>
|
|
73
|
+
(name: string): (db: Db) => Effect.Effect<boolean, MongoError.MongoError>
|
|
75
74
|
(name: string, options: DropCollectionOptions): (db: Db) => Effect.Effect<boolean, MongoError.MongoError>
|
|
76
75
|
(db: Db, name: string): Effect.Effect<boolean, MongoError.MongoError>
|
|
77
76
|
(db: Db, name: string, options: DropCollectionOptions): Effect.Effect<boolean, MongoError.MongoError>
|
|
@@ -5,7 +5,7 @@ import * as Data from "effect/Data"
|
|
|
5
5
|
import * as Effect from "effect/Effect"
|
|
6
6
|
import * as F from "effect/Function"
|
|
7
7
|
import * as Stream from "effect/Stream"
|
|
8
|
-
import type { AggregationCursor as MongoAggregationCursor } from "mongodb"
|
|
8
|
+
import type { AggregationCursor as MongoAggregationCursor, Document } from "mongodb"
|
|
9
9
|
import * as MongoError from "./MongoError.js"
|
|
10
10
|
|
|
11
11
|
export class DocumentAggregationCursor
|
|
@@ -15,10 +15,10 @@ export class DocumentAggregationCursor
|
|
|
15
15
|
|
|
16
16
|
export const toArray = (
|
|
17
17
|
cursor: DocumentAggregationCursor
|
|
18
|
-
): Effect.Effect<
|
|
18
|
+
): Effect.Effect<Array<Document>, MongoError.MongoError> =>
|
|
19
19
|
F.pipe(
|
|
20
20
|
Effect.tryPromise({ try: () => cursor.cursor.toArray(), catch: F.identity }),
|
|
21
|
-
Effect.catchAll(MongoError.mongoErrorDie<
|
|
21
|
+
Effect.catchAll(MongoError.mongoErrorDie<Array<Document>>(`${cursor._tag}.toArray error`))
|
|
22
22
|
)
|
|
23
23
|
|
|
24
24
|
export const toStream = (
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 0.0.1
|
|
3
3
|
*/
|
|
4
|
+
import * as Array from "effect/Array"
|
|
4
5
|
import * as Data from "effect/Data"
|
|
5
6
|
import * as Effect from "effect/Effect"
|
|
6
7
|
import * as F from "effect/Function"
|
|
@@ -110,19 +111,19 @@ export const insertOne: {
|
|
|
110
111
|
|
|
111
112
|
export const insertMany: {
|
|
112
113
|
(
|
|
113
|
-
docs:
|
|
114
|
+
docs: ReadonlyArray<OptionalUnlessRequiredId<Document>>,
|
|
114
115
|
options?: BulkWriteOptions
|
|
115
116
|
): (
|
|
116
117
|
collection: DocumentCollection
|
|
117
118
|
) => Effect.Effect<InsertOneResult, MongoError.MongoError>
|
|
118
119
|
(
|
|
119
120
|
collection: DocumentCollection,
|
|
120
|
-
docs:
|
|
121
|
+
docs: ReadonlyArray<OptionalUnlessRequiredId<Document>>,
|
|
121
122
|
options?: BulkWriteOptions
|
|
122
123
|
): Effect.Effect<InsertOneResult, MongoError.MongoError>
|
|
123
124
|
} = F.dual((args) => isDocumentCollection(args[0]), (
|
|
124
125
|
collection: DocumentCollection,
|
|
125
|
-
docs:
|
|
126
|
+
docs: ReadonlyArray<OptionalUnlessRequiredId<Document>>,
|
|
126
127
|
options?: BulkWriteOptions
|
|
127
128
|
): Effect.Effect<InsertManyResult, MongoError.MongoError> =>
|
|
128
129
|
F.pipe(
|
|
@@ -177,7 +178,7 @@ export const deleteMany: {
|
|
|
177
178
|
export const updateMany: {
|
|
178
179
|
(
|
|
179
180
|
filter: Filter<Document>,
|
|
180
|
-
update: UpdateFilter<Document> |
|
|
181
|
+
update: UpdateFilter<Document> | ReadonlyArray<Document>,
|
|
181
182
|
options?: UpdateOptions
|
|
182
183
|
): (
|
|
183
184
|
collection: DocumentCollection
|
|
@@ -185,7 +186,7 @@ export const updateMany: {
|
|
|
185
186
|
(
|
|
186
187
|
collection: DocumentCollection,
|
|
187
188
|
filter: Filter<Document>,
|
|
188
|
-
update: UpdateFilter<Document> |
|
|
189
|
+
update: UpdateFilter<Document> | ReadonlyArray<Document>,
|
|
189
190
|
options?: UpdateOptions
|
|
190
191
|
): Effect.Effect<UpdateResult, MongoError.MongoError>
|
|
191
192
|
} = F.dual(
|
|
@@ -193,11 +194,13 @@ export const updateMany: {
|
|
|
193
194
|
(
|
|
194
195
|
collection: DocumentCollection,
|
|
195
196
|
filter: Filter<Document>,
|
|
196
|
-
update: UpdateFilter<Document> |
|
|
197
|
+
update: UpdateFilter<Document> | ReadonlyArray<Document>,
|
|
197
198
|
options?: UpdateOptions
|
|
198
199
|
): Effect.Effect<UpdateResult, MongoError.MongoError> =>
|
|
199
200
|
F.pipe(
|
|
200
|
-
Effect.promise(() =>
|
|
201
|
+
Effect.promise(() =>
|
|
202
|
+
collection.collection.updateMany(filter, Array.isArray(update) ? [...update] : update, options)
|
|
203
|
+
),
|
|
201
204
|
Effect.catchAllDefect(MongoError.mongoErrorDie<UpdateResult>("updateMany error"))
|
|
202
205
|
)
|
|
203
206
|
)
|
|
@@ -339,23 +342,23 @@ export const drop: {
|
|
|
339
342
|
)
|
|
340
343
|
|
|
341
344
|
export const createIndexes: {
|
|
342
|
-
(indexSpecs:
|
|
345
|
+
(indexSpecs: ReadonlyArray<IndexDescription>, options?: CreateIndexesOptions): (
|
|
343
346
|
collection: DocumentCollection
|
|
344
347
|
) => Effect.Effect<Array<string>, MongoError.MongoError>
|
|
345
348
|
(
|
|
346
349
|
collection: DocumentCollection,
|
|
347
|
-
indexSpecs:
|
|
350
|
+
indexSpecs: ReadonlyArray<IndexDescription>,
|
|
348
351
|
options?: CreateIndexesOptions
|
|
349
352
|
): Effect.Effect<Array<string>, MongoError.MongoError>
|
|
350
353
|
} = F.dual(
|
|
351
354
|
(args) => isDocumentCollection(args[0]),
|
|
352
355
|
(
|
|
353
356
|
collection: DocumentCollection,
|
|
354
|
-
indexSpecs:
|
|
357
|
+
indexSpecs: ReadonlyArray<IndexDescription>,
|
|
355
358
|
options?: CreateIndexesOptions
|
|
356
359
|
): Effect.Effect<Array<string>, MongoError.MongoError> =>
|
|
357
360
|
F.pipe(
|
|
358
|
-
Effect.promise(() => collection.collection.createIndexes(indexSpecs, options)),
|
|
361
|
+
Effect.promise(() => collection.collection.createIndexes([...indexSpecs], options)),
|
|
359
362
|
Effect.catchAllDefect(MongoError.mongoErrorDie<Array<string>>("createIndexes error"))
|
|
360
363
|
)
|
|
361
364
|
)
|
|
@@ -407,23 +410,23 @@ export const dropIndex: {
|
|
|
407
410
|
)
|
|
408
411
|
|
|
409
412
|
export const aggregate: {
|
|
410
|
-
(pipeline?:
|
|
413
|
+
(pipeline?: ReadonlyArray<Document>, options?: AggregateOptions): (
|
|
411
414
|
collection: DocumentCollection
|
|
412
415
|
) => DocumentAggregationCursor.DocumentAggregationCursor
|
|
413
416
|
(
|
|
414
417
|
collection: DocumentCollection,
|
|
415
|
-
pipeline?:
|
|
418
|
+
pipeline?: ReadonlyArray<Document>,
|
|
416
419
|
options?: AggregateOptions
|
|
417
420
|
): DocumentAggregationCursor.DocumentAggregationCursor
|
|
418
421
|
} = F.dual(
|
|
419
422
|
(args) => isDocumentCollection(args[0]),
|
|
420
423
|
(
|
|
421
424
|
collection: DocumentCollection,
|
|
422
|
-
pipeline?:
|
|
425
|
+
pipeline?: ReadonlyArray<Document>,
|
|
423
426
|
options?: AggregateOptions
|
|
424
427
|
): DocumentAggregationCursor.DocumentAggregationCursor =>
|
|
425
428
|
new DocumentAggregationCursor.DocumentAggregationCursor({
|
|
426
|
-
cursor: collection.collection.aggregate(pipeline, options)
|
|
429
|
+
cursor: collection.collection.aggregate(pipeline ? [...pipeline] : undefined, options)
|
|
427
430
|
})
|
|
428
431
|
)
|
|
429
432
|
|
|
@@ -51,10 +51,10 @@ export const limit: {
|
|
|
51
51
|
new DocumentFindCursor({ cursor: cursor.cursor.limit(value) })
|
|
52
52
|
)
|
|
53
53
|
|
|
54
|
-
export const toArray = (cursor: DocumentFindCursor): Effect.Effect<
|
|
54
|
+
export const toArray = (cursor: DocumentFindCursor): Effect.Effect<Array<Document>, MongoError.MongoError> =>
|
|
55
55
|
F.pipe(
|
|
56
56
|
Effect.tryPromise({ try: () => cursor.cursor.toArray(), catch: F.identity }),
|
|
57
|
-
Effect.catchAll(MongoError.mongoErrorDie<
|
|
57
|
+
Effect.catchAll(MongoError.mongoErrorDie<Array<Document>>("toArray error"))
|
|
58
58
|
)
|
|
59
59
|
|
|
60
60
|
export const toStream = (
|
package/src/FindCursor.ts
CHANGED
|
@@ -79,17 +79,21 @@ export const toArray = <A, I, R>(
|
|
|
79
79
|
): Effect.Effect<Array<A>, MongoError.MongoError | ParseResult.ParseError, R> => {
|
|
80
80
|
const decode = Schema.decodeUnknown(cursor.schema)
|
|
81
81
|
return Effect.tryPromise({ try: () => cursor.cursor.toArray(), catch: F.identity }).pipe(
|
|
82
|
-
Effect.catchAll(MongoError.mongoErrorDie<
|
|
82
|
+
Effect.catchAll(MongoError.mongoErrorDie<Array<A>>("Unable to get array from mongodb cursor")),
|
|
83
83
|
Effect.flatMap(Effect.forEach((x) => decode(x)))
|
|
84
84
|
)
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
export const toArrayEither = <A, I, R>(
|
|
88
88
|
cursor: FindCursor<A, I, R>
|
|
89
|
-
): Effect.Effect<
|
|
89
|
+
): Effect.Effect<
|
|
90
|
+
Array<E.Either<A, [document: unknown, error: ParseResult.ParseError]>>,
|
|
91
|
+
MongoError.MongoError,
|
|
92
|
+
R
|
|
93
|
+
> => {
|
|
90
94
|
const decode = Schema.decodeUnknown(cursor.schema)
|
|
91
95
|
return Effect.tryPromise({ try: () => cursor.cursor.toArray(), catch: F.identity }).pipe(
|
|
92
|
-
Effect.catchAll(MongoError.mongoErrorDie<
|
|
96
|
+
Effect.catchAll(MongoError.mongoErrorDie<Array<unknown>>("Unable to get array from mongodb cursor")),
|
|
93
97
|
Effect.flatMap(Effect.forEach((x) =>
|
|
94
98
|
F.pipe(
|
|
95
99
|
decode(x),
|
|
@@ -30,10 +30,10 @@ export type FullListCollectionsCursor = ListCollectionsCursor<MongoCollectionInf
|
|
|
30
30
|
|
|
31
31
|
export const toArray = <T extends DefaultCollectionInfo>(
|
|
32
32
|
cursor: ListCollectionsCursor<T>
|
|
33
|
-
): Effect.Effect<
|
|
33
|
+
): Effect.Effect<Array<T>, MongoError.MongoError> =>
|
|
34
34
|
F.pipe(
|
|
35
35
|
Effect.tryPromise({ try: () => cursor.cursor.toArray(), catch: F.identity }),
|
|
36
|
-
Effect.catchAll(MongoError.mongoErrorDie<
|
|
36
|
+
Effect.catchAll(MongoError.mongoErrorDie<Array<T>>(`${cursor._tag}.toArray error`))
|
|
37
37
|
)
|
|
38
38
|
|
|
39
39
|
export const toStream = <T extends DefaultCollectionInfo>(
|
package/src/MongoClient.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as Effect from "effect/Effect"
|
|
5
5
|
import * as F from "effect/Function"
|
|
6
|
+
import type * as Scope from "effect/Scope"
|
|
6
7
|
import type { Db, DbOptions, MongoClientOptions } from "mongodb"
|
|
7
8
|
import { MongoClient as MongoClient_ } from "mongodb"
|
|
8
9
|
import * as MongoError from "./MongoError.js"
|
|
@@ -17,6 +18,26 @@ export const connect = (
|
|
|
17
18
|
Effect.catchAll(MongoError.mongoErrorDie<MongoClient_>("connect error"))
|
|
18
19
|
)
|
|
19
20
|
|
|
21
|
+
export const close: {
|
|
22
|
+
(force?: boolean): (client: MongoClient) => Effect.Effect<void, MongoError.MongoError>
|
|
23
|
+
(client: MongoClient, force?: boolean): Effect.Effect<void, MongoError.MongoError>
|
|
24
|
+
} = F.dual(
|
|
25
|
+
(args) => isMongoClient(args[0]),
|
|
26
|
+
(client: MongoClient, force?: boolean): Effect.Effect<void, MongoError.MongoError> =>
|
|
27
|
+
Effect.promise(() => client.close(force)).pipe(
|
|
28
|
+
Effect.catchAll(MongoError.mongoErrorDie<void>("close error"))
|
|
29
|
+
)
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
export const connectScoped = (
|
|
33
|
+
url: string,
|
|
34
|
+
options?: MongoClientOptions & { forceClose?: boolean }
|
|
35
|
+
): Effect.Effect<MongoClient, MongoError.MongoError, Scope.Scope> =>
|
|
36
|
+
Effect.acquireRelease(
|
|
37
|
+
connect(url, options),
|
|
38
|
+
(client) => close(client, options?.forceClose).pipe(Effect.orDie)
|
|
39
|
+
)
|
|
40
|
+
|
|
20
41
|
export const db: {
|
|
21
42
|
(dbName?: string, options?: DbOptions): (client: MongoClient) => Db
|
|
22
43
|
(client: MongoClient, dbName?: string, options?: DbOptions): Db
|
package/src/internal/version.ts
CHANGED