couchset 0.0.0 → 0.0.5
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/LICENSE +21 -0
- package/README.md +231 -0
- package/dist/automate/index.d.ts +4 -0
- package/dist/automate/index.js +17 -0
- package/dist/automate/index.js.map +1 -0
- package/dist/automate/middlewares/index.d.ts +1 -0
- package/dist/automate/middlewares/index.js +14 -0
- package/dist/automate/middlewares/index.js.map +1 -0
- package/dist/automate/middlewares/isAuth.d.ts +7 -0
- package/dist/automate/middlewares/isAuth.js +28 -0
- package/dist/automate/middlewares/isAuth.js.map +1 -0
- package/dist/automate/model/client.d.ts +12 -0
- package/dist/automate/model/client.js +33 -0
- package/dist/automate/model/client.js.map +1 -0
- package/dist/automate/model/index.d.ts +44 -0
- package/dist/automate/model/index.js +304 -0
- package/dist/automate/model/index.js.map +1 -0
- package/dist/automate/morpheus/index.d.ts +14 -0
- package/dist/automate/morpheus/index.js +171 -0
- package/dist/automate/morpheus/index.js.map +1 -0
- package/dist/automate/writer/index.d.ts +10 -0
- package/dist/automate/writer/index.js +72 -0
- package/dist/automate/writer/index.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +8 -0
- package/dist/config/index.js.map +1 -0
- package/dist/connection.d.ts +36 -0
- package/dist/connection.js +129 -0
- package/dist/connection.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/dist/model/index.d.ts +107 -0
- package/dist/model/index.js +329 -0
- package/dist/model/index.js.map +1 -0
- package/dist/pagination/index.d.ts +1 -0
- package/dist/pagination/index.js +14 -0
- package/dist/pagination/index.js.map +1 -0
- package/dist/pagination/pagination.d.ts +19 -0
- package/dist/pagination/pagination.js +97 -0
- package/dist/pagination/pagination.js.map +1 -0
- package/dist/query/base-query.d.ts +17 -0
- package/dist/query/base-query.js +15 -0
- package/dist/query/base-query.js.map +1 -0
- package/dist/query/exceptions.d.ts +24 -0
- package/dist/query/exceptions.js +90 -0
- package/dist/query/exceptions.js.map +1 -0
- package/dist/query/helpers/builders.d.ts +64 -0
- package/dist/query/helpers/builders.js +415 -0
- package/dist/query/helpers/builders.js.map +1 -0
- package/dist/query/helpers/dictionary.d.ts +45 -0
- package/dist/query/helpers/dictionary.js +105 -0
- package/dist/query/helpers/dictionary.js.map +1 -0
- package/dist/query/helpers/index.d.ts +3 -0
- package/dist/query/helpers/index.js +16 -0
- package/dist/query/helpers/index.js.map +1 -0
- package/dist/query/helpers/reservedWords.d.ts +1 -0
- package/dist/query/helpers/reservedWords.js +200 -0
- package/dist/query/helpers/reservedWords.js.map +1 -0
- package/dist/query/index.d.ts +5 -0
- package/dist/query/index.js +27 -0
- package/dist/query/index.js.map +1 -0
- package/dist/query/interface/query.types.d.ts +236 -0
- package/dist/query/interface/query.types.js +3 -0
- package/dist/query/interface/query.types.js.map +1 -0
- package/dist/query/query.cluster.d.ts +14 -0
- package/dist/query/query.cluster.js +80 -0
- package/dist/query/query.cluster.js.map +1 -0
- package/dist/query/query.d.ts +321 -0
- package/dist/query/query.js +457 -0
- package/dist/query/query.js.map +1 -0
- package/dist/query/utils.d.ts +8 -0
- package/dist/query/utils.js +56 -0
- package/dist/query/utils.js.map +1 -0
- package/dist/search/customQuery.d.ts +17 -0
- package/dist/search/customQuery.js +83 -0
- package/dist/search/customQuery.js.map +1 -0
- package/dist/search/index.d.ts +1 -0
- package/dist/search/index.js +14 -0
- package/dist/search/index.js.map +1 -0
- package/dist/shared/ContextType.d.ts +27 -0
- package/dist/shared/ContextType.js +55 -0
- package/dist/shared/ContextType.js.map +1 -0
- package/dist/shared/common.model.d.ts +37 -0
- package/dist/shared/common.model.js +148 -0
- package/dist/shared/common.model.js.map +1 -0
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.js +15 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/utils/awaitTo.d.ts +17 -0
- package/dist/utils/awaitTo.js +31 -0
- package/dist/utils/awaitTo.js.map +1 -0
- package/dist/utils/date.d.ts +11 -0
- package/dist/utils/date.js +21 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +18 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/log.d.ts +9 -0
- package/dist/utils/log.js +19 -0
- package/dist/utils/log.js.map +1 -0
- package/dist/utils/text.utils.d.ts +14 -0
- package/dist/utils/text.utils.js +45 -0
- package/dist/utils/text.utils.js.map +1 -0
- package/dist/utils/utils.schema.d.ts +6 -0
- package/dist/utils/utils.schema.js +33 -0
- package/dist/utils/utils.schema.js.map +1 -0
- package/dist/uuid.d.ts +1 -0
- package/dist/uuid.js +9 -0
- package/dist/uuid.js.map +1 -0
- package/docs/couch.png +0 -0
- package/docs/couchset.png +0 -0
- package/docs/couchset_logo.png +0 -0
- package/package.json +108 -30
- package/register/index.js +1 -0
- package/register/transpile-only.js +3 -0
- package/register/type-check.js +3 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;AAAA,yBAAuB;AACvB,iCAAmC;AAEtB,QAAA,OAAO,GAAG,IAAA,YAAI,EAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;AACxC,QAAA,KAAK,GAAG,eAAO,KAAK,YAAY,CAAC","sourcesContent":["import 'dotenv/config';\nimport {get as _get} from 'lodash';\n\nexport const nodeEnv = _get(process.env, 'NODE_ENV');\nexport const isDev = nodeEnv !== 'production';\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Collection, Cluster, Bucket } from 'couchbase';
|
|
2
|
+
export interface CouchsetArgs {
|
|
3
|
+
connectionString: string;
|
|
4
|
+
bucketName: string;
|
|
5
|
+
username: string;
|
|
6
|
+
password: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* CouchbaseConnection class
|
|
10
|
+
* Only one CouchbaseConnection can exist that's why it's a singleton
|
|
11
|
+
*/
|
|
12
|
+
export declare class CouchbaseConnection implements CouchsetArgs {
|
|
13
|
+
private static _instance;
|
|
14
|
+
bucket: Bucket;
|
|
15
|
+
cluster: Cluster;
|
|
16
|
+
connectionString: string;
|
|
17
|
+
bucketName: string;
|
|
18
|
+
username: string;
|
|
19
|
+
password: string;
|
|
20
|
+
static get Instance(): CouchbaseConnection;
|
|
21
|
+
private constructor();
|
|
22
|
+
/**
|
|
23
|
+
* start
|
|
24
|
+
*/
|
|
25
|
+
init: (args: CouchsetArgs) => Promise<CouchbaseConnection>;
|
|
26
|
+
/**
|
|
27
|
+
* getCollection
|
|
28
|
+
*/
|
|
29
|
+
getCollection: () => Collection;
|
|
30
|
+
getCluster: () => Cluster;
|
|
31
|
+
/**
|
|
32
|
+
* shutdown cluster
|
|
33
|
+
*/
|
|
34
|
+
shutdown: () => Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export default CouchbaseConnection;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
31
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
32
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
33
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
34
|
+
function step(op) {
|
|
35
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
36
|
+
while (_) try {
|
|
37
|
+
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;
|
|
38
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
39
|
+
switch (op[0]) {
|
|
40
|
+
case 0: case 1: t = op; break;
|
|
41
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
42
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
43
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
44
|
+
default:
|
|
45
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
46
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
47
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
48
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
49
|
+
if (t[2]) _.ops.pop();
|
|
50
|
+
_.trys.pop(); continue;
|
|
51
|
+
}
|
|
52
|
+
op = body.call(thisArg, _);
|
|
53
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
54
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
|
+
exports.CouchbaseConnection = void 0;
|
|
59
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
60
|
+
var couchbase = __importStar(require("couchbase"));
|
|
61
|
+
/**
|
|
62
|
+
* CouchbaseConnection class
|
|
63
|
+
* Only one CouchbaseConnection can exist that's why it's a singleton
|
|
64
|
+
*/
|
|
65
|
+
var CouchbaseConnection = /** @class */ (function () {
|
|
66
|
+
function CouchbaseConnection() {
|
|
67
|
+
var _this = this;
|
|
68
|
+
this.bucket = null;
|
|
69
|
+
this.cluster = null;
|
|
70
|
+
// Args
|
|
71
|
+
this.connectionString = null;
|
|
72
|
+
this.bucketName = null;
|
|
73
|
+
this.username = null;
|
|
74
|
+
this.password = null;
|
|
75
|
+
/**
|
|
76
|
+
* start
|
|
77
|
+
*/
|
|
78
|
+
this.init = function (args) { return __awaiter(_this, void 0, void 0, function () {
|
|
79
|
+
var connectionString, password, username, _a, bucketName, cluster;
|
|
80
|
+
return __generator(this, function (_b) {
|
|
81
|
+
switch (_b.label) {
|
|
82
|
+
case 0:
|
|
83
|
+
connectionString = args.connectionString, password = args.password, username = args.username, _a = args.bucketName, bucketName = _a === void 0 ? 'default' : _a;
|
|
84
|
+
this.connectionString = connectionString;
|
|
85
|
+
this.bucketName = bucketName;
|
|
86
|
+
this.username = username;
|
|
87
|
+
this.password = password;
|
|
88
|
+
return [4 /*yield*/, couchbase.connect(connectionString, {
|
|
89
|
+
username: username,
|
|
90
|
+
password: password,
|
|
91
|
+
})];
|
|
92
|
+
case 1:
|
|
93
|
+
cluster = _b.sent();
|
|
94
|
+
this.cluster = cluster;
|
|
95
|
+
this.bucket = this.cluster.bucket(bucketName);
|
|
96
|
+
return [2 /*return*/, this];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}); };
|
|
100
|
+
/**
|
|
101
|
+
* getCollection
|
|
102
|
+
*/
|
|
103
|
+
this.getCollection = function () {
|
|
104
|
+
return _this.bucket.defaultCollection();
|
|
105
|
+
};
|
|
106
|
+
this.getCluster = function () {
|
|
107
|
+
return _this.cluster;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* shutdown cluster
|
|
111
|
+
*/
|
|
112
|
+
this.shutdown = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
113
|
+
return __generator(this, function (_a) {
|
|
114
|
+
return [2 /*return*/, this.cluster.close()];
|
|
115
|
+
});
|
|
116
|
+
}); };
|
|
117
|
+
}
|
|
118
|
+
Object.defineProperty(CouchbaseConnection, "Instance", {
|
|
119
|
+
get: function () {
|
|
120
|
+
return this._instance || (this._instance = new this());
|
|
121
|
+
},
|
|
122
|
+
enumerable: false,
|
|
123
|
+
configurable: true
|
|
124
|
+
});
|
|
125
|
+
return CouchbaseConnection;
|
|
126
|
+
}());
|
|
127
|
+
exports.CouchbaseConnection = CouchbaseConnection;
|
|
128
|
+
exports.default = CouchbaseConnection;
|
|
129
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAsD;AACtD,mDAAuC;AAUvC;;;GAGG;AACH;IAgBI;QAAA,iBAAwB;QAbxB,WAAM,GAAW,IAAI,CAAC;QACtB,YAAO,GAAY,IAAI,CAAC;QAExB,OAAO;QACP,qBAAgB,GAAW,IAAI,CAAC;QAChC,eAAU,GAAW,IAAI,CAAC;QAC1B,aAAQ,GAAW,IAAI,CAAC;QACxB,aAAQ,GAAW,IAAI,CAAC;QAQxB;;WAEG;QACI,SAAI,GAAG,UAAO,IAAkB;;;;;wBAC5B,gBAAgB,GAAgD,IAAI,iBAApD,EAAE,QAAQ,GAAsC,IAAI,SAA1C,EAAE,QAAQ,GAA4B,IAAI,SAAhC,EAAE,KAA0B,IAAI,WAAR,EAAtB,UAAU,mBAAG,SAAS,KAAA,CAAS;wBAE5E,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;wBACzC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;wBAC7B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;wBACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;wBAET,qBAAM,SAAS,CAAC,OAAO,CAAC,gBAAgB,EAAE;gCACtD,QAAQ,UAAA;gCACR,QAAQ,UAAA;6BACX,CAAC,EAAA;;wBAHI,OAAO,GAAG,SAGd;wBAEF,IAAI,CAAC,OAAO,GAAG,OAAc,CAAC;wBAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;wBAE9C,sBAAO,IAAI,EAAC;;;aACf,CAAC;QAEF;;WAEG;QACI,kBAAa,GAAG;YACnB,OAAO,KAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;QAC3C,CAAC,CAAC;QAEK,eAAU,GAAG;YAChB,OAAO,KAAI,CAAC,OAAO,CAAC;QACxB,CAAC,CAAC;QAEF;;WAEG;QACI,aAAQ,GAAG;;gBACd,sBAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAC;;aAC/B,CAAC;IAxCqB,CAAC;IAJxB,sBAAkB,+BAAQ;aAA1B;YACI,OAAO,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,CAAC;QAC3D,CAAC;;;OAAA;IA2CL,0BAAC;AAAD,CAAC,AAzDD,IAyDC;AAzDY,kDAAmB;AA2DhC,kBAAe,mBAAmB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport * as couchbase from 'couchbase';\nimport {Collection, Cluster, Bucket} from 'couchbase';\n\nexport interface CouchsetArgs {\n connectionString: string;\n bucketName: string;\n username: string;\n password: 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 * getCollection\n */\n public getCollection = (): Collection => {\n return this.bucket.defaultCollection();\n };\n\n public getCluster = (): Cluster => {\n return this.cluster;\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"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CouchsetArgs } from './connection';
|
|
2
|
+
export * from 'type-graphql';
|
|
3
|
+
export * from './automate';
|
|
4
|
+
export * from './model';
|
|
5
|
+
export * from './connection';
|
|
6
|
+
export * from './query';
|
|
7
|
+
export * from './search';
|
|
8
|
+
export * from './pagination';
|
|
9
|
+
/**
|
|
10
|
+
* Main function to start CouchSet
|
|
11
|
+
* @param @interface CouchsetArgs
|
|
12
|
+
*/
|
|
13
|
+
export declare const couchset: (args: CouchsetArgs) => Promise<boolean>;
|
|
14
|
+
export default couchset;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (_) try {
|
|
28
|
+
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;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
49
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
50
|
+
};
|
|
51
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
+
exports.couchset = void 0;
|
|
53
|
+
var connection_1 = __importDefault(require("./connection"));
|
|
54
|
+
__exportStar(require("type-graphql"), exports);
|
|
55
|
+
__exportStar(require("./automate"), exports);
|
|
56
|
+
__exportStar(require("./model"), exports);
|
|
57
|
+
__exportStar(require("./connection"), exports);
|
|
58
|
+
__exportStar(require("./query"), exports);
|
|
59
|
+
__exportStar(require("./search"), exports);
|
|
60
|
+
__exportStar(require("./pagination"), exports);
|
|
61
|
+
/**
|
|
62
|
+
* Main function to start CouchSet
|
|
63
|
+
* @param @interface CouchsetArgs
|
|
64
|
+
*/
|
|
65
|
+
var couchset = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
66
|
+
var couch;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
switch (_a.label) {
|
|
69
|
+
case 0:
|
|
70
|
+
couch = connection_1.default.Instance;
|
|
71
|
+
return [4 /*yield*/, couch.init(args)];
|
|
72
|
+
case 1:
|
|
73
|
+
_a.sent();
|
|
74
|
+
return [2 /*return*/, Promise.resolve(true)];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}); };
|
|
78
|
+
exports.couchset = couchset;
|
|
79
|
+
exports.default = exports.couchset;
|
|
80
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA+D;AAE/D,+CAA6B;AAC7B,6CAA2B;AAC3B,0CAAwB;AACxB,+CAA6B;AAC7B,0CAAwB;AACxB,2CAAyB;AACzB,+CAA6B;AAE7B;;;GAGG;AACI,IAAM,QAAQ,GAAG,UAAO,IAAkB;;;;;gBACvC,KAAK,GAAG,oBAAmB,CAAC,QAAQ,CAAC;gBAC3C,qBAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAA;;gBAAtB,SAAsB,CAAC;gBACvB,sBAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAC;;;KAChC,CAAC;AAJW,QAAA,QAAQ,YAInB;AAEF,kBAAe,gBAAQ,CAAC","sourcesContent":["import CouchbaseConnection, {CouchsetArgs} from './connection';\n\nexport * from 'type-graphql';\nexport * from './automate';\nexport * from './model';\nexport * from './connection';\nexport * from './query';\nexport * from './search';\nexport * from './pagination';\n\n/**\n * Main function to start CouchSet\n * @param @interface CouchsetArgs\n */\nexport const couchset = async (args: CouchsetArgs): Promise<boolean> => {\n const couch = CouchbaseConnection.Instance;\n await couch.init(args);\n return Promise.resolve(true);\n};\n\nexport default couchset;\n"]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Collection } from 'couchbase';
|
|
2
|
+
import CouchbaseConnection from '../connection';
|
|
3
|
+
import { SchemaTypes } from '../utils';
|
|
4
|
+
import { CustomQueryPagination } from '../search';
|
|
5
|
+
import { AutomaticMethodOptions } from '../automate';
|
|
6
|
+
export interface AutoModelFields {
|
|
7
|
+
id: string;
|
|
8
|
+
createdAt: Date;
|
|
9
|
+
updatedAt?: Date;
|
|
10
|
+
deleted?: Date;
|
|
11
|
+
_type: string;
|
|
12
|
+
_scope: string;
|
|
13
|
+
}
|
|
14
|
+
interface ModalOptions {
|
|
15
|
+
scope?: string;
|
|
16
|
+
schema?: Record<string, SchemaTypes>;
|
|
17
|
+
graphqlType?: any;
|
|
18
|
+
}
|
|
19
|
+
export declare class Model {
|
|
20
|
+
collection: Collection;
|
|
21
|
+
collectionName: string;
|
|
22
|
+
scope: string;
|
|
23
|
+
schema: Record<string, SchemaTypes>;
|
|
24
|
+
graphqlType: any;
|
|
25
|
+
constructor(name: string, options?: ModalOptions);
|
|
26
|
+
/**
|
|
27
|
+
* Set setGraphqlType
|
|
28
|
+
* setGraphqlType
|
|
29
|
+
*/
|
|
30
|
+
setGraphqlType(gqlType: any): Model;
|
|
31
|
+
/**
|
|
32
|
+
* Refresh and get default collection from CouchbaseConnection
|
|
33
|
+
* Because CouchbaseConnection is a singleton, sometimes it might be undefined depending when model was created
|
|
34
|
+
* So we have to call it from all model methods
|
|
35
|
+
* to avoid error `Cannot read property 'defaultCollection' of null`
|
|
36
|
+
*/
|
|
37
|
+
fresh(): void;
|
|
38
|
+
/** Get this collection
|
|
39
|
+
* getCollection
|
|
40
|
+
*/
|
|
41
|
+
getBucketName(): string;
|
|
42
|
+
/** Get this collection
|
|
43
|
+
* getCollection
|
|
44
|
+
*/
|
|
45
|
+
couchbaseConnection(): CouchbaseConnection;
|
|
46
|
+
/** Get this collection
|
|
47
|
+
* getCollection
|
|
48
|
+
*/
|
|
49
|
+
getCollection(): Collection;
|
|
50
|
+
/**
|
|
51
|
+
* create
|
|
52
|
+
*/
|
|
53
|
+
create<T>(data: T): Promise<T & AutoModelFields>;
|
|
54
|
+
/**
|
|
55
|
+
* findById
|
|
56
|
+
*/
|
|
57
|
+
findById(id: string): Promise<any & AutoModelFields>;
|
|
58
|
+
/**
|
|
59
|
+
* update
|
|
60
|
+
*/
|
|
61
|
+
updateById<T>(id: string, data: T): Promise<T>;
|
|
62
|
+
/**
|
|
63
|
+
* save
|
|
64
|
+
*/
|
|
65
|
+
save<T>(data: T & {
|
|
66
|
+
id: string;
|
|
67
|
+
}): Promise<T>;
|
|
68
|
+
delete(id: string): Promise<boolean>;
|
|
69
|
+
/**
|
|
70
|
+
* Pagination
|
|
71
|
+
*
|
|
72
|
+
select = ['id', 'createdAt']
|
|
73
|
+
where = {
|
|
74
|
+
where: { owner: { $eq: "stoqey" }, _type: { $eq: "Trade" } },
|
|
75
|
+
},
|
|
76
|
+
page = 0,
|
|
77
|
+
limit = 10,
|
|
78
|
+
orderBy = { createdAt: "DESC" },
|
|
79
|
+
* @param args PaginationArgs
|
|
80
|
+
*/
|
|
81
|
+
pagination({ select, where, orderBy, limit, page, customQuery, }: {
|
|
82
|
+
select?: any[] | string;
|
|
83
|
+
where?: any;
|
|
84
|
+
orderBy?: any;
|
|
85
|
+
limit?: number;
|
|
86
|
+
page?: number;
|
|
87
|
+
customQuery?: any;
|
|
88
|
+
}): Promise<any[]>;
|
|
89
|
+
/**
|
|
90
|
+
* Run a custom query with model parsing
|
|
91
|
+
* @param { select, query }
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
94
|
+
customQuery<T>({ params, limit, query, }: {
|
|
95
|
+
params: any;
|
|
96
|
+
limit: number;
|
|
97
|
+
query: string;
|
|
98
|
+
}): Promise<[T[], CustomQueryPagination]>;
|
|
99
|
+
parse<T>(data: T): T;
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* @param args AutomaticModelOptions
|
|
103
|
+
* @returns
|
|
104
|
+
*/
|
|
105
|
+
automate(args?: Partial<AutomaticMethodOptions>): import("../automate").AutomaticOutput;
|
|
106
|
+
}
|
|
107
|
+
export default Model;
|