couchset 0.2.7 → 0.3.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 +284 -153
- package/dist/connection/connection.d.ts +68 -0
- package/dist/connection/connection.js +485 -0
- package/dist/connection/connection.js.map +1 -0
- package/dist/connection/env.d.ts +2 -0
- package/dist/connection/env.js +16 -0
- package/dist/connection/env.js.map +1 -0
- package/dist/connection/index.d.ts +3 -0
- package/dist/connection/index.js +25 -0
- package/dist/connection/index.js.map +1 -0
- package/dist/connection/types.d.ts +25 -0
- package/dist/connection/types.js +3 -0
- package/dist/connection/types.js.map +1 -0
- package/dist/database.d.ts +9 -0
- package/dist/database.js +196 -0
- package/dist/database.js.map +1 -0
- package/dist/index.d.ts +18 -6
- package/dist/index.js +53 -8
- package/dist/index.js.map +1 -1
- package/dist/legacy/connection.d.ts +2 -0
- package/dist/legacy/connection.js +24 -0
- package/dist/legacy/connection.js.map +1 -0
- package/dist/legacy/index.d.ts +10 -0
- package/dist/legacy/index.js +93 -0
- package/dist/legacy/index.js.map +1 -0
- package/dist/legacy/model.d.ts +55 -0
- package/dist/legacy/model.js +282 -0
- package/dist/legacy/model.js.map +1 -0
- package/dist/legacy/pagination/index.d.ts +1 -0
- package/dist/legacy/pagination/index.js +18 -0
- package/dist/legacy/pagination/index.js.map +1 -0
- package/dist/legacy/pagination/pagination.d.ts +12 -0
- package/dist/legacy/pagination/pagination.js +85 -0
- package/dist/legacy/pagination/pagination.js.map +1 -0
- package/dist/legacy/search/customQuery.d.ts +13 -0
- package/dist/legacy/search/customQuery.js +73 -0
- package/dist/legacy/search/customQuery.js.map +1 -0
- package/dist/legacy/search/index.d.ts +1 -0
- package/dist/legacy/search/index.js +18 -0
- package/dist/legacy/search/index.js.map +1 -0
- package/dist/model/default-scope.d.ts +10 -0
- package/dist/model/default-scope.js +47 -0
- package/dist/model/default-scope.js.map +1 -0
- package/dist/model/hydrated-document.d.ts +30 -0
- package/dist/model/hydrated-document.js +118 -0
- package/dist/model/hydrated-document.js.map +1 -0
- package/dist/model/include.d.ts +33 -0
- package/dist/model/include.js +250 -0
- package/dist/model/include.js.map +1 -0
- package/dist/model/index.d.ts +137 -51
- package/dist/model/index.js +519 -174
- package/dist/model/index.js.map +1 -1
- package/dist/model/indexes.d.ts +16 -0
- package/dist/model/indexes.js +155 -0
- package/dist/model/indexes.js.map +1 -0
- package/dist/model/keyspace.d.ts +9 -0
- package/dist/model/keyspace.js +28 -0
- package/dist/model/keyspace.js.map +1 -0
- package/dist/model/read-helpers.d.ts +36 -0
- package/dist/model/read-helpers.js +275 -0
- package/dist/model/read-helpers.js.map +1 -0
- package/dist/model/safe-query.d.ts +23 -0
- package/dist/model/safe-query.js +138 -0
- package/dist/model/safe-query.js.map +1 -0
- package/dist/model/ttl.d.ts +9 -0
- package/dist/model/ttl.js +73 -0
- package/dist/model/ttl.js.map +1 -0
- package/dist/model/validation.d.ts +5 -0
- package/dist/model/validation.js +104 -0
- package/dist/model/validation.js.map +1 -0
- package/dist/model/write-helpers.d.ts +31 -0
- package/dist/model/write-helpers.js +220 -0
- package/dist/model/write-helpers.js.map +1 -0
- package/dist/pagination/index.d.ts +1 -0
- package/dist/pagination/index.js +1 -0
- package/dist/pagination/index.js.map +1 -1
- package/dist/pagination/pagination.d.ts +1 -8
- package/dist/pagination/pagination.js +16 -29
- package/dist/pagination/pagination.js.map +1 -1
- package/dist/pagination/safe-pagination.d.ts +15 -0
- package/dist/pagination/safe-pagination.js +221 -0
- package/dist/pagination/safe-pagination.js.map +1 -0
- package/dist/pagination/types.d.ts +11 -0
- package/dist/pagination/types.js +3 -0
- package/dist/pagination/types.js.map +1 -0
- package/dist/search/customQuery.d.ts +10 -3
- package/dist/search/customQuery.js +17 -18
- package/dist/search/customQuery.js.map +1 -1
- package/dist/shared/common.model.js +2 -2
- package/dist/shared/common.model.js.map +1 -1
- package/dist/timeseries/index.d.ts +1 -0
- package/dist/timeseries/index.js +18 -0
- package/dist/timeseries/index.js.map +1 -0
- package/dist/timeseries/time-series-model.d.ts +60 -0
- package/dist/timeseries/time-series-model.js +267 -0
- package/dist/timeseries/time-series-model.js.map +1 -0
- package/dist/utils/awaitTo.d.ts +1 -1
- package/dist/utils/awaitTo.js +1 -1
- package/dist/utils/awaitTo.js.map +1 -1
- package/docs/beta-migration.md +175 -0
- package/legacy/index.js +1 -0
- package/legacy/package.json +4 -0
- package/next/index.js +1 -0
- package/next/package.json +4 -0
- package/package.json +13 -8
- package/dist/connection.d.ts +0 -42
- package/dist/connection.js +0 -156
- package/dist/connection.js.map +0 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# CouchSet Beta Migration
|
|
2
|
+
|
|
3
|
+
The beta release keeps the main `couchset` import on the legacy implementation so existing projects can upgrade safely. The modern implementation is available from `couchset/next`.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import {Model as LegacyModel} from 'couchset';
|
|
7
|
+
import {Model as NextModel} from 'couchset/next';
|
|
8
|
+
|
|
9
|
+
const legacyUsers = new LegacyModel('User');
|
|
10
|
+
const nextUsers = new NextModel('User');
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Use `couchset` when an application depends on old pagination or custom query behavior. New work should use `couchset/next`.
|
|
14
|
+
|
|
15
|
+
Modern and legacy models share the same connection singleton. Initialize CouchSet once and use both model APIs side by side while migrating.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import {couchset, Model} from 'couchset';
|
|
19
|
+
import {Model as NextModel} from 'couchset/next';
|
|
20
|
+
|
|
21
|
+
await couchset(args);
|
|
22
|
+
|
|
23
|
+
const legacyUsers = new Model('User');
|
|
24
|
+
const nextUsers = new NextModel('User');
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Connection Lifecycle
|
|
28
|
+
|
|
29
|
+
Models can be constructed before the Couchbase connection is ready. Model methods wait for the shared connection before touching the bucket or collection.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import {couchset, Model, ready, health, ping, shutdown} from 'couchset/next';
|
|
33
|
+
|
|
34
|
+
const users = new Model('User');
|
|
35
|
+
|
|
36
|
+
await couchset({
|
|
37
|
+
connectionString: process.env.COUCHBASE_URL || 'couchbase://localhost',
|
|
38
|
+
username: process.env.COUCHBASE_USERNAME || 'admin',
|
|
39
|
+
password: process.env.COUCHBASE_PASSWORD || '1234',
|
|
40
|
+
bucketName: process.env.COUCHBASE_BUCKET || 'dev',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
await ready();
|
|
44
|
+
await ping();
|
|
45
|
+
console.log(health());
|
|
46
|
+
|
|
47
|
+
await couchset.ready();
|
|
48
|
+
|
|
49
|
+
const user = await users.insert({userId: 'ceddy'});
|
|
50
|
+
|
|
51
|
+
await shutdown();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Reconnect is enabled by default. It can be controlled with connection args or environment variables.
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
await couchset({
|
|
58
|
+
connectionString: 'couchbase://localhost',
|
|
59
|
+
username: 'admin',
|
|
60
|
+
password: '1234',
|
|
61
|
+
bucketName: 'dev',
|
|
62
|
+
autoReconnect: true,
|
|
63
|
+
reconnectIntervalMs: 5000,
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Environment flags:
|
|
68
|
+
|
|
69
|
+
- `COUCHSET_RECONNECT`: defaults to enabled. Use `false`, `0`, or `no` to disable.
|
|
70
|
+
- `COUCHSET_RECONNECT_INTERVAL_MS`: reconnect and health-check interval in milliseconds. Defaults to `5000`.
|
|
71
|
+
|
|
72
|
+
`couchset/next` also exports env-based starter helpers:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import {startCouchbase, startCouchbaseServerless} from 'couchset/next';
|
|
76
|
+
|
|
77
|
+
await startCouchbase();
|
|
78
|
+
await startCouchbaseServerless();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The starters read `COUCHBASE_URL`, `COUCHBASE_BUCKET`, `COUCHBASE_USERNAME`, `COUCHBASE_PASSWORD`, and `COUCHBASE_PROXY`, and accept `CouchsetArgs` overrides.
|
|
82
|
+
|
|
83
|
+
## Query Behavior
|
|
84
|
+
|
|
85
|
+
Modern query helpers throw by default. This makes production failures visible and keeps silent fallbacks explicit.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
const rows = await users.findMany({
|
|
89
|
+
where: {userId: {$eq: 'ceddy'}},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const page = await users.page({
|
|
93
|
+
where: {userId: {$eq: 'ceddy'}},
|
|
94
|
+
limit: 25,
|
|
95
|
+
page: 0,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const customRows = await users.queryRows(
|
|
99
|
+
`SELECT * FROM ${users.bucket()} WHERE userId=$userId LIMIT $limit`,
|
|
100
|
+
{userId: 'ceddy', limit: 25}
|
|
101
|
+
);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
If a caller intentionally wants the old empty-result fallback, pass `throwOnError: false`.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
const rows = await users.findMany({
|
|
108
|
+
where: {userId: {$eq: 'ceddy'}},
|
|
109
|
+
limit: 25,
|
|
110
|
+
page: 0,
|
|
111
|
+
throwOnError: false,
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Safer SQL++ Helpers
|
|
116
|
+
|
|
117
|
+
Use the model keyspace helpers instead of hardcoding bucket names.
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
users.bucket(); // `dev`
|
|
121
|
+
users.from('u'); // `dev` AS u
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
For scoped collections, `from()` includes the full keyspace.
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
const audit = new Model('AuditEvent', {
|
|
128
|
+
scope: 'app',
|
|
129
|
+
collection: 'events',
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
audit.from('event'); // `dev`.`app`.`events` AS event
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## New Model APIs
|
|
136
|
+
|
|
137
|
+
The modern path includes safer read, write, document, TTL, include, index, and time series helpers.
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
await users.insert({id: 'user::1', userId: 'ceddy'});
|
|
141
|
+
await users.patchById('user::1', {$set: {email: 'ceddy@example.com'}});
|
|
142
|
+
await users.softDeleteById('user::1');
|
|
143
|
+
await users.restoreById('user::1');
|
|
144
|
+
|
|
145
|
+
const exists = await users.exists({where: {userId: {$eq: 'ceddy'}}});
|
|
146
|
+
const count = await users.count({where: {userId: {$eq: 'ceddy'}}});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Removed Modern Model Aliases
|
|
150
|
+
|
|
151
|
+
The old method names belong to the default `couchset` entrypoint and the explicit `couchset/legacy` alias.
|
|
152
|
+
|
|
153
|
+
| Old method | Modern method |
|
|
154
|
+
| --- | --- |
|
|
155
|
+
| `create()` | `insert()` or `upsert()` |
|
|
156
|
+
| `findById()` | `getById()` |
|
|
157
|
+
| `updateById()` / `save()` | `replaceById()` or `patchById()` |
|
|
158
|
+
| `delete()` | `deleteById()` |
|
|
159
|
+
| `pagination()` | `findMany()` or `page()` |
|
|
160
|
+
| `customQuery()` | `queryRows()`, `queryOne()`, or `queryPage()` |
|
|
161
|
+
|
|
162
|
+
Index declarations can live on the model and be created at app boot.
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
const users = new Model('User', {
|
|
166
|
+
indexes: [
|
|
167
|
+
{
|
|
168
|
+
name: 'idx_user_userId',
|
|
169
|
+
fields: ['userId'],
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
await couchset.ensureIndexes();
|
|
175
|
+
```
|
package/legacy/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/legacy');
|
package/next/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist');
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "couchset",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Couchbase ORM",
|
|
5
5
|
"private": false,
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "dist/legacy/index.js",
|
|
7
|
+
"types": "dist/legacy/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
9
|
"docs/",
|
|
10
10
|
"dist/",
|
|
11
|
+
"legacy/",
|
|
12
|
+
"next/",
|
|
11
13
|
"register/",
|
|
12
14
|
"LICENSE"
|
|
13
15
|
],
|
|
@@ -16,7 +18,6 @@
|
|
|
16
18
|
"build": "rimraf dist && ./node_modules/.bin/tsc --skipLibCheck",
|
|
17
19
|
"test": "mocha src/index.test.ts --exit",
|
|
18
20
|
"test:serverless": "mocha src/index.serverless.test.ts --exit",
|
|
19
|
-
"test:auto": "mocha src/automation.test.ts --exit",
|
|
20
21
|
"prepublishOnly": "npm run build",
|
|
21
22
|
"eslint": "eslint ./src --fix --ext=ts"
|
|
22
23
|
},
|
|
@@ -65,7 +66,7 @@
|
|
|
65
66
|
"@types/dotenv": "^6.1.1",
|
|
66
67
|
"@types/express": "^4.17.13",
|
|
67
68
|
"@types/lodash": "^4.17.10",
|
|
68
|
-
"@types/mocha": "^
|
|
69
|
+
"@types/mocha": "^10.0.10",
|
|
69
70
|
"@types/node": "^10.0.3",
|
|
70
71
|
"@types/source-map-support": "^0.4.0",
|
|
71
72
|
"@types/uuid": "^8.3.0",
|
|
@@ -83,7 +84,7 @@
|
|
|
83
84
|
"eslint-plugin-typescript": "^0.14.0",
|
|
84
85
|
"husky": "^4.2.5",
|
|
85
86
|
"lint-staged": "^10.1.7",
|
|
86
|
-
"mocha": "^
|
|
87
|
+
"mocha": "^11.3.0",
|
|
87
88
|
"prettier": "^2.0.5",
|
|
88
89
|
"reflect-metadata": "^0.1.13",
|
|
89
90
|
"rimraf": "^2.5.4",
|
|
@@ -94,10 +95,14 @@
|
|
|
94
95
|
"typescript": "^5.6.3"
|
|
95
96
|
},
|
|
96
97
|
"dependencies": {
|
|
97
|
-
"couchbase": "^4.
|
|
98
|
+
"couchbase": "^4.7.0",
|
|
98
99
|
"couchbase-serverless": "^0.0.4",
|
|
99
100
|
"debug": "^4.3.1",
|
|
100
|
-
"lodash": "^4.
|
|
101
|
+
"lodash": "^4.18.1",
|
|
101
102
|
"uuid": "^8.3.2"
|
|
103
|
+
},
|
|
104
|
+
"overrides": {
|
|
105
|
+
"serialize-javascript": "^7.0.5",
|
|
106
|
+
"js-yaml": "^4.1.1"
|
|
102
107
|
}
|
|
103
108
|
}
|
package/dist/connection.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { Collection, Cluster, Bucket } from 'couchbase';
|
|
2
|
-
export interface CouchsetArgs {
|
|
3
|
-
connectionString: string;
|
|
4
|
-
bucketName: string;
|
|
5
|
-
username: string;
|
|
6
|
-
password: string;
|
|
7
|
-
proxy?: string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* CouchbaseConnection class
|
|
11
|
-
* Only one CouchbaseConnection can exist that's why it's a singleton
|
|
12
|
-
*/
|
|
13
|
-
export declare class CouchbaseConnection implements CouchsetArgs {
|
|
14
|
-
private static _instance;
|
|
15
|
-
bucket: Bucket;
|
|
16
|
-
cluster: Cluster;
|
|
17
|
-
connectionString: string;
|
|
18
|
-
bucketName: string;
|
|
19
|
-
username: string;
|
|
20
|
-
password: string;
|
|
21
|
-
static get Instance(): CouchbaseConnection;
|
|
22
|
-
private constructor();
|
|
23
|
-
/**
|
|
24
|
-
* start
|
|
25
|
-
*/
|
|
26
|
-
init: (args: CouchsetArgs) => Promise<CouchbaseConnection>;
|
|
27
|
-
/**
|
|
28
|
-
* start serverless start
|
|
29
|
-
*/
|
|
30
|
-
initServerless: (args: CouchsetArgs) => CouchbaseConnection;
|
|
31
|
-
/**
|
|
32
|
-
* getCollection
|
|
33
|
-
*/
|
|
34
|
-
getCollection: () => Collection;
|
|
35
|
-
getCluster: () => Cluster;
|
|
36
|
-
getBucket: () => string;
|
|
37
|
-
/**
|
|
38
|
-
* shutdown cluster
|
|
39
|
-
*/
|
|
40
|
-
shutdown: () => Promise<void>;
|
|
41
|
-
}
|
|
42
|
-
export default CouchbaseConnection;
|
package/dist/connection.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
36
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
-
function step(op) {
|
|
39
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
-
switch (op[0]) {
|
|
44
|
-
case 0: case 1: t = op; break;
|
|
45
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
-
default:
|
|
49
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
-
if (t[2]) _.ops.pop();
|
|
54
|
-
_.trys.pop(); continue;
|
|
55
|
-
}
|
|
56
|
-
op = body.call(thisArg, _);
|
|
57
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
exports.CouchbaseConnection = void 0;
|
|
63
|
-
var couchbase = __importStar(require("couchbase"));
|
|
64
|
-
/**
|
|
65
|
-
* CouchbaseConnection class
|
|
66
|
-
* Only one CouchbaseConnection can exist that's why it's a singleton
|
|
67
|
-
*/
|
|
68
|
-
var CouchbaseConnection = /** @class */ (function () {
|
|
69
|
-
function CouchbaseConnection() {
|
|
70
|
-
var _this = this;
|
|
71
|
-
this.bucket = null;
|
|
72
|
-
this.cluster = null;
|
|
73
|
-
// Args
|
|
74
|
-
this.connectionString = null;
|
|
75
|
-
this.bucketName = null;
|
|
76
|
-
this.username = null;
|
|
77
|
-
this.password = null;
|
|
78
|
-
/**
|
|
79
|
-
* start
|
|
80
|
-
*/
|
|
81
|
-
this.init = function (args) { return __awaiter(_this, void 0, void 0, function () {
|
|
82
|
-
var connectionString, password, username, _a, bucketName, cluster;
|
|
83
|
-
return __generator(this, function (_b) {
|
|
84
|
-
switch (_b.label) {
|
|
85
|
-
case 0:
|
|
86
|
-
connectionString = args.connectionString, password = args.password, username = args.username, _a = args.bucketName, bucketName = _a === void 0 ? 'default' : _a;
|
|
87
|
-
this.connectionString = connectionString;
|
|
88
|
-
this.bucketName = bucketName;
|
|
89
|
-
this.username = username;
|
|
90
|
-
this.password = password;
|
|
91
|
-
return [4 /*yield*/, couchbase.connect(connectionString, {
|
|
92
|
-
username: username,
|
|
93
|
-
password: password,
|
|
94
|
-
})];
|
|
95
|
-
case 1:
|
|
96
|
-
cluster = _b.sent();
|
|
97
|
-
this.cluster = cluster;
|
|
98
|
-
this.bucket = this.cluster.bucket(bucketName);
|
|
99
|
-
return [2 /*return*/, this];
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}); };
|
|
103
|
-
/**
|
|
104
|
-
* start serverless start
|
|
105
|
-
*/
|
|
106
|
-
this.initServerless = function (args) {
|
|
107
|
-
var connectionString = args.connectionString, password = args.password, username = args.username, _a = args.bucketName, bucketName = _a === void 0 ? 'default' : _a;
|
|
108
|
-
_this.connectionString = connectionString;
|
|
109
|
-
_this.bucketName = bucketName;
|
|
110
|
-
_this.username = username;
|
|
111
|
-
_this.password = password;
|
|
112
|
-
var connectionOpt = {
|
|
113
|
-
username: username,
|
|
114
|
-
password: password,
|
|
115
|
-
};
|
|
116
|
-
if (args.proxy) {
|
|
117
|
-
connectionOpt['proxy'] = args.proxy;
|
|
118
|
-
}
|
|
119
|
-
var cluster = new couchbase.Cluster(connectionString, connectionOpt);
|
|
120
|
-
_this.cluster = cluster;
|
|
121
|
-
_this.bucket = _this.cluster.bucket(bucketName);
|
|
122
|
-
return _this;
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* getCollection
|
|
126
|
-
*/
|
|
127
|
-
this.getCollection = function () {
|
|
128
|
-
return _this.bucket.defaultCollection();
|
|
129
|
-
};
|
|
130
|
-
this.getCluster = function () {
|
|
131
|
-
return _this.cluster;
|
|
132
|
-
};
|
|
133
|
-
this.getBucket = function () {
|
|
134
|
-
return _this.bucketName;
|
|
135
|
-
};
|
|
136
|
-
/**
|
|
137
|
-
* shutdown cluster
|
|
138
|
-
*/
|
|
139
|
-
this.shutdown = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
140
|
-
return __generator(this, function (_a) {
|
|
141
|
-
return [2 /*return*/, this.cluster.close()];
|
|
142
|
-
});
|
|
143
|
-
}); };
|
|
144
|
-
}
|
|
145
|
-
Object.defineProperty(CouchbaseConnection, "Instance", {
|
|
146
|
-
get: function () {
|
|
147
|
-
return this._instance || (this._instance = new this());
|
|
148
|
-
},
|
|
149
|
-
enumerable: false,
|
|
150
|
-
configurable: true
|
|
151
|
-
});
|
|
152
|
-
return CouchbaseConnection;
|
|
153
|
-
}());
|
|
154
|
-
exports.CouchbaseConnection = CouchbaseConnection;
|
|
155
|
-
exports.default = CouchbaseConnection;
|
|
156
|
-
//# sourceMappingURL=connection.js.map
|
package/dist/connection.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"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","sourcesContent":["import type {Collection, Cluster, Bucket} from 'couchbase';\nimport * as couchbase from 'couchbase';\n\nexport interface CouchsetArgs {\n connectionString: string;\n bucketName: string;\n username: string;\n password: string;\n proxy?: string;\n}\n\n/**\n * CouchbaseConnection class\n * Only one CouchbaseConnection can exist that's why it's a singleton\n */\nexport class CouchbaseConnection implements CouchsetArgs {\n private static _instance: CouchbaseConnection;\n\n bucket: Bucket = null;\n cluster: Cluster = null;\n\n // Args\n connectionString: string = null;\n bucketName: string = null;\n username: string = null;\n password: string = null;\n\n public static get Instance(): CouchbaseConnection {\n return this._instance || (this._instance = new this());\n }\n\n private constructor() {}\n\n /**\n * start\n */\n public init = async (args: CouchsetArgs): Promise<CouchbaseConnection> => {\n const {connectionString, password, username, bucketName = 'default'} = args;\n\n this.connectionString = connectionString;\n this.bucketName = bucketName;\n this.username = username;\n this.password = password;\n\n const cluster = await couchbase.connect(connectionString, {\n username,\n password,\n });\n\n this.cluster = cluster as any;\n this.bucket = this.cluster.bucket(bucketName);\n\n return this;\n };\n\n /**\n * start serverless start\n */\n public initServerless = (args: CouchsetArgs): CouchbaseConnection => {\n const {connectionString, password, username, bucketName = 'default'} = args;\n\n this.connectionString = connectionString;\n this.bucketName = bucketName;\n this.username = username;\n this.password = password;\n\n const connectionOpt = {\n username,\n password,\n };\n\n if (args.proxy) {\n connectionOpt['proxy'] = args.proxy;\n }\n\n const cluster = new couchbase.Cluster(connectionString, connectionOpt);\n\n this.cluster = cluster as any;\n this.bucket = this.cluster.bucket(bucketName);\n\n return this;\n };\n\n /**\n * getCollection\n */\n public getCollection = (): Collection => {\n return this.bucket.defaultCollection();\n };\n\n public getCluster = (): Cluster => {\n return this.cluster;\n };\n\n public getBucket = (): string => {\n return this.bucketName;\n };\n\n /**\n * shutdown cluster\n */\n public shutdown = async (): Promise<void> => {\n return this.cluster.close();\n };\n}\n\nexport default CouchbaseConnection;\n"]}
|