effect-mongodb 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/cjs/AggregationCursor.js +4 -4
- package/dist/cjs/AggregationCursor.js.map +1 -1
- package/dist/cjs/Collection.js +24 -22
- package/dist/cjs/Collection.js.map +1 -1
- package/dist/cjs/Db.js +2 -2
- package/dist/cjs/Db.js.map +1 -1
- package/dist/cjs/DocumentAggregationCursor.js +4 -4
- package/dist/cjs/DocumentAggregationCursor.js.map +1 -1
- package/dist/cjs/DocumentCollection.js +24 -22
- package/dist/cjs/DocumentCollection.js.map +1 -1
- package/dist/cjs/DocumentFindCursor.js +27 -11
- package/dist/cjs/DocumentFindCursor.js.map +1 -1
- package/dist/cjs/FindCursor.js +33 -17
- package/dist/cjs/FindCursor.js.map +1 -1
- package/dist/cjs/ListCollectionsCursor.js +4 -4
- package/dist/cjs/ListCollectionsCursor.js.map +1 -1
- package/dist/cjs/MongoClient.js +3 -3
- package/dist/cjs/MongoClient.js.map +1 -1
- package/dist/cjs/internal/mongo-operation.js +18 -0
- package/dist/cjs/internal/mongo-operation.js.map +1 -0
- package/dist/cjs/internal/tracing.js +49 -0
- package/dist/cjs/internal/tracing.js.map +1 -0
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Collection.d.ts.map +1 -1
- package/dist/dts/DocumentCollection.d.ts.map +1 -1
- package/dist/dts/DocumentFindCursor.d.ts +4 -2
- package/dist/dts/DocumentFindCursor.d.ts.map +1 -1
- package/dist/dts/FindCursor.d.ts +4 -2
- package/dist/dts/FindCursor.d.ts.map +1 -1
- package/dist/dts/MongoClient.d.ts.map +1 -1
- package/dist/dts/internal/mongo-operation.d.ts +6 -0
- package/dist/dts/internal/mongo-operation.d.ts.map +1 -0
- package/dist/dts/internal/tracing.d.ts +6 -0
- package/dist/dts/internal/tracing.d.ts.map +1 -0
- package/dist/esm/AggregationCursor.js +4 -4
- package/dist/esm/AggregationCursor.js.map +1 -1
- package/dist/esm/Collection.js +24 -22
- package/dist/esm/Collection.js.map +1 -1
- package/dist/esm/Db.js +2 -2
- package/dist/esm/Db.js.map +1 -1
- package/dist/esm/DocumentAggregationCursor.js +4 -4
- package/dist/esm/DocumentAggregationCursor.js.map +1 -1
- package/dist/esm/DocumentCollection.js +24 -22
- package/dist/esm/DocumentCollection.js.map +1 -1
- package/dist/esm/DocumentFindCursor.js +27 -11
- package/dist/esm/DocumentFindCursor.js.map +1 -1
- package/dist/esm/FindCursor.js +31 -16
- package/dist/esm/FindCursor.js.map +1 -1
- package/dist/esm/ListCollectionsCursor.js +4 -4
- package/dist/esm/ListCollectionsCursor.js.map +1 -1
- package/dist/esm/MongoClient.js +3 -3
- package/dist/esm/MongoClient.js.map +1 -1
- package/dist/esm/internal/mongo-operation.js +8 -0
- package/dist/esm/internal/mongo-operation.js.map +1 -0
- package/dist/esm/internal/tracing.js +39 -0
- package/dist/esm/internal/tracing.js.map +1 -0
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/AggregationCursor.ts +4 -4
- package/src/Collection.ts +24 -26
- package/src/Db.ts +2 -2
- package/src/DocumentAggregationCursor.ts +4 -4
- package/src/DocumentCollection.ts +27 -31
- package/src/DocumentFindCursor.ts +28 -15
- package/src/FindCursor.ts +35 -18
- package/src/ListCollectionsCursor.ts +4 -4
- package/src/MongoClient.ts +3 -5
- package/src/internal/mongo-operation.ts +22 -0
- package/src/internal/tracing.ts +47 -0
- package/src/internal/version.ts +1 -1
package/dist/esm/FindCursor.js
CHANGED
|
@@ -8,7 +8,7 @@ import { pipeArguments } from "effect/Pipeable";
|
|
|
8
8
|
import * as Schema from "effect/Schema";
|
|
9
9
|
import * as Stream from "effect/Stream";
|
|
10
10
|
import * as Tuple from "effect/Tuple";
|
|
11
|
-
import {
|
|
11
|
+
import { mongoOperation, mongoStreamOperation } from "./internal/mongo-operation.js";
|
|
12
12
|
import * as MongoError from "./MongoError.js";
|
|
13
13
|
/** @internal */
|
|
14
14
|
export class FindCursorImpl extends /*#__PURE__*/Data.TaggedClass("FindCursor") {
|
|
@@ -17,44 +17,59 @@ export class FindCursorImpl extends /*#__PURE__*/Data.TaggedClass("FindCursor")
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
export const filter = /*#__PURE__*/F.dual(args => isFindCursor(args[0]), (cursor, filter) => new FindCursorImpl({
|
|
20
|
-
cursor
|
|
21
|
-
|
|
20
|
+
...cursor,
|
|
21
|
+
filter
|
|
22
22
|
}));
|
|
23
23
|
export const project = /*#__PURE__*/F.dual(args => isFindCursor(args[0]), (cursor, newSchema, value) => new FindCursorImpl({
|
|
24
|
-
cursor
|
|
25
|
-
schema: newSchema
|
|
24
|
+
...cursor,
|
|
25
|
+
schema: newSchema,
|
|
26
|
+
options: {
|
|
27
|
+
...cursor.options,
|
|
28
|
+
projection: value
|
|
29
|
+
}
|
|
26
30
|
}));
|
|
27
31
|
export const sort = /*#__PURE__*/F.dual(args => isFindCursor(args[0]), (cursor, sort, direction) => new FindCursorImpl({
|
|
28
|
-
cursor
|
|
29
|
-
|
|
32
|
+
...cursor,
|
|
33
|
+
options: {
|
|
34
|
+
...cursor.options,
|
|
35
|
+
sort: sortOption(sort, direction)
|
|
36
|
+
}
|
|
30
37
|
}));
|
|
31
38
|
export const limit = /*#__PURE__*/F.dual(args => isFindCursor(args[0]), (cursor, value) => new FindCursorImpl({
|
|
32
|
-
cursor
|
|
33
|
-
|
|
39
|
+
...cursor,
|
|
40
|
+
options: {
|
|
41
|
+
...cursor.options,
|
|
42
|
+
limit: value
|
|
43
|
+
}
|
|
34
44
|
}));
|
|
35
45
|
export const toArray = cursor => {
|
|
36
46
|
const decode = Schema.decodeUnknown(cursor.schema);
|
|
37
|
-
return Effect.promise(() => cursor.
|
|
47
|
+
return Effect.promise(() => nativeCursor(cursor).toArray()).pipe(mongoOperation(errorSource(cursor, "toArray")), Effect.flatMap(Effect.forEach(x => decode(x))));
|
|
38
48
|
};
|
|
39
49
|
export const toArrayEither = cursor => {
|
|
40
50
|
const decode = Schema.decodeUnknown(cursor.schema);
|
|
41
|
-
return Effect.promise(() => cursor.
|
|
51
|
+
return Effect.promise(() => nativeCursor(cursor).toArray()).pipe(mongoOperation(errorSource(cursor, "toArrayEither")), Effect.flatMap(Effect.forEach(x => F.pipe(decode(x), Effect.mapError(error => Tuple.make(x, error)), Effect.either))));
|
|
42
52
|
};
|
|
43
53
|
export const toStream = cursor => {
|
|
44
54
|
const decode = Schema.decodeUnknown(cursor.schema);
|
|
45
|
-
return F.pipe(Stream.fromAsyncIterable(cursor
|
|
55
|
+
return F.pipe(Stream.suspend(() => Stream.fromAsyncIterable(nativeCursor(cursor), F.identity)), mongoStreamOperation(errorSource(cursor, "toStream")), Stream.mapEffect(x => decode(x)));
|
|
46
56
|
};
|
|
47
57
|
export const toStreamEither = cursor => {
|
|
48
58
|
const decode = Schema.decodeUnknown(cursor.schema);
|
|
49
|
-
return F.pipe(Stream.fromAsyncIterable(cursor
|
|
59
|
+
return F.pipe(Stream.suspend(() => Stream.fromAsyncIterable(nativeCursor(cursor), F.identity)), mongoStreamOperation(errorSource(cursor, "toStreamEither")), Stream.mapEffect(x => F.pipe(
|
|
50
60
|
// keep new line
|
|
51
61
|
decode(x), Effect.mapError(error => Tuple.make(x, error)), Effect.either)));
|
|
52
62
|
};
|
|
63
|
+
/** @internal */
|
|
64
|
+
export const sortOption = (sort, direction) => typeof sort === "string" && direction !== undefined ? {
|
|
65
|
+
[sort]: direction
|
|
66
|
+
} : sort;
|
|
67
|
+
const nativeCursor = cursor => cursor.collection.find(cursor.filter, cursor.options);
|
|
53
68
|
const isFindCursor = x => x instanceof FindCursorImpl;
|
|
54
69
|
const errorSource = (cursor, functionName) => new MongoError.CollectionErrorSource({
|
|
55
|
-
module:
|
|
70
|
+
module: "FindCursor",
|
|
56
71
|
functionName,
|
|
57
|
-
db: cursor.
|
|
58
|
-
collection: cursor.
|
|
72
|
+
db: cursor.collection.dbName,
|
|
73
|
+
collection: cursor.collection.collectionName
|
|
59
74
|
});
|
|
60
75
|
//# sourceMappingURL=FindCursor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FindCursor.js","names":["Data","Effect","F","pipeArguments","Schema","Stream","Tuple","
|
|
1
|
+
{"version":3,"file":"FindCursor.js","names":["Data","Effect","F","pipeArguments","Schema","Stream","Tuple","mongoOperation","mongoStreamOperation","MongoError","FindCursorImpl","TaggedClass","pipe","arguments","filter","dual","args","isFindCursor","cursor","project","newSchema","value","schema","options","projection","sort","direction","sortOption","limit","toArray","decode","decodeUnknown","promise","nativeCursor","errorSource","flatMap","forEach","x","toArrayEither","mapError","error","make","either","toStream","suspend","fromAsyncIterable","identity","mapEffect","toStreamEither","undefined","collection","find","functionName","CollectionErrorSource","module","db","dbName","collectionName"],"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;AAUrC,SAASC,cAAc,EAAEC,oBAAoB,QAAQ,+BAA+B;AACpF,OAAO,KAAKC,UAAU,MAAM,iBAAiB;AAa7C;AACA,OAAM,MAAOC,cAAoC,sBAAQV,IAAI,CAACW,WAAW,CAAC,YAAY,CAA4B;EAGhHC,IAAIA,CAAA;IACF,OAAOT,aAAa,CAAC,IAAI,EAAEU,SAAS,CAAC;EACvC;;AAKF,OAAO,MAAMC,MAAM,gBAGfZ,CAAC,CAACa,IAAI,CACPC,IAAI,IAAKC,YAAY,CAACD,IAAI,CAAC,CAAC,CAAC,CAAC,EAC/B,CACEE,MAA2B,E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;EACZG,EAAE,EAAErC,MAAM,CAACgC,UAAU,CAACM,MAAM;EAC5BN,UAAU,EAAEhC,MAAM,CAACgC,UAAU,CAACO;CAC/B,CAAC","ignoreList":[]}
|
|
@@ -6,7 +6,7 @@ import * as Effect from "effect/Effect";
|
|
|
6
6
|
import * as F from "effect/Function";
|
|
7
7
|
import { pipeArguments } from "effect/Pipeable";
|
|
8
8
|
import * as Stream from "effect/Stream";
|
|
9
|
-
import {
|
|
9
|
+
import { mongoOperation, mongoStreamOperation } from "./internal/mongo-operation.js";
|
|
10
10
|
import * as MongoError from "./MongoError.js";
|
|
11
11
|
/** @internal */
|
|
12
12
|
export class ListCollectionsCursorImpl extends /*#__PURE__*/Data.TaggedClass("ListCollectionsCursor") {
|
|
@@ -14,10 +14,10 @@ export class ListCollectionsCursorImpl extends /*#__PURE__*/Data.TaggedClass("Li
|
|
|
14
14
|
return pipeArguments(this, arguments);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
export const toArray = cursor => F.pipe(Effect.promise(() => cursor.cursor.toArray()),
|
|
18
|
-
export const toStream = cursor => F.pipe(Stream.fromAsyncIterable(cursor.cursor, F.identity),
|
|
17
|
+
export const toArray = cursor => F.pipe(Effect.promise(() => cursor.cursor.toArray()), mongoOperation(errorSource(cursor, "toArray")));
|
|
18
|
+
export const toStream = cursor => F.pipe(Stream.fromAsyncIterable(cursor.cursor, F.identity), mongoStreamOperation(errorSource(cursor, "toStream")));
|
|
19
19
|
const errorSource = (cursor, functionName) => new MongoError.CollectionErrorSource({
|
|
20
|
-
module:
|
|
20
|
+
module: "ListCollectionsCursor",
|
|
21
21
|
functionName,
|
|
22
22
|
db: cursor.cursor.namespace.db,
|
|
23
23
|
collection: cursor.cursor.namespace.collection ?? "NO_COLLECTION_NAME"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListCollectionsCursor.js","names":["Data","Effect","F","pipeArguments","Stream","
|
|
1
|
+
{"version":3,"file":"ListCollectionsCursor.js","names":["Data","Effect","F","pipeArguments","Stream","mongoOperation","mongoStreamOperation","MongoError","ListCollectionsCursorImpl","TaggedClass","pipe","arguments","toArray","cursor","promise","errorSource","toStream","fromAsyncIterable","identity","functionName","CollectionErrorSource","module","db","namespace","collection"],"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;AAEpC,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,OAAO,KAAKC,MAAM,MAAM,eAAe;AAKvC,SAASC,cAAc,EAAEC,oBAAoB,QAAQ,+BAA+B;AACpF,OAAO,KAAKC,UAAU,MAAM,iBAAiB;AAiB7C;AACA,OAAM,MAAOC,yBAEX,sBAAQR,IAAI,CAACS,WAAW,CAAC,uBAAuB,CAAiC;EACjFC,IAAIA,CAAA;IACF,OAAOP,aAAa,CAAC,IAAI,EAAEQ,SAAS,CAAC;EACvC;;AASF,OAAO,MAAMC,OAAO,GAClBC,MAAgC,IAEhCX,CAAC,CAACQ,IAAI,CACJT,MAAM,CAACa,OAAO,CAAC,MAAMD,MAAM,CAACA,MAAM,CAACD,OAAO,EAAE,CAAC,EAC7CP,cAAc,CAACU,WAAW,CAACF,MAAM,EAAE,SAAS,CAAC,CAAC,CAC/C;AAEH,OAAO,MAAMG,QAAQ,GACnBH,MAAgC,IAEhCX,CAAC,CAACQ,IAAI,CACJN,MAAM,CAACa,iBAAiB,CAACJ,MAAM,CAACA,MAAM,EAAEX,CAAC,CAACgB,QAAQ,CAAC,EACnDZ,oBAAoB,CAACS,WAAW,CAACF,MAAM,EAAE,UAAU,CAAC,CAAC,CACtD;AAEH,MAAME,WAAW,GAAGA,CAACF,MAA6B,EAAEM,YAAoB,KACtE,IAAIZ,UAAU,CAACa,qBAAqB,CAAC;EACnCC,MAAM,EAAE,uBAAuB;EAC/BF,YAAY;EACZG,EAAE,EAAET,MAAM,CAACA,MAAM,CAACU,SAAS,CAACD,EAAE;EAC9BE,UAAU,EAAEX,MAAM,CAACA,MAAM,CAACU,SAAS,CAACC,UAAU,IAAI;CACnD,CAAC","ignoreList":[]}
|
package/dist/esm/MongoClient.js
CHANGED
|
@@ -6,15 +6,15 @@ import * as Effect from "effect/Effect";
|
|
|
6
6
|
import * as F from "effect/Function";
|
|
7
7
|
import { MongoClient as MongoClient_ } from "mongodb";
|
|
8
8
|
import * as Db from "./Db.js";
|
|
9
|
-
import {
|
|
9
|
+
import { mongoOperation } from "./internal/mongo-operation.js";
|
|
10
10
|
import * as MongoError from "./MongoError.js";
|
|
11
11
|
export class MongoClient extends /*#__PURE__*/Data.TaggedClass("MongoClient") {}
|
|
12
12
|
export const connect = (url, options) => Effect.promise(() => MongoClient_.connect(url, options)).pipe(Effect.map(client => new MongoClient({
|
|
13
13
|
client
|
|
14
|
-
})),
|
|
14
|
+
})), mongoOperation(errorSource(hostsFromUrl(url), "connect")));
|
|
15
15
|
export const close = /*#__PURE__*/F.dual(args => isMongoClient(args[0]), ({
|
|
16
16
|
client
|
|
17
|
-
}, force) => Effect.promise(() => client.close(force)).pipe(
|
|
17
|
+
}, force) => Effect.promise(() => client.close(force)).pipe(mongoOperation(errorSource(client.options.hosts.map(x => x.host ?? UNKNOWN_HOST), "close"))));
|
|
18
18
|
export const connectScoped = (url, options) => Effect.acquireRelease(connect(url, options), client => close(client, options?.forceClose).pipe(Effect.orDie));
|
|
19
19
|
export const db = /*#__PURE__*/F.dual(args => isMongoClient(args[0]), ({
|
|
20
20
|
client
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoClient.js","names":["Data","Effect","F","MongoClient","MongoClient_","Db","
|
|
1
|
+
{"version":3,"file":"MongoClient.js","names":["Data","Effect","F","MongoClient","MongoClient_","Db","mongoOperation","MongoError","TaggedClass","connect","url","options","promise","pipe","map","client","errorSource","hostsFromUrl","close","dual","args","isMongoClient","force","hosts","x","host","UNKNOWN_HOST","connectScoped","acquireRelease","forceClose","orDie","db","dbName","functionName","ClientErrorSource","module","SCHEME","CREDENTIALS","HOSTS","MONGO_CONNECTION_STRING","RegExp","source","match","split"],"sources":["../../src/MongoClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,CAAC,MAAM,iBAAiB;AAGpC,SAASC,WAAW,IAAIC,YAAY,QAAQ,SAAS;AACrD,OAAO,KAAKC,EAAE,MAAM,SAAS;AAC7B,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,OAAO,KAAKC,UAAU,MAAM,iBAAiB;AAE7C,OAAM,MAAOJ,WAAY,sBAAQH,IAAI,CAACQ,WAAW,CAAC,aAAa,CAA2B;AAE1F,OAAO,MAAMC,OAAO,GAAGA,CACrBC,GAAW,EACXC,OAA4B,KAE5BV,MAAM,CAACW,OAAO,CAAC,MAAMR,YAAY,CAACK,OAAO,CAACC,GAAG,EAAEC,OAAO,CAAC,CAAC,CAACE,IAAI,CAC3DZ,MAAM,CAACa,GAAG,CAAEC,MAAM,IAAK,IAAIZ,WAAW,CAAC;EAAEY;AAAM,CAAE,CAAC,CAAC,EACnDT,cAAc,CAACU,WAAW,CAACC,YAAY,CAACP,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC,CAC1D;AAEH,OAAO,MAAMQ,KAAK,gBAGdhB,CAAC,CAACiB,IAAI,CACPC,IAAI,IAAKC,aAAa,CAACD,IAAI,CAAC,CAAC,CAAC,CAAC,EAChC,CAAC;EAAEL;AAAM,CAAe,EAAEO,KAAe,KACvCrB,MAAM,CAACW,OAAO,CAAC,MAAMG,MAAM,CAACG,KAAK,CAACI,KAAK,CAAC,CAAC,CAACT,IAAI,CAC5CP,cAAc,CAACU,WAAW,CAACD,MAAM,CAACJ,OAAO,CAACY,KAAK,CAACT,GAAG,CAAEU,CA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;EAChD,OAAOG,KAAK,GAAGA,KAAK,CAAC,CAAC,CAAC,CAACC,KAAK,CAAC,GAAG,CAAC,GAAG,CAACjB,YAAY,CAAC;AACrD,CAAC;AAED,MAAMA,YAAY,GAAG,SAAS","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as F from "effect/Function";
|
|
3
|
+
import * as Stream from "effect/Stream";
|
|
4
|
+
import { mongoErrorOrDie } from "./mongo-error.js";
|
|
5
|
+
import { withSpan, withSpanStream } from "./tracing.js";
|
|
6
|
+
export const mongoOperation = source => self => F.pipe(self, Effect.catchAllDefect(mongoErrorOrDie(source)), withSpan(source));
|
|
7
|
+
export const mongoStreamOperation = source => self => F.pipe(self, Stream.catchAll(mongoErrorOrDie(source)), withSpanStream(source));
|
|
8
|
+
//# sourceMappingURL=mongo-operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo-operation.js","names":["Effect","F","Stream","mongoErrorOrDie","withSpan","withSpanStream","mongoOperation","source","self","pipe","catchAllDefect","mongoStreamOperation","catchAll"],"sources":["../../../src/internal/mongo-operation.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,CAAC,MAAM,iBAAiB;AACpC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,SAASC,eAAe,QAAQ,kBAAkB;AAClD,SAASC,QAAQ,EAAEC,cAAc,QAAQ,cAAc;AAEvD,OAAO,MAAMC,cAAc,GACxBC,MAAmB,IAAeC,IAA4B,IAC7DP,CAAC,CAACQ,IAAI,CACJD,IAAI,EACJR,MAAM,CAACU,cAAc,CAACP,eAAe,CAACI,MAAM,CAAC,CAAC,EAC9CH,QAAQ,CAACG,MAAM,CAAC,CACjB;AAEL,OAAO,MAAMI,oBAAoB,GAC9BJ,MAAmB,IAAeC,IAA4B,IAC7DP,CAAC,CAACQ,IAAI,CACJD,IAAI,EACJN,MAAM,CAACU,QAAQ,CAACT,eAAe,CAACI,MAAM,CAAC,CAAC,EACxCF,cAAc,CAACE,MAAM,CAAC,CACvB","ignoreList":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as F from "effect/Function";
|
|
3
|
+
import * as Match from "effect/Match";
|
|
4
|
+
import * as Stream from "effect/Stream";
|
|
5
|
+
export const withSpan = source => self => Effect.withSpan(self, spanName(source), spanOptions(source));
|
|
6
|
+
export const withSpanStream = source => self => Stream.withSpan(self, spanName(source), spanOptions(source));
|
|
7
|
+
const spanName = source => `mongodb.${source.module}.${source.functionName}`;
|
|
8
|
+
const spanOptions = source => ({
|
|
9
|
+
kind: "client",
|
|
10
|
+
captureStackTrace: false,
|
|
11
|
+
attributes: {
|
|
12
|
+
"db.system.name": "mongodb",
|
|
13
|
+
"db.operation.name": source.functionName,
|
|
14
|
+
...sourceAttributes(source)
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const sourceAttributes = source => F.pipe(Match.value(source), Match.tag("ClientErrorSource", s => serverAttributes(s.hosts)), Match.tag("DbErrorSource", s => ({
|
|
18
|
+
"db.namespace": s.db
|
|
19
|
+
})), Match.tag("CollectionErrorSource", s => ({
|
|
20
|
+
"db.namespace": s.db,
|
|
21
|
+
"db.collection.name": s.collection
|
|
22
|
+
})), Match.exhaustive);
|
|
23
|
+
const serverAttributes = hosts => {
|
|
24
|
+
if (hosts.length !== 1) return {};
|
|
25
|
+
const [address, port] = splitHost(hosts[0]);
|
|
26
|
+
return port === undefined ? {
|
|
27
|
+
"server.address": address
|
|
28
|
+
} : {
|
|
29
|
+
"server.address": address,
|
|
30
|
+
"server.port": port
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const splitHost = host => {
|
|
34
|
+
const separator = host.lastIndexOf(":");
|
|
35
|
+
if (separator === -1) return [host, undefined];
|
|
36
|
+
const port = Number(host.slice(separator + 1));
|
|
37
|
+
return Number.isInteger(port) ? [host.slice(0, separator), port] : [host, undefined];
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=tracing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracing.js","names":["Effect","F","Match","Stream","withSpan","source","self","spanName","spanOptions","withSpanStream","module","functionName","kind","captureStackTrace","attributes","sourceAttributes","pipe","value","tag","s","serverAttributes","hosts","db","collection","exhaustive","length","address","port","splitHost","undefined","host","separator","lastIndexOf","Number","slice","isInteger"],"sources":["../../../src/internal/tracing.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,CAAC,MAAM,iBAAiB;AACpC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAIvC,OAAO,MAAMC,QAAQ,GAAIC,MAAmB,IAAeC,IAA4B,IACrFN,MAAM,CAACI,QAAQ,CAACE,IAAI,EAAEC,QAAQ,CAACF,MAAM,CAAC,EAAEG,WAAW,CAACH,MAAM,CAAC,CAAC;AAE9D,OAAO,MAAMI,cAAc,GACxBJ,MAAmB,IAAeC,IAA4B,IAC7DH,MAAM,CAACC,QAAQ,CAACE,IAAI,EAAEC,QAAQ,CAACF,MAAM,CAAC,EAAEG,WAAW,CAACH,MAAM,CAAC,CAAC;AAEhE,MAAME,QAAQ,GAAIF,MAAmB,IAAK,WAAWA,MAAM,CAACK,MAAM,IAAIL,MAAM,CAACM,YAAY,EAAE;AAE3F,MAAMH,WAAW,GAAIH,MAAmB,KAA0B;EAChEO,IAAI,EAAE,QAAQ;EACdC,iBAAiB,EAAE,KAAK;EACxBC,UAAU,EAAE;IACV,gBAAgB,EAAE,SAAS;IAC3B,mBAAmB,EAAET,MAAM,CAACM,YAAY;IACxC,GAAGI,gBAAgB,CAACV,MAAM;;CAE7B,CAAC;AAEF,MAAMU,gBAAgB,GAAIV,MAAmB,IAC3CJ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AAG,CAACG,IAAI,EAAED,SAAS,CAAC;AACtF,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
package/src/AggregationCursor.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { pipeArguments } from "effect/Pipeable"
|
|
|
10
10
|
import * as Schema from "effect/Schema"
|
|
11
11
|
import * as Stream from "effect/Stream"
|
|
12
12
|
import type { AggregationCursor as MongoAggregationCursor } from "mongodb"
|
|
13
|
-
import {
|
|
13
|
+
import { mongoOperation, mongoStreamOperation } from "./internal/mongo-operation.js"
|
|
14
14
|
import * as MongoError from "./MongoError.js"
|
|
15
15
|
|
|
16
16
|
interface AggregationCursorFields<A, I = A, R = never> {
|
|
@@ -37,7 +37,7 @@ export const toArray = <A, I, R>(
|
|
|
37
37
|
): Effect.Effect<Array<A>, MongoError.MongoError | ParseResult.ParseError, R> => {
|
|
38
38
|
const decode = Schema.decodeUnknown(cursor.schema)
|
|
39
39
|
return Effect.promise(() => cursor.cursor.toArray()).pipe(
|
|
40
|
-
|
|
40
|
+
mongoOperation(errorSource(cursor, "toArray")),
|
|
41
41
|
Effect.flatMap(Effect.forEach((x) => decode(x)))
|
|
42
42
|
)
|
|
43
43
|
}
|
|
@@ -48,14 +48,14 @@ export const toStream = <A, I, R>(
|
|
|
48
48
|
const decode = Schema.decodeUnknown(cursor.schema)
|
|
49
49
|
return F.pipe(
|
|
50
50
|
Stream.fromAsyncIterable(cursor.cursor, F.identity),
|
|
51
|
-
|
|
51
|
+
mongoStreamOperation(errorSource(cursor, "toStream")),
|
|
52
52
|
Stream.mapEffect((x) => decode(x))
|
|
53
53
|
)
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
const errorSource = <A, I, R>(cursor: AggregationCursor<A, I, R>, functionName: string) =>
|
|
57
57
|
new MongoError.CollectionErrorSource({
|
|
58
|
-
module:
|
|
58
|
+
module: "AggregationCursor",
|
|
59
59
|
functionName,
|
|
60
60
|
db: cursor.cursor.namespace.db,
|
|
61
61
|
collection: cursor.cursor.namespace.collection ?? "NO_COLLECTION_NAME"
|
package/src/Collection.ts
CHANGED
|
@@ -44,7 +44,7 @@ import type { AnyBulkWriteOperation as AnyBulkWriteOperation_ } from "./internal
|
|
|
44
44
|
import { encodeBulkWriteOperation } from "./internal/bulk-write-operation.js"
|
|
45
45
|
import type { Filter as Filter_ } from "./internal/filter.js"
|
|
46
46
|
import type { ModifyResult } from "./internal/modify-result.js"
|
|
47
|
-
import {
|
|
47
|
+
import { mongoOperation } from "./internal/mongo-operation.js"
|
|
48
48
|
import * as SchemaExt from "./internal/schema.js"
|
|
49
49
|
import * as MongoError from "./MongoError.js"
|
|
50
50
|
|
|
@@ -94,7 +94,9 @@ export const find: {
|
|
|
94
94
|
options?: FindOptions
|
|
95
95
|
): FindCursor.FindCursor<A, I, R> =>
|
|
96
96
|
new FindCursor.FindCursorImpl<A, I, R>({
|
|
97
|
-
|
|
97
|
+
collection: collection.collection,
|
|
98
|
+
filter: filter ?? {},
|
|
99
|
+
options: options ?? {},
|
|
98
100
|
schema: collection.schema
|
|
99
101
|
})
|
|
100
102
|
)
|
|
@@ -119,7 +121,7 @@ export const findOne: {
|
|
|
119
121
|
const value = yield* Effect.promise(() => collection.collection.findOne(filter, options))
|
|
120
122
|
return yield* SchemaExt.decodeNullableDocument(collection.schema, value)
|
|
121
123
|
}).pipe(
|
|
122
|
-
|
|
124
|
+
mongoOperation(errorSource(collection, "findOne"))
|
|
123
125
|
)
|
|
124
126
|
)
|
|
125
127
|
|
|
@@ -140,7 +142,7 @@ export const insertOne: {
|
|
|
140
142
|
F.pipe(
|
|
141
143
|
collection.encode(doc),
|
|
142
144
|
Effect.flatMap((doc) => Effect.promise(() => collection.collection.insertOne(doc, options))),
|
|
143
|
-
|
|
145
|
+
mongoOperation(errorSource(collection, "insertOne"))
|
|
144
146
|
))
|
|
145
147
|
|
|
146
148
|
export const insertMany: {
|
|
@@ -161,7 +163,7 @@ export const insertMany: {
|
|
|
161
163
|
docs,
|
|
162
164
|
Effect.forEach((doc) => collection.encode(doc)),
|
|
163
165
|
Effect.flatMap((docs) => Effect.promise(() => collection.collection.insertMany(docs, options))),
|
|
164
|
-
|
|
166
|
+
mongoOperation(errorSource(collection, "insertMany"))
|
|
165
167
|
)
|
|
166
168
|
})
|
|
167
169
|
|
|
@@ -182,7 +184,7 @@ export const deleteOne: {
|
|
|
182
184
|
options?: DeleteOptions
|
|
183
185
|
): Effect.Effect<DeleteResult, MongoError.MongoError, R> =>
|
|
184
186
|
Effect.promise(() => collection.collection.deleteOne(filter, options)).pipe(
|
|
185
|
-
|
|
187
|
+
mongoOperation(errorSource(collection, "deleteOne"))
|
|
186
188
|
)
|
|
187
189
|
)
|
|
188
190
|
|
|
@@ -203,7 +205,7 @@ export const deleteMany: {
|
|
|
203
205
|
options?: DeleteOptions
|
|
204
206
|
): Effect.Effect<DeleteResult, MongoError.MongoError, R> =>
|
|
205
207
|
Effect.promise(() => collection.collection.deleteMany(filter, options)).pipe(
|
|
206
|
-
|
|
208
|
+
mongoOperation(errorSource(collection, "deleteMany"))
|
|
207
209
|
)
|
|
208
210
|
)
|
|
209
211
|
|
|
@@ -235,7 +237,7 @@ export const updateOne: {
|
|
|
235
237
|
Array.isArray(update) ? [...update] : update as UpdateFilter<Document>,
|
|
236
238
|
options
|
|
237
239
|
)
|
|
238
|
-
).pipe(
|
|
240
|
+
).pipe(mongoOperation(errorSource(collection, "updateOne")))
|
|
239
241
|
)
|
|
240
242
|
|
|
241
243
|
export const updateMany: {
|
|
@@ -266,7 +268,7 @@ export const updateMany: {
|
|
|
266
268
|
Array.isArray(update) ? [...update] : update as UpdateFilter<Document>,
|
|
267
269
|
options
|
|
268
270
|
)
|
|
269
|
-
).pipe(
|
|
271
|
+
).pipe(mongoOperation(errorSource(collection, "updateMany")))
|
|
270
272
|
)
|
|
271
273
|
|
|
272
274
|
export const replaceOne: {
|
|
@@ -300,7 +302,7 @@ export const replaceOne: {
|
|
|
300
302
|
Effect.flatMap((replacement) =>
|
|
301
303
|
Effect.promise(() => collection.collection.replaceOne(filter, replacement, options))
|
|
302
304
|
),
|
|
303
|
-
|
|
305
|
+
mongoOperation(errorSource(collection, "replaceOne"))
|
|
304
306
|
)
|
|
305
307
|
)
|
|
306
308
|
|
|
@@ -371,9 +373,7 @@ export const findOneAndReplace: {
|
|
|
371
373
|
return yield* SchemaExt.decodeNullableDocument(collection.schema, value)
|
|
372
374
|
})
|
|
373
375
|
),
|
|
374
|
-
|
|
375
|
-
mongoErrorOrDie(errorSource(collection, "findOneAndReplace"))
|
|
376
|
-
)
|
|
376
|
+
mongoOperation(errorSource(collection, "findOneAndReplace"))
|
|
377
377
|
)
|
|
378
378
|
)
|
|
379
379
|
|
|
@@ -455,9 +455,7 @@ export const findOneAndUpdate: {
|
|
|
455
455
|
return yield* SchemaExt.decodeNullableDocument(collection.schema, value)
|
|
456
456
|
})
|
|
457
457
|
),
|
|
458
|
-
|
|
459
|
-
mongoErrorOrDie(errorSource(collection, "findOneAndUpdate"))
|
|
460
|
-
)
|
|
458
|
+
mongoOperation(errorSource(collection, "findOneAndUpdate"))
|
|
461
459
|
)
|
|
462
460
|
)
|
|
463
461
|
|
|
@@ -482,7 +480,7 @@ export const rename: {
|
|
|
482
480
|
Effect.map((newCollection) =>
|
|
483
481
|
new CollectionImpl<A, I, R>({ collection: newCollection, schema: collection.schema })
|
|
484
482
|
),
|
|
485
|
-
|
|
483
|
+
mongoOperation(errorSource(collection, "rename"))
|
|
486
484
|
)
|
|
487
485
|
)
|
|
488
486
|
|
|
@@ -502,7 +500,7 @@ export const drop: {
|
|
|
502
500
|
): Effect.Effect<boolean, MongoError.MongoError, R> =>
|
|
503
501
|
F.pipe(
|
|
504
502
|
Effect.promise(() => collection.collection.drop(options)),
|
|
505
|
-
|
|
503
|
+
mongoOperation(errorSource(collection, "drop"))
|
|
506
504
|
)
|
|
507
505
|
)
|
|
508
506
|
|
|
@@ -527,7 +525,7 @@ export const createIndexes: {
|
|
|
527
525
|
): Effect.Effect<Array<string>, MongoError.MongoError, R> =>
|
|
528
526
|
F.pipe(
|
|
529
527
|
Effect.promise(() => collection.collection.createIndexes([...indexSpecs], options)),
|
|
530
|
-
|
|
528
|
+
mongoOperation(errorSource(collection, "createIndexes"))
|
|
531
529
|
)
|
|
532
530
|
)
|
|
533
531
|
|
|
@@ -549,7 +547,7 @@ export const createIndex: {
|
|
|
549
547
|
): Effect.Effect<string, MongoError.MongoError, R> =>
|
|
550
548
|
F.pipe(
|
|
551
549
|
Effect.promise(() => collection.collection.createIndex(indexSpec, options)),
|
|
552
|
-
|
|
550
|
+
mongoOperation(errorSource(collection, "createIndex"))
|
|
553
551
|
)
|
|
554
552
|
)
|
|
555
553
|
|
|
@@ -571,7 +569,7 @@ export const dropIndex: {
|
|
|
571
569
|
): Effect.Effect<Document, MongoError.MongoError, R> =>
|
|
572
570
|
F.pipe(
|
|
573
571
|
Effect.promise(() => collection.collection.dropIndex(indexName, options)),
|
|
574
|
-
|
|
572
|
+
mongoOperation(errorSource(collection, "dropIndex"))
|
|
575
573
|
)
|
|
576
574
|
)
|
|
577
575
|
|
|
@@ -591,7 +589,7 @@ export const dropIndexes: {
|
|
|
591
589
|
): Effect.Effect<boolean, MongoError.MongoError, R> =>
|
|
592
590
|
F.pipe(
|
|
593
591
|
Effect.promise(() => collection.collection.dropIndexes(options)),
|
|
594
|
-
|
|
592
|
+
mongoOperation(errorSource(collection, "dropIndexes"))
|
|
595
593
|
)
|
|
596
594
|
)
|
|
597
595
|
|
|
@@ -639,7 +637,7 @@ export const estimatedDocumentCount: {
|
|
|
639
637
|
): Effect.Effect<number, MongoError.MongoError, R> =>
|
|
640
638
|
F.pipe(
|
|
641
639
|
Effect.promise(() => collection.collection.estimatedDocumentCount(options)),
|
|
642
|
-
|
|
640
|
+
mongoOperation(errorSource(collection, "estimatedDocumentCount"))
|
|
643
641
|
)
|
|
644
642
|
)
|
|
645
643
|
|
|
@@ -661,7 +659,7 @@ export const countDocuments: {
|
|
|
661
659
|
): Effect.Effect<number, MongoError.MongoError, R> =>
|
|
662
660
|
F.pipe(
|
|
663
661
|
Effect.promise(() => collection.collection.countDocuments(filter, options)),
|
|
664
|
-
|
|
662
|
+
mongoOperation(errorSource(collection, "countDocuments"))
|
|
665
663
|
)
|
|
666
664
|
)
|
|
667
665
|
|
|
@@ -688,7 +686,7 @@ export const bulkWrite: {
|
|
|
688
686
|
operations,
|
|
689
687
|
Effect.forEach((op) => encodeBulkWriteOperation(collection.schema, op)),
|
|
690
688
|
Effect.flatMap((operations) => Effect.promise(() => collection.collection.bulkWrite(operations, options))),
|
|
691
|
-
|
|
689
|
+
mongoOperation(errorSource(collection, "bulkWrite"))
|
|
692
690
|
)
|
|
693
691
|
)
|
|
694
692
|
|
|
@@ -699,7 +697,7 @@ const errorSource = <A extends Document, I extends Document = A, R = never>(
|
|
|
699
697
|
functionName: string
|
|
700
698
|
) =>
|
|
701
699
|
new MongoError.CollectionErrorSource({
|
|
702
|
-
module:
|
|
700
|
+
module: "Collection",
|
|
703
701
|
functionName,
|
|
704
702
|
db: collection.collection.dbName,
|
|
705
703
|
collection: collection.collection.collectionName
|
package/src/Db.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type * as Schema from "effect/Schema"
|
|
|
8
8
|
import type { Db as Db_, Document, DropCollectionOptions, ListCollectionsOptions } from "mongodb"
|
|
9
9
|
import type * as Collection from "./Collection.js"
|
|
10
10
|
import * as DocumentCollection from "./DocumentCollection.js"
|
|
11
|
-
import {
|
|
11
|
+
import { mongoOperation } from "./internal/mongo-operation.js"
|
|
12
12
|
import * as ListCollectionsCursor from "./ListCollectionsCursor.js"
|
|
13
13
|
import * as MongoError from "./MongoError.js"
|
|
14
14
|
|
|
@@ -82,7 +82,7 @@ export const dropCollection: {
|
|
|
82
82
|
(db: Db, name: string, options?: DropCollectionOptions): Effect.Effect<boolean, MongoError.MongoError> =>
|
|
83
83
|
F.pipe(
|
|
84
84
|
Effect.promise(() => db.db.dropCollection(name, options)),
|
|
85
|
-
|
|
85
|
+
mongoOperation(errorSource(db, "dropCollection"))
|
|
86
86
|
)
|
|
87
87
|
)
|
|
88
88
|
|
|
@@ -8,7 +8,7 @@ import type { Pipeable } from "effect/Pipeable"
|
|
|
8
8
|
import { pipeArguments } from "effect/Pipeable"
|
|
9
9
|
import * as Stream from "effect/Stream"
|
|
10
10
|
import type { AggregationCursor as MongoAggregationCursor, Document } from "mongodb"
|
|
11
|
-
import {
|
|
11
|
+
import { mongoOperation, mongoStreamOperation } from "./internal/mongo-operation.js"
|
|
12
12
|
import * as MongoError from "./MongoError.js"
|
|
13
13
|
|
|
14
14
|
type DocumentAggregationCursorFields = { cursor: MongoAggregationCursor<Document> }
|
|
@@ -32,7 +32,7 @@ export const toArray = (
|
|
|
32
32
|
): Effect.Effect<Array<Document>, MongoError.MongoError> =>
|
|
33
33
|
F.pipe(
|
|
34
34
|
Effect.promise(() => cursor.cursor.toArray()),
|
|
35
|
-
|
|
35
|
+
mongoOperation(errorSource(cursor, "toArray"))
|
|
36
36
|
)
|
|
37
37
|
|
|
38
38
|
export const toStream = (
|
|
@@ -40,12 +40,12 @@ export const toStream = (
|
|
|
40
40
|
): Stream.Stream<Document, MongoError.MongoError> =>
|
|
41
41
|
F.pipe(
|
|
42
42
|
Stream.fromAsyncIterable(cursor.cursor, F.identity),
|
|
43
|
-
|
|
43
|
+
mongoStreamOperation(errorSource(cursor, "toStream"))
|
|
44
44
|
)
|
|
45
45
|
|
|
46
46
|
const errorSource = (cursor: DocumentAggregationCursor, functionName: string) =>
|
|
47
47
|
new MongoError.CollectionErrorSource({
|
|
48
|
-
module:
|
|
48
|
+
module: "DocumentAggregationCursor",
|
|
49
49
|
functionName,
|
|
50
50
|
db: cursor.cursor.namespace.db,
|
|
51
51
|
collection: cursor.cursor.namespace.collection ?? "NO_COLLECTION_NAME"
|