effect-mongodb 0.1.2 → 0.1.4
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 +25 -19
- package/dist/cjs/AggregationCursor.js +18 -8
- package/dist/cjs/AggregationCursor.js.map +1 -1
- package/dist/cjs/Collection.js +40 -29
- package/dist/cjs/Collection.js.map +1 -1
- package/dist/cjs/Db.js +9 -3
- package/dist/cjs/Db.js.map +1 -1
- package/dist/cjs/DocumentAggregationCursor.js +18 -8
- package/dist/cjs/DocumentAggregationCursor.js.map +1 -1
- package/dist/cjs/DocumentCollection.js +36 -24
- package/dist/cjs/DocumentCollection.js.map +1 -1
- package/dist/cjs/DocumentFindCursor.js +24 -14
- package/dist/cjs/DocumentFindCursor.js.map +1 -1
- package/dist/cjs/FindCursor.js +25 -18
- package/dist/cjs/FindCursor.js.map +1 -1
- package/dist/cjs/ListCollectionsCursor.js +18 -8
- package/dist/cjs/ListCollectionsCursor.js.map +1 -1
- package/dist/cjs/MongoClient.js +8 -2
- package/dist/cjs/MongoClient.js.map +1 -1
- package/dist/cjs/MongoError.js +7 -18
- package/dist/cjs/MongoError.js.map +1 -1
- package/dist/cjs/internal/mongo-error.js +27 -0
- package/dist/cjs/internal/mongo-error.js.map +1 -0
- package/dist/cjs/internal/schema.js +2 -2
- package/dist/cjs/internal/schema.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/AggregationCursor.d.ts +5 -5
- package/dist/dts/AggregationCursor.d.ts.map +1 -1
- package/dist/dts/Collection.d.ts +17 -18
- package/dist/dts/Collection.d.ts.map +1 -1
- package/dist/dts/Db.d.ts.map +1 -1
- package/dist/dts/DocumentAggregationCursor.d.ts +5 -5
- package/dist/dts/DocumentAggregationCursor.d.ts.map +1 -1
- package/dist/dts/DocumentCollection.d.ts +7 -7
- package/dist/dts/DocumentCollection.d.ts.map +1 -1
- package/dist/dts/DocumentFindCursor.d.ts +5 -5
- package/dist/dts/DocumentFindCursor.d.ts.map +1 -1
- package/dist/dts/FindCursor.d.ts +5 -5
- package/dist/dts/FindCursor.d.ts.map +1 -1
- package/dist/dts/ListCollectionsCursor.d.ts +5 -5
- package/dist/dts/ListCollectionsCursor.d.ts.map +1 -1
- package/dist/dts/MongoClient.d.ts.map +1 -1
- package/dist/dts/MongoError.d.ts +32 -12
- package/dist/dts/MongoError.d.ts.map +1 -1
- package/dist/dts/internal/mongo-error.d.ts +5 -0
- package/dist/dts/internal/mongo-error.d.ts.map +1 -0
- package/dist/esm/AggregationCursor.js +16 -6
- package/dist/esm/AggregationCursor.js.map +1 -1
- package/dist/esm/Collection.js +38 -27
- package/dist/esm/Collection.js.map +1 -1
- package/dist/esm/Db.js +9 -3
- package/dist/esm/Db.js.map +1 -1
- package/dist/esm/DocumentAggregationCursor.js +16 -6
- package/dist/esm/DocumentAggregationCursor.js.map +1 -1
- package/dist/esm/DocumentCollection.js +34 -22
- package/dist/esm/DocumentCollection.js.map +1 -1
- package/dist/esm/DocumentFindCursor.js +22 -12
- package/dist/esm/DocumentFindCursor.js.map +1 -1
- package/dist/esm/FindCursor.js +23 -16
- package/dist/esm/FindCursor.js.map +1 -1
- package/dist/esm/ListCollectionsCursor.js +16 -6
- package/dist/esm/ListCollectionsCursor.js.map +1 -1
- package/dist/esm/MongoClient.js +8 -2
- package/dist/esm/MongoClient.js.map +1 -1
- package/dist/esm/MongoError.js +3 -17
- package/dist/esm/MongoError.js.map +1 -1
- package/dist/esm/internal/mongo-error.js +18 -0
- package/dist/esm/internal/mongo-error.js.map +1 -0
- package/dist/esm/internal/schema.js +2 -2
- package/dist/esm/internal/schema.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/AggregationCursor.ts +31 -6
- package/src/Collection.ts +80 -50
- package/src/Db.ts +7 -3
- package/src/DocumentAggregationCursor.ts +27 -5
- package/src/DocumentCollection.ts +52 -27
- package/src/DocumentFindCursor.ts +34 -11
- package/src/FindCursor.ts +36 -13
- package/src/ListCollectionsCursor.ts +31 -7
- package/src/MongoClient.ts +6 -2
- package/src/MongoError.ts +24 -32
- package/src/internal/mongo-error.ts +34 -0
- package/src/internal/schema.ts +2 -2
- package/src/internal/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FindCursor.js","names":["Data","Effect","F","Schema","Stream","Tuple","MongoError","
|
|
1
|
+
{"version":3,"file":"FindCursor.js","names":["Data","Effect","F","pipeArguments","Schema","Stream","Tuple","mongoErrorOrDie","MongoError","FindCursorImpl","TaggedClass","pipe","arguments","filter","dual","args","isFindCursor","cursor","schema","project","newSchema","value","sort","direction","limit","toArray","decode","decodeUnknown","promise","catchAllDefect","errorSource","flatMap","forEach","x","toArrayEither","mapError","error","make","either","toStream","fromAsyncIterable","identity","catchAll","mapEffect","toStreamEither","functionName","CollectionErrorSource","module","name","db","namespace","collection"],"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;AAGpC,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AAGrC,SAASC,eAAe,QAAQ,2BAA2B;AAC3D,OAAO,KAAKC,UAAU,MAAM,iBAAiB;AAW7C;AACA,OAAM,MAAOC,cAAoC,sBAAQT,IAAI,CAACU,WAAW,CAAC,YAAY,CAA4B;EAGhHC,IAAIA,CAAA;IACF,OAAOR,aAAa,CAAC,IAAI,EAAES,SAAS,CAAC;EACvC;;AAGF,OAAO,MAAMC,MAAM,gBAGfX,CAAC,CAACY,IAAI,CACPC,IAAI,IAAKC,YAAY,CAACD,IAAI,CAAC,CAAC,CAAC,CAAC,EAC/B,CACEE,MAA2B,E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AAW,CAACb,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EACjEZ,MAAM,CAACsC,SAAS,CAAEV,CAAC,IAAKP,MAAM,CAACO,CAAC,CAAC,CAAC,CACnC;AACH,CAAC;AAED,OAAO,MAAMW,cAAc,GACzB3B,MAA2B,IACiF;EAC5G,MAAMS,MAAM,GAAGtB,MAAM,CAACuB,aAAa,CAACV,MAAM,CAACC,MAAM,CAAC;EAClD,OAAOhB,CAAC,CAACS,IAAI,CACXN,MAAM,CAACmC,iBAAiB,CAACvB,MAAM,CAACA,MAAM,EAAEf,CAAC,CAACuC,QAAQ,CAAC,EACnDpC,MAAM,CAACqC,QAAQ,CAACnC,eAAe,CAACuB,WAAW,CAACb,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACvEZ,MAAM,CAACsC,SAAS,CAAEV,CAAC,IACjB/B,CAAC,CAACS,IAAI;EACJ;EACAe,MAAM,CAACO,CAAC,CAAC,EACThC,MAAM,CAACkC,QAAQ,CAAEC,KAAK,IAAK9B,KAAK,CAAC+B,IAAI,CAACJ,CAAC,EAAEG,KAAK,CAAC,CAAC,EAChDnC,MAAM,CAACqC,MAAM,CACd,CACF,CACF;AACH,CAAC;AAED,MAAMtB,YAAY,GAAIiB,CAAU,IAA+BA,CAAC,YAAYxB,cAAc;AAE1F,MAAMqB,WAAW,GAAGA,CAAUb,MAA2B,EAAE4B,YAAoB,KAC7E,IAAIrC,UAAU,CAACsC,qBAAqB,CAAC;EACnCC,MAAM,EAAEtC,cAAc,CAACuC,IAAI;EAC3BH,YAAY;EACZI,EAAE,EAAEhC,MAAM,CAACA,MAAM,CAACiC,SAAS,CAACD,EAAE;EAC9BE,UAAU,EAAElC,MAAM,CAACA,MAAM,CAACiC,SAAS,CAACC,UAAU,IAAI;CACnD,CAAC","ignoreList":[]}
|
|
@@ -4,12 +4,22 @@
|
|
|
4
4
|
import * as Data from "effect/Data";
|
|
5
5
|
import * as Effect from "effect/Effect";
|
|
6
6
|
import * as F from "effect/Function";
|
|
7
|
+
import { pipeArguments } from "effect/Pipeable";
|
|
7
8
|
import * as Stream from "effect/Stream";
|
|
9
|
+
import { mongoErrorOrDie } from "./internal/mongo-error.js";
|
|
8
10
|
import * as MongoError from "./MongoError.js";
|
|
9
|
-
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
11
|
+
/** @internal */
|
|
12
|
+
export class ListCollectionsCursorImpl extends /*#__PURE__*/Data.TaggedClass("ListCollectionsCursor") {
|
|
13
|
+
pipe() {
|
|
14
|
+
return pipeArguments(this, arguments);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export const toArray = cursor => F.pipe(Effect.promise(() => cursor.cursor.toArray()), Effect.catchAllDefect(mongoErrorOrDie(errorSource(cursor, "toArray"))));
|
|
18
|
+
export const toStream = cursor => F.pipe(Stream.fromAsyncIterable(cursor.cursor, F.identity), Stream.catchAll(mongoErrorOrDie(errorSource(cursor, "toStream"))));
|
|
19
|
+
const errorSource = (cursor, functionName) => new MongoError.CollectionErrorSource({
|
|
20
|
+
module: ListCollectionsCursorImpl.name,
|
|
21
|
+
functionName,
|
|
22
|
+
db: cursor.cursor.namespace.db,
|
|
23
|
+
collection: cursor.cursor.namespace.collection ?? "NO_COLLECTION_NAME"
|
|
24
|
+
});
|
|
15
25
|
//# sourceMappingURL=ListCollectionsCursor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListCollectionsCursor.js","names":["Data","Effect","F","Stream","MongoError","
|
|
1
|
+
{"version":3,"file":"ListCollectionsCursor.js","names":["Data","Effect","F","pipeArguments","Stream","mongoErrorOrDie","MongoError","ListCollectionsCursorImpl","TaggedClass","pipe","arguments","toArray","cursor","promise","catchAllDefect","errorSource","toStream","fromAsyncIterable","identity","catchAll","functionName","CollectionErrorSource","module","name","db","namespace","collection"],"sources":["../../src/ListCollectionsCursor.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,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Client.js
CHANGED
|
@@ -4,10 +4,16 @@
|
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
5
|
import * as F from "effect/Function";
|
|
6
6
|
import { MongoClient as MongoClient_ } from "mongodb";
|
|
7
|
+
import { mongoErrorOrDie } from "./internal/mongo-error.js";
|
|
7
8
|
import * as MongoError from "./MongoError.js";
|
|
8
|
-
export const connect = (url, options) => Effect.promise(() => MongoClient_.connect(url, options)).pipe(Effect.
|
|
9
|
-
export const close = /*#__PURE__*/F.dual(args => isMongoClient(args[0]), (client, force) => Effect.promise(() => client.close(force)).pipe(Effect.
|
|
9
|
+
export const connect = (url, options) => Effect.promise(() => MongoClient_.connect(url, options)).pipe(Effect.catchAllDefect(mongoErrorOrDie(errorSource([new URL(url).host], "connect"))));
|
|
10
|
+
export const close = /*#__PURE__*/F.dual(args => isMongoClient(args[0]), (client, force) => Effect.promise(() => client.close(force)).pipe(Effect.catchAllDefect(mongoErrorOrDie(errorSource(client.options.hosts.map(x => x.host ?? "NO_HOST"), "close")))));
|
|
10
11
|
export const connectScoped = (url, options) => Effect.acquireRelease(connect(url, options), client => close(client, options?.forceClose).pipe(Effect.orDie));
|
|
11
12
|
export const db = /*#__PURE__*/F.dual(args => isMongoClient(args[0]), (client, dbName, options) => client.db(dbName, options));
|
|
12
13
|
const isMongoClient = x => x instanceof MongoClient_;
|
|
14
|
+
const errorSource = (hosts, functionName) => new MongoError.ClientErrorSource({
|
|
15
|
+
module: "MongoClient",
|
|
16
|
+
functionName,
|
|
17
|
+
hosts
|
|
18
|
+
});
|
|
13
19
|
//# sourceMappingURL=MongoClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoClient.js","names":["Effect","F","MongoClient","MongoClient_","MongoError","connect","url","options","promise","pipe","
|
|
1
|
+
{"version":3,"file":"MongoClient.js","names":["Effect","F","MongoClient","MongoClient_","mongoErrorOrDie","MongoError","connect","url","options","promise","pipe","catchAllDefect","errorSource","URL","host","close","dual","args","isMongoClient","client","force","hosts","map","x","connectScoped","acquireRelease","forceClose","orDie","db","dbName","functionName","ClientErrorSource","module"],"sources":["../../src/MongoClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,CAAC,MAAM,iBAAiB;AAGpC,SAASC,WAAW,IAAIC,YAAY,QAAQ,SAAS;AACrD,SAASC,eAAe,QAAQ,2BAA2B;AAC3D,OAAO,KAAKC,UAAU,MAAM,iBAAiB;AAI7C,OAAO,MAAMC,OAAO,GAAGA,CACrBC,GAAW,EACXC,OAA4B,KAE5BR,MAAM,CAACS,OAAO,CAAC,MAAMN,YAAY,CAACG,OAAO,CAACC,GAAG,EAAEC,OAAO,CAAC,CAAC,CAACE,IAAI,CAC3DV,MAAM,CAACW,cAAc,CAACP,eAAe,CAACQ,WAAW,CAAC,CAAC,IAAIC,GAAG,CAACN,GAAG,CAAC,CAACO,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CACpF;AAEH,OAAO,MAAMC,KAAK,gBAGdd,CAAC,CAACe,IAAI,CACPC,IAAI,IAAKC,aAAa,CAACD,IAAI,CAAC,CAAC,CAAC,CAAC,EAChC,CAACE,MAAmB,EAAEC,KAAe,KACnCpB,MAAM,CAACS,OAAO,CAAC,MAAMU,MAAM,CAACJ,KAAK,CAACK,KAAK,CAAC,CAAC,CAACV,IAAI,CAC5CV,MAAM,CAACW,cAAc,CAACP,eAAe,CAACQ,WAAW,CAACO,MAAM,CAACX,OAAO,CAACa,KAAK,CAACC,GAAG,CAAEC,CAAC,IAAKA,CAAC,CAACT,IAAI,IAAI,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CACnH,CACJ;AAED,OAAO,MAAMU,aAAa,GAAGA,CAC3BjB,GAAW,EACXC,OAAuD,KAEvDR,MAAM,CAACyB,cAAc,CACnBnB,OAAO,CAACC,GAAG,EAAEC,OAAO,CAAC,EACpBW,MAAM,IAAKJ,KAAK,CAACI,MAAM,EAAEX,OAAO,EAAEkB,UAAU,CAAC,CAAChB,IAAI,CAACV,MAAM,CAAC2B,KAAK,CAAC,CAClE;AAEH,OAAO,MAAMC,EAAE,gBAGX3B,CAAC,CAACe,IAAI,CACPC,IAAI,IAAKC,aAAa,CAACD,IAAI,CAAC,CAAC,CAAC,CAAC,EAChC,CAACE,MAAmB,EAAEU,MAAe,EAAErB,OAAmB,KAASW,MAAM,CAACS,EAAE,CAACC,MAAM,EAAErB,OAAO,CAAC,CAC9F;AAED,MAAMU,aAAa,GAAIK,CAAU,IAAKA,CAAC,YAAYpB,YAAY;AAE/D,MAAMS,WAAW,GAAGA,CAACS,KAAoB,EAAES,YAAoB,KAC7D,IAAIzB,UAAU,CAAC0B,iBAAiB,CAAC;EAAEC,MAAM,EAAE,aAAa;EAAEF,YAAY;EAAET;AAAK,CAAE,CAAC","ignoreList":[]}
|
package/dist/esm/MongoError.js
CHANGED
|
@@ -2,22 +2,8 @@
|
|
|
2
2
|
* @since 0.0.1
|
|
3
3
|
*/
|
|
4
4
|
import * as Data from "effect/Data";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import * as Stream from "effect/Stream";
|
|
9
|
-
import { MongoError as MongoError_ } from "mongodb";
|
|
5
|
+
export class ClientErrorSource extends /*#__PURE__*/Data.TaggedClass("ClientErrorSource") {}
|
|
6
|
+
export class DbErrorSource extends /*#__PURE__*/Data.TaggedClass("DbErrorSource") {}
|
|
7
|
+
export class CollectionErrorSource extends /*#__PURE__*/Data.TaggedClass("CollectionErrorSource") {}
|
|
10
8
|
export class MongoError extends /*#__PURE__*/Data.TaggedError("MongoError") {}
|
|
11
|
-
export const mongoErrorDie = /*#__PURE__*/F.dual(2, (error, message) => F.pipe(Match.value(error), Match.when(Match.instanceOf(MongoError_), innerError => Effect.fail(new MongoError({
|
|
12
|
-
message,
|
|
13
|
-
innerError
|
|
14
|
-
}))), Match.orElse(cause => Effect.die(new Error(message, {
|
|
15
|
-
cause
|
|
16
|
-
})))));
|
|
17
|
-
export const mongoErrorStream = /*#__PURE__*/F.dual(2, (error, message) => F.pipe(Match.value(error), Match.when(Match.instanceOf(MongoError_), innerError => Stream.fail(new MongoError({
|
|
18
|
-
message,
|
|
19
|
-
innerError
|
|
20
|
-
}))), Match.orElse(cause => Stream.die(new Error(message, {
|
|
21
|
-
cause
|
|
22
|
-
})))));
|
|
23
9
|
//# sourceMappingURL=MongoError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoError.js","names":["Data","
|
|
1
|
+
{"version":3,"file":"MongoError.js","names":["Data","ClientErrorSource","TaggedClass","DbErrorSource","CollectionErrorSource","MongoError","TaggedError"],"sources":["../../src/MongoError.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,IAAI,MAAM,aAAa;AAGnC,OAAM,MAAOC,iBAAkB,sBAAQD,IAAI,CAACE,WAAW,CAAC,mBAAmB,CAIzE;AAEF,OAAM,MAAOC,aAAc,sBAAQH,IAAI,CAACE,WAAW,CAAC,eAAe,CAIjE;AAEF,OAAM,MAAOE,qBAAsB,sBAAQJ,IAAI,CAACE,WAAW,CAAC,uBAAuB,CAKjF;AAIF,OAAM,MAAOG,UAAW,sBAAQL,IAAI,CAACM,WAAW,CAAC,YAAY,CAI3D","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as F from "effect/Function";
|
|
3
|
+
import * as Match from "effect/Match";
|
|
4
|
+
import { MongoError as MongoError_ } from "mongodb";
|
|
5
|
+
import { MongoError } from "../MongoError.js";
|
|
6
|
+
export const mongoErrorOrDie = (source, message) => error => F.pipe(Match.value(error), Match.when(Match.instanceOf(MongoError_), F.flow(makeMongoError(source, message), Effect.fail)), Match.orElse(F.flow(makeError(source, message), Effect.die)));
|
|
7
|
+
const makeMongoError = (source, message) => cause => new MongoError({
|
|
8
|
+
message: messageFrom(source, message),
|
|
9
|
+
cause,
|
|
10
|
+
source
|
|
11
|
+
});
|
|
12
|
+
const makeError = (source, message) => cause => new Error(messageFrom(source, message), {
|
|
13
|
+
cause
|
|
14
|
+
});
|
|
15
|
+
const messageFrom = (source, message) => message ? `${messageFromSource(source)} - ${message}` : messageFromSource(source);
|
|
16
|
+
const messageFromSource = source => F.pipe(Match.value(source), Match.tag("ClientErrorSource", s => `${baseMessage(s)} - hosts ${s.hosts.join(", ")}`), Match.tag("DbErrorSource", s => `${baseMessage(s)} - ${s.db}`), Match.tag("CollectionErrorSource", s => `${baseMessage(s)} - ${s.db}.${s.collection}`), Match.exhaustive);
|
|
17
|
+
const baseMessage = s => `Error in ${s.module}.${s.functionName}`;
|
|
18
|
+
//# sourceMappingURL=mongo-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo-error.js","names":["Effect","F","Match","MongoError","MongoError_","mongoErrorOrDie","source","message","error","pipe","value","when","instanceOf","flow","makeMongoError","fail","orElse","makeError","die","cause","messageFrom","Error","messageFromSource","tag","s","baseMessage","hosts","join","db","collection","exhaustive","module","functionName"],"sources":["../../../src/internal/mongo-error.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,CAAC,MAAM,iBAAiB;AACpC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,SAASC,UAAU,IAAIC,WAAW,QAAQ,SAAS;AAEnD,SAASD,UAAU,QAAQ,kBAAkB;AAE7C,OAAO,MAAME,eAAe,GAC1BA,CAACC,MAAmB,EAAEC,OAAgB,KAAMC,KAAc,IACxDP,CAAC,CAACQ,IAAI,CACJP,KAAK,CAACQ,KAAK,CAACF,KAAK,CAAC,EAClBN,KAAK,CAACS,IAAI,CAACT,KAAK,CAACU,UAAU,CAACR,WAAW,CAAC,EAAEH,CAAC,CAACY,IAAI,CAACC,cAAc,CAACR,MAAM,EAAEC,OAAO,CAAC,EAAEP,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U,EAAE,CAAC,EACxF3B,KAAK,CAAC4B,UAAU,CACjB;AAEH,MAAML,WAAW,GAAID,CAA2C,IAAK,YAAYA,CAAC,CAACO,MAAM,IAAIP,CAAC,CAACQ,YAAY,EAAE","ignoreList":[]}
|
|
@@ -2,9 +2,9 @@ import * as Effect from "effect/Effect";
|
|
|
2
2
|
import * as O from "effect/Option";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
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* (
|
|
5
|
+
export const decodeNullableDocument = (schema, value) => Effect.gen(function* () {
|
|
6
6
|
if (value === null) return O.none();
|
|
7
|
-
const decoded = yield*
|
|
7
|
+
const decoded = yield* Schema.decodeUnknown(schema)(value);
|
|
8
8
|
return O.some(decoded);
|
|
9
9
|
});
|
|
10
10
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":["Effect","O","Schema","decodeNullableDocument","schema","value","gen","
|
|
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,aAAS;EAClB,IAAID,KAAK,KAAK,IAAI,EAAE,OAAOJ,CAAC,CAACM,IAAI,EAAE;EACnC,MAAMC,OAAO,GAAG,OAAON,MAAM,CAACO,aAAa,CAACL,MAAM,CAAC,CAACC,KAAK,CAAC;EAC1D,OAAOJ,CAAC,CAACS,IAAI,CAACF,OAAO,CAAC;AACxB,CAAC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
package/src/AggregationCursor.ts
CHANGED
|
@@ -5,22 +5,39 @@ 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 type * as ParseResult from "effect/ParseResult"
|
|
8
|
+
import type { Pipeable } from "effect/Pipeable"
|
|
9
|
+
import { pipeArguments } from "effect/Pipeable"
|
|
8
10
|
import * as Schema from "effect/Schema"
|
|
9
11
|
import * as Stream from "effect/Stream"
|
|
10
12
|
import type { AggregationCursor as MongoAggregationCursor } from "mongodb"
|
|
13
|
+
import { mongoErrorOrDie } from "./internal/mongo-error.js"
|
|
11
14
|
import * as MongoError from "./MongoError.js"
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
>
|
|
16
|
+
interface AggregationCursorFields<A, I = A, R = never> {
|
|
17
|
+
cursor: MongoAggregationCursor<unknown>
|
|
18
|
+
schema: Schema.Schema<A, I, R>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AggregationCursor<A, I = A, R = never> extends AggregationCursorFields<A, I, R>, Pipeable {
|
|
22
|
+
_tag: "AggregationCursor"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @internal */
|
|
26
|
+
export class AggregationCursorImpl<A, I = A, R = never>
|
|
27
|
+
extends Data.TaggedClass("AggregationCursor")<AggregationCursorFields<A, I, R>>
|
|
28
|
+
implements AggregationCursor<A, I, R>
|
|
29
|
+
{
|
|
30
|
+
pipe() {
|
|
31
|
+
return pipeArguments(this, arguments)
|
|
32
|
+
}
|
|
16
33
|
}
|
|
17
34
|
|
|
18
35
|
export const toArray = <A, I, R>(
|
|
19
36
|
cursor: AggregationCursor<A, I, R>
|
|
20
37
|
): Effect.Effect<Array<A>, MongoError.MongoError | ParseResult.ParseError, R> => {
|
|
21
38
|
const decode = Schema.decodeUnknown(cursor.schema)
|
|
22
|
-
return Effect.
|
|
23
|
-
Effect.
|
|
39
|
+
return Effect.promise(() => cursor.cursor.toArray()).pipe(
|
|
40
|
+
Effect.catchAllDefect(mongoErrorOrDie(errorSource(cursor, "toArray"))),
|
|
24
41
|
Effect.flatMap(Effect.forEach((x) => decode(x)))
|
|
25
42
|
)
|
|
26
43
|
}
|
|
@@ -31,7 +48,15 @@ export const toStream = <A, I, R>(
|
|
|
31
48
|
const decode = Schema.decodeUnknown(cursor.schema)
|
|
32
49
|
return F.pipe(
|
|
33
50
|
Stream.fromAsyncIterable(cursor.cursor, F.identity),
|
|
34
|
-
Stream.catchAll(
|
|
51
|
+
Stream.catchAll(mongoErrorOrDie(errorSource(cursor, "toStream"))),
|
|
35
52
|
Stream.mapEffect((x) => decode(x))
|
|
36
53
|
)
|
|
37
54
|
}
|
|
55
|
+
|
|
56
|
+
const errorSource = <A, I, R>(cursor: AggregationCursor<A, I, R>, functionName: string) =>
|
|
57
|
+
new MongoError.CollectionErrorSource({
|
|
58
|
+
module: AggregationCursorImpl.name,
|
|
59
|
+
functionName,
|
|
60
|
+
db: cursor.cursor.namespace.db,
|
|
61
|
+
collection: cursor.cursor.namespace.collection ?? "NO_COLLECTION_NAME"
|
|
62
|
+
})
|
package/src/Collection.ts
CHANGED
|
@@ -7,6 +7,8 @@ import * as Effect from "effect/Effect"
|
|
|
7
7
|
import * as F from "effect/Function"
|
|
8
8
|
import type * as O from "effect/Option"
|
|
9
9
|
import type * as ParseResult from "effect/ParseResult"
|
|
10
|
+
import type { Pipeable } from "effect/Pipeable"
|
|
11
|
+
import { pipeArguments } from "effect/Pipeable"
|
|
10
12
|
import * as Schema from "effect/Schema"
|
|
11
13
|
import type {
|
|
12
14
|
AggregateOptions,
|
|
@@ -38,14 +40,32 @@ import * as AggregationCursor from "./AggregationCursor.js"
|
|
|
38
40
|
import * as FindCursor from "./FindCursor.js"
|
|
39
41
|
import type { Filter } from "./internal/filter.js"
|
|
40
42
|
import type { ModifyResult } from "./internal/modify-result.js"
|
|
43
|
+
import { mongoErrorOrDie } from "./internal/mongo-error.js"
|
|
41
44
|
import * as SchemaExt from "./internal/schema.js"
|
|
42
45
|
import * as MongoError from "./MongoError.js"
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
type CollectionFields<A extends Document, I extends Document = A, R = never> = {
|
|
45
48
|
collection: MongoCollection
|
|
46
49
|
schema: Schema.Schema<A, I, R>
|
|
47
|
-
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface Collection<A extends Document, I extends Document = A, R = never>
|
|
53
|
+
extends CollectionFields<A, I, R>, Pipeable
|
|
54
|
+
{
|
|
55
|
+
_tag: "Collection"
|
|
56
|
+
/** @internal */
|
|
57
|
+
encode: ReturnType<typeof Schema.encode<A, I, R>>
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** @internal */
|
|
61
|
+
export class CollectionImpl<A extends Document, I extends Document = A, R = never>
|
|
62
|
+
extends Data.TaggedClass("Collection")<CollectionFields<A, I, R>>
|
|
63
|
+
implements Collection<A, I, R>
|
|
64
|
+
{
|
|
48
65
|
readonly encode = Schema.encode(this.schema)
|
|
66
|
+
pipe() {
|
|
67
|
+
return pipeArguments(this, arguments)
|
|
68
|
+
}
|
|
49
69
|
}
|
|
50
70
|
|
|
51
71
|
export type FindOptions = Omit<MongoFindOptions, "projection">
|
|
@@ -67,7 +87,7 @@ export const find: {
|
|
|
67
87
|
filter?: Filter<I>,
|
|
68
88
|
options?: FindOptions
|
|
69
89
|
): FindCursor.FindCursor<A, I, R> =>
|
|
70
|
-
new FindCursor.
|
|
90
|
+
new FindCursor.FindCursorImpl<A, I, R>({
|
|
71
91
|
cursor: collection.collection.find(filter ?? {}, options),
|
|
72
92
|
schema: collection.schema
|
|
73
93
|
})
|
|
@@ -89,53 +109,53 @@ export const findOne: {
|
|
|
89
109
|
filter: Filter<I>,
|
|
90
110
|
options?: FindOptions
|
|
91
111
|
): Effect.Effect<O.Option<A>, MongoError.MongoError | ParseResult.ParseError, R> =>
|
|
92
|
-
Effect.gen(function*(
|
|
93
|
-
const value = yield*
|
|
94
|
-
return yield*
|
|
112
|
+
Effect.gen(function*() {
|
|
113
|
+
const value = yield* Effect.promise(() => collection.collection.findOne(filter, options))
|
|
114
|
+
return yield* SchemaExt.decodeNullableDocument(collection.schema, value)
|
|
95
115
|
}).pipe(
|
|
96
|
-
Effect.catchAllDefect(
|
|
116
|
+
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "findOne")))
|
|
97
117
|
)
|
|
98
118
|
)
|
|
99
119
|
|
|
100
120
|
export const insertOne: {
|
|
101
121
|
<A extends Document>(doc: A, options?: InsertOneOptions): <I extends Document, R>(
|
|
102
122
|
collection: Collection<A, I, R>
|
|
103
|
-
) => Effect.Effect<InsertOneResult
|
|
123
|
+
) => Effect.Effect<InsertOneResult<I>, MongoError.MongoError | ParseResult.ParseError, R>
|
|
104
124
|
<A extends Document, I extends Document, R>(
|
|
105
125
|
collection: Collection<A, I, R>,
|
|
106
126
|
doc: A,
|
|
107
127
|
options?: InsertOneOptions
|
|
108
|
-
): Effect.Effect<InsertOneResult
|
|
128
|
+
): Effect.Effect<InsertOneResult<I>, MongoError.MongoError | ParseResult.ParseError, R>
|
|
109
129
|
} = F.dual((args) => isCollection(args[0]), <A extends Document, I extends Document, R>(
|
|
110
130
|
collection: Collection<A, I, R>,
|
|
111
131
|
doc: A,
|
|
112
132
|
options?: InsertOneOptions
|
|
113
|
-
): Effect.Effect<InsertOneResult
|
|
133
|
+
): Effect.Effect<InsertOneResult<I>, MongoError.MongoError | ParseResult.ParseError, R> =>
|
|
114
134
|
F.pipe(
|
|
115
135
|
collection.encode(doc),
|
|
116
136
|
Effect.flatMap((doc) => Effect.promise(() => collection.collection.insertOne(doc, options))),
|
|
117
|
-
Effect.catchAllDefect(
|
|
137
|
+
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "insertOne")))
|
|
118
138
|
))
|
|
119
139
|
|
|
120
140
|
export const insertMany: {
|
|
121
141
|
<A extends Document>(docs: ReadonlyArray<A>, options?: BulkWriteOptions): <I extends Document, R>(
|
|
122
142
|
collection: Collection<A, I, R>
|
|
123
|
-
) => Effect.Effect<InsertManyResult
|
|
143
|
+
) => Effect.Effect<InsertManyResult<I>, MongoError.MongoError | ParseResult.ParseError, R>
|
|
124
144
|
<A extends Document, I extends Document, R>(
|
|
125
145
|
collection: Collection<A, I, R>,
|
|
126
146
|
docs: ReadonlyArray<A>,
|
|
127
147
|
options?: BulkWriteOptions
|
|
128
|
-
): Effect.Effect<InsertManyResult
|
|
148
|
+
): Effect.Effect<InsertManyResult<I>, MongoError.MongoError | ParseResult.ParseError, R>
|
|
129
149
|
} = F.dual((args) => isCollection(args[0]), <A extends Document, I extends Document, R>(
|
|
130
150
|
collection: Collection<A, I, R>,
|
|
131
151
|
docs: ReadonlyArray<A>,
|
|
132
152
|
options?: BulkWriteOptions
|
|
133
|
-
): Effect.Effect<InsertManyResult
|
|
153
|
+
): Effect.Effect<InsertManyResult<I>, MongoError.MongoError | ParseResult.ParseError, R> => {
|
|
134
154
|
return F.pipe(
|
|
135
155
|
docs,
|
|
136
156
|
Effect.forEach((doc) => collection.encode(doc)),
|
|
137
157
|
Effect.flatMap((docs) => Effect.promise(() => collection.collection.insertMany(docs, options))),
|
|
138
|
-
Effect.catchAllDefect(
|
|
158
|
+
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "insertMany")))
|
|
139
159
|
)
|
|
140
160
|
})
|
|
141
161
|
|
|
@@ -156,7 +176,7 @@ export const deleteOne: {
|
|
|
156
176
|
options?: DeleteOptions
|
|
157
177
|
): Effect.Effect<DeleteResult, MongoError.MongoError, R> =>
|
|
158
178
|
Effect.promise(() => collection.collection.deleteOne(filter, options)).pipe(
|
|
159
|
-
Effect.catchAllDefect(
|
|
179
|
+
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "deleteOne")))
|
|
160
180
|
)
|
|
161
181
|
)
|
|
162
182
|
|
|
@@ -177,7 +197,7 @@ export const deleteMany: {
|
|
|
177
197
|
options?: DeleteOptions
|
|
178
198
|
): Effect.Effect<DeleteResult, MongoError.MongoError, R> =>
|
|
179
199
|
Effect.promise(() => collection.collection.deleteMany(filter, options)).pipe(
|
|
180
|
-
Effect.catchAllDefect(
|
|
200
|
+
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "deleteMany")))
|
|
181
201
|
)
|
|
182
202
|
)
|
|
183
203
|
|
|
@@ -186,15 +206,15 @@ export const updateMany: {
|
|
|
186
206
|
filter: Filter<I>,
|
|
187
207
|
update: UpdateFilter<I> | ReadonlyArray<Document>,
|
|
188
208
|
options?: UpdateOptions
|
|
189
|
-
): <A extends Document, R>(
|
|
190
|
-
collection: Collection<A,
|
|
191
|
-
) => Effect.Effect<UpdateResult
|
|
209
|
+
): <A extends Document, I2 extends I, R>(
|
|
210
|
+
collection: Collection<A, I2, R>
|
|
211
|
+
) => Effect.Effect<UpdateResult<I2>, MongoError.MongoError, R>
|
|
192
212
|
<A extends Document, I extends Document, R>(
|
|
193
213
|
collection: Collection<A, I, R>,
|
|
194
214
|
filter: Filter<I>,
|
|
195
215
|
update: UpdateFilter<I> | ReadonlyArray<Document>,
|
|
196
216
|
options?: UpdateOptions
|
|
197
|
-
): Effect.Effect<UpdateResult
|
|
217
|
+
): Effect.Effect<UpdateResult<I>, MongoError.MongoError, R>
|
|
198
218
|
} = F.dual(
|
|
199
219
|
(args) => isCollection(args[0]),
|
|
200
220
|
<A extends Document, I extends Document, R>(
|
|
@@ -202,31 +222,30 @@ export const updateMany: {
|
|
|
202
222
|
filter: Filter<I>,
|
|
203
223
|
update: UpdateFilter<I> | ReadonlyArray<Document>,
|
|
204
224
|
options?: UpdateOptions
|
|
205
|
-
): Effect.Effect<UpdateResult
|
|
225
|
+
): Effect.Effect<UpdateResult<I>, MongoError.MongoError, R> =>
|
|
206
226
|
Effect.promise(() =>
|
|
207
227
|
collection.collection.updateMany(
|
|
208
228
|
filter,
|
|
209
229
|
Array.isArray(update) ? [...update] : update as UpdateFilter<Document>,
|
|
210
230
|
options
|
|
211
231
|
)
|
|
212
|
-
).pipe(Effect.catchAllDefect(
|
|
232
|
+
).pipe(Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "updateMany"))))
|
|
213
233
|
)
|
|
214
234
|
|
|
215
235
|
export const replaceOne: {
|
|
216
236
|
<A extends Document, I extends Document>(
|
|
217
237
|
filter: Filter<I>,
|
|
218
|
-
// TODO: should we put WithoutId<A> here like the driver signature?
|
|
219
238
|
replacement: A,
|
|
220
239
|
options?: ReplaceOptions
|
|
221
240
|
): <R>(
|
|
222
241
|
collection: Collection<A, I, R>
|
|
223
|
-
) => Effect.Effect<UpdateResult | Document, MongoError.MongoError | ParseResult.ParseError, R>
|
|
242
|
+
) => Effect.Effect<UpdateResult<I> | Document, MongoError.MongoError | ParseResult.ParseError, R>
|
|
224
243
|
<A extends Document, I extends Document, R>(
|
|
225
244
|
collection: Collection<A, I, R>,
|
|
226
245
|
filter: Filter<I>,
|
|
227
246
|
replacement: A,
|
|
228
247
|
options?: ReplaceOptions
|
|
229
|
-
): Effect.Effect<UpdateResult | Document, MongoError.MongoError | ParseResult.ParseError, R>
|
|
248
|
+
): Effect.Effect<UpdateResult<I> | Document, MongoError.MongoError | ParseResult.ParseError, R>
|
|
230
249
|
} = F.dual(
|
|
231
250
|
(args) => isCollection(args[0]),
|
|
232
251
|
<A extends Document, I extends Document, R>(
|
|
@@ -235,7 +254,7 @@ export const replaceOne: {
|
|
|
235
254
|
replacement: A,
|
|
236
255
|
options?: ReplaceOptions
|
|
237
256
|
): Effect.Effect<
|
|
238
|
-
UpdateResult | Document,
|
|
257
|
+
UpdateResult<I> | Document,
|
|
239
258
|
MongoError.MongoError | ParseResult.ParseError,
|
|
240
259
|
R
|
|
241
260
|
> =>
|
|
@@ -244,7 +263,7 @@ export const replaceOne: {
|
|
|
244
263
|
Effect.flatMap((replacement) =>
|
|
245
264
|
Effect.promise(() => collection.collection.replaceOne(filter, replacement, options))
|
|
246
265
|
),
|
|
247
|
-
Effect.catchAllDefect(
|
|
266
|
+
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "replaceOne")))
|
|
248
267
|
)
|
|
249
268
|
)
|
|
250
269
|
|
|
@@ -306,17 +325,17 @@ export const findOneAndReplace: {
|
|
|
306
325
|
Effect.promise(() => collection.collection.findOneAndReplace(filter, replacement, options ?? {}))
|
|
307
326
|
),
|
|
308
327
|
Effect.flatMap((value) =>
|
|
309
|
-
Effect.gen(function*(
|
|
328
|
+
Effect.gen(function*() {
|
|
310
329
|
if (options?.includeResultMetadata && !!value) {
|
|
311
330
|
const result = value as unknown as MongoModifyResult<I>
|
|
312
|
-
const maybeValue = yield*
|
|
331
|
+
const maybeValue = yield* SchemaExt.decodeNullableDocument(collection.schema, result.value)
|
|
313
332
|
return { ...result, value: maybeValue }
|
|
314
333
|
}
|
|
315
|
-
return yield*
|
|
334
|
+
return yield* SchemaExt.decodeNullableDocument(collection.schema, value)
|
|
316
335
|
})
|
|
317
336
|
),
|
|
318
337
|
Effect.catchAllDefect(
|
|
319
|
-
|
|
338
|
+
mongoErrorOrDie(errorSource(collection, "findOneAndReplace"))
|
|
320
339
|
)
|
|
321
340
|
)
|
|
322
341
|
)
|
|
@@ -339,8 +358,10 @@ export const rename: {
|
|
|
339
358
|
): Effect.Effect<Collection<A, I, R>, MongoError.MongoError, R> =>
|
|
340
359
|
F.pipe(
|
|
341
360
|
Effect.promise(() => collection.collection.rename(newName, options)),
|
|
342
|
-
Effect.map((newCollection) =>
|
|
343
|
-
|
|
361
|
+
Effect.map((newCollection) =>
|
|
362
|
+
new CollectionImpl<A, I, R>({ collection: newCollection, schema: collection.schema })
|
|
363
|
+
),
|
|
364
|
+
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "rename")))
|
|
344
365
|
)
|
|
345
366
|
)
|
|
346
367
|
|
|
@@ -360,7 +381,7 @@ export const drop: {
|
|
|
360
381
|
): Effect.Effect<boolean, MongoError.MongoError, R> =>
|
|
361
382
|
F.pipe(
|
|
362
383
|
Effect.promise(() => collection.collection.drop(options)),
|
|
363
|
-
Effect.catchAllDefect(
|
|
384
|
+
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "drop")))
|
|
364
385
|
)
|
|
365
386
|
)
|
|
366
387
|
|
|
@@ -385,7 +406,7 @@ export const createIndexes: {
|
|
|
385
406
|
): Effect.Effect<Array<string>, MongoError.MongoError, R> =>
|
|
386
407
|
F.pipe(
|
|
387
408
|
Effect.promise(() => collection.collection.createIndexes([...indexSpecs], options)),
|
|
388
|
-
Effect.catchAllDefect(
|
|
409
|
+
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "createIndexes")))
|
|
389
410
|
)
|
|
390
411
|
)
|
|
391
412
|
|
|
@@ -407,57 +428,55 @@ export const createIndex: {
|
|
|
407
428
|
): Effect.Effect<string, MongoError.MongoError, R> =>
|
|
408
429
|
F.pipe(
|
|
409
430
|
Effect.promise(() => collection.collection.createIndex(indexSpec, options)),
|
|
410
|
-
Effect.catchAllDefect(
|
|
431
|
+
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "createIndex")))
|
|
411
432
|
)
|
|
412
433
|
)
|
|
413
434
|
|
|
414
|
-
// TODO: review return type. Should we return Document like mongodb driver?
|
|
415
435
|
export const dropIndex: {
|
|
416
436
|
(indexName: string, options?: DropIndexesOptions): <A extends Document, I extends Document, R>(
|
|
417
437
|
collection: Collection<A, I, R>
|
|
418
|
-
) => Effect.Effect<
|
|
438
|
+
) => Effect.Effect<Document, MongoError.MongoError, R>
|
|
419
439
|
<A extends Document, I extends Document, R>(
|
|
420
440
|
collection: Collection<A, I, R>,
|
|
421
441
|
indexName: string,
|
|
422
442
|
options?: DropIndexesOptions
|
|
423
|
-
): Effect.Effect<
|
|
443
|
+
): Effect.Effect<Document, MongoError.MongoError, R>
|
|
424
444
|
} = F.dual(
|
|
425
445
|
(args) => isCollection(args[0]),
|
|
426
446
|
<A extends Document, I extends Document, R>(
|
|
427
447
|
collection: Collection<A, I, R>,
|
|
428
448
|
indexName: string,
|
|
429
449
|
options?: DropIndexesOptions
|
|
430
|
-
): Effect.Effect<
|
|
450
|
+
): Effect.Effect<Document, MongoError.MongoError, R> =>
|
|
431
451
|
F.pipe(
|
|
432
452
|
Effect.promise(() => collection.collection.dropIndex(indexName, options)),
|
|
433
|
-
Effect.
|
|
434
|
-
Effect.catchAllDefect(MongoError.mongoErrorDie<void>("dropIndex error"))
|
|
453
|
+
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "dropIndex")))
|
|
435
454
|
)
|
|
436
455
|
)
|
|
437
456
|
|
|
438
457
|
export const aggregate: {
|
|
439
458
|
<B extends Document, BI extends Document, BR>(
|
|
440
|
-
pipeline: ReadonlyArray<Document>,
|
|
441
459
|
schema: Schema.Schema<B, BI, BR>,
|
|
460
|
+
pipeline: ReadonlyArray<Document>,
|
|
442
461
|
options?: AggregateOptions
|
|
443
462
|
): <A extends Document, I extends Document, R>(
|
|
444
463
|
collection: Collection<A, I, R>
|
|
445
464
|
) => AggregationCursor.AggregationCursor<B, BI, BR>
|
|
446
465
|
<A extends Document, I extends Document, R, B extends Document, BI extends Document, BR>(
|
|
447
466
|
collection: Collection<A, I, R>,
|
|
448
|
-
pipeline: ReadonlyArray<Document>,
|
|
449
467
|
schema: Schema.Schema<B, BI, BR>,
|
|
468
|
+
pipeline: ReadonlyArray<Document>,
|
|
450
469
|
options?: AggregateOptions
|
|
451
470
|
): AggregationCursor.AggregationCursor<B, BI, BR>
|
|
452
471
|
} = F.dual(
|
|
453
472
|
(args) => isCollection(args[0]),
|
|
454
473
|
<A extends Document, I extends Document, R, B extends Document, BI extends Document, BR>(
|
|
455
474
|
collection: Collection<A, I, R>,
|
|
456
|
-
pipeline: ReadonlyArray<Document>,
|
|
457
475
|
schema: Schema.Schema<B, BI, BR>,
|
|
476
|
+
pipeline: ReadonlyArray<Document>,
|
|
458
477
|
options?: AggregateOptions
|
|
459
478
|
): AggregationCursor.AggregationCursor<B, BI, BR> =>
|
|
460
|
-
new AggregationCursor.
|
|
479
|
+
new AggregationCursor.AggregationCursorImpl<B, BI, BR>({
|
|
461
480
|
cursor: collection.collection.aggregate([...pipeline], options),
|
|
462
481
|
schema
|
|
463
482
|
})
|
|
@@ -479,7 +498,7 @@ export const estimatedDocumentCount: {
|
|
|
479
498
|
): Effect.Effect<number, MongoError.MongoError, R> =>
|
|
480
499
|
F.pipe(
|
|
481
500
|
Effect.promise(() => collection.collection.estimatedDocumentCount(options)),
|
|
482
|
-
Effect.catchAllDefect(
|
|
501
|
+
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "estimatedDocumentCount")))
|
|
483
502
|
)
|
|
484
503
|
)
|
|
485
504
|
|
|
@@ -501,8 +520,19 @@ export const countDocuments: {
|
|
|
501
520
|
): Effect.Effect<number, MongoError.MongoError, R> =>
|
|
502
521
|
F.pipe(
|
|
503
522
|
Effect.promise(() => collection.collection.countDocuments(filter, options)),
|
|
504
|
-
Effect.catchAllDefect(
|
|
523
|
+
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "countDocuments")))
|
|
505
524
|
)
|
|
506
525
|
)
|
|
507
526
|
|
|
508
|
-
const isCollection = (x: unknown) => x instanceof
|
|
527
|
+
const isCollection = (x: unknown) => x instanceof CollectionImpl
|
|
528
|
+
|
|
529
|
+
const errorSource = <A extends Document, I extends Document = A, R = never>(
|
|
530
|
+
collection: Collection<A, I, R>,
|
|
531
|
+
functionName: string
|
|
532
|
+
) =>
|
|
533
|
+
new MongoError.CollectionErrorSource({
|
|
534
|
+
module: CollectionImpl.name,
|
|
535
|
+
functionName,
|
|
536
|
+
db: collection.collection.dbName,
|
|
537
|
+
collection: collection.collection.collectionName
|
|
538
|
+
})
|