@nextage/nx-frame-be 1.0.1

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 (119) hide show
  1. package/README.md +1 -0
  2. package/README.md.old +45 -0
  3. package/build/app.d.ts +0 -0
  4. package/build/app.js +1 -0
  5. package/build/aws/aws-cluster-manager.d.ts +28 -0
  6. package/build/aws/aws-cluster-manager.js +105 -0
  7. package/build/aws/aws-email-manager.d.ts +24 -0
  8. package/build/aws/aws-email-manager.js +57 -0
  9. package/build/aws/aws-queue-manager.d.ts +37 -0
  10. package/build/aws/aws-queue-manager.js +100 -0
  11. package/build/aws/aws.interfaces.d.ts +39 -0
  12. package/build/aws/aws.interfaces.js +2 -0
  13. package/build/aws/index.d.ts +4 -0
  14. package/build/aws/index.js +20 -0
  15. package/build/common/base/__test__/base.model.test.d.ts +1 -0
  16. package/build/common/base/__test__/base.model.test.js +283 -0
  17. package/build/common/base/base.controller.d.ts +124 -0
  18. package/build/common/base/base.controller.js +134 -0
  19. package/build/common/base/base.interfaces.d.ts +81 -0
  20. package/build/common/base/base.interfaces.js +2 -0
  21. package/build/common/base/base.model.d.ts +384 -0
  22. package/build/common/base/base.model.js +730 -0
  23. package/build/common/base/folded.model.d.ts +41 -0
  24. package/build/common/base/folded.model.js +215 -0
  25. package/build/common/base/mongo-utils.d.ts +122 -0
  26. package/build/common/base/mongo-utils.js +242 -0
  27. package/build/common/base/mongo.types.d.ts +20 -0
  28. package/build/common/base/mongo.types.js +2 -0
  29. package/build/common/base/sql-utils.d.ts +20 -0
  30. package/build/common/base/sql-utils.js +69 -0
  31. package/build/common/constants.d.ts +27 -0
  32. package/build/common/constants.js +70 -0
  33. package/build/common/crypto/crypto.classes.d.ts +100 -0
  34. package/build/common/crypto/crypto.classes.js +146 -0
  35. package/build/common/crypto/crypto.constants.d.ts +68 -0
  36. package/build/common/crypto/crypto.constants.js +57 -0
  37. package/build/common/crypto/crypto.error.d.ts +4 -0
  38. package/build/common/crypto/crypto.error.js +10 -0
  39. package/build/common/crypto/crypto.interfaces.d.ts +46 -0
  40. package/build/common/crypto/crypto.interfaces.js +2 -0
  41. package/build/common/crypto/crypto.utils.d.ts +139 -0
  42. package/build/common/crypto/crypto.utils.js +380 -0
  43. package/build/common/crypto/index.d.ts +3 -0
  44. package/build/common/crypto/index.js +19 -0
  45. package/build/common/enums.d.ts +61 -0
  46. package/build/common/enums.js +75 -0
  47. package/build/common/errors.d.ts +13 -0
  48. package/build/common/errors.js +24 -0
  49. package/build/common/express/express.interfaces.d.ts +20 -0
  50. package/build/common/express/express.interfaces.js +2 -0
  51. package/build/common/express/express.utils.d.ts +31 -0
  52. package/build/common/express/express.utils.js +85 -0
  53. package/build/common/express/index.d.ts +2 -0
  54. package/build/common/express/index.js +18 -0
  55. package/build/common/graphql/__test__/generator.schema.test.d.ts +1 -0
  56. package/build/common/graphql/__test__/generator.schema.test.js +391 -0
  57. package/build/common/graphql/directives.d.ts +18 -0
  58. package/build/common/graphql/directives.js +56 -0
  59. package/build/common/graphql/generator copy.d.ts +41 -0
  60. package/build/common/graphql/generator copy.js +385 -0
  61. package/build/common/graphql/generator.d.ts +42 -0
  62. package/build/common/graphql/generator.js +385 -0
  63. package/build/common/graphql/index.d.ts +4 -0
  64. package/build/common/graphql/index.js +21 -0
  65. package/build/common/graphql/interfaces.d.ts +67 -0
  66. package/build/common/graphql/interfaces.js +2 -0
  67. package/build/common/graphql/loader.d.ts +22 -0
  68. package/build/common/graphql/loader.js +186 -0
  69. package/build/common/graphql/scalars/index.d.ts +10 -0
  70. package/build/common/graphql/scalars/index.js +6 -0
  71. package/build/common/graphql/scalars/resolvers.d.ts +8 -0
  72. package/build/common/graphql/scalars/resolvers.js +71 -0
  73. package/build/common/graphql/scalars/schema.d.ts +1 -0
  74. package/build/common/graphql/scalars/schema.js +12 -0
  75. package/build/common/graphql/types/index.d.ts +3 -0
  76. package/build/common/graphql/types/index.js +6 -0
  77. package/build/common/graphql/types/schema.d.ts +1 -0
  78. package/build/common/graphql/types/schema.js +98 -0
  79. package/build/common/graphql/utils.d.ts +18 -0
  80. package/build/common/graphql/utils.js +40 -0
  81. package/build/common/grid-fs/gridfs-base.model.d.ts +53 -0
  82. package/build/common/grid-fs/gridfs-base.model.js +95 -0
  83. package/build/common/grid-fs/gridfs.interfaces.d.ts +41 -0
  84. package/build/common/grid-fs/gridfs.interfaces.js +2 -0
  85. package/build/common/index.d.ts +10 -0
  86. package/build/common/index.js +32 -0
  87. package/build/common/interfaces.d.ts +26 -0
  88. package/build/common/interfaces.js +10 -0
  89. package/build/common/manager/bulk-manager.d.ts +59 -0
  90. package/build/common/manager/bulk-manager.js +103 -0
  91. package/build/common/manager/crypto-manager.d.ts +88 -0
  92. package/build/common/manager/crypto-manager.js +200 -0
  93. package/build/common/manager/index.d.ts +5 -0
  94. package/build/common/manager/index.js +21 -0
  95. package/build/common/manager/pubsub-manager.d.ts +20 -0
  96. package/build/common/manager/pubsub-manager.js +38 -0
  97. package/build/common/manager/shutdown-manager.d.ts +27 -0
  98. package/build/common/manager/shutdown-manager.js +118 -0
  99. package/build/common/manager/socket-io-cli-manager.d.ts +53 -0
  100. package/build/common/manager/socket-io-cli-manager.js +91 -0
  101. package/build/common/manager/tunnel-manager.d.ts +28 -0
  102. package/build/common/manager/tunnel-manager.js +49 -0
  103. package/build/common/models/coded-entity.controller.d.ts +5 -0
  104. package/build/common/models/coded-entity.controller.js +9 -0
  105. package/build/common/models/coded-entity.model.d.ts +25 -0
  106. package/build/common/models/coded-entity.model.js +51 -0
  107. package/build/common/models/user.model.d.ts +56 -0
  108. package/build/common/models/user.model.js +72 -0
  109. package/build/common/types.d.ts +136 -0
  110. package/build/common/types.js +16 -0
  111. package/build/common/utils.d.ts +552 -0
  112. package/build/common/utils.js +1100 -0
  113. package/build/index.d.ts +2 -0
  114. package/build/index.js +18 -0
  115. package/build/test/env.d.ts +0 -0
  116. package/build/test/env.js +5 -0
  117. package/build/test/setup.d.ts +6 -0
  118. package/build/test/setup.js +59 -0
  119. package/package.json +90 -0
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authDirective = exports.getUser = exports.createAuthDirective = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const utils_1 = require("@graphql-tools/utils");
6
+ const errors_1 = require("../errors");
7
+ const errors_2 = require("../errors");
8
+ function createAuthDirective(directiveName, getUserFn) {
9
+ const typeDirectiveArgumentMaps = {};
10
+ return {
11
+ name: directiveName,
12
+ typeDefs: `directive @${directiveName}(requires: String = "") on OBJECT | FIELD_DEFINITION`,
13
+ transformer: (schema) => {
14
+ return (0, utils_1.mapSchema)(schema, {
15
+ [utils_1.MapperKind.TYPE]: type => {
16
+ const authDirective = ((0, utils_1.getDirective)(schema, type, directiveName) || [])[0];
17
+ if (authDirective)
18
+ typeDirectiveArgumentMaps[type.name] = authDirective;
19
+ return undefined;
20
+ },
21
+ [utils_1.MapperKind.OBJECT_FIELD]: (fieldConfig, _fieldName, typeName) => {
22
+ const authDirective = ((0, utils_1.getDirective)(schema, fieldConfig, directiveName) || [])[0] || typeDirectiveArgumentMaps[typeName];
23
+ if (!authDirective)
24
+ return;
25
+ const { requires } = authDirective;
26
+ const { resolve = graphql_1.defaultFieldResolver } = fieldConfig;
27
+ fieldConfig.resolve = function (source, args, context, info) {
28
+ const user = getUserFn(context); // getUserFn(context.headers.authToken);
29
+ if (!user || !user.id)
30
+ throw new errors_1.AuthenticationError('messages.authentication.required');
31
+ // if (user.err)
32
+ // throw new AuthenticationError('messages.authentication.required');
33
+ // user exists but is not active
34
+ if (!user.active)
35
+ throw new errors_1.AuthenticationError('messages.authentication.required');
36
+ if (requires && !user.hasRole(requires.split(',')))
37
+ throw new errors_2.ForbiddenError('messages.authorization.missingRole');
38
+ return resolve(source, args, context, info);
39
+ };
40
+ return fieldConfig;
41
+ }
42
+ });
43
+ }
44
+ };
45
+ }
46
+ exports.createAuthDirective = createAuthDirective;
47
+ /**
48
+ *
49
+ * @param {*} context
50
+ * @returns
51
+ */
52
+ function getUser(context) {
53
+ return context.user || null;
54
+ }
55
+ exports.getUser = getUser;
56
+ exports.authDirective = createAuthDirective('auth', getUser);
@@ -0,0 +1,41 @@
1
+ import { BaseModel } from '../base/base.model';
2
+ import { NxGraphQLBaseSubscriptionNames, NxGraphQLSchemaDataAttrs } from './interfaces';
3
+ import { NxGraphQLSchemaExtension } from './interfaces';
4
+ export declare const codedEntityFields: NxGraphQLSchemaDataAttrs;
5
+ export declare const foldedEntityFields: {
6
+ type: string;
7
+ query: string;
8
+ input: string;
9
+ };
10
+ export declare const mainSubChannel = "mainCH";
11
+ /**
12
+ *
13
+ * @param item
14
+ * @param model
15
+ * @param schemaExtension
16
+ * @param eventType
17
+ */
18
+ export declare function publishEventSubData(item: any, model: BaseModel<any, any, any>, schemaExtension: NxGraphQLSchemaExtension | undefined, eventType: keyof NxGraphQLBaseSubscriptionNames): void;
19
+ /**
20
+ *
21
+ * @param item
22
+ * @param model
23
+ * @param schemaExtension
24
+ */
25
+ export declare function publishUpdateSubData(item: any, model: BaseModel<any, any, any>, schemaExtension?: NxGraphQLSchemaExtension): void;
26
+ /**
27
+ *
28
+ * @param item
29
+ * @param subId
30
+ * @param payload
31
+ * @param subChannelAttr
32
+ */
33
+ export declare function publishSubData(item: any, subId: string, payload?: string, subChannelAttr?: string): void;
34
+ /**
35
+ *
36
+ * @param model
37
+ * @param schemaExtension
38
+ * @param mergeCodedEntity
39
+ * @param readOnly
40
+ */
41
+ export declare function generateSchema<T extends BaseModel<any, any, any>>(model: T, schemaExtension?: NxGraphQLSchemaExtension, mergeCodedEntity?: boolean, readOnly?: boolean): void;
@@ -0,0 +1,385 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.generateSchema = exports.publishSubData = exports.publishUpdateSubData = exports.publishEventSubData = exports.mainSubChannel = exports.foldedEntityFields = exports.codedEntityFields = void 0;
13
+ const utils_1 = require("../utils");
14
+ const loader_1 = require("./loader");
15
+ const utils_2 = require("./utils");
16
+ exports.codedEntityFields = {
17
+ type: `
18
+ id : ID!
19
+ code : String!
20
+ name : String!
21
+ description: String
22
+ startDate : Date
23
+ endDate : Date
24
+ `,
25
+ query: `
26
+ id : RegExp
27
+ code : RegExp
28
+ name : RegExp
29
+ description: RegExp
30
+ rangeDate : FilterDate
31
+ startDate : Date
32
+ endDate : Date
33
+ `,
34
+ input: `
35
+ code : String
36
+ name : String
37
+ description: String
38
+ startDate : Date
39
+ endDate : Date
40
+ `
41
+ };
42
+ exports.foldedEntityFields = {
43
+ type: `
44
+ id : ID!
45
+ title : String
46
+ name : String
47
+ description : String
48
+ locked : Boolean
49
+ public : Boolean
50
+ folder : Boolean
51
+ folderId : String
52
+ ownerId : String
53
+ users : [JSON]
54
+ organizations: [JSON]
55
+ `,
56
+ query: `
57
+ title : String
58
+ name : RegExp
59
+ description : String
60
+ public : Boolean
61
+ folder : Boolean
62
+ folderId : String
63
+ `,
64
+ input: `
65
+ title : String
66
+ name : String
67
+ description : String
68
+ locked : Boolean
69
+ public : Boolean
70
+ folder : Boolean
71
+ folderId : String
72
+ ownerId : String
73
+ users : [JSON]
74
+ organizations: [JSON]
75
+ `
76
+ };
77
+ exports.mainSubChannel = 'mainCH';
78
+ /**
79
+ *
80
+ * @param modelName
81
+ * @returns
82
+ */
83
+ function getMethodNames(modelName) {
84
+ const lowerModelName = modelName[0].toLowerCase() + modelName.slice(1);
85
+ return {
86
+ count: `${lowerModelName}Count`,
87
+ list: `${lowerModelName}List`,
88
+ get: `${lowerModelName}`,
89
+ findOne: `findOne${modelName}`,
90
+ create: `create${modelName}`,
91
+ update: `update${modelName}`,
92
+ remove: `remove${modelName}`,
93
+ copy: `copy${modelName}`,
94
+ addArrayItem: `add${modelName}ArrayItem`,
95
+ updateArrayItem: `update${modelName}ArrayItem`,
96
+ removeArrayItem: `remove${modelName}ArrayItem`,
97
+ bulkUpdate: `bulkUpdate${modelName}`,
98
+ bulkRemove: `bulkRemove${modelName}`,
99
+ };
100
+ }
101
+ /**
102
+ *
103
+ * @param modelName
104
+ * @returns
105
+ */
106
+ function getSubscriptionNames(modelName) {
107
+ const lowerModelName = modelName[0].toLowerCase() + modelName.slice(1);
108
+ return {
109
+ create: { id: `${lowerModelName}CreateEvent`, payload: `${lowerModelName}Added` },
110
+ update: { id: `${lowerModelName}UpdateEvent`, payload: `${lowerModelName}Changed` },
111
+ remove: { id: `${lowerModelName}RemoveEvent`, payload: `${lowerModelName}Removed` },
112
+ // addArrayItem : {},
113
+ // updateArrayItem: {},
114
+ // removeArrayItem: {}
115
+ };
116
+ }
117
+ /**
118
+ *
119
+ * @param extension
120
+ * @returns
121
+ */
122
+ function getAuth(extension = {}) {
123
+ const roles = { read: '', write: '' };
124
+ if (!extension.roles)
125
+ return roles;
126
+ if ((0, utils_1.isString)(extension.roles))
127
+ extension.roles = extension.roles.split(',');
128
+ if (Array.isArray(extension.roles))
129
+ extension.roles = { read: extension.roles, write: extension.roles };
130
+ const sr = extension.roles;
131
+ if ((sr.read))
132
+ roles.read = `(requires: "${Array.isArray(sr.read) ? sr.read.join(',') : sr.read}")`;
133
+ if (sr.write)
134
+ roles.write = `(requires: "${Array.isArray(sr.write) ? sr.write.join(',') : sr.write}")`;
135
+ return roles;
136
+ }
137
+ /**
138
+ *
139
+ * @param model
140
+ * @param schemaExtension
141
+ * @param mergeCodedEntity
142
+ * @param readOnly
143
+ * @returns
144
+ */
145
+ function generateTypeDefs(model, schemaExtension = {}, mergeCodedEntity, readOnly) {
146
+ const modelName = getModelName(model, schemaExtension);
147
+ const methods = getMethodNames(modelName);
148
+ const subscriptions = getSubscriptionNames(modelName);
149
+ const roles = getAuth(schemaExtension);
150
+ const typeDefs = schemaExtension.typeDefs || {};
151
+ let dataFields = schemaExtension.fields;
152
+ if (dataFields && mergeCodedEntity) {
153
+ dataFields.type = `${exports.codedEntityFields.type}${dataFields.type}`;
154
+ dataFields.input = `${exports.codedEntityFields.input}${dataFields.input}`;
155
+ dataFields.query = `${exports.codedEntityFields.query}${dataFields.query}`;
156
+ }
157
+ else if (!dataFields)
158
+ dataFields = exports.codedEntityFields;
159
+ const baseTypeDefs = {
160
+ query: `
161
+ ${methods.count}(params: ${modelName}Query) : Int! @auth${roles.read}
162
+ ${methods.list}(params: ${modelName}Query, pagination: OffsetPagination): [${modelName}]! @auth${roles.read}
163
+ ${methods.get}(id: ID!) : ${modelName}! @auth${roles.read}
164
+ ${methods.findOne}(params: ${modelName}Query) : ${modelName} @auth${roles.read}
165
+ `,
166
+ mutation: `
167
+ ${methods.create}(item: ${modelName}Input!) : ${modelName}! @auth${roles.write}
168
+ ${methods.update}(id: ID!, item: ${modelName}Input!) : ${modelName}! @auth${roles.write}
169
+ ${methods.remove}(id: ID!) : String! @auth${roles.write}
170
+ ${methods.copy}(id: ID!, item: ${modelName}Input!) : ${modelName}! @auth${roles.write}
171
+
172
+ ${methods.addArrayItem}(id: ID!, item: AddArrayElemItem!) : ${modelName}! @auth${roles.write}
173
+ ${methods.updateArrayItem}(id: ID!, item: UpdateArrayElemItem!) : ${modelName}! @auth${roles.write}
174
+ ${methods.removeArrayItem}(id: ID!, item: RemoveArrayElemItem!) : ${modelName}! @auth${roles.write}
175
+
176
+ ${methods.bulkUpdate}(ids: [ID]!, items: [${modelName}Input]!) : [${modelName}]! @auth${roles.write}
177
+ ${methods.bulkRemove}(ids: [ID]!) : [${modelName}]! @auth${roles.write}
178
+ `,
179
+ subscription: `
180
+ ${subscriptions.create.id}(channelId: String!, filter: ${modelName}Query): ${modelName}! @auth${roles.read}
181
+ ${subscriptions.update.id}(channelId: String!, filter: ${modelName}Query): ${modelName}! @auth${roles.read}
182
+ ${subscriptions.remove.id}(channelId: String!, filter: ${modelName}Query): ${modelName}! @auth${roles.read}
183
+ `,
184
+ type: `
185
+ type ${modelName} {
186
+ ${dataFields.type}
187
+ }
188
+
189
+ input ${modelName}Query {
190
+ ${dataFields.query}
191
+ text : RegExp
192
+ pagination: OffsetPagination
193
+ }
194
+
195
+ input ${modelName}Input {
196
+ ${dataFields.input || 'noattr: String'}
197
+ }
198
+ `
199
+ };
200
+ return {
201
+ query: `
202
+ ${baseTypeDefs.query}
203
+ ${typeDefs.query || ''}
204
+ `,
205
+ mutation: `
206
+ ${readOnly ? '' : baseTypeDefs.mutation}
207
+ ${typeDefs.mutation || ''}
208
+ `,
209
+ subscription: `
210
+ ${readOnly ? '' : baseTypeDefs.subscription}
211
+ ${typeDefs.subscription || ''}
212
+ `,
213
+ type: `
214
+ ${baseTypeDefs.type}
215
+ ${typeDefs.type || ''}
216
+ `
217
+ };
218
+ }
219
+ /**
220
+ *
221
+ * @param model
222
+ * @param schemaExtension
223
+ * @param readOnly
224
+ * @returns
225
+ */
226
+ function generateResolvers(model, schemaExtension = {}, readOnly) {
227
+ const modelName = getModelName(model, schemaExtension);
228
+ const methods = getMethodNames(modelName);
229
+ const subscriptions = getSubscriptionNames(modelName);
230
+ const resolvers = { Query: {}, Mutation: {}, Subscription: {} };
231
+ resolvers.Query[methods.count] = (root, { params }, context) => model.count(params, context);
232
+ resolvers.Query[methods.list] = (root, { params, fields, pagination }, context) => model.list(params, fields, pagination, context);
233
+ resolvers.Query[methods.get] = (root, { id }, context) => model.get(id, context);
234
+ resolvers.Query[methods.findOne] = (root, { params }, context) => model.findOne(params, context);
235
+ if (!readOnly) {
236
+ resolvers.Mutation[methods.create] = (root, { item }, context) => appendSubscription(() => model.create(item, context), subscriptions.create.id, subscriptions.create.payload, schemaExtension.subChannelAttr);
237
+ resolvers.Mutation[methods.update] = (root, { id, item }, context) => appendSubscription(() => model.update(id, item, context), subscriptions.update.id, subscriptions.update.payload, schemaExtension.subChannelAttr);
238
+ resolvers.Mutation[methods.remove] = (root, { id }, context) => appendSubscription(() => model.remove(id, context), subscriptions.remove.id, subscriptions.remove.payload, schemaExtension.subChannelAttr);
239
+ resolvers.Mutation[methods.copy] = (root, { id, item }, context) => appendSubscription(() => model.copy(id, item, context), subscriptions.create.id, subscriptions.create.payload, schemaExtension.subChannelAttr);
240
+ // resolvers.Mutation[methods.create] = (root, { item }, context) => model.create(item, context);
241
+ // resolvers.Mutation[methods.update] = (root, { id, item }, context) => model.update(id, item, context);
242
+ // resolvers.Mutation[methods.remove] = (root, { id }, context) => model.remove(id, context);
243
+ resolvers.Mutation[methods.addArrayItem] = (root, { id, item }, context) => model.addArrayItem(id, { arrayPath: item.path, item: item.data }, { new: true }, context);
244
+ resolvers.Mutation[methods.updateArrayItem] = (root, { id, item }, context) => model.updateArrayItem(id, { arrayPath: item.path, arrayFilter: item.filter, updateAttr: item.updateAttr, partial: item.partial, item: item.data }, {}, context);
245
+ resolvers.Mutation[methods.removeArrayItem] = (root, { id, item }, context) => model.removeArrayItem(id, { arrayPath: item.path, item: item.data }, { new: true }, context);
246
+ resolvers.Mutation[methods.bulkUpdate] = (root, { ids, items }, context) => model.bulkUpdate(ids, items, context);
247
+ resolvers.Mutation[methods.bulkRemove] = (root, { ids }, context) => model.bulkRemove(ids, context);
248
+ resolvers.Subscription[subscriptions.create.id] = generateSubscription(model, subscriptions.create);
249
+ resolvers.Subscription[subscriptions.update.id] = generateSubscription(model, subscriptions.update);
250
+ resolvers.Subscription[subscriptions.remove.id] = generateSubscription(model, subscriptions.remove);
251
+ }
252
+ if (!schemaExtension.resolvers)
253
+ return resolvers;
254
+ if (schemaExtension.resolvers.Query)
255
+ Object.assign(resolvers.Query, schemaExtension.resolvers.Query);
256
+ if (schemaExtension.resolvers.Mutation)
257
+ Object.assign(resolvers.Mutation, schemaExtension.resolvers.Mutation);
258
+ if (schemaExtension.resolvers.Subscription)
259
+ Object.assign(resolvers.Subscription, schemaExtension.resolvers.Subscription);
260
+ if (schemaExtension.resolvers.Other)
261
+ Object.assign(resolvers, schemaExtension.resolvers.Other);
262
+ return resolvers;
263
+ }
264
+ /**
265
+ *
266
+ * @param {*} model
267
+ * @param {*} extension
268
+ */
269
+ function getModelName(model, extension = {}) {
270
+ const modelName = extension.modelName || model.modelName || model.name;
271
+ return modelName[0].toUpperCase() + modelName.slice(1);
272
+ }
273
+ /**
274
+ *
275
+ * @param model
276
+ * @param subscription
277
+ * @returns
278
+ */
279
+ function generateSubscription(model, subscription) {
280
+ if (!(subscription === null || subscription === void 0 ? void 0 : subscription.id))
281
+ throw new Error('Missing subscription id');
282
+ let payloadKeys = [];
283
+ if (subscription.payload)
284
+ payloadKeys = (0, utils_1.isObject)(subscription.payload) ? Object.values(subscription.payload) : [subscription.payload];
285
+ payloadKeys.push(subscription.id);
286
+ return {
287
+ // include resolve to manipulate payload
288
+ resolve: (payload_1, _a, context_1) => __awaiter(this, [payload_1, _a, context_1], void 0, function* (payload, { channelId, filter }, context) {
289
+ if (!payload)
290
+ return false;
291
+ for (let pk of payloadKeys) {
292
+ // if (payload[pk] && model.checkContextPermission(payload[pk], context))
293
+ // return payload[pk];//filterObject(payload[pk], filter) || false;
294
+ if (payload[pk])
295
+ return yield model.checkContextPermission(payload[pk], context);
296
+ return null;
297
+ //return payload[pk];//filterObject(payload[pk], filter) || false;
298
+ }
299
+ }),
300
+ subscribe: (0, utils_2.getChannelSubscriber)(subscription.id, subscription.payload, model)
301
+ };
302
+ }
303
+ /**
304
+ *
305
+ * @param method
306
+ * @param subId
307
+ * @param payload
308
+ * @param subChannelAttr
309
+ * @returns
310
+ */
311
+ function appendSubscription() {
312
+ return __awaiter(this, arguments, void 0, function* (method = () => Promise.resolve({}), subId, payload, subChannelAttr) {
313
+ if (!subId || !process.env.GRAPHQL_WS)
314
+ return method();
315
+ if (!payload)
316
+ payload = subId;
317
+ let promise = method();
318
+ if (!promise)
319
+ return Promise.resolve();
320
+ if (!promise.then)
321
+ promise = Promise.resolve(promise);
322
+ const item = yield promise;
323
+ publishSubData(item, subId, payload, subChannelAttr);
324
+ return item;
325
+ });
326
+ }
327
+ /**
328
+ *
329
+ * @param item
330
+ * @param model
331
+ * @param schemaExtension
332
+ * @param eventType
333
+ */
334
+ function publishEventSubData(item, model, schemaExtension = {}, eventType) {
335
+ const modelName = getModelName(model, schemaExtension);
336
+ const subscriptions = getSubscriptionNames(modelName);
337
+ publishSubData(item, subscriptions[eventType].id, subscriptions[eventType].payload, schemaExtension.subChannelAttr);
338
+ }
339
+ exports.publishEventSubData = publishEventSubData;
340
+ /**
341
+ *
342
+ * @param item
343
+ * @param model
344
+ * @param schemaExtension
345
+ */
346
+ function publishUpdateSubData(item, model, schemaExtension = {}) {
347
+ const modelName = getModelName(model, schemaExtension);
348
+ const subscriptions = getSubscriptionNames(modelName);
349
+ publishSubData(item, subscriptions.update.id, subscriptions.update.payload, schemaExtension.subChannelAttr);
350
+ }
351
+ exports.publishUpdateSubData = publishUpdateSubData;
352
+ /**
353
+ *
354
+ * @param item
355
+ * @param subId
356
+ * @param payload
357
+ * @param subChannelAttr
358
+ */
359
+ function publishSubData(item, subId, payload, subChannelAttr) {
360
+ if (!payload)
361
+ payload = subId;
362
+ const data = {};
363
+ data[payload] = item;
364
+ data[payload].nxChannelId = [exports.mainSubChannel];
365
+ if (item.id)
366
+ data[payload].nxChannelId.push(item.id.toString());
367
+ if (subChannelAttr && (subChannelAttr = (0, utils_1.getAttr)(item, subChannelAttr)))
368
+ data[payload].nxChannelId.push(subChannelAttr.toString());
369
+ console.log('CHANNEL IDS', data[payload].nxChannelId);
370
+ utils_2.pubsub.publish(subId, data);
371
+ }
372
+ exports.publishSubData = publishSubData;
373
+ /**
374
+ *
375
+ * @param model
376
+ * @param schemaExtension
377
+ * @param mergeCodedEntity
378
+ * @param readOnly
379
+ */
380
+ function generateSchema(model, schemaExtension = {}, mergeCodedEntity = false, readOnly = false) {
381
+ const typeDefs = generateTypeDefs(model, schemaExtension, mergeCodedEntity, readOnly);
382
+ const resolvers = generateResolvers(model, schemaExtension, readOnly);
383
+ (0, loader_1.loadSchema)({ typeDefs, resolvers });
384
+ }
385
+ exports.generateSchema = generateSchema;
@@ -0,0 +1,42 @@
1
+ import { BaseModel } from '../base/base.model';
2
+ import { BaseController } from '../base/base.controller';
3
+ import { NxGraphQLBaseSubscriptionNames, NxGraphQLSchemaDataAttrs } from './interfaces';
4
+ import { NxGraphQLSchemaExtension } from './interfaces';
5
+ export declare const codedEntityFields: NxGraphQLSchemaDataAttrs;
6
+ export declare const foldedEntityFields: {
7
+ type: string;
8
+ query: string;
9
+ input: string;
10
+ };
11
+ export declare const mainSubChannel = "mainCH";
12
+ /**
13
+ *
14
+ * @param item
15
+ * @param model
16
+ * @param schemaExtension
17
+ * @param eventType
18
+ */
19
+ export declare function publishEventSubData(item: any, model: BaseModel<any, any, any>, schemaExtension: NxGraphQLSchemaExtension | undefined, eventType: keyof NxGraphQLBaseSubscriptionNames): void;
20
+ /**
21
+ *
22
+ * @param item
23
+ * @param model
24
+ * @param schemaExtension
25
+ */
26
+ export declare function publishUpdateSubData(item: any, model: BaseModel<any, any, any>, schemaExtension?: NxGraphQLSchemaExtension): void;
27
+ /**
28
+ *
29
+ * @param item
30
+ * @param subId
31
+ * @param payload
32
+ * @param subChannelAttr
33
+ */
34
+ export declare function publishSubData(item: any, subId: string, payload?: string, subChannelAttr?: string): void;
35
+ /**
36
+ *
37
+ * @param model
38
+ * @param schemaExtension
39
+ * @param mergeCodedEntity
40
+ * @param readOnly
41
+ */
42
+ export declare function generateSchema<T extends BaseController<any, any, any>>(ctrl: T, schemaExtension?: NxGraphQLSchemaExtension, mergeCodedEntity?: boolean, readOnly?: boolean): void;