mocody 0.6.7 → 0.6.8

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 (84) hide show
  1. package/dist/index.cjs +5907 -0
  2. package/dist/index.d.cts +723 -0
  3. package/dist/index.d.ts +723 -10
  4. package/dist/index.js +5907 -9
  5. package/package.json +33 -8
  6. package/dist/core/base-schema.d.ts +0 -13
  7. package/dist/core/base-schema.js +0 -8
  8. package/dist/core/base-schema.js.map +0 -1
  9. package/dist/couch/couch-data-operation.d.ts +0 -91
  10. package/dist/couch/couch-data-operation.js +0 -528
  11. package/dist/couch/couch-data-operation.js.map +0 -1
  12. package/dist/couch/couch-filter-query-operation.d.ts +0 -45
  13. package/dist/couch/couch-filter-query-operation.js +0 -369
  14. package/dist/couch/couch-filter-query-operation.js.map +0 -1
  15. package/dist/couch/couch-initializer.d.ts +0 -126
  16. package/dist/couch/couch-initializer.js +0 -173
  17. package/dist/couch/couch-initializer.js.map +0 -1
  18. package/dist/couch/couch-manage-table.d.ts +0 -46
  19. package/dist/couch/couch-manage-table.js +0 -75
  20. package/dist/couch/couch-manage-table.js.map +0 -1
  21. package/dist/dynamo/dynamo-data-operation.d.ts +0 -101
  22. package/dist/dynamo/dynamo-data-operation.js +0 -860
  23. package/dist/dynamo/dynamo-data-operation.js.map +0 -1
  24. package/dist/dynamo/dynamo-filter-query-operation.d.ts +0 -30
  25. package/dist/dynamo/dynamo-filter-query-operation.js +0 -652
  26. package/dist/dynamo/dynamo-filter-query-operation.js.map +0 -1
  27. package/dist/dynamo/dynamo-filter-query-partiql-operation.d.ts +0 -23
  28. package/dist/dynamo/dynamo-filter-query-partiql-operation.js +0 -560
  29. package/dist/dynamo/dynamo-filter-query-partiql-operation.js.map +0 -1
  30. package/dist/dynamo/dynamo-helper.d.ts +0 -22
  31. package/dist/dynamo/dynamo-helper.js +0 -54
  32. package/dist/dynamo/dynamo-helper.js.map +0 -1
  33. package/dist/dynamo/dynamo-initializer.d.ts +0 -16
  34. package/dist/dynamo/dynamo-initializer.js +0 -52
  35. package/dist/dynamo/dynamo-initializer.js.map +0 -1
  36. package/dist/dynamo/dynamo-manage-table.d.ts +0 -33
  37. package/dist/dynamo/dynamo-manage-table.js +0 -387
  38. package/dist/dynamo/dynamo-manage-table.js.map +0 -1
  39. package/dist/dynamo/dynamo-query-partiql-processor.d.ts +0 -29
  40. package/dist/dynamo/dynamo-query-partiql-processor.js +0 -209
  41. package/dist/dynamo/dynamo-query-partiql-processor.js.map +0 -1
  42. package/dist/dynamo/dynamo-query-scan-processor.d.ts +0 -25
  43. package/dist/dynamo/dynamo-query-scan-processor.js +0 -265
  44. package/dist/dynamo/dynamo-query-scan-processor.js.map +0 -1
  45. package/dist/helpers/base-joi-helper.d.ts +0 -2
  46. package/dist/helpers/base-joi-helper.js +0 -9
  47. package/dist/helpers/base-joi-helper.js.map +0 -1
  48. package/dist/helpers/constants.d.ts +0 -3
  49. package/dist/helpers/constants.js +0 -4
  50. package/dist/helpers/constants.js.map +0 -1
  51. package/dist/helpers/errors.d.ts +0 -14
  52. package/dist/helpers/errors.js +0 -34
  53. package/dist/helpers/errors.js.map +0 -1
  54. package/dist/helpers/logging-service.d.ts +0 -9
  55. package/dist/helpers/logging-service.js +0 -46
  56. package/dist/helpers/logging-service.js.map +0 -1
  57. package/dist/helpers/mocody-utils.d.ts +0 -22
  58. package/dist/helpers/mocody-utils.js +0 -70
  59. package/dist/helpers/mocody-utils.js.map +0 -1
  60. package/dist/helpers/query-validator.d.ts +0 -21
  61. package/dist/helpers/query-validator.js +0 -102
  62. package/dist/helpers/query-validator.js.map +0 -1
  63. package/dist/helpers/util-service.d.ts +0 -38
  64. package/dist/helpers/util-service.js +0 -225
  65. package/dist/helpers/util-service.js.map +0 -1
  66. package/dist/index.js.map +0 -1
  67. package/dist/model/index.d.ts +0 -40
  68. package/dist/model/index.js +0 -3
  69. package/dist/model/index.js.map +0 -1
  70. package/dist/mongo/mongo-data-operation.d.ts +0 -89
  71. package/dist/mongo/mongo-data-operation.js +0 -557
  72. package/dist/mongo/mongo-data-operation.js.map +0 -1
  73. package/dist/mongo/mongo-filter-query-operation.d.ts +0 -45
  74. package/dist/mongo/mongo-filter-query-operation.js +0 -367
  75. package/dist/mongo/mongo-filter-query-operation.js.map +0 -1
  76. package/dist/mongo/mongo-initializer.d.ts +0 -16
  77. package/dist/mongo/mongo-initializer.js +0 -33
  78. package/dist/mongo/mongo-initializer.js.map +0 -1
  79. package/dist/mongo/mongo-table-manager.d.ts +0 -31
  80. package/dist/mongo/mongo-table-manager.js +0 -76
  81. package/dist/mongo/mongo-table-manager.js.map +0 -1
  82. package/dist/type/index.d.ts +0 -128
  83. package/dist/type/index.js +0 -2
  84. package/dist/type/index.js.map +0 -1
@@ -1,369 +0,0 @@
1
- import { MocodyErrorUtilsService } from "../helpers/errors";
2
- import { QueryValidatorCheck } from "../helpers/query-validator";
3
- const KEY_CONDITION_MAP = {
4
- $eq: "$eq",
5
- $lt: "$lt",
6
- $lte: "$lte",
7
- $gt: "$gt",
8
- $gte: "$gte",
9
- $between: "",
10
- $beginsWith: "",
11
- };
12
- const QUERY_CONDITION_MAP_PART = {
13
- $ne: "$ne",
14
- $exists: "",
15
- $in: "",
16
- $nin: "",
17
- $contains: "",
18
- $notContains: "",
19
- $elemMatch: "",
20
- $nestedMatch: "",
21
- $nestedArrayMatch: "",
22
- };
23
- const QUERY_CONDITION_MAP_FULL = { ...KEY_CONDITION_MAP, ...QUERY_CONDITION_MAP_PART };
24
- function getQueryConditionExpression(key) {
25
- if (key && Object.keys(QUERY_CONDITION_MAP_FULL).includes(key)) {
26
- const conditionExpr = QUERY_CONDITION_MAP_FULL[key];
27
- if (conditionExpr) {
28
- return conditionExpr;
29
- }
30
- }
31
- return null;
32
- }
33
- function regex_pcre_beginWith(text) {
34
- return `(?i)\\A${text}`;
35
- }
36
- function regex_pcre_contain(text) {
37
- return `(?i)${text}`;
38
- }
39
- export class CouchFilterQueryOperation {
40
- operation__filterFieldExist({ fieldName }) {
41
- const result = {
42
- [fieldName]: { $exists: true },
43
- };
44
- return result;
45
- }
46
- operation__filterFieldNotExist({ fieldName }) {
47
- const result = {
48
- [fieldName]: { $exists: false },
49
- };
50
- return result;
51
- }
52
- operation__helperFilterBasic({ fieldName, val, conditionExpr, }) {
53
- if (conditionExpr) {
54
- return {
55
- [fieldName]: { [conditionExpr]: val },
56
- };
57
- }
58
- const result = {
59
- [fieldName]: { $eq: val },
60
- };
61
- return result;
62
- }
63
- operation__filterIn({ fieldName, attrValues }) {
64
- const result = {
65
- [fieldName]: { $in: attrValues },
66
- };
67
- return result;
68
- }
69
- operation__filterNotIn({ fieldName, attrValues }) {
70
- const result = {
71
- [fieldName]: { $nin: attrValues },
72
- };
73
- return result;
74
- }
75
- operation__filterElementMatch({ fieldName, attrValues, }) {
76
- const result = {
77
- [fieldName]: {
78
- $elemMatch: attrValues,
79
- },
80
- };
81
- return result;
82
- }
83
- operation__filterContains({ fieldName, term }) {
84
- const result = {
85
- [fieldName]: { $regex: regex_pcre_contain(term) },
86
- };
87
- return result;
88
- }
89
- operation__filterNotContains({ fieldName, term }) {
90
- const result = {
91
- [fieldName]: { $not: { $regex: regex_pcre_contain(term) } },
92
- };
93
- return result;
94
- }
95
- operation__filterBetween({ fieldName, from, to }) {
96
- const result = {
97
- [fieldName]: { $gte: from, $lte: to },
98
- };
99
- return result;
100
- }
101
- operation__filterBeginsWith({ fieldName, term }) {
102
- const result = {
103
- [fieldName]: { $regex: regex_pcre_beginWith(term) },
104
- };
105
- return result;
106
- }
107
- operation__filterNestedMatchObject({ fieldName, attrValues, }) {
108
- const results = [];
109
- Object.entries(attrValues).forEach(([subFieldName, queryval]) => {
110
- let _queryValue;
111
- if (queryval && typeof queryval === "object") {
112
- _queryValue = { ...queryval };
113
- }
114
- else {
115
- _queryValue = { $eq: queryval };
116
- }
117
- Object.entries(_queryValue).forEach(([condKey, val]) => {
118
- const conditionKey = condKey;
119
- if (!Object.keys(KEY_CONDITION_MAP).includes(conditionKey)) {
120
- throw MocodyErrorUtilsService.mocody_helper_createFriendlyError(`Invalid query key: ${conditionKey} @ NestedMatchObject`);
121
- }
122
- const conditionExpr = KEY_CONDITION_MAP[conditionKey];
123
- if (conditionExpr) {
124
- const result = {
125
- [`${fieldName}.${subFieldName}`]: { [conditionExpr]: val },
126
- };
127
- results.push(result);
128
- }
129
- else {
130
- if (conditionKey === "$between") {
131
- if (!(Array.isArray(val) && val.length === 2)) {
132
- throw MocodyErrorUtilsService.mocody_helper_createFriendlyError("$between query must be an array of length 2");
133
- }
134
- const [fromVal, toVal] = val;
135
- const result = {
136
- [`${fieldName}.${subFieldName}`]: { $gte: fromVal, $lte: toVal },
137
- };
138
- results.push(result);
139
- }
140
- else if (conditionKey === "$beginsWith") {
141
- const result = {
142
- [`${fieldName}.${subFieldName}`]: { $regex: regex_pcre_beginWith(val) },
143
- };
144
- results.push(result);
145
- }
146
- else {
147
- throw MocodyErrorUtilsService.mocody_helper_createFriendlyError(`Query key: ${conditionKey} not currently supported`);
148
- }
149
- }
150
- });
151
- });
152
- return results;
153
- }
154
- operation__translateAdvancedQueryOperation({ fieldName, queryObject, }) {
155
- const queryConditions = [];
156
- Object.entries(queryObject).forEach(([condKey, conditionValue]) => {
157
- const conditionKey = condKey;
158
- if (conditionValue !== undefined) {
159
- if (conditionKey === "$between") {
160
- QueryValidatorCheck.between(conditionValue);
161
- const _queryConditions = this.operation__filterBetween({
162
- fieldName: fieldName,
163
- from: conditionValue[0],
164
- to: conditionValue[1],
165
- });
166
- queryConditions.push(_queryConditions);
167
- }
168
- else if (conditionKey === "$beginsWith") {
169
- QueryValidatorCheck.beginWith(conditionValue);
170
- const _queryConditions = this.operation__filterBeginsWith({
171
- fieldName: fieldName,
172
- term: conditionValue,
173
- });
174
- queryConditions.push(_queryConditions);
175
- }
176
- else if (conditionKey === "$contains") {
177
- QueryValidatorCheck.contains(conditionValue);
178
- const _queryConditions = this.operation__filterContains({
179
- fieldName: fieldName,
180
- term: conditionValue,
181
- });
182
- queryConditions.push(_queryConditions);
183
- }
184
- else if (conditionKey === "$notContains") {
185
- QueryValidatorCheck.notContains(conditionValue);
186
- const _queryConditions = this.operation__filterNotContains({
187
- fieldName: fieldName,
188
- term: conditionValue,
189
- });
190
- queryConditions.push(_queryConditions);
191
- }
192
- else if (conditionKey === "$in") {
193
- QueryValidatorCheck.in_query(conditionValue);
194
- const _queryConditions = this.operation__filterIn({
195
- fieldName: fieldName,
196
- attrValues: conditionValue,
197
- });
198
- queryConditions.push(_queryConditions);
199
- }
200
- else if (conditionKey === "$nin") {
201
- QueryValidatorCheck.notIn(conditionValue);
202
- const _queryConditions = this.operation__filterNotIn({
203
- fieldName: fieldName,
204
- attrValues: conditionValue,
205
- });
206
- queryConditions.push(_queryConditions);
207
- }
208
- else if (conditionKey === "$elemMatch") {
209
- QueryValidatorCheck.elemMatch(conditionValue);
210
- const _queryConditions = this.operation__filterElementMatch({
211
- fieldName: fieldName,
212
- attrValues: conditionValue,
213
- });
214
- queryConditions.push(_queryConditions);
215
- }
216
- else if (conditionKey === "$nestedMatch") {
217
- QueryValidatorCheck.nestedMatch(conditionValue);
218
- const nestedMatchConditions = this.operation__filterNestedMatchObject({
219
- fieldName: fieldName,
220
- attrValues: conditionValue,
221
- });
222
- if (nestedMatchConditions?.length) {
223
- nestedMatchConditions.forEach((_queryCondition) => {
224
- queryConditions.push(_queryCondition);
225
- });
226
- }
227
- }
228
- else if (conditionKey === "$exists") {
229
- QueryValidatorCheck.exists(conditionValue);
230
- if (String(conditionValue) === "true") {
231
- const _queryConditions = this.operation__filterFieldExist({
232
- fieldName: fieldName,
233
- });
234
- queryConditions.push(_queryConditions);
235
- }
236
- else if (String(conditionValue) === "false") {
237
- const _queryConditions = this.operation__filterFieldNotExist({
238
- fieldName: fieldName,
239
- });
240
- queryConditions.push(_queryConditions);
241
- }
242
- }
243
- else {
244
- const conditionExpr = getQueryConditionExpression(conditionKey);
245
- if (conditionExpr) {
246
- const _queryConditions = this.operation__helperFilterBasic({
247
- fieldName: fieldName,
248
- val: conditionValue,
249
- conditionExpr: conditionExpr,
250
- });
251
- queryConditions.push(_queryConditions);
252
- }
253
- else {
254
- QueryValidatorCheck.throwQueryNotFound(conditionKey);
255
- }
256
- }
257
- }
258
- });
259
- return queryConditions;
260
- }
261
- operation_translateBasicQueryOperation({ fieldName, queryObject }) {
262
- const _queryConditions = this.operation__helperFilterBasic({
263
- fieldName: fieldName,
264
- val: queryObject,
265
- });
266
- return _queryConditions;
267
- }
268
- processQueryFilter({ queryDefs }) {
269
- let queryMainConditions = [];
270
- let queryAndConditions = [];
271
- let queryOrConditions = [];
272
- Object.keys(queryDefs).forEach((fieldName_Or_And) => {
273
- if (fieldName_Or_And === "$or") {
274
- const orKey = fieldName_Or_And;
275
- const orArray = queryDefs[orKey];
276
- QueryValidatorCheck.or_query(orArray);
277
- if (orArray && Array.isArray(orArray)) {
278
- orArray.forEach((orQuery) => {
279
- Object.keys(orQuery).forEach((fieldName) => {
280
- const orQueryObjectOrValue = orQuery[fieldName];
281
- if (orQueryObjectOrValue !== undefined) {
282
- if (orQueryObjectOrValue && typeof orQueryObjectOrValue === "object") {
283
- const _orQueryCond = this.operation__translateAdvancedQueryOperation({
284
- fieldName,
285
- queryObject: orQueryObjectOrValue,
286
- });
287
- queryOrConditions = [...queryOrConditions, ..._orQueryCond];
288
- }
289
- else {
290
- const _orQueryConditions = this.operation_translateBasicQueryOperation({
291
- fieldName,
292
- queryObject: orQueryObjectOrValue,
293
- });
294
- queryOrConditions = [...queryOrConditions, _orQueryConditions];
295
- }
296
- }
297
- });
298
- });
299
- }
300
- }
301
- else if (fieldName_Or_And === "$and") {
302
- const andKey = fieldName_Or_And;
303
- const andArray = queryDefs[andKey];
304
- QueryValidatorCheck.and_query(andArray);
305
- if (andArray && Array.isArray(andArray)) {
306
- andArray.forEach((andQuery) => {
307
- Object.keys(andQuery).forEach((fieldName) => {
308
- const andQueryObjectOrValue = andQuery[fieldName];
309
- if (andQueryObjectOrValue !== undefined) {
310
- if (andQueryObjectOrValue && typeof andQueryObjectOrValue === "object") {
311
- const _andQueryCond = this.operation__translateAdvancedQueryOperation({
312
- fieldName,
313
- queryObject: andQueryObjectOrValue,
314
- });
315
- queryAndConditions = [...queryAndConditions, ..._andQueryCond];
316
- }
317
- else {
318
- const _andQueryConditions = this.operation_translateBasicQueryOperation({
319
- fieldName,
320
- queryObject: andQueryObjectOrValue,
321
- });
322
- queryAndConditions = [...queryAndConditions, _andQueryConditions];
323
- }
324
- }
325
- });
326
- });
327
- }
328
- }
329
- else {
330
- if (fieldName_Or_And) {
331
- const fieldName2 = fieldName_Or_And;
332
- const queryObjectOrValue = queryDefs[fieldName2];
333
- if (queryObjectOrValue !== undefined) {
334
- if (queryObjectOrValue && typeof queryObjectOrValue === "object") {
335
- const _queryCond = this.operation__translateAdvancedQueryOperation({
336
- fieldName: fieldName2,
337
- queryObject: queryObjectOrValue,
338
- });
339
- queryMainConditions = [...queryMainConditions, ..._queryCond];
340
- }
341
- else {
342
- const _queryConditions = this.operation_translateBasicQueryOperation({
343
- fieldName: fieldName2,
344
- queryObject: queryObjectOrValue,
345
- });
346
- queryMainConditions = [...queryMainConditions, _queryConditions];
347
- }
348
- }
349
- }
350
- }
351
- });
352
- let queryAllConditions = {};
353
- if (queryMainConditions?.length) {
354
- queryMainConditions.forEach((item1) => {
355
- if (item1) {
356
- queryAllConditions = { ...queryAllConditions, ...item1 };
357
- }
358
- });
359
- }
360
- if (queryAndConditions?.length) {
361
- queryAllConditions.$and = queryAndConditions;
362
- }
363
- if (queryOrConditions?.length) {
364
- queryAllConditions.$or = queryOrConditions;
365
- }
366
- return queryAllConditions;
367
- }
368
- }
369
- //# sourceMappingURL=couch-filter-query-operation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"couch-filter-query-operation.js","sourceRoot":"","sources":["../../src/couch/couch-filter-query-operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MA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AC;QAEH,IAAI,kBAAkB,GAAkF,EAAS,CAAC;QAElH,IAAI,mBAAmB,EAAE,MAAM,EAAE,CAAC;YAChC,mBAAmB,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;gBACpC,IAAI,KAAK,EAAE,CAAC;oBACV,kBAAkB,GAAG,EAAE,GAAG,kBAAkB,EAAE,GAAG,KAAK,EAAE,CAAC;gBAC3D,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAED,IAAI,kBAAkB,EAAE,MAAM,EAAE,CAAC;YAC/B,kBAAkB,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/C,CAAC;QAED,IAAI,iBAAiB,EAAE,MAAM,EAAE,CAAC;YAC9B,kBAAkB,CAAC,GAAG,GAAG,iBAAiB,CAAC;QAC7C,CAAC;QACD,OAAO,kBAAkB,CAAC;IAC5B,CAAC;CACF"}
@@ -1,126 +0,0 @@
1
- import type { IMocodyCoreEntityModel } from "../core/base-schema";
2
- import Nano from "nano";
3
- type IBaseDef<T> = Omit<T & IMocodyCoreEntityModel, "">;
4
- type IFindOptions = {
5
- featureEntity: string;
6
- skip: number | undefined;
7
- limit: number | undefined;
8
- selector: Nano.MangoSelector;
9
- fields: string[] | undefined;
10
- use_index: string;
11
- sort?: {
12
- [propName: string]: "asc" | "desc";
13
- }[];
14
- };
15
- interface IBasisOptions {
16
- authType: "basic";
17
- couchConfig: {
18
- host: string;
19
- password: string;
20
- username: string;
21
- databaseName: string;
22
- port?: number;
23
- protocol?: "http" | "https";
24
- };
25
- indexes?: {
26
- indexName: string;
27
- fields: string[];
28
- }[];
29
- }
30
- interface ICookieOptions {
31
- authType: "cookie";
32
- couchConfig: {
33
- host: string;
34
- databaseName: string;
35
- port?: number;
36
- protocol?: "http" | "https";
37
- cookie: string;
38
- headers?: {
39
- [key: string]: string;
40
- };
41
- };
42
- indexes?: {
43
- indexName: string;
44
- fields: string[];
45
- }[];
46
- }
47
- interface IProxyOptions {
48
- authType: "proxy";
49
- couchConfig: {
50
- host: string;
51
- databaseName: string;
52
- port?: number;
53
- protocol?: "http" | "https";
54
- proxyHeaders: {
55
- [key: string]: string;
56
- };
57
- };
58
- indexes?: {
59
- indexName: string;
60
- fields: string[];
61
- }[];
62
- }
63
- type IOptions = IProxyOptions | ICookieOptions | IBasisOptions;
64
- export declare class MocodyInitializerCouch {
65
- private _databaseInstance;
66
- private _documentScope;
67
- private readonly baseConfig;
68
- constructor(baseConfig: IOptions);
69
- deleteIndex({ ddoc, name }: {
70
- ddoc: string;
71
- name: string;
72
- }): Promise<{
73
- ok: boolean;
74
- }>;
75
- getIndexes(): Promise<{
76
- indexes: {
77
- ddoc: string;
78
- name: string;
79
- type: string;
80
- def: {
81
- fields: {
82
- [field: string]: "asc" | "desc";
83
- }[];
84
- };
85
- }[];
86
- total_rows: number;
87
- }>;
88
- findPartitionedDocs({ featureEntity, selector, fields, use_index, sort, limit, skip }: IFindOptions): Promise<Nano.MangoResponse<IBaseDef<unknown>>>;
89
- getById({ nativeId }: {
90
- nativeId: string;
91
- }): Promise<(Nano.DocumentGetResponse & IBaseDef<unknown>) | null>;
92
- getManyByIds({ nativeIds }: {
93
- nativeIds: string[];
94
- }): Promise<Nano.DocumentListResponse<IBaseDef<unknown>>>;
95
- createDoc({ validatedData }: {
96
- validatedData: any;
97
- }): Promise<Nano.DocumentInsertResponse>;
98
- updateDoc({ docRev, validatedData }: {
99
- docRev: string;
100
- validatedData: any;
101
- }): Promise<Nano.DocumentInsertResponse>;
102
- getList({ featureEntity, size, skip }: {
103
- featureEntity: string;
104
- size?: number | null;
105
- skip?: number | null;
106
- }): Promise<Nano.DocumentListResponse<IBaseDef<unknown>>>;
107
- deleteById({ docRev, nativeId }: {
108
- docRev: string;
109
- nativeId: string;
110
- }): Promise<Nano.DocumentDestroyResponse>;
111
- private getDocInstance;
112
- createIndex({ indexName, fields, dbx, }: {
113
- indexName: string;
114
- fields: string[];
115
- dbx?: Nano.DocumentScope<IBaseDef<any>>;
116
- }): Promise<{
117
- id: string;
118
- name: string;
119
- result: string;
120
- }>;
121
- checkDatabaseExists(databaseName?: string): Promise<any>;
122
- createDatabase(): Promise<Nano.DatabaseCreateResponse>;
123
- getInstance(): Promise<Nano.ServerScope>;
124
- private getInstanceBase;
125
- }
126
- export {};
@@ -1,173 +0,0 @@
1
- import { LoggingService } from "../helpers/logging-service";
2
- import Nano from "nano";
3
- import throat from "throat";
4
- import { MocodyGenericError } from "../helpers/errors";
5
- const concurrency = throat(1);
6
- export class MocodyInitializerCouch {
7
- _databaseInstance;
8
- _documentScope;
9
- baseConfig;
10
- constructor(baseConfig) {
11
- this.baseConfig = baseConfig;
12
- }
13
- async deleteIndex({ ddoc, name }) {
14
- const path = ["_index", ddoc, "json", name].join("/");
15
- const instance = await this.getInstance();
16
- const result = await instance.relax({
17
- db: this.baseConfig.couchConfig.databaseName,
18
- method: "DELETE",
19
- path,
20
- content_type: "application/json",
21
- });
22
- return result;
23
- }
24
- async getIndexes() {
25
- const instance = await this.getInstance();
26
- const result = await instance.request({
27
- db: this.baseConfig.couchConfig.databaseName,
28
- method: "GET",
29
- path: "_index",
30
- content_type: "application/json",
31
- });
32
- LoggingService.log({ indexes: result });
33
- return result;
34
- }
35
- async findPartitionedDocs({ featureEntity, selector, fields, use_index, sort, limit, skip }) {
36
- const db01 = await this.getDocInstance();
37
- return await db01.partitionedFind(featureEntity, {
38
- selector: { ...selector },
39
- fields,
40
- use_index,
41
- sort: sort?.length ? sort : undefined,
42
- limit,
43
- skip,
44
- });
45
- }
46
- async getById({ nativeId }) {
47
- try {
48
- const db01 = await this.getDocInstance();
49
- return await db01.get(nativeId);
50
- }
51
- catch (error) {
52
- const error01 = error;
53
- if (error01?.error === "not_found" || error01?.statusCode === 404) {
54
- return null;
55
- }
56
- LoggingService.error(error);
57
- throw error;
58
- }
59
- }
60
- async getManyByIds({ nativeIds }) {
61
- const db01 = await this.getDocInstance();
62
- const dataList = await db01.list({
63
- keys: nativeIds,
64
- include_docs: true,
65
- });
66
- return dataList;
67
- }
68
- async createDoc({ validatedData }) {
69
- const db01 = await this.getDocInstance();
70
- return await db01.insert(validatedData);
71
- }
72
- async updateDoc({ docRev, validatedData }) {
73
- const db01 = await this.getDocInstance();
74
- return await db01.insert({ ...validatedData, _rev: docRev });
75
- }
76
- async getList({ featureEntity, size, skip }) {
77
- const db01 = await this.getDocInstance();
78
- const data = await db01.list({
79
- include_docs: true,
80
- startkey: featureEntity,
81
- endkey: `${featureEntity}\ufff0`,
82
- inclusive_end: true,
83
- limit: size ?? undefined,
84
- skip: skip ?? undefined,
85
- });
86
- return data;
87
- }
88
- async deleteById({ docRev, nativeId }) {
89
- const db01 = await this.getDocInstance();
90
- return await db01.destroy(nativeId, docRev);
91
- }
92
- async getDocInstance() {
93
- if (!this._documentScope) {
94
- const serverScope = await this.getInstance();
95
- const db = serverScope.db.use(this.baseConfig.couchConfig.databaseName);
96
- try {
97
- if (this.baseConfig?.indexes?.length) {
98
- for (const indexItem of this.baseConfig.indexes) {
99
- await this.createIndex({ ...indexItem, dbx: db });
100
- }
101
- }
102
- }
103
- catch (error) {
104
- LoggingService.error(error);
105
- }
106
- this._documentScope = db;
107
- }
108
- return this._documentScope;
109
- }
110
- async createIndex({ indexName, fields, dbx, }) {
111
- const instance = dbx || (await this.getDocInstance());
112
- const result = await instance.createIndex({
113
- index: { fields },
114
- name: indexName,
115
- ddoc: indexName,
116
- type: "json",
117
- partitioned: true,
118
- });
119
- LoggingService.log(result);
120
- return {
121
- id: result.id,
122
- name: result.name,
123
- result: result.result,
124
- };
125
- }
126
- async checkDatabaseExists(databaseName) {
127
- const instance = await this.getInstance();
128
- const checkDbExistResult = await instance.request({
129
- db: databaseName || this.baseConfig.couchConfig.databaseName,
130
- method: "HEAD",
131
- content_type: "application/json",
132
- });
133
- LoggingService.logAsString({ checkDbExistResult });
134
- return checkDbExistResult;
135
- }
136
- async createDatabase() {
137
- const instance = await this.getInstance();
138
- return instance.db.create(this.baseConfig.couchConfig.databaseName, { partitioned: true });
139
- }
140
- async getInstance() {
141
- return await concurrency(() => this.getInstanceBase());
142
- }
143
- async getInstanceBase() {
144
- if (!this._databaseInstance) {
145
- const { host, port } = this.baseConfig.couchConfig;
146
- const protocol = this.baseConfig.couchConfig.protocol || "http";
147
- if (this.baseConfig.authType === "basic") {
148
- const { password, username } = this.baseConfig.couchConfig;
149
- const pw = encodeURIComponent(password);
150
- const uname = encodeURIComponent(username);
151
- const url = `${protocol}://${uname}:${pw}@${host}:${port}`;
152
- this._databaseInstance = Nano({ url });
153
- }
154
- else if (this.baseConfig.authType === "proxy") {
155
- const proxyHeaders = this.baseConfig.couchConfig.proxyHeaders;
156
- const url = `${protocol}://${host}:${port}`;
157
- this._databaseInstance = Nano({
158
- url,
159
- headers: proxyHeaders,
160
- });
161
- }
162
- else if (this.baseConfig.authType === "cookie") {
163
- const url = `${protocol}://${host}:${port}`;
164
- this._databaseInstance = Nano({ url, cookie: this.baseConfig.couchConfig.cookie });
165
- }
166
- else {
167
- throw new MocodyGenericError("Invalid auth type definition");
168
- }
169
- }
170
- return await Promise.resolve(this._databaseInstance);
171
- }
172
- }
173
- //# sourceMappingURL=couch-initializer.js.map