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.
Files changed (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +231 -0
  3. package/dist/automate/index.d.ts +4 -0
  4. package/dist/automate/index.js +17 -0
  5. package/dist/automate/index.js.map +1 -0
  6. package/dist/automate/middlewares/index.d.ts +1 -0
  7. package/dist/automate/middlewares/index.js +14 -0
  8. package/dist/automate/middlewares/index.js.map +1 -0
  9. package/dist/automate/middlewares/isAuth.d.ts +7 -0
  10. package/dist/automate/middlewares/isAuth.js +28 -0
  11. package/dist/automate/middlewares/isAuth.js.map +1 -0
  12. package/dist/automate/model/client.d.ts +12 -0
  13. package/dist/automate/model/client.js +33 -0
  14. package/dist/automate/model/client.js.map +1 -0
  15. package/dist/automate/model/index.d.ts +44 -0
  16. package/dist/automate/model/index.js +304 -0
  17. package/dist/automate/model/index.js.map +1 -0
  18. package/dist/automate/morpheus/index.d.ts +14 -0
  19. package/dist/automate/morpheus/index.js +171 -0
  20. package/dist/automate/morpheus/index.js.map +1 -0
  21. package/dist/automate/writer/index.d.ts +10 -0
  22. package/dist/automate/writer/index.js +72 -0
  23. package/dist/automate/writer/index.js.map +1 -0
  24. package/dist/config/index.d.ts +3 -0
  25. package/dist/config/index.js +8 -0
  26. package/dist/config/index.js.map +1 -0
  27. package/dist/connection.d.ts +36 -0
  28. package/dist/connection.js +129 -0
  29. package/dist/connection.js.map +1 -0
  30. package/dist/index.d.ts +14 -0
  31. package/dist/index.js +80 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/model/index.d.ts +107 -0
  34. package/dist/model/index.js +329 -0
  35. package/dist/model/index.js.map +1 -0
  36. package/dist/pagination/index.d.ts +1 -0
  37. package/dist/pagination/index.js +14 -0
  38. package/dist/pagination/index.js.map +1 -0
  39. package/dist/pagination/pagination.d.ts +19 -0
  40. package/dist/pagination/pagination.js +97 -0
  41. package/dist/pagination/pagination.js.map +1 -0
  42. package/dist/query/base-query.d.ts +17 -0
  43. package/dist/query/base-query.js +15 -0
  44. package/dist/query/base-query.js.map +1 -0
  45. package/dist/query/exceptions.d.ts +24 -0
  46. package/dist/query/exceptions.js +90 -0
  47. package/dist/query/exceptions.js.map +1 -0
  48. package/dist/query/helpers/builders.d.ts +64 -0
  49. package/dist/query/helpers/builders.js +415 -0
  50. package/dist/query/helpers/builders.js.map +1 -0
  51. package/dist/query/helpers/dictionary.d.ts +45 -0
  52. package/dist/query/helpers/dictionary.js +105 -0
  53. package/dist/query/helpers/dictionary.js.map +1 -0
  54. package/dist/query/helpers/index.d.ts +3 -0
  55. package/dist/query/helpers/index.js +16 -0
  56. package/dist/query/helpers/index.js.map +1 -0
  57. package/dist/query/helpers/reservedWords.d.ts +1 -0
  58. package/dist/query/helpers/reservedWords.js +200 -0
  59. package/dist/query/helpers/reservedWords.js.map +1 -0
  60. package/dist/query/index.d.ts +5 -0
  61. package/dist/query/index.js +27 -0
  62. package/dist/query/index.js.map +1 -0
  63. package/dist/query/interface/query.types.d.ts +236 -0
  64. package/dist/query/interface/query.types.js +3 -0
  65. package/dist/query/interface/query.types.js.map +1 -0
  66. package/dist/query/query.cluster.d.ts +14 -0
  67. package/dist/query/query.cluster.js +80 -0
  68. package/dist/query/query.cluster.js.map +1 -0
  69. package/dist/query/query.d.ts +321 -0
  70. package/dist/query/query.js +457 -0
  71. package/dist/query/query.js.map +1 -0
  72. package/dist/query/utils.d.ts +8 -0
  73. package/dist/query/utils.js +56 -0
  74. package/dist/query/utils.js.map +1 -0
  75. package/dist/search/customQuery.d.ts +17 -0
  76. package/dist/search/customQuery.js +83 -0
  77. package/dist/search/customQuery.js.map +1 -0
  78. package/dist/search/index.d.ts +1 -0
  79. package/dist/search/index.js +14 -0
  80. package/dist/search/index.js.map +1 -0
  81. package/dist/shared/ContextType.d.ts +27 -0
  82. package/dist/shared/ContextType.js +55 -0
  83. package/dist/shared/ContextType.js.map +1 -0
  84. package/dist/shared/common.model.d.ts +37 -0
  85. package/dist/shared/common.model.js +148 -0
  86. package/dist/shared/common.model.js.map +1 -0
  87. package/dist/shared/index.d.ts +2 -0
  88. package/dist/shared/index.js +15 -0
  89. package/dist/shared/index.js.map +1 -0
  90. package/dist/utils/awaitTo.d.ts +17 -0
  91. package/dist/utils/awaitTo.js +31 -0
  92. package/dist/utils/awaitTo.js.map +1 -0
  93. package/dist/utils/date.d.ts +11 -0
  94. package/dist/utils/date.js +21 -0
  95. package/dist/utils/date.js.map +1 -0
  96. package/dist/utils/index.d.ts +5 -0
  97. package/dist/utils/index.js +18 -0
  98. package/dist/utils/index.js.map +1 -0
  99. package/dist/utils/log.d.ts +9 -0
  100. package/dist/utils/log.js +19 -0
  101. package/dist/utils/log.js.map +1 -0
  102. package/dist/utils/text.utils.d.ts +14 -0
  103. package/dist/utils/text.utils.js +45 -0
  104. package/dist/utils/text.utils.js.map +1 -0
  105. package/dist/utils/utils.schema.d.ts +6 -0
  106. package/dist/utils/utils.schema.js +33 -0
  107. package/dist/utils/utils.schema.js.map +1 -0
  108. package/dist/uuid.d.ts +1 -0
  109. package/dist/uuid.js +9 -0
  110. package/dist/uuid.js.map +1 -0
  111. package/docs/couch.png +0 -0
  112. package/docs/couchset.png +0 -0
  113. package/docs/couchset_logo.png +0 -0
  114. package/package.json +108 -30
  115. package/register/index.js +1 -0
  116. package/register/transpile-only.js +3 -0
  117. package/register/type-check.js +3 -0
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.CustomQuery = void 0;
43
+ var connection_1 = __importDefault(require("../connection"));
44
+ /**
45
+ * Common pagination
46
+ * query,
47
+ bucketName = "",
48
+ select = ["id", "owner"] || "*"
49
+ * @param args PaginationArgs
50
+ */
51
+ var CustomQuery = function (args) { return __awaiter(void 0, void 0, void 0, function () {
52
+ var query, limit, params, cluster, _a, rows, totalItems, hasNext, error_1;
53
+ return __generator(this, function (_b) {
54
+ switch (_b.label) {
55
+ case 0:
56
+ query = args.query, limit = args.limit, params = args.params;
57
+ cluster = connection_1.default.Instance.cluster;
58
+ _b.label = 1;
59
+ case 1:
60
+ _b.trys.push([1, 3, , 4]);
61
+ console.log('-> ', query);
62
+ return [4 /*yield*/, cluster.query(query)];
63
+ case 2:
64
+ _a = (_b.sent()).rows, rows = _a === void 0 ? [] : _a;
65
+ totalItems = rows.length;
66
+ hasNext = true;
67
+ if (totalItems >= limit) {
68
+ hasNext = true;
69
+ }
70
+ else {
71
+ hasNext = false;
72
+ }
73
+ return [2 /*return*/, [rows, { params: params, hasNext: hasNext }]];
74
+ case 3:
75
+ error_1 = _b.sent();
76
+ console.error('error running CustomQuery', error_1);
77
+ return [2 /*return*/, [[], { params: params, hasNext: false }]];
78
+ case 4: return [2 /*return*/];
79
+ }
80
+ });
81
+ }); };
82
+ exports.CustomQuery = CustomQuery;
83
+ //# sourceMappingURL=customQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customQuery.js","sourceRoot":"","sources":["../../src/search/customQuery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6DAAgD;AAahD;;;;;;GAMG;AACI,IAAM,WAAW,GAAG,UACvB,IAAqB;;;;;gBAEd,KAAK,GAAmB,IAAI,MAAvB,EAAE,KAAK,GAAY,IAAI,MAAhB,EAAE,MAAM,GAAI,IAAI,OAAR,CAAS;gBAE9B,OAAO,GAAG,oBAAmB,CAAC,QAAQ,CAAC,OAAO,CAAC;;;;gBAGjD,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBAEN,qBAAM,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAA;;gBAAvC,KAAa,CAAA,SAA0B,CAAA,KAA9B,EAAT,IAAI,mBAAG,EAAE,KAAA;gBAEV,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC;gBAE3B,OAAO,GAAG,IAAI,CAAC;gBACnB,IAAI,UAAU,IAAI,KAAK,EAAE;oBACrB,OAAO,GAAG,IAAI,CAAC;iBAClB;qBAAM;oBACH,OAAO,GAAG,KAAK,CAAC;iBACnB;gBAED,sBAAO,CAAC,IAAsB,EAAE,EAAC,MAAM,QAAA,EAAE,OAAO,SAAA,EAAC,CAAC,EAAC;;;gBAEnD,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,OAAK,CAAC,CAAC;gBAClD,sBAAO,CAAC,EAAE,EAAE,EAAC,MAAM,QAAA,EAAE,OAAO,EAAE,KAAK,EAAC,CAAC,EAAC;;;;KAE7C,CAAC;AA1BW,QAAA,WAAW,eA0BtB","sourcesContent":["import CouchbaseConnection from '../connection';\n\nexport interface CustomQueryArgs {\n query: any;\n limit: number;\n params: any;\n}\n\nexport interface CustomQueryPagination {\n hasNext: boolean;\n params: any;\n}\n\n/**\n * Common pagination\n * query,\n bucketName = \"\",\n select = [\"id\", \"owner\"] || \"*\"\n * @param args PaginationArgs\n */\nexport const CustomQuery = async <T>(\n args: CustomQueryArgs\n): Promise<[T[], CustomQueryPagination]> => {\n const {query, limit, params} = args;\n\n const cluster = CouchbaseConnection.Instance.cluster;\n\n try {\n console.log('-> ', query);\n\n const {rows = []} = await cluster.query(query);\n\n const totalItems = rows.length;\n\n let hasNext = true;\n if (totalItems >= limit) {\n hasNext = true;\n } else {\n hasNext = false;\n }\n\n return [rows as unknown as T[], {params, hasNext}];\n } catch (error) {\n console.error('error running CustomQuery', error);\n return [[], {params, hasNext: false}];\n }\n};\n"]}
@@ -0,0 +1 @@
1
+ export * from './customQuery';
@@ -0,0 +1,14 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./customQuery"), exports);
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/search/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAA8B","sourcesContent":["export * from './customQuery';\n"]}
@@ -0,0 +1,27 @@
1
+ import { Request, Response } from 'express';
2
+ import { RedisPubSub } from 'graphql-redis-subscriptions';
3
+ export interface ContextType {
4
+ req: Request;
5
+ res: Response;
6
+ payload?: any;
7
+ pubsub: RedisPubSub;
8
+ }
9
+ /**
10
+ * GraphQL Types start
11
+ */
12
+ /**
13
+ * ResType
14
+ */
15
+ export declare class ResType {
16
+ success: boolean;
17
+ message?: string;
18
+ data?: any;
19
+ }
20
+ export declare class GeoType {
21
+ lat: number;
22
+ lon: number;
23
+ }
24
+ export interface GeoLocationType {
25
+ lat: number;
26
+ lon: number;
27
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GeoType = exports.ResType = void 0;
13
+ var type_graphql_1 = require("type-graphql");
14
+ var graphql_type_json_1 = __importDefault(require("graphql-type-json"));
15
+ /**
16
+ * GraphQL Types start
17
+ */
18
+ /**
19
+ * ResType
20
+ */
21
+ var ResType = /** @class */ (function () {
22
+ function ResType() {
23
+ }
24
+ __decorate([
25
+ (0, type_graphql_1.Field)(function () { return Boolean; })
26
+ ], ResType.prototype, "success", void 0);
27
+ __decorate([
28
+ (0, type_graphql_1.Field)(function () { return String; }, { nullable: true })
29
+ ], ResType.prototype, "message", void 0);
30
+ __decorate([
31
+ (0, type_graphql_1.Field)(function (type) { return graphql_type_json_1.default; }, { nullable: true })
32
+ ], ResType.prototype, "data", void 0);
33
+ ResType = __decorate([
34
+ (0, type_graphql_1.ObjectType)()
35
+ ], ResType);
36
+ return ResType;
37
+ }());
38
+ exports.ResType = ResType;
39
+ var GeoType = /** @class */ (function () {
40
+ function GeoType() {
41
+ }
42
+ __decorate([
43
+ (0, type_graphql_1.Field)(function () { return Number; }, { nullable: true })
44
+ ], GeoType.prototype, "lat", void 0);
45
+ __decorate([
46
+ (0, type_graphql_1.Field)(function () { return Number; }, { nullable: true })
47
+ ], GeoType.prototype, "lon", void 0);
48
+ GeoType = __decorate([
49
+ (0, type_graphql_1.InputType)('GeoTypeInput'),
50
+ (0, type_graphql_1.ObjectType)()
51
+ ], GeoType);
52
+ return GeoType;
53
+ }());
54
+ exports.GeoType = GeoType;
55
+ //# sourceMappingURL=ContextType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextType.js","sourceRoot":"","sources":["../../src/shared/ContextType.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,6CAA0D;AAC1D,wEAA4C;AAU5C;;GAEG;AAEH;;GAEG;AAEH;IAAA;IAUA,CAAC;IARG;QADC,IAAA,oBAAK,EAAC,cAAM,OAAA,OAAO,EAAP,CAAO,CAAC;4CACJ;IAGjB;QADC,IAAA,oBAAK,EAAC,cAAM,OAAA,MAAM,EAAN,CAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;4CACrB;IAIjB;QADC,IAAA,oBAAK,EAAC,UAAC,IAAI,IAAK,OAAA,2BAAW,EAAX,CAAW,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;yCACpC;IATF,OAAO;QADnB,IAAA,yBAAU,GAAE;OACA,OAAO,CAUnB;IAAD,cAAC;CAAA,AAVD,IAUC;AAVY,0BAAO;AAcpB;IAAA;IAMA,CAAC;IAJG;QADC,IAAA,oBAAK,EAAC,cAAM,OAAA,MAAM,EAAN,CAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;wCAC1B;IAGZ;QADC,IAAA,oBAAK,EAAC,cAAM,OAAA,MAAM,EAAN,CAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;wCAC1B;IALH,OAAO;QAFnB,IAAA,wBAAS,EAAC,cAAc,CAAC;QACzB,IAAA,yBAAU,GAAE;OACA,OAAO,CAMnB;IAAD,cAAC;CAAA,AAND,IAMC;AANY,0BAAO","sourcesContent":["import {Request, Response} from 'express';\nimport {ObjectType, Field, InputType} from 'type-graphql';\nimport GraphQLJSON from 'graphql-type-json';\nimport {RedisPubSub} from 'graphql-redis-subscriptions';\n\nexport interface ContextType {\n req: Request;\n res: Response;\n payload?: any;\n pubsub: RedisPubSub;\n}\n\n/**\n * GraphQL Types start\n */\n\n/**\n * ResType\n */\n@ObjectType()\nexport class ResType {\n @Field(() => Boolean)\n success: boolean;\n\n @Field(() => String, {nullable: true})\n message?: string;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n @Field((type) => GraphQLJSON, {nullable: true})\n data?: any;\n}\n\n@InputType('GeoTypeInput')\n@ObjectType()\nexport class GeoType {\n @Field(() => Number, {nullable: true})\n lat: number;\n\n @Field(() => Number, {nullable: true})\n lon: number;\n}\n\nexport interface GeoLocationType {\n lat: number;\n lon: number;\n}\n"]}
@@ -0,0 +1,37 @@
1
+ import { Model } from '../model';
2
+ export declare class CommonType {
3
+ id?: string;
4
+ env?: string;
5
+ owner?: string;
6
+ createdAt?: Date;
7
+ updatedAt?: Date;
8
+ deleted?: boolean;
9
+ }
10
+ export declare const CommonSchema: {
11
+ id: StringConstructor;
12
+ env: StringConstructor;
13
+ owner: StringConstructor;
14
+ createdAt: DateConstructor;
15
+ updatedAt: DateConstructor;
16
+ deleted: BooleanConstructor;
17
+ };
18
+ interface CreateUpdate {
19
+ model: Model;
20
+ id?: string;
21
+ owner?: string;
22
+ data: any;
23
+ }
24
+ export declare const createUpdate: <T>(args: CreateUpdate) => Promise<T>;
25
+ /**
26
+ * Creates a [className]Pagination ObjectType
27
+ * @param c class
28
+ * @returns
29
+ */
30
+ export declare const getPagination: <T>(c: T) => any;
31
+ export interface IResType {
32
+ success: boolean;
33
+ message?: string;
34
+ data?: any;
35
+ }
36
+ export declare const ResTypeFragment: import("graphql").DocumentNode;
37
+ export {};
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
+ return cooked;
5
+ };
6
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
7
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
8
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
9
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
10
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
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.ResTypeFragment = exports.getPagination = exports.createUpdate = exports.CommonSchema = exports.CommonType = void 0;
53
+ var type_graphql_1 = require("type-graphql");
54
+ var graphql_type_json_1 = __importDefault(require("graphql-type-json"));
55
+ var graphql_tag_1 = __importDefault(require("graphql-tag"));
56
+ var CommonType = /** @class */ (function () {
57
+ function CommonType() {
58
+ }
59
+ __decorate([
60
+ (0, type_graphql_1.Field)(function () { return String; }, { nullable: true })
61
+ ], CommonType.prototype, "id", void 0);
62
+ __decorate([
63
+ (0, type_graphql_1.Field)(function () { return String; }, { nullable: true })
64
+ ], CommonType.prototype, "env", void 0);
65
+ __decorate([
66
+ (0, type_graphql_1.Field)(function () { return String; }, { nullable: true })
67
+ ], CommonType.prototype, "owner", void 0);
68
+ __decorate([
69
+ (0, type_graphql_1.Field)(function () { return Date; }, { nullable: true })
70
+ ], CommonType.prototype, "createdAt", void 0);
71
+ __decorate([
72
+ (0, type_graphql_1.Field)(function () { return Date; }, { nullable: true })
73
+ ], CommonType.prototype, "updatedAt", void 0);
74
+ __decorate([
75
+ (0, type_graphql_1.Field)(function () { return Boolean; }, { nullable: true })
76
+ ], CommonType.prototype, "deleted", void 0);
77
+ CommonType = __decorate([
78
+ (0, type_graphql_1.ObjectType)()
79
+ ], CommonType);
80
+ return CommonType;
81
+ }());
82
+ exports.CommonType = CommonType;
83
+ exports.CommonSchema = {
84
+ id: String,
85
+ env: String,
86
+ owner: String,
87
+ createdAt: Date,
88
+ updatedAt: Date,
89
+ deleted: Boolean,
90
+ };
91
+ var createUpdate = function (args) { return __awaiter(void 0, void 0, void 0, function () {
92
+ var model, id, data, createdItem, error_1;
93
+ return __generator(this, function (_a) {
94
+ switch (_a.label) {
95
+ case 0:
96
+ model = args.model, id = args.id, data = args.data;
97
+ _a.label = 1;
98
+ case 1:
99
+ _a.trys.push([1, 5, , 6]);
100
+ if (!id) return [3 /*break*/, 3];
101
+ // update
102
+ return [4 /*yield*/, model.updateById(id, data)];
103
+ case 2:
104
+ // update
105
+ _a.sent();
106
+ return [2 /*return*/, data];
107
+ case 3: return [4 /*yield*/, model.create(data)];
108
+ case 4:
109
+ createdItem = _a.sent();
110
+ return [2 /*return*/, createdItem];
111
+ case 5:
112
+ error_1 = _a.sent();
113
+ console.error("error creating for " + model.collectionName, error_1);
114
+ return [2 /*return*/, null];
115
+ case 6: return [2 /*return*/];
116
+ }
117
+ });
118
+ }); };
119
+ exports.createUpdate = createUpdate;
120
+ /**
121
+ * Creates a [className]Pagination ObjectType
122
+ * @param c class
123
+ * @returns
124
+ */
125
+ var getPagination = function (c) {
126
+ var Pagination = /** @class */ (function () {
127
+ function Pagination() {
128
+ }
129
+ __decorate([
130
+ (0, type_graphql_1.Field)(function () { return [c]; }, { nullable: true })
131
+ ], Pagination.prototype, "items", void 0);
132
+ __decorate([
133
+ (0, type_graphql_1.Field)(function () { return Boolean; }, { nullable: true })
134
+ ], Pagination.prototype, "hasNext", void 0);
135
+ __decorate([
136
+ (0, type_graphql_1.Field)(function () { return graphql_type_json_1.default; }, { nullable: true })
137
+ ], Pagination.prototype, "params", void 0);
138
+ Pagination = __decorate([
139
+ (0, type_graphql_1.ObjectType)(c.name + "Pagination")
140
+ ], Pagination);
141
+ return Pagination;
142
+ }());
143
+ return Pagination;
144
+ };
145
+ exports.getPagination = getPagination;
146
+ exports.ResTypeFragment = (0, graphql_tag_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n fragment ResTypeFragment on ResType {\n success\n message\n data\n }\n"], ["\n fragment ResTypeFragment on ResType {\n success\n message\n data\n }\n"])));
147
+ var templateObject_1;
148
+ //# sourceMappingURL=common.model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.model.js","sourceRoot":"","sources":["../../src/shared/common.model.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+C;AAC/C,wEAA4C;AAC5C,4DAA8B;AAK9B;IAAA;IAkBA,CAAC;IAhBG;QADC,IAAA,oBAAK,EAAC,cAAM,OAAA,MAAM,EAAN,CAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;0CAC1B;IAGZ;QADC,IAAA,oBAAK,EAAC,cAAM,OAAA,MAAM,EAAN,CAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;2CACzB;IAGb;QADC,IAAA,oBAAK,EAAC,cAAM,OAAA,MAAM,EAAN,CAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;6CACvB;IAGf;QADC,IAAA,oBAAK,EAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;iDACnB;IAGjB;QADC,IAAA,oBAAK,EAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;iDACnB;IAGjB;QADC,IAAA,oBAAK,EAAC,cAAM,OAAA,OAAO,EAAP,CAAO,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;+CACrB;IAjBT,UAAU;QADtB,IAAA,yBAAU,GAAE;OACA,UAAU,CAkBtB;IAAD,iBAAC;CAAA,AAlBD,IAkBC;AAlBY,gCAAU;AAoBV,QAAA,YAAY,GAAG;IACxB,EAAE,EAAE,MAAM;IACV,GAAG,EAAE,MAAM;IACX,KAAK,EAAE,MAAM;IACb,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,IAAI;IACf,OAAO,EAAE,OAAO;CACnB,CAAC;AASK,IAAM,YAAY,GAAG,UAAU,IAAkB;;;;;gBAC7C,KAAK,GAAc,IAAI,MAAlB,EAAE,EAAE,GAAU,IAAI,GAAd,EAAE,IAAI,GAAI,IAAI,KAAR,CAAS;;;;qBAEvB,EAAE,EAAF,wBAAE;gBACF,SAAS;gBACT,qBAAM,KAAK,CAAC,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,EAAA;;gBADhC,SAAS;gBACT,SAAgC,CAAC;gBACjC,sBAAO,IAAI,EAAC;oBAGI,qBAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAA;;gBAAtC,WAAW,GAAG,SAAwB;gBAC5C,sBAAO,WAAW,EAAC;;;gBAEnB,OAAO,CAAC,KAAK,CAAC,wBAAsB,KAAK,CAAC,cAAgB,EAAE,OAAK,CAAC,CAAC;gBACnE,sBAAO,IAAI,EAAC;;;;KAEnB,CAAC;AAfW,QAAA,YAAY,gBAevB;AAEF;;;;GAIG;AACI,IAAM,aAAa,GAAG,UAAI,CAAI;IAEjC;QAAA;QASA,CAAC;QAPG;YADC,IAAA,oBAAK,EAAC,cAAM,OAAA,CAAC,CAAC,CAAC,EAAH,CAAG,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;iDACjB;QAGlB;YADC,IAAA,oBAAK,EAAC,cAAM,OAAA,OAAO,EAAP,CAAO,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;mDACrB;QAGlB;YADC,IAAA,oBAAK,EAAC,cAAM,OAAA,2BAAW,EAAX,CAAW,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;kDAC9B;QARX,UAAU;YADf,IAAA,yBAAU,EAAK,CAAS,CAAC,IAAI,eAAY,CAAC;WACrC,UAAU,CASf;QAAD,iBAAC;KAAA,AATD,IASC;IACD,OAAO,UAAU,CAAC;AACtB,CAAC,CAAC;AAbW,QAAA,aAAa,iBAaxB;AAQW,QAAA,eAAe,OAAG,qBAAG,0KAAA,sGAMjC,KAAC","sourcesContent":["import {ObjectType, Field} from 'type-graphql';\nimport GraphQLJSON from 'graphql-type-json';\nimport gql from 'graphql-tag';\n\nimport {Model} from '../model';\n\n@ObjectType()\nexport class CommonType {\n @Field(() => String, {nullable: true})\n id?: string;\n\n @Field(() => String, {nullable: true})\n env?: string;\n\n @Field(() => String, {nullable: true})\n owner?: string;\n\n @Field(() => Date, {nullable: true})\n createdAt?: Date;\n\n @Field(() => Date, {nullable: true})\n updatedAt?: Date;\n\n @Field(() => Boolean, {nullable: true})\n deleted?: boolean;\n}\n\nexport const CommonSchema = {\n id: String,\n env: String,\n owner: String,\n createdAt: Date,\n updatedAt: Date,\n deleted: Boolean,\n};\n\ninterface CreateUpdate {\n model: Model;\n id?: string;\n owner?: string;\n data: any;\n}\n\nexport const createUpdate = async <T>(args: CreateUpdate): Promise<T | null> => {\n const {model, id, data} = args;\n try {\n if (id) {\n // update\n await model.updateById(id, data);\n return data;\n }\n // create\n const createdItem = await model.create(data);\n return createdItem;\n } catch (error) {\n console.error(`error creating for ${model.collectionName}`, error);\n return null;\n }\n};\n\n/**\n * Creates a [className]Pagination ObjectType\n * @param c class\n * @returns\n */\nexport const getPagination = <T>(c: T): any => {\n @ObjectType(`${(c as any).name}Pagination`)\n class Pagination {\n @Field(() => [c], {nullable: true})\n items: [typeof c];\n\n @Field(() => Boolean, {nullable: true})\n hasNext?: boolean;\n\n @Field(() => GraphQLJSON, {nullable: true})\n params?: any;\n }\n return Pagination;\n};\n\nexport interface IResType {\n success: boolean;\n message?: string;\n data?: any;\n}\n\nexport const ResTypeFragment = gql`\n fragment ResTypeFragment on ResType {\n success\n message\n data\n }\n`;\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './ContextType';
2
+ export * from './common.model';
@@ -0,0 +1,15 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./ContextType"), exports);
14
+ __exportStar(require("./common.model"), exports);
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAA8B;AAC9B,iDAA+B","sourcesContent":["export * from './ContextType';\nexport * from './common.model';\n"]}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Async await wrapper for easy error handling
3
+ * @param { Promise } promise
4
+ * @param { Object= } errorExt - Additional Information you can pass to the err object
5
+ * @return { Promise }
6
+ *
7
+ let err, user, savedTask;
8
+
9
+ [ err, user ] = await awaitTo(UserModel.findById(1));
10
+ if(!user) return cb('No user found');
11
+
12
+ [ err, savedTask ] = await awaitTo(TaskModel({userId: user.id, name: 'Demo Task'}));
13
+ if(err) return cb('Error occurred while saving task');
14
+
15
+ */
16
+ export declare function awaitTo<T, U = Error>(promise: Promise<T>, errorExt?: Record<string, any>): Promise<[U, undefined] | [null, T]>;
17
+ export default awaitTo;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.awaitTo = void 0;
4
+ /**
5
+ * Async await wrapper for easy error handling
6
+ * @param { Promise } promise
7
+ * @param { Object= } errorExt - Additional Information you can pass to the err object
8
+ * @return { Promise }
9
+ *
10
+ let err, user, savedTask;
11
+
12
+ [ err, user ] = await awaitTo(UserModel.findById(1));
13
+ if(!user) return cb('No user found');
14
+
15
+ [ err, savedTask ] = await awaitTo(TaskModel({userId: user.id, name: 'Demo Task'}));
16
+ if(err) return cb('Error occurred while saving task');
17
+
18
+ */
19
+ function awaitTo(promise, errorExt) {
20
+ return promise
21
+ .then(function (data) { return [null, data]; })
22
+ .catch(function (err) {
23
+ if (errorExt) {
24
+ Object.assign(err, errorExt);
25
+ }
26
+ return [err, undefined];
27
+ });
28
+ }
29
+ exports.awaitTo = awaitTo;
30
+ exports.default = awaitTo;
31
+ //# sourceMappingURL=awaitTo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"awaitTo.js","sourceRoot":"","sources":["../../src/utils/awaitTo.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,SAAgB,OAAO,CACnB,OAAmB,EACnB,QAA8B;IAE9B,OAAO,OAAO;SACT,IAAI,CAAY,UAAC,IAAO,IAAK,OAAA,CAAC,IAAI,EAAE,IAAI,CAAC,EAAZ,CAAY,CAAC;SAC1C,KAAK,CAAiB,UAAC,GAAM;QAC1B,IAAI,QAAQ,EAAE;YACV,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;SAChC;QAED,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACX,CAAC;AAbD,0BAaC;AAED,kBAAe,OAAO,CAAC","sourcesContent":["/**\n * Async await wrapper for easy error handling\n * @param { Promise } promise\n * @param { Object= } errorExt - Additional Information you can pass to the err object\n * @return { Promise }\n * \n let err, user, savedTask;\n\n [ err, user ] = await awaitTo(UserModel.findById(1));\n if(!user) return cb('No user found');\n\n [ err, savedTask ] = await awaitTo(TaskModel({userId: user.id, name: 'Demo Task'}));\n if(err) return cb('Error occurred while saving task');\n\n */\nexport function awaitTo<T, U = Error>(\n promise: Promise<T>,\n errorExt?: Record<string, any>\n): Promise<[U, undefined] | [null, T]> {\n return promise\n .then<[null, T]>((data: T) => [null, data])\n .catch<[U, undefined]>((err: U) => {\n if (errorExt) {\n Object.assign(err, errorExt);\n }\n\n return [err, undefined];\n });\n}\n\nexport default awaitTo;\n"]}
@@ -0,0 +1,11 @@
1
+ interface DataWithDates {
2
+ createdAt: Date;
3
+ updatedAt: Date;
4
+ date: Date;
5
+ }
6
+ /**
7
+ * Convert date strings to data objects
8
+ * @param data
9
+ */
10
+ export declare const convertDates: (data: DataWithDates) => any;
11
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertDates = void 0;
4
+ /**
5
+ * Convert date strings to data objects
6
+ * @param data
7
+ */
8
+ var convertDates = function (data) {
9
+ if (data && data.createdAt) {
10
+ data.createdAt = new Date(data.createdAt);
11
+ }
12
+ if (data && data.updatedAt) {
13
+ data.updatedAt = new Date(data.updatedAt);
14
+ }
15
+ if (data && data.date) {
16
+ data.date = new Date(data.date);
17
+ }
18
+ return data;
19
+ };
20
+ exports.convertDates = convertDates;
21
+ //# sourceMappingURL=date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/utils/date.ts"],"names":[],"mappings":";;;AAMA;;;GAGG;AACI,IAAM,YAAY,GAAG,UAAC,IAAmB;IAC5C,IAAI,IAAI,IAAI,IAAI,CAAC,SAAS,EAAE;QACxB,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KAC7C;IAED,IAAI,IAAI,IAAI,IAAI,CAAC,SAAS,EAAE;QACxB,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KAC7C;IAED,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KACnC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAdW,QAAA,YAAY,gBAcvB","sourcesContent":["interface DataWithDates {\n createdAt: Date;\n updatedAt: Date;\n date: Date;\n}\n\n/**\n * Convert date strings to data objects\n * @param data\n */\nexport const convertDates = (data: DataWithDates): any => {\n if (data && data.createdAt) {\n data.createdAt = new Date(data.createdAt);\n }\n\n if (data && data.updatedAt) {\n data.updatedAt = new Date(data.updatedAt);\n }\n\n if (data && data.date) {\n data.date = new Date(data.date);\n }\n\n return data;\n};\n"]}
@@ -0,0 +1,5 @@
1
+ export * from './date';
2
+ export * from './text.utils';
3
+ export * from './utils.schema';
4
+ export * from './awaitTo';
5
+ export * from './log';
@@ -0,0 +1,18 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./date"), exports);
14
+ __exportStar(require("./text.utils"), exports);
15
+ __exportStar(require("./utils.schema"), exports);
16
+ __exportStar(require("./awaitTo"), exports);
17
+ __exportStar(require("./log"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAuB;AACvB,+CAA6B;AAC7B,iDAA+B;AAC/B,4CAA0B;AAC1B,wCAAsB","sourcesContent":["export * from './date';\nexport * from './text.utils';\nexport * from './utils.schema';\nexport * from './awaitTo';\nexport * from './log';\n"]}
@@ -0,0 +1,9 @@
1
+ import debug from 'debug';
2
+ /**
3
+ * Use to log in general case
4
+ */
5
+ export declare const log: debug.Debugger;
6
+ /**
7
+ * Use for verbose log
8
+ */
9
+ export declare const verbose: debug.Debugger;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.verbose = exports.log = void 0;
7
+ var debug_1 = __importDefault(require("debug"));
8
+ var get_1 = __importDefault(require("lodash/get"));
9
+ var appName = (0, get_1.default)(process.env, 'APP_NAME', 'couchset');
10
+ var libraryPrefix = appName;
11
+ /**
12
+ * Use to log in general case
13
+ */
14
+ exports.log = (0, debug_1.default)(libraryPrefix + ":info");
15
+ /**
16
+ * Use for verbose log
17
+ */
18
+ exports.verbose = (0, debug_1.default)(libraryPrefix + ":verbose");
19
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/utils/log.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA0B;AAC1B,mDAA8B;AAE9B,IAAM,OAAO,GAAG,IAAA,aAAI,EAAC,OAAO,CAAC,GAAG,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAE1D,IAAM,aAAa,GAAG,OAAO,CAAC;AAE9B;;GAEG;AACU,QAAA,GAAG,GAAG,IAAA,eAAK,EAAI,aAAa,UAAO,CAAC,CAAC;AAElD;;GAEG;AACU,QAAA,OAAO,GAAG,IAAA,eAAK,EAAI,aAAa,aAAU,CAAC,CAAC","sourcesContent":["import debug from 'debug';\nimport _get from 'lodash/get';\n\nconst appName = _get(process.env, 'APP_NAME', 'couchset');\n\nconst libraryPrefix = appName;\n\n/**\n * Use to log in general case\n */\nexport const log = debug(`${libraryPrefix}:info`);\n\n/**\n * Use for verbose log\n */\nexport const verbose = debug(`${libraryPrefix}:verbose`);\n"]}
@@ -0,0 +1,14 @@
1
+ export declare const JSONDATA: (data: any) => Record<string, any> | string | null;
2
+ /**
3
+ * CapitalizeFirstLetter
4
+ * @param txt
5
+ * @returns
6
+ */
7
+ export declare function capText(txt: string): string;
8
+ /**
9
+ * To Snake case and in upper case
10
+ * @param txt
11
+ * @returns
12
+ */
13
+ export declare const toSnakeUpper: (txt: string) => string;
14
+ export default JSONDATA;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.toSnakeUpper = exports.capText = exports.JSONDATA = void 0;
7
+ var isEmpty_1 = __importDefault(require("lodash/isEmpty"));
8
+ var snakeCase_1 = __importDefault(require("lodash/snakeCase"));
9
+ var toUpper_1 = __importDefault(require("lodash/toUpper"));
10
+ var JSONDATA = function (data) {
11
+ if ((0, isEmpty_1.default)(data) || !data) {
12
+ return null;
13
+ }
14
+ try {
15
+ if (typeof data !== 'object') {
16
+ return JSON.parse(data);
17
+ }
18
+ return data;
19
+ }
20
+ catch (error) {
21
+ // console.log('error trying to parse response data');
22
+ return data;
23
+ }
24
+ };
25
+ exports.JSONDATA = JSONDATA;
26
+ /**
27
+ * CapitalizeFirstLetter
28
+ * @param txt
29
+ * @returns
30
+ */
31
+ function capText(txt) {
32
+ return txt.charAt(0).toUpperCase() + txt.slice(1); //or if you want lowercase the rest txt.slice(1).toLowerCase();
33
+ }
34
+ exports.capText = capText;
35
+ /**
36
+ * To Snake case and in upper case
37
+ * @param txt
38
+ * @returns
39
+ */
40
+ var toSnakeUpper = function (txt) {
41
+ return (0, toUpper_1.default)((0, snakeCase_1.default)(txt));
42
+ };
43
+ exports.toSnakeUpper = toSnakeUpper;
44
+ exports.default = exports.JSONDATA;
45
+ //# sourceMappingURL=text.utils.js.map