@memberjunction/codegen-lib 0.9.2

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 (50) hide show
  1. package/dist/angular_client_codegen.d.ts +2 -0
  2. package/dist/angular_client_codegen.js +360 -0
  3. package/dist/angular_client_codegen.js.map +1 -0
  4. package/dist/config.d.ts +101 -0
  5. package/dist/config.js +55 -0
  6. package/dist/config.js.map +1 -0
  7. package/dist/db.d.ts +3 -0
  8. package/dist/db.js +19 -0
  9. package/dist/db.js.map +1 -0
  10. package/dist/dbSchema.d.ts +3 -0
  11. package/dist/dbSchema.js +143 -0
  12. package/dist/dbSchema.js.map +1 -0
  13. package/dist/entity_subclasses_codegen.d.ts +4 -0
  14. package/dist/entity_subclasses_codegen.js +84 -0
  15. package/dist/entity_subclasses_codegen.js.map +1 -0
  16. package/dist/graphql_client_codegen.d.ts +4 -0
  17. package/dist/graphql_client_codegen.js +161 -0
  18. package/dist/graphql_client_codegen.js.map +1 -0
  19. package/dist/graphql_server_codegen.d.ts +5 -0
  20. package/dist/graphql_server_codegen.js +509 -0
  21. package/dist/graphql_server_codegen.js.map +1 -0
  22. package/dist/index.d.ts +15 -0
  23. package/dist/index.js +32 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/logging.d.ts +2 -0
  26. package/dist/logging.js +36 -0
  27. package/dist/logging.js.map +1 -0
  28. package/dist/manageMetadata.d.ts +9 -0
  29. package/dist/manageMetadata.js +603 -0
  30. package/dist/manageMetadata.js.map +1 -0
  31. package/dist/react_client_codegen.d.ts +4 -0
  32. package/dist/react_client_codegen.js +147 -0
  33. package/dist/react_client_codegen.js.map +1 -0
  34. package/dist/runCodeGen.d.ts +1 -0
  35. package/dist/runCodeGen.js +213 -0
  36. package/dist/runCodeGen.js.map +1 -0
  37. package/dist/runCommand.d.ts +9 -0
  38. package/dist/runCommand.js +111 -0
  39. package/dist/runCommand.js.map +1 -0
  40. package/dist/sql.d.ts +6 -0
  41. package/dist/sql.js +78 -0
  42. package/dist/sql.js.map +1 -0
  43. package/dist/sql_codegen.d.ts +11 -0
  44. package/dist/sql_codegen.js +753 -0
  45. package/dist/sql_codegen.js.map +1 -0
  46. package/dist/util.d.ts +4 -0
  47. package/dist/util.js +36 -0
  48. package/dist/util.js.map +1 -0
  49. package/package.json +28 -0
  50. package/readme.md +3 -0
@@ -0,0 +1,509 @@
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.generateEntitySpecificServerFileHeader = exports.generateAllEntitiesServerFileHeader = exports.generateServerEntityString = exports.generateGraphQLServerCode = void 0;
7
+ const core_1 = require("@memberjunction/core");
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ function generateGraphQLServerCode(entities, outputDirectory) {
11
+ let sRet = '';
12
+ try {
13
+ sRet = generateAllEntitiesServerFileHeader();
14
+ for (let i = 0; i < entities.length; ++i) {
15
+ sRet += generateServerEntityString(entities[i], false);
16
+ }
17
+ fs_1.default.writeFileSync(path_1.default.join(outputDirectory, 'generated.ts'), sRet);
18
+ return true;
19
+ }
20
+ catch (err) {
21
+ console.error(err);
22
+ return false;
23
+ }
24
+ }
25
+ exports.generateGraphQLServerCode = generateGraphQLServerCode;
26
+ const _graphQLTypeSuffix = '_';
27
+ function generateServerEntityString(entity, includeFileHeader) {
28
+ let sEntityOutput = '';
29
+ try {
30
+ const fields = entity.Fields;
31
+ const serverGraphQLTypeName = entity.ClassName + _graphQLTypeSuffix;
32
+ if (includeFileHeader)
33
+ sEntityOutput = generateEntitySpecificServerFileHeader(entity);
34
+ sEntityOutput += generateServerEntityHeader(entity, serverGraphQLTypeName);
35
+ // now generate the fields by looping through the fields collection from the database
36
+ for (let j = 0; j < fields.length; ++j) {
37
+ sEntityOutput += generateServerField(fields[j]);
38
+ }
39
+ for (let j = 0; j < entity.RelatedEntities.length; ++j) {
40
+ sEntityOutput += generateServerRelationship(entity.RelatedEntities[j]);
41
+ }
42
+ // finally, close it up with the footer
43
+ sEntityOutput += generateServerEntityFooter(entity);
44
+ sEntityOutput += generateServerGraphQLResolver(entity, serverGraphQLTypeName);
45
+ }
46
+ catch (err) {
47
+ console.error(err);
48
+ }
49
+ finally {
50
+ return sEntityOutput;
51
+ }
52
+ }
53
+ exports.generateServerEntityString = generateServerEntityString;
54
+ function generateAllEntitiesServerFileHeader() {
55
+ let sRet = `/********************************************************************************
56
+ * ALL ENTITIES - TypeORM/TypeGraphQL Type Class Definition - AUTO GENERATED FILE
57
+ * Generated Entities and Resolvers for Server
58
+ *
59
+ * GENERATED: ${new Date().toLocaleString()}
60
+ *
61
+ * >>> DO NOT MODIFY THIS FILE!!!!!!!!!!!!
62
+ * >>> YOUR CHANGES WILL BE OVERWRITTEN
63
+ * >>> THE NEXT TIME THIS FILE IS GENERATED
64
+ *
65
+ **********************************************************************************/
66
+ import { Arg, Ctx, Int, Query, Resolver, Field, Float, ObjectType, FieldResolver, Root, InputType, Mutation, PubSub, PubSubEngine } from '@memberjunction/server';
67
+ import { AppContext } from '@memberjunction/server';
68
+ import { MaxLength } from 'class-validator';
69
+ import { ResolverBase } from '../generic/ResolverBase';
70
+ import { RunViewByIDInput, RunViewByNameInput, RunDynamicViewInput } from '../generic/RunViewResolver';
71
+ import {
72
+ BaseEntity,
73
+ PrimaryGeneratedColumn,
74
+ JoinTable,
75
+ ViewEntity,
76
+ ManyToMany,
77
+ OneToMany,
78
+ Column,
79
+ ViewColumn,
80
+ DataSource
81
+ } from 'typeorm';
82
+ import * as MJGeneratedEntities from 'mj_generatedentities'
83
+ import { Metadata, EntityPermissionType } from '@memberjunction/core'
84
+ `;
85
+ return sRet;
86
+ }
87
+ exports.generateAllEntitiesServerFileHeader = generateAllEntitiesServerFileHeader;
88
+ function generateEntitySpecificServerFileHeader(entity) {
89
+ let sRet = `/********************************************************************************
90
+ * ${entity.Name} TypeORM/TypeGraphQL Type Class Definition - AUTO GENERATED FILE
91
+ *
92
+ * GENERATED: ${new Date().toLocaleString()}
93
+ *
94
+ * >>> DO NOT MODIFY THIS FILE!!!!!!!!!!!!
95
+ * >>> YOUR CHANGES WILL BE OVERWRITTEN
96
+ * >>> THE NEXT TIME THIS FILE IS GENERATED
97
+ *
98
+ **********************************************************************************/
99
+ import { MaxLength } from 'class-validator';
100
+ import { Field, ${entity._floatCount > 0 ? 'Float, ' : ''}Int, ObjectType } from '@memberjunction/server';
101
+ import {
102
+ BaseEntity,${entity._hasIdField ? '\n PrimaryGeneratedColumn,' : ''}${entity._manyToManyCount > 0 ? '\n JoinTable,' : ''}
103
+ ViewEntity,${entity._manyToManyCount > 0 ? '\n ManyToMany,' : ''}${entity._oneToManyCount > 0 ? '\n OneToMany,' : ''}
104
+ Column,${entity._virtualCount > 0 ? '\n ViewColumn,' : ''}
105
+ } from 'typeorm';
106
+ `;
107
+ for (let i = 0; i < entity.RelatedEntities.length; ++i) {
108
+ const tableName = entity.RelatedEntities[i].RelatedEntityBaseTableCodeName;
109
+ sRet += `\nimport ${tableName} from './${tableName}';`;
110
+ }
111
+ return sRet;
112
+ }
113
+ exports.generateEntitySpecificServerFileHeader = generateEntitySpecificServerFileHeader;
114
+ function generateServerEntityHeader(entity, serverGraphQLTypeName) {
115
+ let sDescription = entity.Description?.trim().length > 0 ? entity.Description : '';
116
+ if (sDescription.includes("'"))
117
+ sDescription = sDescription.replace(/'/g, "\\'");
118
+ return `
119
+
120
+ //****************************************************************************
121
+ // ENTITY CLASS for ${entity.Name}
122
+ //****************************************************************************
123
+ @ViewEntity({
124
+ name: '${entity.BaseView.trim().length > 0 ? entity.BaseView :
125
+ (entity.SchemaName.trim().length > 0 ? entity.SchemaName + '.' : '') + entity.BaseTable}',
126
+ synchronize: false,
127
+ })
128
+ @ObjectType(${sDescription.length > 0 ? `{ description: '${sDescription}' }` : ''})
129
+ export class ${serverGraphQLTypeName} extends BaseEntity {`;
130
+ }
131
+ function generateServerEntityFooter(entity) {
132
+ if (!entity)
133
+ console.log(entity);
134
+ return `\n}`;
135
+ }
136
+ function generateServerField(fieldInfo) {
137
+ const fieldString = getTypeORMFieldString(fieldInfo);
138
+ let fieldOptions = '';
139
+ if (fieldInfo.AllowsNull)
140
+ fieldOptions += 'nullable: true';
141
+ if (fieldInfo.Description !== null && fieldInfo.Description.trim().length > 0)
142
+ fieldOptions += (fieldOptions.length > 0 ? ', ' : '') + `description: '${fieldInfo.Description.replace(/'/g, "\\'")}'`;
143
+ if (fieldInfo.Name.toUpperCase() == 'ID') {
144
+ return `
145
+ @Field(() => Int)
146
+ @PrimaryGeneratedColumn()
147
+ ID: number;
148
+ `;
149
+ }
150
+ else {
151
+ return `
152
+ @Field(${fieldString}${fieldOptions.length > 0 ? (fieldString == '' ? '' : ', ') + `{${fieldOptions}}` : ''}) ${fieldInfo.Length > 0 && fieldString == '' /*string*/ ? '\n @MaxLength(' + fieldInfo.Length + ')' : ''}
153
+ ${fieldInfo.IsVirtual ? '@ViewColumn()' : '@Column()'}
154
+ ${fieldInfo.Name}${fieldInfo.AllowsNull ? '?' : ''}: ${(0, core_1.TypeScriptTypeFromSQLType)(fieldInfo.Type)};
155
+ `;
156
+ }
157
+ }
158
+ function getTypeORMFieldString(fieldInfo) {
159
+ switch (fieldInfo.Type.toLowerCase()) {
160
+ case 'text':
161
+ case 'char':
162
+ case 'varchar':
163
+ case 'ntext':
164
+ case 'nchar':
165
+ case 'nvarchar':
166
+ case 'uniqueidentifier': //treat this as a string
167
+ return '';
168
+ case 'datetime':
169
+ case 'datetimeoffset':
170
+ case 'date':
171
+ case 'time':
172
+ return '';
173
+ case 'bit':
174
+ return "() => Boolean";
175
+ case 'decimal':
176
+ case 'money':
177
+ fieldInfo.IsFloat = true; // used by calling functions to determine if we need to import Float
178
+ return '() => Float';
179
+ default:
180
+ return '() => Int';
181
+ }
182
+ }
183
+ function generateServerRelationship(r) {
184
+ let relatedClassName = r.RelatedEntityBaseTableCodeName;
185
+ if (r.Type.toLowerCase().trim() == 'one to many') {
186
+ return `
187
+ @Field(() => [${relatedClassName + _graphQLTypeSuffix}])
188
+ @OneToMany(() => ${relatedClassName + _graphQLTypeSuffix}, () => null)
189
+ ${r.RelatedEntityCodeName}: ${relatedClassName + _graphQLTypeSuffix}[]; // Link to ${r.RelatedEntityCodeName}
190
+ `;
191
+ }
192
+ else { // many to many
193
+ return `
194
+ @Field(() => [${relatedClassName + _graphQLTypeSuffix}])
195
+ @ManyToMany(() => ${relatedClassName + _graphQLTypeSuffix}, (${relatedClassName.toLowerCase()}) => ${relatedClassName.toLowerCase()}.${r.Entity})
196
+ @JoinTable({
197
+ name: '${r.JoinView}',
198
+ joinColumn: { name: '${r.JoinEntityJoinField}', referencedColumnName: '${r.RelatedEntityJoinField}' },
199
+ inverseJoinColumn: { name: '${r.JoinEntityInverseJoinField}', referencedColumnName: 'ID' },
200
+ })
201
+ ${r.RelatedEntityCodeName}: ${relatedClassName + _graphQLTypeSuffix}[]; // Link to ${r.RelatedEntity}
202
+ `;
203
+ }
204
+ }
205
+ function generateServerGraphQLResolver(entity, serverGraphQLTypeName) {
206
+ let sRet = '';
207
+ // we only generate resolvers for entities that have an ID field
208
+ if (entity._hasIdField) {
209
+ // first add in the base resolver query to lookup by ID for all entities
210
+ const auditAccessCode = entity.AuditRecordAccess ? `
211
+ this.createRecordAccessAuditLogRecord(userPayload, '${entity.Name}', ID)` : '';
212
+ sRet = `
213
+ //****************************************************************************
214
+ // RESOLVER for ${entity.Name}
215
+ //****************************************************************************
216
+ @ObjectType()
217
+ export class Run${entity.BaseTableCodeName}ViewResult {
218
+ @Field(() => [${serverGraphQLTypeName}])
219
+ Results: ${serverGraphQLTypeName}[];
220
+
221
+ @Field(() => Int, {nullable: true})
222
+ UserViewRunID?: number;
223
+
224
+ @Field(() => Int, {nullable: true})
225
+ RowCount: number;
226
+
227
+ @Field(() => Int, {nullable: true})
228
+ TotalRowCount: number;
229
+
230
+ @Field(() => Int, {nullable: true})
231
+ ExecutionTime: number;
232
+
233
+ @Field({nullable: true})
234
+ ErrorMessage?: string;
235
+
236
+ @Field(() => Boolean, {nullable: false})
237
+ Success: boolean;
238
+ }
239
+
240
+ @Resolver(${serverGraphQLTypeName})
241
+ export class ${entity.BaseTableCodeName}Resolver${entity.CustomResolverAPI ? 'Base' : ''} extends ResolverBase {
242
+ @Query(() => Run${entity.BaseTableCodeName}ViewResult)
243
+ async Run${entity.BaseTableCodeName}ViewByID(@Arg('input', () => RunViewByIDInput) input: RunViewByIDInput, @Ctx() { dataSource, userPayload }: AppContext, @PubSub() pubSub: PubSubEngine) {
244
+ return super.RunViewByIDGeneric(input, dataSource, userPayload, pubSub);
245
+ }
246
+
247
+ @Query(() => Run${entity.BaseTableCodeName}ViewResult)
248
+ async Run${entity.BaseTableCodeName}ViewByName(@Arg('input', () => RunViewByNameInput) input: RunViewByNameInput, @Ctx() { dataSource, userPayload }: AppContext, @PubSub() pubSub: PubSubEngine) {
249
+ return super.RunViewByNameGeneric(input, dataSource, userPayload, pubSub);
250
+ }
251
+
252
+ @Query(() => Run${entity.BaseTableCodeName}ViewResult)
253
+ async Run${entity.BaseTableCodeName}DynamicView(@Arg('input', () => RunDynamicViewInput) input: RunDynamicViewInput, @Ctx() { dataSource, userPayload }: AppContext, @PubSub() pubSub: PubSubEngine) {
254
+ input.EntityName = '${entity.Name}';
255
+ return super.RunDynamicViewGeneric(input, dataSource, userPayload, pubSub);
256
+ }
257
+
258
+ @Query(() => ${serverGraphQLTypeName}, { nullable: true })
259
+ async ${entity.BaseTableCodeName}(@Arg('ID', () => Int) ID: number, @Ctx() { dataSource, userPayload }: AppContext, @PubSub() pubSub: PubSubEngine): Promise<${serverGraphQLTypeName} | null> {
260
+ this.CheckUserReadPermissions('${entity.Name}', userPayload);
261
+ const sSQL = \`SELECT * FROM ${entity.BaseView} WHERE ID=\${ID} \` + this.getRowLevelSecurityWhereClause('${entity.Name}', userPayload, EntityPermissionType.Read, 'AND');${auditAccessCode}
262
+ return dataSource.query(sSQL).then((r) => r && r.length > 0 ? r[0] : {});
263
+ }
264
+ `;
265
+ if (entity.AllowAllRowsAPI) {
266
+ // this entity allows a query to return all rows, so include that type of query next
267
+ sRet += `
268
+ @Query(() => [${serverGraphQLTypeName}])
269
+ All${entity.CodeName}(@Ctx() { dataSource, userPayload }: AppContext, @PubSub() pubSub: PubSubEngine) {
270
+ this.CheckUserReadPermissions('${entity.Name}', userPayload);
271
+ const sSQL = 'SELECT * FROM ${entity.BaseView}' + this.getRowLevelSecurityWhereClause('${entity.Name}', userPayload, EntityPermissionType.Read, ' WHERE');
272
+ return dataSource.query(sSQL);
273
+ }
274
+ `;
275
+ }
276
+ // now, generate the FieldResolvers for each of the one-to-many relationships
277
+ for (let i = 0; i < entity.RelatedEntities.length; i++) {
278
+ const r = entity.RelatedEntities[i];
279
+ if (r.Type.toLowerCase().trim() == 'many to many')
280
+ sRet += generateManyToManyFieldResolver(entity, r);
281
+ else
282
+ sRet += generateOneToManyFieldResolver(entity, r);
283
+ }
284
+ // now do the mutations
285
+ const sInputType = generateServerGraphQLInputType(entity);
286
+ if (sInputType !== '') {
287
+ // only generate mutations if we have input type, because otherwsie we don't need em
288
+ sRet += generateServerGraphQLMutations(entity, serverGraphQLTypeName);
289
+ }
290
+ sRet += `\n}`;
291
+ if (sInputType !== '') {
292
+ sRet = sInputType + sRet; // put the input type before the resolver as the decorators have to be evaluated ahead of their use in the resolver
293
+ }
294
+ }
295
+ return sRet;
296
+ }
297
+ function generateServerGraphQLInputType(entity) {
298
+ let sRet = '';
299
+ if (entity.AllowCreateAPI)
300
+ sRet += generateServerGraphQLInputTypeInner(entity, false, 'Create');
301
+ if (entity.AllowUpdateAPI)
302
+ sRet += generateServerGraphQLInputTypeInner(entity, true, 'Update');
303
+ return sRet;
304
+ }
305
+ function generateServerGraphQLInputTypeInner(entity, includeID, classPrefix) {
306
+ let sRet = '';
307
+ sRet += `\n
308
+ //****************************************************************************
309
+ // INPUT TYPE for ${entity.Name}
310
+ //****************************************************************************
311
+ @InputType()
312
+ export class ${classPrefix}${entity.BaseTableCodeName}Input {`;
313
+ for (let i = 0; i < entity.Fields.length; i++) {
314
+ const f = entity.Fields[i];
315
+ const sTypeORMString = getTypeORMFieldString(f);
316
+ const sNull = f.AllowsNull ? '{ nullable: true }' : '';
317
+ const sFullTypeORMString = sTypeORMString + (sTypeORMString == '' ? '' : ', ') + sNull;
318
+ // always include ID becuase it is used for UPDATES
319
+ if ((includeID && f.Name.toLowerCase() == 'id') || (!f.IsVirtual && f.AllowUpdateAPI && f.Type.trim().toLowerCase() !== 'uniqueidentifier')) {
320
+ sRet += `
321
+ @Field(${sFullTypeORMString})
322
+ ${f.Name}: ${(0, core_1.TypeScriptTypeFromSQLType)(f.Type)};
323
+ `;
324
+ }
325
+ }
326
+ sRet += `}
327
+ `;
328
+ return sRet;
329
+ }
330
+ function generateServerGraphQLMutations(entity, serverGraphQLTypeName) {
331
+ let sRet = '';
332
+ // MUTATIONS
333
+ // First, determine if the entity has either Create/Edit allowed, if either, we need to generate a InputType
334
+ if (entity.AllowCreateAPI && !entity.VirtualEntity) {
335
+ const logChanges = !entity.TrackRecordChanges ? '' : `
336
+ if (result && result.length > 0 && result[0].ID > 0)
337
+ await this.LogRecordChange(dataSource, input, null, '${entity.Name}', result[0].ID ) // part of same transaction so all good if we succeed
338
+ `;
339
+ // generate a create mutation
340
+ sRet += `
341
+ @Mutation(() => ${serverGraphQLTypeName})
342
+ async Create${entity.BaseTableCodeName}(
343
+ @Arg('input', () => Create${entity.BaseTableCodeName}Input) input: Create${entity.BaseTableCodeName}Input,
344
+ @Ctx() { dataSource, userPayload }: AppContext,
345
+ @PubSub() pubSub: PubSubEngine
346
+ ) {
347
+ if (await this.BeforeCreate(dataSource, input)) { // fire event and proceed if it wasn't cancelled
348
+ const entityObject = await new Metadata().GetEntityObject('${entity.Name}', this.GetUserFromPayload(userPayload));
349
+ await entityObject.NewRecord();
350
+ entityObject.SetMany(input);
351
+ if (await entityObject.Save()) {
352
+ // save worked, fire the AfterCreate event and then return all the data
353
+ await this.AfterCreate(dataSource, input); // fire event
354
+ return entityObject.GetAll();
355
+ }
356
+ else
357
+ // save failed, return null
358
+ return null;
359
+ }
360
+ else
361
+ return null;
362
+ }
363
+
364
+ // Before/After CREATE Event Hooks for Sub-Classes to Override
365
+ protected async BeforeCreate(dataSource: DataSource, input: Create${entity.BaseTableCodeName}Input): Promise<boolean> {
366
+ const i = input, d = dataSource; // prevent error
367
+ return true;
368
+ }
369
+ protected async AfterCreate(dataSource: DataSource, input: Create${entity.BaseTableCodeName}Input) {
370
+ const i = input, d = dataSource; // prevent error
371
+ }
372
+ `;
373
+ }
374
+ if (entity.AllowUpdateAPI && !entity.VirtualEntity) {
375
+ // generate an edit mutation
376
+ sRet += `
377
+ @Mutation(() => ${serverGraphQLTypeName})
378
+ async Update${entity.BaseTableCodeName}(
379
+ @Arg('input', () => Update${entity.BaseTableCodeName}Input) input: Update${entity.BaseTableCodeName}Input,
380
+ @Ctx() { dataSource, userPayload }: AppContext,
381
+ @PubSub() pubSub: PubSubEngine
382
+ ) {
383
+ if (await this.BeforeUpdate(dataSource, input)) { // fire event and proceed if it wasn't cancelled
384
+ const entityObject = await new Metadata().GetEntityObject('${entity.Name}', this.GetUserFromPayload(userPayload));
385
+ ${entity.TrackRecordChanges ? 'await entityObject.Load(input.ID) // Track Changes is turned on, so we need to get the latest data from DB first before we save' : `entityObject.LoadFromData(input) // using the input instead of loading from DB because TrackChanges is turned off for ${entity.Name}`}
386
+ ${entity.TrackRecordChanges ? 'entityObject.SetMany(input);' : ''}
387
+ if (await entityObject.Save(${entity.TrackRecordChanges ? '' : '{ IgnoreDirtyState: true /*flag used because of LoadFromData() call above*/ }'})) {
388
+ // save worked, fire afterevent and return all the data
389
+ await this.AfterUpdate(dataSource, input); // fire event
390
+ return entityObject.GetAll();
391
+ }
392
+ else
393
+ return null; // save failed, return null
394
+ }
395
+ else
396
+ return null;
397
+ }
398
+
399
+ // Before/After UPDATE Event Hooks for Sub-Classes to Override
400
+ protected async BeforeUpdate(dataSource: DataSource, input: Update${entity.BaseTableCodeName}Input): Promise<boolean> {
401
+ const i = input, d = dataSource; // prevent error
402
+ return true;
403
+ }
404
+ protected async AfterUpdate(dataSource: DataSource, input: Update${entity.BaseTableCodeName}Input) {
405
+ const i = input, d = dataSource; // prevent error
406
+ }
407
+ `;
408
+ }
409
+ if (entity.AllowDeleteAPI && !entity.VirtualEntity) {
410
+ sRet += `
411
+ @Mutation(() => Int)
412
+ async Delete${entity.BaseTableCodeName}(@Arg('ID', () => Int) ID: number, @Ctx() { dataSource, userPayload }: AppContext, @PubSub() pubSub: PubSubEngine) {
413
+ if (await this.BeforeDelete(dataSource, ID)) { // fire event and proceed if it wasn't cancelled
414
+ const entityObject = await new Metadata().GetEntityObject('${entity.Name}', this.GetUserFromPayload(userPayload));
415
+ await entityObject.Load(ID)
416
+ if (await entityObject.Delete()) {
417
+ await this.AfterDelete(dataSource, ID); // fire event
418
+ return ID;
419
+ }
420
+ else
421
+ return null; // delete failed
422
+ }
423
+ else
424
+ return null;
425
+ }
426
+
427
+ // Before/After UPDATE Event Hooks for Sub-Classes to Override
428
+ protected async BeforeDelete(dataSource: DataSource, ID: number): Promise<boolean> {
429
+ const i = ID, d = dataSource; // prevent error;
430
+ return true;
431
+ }
432
+ protected async AfterDelete(dataSource: DataSource, ID: number) {
433
+ const i = ID, d = dataSource; // prevent error
434
+ }
435
+ `;
436
+ }
437
+ return sRet;
438
+ }
439
+ function generateSPParams(entity, isUpdate) {
440
+ let sRet = '', bFirst = true;
441
+ for (let i = 0; i < entity.Fields.length; i++) {
442
+ const f = entity.Fields[i];
443
+ if (!f.IsVirtual) {
444
+ switch (f.Name.toLowerCase()) {
445
+ case 'id':
446
+ if (isUpdate) {
447
+ sRet += generateSingleSPParam(f, bFirst);
448
+ bFirst = false;
449
+ }
450
+ break;
451
+ case 'createdat':
452
+ case 'updatedat':
453
+ // do nothing
454
+ break;
455
+ default:
456
+ if (f.Type.trim().toLowerCase() !== 'uniqueidentifier') {
457
+ // DO NOT INCLUDE UNIQUEIDENTIFIER FIELDS
458
+ // FOR CREATE/UPDATE, THEY ARE GENERATED BY THE DB
459
+ sRet += generateSingleSPParam(f, bFirst);
460
+ bFirst = false;
461
+ }
462
+ break;
463
+ }
464
+ }
465
+ }
466
+ return sRet;
467
+ }
468
+ function generateSingleSPParam(f, isFirst) {
469
+ let sRet = '';
470
+ let quotes = '';
471
+ switch ((0, core_1.TypeScriptTypeFromSQLType)(f.Type).toLowerCase()) {
472
+ case 'string':
473
+ case 'date':
474
+ quotes = "'";
475
+ break;
476
+ default:
477
+ break;
478
+ }
479
+ if (!isFirst)
480
+ sRet += ',\n ';
481
+ sRet += `@${f.Name}=\${this.packageSPParam(input.${f.Name},"${quotes}")}`;
482
+ return sRet;
483
+ }
484
+ function generateOneToManyFieldResolver(entity, r) {
485
+ // let keyFieldTS: string = 'number';
486
+ // if (r.EntityKeyField) {
487
+ // const keyField = entity.Fields.find(f => f.Name.toLowerCase() == r.EntityKeyField.toLowerCase())
488
+ // keyFieldTS = keyField ? TypeScriptTypeFromSQLType(keyField.Type) : 'int';
489
+ // }
490
+ return `
491
+ @FieldResolver(() => [${r.RelatedEntityBaseTableCodeName + _graphQLTypeSuffix}])
492
+ async ${r.RelatedEntityCodeName}(@Root() ${entity.BaseTableCodeName.toLowerCase()}: ${entity.BaseTableCodeName + _graphQLTypeSuffix}, @Ctx() { dataSource, userPayload }: AppContext, @PubSub() pubSub: PubSubEngine) {
493
+ this.CheckUserReadPermissions('${r.RelatedEntity}', userPayload);
494
+ const sSQL = \`SELECT * FROM ${r.RelatedEntityBaseView}\ WHERE ${r.RelatedEntityJoinField}=\${${entity.BaseTableCodeName.toLowerCase()}.${!r.EntityKeyField ? 'ID' : r.EntityKeyField}} \` + this.getRowLevelSecurityWhereClause('${r.RelatedEntity}', userPayload, EntityPermissionType.Read, 'AND');
495
+ return dataSource.query(sSQL);
496
+ }
497
+ `;
498
+ }
499
+ function generateManyToManyFieldResolver(entity, r) {
500
+ return `
501
+ @FieldResolver(() => [${r.RelatedEntityBaseTableCodeName + _graphQLTypeSuffix}])
502
+ async ${r.RelatedEntityCodeName}(@Root() ${entity.BaseTableCodeName.toLowerCase()}: ${entity.BaseTableCodeName + _graphQLTypeSuffix}, @Ctx() { dataSource, userPayload }: AppContext, @PubSub() pubSub: PubSubEngine) {
503
+ this.CheckUserReadPermissions('${r.RelatedEntity}', userPayload);
504
+ const sSQL = \`SELECT * FROM ${r.RelatedEntityBaseView}\ WHERE ID IN (SELECT ${r.JoinEntityInverseJoinField} FROM ${r.JoinView} WHERE ${r.JoinEntityJoinField}=\${${entity.BaseTableCodeName.toLowerCase()}.${!r.EntityKeyField ? 'ID' : r.EntityKeyField}}) \` + this.getRowLevelSecurityWhereClause('${r.RelatedEntity}', userPayload, EntityPermissionType.Read, 'AND');
505
+ return dataSource.query(sSQL);
506
+ }
507
+ `;
508
+ }
509
+ //# sourceMappingURL=graphql_server_codegen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql_server_codegen.js","sourceRoot":"","sources":["../src/graphql_server_codegen.ts"],"names":[],"mappings":";;;;;;AAAA,+CAAsH;AACtH,4CAAoB;AACpB,gDAAwB;AAExB,SAAgB,yBAAyB,CAAC,QAAsB,EAAE,eAAuB;IACrF,IAAI,IAAI,GAAW,EAAE,CAAC;IACtB,IAAI;QACA,IAAI,GAAG,mCAAmC,EAAE,CAAC;QAE7C,KAAK,IAAI,CAAC,GAAU,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YAC7C,IAAI,IAAI,0BAA0B,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;SAC1D;QACD,YAAE,CAAC,aAAa,CAAC,cAAI,CAAC,IAAI,CAAC,eAAe,EAAE,cAAc,CAAC,EAAE,IAAI,CAAC,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CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,+CAA+C,CAAC,CAAC,aAAa;;;KAGtP,CAAA;AACL,CAAC;AACD,SAAS,+BAA+B,CAAC,MAAkB,EAAE,CAAyB;IAClF,OAAO;4BACiB,CAAC,CAAC,8BAA8B,GAAI,kBAAkB;YACtE,CAAC,CAAC,qBAAqB,YAAY,MAAM,CAAC,iBAAiB,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,iBAAiB,GAAG,kBAAkB;yCAC9F,CAAC,CAAC,aAAa;uCACjB,CAAC,CAAC,qBAAqB,yBAAyB,CAAC,CAAC,0BAA0B,SAAS,CAAC,CAAC,QAAQ,UAAU,CAAC,CAAC,mBAAmB,OAAO,MAAM,CAAC,iBAAiB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,gDAAgD,CAAC,CAAC,aAAa;;;KAG3T,CAAC;AACN,CAAC"}
@@ -0,0 +1,15 @@
1
+ export * from './angular_client_codegen';
2
+ export * from './config';
3
+ export * from './db';
4
+ export * from './dbSchema';
5
+ export * from './entity_subclasses_codegen';
6
+ export * from './graphql_client_codegen';
7
+ export * from './graphql_server_codegen';
8
+ export * from './logging';
9
+ export * from './manageMetadata';
10
+ export * from './react_client_codegen';
11
+ export * from './runCommand';
12
+ export * from './sql_codegen';
13
+ export * from './sql';
14
+ export * from './util';
15
+ export * from './runCodeGen';
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./angular_client_codegen"), exports);
18
+ __exportStar(require("./config"), exports);
19
+ __exportStar(require("./db"), exports);
20
+ __exportStar(require("./dbSchema"), exports);
21
+ __exportStar(require("./entity_subclasses_codegen"), exports);
22
+ __exportStar(require("./graphql_client_codegen"), exports);
23
+ __exportStar(require("./graphql_server_codegen"), exports);
24
+ __exportStar(require("./logging"), exports);
25
+ __exportStar(require("./manageMetadata"), exports);
26
+ __exportStar(require("./react_client_codegen"), exports);
27
+ __exportStar(require("./runCommand"), exports);
28
+ __exportStar(require("./sql_codegen"), exports);
29
+ __exportStar(require("./sql"), exports);
30
+ __exportStar(require("./util"), exports);
31
+ __exportStar(require("./runCodeGen"), exports);
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAwC;AACxC,2CAAwB;AACxB,uCAAoB;AACpB,6CAA0B;AAC1B,8DAA2C;AAC3C,2DAAwC;AACxC,2DAAwC;AACxC,4CAAyB;AACzB,mDAAgC;AAChC,yDAAsC;AACtC,+CAA4B;AAC5B,gDAA6B;AAC7B,wCAAqB;AACrB,yCAAsB;AAEtB,+CAA4B"}
@@ -0,0 +1,2 @@
1
+ export declare function logError(message: string, ...args: any[]): void;
2
+ export declare function logStatus(message: string, ...args: any[]): void;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logStatus = exports.logError = void 0;
4
+ const config_1 = require("./config");
5
+ const core_1 = require("@memberjunction/core");
6
+ function logError(message, ...args) {
7
+ logToConsole(message, true, args);
8
+ logToFile(message, true, args);
9
+ }
10
+ exports.logError = logError;
11
+ function logStatus(message, ...args) {
12
+ logToConsole(message, false, args);
13
+ logToFile(message, false, args);
14
+ }
15
+ exports.logStatus = logStatus;
16
+ function logToConsole(message, isError, ...args) {
17
+ if (config_1.configInfo.logging.console) {
18
+ if (isError)
19
+ (0, core_1.LogError)(message, null, args);
20
+ else
21
+ (0, core_1.LogStatus)(message, null, args);
22
+ }
23
+ }
24
+ function logToFile(message, isError, ...args) {
25
+ if (config_1.configInfo.logging.log) {
26
+ if (config_1.configInfo.logging.logFile === null || config_1.configInfo.logging.logFile === undefined || config_1.configInfo.logging.logFile === '')
27
+ (0, core_1.LogError)('ERROR: No log file specified in config.json');
28
+ else {
29
+ if (isError)
30
+ (0, core_1.LogError)(message, config_1.configInfo.logging.logFile, args);
31
+ else
32
+ (0, core_1.LogStatus)(message, config_1.configInfo.logging.logFile, args);
33
+ }
34
+ }
35
+ }
36
+ //# sourceMappingURL=logging.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.js","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":";;;AAAA,qCAAsC;AACtC,+CAA0D;AAG1D,SAAgB,QAAQ,CAAC,OAAe,EAAE,GAAG,IAAW;IACrD,YAAY,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IACjC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;AACjC,CAAC;AAHD,4BAGC;AAED,SAAgB,SAAS,CAAC,OAAe,EAAE,GAAG,IAAW;IACtD,YAAY,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;IAClC,SAAS,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;AAClC,CAAC;AAHD,8BAGC;AAED,SAAS,YAAY,CAAC,OAAe,EAAE,OAAgB,EAAE,GAAG,IAAW;IACpE,IAAI,mBAAU,CAAC,OAAO,CAAC,OAAO,EAAE;QAC7B,IAAI,OAAO;YACR,IAAA,eAAQ,EAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;;YAE7B,IAAA,gBAAS,EAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;KACnC;AACJ,CAAC;AACD,SAAS,SAAS,CAAC,OAAO,EAAE,OAAgB,EAAE,GAAG,IAAW;IACzD,IAAI,mBAAU,CAAC,OAAO,CAAC,GAAG,EAAE;QACzB,IAAI,mBAAU,CAAC,OAAO,CAAC,OAAO,KAAK,IAAI,IAAI,mBAAU,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,IAAI,mBAAU,CAAC,OAAO,CAAC,OAAO,KAAK,EAAE;YACrH,IAAA,eAAQ,EAAC,6CAA6C,CAAC,CAAA;aACpD;YACH,IAAI,OAAO;gBACR,IAAA,eAAQ,EAAC,OAAO,EAAE,mBAAU,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;;gBAEnD,IAAA,gBAAS,EAAC,OAAO,EAAE,mBAAU,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;SACzD;KACH;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { DataSource } from "typeorm";
2
+ import { Metadata } from "@memberjunction/core";
3
+ export declare const newEntityList: string[];
4
+ export declare function manageMetadata(ds: DataSource): Promise<boolean>;
5
+ export declare function manageEntityRelationships(ds: DataSource, md: Metadata): Promise<boolean>;
6
+ export declare function manageOneToManyEntityRelationships(ds: DataSource, md: Metadata): Promise<boolean>;
7
+ export declare function manageManyToManyEntityRelationships(ds: DataSource): Promise<boolean>;
8
+ export declare function manageEntityFields(ds: DataSource): Promise<boolean>;
9
+ export declare function updateEntityFieldRelatedEntityNameFieldMap(ds: DataSource, entityFieldID: number, relatedEntityNameFieldMap: string): Promise<boolean>;