@effect-mongodb/services 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/DbInstance/package.json +6 -0
- package/DbService/package.json +6 -0
- package/LICENSE +21 -0
- package/MongoClientService/package.json +6 -0
- package/README.md +55 -0
- package/dist/cjs/DbInstance.js +51 -0
- package/dist/cjs/DbInstance.js.map +1 -0
- package/dist/cjs/DbService.js +26 -0
- package/dist/cjs/DbService.js.map +1 -0
- package/dist/cjs/MongoClientService.js +31 -0
- package/dist/cjs/MongoClientService.js.map +1 -0
- package/dist/cjs/index.js +15 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/dts/DbInstance.d.ts +25 -0
- package/dist/dts/DbInstance.d.ts.map +1 -0
- package/dist/dts/DbService.d.ts +16 -0
- package/dist/dts/DbService.d.ts.map +1 -0
- package/dist/dts/MongoClientService.d.ts +16 -0
- package/dist/dts/MongoClientService.d.ts.map +1 -0
- package/dist/dts/index.d.ts +13 -0
- package/dist/dts/index.d.ts.map +1 -0
- package/dist/esm/DbInstance.js +39 -0
- package/dist/esm/DbInstance.js.map +1 -0
- package/dist/esm/DbService.js +15 -0
- package/dist/esm/DbService.js.map +1 -0
- package/dist/esm/MongoClientService.js +18 -0
- package/dist/esm/MongoClientService.js.map +1 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +4 -0
- package/package.json +61 -0
- package/src/DbInstance.ts +56 -0
- package/src/DbService.ts +42 -0
- package/src/MongoClientService.ts +43 -0
- package/src/index.ts +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present doubleloop.io
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @effect-mongodb/services
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
[Effect](https://github.com/Effect-TS/effect/) services for [effect-mongodb](../effect-mongodb/README.md).
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```shell
|
|
13
|
+
pnpm install @effect-mongodb/services effect-mongodb effect mongodb
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Note that `effect-mongodb`, `effect`, and `mongodb` are requested as peer dependencies.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
Here is a simple example of how to use this package:
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { DbInstance, DbService } from "@effect-mongodb/services"
|
|
24
|
+
import { Effect, Schema } from "effect"
|
|
25
|
+
import { Collection, Db, FindCursor } from "effect-mongodb"
|
|
26
|
+
|
|
27
|
+
const Person = Schema.Struct({ name: Schema.String, age: Schema.Number, birthday: Schema.Date })
|
|
28
|
+
|
|
29
|
+
// 1. Create your database service tag
|
|
30
|
+
const Database = DbService.Tag("Database")
|
|
31
|
+
|
|
32
|
+
const program = Effect.gen(function* () {
|
|
33
|
+
// 2. Use your database service
|
|
34
|
+
const db = yield* Database
|
|
35
|
+
const sourceCollection = Db.collection(db, "source", Person)
|
|
36
|
+
const destinationCollection = Db.collection(db, "destination", Person)
|
|
37
|
+
|
|
38
|
+
const items = yield* Collection.find(sourceCollection).pipe(FindCursor.toArray)
|
|
39
|
+
yield* Collection.insertMany(destinationCollection, items)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
// 3. Create a layer for your service, using DbInstance higher-level API
|
|
43
|
+
const DatabaseLive = DbInstance.layer(
|
|
44
|
+
Database,
|
|
45
|
+
{ database: { name: "mydb" }, client: { url: "mongodb://localhost:27017" } }
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
await program.pipe(
|
|
49
|
+
// 4. Provide the layer to your program
|
|
50
|
+
Effect.provide(DatabaseLive),
|
|
51
|
+
Effect.runPromise
|
|
52
|
+
)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Find more examples in the [examples](./examples) folder.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.layerEffect = exports.layer = exports.fromMongoClient = void 0;
|
|
7
|
+
var MongoClient = _interopRequireWildcard(require("effect-mongodb/MongoClient"));
|
|
8
|
+
var Effect = _interopRequireWildcard(require("effect/Effect"));
|
|
9
|
+
var F = _interopRequireWildcard(require("effect/Function"));
|
|
10
|
+
var Layer = _interopRequireWildcard(require("effect/Layer"));
|
|
11
|
+
var DbService = _interopRequireWildcard(require("./DbService.js"));
|
|
12
|
+
var MongoClientService = _interopRequireWildcard(require("./MongoClientService.js"));
|
|
13
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
+
/**
|
|
16
|
+
* @since 0.0.1
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const layerEffect = (dbTag, options) => F.pipe(options, Effect.map(options => layer(dbTag, options)), Layer.unwrapEffect);
|
|
20
|
+
exports.layerEffect = layerEffect;
|
|
21
|
+
const layer = (dbTag, options) => {
|
|
22
|
+
const {
|
|
23
|
+
name: databaseName,
|
|
24
|
+
...databaseOptions
|
|
25
|
+
} = options.database;
|
|
26
|
+
const {
|
|
27
|
+
url: clientUrl,
|
|
28
|
+
...clientOptions
|
|
29
|
+
} = options.client;
|
|
30
|
+
const dbLayer = DbService.layer(dbTag, DefaultMongoClient, databaseName, databaseOptions);
|
|
31
|
+
const defaultClientLayer = MongoClientService.layer(DefaultMongoClient, clientUrl, clientOptions);
|
|
32
|
+
return dbLayer.pipe(Layer.provide(defaultClientLayer));
|
|
33
|
+
};
|
|
34
|
+
exports.layer = layer;
|
|
35
|
+
const fromMongoClient = (dbTag, options) => Layer.effect(dbTag, Effect.gen(function* () {
|
|
36
|
+
const {
|
|
37
|
+
client: client_,
|
|
38
|
+
database: {
|
|
39
|
+
name,
|
|
40
|
+
...dbOptions
|
|
41
|
+
}
|
|
42
|
+
} = yield* options;
|
|
43
|
+
const client = new MongoClient.MongoClient({
|
|
44
|
+
client: client_
|
|
45
|
+
});
|
|
46
|
+
const db = MongoClient.db(client, name, dbOptions);
|
|
47
|
+
return dbTag.of(db);
|
|
48
|
+
}));
|
|
49
|
+
exports.fromMongoClient = fromMongoClient;
|
|
50
|
+
const DefaultMongoClient = /*#__PURE__*/MongoClientService.Tag("@effect-mongodb/services/DefaultMongoClient");
|
|
51
|
+
//# sourceMappingURL=DbInstance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DbInstance.js","names":["MongoClient","_interopRequireWildcard","require","Effect","F","Layer","DbService","MongoClientService","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","layerEffect","dbTag","options","pipe","map","layer","unwrapEffect","exports","name","databaseName","databaseOptions","database","url","clientUrl","clientOptions","client","dbLayer","DefaultMongoClient","defaultClientLayer","provide","fromMongoClient","effect","gen","client_","dbOptions","db","of","Tag"],"sources":["../../src/DbInstance.ts"],"sourcesContent":[null],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAF,uBAAA,CAAAC,OAAA;AACA,IAAAE,CAAA,GAAAH,uBAAA,CAAAC,OAAA;AACA,IAAAG,KAAA,GAAAJ,uBAAA,CAAAC,OAAA;AAEA,IAAAI,SAAA,GAAAL,uBAAA,CAAAC,OAAA;AACA,IAAAK,kBAAA,GAAAN,uBAAA,CAAAC,OAAA;AAA6D,SAAAM,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAR,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2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.layerEffect = exports.layer = exports.Tag = void 0;
|
|
7
|
+
var MongoClient = _interopRequireWildcard(require("effect-mongodb/MongoClient"));
|
|
8
|
+
var Context = _interopRequireWildcard(require("effect/Context"));
|
|
9
|
+
var Effect = _interopRequireWildcard(require("effect/Effect"));
|
|
10
|
+
var Layer = _interopRequireWildcard(require("effect/Layer"));
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
+
const Tag = key => Context.GenericTag(key);
|
|
14
|
+
exports.Tag = Tag;
|
|
15
|
+
const layerEffect = (dbTag, clientTag, dbName, options) => Effect.gen(function* () {
|
|
16
|
+
const dbname_ = yield* dbName;
|
|
17
|
+
return layer(dbTag, clientTag, dbname_, options);
|
|
18
|
+
}).pipe(Layer.unwrapEffect);
|
|
19
|
+
exports.layerEffect = layerEffect;
|
|
20
|
+
const layer = (dbTag, clientTag, dbName, options) => Layer.effect(dbTag, Effect.gen(function* () {
|
|
21
|
+
const client = yield* clientTag;
|
|
22
|
+
const db = MongoClient.db(client, dbName, options);
|
|
23
|
+
return dbTag.of(db); // TODO fix cast using branded ctor
|
|
24
|
+
}));
|
|
25
|
+
exports.layer = layer;
|
|
26
|
+
//# sourceMappingURL=DbService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DbService.js","names":["MongoClient","_interopRequireWildcard","require","Context","Effect","Layer","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","Tag","key","GenericTag","exports","layerEffect","dbTag","clientTag","dbName","options","gen","dbname_","layer","pipe","unwrapEffect","effect","client","db","of"],"sources":["../../src/DbService.ts"],"sourcesContent":[null],"mappings":";;;;;;AAIA,IAAAA,WAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAF,uBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,uBAAA,CAAAC,OAAA;AACA,IAAAG,KAAA,GAAAJ,uBAAA,CAAAC,OAAA;AAAqC,SAAAI,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAN,wBAAAM,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,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A,CAAAQ,KAAA,GAAAA,KAAA","ignoreList":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.layerEffect = exports.layer = exports.fromMongoClient = exports.Tag = void 0;
|
|
7
|
+
var MongoClient = _interopRequireWildcard(require("effect-mongodb/MongoClient"));
|
|
8
|
+
var Context = _interopRequireWildcard(require("effect/Context"));
|
|
9
|
+
var Effect = _interopRequireWildcard(require("effect/Effect"));
|
|
10
|
+
var Layer = _interopRequireWildcard(require("effect/Layer"));
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
+
/**
|
|
14
|
+
* @since 0.0.1
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const Tag = key => Context.GenericTag(key);
|
|
18
|
+
exports.Tag = Tag;
|
|
19
|
+
const layerEffect = (clientTag, url, options) => Effect.gen(function* () {
|
|
20
|
+
const url_ = yield* url;
|
|
21
|
+
return layer(clientTag, url_, options);
|
|
22
|
+
}).pipe(Layer.unwrapEffect);
|
|
23
|
+
exports.layerEffect = layerEffect;
|
|
24
|
+
const layer = (clientTag, url, options) => Layer.scopedContext(Effect.gen(function* () {
|
|
25
|
+
const client = yield* MongoClient.connectScoped(url, options);
|
|
26
|
+
return Context.make(clientTag, client);
|
|
27
|
+
}));
|
|
28
|
+
exports.layer = layer;
|
|
29
|
+
const fromMongoClient = (clientTag, mongoClient) => Layer.effect(clientTag, Effect.map(mongoClient, client => client));
|
|
30
|
+
exports.fromMongoClient = fromMongoClient;
|
|
31
|
+
//# sourceMappingURL=MongoClientService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoClientService.js","names":["MongoClient","_interopRequireWildcard","require","Context","Effect","Layer","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","Tag","key","GenericTag","exports","layerEffect","clientTag","url","options","gen","url_","layer","pipe","unwrapEffect","scopedContext","client","connectScoped","make","fromMongoClient","mongoClient","effect","map"],"sources":["../../src/MongoClientService.ts"],"sourcesContent":[null],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,OAAA,GAAAF,uBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,uBAAA,CAAAC,OAAA;AACA,IAAAG,KAAA,GAAAJ,uBAAA,CAAAC,OAAA;AAAqC,SAAAI,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAN,wBAAAM,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAA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M,GAAG,OAAOxC,WAAW,CAACyC,aAAa,CAACT,GAAG,EAAEC,OAAO,CAAC;EAC7D,OAAO9B,OAAO,CAACuC,IAAI,CAACX,SAAS,EAAES,MAA0C,CAAC;AAC5E,CAAC,CAAC,CAAC;AAAAX,OAAA,CAAAO,KAAA,GAAAA,KAAA;AAEE,MAAMO,eAAe,GAAGA,CAC7BZ,SAA4B,EAC5Ba,WAAyD,KAEzDvC,KAAK,CAACwC,MAAM,CACVd,SAAS,EACT3B,MAAM,CAAC0C,GAAG,CAACF,WAAW,EAAGJ,MAAM,IAAKA,MAA0C,CAAC,CAChF;AAAAX,OAAA,CAAAc,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MongoClientService = exports.DbService = exports.DbInstance = void 0;
|
|
7
|
+
var _DbInstance = _interopRequireWildcard(require("./DbInstance.js"));
|
|
8
|
+
exports.DbInstance = _DbInstance;
|
|
9
|
+
var _DbService = _interopRequireWildcard(require("./DbService.js"));
|
|
10
|
+
exports.DbService = _DbService;
|
|
11
|
+
var _MongoClientService = _interopRequireWildcard(require("./MongoClientService.js"));
|
|
12
|
+
exports.MongoClientService = _MongoClientService;
|
|
13
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.0.1
|
|
3
|
+
*/
|
|
4
|
+
import * as MongoClient from "effect-mongodb/MongoClient";
|
|
5
|
+
import type * as MongoError from "effect-mongodb/MongoError";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Layer from "effect/Layer";
|
|
8
|
+
import type { DbOptions, MongoClient as MongoClient_ } from "mongodb";
|
|
9
|
+
import * as DbService from "./DbService.js";
|
|
10
|
+
type DbInstanceOptions = {
|
|
11
|
+
database: DbOptions & {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
14
|
+
client: MongoClient.MongoClientScopedOptions & {
|
|
15
|
+
url: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare const layerEffect: <DbK extends string, E = never, R = never>(dbTag: DbService.Tag<DbK>, options: Effect.Effect<DbInstanceOptions, E, R>) => Layer.Layer<DbService.DbService<DbK>, MongoError.MongoError | E, R>;
|
|
19
|
+
export declare const layer: <DbK extends string>(dbTag: DbService.Tag<DbK>, options: DbInstanceOptions) => Layer.Layer<DbService.DbService<DbK>, MongoError.MongoError>;
|
|
20
|
+
type DbInstanceOptionsWithClient = Pick<DbInstanceOptions, "database"> & {
|
|
21
|
+
client: MongoClient_;
|
|
22
|
+
};
|
|
23
|
+
export declare const fromMongoClient: <DbK extends string, E = never, R = never>(dbTag: DbService.Tag<DbK>, options: Effect.Effect<DbInstanceOptionsWithClient, E, R>) => Layer.Layer<DbService.DbService<DbK>, E, R>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=DbInstance.d.ts.map
|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YAAY,CAAA;CAAE,CAAA;AAEjG,eAAO,MAAM,eAAe,GAAI,GAAG,SAAS,MAAM,EAAE,CAAC,UAAU,CAAC,iBACvD,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,WAChB,MAAM,CAAC,MAAM,CAAC,2BAA2B,EAAE,CAAC,EAAE,CAAC,CAAC,KACxD,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAS1C,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.0.1
|
|
3
|
+
*/
|
|
4
|
+
import type * as Db from "effect-mongodb/Db";
|
|
5
|
+
import type * as Brand from "effect/Brand";
|
|
6
|
+
import * as Context from "effect/Context";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Layer from "effect/Layer";
|
|
9
|
+
import type { DbOptions } from "mongodb";
|
|
10
|
+
import type * as MongoClientService from "./MongoClientService.js";
|
|
11
|
+
export type DbService<K extends string> = Db.Db & Brand.Brand<K>;
|
|
12
|
+
export type Tag<K extends string> = Context.Tag<DbService<K>, DbService<K>>;
|
|
13
|
+
export declare const Tag: <K extends string>(key: K) => Tag<K>;
|
|
14
|
+
export declare const layerEffect: <DbK extends string, MongoClientK extends string, E = never, R = never>(dbTag: Tag<DbK>, clientTag: MongoClientService.Tag<MongoClientK>, dbName: Effect.Effect<string, E, R>, options?: DbOptions) => Layer.Layer<DbService<DbK>, E, MongoClientService.MongoClientService<MongoClientK> | R>;
|
|
15
|
+
export declare const layer: <DbK extends string, MongoClientK extends string>(dbTag: Tag<DbK>, clientTag: MongoClientService.Tag<MongoClientK>, dbName: string, options?: DbOptions) => Layer.Layer<DbService<DbK>, never, MongoClientService.MongoClientService<MongoClientK>>;
|
|
16
|
+
//# sourceMappingURL=DbService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DbService.d.ts","sourceRo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,GAAG,CAAC,aACJ,kBAAkB,CAAC,GAAG,CAAC,YAAY,CAAC,UACvC,MAAM,YACJ,SAAS,KAClB,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,kBAAkB,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAQtF,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.0.1
|
|
3
|
+
*/
|
|
4
|
+
import * as MongoClient from "effect-mongodb/MongoClient";
|
|
5
|
+
import type * as MongoError from "effect-mongodb/MongoError";
|
|
6
|
+
import type * as Brand from "effect/Brand";
|
|
7
|
+
import * as Context from "effect/Context";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as Layer from "effect/Layer";
|
|
10
|
+
export type MongoClientService<K extends string> = MongoClient.MongoClient & Brand.Brand<K>;
|
|
11
|
+
export type Tag<K extends string> = Context.Tag<MongoClientService<K>, MongoClientService<K>>;
|
|
12
|
+
export declare const Tag: <K extends string>(key: K) => Tag<K>;
|
|
13
|
+
export declare const layerEffect: <MongoClientK extends string, E = never, R = never>(clientTag: Tag<MongoClientK>, url: Effect.Effect<string, E, R>, options?: MongoClient.MongoClientScopedOptions) => Layer.Layer<MongoClientService<MongoClientK>, MongoError.MongoError | E, R>;
|
|
14
|
+
export declare const layer: <MongoClientK extends string>(clientTag: Tag<MongoClientK>, url: string, options?: MongoClient.MongoClientScopedOptions) => Layer.Layer<MongoClientService<MongoClientK>, MongoError.MongoError>;
|
|
15
|
+
export declare const fromMongoClient: <MongoClientK extends string, E = never, R = never>(clientTag: Tag<MongoClientK>, mongoClient: Effect.Effect<MongoClient.MongoClient, E, R>) => Layer.Layer<MongoClientService<MongoClientK>, E, R>;
|
|
16
|
+
//# sourceMappingURL=MongoClientService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoClientService.d.ts","sourceRoot":"","sources":["../../src/MongoClient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AAI,YAAY,SAAS,MAAM,EAAE,CAAC,UAAU,CAAC,qBAC5D,GAAG,CAAC,YAAY,CAAC,eACf,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC,KACxD,KAAK,CAAC,KAAK,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC,CAIlD,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.0.1
|
|
3
|
+
*/
|
|
4
|
+
export * as DbInstance from "./DbInstance.js";
|
|
5
|
+
/**
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
*/
|
|
8
|
+
export * as DbService from "./DbService.js";
|
|
9
|
+
/**
|
|
10
|
+
* @since 0.0.1
|
|
11
|
+
*/
|
|
12
|
+
export * as MongoClientService from "./MongoClientService.js";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAE7C;;GAEG;AACH,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAE3C;;GAEG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.0.1
|
|
3
|
+
*/
|
|
4
|
+
import * as MongoClient from "effect-mongodb/MongoClient";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as F from "effect/Function";
|
|
7
|
+
import * as Layer from "effect/Layer";
|
|
8
|
+
import * as DbService from "./DbService.js";
|
|
9
|
+
import * as MongoClientService from "./MongoClientService.js";
|
|
10
|
+
export const layerEffect = (dbTag, options) => F.pipe(options, Effect.map(options => layer(dbTag, options)), Layer.unwrapEffect);
|
|
11
|
+
export const layer = (dbTag, options) => {
|
|
12
|
+
const {
|
|
13
|
+
name: databaseName,
|
|
14
|
+
...databaseOptions
|
|
15
|
+
} = options.database;
|
|
16
|
+
const {
|
|
17
|
+
url: clientUrl,
|
|
18
|
+
...clientOptions
|
|
19
|
+
} = options.client;
|
|
20
|
+
const dbLayer = DbService.layer(dbTag, DefaultMongoClient, databaseName, databaseOptions);
|
|
21
|
+
const defaultClientLayer = MongoClientService.layer(DefaultMongoClient, clientUrl, clientOptions);
|
|
22
|
+
return dbLayer.pipe(Layer.provide(defaultClientLayer));
|
|
23
|
+
};
|
|
24
|
+
export const fromMongoClient = (dbTag, options) => Layer.effect(dbTag, Effect.gen(function* () {
|
|
25
|
+
const {
|
|
26
|
+
client: client_,
|
|
27
|
+
database: {
|
|
28
|
+
name,
|
|
29
|
+
...dbOptions
|
|
30
|
+
}
|
|
31
|
+
} = yield* options;
|
|
32
|
+
const client = new MongoClient.MongoClient({
|
|
33
|
+
client: client_
|
|
34
|
+
});
|
|
35
|
+
const db = MongoClient.db(client, name, dbOptions);
|
|
36
|
+
return dbTag.of(db);
|
|
37
|
+
}));
|
|
38
|
+
const DefaultMongoClient = /*#__PURE__*/MongoClientService.Tag("@effect-mongodb/services/DefaultMongoClient");
|
|
39
|
+
//# sourceMappingURL=DbInstance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DbInstance.js","names":["MongoClient","Effect","F","Layer","DbService","MongoClientService","layerEffect","dbTag","options","pipe","map","layer","unwrapEffect","name","databaseName","databaseOptions","database","url","clientUrl","clientOptions","client","dbLayer","DefaultMongoClient","defaultClientLayer","provide","fromMongoClient","effect","gen","client_","dbOptions","db","of","Tag"],"sources":["../../src/DbInstance.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,WAAW,MAAM,4BAA4B;AAEzD,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,CAAC,MAAM,iBAAiB;AACpC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EAAEQ;EAAO,CAAE,CAAC;EAC/D,MAAME,EAAE,GAAG9B,WAAW,CAAC8B,EAAE,CAACV,MAAM,EAAEP,IAAI,EAAEgB,SAAS,CAAC;EAClD,OAAOtB,KAAK,CAACwB,EAAE,CAACD,EAA8B,CAAC;AACjD,CAAC,CAAC,CACH;AAEH,MAAMR,kBAAkB,gBAAGjB,kBAAkB,CAAC2B,GAAG,CAAC,6CAA6C,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as MongoClient from "effect-mongodb/MongoClient";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
export const Tag = key => Context.GenericTag(key);
|
|
6
|
+
export const layerEffect = (dbTag, clientTag, dbName, options) => Effect.gen(function* () {
|
|
7
|
+
const dbname_ = yield* dbName;
|
|
8
|
+
return layer(dbTag, clientTag, dbname_, options);
|
|
9
|
+
}).pipe(Layer.unwrapEffect);
|
|
10
|
+
export const layer = (dbTag, clientTag, dbName, options) => Layer.effect(dbTag, Effect.gen(function* () {
|
|
11
|
+
const client = yield* clientTag;
|
|
12
|
+
const db = MongoClient.db(client, dbName, options);
|
|
13
|
+
return dbTag.of(db); // TODO fix cast using branded ctor
|
|
14
|
+
}));
|
|
15
|
+
//# sourceMappingURL=DbService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DbService.js","names":["MongoClient","Context","Effect","Layer","Tag","key","GenericTag","layerEffect","dbTag","clientTag","dbName","options","gen","dbname_","layer","pipe","unwrapEffect","effect","client","db","of"],"sources":["../../src/DbService.ts"],"sourcesContent":[null],"mappings":"AAIA,OAAO,KAAKA,WAAW,MAAM,4BAA4B;AAEzD,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AAOrC,OAAO,MAAMC,GAAG,GAAsBC,GAAM,IAAaJ,OAAO,CAACK,UAAU,CAAeD,GAAG,CAAC;AAE9F,OAAO,MAAME,WAAW,GAAGA,CACzBC,KAAe,EACfC,SAA+C,EAC/CC,MAAmC,EACnCC,OAAmB,KAEnBT,MAAM,CAACU,GAAG,CAAC,aAAS;EAClB,MAAMC,OAAO,GAAG,OAAOH,MAAM;EAC7B,OAAOI,KAAK,CAACN,KAAK,EAAEC,SAAS,EAAEI,OAAO,EAAEF,OAAO,CAAC;AAClD,CAAC,CAAC,CAACI,IAAI,CAACZ,KAAK,CAACa,YAAY,CAAC;AAE7B,OAAO,MAAMF,KAAK,GAAGA,CACnBN,KAAe,EACfC,SAA+C,EAC/CC,MAAc,EACdC,OAAmB,KAEnBR,KAAK,CAACc,MAAM,CACVT,KAAK,EACLN,MAAM,CAACU,GAAG,CAAC,aAAS;EAClB,MAAMM,MAAM,GAAG,OAAOT,SAAS;EAC/B,MAAMU,EAAE,GAAGnB,WAAW,CAACmB,EAAE,CAACD,MAAM,EAAER,MAAM,EAAEC,OAAO,CAAC;EAClD,OAAOH,KAAK,CAACY,EAAE,CAACD,EAAoB,CAAC,EAAC;AACxC,CAAC,CAAC,CACH","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.0.1
|
|
3
|
+
*/
|
|
4
|
+
import * as MongoClient from "effect-mongodb/MongoClient";
|
|
5
|
+
import * as Context from "effect/Context";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Layer from "effect/Layer";
|
|
8
|
+
export const Tag = key => Context.GenericTag(key);
|
|
9
|
+
export const layerEffect = (clientTag, url, options) => Effect.gen(function* () {
|
|
10
|
+
const url_ = yield* url;
|
|
11
|
+
return layer(clientTag, url_, options);
|
|
12
|
+
}).pipe(Layer.unwrapEffect);
|
|
13
|
+
export const layer = (clientTag, url, options) => Layer.scopedContext(Effect.gen(function* () {
|
|
14
|
+
const client = yield* MongoClient.connectScoped(url, options);
|
|
15
|
+
return Context.make(clientTag, client);
|
|
16
|
+
}));
|
|
17
|
+
export const fromMongoClient = (clientTag, mongoClient) => Layer.effect(clientTag, Effect.map(mongoClient, client => client));
|
|
18
|
+
//# sourceMappingURL=MongoClientService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoClientService.js","names":["MongoClient","Context","Effect","Layer","Tag","key","GenericTag","layerEffect","clientTag","url","options","gen","url_","layer","pipe","unwrapEffect","scopedContext","client","connectScoped","make","fromMongoClient","mongoClient","effect","map"],"sources":["../../src/MongoClientService.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,WAAW,MAAM,4BAA4B;AAGzD,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AAKrC,OAAO,MAAMC,GAAG,GAAsBC,GAAM,IAAaJ,OAAO,CAACK,UAAU,CAAwBD,GAAG,CAAC;AAEvG,OAAO,MAAME,WAAW,GAAGA,CACzBC,SAA4B,EAC5BC,GAAgC,EAChCC,OAA8C,KAE9CR,MAAM,CAACS,GAAG,CAAC,aAAS;EAClB,MAAMC,IAAI,GAAG,OAAOH,GAAG;EACvB,OAAOI,KAAK,CAACL,SAAS,EAAEI,IAAI,EAAEF,OAAO,CAAC;AACxC,CAAC,CAAC,CAACI,IAAI,CAACX,KAAK,CAACY,YAAY,CAAC;AAE7B,OAAO,MAAMF,KAAK,GAAGA,CACnBL,SAA4B,EAC5BC,GAAW,EACXC,OAA8C,KAE9CP,KAAK,CAACa,aAAa,CAACd,MAAM,CAACS,GAAG,CAAC,aAAS;EACtC,MAAMM,MAAM,GAAG,OAAOjB,WAAW,CAACkB,aAAa,CAACT,GAAG,EAAEC,OAAO,CAAC;EAC7D,OAAOT,OAAO,CAACkB,IAAI,CAACX,SAAS,EAAES,MAA0C,CAAC;AAC5E,CAAC,CAAC,CAAC;AAEL,OAAO,MAAMG,eAAe,GAAGA,CAC7BZ,SAA4B,EAC5Ba,WAAyD,KAEzDlB,KAAK,CAACmB,MAAM,CACVd,SAAS,EACTN,MAAM,CAACqB,GAAG,CAACF,WAAW,EAAGJ,MAAM,IAAKA,MAA0C,CAAC,CAChF","ignoreList":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.0.1
|
|
3
|
+
*/
|
|
4
|
+
export * as DbInstance from "./DbInstance.js";
|
|
5
|
+
/**
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
*/
|
|
8
|
+
export * as DbService from "./DbService.js";
|
|
9
|
+
/**
|
|
10
|
+
* @since 0.0.1
|
|
11
|
+
*/
|
|
12
|
+
export * as MongoClientService from "./MongoClientService.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["DbInstance","DbService","MongoClientService"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,UAAU,MAAM,iBAAiB;AAE7C;;;AAGA,OAAO,KAAKC,SAAS,MAAM,gBAAgB;AAE3C;;;AAGA,OAAO,KAAKC,kBAAkB,MAAM,yBAAyB","ignoreList":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@effect-mongodb/services",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Effect services for effect-mongodb",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/doubleloop-io/effect-mongodb",
|
|
9
|
+
"directory": "packages/services"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": [],
|
|
12
|
+
"author": "doubleloop.io",
|
|
13
|
+
"homepage": "https://github.com/doubleloop-io/effect-mongodb",
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"effect": "^3.10.14",
|
|
16
|
+
"mongodb": "^6.9.0",
|
|
17
|
+
"effect-mongodb": "^0.2.0"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"provenance": true
|
|
21
|
+
},
|
|
22
|
+
"main": "./dist/cjs/index.js",
|
|
23
|
+
"module": "./dist/esm/index.js",
|
|
24
|
+
"types": "./dist/dts/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
"./package.json": "./package.json",
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/dts/index.d.ts",
|
|
29
|
+
"import": "./dist/esm/index.js",
|
|
30
|
+
"default": "./dist/cjs/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./DbInstance": {
|
|
33
|
+
"types": "./dist/dts/DbInstance.d.ts",
|
|
34
|
+
"import": "./dist/esm/DbInstance.js",
|
|
35
|
+
"default": "./dist/cjs/DbInstance.js"
|
|
36
|
+
},
|
|
37
|
+
"./DbService": {
|
|
38
|
+
"types": "./dist/dts/DbService.d.ts",
|
|
39
|
+
"import": "./dist/esm/DbService.js",
|
|
40
|
+
"default": "./dist/cjs/DbService.js"
|
|
41
|
+
},
|
|
42
|
+
"./MongoClientService": {
|
|
43
|
+
"types": "./dist/dts/MongoClientService.d.ts",
|
|
44
|
+
"import": "./dist/esm/MongoClientService.js",
|
|
45
|
+
"default": "./dist/cjs/MongoClientService.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"typesVersions": {
|
|
49
|
+
"*": {
|
|
50
|
+
"DbInstance": [
|
|
51
|
+
"./dist/dts/DbInstance.d.ts"
|
|
52
|
+
],
|
|
53
|
+
"DbService": [
|
|
54
|
+
"./dist/dts/DbService.d.ts"
|
|
55
|
+
],
|
|
56
|
+
"MongoClientService": [
|
|
57
|
+
"./dist/dts/MongoClientService.d.ts"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.0.1
|
|
3
|
+
*/
|
|
4
|
+
import * as MongoClient from "effect-mongodb/MongoClient"
|
|
5
|
+
import type * as MongoError from "effect-mongodb/MongoError"
|
|
6
|
+
import * as Effect from "effect/Effect"
|
|
7
|
+
import * as F from "effect/Function"
|
|
8
|
+
import * as Layer from "effect/Layer"
|
|
9
|
+
import type { DbOptions, MongoClient as MongoClient_ } from "mongodb"
|
|
10
|
+
import * as DbService from "./DbService.js"
|
|
11
|
+
import * as MongoClientService from "./MongoClientService.js"
|
|
12
|
+
|
|
13
|
+
type DbInstanceOptions = {
|
|
14
|
+
database: DbOptions & { name: string }
|
|
15
|
+
client: MongoClient.MongoClientScopedOptions & { url: string }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const layerEffect = <DbK extends string, E = never, R = never>(
|
|
19
|
+
dbTag: DbService.Tag<DbK>,
|
|
20
|
+
options: Effect.Effect<DbInstanceOptions, E, R>
|
|
21
|
+
): Layer.Layer<DbService.DbService<DbK>, MongoError.MongoError | E, R> =>
|
|
22
|
+
F.pipe(
|
|
23
|
+
options,
|
|
24
|
+
Effect.map((options) => layer(dbTag, options)),
|
|
25
|
+
Layer.unwrapEffect
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
export const layer = <DbK extends string>(
|
|
29
|
+
dbTag: DbService.Tag<DbK>,
|
|
30
|
+
options: DbInstanceOptions
|
|
31
|
+
): Layer.Layer<DbService.DbService<DbK>, MongoError.MongoError> => {
|
|
32
|
+
const { name: databaseName, ...databaseOptions } = options.database
|
|
33
|
+
const { url: clientUrl, ...clientOptions } = options.client
|
|
34
|
+
|
|
35
|
+
const dbLayer = DbService.layer(dbTag, DefaultMongoClient, databaseName, databaseOptions)
|
|
36
|
+
const defaultClientLayer = MongoClientService.layer(DefaultMongoClient, clientUrl, clientOptions)
|
|
37
|
+
return dbLayer.pipe(Layer.provide(defaultClientLayer))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type DbInstanceOptionsWithClient = Pick<DbInstanceOptions, "database"> & { client: MongoClient_ }
|
|
41
|
+
|
|
42
|
+
export const fromMongoClient = <DbK extends string, E = never, R = never>(
|
|
43
|
+
dbTag: DbService.Tag<DbK>,
|
|
44
|
+
options: Effect.Effect<DbInstanceOptionsWithClient, E, R>
|
|
45
|
+
): Layer.Layer<DbService.DbService<DbK>, E, R> =>
|
|
46
|
+
Layer.effect(
|
|
47
|
+
dbTag,
|
|
48
|
+
Effect.gen(function*() {
|
|
49
|
+
const { client: client_, database: { name, ...dbOptions } } = yield* options
|
|
50
|
+
const client = new MongoClient.MongoClient({ client: client_ })
|
|
51
|
+
const db = MongoClient.db(client, name, dbOptions)
|
|
52
|
+
return dbTag.of(db as DbService.DbService<DbK>)
|
|
53
|
+
})
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
const DefaultMongoClient = MongoClientService.Tag("@effect-mongodb/services/DefaultMongoClient")
|
package/src/DbService.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.0.1
|
|
3
|
+
*/
|
|
4
|
+
import type * as Db from "effect-mongodb/Db"
|
|
5
|
+
import * as MongoClient from "effect-mongodb/MongoClient"
|
|
6
|
+
import type * as Brand from "effect/Brand"
|
|
7
|
+
import * as Context from "effect/Context"
|
|
8
|
+
import * as Effect from "effect/Effect"
|
|
9
|
+
import * as Layer from "effect/Layer"
|
|
10
|
+
import type { DbOptions } from "mongodb"
|
|
11
|
+
import type * as MongoClientService from "./MongoClientService.js"
|
|
12
|
+
|
|
13
|
+
export type DbService<K extends string> = Db.Db & Brand.Brand<K>
|
|
14
|
+
|
|
15
|
+
export type Tag<K extends string> = Context.Tag<DbService<K>, DbService<K>>
|
|
16
|
+
export const Tag = <K extends string>(key: K): Tag<K> => Context.GenericTag<DbService<K>>(key)
|
|
17
|
+
|
|
18
|
+
export const layerEffect = <DbK extends string, MongoClientK extends string, E = never, R = never>(
|
|
19
|
+
dbTag: Tag<DbK>,
|
|
20
|
+
clientTag: MongoClientService.Tag<MongoClientK>,
|
|
21
|
+
dbName: Effect.Effect<string, E, R>,
|
|
22
|
+
options?: DbOptions
|
|
23
|
+
): Layer.Layer<DbService<DbK>, E, MongoClientService.MongoClientService<MongoClientK> | R> =>
|
|
24
|
+
Effect.gen(function*() {
|
|
25
|
+
const dbname_ = yield* dbName
|
|
26
|
+
return layer(dbTag, clientTag, dbname_, options)
|
|
27
|
+
}).pipe(Layer.unwrapEffect)
|
|
28
|
+
|
|
29
|
+
export const layer = <DbK extends string, MongoClientK extends string>(
|
|
30
|
+
dbTag: Tag<DbK>,
|
|
31
|
+
clientTag: MongoClientService.Tag<MongoClientK>,
|
|
32
|
+
dbName: string,
|
|
33
|
+
options?: DbOptions
|
|
34
|
+
): Layer.Layer<DbService<DbK>, never, MongoClientService.MongoClientService<MongoClientK>> =>
|
|
35
|
+
Layer.effect(
|
|
36
|
+
dbTag,
|
|
37
|
+
Effect.gen(function*() {
|
|
38
|
+
const client = yield* clientTag
|
|
39
|
+
const db = MongoClient.db(client, dbName, options)
|
|
40
|
+
return dbTag.of(db as DbService<DbK>) // TODO fix cast using branded ctor
|
|
41
|
+
})
|
|
42
|
+
)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.0.1
|
|
3
|
+
*/
|
|
4
|
+
import * as MongoClient from "effect-mongodb/MongoClient"
|
|
5
|
+
import type * as MongoError from "effect-mongodb/MongoError"
|
|
6
|
+
import type * as Brand from "effect/Brand"
|
|
7
|
+
import * as Context from "effect/Context"
|
|
8
|
+
import * as Effect from "effect/Effect"
|
|
9
|
+
import * as Layer from "effect/Layer"
|
|
10
|
+
|
|
11
|
+
export type MongoClientService<K extends string> = MongoClient.MongoClient & Brand.Brand<K>
|
|
12
|
+
|
|
13
|
+
export type Tag<K extends string> = Context.Tag<MongoClientService<K>, MongoClientService<K>>
|
|
14
|
+
export const Tag = <K extends string>(key: K): Tag<K> => Context.GenericTag<MongoClientService<K>>(key)
|
|
15
|
+
|
|
16
|
+
export const layerEffect = <MongoClientK extends string, E = never, R = never>(
|
|
17
|
+
clientTag: Tag<MongoClientK>,
|
|
18
|
+
url: Effect.Effect<string, E, R>,
|
|
19
|
+
options?: MongoClient.MongoClientScopedOptions
|
|
20
|
+
): Layer.Layer<MongoClientService<MongoClientK>, MongoError.MongoError | E, R> =>
|
|
21
|
+
Effect.gen(function*() {
|
|
22
|
+
const url_ = yield* url
|
|
23
|
+
return layer(clientTag, url_, options)
|
|
24
|
+
}).pipe(Layer.unwrapEffect)
|
|
25
|
+
|
|
26
|
+
export const layer = <MongoClientK extends string>(
|
|
27
|
+
clientTag: Tag<MongoClientK>,
|
|
28
|
+
url: string,
|
|
29
|
+
options?: MongoClient.MongoClientScopedOptions
|
|
30
|
+
): Layer.Layer<MongoClientService<MongoClientK>, MongoError.MongoError> =>
|
|
31
|
+
Layer.scopedContext(Effect.gen(function*() {
|
|
32
|
+
const client = yield* MongoClient.connectScoped(url, options)
|
|
33
|
+
return Context.make(clientTag, client as MongoClientService<MongoClientK>)
|
|
34
|
+
}))
|
|
35
|
+
|
|
36
|
+
export const fromMongoClient = <MongoClientK extends string, E = never, R = never>(
|
|
37
|
+
clientTag: Tag<MongoClientK>,
|
|
38
|
+
mongoClient: Effect.Effect<MongoClient.MongoClient, E, R>
|
|
39
|
+
): Layer.Layer<MongoClientService<MongoClientK>, E, R> =>
|
|
40
|
+
Layer.effect(
|
|
41
|
+
clientTag,
|
|
42
|
+
Effect.map(mongoClient, (client) => client as MongoClientService<MongoClientK>)
|
|
43
|
+
)
|
package/src/index.ts
ADDED