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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Algo Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,231 @@
1
+
2
+ <p align="center">
3
+ <h1 align="center"> CouchSet - Couchbase ORM & Automatic GraphQL API generator (Resolver/Queries)</h1>
4
+ </p>
5
+
6
+
7
+ <div align="center">
8
+
9
+ <div style="display: flex;justify-content:center;">
10
+
11
+
12
+ <img alt="NPM" src="https://img.shields.io/npm/dt/couchset.svg"></img>
13
+
14
+
15
+
16
+ </div>
17
+
18
+ <img width="500px" src="./docs/couchset.png"></img>
19
+ </div>
20
+
21
+
22
+ CouchSet is a Couchbase ORM & Automatic GraphQL API code generator (Resolver/Queries) tool
23
+
24
+
25
+ ## 1. Install
26
+ ```bash
27
+ npm i couchset --save
28
+ ```
29
+
30
+ ## 2. Start couchset
31
+ ```ts
32
+ import { couchset } from 'couchset';
33
+
34
+ const started = await couchset({
35
+ connectionString: 'couchbase://localhost',
36
+ username: 'admin',
37
+ password: '123456',
38
+ bucketName: 'stq'
39
+ })
40
+ ```
41
+
42
+ ## 3. Create a Model and start using it
43
+
44
+ ```ts
45
+ import { Model } from 'couchset';
46
+
47
+ const userModel = new Model('User');
48
+
49
+
50
+ // Create document
51
+ const created = await userModel.create({
52
+ username: 'ceddy',
53
+ password: 'love couchbase',
54
+ });
55
+
56
+ // Find document
57
+ const foundData = await userModel.findById(created.id);
58
+
59
+ // update document
60
+ const updatedData = await userModel.updateById(created.id, { ...created, someValue: 'x' });
61
+
62
+ // delete
63
+ const deletedData = await userModel.delete(created.id);
64
+
65
+ ```
66
+
67
+ ## 4. Pagination
68
+
69
+ All models come with a method for automatic pagination
70
+ ```ts
71
+ const paginationData = await userModel.pagination({
72
+ select: ["id", "email", "phone","fullname"],
73
+ where: {
74
+ userId: { $eq: "ceddy" },
75
+ $or: [{ userId: { $eq: "ceddy" } }, { phone: 10 }],
76
+ },
77
+ limit: 100,
78
+ page: 0,
79
+ });
80
+ ```
81
+
82
+ which translates to this query
83
+
84
+ ```sql
85
+ SELECT * FROM `stq` WHERE _type="User" AND userId="ceddy" AND (userId="ceddy" OR phone=10) ORDER BY createdAt DESC LIMIT 100 OFFSET 0
86
+ ```
87
+
88
+
89
+ Pagination results
90
+
91
+ ```js
92
+ [
93
+ {
94
+ id: '209d3143-09b7-4b3d-bf7d-f0ccd3f98922',
95
+ updatedAt: 2021-01-26T01:51:43.218Z,
96
+ createdAt: 2021-01-26T01:51:43.210Z,
97
+ _type: 'User',
98
+ userId: 'ceddy',
99
+ password: '...',
100
+ someValue: 'x'
101
+ },
102
+ {
103
+ id: '1392e4f6-ae1e-4e01-b7d5-103bdd0e843f',
104
+ updatedAt: 2021-01-26T01:51:29.591Z,
105
+ createdAt: 2021-01-26T01:51:29.583Z,
106
+ _type: 'User',
107
+ userId: 'ceddy',
108
+ password: '...',
109
+ someValue: 'x'
110
+ }
111
+ ]
112
+ ```
113
+
114
+
115
+ ## 5. Custom queries & Query builder
116
+ Query builder is inspired from node-ottoman, for more examples, please see https://ottomanjs.com/guides/query-builder.html#query-builder
117
+
118
+ ```ts
119
+ import { Query } from 'couchset';
120
+
121
+ const params = {
122
+ select: [
123
+ {
124
+ $count: {
125
+ $field: {
126
+ name: 'type',
127
+ },
128
+ as: 'odm',
129
+ },
130
+ },
131
+ ],
132
+ let: [
133
+ { key: 'amount_val', value: 10 },
134
+ { key: 'size_val', value: 20 },
135
+ ],
136
+ where: {
137
+ $or: [{ price: { $gt: 'amount_val', $isNotNull: true } }, { auto: { $gt: 10 } }, { amount: 10 }],
138
+ $and: [
139
+ { price2: { $gt: 1.99, $isNotNull: true } },
140
+ { $or: [{ price3: { $gt: 1.99, $isNotNull: true } }, { id: '20' }] },
141
+ ],
142
+ $any: {
143
+ $expr: [{ $in: { search_expr: 'search', target_expr: 'address' } }],
144
+ $satisfied: { address: '10' },
145
+ },
146
+ $in: { search_expr: 'search', target_expr: ['address'] },
147
+ },
148
+ groupBy: [{ expr: 'type', as: 'sch' }],
149
+ letting: [
150
+ { key: 'amount_v2', value: 10 },
151
+ { key: 'size_v2', value: 20 },
152
+ ],
153
+ having: { type: { $like: '%hotel%' } },
154
+ orderBy: { type: 'DESC' },
155
+ limit: 10,
156
+ offset: 1,
157
+ use: ['airlineR_8093', 'airlineR_8094'],
158
+ };
159
+
160
+ const query = new Query(params, 'travel-sample').build();
161
+ console.log(query);
162
+
163
+ ```
164
+
165
+ which translates to
166
+
167
+ ```sql
168
+ SELECT COUNT(type) AS odm FROM travel-sample USE KEYS ["airlineR_8093","airlineR_8094"] LET amount_val=10,size_val=20 WHERE ((price>amount_val AND price IS NOT NULL) OR auto>10 OR amount=10) AND ((price2>1.99 AND price2 IS NOT NULL) AND ((price3>1.99 AND price3 IS NOT NULL) OR id="20")) AND ANY search IN address SATISFIES address="10" END AND search IN ["address"] GROUP BY type AS sch LETTING amount_v2=10,size_v2=20 HAVING type LIKE "%hotel%" ORDER BY type DESC LIMIT 10 OFFSET 1
169
+ ```
170
+
171
+
172
+
173
+ ### Running custom query on cluster
174
+
175
+ ```ts
176
+ import { QueryCluster } from 'couchset';
177
+
178
+ const queryresults = await QueryCluster(queryBuilder);
179
+ // queryresults = { rows: object[], meta: any}
180
+
181
+ ```
182
+
183
+ ## 6. Model Automation
184
+
185
+ This is how we automate it to generate code with all methods,schema, queries
186
+
187
+ ```ts
188
+ const automaticUser = userModel.automate();
189
+ ```
190
+
191
+ After automating the model, `automaticUser` will come with Server-side Resolver functions, and client queries, mutations, subscriptions, like below
192
+
193
+
194
+ ```ts
195
+ // Get all automatic generated resolvers and queries/fragments,mutations,subscriptions
196
+ const {
197
+ resolver: UserResolver, // Server resolver for building GraphQL
198
+ modelKeys: UserSelectors, // for any custom queries or exporting
199
+ client, // client queries,mutations,subscriptions
200
+ } = automaticUser;
201
+
202
+ ```
203
+
204
+ ## 7. Write to filesystem
205
+ TODO
206
+
207
+
208
+
209
+
210
+ <br/>
211
+ <br/>
212
+ <br/>
213
+
214
+ #### Contributors needed
215
+ - Create automatic pagination ✅
216
+ - Create Schema and validation/population ✅
217
+ - Create static methods for models like `save`, `update`, `findMany` e.t.c ✅
218
+ - Automated indexes (only couchbase enterprise) ✅
219
+ - Geospatial queries ✅
220
+ - FTS queries ✅
221
+
222
+
223
+
224
+
225
+ <div align="center">
226
+ <img height="300px" src="./docs/couch.png"></img>
227
+ </div>
228
+
229
+ <p align="center">
230
+ <h1 align="center"> Algo Inc </h1>
231
+ </p>
@@ -0,0 +1,4 @@
1
+ export * from './middlewares';
2
+ export * from './model';
3
+ export * from './morpheus';
4
+ export * from './writer';
@@ -0,0 +1,17 @@
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("./middlewares"), exports);
14
+ __exportStar(require("./model"), exports);
15
+ __exportStar(require("./morpheus"), exports);
16
+ __exportStar(require("./writer"), exports);
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/automate/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAA8B;AAC9B,0CAAwB;AACxB,6CAA2B;AAC3B,2CAAyB","sourcesContent":["export * from './middlewares';\nexport * from './model';\nexport * from './morpheus';\nexport * from './writer';\n"]}
@@ -0,0 +1 @@
1
+ export * from './isAuth';
@@ -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("./isAuth"), exports);
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/automate/middlewares/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB","sourcesContent":["export * from './isAuth';\n"]}
@@ -0,0 +1,7 @@
1
+ import { MiddlewareFn } from 'type-graphql';
2
+ import { ContextType } from '../../shared';
3
+ /**
4
+ * Default isAuth middleware
5
+ * @returns
6
+ */
7
+ export declare const isAuth: MiddlewareFn<ContextType>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAuth = void 0;
4
+ var jsonwebtoken_1 = require("jsonwebtoken");
5
+ var lodash_1 = require("lodash");
6
+ /**
7
+ * Default isAuth middleware
8
+ * @returns
9
+ */
10
+ var isAuth = function (_a, next) {
11
+ var context = _a.context;
12
+ var authorization = (0, lodash_1.get)(context, 'req.headers.authorization', '');
13
+ if ((0, lodash_1.isEmpty)(authorization)) {
14
+ throw new Error('Not Authenticated');
15
+ }
16
+ try {
17
+ var token = authorization.split(' ')[1];
18
+ var verified = (0, jsonwebtoken_1.verify)(token, process.env.ACCESS_TOKEN_SECRET);
19
+ context.payload = verified;
20
+ }
21
+ catch (err) {
22
+ console.log('not authenticated');
23
+ throw new Error('not authenticated');
24
+ }
25
+ return next();
26
+ };
27
+ exports.isAuth = isAuth;
28
+ //# sourceMappingURL=isAuth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isAuth.js","sourceRoot":"","sources":["../../../src/automate/middlewares/isAuth.ts"],"names":[],"mappings":";;;AAAA,6CAAoC;AAEpC,iCAA4C;AAI5C;;;GAGG;AACI,IAAM,MAAM,GAA8B,UAAC,EAAS,EAAE,IAAI;QAAd,OAAO,aAAA;IACtD,IAAM,aAAa,GAAG,IAAA,YAAI,EAAC,OAAO,EAAE,2BAA2B,EAAE,EAAE,CAAC,CAAC;IAErE,IAAI,IAAA,gBAAO,EAAC,aAAa,CAAC,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;KACxC;IAED,IAAI;QACA,IAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,IAAM,QAAQ,GAAG,IAAA,qBAAM,EAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAoB,CAAC,CAAC;QACjE,OAAO,CAAC,OAAO,GAAG,QAAe,CAAC;KACrC;IAAC,OAAO,GAAG,EAAE;QACV,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;KACxC;IAED,OAAO,IAAI,EAAE,CAAC;AAClB,CAAC,CAAC;AAjBW,QAAA,MAAM,UAiBjB","sourcesContent":["import {verify} from 'jsonwebtoken';\nimport {MiddlewareFn} from 'type-graphql';\nimport {isEmpty, get as _get} from 'lodash';\n\nimport {ContextType} from '../../shared';\n\n/**\n * Default isAuth middleware\n * @returns\n */\nexport const isAuth: MiddlewareFn<ContextType> = ({context}, next) => {\n const authorization = _get(context, 'req.headers.authorization', '');\n\n if (isEmpty(authorization)) {\n throw new Error('Not Authenticated');\n }\n\n try {\n const token = authorization.split(' ')[1];\n const verified = verify(token, process.env.ACCESS_TOKEN_SECRET!);\n context.payload = verified as any;\n } catch (err) {\n console.log('not authenticated');\n throw new Error('not authenticated');\n }\n\n return next();\n};\n"]}
@@ -0,0 +1,12 @@
1
+ interface Props {
2
+ name: string;
3
+ fields: string[];
4
+ }
5
+ export declare const generateClient: (props: Props) => {
6
+ FRAGMENT: import("graphql").DocumentNode;
7
+ GET: import("graphql").DocumentNode;
8
+ DELETE: import("graphql").DocumentNode;
9
+ CREATE: import("graphql").DocumentNode;
10
+ PAGE: import("graphql").DocumentNode;
11
+ };
12
+ export {};
@@ -0,0 +1,33 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.generateClient = void 0;
11
+ var camelCase_1 = __importDefault(require("lodash/camelCase"));
12
+ var graphql_tag_1 = __importDefault(require("graphql-tag"));
13
+ var lodash_1 = require("lodash");
14
+ var shared_1 = require("../../shared");
15
+ var generateClient = function (props) {
16
+ // TODO inner fragments
17
+ // TODO fields mapping
18
+ var name = props.name, fields = props.fields;
19
+ var nameCamel = (0, camelCase_1.default)(name);
20
+ var fragmentName = name + "Fragment";
21
+ var fieldsJoined = (fields || []).join(',');
22
+ var FRAGMENT = (0, lodash_1.isEmpty)(fields)
23
+ ? null
24
+ : (0, graphql_tag_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n fragment ", " on ", " {\n ", "\n }\n "], ["\n fragment ", " on ", " {\n ", "\n }\n "])), fragmentName, name, fieldsJoined);
25
+ var PAGE = (0, graphql_tag_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n query Page", "($id: String!) {\n data: ", "Pagination(id: $id) {\n ...", "\n }\n }\n ", "\n "], ["\n query Page", "($id: String!) {\n data: ", "Pagination(id: $id) {\n ...", "\n }\n }\n ", "\n "])), name, nameCamel, fragmentName, FRAGMENT);
26
+ var GET = (0, graphql_tag_1.default)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n query Get", "($id: String!) {\n data: ", "Get(id: $id) {\n ...", "\n }\n }\n ", "\n "], ["\n query Get", "($id: String!) {\n data: ", "Get(id: $id) {\n ...", "\n }\n }\n ", "\n "])), name, nameCamel, fragmentName, FRAGMENT);
27
+ var DELETE = (0, graphql_tag_1.default)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n mutation Delete", "($id: String!) {\n data: ", "Delete(id: $id) {\n ...ResTypeFragment\n }\n }\n ", "\n "], ["\n mutation Delete", "($id: String!) {\n data: ", "Delete(id: $id) {\n ...ResTypeFragment\n }\n }\n ", "\n "])), name, nameCamel, shared_1.ResTypeFragment);
28
+ var CREATE = (0, graphql_tag_1.default)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n mutation Create", "($args: ", "Input!) {\n data: ", "Create(args: $args) {\n ...ResTypeFragment\n }\n }\n ", "\n "], ["\n mutation Create", "($args: ", "Input!) {\n data: ", "Create(args: $args) {\n ...ResTypeFragment\n }\n }\n ", "\n "])), name, name, nameCamel, shared_1.ResTypeFragment);
29
+ return { FRAGMENT: FRAGMENT, GET: GET, DELETE: DELETE, CREATE: CREATE, PAGE: PAGE };
30
+ };
31
+ exports.generateClient = generateClient;
32
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;
33
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/automate/model/client.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,+DAAyC;AACzC,4DAA8B;AAC9B,iCAA+B;AAE/B,uCAA6C;AAOtC,IAAM,cAAc,GAAG,UAAC,KAAY;IACvC,uBAAuB;IACvB,sBAAsB;IACf,IAAA,IAAI,GAAY,KAAK,KAAjB,EAAE,MAAM,GAAI,KAAK,OAAT,CAAU;IAE7B,IAAM,SAAS,GAAG,IAAA,mBAAS,EAAC,IAAI,CAAC,CAAC;IAClC,IAAM,YAAY,GAAM,IAAI,aAAU,CAAC;IAEvC,IAAM,YAAY,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAE9C,IAAM,QAAQ,GAAG,IAAA,gBAAO,EAAC,MAAM,CAAC;QAC5B,CAAC,CAAC,IAAI;QACN,CAAC,KAAC,qBAAG,4HAAA,iBACE,EAAY,MAAO,EAAI,cAC5B,EAAY,aAEnB,KAHY,YAAY,EAAO,IAAI,EAC5B,YAAY,CAEnB,CAAC;IAEA,IAAM,IAAI,OAAG,qBAAG,wMAAA,kBACJ,EAAI,kCACJ,EAAS,wCACR,EAAY,0BAGvB,EAAQ,MACX,KANa,IAAI,EACJ,SAAS,EACR,YAAY,EAGvB,QAAQ,CACX,CAAC;IAEA,IAAM,GAAG,OAAG,qBAAG,wLAAA,iBACJ,EAAI,gCACL,EAAS,6BACV,EAAY,wBAGnB,EAAQ,MACX,KANY,IAAI,EACL,SAAS,EACV,YAAY,EAGnB,QAAQ,CACX,CAAC;IAEA,IAAM,MAAM,OAAG,qBAAG,uNAAA,wBACA,EAAI,kCACV,EAAS,4EAInB,EAAe,OACjB,KANkB,IAAI,EACV,SAAS,EAInB,wBAAe,CACjB,CAAC;IAED,IAAM,MAAM,OAAG,qBAAG,8NAAA,uBACD,EAAI,UAAW,EAAI,2BACxB,EAAS,+EAInB,EAAe,OACjB,KANiB,IAAI,EAAW,IAAI,EACxB,SAAS,EAInB,wBAAe,CACjB,CAAC;IAED,OAAO,EAAC,QAAQ,UAAA,EAAE,GAAG,KAAA,EAAE,MAAM,QAAA,EAAE,MAAM,QAAA,EAAE,IAAI,MAAA,EAAC,CAAC;AACjD,CAAC,CAAC;AAvDW,QAAA,cAAc,kBAuDzB","sourcesContent":["import camelCase from 'lodash/camelCase';\nimport gql from 'graphql-tag';\nimport {isEmpty} from 'lodash';\n\nimport {ResTypeFragment} from '../../shared';\n\ninterface Props {\n name: string;\n fields: string[];\n}\n\nexport const generateClient = (props: Props) => {\n // TODO inner fragments\n // TODO fields mapping\n const {name, fields} = props;\n\n const nameCamel = camelCase(name);\n const fragmentName = `${name}Fragment`;\n\n const fieldsJoined = (fields || []).join(',');\n\n const FRAGMENT = isEmpty(fields)\n ? null\n : gql`\n fragment ${fragmentName} on ${name} {\n ${fieldsJoined}\n }\n `;\n\n const PAGE = gql`\n query Page${name}($id: String!) {\n data: ${nameCamel}Pagination(id: $id) {\n ...${fragmentName}\n }\n }\n ${FRAGMENT}\n `;\n\n const GET = gql`\n query Get${name}($id: String!) {\n data: ${nameCamel}Get(id: $id) {\n ...${fragmentName}\n }\n }\n ${FRAGMENT}\n `;\n\n const DELETE = gql`\n mutation Delete${name}($id: String!) {\n data: ${nameCamel}Delete(id: $id) {\n ...ResTypeFragment\n }\n }\n ${ResTypeFragment}\n `;\n\n const CREATE = gql`\n mutation Create${name}($args: ${name}Input!) {\n data: ${nameCamel}Create(args: $args) {\n ...ResTypeFragment\n }\n }\n ${ResTypeFragment}\n `;\n\n return {FRAGMENT, GET, DELETE, CREATE, PAGE};\n};\n"]}
@@ -0,0 +1,44 @@
1
+ import { ClassType } from 'type-graphql';
2
+ import { DocumentNode } from 'graphql';
3
+ import { Model } from '../../model';
4
+ import { ResType } from '../../shared';
5
+ interface PaginationResults {
6
+ items: any[];
7
+ hasNext: boolean;
8
+ params: any;
9
+ }
10
+ export interface AutomaticModelOptions extends AutomaticMethodOptions {
11
+ model: Model;
12
+ }
13
+ export interface AutomaticMethodOptions {
14
+ authMiddleware?: any;
15
+ pagination?: {
16
+ public?: boolean;
17
+ method?: (params: any) => Promise<PaginationResults>;
18
+ };
19
+ getById?: {
20
+ public?: boolean;
21
+ matchOwner?: boolean;
22
+ method?: <T>(params: any) => Promise<T & any>;
23
+ };
24
+ deleteById?: {
25
+ method?: (args: any) => Promise<ResType>;
26
+ matchOwner?: boolean;
27
+ };
28
+ createUpdate?: {
29
+ method?: <T>(args: T) => Promise<ResType>;
30
+ };
31
+ }
32
+ export interface AutomaticOutput {
33
+ pagination: ClassType;
34
+ resolver: ClassType;
35
+ modelKeys: string[];
36
+ client: Record<string, DocumentNode>;
37
+ }
38
+ /**
39
+ *
40
+ * @param c
41
+ * @returns
42
+ */
43
+ export declare const automateImplementation: <T>(ClassModelType: T & ClassType<any>, options: AutomaticModelOptions) => AutomaticOutput;
44
+ export {};